summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/program.c
diff options
context:
space:
mode:
authorNicolai Haehnle <[email protected]>2008-07-06 19:48:50 +0200
committerNicolai Haehnle <[email protected]>2008-07-12 09:36:02 +0200
commitd8d086c20b5a43353c4980cf234d8329900585f5 (patch)
tree6d88f83ba0763080a16c36a4e028e520a7d34848 /src/mesa/shader/program.c
parent7904c9fad4c2cb2a4153258a9e86e530a0330a78 (diff)
r500: Add "Not quite SSA" and dead code elimination pass
In addition, this pass fixes non-native swizzles.
Diffstat (limited to 'src/mesa/shader/program.c')
-rw-r--r--src/mesa/shader/program.c61
1 files changed, 54 insertions, 7 deletions
diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c
index 376d7ee60d4..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);
@@ -542,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).
*/
@@ -844,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;