d3d12: add opt-in GPU timing and AS compaction handshake trace #532

Merged
glovepost merged 3 commits from upstream-pr/532 into main 2026-12-01 14:36:26 +00:00
glovepost commented 2026-11-29 20:13:25 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-29T20:13:25Z.


Summary

Adds opt-in per-pipeline GPU timing attribution (TUXBOX_GPU_TIMING=1) and acceleration-structure compaction handshake tracing (TUXBOX_TRACE_AS_COMPACTION=1) in tuxbox-d3d12:

  • Opt-in GPU timing (runtime/d3d12/src/gpu_timing.rs, commands.rs, commands/recording.rs, commands/ray_dispatch.rs, commands/submit.rs, diagnostics/gpu_trace.rs, docs/ENVIRONMENT.md): Adds ListTimer and fence-backed batch retirement (gpu_timing::submit / reap using retire_fence, logging the top 20 pipelines every 10 seconds when TUXBOX_GPU_TIMING=1). Brackets compute dispatches, graphics/mesh/indirect draws, and DispatchRays, and enables diagnostics::gpu_trace::name when TUXBOX_GPU_TIMING=1 without modifying pipeline creation modules.
  • AS compaction handshake trace (runtime/d3d12/src/diagnostics/compaction.rs, diagnostics.rs, commands/raytracing.rs, device/blas.rs, docs/ENVIRONMENT.md): Records compaction postbuild queries (note_request), copy handshakes (note_copy), and published guest addresses (blas::published) when TUXBOX_TRACE_AS_COMPACTION=1.
  • Unit tests (runtime/d3d12/src/tests/gpu_timing.rs, runtime/d3d12/src/tests/diagnostics_compaction.rs): Verifies timing helper defaults and compaction diagnostic state.

Note: submit.rs, recording.rs, ray_dispatch.rs, and blas.rs overlap with open PRs #507, #512, and #406.

Prepared with AI assistance; all changes were reviewed and verified with host checks, Wine unit tests, and both NVIDIA and AMD GPUs.

Tested

Run the checks relevant to this change.

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them:

No new Lanes scenario was added because both TUXBOX_GPU_TIMING=1 and TUXBOX_TRACE_AS_COMPACTION=1 are opt-in diagnostic paths off by default; default execution (10/10 D3D12 regressions and 126/126 verify tests) passes with zero regressions on both NVIDIA and AMD, and diagnostic formatting/state helpers are covered by tests/gpu_timing.rs and tests/diagnostics_compaction.rs.

GPU, driver and backend:

  • NVIDIA GeForce RTX 2070 SUPER (10de:1e84), driver 620.73.04, GE-Proton11-14 (vkd3d-proton)
  • AMD Ryzen 7 9800X3D iGPU (1002:13c0), RADV / Mesa 26.3.1, GE-Proton11-14 (vkd3d-proton)

Commands run and their results:

DXC=<dxc> python3 tuxbox.py check --no-gpu
  -> 7/7 passed (Python 698 tests OK; shader compiler 622 lib + 1 bin + 2 integration; DXBC 109; XG layout 17 passed, 1 ignored; storage codec 18; D3D12 Windows typecheck passed)

CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUNNER=wine cargo xwin test --locked --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --lib
  -> 423 passed, 0 failed, 8 ignored

TUXBOX_CHECK_JOBS=2 python3 tools/check_d3d12_regressions.py --build-dir <build-dir> --proton <proton> --prefix <prefix> --compiler-dir <windows-dxc> --xmem <xmem> --adapter 10de:1e84 --work <work> --output <out>
  -> 10/10 passed

TUXBOX_CHECK_JOBS=2 python3 tuxbox.py verify --backend proton --adapter 10de:1e84 --output <out>
  -> 126/126 passed

TUXBOX_CHECK_JOBS=2 python3 tools/check_d3d12_regressions.py --build-dir <build-dir> --proton <proton> --prefix <prefix> --compiler-dir <windows-dxc> --xmem <xmem> --adapter 1002:13c0 --work <work> --output <out>
  -> 10/10 passed

TUXBOX_CHECK_JOBS=2 python3 tuxbox.py verify --backend proton --adapter 1002:13c0 --output <out>
  -> 126/126 passed

Checks

CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of tuxbox-d3d12.

<!-- greyfinch-sync:brcly/TuxBox:issue:5554660864 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/532). Originally posted by [glovepost](https://github.com/glovepost) on 2026-11-29T20:13:25Z. --- ## Summary Adds opt-in per-pipeline GPU timing attribution (`TUXBOX_GPU_TIMING=1`) and acceleration-structure compaction handshake tracing (`TUXBOX_TRACE_AS_COMPACTION=1`) in `tuxbox-d3d12`: - **Opt-in GPU timing (`runtime/d3d12/src/gpu_timing.rs`, `commands.rs`, `commands/recording.rs`, `commands/ray_dispatch.rs`, `commands/submit.rs`, `diagnostics/gpu_trace.rs`, `docs/ENVIRONMENT.md`):** Adds `ListTimer` and fence-backed batch retirement (`gpu_timing::submit` / `reap` using `retire_fence`, logging the top 20 pipelines every 10 seconds when `TUXBOX_GPU_TIMING=1`). Brackets compute dispatches, graphics/mesh/indirect draws, and `DispatchRays`, and enables `diagnostics::gpu_trace::name` when `TUXBOX_GPU_TIMING=1` without modifying pipeline creation modules. - **AS compaction handshake trace (`runtime/d3d12/src/diagnostics/compaction.rs`, `diagnostics.rs`, `commands/raytracing.rs`, `device/blas.rs`, `docs/ENVIRONMENT.md`):** Records compaction postbuild queries (`note_request`), copy handshakes (`note_copy`), and published guest addresses (`blas::published`) when `TUXBOX_TRACE_AS_COMPACTION=1`. - **Unit tests (`runtime/d3d12/src/tests/gpu_timing.rs`, `runtime/d3d12/src/tests/diagnostics_compaction.rs`):** Verifies timing helper defaults and compaction diagnostic state. Note: `submit.rs`, `recording.rs`, `ray_dispatch.rs`, and `blas.rs` overlap with open PRs `#507`, `#512`, and `#406`. Prepared with AI assistance; all changes were reviewed and verified with host checks, Wine unit tests, and both NVIDIA and AMD GPUs. ## Tested Run the [checks relevant to this change](../CONTRIBUTING.md#test-what-your-change-touches). - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [x] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: No new Lanes scenario was added because both `TUXBOX_GPU_TIMING=1` and `TUXBOX_TRACE_AS_COMPACTION=1` are opt-in diagnostic paths off by default; default execution (`10/10` D3D12 regressions and `126/126` verify tests) passes with zero regressions on both NVIDIA and AMD, and diagnostic formatting/state helpers are covered by `tests/gpu_timing.rs` and `tests/diagnostics_compaction.rs`. GPU, driver and backend: - NVIDIA GeForce RTX 2070 SUPER (`10de:1e84`), driver `620.73.04`, GE-Proton11-14 (`vkd3d-proton`) - AMD Ryzen 7 9800X3D iGPU (`1002:13c0`), RADV / Mesa `26.3.1`, GE-Proton11-14 (`vkd3d-proton`) Commands run and their results: ```text DXC=<dxc> python3 tuxbox.py check --no-gpu -> 7/7 passed (Python 698 tests OK; shader compiler 622 lib + 1 bin + 2 integration; DXBC 109; XG layout 17 passed, 1 ignored; storage codec 18; D3D12 Windows typecheck passed) CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUNNER=wine cargo xwin test --locked --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --lib -> 423 passed, 0 failed, 8 ignored TUXBOX_CHECK_JOBS=2 python3 tools/check_d3d12_regressions.py --build-dir <build-dir> --proton <proton> --prefix <prefix> --compiler-dir <windows-dxc> --xmem <xmem> --adapter 10de:1e84 --work <work> --output <out> -> 10/10 passed TUXBOX_CHECK_JOBS=2 python3 tuxbox.py verify --backend proton --adapter 10de:1e84 --output <out> -> 126/126 passed TUXBOX_CHECK_JOBS=2 python3 tools/check_d3d12_regressions.py --build-dir <build-dir> --proton <proton> --prefix <prefix> --compiler-dir <windows-dxc> --xmem <xmem> --adapter 1002:13c0 --work <work> --output <out> -> 10/10 passed TUXBOX_CHECK_JOBS=2 python3 tuxbox.py verify --backend proton --adapter 1002:13c0 --output <out> -> 126/126 passed ``` ## Checks CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of `tuxbox-d3d12`.
brcly commented 2026-11-29 21:41:56 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T21:41:56Z.


Thanks. Opt-in GPU timing is useful next to the frame log. It conflicts with main now (commands/recording.rs, diagnostics/gpu_trace.rs and docs/ENVIRONMENT.md, probably with #541's marker names). Could you rebase it? Then we'll put it through the check.

<!-- greyfinch-sync:brcly/TuxBox:comment:7263079672 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/532#issuecomment-7263079672). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T21:41:56Z. --- Thanks. Opt-in GPU timing is useful next to the frame log. It conflicts with `main` now (`commands/recording.rs`, `diagnostics/gpu_trace.rs` and `docs/ENVIRONMENT.md`, probably with #541's marker names). Could you rebase it? Then we'll put it through the check.
glovepost commented 2026-11-29 22:24:36 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-29T22:24:36Z.


@brcly Rebased #532 onto main (6bab5478, commit 7ec2a41b), preserving #541's PIX marker / markers_wanted() updates in gpu_trace.rs / recording.rs / docs/ENVIRONMENT.md and #512's consume_tables in recording.rs.

DXC=<dxc> python3 tuxbox.py check --no-gpu (9/9) and cargo check --tests --target x86_64-pc-windows-msvc on tuxbox-d3d12 passed. ProjectScarlett was not re-run since the rebase.

<!-- greyfinch-sync:brcly/TuxBox:comment:7263650283 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/532#issuecomment-7263650283). Originally posted by [glovepost](https://github.com/glovepost) on 2026-11-29T22:24:36Z. --- @brcly Rebased #532 onto `main` (`6bab5478`, commit `7ec2a41b`), preserving #541's PIX marker / `markers_wanted()` updates in `gpu_trace.rs` / `recording.rs` / `docs/ENVIRONMENT.md` and #512's `consume_tables` in `recording.rs`. `DXC=<dxc> python3 tuxbox.py check --no-gpu` (`9/9`) and `cargo check --tests --target x86_64-pc-windows-msvc` on `tuxbox-d3d12` passed. ProjectScarlett was not re-run since the rebase.
glovepost commented 2026-11-30 01:32:41 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-30T01:32:41Z.


Rebased onto main (f482572a, commit 072ec7d57a3f) with no functional changes from 7ec2a41b, and ran the changed GPU checks on NVIDIA (headless xvfb-run with WAYLAND_DISPLAY=""):

  • Command: WAYLAND_DISPLAY="" TUXBOX_CHECK_JOBS=2 DXC=<dxc> xvfb-run -a -s "-screen 0 2560x1440x24" python3 tuxbox.py check --changed --adapter 10de:1e84 --proton <proton> --prefix <prefix> --windows-dxc <windows-dxc>
  • GPU / driver / backend: NVIDIA GeForce RTX 2070 SUPER (10de:1e84), driver 620.73.04, GE-Proton11-14
  • Results: Lanes and fixtures on the GPU (d3d12-*, guest-frame, present, lanes, lanes-*) and all D3D12 regression controls (22/22) passed (13 passed, 0 failed, 0 not run).
  • Still missing: AMD GPU checks. ProjectScarlett was not run on this commit.

Evidence: TuxBox check of 072ec7d57a3f, no uncommitted changes, GPU 10de:1e84: 13 passed, 0 failed, 0 not run

<!-- greyfinch-sync:brcly/TuxBox:comment:7266226939 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/532#issuecomment-7266226939). Originally posted by [glovepost](https://github.com/glovepost) on 2026-11-30T01:32:41Z. --- Rebased onto `main` (`f482572a`, commit `072ec7d57a3f`) with no functional changes from `7ec2a41b`, and ran the changed GPU checks on NVIDIA (headless `xvfb-run` with `WAYLAND_DISPLAY=""`): - **Command:** `WAYLAND_DISPLAY="" TUXBOX_CHECK_JOBS=2 DXC=<dxc> xvfb-run -a -s "-screen 0 2560x1440x24" python3 tuxbox.py check --changed --adapter 10de:1e84 --proton <proton> --prefix <prefix> --windows-dxc <windows-dxc>` - **GPU / driver / backend:** NVIDIA GeForce RTX 2070 SUPER (`10de:1e84`), driver `620.73.04`, `GE-Proton11-14` - **Results:** `Lanes and fixtures on the GPU` (`d3d12-*`, `guest-frame`, `present`, `lanes`, `lanes-*`) and all `D3D12 regression controls` (`22/22`) passed (**13 passed, 0 failed, 0 not run**). - **Still missing:** AMD GPU checks. ProjectScarlett was not run on this commit. `Evidence: TuxBox check of 072ec7d57a3f, no uncommitted changes, GPU 10de:1e84: 13 passed, 0 failed, 0 not run`
NickStallman commented 2026-11-30 03:02:32 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T03:02:32Z.


The AMD check you were missing, on 072ec7d5: AMD iGPU (1002:13c0, RADV, Mesa 26.0.8, GE-Proton11-14, Linux), full python tuxbox.py check: 199 pass, 0 fail. ProjectScarlett was not run on this commit.

Evidence: TuxBox check of 072ec7d57a, no uncommitted changes, GPU 1002:13c0: 14 passed, 0 failed, 0 not run

<!-- greyfinch-sync:brcly/TuxBox:comment:7267534475 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/532#issuecomment-7267534475). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-30T03:02:32Z. --- The AMD check you were missing, on 072ec7d5: AMD iGPU (`1002:13c0`, RADV, Mesa 26.0.8, GE-Proton11-14, Linux), full `python tuxbox.py check`: 199 pass, 0 fail. ProjectScarlett was not run on this commit. Evidence: TuxBox check of 072ec7d57a3f, no uncommitted changes, GPU 1002:13c0: 14 passed, 0 failed, 0 not run
brcly commented 2026-11-30 04:12:19 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T04:12:19Z.


Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase.

  • Formatting: the whole workspace is now formatted with rustfmt (see the new rustfmt.toml).
  • Lints: every crate denies unwrap(), lossy as casts and undocumented unsafe outside tests.
  • CI: it now also runs cargo fmt --check, rustdoc with warnings denied, and Miri on the providers' unit tests.

The least painful way is to format your branch first, so the rebase only shows real changes:

git fetch origin
git checkout origin/main -- rustfmt.toml
cargo fmt --all && git commit -am "rustfmt"
git rebase origin/main

Then run python tuxbox.py check --no-gpu, which now includes the format step.

If clippy flags something new:

  • A cast: use From for widening, TryFrom for narrowing, and a mask for bit fields.
  • An unwrap(): use ?, or expect with the reason it can't fail.
  • An unsafe block: it needs a // SAFETY: comment.

CONTRIBUTING's "Code checks" section lists the commands. Thanks!

<!-- greyfinch-sync:brcly/TuxBox:comment:7268562293 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/532#issuecomment-7268562293). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T04:12:19Z. --- Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase. - **Formatting:** the whole workspace is now formatted with rustfmt (see the new `rustfmt.toml`). - **Lints:** every crate denies `unwrap()`, lossy `as` casts and undocumented `unsafe` outside tests. - **CI:** it now also runs `cargo fmt --check`, rustdoc with warnings denied, and Miri on the providers' unit tests. The least painful way is to format your branch first, so the rebase only shows real changes: ```sh git fetch origin git checkout origin/main -- rustfmt.toml cargo fmt --all && git commit -am "rustfmt" git rebase origin/main ``` Then run `python tuxbox.py check --no-gpu`, which now includes the format step. If clippy flags something new: - **A cast:** use `From` for widening, `TryFrom` for narrowing, and a mask for bit fields. - **An `unwrap()`:** use `?`, or `expect` with the reason it can't fail. - **An `unsafe` block:** it needs a `// SAFETY:` comment. CONTRIBUTING's "Code checks" section lists the commands. Thanks!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!532
No description provided.