fix(agc): run quad-masked early-Z stores under early fragment tests #28218
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28218"
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 Meh7an on 2026-11-29T07:37:01Z.
What
PA_SC_AA_MASK_X0Y0_X1Y0andPA_SC_AA_MASK_X0Y1_X1Y1give each pixel of a 2x2 quad its own sample mask, while Vulkan'spSampleMaskis one mask for every pixel. A mask that differs between the pixels, or a uniform one that a sample reorder moves into the shader, is therefore applied in the pixel shader, and the recompiler leavesEarlyFragmentTestsout of such a module (QuadMasked()inSpirvModuleSetup.cpp). For a pixel program with early Z that writes memory under a depth, stencil or depth-bounds test, that order is wrong: the program would run, and store, for the pixels the tests reject. Main refuses such a draw inValidateSampleMask("a sample mask that differs between the pixels of a quad, from a pixel program with early depth or stencil tests that writes memory, is unsupported").For that draw (
SampleMaskAfterEarlyTests) the pipeline now addsEarlyFragmentTeststo the fragment module (WithEarlyFragmentTests, right after the fragment entry point), so the tests run first and the masked pixels are demoted after them.PixelEarlyZonly reports early Z for a program that neither kills nor exports depth, a sample mask or a stencil value (or underDEPTH_BEFORE_SHADER), so moving the tests ahead of the shader adds no conflict with those.The early tests then also run for the masked pixels, so such a draw stays refused when:
QuantizeFragmentDepth16patches the same module.The patch is part of the pipeline key and the fragment library key, and the pipeline journal now records
pixelEarlyZ, so a replay builds the same module (journal format 20). The first-visit library prebuild skips such a draw, whose libraries would be built from the unpatched module and never used. A debt fragment updates the "Sample masks" entry.Tested
agc_driver_sample_mask_early_stores. Over five quad pixel masks (1, 2, 6, 9, 14), a storing early-Z program draws and stores exactly where the mask keeps the pixel and the test passes, under a LESS and a GEQUAL depth test and under a stencil test; the late-Z program stores in every kept pixel. Depth and stencil are unchanged afterwards, the same draw recorded into a pass stores the same, and draws that write depth or stencil are refused and leave both unchanged. With occlusion queries counting samples, the early-Z draw is refused and the late-Z one draws.agc_driver_sample_mask_depth_stencilnow expects the storing early-Z and late-Z programs to store only in the kept pixels, and the depth-writing one to be refused.quadPixelMaskTestsandsampleOrderTests(agc_graphics_profile_draw) cover which draws take the early tests: not without early Z, without a test, with a uniform mask, or when only the vertex program writes memory. They also cover the refusals, 4x masks that keep whole pixels, and the SPIR-V patch.EarlyFragmentTestsfails at "quad pixel mask 1, the storing early-Z program at depth 0.5 under a LESS depth test: pixel (2, 0) stored 1, expected 0", and one without the occlusion refusal fails at "the storing early-Z program under a quad mask drew while occlusion queries count samples".agc_graphics_profile_draw,agc_driver_sample_mask_depth_stencil,_draw,_multisample,agc_driver_sample_order,agc_driver_alpha_to_coverage,agc_driver_pixel_sample_iteration,agc_driver_msaa_enable_single_sample, the eight*pipeline_journal*entries and the nine*pipeline_library*entries) ran withctest --test-dir build -R <those names> -Von main06f1befb65and on this change (26 with the new test). Both runs usedANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer(validation layer 1.4.363.1). All pass on both. The loader inserts the layer in the same tests on both (38 lines on main, 39 with the new test), neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither has aVUID-line.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T07:45:48Z.
Review: COMMENTED
436dfa7b-5fd0-4dba-bbaf-78fb21713c92Reviewing files that changed from the base of the PR and between
9d8f60b234anddf657f4f26.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/execution/SampleMaskDepthStencil.cppcore/libs/prx/libSceAgcDriver/tests/execution/SampleMaskEarlyStores.cppdocs/dev/debt/changes/fix-agc-quad-mask-early-tests.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T07:59:03Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the changed code and its added tests support merging.
What I ran
Reviewed head
df657f4f268f68dc4a09d52b8012f2d7a17a3da1using the prepared diff andrepo_read.pyat the pinned head. No build or tests were run. The author reports passing targeted ctest runs on main and this change; those results were not independently run here.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, ctest, or Vulkan execution test was run in this review.
core/libs/prx/libSceAgcDriver/tests/Graphics.cppwas excluded from the review folder, but the modified range was read throughrepo_read.py. The other changed files listed inreview/manifest.jsonwere read at their relevant changed lines; no changed files were excluded from review.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T06:05:30Z.
Review: APPROVED
I read the diff at
df657f4f26. Windows 11, GCC 15.2, merged intomainatcf556db18c3together with other open PRs (so not an isolated build), withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1andVK_LAYER_KHRONOS_validationon an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).agc_driver_sample_mask_early_stores,agc_driver_sample_mask_depth_stenciland the 60 tests ofagc_driver_graphics_tests: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has aVUID-orSYNC-HAZARDline.main's): the first two fail on both GPUs: "a sample mask that differs between the pixels of a quad, from a pixel program with early depth or stencil tests that writes memory, is unsupported".The tree also had #28229, which builds on this.
Not checked: a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:21:03Z.
Review: COMMENTED
The runtime fixture exercises the early-Z store against depth and stencil at one sample. The four-sample mask is covered through
ValidateSampleMask. Could an execution case also use a 4x target with whole-pixel masks and compare both the color result and memory stores? That covers the newly supported multisample path through the patched fragment module.Source review at
df657f4f26. Paired Vulkan execution is pending.AI-assisted: yes.