Shaders, GPU: a rectangle list's pixel shader can read SV_PrimitiveID #2868
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2868
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@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 · openWhat
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
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]>@fuzeofficlal on GitHub · 2026-11-25 22:54 UTC · original
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.
@Marvisak on GitHub · 2026-11-26 04:26 UTC · original
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
@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 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.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.