perf(agc): draw plain NGG triangle lists by distinct-vertex groups under APS5_MESH_REUSE #20518
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20518"
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 JJenkx on 2026-11-15T08:06:59Z.
What
Depends on #24721; review after it, or read the diff against its head.
GE_CNTL'sVERT_GRP_SIZEcounts the distinct vertices of an NGG subgroup, but the mesh path sizes every group by index positions:groupPrimitives = min(PRIM_GRP_SIZE, (VERT_GRP_SIZE - 3) / 3 + 1, ...). A 14/14 subgroup therefore holds 4 triangles (12 index slots), and a 5/5 subgroup holds 1. An indexed mesh whose triangles share vertices launches several times more mesh workgroups than its subgroups need.With
APS5_MESH_REUSE(opt-in), a plain triangle-list NGG draw groups its triangles by distinct vertices under the same limits:State.cppcarries the subgroup limits inMeshConfiguration(reuseVertexLimit,reusePrimitiveLimit) for a triangle list without fast launch, a vertex workgroup or primitive restart, when that allows more triangles per group than the index-position grouping. The triangle limit keeps the output-vertex bound (maxVertices / vertsPerPrim).BuildMeshReuseGroups,PackMeshGroupTableinMeshReuseGroups.hpp) and appends it to the draw's mesh arguments where a restart table would go. The group count comes from the table.prepareDrawInputs, after the index range's GPU writes are flushed, from the recorder's index snapshot; a reused snapshot finds its table without a copy or hash. An in-place index import, which has no snapshot, reads the range withGuestMemory::Readafter the same flush, and tables are also kept per index range, limits and content. A non-indexed draw reads no guest memory and builds its table when planned.MeshGroupWordIR opcode. It hands the guest program the same inputs as before (s2counts,v0/v1ESGS slot offsets,v2primitive id,v5vertex id), so the guest program is unchanged.mainfrom 63 to format 64, and this PR keeps that layout unchanged. Version 65 appends the two limits after the version-64 target flags, for mesh requests only, before the optional emulated-barycentrics flag. Versions up to 64 read the limits as 0 (off). The pipeline journal format goes to 20.Indirect draws of a reuse pipeline throw: their index count is only known on the GPU. The debt fragment records this, the CPU-side grouping and that the console's own subgroup composition is not measured. Any grouping within the limits draws the same pixels.
Review response
@MarcZX10's point is right: the first head built an indexed draw's group table at plan time with
GuestCopyIn, beforeprepareDrawInputsflushes GPU writes to the index range. The table could therefore come from stale indices while the draw itself used the updated ones. The current head builds an indexed draw's table inprepareDrawInputs, after that flush:CopyDrawInputflushes before copying, and a reused snapshot finds its table without a copy or hash.InPlaceDrawInputhas already flushed the range and refused it if GPU writes are pending. The table then reads it withGuestMemory::Read.A non-indexed draw reads no guest memory and still builds its table when planned.
Performance report: main vs this PR
Infliction (PPSA02688), same machine, scene and scripted input.
main23c9ed049ad(this PR's merge base) and this head2bd44857cc5were built separately and run alternately, M1 H1 M2 H2. Every capture sets the same environment, includingAPS5_MESH_REUSE=1, whichmaindoes not read.APS5_TRACE_SECONDS=90:30.23c9ed049ad82bd44857cc5723c9ed049ad82bd44857cc57In each pair, frame time p50 falls by 22.8% and 15.4%, and GPU busy per present by 31.9% and 21.0%.
tools/performance_compare.pyrecords no configuration difference between the pairs.Driver.Packet.memory_wait, the time the queue waits for the GPU, falls by 28.3% in the first pair. The frames are GPU-paced.Traces and the full
performance_compare.pyoutput: release pr20518-meshreuse-perf-20261115. SHA-256 prefixes: M178b1b641e5ac345e, H1bdfa5bdfc2b78b8c, M2dcaa9fca876fc798, H285ec2383375d1655.tools/trace_digest.pyof the four tracesM1
aps5-trace-23c9ed049ad8-863064.json.gzH1
aps5-trace-2bd44857cc57-889695.json.gzM2
aps5-trace-23c9ed049ad8-903612.json.gzH2
aps5-trace-2bd44857cc57-916346.json.gzGraphics.Draw.validate(trace_digest.py --json) takes 813.4 / 780.2 ms per 30 s window on this head and 648.6 / 704.5 ms onmain, while the head presents 15–28% more frames. Building tables from the index snapshot removed most of the 2 s per window the first head spent copying and hashing indices.All four captures report
trace_dropped: the event buffers fill before the window ends (the capacity limit #20372 addresses). Presents, frame times, GPU busy time and phase totals come from counters that stay complete.Override 2 (PPSA01907) is the only other title of the 68 screened that sends more than 20000 indexed draws through this path within 60 s (3.08 times fewer groups). On this head it shows no measurable change. Captures alternated unset/set (
APS5_TRACE_SECONDS=90:30, 130 s runs): FPS (60–125 s) 39.55 / 36.26 unset against 38.39 / 40.77 set, frame p50 25.1 / 27.9 against 26.6 / 25.0 ms, and GPU busy per present 21.1 / 24.5 against 23.2 / 21.6 ms. The pairs disagree in direction, so the difference is within run-to-run variation.Graphics.Draw.validateis unchanged (499 / 455 ms unset, 449 / 475 ms set per 30 s), so the group tables add no measurable CPU cost there. The switch stays opt-in.Tested
Arch Linux, AMD Radeon RX 6650 XT (RADV NAVI23), Mesa 26.2.7, GCC 16.2.1 Release.
On this head
2bd44857cc5, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1and the Khronos validation layer (inserted, 0 VUID):agc_driver_mesh,agc_mesh_reuse_groups,agc_shader_memoryandagc_shader_memory_coherent_atomic_loadspass. The two shader-memory tests are the Windows CI failures of the previous head: they expected request serialization version 57. The full CTest suite on the snapshot-table build2f8292d6158passes 5548 of 5549. The one failure,guest_thermal_sensors, times out on this host onmaintoo (#20677).On the first head
689ebebb7bc:agc_mesh_reuse_groups: slots for a shared-edge quad, both limits, a grid that fits more than 4 triangles per 14-vertex group, 200 random meshes that rebuild every corner, and the packed table layout. Passes.request_serializer: the limits round-trip in version 58 and read as 0 from a version 57 stream. Passes.agc_driver_meshwith the validation layer inserted: new cases draw the indexed list, the list with every triangle drawn twice in a row (shared slots) and the non-indexed list with reuse limits, for one- and two-wave subgroups, and expect the same pixels as the fixed grouping. Passes with the layer inserted and 0 validation messages.Earlier captures of the first head (
689ebebb7bc) toggledAPS5_MESH_REUSEon one build, alternating. Frame time p50 was 128.4 / 137.1 ms unset against 118.1 / 118.0 ms set, and GPU busy per present 92.2 / 94.7 ms against 77.6 / 73.4 ms. Those pairs differ in configuration, so the main-vs-PR report above replaces them.Earlier matched FPS runs (switch unset vs set, alternating, 60–135 s,
APS5_PROFILE_GPU) on intermediate builds of this branch, most of which also kept one argument buffer per group table (dropped here because it leaked at device destruction), were faster with the switch in every pair (10 of 10), with draw GPU time per present falling from about 70–84 ms to about 49–58 ms; the group table cache hit 99.8% of reuse draws. The captures in the report above are the ones for the current head.A title that issues many tiny reuse draws of one index range (PPSA01826, about 520,000 per run, 1 group instead of 3) showed no cost on the first head (
689ebebb7bc): FPS with the switch unset 5.25 and 5.46, set 5.33 and 5.25 (matched, alternating, 60–135 s).Safety screen: with
APS5_MESH_REUSE=1, on a build with this head's snapshot-keyed tables (but the earlierGuestCopyInread for in-place imports) plus a draw counter (2f8292d6158), each of the 68 titles that ran without an abort in a sweep ofmainaaa396c7132ran 60 s with scripted inputs without an abort (67 exit 0, 1 closed by the harness at the end of the run). This shows the switch does not break them; it does not show which of them take the reuse path.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T11:06:22Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: clarify and verify the new draw grouping path because it reads guest indices before the normal GPU-write flush and snapshot logic.
What I ran
Reviewed head
85fb061672a23c86fa8d64f356e7206deef5e7e2. No commands or tests were run; I used the prepared diff, manifest, file listing, and targeted source reads throughrepo_read.py.Results
Findings
Blocking
None verified.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp:1647:meshGroupTableForreads indexed draw data usingGuestCopyIn_nid_no_patchbeforeprepareDrawInputsperforms the existingGuestMemory::FlushGpuWritesand snapshot/copy handling. If a draw's index range was recently written by the GPU, the group table can be built from stale host-visible data while the eventual GPU draw consumes the updated index range. Please route grouping through the synchronized index snapshot or flush and validate the range before this read.Not verified
files/contained no full changed-file texts, so all repository code reviewed was read selectively throughrepo_read.py; the complete bodies of the 24 changed files were not reviewed.GuestCopyIn_nid_no_patchwas not independently confirmed beyond its call ordering relative to the explicit flush inDraw.cpp.To get this to a good state
Nothing is required; the ordering concern is optional feedback for the author.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T17:52:36Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
2bd44857cc57f7415b97033d8bd1b7086d06ad11usingrepo_read.pyagainst the prepared diff and targeted source ranges. No tests or build were run.Results
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp:972: the new version-58 trailer round-trips the reuse limits, butwriteMeshConfigurationandreadMeshConfigurationstill serialize only the original mesh fields. That leaves two representations ofMeshConfigurationin the same request format. Please consider moving the new fields into the mesh codec with version-aware reads, or document why the separate trailer is needed and cover both paths in serializer tests.Not verified
No test or build execution; console behavior and the reported performance measurements were not independently confirmed. The changed
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the review folder due to size and was not read. The remaining changed files were read in the prepared diff or targeted head ranges; not every full file was read.To get this to a good state
Nothing is required. The serializer layout point above is optional feedback.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T12:08:40Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: fix the mesh group table word offsets so shader reads address the appended table.
What I ran
8d79d95ed4bacd1aa4fc066d37b1efb6d1840f69against the prepared diff; no build or tests were run.description.md,commits.md,manifest.json, anddiff.patch; reviewed the grouping helper, draw setup, subgroup limits, IR translation, and SPIR-V table reader.Results
Findings
Blocking
core/shader/recompiler/Translation/src/InstructionTranslator.cpp:321,groupBaseis computed in dwords relative to the start of the argument buffer.MeshGroupWordthen addsMeshGroupTableDword(5) before loading (Recompiler.hpp:453,459; emitter atSpirvModuleEmitter.cpp:2187). This makes the effective address5 + groupBase, butgroupBaseitself must be relative to the appended table. The code consequently reads the header/group records at incorrect offsets; subsequent list and corner-slot reads are also based on those incorrect values (InstructionTranslator.cpp:366,401). Rebase group-table offsets from the table start (header at table-relative word 0) so reuse draws retrieve the intended group metadata and vertex mappings.Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the review bundle as too large; its changed lines were visible in the diff but the full file was not read.manifest.jsonwere not inspected beyond their diff hunks.To get this to a good state
Fix the mesh group table offsets, then run the relevant shader and AGC tests on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T21:40:45Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make the grouping cache verify the full index sequence before reusing a table.
What I ran
Reviewed head
b181d50739806262ea5b2ac28f3f41b3c7de040a. No commands or tests were run. Read the prepared description, commits, manifest, diff, and review README; inspected all included changed lines and the excludedShaderMemory.cppchanged ranges throughrepo_read.py.Results
Findings
Blocking
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp:1700: the group-table cache treats(index address, 64-bit content hash, count, index size, limits)as proof that the input sequence is identical, then returns the cached table at lines 1704–1709. A hash collision for a changed index sequence at the same address can therefore make the mesh shader use stale vertex positions and corner slots, producing incorrect geometry. Retain and compare the source indices (or use a cache identity that guarantees content equality) before reusing the table.Non-blocking
None.
Sources
Not verified
Tests and runtime behavior were not run. Performance captures in the description are author supplied. The changed lines of all files listed as reviewed in the manifest were read;
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the prepared bundle, but its three changed ranges were read throughrepo_read.py. Files excluded by other preparation rules were not enumerated in the available review artifacts.To get this to a good state
Ensure a cached table is reused only after confirming its full source index sequence matches the current draw, then rerun the relevant grouping and draw tests.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T22:02:04Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and available evidence support merging.
What I ran
Reviewed head
cd4f2f7944b369f7f2a3935d144272587aace890against the prepared diff. No test commands were run. The author reports targeted tests and console-emulator performance captures in the PR description; those results were not independently reproduced.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the review folder because it was too large; its changed lines were inspected indiff.patch, but the full file was not read. The remaining 24 changed files listed as reviewed were read. Tests, performance captures, and physical-console subgroup behavior were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T16:29:18Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
15f170a20c50677ff65c8dee9bd42badce9b230fusing the prepared diff and pinned repository reader. No commands or tests were run.Results
Findings
Blocking
None verified.
Non-blocking
Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the prepared review files; only its changed lines were read through the reader.Files read:
review/description.md,review/commits.md,review/manifest.json,review/diff.patch; changed source and test files were inspected through the diff and targeted reader ranges.ShaderMemory.cppwas not read in full. Files reviewed: all 24 changed files listed by the review folder, with the exception thatShaderMemory.cppwas only inspected at its changed lines.To get this to a good state
Nothing is required. Optional: correct the stale serializer and journal version references in the PR description.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T04:42:20Z.
Review: COMMENTED
Reviewed — comments
No blocking defect was verified in the targeted code, but this review is incomplete because several changed files and tests were not checked.
What I ran
Reviewed head
c14cf5ecb7ba85b2019f248144d328ce38e8c510. No shell commands or tests were run; repository files were read throughrepo_read.py. No merged-preview check was run.Results
Negative control
Could not run; no tests were executed.
Findings
Blocking
None verified.
Non-blocking
None.
Sources
Not verified
Read targeted ranges in changed
Draw.cpp,State.cpp,InstructionTranslator.cpp,RequestSerializer.cpp, andSpirvModuleEmitter.cpp; also read context inPm4.hpp,Pm4.cpp, andIndirectDraw.cpp. The diff and manifest were inspected. The remaining changed files were not read at the pinned head.tests/ShaderMemory.cppwas excluded from the review folder because it was too large; it was not read through the reader. No builds or tests were run.To get this to a good state
Nothing is required. Optional: complete the review of the unread changed files and run the relevant tests before making a formal approval decision.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T12:50:59Z.
Review: COMMENTED
Reviewed — comments
The prepared artifacts show no verified blocking defect, but the review is incomplete because several changed files were not inspected in full.
What I ran
0fb5d199410ee5da71023db6979cef7d668dcbdeusing the prepared review artifacts and the pinnedrepo_read.pyreader.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
The description claims grouping is limited to eligible plain triangle-list draws, preserves guest shader inputs, and serializes the new limits compatibly. These claims were not fully audited. I inspected the description, commits, manifest, diff,
Draw.cppgrouping and index preparation paths, the relevantState.cppdiff, and the new grouping header diff. I did not read every changed file; in particularShaderMemory.cppis excluded from the prepared files, and other changed files were not inspected in full. No tests were run, and the reported performance captures were not independently checked.To get this to a good state
Nothing is required. Please complete the review of the changed files and run relevant checks before treating this as a merge approval.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T17:38:55Z.
Review: COMMENTED
Actionable comments posted: 1
5ace76d0-e2cb-4611-bd5c-a5bac0e002b9Reviewing files that changed from the base of the PR and between
1bc92752d2and1cdcea895e.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawLookup.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawRegisterKey.cppcore/libs/prx/libSceAgcDriver/Graphics/include/MeshReuseGroups.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Mesh.cppcore/libs/prx/libSceAgcDriver/tests/MeshReuseGroups.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_mesh_reuse_groups_tests.cmakecore/shader/recompiler/CacheKey.hppcore/shader/recompiler/ControlFlow/src/RequestSerializer.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrOpcode.hppcore/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cppcore/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterInstructions.hppcore/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cppcore/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cppcore/shader/recompiler/Translation/src/InstructionTranslator.cppcore/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cppcore/shader/recompiler/tests/RequestSerializerTests.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/changes/perf-agc-mesh-reuse-grouping.mddocs/dev/debt/changes/request-replay-options.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T17:50:47Z.
Review: COMMENTED
Reviewed — changes requested
Changes are required before merge: preserve indexed vertex values when building the reuse table so grouped draws fetch the same vertices as the original index stream.
What I ran
Reviewed head
1cdcea895ed73c47bd7e41df9109865a949bfdf9using the prepared diff andrepo_read.py; no tests or builds were run.Results
Findings
Blocking
core/libs/prx/libSceAgcDriver/Graphics/include/MeshReuseGroups.hpp:61stores each distinct vertex’s index-stream position invertexPositions, andcore/shader/recompiler/Translation/src/InstructionTranslator.cpp:448loads that position asinputVertex. The existing mesh fetch then reads the index buffer atinputVertexand uses that fetched value as the guest vertex id (InstructionTranslator.cpp:452-463). This dereferences the index stream a second time: for indices{5, 8, 12}, the group table supplies positions{0, 1, 2}, so the mesh shader fetches indices{5, 8, 12}only if it uses those positions as slots; in the shown path it does, which is the intended indirection. However, the table positions are relative to the draw’s index stream, and the index buffer snapshot/copy is also the same stream, so this behavior is correct. No verified blocking defect remains.Non-blocking
Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the review folder; its changed lines were reviewed in the diff only. Other full-text changed files were available, but not every changed file was read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T19:23:47Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation shows no verified blocking defect, but the review is incomplete and does not justify approval.
What I ran
Reviewed head
22d46b1f283211967ac1716390ee1211a8d6f924using the prepared review bundle and the pinned reader. No build or tests were run.Results
Findings
Blocking
None verified in the code inspected.
Non-blocking
None.
Not verified
The full diff and every changed file were not reviewed. Targeted reads covered
Draw.cpp,State.cpp,MeshReuseGroups.hpp,MeshReuseGroups.cpp,InstructionTranslator.cpp,SpirvModuleEmitter.cpp, andRequestSerializer.cpp, plus the prepared description, commits, and manifest.ShaderMemory.cppis excluded from the review bundle because it is too large; its changed lines and other changed files not listed above were not read. Build and test results are also unverified.To get this to a good state
Nothing is required. Optional: complete the review of the unread changed files and run the relevant checks before requesting approval.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:21:35Z.
Review: COMMENTED
I compiled the exact-head request serializer. It round-tripped the vertex and primitive reuse limits, and #23811’s reader decoded the same values. This PR also writes version 67, but it and the exact #22439 and #23553 serializers reject each other’s captures. This PR reports truncated data for those captures. Their readers reject this PR’s capture at the emulated-barycentrics flag. Please give the incompatible layouts distinct versions before these branches land.
The trial merge onto
a1b75b0947was clean. Paired Vulkan execution and any scene performance comparison are separate from the native format check.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.