Check if the user/texenvprogram is just a pass-through program and skip program conca...
authorBrian <brian.paul@tungstengraphics.com>
Sun, 4 Nov 2007 23:38:36 +0000 (16:38 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Sun, 4 Nov 2007 23:39:01 +0000 (16:39 -0700)
src/mesa/state_tracker/st_cb_drawpixels.c

index ffaa34d7d31e12e602dc613c0f76cd7b73d9cfeb..fc58035d00b69091eff52ae72545b9c9efa156db 100644 (file)
 #include "shader/prog_instruction.h"
 
 
+/**
+ * Check if the given program is:
+ * 0: MOVE result.color, fragment.color;
+ * 1: END;
+ */
+static GLboolean
+is_passthrough_program(const struct gl_fragment_program *prog)
+{
+   if (prog->Base.NumInstructions == 2) {
+      const struct prog_instruction *inst = prog->Base.Instructions;
+      if (inst[0].Opcode == OPCODE_MOV &&
+          inst[1].Opcode == OPCODE_END &&
+          inst[0].DstReg.File == PROGRAM_OUTPUT &&
+          inst[0].DstReg.Index == FRAG_RESULT_COLR &&
+          inst[0].DstReg.WriteMask == WRITEMASK_XYZW &&
+          inst[0].SrcReg[0].File == PROGRAM_INPUT &&
+          inst[0].SrcReg[0].Index == FRAG_ATTRIB_COL0 &&
+          inst[0].SrcReg[0].Swizzle == SWIZZLE_XYZW) {
+         return GL_TRUE;
+      }
+   }
+   return GL_FALSE;
+}
+
 
 /**
  * Make fragment program for glBitmap:
@@ -215,14 +239,21 @@ combined_drawpix_fragment_program(GLcontext *ctx)
       /* Concatenate the pixel transfer program with the current user-
        * defined program.
        */
-      stfp = (struct st_fragment_program *)
-         _mesa_combine_programs(ctx,
-                                &st->pixel_xfer.program->Base.Base,
-                                &st->fp->Base.Base);
+      if (is_passthrough_program(&st->fp->Base)) {
+         stfp = (struct st_fragment_program *)
+            _mesa_clone_program(ctx, &st->pixel_xfer.program->Base.Base);
+      }
+      else {
+         stfp = (struct st_fragment_program *)
+            _mesa_combine_programs(ctx,
+                                   &st->pixel_xfer.program->Base.Base,
+                                   &st->fp->Base.Base);
+      }
 
 #if 0
       {
          struct gl_program *p = &stfp->Base.Base;
+         printf("Combined DrawPixels program:\n");
          _mesa_print_program(p);
          printf("InputsRead: 0x%x\n", p->InputsRead);
          printf("OutputsWritten: 0x%x\n", p->OutputsWritten);