浏览代码

[spirv] Fix crash if ControlPointID is missing. (#2568)

Ehsan 5 年之前
父节点
当前提交
34143cb26c

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

@@ -2160,7 +2160,7 @@ bool DeclResultIdMapper::createStageVars(
       // Special handling of HS ouput, for which we write to only one
       // element in the per-vertex data array: the one indexed by
       // SV_ControlPointID.
-      else if (invocationId.hasValue()) {
+      else if (invocationId.hasValue() && invocationId.getValue() != nullptr) {
         // Remove the arrayness to get the element type.
         assert(isa<ConstantArrayType>(evalType));
         const auto elementType =

+ 36 - 0
tools/clang/test/CodeGenSPIRV/semantic.output-control-point-id.hs.error.hlsl

@@ -0,0 +1,36 @@
+// Run: %dxc -T hs_6_0 -E main
+
+// CHECK: 32:11: error: SV_OutputControlPointID semantic must be provided in hull shader
+
+struct HS_QUAD_INPUT {
+	float2 Origin: TEXCOORD0;
+	float2 Size: TEXCOORD1;
+};
+
+struct HS_OUTPUT {
+	float Dummy : TEXCOORD0;
+};
+
+struct QUAD_PATCH_DATA {
+	float Edges[4]: SV_TessFactor;
+	float Inside[2]: SV_InsideTessFactor;
+
+	float2 Origin: TEXCOORD0;
+	float2 Size: TEXCOORD1;
+};
+
+
+QUAD_PATCH_DATA hsPatchConstant(InputPatch<HS_QUAD_INPUT, 1> Input) {
+	return (QUAD_PATCH_DATA)0;
+
+}
+[domain("quad")]
+[outputtopology("triangle_ccw")]
+[partitioning("fractional_odd")]
+[outputcontrolpoints(1)]
+[patchconstantfunc("hsPatchConstant")]
+HS_OUTPUT main(InputPatch<HS_QUAD_INPUT, 1> Input)
+{
+	return (HS_OUTPUT)0;
+}
+

+ 4 - 0
tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

@@ -701,6 +701,10 @@ TEST_F(FileTest, SemanticPrimitiveIdPS) {
 TEST_F(FileTest, SemanticOutputControlPointIdHS) {
   runFileTest("semantic.output-control-point-id.hs.hlsl");
 }
+TEST_F(FileTest, SemanticOutputControlPointIdHSError) {
+  runFileTest("semantic.output-control-point-id.hs.error.hlsl",
+              Expect::Failure);
+}
 TEST_F(FileTest, SemanticGSInstanceIDGS) {
   runFileTest("semantic.gs-instance-id.gs.hlsl");
 }