Skip to content

D3D12.X: gate vram_small block recycling on GPU fences, evict idle heaps under VRAM pressure, and pack small Texture1D - #3025

Open
Saksukella wants to merge 286 commits into
xcl-dev:amd-devfrom
Saksukella:fix/vram-small-fence-cooling-and-tex1d
Open

Saksukella wants to merge 286 commits into
xcl-dev:amd-devfrom
Saksukella:fix/vram-small-fence-cooling-and-tex1d

Conversation

@Saksukella

Copy link
Copy Markdown
Contributor

Fixes premature block reuse in vram_small across multi-second pipeline-compile stalls, adds idle fallback-heap eviction under VRAM pressure, and enables 4 KiB sub-allocation for small Texture1D resources.

Summary

  1. GPU-fence-gated cooling (alloc_pool::pending_gpu_marks() + GpuMarks):
    • Previously, SmallPools and DefaultFallbackPools only waited for wall-clock COOL = 2s before recycling freed blocks. When a multi-second PSO compilation stall holds title-queue work in flight longer than 2 s, wall-clock cooling expires while the GPU is still reading/writing the old resource, causing placement aliasing / UAF.
    • Freed blocks now capture alloc_pool::pending_gpu_marks() (all in-flight (fence, value) pairs where completed < value) and cannot be recycled until both COOL has elapsed and every captured title-queue fence has completed.
  2. Idle fallback-heap eviction under VRAM pressure (sweep_idle_heaps):
    • Track per-heap pinned_count (live + cooling blocks) in DefaultFallbackPools.
    • When vram_pressure_tight() reports local VRAM usage >= 85% of budget or low system commit (cached every 250 ms), forget_fallback drains completed cooling blocks and drops empty 16 MiB heaps (pinned_count == 0) outside the pool mutex.
  3. 4 KiB Texture1D packing:
    • Allow small sampled D3D12_RESOURCE_DIMENSION_TEXTURE1D resources (< 64 KiB, non-UAV/RT/DS) into SmallPools so tiny 1D LUTs pack at 4 KiB granularity instead of 64 KiB.
  4. Unit tests:
    • fallback_pool_blocks_recycle_until_gpu_fence_completes_even_after_cool
    • small_pool_blocks_recycle_until_gpu_fence_completes_even_after_cool
    • fallback_pool_evicts_empty_heaps_under_vram_pressure
    • candidate_accepts_small_texture1d_for_4k_small_pool

Verification

$ cargo test --manifest-path C:\XCL-wt\pr14-vram-small-uaf\Cargo.toml -p xcl --lib -j 4 -- hle::d3d12x::vram_small

test result: ok. 10 passed; 0 failed; 1 ignored; 0 measured; 1710 filtered out; finished in 0.14s

(All 4 new unit tests pass; the 1 ignored test is the pre-existing bench_fallback_pool_vs_committed_and_xg_dedup benchmark.)

ivall and others added 30 commits November 25, 2026 16:29
A retail game unmaps addresses while it streams its world with
XMemMapPhysicalPagesScatter(addresses, n, NULL); it checks the result
and runs into its own int3 when the call fails (+0xb18de7, then its
crash reporter). XCL refused a NULL page array with
ERROR_INVALID_PARAMETER. Page 0 already means "unmap this address" in a
scatter, so no array is taken as page 0 for every address.

Test scatter_without_pages_unmaps: two pages mapped and written, unmapped
with no array (the call succeeds, the addresses are no longer committed),
mapped again they read what was written. It fails without the change
("refused").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retail title keeps its destination page lists in slots of its own
table and writes a slot's pages after EnqueueRequest. At enqueue such a
slot can still name the pages of the slot's previous request, and the
snapshot taken then is what execute() wrote to (xcl-dev#289 rereads only the
entries that are 0). Over 16 000 requests a run were written into pages
the title had since reused: its objects got garbage pointers and it
crashed about 20 s into world loading; when the old pages were freed,
the request failed with E_ACCESS_VIOLATION.

The console reads the list when it runs the request. execute() now
reads it again (through read_own, as the snapshot) and takes it when it
differs and every page in it is allocated (kernelx::physical_pages_live).
A list that was on the enqueuing thread's stack keeps the snapshot: that
memory is reused once the call returns, and a page ID written there
since can belong to another live allocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir pages with their texels

A retail title places its streamed textures at full size and has memory behind
their levels only as it loads them, the small ones first. vram::place_pages
gives a sampled texture a 64 KiB page of video memory for every tile at once:
when that title's world is set up about 92 % of those pages have nothing behind
them (80 690 pages, 6 809 committed, on one card).

With the switch (off by default) a sampled 2D texture of one slice is placed
with no tile mapped. Its tiling is kept as groups of tiles, one for each level
with tiles of its own and one for the packed levels, and a group gets its pages
before the first upload that has texels for it - the same pages by address as
before, so textures placed at one address still share them. A texture the GPU
writes gets all its pages.

Part of xcl-dev#1773.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… done

When the GPU-wait watchdog releases a wait (xcl-dev#505), its lines say which
queues wait on which, but not what the GPU is running. With
XCL_GPU_CULPRIT=1 every dispatch XCL records (title lists,
console-recorded lists, ExecuteIndirect of a translated compute
pipeline) is wrapped in WriteBufferImmediate markers, in before and out
after, one pair of words per PC list in a readback buffer. At a release
the lists whose marker in is above their marker out are logged with the
dispatches between the two: console CS (fnv64 of the title's bytecode),
PC pipeline and groups.

On the retail title of xcl-dev#505 (RTX 5080) this named, at each stall, one
list with a run of 1-D dispatches of one CS whose first never finished;
not the same CS from run to run. DRED breadcrumbs were tried first: they
change the driver's pipeline cache keys, so every pipeline was built
again and the title never got past its start.

Off by default; without the variable nothing is recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring in 36 upstream PRs from origin/main (xcl-dev#2310..xcl-dev#587) onto amd-dev (c7a18d8) while preserving all local AMD RDNA4 work (xcl-dev#615 pipelined presenter SRVs, xcl-dev#495/xcl-dev#1405 XCL_PAGE_ALIAS=1 hooks, xcl-dev#2306 level tiling timers, xcl-dev#1989 vtable fix, mesh user SGPRs).

Resolved 4 conflicts:
- console_list.rs: kept both mesh_arguments_go_in_user_sgprs_from_s16 and xcl-dev#2323 dispatch-heap tests
- real.rs: kept both effective_st depth-UAV tracking and xcl-dev#2280 pc_clear_for_desc
- vram.rs: kept Step::Tiling timer around level_tiling
- kernelx.rs: kept XCL_PAGE_ALIAS=1 hooks in physical_pages_live and XMemMapPhysicalPagesScatter

Assisted-by: Antigravity (Gemini 4 Neon High)
Both internal indirect-argument rewrite passes in bind.rs (guard_dispatch_args and make_scaled_args_buffer) emitted the exact DRED breadcrumb pattern (barrier, barrier, marker, Dispatch, barrier, marker) with an unlabeled pipeline and had root-binding and alignment hazards on AMD RDNA4:

1. Neither guard_indirect_pipeline nor scale_indirect_pipeline called dred::label_text (or SetName), so DRED printed the fallback stand-in label.
2. Both reused abi_root_signature (6 root UAVs + directly-indexed heap flags) while leaving slots unbound; SCALE_ARGS_HLSL statically references cnt (u4) via a ternary even when no count buffer is bound.
3. src_va and count_va were passed directly to SetComputeRootUnorderedAccessView even when args_off or count_off was not 16-byte aligned (e.g. 12-byte Dispatch argument strides or 4-byte count offsets).

Fix all three: label both pipelines for DRED, give args_pipeline a minimal root signature with every parameter unconditionally bound (binding u4 to consts_va when count is None and guarding cnt.Load with an if), align root UAV bases down to 256 bytes and pass the byte offset via io, guard GUARD_ARGS_HLSL divisions, and validate bundle/stride/offset bounds.

Assisted-by: Antigravity (Gemini 4 Neon High)
Console D16_UNORM_S8_UINT (118..=120) depth+UAV twins used R16_UNORM SRVs and a float fullscreen pass. Because 2^24-1 is not a multiple of 65535, hardware R16_UNORM conversion can differ by 1 ULP from float(k) * asfloat(0x37800080) computed by tiled-lighting DepthFunc = EQUAL vertex shaders, rejecting lighting draws on AMD RDNA4.

Read the R16_TYPELESS twin as R16_UINT in a dedicated fullscreen PSO returning float(val) * asfloat(0x37800080) for console formats 118..=120, and update the twin-plan unit test.

Assisted-by: Antigravity (Gemini 4 Neon High)
…olves

Command list xcl-dev#146 (uav_barrier_x) synced depth+UAV enhanced barriers and PlacedUav format-alias pairs, but never checked D3D12_BARRIER_TYPE_TEXTURE transitions on TitlePlaced format-alias writers (such as R9G9B9E5 lighting targets), leaving aliased SRVs stale under enhanced barriers.

Add format_alias::filter_enhanced_barriers and call sync_title_writers in uav_barrier_x. Also translate console target formats in resolve_subresource_x and resolve_subresource_region_x via device_x::pc_target_format.

Assisted-by: Antigravity (Gemini 4 Neon High)
buffer_view (used by CreateShaderResourceView and CreateUnorderedAccessView on buffer resources) returned empty V# descriptors for placed GPU-view buffers, and dev_create_cbv_x / buffer_words_at only fell back to read-only sparse::gpu_view mirrors (requiring XCL_GPU_VIEW_BUFFERS=1 and skipping UAVs).

Add real::resolve_uma_va(va, len) consulting kernelx::mirrors::mapped_source and mirrors::source with per-64-KiB-page contiguity verification inside UMA, wire it ahead of sparse::gpu_view::base_for in buffer_view, dev_create_cbv_x, and buffer_words_at, and add read-only sparse fallback to buffer_view.

Assisted-by: Antigravity (Gemini 4 Neon High)
Keep amd-dev 0 commits behind origin/main (xcl-dev#573, xcl-dev#2083, xcl-dev#2345, xcl-dev#2342).
Resolved 1 conflict in bind.rs: kept pso_for_draw(raw_pso) and bounds-checked commands_at/count_at while taking xcl-dev#2342 failed shared compute stand-in check.

Assisted-by: Antigravity (Gemini 4 Neon High)
map_pages and move_away previously called sparse::committed(at, PHYS_PAGE)
inside the per-page loop. When a large physical-page allocation (~2+ GB) lands
in a sparse UMA window (such as Series S / lockhart TileHeap), this issued
~34,000 separate 64 KiB UpdateTileMappings + queue.Signal calls (>31 s at
~64 MB/s), tripping the title's 30 s init watchdog.

Coalesce contiguous 64 KiB sparse-window commits in SparseCommitBatch across
map_pages, move_away_batched, MapTitlePhysicalPages, and
XMemMapPhysicalPagesScatter, flushing early on any overlapping decommit/unmap.
Reduces ~34,000 UpdateTileMappings calls to one batched commit per contiguous
run (~34 pool-heap calls, <100 ms).

Assisted-by: Antigravity (Gemini 4 Neon High)
Titles can enqueue DirectStorage requests with heap-backed
DestinationPageArray pointers, populate/map the physical page lists, and then
call Submit(). Auto-submitting the queue at half capacity let worker threads
run mid-batch against unpopulated page entries, dropping streamed geometry.

When the pending queue contains any non-stack DestinationPageArray request,
suppress the half-capacity auto-submit and wait for explicit Submit() (or full
queue capacity), while keeping normal half-capacity auto-submit for memory,
file, and stack-backed page-list requests.

Assisted-by: Antigravity (Gemini 4 Neon High)
VOP3 v_interp_p1ll_f16, v_interp_p1lv_f16, and v_interp_p2_f16 encode
(high << 8) | (chan << 6) | attr in SRC0 (OPR_ATTR). For attr63.w (attr=63,
chan=3, high=0), SRC0 == 0xFF == 255, which rdna2::decode's VALU fallback
literal scan mistook for a 32-bit inline literal and consumed the following
instruction word.

Skip fields explicitly typed as non-source operands (!is_src_type) during the
VALU fallback literal scan while keeping v_nop's empty-operand hidden shader
hash literals intact.

Assisted-by: Antigravity (Gemini 4 Neon High)
ivall and others added 10 commits November 27, 2026 12:47
Share identical shader bytes from different title addresses and check byte equality before reusing a hash match.

Assisted-by: Codex (exact model identifier unavailable)
Port the mapping and retirement changes from xcl-dev#2981. Seal only the unmaps covered by the queue signals and keep zero-buffer aliases alive through retirement.

Assisted-by: Codex (exact model identifier unavailable)
Adapt xcl-dev#2821 to bound fence waits and retry unsent writes when a slot is still busy. Use smaller upload and readback staging buffers with chunked transfers.

Assisted-by: Codex (exact model identifier unavailable)
Port xcl-dev#2912 so finished staging allocations are reaped even when the originating queue goes quiet.

Assisted-by: Codex (exact model identifier unavailable)
Port xcl-dev#2985 so supported fallback resources can share backing heaps and reuse the decoded layout.

Assisted-by: Codex (exact model identifier unavailable)
Sample process pages to distinguish unified, sparse, and other resident memory in the diagnostic report.

Assisted-by: Codex (exact model identifier unavailable)
Track the latest submitted work along with missing completion markers.

Assisted-by: Codex (exact model identifier unavailable)
Port the GPU timestamp profiler from nvidia-dev ea22791, including submission and pipeline identification hooks.

Assisted-by: Codex (exact model identifier unavailable)
XCL moves from GPL-2.0-only to GPL-3.0-or-later so that code can move
between XCL and GPL-3.0 projects (VIctory and its forks) in both
directions.

- LICENSE: the GPL-3.0 text from gnu.org; Cargo.toml: GPL-3.0-or-later.
- README, CONTRIBUTING, AGENTS, SECURITY: the new licence and the
  GPL-3.0 compatibility rule for dependencies.
- THIRD_PARTY.md: the GPL-3.0-compatible licence list; VIctory is used
  under its own GPL-3.0; AnyPS5 is listed as a reference only.
- AnyPS5 was read as a description of the hardware behaviour (MIMG A16
  address layout, 16-bit VALU halves), no code was taken from it: the
  two comments in recomp/emit.rs that said "ported" now say so.
- Headers of the VIctory and FFmpeg ports no longer name GPL-2.0-only.

No code change.

(cherry picked from commit 06f90c1)
… pack TEXTURE1D at 4 KiB

1. Gate `SmallPools` and `DefaultFallbackPools` block reuse on both `COOL`
   (2 s) and completion of all in-flight title-queue fences captured via
   `alloc_pool::pending_gpu_marks()`, preventing premature placement aliasing
   across multi-second pipeline-compile stalls.
2. Track per-heap `pinned_count` in `DefaultFallbackPools` and evict empty
   16 MiB heaps outside locks when local video memory exceeds 85% of budget
   (or system commit is low).
3. Include `D3D12_RESOURCE_DIMENSION_TEXTURE1D` (`< 64 KiB`) in `SmallPools`
   so tiny sampled 1D LUTs pack at 4 KiB granularity instead of 64 KiB.

Add unit tests covering GPU-fence-gated cooling for both pools, empty-heap
eviction under VRAM pressure, and `TEXTURE1D` 4 KiB eligibility.
@vibryxcx

Copy link
Copy Markdown

Title A/B on an RX 6800 (RDNA2, 16 GB). No measurable change in peak video memory, run length or frame rate in 4 runs.

Setup: RX 6800, driver 32.0.21045.5002, i5-10600KF, 32 GB, Windows 11 Pro 26200, release builds of base 7c795f5e (amd-dev; its runtime is the same as 494f08b2) and head d818f464, clean worktrees, same retail title with warm caches. 300 s runs, A every 10 s, interleaved, with 2 min between runs. Peak video memory is the highest video memory N of a M budget value XCL logged in the run.

run tree end last present fps while presenting (avg / peak) peak video memory (budget at the end)
1 base 0x887a0020 at 286 s (after the title int3 at +0x2474606) 285 s 11.0 / 34.5 16,343 MB (14,049)
2 head 0x887a0020 at 269 s 268 s 10.3 / 33 16,066 MB (13,999)
3 base 0x887a0020 at 236 s (after the same int3) 235 s 11.9 / 33.5 15,684 MB (13,998)
4 head 0x887a0020 at 274 s (after the same int3) 273 s 10.7 / 33 15,880 MB (14,006)
  • Peak video memory: base averages 16,014 MB and head 15,973 MB, within run-to-run noise. Both trees go about 2 GB over the DXGI budget on this card before the device loss.
  • Run length and frame rate: the same on both trees.
  • So the vram_small pools may simply not be a large share of this title's video memory here. The per-owner memory lines would tell, and I can rerun with them if that helps.

Not tested: more runs; a per-owner breakdown of where the 16 GB goes; RDNA3/4; NVIDIA.

AI use: Claude Code (Claude Opus 5.5) ran the A/B through a local test runner, read the logs and wrote this comment.

@Anon64

Anon64 commented Nov 27, 2026 •

Copy link
Copy Markdown

RTX 3060 12 GB (NVIDIA): on a retail title the base 7c795f5e lost the device in 2 of 2 runs (0x887a0006 at ~200 s after the first frame); this PR d818f464 ran its 300 s clean in 2 of 2 runs.

Edit: a second PR run added: exit 0x0, 1 888 frames, presents to ~316 s, peak commit 26 836 MB, local 9 712 MB, non-local 5 302 MB, no device removal.

Release builds, XCL_ACTIVITY=1, A pressed every 4 s from 20 s, warm caches, 300 s each.

base 7c795f5e run 1 base run 2 PR d818f464
end device removed 0x887a0006, then the title's own break 0x80000003 the same, at 228 s exit 0x0 at 300 s
frames none logged none logged 1 955
peak commit 26 256 MB 25 793 MB 26 438 MB
peak local video memory 9 459 MB 9 511 MB 9 615 MB
peak non-local 5 126 MB 5 145 MB 5 107 MB

So here the PR keeps memory where it was, as the RX 6800 check above also found. It does take away a device removal the base hits every time. That fits the first point, recycling vram_small blocks only after their GPU fences. Two runs per side is still a small sample, and I have not checked which of the three changes does it.

xcl-smoke v1
commit: d818f4643dcf5e950fefd12ec98faefa699c4b02
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 300
exit: 0x0
frames shown: 1955 (PresentX 1955)
presents per 2 s (last 3): 1 0 1
device removals: 0
crashes: 0
peak commit: 26438 MB

RTX 3060 12 GB (driver 581.80), i9-14900KF, 64 GB RAM, Windows 11 26200.

AI use: Claude Code (Claude Opus 5.5) built both sides, ran the title and wrote this report.

@pickles976

Copy link
Copy Markdown

Local Wine/NVIDIA verification of exact production d818f46, with test-only fail-closed host assertions and one native-fence retention probe; no production changes or title run.

Linux 6.17, i7-13620H, 16 GiB RAM, physical RTX 4060 Laptop 8 GiB / NVIDIA 590.48.1, Wine 11, Rust 1.98.1, Windows MSVC target. Diagnostic-relaxed-vtable vkd3d-proton 2576c0b4adfae4a+; this is NOT stock-vkd3d certification. DXVK NVIDIA masking disabled. External 6000 MiB GPU / 2048 MiB available-RAM / 10 GiB disk cutoffs, 9 GiB scope + 512 MiB swap remained unchanged.

cargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib vram_small::tests:: -- --nocapture --test-threads=1: 11 passed, 0 failed, 1 ignored benchmark, 0.74 s tests. Fresh intended-worktree Compiling xcl .../xcl-pr3025/crates/xcl, 32.64 s build / 34.35 s total.

The two existing hardware fixtures now require a physical NVIDIA device and their heap/tile capabilities rather than returning early. Small texture pixel readbacks pass, including the shared backing/alias checks. 512 BC1 textures account for 2 MiB used within a 16 MiB small pool; that is allocation bookkeeping, NOT a measured 32-to-2 MiB physical VRAM reduction.

The added probe uses a real native queue held on a CPU-signaled fence (no intentionally stalled shader), calls production alloc_pool::executed(queue, &[]), and captures production pending_gpu_marks. Both small/fallback pool models retain their old blocks after synthetic idle/cooling deadlines while that native fence is pending. After CPU release and bounded native completion, the same blocks recycle; after all fallback blocks retire, the empty model heap is evicted. The release guard also signals on panic. This tests native-fence capture and reuse/eviction policy together; the modeled heaps are u32 identities, so it does NOT prove physical heap eviction or texture integrity across a still-pending GPU read.

Sampled peak GPU 281 MiB, minimum available RAM 9126.49 MiB, minimum available disk 12.0567 GiB. Evidence: .compat-runtime/logs/verify-xcl3025-native-fence-pool-lifetime-20261127T191536Z/ (console, resource samples, manifest). Local test changes retained as provenance.

Next useful owner gate: retain a real placed texture's pending GPU use across release/cooling, then verify its bytes after completion and reuse. No matched-parent, peak-title-memory, frame-time, loading, or Game-Init stuck-fence improvement is claimed here.

@kleborgn

Copy link
Copy Markdown

Setup: AMD Radeon RX 7900 XTX 24 GB (driver 32.0.32029.2010), Ryzen 9 7950X3D, 31 GB RAM, Windows 11 Pro 26300, Rust 1.100.0, release, DXC 1.8.2505.32. Tree: amd-dev 7c795f5 + #3024 (b7fc3b4) + #3025 (d818f46) applied as patches. XCL_NETWORK=0 throughout.

Test report, not a review. Both PRs applied together on amd-dev 7c795f5 (b7fc3b4 + d818f46), RX 7900 XTX (setup line above).
I did not run 7c795f5 without them, so nothing below can be credited to one PR or to both.

run settings (besides XCL_NETWORK=0, XCL_DRED=1) first ListX #101 result
A hive recipe: XCL_RT_GATE=miss XCL_PREPARE=0, native wave64 94 s last present 95.7 s, then 0 presents to the 600 s timer; no removal; 15,374 draws (4,096 skipped), 6,388 dispatches; plib 8 hits / 1,447 misses
B XCL_DIRECT_DXIL=1 XCL_SPLIT_WAVE64=1 XCL_RT_GATE=auto XCL_PREPARE=0 XCL_PIPELINE_MAX_KB=1500 66 s 600 s timer, no removal, 1,649 presents, last present 584 s; 93,783 draws (35,481 skipped), 70,639 dispatches (55 skipped)
C as B, 40 min window 66 s device removed at 623.4 s (0x887a0006), 1,812 presents, 381,777 draws, 327,425 dispatches

Run C, at the removal: DRED page fault at GPU VA 0x0; allocations there: []; recently freed: []. The first command list DRED
names was 19 of 23 operations done with xcl prelude_scale_mesh_args bound (an XCL helper, not a title shader). Title,
texture-upload, VRAM-page and sparse-readback queues had work pending and had not moved for ~2.3 s. In the 2 s before it the title
submitted 7,353 draws and 4,920 dispatches after ~15 s of nothing (it had been waiting on cold graphics builds, 5 "still going").
The older page fault I saw at ~85-88 s on 60d67a1 / 04e0b95 (freed resources, dispatch_chain_slicer bound) did not appear
in any of these runs; as said above I cannot tell whether #3024 / #3025 or other commits in between removed it.

Not tested: each PR alone, 7c795f5 plain, more than one run per row, cargo test, scripts/smoke.ps1.

AI use: Claude Code, Claude Sonnet 5.5 ran the runs and wrote this.

@Grimkaaah

Copy link
Copy Markdown

I compared this with the block reuse and spare-heap code in my project. There, a pooled texture's block is given back only when the native texture is destroyed, and that happens only after every submission running at the time has finished. I read this PR's own commit d818f46 against xcl's late_release.rs and the D3D12 docs. The other 285 commits come from the PR's base line.

  1. Rebase. GitHub shows the PR as conflicting with amd-dev. It carries 286 commits and 112 files because it is based on 7c795f5, which amd-dev doesn't contain.
    • amd-dev (6bab0c5) already has the SmallPools fence gate and the TEXTURE1D candidate in vram_small.rs. They came in with 6fa964d, together with this PR's TEXTURE1D test.
    • amd-dev has no DefaultFallbackPools. That pool comes from 47cbd3a on this PR's base line.
    • So on amd-dev, this PR would only add the fallback-pool half, and that needs 47cbd3a first. Please say in the PR which part is left.
  2. The gate is off when XCL_ALLOC_SWAP=0. pending_gpu_marks() reads alloc_pool's per-queue fences, but executed() returns before it signals them when the swap is off (alloc_pool.rs:304). GpuMarks is then always empty, and reuse depends on COOL alone. amd-dev has the same early return. Fix: signal and record the per-queue fence in executed() whatever the swap switch says (move the enabled() check below the Signal), or take the marks from late_release (point 2).
  3. The marks only cover queues that go through alloc_pool::executed, which are the title's. The block goes into cooling at the title's last Release: real.rs:2139 -> vram.rs:254-260 -> vram_small::forget / forget_fallback.
    • At that point late_release still holds the native placed resource. It keeps it until the title's queues, the tile-mapping queue, the sparse queue and the upload queues have passed a seal (late_release.rs:173-195).
    • So there are two lifetimes for the same memory, and the one that gates reuse covers fewer queues.
    • Fix: give the block back when the native resource really goes. Either do it from the late_release drain, as vram::recycle_ready does (late_release.rs:207), or attach a small COM object to the placed resource with SetPrivateDataInterface whose final Release returns the block. We use the second; it works with and without late_release.
    • Then reuse waits for every queue late_release knows about. GpuMarks is only needed with XCL_LATE_RELEASE=0.
  4. GpuMarks::capture() (vram_small.rs:53) takes alloc_pool's STATE lock and calls GetCompletedValue on every title fence, once per block.
    • It does this while SMALL_POOLS is held (vram_small.rs:128, inside try_acquire's sweep) or FALLBACK_POOLS is held (forget_with, :493).
    • STATE is also taken on every title ExecuteCommandLists.
    • This adds a new lock order, pool lock -> STATE. I found no path that takes them the other way round, so there is no deadlock today. It also means N captures per sweep.
    • Suggest one capture before taking the pool lock, shared through an Arc by every block of that sweep or forget. A snapshot taken a little later is still on the safe side.
  5. Eviction (vram_small.rs:640-658, sweep_idle_heaps at :407) drops every empty 16 MiB heap whenever use is at or above 85 %. It only runs when a fallback resource is released.
    • (a) There is no floor. The next fallback placement while still above 85 % creates a heap again, which is the CreateHeap cost the pool is there to avoid, and the next release drops it again. Keeping one empty heap per device, or evicting only heaps that have been empty for a few seconds, avoids that churn. We keep at least 2 spare blocks and count blocks re-made soon after being let go.
    • (b) Dropping the heap doesn't free its memory yet. The runtime keeps a heap alive while placed resources on it exist, and late_release still holds those resources. So bytes() (active_pool_count) reports the memory gone before it is. This is not a safety problem. For the same reason, eviction can't take memory away from a list still in flight.
    • (c) Under pressure with no releases, nothing is evicted. Calling the sweep from somewhere periodic would fix that, for example where release_finished is polled at PresentX.

What I checked, all fine:

  • TEXTURE1D goes through place(), which keeps the 4 KiB placement only if GetResourceAllocationInfo returns 4 KiB alignment (vram_small.rs:290). A driver that refuses it for 1D falls back.
  • pinned_count stays balanced across acquire, rollback, forget and drain.
  • An evicted pool's free entries are removed before its slot is reused.

Not checked: we haven't built or run this PR, with or without a title. We don't test on NVIDIA. I didn't check whether the fallback pools hold enough memory to matter; vibryxcx's A/B suggests they don't on that title.

AI use: Claude Code (Claude Opus 5.5) reviewed this by comparing it with the same mechanism in my project, Victory Grimkaaah.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head d818f46

Half of the top commit (d818f46) is already on amd-dev via 6fa964d: the same GpuMarks fence-gated cooling for SmallPools, alloc_pool::pending_gpu_marks and the TEXTURE1D candidate with its test.
The rest (fence gating and idle-heap eviction in DefaultFallbackPools) targets code from 47cbd3a, which is not on current amd-dev (no DefaultFallbackPools/forget_fallback there; #2985 was closed in its favour). It cannot land without that base.
The branch also carries about 235 commits not on amd-dev, which is where the +51k lines come from.
Recommendation: keep open, but rebase onto current amd-dev and reduce it to what is missing there.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.