From 72f2c55069f167a46560005931382e3b472f92ed Mon Sep 17 00:00:00 2001
From: Brian Paul <brian.paul@tungstengraphics.com>
Date: Fri, 4 Apr 2008 11:20:44 -0600
Subject: gallium: make sure to set the SamplersUsed field for
 bitmap/drawpixels shaders

Also, make sure that field is copied/updated in the program clone and combine functions.
Without this we weren't getting SAMP declarations in the TGSI shaders.
---
 src/mesa/shader/program.c | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'src/mesa/shader/program.c')

diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c
index 09a8494bd3..3069b04836 100644
--- a/src/mesa/shader/program.c
+++ b/src/mesa/shader/program.c
@@ -361,6 +361,7 @@ _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog)
                            prog->NumInstructions);
    clone->InputsRead = prog->InputsRead;
    clone->OutputsWritten = prog->OutputsWritten;
+   clone->SamplersUsed = prog->SamplersUsed;
    memcpy(clone->TexturesUsed, prog->TexturesUsed, sizeof(prog->TexturesUsed));
 
    if (prog->Parameters)
@@ -537,6 +538,7 @@ _mesa_combine_programs(GLcontext *ctx,
       }
       newProg->InputsRead = progA->InputsRead | inputsB;
       newProg->OutputsWritten = progB->OutputsWritten;
+      newProg->SamplersUsed = progA->SamplersUsed | progB->SamplersUsed;
    }
    else {
       /* vertex program */
-- 
cgit v1.2.3


From 5d1e73028aabfa1470bfed02c705a2696706f857 Mon Sep 17 00:00:00 2001
From: Brian <brian.paul@tungstengraphics.com>
Date: Mon, 7 Apr 2008 11:16:18 -0600
Subject: mesa: added _mesa_insert_instructions()

Also, use new _mesa_free_instructions() in a few places.
---
 src/mesa/shader/program.c | 60 +++++++++++++++++++++++++++++++++++++++--------
 src/mesa/shader/program.h |  2 ++
 2 files changed, 52 insertions(+), 10 deletions(-)

(limited to 'src/mesa/shader/program.c')

diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c
index 3069b04836..0ed7f833d2 100644
--- a/src/mesa/shader/program.c
+++ b/src/mesa/shader/program.c
@@ -287,16 +287,7 @@ _mesa_delete_program(GLcontext *ctx, struct gl_program *prog)
    if (prog->String)
       _mesa_free(prog->String);
 
-   if (prog->Instructions) {
-      GLuint i;
-      for (i = 0; i < prog->NumInstructions; i++) {
-         if (prog->Instructions[i].Data)
-            _mesa_free(prog->Instructions[i].Data);
-         if (prog->Instructions[i].Comment)
-            _mesa_free((char *) prog->Instructions[i].Comment);
-      }
-      _mesa_free(prog->Instructions);
-   }
+   _mesa_free_instructions(prog->Instructions, prog->NumInstructions);
 
    if (prog->Parameters) {
       _mesa_free_parameter_list(prog->Parameters);
@@ -415,6 +406,55 @@ _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog)
 }
 
 
+/**
+ * Insert 'count' NOP instructions at 'start' in the given program.
+ * Adjust branch targets accordingly.
+ */
+GLboolean
+_mesa_insert_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);
+
+   /* init the new instructions */
+   _mesa_init_instructions(newInst + start, count);
+
+   /* Copy the remaining/tail instructions to new inst buffer */
+   _mesa_copy_instructions(newInst + start + count,
+                           prog->Instructions + start,
+                           origLen - 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),
diff --git a/src/mesa/shader/program.h b/src/mesa/shader/program.h
index 4b7297e4c6..414a57d39c 100644
--- a/src/mesa/shader/program.h
+++ b/src/mesa/shader/program.h
@@ -87,6 +87,8 @@ _mesa_lookup_program(GLcontext *ctx, GLuint id);
 extern struct gl_program *
 _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog);
 
+extern  GLboolean
+_mesa_insert_instructions(struct gl_program *prog, GLuint start, GLuint count);
 
 extern struct gl_program *
 _mesa_combine_programs(GLcontext *ctx,
-- 
cgit v1.2.3