feat(agc): draw DB stencil copies with a driver pixel program #16025

Merged
XatiX merged 1 commit from upstream-pr/16025 into main 2026-11-14 17:40:01 +00:00
XatiX commented 2026-11-05 11:13:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XatiX on 2026-11-05T11:13:40Z.


What

A DB copy with STENCIL_COPY set in DB_RENDER_CONTROL (bit 3, alone or with COPY_CENTROID or COPY_SAMPLE) was refused with DB_RENDER_CONTROL depth copy, resummarize or decompress is unsupported. PPSA06866 stops on it on the first loading screen with 0x88, and PPSA05666 sends the same value (#5499, #7649).

DecodeDepthCopyPass now accepts a stencil copy into a single-sample R8_UINT color target and refuses one without a stencil plane, into any other format, or combined with a depth copy. The draw is replaced by a driver pixel program, as the depth copy already is for R32_SFLOAT. It fetches the selected sample of the stencil plane through a descriptor with format 5 and no HTILE, and exports it on the first two channels (SPI_SHADER_COL_FORMAT 2, shader mask 3), so a target that swaps or masks to green also gets the value. The two programs (one and two samples) are added to DriverOwnedProgram, so their code is not captured as guest memory.

What the console DB writes for a stencil copy is not measured. The export on both channels follows the registers PPSA06866 sets (CB_COLOR0_INFO 0x00050c04, CB_TARGET_MASK 0x2, CB_SHADER_MASK 0x3).

Tests:

  • New agc_driver_stencil_copy_draw. Two stencil draws write 0x25 and then 0x5a over a shifted triangle, the copy runs, and every texel is compared with reference draws of each triangle: the copied value inside the copy's triangle, nothing outside it or in the row padding (the R8_UINT rows are 256 bytes apart). Cases: one sample with 0x88 and 0x08; two samples with 0x88 and 0x108, where the shifted draw is masked to sample 1, so the sample 0 copy must not see it and the sample 1 copy must; and both two-sample cases again into PPSA06866's alternate-swap target written through green.
  • agc_driver_graphics: decode of a stencil copy for one and two samples, its source descriptor, and the three refusals.
  • agc_driver_builtin_program_memory: the stencil copy programs are not captured, as for the depth copy.

Tested

  • Windows 11 Pro 26300, NVIDIA GeForce RTX 5080, driver 617.42, Vulkan SDK layer 1.4.363.0, WinLibs GCC 15.2.0 Release, ANYPS5_ENABLE_SPIRV_TOOLS=OFF.
  • ctest -V -R "stencil_copy|depth_copy|stencil_known|builtin_program|native_multisample_depth|agc_driver_graphics" with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1. Each log starts with its tested commit and these variables.
    • This change (7b6ac7fb8f, on main 8eca0f607d): 7/7 passed.
    • Control, the same tree with the eight non-test files from main 8eca0f607d: agc_driver_stencil_copy_draw fails with DB_RENDER_CONTROL depth copy, resummarize or decompress is unsupported (register 0x0 = 0x00000088), the error PPSA06866 stops on. Only that test runs in the control, because the other new checks call functions main does not have.
    • Neither log reports the layer as not found, has a VUID- line or skips a test. Logs: attached in the first comment.
  • Two mutants, each run once: a copy that always reads sample 0 fails at the sample 1 case, and a copy that reads the depth plane fails at the first case.
  • PPSA06866 (Divinity: Original Sin II Definitive Edition v01.007.000), 180 s scripted run on main 7ad9749ed0 plus only this commit (as ddf1290fb7; since then only a test case was added and the branch was rebased): no DB_RENDER_CONTROL refusal, it reaches the first loading screen and its bar advances (563 presents in the first 10 s), and it stops about 19 s after launch on native multisample depth publication cannot distinguish an unwritten byte from a same-value guest store. That is the next stop on this title (blocker 4 in #13726), not part of this change. The log does not show whether a stencil copy ran before that point: on plain main blocker 2 came 26 to 35 s in, and the driver logs no stencil copy that succeeds.
  • tools/check_conventions.py passes. No open PR found for stencil copy.

Found while writing the test, not changed here: a guest's stencil bytes are not loaded into a new stencil plane. A stencil EQUAL 0x25 draw over stencil memory filled with 0x25 passed on 0 of 256 texels. The test writes both values with draws, so it does not depend on this.

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
  • Fixes: none
  • Unblocks: PPSA06866 #13726 (blocker 2; the title then stops at blocker 4)
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 617.42, Windows 11 Pro 26300
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5170584542 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16025). Originally posted by [XatiX](https://github.com/XatiX) on 2026-11-05T11:13:40Z. --- ### What A DB copy with `STENCIL_COPY` set in `DB_RENDER_CONTROL` (bit 3, alone or with `COPY_CENTROID` or `COPY_SAMPLE`) was refused with `DB_RENDER_CONTROL depth copy, resummarize or decompress is unsupported`. PPSA06866 stops on it on the first loading screen with 0x88, and PPSA05666 sends the same value (#5499, #7649). `DecodeDepthCopyPass` now accepts a stencil copy into a single-sample `R8_UINT` color target and refuses one without a stencil plane, into any other format, or combined with a depth copy. The draw is replaced by a driver pixel program, as the depth copy already is for `R32_SFLOAT`. It fetches the selected sample of the stencil plane through a descriptor with format 5 and no HTILE, and exports it on the first two channels (`SPI_SHADER_COL_FORMAT` 2, shader mask 3), so a target that swaps or masks to green also gets the value. The two programs (one and two samples) are added to `DriverOwnedProgram`, so their code is not captured as guest memory. What the console DB writes for a stencil copy is not measured. The export on both channels follows the registers PPSA06866 sets (`CB_COLOR0_INFO` 0x00050c04, `CB_TARGET_MASK` 0x2, `CB_SHADER_MASK` 0x3). Tests: - New `agc_driver_stencil_copy_draw`. Two stencil draws write 0x25 and then 0x5a over a shifted triangle, the copy runs, and every texel is compared with reference draws of each triangle: the copied value inside the copy's triangle, nothing outside it or in the row padding (the `R8_UINT` rows are 256 bytes apart). Cases: one sample with 0x88 and 0x08; two samples with 0x88 and 0x108, where the shifted draw is masked to sample 1, so the sample 0 copy must not see it and the sample 1 copy must; and both two-sample cases again into PPSA06866's alternate-swap target written through green. - `agc_driver_graphics`: decode of a stencil copy for one and two samples, its source descriptor, and the three refusals. - `agc_driver_builtin_program_memory`: the stencil copy programs are not captured, as for the depth copy. ### Tested - Windows 11 Pro 26300, NVIDIA GeForce RTX 5080, driver 617.42, Vulkan SDK layer 1.4.363.0, WinLibs GCC 15.2.0 Release, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`. - `ctest -V -R "stencil_copy|depth_copy|stencil_known|builtin_program|native_multisample_depth|agc_driver_graphics"` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`. Each log starts with its tested commit and these variables. - This change (`7b6ac7fb8f`, on `main` `8eca0f607d`): 7/7 passed. - Control, the same tree with the eight non-test files from `main` `8eca0f607d`: `agc_driver_stencil_copy_draw` fails with `DB_RENDER_CONTROL depth copy, resummarize or decompress is unsupported (register 0x0 = 0x00000088)`, the error PPSA06866 stops on. Only that test runs in the control, because the other new checks call functions `main` does not have. - Neither log reports the layer as not found, has a `VUID-` line or skips a test. Logs: attached in the first comment. - Two mutants, each run once: a copy that always reads sample 0 fails at the sample 1 case, and a copy that reads the depth plane fails at the first case. - PPSA06866 (Divinity: Original Sin II Definitive Edition v01.007.000), 180 s scripted run on `main` `7ad9749ed0` plus only this commit (as `ddf1290fb7`; since then only a test case was added and the branch was rebased): no `DB_RENDER_CONTROL` refusal, it reaches the first loading screen and its bar advances (563 presents in the first 10 s), and it stops about 19 s after launch on `native multisample depth publication cannot distinguish an unwritten byte from a same-value guest store`. That is the next stop on this title (blocker 4 in #13726), not part of this change. The log does not show whether a stencil copy ran before that point: on plain `main` blocker 2 came 26 to 35 s in, and the driver logs no stencil copy that succeeds. - `tools/check_conventions.py` passes. No open PR found for stencil copy. Found while writing the test, not changed here: a guest's stencil bytes are not loaded into a new stencil plane. A stencil EQUAL 0x25 draw over stencil memory filled with 0x25 passed on 0 of 256 texels. The test writes both values with draws, so it does not depend on this. ### 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 - [x] Fixes: none - [x] Unblocks: PPSA06866 #13726 (blocker 2; the title then stops at blocker 4) - [x] GPUs tested: NVIDIA GeForce RTX 5080, driver 617.42, Windows 11 Pro 26300 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gabichuuuuu commented 2026-11-08 15:48:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T15:48:33Z.

Review: COMMENTED


Ran 7b6ac7fb8f merged on main 302864d48c on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Khronos validation layer 1.4.368), ctest -R '^(agc_driver_graphics$|agc_driver_builtin_program_memory|agc_driver_stencil_copy)' -V:

main change, 2 runs each
NVIDIA 2/2 3/3 twice
Intel 2/2 3/3 twice
  • The PR's test changes don't build on main (DepthCopyPass::stencil and the new DepthCopySourceWords argument come with this PR), so there's no run of the tests without the change.
  • The layer was inserted in every test that opens a device (agc_driver_graphics open none). No log has was not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has a VUID-. To be sure validation messages reach these logs, the same layer with best practices on printed 28 BestPractices- warnings into an agc_driver_recorder log on each GPU.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5818522854 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16025#pullrequestreview-5818522854). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T15:48:33Z. **Review:** COMMENTED --- Ran `7b6ac7fb8f` merged on `main` 302864d48c on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Khronos validation layer 1.4.368), `ctest -R '^(agc_driver_graphics$|agc_driver_builtin_program_memory|agc_driver_stencil_copy)' -V`: | | `main` | change, 2 runs each | |---|---|---| | NVIDIA | 2/2 | 3/3 twice | | Intel | 2/2 | 3/3 twice | - The PR's test changes don't build on `main` (`DepthCopyPass::stencil` and the new `DepthCopySourceWords` argument come with this PR), so there's no run of the tests without the change. - The layer was inserted in every test that opens a device (`agc_driver_graphics` open none). No log has `was not found but was requested by env var VK_INSTANCE_LAYERS`, and no log on either side has a `VUID-`. To be sure validation messages reach these logs, the same layer with best practices on printed 28 `BestPractices-` warnings into an `agc_driver_recorder` log on each GPU. AI-assisted: yes.
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!16025
No description provided.