feat(agc): truncate exports into 4_4_4_4 unorm targets with ROUND_MODE set #23258

Open
Colewiz7 wants to merge 1 commit from upstream-pr/23258 into main
Colewiz7 commented 2026-11-18 21:13:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Colewiz7 on 2026-11-18T21:13:26Z.


What

A 4_4_4_4 UNORM color target with CB_COLOR_INFO.ROUND_MODE set is drawn with truncated exports instead of refused (truncating (ROUND_MODE) 4_4_4_4 unorm color targets are unsupported).

State.cpp gives such a target the new packing Unorm4_4_4_4Truncated. Its exports and partial-write merges pack each component as floor(clamp(v, 0, 1) * 15), with NaN to 0. That is NormStoreBits without its rounding step. Without ROUND_MODE, packing still rounds to nearest even, as before.

Measured on a 7800X3D iGPU (gfx1036) with a local Mesa 26.0.6 RADV patched for RB+ off (gfx1013 has none) and 32_ABGR exports, into VK_FORMAT_R4G4B4A4_UNORM_PACK16:

export ROUND_MODE 0 ROUND_MODE 1
262,144 components, half of them within 0.001/15 of a midpoint nearest, all truncated, all
0x3d888888 / 0x3d888889 (either side of 1/15) 1 / 1 0 / 1
0x3f7fffff (0.99999994) 15 14
NaN (any payload), -inf, -1, -0 0 0
+inf, 1.00000012, 2 15 15

The same runs on 11_11_10 float show the bit has no effect there (#23206).

Tested

Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, main 67d3465feb. The branch carries #23206's commit first, since both change PackExport.

  • agc_driver_packed_unorm4444_color_target runs its goldens again on a target with ROUND_MODE set, plus a case of 0x3d888888, 0x3d888889, 0x3f088888 and 0x3f088889 (0x1188 rounded, 0x0178 truncated). agc_driver_packed_unorm4444_partial_write replays its nine merges on a truncating target. agc_graphics_profile_draw decodes the target as Unorm4_4_4_4Truncated, and its invalid-packing check now uses the value after the last one.
  • With main's State.cpp, emitter and converter, both new passes fail on both GPUs with truncating (ROUND_MODE) 4_4_4_4 unorm color targets are unsupported. With only the truncation step removed, they fail with holds 0xf804, expected 0xf703 (export) and holds 0x3f84, expected 0x3f73 (partial write).
  • The three agc_driver_packed_unorm4444_* tests, agc_driver_packed_float_color_target, agc_driver_packed_float_blend and agc_graphics_profile_draw, run with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer and ctest -V: 6/6 on both GPUs, layer 1.4.363.1 inserted, 0 VUID- lines.
  • ctest -R '^agc' (1936 tests): the failures match main's on each GPU.

Not tested: gfx1013, Windows, NVIDIA. PS4 (GCN) targets don't read ROUND_MODE, which the debt entry records.

Overlap: #22609 also appends ColorExportPacking values, so whichever merges second renumbers the range checks.

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: #23206
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31) and AMD Ryzen 7 7800X3D iGPU (RADV RAPHAEL_MENDOCINO), Mesa 26.2.6, Linux 7.3.4
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5384198752 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23258). Originally posted by [Colewiz7](https://github.com/Colewiz7) on 2026-11-18T21:13:26Z. --- ### What A 4_4_4_4 UNORM color target with `CB_COLOR_INFO.ROUND_MODE` set is drawn with truncated exports instead of refused (`truncating (ROUND_MODE) 4_4_4_4 unorm color targets are unsupported`). `State.cpp` gives such a target the new packing `Unorm4_4_4_4Truncated`. Its exports and partial-write merges pack each component as `floor(clamp(v, 0, 1) * 15)`, with NaN to 0. That is `NormStoreBits` without its rounding step. Without `ROUND_MODE`, packing still rounds to nearest even, as before. Measured on a 7800X3D iGPU (gfx1036) with a local Mesa 26.0.6 RADV patched for RB+ off (gfx1013 has none) and 32_ABGR exports, into `VK_FORMAT_R4G4B4A4_UNORM_PACK16`: | export | `ROUND_MODE` 0 | `ROUND_MODE` 1 | |---|---|---| | 262,144 components, half of them within 0.001/15 of a midpoint | nearest, all | truncated, all | | `0x3d888888` / `0x3d888889` (either side of 1/15) | 1 / 1 | 0 / 1 | | `0x3f7fffff` (0.99999994) | 15 | 14 | | NaN (any payload), -inf, -1, -0 | 0 | 0 | | +inf, 1.00000012, 2 | 15 | 15 | The same runs on 11_11_10 float show the bit has no effect there (#23206). ### Tested Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, `main` `67d3465feb`. The branch carries #23206's commit first, since both change `PackExport`. - `agc_driver_packed_unorm4444_color_target` runs its goldens again on a target with `ROUND_MODE` set, plus a case of `0x3d888888`, `0x3d888889`, `0x3f088888` and `0x3f088889` (`0x1188` rounded, `0x0178` truncated). `agc_driver_packed_unorm4444_partial_write` replays its nine merges on a truncating target. `agc_graphics_profile_draw` decodes the target as `Unorm4_4_4_4Truncated`, and its invalid-packing check now uses the value after the last one. - With `main`'s `State.cpp`, emitter and converter, both new passes fail on both GPUs with `truncating (ROUND_MODE) 4_4_4_4 unorm color targets are unsupported`. With only the truncation step removed, they fail with `holds 0xf804, expected 0xf703` (export) and `holds 0x3f84, expected 0x3f73` (partial write). - The three `agc_driver_packed_unorm4444_*` tests, `agc_driver_packed_float_color_target`, `agc_driver_packed_float_blend` and `agc_graphics_profile_draw`, run with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer` and `ctest -V`: 6/6 on both GPUs, layer 1.4.363.1 inserted, 0 `VUID-` lines. - `ctest -R '^agc'` (1936 tests): the failures match `main`'s on each GPU. Not tested: gfx1013, Windows, NVIDIA. PS4 (GCN) targets don't read `ROUND_MODE`, which the debt entry records. Overlap: #22609 also appends `ColorExportPacking` values, so whichever merges second renumbers the range checks. ### 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) 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: #23206 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31) and AMD Ryzen 7 7800X3D iGPU (RADV RAPHAEL_MENDOCINO), Mesa 26.2.6, Linux 7.3.4 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-19 05:42:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T05:42:52Z.

Review: APPROVED


Reviewed — looks good

The inspected implementation supports truncating 4_4_4_4 UNORM exports and partial writes when ROUND_MODE is set; no blocking defect was verified at head 4636f218a153a2d470ae2c5dc8fd7edbbb6b1b5d.

What I ran

No commands or tests were run. I read the prepared diff and manifest, then inspected targeted source ranges through repo_read.py at the pinned head.

Results

Check Result Note
Diff and manifest review passed Prepared review inputs read
Targeted code inspection passed Packing, state decode, merge, and serializer paths
Tests not run Execution results in the description are author-reported

Findings

Blocking

None verified in the inspected code.

Non-blocking

None.

Not verified

I read all changed files marked included: true in the manifest. core/libs/prx/libSceAgcDriver/tests/Graphics.cpp was excluded from review/files/ because it was too large for the review folder; I inspected its changed lines at the pinned head. Its full text was not read. Tests were not run; the reported GPU and ctest results were not independently verified. Graphics behavior on gfx1013, Windows, NVIDIA, and PS4 hardware was not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5969894848 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23258#pullrequestreview-5969894848). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-19T05:42:52Z. **Review:** APPROVED --- # Reviewed — looks good The inspected implementation supports truncating 4_4_4_4 UNORM exports and partial writes when `ROUND_MODE` is set; no blocking defect was verified at head `4636f218a153a2d470ae2c5dc8fd7edbbb6b1b5d`. ## What I ran No commands or tests were run. I read the prepared diff and manifest, then inspected targeted source ranges through `repo_read.py` at the pinned head. ## Results | Check | Result | Note | |---|---|---| | Diff and manifest review | passed | Prepared review inputs read | | Targeted code inspection | passed | Packing, state decode, merge, and serializer paths | | Tests | not run | Execution results in the description are author-reported | ## Findings ### Blocking None verified in the inspected code. ### Non-blocking None. ## Not verified I read all changed files marked `included: true` in the manifest. `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` was excluded from `review/files/` because it was too large for the review folder; I inspected its changed lines at the pinned head. Its full text was not read. Tests were not run; the reported GPU and `ctest` results were not independently verified. Graphics behavior on gfx1013, Windows, NVIDIA, and PS4 hardware was not verified. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-20 04:53:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T04:53:49Z.

Review: APPROVED


Reviewed — looks good

The changed packing path and its serialization and merge handling look consistent in the inspected code; hardware test results are author-reported and were not run in this review.

What I ran

Reviewed head ba9b82437dff18c5720b2e624d3e970858a142b1 using the prepared diff and repo_read.py at the pinned head. No commands or tests were run.

Read: description.md, commits.md, manifest.json, diff.patch; changed repository files State.cpp, Graphics.cpp (lines 12500–12600), PackedFloatColorTarget.cpp, PackedUnorm4444ColorTarget.cpp, PackedUnorm4444PartialWrite.cpp, RequestSerializer.cpp, FragmentOutputSpecialization.hpp, Recompiler.hpp, SpirvEmitterHelpers.hpp, SpirvFormatConvert.cpp, SpirvModuleEmitter.cpp, ShaderInputInfoBuilder.cpp, and both added debt notes. The full Graphics.cpp was excluded from the review folder; I read only the relevant region through the reader. No other changed files were excluded.

Results

Check Result Note
Change inspection passed Relevant changed paths inspected
Tests not run No local checks performed
Hardware claims not run Reported runs not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

The reported GPU test runs and their environments were not independently verified. The full Graphics.cpp was not read; only the modified target test region was inspected. The implementation was not built or tested here, and behavior on gfx1013, Windows, and NVIDIA was not confirmed.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5987686449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23258#pullrequestreview-5987686449). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T04:53:49Z. **Review:** APPROVED --- # Reviewed — looks good The changed packing path and its serialization and merge handling look consistent in the inspected code; hardware test results are author-reported and were not run in this review. ## What I ran Reviewed head `ba9b82437dff18c5720b2e624d3e970858a142b1` using the prepared diff and `repo_read.py` at the pinned head. No commands or tests were run. Read: `description.md`, `commits.md`, `manifest.json`, `diff.patch`; changed repository files `State.cpp`, `Graphics.cpp` (lines 12500–12600), `PackedFloatColorTarget.cpp`, `PackedUnorm4444ColorTarget.cpp`, `PackedUnorm4444PartialWrite.cpp`, `RequestSerializer.cpp`, `FragmentOutputSpecialization.hpp`, `Recompiler.hpp`, `SpirvEmitterHelpers.hpp`, `SpirvFormatConvert.cpp`, `SpirvModuleEmitter.cpp`, `ShaderInputInfoBuilder.cpp`, and both added debt notes. The full `Graphics.cpp` was excluded from the review folder; I read only the relevant region through the reader. No other changed files were excluded. ## Results | Check | Result | Note | |---|---|---| | Change inspection | passed | Relevant changed paths inspected | | Tests | not run | No local checks performed | | Hardware claims | not run | Reported runs not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The reported GPU test runs and their environments were not independently verified. The full `Graphics.cpp` was not read; only the modified target test region was inspected. The implementation was not built or tested here, and behavior on gfx1013, Windows, and NVIDIA was not confirmed. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 21:59:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:59:19Z.

Review: COMMENTED


The current head conflicts with main 63db72fb61 in the graphics tests and shader-format declarations and serializer. Please preserve both the full-write and masked merge routes to 4_4_4_4 truncation when reconciling #23206. The paired cases should keep ties-to-even as the clear ROUND_MODE control, since the partial-write path can otherwise mask a regression in the packing choice.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179341788 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23258#pullrequestreview-6179341788). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T21:59:19Z. **Review:** COMMENTED --- The current head conflicts with `main` `63db72fb61` in the graphics tests and shader-format declarations and serializer. Please preserve both the full-write and masked merge routes to 4_4_4_4 truncation when reconciling #23206. The paired cases should keep ties-to-even as the clear ROUND_MODE control, since the partial-write path can otherwise mask a regression in the packing choice. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/23258:upstream-pr/23258'
git switch 'upstream-pr/23258'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/23258'
git switch 'upstream-pr/23258'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/23258'
git switch 'upstream-pr/23258'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/23258'
git switch 'main'
git merge --squash 'upstream-pr/23258'
git switch 'main'
git merge --ff-only 'upstream-pr/23258'
git switch 'main'
git merge 'upstream-pr/23258'
git push origin 'main'
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!23258
No description provided.