mesa: added _mesa_postprocess_program() to aid shader debugging
authorBrian Paul <brianp@vmware.com>
Wed, 17 Jun 2009 13:42:49 +0000 (07:42 -0600)
committerBrian Paul <brianp@vmware.com>
Wed, 17 Jun 2009 15:58:29 +0000 (09:58 -0600)
src/mesa/shader/program.c
src/mesa/shader/program.h

index d270bf9e1c36cc07032f87fc57a37599b0688cb2..b56308b029707dab981b9bd22440626dd12edff8 100644 (file)
@@ -820,3 +820,61 @@ _mesa_find_free_register(const struct gl_program *prog, GLuint regFile)
 
    return -1;
 }
+
+
+
+/**
+ * "Post-process" a GPU program.  This is intended to be used for debugging.
+ * Example actions include no-op'ing instructions or changing instruction
+ * behaviour.
+ */
+void
+_mesa_postprocess_program(GLcontext *ctx, struct gl_program *prog)
+{
+   static const GLfloat white[4] = { 0.5, 0.5, 0.5, 0.5 };
+   GLuint i;
+   GLuint whiteSwizzle;
+   GLint whiteIndex = _mesa_add_unnamed_constant(prog->Parameters,
+                                                 white, 4, &whiteSwizzle);
+
+   for (i = 0; i < prog->NumInstructions; i++) {
+      struct prog_instruction *inst = prog->Instructions + i;
+      const GLuint n = _mesa_num_inst_src_regs(inst->Opcode);
+
+      (void) n;
+
+      if (_mesa_is_tex_instruction(inst->Opcode)) {
+#if 0
+         /* replace TEX/TXP/TXB with MOV */
+         inst->Opcode = OPCODE_MOV;
+         inst->DstReg.WriteMask = WRITEMASK_XYZW;
+         inst->SrcReg[0].Swizzle = SWIZZLE_XYZW;
+         inst->SrcReg[0].Negate = NEGATE_NONE;
+#endif
+
+#if 0
+         /* disable shadow texture mode */
+         inst->TexShadow = 0;
+#endif
+      }
+
+      if (inst->Opcode == OPCODE_TXP) {
+#if 0
+         inst->Opcode = OPCODE_MOV;
+         inst->DstReg.WriteMask = WRITEMASK_XYZW;
+         inst->SrcReg[0].File = PROGRAM_CONSTANT;
+         inst->SrcReg[0].Index = whiteIndex;
+         inst->SrcReg[0].Swizzle = SWIZZLE_XYZW;
+         inst->SrcReg[0].Negate = NEGATE_NONE;
+#endif
+#if 0
+         inst->TexShadow = 0;
+#endif
+#if 0
+         inst->Opcode = OPCODE_TEX;
+         inst->TexShadow = 0;
+#endif
+      }
+
+   }
+}
index 48176162c35fb62e7061cb52721032797d323ca6..56a4191f5788f7f2b2d571f992ed21856f2fa5bd 100644 (file)
@@ -122,6 +122,8 @@ _mesa_combine_programs(GLcontext *ctx,
 extern GLint
 _mesa_find_free_register(const struct gl_program *prog, GLuint regFile);
 
+extern void
+_mesa_postprocess_program(GLcontext *ctx, struct gl_program *prog);
 
 
 #endif /* PROGRAM_H */