Skip to content

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

Open
T0ns1 wants to merge 1 commit into
fxceless:mainfrom
T0ns1:pr/rect-tolerance
Open

T0ns1 wants to merge 1 commit into
fxceless:mainfrom
T0ns1:pr/rect-tolerance

Conversation

@T0ns1

@T0ns1 T0ns1 commented Nov 24, 2026

Copy link
Copy Markdown

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

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.
@adriaespii

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

RecompLive added a commit to RecompLive/victory-fork that referenced this pull request Nov 25, 2026
`view_format` reads the host resource's description, which only exists on
Windows, but it was compiled everywhere; its only callers (`descriptor.rs`
and `descriptor/host.rs`) are already Windows-gated. `#[cfg(windows)]` on it
lets victory-gpu build on Linux (upstream issue fxceless#90).

Ported from Marvisak/VIctory PR #2008 (GPL-3.0-or-later); not built on
Linux here, only checked on Windows.
oceansde012 pushed a commit to oceansde012/victory-gta6 that referenced this pull request Nov 25, 2026
…rners match within a tolerance, not bit for bit (by António Mendes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants