Skip to content

perf(agc): build the pipeline store key without per-field vector appends - #18863

Merged
oneandonlydean merged 5 commits into
boykopovar:mainfrom
atinseau:codex/perf-pipeline-store-key
Nov 14, 2026
Merged

oneandonlydean merged 5 commits into
boykopovar:mainfrom
atinseau:codex/perf-pipeline-store-key

Conversation

@atinseau

Copy link
Copy Markdown
Contributor

What

Every draw resolves its pipeline through CachedPipeline, which builds a byte key from the pipeline state: one std::vector insert per field, about 600 bytes for a typical draw with 12 vertex bindings, 8 attributes and 2 colour targets. On a store hit that key construction is most of the cost.

The key now goes through a writer that copies into a pre-sized thread-local buffer and bulk-copies the vertex bindings, attributes, layout words, blends and blend constants. The buffer is sized once per lookup from the state, the context and the per-item counts, which bound everything the key writes, and every write checks the room left and throws before it copies, so a key field added without its share of the capacity cannot write past the buffer. The key bytes, the hash and the stored identities are unchanged, and the append(key, field) spelling of the call sites stays, so open PRs that add key fields rebase with at most the signature lines in conflict.

On a probe that calls CachedPipeline with a 611-byte key (12 bindings, 8 attributes, 2 colour targets, every lookup a hit), 7 alternating runs of the parent and the change:

before after
store hit 870 ns, 21,106 instructions 313 ns, 4,339 instructions
key build 582 ns, 14,126 instructions 143 ns, 2,381 instructions

The bounds check costs 249 instructions per key (277.4 against 276.8 ns on the lookup probe, median of 5 alternating runs). A differential run of the production key writer against the previous key builder, copied verbatim, over 150,000 random states (18,626 empty keys, keys up to 790 bytes) found no mismatch, for the final writer and for each intermediate one. At 3,000 draws per frame, all resolved through the store, the saving is about 1.7 ms of CPU per frame; no title trace was captured for this change. agc_driver_graphics gains a check that a key built after a longer one keeps none of the longer key's bytes.

Tested

macOS 27.0.1, Apple M3 Max (36 GB), MoltenVK 1.4.2 from Vulkan SDK 1.4.363.0, Release build with -DBUILD_TESTING=ON, x86_64 under Rosetta 2. main does not run its libraries on macOS, so both sides are main 3b7f31fa7 with the macOS port (the squash of #8658, which its author upstreams in parts) and local macOS build fixes for tests of main that Apple clang refuses; the change side adds this PR's commits.

  • Focused AGC, shader recompiler and VideoOut set, 811 tests, on both sides with VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer, ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1 (ctest --test-dir build-macos -R '<811 test names>' -V): on the change 703 pass, 71 skip, 36 fail and 1 times out, against 704, 71, 35 and 1 on main. The one test that differs is agc_driver_msaa_dcc_clear_2 ("multisampled DCC target reuse requires watched guest memory"), which is intermittent on this Mac with or without the change: run alone ten times in the same conditions, it passes 7 times on main and 8 times with the change. Every other test has the same status as on main; the failures are the ones main has on macOS (MoltenVK limits and macOS-only gaps of the tests). Both runs report the same 77 VUID- errors test by test, and was not found but was requested by env var VK_INSTANCE_LAYERS appears only in the 12 lines that print the failure regex of the agc_driver_image_table_packed* tests. The logs show the loader inserting the layer (Insert instance layer) in 490 tests.
  • python3 tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py found no open pull request that changes the pipeline store key building; the open pull requests that add key fields use append(key, field) lines, which stay as they are.

Not tested: Linux and Windows.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Apple M3 Max, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), macOS 27.0.1
  • AI-assisted: yes

…ps none of its bytes

The key is built into a reused buffer; this guards the shorter key against stale tail bytes of an earlier longer one. It passes on the base.
Each draw's pipeline lookup built its key with one vector insert per field. The key now goes through a writer that copies into the pre-sized thread-local buffer and bulk-copies the vertex bindings, attributes, layout words, blends and blend constants; the bytes are unchanged, the lookup compares them with memcmp.

On the probe fixture (611-byte key, 12 bindings, 8 attributes, 2 colors, all hits) a store hit drops from 21116 to 6365 instructions and from about 900 to 390 ns, and key building from 14127 to 4404 instructions. A differential against the base key builder over 150k random states shows no mismatch.
The key writer checked and grew the buffer on every field. The buffer is now sized once from the state, context and per-item counts, which bound everything the key writes, so each field is a plain store.

On the probe fixture a store hit drops from 6365 to 4309 instructions (about 390 to 330 ns) and key building from 4404 to 2351. The key bytes are unchanged: the differential against the base key builder shows no mismatch over 150k random states.
The key writer sized its buffer from State, Context and the per-item counts and only checked the written length after the last field, so a key field added without its share of the capacity would have written past the buffer before the check fired. Each write now checks the room left and throws before copying. On the lookup probe the hit keeps its cost: 277.4 ns before and 276.8 ns after (median of 5 alternating runs), with 249 more instructions per key (4,339 to 4,588).
@github-actions github-actions Bot added agc libSceAgc* perf Performance change perf numbers missing perf pull request without a before and after summary line labels Nov 12, 2026
@github-actions

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1395 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 4040 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
PR 5925 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6280 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6481 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6804 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6808 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 7085 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 7256 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 7275 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8246 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9335 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9356 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9387 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9712 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9895 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9897 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 10049 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 10351 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 11551 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 11825 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 12619 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 14032 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 14944 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 15548 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 15570 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 16025 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 17056 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 17611 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 17899 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
PR 19100 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 19119 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 19373 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
PR 19559 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 19620 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 19697 core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp

@JJenkx

JJenkx commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Windows check of head aee4029f70. Setup: Windows 11 Enterprise 22621, AMD RX 6700 XT, AMD driver 26.10.1, MinGW-w64 GCC 15.2 UCRT, Release.

The 47 AGC driver tests that cover the pipeline-store key, built from agc_driver_graphics_tests:

  • GPU, through the shared Windows GPU FIFO with ANYPS5_REQUIRE_VULKAN=1, merged onto main 73efc9fe79 (merge b221d3632d): all 47 passed in 3 of 3 runs, 141 of 141 outcomes. The binaries matched the hashes recorded at preparation, and the receipt shows exit 0 and app_count=0.
  • CPU, Vulkan hidden, merged onto main 4415329995 (merge af22572fa3): all 47 pass in 3 of 3 runs.

This is a correctness check only; I did not measure the key-building cost.

AI-assisted: yes.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Head aee4029f70d403064814ce45920682c338131962 (base main). No build and no tests in this review. I read the diff and the head source with the repository reader:

repo_read.py search keyedBlend core/libs/prx/libSceAgcDriver
repo_read.py search blendConstants core/libs/prx/libSceAgcDriver/Graphics
repo_read.py search mainKey core/libs/prx/libSceAgcDriver/Graphics/include
repo_read.py cat core/libs/prx/libSceAgcDriver/tests/Graphics.cpp 13490 13545

Results

Check Result Note
Build and focused tests not run No build in this review
Author's focused test run (811 tests) not run Author-reported, macOS only
check_conventions.py not run Author-reported
Changed hunks read at head passed Read, not compiled
Key capacity bound passed Read against the fixed fields; no overflow found

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp:1064 and :1071 call std::memcpy, and :1353 calls std::memcmp, but the include list of Pipeline.cpp (lines 1–29) has no <cstring>. It compiles only if a header already brings it in. Not built here, so this is unverified. Suggested fix, next to <cstdlib>:

    #include <cstdlib>
    #include <cstring>

The key bytes match the old field-by-field writes: the bulk copies are only used where the static asserts prove the struct layout (no padding, offsets as expected), and blendConstants is std::array<float, 4> and mainKey is a std::span<const std::uint32_t>, so sizeof and size_bytes() give the right byte counts.

Not verified

  • The build, the compile, and every test. The author reports a focused run of 811 tests on macOS (703 pass, 71 skip, 36 fail, 1 timeout, against 704, 71, 35, 1 on main), and check_conventions.py passing. Neither was reproduced here.
  • The benchmark numbers (store hit 870 ns to 313 ns, key build 582 ns to 143 ns), and the differential run over 150,000 random states. Author-reported only.
  • Linux and Windows: not tested by the author and not checked here.
  • Callers of BuildPipelineStoreKey (for example in PipelineJournal.cpp) were not read. BuildPipelineStoreKey now copies out of a scratch buffer on every call; the cost of that was not measured.
  • core/libs/prx/libSceAgcDriver/tests/Graphics.cpp is 14,282 lines and is in the reviewed list, but only lines 13490–13545 were read: the new check and its neighbours. It was read through the reader, since its full text is not in the review folder.
  • The capacity bound: I checked the fixed fields outside State and Context against the 512-byte slack, and the per-element sizes for shaders, colours, blends and vertex descriptions. I did not check every nested field size inside State.

Read in full or in the hunks shown: Pipeline.cpp (the diff, plus lines 1–30, 1048–1087, 1095–1119 and 1140–1215 of the head); Graphics.cpp (lines 13490–13545 only). Excluded by rule: none.

To get this to a good state

Nothing is required.

Optional: add #include <cstring> to Pipeline.cpp (see the finding above), so the file does not depend on a transitive include.

Pipeline.cpp calls std::memcpy and std::memcmp and relied on a transitive include.
@atinseau

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Pipeline.cpp now includes <cstring> in dadf526, so the std::memcpy and std::memcmp calls no longer depend on a transitive include. I rebuilt and ran 41 pipeline store, pipeline journal and shader tests on macOS with VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer and ANYPS5_REQUIRE_VULKAN=1: same statuses as before the change and no new VUID-.

@Doorriiaann

Copy link
Copy Markdown
Contributor

A Linux run, next to the Mac and RX 6700 XT Windows runs: RTX 3070 (8 GB), NVIDIA 610.57.04, Ryzen 5 5600X, Debian 13, kernel 6.12.115, GCC 13.3.0 Release, validation layer 1.4.335, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, the 47 tests of agc_driver_graphics_tests with ctest -V, 3 runs each.

merge-base 5e518ff this PR dadf526
47 tests, including agc_driver_graphics, the agc_pipeline_store_* and agc_pipeline_journal* tests all passed 3/3 all passed 3/3
VUID- lines / layer not found 0 / 0 0 / 0

The same 47 tests also passed 3/3 at the previous head aee4029. This is a correctness check only; I did not measure timings.

AI-assisted: yes

@relativespace2K

Copy link
Copy Markdown
Contributor

Windows/AMD validation on RDNA 2: the new key case passes.

  • AMD Radeon RX 6800 XT (gfx1030, subgroup 64), AMD proprietary driver 26.10.1, Windows 11 IoT Enterprise LTSC 26100, head dadf526431, Release, WinLibs GCC 15.2.
  • ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.
  • agc_driver_graphics passes in 12.08 s, including the new Graphics.cpp case; no VUID- line and the layer loaded.

No AMD frame-time number here: the PR's measurement is on macOS/MoltenVK, and I only ran the functional side on a different vendor.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The reviewed changes preserve the pipeline key’s field order and bound each write; I could not run the checks needed to justify approval.

What I ran

Read the prepared diff and changed code at head dadf5264319dc2aba1ec5c5a9f7670d3ac5e1cd9 through repo_read.py. No build or tests were run.

Results

Check Result Note
Diff and changed code passed Both changed files inspected
Build and tests not run No execution performed
Negative control not run No test execution performed

Findings

Blocking

None verified.

Non-blocking

None.

Not verified

No test or build was run. The description reports tests and performance measurements, but these were not independently verified. Pipeline.cpp and the changed lines in Graphics.cpp were read; Graphics.cpp was excluded from the prepared full-text bundle and was read through the repository reader. No other files were excluded according to the manifest.

To get this to a good state

Nothing is required.

@oneandonlydean
oneandonlydean merged commit da37215 into boykopovar:main Nov 14, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf numbers missing perf pull request without a before and after summary line perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants