mojoshader_vulkan.c
changeset 1315 c54ad4b34c03
parent 1304 d68910d81b6e
equal deleted inserted replaced
1314:3ddd9fca664f 1315:c54ad4b34c03
    45     VkBuffer buffer;
    45     VkBuffer buffer;
    46     VkDeviceMemory deviceMemory;
    46     VkDeviceMemory deviceMemory;
    47     VkDeviceSize bufferSize;
    47     VkDeviceSize bufferSize;
    48     VkDeviceSize dynamicOffset;
    48     VkDeviceSize dynamicOffset;
    49     VkDeviceSize currentBlockSize;
    49     VkDeviceSize currentBlockSize;
       
    50     VkDeviceSize currentBlockIncrement;
    50     uint8_t *mapPointer;
    51     uint8_t *mapPointer;
    51 } MOJOSHADER_vkUniformBuffer;
    52 } MOJOSHADER_vkUniformBuffer;
    52 
    53 
    53 // Error state...
    54 // Error state...
    54 static char error_buffer[1024] = { '\0' };
    55 static char error_buffer[1024] = { '\0' };
   215                      (void**) &result->mapPointer
   216                      (void**) &result->mapPointer
   216     );
   217     );
   217 
   218 
   218     result->bufferSize = UBO_ACTUAL_SIZE;
   219     result->bufferSize = UBO_ACTUAL_SIZE;
   219     result->currentBlockSize = 0;
   220     result->currentBlockSize = 0;
       
   221     result->currentBlockIncrement = 0;
   220     result->dynamicOffset = 0;
   222     result->dynamicOffset = 0;
   221 
   223 
   222     return result;
   224     return result;
   223 } // create_ubo
   225 } // create_ubo
   224 
   226 
   296         regB = ctx->ps_reg_file_b;
   298         regB = ctx->ps_reg_file_b;
   297 
   299 
   298         ubo = ctx->fragUboBuffer;
   300         ubo = ctx->fragUboBuffer;
   299     } // else
   301     } // else
   300 
   302 
   301     ubo->dynamicOffset += ubo->currentBlockSize;
   303     ubo->dynamicOffset += ubo->currentBlockIncrement;
   302 
   304 
   303     ubo->currentBlockSize = next_highest_offset_alignment(uniform_data_size(shader));
   305     ubo->currentBlockSize = next_highest_offset_alignment(uniform_data_size(shader));
       
   306     ubo->currentBlockIncrement = ubo->currentBlockSize;
   304 
   307 
   305     if (ubo->dynamicOffset + ubo->currentBlockSize >= ubo->bufferSize * ctx->frameIndex)
   308     if (ubo->dynamicOffset + ubo->currentBlockSize >= ubo->bufferSize * ctx->frameIndex)
   306     {
   309     {
   307         set_error("UBO overflow!!");
   310         set_error("UBO overflow!!");
   308     } // if
   311     } // if
   781     ctx->frameIndex = (ctx->frameIndex + 1) % 2;
   784     ctx->frameIndex = (ctx->frameIndex + 1) % 2;
   782 
   785 
   783     // Reset counters
   786     // Reset counters
   784     // Offset by size of buffer to simulate "rotating" the buffers
   787     // Offset by size of buffer to simulate "rotating" the buffers
   785     ctx->vertUboBuffer->dynamicOffset = UBO_BUFFER_SIZE * ctx->frameIndex;
   788     ctx->vertUboBuffer->dynamicOffset = UBO_BUFFER_SIZE * ctx->frameIndex;
   786     ctx->vertUboBuffer->currentBlockSize = 0;
   789     ctx->vertUboBuffer->currentBlockIncrement = 0;
   787     ctx->fragUboBuffer->dynamicOffset = UBO_BUFFER_SIZE * ctx->frameIndex;
   790     ctx->fragUboBuffer->dynamicOffset = UBO_BUFFER_SIZE * ctx->frameIndex;
   788     ctx->fragUboBuffer->currentBlockSize = 0;
   791     ctx->fragUboBuffer->currentBlockIncrement = 0;
   789 } // MOJOSHADER_VkEndFrame
   792 } // MOJOSHADER_VkEndFrame
   790 
   793 
   791 int MOJOSHADER_vkGetVertexAttribLocation(MOJOSHADER_vkShader *vert,
   794 int MOJOSHADER_vkGetVertexAttribLocation(MOJOSHADER_vkShader *vert,
   792                                          MOJOSHADER_usage usage, int index)
   795                                          MOJOSHADER_usage usage, int index)
   793 {
   796 {