[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:42: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(
----------------
dnovillo wrote:
> I did a quick check and it seems that there is a `reportUnsupported` function that already does this and reports the line number if available.
Thanks, done. I changed it to return the use instead of a boolean. It now reports errors using `reportUnsupported`. HLSL errors still don't get a line, though, because Clang emits the entry point's input loads without a debug location.
https://github.com/llvm/llvm-project/pull/243513
More information about the cfe-commits
mailing list