fix(agc): store D16 depth with stencil as D24 or D32 where the device lacks it #3846

Merged
tv7 merged 4 commits from upstream-pr/3846 into main 2026-10-12 20:20:06 +00:00
tv7 commented 2026-10-11 17:53:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-11T17:53:33Z.


What

A 16-bit depth target with stencil decodes to VK_FORMAT_D16_UNORM_S8_UINT (State.cpp, zFormat == 1 with stencil). NVIDIA devices do not offer that format as a depth/stencil attachment, so DepthSurface threw depth/stencil format 128 cannot be an attachment on this device.

The depth surface lives only on the host: it is cleared at creation and sampled through views, never copied from or to guest memory. So the host image can use a wider format:

  • New HostDepthFormat(context, format): for D16_UNORM_S8_UINT it returns the first of D16_UNORM_S8_UINT, D24_UNORM_S8_UINT, D32_SFLOAT_S8_UINT that the device can attach and sample (cached per physical device). Every other format is returned unchanged.
  • DepthSurface creates its image, view and sampled textures with it, and the pipeline uses it for the render pass attachment, the dynamic rendering formats and the Begin depth format.
  • Guest-side decisions still use the guest format: 16-bit sampled views (R16_UNORM or 16 depth bits) of the plane, the depth-bias units check in decodeDepthBias, and the pipeline keys.
  • Depth bias: the constant is in units of the format's resolution, so HostDepthBiasConstant scales it by 256 for D24 storage. For D32 float storage the unit depends on the depth value, so a non-zero constant there throws (not implemented). The slope factor needs no change.

Tested

Windows 11, RTX 3070 (no D16_UNORM_S8_UINT attachment support), GCC 15.2.0 UCRT, Release, on main a11c8f7f7.

  • agc_driver_graphics (DepthSurfaceReuse.cpp, TestD16StencilFallback, mocked format properties): a device with D16S8 keeps it and its bias; a device without it creates the surface as D24S8, its R16 depth view and R8 stencil view still sample, and a bias of 2 becomes 512; a device with only D32S8 uses it, and a constant bias there throws.
  • ctest 831/836. 4 others (guest_kernel_sys, windows_exceptions, guest_filesystem, agc_driver_emulated_color_compare) fail the same way on main on this machine. agc_driver_prepared_shaders_debug failed once under -j8 and once in 3 runs alone. It then passed 6/6 here and 6/6 on main. It also failed once under -j8 today on a branch that only changes Apr.cpp, so it looks like an existing intermittent failure.
  • tools/check_conventions.py passes.
  • Marvel's Wolverine (PPSA03671), on main plus #757, #3588, #3633 and #3336: without this change it stops at its first 16-bit depth/stencil target with the error above. With it, it plays its intro videos for 7 minutes at about 2.3 FPS, until a separate VideoOut stop (buffer attributes are in use by a pending flip).
  • Merges cleanly with the open PRs that touch the same files (#757, #2904, #3702, #3816).

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes, Claude Code

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4821098731 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3846). Originally posted by [tv7](https://github.com/tv7) on 2026-10-11T17:53:33Z. --- ### What A 16-bit depth target with stencil decodes to `VK_FORMAT_D16_UNORM_S8_UINT` (`State.cpp`, `zFormat == 1` with stencil). NVIDIA devices do not offer that format as a depth/stencil attachment, so `DepthSurface` threw `depth/stencil format 128 cannot be an attachment on this device`. The depth surface lives only on the host: it is cleared at creation and sampled through views, never copied from or to guest memory. So the host image can use a wider format: - New `HostDepthFormat(context, format)`: for `D16_UNORM_S8_UINT` it returns the first of `D16_UNORM_S8_UINT`, `D24_UNORM_S8_UINT`, `D32_SFLOAT_S8_UINT` that the device can attach and sample (cached per physical device). Every other format is returned unchanged. - `DepthSurface` creates its image, view and sampled textures with it, and the pipeline uses it for the render pass attachment, the dynamic rendering formats and the `Begin` depth format. - Guest-side decisions still use the guest format: 16-bit sampled views (`R16_UNORM` or 16 depth bits) of the plane, the depth-bias units check in `decodeDepthBias`, and the pipeline keys. - Depth bias: the constant is in units of the format's resolution, so `HostDepthBiasConstant` scales it by 256 for D24 storage. For D32 float storage the unit depends on the depth value, so a non-zero constant there throws (not implemented). The slope factor needs no change. ### Tested Windows 11, RTX 3070 (no `D16_UNORM_S8_UINT` attachment support), GCC 15.2.0 UCRT, Release, on main `a11c8f7f7`. - `agc_driver_graphics` (`DepthSurfaceReuse.cpp`, `TestD16StencilFallback`, mocked format properties): a device with D16S8 keeps it and its bias; a device without it creates the surface as D24S8, its R16 depth view and R8 stencil view still sample, and a bias of 2 becomes 512; a device with only D32S8 uses it, and a constant bias there throws. - ctest 831/836. 4 others (`guest_kernel_sys`, `windows_exceptions`, `guest_filesystem`, `agc_driver_emulated_color_compare`) fail the same way on main on this machine. `agc_driver_prepared_shaders_debug` failed once under `-j8` and once in 3 runs alone. It then passed 6/6 here and 6/6 on main. It also failed once under `-j8` today on a branch that only changes `Apr.cpp`, so it looks like an existing intermittent failure. - `tools/check_conventions.py` passes. - Marvel's Wolverine (PPSA03671), on main plus #757, #3588, #3633 and #3336: without this change it stops at its first 16-bit depth/stencil target with the error above. With it, it plays its intro videos for 7 minutes at about 2.3 FPS, until a separate VideoOut stop (`buffer attributes are in use by a pending flip`). - Merges cleanly with the open PRs that touch the same files (#757, #2904, #3702, #3816). ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes, Claude Code 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-11 22:09:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:09:28Z.


Checked: every use of the depth format (image, view, sampled textures, render pass, dynamic rendering, Begin, depth bias in all three paths); guest-side decisions (16-bit views, bias units check, pipeline keys) correctly keep the guest format. The bias scale (2^-16 → 2^-24 = x256) is right, and the D32 constant bias throws instead of guessing. agc_driver_graphics passes with the new case, and the case does not build without the change.

Added one commit: a TechnicalDebt line under Functional for the D24/D32 precision difference and the D32 bias throw (checklist: unverified choices get a line). Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114398157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3846#issuecomment-6114398157). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T22:09:28Z. --- Checked: every use of the depth format (image, view, sampled textures, render pass, dynamic rendering, `Begin`, depth bias in all three paths); guest-side decisions (16-bit views, bias units check, pipeline keys) correctly keep the guest format. The bias scale (2^-16 → 2^-24 = x256) is right, and the D32 constant bias throws instead of guessing. `agc_driver_graphics` passes with the new case, and the case does not build without the change. Added one commit: a TechnicalDebt line under Functional for the D24/D32 precision difference and the D32 bias throw (checklist: unverified choices get a line). Merging once CI is green.
oneandonlydean commented 2026-10-12 08:24:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T08:24:20Z.


Conflicts with main in DepthSurface.cpp since #2169: it added SampleLocationsCompatibleDepth(context, target.format, target.samples) just above info.format in the DepthSurface constructor. Please rebase; that call checks the image being created, so it should take hostFormat too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120522680 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3846#issuecomment-6120522680). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T08:24:20Z. --- Conflicts with main in `DepthSurface.cpp` since #2169: it added `SampleLocationsCompatibleDepth(context, target.format, target.samples)` just above `info.format` in the `DepthSurface` constructor. Please rebase; that call checks the image being created, so it should take `hostFormat` too.
blawesom commented 2026-10-12 13:09:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T13:09:55Z.


Rebase handoff — rebased onto current main, authorship unchanged (both commits).

Two conflicts, both resolved: (1) DepthSurface.cpp — main added SampleLocationsCompatibleDepth where this PR adds HostDepthFormat/HostDepthBiasConstant; kept both, independent functions. (2) TechnicalDebt.md — union, both entries kept.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV — a device that has native D16_UNORM_S8_UINT, so this PR's fallback path is not exercised here, only that nothing regresses):

  • builds; tools/check_conventions.py --base origin/main passes
  • full suite: 952/952 passed

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/3846
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is 042ff1dff.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6124936502 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3846#issuecomment-6124936502). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-12T13:09:55Z. --- **Rebase handoff** — rebased onto current `main`, authorship unchanged (both commits). Two conflicts, both resolved: (1) `DepthSurface.cpp` — main added `SampleLocationsCompatibleDepth` where this PR adds `HostDepthFormat`/`HostDepthBiasConstant`; kept both, independent functions. (2) `TechnicalDebt.md` — union, both entries kept. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV — a device that *has* native D16_UNORM_S8_UINT, so this PR's fallback path is not exercised here, only that nothing regresses): - builds; `tools/check_conventions.py --base origin/main` passes - **full suite: 952/952 passed** **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/3846 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `042ff1dff`.
tv7 commented 2026-10-12 17:20:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-12T17:20:35Z.


Took @blawesom's rebase (thanks!) and rebased it on main 2a5eca11c. Per @oneandonlydean: SampleLocationsCompatibleDepth now gets the host format, both in the DepthSurface constructor (hostFormat) and in ValidateSampleLocations (HostDepthFormat(context, state.depth->format)), so the pipeline and the image ask about the same format (c2160f0e8). Windows/MinGW: 973/973.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6129136128 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3846#issuecomment-6129136128). Originally posted by [tv7](https://github.com/tv7) on 2026-10-12T17:20:35Z. --- Took @blawesom's rebase (thanks!) and rebased it on main 2a5eca11c. Per @oneandonlydean: `SampleLocationsCompatibleDepth` now gets the host format, both in the `DepthSurface` constructor (`hostFormat`) and in `ValidateSampleLocations` (`HostDepthFormat(context, state.depth->format)`), so the pipeline and the image ask about the same format (c2160f0e8). Windows/MinGW: 973/973.
tv7 commented 2026-10-12 19:14:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-12T19:14:54Z.


Rebased on main d53960612 (574d7ec44). The only conflict was docs/dev/TechnicalDebt.md after 342a8c459: the D16 stencil entry now sits in docs/dev/debt/libSceAgcDriver.md under Functional (link depth adjusted). This also undoes a join from the earlier union, where the entry had run into the next line. Windows/MinGW: 995/995.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6130935907 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3846#issuecomment-6130935907). Originally posted by [tv7](https://github.com/tv7) on 2026-10-12T19:14:54Z. --- Rebased on main d53960612 (574d7ec44). The only conflict was `docs/dev/TechnicalDebt.md` after 342a8c459: the D16 stencil entry now sits in `docs/dev/debt/libSceAgcDriver.md` under Functional (link depth adjusted). This also undoes a join from the earlier union, where the entry had run into the next line. Windows/MinGW: 995/995.
github-actions[bot] commented 2026-10-12 19:26:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T19:26:32Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4500 core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp L28
#4683 core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp L8-9, L33-35
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131124847 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3846#issuecomment-6131124847). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T19:26:32Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4500 | `core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp` [L28](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp#L28) | | | | #4683 | `core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp` [L8-9](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp#L8-L9), [L33-35](https://github.com/boykopovar/AnyPS5/blob/0428328b79af7820990ffc6964fb9009041bcdcf/core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp#L33-L35) | | |
adriadam10 commented 2026-10-12 20:16:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:16:02Z.


Checked the new head: SampleLocationsCompatibleDepth now gets the host depth format in the DepthSurface constructor and in ValidateSampleLocations, as @oneandonlydean asked, so the pipeline and the image query the same format. The debt entry in docs/dev/debt/libSceAgcDriver.md is correct after the move. agc_driver_graphics passes with the D16/D24/D32 cases; libSceAgcDriver ctest 452/452.

Added one commit: dropped the duplicated DepthSurface.hpp include in Pipeline.cpp. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131879076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3846#issuecomment-6131879076). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T20:16:02Z. --- Checked the new head: `SampleLocationsCompatibleDepth` now gets the host depth format in the `DepthSurface` constructor and in `ValidateSampleLocations`, as @oneandonlydean asked, so the pipeline and the image query the same format. The debt entry in `docs/dev/debt/libSceAgcDriver.md` is correct after the move. `agc_driver_graphics` passes with the D16/D24/D32 cases; libSceAgcDriver ctest 452/452. Added one commit: dropped the duplicated `DepthSurface.hpp` include in `Pipeline.cpp`. Merging once CI is green.
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!3846
No description provided.