Repository navigation
fix(shader): export valid-mask colors without branching on EXEC - #14341
oneandonlydean merged 8 commits into
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The unconditional store is sound on the paths I read: a lane with a clear valid mask is killed at every return unless it is a helper invocation, so its stored value is discarded. One non-blocking question remains about helper invocations.
What I ran
Reviewed head 25eb2a4c36d8d62f6567161fc0e7f0842c256824 against base 26fa1212b82f76dd49cf12d65e445d6ff3e0844c; the precheck merge preview is clean. Environment: Linux x86-64, Python 3.11. I read the full diff and the emitter paths listed under Sources at this head. No local build or shader test was run.
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14341
python3 -I tools/pr_abi_audit.py --repo /marc/AnyPS5 --base 26fa1212b82f76dd49cf12d65e445d6ff3e0844c --head 25eb2a4c36d8d62f6567161fc0e7f0842c256824 --json
python3 -I tools/pr_test_quality.py --root <git archive of 25eb2a4c36: core/libs, core/shader, docs/dev/debt> --json core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
The precheck's ABI and test-quality helpers were missing from the PR head tree, so I ran both by hand from the main checkout.
Results
| Check | Result |
|---|---|
git diff --check, conventions and PR template (precheck) |
Passed |
| Live dependency and mergeability (precheck) | Passed |
| ABI audit (by hand) | Not applicable: no export declaration changed |
| Test quality (by hand) | One possible-unregistered-cpp-test finding for core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp; false positive, the file is registered in core/libs/prx/libSceAgcDriver/tests/cmake/agc_shader_memory_tests.cmake |
| Build and the AGC shader tests | Not run (no-build protocol) |
conventions_and_pr_template, unedited precheck output
All conventions checks passed.
Findings
Blocking
None found.
Non-blocking
- Helper invocations.
EmitKillIfPixelValidMaskInactivekeeps a helper invocation alive even when its valid mask is clear (SpirvFlowEmitter.cpp#L30-L45). Such a lane now executes the unconditional store, where the EXEC branch previously skipped it. Please state why a value written by a helper lane is not observable on the target, or cover that case in the GPU evidence. This is a question, not a request for a change.
Sources
- Valid mask starts at 1 and is cleared to 0 for an inactive
vmexport: SpirvModuleEmitter.cpp#L1840-L1841, #L2164-L2167. - Kill of lanes with a clear mask at return, and the empty-block path: SpirvFlowEmitter.cpp#L97, SpirvModuleEmitter.cpp#L1921-L1933.
- Scope of the unconditional store (pixel MRT,
vm, no color merge): SpirvModuleEmitter.cpp#L2271-L2273. - Test registration: agc_shader_memory_tests.cmake.
Not verified
- The GPU results in the PR (Radeon 860M and RTX 5060 Ti) are author-reported; I did not reproduce them.
- The build, the AGC shader tests, and the hosted Windows, macOS and relinker jobs (queued or running at review time).
- The helper-invocation question above.
|
The terminal valid-mask export case makes sense, but the new condition also removes EXEC guarding from a nonterminal VM color export. A later VM export can make that lane valid again. AMD’s RDNA ISA, section 11.2.1, says that EXEC gates each export’s data write, exports accumulate, and the final VM export supplies the valid mask: https://docs.amd.com/api/khub/documents/mU0vhV4IgdmIWSgRqlt70g/content For one lane, with no color merge:
The final mask keeps the lane, but step 2 must not replace its red output. On Could you restrict this optimization to exports proven safe with respect to the final valid mask, or preserve inactive lanes’ previous output without divergent control flow, and add this repeated-VM/NULL-reactivation regression? Please retain the implicit-LOD fix and the EXEC guard for color-merge writes. The new structural test checks only one quad mask and a terminal export, so it cannot catch this sequence. This finding comes from the exact source and an ISA schedule model; I have not executed this sequence through the C++ emitter or on a GPU. |
|
Thanks, both. oneandonlydean: you're right, the first version broke that schedule. Changed in
MarcZX10: a helper's store to an Results for AI-assisted: yes (Claude Code) |
|
Another data point: this also clears the remaining failure of AI-assisted: yes (Claude Code) |
|
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.
|
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validation IDs already present on main (5 IDs in 484 tests)Skipped (45)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
Tested on Windows with two more GPUs: the fix clears the failure on an RTX 5070 Ti, and the integrated Radeon of a Ryzen 7 7700X passes before and after.
For #14237: unlike the Radeon 860M, this RDNA 2 iGPU on AMD's Windows driver samples level 2 on AI-assisted: yes (Claude Code) |
CnRJay
left a comment
There was a problem hiding this comment.
The diagnosis is clear: sinking the sample into the EXEC branch is what breaks the derivatives, and the table of hand-edited modules shows it. The fix is wider than the bug, though, and the PR carries no cost figure for that.
1. It applies to every pixel shader, not only to the shaders that hit the bug. preserveInactive is stage == Pixel && kind == Mrt && no merge for the target. Nothing in it looks at vm, a quad mask, or an implicit-LOD sample. So every ordinary pixel export in every title now gets a Private shadow variable, an OpLoad of it, a 4-wide OpCompositeConstruct of EXEC, an OpSelect, and two stores, where before it had one branch. In the common case (EXEC set for the whole shader, a single export) a driver compiler can usually fold the select away, but only if it can prove EXEC is uniform. The shader here reads EXEC as a runtime value, so on a shader that does s_mov exec or wave-mask work before the export the compiler keeps 4 v_cndmask per export per target and an extra live range. With 8 MRTs that is 32 selects per pixel. The new agc_shader_quad_mask_no_demote test counts nesting, not instructions, so it does not show either.
Please restrict preserveInactive to the cases that need it: a program with a quad mask or demote, an export with vm, or a program that samples with implicit LOD after an EXEC change. Everything else keeps the branch it has on main. If you want it unconditional, show the cost.
2. The SPIR-V and pipeline compile-time cost is not measured. The description tests correctness on four GPUs and runs the full suite, but gives no figure for SPIR-V size or pixel-stage compile time. A before/after of spirv-dis | wc -l and Driver.Draw.prepare ms per frame on one pixel-heavy scene would settle it. Pipeline compile time matters on a cold cache, where every pixel variant is compiled at the first draw.
3. Uninitialized shadow. The first export reads the Private shadow before any store. That is undefined, so a lane with EXEC clear on the first export gets an undefined color, where main's branch left the output undefined as well. Fine for correctness, but state that the previous value is only meaningful after a store, and consider an OpConstantNull initializer so drivers can fold the first select when EXEC is a known constant.
81b3d01 to
20acd94
Compare
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validation IDs already present on main (5 IDs in 484 tests)Skipped (45)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
Thanks, @CnRJay. Changed in
The structural test now uses a pixel program with a live cross-lane read ( On the RTX 5060 Ti, full AI-assisted: yes (Claude Code) |
|
Radeon 860M (AMD 32.0.13058.8001, Windows 11) on AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings; the valid-mask export path has no hosted run of its execution test
This PR changes how the SPIR-V emitter writes pixel exports when the shader reads helper lanes. Inactive lanes now keep their previous value through a private shadow variable, instead of branching on EXEC. The Windows run passed three shader cases, but the execution test for this path, QuadPixelMask.cpp, is a stub on Windows and did not run. I read the production change in full.
What I ran
- Head
20acd940ce94896ade451a0dc142e28c9244ecc3; base5bae1a4bc2cffc66c13e37ce8e63ae48b1b5dd1e. 4 files, +68/-3:SpirvBackend/src/SpirvModuleEmitter.cpp(+35/-, the export path),SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp(+1),libSceAgcDriver/tests/ShaderMemory.cpp(+28), andlibSceAgcDriver/tests/execution/QuadPixelMask.cpp(+7). - Read the
SpirvModuleEmitter.cppchange in full. When a pixel MRT export is not merged and the shader reads neighbour lanes or non-barycentric inputs, the export writes through a privateSelectbetween the new value (active lanes) and the previous value (inactive lanes). The shadow variable is added to the interface list only for SPIR-V 1.4 and later. Otherwise the code keeps the originalEXECbranch. - Read the
ShaderMemory.cppadditions by their names only, andQuadPixelMask.cppby its names only. - Hosted, Windows CTest: 21 of 21 passed.
agc_shader_quad_mask_no_demote(Test #1909),agc_shader_result_memo_budget_masked(Test #1913),agc_shader_table_snapshot_reuse_unmasked(Test #1904) andagc_shader_memory(Test #1917) passed. TheQuadPixelMaskexecution test does not appear in the run; on Windows it is a stub unless it is listed inANYPS5_AGC_EXECUTION_TESTS, and it is not. - Read-only checks from the trusted main checkout: diff check and conventions passed. ABI audit not applicable. Stack check: clean, no declared dependencies, no errors.
- No MarcZX10 review at this head.
Results
| Check | Result | Note |
|---|---|---|
| Diff check | passed | |
| Conventions and PR template | passed | conventions check from the main checkout |
| Mergeability and dependencies | passed | stack check: clean; no declared dependencies |
| ABI audit | not applicable | no export changed |
| Four shader cases (hosted, Windows) | passed | Test #1904, #1909, #1913, #1917 |
QuadPixelMask execution test (the changed path) |
not verified | an execution stub on Windows; no case in the run |
Export path in SpirvModuleEmitter.cpp (read) |
passed by reading | the shadow-variable path is as described; no blocking defect found |
| Behaviour on hardware and the SPIR-V validator | not verified | not run here |
| Negative controls | not run | no local build |
Read-only check output
Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: clean, no declared dependencies, no errors. Hosted: gh api repos/boykopovar/AnyPS5/commits/20acd940ce94896ade451a0dc142e28c9244ecc3/check-runs, and the Windows job log (21 of 21).
Negative control
Not run here. A negative control needs a local build and run of the execution test, and code from this head is not run here.
Findings
Blocking
None from the code read.
Non-blocking
- The execution test that covers the new path (
QuadPixelMask) did not run on Windows. The hosted shader cases that passed do not exercise the valid-mask export on a helper-lane shader. A run ofQuadPixelMaskon a host that builds the execution tests would close that gap. - The shadow variable is a private global that is written on every masked export. Its cost on large shaders was not measured.
Sources
- Export path: https://github.com/boykopovar/AnyPS5/blob/20acd940ce94896ade451a0dc142e28c9244ecc3/core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
- Execution test: https://github.com/boykopovar/AnyPS5/blob/20acd940ce94896ade451a0dc142e28c9244ecc3/core/libs/prx/libSceAgcDriver/tests/execution/QuadPixelMask.cpp
- Shader memory test: https://github.com/boykopovar/AnyPS5/blob/20acd940ce94896ade451a0dc142e28c9244ecc3/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
- Windows job log: check-run
windowson 20acd94
Not verified
- The
QuadPixelMaskexecution test (stub on Windows). - The new path's behaviour on hardware and under the SPIR-V validator.
- The bodies of the
ShaderMemory.cppadditions.
To get this to a good state
- Nothing blocking. Run
QuadPixelMaskat this head in hosted CI, or add it to the Windows execution list.
|
Windows check of exact head Setup: Windows 11 Enterprise 10.0.22621, Radeon RX 6700 XT, AMD proprietary driver 26.10.1, WinLibs GCC 15.2.0 UCRT r7, Release. Runs went through the shared GPU queue with
|
|
Thanks, @MarcZX10 and @JJenkx. On the execution test: the hosted Windows runners have no GPU, so
All of these ran with On cost: the shadow is one Private AI-assisted: yes (Claude Code) |
|
@LeandroLP23 on whether the narrowed head still covers #12277: on a Radeon 780M it doesn't. With #9503, Radeon 780M (RDNA 3 integrated), AMD 26.10.2 (32.0.32015.12012), Windows 11, WinLibs GCC 15.2.0 r7, Release.
So the AI-assisted: yes (Claude Code) |
✅ AMD GPU test: passedPR head
Unstable on main (3, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (7, not counted against this PR)Validation IDs already present on main (8 IDs in 549 tests)Skipped (60)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…instead of storing it unconditionally Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… copy Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…read no helper lanes and zero-initialize the shadow Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cross-lane read Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @sharveshprabhu, that was a bug in Fixed in On the RTX 5060 Ti (621.01), AI-assisted: yes (Claude Code) |
|
Windows AMD RX 7800 XT data point for exact head d35348b, merged alone into main b611e63 (local merge f3b4212671f09d1be425c879e5f5ce4700d76d72, clean tree). Windows x64 build 26300.9711, AMD driver 26.10.1 (LLPC), Vulkan 1.4.359, WinLibs GCC 15.2.0 UCRT, Release. agc_driver_quad_pixel_mask passed on both main and this head; agc_shader_quad_mask_no_demote also passed on this head. Logs selected AMD Radeon RX 7800 XT (1002:747e). This card passed the quad-mask test on main, so this is regression coverage rather than a reproduction of the reported failure. I ran ctest --test-dir R:/b-latest -V with ANYPS5_GPU=7800 XT, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. The layer loaded from Steam's CEF bundle. It uses older Vulkan headers and reports VUID-VkDeviceCreateInfo-pNext-pNext for unknown extension structs on both main and this head; no additional VUID ID appeared. That limits the validation conclusion. AI-assisted local test; no game or FPS claim. |
✅ AMD GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (7, not counted against this PR)Passed on retry (1, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)Validation IDs already present on main (4 IDs in 556 tests)Skipped (58)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
RX 7800 XT follow-up to the request to retest the narrowed head: I built three successive, clean local source trees with the same Release/WinLibs GCC 15.2 UCRT toolchain. The baseline is upstream
The #9503 arm's 42-color result also repeats with the validation layer disabled, so that residual is not introduced by this older layer. With both PRs, the other registered sample-order cases ( Validation limitation: the available layer comes from Steam CEF and uses Vulkan header version 284. It loads, but it reports AI-assisted local test; source, build and CTest logs are retained locally. |
|
Thanks @DonRyuzaki, that's the pairing I couldn't run: with #9503, AI-assisted: yes (Claude Code) |
|
@LeandroLP23 confirmed on the Radeon 780M: with #9503, Same setup as before (780M, AMD 26.10.2,
AI-assisted: yes (Claude Code) |
✅ NVIDIA GPU test: passedPR head
Unstable on main (2, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validation IDs already present on main (9 IDs in 556 tests)Skipped (55)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
…l programs A pixel program that reads helper lanes stores its MRT color outside the EXEC branch, so a lane with EXEC clear must store its previous color: a later valid-mask export can make the lane valid again, and it must then show the color it exported while active. The structural checks only looked at where the store is. Require that every color store of the offset-interpolating and neighbour-reading programs takes its value from a select between the new and the previous color. Co-authored-by: LeandroLP23 <92315992+LeandroLP23@users.noreply.github.com>
|
Hi @LeandroLP23, I pushed one small commit to your branch, Your change keeps an inactive lane's previous color in pixel programs that read helper lanes: the MRT store sits outside the EXEC branch and stores The commit adds a check next to yours: for the offset-interpolating program and the neighbour-reading program (masked and unmasked), every store to a color output must take its value from an |
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validation IDs already present on main (9 IDs in 594 tests)Skipped (56)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
Thanks, that's a gap I missed. The structural checks pinned where the store sits, not what it stores, so dropping the I read AI-assisted: yes (Claude Code) |
|
Radeon 860M (RDNA 3.5,
|
There was a problem hiding this comment.
A Windows NVIDIA run on a GPU where agc_driver_quad_pixel_mask already passes on main, to check that this change keeps it passing.
Setup: Windows 11 x64, NVIDIA laptop GPU (Turing), driver 610, WinLibs GCC 15.2.0 r7 UCRT, Release, every AGC execution test built. Head 608b3860c7 merged onto main 4e44ed59b2 (clean merge), with main 4e44ed59b2 from the same build directory as the control. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, Selected GPU was the NVIDIA GPU. No validation layer on this machine.
| Tree | agc_driver_quad_pixel_mask |
|---|---|
main 4e44ed59b2 |
10 of 10 |
| this PR | 10 of 10 |
No pixel (1, 0) channel 0 is 32, expected 96 on either side. This driver is older than 617.42, which #14237 reports as passing, so it does not reproduce the 621.x failure. It does show that this change does not regress Turing.
AI-assisted: yes.
|
Re-test of head
Red checks on the merge, 3 runs on each GPU:
Non-blocking note: the second row shows that the new check from Not run: the rest of the AGC suite, on either tree or with either red check. AI-assisted: yes |
What
On Windows,
agc_driver_quad_pixel_maskfails in the implicit-LOD case under a partial quad mask, on both AMD and NVIDIA (#14237). The pixel samples the wrong mip level: level 0 on an RTX 5060 Ti, levels 3 and 4 on a Radeon 860M, where level 2 is expected.The cause is not the demoted helpers. A pixel export with
vmset was stored insideif (exec) { ... }. The sampled value is only used inside that branch, so both Windows drivers move theOpImageSampleImplicitLodinto it, out of uniform control flow, and the derivatives lose the neighbouring lanes. I checked this by editing the generated SPIR-V by hand on both GPUs:OpDemoteToHelperInvocationremovedOpKills removedtrueThe fix keeps the EXEC semantics but drops the divergent control flow, only where it matters. A pixel program whose result depends on helper lanes either has
neighbourLaneReadsset (implicit-LOD samples,ImageQueryLod, DPP/swizzle/permute/readlane/ballot, WQM) or reads an offset barycentric (aGetBuiltinof a sample or centre barycentric kind), which goes throughInterpolateAtOffset. In such a program, an MRT export without a color merge now storesselect(exec, new, previous)unconditionally.previousis the last color the invocation stored to that output, kept in aPrivateshadow per output, zero-initialized withOpConstantNull, because the packed and reversed-order output specializations only accept whole stores to theOutputvariable. A lane with EXEC clear therefore keeps its earlier color, including when a latervmexport makes it valid again, and the helper-lane reads stay in uniform control flow. Every other pixel export keeps its EXEC branch as onmain, and so do targets with a color merge and the alpha-to-coverage store (in its own branch).New checks:
agc_driver_quad_pixel_maskalso runs the sequence from review: red to MRT 0 with EXEC set, then green to MRT 0 withvmand EXEC clear, then a NULLvm doneexport with EXEC set. It expects red. It passes onmain, fails on this PR's first version (52fcd28bba, which stored green), and passes now.agc_shader_quad_mask_no_demotechecks that the color store of a pixel program with a live cross-lane read (ds_permutewith EXEC left at the live lanes) is not nested in any selection or loop construct, with and without a quad mask. That check needs no GPU. It fails withmain's emitter and passes here.20acd940ce, whose check looked for the offset kinds in the program's input list, which records only the base barycentric.Tested
Windows 11, NVIDIA RTX 5060 Ti: full
ctest -j 6withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,main26fa1212b8against81b3d01f31.main: 2 of 3,265 failed,agc_driver_quad_pixel_maskandagc_driver_vulkan_test_device_no_driver(the elevated-loader case of test(agc): skip the no-driver device test where an elevated loader still opens a device #14069).agc_driver_vulkan_test_device_no_driverfailed.VUID-line.Windows 11, AMD Radeon 860M:
ctest -R '^(agc_|shader)'(1,217 tests) on81b3d01f31, same environment.agc_driver_quad_pixel_maskandagc_shader_quad_mask_no_demotepass.agc_driver_mesh,agc_driver_msaa_dcc_srgb_clear_2/4/8andagc_driver_sample_order_grid_reference. They fail the same way withmain'sSpirvModuleEmitter.cpp.VUID-lines, and the layer was loaded.Windows 11, NVIDIA RTX 5060 Ti (621.01), head
d35348be5eonmainb611e634f7:agc_driver_quad_pixel_maskandagc_shader_memorywith the same environment.main: the quad mask test fails; this PR: both pass. The layer was loaded and there are noVUID-lines.Independent runs:
d35348be5ewith fix(agc): bind the sample order depth set after its pipeline #9503 onmainc3a5290c7d:agc_driver_sample_order_grid_referencepasses 3 of 3 (0 color and 0 depth samples differ), where fix(agc): bind the sample order depth set after its pipeline #9503 alone leaves 42 color samples.agc_driver_quad_pixel_maskpasses onmainand on this head there.81b3d01f31: the RTX 5070 Ti (621.01) fails onmainand passes with this PR; the Ryzen 7 7700X iGPU (RDNA 2, AMD 24.30.18) passes on both. NoVUID-lines.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)