Skip to content

D3D12.X: recycle released reserved sampled textures by description and state - #2436

Open
saintwolf wants to merge 1 commit into
xcl-dev:mainfrom
saintwolf:vram/recycle-reserved-textures
Open

saintwolf wants to merge 1 commit into
xcl-dev:mainfrom
saintwolf:vram/recycle-reserved-textures

Conversation

@saintwolf

@saintwolf saintwolf commented Nov 25, 2026 •

Copy link
Copy Markdown

Recycles released reserved sampled textures in a bounded per-device pool keyed by exact (D3D12_RESOURCE_DESC, uniform D3D12_RESOURCE_STATES) so streamed texture placements skip CreateReservedResource and GetResourceTiling. Fixes #1268. Part of #1833.

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: forget(res) returns the removed texture's last tracked uniform D3D12_RESOURCE_STATES when all subresources share a single state (states.len() == 1), or None for mixed-state / untracked textures.
  • crates/xcl/src/hle/d3d12x/real.rs: on final Release (n == 0) while late_release holds the last PC ref, parks eligible place_pages sampled textures with their actual uniform D3D12 state; exposes note_reserved so reused pointers re-register in RESERVED.
  • crates/xcl/src/hle/d3d12x/late_release.rs: once every live GPU queue is past a batch's fence, hands parked textures to vram::recycle_ready instead of destroying them.
  • crates/xcl/src/hle/d3d12x/vram.rs: adds ReservedKey and a bounded per-device ReservedPool (512 idle entries/device, FIFO eviction dropped outside PAGES.lock(), opt-out via XCL_RESERVED_POOL=0). recycle_ready unmaps any still-mapped tiles (pages.unmap) on the background late_release thread so retired 64 MiB VRAM pool heaps never leave stale page-table references. place_on_pages pops matching pooled reserved textures via QueryInterface and reuses their cached tile count, skipping CreateReservedResource and GetResourceTiling. Adds unit tests (reuse hit, state isolation, FIFO eviction, cap=0) and a GPU recycle/rebind test.

Tested

  • Windows 11 (build 26300), NVIDIA GeForce RTX 4070 SUPER (driver 32.0.16.2140), AMD Ryzen 7 7800X3D, rustc 1.100.0 (0ef1bc386 2026-11-09), DXC/DXIL 1.8.2502.11.
  • cargo test -p xcl --lib hle::d3d12x::vram::tests -- --test-threads=1 on rebased head bebf2dd: 21 passed, 0 failed, 1 ignored (including #2306's the_tiles_of_a_texture_are_grouped_by_its_levels, reserved_pool_reuses_matching_key_isolates_state_and_evicts_fifo, and reserved_resource_recycle_unmaps_reuses_and_remaps_on_gpu).
  • .\scripts\test.ps1 (cargo test --workspace -- --test-threads=4, debug): 1277 passed, 0 failed, 46 ignored across 23 test binaries before rebase (and 1280 passed after rebase onto 3f27770, with 1 unrelated pre-existing gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier failure).
  • SKIPPED GPU tests on this adapter (27 total): 21 no wave64, 3 per-lane form #1426 refusals (V_CVT_F16_F32, V_MUL_F16, V_PK_MUL_F16), 1 cannot disable the driver cache (Windows Developer Mode is required) (0x887A002D), 1 no xgameruntime.dll, 1 no heap windows.
  • Isolated #1268 microbenchmark on RTX 4070 SUPER (release, 2,000 iterations each):
    • 256x256 BC1 (9 mips): CreateReservedResource + GetResourceTiling + Release 222.33 ms (111.17 µs/tex) → recycled pool 0.04 ms (0.019 µs/tex) (5,730× faster).
    • 1024x1024 BC7 (11 mips): 279.58 ms (139.79 µs/tex) → recycled pool 0.04 ms (0.019 µs/tex) (7,262× faster).
  • Paired retail world-load A/B run (XCL_DIRECT_DXIL=1, XCL_PSO_WAIT_MS=50, XCL_PRESS_A_AT=15,20,25,30,35,40,45, isolated caches): XCL_RESERVED_POOL=1 cleanly recycled 32+ streamed reserved textures live before both arms hit the same pre-existing xboxbvhbuilder.dll 40-bit VA exception (~112–116 s), with 0 device removals and -352 MB lower peak commit (28,903 MB vs 29,255 MB).

Regression run

xcl-smoke v1
commit: 3f4495a2b325ae5a9df314dd86d10327502b5cf5
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 971 (PresentX 971)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14961 MB
xcl-smoke v1
commit: bebf2dd4b57605839f6578a5baeab225617b9b1f
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 972 (PresentX 973)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14960 MB

Not tested

AI use

  • Antigravity (Gemini 4 Neon) for issue diagnosis, implementation, tests, benchmarking, and PR drafting; all builds, tests, benchmarks, and retail runs were executed locally on the hardware above.

…d state

Streamed sampled textures placed on shared 64 KiB video-memory pages previously called CreateReservedResource and GetResourceTiling on every placement, costing 0.6-1.7 ms per texture on AMD drivers (xcl-dev#1268) and ~111-140 us on NVIDIA.

Keep a bounded per-device pool (512 idle entries, FIFO eviction, opt-out via XCL_RESERVED_POOL=0) of released reserved sampled textures keyed by exact (D3D12_RESOURCE_DESC, uniform D3D12_RESOURCE_STATES). When late_release finishes draining all live GPU queues past a texture's batch, vram::recycle_ready unmaps any still-mapped tiles on the background thread and parks the ID3D12Resource for reuse; matching place_pages calls QueryInterface on the pooled object and reuse its cached tile count, skipping CreateReservedResource and GetResourceTiling.

Fixes xcl-dev#1268. Part of xcl-dev#1833.

Assisted-by: Antigravity (Gemini 4 Neon)

# Conflicts:
#	crates/xcl/src/hle/d3d12x/vram.rs
@saintwolf
saintwolf force-pushed the vram/recycle-reserved-textures branch from e2cf935 to bebf2dd Compare November 25, 2026 18:53
@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head e2cf9357ba193507dfbc19d4e3b040b63ee957e7 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1275 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • Both PR tests passed (no skips): hle::d3d12x::vram::tests::reserved_pool_reuses_matching_key_isolates_state_and_evicts_fifo and reserved_resource_recycle_unmaps_reuses_and_remaps_on_gpu.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: e2cf9357ba193507dfbc19d4e3b040b63ee957e7
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1598 (PresentX 1598)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13927 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

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.

D3D12.X: CreateReservedResource for each streamed title texture costs ~1 ms on AMD and stalls the title's render thread during world loading

2 participants