From: Icecream95 Date: Sat, 11 Jan 2020 06:19:45 +0000 (+1300) Subject: panfrost: Add ASTC texture formats X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=31bd3b52795faa02717d5cca3179965b0d207bea;p=mesa.git panfrost: Add ASTC texture formats Acked-by: Daniel Stone Reviewed-by: Alyssa Rosenzweig Part-of: --- diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 49716ab9bc4..1cd9cf3f24c 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -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 diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index 53ce9ec71df..98d327cfde4 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -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; }; diff --git a/src/gallium/drivers/panfrost/pan_format.c b/src/gallium/drivers/panfrost/pan_format.c index 040b01d9e5b..c52756301b9 100644 --- a/src/gallium/drivers/panfrost/pan_format.c +++ b/src/gallium/drivers/panfrost/pan_format.c @@ -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); diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index b7d24c93ea2..8b8de9d6ef2 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -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; diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h index 95356699186..0861d10e509 100644 --- a/src/panfrost/include/panfrost-job.h +++ b/src/panfrost/include/panfrost-job.h @@ -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,