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

Open
0xkn0wh3r3 wants to merge 1 commit from upstream-pr/2868 into main
0xkn0wh3r3 commented 2026-11-25 22:46:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T22:46:37Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5500484358 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2868). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T22:46:37Z. --- ## 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.
kotekompotek commented 2026-11-25 22:51:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T22:51:58Z.

Review: COMMENTED


Coherent: SV_PrimitiveID can't be a PS system input on this topology path — it has to be produced per-primitive by the generated GS, so threading the PS container into rectangle_gs to decide emission is the right place. The DrawInstanced count change (real vertex count for triangle-list tests rather than a fixed 3) is the matching harness side. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066078026 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2868#pullrequestreview-6066078026). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T22:51:58Z. **Review:** COMMENTED --- Coherent: SV_PrimitiveID can't be a PS system input on this topology path — it has to be produced per-primitive by the generated GS, so threading the PS container into rectangle_gs to decide emission is the right place. The DrawInstanced count change (real vertex count for triangle-list tests rather than a fixed 3) is the matching harness side. LGTM.
fuzeofficlal commented 2026-11-25 23:06:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T22:54:28Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176924982 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2868#issuecomment-7176924982). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T22:54:28Z. --- 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.
Marvisak commented 2026-11-26 05:04:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:26:02Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182591069 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2868#issuecomment-7182591069). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:26:02Z. --- <!-- 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)_
0xkn0wh3r3 commented 2026-11-26 08:03:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T07:21:43Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185372868 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2868#issuecomment-7185372868). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T07:21:43Z. --- 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.
andrewpozdnakov7-jpg commented 2026-11-27 13:14:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T13:14:47Z.


@0xkn0wh3r3 I checked the translator path raised in the review. Test commit f8c18e9 is based on 34f062a8. The fixture starts with synthetic GFX10 v_interp_mov_f32 ... p0 and a uint SV_PrimitiveID input signature, then runs the normal IR, I/O and DXIL emission stages. The translated pixel shader writes the primitive ID plus one.

On app-local WARP 1.0.22, every red-channel readback was correct: 128 pixels at 1, 128 at 2, and 768 clear pixels. With the same translated pixel shader and a geometry shader that omitted SV_PrimitiveID, D3D12 refused to create the PSO with an invalid-parameter error. D3D12 linkage rule

The DXIL validator loaded and accepted both generated stages in a separate test run. The final test-only commit passed 3 rectangle, 33 lowering, and 35 VALU tests, strict shader Clippy in both feature configurations, and the asset policy check. The fixture establishes reachability with synthetic input. Title usage remains to be measured.

You can cherry-pick the test as-is for re-review. Please retain its Git author, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7219238266 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2868#issuecomment-7219238266). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T13:14:47Z. --- @0xkn0wh3r3 I checked the translator path raised in the review. [Test commit `f8c18e9`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/f8c18e9ee848861aec35de338c55fcda6f818cec) is based on `34f062a8`. The fixture starts with synthetic GFX10 `v_interp_mov_f32 ... p0` and a `uint SV_PrimitiveID` input signature, then runs the normal IR, I/O and DXIL emission stages. The translated pixel shader writes the primitive ID plus one. On app-local WARP 1.0.22, every red-channel readback was correct: 128 pixels at `1`, 128 at `2`, and 768 clear pixels. With the same translated pixel shader and a geometry shader that omitted `SV_PrimitiveID`, D3D12 refused to create the PSO with an invalid-parameter error. [D3D12 linkage rule](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics#system-value-semantics) The DXIL validator loaded and accepted both generated stages in a separate test run. The final test-only commit passed 3 rectangle, 33 lowering, and 35 VALU tests, strict shader Clippy in both feature configurations, and the asset policy check. The fixture establishes reachability with synthetic input. Title usage remains to be measured. You can cherry-pick the test as-is for re-review. Please retain its Git author, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding it into another commit. AI-assisted.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2868:upstream-pr/2868'
git switch 'upstream-pr/2868'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2868'
git switch 'upstream-pr/2868'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2868'
git switch 'upstream-pr/2868'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2868'
git switch 'main'
git merge --squash 'upstream-pr/2868'
git switch 'main'
git merge --ff-only 'upstream-pr/2868'
git switch 'main'
git merge 'upstream-pr/2868'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2866
No description provided.