Browse Source

Set default input control point count to 1. (#1135)

Xiang Li 7 years ago
parent
commit
d66d48721f

+ 1 - 0
include/dxc/HLSL/DxilConstants.h

@@ -66,6 +66,7 @@ namespace DXIL {
   const unsigned kMaxIAPatchControlPointCount = 32;
   const float kHSMaxTessFactorLowerBound = 1.0f;
   const float kHSMaxTessFactorUpperBound = 64.0f;
+  const unsigned kHSDefaultInputControlPointCount = 1;
   const unsigned kMaxCSThreadsPerGroup = 1024;
   const unsigned kMaxCSThreadGroupX	= 1024;
   const unsigned kMaxCSThreadGroupY	= 1024;

+ 16 - 11
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

@@ -3975,6 +3975,22 @@ public:
     for (auto Iter : funcMap)
       replaceCall(Iter.first, Iter.second);
 
+    // Update patch constant function.
+    for (Function &F : M.functions()) {
+      if (F.isDeclaration())
+        continue;
+      if (!m_pHLModule->HasDxilFunctionProps(&F))
+        continue;
+      DxilFunctionProps &funcProps = m_pHLModule->GetDxilFunctionProps(&F);
+      if (funcProps.shaderKind == DXIL::ShaderKind::Hull) {
+        Function *oldPatchConstantFunc =
+            funcProps.ShaderProps.HS.patchConstantFunc;
+        if (funcMap.count(oldPatchConstantFunc))
+          funcProps.ShaderProps.HS.patchConstantFunc =
+              funcMap[oldPatchConstantFunc];
+      }
+    }
+
     // Remove flattened functions.
     for (auto Iter : funcMap) {
       Function *F = Iter.first;
@@ -6276,17 +6292,6 @@ void SROA_Parameter_HLSL::replaceCall(Function *F, Function *flatF) {
   if (F == m_pHLModule->GetEntryFunction()) {
     m_pHLModule->SetEntryFunction(flatF);
   }
-  // Update patch constant function.
-  if (m_pHLModule->HasDxilFunctionProps(flatF)) {
-    DxilFunctionProps &funcProps = m_pHLModule->GetDxilFunctionProps(flatF);
-    if (funcProps.shaderKind == DXIL::ShaderKind::Hull) {
-      Function *oldPatchConstantFunc =
-          funcProps.ShaderProps.HS.patchConstantFunc;
-      if (funcMap.count(oldPatchConstantFunc))
-        funcProps.ShaderProps.HS.patchConstantFunc =
-            funcMap[oldPatchConstantFunc];
-    }
-  }
   // TODO: flatten vector argument and lower resource argument when flatten
   // functions.
   for (auto it = F->user_begin(); it != F->user_end(); ) {

+ 1 - 0
tools/clang/lib/CodeGen/CGHLSLMS.cpp

@@ -1346,6 +1346,7 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) {
 
   if (isHS) {
     funcProps->ShaderProps.HS.maxTessFactor = DXIL::kHSMaxTessFactorUpperBound;
+    funcProps->ShaderProps.HS.inputControlPoints = DXIL::kHSDefaultInputControlPointCount;
   }
 
   if (const HLSLMaxTessFactorAttr *Attr =

+ 47 - 0
tools/clang/test/CodeGenHLSL/quick-test/NoInputPatchHs.hlsl

@@ -0,0 +1,47 @@
+// RUN: %dxc -E main -T hs_6_0  %s 2>&1 | FileCheck %s
+
+// Make sure input control point is not 0.
+// CHECK: !{void ()* @"\01?HSPerPatchFunc@@YA?AUHSPerPatchData@@XZ", i32 1
+
+
+struct HSPerPatchData
+{
+    // We at least have to specify tess factors per patch
+    // As we're tesselating triangles, there will be 4 tess factors
+    // In real life case this might contain face normal, for example
+	float	edges[3] : SV_TessFactor;
+	float	inside   : SV_InsideTessFactor;
+};
+
+
+
+// This overload is a patch constant function candidate because it has an
+// output with the SV_TessFactor semantic. However, the compiler should
+// *not* select it because there is another overload defined later in this
+// translation unit (which is the old compiler's behavior). If it did, then
+// the semantic checker will report an error due to this overload's input
+// having 32 elements (versus the expected 3).
+HSPerPatchData HSPerPatchFunc()
+{
+  HSPerPatchData d;
+
+  d.edges[0] = -5;
+  d.edges[1] = -6;
+  d.edges[2] = -7;
+  d.inside = -8;
+
+  return d;
+}
+
+
+
+// hull per-control point shader
+[domain("tri")]
+[partitioning("fractional_odd")]
+[outputtopology("triangle_cw")]
+[patchconstantfunc("HSPerPatchFunc")]
+[outputcontrolpoints(3)]
+void main( const uint id : SV_OutputControlPointID )
+{
+}
+