GPU: refresh table CBVs on fresh_tables cache hits #2850

Open
github-bot wants to merge 1 commit from github-bot/gh-2850 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 22:17 UTC · original
fuzeofficlal:fix/gpu-fresh-table-cbv-refresh → main · +88 −1 · 1 files · 1 commits · open

Problem

In State::tables (crates/victory-gpu/src/draw.rs:1299), when a descriptor table spills past the host descriptor heap cap (index >= host.count(), e.g., on NVIDIA/WARP clamping a 1.5M view heap to 934,464) and hits the per-list self.fresh_tables cache, the refresh loop skips constant buffers:

for u in entries.iter().filter(|u| u.kind != ResourceType::Cbv) {

Because table CBVs are mirrored as shadow-backed raw SRVs (descriptor/host.rs) and rely on readable(list, u, &view, true) (just as State::table_entry and fresh-table creation already do unconditionally), skipping ResourceType::Cbv on a fresh_tables hit leaves the host shadow buffer out of date in two cases within a command list:

  1. After a buffer copy: Draw 1 populates and caches the table in fresh_tables, a copy updates the CBV backing memory (clearing deferred.refreshed), and Draw 2 hits fresh_tables—skipping readable leaves stale pre-copy data in the shadow buffer.
  2. After partial first use: Table T has a CBV at slot 0 and an SRV at slot 1. Draw A uses only slot 1 (n = 2, hashing slots 0..2 into the cache key without calling readable on slot 0). Draw B uses both slot 0 and slot 1, hits the same (table, hash) entry in fresh_tables, skips ResourceType::Cbv, and never refreshes slot 0's shadow buffer (reading zeros).

Fix

Call readable(list, u, &view, true) for all entries on a fresh_tables cache hit (for u in entries). Unchanged ranges remain O(1) deduplicated by deferred.refreshed.

Verification

  • Added synthetic regression test draw::tests::fresh_table_cache_hit_refreshes_cbv_after_copy_and_partial_first_use covering both cases (fails on f3578e3 before the 1-line fix: 0x1111_1111 vs 0x2222_2222 after copy, 0 vs 0x3333_3333 after partial first use).
  • RTX 5090 (cargo test --locked -p victory-gpu --lib draw::tests -- --test-threads=1): 21/21 passed, no debug-layer errors.
  • WARP (VICTORY_D3D12_WARP=1, default & --features diagnostics): 21/21 passed.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default & --features diagnostics): 0 warnings.
  • cargo xtask policy: 190 files ok.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 22:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2850) `fuzeofficlal:fix/gpu-fresh-table-cbv-refresh` → `main` · +88 −1 · 1 files · 1 commits · open ### Problem In `State::tables` (`crates/victory-gpu/src/draw.rs:1299`), when a descriptor table spills past the host descriptor heap cap (`index >= host.count()`, e.g., on NVIDIA/WARP clamping a 1.5M view heap to 934,464) and hits the per-list `self.fresh_tables` cache, the refresh loop skips constant buffers: ```rust for u in entries.iter().filter(|u| u.kind != ResourceType::Cbv) { ``` Because table CBVs are mirrored as shadow-backed raw SRVs (`descriptor/host.rs`) and rely on `readable(list, u, &view, true)` (just as `State::table_entry` and fresh-table creation already do unconditionally), skipping `ResourceType::Cbv` on a `fresh_tables` hit leaves the host shadow buffer out of date in two cases within a command list: 1. **After a buffer copy**: Draw 1 populates and caches the table in `fresh_tables`, a copy updates the CBV backing memory (clearing `deferred.refreshed`), and Draw 2 hits `fresh_tables`—skipping `readable` leaves stale pre-copy data in the shadow buffer. 2. **After partial first use**: Table `T` has a CBV at slot 0 and an SRV at slot 1. Draw A uses only slot 1 (`n = 2`, hashing slots `0..2` into the cache key without calling `readable` on slot 0). Draw B uses both slot 0 and slot 1, hits the same `(table, hash)` entry in `fresh_tables`, skips `ResourceType::Cbv`, and never refreshes slot 0's shadow buffer (reading zeros). ### Fix Call `readable(list, u, &view, true)` for all `entries` on a `fresh_tables` cache hit (`for u in entries`). Unchanged ranges remain O(1) deduplicated by `deferred.refreshed`. ### Verification - Added synthetic regression test `draw::tests::fresh_table_cache_hit_refreshes_cbv_after_copy_and_partial_first_use` covering both cases (fails on `f3578e3` before the 1-line fix: `0x1111_1111` vs `0x2222_2222` after copy, `0` vs `0x3333_3333` after partial first use). - RTX 5090 (`cargo test --locked -p victory-gpu --lib draw::tests -- --test-threads=1`): 21/21 passed, no debug-layer errors. - WARP (`VICTORY_D3D12_WARP=1`, default & `--features diagnostics`): 21/21 passed. - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default & `--features diagnostics`): 0 warnings. - `cargo xtask policy`: 190 files ok.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:15:53 +00:00
Author
Owner

@⁠Machad3x on GitHub · 2026-11-25 23:18 UTC · original

Hardware result at head 6ae15a75, cherry-picked onto a fork stack, RTX 3080 Ti: the library tests pass with its new test; one 7-minute run in play without device removal, window scene median 675 ms a frame (688 in an earlier run without it, one run each).

Ran with AI assistance (Claude Code).

**@⁠Machad3x** on GitHub · 2026-11-25 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2850#issuecomment-7177396838) Hardware result at head 6ae15a75, cherry-picked onto a fork stack, RTX 3080 Ti: the library tests pass with its new test; one 7-minute run in play without device removal, window scene median 675 ms a frame (688 in an earlier run without it, one run each). Ran with AI assistance (Claude Code).
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 00:00 UTC · original

Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 6ae15a7 (on its base f3578e3).

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: 864 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: fresh_table_cache_hit_refreshes_cbv_after_copy_and_partial_first_use.
  • --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-26 00:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2850#issuecomment-7178288940) Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `6ae15a7` (on its base `f3578e3`). **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`: **864 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `fresh_table_cache_hit_refreshes_cbv_after_copy_and_partial_first_use`. - `--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

@⁠Marvisak on GitHub · 2026-11-26 03:21 UTC · original

Automated triage for the maintainers.

This is a one-line fix in State::tables (crates/victory-gpu/src/draw.rs). On a fresh_tables cache hit, main refreshes only non-CBV entries. When the table is made, the same function calls readable for every used entry, CBVs included, and readable already handles View::Constant by refreshing its shadow range. Skipping CBVs on a hit therefore leaves a constant buffer stale after a copy in the same list, or never refreshed when an earlier draw used fewer slots of the same table. The PR drops the filter, and deferred.refreshed still avoids repeated refreshes. The new test covers both cases.

Others' runs on an RTX 5070 Ti, an RTX 5090 and WARP pass. I found no other open PR doing the same.

Verdict: merge candidate (a recommendation to look, not an approval). CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 03:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2850#issuecomment-7181649062) <!-- victory-triage v1 head=6ae15a7576ebcb9be61f3e71a916b2fa9eb4a7b6 verdict=merge-candidate at=2026-11-26T03:21:42Z --> Automated triage for the maintainers. This is a one-line fix in `State::tables` (`crates/victory-gpu/src/draw.rs`). On a `fresh_tables` cache hit, `main` refreshes only non-CBV entries. When the table is made, the same function calls `readable` for every used entry, CBVs included, and `readable` already handles `View::Constant` by refreshing its shadow range. Skipping CBVs on a hit therefore leaves a constant buffer stale after a copy in the same list, or never refreshed when an earlier draw used fewer slots of the same table. The PR drops the filter, and `deferred.refreshed` still avoids repeated refreshes. The new test covers both cases. Others' runs on an RTX 5070 Ti, an RTX 5090 and WARP pass. I found no other open PR doing the same. **Verdict: merge candidate** (a recommendation to look, not an approval). CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
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/2850/head:github-bot/gh-2850'
git switch 'github-bot/gh-2850'

Merge

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