Jump to content
  • Advertisement
Sign in to follow this  
alek314??

DX12 vulkan barrier initial state confusion

This topic is 498 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi!

vkCmdPipelineBarrier needs srcStageMask and srcAccessMask, what should be the initial value for these parameters right after a resource is created? In DirectX 12, you can specify initial state for resources, what about vulkan?

Share this post


Link to post
Share on other sites
Advertisement

you can also provide an initial state (member of VkImageCreateInfo) but it has to be VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED.

Share this post


Link to post
Share on other sites
The pipeline stage doesn't have anything to do with resource initial state. Pipeline barrier allows to change for example image layout but it's up to you to decide how and when you are going to use the resource. For example, a newly created image with bound memory must make sure that all the writes and reads already happened before you try to change the layout. The safest place ( but usually least optimal )  is going to be a top of the pipeline for both - source and destination stages, as you may want to use this resource for example as sampled image. But again it depends on when and how you use your resource in the pipeline. To understand barriers you may think of it as "all the access operation must complete before source stage(s) to perform access operations after destination stage(s)". If we continue the example of image layout transition, usually the source stage for the new image is top of the pipeline ( regardless if the old layout is preinitialized or undefined ). The source access usually stays empty for uninitialized layout ( the data is undefined, no read and writes will occur at this point ). If your image is preinitialized you are going probably to write the data, so host write access must be complete before layout transition will happen. Those layouts are useless anywhere in the pipeline, so we use top of the pipeline as the source stage. Now depends on what you want to do next. If for example, you want to turn your image into the color attachment, then your destination stage mask will include color attachment output bit and access mask will include color attachment read and write bits. However, if you want to sample image in the shader, you need to perform transition earlier ( for example your new layout is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL ). The stage mask should include all stages that may try to sample your image ( so mostly all shading stages ). Destination access flag would include shader read bit as that's the only operation that may happen after layout change.
 
I'm not sure if it's clear enough. I used image resource as the example although mind that barriers are a lot more complex in terms of what and how they synchronise. The example above is a simplification of the concept to help you understand what stages and access masks are.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!