[Mesa-dev] [PATCH 09/25] radeonsi: add basic memory object support

Marek Olšák maraeo at gmail.com
Tue Jul 11 22:19:00 UTC 2017


On Fri, Jul 7, 2017 at 6:24 AM, Andres Rodriguez <andresx7 at gmail.com> wrote:
> From: Dave Airlie <airlied at redhat.com>
>
> Signed-off-by: Andres Rodriguez <andresx7 at gmail.com>
> ---
>  src/gallium/drivers/radeon/r600_pipe_common.h |   7 ++
>  src/gallium/drivers/radeon/r600_texture.c     | 112 ++++++++++++++++++++++++++
>  2 files changed, 119 insertions(+)
>
> diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h b/src/gallium/drivers/radeon/r600_pipe_common.h
> index b22a3a7..4c1a706 100644
> --- a/src/gallium/drivers/radeon/r600_pipe_common.h
> +++ b/src/gallium/drivers/radeon/r600_pipe_common.h
> @@ -377,6 +377,13 @@ union r600_mmio_counters {
>         unsigned array[0];
>  };
>
> +struct r600_memory_object {
> +       struct pipe_memory_object       b;
> +       struct pb_buffer                *buf;
> +       uint32_t                        stride;
> +       uint32_t                        offset;
> +};
> +
>  struct r600_common_screen {
>         struct pipe_screen              b;
>         struct radeon_winsys            *ws;
> diff --git a/src/gallium/drivers/radeon/r600_texture.c b/src/gallium/drivers/radeon/r600_texture.c
> index 2deb56a..0baa0ee 100644
> --- a/src/gallium/drivers/radeon/r600_texture.c
> +++ b/src/gallium/drivers/radeon/r600_texture.c
> @@ -2822,10 +2822,122 @@ void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
>         }
>  }
>
> +static struct pipe_memory_object *
> +r600_memobj_from_handle(struct pipe_screen *screen,
> +                       struct winsys_handle *whandle,
> +                       bool dedicated)
> +{
> +       struct r600_common_screen *rscreen = (struct r600_common_screen*)screen;
> +       struct r600_memory_object *memobj = CALLOC_STRUCT(r600_memory_object);
> +       struct pb_buffer *buf = NULL;
> +       uint32_t stride, offset;
> +
> +       if (!memobj)
> +               return NULL;
> +
> +       buf = rscreen->ws->buffer_from_handle(rscreen->ws, whandle,
> +                                             &stride, &offset);
> +       if (!buf)
> +               return NULL;
> +
> +       memobj->b.dedicated = dedicated;
> +       memobj->buf = buf;
> +       memobj->stride = stride;
> +       memobj->offset = offset;
> +
> +       return (struct pipe_memory_object *)memobj;
> +}
> +
> +static void
> +r600_memobj_destroy(struct pipe_screen *screen,
> +                   struct pipe_memory_object *memobj)
> +{
> +       free(memobj);
> +}
> +
> +static struct pipe_resource *
> +r600_texture_from_memobj(struct pipe_screen *screen,
> +                        const struct pipe_resource *templ,
> +                        struct pipe_memory_object *_memobj,
> +                        uint64_t offset)
> +{
> +       int r;
> +       struct r600_common_screen *rscreen = (struct r600_common_screen*)screen;
> +       struct r600_memory_object *memobj = (struct r600_memory_object *)_memobj;
> +       struct r600_texture *rtex;
> +       struct radeon_surf surface;
> +       struct radeon_bo_metadata metadata = {};
> +       unsigned array_mode;
> +
> +       if (memobj->b.dedicated) {
> +               rscreen->ws->buffer_get_metadata(memobj->buf, &metadata);
> +
> +               surface.u.legacy.pipe_config = metadata.u.legacy.pipe_config;
> +               surface.u.legacy.bankw = metadata.u.legacy.bankw;
> +               surface.u.legacy.bankh = metadata.u.legacy.bankh;
> +               surface.u.legacy.tile_split = metadata.u.legacy.tile_split;
> +               surface.u.legacy.mtilea = metadata.u.legacy.mtilea;
> +               surface.u.legacy.num_banks = metadata.u.legacy.num_banks;
> +
> +               if (metadata.u.legacy.macrotile == RADEON_LAYOUT_TILED)
> +                       array_mode = RADEON_SURF_MODE_2D;
> +               else if (metadata.u.legacy.microtile == RADEON_LAYOUT_TILED)
> +                       array_mode = RADEON_SURF_MODE_1D;
> +               else
> +                       array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;

This "legacy" metadata is only for SI-CI-VI. GFX9 should be handled here too.

Marek


More information about the mesa-dev mailing list