Renderpass storeop only reads the blue channel

I am trying to write the hello world triangle in Vulkan and I got a very weird bug with the renderpass. The render pass has one attachment, that has the load op VK_ATTACHMENT_LOAD_OP_CLEAR. The whole attachment description looks like this:

AttachmentDescription.flags = 0;
AttachmentDescription.format = format;
AttachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
AttachmentDescription.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
AttachmentDescription.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
AttachmentDescription.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
AttachmentDescription.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
AttachmentDescription.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
AttachmentDescription.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;

The only subpass in the renderpass looks like this:

SubpassDescription.flags = 0;
SubpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
SubpassDescription.inputAttachmentCount = 0;
SubpassDescription.pInputAttachments = nullptr;
SubpassDescription.colorAttachmentCount = 1;
SubpassDescription.pColorAttachments = &AttachmentReference;
SubpassDescription.pResolveAttachments = nullptr;
SubpassDescription.pDepthStencilAttachment = nullptr;
SubpassDescription.preserveAttachmentCount = 0;
SubpassDescription.pPreserveAttachments = nullptr;

The clear color looks like this:
VkClearColorValue clearColor = {};
clearColor.float32[0] = 1.0f;
clearColor.float32[1] = 0.0f;
clearColor.float32[2] = 1.0f;
clearColor.float32[3] = 1.0f;

Now, what I expect from this would be a magenta screen if the format is RGBA or something else, but regardless of what values I insert in R(clearColor.float32[0] = 1.0f), G(clearColor.float32[1] = 0.0f) and A(clearColor.float32[3] = 1.0f), the only value that is really aknowledged is B(clearColor.float32[2] = 1.0f). The blue color channel is fully acknowledged, I can slide from 1.0f to 0.0f and the output is correct. But the other 3 channels seem to don’t be used for the output. What am I doing wrong?

What’s your format exactly? Is it UNORM?

Common mistake is also to use an object past its lifetime or not wiring it in at all. Would have to see the actual code for that. Nevertheless make sure the clear color values are alive at least until the vkCmdBeginRenderPass() is called and returns.

1 Like

I figured it out. The problem was, that I was using the clear value union which is a union of VkClearColorValue and VkClearDepthStencilValue. I first set the VkClearColorValue and then the VkClearDepthValue. This has overriden the color values of the VkClearColorValue. I’d guess I just skimmed through the declaration and didn’t read the union keyword (and probably also didn’t expect it, but now as I looked it up in the spec it makes sense). I’m still not sure why it didn’t make the green channel visible, because this should’ve just overriden the red and green channel and green should’ve been 1.0f.
Still, thanks for the anwser.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.