diff --git a/lib/HLSL/HLOperationLower.cpp b/lib/HLSL/HLOperationLower.cpp index 6f1e1e4765..e3166efd69 100644 --- a/lib/HLSL/HLOperationLower.cpp +++ b/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)); diff --git a/tools/clang/test/CodeGenHLSL/quick-test/mat_row_dyn_cb.hlsl b/tools/clang/test/CodeGenHLSL/quick-test/mat_row_dyn_cb.hlsl new file mode 100644 index 0000000000..fbf2b2a31e --- /dev/null +++ b/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 output; + +[shader("compute")] +[numthreads(12,1,1)] +void main(uint3 tid : SV_DispatchThreadID) +{ + uint i = tid.x; + + output[i] = m[i / 4][i % 4]; +}