panfrost: Implement panfrost_query_dmabuf_modifiers
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 22 Jul 2020 16:11:39 +0000 (12:11 -0400)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 12 Aug 2020 13:59:21 +0000 (09:59 -0400)
v2: Only advertise AFBC if PAN_MESA_DEBUG=afbc is set. This is to avoid
sharing AFBC buffers as SCANOUT until corresponding kernel bugfixes are
landed. Technically a kernel issue but let's prevent a regression.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tested-by: Icecream95 <ixn@keemail.me> [v1]
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6159>

src/gallium/drivers/panfrost/pan_screen.c

index eed910fb3f8077fcb0783504872088e126edbb12..9942ea8e1afdb8f821bb85f2208b0d703ef58b88 100644 (file)
@@ -59,7 +59,7 @@ static const struct debug_named_value debug_options[] = {
         {"msgs",      PAN_DBG_MSGS,    "Print debug messages"},
         {"trace",     PAN_DBG_TRACE,    "Trace the command stream"},
         {"deqp",      PAN_DBG_DEQP,     "Hacks for dEQP"},
-        {"afbc",      PAN_DBG_AFBC,     "Enable non-conformant AFBC impl"},
+        {"afbc",      PAN_DBG_AFBC,     "Enable AFBC buffer sharing"},
         {"sync",      PAN_DBG_SYNC,     "Wait for each job's completion and check for any GPU fault"},
         {"precompile", PAN_DBG_PRECOMPILE, "Precompile shaders for shader-db"},
         {"nofp16",     PAN_DBG_NOFP16,     "Disable 16-bit support"},
@@ -485,6 +485,48 @@ panfrost_is_format_supported( struct pipe_screen *screen,
         return fmt.hw && ((relevant_bind & ~fmt.bind) == 0);
 }
 
+/* We always support linear and tiled operations, both external and internal.
+ * We support AFBC for a subset of formats, and colourspace transform for a
+ * subset of those. */
+
+static void
+panfrost_query_dmabuf_modifiers(struct pipe_screen *screen,
+                enum pipe_format format, int max, uint64_t *modifiers, unsigned
+                int *external_only, int *out_count)
+{
+        /* Query AFBC status */
+        bool afbc = panfrost_format_supports_afbc(format);
+        bool ytr = panfrost_afbc_can_ytr(format);
+
+        /* Don't advertise AFBC before T760 */
+        struct panfrost_device *dev = pan_device(screen);
+        afbc &= !(dev->quirks & MIDGARD_NO_AFBC);
+
+        /* XXX: AFBC scanout is broken on mainline RK3399 with older kernels */
+        afbc &= (dev->debug & PAN_DBG_AFBC);
+
+        unsigned count = 0;
+
+        for (unsigned i = 0; i < PAN_MODIFIER_COUNT; ++i) {
+                if (drm_is_afbc(pan_best_modifiers[i]) && !afbc)
+                        continue;
+
+                if ((pan_best_modifiers[i] & AFBC_FORMAT_MOD_YTR) && !ytr)
+                        continue;
+
+                count++;
+
+                if (max > (int) count) {
+                        modifiers[count] = pan_best_modifiers[i];
+
+                        if (external_only)
+                                external_only[count] = false;
+                }
+        }
+
+        *out_count = count;
+}
+
 static int
 panfrost_get_compute_param(struct pipe_screen *pscreen, enum pipe_shader_ir ir_type,
                 enum pipe_compute_cap param, void *ret)
@@ -695,6 +737,7 @@ panfrost_create_screen(int fd, struct renderonly *ro)
         screen->base.get_paramf = panfrost_get_paramf;
         screen->base.get_timestamp = panfrost_get_timestamp;
         screen->base.is_format_supported = panfrost_is_format_supported;
+        screen->base.query_dmabuf_modifiers = panfrost_query_dmabuf_modifiers;
         screen->base.context_create = panfrost_create_context;
         screen->base.get_compiler_options = panfrost_screen_get_compiler_options;
         screen->base.fence_reference = panfrost_fence_reference;