Skip to content

D3D12.X: fence sparse tile reuse after the last placed-buffer pin - #2531

Open
razormontana wants to merge 1 commit into
xcl-dev:mainfrom
razormontana:d3d12x/retire-sparse-tiles-after-final-pin
Open

razormontana wants to merge 1 commit into
xcl-dev:mainfrom
razormontana:d3d12x/retire-sparse-tiles-after-final-pin

Conversation

@razormontana

Copy link
Copy Markdown
Contributor

D3D12.X: fence sparse tile reuse after the last placed-buffer pin

When a sparse window unmaps a tile still pinned by a placed buffer, the last unpin can put the tile back in the pool before outstanding queue work completes. Defer that return to the existing sparse tile quarantine and take fence marks after the last pin drops. Part of #2457 (item 1), #1773 and #1833.

What is in it

  • sparse.rs queues unused tiles at the last unpin. Allocation and submission fence the queued tiles on the sparse and title queues. Pool reuse and retirement continue to use the free list.
  • A CPU regression checks both mock queue completion orders and exactly-once return. The README documents when a pinned sparse tile returns to the pool.

Tested

  • Windows 11 Pro 22631, Intel Core i7-10700K, GeForce RTX 3070 8 GB (driver 617.42), Rust 1.100.0 MSVC and Windows SDK DXC.
  • Clean 6d7f8b9269a1a83f0b1e23805fd3388cdc0c2c44. cargo test -p xcl --lib -j 2 hle::d3d12x::sparse::tests::unpinned_sparse_tiles_wait_for_every_queue_before_reuse -- --exact passed 1 test with 0 failures, ignored tests or GPU skips.
  • A standalone, CPU-only control using the previous immediate free-list return failed the assertion that the last unpin keeps the tile unavailable.
  • cargo build --offline --locked --workspace and cargo build --offline --locked --release --workspace succeeded. The debug cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-output run with XCL_ADAPTER=3070 reported 1,424 passed, 0 failed and 46 ignored across 37 targets. The pass count includes 26 SKIPPED notices (21 native-wave64 checks, 3 unsupported per-lane forms, 1 reserved cube with mips and 1 heap-window check).

Regression run

Both clean release builds ran scripts/smoke.ps1 -Game <folder> -Seconds 60 on the same retail title in the Series S profile on the RTX 3070. They used XCL_DIRECT_DXIL=1, networking off and identical starting copies of XCL's warmed cache. NVIDIA's driver cache settings were left at their defaults.

Main

xcl-smoke v1
commit: 6d12f58a229bc73889878a448c64dc3af25eeba0
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 651 (PresentX 651)
presents per 2 s (last 3): 8 0 15
device removals: 0
crashes: 0
peak commit: 14469 MB

Candidate

xcl-smoke v1
commit: 6d7f8b9269a1a83f0b1e23805fd3388cdc0c2c44
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 808 (PresentX 808)
presents per 2 s (last 3): 0 18 23
device removals: 0
crashes: 0
peak commit: 14692 MB

Not tested

  • The focused regression uses simulated fence completion. The retail smoke checks startup but does not establish that the last-pin retirement case occurred. AMD and Intel GPU coverage is pending.

AI use

  • OpenAI Codex (GPT-6.2 Sol) traced the sparse tile lifetime, implemented the fix, wrote and ran the focused regression, independently reviewed the diff and evidence, and drafted this description. The lead agent ran the workspace suite and retail smoke using OpenAI Codex (GPT-6.2).

A decommitted sparse tile can stay pinned after the window unmap is queued. Queue its eventual last unpin for the existing fence retirement path before the tile can enter the free list. Mark the sparse queue and title queues from an allocation or submission, outside the Release callback.

Part of xcl-dev#2457 (item 1) and xcl-dev#1773.
@razormontana
razormontana marked this pull request as ready for review November 25, 2026 22:00
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@xpatfussy69x

Copy link
Copy Markdown

Test run on exact head 6d7f8b9 (6d7f8b9269a1a83f0b1e23805fd3388cdc0c2c44, on its base 6d12f58), clean tree.

Tested

Regression run (60 s, default settings, a retail title)

main:

xcl-smoke v1
commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea
gpu: NVIDIA GeForce RTX 3060
title: c3f791f3
seconds: 60
exit: 0x0
frames shown: 1091 (PresentX 1091)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14814 MB

this PR:

xcl-smoke v1
commit: 6d7f8b9269a1a83f0b1e23805fd3388cdc0c2c44
gpu: NVIDIA GeForce RTX 3060
title: c3f791f3
seconds: 60
exit: 0x0
frames shown: 1140 (PresentX 1140)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14787 MB

No crash or device removal; frames 104 % of main's, peak commit 100 %.

Not tested

  • Whether a placed buffer unpins a parked tile while a queue still uses it in this run: a regression check only
  • The PR merged into current main (tested on its own base; it merges into e1d84b7 without conflicts)
  • AMD / native wave64

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and both smoke runs on the machine above and wrote this report.

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) verification of exact PR head 6d7f8b9269a1a83f0b1e23805fd3388cdc0c2c44 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: 1422 passed, 2 failed, 46 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).
    • The new test hle::d3d12x::sparse::tests::unpinned_sparse_tiles_wait_for_every_queue_before_reuse passed.
    • 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: 6d7f8b9269a1a83f0b1e23805fd3388cdc0c2c44
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1600 (PresentX 1600)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13934 MB

(Compare against main 68a284a on this machine: 1573 frames, 14420 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.

@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite (cold cache): 164 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.
Targeted run of unpinned_sparse_tiles_wait_for_every_queue_before_reuse: passed. Sparse tiling on RADV executes for real on this lane.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

@KOLESNiii KOLESNiii mentioned this pull request Nov 25, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…cl-dev#2531 + xcl-dev#2638)

(cherry picked from commit fa5b533156ecdf632edcb1b703c54a16948928bf)
@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #2531 at head 6d7f8b9269a1a83f0b1e23805fd3388cdc0c2c44 (1 commit; exact parent & merge-base: 6d12f58a229bc73889878a448c64dc3af25eeba0, pre-#2555 ancestor of main).

Environment

  • 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 (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (6d7f8b92)

Command Result
cargo test --release -p xcl --lib unpinned_sparse_tiles_wait_for_every_queue_before_reuse -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1324 filtered out × 3 (0.00s × 3, 0 skipped)
cargo test --release -p xcl --lib hle::d3d12x::sparse:: -- --test-threads=1 (3 consecutive runs) 18 passed; 0 failed; 1 ignored; 1306 filtered out × 3 (1.21s, 1.22s, 1.18s, 0 skipped)
cargo build --release -p xcl Clean build (1m 10s, exit 0, 0 new warnings)

Paired quiet 60 s retail smoke (title: 29640639)

Exact parent & merge-base (6d12f58a229bc73889878a448c64dc3af25eeba0, cached baseline on the same machine):

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

PR #2531 (6d7f8b9269a1a83f0b1e23805fd3388cdc0c2c44):

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

Runtime log observations (xcl.log)

  • 9221 log lines, 0 [ERROR] / device-removal / panic lines.
  • Final draw/memory telemetry in log: 19525 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample 14023 MB committed by the process; video memory 6114 MB local, 4686 MB non-local.

Limits of coverage

  • Fencing sparse tile reuse after the last placed-buffer pin across every active queue was verified via unpinned_sparse_tiles_wait_for_every_queue_before_reuse (3/3) and hle::d3d12x::sparse:: (18/0/1 × 3).
  • The 60 s retail smoke on title: 29640639 exercises live sparse VRAM allocation (7445 MB sparse) with zero device removals or crashes (frame-count and commit deltas vs. cached parent reflect single-run startup variance, not this PR); heavy multi-minute placed-buffer churn under tight 8 GB VRAM eviction was not separately stressed here.

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

@andrewDoing

Copy link
Copy Markdown

I tested the last-pin retirement case on NVIDIA GeForce RTX 5070 12 GB, driver 616.92, Windows 11, at PR head 6d7f8b9269a1a83f0b1e23805fd3388cdc0c2c44 with one local test added to sparse.rs. Production code was unchanged.

The fixture mapped a native reserved buffer and a sparse window to the same 64 KiB tile. It registered one placed-buffer pin, removed the sparse window mapping, and waited for the sparse queue to finish the unmap. It then gated a separate D3D12 direct queue on a native fence and queued a four-byte CopyBufferRegion from the still-mapped alias. At that point it invoked forget_in, the production last-release bookkeeping, and requested a tile through take_tile.

Queue state Expected Observed
Alias copy pending after the last pin drops Original tile stays unavailable Original tile (0,0) stayed out of the free list. Allocation returned (0,1).
Gate signaled and title queue passes the copy Original tile becomes reusable exactly once The free list contained (0,0) once, another drain added nothing, and the next allocation returned (0,0).

cargo test --locked -p xcl --lib hle::d3d12x::sparse::tests::native_last_pin_fence_probe -- --exact --nocapture passed in 0.45 s, with 1 passed, 0 failed, and no capability skip. This is a test-only fixture using isolated sparse state. It seeded the pin and buffer records and called forget_in directly. It kept a native COM reference alive for the queued copy. The guest COM Release hook, memory pressure, and title gameplay remain outside this test's coverage.

AI use: OpenAI Codex with GPT-6.2 Astra prepared the fixture and ran the test; Codex coordinated and prepared 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.

7 participants