Because vulkan requires that mutable objects are usually externally synchronized you can use a shared lock around getting the custom data. It helps that std::map maintains referential consistency when inserting/removing.
So cmdDraw can boil down to:
VK_LAYER_EXPORT void VKAPI_CALL SampleLayer_CmdDraw(
VkCommandBuffer commandBuffer,
uint32_t vertexCount,
uint32_t instanceCount,
uint32_t firstVertex,
uint32_t firstInstance)
{
CommandStats* state;
{
scoped_lock_shared l(global_lock);
state = &commandbuffer_stats[commandBuffer];
}
state->drawCount++;
state->instanceCount += instanceCount;
state->vertCount += instanceCount*vertexCount;
device_dispatch[GetKey(commandBuffer)].CmdDraw(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
}
This will improve threading behavior and stay correct as long as the application obeys the threading requirements.
Because vulkan requires that mutable objects are usually externally synchronized you can use a shared lock around getting the custom data. It helps that std::map maintains referential consistency when inserting/removing.
So cmdDraw can boil down to:
This will improve threading behavior and stay correct as long as the application obeys the threading requirements.