freedreno: Add layout_resource_for_modifier screen vfunc
authorKristian H. Kristensen <hoegsberg@google.com>
Wed, 5 Feb 2020 01:46:10 +0000 (17:46 -0800)
committerMarge Bot <eric+marge@anholt.net>
Wed, 5 Feb 2020 20:53:32 +0000 (20:53 +0000)
This function is responsible for completing the layout for an imported
resource with the given modifier.  Returns 0 on success or -1 If the
modifier is unsupported, invalid or the input parameters are not
compatible with the modifier.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3704>

src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_screen.h

index 54bf359a0cc3b5766670e5f1233659584c4da619..56f5c478b275edfc43c9c73b29f690bf1a7ee7a2 100644 (file)
@@ -1023,26 +1023,6 @@ fd_resource_create(struct pipe_screen *pscreen,
        return fd_resource_create_with_modifiers(pscreen, tmpl, &mod, 1);
 }
 
-static bool
-is_supported_modifier(struct pipe_screen *pscreen, enum pipe_format pfmt,
-               uint64_t mod)
-{
-       int count;
-
-       /* Get the count of supported modifiers: */
-       pscreen->query_dmabuf_modifiers(pscreen, pfmt, 0, NULL, NULL, &count);
-
-       /* Get the supported modifiers: */
-       uint64_t modifiers[count];
-       pscreen->query_dmabuf_modifiers(pscreen, pfmt, count, modifiers, NULL, &count);
-
-       for (int i = 0; i < count; i++)
-               if (modifiers[i] == mod)
-                       return true;
-
-       return false;
-}
-
 /**
  * Create a texture from a winsys_handle. The handle is often created in
  * another process by first creating a pipe texture and then calling
@@ -1091,20 +1071,11 @@ fd_resource_from_handle(struct pipe_screen *pscreen,
                        (slice->pitch & (pitchalign - 1)))
                goto fail;
 
-       if (handle->modifier == DRM_FORMAT_MOD_QCOM_COMPRESSED) {
-               if (!is_supported_modifier(pscreen, tmpl->format,
-                               DRM_FORMAT_MOD_QCOM_COMPRESSED)) {
-                       DBG("bad modifier: %"PRIx64, handle->modifier);
-                       goto fail;
-               }
-               /* XXX UBWC setup */
-       } else if (handle->modifier &&
-                       (handle->modifier != DRM_FORMAT_MOD_INVALID)) {
-               goto fail;
-       }
-
        assert(rsc->layout.cpp);
 
+       if (screen->layout_resource_for_modifier(rsc, handle->modifier) < 0)
+               goto fail;
+
        if (screen->ro) {
                rsc->scanout =
                        renderonly_create_gpu_import_for_resource(prsc, screen->ro, NULL);
@@ -1210,6 +1181,17 @@ static const uint64_t supported_modifiers[] = {
        DRM_FORMAT_MOD_LINEAR,
 };
 
+static int
+fd_layout_resource_for_modifier(struct fd_resource *rsc, uint64_t modifier)
+{
+       switch (modifier) {
+       case DRM_FORMAT_MOD_LINEAR:
+               return 0;
+       default:
+               return -1;
+       }
+}
+
 void
 fd_resource_screen_init(struct pipe_screen *pscreen)
 {
@@ -1230,6 +1212,8 @@ fd_resource_screen_init(struct pipe_screen *pscreen)
 
        if (!screen->setup_slices)
                screen->setup_slices = fd_setup_slices;
+       if (!screen->layout_resource_for_modifier)
+               screen->layout_resource_for_modifier = fd_layout_resource_for_modifier;
        if (!screen->supported_modifiers) {
                screen->supported_modifiers = supported_modifiers;
                screen->num_supported_modifiers = ARRAY_SIZE(supported_modifiers);
index b5730da0297b2b5123eb65e46dd1e8929347117a..534d0a2f85934c51e9fd5cd185e5d04a9c4b8661 100644 (file)
@@ -93,6 +93,7 @@ struct fd_screen {
 
        uint32_t (*setup_slices)(struct fd_resource *rsc);
        unsigned (*tile_mode)(const struct pipe_resource *prsc);
+       int (*layout_resource_for_modifier)(struct fd_resource *rsc, uint64_t modifier);
 
        /* constant emit:  (note currently not used/needed for a2xx) */
        void (*emit_const)(struct fd_ringbuffer *ring, gl_shader_stage type,