Browse Source

[spirv] fix vector splat cast bug (#2249)

Fixes #2237
Jaebaek Seo 6 năm trước cách đây
mục cha
commit
e0c2567c0b

+ 1 - 1
tools/clang/lib/SPIRV/SpirvEmitter.cpp

@@ -5572,7 +5572,7 @@ SpirvInstruction *SpirvEmitter::createVectorSplat(const Expr *scalarExpr,
   if ((scalarVal = tryToEvaluateAsConst(scalarExpr))) {
     scalarVal->setRValue();
   } else {
-    scalarVal = doExpr(scalarExpr);
+    scalarVal = loadIfGLValue(scalarExpr);
   }
 
   if (!scalarVal || size == 1) {

+ 20 - 0
tools/clang/test/CodeGenSPIRV/cast.vector.splat.hlsl

@@ -2,6 +2,8 @@
 
 // CHECK: [[v4f32c:%\d+]] = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
 // CHECK: [[v3f32c:%\d+]] = OpConstantComposite %v3float %float_2 %float_2 %float_2
+// CHECK: [[v4fc_2:%\d+]] = OpConstantComposite %v4float %float_2 %float_2 %float_2 %float_2
+// CHECK: [[v4fc_3:%\d+]] = OpConstantComposite %v4float %float_3 %float_3 %float_3 %float_3
 
 void main() {
 // CHECK-LABEL: %bb_entry = OpLabel
@@ -33,4 +35,22 @@ void main() {
 // CHECK-NEXT: [[v3:%\d+]] = OpCompositeConstruct %v3int %int_3 %int_3 %int_3
 // CHECK-NEXT: OpStore %vi3 [[v3]]
     vi3 = int3(3.xxx);
+
+    float sf;
+
+// CHECK:         [[sf:%\d+]] = OpLoad %float %sf
+// CHECK-NEXT: [[sf_v4:%\d+]] = OpCompositeConstruct %v4float [[sf]] [[sf]] [[sf]] [[sf]]
+// CHECK-NEXT:                  OpStore %vf4_0 [[sf_v4]]
+    float4 vf4_0 = (sf, sf, sf, sf);
+
+// CHECK:         [[sf:%\d+]] = OpLoad %float %sf
+// CHECK-NEXT: [[sf_v4:%\d+]] = OpCompositeConstruct %v4float [[sf]] [[sf]] [[sf]] [[sf]]
+// CHECK-NEXT:                  OpStore %vf4 [[sf_v4]]
+    vf4 = (sf, sf, sf, sf);
+
+// CHECK: OpStore %vf4_1 [[v4fc_2]]
+    float4 vf4_1 = (2.0f, 2.0f, 2.0f, 2.0f);
+
+// CHECK: OpStore %vf4 [[v4fc_3]]
+    vf4 = (3.0f, 3.0f, 3.0f, 3.0f);
 }