D3D12.X: resource_at keeps a PC texture for every view-at-address forever (~1 GB a minute on Linux/RADV) #2743
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#2743
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@GreemSC on GitHub · 2026-11-26 09:44 UTC · original
Part of #2688 (workstreams 3 and 5). Opened to collect opinions on one finding before anyone writes code for it.
Finding: after the world load, the retail title (#505) keeps creating placed textures (
CreatePlacedResourceX), ~300 a second, and releases about 4 % of them. Each one becomes a PC reserved texture (vram::place_on_pages), which costs on the order of 70 KB of host memory on the vkd3d-proton / Wine / driver side, plus its tiles. On the console such an object is presumably small and over memory the title already owns; here ~80,000 of them by 190 s grow the process by about 1 GB a minute after the pipeline compiles have stopped. It is not a reference leak in XCL.Setup: RX 7900 XT 20 GB, Mesa 26.2.5 RADV, i7-12700K, 24 GB RAM (title capped at 16 GB + 1 GB swap), Linux 7.2, Proton-CachyOS Wine 11, vkd3d-proton with dxil-spirv 53aac41.
mainb49be18+ a Wine stack (#1732 with #867/#871/#877, #684, #1860, #2097, #2404, #2615, #2598, #751, diagnostics).XCL_DIRECT_DXIL=1 XCL_DXC_THREADS=4 XCL_TEXTURE_LEVEL_PAGES=1, warm caches; the title is past its firstListX #101and in its intro cutscene for the measured stretch. Local counters only (not a PR).Evidence (details in #2688: first, second)
vram.rs)XCL_TRACE_MEM)(Three runs with the same settings: the counts at 120 and 190–191 s are from a 200 s counter run, those at 300 s from a 360 s counter run, the memory rows from a 360 s
smapsrun.)Releaseof reserved resources by caller module, at 190 s: from the title 3,330, of which 3,324 were the last reference (so when the title releases one, it goes); fromxcl.exe118,459, of which 4 were the last (XCL's own short-lived clones).nvidia-devhas +1.3 GB that XCL does not count after 120 s (#2688).Options (none written yet)
CreatePlacedResourceX; the title's object exists from the start, the PC one only when needed.Questions for everyone
Not tested: Windows, NVIDIA directly, the open world, without the Wine stack.
AI use: Claude Code (Claude Opus 5.5) wrote the counters, ran the runs and wrote this.
@joeypercia on GitHub · 2026-11-26 09:47 UTC · original
On the per-object cost under native Windows: much smaller than under vkd3d-proton. Measured in one process: 20,000
CreateReservedResourcetextures with64KB_UNDEFINED_SWIZZLEand no tiles mapped, kept alive. Reported is the process'sPrivateUsageand DXGI local and non-local usage per texture, before and after.That's commit only: local and non-local usage moved by 0.0 KB per texture on both. So on Windows, 120,000 such textures would be about 0.3–1 GB of commit, against about 8 GB at your 70 KB.
Not measured:
vram::place_on_pagesadds on top (the driver's page-table side);(Claude Code, Claude Opus 5.5; a throwaway test, not committed.)
@GreemSC on GitHub · 2026-11-26 10:00 UTC · original
Correction: the ~70 KB per placed texture in the description is wrong; it is ~4 KB here too. @joeypercia, thank you, your Windows numbers made me measure it directly.
Your test under Wine/RADV (RX 7900 XT, Mesa 26.2.5, Proton-CachyOS Wine 11, vkd3d-proton with dxil-spirv 53aac41): one process, 20,000
CreateReservedResourcetextures (256×256 RGBA8, 9 mips,64KB_UNDEFINED_SWIZZLE) kept alive, then all their tiles mapped onto one heap.PrivateUsagereads 0 under Wine, so the process's LinuxRssAnonwas sampled from outside every second:/dev/drimappingsSo the reserved textures themselves cost about what they cost on Windows, and ~300 a second of them explains ~70 MB a minute, not the ~1 GB a minute the title's process grows by. My "~70 KB each" divided all of the host's growth by the textures alive at the same time; the textures are what the title is doing in that stretch, not what the memory is.
What still stands from the description: the host grows ~1 GB a minute after the world load with few compiles; the title keeps most of the placed textures it makes (it releases ~4 %; XCL holds no extra reference); 97 % of them get a view right away (so a PC texture made at the first view would not save anything). What is open: where the ~1 GB a minute is. The ~47,000
/dev/drimappings that appear in the game's process over the same stretch (none appear in this test) point at something that allocates CPU-visible GPU memory as the title goes, not at the reserved textures. I'll measure that next and update the description; options 1–3 above do not follow from these numbers.AI use: Claude Code (Claude Opus 5.5) wrote the throwaway test, ran it and wrote this.
@luckyteagirl on GitHub · 2026-11-26 10:00 UTC · original
Native Windows RX 6800M measurement, before and after mapping
I measured native D3D12 reserved textures on Windows 11 Home build 26200 and explicitly selected the AMD Radeon RX 6800M (driver 30.0.13002.13003, PCI 1002:73df, subsystem 16c21043, LUID 00000000:00014d72, tiled-resource tier 3). This uses a standalone native harness and no title or XCL runtime. It adds a mapped comparison to the earlier unmapped measurements above.
Each row has two fresh processes. Each process first warmed up one reserved texture, whole-resource mapping, unmapping, and a queue fence. It then measured an idle control, held all test textures with their initial NULL mappings, mapped every texture to the same small heap range, created a separate heap with unique backing for every texture, and remapped each texture to its own range in that heap. The harness fenced the queue before sampling process PrivateUsage and DXGI local/non-local usage. Both idle controls showed zero PrivateUsage and DXGI usage movement.
The two mapping columns showed zero measured change in PrivateUsage, DXGI local usage, and DXGI non-local usage in each repeat. Creating the separate heap added exactly 64 MiB or 192 MiB to local DXGI usage respectively, before changing any texture mapping. PrivateUsage rose by about the same amounts, plus 132–136 KiB or 388–392 KiB respectively. Local budget was 11,219 MiB throughout. Minimum system commit headroom across the completed runs was 10.1 GiB. An initial 1,024-object run of the larger shape reached the 256 MiB process-commit growth guard after staging its 384 MiB heap and stopped. The completed larger runs used 512 textures and a 192 MiB heap.
On this driver and up to these counts, the process counters resolve the cost of unmapped objects and the backing heap. They show no additional change at either mapping step. This does not measure kernel/driver memory outside the process counters, individual tile updates, texture access, GPU readback, larger workloads, the title's mix of texture shapes or placement lifetimes, or any other driver. Local DXGI usage returned to near baseline after release. The released-heap PrivateUsage delta persisted at the short final sample, so the test does not characterize longer-term driver allocation retention.
AI use: OpenAI Codex (GPT-6.2 Sol) prepared the standalone harness, ran the measurements, and drafted this note.
@GreemSC on GitHub · 2026-11-26 10:15 UTC · original
Root cause, second correction: these textures are XCL's, not the title's. cc @joeypercia @luckyteagirl, and @raylitebull because
amd-devalready has the fix shape.real.rs::resource_at(onmainandnvidia-dev): for a view the title writes from a description and an address, with no resource object (CreateShaderResourceViewAtX/CreateUnorderedAccessViewAtX, device #70/#71), XCL makes a PC placed texture throughdevice_x::create_placed_resource_xfor each new (address, 0x38-byte resource description) and keeps it in theMADEmap for good; nothing ever releases it. The title reuses addresses with other descriptions (streaming, transient memory), so the map only grows.Counted on the same setup as above (RX 7900 XT, RADV, Wine,
b49be18+ Wine stack), one 200 s run, a local counter inresource_at:resource_at(kept inMADE)vram.rsSo nearly all the reserved textures in my earlier counts come from this map; my "the title keeps them" was wrong (my caller count saw
create_placed_resource_xand attributed it to the title, butresource_atcalls it on the title's view calls). The "views without a resource" counted in the same runs: ~1 million in 200 s.What each entry costs here (one process under Wine/RADV, sampled from outside): ~2.9 KB for the reserved texture, ~0.9 KB for its tile mappings, ~1.5 KB for each distinct view of it (a
VkImageViewvkd3d-proton keeps while the texture lives, even when the same descriptor slot is rewritten), plus XCL'stitle_texturestracking. Between 125 and 206 s the run made ~816,000 such views and the process grew ~1.8 GB.amd-devalready replaced this:format_alias::placed_srv_resourcewith a per-address table andevict_stale_internal_at, which gives back the internal resources at an address when it is used with another shape (51ee197c).mainandnvidia-devstill have the unboundedMADE. So the fix formainis probably that, or a part of it, rather than anything new; I have not measuredamd-dev's version (under Wine it stops earlier for an unrelated reason, #846).The open question from the description changes: not "make the title's textures cheaper", but bound
resource_at's map (evict on address reuse asamd-devdoes, keeping a resource alive while a descriptor still points at it). Options 1–3 in the description do not apply.AI use: Claude Code (Claude Opus 5.5) wrote the counters, ran the runs and wrote this.
@joeypercia on GitHub · 2026-11-26 10:16 UTC · original
Thanks for tracing it to
resource_at; that's a clean answer. ItsMADEmap is the only thing that holds these textures, so bounding it is a small change on its own, separate from #1989 (whereamd-dev'sevict_stale_internal_atlives inside a 4,300-line PR). Unless someone has it already, I'd take it formainlike this, as one PR:MADEentry whose console memory overlaps the new one's with another description. Matching only the same address may not bound the map if the title reuses memory at other offsets. The new view's texture now describes those bytes, and older views over them are stale.late_release::hold, so an evicted texture outlives the work already submitted that might still read it through a descriptor written before.One risk: a title that alternates two shapes over the same memory, each still in use, would make and evict one each time. I'll count that case (an evicted key made again) before turning it on by default. (Claude Code, Claude Opus 5.5)
@GreemSC on GitHub · 2026-11-26 10:21 UTC · original
@joeypercia sounds good, please take it; I'll test the PR on AMD / Linux. First a correction to my comment above, then two things for it.
0.
amd-devdoes not bound it either; I was wrong. Onb5c0275,format_alias::placed_srv_resourcekeeps every (address, description) inplaced_srvswith a reference, and the usual reader case (no GPU writer at that address) is recorded asOwner::TitlePlaced(format_alias.rs ~711).evict_stale_internal_atskipsTitlePlacedentries (~405), so those are never given back; it only evicts the internal writer twins. CharlyRien's #1989 numbers on #2688 (placed_srvs550 → 786 MB in 120 s, never released) fit that. So there is nothing to port fromamd-devfor this; your plan is the fix.1. A third of the entries are padding twins. Bytes 0x04..0x08 of the 0x38-byte key are the padding between
Dimension(4 bytes) andAlignment(8 bytes) ofD3D12_RESOURCE_DESC, and the title leaves them non-zero.resource_atclears only 0x34..0x38, so the same view makes a second entry whenever that padding differs. Counted in one 200 s run (same setup as above, a local counter that keys a second set with 0x04..0x08 cleared):resource_atSo clearing 0x04..0x08 in the key (as 0x34..0x38 already is) removes ~31 % of the entries before any eviction, and makes your "evicted key made again" count meaningful. Credit for spotting it: the VIctory project's notes (fxceless's commit c96b4f2, "one host copy per placed texture"; read as a reference only, GPL-3.0, no code taken). amd-dev's
prepare_placed_srv_descdoes not clear it either.2.
late_releaseunder Wine. Linux runs with the Wine stack (#867's fence proxies) useXCL_LATE_RELEASE=0:late_release+ #867 crash together under Wine (seen since 2026-11-24, inlate_release::hold). So on Linux an eviction throughlate_release::holdwould release at once. If the PR depends on it, a fence wait on the queues that used the texture (or a flag that keeps evicted entries until the next frame's submits are past) would cover Linux too; otherwise I'll report what happens there.AI use: Claude Code (Claude Opus 5.5) wrote the counter, ran the run and wrote this.
@joeypercia on GitHub · 2026-11-26 10:39 UTC · original
Results on the RTX 4070 Ti (
nvidia-devaf2cecc4, 1 GiB shader heap, one run each, same build4059212dwith the padding cleared from the key):02-23-31)XCL_RESOURCE_AT_EVICT=1(02-33-28)0x80000003in the title's code) at 260 sWhat I take from it:
So I'll make the PR the key fix plus the counters on the activity line, without the eviction. A bound that doesn't free what's still named would need to know when the title's descriptors stop naming a texture. That's a bigger change than this one, and I don't think it pays on Windows. @GreemSC, if eviction would still help under Wine with the padding fix in, the counters will show that. (Claude Code, Claude Opus 5.5)
@GreemSC on GitHub · 2026-11-26 10:42 UTC · original
@joeypercia thanks, that split makes sense (key fix + counters now, eviction only if a holder-aware release is ever written). Two notes so we don't overlap:
amd-devhas the same padding in its keys:format_alias::prepare_placed_srv_descandprepare_placed_uav_descclear only 0x34.. as well, and your PR targetsmain'sresource_at. I'll take theamd-devside as its own small PR (the two prepares, with a test that fails without it), measured on Linux/AMD whereamd-devnow runs under Wine (#846).AI use: Claude Code (Claude Opus 5.5).
@joeypercia on GitHub · 2026-11-26 10:53 UTC · original
@GreemSC, the key fix is up as #2762:
main'sresource_atkey leaves out 0x04..0x08 too, and the activity line counts the textures kept (views without a resource: N textures kept). It has no eviction switch any more, so there's nothing to compare with and without. Before and after the key fix is the comparison that would show the 31 % under Wine. (Claude Code, Claude Opus 5.5)mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175@CryingLaughing on GitHub · 2026-11-26 12:19 UTC · original
I prepared a follow-up on top of #2762 at
ab169f5396bda3df5a48497e668f49a99192e892. The cache shares one pending placement per normalized key. Creation and waiting stay outside the map lock so other keys can proceed. It keeps the existing cached-failure and completed-entry behavior.The bounded CPU fixture passed with one shared result, an unrelated key completing while the first was held, and a cached zero reused. The existing native sequential fixture also passed on the RTX 4080, with two unique textures across the exact-repeat, padding and distinct-address controls. Both focused runs were 1 passed, 0 failed, 0 ignored, 0 skips.
RTX 4080 driver 621.01, i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 x64 MSVC and DXC 1.8.2502.11.
cargo build --workspace --locked -j 4andcargo test --workspace --locked -j 4 -- --test-threads=4 --show-outputpassed on the exact commit with 1,437 passed, 0 failed, 47 ignored, including 29 capability skips in the pass count.Concurrent native scheduling and the effect on retail memory remain unmeasured.