[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:46:29 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))
+ if (const Function *Callee = Call->getCalledFunction();
+ Callee && !Callee->isDeclaration())
+ Worklist.push_back(Callee);
+ }
+ }
+}
+
static void collectReqs(const Module &M, SPIRV::ModuleAnalysisInfo &MAI,
MachineFunctionGetter GetMF, const SPIRVSubtarget &ST) {
+ if (ST.isShader())
----------------
dnovillo wrote:
> I'm not familiar with shaders but should we also check that it is vulkan?
`isShader()` implies that, yeah. Only the Vulkan triple gets this.
https://github.com/llvm/llvm-project/pull/243513
More information about the cfe-commits
mailing list