[pr-fix][memory][RAYTRACING][AMD] hwrt: BLASes that are refitted get committed buffers, not reused shared-heap units (DARNER_HW_RT_REFIT_COMMITTED, on by default; RX 7900 XTX "device hung") #445

Manually merged
TrustNo1 merged 1 commit from duckey-dev/Darner:hwrt-refit-committed into main 2026-12-05 04:51:36 +00:00
Contributor

Refs #197
Refs #388

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: with hardware ray tracing on an RX 7900 XTX, f3840d7 loses the device ("device hung", 0x887A0006) in 8 of 10 runs, within about 1 to 2 minutes of play. DRED: the GPU stops at the barrier right after a wave of BLAS builds and refits. The page-fault addresses are outside every live allocation, all just above 0x800000000 (for example 0x800080000, 0x8022a3000, 0x8084f4000, 0x80a114000). That fits the GPU following a garbage 32-bit BVH node pointer: (ptr & ~7) << 3 reaches up to 32 GiB above the structure.

Follow-up to my report in #197: the delayed unit return I suggested there was tested and is not enough (units given back only after 2 or 120 frames plus retirement still hung 3 of 3 and 2 of 3 runs); this is the fix.

What the runs show (same PC, same save, same switches, each about 80 to 90 s of play):

f3840d7, hardware RT on runs device hung
as is 10 8
DARNER_HW_RT_BLAS_HEAPS=0 (every BLAS committed) 3 0
local test patch: heap units never given back 3 0
local test patch: units given back after 2 frames plus retirement 3 3
local test patch: units given back after 120 frames plus retirement 3 2
DARNER_HW_RT_REFIT=0 (no refits at all) 3 0 (about 30 fps)

So the hang needs both refits and BLASes placed in heap units that held another BLAS before. Giving units back later does not help, so this is not a BLAS's memory being reused while the GPU still reads the old one. What the evidence fits is that an in-place refit reads something in the structure that its build did not write, and in a reused unit that is the previous BLAS's tree. I have not proven that inside the driver. AMD's RDNA performance guide advises fully initialising placed resources; a committed buffer never holds another BLAS's tree.

This change is a placement rule for the BLASes that are refitted every frame: a BLAS built with ALLOW_UPDATE gets a committed buffer (create_blas_buffer now takes refittable); every other BLAS is still placed in the shared heaps (DARNER_HW_RT_BLAS_HEAPS, from fa0b1fc) as before. DARNER_HW_RT_REFIT_COMMITTED=0 places refittable BLASes in the heaps again. The switch's state is logged once, when it is first read.

Per run, about 1,050 to 1,190 refittable BLASes were committed and about 1,850 to 2,250 others were still placed, in 8 to 9 heaps of 64 MB, so most of the shared-heap placement stays.

Cost: committed creation for the refittable BLASes. The log's average is about 300 to 345 µs per BLAS buffer made (both kinds together), against 715 to 848 µs with every BLAS committed (DARNER_HW_RT_BLAS_HEAPS=0). Frame rate in the clean runs is in the same range as f3840d7 runs before their hang. This is not a performance claim.

A second, separate pull request (#446) closes an ordering hole in refits (DARNER_HW_RT_REFIT_BUILT). On its own it did not stop this hang (7 of 7 runs hung).

How it was tested

  • Tested revision: game runs on f3840d7 with this change, diagnostics (diag) builds. This branch is the same change on 47d21cd (commit fc606f0); hwrt.rs is the same file at f3840d7 and 47d21cd. Not run in the game on 47d21cd.

  • Commands and results: the game runs in the table above and the A/B below; the gates below.

  • Changes a default: yes, for every card with hardware ray tracing on (DARNER_HW_RT=1): refittable BLASes are committed unless DARNER_HW_RT_REFIT_COMMITTED=0.

  • A/B result, on an RX 7900 XTX, same save, same switches (DARNER_HW_RT=1 DARNER_RELAY=2 DARNER_PORT_CBV=1 DARNER_EARLY_DEPTH=1), each run about 80 to 90 s of play:

    A (off: f3840d7 as is) B (on: this change)
    Device hung, this change alone 8 of 10 runs 0 of 3 runs (30.6 to 32.4 fps)
    Device hung, with the separate refit-source gate (#446) also on 7 of 7 runs 0 of 9 runs (5 of an earlier build, 4 of the final diff; 30.5 to 33.6 fps)
    fps about 33 to 34, before the hang 30.5 to 33.6
  • Gates run on fc606f0 (there is no CI): gates 1 and 2 (cargo clippy --workspace --all-targets --locked -- -D warnings, without and with --all-features) passed. Gate 3: the full cargo test --workspace --locked was stopped after about 27 minutes in darner-shader's tests, which this change does not touch. Run instead: cargo test --locked -p darner-gpu -p darner-hle -p darner (the changed crate and the crates that depend on it): 1,993 passed, 1 failed (host::refresh_tests::unchanged_ranges_are_known, passed when rerun), 82 ignored; the game was running on the same PC during part of these test runs. Thread-timing tests in darner-gpu also fail now and then on main: run back to back, gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback failed 1 of 10 runs on 47d21cd and 1 of 10 on this branch.

  • Gameplay, when relevant: RX 7900 XTX, Ryzen 7 7800X3D, 64 GB, Windows 11; game build Xbox Series 1.0.2.1; hardware ray tracing on. Series S console profile, the game's 1920x1080 output, the title's own upscaler (type 6), frame generation off.

  • Shader wave sizes tested, when relevant: not relevant (no shader change).

  • Hardware dependence: seen on an RX 7900 XTX (RDNA 3). #388 (RX 9060 XT, hardware RT) and #69 (device hung with hardware RT) may be the same hang; not tested on those cards. #342 (NVIDIA device loss with hardware RT) works around with DARNER_HW_RT_REFIT=0, which may point to the same cause; not tested on NVIDIA.

  • Coverage gaps: one card, one save. Not run on NVIDIA or Intel cards, where the change is on by default too. The mechanism inside the driver is not proven.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #318 (reorganises the BLAS heaps by size class and gives empty heaps back; same area, a different change), #268 (BLAS TDR bursts and in-flight HostAs reuse; tested on this PC, still hung 1 of 1), #279 (also changes hwrt.rs: TLAS reallocation, a different change). Related issues: #197 (my earlier report), #388, #69, #342, #290 (BLAS heaps never given back; same heaps, a different problem).
  • Replaces or overlaps: none found

🤖 Generated with Claude Code

Refs #197 Refs #388 ## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: with hardware ray tracing on an RX 7900 XTX, `f3840d7` loses the device ("device hung", `0x887A0006`) in 8 of 10 runs, within about 1 to 2 minutes of play. DRED: the GPU stops at the barrier right after a wave of BLAS builds and refits. The page-fault addresses are outside every live allocation, all just above `0x800000000` (for example `0x800080000`, `0x8022a3000`, `0x8084f4000`, `0x80a114000`). That fits the GPU following a garbage 32-bit BVH node pointer: `(ptr & ~7) << 3` reaches up to 32 GiB above the structure. Follow-up to my report in #197: the delayed unit return I suggested there was tested and is not enough (units given back only after 2 or 120 frames plus retirement still hung 3 of 3 and 2 of 3 runs); this is the fix. What the runs show (same PC, same save, same switches, each about 80 to 90 s of play): | `f3840d7`, hardware RT on | runs | device hung | |---|---|---| | as is | 10 | 8 | | `DARNER_HW_RT_BLAS_HEAPS=0` (every BLAS committed) | 3 | 0 | | local test patch: heap units never given back | 3 | 0 | | local test patch: units given back after 2 frames plus retirement | 3 | 3 | | local test patch: units given back after 120 frames plus retirement | 3 | 2 | | `DARNER_HW_RT_REFIT=0` (no refits at all) | 3 | 0 (about 30 fps) | So the hang needs both refits and BLASes placed in heap units that held another BLAS before. Giving units back later does not help, so this is not a BLAS's memory being reused while the GPU still reads the old one. What the evidence fits is that an in-place refit reads something in the structure that its build did not write, and in a reused unit that is the previous BLAS's tree. I have not proven that inside the driver. AMD's RDNA performance guide advises fully initialising placed resources; a committed buffer never holds another BLAS's tree. This change is a placement rule for the BLASes that are refitted every frame: a BLAS built with `ALLOW_UPDATE` gets a committed buffer (`create_blas_buffer` now takes `refittable`); every other BLAS is still placed in the shared heaps (`DARNER_HW_RT_BLAS_HEAPS`, from `fa0b1fc`) as before. `DARNER_HW_RT_REFIT_COMMITTED=0` places refittable BLASes in the heaps again. The switch's state is logged once, when it is first read. Per run, about 1,050 to 1,190 refittable BLASes were committed and about 1,850 to 2,250 others were still placed, in 8 to 9 heaps of 64 MB, so most of the shared-heap placement stays. Cost: committed creation for the refittable BLASes. The log's average is about 300 to 345 µs per BLAS buffer made (both kinds together), against 715 to 848 µs with every BLAS committed (`DARNER_HW_RT_BLAS_HEAPS=0`). Frame rate in the clean runs is in the same range as `f3840d7` runs before their hang. This is not a performance claim. A second, separate pull request (#446) closes an ordering hole in refits (`DARNER_HW_RT_REFIT_BUILT`). On its own it did not stop this hang (7 of 7 runs hung). ## How it was tested - Tested revision: game runs on `f3840d7` with this change, diagnostics (`diag`) builds. This branch is the same change on `47d21cd` (commit `fc606f0`); `hwrt.rs` is the same file at `f3840d7` and `47d21cd`. Not run in the game on `47d21cd`. - Commands and results: the game runs in the table above and the A/B below; the gates below. - Changes a default: yes, for every card with hardware ray tracing on (`DARNER_HW_RT=1`): refittable BLASes are committed unless `DARNER_HW_RT_REFIT_COMMITTED=0`. - A/B result, on an RX 7900 XTX, same save, same switches (`DARNER_HW_RT=1 DARNER_RELAY=2 DARNER_PORT_CBV=1 DARNER_EARLY_DEPTH=1`), each run about 80 to 90 s of play: | | A (off: `f3840d7` as is) | B (on: this change) | |---|---|---| | Device hung, this change alone | 8 of 10 runs | 0 of 3 runs (30.6 to 32.4 fps) | | Device hung, with the separate refit-source gate (#446) also on | 7 of 7 runs | 0 of 9 runs (5 of an earlier build, 4 of the final diff; 30.5 to 33.6 fps) | | fps | about 33 to 34, before the hang | 30.5 to 33.6 | - Gates run on `fc606f0` (there is no CI): gates 1 and 2 (`cargo clippy --workspace --all-targets --locked -- -D warnings`, without and with `--all-features`) passed. Gate 3: the full `cargo test --workspace --locked` was stopped after about 27 minutes in `darner-shader`'s tests, which this change does not touch. Run instead: `cargo test --locked -p darner-gpu -p darner-hle -p darner` (the changed crate and the crates that depend on it): 1,993 passed, 1 failed (`host::refresh_tests::unchanged_ranges_are_known`, passed when rerun), 82 ignored; the game was running on the same PC during part of these test runs. Thread-timing tests in `darner-gpu` also fail now and then on main: run back to back, `gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback` failed 1 of 10 runs on `47d21cd` and 1 of 10 on this branch. - Gameplay, when relevant: RX 7900 XTX, Ryzen 7 7800X3D, 64 GB, Windows 11; game build Xbox Series 1.0.2.1; hardware ray tracing on. Series S console profile, the game's 1920x1080 output, the title's own upscaler (type 6), frame generation off. - Shader wave sizes tested, when relevant: not relevant (no shader change). - Hardware dependence: seen on an RX 7900 XTX (RDNA 3). #388 (RX 9060 XT, hardware RT) and #69 (device hung with hardware RT) may be the same hang; not tested on those cards. #342 (NVIDIA device loss with hardware RT) works around with `DARNER_HW_RT_REFIT=0`, which may point to the same cause; not tested on NVIDIA. - Coverage gaps: one card, one save. Not run on NVIDIA or Intel cards, where the change is on by default too. The mechanism inside the driver is not proven. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #318 (reorganises the BLAS heaps by size class and gives empty heaps back; same area, a different change), #268 (BLAS TDR bursts and in-flight `HostAs` reuse; tested on this PC, still hung 1 of 1), #279 (also changes `hwrt.rs`: TLAS reallocation, a different change). Related issues: #197 (my earlier report), #388, #69, #342, #290 (BLAS heaps never given back; same heaps, a different problem). - Replaces or overlaps: none found 🤖 Generated with [Claude Code](https://claude.com/claude-code)
In-place refits of BLASes placed in reused units of the shared BLAS
heaps page-faulted on an RX 7900 XTX ("device hung", 0x887A0006) at the
barrier after a wave of refits, at addresses just over 32 GiB away from
any live allocation (the GPU followed a garbage 32-bit node pointer).
Committed BLAS buffers, and heap units never reused, did not fault, and
delaying the reuse of units did not help. BLASes built with ALLOW_UPDATE
now take committed buffers; the rest stay in the heaps.
DARNER_HW_RT_REFIT_COMMITTED=0 places them as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
First-time contributor

Tested on a different GPU: RTX 5080 16 GB, Ryzen 7 9800X3D, driver 32.0.16.2140, Windows. In game with hardware RT (DARNER_MENU_RT=hardware, fullscreen, frame gen on), same save/area: main 47d21cd vs this PR fc606f0.

Method: sampled the hardware RT BLAS buffers: and hardware RT BLAS memory: lines from the log and compared the end state, where live BLAS is close between the runs (4.4k vs 4.1k). The PR run was longer (~12 min, part of it in the menu), so the sample means are not comparable; the end state and the per-buffer creation cost are.

main 47d21cd PR fc606f0
BLASes placed / committed 10,564 / 0 4,906 / 3,438
Heaps 12 x 64 MB 8 x 64 MB
Heap in use 632 MB 380 MB
Live BLAS (memory line) 4,425 4,069
Creation per BLAS buffer 20.6 us 242.5 us
Total creation time 217 ms 2,023 ms

At comparable live BLAS, 3,438 BLASes (about 41% of the 8.3k buffers) moved out of the shared heaps: heaps 12 -> 8 and heap in use down 252 MB (-40%). The cost is creation: 242.5 us per buffer made on average against 20.6 us, 2.0 s against 0.2 s in all - a little below the 300-345 us the description reports (and far from the 715-848 us with every BLAS committed). No device loss in either run.

Caveat: the run included menu time, so the sample means (placed 1,273 / committed 724 on average) say little; the end state and the per-buffer cost do not depend on play time.

Not tested: DARNER_HW_RT_REFIT_COMMITTED=0 on this GPU, other GPUs, and frame rate (the scenes and durations differ).

Drafted with AI assistance (OpenCode).

Tested on a different GPU: RTX 5080 16 GB, Ryzen 7 9800X3D, driver 32.0.16.2140, Windows. In game with hardware RT (`DARNER_MENU_RT=hardware`, fullscreen, frame gen on), same save/area: main `47d21cd` vs this PR `fc606f0`. Method: sampled the `hardware RT BLAS buffers:` and `hardware RT BLAS memory:` lines from the log and compared the end state, where live BLAS is close between the runs (4.4k vs 4.1k). The PR run was longer (~12 min, part of it in the menu), so the sample means are not comparable; the end state and the per-buffer creation cost are. | | main `47d21cd` | PR `fc606f0` | |---|---|---| | BLASes placed / committed | 10,564 / 0 | 4,906 / 3,438 | | Heaps | 12 x 64 MB | 8 x 64 MB | | Heap in use | 632 MB | 380 MB | | Live BLAS (memory line) | 4,425 | 4,069 | | Creation per BLAS buffer | 20.6 us | 242.5 us | | Total creation time | 217 ms | 2,023 ms | At comparable live BLAS, 3,438 BLASes (about 41% of the 8.3k buffers) moved out of the shared heaps: heaps 12 -> 8 and heap in use down 252 MB (-40%). The cost is creation: 242.5 us per buffer made on average against 20.6 us, 2.0 s against 0.2 s in all - a little below the 300-345 us the description reports (and far from the 715-848 us with every BLAS committed). No device loss in either run. Caveat: the run included menu time, so the sample means (placed 1,273 / committed 724 on average) say little; the end state and the per-buffer cost do not depend on play time. Not tested: `DARNER_HW_RT_REFIT_COMMITTED=0` on this GPU, other GPUs, and frame rate (the scenes and durations differ). Drafted with AI assistance (OpenCode).
TrustNo1 manually merged commit 0600e87b0d into main 2026-12-05 04:51:36 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!445
No description provided.