Issue 184379
Summary [HLSL][Matrix] HLSLElementwiseCast to matrix does not respect default matrix memory layout
Labels clang:codegen, HLSL
Assignees
Reporter Icohedron
    HLSLElementwiseCast does not respect the default matrix memory layout

https://hlsl.godbolt.org/z/bzM839Mc9

```hlsl
// args: -T cs_6_8 /Zpr
RWBuffer<int3> Out : register(u1);

[numthreads(4,1,1)]
void main(uint GI : SV_GroupIndex) {
    int A[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
    int2x3 M = (int2x3)A;
    Out[0] = M[0];
    Out[1] = M[1];
}
```

Clang:
```llvm
define void @main() local_unnamed_addr #0 {
  %0 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 1, i32 1, i32 0, i8 1 }, i32 1, i1 false) #1, !dbg !105
  %1 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %0, %dx.types.ResourceProperties { i32 4106, i32 772 }) #1, !dbg !105
  call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %1, i32 0, i32 undef, i32 0, i32 3, i32 1, i32 0, i8 15), !dbg !125
  call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %1, i32 1, i32 undef, i32 4, i32 2, i32 5, i32 4, i8 15), !dbg !128
  ret void
```
Stores 0, 3, 1, 4, 2, 5 into the Out buffer.

DXC:
```llvm
define void @main() {
 %Out_UAV_buf = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 1, i32 1, i32 0, i8 1 }, i32 1, i1 false), !dbg !55
 %1 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %Out_UAV_buf, %dx.types.ResourceProperties { i32 4106, i32 772 }), !dbg !55
 call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %1, i32 0, i32 undef, i32 0, i32 1, i32 2, i32 0, i8 15), !dbg !73
  %2 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %Out_UAV_buf, %dx.types.ResourceProperties { i32 4106, i32 772 }), !dbg !74
 call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %2, i32 1, i32 undef, i32 3, i32 4, i32 5, i32 3, i8 15), !dbg !75
  ret void, !dbg !76
```
Stores 0, 1, 2, 3, 4, 5 into the Out buffer.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to