fix(shader_recompiler): pack format 11_11_10 float image stores in shader #8898

Merged
camezaro-intc merged 2 commits from upstream-pr/8898 into main 2026-10-26 12:03:40 +00:00
camezaro-intc commented 2026-10-21 05:04:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by camezaro-intc on 2026-10-21T05:04:14Z.


What

Packs storage image stores into guest format 36 (Format11_11_10Float) in-shader via Format32UInt views rather than relying on Vulkan's VK_FORMAT_B10G11R11_UFLOAT_PACK32 write path. Real RDNA 2 hardware rounds toward zero and saturates finite values exceeding maximum representable range to 65024.0 (11-bit) and 64512.0 (10-bit), whereas host Vulkan drivers round to nearest-even and overflow to infinity.

Routes DCC fast clears for formats 36 and 43 through VK_FORMAT_B10G11R11_UFLOAT_PACK32 via DccClearTextureFormat so fast clears produce valid 3-channel packed float layouts rather than single-channel R32_UINT.

Tested

  • Windows 11, AMD Radeon RX 5700 XT (driver 32.0.21045.5002) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:
    • ctest --test-dir build -R "agc_driver_image_converted_unorm|agc_driver_image_repacked_float|texture_format_lookup|agc_driver$" -V passed 100% with zero validation errors.

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: Part of #8282
  • Unblocks: none
  • GPUs tested: AMD, Radeon RX 5700 XT, 32.0.21045.5002, Windows 11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4946674630 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8898). Originally posted by [camezaro-intc](https://github.com/camezaro-intc) on 2026-10-21T05:04:14Z. --- ### What Packs storage image stores into guest format 36 (`Format11_11_10Float`) in-shader via `Format32UInt` views rather than relying on Vulkan's `VK_FORMAT_B10G11R11_UFLOAT_PACK32` write path. Real RDNA 2 hardware rounds toward zero and saturates finite values exceeding maximum representable range to 65024.0 (11-bit) and 64512.0 (10-bit), whereas host Vulkan drivers round to nearest-even and overflow to infinity. Routes DCC fast clears for formats 36 and 43 through `VK_FORMAT_B10G11R11_UFLOAT_PACK32` via `DccClearTextureFormat` so fast clears produce valid 3-channel packed float layouts rather than single-channel `R32_UINT`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Windows 11, AMD Radeon RX 5700 XT (driver 32.0.21045.5002) with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`: - `ctest --test-dir build -R "agc_driver_image_converted_unorm|agc_driver_image_repacked_float|texture_format_lookup|agc_driver$" -V` passed 100% with zero validation errors. ### 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) - [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: Part of #8282 - [x] Unblocks: none - [x] GPUs tested: AMD, Radeon RX 5700 XT, 32.0.21045.5002, Windows 11 - [x] AI-assisted: yes
thuanquang commented 2026-10-21 11:58:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T11:58:07Z.


Runs of this head (5236bb622) on AMD hardware and on lavapipe.

The edge rows on hardware. The seven Float36StoreEdges rows match an RX 6700 XT (gfx1031, AMD's Windows driver 32.0.21045.5002). Each row was stored with image_store through a format 36 T# and read back through a 32_UINT T#, as raw ISA through the HIP runtime. All seven dwords equal the test's expected values, with f32 denormals kept and with them flushed.

RX 6700 XT (Windows 11 26200, MinGW Release, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1), the four tests from the body:

  • main a07e985c8 with only this PR's test changes: 3 of 4 pass. agc_driver_graphics fails with format 36 must be sampled as B10G11R11_UFLOAT and stored as R32_UINT. The new store case passes on main here, so AMD's own B10G11R11_UFLOAT_PACK32 storage write already converts as the hardware does.
  • main merged with this head: 4 of 4 pass, 3 rounds.
  • Khronos validation layer, -V: 4 of 4 pass, 0 VUID- lines. VK_LOADER_DEBUG=layer shows the layer inserted in agc_driver_image_converted_unorm and agc_driver_image_repacked_float.

lavapipe (WSL Ubuntu 24.04, Mesa 25.2.8 with LLVM 20.1.2 as in the Linux CI, GCC 13.3 Release with SPIRV-Tools on), agc_driver_image_converted_unorm. The tree is main d0852defa with #8055, #8884 and #8886 applied; none of them touches image stores.

  • With only this PR's test changes it fails: image_store of R11_G11_B10_FLOAT: texel 6 is 0xfc3f07e0, expected 0xfa3e0fc1. Texels 0 to 5 already match: lavapipe also rounds these fields toward zero, saturates and stores 0 for negatives. Only the NaN row differs. lavapipe writes the canonical quiet NaN in each field (0x7e0, 0x7e0, 0x3f0). The hardware keeps the top bits of the payload and sets the lowest mantissa bit when none of them is set (0x7c1, 0x7c1, 0x3e8).
  • With this PR: 3 of 3 pass.

Two notes:

  • The body says finite values saturate to 65504.0 in the 11-bit fields. The largest finite 11-bit value is 65024.0 (0x7bf, which the test uses). 65504 is the f16 maximum.
  • #8282 also covers 16_FLOAT, 16_16_FLOAT and 16_16_16_16_FLOAT, which #8998 handles. With Fixes #8282, merging this PR would close the issue while #8998 is still open. Part of #8282 would keep it open until both are in.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6315334058 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8898#issuecomment-6315334058). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-21T11:58:07Z. --- Runs of this head (`5236bb622`) on AMD hardware and on lavapipe. **The edge rows on hardware.** The seven `Float36StoreEdges` rows match an RX 6700 XT (gfx1031, AMD's Windows driver 32.0.21045.5002). Each row was stored with `image_store` through a format 36 T# and read back through a `32_UINT` T#, as raw ISA through the HIP runtime. All seven dwords equal the test's expected values, with f32 denormals kept and with them flushed. **RX 6700 XT** (Windows 11 26200, MinGW Release, `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_REQUIRE_VULKAN=1`), the four tests from the body: - `main` `a07e985c8` with only this PR's test changes: 3 of 4 pass. `agc_driver_graphics` fails with `format 36 must be sampled as B10G11R11_UFLOAT and stored as R32_UINT`. The new store case passes on `main` here, so AMD's own `B10G11R11_UFLOAT_PACK32` storage write already converts as the hardware does. - `main` merged with this head: 4 of 4 pass, 3 rounds. - Khronos validation layer, `-V`: 4 of 4 pass, 0 `VUID-` lines. `VK_LOADER_DEBUG=layer` shows the layer inserted in `agc_driver_image_converted_unorm` and `agc_driver_image_repacked_float`. **lavapipe** (WSL Ubuntu 24.04, Mesa 25.2.8 with LLVM 20.1.2 as in the Linux CI, GCC 13.3 Release with SPIRV-Tools on), `agc_driver_image_converted_unorm`. The tree is `main` `d0852defa` with #8055, #8884 and #8886 applied; none of them touches image stores. - With only this PR's test changes it fails: `image_store of R11_G11_B10_FLOAT: texel 6 is 0xfc3f07e0, expected 0xfa3e0fc1`. Texels 0 to 5 already match: lavapipe also rounds these fields toward zero, saturates and stores 0 for negatives. Only the NaN row differs. lavapipe writes the canonical quiet NaN in each field (`0x7e0`, `0x7e0`, `0x3f0`). The hardware keeps the top bits of the payload and sets the lowest mantissa bit when none of them is set (`0x7c1`, `0x7c1`, `0x3e8`). - With this PR: 3 of 3 pass. Two notes: - The body says finite values saturate to 65504.0 in the 11-bit fields. The largest finite 11-bit value is 65024.0 (`0x7bf`, which the test uses). 65504 is the f16 maximum. - #8282 also covers `16_FLOAT`, `16_16_FLOAT` and `16_16_16_16_FLOAT`, which #8998 handles. With `Fixes #8282`, merging this PR would close the issue while #8998 is still open. `Part of #8282` would keep it open until both are in.
ryanc2112 commented 2026-10-21 12:23:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ryanc2112 on 2026-10-21T12:23:33Z.


Tested on Linux / RADV (SteamOS 3.8.28, AMD Radeon RX 570 / Polaris10, Mesa 26.2.5, GCC 16.2.1, Release), this PR (5236bb622) merged onto main 3e91c8edf vs main, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (loader confirms the layer is inserted).

  • Focused set from the PR description plus agc_driver_image_store_*: 10/10 pass on both, zero VUID- on both.
  • Control: this PR's ImageConvertedUnorm.cpp on unpatched main fails with image_store of R11_G11_B10_FLOAT: texel 0 is 0xffc00000, expected 0xfc000000 (RADV writes the canonical all-ones NaN mantissa), and passes with the PR.
  • All agc_* + texture_format_lookup (855 tests): identical pass/fail set on both, identical validation output (6× VUID-VkWriteDescriptorSet-descriptorType-00337, 2× VUID-vkResetFences-pFences-01123 on both). No regressions observed.

One issue from reading the diff: remapGuestFormat now resolves format 36 to R32_UINT everywhere, and the DCC clear paths derive the clear layout from ResolveTextureFormat (DccMetadata.cpp:529,777,786, ShaderResources.cpp:740). On main format 36 uses the B10G11R11_UFLOAT_PACK32 layout (3 float channels, DccMetadata.cpp:409); with this PR it gets the R32_UINT layout (1 uint channel, :401), which FillDccClear treats as alpha. So Clear1111 fills 0x00000001 instead of 1.0 in each channel, and Clear1110 fills 0. No existing test covers a format-36 DCC clear, which is why the full run is unchanged. Could the DCC clear layout use the native format for 36 (and 43, which looks to have the same gap)?

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6315809208 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8898#issuecomment-6315809208). Originally posted by [ryanc2112](https://github.com/ryanc2112) on 2026-10-21T12:23:33Z. --- **Tested on Linux / RADV** (SteamOS 3.8.28, AMD Radeon RX 570 / Polaris10, Mesa 26.2.5, GCC 16.2.1, Release), this PR (5236bb622) merged onto `main` 3e91c8edf vs `main`, with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (loader confirms the layer is inserted). - Focused set from the PR description plus `agc_driver_image_store_*`: 10/10 pass on both, zero `VUID-` on both. - Control: this PR's `ImageConvertedUnorm.cpp` on unpatched `main` fails with `image_store of R11_G11_B10_FLOAT: texel 0 is 0xffc00000, expected 0xfc000000` (RADV writes the canonical all-ones NaN mantissa), and passes with the PR. - All `agc_*` + `texture_format_lookup` (855 tests): identical pass/fail set on both, identical validation output (6× `VUID-VkWriteDescriptorSet-descriptorType-00337`, 2× `VUID-vkResetFences-pFences-01123` on both). No regressions observed. **One issue from reading the diff:** `remapGuestFormat` now resolves format 36 to `R32_UINT` everywhere, and the DCC clear paths derive the clear layout from `ResolveTextureFormat` (`DccMetadata.cpp:529,777,786`, `ShaderResources.cpp:740`). On `main` format 36 uses the `B10G11R11_UFLOAT_PACK32` layout (3 float channels, `DccMetadata.cpp:409`); with this PR it gets the `R32_UINT` layout (1 uint channel, `:401`), which `FillDccClear` treats as alpha. So `Clear1111` fills `0x00000001` instead of 1.0 in each channel, and `Clear1110` fills 0. No existing test covers a format-36 DCC clear, which is why the full run is unchanged. Could the DCC clear layout use the native format for 36 (and 43, which looks to have the same gap)? AI-assisted: yes.
camezaro-intc commented 2026-10-21 16:17:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by camezaro-intc on 2026-10-21T16:17:47Z.


Thanks @thuanquang and @ryanc2112 for the thorough review, measurements, and tests across real hardware and lavapipe!

  • PR Description: Corrected the 11-bit saturation limit note from 65504.0 to 65024.0 (0x7bf), and changed Fixes #8282 to Part of #8282 so the issue remains open for #8998.
  • DCC Fast Clear Layout: Added DccClearTextureFormat(guestFormat) returning VK_FORMAT_B10G11R11_UFLOAT_PACK32 for formats 36 and 43 (IsRepackedTextureFormat), and updated the clear-format resolution calls in DccMetadata.cpp and ShaderResources.cpp. FillDccClear now receives the native 3-channel layout (Clear1111 and Clear1110 produce 0x781e03c0u, Clear0000 produces 0u) instead of defaulting to single-channel R32_UINT. Added test coverage in packedFloatDccClearTests for both formats 36 and 43 under Clear1111, Clear1110, and Clear0000 with ReadTextureSurface.

All validation tests pass 100% with 0 VUID- validation errors on RX 5700 XT.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6320790387 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8898#issuecomment-6320790387). Originally posted by [camezaro-intc](https://github.com/camezaro-intc) on 2026-10-21T16:17:47Z. --- Thanks @thuanquang and @ryanc2112 for the thorough review, measurements, and tests across real hardware and lavapipe! - **PR Description:** Corrected the 11-bit saturation limit note from `65504.0` to `65024.0` (`0x7bf`), and changed `Fixes #8282` to `Part of #8282` so the issue remains open for #8998. - **DCC Fast Clear Layout:** Added `DccClearTextureFormat(guestFormat)` returning `VK_FORMAT_B10G11R11_UFLOAT_PACK32` for formats 36 and 43 (`IsRepackedTextureFormat`), and updated the clear-format resolution calls in `DccMetadata.cpp` and `ShaderResources.cpp`. `FillDccClear` now receives the native 3-channel layout (`Clear1111` and `Clear1110` produce `0x781e03c0u`, `Clear0000` produces `0u`) instead of defaulting to single-channel `R32_UINT`. Added test coverage in `packedFloatDccClearTests` for both formats 36 and 43 under `Clear1111`, `Clear1110`, and `Clear0000` with `ReadTextureSurface`. All validation tests pass 100% with 0 `VUID-` validation errors on RX 5700 XT.
MaxLikesCode commented 2026-10-21 16:35:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MaxLikesCode on 2026-10-21T16:35:22Z.


RTX 4090 (Ada) on Windows, head 9e8f18888 merged onto main cecb540a6 (clean). The four tests from the Tested section (agc_driver_image_converted_unorm, agc_driver_image_repacked_float, texture_format_lookup, agc_driver), plus the 8 tests matching dcc for the packed-float DCC clear change:

  • main: 12 of 12 in 3 runs without and 3 with the validation layer.
  • this PR: 12 of 12 in the same 6 runs, including the new R11_G11_B10_FLOAT store and sample checks in agc_driver_image_converted_unorm.
  • No run on either side logs a VUID-.

NVIDIA GeForce RTX 4090, driver 617.42, Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, ctest --test-dir build -R <tests> -V. Validation runs add VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Vulkan-ValidationLayers vulkan-sdk-1.4.363.0, implicit layers disabled); the loader log shows the layer inserted in every Vulkan test process, and no log has was not found but was requested by env var VK_INSTANCE_LAYERS.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6321173821 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8898#issuecomment-6321173821). Originally posted by [MaxLikesCode](https://github.com/MaxLikesCode) on 2026-10-21T16:35:22Z. --- RTX 4090 (Ada) on Windows, head `9e8f18888` merged onto `main` `cecb540a6` (clean). The four tests from the Tested section (`agc_driver_image_converted_unorm`, `agc_driver_image_repacked_float`, `texture_format_lookup`, `agc_driver`), plus the 8 tests matching `dcc` for the packed-float DCC clear change: - `main`: 12 of 12 in 3 runs without and 3 with the validation layer. - this PR: 12 of 12 in the same 6 runs, including the new R11_G11_B10_FLOAT store and sample checks in `agc_driver_image_converted_unorm`. - No run on either side logs a `VUID-`. NVIDIA GeForce RTX 4090, driver 617.42, Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `ctest --test-dir build -R <tests> -V`. Validation runs add `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Vulkan-ValidationLayers `vulkan-sdk-1.4.363.0`, implicit layers disabled); the loader log shows the layer inserted in every Vulkan test process, and no log has `was not found but was requested by env var VK_INSTANCE_LAYERS`. 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!8898
No description provided.