D3D12.X: a draw's two-pass buffer goes past the headroom cap, not skipped #3165
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3165"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-28T15:03:08Z.
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 inWait64BitValueX >= 0x713(wait-before-signal, producer queue 1) with 0 draws for the remaining 13 minutes and no device removal. WithXCL_TWO_PASS_MB=2048the 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 setXCL_TWO_PASS_MBis 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-devPRs that touch two-pass code (#2999, #3052, #3056, #3105, #3116, #3131, #3012, #2987) leave it as it is, andmain/amd-devhave no such cap.What is in it
crates/xcl/src/hle/d3d12x/bind.rs:env_two_pass_cap(the existingXCL_TWO_PASS_MBread, moved out oftwo_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).ac81767f(review, to be squashed): past the cap, the record buffer runs its existing bucket walk (acquire_res_buf_with_cap) at the ceiling with no fence wait, so a smaller usable buffer is taken before the draw is refused. Test:a_record_buffer_past_the_headroom_cap_shrinks_to_what_fits_under_the_ceiling.Tested
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 past_theatac81767f: 7 passed, 0 failed.cargo test --workspace -- --test-threads=4aborts on this card withCreateCommandQueue ... 0x8007000Eafter 4title_texturesfailures, identically on the base54225f58without this change;cargo test -p xcl --lib title_texturespasses 35/35 on both. So the whole-suite counts are not available from this machine.nvidia-devtree with #3039 + #2975 merged (16 heap windows,XCL_PREPARE=0, noXCL_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 #1989).Regression run
(
mainand this PR's head,XCL_PREPARE=0, otherwise plain settings; this title does not reach the cap without 16 windows. Themainblock replaces an earlier one whose build had failed, so that run used a stale binary. Peak commit varies between ~17 and ~37 GB from run to run here with the cache state.)Not tested
XCL_UMA_DRIVER=mixeddevice-hangs (0x887a0006) in the menus in about half the runs here, before any two-pass buffers; that is separate from this change.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T15:45:43Z.
On head
b2316919, the record-buffer ceiling retry can still refuse a draw when a smaller usable buffer fits. Both production callers ofrecords_forpass one record as the minimum. After the headroom-cap shrink attempts are exhausted,ensure_res_buffer_with_capcallsmake_two_pass_past_capwith 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.Could the record-buffer path reuse the existing bucket walk at the automatic ceiling with zero additional fence wait? The explicit
XCL_TWO_PASS_MBlimit 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.
Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-28T16:01:46Z.
@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 explicitXCL_TWO_PASS_MBkeep 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_pass38 passed, 0 failed (1 SKIPPED, no heap windows); a filtered run including the newa_record_buffer_past_the_headroom_cap_shrinks_to_what_fits_under_the_ceiling7 passed, 0 failed. That test exercises the walk at a ceiling it sets itself, so it does not by itself prove theensure_res_buffer_with_capwiring; no retail rerun yet.AI use: Claude Code (Claude Opus 5.5) wrote the change, the test and this reply, and ran the tests.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T16:15:54Z.
Retested the four admission boundaries at
ac81767fwith 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 thatensure_res_buffer_with_capnow 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.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T19:04:13Z.
I verified the ceiling retry through
records_foratac81767fon an RTX 5070, driver 616.92. The two intermediate requests returned actual 48 MiB and 32 MiB GPU buffers. Both carried the correct data through a two-pass indirect compute workload.Each row ran in a fresh process, with no reusable record buffer. I requested 64 MiB with a 47,632-byte minimum and batching enabled. A test-only memory query and the alive counter supplied a 12 GiB budget and 10 GiB of non-two-pass usage. Production cap calculation gave 512 MiB headroom and a 2,048 MiB ceiling. The fixture supplied the native device through the existing test-list GetDevice shim.
XCL_TWO_PASS_MB=512For each admission I checked the returned capacity and native resource width, then passed that same resource to the existing two-pass GPU test. It wrote and read records for six indirect commands, waited on a real fence and checked all 16 expected output words. All five cases passed. The budget inputs were synthetic and the workload touched a small portion of each allocation. This verifies caller wiring, allocation, GPU usability, and the hard-cap boundary. It does not measure residency under pressure or reproduce the retail queue stall.
AI use: OpenAI Codex adapted the native fixture, ran the controls and prepared this report.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-29T22:16:06Z.
A data point for why this is needed, from a 16 GB card that runs over its video memory budget. The binary in these runs is
main7a649b0emerged with #3304, release, without this PR.RTX 5070 Ti 16 GB (617.42), Ryzen 7 9800X3D, 32 GB, Windows 11 26300. The newer retail title, after a full shader preparation for this binary,
XCL_RAM_MB=12000 XCL_CS_PSO_WAIT_MS=200 XCL_UMA_DRIVER=mixed:1536:1792 XCL_TEXTURE_LEVEL_PAGES=1 XCL_PREPARE=0. The title enters the world at about 90 s and stays there until the run is closed.In the world the process holds 17.6 to 18.8 GB of local video memory against a budget of about 15.0 GB, so there is no headroom and the cap sits on its floor (budget / 32, about 470 MiB here) for the rest of the run.
XCL_TWO_PASS_MBThe counts are from the last
console code so farandtwo-pass bufferslog lines of each run.So with the cap left to itself, half to three quarters of the draws in the world are skipped here, and the title needs 1.1 to 1.3 GiB of two-pass buffers alive. On this card your ceiling works out to 2048 MiB, which would cover that.
On screen it changes nothing I can measure. In every run, with the cap unset or raised, the world frames are black (no pixel above 2 of 255 in the frame dumps) except for the title's button-prompt box, which shows in 1 to 3 of the 9 to 25 frames dumped in the world. The 3D scene behind it is black in all of them, so the skipped draws are not what keeps the scene black on this card. (Edited: this paragraph first said the prompts only appear with the cap raised. That was wrong; I had looked at every fifth frame.)
No device removal in any of these runs. Lowest free RAM was 1.1 GB with 3072 and 2.2 GB with 1536, against 2.0 to 2.4 GB with the cap unset, so the larger buffers cost RAM here (the video memory over the budget ends up in shared memory).
This PR, cap unset (edited in:
ac81767fmerged onto the same tree, same switches withoutXCL_TWO_PASS_MB, one run of 420 s):So the PR does what it says here: no draw is skipped and nothing is refused. But on this card most draws do not get their preferred record buffer past the cap.
ensure_res_buffer_with_capgoes to the ceiling only afteracquire_res_buf_with_caphas waited and walked the smaller buckets under the headroom cap, and after the list's existing smaller buffer has been tried, so whenever a smaller bucket fits under the cap the draw takes it, and the clamp then drops the groups that have no record. That fits 637 MiB alive at a 465 MiB cap where the title uses 1.1 to 1.3 GiB when the cap is raised by hand, and 5.5 M groups dropped against 25 to 82 thousand. Trying the preferred size under the ceiling before shrinking would keep those groups on a card that sits on the floor cap.The groups-dropped figures of the base and of this PR cannot be compared directly: a skipped draw loses all its groups and none of them are counted there.
Not tested: more than one run per setting for 1536, 3072 and this PR. All these runs had the default UMA layout (the log says 0 view windows), so the title's two-pass demand with
XCL_UMA_WINDOWS=16is not measured here. The picture is the same black scene in all of them, for a reason that is not this cap (the G-buffer targets are empty in a target dump although their draws ran).AI use: Claude Code (Claude Fable 5.2) set up the runs, counted from the logs and frame dumps, and wrote this; Claude Opus 5.5 read
bind.rsfor the order of the wait, the shrink and the ceiling, and I checked it in the source.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:39:31Z.
Triage (#1607) – head
ac81767No open or merged PR does this. It builds on the headroom cap from the merged #2817 (
budget_two_pass_cap) and lets a draw's record buffer or argument scratch go past that cap, up todraw_two_pass_ceiling, instead of skipping the draw.XCL_TWO_PASS_MBstill caps the buffers as before. #3555 only documentsXCL_TWO_PASS_MBin the README.No problems found in the diff (bind.rs
make_two_pass_past_cap_with,ensure_res_buffer_with_cap,scratch_args). The two commits could be squashed into one.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:52:47Z.
Review (head
ac81767f, diff read, not a merge-check; draft):bind.rs~2630, then ~2640), so the preferred record size is almost never made past the cap. A tester's run on the PR shows it: 5.5 M mesh groups still dropped, against 25-82 thousand with the cap raised by hand.make_two_pass_past_cap_withcallsreal::video_memory()directly (~339), which makes a DXGI factory each time, instead oftwo_pass_cap's 250 ms cache.min(budget / 4, 2 GiB)(~315) can be allocated when VRAM is already over budget, and it spills into system RAM; the tester saw free RAM drop to 1.1 GB with a 3072 MiB cap. With the live count above the cap, the capped callers (pools, batches) keep being refused.ensure_res_buffer_with_cap) nor the argument scratch (scratch_args) is tested, only the helpers. The refusal log (~253) still blamesXCL_TWO_PASS_MBwhile printing the new ceiling.Fine: growth is bounded by the ceiling and counted as before, a failed allocation returns an error and the draw is skipped, and a set
XCL_TWO_PASS_MBstays a hard cap. Going over the cap rather than skipping is the better trade when a skipped draw can hang the title.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.