D3D12.X: bound scratch for sliced indirect mesh draws #3681
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3681"
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 jeroenhaentjens on 2026-12-02T08:53:30Z.
What & Why
On main a cold two-pass mesh ExecuteIndirect can ask for 32 MiB of records. A recording with space for the whole record buffer and its rewritten arguments keeps one compute and mesh pass pair per command. Under scratch pressure, a 2 MiB buffer covers the same group range across slices and limits the record allocation.
What is in it
Tested
af49d4a815. Intel Core i7-9750H, NVIDIA Quadro RTX 3000 (driver 597.06 / 32.0.15.9706), Windows 11 25H2 build 26200.9974, Rust MSVC 1.100.0 and DXC 1.9.2609.5.Regression run
Both 60-second runs used the same installed retail title, seeded profile, input schedule (15:A,35:A,55:A), device settings and shader cache. Each capture recorded zero two-pass mesh ExecuteIndirect log entries. These captures cover startup and presentation.
Baseline (current origin/main)
PR head
Not tested
A retail scene that exercises mesh ExecuteIndirect during the measured interval, AMD, Intel discrete GPUs, and Linux.
AI use
OpenAI Codex (GPT-6, specific revision unavailable) assisted with the implementation, tests and PR update.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:04:38Z.
Review (head
bc9f4ebf, diff read, not a merge-check; checks red):dispatch_chain.rs); the empty-BVH fallback (real.rs~3311); new stats and diagnostic logs; and copying indirect arguments and counts from PC buffers outside the memory windows into scratch. The last is in neither the description nor the commit messages:RewriteInput::Pc,indirect_pc_sourceandrecord_indirect_pc_copyinbind.rs, plus anote_indirect_source_barriershook every titleResourceBarriernow goes through (list_x.rs~6489). It overlaps draft #3105, which stages only UPLOAD-heap sources on purpose; this also stages DEFAULT-heap buffers whose state it assumes isCOMMON. A natural split: the BVH fallback; the wait budgets; the PC staging (or #3105); the mesh slicing; the stats.ExecuteIndirectnow records far more passes and barriers by default.sliceddepends only ontp.kind == "MS"(bind.rs~4028), andtotal_capis always the old 32 MiB group limit even when feedback gave a hint, soslices = total_cap / cap(~4036-4038) ignores it: the PR's own 47,632-byte record gives 16 slices cold and 32 with a 10-group hint, wheremainhad 1. Each command records up to 32 compute + mesh pairs, each followed by a UAV barrier (Records::Whole), most with zero groups. Not opt-in, and the smoke run is "pending".XCL_CS_PSO_WAIT_MSon pinned and retained compute pipelines conflicts with #3318.resolve_for_indirect(pso_async.rs~11604),ResolveMode::Wait(~12396) andresolve_retained_for_emission(~12489) now passcs_wait_budget(); draft #3318 changes the same functions and deliberately leaves the compute budget off these paths after measuring ~300 left-out compute passes a session and a device hang with it on.XCL_CS_PSO_WAIT_MSchanges more than described.waits_bounded()now returnscompute_wait_budget().is_some()(~11175), so direct dispatches whose pipeline is still building are no longer deferred to the submit (list_x.rsdefer_pipeline_wait) but wait on the title thread, andwhole_readynow blocks for up to the compute budget instead of skipping at once.gpu_empty_bvh_in_uma_returns_a_misschecksbvh::alloc_empty's structure, the same dataempty_bvh()already wrote onmain; the new decision indev_create_srv_inner(~3311), a non-null VA outside UMA getting the shared empty BVH instead of a zero descriptor on the default path, has no test.Fine: the
SCALE_ARGS_HLSLslice layout matches the recorded steps; the console-buffer offsets for arguments and count are overflow-checked;WholeRequestwakes waiters on every exit path throughWholeSentGuard. Thexcl-smokeblocks are owed (the reasonPR descriptionis red).AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-02T14:01:39Z.
The duplicate empty-BVH commit has been removed. I addressed the feedback on mesh slice counts and pinned/retained compute waits, and dropped the PC staging and extra diagnostics. The description includes both 60-second smoke runs and the workspace-test abort reproduced on main.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T14:07:27Z.
Follow-up review (head
77a7d262, sincebc9f4ebf, diff read, not a merge-check):dispatch_chain.rschanges are gone (now 243+/56-), but the meshExecuteIndirectslicing (bind.rs) and the retained graphics wait budgets (pso_async.rs) are still two unrelated changes, plus undescribed overflow-checked console-buffer offsets (bind.rs~3659); the title still says "split PSO waits".ExecuteIndirectalways sliced, ignoring the feedback hint: partly fixed. With a hintcapnow equalstotal_groups, so a warm draw takes one pass pair (~3758-3768), but cold draws, and any pipeline without a feedback slot (fb_slot == 0), still gettotal_cap / capslices with a UAV barrier after every pass: 16 for the PR's 47,632-byte record, more for records just over 1 MiB.XCL_CS_PSO_WAIT_MSon pinned / retained paths: partly fixed. The compute budget is nowNonethere (~11607, ~12374, ~12467), but the graphics half of those changes is what draft #3318 already does on the same functions, so the two duplicate and conflict; one should be dropped.waits_bounded()changing direct-dispatch deferral: still open, now through the graphics budget.waits_bounded()returnsgfx_wait_budget().or_else(wait_budget).is_some()(~11151), so with onlyXCL_GFX_PSO_WAIT_MSset a directDispatchor dispatchingExecuteIndirectwhose compute pipeline is still building is no longer put off to the submit (list_x.rsdefer_retained~4381) and waits on the title thread with no bound, since compute still uses the unsetXCL_PSO_WAIT_MS. The new test asserts it (~6384) and the description does not mention it; the PR's smoke run setXCL_GFX_PSO_WAIT_MS=500.New:
prepare_scaled_argsnow writes2 · max · stride · slicesbytes (~3355) into the recording's 16 MiB argument scratch (SCRATCH_CAP, ~3235), so a cold draw uses the budget up to 16× faster than onmain, and once it runs out later two-passExecuteIndirects in the recording are skipped.scale_args_slicedcovers the shader's output layout, but nothing covers whatexecute_indirect_snapshotrecords (the per-slice stagestages[k % slices]~3791, the mesh arguments atat + commands · slices~3800, thesliced/total_capchoice);gpu_two_pass_recordsdrives its own one-command plan.Fine: the
SCALE_ARGS_HLSLslice layout matches the recorded steps and the unsliced form still works through the bit-31 flag; each compute slice getsgroup_base = slice · capas the direct mesh slicing does; the feedback overflow is measured againsttotal_cap.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-02T23:26:42Z.
@Foniass I removed the PSO wait changes and updated the PR scope. Immediate sliced draws now reuse the same argument scratch. The new GPU test calls execute_indirect_snapshot and checks the recorded slice group bases and offsets.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:34:11Z.
Follow-up review of
b0819749, since77a7d262(code reading only, not a merge-check) · 1 high, 1 medium, 2 nitsIn short: Since
77a7d262the two commits were folded into one, and the PR now covers only the sliced meshExecuteIndirectinbind.rs. The graphics wait budgets, thewaits_bounded()change and their README text are gone. Sliced draws reuse one argument block, and a new test records the sliced path throughexecute_indirect_snapshot. One problem blocks it: the new test panics instead of skipping without the D3D12 Debug Layer. Cold draws still get 16 pass pairs per command, and that cost is unmeasured.High
The new test fails instead of skipping without the D3D12 Debug Layer.
execute_indirect_snapshot_records_sliced_arguments_and_reuses_scratchcallsenable_debug_layer().as_ref().expect("D3D12 Debug Layer")(bind.rs~9048) before it checks for an adapter. Later it callsdev.cast::<ID3D12InfoQueue>().expect(...)(~9094).D3D12GetDebugInterfacefails, so the test panics on an ordinary GPU PC with DXC.mainrequires the debug layer; it is used only whenXCL_D3D12_DEBUGis set.Fix:
skip_test("no D3D12 Debug Layer")and return when either call fails, or count the messages only when the layer is present.Medium
Cold mesh
ExecuteIndirectstill records 16 pass pairs per command (still open).INDIRECT_INITIAL_RECORDS, ~2622), while its total stays at the old 32 MiB group limit. For the 47,632-byte record that is 44 groups per slice out of 704, so 16 slices (~3779-3790).ExecuteIndirects, each with a UAV barrier, wheremainrecords one pair. Slices past a command's groups still run with zero groups.Fix: measure what the 2 MiB cold buffer saves against the extra passes, or keep the cold buffer whole when the budget has room and slice only when it is shrunk.
Nit
main. "Keep cold two-pass indirect mesh draws within the existing per-recording argument scratch budget" describes a problem the slicing itself creates. Againstmain, cold MS draws drop from 32 MiB to 2 MiB of records and are sliced. WithXCL_TWO_PASS_BATCH=2, cold MS draws are no longer deferred (~2575). The commit has no body.gpu_two_pass_indirect_commands_keep_their_own_records(~8993) was rewritten to userunner::device()and a debug-layer child process, which is unrelated to the sliced path. Both belong in their own PRs.Checked and fine
waits_bounded()deferral change, andXCL_CS_PSO_WAIT_MSon pinned and retained paths. The BVH test went to #3688.sliced_scratch,scratch_args~3232) at offset 0. It goes COMMON → UAV → INDIRECT_ARGUMENT → COMMON for each draw (~3839), so the next rewrite is ordered after the previous draw's reads.resetandprepare_splitclear it, and it counts towardscratch_taken.SCALE_ARGS_HLSL's slice layout matches the host offsets. Each compute slice getsIO_MESH_GROUP_BASE = slice·cap. Unsliced callers keep the old ten-dword layout.max_sliceskeepscommands·slices·2withinSCRATCH_CAP, andprepare_scaled_argschecks it again (~3371). The feedback overflow is measured againsttotal_cap.raw_nlines inSCALE_ARGS_HLSL, so expect a textual conflict.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-03T07:25:39Z.
@Foniass The sliced recording fixture now skips when the D3D12 Debug Layer or its info queue is unavailable. The unrelated buffer-offset and existing fixture changes are out of the diff. The commit and description explain the 32 MiB to 2 MiB cold record change, its extra pass pairs, and why cold draws record immediately in batch mode 2. The targeted checks and the fresh 60-second head smoke are recorded above.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T07:27:19Z.
Follow-up review of
61408de0, sinceb0819749(code reading only, not a merge-check) · 1 mediumIn short: This push fixes the blocking test point and narrows the commit. The new GPU test now skips when the D3D12 Debug Layer or info queue is missing. The overflow-checked offsets and the unrelated rewrite of
gpu_two_pass_indirect_commands_keep_their_own_recordsare gone. The commit message and the description now say what changes againstmain, including the cold pass-pair cost. That cost is stated but still not measured.Medium
ExecuteIndirectstill records up to 16 pass pairs per command, unmeasured (still open). The description now says so: a cold draw starts at 2 MiB of records and is sliced across the old group limit, up to 16 compute and mesh pairs per command for the 47,632-byte record, and a pipeline with no feedback slot keeps that cost. Not tested says the smoke run neither isolates the cost nor confirms it reaches this path. A frame-time comparison on a scene with cold meshExecuteIndirectdraws would settle it. Otherwise keep the cold buffer whole when the budget has room, and slice only when it is shrunk.Checked and fine
execute_indirect_snapshot_records_sliced_arguments_and_reuses_scratchreturns throughskip_test("no D3D12 Debug Layer")whenenable_debug_layer()fails or the device has noID3D12InfoQueue.execute_indirect_snapshotis back tomain's, and so is the rewritten two-pass record test.main, including that cold MS draws are not deferred withXCL_TWO_PASS_BATCH=2. The description says the same.b0819749.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-03T15:16:22Z.
@Foniass A cold indirect mesh command now keeps one compute and mesh pair when the full record buffer and its rewritten arguments fit. It uses the 2 MiB slice path under scratch pressure. The native recording tests cover both budgets and verify the pass sequence and slice scratch reuse. The test and smoke results are recorded in the PR.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T15:19:05Z.
Follow-up review of
af49d4a8, since61408de0(code reading only, not a merge-check) · 2 mediumIn short: This push answers the open point. A cold mesh
ExecuteIndirectnow first tries a whole record buffer, which keeps one compute and mesh pass pair per command. It falls back to the 2 MiB slices only when the exact buffer does not fit the budget without waiting. The fixture covers both budgets. Two evidence gaps remain: Tested lists only named tests, and the regression run is the repository's test fixture, which does not reach this code.Medium
hle::d3d12x::bind::tests, with--test-threads=1. CONTRIBUTING.md asks forcargo test --workspace -- --test-threads=4on the head under review, with its counts and SKIPPED tests.ExecuteIndirect. Both smoke blocks are ofxcl-owned-test-fixture, which shows 1 frame (presents per 2 s: 0 0 0). This PR changes how every cold meshExecuteIndirectgets its record scratch, on every adapter. CONTRIBUTING.md asks for the regression run on a real title. Add a pair of runs, onmainand onaf49d4a8, on a title that issues meshExecuteIndirectdraws.Checked and fine
Earlier finding fixed: cold draws always recorded up to 16 pass pairs per command.
execute_indirect_snapshotaskstry_ensure_res_buffer_exact_with_capfor the full record buffer. The cap is the budget minus whatcold_indirect_record_budgetleaves for the rewritten arguments.Nonedoes it take the sliced 2 MiB path.cold_indirect_record_budgetreserves the right amount.commandsis alreadymax * byte_stridebytes, and the unsliced path writescommands * slices * 2bytes withslices = 1. The function matchesscratch_args: it checks the open block's free bytes first, then a new block of at leastSCRATCH_BLOCKwithinSCRATCH_CAP. Its unit test covers the edge atSCRATCH_CAP - SCRATCH_BLOCK.The fixture now runs as two child processes, with
XCL_TWO_PASS_MBat 96 and at 4:Both also check for zero Debug Layer messages. The
INDIRECT_MESH_CALLShook now records unsliced draws too, which the whole-buffer case needs.The
defer_execute_indirectcomment now matches what it does: cold MS draws still record immediately.Written by Claude Code (Claude Opus 5.5) and 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.