2
0
Эх сурвалжийг харах

[spirv] Use entry point attr to find correct PCF. (#1024)

Ehsan 7 жил өмнө
parent
commit
dd487ffec7

+ 8 - 3
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -486,9 +486,6 @@ void SPIRVEmitter::HandleTranslationUnit(ASTContext &context) {
       if (funcDecl->getName() == entryFunctionName) {
         workQueue.insert(funcDecl);
       }
-      if (context.IsPatchConstantFunctionDecl(funcDecl)) {
-        patchConstFunc = funcDecl;
-      }
     } else {
       // If ignoring unused resources, defer Decl handling inside
       // TranslationUnit to the time of first referencing.
@@ -7863,6 +7860,14 @@ bool SPIRVEmitter::processTessellationShaderAttributes(
                                 spv::ExecutionMode::OutputVertices,
                                 {*numOutputControlPoints});
   }
+  if (auto *pcf = decl->getAttr<HLSLPatchConstantFuncAttr>()) {
+    llvm::StringRef pcf_name = pcf->getFunctionName();
+    for (auto *decl : astContext.getTranslationUnitDecl()->decls())
+      if (auto *funcDecl = dyn_cast<FunctionDecl>(decl))
+        if (astContext.IsPatchConstantFunctionDecl(funcDecl) &&
+            funcDecl->getName() == pcf_name)
+          patchConstFunc = funcDecl;
+  }
 
   return true;
 }

+ 14 - 0
tools/clang/test/CodeGenSPIRV/hs.pcf.input-patch.hlsl

@@ -27,6 +27,20 @@ HS_CONSTANT_DATA_OUTPUT PCF(InputPatch<VS_CONTROL_POINT_OUTPUT, MAX_POINTS> ip)
   return Output;
 }
 
+// Note: This second patch constant function is placed here, but should not be used
+// because the "patchconstantfunc" attribute does not point to this function.
+HS_CONSTANT_DATA_OUTPUT PCF_2(InputPatch<VS_CONTROL_POINT_OUTPUT, MAX_POINTS> ip) {
+  HS_CONSTANT_DATA_OUTPUT Output;
+  // Must initialize Edges and Inside; otherwise HLSL validation will fail.
+  Output.Edges[0]  = 2.0;
+  Output.Edges[1]  = 3.0;
+  Output.Edges[2]  = 4.0;
+  Output.Edges[3]  = 5.0;
+  Output.Inside[0] = 6.0;
+  Output.Inside[1] = 7.0;
+  return Output;
+}
+
 [domain("isoline")]
 [partitioning("fractional_odd")]
 [outputtopology("line")]