[Mesa-dev] [PATCH 08/10] mesa: convert mesa_bind_buffer_range_transform_feedback() to a validate function

Timothy Arceri tarceri at itsqueeze.com
Mon May 22 05:47:00 UTC 2017


This allows some tidy up and also makes it so we can add KHR_no_error
support.
---
 src/mesa/main/bufferobj.c         | 12 +++++++----
 src/mesa/main/transformfeedback.c | 42 ++++++++++++++++++++-------------------
 src/mesa/main/transformfeedback.h | 12 +++++------
 3 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index aa253ef..2d3e0f2 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -4022,24 +4022,28 @@ _mesa_BindBufferRange(GLenum target, GLuint index,
    if (buffer != 0) {
       if (size <= 0) {
          _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(size=%d)",
                      (int) size);
          return;
       }
    }
 
    switch (target) {
    case GL_TRANSFORM_FEEDBACK_BUFFER:
-      _mesa_bind_buffer_range_transform_feedback(ctx,
-                                                 ctx->TransformFeedback.CurrentObject,
-                                                 index, bufObj, offset, size,
-                                                 false);
+      if (!_mesa_validate_buffer_range_xfb(ctx,
+                                           ctx->TransformFeedback.CurrentObject,
+                                           index, bufObj, offset, size,
+                                           false))
+         return;
+
+      _mesa_bind_buffer_range_xfb(ctx, ctx->TransformFeedback.CurrentObject,
+                                  index, bufObj, offset, size);
       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_err(ctx, index, bufObj, offset, size,
diff --git a/src/mesa/main/transformfeedback.c b/src/mesa/main/transformfeedback.c
index c3aa61c..fdc3152 100644
--- a/src/mesa/main/transformfeedback.c
+++ b/src/mesa/main/transformfeedback.c
@@ -534,99 +534,96 @@ bind_buffer_range(struct gl_context *ctx,
                                     &ctx->TransformFeedback.CurrentBuffer,
                                     bufObj);
    }
 
    /* The per-attribute binding point */
    _mesa_set_transform_feedback_binding(ctx, obj, index, bufObj, offset, size);
 }
 
 
 /**
- * Specify a buffer object to receive transform feedback results.  Plus,
- * specify the starting offset to place the results, and max size.
+ * Validate the buffer object to receive transform feedback results.  Plus,
+ * validate the starting offset to place the results, and max size.
  * Called from the glBindBufferRange() and glTransformFeedbackBufferRange
  * functions.
  */
-void
-_mesa_bind_buffer_range_transform_feedback(struct gl_context *ctx,
-                                           struct gl_transform_feedback_object *obj,
-                                           GLuint index,
-                                           struct gl_buffer_object *bufObj,
-                                           GLintptr offset,
-                                           GLsizeiptr size,
-                                           bool dsa)
+bool
+_mesa_validate_buffer_range_xfb(struct gl_context *ctx,
+                                struct gl_transform_feedback_object *obj,
+                                GLuint index, struct gl_buffer_object *bufObj,
+                                GLintptr offset, GLsizeiptr size, bool dsa)
 {
    const char *gl_methd_name;
    if (dsa)
       gl_methd_name = "glTransformFeedbackBufferRange";
    else
       gl_methd_name = "glBindBufferRange";
 
 
    if (obj->Active) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(transform feedback active)",
                   gl_methd_name);
-      return;
+      return false;
    }
 
    if (index >= ctx->Const.MaxTransformFeedbackBuffers) {
       /* OpenGL 4.5 core profile, 6.1, pdf page 82: "An INVALID_VALUE error is
        * generated if index is greater than or equal to the number of binding
        * points for transform feedback, as described in section 6.7.1."
        */
       _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%d out of bounds)",
                   gl_methd_name, index);
-      return;
+      return false;
    }
 
    if (size & 0x3) {
       /* OpenGL 4.5 core profile, 6.7, pdf page 103: multiple of 4 */
       _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d must be a multiple of "
                   "four)", gl_methd_name, (int) size);
-      return;
+      return false;
    }  
 
    if (offset & 0x3) {
       /* OpenGL 4.5 core profile, 6.7, pdf page 103: multiple of 4 */
       _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset=%d must be a multiple "
                   "of four)", gl_methd_name, (int) offset);
-      return;
+      return false;
    }
 
    if (offset < 0) {
       /* OpenGL 4.5 core profile, 6.1, pdf page 82: "An INVALID_VALUE error is
        * generated by BindBufferRange if offset is negative."
        *
        * OpenGL 4.5 core profile, 13.2, pdf page 445: "An INVALID_VALUE error
        * is generated by TransformFeedbackBufferRange if offset is negative."
        */
       _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset=%d must be >= 0)",
                   gl_methd_name,
                   (int) offset);
-      return;
+      return false;
    }
 
    if (size <= 0 && (dsa || bufObj != ctx->Shared->NullBufferObj)) {
       /* OpenGL 4.5 core profile, 6.1, pdf page 82: "An INVALID_VALUE error is
        * generated by BindBufferRange if buffer is non-zero and size is less
        * than or equal to zero."
        *
        * OpenGL 4.5 core profile, 13.2, pdf page 445: "An INVALID_VALUE error
        * is generated by TransformFeedbackBufferRange if size is less than or
        * equal to zero."
        */
       _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d must be > 0)",
                   gl_methd_name, (int) size);
-      return;
+      return false;
    }
 
-   bind_buffer_range(ctx, obj, index, bufObj, offset, size, dsa);
+   return true;
 }
 
 
 /**
  * Specify a buffer object to receive transform feedback results.
  * As above, but start at offset = 0.
  * Called from the glBindBufferBase() and glTransformFeedbackBufferBase()
  * functions.
  */
 void
@@ -736,22 +733,27 @@ _mesa_TransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer,
    if(!obj) {
       return;
    }
 
    bufObj = lookup_transform_feedback_bufferobj_err(ctx, buffer,
                                               "glTransformFeedbackBufferRange");
    if(!bufObj) {
       return;
    }
 
-   _mesa_bind_buffer_range_transform_feedback(ctx, obj, index, bufObj, offset,
-                                              size, true);
+   if (!_mesa_validate_buffer_range_xfb(ctx, obj, index, bufObj, offset,
+                                        size, true))
+      return;
+
+   /* The per-attribute binding point */
+   _mesa_set_transform_feedback_binding(ctx, obj, index, bufObj, offset,
+                                        size);
 }
 
 /**
  * Specify a buffer object to receive transform feedback results, plus the
  * offset in the buffer to start placing results.
  * This function is part of GL_EXT_transform_feedback, but not GL3.
  */
 void GLAPIENTRY
 _mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
                           GLintptr offset)
@@ -791,21 +793,21 @@ _mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
    } else {
       bufObj = _mesa_lookup_bufferobj(ctx, buffer);
    }
 
    if (!bufObj) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glBindBufferOffsetEXT(invalid buffer=%u)", buffer);
       return;
    }
 
-   bind_buffer_range(ctx, obj, index, bufObj, offset, 0, false);
+   _mesa_bind_buffer_range_xfb(ctx, obj, index, bufObj, offset, 0);
 }
 
 
 /**
  * This function specifies the transform feedback outputs to be written
  * to the feedback buffer(s), and in what order.
  */
 void GLAPIENTRY
 _mesa_TransformFeedbackVaryings(GLuint program, GLsizei count,
                                 const GLchar * const *varyings,
diff --git a/src/mesa/main/transformfeedback.h b/src/mesa/main/transformfeedback.h
index 475f5f1..cb3bb67 100644
--- a/src/mesa/main/transformfeedback.h
+++ b/src/mesa/main/transformfeedback.h
@@ -56,27 +56,25 @@ _mesa_compute_max_transform_feedback_vertices( struct gl_context *ctx,
 
 
 /*** GL_EXT_transform_feedback ***/
 
 extern void GLAPIENTRY
 _mesa_BeginTransformFeedback(GLenum mode);
 
 extern void GLAPIENTRY
 _mesa_EndTransformFeedback(void);
 
-extern void
-_mesa_bind_buffer_range_transform_feedback(struct gl_context *ctx,
-					   struct gl_transform_feedback_object *obj,
-					   GLuint index,
-					   struct gl_buffer_object *bufObj,
-					   GLintptr offset,
-					   GLsizeiptr size, bool dsa);
+extern bool
+_mesa_validate_buffer_range_xfb(struct gl_context *ctx,
+                                struct gl_transform_feedback_object *obj,
+                                GLuint index, struct gl_buffer_object *bufObj,
+                                GLintptr offset, GLsizeiptr size, bool dsa);
 
 extern void
 _mesa_bind_buffer_base_transform_feedback(struct gl_context *ctx,
 					  struct gl_transform_feedback_object *obj,
 					  GLuint index,
 					  struct gl_buffer_object *bufObj,
 					  bool dsa);
 
 extern void GLAPIENTRY
 _mesa_BindBufferOffsetEXT(GLenum target, GLuint index, GLuint buffer,
-- 
2.9.4



More information about the mesa-dev mailing list