From 6f15e7c2f89680d8c7b178b78e74224ec870dfaa Mon Sep 17 00:00:00 2001 From: Cassandra Beckley Date: Mon, 14 Oct 2024 21:01:58 -0700 Subject: [PATCH] Fix handling of rows and columns --- tools/clang/lib/SPIRV/SpirvEmitter.cpp | 6 +-- .../test/CodeGenSPIRV/intrinsics.asuint.hlsl | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/tools/clang/lib/SPIRV/SpirvEmitter.cpp b/tools/clang/lib/SPIRV/SpirvEmitter.cpp index fc33d02d90..3cbed75f22 100644 --- a/tools/clang/lib/SPIRV/SpirvEmitter.cpp +++ b/tools/clang/lib/SPIRV/SpirvEmitter.cpp @@ -11465,13 +11465,13 @@ void SpirvEmitter::splitDoubleMatrix(QualType elemType, uint32_t rowCount, llvm::SmallVector lowElems; llvm::SmallVector highElems; - QualType colType = astContext.getExtVectorType(elemType, rowCount); + QualType colType = astContext.getExtVectorType(elemType, colCount); const QualType uintType = astContext.UnsignedIntTy; const QualType outputColType = - astContext.getExtVectorType(uintType, rowCount); + astContext.getExtVectorType(uintType, colCount); - for (uint32_t i = 0; i < colCount; ++i) { + for (uint32_t i = 0; i < rowCount; ++i) { SpirvInstruction *column = spvBuilder.createCompositeExtract(colType, value, {i}, loc, range); SpirvInstruction *lowbitsResult = nullptr; diff --git a/tools/clang/test/CodeGenSPIRV/intrinsics.asuint.hlsl b/tools/clang/test/CodeGenSPIRV/intrinsics.asuint.hlsl index 3c7dd6083b..3f84a4970f 100644 --- a/tools/clang/test/CodeGenSPIRV/intrinsics.asuint.hlsl +++ b/tools/clang/test/CodeGenSPIRV/intrinsics.asuint.hlsl @@ -137,4 +137,47 @@ void main() { // CHECK-NEXT: OpStore %lowbits2x2 [[low]] // CHECK-NEXT: OpStore %highbits2x2 [[high]] asuint(value2x2, lowbits2x2, highbits2x2); + + double3x2 value3x2; + uint3x2 lowbits3x2; + uint3x2 highbits3x2; +// CHECK-NEXT: [[value:%[0-9]+]] = OpLoad %mat3v2double %value3x2 +// CHECK-NEXT: [[row0:%[0-9]+]] = OpCompositeExtract %v2double [[value]] 0 +// CHECK-NEXT: [[value0:%[0-9]+]] = OpCompositeExtract %double [[row0]] 0 +// CHECK-NEXT: [[resultVec0:%[0-9]+]] = OpBitcast %v2uint [[value0]] +// CHECK-NEXT: [[low0:%[0-9]+]] = OpCompositeExtract %uint [[resultVec0]] 0 +// CHECK-NEXT: [[high0:%[0-9]+]] = OpCompositeExtract %uint [[resultVec0]] 1 +// CHECK-NEXT: [[value1:%[0-9]+]] = OpCompositeExtract %double [[row0]] 1 +// CHECK-NEXT: [[resultVec1:%[0-9]+]] = OpBitcast %v2uint [[value1]] +// CHECK-NEXT: [[low1:%[0-9]+]] = OpCompositeExtract %uint [[resultVec1]] 0 +// CHECK-NEXT: [[high1:%[0-9]+]] = OpCompositeExtract %uint [[resultVec1]] 1 +// CHECK-NEXT: [[lowRow0:%[0-9]+]] = OpCompositeConstruct %v2uint [[low0]] [[low1]] +// CHECK-NEXT: [[highRow0:%[0-9]+]] = OpCompositeConstruct %v2uint [[high0]] [[high1]] +// CHECK-NEXT: [[row1:%[0-9]+]] = OpCompositeExtract %v2double [[value]] 1 +// CHECK-NEXT: [[value2:%[0-9]+]] = OpCompositeExtract %double [[row1]] 0 +// CHECK-NEXT: [[resultVec2:%[0-9]+]] = OpBitcast %v2uint [[value2]] +// CHECK-NEXT: [[low2:%[0-9]+]] = OpCompositeExtract %uint [[resultVec2]] 0 +// CHECK-NEXT: [[high2:%[0-9]+]] = OpCompositeExtract %uint [[resultVec2]] 1 +// CHECK-NEXT: [[value3:%[0-9]+]] = OpCompositeExtract %double [[row1]] 1 +// CHECK-NEXT: [[resultVec3:%[0-9]+]] = OpBitcast %v2uint [[value3]] +// CHECK-NEXT: [[low3:%[0-9]+]] = OpCompositeExtract %uint [[resultVec3]] 0 +// CHECK-NEXT: [[high3:%[0-9]+]] = OpCompositeExtract %uint [[resultVec3]] 1 +// CHECK-NEXT: [[lowRow1:%[0-9]+]] = OpCompositeConstruct %v2uint [[low2]] [[low3]] +// CHECK-NEXT: [[highRow1:%[0-9]+]] = OpCompositeConstruct %v2uint [[high2]] [[high3]] +// CHECK-NEXT: [[row2:%[0-9]+]] = OpCompositeExtract %v2double [[value]] 2 +// CHECK-NEXT: [[value4:%[0-9]+]] = OpCompositeExtract %double [[row2]] 0 +// CHECK-NEXT: [[resultVec4:%[0-9]+]] = OpBitcast %v2uint [[value4]] +// CHECK-NEXT: [[low4:%[0-9]+]] = OpCompositeExtract %uint [[resultVec4]] 0 +// CHECK-NEXT: [[high4:%[0-9]+]] = OpCompositeExtract %uint [[resultVec4]] 1 +// CHECK-NEXT: [[value5:%[0-9]+]] = OpCompositeExtract %double [[row2]] 1 +// CHECK-NEXT: [[resultVec5:%[0-9]+]] = OpBitcast %v2uint [[value5]] +// CHECK-NEXT: [[low5:%[0-9]+]] = OpCompositeExtract %uint [[resultVec5]] 0 +// CHECK-NEXT: [[high5:%[0-9]+]] = OpCompositeExtract %uint [[resultVec5]] 1 +// CHECK-NEXT: [[lowRow2:%[0-9]+]] = OpCompositeConstruct %v2uint [[low4]] [[low5]] +// CHECK-NEXT: [[highRow2:%[0-9]+]] = OpCompositeConstruct %v2uint [[high4]] [[high5]] +// CHECK-NEXT: [[low:%[0-9]+]] = OpCompositeConstruct %_arr_v2uint_uint_3 [[lowRow0]] [[lowRow1]] [[lowRow2]] +// CHECK-NEXT: [[high:%[0-9]+]] = OpCompositeConstruct %_arr_v2uint_uint_3 [[highRow0]] [[highRow1]] [[highRow2]] +// CHECK-NEXT: OpStore %lowbits3x2 [[low]] +// CHECK-NEXT: OpStore %highbits3x2 [[high]] + asuint(value3x2, lowbits3x2, highbits3x2); }