Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Celegans12:feat/agc-srgb-load-fallback
Oct 7, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Celegans12:feat/agc-srgb-load-fallback

Conversation

@Celegans12

@Celegans12 Celegans12 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 0d3c1ee: 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

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

NVIDIA 610.62 cannot sample R8G8_SRGB, and lavapipe can sample neither
it nor R8_SRGB, so an 8_8 sRGB T# made an image the device does not
support: creating it crashes the NVIDIA driver and lavapipe loads zeros.

The device's format support is read once. An 8 or 8_8 sRGB texture the
device cannot sample is created and viewed as R8_UNORM or R8G8_UNORM,
and SpirvTarget::srgbDecodeFormats makes the materializer mark the
image, so image loads map every channel through a 256-entry table of
the sRGB EOTF rounded to nearest even at bf16 precision, which is what
RDNA2 (gfx1035) returns; both channels of 8_8 are sRGB, and DST_SEL 0
and 1 map to themselves. Samples and gathers of such an image throw,
and its bindless table entries are unmapped like converted formats.
APS5_SRGB_SHADER_DECODE=1 takes this path on every device. Shader disk
cache entries and keys carry the mark: cache format version 7.
@Celegans12

Copy link
Copy Markdown
Contributor Author

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

I've pushed 9185271. 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.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 7, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked 9185271 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.

@adriadam10
adriadam10 merged commit 931109b into boykopovar:main Oct 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants