Skip to content

Commit 3e46e22

Browse files
authored
[SPIR-V] Handle vector element assignment for asuint. (#8011)
We need to consider the case where the destination for `asuint` is a vector swizzle. Fixes #7666
1 parent b678d82 commit 3e46e22

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12556,8 +12556,6 @@ SpirvEmitter::processIntrinsicAsType(const CallExpr *callExpr) {
1255612556
const Expr *arg2 = callExpr->getArg(2);
1255712557

1255812558
SpirvInstruction *value = doExpr(arg0);
12559-
SpirvInstruction *lowbits = doExpr(arg1);
12560-
SpirvInstruction *highbits = doExpr(arg2);
1256112559

1256212560
QualType elemType = QualType();
1256312561
uint32_t rowCount = 0;
@@ -12580,9 +12578,8 @@ SpirvEmitter::processIntrinsicAsType(const CallExpr *callExpr) {
1258012578
return nullptr;
1258112579
}
1258212580

12583-
spvBuilder.createStore(lowbits, lowbitsResult, loc, range);
12584-
spvBuilder.createStore(highbits, highbitsResult, loc, range);
12585-
12581+
processAssignment(arg1, lowbitsResult, false, nullptr, range);
12582+
processAssignment(arg2, highbitsResult, false, nullptr, range);
1258612583
return nullptr;
1258712584
}
1258812585
default:

tools/clang/test/CodeGenSPIRV/intrinsics.asuint.hlsl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,33 @@ void main() {
106106
// CHECK-NEXT: OpStore %highbits3 [[high]]
107107
asuint(value3, lowbits3, highbits3);
108108

109+
double4 value4;
110+
uint4 lowbits4;
111+
uint4 highbits4;
112+
// CHECK-NEXT: [[value:%[0-9]+]] = OpLoad %v4double %value4
113+
// CHECK-NEXT: [[shuffle0:%[0-9]+]] = OpVectorShuffle %v3double [[value]] [[value]] 0 1 2
114+
// CHECK-NEXT: [[value0:%[0-9]+]] = OpCompositeExtract %double [[shuffle0]] 0
115+
// CHECK-NEXT: [[resultVec0:%[0-9]+]] = OpBitcast %v2uint [[value0]]
116+
// CHECK-NEXT: [[low0:%[0-9]+]] = OpCompositeExtract %uint [[resultVec0]] 0
117+
// CHECK-NEXT: [[high0:%[0-9]+]] = OpCompositeExtract %uint [[resultVec0]] 1
118+
// CHECK-NEXT: [[value1:%[0-9]+]] = OpCompositeExtract %double [[shuffle0]] 1
119+
// CHECK-NEXT: [[resultVec1:%[0-9]+]] = OpBitcast %v2uint [[value1]]
120+
// CHECK-NEXT: [[low1:%[0-9]+]] = OpCompositeExtract %uint [[resultVec1]] 0
121+
// CHECK-NEXT: [[high1:%[0-9]+]] = OpCompositeExtract %uint [[resultVec1]] 1
122+
// CHECK-NEXT: [[value2:%[0-9]+]] = OpCompositeExtract %double [[shuffle0]] 2
123+
// CHECK-NEXT: [[resultVec2:%[0-9]+]] = OpBitcast %v2uint [[value2]]
124+
// CHECK-NEXT: [[low2:%[0-9]+]] = OpCompositeExtract %uint [[resultVec2]] 0
125+
// CHECK-NEXT: [[high2:%[0-9]+]] = OpCompositeExtract %uint [[resultVec2]] 1
126+
// CHECK-NEXT: [[lowConstruct:%[0-9]+]] = OpCompositeConstruct %v3uint [[low0]] [[low1]] [[low2]]
127+
// CHECK-NEXT: [[highConstruct:%[0-9]+]] = OpCompositeConstruct %v3uint [[high0]] [[high1]] [[high2]]
128+
// CHECK-NEXT: [[loadedLow:%[0-9]+]] = OpLoad %v4uint %lowbits4
129+
// CHECK-NEXT: [[finalLow:%[0-9]+]] = OpVectorShuffle %v4uint [[loadedLow]] [[lowConstruct]] 4 5 6 3
130+
// CHECK-NEXT: OpStore %lowbits4 [[finalLow]]
131+
// CHECK-NEXT: [[loadedHigh:%[0-9]+]] = OpLoad %v4uint %highbits4
132+
// CHECK-NEXT: [[finalHigh:%[0-9]+]] = OpVectorShuffle %v4uint [[loadedHigh]] [[highConstruct]] 4 5 6 3
133+
// CHECK-NEXT: OpStore %highbits4 [[finalHigh]]
134+
asuint(value4.xyz, lowbits4.xyz, highbits4.xyz);
135+
109136
double2x2 value2x2;
110137
uint2x2 lowbits2x2;
111138
uint2x2 highbits2x2;

0 commit comments

Comments
 (0)