fix(agc): put back depth and stencil of quad-masked pixels #28229
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28229"
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-29T10:23:01Z.
What
Stacked on #28218: its commit is the first one here, and this PR is the second commit only.
With #28218, a draw that applies a quad sample mask in the pixel shader under early depth or stencil tests, from a pixel program that writes memory, runs under
EarlyFragmentTests. The early tests then also run for the masked pixels, so #28218 still refuses such a draw when it writes depth or stencil: the masked pixels would get the draw's depth and stencil, which on the console they never reach.This PR lifts that refusal. For such a draw (
prepareDraw,MaskedDepth), the depth-stencil target is copied before the draw's render pass (RecordMaskedDepthSave). After the pass, one pass puts the copy's depth back throughgl_FragDepth, and its stencil throughVK_EXT_shader_stencil_export, or one pass per bit without it, into the masked pixels only (RecordMaskedDepthRestore). The kept pixels are therefore tested and written in primitive order as on the console, and the masked ones end unchanged.Depthis split intoSaveand the draw, and the pass gets single-sample variants of its three fragment programs (DepthSingle,StencilExportSingle,StencilBitsSingle) plus sample shading only above one sample.DepthSurfaceMaskedTargetfinds the resident depth surface the copy is taken from.MaskedDepthRestoreRefusalkeeps the refusal where the restore is not implemented: a multisampled or layered depth target, or a host depth format other than the ones the sample-order depth pass writes back throughgl_FragDepth(16-bit, or 32-bit float). Like that pass, the restore does not keep a subnormal or NaN depth value on the RTX 2080 Ti's driver, as found in the review of #12120.The debt fragment of #28218 is updated to describe the restore.
Tested
agc_driver_sample_mask_early_stores(from #28218) now covers draws that write depth or stencil, over five quad pixel masks, for one triangle and for two overlapping triangles in one draw:agc_driver_sample_mask_depth_stencilnow expects the storing early-Z program with depth writes to store only in the kept pixels.sampleOrderTests(agc_graphics_profile_draw) checksMaskedDepthRestoreRefusal: a single-sampled 32-bit float target with stencil and a stencil-only write are accepted, and layered, multisampled and 24-bit depth targets are refused.agc_driver_sample_mask_early_stores: a restore that does nothing fails at "quad pixel mask 1, one triangle, depth is the draw's where the mask kept the pixel and the test passed, and the old depth elsewhere: pixel (3, 0) is 255, expected kept", and one that puts back every pixel fails at the same check with "pixel (2, 0) is 64, expected drawn".ctest --test-dir build -R <those names> -V, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer(validation layer 1.4.363.1). On this change all 28 pass. On #28218 alone, the same base06f1befb65, the 26 of them it has pass. The loader inserts the layer in every test that creates a Vulkan instance, neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither has aVUID-line.D32_SFLOAT_S8_UINTtarget. With both parts on the bring-up tree, the title draws them and reaches its first world frame (bring-up run 157).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
Bug Fixes
Tests
Documentation
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T10:34:49Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the remaining point is optional, and one changed test file could not be read in full.
What I ran
Reviewed head
d7018563da936789b9587945581d9d95f2f83b1eusing the prepared diff and the pinned repository reader. No commands or tests were run in this review.Results
tests/Graphics.cppwas excluded as too largeFindings
Blocking
None.
Non-blocking
Graphics/src/Draw.cpp:3180distinguishes a masked pass from other render passes by mixing a mask value into the existing pass key. This appears to prevent an unmasked draw from joining the restore pass, as intended; consider using an explicit key component if the pass-key representation is extended later, so the distinction is structural rather than hash-based.Not verified
core/libs/prx/libSceAgcDriver/tests/Graphics.cppwas excluded by the review folder size rule; its changed hunks were inspected indiff.patchonly.manifest.jsonwere read from the prepared full texts or targeted pinned-head ranges, includingtests/execution/SampleMaskEarlyStores.cppand the debt note.To get this to a good state
Nothing is required. Optional: consider representing the masked-pass discriminator explicitly in the pass key.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T06:05:37Z.
Review: APPROVED
I read the diff at
d7018563da. 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_depth_stencil,agc_driver_sample_mask_early_storesand 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 control also lacks #28218).Not checked: a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:11:53Z.
Review: COMMENTED
The fixture checks that a masked early-Z draw and a later unmasked draw use separate passes. The recording logic can also continue a pass across draws with the same mask, where it saves depth once and restores the excluded pixels only at pass end. Could the fixture issue two consecutive same-mask draws with distinct depth/stencil values and assert both that the pass continues and that the masked pixels retain their original values afterward? This covers the lifetime of the saved attachment across the continuation.
Source review at
d7018563da. The head trial-merges ontod2e04ef9b3. Paired Vulkan execution is queued.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.