Skip to content

fix(gpu): move the replay test's results to a shader resource before the draws read them - #703

Closed
buddybot89 wants to merge 1 commit into
pragyaangaur:mainfrom
buddybot89:buddybot89/replay-test-results-transition
Closed

buddybot89 wants to merge 1 commit into
pragyaangaur:mainfrom
buddybot89:buddybot89/replay-test-results-transition

Conversation

@buddybot89

Copy link
Copy Markdown

What

In the synthetic frame that tests/replay.rs records (replay/testing.rs), each compute pass now ends with a transition of replay test: results from UNORDERED_ACCESS to ALL_SHADER_RESOURCE, right after its UAV barrier.

Why

a_frame_recorded_through_the_host_layer_is_replayed (added in #670) failed on every run on an M2 Ultra. Recording was fine. The first replay failed at replay.rs:76 because the picture changed from loop to loop:

pictures of the loops: 2 different: inf dB 6ea0abda, 47.5 dB f1e976c7, inf dB 6ea0abda
pictures of the loops: 2 different: 29.1 dB 6ea0abda, 29.2 dB f1e976c7, 29.2 dB f1e976c7
pictures of the loops: 3 different: inf dB ac39d983, 47.5 dB 33d5ed68, 29.1 dB f1e976c7

The draws' pixel shader reads results as a root SRV (shades) right after the pass that writes it, with only a UAV barrier in between. D3D12 needs a transition from UNORDERED_ACCESS to a shader-resource state before that read. D3DMetal appears to rely on that transition to make the render work wait for the compute work. Without it, the draws sometimes read the previous pass's results.

To find where it went wrong, I used a throwaway probe (not in this PR). It replayed the capture 6 times per mode and mapped the changed pixels onto the frame's rectangles:

Mode Before After
each submission waited (default) pink and green rectangles wrong in 5 of 6 loops same picture in 6 of 6
each list waited pink always right; green (pass and draw in one list) wrong 6 of 6
one submission wrong 6 of 6
keep_clamps wrong 6 of 6

The changed pixels were off by a few units in red and green, which is the shade * 0.25 term the shader takes from results. The results buffer itself was correct after every run.

How it was tested

Mac Studio, M2 Ultra, 64 GB, macOS 26.7.1, GPTK 4.0 beta 3, ./setup.sh Wine (the full-suite runs below were on 5b57b11):

  • tests/replay.rs: failed 6 of 6 runs before the change, passed 8 of 8 after, including 3 with WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=b".
  • Again on current main 51b1d12: tests/replay.rs failed 3 of 3 runs without the change and passed 5 of 5 with it.
  • cargo test --workspace: 837 passed, 0 failed.
  • tools/macos/test-wine.sh --workspace --no-fail-fast: 1738 passed. One unrelated test failed in that full run: shadow::tests::marked_pages_go_back_by_the_bytes_the_gpu_changed (both writers' bytes, page 1: (0, 17) vs (187, 17)). It passed 6 of 6 times on its own and doesn't use the replay code, so it looks flaky under a parallel full-suite run on this machine.
  • Both cargo clippy --target x86_64-pc-windows-gnullvm runs (with and without --all-features, -D warnings) are clean, and cargo xtask policy passes.

Something to look at separately

This fixes the test frame, which wasn't valid D3D12. But the same pattern could also come from the host layer translating console command lists: a UAV barrier between a compute write and a graphics read, with no transition. If so, this race would affect real frames on some Macs, and the "stale layers" in the world could be one sign of it. I haven't checked; it just seems worth a look.

🤖 Generated with Claude Code

…the draws read them

The replay test frame wrote its results buffer in a compute pass and read
it as a root SRV in the following draws with only a UAV barrier between
them. D3D12 wants a transition from UNORDERED_ACCESS to a shader-resource
state there, and D3DMetal appears to need it to order the render work
after the compute work: on an M2 Ultra (macOS 26.7.1, GPTK 4.0 beta 3)
the draws read stale results and the replayed picture changed between
loops, failing tests/replay.rs on every run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pragyaangaur

Copy link
Copy Markdown
Owner

Thank you. This is the same change as #699, and it landed on main today in #702 (commit d983df0), with credit to #699. It is safe to close this one.

@buddybot89

Copy link
Copy Markdown
Author

Thanks, closing since #702 (d983df0) landed the same fix.

@buddybot89 buddybot89 closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants