From 30d6a4bffa9a24b2080d145c8823bf6b1b8cbee7 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 5 Nov 2005 20:18:18 +0000 Subject: consolidate vertex/fragment program printing into _mesa_print_program() --- src/mesa/shader/arbfragparse.c | 89 +----------------------- src/mesa/shader/arbvertparse.c | 87 +----------------------- src/mesa/shader/arbvertparse.h | 7 +- src/mesa/shader/program.c | 123 +++++++++++++++++++++++++++++++++- src/mesa/shader/program.h | 5 ++ src/mesa/shader/program_instruction.h | 2 - 6 files changed, 131 insertions(+), 182 deletions(-) (limited to 'src/mesa') diff --git a/src/mesa/shader/arbfragparse.c b/src/mesa/shader/arbfragparse.c index 296553b269..e222bafd7d 100644 --- a/src/mesa/shader/arbfragparse.c +++ b/src/mesa/shader/arbfragparse.c @@ -39,93 +39,6 @@ #include "arbprogparse.h" #include "arbfragparse.h" -void -_mesa_debug_fp_inst(GLint num, struct prog_instruction *fp) -{ - GLint a; - static const char swz[] = "xyzw01??"; - - for (a=0; aFogOption = ap.FogOption; #if DEBUG_FP - _mesa_debug_fp_inst(ap.Base.NumInstructions, ap.FPInstructions); + _mesa_print_program(ap.Base.NumInstructions, ap.FPInstructions); #endif } diff --git a/src/mesa/shader/arbvertparse.c b/src/mesa/shader/arbvertparse.c index 27bdaff1c2..c8455793d9 100644 --- a/src/mesa/shader/arbvertparse.c +++ b/src/mesa/shader/arbvertparse.c @@ -45,89 +45,6 @@ #include "arbprogparse.h" -/** - * XXX this is probably redundant. We've already got code like this - * in the nvvertparse.c file. Combine/clean-up someday. - */ -void _mesa_debug_vp_inst(GLint num, struct prog_instruction *vp) -{ - GLint a; - static const char swz[] = "xyzw01??"; - - for (a=0; aParameters = ap.Parameters; -#if DEBUG_VP - _mesa_debug_vp_inst(ap.Base.NumInstructions, ap.VPInstructions); +#if 1/*DEBUG_VP*/ + _mesa_print_program(ap.Base.NumInstructions, ap.VPInstructions); #endif } diff --git a/src/mesa/shader/arbvertparse.h b/src/mesa/shader/arbvertparse.h index 30ff162913..c18e422a49 100644 --- a/src/mesa/shader/arbvertparse.h +++ b/src/mesa/shader/arbvertparse.h @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 5.1 + * Version: 6.5 * - * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -30,7 +30,4 @@ _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target, const GLubyte * str, GLsizei len, struct vertex_program *program); -extern void -_mesa_debug_vp_inst(GLint num, struct prog_instruction *vp); - #endif diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 44949500d6..d762205c29 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -1074,8 +1074,8 @@ _mesa_opcode_string(enum prog_opcode opcode) /** * Return string name for given program/register file. */ -const char * -_mesa_program_file_string(enum register_file f) +static const char * +program_file_string(enum register_file f) { switch (f) { case PROGRAM_TEMPORARY: @@ -1104,6 +1104,125 @@ _mesa_program_file_string(enum register_file f) } +/** + * Return a string representation of the given swizzle word. + */ +static const char * +swizzle_string(GLuint swizzle, GLuint negateBase) +{ + static const char swz[] = "xyzw01"; + static char s[20]; + GLuint i = 0; + + if (swizzle == SWIZZLE_NOOP && negateBase == 0) + return ""; /* no swizzle/negation */ + + s[i++] = '.'; + + if (negateBase & 0x1) + s[i++] = '-'; + s[i++] = swz[GET_SWZ(swizzle, 0)]; + + if (negateBase & 0x2) + s[i++] = '-'; + s[i++] = swz[GET_SWZ(swizzle, 1)]; + + if (negateBase & 0x4) + s[i++] = '-'; + s[i++] = swz[GET_SWZ(swizzle, 2)]; + + if (negateBase & 0x8) + s[i++] = '-'; + s[i++] = swz[GET_SWZ(swizzle, 3)]; + + s[i] = 0; + return s; +} + + +static const char * +writemask_string(GLuint writeMask) +{ + static char s[10]; + GLuint i = 0; + + if (writeMask == WRITEMASK_XYZW) + return ""; + + s[i++] = '.'; + if (writeMask & WRITEMASK_X) + s[i++] = 'x'; + if (writeMask & WRITEMASK_Y) + s[i++] = 'y'; + if (writeMask & WRITEMASK_Z) + s[i++] = 'z'; + if (writeMask & WRITEMASK_W) + s[i++] = 'w'; + + s[i] = 0; + return s; +} + + +/** + * Print a vertx/fragment program to stdout. + * XXX this function could be greatly improved. + */ +void +_mesa_print_program(GLuint count, const struct prog_instruction *inst) +{ + GLuint i; + + for (i = 0; i < count; i++) { + /* inst number */ + _mesa_printf("%3d: ", i); + + switch (inst[i].Opcode) { + case OPCODE_PRINT: + _mesa_printf("PRINT %s\n", inst->Data); + break; + /* XXX check for a bunch of other special-case instructions */ + default: + /* typical alu instruction */ + { + const GLuint numRegs = _mesa_num_inst_src_regs(inst[i].Opcode); + GLuint j; + + _mesa_printf("%s", _mesa_opcode_string(inst[i].Opcode)); + + /* frag prog only */ + if (inst[i].Saturate) + _mesa_printf("_SAT"); + + if (inst[i].DstReg.File != PROGRAM_UNDEFINED) { + _mesa_printf(" %s[%d]%s", + program_file_string(inst[i].DstReg.File), + inst[i].DstReg.Index, + writemask_string(inst[i].DstReg.WriteMask)); + } + + if (numRegs > 0) + _mesa_printf(", "); + + for (j = 0; j < numRegs; j++) { + _mesa_printf("%s[%d]%s", + program_file_string(inst[i].SrcReg[j].File), + inst[i].SrcReg[j].Index, + swizzle_string(inst[i].SrcReg[j].Swizzle, + inst[i].SrcReg[j].NegateBase)); + if (j + 1 < numRegs) + _mesa_printf(", "); + } + + _mesa_printf(";\n"); + } + } + } +} + + + + /**********************************************************************/ /* API functions */ /**********************************************************************/ diff --git a/src/mesa/shader/program.h b/src/mesa/shader/program.h index b45f9a50df..373a046da7 100644 --- a/src/mesa/shader/program.h +++ b/src/mesa/shader/program.h @@ -254,6 +254,11 @@ _mesa_load_state_parameters(GLcontext *ctx, struct program_parameter_list *paramList); + +extern void +_mesa_print_program(GLuint count, const struct prog_instruction *inst); + + /* * API functions common to ARB/NV_vertex/fragment_program */ diff --git a/src/mesa/shader/program_instruction.h b/src/mesa/shader/program_instruction.h index dbec622634..07a22145fa 100644 --- a/src/mesa/shader/program_instruction.h +++ b/src/mesa/shader/program_instruction.h @@ -346,7 +346,5 @@ _mesa_num_inst_src_regs(enum prog_opcode opcode); extern const char * _mesa_opcode_string(enum prog_opcode opcode); -extern const char * -_mesa_program_file_string(enum register_file f); #endif /* PROG_INSTRUCTION_H */ -- cgit v1.2.3