fix(libSceAgcDriver): store 32-bit exports into narrow UINT targets as Navi21 does #15693

Merged
Tamalero merged 1 commit from upstream-pr/15693 into main 2026-11-16 05:37:29 +00:00
Tamalero commented 2026-11-04 06:57:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-11-04T06:57:18Z.


What

A raw 32-bit export into an 8- or 16-bit UINT color target is passed to the attachment unchanged on main. Vulkan leaves an integer write that does not fit the channel undefined, and the drivers I tried saturate it. Navi21 hardware does something different, and it depends on the export format:

Export format What an 8- or 16-bit UINT channel stores on Navi21 This PR
32_R the word's low bits (0x12345678 → 0x78 / 0x5678, 0x100 → 0x00) UintMask8 / UintMask16: word & 0xff / 0xffff
32_GR, 32_ABGR the word clamped as an unsigned integer (0x7f → 0x7f, 0x100 → 0xff, 0x80000000 → 0xff) UintClamp8 / UintClamp16, the clamp #14243 uses for FP16_ABGR
32_AR no consistent result unchanged
  • Measurement. Two Radeon PRO V620s (Navi21, RDNA2) with RADV forced to each SPI_SHADER_COL_FORMAT, the same method as #11513. The ISA shows the raw words exported with no compiler clamp. Sixteen words from 0 to 0xffffffff went into R8, R16, RG8, RG16, RGBA8 and RGBA16 UINT targets, with identical results on both GPUs. This is desktop RDNA2, not the console.
  • Code. The packing is picked per export format in State.cpp. SelectExportPacking masks for 32_R and clamps for 32_GR, 32_ABGR and FP16_ABGR; both read the target width from the packing specialization constant. The new packings travel in targetExportPacking like the existing ones.
  • Debt entry. The "clamp or truncate" gap is cut to what is still open: 32_AR, blending into integer targets, and the console itself.

This follows #14243, which added the clamp for FP16_ABGR.

Tested

  • Paired validation run (CONTRIBUTING), RTX 4090, NVIDIA 615.78.08, Linux 7.3: ctest -V -R '^(agc_driver_uint_color_target|agc_driver_graphics)$' with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, on main 5b1d381d5a and on this branch (0ce0944491). Both pass. Neither log reports was not found but was requested by env var VK_INSTANCE_LAYERS. Both report only VUID-vkCreateDevice-ppEnabledExtensionNames-01387 at device creation.
  • agc_driver_uint_color_target_tests:
    • Words wider than the channel, now including 0x1ff and 0x12345678, go into R8_UINT and R16_UINT (32_R), R8G8_UINT (32_GR), and R8G8B8A8_UINT and R16G16B16A16_UINT (32_ABGR).
    • Each masking and clamping packing is also drawn into R32_UINT and R32G32B32A32_UINT, where the driver cannot saturate.
  • agc_driver_graphics_tests: uintTargetTests decodes each export format into 8- and 16-bit targets to its packing (32_AR keeps Uint). The invalid-packing check now uses 9.
  • Negative controls, each built and run on its own:
    Variant RTX 4090 Radeon PRO V620, RADV Mesa 25.2.8 llvmpipe, Mesa 25.2.8
    this branch passes passes passes
    masking removed fails: 0xff stored, 0x00 expected (32_R, R8_UINT) fails, same fails, same
    clamp limited to FP16_ABGR fails: 0x1ff stored, 0xff expected (32_ABGR, UintClamp8) fails, same fails, same

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 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: none
  • GPUs tested: NVIDIA GeForce RTX 4090 (615.78.08, Linux 7.3 CachyOS); AMD Radeon PRO V620 (RADV Mesa 25.2.8, Ubuntu 24.04); llvmpipe (Mesa 25.2.8, Ubuntu 24.04)
  • AI-assisted: yes

Tested and written by Claude (AI assistant) on a contributor's machine.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5150258328 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15693). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-11-04T06:57:18Z. --- ### What A raw 32-bit export into an 8- or 16-bit UINT color target is passed to the attachment unchanged on `main`. Vulkan leaves an integer write that does not fit the channel undefined, and the drivers I tried saturate it. Navi21 hardware does something different, and it depends on the export format: | Export format | What an 8- or 16-bit UINT channel stores on Navi21 | This PR | |---|---|---| | `32_R` | the word's low bits (`0x12345678` → `0x78` / `0x5678`, `0x100` → `0x00`) | `UintMask8` / `UintMask16`: `word & 0xff` / `0xffff` | | `32_GR`, `32_ABGR` | the word clamped as an unsigned integer (`0x7f` → `0x7f`, `0x100` → `0xff`, `0x80000000` → `0xff`) | `UintClamp8` / `UintClamp16`, the clamp #14243 uses for `FP16_ABGR` | | `32_AR` | no consistent result | unchanged | - **Measurement.** Two Radeon PRO V620s (Navi21, RDNA2) with RADV forced to each `SPI_SHADER_COL_FORMAT`, the same method as #11513. The ISA shows the raw words exported with no compiler clamp. Sixteen words from `0` to `0xffffffff` went into `R8`, `R16`, `RG8`, `RG16`, `RGBA8` and `RGBA16` UINT targets, with identical results on both GPUs. This is desktop RDNA2, not the console. - **Code.** The packing is picked per export format in `State.cpp`. `SelectExportPacking` masks for `32_R` and clamps for `32_GR`, `32_ABGR` and `FP16_ABGR`; both read the target width from the packing specialization constant. The new packings travel in `targetExportPacking` like the existing ones. - **Debt entry.** The "clamp or truncate" gap is cut to what is still open: `32_AR`, blending into integer targets, and the console itself. This follows #14243, which added the clamp for `FP16_ABGR`. ### Tested - **Paired validation run** (CONTRIBUTING), RTX 4090, NVIDIA 615.78.08, Linux 7.3: `ctest -V -R '^(agc_driver_uint_color_target|agc_driver_graphics)$'` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, on `main` `5b1d381d5a` and on this branch (`0ce0944491`). Both pass. Neither log reports `was not found but was requested by env var VK_INSTANCE_LAYERS`. Both report only `VUID-vkCreateDevice-ppEnabledExtensionNames-01387` at device creation. - **`agc_driver_uint_color_target_tests`:** - Words wider than the channel, now including `0x1ff` and `0x12345678`, go into `R8_UINT` and `R16_UINT` (`32_R`), `R8G8_UINT` (`32_GR`), and `R8G8B8A8_UINT` and `R16G16B16A16_UINT` (`32_ABGR`). - Each masking and clamping packing is also drawn into `R32_UINT` and `R32G32B32A32_UINT`, where the driver cannot saturate. - **`agc_driver_graphics_tests`:** `uintTargetTests` decodes each export format into 8- and 16-bit targets to its packing (`32_AR` keeps `Uint`). The invalid-packing check now uses 9. - **Negative controls**, each built and run on its own: | Variant | RTX 4090 | Radeon PRO V620, RADV Mesa 25.2.8 | llvmpipe, Mesa 25.2.8 | |---|---|---|---| | this branch | passes | passes | passes | | masking removed | fails: `0xff` stored, `0x00` expected (`32_R`, `R8_UINT`) | fails, same | fails, same | | clamp limited to `FP16_ABGR` | fails: `0x1ff` stored, `0xff` expected (`32_ABGR`, `UintClamp8`) | fails, same | fails, same | ### 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 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: none - [x] GPUs tested: NVIDIA GeForce RTX 4090 (615.78.08, Linux 7.3 CachyOS); AMD Radeon PRO V620 (RADV Mesa 25.2.8, Ubuntu 24.04); llvmpipe (Mesa 25.2.8, Ubuntu 24.04) - [x] AI-assisted: yes *Tested and written by Claude (AI assistant) on a contributor's machine.* 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Superseabas commented 2026-11-04 17:49:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-04T17:49:38Z.

Review: APPROVED


Head 0ce0944491 merged onto current main b11c7bf84f (clean merge, local only): code read, red/green check and a run on AMD's Windows driver, with an NVIDIA Blackwell run alongside.

Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), Release, BUILD_TESTING=ON. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -R '^(agc_driver_graphics|agc_driver_.*uint.*|agc_driver_pixel_.*|agc_driver_.*float16.*|agc_driver_.*storage_image.*|agc_driver_.*export.*)$' (44 tests, agc_driver_uint_color_target among them), ANYPS5_GPU selecting the device (confirmed by Selected GPU):

GPU Driver main merged
NVIDIA GeForce RTX 5070 Ti (10de:2c05) 621.01 43 + 1 skip 43 + 1 skip
AMD Radeon Graphics, Ryzen 7 7700X iGPU (1002:164e) AMD 26.10.2 43 + 1 skip 43 + 1 skip
  • The skips are the same on both sides. The only VUID- in either tree is VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (#11990), which is on main too. No new ID appears, and there is no missing-layer line.
  • Red check: the merged tree with this PR's State.cpp and SpirvModuleEmitter.cpp changes reversed fails on both GPUs:
    • agc_driver_uint_color_target with a 32_R export of 0x3f800000 … into a tiled R8_UINT target …: channel 0 of pixel (0, 0) written holds 0x000000ff, expected 0x00000000. So both Windows drivers saturate where the PR masks, as the description says of the drivers it tried.
    • agc_driver_graphics with a 32_ABGR export into an 8-bit UINT target did not get the clamping packing.

Read through the change:

  • NarrowUintPacking picks clamp for 32_GR, FP16_ABGR and 32_ABGR, and mask for 32_R. 32_AR stays unpacked, and any other export into a UINT target still throws.
  • The two new ColorExportPacking values are appended after UintClamp16. RequestSerializer and FragmentOutputSpecialization raise their upper bound to UintMask16, so the existing values keep their numbers.
  • In SelectExportPacking, the mask path ANDs the bitcast word with the same 0xff / 0xffff limit the clamp path uses. IsUintPacking includes the new modes.

One non-blocking note: check_conventions.py --base main passes with one debt-length warning on the UINT color targets entry, which this PR takes from 2,119 to 2,497 characters. It was already over the limit on main.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5773077847 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15693#pullrequestreview-5773077847). Originally posted by [Superseabas](https://github.com/Superseabas) on 2026-11-04T17:49:38Z. **Review:** APPROVED --- Head `0ce0944491` merged onto current `main` `b11c7bf84f` (clean merge, local only): code read, red/green check and a run on AMD's Windows driver, with an NVIDIA Blackwell run alongside. Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (`x86_64-ucrt-posix-seh`, r3), Release, `BUILD_TESTING=ON`. `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ctest -R '^(agc_driver_graphics|agc_driver_.*uint.*|agc_driver_pixel_.*|agc_driver_.*float16.*|agc_driver_.*storage_image.*|agc_driver_.*export.*)$'` (44 tests, `agc_driver_uint_color_target` among them), `ANYPS5_GPU` selecting the device (confirmed by `Selected GPU`): | GPU | Driver | `main` | merged | |---|---|---|---| | NVIDIA GeForce RTX 5070 Ti (`10de:2c05`) | 621.01 | 43 + 1 skip | 43 + 1 skip | | AMD Radeon Graphics, Ryzen 7 7700X iGPU (`1002:164e`) | AMD 26.10.2 | 43 + 1 skip | 43 + 1 skip | - The skips are the same on both sides. The only `VUID-` in either tree is `VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605` (#11990), which is on `main` too. No new ID appears, and there is no missing-layer line. - Red check: the merged tree with this PR's `State.cpp` and `SpirvModuleEmitter.cpp` changes reversed fails on both GPUs: - `agc_driver_uint_color_target` with `a 32_R export of 0x3f800000 … into a tiled R8_UINT target …: channel 0 of pixel (0, 0) written holds 0x000000ff, expected 0x00000000`. So both Windows drivers saturate where the PR masks, as the description says of the drivers it tried. - `agc_driver_graphics` with `a 32_ABGR export into an 8-bit UINT target did not get the clamping packing`. Read through the change: - `NarrowUintPacking` picks clamp for `32_GR`, `FP16_ABGR` and `32_ABGR`, and mask for `32_R`. `32_AR` stays unpacked, and any other export into a UINT target still throws. - The two new `ColorExportPacking` values are appended after `UintClamp16`. `RequestSerializer` and `FragmentOutputSpecialization` raise their upper bound to `UintMask16`, so the existing values keep their numbers. - In `SelectExportPacking`, the mask path ANDs the bitcast word with the same `0xff` / `0xffff` limit the clamp path uses. `IsUintPacking` includes the new modes. One non-blocking note: `check_conventions.py --base main` passes with one `debt-length` warning on the `UINT color targets` entry, which this PR takes from 2,119 to 2,497 characters. It was already over the limit on `main`. AI-assisted: yes (Claude Code)
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!15693
No description provided.