d3d12: flush GPU fault trace on device loss and mark raytracing commands #424

Merged
DrArroway merged 1 commit from upstream-pr/424 into main 2026-11-29 01:45:01 +00:00
DrArroway commented 2026-11-28 22:23:38 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-28T22:23:38Z.


Summary

When TUXBOX_TRACE_GPU_FAULT=1 is enabled, two gaps made GPU resets hard to attribute:

  1. Fast device-loss exit race: The watchdog thread polls GetDeviceRemovedReason() every 1 second. When a GPU reset causes UINT64_MAX / DXGI_ERROR_DEVICE_REMOVED on a submission or publication thread (or a MODE1 reset takes down the desktop/compositor), the process can abort before the next 1-second tick, printing nothing from gpu_trace.
    • Added gpu_trace::flush_on_device_lost(why) (guarded by an AtomicBool so the report logs once) and invoked it immediately when submit.rs or publication.rs observes UINT64_MAX or a device-removed HRESULT (0x887A0005 / 0x887A0006 / 0x887A0007), before returning the error to the title.
    • Always emits a summary line on device loss even when 0 marked commands remain unfinished (0 unfinished commands of N recorded), so an empty trace is distinguishable from a trace that failed to flush.
  2. Unmarked raytracing commands: gpu_trace::around previously covered draws and dispatches, leaving raytracing work invisible during faults.
    • Wrapped BuildRaytracingAccelerationStructure (build_as), guest-memory rehydration builds (rehydrate_as), CopyRaytracingAccelerationStructure (copy_as), EmitRaytracingAccelerationStructurePostbuildInfo (postbuild_as), TLAS instance fixup (instance_fixup), and DispatchRays (dispatch_rays) with gpu_trace::around when TUXBOX_TRACE_GPU_FAULT=1 is set (zero overhead when disabled).
    • Caveat noted during #403/#409 investigation: on RADV, a faulting BLAS build can occasionally complete with garbage data and hang later on another ring; marking both raytracing commands and graphics/compute draws covers direct build hangs as well as downstream traversal hangs.

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 (TUXBOX_TRACE_GPU_FAULT=1 device-loss flushing requires an actual GPU device reset; verified live during ProjectScarlett GPU fault debugging on #403 where it immediately reported unfinished build_as and mesh-draw commands on UINT64_MAX / DEVICE_REMOVED, and verified no regression across all Lanes raytracing and D3D12 fixtures)
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: NVIDIA still needs to run them (verified on both AMD RDNA2 discrete and AMD Raphael RDNA2 iGPU).

GPU, driver and backend:

  • AMD Radeon RX 6900 XT (1002:73bf, RADV NAVI21, Mesa 26.3.1, Linux 7.3.6, GE-Proton11-14)
  • AMD Radeon 610M Raphael iGPU (1002:164e, RADV RAPHAEL_MENDOCINO, Mesa 26.3.1, Linux 7.3.6, GE-Proton11-14)

Commands run and their results:

# AMD Raphael iGPU (1002:164e): full tuxbox.py check
  passed   Build the shader compiler
  passed   Python tests (581 ok, 8 skipped)
  passed   Shader compiler tests
  passed   DXBC tests
  passed   XG layout tests
  passed   Storage codec tests
  passed   D3D12 Windows typecheck
  passed   Build
  passed   Lanes and fixtures on the GPU (112/112 checks)
  passed   D3D12 regression controls (22/22 cases including buffer-remap, buffer-unmap-alive, buffer-unmap-released, mesh)
  passed   Shader translator on the GPU

# AMD RX 6900 XT (1002:73bf):
  tuxbox.py verify --adapter 1002:73bf: 113/113 checks PASS
  tuxbox.py check --adapter 1002:73bf: CI steps, Build, Shader translator on the GPU PASS;
    D3D12 regression controls 21/22 PASS (mesh failed with "word 76 expected 1548 observed 0",
    which reproduces identically on unmodified main b8355fa on 1002:73bf).

Checks

No evidence/ JSON files were modified.

<!-- greyfinch-sync:brcly/TuxBox:issue:5545158015 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/424). Originally posted by [DrArroway](https://github.com/DrArroway) on 2026-11-28T22:23:38Z. --- ## Summary When `TUXBOX_TRACE_GPU_FAULT=1` is enabled, two gaps made GPU resets hard to attribute: 1. **Fast device-loss exit race:** The watchdog thread polls `GetDeviceRemovedReason()` every 1 second. When a GPU reset causes `UINT64_MAX` / `DXGI_ERROR_DEVICE_REMOVED` on a submission or publication thread (or a MODE1 reset takes down the desktop/compositor), the process can abort before the next 1-second tick, printing nothing from `gpu_trace`. - Added `gpu_trace::flush_on_device_lost(why)` (guarded by an `AtomicBool` so the report logs once) and invoked it immediately when `submit.rs` or `publication.rs` observes `UINT64_MAX` or a device-removed HRESULT (`0x887A0005` / `0x887A0006` / `0x887A0007`), before returning the error to the title. - Always emits a summary line on device loss even when 0 marked commands remain unfinished (`0 unfinished commands of N recorded`), so an empty trace is distinguishable from a trace that failed to flush. 2. **Unmarked raytracing commands:** `gpu_trace::around` previously covered draws and dispatches, leaving raytracing work invisible during faults. - Wrapped `BuildRaytracingAccelerationStructure` (`build_as`), guest-memory rehydration builds (`rehydrate_as`), `CopyRaytracingAccelerationStructure` (`copy_as`), `EmitRaytracingAccelerationStructurePostbuildInfo` (`postbuild_as`), TLAS instance fixup (`instance_fixup`), and `DispatchRays` (`dispatch_rays`) with `gpu_trace::around` when `TUXBOX_TRACE_GPU_FAULT=1` is set (zero overhead when disabled). - Caveat noted during `#403`/`#409` investigation: on RADV, a faulting BLAS build can occasionally complete with garbage data and hang later on another ring; marking both raytracing commands and graphics/compute draws covers direct build hangs as well as downstream traversal hangs. ## Tested Run the [checks relevant to this change](../CONTRIBUTING.md#test-what-your-change-touches). - [x] 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 (`TUXBOX_TRACE_GPU_FAULT=1` device-loss flushing requires an actual GPU device reset; verified live during ProjectScarlett GPU fault debugging on `#403` where it immediately reported unfinished `build_as` and mesh-draw commands on `UINT64_MAX` / `DEVICE_REMOVED`, and verified no regression across all Lanes raytracing and D3D12 fixtures) - [ ] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: NVIDIA still needs to run them (verified on both AMD RDNA2 discrete and AMD Raphael RDNA2 iGPU). GPU, driver and backend: - AMD Radeon RX 6900 XT (`1002:73bf`, RADV NAVI21, Mesa 26.3.1, Linux 7.3.6, `GE-Proton11-14`) - AMD Radeon 610M Raphael iGPU (`1002:164e`, RADV RAPHAEL_MENDOCINO, Mesa 26.3.1, Linux 7.3.6, `GE-Proton11-14`) Commands run and their results: ```text # AMD Raphael iGPU (1002:164e): full tuxbox.py check passed Build the shader compiler passed Python tests (581 ok, 8 skipped) passed Shader compiler tests passed DXBC tests passed XG layout tests passed Storage codec tests passed D3D12 Windows typecheck passed Build passed Lanes and fixtures on the GPU (112/112 checks) passed D3D12 regression controls (22/22 cases including buffer-remap, buffer-unmap-alive, buffer-unmap-released, mesh) passed Shader translator on the GPU # AMD RX 6900 XT (1002:73bf): tuxbox.py verify --adapter 1002:73bf: 113/113 checks PASS tuxbox.py check --adapter 1002:73bf: CI steps, Build, Shader translator on the GPU PASS; D3D12 regression controls 21/22 PASS (mesh failed with "word 76 expected 1548 observed 0", which reproduces identically on unmodified main b8355fa on 1002:73bf). ``` ## Checks No `evidence/` JSON files were modified.
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!424
No description provided.