Repository navigation
perf(shader): deduplicate runtime image switch modes and base-level sample branches - #8716
Conversation
| return false; | ||
| } | ||
| const auto opcode = inst.Opcode(); | ||
| if (ImageOpcodeInfoOf(opcode).access == ImageAccess::Atomic || opcode == IrOpcode::ImageQueryDimensions) { |
There was a problem hiding this comment.
Correction: I withdraw this concern. Rechecking the condition shows alreadyBaseLevel requires opcode == spv::OpImageSampleExplicitLod; it therefore cannot suppress SamplesBaseLevelIfUnnormalized for OpImageSampleImplicitLod, and that fallback remains enabled for implicit samples. My earlier comment incorrectly described the opcode condition. I have not found a regression from this guard.
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
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.
|
4bf7fec to
d8ea386
Compare
|
Rebased/merged Uncovered diff lines before (
|
|
@hamb3r thanks, I checked the merged switch cases against every image field the read, write, atomic and query emitters use, and the grouping holds for each of them. One request: could you update the description to match the code? It mentions |
|
@oneandonlydean Updated the PR description (What section) to accurately describe the three changes in SpirvImageEmitter.cpp. Thanks for the review! |
|
@hamb3r thanks, the What section now matches the three changes in |
|
@oneandonlydean Merged current |
MarcZX10
left a comment
There was a problem hiding this comment.
I reviewed the current head 8a747c6ef125e8a15fd213af0d6a08e0c58034df. The three changes remain distinct and the new emitter tests exercise packed-format deduplication and mip-mode separation. The PR reports the same focused validation-layer set on main and the change, with no missing-layer warning or VUIDs, plus Windows and Polaris results. Local diff whitespace, conventions, and registration checks pass; I could not run GPU tests on this host.
One repository-readiness blocker remains: tools/check_main_sync.py --base upstream/main --head <head> reports this branch 5 commits ahead / 256 behind current upstream/main (merge base fcd455870), though it merges cleanly. core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp also changed on main after that base (#6801), so the new test must be retained alongside current tests. CONTRIBUTING requires branches to be kept up to date. Please merge current main, preserve both sets of changes, and rerun the focused shader/AGC validation tests on the resulting head. This request concerns current-main readiness only; it is not based on intake volume.
|
@MarcZX10 Merged current
|
|
@oneandonlydean Rebased/merged latest |
|
Linux run of this head
AI-assisted: yes (Claude Code) |
…tter-dedup # Conflicts: # core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
|
@oneandonlydean Rebased/merged latest |
|
A CPU-only data point from another title: I recompiled the 71 shader requests dumped from Mortal Shell II (PPSA34008) with AI-assisted: yes (Claude Code). |
imellag
left a comment
There was a problem hiding this comment.
macOS / MoltenVK data point. Apple M4 Pro, macOS 27.2, MoltenVK 1.4.2, x86_64 Release under Rosetta. main doesn't run titles on macOS yet, so the base is a support branch, not main: main 750cf6cf48 + only the macOS boot PRs #7631 #10552 #11249 #11447 #11554 #10669 #7804, + #12529 (the revert of #10337, which roughly doubles the GPU time on this GPU and would hide smaller changes). Change: that base + eight open shader performance PRs merged together (#12287 #11952 #12299 #12280 #11368 #11265 #8716 #8958, all clean merges). I did not measure each PR alone.
Two alternated runs per side, warm shader cache, APS5_TRACE_SUMMARY_EVERY=10:
| base | with the eight PRs | |
|---|---|---|
| God of War Sons of Sparta (PPSA28997), fps from 30 s | 51.5 / 51.8 | 51.6 / 51.8 |
| GoW GPU ms/present, gameplay before the fight / in the fight | 13.6 / 19.6 | 13.5 / 19.5 |
| Planet of Lana (PPSA19450), fps from 85 s | 32.2 / 32.7 | 32.5 / 32.6 |
Together they don't raise the GPU time on MoltenVK. I'm checking open shader performance PRs on this GPU because #10337 was measured on RADV and doubled it here.
Focused tests below ran with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation on the same two trees; the layer was found and both logs have the same VUID- lines (12 VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605, 20 VUID-vkCreateDescriptorSetLayout-support-09582, from tests that fail the same way on the base).
Interaction with #12299. The two merge without a textual conflict, but together they fail agc_shader_memory at this PR's new check: runtime image switch deduplication: OpSwitch did not cover every runtime image mode. Each one alone passes it (base + #8716: pass; base + #12299: pass; base + #8716 + #12299: fail; base + #8716 + #11952: pass). #12299 turns the direct-image OpSwitch into a balanced if tree for value-returning images, so the switch this PR deduplicates is no longer there. Could you and @Filip722 agree which lands first and how the second adapts?
This PR on MoltenVK otherwise: agc_redundant_value_elimination, agc_shader_srt_read_patching, agc_formatted_buffer_once, agc_formatted_buffer_byte_stores, agc_driver_gated_dispatch_capture, agc_driver_image_sample_unnormalized, agc_driver_image_store_sint and agc_driver_prepared_shaders_indirect pass on the base and with the change; agc_driver_image_table fails on both with the same VUID-vkCreateDescriptorSetLayout-support-09582. No GPU regression in the group.
AI-assisted: yes (Claude Code ran the builds, runs and tests and drafted this review)
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — changes requested
The previous code-level concerns appear addressed: the author reports preserving #6801’s ShaderMemory.cpp additions and the runtime image-switch deduplication regression, then rerunning focused Vulkan-validation tests and a Linux selected-test run. The PR includes the required same-title/machine performance summary lines and trace digests.
One integration blocker remains. The current PR head e6504377c6b565b8ab39609d5f83e7391a8df116 is 1,644 commits behind current main 2960e9a6e7e1fc99c4ed180c71495b5eb83464c7 (merge base 5bc84038c490a0427ff272e39e2a1cdf6fdc3c0e). ShaderMemory.cpp and SpirvImageEmitter.cpp changed on both sides since that base. The merge preview is clean, but a clean merge alone does not validate the resulting code or establish that the recorded performance comparison still describes the current integration. Please update against current main, rerun the focused shader/image validation suite, and refresh the same-title performance pair if those current-main changes affect the measured emitter path.
I did not run GPU tests locally. The hosted checks currently pass policy and Windows jobs plus relinker matrices; Linux product CI is skipped.
|
@hamb3r Following @imellag's combined-test report, could we agree on #12299 → #8716? #12299 replaces direct value-returning, exit-safe image dispatch with a balanced tree; your deduplication remains useful for the I propose that #8716 integrates downstream, retains its fallback deduplication and narrows the shape assertion to the cases that still emit a switch, with a separate direct-read behavior/validation check. Please confirm the order and who will carry that adaptation and combined validation; I will record the reciprocal declaration once agreed. I am refreshing #12299 against main AI-assisted: yes (Codex). |
|
@Filip722 @imellag The order should be #8716 -> #12299 (with #12299 declaring
With #8716 -> #12299, #8716 lands first with |
|
@MarcZX10 Merged current |
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (5, not counted against this PR)Validation IDs already present on main (4 IDs in 405 tests)Skipped (39)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-check — changes requested for current-main performance validation\n\nThe author’s 10/10 focused Vulkan-validation run on main 1b580f13cf7e and head 01514a6e7a49 addresses the earlier test rerun request; the report includes validation-layer loading and zero VUID results.\n\nCurrent upstream main has since advanced to d2b15d8802. It changed core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp, core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp, and docs/dev/debt/shader.md, all touched by this PR. The clean merge preview does not make the existing tests or performance comparison current for those emitter/materialization changes. Please update the branch and rerun the focused comparison on current main and the updated head with validation enabled. Since this is a perf PR and the changed main paths overlap the measured shader work, refresh the same-scene/same-machine summary lines, traces, and trace digests for the new pair.\n\nI checked the current-main merge preview and whitespace; both are clean. I did not run local GPU tests. Hosted Linux/Windows relinker and ASan pass; platform product jobs are skipped, and macOS relinker jobs remain queued.
|
@hamb3r @MarcZX10 I accept #8716 → #12299 and own the downstream adaptation and combined validation. Pushed Paired required-Radeon/Khronos/no-cache validation on your prerequisite and our combined head gives seven passes on each side and the same pre-existing image-table descriptor-allocation failure, zero VUIDs, no skips/missing layer. The previously failing Gameplay captures remain paused at the author’s request; the old standalone timing report is preserved with its original labels and does not qualify this integration. Updated performance evidence remains open. AI-assisted: yes (Codex). |
|
@Filip722 @imellag @MarcZX10 Sounds good, agreed on #8716 -> #12299 ( @oneandonlydean Everything is ready on this PR:
|
✅ NVIDIA GPU test: passedPR head
Unstable on main (2, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (5, not counted against this PR)Validation IDs already present on main (4 IDs in 404 tests)Skipped (39)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
@hamb3r Following up on the agreed #8716 → #12299 order: our downstream PR now includes the four-line separate-heap-source fixture correction for the #9749 interaction, in 5e4b0682fc. It retains the OpSwitch assertions and the nested-table rejection. The reproduction and corrected combined-tree result are documented here. Your published head still predates that correction. Could you apply it to #8716 and address its current-main/focused-validation review so the prerequisite can land? We retain downstream ownership and will revalidate #12299 after your refresh. The downstream macOS CI configuration issue is also fixed; both write-watch jobs now pass. This is dependency coordination, not a claim that #8716 or the full combined tree has been freshly tested by this follow-up. AI-assisted: yes (Codex). |
|
@Filip722 @MarcZX10 Merged current Re-ran the 10 focused Vulkan validation tests with |
✅ NVIDIA GPU test: passedPR head
Unstable on main (2, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (4, not counted against this PR)Validation IDs already present on main (5 IDs in 484 tests)Skipped (46)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
@hamb3r Confirmed the downstream refresh promised above: #12299 now integrates your Both exact trees pass all eight focused image/shader tests on Radeon 760M/private RADV 26.2.6 with required Vulkan, cache bypass and actual Khronos layers, with no VUIDs, synchronization hazards, missing layers or skips. The report is on #12299. Landing order remains #8716 → #12299. #12299 is draft because the current selector is specialized by merged #11952 and the new diagnostic pair does not demonstrate a gain; that value decision is separate from this completed combined validation. AI-assisted: yes (Codex). |
What
EmitImage(SameImageModeForInstruction) forImageAtomic,ImageQueryDimensions,ImageQueryLod,ImageRead, andImageWriteso modes that emit identical SPIR-V share a singleOpSwitchtarget basic block with multiple case literals.EmitImageSampleInstructionwhen the sample already uses LOD 0 (hasExplicitZeroLod:ImageSampleLZ,ImageSampleC_LZ, orImageSampleExplicitLodwith constant0.0fLOD).EmitFormatStoreComponentinEmitFormatConvertedImageStorefor 32-bitSINTcomponents, whereEmitFormatStoreComponentalready returns its input unchanged.Tested
x86_64), NVIDIA GeForce RTX 3080 (driver 617.14), AMD Ryzen 7 7700:main(7a5d9bf02af6) and on this branch (45998c33789b) withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(ctest --test-dir build-portable -R "^(agc_shader_memory|agc_redundant_value_elimination|agc_shader_srt_read_patching|agc_formatted_buffer_once|agc_formatted_buffer_byte_stores|agc_driver_gated_dispatch_capture|agc_driver_image_sample_unnormalized|agc_driver_image_store_sint|agc_driver_image_table|agc_driver_prepared_shaders_indirect)$" -V):main(5.10stotal) and this branch (5.78stotal).was not found but was requested by env var VK_INSTANCE_LAYERSand 0VUID-validation errors are logged.PPSA01341v01.007.000,APS5_TRACE_FRAMES=0:5): total cached SPIR-V size across the 278 shaders inframes 0:5decreased by 6,172,384 bytes (249.12 MB->243.23 MB).tools/trace_digest.py—main(ca74ef2177ee)frames 0:5 from present 0: 5 presents, frame p50 970.2 / p90 178158.2 / p99 178158.2 / max 178158.2 ms, GPU busy 51.6 ms per present
NVIDIA GeForce RTX 3080, NVIDIA 617.14, Windows 10.0.19045, 1920x1080, commit ca74ef2, dropped: no
{"commit":"ca74ef2177ee","dirty":false,"env":{"APS5_DRAW_CACHE_ENTRIES":"4096","APS5_GPU_WAIT_TIMEOUT_MS":"50","APS5_LAZY_SHADER_PREPARE":"1","APS5_NO_SNAPSHOT_CHECK":"1","APS5_PIPELINED_DRAWS":"1","APS5_PIPELINE_DISPATCH":"1","APS5_SKIP_FAILED_SHADERS":"1","APS5_TEXTURE_CACHE_MIB":"6144","APS5_THREAD_PRIORITY":"off","APS5_TRACE_DIR":"logs","APS5_TRACE_FRAMES":"0:5","APS5_UNKEYED_TABLE_KEYS":"256"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 617.14","os":"Windows 10.0.19045","cpu":"AMD Ryzen 7 7700 8-Core Processor","cpu_threads":16,"memory_mib":48005,"title_id":"PPSA01341","title":"Demon's Souls","content_version":"01.007.000","resolution":"1920x1080","window":{"spec":"frames 0:5","first_present":0,"ms":181523.249},"presents":5,"frame_ms":{"p50":970.158,"p90":178158.169,"p99":178158.169,"max":178158.169},"gpu_busy_ms_per_present":51.609,"worker_busy_pct":{"queue worker 0x0":99.911,"queue worker 0x20":99.91,"queue worker 0x28":99.812,"queue worker 0x30":99.91,"queue worker 0x38":99.887,"queue worker 0x40":99.903,"queue worker 0x50":99.901,"queue worker 0x48":99.815},"top_phases_ms_per_frame":{"Driver.Packet":290051.157,"Driver.Packet.memory_wait":251696.612,"Driver.Packet.dispatch":38274.806,"Driver.Dispatch":38227.808,"Vulkan.ComputePipeline":35186.352,"Driver.Dispatch.prepared_invocation":1210.725,"Driver.Dispatch.materialize":601.947,"Vulkan.Dispatch":489.598},"trace_dropped":false,"trace":"aps5-trace-ca74ef2177ee-49812.json.gz"}Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 290048.8, Driver.Packet.memory_wait 251696.5, Driver.Packet.dispatch 38274.4, Driver.Dispatch 38227.1, Vulkan.ComputePipeline 35186.4, Driver.Dispatch.prepared_invocation 1210.4, Driver.Dispatch.materialize 601.1, Vulkan.Dispatch 489.1, Vulkan.Dispatch.shader_resources 476.1, Resources.Prepare 331.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py— PR (4bf7fec0488f)frames 0:5 from present 0: 5 presents, frame p50 834.3 / p90 17540.9 / p99 17540.9 / max 17540.9 ms, GPU busy 44.2 ms per present
NVIDIA GeForce RTX 3080, NVIDIA 617.14, Windows 10.0.19045, 1920x1080, commit 4bf7fec, dropped: no
{"commit":"4bf7fec0488f","dirty":false,"env":{"APS5_DRAW_CACHE_ENTRIES":"4096","APS5_GPU_WAIT_TIMEOUT_MS":"50","APS5_LAZY_SHADER_PREPARE":"1","APS5_NO_SNAPSHOT_CHECK":"1","APS5_PIPELINED_DRAWS":"1","APS5_PIPELINE_DISPATCH":"1","APS5_SKIP_FAILED_SHADERS":"1","APS5_TEXTURE_CACHE_MIB":"6144","APS5_THREAD_PRIORITY":"off","APS5_TRACE_DIR":"logs","APS5_TRACE_FRAMES":"0:5","APS5_UNKEYED_TABLE_KEYS":"256"},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 617.14","os":"Windows 10.0.19045","cpu":"AMD Ryzen 7 7700 8-Core Processor","cpu_threads":16,"memory_mib":48005,"title_id":"PPSA01341","title":"Demon's Souls","content_version":"01.007.000","resolution":"1920x1080","window":{"spec":"frames 0:5","first_present":0,"ms":21003.83},"presents":5,"frame_ms":{"p50":834.291,"p90":17540.886,"p99":17540.886,"max":17540.886},"gpu_busy_ms_per_present":44.222,"worker_busy_pct":{"queue worker 0x0":99.003,"queue worker 0x20":99.022,"queue worker 0x30":99.019,"queue worker 0x38":98.797,"queue worker 0x40":99.022,"queue worker 0x48":98.79,"queue worker 0x28":98.915,"queue worker 0x50":98.974},"top_phases_ms_per_frame":{"Driver.Packet":33210.363,"Driver.Packet.memory_wait":27772.831,"Driver.Packet.dispatch":5391.425,"Driver.Dispatch":5366.233,"Vulkan.ComputePipeline":3652.81,"Driver.Dispatch.materialize":580.937,"Vulkan.Dispatch":409.216,"Vulkan.Dispatch.shader_resources":394.661},"trace_dropped":false,"trace":"aps5-trace-4bf7fec0488f-34668.json.gz"}Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 33203.2, Driver.Packet.memory_wait 27768.9, Driver.Packet.dispatch 5389.9, Driver.Dispatch 5365.5, Vulkan.ComputePipeline 3652.8, Driver.Dispatch.materialize 580.1, Vulkan.Dispatch 408.7, Vulkan.Dispatch.shader_resources 394.3, Driver.Dispatch.prepared_invocation 225.6, Driver.Dispatch.lookup_cache 223.7
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)