Issue 184371
Summary [HLSL][Matrix] Matrix truncation produces incorrect results in some cases
Labels HLSL
Assignees
Reporter Icohedron
    In some cases matrix truncation produces incorrect results, particularly with truncations to non-square matrices

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

```hlsl
// args: -T cs_6_8
RWBuffer<int> In : register(u0);
RWBuffer<int> Out : register(u1);

[numthreads(4,1,1)]
void main(uint GI : SV_GroupIndex) {
 int2x2 A = {0, 1, 2, 3};
    // 0 1
    // 2 3
    int2x1 B = (int2x1)A;
    Out[0] = B[0][0]; // 0
    Out[1] = B[1][0]; // 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 !111
  %1 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %0, %dx.types.ResourceProperties { i32 4106, i32 260 }) #1, !dbg !111
  call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %1, i32 0, i32 undef, i32 0, i32 0, i32 0, i32 0, i8 15), !dbg !131
  call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %1, i32 1, i32 undef, i32 1, i32 1, i32 1, i32 1, i8 15), !dbg !134 ; <-- stores a 1
  ret void
```

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 !44
  %1 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %Out_UAV_buf, %dx.types.ResourceProperties { i32 4106, i32 260 }), !dbg !44
 call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %1, i32 0, i32 undef, i32 0, i32 0, i32 0, i32 0, i8 15), !dbg !59
  %2 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %Out_UAV_buf, %dx.types.ResourceProperties { i32 4106, i32 260 }), !dbg !60
 call void @dx.op.bufferStore.i32(i32 69, %dx.types.Handle %2, i32 1, i32 undef, i32 2, i32 2, i32 2, i32 2, i8 15), !dbg !61 ; <-- stores a 2
  ret void, !dbg !62
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to