X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fshared.c;h=caa6132d4abaa2554116846009bd5ac788819164;hb=0cbdead62e615dc197b3831941ae311865fa6642;hp=4d01e8abc6ef01a6920b2bdf4293747d6b75ceaa;hpb=ab9d1011f5549502a4b960c2067cde69856a2719;p=mesa.git diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c index 4d01e8abc6e..caa6132d4ab 100644 --- a/src/mesa/main/shared.c +++ b/src/mesa/main/shared.c @@ -27,23 +27,23 @@ * Shared-context state */ - - #include "imports.h" +#include "mfeatures.h" #include "mtypes.h" #include "hash.h" -#include "arrayobj.h" +#if FEATURE_ATI_fragment_shader +#include "atifragshader.h" +#endif #include "bufferobj.h" #include "shared.h" -#include "shader/program.h" -#include "shader/shader_api.h" +#include "program/program.h" #include "dlist.h" -#if FEATURE_ATI_fragment_shader -#include "shader/atifragshader.h" +#if FEATURE_ARB_sampler_objects +#include "samplerobj.h" #endif -#if FEATURE_ARB_sync +#include "shaderobj.h" #include "syncobj.h" -#endif + /** * Allocate and initialize a shared context state structure. @@ -55,7 +55,7 @@ * failure. */ struct gl_shared_state * -_mesa_alloc_shared_state(GLcontext *ctx) +_mesa_alloc_shared_state(struct gl_context *ctx) { struct gl_shared_state *shared; GLuint i; @@ -93,25 +93,29 @@ _mesa_alloc_shared_state(GLcontext *ctx) shared->BufferObjects = _mesa_NewHashTable(); #endif - /* Allocate the default buffer object and set refcount so high that - * it never gets deleted. - * XXX with recent/improved refcounting this may not longer be needed. - */ +#if FEATURE_ARB_sampler_objects + /* GL_ARB_sampler_objects */ + shared->SamplerObjects = _mesa_NewHashTable(); +#endif + + /* Allocate the default buffer object */ shared->NullBufferObj = ctx->Driver.NewBufferObject(ctx, 0, 0); - shared->NullBufferObj->RefCount = 1000 * 1000 * 1000; /* 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[NUM_TEXTURE_TARGETS] = { + GL_TEXTURE_BUFFER, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_1D_ARRAY_EXT, + GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_CUBE_MAP, GL_TEXTURE_3D, GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_2D, GL_TEXTURE_1D }; + assert(Elements(targets) == NUM_TEXTURE_TARGETS); shared->DefaultTex[i] = ctx->Driver.NewTextureObject(ctx, 0, targets[i]); } @@ -127,9 +131,7 @@ _mesa_alloc_shared_state(GLcontext *ctx) shared->RenderBuffers = _mesa_NewHashTable(); #endif -#if FEATURE_ARB_sync make_empty_list(& shared->SyncObjects); -#endif return shared; } @@ -142,7 +144,7 @@ static void delete_displaylist_cb(GLuint id, void *data, void *userData) { struct gl_display_list *list = (struct gl_display_list *) data; - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; _mesa_delete_list(ctx, list); } @@ -154,7 +156,7 @@ static void delete_texture_cb(GLuint id, void *data, void *userData) { struct gl_texture_object *texObj = (struct gl_texture_object *) data; - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; ctx->Driver.DeleteTexture(ctx, texObj); } @@ -166,7 +168,7 @@ static void delete_program_cb(GLuint id, void *data, void *userData) { struct gl_program *prog = (struct gl_program *) data; - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; if(prog != &_mesa_DummyProgram) { ASSERT(prog->RefCount == 1); /* should only be referenced by hash table */ prog->RefCount = 0; /* now going away */ @@ -184,7 +186,7 @@ static void delete_fragshader_cb(GLuint id, void *data, void *userData) { struct ati_fragment_shader *shader = (struct ati_fragment_shader *) data; - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; _mesa_delete_ati_fragment_shader(ctx, shader); } #endif @@ -197,12 +199,12 @@ static void delete_bufferobj_cb(GLuint id, void *data, void *userData) { struct gl_buffer_object *bufObj = (struct gl_buffer_object *) data; - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; if (_mesa_bufferobj_mapped(bufObj)) { - ctx->Driver.UnmapBuffer(ctx, 0, bufObj); + ctx->Driver.UnmapBuffer(ctx, bufObj); bufObj->Pointer = NULL; } - ctx->Driver.DeleteBuffer(ctx, bufObj); + _mesa_reference_buffer_object(ctx, &bufObj, NULL); } @@ -213,7 +215,7 @@ delete_bufferobj_cb(GLuint id, void *data, void *userData) static void free_shader_program_data_cb(GLuint id, void *data, void *userData) { - GLcontext *ctx = (GLcontext *) userData; + struct gl_context *ctx = (struct gl_context *) userData; struct gl_shader_program *shProg = (struct gl_shader_program *) data; if (shProg->Type == GL_SHADER_PROGRAM_MESA) { @@ -229,15 +231,15 @@ free_shader_program_data_cb(GLuint id, void *data, void *userData) static void delete_shader_cb(GLuint id, void *data, void *userData) { - GLcontext *ctx = (GLcontext *) 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) { - _mesa_free_shader(ctx, sh); + ctx->Driver.DeleteShader(ctx, sh); } else { struct gl_shader_program *shProg = (struct gl_shader_program *) data; ASSERT(shProg->Type == GL_SHADER_PROGRAM_MESA); - _mesa_free_shader_program(ctx, shProg); + ctx->Driver.DeleteShaderProgram(ctx, shProg); } } @@ -276,6 +278,20 @@ delete_renderbuffer_cb(GLuint id, void *data, void *userData) } +#if FEATURE_ARB_sampler_objects +/** + * Callback for deleting a sampler object. Called by _mesa_HashDeleteAll() + */ +static void +delete_sampler_object_cb(GLuint id, void *data, void *userData) +{ + struct gl_context *ctx = (struct gl_context *) userData; + struct gl_sampler_object *sampObj = (struct gl_sampler_object *) data; + _mesa_reference_sampler_object(ctx, &sampObj, NULL); +} +#endif + + /** * Deallocate a shared state object and all children structures. * @@ -288,11 +304,15 @@ delete_renderbuffer_cb(GLuint id, void *data, void *userData) * * \sa alloc_shared_state(). */ -void -_mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) +static void +free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared) { GLuint i; + /* Free the dummy/fallback texture object */ + if (shared->FallbackTex) + ctx->Driver.DeleteTexture(ctx, shared->FallbackTex); + /* * Free display lists */ @@ -335,10 +355,9 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) #endif #if FEATURE_ARB_vertex_buffer_object - ctx->Driver.DeleteBuffer(ctx, shared->NullBufferObj); + _mesa_reference_buffer_object(ctx, &shared->NullBufferObj, NULL); #endif -#if FEATURE_ARB_sync { struct simple_node *node; struct simple_node *temp; @@ -347,6 +366,10 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) _mesa_unref_sync_object(ctx, (struct gl_sync_object *) node); } } + +#if FEATURE_ARB_sampler_objects + _mesa_HashDeleteAll(shared->SamplerObjects, delete_sampler_object_cb, ctx); + _mesa_DeleteHashTable(shared->SamplerObjects); #endif /* @@ -366,5 +389,33 @@ _mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) _glthread_DESTROY_MUTEX(shared->Mutex); _glthread_DESTROY_MUTEX(shared->TexMutex); - _mesa_free(shared); + free(shared); +} + + +/** + * Decrement shared state object reference count and potentially free it + * and all children structures. + * + * \param ctx GL context. + * \param shared shared state pointer. + * + * \sa free_shared_state(). + */ +void +_mesa_release_shared_state(struct gl_context *ctx, + struct gl_shared_state *shared) +{ + GLint RefCount; + + _glthread_LOCK_MUTEX(shared->Mutex); + RefCount = --shared->RefCount; + _glthread_UNLOCK_MUTEX(shared->Mutex); + + assert(RefCount >= 0); + + if (RefCount == 0) { + /* free shared state */ + free_shared_state( ctx, shared ); + } }