Skip to content

D3D12.X: title textures on shared 64 KiB pages of video memory – video memory stays at what the title covers (#248) - #269

Open
TG0000 wants to merge 1 commit into
ivall:mainfrom
TG0000:fix/title-textures-shared-pages
Open

TG0000 wants to merge 1 commit into
ivall:mainfrom
TG0000:fix/title-textures-shared-pages

Conversation

@TG0000

@TG0000 TG0000 commented Nov 23, 2026

Copy link
Copy Markdown

Fixes #248.

What changes

A texture the CPU fills (kept in step with title memory, title_textures) 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. Every such texture placed there shares those pages, which is what #248 suggests: the model render targets have used since 38b05b7. Before, each placement got its own committed PC texture that was never let go, so a streaming title's video memory held the sum of every texture it ever placed.

  • vram.rs: the page bookkeeping (pages, own tiles, idle/cool reuse) moves into a plain Book struct that tests can drive without D3D12. Pages come in two spaces, Space::Targets and Space::Textures. Kept-in-step textures share only with each other: their uploads are the CPU's view of the memory and would overwrite what the GPU rendered into a target at the same address. New place_title_texture. Render targets behave as before.
  • title_textures.rs: register is split into a layout check and register. Uploads run in placement order, oldest first, so on shared pages the newest texture's texels are what the memory holds, as on the console. The upload queue waits on the page-mapping fence before copying.
  • device_x.rs: CreatePlacedResourceX tries the pages first. A texture that cannot be reserved (unaligned address, 3D on tiled-resources tier 2, a driver refusal) is committed as before. XCL_TITLE_TEXTURE_PAGES=0 turns this off.

Tested

Windows 11, Ryzen 9 5900X, AMD Radeon RX 6800 (RDNA2, gfx1030), Rust stable x86_64-pc-windows-gnu (llvm-mingw linker).

  • cargo build --workspace --tests: no new warnings. The only warning is the existing fetch_update deprecation in xgameruntime/mod.rs, which XGameRuntime: try_update instead of the deprecated fetch_update #251 fixes.
  • New unit tests (no GPU):
    • textures_share_pages_with_textures_not_with_targets
    • streamed_textures_cost_the_memory_they_cover: 8000 placements, more than 30× a 256 MiB span, stay within the span.
    • released_pages_are_kept_then_cooled_before_reuse
  • New GPU test title_textures_at_one_address_share_video_memory, passes on the RX 6800:
    • Texels uploaded through one texture read back identically through another placed at the same address.
    • 256 RGBA8 512×512 placements at 8 addresses use 8 388 608 bytes of pages, exactly 8 textures, where they used to be 256 committed textures.
  • The existing vram / title_textures tests pass, including the D32S8 arena GPU test.
  • cargo test --workspace --exclude testgame-mw: 614 of 615 lib tests pass, and all other targets pass except e2e. The two failures don't touch this code and come from the GNU toolchain used here:
    • pe::tests::parses_own_test_binary_tls: a GNU-built test binary has no PE TLS directory.
    • e2e::test_title_runs_and_game_folder_is_untouched: testgame_mw.dll / xcl_testtitle.exe aren't built on this toolchain.
  • Not run here: a retail title (no game data used). A regression run on a streaming title, comparing the video-memory line from A memory line at every crash and while the title runs: process and system commit, video memory, what the title asked for #194 or XCL_ACTIVITY against main, would confirm the 0x887a0007 is gone.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…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>
@gw1337x

gw1337x commented Nov 23, 2026

Copy link
Copy Markdown

Retail regression run, as asked: GTA VI, RX 7800 XT 16 GB, 31.6 GB RAM, main 9ab7d76 + #244 (without it the title crashes at 67 s on the lazy-page race) + this PR at 8111cf9. Menus walked with XCL_PRESS_A_AT=14,17,21; every run was stopped by an external kill-switch (process commit over the limit, or the system's free RAM under 2.5 GB), because a run without one took the whole PC down.

No device removal and no crash with this PR – the 0x887a0007 from #248 did not come back. Video memory still grows past the card, though, through the textures that do not get pages:

main + #244 + #269 + a local variant (below)
stopped at 71 s (28 GB limit) 115 s (34 GB, free RAM 2.5 GB) 127–133 s (28 / 34 GB)
video memory (local) at 80 s – 13.5 GB 11.8–12.0 GB
process commit at 80 s – 30.0 GB 24.2–24.6 GB
video memory at 110 s – 15.1 GB 12.7 GB
kept-in-step bytes vs title memory they cover, 110 s – 15.0 GB vs 4.6 GB 5.9 GB vs 5.9 GB

Kept-in-step bytes and covered memory are from a local counter on the XCL_ACTIVITY line: the sum of the kept textures' console sizes, and the union of their address ranges.

The gap with #269 is the unaligned textures. In this title only about a quarter of the kept-in-step placements are 64 KiB-aligned (~10 000 of ~42 500 in the first ~110 s). The rest are packed at 4 KiB, stay committed, and the older ones under newer placements stay alive (11 releases in 90 s). The local variant adds two things on top of the aligned pages:

  • unaligned kept-in-step textures are reserved too, on tiles of their own (not shared);
  • a placement over an older kept texture's range (the same range included) unmaps the older one's tiles (D3D12_TILE_RANGE_FLAG_NULL, on the pages queue, then the fence) and gives them back: 41 213 textures superseded and 19.3 GB of tiles given back by 128 s.

That variant has costs and risks of its own: each unaligned texture takes at least one 64 KiB tile (9.7 GB of pages for 6.0 GB of textures), and a superseded texture reads zeros, which would show if the title still samples one. I have not checked the picture during world loading. Its remaining limit here is different: at ~126 s the title builds ~90 compute pipelines at once (+3.3 GB of video memory in 2 s), on top of its own growing memory.

Details and the earlier numbers are in #248. I can share the variant's diff (about 130 lines on top of an earlier version of the aligned part) if it is useful for this PR.

heretic1321 added a commit to heretic1321/xcl that referenced this pull request Nov 23, 2026
…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)
@TG0000

TG0000 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Huge thanks @gw1337x for running the retail regression test on the RX 7800 XT! Really glad to hear the 0x887a0007 device-removal crash is gone and the 64 KiB-aligned path held up cleanly.

The 4 KiB-aligned packing measurement (~3/4 of placements, 41,213 superseded textures / 19.3 GB of tiles reclaimed!) is a massive insight. Yes, please share your diff (or post it in #248) — we can either fold it cleanly into this PR (behind a guard/unit+GPU test) or land the aligned-pages foundation here first and follow up immediately with the unaligned + superseded-unmap layer, whichever is cleaner for @ivall to review!

@likecrank-dotcom

Copy link
Copy Markdown

Independent native Windows/MSVC + NVIDIA run on #269 at 8111cf945fb38f53a4856edfb63bcba46b524b29 (clean checkout).

Tested

  • Ryzen 5 3600, RTX 5060 Ti, NVIDIA 621.14 / 32.0.16.2114, 32 GB RAM; Windows 11 Pro 10.0.26300. Rust 1.100.0 x86_64-pc-windows-msvc, MSVC 19.44, Windows SDK 10.0.26100.0, DXC 1.9.2602.17; debug builds.
  • cargo build --workspace: exit 0 (only the existing fetch_update deprecation warning).
  • cargo test --workspace -- --test-threads=4 --nocapture: exit 0; 655 passed, 0 failed, 40 ignored, across 17 result blocks. Library: 615 passed, 0 failed, 20 ignored.
  • The GPU test title_textures_at_one_address_share_video_memory passed on the hardware adapter, without skipping: uploading through one placed texture and reading back through the other produced 0 differing rows. Its 256 RGBA8 512x512 placements at 8 addresses used 8,388,608 tracked tile-page bytes. The DXGI local-memory delta printed by this run was 0 bytes; I do not interpret that instantaneous value as total VRAM usage.
  • textures_share_pages_with_textures_not_with_targets, streamed_textures_cost_the_memory_they_cover (8,000 placements), and released_pages_are_kept_then_cooled_before_reuse passed.
  • Unlike the GNU environment in the description, both pe::tests::parses_own_test_binary_tls and test_title_runs_and_game_folder_is_untouched passed on this MSVC host.

SKIPPED / Not tested
Four explicit skips: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64); test_title_draws_with_a_root_signature_under_the_debug_layer (no d3d12SDKLayers.dll); uploads_start_from_each_subresources_state (no D3D12 debug layer, 0x887A002D). No XCL_SAMPLE variables were set; sample tests returning early are not retail coverage. No retail title/smoke run, no AMD/Wine run, and no conclusion about unaligned streaming placements or the title's remaining memory growth.

AI use
Codex ran the builds/tests and summarized their actual logs. Exact deployed model identifier is not exposed in this session. No production-code changes or game data published.

@emirduran707

Copy link
Copy Markdown

Retail run on RDNA4, for comparison with the RX 7800 XT numbers above: the same title as #248, main 9ab7d76 + #244 (77905f6), with and without this PR (8111cf9). Merged locally, release builds.

Hardware: AMD Radeon RX 9060 XT 16 GB (driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, rustc 1.100.0 MSVC, DXC 1.9.2602.17.

Run: xcl run <folder> with XCL_NETWORK=0, XCL_ACTIVITY=1, XCL_FRAME_DUMP=60, XCL_RUN_SECONDS=300; menus walked by hand with a controller (so the timings differ by a few seconds between runs). A kill-switch stopped each run when the xcl processes' private bytes went over 28 GB.

Process commit / local video memory from the XCL_ACTIVITY memory line:

time main + #244 main + #244 + #269
62 s 16.2 GB / 6.9 GB 16.0 GB / 6.8 GB
72 s 18.9 GB / 8.3 GB 17.7 GB / 7.4 GB
82 s 22.8 GB / 10.5 GB 21.6 GB / 8.9 GB
92 s 28.0 GB / 13.6 GB 24.1 GB / 10.2 GB
102 s – 27.8 GB / 12.6 GB
stopped at 28 GB 99 s 112 s

Not tested: whether #244 gets past that fault (this 32 GB machine cannot reach it safely); #288 and #292; the picture during the load (the loading screen's band is drawn black).

Test runs and this comment: Claude Code (Claude Opus 5.5), from my runs.

josilo added a commit to josilo/xcl that referenced this pull request Nov 23, 2026
Apply upstream XCL PRs ivall#269 (8111cf9) and ivall#267 (b5c9057). Keep compute waits unchanged and preserve the streamed texture and render-target page separation.
josilo added a commit to josilo/xcl that referenced this pull request Nov 23, 2026
Apply XCL PRs ivall#283 (065be41 and 2a64505) and ivall#289 (d0b6079). Preserve placement-order uploads from ivall#269 while sourcing mirrored textures from the CPU view.
@mariuslozo-boop

Copy link
Copy Markdown

NVIDIA result: this PR removes the out-of-memory failures here, but video memory keeps growing past the card's size. The title's own watchdog then ends the run.

Setup: RTX 5070 Ti (16 GB), driver 616.92, Ryzen 7 7700X, 32 GB RAM, Windows 11 Pro 26300. Release build of main 0e946cf + #244 (77905f6) + this PR (8111cf9), merged locally without conflicts. Retail title 1.0.2.1. XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_RUN_SECONDS=300 xcl.exe run <game folder>, no input. One run.

main 9ab7d76 + #244 (earlier run) + this PR
CreatePlacedResourceX … (0x8007000e) 860 lines from 180.6 s 0
end title breakpoint at 182.5 s (0x80000003, +0xf7d415) title watchdog at 255.1 s (+0x23cf683, write to 0)

The memory: lines with this PR:

time committed by the process video memory, local target pages
6 s 7.6 GB 0.8 GB 0.1 GB
86 s 16.7 GB 7.5 GB 3.5 GB
166 s 35.9 GB 16.6 GB 7.5 GB
246 s 47.0 GB 21.2 GB 8.5 GB

Not tested: #288 / #292; AMD; more than one run. I could not combine this PR with #283: they conflict in title_textures.rs.

AI-assisted: Claude Code (Claude Opus 5.5 ran the build and the run and wrote this report; Claude Fable 5.2 decoded the abort). No game files attached.

@grahamster2

Copy link
Copy Markdown
Contributor

Retail run of 8111cf9 on a 10 GB NVIDIA card: GTA VI (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 7.4 → 14.8 GiB 14.8 GiB none AV write +0x61bbd6, 120 s
2 7.4 → 15.0 GiB 17.4 GiB none timer, 180 s, exit 0
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

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: 8111cf945fb38f53a4856edfb63bcba46b524b29
gpu: NVIDIA GeForce RTX 3080
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1463 (PresentX 1463)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14812 MB

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

forbesfields pushed a commit to forbesfields/xcl that referenced this pull request Nov 23, 2026
Handle 16-byte constant-buffer records, upload intro textures from their CPU view, and decode BC1 BCPack streams. Share bounded texture pages, batch upload staging, and tolerate pages decommitted during streaming reads.

Includes work from ivall/xcl ivall#208, ivall#244, ivall#252, ivall#254, ivall#269 and ivall#283. DirectStorage late destination pages are already in the base.

Assisted-by: OpenAI Codex (gpt-6.2-sol)
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.

Title textures: a PC copy per placement, never shared or let go – video memory grows past the card while a retail game streams its world (0x887a0007)

6 participants