feat(agc): replay stencil exports over triangle strips, with culling by the facing of each original triangle #24379

Merged
Capmare merged 1 commit from upstream-pr/24379 into main 2026-11-21 02:37:39 +00:00
Capmare commented 2026-11-20 15:28:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Capmare on 2026-11-20T15:28:33Z.


What

On a device without VK_EXT_shader_stencil_export (NVIDIA), the stencil replay draws each triangle once per reference value. Until now it accepted only triangle lists, so a triangle strip stopped the draw with stencil replay supports direct triangle lists without restart, mesh or tessellation.

Marvel's Wolverine (PPSA03671) stops on this after #18530: the draw of shader 0x11d01d0900 is a 4-vertex triangle strip with back-face culling. mrfelek saw the same stop on an RTX 3080 Ti in #18530.

The replay now splits a strip into its triangles. Triangle i uses vertices i to i + 2. A strip reverses the winding of every odd triangle, but the split triangle does not. So for each odd triangle the replay flips the front face with vkCmdSetFrontFace, and culling sees the facing of the original triangle.

A strip is accepted only when:

  • the front and back stencil states are equal,
  • no fragment input is flat, per-vertex or reads the vertex order, because the vertex order of a split triangle differs from the strip,
  • culling is off, or the device has graphics pipeline libraries. The front face is dynamic only in that path, so a culled strip is still refused without them.

The change:

  • Draw.cpp: StencilReplayStrip, FlippedFrontFace, and the strip split in recordStencilReplay.
  • Pipeline.cpp: VK_DYNAMIC_STATE_FRONT_FACE_EXT for a culled replay strip.
  • StencilReplay.cpp (test): a strip without culling, the four cull mode and front face pairs, and two strips that must stay refused.

Tested

Rocky Linux 10.2, i7-14700K, RTX 4070 SUPER, NVIDIA 620.70.06, Release, on main 7fa48cd1c6. Tests were run as ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R '^agc_driver_stencil'.

main this branch
agc_driver_stencil_* passing 7 of 11 (with the new test cases) 10 of 11

agc_driver_stencil_ref_export reports skipped on both sides, because NVIDIA does not expose the extension. On main the three agc_driver_stencil_replay* tests stop on the new strip case with stencil replay supports direct triangle lists without restart, mesh or tessellation.

New cases in agc_driver_stencil_replay:

  • A strip of two triangles that covers the target, without culling: both triangles are drawn.
  • The same strip with back or front culling and a clockwise or counter-clockwise front face: each pair draws both triangles or none, and the pairs that cull follow the face state. With the flip removed, the test fails with a replayed culled triangle strip draws both of its triangles or none: pixel (2, 0) is 64, expected drawn, because the odd triangle is culled the other way.
  • A strip with primitive restart, and a strip with different front and back stencil operations, are still refused. A culled strip is also refused in agc_driver_stencil_replay_no_gpl.

The validation layer reports only VUID-VkDeviceCreateInfo-pNext-pNext and VUID-VkShaderModuleCreateInfo-pCode-08737, 08739 and 08741. They come from device creation and the float-controls probe at startup, before the first draw, and also occur on main.

Marvel's Wolverine: with this change on top of #18530, the game accepts the draw and logs Stencil replay: a draw replays all 256 stencil reference values because its pixel shader's export is not bounded, recording 256 passes per triangle and instance. The run continued 90 s after the draw with no abort. I have not checked the image or the frame rate. The game reaches this draw only after the texture memory stall of #12575.

tools/pr_overlap.py merged the 87 PRs that share files with this branch into main with no conflict, and failed closed on 52 of them because they edit Draw.cpp or Pipeline.cpp. #22697 also edits StencilReplay.cpp; it moves recording into command streams and does not change the replay topology.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (#18530 is merged)
  • Fixes: none
  • Unblocks: the stencil replay strip stop of PPSA03671 #1033 (the game still stops at #12575)
  • GPUs tested: NVIDIA RTX 4070 SUPER, 620.70.06, Rocky Linux 10.2
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5415866285 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24379). Originally posted by [Capmare](https://github.com/Capmare) on 2026-11-20T15:28:33Z. --- ### What On a device without `VK_EXT_shader_stencil_export` (NVIDIA), the stencil replay draws each triangle once per reference value. Until now it accepted only triangle lists, so a triangle strip stopped the draw with `stencil replay supports direct triangle lists without restart, mesh or tessellation`. Marvel's Wolverine (PPSA03671) stops on this after #18530: the draw of shader `0x11d01d0900` is a 4-vertex triangle strip with back-face culling. mrfelek saw the same stop on an RTX 3080 Ti in #18530. The replay now splits a strip into its triangles. Triangle `i` uses vertices `i` to `i + 2`. A strip reverses the winding of every odd triangle, but the split triangle does not. So for each odd triangle the replay flips the front face with `vkCmdSetFrontFace`, and culling sees the facing of the original triangle. A strip is accepted only when: - the front and back stencil states are equal, - no fragment input is flat, per-vertex or reads the vertex order, because the vertex order of a split triangle differs from the strip, - culling is off, or the device has graphics pipeline libraries. The front face is dynamic only in that path, so a culled strip is still refused without them. The change: - `Draw.cpp`: `StencilReplayStrip`, `FlippedFrontFace`, and the strip split in `recordStencilReplay`. - `Pipeline.cpp`: `VK_DYNAMIC_STATE_FRONT_FACE_EXT` for a culled replay strip. - `StencilReplay.cpp` (test): a strip without culling, the four cull mode and front face pairs, and two strips that must stay refused. ### Tested Rocky Linux 10.2, i7-14700K, RTX 4070 SUPER, NVIDIA 620.70.06, Release, on `main` 7fa48cd1c6. Tests were run as `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R '^agc_driver_stencil'`. | | `main` | this branch | |---|---|---| | `agc_driver_stencil_*` passing | 7 of 11 (with the new test cases) | 10 of 11 | `agc_driver_stencil_ref_export` reports skipped on both sides, because NVIDIA does not expose the extension. On `main` the three `agc_driver_stencil_replay*` tests stop on the new strip case with `stencil replay supports direct triangle lists without restart, mesh or tessellation`. New cases in `agc_driver_stencil_replay`: - A strip of two triangles that covers the target, without culling: both triangles are drawn. - The same strip with back or front culling and a clockwise or counter-clockwise front face: each pair draws both triangles or none, and the pairs that cull follow the face state. With the flip removed, the test fails with `a replayed culled triangle strip draws both of its triangles or none: pixel (2, 0) is 64, expected drawn`, because the odd triangle is culled the other way. - A strip with primitive restart, and a strip with different front and back stencil operations, are still refused. A culled strip is also refused in `agc_driver_stencil_replay_no_gpl`. The validation layer reports only `VUID-VkDeviceCreateInfo-pNext-pNext` and `VUID-VkShaderModuleCreateInfo-pCode-08737`, `08739` and `08741`. They come from device creation and the float-controls probe at startup, before the first draw, and also occur on `main`. Marvel's Wolverine: with this change on top of #18530, the game accepts the draw and logs `Stencil replay: a draw replays all 256 stencil reference values because its pixel shader's export is not bounded, recording 256 passes per triangle and instance`. The run continued 90 s after the draw with no abort. I have not checked the image or the frame rate. The game reaches this draw only after the texture memory stall of #12575. `tools/pr_overlap.py` merged the 87 PRs that share files with this branch into `main` with no conflict, and failed closed on 52 of them because they edit `Draw.cpp` or `Pipeline.cpp`. #22697 also edits `StencilReplay.cpp`; it moves recording into command streams and does not change the replay topology. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none (#18530 is merged) - [x] Fixes: none - [x] Unblocks: the stencil replay strip stop of PPSA03671 #1033 (the game still stops at #12575) - [x] GPUs tested: NVIDIA RTX 4070 SUPER, 620.70.06, Rocky Linux 10.2 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-20 15:48:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T15:48:10Z.

Review: COMMENTED


Reviewed — no blocking findings

The reviewed change is consistent with its stated scope at head 246e22fc9ac5784829738b8b2e9a0fe24e221e7a; the prepared diff and targeted source reads show no verified blocking defect.

What I ran

No commands were run. I inspected the prepared diff and targeted source context; I did not run tests or build the change.

Results

Check Result Note
Diff and targeted code review passed Three changed files inspected
Tests and build not run Author-reported results were not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • The reported agc_driver_stencil_* test results, Vulkan validation output, game behavior, and performance were not independently verified.
  • The full text of all three changed files was not read; only changed-line ranges and targeted caller/context ranges were inspected. All changed files are included in the manifest; no excluded files were listed in the review folder.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5995397710 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24379#pullrequestreview-5995397710). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T15:48:10Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The reviewed change is consistent with its stated scope at head `246e22fc9ac5784829738b8b2e9a0fe24e221e7a`; the prepared diff and targeted source reads show no verified blocking defect. ## What I ran No commands were run. I inspected the prepared diff and targeted source context; I did not run tests or build the change. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted code review | passed | Three changed files inspected | | Tests and build | not run | Author-reported results were not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - The reported `agc_driver_stencil_*` test results, Vulkan validation output, game behavior, and performance were not independently verified. - The full text of all three changed files was not read; only changed-line ranges and targeted caller/context ranges were inspected. All changed files are included in the manifest; no excluded files were listed in the review folder. ## To get this to a good state Nothing is required.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!24379
No description provided.