Repository navigation
D3D12.X: gate vram_small block recycling on GPU fences, evict idle heaps under VRAM pressure, and pack small Texture1D - #3025
Conversation
…esent in flight)
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>
This reverts commit bd4584d.
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)
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.
|
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
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. |
|
RTX 3060 12 GB (NVIDIA): on a retail title the base 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,
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 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. |
|
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.
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 Sampled peak GPU 281 MiB, minimum available RAM 9126.49 MiB, minimum available disk 12.0567 GiB. Evidence: 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. |
|
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: Test report, not a review. Both PRs applied together on
Run C, at the removal: Not tested: each PR alone, AI use: Claude Code, Claude Sonnet 5.5 ran the runs and wrote this. |
|
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
What I checked, all fine:
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. |
|
Half of the top commit (d818f46) is already on AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
Fixes premature block reuse in
vram_smallacross multi-second pipeline-compile stalls, adds idle fallback-heap eviction under VRAM pressure, and enables 4 KiB sub-allocation for smallTexture1Dresources.Summary
alloc_pool::pending_gpu_marks()+GpuMarks):SmallPoolsandDefaultFallbackPoolsonly waited for wall-clockCOOL = 2sbefore 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.alloc_pool::pending_gpu_marks()(all in-flight(fence, value)pairs wherecompleted < value) and cannot be recycled until bothCOOLhas elapsed and every captured title-queue fence has completed.sweep_idle_heaps):pinned_count(live + cooling blocks) inDefaultFallbackPools.vram_pressure_tight()reports local VRAM usage >= 85% of budget or low system commit (cached every 250 ms),forget_fallbackdrains completed cooling blocks and drops empty 16 MiB heaps (pinned_count == 0) outside the pool mutex.Texture1Dpacking:D3D12_RESOURCE_DIMENSION_TEXTURE1Dresources (< 64 KiB, non-UAV/RT/DS) intoSmallPoolsso tiny 1D LUTs pack at 4 KiB granularity instead of 64 KiB.fallback_pool_blocks_recycle_until_gpu_fence_completes_even_after_coolsmall_pool_blocks_recycle_until_gpu_fence_completes_even_after_coolfallback_pool_evicts_empty_heaps_under_vram_pressurecandidate_accepts_small_texture1d_for_4k_small_poolVerification
(All 4 new unit tests pass; the 1 ignored test is the pre-existing
bench_fallback_pool_vs_committed_and_xg_dedupbenchmark.)