[Mesa-dev] [PATCH 06/10] mesa: split bind_atomic_buffer() in two

Timothy Arceri tarceri at itsqueeze.com
Mon May 22 05:46:58 UTC 2017


This will help us add KHR_no_error support.
---
 src/mesa/main/bufferobj.c | 54 +++++++++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 132391b..aa253ef 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -3266,63 +3266,67 @@ set_atomic_buffer_binding(struct gl_context *ctx,
    if (bufObj == ctx->Shared->NullBufferObj) {
       binding->Offset = 0;
       binding->Size = 0;
    } else {
       binding->Offset = offset;
       binding->Size = size;
       bufObj->UsageHistory |= USAGE_ATOMIC_COUNTER_BUFFER;
    }
 }
 
+static void
+bind_atomic_buffer(struct gl_context *ctx, unsigned index,
+                   struct gl_buffer_object *bufObj, GLintptr offset,
+                   GLsizeiptr size)
+{
+   _mesa_reference_buffer_object(ctx, &ctx->AtomicBuffer, bufObj);
+
+   struct gl_atomic_buffer_binding *binding =
+      &ctx->AtomicBufferBindings[index];
+   if (binding->BufferObject == bufObj &&
+       binding->Offset == offset &&
+       binding->Size == size) {
+      return;
+   }
+
+   FLUSH_VERTICES(ctx, 0);
+   ctx->NewDriverState |= ctx->DriverFlags.NewAtomicBuffer;
+
+   set_atomic_buffer_binding(ctx, binding, bufObj, offset, size);
+}
+
 /**
  * Binds a buffer object to an atomic buffer binding point.
  *
  * Unlike set_atomic_buffer_binding(), this function also validates the
  * index and offset, flushes vertices, and updates NewDriverState.
  * It also checks if the binding has actually changing before
  * updating it.
  */
 static void
-bind_atomic_buffer(struct gl_context *ctx,
-                   unsigned index,
-                   struct gl_buffer_object *bufObj,
-                   GLintptr offset,
-                   GLsizeiptr size,
-                   const char *name)
+bind_atomic_buffer_err(struct gl_context *ctx, unsigned index,
+                       struct gl_buffer_object *bufObj, GLintptr offset,
+                       GLsizeiptr size, const char *name)
 {
-   struct gl_atomic_buffer_binding *binding;
-
    if (index >= ctx->Const.MaxAtomicBufferBindings) {
       _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%d)", name, index);
       return;
    }
 
    if (offset & (ATOMIC_COUNTER_SIZE - 1)) {
       _mesa_error(ctx, GL_INVALID_VALUE,
                   "%s(offset misaligned %d/%d)", name, (int) offset,
                   ATOMIC_COUNTER_SIZE);
       return;
    }
 
-   _mesa_reference_buffer_object(ctx, &ctx->AtomicBuffer, bufObj);
-
-   binding = &ctx->AtomicBufferBindings[index];
-   if (binding->BufferObject == bufObj &&
-       binding->Offset == offset &&
-       binding->Size == size) {
-      return;
-   }
-
-   FLUSH_VERTICES(ctx, 0);
-   ctx->NewDriverState |= ctx->DriverFlags.NewAtomicBuffer;
-
-   set_atomic_buffer_binding(ctx, binding, bufObj, offset, size);
+   bind_atomic_buffer(ctx, index, bufObj, offset, size);
 }
 
 static inline bool
 bind_buffers_check_offset_and_size(struct gl_context *ctx,
                                    GLuint index,
                                    const GLintptr *offsets,
                                    const GLsizeiptr *sizes)
 {
    if (offsets[index] < 0) {
       /* The ARB_multi_bind spec says:
@@ -4031,22 +4035,22 @@ _mesa_BindBufferRange(GLenum target, GLuint index,
                                                  false);
       return;
    case GL_UNIFORM_BUFFER:
       bind_buffer_range_uniform_buffer_err(ctx, index, bufObj, offset, size);
       return;
    case GL_SHADER_STORAGE_BUFFER:
       bind_buffer_range_shader_storage_buffer_err(ctx, index, bufObj, offset,
                                                   size);
       return;
    case GL_ATOMIC_COUNTER_BUFFER:
-      bind_atomic_buffer(ctx, index, bufObj, offset, size,
-                         "glBindBufferRange");
+      bind_atomic_buffer_err(ctx, index, bufObj, offset, size,
+                             "glBindBufferRange");
       return;
    default:
       _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferRange(target)");
       return;
    }
 }
 
 void GLAPIENTRY
 _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer)
 {
@@ -4105,22 +4109,22 @@ _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer)
                                                 ctx->TransformFeedback.CurrentObject,
                                                 index, bufObj, false);
       return;
    case GL_UNIFORM_BUFFER:
       bind_buffer_base_uniform_buffer(ctx, index, bufObj);
       return;
    case GL_SHADER_STORAGE_BUFFER:
       bind_buffer_base_shader_storage_buffer(ctx, index, bufObj);
       return;
    case GL_ATOMIC_COUNTER_BUFFER:
-      bind_atomic_buffer(ctx, index, bufObj, 0, 0,
-                         "glBindBufferBase");
+      bind_atomic_buffer_err(ctx, index, bufObj, 0, 0,
+                             "glBindBufferBase");
       return;
    default:
       _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferBase(target)");
       return;
    }
 }
 
 void GLAPIENTRY
 _mesa_BindBuffersRange(GLenum target, GLuint first, GLsizei count,
                        const GLuint *buffers,
-- 
2.9.4



More information about the mesa-dev mailing list