Skip to content

D3D12.X: retire overwritten title textures, evict MADE, and clean up (#248) - #292

Draft
heretic1321 wants to merge 2 commits into
ivall:mainfrom
heretic1321:fix/title-texture-lifetime-248
Draft

heretic1321 wants to merge 2 commits into
ivall:mainfrom
heretic1321:fix/title-texture-lifetime-248

Conversation

@heretic1321

@heretic1321 heretic1321 commented Nov 23, 2026 •

Copy link
Copy Markdown

Stacked on #269 — review and merge #269 first (this branch is rebased onto #269 head 8111cf9). Part of #248.

Overlaps

Dropped (taken from #269, which has RX 6800 GPU evidence):

Kept (unique on top of #269; 4 files, +274 / -33):

What the reporter should measure (on top of #269)

Run the streaming repro on Windows + RX 7800 XT (16 GB) for 5 minutes with XCL_ACTIVITY=1, XCL_PRESS_A_AT=14,17,21, XCL_NETWORK=0, comparing #269 (8111cf9) vs this stacked commit (bf8e16c):

  1. Check title textures <active> (<covered> MB covered, <retired> retired, <released> released) and video memory ... MB local at 30 s, 60 s, 90 s, 120 s, 180 s, 240 s, 300 s — verify active count stays bounded near the covered memory (instead of growing to 15.0 GB vs 4.6 GB covered as measured on D3D12.X: title textures on shared 64 KiB pages of video memory – video memory stays at what the title covers (#248) #269) and confirm whether MADE eviction frees superseded unaligned by-address views.
  2. Run cargo test --workspace -- --test-threads=4 (including D3D12.X: title textures on shared 64 KiB pages of video memory – video memory stays at what the title covers (#248) #269's 4 tests plus our 2 new unit tests) and scripts/smoke.ps1 on main / D3D12.X: title textures on shared 64 KiB pages of video memory – video memory stays at what the title covers (#248) #269 and on bf8e16c.

Tested

  • Linux host cross-check only (no Windows runtime or GPU):
    • AR_x86_64_pc_windows_msvc=llvm-ar cargo check --release --workspace --target x86_64-pc-windows-msvc — exit 0
    • AR_x86_64_pc_windows_msvc=llvm-ar cargo check --release --workspace --tests --target x86_64-pc-windows-msvc — exit 0

Not tested

AI use

TG0000 and others added 2 commits November 23, 2026 23:12
…memory (ivall#248)

A texture the CPU fills (kept in step with title memory) placed at a 64 KiB
aligned address is now a reserved resource on 64 KiB pages of video memory,
one per page of the title's address, shared by every such texture placed
there - as on the console, where a texture placed over another overwrites its
memory. A committed PC texture per placement, never let go, held the sum of
every texture a streaming title ever placed (12.7 GB over 4.0 GB of its
memory at 90 s, then 0x887a0007).

- vram: page bookkeeping in a plain Book (unit-tested); textures and GPU-owned
  targets in separate spaces, so a texture's CPU-view upload never overwrites
  what the GPU rendered into a target at the same address.
- title_textures: uploads oldest placement first (the newest texture's texels
  win on shared pages); the upload queue waits for tile mappings.
- device_x: pages first, committed as before when a texture cannot be reserved
  (unaligned address, 3D on tier 2, driver refusal). XCL_TITLE_TEXTURE_PAGES=0
  turns it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…vall#248)

Stacked on ivall#269 (which moves 64 KiB-aligned kept-in-step title textures
onto shared 64 KiB pages in vram::Book).

What remains after ivall#269:
- Overwritten placements stayed registered in title_textures forever,
  continuing to be scanned/uploaded and holding extra tiles / leftover
  pages in vram::Book even when a newer texture replaced their memory.
- real::resource_at (device ivall#70/ivall#71 by-address SRV/UAV creation) stored
  every created ID3D12Resource in MADE forever and never released
  superseded entries (including unaligned committed textures).
- Device / queue release did not clear MADE, title_textures state,
  upload queues, or vram::Pages::waited.
- XCL_ACTIVITY memory lines lacked title-texture active/covered/retired/
  released counters.

This commit adds O(log N + k) overlap retirement in title_textures,
detaches retired entries from vram::Book, cools and releases superseded
entries in real::resource_at (2 s cooling + MADE_MAX cap), cleans up on
device/queue release, and logs title-texture counters on XCL_ACTIVITY.

Assisted-by: Antigravity CLI (Gemini 4 Neon)
@heretic1321
heretic1321 force-pushed the fix/title-texture-lifetime-248 branch from 86a9207 to bf8e16c Compare November 23, 2026 22:35
@heretic1321 heretic1321 changed the title D3D12.X: give title textures shared pages, reuse, and retirement (#248) D3D12.X: retire overwritten title textures, evict MADE, and clean up (#248) Nov 23, 2026
@grahamster2

grahamster2 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Retail run of bf8e16c on a 10 GB NVIDIA card: the retail title (Series 1.0.2.1), RTX 3080, driver 610.88, warm caches, XCL_PRESS_A_AT=30,40,50,60,70,80,95,110, 180 s, two runs. All four heads are compared in #248 (comment).

run local VRAM 60 s → 120 s max VRAM first 0x8007000e end
1 6.9 → 11.4 GiB 12.3 GiB none AV write +0x2926872, 145 s
2 7.4 → (ended at 95 s, 9.3 GiB) 9.3 GiB none AV write +0x13936, 95 s
main (two runs) 7.5 → 17.6 / 17.9 GiB 19.8 GiB 127 s / 128 s AV +0x13936 128 s / 0x80000003 +0x193e00f 138 s

The access violation at +0x13936 is also one of main's endings, and this run ended at 9.3 GiB, well under the card. The title textures counter at the end: 19 330 active, 4 829 MB covered, 31 003 retired (run 1); 16 349 / 1 963 MB / 14 997 (run 2).

No device removal, and no new warning kinds compared with main. Correctness wasn't checked: the loading frames are a dark fade, and I can't look at them.

xcl-smoke, 60 s
xcl-smoke v1
commit: bf8e16cdc2faf0cf5a5994c381890a0c5170376e
gpu: NVIDIA GeForce RTX 3080
title: the retail title.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1482 (PresentX 1482)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14770 MB

Claude Code (Claude Opus 5.5) ran the tests and wrote this report. No game files attached.

@emirduran707

Copy link
Copy Markdown

A data point for the retirement part of this PR, on current main (where #288 is in and #269 is closed, so this branch conflicts now).

RX 9060 XT 16 GB, 32 GB RAM, release, main a6f5f7a + #440 (video at speed) + #300 + #435, the same title, A pressed by hand, XCL_ACTIVITY=1. While the world streams in (from ~60 s), the tiled-texture pages (the target pages figure on the activity line, which since #288 counts targets and sampled textures on one shared book) keep growing, with no E_OUTOFMEMORY:

time process commit local VRAM tiled-texture pages
62 s 17.3 GB 7.9 GB 4.9 GB
82 s 23.4 GB 11.8 GB 7.9 GB
122 s 26.4 GB 13.3 GB 9.4 GB
142 s 27.8 GB 13.9 GB 9.8 GB

Pages are shared per address on main, so this is distinct addresses covered by resources the title has not released, which is what the retirement here addresses. Are you planning to rebase it onto main? I can run the same measurement on this card when it is.

AI use: Claude Code with Claude Opus 5.5 read the run's log and wrote this comment from my run.

@Cattn

Cattn commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

From a static review (no builds or runs) of bf8e16c:

resource_at returns a borrowed COM pointer, which the caller uses to create a descriptor after the cache lock is released. Another caller can retire the entry and drain the cache's reference after the two-second cooldown, leaving descriptor creation or submitted GPU work without a live resource if that was the final reference. This is a resource-lifetime bug, and I found no indication of malicious code.

Hold a COM reference through descriptor creation and defer GPU retirement until the relevant queue fences complete.

unsafe fn resource_at(this: *mut c_void, desc: *const u8, va: u64) -> *mut c_void {
if desc.is_null() || va == 0 || !crate::gpu::shader::readable(desc as usize, 0x38) {
return std::ptr::null_mut();
}
let expired = MADE.lock().unwrap().get_or_insert_with(ResourceAtCache::default).drain_expired(std::time::Instant::now());
for r in expired {
drop(windows::core::IUnknown::from_raw(r as *mut c_void));
}
// the PC part of the desc; the flags (@0x30) are its last dword, padding follows
let mut x: [u8; 0x38] = (desc as *const [u8; 0x38]).read_unaligned();
x[0x34..].fill(0);
let key = (this as usize, va, x);
if let Some(&r) = MADE.lock().unwrap().get_or_insert_with(ResourceAtCache::default).made.get(&key) {
return r as *mut c_void;

const MADE_COOL: std::time::Duration = std::time::Duration::from_secs(2);
const MADE_MAX: usize = 65536;
static MADE: Mutex<Option<ResourceAtCache>> = Mutex::new(None);
impl ResourceAtCache {
fn retire(&mut self, res: usize, now: std::time::Instant) -> bool {
let Some(k) = self.by_res.remove(&res) else { return false };
self.made.remove(&k);
self.cooling.push_back((k.0, res, now));
true
}
fn drain_expired(&mut self, now: std::time::Instant) -> Vec<usize> {
let mut out = Vec::new();
while self.cooling.front().is_some_and(|&(_, _, at)| now.duration_since(at) >= MADE_COOL) {
out.push(self.cooling.pop_front().unwrap().1);
}
out
}

Review by Claude Code (Claude Opus 5.5) with a gpt-6.2-sol audit subagent; I checked each point against the code.

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.

5 participants