GPU: keep rectangle corners consistent across vertex streams #2729

Open
github-bot wants to merge 4 commits from github-bot/gh-2729 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 19:01 UTC · original
andrewpozdnakov7-jpg:fix/rectangle-stream-corner → main · +441 −38 · 3 files · 4 commits · open

The CPU fallback for rectangle draws chose a right-angle vertex in each vertex buffer. A separate RGBA8 color stream could use its fallback vertex even when the position stream chose a different one. Its attributes then went to the wrong vertices of the second triangle.

Choose the corners once from the explicit POSITION input when available, with the existing float-position heuristic as fallback. Use the same corners to expand every per-vertex stream.

The same WARP regression submits a rectangle through VIctory's draw vtable with positions and colors in separate buffers and a nonzero start vertex. On 13f91ca the bottom-right texel reads [0.75, 0, 0, 1]. On f701a1d it reads [0.75, 0.75, 0, 1]. The top-left control reads [0.25, 0.25, 0, 1] in both. Six paired runs reproduced the result across both D3D12 debug settings.

The second case puts a float color in slot 0 and POSITION in slot 1. On f701a1d the bottom-right texel is clear. On 5f92980 it reads [0.75, 1.5, 0, 1]. The original RGBA8 case still passes. Six paired WARP runs reproduce the second result across both debug settings.

The third case binds a four-byte RGBA8 buffer with stride zero, so the input assembler reads one color for every vertex. On 5f92980 both sampled texels are clear. On bd0226e both read [1, 0, 0, 1]. The expanded draw keeps the input assembler view for this constant stream. The two earlier layouts still pass.

The serial GPU suite passed 199 tests with one ignored in each setting. Strict GPU Clippy with both feature configurations and asset policy passed. AI-assisted using Codex. Synthetic vertex data.

Coordination claim

Please keep the Git author when reapplying the commit. If you fold the change or test into another commit, please add:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 19:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2729) `andrewpozdnakov7-jpg:fix/rectangle-stream-corner` → `main` · +441 −38 · 3 files · 4 commits · open The CPU fallback for rectangle draws chose a right-angle vertex in each vertex buffer. A separate RGBA8 color stream could use its fallback vertex even when the position stream chose a different one. Its attributes then went to the wrong vertices of the second triangle. Choose the corners once from the explicit POSITION input when available, with the existing float-position heuristic as fallback. Use the same corners to expand every per-vertex stream. The same WARP regression submits a rectangle through VIctory's draw vtable with positions and colors in separate buffers and a nonzero start vertex. On 13f91ca the bottom-right texel reads [0.75, 0, 0, 1]. On f701a1d it reads [0.75, 0.75, 0, 1]. The top-left control reads [0.25, 0.25, 0, 1] in both. Six paired runs reproduced the result across both D3D12 debug settings. The second case puts a float color in slot 0 and POSITION in slot 1. On f701a1d the bottom-right texel is clear. On 5f92980 it reads [0.75, 1.5, 0, 1]. The original RGBA8 case still passes. Six paired WARP runs reproduce the second result across both debug settings. The third case binds a four-byte RGBA8 buffer with stride zero, so the input assembler reads one color for every vertex. On 5f92980 both sampled texels are clear. On bd0226e both read [1, 0, 0, 1]. The expanded draw keeps the input assembler view for this constant stream. The two earlier layouts still pass. The serial GPU suite passed 199 tests with one ignored in each setting. Strict GPU Clippy with both feature configurations and asset policy passed. AI-assisted using Codex. Synthetic vertex data. [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) Please keep the Git author when reapplying the commit. If you fold the change or test into another commit, please add: Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:12:54 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 19:04 UTC · original

Correct fix for a real per-stream divergence: expand_rects previously picked the right-angle corner independently per stream, so an RGBA8 color stream could choose a different corner than the position stream and scramble the second triangle's attributes. Choosing corners once via find_map over streams (first stream whose elements yield a usable float position) and sharing them across all expands is the right shape; corners.as_deref().unwrap_or_default() keeps a sane fallback when no stream yields one. Collapsing the per-slot defer_host calls into one closure is also tidier. The regression test (separate position/color buffers, nonzero start vertex, texel asserts) reproduces the exact failure.

**@⁠kotekompotek** on GitHub · 2026-11-25 19:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/2729#issuecomment-7171795540) Correct fix for a real per-stream divergence: expand_rects previously picked the right-angle corner independently per stream, so an RGBA8 color stream could choose a different corner than the position stream and scramble the second triangle's attributes. Choosing corners once via find_map over streams (first stream whose elements yield a usable float position) and sharing them across all expands is the right shape; corners.as_deref().unwrap_or_default() keeps a sane fallback when no stream yields one. Collapsing the per-slot defer_host calls into one closure is also tidier. The regression test (separate position/color buffers, nonzero start vertex, texel asserts) reproduces the exact failure.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 19:10 UTC · original · edited 2026-11-25 19:14 UTC

I reran the rectangle with float colors in slot 0 and POSITION in slot 1. On f701a1d the fallback chose its angle from color and left the bottom-right texel clear. 5f92980 prioritizes the named position and reads [0.75, 1.5, 0, 1]. The original separate RGBA8 case still passes. Six paired WARP runs, the serial GPU suite (199 passed, one ignored) in both debug settings, strict Clippy and asset policy passed.

I also ran DrDarkDK's exact TEXCOORD example with [(0,1), (0,0), (1,0)] in slot 0. The bottom-right texel is clear on f701a1d and reads [0.75, -0.5, 0, 1] on 5f92980. CI passed on the updated head.

Please keep the Git author on cherry-pick or rebase. If the solution or tests are folded into another commit, please add:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 19:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2729#issuecomment-7171927816) · edited 2026-11-25 19:14 UTC I reran the rectangle with float colors in slot 0 and POSITION in slot 1. On f701a1d the fallback chose its angle from color and left the bottom-right texel clear. [5f92980](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/5f92980ee99565b394ef8e6bd551c044636a7866) prioritizes the named position and reads [0.75, 1.5, 0, 1]. The original separate RGBA8 case still passes. Six paired WARP runs, the serial GPU suite (199 passed, one ignored) in both debug settings, strict Clippy and asset policy passed. I also ran [DrDarkDK's exact TEXCOORD example](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2729) with [(0,1), (0,0), (1,0)] in slot 0. The bottom-right texel is clear on f701a1d and reads [0.75, -0.5, 0, 1] on 5f92980. [CI passed on the updated head](https://github.com/Marvisak/VIctory/actions/runs/45682605530/job/139446775325). Please keep the Git author on cherry-pick or rebase. If the solution or tests are folded into another commit, please add: Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 19:24 UTC · original · edited 2026-11-25 19:37 UTC

The expanded draw also needs to keep a valid zero-stride vertex stream. I added a four-byte RGBA8 buffer containing opaque red. Both sampled texels are clear on 5f92980. bd0226e reuses the bound vertex view and both read [1, 0, 0, 1] on WARP. The two earlier layouts pass. Six paired runs, the serial GPU suite (199 passed, one ignored) in both debug settings, strict Clippy and asset policy passed.

Please retain the Git author on cherry-pick or rebase. If you fold the change or test into another commit, please add:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

The GitHub check failed on the frame-pacing test, whose source is identical to main at 13f91ca. I reproduced its S_OK versus TIMEOUT assertion with a simulated late poll and updated the existing fixture PR, #2265, in 303be14. A maintainer rerun of the check on bd0226e would help verify the current rectangle head independently.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 19:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2729#issuecomment-7172244852) · edited 2026-11-25 19:37 UTC The expanded draw also needs to keep a valid zero-stride vertex stream. I added a four-byte RGBA8 buffer containing opaque red. Both sampled texels are clear on 5f92980. [bd0226e](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/bd0226e68c9de8b5f38b5b160fddb4bcd65ba1e1) reuses the bound vertex view and both read [1, 0, 0, 1] on WARP. The two earlier layouts pass. Six paired runs, the serial GPU suite (199 passed, one ignored) in both debug settings, strict Clippy and asset policy passed. Please retain the Git author on cherry-pick or rebase. If you fold the change or test into another commit, please add: Co-authored-by: andrewpozdnakov7-jpg <[email protected]> The [GitHub check](https://github.com/Marvisak/VIctory/actions/runs/45684843740/job/139454597062) failed on the frame-pacing test, whose source is identical to main at 13f91ca. I reproduced its S_OK versus TIMEOUT assertion with a simulated late poll and updated the existing fixture PR, [#2265](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2265), in [303be14](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/303be14ec53ab5ca1ce2ea9a0e246a7aa0b785e7). A maintainer rerun of the check on bd0226e would help verify the current rectangle head independently.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:36 UTC · original

Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP verification and review of bd0226e6 (on 13f91ca):

Verification (rustc 1.98.1 MSVC)

  • cargo xtask policy: 184 files ok.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings and --features diagnostics: 0 warnings.
  • RTX 5090: cargo test --locked -p victory-gpu --lib -- primitive (9 passed) and rect (12 passed, including cpu_rectangle_uses_the_position_corner_order_for_split_vertex_streams).
  • WARP (VICTORY_D3D12_WARP=1): cargo test --locked -p victory-gpu --features diagnostics -> 199 passed, 0 failed, 1 ignored.

Review & Merge-Ordering Notes

  • Computing corners once from the POSITION (index 0) stream — with fallback to the first F32/F16 attribute stream and v1 default — keeps split vertex streams consistent, and the stride == 0 constant-stream handling (v.address != 0 && v.size != 0 && shadow::find(...)) skips CPU expansion cleanly.
  • Merge-ordering notes: cleanly orthogonal to #2603 (victory-shader/src/emit/rect.rs, which improves right_angle that this PR calls); conflicts in crates/victory-gpu/src/draw.rs::State::rectangles with #2727 (f712e159, which adds checked arithmetic for first + count / SizeInBytes overflow) — both are semantically complementary and straightforward to rebase together.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2729#issuecomment-7172526647) Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP verification and review of `bd0226e6` (on `13f91ca`): ### Verification (`rustc 1.98.1` MSVC) - `cargo xtask policy`: **184 files ok**. - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` and `--features diagnostics`: **0 warnings**. - **RTX 5090:** `cargo test --locked -p victory-gpu --lib -- primitive` (**9 passed**) and `rect` (**12 passed**, including `cpu_rectangle_uses_the_position_corner_order_for_split_vertex_streams`). - **WARP (`VICTORY_D3D12_WARP=1`):** `cargo test --locked -p victory-gpu --features diagnostics` -> **199 passed, 0 failed, 1 ignored**. ### Review & Merge-Ordering Notes - Computing `corners` once from the `POSITION` (index 0) stream — with fallback to the first `F32`/`F16` attribute stream and `v1` default — keeps split vertex streams consistent, and the `stride == 0` constant-stream handling (`v.address != 0 && v.size != 0 && shadow::find(...)`) skips CPU expansion cleanly. - **Merge-ordering notes:** cleanly orthogonal to #2603 (`victory-shader/src/emit/rect.rs`, which improves `right_angle` that this PR calls); conflicts in `crates/victory-gpu/src/draw.rs::State::rectangles` with #2727 (`f712e159`, which adds checked arithmetic for `first + count` / `SizeInBytes` overflow) — both are semantically complementary and straightforward to rebase together.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 22:51 UTC · original

I resolved the test-module conflict and merged current main 842b0cb in 857f394.

The same WARP draw on 219878a yields bottom-right [0.75, 0, 0, 1] for the split UNORM streams. The updated branch yields [0.75, 0.75, 0, 1] and passes the float-first and constant-stride controls. Both serial GPU suites on the final revision passed 247 tests with one ignored, including the upstream depth-bounds tests and the frame-timing test that failed in the previous CI run. Both strict GPU Clippy modes and asset policy passed.

Please retain the Git author when moving the fix or tests. If squashing them into another commit, please add this trailer.

Co-authored-by: andrewpozdnakov7-jpg [email protected]

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 22:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2729#issuecomment-7176868914) I resolved the test-module conflict and merged current main `842b0cb` in [857f394](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/857f394ebe5a7f8d1b4100979cd801eb4ac4deb8). The same WARP draw on `219878a` yields bottom-right `[0.75, 0, 0, 1]` for the split UNORM streams. The updated branch yields `[0.75, 0.75, 0, 1]` and passes the float-first and constant-stride controls. Both serial GPU suites on the final revision passed 247 tests with one ignored, including the upstream depth-bounds tests and the frame-timing test that failed in the previous CI run. Both strict GPU Clippy modes and asset policy passed. Please retain the Git author when moving the fix or tests. If squashing them into another commit, please add this trailer. Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:16 UTC · original

Automated triage for the maintainers.

The CPU rectangle expansion in State::rectangles (crates/victory-gpu/src/draw.rs) picked the right-angle corner separately for each vertex stream, so a separate colour stream could end up paired with the wrong vertices. This PR picks the corners once, via primitive::rectangle_corners, from the POSITION input when the layout names one and with the old float heuristic otherwise, and expands every stream with them. A stride-0 stream now keeps its bound view instead of failing the draw.

I checked the new position flag in pipeline/host.rs, that source ranges are still checked before the deferred copy, and the three-layout WARP test. The branch is merged with current main, and CI check passes. #2727 edits the same function and will need a rebase after this one. This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2729#issuecomment-7177352809) <!-- victory-triage v1 head=857f394ebe5a7f8d1b4100979cd801eb4ac4deb8 verdict=merge-candidate at=2026-11-25T23:22:00Z --> Automated triage for the maintainers. The CPU rectangle expansion in `State::rectangles` (`crates/victory-gpu/src/draw.rs`) picked the right-angle corner separately for each vertex stream, so a separate colour stream could end up paired with the wrong vertices. This PR picks the corners once, via `primitive::rectangle_corners`, from the `POSITION` input when the layout names one and with the old float heuristic otherwise, and expands every stream with them. A stride-0 stream now keeps its bound view instead of failing the draw. I checked the new `position` flag in `pipeline/host.rs`, that source ranges are still checked before the deferred copy, and the three-layout WARP test. The branch is merged with current `main`, and CI `check` passes. #2727 edits the same function and will need a rebase after this one. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 02:47 UTC · original

@⁠andrewpozdnakov7-jpg I tested your 857f394 alongside the CPU provoking-vertex follow-up requested on #2970. I've left your position-slot selection and constant-stride handling in this PR. My standalone follow-up #2994 only changes the triangle order and is marked to merge after #2729.

The two changes together matched the reference GS on all 24 draws on both an RTX 5080 and built-in WARP. I also ran your three-layout draw-vtable regression on each adapter; its sampled colors all passed. For integration there's one commit directly on your current head which keeps your expander signature and original commit history. No action needed on your branch.

**@⁠steven-seagull27** on GitHub · 2026-11-26 02:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2729#issuecomment-7181123297) @⁠andrewpozdnakov7-jpg I tested your `857f394` alongside the CPU provoking-vertex follow-up requested on #2970. I've left your position-slot selection and constant-stride handling in this PR. My [standalone follow-up #2994](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2994) only changes the triangle order and is marked to merge **after #2729**. The two changes together matched the reference GS on all 24 draws on both an RTX 5080 and built-in WARP. I also ran your three-layout draw-vtable regression on each adapter; its sampled colors all passed. For integration there's [one commit directly on your current head](https://github.com/steven-seagull27/VIctory/commit/4cd40bec67f6877b839e0dff4bae5a7d3ca5c7dc) which keeps your expander signature and original commit history. No action needed on your branch.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2729/head:github-bot/gh-2729'
git switch 'github-bot/gh-2729'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2729'
git switch 'github-bot/gh-2729'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2729'
git switch 'github-bot/gh-2729'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2729'
git switch 'main'
git merge --squash 'github-bot/gh-2729'
git switch 'main'
git merge --ff-only 'github-bot/gh-2729'
git switch 'main'
git merge 'github-bot/gh-2729'
git push origin 'main'
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!2729
No description provided.