GPU: reuse idle 16 MiB title-memory page tables across view heaps #3662
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3662"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-28T03:57:32Z.
Each view heap that touches title memory allocates a ~16.05 MiB (
TABLE_DWORDS) page-table buffer inmemory::Shared::new, which was previously destroyed whenever the heap was dropped and reallocated from scratch for the next heap.Changes
TABLE_POOL_CAP = 1) for page-table buffers incrates/victory-gpu/src/memory.rs.Drop for Shared, only return the table to the pool whensole_holderconfirms no command list still holds a COM reference (list.keep(&s.table)); otherwise drop it as before so no in-flight GPU work can observe reuse.Shared::new, reuse and zero a pooled table when available before allocating a new one.memory::tests::idle_tables_are_capped.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 memory::(9/9) anddescriptor::(22/22)Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T07:32:53Z.
Independent verification (software WARP only) — AI disclosure: Claude Sonnet 5.5 (Claude Code).
Environment: Windows 11 26200,
VICTORY_WARP=1,VICTORY_D3D12_WARP=1,--features diagnostics(host.rswarp_adapter()path, which refuses a non-software adapter). Physical GPU not used.d3d10warp.dll10.0.26100.9818,dxil.dll1.8.2502.11 (Windows Kits 10.0.26100.0 x64).SHAs: main
63bcca43c6a00a758510398fa43096ce7e4f7df0; PR head3907257c72a7a23e533a6e5be784e2b39e21117b; merges cleanly, merge tree2b048cbee67ccf5069ca74f261e2d7579b6eb971. Diff:memory.rsonly (+85/-6).Results (
cargo test --locked -p victory-gpu --features diagnostics -j 4 --no-fail-fast):idle_tables_are_cappedabsent.memory::tests::idle_tables_are_cappedok; 31memory::/descriptor::tests ok.cargo clippy --locked -p victory-gpu --all-targets -j 4 -- -D warnings: clean, default and--features diagnostics.cargo xtask policy: 191 files ok.Review notes (no blockers):
sole_holder: AddRef/Release returning 2 means the droppedSharedis the only owner. No TOCTOU is possible, since a new reference can only be taken from an existing one and no other holder remains. A list that still holds it (viakeep) makes the buffer be released rather than pooled, which is the conservative choice. Lock order is SHARED then TABLE_POOL on both paths, so there is no inversion.ManuallyDrop::takeinDrop for Sharedis called once, andtableis not used afterwards.bindderefs through&*s.table. Sound.TABLE_POOLis a process-wide static, andhost()is a singleOnceLockdevice, so a pooled buffer can't outlive its device. Cap of 1 means at most 16 MiB idle.write_byteszeroing matches a freshupload_buffer(all level-1 entries are 0, so everything routes to block 0 slot 0). It does not apply the null-pair init from #3119 (open, sameShared::newregion). If #3119 lands first, the pooled path must apply that same null init after the zeroing, or reused tables would route to slot 0 untilrewrite. Expect a textual/semantic overlap there. #3106 and #3487 also touchmemory.rs. I did not test those merges.sole_holder, zeroing) is not covered, though the existing GPU tests exerciseShared::newunder WARP.Imported from Marvisak/VIctory. Originally posted by reallyvibe on 2026-11-29T01:10:46Z.
Merge checks for the two open points in oni-swr's report: the #3119 overlap and the untested reuse path
oni-swr's report left two questions open: whether pooled tables get #3119's null-pair init, and whether the reuse path is tested. I merged this head
3907257cwith #3119fe530463on main63bcca43. The merge is clean, and #3119's block lands after this PR'smatch idle, so the null pair is written into pooled tables as well as fresh ones.cargo build -p victory-gpu --libandcargo clippy -p victory-gpu --all-targets -- -D warnings(default and--all-features) are clean.For the reuse path I wrote the regression test below, against the merged tree. You're welcome to take it into this PR, or into #3119, whichever lands second. Its null-pair checks need #3119. Without #3119, keep only the pooling, zeroing and held-table checks.
On the merged tree with this test, WARP
memory::passes 11/11. I mutated the tree one change at a time and ran each test in its own process; the test fails each time:write_byteson a pooled tablesole_holdercheck)So the null-pair concern doesn't apply to the merge as it stands. It would come back if a rebase moved #3119's init into the fresh-buffer branch only. #3119's test alone would not catch that unless a pooled table happened to be available when it runs. #3487
612207a8also merges cleanly with this head: the lib and the test binary build, and WARPmemory::passes 13/13. #3106a81d5dd4conflicts textually inmemory.rs, so that one is visible.On lifetime:
HostList::resetruns only after the list's last submission finished, andkeepholds the table until then. So ifsole_holdercorrectly reports no other COM holder, no list is still using the table. That depends on the reference count, though.sole_holderreads the valueIUnknown::AddRefreturns, and Microsoft documents that value as intended only for testing purposes (https://learn.microsoft.com/windows/win32/api/unknwn/nf-unknwn-iunknown-addref). This is an API-contract concern, not a reproduced failure: the WARP tests above passed. Whether the count is reliable on other drivers and runtimes isn't established.Not measured: the time pooling saves, which this PR doesn't claim.
Windows 11, Ryzen 7 7445HS, WARP, synthetic data only.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-29T23:18:47Z.
NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head
3907257(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo 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.idle_tables_are_capped.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#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_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.