feat(agc): implement 8 and 8_8 srgb image loads through unorm views #866
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/866"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T10:58:15Z.
What
GFX10
8_SRGBand8_8_SRGBmap to optional Vulkan formats: NVIDIA 610.62 lacks R8G8_SRGB and crashes creating such a texture; lavapipe lacks R8_SRGB too and loads zeros.SrgbDecodeFormatsmarks per device which of the two lackSAMPLED_IMAGE; their textures and views use R8_UNORM or R8G8_UNORM, andSpirvTarget::srgbDecodeFormatstakes the mark to shaders, the disk cache (FormatVersion7) and serialized requests (version 9).gfx10_format_table.py).APS5_SRGB_SHADER_DECODE=1forces the path.FormatVersion.Tested
main0d3c1eec: configure-DBUILD_TESTING=ON, full build,--target libs,ctest:ctest --output-on-failure)VK_DRIVER_FILES): 387/387 pass;agc_driver_flat_storeis left out there because it takes several minutes on Windows llvmpipeagc_driver_image_srgb_load: every code of 8_8_SRGB and 8_SRGB in four swizzle and dmask cases, uploaded or written by UNORMimage_stores, bit-exact against the bf16-rounded EOTF, plus two refusals; fails onmain(NVIDIA crash, lavapipe zeros) and with an f32 table.agc_driver_graphics,agc_shader_disk_cacheandagc_shader_memorycover the mapping, key and serialization (no build onmain).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)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.:0x399f00000x399f22b40x3e5d00000x3e5d0a890x3f7e00000x3f7db8deFix: build the table as the EOTF rounded to nearest-even to the top 16 bits, and make
Linear()inImageSrgbLoad.cpp:112the same so the test pins the hardware values.TechnicalDebt.md:194says 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?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
FormatVersion7 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_loadof a linear 256x1 8_SRGB T#, compared with the bf16 round-to-nearest-even EOTF (your gfx1035 values):0x39a00000(gfx10350x399f0000), code 12 is0x3b700000(0x3b710000), and code 253 is0x3f7c0000(0x3f7b0000).Neither this NVIDIA driver nor lavapipe reports
SAMPLED_IMAGEfor R8G8_SRGB, so 8_8_SRGB always goes through the R8G8_UNORM view and the table here.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T11:49:55Z.
Review: APPROVED
Re-checked
91852719bmerged 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 makesagc_driver_image_srgb_loadfail on both. The per-imagesrgbDecodefield follows the existingconversionFormatpattern, so per boykopovar's note that changes on main don't get in #639's way, I'm merging this.