mojoshader.c
branchtrunk
changeset 154 ebd0921fdd39
parent 152 cc7c38dfe145
child 155 d078e6be5a39
equal deleted inserted replaced
153:4410cc03dade 154:ebd0921fdd39
  1410     const char *dst0 = make_D3D_destarg_string(ctx, 0);
  1410     const char *dst0 = make_D3D_destarg_string(ctx, 0);
  1411     const DestArgInfo *arg = &ctx->dest_args[0];
  1411     const DestArgInfo *arg = &ctx->dest_args[0];
  1412     const char *usage_str = "";
  1412     const char *usage_str = "";
  1413     char index_str[16] = { '\0' };
  1413     char index_str[16] = { '\0' };
  1414 
  1414 
  1415     if (shader_is_vertex(ctx))
  1415     if (arg->regtype == REG_TYPE_SAMPLER)
       
  1416     {
       
  1417         const TextureType ttype = (const TextureType) ctx->dwords[0];
       
  1418         switch (ttype)
       
  1419         {
       
  1420             case TEXTURE_TYPE_2D: usage_str = "_2d"; break;
       
  1421             case TEXTURE_TYPE_CUBE: usage_str = "_cube"; break;
       
  1422             case TEXTURE_TYPE_VOLUME: usage_str = "_volume"; break;
       
  1423             default: fail(ctx, "unknown sampler texture type"); return;
       
  1424         } // switch
       
  1425     } // if
       
  1426 
       
  1427     else
  1416     {
  1428     {
  1417         const uint32 usage = ctx->dwords[0];
  1429         const uint32 usage = ctx->dwords[0];
  1418         const uint32 index = ctx->dwords[1];
  1430         const uint32 index = ctx->dwords[1];
  1419         usage_str = usagestrs[usage];
  1431         usage_str = usagestrs[usage];
  1420         if (index != 0)
  1432         if (index != 0)
  1421             snprintf(index_str, sizeof (index_str), "%u", (uint) index);
  1433             snprintf(index_str, sizeof (index_str), "%u", (uint) index);
  1422     } // if
  1434     } // else
  1423 
       
  1424     else if (shader_is_pixel(ctx))
       
  1425     {
       
  1426         if (arg->regtype == REG_TYPE_SAMPLER)
       
  1427         {
       
  1428             const TextureType ttype = (const TextureType) ctx->dwords[0];
       
  1429             switch (ttype)
       
  1430             {
       
  1431                 case TEXTURE_TYPE_2D: usage_str = "_2d"; break;
       
  1432                 case TEXTURE_TYPE_CUBE: usage_str = "_cube"; break;
       
  1433                 case TEXTURE_TYPE_VOLUME: usage_str = "_volume"; break;
       
  1434                 default: fail(ctx, "unknown sampler texture type"); return;
       
  1435             } // switch
       
  1436         } // if
       
  1437     } // else if
       
  1438 
  1435 
  1439     output_line(ctx, "dcl%s%s%s", usage_str, index_str, dst0);
  1436     output_line(ctx, "dcl%s%s%s", usage_str, index_str, dst0);
  1440 } // emit_D3D_DCL
  1437 } // emit_D3D_DCL
  1441 
  1438 
  1442 
  1439 
  3172 
  3169 
  3173     return 3;
  3170     return 3;
  3174 } // parse_args_DEFB
  3171 } // parse_args_DEFB
  3175 
  3172 
  3176 
  3173 
       
  3174 // !!! FIXME: this function is kind of a mess.
  3177 static int parse_args_DCL(Context *ctx)
  3175 static int parse_args_DCL(Context *ctx)
  3178 {
  3176 {
  3179     int unsupported = 0;
  3177     int unsupported = 0;
  3180     const uint32 token = SWAP32(*(ctx->tokens));
  3178     const uint32 token = SWAP32(*(ctx->tokens));
  3181     const int reserved1 = (int) ((token >> 31) & 0x1); // bit 31
  3179     const int reserved1 = (int) ((token >> 31) & 0x1); // bit 31
  3195     const RegisterType regtype = ctx->dest_args[0].regtype;
  3193     const RegisterType regtype = ctx->dest_args[0].regtype;
  3196     const int regnum = ctx->dest_args[0].regnum;
  3194     const int regnum = ctx->dest_args[0].regnum;
  3197     if ( (shader_is_pixel(ctx)) && (shader_version_atleast(ctx, 3, 0)) )
  3195     if ( (shader_is_pixel(ctx)) && (shader_version_atleast(ctx, 3, 0)) )
  3198     {
  3196     {
  3199         if (regtype == REG_TYPE_INPUT)
  3197         if (regtype == REG_TYPE_INPUT)
  3200             reserved_mask = 0x7FFFFFFF;
  3198         {
       
  3199             const uint32 usage = (token & 0xF);
       
  3200             const uint32 index = ((token >> 16) & 0xF);
       
  3201             reserved_mask = 0x7FF0FFE0;
       
  3202             ctx->dwords[0] = usage;
       
  3203             ctx->dwords[1] = index;
       
  3204         } // if
  3201 
  3205 
  3202         else if (regtype == REG_TYPE_MISCTYPE)
  3206         else if (regtype == REG_TYPE_MISCTYPE)
  3203         {
  3207         {
  3204             const MiscTypeType mt = (MiscTypeType) regnum;
  3208             const MiscTypeType mt = (MiscTypeType) regnum;
  3205             if (mt == MISCTYPE_TYPE_POSITION)
  3209             if (mt == MISCTYPE_TYPE_POSITION)