Shaders: keep v0 as the leading vertex of both rectangle triangles #2970
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!2970
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2970"
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?
@fuzeofficlal on GitHub · 2026-11-26 01:48 UTC · original
fuzeofficlal:fix/shader-rect-gs-provoking-vertex→main· +145 −18 · 1 files · 1 commits · openProblem
On
main,rectangle_gs(crates/victory-shader/src/emit/rect.rs) already emits two separate triangles (cutStreamafter each,s.gs = Some(6)): the input triangle(v0, v1, v2)followed by the completion triangle(va, vb, v3), wherevais the vertex before the right-angle cornervcandvbis the vertex after it.v1,va = v0, somain's second triangle(v0, v2, v3)already leads withv0.v0(as in tiled lighting),mainemits(v2, v1, v3)leading withv2, and copiesv2for integer outputs atv3.v2,mainemits(v1, v0, v3)leading withv1, and copiesv1for integer outputs atv3.Because D3D12 uses the leading (first) vertex of each triangle for
nointerpolation/ flat attributes, the two triangles of a single rectangle read different provoking vertices whenevervc != v1.Specification basis
v0) of a primitive as its provoking vertex for constant /nointerpolationattributes (PA_SU_SC_MODE_CNTL.PROVOKING_VTX_LAST = 0on AMD GCN/RDNA hardware).DI_PT_RECTLIST) is a single 3-vertex primitive whose fourth corner is synthesized in scan conversion rather than split into two independent triangles; flat interpolation (v_interp_mov_f32 p0) reads vertex 0 (v0) uniformly across the entire rectangle regardless of which corner holds the right angle.Fix
v0and emit both triangles withv0as the leading vertex while preserving the exact input winding order for every right-angle placement:v0:(v0, v1, v3),(v0, v3, v2)v1:(v0, v1, v2),(v0, v2, v3)v2:(v0, v1, v2),(v0, v3, v1)v0for non-float (integer) attributes at the synthesized cornerv3.Verification
emit::rect::tests::flat_attributes_keep_v0_across_the_entire_rectangle, validatingvs,gs, andpswithdxil.dlland rendering on both hardware D3D12 (RTX 5090) and WARP across all 3 right-angle placements (vc = 0, 1, 2) and both winding orientations (mirror = +1.0, -1.0), asserting every pixel receivesv0's flat uint & float attributes and matches the input triangle'sSV_IsFrontFace.cargo test -p victory-shader --lib emit::rect: 3/3 passed (hardware + WARP + DXIL validator)cargo test -p victory-shader --lib emit::tests emit::lower::tests: 50/50 passedcargo clippy -p victory-shader --tests&--all-features --tests: 0 warningscargo xtask policy: 191 files ok@steven-seagull27 on GitHub · 2026-11-26 02:23 UTC · original
I found the same leading-vertex problem in the non-indexed CPU fallback used when a pipeline has no rectangle GS. On
a6b40d3c, I fed the six vertices fromvictory_gpu::primitivethrough a triangle-list PSO and compared its 32×32 readback with this PR’s geometry shader. The RTX 5080 (621.40) and built-in WARP returned the same counts.I put the CPU follow-up in one cherry-pickable commit. It uses the same split through v0 as your GS and computes the corner once per rectangle for all streams on command-list submission. It prefers a named position and falls back to the first suitable float element in layout order. The CPU path still computes the fourth corner before the vertex shader, so the comparison uses a pass-through VS.
With that commit, 24/24 readbacks on RTX and 24/24 on WARP matched the GS, covering the three right-angle corners, both windings, both layouts and flat versus interpolated float. I checked all 1,024 pixels per draw, including coverage and facing; float comparison tolerance was
1e-5. Twelve focused CPU/layout tests passed, including the new separate-stream regression. Strictvictory-gputest-target Clippy and asset policy passed.Synthetic geometry only. AI-assisted.
@fuzeofficlal on GitHub · 2026-11-26 02:36 UTC · original
Thanks for verifying the GS retriangulation across both RTX 5080 and WARP and pointing out the matching provoking-vertex issue in
victory-gpu::primitive!Keeping this PR scoped strictly to
crates/victory-shader/src/emit/rect.rsso it stays minimal and avoids overlapping #2729 (which already touches multi-stream rectangle corner selection invictory-gpu/src/primitive.rs). Yourprimitive.rsleading-vertex fix looks like a great standalone follow-up PR.@steven-seagull27 on GitHub · 2026-11-26 02:47 UTC · original
@fuzeofficlal I opened the standalone CPU fix as #2994 and credited your geometry shader's diagonal and winding. It only changes
primitive.rs. With #2729's shared-corner change, the fallback matches your GS in all 24 synthetic pixel readbacks on both RTX 5080 and WARP. I marked #2994 as a draft pending #2729 so the split-stream cases move together.@Marvisak on GitHub · 2026-11-26 05:40 UTC · original · edited 2026-11-26 07:19 UTC
Automated triage for the maintainers.
Needs work. Thanks for correcting the description, which now matches
main'srectangle_gs.On evidence:
DI_PT_RECTLISTas one primitive, sov_interp_mov p0returnsv0across the whole rectangle. It is plausible, but the PR states it without a source.Any one of these would settle it:
v0) that this PR fixes.With that, this is a merge candidate. The code itself does what it says, and the GS test passes on hardware and WARP.
CI: passing (
check).Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-26 06:09 UTC · original
Updated the PR description to address both triage points:
main:mainalready emits two separate triangles withcutStreamafter each ((v0, v1, v2)and(va, vb, v3)), sovc = v1already leads withv0and onlyvc = v0(leadingv2) andvc = v2(leadingv1) disagree across the diagonal.DI_PT_RECTLISTsingle-primitive flat interpolation (PA_SU_SC_MODE_CNTL.PROVOKING_VTX_LAST = 0,v_interp_mov p0= vertex 0 across the whole rectangle). Note transparently that this has only been verified with synthetic tests on hardware + WARP (no title run).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.