Browse Source

Fix dynamic indexed row_major matrix from cbuffer (#1643)

Tex Riddell 6 years ago
parent
commit
a81fa03444

+ 2 - 2
lib/HLSL/HLOperationLower.cpp

@@ -5617,9 +5617,9 @@ void TranslateCBAddressUserLegacy(Instruction *user, Value *handle,
           Value *cCol = ConstantInt::get(idx->getType(), col);
           idx = Builder.CreateUDiv(idx, cCol);
           idx = Builder.CreateAdd(idx, legacyIdx);
-          // Just return a row.
+          // Just return a row; 'col' is the number of columns in the row.
           ldData = GenerateCBLoadLegacy(handle, idx, /*channelOffset*/ 0, EltTy,
-                                        row, hlslOP, Builder);
+                                        col, hlslOP, Builder);
         }
         if (!resultType->isVectorTy()) {
           ldData = Builder.CreateExtractElement(ldData, Builder.getInt32(0));

+ 20 - 0
tools/clang/test/CodeGenHLSL/quick-test/mat_row_dyn_cb.hlsl

@@ -0,0 +1,20 @@
+// RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
+
+// One row should be 4 elements, loaded into array for component indexing
+// CHECK: alloca [4 x i32]
+
+cbuffer C
+{
+    row_major int3x4 m;
+};
+
+RWStructuredBuffer<int> output;
+
+[shader("compute")]
+[numthreads(12,1,1)]
+void main(uint3 tid : SV_DispatchThreadID)
+{
+    uint i = tid.x;
+
+    output[i] = m[i / 4][i % 4];
+}