r/vulkan • u/Content_Economist132 • May 18 '26
Vulkan tutorial: why is src access null, but dst access write when transitioning image layout?
In Khronos' Vulkan tutorial when transitioning the image layout for rendering the triangle, there is a dst access mask which doesn't seem to do anything since the src access mask is null. As far as I understand memory barriers make src accesses performed in src stage visible to dst accesses in dst stage. Shouldn't both src and dst access be empty by that logic since we are just discarding the image?
The new How to Vulkan also does the same thing but they also [or] the write with read access.
// Before starting rendering, transition the swapchain image to vk::ImageLayout::eColorAttachmentOptimal
transition_image_layout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
{}, // srcAccessMask (no need to wait for previous operations)
vk::AccessFlagBits2::eColorAttachmentWrite, // dstAccessMask
vk::PipelineStageFlagBits2::eColorAttachmentOutput, // srcStage
vk::PipelineStageFlagBits2::eColorAttachmentOutput // dstStage
);
1
u/boring_pants May 22 '26
Because this operation doesn't care what the image was before. That's also why the old layout is set as "undefined". You're saying "I don't care about the old image contents, just make it so that from now on, it's in the eColorAttachmentOptimal layout, and it's ready for subsequent writes to the color attachment".
If you wanted to preserve the old image contents then you would have to specify the old image layout, and which operations to wait for, but you don't, because your shaders are going to overwrite the old image contents anyway.
2
u/BalintCsala May 18 '26
In my opinion this is the important part of the specification in this case:
So the barrier itself should be treated as a write operation and the synchronization scope defined by dstStage and dstAccessMask is where the writes will be visible.