feat(agc): accept conservative Z export in DB_SHADER_CONTROL #752

Merged
Celegans12 merged 1 commit from upstream-pr/752 into main 2026-10-05 23:13:21 +00:00
Celegans12 commented 2026-10-05 20:40:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-05T20:40:03Z.


What

A nonzero DB_SHADER_CONTROL.CONSERVATIVE_Z_EXPORT (bits 13-14) was rejected by DecodeState and the draw precheck (depth export, shader coverage or ordered fragment execution) and by DecodePixelStageInfo (AGC graphics: DB_SHADER_CONTROL.CONSERVATIVE_Z_EXPORT is unsupported).

  • Bits 13-14 pass the DecodeState/precheck mask and become the pixel stage field ConservativeZExport: 0 EXPORT_ANY_Z, 1 EXPORT_LESS_THAN_Z, 2 EXPORT_GREATER_THAN_Z, as in Mesa's GFX10.3 register database (enum, field). The reserved value 3 still throws.
  • A pixel shader that writes FragDepth declares DepthLess (1) or DepthGreater (2) next to DepthReplacing, the inverse of RADV's mapping (radv_shader.c, spirv_to_nir.c). Without a Z export the depth is the interpolated Z, which keeps either promise, so nothing is declared.
  • Vulkan lets these modes only add a depth test of the interpolated depth before shading (fragops.adoc), so a shader that keeps the promise renders the same. TechnicalDebt (Functional): what a shader that breaks it gets is up to the host driver.
  • The field is in the recompile cache key, the draw key and the serialized request (version 7). ValidateShaders accepts both modes. Drawing a depth-exporting pixel shader still needs #375 (Z_EXPORT_ENABLE, SPI_SHADER_Z_FORMAT, FragDepth, DepthReplacing).
  • PPSA26344 v1.008: pixel shader 37a91497897c68dd (all_shaders.xpps, 2 instances) has DB_SHADER_CONTROL = 0x2021 and ends with v_sub_f32 v0, v2, v0 (0x08000102, v2 = POS_Z) and exp mrtz v0 done vm (0xf8001881 0x00000000).
  • Overlaps (textual only): #375, #423 and #448 edit the same ValidateShaders line. #448 also adds a pixel field at the same places in CacheKey.hpp, ShaderStageInputInfo.hpp and ShaderInputInfoBuilder.cpp and bumps the same serializer version lines. Their State.cpp and ShaderInputState.cpp edits merge cleanly.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 681f83e5: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 316/316 tests pass (ctest --output-on-failure)
  • New conservativeZExportTests in agc_driver_graphics: with a shader that exports POS_Z as MRTZ, DB_SHADER_CONTROL 0x21, 0x2021, 0x4021 and 0x2020 give DepthReplacing, plus DepthLess, plus DepthGreater, and no depth mode, also after a serializer round trip, with distinct cache keys; DecodeState and the precheck accept 0x2020 and 0x4020; 0x6021 throws; ValidateShaders accepts DepthLess and DepthGreater and still rejects DepthUnchanged. On main it fails with the DecodePixelStageInfo message above.
  • PPSA26344 v1.008, offline over all 10,504 extracted pixel shaders with the driver's DecodePixelStageInfo: only 37a91497897c68dd changes. It now decodes, and its SPIR-V gains OpExecutionMode DepthLess and passes spirv-val. The other 10,503 give the same result and SPIR-V size. Not yet run in game.
  • Not tested: PPSA21564 and Dreaming Sarah (expect a PPSA21564 gate), Linux (CI), console behaviour.

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 (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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4750515299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/752). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-05T20:40:03Z. --- ### What A nonzero DB_SHADER_CONTROL.CONSERVATIVE_Z_EXPORT (bits 13-14) was rejected by `DecodeState` and the draw precheck (`depth export, shader coverage or ordered fragment execution`) and by `DecodePixelStageInfo` (`AGC graphics: DB_SHADER_CONTROL.CONSERVATIVE_Z_EXPORT is unsupported`). - Bits 13-14 pass the `DecodeState`/precheck mask and become the pixel stage field `ConservativeZExport`: 0 `EXPORT_ANY_Z`, 1 `EXPORT_LESS_THAN_Z`, 2 `EXPORT_GREATER_THAN_Z`, as in Mesa's GFX10.3 register database ([enum](https://gitlab.freedesktop.org/mesa/mesa/-/blob/dfff31fb57c7edf18e87c48cf51c7ca8be2dd45d/src/amd/registers/gfx103.json#L197-204), [field](https://gitlab.freedesktop.org/mesa/mesa/-/blob/dfff31fb57c7edf18e87c48cf51c7ca8be2dd45d/src/amd/registers/gfx103.json#L12765)). The reserved value 3 still throws. - A pixel shader that writes `FragDepth` declares `DepthLess` (1) or `DepthGreater` (2) next to `DepthReplacing`, the inverse of RADV's mapping ([radv_shader.c](https://gitlab.freedesktop.org/mesa/mesa/-/blob/dfff31fb57c7edf18e87c48cf51c7ca8be2dd45d/src/amd/vulkan/radv_shader.c#L2011-2015), [spirv_to_nir.c](https://gitlab.freedesktop.org/mesa/mesa/-/blob/dfff31fb57c7edf18e87c48cf51c7ca8be2dd45d/src/compiler/spirv/spirv_to_nir.c#L5962-5969)). Without a Z export the depth is the interpolated Z, which keeps either promise, so nothing is declared. - Vulkan lets these modes only add a depth test of the interpolated depth before shading ([fragops.adoc](https://github.com/KhronosGroup/Vulkan-Docs/blob/e4e53e4b31e13eeaee1ad99fb940aa72b2ec1b14/chapters/fragops.adoc#L159-L183)), so a shader that keeps the promise renders the same. TechnicalDebt (Functional): what a shader that breaks it gets is up to the host driver. - The field is in the recompile cache key, the draw key and the serialized request (version 7). `ValidateShaders` accepts both modes. Drawing a depth-exporting pixel shader still needs #375 (`Z_EXPORT_ENABLE`, `SPI_SHADER_Z_FORMAT`, `FragDepth`, `DepthReplacing`). - PPSA26344 v1.008: pixel shader `37a91497897c68dd` (`all_shaders.xpps`, 2 instances) has `DB_SHADER_CONTROL = 0x2021` and ends with `v_sub_f32 v0, v2, v0` (`0x08000102`, v2 = POS_Z) and `exp mrtz v0 done vm` (`0xf8001881 0x00000000`). - Overlaps (textual only): #375, #423 and #448 edit the same `ValidateShaders` line. #448 also adds a pixel field at the same places in `CacheKey.hpp`, `ShaderStageInputInfo.hpp` and `ShaderInputInfoBuilder.cpp` and bumps the same serializer version lines. Their `State.cpp` and `ShaderInputState.cpp` edits merge cleanly. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 681f83e5: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 316/316 tests pass (`ctest --output-on-failure`) - New `conservativeZExportTests` in `agc_driver_graphics`: with a shader that exports POS_Z as MRTZ, DB_SHADER_CONTROL 0x21, 0x2021, 0x4021 and 0x2020 give `DepthReplacing`, plus `DepthLess`, plus `DepthGreater`, and no depth mode, also after a serializer round trip, with distinct cache keys; `DecodeState` and the precheck accept 0x2020 and 0x4020; 0x6021 throws; `ValidateShaders` accepts `DepthLess` and `DepthGreater` and still rejects `DepthUnchanged`. On `main` it fails with the `DecodePixelStageInfo` message above. - PPSA26344 v1.008, offline over all 10,504 extracted pixel shaders with the driver's `DecodePixelStageInfo`: only `37a91497897c68dd` changes. It now decodes, and its SPIR-V gains `OpExecutionMode DepthLess` and passes `spirv-val`. The other 10,503 give the same result and SPIR-V size. Not yet run in game. - Not tested: PPSA21564 and Dreaming Sarah (expect a PPSA21564 gate), Linux (CI), console behaviour. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-05 21:03:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T21:03:54Z.


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
#375 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp L371
#423 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp L371
#448 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp L371
core/shader/recompiler/CacheKey.hpp L142
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp L680, L704
core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp L185
core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp L139
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6002885358 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/752#issuecomment-6002885358). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T21:03:54Z. --- <!-- 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 | |---|---|---|---| | #375 | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp` [L371](https://github.com/boykopovar/AnyPS5/blob/d3e4edf15b0254166faff138a3ab18e3dd69b95f/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp#L371) | | | | #423 | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp` [L371](https://github.com/boykopovar/AnyPS5/blob/d3e4edf15b0254166faff138a3ab18e3dd69b95f/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp#L371) | | | | #448 | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp` [L371](https://github.com/boykopovar/AnyPS5/blob/d3e4edf15b0254166faff138a3ab18e3dd69b95f/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp#L371)<br>`core/shader/recompiler/CacheKey.hpp` [L142](https://github.com/boykopovar/AnyPS5/blob/d3e4edf15b0254166faff138a3ab18e3dd69b95f/core/shader/recompiler/CacheKey.hpp#L142)<br>`core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp` [L680](https://github.com/boykopovar/AnyPS5/blob/d3e4edf15b0254166faff138a3ab18e3dd69b95f/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp#L680), [L704](https://github.com/boykopovar/AnyPS5/blob/d3e4edf15b0254166faff138a3ab18e3dd69b95f/core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp#L704)<br>`core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp` [L185](https://github.com/boykopovar/AnyPS5/blob/d3e4edf15b0254166faff138a3ab18e3dd69b95f/core/shader/recompiler/Optimization/include/Optimization/ShaderStageInputInfo.hpp#L185)<br>`core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp` [L139](https://github.com/boykopovar/AnyPS5/blob/d3e4edf15b0254166faff138a3ab18e3dd69b95f/core/shader/recompiler/Translation/src/ShaderInputInfoBuilder.cpp#L139) | | |
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!752
No description provided.