Repository navigation
fix(shader): declare FragStencilRefEXT unsigned so MoltenVK compiles it with the stencil output disabled - #19966
Conversation
…it with the stencil output disabled
|
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.
|
|
Windows check of head All 10 selected tests (
AI-assisted: yes. |
kurexw
left a comment
There was a problem hiding this comment.
Tested on macOS 27.2 / Apple M4 with MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1, validation layer 1.4.363), x86-64 build under Rosetta. This is the only GPU I tested.
Head b1c1de1c21 merged alone onto main 3b17977ba6, compared with 3b17977ba6 itself. I ran the 29 AGC tests that fail on main on this Mac, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer, through ctest --test-dir build -R <those 29> -V, three runs per side. Every Vulkan test logged Insert instance layer "VK_LAYER_KHRONOS_validation" and none logged was not found but was requested by env var VK_INSTANCE_LAYERS.
| test | main (3 runs) | this PR (3 runs) |
|---|---|---|
agc_driver_stencil_ref_export_unused |
Failed, Failed, Failed | Passed, Passed, Passed |
The other 27 tests gave the same result on both sides.
agc_driver_label_after_import_copy is flaky on main as well: main Failed, Passed, Passed, this PR Failed, Failed, Failed. Every failure on either side is the same timing check ("round N: a CPU read after the label that followed the copy found K of 262144 destination bytes not yet copied"), and it varied the same way across the other PRs I tested in the same session, so I don't attribute it to this change.
VUID- lines: identical per test on both sides (30 on main, 30 with this PR, over the three runs). The VUID- lines on both sides are main's existing VUID-VkDeviceCreateInfo-sType-unique (a duplicated VkPhysicalDevicePortabilitySubsetFeaturesKHR in the device pNext chain) and VUID-VkSamplerCreateInfo-samplerMipLodBias-04467; this PR adds none.
|
Tested this head (
Also run under the Khronos validation layer 1.4.363 ( AI-assisted: yes (Claude Code) |
|
Ran the focused tests with the Khronos validation layer on Linux and an NVIDIA GPU, since CI runs the GPU tests only on lavapipe and the Tested section is on MoltenVK only. The pattern covers all 21 tests with Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor
All 21 pass on both sides; every device selected the RTX 4090. No new AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the reviewed code supports the reported fix, and the optional note below is for validation coverage.
What I ran
Reviewed head b1c1de1c21df8b27187f180617396d7a7f20050b. No build or tests were run. I read the PR description, commit summary, manifest, diff, and all three changed files; I also inspected the stencil replay store and fragment setup that use the changed variable. files.json was not available in the prepared review bundle.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed code | passed | All three changed files read |
| Build and tests | not run | Author reports macOS build and test runs |
Findings
Blocking
None.
Non-blocking
ShaderValidation.cpp:167permitsu32forFragStencilRefEXT, and the emitter now declares and stores the built-in as unsigned. The signed private replay variable remainsi32and is still bitcast tou32before comparison, which keeps the two paths consistent. Consider adding a focused regression test for validation of both signed and unsigned stencil reference outputs; no such test was verified in this review.
Not verified
The author-reported MoltenVK compilation, macOS build, and test results were not independently run. Other GPU vendors and physical-console behavior were not verified. files.json was unavailable, so the complete reviewed versus files inventory could not be confirmed.
To get this to a good state
Nothing is required. Optional: add focused test coverage for the signed and unsigned stencil-reference output cases.
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
What
On MoltenVK, a pixel shader that exports the stencil reference fails to compile when the render pass has no stencil attachment (
agc_driver_stencil_ref_export_unused):The recompiler declares
FragStencilRefEXTas a signed 32-bit integer and writes it from the shader body, which is its own function called frommain. Without a stencil attachment MoltenVK has SPIRV-Cross disable the[[stencil]]output, and SPIRV-Cross then declares the replacement local inmainwith the SPIR-V type (int gl_FragStencilRefARB;) while the body function takes Metal's built-in type (thread uint& gl_FragStencilRefARB), so the call has no match. This reproduces outside AnyPS5 with the SDK's own tools on the SPIR-V MoltenVK logs:spirv-cross --msl --msl-version 30100 --msl-disable-frag-stencil-ref-builtin(vulkan-sdk-1.4.363.0) andxcrun metalgive the same error; with the default options (stencil output enabled) it compiles.VK_EXT_shader_stencil_exportonly requires a scalar 32-bit integer forFragStencilRefEXT, so this declares the built-in as unsigned:SpirvEmitterHelpers.cpp: the built-in usesTypeU32.SpirvModuleEmitter.cpp: the export stores the rawu32into the built-in; the replay emulation's private variable staysi32and keeps its bitcast.ShaderValidation.cpp: the fragment built-in check acceptsu32as well asi32forFragStencilRefEXT.With the unsigned type both declarations are
uint, and the same SPIR-V edited touintcompiles with and without--msl-disable-frag-stencil-ref-builtin.This touches the same stencil store in
SpirvModuleEmitter.cppas #10351 (which adds a stencil attachment branch there and is currently conflicting withmain); the changes are independent, and whichever lands second keeps both: the attachment branch from #10351, and the rawu32store for the built-in from this one.Tested
Apple M4, macOS 26.7.3, MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1), Apple clang 21.0.0, full Release build with
-DCMAKE_OSX_ARCHITECTURES=x86_64(tests under Rosetta),ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, onmain290ee1aa0fwith the open macOS build fixes (#17425, #11049, #11437, #19903, #19920) applied:agc_driver_stencil_ref_export_unused: fails before with the error above, passes after.*stencil*tests and the graphics validation unit test pass, includingagc_driver_stencil_ref_export,agc_driver_stencil_replayandagc_driver_stencil_replay_no_gpl.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer(layer from the same SDK), the 15 stencil tests pass, the loader inserts the layer in each run, nowas not found but was requested, and there are noVUID-messages.ctest -R '^(agc|shader|job)', 1578 tests,-j 4, compared with the same run before the change: no test fails that passed before. 13agc_driver_image_table*tests hit the validation-output regex under-j 4in the run with the change and pass when rerun serially with it, so I count them as load-dependent.Not run on lavapipe, AMD or NVIDIA; the change keeps the signed private variable for the replay path that devices without stencil export use.
The two other MoltenVK compile failures with the same shape (
agc_driver_pixel_sample_coverage,agc_driver_sample_order:SampleMaskinput passed into the body function asuint (&)[1]and read without[0]) are a separate SPIRV-Cross path and are not changed here.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)