perf(shader): insert patched SRT reads before their use without appending first #7431
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7431"
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 milescoviello on 2026-10-18T06:17:38Z.
What
PlanBuilder::PatchReadsreplaces each planned SRT read with aGetSrtResourceand aReadConstplaced right before the read. It built both values withIrBuilder::Emit, which appends them at the end of the block, then took each back out withIrBlock::RemoveInstructionand inserted it before the read.RemoveInstructionsearches the block's list from the front, and the value it looks for is always the last one. So every patched read walked its whole block twice.Both values are now created with
IrProgram::CreateValueand inserted before the read directly, the wayEmitBeforeinResourceTracker.cppalready does it.ReferenceU32for kept reads is still emitted through the builder at the end of the block. The order of the instructions, and so the SPIR-V, is unchanged.verifySrtReadPatchinginShaderMemory.cppnow also checks that theGetSrtResourceand itsReadConstsit right before the original read. That holds onmaintoo, so it is not a red test; it guards the placement this PR now does by hand. With theReadConstappended at the end of the block instead, it fails with "the flat read is not right before the original read".Tested
Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02.
ctest -R ^agc_: 707/707 pass (3 skipped: host import sparse, sparse dma-buf import, stencil ref export).ctest -R "^(agc_shader|agc_ir|shader_ir)": 23/23 pass. With the new check added,agc_shader_srt_read_patchingandagc_shader_memorypass, onmain'sPatchReadstoo.agc_shader_replay --spv(Release,ANYPS5_ENABLE_SPIRV_TOOLSoff,ANYPS5_NO_SHADER_CACHE=1) on all 46 shader requests dumped from PPSA31162: the 46.spvfiles have the same SHA-256 onmainccb0c09268and with this PR, and the replay output is identical.main2185dbf92emerged with this PR (d87f876236, a clean merge): the 304 shader requests dumped from PPSA30839. All 304.spvfiles have the same SHA-256 onmainand with this PR, and the replay logs match. CPU time (perf stat -e task-clock, interleaved runs) for the whole set: median 20.51 s onmainand 18.84 s with this PR, 4 runs each, ranges 20.49–20.55 s and 18.54–18.94 s, so about 8% less. For its largest shader,shader_10f9f30000(1.13M SPIR-V words): 807 ms and 760 ms, 10 runs each. In a--call-graph dwarfprofile of that shader onmain,IrBlock::RemoveInstructionis 7.2% of samples, all of it fromPlanBuilder::PatchReads.Where it showed up. I profiled the Release replay of that title's largest compute shader (13,508 code words, 1,056,287 SPIR-V words) with
perf record(task-clock). Onmain,IrBlock::RemoveInstructionwas 6.6% of samples. In a--call-graph dwarfprofile it was 8.1%, and all of it came fromPatchReads, reached through bothRecompileandPrepareResourceProgram. With this PR it no longer appears in the profile.Replay CPU time of that shader (
perf stat -e task-clock), 40 runs per build, interleaved:mainccb0c09268Another workload was using about 8 cores on the host during these runs, so the spread is wide. Wall-clock times from the same kind of run were noisier (means 1.248 s and 1.187 s). I didn't time the other 45 requests separately (the next largest produce 211,283 to 254,011 SPIR-V words), and I make no claim about them.
Title level: no speed claim. This is background shader preparation. I didn't run the title for it.
tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.pylists only conflicting PRs that it could not compare, all forShaderMemory.cpp. Of those, #6412 has the end ofverifySrtReadPatchingas context, and #6674 calls it. #6947 changesSrtPlanBuilder.cpp, but notPatchReads.main0fbfd91e5: 1637/1639 with this PR and onmain, with the same two failures (#7766, #7784), and no test added, skipped or removed. That's correctness only; the speed-up wasn't measured there.Title capture
As the
perflabel asks, these are captures of one title and scene on one machine. MXGP26 (PPSA30839) ran from boot withAPS5_TRACE_SECONDS=0:60,ANYPS5_NO_SHADER_CACHE=1and a fresh run directory (cold AnyPS5 and NVIDIA caches), so the shaders compile inside the window. NVIDIA RTX 4070 Ti (595.99.02), Ubuntu 24.04, release libs, Xvfb display, no input.maindbac9fa15bwas captured five times: before the PR captures, after them, and three more times in a row after that. Each PR capture and the first twomaincaptures followed a rebuild of the release libraries; the last threemaincaptures did not, and they came out lower. The change ismainwith this PR merged on top as a local merge commit (632261e94460). The time is the wall time of theShader.PrepareArtifactslices on theshader preparethreads in each trace.main1main2main3main4main5The five
maincaptures span 17.7% in total prepare time, and the 13 prepare threads run in parallel with the title, so a title capture can't resolve a recompiler change of a few percent. The replay measurement above is this change's measurement. This PR's capture falls inside the range of the fivemaincaptures.main1 trace, digest,main2 trace, digest,main3 trace, digest,main4 trace, digest,main5 trace, digest, this PR trace, digestVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -R '^agc_' -Vonmaine2a2914aa1and onmain+ this PR (9be717d11b, a local merge).main: 815 of 815 pass; with this PR: 815 of 815 pass. Neither log reports the layer missing. VUIDs onmain:VUID-VkImageViewCreateInfo-usage-02275×6,VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605×18,VUID-vkCmdCopyBuffer-srcBuffer-00118×2,VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285×2,VUID-vkCmdWaitEvents-srcStageMask-01158×2,VUID-vkSetEvent-event-09543×2; with this PR:VUID-VkImageViewCreateInfo-usage-02275×6,VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605×18,VUID-vkCmdCopyBuffer-srcBuffer-00118×2,VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285×2,VUID-vkCmdWaitEvents-srcStageMask-01158×2,VUID-vkSetEvent-event-09543×2. None is new with this PR.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 github-actions[bot] on 2026-10-18T06:28:42Z.
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.
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/SrtWalker/SrtPlanBuilder.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/SrtWalker/SrtPlanBuilder.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppImported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T16:27:56Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
main0fbfd91e5(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8): 1637/1639 with this PR, against 1637/1639 onmain. The failures are the same two on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784). The PR adds no new ctest entry, and no test is skipped or removed compared withmain. This checks correctness only: I did not measure the speed-up.GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T16:30:48Z.
@DavidAmsellem thank you for the RADV full-suite run. It matches
mainon gfx1100 with the same two failures, so this change adds none. It's in the description now.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T16:31:00Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T21:35:37Z.
The title capture the
perflabel asks for is now in the description, with both summary lines, the traces and the digests: MXGP26 from boot, a cold shader cache,maindbac9fa15bagainstmain+ this PR (632261e94460). The fivemaincaptures span 17.7% in total shader prepare time, so the capture can't resolve this change, and the replay measurement in the description is still its measurement. This PR's capture falls inside the range of the fivemaincaptures.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T20:23:04Z.
More evidence, from a second title's corpus on current
main2185dbf92e. The PR merges cleanly onto it. The 304 PPSA30839 shader requests produce identical SPIR-V, and the whole set takes 20.51 s onmainagainst 18.84 s with this PR (median CPU time of 4 interleaved runs each, ranges not overlapping), about 8% less. The description has the details.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T20:30:06Z.
Checked
PatchReadsagainstIrBuilder::EmitandEmitBeforeinResourceTracker.cpp: same opcodes, types and arguments, same instruction order; the removed append/RemoveInstructionpair was the only difference. Rechecked against currentmain: clean merge, nothing it changed touchesPatchReadsorverifySrtReadPatching. The new placement check guards the order, and the RADV full-suite run from @DavidAmsellem matchesmain; merged.