X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fshaderobj.c;h=de66851e9c9549f0d4281b62d41db573e0679d87;hb=8fe6755ed52acfb88a7a787c3406b64fcdd80e6e;hp=863d50fbe559f1e20d00961feea966c723dea5db;hpb=443a7e4e9a360acbc3e662c098be436f180bf81d;p=mesa.git diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c index 863d50fbe55..de66851e9c9 100644 --- a/src/mesa/main/shaderobj.c +++ b/src/mesa/main/shaderobj.c @@ -32,11 +32,13 @@ #include "main/glheader.h" #include "main/context.h" #include "main/hash.h" +#include "main/mfeatures.h" +#include "main/mtypes.h" #include "main/shaderobj.h" #include "program/program.h" #include "program/prog_parameter.h" -#include "program/prog_uniform.h" -#include "talloc.h" +#include "program/hash_table.h" +#include "ralloc.h" /**********************************************************************/ /*** Shader object functions ***/ @@ -50,7 +52,7 @@ * Then set ptr to point to sh, incrementing its refcount. */ void -_mesa_reference_shader(GLcontext *ctx, struct gl_shader **ptr, +_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr, struct gl_shader *sh) { assert(ptr); @@ -70,7 +72,8 @@ _mesa_reference_shader(GLcontext *ctx, struct gl_shader **ptr, deleteFlag = (old->RefCount == 0); if (deleteFlag) { - _mesa_HashRemove(ctx->Shared->ShaderObjects, old->Name); + if (old->Name != 0) + _mesa_HashRemove(ctx->Shared->ShaderObjects, old->Name); ctx->Driver.DeleteShader(ctx, old); } @@ -87,22 +90,27 @@ _mesa_reference_shader(GLcontext *ctx, struct gl_shader **ptr, } } +void +_mesa_init_shader(struct gl_context *ctx, struct gl_shader *shader) +{ + shader->RefCount = 1; +} /** * Allocate a new gl_shader object, initialize it. * Called via ctx->Driver.NewShader() */ struct gl_shader * -_mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type) +_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type) { struct gl_shader *shader; assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER || type == GL_GEOMETRY_SHADER_ARB); - shader = talloc_zero(NULL, struct gl_shader); + shader = rzalloc(NULL, struct gl_shader); if (shader) { shader->Type = type; shader->Name = name; - shader->RefCount = 1; + _mesa_init_shader(ctx, shader); } return shader; } @@ -113,12 +121,12 @@ _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type) * Called via ctx->Driver.DeleteShader(). */ static void -__mesa_delete_shader(GLcontext *ctx, struct gl_shader *sh) +_mesa_delete_shader(struct gl_context *ctx, struct gl_shader *sh) { if (sh->Source) free((void *) sh->Source); _mesa_reference_program(ctx, &sh->Program, NULL); - talloc_free(sh); + ralloc_free(sh); } @@ -126,7 +134,7 @@ __mesa_delete_shader(GLcontext *ctx, struct gl_shader *sh) * Lookup a GLSL shader object. */ struct gl_shader * -_mesa_lookup_shader(GLcontext *ctx, GLuint name) +_mesa_lookup_shader(struct gl_context *ctx, GLuint name) { if (name) { struct gl_shader *sh = (struct gl_shader *) @@ -148,21 +156,21 @@ _mesa_lookup_shader(GLcontext *ctx, GLuint name) * As above, but record an error if shader is not found. */ struct gl_shader * -_mesa_lookup_shader_err(GLcontext *ctx, GLuint name, const char *caller) +_mesa_lookup_shader_err(struct gl_context *ctx, GLuint name, const char *caller) { if (!name) { - _mesa_error(ctx, GL_INVALID_VALUE, caller); + _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller); return NULL; } else { struct gl_shader *sh = (struct gl_shader *) _mesa_HashLookup(ctx->Shared->ShaderObjects, name); if (!sh) { - _mesa_error(ctx, GL_INVALID_VALUE, caller); + _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller); return NULL; } if (sh->Type == GL_SHADER_PROGRAM_MESA) { - _mesa_error(ctx, GL_INVALID_OPERATION, caller); + _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller); return NULL; } return sh; @@ -183,7 +191,7 @@ _mesa_lookup_shader_err(GLcontext *ctx, GLuint name, const char *caller) * Then set ptr to point to shProg, incrementing its refcount. */ void -_mesa_reference_shader_program(GLcontext *ctx, +_mesa_reference_shader_program(struct gl_context *ctx, struct gl_shader_program **ptr, struct gl_shader_program *shProg) { @@ -206,7 +214,8 @@ _mesa_reference_shader_program(GLcontext *ctx, deleteFlag = (old->RefCount == 0); if (deleteFlag) { - _mesa_HashRemove(ctx->Shared->ShaderObjects, old->Name); + if (old->Name != 0) + _mesa_HashRemove(ctx->Shared->ShaderObjects, old->Name); ctx->Driver.DeleteShaderProgram(ctx, old); } @@ -224,26 +233,36 @@ _mesa_reference_shader_program(GLcontext *ctx, } } +void +_mesa_init_shader_program(struct gl_context *ctx, struct gl_shader_program *prog) +{ + prog->Type = GL_SHADER_PROGRAM_MESA; + prog->RefCount = 1; + + prog->AttributeBindings = string_to_uint_map_ctor(); + prog->FragDataBindings = string_to_uint_map_ctor(); + +#if FEATURE_ARB_geometry_shader4 + prog->Geom.VerticesOut = 0; + prog->Geom.InputType = GL_TRIANGLES; + prog->Geom.OutputType = GL_TRIANGLE_STRIP; +#endif + + prog->InfoLog = ralloc_strdup(prog, ""); +} /** * Allocate a new gl_shader_program object, initialize it. * Called via ctx->Driver.NewShaderProgram() */ static struct gl_shader_program * -_mesa_new_shader_program(GLcontext *ctx, GLuint name) +_mesa_new_shader_program(struct gl_context *ctx, GLuint name) { struct gl_shader_program *shProg; - shProg = talloc_zero(NULL, struct gl_shader_program); + shProg = rzalloc(NULL, struct gl_shader_program); if (shProg) { - shProg->Type = GL_SHADER_PROGRAM_MESA; shProg->Name = name; - shProg->RefCount = 1; - shProg->Attributes = _mesa_new_parameter_list(); -#if FEATURE_ARB_geometry_shader4 - shProg->Geom.VerticesOut = 0; - shProg->Geom.InputType = GL_TRIANGLES; - shProg->Geom.OutputType = GL_TRIANGLE_STRIP; -#endif + _mesa_init_shader_program(ctx, shProg); } return shProg; } @@ -253,22 +272,23 @@ _mesa_new_shader_program(GLcontext *ctx, GLuint name) * Clear (free) the shader program state that gets produced by linking. */ void -_mesa_clear_shader_program_data(GLcontext *ctx, +_mesa_clear_shader_program_data(struct gl_context *ctx, struct gl_shader_program *shProg) { - _mesa_reference_vertprog(ctx, &shProg->VertexProgram, NULL); - _mesa_reference_fragprog(ctx, &shProg->FragmentProgram, NULL); - _mesa_reference_geomprog(ctx, &shProg->GeometryProgram, NULL); - - if (shProg->Uniforms) { - _mesa_free_uniform_list(shProg->Uniforms); - shProg->Uniforms = NULL; + if (shProg->UniformStorage) { + ralloc_free(shProg->UniformStorage); + shProg->NumUserUniformStorage = 0; + shProg->UniformStorage = NULL; } - if (shProg->Varying) { - _mesa_free_parameter_list(shProg->Varying); - shProg->Varying = NULL; + if (shProg->UniformHash) { + string_to_uint_map_dtor(shProg->UniformHash); + shProg->UniformHash = NULL; } + + assert(shProg->InfoLog != NULL); + ralloc_free(shProg->InfoLog); + shProg->InfoLog = ralloc_strdup(shProg, ""); } @@ -277,18 +297,24 @@ _mesa_clear_shader_program_data(GLcontext *ctx, * object itself. */ void -_mesa_free_shader_program_data(GLcontext *ctx, +_mesa_free_shader_program_data(struct gl_context *ctx, struct gl_shader_program *shProg) { GLuint i; + gl_shader_type sh; assert(shProg->Type == GL_SHADER_PROGRAM_MESA); _mesa_clear_shader_program_data(ctx, shProg); - if (shProg->Attributes) { - _mesa_free_parameter_list(shProg->Attributes); - shProg->Attributes = NULL; + if (shProg->AttributeBindings) { + string_to_uint_map_dtor(shProg->AttributeBindings); + shProg->AttributeBindings = NULL; + } + + if (shProg->FragDataBindings) { + string_to_uint_map_dtor(shProg->FragDataBindings); + shProg->FragDataBindings = NULL; } /* detach shaders */ @@ -302,11 +328,6 @@ _mesa_free_shader_program_data(GLcontext *ctx, shProg->Shaders = NULL; } - if (shProg->InfoLog) { - talloc_free(shProg->InfoLog); - shProg->InfoLog = NULL; - } - /* Transform feedback varying vars */ for (i = 0; i < shProg->TransformFeedback.NumVarying; i++) { free(shProg->TransformFeedback.VaryingNames[i]); @@ -314,6 +335,14 @@ _mesa_free_shader_program_data(GLcontext *ctx, free(shProg->TransformFeedback.VaryingNames); shProg->TransformFeedback.VaryingNames = NULL; shProg->TransformFeedback.NumVarying = 0; + + + for (sh = 0; sh < MESA_SHADER_TYPES; sh++) { + if (shProg->_LinkedShaders[sh] != NULL) { + ctx->Driver.DeleteShader(ctx, shProg->_LinkedShaders[sh]); + shProg->_LinkedShaders[sh] = NULL; + } + } } @@ -322,11 +351,11 @@ _mesa_free_shader_program_data(GLcontext *ctx, * Called via ctx->Driver.DeleteShaderProgram(). */ static void -__mesa_delete_shader_program(GLcontext *ctx, struct gl_shader_program *shProg) +_mesa_delete_shader_program(struct gl_context *ctx, struct gl_shader_program *shProg) { _mesa_free_shader_program_data(ctx, shProg); - talloc_free(shProg); + ralloc_free(shProg); } @@ -334,7 +363,7 @@ __mesa_delete_shader_program(GLcontext *ctx, struct gl_shader_program *shProg) * Lookup a GLSL program object. */ struct gl_shader_program * -_mesa_lookup_shader_program(GLcontext *ctx, GLuint name) +_mesa_lookup_shader_program(struct gl_context *ctx, GLuint name) { struct gl_shader_program *shProg; if (name) { @@ -357,22 +386,22 @@ _mesa_lookup_shader_program(GLcontext *ctx, GLuint name) * As above, but record an error if program is not found. */ struct gl_shader_program * -_mesa_lookup_shader_program_err(GLcontext *ctx, GLuint name, +_mesa_lookup_shader_program_err(struct gl_context *ctx, GLuint name, const char *caller) { if (!name) { - _mesa_error(ctx, GL_INVALID_VALUE, caller); + _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller); return NULL; } else { struct gl_shader_program *shProg = (struct gl_shader_program *) _mesa_HashLookup(ctx->Shared->ShaderObjects, name); if (!shProg) { - _mesa_error(ctx, GL_INVALID_VALUE, caller); + _mesa_error(ctx, GL_INVALID_VALUE, "%s", caller); return NULL; } if (shProg->Type != GL_SHADER_PROGRAM_MESA) { - _mesa_error(ctx, GL_INVALID_OPERATION, caller); + _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller); return NULL; } return shProg; @@ -384,9 +413,8 @@ void _mesa_init_shader_object_functions(struct dd_function_table *driver) { driver->NewShader = _mesa_new_shader; - driver->DeleteShader = __mesa_delete_shader; + driver->DeleteShader = _mesa_delete_shader; driver->NewShaderProgram = _mesa_new_shader_program; - driver->DeleteShaderProgram = __mesa_delete_shader_program; - driver->CompileShader = _mesa_ir_compile_shader; + driver->DeleteShaderProgram = _mesa_delete_shader_program; driver->LinkShader = _mesa_ir_link_shader; }