[Mesa-dev] [PATCH 05/13] mesa: add error checks to glMapBufferRange for ARB_buffer_storage
Marek Olšák
maraeo at gmail.com
Wed Jan 29 17:20:47 PST 2014
From: Marek Olšák <marek.olsak at amd.com>
---
src/mesa/main/bufferobj.c | 46 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 7 deletions(-)
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 55184f1..ca0b5dd 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -1934,6 +1934,7 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
GET_CURRENT_CONTEXT(ctx);
struct gl_buffer_object *bufObj;
void *map;
+ GLbitfield allowed_access;
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
@@ -1968,13 +1969,20 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
return NULL;
}
- if (access & ~(GL_MAP_READ_BIT |
- GL_MAP_WRITE_BIT |
- GL_MAP_INVALIDATE_RANGE_BIT |
- GL_MAP_INVALIDATE_BUFFER_BIT |
- GL_MAP_FLUSH_EXPLICIT_BIT |
- GL_MAP_UNSYNCHRONIZED_BIT)) {
- /* generate an error if any undefind bit is set */
+ allowed_access = GL_MAP_READ_BIT |
+ GL_MAP_WRITE_BIT |
+ GL_MAP_INVALIDATE_RANGE_BIT |
+ GL_MAP_INVALIDATE_BUFFER_BIT |
+ GL_MAP_FLUSH_EXPLICIT_BIT |
+ GL_MAP_UNSYNCHRONIZED_BIT;
+
+ if (ctx->Extensions.ARB_buffer_storage) {
+ allowed_access |= GL_MAP_PERSISTENT_BIT |
+ GL_MAP_COHERENT_BIT;
+ }
+
+ if (access & ~allowed_access) {
+ /* generate an error if any other than allowed bit is set */
_mesa_error(ctx, GL_INVALID_VALUE, "glMapBufferRange(access)");
return NULL;
}
@@ -2005,6 +2013,30 @@ _mesa_MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
if (!bufObj)
return NULL;
+ if (access & GL_MAP_READ_BIT &&
+ !(bufObj->StorageFlags & GL_MAP_READ_BIT)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(invalid read flag)");
+ }
+
+ if (access & GL_MAP_WRITE_BIT &&
+ !(bufObj->StorageFlags & GL_MAP_WRITE_BIT)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(invalid write flag)");
+ }
+
+ if (access & GL_MAP_COHERENT_BIT &&
+ !(bufObj->StorageFlags & GL_MAP_COHERENT_BIT)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(invalid coherent flag)");
+ }
+
+ if (access & GL_MAP_PERSISTENT_BIT &&
+ !(bufObj->StorageFlags & GL_MAP_PERSISTENT_BIT)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glMapBufferRange(invalid persistent flag)");
+ }
+
if (offset + length > bufObj->Size) {
_mesa_error(ctx, GL_INVALID_VALUE,
"glMapBufferRange(offset + length > size)");
--
1.8.3.2
More information about the mesa-dev
mailing list