Skip to content

Support GL fixed-rate compression, use formats consistently

Daniel Stone requested to merge daniels/weston:fixed-rate-compression into main

this is a draft because it depends on still-unmerged GBM interface changes, as well as !1461

Currently we support 'compressed' modifiers for formats, but these mostly only result in efficiency rather than space savings - AMD's DCC, Arm's sparse AFBC, and Intel's CCS are all layouts which reduce memory bandwidth whilst keeping the same space allocation. GL and Vulkan have added extensions for 'fixed-rate' compression, which is true compression in the sense that the buffers will be smaller in memory, but also lossy. The way this is exposed is by forcing the user to go out of their way to select a compression mode: either none, 'default' (driver chooses), or a target bitrate per channel.

This series adds support for the GL extensions. The actual work to support the extensions is small: some extra flags/attribs, and plumbing through the frontend to allow the user to select if they want the composition renderer output and/or client SHM textures to have fixed-rate compression applied to them, and at which rate.

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.

Edited by Daniel Stone

Merge request reports