feat(agc): replay proven finite stencil reference exports #5466
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5466"
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 fdfawef324 on 2026-10-13T20:27:54Z.
What
Replay finite stencil reference exports on devices without
VK_EXT_shader_stencil_export, for a conservative subset of shaders and draws whose equivalence can be proved. This PR establishes synthetic replay cases; it does not establish advancement in Demon's Souls. The title's quad DPP and ballot-based kill early-outs remain refused.The recompiler proves complete export coverage and at most 16 eight-bit references, and reserves a bounded word in the existing push block. The driver keeps one Vulkan pipeline bound throughout each original draw and preserves instance, primitive and reference order. Both faces retain their stencil operations and masks, including depth-fail replacement. Multiple-reference replay admits direct triangle lists and preserves indexed offsets, base vertex and first instance.
Replay requires deterministic, read-only stages and no attachment feedback. Unsupported topology, indirect/restart draws, multisampling, early/ordered tests, incomplete coverage, unbounded references, side effects and surviving subgroup/helper dependence throw. Guarded read-only SRT faults are checked synchronously before host copyback. The native extension path is retained.
This revision separates the vertex lane-bound fold into #5914 and the empty-image feedback check into dependent #5917.
GuardImpliesand masked-export coverage helpers remain here because they prove the pixel export coverage needed for replay; the separate vertex optimizer is absent from this diff. Current-main vertex input layouts, sample-location grids and per-sample shading are retained.The artifact schema uses format 34 and updates
docs/dev/ARCHITECTURE.md. It rejects formats 31/32/33 and preserves current main's image-table invocation metadata and mapped persistent-cache tests. Merged #758 uses format 33; #5734 also touches this cache. Format 34 keeps the replay schema distinct. The feedback scan now also checks sampled ImageTable entries using main's validated eight-word image elements.Tested
e34c47921; original authors, author dates and full commit messages are preserved. Conventions and diff checks pass.g++ -O3 -fsyntax-onlychecks pass for Recompiler, the full ShaderDiskCache test, Draw, Pipeline, State and the native replay fixture. The fixture now copies the immutable SPIR-V span into a vector before mutation.APS5_NO_GPL=1, without skips: overlapping primitives/instances, indexed offsets/base vertex, first instance, distinct face operations/masks, truncation, depth-fail replacement, fragment kills, adjacent push data and valid/poisoned SRT handling. These results predate this rebase. This current public head has no fresh native GPU or title run; that validation remains pending. Integration character-creation/FPS results are not evidence for this public head.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryCo-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-14T01:17:23Z.
Intel run for this PR: Intel UHD Graphics 770 (Raptor Lake iGPU of an i9-13900K), driver 32.0.101.6129, Windows 11, MinGW-w64 GCC 15.2.0 Release, device picked with
ANYPS5_GPU=Intel, at head63368e11e.agc_driver_stencil_replayandagc_driver_stencil_replay_no_gplpass, as doagc_masked_selectandagc_driver_graphics.ctest -R "agc_driver|agc_masked|agc_shader" -j4: no failures out of 390 (362 pass, 28 skipped). These are the same 28 skips asmainhas on this GPU (f64, 64-bit and float atomics, fp16 interpolation and dot, mesh, shader clock and the like, which it does not support), and no new ones.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T01:57:05Z.
Thanks for testing head 63368e11e. I have recorded the Intel UHD 770 result separately from the local RTX 3060 matrix: both stencil pipeline modes and the masked-select/graphics checks passed, with 362 passes and the same 28 main-branch skips in the broader selection. The current rebase also needs compatibility checks for the disk resource-plan format that merged into main; those CPU results will be reported separately. A further vertex-mask case is being verified and is not covered by the tested head.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-14T01:58:12Z.
Demon's Souls (PPSA01341 v1.07) on Linux, RTX 5070 Ti, NVIDIA 595.91 (no
VK_EXT_shader_stencil_export), tested at c7595e9fb. The setup and the per-build table are on #4276: https://github.com/boykopovar/AnyPS5/issues/4276 . The title stops on this PR's refusalstencil reference export emulation requires a replay-safe pixel shader with late tests. The pixel shader is 788 words. It is refused at four addresses: 0x24abb6d00 and 0x24ab57200 are byte-identical, and 0x24ab5a100 and 0x24ab6dc00 stop the same way, so they are most likely the same code, and the draw that matters writes the reference through write mask 0x80. Tests are late: the driver clears early Z when stencil export is on.With your three #758 adaptations applied (the first removes a separate blocker, #758's EXEC operand on
ImageSampleRaw),StencilReplaySafestill rejects the shader for two reasons. Line numbers are at 63368e11e.agc_shader_replayon the captured request reproduces both offline, and the in-game logs report the same reasons.StencilReplay.cpp:702,DppMoveU32/DppUpdateU32). The shader computes coarse derivatives by hand with DPPquad_perm:v_mov_b32withquad_perm [0,0,0,0]at 0x234, 0x23c, 0x40c and 0x414, andv_sub_f32withquad_perm [1,1,1,1]/[2,2,2,2]at 0x260-0x278 and 0x438-0x450. All use row_mask 0xf, bank_mask 0xf and bound_ctrl 1, so these are quad-local reads.control()(called atStencilReplay.cpp:110). It rejects six conditional branches, all kill early-outs:s_andn2_b64 s[20:21], s[20:21], vccthens_cbranch_scc0. The IR condition isany()of the ballot mask, whichguaranteed()can't prove. The kill exit is exec 0,exp null,s_endpgm. The main exit exports MRTZ with stencil 0 or 255.With both rules bypassed locally, the shader recompiles (66435 SPIR-V words). The title then stops at t+513, still in the level load, on another limit:
stencil replay requires an unused push constant dword(BindingAllocator.cpp:120), shader 0x24ac2cb00, whose push data already fills the push block. The bypass is a local experiment only.The captured request holds the game's shader binary and captured guest memory, so I can't attach it. I can run a build or log specific values on request.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:42:30Z.
Review: CHANGES_REQUESTED
Reviewed at 47290fbea, merged onto current
main(9a3e2ac4d).core/libs/prx/libSceAgcDriver/tests/execution/StencilReplay.cpp:109-142.RecompileResult::spirv.Words()now returnsstd::span<const std::uint32_t>(87911b3bb), somodule.insert(...),module[3] = idandresult.spirv = std::move(module)don't compile. Copy the words into astd::vectorfirst.agc_driver_stencil_replay*never ran here because of this; please rebase on currentmainand rerun the PR's tests.stencil reference export emulation requires a replay-safe pixel shader with late tests, becauseStencilReplaySaferejects the title's shader (DPPquad_permmoves/subs, and sixany()-of-ballot kill branches thatcontrol()can't prove). Either handle those two patterns with proof (quad-local DPP with full row/bank masks; kill early-outs whose exit exports nothing) or reword the title and "Unblocks" so they don't claim the title advances. The character-creation result in the body includes private changes that aren't in this PR.MaskedSelectEliminator/ConstantFolder), the null-image feedback fix and a disk-cache format bump. Please split the vertex fold and the null-image fix into their own PRs (each with its own test) and keep this one to the replay.ShaderDiskCache.cpplines 92-93. Please coordinate the number and list the PRs under Depends on; updatedocs/dev/ARCHITECTURE.mdwhere the cache format is described.I haven't measured anything on the HW oracle (stencil export is driver/pipeline behaviour, not an ISA op). Happy to re-review once the test builds and the scope is split.
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T15:37:28Z.
Rebased to current main
84b01f9cdat head821c8d7b5and repaired the span mutation in the native fixture. Fresh matching-current-header whole Recompiler/cache test/Draw/Pipeline/State/native-fixture syntax checks pass with-O3; fresh actual replay IR tests pass, with the frozen selective failure controls matching the compiler-resolved current inputs after only CRLF normalization.The vertex lane-bound optimizer is now separate in #5914; the empty-image feedback fix is separate in dependent #5917. The replay PR's final diff contains neither follow-up.
GuardImpliesand masked-export coverage remain because they are the proof for complete pixel stencil export coverage.The body now explicitly limits Unblocks to synthetic cases. It makes no Demon's Souls advancement claim and records the remaining DPP/kill-branch refusal. Format 34 and ARCHITECTURE are updated; #758 and #5734 are listed for schema coordination. Please reserve a distinct compatible number between these changes.
Fresh current-public-head native GPU runs are still pending. The tested section distinguishes the current CPU checks from historical GPU/integration results; #5914 and #5917 are draft while native validation is pending.
AI-assisted: yes
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T20:17:08Z.
Review: APPROVED
Re-checked at 436fc35e3: the build error, the title/"Unblocks" claim and the topic split are fixed, thanks.
Since your base,
dd8f2eb8aalso moved the shader disk cache to format 34 (with a different layout), so both would have loaded each other's entries. I rebased onto currentmain, resolved thedocs/dev/ARCHITECTURE.mdconflict, and moved the stencil artifacts to format 35 (ShaderDiskCache.hpp, ARCHITECTURE.md now says entries from formats 31 to 34 are rejected; the existing previous-version test covers 34).Checked on the rebased tree: build,
agc_driver_stencil_replay,agc_driver_stencil_replay_no_gpl,agc_shader_disk_cache,agc_masked_select,agc_driver_graphicspass; the PR's tests don't build without the code change. The only failing test in the area,agc_driver_tessellation, segfaults inside RADV on plainmaintoo. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T20:22:06Z.
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.
main)docs/dev/debt/libSceAgcDriver.mdL81core/shader/recompiler/ShaderDiskCache.cppL93-94core/shader/recompiler/ShaderDiskCache.hppL16