hwrt: set the shadow buffer back to common after a DXR postbuild write (complements #3107) #3406

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u origin "fix/dxr-postbuild-barrier:fix/dxr-postbuild-barrier"
git switch "fix/dxr-postbuild-barrier"
Open
leonida/mandy
MoonEyes wants to merge 1 commit from fix/dxr-postbuild-barrier into main

This pull request has changes conflicting with the target branch.

Merge manually to resolve the conflicts.

Conversation
Reviewers 0 approvals
  • No reviewers
Details

This pull request has changes conflicting with the target branch.

Merge manually to resolve the conflicts.

  • d3d12/docs/findings.md
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 origin 'fix/dxr-postbuild-barrier:fix/dxr-postbuild-barrier'
git switch 'fix/dxr-postbuild-barrier'
Member

What changes

This complements #3107 (D3D12-HWRT-SPEC-AND-DISPATCH-GUARDS). #3107 handles the states of the postbuild scratch
pb_buf; it does not touch the title's shadow buffer sh.buffer, which this PR is about.

HwRtManager::emit_postbuild (d3d12/crates/leonida-gpu/src/hwrt.rs) writes the postbuild answer into sh.buffer:
WriteBufferImmediate for a size answer on main (a copy from pb_buf with #3107), CopyBufferRegion for a
serialization answer. The shadow buffer is in common state and the write promotes it to copy destination. A buffer
promoted to a write state keeps it until the command list ends, so a later command of the same list that reads it (the
title copies the size answer on, as a copy source) found it in a state the promotion rules do not allow.

Each answer that writes the shadow now ends with a barrier from copy destination back to common. In the copy path it
shares the ResourceBarrier that already set the scratch back to unordered access.

The order of the commands is a small table (PostbuildStep, postbuild_steps) that the recording loop follows, so it
can be tested without a device. findings.md has a short section on it.

With #3107: the two touch the same block of the size path. Whichever lands second takes both: the size steps become
scratch to copy dest, write into pb_buf, scratch to copy source, copy into sh.buffer, then one barrier with scratch
to unordered access and shadow to common.

Tests

  • cargo test -p leonida-gpu --locked: 730 passed, 0 failed, 59 ignored (Windows 11, no GPU needed).
  • New unit test hwrt::tests::a_postbuild_write_leaves_the_shadow_in_common_state: for every info type, the barrier
    comes after the last write and ends the steps.
  • python -I scripts/check_no_game_data.py on the touched files: clean.

In-game run required

Not run in game. Before merging: a run with hardware ray tracing on, on an RTX 4070 (the card that drives HW RT here),
300 s without device loss, and the debug layer quiet about the shadow buffer's state.

Credit

Ported from Darner commit 2519633 by Ondra97 (https://github.com/tyr0nsur/Darner, GPL-3.0-or-later, like this
repository). The credit is also in the code comment and the commit message.

AI assistance

AI-assisted: written by Claude Opus 5.5 (claude-opus-5-5) in Claude Code, reviewed by a separate Claude Opus 5.5
review agent that did not write it. Submitted by Moon.

🤖 Generated with Claude Code

### What changes This complements #3107 (D3D12-HWRT-SPEC-AND-DISPATCH-GUARDS). #3107 handles the states of the postbuild scratch `pb_buf`; it does not touch the title's shadow buffer `sh.buffer`, which this PR is about. `HwRtManager::emit_postbuild` (`d3d12/crates/leonida-gpu/src/hwrt.rs`) writes the postbuild answer into `sh.buffer`: `WriteBufferImmediate` for a size answer on main (a copy from `pb_buf` with #3107), `CopyBufferRegion` for a serialization answer. The shadow buffer is in common state and the write promotes it to copy destination. A buffer promoted to a write state keeps it until the command list ends, so a later command of the same list that reads it (the title copies the size answer on, as a copy source) found it in a state the promotion rules do not allow. Each answer that writes the shadow now ends with a barrier from copy destination back to common. In the copy path it shares the `ResourceBarrier` that already set the scratch back to unordered access. The order of the commands is a small table (`PostbuildStep`, `postbuild_steps`) that the recording loop follows, so it can be tested without a device. `findings.md` has a short section on it. **With #3107:** the two touch the same block of the size path. Whichever lands second takes both: the size steps become scratch to copy dest, write into `pb_buf`, scratch to copy source, copy into `sh.buffer`, then one barrier with scratch to unordered access and shadow to common. ### Tests - `cargo test -p leonida-gpu --locked`: 730 passed, 0 failed, 59 ignored (Windows 11, no GPU needed). - New unit test `hwrt::tests::a_postbuild_write_leaves_the_shadow_in_common_state`: for every info type, the barrier comes after the last write and ends the steps. - `python -I scripts/check_no_game_data.py` on the touched files: clean. ### In-game run required Not run in game. Before merging: a run with hardware ray tracing on, on an RTX 4070 (the card that drives HW RT here), 300 s without device loss, and the debug layer quiet about the shadow buffer's state. ### Credit Ported from Darner commit `2519633` by Ondra97 (https://github.com/tyr0nsur/Darner, GPL-3.0-or-later, like this repository). The credit is also in the code comment and the commit message. ### AI assistance AI-assisted: written by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, reviewed by a separate Claude Opus 5.5 review agent that did not write it. Submitted by Moon. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Complements #3107 (D3D12-HWRT-SPEC-AND-DISPATCH-GUARDS), which handles the
states of the postbuild scratch pb_buf but not of the title's shadow
buffer sh.buffer.

emit_postbuild writes sh.buffer (WriteBufferImmediate for a size answer on
main, a copy from pb_buf with #3107; CopyBufferRegion for a serialization
answer). The buffer is in common state and the write promotes it to copy
destination; a buffer promoted to a write state keeps it until the list
ends, so a later read of it in the same list (the title copies the size
answer on, as a copy source) found it in a state the promotion rules do
not allow. Each answer that writes the shadow now ends with a barrier from
copy destination back to common; in the copy path it shares the barrier
that sets the scratch back to unordered access.

The order of the commands is a small table (postbuild_steps) the recording
loop follows, so a unit test checks it for every info type: the barrier
comes after the last write and ends the steps.

If #3107 lands first, its size path becomes write-to-pb_buf then copy: the
size steps here then read [scratch to copy dest, write, scratch to source,
copy, scratch to uav + shadow to common]; the conflict is in that block.

Ported from Darner 2519633 (Ondra97, GPL-3.0-or-later).
Not run in game: needs a run with hardware ray tracing (RTX 4070).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OreoFR referenced this pull request from a commit 2026-12-04 02:26:46 +00:00
Sign in to join this conversation.
No description provided.