From 4045a2c7d302352646c1ff2a01cd531aa1b55d31 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 7 Mar 2009 13:14:37 -0700 Subject: mesa: move shared context state functions to new shared.c file --- src/mesa/main/shared.c | 356 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 356 insertions(+) create mode 100644 src/mesa/main/shared.c (limited to 'src/mesa/main/shared.c') diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c new file mode 100644 index 0000000000..936ee9061b --- /dev/null +++ b/src/mesa/main/shared.c @@ -0,0 +1,356 @@ +/* + * Mesa 3-D graphics library + * Version: 7.5 + * + * Copyright (C) 2009 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * 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. + */ + +/** + * \file shared.c + * Shared-context state + */ + + + +#include "imports.h" +#include "mtypes.h" +#include "hash.h" +#include "arrayobj.h" +#include "shared.h" +#include "shader/program.h" +#include "shader/shader_api.h" +#if FEATURE_dlist +#include "dlist.h" +#endif +#if FEATURE_ATI_fragment_shader +#include "shader/atifragshader.h" +#endif + + +/** + * Allocate and initialize a shared context state structure. + * Initializes the display list, texture objects and vertex programs hash + * tables, allocates the texture objects. If it runs out of memory, frees + * everything already allocated before returning NULL. + * + * \return pointer to a gl_shared_state structure on success, or NULL on + * failure. + */ +struct gl_shared_state * +_mesa_alloc_shared_state(GLcontext *ctx) +{ + struct gl_shared_state *shared; + GLuint i; + + shared = CALLOC_STRUCT(gl_shared_state); + if (!shared) + return NULL; + + _glthread_INIT_MUTEX(shared->Mutex); + + shared->DisplayList = _mesa_NewHashTable(); + shared->TexObjects = _mesa_NewHashTable(); + shared->Programs = _mesa_NewHashTable(); + +#if FEATURE_ARB_vertex_program + shared->DefaultVertexProgram = (struct gl_vertex_program *) + ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0); +#endif + +#if FEATURE_ARB_fragment_program + shared->DefaultFragmentProgram = (struct gl_fragment_program *) + ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); +#endif + +#if FEATURE_ATI_fragment_shader + shared->ATIShaders = _mesa_NewHashTable(); + shared->DefaultFragmentShader = _mesa_new_ati_fragment_shader(ctx, 0); +#endif + +#if FEATURE_ARB_shader_objects + shared->ShaderObjects = _mesa_NewHashTable(); +#endif + +#if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object + shared->BufferObjects = _mesa_NewHashTable(); +#endif + + shared->ArrayObjects = _mesa_NewHashTable(); + + /* 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_2D_ARRAY_EXT, + GL_TEXTURE_1D_ARRAY_EXT, + GL_TEXTURE_CUBE_MAP, + GL_TEXTURE_3D, + GL_TEXTURE_RECTANGLE_NV, + GL_TEXTURE_2D, + GL_TEXTURE_1D + }; + shared->DefaultTex[i] = ctx->Driver.NewTextureObject(ctx, 0, targets[i]); + } + + /* sanity check */ + assert(shared->DefaultTex[TEXTURE_1D_INDEX]->RefCount == 1); + + /* Mutex and timestamp for texobj state validation */ + _glthread_INIT_MUTEX(shared->TexMutex); + shared->TextureStateStamp = 0; + +#if FEATURE_EXT_framebuffer_object + shared->FrameBuffers = _mesa_NewHashTable(); + shared->RenderBuffers = _mesa_NewHashTable(); +#endif + + return shared; +} + + +/** + * Callback for deleting a display list. Called by _mesa_HashDeleteAll(). + */ +static void +delete_displaylist_cb(GLuint id, void *data, void *userData) +{ +#if FEATURE_dlist + struct gl_display_list *list = (struct gl_display_list *) data; + GLcontext *ctx = (GLcontext *) userData; + _mesa_delete_list(ctx, list); +#endif +} + + +/** + * Callback for deleting a texture object. Called by _mesa_HashDeleteAll(). + */ +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; + ctx->Driver.DeleteTexture(ctx, texObj); +} + + +/** + * Callback for deleting a program object. Called by _mesa_HashDeleteAll(). + */ +static void +delete_program_cb(GLuint id, void *data, void *userData) +{ + struct gl_program *prog = (struct gl_program *) data; + GLcontext *ctx = (GLcontext *) userData; + ASSERT(prog->RefCount == 1); /* should only be referenced by hash table */ + prog->RefCount = 0; /* now going away */ + ctx->Driver.DeleteProgram(ctx, prog); +} + + +#if FEATURE_ATI_fragment_shader +/** + * Callback for deleting an ATI fragment shader object. + * Called by _mesa_HashDeleteAll(). + */ +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; + _mesa_delete_ati_fragment_shader(ctx, shader); +} +#endif + + +/** + * Callback for deleting a buffer object. Called by _mesa_HashDeleteAll(). + */ +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; + ctx->Driver.DeleteBuffer(ctx, bufObj); +} + + +/** + * Callback for deleting an array object. Called by _mesa_HashDeleteAll(). + */ +static void +delete_arrayobj_cb(GLuint id, void *data, void *userData) +{ + struct gl_array_object *arrayObj = (struct gl_array_object *) data; + GLcontext *ctx = (GLcontext *) userData; + _mesa_delete_array_object(ctx, arrayObj); +} + + +/** + * Callback for freeing shader program data. Call it before delete_shader_cb + * to avoid memory access error. + */ +static void +free_shader_program_data_cb(GLuint id, void *data, void *userData) +{ + GLcontext *ctx = (GLcontext *) userData; + struct gl_shader_program *shProg = (struct gl_shader_program *) data; + + if (shProg->Type == GL_SHADER_PROGRAM_MESA) { + _mesa_free_shader_program_data(ctx, shProg); + } +} + + +/** + * Callback for deleting shader and shader programs objects. + * Called by _mesa_HashDeleteAll(). + */ +static void +delete_shader_cb(GLuint id, void *data, void *userData) +{ + GLcontext *ctx = (GLcontext *) 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); + } + else { + struct gl_shader_program *shProg = (struct gl_shader_program *) data; + ASSERT(shProg->Type == GL_SHADER_PROGRAM_MESA); + _mesa_free_shader_program(ctx, shProg); + } +} + + +/** + * Callback for deleting a framebuffer object. Called by _mesa_HashDeleteAll() + */ +static void +delete_framebuffer_cb(GLuint id, void *data, void *userData) +{ + struct gl_framebuffer *fb = (struct gl_framebuffer *) data; + /* The fact that the framebuffer is in the hashtable means its refcount + * is one, but we're removing from the hashtable now. So clear refcount. + */ + /*assert(fb->RefCount == 1);*/ + fb->RefCount = 0; + + /* NOTE: Delete should always be defined but there are two reports + * of it being NULL (bugs 13507, 14293). Work-around for now. + */ + if (fb->Delete) + fb->Delete(fb); +} + + +/** + * Callback for deleting a renderbuffer object. Called by _mesa_HashDeleteAll() + */ +static void +delete_renderbuffer_cb(GLuint id, void *data, void *userData) +{ + struct gl_renderbuffer *rb = (struct gl_renderbuffer *) data; + rb->RefCount = 0; /* see comment for FBOs above */ + if (rb->Delete) + rb->Delete(rb); +} + + +/** + * Deallocate a shared state object and all children structures. + * + * \param ctx GL context. + * \param ss 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. + * + * \sa alloc_shared_state(). + */ +void +_mesa_free_shared_state(GLcontext *ctx, struct gl_shared_state *shared) +{ + GLuint i; + + /* + * Free display lists + */ + _mesa_HashDeleteAll(shared->DisplayList, delete_displaylist_cb, ctx); + _mesa_DeleteHashTable(shared->DisplayList); + +#if FEATURE_ARB_shader_objects + _mesa_HashWalk(shared->ShaderObjects, free_shader_program_data_cb, ctx); + _mesa_HashDeleteAll(shared->ShaderObjects, delete_shader_cb, ctx); + _mesa_DeleteHashTable(shared->ShaderObjects); +#endif + + _mesa_HashDeleteAll(shared->Programs, delete_program_cb, ctx); + _mesa_DeleteHashTable(shared->Programs); + + _mesa_HashDeleteAll(shared->ArrayObjects, delete_arrayobj_cb, ctx); + _mesa_DeleteHashTable(shared->ArrayObjects); + +#if FEATURE_ARB_vertex_program + _mesa_reference_vertprog(ctx, &shared->DefaultVertexProgram, NULL); +#endif + +#if FEATURE_ARB_fragment_program + _mesa_reference_fragprog(ctx, &shared->DefaultFragmentProgram, NULL); +#endif + +#if FEATURE_ATI_fragment_shader + _mesa_HashDeleteAll(shared->ATIShaders, delete_fragshader_cb, ctx); + _mesa_DeleteHashTable(shared->ATIShaders); + _mesa_delete_ati_fragment_shader(ctx, shared->DefaultFragmentShader); +#endif + +#if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object + _mesa_HashDeleteAll(shared->BufferObjects, delete_bufferobj_cb, ctx); + _mesa_DeleteHashTable(shared->BufferObjects); +#endif + +#if FEATURE_EXT_framebuffer_object + _mesa_HashDeleteAll(shared->FrameBuffers, delete_framebuffer_cb, ctx); + _mesa_DeleteHashTable(shared->FrameBuffers); + _mesa_HashDeleteAll(shared->RenderBuffers, delete_renderbuffer_cb, ctx); + _mesa_DeleteHashTable(shared->RenderBuffers); +#endif + + /* + * Free texture objects (after FBOs since some textures might have + * been bound to FBOs). + */ + ASSERT(ctx->Driver.DeleteTexture); + /* the default textures */ + for (i = 0; i < NUM_TEXTURE_TARGETS; i++) { + ctx->Driver.DeleteTexture(ctx, shared->DefaultTex[i]); + } + + /* all other textures */ + _mesa_HashDeleteAll(shared->TexObjects, delete_texture_cb, ctx); + _mesa_DeleteHashTable(shared->TexObjects); + + _glthread_DESTROY_MUTEX(shared->Mutex); + _glthread_DESTROY_MUTEX(shared->TexMutex); + + _mesa_free(shared); +} -- cgit v1.2.3 From 1eee1bac1f6d911e6124daafc9b9291666d91cef Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Tue, 17 Mar 2009 09:34:30 -0600 Subject: mesa: update/fix doxygen comments --- src/mesa/glapi/glapi_getproc.c | 2 +- src/mesa/main/context.c | 4 ++-- src/mesa/main/dlist.c | 2 +- src/mesa/main/execmem.c | 2 +- src/mesa/main/feedback.c | 4 ++-- src/mesa/main/imports.c | 2 +- src/mesa/main/mipmap.c | 2 +- src/mesa/main/shared.c | 2 +- src/mesa/main/teximage.c | 7 +++---- src/mesa/main/texobj.c | 2 +- src/mesa/shader/prog_parameter.c | 2 +- src/mesa/shader/prog_print.c | 2 +- 12 files changed, 16 insertions(+), 17 deletions(-) (limited to 'src/mesa/main/shared.c') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index 764e2ef98e..ed443c12c8 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -23,7 +23,7 @@ */ /** - * \file glapi_getproc. + * \file glapi_getproc.c * * Code for implementing glXGetProcAddress(), etc. * This was originally in glapi.c but refactored out. diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 84bf0205a8..b24a3b4409 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -179,7 +179,7 @@ GLfloat _mesa_ubyte_to_float_color_tab[256]; /** * Swap buffers notification callback. * - * \param gc GL context. + * \param ctx GL context. * * Called by window system just before swapping buffers. * We have to finish any pending rendering. @@ -923,7 +923,7 @@ _mesa_initialize_context(GLcontext *ctx, * \param share_list another context to share display lists with or NULL * \param driverFunctions points to the dd_function_table into which the * driver has plugged in all its special functions. - * \param driverCtx points to the device driver's private context state + * \param driverContext points to the device driver's private context state * * \return pointer to a new __GLcontextRec or NULL if error. */ diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index ebcef0268a..8f7f703da9 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -707,7 +707,7 @@ unpack_image(GLuint dimensions, GLsizei width, GLsizei height, GLsizei depth, /** * Allocate space for a display list instruction. * \param opcode the instruction opcode (OPCODE_* value) - * \param size instruction size in bytes, not counting opcode. + * \param bytes instruction size in bytes, not counting opcode. * \return pointer to the usable data area (not including the internal * opcode). */ diff --git a/src/mesa/main/execmem.c b/src/mesa/main/execmem.c index b71846c904..57c1e117c8 100644 --- a/src/mesa/main/execmem.c +++ b/src/mesa/main/execmem.c @@ -24,7 +24,7 @@ /** - * \file exemem.c + * \file execmem.c * Functions for allocating executable memory. * * \author Keith Whitwell diff --git a/src/mesa/main/feedback.c b/src/mesa/main/feedback.c index beab535b15..818a804540 100644 --- a/src/mesa/main/feedback.c +++ b/src/mesa/main/feedback.c @@ -197,8 +197,8 @@ _mesa_SelectBuffer( GLsizei size, GLuint *buffer ) /** * Write a value of a record into the selection buffer. * - * \param CTX GL context. - * \param V value. + * \param ctx GL context. + * \param value value. * * Verifies there is free space in the buffer to write the value and * increments the pointer. diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index cb04594c1f..20b8342064 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -1011,7 +1011,7 @@ _mesa_warning( GLcontext *ctx, const char *fmtString, ... ) * Prints the message to stderr via fprintf(). * * \param ctx GL context. - * \param s problem description string. + * \param fmtString problem description string. */ void _mesa_problem( const GLcontext *ctx, const char *fmtString, ... ) diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c index af2bf8fe22..4a79430c34 100644 --- a/src/mesa/main/mipmap.c +++ b/src/mesa/main/mipmap.c @@ -1186,7 +1186,7 @@ make_1d_stack_mipmap(GLenum datatype, GLuint comps, GLint border, /** - * \bugs + * \bug * There is quite a bit of refactoring that could be done with this function * and \c make_2d_mipmap. */ diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c index 936ee9061b..fa45e466b7 100644 --- a/src/mesa/main/shared.c +++ b/src/mesa/main/shared.c @@ -278,7 +278,7 @@ delete_renderbuffer_cb(GLuint id, void *data, void *userData) * Deallocate a shared state object and all children structures. * * \param ctx GL context. - * \param ss shared state pointer. + * \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 diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index bf28986066..4f297738df 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -712,7 +712,7 @@ _mesa_new_texture_image( GLcontext *ctx ) * Free texture image data. * This function is a fallback called via ctx->Driver.FreeTexImageData(). * - * \param teximage texture image. + * \param texImage texture image. * * Free the texture image data if it's not marked as client data. */ @@ -734,7 +734,7 @@ _mesa_free_texture_image_data(GLcontext *ctx, /** * Free texture image. * - * \param teximage texture image. + * \param texImage texture image. * * Free the texture image structure and the associated image data. */ @@ -844,7 +844,7 @@ _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit, * of the given texture unit. * * \param ctx GL context. - * \param texUnit texture unit. + * \param texObj texture unit. * \param target texture target. * \param level image level. * @@ -1852,7 +1852,6 @@ subtexture_error_check2( GLcontext *ctx, GLuint dimensions, * \param internalFormat internal format given by the user. * \param width image width given by the user. * \param height image height given by the user. - * \param depth image depth given by the user. * \param border texture border. * * \return GL_TRUE if an error was detected, or GL_FALSE if no errors. diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c index 9ccb8fa100..b63f747fe8 100644 --- a/src/mesa/main/texobj.c +++ b/src/mesa/main/texobj.c @@ -180,7 +180,7 @@ finish_texture_init(GLcontext *ctx, GLenum target, * Called via ctx->Driver.DeleteTexture() if not overriden by a driver. * * \param shared the shared GL state to which the object belongs. - * \param texOjb the texture object to delete. + * \param texObj the texture object to delete. */ void _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj ) diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c index 60e9d07423..66edae9001 100644 --- a/src/mesa/shader/prog_parameter.c +++ b/src/mesa/shader/prog_parameter.c @@ -517,7 +517,7 @@ _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList, * swizzling to find a match. * \param list the parameter list to search * \param v the float vector to search for - * \param size number of element in v + * \param vSize number of element in v * \param posOut returns the position of the constant, if found * \param swizzleOut returns a swizzle mask describing location of the * vector elements if found. diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c index 3e006a4927..b832ddb477 100644 --- a/src/mesa/shader/prog_print.c +++ b/src/mesa/shader/prog_print.c @@ -213,7 +213,7 @@ arb_output_attrib_string(GLint index, GLenum progType) * Return string representation of the given register. * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined * by the ARB/NV program languages so we've taken some liberties here. - * \param file the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc) + * \param f the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc) * \param index number of the register in the register file * \param mode the output format/mode/style * \param prog pointer to containing program -- cgit v1.2.3