GPU: walk active vertex buffer slots by set bits in draw #3654

Open
Luislariosss wants to merge 1 commit from upstream-pr/3654 into main
Luislariosss commented 2026-11-28 03:20:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-28T03:20:41Z.


Avoid scanning all 32 vertex-buffer slots on every draw when only a subset (or none) are active.

Changes

  • Skip initializing [D3D12_VERTEX_BUFFER_VIEW; 32] and calling IASetVertexBuffers when p.slots == 0.
  • Walk only the set bits of p.slots (active_slots / vertex_slot_count) in the vertex-buffer bind path.
  • Walk only active slots in rectangles() instead of allocating up to 32 temporary Vec<(u32, u32)>s per draw.
  • Add unit test draw::tests::vertex_slots_are_walked_by_their_set_bits.

Verification

  • cargo xtask policy (191 files ok)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics)
  • cargo test -p victory-gpu --lib draw:: (21 passed, 0 failed)
<!-- greyfinch-sync:Marvisak/VIctory:issue:5536176817 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3654). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-28T03:20:41Z. --- Avoid scanning all 32 vertex-buffer slots on every draw when only a subset (or none) are active. ### Changes - Skip initializing `[D3D12_VERTEX_BUFFER_VIEW; 32]` and calling `IASetVertexBuffers` when `p.slots == 0`. - Walk only the set bits of `p.slots` (`active_slots` / `vertex_slot_count`) in the vertex-buffer bind path. - Walk only active slots in `rectangles()` instead of allocating up to 32 temporary `Vec<(u32, u32)>`s per draw. - Add unit test `draw::tests::vertex_slots_are_walked_by_their_set_bits`. ### Verification - `cargo xtask policy` (191 files ok) - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`) - `cargo test -p victory-gpu --lib draw::` (21 passed, 0 failed)
oni-swr commented 2026-11-28 03:35:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T03:35:30Z.


Independent WARP verification and diff review. AI-assisted by Codex (gpt-6.2-sol).

  • Base 63bcca43c6a00a758510398fa43096ce7e4f7df0, PR head b275f5430b14d894974f2ff6e2f0fe703abe8bb5, clean merge tree 5a9b5bdc895c8c4f91668d81bafb09f64099e7fc.
  • VICTORY_WARP=1 and VICTORY_D3D12_WARP=1. DXGI reported software adapter flags (0x2), the compositor initialized, and the GPU test processes loaded d3d10warp.dll 10.0.26100.9818. A separate loader probe resolved SDK dxil.dll 1.8.2502.11 via PATH. The GPU test processes showed no dxil.dll load.
  • Full victory-gpu suites with diagnostics passed on base (246 passed, 1 ignored) and on the merge (247 passed, 1 ignored). The first full merge run failed the unchanged frame::tests::waits_end_on_ticks_and_count_frames timing assertion and passed on retry. draw::tests::vertex_slots_are_walked_by_their_set_bits was absent on base and passed on the merge. Diagnostics draw:: passed 21 tests. Both default-feature test binaries compiled with --no-run, since the host's WARP switch requires diagnostics.
  • Both Clippy invocations passed with -D warnings (2/2, zero warnings). xtask policy passed (191 files, zero violations). All Cargo commands used -j 4.
  • GraphicsState::slots() and elements() use the same layout and clamp each slot to 0..=31, so every stored element is represented. A zero mask implies an empty IA layout (or compute/mesh), so earlier vertex-buffer bindings are unread. The base already skipped the bind for zero, and subsequent draws bind their required slots. Sparse holes keep their null views, vertex_slot_count(0) is zero, and the full mask yields slots 0..=31 with a 32-view span.
  • Pairwise draw.rs conflict with #2729 in rectangle expansion. Each PR merges individually onto the pinned base.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7233198774 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3654#issuecomment-7233198774). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-28T03:35:30Z. --- Independent WARP verification and diff review. AI-assisted by **Codex (gpt-6.2-sol)**. - Base `63bcca43c6a00a758510398fa43096ce7e4f7df0`, PR head `b275f5430b14d894974f2ff6e2f0fe703abe8bb5`, clean merge tree `5a9b5bdc895c8c4f91668d81bafb09f64099e7fc`. - `VICTORY_WARP=1` and `VICTORY_D3D12_WARP=1`. DXGI reported software adapter flags (`0x2`), the compositor initialized, and the GPU test processes loaded `d3d10warp.dll` `10.0.26100.9818`. A separate loader probe resolved SDK `dxil.dll` `1.8.2502.11` via `PATH`. The GPU test processes showed no `dxil.dll` load. - Full `victory-gpu` suites with `diagnostics` passed on base (246 passed, 1 ignored) and on the merge (247 passed, 1 ignored). The first full merge run failed the unchanged `frame::tests::waits_end_on_ticks_and_count_frames` timing assertion and passed on retry. `draw::tests::vertex_slots_are_walked_by_their_set_bits` was absent on base and passed on the merge. Diagnostics `draw::` passed 21 tests. Both default-feature test binaries compiled with `--no-run`, since the host's WARP switch requires `diagnostics`. - Both Clippy invocations passed with `-D warnings` (2/2, zero warnings). `xtask policy` passed (191 files, zero violations). All Cargo commands used `-j 4`. - `GraphicsState::slots()` and `elements()` use the same layout and clamp each slot to `0..=31`, so every stored element is represented. A zero mask implies an empty IA layout (or compute/mesh), so earlier vertex-buffer bindings are unread. The base already skipped the bind for zero, and subsequent draws bind their required slots. Sparse holes keep their null views, `vertex_slot_count(0)` is zero, and the full mask yields slots `0..=31` with a 32-view span. - Pairwise `draw.rs` conflict with #2729 in rectangle expansion. Each PR merges individually onto the pinned base.
andrewpozdnakov7-jpg commented 2026-11-28 03:47:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T03:47:14Z.


I combined this exact head b275f54 with #2729 at 857f394 in 9577abe. The overlap in rectangles keeps the active-slot iterator while retaining the common POSITION-derived corner order for all vertex streams.

Test commit e702f1d extends the existing render-and-readback fixture. All three color cases passed with adjacent slots and with POSITION in slot 31 and COLOR in slot 7. The latter exercises the high mask bit and unused gaps, including the stride-zero constant-color case. The two sampled pixels per rectangle matched the expected colors.

App-local WARP 1.0.22 with Agility 1.620.2 passed 11 focused repository tests plus the local runtime identity check, with the debug switch off and on. Strict all-feature GPU Clippy and asset policy passed.

Please retain the Git authors on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding my test into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7233381814 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3654#issuecomment-7233381814). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T03:47:14Z. --- I combined this exact head `b275f54` with #2729 at `857f394` in [`9577abe`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/9577abedd6fd69fca656a1667aefa0d27211bb7b). The overlap in `rectangles` keeps the active-slot iterator while retaining the common POSITION-derived corner order for all vertex streams. [Test commit `e702f1d`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/e702f1d0f71fba3dd75c7c96cdd0989b738e8f10) extends the existing render-and-readback fixture. All three color cases passed with adjacent slots and with POSITION in slot 31 and COLOR in slot 7. The latter exercises the high mask bit and unused gaps, including the stride-zero constant-color case. The two sampled pixels per rectangle matched the expected colors. App-local WARP 1.0.22 with Agility 1.620.2 passed 11 focused repository tests plus the local runtime identity check, with the debug switch off and on. Strict all-feature GPU Clippy and asset policy passed. Please retain the Git authors on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding my test into another commit. AI-assisted with OpenAI Codex.
futurepro62 commented 2026-11-29 22:31:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-29T22:31:38Z.


NVIDIA full-suite run, to go with the reports above by andrewpozdnakov7-jpg, oni-swr, since none of them names a GPU run. Tested exact head b275f54 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: vertex_slots_are_walked_by_their_set_bits.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7263742466 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3654#issuecomment-7263742466). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-29T22:31:38Z. --- NVIDIA full-suite run, to go with the reports above by andrewpozdnakov7-jpg, oni-swr, since none of them names a GPU run. Tested exact head `b275f54` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `vertex_slots_are_walked_by_their_set_bits`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3654:upstream-pr/3654'
git switch 'upstream-pr/3654'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3654'
git switch 'upstream-pr/3654'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3654'
git switch 'upstream-pr/3654'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3654'
git switch 'main'
git merge --squash 'upstream-pr/3654'
git switch 'main'
git merge --ff-only 'upstream-pr/3654'
git switch 'main'
git merge 'upstream-pr/3654'
git push origin 'main'
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
Marvisak/VIctory!3654
No description provided.