mojoshader.c
changeset 1099 aef946714f39
parent 1098 ef8be3b15633
child 1100 d1c8e5a9dcd0
equal deleted inserted replaced
1098:ef8be3b15633 1099:aef946714f39
   150     int have_multi_color_outputs;
   150     int have_multi_color_outputs;
   151     int determined_constants_arrays;
   151     int determined_constants_arrays;
   152     int predicated;
   152     int predicated;
   153     int uses_pointsize;
   153     int uses_pointsize;
   154     int uses_fog;
   154     int uses_fog;
   155     int glsl_generated_lit_opcode;
   155     int glsl_generated_lit_helper;
   156     int glsl_generated_texldd_setup;
   156     int glsl_generated_texldd_setup;
       
   157     int glsl_generated_texm3x3spec_helper;
   157     int arb1_wrote_position;
   158     int arb1_wrote_position;
   158     int have_preshader;
   159     int have_preshader;
   159     int ignores_ctab;
   160     int ignores_ctab;
       
   161     int reset_texmpad;
       
   162     int texm3x2pad_dst0;
       
   163     int texm3x2pad_src0;
       
   164     int texm3x3pad_dst0;
       
   165     int texm3x3pad_src0;
       
   166     int texm3x3pad_dst1;
       
   167     int texm3x3pad_src1;
   160     MOJOSHADER_preshader *preshader;
   168     MOJOSHADER_preshader *preshader;
   161 
   169 
   162 #if SUPPORT_PROFILE_ARB1_NV
   170 #if SUPPORT_PROFILE_ARB1_NV
   163     int profile_supports_nv2;
   171     int profile_supports_nv2;
   164     int profile_supports_nv3;
   172     int profile_supports_nv3;
  2820 
  2828 
  2821 static void emit_GLSL_LIT_helper(Context *ctx)
  2829 static void emit_GLSL_LIT_helper(Context *ctx)
  2822 {
  2830 {
  2823     const char *maxp = "127.9961"; // value from the dx9 reference.
  2831     const char *maxp = "127.9961"; // value from the dx9 reference.
  2824 
  2832 
  2825     if (ctx->glsl_generated_lit_opcode)
  2833     if (ctx->glsl_generated_lit_helper)
  2826         return;
  2834         return;
  2827 
  2835 
  2828     ctx->glsl_generated_lit_opcode = 1;
  2836     ctx->glsl_generated_lit_helper = 1;
  2829 
  2837 
  2830     push_output(ctx, &ctx->helpers);
  2838     push_output(ctx, &ctx->helpers);
  2831     output_line(ctx, "vec4 LIT(const vec4 src)");
  2839     output_line(ctx, "vec4 LIT(const vec4 src)");
  2832     output_line(ctx, "{"); ctx->indent++;
  2840     output_line(ctx, "{"); ctx->indent++;
  2833     output_line(ctx,   "float power = clamp(src.w, -%s, %s);",maxp,maxp);
  2841     output_line(ctx,   "float power = clamp(src.w, -%s, %s);",maxp,maxp);
  2846 
  2854 
  2847 static void emit_GLSL_LIT(Context *ctx)
  2855 static void emit_GLSL_LIT(Context *ctx)
  2848 {
  2856 {
  2849     char src0[64]; make_GLSL_srcarg_string_full(ctx, 0, src0, sizeof (src0));
  2857     char src0[64]; make_GLSL_srcarg_string_full(ctx, 0, src0, sizeof (src0));
  2850     char code[128];
  2858     char code[128];
       
  2859     emit_GLSL_LIT_helper(ctx);
  2851     make_GLSL_destarg_assign(ctx, code, sizeof (code), "LIT(%s)", src0);
  2860     make_GLSL_destarg_assign(ctx, code, sizeof (code), "LIT(%s)", src0);
  2852     output_line(ctx, "%s", code);
  2861     output_line(ctx, "%s", code);
  2853     emit_GLSL_LIT_helper(ctx);
       
  2854 } // emit_GLSL_LIT
  2862 } // emit_GLSL_LIT
  2855 
  2863 
  2856 static void emit_GLSL_DST(Context *ctx)
  2864 static void emit_GLSL_DST(Context *ctx)
  2857 {
  2865 {
  2858     // !!! FIXME: needs to take ctx->dst_arg.writemask into account.
  2866     // !!! FIXME: needs to take ctx->dst_arg.writemask into account.
  3227         char sampler[64];
  3235         char sampler[64];
  3228         char code[128];
  3236         char code[128];
  3229 
  3237 
  3230         assert(!texldd);
  3238         assert(!texldd);
  3231 
  3239 
  3232         // Note that this code counts on the register not having swizzles, etc.
  3240         // !!! FIXME: this code counts on the register not having swizzles, etc.
  3233         get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
  3241         get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
  3234         get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
  3242         get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
  3235                                 sampler, sizeof (sampler));
  3243                                 sampler, sizeof (sampler));
  3236         make_GLSL_destarg_assign(ctx, code, sizeof (code),
  3244         make_GLSL_destarg_assign(ctx, code, sizeof (code),
  3237                                  "texture2D(%s, %s.xy)",
  3245                                  "texture2D(%s, %s.xy)",
  3351     char dst[64]; get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
  3359     char dst[64]; get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
  3352     char src[64]; get_GLSL_srcarg_varname(ctx, 0, src, sizeof (src));
  3360     char src[64]; get_GLSL_srcarg_varname(ctx, 0, src, sizeof (src));
  3353     char sampler[64];
  3361     char sampler[64];
  3354     char code[512];
  3362     char code[512];
  3355 
  3363 
  3356     // Note that this code counts on the register not having swizzles, etc.
  3364     // !!! FIXME: this code counts on the register not having swizzles, etc.
  3357     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
  3365     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
  3358                             sampler, sizeof (sampler));
  3366                             sampler, sizeof (sampler));
  3359 
  3367 
  3360     make_GLSL_destarg_assign(ctx, code, sizeof (code),
  3368     make_GLSL_destarg_assign(ctx, code, sizeof (code),
  3361         "texture2D(%s, vec2(%s.x + (%s_texbem.x * %s.x) + (%s_texbem.z * %s.y),"
  3369         "texture2D(%s, vec2(%s.x + (%s_texbem.x * %s.x) + (%s_texbem.z * %s.y),"
  3368 } // emit_GLSL_TEXBEM
  3376 } // emit_GLSL_TEXBEM
  3369 
  3377 
  3370 
  3378 
  3371 static void emit_GLSL_TEXBEML(Context *ctx)
  3379 static void emit_GLSL_TEXBEML(Context *ctx)
  3372 {
  3380 {
  3373     // Note that this code counts on the register not having swizzles, etc.
  3381     // !!! FIXME: this code counts on the register not having swizzles, etc.
  3374     DestArgInfo *info = &ctx->dest_arg;
  3382     DestArgInfo *info = &ctx->dest_arg;
  3375     char dst[64]; get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
  3383     char dst[64]; get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
  3376     char src[64]; get_GLSL_srcarg_varname(ctx, 0, src, sizeof (src));
  3384     char src[64]; get_GLSL_srcarg_varname(ctx, 0, src, sizeof (src));
  3377     char sampler[64];
  3385     char sampler[64];
  3378     char code[512];
  3386     char code[512];
  3392     output_line(ctx, "%s", code);
  3400     output_line(ctx, "%s", code);
  3393 } // emit_GLSL_TEXBEML
  3401 } // emit_GLSL_TEXBEML
  3394 
  3402 
  3395 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2AR) // !!! FIXME
  3403 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2AR) // !!! FIXME
  3396 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2GB) // !!! FIXME
  3404 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2GB) // !!! FIXME
  3397 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2PAD) // !!! FIXME
  3405 
  3398 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2TEX) // !!! FIXME
  3406 
  3399 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3PAD) // !!! FIXME
  3407 static void emit_GLSL_TEXM3X2PAD(Context *ctx)
  3400 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3TEX) // !!! FIXME
  3408 {
  3401 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3SPEC) // !!! FIXME
  3409     // no-op ... work happens in emit_GLSL_TEXM3X2TEX().
  3402 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3VSPEC) // !!! FIXME
  3410 } // emit_GLSL_TEXM3X2PAD
       
  3411 
       
  3412 static void emit_GLSL_TEXM3X2TEX(Context *ctx)
       
  3413 {
       
  3414     if (ctx->texm3x2pad_src0 == -1)
       
  3415         return;
       
  3416 
       
  3417     DestArgInfo *info = &ctx->dest_arg;
       
  3418     char dst[64];
       
  3419     char src0[64];
       
  3420     char src1[64];
       
  3421     char src2[64];
       
  3422     char sampler[64];
       
  3423     char code[512];
       
  3424 
       
  3425     // !!! FIXME: this code counts on the register not having swizzles, etc.
       
  3426     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
       
  3427                             sampler, sizeof (sampler));
       
  3428 
       
  3429     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_src0,
       
  3430                             src0, sizeof (src0));
       
  3431     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_dst0,
       
  3432                             src1, sizeof (src1));
       
  3433     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
       
  3434                             src2, sizeof (src2));
       
  3435     get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
       
  3436 
       
  3437     make_GLSL_destarg_assign(ctx, code, sizeof (code),
       
  3438         "texture2D(%s, vec2(dot(%s.xyz, %s.xyz), dot(%s.xyz, %s.xyz)))",
       
  3439         sampler, src0, src1, src2, dst);
       
  3440 
       
  3441     output_line(ctx, "%s", code);
       
  3442 } // emit_GLSL_TEXM3X2TEX
       
  3443 
       
  3444 static void emit_GLSL_TEXM3X3PAD(Context *ctx)
       
  3445 {
       
  3446     // no-op ... work happens in emit_GLSL_TEXM3X3*().
       
  3447 } // emit_GLSL_TEXM3X3PAD
       
  3448 
       
  3449 static void emit_GLSL_TEXM3X3TEX(Context *ctx)
       
  3450 {
       
  3451     if (ctx->texm3x3pad_src1 == -1)
       
  3452         return;
       
  3453 
       
  3454     DestArgInfo *info = &ctx->dest_arg;
       
  3455     char dst[64];
       
  3456     char src0[64];
       
  3457     char src1[64];
       
  3458     char src2[64];
       
  3459     char src3[64];
       
  3460     char src4[64];
       
  3461     char sampler[64];
       
  3462     char code[512];
       
  3463 
       
  3464     // !!! FIXME: this code counts on the register not having swizzles, etc.
       
  3465     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
       
  3466                             sampler, sizeof (sampler));
       
  3467 
       
  3468     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0,
       
  3469                             src0, sizeof (src0));
       
  3470     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0,
       
  3471                             src1, sizeof (src1));
       
  3472     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1,
       
  3473                             src2, sizeof (src2));
       
  3474     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1,
       
  3475                             src3, sizeof (src3));
       
  3476     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
       
  3477                             src4, sizeof (src4));
       
  3478     get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
       
  3479 
       
  3480     make_GLSL_destarg_assign(ctx, code, sizeof (code),
       
  3481         "texture3D(%s,"
       
  3482             " vec3(dot(%s.xyz, %s.xyz),"
       
  3483             " dot(%s.xyz, %s.xyz),"
       
  3484             " dot(%s.xyz, %s.xyz)))",
       
  3485         sampler, src0, src1, src2, src3, dst, src4);
       
  3486 
       
  3487     output_line(ctx, "%s", code);
       
  3488 } // emit_GLSL_TEXM3X3TEX
       
  3489 
       
  3490 static void emit_GLSL_TEXM3X3SPEC_helper(Context *ctx)
       
  3491 {
       
  3492     if (ctx->glsl_generated_texm3x3spec_helper)
       
  3493         return;
       
  3494 
       
  3495     ctx->glsl_generated_texm3x3spec_helper = 1;
       
  3496 
       
  3497     push_output(ctx, &ctx->helpers);
       
  3498     output_line(ctx, "vec3 TEXM3X3SPEC_reflection(const vec3 normal, const vec3 eyeray)");
       
  3499     output_line(ctx, "{"); ctx->indent++;
       
  3500     output_line(ctx,   "return (2.0 * ((normal * eyeray) / (normal * normal)) * normal) - eyeray;"); ctx->indent--;
       
  3501     output_line(ctx, "}");
       
  3502     output_blank_line(ctx);
       
  3503     pop_output(ctx);
       
  3504 } // emit_GLSL_TEXM3X3SPEC_helper
       
  3505 
       
  3506 static void emit_GLSL_TEXM3X3SPEC(Context *ctx)
       
  3507 {
       
  3508     if (ctx->texm3x3pad_src1 == -1)
       
  3509         return;
       
  3510 
       
  3511     DestArgInfo *info = &ctx->dest_arg;
       
  3512     char dst[64];
       
  3513     char src0[64];
       
  3514     char src1[64];
       
  3515     char src2[64];
       
  3516     char src3[64];
       
  3517     char src4[64];
       
  3518     char src5[64];
       
  3519     char sampler[64];
       
  3520     char code[512];
       
  3521 
       
  3522     emit_GLSL_TEXM3X3SPEC_helper(ctx);
       
  3523 
       
  3524     // !!! FIXME: this code counts on the register not having swizzles, etc.
       
  3525     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
       
  3526                             sampler, sizeof (sampler));
       
  3527 
       
  3528     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0,
       
  3529                             src0, sizeof (src0));
       
  3530     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0,
       
  3531                             src1, sizeof (src1));
       
  3532     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1,
       
  3533                             src2, sizeof (src2));
       
  3534     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1,
       
  3535                             src3, sizeof (src3));
       
  3536     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
       
  3537                             src4, sizeof (src4));
       
  3538     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[1].regnum,
       
  3539                             src5, sizeof (src5));
       
  3540     get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
       
  3541 
       
  3542     make_GLSL_destarg_assign(ctx, code, sizeof (code),
       
  3543         "texture3D(%s, "
       
  3544             "TEXM3X3SPEC_reflection("
       
  3545                 "vec3("
       
  3546                     "dot(%s.xyz, %s.xyz), "
       
  3547                     "dot(%s.xyz, %s.xyz), "
       
  3548                     "dot(%s.xyz, %s.xyz)"
       
  3549                 "),"
       
  3550                 "%s.xyz,"
       
  3551             ")"
       
  3552         ")",
       
  3553         sampler, src0, src1, src2, src3, dst, src4, src5);
       
  3554 
       
  3555     output_line(ctx, "%s", code);
       
  3556 } // emit_GLSL_TEXM3X3SPEC
       
  3557 
       
  3558 static void emit_GLSL_TEXM3X3VSPEC(Context *ctx)
       
  3559 {
       
  3560     if (ctx->texm3x3pad_src1 == -1)
       
  3561         return;
       
  3562 
       
  3563     DestArgInfo *info = &ctx->dest_arg;
       
  3564     char dst[64];
       
  3565     char src0[64];
       
  3566     char src1[64];
       
  3567     char src2[64];
       
  3568     char src3[64];
       
  3569     char src4[64];
       
  3570     char sampler[64];
       
  3571     char code[512];
       
  3572 
       
  3573     emit_GLSL_TEXM3X3SPEC_helper(ctx);
       
  3574 
       
  3575     // !!! FIXME: this code counts on the register not having swizzles, etc.
       
  3576     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
       
  3577                             sampler, sizeof (sampler));
       
  3578 
       
  3579     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0,
       
  3580                             src0, sizeof (src0));
       
  3581     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0,
       
  3582                             src1, sizeof (src1));
       
  3583     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1,
       
  3584                             src2, sizeof (src2));
       
  3585     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1,
       
  3586                             src3, sizeof (src3));
       
  3587     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
       
  3588                             src4, sizeof (src4));
       
  3589     get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
       
  3590 
       
  3591     make_GLSL_destarg_assign(ctx, code, sizeof (code),
       
  3592         "texture3D(%s, "
       
  3593             "TEXM3X3SPEC_reflection("
       
  3594                 "vec3("
       
  3595                     "dot(%s.xyz, %s.xyz), "
       
  3596                     "dot(%s.xyz, %s.xyz), "
       
  3597                     "dot(%s.xyz, %s.xyz)"
       
  3598                 "), "
       
  3599                 "vec3(%s.w, %s.w, %s.w)"
       
  3600             ")"
       
  3601         ")",
       
  3602         sampler, src0, src1, src2, src3, dst, src4, src0, src2, dst);
       
  3603 
       
  3604     output_line(ctx, "%s", code);
       
  3605 } // emit_GLSL_TEXM3X3VSPEC
  3403 
  3606 
  3404 static void emit_GLSL_EXPP(Context *ctx)
  3607 static void emit_GLSL_EXPP(Context *ctx)
  3405 {
  3608 {
  3406     // !!! FIXME: msdn's asm docs don't list this opcode, I'll have to check the driver documentation.
  3609     // !!! FIXME: msdn's asm docs don't list this opcode, I'll have to check the driver documentation.
  3407     emit_GLSL_EXP(ctx);  // I guess this is just partial precision EXP?
  3610     emit_GLSL_EXP(ctx);  // I guess this is just partial precision EXP?
  5279     output_line(ctx, "KIL %s.xyzx;", dst);
  5482     output_line(ctx, "KIL %s.xyzx;", dst);
  5280 } // emit_ARB1_TEXKILL
  5483 } // emit_ARB1_TEXKILL
  5281 
  5484 
  5282 static void arb1_texbem(Context *ctx, const int luminance)
  5485 static void arb1_texbem(Context *ctx, const int luminance)
  5283 {
  5486 {
  5284     // Note that this code counts on the register not having swizzles, etc.
  5487     // !!! FIXME: this code counts on the register not having swizzles, etc.
  5285     const int stage = ctx->dest_arg.regnum;
  5488     const int stage = ctx->dest_arg.regnum;
  5286     char dst[64]; get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
  5489     char dst[64]; get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
  5287     char src[64]; get_ARB1_srcarg_varname(ctx, 0, src, sizeof (src));
  5490     char src[64]; get_ARB1_srcarg_varname(ctx, 0, src, sizeof (src));
  5288     char tmp[64]; allocate_ARB1_scratch_reg_name(ctx, tmp, sizeof (tmp));
  5491     char tmp[64]; allocate_ARB1_scratch_reg_name(ctx, tmp, sizeof (tmp));
  5289     char sampler[64];
  5492     char sampler[64];
  5315     arb1_texbem(ctx, 1);
  5518     arb1_texbem(ctx, 1);
  5316 } // emit_ARB1_TEXBEML
  5519 } // emit_ARB1_TEXBEML
  5317 
  5520 
  5318 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2AR)
  5521 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2AR)
  5319 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2GB)
  5522 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2GB)
  5320 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2PAD)
  5523 
  5321 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2TEX)
  5524 
  5322 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3PAD)
  5525 static void emit_ARB1_TEXM3X2PAD(Context *ctx)
  5323 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3TEX)
  5526 {
  5324 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3SPEC)
  5527     // no-op ... work happens in emit_ARB1_TEXM3X2TEX().
  5325 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3VSPEC)
  5528 } // emit_ARB1_TEXM3X2PAD
       
  5529 
       
  5530 static void emit_ARB1_TEXM3X2TEX(Context *ctx)
       
  5531 {
       
  5532     if (ctx->texm3x2pad_src0 == -1)
       
  5533         return;
       
  5534 
       
  5535     char dst[64];
       
  5536     char src0[64];
       
  5537     char src1[64];
       
  5538     char src2[64];
       
  5539 
       
  5540     // !!! FIXME: this code counts on the register not having swizzles, etc.
       
  5541     const int stage = ctx->dest_arg.regnum;
       
  5542     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_src0,
       
  5543                             src0, sizeof (src0));
       
  5544     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_dst0,
       
  5545                             src1, sizeof (src1));
       
  5546     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
       
  5547                             src2, sizeof (src2));
       
  5548     get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
       
  5549 
       
  5550     output_line(ctx, "DP3 %s.y, %s, %s;", dst, src2, dst);
       
  5551     output_line(ctx, "DP3 %s.x, %s, %s;", dst, src0, src1);
       
  5552     output_line(ctx, "TEX %s, %s, texture[%d], 2D;", dst, dst, stage);
       
  5553     emit_ARB1_dest_modifiers(ctx);
       
  5554 } // emit_ARB1_TEXM3X2TEX
       
  5555 
       
  5556 
       
  5557 static void emit_ARB1_TEXM3X3PAD(Context *ctx)
       
  5558 {
       
  5559     // no-op ... work happens in emit_ARB1_TEXM3X3*().
       
  5560 } // emit_ARB1_TEXM3X3PAD
       
  5561 
       
  5562 
       
  5563 static void emit_ARB1_TEXM3X3TEX(Context *ctx)
       
  5564 {
       
  5565     if (ctx->texm3x3pad_src1 == -1)
       
  5566         return;
       
  5567 
       
  5568     char dst[64];
       
  5569     char src0[64];
       
  5570     char src1[64];
       
  5571     char src2[64];
       
  5572     char src3[64];
       
  5573     char src4[64];
       
  5574 
       
  5575     // !!! FIXME: this code counts on the register not having swizzles, etc.
       
  5576     const int stage = ctx->dest_arg.regnum;
       
  5577     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0,
       
  5578                             src0, sizeof (src0));
       
  5579     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0,
       
  5580                             src1, sizeof (src1));
       
  5581     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1,
       
  5582                             src2, sizeof (src2));
       
  5583     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1,
       
  5584                             src3, sizeof (src3));
       
  5585     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
       
  5586                             src4, sizeof (src4));
       
  5587     get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
       
  5588 
       
  5589     output_line(ctx, "DP3 %s.z, %s, %s;", dst, dst, src4);
       
  5590     output_line(ctx, "DP3 %s.x, %s, %s;", dst, src0, src1);
       
  5591     output_line(ctx, "DP3 %s.y, %s, %s;", dst, src2, src3);
       
  5592     output_line(ctx, "TEX %s, %s, texture[%d], 3D;", dst, dst, stage);
       
  5593     emit_ARB1_dest_modifiers(ctx);
       
  5594 } // emit_ARB1_TEXM3X3TEX
       
  5595 
       
  5596 static void emit_ARB1_TEXM3X3SPEC(Context *ctx)
       
  5597 {
       
  5598     if (ctx->texm3x3pad_src1 == -1)
       
  5599         return;
       
  5600 
       
  5601     char dst[64];
       
  5602     char src0[64];
       
  5603     char src1[64];
       
  5604     char src2[64];
       
  5605     char src3[64];
       
  5606     char src4[64];
       
  5607     char src5[64];
       
  5608     char tmp[64];
       
  5609     char tmp2[64];
       
  5610 
       
  5611     // !!! FIXME: this code counts on the register not having swizzles, etc.
       
  5612     const int stage = ctx->dest_arg.regnum;
       
  5613     allocate_ARB1_scratch_reg_name(ctx, tmp, sizeof (tmp));
       
  5614     allocate_ARB1_scratch_reg_name(ctx, tmp2, sizeof (tmp2));
       
  5615     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0,
       
  5616                             src0, sizeof (src0));
       
  5617     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0,
       
  5618                             src1, sizeof (src1));
       
  5619     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1,
       
  5620                             src2, sizeof (src2));
       
  5621     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1,
       
  5622                             src3, sizeof (src3));
       
  5623     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
       
  5624                             src4, sizeof (src4));
       
  5625     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[1].regnum,
       
  5626                             src5, sizeof (src5));
       
  5627     get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
       
  5628 
       
  5629     output_line(ctx, "DP3 %s.z, %s, %s;", dst, dst, src4);
       
  5630     output_line(ctx, "DP3 %s.x, %s, %s;", dst, src0, src1);
       
  5631     output_line(ctx, "DP3 %s.y, %s, %s;", dst, src2, src3);
       
  5632     output_line(ctx, "MUL %s, %s, %s;", tmp, dst, dst);    // normal * normal
       
  5633     output_line(ctx, "MUL %s, %s, %s;", tmp2, dst, src5);  // normal * eyeray
       
  5634     output_line(ctx, "DIV %s, %s, %s;", tmp, tmp, tmp2);
       
  5635     output_line(ctx, "MUL %s, %s, { 2.0, 2.0, 2.0, 2.0 };", tmp, tmp);
       
  5636     output_line(ctx, "MAD %s, %s, %s, -%s;", tmp, tmp, dst, src5);
       
  5637     output_line(ctx, "TEX %s, %s, texture[%d], 3D;", dst, tmp, stage);
       
  5638     emit_ARB1_dest_modifiers(ctx);
       
  5639 } // emit_ARB1_TEXM3X3SPEC
       
  5640 
       
  5641 static void emit_ARB1_TEXM3X3VSPEC(Context *ctx)
       
  5642 {
       
  5643     if (ctx->texm3x3pad_src1 == -1)
       
  5644         return;
       
  5645 
       
  5646     char dst[64];
       
  5647     char src0[64];
       
  5648     char src1[64];
       
  5649     char src2[64];
       
  5650     char src3[64];
       
  5651     char src4[64];
       
  5652     char tmp[64];
       
  5653     char tmp2[64];
       
  5654     char tmp3[64];
       
  5655 
       
  5656     // !!! FIXME: this code counts on the register not having swizzles, etc.
       
  5657     const int stage = ctx->dest_arg.regnum;
       
  5658     allocate_ARB1_scratch_reg_name(ctx, tmp, sizeof (tmp));
       
  5659     allocate_ARB1_scratch_reg_name(ctx, tmp2, sizeof (tmp2));
       
  5660     allocate_ARB1_scratch_reg_name(ctx, tmp3, sizeof (tmp3));
       
  5661     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0,
       
  5662                             src0, sizeof (src0));
       
  5663     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0,
       
  5664                             src1, sizeof (src1));
       
  5665     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1,
       
  5666                             src2, sizeof (src2));
       
  5667     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1,
       
  5668                             src3, sizeof (src3));
       
  5669     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
       
  5670                             src4, sizeof (src4));
       
  5671     get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
       
  5672 
       
  5673     output_line(ctx, "MOV %s.x, %s.w;", tmp3, src0);
       
  5674     output_line(ctx, "MOV %s.y, %s.w;", tmp3, src2);
       
  5675     output_line(ctx, "MOV %s.z, %s.w;", tmp3, dst);
       
  5676     output_line(ctx, "DP3 %s.z, %s, %s;", dst, dst, src4);
       
  5677     output_line(ctx, "DP3 %s.x, %s, %s;", dst, src0, src1);
       
  5678     output_line(ctx, "DP3 %s.y, %s, %s;", dst, src2, src3);
       
  5679     output_line(ctx, "MUL %s, %s, %s;", tmp, dst, dst);    // normal * normal
       
  5680     output_line(ctx, "MUL %s, %s, %s;", tmp2, dst, tmp3);  // normal * eyeray
       
  5681     output_line(ctx, "DIV %s, %s, %s;", tmp, tmp, tmp2);
       
  5682     output_line(ctx, "MUL %s, %s, { 2.0, 2.0, 2.0, 2.0 };", tmp, tmp);
       
  5683     output_line(ctx, "MAD %s, %s, %s, -%s;", tmp, tmp, dst, tmp3);
       
  5684     output_line(ctx, "TEX %s, %s, texture[%d], 3D;", dst, tmp, stage);
       
  5685     emit_ARB1_dest_modifiers(ctx);
       
  5686 } // emit_ARB1_TEXM3X3VSPEC
  5326 
  5687 
  5327 static void emit_ARB1_EXPP(Context *ctx) { emit_ARB1_opcode_ds(ctx, "EX2"); }
  5688 static void emit_ARB1_EXPP(Context *ctx) { emit_ARB1_opcode_ds(ctx, "EX2"); }
  5328 static void emit_ARB1_LOGP(Context *ctx) { arb1_log(ctx, "LG2"); }
  5689 static void emit_ARB1_LOGP(Context *ctx) { arb1_log(ctx, "LG2"); }
  5329 
  5690 
  5330 static void emit_ARB1_CND(Context *ctx)
  5691 static void emit_ARB1_CND(Context *ctx)
  5576 
  5937 
  5577 static void emit_ARB1_TEXLD(Context *ctx)
  5938 static void emit_ARB1_TEXLD(Context *ctx)
  5578 {
  5939 {
  5579     if (!shader_version_atleast(ctx, 1, 4))
  5940     if (!shader_version_atleast(ctx, 1, 4))
  5580     {
  5941     {
  5581         // Note that this code counts on the register not having swizzles, etc.
  5942         // !!! FIXME: this code counts on the register not having swizzles, etc.
  5582         DestArgInfo *info = &ctx->dest_arg;
  5943         DestArgInfo *info = &ctx->dest_arg;
  5583         char dst[64]; get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
  5944         char dst[64]; get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
  5584         output_line(ctx, "TEX %s, %s, texture[%d], 2D;",
  5945         output_line(ctx, "TEX %s, %s, texture[%d], 2D;",
  5585                     dst, dst, info->regnum);
  5946                     dst, dst, info->regnum);
  5586         return;
  5947         return;
  6978     // !!! FIXME: "If a temporary register is used, all components must have been previously written."
  7339     // !!! FIXME: "If a temporary register is used, all components must have been previously written."
  6979     // !!! FIXME: "If a texture register is used, all components that are read must have been declared."
  7340     // !!! FIXME: "If a texture register is used, all components that are read must have been declared."
  6980     // !!! FIXME: there are further limitations in ps_1_3 and earlier.
  7341     // !!! FIXME: there are further limitations in ps_1_3 and earlier.
  6981 } // state_TEXKILL
  7342 } // state_TEXKILL
  6982 
  7343 
       
  7344 // Some rules that apply to some of the fruity ps_1_1 texture opcodes...
       
  7345 static void state_texops(Context *ctx, const char *opcode,
       
  7346                          const int dims, const int texbem)
       
  7347 {
       
  7348     const DestArgInfo *dst = &ctx->dest_arg;
       
  7349     const SourceArgInfo *src = &ctx->source_args[0];
       
  7350     if (dst->regtype != REG_TYPE_TEXTURE)
       
  7351         failf(ctx, "%s destination must be a texture register", opcode);
       
  7352     if (src->regtype != REG_TYPE_TEXTURE)
       
  7353         failf(ctx, "%s source must be a texture register", opcode);
       
  7354     if (src->regnum >= dst->regnum)  // so says MSDN.
       
  7355         failf(ctx, "%s dest must be a higher register than source", opcode);
       
  7356 
       
  7357     if (dims)
       
  7358     {
       
  7359         TextureType ttyp = (dims == 2) ? TEXTURE_TYPE_2D : TEXTURE_TYPE_VOLUME;
       
  7360         add_sampler(ctx, REG_TYPE_SAMPLER, dst->regnum, ttyp, texbem);
       
  7361     } // if
       
  7362 
       
  7363     add_attribute_register(ctx, REG_TYPE_TEXTURE, dst->regnum,
       
  7364                            MOJOSHADER_USAGE_TEXCOORD, dst->regnum, 0xF, 0);
       
  7365 
       
  7366     // Strictly speaking, there should be a TEX opcode prior to this call that
       
  7367     //  should fill in this metadata, but I'm not sure that's required for the
       
  7368     //  shader to assemble in D3D, so we'll do this so we don't fail with a
       
  7369     //  cryptic error message even if the developer didn't do the TEX.
       
  7370     add_attribute_register(ctx, REG_TYPE_TEXTURE, src->regnum,
       
  7371                            MOJOSHADER_USAGE_TEXCOORD, src->regnum, 0xF, 0);
       
  7372 } // state_texops
       
  7373 
  6983 static void state_texbem(Context *ctx, const char *opcode)
  7374 static void state_texbem(Context *ctx, const char *opcode)
  6984 {
  7375 {
  6985     // The TEXBEM equasion, according to MSDN:
  7376     // The TEXBEM equasion, according to MSDN:
  6986     //u' = TextureCoordinates(stage m)u + D3DTSS_BUMPENVMAT00(stage m)*t(n)R
  7377     //u' = TextureCoordinates(stage m)u + D3DTSS_BUMPENVMAT00(stage m)*t(n)R
  6987     //         + D3DTSS_BUMPENVMAT10(stage m)*t(n)G
  7378     //         + D3DTSS_BUMPENVMAT10(stage m)*t(n)G
  7005     // !!! FIXME: MSDN:
  7396     // !!! FIXME: MSDN:
  7006     // !!! FIXME: Register data that has been read by a texbem
  7397     // !!! FIXME: Register data that has been read by a texbem
  7007     // !!! FIXME:  or texbeml instruction cannot be read later,
  7398     // !!! FIXME:  or texbeml instruction cannot be read later,
  7008     // !!! FIXME:  except by another texbem or texbeml.
  7399     // !!! FIXME:  except by another texbem or texbeml.
  7009 
  7400 
  7010     const DestArgInfo *dst = &ctx->dest_arg;
  7401     state_texops(ctx, opcode, 2, 1);
  7011     const SourceArgInfo *src = &ctx->source_args[0];
       
  7012     if (dst->regtype != REG_TYPE_TEXTURE)
       
  7013         failf(ctx, "%s destination must be a texture register", opcode);
       
  7014     if (src->regtype != REG_TYPE_TEXTURE)
       
  7015         failf(ctx, "%s source must be a texture register", opcode);
       
  7016     if (src->regnum >= dst->regnum)  // so says MSDN.
       
  7017         failf(ctx, "%s dest must be a higher register than source", opcode);
       
  7018 
       
  7019     add_sampler(ctx, REG_TYPE_SAMPLER, dst->regnum, TEXTURE_TYPE_2D, 1);
       
  7020     add_attribute_register(ctx, REG_TYPE_TEXTURE, dst->regnum,
       
  7021                            MOJOSHADER_USAGE_TEXCOORD, dst->regnum, 0xF, 0);
       
  7022 
       
  7023     // Strictly speaking, there should be a TEX opcode prior to this call that
       
  7024     //  should fill in this metadata, but I'm not sure that's required for the
       
  7025     //  shader to assemble in D3D, so we'll do this so we don't fail with a
       
  7026     //  cryptic error message even if the developer didn't do the TEX.
       
  7027     add_sampler(ctx, REG_TYPE_SAMPLER, src->regnum, TEXTURE_TYPE_2D, 0);
       
  7028     add_attribute_register(ctx, REG_TYPE_TEXTURE, src->regnum,
       
  7029                            MOJOSHADER_USAGE_TEXCOORD, src->regnum, 0xF, 0);
       
  7030 } // state_texbem
  7402 } // state_texbem
  7031 
  7403 
  7032 static void state_TEXBEM(Context *ctx)
  7404 static void state_TEXBEM(Context *ctx)
  7033 {
  7405 {
  7034     state_texbem(ctx, "TEXBEM");
  7406     state_texbem(ctx, "TEXBEM");
  7036 
  7408 
  7037 static void state_TEXBEML(Context *ctx)
  7409 static void state_TEXBEML(Context *ctx)
  7038 {
  7410 {
  7039     state_texbem(ctx, "TEXBEML");
  7411     state_texbem(ctx, "TEXBEML");
  7040 } // state_TEXBEML
  7412 } // state_TEXBEML
       
  7413 
       
  7414 static void state_TEXM3X2PAD(Context *ctx)
       
  7415 {
       
  7416     if (shader_version_atleast(ctx, 1, 4))
       
  7417         fail(ctx, "TEXM3X2PAD opcode not available after Shader Model 1.3");
       
  7418     state_texops(ctx, "TEXM3X2PAD", 0, 0);
       
  7419     // !!! FIXME: check for correct opcode existance and order more rigorously?
       
  7420     ctx->texm3x2pad_src0 = ctx->source_args[0].regnum;
       
  7421     ctx->texm3x2pad_dst0 = ctx->dest_arg.regnum;
       
  7422 } // state_TEXM3X2PAD
       
  7423 
       
  7424 static void state_TEXM3X2TEX(Context *ctx)
       
  7425 {
       
  7426     if (shader_version_atleast(ctx, 1, 4))
       
  7427         fail(ctx, "TEXM3X2TEX opcode not available after Shader Model 1.3");
       
  7428     if (ctx->texm3x2pad_dst0 == -1)
       
  7429         fail(ctx, "TEXM3X2TEX opcode without matching TEXM3X2PAD");
       
  7430     // !!! FIXME: check for correct opcode existance and order more rigorously?
       
  7431     state_texops(ctx, "TEXM3X2TEX", 2, 0);
       
  7432     ctx->reset_texmpad = 1;
       
  7433 } // state_TEXM3X2TEX
       
  7434 
       
  7435 static void state_TEXM3X3PAD(Context *ctx)
       
  7436 {
       
  7437     if (shader_version_atleast(ctx, 1, 4))
       
  7438         fail(ctx, "TEXM3X2TEX opcode not available after Shader Model 1.3");
       
  7439     state_texops(ctx, "TEXM3X3PAD", 0, 0);
       
  7440 
       
  7441     // !!! FIXME: check for correct opcode existance and order more rigorously?
       
  7442     if (ctx->texm3x3pad_dst0 == -1)
       
  7443     {
       
  7444         ctx->texm3x3pad_src0 = ctx->source_args[0].regnum;
       
  7445         ctx->texm3x3pad_dst0 = ctx->dest_arg.regnum;
       
  7446     } // if
       
  7447     else if (ctx->texm3x3pad_dst1 == -1)
       
  7448     {
       
  7449         ctx->texm3x3pad_src1 = ctx->source_args[0].regnum;
       
  7450         ctx->texm3x3pad_dst1 = ctx->dest_arg.regnum;
       
  7451     } // else
       
  7452 } // state_TEXM3X3PAD
       
  7453 
       
  7454 static void state_texm3x3(Context *ctx, const char *opcode)
       
  7455 {
       
  7456     // !!! FIXME: check for correct opcode existance and order more rigorously?
       
  7457     if (shader_version_atleast(ctx, 1, 4))
       
  7458         failf(ctx, "%s opcode not available after Shader Model 1.3", opcode);
       
  7459     if (ctx->texm3x3pad_dst1 == -1)
       
  7460         failf(ctx, "%s opcode without matching TEXM3X3PADs", opcode);
       
  7461     state_texops(ctx, opcode, 3, 0);
       
  7462     ctx->reset_texmpad = 1;
       
  7463 } // state_texm3x3
       
  7464 
       
  7465 static void state_TEXM3X3(Context *ctx)
       
  7466 {
       
  7467     if (!shader_version_atleast(ctx, 1, 2))
       
  7468         fail(ctx, "TEXM3X3 opcode not available in Shader Model 1.1");
       
  7469     state_texm3x3(ctx, "TEXM3X3");
       
  7470 } // state_TEXM3X3
       
  7471 
       
  7472 static void state_TEXM3X3TEX(Context *ctx)
       
  7473 {
       
  7474     state_texm3x3(ctx, "TEXM3X3TEX");
       
  7475 } // state_TEXM3X3TEX
       
  7476 
       
  7477 static void state_TEXM3X3SPEC(Context *ctx)
       
  7478 {
       
  7479     state_texm3x3(ctx, "TEXM3X3SPEC");
       
  7480     if (ctx->source_args[1].regtype != REG_TYPE_CONST)
       
  7481         fail(ctx, "TEXM3X3SPEC final arg must be a constant register");
       
  7482 } // state_TEXM3X3SPEC
       
  7483 
       
  7484 static void state_TEXM3X3VSPEC(Context *ctx)
       
  7485 {
       
  7486     state_texm3x3(ctx, "TEXM3X3VSPEC");
       
  7487 } // state_TEXM3X3VSPEC
       
  7488 
  7041 
  7489 
  7042 static void state_TEXLD(Context *ctx)
  7490 static void state_TEXLD(Context *ctx)
  7043 {
  7491 {
  7044     if (shader_version_atleast(ctx, 2, 0))
  7492     if (shader_version_atleast(ctx, 2, 0))
  7045     {
  7493     {
  7226 
  7674 
  7227     ctx->instruction_count += instruction->slots;
  7675     ctx->instruction_count += instruction->slots;
  7228 
  7676 
  7229     if (!isfail(ctx))
  7677     if (!isfail(ctx))
  7230         emitter(ctx);  // call the profile's emitter.
  7678         emitter(ctx);  // call the profile's emitter.
       
  7679 
       
  7680     if (ctx->reset_texmpad)
       
  7681     {
       
  7682         ctx->texm3x2pad_dst0 = -1;
       
  7683         ctx->texm3x2pad_src0 = -1;
       
  7684         ctx->texm3x3pad_dst0 = -1;
       
  7685         ctx->texm3x3pad_src0 = -1;
       
  7686         ctx->texm3x3pad_dst1 = -1;
       
  7687         ctx->texm3x3pad_src1 = -1;
       
  7688         ctx->reset_texmpad = 0;
       
  7689     } // if
  7231 
  7690 
  7232     ctx->previous_opcode = opcode;
  7691     ctx->previous_opcode = opcode;
  7233     ctx->scratch_registers = 0;  // reset after every instruction.
  7692     ctx->scratch_registers = 0;  // reset after every instruction.
  7234 
  7693 
  7235     if (!shader_version_atleast(ctx, 2, 0))
  7694     if (!shader_version_atleast(ctx, 2, 0))
  7970     ctx->swizzles_count = swizcount;
  8429     ctx->swizzles_count = swizcount;
  7971     ctx->endline = ENDLINE_STR;
  8430     ctx->endline = ENDLINE_STR;
  7972     ctx->endline_len = strlen(ctx->endline);
  8431     ctx->endline_len = strlen(ctx->endline);
  7973     ctx->last_address_reg_component = -1;
  8432     ctx->last_address_reg_component = -1;
  7974     ctx->current_position = MOJOSHADER_POSITION_BEFORE;
  8433     ctx->current_position = MOJOSHADER_POSITION_BEFORE;
       
  8434     ctx->texm3x2pad_dst0 = -1;
       
  8435     ctx->texm3x2pad_src0 = -1;
       
  8436     ctx->texm3x3pad_dst0 = -1;
       
  8437     ctx->texm3x3pad_src0 = -1;
       
  8438     ctx->texm3x3pad_dst1 = -1;
       
  8439     ctx->texm3x3pad_src1 = -1;
  7975 
  8440 
  7976     ctx->errors = errorlist_create(MallocBridge, FreeBridge, ctx);
  8441     ctx->errors = errorlist_create(MallocBridge, FreeBridge, ctx);
  7977     if (ctx->errors == NULL)
  8442     if (ctx->errors == NULL)
  7978     {
  8443     {
  7979         f(ctx, d);
  8444         f(ctx, d);