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

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

Closed
leafspr1ng opened this issue Nov 19, 2024 · 5 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.

@leafspr1ng
Copy link
Author

One small addendum I just noticed: The code from above (minus the depth/stencil info) does create a black clear on Windows as expected. However, the same code seems to create a transparent clear instead on MacOS.

Probably something related to MoltenVK and also probably wrong usage somewhere on my part again but I figured I mention it in case somebody else stumbles upon this topic. :)

(if I figure out where the difference comes from, I'll update here)

@leafspr1ng leafspr1ng changed the title Setting a ClearValue that includes ClearColorValue and ClearDepthStencilValue has weird effects [Vulkan] Setting a ClearValue that includes ClearColorValue and ClearDepthStencilValue has weird effects Nov 25, 2024
@Perksey
Copy link
Member

Perksey commented Nov 25, 2024

Ok, I’m closing this though as Silk.NET seems to be doing everything right here. Feel free to reopen if there is a C vs C# discrepancy though.

@Perksey Perksey closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants