Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a ClearValue that includes ClearColorValue and ClearDepthStencilValue has weird effects #2360

Open
leafspr1ng opened this issue Nov 19, 2024 · 3 comments

Comments

@leafspr1ng
Copy link

leafspr1ng commented Nov 19, 2024

I'm not sure if this is an actual issue or I am using the structs wrong.

What I am doing is the following, which should lead to a black clear:

var clearValue = new ClearValue()
 {
     Color = new ClearColorValue()
     {
         Float32_0 = 0,
         Float32_1 = 0,
         Float32_2 = 0,
         Float32_3 = 1,
     },

     DepthStencil = new ClearDepthStencilValue()
     {
         Depth = 1.0f,
         Stencil = 0
     }
 };

However, the clear is red and the only way to get it to actually be whatever color is specified in the ClearColorValue is to remove the depth/stencil part. Looking into the Silk structs, I noticed the field offsets do seem odd, as in: They are both 0, so it might end up in arbitrary order when copied?

/// <summary></summary>
        [FieldOffset(0)]
        [NativeName("Type", "VkClearColorValue")]
        [NativeName("Type.Name", "VkClearColorValue")]
        [NativeName("Name", "color")]
        public ClearColorValue Color;
/// <summary></summary>
        [FieldOffset(0)]
        [NativeName("Type", "VkClearDepthStencilValue")]
        [NativeName("Type.Name", "VkClearDepthStencilValue")]
        [NativeName("Name", "depthStencil")]
        public ClearDepthStencilValue DepthStencil;

Again, not sure if this is actually an issue or the ClearValue is supposed to only be used with an either/or approach.

@Perksey
Copy link
Member

Perksey commented Nov 20, 2024

This is correct. ClearValue should be used to clear one attachment i.e. a color attachment or a depth/stencil attachment. When you begin your render pass you can pass in multiple of these values, intended to correspond with the respective attachments.

More info: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkRenderPassBeginInfo.html

@leafspr1ng
Copy link
Author

That makes a lot of sense and I probably should have read the spec more carefully. :)

The fact that Silk technically does not behave according to spec (values are ignored vs. their presence breaks the intended behavior) is probably acceptable in this case and more of a known idiosyncrasy than something to waste effort on...

@Perksey
Copy link
Member

Perksey commented Nov 20, 2024

It's a union so writes to Color will overwrite values in DepthStencil - equivalent C code behaves the same way. The spec wording is interesting here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants