Skip to content

panfrost: Rewrite the clear colour packing code

Alyssa Rosenzweig requested to merge alyssa/mesa:clear-fixes into main

At the beginning of a render pass, the hardware will fill the tilebuffer with an arbitrary 128-bit word. To implement colour clears, the driver must pack the API-specific clear colour according to the 128-bit layout of the tilebuffer. This layout depends only on the render target format.

The existing code to handle this was based on loose guesswork. It works for the format / clear colour combinations tested in dEQP-GLES3, but it is severely deficient in the general case. It works by matching on the PIPE format of the render target (not the layout of the tilebuffer). For special cased PIPE formats, it open codes a buggy pack routine. Otherwise, it defaults to util_pack_color in the hope that will work. Since util_pack_color doesn't know anything about Mali tilebuffer layouts, that means it's defaulting to wrong behaviour.

Now that we understand internal tilebuffer layouts, let's rewrite the packing code. Instead of matching PIPE formats, map the PIPE format to the internal tilebuffer layout using the common table, ensuring the mapping remains in sync with the render target descriptor. Then for blendable tilebuffer formats, pack using a common float -> fixed point path supporting optional sRGB translation. Raw formats use util_pack_color as before.

For formats with less than 8 bits per channel, the new code uses the fractional bits of the fixed-point representation. This is required for correct dithering if the clear colour is not exactly representable in the final low precision format.

In summary, at least the following bugs in the old code are fixed:

  • Swapped R/B channels with sRGB
  • Swapped R/B channels with some missing formats
  • Incorrect dithering with RGB565, RGB5_A1

Fixes the following test cases:

dEQP-EGL.functional.wide_color.window_8888_colorspace_srgb dEQP-EGL.functional.wide_color.pbuffer_8888_colorspace_srgb dEQP-EGL.functional.wide_color.window_888_colorspace_srgb dEQP-EGL.functional.wide_color.pbuffer_888_colorspace_srgb

Later in the series, unit tests are added for the new implementation.

Signed-off-by: Alyssa Rosenzweig alyssa@collabora.com Cc: mesa-stable

Merge request reports