fix(agc): key the pre-rasterization library by rasterizer discard #22058

Closed
chitters2004 wants to merge 1 commit from upstream-pr/22058 into main
chitters2004 commented 2026-11-17 03:35:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by chitters2004 on 2026-11-17T03:35:57Z.


What

The pre-rasterization pipeline library bakes rasterizerDiscardEnable from state.rasterizerDiscard, but libraryKeys (Graphics/src/Pipeline.cpp) did not add it to the pre-rasterization part key. Two draws with the same shaders and raster state, one with rasterization discarded and one without, therefore shared whichever pre-rasterization library was built first. The later draw then ran with the other draw's discard setting: either nothing reached the fragment stage, or a pass meant to discard rasterized.

Draws that set it include a position export with POS_FORMAT 0 (State.cpp) and the tessellation capture pass (Draw.cpp). This was found by reading the code; I have not seen it in a title.

This PR adds state.rasterizerDiscard to the pre-rasterization key. Only pre-rasterization libraries change; the vertex-input, fragment-shader and fragment-output keys do not.

Tested

  • New mock test pipelineLibraryRasterizerDiscardTests in tests/Graphics.cpp, run by agc_driver_graphics. It prebuilds the same shaders with discard off, on, off, on and requires two pre-rasterization libraries, created with discard VK_FALSE and then VK_TRUE. It also requires exactly one vertex-input, one fragment-shader and one fragment-output library. Without the fix it fails: only one pre-rasterization library is built.
  • Fork CI on lavapipe (Linux) and Windows passed: agc_driver_graphics, agc_pipeline_library_clear_waits_for_build and color_write_mask_dynamic.
  • python3 tools/check_conventions.py --base origin/main passes.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • GPUs tested: lavapipe (Linux, fork CI) and the Windows fork CI runner (mock and lavapipe tests only)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5350092872 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22058). Originally posted by [chitters2004](https://github.com/chitters2004) on 2026-11-17T03:35:57Z. --- ### What The pre-rasterization pipeline library bakes `rasterizerDiscardEnable` from `state.rasterizerDiscard`, but `libraryKeys` (`Graphics/src/Pipeline.cpp`) did not add it to the pre-rasterization part key. Two draws with the same shaders and raster state, one with rasterization discarded and one without, therefore shared whichever pre-rasterization library was built first. The later draw then ran with the other draw's discard setting: either nothing reached the fragment stage, or a pass meant to discard rasterized. Draws that set it include a position export with `POS_FORMAT` 0 (`State.cpp`) and the tessellation capture pass (`Draw.cpp`). This was found by reading the code; I have not seen it in a title. This PR adds `state.rasterizerDiscard` to the pre-rasterization key. Only pre-rasterization libraries change; the vertex-input, fragment-shader and fragment-output keys do not. ### Tested - New mock test `pipelineLibraryRasterizerDiscardTests` in `tests/Graphics.cpp`, run by `agc_driver_graphics`. It prebuilds the same shaders with discard off, on, off, on and requires two pre-rasterization libraries, created with discard `VK_FALSE` and then `VK_TRUE`. It also requires exactly one vertex-input, one fragment-shader and one fragment-output library. Without the fix it fails: only one pre-rasterization library is built. - Fork CI on lavapipe (Linux) and Windows passed: `agc_driver_graphics`, `agc_pipeline_library_clear_waits_for_build` and `color_write_mask_dynamic`. - `python3 tools/check_conventions.py --base origin/main` passes. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: none - [x] GPUs tested: lavapipe (Linux, fork CI) and the Windows fork CI runner (mock and lavapipe tests only) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
kurexw commented 2026-11-17 09:35:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T09:35:25Z.

Review: COMMENTED


Tested on macOS 27.2 on an Apple M4. This is an x86-64 build under Rosetta with Apple clang 21.0.0, on MoltenVK 1.4.2 from the LunarG Vulkan SDK 1.4.363.1.

Method. The base was main at a72186d3cf plus #22056 and #22074, which fix the macOS build of two other targets; both have since merged. I built the base and this PR merged onto it (a clean merge) in two separate build directories. I ran them alternately, base then PR, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer: five runs each, since agc_driver_graphics is known to be flaky:

ctest --test-dir build -R '^agc_driver_graphics$|^agc_pipeline_library_clear_waits_for_build$|color_write_mask_dynamic' -V
base (5 runs) This PR (5 runs)
agc_driver_graphics 4 Passed, 1 Failed 3 Passed, 2 Failed
agc_pipeline_library_clear_waits_for_build and the 3 color_write_mask_dynamic tests Passed Passed
Layer inserts per run 3 3
was not found but was requested 0 0
VUID- lines 0 0

Every agc_driver_graphics failure, on both sides, is the same pre-existing intermittent one: AGC graphics: two ranges under a budget for two were not imported, after MoltenVK refuses a host import (vkAllocateMemory (-2)). The difference between 1 and 2 failures in 5 runs is within that flakiness. The PR's change doesn't touch host imports.

Negative control. I kept this PR's test and restored the base's Graphics/src/Pipeline.cpp. Then agc_driver_graphics fails 3 runs out of 3 with a draw that discards rasterization shared a pre-rasterization library with one that does not. So the new mock test catches the bug on macOS too.

I didn't run a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5936017411 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22058#pullrequestreview-5936017411). Originally posted by [kurexw](https://github.com/kurexw) on 2026-11-17T09:35:25Z. **Review:** COMMENTED --- Tested on macOS 27.2 on an Apple M4. This is an x86-64 build under Rosetta with Apple clang 21.0.0, on MoltenVK 1.4.2 from the LunarG Vulkan SDK 1.4.363.1. **Method.** The base was `main` at a72186d3cf plus #22056 and #22074, which fix the macOS build of two other targets; both have since merged. I built the base and this PR merged onto it (a clean merge) in two separate build directories. I ran them alternately, base then PR, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer`: five runs each, since `agc_driver_graphics` is known to be flaky: ``` ctest --test-dir build -R '^agc_driver_graphics$|^agc_pipeline_library_clear_waits_for_build$|color_write_mask_dynamic' -V ``` | | base (5 runs) | This PR (5 runs) | | --- | --- | --- | | `agc_driver_graphics` | 4 Passed, 1 Failed | 3 Passed, 2 Failed | | `agc_pipeline_library_clear_waits_for_build` and the 3 `color_write_mask_dynamic` tests | Passed | Passed | | Layer inserts per run | 3 | 3 | | `was not found but was requested` | 0 | 0 | | `VUID-` lines | 0 | 0 | Every `agc_driver_graphics` failure, on both sides, is the same pre-existing intermittent one: `AGC graphics: two ranges under a budget for two were not imported`, after MoltenVK refuses a host import (`vkAllocateMemory (-2)`). The difference between 1 and 2 failures in 5 runs is within that flakiness. The PR's change doesn't touch host imports. **Negative control.** I kept this PR's test and restored the base's `Graphics/src/Pipeline.cpp`. Then `agc_driver_graphics` fails 3 runs out of 3 with `a draw that discards rasterization shared a pre-rasterization library with one that does not`. So the new mock test catches the bug on macOS too. I didn't run a title.
Jazeupoi commented 2026-11-18 14:42:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-18T14:42:10Z.

Review: COMMENTED


Tested on NVIDIA hardware, since the description's runs are on lavapipe and the fork's Windows CI.

Setup: Windows 11 Pro (build 26300), AMD Ryzen 5 3400G, NVIDIA GeForce RTX 2060 (driver 621.24), WinLibs GCC 15.2.0, Release. Base: main 28a71b481e with #22373 (a test-build fix only). "This PR" is the same tree with head 5a79dca262 merged.

10 tests, 3 runs each, with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1 (ctest -V, validation layer 1.4.363): agc_driver_graphics (which runs the new pipelineLibraryRasterizerDiscardTests), agc_pipeline_library_clear_waits_for_build, the three agc_driver_color_write_mask_dynamic* tests and the five agc_pipeline_library* recorder tests.

result layer inserted not found lines VUID-
main 10/10, 3/3 runs 8 per run 0 0
this PR 10/10, 3/3 runs 8 per run 0 0

No new validation errors on NVIDIA.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5958801573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22058#pullrequestreview-5958801573). Originally posted by [Jazeupoi](https://github.com/Jazeupoi) on 2026-11-18T14:42:10Z. **Review:** COMMENTED --- Tested on NVIDIA hardware, since the description's runs are on lavapipe and the fork's Windows CI. **Setup:** Windows 11 Pro (build 26300), AMD Ryzen 5 3400G, NVIDIA GeForce RTX 2060 (driver 621.24), WinLibs GCC 15.2.0, Release. Base: `main` `28a71b481e` with #22373 (a test-build fix only). "This PR" is the same tree with head `5a79dca262` merged. 10 tests, 3 runs each, with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `VK_LOADER_DEBUG=layer`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1` (`ctest -V`, validation layer 1.4.363): `agc_driver_graphics` (which runs the new `pipelineLibraryRasterizerDiscardTests`), `agc_pipeline_library_clear_waits_for_build`, the three `agc_driver_color_write_mask_dynamic*` tests and the five `agc_pipeline_library*` recorder tests. | | result | layer inserted | `not found` lines | `VUID-` | |---|---|---|---|---| | `main` | 10/10, 3/3 runs | 8 per run | 0 | 0 | | this PR | 10/10, 3/3 runs | 8 per run | 0 | 0 | No new validation errors on NVIDIA. AI-assisted: yes (Claude Code)

Pull request closed

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!22058
No description provided.