Skip to content

Commit

Permalink
Drop the global lock around calling some of the underlying API commands
Browse files Browse the repository at this point in the history
Unlock before calling some of the underlying API command calls, and lock
again after return from the underlying API command calls.

This improves the tracing performance, especially when the application
builds Vulkan pipelines in multiple threads.
  • Loading branch information
Qining committed Sep 13, 2018
1 parent 1a3259d commit c974f65
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 9 deletions.
8 changes: 4 additions & 4 deletions gapis/api/templates/api_spy.cpp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@
observer->observeTimestamp();
}

{{if (GetAnnotation $ "blocking")}}
unlock();
{{if (GetAnnotation $ "threadsafe")}}
unlock();
{{end}}
{{/* Perform the call */}}
{{if not (GetAnnotation $ "synthetic")}}
Expand All @@ -243,8 +243,8 @@
mImports.{{Template "CmdName" $}}({{Template "C++.CallArguments" $}});
{{end}}
{{end}}
{{if (GetAnnotation $ "blocking")}}
lock(observer);
{{if (GetAnnotation $ "threadsafe")}}
lock(observer);
{{end}}
{{if IsVoid $.Return.Type}}
Expand Down
11 changes: 11 additions & 0 deletions gapis/api/vulkan/api/copy_clear_commands.api
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ sub void copyBufferToBuffer(ref!BufferObject dstBuf, VkDeviceSize dstOffset, ref

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdCopyBuffer(
VkCommandBuffer commandBuffer,
VkBuffer srcBuffer,
Expand Down Expand Up @@ -296,6 +297,7 @@ sub void dovkCmdCopyImage(ref!vkCmdCopyImageArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdCopyImage(
VkCommandBuffer commandBuffer,
VkImage srcImage,
Expand Down Expand Up @@ -340,6 +342,7 @@ sub void dovkCmdBlitImage(ref!vkCmdBlitImageArgs dispatch) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdBlitImage(
VkCommandBuffer commandBuffer,
VkImage srcImage,
Expand Down Expand Up @@ -485,6 +488,7 @@ sub void dovkCmdCopyBufferToImage(ref!vkCmdCopyBufferToImageArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdCopyBufferToImage(
VkCommandBuffer commandBuffer,
VkBuffer srcBuffer,
Expand Down Expand Up @@ -522,6 +526,7 @@ sub void dovkCmdCopyImageToBuffer(ref!vkCmdCopyImageToBufferArgs dispatch) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdCopyImageToBuffer(
VkCommandBuffer commandBuffer,
VkImage srcImage,
Expand Down Expand Up @@ -569,6 +574,7 @@ sub void dovkCmdUpdateBuffer(ref!vkCmdUpdateBufferArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdUpdateBuffer(
VkCommandBuffer commandBuffer,
VkBuffer dstBuffer,
Expand Down Expand Up @@ -611,6 +617,7 @@ sub void dovkCmdFillBuffer(ref!vkCmdFillBufferArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdFillBuffer(
VkCommandBuffer commandBuffer,
VkBuffer dstBuffer,
Expand Down Expand Up @@ -646,6 +653,7 @@ sub void dovkCmdClearColorImage(ref!vkCmdClearColorImageArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdClearColorImage(
VkCommandBuffer commandBuffer,
VkImage image,
Expand Down Expand Up @@ -687,6 +695,7 @@ sub void dovkCmdClearDepthStencilImage(ref!vkCmdClearDepthStencilImageArgs args)

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdClearDepthStencilImage(
VkCommandBuffer commandBuffer,
VkImage image,
Expand Down Expand Up @@ -726,6 +735,7 @@ sub void dovkCmdClearAttachments(ref!vkCmdClearAttachmentsArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdClearAttachments(
VkCommandBuffer commandBuffer,
u32 attachmentCount,
Expand Down Expand Up @@ -782,6 +792,7 @@ sub void dovkCmdResolveImage(ref!vkCmdResolveImageArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdResolveImage(
VkCommandBuffer commandBuffer,
VkImage srcImage,
Expand Down
3 changes: 3 additions & 0 deletions gapis/api/vulkan/api/descriptor.api
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ sub map!(u32, DescriptorSetCopy) RewriteWriteDescriptorCopies
}

@indirect("VkDevice")
@threadsafe
cmd void vkUpdateDescriptorSets(
VkDevice device,
u32 descriptorWriteCount,
Expand Down Expand Up @@ -752,6 +753,7 @@ sub void dovkCmdBindDescriptorSets(ref!vkCmdBindDescriptorSetsArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdBindDescriptorSets(
VkCommandBuffer commandBuffer,
VkPipelineBindPoint pipelineBindPoint,
Expand Down Expand Up @@ -798,6 +800,7 @@ sub void dovkCmdPushConstants(ref!vkCmdPushConstantsArgs args) {
}

@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdPushConstants(
VkCommandBuffer commandBuffer,
VkPipelineLayout layout,
Expand Down
2 changes: 1 addition & 1 deletion gapis/api/vulkan/api/device.api
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ cmd void vkDestroyDevice(

@threadSafety("system")
@indirect("VkDevice")
@blocking
@threadsafe
cmd VkResult vkDeviceWaitIdle(
VkDevice device) {
if !(device in Devices) { vkErrorInvalidDevice(device) }
Expand Down
8 changes: 8 additions & 0 deletions gapis/api/vulkan/api/draw_commands.api
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ sub void dovkCmdBindIndexBuffer(ref!vkCmdBindIndexBufferArgs buffer) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdBindIndexBuffer(
VkCommandBuffer commandBuffer,
VkBuffer buffer,
Expand Down Expand Up @@ -104,6 +105,7 @@ sub void dovkCmdBindVertexBuffers(ref!vkCmdBindVertexBuffersArgs bind) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdBindVertexBuffers(
VkCommandBuffer commandBuffer,
u32 firstBinding,
Expand Down Expand Up @@ -148,6 +150,7 @@ sub void dovkCmdDraw(ref!vkCmdDrawArgs draw) {
@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@executed_draw
@threadsafe
cmd void vkCmdDraw(
VkCommandBuffer commandBuffer,
u32 vertexCount,
Expand Down Expand Up @@ -200,6 +203,7 @@ sub void dovkCmdDrawIndexed(ref!vkCmdDrawIndexedArgs draw) {
@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@executed_draw
@threadsafe
cmd void vkCmdDrawIndexed(
VkCommandBuffer commandBuffer,
u32 indexCount,
Expand Down Expand Up @@ -246,6 +250,7 @@ sub void dovkCmdDrawIndirect(ref!vkCmdDrawIndirectArgs draw) {
@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@executed_draw
@threadsafe
cmd void vkCmdDrawIndirect(
VkCommandBuffer commandBuffer,
VkBuffer buffer,
Expand Down Expand Up @@ -289,6 +294,7 @@ sub void dovkCmdDrawIndexedIndirect(ref!vkCmdDrawIndexedIndirectArgs draw) {
@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@executed_draw
@threadsafe
cmd void vkCmdDrawIndexedIndirect(
VkCommandBuffer commandBuffer,
VkBuffer buffer,
Expand Down Expand Up @@ -319,6 +325,7 @@ sub void dovkCmdDispatch(ref!vkCmdDispatchArgs args) {
@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@executed_draw
@threadsafe
cmd void vkCmdDispatch(
VkCommandBuffer commandBuffer,
u32 groupCountX,
Expand Down Expand Up @@ -350,6 +357,7 @@ sub void dovkCmdDispatchIndirect(ref!vkCmdDispatchIndirectArgs dispatch) {
@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@executed_draw
@threadsafe
cmd void vkCmdDispatchIndirect(
VkCommandBuffer commandBuffer,
VkBuffer buffer,
Expand Down
12 changes: 12 additions & 0 deletions gapis/api/vulkan/api/pipeline.api
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

@threadSafety("system")
@indirect("VkDevice")
@threadsafe
cmd VkResult vkCreatePipelineLayout(
VkDevice device,
const VkPipelineLayoutCreateInfo* pCreateInfo,
Expand Down Expand Up @@ -220,6 +221,7 @@ class CreatedGraphicsPipelines {
}

@indirect("VkDevice")
@threadsafe
cmd VkResult vkCreateGraphicsPipelines(
VkDevice device,
VkPipelineCache pipelineCache,
Expand Down Expand Up @@ -445,6 +447,7 @@ class CreatedComputePipelines {
}

@indirect("VkDevice")
@threadsafe
cmd VkResult vkCreateComputePipelines(
VkDevice device,
VkPipelineCache pipelineCache,
Expand Down Expand Up @@ -538,6 +541,7 @@ cmd void vkDestroyPipeline(
}

@indirect("VkDevice")
@threadsafe
cmd VkResult vkCreateShaderModule(
VkDevice device,
const VkShaderModuleCreateInfo* pCreateInfo,
Expand Down Expand Up @@ -660,6 +664,7 @@ sub void dovkCmdBindPipeline(ref!vkCmdBindPipelineArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdBindPipeline(
VkCommandBuffer commandBuffer,
VkPipelineBindPoint pipelineBindPoint,
Expand All @@ -685,6 +690,7 @@ sub void dovkCmdSetViewport(ref!vkCmdSetViewportArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdSetViewport(
VkCommandBuffer commandBuffer,
u32 firstViewport,
Expand Down Expand Up @@ -717,6 +723,7 @@ sub void dovkCmdSetScissor(ref!vkCmdSetScissorArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdSetScissor(
VkCommandBuffer commandBuffer,
u32 firstScissor,
Expand Down Expand Up @@ -748,6 +755,7 @@ sub void dovkCmdSetLineWidth(ref!vkCmdSetLineWidthArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdSetLineWidth(
VkCommandBuffer commandBuffer,
f32 lineWidth) {
Expand Down Expand Up @@ -803,6 +811,7 @@ sub void dovkCmdSetBlendConstants(ref!vkCmdSetBlendConstantsArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdSetBlendConstants(
VkCommandBuffer commandBuffer,
@readonly f32[4] blendConstants) {
Expand Down Expand Up @@ -830,6 +839,7 @@ sub void dovkCmdSetDepthBounds(ref!vkCmdSetDepthBoundsArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdSetDepthBounds(
VkCommandBuffer commandBuffer,
f32 minDepthBounds,
Expand All @@ -856,6 +866,7 @@ sub void dovkCmdSetStencilCompareMask(ref!vkCmdSetStencilCompareMaskArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdSetStencilCompareMask(
VkCommandBuffer commandBuffer,
VkStencilFaceFlags faceMask,
Expand Down Expand Up @@ -883,6 +894,7 @@ sub void dovkCmdSetStencilWriteMask(ref!vkCmdSetStencilWriteMaskArgs args) {

@threadSafety("app")
@indirect("VkCommandBuffer", "VkDevice")
@threadsafe
cmd void vkCmdSetStencilWriteMask(
VkCommandBuffer commandBuffer,
VkStencilFaceFlags faceMask,
Expand Down
2 changes: 1 addition & 1 deletion gapis/api/vulkan/api/query_pool.api
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ cmd void vkDestroyQueryPool(

@threadSafety("system")
@indirect("VkDevice")
@blocking
@threadsafe
@no_replay
// GetQueryPoolResults has no semantic impact
// on replay, so avoid replaying it. It can cause
Expand Down
2 changes: 1 addition & 1 deletion gapis/api/vulkan/api/queue.api
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ cmd VkResult vkQueueSubmit(

@threadSafety("system")
@indirect("VkQueue", "VkDevice")
@blocking
@threadsafe
cmd VkResult vkQueueWaitIdle(
VkQueue queue) {
if !(queue in Queues) { vkErrorInvalidQueue(queue) }
Expand Down
2 changes: 1 addition & 1 deletion gapis/api/vulkan/api/synchronization.api
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ cmd VkResult vkGetFenceStatus(

@threadSafety("system")
@indirect("VkDevice")
@blocking
@threadsafe
cmd VkResult vkWaitForFences(
VkDevice device,
u32 fenceCount,
Expand Down
2 changes: 1 addition & 1 deletion gapis/api/vulkan/extensions/khr_swapchain.api
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ cmd VkResult vkGetSwapchainImagesKHR(
@extension("VK_KHR_swapchain")
@indirect("VkDevice")
@custom
@blocking
@threadsafe
cmd VkResult vkAcquireNextImageKHR(
VkDevice device,
VkSwapchainKHR swapchain,
Expand Down

0 comments on commit c974f65

Please sign in to comment.