Shaders: a rectangle's corners match within a tolerance, not bit for bit #90

Open
github-bot wants to merge 1 commit from github-bot/gh-90 into main AGit
Owner

@⁠T0ns1 on GitHub · 2026-11-24 21:24 UTC · original
T0ns1:pr/rect-tolerance → main · +25 −3 · 1 files · 1 commits · open

Summary

The rectangle-list geometry shader (emit/rect.rs) completes a console rectangle only when one vertex shares x with one of the others and y with the other exactly, and when every w is exactly the same (OEQ). Otherwise "three that differ in w, or are not such corners, stay the triangle they make".

A vertex shader that computes each corner (a scale and an offset per vertex) can leave the corners a few bits apart. Such a rectangle then stays the one triangle it arrives as and draws half of itself, cut along its diagonal.

Corners now match within 1e-4 of the first vertex's w (RECT_TOLERANCE, under a fifth of a pixel at 3840 pixels across), for the corner test, the "no two vertices in one place" test and the equal-w test. Exact matches behave as before.

What is in it

  • same (OEQ) becomes close(a, b, tol): -tol <= a - b <= tol, with tol = w0 * RECT_TOLERANCE. A negative or NaN tol makes nothing close, so a non-positive w still stays a triangle, as before.
  • The module docs say why the tolerance is there.
  • rectangles_are_drawn_whole gets a case whose corners are a few bits apart: (-1, 1), (-1.00001, -1), (1, -0.99999).

Tested

Windows 11 Pro 26300, RTX 5070 Ti 16 GB (driver 32.0.16.2140, 32-lane waves), Ryzen 7 9800X3D, Rust 1.98.1 MSVC (the pinned toolchain).

  • cargo test --release -p victory-shader: 210 passed, 0 failed, 2 ignored.
  • With RECT_TOLERANCE set to 0.0 (the old exact comparison), the new case fails: corner second, a few bits apart: texel 0 is [0.0, 0.0, 0.0, 0.0], not [-0.875, 0.875, 0.0, 1.0]. With 1e-4 it passes.

Not tested

  • Which of the title's rectangle lists have corners a few bits apart: I did not trace the vertex values in a capture. In a run of the first gameplay scene, large diagonal shards were gone after this change, but that run also had #77's change (deferred material programs that were dropped before), so I cannot attribute it to this one.
  • Non-Windows platforms.

AI use: Claude Code (Claude Opus 5.5) found the exact comparison, wrote the change and the test, and ran the tests.

**@⁠T0ns1** on GitHub · 2026-11-24 21:24 UTC · [original](https://github.com/fxceless/victory-fork/pull/90) `T0ns1:pr/rect-tolerance` → `main` · +25 −3 · 1 files · 1 commits · open ## Summary The rectangle-list geometry shader (`emit/rect.rs`) completes a console rectangle only when one vertex shares x with one of the others and y with the other **exactly**, and when every w is **exactly** the same (`OEQ`). Otherwise "three that differ in w, or are not such corners, stay the triangle they make". A vertex shader that computes each corner (a scale and an offset per vertex) can leave the corners a few bits apart. Such a rectangle then stays the one triangle it arrives as and draws half of itself, cut along its diagonal. Corners now match within `1e-4` of the first vertex's w (`RECT_TOLERANCE`, under a fifth of a pixel at 3840 pixels across), for the corner test, the "no two vertices in one place" test and the equal-w test. Exact matches behave as before. ## What is in it - `same` (`OEQ`) becomes `close(a, b, tol)`: `-tol <= a - b <= tol`, with `tol = w0 * RECT_TOLERANCE`. A negative or NaN `tol` makes nothing close, so a non-positive w still stays a triangle, as before. - The module docs say why the tolerance is there. - `rectangles_are_drawn_whole` gets a case whose corners are a few bits apart: `(-1, 1), (-1.00001, -1), (1, -0.99999)`. ## Tested Windows 11 Pro 26300, RTX 5070 Ti 16 GB (driver 32.0.16.2140, 32-lane waves), Ryzen 7 9800X3D, Rust 1.98.1 MSVC (the pinned toolchain). - `cargo test --release -p victory-shader`: 210 passed, 0 failed, 2 ignored. - With `RECT_TOLERANCE` set to `0.0` (the old exact comparison), the new case fails: `corner second, a few bits apart: texel 0 is [0.0, 0.0, 0.0, 0.0], not [-0.875, 0.875, 0.0, 1.0]`. With `1e-4` it passes. ## Not tested - Which of the title's rectangle lists have corners a few bits apart: I did not trace the vertex values in a capture. In a run of the first gameplay scene, large diagonal shards were gone after this change, but that run also had #77's change (deferred material programs that were dropped before), so I cannot attribute it to this one. - Non-Windows platforms. AI use: Claude Code (Claude Opus 5.5) found the exact comparison, wrote the change and the test, and ran the tests.
The rectangle-list geometry shader took a vertex as the corner between
the other two only when it shared x with one and y with the other
exactly, and every w had to be exactly the same. A vertex shader that
computes each corner (a scale and an offset per vertex) can leave them a
few bits apart; such a rectangle stayed the one triangle it came as and
drew half of itself, cut along its diagonal.

Corners now match within 1e-4 of the first vertex's w (under a fifth of
a pixel at 3840 pixels across), for the corner test, the "no two
vertices in one place" test and the equal-w test.

rectangles_are_drawn_whole gets a case whose corners are a few bits
apart; it fails with the old exact comparison (texel 0 left empty) and
passes with this.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:00 +00:00
Author
Owner

@⁠adriaespii on GitHub · 2026-11-24 21:37 UTC · original

Independent test run on commit 6cf8f8c (AMD RDNA4):

  • Hardware: AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo test --workspace: 496 passed, 0 failed, 7 ignored (victory-shader: 210 passed, 0 failed, 2 ignored; victory-gpu: 110 passed, 0 failed, 1 ignored)
  • Not tested: live game run (no game files on this machine)

AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.

**@⁠adriaespii** on GitHub · 2026-11-24 21:37 UTC · [original](https://github.com/fxceless/victory-fork/pull/90#issuecomment-7145171906) Independent test run on commit `6cf8f8c` (AMD RDNA4): - **Hardware:** AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (`x86_64-pc-windows-msvc`) - `cargo clippy --workspace --all-targets -- -D warnings`: 0 warnings - `cargo test --workspace`: 496 passed, 0 failed, 7 ignored (`victory-shader`: 210 passed, 0 failed, 2 ignored; `victory-gpu`: 110 passed, 0 failed, 1 ignored) - **Not tested:** live game run (no game files on this machine) *AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.*
Author
Owner

@⁠arminkhaleghirod on GitHub · 2026-11-24 22:23 UTC · original

Merged onto main 90228a7 and ran victory translate --validate over the full title (26,148 programs) on Windows 11 / RTX 4080.

No change: every failure count matches main, and no new reason appears. What it changes at run time isn't covered by this check.

**@⁠arminkhaleghirod** on GitHub · 2026-11-24 22:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/90#issuecomment-7146179689) Merged onto main 90228a7 and ran `victory translate --validate` over the full title (26,148 programs) on Windows 11 / RTX 4080. No change: every failure count matches main, and no new reason appears. What it changes at run time isn't covered by this check.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/90/head:github-bot/gh-90'
git switch 'github-bot/gh-90'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-90'
git switch 'github-bot/gh-90'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-90'
git switch 'github-bot/gh-90'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-90'
git switch 'main'
git merge --squash 'github-bot/gh-90'
git switch 'main'
git merge --ff-only 'github-bot/gh-90'
git switch 'main'
git merge 'github-bot/gh-90'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.