Advertisement

Piepline barrier stage masks

Started by January 23, 2019 03:25 PM
1 comment, last by Cararasu 6 years ago

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!

 

Hi!

2 hours ago, Shnoutz said:

Regarding the stage masks; is it safe and efficient to "bit or" the stage flags?

Yes, that is the safest and most efficient way of doing it.

2 hours ago, Shnoutz said:

Should I modify my code to remove all the redundant bits?

No, you should not.

From the documentation of vkCmdPipelineBarrier:

Quote
  • Each element of pMemoryBarriers, pBufferMemoryBarriers and pImageMemoryBarriers must not have any access flag included in its srcAccessMask member if that bit is not supported by any of the pipeline stages in srcStageMask, as specified in the table of supported access types.

  • Each element of pMemoryBarriers, pBufferMemoryBarriers and pImageMemoryBarriers must not have any access flag included in its dstAccessMask member if that bit is not supported by any of the pipeline stages in dstStageMask, as specified in the table of supported access types.

Why this is enforced I am honestly not quite sure. The bottom-most stage should implicitly include all previous ones for the srcStageMask so forcing this seems a bit unnecessary to me. Maybe it has something to do with execution dependency chains as described in chapter 6.4(http://vulkan-spec-chunked.ahcox.com/ch06s04.html), but I am not sure.

This topic is closed to new replies.

Advertisement