From: Timothy Arceri Date: Fri, 12 May 2017 07:10:10 +0000 (+1000) Subject: mesa: create validate_buffer_sub_data() helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5d29e6aab8ac05cbd73433b45958b2f82eefa91d;p=mesa.git mesa: create validate_buffer_sub_data() helper This change assumes meta will always pass valid arguments to _mesa_buffer_sub_data(). Reviewed-by: Nicolai Hähnle --- diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index 47ef16b3e7d..1ff46515f12 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -1902,8 +1902,7 @@ _mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcX, GLint srcY, verts[3].tex[1] = tex->Ttop; /* upload new vertex data */ - _mesa_buffer_sub_data(ctx, copypix->buf_obj, 0, sizeof(verts), verts, - __func__); + _mesa_buffer_sub_data(ctx, copypix->buf_obj, 0, sizeof(verts), verts); } _mesa_set_enable(ctx, tex->Target, GL_TRUE); @@ -2422,8 +2421,7 @@ _mesa_meta_Bitmap(struct gl_context *ctx, } /* upload new vertex data */ - _mesa_buffer_sub_data(ctx, bitmap->buf_obj, 0, sizeof(verts), verts, - __func__); + _mesa_buffer_sub_data(ctx, bitmap->buf_obj, 0, sizeof(verts), verts); } /* choose different foreground/background alpha values */ @@ -3140,8 +3138,7 @@ decompress_texture_image(struct gl_context *ctx, _mesa_set_viewport(ctx, 0, 0, 0, width, height); /* upload new vertex data */ - _mesa_buffer_sub_data(ctx, decompress->buf_obj, 0, sizeof(verts), verts, - __func__); + _mesa_buffer_sub_data(ctx, decompress->buf_obj, 0, sizeof(verts), verts); /* setup texture state */ _mesa_BindTexture(target, texObj->Name); @@ -3409,8 +3406,7 @@ _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z, verts[3].st[i][1] = t1; } - _mesa_buffer_sub_data(ctx, drawtex->buf_obj, 0, sizeof(verts), verts, - __func__); + _mesa_buffer_sub_data(ctx, drawtex->buf_obj, 0, sizeof(verts), verts); } _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4); diff --git a/src/mesa/drivers/common/meta_blit.c b/src/mesa/drivers/common/meta_blit.c index 991d52f21e9..e8719a3a770 100644 --- a/src/mesa/drivers/common/meta_blit.c +++ b/src/mesa/drivers/common/meta_blit.c @@ -800,8 +800,7 @@ blitframebuffer_texture(struct gl_context *ctx, verts[3].tex[1] = t1; verts[3].tex[2] = readAtt->Zoffset; - _mesa_buffer_sub_data(ctx, blit->buf_obj, 0, sizeof(verts), verts, - __func__); + _mesa_buffer_sub_data(ctx, blit->buf_obj, 0, sizeof(verts), verts); } /* setup viewport */ diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 674ff630cd6..97e4df91875 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -1793,42 +1793,27 @@ _mesa_NamedBufferData(GLuint buffer, GLsizeiptr size, const GLvoid *data, } -/** - * Implementation for glBufferSubData and glNamedBufferSubData. - * - * \param ctx GL context. - * \param bufObj The buffer object. - * \param offset Offset of the first byte of the subdata range. - * \param size Size, in bytes, of the subdata range. - * \param data The data store. - * \param func Name of calling function for recording errors. - * - */ -void -_mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj, - GLintptr offset, GLsizeiptr size, const GLvoid *data, - const char *func) +static bool +validate_buffer_sub_data(struct gl_context *ctx, + struct gl_buffer_object *bufObj, + GLintptr offset, GLsizeiptr size, + const char *func) { if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size, true, func)) { /* error already recorded */ - return; + return false; } if (bufObj->Immutable && !(bufObj->StorageFlags & GL_DYNAMIC_STORAGE_BIT)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func); - return; + return false; } - if (size == 0) - return; - - bufObj->NumSubDataCalls++; - if ((bufObj->Usage == GL_STATIC_DRAW || bufObj->Usage == GL_STATIC_COPY) && - bufObj->NumSubDataCalls >= BUFFER_WARNING_CALL_COUNT) { + bufObj->NumSubDataCalls >= BUFFER_WARNING_CALL_COUNT - 1) { /* If the application declared the buffer as static draw/copy or stream * draw, it should not be frequently modified with glBufferSubData. */ @@ -1839,6 +1824,29 @@ _mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj, _mesa_enum_to_string(bufObj->Usage)); } + return true; +} + + +/** + * Implementation for glBufferSubData and glNamedBufferSubData. + * + * \param ctx GL context. + * \param bufObj The buffer object. + * \param offset Offset of the first byte of the subdata range. + * \param size Size, in bytes, of the subdata range. + * \param data The data store. + * \param func Name of calling function for recording errors. + * + */ +void +_mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj, + GLintptr offset, GLsizeiptr size, const GLvoid *data) +{ + if (size == 0) + return; + + bufObj->NumSubDataCalls++; bufObj->Written = GL_TRUE; bufObj->MinMaxCacheDirty = true; @@ -1852,12 +1860,14 @@ _mesa_BufferSubData(GLenum target, GLintptr offset, { GET_CURRENT_CONTEXT(ctx); struct gl_buffer_object *bufObj; + const char *func = "glBufferSubData"; - bufObj = get_buffer(ctx, "glBufferSubData", target, GL_INVALID_OPERATION); + bufObj = get_buffer(ctx, func, target, GL_INVALID_OPERATION); if (!bufObj) return; - _mesa_buffer_sub_data(ctx, bufObj, offset, size, data, "glBufferSubData"); + if (validate_buffer_sub_data(ctx, bufObj, offset, size, func)) + _mesa_buffer_sub_data(ctx, bufObj, offset, size, data); } void GLAPIENTRY @@ -1866,13 +1876,14 @@ _mesa_NamedBufferSubData(GLuint buffer, GLintptr offset, { GET_CURRENT_CONTEXT(ctx); struct gl_buffer_object *bufObj; + const char *func = "glNamedBufferSubData"; - bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, "glNamedBufferSubData"); + bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, func); if (!bufObj) return; - _mesa_buffer_sub_data(ctx, bufObj, offset, size, data, - "glNamedBufferSubData"); + if (validate_buffer_sub_data(ctx, bufObj, offset, size, func)) + _mesa_buffer_sub_data(ctx, bufObj, offset, size, data); } diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h index 024d07daaf8..a7a9673b852 100644 --- a/src/mesa/main/bufferobj.h +++ b/src/mesa/main/bufferobj.h @@ -139,8 +139,7 @@ _mesa_buffer_data(struct gl_context *ctx, struct gl_buffer_object *bufObj, extern void _mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj, - GLintptr offset, GLsizeiptr size, const GLvoid *data, - const char *func); + GLintptr offset, GLsizeiptr size, const GLvoid *data); extern void _mesa_buffer_unmap_all_mappings(struct gl_context *ctx,