Shaders: keep v0 as the leading vertex of both rectangle triangles #2968
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:48:48Z.
Problem
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 okImported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T02:00:42Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP,dxil.dllvalidator active):cargo test -p victory-shader --lib emit::rect::tests: 2 passed, 0 failed (bothrectangles_get_their_fourth_cornerandflat_attributes_keep_v0_across_the_entire_rectanglepass on RTX 5090 hardware and WARP, verifying all 3 right-angle corner positions, both mirrored windings,SV_IsFrontFace, and flat integer/float attributes keepingv0across both triangles).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.The diagonal split through
v0((v0, v1, v3)+(v0, v3, v2)/(v0, v1, v2)+(v0, v2, v3)/(v0, v1, v2)+(v0, v3, v1)) preserves input winding and keepsv0as the leading vertex for both triangles cleanly.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:25:24Z.
Review: COMMENTED
Verified the retriangulation: for all three right-angle positions the second emitted triangle shares the v0-v3 (resp. v0-v2, v0-v1) diagonal and preserves input winding — I checked each case with concrete coordinates. v0 leading both triangles is what makes flat attributes consistent across the diagonal, and integer attrs now take v0's value at v3 (matching the provoking vertex) instead of va's. Cleaner than the old (va, vb, v3) completion.
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T02:23:09Z.
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.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:36:10Z.
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.Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T02:47:26Z.
@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.upstream-sync referenced this pull request2026-11-26 06:03:43 +00:00
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:40:17Z.
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
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T06:09:05Z.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.