panfrost: Add ASTC texture formats
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>
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index 49716ab..1cd9cf3 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -601,7 +601,7 @@
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 @@
}
}
+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 @@
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
diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h
index 53ce9ec..98d327c 100644
--- a/src/gallium/drivers/panfrost/pan_context.h
+++ b/src/gallium/drivers/panfrost/pan_context.h
@@ -273,6 +273,7 @@
struct panfrost_sampler_view {
struct pipe_sampler_view base;
struct mali_texture_descriptor hw;
+ uint8_t astc_stretch;
bool manual_stride;
};
diff --git a/src/gallium/drivers/panfrost/pan_format.c b/src/gallium/drivers/panfrost/pan_format.c
index 040b01d..c527563 100644
--- a/src/gallium/drivers/panfrost/pan_format.c
+++ b/src/gallium/drivers/panfrost/pan_format.c
@@ -245,6 +245,13 @@
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);
diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c
index b7d24c9..8b8de9d 100644
--- a/src/gallium/drivers/panfrost/pan_screen.c
+++ b/src/gallium/drivers/panfrost/pan_screen.c
@@ -464,6 +464,7 @@
case UTIL_FORMAT_LAYOUT_OTHER:
break;
case UTIL_FORMAT_LAYOUT_ETC:
+ case UTIL_FORMAT_LAYOUT_ASTC:
return true;
default:
return false;
diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h
index 9535669..0861d10 100644
--- a/src/panfrost/include/panfrost-job.h
+++ b/src/panfrost/include/panfrost-job.h
@@ -283,6 +283,8 @@
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,