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

Merged
Sheffy007 merged 1 commit from upstream-pr/369 into main 2026-11-27 16:04:48 +00:00
Sheffy007 commented 2026-11-27 14:26:24 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T14:26:24Z.


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 #338).

  • 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 #360
Refs #258, #16

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5528256792 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/369). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T14:26:24Z. --- ### 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 #338). - **`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 #360 Refs #258, #16
LakshanSivakumar commented 2026-11-27 16:05:08 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:05:08Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222837446 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/369#issuecomment-7222837446). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:05:08Z. --- 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.
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
LakshanSivakumar/Native-Victory-macOS!369
No description provided.