Skip to content

GPU: reuse immutable descriptor tables across command lists - #562

Draft
aycow wants to merge 11 commits into
Marvisak:mainfrom
aycow:gpu/reuse-immutable-descriptor-tables
Draft

aycow wants to merge 11 commits into
Marvisak:mainfrom
aycow:gpu/reuse-immutable-descriptor-tables

Conversation

@aycow

@aycow aycow commented Nov 24, 2026 •

Copy link
Copy Markdown

Change

Share immutable texture SRV tables that current main already rebuilds because they extend beyond the mirrored portion of a capped native descriptor heap. The cache matches the full table width, populated offsets, title view generations and native resource identities. Each recorded list retains its allocation and the native resources through execution and replay. Cache hits still schedule the list's usual texture preparation and state transitions. Resolution snapshots each title descriptor generation and pins the resource until preparation completes. The global view registry lock is released before native descriptor creation, uploads, or state transitions.

Ordinary dynamic ranges also retain their original allocator. Resetting an old recording releases only the slots it owns, even if a replacement title heap uses the same guest address. Current main's raw table CBVs, mixed tables, placed views, UAVs and direct bindless paths keep their existing materialization.

Current-main eligibility is limited to already materialized textures with fixed backing. Evictable textures and textures placed in the new native arena use normal table materialization. This keeps recorded tables out of the path that can recycle their backing allocations.

Synthetic reproduction and validation

On Windows, select the adapter and run the fixture on the system D3D12 runtime.

$env:VICTORY_TABLE_TEST_ADAPTER = 'amd' # or nvidia or warp
cargo test --locked -p victory-gpu --features diagnostics --lib descriptor::host::reuse_tests::capped_pool_texture_table_reuse -- --exact --ignored --nocapture --test-threads=1

The fixture at 134dde0 uses the Windows system shader compiler and system D3D12 device creation. It passed native output, closed-list replay, heap replacement, and retirement on AMD Radeon Graphics, GeForce RTX 5070 Laptop GPU, and WARP. The native workload also passed full GPU-based validation on all three using a local validation harness. The fixture accepts VICTORY_TABLE_TEST_GBV=1 for installations where the system debug runtime supports it and requires no SDK path. The lifetime regression covers rejection after collecting a pin and resource release after descriptor replacement. Both strict workspace Clippy configurations passed.

Workload on a 65,536-slot pool Allocation failures, baseline → shared Peak slots, baseline → shared
41 requests for repeated 2,048-slot tables 9 → 0 65,536 → 4,096
24 requests for repeated 2,048-slot tables 0 → 0 49,152 → 4,096
24 requests for unique 2,048-slot tables 0 → 0 49,152 → 49,152

The update at db0c7e5 incorporates main f3578e3. Shared tables now populate view-address entries and clear stale buffer write marks. If the address buffer appears after a table was recorded, a new table supplies its metadata while the old recording keeps its own descriptors. The metadata regression and capped-pool fixture passed on AMD, NVIDIA, and WARP. Thanks to fuzeofficlal for independently verifying the previous head on RTX 5090 and WARP. Independent report

Scope

The current results measure occupancy and correctness on an original synthetic workload. Title-level hit rates, performance and mixed-table coverage remain open. The cache uses main's synchronous completion contract and retains slots while a valid recording can replay them. Distinct ranges can still exhaust or fragment the pool. Fragmentation report

rpmaster2 recorded 12,212 mixed and 3,710 CBV-only requests before the first failed rebuilt table on RX 9070 XT. The texture cache saw zero hits there. LooperSalty eliminated the reported indirect allocation failures by enlarging the dynamic range from 65,536 to 262,144 on a different NVIDIA stack. AMD demand report · NVIDIA capacity control

The earlier CBV ownership and transactional reservation experiments remain available as supporting results. Cross-list mixed-resource and CBV sharing still requires immutable upload versions or submission-time binding. CBV replay fixture · Transactional reservation fixture

Draft pending a matched title capture that demonstrates cross-recording reuse of eligible SRV tables and lower peak slot occupancy or fewer allocation failures. Capture follow-up and A/B instructions · Capture build updated to main AI-assisted with OpenAI Codex.

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

I published an opt-in companion branch at 82e4aa6 to measure which rebuilt tables account for the dynamic-pool demand. It reports reservations and failures by width, descriptor type, CBV presence, exact cross-list record duplication, generation changes and texture-sharing eligibility. AMD, NVIDIA and WARP passed the capped-pool readback fixture with full GPU-based validation.

If you're authorized to retest the exhaustion case, build the diagnostics branch, set VICTORY_DESCRIPTOR_DEMAND=1, and repeat the same warm-cache route. Please share only the rebuilt descriptor demand aggregate lines, revision, GPU/driver and whether the run exhausted the pool. Use a separate pass with the flag off for timing comparisons. Reproduction and counter definitions

@rpmaster2

rpmaster2 commented Nov 24, 2026 •

Copy link
Copy Markdown

Tested on RX 9070 XT 16 GB (RDNA4), Adrenalin 26.11.2 (32.0.32029.2010), Windows 11 26300, Ryzen 5 5600, 32 GB, pagefile 32/48 GB; diag build of this PR.

Menus 30 fps; world entry around frame 1024; no free dynamic descriptor slots: a table is not made n=135; 2 fps; host device removed (0x887A0004/0x887A0006) before the first cutscene. The reuse here does not remove the exhaustion on this host.

Requested diagnostics (aycow:gpu/descriptor-allocation-demand @82e4aa6, VICTORY_DESCRIPTOR_DEMAND=1), at the first failed rebuilt table (frame 1096):

  • outcome: LocalNew 13,879 tables / 71,536 slots; LocalReuse 2,906 / 39,215; NoRange 1 / 178; SharedNew and SharedReuse 0.
  • widths: 16 -> 8,483 / 60,196; 256 -> 167 / 23,064; 1024 -> 25 / 6,450; 4 -> 4,316 / 15,483; 1 -> 3,695 / 3,695; 64 -> 100 / 2,041.
  • composition: Mixed 12,212 / 72,250 with duplicate_untracked 11,947 / 71,159; CbvOnly 3,710 / 3,725 with duplicate_untracked 3,707 / 3,722; Unresolved 864 / 34,954 with duplicate_untracked 864 / 34,954.
  • then no free dynamic descriptor slots n=178 and device removal.

#550 was tested too: its past-host-heap path never fires on this host and the TDR remains. Full report: #597 (comment). No game data.

AI-assisted: written by DeepSeek (OpenCode harness) from my run logs and observations; the hardware, the dump and the runs are mine.

@LooperSalty

Copy link
Copy Markdown

A measurement for the capped-heap case this PR is about, on an RTX 4070 SUPER (view heap capped at 1,000,000; the title asks for 1,245,184), diag build of main 58fed37 + #89 #493 #189 #206 #469 #459 #454 #688 #464 #490 #497 #346 #483 #638 #579 #302 #489 #585 #617 #307 #550, 2 minutes in the world each time:

  • capped dynamic range 65,536 (current MIN_DYNAMIC): no dynamic slots for its tables 15 times, up to dropped=16384; and ~720 draws/frame dropped as indirect kind 10: prepare failed (compute false, mesh true) plus ~256/frame indirect kind 0: prepare failed for indirect rectangles (both go through take_dynamic in prepare_for/root_srv_table).
  • capped dynamic range 262,144 (local experiment: the capped branch takes PORTABLE_VIEWS - dynamic - guard title slots instead): 0 no dynamic slots, and neither indirect message appears any more. No new warning, no device removal.

So on NVIDIA the exhaustion is what drops the indirect mesh dispatches. The cost is fewer mirrored title slots (737,855 instead of 934,463); I saw no draw needing a slot in that range, but I have not checked it directly. Reusing tables as this PR does would get the same result without giving up title slots; it conflicts with #688's lease/reclaim allocator on my stack, so I could not test the two together.

🤖 Generated with Claude Code

@aycow
aycow force-pushed the gpu/reuse-immutable-descriptor-tables branch from b82f29c to 05c3757 Compare November 24, 2026 16:27
@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

@rpmaster2 @LooperSalty Thanks for the two controls. 05c3757 is rebased on ffe310e and keeps the #336 cap and refusal behavior. The 65,536-slot texture fixture again passed AMD, NVIDIA and WARP with GBV. The AMD workload had zero texture sharing hits and points to mixed/CBV demand. The NVIDIA capacity experiment identifies allocation pressure for indirect mesh admission, with a title-slot tradeoff on that test stack. I’ve recorded both results in the description. The synthetic ordered-copy test still needs separate upload versions even for identical CBV records; the rebased path keeps those uploads list-local.

@rpmaster2

Copy link
Copy Markdown

@aycow thanks - noted, and good to see 05c3757 rebased on ffe310e with the #336 cap and refusal behaviour kept.

One honest limitation from my side, so the record is clear: on the RX 9070 XT the "no free dynamic descriptor slots" refusal no longer appears at all on main @58fed37 or later (0 occurrences across a dozen 300-480 s world runs), so I cannot show a benefit from table reuse there any more - the pool simply is not the limiter on this host now. The AMD control you recorded (zero texture-sharing hits, mixed/CBV demand) is the last measurement where the demand was visible.

What I can still test on the rebased head, if it helps you: the same 480 s A/B against ffe310e with VICTORY_DESCRIPTOR_DEMAND=1, reporting the demand breakdown and whether no free dynamic slots stays at zero. Say the word and it goes in the queue - GPU runs on this machine are paused tonight after a driver reset froze it, so it would be tomorrow.

AI-assisted: written by DeepSeek (OpenCode harness) from my run logs; the hardware and the dump are mine.

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

Thanks for the RX 9070 XT repetition. The zero current-main refusals are a useful control. If a matched warm scene is available, could you share aggregate dynamic table counts by width and composition (CBV-only, mixed CBV/SRV/UAV, and sampler), unique/repeated counts, peak live slots and refusal counts? The exact commit and settings help compare shape without attributing a speedup to reuse. Counts only are sufficient. Cross-list CBVs still need immutable upload contents retained until fence completion.

@rpmaster2

Copy link
Copy Markdown

@aycow counts from the run I did on your diagnostics branch, as requested. All numbers are aggregates at the first failed rebuilt table, nothing scene-specific.

  • commit: aycow:gpu/descriptor-allocation-demand @82e4aa6, diag build, VICTORY_DESCRIPTOR_DEMAND=1, VICTORY_D3D12_DRED=1, DRED off for this run otherwise default; RX 9070 XT 16 GB, Adrenalin 26.11.2, Windows 11 26300, Ryzen 5 5600, 32 GB.
  • frame: 1096, reason first failed rebuilt table.

Outcome across the frame:

  • LocalNew 13,879 tables / 71,536 slots
  • LocalReuse 2,906 / 39,215
  • NoRange 1 / 178
  • SharedNew and SharedReuse 0 / 0

By width (requested):

  • 16: 8,483 tables / 60,196 slots (reserved 7,073 / 48,794)
  • 256: 167 / 23,064 (reserved 22 / 2,818)
  • 1024: 25 / 6,450 (reserved 3 / 774)
  • 4: 4,316 / 15,483 (reserved 4,289 / 15,405)
  • 1: 3,695 / 3,695 (reserved 2,427 / 2,427)
  • 64: 100 / 2,041 (reserved 65 / 1,318)

By composition:

  • Mixed: 12,212 tables / 72,250 slots, reserved 10,775 / 60,770, duplicate_untracked 11,947 / 71,159
  • CbvOnly: 3,710 / 3,725, reserved 2,442 / 2,457, duplicate_untracked 3,707 / 3,722
  • Unresolved: 864 / 34,954, reserved 662 / 8,309, duplicate_untracked 864 / 34,954

Then no free dynamic descriptor slots: a table is not made n=178 and the device was removed.

Two caveats for shape comparison, both from later runs on my host:

  1. That run predates GPU: drop draws whose fresh tables cannot be made; 2^18 dynamic slots #336 landing in main; on main @58fed37 and later the refusal count is zero in every 300-480 s world run (a dozen of them), so this is the last measurement where the demand was visible on this card.
  2. I do not have a matched warm scene: each run restores the same save, but which passes finish compiling varies, so treat the counts as one sample of the same scene rather than a repeatable steady state.

I can re-run the demand branch on current main after this session (a long run is in flight right now) if a current-tree number is more useful than the historical one; it would be the same protocol, counts only.

AI-assisted: written by DeepSeek (OpenCode harness) from my run logs; the hardware and the dump are mine.

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

@rpmaster2 Thanks for the breakdown. The historical failure provides a useful width-178 stress case. Mixed tables accounted for 60,770 reserved slots and CBV-only tables for 2,457. The mixed duplicate counter did not establish identical immutable descriptor and upload generations, so it does not predict reusable capacity.

Your zero-refusal current-main results and the new RTX 5060 #1349 comparison make the next comparison more specific. Would you be able to share a current-main warm-window census with the same aggregate fields and peak live slots, including when refusals are zero? A #1349 comparison on the affected hardware would help establish how much pressure remains. We are keeping #562 in draft and holding mixed-CBV expansion until there is current demand and evidence that sealed upload versions can reduce it.

AI-assisted using Codex.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work: needs the maintainer's decision. It now merges cleanly into main. CI: check passing.

The PR shares fully resolved texture-SRV tables across command lists (HostHeap::shared_textures, Heap::with_texture_table, the new branch in State::tables in draw.rs). It also replaces the (heap, first, n) release bookkeeping with drop-released DynamicRanges tied to a per-heap DynamicSlots identity. The identity change is a good fix: a release can no longer reach a reused heap address. Three things block it:

  • with_texture_table holds the global VIEWS mutex while its closure runs, and the closure calls readable (texture uploads, alias copies, state transitions) and CreateShaderResourceView. That stalls descriptor creation on every title thread and risks lock-order inversions. Please collect the entries, release the lock, then do the work.
  • The reuse_tests.rs fixture loads an Agility SDK from VICTORY_TABLE_TEST_AGILITY through ID3D12DeviceFactory, which loads external code and needs the maintainer's decision.
  • As you note, the demand this addresses hasn't been shown on current main. The capture build you posted is the right way to get that number.

Splitting out the DynamicSlots identity fix would let it land on its own.


Generated by Claude Code

@aycow

aycow commented Nov 25, 2026

Copy link
Copy Markdown
Author

Updated to upstream 42363ab at 4cd352f. The draft shares immutable texture SRVs only when main already rebuilds the table on a capped heap. Main’s raw CBV and mixed-table paths are preserved. Recorded allocations now release into their original native heap even after title heap address reuse.

AMD, NVIDIA, and WARP passed native readback and closed-list replay with full GPU-based validation. In the synthetic 65,536-slot test, repeated tables reduced peak slots from 65,536 to 4,096 and allocation failures from nine to zero. The unique-table control kept the same occupancy. I updated the description with reproduction steps and the limitations of the current workload.

@rpmaster2

Copy link
Copy Markdown

@aycow happy to run it, with one blocker on this host right now.

Current main (@940d32f) dies in the driver's shader compiler before a warm window exists here: 0xc0000005 at amdxc64.dll+0x861b9f, the same offset on main, on main + #1762, and on fxceless's fork. It happens during pipeline creation in the credits/prologue, so a 300-480 s run reaches 1,700-9,100 draws/frame and then the process is gone - there is no steady window to census. I filed it as #2124 with the Windows Event Log entry naming amdxc64.dll 32.0.32029.2010.

Two ways I can give you the census you want, pick one:

  1. On the last good tree, ffe310e (yesterday's main). That is where my historical numbers came from and where the zero-refusal runs happened; I can run the diagnostics there with VICTORY_DESCRIPTOR_DEMAND=1 and report the same aggregate fields plus peak live slots, flagged as historical rather than current.
  2. On current main as soon as RDNA4: the AMD shader compiler crashes (amdxc64+0x861b9f) when pipelines compile on several threads; one thread avoids it #2124 has a workaround or a fix. If the fix is "skip the offending class", the census may be reachable again quickly.

On #1349: that card is not in this machine, so I cannot give you a same-hardware comparison. What I can add is the RX 9070 XT side of the picture at the moment refusals were zero - which, per my earlier runs, is the whole steady state on this card since #336 landed, so the "how much pressure remains" answer from here is likely "none that the dynamic pool can see, whatever the tables do".

I would rather not report a census from runs that die at 86% of pipeline compilation; a truncated window is worse than a historical one, and you already have my full historical breakdown.

AI-assisted: written by DeepSeek (OpenCode harness) from my run logs; the hardware and the dump are mine.

@aycow

aycow commented Nov 25, 2026

Copy link
Copy Markdown
Author

Updated against current main at e9d3e95. Sharing now checks for fixed backing before caching an immutable table because upstream can evict title-fed textures and reuse native placement ranges. The capped 65,536-slot synthetic fixture again went from nine failures to zero and from 65,536 to 4,096 peak slots on AMD, NVIDIA, and WARP with full GPU-based validation. The unique-table control retained its original occupancy.

Thanks @rpmaster2 for documenting the compiler crash that prevented a warm capture. The draft remains open pending evidence that eligible tables account for meaningful demand in an affected run. The documentation page has been removed and the reproduction is in the PR description.

@aycow

aycow commented Nov 25, 2026

Copy link
Copy Markdown
Author

@LooperSalty @Ender1Dragon If either of you has an authorized test slot for the capped-heap workload, this capture build at 8d1685c can now measure the exact tables #562 can share. The older reports established pool pressure. This capture separates fixed-backing eligibility and cross-recording hits from mixed or evictable tables.

Build that commit with cargo build --locked --profile diag -p victory --features diagnostics. For both runs, set VICTORY_LOG=info and VICTORY_DESCRIPTOR_DEMAND=1. Use VICTORY_DESCRIPTOR_DEMAND_NO_SHARE=1 for the baseline and 0 for the reuse run. Start a fresh process for each arm and match the adapter, driver, save, cache state and present window. The same binary runs both modes.

Please share only the rebuilt descriptor demand lines and the adapter, driver and scene phase. A zero-eligible or zero-refusal window is useful, and a first-refusal snapshot is enough if the run ends early. The collector reports exact eligibility, cross-recording hits, live and peak slot counts, and refused ranges. The capture is separate from the draft PR.

@aycow

aycow commented Nov 25, 2026

Copy link
Copy Markdown
Author

Quick follow-up for @LooperSalty and @Ender1Dragon. If either of you has an authorized test slot, one matched pair on the capped-heap workload would help resolve the review question for #562.

Use the same capture build at 8d1685c, with a fresh process for each run. Keep the adapter, driver, save, cache state, heap cap, and present window matched. Set VICTORY_LOG=info and VICTORY_DESCRIPTOR_DEMAND=1 for both runs. Set VICTORY_DESCRIPTOR_DEMAND_NO_SHARE=1 for the baseline and 0 for reuse.

Please post just the aggregate rebuilt descriptor demand lines for both runs, including any first_refusal line in the matched window. The comparison is cross-list hits (SharedOtherList), peak slots for the same capacity, and allocation failures (NoRange). A zero-hit or unchanged result is useful too. If the scene is blocked before a matched window, a short status is enough.

Snapshot descriptor generations and take non-resurrecting title resource references. Release the registry before descriptor creation, state changes or uploads. Keep the references live through preparation, and drop them after releasing the registry even on a rejected table.
@fuzeofficlal

Copy link
Copy Markdown
Contributor

Reviewed and verified 134dde05 on Windows 11 (RTX 5090 + WARP) against main (13f91ca).

Code review

  • Lifetime and safety look solid: Heap::texture_table_records snapshots [tag, id, generation] under VIEWS and acquires temporary refs via object::try_add_ref so resources mid-teardown are not resurrected; SharedTextureTable holds DynamicRange, the heap, and backing ID3D12Resources while DynamicSlots::shared keeps only Weak, and draw::State::shared_tables keeps the Arc alive through execution/replay.
  • Dirty detection & heap replacement: TextureTableKey incorporates (slot, generation << 32 | id, raw_resource) so rewritten slots miss cleanly; cache hits still call readable(..., true) for every used slot so uploads/transitions stay intact; HostHeap::identity() + DynamicRange properly isolates heap replacement at the same address.
  • Eligibility note on current main (13f91ca): fixed_table_texture intentionally requires copy.key.is_none() && copy.placement.is_none() to avoid eviction and placement hazards. Note that in resource.rs:1256 (shared_texture), almost every standard DXGI format with element(desc.format).is_some() (1..=99, 115..=120, 189..=191) is assigned t.key = Some(memory_key(...)). On current main, common-format non-placed textures will therefore have key.is_some() and bypass shared-table reuse until HostHeap::evict (and #2707) can invalidate or account for slots pinned in SharedTextureTable.

Verification (Windows 11, RTX 5090 + WARP)

  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1: 200 passed, 0 failed, 2 ignored.
  • capped_pool_texture_table_reuse (--features diagnostics, -- --ignored --nocapture):
    • WARP: over-cap shared=false failed=9 peak=65536 vs shared=true failed=0 peak=4096.
    • RTX 5090:
      • over-cap: shared=false failed=9 peak=65536 prepare_ms=9.021 vs shared=true failed=0 peak=4096 prepare_ms=0.946
      • equal-work: shared=false peak=49152 prepare_ms=2.597 vs shared=true peak=4096 prepare_ms=0.886
      • unique (no reuse): both failed=0 peak=49152, prepare_ms=2.613 (shared=false) vs 9.763 (shared=true)
  • RTX 5090 unit suites (--test-threads=1): descriptor::tests 7/7, draw::tests 11/11.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default and --features diagnostics): 0 warnings; cargo xtask policy: 185 files ok.
  • Merge compatibility: clean git merge-tree against 13f91ca and #2707 (fb10ff37); conflicts in crates/victory-gpu/src/draw.rs with #2650 (3e606d27).

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.

5 participants