panfrost: Fake RGTC support

For most GPUs RGTC is disabled, so it needs to be emulated, using the
fake_rgtc option of u_transfer_helper.

Passes the rgtc-teximage tests in piglit.

v2: Update docs/features.txt (Alyssa)

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5975>
diff --git a/docs/features.txt b/docs/features.txt
index fed566e..9d5198e 100644
--- a/docs/features.txt
+++ b/docs/features.txt
@@ -52,7 +52,7 @@
   GL_EXT_texture_integer                                DONE (panfrost, v3d)
   GL_EXT_texture_array                                  DONE (panfrost, v3d)
   GL_EXT_draw_buffers2 (Per-buffer blend and masks)     DONE (panfrost, v3d)
-  GL_EXT_texture_compression_rgtc                       DONE (panfrost/if SoC supports)
+  GL_EXT_texture_compression_rgtc                       DONE (panfrost)
   GL_ARB_texture_rg                                     DONE (panfrost, v3d)
   GL_EXT_transform_feedback (Transform feedback)        DONE (panfrost, v3d)
   GL_ARB_vertex_array_object (Vertex array objects)     DONE (panfrost, v3d)
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index d2b44f9..5d84322 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -941,13 +941,25 @@
         assert(prsrc->bo);
 
         /* Format to access the stencil portion of a Z32_S8 texture */
-        if (so->base.format == PIPE_FORMAT_X32_S8X24_UINT) {
+        if (format == PIPE_FORMAT_X32_S8X24_UINT) {
                 assert(prsrc->separate_stencil);
                 texture = &prsrc->separate_stencil->base;
                 prsrc = (struct panfrost_resource *)texture;
                 format = texture->format;
         }
 
+        const struct util_format_description *desc = util_format_description(format);
+
+        bool fake_rgtc = !panfrost_supports_compressed_format(device, MALI_BC4_UNORM);
+
+        if (desc->layout == UTIL_FORMAT_LAYOUT_RGTC && fake_rgtc) {
+                if (desc->is_snorm)
+                        format = PIPE_FORMAT_R8G8B8A8_SNORM;
+                else
+                        format = PIPE_FORMAT_R8G8B8A8_UNORM;
+                desc = util_format_description(format);
+        }
+
         so->texture_bo = prsrc->bo->gpu;
         so->layout = prsrc->layout;
 
@@ -985,8 +997,6 @@
                 panfrost_translate_texture_type(so->base.target);
 
         if (device->quirks & IS_BIFROST) {
-                const struct util_format_description *desc =
-                        util_format_description(format);
                 unsigned char composed_swizzle[4];
                 util_format_compose_swizzles(desc->swizzle, user_swizzle, composed_swizzle);
 
diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
index 3cd9b65..f03cd9c 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -934,6 +934,10 @@
 void
 panfrost_resource_screen_init(struct pipe_screen *pscreen)
 {
+        struct panfrost_device *dev = pan_device(pscreen);
+
+        bool fake_rgtc = !panfrost_supports_compressed_format(dev, MALI_BC4_UNORM);
+
         //pscreen->base.resource_create_with_modifiers =
         //        panfrost_resource_create_with_modifiers;
         pscreen->resource_create = u_transfer_helper_resource_create;
@@ -942,7 +946,7 @@
         pscreen->resource_get_handle = panfrost_resource_get_handle;
         pscreen->transfer_helper = u_transfer_helper_create(&transfer_vtbl,
                                         true, false,
-                                        true, true);
+                                        fake_rgtc, true);
 }
 
 void
diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c
index a5d264e..e776add 100644
--- a/src/gallium/drivers/panfrost/pan_screen.c
+++ b/src/gallium/drivers/panfrost/pan_screen.c
@@ -463,11 +463,6 @@
         if (scanout && renderable && !util_format_is_rgba8_variant(format_desc))
                 return false;
 
-        if (dev->debug & (PAN_DBG_GL3 | PAN_DBG_DEQP)) {
-                if (format_desc->layout == UTIL_FORMAT_LAYOUT_RGTC)
-                        return true;
-        }
-
         /* Check we support the format with the given bind */
 
         unsigned relevant_bind = bind &
@@ -478,9 +473,12 @@
 
         /* Also check that compressed texture formats are supported on this
          * particular chip. They may not be depending on system integration
-         * differences. */
+         * differences. RGTC can be emulated so is always supported. */
 
-        if (!panfrost_supports_compressed_format(dev, fmt.hw))
+        bool is_rgtc = format_desc->layout == UTIL_FORMAT_LAYOUT_RGTC;
+        bool supported = panfrost_supports_compressed_format(dev, fmt.hw);
+
+        if (!is_rgtc && !supported)
                 return false;
 
         return fmt.hw && ((relevant_bind & ~fmt.bind) == 0);