Skip to content

Use sized internal formats and immutable textures in GL renderer

Daniel Stone requested to merge daniels/weston:gl-internalformat into main

Split out from !1382, which was the original motivation as immutable textures are a requirement for fixed-rate compression, and sized internal formats are a requirement for immutable textures. But it's a nice cleanup on its own, and not blocked by new GBM.

Most of the work is untangling GL formats. Whilst GLES2 only had unsized format+type, GLES3 introduces true sized internal formats in addition to the base format and type. Using these actually untangles some annoying corner cases where we have to special-case handling of particular formats and do open-coded conversion between sized and unsized formats. That's a nice bonus, but what it's really required for is making textures immutable, which is required to use fixed-rate compression.

glTexImage2D will 'respecify' a texture, optionally reallocating it to different dimensions, formats, mip levels, etc. In order to have immutable textures, we need to use glTexStorage2D (or glTexStorageAttribs2DEXT, or glEGLImageTextureStorage2DEXT) to declare the texture's properties up front - but doing this requires us to use sized internal formats when we specify the texture storage, as it does not accept unsized base formats. Once this is done, the texture can still be written to via glTexSubImage2D, but can no longer be respecified. This actually matches pretty well with previous reworks in gl-renderer to cache the buffer state; GL textures within the renderer are already never resized.

There is a small window where this doesn't work on Mesa. This is because we fall into a spec hole: GLES2 has unsized format+type only, GLES3 specifies a set of sized internal formats, GL_EXT_texture_format_BGRA8888 specifies only an unsized internal format, and GL_APPLE_texture_format_BGRA8888 goes most of the way to fixing this but still has a gap for renderbuffers AFAICT? so this fails all the test without the top hack commit; with it there's still an error message thrown about trying to respecify an immutable texture when using EGLImage sources. It was resolved in Mesa with a spec clarification as well.

Edited by Daniel Stone

Merge request reports