Repository navigation
Shaders: keep v0 as the leading vertex of both rectangle triangles - #2970
fuzeofficlal wants to merge 1 commit into
Conversation
Split the rectangle along the diagonal through v0 so both triangles can lead with it and keep the input winding. Copy integer attributes from v0 at the synthesized corner.
61e078b to
a6b40d3
Compare
Dukestar69
left a comment
There was a problem hiding this comment.
Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator 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 keeps v0 as the leading vertex for both triangles cleanly.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
I found the same leading-vertex problem in the non-indexed CPU fallback used when a pipeline has no rectangle GS. On
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 git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2970-fallback-leading-vertex
git cherry-pick c4719681289b811f130a61bbea60b315a5be1a12Synthetic geometry only. AI-assisted. |
kotekompotek
left a comment
There was a problem hiding this comment.
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.
|
Thanks for verifying the GS retriangulation across both RTX 5080 and WARP and pointing out the matching provoking-vertex issue in Keeping this PR scoped strictly to |
|
@fuzeofficlal I opened the standalone CPU fix as #2994 and credited your geometry shader's diagonal and winding. It only changes |
|
Automated triage for the maintainers. Needs work. Thanks for correcting the description, which now matches On evidence:
Any one of these would settle it:
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 ( Generated by Claude Code |
|
Updated the PR description to address both triage points:
|
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 ok