fix(shader): imply a masked condition that is a structural copy of the mask #21758
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21758"
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 edubox on 2026-11-16T18:44:35Z.
What
ActiveMaskImpliesdecides whether a mask makes a guardedSelecttake only its active arm, which is what lets a per-lane descriptor dword be evaluated at bind time. It accepted the condition only when it was the mask itself or a conjunct of anANDmask, comparing resolved pointers. A mask and the condition of the select it guards reach the IR as different nodes whenever they are computed on two paths, so the runtime validator fell back to validating both arms and refused a lane-dependent arm that no lane the console runs ever reads.The implication now also holds when
EquivalentValuefinds both values equal, the same notion of equality the recompiler already uses to deduplicate descriptor web arms and to resolve an invariant Phi. The program is threaded into the predicate (every call site has it); the threeResourceTrackerhelpers that peel a select under a mask becameconstmembers so they can reachm_program.ShaderDiskCache::FormatVersionmoves 88 to 89: a value this accepts stops being refused or folded, so the same source can emit a different module.Evidence: PPSA07642 (The Last of Us Part I) builds the mask and the condition of the S# dword's
v_readfirstlaneselect from the same ballot predicate on two different paths. This is the precondition the descriptor web needs before those reads can be split into arms; those shaders still stop at aPhiinside the arm, which is a separate gap.Tested
verifyWaterfallRuntimeValues(registered asagc_shader_srt_read_patching): a mask whose conjunct is a structural copy of the select condition is accepted, and the negation of that condition is still refused. The first case fails onmainwithwaterfall: a mask whose conjunct is a structural copy of the select condition was rejectedand passes with the change; the second one passes on both.agc_shader_memory_tests(every internal case) withANYPS5_NO_SHADER_CACHE=1: passes onmainand with the change.agc_shader_srt_read_patching,agc_shader_descriptor_phis,agc_driver_descriptor_web_faultsandagc_driver_buffer_descriptor_runtimewithANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer: 4/4 pass on both, fourInsert instance layer "VK_LAYER_KHRONOS_validation"lines, noVUID-and nowas not found but was requested by env var.check_conventionsclean;pr_overlap --names ActiveMaskImpliesshows no other branch declaring it.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)Imported from boykopovar/AnyPS5. Originally posted by mattiolocoding on 2026-11-17T21:26:49Z.
Review: COMMENTED
Code Review: PR #21758 (commit
0c926efb7497d05f82616952a491215da26e1b83)Summary of Changes
ActiveMaskImpliesStructural Equivalence: ExtendedActiveMaskImpliesto takeconst IrResourcePlan& programand evaluateEquivalentValue(program, mask, condition)when direct pointer equality fails.programacrossResourceTracker.cpp,SrtEvaluator.cpp,SrtRuntimeValidator.cpp, andSrtTape.cpp. Converted helper routines (MatchAffineOffset,ExtractBaseRegister,ExtractDwordKey) toTrackerconstmember methods to provide access tom_program.ShaderDiskCache::FormatVersionfrom 88 to 89 to avoid stale deserialization.verifyWaterfallRuntimeValues(ShaderMemory.cpp), verifying both acceptance of structural copies and rejection of negated conditions.Verification & Analysis
python tools/check_conventions.py --base upstream/mainpassed cleanly with 0 violations.python tools/pr_overlap.py --repo boykopovar/AnyPS5 --names ActiveMaskImpliesverified against all 1,760 open pull requests: 0 overlaps (main: not declared,open: none).v_readfirstlane, distinct IR value pointers often represent identical Boolean logic. CheckingEquivalentValueresolves these cases without weakening safety guarantees.equivalentValueImplinIrProgram.cppemploys a dedicatedVisitedPairsmemoization set.A \land B \implies CwheneverA \implies CorB \implies C.ShaderDiskCache::FormatVersionto the next sequential integer.The implementation is clean, precise, and meets all repository standards.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T01:22:25Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed change uses value equivalence to recognize structurally copied mask conditions, and the inspected call sites consistently pass the resource plan needed for that comparison.
What I ran
Reviewed head
0c926efb7497d05f82616952a491215da26e1b83from the prepared diff and repository reader. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Did not read the full changed
ShaderMemory.cppbecause it was excluded from the review folder as too large; inspected its changed hunk in the diff only. Did not inspect the fullResourceTracker.cpp,SrtEvaluator.cpp, orSrtTape.cpp; only relevant ranges were read. No tests were run. Author-reported evidence and GPU behavior were not independently verified.Files read:
description.md,commits.md,manifest.json,diff.patch; full changed text forSrtInstructionPredicates.hppand targeted code ranges fromSrtInstructionPredicates.cpp,SrtEvaluator.cpp,SrtRuntimeValidator.cpp, andSrtTape.cpp. Excluded from full-text bundle:ShaderMemory.cpp(too large). Other changed files were not read in full.To get this to a good state
Nothing is required.