Shaders, GPU: a rectangle list's pixel shader can read SV_PrimitiveID #2868

Open
github-bot wants to merge 1 commit from github-bot/gh-2868 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 22:46 UTC · original
0xkn0wh3r3:shader/rectangle-lists-pass-the-primitive-id → main · +146 −6 · 3 files · 1 commits · open

What

Rectangle lists draw through a geometry shader built from the vertex shader (rectangle_gs), which copies the vertex shader's outputs. When a geometry stage is present, a pixel shader's SV_PrimitiveID must come from it. So any pipeline whose pixel shader reads the primitive id was refused by the host: CreateGraphicsPipelineState returns "The parameter is incorrect." on the RTX 5070 Ti and on WARP. That pipeline's rectangle draws were lost.

This PR changes three things:

  • rectangle_gs(vs, ps): when the pixel shader reads SV_PrimitiveID and the vertex shader writes none, the geometry shader writes it as one more output. The output is constant, in the pixel shader's register, and holds the input triangle's number on every vertex it emits. A primitive id in a register that a vertex output uses with another interpolation mode (or in the same columns) is refused with a reason.
  • victory-gpu: pipeline/host.rs passes the translated pixel shader.
  • Test harness: Host::draw now draws as many vertices as it's given (at least three). Every existing caller gives exactly three.

Where it came from

From DexNom's fork, DexNom/VIctory@570a941: their rect_list_gs(vs, ps) adds the same output. It's reworked here for this tree's rectangle_gs and credited with Co-authored-by: DexNom.

Tested

  • New test rect::tests::rectangles_number_themselves_for_the_pixel_shader: two rectangles whose pixel shader writes primitive id + 1 read 1 in the left one, 2 in the right one and 0 between them, on the hardware adapter and on WARP. On current main the same pipeline isn't created (I checked with a probe before the change).
  • cargo test -p victory-shader (Windows 11, RTX 5070 Ti): 299 passed. Four tests fail identically on main on this machine: heap_direct_texture_reads_mark_their_heap_index (crash, skipped), two stride_tests and gathers_at_a_level_match_the_hardware.
  • cargo test -p victory-gpu: 226 passed. 2 known NVIDIA failures, fixed by #2121.
  • cargo clippy --all-targets -- -D warnings on victory-shader, and on victory-gpu with and without --features diagnostics: clean.
  • With dxil.dll 1.6 (VICTORY_DXIL), the pixel shader validates. The geometry shader, like the existing rectangles_get_their_fourth_corner on unmodified main, fails only on the PSV0 part. That's the validator-version mismatch discussed in #1945; the runtime creates the pipeline. Without that DLL, both rectangle tests pass.

Not tested

  • Not run with the title, so I haven't counted how many of its rectangle-list pipelines read the primitive id.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 22:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2868) `0xkn0wh3r3:shader/rectangle-lists-pass-the-primitive-id` → `main` · +146 −6 · 3 files · 1 commits · open ## What Rectangle lists draw through a geometry shader built from the vertex shader (`rectangle_gs`), which copies the vertex shader's outputs. When a geometry stage is present, a pixel shader's `SV_PrimitiveID` must come from it. So any pipeline whose pixel shader reads the primitive id was **refused by the host**: `CreateGraphicsPipelineState` returns "The parameter is incorrect." on the RTX 5070 Ti and on WARP. That pipeline's rectangle draws were lost. This PR changes three things: - **`rectangle_gs(vs, ps)`:** when the pixel shader reads `SV_PrimitiveID` and the vertex shader writes none, the geometry shader writes it as one more output. The output is constant, in the pixel shader's register, and holds the input triangle's number on every vertex it emits. A primitive id in a register that a vertex output uses with another interpolation mode (or in the same columns) is refused with a reason. - **victory-gpu:** `pipeline/host.rs` passes the translated pixel shader. - **Test harness:** `Host::draw` now draws as many vertices as it's given (at least three). Every existing caller gives exactly three. ## Where it came from From DexNom's fork, [DexNom/VIctory@570a941](https://github.com/DexNom/VIctory/commit/570a941e9b4e945121c26eb30dfc10c126845207): their `rect_list_gs(vs, ps)` adds the same output. It's reworked here for this tree's `rectangle_gs` and credited with `Co-authored-by: DexNom`. ## Tested - **New test** `rect::tests::rectangles_number_themselves_for_the_pixel_shader`: two rectangles whose pixel shader writes `primitive id + 1` read 1 in the left one, 2 in the right one and 0 between them, on the hardware adapter and on WARP. On current main the same pipeline isn't created (I checked with a probe before the change). - `cargo test -p victory-shader` (Windows 11, RTX 5070 Ti): 299 passed. Four tests fail identically on main on this machine: `heap_direct_texture_reads_mark_their_heap_index` (crash, skipped), two `stride_tests` and `gathers_at_a_level_match_the_hardware`. - `cargo test -p victory-gpu`: 226 passed. 2 known NVIDIA failures, fixed by #2121. - `cargo clippy --all-targets -- -D warnings` on victory-shader, and on victory-gpu with and without `--features diagnostics`: clean. - With `dxil.dll` 1.6 (`VICTORY_DXIL`), the pixel shader validates. The geometry shader, like the existing `rectangles_get_their_fourth_corner` on unmodified main, fails only on the PSV0 part. That's the validator-version mismatch discussed in #1945; the runtime creates the pipeline. Without that DLL, both rectangle tests pass. ## Not tested - Not run with the title, so I haven't counted how many of its rectangle-list pipelines read the primitive id.
Rectangle lists draw through a geometry shader made for the vertex
shader, whose outputs it copies. With a geometry stage, a pixel shader's
SV_PrimitiveID must come from it, so a pipeline whose pixel shader reads
the primitive id was refused by the host ("The parameter is incorrect",
on the hardware adapter and WARP) and its rectangle draws were lost.

rectangle_gs now takes the pixel shader too: when it reads
SV_PrimitiveID and the vertex shader writes none, the geometry shader
writes it as one more output (constant, in the pixel shader's register),
the input triangle's number, on every emitted vertex. A primitive id in
a register a vertex output uses with another mode, or in the same
columns, is refused.

The test harness's draws now take as many vertices as they are given (at
least three; every caller gave three).

Test: rectangles_number_themselves_for_the_pixel_shader draws two
rectangles whose pixel shader writes the primitive id + 1: 1 in the
left, 2 in the right, 0 between, on the hardware adapter and WARP.

From DexNom/VIctory@570a941e9b
(rect_list_gs with a pixel shader), reworked for this tree's
rectangle_gs.

Co-authored-by: DexNom <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:18 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 22:54 UTC · original

Reviewed and verified 34f062a8 on Windows 11 (RTX 5090 + WARP + dxil.dll) against main (842b0cb):

  • primitive_id_input cleanly inspects PS ISG1 for kind == 10 && row.is_some(), checks constant-interpolation and non-overlapping column compatibility when sharing a row with VS OSG1 (falling back safely to rectangles = false otherwise), emits dx.op.primitiveID.i32 (opcode 108) across all 6 emitted vertices, and leaves non-SV_PrimitiveID rectangle pipelines unchanged.
  • Local checks: victory-shader --lib emit::rect 3/3 passed (including rectangles_number_themselves_for_the_pixel_shader with dxil.dll validation and RTX 5090 + WARP readback), victory-gpu primitive::tests 9/9 and draw::tests 20/20 passed, cargo clippy --locked -p victory-shader -p victory-gpu --all-targets -- -D warnings 0 warnings, cargo xtask policy (190 files ok; emit/lower.rs untouched).

Looks clean and ready to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 22:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2868#issuecomment-7176924982) Reviewed and verified `34f062a8` on Windows 11 (RTX 5090 + WARP + `dxil.dll`) against `main` (`842b0cb`): - `primitive_id_input` cleanly inspects PS `ISG1` for `kind == 10 && row.is_some()`, checks constant-interpolation and non-overlapping column compatibility when sharing a row with VS `OSG1` (falling back safely to `rectangles = false` otherwise), emits `dx.op.primitiveID.i32` (opcode `108`) across all 6 emitted vertices, and leaves non-`SV_PrimitiveID` rectangle pipelines unchanged. - Local checks: `victory-shader --lib emit::rect` 3/3 passed (including `rectangles_number_themselves_for_the_pixel_shader` with `dxil.dll` validation and RTX 5090 + WARP readback), `victory-gpu` `primitive::tests` 9/9 and `draw::tests` 20/20 passed, `cargo clippy --locked -p victory-shader -p victory-gpu --all-targets -- -D warnings` 0 warnings, `cargo xtask policy` (`190 files ok`; `emit/lower.rs` untouched). Looks clean and ready to merge.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:26 UTC · original

Automated triage for the maintainers.

Needs work. This makes rectangle_gs write SV_PrimitiveID when the pixel shader's ISG1 declares one. The D3D12 linkage rule is right, but in this tree a translated pixel shader never declares SV_PrimitiveID: Lower's input mapping in emit/lower.rs returns Val::Missing("the primitive id") for Input::PrimitiveId, and io.rs maps it only for the vertex stage. So only the hand-built test shader reaches the new path. Please show a title pixel shader that reaches it, or pair this with the translator change that makes pixel shaders declare the primitive id, with evidence of where the console's pixel shaders get it (for example the RDNA2 ISA guide's PS input description).

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2868#issuecomment-7182591069) <!-- victory-triage v1 head=34f062a8f1e9d35651274b5b02cd2d90091f3dcd verdict=needs-work at=2026-11-26T04:25:55Z --> Automated triage for the maintainers. **Needs work.** This makes `rectangle_gs` write `SV_PrimitiveID` when the pixel shader's ISG1 declares one. The D3D12 linkage rule is right, but in this tree a translated pixel shader never declares `SV_PrimitiveID`: `Lower`'s input mapping in `emit/lower.rs` returns `Val::Missing("the primitive id")` for `Input::PrimitiveId`, and `io.rs` maps it only for the vertex stage. So only the hand-built test shader reaches the new path. Please show a title pixel shader that reaches it, or pair this with the translator change that makes pixel shaders declare the primitive id, with evidence of where the console's pixel shaders get it (for example the RDNA2 ISA guide's PS input description). CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 07:21 UTC · original

A translated pixel shader can declare SV_PrimitiveID, through a different path from the one the triage points at:

  • Input::PrimitiveId → Val::Missing (emit/lower.rs) and its mapping in io.rs are the vertex stage's hardware input (VGPR v2). Pixel shaders don't use it.
  • A pixel shader's input signature is the title's own: emit/mod.rs:443 takes ISG1 from the title's container, and system value 7 (SV_PrimitiveID) maps to DXIL's PrimitiveID (emit/mod.rs:579). The shader reads it as a flat attribute: v_interp_mov on its row resolves through find_input (emit/lower.rs:1570), like any other input.

So a title pixel shader that reads the primitive id has SV_PrimitiveID in its translated signature. In a rectangle-list pipeline, the host then refuses the PSO, because the geometry stage rectangle_gs adds doesn't write it. That refusal is what this PR removes.

On where the console's pixel shaders get the value: the public RDNA2 ISA guide lists no primitive-id input among the pixel shader's initialized registers (§3.12.2, p.23). Pixel shaders read attributes as parameters from LDS through v_interp_* (§10.4, p.93). That's consistent with the primitive id arriving as a flat parameter the previous stage exports, which the translated signature keeps.

What I can't show here is a count of the title's pixel shaders that list SV_PrimitiveID: that needs title data. The PR's test uses a hand-built shader for that reason.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 07:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2868#issuecomment-7185372868) A translated pixel shader can declare `SV_PrimitiveID`, through a different path from the one the triage points at: - `Input::PrimitiveId` → `Val::Missing` (`emit/lower.rs`) and its mapping in `io.rs` are the **vertex** stage's hardware input (VGPR v2). Pixel shaders don't use it. - A pixel shader's input signature is the title's own: `emit/mod.rs:443` takes `ISG1` from the title's container, and system value 7 (`SV_PrimitiveID`) maps to DXIL's PrimitiveID (`emit/mod.rs:579`). The shader reads it as a flat attribute: `v_interp_mov` on its row resolves through `find_input` (`emit/lower.rs:1570`), like any other input. So a title pixel shader that reads the primitive id has `SV_PrimitiveID` in its translated signature. In a rectangle-list pipeline, the host then refuses the PSO, because the geometry stage `rectangle_gs` adds doesn't write it. That refusal is what this PR removes. On where the console's pixel shaders get the value: the public RDNA2 ISA guide lists no primitive-id input among the pixel shader's initialized registers (§3.12.2, p.23). Pixel shaders read attributes as parameters from LDS through `v_interp_*` (§10.4, p.93). That's consistent with the primitive id arriving as a flat parameter the previous stage exports, which the translated signature keeps. What I can't show here is a count of the title's pixel shaders that list `SV_PrimitiveID`: that needs title data. The PR's test uses a hand-built shader for that reason.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2868/head:github-bot/gh-2868'
git switch 'github-bot/gh-2868'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2868'
git switch 'github-bot/gh-2868'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2868'
git switch 'github-bot/gh-2868'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2868'
git switch 'main'
git merge --squash 'github-bot/gh-2868'
git switch 'main'
git merge --ff-only 'github-bot/gh-2868'
git switch 'main'
git merge 'github-bot/gh-2868'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2868
No description provided.