[Mesa-dev] [PATCH 3/5] mesa/bufferobj: consolidate some codepaths between ubo/ssbo/atomics.

Samuel Pitoiset samuel.pitoiset at gmail.com
Fri Sep 15 08:04:41 UTC 2017



On 09/15/2017 05:57 AM, Dave Airlie wrote:
> From: Dave Airlie <airlied at redhat.com>
> 
> These are 90% the same code, consoldiate them into a couple of

typo: consolidate.

> common codepaths.
> 
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>   src/mesa/main/bufferobj.c | 146 +++++++++++++++-------------------------------
>   1 file changed, 47 insertions(+), 99 deletions(-)
> 
> diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
> index 7eb7ccf..052a671 100644
> --- a/src/mesa/main/bufferobj.c
> +++ b/src/mesa/main/bufferobj.c
> @@ -1258,18 +1258,18 @@ _mesa_BindBuffer(GLenum target, GLuint buffer)
>   }
>   
>   /**
> - * Binds a buffer object to an atomic buffer binding point.
> + * Binds a buffer object to a binding point.
>    *
>    * The caller is responsible for validating the offset,
>    * flushing the vertices and updating NewDriverState.
>    */
>   static void
> -set_atomic_buffer_binding(struct gl_context *ctx,
> -                          struct gl_buffer_binding *binding,
> -                          struct gl_buffer_object *bufObj,
> -                          GLintptr offset,
> -                          GLsizeiptr size,
> -                          bool autoSize)
> +set_buffer_binding(struct gl_context *ctx,
> +                   struct gl_buffer_binding *binding,
> +                   struct gl_buffer_object *bufObj,
> +                   GLintptr offset,
> +                   GLsizeiptr size,
> +                   bool autoSize, gl_buffer_usage usage)
>   {
>      _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj);
>   
> @@ -1280,67 +1280,38 @@ set_atomic_buffer_binding(struct gl_context *ctx,
>       * at some point as an atomic counter buffer.
>       */
>      if (size >= 0)
> -     bufObj->UsageHistory |= USAGE_ATOMIC_COUNTER_BUFFER;
> +      bufObj->UsageHistory |= usage;
>   }
>   
> -/**
> - * Binds a buffer object to a uniform buffer binding point.
> - *
> - * The caller is responsible for flushing vertices and updating
> - * NewDriverState.
> - */
>   static void
> -set_ubo_binding(struct gl_context *ctx,
> -                struct gl_buffer_binding *binding,
> -                struct gl_buffer_object *bufObj,
> -                GLintptr offset,
> -                GLsizeiptr size,
> -                GLboolean autoSize)
> +set_buffer_multi_binding(struct gl_context *ctx,
> +                         const GLuint *buffers,
> +                         int idx,
> +                         const char *caller,
> +                         struct gl_buffer_binding *binding,
> +                         GLintptr offset,
> +                         GLsizeiptr size,
> +                         bool range,
> +                         gl_buffer_usage usage)
>   {
> -   _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj);
> -
> -   binding->Offset = offset;
> -   binding->Size = size;
> -   binding->AutomaticSize = autoSize;
> -
> -   /* If this is a real buffer object, mark it has having been used
> -    * at some point as a UBO.
> -    */
> -   if (size >= 0)
> -      bufObj->UsageHistory |= USAGE_UNIFORM_BUFFER;
> -}
> -
> -/**
> - * Binds a buffer object to a shader storage buffer binding point.
> - *
> - * The caller is responsible for flushing vertices and updating
> - * NewDriverState.
> - */
> -static void
> -set_ssbo_binding(struct gl_context *ctx,
> -                 struct gl_buffer_binding *binding,
> -                 struct gl_buffer_object *bufObj,
> -                 GLintptr offset,
> -                 GLsizeiptr size,
> -                 GLboolean autoSize)
> -{
> -   _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj);
> -
> -   binding->Offset = offset;
> -   binding->Size = size;
> -   binding->AutomaticSize = autoSize;
> +   struct gl_buffer_object *bufObj;
> +   if (binding->BufferObject && binding->BufferObject->Name == buffers[idx])
> +      bufObj = binding->BufferObject;
> +   else
> +      bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, idx, caller);
>   
> -   /* If this is a real buffer object, mark it has having been used
> -    * at some point as a SSBO.
> -    */
> -   if (size >= 0)
> -      bufObj->UsageHistory |= USAGE_SHADER_STORAGE_BUFFER;
> +   if (bufObj) {
> +      if (bufObj == ctx->Shared->NullBufferObj)
> +         set_buffer_binding(ctx, binding, bufObj, -1, -1, !range, usage);
> +      else
> +         set_buffer_binding(ctx, binding, bufObj, offset, size, !range, usage);
> +   }
>   }
>   
>   /**
>    * Binds a buffer object to a uniform buffer binding point.
>    *
> - * Unlike set_ubo_binding(), this function also flushes vertices
> + * Unlike set_buffer_binding(), this function also flushes vertices
>    * and updates NewDriverState.  It also checks if the binding
>    * has actually changed before updating it.
>    */
> @@ -1365,7 +1336,7 @@ bind_uniform_buffer(struct gl_context *ctx,
>      FLUSH_VERTICES(ctx, 0);
>      ctx->NewDriverState |= ctx->DriverFlags.NewUniformBuffer;
>   
> -   set_ubo_binding(ctx, binding, bufObj, offset, size, autoSize);
> +   set_buffer_binding(ctx, binding, bufObj, offset, size, autoSize, USAGE_UNIFORM_BUFFER);
>   }
>   
>   /**
> @@ -1396,7 +1367,7 @@ bind_shader_storage_buffer(struct gl_context *ctx,
>      FLUSH_VERTICES(ctx, 0);
>      ctx->NewDriverState |= ctx->DriverFlags.NewShaderStorageBuffer;
>   
> -   set_ssbo_binding(ctx, binding, bufObj, offset, size, autoSize);
> +   set_buffer_binding(ctx, binding, bufObj, offset, size, autoSize, USAGE_SHADER_STORAGE_BUFFER);
>   }
>   
>   /**
> @@ -1423,7 +1394,7 @@ bind_atomic_buffer(struct gl_context *ctx, unsigned index,
>      FLUSH_VERTICES(ctx, 0);
>      ctx->NewDriverState |= ctx->DriverFlags.NewAtomicBuffer;
>   
> -   set_atomic_buffer_binding(ctx, binding, bufObj, offset, size, autoSize);
> +   set_buffer_binding(ctx, binding, bufObj, offset, size, autoSize, USAGE_ATOMIC_COUNTER_BUFFER);
>   }
>   
>   /**
> @@ -3736,8 +3707,8 @@ unbind_uniform_buffers(struct gl_context *ctx, GLuint first, GLsizei count)
>      struct gl_buffer_object *bufObj = ctx->Shared->NullBufferObj;
>   
>      for (int i = 0; i < count; i++)
> -      set_ubo_binding(ctx, &ctx->UniformBufferBindings[first + i],
> -                      bufObj, -1, -1, GL_TRUE);
> +      set_buffer_binding(ctx, &ctx->UniformBufferBindings[first + i],
> +                         bufObj, -1, -1, GL_TRUE, 0);
>   }
>   
>   /**
> @@ -3751,8 +3722,8 @@ unbind_shader_storage_buffers(struct gl_context *ctx, GLuint first,
>      struct gl_buffer_object *bufObj = ctx->Shared->NullBufferObj;
>   
>      for (int i = 0; i < count; i++)
> -      set_ssbo_binding(ctx, &ctx->ShaderStorageBufferBindings[first + i],
> -                       bufObj, -1, -1, GL_TRUE);
> +      set_buffer_binding(ctx, &ctx->ShaderStorageBufferBindings[first + i],
> +                         bufObj, -1, -1, GL_TRUE, 0);
>   }
>   
>   static void
> @@ -3806,7 +3777,6 @@ bind_uniform_buffers(struct gl_context *ctx, GLuint first, GLsizei count,
>      for (int i = 0; i < count; i++) {
>         struct gl_buffer_binding *binding =
>            &ctx->UniformBufferBindings[first + i];
> -      struct gl_buffer_object *bufObj;
>         GLintptr offset = 0;
>         GLsizeiptr size = 0;
>   
> @@ -3848,17 +3818,9 @@ bind_uniform_buffers(struct gl_context *ctx, GLuint first, GLsizei count,
>            size = sizes[i];
>         }
>   
> -      if (binding->BufferObject && binding->BufferObject->Name == buffers[i])
> -         bufObj = binding->BufferObject;
> -      else
> -         bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, caller);
> -
> -      if (bufObj) {
> -         if (bufObj == ctx->Shared->NullBufferObj)
> -            set_ubo_binding(ctx, binding, bufObj, -1, -1, !range);
> -         else
> -            set_ubo_binding(ctx, binding, bufObj, offset, size, !range);
> -      }
> +      set_buffer_multi_binding(ctx, buffers, i, caller,
> +                               binding, offset, size, !range,
> +                               USAGE_UNIFORM_BUFFER);
>      }
>   
>      _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
> @@ -3916,7 +3878,6 @@ bind_shader_storage_buffers(struct gl_context *ctx, GLuint first,
>      for (int i = 0; i < count; i++) {
>         struct gl_buffer_binding *binding =
>            &ctx->ShaderStorageBufferBindings[first + i];
> -      struct gl_buffer_object *bufObj;
>         GLintptr offset = 0;
>         GLsizeiptr size = 0;
>   
> @@ -3958,17 +3919,9 @@ bind_shader_storage_buffers(struct gl_context *ctx, GLuint first,
>            size = sizes[i];
>         }
>   
> -      if (binding->BufferObject && binding->BufferObject->Name == buffers[i])
> -         bufObj = binding->BufferObject;
> -      else
> -         bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, caller);
> -
> -      if (bufObj) {
> -         if (bufObj == ctx->Shared->NullBufferObj)
> -            set_ssbo_binding(ctx, binding, bufObj, -1, -1, !range);
> -         else
> -            set_ssbo_binding(ctx, binding, bufObj, offset, size, !range);
> -      }
> +      set_buffer_multi_binding(ctx, buffers, i, caller,
> +                               binding, offset, size, !range,
> +                               USAGE_SHADER_STORAGE_BUFFER);
>      }
>   
>      _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
> @@ -4192,8 +4145,8 @@ unbind_atomic_buffers(struct gl_context *ctx, GLuint first, GLsizei count)
>      struct gl_buffer_object * const bufObj = ctx->Shared->NullBufferObj;
>   
>      for (int i = 0; i < count; i++)
> -      set_atomic_buffer_binding(ctx, &ctx->AtomicBufferBindings[first + i],
> -                                bufObj, -1, -1, GL_TRUE);
> +      set_buffer_binding(ctx, &ctx->AtomicBufferBindings[first + i],
> +                         bufObj, -1, -1, GL_TRUE, 0);
>   }
>   
>   static void
> @@ -4250,7 +4203,6 @@ bind_atomic_buffers(struct gl_context *ctx,
>      for (int i = 0; i < count; i++) {
>         struct gl_buffer_binding *binding =
>            &ctx->AtomicBufferBindings[first + i];
> -      struct gl_buffer_object *bufObj;
>         GLintptr offset = 0;
>         GLsizeiptr size = 0;
>   
> @@ -4289,13 +4241,9 @@ bind_atomic_buffers(struct gl_context *ctx,
>            size = sizes[i];
>         }
>   
> -      if (binding->BufferObject && binding->BufferObject->Name == buffers[i])
> -         bufObj = binding->BufferObject;
> -      else
> -         bufObj = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, caller);
> -
> -      if (bufObj)
> -         set_atomic_buffer_binding(ctx, binding, bufObj, offset, size, !range);
> +      set_buffer_multi_binding(ctx, buffers, i, caller,
> +                               binding, offset, size, !range,
> +                               USAGE_ATOMIC_COUNTER_BUFFER);
>      }
>   
>      _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
> 


More information about the mesa-dev mailing list