graphics: bind draw shader buffers after the draw inputs that can join them #2224
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2224
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2224/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Nawid3333 on GitHub · 2026-11-12 00:52 UTC · original
Nawid3333:fix/draw-inputs-before-buffer-bindings-r2→main· +250 −7 · 4 files · 3 commits · closed without mergingCause
RenderExecutor::ExecutePreparedDrawcallsPrepareGraphicsBindings(renderDraw.cpp:1112 atbc934ef03), which ends with theRebindBuffersloop (descriptors.cpp:913-918):NativeStorageBuffertakes the cache buffer of every storage binding of every stage. Only after that does the draw acquire its own inputs: the vertex buffers (AcquireVertexBuffers), the index buffer (PrepareIndexBuffer, orObtainBufferfor mesh indices) and the indirect arguments (ObtainBuffer, renderDraw.cpp:1113-1131).An input range that spans two existing cache buffers makes
ObtainBuffercreate one buffer over both:CreateBuffercallsJoinOverlap(bufferCache.cpp:402-417) and the old buffers are deleted (DeleteBuffer, bufferCache.cpp:154, which defers the erase to GPU completion). When one of those old buffers was a storage binding of the draw, the shader writes into the retired buffer, and every later read of that memory uses the new one, so the writes are lost.The compute path already acquires its indirect arguments before
RebindBuffers(renderCompute.cpp:512-516, "Acquiring arguments can merge cache buffers; finalize shader bindings afterward"). The draw path is the remaining case.Change
The
RebindBuffersloop, with its comment, moves from the end ofPrepareGraphicsBindingstoExecutePreparedDraw, after the vertex, index and indirect-argument acquisitions and beforeGetGraphicsPipeline(renderDraw.cpp:1132-1136 at 57aa9d7f7).ExecutePreparedDrawis the only caller ofPrepareGraphicsBindingsoutside the tests; the two test wrappers (RenderExecutorTestAccess::PrepareGraphicsBindings) callRebindBuffersafter it themselves, so the tests that use them keep their bindings.Closed #532 re-resolved every binding after every range-changing operation; it was closed after an in-game comparison showed corrupted geometry. This change keeps the existing binding code and only uses the order compute already uses.
Tests
shader_recompiler_compute_testsaddsCheckDrawStorageBufferJoinin two variants (selectors--draw-storage-join-onlyand--draw-index-storage-join-only, ctestgraphics_draw_storage_joinandgraphics_draw_index_storage_join). A vertex shader stores a marker word into a storage buffer. The storage buffer and the draw's indirect record (first variant) or its index range (second variant) sit in two separate 16 KiB cache buffers, and the record or index range crosses the page boundary between them, so acquiring it joins both. Before the draw the test checks two separate owners and a GPU-modified record (so the record does not take the streaming copy). After the draw it checks that the draw was accepted, merged both owners and covered the target, and then reads back the shader's output.On main (
bc934ef03) with the tests, both variants fail with every precondition passing:With the change both pass. The full suite (keep-going) has the same 22 failed checks with and without the change, with identical messages; they are failures of the test harness on this machine that were known before. This was run on an AMD RX 9070 XT with the local harness changes described in #2193.
Fork CI on this head (run 43100001998) passed on Windows, Linux and macOS.
Costs
None: the same calls run in another order.
In a game
No game is known to show this yet.
Written with Claude Code (AI): Codex found the ordering gap in a review of recent main commits; Claude Code wrote the test and the change and ran them.
@coderabbitai[bot] on GitHub · 2026-11-12 00:59 UTC · original · edited 2026-11-13 15:25 UTC
No actionable comments were generated in the recent review.
Walkthrough
Graphics draw execution now rebinds prepared shader-stage buffers after indirect-argument buffer acquisition and before pipeline and render-target setup. The change also adds tests for indirect and indexed draws whose records span separate buffer-cache pages, with dedicated command-line modes and CTest entries.
Suggested reviewers:
nmzik,defektu,senaxxChange: Bug fix · Severity of issue fixed: Medium
Merge Risk:
Minimal · up to
5c031The draw path now rebinds shader-stage buffers after draw inputs are acquired, and the new tests skip cleanly on devices that lack the required Vulkan feature. No merge-blocking risk remains.
Pre-merge checks:
4
#532, is closed and marked as historical context only. Its acceptance criteria do not apply to this pull request, so no active linked-issue coding requirements remain. …Full details: Title check
Explanation
The title names the main change: the draw path now rebinds shader buffers after the draw inputs that can join cache buffers are acquired. The changeset moves the RebindBuffers loop from PrepareGraphicsBindings to ExecutePreparedDraw, which matches the title. The title is long at 75 characters, but it is specific and accurate.
Full details: Description check
Explanation
The description explains the cause (RebindBuffers runs before vertex, index, and indirect-argument buffers are acquired, so a joined cache buffer can retire a bound storage buffer), the change (moving the loop after those acquisitions), and the tests (CheckDrawStorageBufferJoin with two ctest variants, with failing and passing results). It is directly related to the changeset.
Full details: Linked Issues check
Explanation
The only directly linked issue,
#532, is closed and marked as historical context only. Its acceptance criteria do not apply to this pull request, so no active linked-issue coding requirements remain. The pull request does not implement#532's requested redesign (PublishBuffers, FindPublishedOwner, published flag). It keeps the existing binding code and changes only the order of the RebindBuffers loop in the draw path. This difference does not fail the check because#532is not an active requirement. The incremental change since the previous reviewed head (57aa9d7f7 to5c031ba1) does not add any active requirement, so this verdict does not need reassessment against new issue text.Full details: Out of Scope Changes check
Explanation
All changes relate to the stated objective: the order of RebindBuffers relative to vertex, index and indirect-argument acquisition in the graphics draw path. descriptors.cpp removes the RebindBuffers loop from PrepareGraphicsBindings. renderDraw.cpp adds it to ExecutePreparedDraw after indirect-argument acquisition and before GetGraphicsPipeline. The test wrappers call RebindBuffers themselves, so existing test bindings are kept. CMakeLists.txt registers the two ctest entries for the new tests. ShaderRecompilerComputeTests.cpp adds CheckDrawStorageBufferJoin and its command-line selectors. The incremental change since 57aa9d7f7 adds the vertexPipelineStoresAndAtomics feature requirement to the test harness. The new vertex shader in CheckDrawStorageBufferJoin stores to a storage buffer, so this feature supports that test, and the test returns 77 when rasterization is unsupported. No unrelated change was identified. Test outcomes and fork CI were not re-run in this review. Evidence for the incremental change comes from the supplied change summary; the source diff was not separately read. This does not change the scope verdict.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
57337fd2-3e28-4c18-9b4b-f2f4dbdfd2ceReviewing files that changed from the base of the PR and between 57aa9d7f7f28fac788deff9441f28a806edb9501 and
5c031ba1ed.CMakeLists.txtsrc/graphics/host_gpu/renderer/pipeline/descriptors.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -20176,0 +20196,4 @@AppendVMovLiteral(&code, 9, marker);code.push_back(EncodeVop2(0x1a, 10, InlineU32(2), 5));code.push_back(EncodeMubuf0(0x1c));code.push_back(EncodeMubuf1(9, 2, 10));@coderabbitai[bot] on GitHub · 2026-11-12 00:59 UTC · original · edited 2026-11-13 17:01 UTC
Enable vertex-stage storage writes before running this shader.
The new shader writes an SSBO from the vertex stage. However,
VulkanHarness::InitleavesvertexPipelineStoresAndAtomicsdisabled.RasterizationSupported()does not check this feature either. (raw.githubusercontent.com)Both test modes therefore violate
VUID-RuntimeSpirv-NonWritable-06341, even if readback passes on a particular driver. Vulkan 1.3 requires this feature for writable storage buffers in the vertex stage. (raw.githubusercontent.com)Query and enable
vertexPipelineStoresAndAtomicsduring device creation. Return 77 for these tests when the feature is unavailable.✅ Confirmed as addressed by @Nawid3333
@coderabbitai[bot] on GitHub · 2026-11-12 00:59 UTC · original · reviewed
Actionable comments posted: 1
46dfb29c-22ef-4cd6-9709-f8134a1f326cReviewing files that changed from the base of the PR and between
bc934ef034and 57aa9d7f7f28fac788deff9441f28a806edb9501.CMakeLists.txtsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/renderDraw.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -20176,0 +20196,4 @@AppendVMovLiteral(&code, 9, marker);code.push_back(EncodeVop2(0x1a, 10, InlineU32(2), 5));code.push_back(EncodeMubuf0(0x1c));code.push_back(EncodeMubuf1(9, 2, 10));@Nawid3333 on GitHub · 2026-11-13 17:00 UTC · original
Fixed in
5c031ba1e:RasterizationSupported()now also requiresvertexPipelineStoresAndAtomics, and the harness enables it at device creation, so on a device without it these tests are skipped instead of running.Pull request closed