[pr-fix][RAYTRACING] hwrt: a refit reads only a source whose build has been submitted (DARNER_HW_RT_REFIT_BUILT, on by default) #446

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

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: read from the code, then counted in the game. A BLAS is in the map from when its build is recorded, but lists are recorded on several threads and submitted in the title's order. A refit can name a source whose build is in a list submitted after the refit's, or in one never submitted, and then reads whatever that source's memory holds. In runs on an RX 7900 XTX with this change, 64 or more refits a run were built anew for this reason in the first ~10 s.

Each BLAS now carries a flag that is set when the list recording its build is submitted (HostList::at_submit). A refit whose source is not flagged yet is built anew instead, as a request that matches no source. The first eight such refits, then every power of two, are logged. DARNER_HW_RT_REFIT_BUILT=0 gives the old behaviour.

This is a real ordering hole, but not the cause of the "device hung" with hardware RT on the RX 7900 XTX: on its own it still hung 7 of 7 runs. That hang is the subject of #445.

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 78cff43); hwrt.rs is the same file at f3840d7 and 47d21cd. Not run in the game on 47d21cd.

  • Commands and results: the game runs below; the gates below.

  • Changes a default: yes, for every card with hardware ray tracing on.

  • 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) B (on: this change)
    On f3840d7 alone 8 of 10 runs hung 7 of 7 runs hung; 64+ refits a run built anew in the first ~10 s
    With #445 0 of 3 runs hung, 30.6 to 32.4 fps 0 of 9 runs hung, 30.5 to 33.6 fps
  • Gates run on 78cff43 (there is no CI): gates 1 and 2 (cargo clippy --workspace --all-targets --locked -- -D warnings, without and with --all-features) passed. Gate 3: not the full cargo test --workspace --locked (it ran over 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,989 passed, 5 failed, 82 ignored. The 5 are thread-timing tests outside hwrt.rs (in gpu_owned, watch, host::watch_pipe and rangelock); each passed when rerun. The game was running on the same PC during part of these test runs. Such tests also fail now and then on main: gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback failed 1 of 10 runs on 47d21cd.

  • 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: likely general (an ordering question, not a card's); tested only on an RX 7900 XTX.

  • Coverage gaps: no frame-rate figure for this change alone; not run on NVIDIA or Intel cards.

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: #445 (committed buffers for refittable BLASes), #268 (in-flight HostAs reuse; it also holds back copies whose source is not built yet, which are copies, not refits), #318, #279 (also change hwrt.rs).
  • Replaces or overlaps: none found

🤖 Generated with Claude Code

## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: read from the code, then counted in the game. A BLAS is in the map from when its build is recorded, but lists are recorded on several threads and submitted in the title's order. A refit can name a source whose build is in a list submitted after the refit's, or in one never submitted, and then reads whatever that source's memory holds. In runs on an RX 7900 XTX with this change, 64 or more refits a run were built anew for this reason in the first ~10 s. Each BLAS now carries a flag that is set when the list recording its build is submitted (`HostList::at_submit`). A refit whose source is not flagged yet is built anew instead, as a request that matches no source. The first eight such refits, then every power of two, are logged. `DARNER_HW_RT_REFIT_BUILT=0` gives the old behaviour. This is a real ordering hole, but not the cause of the "device hung" with hardware RT on the RX 7900 XTX: on its own it still hung 7 of 7 runs. That hang is the subject of #445. ## 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 `78cff43`); `hwrt.rs` is the same file at `f3840d7` and `47d21cd`. Not run in the game on `47d21cd`. - Commands and results: the game runs below; the gates below. - Changes a default: yes, for every card with hardware ray tracing on. - 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) | B (on: this change) | |---|---|---| | On `f3840d7` alone | 8 of 10 runs hung | 7 of 7 runs hung; 64+ refits a run built anew in the first ~10 s | | With #445 | 0 of 3 runs hung, 30.6 to 32.4 fps | 0 of 9 runs hung, 30.5 to 33.6 fps | - Gates run on `78cff43` (there is no CI): gates 1 and 2 (`cargo clippy --workspace --all-targets --locked -- -D warnings`, without and with `--all-features`) passed. Gate 3: not the full `cargo test --workspace --locked` (it ran over 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,989 passed, 5 failed, 82 ignored. The 5 are thread-timing tests outside `hwrt.rs` (in `gpu_owned`, `watch`, `host::watch_pipe` and `rangelock`); each passed when rerun. The game was running on the same PC during part of these test runs. Such tests also fail now and then on main: `gpu_owned::tests::concurrent_faults_on_same_block_serialize_single_readback` failed 1 of 10 runs on `47d21cd`. - 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: likely general (an ordering question, not a card's); tested only on an RX 7900 XTX. - Coverage gaps: no frame-rate figure for this change alone; not run on NVIDIA or Intel cards. ## 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: #445 (committed buffers for refittable BLASes), #268 (in-flight `HostAs` reuse; it also holds back copies whose source is not built yet, which are copies, not refits), #318, #279 (also change `hwrt.rs`). - Replaces or overlaps: none found 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The map of acceleration structures holds an entry from when its build
is recorded. Lists are recorded on several threads and submitted in the
title's order, so a refit could name a source whose build had not been
submitted (or never was) and read whatever its memory held. Such a
request is now built anew. DARNER_HW_RT_REFIT_BUILT=0: as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor

I checked the tests at 78cff430. I see coverage for refit budgeting and masking unbuilt structures, but not for the refit planner’s decision before and after the source build is submitted. I’d like to add a game-free regression that checks for a full build before submission and a refit afterward, with a dropped list as a negative control. Is anyone already covering that, or would you like me to take it?

I checked the tests at `78cff430`. I see coverage for refit budgeting and masking unbuilt structures, but not for the refit planner’s decision before and after the source build is submitted. I’d like to add a game-free regression that checks for a full build before submission and a refit afterward, with a dropped list as a negative control. Is anyone already covering that, or would you like me to take it?
Contributor

Written by 🤖, results are mine.

NVIDIA data point, tested via my integration branch (theforgotten669/Darner integration/rtx4090 @ eba6512): 9800X3D, RTX 4090, driver 621.47, Series X 4K, DLSS Quality, FG 2x, hardware RT, Reflex boost.

The hole is hit far more here than the 64 in ~10 s on the 7900 XTX: the first "built anew instead" came ~21 s after hardware RT started, and the count passed 8,192 within 16 min (last logged refits=8192, at the power-of-two step). 19-min city drive: 1.1 M refits, 122 k BLAS builds, 83 k TLAS builds, no ERROR lines, no device removal, closed normally.

_Written by 🤖, results are mine._ NVIDIA data point, tested via my integration branch ([theforgotten669/Darner `integration/rtx4090` @ `eba6512`](https://git.gtahub.st/theforgotten669/Darner/src/branch/integration/rtx4090)): 9800X3D, RTX 4090, driver 621.47, Series X 4K, DLSS Quality, FG 2x, hardware RT, Reflex boost. The hole is hit far more here than the 64 in ~10 s on the 7900 XTX: the first "built anew instead" came ~21 s after hardware RT started, and the count passed **8,192** within 16 min (last logged `refits=8192`, at the power-of-two step). 19-min city drive: 1.1 M refits, 122 k BLAS builds, 83 k TLAS builds, no ERROR lines, no device removal, closed normally.
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), same save/area: main 47d21cd vs this PR 78cff43.

The ordering hole is real on NVIDIA too, not only on the RX 7900 XTX: the log's counter (the first eight refits, then every power of two) reached refits=128, so at least 128 refits named a source whose build had not been submitted (the true count is 128 to 255). The BLAS stats agree: blas_update_fb is 14 on main and 172 with this change.

main 47d21cd PR 78cff43
update fallbacks (blas_update_fb) 14 172
refits built anew (logged lower bound) - 128
BLAS builds 17,005 17,038
BLAS refits 479,838 560,493
Heap in use (end) 632 MB 596 MB
Device loss none none

The PR run was longer (5m52s against 5m11s), so the refit totals differ; per minute the refit rate is about the same (93k vs 95k), while blas_update_fb goes from 2.7 to 29 a minute. The 128 is a lower bound because only powers of two are logged.

Not tested: DARNER_HW_RT_REFIT_BUILT=0 on this GPU, other GPUs, and whether an image ever showed the bad read (no visual check beyond playing; no device loss in either run).

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`), same save/area: main `47d21cd` vs this PR `78cff43`. The ordering hole is real on NVIDIA too, not only on the RX 7900 XTX: the log's counter (the first eight refits, then every power of two) reached `refits=128`, so at least 128 refits named a source whose build had not been submitted (the true count is 128 to 255). The BLAS stats agree: `blas_update_fb` is 14 on main and 172 with this change. | | main `47d21cd` | PR `78cff43` | |---|---|---| | update fallbacks (`blas_update_fb`) | 14 | 172 | | refits built anew (logged lower bound) | - | 128 | | BLAS builds | 17,005 | 17,038 | | BLAS refits | 479,838 | 560,493 | | Heap in use (end) | 632 MB | 596 MB | | Device loss | none | none | The PR run was longer (5m52s against 5m11s), so the refit totals differ; per minute the refit rate is about the same (93k vs 95k), while `blas_update_fb` goes from 2.7 to 29 a minute. The 128 is a lower bound because only powers of two are logged. Not tested: `DARNER_HW_RT_REFIT_BUILT=0` on this GPU, other GPUs, and whether an image ever showed the bad read (no visual check beyond playing; no device loss in either run). Drafted with AI assistance (OpenCode).
First-time contributor

A case where this change stops a device loss: RTX 4080, a save that loses the device on main within a few loads.

A/B on this PR's commit 78cff43 (release profile), same save, same settings, same PC

DARNER_HW_RT_REFIT_BUILT Sessions Loads of the save Device lost
on (default) 3 10, 7, 12 0 of 3
0 3 1, 3, 1 3 of 3

The log confirmed on=true / on=false in every session. With it on, the counter's last logged step was 512, 256 and 512 (blas_update_fb 623 of 391,723 refits in the longest session). The first 16 came in the same millisecond the world first appeared.

The three losses with it off (0x887A0006): 10 s into the first world; 15 s into the third load; 11 s into the first world.

Unpatched builds, for reference: main d91d8e4 lost the device 1 s into its second load. Release f3840d7 lost it in every session where the save was loaded a second time (three sessions), and in none where it was loaded once.

Steps: hardware RT on, DARNER_THIN=1. Load a save, wait until in the world, load the same save again; repeat.

Two signatures, one build. Of the three switch-off losses on 78cff43, one was nvlddmkm event 13 Graphics SM Warp Exception ... MMU Fault, ESR ...=0xf812b60 ...=0x1104 (the signature #279 names, and the one main and f3840d7 gave every time). The other two had no event 13: three event 153 over 5 s and 23 to 25 submissions on the card with none finishing for 3 to 4.5 s, which reads as a hang. Same exe, same switch, so the same hole seems to end either way. A local build carrying #279 and #268 lost the device with the MMU fault too, three times.

Where the card stops. Light breadcrumbs on f3840d7 (DARNER_D3D12_DRED=light, diag): a list stopped at command 650 of 963 (op 31) of "darner host list 129", commands 649 to 657 all op 31 (BuildRaytracingAccelerationStructure); every other list finished or not begun. The last things recorded, on two threads within 80 ms: 88 structure copies (mode 1), about 100 BLAS builds and rehydrates, and 5 TLAS builds on each of two lists. With the debug layer or full breadcrumbs the game ran at half speed and did not lose the device, so those gave nothing.

Two notes on the counter

  • source_built is tested before allow_update, update_scratch, the flags and geom_keys, so it also counts sources that would not have been refitted anyway. The logged figure is an upper bound on the refits this change turns into builds; tested last in that chain it would be exact.
  • A local patch of the same idea looked at each such refit again when its own list was submitted. In a 20 min session with about 12 loads: 481 had their source built by then (recorded ahead of the submitting thread; the refit would have been sound), 26 still had not. The 26 came in two bursts of 14 and 12, each within 2 s of a load ending. That split could be logged from at_submit to tell the harmless cases from the others.

Not tested: #445 (not applied in any run above); long play sessions.

RTX 4080 16 GB, driver 621.47, Ryzen 7 9850X3D, 32 GB, Windows 11. Series S profile, 2560x1440 output, DLSS Quality, frame generation off, DARNER_HW_RT=1 DARNER_RELAY=2 DARNER_THIN=1 DARNER_CARD_STEPS=2.

Drafted with AI assistance (Claude Code); the runs and results are mine.

A case where this change stops a device loss: RTX 4080, a save that loses the device on main within a few loads. **A/B on this PR's commit `78cff43` (release profile), same save, same settings, same PC** | `DARNER_HW_RT_REFIT_BUILT` | Sessions | Loads of the save | Device lost | |---|---|---|---| | on (default) | 3 | 10, 7, 12 | 0 of 3 | | `0` | 3 | 1, 3, 1 | 3 of 3 | The log confirmed `on=true` / `on=false` in every session. With it on, the counter's last logged step was 512, 256 and 512 (`blas_update_fb` 623 of 391,723 refits in the longest session). The first 16 came in the same millisecond the world first appeared. The three losses with it off (`0x887A0006`): 10 s into the first world; 15 s into the third load; 11 s into the first world. **Unpatched builds, for reference:** main `d91d8e4` lost the device 1 s into its second load. Release `f3840d7` lost it in every session where the save was loaded a second time (three sessions), and in none where it was loaded once. **Steps:** hardware RT on, `DARNER_THIN=1`. Load a save, wait until in the world, load the same save again; repeat. **Two signatures, one build.** Of the three switch-off losses on `78cff43`, one was nvlddmkm event 13 `Graphics SM Warp Exception ... MMU Fault`, `ESR ...=0xf812b60 ...=0x1104` (the signature #279 names, and the one main and `f3840d7` gave every time). The other two had no event 13: three event 153 over 5 s and 23 to 25 submissions on the card with none finishing for 3 to 4.5 s, which reads as a hang. Same exe, same switch, so the same hole seems to end either way. A local build carrying #279 and #268 lost the device with the MMU fault too, three times. **Where the card stops.** Light breadcrumbs on `f3840d7` (`DARNER_D3D12_DRED=light`, diag): `a list stopped at command 650 of 963 (op 31) of "darner host list 129"`, commands 649 to 657 all op 31 (`BuildRaytracingAccelerationStructure`); every other list finished or not begun. The last things recorded, on two threads within 80 ms: 88 structure copies (mode 1), about 100 BLAS builds and rehydrates, and 5 TLAS builds on each of two lists. With the debug layer or full breadcrumbs the game ran at half speed and did not lose the device, so those gave nothing. **Two notes on the counter** - `source_built` is tested before `allow_update`, `update_scratch`, the flags and `geom_keys`, so it also counts sources that would not have been refitted anyway. The logged figure is an upper bound on the refits this change turns into builds; tested last in that chain it would be exact. - A local patch of the same idea looked at each such refit again when its own list was submitted. In a 20 min session with about 12 loads: 481 had their source built by then (recorded ahead of the submitting thread; the refit would have been sound), 26 still had not. The 26 came in two bursts of 14 and 12, each within 2 s of a load ending. That split could be logged from `at_submit` to tell the harmless cases from the others. **Not tested:** #445 (not applied in any run above); long play sessions. RTX 4080 16 GB, driver 621.47, Ryzen 7 9850X3D, 32 GB, Windows 11. Series S profile, 2560x1440 output, DLSS Quality, frame generation off, `DARNER_HW_RT=1 DARNER_RELAY=2 DARNER_THIN=1 DARNER_CARD_STEPS=2`. Drafted with AI assistance (Claude Code); the runs and results are mine.
TrustNo1 manually merged commit c0dc281b57 into main 2026-12-05 04:51:37 +00:00
Contributor

Data point from an RTX 4070 Ti 12 GB on the release: the guard fires 64 to 255 times in every world entry here, and the one Aftermath dump I have of our world-entry loss on a build without it points at an AS build or refit.

PC: RTX 4070 Ti 12 GB, driver 621.24, Ryzen 7 7800X3D, Windows 11. Native 1440p, hardware RT, no frame generation, one save started from the command line.

With the guard (own release build of 9b288a70): 6 launches of 90 s, each 41 to 46 s in the world.

Launch Last refits= logged on "a refit's source not built yet ... built anew instead" Event 13 / device loss
1 64 none
2 128 none
3 64 none
4 64 none
5 64 none
6 128 none

The line prints at powers of two, so that is 64 to 127 or 128 to 255 refits a launch, all in the first seconds of the world.

Without it (f3840d73, today, with the Aftermath Monitor running): one launch lost the device 11 s after the first world draws, still streaming in. nvlddmkm 13 "MMU Fault" on one SM, 0x887A0006. The dump says page fault, "Failed to translate the virtual address", and the faulting warp is in the driver's ray_tracing_01, type "AS Build or Refit". No title shader is named.

  • That loss is the kind I have been seeing on about 8% of hardware-RT launches on builds from before this PR (event 13 MMU fault within about 12 s of entering the world).
  • I can't tie the dump to a refit for certain: it says "build or refit", and the last hwrt line before the loss showed 0 refits in its interval, with 2,456 rehydrates and 579 builds waiting.
  • Six clean launches don't prove much against an 8% rate (about a 60% chance of seeing one even with no change). The counter is the stronger part: the case this PR closes happens dozens of times per entry on this card.

I'll say so here if the loss shows up on the release.

Data point from an RTX 4070 Ti 12 GB on the release: the guard fires 64 to 255 times in every world entry here, and the one Aftermath dump I have of our world-entry loss on a build without it points at an AS build or refit. **PC:** RTX 4070 Ti 12 GB, driver 621.24, Ryzen 7 7800X3D, Windows 11. Native 1440p, hardware RT, no frame generation, one save started from the command line. **With the guard (own release build of `9b288a70`):** 6 launches of 90 s, each 41 to 46 s in the world. | Launch | Last `refits=` logged on "a refit's source not built yet ... built anew instead" | Event 13 / device loss | |---|---|---| | 1 | 64 | none | | 2 | 128 | none | | 3 | 64 | none | | 4 | 64 | none | | 5 | 64 | none | | 6 | 128 | none | The line prints at powers of two, so that is 64 to 127 or 128 to 255 refits a launch, all in the first seconds of the world. **Without it (`f3840d73`, today, with the Aftermath Monitor running):** one launch lost the device 11 s after the first world draws, still streaming in. `nvlddmkm` 13 "MMU Fault" on one SM, `0x887A0006`. The dump says page fault, "Failed to translate the virtual address", and the faulting warp is in the driver's `ray_tracing_01`, type "AS Build or Refit". No title shader is named. - That loss is the kind I have been seeing on about 8% of hardware-RT launches on builds from before this PR (event 13 MMU fault within about 12 s of entering the world). - I can't tie the dump to a refit for certain: it says "build or refit", and the last hwrt line before the loss showed 0 refits in its interval, with 2,456 rehydrates and 579 builds waiting. - Six clean launches don't prove much against an 8% rate (about a 60% chance of seeing one even with no change). The counter is the stronger part: the case this PR closes happens dozens of times per entry on this card. I'll say so here if the loss shows up on the release.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
6 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!446
No description provided.