mojoshader.c
changeset 1109 51292bd4476b
parent 1108 b27629cb8124
child 1111 7530b37979b8
equal deleted inserted replaced
1108:b27629cb8124 1109:51292bd4476b
  3258     if (!shader_version_atleast(ctx, 1, 4))
  3258     if (!shader_version_atleast(ctx, 1, 4))
  3259     {
  3259     {
  3260         DestArgInfo *info = &ctx->dest_arg;
  3260         DestArgInfo *info = &ctx->dest_arg;
  3261         char dst[64];
  3261         char dst[64];
  3262         char sampler[64];
  3262         char sampler[64];
  3263         char code[128];
  3263         char code[128] = {0};
  3264 
  3264 
  3265         assert(!texldd);
  3265         assert(!texldd);
       
  3266 
       
  3267         RegisterList *sreg;
       
  3268         sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER, info->regnum);
       
  3269         const TextureType ttype = (TextureType) (sreg ? sreg->index : 0);
  3266 
  3270 
  3267         // !!! FIXME: this code counts on the register not having swizzles, etc.
  3271         // !!! FIXME: this code counts on the register not having swizzles, etc.
  3268         get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
  3272         get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
  3269         get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
  3273         get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
  3270                                 sampler, sizeof (sampler));
  3274                                 sampler, sizeof (sampler));
  3271         make_GLSL_destarg_assign(ctx, code, sizeof (code),
  3275 
  3272                                  "texture2D(%s, %s.xy)",
  3276         if (ttype == TEXTURE_TYPE_2D)
  3273                                  sampler, dst);
  3277         {
       
  3278             make_GLSL_destarg_assign(ctx, code, sizeof (code),
       
  3279                                      "texture2D(%s, %s.xy)",
       
  3280                                      sampler, dst);
       
  3281         }
       
  3282         else if (ttype == TEXTURE_TYPE_CUBE)
       
  3283         {
       
  3284             make_GLSL_destarg_assign(ctx, code, sizeof (code),
       
  3285                                      "textureCube(%s, %s.xyz)",
       
  3286                                      sampler, dst);
       
  3287         }
       
  3288         else if (ttype == TEXTURE_TYPE_VOLUME)
       
  3289         {
       
  3290             make_GLSL_destarg_assign(ctx, code, sizeof (code),
       
  3291                                      "texture3D(%s, %s.xyz)",
       
  3292                                      sampler, dst);
       
  3293         }
       
  3294         else
       
  3295         {
       
  3296             fail(ctx, "unexpected texture type");
       
  3297         } // else
  3274         output_line(ctx, "%s", code);
  3298         output_line(ctx, "%s", code);
  3275     } // if
  3299     } // if
  3276 
  3300 
  3277     else if (!shader_version_atleast(ctx, 2, 0))
  3301     else if (!shader_version_atleast(ctx, 2, 0))
  3278     {
  3302     {
  5906     // !!! FIXME: Hack: "TEXH" is invalid in nv4. Fix this more cleanly.
  5930     // !!! FIXME: Hack: "TEXH" is invalid in nv4. Fix this more cleanly.
  5907     if ((ctx->dest_arg.result_mod & MOD_PP) && (support_nv4(ctx)))
  5931     if ((ctx->dest_arg.result_mod & MOD_PP) && (support_nv4(ctx)))
  5908         ctx->dest_arg.result_mod &= ~MOD_PP;
  5932         ctx->dest_arg.result_mod &= ~MOD_PP;
  5909 
  5933 
  5910     char dst[64]; make_ARB1_destarg_string(ctx, dst, sizeof (dst));
  5934     char dst[64]; make_ARB1_destarg_string(ctx, dst, sizeof (dst));
  5911     const SourceArgInfo *samp_arg = &ctx->source_args[1];
  5935 
  5912     RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
  5936     const int sm1 = !shader_version_atleast(ctx, 1, 4);
  5913                                       samp_arg->regnum);
  5937     const int regnum = sm1 ? ctx->dest_arg.regnum : ctx->source_args[1].regnum;
       
  5938     RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER, regnum);
       
  5939 
  5914     const char *ttype = NULL;
  5940     const char *ttype = NULL;
  5915     char src0[64]; get_ARB1_srcarg_varname(ctx, 0, src0, sizeof (src0));
  5941     char src0[64];
       
  5942     if (sm1)
       
  5943         get_ARB1_destarg_varname(ctx, src0, sizeof (src0));
       
  5944     else
       
  5945         get_ARB1_srcarg_varname(ctx, 0, src0, sizeof (src0));
  5916     //char src1[64]; get_ARB1_srcarg_varname(ctx, 1, src1, sizeof (src1));  // !!! FIXME: SRC_MOD?
  5946     //char src1[64]; get_ARB1_srcarg_varname(ctx, 1, src1, sizeof (src1));  // !!! FIXME: SRC_MOD?
  5917 
  5947 
  5918     char src2[64] = { 0 };
  5948     char src2[64] = { 0 };
  5919     char src3[64] = { 0 };
  5949     char src3[64] = { 0 };
  5920 
  5950 
  5929     {
  5959     {
  5930         fail(ctx, "TEXLD using undeclared sampler");
  5960         fail(ctx, "TEXLD using undeclared sampler");
  5931         return;
  5961         return;
  5932     } // if
  5962     } // if
  5933 
  5963 
  5934     if (!no_swizzle(samp_arg->swizzle))
  5964     // SM1 only specifies dst, so don't check swizzle there.
       
  5965     if ( !sm1 && (!no_swizzle(ctx->source_args[1].swizzle)) )
  5935     {
  5966     {
  5936         // !!! FIXME: does this ever actually happen?
  5967         // !!! FIXME: does this ever actually happen?
  5937         fail(ctx, "BUG: can't handle TEXLD with sampler swizzle at the moment");
  5968         fail(ctx, "BUG: can't handle TEXLD with sampler swizzle at the moment");
  5938     } // if
  5969     } // if
  5939 
  5970 
  5946     } // switch
  5977     } // switch
  5947 
  5978 
  5948     if (texldd)
  5979     if (texldd)
  5949     {
  5980     {
  5950         output_line(ctx, "%s%s, %s, %s, %s, texture[%d], %s;", opcode, dst,
  5981         output_line(ctx, "%s%s, %s, %s, %s, texture[%d], %s;", opcode, dst,
  5951                     src0, src2, src3, samp_arg->regnum, ttype);
  5982                     src0, src2, src3, regnum, ttype);
  5952     } // if
  5983     } // if
  5953     else
  5984     else
  5954     {
  5985     {
  5955         output_line(ctx, "%s%s, %s, texture[%d], %s;", opcode, dst, src0,
  5986         output_line(ctx, "%s%s, %s, texture[%d], %s;", opcode, dst, src0,
  5956                     samp_arg->regnum, ttype);
  5987                     regnum, ttype);
  5957     } // else
  5988     } // else
  5958 } // arb1_texld
  5989 } // arb1_texld
  5959 
  5990 
  5960 
  5991 
  5961 static void emit_ARB1_TEXLDD(Context *ctx)
  5992 static void emit_ARB1_TEXLDD(Context *ctx)
  6071 
  6102 
  6072 static void emit_ARB1_TEXLD(Context *ctx)
  6103 static void emit_ARB1_TEXLD(Context *ctx)
  6073 {
  6104 {
  6074     if (!shader_version_atleast(ctx, 1, 4))
  6105     if (!shader_version_atleast(ctx, 1, 4))
  6075     {
  6106     {
  6076         // !!! FIXME: this code counts on the register not having swizzles, etc.
  6107         arb1_texld(ctx, "TEX", 0);
  6077         DestArgInfo *info = &ctx->dest_arg;
       
  6078         char dst[64]; get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
       
  6079         output_line(ctx, "TEX %s, %s, texture[%d], 2D;",
       
  6080                     dst, dst, info->regnum);
       
  6081         return;
  6108         return;
  6082     } // if
  6109     } // if
  6083 
  6110 
  6084     else if (!shader_version_atleast(ctx, 2, 0))
  6111     else if (!shader_version_atleast(ctx, 2, 0))
  6085     {
  6112     {