Skip to content

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

Open
itsSio wants to merge 1 commit into
xcl-dev:mainfrom
itsSio:d3d12x/zero-recycled-vram-tiles
Open

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

Conversation

@itsSio

@itsSio itsSio commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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. If zeroer initialization, reset, or command-list close fails, Pages::bind_range returns the reserved tiles to TilePool with their dirty bits restored and returns None instead of publishing an unzeroed mapping. 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 (e5404036): crates/xcl/src/hle/d3d12x/vram.rs (TilePool::dirty_tiles per-heap bitset set in drain_cooling, restored on rollback in return_tiles, cleared on add_heap_at/reclaim_empty_heaps and after successful take_batch; lazy Pages::Zeroer returning bool so bind_range rolls back and returns None on Zeroer::new, Reset, or Close failure; unit tests tile_pool_marks_recycled_tiles_dirty_and_preserves_dirty_on_rollback and tile_pool_return_tiles_restores_dirty_bits_after_take_batch; GPU test recycled_pages_tiles_are_zeroed_before_reuse verifying recycled-tile zeroing and same-VA IDLE alias preservation)

Tested
Commit e54040363979e2c629e45e323bd0f84b692770e4 (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: 1438 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 --nocapture: 22 passed, 0 failed, 1 ignored (churn_update_tile_mappings_timing), 0 SKIPPED (recycled_pages_tiles_are_zeroed_before_reuse and tile_pool_return_tiles_restores_dirty_bits_after_take_batch both passed 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: 1438 passed, 0 failed, 47 ignored.
    • SKIPPED: 29 (same 26 as PC 1 plus 3 requiring d3d12SDKLayers.dll).
    • cargo test -p xcl --lib vram:: -- --test-threads=1 --nocapture: 22 passed, 0 failed, 1 ignored, 0 SKIPPED.

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 (e5404036, RTX 5080, release):

xcl-smoke v1
commit: e54040363979e2c629e45e323bd0f84b692770e4
gpu: NVIDIA GeForce RTX 5080
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1669 (PresentX 1669)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14736 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).
  • Injected D3D12 Zeroer::new, Reset, or Close failure on a live GPU (covered by source audit and tile_pool_return_tiles_restores_dirty_bits_after_take_batch on TilePool).
  • 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 and the Zeroer/reset/close error-rollback fix and unit test in e5404036, independently reviewed e5404036, ran the pre-fix/post-fix repro, dual-PC workspace and vram:: suites, and the fresh RTX 5080 e5404036 smoke run.
  • Google Antigravity CLI (Claude Opus 5.5 (High)): performed an independent cross-model read-only code review of 94c59303 (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 diff, ran the paired RTX 5080 scripts/smoke.ps1 baseline, ran scripts/pr_check.py --local, updated this PR description, and pushed e5404036.

@luckyteagirl luckyteagirl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 94c5930, a recycled tile can still be mapped with its previous texture's bytes if the zeroer cannot start. For example, if the first batch contains a dirty recycled tile and creating the zeroer's upload buffer fails, Zeroer::new returns None. zero_tiles returns without submitting any clear, but bind_range continues to map the tile and reports success. The reset and command-list-close error branches also proceed without clearing the affected chunk. The caller's non-tiled fallback only runs when the bind reports failure.

Could zero_tiles report failure so bind_range can stop before publishing the new mapping and return all selected tiles with their original dirty bits? take_batch already clears dirty bits on success, so the existing reservation rollback alone would need to restore those bits in this case. A failure-injection fixture could exhaust fresh tiles, recycle one dirty tile, fail zeroer initialization, then assert the bind does not publish a mapping and that a subsequent reservation still flags the tile for clearing.

This is an exact-head source review. I did not inject a D3D12 failure or run a GPU test.

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))
@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

amd-win test report for 94c5930 (head at the time of the run; merge-base with main is b49be18). Library tests only: I did not run scripts/smoke.ps1 or a retail title, and no integration tests (crates/xcl/tests/).

Environment

  • AMD Radeon RX 7800 XT, driver 32.0.31035.1003, Windows 11 Pro 10.0.26200, rustc 1.100.0 (2026-11-09), debug build
  • DXC 1.8.2502.11 (Windows SDK 10.0.26100.0)
  • XCL_ADAPTER=7800, XCL_REQUIRE_GPU=1, cargo -j 4, separate target dir

Tested (all with the PR checked out detached at 94c5930)

  • cargo test -p xcl --lib vram -- --test-threads=1: 23 passed, 0 failed, 1 ignored. Includes the two new tests, recycled_pages_tiles_are_zeroed_before_reuse and tile_pool_marks_recycled_tiles_dirty_and_preserves_dirty_on_rollback, both ok.
  • cargo test -p xcl --lib d3d12x -- --test-threads=1: 256 passed, 0 failed, 2 ignored.
  • cargo test -p xcl --lib -- --test-threads=4: 1310 passed, 1 failed, 27 ignored.

Result

  • The one failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722: res[30] = 0x1, CPU 0x7fffffff). It fails with the same message on the merge-base b49be18 (cargo test -p xcl --lib fuzz_validate_and_gpu_1), so it is not caused by this PR.
  • 6 GPU tests printed SKIPPED (f16_programs_on_the_gpu x4, f32_programs_on_the_gpu x2: unsupported V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32 per-lane forms). They are not counted as coverage and are unrelated to vram.

Not tested

  • No title run: scripts/smoke.ps1 main vs head, so the maintainer's regression-run requirement is not covered by this report.
  • The failure path raised in the earlier review comment (zeroer cannot start, so the tile is still mapped with old bytes) is not exercised by the tests above, and I did not inject one.
  • The new tests check the zeroing and the dirty-bit bookkeeping; I did not read back tile contents on a real title.
  • Not run on NVIDIA, Intel, or Linux.

AI use: Claude Code (Claude Sonnet 5.5) ran the verification and wrote this report; Claude Code (Claude Opus 5.5) coordinated. Results are from the runs above.

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) verification of exact PR head 94c593033ba03fb5a2302786ff810483be13663d on Windows 11 Pro 26300 (AMD Radeon RX 9060 XT 16 GB, driver 32.0.31044.16, Ryzen 5 5600, Rust 1.100.0 MSVC, DXC 1.9.2602.17).

Tested

  • cargo build --workspace (debug): passed (0 errors).
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1435 passed, 2 failed, 47 ignored (8 SKIPPED: 6 per-lane DXIL forms refused by host adapter/driver, 1 heap_window_out_of_memory_falls_back_to_the_switch_form no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record Windows Developer Mode off).
    • Both new tests passed on this GPU:
      • hle::d3d12x::vram::tests::recycled_pages_tiles_are_zeroed_before_reuse
      • hle::d3d12x::vram::tests::tile_pool_marks_recycled_tiles_dirty_and_preserves_dirty_on_rollback
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and fuzz_validate_and_gpu_3) are pre-existing on unmodified main on this RX 9060 XT / driver 32.0.31044.16.
  • cargo build --release -p xcl + 60 s retail-title smoke test (scripts/smoke.ps1, offline):
xcl-smoke v1
commit: 94c593033ba03fb5a2302786ff810483be13663d
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1595 (PresentX 1596)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18641 MB

(Compare against main b49be183 on this machine: 1603 frames, 18576 MB peak, 0 device removals, 0 crashes.)

Not tested

  • NVIDIA / Intel GPUs, Linux / Wine.

AI use

  • Verification run and report prepared with Antigravity (Gemini 4 Neon); all build, test, and smoke results are from live runs on this machine.

@luckyteagirl

Copy link
Copy Markdown
Contributor

I ran the recycled-tile fixture on Windows at 94c593033ba03fb5a2302786ff810483be13663d to add RX 6800M evidence for the successful zeroing path.

Tested

Windows 11 Home build 26200, Ryzen 9 5980HX, Radeon RX 6800M driver 30.0.13002.13003, and Rust 1.99.0 MSVC.

cargo test --locked -p xcl --lib -j 1 hle::d3d12x::vram::tests::recycled_pages_tiles_are_zeroed_before_reuse -- --exact --test-threads=1 --nocapture
  • The unchanged clean-head fixture uses a default-device creation call and ignores XCL_ADAPTER. It passed. A separate inbox D3D12 probe found the integrated Radeon was the default, but the fixture did not print its device LUID.
  • A disposable test-only overlay selected AMD Radeon RX 6800M explicitly and verified the created device's LUID against the DXGI adapter. It printed PCI 1002:73df, LUID 00000000:00014d72, and passed. The overlay changed only adapter setup in this test and was restored afterward.

Both runs used XCL_REQUIRE_GPU=1 and each exited 0 with 1 passed, 0 failed, 0 ignored, 1,337 filtered out, and no skip markers.

Not tested

Zeroer initialization, reset, or close failures were not injected. I did not run the full workspace suite or a title.

AI use

OpenAI Codex (GPT-6.2 Sol) ran the tests, prepared and restored the adapter overlay, and drafted this report.

@itsSio
itsSio force-pushed the d3d12x/zero-recycled-vram-tiles branch from 94c5930 to e540403 Compare November 26, 2026 12:08
@itsSio

itsSio commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review @luckyteagirl. Pushed squashed commit e54040363979e2c629e45e323bd0f84b692770e4 addressing all three failure branches (Zeroer::new, Reset, and Close) and updated the PR description with fresh dual-PC results and an e5404036 RTX 5080 smoke block:

  • Pages::zero_tiles now returns bool (false if Zeroer::new returns None, alloc.Reset/list.Reset fails, or list.Close fails after unmapping the scratch buffer).
  • TilePool::return_tiles restores each returned tile's dirty bit so failed-zero rollbacks keep recycled tiles marked dirty for subsequent reservations.
  • Pages::bind_range checks !self.zero_tiles(dev, &to_zero) and calls self.pool.return_tiles(&fresh); return None; before publishing any mapping.
  • Added unit test tile_pool_return_tiles_restores_dirty_bits_after_take_batch.

Tested (e5404036)

  • PC 1 (RTX 5080, driver 32.0.16.1088, Ryzen 7 9800X3D, Win11 26200, rustc 1.97.0, DXC 1.9.2609.5): full workspace 1438/0/47 (26 SKIPPED), vram:: 22/0/1 (0 SKIPPED), 60 s smoke 1669 frames (0 removals/crashes).
  • PC 2 (RTX 2080 SUPER, driver 32.0.16.1088, Ryzen 5 5600X, Win11 26200, rustc 1.99.1, WinSDK DXC 1.8.2502.11): full workspace 1438/0/47 (29 SKIPPED), vram:: 22/0/1 (0 SKIPPED).

Not tested

  • Live D3D12 failure injection for Zeroer::new/Reset/Close (rollback dirty-bit restoration is covered by the new TilePool unit test and source audit).

AI use
Ran via Samaritan:

  • Google Antigravity CLI (Gemini 4 Hydrogen (High)): wrote and reviewed the e5404036 error-rollback fix and unit test and ran the dual-PC workspace, vram::, and smoke checks.
  • Google Antigravity CLI (Gemini 4 Neon (High)): verified pr_check.py, pushed e5404036, and posted this update.

@Decodere

Copy link
Copy Markdown
Contributor

Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2759 at e54040363979e2c629e45e323bd0f84b692770e4 (exact parent origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements and targeted test results only; not a full source review.

Setup

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6 cores / 12 threads), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200
  • Toolchain / caches: rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)
  • Workload: Retail workload title: 29640639 via scripts/smoke.ps1 -Seconds 60 (XCL_NETWORK=0 XCL_ACTIVITY=1, default flags, no input)

Targeted RTX 4060 release unit tests (e5404036)

  • cargo test --release -p xcl --lib tile_pool_marks_recycled_tiles_dirty_and_preserves_dirty_on_rollback -- --nocapture: 1 passed, 0 failed, 0 ignored (0.00 s, exit 0).
  • cargo test --release -p xcl --lib tile_pool_return_tiles_restores_dirty_bits_after_take_batch -- --nocapture: 1 passed, 0 failed, 0 ignored (0.00 s, exit 0).
  • cargo test --release -p xcl --lib recycled_pages_tiles_are_zeroed_before_reuse -- --nocapture: 1 passed, 0 failed, 0 ignored (0.26 s, ran live on RTX 4060, 0 skipped, exit 0).
  • cargo test --release -p xcl --lib hle::d3d12x::vram:: -- --test-threads=4: 22 passed, 0 failed, 1 ignored (2.50 s, churn_update_tile_mappings_timing ignored, 0 skipped, exit 0).

Observations

  • All 3 recycled-tile dirty-bit and GPU zero-before-reuse tests (tile_pool_marks_recycled_tiles_dirty_and_preserves_dirty_on_rollback, tile_pool_return_tiles_restores_dirty_bits_after_take_batch, and live RTX 4060 recycled_pages_tiles_are_zeroed_before_reuse) plus the full 22-test hle::d3d12x::vram:: module passed cleanly in --release on exact head e5404036 with 0 skips.
  • Quiet 60 s retail smoke ran cleanly (exit: 0x0, 1570 frames shown, 60 60 60 steady-state presents per 2 s, 0 device removals, 0 crashes, 13987 MB peak commit vs parent b49be183's 14018 MB / 1518 frames).

Paired 60 s RTX 4060 smoke (b49be183 vs e5404036)

Parent origin/main (b49be183):

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

PR #2759 head (e5404036):

xcl-smoke v1
commit: e54040363979e2c629e45e323bd0f84b692770e4
gpu: NVIDIA GeForce RTX 4060
title: 29640639
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: 13987 MB

Limits of coverage

  • Full workspace test suite was not re-run on e5404036 (only targeted hle::d3d12x::vram:: release tests plus paired quiet 60 s smoke).
  • The quiet 60 s retail smoke verifies no runtime regression on normal tile-pool reuse; synthetic Zeroer failure/rollback preservation and recycled-tile GPU zeroing are exercised by the 3 vram::tests cases above.
  • Single discrete NVIDIA 8 GB GPU (RTX 4060) on native Windows 11; no AMD, Intel, or Wine/Linux run on this host.

AI use

Ran the targeted release unit tests and paired quiet 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all test counts and smoke blocks were taken directly from cargo test and scripts/smoke.ps1 outputs.

@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the VRAM tile-recycling tests at e5404036:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=nvidia cargo test -p xcl --lib vram:: -- --test-threads=1 --nocapture
22 passed; 0 failed; 1 ignored; 1316 filtered out      (exit 0)

All three new tests pass here, including the GPU test recycled_pages_tiles_are_zeroed_before_reuse on the real adapter. The ignored test is the existing churn_update_tile_mappings_timing.

What this adds: the author tested an RTX 5080 and an RTX 2080 SUPER with the same driver. This is a third NVIDIA host (Blackwell, 16 GB) and the thread has no report from another machine.

Not tested: the title's tile-mosaic visual A/B, injected zeroer failures, multi-chunk/multi-copy stress, the full workspace suite, a paired 60 s smoke run, AMD and Intel GPUs, native wave64, Wine, release profile, title data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

@SzczepanGrela

Copy link
Copy Markdown

RX 9070 / Wine verification of recycled-tile zeroing, including multi-chunk/slot-reuse coverage and a combined-suite limitation.

Tested

  • Head e54040363979e2c629e45e323bd0f84b692770e4 against main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7.
  • RX 9070 16 GB (RADV GFX1201), Ryzen 7 7700, CachyOS kernel 7.3.0-5-cachyos, Mesa 26.3.1-arch3.5, GE-Proton11-12 Wine 11.0 Staging, vkd3d-proton 8293130ebe370b1+ (local asserts-disabled build), DXC/DXIL 1.9.2602.17, Rust 1.97.1, release x86_64-pc-windows-gnu.
  • The original upstream test body was retained unchanged. A second, identical local test was inserted inside the existing #[cfg(test)] module on both revisions. Every original source byte was preserved and verified.
  • The local test selects RX 9070 explicitly and compares the created device LUID with the selected DXGI adapter. It printed PCI 1002:7550, LUID 00000000:000003ef. It verifies reused physical tile identities, every recycled pixel byte, and every same-VA alias pixel. The two assertions about the new pages.zeroer field are omitted in this shared fixture so it also builds on main.
  • XCL_NETWORK=0, private caches, direct invocation of Windows libtest binaries through GE-Proton Wine with --exact, --nocapture, --test-threads=1. Each paired case was repeated in three fresh processes per revision.
Local fixture Observed tiles Main Head
256 x 256 RGBA8 render target 4 3/3 expected failures: recycled row 0 still magenta (ff 00 ff ff) 3/3 passes: all 262,144 bytes zero, all 65,536 alias pixels cyan
8192 x 8192 RGBA8 render target 4096 3/3 expected failures at the same stale-pixel assertion 3/3 passes: all 268,435,456 bytes zero, all 67,108,864 alias pixels cyan

With the head's unchanged 256-tile chunk size and eight slots, the 4096-tile case exercises 16 chunks and slot reuse. This coverage follows from the observed tile count and the unchanged batching code; no production instrumentation was added.

The original recycled_pages_tiles_are_zeroed_before_reuse also passed 3/3 standalone invocations on the head, without changing its default-device setup.

Combined-module results and controls

Filter hle::d3d12x::vram::tests::, separately at 1 and 4 threads. Main module runs omit the local negative-control fixture; head module runs include it.

Configuration Main, at each thread count Head, at each thread count
D32S8 test included 18 passed / 1 failed / 1 ignored 20 passed / 3 failed / 1 ignored
D32S8 test excluded with --skip d32s8_targets_take_their_own_size_of_video_memory 18 passed / 0 failed / 1 ignored 22 passed / 0 failed / 1 ignored

The common failure is d32s8_targets_take_their_own_size_of_video_memory. On the head, both the original recycled-tile test and the local fixture also fail in the combined run. All three errors occur at CreateCommandList, returning 0x80070057. Those two recycled-tile tests pass standalone and in the module with D32S8 excluded. A separate fresh-process D32S8 invocation fails at that API call on each revision. These are observations, not a root-cause attribution.

The ignored test is churn_update_tile_mappings_timing. No runtime skip markers. All 25 process summaries, failure names, readback markers, executable hashes and source inventories were checked independently.

Not tested

Injected zeroer initialization/reset/close failures, other formats, native Windows, full workspace suite, retail visual behavior, smoke workloads, performance or FPS. The combined module is not a clean pass on this setup.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the diff, adapted the local fixture, ran and verified the paired tests and controls, and drafted this report. Publication authorized by the account owner.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Under Wine + vkd3d-proton on an RTX 4070, this pull request's vram:: tests passed in 3 of 3 runs, and the title stopped presenting between 76 and 87 s in all five runs (78 to 82 s with it, 76 and 87 s without), with no device removal. From 42 to 68 s the runs with it made a median of 837 to 1,100 submissions per 2 s, against 64 and 95 without it.

Setup: main b49be18 + #684 (e56dbc3, which our runs need to get this far), against the same + this pull request (e5404036), release, Wine 11.21 Staging + vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, RTX 4070 12 GB, driver 615.71.09. Title: 120 s each, A pressed once the title presented steadily, XCL_PSO_PRELOAD=0, the first-run screens completed once, no story progress. Tests: -- vram:: --test-threads=4, with vkd3d-proton's device filter leaving only the RTX 4070 (Skipping: Device filter for the others).

Run Tree A pressed Last 2 s with presents ends Submits per 2 s, 42–68 s (median) Peak submits per 2 s Frames
1 main + #684 18.4 s 86.7 s 64 348 1,480
2 main + #684 16.2 s 76.1 s 95 342 1,346
3 + #2759 16.4 s 82.3 s 837 2,533 1,372
4 + #2759 16.4 s 78.1 s 999 1,633 1,298
5 + #2759 16.5 s 78.1 s 1,100 1,652 1,301
  • My guess at the extra submissions: the zeroing copies. The submits count is every ExecuteCommandLists through XCL's queue hook (real.rs:7291), and zero_tiles makes one submission per 256 recycled tiles a bind takes (the chunks loop at vram.rs:888, ExecuteCommandLists at vram.rs:912). No run separated them by queue. Presents were alike up to 40 s (769 to 779 per run from 14 to 40 s) and fewer with it from 42 to 68 s (204 to 226, against 268 and 291).
  • Read: each chunk maps the one scratch buffer onto its tiles (vram.rs:900) and is its own submission. With ZERO_SLOTS = 8 (vram.rs:621), a ninth chunk whose slot's copy is still on the GPU waits on the fence with a null event (vram.rs:895). That wait holds PAGES (vram.rs:1186, 1496), which before_execute takes before every title submission (vram.rs:1386). I did not measure whether it waits. Is a blocking wait under that lock intended during loading?
  • Unlike the RX 9070 / RADV report above, d32s8_targets_take_their_own_size_of_video_memory and recycled_pages_tiles_are_zeroed_before_reuse passed together in the vram:: module here, in 3 of 3 runs at 4 threads (that report's local fixture was not run).

Not tested: Windows; the new tests without this pull request; an injected Zeroer::new, Reset or Close failure; the title past the point where it stops here, so not the #505 scene; the whole test suite.

AI use: Claude Code (Claude Opus 5.5) ran the title and the tests and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

@safesearch77

Copy link
Copy Markdown

Reviewed e5404036 against main (b49be183). The tile bookkeeping holds up: dirty bits
are only cleared after take_batch succeeds, so the OOM rollback keeps them, and reclaimed
heap slots are reset. One thing that breaks once it meets #2385:

#2385 and #2759 apply cleanly on top of each other, but the result does not compile
under cargo test.
#2385 (005a4427) adds a sixth parameter skip: &[bool] to
Pages::bind. The new test recycled_pages_tiles_are_zeroed_before_reuse calls the
five-argument form three times: pages.bind(&dev, &tex_a, 0x10_0000, None, total),
... &tex_b, 0x20_0000 ... and ... &tex_c, 0x20_0000 .... On main + #2385 + this PR:

error[E0061]: this method takes 6 arguments but 5 arguments were supplied
  --> crates/xcl/src/hle/d3d12x/vram.rs:2595, 2669, 2685

Whichever of the two merges second needs &[] as the last argument at those three calls
(#2385's own tests pass &mask or &vec![false; total as usize]). cargo build is
unaffected; only cargo test --workspace breaks, so CI on the second PR to land will
fail rather than the merge being refused.

Checked with cargo check --tests on a scratch tree (main + #2385 + #2759),
x86_64-pc-windows-gnu, compile only; nothing was run.

AI use: Antigravity (Claude Sonnet 5.5) applied both patches and compiled the combined tree;
the error output above is from that run.

@tiagonleal

Copy link
Copy Markdown
Contributor

Suite on RTX 5070 Ti (Windows 11) at e5404036: 1434 passed, 4 failed (the fuzz out-of-memory ones, same on main); all three new tests pass

Tested

  • Head e54040363979e2c629e45e323bd0f84b692770e4 (parent main b49be183), clean detached worktree, built as is, debug. PR open and head unchanged when I started.
  • RTX 5070 Ti 16 GB (driver 32.0.16.1742), Ryzen 7 9800X3D, 32 GB RAM, Windows 11 Pro 26300, rustc 1.100.0 (0ef1bc386 2026-11-09). NVIDIA profile for xcl.exe: shader heap 1024 MB. DXC in use: Windows SDK 1.8.2502.11.
  • cargo build --workspace: ok. cargo test --workspace --no-fail-fast -- --test-threads=4: 1434 passed, 4 failed, 47 ignored.
  • 25 lines contain SKIPPED: 21 "no wave64", 3 wave32 per-lane forms refused (f16 arithmetic, f16 packed, f32 conversions), 1 heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • The failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3, each CreateComputePipelineState: Not enough memory resources are available to complete this operation. (0x8007000E). They fail the same way on main b49be183 (cargo test -p xcl --lib gpu::dxil::fuzz_tests::fuzz_validate_and_gpu: 0 passed, 4 failed).
  • New tests: cargo test -p xcl --lib -- vram:: --nocapture --test-threads=1: 22 passed, 0 failed, 1 ignored (churn_update_tile_mappings_timing). It includes tile_pool_marks_recycled_tiles_dirty_and_preserves_dirty_on_rollback, tile_pool_return_tiles_restores_dirty_bits_after_take_batch and recycled_pages_tiles_are_zeroed_before_reuse. The GPU one ran; it was not skipped.

Not tested

  • The retail title, AMD or Intel, a release-profile suite, Wine or Linux. One machine, one suite run.
  • Injected D3D12 failures in the zeroer, and binds of more than 256 tiles.

AI use

  • Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Sonnet 5.5) ran the builds and tests and wrote this; I checked it.

@thehollowedone

Copy link
Copy Markdown

Independent native D3D12 measurement on #2759 head e5404036, following the question about command-slot fence waits. I used a disposable test-only enlargement of recycled_pages_tiles_are_zeroed_before_reuse: an 8192×8192 RGBA8 reserved texture (4,096 tiles, 256 MiB), so the recycled bind runs 16 zeroing chunks and reuses the eight command-list slots. I counted only calls where the slot fence was incomplete before SetEventOnCompletion and timed the zero_tiles CPU call.

Windows 11 build 26300; RTX 3080 Ti (621.35); Ryzen 7 9800X3D; rustc 1.99.1 MSVC; DXC 1.8.2502.11. cargo test --offline --locked -p xcl --lib recycled_pages_tiles_are_zeroed_before_reuse -- --nocapture --test-threads=1 passed in six fresh processes: each 1 passed, 0 failed, 0 ignored, 0 skipped. All 8,192 readback rows of the recycled texture were zero; the existing same-address alias check passed at rows 0, 4095 and 8191. Each run processed 4,096 recycled tiles in 16 chunks. Incomplete slot-fence waits were 0/6 runs. The zero_tiles CPU call took 9.50–10.79 ms across those runs; that includes queue submission and mapping calls, not GPU completion.

The production path can hold PAGES while waiting for an unfinished slot, but this local fixture constructs Pages directly, and none of these six runs entered that wait. These results neither measure title-thread lock contention nor identify the cause of the Wine run's extra submissions. A native title comparison would need to count internal zeroing submissions separately from title submissions and time actual incomplete-slot waits. No title files or retail run were used; I did not run the full workspace suite on this test-only overlay.

Exact test-only instrumentation diff (restored after testing)
diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs
index 27fe8e6b..a8e59259 100644
--- a/crates/xcl/src/hle/d3d12x/vram.rs
+++ b/crates/xcl/src/hle/d3d12x/vram.rs
@@ -879,6 +879,8 @@ impl Pages {
         if tiles.is_empty() {
             return true;
         }
+        #[cfg(test)]
+        let (test_start, mut test_waits, mut test_wait_time) = (std::time::Instant::now(), 0usize, std::time::Duration::ZERO);
         if self.zeroer.is_none() {
             self.zeroer = Zeroer::new(dev);
         }
@@ -892,7 +894,14 @@ impl Pages {
                 (slot.alloc.clone(), slot.list.clone(), slot.fence_val, z.scratch_buf.clone(), z.zero_buf.clone())
             };
             if fence_val > 0 && self.fence.GetCompletedValue() < fence_val {
+                #[cfg(test)]
+                let wait_start = std::time::Instant::now();
                 let _ = self.fence.SetEventOnCompletion(fence_val, windows::Win32::Foundation::HANDLE::default());
+                #[cfg(test)]
+                {
+                    test_waits += 1;
+                    test_wait_time += wait_start.elapsed();
+                }
             }
             if alloc.Reset().is_err() || list.Reset(&alloc, None).is_err() {
                 return false;
@@ -918,6 +927,11 @@ impl Pages {
             z.slots[z.next_slot].fence_val = self.value;
             z.next_slot = (z.next_slot + 1) % z.slots.len();
         }
+        #[cfg(test)]
+        if tiles.len() > ZERO_SLOTS * ZERO_SCRATCH_TILES {
+            println!("zero_tiles: tiles={} chunks={} incomplete_slot_waits={} wait={:?} total={:?}",
+                tiles.len(), tiles.len().div_ceil(ZERO_SCRATCH_TILES), test_waits, test_wait_time, test_start.elapsed());
+        }
         true
     }
 
@@ -2333,7 +2347,7 @@ mod tests {
             };
             let sample = DXGI_SAMPLE_DESC { Count: 1, Quality: 0 };
             let tex_desc = D3D12_RESOURCE_DESC {
-                Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, Width: 256, Height: 256, DepthOrArraySize: 1, MipLevels: 1,
+                Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, Width: 8192, Height: 8192, DepthOrArraySize: 1, MipLevels: 1,
                 Format: DXGI_FORMAT_R8G8B8A8_UNORM, SampleDesc: sample, Layout: D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE,
                 Flags: D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, ..Default::default()
             };
@@ -2348,7 +2362,9 @@ mod tests {
             let tex_a = make_tex();
             let mut total = 0u32;
             dev.GetResourceTiling(&tex_a, Some(&mut total), None, None, None, 0, std::ptr::null_mut());
-            assert!(total >= 4);
+            if total <= (ZERO_SLOTS * ZERO_SCRATCH_TILES) as u32 || total > 4096 {
+                return crate::gpu::recomp::runner::skip_test("4096-tile bound unavailable");
+            }
 
             let (used_a, extra_a) = pages.bind(&dev, &tex_a, 0x10_0000, None, total).unwrap();
             assert!(pages.zeroer.is_none(), "fresh pool heap tiles must not spin up the zeroer");
@@ -2431,8 +2447,8 @@ mod tests {
 
             let pixels_b = read_tex(&pages, &tex_b, &mut fval);
             let pitch = layout.Footprint.RowPitch as usize;
-            for y in 0..256usize {
-                let row = &pixels_b[y * pitch..y * pitch + 256 * 4];
+            for y in 0..8192usize {
+                let row = &pixels_b[y * pitch..y * pitch + 8192 * 4];
                 assert!(row.iter().all(|&b| b == 0), "recycled tile row {y} leaked non-zero data: {:02x?}", &row[..16]);
             }
 
@@ -2442,7 +2458,7 @@ mod tests {
             let tex_c = make_tex();
             let (used_c, extra_c) = pages.bind(&dev, &tex_c, 0x20_0000, None, total).unwrap();
             let pixels_c = read_tex(&pages, &tex_c, &mut fval);
-            for y in [0usize, 127, 255] {
+            for y in [0usize, 4095, 8191] {
                 assert_eq!(&pixels_c[y * pitch..y * pitch + 4], [0, 255, 255, 255], "same-VA idle reuse at row {y} lost contents");
             }
             pages.release_tiles(used_c, extra_c, Instant::now(), false);

AI use: Codex (GPT-6.2 Sol) reviewed the queue and fence path, ran the six synthetic GPU checks, and drafted this report.

@pvfreis

pvfreis commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

By reading only, not run, at #2436 bab2f537 and #2759 e5404036 merged onto main 8b957bec (clean merge): together these two can self-deadlock on PAGES unless #2703 (9e518da4) lands with or before them.

  • place_on_pages holds PAGES (vram.rs:1404) and calls pages.bind (vram.rs:1412) → zero_tiles (vram.rs:1171) → self.queue.ExecuteCommandLists inside own_work (vram.rs:1091-1092).
  • The Pages queue is made through the title's device (vram.rs:916), so it is adopted (real.rs:2899, 3196) and its ExecuteCommandLists is q_execute_command_lists (real.rs:2945).
  • own_work only makes refresh return early (title_textures.rs:708). q_execute_command_lists still reaches present::note_execute (real.rs:7464) → late_release::drain_known(false) (present.rs:316). When that drain finds a parked texture whose batch every queue is past, it calls D3D12.X: recycle released reserved sampled textures by description and state #2436's vram::recycle_ready (late_release.rs:146), which locks PAGES again (vram.rs:296), a std::sync::Mutex (vram.rs:28, 905), on the same thread. The recycle pool is on by default (vram.rs:137-139). It depends on timing (the xcl-late-release thread and other submits drain too); both halves are busiest while textures stream.
  • Neither PR alone has both halves: on main, vram.rs has no ExecuteCommandLists outside tests, and without D3D12.X: recycle released reserved sampled textures by description and state #2436 there is no recycle_ready.

amd-dev already hit this mechanism, with its own zeroing (d625b20, flush_zero_tiles under PAGES) and the #2436 port (d40d027). It was fixed there by b393194, which is #2703's diff. #2703's description reports the deadlock on amd-dev b5c0275f at t=36s on PAGES.lock(), and bobosneefdev's report on #2703 has the symbolized stack (2 of 5 runs there). On the merge with #2703 added (clean), the is_own_work() early return (real.rs:7433) comes before note_execute, which breaks the chain.

Ask: merge #2703 with or before #2436 + #2759.

AI use: Claude Code (Claude Opus 5.5) found this; Claude Fable 5.2 rechecked it; checked by a person before posting.

@itsSio

itsSio commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the measurements and merge-interaction checks:

  • @Royalflamejlh / @thehollowedone (slot waits and submit count): ZERO_SLOTS = 8 (2,048 tiles = 128 MiB of in-flight zero fills) is intended backpressure to bound the zeroer's command-allocator pool rather than growing it during loading. As @thehollowedone measured on native D3D12 (4,096 tiles / 16 chunks wrapping the 8 slots twice on RTX 3080 Ti, 0/6 incomplete slot-fence waits), the GPU copies finish well ahead of wrapping the ring on Windows; the higher submits counter under XCL_ACTIVITY is expected because each 256-tile chunk submits on Pages's queue through the ExecuteCommandLists hook.
  • @safesearch77 (#2385 Pages::bind 6th skip parameter): noted — if #2385 merges first, I will rebase and update the three pages.bind(...) test calls in recycled_pages_tiles_are_zeroed_before_reuse to pass &[].
  • @pvfreis (#2436 + #2703 PAGES re-entry): agreed — merging #2703 with or before #2436 + #2759 keeps q_execute_command_lists's is_own_work() early return ahead of present::note_execute / late_release::drain_known. Happy to keep #2759 minimal against main as-is unless maintainers want it stacked on #2703.

AI use
Ran via Samaritan:

  • Antigravity (Gemini 4 Neon (High)): reviewed the comments and vram.rs lines on e5404036 and drafted this reply.

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.