From 8a9d4add0b6cb9b4a71b414ad4671194a921173b Mon Sep 17 00:00:00 2001 From: Tex Riddell Date: Mon, 29 Oct 2018 19:53:59 -0700 Subject: [PATCH 1/2] Fix dynamic indexed row_major matrix from cbuffer --- lib/HLSL/HLOperationLower.cpp | 2 +- .../quick-test/mat_row_dyn_cb.hlsl | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tools/clang/test/CodeGenHLSL/quick-test/mat_row_dyn_cb.hlsl diff --git a/lib/HLSL/HLOperationLower.cpp b/lib/HLSL/HLOperationLower.cpp index 6f1e1e4765..4092e0bccb 100644 --- a/lib/HLSL/HLOperationLower.cpp +++ b/lib/HLSL/HLOperationLower.cpp @@ -5619,7 +5619,7 @@ void TranslateCBAddressUserLegacy(Instruction *user, Value *handle, idx = Builder.CreateAdd(idx, legacyIdx); // Just return a 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]; +} From ee0fc9100cb0edc9fcb497eaee9f3f2a7b1d42f0 Mon Sep 17 00:00:00 2001 From: Tex Riddell Date: Tue, 30 Oct 2018 11:31:42 -0700 Subject: [PATCH 2/2] Update comment to make use of 'col' clear. --- lib/HLSL/HLOperationLower.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/HLSL/HLOperationLower.cpp b/lib/HLSL/HLOperationLower.cpp index 4092e0bccb..e3166efd69 100644 --- a/lib/HLSL/HLOperationLower.cpp +++ b/lib/HLSL/HLOperationLower.cpp @@ -5617,7 +5617,7 @@ 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, col, hlslOP, Builder); }