mojoshader_assembler.c
changeset 1287 c5a53296dbd5
parent 1285 1952246ec6cd
child 1288 259d3bba6b66
equal deleted inserted replaced
1286:d9e3872a055e 1287:c5a53296dbd5
    53     Token tokenval;         // assembler token!
    53     Token tokenval;         // assembler token!
    54     uint32 version_token;   // bytecode token!
    54     uint32 version_token;   // bytecode token!
    55     uint32 tokenbuf[16];    // bytecode tokens!
    55     uint32 tokenbuf[16];    // bytecode tokens!
    56     int tokenbufpos;        // bytecode tokens!
    56     int tokenbufpos;        // bytecode tokens!
    57     DestArgInfo dest_arg;
    57     DestArgInfo dest_arg;
       
    58     uint8 default_writemask;
    58     Buffer *output;
    59     Buffer *output;
    59     Buffer *token_to_source;
    60     Buffer *token_to_source;
    60     Buffer *ctab;
    61     Buffer *ctab;
    61 } Context;
    62 } Context;
    62 
    63 
   550     // !!! FIXME: can dest registers do relative addressing?
   551     // !!! FIXME: can dest registers do relative addressing?
   551 
   552 
   552     int invalid_writemask = 0;
   553     int invalid_writemask = 0;
   553     if (nexttoken(ctx) != ((Token) '.'))
   554     if (nexttoken(ctx) != ((Token) '.'))
   554     {
   555     {
   555         info->writemask = 0xF;
   556         info->writemask = ctx->default_writemask;
   556         info->writemask0 = info->writemask1 = info->writemask2 = info->writemask3 = 1;
   557         info->writemask0 = ((info->writemask >> 0) & 0x1);
       
   558         info->writemask1 = ((info->writemask >> 1) & 0x1);
       
   559         info->writemask2 = ((info->writemask >> 2) & 0x1);
       
   560         info->writemask3 = ((info->writemask >> 3) & 0x1);
   557         pushback(ctx);  // no explicit writemask; do full mask.
   561         pushback(ctx);  // no explicit writemask; do full mask.
   558     } // if
   562     } // if
   559     else if (nexttoken(ctx) != TOKEN_IDENTIFIER)
   563     else if (nexttoken(ctx) != TOKEN_IDENTIFIER)
   560     {
   564     {
   561         invalid_writemask = 1;
   565         invalid_writemask = 1;
  1105 
  1109 
  1106 // Lookup table for instruction opcodes...
  1110 // Lookup table for instruction opcodes...
  1107 typedef struct
  1111 typedef struct
  1108 {
  1112 {
  1109     const char *opcode_string;
  1113     const char *opcode_string;
       
  1114     const uint8 default_writemask;
  1110     args_function parse_args;
  1115     args_function parse_args;
  1111 } Instruction;
  1116 } Instruction;
  1112 
  1117 
  1113 
  1118 
  1114 static const Instruction instructions[] =
  1119 static const Instruction instructions[] =
  1115 {
  1120 {
  1116     #define INSTRUCTION_STATE(op, opstr, s, a, t) { opstr, parse_args_##a },
  1121     #define INSTRUCTION_STATE(op, opstr, s, a, t, w) { opstr, w, parse_args_##a },
  1117     #define INSTRUCTION(op, opstr, slots, a, t) { opstr, parse_args_##a },
  1122     #define INSTRUCTION(op, opstr, slots, a, t, w) { opstr, w, parse_args_##a },
  1118     #define MOJOSHADER_DO_INSTRUCTION_TABLE 1
  1123     #define MOJOSHADER_DO_INSTRUCTION_TABLE 1
  1119     #include "mojoshader_internal.h"
  1124     #include "mojoshader_internal.h"
  1120 };
  1125 };
  1121 
  1126 
  1122 
  1127 
  1233     const Instruction *instruction = &instructions[opcode];
  1238     const Instruction *instruction = &instructions[opcode];
  1234 
  1239 
  1235     // !!! FIXME: predicated instructions
  1240     // !!! FIXME: predicated instructions
  1236 
  1241 
  1237     ctx->tokenbufpos = 0;
  1242     ctx->tokenbufpos = 0;
       
  1243     ctx->default_writemask = instruction->default_writemask;
  1238 
  1244 
  1239     const int tokcount = instruction->parse_args(ctx);
  1245     const int tokcount = instruction->parse_args(ctx);
  1240 
  1246 
  1241     // insttoks bits are reserved and should be zero if < SM2.
  1247     // insttoks bits are reserved and should be zero if < SM2.
  1242     const uint32 insttoks = shader_version_atleast(ctx, 2, 0) ? tokcount-1 : 0;
  1248     const uint32 insttoks = shader_version_atleast(ctx, 2, 0) ? tokcount-1 : 0;
  1446     memset(ctx, '\0', sizeof (Context));
  1452     memset(ctx, '\0', sizeof (Context));
  1447     ctx->malloc = m;
  1453     ctx->malloc = m;
  1448     ctx->free = f;
  1454     ctx->free = f;
  1449     ctx->malloc_data = d;
  1455     ctx->malloc_data = d;
  1450     ctx->current_position = MOJOSHADER_POSITION_BEFORE;
  1456     ctx->current_position = MOJOSHADER_POSITION_BEFORE;
       
  1457     ctx->default_writemask = 0xF;
  1451 
  1458 
  1452     const size_t outblk = sizeof (uint32) * 4 * 64; // 64 4-token instrs.
  1459     const size_t outblk = sizeof (uint32) * 4 * 64; // 64 4-token instrs.
  1453     ctx->output = buffer_create(outblk, MallocBridge, FreeBridge, ctx);
  1460     ctx->output = buffer_create(outblk, MallocBridge, FreeBridge, ctx);
  1454     if (ctx->output == NULL)
  1461     if (ctx->output == NULL)
  1455         goto build_context_failed;
  1462         goto build_context_failed;