texSubImage2D with sRGB texture on Metal

55 views
Skip to first unread message

amshv

unread,
Aug 3, 2026, 11:06:41 PM (2 days ago) Aug 3
to angleproject
Hi,

I am using texStorage2D to create textures with internalformat SRGB8_ALPHA8 and then calling texSubImage2D with format RGBA and type UNSIGNED_BYTE. On the Metal debugger I noticed that there are several replaceRegion calls apparently for a row by row format conversion.

I put some print statements where this is happening, here https://github.com/google/angle/blob/91d2d125ec0054f970594b29660f1cf3d172a8f1/src/libANGLE/renderer/metal/TextureMtl.mm#L2324 it's trying to convert to R8G8B8A8_UNORM_SRGB from R8G8B8A8_UNORM which it gets from the format and type. But R8G8B8A8_UNORM_SRGB also corresponds to the same format and type. I can work around this by changing the internal format to RGBA8 and decoding in the fragment shader but I'm wondering if the conversion could be skipped in this case.

Thanks.

Shahbaz Youssefi

unread,
Aug 4, 2026, 9:30:16 AM (yesterday) Aug 4
to angleproject
Hi,

This could be a bug, but I'm looking at the `SRGBTextureTestES3.SRGBFormatCombinationValidation` test, and it looks like creating a texture with `GL_SRGB_ALPHA_EXT` and uploading to it with GL_RGBA+GL_UNSIGNED_BYTE is tested and apparently passing on Metal (test uploads sRGB, expects sampling to return linear). I don't see the sized GL_SRGB8_ALPHA8 format tested with GL_RGBA though; the test is using GL_SRGB_ALPHA_EXT+GL_UNSIGNED_BYTE instead. Perhaps GL_SRGB_ALPHA_EXT is what you need to use in GL_RGBA in glTexSubImage2D?

amshv

unread,
Aug 4, 2026, 10:13:51 AM (yesterday) Aug 4
to angleproject
Thanks for looking into it. For me the values are correct both ways, ie I also get linear values in the shader as expected. However the row conversion loop is taking 5-10 ms for a 512x512 texture so I assume it's copying the data unchanged. I don't know if it's a bug necessarily rather than a performance thing, or if it's something with the way this data has to be stored.

Shahbaz Youssefi

unread,
Aug 4, 2026, 10:45:25 AM (yesterday) Aug 4
to angleproject
Right, I checked with an expert and using GL_RGBA is fine, and this is just a matter of the metal backend not implementing the conversion efficiently.

amshv

unread,
Aug 4, 2026, 3:40:10 PM (yesterday) Aug 4
to angleproject
I see, thank you. I opened https://issues.angleproject.org/issues/542677296 in case this is worth tracking.
Reply all
Reply to author
Forward
0 new messages