mesa: add clear_buffer_sub_data_error() helper
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 21 Jul 2017 09:51:47 +0000 (11:51 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 2 Aug 2017 10:54:31 +0000 (12:54 +0200)
And make clear_buffer_sub_data() always inline.

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

index 2d1b652dfc06ea1284d9cd7ec554da7183260602..61f680cf31559c45e52b59c27ebd1edfdad9e6ba 100644 (file)
@@ -2270,31 +2270,35 @@ _mesa_GetNamedBufferSubData(GLuint buffer, GLintptr offset,
 /**
  * \param subdata   true if caller is *SubData, false if *Data
  */
-static void
+static ALWAYS_INLINE void
 clear_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
                       GLenum internalformat, GLintptr offset, GLsizeiptr size,
                       GLenum format, GLenum type, const GLvoid *data,
-                      const char *func, bool subdata)
+                      const char *func, bool subdata, bool no_error)
 {
    mesa_format mesaFormat;
    GLubyte clearValue[MAX_PIXEL_BYTES];
    GLsizeiptr clearValueSize;
 
    /* This checks for disallowed mappings. */
-   if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,
-                                         subdata, func)) {
+   if (!no_error && !buffer_object_subdata_range_good(ctx, bufObj, offset, size,
+                                                      subdata, func)) {
       return;
    }
 
-   mesaFormat = validate_clear_buffer_format(ctx, internalformat,
-                                             format, type, func);
+   if (no_error) {
+      mesaFormat = _mesa_get_texbuffer_format(ctx, internalformat);
+   } else {
+      mesaFormat = validate_clear_buffer_format(ctx, internalformat,
+                                                format, type, func);
+   }
 
-   if (mesaFormat == MESA_FORMAT_NONE) {
+   if (mesaFormat == MESA_FORMAT_NONE)
       return;
-   }
 
    clearValueSize = _mesa_get_format_bytes(mesaFormat);
-   if (offset % clearValueSize != 0 || size % clearValueSize != 0) {
+   if (!no_error &&
+       (offset % clearValueSize != 0 || size % clearValueSize != 0)) {
       _mesa_error(ctx, GL_INVALID_VALUE,
                   "%s(offset or size is not a multiple of "
                   "internalformat size)", func);
@@ -2323,6 +2327,17 @@ clear_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
                                   clearValue, clearValueSize, bufObj);
 }
 
+static void
+clear_buffer_sub_data_error(struct gl_context *ctx,
+                            struct gl_buffer_object *bufObj,
+                            GLenum internalformat, GLintptr offset,
+                            GLsizeiptr size, GLenum format, GLenum type,
+                            const GLvoid *data, const char *func, bool subdata)
+{
+   clear_buffer_sub_data(ctx, bufObj, internalformat, offset, size, format,
+                         type, data, func, subdata, false);
+}
+
 void GLAPIENTRY
 _mesa_ClearBufferData(GLenum target, GLenum internalformat, GLenum format,
                       GLenum type, const GLvoid *data)
@@ -2334,8 +2349,8 @@ _mesa_ClearBufferData(GLenum target, GLenum internalformat, GLenum format,
    if (!bufObj)
       return;
 
-   clear_buffer_sub_data(ctx, bufObj, internalformat, 0, bufObj->Size,
-                         format, type, data, "glClearBufferData", false);
+   clear_buffer_sub_data_error(ctx, bufObj, internalformat, 0, bufObj->Size,
+                               format, type, data, "glClearBufferData", false);
 }
 
 void GLAPIENTRY
@@ -2349,8 +2364,9 @@ _mesa_ClearNamedBufferData(GLuint buffer, GLenum internalformat,
    if (!bufObj)
       return;
 
-   clear_buffer_sub_data(ctx, bufObj, internalformat, 0, bufObj->Size,
-                         format, type, data, "glClearNamedBufferData", false);
+   clear_buffer_sub_data_error(ctx, bufObj, internalformat, 0, bufObj->Size,
+                               format, type, data, "glClearNamedBufferData",
+                               false);
 }
 
 
@@ -2367,8 +2383,9 @@ _mesa_ClearBufferSubData(GLenum target, GLenum internalformat,
    if (!bufObj)
       return;
 
-   clear_buffer_sub_data(ctx, bufObj, internalformat, offset, size,
-                         format, type, data, "glClearBufferSubData", true);
+   clear_buffer_sub_data_error(ctx, bufObj, internalformat, offset, size,
+                               format, type, data, "glClearBufferSubData",
+                               true);
 }
 
 void GLAPIENTRY
@@ -2385,8 +2402,9 @@ _mesa_ClearNamedBufferSubData(GLuint buffer, GLenum internalformat,
    if (!bufObj)
       return;
 
-   clear_buffer_sub_data(ctx, bufObj, internalformat, offset, size, format,
-                         type, data, "glClearNamedBufferSubData", true);
+   clear_buffer_sub_data_error(ctx, bufObj, internalformat, offset, size,
+                               format, type, data, "glClearNamedBufferSubData",
+                               true);
 }
 
 static GLboolean