feat(agc): average the samples of a 4_4_4_4 unorm CB resolve #24049

Open
Colewiz7 wants to merge 2 commits from upstream-pr/24049 into main
Colewiz7 commented 2026-11-20 02:15:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Colewiz7 on 2026-11-20T02:15:33Z.


What

A CB resolve of a multisampled 4_4_4_4 unorm color target was refused (CB resolves of 4_4_4_4 unorm color targets are unsupported). It now runs through the fragment pass #23225 added for 11_11_10 float, with two new variants of FirstSample.frag. Each averages the four 4-bit fields over the samples:

CB_COLOR_INFO.ROUND_MODE resolved field
0 (sum + n / 2) / n, halves round up
1 sum / n, truncated

That is the rule measured on a 7800X3D iGPU (gfx1036) with Mesa 26.0.6 RADV's hardware resolve (method=HW), RB+ off, VK_FORMAT_R4G4B4A4_UNORM_PACK16, 256x256. Per-sample codes were rendered and read back through 1-sample draws, and the rule matched every one of the 262,144 fields for 2, 4 and 8 samples in each mode. Rounding halves to even fails, and so does averaging the normalized floats.

The probe set ROUND_MODE on both targets at once, so a resolve between 4_4_4_4 targets whose ROUND_MODE or layout differ is still refused.

FirstSampleCopy's averagePacked flag becomes PackedAverage (None, Float11_11_10, Unorm4_4_4_4, Unorm4_4_4_4Truncated), and MultisampleTarget keeps one resolve pass per kind. The debt fragment changes the "4_4_4_4 CB resolves" entry.

Tested

Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, main d50640e264 with #23258's commits first.

  • agc_driver_packed_unorm4444_color_target now resolves 2-, 4- and 8-sample tiled targets in both modes and compares every pixel with the rule above. The expected words come from the codes each sample was drawn with. agc_graphics_profile_draw checks that the resolve decodes, and that a mismatched ROUND_MODE is refused.
  • With the half-up step removed from the shader, the test fails on both GPUs: a CB resolve of a two-sample 4_4_4_4 unorm target with ROUND_MODE 0: pixel (0, 0) inside the scissor holds 0x774e, expected 0x884f.
  • agc_driver_packed_unorm4444_color_target solo: 3/3 on each GPU.
  • agc_driver_packed_unorm4444_color_target, agc_driver_packed_unorm_color_target, agc_driver_packed_float_color_target and agc_graphics_profile_draw with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer and ctest -V: 4/4 on both GPUs, 0 VUID- lines.
  • ctest -R '^agc' (1965 tests): the only failure is agc_driver_image_table_packed_guards, which fails on main too (#22512).

Not tested: gfx1013, Windows, NVIDIA, and which target's ROUND_MODE the hardware applies when the two differ.

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: #23258
  • 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:5406512403 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24049). Originally posted by [Colewiz7](https://github.com/Colewiz7) on 2026-11-20T02:15:33Z. --- ### What A CB resolve of a multisampled 4_4_4_4 unorm color target was refused (`CB resolves of 4_4_4_4 unorm color targets are unsupported`). It now runs through the fragment pass #23225 added for 11_11_10 float, with two new variants of `FirstSample.frag`. Each averages the four 4-bit fields over the samples: | `CB_COLOR_INFO.ROUND_MODE` | resolved field | |---|---| | 0 | `(sum + n / 2) / n`, halves round up | | 1 | `sum / n`, truncated | That is the rule measured on a 7800X3D iGPU (gfx1036) with Mesa 26.0.6 RADV's hardware resolve (`method=HW`), RB+ off, `VK_FORMAT_R4G4B4A4_UNORM_PACK16`, 256x256. Per-sample codes were rendered and read back through 1-sample draws, and the rule matched every one of the 262,144 fields for 2, 4 and 8 samples in each mode. Rounding halves to even fails, and so does averaging the normalized floats. The probe set `ROUND_MODE` on both targets at once, so a resolve between 4_4_4_4 targets whose `ROUND_MODE` or layout differ is still refused. `FirstSampleCopy`'s `averagePacked` flag becomes `PackedAverage` (`None`, `Float11_11_10`, `Unorm4_4_4_4`, `Unorm4_4_4_4Truncated`), and `MultisampleTarget` keeps one resolve pass per kind. The debt fragment changes the "4_4_4_4 CB resolves" entry. ### Tested Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, `main` `d50640e264` with #23258's commits first. - `agc_driver_packed_unorm4444_color_target` now resolves 2-, 4- and 8-sample tiled targets in both modes and compares every pixel with the rule above. The expected words come from the codes each sample was drawn with. `agc_graphics_profile_draw` checks that the resolve decodes, and that a mismatched `ROUND_MODE` is refused. - With the half-up step removed from the shader, the test fails on both GPUs: `a CB resolve of a two-sample 4_4_4_4 unorm target with ROUND_MODE 0: pixel (0, 0) inside the scissor holds 0x774e, expected 0x884f`. - `agc_driver_packed_unorm4444_color_target` solo: 3/3 on each GPU. - `agc_driver_packed_unorm4444_color_target`, `agc_driver_packed_unorm_color_target`, `agc_driver_packed_float_color_target` and `agc_graphics_profile_draw` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer` and `ctest -V`: 4/4 on both GPUs, 0 `VUID-` lines. - `ctest -R '^agc'` (1965 tests): the only failure is `agc_driver_image_table_packed_guards`, which fails on `main` too (#22512). Not tested: gfx1013, Windows, NVIDIA, and which target's `ROUND_MODE` the hardware applies when the two differ. ### 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: #23258 - [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-20 10:14:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T10:14:06Z.

Review: COMMENTED


Reviewed — comments

The shader and state changes look consistent with the stated behavior, but review coverage is incomplete because one changed file was excluded and not all included changed files were inspected.

What I ran

Reviewed head 43cba43a37853d35c3f0f3238a948d1d37da76af using the prepared diff and repo_read.py; no tests or build commands were run.

Results

Check Result Note
Diff and targeted source review passed Main resolve and conversion paths inspected
Tests and build not run Relied on author-reported results

Findings

Blocking

None identified in the inspected code.

Non-blocking

The PR changes float 11_11_10 NaN packing and rounding behavior alongside the 4_4_4_4 work. Its description and tests give a separate measurement basis for that change, but this review did not inspect every related implementation and test path.

Not verified

core/libs/prx/libSceAgcDriver/tests/Graphics.cpp was excluded from the review bundle because it was too large; only its changed resolve-test hunk was read. Other included changed files not listed as inspected were not fully reviewed. The author-reported test results were not independently run. The review did not verify behavior on gfx1013, Windows, NVIDIA, or a physical console.

Files read: review/description.md, review/commits.md, review/manifest.json, review/diff.patch; selected ranges from core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp, core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp, core/libs/prx/libSceAgcDriver/Graphics/shaders/FirstSample.frag, core/libs/prx/libSceAgcDriver/Graphics/src/FirstSampleCopy.cpp, core/libs/prx/libSceAgcDriver/tests/Graphics.cpp, core/shader/recompiler/Recompiler.hpp, core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp, and core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvFormatConvert.cpp.

To get this to a good state

Nothing is required. Optional: complete review of the remaining changed files and independently run the reported checks before making a formal approval decision.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5991011520 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24049#pullrequestreview-5991011520). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T10:14:06Z. **Review:** COMMENTED --- # Reviewed — comments The shader and state changes look consistent with the stated behavior, but review coverage is incomplete because one changed file was excluded and not all included changed files were inspected. ## What I ran Reviewed head `43cba43a37853d35c3f0f3238a948d1d37da76af` using the prepared diff and `repo_read.py`; no tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Main resolve and conversion paths inspected | | Tests and build | not run | Relied on author-reported results | ## Findings ### Blocking None identified in the inspected code. ### Non-blocking The PR changes float 11_11_10 NaN packing and rounding behavior alongside the 4_4_4_4 work. Its description and tests give a separate measurement basis for that change, but this review did not inspect every related implementation and test path. ## Not verified `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` was excluded from the review bundle because it was too large; only its changed resolve-test hunk was read. Other included changed files not listed as inspected were not fully reviewed. The author-reported test results were not independently run. The review did not verify behavior on gfx1013, Windows, NVIDIA, or a physical console. Files read: `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`; selected ranges from `core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp`, `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp`, `core/libs/prx/libSceAgcDriver/Graphics/shaders/FirstSample.frag`, `core/libs/prx/libSceAgcDriver/Graphics/src/FirstSampleCopy.cpp`, `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp`, `core/shader/recompiler/Recompiler.hpp`, `core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp`, and `core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvFormatConvert.cpp`. ## To get this to a good state Nothing is required. Optional: complete review of the remaining changed files and independently run the reported checks before making a formal approval decision.
ligmaSec commented 2026-12-03 21:56:54 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Trial merging this head with main 63db72fb61 conflicts in the resolve implementation, graphics fixture and three shader format/serialization files. Please reconcile the packed mode through both the color export and resolve paths in the same rebase. Keep coverage for integer tie-up and truncation at 2x, 4x and 8x, plus the refusal when the source and destination modes differ. The paired Vulkan run is pending the merge resolution.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179304205 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24049#pullrequestreview-6179304205). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T21:56:54Z. **Review:** COMMENTED --- Trial merging this head with `main` `63db72fb61` conflicts in the resolve implementation, graphics fixture and three shader format/serialization files. Please reconcile the packed mode through both the color export and resolve paths in the same rebase. Keep coverage for integer tie-up and truncation at 2x, 4x and 8x, plus the refusal when the source and destination modes differ. The paired Vulkan run is pending the merge resolution. 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/24049:upstream-pr/24049'
git switch 'upstream-pr/24049'

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