HLSL Push Constants assigned to $Global

Hi everyone!

While translating Vulkan shaders from GLSL to HLSL, I ran into the following issue.
I defined a push constant struct in GLSL as follows:

layout (push_constant) uniform PushConsts {
    mat4 matrix;
} pushConsts;

The Vulkan High Level Shader Language Comparison recommends doing it as so for HLSL:

struct PushConsts {
    float4x4 matrix;
};
[[vk::push_constant]] PushConsts pushConsts;

However, this syntax ends up adding the pushConsts variable inside the $Global cbuffer, bound at set 0, index 0. In my case, the contents of matrix were being filled by another buffer that I bind at that location…

Looking online I found a post by Saalvage titled “HLSL Push Constant Offset”. The person used a different syntax, which fixed my problem, producing the same SPIR-V code for my new HLSL shaders as my old GLSL shaders.

[[vk::push_constant]]
cbuffer pushConsts {
    float4x4 matrix;
};

So my question is: why doesn’t the first approach work for me, could it be something to do with how I compile the shaders or is it reproducible for other people? If the first approach really is broken, why isn’t the second syntax explained instead?