freedreno: Implement memory object create/destroy for GL_EXT_memory_object
authorEduardo Lima Mitev <elima@igalia.com>
Tue, 7 Apr 2020 06:52:25 +0000 (08:52 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 18 Aug 2020 20:40:40 +0000 (20:40 +0000)
v2: Add implementation of fd_memobj_destroy() virtual func, which was newly
added.

v3: The memobj bo must be non-NULL and destroyed as part of memobj
destruction (instead of its reference being stolen). (Rob Clark)

Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4565>

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

index 07baa7d293b16f8bc7e4b5fc9dc6ab39838d9331..1696cb8cc9ca75604866e6423f62eee0c5afa4fb 100644 (file)
@@ -1173,6 +1173,39 @@ fd_layout_resource_for_modifier(struct fd_resource *rsc, uint64_t modifier)
        }
 }
 
+static struct pipe_memory_object *
+fd_memobj_create_from_handle(struct pipe_screen *pscreen,
+                                                        struct winsys_handle *whandle,
+                                                        bool dedicated)
+{
+       struct fd_memory_object *memobj = CALLOC_STRUCT(fd_memory_object);
+       if (!memobj)
+               return NULL;
+
+       struct fd_bo *bo = fd_screen_bo_from_handle(pscreen, whandle);
+       if (!bo) {
+               free(memobj);
+               return NULL;
+       }
+
+       memobj->b.dedicated = dedicated;
+       memobj->bo = bo;
+
+       return &memobj->b;
+}
+
+static void
+fd_memobj_destroy(struct pipe_screen *pscreen,
+               struct pipe_memory_object *pmemobj)
+{
+       struct fd_memory_object *memobj = fd_memory_object(pmemobj);
+
+       assert(memobj->bo);
+       fd_bo_del(memobj->bo);
+
+       free(pmemobj);
+}
+
 void
 fd_resource_screen_init(struct pipe_screen *pscreen)
 {
@@ -1197,6 +1230,10 @@ fd_resource_screen_init(struct pipe_screen *pscreen)
                screen->supported_modifiers = supported_modifiers;
                screen->num_supported_modifiers = ARRAY_SIZE(supported_modifiers);
        }
+
+       /* GL_EXT_memory_object */
+       pscreen->memobj_create_from_handle = fd_memobj_create_from_handle;
+       pscreen->memobj_destroy = fd_memobj_destroy;
 }
 
 static void
index 9419097dcdfe82be30e148369c165eebab930718..f2382d75be222b0c8e02058a883337dc879bfb03 100644 (file)
@@ -101,6 +101,11 @@ struct fd_resource {
        struct fd_bo *lrz;
 };
 
+struct fd_memory_object {
+       struct pipe_memory_object b;
+       struct fd_bo *bo;
+};
+
 static inline struct fd_resource *
 fd_resource(struct pipe_resource *ptex)
 {
@@ -113,6 +118,12 @@ fd_resource_const(const struct pipe_resource *ptex)
        return (const struct fd_resource *)ptex;
 }
 
+static inline struct fd_memory_object *
+fd_memory_object (struct pipe_memory_object *pmemobj)
+{
+       return (struct fd_memory_object *)pmemobj;
+}
+
 static inline bool
 pending(struct fd_resource *rsc, bool write)
 {