Skip to content

D3D12.X: recycle driver timing slots after thread exit - #3107

Draft
Prime1997 wants to merge 1 commit into
xcl-dev:mainfrom
Prime1997:codex/nvidia-driver-timing-slots
Draft

Prime1997 wants to merge 1 commit into
xcl-dev:mainfrom
Prime1997:codex/nvidia-driver-timing-slots

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Driver-call timing now releases its slot when a thread exits. The NVIDIA branch previously assigned 64 slots over the entire process lifetime, so later threads silently lost timing and the full-suite timing assertion failed.

Rebased onto main (2026-11-28). nvidia-dev was merged into main by #3203, so this PR now targets main and its branch was rebased onto main 765b2c5bfff6754e8c9886a73e188a86aca3c64c: head c08bd75d4e246a223baef36e3c2c40313514dfa7 (was 95119afe19105b4800ffc4e6d6f007c5f69dc564). The only conflict was the README.md bullet. On the rebased head, on the same RTX 3060 Ti PC, debug profile: cargo check -p xcl --all-targets exited 0, and cargo test -p xcl --lib -- --test-threads=4 a_driver_snapshot_never_combines_two_calls a_nested_driver_guard_does_not_end_a_later_outer_call an_outer_driver_guard_keeps_its_lease_after_the_tls_owner_drops driver_timing_survives_more_than_64_exited_threads exhausted_driver_slots_can_be_claimed_after_release simultaneous_driver_slot_claims_are_distinct the_ring_holds_what_was_noted_last d3d12x::watch gave 15 passed, 0 failed, 0 ignored, no SKIPPED. The whole suite and the paired title runs have not been rerun on this head; every other result below is from the earlier head. The rebase and its conflict resolution were done with Claude Code.

What is in it

  • Reusable thread-owned slot leases; active guards retain ownership through TLS teardown. Nested guards stay inert and exhausted callers can retry after capacity returns.
  • Version-checked snapshots keep timestamp, call kind and thread identity consistent during reuse.
  • Six new CPU-only tests and README update; the original nine watch tests remain unchanged.
  • Duplicate check: current main e429936c has no watch.rs timing registry. Open/draft searches found no matching slot repair. D3D12.X: DXC compiles XCL's own HLSL when D3DCompile refuses it #3018 reports the same test failure but changes DXC compilation, not slot ownership.

Tested

  • Windows 11 Pro 26200; Intel i5-10400; RTX 3060 Ti driver 32.0.16.1714; Rust 1.100.0. These focused checks are CPU-only, debug/test profile with debug symbols disabled, two build jobs.
  • Build: cargo test --locked -p xcl --lib --target-dir <isolated-target> --no-run passed for both controls.
  • Unchanged NVIDIA runtime 54225f58 plus only driver_timing_survives_more_than_64_exited_threads: 0 passed, 1 failed, 0 ignored, 1,806 filtered; no SKIPPED messages. The unchanged API stopped timing at thread 64.
  • Corrected source: cargo test --locked -p xcl --lib --target-dir <isolated-target> hle::d3d12x::watch::tests:: -- --nocapture --test-threads=1: 15 passed, 0 failed, 0 ignored, 1,797 filtered; no SKIPPED messages.
  • Executions preceded committing the unchanged source. Exact commands, hashes and logs are retained locally.
  • Triggering baseline evidence: the full NVIDIA workspace run had 1,909 passed, 1 failed, 48 ignored, with 29 explicit SKIPPED lines (not counted as coverage). The sole failure was a_thread_in_the_driver_is_seen_until_it_returns, after diagnostic-slot exhaustion.

Regression run
Pending paired clean-head main/PR title runs; no smoke block claimed.

Not tested

  • Full workspace rerun on this head; paired retail runs; performance impact under gameplay.
  • This retains the 64-concurrently-registered-live-thread limit. It repairs diagnostics, not rendering or shader memory usage.
  • Draft until full required validation is complete.

AI use
Codex (GPT-6) diagnosed the baseline failure, checked overlap, implemented and independently reviewed the repair, ran the focused controls/tests and prepared this PR.

Optional temporary Discord for coordinating contributor work, testing and comparing results: https://discord.gg/6B4TykyC4W

@JJAutoCompare

Copy link
Copy Markdown

Tested

Exact 95119afe19105b4800ffc4e6d6f007c5f69dc564 on Windows 11 x64 build 26200.9974, Ryzen 7 3800X, Rust 1.100.1 MSVC debug. The pinned executable used a verified Git archive with one private test inserted in watch.rs. All 386 original Git blobs matched after excluding the fixture.

I ran <libtest.exe> <filter> --exact --nocapture --test-threads=1 for each CPU test.

  • hle::d3d12x::watch::tests::a_recycled_driver_slot_preserves_the_other_live_snapshot recorded Execute in slot 0 and Present in slot 1. Slot 0 went idle after the first thread joined. A third thread reused it with its own active Present record while the live record in slot 1 kept the same timestamp, call kind, and thread ID.
  • The stock control hle::d3d12x::watch::tests::a_thread_in_the_driver_is_seen_until_it_returns passed.

2 passed, 0 failed, 0 ignored, 0 runtime skips. Both native processes exited 0, with 1,812 filtered out per invocation.

Not tested

Real driver calls, GPU execution, the base revision, performance, retail smoke, or the full suite.

AI use

T3 Code through the Codex harness (gpt-6.2-sol) verified the source and executable, reran the tests, and wrote this report.

@Prime1997
Prime1997 changed the base branch from nvidia-dev to main November 28, 2026 20:12
The lifetime-monotonic 64-slot registry exhausted itself during the full workspace suite. Reuse thread-owned leases after exit and read stable call snapshots. The unchanged-runtime 65-thread regression fails on thread64; all15 focused tests pass after the fix. Full workspace rerun and paired clean-head title validation remain pending.

Assisted-by: Codex (GPT-6)
@vasanex

vasanex commented Nov 29, 2026

Copy link
Copy Markdown
merge-check
base: fa204595a488c60c6c5f905244f0172072c9c2a9
head: c08bd75d4e246a223baef36e3c2c40313514dfa7
merge: clean
build: cargo build --workspace -> ok
tests: not run alone; in a stack of 11 of your PRs on this base: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2650 passed, 1 failed, 49 ignored; SKIPPED: 27 lines; failing: #3123's private_physical_pages_reach_the_gpu_on_mapping only. Alone: hle::d3d12x::watch:: 15 passed, 0 failed.
review: none blocking. Diagnostics only (two call sites: Present and ExecuteCommandLists). Single-writer seqlock and lease lifetime read through. Note: a_driver_snapshot_never_combines_two_calls writes made-up timestamps into a real global slot, which can make the watch thread log a stall in a shared test process (log noise only); a private pool as in exhausted_driver_slots_can_be_claimed_after_release would avoid it.
performance: about 8 locked instructions per timed call, a few calls per frame. 60 s smoke of the merged tree (771347ae): 1687 frames, peak commit 19041 MB, 0 removals, 0 crashes (base 1629-1689 frames, 16065-16596 MB; commit is noisy in this series: a tree identical to the base showed 19938 MB).
verdict: safe to merge (still a draft; description check red; CI red is the unrelated pipeline_library test, which passes here)
hardware / tool and model: RTX 3080 10 GB 621.40, Ryzen 9 7950X, Windows 11 26200 / Claude Code (Claude Opus 5.5, Claude Fable 5.2)

How this was run: the suite ran once on the 11 of your PRs that build on this base, merged together (#3047 #3048 #3049 #3091 #3092 #3103 #3104 #3105 #3107 #3123 #3125; a local tree, only #3125 needed a resolution in README and the sparse.rs test module); the base alone gave 2608 passed, 0 failed, 49 ignored with the same 27 SKIPPED lines (21 no wave64, 3 refused per-lane f16/f32 forms, 2 heap windows opt-in, 1 driver cache needs Developer Mode). This PR alone was merged onto the base, built (cargo build --workspace, then release), its modules' lib tests run (debug), and smoke-run once for 60 s (scripts/smoke.ps1, retail title, front end, XCL_PREPARE=0). The smoke numbers are for my local merged tree, not a clean-head block for the description.

AI use: Claude Code (Claude Opus 5.5 and Claude Fable 5.2) ran the builds, tests and title runs, reviewed the diff and wrote this; the code points cited were checked against the merged tree.

@Kalmarv

Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: beeb81b (mergeable cleanly on current main)
head: c08bd75
merge: clean
build: cargo check -p xcl --all-targets -> ok
tests: non-GPU lib tests of touched module (watch 15 passed, including 65-thread slot reuse test). Full workspace suite and GPU tests not run.
review: none blocking. Slots are leased per thread via Rc lease and returned on thread exit; versioned records (odd = writing) prevent torn reads.
performance: a few SeqCst stores per timed driver call; no overhead seen. Tested in a combined 600 s retail run on main beeb81b + 13 PRs (warm cache, defaults) vs baseline: presents/2 s 3.27 vs 3.29, peak commit 35,016 vs 35,767 MB, local video memory 14.19-14.76 vs 14.32-14.95 GB, 0 pipeline waits >= 1 s vs 5, 0 device removals, 0 crashes. Combined result across all 13 PRs, not isolated to this PR.
verdict: not yet: full workspace suite not run on its own merge.
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1074, AMD Ryzen 9 9950X, Windows 11 Pro 26200 / Claude Code (claude-opus-5-5)

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 29, 2026

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical review of current head c08bd75d. I found no ownership blocker in the per-thread timing-slot lease: the slot is returned on thread exit and the lease keeps an outer call valid after the TLS owner drops. The important remaining coverage is concurrent churn with more than 64 short-lived threads while one outer guard remains active; the included tests address the isolated cases, and existing Windows reports show them passing. Keep the no-slot fallback observable so timing data loss is not silent if all 64 slots are simultaneously occupied. No local Windows run; nonblocking review.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head c08bd75, diff read, not a merge-check; draft, so not built or run):

  • No full-suite run at this head and no smoke runs (main and head), which PR checks requires for a runtime change. AI use says "Claude Code" for the rebase without naming the model.
  • a_driver_snapshot_never_combines_two_calls (watch.rs ~751) writes start times 11 and 22 into a real global slot; if a GPU test in the same process has started xcl-gpu-watch, that thread logs a stalled driver call and a report. Noise, not a failure, but a private slot would avoid it.
  • The description's "current main e429936 has no watch.rs timing registry" is out of date.

Fine: slots are claimed with an atomic compare-and-swap and released only after the thread-local lease and any active call guard are gone and the slot is cleared; a version counter stops the watch thread from pairing an old call's time with a new thread's id; try_with avoids a panic during thread-local teardown; nested calls stay untimed. driver_timing_survives_more_than_64_exited_threads fails on main, which never reuses a slot. The added cost is a few atomics per ExecuteCommandLists / Present (a thread killed with TerminateThread keeps its slot, as on main).

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Test report (not a merge-check: draft, PR description red)
base: b2b1f10
head: c08bd75
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2908 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 #3107 (comment), 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, its new tests included); 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants