perf(agc): bind indices behind a GPU writer for draws with vertex attributes #26775
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26775"
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?
Imported from boykopovar/AnyPS5. Originally posted by Gonic0 on 2026-11-24T21:08:04Z.
What
With
APS5_INDEX_IN_PLACE_BEHIND_WRITER, an indexed draw binds its index range in place from the host import behind a pending GPU writer, instead of waiting for the writer and copying the range on the CPU. Until nowInPlaceIndexBehindWriterrefused every draw whose vertex shader has fixed vertex attributes (IndexBehindWriter::VertexAttributes). The vertex buffer copies are sized from the highest index, and the CPU cannot read that while the GPU still writes the indices. Those draws fell back toInPlaceDrawInput(..., nullptr), whoseFlushGpuWriteswaits for the writer under the GPU mutex.This PR takes those draws behind the writer too:
InPlaceIndexBehindWriterno longer refuses vertex attributes. ItsvertexAttributesparameter and theVertexAttributesoutcome are removed.prepareDrawInputs, when the indices are bound behind the writer (inputs.indexInputBehindGpuWrite), each attribute's range is the whole buffer descriptor (VertexBufferExtent), as for an indirect draw.firstByte,fetchValidandrangeFromfollow the same rule.docs/dev/ENVIRONMENT.mddescribes the new behaviour and dropsvertex attributesfrom the[index-behind-writer]outcomes.The switch stays opt-in. Without it nothing changes.
This touches the same lines of
Graphics/src/Draw.cppas #19620 (fetchValid), #26036 (firstByte), #26041 and #26706 (Draw.hpp), on other topics. Whichever lands second has a small textual conflict.#21923 works on the same wait from the other side: it releases the GPU mutex while an indexed draw waits for its index writer. This PR removes that wait for draws with vertex attributes when
APS5_INDEX_IN_PLACE_BEHIND_WRITERis on. They do not implement the same thing, but both change theInPlaceIndexBehindWritercall line inprepareDrawInputs.Tested
macOS 27.3, Apple M5 Pro, MoltenVK from Vulkan SDK 1.4.363.0, x86_64 Release build under Rosetta.
maindoes not build on macOS right now (libc/src/exception/Runtime.cppuses__sub_kindvalues that Apple's libc++abi does not declare), so #26739 was applied locally for both builds and is not part of this PR.New test
agc_driver_index_behind_writer_vertex_attributes(tests/execution/IndexBehindWriterVertexAttributes.cpp):FillBufferin the open batch then writes {0, 9, 15, 3, 12, 7}.Takenand nothing else. Every referenced vertex holds its exact attribute bits, including record 15, which a range sized from the stale indices (highest 2) misses. Unreferenced vertices stay unwritten.vertex fetch exceeds descriptor record count: OOB_SELECT 2, stride 32, NUM_RECORDS 16, vertex index 65535.agc_index_in_place_behind_writer(updated for the removed outcome) passes.Validation layer A/B, same machine, with
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layerand the 1.4.363 layer, runningctest --test-dir build -R <pattern> -V:main:agc_index_in_place_behind_writer,agc_driver_vertex_fetchandagc_driver_draw_offset_indicespass.Insert instance layer "VK_LAYER_KHRONOS_validation"for every test and nowas not found but was requested by env var VK_INSTANCE_LAYERS.VUID-VkDeviceCreateInfo-sType-unique, twice, at device creation inagc_index_in_place_behind_writer. The PR adds no newVUID-.Grand Theft Auto V (PPSA04264), first 3D scene, on a lab build that needs unmerged fixes to get there, not
main. WithAPS5_INDEX_IN_PLACE_BEHIND_WRITER=1,[index-behind-writer]counted about 70 refusals per 10 s asvertex attributes. Each one waited about 40 ms for its writer under the GPU mutex, with the index bytes unchanged after the wait. With the switch on in both runs, this change brought the GPU mutex waits over 1 ms from 226 to 23 ms per frame. The draw committer went from 102.8 µs per commit ([draw] pipelined, a run without the switch) to 59.6 µs (switch on, this change).The frame time did not change, because those waits were not on that scene's critical path. I make no speed claim.
Performance capture
maindoes not reach this scene on macOS, so both captures come from the lab build of the GTA V bullet above, with the same steps for each:d39ebf7cec89: the lab build, with the lab copy of this change removed.49105d912269: the baseline with this PR's commit cherry-picked onto it (the same 5 files, +277/-29).Both builds are clean (
dirty: false). Same machine (Apple M5 Pro, macOS 27.3, x86_64 Release under Rosetta), KosmicKrisp (Mesafc930002fcwith local lab changes), GTA V 01.011.001 at 3840x2160, the same pad script, the sameAPS5_*environment withAPS5_INDEX_IN_PLACE_BEHIND_WRITER=1, and frames2800:150.tools/performance_compare.py --require-matching-contextreports no configuration difference.GpuMutex.wait.hookwent from 175.9 to 29.3 ms per frame, andGpuMutex.wait.endfrom 9.1 to 0.8.Driver.Draw.shader_compile_and_link81.2 against 19.8 ms per frame). I still make no speed claim.The two traces are attached in a comment below.
Baseline summary line:
Candidate summary line:
tools/performance_compare.pyPerformance comparison
Frame and GPU times (ms)
Top phases (ms per frame)
Worker busy time (%)
Graphics track (per present)
tools/trace_digest.py, baselineframes 2800:150 from present 2800: 150 presents, frame p50 316.4 / p90 354.1 / p99 439.8 / max 455.3 ms, GPU busy 190.7 ms per present
Apple M5 Pro, KosmicKrisp Mesa 27.0.0-devel (git-fc930002fc), Darwin 27.3.0, 3840x2160, commit d39ebf7cec89, dropped: no
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 929.1, Driver.WorkerWait 647.9, Driver.WorkerWait.idle_and_completion_poll 647.9, Driver.Packet.memory_wait 470.6, Driver.Packet.dispatch 313.3, Driver.Dispatch 273.3, batch 190.5, GpuMutex.wait.hook 175.8, Graphics.Draw 129.1, Driver.Packet.draw 124.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py, candidateframes 2800:150 from present 2800: 150 presents, frame p50 304.7 / p90 336.2 / p99 382.2 / max 389.9 ms, GPU busy 179.1 ms per present
Apple M5 Pro, KosmicKrisp Mesa 27.0.0-devel (git-fc930002fc), Darwin 27.3.0, 3840x2160, commit 49105d912269, dropped: no
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 894.4, Driver.WorkerWait 611.6, Driver.WorkerWait.idle_and_completion_poll 611.6, Driver.Packet.memory_wait 460.3, Driver.Packet.dispatch 304.4, Driver.Dispatch 263.3, batch 178.5, Driver.Packet.draw 116.0, Driver.Draw 115.9, Driver.Draw.shader_compile_and_link 70.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T01:08:13Z.
Review: COMMENTED
Reviewed — comments
The review covered all five changed files at head
4b3f8d440235f89b948a954efa843c6b34e141e8; no tests were run, and one edge case still takes the index-wait path.What I ran
Read the prepared diff and changed lines at the pinned head. No build or test commands were run.
Results
Negative control
Not run; no tests were executed.
Findings
Blocking
None.
Non-blocking
ZeroFetchVertexreturns a clamp threshold. The new whole-range sentinel setsinputs.maxIndexto the maximum possible index, so the existing clamp branch can callFlushGpuWritesand read the index range on the CPU before this whole-range sizing is reached. Those draws can still wait for their index writer. Consider documenting this exception or handling the clamp without synchronously reading the indices. Changed line:core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp:2165. Pinned sourceNot verified
The reported build, execution tests, Vulkan validation, and performance captures were author-reported and not independently run.
core/libs/prx/libSceAgcDriver/tests/Recorder.cppwas read at the changed lines through the repository reader; the other changed files were read from the prepared diff and targeted source ranges. No changed files were excluded from review.To get this to a good state
Nothing is required. Optional: clarify the zero-fetch clamp exception in the description or address that path.