pipebuffer: use new pb_usage_flags enum type
authorBrian Paul <brianp@vmware.com>
Tue, 5 Mar 2019 21:08:35 +0000 (14:08 -0700)
committerBrian Paul <brianp@vmware.com>
Fri, 8 Mar 2019 14:40:35 +0000 (07:40 -0700)
Use a new enum type instead of 'unsigned' to make things a bit more
understandable.

Reviewed-by: Neha Bhende <bhenden@vmware.com>
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
src/gallium/auxiliary/pipebuffer/pb_buffer.h
src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c
src/gallium/auxiliary/pipebuffer/pb_validate.c
src/gallium/auxiliary/pipebuffer/pb_validate.h

index 33c23068c275b94fd0a4853427a53680fb0dd713..11f70ead51a65cb069bcc690834963997dcd3773 100644 (file)
@@ -59,13 +59,22 @@ struct pb_vtbl;
 struct pb_validate;
 struct pipe_fence_handle;
 
+enum pb_usage_flags {
+   PB_USAGE_CPU_READ = (1 << 0),
+   PB_USAGE_CPU_WRITE = (1 << 1),
+   PB_USAGE_GPU_READ = (1 << 2),
+   PB_USAGE_GPU_WRITE = (1 << 3),
+   PB_USAGE_DONTBLOCK = (1 << 9),
+   PB_USAGE_UNSYNCHRONIZED = (1 << 10),
+};
 
-#define PB_USAGE_CPU_READ  (1 << 0)
-#define PB_USAGE_CPU_WRITE (1 << 1)
-#define PB_USAGE_GPU_READ  (1 << 2)
-#define PB_USAGE_GPU_WRITE (1 << 3)
-#define PB_USAGE_UNSYNCHRONIZED (1 << 10)
-#define PB_USAGE_DONTBLOCK (1 << 9)
+/* For error checking elsewhere */
+#define PB_USAGE_ALL (PB_USAGE_CPU_READ | \
+                      PB_USAGE_CPU_WRITE | \
+                      PB_USAGE_GPU_READ | \
+                      PB_USAGE_GPU_WRITE | \
+                      PB_USAGE_DONTBLOCK | \
+                      PB_USAGE_UNSYNCHRONIZED)
 
 #define PB_USAGE_CPU_READ_WRITE \
    ( PB_USAGE_CPU_READ | PB_USAGE_CPU_WRITE )
@@ -82,7 +91,7 @@ struct pipe_fence_handle;
 struct pb_desc
 {
    unsigned alignment;
-   unsigned usage;
+   enum pb_usage_flags usage;
 };
 
 
@@ -100,7 +109,7 @@ struct pb_buffer
    struct pipe_reference  reference;
    unsigned               alignment;
    pb_size                size;
-   unsigned               usage;
+   enum pb_usage_flags    usage;
 
    /**
     * Pointer to the virtual function table.
@@ -126,13 +135,13 @@ struct pb_vtbl
     * flags is bitmask of PB_USAGE_CPU_READ/WRITE. 
     */
    void *(*map)( struct pb_buffer *buf, 
-                 unsigned flags, void *flush_ctx );
+                 enum pb_usage_flags flags, void *flush_ctx );
    
    void (*unmap)( struct pb_buffer *buf );
 
    enum pipe_error (*validate)( struct pb_buffer *buf, 
                                 struct pb_validate *vl,
-                                unsigned flags );
+                                enum pb_usage_flags flags );
 
    void (*fence)( struct pb_buffer *buf, 
                   struct pipe_fence_handle *fence );
@@ -160,7 +169,7 @@ struct pb_vtbl
  */
 static inline void *
 pb_map(struct pb_buffer *buf, 
-       unsigned flags, void *flush_ctx)
+       enum pb_usage_flags flags, void *flush_ctx)
 {
    assert(buf);
    if (!buf)
@@ -201,7 +210,8 @@ pb_get_base_buffer( struct pb_buffer *buf,
 
 
 static inline enum pipe_error 
-pb_validate(struct pb_buffer *buf, struct pb_validate *vl, unsigned flags)
+pb_validate(struct pb_buffer *buf, struct pb_validate *vl,
+            enum pb_usage_flags flags)
 {
    assert(buf);
    if (!buf)
index 7421741c17ce3edcd33928102ee6bc99ac25e255..53b9ce06379f67c702544bf47acbe772c3bbb49a 100644 (file)
@@ -139,7 +139,7 @@ struct fenced_buffer
     * A bitmask of PB_USAGE_CPU/GPU_READ/WRITE describing the current
     * buffer usage.
     */
-   unsigned flags;
+   enum pb_usage_flags flags;
 
    unsigned mapcount;
 
@@ -662,7 +662,7 @@ fenced_buffer_destroy(struct pb_buffer *buf)
 
 static void *
 fenced_buffer_map(struct pb_buffer *buf,
-                  unsigned flags, void *flush_ctx)
+                  enum pb_usage_flags flags, void *flush_ctx)
 {
    struct fenced_buffer *fenced_buf = fenced_buffer(buf);
    struct fenced_manager *fenced_mgr = fenced_buf->mgr;
@@ -739,7 +739,7 @@ fenced_buffer_unmap(struct pb_buffer *buf)
 static enum pipe_error
 fenced_buffer_validate(struct pb_buffer *buf,
                        struct pb_validate *vl,
-                       unsigned flags)
+                       enum pb_usage_flags flags)
 {
    struct fenced_buffer *fenced_buf = fenced_buffer(buf);
    struct fenced_manager *fenced_mgr = fenced_buf->mgr;
index ea2f2fa107cf2c8eb98fc455e8bfa23c5af73dce..d83e8e4f18008d2ee422ce54d430a138dc4baaf3 100644 (file)
@@ -70,7 +70,7 @@ malloc_buffer_destroy(struct pb_buffer *buf)
 
 static void *
 malloc_buffer_map(struct pb_buffer *buf, 
-                  unsigned flags,
+                  enum pb_usage_flags flags,
                  void *flush_ctx)
 {
    return malloc_buffer(buf)->data;
@@ -87,7 +87,7 @@ malloc_buffer_unmap(struct pb_buffer *buf)
 static enum pipe_error 
 malloc_buffer_validate(struct pb_buffer *buf, 
                        struct pb_validate *vl,
-                       unsigned flags)
+                       enum pb_usage_flags flags)
 {
    assert(0);
    return PIPE_ERROR;
index 4e70048cd8348c02cfe5090225cc8b3470a608e4..ceed1daa41476b5797c0bc8b1cbff68b2d99203b 100644 (file)
@@ -122,7 +122,7 @@ pb_cache_buffer_destroy(struct pb_buffer *_buf)
 
 static void *
 pb_cache_buffer_map(struct pb_buffer *_buf, 
-                   unsigned flags, void *flush_ctx)
+                   enum pb_usage_flags flags, void *flush_ctx)
 {
    struct pb_cache_buffer *buf = pb_cache_buffer(_buf);   
    return pb_map(buf->buffer, flags, flush_ctx);
@@ -140,7 +140,7 @@ pb_cache_buffer_unmap(struct pb_buffer *_buf)
 static enum pipe_error 
 pb_cache_buffer_validate(struct pb_buffer *_buf, 
                          struct pb_validate *vl,
-                         unsigned flags)
+                         enum pb_usage_flags flags)
 {
    struct pb_cache_buffer *buf = pb_cache_buffer(_buf);
    return pb_validate(buf->buffer, vl, flags);
index 3c83de80375c8bbc779c4a029c22aeea04b60e26..7101fdc269b18c47c2c7082f9aebd98df87dba65 100644 (file)
@@ -248,7 +248,7 @@ pb_debug_buffer_destroy(struct pb_buffer *_buf)
 
 static void *
 pb_debug_buffer_map(struct pb_buffer *_buf, 
-                    unsigned flags, void *flush_ctx)
+                    enum pb_usage_flags flags, void *flush_ctx)
 {
    struct pb_debug_buffer *buf = pb_debug_buffer(_buf);
    void *map;
@@ -299,10 +299,12 @@ pb_debug_buffer_get_base_buffer(struct pb_buffer *_buf,
 static enum pipe_error 
 pb_debug_buffer_validate(struct pb_buffer *_buf, 
                          struct pb_validate *vl,
-                         unsigned flags)
+                         enum pb_usage_flags flags)
 {
    struct pb_debug_buffer *buf = pb_debug_buffer(_buf);
    
+   assert((flags & ~PB_ALL_USAGE_FLAGS) == 0);
+
    mtx_lock(&buf->mutex);
    if(buf->map_count) {
       debug_printf("%s: attempting to validate a mapped buffer\n", __FUNCTION__);
index 818cadd80a424d99ffb5c2e6af3a2bb3d2749ff9..f975cfbfe93ea68e87546dbe04d2fbb5fe65370f 100644 (file)
@@ -108,7 +108,7 @@ mm_buffer_destroy(struct pb_buffer *buf)
 
 static void *
 mm_buffer_map(struct pb_buffer *buf,
-              unsigned flags,
+              enum pb_usage_flags flags,
               void *flush_ctx)
 {
    struct mm_buffer *mm_buf = mm_buffer(buf);
@@ -130,7 +130,7 @@ mm_buffer_unmap(struct pb_buffer *buf)
 static enum pipe_error 
 mm_buffer_validate(struct pb_buffer *buf, 
                    struct pb_validate *vl,
-                   unsigned flags)
+                   enum pb_usage_flags flags)
 {
    struct mm_buffer *mm_buf = mm_buffer(buf);
    struct mm_pb_manager *mm = mm_buf->mgr;
index 4885d68c39836e1b9fea90b9b4727ce0887f125e..967d8358f0c6e1efe95ad601629eadfa06d546bd 100644 (file)
@@ -103,7 +103,7 @@ pb_ondemand_buffer_destroy(struct pb_buffer *_buf)
 
 static void *
 pb_ondemand_buffer_map(struct pb_buffer *_buf, 
-                       unsigned flags, void *flush_ctx)
+                       enum pb_usage_flags flags, void *flush_ctx)
 {
    struct pb_ondemand_buffer *buf = pb_ondemand_buffer(_buf);
 
@@ -172,7 +172,7 @@ pb_ondemand_buffer_instantiate(struct pb_ondemand_buffer *buf)
 static enum pipe_error 
 pb_ondemand_buffer_validate(struct pb_buffer *_buf, 
                             struct pb_validate *vl,
-                            unsigned flags)
+                            enum pb_usage_flags flags)
 {
    struct pb_ondemand_buffer *buf = pb_ondemand_buffer(_buf);
    enum pipe_error ret; 
index 89df2e947bc9d5039a8a4e37bed2771aba875f4b..f356ecfd568e398563fe0c9ce138d4d9300e3f91 100644 (file)
@@ -118,7 +118,8 @@ pool_buffer_destroy(struct pb_buffer *buf)
 
 
 static void *
-pool_buffer_map(struct pb_buffer *buf, unsigned flags, void *flush_ctx)
+pool_buffer_map(struct pb_buffer *buf, enum pb_usage_flags flags,
+                void *flush_ctx)
 {
    struct pool_buffer *pool_buf = pool_buffer(buf);
    struct pool_pb_manager *pool = pool_buf->mgr;
@@ -143,7 +144,7 @@ pool_buffer_unmap(struct pb_buffer *buf)
 static enum pipe_error 
 pool_buffer_validate(struct pb_buffer *buf, 
                      struct pb_validate *vl,
-                     unsigned flags)
+                     enum pb_usage_flags flags)
 {
    struct pool_buffer *pool_buf = pool_buffer(buf);
    struct pool_pb_manager *pool = pool_buf->mgr;
index 5cf707164ff4ec01554703e301b17f00acb35291..8a3b28761490e846776adf35c8208f68e1ac9013 100644 (file)
@@ -226,7 +226,7 @@ pb_slab_buffer_destroy(struct pb_buffer *_buf)
 
 static void *
 pb_slab_buffer_map(struct pb_buffer *_buf, 
-                   unsigned flags,
+                   enum pb_usage_flags flags,
                    void *flush_ctx)
 {
    struct pb_slab_buffer *buf = pb_slab_buffer(_buf);
@@ -252,7 +252,7 @@ pb_slab_buffer_unmap(struct pb_buffer *_buf)
 static enum pipe_error 
 pb_slab_buffer_validate(struct pb_buffer *_buf, 
                          struct pb_validate *vl,
-                         unsigned flags)
+                         enum pb_usage_flags flags)
 {
    struct pb_slab_buffer *buf = pb_slab_buffer(_buf);
    return pb_validate(buf->slab->bo, vl, flags);
@@ -486,7 +486,7 @@ pb_slab_range_manager_create_buffer(struct pb_manager *_mgr,
    struct pb_slab_range_manager *mgr = pb_slab_range_manager(_mgr);
    pb_size bufSize;
    pb_size reqSize = size;
-   unsigned i;
+   enum pb_usage_flags i;
 
    if(desc->alignment > reqSize)
           reqSize = desc->alignment;
index 8489842effd0e869591a6af1e60a6152e204732e..0c61c906a3a1710e531f0e5ad1a6856ec63bd5b6 100644 (file)
@@ -63,7 +63,7 @@ struct pb_validate
 enum pipe_error
 pb_validate_add_buffer(struct pb_validate *vl,
                        struct pb_buffer *buf,
-                       unsigned flags)
+                       enum pb_usage_flags flags)
 {
    assert(buf);
    if (!buf)
index fa788b08a2e6ca8dd3da0cc1040dd61b98bfa294..ea364330eff213b74b904865e6af8ee85a4c0178 100644 (file)
@@ -59,7 +59,7 @@ struct pb_validate;
 enum pipe_error
 pb_validate_add_buffer(struct pb_validate *vl,
                        struct pb_buffer *buf,
-                       unsigned flags);
+                       enum pb_usage_flags flags);
 
 enum pipe_error
 pb_validate_foreach(struct pb_validate *vl,