perf(agc): replay an unbounded replace stencil export as one pass per bit #24802
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24802"
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 Capmare on 2026-11-21T03:30:33Z.
What
On a device without
VK_EXT_shader_stencil_export(NVIDIA), the stencil replay draws a pixel shader that exports a stencil value once per possible reference value. When the prover cannot bound the export, the replay records all 256 values, one pass per value per triangle and instance.Such a draw can write the stencil with compare
ALWAYSand passREPLACE. For such a draw, the value that the shader exports goes directly into the written stencil bits. So the replay can build that value bit by bit:A draw that writes 8 stencil bits records 10 passes per triangle and instance, not 256. The replay uses the bit passes only when both faces compare
ALWAYS, passREPLACEand keep the value on a depth failure (or the depth test is off), and when that gives fewer passes. The passes change depth, color and stencil write masks through dynamic state, so the draw needs graphics pipeline libraries, and dynamic color write masks when it writes color. Other draws keep one pass per value.The change:
Draw.cpp:StencilReplayPassesselects the passes;recordStencilReplayrecords them and sets the masks of each pass.Pipeline.cpp,Pipeline.hpp:MasksStencilReplayPassesandSetStencilReplayMasks.SpirvFlowEmitter.cpp: the replay compares the bits that the pass word names. The high byte of the word lists the bits to ignore; a word of only low bits compares all 8 bits as before.fix-stencil-replay-multisample.md: the debt entry describes the bit passes. It also records the triangle strip replay of #24379, which that PR did not put in the entry.Marvel's Wolverine (PPSA03671) has such a draw: shader
0x11d01d0900exports an unbounded value with compareALWAYSand passREPLACEon both faces and writes all 8 bits (STENCIL-BITS bitwise=1 values=256 bits=ff). With this change it records 10 passes per triangle in place of 256. I did not measure the frame time of that scene.Tested
Rocky Linux 10.2, i7-14700K, RTX 4070 SUPER, NVIDIA 620.70.06, Release.
main2ab4b094c9and this branch, same machine. Tests were run asVK_ADD_LAYER_PATH=<layer build> ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -V -R '^agc_driver_stencil'.mainagc_driver_stencil_ref_exportskipped)agc_driver_stencil_ref_exportskipped)agc_driver_stencil_ref_exportskips on NVIDIA on both sides, because the device has noVK_EXT_shader_stencil_export. The layer is Vulkan-ValidationLayersvulkan-sdk-1.4.335.0, built from source and added withVK_ADD_LAYER_PATH. Both logs show the loader inserting the layer 13 times from that build, neither containswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither contains aVUID-line. (With the installed 1.4.328 layer, both sides logged the same set:VUID-VkDeviceCreateInfo-pNext-pNextand threeVUID-VkShaderModuleCreateInfo-pCode-*IDs, 26 and 52 times each.)New cases in
agc_driver_stencil_replay, for an export the prover cannot bound, written with compareALWAYSand passREPLACE:agc_driver_stencil_replay_no_gpl).Negative control: with
Draw.cppfrommainand the new test,agc_driver_stencil_replayfails withan unbounded replace export recorded 256 passes.tools/pr_overlap.pyfailed closed. Two open PRs change the same debt entry,Draw.cppandStencilReplay.cpp: #24572 (stencil replay of indirect draws) and #24735 (depth feedback check against buffer descriptors). Neither changes the number of passes. The PR that lands second needs a rebase of the debt sentence; I will rebase if this one is second.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 MarcZX10 on 2026-11-21T03:55:22Z.
Review: APPROVED
Reviewed — looks good
The bitwise stencil replay path and its fallback are supported by the inspected implementation and added execution cases; no blocking defect was verified.
What I ran
Reviewed head
06a9ffc687ce9c2217b22d6fbe8547fd9b92cf6fusing the prepared review bundle andrepo_read.pyat the pinned head. I did not run commands or tests; the test results below are author-reported.Results
mainFindings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run independently, and console behavior or frame-time impact was not measured. The author reports tests on Rocky Linux 10.2 with an RTX 4070 SUPER and NVIDIA 620.70.06; this review did not verify those results. No changed files were excluded:
Pipeline.hpp,Draw.cpp,Pipeline.cpp,StencilReplay.cpp,SpirvFlowEmitter.cpp, andfix-stencil-replay-multisample.mdwere read.To get this to a good state
Nothing is required.