Skip to content

GPU: keep rectangle corners consistent across vertex streams - #2729

Open
andrewpozdnakov7-jpg wants to merge 4 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/rectangle-stream-corner
Open

andrewpozdnakov7-jpg wants to merge 4 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/rectangle-stream-corner

Conversation

@andrewpozdnakov7-jpg

@andrewpozdnakov7-jpg andrewpozdnakov7-jpg commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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 andrewpozdnakov7-jpg@users.noreply.github.com

@DrDarkDK DrDarkDK left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lower-numbered float attribute stream can choose the corner for the position stream. For example, put TEXCOORD in slot 0 with [(0,1), (0,0), (1,0)] and POSITION in slot 1 with the three positions from your test. The UVs pick vertex 1, while the positions pick vertex 0. Applying the UV choice changes the generated fourth position from (1,-1) to (1,3).

Could the draw prefer an identified position input when choosing the shared corner? Swapping the slots in the existing fixture and using float UVs that choose a different corner would cover this regression.

AI-assisted with Codex.

@kotekompotek

Copy link
Copy Markdown

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.

@andrewpozdnakov7-jpg

andrewpozdnakov7-jpg commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

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 andrewpozdnakov7-jpg@users.noreply.github.com

@andrewpozdnakov7-jpg

andrewpozdnakov7-jpg commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

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 andrewpozdnakov7-jpg@users.noreply.github.com

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.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

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 Shaders: avoid f32 precision loss in thin rectangle right-angle check #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 GPU: reject overflowing rectangle vertex ranges #2727 (f712e159, which adds checked arithmetic for first + count / SizeInBytes overflow) — both are semantically complementary and straightforward to rebase together.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

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 andrewpozdnakov7-jpg@users.noreply.github.com

Copy link
Copy Markdown
Owner

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

@steven-seagull27

Copy link
Copy Markdown

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

BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
…with the branch

The refreshed community PRs merge cleanly as text but did not build
together with the branch:

- Marvisak#2935 returns `None` for an unaccepted present, but on this branch
  `present_planes_with_compositor` returns the primary plane's state
  too. The unaccepted present now returns `(None, primary_state)`: the
  present copy has already run, so the plane is back in that state.
- Marvisak#2509 makes `Staging::layout` the whole texture (all planes). The
  levels-on-demand check (Marvisak#2389) reads plane 0's level layout, so it
  now passes `layout.planes[0].layout`, as before Marvisak#2509.
- Tests from Marvisak#1933, Marvisak#2336 and Marvisak#2729 used older APIs: the depth twin test
  imports `D3DCompile` itself (the branch's twin.rs writes its DXIL and no
  longer imports it), `HostShader` and `Translated` gained
  `written_root_uavs`, `threads` and `atomics64`, `hand_out` takes the
  title's bytecode pointers and `emit::emit` a `Target`. Marvisak#3005's test
  reads `queued` as the `Once` Marvisak#2223 makes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants