winsys/svga: use new pb_usage_flags enum type
authorBrian Paul <brianp@vmware.com>
Tue, 5 Mar 2019 21:20:29 +0000 (14:20 -0700)
committerBrian Paul <brianp@vmware.com>
Fri, 8 Mar 2019 14:40:35 +0000 (07:40 -0700)
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.

Reviewed-by: Neha Bhende <bhenden@vmware.com>
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
src/gallium/winsys/svga/drm/vmw_buffer.c
src/gallium/winsys/svga/drm/vmw_buffer.h
src/gallium/winsys/svga/drm/vmw_context.c

index 3ac80c7caf530290893551b319996d1c9ac9d618..91b5b259435ed9367d00f5972f9128288b8f2ba4 100644 (file)
@@ -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
index 6e1151e5f3632ad8ce5d70bff027dbef5b8ce56c..8ed56d4aa1e7ddd0351bbc0301ad63f2361f7266 100644 (file)
@@ -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)
 
index c0ee833e334924c1148cee2b0284b0764e92e474..59963ff7a82c3337a94286586f26b864b3832af3 100644 (file)
@@ -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;