GPU: copystat counts its counters at compile time; range and drain tests (revives #1188) #2397

Open
github-bot wants to merge 2 commits from github-bot/gh-2397 into main AGit
Owner

@⁠KainanP on GitHub · 2026-11-25 12:44 UTC · original
KainanP:test/copystat-tests-919 → main · +108 −22 · 1 files · 2 commits · open

Fixes #919.

This revives #1188 by geiyiliyabumo, which was closed because its counter_enum_matches_array_length failed on main once the counter list grew. Their commit (200f5ae) is cherry-picked unchanged onto current main with their name kept on it. One commit of mine follows it (b7ce077) and reworks it per the triage of 2026-11-25. Their range-accumulation test stays, moved onto a local table.

What changed after the triage (crates/victory-gpu/src/copystat.rs)

  • Counter count at compile time. C gets a last variant Count (documented as not a counter, keep it last), and const COUNTERS: usize = C::Count as usize;. A counter added before it grows COUNT with it. The include_str! test is gone. I chose Count over C::SavedPages as usize + 1 because with the + 1 form a counter appended after SavedPages would still need someone to update the constant.
  • Tests that only restated the code are dropped: parse_mode_maps_known_and_unknown_values (and the parse_mode split, so mode() is back as on main) and page_faults_queries_current_process.
  • The two behaviour tests can't race now. The counters and the range table are now small types (Counters, Ranges, each with add and take), and the globals COUNT/RANGES are instances of them. log() drains them through take, the same swap-to-zero and sort-by-bytes as before. The tests build their own instances, so the GPU submission and watch tests counting into the globals at the same time can't affect them. No lock needed:
    • range_accumulates_same_key_and_separates_distinct_ranges: same key accumulates, distinct keys stay apart, take sorts by bytes and empties.
    • take_drains_counters_per_frame: values divided per frame, every other counter zero, and the next take counts from zero.
  • frames <= 0 guard dropped. The only caller is Meter::frame in host.rs. It does self.copy_stats_frames += 1 before the 1 s / 5 s checks and then logs std::mem::take(&mut self.copy_stats_frames) as f64, so the count is a u64 of at least 1 and can't be zero, negative or NaN. bindless::log and shadow::log_views get the same value unguarded. The guard's test is gone too.

Tests, Windows 11 x64, main 940d32f + these two commits. copystat only builds with --features diagnostics on Windows (lib.rs):

  • cargo test -p victory-gpu --features diagnostics --locked copystat: 2 passed
  • The whole victory-gpu suite with --features diagnostics (GPU submission, host, shadow and watch tests together with these), 5 runs: 146 passed, 0 failed each time. Two tests are skipped in those runs: descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views. They fail the same way on plain main 940d32f with --features diagnostics on this machine (descriptor heap smaller than HEAP_VIEWS), so the failure is not from this PR.
  • copystat + watch filter, 5 runs: 8 passed each time
  • Fail checks: with take using load instead of swap, the drain test fails. With add setting the copy count instead of adding to it, the range test fails.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and the --all-features variant: clean
  • cargo xtask policy: asset policy, 182 files ok
  • My lines are rustfmt-clean. The file's 4 rustfmt differences on main are left alone.

Not covered: CI runs cargo test --workspace without diagnostics, so these tests still don't run there. Only the --all-features clippy job compiles them. 200f5ae on its own still has its original tests and guard. The commits are kept separate to keep authorship.

No game data used. AI use: Claude Code (Claude Opus 5.5).

🤖 Generated with Claude Code

**@⁠KainanP** on GitHub · 2026-11-25 12:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2397) `KainanP:test/copystat-tests-919` → `main` · +108 −22 · 1 files · 2 commits · open Fixes #919. This revives #1188 by geiyiliyabumo, which was closed because its `counter_enum_matches_array_length` failed on `main` once the counter list grew. Their commit (`200f5ae`) is cherry-picked unchanged onto current `main` with their name kept on it. One commit of mine follows it (`b7ce077`) and reworks it per the triage of 2026-11-25. Their range-accumulation test stays, moved onto a local table. **What changed after the triage** (`crates/victory-gpu/src/copystat.rs`) - **Counter count at compile time.** `C` gets a last variant `Count` (documented as not a counter, keep it last), and `const COUNTERS: usize = C::Count as usize;`. A counter added before it grows `COUNT` with it. The `include_str!` test is gone. I chose `Count` over `C::SavedPages as usize + 1` because with the `+ 1` form a counter appended after `SavedPages` would still need someone to update the constant. - **Tests that only restated the code are dropped**: `parse_mode_maps_known_and_unknown_values` (and the `parse_mode` split, so `mode()` is back as on `main`) and `page_faults_queries_current_process`. - **The two behaviour tests can't race now.** The counters and the range table are now small types (`Counters`, `Ranges`, each with `add` and `take`), and the globals `COUNT`/`RANGES` are instances of them. `log()` drains them through `take`, the same swap-to-zero and sort-by-bytes as before. The tests build their own instances, so the GPU submission and `watch` tests counting into the globals at the same time can't affect them. No lock needed: - `range_accumulates_same_key_and_separates_distinct_ranges`: same key accumulates, distinct keys stay apart, `take` sorts by bytes and empties. - `take_drains_counters_per_frame`: values divided per frame, every other counter zero, and the next `take` counts from zero. - **`frames <= 0` guard dropped.** The only caller is `Meter::frame` in `host.rs`. It does `self.copy_stats_frames += 1` before the 1 s / 5 s checks and then logs `std::mem::take(&mut self.copy_stats_frames) as f64`, so the count is a `u64` of at least 1 and can't be zero, negative or NaN. `bindless::log` and `shadow::log_views` get the same value unguarded. The guard's test is gone too. **Tests**, Windows 11 x64, `main` `940d32f` + these two commits. `copystat` only builds with `--features diagnostics` on Windows (`lib.rs`): - `cargo test -p victory-gpu --features diagnostics --locked copystat`: 2 passed - The whole `victory-gpu` suite with `--features diagnostics` (GPU submission, `host`, `shadow` and `watch` tests together with these), 5 runs: 146 passed, 0 failed each time. Two tests are skipped in those runs: `descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`. They fail the same way on plain `main` `940d32f` with `--features diagnostics` on this machine (descriptor heap smaller than `HEAP_VIEWS`), so the failure is not from this PR. - `copystat` + `watch` filter, 5 runs: 8 passed each time - Fail checks: with `take` using `load` instead of `swap`, the drain test fails. With `add` setting the copy count instead of adding to it, the range test fails. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the `--all-features` variant: clean - `cargo xtask policy`: asset policy, 182 files ok - My lines are rustfmt-clean. The file's 4 rustfmt differences on `main` are left alone. **Not covered:** CI runs `cargo test --workspace` without `diagnostics`, so these tests still don't run there. Only the `--all-features` clippy job compiles them. `200f5ae` on its own still has its original tests and guard. The commits are kept separate to keep authorship. No game data used. AI use: Claude Code (Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
COUNTERS is now `C::Count as usize`, a last variant that is not a
counter, so a counter added before it grows the array with it and needs
no test. The counters and the range table become small types with the
global instances behind them, and log() drains them through `take`, so
the two behaviour tests (range accumulation from #1188, and the drain)
run on their own instances and cannot race with the GPU tests that
count into the global ones.

Dropped from #1188: the guard for frames <= 0 in log(), since its one
caller (Meter::frame in host.rs) counts the frame before it logs, so
the count is at least 1; the parse_mode split and its test, and the
page_faults test, which only restated the code. The range test is
geiyiliyabumo's, moved onto a local table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:04:39 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:01 UTC · original · edited 2026-11-25 18:28 UTC

Automated triage for the maintainers.

After the rebase, crates/victory-gpu/src/copystat.rs gets the counter-array length from a trailing C::Count variant instead of the hand-kept 61. That 61 matches main's 61 counters today, but adding a counter without updating it would panic at runtime on indexing. The counter array and range table move into small Counters / Ranges types whose add / take keep main's behaviour: swap-to-zero divided by frames, and a range table sorted by bytes and emptied. log() uses them unchanged otherwise. I found no match over C that the extra variant would break. The PR still merges cleanly with current main. The two tests use their own instances, so they cannot race the GPU tests that count into the globals.

The points from the earlier triage (include_str test, tests that restated the code, the unreachable frames <= 0 guard) are addressed. The module only builds with diagnostics, so CI compiles these tests in the --all-features clippy step but does not run them.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2397#issuecomment-7166190761) · edited 2026-11-25 18:28 UTC <!-- victory-triage v1 head=7dc8075ef6929567f30a78d1db0bf8c5e388e28f verdict=merge-candidate at=2026-11-25T18:28:06Z --> Automated triage for the maintainers. After the rebase, `crates/victory-gpu/src/copystat.rs` gets the counter-array length from a trailing `C::Count` variant instead of the hand-kept `61`. That `61` matches main's 61 counters today, but adding a counter without updating it would panic at runtime on indexing. The counter array and range table move into small `Counters` / `Ranges` types whose `add` / `take` keep main's behaviour: swap-to-zero divided by frames, and a range table sorted by bytes and emptied. `log()` uses them unchanged otherwise. I found no `match` over `C` that the extra variant would break. The PR still merges cleanly with current `main`. The two tests use their own instances, so they cannot race the GPU tests that count into the globals. The points from the earlier triage (include_str test, tests that restated the code, the unreachable `frames <= 0` guard) are addressed. The module only builds with `diagnostics`, so CI compiles these tests in the `--all-features` clippy step but does not run them. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠KainanP on GitHub · 2026-11-25 15:24 UTC · original

Thanks for the triage. Reworked in b7ce077 (force-pushed; 200f5ae by geiyiliyabumo is kept as is):

  • COUNTERS: C now ends with a Count variant (not a counter, documented to stay last), and const COUNTERS: usize = C::Count as usize;. The include_str! test is gone. I used Count rather than C::SavedPages as usize + 1 so that appending a counter needs no change to the constant.
  • Restating tests: parse_mode_maps_known_and_unknown_values (plus the parse_mode split, so mode() is as on main) and page_faults_queries_current_process are dropped.
  • Range and drain tests: the counters and range table are now small Counters/Ranges types with add/take, and the globals are instances of them. log() drains through take. Both tests use their own instances, so the GPU and watch tests counting into the globals can't race them. The whole --features diagnostics suite passed 146/146 in 5 runs. Two tests are skipped: dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views, which fail the same way on plain main here.
  • Guard: dropped, along with its test. Meter::frame increments copy_stats_frames before it can log and then passes take(..) as f64, so the count is always ≥ 1. I found no zero path.

Clippy -D warnings (default and --all-features) and cargo xtask policy are clean.

**@⁠KainanP** on GitHub · 2026-11-25 15:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2397#issuecomment-7166783325) Thanks for the triage. Reworked in `b7ce077` (force-pushed; `200f5ae` by geiyiliyabumo is kept as is): - **`COUNTERS`:** `C` now ends with a `Count` variant (not a counter, documented to stay last), and `const COUNTERS: usize = C::Count as usize;`. The `include_str!` test is gone. I used `Count` rather than `C::SavedPages as usize + 1` so that appending a counter needs no change to the constant. - **Restating tests:** `parse_mode_maps_known_and_unknown_values` (plus the `parse_mode` split, so `mode()` is as on `main`) and `page_faults_queries_current_process` are dropped. - **Range and drain tests:** the counters and range table are now small `Counters`/`Ranges` types with `add`/`take`, and the globals are instances of them. `log()` drains through `take`. Both tests use their own instances, so the GPU and `watch` tests counting into the globals can't race them. The whole `--features diagnostics` suite passed 146/146 in 5 runs. Two tests are skipped: `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`, which fail the same way on plain `main` here. - **Guard:** dropped, along with its test. `Meter::frame` increments `copy_stats_frames` before it can log and then passes `take(..) as f64`, so the count is always ≥ 1. I found no zero path. Clippy `-D warnings` (default and `--all-features`) and `cargo xtask policy` are clean.
Author
Owner

@⁠KainanP on GitHub · 2026-11-25 16:56 UTC · original

Rebased onto main 67e8ae14 (conflict was main's new counters and CountingAlloc in copystat.rs; kept, Count stays last); copystat tests, clippy -D warnings (default/all-features) and xtask policy pass.

AI use: Claude Code (Claude Opus 5.5).

**@⁠KainanP** on GitHub · 2026-11-25 16:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2397#issuecomment-7168762408) Rebased onto main 67e8ae14 (conflict was main's new counters and CountingAlloc in copystat.rs; kept, `Count` stays last); copystat tests, clippy -D warnings (default/all-features) and xtask policy pass. _AI use: Claude Code (Claude Opus 5.5)._
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-25 23:56 UTC · original

Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 7dc8075 (on its base 67e8ae1).

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: 773 passed, 0 failed, 9 ignored.
  • The new tests live in copystat, which only builds with the diagnostics feature, so the run above doesn't include them. Run on their own: cargo test -p victory-gpu --lib --locked --features diagnostics copystat: range_accumulates_same_key_and_separates_distinct_ranges and take_drains_counters_per_frame pass (2 passed, 0 failed).
  • --skip leaves out tests that fail on main 842b0cb 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.
**@⁠futurepro62** on GitHub · 2026-11-25 23:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2397#issuecomment-7178224494) Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `7dc8075` (on its base `67e8ae1`). **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`: **773 passed, 0 failed, 9 ignored**. - The new tests live in `copystat`, which only builds with the `diagnostics` feature, so the run above doesn't include them. Run on their own: `cargo test -p victory-gpu --lib --locked --features diagnostics copystat`: `range_accumulates_same_key_and_separates_distinct_ranges` and `take_drains_counters_per_frame` pass (**2 passed, 0 failed**). - `--skip` leaves out tests that fail on main `842b0cb` 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.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 13:19 UTC · original · reviewed

copystat tests and guard for frames <= 0 (revives). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

**@⁠catminou4** on GitHub · 2026-11-25 13:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2397#pullrequestreview-6058345101) · **reviewed** copystat tests and guard for frames <= 0 (revives). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 19:51 UTC · original · approved these changes

Reviewed and verified 7dc8075ef6929567f30a78d1db0bf8c5e388e28f merged onto origin/main (63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (RTX 5090 + Microsoft WARP, Rust 1.98.1 MSVC).

Code Audit

  • Deriving const COUNTERS: usize = C::Count as usize (crates/victory-gpu/src/copystat.rs:108-110) eliminates the manual 61 constant and evaluates to 61 on current main. Audited all copystat::C references across crates/victory-gpu/src/: every site indexes via c as usize with no exhaustive match on C.
  • Wrapping COUNT and RANGES in Counters (L112-130) and Ranges (L152-177) preserves the exact swap(0, Relaxed) / frames and sort-by-bytes drain semantics in log() while letting unit tests run against isolated instances without racing global GPU/watch counters.

Local Verification

  • cargo xtask policy — pass (191 files ok).
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features) — 0 warnings.
  • cargo test --locked -p victory-gpu --features diagnostics --lib copystat::tests:: — 2/2 passed.
  • Additional 8-thread x 500-iteration concurrent probe exercising Counters::add/take and Ranges::add/take plus asserting COUNTERS == 61 — passed cleanly.
  • Also verified a 4-way co-merge with #1862, #2303, and #2299 on 63bcca43c6a0 builds with 0 clippy warnings (--all-features) and passes all 6 PR tests on both RTX 5090 and WARP.

Looks good to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 19:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2397#pullrequestreview-6079792989) · **approved these changes** Reviewed and verified `7dc8075ef6929567f30a78d1db0bf8c5e388e28f` merged onto `origin/main` (`63bcca43c6a00a758510398fa43096ce7e4f7df0`) on Windows 11 x64 (RTX 5090 + Microsoft WARP, Rust 1.98.1 MSVC). ### Code Audit - Deriving `const COUNTERS: usize = C::Count as usize` (`crates/victory-gpu/src/copystat.rs:108-110`) eliminates the manual `61` constant and evaluates to `61` on current `main`. Audited all `copystat::C` references across `crates/victory-gpu/src/`: every site indexes via `c as usize` with no exhaustive `match` on `C`. - Wrapping `COUNT` and `RANGES` in `Counters` (`L112-130`) and `Ranges` (`L152-177`) preserves the exact `swap(0, Relaxed) / frames` and sort-by-bytes drain semantics in `log()` while letting unit tests run against isolated instances without racing global GPU/watch counters. ### Local Verification - `cargo xtask policy` — pass (`191 files ok`). - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`) — 0 warnings. - `cargo test --locked -p victory-gpu --features diagnostics --lib copystat::tests::` — 2/2 passed. - Additional 8-thread x 500-iteration concurrent probe exercising `Counters::add`/`take` and `Ranges::add`/`take` plus asserting `COUNTERS == 61` — passed cleanly. - Also verified a 4-way co-merge with `#1862`, `#2303`, and `#2299` on `63bcca43c6a0` builds with 0 clippy warnings (`--all-features`) and passes all 6 PR tests on both RTX 5090 and WARP. Looks good to merge.
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/2397/head:github-bot/gh-2397'
git switch 'github-bot/gh-2397'

Merge

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