glslang icon indicating copy to clipboard operation
glslang copied to clipboard

Wrong ArrayStride when using HLSL rules for block offsets

Open vmilea opened this issue 2 years ago • 0 comments

When compiling a GLSL shader with --hlsl-offsets, glslang adjusts offsets as expected. However, the tighter packing isn't accounted for in ArrayStride.

#version 460

struct Vertex {
    float a;
    vec2 position;
    float b;
};

layout(std430, set = 0, binding = 0) readonly buffer Vertices {
    Vertex vertices[];
} buf;

layout(location = 0) out vec2 vPosition;

void main() {
    vec2 position = buf.vertices[gl_VertexIndex].position;
    gl_Position = vec4(position, 0.0, 1.0);
} 

compiles to:

OpMemberDecorate %Vertex 0 Offset 0
OpMemberDecorate %Vertex 1 Offset 4
OpMemberDecorate %Vertex 2 Offset 12
OpDecorate %_runtimearr_Vertex ArrayStride 24

Here the offsets are correct, but ArrayStride should be 16.

vmilea avatar Sep 28 '23 09:09 vmilea