feat(agc): emulate a one-sided depth bounds test without the depthBounds feature #9737

Merged
imellag merged 1 commit from upstream-pr/9737 into main 2026-10-25 23:35:49 +00:00
imellag commented 2026-10-22 11:02:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-22T11:02:21Z.


What

On a device without the depthBounds feature (MoltenVK has none), every draw with the depth bounds test stops with device does not support the depth bounds test. Stray (PPSA02100) stops there on macOS, at two full-screen draws with bounds [0, 0.000125] and [0.000125, 1], no depth test and no depth write.

The depth bounds test passes a pixel when its stored depth Zs is within [min, max]. When the draw itself neither tests nor writes depth and one bound is at the end of the range, a depth test does the same thing:

  • With the viewport depth range pinned to one bound (minDepth = maxDepth = bound), every fragment's depth is that bound, whatever the vertices say. DB_RENDER_CONTROL.DEPTH_CLEAR_ENABLE draws already pin the range this way.
  • GREATER_OR_EQUAL against the upper bound passes exactly when max >= Zs; LESS_OR_EQUAL against the lower bound exactly when min <= Zs.

ApplyDepthBoundsEmulation (Graphics/src/State.cpp) runs after ApplyDepthRemap in decodeDraw, only when the device lacks depthBounds, and turns such a draw into a read-only depth test against one bound:

  • lower bound <= 0: GREATER_OR_EQUAL against the upper bound (bounds covering [0, 1] take this case too);
  • upper bound >= 1: LESS_OR_EQUAL against the lower bound;
  • depth bias is dropped: with no depth test or write in the draw it had no effect.

It throws, with its own message, for every case where this would not be exact:

  • both bounds inside (0, 1);
  • the draw tests or writes depth;
  • a pixel program that reads FragCoord.z or exports depth, since its fragment depth would change;
  • a stencil test that writes on a failed stencil test (failOp) or on a failed depth test (depthFailOp), since fragments outside the bounds now reach the stencil test;
  • a normalized depth target: the bound would be rounded to the format before the compare;
  • a device with VK_EXT_depth_range_unrestricted, where stored depth can be outside [0, 1] and a bound at 0 or 1 does not cover every value;
  • bounds outside [0, 1], as ValidateDepthBounds already refuses.

Devices with depthBounds are unchanged. The limits are a new entry in docs/dev/debt/libSceAgcDriver.md.

Tested

macOS (Apple M4 Pro, macOS 27.0.1, MoltenVK 1.4.2 from Vulkan SDK 1.4.363.0, x86-64 Release under Rosetta 2). main does not build on macOS, so this ran on main + #8658 + #9193 + #9263 + #8612 + #8477 + #9356 + #9387 (with the three fixes from #9387's review: the reviewed names, meshBarycentricPixel off under meshAsCompute, the test text) with this commit. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:

  • agc_driver_graphics passes. Its new DepthBoundsEmulationTests check the state each case becomes, that a device with depthBounds and a draw without a depth target are left alone, and each refusal.
  • New agc_driver_depth_bounds_emulation_draw passes. It stores a known depth with one draw, then draws with depth bounds and counts the pixels that pass, in 12 cases: each bound equal to the stored depth, and one float step past it, Stray's two bounds, and [0, 1] around stored 0 and 1. On a device with depthBounds it runs each case through the native test as well and requires the same result.
  • agc_driver_depth_bounds_state passes.
  • The validation layer loaded, and its only message is VUID-VkDeviceCreateInfo-pProperties-04451 at device creation, which every test on this stack prints.
  • Negative controls: with the two compare ops swapped, or without pinning the viewport depth range, agc_driver_depth_bounds_emulation_draw fails (stored 0.25, upper bound one step below it (emulated): 2048 of 2048 pixels passed, expected none).
  • Stray (PPSA02100 v01.002.000) on the same stack: before this change it stops at device does not support the depth bounds test. With it, it passes those draws and the mesh check, and stops about 70 s in at a Metal GPU hang (kIOGPUCommandBufferCallbackErrorHang) after the first mesh compute fallback work. That stop is outside this change. No frame is presented yet.

Linux (Ubuntu 24.04 x86-64 container, GCC 14.2, Release, lavapipe from Mesa 25.2.8, llvmpipe LLVM 20.1.2), paired: main 8a85a5c848 and this PR rebased onto it (dbda360df4), same container, same environment variables:

  • agc_driver_graphics and agc_driver_depth_bounds_state pass on both; agc_driver_depth_bounds_emulation_draw (12 cases) passes on the PR.
  • lavapipe has no depthBounds either, so neither of these runs could compare the emulation with the native test; the NVIDIA run below does.
  • The validation layer loaded. Its only message is VUID-VkDeviceCreateInfo-pNext-pNext at device creation, on both sides: Ubuntu's layer (1.3.275) does not know a structure type the device chain carries. main prints it through the existing agc_driver_pixel_barycentric_emulation; the PR prints it once more for its new draw test.

NVIDIA (run by @Lindamea1): RTX 5090, which reports depthBounds, driver 595.99.02, Gentoo, GCC 16.2.1, Release, layer 1.4.350, head 077bb434e5 merged onto main 8499ea52e, same environment variables:

  • agc_driver_depth_bounds_emulation_draw passes with 12 cases, 12 compared with the native test: every case also ran through the native depth bounds test, with the expected pixel count on both paths.
  • agc_driver_graphics and agc_driver_depth_bounds_state pass on main and with the change, with no validation errors.
  • ^(agc|shader|request_serializer) under the layer (874 tests on main, 875 with the change) and the full ctest without it: the same results as main apart from the new test passing, and the same validation errors, all present on main.

tools/check_conventions.py --base upstream/main passes. No other open pull request implements the depth bounds test. Merging each PR that tools/pr_overlap.py lists into current main and this PR on top: #6146, #6612, #6639, #6804, #9412, #9533, #9717 and #9742 merge cleanly; #7893, #8395, #8538, #9020, #9335, #9387 and #9748 conflict with main on their own and were not checked.

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: PPSA02100 #2461 (on macOS, past the depth bounds stop; the next stop is the GPU hang above)
  • GPUs tested: Apple M4 Pro, MoltenVK 1.4.2, macOS 27.0.1; lavapipe (Mesa 25.2.8, LLVM 20.1.2), Ubuntu 24.04 x86-64 container; NVIDIA RTX 5090, driver 595.99.02, Gentoo (run by @Lindamea1)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4966290604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9737). Originally posted by [imellag](https://github.com/imellag) on 2026-10-22T11:02:21Z. --- ### What On a device without the `depthBounds` feature (MoltenVK has none), every draw with the depth bounds test stops with `device does not support the depth bounds test`. Stray (PPSA02100) stops there on macOS, at two full-screen draws with bounds `[0, 0.000125]` and `[0.000125, 1]`, no depth test and no depth write. The depth bounds test passes a pixel when its **stored** depth `Zs` is within `[min, max]`. When the draw itself neither tests nor writes depth and one bound is at the end of the range, a depth test does the same thing: - With the viewport depth range pinned to one bound (`minDepth = maxDepth = bound`), every fragment's depth is that bound, whatever the vertices say. `DB_RENDER_CONTROL.DEPTH_CLEAR_ENABLE` draws already pin the range this way. - `GREATER_OR_EQUAL` against the upper bound passes exactly when `max >= Zs`; `LESS_OR_EQUAL` against the lower bound exactly when `min <= Zs`. `ApplyDepthBoundsEmulation` (Graphics/src/State.cpp) runs after `ApplyDepthRemap` in `decodeDraw`, only when the device lacks `depthBounds`, and turns such a draw into a read-only depth test against one bound: - lower bound `<= 0`: `GREATER_OR_EQUAL` against the upper bound (bounds covering `[0, 1]` take this case too); - upper bound `>= 1`: `LESS_OR_EQUAL` against the lower bound; - depth bias is dropped: with no depth test or write in the draw it had no effect. It throws, with its own message, for every case where this would not be exact: - both bounds inside `(0, 1)`; - the draw tests or writes depth; - a pixel program that reads `FragCoord.z` or exports depth, since its fragment depth would change; - a stencil test that writes on a failed stencil test (`failOp`) or on a failed depth test (`depthFailOp`), since fragments outside the bounds now reach the stencil test; - a normalized depth target: the bound would be rounded to the format before the compare; - a device with `VK_EXT_depth_range_unrestricted`, where stored depth can be outside `[0, 1]` and a bound at 0 or 1 does not cover every value; - bounds outside `[0, 1]`, as `ValidateDepthBounds` already refuses. Devices with `depthBounds` are unchanged. The limits are a new entry in `docs/dev/debt/libSceAgcDriver.md`. ### Tested **macOS** (Apple M4 Pro, macOS 27.0.1, MoltenVK 1.4.2 from Vulkan SDK 1.4.363.0, x86-64 Release under Rosetta 2). `main` does not build on macOS, so this ran on `main` + #8658 + #9193 + #9263 + #8612 + #8477 + #9356 + #9387 (with the three fixes from #9387's review: the reviewed names, `meshBarycentricPixel` off under `meshAsCompute`, the test text) with this commit. `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`: - `agc_driver_graphics` passes. Its new `DepthBoundsEmulationTests` check the state each case becomes, that a device with `depthBounds` and a draw without a depth target are left alone, and each refusal. - New `agc_driver_depth_bounds_emulation_draw` passes. It stores a known depth with one draw, then draws with depth bounds and counts the pixels that pass, in 12 cases: each bound equal to the stored depth, and one float step past it, Stray's two bounds, and `[0, 1]` around stored 0 and 1. On a device with `depthBounds` it runs each case through the native test as well and requires the same result. - `agc_driver_depth_bounds_state` passes. - The validation layer loaded, and its only message is `VUID-VkDeviceCreateInfo-pProperties-04451` at device creation, which every test on this stack prints. - Negative controls: with the two compare ops swapped, or without pinning the viewport depth range, `agc_driver_depth_bounds_emulation_draw` fails (`stored 0.25, upper bound one step below it (emulated): 2048 of 2048 pixels passed, expected none`). - Stray (PPSA02100 v01.002.000) on the same stack: before this change it stops at `device does not support the depth bounds test`. With it, it passes those draws and the mesh check, and stops about 70 s in at a Metal GPU hang (`kIOGPUCommandBufferCallbackErrorHang`) after the first mesh compute fallback work. That stop is outside this change. No frame is presented yet. **Linux** (Ubuntu 24.04 x86-64 container, GCC 14.2, Release, lavapipe from Mesa 25.2.8, llvmpipe LLVM 20.1.2), paired: `main` `8a85a5c848` and this PR rebased onto it (`dbda360df4`), same container, same environment variables: - `agc_driver_graphics` and `agc_driver_depth_bounds_state` pass on both; `agc_driver_depth_bounds_emulation_draw` (12 cases) passes on the PR. - lavapipe has no `depthBounds` either, so neither of these runs could compare the emulation with the native test; the NVIDIA run below does. - The validation layer loaded. Its only message is `VUID-VkDeviceCreateInfo-pNext-pNext` at device creation, on both sides: Ubuntu's layer (1.3.275) does not know a structure type the device chain carries. `main` prints it through the existing `agc_driver_pixel_barycentric_emulation`; the PR prints it once more for its new draw test. **NVIDIA** (run by @Lindamea1): RTX 5090, which reports `depthBounds`, driver 595.99.02, Gentoo, GCC 16.2.1, Release, layer 1.4.350, head `077bb434e5` merged onto `main` `8499ea52e`, same environment variables: - `agc_driver_depth_bounds_emulation_draw` passes with `12 cases, 12 compared with the native test`: every case also ran through the native depth bounds test, with the expected pixel count on both paths. - `agc_driver_graphics` and `agc_driver_depth_bounds_state` pass on `main` and with the change, with no validation errors. - `^(agc|shader|request_serializer)` under the layer (874 tests on `main`, 875 with the change) and the full `ctest` without it: the same results as `main` apart from the new test passing, and the same validation errors, all present on `main`. `tools/check_conventions.py --base upstream/main` passes. No other open pull request implements the depth bounds test. Merging each PR that `tools/pr_overlap.py` lists into current `main` and this PR on top: #6146, #6612, #6639, #6804, #9412, #9533, #9717 and #9742 merge cleanly; #7893, #8395, #8538, #9020, #9335, #9387 and #9748 conflict with `main` on their own and were not checked. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: PPSA02100 #2461 (on macOS, past the depth bounds stop; the next stop is the GPU hang above) - [x] GPUs tested: Apple M4 Pro, MoltenVK 1.4.2, macOS 27.0.1; lavapipe (Mesa 25.2.8, LLVM 20.1.2), Ubuntu 24.04 x86-64 container; NVIDIA RTX 5090, driver 595.99.02, Gentoo (run by @Lindamea1) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-22 15:06:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T15:06:29Z.

Review: DISMISSED


The emulation is carefully bounded: it only substitutes a one-sided check for draws without a depth test/write, rejects normalized depth and depth-reading/exporting pixel programs, and guards stencil failure side effects. The state tests cover these refusal boundaries, while the GPU test covers equality and adjacent-float boundary cases. I did not find a substantiated implementation defect.

Please refresh from current main and rerun the focused test/validation comparison on that base. This PR is based on 4777caca, 54 commits behind the current main b7d1d47a. CONTRIBUTING.md requires shader/AGC changes to run the same focused tests on main and the change using VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, and ANYPS5_REQUIRE_VULKAN=1 with ctest -V, comparing VUID output. The description records detailed validation-layer runs on the change and negative controls, but not a paired run on the current main revision.

Please also refresh the overlap check and record the agreed order/dependency for any confirmed shared edits. The current overlap bot comment lists #6612 (Graphics/src/State.cpp) and #6639/#9412 (the AGC debt entry); the description instead lists #6146/#6804/#9335. Since #6612 is still open, please reconcile the current overlap list and follow the repository rule to coordinate order and update Depends on when applicable.

Local git diff --check and python tools/check_conventions.py --base upstream/main --head upstream/pr/9737 pass. I could not run Vulkan tests locally because there is no configured build and only about 649 MB free. The PR reports macOS/MoltenVK and Linux/lavapipe runs; neither device has the native depthBounds feature, so an NVIDIA/AMD comparison would add valuable coverage if available.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5616367210 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9737#pullrequestreview-5616367210). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T15:06:29Z. **Review:** DISMISSED --- The emulation is carefully bounded: it only substitutes a one-sided check for draws without a depth test/write, rejects normalized depth and depth-reading/exporting pixel programs, and guards stencil failure side effects. The state tests cover these refusal boundaries, while the GPU test covers equality and adjacent-float boundary cases. I did not find a substantiated implementation defect. Please refresh from current `main` and rerun the focused test/validation comparison on that base. This PR is based on `4777caca`, 54 commits behind the current `main` `b7d1d47a`. `CONTRIBUTING.md` requires shader/AGC changes to run the same focused tests on `main` and the change using `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1`, and `ANYPS5_REQUIRE_VULKAN=1` with `ctest -V`, comparing VUID output. The description records detailed validation-layer runs on the change and negative controls, but not a paired run on the current main revision. Please also refresh the overlap check and record the agreed order/dependency for any confirmed shared edits. The current overlap bot comment lists #6612 (`Graphics/src/State.cpp`) and #6639/#9412 (the AGC debt entry); the description instead lists #6146/#6804/#9335. Since #6612 is still open, please reconcile the current overlap list and follow the repository rule to coordinate order and update `Depends on` when applicable. Local `git diff --check` and `python tools/check_conventions.py --base upstream/main --head upstream/pr/9737` pass. I could not run Vulkan tests locally because there is no configured build and only about 649 MB free. The PR reports macOS/MoltenVK and Linux/lavapipe runs; neither device has the native `depthBounds` feature, so an NVIDIA/AMD comparison would add valuable coverage if available.
adriadam10 commented 2026-10-24 03:28:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T03:28:33Z.

Review: CHANGES_REQUESTED


Main moved under this PR (the one-sample colour and DB_EQAA changes in State.cpp, Graphics.cpp and the CMake file); the depth bounds emulation itself is unaffected, and the head is unchanged, so the code review stands.

The request still open is the one from @MarcZX10: a paired run of the focused tests with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation on this head against current main. The last paired run (56c0df9795) predates main's multisample and coverage changes. Please post it for da2f6513c rebased onto the current main:

  • ctest -V -R 'agc_driver_(graphics|depth_bounds_state|depth_bounds_emulation_draw)' on main and on the PR, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation;
  • the two logs compared for VUID- messages (the existing device-creation ones are fine; any new one must be explained).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636653942 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9737#pullrequestreview-5636653942). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-24T03:28:33Z. **Review:** CHANGES_REQUESTED --- Main moved under this PR (the one-sample colour and DB_EQAA changes in `State.cpp`, `Graphics.cpp` and the CMake file); the depth bounds emulation itself is unaffected, and the head is unchanged, so the code review stands. The request still open is the one from @MarcZX10: a paired run of the focused tests with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` on this head against current `main`. The last paired run (`56c0df9795`) predates main's multisample and coverage changes. Please post it for `da2f6513c` rebased onto the current `main`: - `ctest -V -R 'agc_driver_(graphics|depth_bounds_state|depth_bounds_emulation_draw)'` on `main` and on the PR, with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`; - the two logs compared for `VUID-` messages (the existing device-creation ones are fine; any new one must be explained).
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!9737
No description provided.