[Vulkan] Setting a ClearValue that includes ClearColorValue and ClearDepthStencilValue has weird effects
leafspr1ng opened this issue · 5 comments
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.
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
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...
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.
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)
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.