diff options
Diffstat (limited to 'src/mesa/shader/program.c')
-rw-r--r-- | src/mesa/shader/program.c | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 7048770cf74..a80e6e91541 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -112,7 +112,7 @@ _mesa_free_program_data(GLcontext *ctx) /** * Update the default program objects in the given context to reference those - * specified in the shared state and release those referencing the old + * specified in the shared state and release those referencing the old * shared state. */ void @@ -238,7 +238,7 @@ struct gl_program * _mesa_init_fragment_program( GLcontext *ctx, struct gl_fragment_program *prog, GLenum target, GLuint id) { - if (prog) + if (prog) return _mesa_init_program_struct( ctx, &prog->Base, target, id ); else return NULL; @@ -252,7 +252,7 @@ struct gl_program * _mesa_init_vertex_program( GLcontext *ctx, struct gl_vertex_program *prog, GLenum target, GLuint id) { - if (prog) + if (prog) return _mesa_init_program_struct( ctx, &prog->Base, target, id ); else return NULL; @@ -265,7 +265,7 @@ _mesa_init_vertex_program( GLcontext *ctx, struct gl_vertex_program *prog, * ctx->Driver.NewProgram. May be overridden (ie. replaced) by a * device driver function to implement OO deriviation with additional * types not understood by this function. - * + * * \param ctx context * \param id program id/number * \param target program target/type @@ -309,7 +309,7 @@ _mesa_delete_program(GLcontext *ctx, struct gl_program *prog) if (prog == &_mesa_DummyProgram) return; - + if (prog->String) _mesa_free(prog->String); @@ -382,7 +382,7 @@ _mesa_reference_program(GLcontext *ctx, deleteFlag = ((*ptr)->RefCount == 0); /*_glthread_UNLOCK_MUTEX((*ptr)->Mutex);*/ - + if (deleteFlag) { ASSERT(ctx); ctx->Driver.DeleteProgram(ctx, *ptr); @@ -437,6 +437,7 @@ _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog) clone->InputsRead = prog->InputsRead; clone->OutputsWritten = prog->OutputsWritten; clone->SamplersUsed = prog->SamplersUsed; + clone->ShadowSamplers = prog->ShadowSamplers; memcpy(clone->TexturesUsed, prog->TexturesUsed, sizeof(prog->TexturesUsed)); if (prog->Parameters) @@ -541,6 +542,53 @@ _mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count) /** + * Delete 'count' instructions at 'start' in the given program. + * Adjust branch targets accordingly. + */ +GLboolean +_mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count) +{ + const GLuint origLen = prog->NumInstructions; + const GLuint newLen = origLen - count; + struct prog_instruction *newInst; + GLuint i; + + /* adjust branches */ + for (i = 0; i < prog->NumInstructions; i++) { + struct prog_instruction *inst = prog->Instructions + i; + if (inst->BranchTarget > 0) { + if (inst->BranchTarget >= start) { + inst->BranchTarget -= count; + } + } + } + + /* Alloc storage for new instructions */ + newInst = _mesa_alloc_instructions(newLen); + if (!newInst) { + return GL_FALSE; + } + + /* Copy 'start' instructions into new instruction buffer */ + _mesa_copy_instructions(newInst, prog->Instructions, start); + + /* Copy the remaining/tail instructions to new inst buffer */ + _mesa_copy_instructions(newInst + start, + prog->Instructions + start + count, + newLen - start); + + /* free old instructions */ + _mesa_free_instructions(prog->Instructions, origLen); + + /* install new instructions */ + prog->Instructions = newInst; + prog->NumInstructions = newLen; + + return GL_TRUE; +} + + +/** * Search instructions for registers that match (oldFile, oldIndex), * replacing them with (newFile, newIndex). */ @@ -843,7 +891,7 @@ _mesa_BindProgram(GLenum target, GLuint id) * \note Not compiled into display lists. * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB. */ -void GLAPIENTRY +void GLAPIENTRY _mesa_DeletePrograms(GLsizei n, const GLuint *ids) { GLint i; |