Repository navigation
fix(shader): keep every lane in a stencil export replay when the device can store through an address - #18530
Conversation
…ce can store through an address Without VK_EXT_shader_stencil_export a pixel shader that exports a stencil reference runs once per reference value, and the hardware stencil test can skip pixels before the shader, so a wave branch or lane read sees other lanes than the guest does. Replay shaders now end in a store through a device address that never runs, so the driver must run them on every covered pixel. The replay then accepts shaders whose only fault was their lane masks.
|
Windows check of head Tests:
AI-assisted: yes. |
|
Thank you for the Windows run. It adds a second vendor and a second driver (AMD RX 6700 XT, 26.10.1) to the NVIDIA result. I added it to the PR text and to the debt entry (head |
|
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.
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.
|
|
@Capmare a run of head Setup: Linux 7.3, Ryzen 9 5950X, RTX 3080 Ti (
0x11d01d0900 offline, from a request logged on this card when
Not checked: the game (on this card the title doesn't reach this draw) and the full AI-assisted. |
|
@mrfelek your notes in section 3 of
Could you test this branch on the 3080 Ti with |
|
@Capmare the Arms: A = Setup: PPSA03671 01.001.005, Linux 7.3, Ryzen 9 5950X, RTX 3080 Ti (NVIDIA 615.71.09), headless, no input, fresh shader cache,
Not checked: the picture, and anything past that draw. AI-assisted. |
Validation run (queue item 56) — PR #18530Verdict: PASS — focused shader-recompiler/stencil/lane/spirv tests green on base and PR head, no new Vulkan validation IDs, validation layer confirmed inserted on both runs. Pushed to fork as Environment
Build
Focused tests
Vulkan validation-layer checks (per AGENTS.md)
Push
Limitations
|
|
@blawesom thank you for the Linux run on the RX 9070 XT. I added it to the debt entry and the PR body. The failed |
|
NVIDIA Linux run with the Khronos validation layer of the current head Setup: Arch Linux, kernel 7.3.4, GCC 16.2.1 Release, NVIDIA GeForce RTX 4090 (10de:2684), driver 620.70.06, Vulkan 1.4.357, Khronos validation layer 1.4.363.1. Head
The skipped test is No new AI-assisted: yes (Claude Code) |
# Conflicts: # core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp # core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hpp # core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp # core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cpp
|
@mrfelek @domx4q thank you for the runs on the RTX 3080 Ti and the RTX 4090. I added both to the PR text and to the debt entry (head @mrfelek your game run shows the title passes |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
- Head SHA: 25b10fc (base: main).
- Read the PR description, commit list, manifest, and the full diff (11 files).
- Read one range at head with the reader:
core/libs/prx/libSceAgcDriver/tests/execution/StencilReplay.cpplines 84–135. - No build and no tests were run in this review.
Results
| Check | Result | Note |
|---|---|---|
| Diff read | passed | 11 of 11 changed files, as diff hunks |
| Description vs code | passed | Lane-set relaxation, store and capabilities match the diff |
| Build and tests | not run | Author-reported runs only |
| Callers at head | not run | Only one test range read |
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/tests/execution/StencilReplay.cpp:239:storeDeviceholdsStencilReplayLanesFixed(...), not a store decision. The final check at line 249 compares store presence with that flag, which only holds if the wave-branch shader fails the strict proof. Renaming the variable tolanesFixedwould make that dependency visible.core/libs/prx/libSceAgcDriver/tests/execution/StencilReplay.cpp:134:LastReplayStoredis set by anyOpConvertUToPtrin the replay module, not only by the reference store. Another device-address conversion would set it too. Matching the exact store sequence would make the check precise.core/shader/recompiler/Recompiler.cpp:909:StencilReplaySafeandStencilReplayNeedsStorerun the strict analysis again for each replay shader, andDefineOutputsrepeats it. The cost is small, but the result could be computed once and passed along.
Not verified
- Results on NVIDIA, Intel and llvmpipe are the author's; I did not build or run them.
- The guard assumes the host writes the reference as 255 or less. The writer is not in the diff, so this is not verified.
- The claim that
fragmentStoresAndAtomicsis always required and enabled is not in the diff and was not checked. - The claim that the shader cache key holds the capability list was not checked.
- Callers of
StencilReplaySafeoutside the changed files were not read. - The driver behaviour the change relies on (side-effect shaders run on every covered pixel) cannot be checked from the code here; the debt entry says so.
Sources
- Repository paths are at head 25b10fc; line numbers refer to that commit.
To get this to a good state
Nothing is required. The non-blocking points above are optional.
What
On a device without
VK_EXT_shader_stencil_export(NVIDIA), a pixel shader that exports a stencil reference runs once per reference value, and the hardware stencil test of each pass can skip pixels before the shader runs. A wave branch or a lane read in the shader then sees other lanes than the guest does.StencilReplaySafetherefore refuses every shader whose exec-mask control it cannot prove independent of the lane set, and the draw aborts withstencil reference export emulation requires a replay-safe pixel shader with late tests.Marvel's Wolverine (PPSA03671) stops on this: shader
0x11d01d0900is a 208-word pass that loads a texel, remaps it through constant tables, divides by a uniform value and exports depth and stencil. Itss_cbranch_execzafter av_cmpxon the loaded value splits it into two return paths, and the analysis only accepts a body that rejoins a merge block.The Vulkan spec lets a driver run a fragment shader on fewer pixels than the guest only when the shader has no side effects. A replay shader that the lane-set proof cannot clear now ends in a store through a device address behind a condition that is always false (the reference is at most 255, and the guard reads it from a push constant, so the driver cannot fold it). The driver has to run that shader on every covered pixel in every pass, as the guest does. A shader that the proof already clears gets no store and keeps the early tests, so no shader that works today gets slower. With the lane set fixed,
StencilReplaySafeno longer needs the lane-mask proof or the ban on lane reads. Shader clock reads, loops, memory writes, shared memory and the other earlier checks stay. A device withoutPhysicalStorageBufferAddressesorInt64keeps the earlier analysis. A device that exposes the extension (Intel and llvmpipe here) exports the stencil natively and is not affected.The change:
StencilReplay.cpp:StencilReplaySafe(program, lanesFixed),StencilReplayLanesFixed(capabilities)andStencilReplayNeedsStore(program, capabilities).SpirvFlowEmitter.cppandSpirvModuleSetup.cpp: the store and the address capability for replay modules.ShaderValidation.cpp: the capability andSPV_KHR_physical_storage_bufferare allowed for a replay fragment shader.docs/dev/debt/shader.md: the entry says the guarantee is measured on one driver only.Tested
Rocky Linux 10.2, i7-14700K, RTX 4070 SUPER, NVIDIA 620.70.06, Release.
maina26b782 and this branch, same machine. Tests were run asANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -V -R '^agc_driver|shader_recompiler'.mainThe 18 failing tests are the same set on both sides:
agc_driver_division,agc_driver_f32_denormal_flush,agc_driver_image_table,agc_driver_image_table_packed*(11),agc_driver_mesh_vector_window_writesandagc_driver_mullit_f32_denormal_modes. Their logs carry the sameVUID-counts on both sides, and neither log containswas not found but was requested by env var VK_INSTANCE_LAYERSapart from ctest echoing its regex:New case in
agc_driver_stencil_replay: a pixel shader (assembled for gfx1030, wave64) whose branch tests whether any lane has an odd column. Even columns export 255 on one path and 254 on the other, and the stencil buffer holds 255 under even and 0 under odd columns. In the guest every wave holds both kinds of column, so every pixel is drawn.pixel (0, 0) is 64, expected drawn. The hardware skips the odd columns in the pass for 255, the branch flips and the even columns export 254.main, the shader is refused withstencil reference export emulation requires a replay-safe pixel shader with late tests.agc_driver_stencil_replayalso passes under the same validation settings on Intel RPL-S and llvmpipe (Mesa 25.2.7, selected withVK_DRIVER_FILES). Both export the stencil natively, so they do not run the replay.Marvel's Wolverine: I replayed the dumped request of
0x11d01d0900through the recompiler offline (the dump lacks one descriptor, which I supplied). It aborts onmainand recompiles on this branch (5157 SPIR-V words). I have not drawn it in the game, because the run stalls on texture memory before it reaches this draw (see #12575).The guarantee rests on the driver following the spec for shaders with side effects (chapter Fragment Operations, section Fragment Shading). The spec does not fix how the driver groups pixels into waves, so the replay assumes that every pass groups them the same way. I measured it on NVIDIA (RTX 4070 SUPER) and, through runs by mrfelek and domx4q, on an RTX 3080 Ti and an RTX 4090. JJenkx and blawesom ran it on AMD (RX 6700 XT, driver 26.10.1, Windows; RX 9070 XT with RADV, Linux). The debt entry says so.
fragmentStoresAndAtomicsis always required and enabled, the shader cache key already holds the capability list, andagc_driver_stencil_replaylogs no new VUID.tools/pr_overlap.pyfailed closed, so I searched the diffs of the 39 PRs it lists for the replay code. #10351 (stencil operation values through an attachment) changesSelectStencilExportModeandSpirvEmitterHelpers.cpparound the same lines, and #7689 changes one condition ofStencilReplaySafe. Neither adds the lane guarantee. #18322 admits first-lane reads of wave-uniform values on every device and complements this change, which also covers non-uniform lane reads and wave branches but needsPhysicalStorageBufferAddressesandInt64. #16571 only touches a neighbouring debt entry indocs/dev/debt/shader.md. I will rebase on whichever lands first.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)agc_driver_stencil_replayonly)