Skip to content

D3D12.X: a dispatch waits for its pipeline at the submit, not in the bind - #2118

Draft
Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:fix/compute-bind-defer
Draft

Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:fix/compute-bind-defer

Conversation

@Royalflamejlh

Copy link
Copy Markdown
Contributor

A compute pipeline that is not built yet was waited for in SetPipelineState: the title's thread stood there, built it itself, and only then reached the next one. This moves that wait to ExecuteCommandLists, so the pipelines a frame binds are built together on the workers. From cold driver caches a retail title finished 70 long builds in the 236 s after its world start against 34 (1 run each, Linux). No dispatch is skipped that was not skipped before, and XCL_PSO_WAIT_MS still bounds the wait. Part of #505 and #1833; scheduling under #2088.

SetPipelineState binds what is there. A Dispatch, or an ExecuteIndirect that dispatches, whose pipeline is still being built ends the list's segment, as a mid-list Wait after a Write64 already does, and gets a closed segment of its own between that one and the next; a translated dispatch sets its own root signature, views and pipeline, so it can be recorded later than the calls around it. At the submit (and KickoffX) each such segment is reset and its call recorded through the wait the bind used to make.

What is in it

  • list_x.rs: try_split_for_wait's body becomes split(list, dispatch), which opens the next segment without waiting for the bound pipeline (also for a mid-list Wait); defer, deferred_segment, record_deferred. A title list's deferred segments record on an allocator of its own (own_alloc), because the title's may be recording another list by the submit; on_release does not release it while the GPU may still run from it (alloc_pool::in_flight; it is then never released).
  • wait_expired: the GPU-wait watchdog's clock stands while a bind or submit is held for a build. Without it a queue waiting for a value whose list stood in such a submit was released after 5 s (3 lines a run in an earlier form, 0 now).
  • bind.rs: dispatch and execute_indirect put the call off when its pipeline is unbuilt; where the list cannot be split (a bundle, no wrapper, no allocator, predication set, the segments used up) they wait where they are, as before. pass_arena: a list's segments share one argument arena (a 256 KiB block each filled the coherent window in an earlier form).
  • real.rs: cl_set_pipeline_state no longer waits; q_execute_command_lists and kickoff_x record a list's deferred segments first. SUBMIT_COMPILES: the lane a put-off call's build takes in compile_slots instead of a turn in BIG_COMPILES: together, each once its commit headroom is free (Shaders: size-based admission for big compute driver compiles #1774); programs of 4 MiB or more stay one at a time. Where the headroom does not come, record_deferred marks the next four put-off pipelines wanted as it goes (WANTED_AT_ONCE), the leave a title thread's own build has today.
  • title_list.rs: push_segment; can_split takes a count; 256 extra segments per recording (two for each put-off call) instead of 32. pso_async.rs: need_by_submit, want.
  • Tests: a_dispatch_with_a_pipeline_still_building_waits_at_the_submit (a build of 1.5 s that returns no pipeline): without the change the dispatch waits for the build; with it the list is three segments, Close returns with the build still running, record_deferred waits for it and counts the dispatch as skipped, and the three segments run on a queue. a_gpu_wait_does_not_expire_while_the_title_is_held_for_a_build.
  • Not in it: the console-list replay, Reset, ClearState, KickoffX's re-open of the list and CreateCommandList with a compute pipeline wait where they did.

Beside #2001, #1652, #889. #2001 also stops the bind waiting and waits at the first Dispatch instead, on the title's thread, with the build on a worker; #1652 bounds the bind's wait and skips; #889 sends compute pipelines to the workers when they are made, and one it has not reached by its first use is still waited for in the bind. None moves the wait to the submit. On #2001's head 1f1d681 this commit conflicts in pso_async.rs only; if it merges first I rebase onto it.

Tested

lib, two skipped other test binaries
main cbc296a 1093 passed, 3 failed, 26 ignored 53 passed, 3 failed, 20 ignored
c2096cf 1095 passed, 3 failed, 26 ignored 53 passed, 3 failed, 20 ignored
first #101 builds of 3 s or more finished after it their build-seconds per second of them on title threads most at once presents stop within queue.Wait timeouts dispatches skipped least memory available
without 96.2 s 34 1.56 21 4 1.8 s 0 0 13 GB of 34
with 74.3 s 70 5.01 10 8 23.8 s 0 0 7 GB of 36
  • Two earlier controls from the same state finished 36 and 33 such builds; four runs of earlier forms of this commit finished 73, 67, 76 and (stopped at 232 s) 59.
  • In all of these the presents then stop for the rest of the run while builds go on. Why the title stays stopped I have not found: with the change no thread of the title waits for a pipeline in the dumps at 200 s and 250 s. So this shows more builds finishing per second, and about 6 GB more memory at its worst, not a title past its world start.
  • Native Windows (NVIDIA GeForce RTX 5070 Ti 16 GB, driver 621.24, Ryzen 7 9800X3D, Windows 11 Pro 26300, rustc 1.99.1): only an earlier form, 66896c9 (without the lane, the watchdog clock, the four-wanted window and the last fixes). cargo test --workspace -- --test-threads=4 in debug: 1151 passed, 4 failed, 46 ignored, 25 lines print SKIPPED; the four are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0 to _3, which failed there on main 689f2db the same day. scripts/smoke.ps1: 1639 frames against main cbc296a's 1632, 60 60 60 on both, 0 removals, 0 crashes, peak commit 15786 MB against 15638 MB.

Regression run
Under Wine on Linux (RTX 4060 Ti; scripts/smoke.ps1 unchanged, run by PowerShell 7 with xcl.exe started through Wine: "peak commit" reads 0 MB there, exit: 0x89 is the wrapper ending Wine after XCL's own process ends, and RTX 4060 Ti 8GB is the name vkd3d-proton gives this 16 GB card).

main:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 4060 Ti 8GB
title: 1253b9d5
seconds: 60
exit: 0x89
frames shown: 1416 (PresentX 1416)
presents per 2 s (last 3): 60 50 35
device removals: 0
crashes: 0
peak commit: 0 MB

PR:

xcl-smoke v1
commit: c2096cf96655d7b2fd991734f2427a736733792c
gpu: NVIDIA GeForce RTX 4060 Ti 8GB
title: 1253b9d5
seconds: 60
exit: 0x89
frames shown: 1590 (PresentX 1590)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

  • c2096cf on Windows: the suite, the smoke pair and a title run there. The window of four is for a machine whose commit headroom does not come, and I have not run one.
  • A title run on main itself, or with D3D12.X: offload PSO builds, defer lazy compile-on-draw, and wire mmap ID3D12PipelineLibrary1 #2001 or D3D12.X: compute pipelines are built ahead of their first bind #889 merged in; AMD and Intel.
  • More than one run of the pair on the final code; peak commit (it reads 0 under Wine; the control's cgroup peaked at 25.0 GB, the changed run's was not read).
  • A run with XCL_PSO_WAIT_MS set (that the bound holds at the submit is from the code).
  • KickoffX with a put-off call; a title list released while its put-off calls are still on the GPU; a deferred call recorded with a built pipeline in a test (the test's build returns none).
  • A list with more than 128 put-off calls.

AI use

  • Claude Code (Claude Fable 5.2) wrote the change and the tests, made the runs and wrote this description; two further instances checked earlier versions of it against the logs and the code.

…bind

A compute pipeline that is not built yet was waited for at its bind: the
title's thread stood in SetPipelineState, built the pipeline itself, and
only then reached the next one. A title that binds many unbuilt compute
pipelines in one frame got them one after another.

SetPipelineState now binds what is there. A Dispatch, or an
ExecuteIndirect that dispatches, whose pipeline is still being built
ends the list's segment, as a mid-list Wait after a Write64 does, and
gets a closed segment of its own between that one and the next: a
translated dispatch sets everything it needs itself (root signature,
the six views, the pipeline), so it can be recorded later than the
calls around it. The title's threads go on recording, and the pipelines
the frame binds next reach the workers while this one is built. At
ExecuteCommandLists (and KickoffX) each such segment is reset and its
call recorded through the same wait the bind made (XCL_PSO_WAIT_MS
still bounds it): no dispatch is skipped that was not skipped before.

While a submit stands in that wait, the lists it carries and their
Write64 signals are not on the queue yet, and another queue's GPU wait
for one of them ran into the 5 s watchdog and was released on the CPU
(3 lines a run). The watchdog's clock now stands while a bind or submit
is held for a build.

A put-off pipeline goes before the workers' queue: behind a start-up
backlog the submit thread would build them itself, one after another,
where several title threads built at once before (a debug build on
Windows stopped presenting on its first screen that way).

The builds of put-off calls do not take turns among the big compiles:
a build that starts after its call was put off runs beside the others,
once the commit headroom it asks for is free. With them in the
one-at-a-time lane the change finished no more builds than before.

Where the headroom is not there (a 32 GB machine at the world start: the
gate's commit wait does not end), that alone would leave them waiting
until the submit reaches each. So the submit marks the next four of its
put-off pipelines wanted as it goes, which a build takes as leave to go
on without the headroom, as a title thread's own build does: about what
the title's threads had in the driver at once before.

The segments of a title list record on an allocator of that list's own,
because the title's may be recording another list by the submit; it is
not released while the GPU may still run from it. They share one
argument arena: a block each filled the coherent window.

A recording takes 256 extra segments (32 before), two for each such
call. Past that, on a list that cannot be split, and under predication
the call waits where it is, as before. The console-list replay, Reset,
ClearState and KickoffX's re-open wait where they did.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant