mojoshader_assembler.c
changeset 1290 2febe5ae83ad
parent 1288 259d3bba6b66
child 1291 db27fb09421a
equal deleted inserted replaced
1289:f47a47343dbc 1290:2febe5ae83ad
    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     uint8 default_writemask;
       
    59     uint8 default_swizzle;
    59     Buffer *output;
    60     Buffer *output;
    60     Buffer *token_to_source;
    61     Buffer *token_to_source;
    61     Buffer *ctab;
    62     Buffer *ctab;
    62 } Context;
    63 } Context;
    63 
    64 
   639 
   640 
   640 static int parse_source_token_maybe_relative(Context *ctx, const int relok)
   641 static int parse_source_token_maybe_relative(Context *ctx, const int relok)
   641 {
   642 {
   642     int retval = 1;
   643     int retval = 1;
   643 
   644 
       
   645     // If we've set a weird default swizzle, save it off and then go back to
       
   646     //  the default, so it won't reuse the setting for relative addressing
       
   647     //  processing. We only need a weird default for a handful of instructions.
       
   648     const uint8 default_swizzle = ctx->default_swizzle;
       
   649     ctx->default_swizzle = 0xE4;  // 0xE4 == 11100100 ... 0 1 2 3. No swizzle.
       
   650 
   644     if (tokenbuf_overflow(ctx))
   651     if (tokenbuf_overflow(ctx))
   645         return 0;
   652         return 0;
   646 
   653 
   647     // mark this now, so optional relative addressing token is placed second.
   654     // mark this now, so optional relative addressing token is placed second.
   648     uint32 *outtoken = &ctx->tokenbuf[ctx->tokenbufpos++];
   655     uint32 *outtoken = &ctx->tokenbuf[ctx->tokenbufpos++];
   757 
   764 
   758     int invalid_swizzle = 0;
   765     int invalid_swizzle = 0;
   759     uint32 swizzle = 0;
   766     uint32 swizzle = 0;
   760     if (nexttoken(ctx) != ((Token) '.'))
   767     if (nexttoken(ctx) != ((Token) '.'))
   761     {
   768     {
   762         swizzle = 0xE4;  // 0xE4 == 11100100 ... 0 1 2 3. No swizzle.
   769         swizzle = default_swizzle;
   763         pushback(ctx);  // no explicit writemask; do full mask.
   770         pushback(ctx);  // no explicit swizzle; use the default.
   764     } // if
   771     } // if
   765     else if (scalar_register(ctx->shader_type, regtype, regnum))
   772     else if (scalar_register(ctx->shader_type, regtype, regnum))
   766         fail(ctx, "Swizzle specified for scalar register");
   773         fail(ctx, "Swizzle specified for scalar register");
   767     else if (nexttoken(ctx) != TOKEN_IDENTIFIER)
   774     else if (nexttoken(ctx) != TOKEN_IDENTIFIER)
   768         invalid_swizzle = 1;
   775         invalid_swizzle = 1;
  1244 
  1251 
  1245     // !!! FIXME: predicated instructions
  1252     // !!! FIXME: predicated instructions
  1246 
  1253 
  1247     ctx->tokenbufpos = 0;
  1254     ctx->tokenbufpos = 0;
  1248     ctx->default_writemask = instruction->default_writemask;
  1255     ctx->default_writemask = instruction->default_writemask;
       
  1256 
       
  1257     if (opcode == OPCODE_RCP)  // RCP has an implicit swizzle of .xxxx if not specified.
       
  1258         ctx->default_swizzle = 0;  // .xxxx replicate swizzle.
  1249 
  1259 
  1250     const int tokcount = instruction->parse_args(ctx);
  1260     const int tokcount = instruction->parse_args(ctx);
  1251 
  1261 
  1252     // insttoks bits are reserved and should be zero if < SM2.
  1262     // insttoks bits are reserved and should be zero if < SM2.
  1253     const uint32 insttoks = shader_version_atleast(ctx, 2, 0) ? tokcount-1 : 0;
  1263     const uint32 insttoks = shader_version_atleast(ctx, 2, 0) ? tokcount-1 : 0;