virgl: Support VIRGL_BIND_STAGING
authorAlexandros Frantzis <alexandros.frantzis@collabora.com>
Mon, 20 May 2019 10:00:38 +0000 (13:00 +0300)
committerChia-I Wu <olvaffe@gmail.com>
Sat, 8 Jun 2019 04:45:31 +0000 (21:45 -0700)
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 <alexandros.frantzis@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
src/gallium/drivers/virgl/virgl_hw.h
src/gallium/drivers/virgl/virgl_resource.c
src/gallium/drivers/virgl/virgl_resource.h

index a01c48dd41f5340433451038be9db56b966329f6..50ccafcb0d6687d0e9c22cb37e4af8720980a50a 100644 (file)
@@ -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;
index 1cb9feb3658ea42033de2c2a66995cdc6e8a79ee..e334d55fa79b2a43e94d1a5510bf17177f8d6148 100644 (file)
@@ -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,
index f9a652367c23e585a4a29461a68418ce4c7d2f4f..87b3ea716737d9c924be6a347ca496c7b6ee3320 100644 (file)
 #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)