If a color attachment is only used for presenting to the swapchain, can I set
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
or must I use VK_ATTACHMENT_STORE_OP_STORE?
I tested VK_ATTACHMENT_STORE_OP_DONT_CARE on macOS, and there seems to be no difference in rendering compared to using STORE.
The spec says:
“VK_ATTACHMENT_STORE_OP_DONT_CARE specifies the contents within the render area are not needed after rendering, and may be discarded.”
Does the present process happen within the render area, or is it considered outside, meaning DONT_CARE is unsafe for swapchain images?
“Don’t care” means “don’t care”. That is, it could be anything, but it may be nonsense. Using this means that you are not given any guarantees on what the data in the image will be after the render pass.
It may do the equivalent of a proper store. It may do the equivalent of a proper store, but only every other frame. It may do the equivalent of a proper store, except for during a full moon.
Unless you actually store what you’ve rendered, you cannot rely on the image containing the results of what you’ve actually rendered.
You cannot “guess and check” your way through Vulkan. Just because something happened to do what you expected, in your test, doesn’t mean that it can’t do something else. You need to follow what the standard actually says.
And the standard is clear that, if you want to read the data you wrote, you need to store it.
1 Like