diff options
author | Timothy Arceri <[email protected]> | 2017-05-12 17:10:10 +1000 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2017-05-17 10:12:03 +1000 |
commit | 5d29e6aab8ac05cbd73433b45958b2f82eefa91d (patch) | |
tree | db63712297054ce10869c15684d4788209390cad /src/mesa/main/bufferobj.c | |
parent | 624dc2833e0d0263b434e234437dfbd9f4840b75 (diff) |
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 <[email protected]>
Diffstat (limited to 'src/mesa/main/bufferobj.c')
-rw-r--r-- | src/mesa/main/bufferobj.c | 67 |
1 files changed, 39 insertions, 28 deletions
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); } |