X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fshader%2Fprogram.c;h=4623ff60de6b5c5a7fe64f11ec44a314b8fa9cbb;hb=4ce73ad92c723b4e65fbdc1d144b2017f9bcd438;hp=37962f0e9bb33717aef36c7ca48c23f38d5b198f;hpb=2a6c6fe01e84ffd54b47ea11aa766960df6ddcaf;p=mesa.git diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 37962f0e9bb..4623ff60de6 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -53,6 +53,15 @@ _mesa_init_program(GLcontext *ctx) { GLuint i; + /* + * If this assertion fails, we need to increase the field + * size for register indexes. + */ + ASSERT(ctx->Const.VertexProgram.MaxUniformComponents / 4 + <= (1 << INST_INDEX_BITS)); + ASSERT(ctx->Const.FragmentProgram.MaxUniformComponents / 4 + <= (1 << INST_INDEX_BITS)); + ctx->Program.ErrorPos = -1; ctx->Program.ErrorString = _mesa_strdup(""); @@ -287,6 +296,7 @@ _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id) struct gl_program *prog; switch (target) { case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */ + case GL_VERTEX_STATE_PROGRAM_NV: prog = _mesa_init_vertex_program(ctx, CALLOC_STRUCT(gl_vertex_program), target, id ); break; @@ -570,7 +580,7 @@ _mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count) for (i = 0; i < prog->NumInstructions; i++) { struct prog_instruction *inst = prog->Instructions + i; if (inst->BranchTarget > 0) { - if (inst->BranchTarget >= start) { + if (inst->BranchTarget > start) { inst->BranchTarget -= count; } } @@ -729,7 +739,7 @@ _mesa_combine_programs(GLcontext *ctx, /* Connect color outputs of fprogA to color inputs of fprogB, via a * new temporary register. */ - if ((progA->OutputsWritten & (1 << FRAG_RESULT_COLR)) && + if ((progA->OutputsWritten & (1 << FRAG_RESULT_COLOR)) && (progB_inputsRead & FRAG_BIT_COL0)) { GLint tempReg = _mesa_find_free_register(newProg, PROGRAM_TEMPORARY); if (tempReg < 0) { @@ -739,7 +749,7 @@ _mesa_combine_programs(GLcontext *ctx, } /* replace writes to result.color[0] with tempReg */ replace_registers(newInst, lenA, - PROGRAM_OUTPUT, FRAG_RESULT_COLR, + PROGRAM_OUTPUT, FRAG_RESULT_COLOR, PROGRAM_TEMPORARY, tempReg); /* replace reads from the input color with tempReg */ replace_registers(newInst + lenA, lenB, @@ -749,7 +759,7 @@ _mesa_combine_programs(GLcontext *ctx, /* compute combined program's InputsRead */ inputsB = progB_inputsRead; - if (progA->OutputsWritten & (1 << FRAG_RESULT_COLR)) { + if (progA->OutputsWritten & (1 << FRAG_RESULT_COLOR)) { inputsB &= ~(1 << FRAG_ATTRIB_COL0); } newProg->InputsRead = progA->InputsRead | inputsB; @@ -810,3 +820,63 @@ _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); + + (void) whiteIndex; + + 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 + } + + } +}