Hello,
Because vkCmdPipelineBarrier allows to submit multiple barriers at once I decided to expose its functionalities through 4 functions:
- CmdBuffer::queueMemoryBarrier(VkMemoryBarrier barrier, VkPipelineStageFlagBit srcStageMask, VkPipelineStageFlagBit dstStageMask)
- CmdBuffer::queueImageMemoryBarrier(VkImageMemoryBarrier barrier, VkPipelineStageFlagBit srcStageMask, VkPipelineStageFlagBit dstStageMask)
- CmdBuffer::queueBufferMemoryBarrier(VkBufferMemoryBarrier barrier, VkPipelineStageFlagBit srcStageMask, VkPipelineStageFlagBit dstStageMask)
- CmdBuffer::flushPipelineBarriers() // calls vkCmdPipelineBarrier
The CmdBuffer::queueXXX functions add the barriers passed in parameter to temporary arrays in the CmdBuffer object and also "augment" (bit or) source and destination stage masks members in the CmdBuffer object.
-----------
Using it looks like this:
- cmds.queueImageMemoryBarrier(imageMemoryBarrier, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT)
- ...
- cmds.queueBufferMemoryBarrier(imageMemoryBarrier, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT)
- ...
- cmds.flushPipelineBarriers()
Regarding the stage masks; is it safe and efficient to "bit or" the stage flags?
From the code just above, CmdBuffer::m_srcStageMask ends up being equal to VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT when Cmd::Buffer::flushPipelineBarrier is called.
The fragment stage happens-after "top of pipe".. Isn't the "top of pipe" bit is redundant as source stage bit in this case? Should I modify my code to remove all the redundant bits?
Thanks!