Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Found, I think, the final preshader opcodes.
I wrote a goofy program to edit a file, run it through fxc.exe /dumpbin,
 and diff the results to automate the search.

#include <stdio.h>
#include <stdlib.h>

#define FNAME "test.fxc"
#define OFFSET 7804
#define STARTVAL 0xA000

int main(void)
{
    system("./fxc.exe /nologo /Tfx_2_0 /dumpbin " FNAME " >dump.txt");

    int i = STARTVAL;
    for (i = STARTVAL; i < STARTVAL+0x100; i += 0x10)
    {
        FILE *io = fopen(FNAME, "r+b");
        if (io == NULL)
            return 1;
        fseek(io, OFFSET, SEEK_SET);
        const unsigned short y = 0x0001;
        fwrite(&y, sizeof (y), 1, io);
        const unsigned short x = (unsigned short) i;
        fwrite(&x, sizeof (x), 1, io);
        fflush(io);
        fclose(io);
        system("./fxc.exe /nologo /Tfx_2_0 /dumpbin " FNAME " >dump2.txt");
        fprintf(stderr, "0x%X ... \n", i);
        system("diff -u dump.txt dump2.txt 1>&2");
    }

    return 0;
}
  • Loading branch information
icculus committed May 31, 2011
1 parent fa99a49 commit c782028
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions mojoshader.c
Expand Up @@ -7281,7 +7281,9 @@ static void parse_preshader(Context *ctx, uint32 tokcount)
case 0x2060: opcode = MOJOSHADER_PRESHADEROP_ATAN2; break;
case 0x2080: opcode = MOJOSHADER_PRESHADEROP_DIV; break;
case 0x3000: opcode = MOJOSHADER_PRESHADEROP_CMP; break;
case 0x3010: opcode = MOJOSHADER_PRESHADEROP_MOVC; break;
case 0x5000: opcode = MOJOSHADER_PRESHADEROP_DOT; break;
case 0x5020: opcode = MOJOSHADER_PRESHADEROP_NOISE; break;
case 0xA000: opcode = MOJOSHADER_PRESHADEROP_MIN_SCALAR; break;
case 0xA010: opcode = MOJOSHADER_PRESHADEROP_MAX_SCALAR; break;
case 0xA020: opcode = MOJOSHADER_PRESHADEROP_CMPLT_SCALAR; break;
Expand All @@ -7291,6 +7293,7 @@ static void parse_preshader(Context *ctx, uint32 tokcount)
case 0xA060: opcode = MOJOSHADER_PRESHADEROP_ATAN2_SCALAR; break;
case 0xA080: opcode = MOJOSHADER_PRESHADEROP_DIV_SCALAR; break;
case 0xD000: opcode = MOJOSHADER_PRESHADEROP_DOT_SCALAR; break;
case 0xD020: opcode = MOJOSHADER_PRESHADEROP_NOISE_SCALAR; break;
default: fail(ctx, "Unknown preshader opcode."); break;
} // switch

Expand Down
3 changes: 3 additions & 0 deletions mojoshader.h
Expand Up @@ -379,7 +379,9 @@ typedef enum MOJOSHADER_preshaderOpcode
MOJOSHADER_PRESHADEROP_ATAN2,
MOJOSHADER_PRESHADEROP_DIV,
MOJOSHADER_PRESHADEROP_CMP,
MOJOSHADER_PRESHADEROP_MOVC,
MOJOSHADER_PRESHADEROP_DOT,
MOJOSHADER_PRESHADEROP_NOISE,
MOJOSHADER_PRESHADEROP_SCALAR_OPS,
MOJOSHADER_PRESHADEROP_MIN_SCALAR = MOJOSHADER_PRESHADEROP_SCALAR_OPS,
MOJOSHADER_PRESHADEROP_MAX_SCALAR,
Expand All @@ -390,6 +392,7 @@ typedef enum MOJOSHADER_preshaderOpcode
MOJOSHADER_PRESHADEROP_ATAN2_SCALAR,
MOJOSHADER_PRESHADEROP_DIV_SCALAR,
MOJOSHADER_PRESHADEROP_DOT_SCALAR,
MOJOSHADER_PRESHADEROP_NOISE_SCALAR,
} MOJOSHADER_preshaderOpcode;

typedef enum MOJOSHADER_preshaderOperandType
Expand Down
6 changes: 3 additions & 3 deletions utils/testparse.c
Expand Up @@ -115,9 +115,9 @@ static void print_preshader(const MOJOSHADER_preshader *preshader,

static const char *opcodestr[] = {
"nop", "mov", "neg", "rcp", "frc", "exp", "log", "rsq", "sin", "cos",
"asin", "acos", "atan", "min", "max", "cmplt", "cmpge", "add", "mul",
"atan2", "div", "cmp", "dot", "min", "max", "cmplt", "cmpge", "add",
"mul", "atan2", "div", "dot"
"asin", "acos", "atan", "min", "max", "lt", "ge", "add", "mul",
"atan2", "div", "cmp", "movc", "dot", "noise", "min", "max", "lt",
"ge", "add", "mul", "atan2", "div", "dot", "noise"
};

static char mask[] = { 'x', 'y', 'z', 'w' };
Expand Down

0 comments on commit c782028

Please sign in to comment.