Skip to content

Global_lock can be a shared_mutex #1

Description

@ratchetfreak

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions