HLSL Push Constant Offset

Hello everyone!
I am trying to write a Vulkan renderer, I use glslangValidator with HLSL for shaders and am trying to implement push constants.

[[vk::push_constant]]
cbuffer cbFragment {
    float4 imageColor;
    float4 aaaa;
};
 
[[vk::push_constant]]
cbuffer cbMatrices {
    float4 bbbb;
};

The annotation “[[vk::push_constant]]” works, I use spirv_reflect for reflection and both push constants show up and they work as intended.
The problem I’m having is that they seemingly overlap, if I assign “bbbb” a value, “imageColor” is affected in exactly the same way and vice versa. In the reflection data both push constant blocks have the offset 0, which explains the issue. However, I seem to be completely unable to change the offset of either of the push constants.
[[vk::offset(x)]] does not work at all, it neither affects the individual member offsets nor the offset of the push constants. The only offset that works at all is HLSL’s built in “packoffset”, which only applies to the buffer members. And although it might actually be a solution to just offset the members of one of the push constants to be outside the range of the other, I hardly believe that can be a sensible solution as it’s also causing the validation layer to fail because offsetting the individual member simply increases the size of the push constant unnecessarily and the overlap itself is still present.

I would greatly appreciate any help on this matter and am willing to provide any necessary clarification, thank you very much!

I got a solution!
Only a single [[vk::push_constant]] annotation is meant to exist per shader.

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