DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SPIR-V] ByteAddressBuffer can not get row-major matrix

Open MaxwellGengYF opened this issue 3 weeks ago • 1 comments

Compile this example with "-Zpr" which enable row-major matrix:

ByteAddressBuffer byte_buffer;
void foo() {
float4x4 matrix = byte_buffer.Load<float4x4>(id);
}

variable "matrix" is not treated as row-major matrix.

MaxwellGengYF avatar Nov 27 '25 14:11 MaxwellGengYF

To make this more concrete: https://godbolt.org/z/1Pn3Kf1jM.

ByteAddressBuffer byte_buffer;

RWBuffer<float> b;

void main() {
  float4x4 matrix = byte_buffer.Load<float4x4>(2);
  b[0] = matrix[2][3];
}

The access to the matrix could come from the byte_buffer as offset 11, that is (2 * 4 + 3). However, we generate:

         %18 = OpAccessChain %_ptr_Uniform_uint %byte_buffer %uint_0 %uint_14
         %19 = OpLoad %uint %18
         %20 = OpBitcast %float %19

We are getting 14, which is (3*4+2).

s-perron avatar Nov 28 '25 03:11 s-perron