Shaders, GPU: a rectangle list's pixel shader can read SV_PrimitiveID #2866
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2868"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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'sSV_PrimitiveIDmust come from it. So any pipeline whose pixel shader reads the primitive id was refused by the host:CreateGraphicsPipelineStatereturns "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 readsSV_PrimitiveIDand 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.pipeline/host.rspasses the translated pixel shader.Host::drawnow 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'srectangle_gsand credited withCo-authored-by: DexNom.Tested
rect::tests::rectangles_number_themselves_for_the_pixel_shader: two rectangles whose pixel shader writesprimitive id + 1read 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), twostride_testsandgathers_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 warningson victory-shader, and on victory-gpu with and without--features diagnostics: clean.dxil.dll1.6 (VICTORY_DXIL), the pixel shader validates. The geometry shader, like the existingrectangles_get_their_fourth_corneron 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
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.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T22:54:28Z.
Reviewed and verified
34f062a8on Windows 11 (RTX 5090 + WARP +dxil.dll) againstmain(842b0cb):primitive_id_inputcleanly inspects PSISG1forkind == 10 && row.is_some(), checks constant-interpolation and non-overlapping column compatibility when sharing a row with VSOSG1(falling back safely torectangles = falseotherwise), emitsdx.op.primitiveID.i32(opcode108) across all 6 emitted vertices, and leaves non-SV_PrimitiveIDrectangle pipelines unchanged.victory-shader --lib emit::rect3/3 passed (includingrectangles_number_themselves_for_the_pixel_shaderwithdxil.dllvalidation and RTX 5090 + WARP readback),victory-gpuprimitive::tests9/9 anddraw::tests20/20 passed,cargo clippy --locked -p victory-shader -p victory-gpu --all-targets -- -D warnings0 warnings,cargo xtask policy(190 files ok;emit/lower.rsuntouched).Looks clean and ready to merge.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:26:02Z.
Automated triage for the maintainers.
Needs work. This makes
rectangle_gswriteSV_PrimitiveIDwhen the pixel shader's ISG1 declares one. The D3D12 linkage rule is right, but in this tree a translated pixel shader never declaresSV_PrimitiveID:Lower's input mapping inemit/lower.rsreturnsVal::Missing("the primitive id")forInput::PrimitiveId, andio.rsmaps 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
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 inio.rsare the vertex stage's hardware input (VGPR v2). Pixel shaders don't use it.emit/mod.rs:443takesISG1from 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_movon its row resolves throughfind_input(emit/lower.rs:1570), like any other input.So a title pixel shader that reads the primitive id has
SV_PrimitiveIDin its translated signature. In a rectangle-list pipeline, the host then refuses the PSO, because the geometry stagerectangle_gsadds 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.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
f8c18e9is based on34f062a8. The fixture starts with synthetic GFX10v_interp_mov_f32 ... p0and auint SV_PrimitiveIDinput 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 at2, and 768 clear pixels. With the same translated pixel shader and a geometry shader that omittedSV_PrimitiveID, D3D12 refused to create the PSO with an invalid-parameter error. D3D12 linkage ruleThe 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.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.