Fence waits for new memory and deferred residency check for device loss; narrow barrier groups keep the whole call beside a UAV wildcard #634

Open
deama wants to merge 2 commits from deama/Darner:c14/barriers-fences into Main
First-time contributor

Run in the game only inside a combined test build (official main c8258f9 + #594–#601 + this PR + the two other fix PRs from the same source), not on its own. Ported from uncommitted "Patch C14" work in a local VIctory-NVIDIA tree (before the rename), written to stop GPU timeouts. Both problems were found by reading the code, not in a run.

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: read from the code.
    • mapped() and with_copy_queue_sync() signal the aside COPY queue and wait only while the fence reads below the target. A lost device (every fence reads u64::MAX) passes at once, and WaitForSingleObject's result is ignored. Both report the memory as mapped, or the tile mappings done, when nothing ran.
    • With DARNER_RESIDENT_LATER=1, wait_asked passes a lost device in the same way, spins when the event can't be made or set, and moves SETTLED even when mapped() failed, so descriptor slots naming non-resident memory get written. before_send() sends the lists without the wait on a lost device or a failed queue Wait.
    • With DARNER_NARROW_BARRIERS naming groups: the first record of a call that needs a UAV barrier on every resource ends the replay with only that wildcard, dropping the call's scoped globals and buffer barriers (a UAV barrier orders only unordered access, not render targets, copies or reads after a write). A null-resource buffer barrier sends the whole call to the global fallback. A texture barrier mixing UAV with another access and a SYNC_NONE side is skipped.

Two commits:

  • host: fence waits for new memory and deferred residency are checked

  • list: narrow barrier groups keep the whole call beside a UAV wildcard

  • Aside::signal_and_wait returns an error for a lost device and a failed wait, and reads the fence again after waking. Callers already warn and degrade on errors.

  • DARNER_RESIDENT_LATER=1 uses wait_host_fence. A lost device, a failed wait or a failed mapped() end the run (fail) before SETTLED moves. before_send() ends the run on a lost device or a failed queue Wait.

  • Narrow-groups replay gathers every record, records the enhanced globals and buffer barriers, then adds the one UAV wildcard (skipped when an ALL → ALL global was recorded, which covers it). Without list7 the wildcard is recorded as before, and buffer references are still released. Mixed texture UAV↔other access is a scoped global even with a SYNC_NONE side (widened to ALL by safe_sync); only pure UAV→UAV stays a single-texture UAV barrier.

  • Left out from the source: compute-queue and PARTS_ONE_CALL submission paths and a JOIN_NOWAIT join check (Darner has no compute queue, and its split path already runs before_send before every ExecuteCommandLists, #190), and the uavonly-mode require_scope flag (Darner has no such mode).

How it was tested

  • Tested revision: 45e04e0d90 (branch head; gates below). Game runs used a combined test build that contains it.
  • Commands and results: on 45e04e0d90, Windows 10 22H2 with its built-in Direct3D 12 (no Shader Model 6.6), Rust 1.98.1:
    • cargo clippy --workspace --all-targets --locked -- -D warnings: passed
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed
    • cargo --config 'profile.test.package.darner-shader.opt-level=3' test --workspace --locked --no-fail-fast (the opt-level only speeds up darner-shader's exhaustive float tests): 66 failed, all of which fail on unmodified main (c8258f9556) on this PC too (darner-shader tests that need Shader Model 6.6).
    • darner-gpu's test process aborts at the first test that needs Shader Model 6.6, on main too, so its tests were run in batches that survive the abort and compared one by one with main (main: 1658 pass, 8 fail, 139 need Shader Model 6.6, 81 ignored): no test that passes on main fails here, none removed; 3 new tests: 3 pass.
    • cargo xtask policy: ok (576 files).
  • Game, combined test build, RTX 4080 16 GB (PCIe 4.0 x4), Windows 10 22H2, driver 581.80, Agility SDK 1.621.0, 4K, DLSS Balanced, Series X profile, no frame generation, outdoor checkpoint (harness from #596): a strict debug-layer run (from #594) loaded and drew at the outdoor pose with no message from these paths. The one debug-layer message (1047, cross-queue write on a pooled texture) also appears in a build of main + #594 + #596 alone, so it predates this change. DARNER_NARROW_BARRIERS and DARNER_RESIDENT_LATER were at their defaults (off), so the changed barrier and residency paths did not run in the game.
  • Changes a default: no switch defaults change. With defaults, the only behaviour change is that mapped() / with_copy_queue_sync() return an error on a lost device or failed wait instead of success.
  • A/B result: not applicable (no default changed; the opt-in modes were checked by unit tests only).
  • Gates run on that revision: see above.
  • Hardware dependence: likely general.
  • Coverage gaps: device loss can't easily be simulated in a test, so the fence paths are untested at run time. In narrow-groups mode, a common first-use barrier (NO_ACCESS→UAV with SYNC_NONE before) now becomes an ALL→X global, which is safer but may cost frame time (not measured). Without enhanced barriers or list7, a mixed texture dependency still gets only a null UAV barrier.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). Only inside the combined build; the opt-in paths it changes were off.
  • 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: #57 (DARNER_RESIDENT_LATER: before_send() also waits for the mapping on the sending thread). It touches the same wait_asked and before_send code and the two combine: #57 adds the mapping wait, and this PR makes those waits fail on a lost device or failed wait instead of passing. Whichever merges second needs a rebase. #599 (title-barrier timing): whichever merges second keeps #599's record_title_barrier wrapper around this PR's Barrier and ResourceBarrier calls in list.rs. Also #517 (console flags on UAV/aliasing barriers, different barriers) and #93 (DARNER_LATE_FENCE, a different fence wait).
  • Replaces or overlaps: none found
**Run in the game only inside a combined test build** (official `main` c8258f9 + #594–#601 + this PR + the two other fix PRs from the same source), not on its own. Ported from uncommitted "Patch C14" work in a local VIctory-NVIDIA tree (before the rename), written to stop GPU timeouts. Both problems were found by reading the code, not in a run. ## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: read from the code. - `mapped()` and `with_copy_queue_sync()` signal the aside COPY queue and wait only while the fence reads below the target. A lost device (every fence reads `u64::MAX`) passes at once, and `WaitForSingleObject`'s result is ignored. Both report the memory as mapped, or the tile mappings done, when nothing ran. - With `DARNER_RESIDENT_LATER=1`, `wait_asked` passes a lost device in the same way, spins when the event can't be made or set, and moves `SETTLED` even when `mapped()` failed, so descriptor slots naming non-resident memory get written. `before_send()` sends the lists without the wait on a lost device or a failed queue `Wait`. - With `DARNER_NARROW_BARRIERS` naming `groups`: the first record of a call that needs a UAV barrier on every resource ends the replay with only that wildcard, dropping the call's scoped globals and buffer barriers (a UAV barrier orders only unordered access, not render targets, copies or reads after a write). A null-resource buffer barrier sends the whole call to the global fallback. A texture barrier mixing UAV with another access and a `SYNC_NONE` side is skipped. Two commits: - host: fence waits for new memory and deferred residency are checked - list: narrow barrier groups keep the whole call beside a UAV wildcard - `Aside::signal_and_wait` returns an error for a lost device and a failed wait, and reads the fence again after waking. Callers already warn and degrade on errors. - `DARNER_RESIDENT_LATER=1` uses `wait_host_fence`. A lost device, a failed wait or a failed `mapped()` end the run (`fail`) before `SETTLED` moves. `before_send()` ends the run on a lost device or a failed queue `Wait`. - Narrow-groups replay gathers every record, records the enhanced globals and buffer barriers, then adds the one UAV wildcard (skipped when an `ALL → ALL` global was recorded, which covers it). Without list7 the wildcard is recorded as before, and buffer references are still released. Mixed texture UAV↔other access is a scoped global even with a `SYNC_NONE` side (widened to ALL by `safe_sync`); only pure UAV→UAV stays a single-texture UAV barrier. - Left out from the source: compute-queue and `PARTS_ONE_CALL` submission paths and a `JOIN_NOWAIT` join check (Darner has no compute queue, and its split path already runs `before_send` before every `ExecuteCommandLists`, #190), and the `uavonly`-mode `require_scope` flag (Darner has no such mode). ## How it was tested - Tested revision: `45e04e0d90` (branch head; gates below). Game runs used a combined test build that contains it. - Commands and results: on `45e04e0d90`, Windows 10 22H2 with its built-in Direct3D 12 (no Shader Model 6.6), Rust 1.98.1: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed - `cargo --config 'profile.test.package.darner-shader.opt-level=3' test --workspace --locked --no-fail-fast` (the opt-level only speeds up darner-shader's exhaustive float tests): 66 failed, all of which fail on unmodified `main` (c8258f9556) on this PC too (darner-shader tests that need Shader Model 6.6). - darner-gpu's test process aborts at the first test that needs Shader Model 6.6, on `main` too, so its tests were run in batches that survive the abort and compared one by one with `main` (`main`: 1658 pass, 8 fail, 139 need Shader Model 6.6, 81 ignored): no test that passes on `main` fails here, none removed; 3 new tests: 3 pass. - `cargo xtask policy`: ok (576 files). - Game, combined test build, RTX 4080 16 GB (PCIe 4.0 x4), Windows 10 22H2, driver 581.80, Agility SDK 1.621.0, 4K, DLSS Balanced, Series X profile, no frame generation, outdoor checkpoint (harness from #596): a strict debug-layer run (from #594) loaded and drew at the outdoor pose with no message from these paths. The one debug-layer message (1047, cross-queue write on a pooled texture) also appears in a build of main + #594 + #596 alone, so it predates this change. `DARNER_NARROW_BARRIERS` and `DARNER_RESIDENT_LATER` were at their defaults (off), so the changed barrier and residency paths did not run in the game. - Changes a default: no switch defaults change. With defaults, the only behaviour change is that `mapped()` / `with_copy_queue_sync()` return an error on a lost device or failed wait instead of success. - A/B result: not applicable (no default changed; the opt-in modes were checked by unit tests only). - Gates run on that revision: see above. - Hardware dependence: likely general. - Coverage gaps: device loss can't easily be simulated in a test, so the fence paths are untested at run time. In narrow-groups mode, a common first-use barrier (NO_ACCESS→UAV with `SYNC_NONE` before) now becomes an ALL→X global, which is safer but may cost frame time (not measured). Without enhanced barriers or list7, a mixed texture dependency still gets only a null UAV barrier. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). Only inside the combined build; the opt-in paths it changes were off. - [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: #57 (`DARNER_RESIDENT_LATER`: `before_send()` also waits for the mapping on the sending thread). It touches the same `wait_asked` and `before_send` code and the two combine: #57 adds the mapping wait, and this PR makes those waits fail on a lost device or failed wait instead of passing. Whichever merges second needs a rebase. #599 (title-barrier timing): whichever merges second keeps #599's `record_title_barrier` wrapper around this PR's `Barrier` and `ResourceBarrier` calls in `list.rs`. Also #517 (console flags on UAV/aliasing barriers, different barriers) and #93 (`DARNER_LATE_FENCE`, a different fence wait). - Replaces or overlaps: none found
`mapped()` and `with_copy_queue_sync()` signalled the aside COPY queue and
waited only while the fence read below the value: a lost device (every
fence reads `u64::MAX`) passed at once, and `WaitForSingleObject`'s result
was not looked at, so both said the memory was mapped, or the tile
mappings were done, when nothing had run. `Aside::signal_and_wait` now
returns an error for a lost device and a failed wait, and reads the fence
again after waking.

With `DARNER_RESIDENT_LATER=1`, `wait_asked` likewise passed a lost device,
spun instead when the event could not be made or set, and moved
`SETTLED` even when `mapped()` failed, so descriptor slots naming memory
that was not resident were written. It now uses `wait_host_fence`, and a
lost device, a failed wait or a failed `mapped()` end the run (`fail`)
before `SETTLED` moves. `before_send()` ends the run on a lost device or a
failed queue `Wait` instead of sending the lists without the wait.

Ported from VIctory-NVIDIA's uncommitted Patch C14 work (track 2 and
blocker 8 of its audit), found by reading the code, not in a run. Left
out: the `before_send` calls Codex added on compute-queue and
`PARTS_ONE_CALL` submissions (Darner sends every title list to the one
direct queue, and its split path already runs `before_send` before every
`ExecuteCommandLists`, #190), the `joinable` change for `JOIN_NOWAIT`, and
the `DARNER_RELAY_COPY` warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `DARNER_NARROW_BARRIERS` naming `groups`, the first record of a call
that needed a UAV barrier on every resource (a texture or buffer with no
host copy, a global without enhanced barriers) ended the replay with only
that barrier: the scoped globals and buffer barriers of the same call were
dropped, and a UAV barrier orders only unordered access, not render
targets, copies or shader reads after a write. A buffer barrier with no
resource made the whole call the global fallback at packing, for the same
result. Replay now gathers every record (`collect_narrow_barriers`),
records the enhanced globals and buffer barriers, and adds the one UAV
wildcard after them (`BarScratch::record`), unless an `ALL -> ALL` global
was recorded, which covers it. Without list7 the wildcard is recorded as
before; the buffers' references are still released by the scratch guard.

A texture barrier whose unordered access meets any other access (UAV <->
SRV, UAV -> UAV | SRV) is now a scoped global even with a `SYNC_NONE` side,
which `safe_sync` widens to ALL; it used to be skipped. Only pure UAV ->
UAV stays a single-texture UAV barrier.

Ported from VIctory-NVIDIA's uncommitted Patch C14 work (track 2, and the
replay half of fix A for blocker 6 of its audit), found by reading the
code, not in a run. Left out: the `require_scope` flag and the compute-list
`compute_sync` path, which serve VIctory's `uavonly` narrow mode and its
compute host lists; Darner has neither (every host list is a direct list,
`host::two_queues`), so every scoped global is already recorded as an
enhanced global wherever the device has enhanced barriers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TrustNo1 changed title from [pr-fix][rendering] Fence waits for new memory and deferred residency check for device loss; narrow barrier groups keep the whole call beside a UAV wildcard to Fence waits for new memory and deferred residency check for device loss; narrow barrier groups keep the whole call beside a UAV wildcard 2026-12-06 03:25:50 +00:00
Owner

Test needed — commit 45e04e0d; what to check:

  • The problem on main: read from the code.
    • mapped() and with_copy_queue_sync() signal the aside COPY queue and wait only while the fence reads below the target. A lost device (every fence reads u64::MAX) passes at once, and WaitForSingleObject's result is ignored. Both report the memory as mapped, or the tile mappings done, when nothing ran.
    • With DARNER_RESIDENT_LATER=1, wait_asked passes a lost device in the same way, spins when the event can't be made or set, and moves SETTLED even when mapped() failed, so descriptor slots naming non-resident memory get written. before_send() sends the lists without the wait on a lost device or a failed queue Wait.
    • With DARNER_NARROW_BARRIERS naming groups: the first record of a call that needs a UAV barrier on every resource ends the replay with only that wildcard, dropping the call's scoped globals and buffer barriers (a UAV barrier orders only unordered access, not render targets, copies or reads after a write). A null-resource buffer barrier sends the whole call to the global fallback. A texture barrier mixing UAV with another access and a SYNC_NONE side is skipped.

Two commits:

  • host: fence waits for n

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `45e04e0d`; what to check: - The problem on main: read from the code. - `mapped()` and `with_copy_queue_sync()` signal the aside COPY queue and wait only while the fence reads below the target. A lost device (every fence reads `u64::MAX`) passes at once, and `WaitForSingleObject`'s result is ignored. Both report the memory as mapped, or the tile mappings done, when nothing ran. - With `DARNER_RESIDENT_LATER=1`, `wait_asked` passes a lost device in the same way, spins when the event can't be made or set, and moves `SETTLED` even when `mapped()` failed, so descriptor slots naming non-resident memory get written. `before_send()` sends the lists without the wait on a lost device or a failed queue `Wait`. - With `DARNER_NARROW_BARRIERS` naming `groups`: the first record of a call that needs a UAV barrier on every resource ends the replay with only that wildcard, dropping the call's scoped globals and buffer barriers (a UAV barrier orders only unordered access, not render targets, copies or reads after a write). A null-resource buffer barrier sends the whole call to the global fallback. A texture barrier mixing UAV with another access and a `SYNC_NONE` side is skipped. Two commits: - host: fence waits for n Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request has changes conflicting with the target branch.
  • crates/darner-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'c14/barriers-fences:deama-c14/barriers-fences'
git switch 'deama-c14/barriers-fences'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'deama-c14/barriers-fences'
git switch 'deama-c14/barriers-fences'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'deama-c14/barriers-fences'
git switch 'deama-c14/barriers-fences'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'deama-c14/barriers-fences'
git switch 'Main'
git merge --squash 'deama-c14/barriers-fences'
git switch 'Main'
git merge --ff-only 'deama-c14/barriers-fences'
git switch 'Main'
git merge 'deama-c14/barriers-fences'
git push origin 'Main'
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!634
No description provided.