[Mesa-dev] [PATCH 1/3] pipebuffer: use new pb_usage_flags enum type

Brian Paul brianp at vmware.com
Tue Apr 23 15:02:24 UTC 2019


It was committed in early March: b286e74df66e25cadd1c82d9ddc4d1fc3887b646

-Brian

On 04/23/2019 07:25 AM, Thomas Hellstrom wrote:
> Hi, Brian,
> 
> Did this series get reviewed? I don't see any replies?
> 
> /Thomas
> 
> 
> On Tue, 2019-03-05 at 20:48 -0700, Brian Paul wrote:
>> Use a new enum type instead of 'unsigned' to make things a bit more
>> understandable.
>> ---
>>   src/gallium/auxiliary/pipebuffer/pb_buffer.h       | 34
>> ++++++++++++++--------
>>   .../auxiliary/pipebuffer/pb_buffer_fenced.c        |  6 ++--
>>   .../auxiliary/pipebuffer/pb_buffer_malloc.c        |  4 +--
>>   src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c |  4 +--
>>   src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c |  6 ++--
>>   src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c    |  4 +--
>>   .../auxiliary/pipebuffer/pb_bufmgr_ondemand.c      |  4 +--
>>   src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c  |  5 ++--
>>   src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c  |  6 ++--
>>   src/gallium/auxiliary/pipebuffer/pb_validate.c     |  2 +-
>>   src/gallium/auxiliary/pipebuffer/pb_validate.h     |  2 +-
>>   11 files changed, 45 insertions(+), 32 deletions(-)
>>
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer.h
>> b/src/gallium/auxiliary/pipebuffer/pb_buffer.h
>> index 33c2306..11f70ea 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_buffer.h
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer.h
>> @@ -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)
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
>> b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
>> index 7421741..53b9ce0 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
>> @@ -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;
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c
>> b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c
>> index ea2f2fa..d83e8e4 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c
>> @@ -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;
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
>> b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
>> index 4e70048..ceed1da 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
>> @@ -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);
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
>> b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
>> index 3c83de8..7101fdc 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
>> @@ -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__);
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
>> b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
>> index 818cadd..f975cfb 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
>> @@ -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;
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c
>> b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c
>> index 4885d68..967d835 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c
>> @@ -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;
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
>> b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
>> index 89df2e9..f356ecf 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
>> @@ -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;
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c
>> b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c
>> index 5cf7071..8a3b287 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c
>> @@ -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;
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_validate.c
>> b/src/gallium/auxiliary/pipebuffer/pb_validate.c
>> index 8489842..0c61c90 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_validate.c
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_validate.c
>> @@ -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)
>> diff --git a/src/gallium/auxiliary/pipebuffer/pb_validate.h
>> b/src/gallium/auxiliary/pipebuffer/pb_validate.h
>> index fa788b0..ea36433 100644
>> --- a/src/gallium/auxiliary/pipebuffer/pb_validate.h
>> +++ b/src/gallium/auxiliary/pipebuffer/pb_validate.h
>> @@ -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,



More information about the mesa-dev mailing list