mojoshader.c
branchtrunk
changeset 292 f6c1a2ec6030
parent 291 2453590bae1b
child 293 57ccf4911b77
equal deleted inserted replaced
291:2453590bae1b 292:f6c1a2ec6030
   752              (((swizzle >> 2) & 0x3) == ((swizzle >> 4) & 0x3)) &&
   752              (((swizzle >> 2) & 0x3) == ((swizzle >> 4) & 0x3)) &&
   753              (((swizzle >> 4) & 0x3) == ((swizzle >> 6) & 0x3)) );
   753              (((swizzle >> 4) & 0x3) == ((swizzle >> 6) & 0x3)) );
   754 } // replicate_swizzle
   754 } // replicate_swizzle
   755 
   755 
   756 
   756 
       
   757 static inline int no_swizzle(const int swizzle)
       
   758 {
       
   759     return (swizzle != 0xE4);  // 0xE4 == 11100100 ... 0 1 2 3. No swizzle.
       
   760 } // no_swizzle
       
   761 
       
   762 
   757 static inline int vecsize_from_writemask(const int m)
   763 static inline int vecsize_from_writemask(const int m)
   758 {
   764 {
   759     return (m & 1) + ((m >> 1) & 1) + ((m >> 2) & 1) + ((m >> 3) & 1);
   765     return (m & 1) + ((m >> 1) & 1) + ((m >> 2) & 1) + ((m >> 3) & 1);
   760 } // vecsize_from_writemask
   766 } // vecsize_from_writemask
   761 
   767 
   995         } // if
  1001         } // if
   996     } // if
  1002     } // if
   997 
  1003 
   998     char swizzle_str[6];
  1004     char swizzle_str[6];
   999     int i = 0;
  1005     int i = 0;
  1000     if (arg->swizzle != 0xE4)  // 0xE4 == 11100100 ... 3 2 1 0. No swizzle.
  1006     if (no_swizzle(arg->swizzle))
  1001     {
  1007     {
  1002         swizzle_str[i++] = '.';
  1008         swizzle_str[i++] = '.';
  1003         swizzle_str[i++] = swizzle_channels[arg->swizzle_x];
  1009         swizzle_str[i++] = swizzle_channels[arg->swizzle_x];
  1004         swizzle_str[i++] = swizzle_channels[arg->swizzle_y];
  1010         swizzle_str[i++] = swizzle_channels[arg->swizzle_y];
  1005         swizzle_str[i++] = swizzle_channels[arg->swizzle_z];
  1011         swizzle_str[i++] = swizzle_channels[arg->swizzle_z];
  1892         } // if
  1898         } // if
  1893     } // if
  1899     } // if
  1894 
  1900 
  1895     char swiz_str[6];
  1901     char swiz_str[6];
  1896     int i = 0;
  1902     int i = 0;
  1897     // 0xE4 == 11100100 ... 3 2 1 0. No swizzle.
  1903     if ( (no_swizzle(arg->swizzle)) || (writemask != 0xF) )
  1898     if ((arg->swizzle != 0xE4) || (writemask != 0xF))
       
  1899     {
  1904     {
  1900         swiz_str[i++] = '.';
  1905         swiz_str[i++] = '.';
  1901         if (writemask0) swiz_str[i++] = swizzle_channels[arg->swizzle_x];
  1906         if (writemask0) swiz_str[i++] = swizzle_channels[arg->swizzle_x];
  1902         if (writemask1) swiz_str[i++] = swizzle_channels[arg->swizzle_y];
  1907         if (writemask1) swiz_str[i++] = swizzle_channels[arg->swizzle_y];
  1903         if (writemask2) swiz_str[i++] = swizzle_channels[arg->swizzle_z];
  1908         if (writemask2) swiz_str[i++] = swizzle_channels[arg->swizzle_z];
  3368 static int parse_predicated_token(Context *ctx)
  3373 static int parse_predicated_token(Context *ctx)
  3369 {
  3374 {
  3370     SourceArgInfo *arg = &ctx->predicate_arg;
  3375     SourceArgInfo *arg = &ctx->predicate_arg;
  3371     if (parse_source_token(ctx, arg) == FAIL)
  3376     if (parse_source_token(ctx, arg) == FAIL)
  3372         return FAIL;
  3377         return FAIL;
  3373     if (arg->regtype != REG_TYPE_PREDICATE)
  3378     else if (arg->regtype != REG_TYPE_PREDICATE)
  3374         return fail(ctx, "Predicated instruction but not predicate register!");
  3379         return fail(ctx, "Predicated instruction but not predicate register!");
  3375     if ((arg->src_mod != SRCMOD_NONE) && (arg->src_mod != SRCMOD_NOT))
  3380     else if ((arg->src_mod != SRCMOD_NONE) && (arg->src_mod != SRCMOD_NOT))
  3376         return fail(ctx, "Predicated instruction register is not NONE or NOT");
  3381         return fail(ctx, "Predicated instruction register is not NONE or NOT");
  3377 
  3382     else if ( no_swizzle(arg->swizzle) && !replicate_swizzle(arg->swizzle) )
  3378     // 0xE4 == 11100100 ... 3 2 1 0. No swizzle.
       
  3379     if ( (arg->swizzle != 0xE4) && (!replicate_swizzle(arg->swizzle)) )
       
  3380         return fail(ctx, "Predicated instruction register has wrong swizzle");
  3383         return fail(ctx, "Predicated instruction register has wrong swizzle");
  3381 
  3384     else if (arg->relative)  // I'm pretty sure this is illegal...?
  3382     if (arg->relative)  // I'm pretty sure this is illegal...?
       
  3383         return fail(ctx, "relative addressing in predicated token");
  3385         return fail(ctx, "relative addressing in predicated token");
  3384 
  3386 
  3385     return 1;
  3387     return 1;
  3386 } // parse_predicated_token
  3388 } // parse_predicated_token
  3387 
  3389 
  4169 
  4171 
  4170     // !!! FIXME: "If a temporary register is used, all components must have been previously written."
  4172     // !!! FIXME: "If a temporary register is used, all components must have been previously written."
  4171     // !!! FIXME: "If a texture register is used, all components that are read must have been declared."
  4173     // !!! FIXME: "If a texture register is used, all components that are read must have been declared."
  4172     // !!! FIXME: there are further limitations in ps_1_3 and earlier.
  4174     // !!! FIXME: there are further limitations in ps_1_3 and earlier.
  4173 } // state_TEXKILL
  4175 } // state_TEXKILL
       
  4176 
       
  4177 static void state_TEXLD(Context *ctx)
       
  4178 {
       
  4179     if (shader_version_atleast(ctx, 2, 0))
       
  4180     {
       
  4181         const SourceArgInfo *src0 = &ctx->source_args[0];
       
  4182         const SourceArgInfo *src1 = &ctx->source_args[1];
       
  4183         const RegisterType rt0 = src0->regtype;
       
  4184         if (ctx->dest_arg.regtype != REG_TYPE_TEMP)
       
  4185             fail(ctx, "TEXLD dest must be a temp register");
       
  4186         else if ((rt0 != REG_TYPE_TEXTURE) && (rt0 != REG_TYPE_TEMP))
       
  4187             fail(ctx, "TEXLD src0 must be texture or temp register");
       
  4188         else if (src0->src_mod != SRCMOD_NONE)
       
  4189             fail(ctx, "TEXLD src0 must have no modifiers");
       
  4190         else if (src1->regtype != REG_TYPE_SAMPLER)
       
  4191             fail(ctx, "TEXLD src1 must be sampler register");
       
  4192         else if (src1->src_mod != SRCMOD_NONE)
       
  4193             fail(ctx, "TEXLD src0 must have no modifiers");
       
  4194 
       
  4195         // Shader Model 3 added swizzle support to this opcode.
       
  4196         if (!shader_version_atleast(ctx, 3, 0))
       
  4197         {
       
  4198             if (!no_swizzle(src0->swizzle))
       
  4199                 fail(ctx, "TEXLD src0 must not swizzle");
       
  4200             else if (!no_swizzle(src1->swizzle))
       
  4201                 fail(ctx, "TEXLD src1 must not swizzle");
       
  4202         } // if
       
  4203     } // if
       
  4204 
       
  4205     // !!! FIXME: checks for ps_1_4 and ps_1_0 versions...
       
  4206 } // state_TEXLD
  4174 
  4207 
  4175 static void state_DP2ADD(Context *ctx)
  4208 static void state_DP2ADD(Context *ctx)
  4176 {
  4209 {
  4177     if (!replicate_swizzle(ctx->source_args[2].swizzle))
  4210     if (!replicate_swizzle(ctx->source_args[2].swizzle))
  4178         fail(ctx, "IFC src2 must have replicate swizzle");
  4211         fail(ctx, "IFC src2 must have replicate swizzle");
  4270     INSTRUCTION(RESERVED, NULL, MOJOSHADER_TYPE_UNKNOWN),
  4303     INSTRUCTION(RESERVED, NULL, MOJOSHADER_TYPE_UNKNOWN),
  4271     INSTRUCTION(RESERVED, NULL, MOJOSHADER_TYPE_UNKNOWN),
  4304     INSTRUCTION(RESERVED, NULL, MOJOSHADER_TYPE_UNKNOWN),
  4272     INSTRUCTION(RESERVED, NULL, MOJOSHADER_TYPE_UNKNOWN),
  4305     INSTRUCTION(RESERVED, NULL, MOJOSHADER_TYPE_UNKNOWN),
  4273     INSTRUCTION_STATE(TEXCRD, TEXCRD, MOJOSHADER_TYPE_PIXEL),
  4306     INSTRUCTION_STATE(TEXCRD, TEXCRD, MOJOSHADER_TYPE_PIXEL),
  4274     INSTRUCTION_STATE(TEXKILL, D, MOJOSHADER_TYPE_PIXEL),
  4307     INSTRUCTION_STATE(TEXKILL, D, MOJOSHADER_TYPE_PIXEL),
  4275     INSTRUCTION(TEXLD, TEXLD, MOJOSHADER_TYPE_PIXEL),
  4308     INSTRUCTION_STATE(TEXLD, TEXLD, MOJOSHADER_TYPE_PIXEL),
  4276     INSTRUCTION(TEXBEM, DS, MOJOSHADER_TYPE_PIXEL),
  4309     INSTRUCTION(TEXBEM, DS, MOJOSHADER_TYPE_PIXEL),
  4277     INSTRUCTION(TEXBEML, DS, MOJOSHADER_TYPE_PIXEL),
  4310     INSTRUCTION(TEXBEML, DS, MOJOSHADER_TYPE_PIXEL),
  4278     INSTRUCTION(TEXREG2AR, DS, MOJOSHADER_TYPE_PIXEL),
  4311     INSTRUCTION(TEXREG2AR, DS, MOJOSHADER_TYPE_PIXEL),
  4279     INSTRUCTION(TEXREG2GB, DS, MOJOSHADER_TYPE_PIXEL),
  4312     INSTRUCTION(TEXREG2GB, DS, MOJOSHADER_TYPE_PIXEL),
  4280     INSTRUCTION(TEXM3X2PAD, DS, MOJOSHADER_TYPE_PIXEL),
  4313     INSTRUCTION(TEXM3X2PAD, DS, MOJOSHADER_TYPE_PIXEL),