Skip to content

[SPIR-V] Replace pixel shader SV_CullPrimitive inputs with 0 - #9088

Open
Abir Deol (apollo-2006) wants to merge 5 commits into
microsoft:mainfrom
apollo-2006:spirv-cullprimitive-psin
Open

Abir Deol (apollo-2006) wants to merge 5 commits into
microsoft:mainfrom
apollo-2006:spirv-cullprimitive-psin

Conversation

@apollo-2006

Copy link
Copy Markdown

Fixes #9084.

Thanks again for the quick go-ahead on this one. DXIL replaces a pixel shader SV_CullPrimitive input with 0, but the SPIR-V backend mapped it to CullPrimitiveEXT, which needs MeshShadingEXT and isn't allowed in fragment shaders, so the output failed validation.

This mirrors DXIL and uses a null constant of the declared type instead (false for bool, 0 for uint). I also removed the old PSIn builtin path, since nothing reaches it anymore.

I added meshshading.ext.cullprimitive.ps.hlsl, which checks bool and uint without -fcgl so spirv-val runs on the output. It fails without the change, and the CodeGenSPIRV suite passes.

Jonathan Zakharov (@jzakharovnv) as promised, here it is :)

DXIL replaces SV_CullPrimitive pixel shader inputs with 0. The SPIR-V
backend mapped them to CullPrimitiveEXT, which needs MeshShadingEXT and
isn't allowed in fragment shaders, so the output was invalid.

Fixes microsoft#9084.
Copilot AI balanced review requested due to automatic review settings October 31, 2026 21:03
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The regression test does not verify that SV_Target is zero for both bool and uint runs, allowing incorrect true/1 behavior to pass undetected.

1 open issue
What changed in this PR

This PR fixes #9084 by making the SPIR-V backend replace pixel shader SV_CullPrimitive inputs with zero, matching DXIL and avoiding invalid fragment-shader builtins.

Changes:

  • Emit a null constant of the declared input type and remove the obsolete pixel-shader builtin path.
  • Add bool and uint regression cases with SPIR-V validation enabled.
  • Document the behavior fix in the release notes.
File Description
tools/​clang/​test/​CodeGenSPIRV/​meshshading.ext.cullprimitive.ps.hlsl Adds bool and uint pixel-shader regression cases.
tools/​clang/​lib/​SPIRV/​DeclResultIdMapper.cpp Replaces pixel-shader cull inputs with typed null constants.
docs/​ReleaseNotes.md Documents the DXIL-compatible behavior.

Review effort: Balanced

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick turnaround. Code looks good, the testing just needs a little more coverage, which I've left some ideas for.

@github-project-automation github-project-automation Bot moved this from New to In progress in HLSL Roadmap Nov 2, 2026
Check with -fcgl that the input becomes a null constant of the declared
type, for bool, uint, bool2 and bool[2]. Add a struct shared between a
mesh shader primitive output and a pixel shader input, with
SV_CullPrimitive first and not first: the other members keep the mesh
shader's locations and the 0 lands in the right member.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 18:10
@apollo-2006

Copy link
Copy Markdown
Author

Thanks for these, pushed tests for all three:

  • the -fcgl runs now check for the OpConstantNull directly (bool, uint, bool2 and bool[2])
  • a struct shared by the MS and PS, with SV_CullPrimitive first and not first (locations match, and the 0 lands in the right member both times)

Both fail without the fix. Also, while I was in there I noticed DXIL crashes on a bool[2] PS input (happy to file that separately if it helps) :)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The early return incorrectly replaces explicit Vulkan builtin values with false, breaking existing builtin-override behavior when combined with SV_CullPrimitive.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 2, 2026 18:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The early return bypasses explicit vk::builtin overrides, silently replacing valid helper-invocation input with false; declarations with VKBuiltInAttr need to retain the existing mapping, with regression coverage.

2 open issues

Review effort: Balanced

An explicit vk::builtin took precedence over SV_CullPrimitive before
the PS input was replaced with 0. Skip the replacement when the
attribute is present.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 19:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the SPIR-V SV_CullPrimitive input change.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@pow2clk

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI balanced review requested due to automatic review settings November 5, 2026 07:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change aligning SPIR-V pixel-shader SV_CullPrimitive handling with DXIL.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

[SPIR-V] SV_CullPrimitive as a pixel shader input produces invalid SPIR-V

4 participants