From 7f19018cc3a66c44530994533f1700fba8ee9f7d Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Thu, 20 Jul 2017 10:43:30 +0200 Subject: [PATCH] mesa: add buffer_data() and buffer_data_error() helpers And call buffer_data_error() from _mesa_buffer_data(). Signed-off-by: Samuel Pitoiset Reviewed-by: Timothy Arceri --- src/mesa/main/bufferobj.c | 112 ++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 48 deletions(-) diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index b46b81271a1..1bae0258054 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -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 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 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) -- 2.30.2