Shaders: avoid f32 precision loss in thin rectangle right-angle check #2603
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!2603
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2603"
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-25 16:38 UTC · original
fuzeofficlal:fix/shader-rect-thin-right-angle→main· +155 −20 · 1 files · 1 commits · openSummary
right_angleandrectangle_gsincrates/victory-shader/src/emit/rect.rspicked the corner opposite the longest side by comparing squared side lengths directly (d12 > d20 && d12 > d01,d01 > d12 && d01 > d20).For thin rectangles whose aspect ratio is at least
2^12(for example a 1-pixel-tall bar across a 4K target,[[0, 0], [0, 2^-12], [1, 0]]), the squared hypotenuse1.0 + 2^-24rounds to1.0inf32, tyingd20 = 1.0. The strict>check fails and falls back tov1instead ofv0, placing the completed fourth corner on the wrong side ((1, -2^-12)instead of(1, +2^-12)).Changes
crates/victory-shader/src/emit/rect.rs:right_angleandrectangle_gsusing the law of cosines:d12 > d20 && d12 > d01⇔d01 > 2 * dot(e01, e02) && d20 > 2 * dot(e01, e02)d01 > d12 && d01 > d20⇔d20 > 2 * dot(e02, e12) && d12 > 2 * dot(e02, e12)NaNfallback semantics (v1).rule_tests::thin_rectangles_find_their_right_angle(axis-aligned, shifted,2^-20, rotated, and thin isosceles tie cases) andtests::thin_rectangles_get_their_fourth_corner(validating DXIL and rasterizing a2^-12-tall rectangle on an8x8192target on both hardware and WARP).Verification
thin_rectangles_find_their_right_anglefails (left: 1, right: 0), andthin_rectangles_get_their_fourth_cornerrenders empty pixels at row4095on hardware/WARP because the fourth corner flips onto-y.cargo test -p victory-shader --lib emit::rect— 4/4 pass on hardware and WARP (dxil.dllvalidation included).cargo clippy -p victory-shader --all-targets -- -D warningsand--features host— pass (0 warnings).cargo xtask policy— pass (184 files ok).@DrDarkDK on GitHub · 2026-11-25 16:50 UTC · original
I found an exact tie where the fallback changes:
[[0.0, 0.0], [8193.0 / 16384.0, 4100.0 / 16384.0], [4100.0 / 16384.0, 8193.0 / 16384.0]]Here
d01 == d20 > d12. The base rule returns1. The new rule returns2becaused12rounds to0x3dffa009and2 * dot(e02, e12)rounds one ULP lower. That changes the fourth vertex in the CPU expansion path.Could we add this input to
rule_teststo cover the documented tie fallback? I verified the arithmetic with explicit f32 rounding after each operation. I didn’t run the Rust tests or the geometry shader.AI-assisted with Codex.
@fuzeofficlal on GitHub · 2026-11-25 17:22 UTC · original
Great catch @DrDarkDK — replacing
d01 > d20outright withd12 > 2 * dot(e02, e12)introduced a 1-ULP sensitivity on exact acute isosceles ties like[[0, 0], [8193/16384, 4100/16384], [4100/16384, 8193/16384]].Updated (
2a9cca1) in bothright_angleandrectangle_gsto keep the strict squared-length check(d12 > d20 && d12 > d01)and pair it with a dot-product rescue(d01 > 4 * dot(e01, e02) && d20 > 4 * dot(e01, e02))(and symmetrically forv2):4 * dot < min(leg0^2, leg1^2), the law of cosines guaranteesopp^2 > max + 0.5 * min, recovering thin rectangles (both axis-aligned and rotated, well past2^-20).2 * dot == base^2),4 * dot == 2 * base^2fails the rescue with a 2x margin (never near 1 ULP), preserving the exactv1tie fallback.Added your input (and its symmetric rotation) to
rule_tests::thin_rectangles_find_their_right_angleasserting== 1, and re-verified all 4emit::recttests on RTX 5090 + WARP +dxil.dll, clippy (default +--features host), andcargo xtask policy.@Marvisak on GitHub · 2026-11-25 23:19 UTC · original
Automated triage for the maintainers.
In
crates/victory-shader/src/emit/rect.rs,right_angleand the matching GPU logic inrectangle_gskeep the existing strict longest-side test and add a rescue:d01 > 4*dot(e01,e02) && d20 > 4*dot(e01,e02)for v0, and the same for v2. This handles thin rectangles whose squared hypotenuse rounds to the long leg in f32. I checked the math: by the law of cosines,4*dot < min(leg²)givesopp² > max + min/2, so in exact arithmetic the rescue fires only when the opposite side really is the longest. The v0 and v2 rescues cannot both hold, and the GPUpickorder matches the CPU order. Exact isosceles ties fail the rescue by a factor of 2 and stay on v1, including the tie case raised in review, which is now inrule_tests. A rasterizing test on an 8x8192 target is also added. It merges cleanly with currentmain. CI: passing (check). This is a recommendation for a maintainer to look, not an approval.Generated by Claude Code
@futurepro62 on GitHub · 2026-11-25 23:52 UTC · original
Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head
2a9cca1(on its base67e8ae1).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 775 passed, 0 failed, 9 ignored.thin_rectangles_find_their_right_angle,thin_rectangles_get_their_fourth_corner.--skipleaves out tests that fail on main842b0cbon this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
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.