fix(agc): scale a depth bias constant to the target depth format #21345

Merged
relativespace2K merged 5 commits from upstream-pr/21345 into main 2026-11-20 09:56:17 +00:00
relativespace2K commented 2026-11-16 05:25:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by relativespace2K on 2026-11-16T05:25:47Z.


What

The AGC depth-bias format register (0x2de) selects 16-bit (0xf0) or float (0x1e9) bias units. decodeDepthBias rejected a draw when the selected units differed from the target depth format. It now scales the front and back constant factors by 256 (16-bit units on a float target) or 1/256 (float units on a 16-bit target) instead of throwing; the slope factor is already divided by 16. The new case in tests/Graphics.cpp covers the four format pairs, including 16-bit units on a D16 target.

The fixed factor is an approximation for the float-unit case: 0x1e9 is the float encoding, so on a D16 target the exact factor depends on the primitive's largest-depth exponent (2^(e-7)); 1/256 is exact only for a largest depth in [0.5, 1). 0xf0 on a D32F target can be exact with VK_EXT_depth_bias_control's force-unorm representation, which is not used. The gap is recorded in docs/dev/debt/changes/fix-agc-depth-bias-format.md.

Tested

Windows 11 22621, AMD RX 6800 XT (RDNA2, driver 26.10.1), Ryzen 5 5600, MinGW-w64 GCC 15.2.0.

  • agc_driver_graphics with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1: 1/1 passed, 0 VUID- lines. This test validates decoded state on the CPU and creates no Vulkan instance, so the validation layer has nothing to insert.
  • The Witcher 3 (PPSA03977): plain main aborts at about 90 s with depth bias in units other than the depth format (register 0x2de = 0x000001e9). With this change the village scene runs; 300 s stable with no crash.

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: PPSA03977 #20342; PPSA01487 #21176 (same 0x2de = 0x1e9/D16 stop)
  • GPUs tested: AGC: AMD RX 6800 XT (RDNA2, driver 26.10.1), Windows 11 22621; shader recompiler and VideoOut: n/a (state decode only)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5331586008 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21345). Originally posted by [relativespace2K](https://github.com/relativespace2K) on 2026-11-16T05:25:47Z. --- ### What The AGC depth-bias format register (`0x2de`) selects 16-bit (`0xf0`) or float (`0x1e9`) bias units. `decodeDepthBias` rejected a draw when the selected units differed from the target depth format. It now scales the front and back constant factors by 256 (16-bit units on a float target) or 1/256 (float units on a 16-bit target) instead of throwing; the slope factor is already divided by 16. The new case in `tests/Graphics.cpp` covers the four format pairs, including 16-bit units on a D16 target. The fixed factor is an approximation for the float-unit case: `0x1e9` is the float encoding, so on a D16 target the exact factor depends on the primitive's largest-depth exponent (`2^(e-7)`); 1/256 is exact only for a largest depth in [0.5, 1). `0xf0` on a D32F target can be exact with `VK_EXT_depth_bias_control`'s force-unorm representation, which is not used. The gap is recorded in `docs/dev/debt/changes/fix-agc-depth-bias-format.md`. ### Tested Windows 11 22621, AMD RX 6800 XT (RDNA2, driver 26.10.1), Ryzen 5 5600, MinGW-w64 GCC 15.2.0. - `agc_driver_graphics` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`: 1/1 passed, 0 `VUID-` lines. This test validates decoded state on the CPU and creates no Vulkan instance, so the validation layer has nothing to insert. - The Witcher 3 (PPSA03977): plain `main` aborts at about 90 s with `depth bias in units other than the depth format (register 0x2de = 0x000001e9)`. With this change the village scene runs; 300 s stable with no crash. ### 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: PPSA03977 #20342; PPSA01487 #21176 (same `0x2de = 0x1e9`/D16 stop) - [x] GPUs tested: AGC: AMD RX 6800 XT (RDNA2, driver 26.10.1), Windows 11 22621; shader recompiler and VideoOut: n/a (state decode only) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-16 05:37:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T05:37:43Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 094fc0db345895ae470edefefa5e5a8994e91618 using the prepared diff and repo_read.py for targeted source reads. No tests were run.

Results

Check Result Note
Changed logic passed Scaling is applied before host depth-format conversion.
Added coverage passed Tests cover both format mismatch directions.
Test execution not run No checks were run during this review.

Findings

Blocking

None.

Non-blocking

None.

Not verified

The changed implementation file was read in full around the modified function. The added test lines were read; the rest of the changed test file was not read. No tests, build, physical console run, or hardware behavior were verified. The author reports Windows 11 and AMD RX 6800 XT testing in the PR description; those runs were not independently verified. Excluded files: none (files.json was unavailable, and the manifest lists both changed files, with the test file's full text excluded from the review folder).

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5915478262 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21345#pullrequestreview-5915478262). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T05:37:43Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `094fc0db345895ae470edefefa5e5a8994e91618` using the prepared diff and `repo_read.py` for targeted source reads. No tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed logic | passed | Scaling is applied before host depth-format conversion. | | Added coverage | passed | Tests cover both format mismatch directions. | | Test execution | not run | No checks were run during this review. | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The changed implementation file was read in full around the modified function. The added test lines were read; the rest of the changed test file was not read. No tests, build, physical console run, or hardware behavior were verified. The author reports Windows 11 and AMD RX 6800 XT testing in the PR description; those runs were not independently verified. Excluded files: none (`files.json` was unavailable, and the manifest lists both changed files, with the test file's full text excluded from the review folder). ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-16 06:48:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T06:48:18Z.

Review: APPROVED


Reviewed — looks good

The depth bias unit conversion and its CPU decode coverage are consistent with the stated goal at head a4288d774c7a06d27f14b3c0c8655c73ddeeeb82; no checks were run in this review.

What I ran

Read the prepared description, commits, manifest, diff, changed State.cpp context, the changed test context, and Pipeline.cpp depth bias call sites through repo_read.py. No test commands were run. The author reports a Windows test run in the PR description; it was not run by this review.

Results

Check Result Note
Code review passed Changed behavior and callers inspected
Tests not run Author-reported run not independently confirmed

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full test file was not read; only lines 3388–3475, including the changed test, were inspected. files.json was not available in the prepared review folder, so exclusions beyond the manifest were not verified. No build, test, GPU, or console run was performed. The PR description reports Windows 11 testing and a 300-second game run; those results were not independently confirmed.

Files read: description.md, commits.md, manifest.json, diff.patch, State.cpp, Graphics.cpp lines 3388–3475, and Pipeline.cpp lines 940–985 and 996–1025. Excluded by the manifest: the remainder of Graphics.cpp, which was too large for the review folder.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5916034155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21345#pullrequestreview-5916034155). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T06:48:18Z. **Review:** APPROVED --- # Reviewed — looks good The depth bias unit conversion and its CPU decode coverage are consistent with the stated goal at head `a4288d774c7a06d27f14b3c0c8655c73ddeeeb82`; no checks were run in this review. ## What I ran Read the prepared description, commits, manifest, diff, changed State.cpp context, the changed test context, and Pipeline.cpp depth bias call sites through `repo_read.py`. No test commands were run. The author reports a Windows test run in the PR description; it was not run by this review. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Changed behavior and callers inspected | | Tests | not run | Author-reported run not independently confirmed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The full test file was not read; only lines 3388–3475, including the changed test, were inspected. `files.json` was not available in the prepared review folder, so exclusions beyond the manifest were not verified. No build, test, GPU, or console run was performed. The PR description reports Windows 11 testing and a 300-second game run; those results were not independently confirmed. Files read: `description.md`, `commits.md`, `manifest.json`, `diff.patch`, `State.cpp`, `Graphics.cpp` lines 3388–3475, and `Pipeline.cpp` lines 940–985 and 996–1025. Excluded by the manifest: the remainder of `Graphics.cpp`, which was too large for the review folder. ## To get this to a good state Nothing is required.
GRG-DA commented 2026-11-16 16:04:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GRG-DA on 2026-11-16T16:04:54Z.

Review: COMMENTED


Checked the fixed direction against the four format pairs:

bias units depth scale
24-bit (0x1e9) D24 1
24-bit (0x1e9) D16 1/256
16-bit (0xf0) D24 256
16-bit (0xf0) D16 1

The first three are covered by the new cases. The fourth — a D16 target with 0x2de = 0xf0, the both-16 combination — is not, and it is the case that would catch a regression where the bias16 == d16 shortcut is lost. Could you add it next to d16Bias? It should leave the constant at 4.0f, with the same slope and clamp assertions.

The direction now matches the units: a 16-bit-unit constant on D24 is c * 2^-16 = (c * 256) * 2^-24, and a 24-bit-unit constant on D16 is c * 2^-24 = (c / 256) * 2^-16. Nothing else in the diff looked wrong.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5923151097 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21345#pullrequestreview-5923151097). Originally posted by [GRG-DA](https://github.com/GRG-DA) on 2026-11-16T16:04:54Z. **Review:** COMMENTED --- Checked the fixed direction against the four format pairs: | bias units | depth | scale | |---|---|---| | 24-bit (`0x1e9`) | D24 | 1 | | 24-bit (`0x1e9`) | D16 | 1/256 | | 16-bit (`0xf0`) | D24 | 256 | | 16-bit (`0xf0`) | D16 | 1 | The first three are covered by the new cases. The fourth — a D16 target with `0x2de = 0xf0`, the both-16 combination — is not, and it is the case that would catch a regression where the `bias16 == d16` shortcut is lost. Could you add it next to `d16Bias`? It should leave the constant at `4.0f`, with the same slope and clamp assertions. The direction now matches the units: a 16-bit-unit constant on D24 is `c * 2^-16 = (c * 256) * 2^-24`, and a 24-bit-unit constant on D16 is `c * 2^-24 = (c / 256) * 2^-16`. Nothing else in the diff looked wrong.
MarcZX10 commented 2026-11-16 16:33:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T16:33:35Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change; the tests were not run in this review, and the documented fixed scaling approximation remains a known limitation.

What I ran

Reviewed head 1309320bc454e750f7805dbb3a53766fb383a3a5 using the prepared diff and repo_read.py source reads. No tests or build commands were run.

Results

Check Result Note
Diff and changed source passed Decoder and scaling callers read
Added tests passed Test setup and assertions read; not executed
Build and runtime checks not run Author-reported results were not rerun

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp:587 uses a fixed 1/256 conversion for float-unit bias on D16. The PR documents that the exact conversion depends on the primitive’s largest-depth exponent; console equivalence remains unmeasured. Consider follow-up work for an exact representation where supported.

Not verified

No build, automated test, or game run was performed. The description’s Windows and Witcher 3 results are author-reported. core/libs/prx/libSceAgcDriver/tests/Graphics.cpp was excluded from the review folder, but its changed lines were read through repo_read.py. No files listed in the changed-file manifest were left unread; no additional files were excluded by rule.

To get this to a good state

Nothing is required. Optional: address the documented depth-dependent conversion approximation in follow-up work.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5923599433 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21345#pullrequestreview-5923599433). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T16:33:35Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change; the tests were not run in this review, and the documented fixed scaling approximation remains a known limitation. ## What I ran Reviewed head `1309320bc454e750f7805dbb3a53766fb383a3a5` using the prepared diff and `repo_read.py` source reads. No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed source | passed | Decoder and scaling callers read | | Added tests | passed | Test setup and assertions read; not executed | | Build and runtime checks | not run | Author-reported results were not rerun | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp:587` uses a fixed `1/256` conversion for float-unit bias on D16. The PR documents that the exact conversion depends on the primitive’s largest-depth exponent; console equivalence remains unmeasured. Consider follow-up work for an exact representation where supported. ## Not verified No build, automated test, or game run was performed. The description’s Windows and Witcher 3 results are author-reported. `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` was excluded from the review folder, but its changed lines were read through `repo_read.py`. No files listed in the changed-file manifest were left unread; no additional files were excluded by rule. ## To get this to a good state Nothing is required. Optional: address the documented depth-dependent conversion approximation in follow-up work.
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!21345
No description provided.