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

Closed
T0ns1 wants to merge 1 commit from upstream-pr/90 into main
T0ns1 commented 2026-11-24 21:24:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by T0ns1 on 2026-11-24T21:24:01Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:5480580501 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/90). Originally posted by [T0ns1](https://github.com/T0ns1) on 2026-11-24T21:24:01Z. --- ## 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.
adriaespii commented 2026-11-24 22:07:33 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by adriaespii on 2026-11-24T21:37:18Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7145171906 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/90#issuecomment-7145171906). Originally posted by [adriaespii](https://github.com/adriaespii) on 2026-11-24T21:37:18Z. --- 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.*
arminkhaleghirod commented 2026-11-24 23:09:35 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by arminkhaleghirod on 2026-11-24T22:23:55Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7146179689 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/90#issuecomment-7146179689). Originally posted by [arminkhaleghirod](https://github.com/arminkhaleghirod) on 2026-11-24T22:23:55Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!90
No description provided.