feat(agc): implement 8 and 8_8 srgb image loads through unorm views #866

Merged
Celegans12 merged 1 commit from upstream-pr/866 into main 2026-10-07 11:49:58 +00:00
Celegans12 commented 2026-10-06 10:58:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T10:58:15Z.


What

GFX10 8_SRGB and 8_8_SRGB map to optional Vulkan formats: NVIDIA 610.62 lacks R8G8_SRGB and crashes creating such a texture; lavapipe lacks R8_SRGB too and loads zeros.

  • SrgbDecodeFormats marks per device which of the two lack SAMPLED_IMAGE; their textures and views use R8_UNORM or R8G8_UNORM, and SpirvTarget::srgbDecodeFormats takes the mark to shaders, the disk cache (FormatVersion 7) and serialized requests (version 9).
  • Marked image loads decode each channel with a table of the sRGB EOTF rounded to nearest even at bf16 precision, which matches all 256 codes adriadam10 measured on RDNA2 (gfx1035); gfx1013 is unmeasured, and NVIDIA's native R8_SRGB is one bf16 step off in 29 codes (TechnicalDebt). Both 8_8 channels are sRGB (Mesa gfx10_format_table.py).
  • Still throws: samples and gathers of a marked image; its bindless table entries read zeros (TechnicalDebt). APS5_SRGB_SHADER_DECODE=1 forces the path.
  • PPSA26344 v1.008: shader 0x8000265d00 loads two 4K 8_8_SRGB T#s written as 8_8_UNORM storage images.
  • #757, #758, #759, #639 and #426 conflict here (image emitter, materializer, disk cache, key), and #822 on FormatVersion.
  • #448 conflicts in the request serializer; #426 bumps its version too, and #423 and #1077 bump it to 9 in identical lines that merge silently.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 0d3c1eec: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 388/388 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 387/387 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • New agc_driver_image_srgb_load: every code of 8_8_SRGB and 8_SRGB in four swizzle and dmask cases, uploaded or written by UNORM image_stores, bit-exact against the bf16-rounded EOTF, plus two refusals; fails on main (NVIDIA crash, lavapipe zeros) and with an f32 table.
  • agc_driver_graphics, agc_shader_disk_cache and agc_shader_memory cover the mapping, key and serialization (no build on main).
  • PPSA26344 v1.008 with our other open PRs: both textures are viewed as R8G8_UNORM and 0x8000265d00 dispatches.
  • Not tested: 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:4757727744 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/866). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-06T10:58:15Z. --- ### What GFX10 `8_SRGB` and `8_8_SRGB` map to optional Vulkan formats: NVIDIA 610.62 lacks R8G8_SRGB and crashes creating such a texture; lavapipe lacks R8_SRGB too and loads zeros. - `SrgbDecodeFormats` marks per device which of the two lack `SAMPLED_IMAGE`; their textures and views use R8_UNORM or R8G8_UNORM, and `SpirvTarget::srgbDecodeFormats` takes the mark to shaders, the disk cache (`FormatVersion` 7) and serialized requests (version 9). - Marked image loads decode each channel with a table of the sRGB EOTF rounded to nearest even at bf16 precision, which matches all 256 codes adriadam10 measured on RDNA2 (gfx1035); gfx1013 is unmeasured, and NVIDIA's native R8_SRGB is one bf16 step off in 29 codes (TechnicalDebt). Both 8_8 channels are sRGB (Mesa `gfx10_format_table.py`). - **Still throws:** samples and gathers of a marked image; its bindless table entries read zeros (TechnicalDebt). `APS5_SRGB_SHADER_DECODE=1` forces the path. - PPSA26344 v1.008: shader 0x8000265d00 loads two 4K 8_8_SRGB T#s written as 8_8_UNORM storage images. - #757, #758, #759, #639 and #426 conflict here (image emitter, materializer, disk cache, key), and #822 on `FormatVersion`. - #448 conflicts in the request serializer; #426 bumps its version too, and #423 and #1077 bump it to 9 in identical lines that merge silently. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 0d3c1eec: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 388/388 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 387/387 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - New `agc_driver_image_srgb_load`: every code of 8_8_SRGB and 8_SRGB in four swizzle and dmask cases, uploaded or written by UNORM `image_store`s, bit-exact against the bf16-rounded EOTF, plus two refusals; fails on `main` (NVIDIA crash, lavapipe zeros) and with an f32 table. - `agc_driver_graphics`, `agc_shader_disk_cache` and `agc_shader_memory` cover the mapping, key and serialization (no build on `main`). - PPSA26344 v1.008 with our other open PRs: both textures are viewed as R8G8_UNORM and 0x8000265d00 dispatches. - Not tested: 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
adriadam10 commented 2026-10-07 07:49:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T07:49:27Z.

Review: CHANGES_REQUESTED


Measured on the HW oracle (gfx1035, image_load ... dmask:0xf unorm, linear 256x1 T#, all 256 codes of 8_SRGB and 8_8_SRGB).

  • The decode isn't the correctly rounded f32 EOTF on hardware. The hardware returns the EOTF rounded to nearest-even at 8 significant bits (bf16 precision, low 16 bits always zero): 0 mismatches against bf16_rne(eotf(c)) across all 256 codes (136 against truncation). SrgbToLinear (SpirvImageEmitter.cpp:330) differs in 254 of 256 codes, e.g.:

    code HW PR table
    1 0x399f0000 0x399f22b4
    128 0x3e5d0000 0x3e5d0a89
    254 0x3f7e0000 0x3f7db8de

    Fix: build the table as the EOTF rounded to nearest-even to the top 16 bits, and make Linear() in ImageSrgbLoad.cpp:112 the same so the test pins the hardware values.

  • TechnicalDebt.md:194 says the console's rounding is "not documented or measured": it now is, on gfx1035 (RDNA2), not on the PS5's gfx1013. Please say that, and note that devices that sample R8_SRGB/R8G8_SRGB natively return full f32 precision, so they don't match the hardware either.

  • @boykopovar: this adds a per-image specialization field (ResourceSpecialization::Image::srgbDecode, ResourceMaterializer.cpp:170) and a new reason to pad bindless table entries with zeros (ResourceMaterializer.cpp:390). #639 replaces resource specialization with runtime descriptors: do you want this in now, or should it wait for #639 and be done there?

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5439218495 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/866#pullrequestreview-5439218495). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T07:49:27Z. **Review:** CHANGES_REQUESTED --- Measured on the HW oracle (gfx1035, `image_load ... dmask:0xf unorm`, linear 256x1 T#, all 256 codes of 8_SRGB and 8_8_SRGB). - **The decode isn't the correctly rounded f32 EOTF on hardware.** The hardware returns the EOTF rounded to nearest-even at 8 significant bits (bf16 precision, low 16 bits always zero): 0 mismatches against `bf16_rne(eotf(c))` across all 256 codes (136 against truncation). `SrgbToLinear` (`SpirvImageEmitter.cpp:330`) differs in 254 of 256 codes, e.g.: | code | HW | PR table | |---|---|---| | 1 | `0x399f0000` | `0x399f22b4` | | 128 | `0x3e5d0000` | `0x3e5d0a89` | | 254 | `0x3f7e0000` | `0x3f7db8de` | Fix: build the table as the EOTF rounded to nearest-even to the top 16 bits, and make `Linear()` in `ImageSrgbLoad.cpp:112` the same so the test pins the hardware values. - `TechnicalDebt.md:194` says the console's rounding is "not documented or measured": it now is, on gfx1035 (RDNA2), not on the PS5's gfx1013. Please say that, and note that devices that sample R8_SRGB/R8G8_SRGB natively return full f32 precision, so they don't match the hardware either. - @boykopovar: this adds a per-image specialization field (`ResourceSpecialization::Image::srgbDecode`, `ResourceMaterializer.cpp:170`) and a new reason to pad bindless table entries with zeros (`ResourceMaterializer.cpp:390`). #639 replaces resource specialization with runtime descriptors: do you want this in now, or should it wait for #639 and be done there?
Celegans12 commented 2026-10-07 10:11:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T10:11:11Z.


Thanks for measuring all 256 codes of both formats on gfx1035, that's exactly what the table was missing.

I've pushed 91852719b. The table is now the sRGB EOTF rounded to nearest even at bf16 precision, which matches every one of your 256 measured codes. Linear() in the test does the same rounding, so the test pins those values and fails if the old f32 table goes back in. The TechnicalDebt line now says the decode was measured on RDNA2 (gfx1035) and that the PS5's gfx1013 isn't measured.

One small correction on native decode, though. On this RTX 3080, native R8_SRGB loads also come back with the low 16 bits zero: they equal the bf16 values in 227 of 256 codes and are one bf16 step off in the other 29, so they aren't full f32 either. That's why the TechnicalDebt line says native decode "need not match gfx1035" instead of calling it full f32. I couldn't check R8G8_SRGB, because no device here samples it natively.

The branch is also rebased on current main, with shader cache FormatVersion 7 and request serializer version 9, since #869 took 8. The #639 question is boykopovar's call; I'm happy either to hold this until #639 lands or to port it into #639.

Details

NVIDIA GeForce RTX 3080 Laptop GPU (driver 610.62), native R8_SRGB view, image_load of a linear 256x1 8_SRGB T#, compared with the bf16 round-to-nearest-even EOTF (your gfx1035 values):

  • 256 of 256 results have the low 16 bits zero; only codes 0 and 255 equal the correctly rounded f32 EOTF.
  • 227 codes are bit-equal to the bf16 values.
  • 29 codes are exactly one bf16 step off: one step high at 1-11, 19, 20, 33, 66, 184, 186, 252 and 253, one step low at 12, 15, 32, 65, 68, 70, 97 and 249-251.
  • For example, code 1 is 0x39a00000 (gfx1035 0x399f0000), code 12 is 0x3b700000 (0x3b710000), and code 253 is 0x3f7c0000 (0x3f7b0000).

Neither this NVIDIA driver nor lavapipe reports SAMPLED_IMAGE for R8G8_SRGB, so 8_8_SRGB always goes through the R8G8_UNORM view and the table here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6035755527 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/866#issuecomment-6035755527). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T10:11:11Z. --- Thanks for measuring all 256 codes of both formats on gfx1035, that's exactly what the table was missing. I've pushed 91852719b. The table is now the sRGB EOTF rounded to nearest even at bf16 precision, which matches every one of your 256 measured codes. `Linear()` in the test does the same rounding, so the test pins those values and fails if the old f32 table goes back in. The TechnicalDebt line now says the decode was measured on RDNA2 (gfx1035) and that the PS5's gfx1013 isn't measured. One small correction on native decode, though. On this RTX 3080, native R8_SRGB loads also come back with the low 16 bits zero: they equal the bf16 values in 227 of 256 codes and are one bf16 step off in the other 29, so they aren't full f32 either. That's why the TechnicalDebt line says native decode "need not match gfx1035" instead of calling it full f32. I couldn't check R8G8_SRGB, because no device here samples it natively. The branch is also rebased on current main, with shader cache `FormatVersion` 7 and request serializer version 9, since #869 took 8. The #639 question is boykopovar's call; I'm happy either to hold this until #639 lands or to port it into #639. <details><summary>Details</summary> NVIDIA GeForce RTX 3080 Laptop GPU (driver 610.62), native R8_SRGB view, `image_load` of a linear 256x1 8_SRGB T#, compared with the bf16 round-to-nearest-even EOTF (your gfx1035 values): - 256 of 256 results have the low 16 bits zero; only codes 0 and 255 equal the correctly rounded f32 EOTF. - 227 codes are bit-equal to the bf16 values. - 29 codes are exactly one bf16 step off: one step high at 1-11, 19, 20, 33, 66, 184, 186, 252 and 253, one step low at 12, 15, 32, 65, 68, 70, 97 and 249-251. - For example, code 1 is `0x39a00000` (gfx1035 `0x399f0000`), code 12 is `0x3b700000` (`0x3b710000`), and code 253 is `0x3f7c0000` (`0x3f7b0000`). Neither this NVIDIA driver nor lavapipe reports `SAMPLED_IMAGE` for R8G8_SRGB, so 8_8_SRGB always goes through the R8G8_UNORM view and the table here. </details>
adriadam10 commented 2026-10-07 11:49:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T11:49:55Z.

Review: APPROVED


Re-checked 91852719b merged onto current main: the table matches the HW oracle (gfx1035) bit for bit on all 256 codes of 8_SRGB and 8_8_SRGB. ctest is green on RADV, and the PR's tests pass on CI's lavapipe. Changing one table entry makes agc_driver_image_srgb_load fail on both. The per-image srgbDecode field follows the existing conversionFormat pattern, so per boykopovar's note that changes on main don't get in #639's way, I'm merging this.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5441821723 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/866#pullrequestreview-5441821723). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T11:49:55Z. **Review:** APPROVED --- Re-checked 91852719b merged onto current main: the table matches the HW oracle (gfx1035) bit for bit on all 256 codes of 8_SRGB and 8_8_SRGB. ctest is green on RADV, and the PR's tests pass on CI's lavapipe. Changing one table entry makes `agc_driver_image_srgb_load` fail on both. The per-image `srgbDecode` field follows the existing `conversionFormat` pattern, so per boykopovar's note that changes on main don't get in #639's way, I'm merging this.
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!866
No description provided.