Repository navigation
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
Closed
buddybot89 wants to merge 1 commit into
buddybot89 wants to merge 1 commit into
Conversation
…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>
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
In the synthetic frame that
tests/replay.rsrecords (replay/testing.rs), each compute pass now ends with a transition ofreplay test: resultsfromUNORDERED_ACCESStoALL_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 atreplay.rs:76because the picture changed from loop to loop:The draws' pixel shader reads
resultsas a root SRV (shades) right after the pass that writes it, with only a UAV barrier in between. D3D12 needs a transition fromUNORDERED_ACCESSto 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:
keep_clampsThe changed pixels were off by a few units in red and green, which is the
shade * 0.25term the shader takes fromresults. Theresultsbuffer 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.shWine (the full-suite runs below were on5b57b11):tests/replay.rs: failed 6 of 6 runs before the change, passed 8 of 8 after, including 3 withWINEDLLOVERRIDES="d3d12,d3d12core,dxgi=b".51b1d12:tests/replay.rsfailed 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.cargo clippy --target x86_64-pc-windows-gnullvmruns (with and without--all-features,-D warnings) are clean, andcargo xtask policypasses.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