Skip to content

D3D12.X: a draw's two-pass buffer goes past the headroom cap, not skipped - #3165

Draft
Anon64 wants to merge 2 commits into
xcl-dev:nvidia-devfrom
Anon64:fix/two-pass-draws-past-headroom
Draft

Anon64 wants to merge 2 commits into
xcl-dev:nvidia-devfrom
Anon64:fix/two-pass-draws-past-headroom

Conversation

@Anon64

@Anon64 Anon64 commented Nov 28, 2026

Copy link
Copy Markdown

When the two-pass buffers alive reach the headroom cap (25 % of local budget headroom, clamped), the record buffer and the argument scratch are refused and the draw that asked is skipped. A title whose later queue waits depend on that draw never wakes. On a 12 GB RTX 3060 (16 heap windows, XCL_PREPARE=0), a retail title skipped its first two-pass ExecuteIndirect at a 340 MiB cap. A second later five queues sat in Wait64BitValueX >= 0x713 (wait-before-signal, producer queue 1) with 0 draws for the remaining 13 minutes and no device removal. With XCL_TWO_PASS_MB=2048 the same run played on, with 794 MiB of two-pass buffers alive, and lit its G-buffer (#1989).

Those two paths now make the buffer up to the budget ceiling the cap is already clamped to (min(local budget / 4, 2048 MiB), 1024 MiB with no budget), and skip the draw only past that. A set XCL_TWO_PASS_MB is kept as a hard cap. Pools, batches and the other callers still stop at the headroom cap: they have their own fallbacks.

Builds on #2817's headroom cap (its wait and shrink run first). No open or merged PR changes the refusal: the open nvidia-dev PRs that touch two-pass code (#2999, #3052, #3056, #3105, #3116, #3131, #3012, #2987) leave it as it is, and main / amd-dev have no such cap.

What is in it

  • crates/xcl/src/hle/d3d12x/bind.rs: env_two_pass_cap (the existing XCL_TWO_PASS_MB read, moved out of two_pass_cap), draw_two_pass_ceiling, make_two_pass_past_cap; the record-buffer (ensure_res_buffer_with_cap) and argument-scratch refusals go through it. Two tests: the ceiling arithmetic, and a buffer the headroom cap refuses being made past it (WARP device).

Tested

  • RTX 3060 12 GB (driver 581.80), i9-14900KF, 64 GB RAM, Windows 11 26200, Rust stable MSVC, debug tests / release smoke. XCL_ADAPTER=3060 (the machine also has a GTX 960).
  • cargo test -p xcl --lib two_pass: 38 passed, 0 failed (1 SKIPPED: two_pass_binds_set_the_shared_view_heap, no heap windows); cargo test -p xcl --lib headroom_cap: 1 passed.
  • cargo test --workspace -- --test-threads=4 aborts on this card with CreateCommandQueue ... 0x8007000E after 4 title_textures failures, identically on the base 54225f58 without this change; cargo test -p xcl --lib title_textures passes 35/35 on both. So the whole-suite counts are not available from this machine.
  • This commit cherry-picked onto a local nvidia-dev tree with D3D12.X: XCL_TEXTURE_SYSMEM puts streamed texture levels in system memory #3039 + D3D12.X: empty shader slots keep a two-pass mesh pipeline's cache key #2975 merged (16 heap windows, XCL_PREPARE=0, no XCL_TWO_PASS_MB): at 91 s the record buffer (32 MiB) and argument scratch went past the 351 MiB headroom cap ("goes past the ... headroom cap" lines), 0 draws skipped, in play at 718 s with ~10 000 draws per 2 s; in-play G-buffer targets 0/1/3 at 52 / 59 / 43 % non-black (frame 1762). The 900 s run ended cleanly: exit 0x0, 2 471 frames, 0 device removals, 0 crashes, peak commit 40.1 GB. Without the change the same setup froze at ~102 s (see D3D12.X: add depth+UAV color twins, format-aliased placed texture copies, and dual-twin UAV barriers #1989).

Regression run
(plain settings; this title does not reach the cap without 16 windows)

xcl-smoke v1
commit: 54225f5884a94cd23b7aab3f703a7c975070aa77
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 300
exit: 0x0
frames shown: 8859 (PresentX 8859)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18535 MB
xcl-smoke v1
commit: b2316919e20503c688c631055e601654992987d6
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 300
exit: 0x0
frames shown: 8873 (PresentX 8873)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17150 MB

Not tested

  • The whole suite to completion (aborts on the base too, above).
  • The 16-window setup without XCL_UMA_DRIVER=mixed device-hangs (0x887a0006) in the menus in about half the runs here, before any two-pass buffers; that is separate from this change.
  • AMD, other NVIDIA cards, cards under 12 GB (where the ceiling is lower).

AI use

  • Claude Code, Claude Opus 5.5: found the deadlock in the run logs, wrote the change, the tests and this description, and ran the tests and smoke runs.

🤖 Generated with Claude Code

…pped

The two-pass record buffer and argument scratch are refused once the
buffers alive reach the headroom cap (25 % of local budget headroom,
clamped), and the draw that asked is skipped. A title whose later queue
waits depend on that draw then never wakes: a retail title on a 12 GB
RTX 3060 (16 heap windows) skipped its first two-pass ExecuteIndirect at
a 340 MiB cap and, a second later, five queues sat in Wait64BitValueX on
a value the skipped work would have written, with 0 draws for the
remaining 13 minutes. With XCL_TWO_PASS_MB=2048 the same run played on
with 794 MiB of two-pass buffers alive and lit its G-buffer.

Those two paths now make the buffer up to the budget ceiling the cap is
clamped to (min(local budget / 4, 2048 MiB), 1024 MiB with no budget)
and skip the draw only past that. An XCL_TWO_PASS_MB cap is kept as it
is. Pools, batches and the other callers still stop at the headroom cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andrewDoing

Copy link
Copy Markdown

On head b2316919, the record-buffer ceiling retry can still refuse a draw when a smaller usable buffer fits. Both production callers of records_for pass one record as the minimum. After the headroom-cap shrink attempts are exhausted, ensure_res_buffer_with_cap calls make_two_pass_past_cap with the full preferred size.

I ran a deterministic CPU fixture using this head's cap arithmetic, atomic reservation, bucket rounding and acquire_res_buf_with_cap. I modeled a 12 GiB DXGI budget and 10 GiB of non-two-pass usage, giving a 512 MiB headroom cap and a 2,048 MiB ceiling. The request preferred 64 MiB, with one 47,632-byte record as its minimum (rounded to 256 KiB). The fixture supplied no current or reusable buffer, disabled waiting and modeled successful device allocation after admission.

Two-pass memory alive Current ceiling retry Existing shrink logic retried at ceiling
1,984 MiB 64 MiB 64 MiB
2,000 MiB Refused 48 MiB
2,016 MiB Refused 32 MiB
2,048 MiB Refused Refused

Could the record-buffer path reuse the existing bucket walk at the automatic ceiling with zero additional fence wait? The explicit XCL_TWO_PASS_MB limit and argument-scratch allocation can retain their current behavior. These controls establish the admission decision only. GPU allocation success and retail incidence remain unverified.

AI use: OpenAI Codex prepared and ran the CPU fixture, checked the production callers and wrote this report.

…ets at the ceiling

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Anon64

Anon64 commented Nov 28, 2026

Copy link
Copy Markdown
Author

@andrewDoing thanks, you're right. Pushed ac81767f: past the headroom cap, the record buffer now runs the same bucket walk (acquire_res_buf_with_cap) at the ceiling, with no fence wait, instead of only trying the preferred size. The argument scratch and an explicit XCL_TWO_PASS_MB keep their behaviour. It is a separate commit for now and will be squashed into the first before review.

Tested on an RTX 3060 12 GB: cargo test -p xcl --lib two_pass 38 passed, 0 failed (1 SKIPPED, no heap windows); a filtered run including the new a_record_buffer_past_the_headroom_cap_shrinks_to_what_fits_under_the_ceiling 7 passed, 0 failed. That test exercises the walk at a ceiling it sets itself, so it does not by itself prove the ensure_res_buffer_with_cap wiring; no retail rerun yet.

AI use: Claude Code (Claude Opus 5.5) wrote the change, the test and this reply, and ran the tests.

@andrewDoing

Copy link
Copy Markdown

Retested the four admission boundaries at ac81767f with the same 64 MiB request and 47,632-byte single-record minimum. At 1,984 / 2,000 / 2,016 / 2,048 MiB alive under a 2,048 MiB ceiling, the revised bucket walk admitted 64 / 48 / 32 MiB / refused, respectively. I also checked that ensure_res_buffer_with_cap now passes its actual minimum and existing capacity to that walk with a zero fence wait. This was a CPU admission test with modeled allocation success, plus inspection of the caller. It did not exercise GPU allocation or retail behavior.

AI use: OpenAI Codex ran the controls and prepared this follow-up.

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.

2 participants