Skip to content

D3D12.X: zero recycled vram::Pages tiles before reuse - #7

Draft
itsSio wants to merge 1 commit into
mainfrom
d3d12x/zero-recycled-vram-tiles
Draft

itsSio wants to merge 1 commit into
mainfrom
d3d12x/zero-recycled-vram-tiles

Conversation

@itsSio

@itsSio itsSio commented Nov 26, 2026

Copy link
Copy Markdown
Owner

TilePool hands cooled recycled tiles back to Pages::bind_range with stale GPU bytes from their previous texture, which can surface as tile-shaped garbage blocks on newly bound render targets, depth buffers, and UAVs (part of #505, recycled-tile finding). This change tracks recycled dirty bits per backing heap in TilePool and lazily zeroes dirty recycled tiles on Pages::queue before mapping them to the new resource. Fresh heaps from CreateHeap and same-address live or IDLE aliases incur no extra GPU work.

What is in it

  • D3D12.X: zero recycled vram::Pages tiles before reuse: crates/xcl/src/hle/d3d12x/vram.rs (TilePool::dirty_tiles per-heap bitset set in drain_cooling, preserved across OOM rollback in return_tiles, cleared on add_heap_at/reclaim_empty_heaps and after successful take_batch; lazy Pages::Zeroer using a 256-tile COMMON reserved scratch buffer, 16-tile zeroed UPLOAD source, and 8-slot fenced DIRECT command list ring to CopyBufferRegion-zero dirty recycled tiles on Pages::queue before Pages::map; unit test tile_pool_marks_recycled_tiles_dirty_and_preserves_dirty_on_rollback and GPU test recycled_pages_tiles_are_zeroed_before_reuse verifying recycled-tile zeroing and same-VA IDLE alias preservation)

Tested
Commit 94c593033ba03fb5a2302786ff810483be13663d (based on main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7), clean checkouts on each PC, debug builds for workspace tests and release builds for retail smoke runs.

  • Pre-fix repro: recycled_pages_tiles_are_zeroed_before_reuse failed without the fix (recycled tile row 0 leaked non-zero data: [ff, 00, ff, ff, ...]) and passes with the fix.
  • PC 1: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11 Pro build 26200.9974, rustc 1.97.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug build (XCL_ADAPTER=NVIDIA).
    • cargo build --workspace: exit 0.
    • cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1437 passed, 0 failed, 47 ignored.
    • SKIPPED: 26 (wave64-only GPU tests, #1426 wave32 f16/cvt refusals, heap_window_out_of_memory_falls_back_to_the_switch_form, pso_measurement_compiles_an_exact_synthetic_record 0x887A002D).
    • cargo test -p xcl --lib vram:: -- --test-threads=1: 21 passed, 0 failed, 1 ignored (churn_update_tile_mappings_timing), 0 SKIPPED (recycled_pages_tiles_are_zeroed_before_reuse ran on the RTX 5080).
  • PC 2: NVIDIA GeForce RTX 2080 SUPER (driver 32.0.16.1088), AMD Ryzen 5 5600X, 16 GB RAM, Windows 11 Pro build 26200.8653, rustc 1.99.1 (stable-x86_64-pc-windows-msvc), Windows SDK 10.0.26100 DXC 1.8.2502.11, debug build (XCL_ADAPTER=NVIDIA).
    • cargo build --workspace: exit 0.
    • cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1436 passed, 1 failed, 47 ignored (both new vram::tests passed; the sole failure was unrelated hle::xgameruntime::gamesave::tests::atomic_writes_preserve_xcltmp_blobs_and_skip_leftover_temps, which passed 1/0 standalone on unpatched b49be183).
    • SKIPPED: 29 (same 26 as PC 1 plus 3 requiring d3d12SDKLayers.dll).

Regression run

main (b49be183, RTX 5080, release):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 5080
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1019 (PresentX 1019)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14670 MB

PR (94c59303, RTX 5080, release):

xcl-smoke v1
commit: 94c593033ba03fb5a2302786ff810483be13663d
gpu: NVIDIA GeForce RTX 5080
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1670 (PresentX 1670)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13913 MB

Not tested

  • Past-world-load visual A/B on the #505 tile-mosaic scene (the 60 s regression run above stays in the loading phase and verifies no performance/memory/stability regression on main).
  • Multi-chunk (>256 tiles) and multi-copy (>16 tiles) GPU stress paths.
  • AMD / Intel GPUs, native wave64, Linux / Wine / vkd3d-proton, and retail scripts/smoke.ps1 on the RTX 2080 SUPER.

AI use
Ran via Samaritan:

  • Google Antigravity CLI (Gemini 4 Hydrogen (High)): wrote the code and tests in 94c59303, ran the pre-fix/post-fix repro, and ran the dual-PC workspace test suites.
  • Google Antigravity CLI (Claude Opus 5.5 (High)): performed an independent cross-model read-only code review (verdict PASS, 0 P0/P1 blockers) and re-ran vram:: GPU tests on the RTX 5080.
  • Google Antigravity CLI (Gemini 4 Neon (High)): coordinated verification, reviewed the full diff, ran the paired RTX 5080 scripts/smoke.ps1 regression runs, ran scripts/pr_check.py --local, and wrote this PR description.

TilePool hands recycled cooling tiles back to Pages::bind_range with stale bytes from their prior texture, causing tile-shaped garbage blocks on new render targets, depth buffers, and UAVs (xcl-dev#505). Track per-heap recycled dirty bits in TilePool and lazily zero dirty tiles on the Pages mapping queue via a scratch reserved buffer and pre-zeroed upload buffer before mapping them to the new resource. Fresh heaps from CreateHeap and live/idle same-address aliases are untouched.

Tested with recycled_pages_tiles_are_zeroed_before_reuse (failed with [ff, 00, ff, ff] leak pre-fix; passed post-fix) and tile_pool_marks_recycled_tiles_dirty_and_preserves_dirty_on_rollback.

Assisted-by: Google Antigravity CLI (Gemini 4 Hydrogen (High))
@itsSio
itsSio force-pushed the d3d12x/zero-recycled-vram-tiles branch from 94c5930 to e540403 Compare November 26, 2026 12:08
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.

1 participant