Skip to content

D3D12.X: late release seals and waits only when nothing is in flight - #1250

Open
duudiis wants to merge 1 commit into
xcl-dev:mainfrom
duudiis:pr/late-release-cheap
Open

duudiis wants to merge 1 commit into
xcl-dev:mainfrom
duudiis:pr/late-release-cheap

Conversation

@duudiis

@duudiis duudiis commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Late release (#866) gets cheaper on the title's threads. A resource's last Release (hold) called drain_known(true) every time. That signalled every known queue (about 10) and then busy-spun up to 300 µs (IDLE_WAIT) on the title's thread. While the GPU has frames in flight, the spin always ran to its end, because a value signalled now is passed only after the work already queued. Every submit (note_execute → drain_known(false)) also cloned every queue and drained, whether anything was due or not. A retail game releases many resources while it loads.

  • hold closes a batch of its own and waits only when no work is known in flight: the queues are past the newest sealed batch, or nothing is sealed. In that case it behaves as before: a title that frees the memory under a resource right after its last Release finds the resource released. With work in flight, the resource could not have gone within IDLE_WAIT anyway. It joins the open batch, which is closed every SEAL_EVERY, and the late-release thread lets it go, as it did after the wait.
  • drain_known first checks cheaply whether anything is due, before it takes any queue. It checks the front sealed batch's marks (GetCompletedValue) and whether an open batch is ready to close.

This touches the same lines of hold as #1070 (hold(res, memory), Dead). The two changes are independent, but whichever is merged second needs a small rebase.

What is in it

  • D3D12.X: late release seals and waits only when nothing is in flight: Held::due, Held::in_flight, Held::admit, Batch::passed, the new hold and the check at the top of drain_known, and two tests (crates/xcl/src/hle/d3d12x/late_release.rs)

Tested

  • NVIDIA GeForce RTX 5070 12 GB (driver 621.24), Intel Core i7-14700KF, Windows 11 (10.0.26300), rustc 1.98.0, release
  • cargo build --workspace --release: ok
  • cargo test --workspace --release -- --test-threads=4: 751 passed, 0 failed, 41 ignored
  • SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
  • SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
  • New tests: a_drain_is_due_only_when_a_batch_can_go_or_be_closed covers when a drain is due: nothing held, an open batch never closed, closed just now, seal_now, and a batch with no marks. a_resource_held_with_work_in_flight_does_not_close_a_batch_of_its_own uses a queue held on a fence: a resource held behind it reports work in flight and closes no batch of its own, and both batches go in order once the queue is let go.

Regression run

xcl-smoke v1
commit: b8b1f491ea5e075a82293f6ebefd8eceffc74de7
gpu: NVIDIA GeForce RTX 5070
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1367 (PresentX 1367)
presents per 2 s (last 3): 9 13 36
device removals: 0
crashes: 0
peak commit: 25764 MB

This PR (a235703):

xcl-smoke v1
commit: a23570302a229a1b3b99d6e305af0aa1bea72e66
gpu: NVIDIA GeForce RTX 5070
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1326 (PresentX 1327)
presents per 2 s (last 3): 13 32 35
device removals: 0
crashes: 0
peak commit: 25803 MB

Both runs reach the loading screen; neither reaches the world, so they are a regression check, not a measurement of the gain.`

Not tested

  • AMD GPUs
  • The retail title (needs the regression run above)
  • No timing was measured for this PR on its own, before or after

AI use

  • Claude Code, Claude Opus 5.5: wrote the code, the tests and this description

A last Release (`hold`) called `drain_known(true)` each time: it Signalled
every known queue (about 10) and then spun up to 300 us (`IDLE_WAIT`) on the
title's thread, and while the GPU has frames in flight the spin always ran
to its end. Each submit (`note_execute`) also cloned every queue and took
their locks to drain, due or not. A retail game releases many resources
while it loads.

- `hold` closes a batch of its own and waits only when no work is known in
  flight (the queues past the newest sealed batch, or none sealed). Then it
  is as before: a title that frees the memory under a resource right after
  its last Release (an imported heap pins the pages under its resources)
  finds it released. With work in flight the resource could not go within
  the wait anyway (a value signalled now is passed after that batch's), so
  it joins the open batch, closed every SEAL_EVERY, and the thread here lets
  it go, as it did after the wait.
- `drain_known` first asks whether anything is due (the front sealed
  batch's marks, GetCompletedValue; or an open batch to close) before it
  takes any queue.

Assisted-by: Claude Code (Claude Opus 5.5)
@thehollowedone

Copy link
Copy Markdown

Independent two-queue check on a235703, Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug.

I exercised the late-release batch logic with native D3D12 direct and copy queues, two batches, and separate gate fences. Completing both marks on the direct queue retired neither batch while the copy queue was blocked. Completing the first copy mark retired only the first batch, while the second stayed in flight. Completing the second mark retired the second batch. A second admission while both queues were blocked was classified as in flight, and the batch sealed on the periodic drain.

All five focused tests passed with no skips, including this scratch fixture. It checks batch eligibility and order with real fences and synthetic resource IDs. CPU release latency and retail behavior were outside this run. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch fixture and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib late_release new tests (drain_is_due, held_with_work_in_flight): 2 passed, 0 failed.

Thanks!

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…all#1248, ivall#1250, ivall#1265, ivall#1273, ivall#1277, ivall#1278

Fix sudden RAM OOM during world loading under XCL_PSO_WAIT_MS and integrate 6 new upstream PRs:
- pso_async.rs: track active waiters via WantGuard so build_is_wanted() drops back to false once resolve_within times out, preventing all background workers from bypassing BIG_COMPILES and commit-memory guards simultaneously (adds unit test a_timed_out_bind_clears_wanted_demand).
- ivall#1248: pack <= 4 KiB sampled textures into 4 KiB heap slots instead of 64 KiB tiles (~768 MiB VRAM saved).
- ivall#1250: late_release seals/waits only when nothing is in flight.
- ivall#1265: default SRVs of multisampled depth buffers use Texture2DMS/Texture2DMSArray.
- ivall#1273: skip budgeted bind waits when all workers are busy / build is queued behind others.
- ivall#1277: exit sparse::upload_dirty cleanly if staging ring fence wait times out.
- ivall#1278: isolate >= 4 MiB DXIL compute driver compiles in a dedicated GIANT_COMPILES queue.

Assisted-by: Antigravity (Google DeepMind)
@ExoCalibra

Copy link
Copy Markdown

Tested exact head a235703 (clean merge onto main 930e8b4).

Tested

  • NVIDIA GeForce RTX 3080 Ti (12,084 MiB VRAM, Wave32, mesh shaders), driver 610.88 (32.0.16.1088), Ryzen 7 7800X3D, 63.1 GB RAM, Windows 11 Pro 10.0.26200, rustc 1.100.0, DXC 1.8.2502.11.
  • .\scripts\test.ps1 (debug): 751 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware. New tests passed: a_drain_is_due_only_when_a_batch_can_go_or_be_closed, a_resource_held_with_work_in_flight_does_not_close_a_batch_of_its_own.
  • cargo build --release -p xcl + 60 s scripts/smoke.ps1 (XCL_NETWORK=0; local VRAM 6155 MB vs 6154 MB on main, target pages 3577 MB vs 3578 MB):

main (930e8b4):

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 3080 Ti
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1576 (PresentX 1576)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15286 MB

PR #1250 (a235703):

xcl-smoke v1
commit: a23570302a229a1b3b99d6e305af0aa1bea72e66
gpu: NVIDIA GeForce RTX 3080 Ti
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1534 (PresentX 1534)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15465 MB

Notes

  • Lock order in late_release.rs checks out (HELD dropped before queue snapshot and COM Release).
  • Overlaps D3D12.X: wait for tiled-texture queues in late_release #1314 at the top of drain_known (small rebase for whichever merges second); due() avoids touching vram::queues() on submits when nothing is due.

Not tested

  • AMD / native wave64, gameplay past startup/menus, isolated CPU latency.

AI use

  • Antigravity (Gemini 4 Neon) ran the tests/smoke and drafted this report; checked by me.

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.

4 participants