[Mesa-dev] [PATCH 3/3] winsys/svga: use new pb_usage_flags enum type

Neha Bhende bhenden at vmware.com
Wed Mar 6 07:06:31 UTC 2019


For the series,

Reviewed-by: Neha Bhende <bhenden at vmware.com>


Regards,

Neha

________________________________
From: Brian Paul <brianp at vmware.com>
Sent: Tuesday, March 5, 2019 7:48 PM
To: mesa-dev at lists.freedesktop.org
Cc: Neha Bhende; Deepak Singh Rawat; Thomas Hellstrom
Subject: [PATCH 3/3] winsys/svga: use new pb_usage_flags enum type

And add a comment that we're implicitly converting PIPE_TRANSFER_
flags to PB_USAGE_ flags in one place.  And statically assert that
the enum values match.
---
 src/gallium/winsys/svga/drm/vmw_buffer.c  | 27 +++++++++++++++++++++++----
 src/gallium/winsys/svga/drm/vmw_buffer.h  |  1 +
 src/gallium/winsys/svga/drm/vmw_context.c |  4 ++--
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/gallium/winsys/svga/drm/vmw_buffer.c b/src/gallium/winsys/svga/drm/vmw_buffer.c
index 3ac80c7..91b5b25 100644
--- a/src/gallium/winsys/svga/drm/vmw_buffer.c
+++ b/src/gallium/winsys/svga/drm/vmw_buffer.c
@@ -90,6 +90,11 @@ static inline struct vmw_gmr_bufmgr *
 vmw_gmr_bufmgr(struct pb_manager *mgr)
 {
    assert(mgr);
+
+   /* Make sure our extra flags don't collide with pipebuffer's flags */
+   STATIC_ASSERT((VMW_BUFFER_USAGE_SHARED & PB_USAGE_ALL) == 0);
+   STATIC_ASSERT((VMW_BUFFER_USAGE_SYNC & PB_USAGE_ALL) == 0);
+
    return (struct vmw_gmr_bufmgr *)mgr;
 }

@@ -109,7 +114,7 @@ vmw_gmr_buffer_destroy(struct pb_buffer *_buf)

 static void *
 vmw_gmr_buffer_map(struct pb_buffer *_buf,
-                   unsigned flags,
+                   enum pb_usage_flags flags,
                    void *flush_ctx)
 {
    struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf);
@@ -140,7 +145,7 @@ static void
 vmw_gmr_buffer_unmap(struct pb_buffer *_buf)
 {
    struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf);
-   unsigned flags = buf->map_flags;
+   enum pb_usage_flags flags = buf->map_flags;

    if ((_buf->usage & VMW_BUFFER_USAGE_SYNC) &&
        !(flags & PB_USAGE_UNSYNCHRONIZED)) {
@@ -164,7 +169,7 @@ vmw_gmr_buffer_get_base_buffer(struct pb_buffer *buf,
 static enum pipe_error
 vmw_gmr_buffer_validate( struct pb_buffer *_buf,
                          struct pb_validate *vl,
-                         unsigned flags )
+                         enum pb_usage_flags flags )
 {
    /* Always pinned */
    return PIPE_OK;
@@ -338,7 +343,7 @@ vmw_svga_winsys_buffer_destroy(struct svga_winsys_screen *sws,
 void *
 vmw_svga_winsys_buffer_map(struct svga_winsys_screen *sws,
                            struct svga_winsys_buffer *buf,
-                           unsigned flags)
+                           enum pipe_transfer_usage flags)
 {
    void *map;

@@ -346,6 +351,20 @@ vmw_svga_winsys_buffer_map(struct svga_winsys_screen *sws,
    if (flags & PIPE_TRANSFER_UNSYNCHRONIZED)
       flags &= ~PIPE_TRANSFER_DONTBLOCK;

+   /* NOTE: we're passing PIPE_TRANSFER_x flags instead of
+    * PB_USAGE_x flags here.  We should probably fix that.
+    */
+   STATIC_ASSERT((unsigned) PB_USAGE_CPU_READ ==
+                 (unsigned) PIPE_TRANSFER_READ);
+   STATIC_ASSERT((unsigned) PB_USAGE_CPU_WRITE ==
+                 (unsigned) PIPE_TRANSFER_WRITE);
+   STATIC_ASSERT((unsigned) PB_USAGE_GPU_READ ==
+                 (unsigned) PIPE_TRANSFER_MAP_DIRECTLY);
+   STATIC_ASSERT((unsigned) PB_USAGE_DONTBLOCK ==
+                 (unsigned) PIPE_TRANSFER_DONTBLOCK);
+   STATIC_ASSERT((unsigned) PB_USAGE_UNSYNCHRONIZED ==
+                 (unsigned) PIPE_TRANSFER_UNSYNCHRONIZED);
+
    map = pb_map(vmw_pb_buffer(buf), flags, NULL);

 #ifdef DEBUG
diff --git a/src/gallium/winsys/svga/drm/vmw_buffer.h b/src/gallium/winsys/svga/drm/vmw_buffer.h
index 6e1151e..8ed56d4 100644
--- a/src/gallium/winsys/svga/drm/vmw_buffer.h
+++ b/src/gallium/winsys/svga/drm/vmw_buffer.h
@@ -33,6 +33,7 @@
 #include "util/u_debug_flush.h"


+/* These extra flags are used wherever the pb_usage_flags enum type is used */
 #define VMW_BUFFER_USAGE_SHARED    (1 << 20)
 #define VMW_BUFFER_USAGE_SYNC      (1 << 21)

diff --git a/src/gallium/winsys/svga/drm/vmw_context.c b/src/gallium/winsys/svga/drm/vmw_context.c
index c0ee833..59963ff 100644
--- a/src/gallium/winsys/svga/drm/vmw_context.c
+++ b/src/gallium/winsys/svga/drm/vmw_context.c
@@ -161,10 +161,10 @@ vmw_svga_winsys_context(struct svga_winsys_context *swc)
 }


-static inline unsigned
+static inline enum pb_usage_flags
 vmw_translate_to_pb_flags(unsigned flags)
 {
-   unsigned f = 0;
+   enum pb_usage_flags f = 0;
    if (flags & SVGA_RELOC_READ)
       f |= PB_USAGE_GPU_READ;

--
1.8.5.6

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20190306/2ac2d5bc/attachment-0001.html>


More information about the mesa-dev mailing list