mojoshader.c
changeset 1139 8cda6a463824
parent 1131 133cf29e30ed
child 1143 e4027cbe2116
equal deleted inserted replaced
1138:119bbce82c8d 1139:8cda6a463824
  6483     if (info->relative)
  6483     if (info->relative)
  6484     {
  6484     {
  6485         if ( (shader_is_pixel(ctx)) && (!shader_version_atleast(ctx, 3, 0)) )
  6485         if ( (shader_is_pixel(ctx)) && (!shader_version_atleast(ctx, 3, 0)) )
  6486             fail(ctx, "Relative addressing in pixel shader version < 3.0");
  6486             fail(ctx, "Relative addressing in pixel shader version < 3.0");
  6487 
  6487 
  6488         const uint32 reltoken = SWAP32(*(ctx->tokens));
  6488         // Shader Model 1 doesn't have an extra token to specify the
  6489         // swallow token for now, for multiple calls in a row.
  6489         //  relative register: it's always a0.x.
  6490         adjust_token_position(ctx, 1);
  6490         if (!shader_version_atleast(ctx, 2, 0))
  6491 
  6491         {
  6492         const int relswiz = (int) ((reltoken >> 16) & 0xFF);
  6492             info->relative_regnum = 0;
  6493         info->relative_regnum = (int) (reltoken & 0x7ff);
  6493             info->relative_regtype = REG_TYPE_ADDRESS;
  6494         info->relative_regtype = (RegisterType)
  6494             info->relative_component = 0;
  6495                                     (((reltoken >> 28) & 0x7) |
  6495         } // if
  6496                                     ((reltoken >> 8) & 0x18));
  6496 
  6497 
  6497         else  // Shader Model 2 and later...
  6498         if (((reltoken >> 31) & 0x1) == 0)
  6498         {
  6499             fail(ctx, "bit #31 in relative address must be set");
  6499             const uint32 reltoken = SWAP32(*(ctx->tokens));
  6500 
  6500             // swallow token for now, for multiple calls in a row.
  6501         if ((reltoken & 0xF00E000) != 0)  // usused bits.
  6501             adjust_token_position(ctx, 1);
  6502             fail(ctx, "relative address reserved bit must be zero");
  6502 
  6503 
  6503             const int relswiz = (int) ((reltoken >> 16) & 0xFF);
  6504         switch (info->relative_regtype)
  6504             info->relative_regnum = (int) (reltoken & 0x7ff);
  6505         {
  6505             info->relative_regtype = (RegisterType)
  6506             case REG_TYPE_LOOP:
  6506                                         (((reltoken >> 28) & 0x7) |
  6507             case REG_TYPE_ADDRESS:
  6507                                         ((reltoken >> 8) & 0x18));
  6508                 break;
  6508 
  6509             default:
  6509             if (((reltoken >> 31) & 0x1) == 0)
       
  6510                 fail(ctx, "bit #31 in relative address must be set");
       
  6511 
       
  6512             if ((reltoken & 0xF00E000) != 0)  // usused bits.
       
  6513                 fail(ctx, "relative address reserved bit must be zero");
       
  6514 
       
  6515             switch (info->relative_regtype)
       
  6516             {
       
  6517                 case REG_TYPE_LOOP:
       
  6518                 case REG_TYPE_ADDRESS:
       
  6519                     break;
       
  6520                 default:
       
  6521                     fail(ctx, "invalid register for relative address");
       
  6522                     break;
       
  6523             } // switch
       
  6524 
       
  6525             if (info->relative_regnum != 0)  // true for now.
  6510                 fail(ctx, "invalid register for relative address");
  6526                 fail(ctx, "invalid register for relative address");
  6511                 break;
  6527 
  6512         } // switch
  6528             if (!replicate_swizzle(relswiz))
  6513 
  6529                 fail(ctx, "relative address needs replicate swizzle");
  6514         if (info->relative_regnum != 0)  // true for now.
  6530 
  6515             fail(ctx, "invalid register for relative address");
  6531             info->relative_component = (relswiz & 0x3);
  6516 
  6532 
  6517         if (!replicate_swizzle(relswiz))
  6533             retval++;
  6518             fail(ctx, "relative address needs replicate swizzle");
  6534         } // else
  6519 
       
  6520         info->relative_component = (relswiz & 0x3);
       
  6521 
  6535 
  6522         if (info->regtype == REG_TYPE_INPUT)
  6536         if (info->regtype == REG_TYPE_INPUT)
  6523         {
  6537         {
  6524             if ( (shader_is_pixel(ctx)) || (!shader_version_atleast(ctx, 3, 0)) )
  6538             if ( (shader_is_pixel(ctx)) || (!shader_version_atleast(ctx, 3, 0)) )
  6525                 fail(ctx, "relative addressing of input registers not supported in this shader model");
  6539                 fail(ctx, "relative addressing of input registers not supported in this shader model");
  6558         } // else if
  6572         } // else if
  6559         else
  6573         else
  6560         {
  6574         {
  6561             fail(ctx, "relative addressing of invalid register");
  6575             fail(ctx, "relative addressing of invalid register");
  6562         } // else
  6576         } // else
  6563 
       
  6564         retval++;
       
  6565     } // if
  6577     } // if
  6566 
  6578 
  6567     switch (info->src_mod)
  6579     switch (info->src_mod)
  6568     {
  6580     {
  6569         case SRCMOD_NONE:
  6581         case SRCMOD_NONE: