Skip to content

D3D12.X: back kept-in-step title textures by shared VRAM pages (#248) - #288

Merged
ivall merged 1 commit into
ivall:mainfrom
iliassgm:title-textures-vram-pages
Nov 23, 2026
Merged

ivall merged 1 commit into
ivall:mainfrom
iliassgm:title-textures-vram-pages

Conversation

@iliassgm

@iliassgm iliassgm commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #248

What is in it

  • vram.rs: add vram::place_pages so non-GPU-owned textures placed via CreatePlacedResourceX use reserved (D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE) resources backed by the existing shared 64 KiB vram::Pages pool (falling back to committed resources when reserved creation is unsupported, e.g. 1D textures or XCL_VRAM_ARENAS).
  • vram.rs: map every 64 KiB page boundary P strictly inside [va, va + console_bytes) (owned_pages, proven non-aliasing for disjoint ranges even at 4 KiB alignment) onto shared pages, share remaining/sub-64 KiB tiles in extra_pages keyed by (va, tile_index) so repeated placements at the same address never leak, wrap pool CreateHeap in title_textures::own_work, and key PAGES per device with queue.GetDevice in before_execute.
  • vram.rs (unmap_superseded / remap_if_unmapped): when a placed texture is superseded by a placement with a different range ((ova, oend) != (va, end)) or a GPU-owned render target, unmap its tiles (D3D12_TILE_RANGE_FLAG_NULL) and return any unshared extra_pages / tail pages straight to cooling so 4 KiB-packed < 64 KiB streaming churn stays bounded without requiring Release. Exact same-range aliases remain mapped and share every tile. If the newer overlapping placement is later released, remap_if_unmapped re-binds the uncovered texture cleanly.
  • title_textures.rs & device_x.rs: wait for pending UpdateTileMappings via vram::before_execute(&queue) before texture::upload_batch (and probe_gpu_content). Keep active (non-shadowed) entries in an O(log N) address-ordered index so refresh_once skips shadowed placements while still tracking transitions/states on shadowed entries and promoting uncovered older textures back to active on forget (fixing row 6 from @Kalmarv's comparison while keeping fast uploads and rows 1–5).
  • Tests: unit tests for owned_pages disjointness, shadowing/unmapping, and multi-layer reactivation (vram.rs, title_textures.rs), plus a hardware D3D12 GPU test covering 512 unreleased 1 MiB textures over a 16 MiB window (+16 MiB pages, +0 B after fill), exact same-range aliasing + release reactivation (rows 4 & 6), partial-overlap isolation + unmap/remap on release (row 5 & 6b), immediate extra_pages reclamation for superseded 4 KiB-packed < 64 KiB textures, and bit-exact GPU readback across RGBA8/BC7 mip chains (including packed mips), a 6-slice cubemap, and a 3D volume.

Tested

  • Hardware: NVIDIA GeForce RTX 3060 12 GB (driver 32.0.16.2124), Intel Core i5-10400F, Windows 11; rustc 1.100.0 (0ef1bc386 2026-11-09), debug + release (cargo build --release -p xcl clean).
  • cargo test --workspace -- --test-threads=4: 654 passed, 0 failed, 40 ignored (SKIPPED GPU tests: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware — RTX 3060 is wave32; uploads_start_from_each_subresources_state skips locally because Windows Graphics Tools / D3D12 debug layer is not installed).
  • RTX 3060 measurement (placed_title_textures_share_vram_and_preserve_pixels): 512 unreleased 1 MiB textures over 16 MiB stay at +16 MiB pages (+0 B after fill), +0 B local VRAM growth after fill (solo run), +16 active kept; rows 4/5/6 + different-range unmap/remap + 4 KiB < 64 KiB extra_pages reclamation all pass bit-exact; negative control with XCL_VRAM_ARENAS=1 fails as expected.

Regression run
Draft PR awaiting a scripts/smoke.ps1 run on a retail title (I do not have a retail game folder on this machine). If @gw1337x or another retail tester can run scripts/smoke.ps1 on main and this head commit (ad799324d6e6) with XCL_ACTIVITY=1, I will paste both blocks here and mark ready for review.

main:
pending (no retail title locally)

PR:
pending (no retail title locally)

Not tested

  • Retail Xbox titles / scripts/smoke.ps1 (no retail game files locally).
  • AMD GPUs (tested on NVIDIA RTX 3060 only).
  • D3D12 debug layer validation (Windows Graphics Tools optional feature is not installed on this PC).

AI use

  • Antigravity (Google DeepMind) assisted with code design, implementation, and unit/GPU test authoring; all changes were reviewed, compiled (debug and release), and verified locally on NVIDIA RTX 3060 + Intel Core i5-10400F hardware.

@gw1337x

gw1337x commented Nov 23, 2026

Copy link
Copy Markdown

@iliassgm tested on the retail streaming repro, as asked. AMD Radeon RX 7800 XT 16 GB (driver 32.0.32015.7029), 31.6 GB RAM, Windows 11, release builds.

Regression run (scripts/smoke.ps1 -Seconds 60, no input – the title stays in its first menus, so this does not reach the streaming):

xcl-smoke v1
commit: 0e946cfc68244edee1fba6e0425371f687a05ccd
gpu: AMD Radeon RX 7800 XT
title: GTA6.Xbox
seconds: 60
exit: 0x0
frames shown: 1553 (PresentX 1553)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15025 MB
xcl-smoke v1
commit: 876557cfce22f5231a4f63449463b1ed6e7ac2dc
gpu: AMD Radeon RX 7800 XT
title: GTA6.Xbox
seconds: 60
exit: 0x0
frames shown: 1572 (PresentX 1572)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14883 MB

Streaming run – this PR's head + #244 (without #244 the title crashes at 67 s on the lazy-page race), menus walked with XCL_PRESS_A_AT=14,17,21, XCL_ACTIVITY=1. An external kill-switch stops a run when the process commit passes 34 GB or the system's free RAM drops under 2.5 GB (an unguarded run once took the whole PC down).

time process commit video memory (local) target pages
38 s 16.7 GB 7.4 GB 4.6 GB
58 s 20.8 GB 9.2 GB 5.6 GB
78 s 24.6 GB 12.0 GB 8.4 GB
98 s 26.1 GB 13.0 GB 9.4 GB
118 s 28.8 GB 14.2 GB 10.6 GB

No device removal, no crash. Stopped by the kill-switch at 129 s (33.7 GB commit, free RAM at 2.5 GB).

The same setup with other builds, for comparison:

build stopped at video memory ~70 s ~110–118 s
main 9ab7d76 + #244 71 s (28 GB limit) 11.2 GB, rising ~0.3 GB/s –
#269 + #244 115 s (34 GB / free RAM) 11.6 GB 15.1 GB
#288 + #244 129 s (free RAM) 11.4 GB 14.2 GB

So the 0x887a0007 from #248 is gone with this PR and after ~80 s video memory grows ~0.06 GB/s (main: ~0.3 GB/s until it was stopped). It still grows during world loading (pages 4.6 → 10.6 GB from 38 to 118 s), and what ends the run on this 32 GB machine is total commit rather than video memory.

Not tested: a run without the kill-switch; the picture during world loading (it is a dark loading fade there); NVIDIA.

AI-assisted (Claude Code, Claude Opus 5.5).

@iliassgm
iliassgm force-pushed the title-textures-vram-pages branch from 876557c to ad79932 Compare November 23, 2026 23:02
@grahamster2

grahamster2 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Retail run of 876557c 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 7.1 → 11.9 GiB 12.6 GiB none AV write +0x35a47bc, 141 s
2 7.1 → 11.5 GiB 14.1 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: 876557cfce22f5231a4f63449463b1ed6e7ac2dc
gpu: NVIDIA GeForce RTX 3080
title: the retail title.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1517 (PresentX 1518)
presents per 2 s (last 3): 61 59 60
device removals: 0
crashes: 0
peak commit: 14667 MB

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

@iliassgm

Copy link
Copy Markdown
Contributor Author

Huge thanks @gw1337x and @grahamster2 for running both retail streaming tests (RX 7800 XT and RTX 3080 10 GB) — seeing VRAM drop from 19.8 GiB / OOM on main down to 11.5–11.9 GiB at 120 s (and commit down ~10 GiB vs main / #269) with zero 0x8007000e / device removals is awesome!

Note that I pushed an updated head commit ad799324d6e6 right as your runs were posted (adding shadowed-entry reactivation for @Kalmarv's row 6 plus D3D12_TILE_RANGE_FLAG_NULL unmapping of superseded different-range extra_pages / tail pages, which should pull the streaming VRAM curve down even further). If either of you gets a chance to rerun scripts/smoke.ps1 on ad799324d6e6, I'll paste the fresh xcl-smoke blocks into the PR description and mark this ready for review!

@grahamster2

grahamster2 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

scripts/smoke.ps1 reruns for ad79932, with the unmodified script at each commit. Setup: the retail title (Series 1.0.2.1), RTX 3080 10 GB, driver 610.88, warm caches, release builds, 60 s, no input.

The gpu: line names this machine's iGPU because the script takes the first adapter Windows lists (fixed in #281). XCL itself ran on the RTX 3080 in both runs (D3D12.X: backend 'real' – NVIDIA GeForce RTX 3080 in the log).

main 4017f8f:

xcl-smoke v1
commit: 4017f8ff8faaae6007fd83910d230a027dd85a33
gpu: AMD Radeon(TM) Graphics
title: the retail title.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1454 (PresentX 1454)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14819 MB

this PR, ad79932:

xcl-smoke v1
commit: ad799324d6e690e0707f25bc9bf746edc287f99c
gpu: AMD Radeon(TM) Graphics
title: the retail title.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1513 (PresentX 1514)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14602 MB

Streaming numbers for ad79932, from one run, guarded and short: local merge of 4017f8f + #244 + this PR (it merges cleanly), XCL_PRESS_A_AT=14,17,21, world streaming from ~48 s. The run was stopped by my RAM watchdog at 73 s (free RAM under 3 GB), not by the title. Process commit / local VRAM:

s main 4017f8f 4017f8f + #244 4017f8f + #244 + ad79932
50 17.0 / 7.7 GB 17.0 / 7.7 GB 16.6 / 7.3 GB
60 17.1 / 7.7 GB 19.3 / 8.9 GB 19.5 / 8.1 GB
70 22.2 / 10.3 GB 23.6 / 10.8 GB 21.8 / 8.8 GB

No crash, device removal or 0x8007000e in any of the three before the stop. The earlier 180 s runs of 876557c are in #248 (comment).

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

@gw1337x

gw1337x commented Nov 23, 2026

Copy link
Copy Markdown

@iliassgm rerun on ad79932, as asked. Same machine and setup as before (RX 7800 XT 16 GB, driver 32.0.32015.7029, 31.6 GB RAM, Windows 11, release build).

Regression run (scripts/smoke.ps1 -Seconds 60, no input, first menus only):

xcl-smoke v1
commit: ad799324d6e690e0707f25bc9bf746edc287f99c
gpu: AMD Radeon RX 7800 XT
title: GTA6.Xbox
seconds: 60
exit: 0x0
frames shown: 1570 (PresentX 1570)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14897 MB

(main's block for comparison is in my earlier comment: 0e946cf, 1553 frames, peak 15025 MB.)

Streaming run, this head + #244, XCL_PRESS_A_AT=14,17,21, XCL_ACTIVITY=1, one run each. The kill-switch now stops a run when free RAM drops under 2.5 GB, video memory passes 15.5 GB or commit passes 40 GB. "Other" is process commit minus local and non-local video memory, from the same activity line.

time 876557c: commit / video / other ad79932: commit / video / other
58 s 20.3 / 9.0 / 6.9 GB 21.7 / 8.7 / 8.6 GB
78 s 24.0 / 11.7 / 7.8 GB 27.2 / 11.3 / 11.5 GB
98 s 25.5 / 12.7 / 8.5 GB 30.8 / 11.8 / 14.6 GB
stopped at 129 s (free RAM) 107 s (free RAM 2.2 GB; commit 32.6 GB, video 12.0 GB)

No device removal, no crash, no 0x8007000e in either. Video memory is a little lower with the new head (11.8 vs 12.7 GB at 98 s), but the commit that is not video memory grows faster: +6 GB at 98 s. That is one run each, and the game's loading may not progress identically between runs, so it may be noise – but it is the first thing I would look at if someone can reproduce it (whatever the shadowed-entry reactivation or the tail-page unmapping keep on the CPU side).

Not tested: more than one run per head; the picture during world loading; NVIDIA.

AI-assisted (Claude Code, Claude Opus 5.5).

@gw1337x

gw1337x commented Nov 23, 2026

Copy link
Copy Markdown

A small one I hit while testing, in case it helps: on this PR (876557c and ad79932), cargo test --release -p xcl --lib -- title_textures gpu_sparse_vram_descriptors_buffers_and_xmem fails in gpu_sparse_vram_descriptors_buffers_and_xmem (submit 1 lane 0 mismatch, left 0, right 1077); the same filter passes on main 4017f8f, and the full lib suite passes on this PR (614 passed, default threads and --test-threads=4). So it looks like an order dependence between the new title-texture GPU tests and that test when they run close together. RX 7800 XT, release build. I have not looked into why.

@ivall
ivall merged commit aeaeecb into ivall:main Nov 23, 2026
0 of 2 checks passed
ivall added a commit that referenced this pull request Nov 23, 2026
…r GPU tests allocate at the same time)

placed_title_textures_share_vram_and_preserve_pixels (PR #288) asserted the process's local
video memory grew under 384 MB; under --test-threads=4 on an RX 9070 other GPU tests in the
process made it +672 MB, alone it passes. The page count, which the change controls, stays
asserted exactly.
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Merged (2b4bb43), from the draft - of the three #248 PRs it kept video memory lowest in grahamster2's NVIDIA runs. Checked on an RX 9070 (RDNA4) on main 2b4bb43 together with #306, #288 and #294: cargo build --workspace && cargo test --workspace -- --test-threads=4 - 630 unit tests passed, 0 failed; the retail game reaches its menus and starts loading the world (stopped at ~150 s by the machine's commit limit, not by the game). Two things done in the merge: #283 (merged before) gave each kept-in-step texture a src (the CPU view behind a GPU view) and in_gpu_view; the entry now has both #283's and this PR's fields, uploads and the write-watch still read src, and recheck_gpu_view_sources walks by_res and shadowed. And placed_title_textures_share_vram_and_preserve_pixels no longer asserts the process's local video memory: under --test-threads=4 other GPU tests in the process made it +672 MB on this machine (alone it passes); the page count stays asserted exactly.

ivall added a commit that referenced this pull request Nov 23, 2026
… is committed, not a failure

placed_title_textures_share_vram_and_preserve_pixels (PR #288) asserted every shape went to
shared video-memory pages. GitHub's runner adapter refuses the 256x256x6 cube with 9 mips as a
reserved resource (arrays with packed mips are a lower tiled tier's limit); the texture is
then committed, which is correct - the test failed and its panic poisoned the lock two other
tests share. Arrays and cubes now note the fallback; their pixels are checked either way.
ivall added a commit that referenced this pull request Nov 24, 2026
…e with mips

GitHub's runner adapter reports tiled resources tier 2 but refuses a reserved 256x256x6
cube with 9 mips, and further steps of placed_title_textures_share_vram_and_preserve_pixels
(PR #288) then expected shared pages it never got. The test now probes that one resource
and is SKIPPED, like the other GPU tests the runner cannot run; on a GPU it runs whole.
ryosen0 added a commit to ryosen0/xcl that referenced this pull request Nov 24, 2026
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)

4 participants