mesa: implement sparse storage buffer allocation
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 2 Feb 2017 20:50:32 +0000 (21:50 +0100)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 5 Apr 2017 08:31:01 +0000 (10:31 +0200)
v2:
- spec quote and style (Ian)

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/main/bufferobj.c

index cbd92289b64278bd088bbdf39d701d8c0d6eb0e2..a4ccf8c5e516acdc7952fbb7621de1c46ea01776 100644 (file)
@@ -1536,16 +1536,33 @@ _mesa_buffer_storage(struct gl_context *ctx, struct gl_buffer_object *bufObj,
       return;
    }
 
-   if (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)) {
+   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;
    }
 
+   /* 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;
+   }
+
    if (flags & GL_MAP_PERSISTENT_BIT &&
        !(flags & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT))) {
       _mesa_error(ctx, GL_INVALID_VALUE,