From 636345f496f1a7d96b8da108e416defe7440904f Mon Sep 17 00:00:00 2001 From: Alexandros Frantzis Date: Mon, 20 May 2019 13:00:38 +0300 Subject: [PATCH] virgl: Support VIRGL_BIND_STAGING Support a new virgl bind type for staging buffers which don't require dedicated host-side storage. These will be used to implement copy transfers. Signed-off-by: Alexandros Frantzis Reviewed-by: Chia-I Wu --- src/gallium/drivers/virgl/virgl_hw.h | 1 + src/gallium/drivers/virgl/virgl_resource.c | 2 +- src/gallium/drivers/virgl/virgl_resource.h | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/virgl/virgl_hw.h b/src/gallium/drivers/virgl/virgl_hw.h index a01c48dd41f..50ccafcb0d6 100644 --- a/src/gallium/drivers/virgl/virgl_hw.h +++ b/src/gallium/drivers/virgl/virgl_hw.h @@ -262,6 +262,7 @@ enum virgl_formats { #define VIRGL_BIND_CURSOR (1 << 16) #define VIRGL_BIND_CUSTOM (1 << 17) #define VIRGL_BIND_SCANOUT (1 << 18) +#define VIRGL_BIND_STAGING (1 << 19) struct virgl_caps_bool_set1 { unsigned indep_blend_enable:1; diff --git a/src/gallium/drivers/virgl/virgl_resource.c b/src/gallium/drivers/virgl/virgl_resource.c index 1cb9feb3658..e334d55fa79 100644 --- a/src/gallium/drivers/virgl/virgl_resource.c +++ b/src/gallium/drivers/virgl/virgl_resource.c @@ -179,7 +179,7 @@ static struct pipe_resource *virgl_resource_create(struct pipe_screen *screen, res->u.b = *templ; res->u.b.screen = &vs->base; pipe_reference_init(&res->u.b.reference, 1); - vbind = pipe_to_virgl_bind(vs, templ->bind); + vbind = pipe_to_virgl_bind(vs, templ->bind, templ->flags); virgl_resource_layout(&res->u.b, &res->metadata); res->hw_res = vs->vws->resource_create(vs->vws, templ->target, templ->format, vbind, diff --git a/src/gallium/drivers/virgl/virgl_resource.h b/src/gallium/drivers/virgl/virgl_resource.h index f9a652367c2..87b3ea71673 100644 --- a/src/gallium/drivers/virgl/virgl_resource.h +++ b/src/gallium/drivers/virgl/virgl_resource.h @@ -33,6 +33,12 @@ #include "virgl_screen.h" #define VR_MAX_TEXTURE_2D_LEVELS 15 +/* Indicates that the resource will be used as a staging buffer, not requiring + * dedicated host-side storage. Can only be used with PIPE_BUFFER resources + * that have a PIPE_BIND_CUSTOM bind type. + */ +#define VIRGL_RESOURCE_FLAG_STAGING (PIPE_RESOURCE_FLAG_DRV_PRIV << 0) + struct winsys_handle; struct virgl_screen; struct virgl_context; @@ -90,7 +96,8 @@ static inline struct virgl_transfer *virgl_transfer(struct pipe_transfer *trans) void virgl_buffer_init(struct virgl_resource *res); -static inline unsigned pipe_to_virgl_bind(const struct virgl_screen *vs, unsigned pbind) +static inline unsigned pipe_to_virgl_bind(const struct virgl_screen *vs, + unsigned pbind, unsigned flags) { unsigned outbind = 0; if (pbind & PIPE_BIND_DEPTH_STENCIL) @@ -111,8 +118,12 @@ static inline unsigned pipe_to_virgl_bind(const struct virgl_screen *vs, unsigne outbind |= VIRGL_BIND_STREAM_OUTPUT; if (pbind & PIPE_BIND_CURSOR) outbind |= VIRGL_BIND_CURSOR; - if (pbind & PIPE_BIND_CUSTOM) - outbind |= VIRGL_BIND_CUSTOM; + if (pbind & PIPE_BIND_CUSTOM) { + if (flags & VIRGL_RESOURCE_FLAG_STAGING) + outbind |= VIRGL_BIND_STAGING; + else + outbind |= VIRGL_BIND_CUSTOM; + } if (pbind & PIPE_BIND_SCANOUT) outbind |= VIRGL_BIND_SCANOUT; if (pbind & PIPE_BIND_SHADER_BUFFER) -- 2.30.2