Friday, May 17, 2024
HomeGame DevelopmentIssues with binding structure layout in the shaders which translated from glsl...

Issues with binding structure layout in the shaders which translated from glsl to hlsl


I have a small issue with my shaders. Sorry if it is not the right place for this question. In general, the essence is that for my application on dx12, I have shaders in glsl (I’m too lazy to rewrite them because there are many, and they are not only for dx12), and I compile them into hlsl using spirv-cross (I get approximately what I expect). My problem is as follows: I don’t quite understand how to correctly set up the layout for bindings in shaders. If the binding is just a structure, everything is fine. But if it’s an array of structures, everything breaks. On the C++ side, all my structures are aligned (alignas(16)).

For example, I have a binding, in hlsl it looks like this:

struct vert_in
{
    float4 Pos;
    float4 Tangent;
    float4 Bitangent;
    float2 TexPos;
    uint Normal;
};
ByteAddressBuffer _41 : register(t1, space0); // This is where vert_in is being used

Initially vert_in was used by storage buffer, so it was using std430 layout.
I’ve tried adding paddings (for example, added one uint in the example with vert_in), but it didn’t really help.
When I added paddings to all array of structures bindings,it happened that nothing rendered at all. Apparently, in vulkan/glsl everything working is fine.
Either I don’t understand something, or I’m just doing it wrong. I tried adding paddings, but I guess, it’s not the right approach.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments