Skip to content

Commit

Permalink
Place preshader destination register last in operand list.
Browse files Browse the repository at this point in the history
This is where it's located in the shader, and it simplies some things.
  • Loading branch information
icculus committed Jun 1, 2011
1 parent 9a647fa commit b2524a0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 70 deletions.
5 changes: 1 addition & 4 deletions mojoshader.c
Expand Up @@ -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]))
{
Expand Down
5 changes: 2 additions & 3 deletions mojoshader_effects.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
132 changes: 69 additions & 63 deletions utils/testparse.c
Expand Up @@ -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",
Expand All @@ -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");
Expand Down

0 comments on commit b2524a0

Please sign in to comment.