[clang] [llvm] [VK][HLSL][SPIRV] Accept vk::builtin("PointSize") on pixel shader inputs (PR #243513)

Diego Novillo via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 27 12:44:45 PST 2026


================
@@ -2806,8 +2808,65 @@ void addInstrRequirements(const MachineInstr &MI,
                           SPIRV::Capability::Shader);
 }
 
+// Returns true if MF accesses a variable decorated BuiltIn PointSize.
+static bool accessesPointSize(const MachineFunction &MF) {
+  const MachineRegisterInfo &MRI = MF.getRegInfo();
+  for (const MachineBasicBlock &MBB : MF)
+    for (const MachineInstr &MI : MBB) {
+      if (MI.getOpcode() != SPIRV::OpDecorate ||
+          MI.getOperand(1).getImm() != SPIRV::Decoration::BuiltIn ||
+          MI.getOperand(2).getImm() != SPIRV::BuiltIn::PointSize)
+        continue;
+      for (const MachineInstr &User :
+           MRI.use_nodbg_instructions(MI.getOperand(0).getReg()))
+        if (User.getOpcode() != SPIRV::OpDecorate &&
+            User.getOpcode() != SPIRV::OpName)
+          return true;
+    }
+  return false;
+}
+
+// Vulkan allows BuiltIn PointSize only in the MeshEXT, MeshNV, Vertex,
+// TessellationControl, TessellationEvaluation and Geometry execution models
+// (VUID-PointSize-PointSize-04314), so the static call tree of a Fragment entry
+// point must not access it.
+static void checkFragmentPointSize(const Module &M,
+                                   MachineFunctionGetter GetMF) {
+  for (const Function &EntryF : M) {
+    // Pixel shaders become Fragment entry points.
+    if (EntryF.getFnAttribute("hlsl.shader").getValueAsString() != "pixel")
+      continue;
+
+    // Walk its static call tree and report the first function that accesses
+    // PointSize.
+    SmallPtrSet<const Function *, 8> Visited;
+    SmallVector<const Function *, 8> Worklist = {&EntryF};
+    while (!Worklist.empty()) {
+      const Function *F = Worklist.pop_back_val();
+      if (!Visited.insert(F).second)
+        continue;
+      if (const MachineFunction *MF = GetMF(*F); MF && accessesPointSize(*MF)) {
+        EntryF.getContext().diagnose(DiagnosticInfoUnsupported(
+            EntryF, "BuiltIn PointSize cannot be used in a Fragment entry "
+                    "point (VUID-PointSize-PointSize-04314)"));
+        break;
+      }
+
+      // Queue the defined functions called by F.
+      for (const Instruction &I : instructions(*F))
+        if (const auto *Call = dyn_cast<CallBase>(&I))
----------------
dnovillo wrote:

> Could you have a call that is in IR but that has been optimized away and it is not present in MIR/SPIRV?

Not really. Codegen removes unreachable blocks before ISel at every optimization level, and every call to a defined function becomes an `OpFunctionCall`, which has side effects, so later passes keep it. The walk follows the same calls that end up in the output.


https://github.com/llvm/llvm-project/pull/243513


More information about the cfe-commits mailing list