mesa: add Const.BufferCreateMapUnsynchronizedThreadSafe & MESA_MAP_THREAD_SAFE
[mesa.git] / src / mesa / main / shared.c
index e3417a4df3067fea2708c57ff17c77dd984a02a7..357368b38deb8bf221585adfe3a3280650cff5fa 100644 (file)
@@ -27,7 +27,7 @@
  * Shared-context state
  */
 
-#include "imports.h"
+
 #include "mtypes.h"
 #include "hash.h"
 #include "atifragshader.h"
@@ -43,6 +43,7 @@
 
 #include "util/hash_table.h"
 #include "util/set.h"
+#include "util/u_memory.h"
 
 static void
 free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared);
@@ -91,10 +92,9 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
    /* GL_ARB_bindless_texture */
    _mesa_init_shared_handles(shared);
 
-   /* Allocate the default buffer object */
-   shared->NullBufferObj = ctx->Driver.NewBufferObject(ctx, 0);
-   if (!shared->NullBufferObj)
-      goto fail;
+   /* ARB_shading_language_include */
+   _mesa_init_shader_includes(shared);
+   mtx_init(&shared->ShaderIncludeMutex, mtx_plain);
 
    /* Create default texture objects */
    for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
@@ -136,11 +136,9 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
                                           _mesa_key_pointer_equal);
 
    shared->MemoryObjects = _mesa_NewHashTable();
-   return shared;
+   shared->SemaphoreObjects = _mesa_NewHashTable();
 
-fail:
-   free_shared_state(ctx, shared);
-   return NULL;
+   return shared;
 }
 
 
@@ -316,13 +314,23 @@ delete_memory_object_cb(GLuint id, void *data, void *userData)
    ctx->Driver.DeleteMemoryObject(ctx, memObj);
 }
 
+/**
+ * Callback for deleting a memory object.  Called by _mesa_HashDeleteAll().
+ */
+static void
+delete_semaphore_object_cb(GLuint id, void *data, void *userData)
+{
+   struct gl_semaphore_object *semObj = (struct gl_semaphore_object *) data;
+   struct gl_context *ctx = (struct gl_context *) userData;
+   ctx->Driver.DeleteSemaphoreObject(ctx, semObj);
+}
 
 /**
  * Deallocate a shared state object and all children structures.
  *
  * \param ctx GL context.
  * \param shared shared state pointer.
- * 
+ *
  * Frees the display lists, the texture objects (calling the driver texture
  * deletion callback to free its private data) and the vertex programs, as well
  * as their hash tables.
@@ -393,11 +401,7 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared)
       _mesa_DeleteHashTable(shared->RenderBuffers);
    }
 
-   if (shared->NullBufferObj)
-      _mesa_reference_buffer_object(ctx, &shared->NullBufferObj, NULL);
-
    if (shared->SyncObjects) {
-      struct set_entry *entry;
       set_foreach(shared->SyncObjects, entry) {
          _mesa_unref_sync_object(ctx, (struct gl_sync_object *) entry->key, 1);
       }
@@ -430,11 +434,20 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared)
 
    _mesa_free_shared_handles(shared);
 
+   /* ARB_shading_language_include */
+   _mesa_destroy_shader_includes(shared);
+   mtx_destroy(&shared->ShaderIncludeMutex);
+
    if (shared->MemoryObjects) {
       _mesa_HashDeleteAll(shared->MemoryObjects, delete_memory_object_cb, ctx);
       _mesa_DeleteHashTable(shared->MemoryObjects);
    }
 
+   if (shared->SemaphoreObjects) {
+      _mesa_HashDeleteAll(shared->SemaphoreObjects, delete_semaphore_object_cb, ctx);
+      _mesa_DeleteHashTable(shared->SemaphoreObjects);
+   }
+
    simple_mtx_destroy(&shared->Mutex);
    mtx_destroy(&shared->TexMutex);