fix(shader): reconstruct fourth corner and instance ids for SV_VertexID rectangle lists #372

Manually merged
github merged 1 commit from github-bot/gh-369 into main 2026-11-27 16:13:15 +00:00 AGit
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 14:26 UTC · original
Sheffy007:fix/rect-list-vertex-id-corners → main · +731 −115 · 6 files · 1 commits · merged 2026-11-27 16:04 UTC

Summary

Fixes Options::rect_list translation for guessed vertex programs that compute corner positions or varyings from SV_VertexID (v0) rather than solely via VERTEX_TABLE stage-in fetches (the free item noted on #339).

  • Lower::rect_vertex_id (crates/victory-shader/src/emit/lower/rect.rs): Detects guessed Options::rect_list vertex programs where Reg::V(0) (Input::VertexId) is read outside the ignored vertex-index operand of an indexed VERTEX_TABLE stage-in fetch. Pure vertex-buffer rect_list programs and all rect_list: false programs take the existing single-pass path unchanged.
  • Lower::run_rect_by_id: Evaluates the vertex program body for the rectangle's three console vertex IDs 3 * SV_InstanceID + 0..2 (keeping Reg::V(3) Input::InstanceId at 0 as on the console's non-instanced rectangle list, and refusing UAV-writing programs rather than replaying side effects), finds the right-angle corner opposite the longest SV_Position.xy side, extrapolates the fourth corner p + q - r across every exported float channel (preserving bitwise-equal shared values exactly), selects (p, r, fourth, q) by the host strip vertex ID 0..3, and emits all storeOutput calls back to back (#181).

Verification

  • victory-gpu native::tests::mesh_tests::a_rectangle_of_a_vertex_id_program_covers_half_its_rectangle: RECT_BY_ID now lights all 64 of 64 texels (was 28 of 64) on Metal, for both direct draws and ExecuteIndirect (an_indirect_rectangle_list_draws_its_records_as_a_direct_one).
  • victory-gpu native::tests::mesh_tests::vertex_id_rectangle_lists_draw_half_tiles_multiple_rects_and_interpolated_params: Metal execution test verifying a half-size tile (32 of 64 texels), a two-rectangle draw (vertices = 6, 48 of 64 texels, both direct and draw_rects_indirect) with differing right-angle corner indices, and linear TEXCOORD interpolation across the extrapolated fourth corner.
  • victory-shader emit::export_tests::a_vertex_id_rect_list_export_makes_every_value_before_its_first_store: verifies all output values precede the first storeOutput of their element.
  • cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask, both Windows clippy passes (-- -D warnings), and cargo xtask policy pass.

Closes #363
Refs #258, #16

**@⁠Sheffy007** on GitHub · 2026-11-27 14:26 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/369) `Sheffy007:fix/rect-list-vertex-id-corners` → `main` · +731 −115 · 6 files · 1 commits · merged 2026-11-27 16:04 UTC ### Summary Fixes `Options::rect_list` translation for guessed vertex programs that compute corner positions or varyings from `SV_VertexID` (`v0`) rather than solely via `VERTEX_TABLE` stage-in fetches (the free item noted on #339). - **`Lower::rect_vertex_id` (`crates/victory-shader/src/emit/lower/rect.rs`):** Detects guessed `Options::rect_list` vertex programs where `Reg::V(0)` (`Input::VertexId`) is read outside the ignored vertex-index operand of an indexed `VERTEX_TABLE` stage-in fetch. Pure vertex-buffer `rect_list` programs and all `rect_list: false` programs take the existing single-pass path unchanged. - **`Lower::run_rect_by_id`:** Evaluates the vertex program body for the rectangle's three console vertex IDs `3 * SV_InstanceID + 0..2` (keeping `Reg::V(3)` `Input::InstanceId` at `0` as on the console's non-instanced rectangle list, and refusing UAV-writing programs rather than replaying side effects), finds the right-angle corner opposite the longest `SV_Position.xy` side, extrapolates the fourth corner `p + q - r` across every exported float channel (preserving bitwise-equal shared values exactly), selects `(p, r, fourth, q)` by the host strip vertex ID `0..3`, and emits all `storeOutput` calls back to back (#181). ### Verification - `victory-gpu` `native::tests::mesh_tests::a_rectangle_of_a_vertex_id_program_covers_half_its_rectangle`: `RECT_BY_ID` now lights all **64 of 64** texels (was 28 of 64) on Metal, for both direct draws and `ExecuteIndirect` (`an_indirect_rectangle_list_draws_its_records_as_a_direct_one`). - `victory-gpu` `native::tests::mesh_tests::vertex_id_rectangle_lists_draw_half_tiles_multiple_rects_and_interpolated_params`: Metal execution test verifying a half-size tile (**32 of 64** texels), a two-rectangle draw (`vertices = 6`, **48 of 64** texels, both direct and `draw_rects_indirect`) with differing right-angle corner indices, and linear `TEXCOORD` interpolation across the extrapolated fourth corner. - `victory-shader` `emit::export_tests::a_vertex_id_rect_list_export_makes_every_value_before_its_first_store`: verifies all output values precede the first `storeOutput` of their element. - `cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask`, both Windows `clippy` passes (`-- -D warnings`), and `cargo xtask policy` pass. Closes #363 Refs #258, #16
When Options::rect_list lowers a guessed vertex program that reads Reg::V(0)
(SV_VertexID) outside the ignored vertex-index operand of a VERTEX_TABLE
stage-in fetch, run the program body for console vertex ids 3 * SV_InstanceID +
0..2 (with InstanceId fixed at 0), find the right-angle corner opposite the
longest SV_Position.xy side, extrapolate p + q - r across every float output,
and emit all storeOutput calls back to back.

Closes #360
Refs #258, #16
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:28:38 +00:00
github manually merged commit f9631f0897 into main 2026-11-27 16:13:15 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 16:05 UTC · original

Merged in be7dc1b5 with the other shader PRs from tonight. Ran the tests (native arm64), Windows clippy, the policy check and a release build on the merged tree, and swept my full corpus of 21,600 shaders before and after: 0 lost, 352 newly translated, every changed output accounted for. I have not run the game on it yet. Thanks.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 16:05 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/369#issuecomment-7222837446) Merged in be7dc1b5 with the other shader PRs from tonight. Ran the tests (native arm64), Windows clippy, the policy check and a release build on the merged tree, and swept my full corpus of 21,600 shaders before and after: 0 lost, 352 newly translated, every changed output accounted for. I have not run the game on it yet. Thanks.
This discussion has been locked. Commenting is limited to contributors.
No description provided.