Shaders: a rectangle's fourth corner is across the diagonal from its right angle, wherever that comes #2366

Closed
github-bot wants to merge 3 commits from gh-pr/2366/head into gh-pr/2366/base
Owner

@⁠r4tedx on GitHub · 2026-11-25 11:57 UTC · original
r4tedx:fix/edge-triangles → main · +154 −42 · 1 files · 3 commits · closed without merging

The problem

A rectangle list gives three corners of each rectangle. The hardware adds the fourth across the diagonal from the corner between the other two. rectangle_gs (emit/rect.rs) assumes that corner is always the second vertex and adds the fourth at v0 + v2 - v1.

The title's tiled-lighting draws give their tiles as top left, bottom left, top right, so the right-angle corner comes first. For them v0 + v2 - v1 is a point above the tile's top-right corner. The second triangle then covers the lower-right half of the tile above, with this tile's attributes, and each tile's own lower-right half is never drawn. On screen this shows as saw-tooth triangles on a diagonal, tile-sized grid along geometry edges.

The fix

The geometry shader picks the corner between the other two as the one facing the longest side, in screen space (x/w, y/w of SV_Position), and emits the completion (a, b, a + b - c). It turns the same way as the first triangle in all three orders. With no position output, or with a tie (a degenerate rectangle), it keeps the old rule (the second corner), so full-screen rectangles given as top left, bottom left, bottom right come out as before.

Tests

  • rectangles_get_their_fourth_corner (existing, corner second) now shares its drawing code with two new tests:
  • rectangles_with_the_corner_first_complete_across_their_diagonal
  • rectangles_with_the_corner_third_complete_across_their_diagonal

Each draws one square into 32x32 and checks every pixel: inside, the interpolated coordinates; outside, nothing.

Run on WARP (the software adapter) only:

main 940d32f this branch
emit::rect::tests (VICTORY_WARP=1) 1 passed, 2 failed (the two new tests, with main's rect.rs) 3 passed
victory-shader --lib (VICTORY_WARP=1, every-adapter tests skipped) 244 passed, 2 failed 246 passed, 2 failed (the same two: gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out)
cargo clippy -p victory-shader --all-targets -- -D warnings clean

How it was found

Local title data was used for the diagnosis only: a target dump of one frame (RTX 5070, a build of main with open PRs) and offline disassembly of the vertex shaders involved. The pattern first appears in the tiled-lighting output target, and in 128x128 tiles exactly the x + y >= 128 half is lit. The tests above use no title data.

Not covered

  • primitive.rs's CPU fallback (pipelines without a geometry shader) makes the same second-corner assumption. It doesn't know which input is the position, so it is unchanged here.
  • #1907 changes the same function (unwritten channels, interpolation modes), so whichever lands second needs a small rebase. The two changes are independent.
  • Not yet checked in game with the fix.

AI-assisted

🤖 Generated with Claude Code

**@⁠r4tedx** on GitHub · 2026-11-25 11:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366) `r4tedx:fix/edge-triangles` → `main` · +154 −42 · 1 files · 3 commits · closed without merging ## The problem A rectangle list gives three corners of each rectangle. The hardware adds the fourth across the diagonal from the corner between the other two. `rectangle_gs` (`emit/rect.rs`) assumes that corner is always the second vertex and adds the fourth at `v0 + v2 - v1`. The title's tiled-lighting draws give their tiles as top left, bottom left, top right, so the right-angle corner comes first. For them `v0 + v2 - v1` is a point above the tile's top-right corner. The second triangle then covers the lower-right half of the tile above, with this tile's attributes, and each tile's own lower-right half is never drawn. On screen this shows as saw-tooth triangles on a diagonal, tile-sized grid along geometry edges. ## The fix The geometry shader picks the corner between the other two as the one facing the longest side, in screen space (`x/w`, `y/w` of `SV_Position`), and emits the completion `(a, b, a + b - c)`. It turns the same way as the first triangle in all three orders. With no position output, or with a tie (a degenerate rectangle), it keeps the old rule (the second corner), so full-screen rectangles given as top left, bottom left, bottom right come out as before. ## Tests - `rectangles_get_their_fourth_corner` (existing, corner second) now shares its drawing code with two new tests: - `rectangles_with_the_corner_first_complete_across_their_diagonal` - `rectangles_with_the_corner_third_complete_across_their_diagonal` Each draws one square into 32x32 and checks every pixel: inside, the interpolated coordinates; outside, nothing. Run on WARP (the software adapter) only: | | `main` 940d32f | this branch | |---|---|---| | `emit::rect::tests` (`VICTORY_WARP=1`) | 1 passed, 2 failed (the two new tests, with `main`'s `rect.rs`) | 3 passed | | `victory-shader --lib` (`VICTORY_WARP=1`, every-adapter tests skipped) | 244 passed, 2 failed | 246 passed, 2 failed (the same two: `gathers_at_a_level_match_the_hardware`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`) | | `cargo clippy -p victory-shader --all-targets -- -D warnings` | | clean | ## How it was found Local title data was used for the diagnosis only: a target dump of one frame (RTX 5070, a build of `main` with open PRs) and offline disassembly of the vertex shaders involved. The pattern first appears in the tiled-lighting output target, and in 128x128 tiles exactly the `x + y >= 128` half is lit. The tests above use no title data. ## Not covered - `primitive.rs`'s CPU fallback (pipelines without a geometry shader) makes the same second-corner assumption. It doesn't know which input is the position, so it is unchanged here. - #1907 changes the same function (unwritten channels, interpolation modes), so whichever lands second needs a small rebase. The two changes are independent. - Not yet checked in game with the fix. AI-assisted 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A rectangle list gives three corners; the hardware adds the fourth
across the diagonal from the corner between the other two. rectangle_gs
took that corner to be the second always (v0 + v2 - v1). The title's
tiled-lighting draws give their tiles as top left, bottom left, top
right, so the corner comes first: the fourth corner fell above the
tile's top right, the second triangle covered the lower-right half of
the tile above with this tile's attributes, and every tile's own
lower-right half went undrawn (saw-tooth triangles on a diagonal,
tile-sized grid along geometry edges).

The geometry shader now picks the corner facing the longest side, in
screen space (SV_Position x/w, y/w), and emits the completion
(a, b, a + b - c), turning as the first triangle does. With no position
output, or a tie, it keeps the second corner as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A zero w at the second corner makes the diagonal comparisons unordered,
so the completion falls back to main's rule (v0 + v2 - v1). The test
draws such a rectangle on WARP and checks a pixel the fourth corner
weighs into. The drawing helper keeps to WARP when VICTORY_WARP=1.

Co-Authored-By: GPT-6.2 Sol (Codex) <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:03:40 +00:00
github-bot closed this pull request 2026-11-26 05:03:40 +00:00
Author
Owner

@⁠Machad3x on GitHub · 2026-11-25 12:26 UTC · original

In-game check of this branch (the PR's "Not yet checked in game" item), RTX 3080 Ti, driver 621.24, Windows 11. Both commits (a54e0c84, 1853bce5) cherry-picked onto a local stack of main 940d32f with other open PRs, including #439.

  • emit::rect tests on the hardware adapter run: 3 passed.
  • 5-minute run without the commits: saw-tooth triangles on a regular tile grid, most visibly along the bottom edge of the picture and along geometry edges (seen in two separate runs).
  • 5-minute run with them, same stack otherwise: no such triangles in the inspected screenshots (240 s and 300 s). No device removal; frame rate unchanged (about 1.1 fps).

Only the screenshots were inspected, not a frame dump.

AI-assisted (Claude Code).

**@⁠Machad3x** on GitHub · 2026-11-25 12:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7162378949) In-game check of this branch (the PR's "Not yet checked in game" item), RTX 3080 Ti, driver 621.24, Windows 11. Both commits (a54e0c84, 1853bce5) cherry-picked onto a local stack of `main` 940d32f with other open PRs, including #439. - `emit::rect` tests on the hardware adapter run: 3 passed. - 5-minute run without the commits: saw-tooth triangles on a regular tile grid, most visibly along the bottom edge of the picture and along geometry edges (seen in two separate runs). - 5-minute run with them, same stack otherwise: no such triangles in the inspected screenshots (240 s and 300 s). No device removal; frame rate unchanged (about 1.1 fps). Only the screenshots were inspected, not a frame dump. AI-assisted (Claude Code).
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 12:28 UTC · original

@⁠Machad3x thank you for the in-game check: it is the first one on hardware, and it matches what the tiled-lighting draws led us to expect. Your note that the frame rate stayed the same is useful too, since the fix adds a few instructions to every rectangle.

@⁠Melow-code thanks for the review. Taking the three points in order, from the code at 1853bce5:

w = 0. Bin::SDiv is LLVM's binary opcode 4, and on float operands it is fdiv (the same opcode v_rcp_f32 uses in lower.rs). So a zero w gives ±inf or NaN, not an undefined value. If any corner's x/w or y/w is inf or NaN, the two sides that touch it come out inf or NaN. OGT is ordered, so it is false for NaN and for inf > inf, and the only finite side is never the longest. Both first and third are then false, and pick takes the second corner, which is main's rule (v0 + v2 - v1). A degenerate w falls back to the old behaviour without needing a guard. I have not checked what happens when the three corners' w have different signs (some corners behind the eye). The pick then works on the mirrored projected points.

Tests. The three input orders have a test each in emit/rect.rs: rectangles_get_their_fourth_corner (the right angle second), rectangles_with_the_corner_first_complete_across_their_diagonal and rectangles_with_the_corner_third_complete_across_their_diagonal. Each one draws the square into 32x32 and checks every pixel on WARP and on the hardware adapter. You are right that the fallbacks have no test: no position output, a position with fewer than 4 columns, and a zero w. I'll add tests for them and report back here.

Ties. A strict tie can only happen when two sides are equal and longer than the third. A real rectangle's three corners form a right triangle, and its hypotenuse is strictly the longest side, so a rectangle never ties. A tie means the input is not a rectangle (it is degenerate, or equilateral, or similar). Then both comparisons are false and the second corner is used, whatever the order, so the tie case is order-independent by construction: it is main's old rule. That is intended.

No title data was used for this reply (code reading only).

AI-assisted (Claude Code).

**@⁠r4tedx** on GitHub · 2026-11-25 12:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7162422086) @⁠Machad3x thank you for the in-game check: it is the first one on hardware, and it matches what the tiled-lighting draws led us to expect. Your note that the frame rate stayed the same is useful too, since the fix adds a few instructions to every rectangle. @⁠Melow-code thanks for the review. Taking the three points in order, from the code at 1853bce5: **w = 0.** `Bin::SDiv` is LLVM's binary opcode 4, and on float operands it is `fdiv` (the same opcode `v_rcp_f32` uses in `lower.rs`). So a zero w gives ±inf or NaN, not an undefined value. If any corner's x/w or y/w is inf or NaN, the two sides that touch it come out inf or NaN. `OGT` is ordered, so it is false for NaN and for inf > inf, and the only finite side is never the longest. Both `first` and `third` are then false, and `pick` takes the second corner, which is main's rule (`v0 + v2 - v1`). A degenerate w falls back to the old behaviour without needing a guard. I have not checked what happens when the three corners' w have different signs (some corners behind the eye). The pick then works on the mirrored projected points. **Tests.** The three input orders have a test each in `emit/rect.rs`: `rectangles_get_their_fourth_corner` (the right angle second), `rectangles_with_the_corner_first_complete_across_their_diagonal` and `rectangles_with_the_corner_third_complete_across_their_diagonal`. Each one draws the square into 32x32 and checks every pixel on WARP and on the hardware adapter. You are right that the fallbacks have no test: no position output, a position with fewer than 4 columns, and a zero w. I'll add tests for them and report back here. **Ties.** A strict tie can only happen when two sides are equal and longer than the third. A real rectangle's three corners form a right triangle, and its hypotenuse is strictly the longest side, so a rectangle never ties. A tie means the input is not a rectangle (it is degenerate, or equilateral, or similar). Then both comparisons are false and the second corner is used, whatever the order, so the tie case is order-independent by construction: it is main's old rule. That is intended. No title data was used for this reply (code reading only). AI-assisted (Claude Code).
Author
Owner

@⁠hah346 on GitHub · 2026-11-25 12:57 UTC · original

Turing hardware result for #2366 at 1853bce5016d2be0ab6c397da7fab6ea4c9dc1d2, as requested in #439. Windows 11 build 26300, RTX 2060 (6 GiB), NVIDIA 616.64, Rust 1.98.1 MSVC.

Clean checkout, VICTORY_WARP unset: cargo test -p victory-shader --lib --locked emit::rect -- --test-threads=1 gave 3 passed, 0 failed, 0 ignored (1.12 s).

I also reran with temporary test-only diagnostics to rule out an adapter skip. All three cases explicitly selected the RTX 2060 for warp false and Microsoft Basic Render Driver for warp true. Each case returned 1,024 texels per adapter, and all existing pixel checks passed (3,072 pixels per adapter, 6,144 total). The checkout is clean again. Synthetic fixtures only; AI-assisted with Codex.

**@⁠hah346** on GitHub · 2026-11-25 12:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7163099740) Turing hardware result for #2366 at `1853bce5016d2be0ab6c397da7fab6ea4c9dc1d2`, as requested in #439. Windows 11 build 26300, RTX 2060 (6 GiB), NVIDIA 616.64, Rust 1.98.1 MSVC. Clean checkout, `VICTORY_WARP` unset: `cargo test -p victory-shader --lib --locked emit::rect -- --test-threads=1` gave **3 passed, 0 failed, 0 ignored** (1.12 s). I also reran with temporary test-only diagnostics to rule out an adapter skip. All three cases explicitly selected the RTX 2060 for `warp false` and Microsoft Basic Render Driver for `warp true`. Each case returned 1,024 texels per adapter, and all existing pixel checks passed (3,072 pixels per adapter, 6,144 total). The checkout is clean again. Synthetic fixtures only; AI-assisted with Codex.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 12:59 UTC · original

@⁠Melow-code following up on the tests I said I'd add: head is now d29e14f7 (one test-only commit on 1853bce5).

  • Zero w: rectangles_with_zero_w_complete_from_the_second_corner draws a rectangle whose second corner has w = 0 and checks a pixel the fourth corner weighs into. The comparisons come out unordered, so the completion falls back to main's rule (v0 + v2 - v1), as I described above. It passes on WARP.
  • No position output: no new code there. first and third are None, and pick returns the second corner, which is main's rule unchanged. So there's no new test for it.
  • A position with two or three columns: this path does use the new comparison (on x and y, without the divide), but no draw can reach it. A rasterized SV_Position must have four components, so the validator refuses anything shorter. I tried testing it through the emitted DXIL text, but that means starting dxc from a test and matching exact value numbers, so I dropped it.
  • The drawing helper now keeps to WARP when VICTORY_WARP=1 is set.

Rect tests on WARP: 4 passed. cargo clippy -p victory-shader --tests -- -D warnings: clean. Synthetic tests only; no title data used.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 12:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7163131593) @⁠Melow-code following up on the tests I said I'd add: head is now `d29e14f7` (one test-only commit on `1853bce5`). - **Zero w:** `rectangles_with_zero_w_complete_from_the_second_corner` draws a rectangle whose second corner has w = 0 and checks a pixel the fourth corner weighs into. The comparisons come out unordered, so the completion falls back to main's rule (`v0 + v2 - v1`), as I described above. It passes on WARP. - **No position output:** no new code there. `first` and `third` are `None`, and `pick` returns the second corner, which is main's rule unchanged. So there's no new test for it. - **A position with two or three columns:** this path does use the new comparison (on x and y, without the divide), but no draw can reach it. A rasterized `SV_Position` must have four components, so the validator refuses anything shorter. I tried testing it through the emitted DXIL text, but that means starting `dxc` from a test and matching exact value numbers, so I dropped it. - The drawing helper now keeps to WARP when `VICTORY_WARP=1` is set. Rect tests on WARP: 4 passed. `cargo clippy -p victory-shader --tests -- -D warnings`: clean. Synthetic tests only; no title data used. AI-assisted
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 12:59 UTC · original

@⁠hah346 thank you. That's the first hardware run of the rect tests on Turing, and checking which adapter was picked rules out a silent skip.

The head has since moved to d29e14f7: one test-only commit on 1853bce5 that adds rectangles_with_zero_w_complete_from_the_second_corner. The fix itself is unchanged, so your result holds for it. A rerun at the new head would give 4 tests per adapter, if you want to cover the new one as well.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 12:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7163143498) @⁠hah346 thank you. That's the first hardware run of the rect tests on Turing, and checking which adapter was picked rules out a silent skip. The head has since moved to `d29e14f7`: one test-only commit on `1853bce5` that adds `rectangles_with_zero_w_complete_from_the_second_corner`. The fix itself is unchanged, so your result holds for it. A rerun at the new head would give 4 tests per adapter, if you want to cover the new one as well. AI-assisted
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 13:02 UTC · original

In-title result for this PR on hardware, since it has only run on WARP and macOS so far.

Setup: Grand Theft Auto VI Series X, the first mission's prison yard (player character at the window). RTX 5080 on Linux, Proton with vkd3d-proton 3.2.0 and the NVIDIA 580 driver. I built our working branch (main plus our open GPU fixes) with this PR merged at 1853bce, then compared it with the same branch without this PR in the same scene.

Without this PR: rows of light right-angled triangles in every frame. They run along the top edge above the window, along the bottom edge of the screen, across the window frame, and cut diagonally into the player character's neck and shoulders. Each one looks like half of a quad.

With this PR: all of those rows are gone. The rest of the picture is unchanged, at 4,861 draws per frame.

The tests also pass here: cargo test -p victory-shader --lib --locked emit::rect -- --test-threads=1 gives 3 passed. That's weak evidence, though. Under Wine, DXVK's DXGI has no WARP adapter (EnumWarpAdapter: WARP not supported, returning first hardware adapter), so both sides of the comparison ran on the RTX 5080. The in-title result is the part that matters.

How it was found: the triangle rows showed up in every screenshot of this scene, and their regular half-quad shape pointed at rectangle expansion. I merged this PR into the same build and the user compared the two runs by eye.

Without this PR (same scene):
2026-11-25_08-01_1

With this PR:
2026-11-25_08-01

**@⁠desplmfao** on GitHub · 2026-11-25 13:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7163202198) In-title result for this PR on hardware, since it has only run on WARP and macOS so far. **Setup:** Grand Theft Auto VI Series X, the first mission's prison yard (player character at the window). RTX 5080 on Linux, Proton with vkd3d-proton 3.2.0 and the NVIDIA 580 driver. I built our working branch (`main` plus our open GPU fixes) with this PR merged at `1853bce`, then compared it with the same branch without this PR in the same scene. **Without this PR:** rows of light right-angled triangles in every frame. They run along the top edge above the window, along the bottom edge of the screen, across the window frame, and cut diagonally into the player character's neck and shoulders. Each one looks like half of a quad. **With this PR:** all of those rows are gone. The rest of the picture is unchanged, at 4,861 draws per frame. The tests also pass here: `cargo test -p victory-shader --lib --locked emit::rect -- --test-threads=1` gives 3 passed. That's weak evidence, though. Under Wine, DXVK's DXGI has no WARP adapter (`EnumWarpAdapter: WARP not supported, returning first hardware adapter`), so both sides of the comparison ran on the RTX 5080. The in-title result is the part that matters. **How it was found:** the triangle rows showed up in every screenshot of this scene, and their regular half-quad shape pointed at rectangle expansion. I merged this PR into the same build and the user compared the two runs by eye. **Without this PR** (same scene): <img width="2241" height="1256" alt="2026-11-25_08-01_1" src="https://github.com/user-attachments/assets/43b39501-cddd-4149-9057-4d1148060331" /> **With this PR:** <img width="2200" height="1288" alt="2026-11-25_08-01" src="https://github.com/user-attachments/assets/de225542-3030-40b7-adb1-3dbe535a1122" />
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 13:03 UTC · original

@⁠desplmfao thank you. It's the first in-title check on vkd3d-proton under Linux, and the before/after in one scene shows exactly the half-quad rows this was meant to remove.

Your note on the tests is a good one to have on record. Under Wine, DXVK's DXGI hands back the first hardware adapter when asked for WARP, so on that setup both halves of each rect test run on the RTX 5080, as you say. The head is now d29e14f7 (one test-only commit adding a zero-w case). The fix is the same, so your result applies to it.

This reply is based only on reading your report and the PR's code; no title data was used.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 13:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7163235381) @⁠desplmfao thank you. It's the first in-title check on vkd3d-proton under Linux, and the before/after in one scene shows exactly the half-quad rows this was meant to remove. Your note on the tests is a good one to have on record. Under Wine, DXVK's DXGI hands back the first hardware adapter when asked for WARP, so on that setup both halves of each rect test run on the RTX 5080, as you say. The head is now `d29e14f7` (one test-only commit adding a zero-w case). The fix is the same, so your result applies to it. This reply is based only on reading your report and the PR's code; no title data was used. AI-assisted
Author
Owner

@⁠hah346 on GitHub · 2026-11-25 13:03 UTC · original

Reran at d29e14f7802647acfe0b0a9e5e167c4e86af6687 on the same Windows 11 / RTX 2060 (616.64) setup, with VICTORY_WARP unset. The clean checkout gave 4 passed, 0 failed, 0 ignored (1.40 s).

A separate diagnostic rerun confirmed that all four cases, including rectangles_with_zero_w_complete_from_the_second_corner, drew and passed their existing checks on both the RTX 2060 and Microsoft WARP. The adapter checks were local to the test and the checkout is clean again. Synthetic fixtures only; AI-assisted with Codex.

**@⁠hah346** on GitHub · 2026-11-25 13:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7163240483) Reran at `d29e14f7802647acfe0b0a9e5e167c4e86af6687` on the same Windows 11 / RTX 2060 (616.64) setup, with `VICTORY_WARP` unset. The clean checkout gave **4 passed, 0 failed, 0 ignored** (1.40 s). A separate diagnostic rerun confirmed that all four cases, including `rectangles_with_zero_w_complete_from_the_second_corner`, drew and passed their existing checks on both the RTX 2060 and Microsoft WARP. The adapter checks were local to the test and the checkout is clean again. Synthetic fixtures only; AI-assisted with Codex.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 14:50 UTC · original

Automated triage for the maintainers.

Merge candidate. rectangle_gs in crates/victory-shader/src/emit/rect.rs no longer assumes the right-angle corner of a rectangle-list primitive is the second vertex: it picks the corner opposite the longest screen-space side and completes (a, b, a + b - c), falling back to main's v0 + v2 - v1 with no position, a tie, or a non-finite x/w. I checked that Bin::SDiv/Bin::Add on f32 operands encode as fdiv/fadd (as elsewhere in the lowering), that OGT is ordered so NaN/inf falls back to the old rule, and that the winding of the second triangle matches the first in all three orders. The evidence is the title's own tiled-lighting vertex shaders (corners given top left, bottom left, top right), plus independent in-title before/after reports in the thread; the tests cover all three orders and zero w on hardware and WARP.

Caveats for the maintainer: primitive.rs's CPU fallback keeps the second-corner rule, and #1907 touches the same function.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 14:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7165886341) <!-- victory-triage v1 head=d29e14f7802647acfe0b0a9e5e167c4e86af6687 verdict=merge-candidate at=2026-11-25T14:49:51Z --> Automated triage for the maintainers. **Merge candidate.** `rectangle_gs` in `crates/victory-shader/src/emit/rect.rs` no longer assumes the right-angle corner of a rectangle-list primitive is the second vertex: it picks the corner opposite the longest screen-space side and completes `(a, b, a + b - c)`, falling back to `main`'s `v0 + v2 - v1` with no position, a tie, or a non-finite `x/w`. I checked that `Bin::SDiv`/`Bin::Add` on f32 operands encode as `fdiv`/`fadd` (as elsewhere in the lowering), that `OGT` is ordered so NaN/inf falls back to the old rule, and that the winding of the second triangle matches the first in all three orders. The evidence is the title's own tiled-lighting vertex shaders (corners given top left, bottom left, top right), plus independent in-title before/after reports in the thread; the tests cover all three orders and zero w on hardware and WARP. Caveats for the maintainer: `primitive.rs`'s CPU fallback keeps the second-corner rule, and #1907 touches the same function. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 15:49 UTC · original

Closing this as superseded by 8ff79135 on main ("rectangles complete opposite their right angle, wherever it is"). It finds the corner opposite the longest side the same way, keeps v1 on ties and NaN, and covers the CPU expansion too. Thanks to everyone who tested this, especially Machad3x for the RTX 3080 Ti confirmation and Melow-code for the review.

Two small differences, for the record only:

  • This PR compared the sides after dividing x and y by w. That only changes the result when a rectangle's corners have different w, which screen-aligned rectangle lists don't normally have.
  • With no position output, this PR fell back to v1, where main returns Malformed.

If a title ever turns up a case where either matters, I'll send a small follow-up against main.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 15:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7167338372) Closing this as superseded by 8ff79135 on main ("rectangles complete opposite their right angle, wherever it is"). It finds the corner opposite the longest side the same way, keeps `v1` on ties and NaN, and covers the CPU expansion too. Thanks to everyone who tested this, especially Machad3x for the RTX 3080 Ti confirmation and Melow-code for the review. Two small differences, for the record only: - This PR compared the sides after dividing x and y by w. That only changes the result when a rectangle's corners have different w, which screen-aligned rectangle lists don't normally have. - With no position output, this PR fell back to `v1`, where main returns `Malformed`. If a title ever turns up a case where either matters, I'll send a small follow-up against main. AI-assisted
Author
Owner

@⁠Slay326 on GitHub · 2026-11-25 16:25 UTC · original · edited 2026-11-25 16:27 UTC

Note: I posted this after the PR was closed as superseded by 8ff79135 on main; the run below used this PR's head, not 8ff79135. Leaving it for the record, since it is the same fix on the same scene. I have not yet run 8ff79135 itself on this card.

Hardware test: this fixes the orange triangles on an RTX 3070. RTX 3070 (8 GB, 32-lane waves), Windows 11, Series X mode, 480 s runs into the world of Grand Theft Auto VI 1.0.2.1. Local test branch: main 940d32f plus #1906, #1890, #1883, #1962, #1779, #1763, #1762, a page-mark guard like #2167 and the memory PRs #2129, #2180, #1873, #1969, #2161.

Before: orange right triangles along tile edges over the whole screen in the lit world (the tiled-lighting rectangle draws VS_TiledLighting, VS_TiledWeathering_*, VS_Blit; the lighting target showed the second triangle of each tile one tile up, as the description says).

With this PR (merged without conflicts, together with #158, #2342, #2324, #2363, #2348, #1014): the triangles are gone in the same cell scene. 480 s run, no device removal, world median 1.9 fps. victory-shader 270 passed, 0 failed on this card.

AI-assisted.

**@⁠Slay326** on GitHub · 2026-11-25 16:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2366#issuecomment-7167956014) · edited 2026-11-25 16:27 UTC Note: I posted this after the PR was closed as superseded by 8ff79135 on main; the run below used this PR's head, not 8ff79135. Leaving it for the record, since it is the same fix on the same scene. I have not yet run 8ff79135 itself on this card. Hardware test: this fixes the orange triangles on an RTX 3070. RTX 3070 (8 GB, 32-lane waves), Windows 11, Series X mode, 480 s runs into the world of Grand Theft Auto VI 1.0.2.1. Local test branch: main 940d32f plus #1906, #1890, #1883, #1962, #1779, #1763, #1762, a page-mark guard like #2167 and the memory PRs #2129, #2180, #1873, #1969, #2161. **Before:** orange right triangles along tile edges over the whole screen in the lit world (the tiled-lighting rectangle draws `VS_TiledLighting`, `VS_TiledWeathering_*`, `VS_Blit`; the lighting target showed the second triangle of each tile one tile up, as the description says). **With this PR** (merged without conflicts, together with #158, #2342, #2324, #2363, #2348, #1014): the triangles are gone in the same cell scene. 480 s run, no device removal, world median 1.9 fps. `victory-shader` 270 passed, 0 failed on this card. AI-assisted.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2366
No description provided.