fix(shader): give equivalent specialized modules one identity #28102
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28102"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-28T15:00:03Z.
What
Two dispatches of one program whose live code is the same could still specialize into different SPIR-V words. Each new word set is a new pipeline key and a full driver compile, and neither the pipeline journal nor the Vulkan pipeline cache can reuse it. This PR makes equivalent specializations produce the same module:
EmitRuntimeBufferLoadreturns before it reads the DST_SELs.APS5_NO_BUFFER_SUBSTITUTESis gone, and the test is renamedagc_driver_null_buffer_specialization.VisitIdOperandsdecodes operands by the core grammar, including the opcode nested inOpSpecConstantOpand the extension opcodes the recompiler emits, and reports any instruction it cannot classify. The normalizer, the specializer and the spanned-uniformity pass then treat every word of such an instruction as a possible id.dfe374c2f94, taken from #28295 as offered there): the specializer now also folds an integer multiply or and with a constant 0 to that 0, and a multiply by 1, an add, or, xor with 0, a subtract of 0 and a logical shift by 0 to the other operand. It leaves an operation alone when that operand's type differs from the result's, and when the result is decorated.APS5_TRACE_SPECIALIZATION_VARIANTSis a new switch. When a program that already has a specialized module gets one for other values, it prints the values that differ from the nearest variant and whether the SPIR-V came out the same. Every specialization constant is printed under its own name (ShaderRecompiler::SpecializationConstantName). The switch only prints, so it is kept out of the shader disk cache key, and a test checks that.Known gaps are recorded as debt (
docs/dev/debt/changes/shader-pipeline-variant-identity.md):Tested
Windows 11, MinGW-w64 GCC (WinLibs), Release, one build directory per comparison:
mainfirst, then this branch rebuilt incrementally. This PR is rebased ontomainf61eb307c02, after #26593.ctest --test-dir build -R <pattern> -Vand the AGENTS.md Vulkan variables (ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer). It covers:ir_opcode_traits,shader_memory_decoder_tolerance,spanned_uniformity,spirv_literal_float,spirv_validator_exit);agc_shader_*test, including the shader disk cache tests;agc_spirv_*test;mainf61eb307c02: 105/105 passed. It runsagc_driver_null_buffer_substitutes.d9149614af0, with the identity-fold commit and the 64-bit switch test change): 105/105 passed, in a fresh build directory aftermain. It runsagc_driver_null_buffer_specialization.cdded18cb0: 105/105 passed; before the rebase,main01022f9a71and this PR were also 105/105 each.agc_driver_image_load_after_store, which is #26593's test, passes onmainand on this PR.Insert instance layer "VK_LAYER_KHRONOS_validation"in the 22 test processes that create an instance;was not found but was requested by env var VK_INSTANCE_LAYERS;VUID-, so this PR adds no validation errors.agc_spirv_module: dead values and declaration order, ids below the input bound, idempotence, decorated constants, dead composite chains, float bit patterns,OpSpecConstantOp, unclassified operands and literals, the emitted extension opcodes, 64-bit switch literals, truncated names, and the arithmetic identity folds. The 64-bit switch case fails when the normalizer reads that literal as one word (checked by forcing it), and passes without that change;agc_driver_null_buffer_specialization: direct, captured and prepared calls; xyzw loads and atomics; a module that does not change after its slot is bound;agc_shader_disk_cache: the partial-dword tail, the trace switch keeping the cache key, and the trace names of the store-pages, storage-read and D16 toward-zero constants.tools/select_tests.pywas not used to widen the set.Recompiler.cpplinks into nearly every AGC test, so it selects close to the whole tree.python3 tools/check_conventions.py: all checks passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)mainand this PR, Khronos validation layer 1.4.363)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T15:08:03Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes support the stated shader specialization identity goal, but this review is incomplete and does not justify approval.
What I ran
Reviewed head
6deb30f989c0cd92329de6e2a60e91cb694bf0e0using the prepared review bundle and targeted source reads. No commands or tests were run.Results
Findings
Blocking
None verified in the inspected portions.
Non-blocking
None.
Not verified
The review bundle lists 15 changed files. I inspected the description, commits, file manifest and parts of the diff, plus targeted portions of
Recompiler.cpp,DescriptorBindingBuilder.cpp,DescriptorBindingBuilder.hpp,SpirvInstructionOperands.hppandNullBufferSpecialization.cpp. I did not read every changed file or all diff hunks. No excluded-file list was available through the reader. Author-reported tests were not run by me.To get this to a good state
Complete inspection of the remaining changed files and diff hunks, then run the relevant checks before making a formal review decision.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T15:11:09Z.
Review: COMMENTED
Actionable comments posted: 1
fae87e12-c095-4400-adfb-c69c73aaa9d6Reviewing files that changed from the base of the PR and between
bb89b8a4f5and6deb30f989.core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/SpirvModule.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_runtime_formatted_store_tests.cmakecore/libs/prx/libSceAgcDriver/tests/execution/BufferDescriptorRuntime.cppcore/libs/prx/libSceAgcDriver/tests/execution/NullBufferSpecialization.cppcore/shader/recompiler/CompiledVariant.hppcore/shader/recompiler/Optimization/include/Optimization/DescriptorBindingBuilder.hppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvSpecialization.hppcore/shader/recompiler/SpirvBackend/src/SpirvInstructionOperands.hppcore/shader/recompiler/SpirvBackend/src/SpirvSpannedUniformity.cppcore/shader/recompiler/SpirvBackend/src/SpirvSpecialization.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/changes/shader-pipeline-variant-identity.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T16:12:55Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: review remains incomplete because several changed implementation files were not read in full, so a formal approval is not justified.
What I ran
Reviewed head
f362b0f0586ace5c2d3af709e58000b725a52c05; no commands or tests were run. Read the PR description, commits, diff, manifest, and selected ranges from the changed implementation and test files.Results
Findings
Blocking
None verified in the inspected ranges.
Non-blocking
None.
Not verified
The changed files
core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp,core/libs/prx/libSceAgcDriver/tests/SpirvModule.cpp,core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_runtime_formatted_store_tests.cmake,core/libs/prx/libSceAgcDriver/tests/execution/BufferDescriptorRuntime.cpp,core/shader/recompiler/CompiledVariant.hpp,core/shader/recompiler/Optimization/include/Optimization/DescriptorBindingBuilder.hpp,core/shader/recompiler/ShaderDiskCache.cpp,core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvSpecialization.hpp,docs/dev/ENVIRONMENT.md, anddocs/dev/debt/changes/shader-pipeline-variant-identity.mdwere not read in full. Additional uninspected ranges remain incore/shader/recompiler/Recompiler.cpp,core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp,core/shader/recompiler/SpirvBackend/src/SpirvSpecialization.cpp, andcore/libs/prx/libSceAgcDriver/tests/execution/NullBufferSpecialization.cpp.core/shader/recompiler/SpirvBackend/src/SpirvInstructionOperands.hppwas read in full. No programmatic checks were run.To get this to a good state
Nothing is required; this draft records an incomplete review and does not make a merge recommendation.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T06:45:43Z.
Review: COMMENTED
Reviewed — comments
The review is incomplete because several changed files and test results were not independently checked, so a formal merge decision is not justified.
What I ran
cdded18cb00cfe1da490ba6d1272f343639533c2.repo_read.py. Ran no build or tests.Results
Findings
Blocking
None verified in the code inspected.
Non-blocking
None.
Not verified
core/shader/recompiler/SpirvBackend/src/SpirvInstructionOperands.hpp,core/shader/recompiler/SpirvBackend/src/SpirvSpecialization.cpp(normalization implementation),core/shader/recompiler/Recompiler.cpp(specialization tracing and prepared binding plan), andcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp(buffer specialization fields); also the displayed portions ofreview/diff.patchand the prepared description, commits, manifest, and file listing.core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp,core/libs/prx/libSceAgcDriver/tests/SpirvModule.cpp,core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_runtime_formatted_store_tests.cmake,core/libs/prx/libSceAgcDriver/tests/execution/BufferDescriptorRuntime.cpp,core/libs/prx/libSceAgcDriver/tests/execution/NullBufferSpecialization.cpp,core/shader/recompiler/CompiledVariant.hpp,core/shader/recompiler/Optimization/include/Optimization/DescriptorBindingBuilder.hpp,core/shader/recompiler/Recompiler.hpp,core/shader/recompiler/ShaderDiskCache.cpp,core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvSpecialization.hpp,core/shader/recompiler/SpirvBackend/src/SpirvSpannedUniformity.cpp,docs/dev/ENVIRONMENT.md, anddocs/dev/debt/changes/shader-pipeline-variant-identity.md.To get this to a good state
Nothing is required. Optional: complete review of the unverified changed files and run the focused checks on this head before making a formal merge decision.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T00:56:30Z.
Review: COMMENTED
Architecture findings (1)
Advisory architecture findings (1)
e2f9e59d-2a94-4fe5-bfd8-665666e32992Reviewing files that changed from the base of the PR and between
cdded18cb0andd9149614af.core/libs/prx/libSceAgcDriver/tests/SpirvModule.cppcore/shader/recompiler/SpirvBackend/src/SpirvSpecialization.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T01:01:36Z.
Review: COMMENTED
Reviewed — comments
The focused inspection found no verified blocking defect, but the full changed-file review and independent test run are incomplete.
What I ran
Reviewed head
d9149614af0b7b515da38e9c4307da4c51edf059using the preparedreviewbundle and the pinnedrepo_read.pyreader. No tests or build commands were run; test results in the description are author-reported.Results
Findings
Blocking
None verified in the inspected sections.
Non-blocking
None.
Not verified
The complete contents of every changed file were not read, and the reported tests were not rerun. Targeted source sections inspected:
DescriptorBindingBuilder.cpp,Recompiler.cpp,SpirvInstructionOperands.hpp,SpirvSpecialization.cpp, andNullBufferSpecialization.cpp. Changed-file hunks inspected inShaderDiskCache.cppandSpirvModule.cpp. Other changed files, and portions outside the targeted ranges in those files, were not verified. The bundle listing showed all changed files included; none were excluded by its inclusion rules.To get this to a good state
Nothing is required. Optional: complete review of the remaining changed-file content and rerun the focused test set on this head before making a formal approval decision.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:46:06Z.
Review: COMMENTED
The operand tests cover literal-preserving normalization, including the 64-bit switch, and the cache fixture checks identity reuse. Could one focused execution case dispatch two distinct specialization inputs that intentionally normalize to the same module, and verify both output data and one native pipeline creation? That would connect the identity assertion to the live cache behavior.
Source review at
d9149614af. The head trial-merges onto700fae9438. Paired Vulkan execution is queued.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.