diff options
Diffstat (limited to 'src/mesa/shader')
-rw-r--r-- | src/mesa/shader/atifragshader.c | 108 | ||||
-rw-r--r-- | src/mesa/shader/atifragshader.h | 9 | ||||
-rw-r--r-- | src/mesa/shader/program.c | 41 | ||||
-rw-r--r-- | src/mesa/shader/program.h | 5 |
4 files changed, 84 insertions, 79 deletions
diff --git a/src/mesa/shader/atifragshader.c b/src/mesa/shader/atifragshader.c index e16c029aa55..d349a496dc7 100644 --- a/src/mesa/shader/atifragshader.c +++ b/src/mesa/shader/atifragshader.c @@ -32,7 +32,42 @@ #define MESA_DEBUG_ATI_FS 0 -extern struct program _mesa_DummyProgram; +static struct ati_fragment_shader DummyShader; + + +/** + * Allocate and initialize a new ATI fragment shader object. + */ +struct ati_fragment_shader * +_mesa_new_ati_fragment_shader(GLcontext *ctx, GLuint id) +{ + struct ati_fragment_shader *s = CALLOC_STRUCT(ati_fragment_shader); + (void) ctx; + if (s) { + s->Id = id; + s->RefCount = 1; + } + return s; +} + + +/** + * Delete the given ati fragment shader + */ +void +_mesa_delete_ati_fragment_shader(GLcontext *ctx, struct ati_fragment_shader *s) +{ + GLuint i; + for (i = 0; i < MAX_NUM_PASSES_ATI; i++) { + if (s->Instructions[i]) + _mesa_free(s->Instructions[i]); + if (s->SetupInst[i]) + _mesa_free(s->SetupInst[i]); + } + _mesa_free(s); +} + + static void new_arith_inst(struct ati_fragment_shader *prog) @@ -165,9 +200,9 @@ _mesa_GenFragmentShadersATI(GLuint range) return 0; } - first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, range); + first = _mesa_HashFindFreeKeyBlock(ctx->Shared->ATIShaders, range); for (i = 0; i < range; i++) { - _mesa_HashInsert(ctx->Shared->Programs, first + i, &_mesa_DummyProgram); + _mesa_HashInsert(ctx->Shared->ATIShaders, first + i, &DummyShader); } return first; @@ -176,9 +211,9 @@ _mesa_GenFragmentShadersATI(GLuint range) void GLAPIENTRY _mesa_BindFragmentShaderATI(GLuint id) { - struct program *prog; GET_CURRENT_CONTEXT(ctx); struct ati_fragment_shader *curProg = ctx->ATIFragmentShader.Current; + struct ati_fragment_shader *newProg; if (ctx->ATIFragmentShader.Compiling) { _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFragmentShaderATI(insideShader)"); @@ -187,41 +222,43 @@ _mesa_BindFragmentShaderATI(GLuint id) FLUSH_VERTICES(ctx, _NEW_PROGRAM); - if (curProg->Base.Id == id) { + if (curProg->Id == id) { return; } - if (curProg->Base.Id != 0) { - curProg->Base.RefCount--; - if (curProg->Base.RefCount <= 0) { - _mesa_HashRemove(ctx->Shared->Programs, id); + /* unbind current */ + if (curProg->Id != 0) { + curProg->RefCount--; + if (curProg->RefCount <= 0) { + _mesa_HashRemove(ctx->Shared->ATIShaders, id); } } - /* Go bind */ + /* find new shader */ if (id == 0) { - prog = ctx->Shared->DefaultFragmentShader; + newProg = ctx->Shared->DefaultFragmentShader; } else { - prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id); - if (!prog || prog == &_mesa_DummyProgram) { + newProg = (struct ati_fragment_shader *) + _mesa_HashLookup(ctx->Shared->ATIShaders, id); + if (!newProg || newProg == &DummyShader) { /* allocate a new program now */ - prog = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_SHADER_ATI, id); - if (!prog) { + newProg = _mesa_new_ati_fragment_shader(ctx, id); + if (!newProg) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindFragmentShaderATI"); return; } - _mesa_HashInsert(ctx->Shared->Programs, id, prog); + _mesa_HashInsert(ctx->Shared->ATIShaders, id, newProg); } } /* do actual bind */ - ctx->ATIFragmentShader.Current = (struct ati_fragment_shader *) prog; + ctx->ATIFragmentShader.Current = newProg; ASSERT(ctx->ATIFragmentShader.Current); - if (prog) - prog->RefCount++; + if (newProg) + newProg->RefCount++; /*if (ctx->Driver.BindProgram) ctx->Driver.BindProgram(ctx, target, prog); */ @@ -238,38 +275,29 @@ _mesa_DeleteFragmentShaderATI(GLuint id) } if (id != 0) { - struct program *prog = (struct program *) - _mesa_HashLookup(ctx->Shared->Programs, id); - if (prog == &_mesa_DummyProgram) { - _mesa_HashRemove(ctx->Shared->Programs, id); + struct ati_fragment_shader *prog = (struct ati_fragment_shader *) + _mesa_HashLookup(ctx->Shared->ATIShaders, id); + if (prog == &DummyShader) { + _mesa_HashRemove(ctx->Shared->ATIShaders, id); } else if (prog) { if (ctx->ATIFragmentShader.Current && - ctx->ATIFragmentShader.Current->Base.Id == id) { + ctx->ATIFragmentShader.Current->Id == id) { FLUSH_VERTICES(ctx, _NEW_PROGRAM); _mesa_BindFragmentShaderATI(0); } } -#if 0 - if (!prog->DeletePending) { - prog->DeletePending = GL_TRUE; - prog->RefCount--; - } - if (prog->RefCount <= 0) { - _mesa_HashRemove(ctx->Shared->Programs, id); - ctx->Driver.DeleteProgram(ctx, prog); - } -#else + /* The ID is immediately available for re-use now */ - _mesa_HashRemove(ctx->Shared->Programs, id); + _mesa_HashRemove(ctx->Shared->ATIShaders, id); prog->RefCount--; if (prog->RefCount <= 0) { - ctx->Driver.DeleteProgram(ctx, prog); + _mesa_free(prog); } -#endif } } + void GLAPIENTRY _mesa_BeginFragmentShaderATI(void) { @@ -307,7 +335,7 @@ _mesa_BeginFragmentShaderATI(void) } /* can't rely on calloc for initialization as it's possible to redefine a shader (?) */ - ctx->ATIFragmentShader.Current->localConstDef = 0; + ctx->ATIFragmentShader.Current->LocalConstDef = 0; ctx->ATIFragmentShader.Current->numArithInstr[0] = 0; ctx->ATIFragmentShader.Current->numArithInstr[1] = 0; ctx->ATIFragmentShader.Current->regsAssigned[0] = 0; @@ -720,10 +748,10 @@ _mesa_SetFragmentShaderConstantATI(GLuint dst, const GLfloat * value) if (ctx->ATIFragmentShader.Compiling) { struct ati_fragment_shader *curProg = ctx->ATIFragmentShader.Current; COPY_4V(curProg->Constants[dstindex], value); - curProg->localConstDef |= 1 << dstindex; + curProg->LocalConstDef |= 1 << dstindex; } else { FLUSH_VERTICES(ctx, _NEW_PROGRAM); - COPY_4V(ctx->ATIFragmentShader.globalConstants[dstindex], value); + COPY_4V(ctx->ATIFragmentShader.GlobalConstants[dstindex], value); } } diff --git a/src/mesa/shader/atifragshader.h b/src/mesa/shader/atifragshader.h index 9621502ca66..32fb3a80190 100644 --- a/src/mesa/shader/atifragshader.h +++ b/src/mesa/shader/atifragshader.h @@ -57,6 +57,15 @@ struct atifs_setupinst GLenum swizzle; }; + +extern struct ati_fragment_shader * +_mesa_new_ati_fragment_shader(GLcontext *ctx, GLuint id); + +extern void +_mesa_delete_ati_fragment_shader(GLcontext *ctx, + struct ati_fragment_shader *s); + + extern GLuint GLAPIENTRY _mesa_GenFragmentShadersATI(GLuint range); extern void GLAPIENTRY _mesa_BindFragmentShaderATI(GLuint id); diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 6e0805c3cb2..28b982b6ea7 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -88,11 +88,12 @@ _mesa_init_program(GLcontext *ctx) ctx->FragmentProgram.Current->Base.RefCount++; #endif + /* XXX probably move this stuff */ #if FEATURE_ATI_fragment_shader ctx->ATIFragmentShader.Enabled = GL_FALSE; ctx->ATIFragmentShader.Current = (struct ati_fragment_shader *) ctx->Shared->DefaultFragmentShader; assert(ctx->ATIFragmentShader.Current); - ctx->ATIFragmentShader.Current->Base.RefCount++; + ctx->ATIFragmentShader.Current->RefCount++; #endif } @@ -117,11 +118,13 @@ _mesa_free_program_data(GLcontext *ctx) ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base)); } #endif + /* XXX probably move this stuff */ #if FEATURE_ATI_fragment_shader if (ctx->ATIFragmentShader.Current) { - ctx->ATIFragmentShader.Current->Base.RefCount--; - if (ctx->ATIFragmentShader.Current->Base.RefCount <= 0) - ctx->Driver.DeleteProgram(ctx, &(ctx->ATIFragmentShader.Current->Base)); + ctx->ATIFragmentShader.Current->RefCount--; + if (ctx->ATIFragmentShader.Current->RefCount <= 0) { + _mesa_free(ctx->ATIFragmentShader.Current); + } } #endif _mesa_free((void *) ctx->Program.ErrorString); @@ -234,21 +237,6 @@ _mesa_init_vertex_program( GLcontext *ctx, struct vertex_program *prog, return NULL; } -/** - * Initialize a new ATI fragment shader object. - */ -struct program * -_mesa_init_ati_fragment_shader( GLcontext *ctx, - struct ati_fragment_shader *prog, - GLenum target, GLuint id ) -{ - if (prog) - return _mesa_init_program_struct( ctx, &prog->Base, target, id ); - else - return NULL; -} - - /** * Allocate and initialize a new fragment/vertex program object but @@ -273,10 +261,6 @@ _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id) case GL_FRAGMENT_PROGRAM_ARB: return _mesa_init_fragment_program( ctx, CALLOC_STRUCT(fragment_program), target, id ); - case GL_FRAGMENT_SHADER_ATI: - return _mesa_init_ati_fragment_shader( ctx, CALLOC_STRUCT(ati_fragment_shader), - target, id ); - default: _mesa_problem(ctx, "bad target in _mesa_new_program"); return NULL; @@ -311,17 +295,6 @@ _mesa_delete_program(GLcontext *ctx, struct program *prog) if (prog->Parameters) _mesa_free_parameter_list(prog->Parameters); - if (prog->Target == GL_FRAGMENT_SHADER_ATI) { - struct ati_fragment_shader *atifs = (struct ati_fragment_shader *)prog; - GLuint i; - for (i = 0; i < MAX_NUM_PASSES_ATI; i++) { - if (atifs->Instructions[i]) - _mesa_free(atifs->Instructions[i]); - if (atifs->SetupInst[i]) - _mesa_free(atifs->SetupInst[i]); - } - } - _mesa_free(prog); } diff --git a/src/mesa/shader/program.h b/src/mesa/shader/program.h index ab72f457eeb..a1ee3349dce 100644 --- a/src/mesa/shader/program.h +++ b/src/mesa/shader/program.h @@ -106,11 +106,6 @@ _mesa_init_fragment_program(GLcontext *ctx, GLenum target, GLuint id); extern struct program * -_mesa_init_ati_fragment_shader(GLcontext *ctx, - struct ati_fragment_shader *prog, - GLenum target, GLuint id ); - -extern struct program * _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id); extern void |