fix(agc): flip the front face of replayed odd strip triangles without culling #27734
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27734"
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 frankea on 2026-11-27T06:39:02Z.
What
Stencil replay (devices without
VK_EXT_shader_stencil_export) draws a triangle strip one triangle at a time. A triangle replayed alone loses the strip's winding swap, so an odd triangle has reversed winding. #24379 flips the front face for those triangles, but only when culling is on:faceDynamicinrecordStencilReplayandVK_DYNAMIC_STATE_FRONT_FACE_EXTinPipeline.cppboth checkcullMode != VK_CULL_MODE_NONE. With culling off, a pixel shader that readsFrontFacingsees the wrong value on every odd triangle. The stencil result is not affected, becauseStencilReplayStripalready requires matching front and back stencil states.Changes:
recordStencilReplay: the front face of each odd strip triangle is now flipped whenever the device has graphics pipeline libraries, whether or not the strip is culled.Pipeline.cpp: a replay pipeline for a strip getsVK_DYNAMIC_STATE_FRONT_FACE_EXTon those devices without the culling condition (library pipelines already list it inPipelineLibraryDynamicStates).StencilReplayStrip: without graphics pipeline libraries, where the front face cannot be dynamic, a strip whose pixel shader readsFrontFacingthrowsstencil replay of a triangle strip whose pixel shader reads FrontFacing needs graphics pipeline libraries to flip the front face of its odd triangles. The newReadsFrontFacing(Pipeline.hpp) looks for aBuiltIn FrontFacingdecoration in the fragment SPIR-V. Culled strips on those devices were already refused, and strips that do not readFrontFacingreplay as before.fix-stencil-replay-multisample.mdnow describes the flip and the new refusal.Found while answering CodeRabbit on #24735 (https://github.com/boykopovar/AnyPS5/pull/24735#discussion_r4715710362). That PR and #24572 do not touch this code.
Tested
New case in
agc_driver_stencil_replay_tests(tests/execution/StencilReplay.cpp). A two-triangle strip covers the target with culling off. It is drawn once with a counter-clockwise front face and once with a clockwise one. The pixel shader exports alternating stencil references (two replay passes, so the strip is split) and writesmax(FrontFacing, 0)to color: 255 for front, 0 for back. With graphics pipeline libraries, every pixel of a strip must hold the same value, and the two front-face settings must give different values. Without them, the draw must throw the new refusal. The_no_gpland_unsuppressedctest entries (APS5_NO_GPL=1) run the refusal path on the 4090 too. The test helper gets apixelInputsargument (SPI_PS_INPUT_ENA/ADDR= POS_X + FRONT_FACE, plusSPI_BARYC_CNTL0). Existing draws keep the oldPixelInfo.Windows 11 on an RTX 4090 (NVIDIA 621.14), WinLibs GCC 15.2.0. macOS 27.0.1 on an Apple M5 Max, x86_64 Release under Rosetta, MoltenVK from the LunarG SDK 1.4.363.0 (no graphics pipeline libraries;
StencilReplay.cppalready removesStencilExportEXTfrom the target, so the replay path runs there). Both ran withANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1, three plain runs, and one run withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation+VK_LOADER_DEBUG=layerviactest -V. Focused set:^agc_driver_(stencil_replay|stencil_null_feedback|native_depth|native_multisample_depth). The change isb8f2517399onmain4cb7752e50. The headf321697b7emergesmain68d65e6b14into the earlier head980ec0df74(which mergedmain859a238b8cintob8f2517399). Both merges were clean, with no conflicts, and the change itself is the same.The table is from
f321697b7e. The 4090 control ismain68d65e6b14plus only the test change, run once plain and once with the validation layer (2/2). The Mac control is from the first round (main4cb7752e50plus only the test change) and was not rerun. Two entries skip by their own checks on both sides:native_depth_driver_queued_fillon the 4090 (host imports are compared there, not write-watched) andnative_depth_colour_importon the Mac.main+ testagc_driver_stencil_replaya replayed odd strip triangle reads a different FrontFacing than its strip at pixel (2, 0)agc_driver_stencil_replay_no_gpl,_unsuppresseda replayed triangle strip that reads FrontFacing was accepted without graphics pipeline librarieswas not found, 0VUID-was not found, 0VUID-agc_driver_stencil_replay(+_no_gpl,_unsuppressed)... accepted without graphics pipeline librariesnative_depth_publication(guest writes raced native multisample depth publication), which fails the same way onmain+ test (first round), 4/4was not found, 0VUID-The first round at
b8f2517399onmain4cb7752e50showed the same split: on the 4090 the control passed 42 of 45 with the three failures above and the PR passed 45 of 45 (no entry skipped then; 4/4 each, 85 validation inserts), and on the Mac the PR gave the rows above with 91 validation inserts.Plain
main4cb7752e50on the 4090 passed the same 45 entries 4/4 (0VUID-). Mutation on the Mac: with the newRequiredisabled, the three stencil replay entries fail with theaccepted without graphics pipeline librariesmessage.Other testers: JJenkx built this PR's exact head
980ec0df74(not merged into main) on Windows 11 (build 22621), Ryzen 9 5950X, MinGW-w64 GCC 15.2 UCRT r7, Release (https://github.com/boykopovar/AnyPS5/pull/27734#issuecomment-7265422864):agc_driver_stencil_replay,_no_gpland_unsuppressedpassed in 3 of 3 runs. Their report names no GPU, and has no control on main and no validation-layer run.tablefrogpillow built
b8f2517399onmain4cb7752e50on Linux with an AMD Radeon RX Vega 56 (gfx900, RADV) and the Mesa validation layers (https://github.com/boykopovar/AnyPS5/pull/27734#issuecomment-7211999878):agc_driver_stencil_replaypassed 3 of 3 runs, and withPipeline.hpp,Draw.cppandPipeline.cppreverted tomainit failed witha replayed odd strip triangle reads a different FrontFacing than its strip at pixel (2, 0). They report no validation errors at the PR head.Checklist
main; no other open PR implements the same functions (mainmerged at68d65e6b14). #24572 and #24735 edit the same sentence of the pendingfix-stencil-replay-multisample.mdfragment, so whichever merges second has a one-line conflict there. There are no code conflicts: the refusal sits insideStencilReplayStrip, not in theprepareDrawRequirethat #24572 rewrites.NotImplemented_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 MarcZX10 on 2026-11-27T07:37:30Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the available code and author-reported checks support the fix, though this review did not run them.
What I ran
Reviewed head
b8f2517399d760569de7585b987b8a4ce00ea0fe. Read the prepared description, commit summary, manifest, diff, and all five changed files; inspected the stencil replay caller and the changed replay and pipeline functions throughrepo_read.py. No test commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported Windows/NVIDIA and macOS/MoltenVK test runs were not independently verified. No build, tests, or console hardware behavior were run or confirmed. Files read:
core/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hpp,core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp,core/libs/prx/libSceAgcDriver/tests/execution/StencilReplay.cpp,docs/dev/debt/changes/fix-stencil-replay-multisample.md. Excluded changed files: none (files.jsonwas unavailable as a repository file; the review manifest and directory listing show all changed files included).To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T06:22:54Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
980ec0df742936ad0313d3706c4e29c8cb992b30using the prepared diff and repository reader. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime behavior and the author-reported test results were not independently verified. All five changed files listed as reviewed in the manifest were read; no changed files were excluded.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-02T03:23:31Z.
Review: COMMENTED
Actionable comments
35a77831-5b44-4dd9-af50-c0af261fb75aReviewing files that changed from the base of the PR and between
980ec0df74andf321697b7e.core/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:02:27Z.
Review: COMMENTED
The new fixture checks that the two replayed triangles agree and that toggling
frontFacechanges the answer. Could one variant compare facing against the same strip rendered in one native draw? Agreement within the replay and a toggle can both hold if the replay starts with the opposite winding. A native reference would check the absolute orientation.Source review at
f321697b7e. The head trial-merges onto6ef4f2f73b. Focused Linux checks are 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.