X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fshared.c;h=b0338d78b05009e577553dd728a5fa4f43149806;hb=095515e16ca3cb2c9f1813b6602ee57ae28325a8;hp=40812599819701e37e7f08d580b99d48438c7210;hpb=d04a4dd0039d397c19e28cde878f51cad0877f07;p=mesa.git diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c index 40812599819..b0338d78b05 100644 --- a/src/mesa/main/shared.c +++ b/src/mesa/main/shared.c @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 7.5 * * Copyright (C) 2009 VMware, Inc. All Rights Reserved. * @@ -17,9 +16,10 @@ * 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,20 +28,24 @@ */ #include "imports.h" -#include "mfeatures.h" #include "mtypes.h" #include "hash.h" -#include "hash_table.h" #include "atifragshader.h" #include "bufferobj.h" #include "shared.h" #include "program/program.h" #include "dlist.h" #include "samplerobj.h" -#include "set.h" +#include "shaderapi.h" #include "shaderobj.h" #include "syncobj.h" +#include "texturebindless.h" +#include "util/hash_table.h" +#include "util/set.h" + +static void +free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared); /** * Allocate and initialize a shared context state structure. @@ -62,18 +66,17 @@ _mesa_alloc_shared_state(struct gl_context *ctx) if (!shared) return NULL; - _glthread_INIT_MUTEX(shared->Mutex); + simple_mtx_init(&shared->Mutex, mtx_plain); shared->DisplayList = _mesa_NewHashTable(); + shared->BitmapAtlas = _mesa_NewHashTable(); shared->TexObjects = _mesa_NewHashTable(); shared->Programs = _mesa_NewHashTable(); shared->DefaultVertexProgram = - gl_vertex_program(ctx->Driver.NewProgram(ctx, - GL_VERTEX_PROGRAM_ARB, 0)); + ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0, true); shared->DefaultFragmentProgram = - gl_fragment_program(ctx->Driver.NewProgram(ctx, - GL_FRAGMENT_PROGRAM_ARB, 0)); + ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0, true); shared->ATIShaders = _mesa_NewHashTable(); shared->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0); @@ -85,8 +88,13 @@ _mesa_alloc_shared_state(struct gl_context *ctx) /* GL_ARB_sampler_objects */ shared->SamplerObjects = _mesa_NewHashTable(); + /* GL_ARB_bindless_texture */ + _mesa_init_shared_handles(shared); + /* Allocate the default buffer object */ - shared->NullBufferObj = ctx->Driver.NewBufferObject(ctx, 0, 0); + shared->NullBufferObj = ctx->Driver.NewBufferObject(ctx, 0); + if (!shared->NullBufferObj) + goto fail; /* Create default texture objects */ for (i = 0; i < NUM_TEXTURE_TARGETS; i++) { @@ -105,23 +113,36 @@ _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(); - shared->SyncObjects = _mesa_set_create(NULL, _mesa_key_pointer_equal); + shared->SyncObjects = _mesa_set_create(NULL, _mesa_hash_pointer, + _mesa_key_pointer_equal); + + shared->MemoryObjects = _mesa_NewHashTable(); + shared->SemaphoreObjects = _mesa_NewHashTable(); return shared; + +fail: + free_shared_state(ctx, shared); + return NULL; } @@ -137,6 +158,18 @@ delete_displaylist_cb(GLuint id, void *data, void *userData) } +/** + * Callback for deleting a bitmap atlas. Called by _mesa_HashDeleteAll(). + */ +static void +delete_bitmap_atlas_cb(GLuint id, void *data, void *userData) +{ + struct gl_bitmap_atlas *atlas = (struct gl_bitmap_atlas *) data; + struct gl_context *ctx = (struct gl_context *) userData; + _mesa_delete_bitmap_atlas(ctx, atlas); +} + + /** * Callback for deleting a texture object. Called by _mesa_HashDeleteAll(). */ @@ -158,7 +191,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); } @@ -186,10 +219,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); } @@ -219,13 +250,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); } } @@ -276,6 +307,27 @@ delete_sampler_object_cb(GLuint id, void *data, void *userData) _mesa_reference_sampler_object(ctx, &sampObj, NULL); } +/** + * Callback for deleting a memory object. Called by _mesa_HashDeleteAll(). + */ +static void +delete_memory_object_cb(GLuint id, void *data, void *userData) +{ + struct gl_memory_object *memObj = (struct gl_memory_object *) data; + struct gl_context *ctx = (struct gl_context *) 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. @@ -303,61 +355,105 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared) /* * Free display lists */ - _mesa_HashDeleteAll(shared->DisplayList, delete_displaylist_cb, ctx); - _mesa_DeleteHashTable(shared->DisplayList); + if (shared->DisplayList) { + _mesa_HashDeleteAll(shared->DisplayList, delete_displaylist_cb, ctx); + _mesa_DeleteHashTable(shared->DisplayList); + } + + if (shared->BitmapAtlas) { + _mesa_HashDeleteAll(shared->BitmapAtlas, delete_bitmap_atlas_cb, ctx); + _mesa_DeleteHashTable(shared->BitmapAtlas); + } - _mesa_HashWalk(shared->ShaderObjects, free_shader_program_data_cb, ctx); - _mesa_HashDeleteAll(shared->ShaderObjects, delete_shader_cb, ctx); - _mesa_DeleteHashTable(shared->ShaderObjects); + if (shared->ShaderObjects) { + _mesa_HashWalk(shared->ShaderObjects, free_shader_program_data_cb, ctx); + _mesa_HashDeleteAll(shared->ShaderObjects, delete_shader_cb, ctx); + _mesa_DeleteHashTable(shared->ShaderObjects); + } - _mesa_HashDeleteAll(shared->Programs, delete_program_cb, ctx); - _mesa_DeleteHashTable(shared->Programs); + if (shared->Programs) { + _mesa_HashDeleteAll(shared->Programs, delete_program_cb, ctx); + _mesa_DeleteHashTable(shared->Programs); + } - _mesa_reference_vertprog(ctx, &shared->DefaultVertexProgram, NULL); - _mesa_reference_fragprog(ctx, &shared->DefaultFragmentProgram, NULL); + if (shared->DefaultVertexProgram) + _mesa_reference_program(ctx, &shared->DefaultVertexProgram, NULL); - _mesa_HashDeleteAll(shared->ATIShaders, delete_fragshader_cb, ctx); - _mesa_DeleteHashTable(shared->ATIShaders); - _mesa_delete_ati_fragment_shader(ctx, shared->DefaultFragmentShader); + if (shared->DefaultFragmentProgram) + _mesa_reference_program(ctx, &shared->DefaultFragmentProgram, NULL); - _mesa_HashDeleteAll(shared->BufferObjects, delete_bufferobj_cb, ctx); - _mesa_DeleteHashTable(shared->BufferObjects); + if (shared->DefaultFragmentShader) + _mesa_delete_ati_fragment_shader(ctx, shared->DefaultFragmentShader); - _mesa_HashDeleteAll(shared->FrameBuffers, delete_framebuffer_cb, ctx); - _mesa_DeleteHashTable(shared->FrameBuffers); - _mesa_HashDeleteAll(shared->RenderBuffers, delete_renderbuffer_cb, ctx); - _mesa_DeleteHashTable(shared->RenderBuffers); + if (shared->ATIShaders) { + _mesa_HashDeleteAll(shared->ATIShaders, delete_fragshader_cb, ctx); + _mesa_DeleteHashTable(shared->ATIShaders); + } - _mesa_reference_buffer_object(ctx, &shared->NullBufferObj, NULL); + if (shared->BufferObjects) { + _mesa_HashDeleteAll(shared->BufferObjects, delete_bufferobj_cb, ctx); + _mesa_DeleteHashTable(shared->BufferObjects); + } - { - struct set_entry *entry; + if (shared->FrameBuffers) { + _mesa_HashDeleteAll(shared->FrameBuffers, delete_framebuffer_cb, ctx); + _mesa_DeleteHashTable(shared->FrameBuffers); + } + if (shared->RenderBuffers) { + _mesa_HashDeleteAll(shared->RenderBuffers, delete_renderbuffer_cb, ctx); + _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); + _mesa_unref_sync_object(ctx, (struct gl_sync_object *) entry->key, 1); } + + _mesa_set_destroy(shared->SyncObjects, NULL); } - _mesa_set_destroy(shared->SyncObjects, NULL); - _mesa_HashDeleteAll(shared->SamplerObjects, delete_sampler_object_cb, ctx); - _mesa_DeleteHashTable(shared->SamplerObjects); + if (shared->SamplerObjects) { + _mesa_HashDeleteAll(shared->SamplerObjects, delete_sampler_object_cb, + ctx); + _mesa_DeleteHashTable(shared->SamplerObjects); + } /* * 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]); + if (shared->DefaultTex[i]) + ctx->Driver.DeleteTexture(ctx, shared->DefaultTex[i]); } /* all other textures */ - _mesa_HashDeleteAll(shared->TexObjects, delete_texture_cb, ctx); - _mesa_DeleteHashTable(shared->TexObjects); + if (shared->TexObjects) { + _mesa_HashDeleteAll(shared->TexObjects, delete_texture_cb, ctx); + _mesa_DeleteHashTable(shared->TexObjects); + } + + _mesa_free_shared_handles(shared); + + 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); + } - _glthread_DESTROY_MUTEX(shared->Mutex); - _glthread_DESTROY_MUTEX(shared->TexMutex); + simple_mtx_destroy(&shared->Mutex); + mtx_destroy(&shared->TexMutex); free(shared); } @@ -380,11 +476,11 @@ _mesa_reference_shared_state(struct gl_context *ctx, struct gl_shared_state *old = *ptr; GLboolean delete; - _glthread_LOCK_MUTEX(old->Mutex); + simple_mtx_lock(&old->Mutex); assert(old->RefCount >= 1); old->RefCount--; delete = (old->RefCount == 0); - _glthread_UNLOCK_MUTEX(old->Mutex); + simple_mtx_unlock(&old->Mutex); if (delete) { free_shared_state(ctx, old); @@ -395,9 +491,9 @@ _mesa_reference_shared_state(struct gl_context *ctx, if (state) { /* reference new state */ - _glthread_LOCK_MUTEX(state->Mutex); + simple_mtx_lock(&state->Mutex); state->RefCount++; *ptr = state; - _glthread_UNLOCK_MUTEX(state->Mutex); + simple_mtx_unlock(&state->Mutex); } }