D3D12.X: the fence and CPU-write threads run at high priority #3321
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3321"
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 Prime1997 on 2026-11-29T08:03:36Z.
Requested by Prime
xcl-fenceswrites the completed values that title threads spin on, andxcl-cpu-writeswrites the values a GPU command list leaves for the CPU. At normal priority both can queue behind the very title threads that spin waiting for them. Both sleep nearly all the time, soTHREAD_PRIORITY_HIGHESTcosts the title little. Not time-critical: a fences wake can settle readbacks for up to 20 ms.What is in it
crates/xcl/src/hle/d3d12x/fence_x.rs:xcl-fencessetsTHREAD_PRIORITY_HIGHESTwhen it startscrates/xcl/src/hle/d3d12x/cpu_writes.rs:xcl-cpu-writesdoes the sameTested
cargo test --workspace --no-fail-fast -- --test-threads=4with the threeuma_drivertests below skipped, on4250334773: 2605 passed, 0 failed, 49 ignored (SKIPPED GPU tests: 28 lines: 21no wave64(this card runs wave32), 3 a wave32 per-lane form refused by the translator (#1426), 2no heap windows(opt-inXCL_HEAP_WINDOWS=1), 1no dxc.exe, 1cannot disable the driver cache(needs Windows Developer Mode))cargo test -p xcl --lib -- --test-threads=1 uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment uma_driver::tests::failed_restore_stops_before_importing_an_unbacked_window): 3 passed, 0 failed. They are left out of the whole run because on this PC's driver they can end the library test process (exit 0x7c10003, "coherent window could not be restored"), onmaintoocargo test -p xcl --lib -- --test-threads=4, same skips): 2466 passed, 0 failed; 2466 passed, 0 failedmainfa204595a4: 2605 passed, 0 failed, 49 ignored, 28SKIPPEDlines (own-prs-20261129 run, same command)scripts/smoke.ps1, no input, copied profile and shader cache): blocks belowRegression run
Not tested
AI use
Optional temporary Discord for coordinating contributor work, testing and comparing results.
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T08:08:14Z.
Confirmed both production workers select Windows priority +2 (HIGHEST) on
42503347, using GetThreadPriority inside each worker. A matched fresh-process control using the same binary with only the two SetThreadPriority calls bypassed read 0 (NORMAL) for both. RTX 5070 / driver 616.92, Ryzen 7 5700X3D.A bounded two-queue test distinguished the two publication paths. An ungated write on queue B first published 0xC3C3C3C3 and completed its receipt. Then I gated queue A, scheduled a deferred CPU write on A, scheduled a write to a different CPU cell on independent queue B, and signaled a B fence after B’s write-fence signal.
At both priorities, the native B fence and its XCL CPU-visible mirror reached 1 while A was gated. B's CPU-write receipt remained pending throughout a subsequent 100 ms observation, and the cells still held 0 and 0xC3C3C3C3. Releasing A completed both receipts; acquire loads then read 0xA1A1A1A1 and 0xB2B2B2B2.
This identifies a distinct limit when interpreting critical-path traces: a ready fence mirror can coexist with deferred CPU writes still queued behind another queue’s fence. Raising worker priority can affect runnable work, but this FIFO dependency survives the change. The 100 ms was an intentional observation window, not measured scheduler latency. The test used the production write scheduler and fence-mirror hook with native DIRECT queues. It did not exercise guest submit hooks, title CPU contention, or title frame time.
AI disclosure: OpenAI Codex built and ran the fixture and drafted this report.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T22:39:28Z.
Review: COMMENTED
Static review of
42503347for the stack in the #3041 comparison.I found no actionable issue in the tested fence and CPU-write worker priority changes.
Review assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T22:43:31Z.
Review: COMMENTED
Critical review of current head
42503347. I found no immediate correctness defect in settingTHREAD_PRIORITY_HIGHESTon the two sleeping completion workers; the work they wake for unblocks title threads. The remaining risk is scheduling under sustained wakeups:poll_fence_downloadsandtable().refresh()share the boosted fence worker, and neither call's duration is bounded here. Please report wake frequency and worst-case active time in a retail world, plus a before/after frame-time distribution. This is a nonblocking performance check. No local Windows run.Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T22:54:46Z.
Test run data for the static review
cargo build --release -p xclbuild4465c886included this PR in the Prime1997 stack. One warm-cache retail run (XCL_PREPARE_ALL=1,XCL_RUN_SECONDS=180) reached the first present in 12,326 s and showed 5,104 frames in the subsequent 180 s, with zero failed or fallback pipelines and no crash. This is combined-build coverage. It cannot isolate this PR's effect. Run report and comparison42503347, andrewDoing measured both production workers at Windows priority +2 and both matched controls at 0. Their two-queue fixture also showed that the deferred-write FIFO dependency persists at both priorities. Independent fixture runcargo build --workspacepassed on trial merged761fc59, applying the reviewed head tomainat5b0d5fa3. The test binaries built withcargo test --workspace --no-fail-fast --no-runand the GPU suite is queued.Local system used for these runs was an RTX 2070 SUPER 8 GB (621.40, wave32), Ryzen 5 3600XT, 32 GB RAM, Windows 11 build 26300, and rustc 1.100.1. Claude Code (Claude Opus 5.5) ran the earlier tests. Codex (GPT-6, exact variant unavailable) checked the artifacts and ran the new build.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:00:38Z.
Review (head
42503347, diff read, not a merge-check; draft, so not built or run):xcl-fencesbusy-waits at HIGHEST in one case. On each wake it runsrefresh(), and every cell'srefresh_one(fence_x.rs ~63) callssettle_readbacks_within(20), which loops onyield_nowfor up to 300 µs while copies back are pending (sparse.rs ~5034-5042) and while trying theSTATElock, for up to 20 ms per cell (~5607-5626). The thread wakes once per armed title Signal, so while readbacks are pending those loops now outrank the title's normal-priority threads, which matters most on 4-6 core CPUs.monitorx/mwaitx) rather than spinning on it.XCL_LOW_PRIORITY_WORKERS=0.pipeline_library/warm_librarytests (3 == 2 at pipeline_library.rs:414, then PoisonError), in files this PR doesn't touch; looks like the existing test race, so a rerun should do.Fine:
SetThreadPriority(GetCurrentThread(), ...)runs inside each spawned thread, as elsewhere in the crate,xcl-cpu-writesonly waits on an event and stores (no spin), and nothing is shared with #3336's workers.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 Foniass on 2026-12-01T16:25:59Z.
Test report (not a merge-check: draft)
base:
b2b1f109d2head:
4250334773merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2902 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3321#issuecomment-7300286351, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run.
assessment: merges, builds and passes the whole suite on current main (0 failed); the findings in my review stand
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written 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.