From 407a052ced43e4754fc46c20eb8e55feaaae105a Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 10 Jul 2020 10:42:24 -0400 Subject: [PATCH] panfrost: Pipe in compressed texture feature mask So we can query at run-time as part of Gallium's checks. v2: More explicit naming. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/encoder/pan_device.h | 6 +++++ src/panfrost/encoder/pan_props.c | 40 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/panfrost/encoder/pan_device.h b/src/panfrost/encoder/pan_device.h index 44afb411806..e68d0445f08 100644 --- a/src/panfrost/encoder/pan_device.h +++ b/src/panfrost/encoder/pan_device.h @@ -80,6 +80,9 @@ struct panfrost_device { unsigned thread_tls_alloc; unsigned quirks; + /* Bitmask of supported compressed texture formats */ + uint32_t compressed_formats; + /* debug flags, see pan_util.h how to interpret */ unsigned debug; @@ -114,6 +117,9 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev); void panfrost_close_device(struct panfrost_device *dev); +bool +panfrost_supports_compressed_format(struct panfrost_device *dev, unsigned fmt); + static inline struct panfrost_bo * pan_lookup_bo(struct panfrost_device *dev, uint32_t gem_handle) { diff --git a/src/panfrost/encoder/pan_props.c b/src/panfrost/encoder/pan_props.c index 3ff0dbfdf93..df471a73c8d 100644 --- a/src/panfrost/encoder/pan_props.c +++ b/src/panfrost/encoder/pan_props.c @@ -93,6 +93,45 @@ panfrost_query_thread_tls_alloc(int fd) return 256; } +static uint32_t +panfrost_query_compressed_formats(int fd) +{ + /* If unspecified, assume ASTC/ETC only. Factory default for Juno, and + * should exist on any Mali configuration. All hardware should report + * these texture formats but the kernel might not be new enough. */ + + uint32_t default_set = + (1 << MALI_ETC2_RGB8) | + (1 << MALI_ETC2_R11_UNORM) | + (1 << MALI_ETC2_RGBA8) | + (1 << MALI_ETC2_RG11_UNORM) | + (1 << MALI_ETC2_R11_SNORM) | + (1 << MALI_ETC2_RG11_SNORM) | + (1 << MALI_ETC2_RGB8A1) | + (1 << MALI_ASTC_3D_LDR) | + (1 << MALI_ASTC_3D_HDR) | + (1 << MALI_ASTC_2D_LDR) | + (1 << MALI_ASTC_2D_HDR); + + return panfrost_query_raw(fd, DRM_PANFROST_PARAM_TEXTURE_FEATURES0, + false, default_set); +} + +/* DRM_PANFROST_PARAM_TEXTURE_FEATURES0 will return a bitmask of supported + * compressed formats, so we offer a helper to test if a format is supported */ + +bool +panfrost_supports_compressed_format(struct panfrost_device *dev, unsigned fmt) +{ + if (MALI_EXTRACT_TYPE(fmt) != MALI_FORMAT_COMPRESSED) + return true; + + unsigned idx = fmt & ~MALI_FORMAT_COMPRESSED; + assert(idx < 32); + + return dev->compressed_formats & (1 << idx); +} + /* Given a GPU ID like 0x860, return a prettified model name */ const char * @@ -124,6 +163,7 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev) dev->thread_tls_alloc = panfrost_query_thread_tls_alloc(fd); dev->kernel_version = drmGetVersion(fd); dev->quirks = panfrost_get_quirks(dev->gpu_id); + dev->compressed_formats = panfrost_query_compressed_formats(fd); util_sparse_array_init(&dev->bo_map, sizeof(struct panfrost_bo), 512); -- 2.30.2