panfrost: Add ASTC texture formats
authorIcecream95 <ixn@keemail.me>
Sat, 11 Jan 2020 06:19:45 +0000 (19:19 +1300)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 21 Jan 2020 13:35:23 +0000 (08:35 -0500)
Acked-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3414>

src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h
src/gallium/drivers/panfrost/pan_format.c
src/gallium/drivers/panfrost/pan_screen.c
src/panfrost/include/panfrost-job.h

index 49716ab9bc446b5546835bfe1ce359d2af1d8993..1cd9cf3f24cfc579ca931192922daf320baa9c43 100644 (file)
@@ -601,7 +601,7 @@ panfrost_upload_tex(
                         for (unsigned f = first_face; f <= last_face; ++f) {
                                 pointers_and_strides[idx++] =
                                         panfrost_get_texture_address(rsrc, l, w*face_mult + f)
-                                                + afbc_bit;
+                                                + afbc_bit + view->astc_stretch;
 
                                 if (has_manual_stride) {
                                         pointers_and_strides[idx++] =
@@ -2124,6 +2124,21 @@ panfrost_translate_texture_type(enum pipe_texture_target t) {
         }
 }
 
+static uint8_t
+panfrost_compute_astc_stretch(
+        const struct util_format_description *desc)
+{
+        unsigned width = desc->block.width;
+        unsigned height = desc->block.height;
+        assert(width >= 4 && width <= 12);
+        assert(height >= 4 && height <= 12);
+        if (width == 12)
+                width = 11;
+        if (height == 12)
+                height = 11;
+        return ((height - 4) * 8) + (width - 4);
+}
+
 static struct pipe_sampler_view *
 panfrost_create_sampler_view(
         struct pipe_context *pctx,
@@ -2158,6 +2173,9 @@ panfrost_create_sampler_view(
 
         enum mali_format format = panfrost_find_format(desc);
 
+        if (format == MALI_ASTC_HDR_SUPP || format == MALI_ASTC_SRGB_SUPP)
+                so->astc_stretch = panfrost_compute_astc_stretch(desc);
+
         /* Check if we need to set a custom stride by computing the "expected"
          * stride and comparing it to what the BO actually wants. Only applies
          * to linear textures, since tiled/compressed textures have strict
index 53ce9ec71df47b46964eb7f21598687c61fb713f..98d327cfde499f30b8e8f256771d1e5cf2d004ad 100644 (file)
@@ -273,6 +273,7 @@ struct panfrost_sampler_state {
 struct panfrost_sampler_view {
         struct pipe_sampler_view base;
         struct mali_texture_descriptor hw;
+        uint8_t astc_stretch;
         bool manual_stride;
 };
 
index 040b01d9e5bd4f4c95906e2c6f714e5e0753bf6e..c52756301b99e19635a51963d3468df03c02ccbb 100644 (file)
@@ -245,6 +245,13 @@ panfrost_find_format(const struct util_format_description *desc) {
                 break;
         }
 
+        if (desc->layout == UTIL_FORMAT_LAYOUT_ASTC) {
+                if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
+                        return MALI_ASTC_SRGB_SUPP;
+                else
+                        return MALI_ASTC_HDR_SUPP;
+        }
+
         /* Formats must match in channel count */
         assert(desc->nr_channels >= 1 && desc->nr_channels <= 4);
         unsigned format = MALI_NR_CHANNELS(desc->nr_channels);
index b7d24c93ea24965c5198bed4beac2a9bfa4b7723..8b8de9d6ef25fe8853fcc836dfa686f7c913b37a 100644 (file)
@@ -464,6 +464,7 @@ panfrost_is_format_supported( struct pipe_screen *screen,
                 case UTIL_FORMAT_LAYOUT_OTHER:
                         break;
                 case UTIL_FORMAT_LAYOUT_ETC:
+                case UTIL_FORMAT_LAYOUT_ASTC:
                         return true;
                 default:
                         return false;
index 9535669918665632b3aee83f5f84b5ddcdb19797..0861d10e5096b4180a0449e50d95cc574efb5905 100644 (file)
@@ -283,6 +283,8 @@ enum mali_format {
        MALI_ETC2_R11_SNORM  = MALI_FORMAT_COMPRESSED | 0x11,
        MALI_ETC2_RG11_SNORM = MALI_FORMAT_COMPRESSED | 0x12,
        MALI_ETC2_RGB8A1     = MALI_FORMAT_COMPRESSED | 0x13,
+       MALI_ASTC_SRGB_SUPP  = MALI_FORMAT_COMPRESSED | 0x16,
+       MALI_ASTC_HDR_SUPP   = MALI_FORMAT_COMPRESSED | 0x17,
 
        MALI_RGB565         = MALI_FORMAT_SPECIAL | 0x0,
        MALI_RGB5_A1_UNORM  = MALI_FORMAT_SPECIAL | 0x2,