mesa/glsl: set num_textures per stage directly in shader_info
[mesa.git] / src / mesa / main / bufferobj.c
index e60a8ea523751d9c2d48d9d3964dba0af3a6ec4d..eca86aae98ce8e17439d868c821045bc99a2f21a 100644 (file)
@@ -44,6 +44,7 @@
 #include "glformats.h"
 #include "texstore.h"
 #include "transformfeedback.h"
+#include "varray.h"
 
 
 /* Debug flags */
@@ -1020,7 +1021,8 @@ bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer)
 
    bindTarget = get_buffer_target(ctx, target);
    if (!bindTarget) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target 0x%x)", target);
+      _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferARB(target %s)",
+                  _mesa_enum_to_string(target));
       return;
    }
 
@@ -1097,8 +1099,11 @@ _mesa_lookup_bufferobj(struct gl_context *ctx, GLuint buffer)
 struct gl_buffer_object *
 _mesa_lookup_bufferobj_locked(struct gl_context *ctx, GLuint buffer)
 {
-   return (struct gl_buffer_object *)
-      _mesa_HashLookupLocked(ctx->Shared->BufferObjects, buffer);
+   if (buffer == 0)
+      return NULL;
+   else
+      return (struct gl_buffer_object *)
+         _mesa_HashLookupLocked(ctx->Shared->BufferObjects, buffer);
 }
 
 /**
@@ -1195,11 +1200,13 @@ _mesa_multi_bind_lookup_bufferobj(struct gl_context *ctx,
  */
 static void
 unbind(struct gl_context *ctx,
-       struct gl_buffer_object **ptr,
+       struct gl_vertex_array_object *vao, unsigned index,
        struct gl_buffer_object *obj)
 {
-   if (*ptr == obj) {
-      _mesa_reference_buffer_object(ctx, ptr, ctx->Shared->NullBufferObj);
+   if (vao->BufferBinding[index].BufferObj == obj) {
+      _mesa_bind_vertex_buffer(ctx, vao, index, ctx->Shared->NullBufferObj,
+                               vao->BufferBinding[index].Offset,
+                               vao->BufferBinding[index].Stride);
    }
 }
 
@@ -1283,10 +1290,11 @@ _mesa_DeleteBuffers(GLsizei n, const GLuint *ids)
       return;
    }
 
-   mtx_lock(&ctx->Shared->Mutex);
+   _mesa_HashLockMutex(ctx->Shared->BufferObjects);
 
    for (i = 0; i < n; i++) {
-      struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, ids[i]);
+      struct gl_buffer_object *bufObj =
+         _mesa_lookup_bufferobj_locked(ctx, ids[i]);
       if (bufObj) {
          struct gl_vertex_array_object *vao = ctx->Array.VAO;
          GLuint j;
@@ -1296,8 +1304,8 @@ _mesa_DeleteBuffers(GLsizei n, const GLuint *ids)
          _mesa_buffer_unmap_all_mappings(ctx, bufObj);
 
          /* unbind any vertex pointers bound to this buffer */
-         for (j = 0; j < ARRAY_SIZE(vao->VertexBinding); j++) {
-            unbind(ctx, &vao->VertexBinding[j].BufferObj, bufObj);
+         for (j = 0; j < ARRAY_SIZE(vao->BufferBinding); j++) {
+            unbind(ctx, vao, j, bufObj);
          }
 
          if (ctx->Array.ArrayBufferObj == bufObj) {
@@ -1395,7 +1403,7 @@ _mesa_DeleteBuffers(GLsizei n, const GLuint *ids)
          }
 
          /* The ID is immediately freed for re-use */
-         _mesa_HashRemove(ctx->Shared->BufferObjects, ids[i]);
+         _mesa_HashRemoveLocked(ctx->Shared->BufferObjects, ids[i]);
          /* Make sure we do not run into the classic ABA problem on bind.
           * We don't want to allow re-binding a buffer object that's been
           * "deleted" by glDeleteBuffers().
@@ -1411,7 +1419,7 @@ _mesa_DeleteBuffers(GLsizei n, const GLuint *ids)
       }
    }
 
-   mtx_unlock(&ctx->Shared->Mutex);
+   _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
 }
 
 
@@ -1445,7 +1453,7 @@ create_buffers(GLsizei n, GLuint *buffers, bool dsa)
    /*
     * This must be atomic (generation and allocation of buffer object IDs)
     */
-   mtx_lock(&ctx->Shared->Mutex);
+   _mesa_HashLockMutex(ctx->Shared->BufferObjects);
 
    first = _mesa_HashFindFreeKeyBlock(ctx->Shared->BufferObjects, n);
 
@@ -1460,17 +1468,17 @@ create_buffers(GLsizei n, GLuint *buffers, bool dsa)
          buf = ctx->Driver.NewBufferObject(ctx, buffers[i]);
          if (!buf) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
-            mtx_unlock(&ctx->Shared->Mutex);
+            _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
             return;
          }
       }
       else
          buf = &DummyBufferObject;
 
-      _mesa_HashInsert(ctx->Shared->BufferObjects, buffers[i], buf);
+      _mesa_HashInsertLocked(ctx->Shared->BufferObjects, buffers[i], buf);
    }
 
-   mtx_unlock(&ctx->Shared->Mutex);
+   _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
 }
 
 /**
@@ -1512,9 +1520,7 @@ _mesa_IsBuffer(GLuint id)
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
 
-   mtx_lock(&ctx->Shared->Mutex);
    bufObj = _mesa_lookup_bufferobj(ctx, id);
-   mtx_unlock(&ctx->Shared->Mutex);
 
    return bufObj && bufObj != &DummyBufferObject;
 }
@@ -1762,7 +1768,7 @@ _mesa_buffer_sub_data(struct gl_context *ctx, struct gl_buffer_object *bufObj,
                       const char *func)
 {
    if (!buffer_object_subdata_range_good(ctx, bufObj, offset, size,
-                                         false, func)) {
+                                         true, func)) {
       /* error already recorded */
       return;
    }
@@ -3069,11 +3075,11 @@ bind_buffers_check_offset_and_size(struct gl_context *ctx,
                                    const GLsizeiptr *sizes)
 {
    if (offsets[index] < 0) {
-     /* The ARB_multi_bind spec says:
-      *
-      *    "An INVALID_VALUE error is generated by BindBuffersRange if any
-      *     value in <offsets> is less than zero (per binding)."
-      */
+      /* The ARB_multi_bind spec says:
+       *
+       *    "An INVALID_VALUE error is generated by BindBuffersRange if any
+       *     value in <offsets> is less than zero (per binding)."
+       */
       _mesa_error(ctx, GL_INVALID_VALUE,
                   "glBindBuffersRange(offsets[%u]=%" PRId64 " < 0)",
                   index, (int64_t) offsets[index]);
@@ -3081,11 +3087,11 @@ bind_buffers_check_offset_and_size(struct gl_context *ctx,
    }
 
    if (sizes[index] <= 0) {
-     /* The ARB_multi_bind spec says:
-      *
-      *     "An INVALID_VALUE error is generated by BindBuffersRange if any
-      *      value in <sizes> is less than or equal to zero (per binding)."
-      */
+      /* The ARB_multi_bind spec says:
+       *
+       *     "An INVALID_VALUE error is generated by BindBuffersRange if any
+       *      value in <sizes> is less than or equal to zero (per binding)."
+       */
       _mesa_error(ctx, GL_INVALID_VALUE,
                   "glBindBuffersRange(sizes[%u]=%" PRId64 " <= 0)",
                   index, (int64_t) sizes[index]);
@@ -3964,7 +3970,7 @@ _mesa_InvalidateBufferSubData(GLuint buffer, GLintptr offset,
    bufObj = _mesa_lookup_bufferobj(ctx, buffer);
    if (!bufObj || bufObj == &DummyBufferObject) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glInvalidateBufferSubData(name = 0x%x) invalid object",
+                  "glInvalidateBufferSubData(name = %u) invalid object",
                   buffer);
       return;
    }
@@ -4015,7 +4021,7 @@ _mesa_InvalidateBufferData(GLuint buffer)
    bufObj = _mesa_lookup_bufferobj(ctx, buffer);
    if (!bufObj || bufObj == &DummyBufferObject) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glInvalidateBufferData(name = 0x%x) invalid object",
+                  "glInvalidateBufferData(name = %u) invalid object",
                   buffer);
       return;
    }