D3D12.X: spill overflow two-pass UAV buffers to L0 system memory #3614

Open
saintwolf wants to merge 1 commit from upstream-pr/3614 into main
saintwolf commented 2026-12-01 20:58:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-01T20:58:51Z.


When local-VRAM two-pass UAV buffers reach XCL_TWO_PASS_MB (or the dynamic DXGI headroom floor), two-pass draws spin-wait up to FENCE_WAIT_LIMIT and then shrink or skip draws once the local cap is saturated. On 12 GiB non-UMA cards during heavy mesh-shader world loads, this caused heavy draw skipping and multi-millisecond fence-wait stalls.

This PR adds a bounded D3D12_MEMORY_POOL_L0 (system-memory) spillover pool for full-size overflow two-pass record and argument-scratch UAV buffers, tracked separately from the local VRAM cap (TWO_PASS_L0_ALIVE and FREE_L0_RES), while preserving the original local FENCE_WAIT_LIMIT wait and shrink/refusal fallback whenever L0 spillover is disabled, full, or unsupported by the adapter.

Complementary to #3165 (draft).

What is in it

  • crates/xcl/src/hle/d3d12x/bind.rs:
    • XCL_TWO_PASS_L0_MB (default 512 MiB; 0 disables spillover) and TWO_PASS_L0_ALIVE / FREE_L0_RES tracking (TwoPassBuf::is_l0).
    • uav_buffer_in_pool creates D3D12_HEAP_TYPE_CUSTOM + D3D12_MEMORY_POOL_L0 + D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE buffers for L0 spillover and caches non-OOM adapter refusals (L0_UNSUPPORTED).
    • acquire_res_buf_or_l0 and scratch_args: try full-size local (0 ms, no shrink), spill full-size to L0 on local-cap miss, and fall back to the original local FENCE_WAIT_LIMIT wait + shrink/refusal path if L0 is full or unsupported.
    • trim_idle_l0_free: trims idle FREE_L0_RES entries older than FREE_RES_IDLE from release_allocator_res and take_free as well as put_free_bufs.
    • Unit tests: two_pass_l0_spillover_tracks_and_reuses_separately_from_local and two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full (caps computed relative to TWO_PASS[TP_ALIVE] / TWO_PASS_L0_ALIVE).

Tested

  • Hardware: NVIDIA GeForce RTX 4070 SUPER (12 GiB, driver 32.0.16.2140), AMD Ryzen 7 7800X3D, 31.1 GB RAM, Windows 11 build 26300, rustc 1.100.0, DXC 1.8.2502.11.
  • cargo test -p xcl --lib hle::d3d12x::bind::tests::two_pass_l0 -- --nocapture --test-threads=1 on 4179a5a5: 2 passed, 0 failed, 0 skipped.
  • cargo test -p xcl --lib hle::d3d12x::bind::tests -- --test-threads=4: 117 passed, 0 failed.

Regression run
Matched 60 s smoke runs with identical settings (XCL_DIRECT_DXIL=1, default XCL_PSO_PRELOAD, smoke.ps1 default XCL_PREPARE=0):

main (f07e426d):

xcl-smoke v1
commit: f07e426dade72aa7112cf6bfe08ca6f6ff5a9d5c
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1668 (PresentX 1668)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 16731 MB

this PR (4179a5a5):

xcl-smoke v1
commit: 4179a5a59e50520bab7f0be8b608a0e8625a2db1
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1685 (PresentX 1685)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 17117 MB

Not tested

  • AMD / Intel GPUs, Linux / Wine (vkd3d-proton), and full workspace test suite locally (covered by CI).
  • Note that the 60 s menu smoke does not saturate the local two-pass cap; the spillover, local-shrink fallback, and L0-full refusal paths are exercised by the two unit tests on hardware D3D12.

AI use

  • Antigravity (Gemini 4 Neon) assisted with diagnosing the two-pass cap exhaustion, writing the L0 spillover + fallback/trimming fixes and unit tests, running tests and matched smokes, and drafting this description. Reviewed by me.
<!-- greyfinch-sync:ivall/xcl:issue:5594429809 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614). Originally posted by [saintwolf](https://github.com/saintwolf) on 2026-12-01T20:58:51Z. --- When local-VRAM two-pass UAV buffers reach `XCL_TWO_PASS_MB` (or the dynamic DXGI headroom floor), two-pass draws spin-wait up to `FENCE_WAIT_LIMIT` and then shrink or skip draws once the local cap is saturated. On 12 GiB non-UMA cards during heavy mesh-shader world loads, this caused heavy draw skipping and multi-millisecond fence-wait stalls. This PR adds a bounded `D3D12_MEMORY_POOL_L0` (system-memory) spillover pool for full-size overflow two-pass record and argument-scratch UAV buffers, tracked separately from the local VRAM cap (`TWO_PASS_L0_ALIVE` and `FREE_L0_RES`), while preserving the original local `FENCE_WAIT_LIMIT` wait and shrink/refusal fallback whenever L0 spillover is disabled, full, or unsupported by the adapter. Complementary to #3165 (draft). **What is in it** - `crates/xcl/src/hle/d3d12x/bind.rs`: - `XCL_TWO_PASS_L0_MB` (default `512` MiB; `0` disables spillover) and `TWO_PASS_L0_ALIVE` / `FREE_L0_RES` tracking (`TwoPassBuf::is_l0`). - `uav_buffer_in_pool` creates `D3D12_HEAP_TYPE_CUSTOM` + `D3D12_MEMORY_POOL_L0` + `D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE` buffers for L0 spillover and caches non-OOM adapter refusals (`L0_UNSUPPORTED`). - `acquire_res_buf_or_l0` and `scratch_args`: try full-size local (`0 ms`, no shrink), spill full-size to L0 on local-cap miss, and fall back to the original local `FENCE_WAIT_LIMIT` wait + shrink/refusal path if L0 is full or unsupported. - `trim_idle_l0_free`: trims idle `FREE_L0_RES` entries older than `FREE_RES_IDLE` from `release_allocator_res` and `take_free` as well as `put_free_bufs`. - Unit tests: `two_pass_l0_spillover_tracks_and_reuses_separately_from_local` and `two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full` (caps computed relative to `TWO_PASS[TP_ALIVE]` / `TWO_PASS_L0_ALIVE`). **Tested** - Hardware: NVIDIA GeForce RTX 4070 SUPER (12 GiB, driver `32.0.16.2140`), AMD Ryzen 7 7800X3D, 31.1 GB RAM, Windows 11 build 26300, `rustc 1.100.0`, DXC `1.8.2502.11`. - `cargo test -p xcl --lib hle::d3d12x::bind::tests::two_pass_l0 -- --nocapture --test-threads=1` on `4179a5a5`: **2 passed, 0 failed, 0 skipped**. - `cargo test -p xcl --lib hle::d3d12x::bind::tests -- --test-threads=4`: **117 passed, 0 failed**. **Regression run** Matched 60 s smoke runs with identical settings (`XCL_DIRECT_DXIL=1`, default `XCL_PSO_PRELOAD`, `smoke.ps1` default `XCL_PREPARE=0`): `main` (`f07e426d`): ``` xcl-smoke v1 commit: f07e426dade72aa7112cf6bfe08ca6f6ff5a9d5c gpu: NVIDIA GeForce RTX 4070 SUPER title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1668 (PresentX 1668) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 16731 MB ``` this PR (`4179a5a5`): ``` xcl-smoke v1 commit: 4179a5a59e50520bab7f0be8b608a0e8625a2db1 gpu: NVIDIA GeForce RTX 4070 SUPER title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1685 (PresentX 1685) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 17117 MB ``` **Not tested** - AMD / Intel GPUs, Linux / Wine (`vkd3d-proton`), and full workspace test suite locally (covered by CI). - Note that the 60 s menu smoke does not saturate the local two-pass cap; the spillover, local-shrink fallback, and L0-full refusal paths are exercised by the two unit tests on hardware D3D12. **AI use** - Antigravity (Gemini 4 Neon) assisted with diagnosing the two-pass cap exhaustion, writing the L0 spillover + fallback/trimming fixes and unit tests, running tests and matched smokes, and drafting this description. Reviewed by me.
Foniass commented 2026-12-01 21:10:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:10:09Z.


Review (head 19fc7dd3, diff read, not a merge-check):

  • The fence wait is gone on the default path, even when L0 cannot help. ensure_res_buffer_with_cap (bind.rs ~3087) and scratch_args (~3297) now pass a zero wait whenever XCL_TWO_PASS_L0_MB is non-zero, which is the default. When try_make_l0 then returns None (the 512 MiB L0 cap is full, or CreateCommittedResource on the L0 heap fails, ~285-301), the draw is refused at once instead of waiting up to FENCE_WAIT_LIMIT as on main, so under the heaviest load more draws can be skipped than before. A failed L0 creation is not remembered and is retried on every miss. "Fall back cleanly to the existing refusal path" does not hold, because that path used to wait.
  • On by default with no like-for-like evidence. With the default 512 MiB, any local-cap miss moves record and argument buffers to system memory, even when in-flight fences are about to free local ones, and the L0 attempt comes before the existing-buffer shrink path (~3091). The PR-head smoke run used XCL_DIRECT_DXIL=1, XCL_PREPARE=0 and XCL_PSO_PRELOAD=0, but no settings are given for the main run, so 1045 → 1658 frames does not isolate this change; the retail numbers were measured together with other local L0 testing, and the full suite was not run.
  • Idle L0 buffers stay allocated after spilling stops. FREE_L0_RES is trimmed only when L0 buffers are put back (put_free_bufs, ~491); release_allocator_res (~737) and take_free trim only FREE_RES, and try_make_l0 only runs when the local cap is full. After a spill burst up to 256 MiB of system-memory buffers stay committed until the next spill instead of going after FREE_RES_IDLE.
  • The test does not cover the fallback wiring. two_pass_l0_spillover_tracks_and_reuses_separately_from_local (~10294) calls try_make_l0 and put_free_bufs directly; nothing tests that ensure_res_buffer_with_cap or scratch_args fall back to L0 after a local refusal, the L0-full case, or the zero-wait change.

Fine: TWO_PASS_L0_ALIVE and the is_l0 drop path keep L0 bytes out of the local TP_ALIVE cap, and the reserve calls are rolled back when L0 creation fails. Draft #3165 tackles the same skipped draws by letting buffers exceed the local cap; a maintainer may want only one of the two.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7325847670 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7325847670). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T21:10:09Z. --- Review (head 19fc7dd3, diff read, not a merge-check): - **The fence wait is gone on the default path, even when L0 cannot help.** `ensure_res_buffer_with_cap` (`bind.rs` ~3087) and `scratch_args` (~3297) now pass a zero wait whenever `XCL_TWO_PASS_L0_MB` is non-zero, which is the default. When `try_make_l0` then returns `None` (the 512 MiB L0 cap is full, or `CreateCommittedResource` on the L0 heap fails, ~285-301), the draw is refused at once instead of waiting up to `FENCE_WAIT_LIMIT` as on `main`, so under the heaviest load more draws can be skipped than before. A failed L0 creation is not remembered and is retried on every miss. "Fall back cleanly to the existing refusal path" does not hold, because that path used to wait. - **On by default with no like-for-like evidence.** With the default 512 MiB, any local-cap miss moves record and argument buffers to system memory, even when in-flight fences are about to free local ones, and the L0 attempt comes before the existing-buffer shrink path (~3091). The PR-head smoke run used `XCL_DIRECT_DXIL=1`, `XCL_PREPARE=0` and `XCL_PSO_PRELOAD=0`, but no settings are given for the `main` run, so 1045 → 1658 frames does not isolate this change; the retail numbers were measured together with other local L0 testing, and the full suite was not run. - **Idle L0 buffers stay allocated after spilling stops.** `FREE_L0_RES` is trimmed only when L0 buffers are put back (`put_free_bufs`, ~491); `release_allocator_res` (~737) and `take_free` trim only `FREE_RES`, and `try_make_l0` only runs when the local cap is full. After a spill burst up to 256 MiB of system-memory buffers stay committed until the next spill instead of going after `FREE_RES_IDLE`. - **The test does not cover the fallback wiring.** `two_pass_l0_spillover_tracks_and_reuses_separately_from_local` (~10294) calls `try_make_l0` and `put_free_bufs` directly; nothing tests that `ensure_res_buffer_with_cap` or `scratch_args` fall back to L0 after a local refusal, the L0-full case, or the zero-wait change. Fine: `TWO_PASS_L0_ALIVE` and the `is_l0` drop path keep L0 bytes out of the local `TP_ALIVE` cap, and the `reserve` calls are rolled back when L0 creation fails. Draft #3165 tackles the same skipped draws by letting buffers exceed the local cap; a maintainer may want only one of the two. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
saintwolf commented 2026-12-01 21:38:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-01T21:38:29Z.


Thanks for the thorough review — addressed all four points in 1aa29c4d:

  1. Preserved local fence-wait fallback: \cquire_res_buf_or_l0\ and \scratch_args\ now try fast local (0 ms) -> L0 spillover -> if L0 is full or unsupported, fall back to the original local \FENCE_WAIT_LIMIT\ wait before shrinking/refusing, so it cannot skip more draws than \main. Non-OOM L0 creation failures are cached in \L0_UNSUPPORTED\ so subsequent misses go straight to the local wait path.
  2. Idle L0 buffer trimming: Added \ rim_idle_l0_free\ (older than \FREE_RES_IDLE) called from
    elease_allocator_res\ and \ ake_free\ as well as \put_free_bufs, so idle L0 buffers are released after a spill burst ends.
  3. Fallback wiring test: Added \ wo_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full\ exercising \cquire_res_buf_or_l0\ on both local-cap-full -> L0 spillover and L0-full -> clean \Ok(None)\ fallback (2/2 passed on RTX 4070 SUPER).
  4. Matched smoke: Replaced the regression section with matched 60 s runs of \main\ (\ 07e426d) and \1aa29c4d\ under identical settings (\XCL_DIRECT_DXIL=1, default \XCL_PSO_PRELOAD).

AI use: Antigravity (Gemini 4 Neon) assisted with implementing the fixes, running the tests and matched smokes, and drafting this reply.

<!-- greyfinch-sync:ivall/xcl:comment:7326565975 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7326565975). Originally posted by [saintwolf](https://github.com/saintwolf) on 2026-12-01T21:38:29Z. --- Thanks for the thorough review — addressed all four points in 1aa29c4d: 1. **Preserved local fence-wait fallback**: \cquire_res_buf_or_l0\ and \scratch_args\ now try fast local (0 ms) -> L0 spillover -> if L0 is full or unsupported, fall back to the original local \FENCE_WAIT_LIMIT\ wait before shrinking/refusing, so it cannot skip more draws than \main\. Non-OOM L0 creation failures are cached in \L0_UNSUPPORTED\ so subsequent misses go straight to the local wait path. 2. **Idle L0 buffer trimming**: Added \ rim_idle_l0_free\ (older than \FREE_RES_IDLE\) called from \ elease_allocator_res\ and \ ake_free\ as well as \put_free_bufs\, so idle L0 buffers are released after a spill burst ends. 3. **Fallback wiring test**: Added \ wo_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full\ exercising \cquire_res_buf_or_l0\ on both local-cap-full -> L0 spillover and L0-full -> clean \Ok(None)\ fallback (2/2 passed on RTX 4070 SUPER). 4. **Matched smoke**: Replaced the regression section with matched 60 s runs of \main\ (\ 07e426d\) and \1aa29c4d\ under identical settings (\XCL_DIRECT_DXIL=1\, default \XCL_PSO_PRELOAD\). AI use: Antigravity (Gemini 4 Neon) assisted with implementing the fixes, running the tests and matched smokes, and drafting this reply.
Foniass commented 2026-12-01 21:41:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:41:22Z.


Follow-up review (head 1aa29c4d, since 19fc7dd3, diff read, not a merge-check):

  • The fence wait is gone on the default path, even when L0 cannot help: fixed. acquire_res_buf_or_l0 (bind.rs ~3105-3124) and scratch_args (~3345-3359) try local with no wait, then L0, then the old FENCE_WAIT_LIMIT wait when L0 returns None; adapter refusals other than out-of-memory are remembered in L0_UNSUPPORTED (~304-308).
  • On by default with no like-for-like evidence: partly fixed. The smoke runs now use the same settings, but the description says the 60 s run never fills the local cap, so the spill path is not measured in a game, and the full suite was not run on a GPU.
  • Idle L0 buffers stay allocated after spilling stops: fixed. trim_idle_l0_free (~743) is also called from release_allocator_res (~751) and take_free (~771).
  • The test does not cover the fallback wiring: partly fixed. two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full (~10392) goes through acquire_res_buf_or_l0, but with min_fit == need, so the shrink case below is not covered, and the L0 fallback in scratch_args is not tested.

New:

  • Under cap pressure the record buffer shrinks before any wait or spill. acquire_res_buf_or_l0 first calls acquire_res_buf_with_cap with a zero wait (~3115), and that function still runs its shrink loop (~666-690), down to one record (min_fit is record_bytes, ~3579, ~3846). With the default XCL_TWO_PASS_L0_MB=512, a draw that hits the local cap gets a smaller local buffer at once and is sliced or has groups cut (record_groups, ~3580), where main first waits up to FENCE_WAIT_LIMIT for a full-size buffer. L0 is tried only when even the smallest size fails, so "spill to L0 on a local-cap miss" does not hold for record buffers.
  • Fixup commit not squashed. 1aa29c4d fixes 19fc7dd3, whose message still says overflow buffers spill "instead of spin-waiting and skipping draws".

Fine: L0 bytes stay out of the local cap (TWO_PASS_L0_ALIVE, is_l0 on drop); reserve is rolled back when L0 creation fails; XCL_TWO_PASS_L0_MB=0 gives back the main path.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7326638435 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7326638435). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T21:41:22Z. --- Follow-up review (head 1aa29c4d, since 19fc7dd3, diff read, not a merge-check): - **The fence wait is gone on the default path, even when L0 cannot help:** fixed. `acquire_res_buf_or_l0` (`bind.rs` ~3105-3124) and `scratch_args` (~3345-3359) try local with no wait, then L0, then the old `FENCE_WAIT_LIMIT` wait when L0 returns `None`; adapter refusals other than out-of-memory are remembered in `L0_UNSUPPORTED` (~304-308). - **On by default with no like-for-like evidence:** partly fixed. The smoke runs now use the same settings, but the description says the 60 s run never fills the local cap, so the spill path is not measured in a game, and the full suite was not run on a GPU. - **Idle L0 buffers stay allocated after spilling stops:** fixed. `trim_idle_l0_free` (~743) is also called from `release_allocator_res` (~751) and `take_free` (~771). - **The test does not cover the fallback wiring:** partly fixed. `two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full` (~10392) goes through `acquire_res_buf_or_l0`, but with `min_fit == need`, so the shrink case below is not covered, and the L0 fallback in `scratch_args` is not tested. New: - **Under cap pressure the record buffer shrinks before any wait or spill.** `acquire_res_buf_or_l0` first calls `acquire_res_buf_with_cap` with a zero wait (~3115), and that function still runs its shrink loop (~666-690), down to one record (`min_fit` is `record_bytes`, ~3579, ~3846). With the default `XCL_TWO_PASS_L0_MB=512`, a draw that hits the local cap gets a smaller local buffer at once and is sliced or has groups cut (`record_groups`, ~3580), where `main` first waits up to `FENCE_WAIT_LIMIT` for a full-size buffer. L0 is tried only when even the smallest size fails, so "spill to L0 on a local-cap miss" does not hold for record buffers. - **Fixup commit not squashed.** `1aa29c4d` fixes `19fc7dd3`, whose message still says overflow buffers spill "instead of spin-waiting and skipping draws". Fine: L0 bytes stay out of the local cap (`TWO_PASS_L0_ALIVE`, `is_l0` on drop); `reserve` is rolled back when L0 creation fails; `XCL_TWO_PASS_L0_MB=0` gives back the `main` path. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
saintwolf commented 2026-12-01 21:48:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-01T21:48:35Z.


Thanks for catching the shrink-before-spill bug — fixed and squashed into a single clean commit (344962b9) on main (f07e426d):

  1. No shrink before L0 spill: acquire_res_buf_or_l0 now calls acquire_two_pass_buf_with_cap for the full need size with Duration::ZERO (no shrink loop), then spills the full-size buffer to L0 via TwoPassBuf::try_make_l0_with_cap, and only falls back to acquire_res_buf_with_cap(..., FENCE_WAIT_LIMIT) (wait + shrink) if L0 is disabled, full, or unsupported.
  2. Expanded fallback test: two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full now uses min_fit < local_cap < need to assert all three transitions: full-size L0 spill without shrinking, local-shrink fallback when L0 is full, and Ok(None) when both caps are full (2/2 passed on RTX 4070 SUPER).
  3. Squashed: Combined into one commit (344962b9) with an accurate commit message.

AI use: Antigravity (Gemini 4 Neon) assisted with fixing the shrink-before-spill path, updating the unit test, squashing, and drafting this reply.

<!-- greyfinch-sync:ivall/xcl:comment:7326813267 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7326813267). Originally posted by [saintwolf](https://github.com/saintwolf) on 2026-12-01T21:48:35Z. --- Thanks for catching the shrink-before-spill bug — fixed and squashed into a single clean commit (`344962b9`) on `main` (`f07e426d`): 1. **No shrink before L0 spill**: `acquire_res_buf_or_l0` now calls `acquire_two_pass_buf_with_cap` for the full `need` size with `Duration::ZERO` (no shrink loop), then spills the full-size buffer to L0 via `TwoPassBuf::try_make_l0_with_cap`, and only falls back to `acquire_res_buf_with_cap(..., FENCE_WAIT_LIMIT)` (wait + shrink) if L0 is disabled, full, or unsupported. 2. **Expanded fallback test**: `two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full` now uses `min_fit < local_cap < need` to assert all three transitions: full-size L0 spill without shrinking, local-shrink fallback when L0 is full, and `Ok(None)` when both caps are full (`2/2` passed on RTX 4070 SUPER). 3. **Squashed**: Combined into one commit (`344962b9`) with an accurate commit message. AI use: Antigravity (Gemini 4 Neon) assisted with fixing the shrink-before-spill path, updating the unit test, squashing, and drafting this reply.
Foniass commented 2026-12-01 21:51:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T21:51:41Z.


Follow-up review (head 344962b9, since 1aa29c4d, diff read, not a merge-check; checks red):

  • Under cap pressure the record buffer shrinks before any wait or spill: fixed. acquire_res_buf_or_l0 (bind.rs ~3106-3123) now tries acquire_two_pass_buf_with_cap at full size with no wait and no shrink loop, then L0, and only then acquire_res_buf_with_cap with FENCE_WAIT_LIMIT.
  • The test does not cover the fallback wiring: partly fixed. The shrink case is covered (~10409-10423: full-size L0 buffer, then a local shrink once L0 is full); the L0 fallback in scratch_args (~3344-3358) is still untested.
  • Fixup commit: fixed; one commit, with a message that no longer claims draws stop being skipped.
  • No like-for-like evidence on the spill path: partly fixed. The smoke blocks name 1aa29c4d, not the head 344962b9, so PR description fails; the description still says the 60 s run never fills the local cap, and the full suite was not run on a GPU.

New:

  • The new test steps use absolute local caps. Steps 2 and 3 (~10421, ~10426) pass budget_cap as 2 << 20 and 1, but TWO_PASS[TP_ALIVE] counts every live local two-pass buffer in the process, so if earlier tests still hold more than 1 MiB (fenced or awaiting an allocator reset) the shrink in step 2 cannot fit and the test fails depending on order. The other cap tests compute their cap from TWO_PASS[TP_ALIVE].load(..) (~10001, ~10123, ~10330).

Fine: the record path no longer shrinks before spilling; XCL_TWO_PASS_L0_MB=0 (or an adapter that refuses L0) keeps main's wait-and-shrink path; L0 bytes stay out of the local cap; reserve is rolled back when L0 creation fails.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7326916678 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7326916678). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T21:51:41Z. --- Follow-up review (head 344962b9, since 1aa29c4d, diff read, not a merge-check; checks red): - **Under cap pressure the record buffer shrinks before any wait or spill:** fixed. `acquire_res_buf_or_l0` (`bind.rs` ~3106-3123) now tries `acquire_two_pass_buf_with_cap` at full size with no wait and no shrink loop, then L0, and only then `acquire_res_buf_with_cap` with `FENCE_WAIT_LIMIT`. - **The test does not cover the fallback wiring:** partly fixed. The shrink case is covered (~10409-10423: full-size L0 buffer, then a local shrink once L0 is full); the L0 fallback in `scratch_args` (~3344-3358) is still untested. - **Fixup commit:** fixed; one commit, with a message that no longer claims draws stop being skipped. - **No like-for-like evidence on the spill path:** partly fixed. The smoke blocks name `1aa29c4d`, not the head `344962b9`, so `PR description` fails; the description still says the 60 s run never fills the local cap, and the full suite was not run on a GPU. New: - **The new test steps use absolute local caps.** Steps 2 and 3 (~10421, ~10426) pass `budget_cap` as `2 << 20` and `1`, but `TWO_PASS[TP_ALIVE]` counts every live local two-pass buffer in the process, so if earlier tests still hold more than 1 MiB (fenced or awaiting an allocator reset) the shrink in step 2 cannot fit and the test fails depending on order. The other cap tests compute their cap from `TWO_PASS[TP_ALIVE].load(..)` (~10001, ~10123, ~10330). Fine: the record path no longer shrinks before spilling; `XCL_TWO_PASS_L0_MB=0` (or an adapter that refuses L0) keeps `main`'s wait-and-shrink path; L0 bytes stay out of the local cap; `reserve` is rolled back when L0 creation fails. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 22:00:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T22:00:31Z.


Follow-up review (head 4179a5a5, since 344962b9, diff read, not a merge-check; checks red):

  • The new test steps use absolute local caps: fixed. two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full (bind.rs ~10404-10431) now takes its local and L0 caps relative to TWO_PASS[TP_ALIVE] and TWO_PASS_L0_ALIVE at the start, like the other cap tests, so it no longer depends on what earlier tests still hold.
  • The L0 fallback in scratch_args is untested: still open (~3344-3358).
  • Evidence: still open. The smoke block still names 1aa29c4d, not the head 4179a5a5 (the reason PR description is red), the spill path is not reached in the 60 s run, and the test counts are from 1aa29c4d / 19fc7dd3 with no full-suite run on a GPU.

New: none. Since 344962b9 only the test changed.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7327135158 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7327135158). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T22:00:31Z. --- Follow-up review (head 4179a5a5, since 344962b9, diff read, not a merge-check; checks red): - **The new test steps use absolute local caps:** fixed. `two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full` (`bind.rs` ~10404-10431) now takes its local and L0 caps relative to `TWO_PASS[TP_ALIVE]` and `TWO_PASS_L0_ALIVE` at the start, like the other cap tests, so it no longer depends on what earlier tests still hold. - **The L0 fallback in `scratch_args` is untested:** still open (~3344-3358). - **Evidence:** still open. The smoke block still names `1aa29c4d`, not the head `4179a5a5` (the reason `PR description` is red), the spill path is not reached in the 60 s run, and the test counts are from `1aa29c4d` / `19fc7dd3` with no full-suite run on a GPU. New: none. Since `344962b9` only the test changed. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
saintwolf commented 2026-12-01 22:02:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-01T22:02:00Z.


@Foniass Let your bot take a breath bro. I haven't even had a chance to post the smoke results yet.

<!-- greyfinch-sync:ivall/xcl:comment:7327170648 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7327170648). Originally posted by [saintwolf](https://github.com/saintwolf) on 2026-12-01T22:02:00Z. --- @Foniass Let your bot take a breath bro. I haven't even had a chance to post the smoke results yet.
saintwolf commented 2026-12-01 22:02:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by saintwolf on 2026-12-01T22:02:55Z.


Fixed the relative local/L0 caps in two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full (local_before + ... / l0_before + ...), amended to 4179a5a5, and updated the PR description with a fresh 60 s head smoke (1685 frames, 60 61 60, 0 removals/crashes).

All substantive review points are now addressed and tested (2/2 L0 unit tests passed on hardware D3D12, single clean commit, matched head smoke). Leaving this ready for human maintainer review.

AI use: Antigravity (Gemini 4 Neon) applied the relative-cap test fix, ran the head smoke, and drafted this reply.

<!-- greyfinch-sync:ivall/xcl:comment:7327192197 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7327192197). Originally posted by [saintwolf](https://github.com/saintwolf) on 2026-12-01T22:02:55Z. --- Fixed the relative local/L0 caps in `two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full` (`local_before + ...` / `l0_before + ...`), amended to `4179a5a5`, and updated the PR description with a fresh 60 s head smoke (`1685` frames, `60 61 60`, `0` removals/crashes). All substantive review points are now addressed and tested (`2/2` L0 unit tests passed on hardware D3D12, single clean commit, matched head smoke). Leaving this ready for human maintainer review. AI use: Antigravity (Gemini 4 Neon) applied the relative-cap test fix, ran the head smoke, and drafted this reply.
jsalzy commented 2026-12-01 22:43:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by jsalzy on 2026-12-01T22:43:48Z.


merge-check claim
head: 4179a5a59e

<!-- greyfinch-sync:ivall/xcl:comment:7328253112 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7328253112). Originally posted by [jsalzy](https://github.com/jsalzy) on 2026-12-01T22:43:48Z. --- merge-check claim head: 4179a5a59e50520bab7f0be8b608a0e8625a2db1
jsalzy commented 2026-12-01 22:57:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by jsalzy on 2026-12-01T22:57:57Z.


merge-check
base: 1c8b551
head: 4179a5a
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64 on this GPU; 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: none
review: whole diff read (bind.rs, +270/-23). Both new GPU tests ran and passed on this NVIDIA card (not skipped: the driver made the CUSTOM / MEMORY_POOL_L0 / NOT_AVAILABLE UAV buffers): two_pass_l0_spillover_tracks_and_reuses_separately_from_local, two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full. L0 buffers are counted in TWO_PASS_L0_ALIVE and FREE_L0_RES only, and Drop subtracts from the right counter. Foniass's points look addressed at this head: with L0 full or unsupported, the original FENCE_WAIT_LIMIT wait and shrink path runs as before. Behaviour change to note: it is on by default (XCL_TWO_PASS_L0_MB=512), and while L0 has room a full local cap now spills at once instead of waiting up to 10 ms for in-flight buffers, so up to 512 MiB alive plus a 256 MiB free pool go to system commit, which matters on 32 GB machines near their commit limit. Minor: the adapter-refusal test in try_make_l0_with_cap matches the error text ("0x8007000E"); #3620 checks err.code() instead, which is sturdier. Overlaps draft #3165 in the same two-pass cap code (the author calls them complementary); not a duplicate.
performance: not measured.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.

<!-- greyfinch-sync:ivall/xcl:comment:7328564213 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7328564213). Originally posted by [jsalzy](https://github.com/jsalzy) on 2026-12-01T22:57:57Z. --- merge-check base: 1c8b551 head: 4179a5a merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64 on this GPU; 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: none review: whole diff read (bind.rs, +270/-23). Both new GPU tests ran and passed on this NVIDIA card (not skipped: the driver made the CUSTOM / MEMORY_POOL_L0 / NOT_AVAILABLE UAV buffers): two_pass_l0_spillover_tracks_and_reuses_separately_from_local, two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full. L0 buffers are counted in TWO_PASS_L0_ALIVE and FREE_L0_RES only, and Drop subtracts from the right counter. Foniass's points look addressed at this head: with L0 full or unsupported, the original FENCE_WAIT_LIMIT wait and shrink path runs as before. Behaviour change to note: it is on by default (XCL_TWO_PASS_L0_MB=512), and while L0 has room a full local cap now spills at once instead of waiting up to 10 ms for in-flight buffers, so up to 512 MiB alive plus a 256 MiB free pool go to system commit, which matters on 32 GB machines near their commit limit. Minor: the adapter-refusal test in try_make_l0_with_cap matches the error text ("0x8007000E"); #3620 checks err.code() instead, which is sturdier. Overlaps draft #3165 in the same two-pass cap code (the author calls them complementary); not a duplicate. performance: not measured. verdict: safe to merge hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.
vasanex commented 2026-12-02 00:18:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T00:18:18Z.


merge-check claim
head: 4179a5a59e

<!-- greyfinch-sync:ivall/xcl:comment:7330388352 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7330388352). Originally posted by [vasanex](https://github.com/vasanex) on 2026-12-02T00:18:18Z. --- merge-check claim head: 4179a5a59e50520bab7f0be8b608a0e8625a2db1
vasanex commented 2026-12-02 00:45:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T00:45:49Z.


merge-check
base: 1c8b551475
head: 4179a5a59e
merge: clean (merged tree f0185483, git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same set as on the base; failing: none. Base alone, same machine: 2909 passed, 0 failed, 51 ignored. Both new tests pass and did not skip (two_pass_l0_spillover_tracks_and_reuses_separately_from_local, two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full), so this card and driver accept a custom L0 UAV buffer without CPU access.
review: whole diff read (bind.rs), in the merge result. No blocking finding; three points for whoever merges, most serious first. (1) It is on by default (512 MiB) and it changes what happens at a full local cap: main waits up to 10 ms on the oldest fences for local memory and then shrinks; with this the first try has no wait, the buffer goes to system memory at once, and the wait and shrink come only when L0 is full or refused. Draws are kept instead of cut, at the price of record and argument buffers the GPU writes and reads over PCIe. Neither side of that is measured: the description's smoke and mine do not reach the cap (no two-pass buffers: line in either of my logs). (2) two_pass_cap is derived from the adapter's local budget. On an adapter with one memory segment (integrated GPUs) an L0 heap is the same memory, so there the default raises the two-pass ceiling by up to 512 MiB instead of moving anything; nothing in the diff tells the two kinds apart. Reasoned from the code, not run on such an adapter. (3) L0_UNSUPPORTED is set for good by any creation error whose text does not hold 0x8007000E, a lost device included; harmless (it only turns the spill off), but the log does not say so. Otherwise: L0 buffers are counted and freed apart from the local ones (TWO_PASS_L0_ALIVE, FREE_L0_RES, Drop), a buffer cannot change pools on reuse, idle L0 buffers are trimmed on the same paths as local ones, and XCL_TWO_PASS_L0_MB=0 gives main's path exactly. The tests compute their caps from the live counters, as the file's other cap tests do. No README line for XCL_TWO_PASS_L0_MB. Duplicates: none; #3165 (draft, lets a draw's buffer go past the cap) and #3620 (same author, texture pools) are other changes.
performance: 60 s smoke of the same title, release, default settings, same machine, one run each. Base 1c8b5514: 1608 frames shown, presents per 2 s (last 3) 60 60 61, 0 device removals, 0 crashes, peak commit 19911 MB. Merge result (local merge commit of the two commits above): 1616 frames shown, 61 60 60, 0 device removals, 0 crashes, peak commit 18794 MB. No difference outside the run-to-run spread, and the run does not saturate the cap, so this shows only that the default path is unharmed when the cap is not reached. By default it can add up to 512 MiB of system memory once the cap is full.
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0, debug suite and release smoke / Claude Code with Claude Fable 5.2. Run and posted without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7330929923 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7330929923). Originally posted by [vasanex](https://github.com/vasanex) on 2026-12-02T00:45:49Z. --- merge-check base: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f head: 4179a5a59e50520bab7f0be8b608a0e8625a2db1 merge: clean (merged tree f0185483, `git diff --check` clean) build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2911 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same set as on the base; failing: none. Base alone, same machine: 2909 passed, 0 failed, 51 ignored. Both new tests pass and did not skip (`two_pass_l0_spillover_tracks_and_reuses_separately_from_local`, `two_pass_l0_fallback_spills_on_local_cap_and_refuses_when_l0_full`), so this card and driver accept a custom L0 UAV buffer without CPU access. review: whole diff read (bind.rs), in the merge result. No blocking finding; three points for whoever merges, most serious first. (1) It is on by default (512 MiB) and it changes what happens at a full local cap: main waits up to 10 ms on the oldest fences for local memory and then shrinks; with this the first try has no wait, the buffer goes to system memory at once, and the wait and shrink come only when L0 is full or refused. Draws are kept instead of cut, at the price of record and argument buffers the GPU writes and reads over PCIe. Neither side of that is measured: the description's smoke and mine do not reach the cap (no `two-pass buffers:` line in either of my logs). (2) `two_pass_cap` is derived from the adapter's local budget. On an adapter with one memory segment (integrated GPUs) an L0 heap is the same memory, so there the default raises the two-pass ceiling by up to 512 MiB instead of moving anything; nothing in the diff tells the two kinds apart. Reasoned from the code, not run on such an adapter. (3) `L0_UNSUPPORTED` is set for good by any creation error whose text does not hold 0x8007000E, a lost device included; harmless (it only turns the spill off), but the log does not say so. Otherwise: L0 buffers are counted and freed apart from the local ones (`TWO_PASS_L0_ALIVE`, `FREE_L0_RES`, `Drop`), a buffer cannot change pools on reuse, idle L0 buffers are trimmed on the same paths as local ones, and `XCL_TWO_PASS_L0_MB=0` gives main's path exactly. The tests compute their caps from the live counters, as the file's other cap tests do. No README line for `XCL_TWO_PASS_L0_MB`. Duplicates: none; #3165 (draft, lets a draw's buffer go past the cap) and #3620 (same author, texture pools) are other changes. performance: 60 s smoke of the same title, release, default settings, same machine, one run each. Base 1c8b5514: 1608 frames shown, presents per 2 s (last 3) 60 60 61, 0 device removals, 0 crashes, peak commit 19911 MB. Merge result (local merge commit of the two commits above): 1616 frames shown, 61 60 60, 0 device removals, 0 crashes, peak commit 18794 MB. No difference outside the run-to-run spread, and the run does not saturate the cap, so this shows only that the default path is unharmed when the cap is not reached. By default it can add up to 512 MiB of system memory once the cap is full. verdict: safe to merge hardware / tool and model: NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0, debug suite and release smoke / Claude Code with Claude Fable 5.2. Run and posted without a human check of each point.
bmjask commented 2026-12-02 16:03:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:03:42Z.

Code review location: crates/xcl/src/hle/d3d12x/bind.rs; line 311

@@ -244,7 +263,58 @@ impl TwoPassBuf {
             }
         };
         note_two_pass(TP_MADE);
-        Ok(Some(TwoPassBuf { res, bytes, dev: dev.as_raw() as usize }))
+        Ok(Some(TwoPassBuf { res, bytes, dev: dev.as_raw() as usize, is_l0: false }))
+    }
+
+    /// Spillover allocation in `D3D12_MEMORY_POOL_L0` (system memory) when local VRAM
+    /// `two_pass_cap` is exhausted. Returns `None` if disabled, at `cap`, or if the adapter
+    /// rejects custom L0 UAV buffers.
+    #[cfg(test)]
+    unsafe fn try_make_l0(dev: &ID3D12Device, min: u64, max: u64, what: &str) -> Option<Self> {
+        Self::try_make_l0_with_cap(dev, min, max, what, two_pass_l0_cap())
+    }
+
+    unsafe fn try_make_l0_with_cap(dev: &ID3D12Device, min: u64, max: u64, what: &str, cap: u64) -> Option<Self> {
+        if cap == 0 || min > cap || L0_UNSUPPORTED.load(Ordering::Relaxed) {
+            return None;
+        }
+        let dev_key = dev.as_raw() as usize;
+        if let Some(b) = FREE_L0_RES.lock().unwrap().take(dev_key, min, max) {
+            note_two_pass(TP_REUSED);
+            return Some(b);
+        }
+        if !reserve(&TWO_PASS_L0_ALIVE, min, cap) {
+            reclaim_fenced();
+            if let Some(b) = FREE_L0_RES.lock().unwrap().take(dev_key, min, max) {
+                note_two_pass(TP_REUSED);
+                return Some(b);
+            }
+            if !reserve(&TWO_PASS_L0_ALIVE, min, cap) {
+                let gone = {
+                    let mut free = FREE_L0_RES.lock().unwrap();
+                    let over = TWO_PASS_L0_ALIVE.load(Ordering::Relaxed).saturating_add(min).saturating_sub(cap);
+                    free.take_room(over)
+                };
+                let made_room = gone.is_some();
+                drop(gone);
+                if !made_room || !reserve(&TWO_PASS_L0_ALIVE, min, cap) {
+                    return None;
+                }
+            }
+        }
+        let res = match uav_buffer_in_pool(dev, min, what, true) {
+            Ok(r) => r,
+            Err(e) => {
+                TWO_PASS_L0_ALIVE.fetch_sub(min, Ordering::Relaxed);
+                // Remember non-OOM adapter refusals so subsequent misses go straight to local wait.
+                if !e.contains("0x8007000E") && !e.contains("0x8007000e") {
+                    L0_UNSUPPORTED.store(true, Ordering::Relaxed);

Medium: L0_UNSUPPORTED is one process-wide flag, set for life on any error other than E_OUTOFMEMORY (device removed 0x887A0005, E_INVALIDARG, a null resource), with no log line, while E_OUTOFMEMORY is retried on every miss with no backoff. A device-removed or other transient error, or a refusal on one device (e.g. a WARP test device), turns spillover off silently and permanently for every device, including one recreated after a TDR. Meanwhile, with system memory exhausted, every two-pass draw that misses local calls CreateCommittedResource for a full-size L0 buffer, which fails each time before falling through to the local wait. Keeping the flag per device, logging it, and backing off on E_OUTOFMEMORY would avoid both.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772466286 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#discussion_r4772466286). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T16:03:42Z. **Code review location:** `crates/xcl/src/hle/d3d12x/bind.rs`; line 311 ~~~~diff @@ -244,7 +263,58 @@ impl TwoPassBuf { } }; note_two_pass(TP_MADE); - Ok(Some(TwoPassBuf { res, bytes, dev: dev.as_raw() as usize })) + Ok(Some(TwoPassBuf { res, bytes, dev: dev.as_raw() as usize, is_l0: false })) + } + + /// Spillover allocation in `D3D12_MEMORY_POOL_L0` (system memory) when local VRAM + /// `two_pass_cap` is exhausted. Returns `None` if disabled, at `cap`, or if the adapter + /// rejects custom L0 UAV buffers. + #[cfg(test)] + unsafe fn try_make_l0(dev: &ID3D12Device, min: u64, max: u64, what: &str) -> Option<Self> { + Self::try_make_l0_with_cap(dev, min, max, what, two_pass_l0_cap()) + } + + unsafe fn try_make_l0_with_cap(dev: &ID3D12Device, min: u64, max: u64, what: &str, cap: u64) -> Option<Self> { + if cap == 0 || min > cap || L0_UNSUPPORTED.load(Ordering::Relaxed) { + return None; + } + let dev_key = dev.as_raw() as usize; + if let Some(b) = FREE_L0_RES.lock().unwrap().take(dev_key, min, max) { + note_two_pass(TP_REUSED); + return Some(b); + } + if !reserve(&TWO_PASS_L0_ALIVE, min, cap) { + reclaim_fenced(); + if let Some(b) = FREE_L0_RES.lock().unwrap().take(dev_key, min, max) { + note_two_pass(TP_REUSED); + return Some(b); + } + if !reserve(&TWO_PASS_L0_ALIVE, min, cap) { + let gone = { + let mut free = FREE_L0_RES.lock().unwrap(); + let over = TWO_PASS_L0_ALIVE.load(Ordering::Relaxed).saturating_add(min).saturating_sub(cap); + free.take_room(over) + }; + let made_room = gone.is_some(); + drop(gone); + if !made_room || !reserve(&TWO_PASS_L0_ALIVE, min, cap) { + return None; + } + } + } + let res = match uav_buffer_in_pool(dev, min, what, true) { + Ok(r) => r, + Err(e) => { + TWO_PASS_L0_ALIVE.fetch_sub(min, Ordering::Relaxed); + // Remember non-OOM adapter refusals so subsequent misses go straight to local wait. + if !e.contains("0x8007000E") && !e.contains("0x8007000e") { + L0_UNSUPPORTED.store(true, Ordering::Relaxed); ~~~~ --- **Medium**: L0_UNSUPPORTED is one process-wide flag, set for life on any error other than E_OUTOFMEMORY (device removed 0x887A0005, E_INVALIDARG, a null resource), with no log line, while E_OUTOFMEMORY is retried on every miss with no backoff. A device-removed or other transient error, or a refusal on one device (e.g. a WARP test device), turns spillover off silently and permanently for every device, including one recreated after a TDR. Meanwhile, with system memory exhausted, every two-pass draw that misses local calls CreateCommittedResource for a full-size L0 buffer, which fails each time before falling through to the local wait. Keeping the flag per device, logging it, and backing off on E_OUTOFMEMORY would avoid both.
bmjask commented 2026-12-02 16:03:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:03:42Z.

Code review location: crates/xcl/src/hle/d3d12x/bind.rs; line 3114

@@ -2977,6 +3100,29 @@ unsafe fn try_ensure_res_buffer_exact_with_cap(this: *mut c_void, need_bytes: u6
     Ok(Some(install_res_buffer(this, entry)))
 }
 
+/// Acquire a two-pass record buffer: try full-size local VRAM first (no shrink, no wait); when
+/// the local cap is full and L0 spillover is enabled, spill the full-size buffer to L0; if L0 is
+/// also full or unsupported, fall back to the original local `FENCE_WAIT_LIMIT` wait + shrink path.
+unsafe fn acquire_res_buf_or_l0(
+    dev: &ID3D12Device,
+    need: u64,
+    min_fit_bytes: u64,
+    existing_cap: u64,
+    budget_cap: u64,
+    l0_cap: u64,
+) -> Result<Option<TwoPassBuf>, String> {
+    let try_l0 = l0_cap > 0 && !L0_UNSUPPORTED.load(Ordering::Relaxed);

Medium: Not certain about this one: nothing checks whether the adapter is UMA (D3D12_FEATURE_ARCHITECTURE). On UMA adapters MEMORY_POOL_L0 is the same physical memory as DEFAULT, so the spill just sidesteps the cap, and two_pass_cap's non_tp (~368) subtracts only TP_ALIVE, so L0 bytes count as non-two-pass usage and shrink the dynamic cap. On an iGPU/APU (or vkd3d-proton UMA), once the local cap is hit, up to another 512 MiB of two-pass buffers lands in the same memory. DXGI used grows, budget_two_pass_cap returns a smaller cap, and that causes more misses, more L0 spill and more refusals, a feedback loop past what XCL_TWO_PASS_MB was meant to bound. Disabling the spill on UMA adapters (and subtracting L0 bytes in non_tp) would avoid it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772466299 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#discussion_r4772466299). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T16:03:42Z. **Code review location:** `crates/xcl/src/hle/d3d12x/bind.rs`; line 3114 ~~~~diff @@ -2977,6 +3100,29 @@ unsafe fn try_ensure_res_buffer_exact_with_cap(this: *mut c_void, need_bytes: u6 Ok(Some(install_res_buffer(this, entry))) } +/// Acquire a two-pass record buffer: try full-size local VRAM first (no shrink, no wait); when +/// the local cap is full and L0 spillover is enabled, spill the full-size buffer to L0; if L0 is +/// also full or unsupported, fall back to the original local `FENCE_WAIT_LIMIT` wait + shrink path. +unsafe fn acquire_res_buf_or_l0( + dev: &ID3D12Device, + need: u64, + min_fit_bytes: u64, + existing_cap: u64, + budget_cap: u64, + l0_cap: u64, +) -> Result<Option<TwoPassBuf>, String> { + let try_l0 = l0_cap > 0 && !L0_UNSUPPORTED.load(Ordering::Relaxed); ~~~~ --- **Medium**: Not certain about this one: nothing checks whether the adapter is UMA (D3D12_FEATURE_ARCHITECTURE). On UMA adapters MEMORY_POOL_L0 is the same physical memory as DEFAULT, so the spill just sidesteps the cap, and `two_pass_cap`'s `non_tp` (~368) subtracts only TP_ALIVE, so L0 bytes count as non-two-pass usage and shrink the dynamic cap. On an iGPU/APU (or vkd3d-proton UMA), once the local cap is hit, up to another 512 MiB of two-pass buffers lands in the same memory. DXGI `used` grows, `budget_two_pass_cap` returns a smaller cap, and that causes more misses, more L0 spill and more refusals, a feedback loop past what XCL_TWO_PASS_MB was meant to bound. Disabling the spill on UMA adapters (and subtracting L0 bytes in `non_tp`) would avoid it.
bmjask commented 2026-12-02 16:03:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:03:42Z.

Review: COMMENTED


Review of 4179a5a5: 2 finding(s) (2 medium), most severe first.

  1. Medium crates/xcl/src/hle/d3d12x/bind.rs:311: L0_UNSUPPORTED is one process-wide flag, set for life on any error other than E_OUTOFMEMORY (device removed 0x887A0005, E_INVALIDARG, a null resource), with no log line, while E_OUTOFMEMORY is retried on every miss with no backoff. (inline)
  2. Medium crates/xcl/src/hle/d3d12x/bind.rs:3114: Not certain about this one: nothing checks whether the adapter is UMA (D3D12_FEATURE_ARCHITECTURE). (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6154498949 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#pullrequestreview-6154498949). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T16:03:42Z. **Review:** COMMENTED --- Review of `4179a5a5`: 2 finding(s) (2 medium), most severe first. 1. **Medium** `crates/xcl/src/hle/d3d12x/bind.rs:311`: L0_UNSUPPORTED is one process-wide flag, set for life on any error other than E_OUTOFMEMORY (device removed 0x887A0005, E_INVALIDARG, a null resource), with no log line, while E_OUTOFMEMORY is retried on every miss with no backoff. (inline) 2. **Medium** `crates/xcl/src/hle/d3d12x/bind.rs:3114`: Not certain about this one: nothing checks whether the adapter is UMA (D3D12_FEATURE_ARCHITECTURE). (inline) --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
bmjask commented 2026-12-02 16:03:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:03:47Z.


@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

<!-- greyfinch-sync:ivall/xcl:comment:7351378030 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3614#issuecomment-7351378030). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T16:03:47Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3614:upstream-pr/3614'
git switch 'upstream-pr/3614'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3614'
git switch 'upstream-pr/3614'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3614'
git switch 'upstream-pr/3614'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3614'
git switch 'main'
git merge --squash 'upstream-pr/3614'
git switch 'main'
git merge --ff-only 'upstream-pr/3614'
git switch 'main'
git merge 'upstream-pr/3614'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3614
No description provided.