From: Eduardo Lima Mitev Date: Tue, 7 Apr 2020 06:52:25 +0000 (+0200) Subject: freedreno: Implement memory object create/destroy for GL_EXT_memory_object X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0eecd3d68466327567df7da468cc2088a652e22f;p=mesa.git freedreno: Implement memory object create/destroy for GL_EXT_memory_object 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 Part-of: --- diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index 07baa7d293b..1696cb8cc9c 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -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 diff --git a/src/gallium/drivers/freedreno/freedreno_resource.h b/src/gallium/drivers/freedreno/freedreno_resource.h index 9419097dcdf..f2382d75be2 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.h +++ b/src/gallium/drivers/freedreno/freedreno_resource.h @@ -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) {