[Mesa-dev] [PATCH 01/17] mesa: add validate_buffer_storage() helper
Timothy Arceri
tarceri at itsqueeze.com
Mon May 15 06:19:10 UTC 2017
This will allow use to add KHR_no_error support.
---
src/mesa/main/bufferobj.c | 42 +++++++++++++++++++++++++++---------------
1 file changed, 27 insertions(+), 15 deletions(-)
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 2ab7fe9..0f93b0f 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -1495,75 +1495,84 @@ _mesa_IsBuffer(GLuint id)
struct gl_buffer_object *bufObj;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
bufObj = _mesa_lookup_bufferobj(ctx, id);
return bufObj && bufObj != &DummyBufferObject;
}
-static void
-buffer_storage(struct gl_context *ctx, struct gl_buffer_object *bufObj,
- GLenum target, GLsizeiptr size, const GLvoid *data,
- GLbitfield flags, const char *func)
+static bool
+validate_buffer_storage(struct gl_context *ctx,
+ struct gl_buffer_object *bufObj, GLsizeiptr size,
+ GLbitfield flags, const char *func)
{
if (size <= 0) {
_mesa_error(ctx, GL_INVALID_VALUE, "%s(size <= 0)", func);
- return;
+ return false;
}
GLbitfield valid_flags = GL_MAP_READ_BIT |
GL_MAP_WRITE_BIT |
GL_MAP_PERSISTENT_BIT |
GL_MAP_COHERENT_BIT |
GL_DYNAMIC_STORAGE_BIT |
GL_CLIENT_STORAGE_BIT;
if (ctx->Extensions.ARB_sparse_buffer)
valid_flags |= GL_SPARSE_STORAGE_BIT_ARB;
if (flags & ~valid_flags) {
_mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid flag bits set)", func);
- return;
+ return false;
}
/* The Errors section of the GL_ARB_sparse_buffer spec says:
*
* "INVALID_VALUE is generated by BufferStorage if <flags> contains
* SPARSE_STORAGE_BIT_ARB and <flags> also contains any combination of
* MAP_READ_BIT or MAP_WRITE_BIT."
*/
if (flags & GL_SPARSE_STORAGE_BIT_ARB &&
flags & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) {
_mesa_error(ctx, GL_INVALID_VALUE, "%s(SPARSE_STORAGE and READ/WRITE)", func);
- return;
+ return false;
}
if (flags & GL_MAP_PERSISTENT_BIT &&
!(flags & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT))) {
_mesa_error(ctx, GL_INVALID_VALUE,
"%s(PERSISTENT and flags!=READ/WRITE)", func);
- return;
+ return false;
}
if (flags & GL_MAP_COHERENT_BIT && !(flags & GL_MAP_PERSISTENT_BIT)) {
_mesa_error(ctx, GL_INVALID_VALUE,
"%s(COHERENT and flags!=PERSISTENT)", func);
- return;
+ return false;
}
if (bufObj->Immutable) {
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(immutable)", func);
- return;
+ return false;
}
+ return true;
+}
+
+
+static void
+buffer_storage(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+ GLenum target, GLsizeiptr size, const GLvoid *data,
+ GLbitfield flags, const char *func)
+{
/* Unmap the existing buffer. We'll replace it now. Not an error. */
_mesa_buffer_unmap_all_mappings(ctx, bufObj);
FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
bufObj->Written = GL_TRUE;
bufObj->Immutable = GL_TRUE;
bufObj->MinMaxCacheDirty = true;
assert(ctx->Driver.BufferData);
@@ -1581,45 +1590,48 @@ buffer_storage(struct gl_context *ctx, struct gl_buffer_object *bufObj,
}
}
}
void GLAPIENTRY
_mesa_BufferStorage(GLenum target, GLsizeiptr size, const GLvoid *data,
GLbitfield flags)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
+ const char *func = "glBufferStorage";
- bufObj = get_buffer(ctx, "glBufferStorage", target, GL_INVALID_OPERATION);
+ bufObj = get_buffer(ctx, func, target, GL_INVALID_OPERATION);
if (!bufObj)
return;
- buffer_storage(ctx, bufObj, target, size, data, flags, "glBufferStorage");
+ if (validate_buffer_storage(ctx, bufObj, size, flags, func))
+ buffer_storage(ctx, bufObj, target, size, data, flags, func);
}
void GLAPIENTRY
_mesa_NamedBufferStorage(GLuint buffer, GLsizeiptr size, const GLvoid *data,
GLbitfield flags)
{
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
+ const char *func = "glNamedBufferStorage";
- bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, "glNamedBufferStorage");
+ bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, func);
if (!bufObj)
return;
/*
* In direct state access, buffer objects have an unspecified target since
* they are not required to be bound.
*/
- buffer_storage(ctx, bufObj, GL_NONE, size, data, flags,
- "glNamedBufferStorage");
+ if (validate_buffer_storage(ctx, bufObj, size, flags, func))
+ buffer_storage(ctx, bufObj, GL_NONE, size, data, flags, func);
}
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)
{
bool valid_usage;
--
2.9.3
More information about the mesa-dev
mailing list