mesa: add buffer_data() and buffer_data_error() helpers
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 20 Jul 2017 08:43:30 +0000 (10:43 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 2 Aug 2017 10:54:31 +0000 (12:54 +0200)
And call buffer_data_error() from _mesa_buffer_data().

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/main/bufferobj.c

index b46b812..1bae025 100644 (file)
@@ -1923,10 +1923,10 @@ _mesa_NamedBufferStorage(GLuint buffer, GLsizeiptr size, const GLvoid *data,
 }
 
 
-void
-_mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
-                  GLenum target, GLsizeiptr size, const GLvoid *data,
-                  GLenum usage, const char *func)
+static ALWAYS_INLINE void
+buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+            GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage,
+            const char *func, bool no_error)
 {
    bool valid_usage;
 
@@ -1938,44 +1938,43 @@ _mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
                   _mesa_enum_to_string(usage));
    }
 
-   if (size < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "%s(size < 0)", func);
-      return;
-   }
-
-   switch (usage) {
-   case GL_STREAM_DRAW_ARB:
-      valid_usage = (ctx->API != API_OPENGLES);
-      break;
-
-   case GL_STATIC_DRAW_ARB:
-   case GL_DYNAMIC_DRAW_ARB:
-      valid_usage = true;
-      break;
-
-   case GL_STREAM_READ_ARB:
-   case GL_STREAM_COPY_ARB:
-   case GL_STATIC_READ_ARB:
-   case GL_STATIC_COPY_ARB:
-   case GL_DYNAMIC_READ_ARB:
-   case GL_DYNAMIC_COPY_ARB:
-      valid_usage = _mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx);
-      break;
+   if (!no_error) {
+      if (size < 0) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "%s(size < 0)", func);
+         return;
+      }
 
-   default:
-      valid_usage = false;
-      break;
-   }
+      switch (usage) {
+      case GL_STREAM_DRAW_ARB:
+         valid_usage = (ctx->API != API_OPENGLES);
+         break;
+      case GL_STATIC_DRAW_ARB:
+      case GL_DYNAMIC_DRAW_ARB:
+         valid_usage = true;
+         break;
+      case GL_STREAM_READ_ARB:
+      case GL_STREAM_COPY_ARB:
+      case GL_STATIC_READ_ARB:
+      case GL_STATIC_COPY_ARB:
+      case GL_DYNAMIC_READ_ARB:
+      case GL_DYNAMIC_COPY_ARB:
+         valid_usage = _mesa_is_desktop_gl(ctx) || _mesa_is_gles3(ctx);
+         break;
+      default:
+         valid_usage = false;
+         break;
+      }
 
-   if (!valid_usage) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid usage: %s)", func,
-                  _mesa_enum_to_string(usage));
-      return;
-   }
+      if (!valid_usage) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid usage: %s)", func,
+                     _mesa_enum_to_string(usage));
+         return;
+      }
 
-   if (bufObj->Immutable || bufObj->HandleAllocated) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(immutable)", func);
-      return;
+      if (bufObj->Immutable || bufObj->HandleAllocated) {
+         _mesa_error(ctx, GL_INVALID_OPERATION, "%s(immutable)", func);
+         return;
+      }
    }
 
    /* Unmap the existing buffer.  We'll replace it now.  Not an error. */
@@ -2002,20 +2001,37 @@ _mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
                                GL_DYNAMIC_STORAGE_BIT,
                                bufObj)) {
       if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {
-         /* From GL_AMD_pinned_memory:
-          *
-          *   INVALID_OPERATION is generated by BufferData if <target> is
-          *   EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, and the store cannot be
-          *   mapped to the GPU address space.
-          */
-         _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
-      }
-      else {
+         if (!no_error) {
+            /* From GL_AMD_pinned_memory:
+             *
+             *   INVALID_OPERATION is generated by BufferData if <target> is
+             *   EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, and the store cannot be
+             *   mapped to the GPU address space.
+             */
+            _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
+         }
+      } else {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
       }
    }
 }
 
+static void
+buffer_data_error(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+                  GLenum target, GLsizeiptr size, const GLvoid *data,
+                  GLenum usage, const char *func)
+{
+   buffer_data(ctx, bufObj, target, size, data, usage, func, false);
+}
+
+void
+_mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+                  GLenum target, GLsizeiptr size, const GLvoid *data,
+                  GLenum usage, const char *func)
+{
+   buffer_data_error(ctx, bufObj, target, size, data, usage, func);
+}
+
 void GLAPIENTRY
 _mesa_BufferData(GLenum target, GLsizeiptr size,
                  const GLvoid *data, GLenum usage)