From b2524a0c955edfd2971d7f855f4df9a82493b913 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 1 Jun 2011 13:22:21 -0400 Subject: [PATCH] Place preshader destination register last in operand list. This is where it's located in the shader, and it simplies some things. --- mojoshader.c | 5 +- mojoshader_effects.c | 5 +- utils/testparse.c | 132 ++++++++++++++++++++++--------------------- 3 files changed, 72 insertions(+), 70 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 7f8eb8b1..a43f7618 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -7320,14 +7320,11 @@ static void parse_preshader(Context *ctx, uint32 tokcount) return; } // if - MOJOSHADER_preshaderOperand *operand = &inst->operands[1]; + MOJOSHADER_preshaderOperand *operand = inst->operands; while (operand_count--) { const unsigned int item = (unsigned int) SWAP32(fxlc.tokens[2]); - if (operand_count == 0) // List destination first. - operand = &inst->operands[0]; - // !!! FIXME: don't know what first token does. switch (SWAP32(fxlc.tokens[1])) { diff --git a/mojoshader_effects.c b/mojoshader_effects.c index 1a5c203c..11157f2c 100644 --- a/mojoshader_effects.c +++ b/mojoshader_effects.c @@ -34,14 +34,14 @@ void MOJOSHADER_runPreshader(const MOJOSHADER_preshader *preshader, for (instit = 0; instit < preshader->instruction_count; instit++, inst++) { - const MOJOSHADER_preshaderOperand *operand = &inst->operands[1]; + const MOJOSHADER_preshaderOperand *operand = inst->operands; const int isscalar = (inst->opcode >= scalarstart); const int elems = inst->element_count; const int elemsbytes = sizeof (double) * elems; // load up our operands... int opiter, elemiter; - for (opiter = 1; opiter < inst->operand_count; opiter++, operand++) + for (opiter = 0; opiter < inst->operand_count-1; opiter++, operand++) { const unsigned int index = operand->index; switch (operand->type) @@ -164,7 +164,6 @@ void MOJOSHADER_runPreshader(const MOJOSHADER_preshader *preshader, } // switch // Figure out where dst wants to be stored. - operand = inst->operands; if (operand->type == MOJOSHADER_PRESHADEROPERAND_TEMP) memcpy(temps + operand->index, dst, elemsbytes); else diff --git a/utils/testparse.c b/utils/testparse.c index 2a6c5515..4d7f9d5c 100644 --- a/utils/testparse.c +++ b/utils/testparse.c @@ -135,11 +135,72 @@ static void print_symbols(const MOJOSHADER_symbol *sym, } // print_symbols +static void print_preshader_operand(const MOJOSHADER_preshader *preshader, + const int instidx, const int opidx) +{ + static char mask[] = { 'x', 'y', 'z', 'w' }; + const MOJOSHADER_preshaderInstruction *inst = &preshader->instructions[instidx]; + const MOJOSHADER_preshaderOperand *operand = &inst->operands[opidx]; + const int elems = inst->element_count; + const int isscalarop = (inst->opcode >= MOJOSHADER_PRESHADEROP_SCALAR_OPS); + const int isscalar = ((isscalarop) && (opidx == 1)); // probably wrong. + int i; + + switch (operand->type) + { + case MOJOSHADER_PRESHADEROPERAND_LITERAL: + { + const double *lit = &preshader->literals[operand->index]; + printf("("); + if (isscalar) + { + const double val = *lit; + for (i = 0; i < elems-1; i++) + printf("%g, ", val); + printf("%g)", val); + } // if + else + { + for (i = 0; i < elems-1; i++, lit++) + printf("%g, ", *lit); + printf("%g)", *lit); + } // else + break; + } // case + + case MOJOSHADER_PRESHADEROPERAND_INPUT: + case MOJOSHADER_PRESHADEROPERAND_OUTPUT: + case MOJOSHADER_PRESHADEROPERAND_TEMP: + { + int idx = operand->index % 4; + char regch = 'c'; + if (operand->type == MOJOSHADER_PRESHADEROPERAND_TEMP) + regch = 'r'; + + printf("%c%d", regch, operand->index / 4); + if (isscalar) + printf(".%c", mask[idx]); + else if (elems != 4) + { + printf("."); + for (i = 0; i < elems; i++) + printf("%c", mask[idx++]); + } // else if + break; + } // case + + default: + printf("[???{%d, %u}???]", (int) operand->type, operand->index); + break; + } // switch +} // print_preshader_operand + + static void print_preshader(const MOJOSHADER_preshader *preshader, const int indent) { MOJOSHADER_preshaderInstruction *inst = preshader->instructions; - int i, j, k; + int i, j; static const char *opcodestr[] = { "nop", "mov", "neg", "rcp", "frc", "exp", "log", "rsq", "sin", "cos", @@ -148,77 +209,22 @@ static void print_preshader(const MOJOSHADER_preshader *preshader, "ge", "add", "mul", "atan2", "div", "dot", "noise" }; - static char mask[] = { 'x', 'y', 'z', 'w' }; - INDENT(); printf("PRESHADER:\n"); print_symbols(preshader->symbols, preshader->symbol_count, indent + 1); for (i = 0; i < preshader->instruction_count; i++, inst++) { - const MOJOSHADER_preshaderOperand *operand = inst->operands; - const int scalarstart = (int) MOJOSHADER_PRESHADEROP_SCALAR_OPS; - const int isscalarop = (inst->opcode >= scalarstart); + INDENT(); printf(" %s ", opcodestr[inst->opcode]); - INDENT(); printf(" %s", opcodestr[inst->opcode]); + // print dest register first... + print_preshader_operand(preshader, i, inst->operand_count - 1); - for (j = 0; j < inst->operand_count; j++, operand++) + // ...then the source registers. + for (j = 0; j < inst->operand_count - 1; j++) { - const int elems = inst->element_count; - const int isscalar = ((isscalarop) && (j == 1)); // probably wrong. - - if (j != 0) - printf(","); - printf(" "); - - switch (operand->type) - { - case MOJOSHADER_PRESHADEROPERAND_LITERAL: - { - const double *lit = &preshader->literals[operand->index]; - printf("("); - if (isscalar) - { - const double val = *lit; - for (k = 0; k < elems-1; k++) - printf("%g, ", val); - printf("%g)", val); - } // if - else - { - for (k = 0; k < elems-1; k++, lit++) - printf("%g, ", *lit); - printf("%g)", *lit); - } // else - break; - } // case - - case MOJOSHADER_PRESHADEROPERAND_INPUT: - case MOJOSHADER_PRESHADEROPERAND_OUTPUT: - case MOJOSHADER_PRESHADEROPERAND_TEMP: - { - int idx = operand->index % 4; - char regch = 'c'; - if (operand->type == MOJOSHADER_PRESHADEROPERAND_TEMP) - regch = 'r'; - - printf("%c%d", regch, operand->index / 4); - if (isscalar) - printf(".%c", mask[idx]); - else if (elems != 4) - { - printf("."); - for (k = 0; k < elems; k++) - printf("%c", mask[idx++]); - } // else if - break; - } // case - - default: - printf("[???{%d, %u}???]", - (int) operand->type, operand->index); - break; - } // switch + printf(", "); + print_preshader_operand(preshader, i, j); } // for printf("\n");