mesa: improve debug log in atifragshader
[mesa.git] / src / mesa / main / shared.c
index 2d2f7bd1d78158dd669a936dc3c9d3ceab2d059d..c37b31d1753e45455627382d936c18febceaa2d4 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.5
  *
  * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 /**
@@ -28,7 +28,6 @@
  */
 
 #include "imports.h"
-#include "mfeatures.h"
 #include "mtypes.h"
 #include "hash.h"
 #include "atifragshader.h"
 #include "program/program.h"
 #include "dlist.h"
 #include "samplerobj.h"
+#include "shaderapi.h"
 #include "shaderobj.h"
 #include "syncobj.h"
 
+#include "util/hash_table.h"
+#include "util/set.h"
 
 /**
  * Allocate and initialize a shared context state structure.
@@ -60,7 +62,7 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
    if (!shared)
       return NULL;
 
-   _glthread_INIT_MUTEX(shared->Mutex);
+   mtx_init(&shared->Mutex, mtx_plain);
 
    shared->DisplayList = _mesa_NewHashTable();
    shared->TexObjects = _mesa_NewHashTable();
@@ -84,12 +86,15 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
    shared->SamplerObjects = _mesa_NewHashTable();
 
    /* Allocate the default buffer object */
-   shared->NullBufferObj = ctx->Driver.NewBufferObject(ctx, 0, 0);
+   shared->NullBufferObj = ctx->Driver.NewBufferObject(ctx, 0);
 
    /* Create default texture objects */
    for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
       /* NOTE: the order of these enums matches the TEXTURE_x_INDEX values */
       static const GLenum targets[] = {
+         GL_TEXTURE_2D_MULTISAMPLE,
+         GL_TEXTURE_2D_MULTISAMPLE_ARRAY,
+         GL_TEXTURE_CUBE_MAP_ARRAY,
          GL_TEXTURE_BUFFER,
          GL_TEXTURE_2D_ARRAY_EXT,
          GL_TEXTURE_1D_ARRAY_EXT,
@@ -100,21 +105,27 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
          GL_TEXTURE_2D,
          GL_TEXTURE_1D
       };
-      STATIC_ASSERT(Elements(targets) == NUM_TEXTURE_TARGETS);
+      STATIC_ASSERT(ARRAY_SIZE(targets) == NUM_TEXTURE_TARGETS);
       shared->DefaultTex[i] = ctx->Driver.NewTextureObject(ctx, 0, targets[i]);
+      /* Need to explicitly set/overwrite the TargetIndex field here since
+       * the call to _mesa_tex_target_to_index() in NewTextureObject() may
+       * fail if the texture target is not supported.
+       */
+      shared->DefaultTex[i]->TargetIndex = i;
    }
 
    /* sanity check */
    assert(shared->DefaultTex[TEXTURE_1D_INDEX]->RefCount == 1);
 
    /* Mutex and timestamp for texobj state validation */
-   _glthread_INIT_MUTEX(shared->TexMutex);
+   mtx_init(&shared->TexMutex, mtx_recursive);
    shared->TextureStateStamp = 0;
 
    shared->FrameBuffers = _mesa_NewHashTable();
    shared->RenderBuffers = _mesa_NewHashTable();
 
-   make_empty_list(& shared->SyncObjects);
+   shared->SyncObjects = _mesa_set_create(NULL, _mesa_hash_pointer,
+                                          _mesa_key_pointer_equal);
 
    return shared;
 }
@@ -153,7 +164,7 @@ delete_program_cb(GLuint id, void *data, void *userData)
    struct gl_program *prog = (struct gl_program *) data;
    struct gl_context *ctx = (struct gl_context *) userData;
    if(prog != &_mesa_DummyProgram) {
-      ASSERT(prog->RefCount == 1); /* should only be referenced by hash table */
+      assert(prog->RefCount == 1); /* should only be referenced by hash table */
       prog->RefCount = 0;  /* now going away */
       ctx->Driver.DeleteProgram(ctx, prog);
    }
@@ -181,10 +192,8 @@ delete_bufferobj_cb(GLuint id, void *data, void *userData)
 {
    struct gl_buffer_object *bufObj = (struct gl_buffer_object *) data;
    struct gl_context *ctx = (struct gl_context *) userData;
-   if (_mesa_bufferobj_mapped(bufObj)) {
-      ctx->Driver.UnmapBuffer(ctx, bufObj);
-      bufObj->Pointer = NULL;
-   }
+
+   _mesa_buffer_unmap_all_mappings(ctx, bufObj);
    _mesa_reference_buffer_object(ctx, &bufObj, NULL);
 }
 
@@ -214,13 +223,13 @@ delete_shader_cb(GLuint id, void *data, void *userData)
 {
    struct gl_context *ctx = (struct gl_context *) userData;
    struct gl_shader *sh = (struct gl_shader *) data;
-   if (sh->Type == GL_FRAGMENT_SHADER || sh->Type == GL_VERTEX_SHADER) {
-      ctx->Driver.DeleteShader(ctx, sh);
+   if (_mesa_validate_shader_target(ctx, sh->Type)) {
+      _mesa_delete_shader(ctx, sh);
    }
    else {
       struct gl_shader_program *shProg = (struct gl_shader_program *) data;
-      ASSERT(shProg->Type == GL_SHADER_PROGRAM_MESA);
-      ctx->Driver.DeleteShaderProgram(ctx, shProg);
+      assert(shProg->Type == GL_SHADER_PROGRAM_MESA);
+      _mesa_delete_shader_program(ctx, shProg);
    }
 }
 
@@ -252,10 +261,11 @@ delete_framebuffer_cb(GLuint id, void *data, void *userData)
 static void
 delete_renderbuffer_cb(GLuint id, void *data, void *userData)
 {
+   struct gl_context *ctx = (struct gl_context *) userData;
    struct gl_renderbuffer *rb = (struct gl_renderbuffer *) data;
    rb->RefCount = 0;  /* see comment for FBOs above */
    if (rb->Delete)
-      rb->Delete(rb);
+      rb->Delete(ctx, rb);
 }
 
 
@@ -325,13 +335,13 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared)
    _mesa_reference_buffer_object(ctx, &shared->NullBufferObj, NULL);
 
    {
-      struct simple_node *node;
-      struct simple_node *temp;
+      struct set_entry *entry;
 
-      foreach_s(node, temp, & shared->SyncObjects) {
-        _mesa_unref_sync_object(ctx, (struct gl_sync_object *) node);
+      set_foreach(shared->SyncObjects, entry) {
+         _mesa_unref_sync_object(ctx, (struct gl_sync_object *) entry->key);
       }
    }
+   _mesa_set_destroy(shared->SyncObjects, NULL);
 
    _mesa_HashDeleteAll(shared->SamplerObjects, delete_sampler_object_cb, ctx);
    _mesa_DeleteHashTable(shared->SamplerObjects);
@@ -340,7 +350,7 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared)
     * Free texture objects (after FBOs since some textures might have
     * been bound to FBOs).
     */
-   ASSERT(ctx->Driver.DeleteTexture);
+   assert(ctx->Driver.DeleteTexture);
    /* the default textures */
    for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
       ctx->Driver.DeleteTexture(ctx, shared->DefaultTex[i]);
@@ -350,8 +360,8 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared)
    _mesa_HashDeleteAll(shared->TexObjects, delete_texture_cb, ctx);
    _mesa_DeleteHashTable(shared->TexObjects);
 
-   _glthread_DESTROY_MUTEX(shared->Mutex);
-   _glthread_DESTROY_MUTEX(shared->TexMutex);
+   mtx_destroy(&shared->Mutex);
+   mtx_destroy(&shared->TexMutex);
 
    free(shared);
 }
@@ -374,11 +384,11 @@ _mesa_reference_shared_state(struct gl_context *ctx,
       struct gl_shared_state *old = *ptr;
       GLboolean delete;
 
-      _glthread_LOCK_MUTEX(old->Mutex);
+      mtx_lock(&old->Mutex);
       assert(old->RefCount >= 1);
       old->RefCount--;
       delete = (old->RefCount == 0);
-      _glthread_UNLOCK_MUTEX(old->Mutex);
+      mtx_unlock(&old->Mutex);
 
       if (delete) {
          free_shared_state(ctx, old);
@@ -389,9 +399,9 @@ _mesa_reference_shared_state(struct gl_context *ctx,
 
    if (state) {
       /* reference new state */
-      _glthread_LOCK_MUTEX(state->Mutex);
+      mtx_lock(&state->Mutex);
       state->RefCount++;
       *ptr = state;
-      _glthread_UNLOCK_MUTEX(state->Mutex);
+      mtx_unlock(&state->Mutex);
    }
 }