Skip to content

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

Merged
oneandonlydean merged 10 commits into
boykopovar:mainfrom
hamb3r:perf/shader-image-emitter-dedup
Nov 2, 2026
Merged

oneandonlydean merged 10 commits into
boykopovar:mainfrom
hamb3r:perf/shader-image-emitter-dedup

Conversation

@hamb3r

@hamb3r hamb3r commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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 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)

  • 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 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)

  • 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

@github-actions github-actions Bot added the perf Performance change label Oct 20, 2026
return false;
}
const auto opcode = inst.Opcode();
if (ImageOpcodeInfoOf(opcode).access == ImageAccess::Atomic || opcode == IrOpcode::ImageQueryDimensions) {

@MarcZX10 MarcZX10 Oct 20, 2026 •

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.

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.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 10867 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp L1665
PR 14944 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L10153

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 907 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 5021 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 5371 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6280 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 7223 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 7410 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7642 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 7684 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 8004 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 9020 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 9183 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 9335 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 9356 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 9387 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 10233 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 10359 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 10547 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 10757 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 11351 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 11483 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 11551 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 12324 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 12548 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 12828 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp

@github-actions github-actions Bot added the shader core/shader label Oct 20, 2026
@hamb3r
hamb3r force-pushed the perf/shader-image-emitter-dedup branch from 4bf7fec to d8ea386 Compare October 20, 2026 22:49
@hamb3r

hamb3r commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

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

@github-actions github-actions Bot added the agc libSceAgc* label Oct 21, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@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

hamb3r commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@hamb3r

hamb3r commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Merged current main (fcd455870c) into 8a747c6ef1, resolved the #include conflict in ShaderMemory.cpp, and re-verified agc_shader_memory.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 23, 2026

@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.

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.

@hamb3r

hamb3r commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Merged current main (11b175a6b) into this branch (beeda2f06d), preserving both #6801's ShaderMemory.cpp additions and verifyRuntimeImageSwitchDeduplication():

  • python tools/check_main_sync.py --base origin/main --head HEAD: 0 behind origin/main (merge base 11b175a6b), merge: clean
  • python tools/check_conventions.py --base origin/main: All conventions checks passed.
  • Re-ran the focused shader and AGC validation tests on the resulting head 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 (3.93s total, 0 VUID- validation errors, no missing VK_INSTANCE_LAYERS warning).

@hamb3r

hamb3r commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Rebased/merged latest main (11b175a6b -> beeda2f06d), all checks and focused validation tests pass — ready to go!

@babyhuey

Copy link
Copy Markdown
Contributor

Linux run of this head beeda2f06d1, merged onto main 442c43a574d (clean merge, local only), with the selection CI's skipped Linux product job uses: anyps5-build CI image (Ubuntu 24.04, GCC 13, Release, BUILD_TESTING=ON), lavapipe with ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx. The tree was configured fresh after the merge and built in full, then select_tests.py select / ninja -f select.ninja selected / --target libs / select_tests.py ctest --timeout 120.

  • Selected 1,465 tests: all pass. (main itself passes its full suite in this container.)

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 27, 2026
…tter-dedup

# Conflicts:
#	core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
@hamb3r

hamb3r commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Rebased/merged latest main

@JJenkx

JJenkx commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

A CPU-only data point from another title: I recompiled the 71 shader requests dumped from Mortal Shell II (PPSA34008) with agc_shader_replay on Windows (WinLibs GCC 15.2.0, Release). main e4da19aff0 and main + this PR (56233fe2f2, a merge of e6504377c6) produce identical SPIR-V word counts for all 71 (1,400,031 words in total). The emitter was rebuilt for the PR arm, so this title just has none of the runtime image modes the change merges. It's a neutral result rather than a regression.

AI-assisted: yes (Claude Code).

@imellag imellag 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.

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 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.

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.

@Filip722

Copy link
Copy Markdown
Contributor

@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 OpSwitch fallback (tables, writes and continuation cases). I inspected both current diffs: the combined failure is your new fixture requiring an OpSwitch for the direct read that the tree replaces. Clean textual merging does not resolve that interaction.

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 edf6804cf52c and will report its standalone validation and fresh camp comparison separately. This is source inspection, not a passing combined-runtime claim.

AI-assisted: yes (Codex).

@hamb3r

hamb3r commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@Filip722 @imellag The order should be #8716 -> #12299 (with #12299 declaring Depends on #8716), for both chronological and technical reasons:

  1. Order of opening: perf(shader): deduplicate runtime image switch modes and base-level sample branches #8716 was opened on Oct 20 (8 days before perf(shader): balance dense runtime image dispatch #12299 on Oct 28). Per repository overlap conventions, the newer PR targeting the same EmitImage path should depend on the earlier PR (Depends on #8716).
  2. Technical interaction in EmitImage: In perf(shader): balance dense runtime image dispatch #12299 (85eba6b3b8), the early if (returnsValue && !tables && exits && modes.size() > 1u) path recursively calls emitMode(modes[begin]) for every index 0 .. modes.size() - 1 without deduplicating equivalent modes via SameImageModeForInstruction. For returnsValue instructions (ImageQueryDimensions, ImageQueryLod, ImageAtomic*, and packed/swizzled ImageRead), multiple entries in modes produce identical SPIR-V:

With #8716 -> #12299, #8716 lands first with SameImageModeForInstruction and the OpSwitch deduplication test intact, and #12299 can then build on top of SameImageModeForInstruction (avoiding duplicate leaf emission for equivalent returnsValue modes) and update the test assertion accordingly.

@hamb3r

hamb3r commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Merged current main (1b580f13cf7e) into this branch at head 01514a6e7a49 and reran the 10 focused shader/image tests (including agc_shader_memory) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation on both main (1b580f13cf7e, 8.25s total, agc_driver_image_table 3.16s) and this branch (01514a6e7a49, 5.18s total, agc_driver_image_table 1.16s): 10/10 passed, no missing-layer messages, and 0 VUID- validation errors. Updated the Tested section accordingly.

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head e650437 merged onto main 52c09d5 · tested 2026-10-29 10:28 UTC · 19 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,198 passed · 6 failed (0 new, 5 also fail on main, 1 unstable on main) · 39 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,243 of 2,873 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (855 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) none
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_submit_progress: failed in 2 of the last 4 main runs
Failing on main too (5, not counted against this PR)
agc_compute_pipeline_inspection
agc_submit_progress
agc_submit_progress_no_timeline
guest_mmap_executable
guest_socket_options_multicast
Validation IDs already present on main (4 IDs in 405 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (405 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_passes, agc_driver_address_passes_draw_transitions, agc_driver_address_passes_targets_split, agc_driver_alpha_to_coverage, agc_driver_array_layer_target_cpu, agc_driver_bc_block_copy, and 397 more
VUID-vkCmdCopyImage-srcImage-01548 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-vkCmdCopyImage-srcImage-01551 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
Skipped (39)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_msaa_dcc_compared_import_2: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_4: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_8: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_stencil_ref_export: skipped, the device lacks VK_EXT_shader_stencil_export
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fresh: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_labels: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SD
Reproduce
git fetch origin e6504377c6b565b8ab39609d5f83e7391a8df116 52c09d567d2fa453494dd720fcf53a98149468e4
git checkout 52c09d567d2fa453494dd720fcf53a98149468e4 && git merge --no-ff e6504377c6b565b8ab39609d5f83e7391a8df116
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated 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 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.

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.

@Filip722

Copy link
Copy Markdown
Contributor

@hamb3r @MarcZX10 I accept #8716 → #12299 and own the downstream adaptation and combined validation. Pushed b461c319bec8, incorporating your exact 01514a6e7a49 head. Equivalent modes now keep your deduplicated switch; distinct direct value-returning modes use the balanced tree. Your packed-read/write shape assertions remain intact.

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 agc_shader_memory now passes. The body declares Depends on: #8716 and records exact sources/environment. Please record the reciprocal landing order on #8716 and review this resolution.

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).

@hamb3r

hamb3r commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@Filip722 @imellag @MarcZX10 Sounds good, agreed on #8716 -> #12299 (Depends on: none on #8716, Depends on: #8716 on #12299). Thanks for adapting #12299 on top of 01514a6e7a49 and verifying the combined agc_shader_memory pass!

@oneandonlydean Everything is ready on this PR:

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head 01514a6 merged onto main ba5b533 · tested 2026-10-29 16:28 UTC · 30 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,207 passed · 7 failed (0 new, 5 also fail on main, 2 unstable on main) · 39 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,253 of 2,891 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (855 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_lazy_resolved_abi_switch_set 37.0 s, ⚠️ agc_driver_graphics_maps_fallback 36.5 s, ⚠️ agc_driver_native_depth_clears 30.1 s
Unstable on main (2, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_native_depth_clears: failed in 2 of the last 5 main runs
agc_driver_submit_progress: failed in 3 of the last 5 main runs
Failing on main too (5, not counted against this PR)
agc_compute_pipeline_inspection
agc_submit_progress
agc_submit_progress_no_timeline
guest_mmap_executable
guest_socket_options_multicast
Validation IDs already present on main (4 IDs in 404 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (404 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_passes, agc_driver_address_passes_draw_transitions, agc_driver_address_passes_targets_split, agc_driver_alpha_to_coverage, agc_driver_array_layer_target_cpu, agc_driver_bc_block_copy, and 396 more
VUID-vkCmdCopyImage-srcImage-01548 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-vkCmdCopyImage-srcImage-01551 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
Skipped (39)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_msaa_dcc_compared_import_2: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_4: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_8: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_stencil_ref_export: skipped, the device lacks VK_EXT_shader_stencil_export
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fresh: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_labels: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SD
Reproduce
git fetch origin 01514a6e7a49a41d66fa8448149f121e3e45e72b ba5b5330b37724bca4b99f30faab504653635a04
git checkout ba5b5330b37724bca4b99f30faab504653635a04 && git merge --no-ff 01514a6e7a49a41d66fa8448149f121e3e45e72b
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated 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.

@Filip722

Copy link
Copy Markdown
Contributor

@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).

@hamb3r

hamb3r commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

@Filip722 @MarcZX10 Merged current origin/main (7a5d9bf02af6) and applied the separate heap DescriptorSource (column.heapSource = 1u) in verifyRuntimeImageSwitchDeduplication (45998c33789b) so the non-packed table fixture works with #9749's nested-image-table check.

Re-ran the 10 focused Vulkan validation tests with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation on both origin/main (7a5d9bf02af6, 5.10s) and 45998c33789b (5.78s) — 10/10 passed with 0 VUID- errors, and check_conventions.py / check_main_sync.py are clean.

@TechLevelZero

TechLevelZero commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head 45998c3 merged onto main f2d874c · tested 2026-11-01 21:23 UTC · 29 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,445 passed · 6 failed (0 new, 4 also fail on main, 2 unstable on main) · 46 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,497 of 3,168 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (936 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 119.6 s, ⚠️ agc_driver_lookup_log_fits_build 61.9 s, ⚠️ agc_driver_lazy_resolved_abi 34.4 s, ⚠️ agc_driver_graphics_maps_fallback 31.6 s, ⚠️ agc_driver_graphics 30.3 s
Unstable on main (2, these also failed in recent main runs on this machine; not counted against this PR)
agc_submit_progress: failed in 5 of the last 10 main runs
agc_submit_progress_no_timeline: failed in 7 of the last 10 main runs
Failing on main too (4, not counted against this PR)
agc_driver_dcc_keys_first_write
agc_driver_image_table
guest_mmap_executable
guest_socket_options_multicast
Validation IDs already present on main (5 IDs in 484 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (484 tests): agc_driver, agc_driver_address_passes, agc_driver_alias_copy_label, agc_driver_alpha_to_coverage, agc_driver_array_layer_target, agc_driver_bc_block_copy, agc_driver_bda_anchor_reads, agc_driver_bda_span_reads, and 476 more
VUID-vkCmdCopyImage-srcImage-01548 (7 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_sampling, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-vkCmdCopyImage-srcImage-01551 (7 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_sampling, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (1 test): agc_driver_prepared_exports
VUID-VkShaderModuleCreateInfo-pCode-08737 (1 test): agc_driver_image_sample_derivatives
Skipped (46)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_pipeline_binary_vulkan: skipped, the device lacks VK_KHR_pipeline_binary
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_http_uri_locale: 
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_backtoback: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_dcc: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_deferred: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fps_limit: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL
Reproduce
git fetch origin 45998c33789bc84b5a07a10260ece689b1d9cbde f2d874c1fdccf781c0fa5d86619bb5dd8894b958
git checkout f2d874c1fdccf781c0fa5d86619bb5dd8894b958 && git merge --no-ff 45998c33789bc84b5a07a10260ece689b1d9cbde
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated 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.

@Filip722

Filip722 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

@hamb3r Confirmed the downstream refresh promised above: #12299 now integrates your 45998c33789b prerequisite and main 5bae1a4bc2, retaining the separate-heap fixture correction and equivalent-mode assertions. Matching baseline 7673d25f370d includes that same main and prerequisite; updated #12299 head 12367bdb6c32 differs only in its 40-line balanced dispatch.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf Performance change shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants