glthread: track primitive restart state
[mesa.git] / src / mesa / main / shared.c
index a2f0f8d398c40ad436a92ad8d1cf08724b9ee226..51e15178ce7bd6a40de156869b8d96aa440408be 100644 (file)
@@ -27,7 +27,7 @@
  * Shared-context state
  */
 
-#include "imports.h"
+
 #include "mtypes.h"
 #include "hash.h"
 #include "atifragshader.h"
 
 #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);
 
 /**
  * Allocate and initialize a shared context state structure.
@@ -63,7 +67,7 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
    if (!shared)
       return NULL;
 
-   mtx_init(&shared->Mutex, mtx_plain);
+   simple_mtx_init(&shared->Mutex, mtx_plain);
 
    shared->DisplayList = _mesa_NewHashTable();
    shared->BitmapAtlas = _mesa_NewHashTable();
@@ -71,9 +75,9 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
    shared->Programs = _mesa_NewHashTable();
 
    shared->DefaultVertexProgram =
-      ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0, true);
+      ctx->Driver.NewProgram(ctx, MESA_SHADER_VERTEX, 0, true);
    shared->DefaultFragmentProgram =
-      ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0, true);
+      ctx->Driver.NewProgram(ctx, MESA_SHADER_FRAGMENT, 0, true);
 
    shared->ATIShaders = _mesa_NewHashTable();
    shared->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0);
@@ -88,8 +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);
+   /* 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++) {
@@ -131,6 +136,8 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
                                           _mesa_key_pointer_equal);
 
    shared->MemoryObjects = _mesa_NewHashTable();
+   shared->SemaphoreObjects = _mesa_NewHashTable();
+
    return shared;
 }
 
@@ -307,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.
@@ -384,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);
       }
@@ -421,12 +434,21 @@ 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);
    }
 
-   mtx_destroy(&shared->Mutex);
+   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);
 
    free(shared);
@@ -450,11 +472,11 @@ _mesa_reference_shared_state(struct gl_context *ctx,
       struct gl_shared_state *old = *ptr;
       GLboolean delete;
 
-      mtx_lock(&old->Mutex);
+      simple_mtx_lock(&old->Mutex);
       assert(old->RefCount >= 1);
       old->RefCount--;
       delete = (old->RefCount == 0);
-      mtx_unlock(&old->Mutex);
+      simple_mtx_unlock(&old->Mutex);
 
       if (delete) {
          free_shared_state(ctx, old);
@@ -465,9 +487,9 @@ _mesa_reference_shared_state(struct gl_context *ctx,
 
    if (state) {
       /* reference new state */
-      mtx_lock(&state->Mutex);
+      simple_mtx_lock(&state->Mutex);
       state->RefCount++;
       *ptr = state;
-      mtx_unlock(&state->Mutex);
+      simple_mtx_unlock(&state->Mutex);
    }
 }