perf(shader): deduplicate runtime image switch modes and base-level sample branches #8716

Merged
hamb3r merged 10 commits from upstream-pr/8716 into main 2026-11-02 07:56:57 +00:00
hamb3r commented 2026-10-20 22:01:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-20T22:01:16Z.


What

  • Merge equivalent runtime image modes in EmitImage (SameImageModeForInstruction) for ImageAtomic, ImageQueryDimensions, ImageQueryLod, ImageRead, and ImageWrite so modes that emit identical SPIR-V share a single OpSwitch target basic block with multiple case literals.
  • Skip the unnormalized base-level branch in EmitImageSampleInstruction when the sample already uses LOD 0 (hasExplicitZeroLod: ImageSampleLZ, ImageSampleC_LZ, or ImageSampleExplicitLod with constant 0.0f LOD).
  • Skip calling EmitFormatStoreComponent in EmitFormatConvertedImageStore for 32-bit SINT components, where EmitFormatStoreComponent already returns its input unchanged.

Tested

  • Windows 10.0.19045 (x86_64), NVIDIA GeForce RTX 3080 (driver 617.14), AMD Ryzen 7 7700:
    • Ran focused shader recompiler and AGC image/buffer tests on main (7a5d9bf02af6) and on this branch (45998c33789b) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_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):
      • 10/10 passed on both main (5.10s total) and this branch (5.78s total).
      • Confirmed neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS and 0 VUID- validation errors are logged.
    • Demon's Souls (PPSA01341 v01.007.000, APS5_TRACE_FRAMES=0:5): total cached SPIR-V size across the 278 shaders in frames 0:5 decreased 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 ca74ef2177, 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)

  • present 1: 178158.2 ms at 21 ms: Driver.Packet (queue worker 0x0) 178015.2, Driver.Packet (queue worker 0x30) 178014.1, Driver.Packet (queue worker 0x40) 178002.0, Driver.Packet (queue worker 0x50) 178000.1
  • present 3: 2282.8 ms at 179149 ms: Driver.Packet (queue worker 0x30) 2282.7, Driver.Packet (queue worker 0x50) 2282.5, Driver.Packet (queue worker 0x40) 2282.5, Driver.Packet (queue worker 0x38) 2282.2
  • present 2: 970.2 ms at 178179 ms: Driver.Packet (queue worker 0x40) 969.8, Driver.Packet (queue worker 0x20) 969.5, Driver.Packet (queue worker 0x0) 968.4, Driver.Packet (queue worker 0x50) 967.0
  • present 4: 91.4 ms at 181432 ms: Driver.Packet (queue worker 0x30) 91.0, Driver.Packet (queue worker 0x40) 90.9, Driver.Packet (queue worker 0x50) 90.7, Driver.Packet (queue worker 0x20) 90.5
  • present 0: 20.7 ms at 0 ms: Driver.Present (presenter) 1.4, Driver.Present.queue_present (presenter) 1.0, Vulkan.QueuePresent (presenter) 1.0, Vulkan.QueuePresent.queue_present (presenter) 1.0

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
title 0.1 (0 %) 0.0 (0 %) 36304.5 0.0 Shader.Register 0.1, Shader.ResolveGraphicsStagesAbi 0.0
title 0.0 (0 %) 0.0 (0 %) 36304.6 0.0 Shader.ResolveGraphicsStagesAbi 0.0
title 0.0 (0 %) 0.0 (0 %) 36304.6 0.0
shader prepare 2.1 (0 %) 0.0 (0 %) 36302.6 0.0 Vulkan.GraphicsPipelinePrebuild 2.1
title 0.1 (0 %) 0.0 (0 %) 36304.5 0.0 Shader.Register 0.1
title 0.0 (0 %) 0.0 (0 %) 36304.6 0.0
title 5.8 (0 %) 0.0 (0 %) 36298.9 0.0 Shader.ResolveAbi 5.7, Shader.ResolveGraphicsStagesAbi 0.1
title 0.0 (0 %) 0.0 (0 %) 36304.6 0.0
queue worker 0x0 35724.0 (98 %) 546.8 (2 %) 33.8 5.2 Driver.Packet 36270.8
presenter 1.2 (0 %) 2.6 (0 %) 36300.9 0.1 VideoOut.Flip 3.4, Driver.Present 0.3
draw committer 21.3 (0 %) 249.8 (1 %) 36033.5 0.2 Graphics.Draw 19.6, Vulkan.DispatchRecipe 1.1
queue worker 0x20 1764.7 (5 %) 34507.0 (95 %) 33.0 1.3 Driver.Packet 36263.2, Driver.EndSubmission 8.2
queue worker 0x28 59.4 (0 %) 36212.5 (100 %) 32.7 0.6 Driver.Packet 36234.4, Driver.EndSubmission 1.6
queue worker 0x30 265.2 (1 %) 36006.7 (99 %) 32.8 0.1 Driver.Packet 36270.9, Driver.EndSubmission 0.9
queue worker 0x38 58.7 (0 %) 36212.1 (100 %) 33.8 0.2 Driver.Packet 36236.3, Driver.EndSubmission 27.2
queue worker 0x40 329.7 (1 %) 35939.5 (99 %) 35.5 0.4 Driver.Packet 36269.0, Driver.EndSubmission 0.1
queue worker 0x50 3.0 (0 %) 36265.7 (100 %) 35.9 0.3 Driver.Packet 36268.1, Driver.EndSubmission 0.7
queue worker 0x48 0.0 (0 %) 36268.8 (100 %) 35.8 0.0 Driver.Packet 36236.1, Driver.EndSubmission 1.5
gpu 62.4 (0 %) 0.0 (0 %) 36242.2 0.0 batch 62.4

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

  • Driver.Packet.memory_wait (queue worker 0x50) 177686.8 ms at 485 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x28) 176970.3 ms at 323 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x30) 176124.7 ms at 2048 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x38) 175880.3 ms at 2292 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x40) 175594.8 ms at 2577 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x48) 175584.2 ms at 323 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x20) 170075.8 ms at 2049 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x48) 2265.0 ms at 175907 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x28) 2246.4 ms at 179158 ms, present 3
  • Driver.Packet.memory_wait (queue worker 0x48) 2245.5 ms at 179158 ms, present 3

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 53: 51.3 ms at 2508 ms, present 1: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 281.0, Driver.Packet.dispatch (queue worker 0x0) 281.0, Driver.Dispatch (queue worker 0x0) 281.0, GpuMutex.wait.dispatch (queue worker 0x0) 232.2
  • batch 1: 25.0 ms at 298 ms, present 1: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 321.3, Driver.Packet.dispatch (queue worker 0x0) 321.3, Driver.Dispatch (queue worker 0x0) 321.2, GpuMutex.wait.dispatch (queue worker 0x0) 180.5
  • batch 177: 10.9 ms at 181409 ms, present 3: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 35.4, Driver.Packet.device_lock (queue worker 0x0) 22.7, Driver.Packet.draw (queue worker 0x0) 8.7, Driver.Draw (queue worker 0x0) 8.6
  • batch 136: 6.9 ms at 179107 ms, present 2: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 818.0, Driver.Packet.dispatch (queue worker 0x0) 776.1, Driver.Dispatch (queue worker 0x0) 776.1, Driver.Packet.device_lock (queue worker 0x0) 33.6
  • batch 217: 6.7 ms at 181514 ms, present 4: GPU no ranges; recorded by Graphics.Draw (draw committer) 0.4, Graphics.Draw.draw_and_resource_release (draw committer) 0.4

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 4bf7fec0488f, 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)

  • present 1: 17540.9 ms at 27 ms: Driver.Packet (queue worker 0x0) 17357.3, Driver.Packet (queue worker 0x40) 17356.0, Driver.Packet (queue worker 0x30) 17355.9, Driver.Packet (queue worker 0x50) 17347.1
  • present 3: 2496.6 ms at 18402 ms: Driver.Packet (queue worker 0x30) 2496.4, Driver.Packet (queue worker 0x50) 2496.3, Driver.Packet (queue worker 0x40) 2496.2, Driver.Packet.memory_wait (queue worker 0x50) 2496.0
  • present 2: 834.3 ms at 17568 ms: Driver.Packet (queue worker 0x30) 834.0, Driver.Packet (queue worker 0x40) 834.0, Driver.Packet (queue worker 0x20) 833.8, Driver.Packet (queue worker 0x0) 832.3
  • present 4: 104.9 ms at 20899 ms: Driver.Packet (queue worker 0x30) 104.1, Driver.Packet (queue worker 0x40) 104.0, Driver.Packet (queue worker 0x50) 104.0, Driver.Packet (queue worker 0x20) 103.7
  • present 0: 27.2 ms at 0 ms: Driver.Present (presenter) 2.8, Driver.Present.queue_present (presenter) 1.5, Vulkan.QueuePresent (presenter) 1.5, Vulkan.QueuePresent.queue_present (presenter) 1.5

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
title 5.3 (0 %) 0.0 (0 %) 4195.4 0.0 Shader.ResolveAbi 5.2, Shader.ResolveGraphicsStagesAbi 0.1
title 0.0 (0 %) 0.0 (0 %) 4200.8 0.0
title 0.1 (0 %) 0.0 (0 %) 4200.7 0.0 Shader.Register 0.1
shader prepare 2.0 (0 %) 0.0 (0 %) 4198.8 0.0 Vulkan.GraphicsPipelinePrebuild 2.0
title 0.1 (0 %) 0.0 (0 %) 4200.7 0.0 Shader.Register 0.1
title 0.0 (0 %) 0.0 (0 %) 4200.8 0.0
queue worker 0x0 3551.6 (85 %) 605.8 (14 %) 43.3 5.2 Driver.Packet 4157.4, Driver.EndSubmission 0.0
draw committer 14.9 (0 %) 214.4 (5 %) 3971.5 0.2 Graphics.Draw 13.8, Vulkan.DispatchRecipe 0.6
presenter 1.6 (0 %) 2.2 (0 %) 4197.1 0.1 VideoOut.Flip 3.2, Driver.Present 0.6
queue worker 0x20 1267.8 (30 %) 2890.4 (69 %) 42.6 1.2 Driver.Packet 4151.5, Driver.EndSubmission 6.7
queue worker 0x30 231.3 (6 %) 3927.0 (93 %) 42.4 0.1 Driver.Packet 4158.1, Driver.EndSubmission 0.2
queue worker 0x38 38.5 (1 %) 4119.8 (98 %) 42.4 0.2 Driver.Packet 4148.0, Driver.EndSubmission 2.1
queue worker 0x40 102.3 (2 %) 4055.8 (97 %) 42.6 0.5 Driver.Packet 4158.1, Driver.EndSubmission 0.1
queue worker 0x48 0.0 (0 %) 4157.9 (99 %) 42.8 0.0 Driver.Packet 4148.0, Driver.EndSubmission 1.7
queue worker 0x28 72.7 (2 %) 4084.5 (97 %) 43.5 0.6 Driver.Packet 4126.9, Driver.EndSubmission 28.0
queue worker 0x50 6.4 (0 %) 4150.0 (99 %) 44.4 0.3 Driver.Packet 4155.2, Driver.EndSubmission 1.2
gpu 52.5 (1 %) 0.0 (0 %) 4148.3 0.0 batch 52.5

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

  • Driver.Packet.memory_wait (queue worker 0x50) 17017.3 ms at 543 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x28) 16508.1 ms at 346 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x48) 15704.7 ms at 241 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x30) 15635.8 ms at 1924 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x38) 15349.7 ms at 2211 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x40) 15031.9 ms at 2528 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x20) 12134.1 ms at 855 ms, present 1
  • Driver.Packet.memory_wait (queue worker 0x28) 2466.9 ms at 18407 ms, present 3
  • Driver.Packet.memory_wait (queue worker 0x48) 2466.0 ms at 18407 ms, present 3
  • Driver.Packet.memory_wait (queue worker 0x40) 2418.0 ms at 18402 ms, present 2

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 56: 43.0 ms at 2417 ms, present 1: GPU no ranges; recorded by Recorder.Submit (queue worker 0x40) 0.1
  • batch 1: 27.5 ms at 346 ms, present 1: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 308.5, Driver.Packet.dispatch (queue worker 0x0) 308.4, Driver.Dispatch (queue worker 0x0) 308.4, GpuMutex.wait.dispatch (queue worker 0x0) 202.1
  • batch 98: 8.5 ms at 17544 ms, present 1: GPU no ranges; recorded by Graphics.Draw (draw committer) 6.3, Graphics.Draw.draw_and_resource_release (draw committer) 5.8, Resources.Complete (draw committer) 0.7, Vulkan.GraphicsPipeline (draw committer) 0.6
  • batch 177: 7.0 ms at 20878 ms, present 3: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.0, Graphics.Draw.draw_and_resource_release (draw committer) 1.0, Recorder.Submit (draw committer) 0.0
  • batch 137: 6.2 ms at 18384 ms, present 2: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 684.4, Driver.Packet.dispatch (queue worker 0x0) 666.4, Driver.Dispatch (queue worker 0x0) 666.4, Driver.Packet.device_lock (queue worker 0x0) 9.0

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: NVIDIA GeForce RTX 3080, driver 617.14, Windows 10.0.19045
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4943096964 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8716). Originally posted by [hamb3r](https://github.com/hamb3r) on 2026-10-20T22:01:16Z. --- ### What - Merge equivalent runtime image modes in `EmitImage` (`SameImageModeForInstruction`) for `ImageAtomic`, `ImageQueryDimensions`, `ImageQueryLod`, `ImageRead`, and `ImageWrite` so modes that emit identical SPIR-V share a single `OpSwitch` target basic block with multiple case literals. - Skip the unnormalized base-level branch in `EmitImageSampleInstruction` when the sample already uses LOD 0 (`hasExplicitZeroLod`: `ImageSampleLZ`, `ImageSampleC_LZ`, or `ImageSampleExplicitLod` with constant `0.0f` LOD). - Skip calling `EmitFormatStoreComponent` in `EmitFormatConvertedImageStore` for 32-bit `SINT` components, where `EmitFormatStoreComponent` already returns its input unchanged. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Windows 10.0.19045 (`x86_64`), NVIDIA GeForce RTX 3080 (driver 617.14), AMD Ryzen 7 7700: - Ran focused shader recompiler and AGC image/buffer tests on `main` (`7a5d9bf02af6`) and on this branch (`45998c33789b`) with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_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`): - 10/10 passed on both `main` (`5.10s` total) and this branch (`5.78s` total). - Confirmed neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS` and 0 `VUID-` validation errors are logged. - Demon's Souls (`PPSA01341` v01.007.000, `APS5_TRACE_FRAMES=0:5`): total cached SPIR-V size across the 278 shaders in `frames 0:5` decreased 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 ca74ef2177ee, dropped: no ```json {"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) - present 1: 178158.2 ms at 21 ms: Driver.Packet (queue worker 0x0) 178015.2, Driver.Packet (queue worker 0x30) 178014.1, Driver.Packet (queue worker 0x40) 178002.0, Driver.Packet (queue worker 0x50) 178000.1 - present 3: 2282.8 ms at 179149 ms: Driver.Packet (queue worker 0x30) 2282.7, Driver.Packet (queue worker 0x50) 2282.5, Driver.Packet (queue worker 0x40) 2282.5, Driver.Packet (queue worker 0x38) 2282.2 - present 2: 970.2 ms at 178179 ms: Driver.Packet (queue worker 0x40) 969.8, Driver.Packet (queue worker 0x20) 969.5, Driver.Packet (queue worker 0x0) 968.4, Driver.Packet (queue worker 0x50) 967.0 - present 4: 91.4 ms at 181432 ms: Driver.Packet (queue worker 0x30) 91.0, Driver.Packet (queue worker 0x40) 90.9, Driver.Packet (queue worker 0x50) 90.7, Driver.Packet (queue worker 0x20) 90.5 - present 0: 20.7 ms at 0 ms: Driver.Present (presenter) 1.4, Driver.Present.queue_present (presenter) 1.0, Vulkan.QueuePresent (presenter) 1.0, Vulkan.QueuePresent.queue_present (presenter) 1.0 **Threads** (ms per frame) | thread | busy | wait | untraced | in slices < 20 us | largest | |---|---|---|---|---|---| | title | 0.1 (0 %) | 0.0 (0 %) | 36304.5 | 0.0 | Shader.Register 0.1, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 0.0 (0 %) | 0.0 (0 %) | 36304.6 | 0.0 | Shader.ResolveGraphicsStagesAbi 0.0 | | title | 0.0 (0 %) | 0.0 (0 %) | 36304.6 | 0.0 | | | shader prepare | 2.1 (0 %) | 0.0 (0 %) | 36302.6 | 0.0 | Vulkan.GraphicsPipelinePrebuild 2.1 | | title | 0.1 (0 %) | 0.0 (0 %) | 36304.5 | 0.0 | Shader.Register 0.1 | | title | 0.0 (0 %) | 0.0 (0 %) | 36304.6 | 0.0 | | | title | 5.8 (0 %) | 0.0 (0 %) | 36298.9 | 0.0 | Shader.ResolveAbi 5.7, Shader.ResolveGraphicsStagesAbi 0.1 | | title | 0.0 (0 %) | 0.0 (0 %) | 36304.6 | 0.0 | | | queue worker 0x0 | 35724.0 (98 %) | 546.8 (2 %) | 33.8 | 5.2 | Driver.Packet 36270.8 | | presenter | 1.2 (0 %) | 2.6 (0 %) | 36300.9 | 0.1 | VideoOut.Flip 3.4, Driver.Present 0.3 | | draw committer | 21.3 (0 %) | 249.8 (1 %) | 36033.5 | 0.2 | Graphics.Draw 19.6, Vulkan.DispatchRecipe 1.1 | | queue worker 0x20 | 1764.7 (5 %) | 34507.0 (95 %) | 33.0 | 1.3 | Driver.Packet 36263.2, Driver.EndSubmission 8.2 | | queue worker 0x28 | 59.4 (0 %) | 36212.5 (100 %) | 32.7 | 0.6 | Driver.Packet 36234.4, Driver.EndSubmission 1.6 | | queue worker 0x30 | 265.2 (1 %) | 36006.7 (99 %) | 32.8 | 0.1 | Driver.Packet 36270.9, Driver.EndSubmission 0.9 | | queue worker 0x38 | 58.7 (0 %) | 36212.1 (100 %) | 33.8 | 0.2 | Driver.Packet 36236.3, Driver.EndSubmission 27.2 | | queue worker 0x40 | 329.7 (1 %) | 35939.5 (99 %) | 35.5 | 0.4 | Driver.Packet 36269.0, Driver.EndSubmission 0.1 | | queue worker 0x50 | 3.0 (0 %) | 36265.7 (100 %) | 35.9 | 0.3 | Driver.Packet 36268.1, Driver.EndSubmission 0.7 | | queue worker 0x48 | 0.0 (0 %) | 36268.8 (100 %) | 35.8 | 0.0 | Driver.Packet 36236.1, Driver.EndSubmission 1.5 | | gpu | 62.4 (0 %) | 0.0 (0 %) | 36242.2 | 0.0 | batch 62.4 | **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** - Driver.Packet.memory_wait (queue worker 0x50) 177686.8 ms at 485 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x28) 176970.3 ms at 323 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x30) 176124.7 ms at 2048 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x38) 175880.3 ms at 2292 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x40) 175594.8 ms at 2577 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x48) 175584.2 ms at 323 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x20) 170075.8 ms at 2049 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x48) 2265.0 ms at 175907 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x28) 2246.4 ms at 179158 ms, present 3 - Driver.Packet.memory_wait (queue worker 0x48) 2245.5 ms at 179158 ms, present 3 **Largest GPU batches** (GPU ranges inside, and the CPU slices that recorded each, inclusive) - batch 53: 51.3 ms at 2508 ms, present 1: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 281.0, Driver.Packet.dispatch (queue worker 0x0) 281.0, Driver.Dispatch (queue worker 0x0) 281.0, GpuMutex.wait.dispatch (queue worker 0x0) 232.2 - batch 1: 25.0 ms at 298 ms, present 1: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 321.3, Driver.Packet.dispatch (queue worker 0x0) 321.3, Driver.Dispatch (queue worker 0x0) 321.2, GpuMutex.wait.dispatch (queue worker 0x0) 180.5 - batch 177: 10.9 ms at 181409 ms, present 3: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 35.4, Driver.Packet.device_lock (queue worker 0x0) 22.7, Driver.Packet.draw (queue worker 0x0) 8.7, Driver.Draw (queue worker 0x0) 8.6 - batch 136: 6.9 ms at 179107 ms, present 2: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 818.0, Driver.Packet.dispatch (queue worker 0x0) 776.1, Driver.Dispatch (queue worker 0x0) 776.1, Driver.Packet.device_lock (queue worker 0x0) 33.6 - batch 217: 6.7 ms at 181514 ms, present 4: GPU no ranges; recorded by Graphics.Draw (draw committer) 0.4, Graphics.Draw.draw_and_resource_release (draw committer) 0.4 #### `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 4bf7fec0488f, dropped: no ```json {"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) - present 1: 17540.9 ms at 27 ms: Driver.Packet (queue worker 0x0) 17357.3, Driver.Packet (queue worker 0x40) 17356.0, Driver.Packet (queue worker 0x30) 17355.9, Driver.Packet (queue worker 0x50) 17347.1 - present 3: 2496.6 ms at 18402 ms: Driver.Packet (queue worker 0x30) 2496.4, Driver.Packet (queue worker 0x50) 2496.3, Driver.Packet (queue worker 0x40) 2496.2, Driver.Packet.memory_wait (queue worker 0x50) 2496.0 - present 2: 834.3 ms at 17568 ms: Driver.Packet (queue worker 0x30) 834.0, Driver.Packet (queue worker 0x40) 834.0, Driver.Packet (queue worker 0x20) 833.8, Driver.Packet (queue worker 0x0) 832.3 - present 4: 104.9 ms at 20899 ms: Driver.Packet (queue worker 0x30) 104.1, Driver.Packet (queue worker 0x40) 104.0, Driver.Packet (queue worker 0x50) 104.0, Driver.Packet (queue worker 0x20) 103.7 - present 0: 27.2 ms at 0 ms: Driver.Present (presenter) 2.8, Driver.Present.queue_present (presenter) 1.5, Vulkan.QueuePresent (presenter) 1.5, Vulkan.QueuePresent.queue_present (presenter) 1.5 **Threads** (ms per frame) | thread | busy | wait | untraced | in slices < 20 us | largest | |---|---|---|---|---|---| | title | 5.3 (0 %) | 0.0 (0 %) | 4195.4 | 0.0 | Shader.ResolveAbi 5.2, Shader.ResolveGraphicsStagesAbi 0.1 | | title | 0.0 (0 %) | 0.0 (0 %) | 4200.8 | 0.0 | | | title | 0.1 (0 %) | 0.0 (0 %) | 4200.7 | 0.0 | Shader.Register 0.1 | | shader prepare | 2.0 (0 %) | 0.0 (0 %) | 4198.8 | 0.0 | Vulkan.GraphicsPipelinePrebuild 2.0 | | title | 0.1 (0 %) | 0.0 (0 %) | 4200.7 | 0.0 | Shader.Register 0.1 | | title | 0.0 (0 %) | 0.0 (0 %) | 4200.8 | 0.0 | | | queue worker 0x0 | 3551.6 (85 %) | 605.8 (14 %) | 43.3 | 5.2 | Driver.Packet 4157.4, Driver.EndSubmission 0.0 | | draw committer | 14.9 (0 %) | 214.4 (5 %) | 3971.5 | 0.2 | Graphics.Draw 13.8, Vulkan.DispatchRecipe 0.6 | | presenter | 1.6 (0 %) | 2.2 (0 %) | 4197.1 | 0.1 | VideoOut.Flip 3.2, Driver.Present 0.6 | | queue worker 0x20 | 1267.8 (30 %) | 2890.4 (69 %) | 42.6 | 1.2 | Driver.Packet 4151.5, Driver.EndSubmission 6.7 | | queue worker 0x30 | 231.3 (6 %) | 3927.0 (93 %) | 42.4 | 0.1 | Driver.Packet 4158.1, Driver.EndSubmission 0.2 | | queue worker 0x38 | 38.5 (1 %) | 4119.8 (98 %) | 42.4 | 0.2 | Driver.Packet 4148.0, Driver.EndSubmission 2.1 | | queue worker 0x40 | 102.3 (2 %) | 4055.8 (97 %) | 42.6 | 0.5 | Driver.Packet 4158.1, Driver.EndSubmission 0.1 | | queue worker 0x48 | 0.0 (0 %) | 4157.9 (99 %) | 42.8 | 0.0 | Driver.Packet 4148.0, Driver.EndSubmission 1.7 | | queue worker 0x28 | 72.7 (2 %) | 4084.5 (97 %) | 43.5 | 0.6 | Driver.Packet 4126.9, Driver.EndSubmission 28.0 | | queue worker 0x50 | 6.4 (0 %) | 4150.0 (99 %) | 44.4 | 0.3 | Driver.Packet 4155.2, Driver.EndSubmission 1.2 | | gpu | 52.5 (1 %) | 0.0 (0 %) | 4148.3 | 0.0 | batch 52.5 | **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** - Driver.Packet.memory_wait (queue worker 0x50) 17017.3 ms at 543 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x28) 16508.1 ms at 346 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x48) 15704.7 ms at 241 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x30) 15635.8 ms at 1924 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x38) 15349.7 ms at 2211 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x40) 15031.9 ms at 2528 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x20) 12134.1 ms at 855 ms, present 1 - Driver.Packet.memory_wait (queue worker 0x28) 2466.9 ms at 18407 ms, present 3 - Driver.Packet.memory_wait (queue worker 0x48) 2466.0 ms at 18407 ms, present 3 - Driver.Packet.memory_wait (queue worker 0x40) 2418.0 ms at 18402 ms, present 2 **Largest GPU batches** (GPU ranges inside, and the CPU slices that recorded each, inclusive) - batch 56: 43.0 ms at 2417 ms, present 1: GPU no ranges; recorded by Recorder.Submit (queue worker 0x40) 0.1 - batch 1: 27.5 ms at 346 ms, present 1: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 308.5, Driver.Packet.dispatch (queue worker 0x0) 308.4, Driver.Dispatch (queue worker 0x0) 308.4, GpuMutex.wait.dispatch (queue worker 0x0) 202.1 - batch 98: 8.5 ms at 17544 ms, present 1: GPU no ranges; recorded by Graphics.Draw (draw committer) 6.3, Graphics.Draw.draw_and_resource_release (draw committer) 5.8, Resources.Complete (draw committer) 0.7, Vulkan.GraphicsPipeline (draw committer) 0.6 - batch 177: 7.0 ms at 20878 ms, present 3: GPU no ranges; recorded by Graphics.Draw (draw committer) 1.0, Graphics.Draw.draw_and_resource_release (draw committer) 1.0, Recorder.Submit (draw committer) 0.0 - batch 137: 6.2 ms at 18384 ms, present 2: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 684.4, Driver.Packet.dispatch (queue worker 0x0) 666.4, Driver.Dispatch (queue worker 0x0) 666.4, Driver.Packet.device_lock (queue worker 0x0) 9.0 ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3080, driver 617.14, Windows 10.0.19045 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-20 22:03:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:03:53Z.

Code review location: core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp; line 1897

@@ -1887,6 +1888,47 @@ void EmitImageMode(SpirvValueEmitContext& ctx, const IrValue& inst, const ImageR
     }
 }
 
+bool SameImageModeForInstruction(const IrValue& inst, const MemoryInfo& memory, const ImageResource& a, const ImageResource& b) {
+    if (a.resourceClass != b.resourceClass || a.dimension != b.dimension || a.numericClass != b.numericClass ||
+        a.depthCompare != b.depthCompare || a.atomic != b.atomic || a.atomic64 != b.atomic64 || a.table != b.table || a.depthBits != b.depthBits) {
+        return false;
+    }
+    const auto opcode = inst.Opcode();
+    if (ImageOpcodeInfoOf(opcode).access == ImageAccess::Atomic || opcode == IrOpcode::ImageQueryDimensions) {

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4330823247 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8716#discussion_r4330823247). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T22:03:53Z. **Code review location:** `core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp`; line 1897 ~~~~diff @@ -1887,6 +1888,47 @@ void EmitImageMode(SpirvValueEmitContext& ctx, const IrValue& inst, const ImageR } } +bool SameImageModeForInstruction(const IrValue& inst, const MemoryInfo& memory, const ImageResource& a, const ImageResource& b) { + if (a.resourceClass != b.resourceClass || a.dimension != b.dimension || a.numericClass != b.numericClass || + a.depthCompare != b.depthCompare || a.atomic != b.atomic || a.atomic64 != b.atomic64 || a.table != b.table || a.depthBits != b.depthBits) { + return false; + } + const auto opcode = inst.Opcode(); + if (ImageOpcodeInfoOf(opcode).access == ImageAccess::Atomic || opcode == IrOpcode::ImageQueryDimensions) { ~~~~ --- 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.
hamb3r commented 2026-10-21 00:31:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-21T00:31:28Z.


Rebased/merged origin/main (d8ea38616e) and audited line-by-line gcov diff coverage on core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp.

Uncovered diff lines before (40 / 43 = 93.0%)

        2 : 1909 :         if (memory.imagePacked) {
    ##### : 1910 :             return a.packedFormat == b.packedFormat && (a.conversionFormat != IrBufferFormat::Invalid) == (b.conversionFormat != IrBufferFormat::Invalid);
        - : 1911 :         }
        2 : 1912 :         return a.conversionFormat == b.conversionFormat && (a.conversionFormat == IrBufferFormat::Invalid || a.shaderSwizzle == b.shaderSwizzle);
        - : 1913 :     }
       52 : 1914 :     if (opcode == IrOpcode::ImageWrite) {
       52 : 1915 :         if (a.mipMode != b.mipMode) {
    ##### : 1916 :             return false;
        - : 1917 :         }
       52 : 1918 :         if (memory.imagePacked) {
    ##### : 1919 :             return a.packedFormat == b.packedFormat && (a.conversionFormat != IrBufferFormat::Invalid) == (b.conversionFormat != IrBufferFormat::Invalid);
        - : 1920 :         }

Coverage added in dd90db591d (43 / 43 = 100.0%)

Added verifyRuntimeImageSwitchDeduplication() in core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp (agc_shader_memory) to exercise:

  1. Packed IrOpcode::ImageRead and IrOpcode::ImageWrite runtime-image OpSwitch deduplication across ResourceMaterializer::RuntimeImageModes(image) (verifying that packed cube and 2D-array modes with identical packedFormat share an OpSwitch label while distinct packedFormats stay separate — covering lines 1910 and 1919).
  2. Storage-table IrOpcode::ImageWrite runtime-image modes with distinct ImageMipMode values (verifying that they emit distinct OpSwitch labels — covering line 1916).
      437 : 1909 :         if (memory.imagePacked) {
      435 : 1910 :             return a.packedFormat == b.packedFormat && (a.conversionFormat != IrBufferFormat::Invalid) == (b.conversionFormat != IrBufferFormat::Invalid);
        - : 1911 :         }
        2 : 1912 :         return a.conversionFormat == b.conversionFormat && (a.conversionFormat == IrBufferFormat::Invalid || a.shaderSwizzle == b.shaderSwizzle);
        - : 1913 :     }
      275 : 1914 :     if (opcode == IrOpcode::ImageWrite) {
      275 : 1915 :         if (a.mipMode != b.mipMode) {
        1 : 1916 :             return false;
        - : 1917 :         }
      274 : 1918 :         if (memory.imagePacked) {
      222 : 1919 :             return a.packedFormat == b.packedFormat && (a.conversionFormat != IrBufferFormat::Invalid) == (b.conversionFormat != IrBufferFormat::Invalid);
        - : 1920 :         }

Diff executable lines covered: 43 / 43 (100.0%)

Focused tests re-verified with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (0 VUID- errors).

cc @MarcZX10

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6304965387 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8716#issuecomment-6304965387). Originally posted by [hamb3r](https://github.com/hamb3r) on 2026-10-21T00:31:28Z. --- Rebased/merged `origin/main` (`d8ea38616e`) and audited line-by-line `gcov` diff coverage on `core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp`. ### Uncovered diff lines before (`40 / 43 = 93.0%`) ```text 2 : 1909 : if (memory.imagePacked) { ##### : 1910 : return a.packedFormat == b.packedFormat && (a.conversionFormat != IrBufferFormat::Invalid) == (b.conversionFormat != IrBufferFormat::Invalid); - : 1911 : } 2 : 1912 : return a.conversionFormat == b.conversionFormat && (a.conversionFormat == IrBufferFormat::Invalid || a.shaderSwizzle == b.shaderSwizzle); - : 1913 : } 52 : 1914 : if (opcode == IrOpcode::ImageWrite) { 52 : 1915 : if (a.mipMode != b.mipMode) { ##### : 1916 : return false; - : 1917 : } 52 : 1918 : if (memory.imagePacked) { ##### : 1919 : return a.packedFormat == b.packedFormat && (a.conversionFormat != IrBufferFormat::Invalid) == (b.conversionFormat != IrBufferFormat::Invalid); - : 1920 : } ``` ### Coverage added in `dd90db591d` (`43 / 43 = 100.0%`) Added `verifyRuntimeImageSwitchDeduplication()` in `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` (`agc_shader_memory`) to exercise: 1. Packed `IrOpcode::ImageRead` and `IrOpcode::ImageWrite` runtime-image `OpSwitch` deduplication across `ResourceMaterializer::RuntimeImageModes(image)` (verifying that packed cube and 2D-array modes with identical `packedFormat` share an `OpSwitch` label while distinct `packedFormat`s stay separate — covering lines `1910` and `1919`). 2. Storage-table `IrOpcode::ImageWrite` runtime-image modes with distinct `ImageMipMode` values (verifying that they emit distinct `OpSwitch` labels — covering line `1916`). ```text 437 : 1909 : if (memory.imagePacked) { 435 : 1910 : return a.packedFormat == b.packedFormat && (a.conversionFormat != IrBufferFormat::Invalid) == (b.conversionFormat != IrBufferFormat::Invalid); - : 1911 : } 2 : 1912 : return a.conversionFormat == b.conversionFormat && (a.conversionFormat == IrBufferFormat::Invalid || a.shaderSwizzle == b.shaderSwizzle); - : 1913 : } 275 : 1914 : if (opcode == IrOpcode::ImageWrite) { 275 : 1915 : if (a.mipMode != b.mipMode) { 1 : 1916 : return false; - : 1917 : } 274 : 1918 : if (memory.imagePacked) { 222 : 1919 : return a.packedFormat == b.packedFormat && (a.conversionFormat != IrBufferFormat::Invalid) == (b.conversionFormat != IrBufferFormat::Invalid); - : 1920 : } Diff executable lines covered: 43 / 43 (100.0%) ``` Focused tests re-verified with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (`0` `VUID-` errors). cc @MarcZX10
oneandonlydean commented 2026-10-21 05:54:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T05:54:43Z.


@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 EmitImageSwitch, EmitSampleImageSwitch, EmitWriteSwitch, EmitQuerySwitch, an is_zero_lod short-circuit in EmitImageSampleWithLod and a hoisted result_type, but none of these are in the diff, and SameImageModeForInstruction never merges sampling modes. The code does three things: it merges equal runtime modes in EmitImage for atomic, query, read and write; it skips the unnormalized base-level branch for samples that already use LOD 0; and it skips EmitFormatStoreComponent for 32-bit SINT components. That last one returns its input unchanged at 32 bits already, so the SPIR-V stays the same.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6309142691 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8716#issuecomment-6309142691). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T05:54:43Z. --- @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 `EmitImageSwitch`, `EmitSampleImageSwitch`, `EmitWriteSwitch`, `EmitQuerySwitch`, an `is_zero_lod` short-circuit in `EmitImageSampleWithLod` and a hoisted `result_type`, but none of these are in the diff, and `SameImageModeForInstruction` never merges sampling modes. The code does three things: it merges equal runtime modes in `EmitImage` for atomic, query, read and write; it skips the unnormalized base-level branch for samples that already use LOD 0; and it skips `EmitFormatStoreComponent` for 32-bit SINT components. That last one returns its input unchanged at 32 bits already, so the SPIR-V stays the same.
hamb3r commented 2026-10-21 07:08:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hamb3r on 2026-10-21T07:08:16Z.


@oneandonlydean Updated the PR description (What section) to accurately describe the three changes in SpirvImageEmitter.cpp. Thanks for the review!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310214114 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8716#issuecomment-6310214114). Originally posted by [hamb3r](https://github.com/hamb3r) on 2026-10-21T07:08:16Z. --- @oneandonlydean Updated the PR description (What section) to accurately describe the three changes in SpirvImageEmitter.cpp. Thanks for the review!
oneandonlydean commented 2026-10-21 07:24:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T07:24:50Z.


@hamb3r thanks, the What section now matches the three changes in SpirvImageEmitter.cpp: the merged image modes, the skipped base-level branch for LOD 0 samples, and the skipped conversion for 32-bit SINT components.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310482225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8716#issuecomment-6310482225). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T07:24:50Z. --- @hamb3r thanks, the What section now matches the three changes in `SpirvImageEmitter.cpp`: the merged image modes, the skipped base-level branch for LOD 0 samples, and the skipped conversion for 32-bit SINT components.
MarcZX10 commented 2026-10-23 05:16:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:16:35Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624190571 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8716#pullrequestreview-5624190571). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T05:16:35Z. **Review:** CHANGES_REQUESTED --- 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.
imellag commented 2026-10-28 18:45:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-28T18:45:08Z.

Review: COMMENTED


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)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5687926307 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8716#pullrequestreview-5687926307). Originally posted by [imellag](https://github.com/imellag) on 2026-10-28T18:45:08Z. **Review:** COMMENTED --- **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 commented 2026-10-29 06:15:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:15:35Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5693612453 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8716#pullrequestreview-5693612453). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T06:15:35Z. **Review:** CHANGES_REQUESTED --- ## 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.
MarcZX10 commented 2026-10-29 10:56:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T10:56:18Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5696578308 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8716#pullrequestreview-5696578308). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T10:56:18Z. **Review:** CHANGES_REQUESTED --- ## 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!8716
No description provided.