From 00cdc0a472c55330cbc58317f01b07f8f90be5a5 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 14 Dec 2006 15:01:06 -0700 Subject: Split the program.[ch] files into several new files. --- src/mesa/shader/prog_print.h | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/mesa/shader/prog_print.h (limited to 'src/mesa/shader/prog_print.h') diff --git a/src/mesa/shader/prog_print.h b/src/mesa/shader/prog_print.h new file mode 100644 index 0000000000..595a0dcf37 --- /dev/null +++ b/src/mesa/shader/prog_print.h @@ -0,0 +1,45 @@ +/* + * Mesa 3-D graphics library + * Version: 6.5.3 + * + * Copyright (C) 1999-2006 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"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#ifndef PROG_PRINT_H +#define PROG_PRINT_H + + +extern void +_mesa_print_instruction(const struct prog_instruction *inst); + +extern void +_mesa_print_alu_instruction(const struct prog_instruction *inst, + const char *opcode_string, + GLuint numRegs); + +extern void +_mesa_print_program(const struct gl_program *prog); + +extern void +_mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog); + + +#endif /* PROG_PRINT_H */ -- cgit v1.2.3 From 83ca3ff384ac09524ff6946134cded4174590d92 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 20 Dec 2006 17:17:38 -0700 Subject: added _mesa_print_parameter_list() --- src/mesa/shader/prog_print.c | 22 ++++++++++++++-------- src/mesa/shader/prog_print.h | 3 +++ 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src/mesa/shader/prog_print.h') diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c index 4cd55d0bca..07b383dc56 100644 --- a/src/mesa/shader/prog_print.c +++ b/src/mesa/shader/prog_print.c @@ -344,8 +344,6 @@ _mesa_print_program(const struct gl_program *prog) void _mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog) { - GLint i; - _mesa_printf("InputsRead: 0x%x\n", prog->InputsRead); _mesa_printf("OutputsWritten: 0x%x\n", prog->OutputsWritten); _mesa_printf("NumInstructions=%d\n", prog->NumInstructions); @@ -363,13 +361,21 @@ _mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog) _mesa_printf("%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]); } #endif + _mesa_print_parameter_list(prog->Parameters); +} + - for (i = 0; i < prog->Parameters->NumParameters; i++){ - struct gl_program_parameter *param = prog->Parameters->Parameters + i; - const GLfloat *v = prog->Parameters->ParameterValues[i]; - _mesa_printf("param[%d] %s %s = {%.3f, %.3f, %.3f, %.3f};\n", - i, - program_file_string(prog->Parameters->Parameters[i].Type), +void +_mesa_print_parameter_list(const struct gl_program_parameter_list *list) +{ + GLuint i; + _mesa_printf("param list %p\n", (void *) list); + for (i = 0; i < list->NumParameters; i++){ + struct gl_program_parameter *param = list->Parameters + i; + const GLfloat *v = list->ParameterValues[i]; + _mesa_printf("param[%d] sz=%d %s %s = {%.3f, %.3f, %.3f, %.3f};\n", + i, param->Size, + program_file_string(list->Parameters[i].Type), param->Name, v[0], v[1], v[2], v[3]); } } diff --git a/src/mesa/shader/prog_print.h b/src/mesa/shader/prog_print.h index 595a0dcf37..8bc2c69c6f 100644 --- a/src/mesa/shader/prog_print.h +++ b/src/mesa/shader/prog_print.h @@ -41,5 +41,8 @@ _mesa_print_program(const struct gl_program *prog); extern void _mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog); +extern void +_mesa_print_parameter_list(const struct gl_program_parameter_list *list); + #endif /* PROG_PRINT_H */ -- cgit v1.2.3 From 5db088d70fbd14620c2fc7840096a05993f8e2b9 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 5 Feb 2007 14:58:15 -0700 Subject: indentation for program instructions (if/else, loops) --- src/mesa/shader/prog_print.c | 56 ++++++++++++++++++++++++++++++++++++-------- src/mesa/shader/prog_print.h | 6 ++--- 2 files changed, 49 insertions(+), 13 deletions(-) (limited to 'src/mesa/shader/prog_print.h') diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c index 63ff84e345..9474fe995f 100644 --- a/src/mesa/shader/prog_print.c +++ b/src/mesa/shader/prog_print.c @@ -2,7 +2,7 @@ * Mesa 3-D graphics library * Version: 6.5.3 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -238,9 +238,22 @@ _mesa_print_alu_instruction(const struct prog_instruction *inst, /** * Print a single vertex/fragment program instruction. */ -void -_mesa_print_instruction(const struct prog_instruction *inst) +GLint +_mesa_print_instruction(const struct prog_instruction *inst, GLint indent) { + GLuint i; + + if (inst->Opcode == OPCODE_ELSE || + inst->Opcode == OPCODE_ENDIF || + inst->Opcode == OPCODE_ENDLOOP || + inst->Opcode == OPCODE_ENDSUB) { + indent -= 3; + } + assert(indent >= 0); + for (i = 0; i < indent; i++) { + _mesa_printf(" "); + } + switch (inst->Opcode) { case OPCODE_PRINT: _mesa_printf("PRINT '%s'", inst->Data); @@ -306,16 +319,38 @@ _mesa_print_instruction(const struct prog_instruction *inst) print_comment(inst); break; case OPCODE_IF: - _mesa_printf(" IF (%s%s)", + _mesa_printf("IF (%s%s)", condcode_string(inst->DstReg.CondMask), swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE)); print_comment(inst); - break; + return indent + 3; case OPCODE_ELSE: - _mesa_printf(" ELSE;\n"); - break; + _mesa_printf("ELSE;\n"); + return indent + 3; case OPCODE_ENDIF: - _mesa_printf(" ENDIF;\n"); + _mesa_printf("ENDIF;\n"); + break; + case OPCODE_BGNLOOP: + _mesa_printf("LOOP;\n"); + return indent + 3; + case OPCODE_ENDLOOP: + _mesa_printf("ENDLOOP;\n"); + break; + case OPCODE_BRK: + /* XXX just like BRA */ + _mesa_printf("BRK %u (%s%s)", + inst->BranchTarget, + condcode_string(inst->DstReg.CondMask), + swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE)); + print_comment(inst); + break; + case OPCODE_BGNSUB: + _mesa_printf("SUB;\n"); + print_comment(inst); + return indent + 3; + case OPCODE_ENDSUB: + _mesa_printf("ENDSUB;\n"); + print_comment(inst); break; case OPCODE_END: _mesa_printf("END"); @@ -333,6 +368,7 @@ _mesa_print_instruction(const struct prog_instruction *inst) _mesa_num_inst_src_regs(inst->Opcode)); break; } + return indent; } @@ -343,10 +379,10 @@ _mesa_print_instruction(const struct prog_instruction *inst) void _mesa_print_program(const struct gl_program *prog) { - GLuint i; + GLuint i, indent = 0; for (i = 0; i < prog->NumInstructions; i++) { _mesa_printf("%3d: ", i); - _mesa_print_instruction(prog->Instructions + i); + indent = _mesa_print_instruction(prog->Instructions + i, indent); } } diff --git a/src/mesa/shader/prog_print.h b/src/mesa/shader/prog_print.h index 8bc2c69c6f..19aaa53800 100644 --- a/src/mesa/shader/prog_print.h +++ b/src/mesa/shader/prog_print.h @@ -2,7 +2,7 @@ * Mesa 3-D graphics library * Version: 6.5.3 * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 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"), @@ -27,8 +27,8 @@ #define PROG_PRINT_H -extern void -_mesa_print_instruction(const struct prog_instruction *inst); +extern GLint +_mesa_print_instruction(const struct prog_instruction *inst, GLint indent); extern void _mesa_print_alu_instruction(const struct prog_instruction *inst, -- cgit v1.2.3 From 501ee87180047dd04afc69103c31e1eae5374bf1 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 17 Feb 2007 09:15:00 -0700 Subject: Lots of changes to prog_print.c code. Mainly, allow printing programs in either ARB, NV or "debug" formats. --- src/mesa/shader/prog_print.c | 352 ++++++++++++++++++++++++++++++++++++++----- src/mesa/shader/prog_print.h | 24 ++- src/mesa/swrast/s_fragprog.c | 3 +- src/mesa/tnl/t_vp_build.c | 2 +- 4 files changed, 336 insertions(+), 45 deletions(-) (limited to 'src/mesa/shader/prog_print.h') diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c index 0adb589daa..647ade9505 100644 --- a/src/mesa/shader/prog_print.c +++ b/src/mesa/shader/prog_print.c @@ -37,11 +37,12 @@ #include "prog_statevars.h" + /** * Return string name for given program/register file. */ static const char * -program_file_string(enum register_file f) +file_string(enum register_file f, gl_prog_print_mode mode) { switch (f) { case PROGRAM_TEMPORARY: @@ -76,6 +77,213 @@ program_file_string(enum register_file f) } +/** + * Return ARB_v/f_prog-style input attrib string. + */ +static const char * +arb_input_attrib_string(GLint index, GLenum progType) +{ + const char *vertAttribs[] = { + "vertex.position", + "vertex.weight", + "vertex.normal", + "vertex.color.primary", + "vertex.color.secondary", + "vertex.fogcoord", + "vertex.(six)", + "vertex.(seven)", + "vertex.texcoord[0]", + "vertex.texcoord[1]", + "vertex.texcoord[2]", + "vertex.texcoord[3]", + "vertex.texcoord[4]", + "vertex.texcoord[5]", + "vertex.texcoord[6]", + "vertex.texcoord[7]" + }; + const char *fragAttribs[] = { + "fragment.position", + "fragment.color.primary", + "fragment.color.secondary", + "fragment.fogcoord", + "fragment.texcoord[0]", + "fragment.texcoord[1]", + "fragment.texcoord[2]", + "fragment.texcoord[3]", + "fragment.texcoord[4]", + "fragment.texcoord[5]", + "fragment.texcoord[6]", + "fragment.texcoord[7]", + "fragment.varying[0]", + "fragment.varying[1]", + "fragment.varying[2]", + "fragment.varying[3]", + "fragment.varying[4]", + "fragment.varying[5]", + "fragment.varying[6]", + "fragment.varying[7]" + }; + + if (progType == GL_VERTEX_PROGRAM_ARB) { + assert(index < sizeof(vertAttribs) / sizeof(vertAttribs[0])); + return vertAttribs[index]; + } + else { + assert(index < sizeof(fragAttribs) / sizeof(fragAttribs[0])); + return fragAttribs[index]; + } +} + + +/** + * Return ARB_v/f_prog-style output attrib string. + */ +static const char * +arb_output_attrib_string(GLint index, GLenum progType) +{ + const char *vertResults[] = { + "result.position", + "result.color.primary", + "result.color.secondary", + "result.fogcoord", + "result.texcoord[0]", + "result.texcoord[1]", + "result.texcoord[2]", + "result.texcoord[3]", + "result.texcoord[4]", + "result.texcoord[5]", + "result.texcoord[6]", + "result.texcoord[7]", + "result.varying[0]", + "result.varying[1]", + "result.varying[2]", + "result.varying[3]", + "result.varying[4]", + "result.varying[5]", + "result.varying[6]", + "result.varying[7]" + }; + const char *fragResults[] = { + "result.color", + "result.depth" + }; + + if (progType == GL_VERTEX_PROGRAM_ARB) { + assert(index < sizeof(vertResults) / sizeof(vertResults[0])); + return vertResults[index]; + } + else { + assert(index < sizeof(fragResults) / sizeof(fragResults[0])); + return fragResults[index]; + } +} + + +/** + * Return string representation of the given register. + * Note that some types of registers (like PROGRAM_UNIFORM) aren't defined + * by the ARB/NV program languages so we've taken some liberties here. + * \param file the register file (PROGRAM_INPUT, PROGRAM_TEMPORARY, etc) + * \param index number of the register in the register file + * \param mode the output format/mode/style + * \param prog pointer to containing program + */ +static const char * +reg_string(enum register_file f, GLint index, gl_prog_print_mode mode, + const struct gl_program *prog) +{ + static char str[100]; + + str[0] = 0; + + switch (mode) { + case PROG_PRINT_DEBUG: + sprintf(str, "%s[%d]", file_string(f, mode), index); + break; + + case PROG_PRINT_ARB: + switch (f) { + case PROGRAM_INPUT: + sprintf(str, "%s", arb_input_attrib_string(index, prog->Target)); + break; + case PROGRAM_OUTPUT: + sprintf(str, "%s", arb_output_attrib_string(index, prog->Target)); + break; + case PROGRAM_TEMPORARY: + sprintf(str, "temp%d", index); + break; + case PROGRAM_ENV_PARAM: + sprintf(str, "program.env[%d]", index); + break; + case PROGRAM_LOCAL_PARAM: + sprintf(str, "program.local[%d]", index); + break; + case PROGRAM_VARYING: /* extension */ + sprintf(str, "varying[%d]", index); + break; + case PROGRAM_CONSTANT: /* extension */ + sprintf(str, "constant[%d]", index); + break; + case PROGRAM_UNIFORM: /* extension */ + sprintf(str, "uniform[%d]", index); + break; + case PROGRAM_STATE_VAR: + { + struct gl_program_parameter *param + = prog->Parameters->Parameters + index; + sprintf(str, _mesa_program_state_string(param->StateIndexes)); + } + break; + case PROGRAM_ADDRESS: + sprintf(str, "A%d", index); + break; + default: + _mesa_problem(NULL, "bad file in reg_string()"); + } + break; + + case PROG_PRINT_NV: + switch (f) { + case PROGRAM_INPUT: + if (prog->Target == GL_VERTEX_PROGRAM_ARB) + sprintf(str, "v[%d]", index); + else + sprintf(str, "f[%d]", index); + break; + case PROGRAM_OUTPUT: + sprintf(str, "o[%d]", index); + break; + case PROGRAM_TEMPORARY: + sprintf(str, "R%d", index); + break; + case PROGRAM_ENV_PARAM: + sprintf(str, "c[%d]", index); + break; + case PROGRAM_VARYING: /* extension */ + sprintf(str, "varying[%d]", index); + break; + case PROGRAM_UNIFORM: /* extension */ + sprintf(str, "uniform[%d]", index); + break; + case PROGRAM_CONSTANT: /* extension */ + sprintf(str, "constant[%d]", index); + break; + case PROGRAM_STATE_VAR: /* extension */ + sprintf(str, "state[%d]", index); + break; + default: + _mesa_problem(NULL, "bad file in reg_string()"); + } + break; + + default: + _mesa_problem(NULL, "bad mode in reg_string()"); + } + + return str; +} + + /** * Return a string representation of the given swizzle word. * If extended is true, use extended (comma-separated) format. @@ -172,22 +380,38 @@ condcode_string(GLuint condcode) static void -print_dst_reg(const struct prog_dst_register *dstReg) +print_dst_reg(const struct prog_dst_register *dstReg, gl_prog_print_mode mode, + const struct gl_program *prog) { - _mesa_printf(" %s[%d]%s", - program_file_string((enum register_file) dstReg->File), + _mesa_printf("%s%s", + reg_string((enum register_file) dstReg->File, + dstReg->Index, mode, prog), + writemask_string(dstReg->WriteMask)); + +#if 0 + _mesa_printf("%s[%d]%s", + file_string((enum register_file) dstReg->File, mode), dstReg->Index, writemask_string(dstReg->WriteMask)); +#endif } static void -print_src_reg(const struct prog_src_register *srcReg) +print_src_reg(const struct prog_src_register *srcReg, gl_prog_print_mode mode, + const struct gl_program *prog) { + _mesa_printf("%s%s", + reg_string((enum register_file) srcReg->File, + srcReg->Index, mode, prog), + swizzle_string(srcReg->Swizzle, + srcReg->NegateBase, GL_FALSE)); +#if 0 _mesa_printf("%s[%d]%s", - program_file_string((enum register_file) srcReg->File), + file_string((enum register_file) srcReg->File, mode), srcReg->Index, swizzle_string(srcReg->Swizzle, srcReg->NegateBase, GL_FALSE)); +#endif } static void @@ -200,10 +424,11 @@ print_comment(const struct prog_instruction *inst) } -void -_mesa_print_alu_instruction(const struct prog_instruction *inst, - const char *opcode_string, - GLuint numRegs) +static void +print_alu_instruction(const struct prog_instruction *inst, + const char *opcode_string, GLuint numRegs, + gl_prog_print_mode mode, + const struct gl_program *prog) { GLuint j; @@ -215,8 +440,9 @@ _mesa_print_alu_instruction(const struct prog_instruction *inst, if (inst->SaturateMode == SATURATE_ZERO_ONE) _mesa_printf("_SAT"); + _mesa_printf(" "); if (inst->DstReg.File != PROGRAM_UNDEFINED) { - print_dst_reg(&inst->DstReg); + print_dst_reg(&inst->DstReg, mode, prog); } else { _mesa_printf(" ???"); @@ -226,7 +452,7 @@ _mesa_print_alu_instruction(const struct prog_instruction *inst, _mesa_printf(", "); for (j = 0; j < numRegs; j++) { - print_src_reg(inst->SrcReg + j); + print_src_reg(inst->SrcReg + j, mode, prog); if (j + 1 < numRegs) _mesa_printf(", "); } @@ -235,11 +461,21 @@ _mesa_print_alu_instruction(const struct prog_instruction *inst, } +void +_mesa_print_instruction(const struct prog_instruction *inst) +{ + /* note: 4th param should be ignored for PROG_PRINT_DEBUG */ + _mesa_print_instruction_opt(inst, 0, PROG_PRINT_DEBUG, NULL); +} + + /** * Print a single vertex/fragment program instruction. */ GLint -_mesa_print_instruction(const struct prog_instruction *inst, GLint indent) +_mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent, + gl_prog_print_mode mode, + const struct gl_program *prog) { GLuint i; @@ -260,7 +496,8 @@ _mesa_print_instruction(const struct prog_instruction *inst, GLint indent) if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) { _mesa_printf(", "); _mesa_printf("%s[%d]%s", - program_file_string((enum register_file) inst->SrcReg[0].File), + file_string((enum register_file) inst->SrcReg[0].File, + mode), inst->SrcReg[0].Index, swizzle_string(inst->SrcReg[0].Swizzle, inst->SrcReg[0].NegateBase, GL_FALSE)); @@ -273,9 +510,11 @@ _mesa_print_instruction(const struct prog_instruction *inst, GLint indent) _mesa_printf("SWZ"); if (inst->SaturateMode == SATURATE_ZERO_ONE) _mesa_printf("_SAT"); - print_dst_reg(&inst->DstReg); + _mesa_printf(" "); + print_dst_reg(&inst->DstReg, mode, prog); _mesa_printf("%s[%d], %s", - program_file_string((enum register_file) inst->SrcReg[0].File), + file_string((enum register_file) inst->SrcReg[0].File, + mode), inst->SrcReg[0].Index, swizzle_string(inst->SrcReg[0].Swizzle, inst->SrcReg[0].NegateBase, GL_TRUE)); @@ -287,9 +526,10 @@ _mesa_print_instruction(const struct prog_instruction *inst, GLint indent) _mesa_printf("%s", _mesa_opcode_string(inst->Opcode)); if (inst->SaturateMode == SATURATE_ZERO_ONE) _mesa_printf("_SAT"); - print_dst_reg(&inst->DstReg); + _mesa_printf(" "); + print_dst_reg(&inst->DstReg, mode, prog); _mesa_printf(", "); - print_src_reg(&inst->SrcReg[0]); + print_src_reg(&inst->SrcReg[0], mode, prog); _mesa_printf(", texture[%d], ", inst->TexSrcUnit); switch (inst->TexSrcTarget) { case TEXTURE_1D_INDEX: _mesa_printf("1D"); break; @@ -304,7 +544,7 @@ _mesa_print_instruction(const struct prog_instruction *inst, GLint indent) break; case OPCODE_ARL: _mesa_printf("ARL addr.x, "); - print_src_reg(&inst->SrcReg[0]); + print_src_reg(&inst->SrcReg[0], mode, prog); print_comment(inst); break; case OPCODE_BRA: @@ -319,49 +559,48 @@ _mesa_print_instruction(const struct prog_instruction *inst, GLint indent) print_comment(inst); break; case OPCODE_IF: - _mesa_printf("IF (%s%s) (if false, goto %d)", + _mesa_printf("IF (%s%s); # (if false, goto %d)", condcode_string(inst->DstReg.CondMask), swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE), inst->BranchTarget); print_comment(inst); return indent + 3; case OPCODE_ELSE: - _mesa_printf("ELSE (goto %d)\n", inst->BranchTarget); + _mesa_printf("ELSE; # (goto %d)\n", inst->BranchTarget); return indent + 3; case OPCODE_ENDIF: - _mesa_printf("ENDIF\n"); + _mesa_printf("ENDIF;\n"); break; case OPCODE_BGNLOOP: - _mesa_printf("BGNLOOP (end at %d)\n", inst->BranchTarget); + _mesa_printf("BGNLOOP; # (end at %d)\n", inst->BranchTarget); return indent + 3; case OPCODE_ENDLOOP: - _mesa_printf("ENDLOOP (goto %d)\n", inst->BranchTarget); + _mesa_printf("ENDLOOP; # (goto %d)\n", inst->BranchTarget); break; case OPCODE_BRK: - _mesa_printf("BRK (%s%s) (goto %d)", + _mesa_printf("BRK (%s%s); #(goto %d)", condcode_string(inst->DstReg.CondMask), swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE), inst->BranchTarget); print_comment(inst); break; case OPCODE_CONT: - _mesa_printf("CONT (%s%s) (goto %d)", + _mesa_printf("CONT (%s%s); #(goto %d)", condcode_string(inst->DstReg.CondMask), swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE), inst->BranchTarget); print_comment(inst); break; case OPCODE_BGNSUB: - _mesa_printf("SUB;\n"); + _mesa_printf("SUB"); print_comment(inst); return indent + 3; case OPCODE_ENDSUB: - _mesa_printf("ENDSUB;\n"); + _mesa_printf("ENDSUB"); print_comment(inst); break; case OPCODE_END: - _mesa_printf("END"); - print_comment(inst); + _mesa_printf("END\n"); break; case OPCODE_NOP: _mesa_printf("NOP"); @@ -370,9 +609,10 @@ _mesa_print_instruction(const struct prog_instruction *inst, GLint indent) /* XXX may need other special-case instructions */ default: /* typical alu instruction */ - _mesa_print_alu_instruction(inst, - _mesa_opcode_string(inst->Opcode), - _mesa_num_inst_src_regs(inst->Opcode)); + print_alu_instruction(inst, + _mesa_opcode_string(inst->Opcode), + _mesa_num_inst_src_regs(inst->Opcode), + mode, prog); break; } return indent; @@ -380,16 +620,50 @@ _mesa_print_instruction(const struct prog_instruction *inst, GLint indent) /** - * Print a vertx/fragment program to stdout. - * XXX this function could be greatly improved. + * Print program to stdout, default options. */ void _mesa_print_program(const struct gl_program *prog) +{ + _mesa_print_program_opt(prog, PROG_PRINT_ARB, GL_TRUE); +} + + +/** + * Print program, with options. + */ +void +_mesa_print_program_opt(const struct gl_program *prog, + gl_prog_print_mode mode, + GLboolean lineNumbers) { GLuint i, indent = 0; + + switch (prog->Target) { + case GL_VERTEX_PROGRAM_ARB: + if (mode == PROG_PRINT_ARB) + _mesa_printf("!!ARBvp1.0\n"); + else if (mode == PROG_PRINT_NV) + _mesa_printf("!!VP1.0\n"); + else + _mesa_printf("# Vertex Program/Shader\n"); + break; + case GL_FRAGMENT_PROGRAM_ARB: + case GL_FRAGMENT_PROGRAM_NV: + if (mode == PROG_PRINT_ARB) + _mesa_printf("!!ARBfp1.0\n"); + else if (mode == PROG_PRINT_NV) + _mesa_printf("!!FP1.0\n"); + else + _mesa_printf("# Fragment Program/Shader\n"); + break; + } + for (i = 0; i < prog->NumInstructions; i++) { - _mesa_printf("%3d: ", i); - indent = _mesa_print_instruction(prog->Instructions + i, indent); + if (lineNumbers) + _mesa_printf("%3d: ", i); + indent = _mesa_print_instruction_opt(prog->Instructions + i, + indent, mode, prog); } } @@ -424,14 +698,16 @@ _mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog) void _mesa_print_parameter_list(const struct gl_program_parameter_list *list) { + const gl_prog_print_mode mode = PROG_PRINT_DEBUG; GLuint i; + _mesa_printf("param list %p\n", (void *) list); for (i = 0; i < list->NumParameters; i++){ struct gl_program_parameter *param = list->Parameters + i; const GLfloat *v = list->ParameterValues[i]; _mesa_printf("param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g};\n", i, param->Size, - program_file_string(list->Parameters[i].Type), + file_string(list->Parameters[i].Type, mode), param->Name, v[0], v[1], v[2], v[3]); } } diff --git a/src/mesa/shader/prog_print.h b/src/mesa/shader/prog_print.h index 19aaa53800..79c599f5a7 100644 --- a/src/mesa/shader/prog_print.h +++ b/src/mesa/shader/prog_print.h @@ -27,17 +27,31 @@ #define PROG_PRINT_H -extern GLint -_mesa_print_instruction(const struct prog_instruction *inst, GLint indent); +/** + * The output style to use when printing programs. + */ +typedef enum { + PROG_PRINT_ARB, + PROG_PRINT_NV, + PROG_PRINT_DEBUG +} gl_prog_print_mode; + extern void -_mesa_print_alu_instruction(const struct prog_instruction *inst, - const char *opcode_string, - GLuint numRegs); +_mesa_print_instruction(const struct prog_instruction *inst); + +extern GLint +_mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent, + gl_prog_print_mode mode, + const struct gl_program *prog); extern void _mesa_print_program(const struct gl_program *prog); +extern void +_mesa_print_program_opt(const struct gl_program *prog, gl_prog_print_mode mode, + GLboolean lineNumbers); + extern void _mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog); diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index fe41c0b5f4..89907f73c6 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -554,6 +554,7 @@ init_machine_deriv( GLcontext *ctx, _mesa_memcpy(dMachine, machine, sizeof(struct fp_machine)); if (program->Base.Target == GL_FRAGMENT_PROGRAM_NV) { + /* XXX also need to do this when using valgrind */ /* Clear temporary registers (undefined for ARB_f_p) */ _mesa_bzero( (void*) machine->Temporaries, MAX_NV_FRAGMENT_PROGRAM_TEMPS * 4 * sizeof(GLfloat)); @@ -665,7 +666,7 @@ execute_program( GLcontext *ctx, } if (DEBUG_FRAG) { - _mesa_print_instruction(inst, 0); + _mesa_print_instruction(inst); } switch (inst->Opcode) { diff --git a/src/mesa/tnl/t_vp_build.c b/src/mesa/tnl/t_vp_build.c index 6fb14e7caa..47fed32904 100644 --- a/src/mesa/tnl/t_vp_build.c +++ b/src/mesa/tnl/t_vp_build.c @@ -497,7 +497,7 @@ static void debug_insn( struct prog_instruction *inst, const char *fn, } _mesa_printf("%d:\t", line); - _mesa_print_instruction(inst, 0); + _mesa_print_instruction(inst); } } -- cgit v1.2.3 From 059376c855cbeb160e98f438a35edb8bd88b8bb2 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 22 Feb 2007 17:45:32 -0700 Subject: expose _mesa_swizzle_string() --- src/mesa/shader/prog_print.c | 34 ++++++++++++++++++++-------------- src/mesa/shader/prog_print.h | 3 +++ 2 files changed, 23 insertions(+), 14 deletions(-) (limited to 'src/mesa/shader/prog_print.h') diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c index 95b62fcfb5..0d21912a0e 100644 --- a/src/mesa/shader/prog_print.c +++ b/src/mesa/shader/prog_print.c @@ -291,8 +291,8 @@ reg_string(enum register_file f, GLint index, gl_prog_print_mode mode, * \param negateBase 4-bit negation vector * \param extended if true, also allow 0, 1 values */ -static const char * -swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended) +const char * +_mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended) { static const char swz[] = "xyzw01?!"; static char s[20]; @@ -403,13 +403,13 @@ print_src_reg(const struct prog_src_register *srcReg, gl_prog_print_mode mode, _mesa_printf("%s%s", reg_string((enum register_file) srcReg->File, srcReg->Index, mode, prog), - swizzle_string(srcReg->Swizzle, + _mesa_swizzle_string(srcReg->Swizzle, srcReg->NegateBase, GL_FALSE)); #if 0 _mesa_printf("%s[%d]%s", file_string((enum register_file) srcReg->File, mode), srcReg->Index, - swizzle_string(srcReg->Swizzle, + _mesa_swizzle_string(srcReg->Swizzle, srcReg->NegateBase, GL_FALSE)); #endif } @@ -498,8 +498,8 @@ _mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent, file_string((enum register_file) inst->SrcReg[0].File, mode), inst->SrcReg[0].Index, - swizzle_string(inst->SrcReg[0].Swizzle, - inst->SrcReg[0].NegateBase, GL_FALSE)); + _mesa_swizzle_string(inst->SrcReg[0].Swizzle, + inst->SrcReg[0].NegateBase, GL_FALSE)); } if (inst->Comment) _mesa_printf(" # %s", inst->Comment); @@ -515,8 +515,8 @@ _mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent, file_string((enum register_file) inst->SrcReg[0].File, mode), inst->SrcReg[0].Index, - swizzle_string(inst->SrcReg[0].Swizzle, - inst->SrcReg[0].NegateBase, GL_TRUE)); + _mesa_swizzle_string(inst->SrcReg[0].Swizzle, + inst->SrcReg[0].NegateBase, GL_TRUE)); print_comment(inst); break; case OPCODE_TEX: @@ -550,7 +550,7 @@ _mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent, _mesa_printf("BRA %u (%s%s)", inst->BranchTarget, condcode_string(inst->DstReg.CondMask), - swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE)); + _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE)); print_comment(inst); break; case OPCODE_CAL: @@ -560,7 +560,7 @@ _mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent, case OPCODE_IF: _mesa_printf("IF (%s%s); # (if false, goto %d)", condcode_string(inst->DstReg.CondMask), - swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE), + _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE), inst->BranchTarget); print_comment(inst); return indent + 3; @@ -579,14 +579,14 @@ _mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent, case OPCODE_BRK: _mesa_printf("BRK (%s%s); #(goto %d)", condcode_string(inst->DstReg.CondMask), - swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE), + _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE), inst->BranchTarget); print_comment(inst); break; case OPCODE_CONT: _mesa_printf("CONT (%s%s); #(goto %d)", condcode_string(inst->DstReg.CondMask), - swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE), + _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE), inst->BranchTarget); print_comment(inst); break; @@ -602,8 +602,14 @@ _mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent, _mesa_printf("END\n"); break; case OPCODE_NOP: - _mesa_printf("NOP"); - print_comment(inst); + if (mode == PROG_PRINT_DEBUG) { + _mesa_printf("NOP"); + print_comment(inst); + } + else if (inst->Comment) { + /* ARB/NV extensions don't have NOP instruction */ + _mesa_printf("# %s\n", inst->Comment); + } break; /* XXX may need other special-case instructions */ default: diff --git a/src/mesa/shader/prog_print.h b/src/mesa/shader/prog_print.h index 79c599f5a7..c0101b6b0f 100644 --- a/src/mesa/shader/prog_print.h +++ b/src/mesa/shader/prog_print.h @@ -37,6 +37,9 @@ typedef enum { } gl_prog_print_mode; +extern const char * +_mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended); + extern void _mesa_print_instruction(const struct prog_instruction *inst); -- cgit v1.2.3 From 0020d1022f4b5befe4adf783bedc4cf83e09f01f Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 23 Feb 2007 11:43:44 -0700 Subject: re-expose _mesa_print_alu_instruction() --- src/mesa/shader/prog_print.c | 10 +++++++++- src/mesa/shader/prog_print.h | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/mesa/shader/prog_print.h') diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c index 0d21912a0e..4519f0c030 100644 --- a/src/mesa/shader/prog_print.c +++ b/src/mesa/shader/prog_print.c @@ -426,7 +426,7 @@ print_comment(const struct prog_instruction *inst) static void print_alu_instruction(const struct prog_instruction *inst, - const char *opcode_string, GLuint numRegs, + const char *opcode_string, GLuint numRegs, gl_prog_print_mode mode, const struct gl_program *prog) { @@ -461,6 +461,14 @@ print_alu_instruction(const struct prog_instruction *inst, } +void +_mesa_print_alu_instruction(const struct prog_instruction *inst, + const char *opcode_string, GLuint numRegs) +{ + print_alu_instruction(inst, opcode_string, numRegs, PROG_PRINT_DEBUG, NULL); +} + + void _mesa_print_instruction(const struct prog_instruction *inst) { diff --git a/src/mesa/shader/prog_print.h b/src/mesa/shader/prog_print.h index c0101b6b0f..9c7607f9d5 100644 --- a/src/mesa/shader/prog_print.h +++ b/src/mesa/shader/prog_print.h @@ -40,6 +40,10 @@ typedef enum { extern const char * _mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended); +extern void +_mesa_print_alu_instruction(const struct prog_instruction *inst, + const char *opcode_string, GLuint numRegs); + extern void _mesa_print_instruction(const struct prog_instruction *inst); -- cgit v1.2.3