mojoshader.c
changeset 1090 636ffcd3f14a
parent 1089 b965d0942dff
child 1091 4edfe78c14f8
equal deleted inserted replaced
1089:b965d0942dff 1090:636ffcd3f14a
   218 // one emit function for uniforms in each profile.
   218 // one emit function for uniforms in each profile.
   219 typedef void (*emit_uniform)(Context *ctx, RegisterType regtype, int regnum,
   219 typedef void (*emit_uniform)(Context *ctx, RegisterType regtype, int regnum,
   220                              const VariableList *var);
   220                              const VariableList *var);
   221 
   221 
   222 // one emit function for samplers in each profile.
   222 // one emit function for samplers in each profile.
   223 typedef void (*emit_sampler)(Context *ctx, int stage, TextureType ttype);
   223 typedef void (*emit_sampler)(Context *ctx, int stage, TextureType ttype,
       
   224                              int texbem);
   224 
   225 
   225 // one emit function for attributes in each profile.
   226 // one emit function for attributes in each profile.
   226 typedef void (*emit_attribute)(Context *ctx, RegisterType regtype, int regnum,
   227 typedef void (*emit_attribute)(Context *ctx, RegisterType regtype, int regnum,
   227                                MOJOSHADER_usage usage, int index, int wmask,
   228                                MOJOSHADER_usage usage, int index, int wmask,
   228                                int flags);
   229                                int flags);
   616     else if ((rtype == REG_TYPE_OUTPUT) && (usage == MOJOSHADER_USAGE_FOG))
   617     else if ((rtype == REG_TYPE_OUTPUT) && (usage == MOJOSHADER_USAGE_FOG))
   617         ctx->uses_fog = 1;  // note that we have to check this later.
   618         ctx->uses_fog = 1;  // note that we have to check this later.
   618 } // add_attribute_register
   619 } // add_attribute_register
   619 
   620 
   620 static inline void add_sampler(Context *ctx, const RegisterType rtype,
   621 static inline void add_sampler(Context *ctx, const RegisterType rtype,
   621                                const int regnum, const TextureType ttype)
   622                                const int regnum, const TextureType ttype,
       
   623                                const int texbem)
   622 {
   624 {
   623     // !!! FIXME: make sure it doesn't exist?
   625     // !!! FIXME: make sure it doesn't exist?
   624     // !!! FIXME:  (ps_1_1 assume we can add it multiple times...)
   626     // !!! FIXME:  (ps_1_1 assume we can add it multiple times...)
   625     RegisterList *item = reglist_insert(ctx, &ctx->samplers, rtype, regnum);
   627     RegisterList *item = reglist_insert(ctx, &ctx->samplers, rtype, regnum);
   626     item->index = (int) ttype;
   628     item->index = (int) ttype;
       
   629     item->misc |= texbem;
   627 } // add_sampler
   630 } // add_sampler
   628 
   631 
   629 
   632 
   630 static inline int writemask_xyzw(const int writemask)
   633 static inline int writemask_xyzw(const int writemask)
   631 {
   634 {
  1152 {
  1155 {
  1153     // no-op.
  1156     // no-op.
  1154 } // emit_D3D_uniform
  1157 } // emit_D3D_uniform
  1155 
  1158 
  1156 
  1159 
  1157 static void emit_D3D_sampler(Context *ctx, int stage, TextureType ttype)
  1160 static void emit_D3D_sampler(Context *ctx, int s, TextureType ttype, int tb)
  1158 {
  1161 {
  1159     // no-op.
  1162     // no-op.
  1160 } // emit_D3D_sampler
  1163 } // emit_D3D_sampler
  1161 
  1164 
  1162 
  1165 
  1559 static void emit_BYTECODE_end(Context *ctx) {}
  1562 static void emit_BYTECODE_end(Context *ctx) {}
  1560 static void emit_BYTECODE_phase(Context *ctx) {}
  1563 static void emit_BYTECODE_phase(Context *ctx) {}
  1561 static void emit_BYTECODE_finalize(Context *ctx) {}
  1564 static void emit_BYTECODE_finalize(Context *ctx) {}
  1562 static void emit_BYTECODE_global(Context *ctx, RegisterType t, int n) {}
  1565 static void emit_BYTECODE_global(Context *ctx, RegisterType t, int n) {}
  1563 static void emit_BYTECODE_array(Context *ctx, VariableList *var) {}
  1566 static void emit_BYTECODE_array(Context *ctx, VariableList *var) {}
  1564 static void emit_BYTECODE_sampler(Context *ctx, int s, TextureType ttype) {}
  1567 static void emit_BYTECODE_sampler(Context *c, int s, TextureType t, int tb) {}
  1565 static void emit_BYTECODE_const_array(Context *ctx, const ConstantsList *c,
  1568 static void emit_BYTECODE_const_array(Context *ctx, const ConstantsList *c,
  1566                                          int base, int size) {}
  1569                                          int base, int size) {}
  1567 static void emit_BYTECODE_uniform(Context *ctx, RegisterType t, int n,
  1570 static void emit_BYTECODE_uniform(Context *ctx, RegisterType t, int n,
  1568                                   const VariableList *var) {}
  1571                                   const VariableList *var) {}
  1569 static void emit_BYTECODE_attribute(Context *ctx, RegisterType t, int n,
  1572 static void emit_BYTECODE_attribute(Context *ctx, RegisterType t, int n,
  2389     } // else
  2392     } // else
  2390 
  2393 
  2391     pop_output(ctx);
  2394     pop_output(ctx);
  2392 } // emit_GLSL_uniform
  2395 } // emit_GLSL_uniform
  2393 
  2396 
  2394 static void emit_GLSL_sampler(Context *ctx, int stage, TextureType ttype)
  2397 static void emit_GLSL_sampler(Context *ctx,int stage,TextureType ttype,int tb)
  2395 {
  2398 {
  2396     const char *type = "";
  2399     const char *type = "";
  2397     switch (ttype)
  2400     switch (ttype)
  2398     {
  2401     {
  2399         case TEXTURE_TYPE_2D: type = "sampler2D"; break;
  2402         case TEXTURE_TYPE_2D: type = "sampler2D"; break;
  2405     char var[64];
  2408     char var[64];
  2406     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, stage, var, sizeof (var));
  2409     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, stage, var, sizeof (var));
  2407 
  2410 
  2408     push_output(ctx, &ctx->globals);
  2411     push_output(ctx, &ctx->globals);
  2409     output_line(ctx, "uniform %s %s;", type, var);
  2412     output_line(ctx, "uniform %s %s;", type, var);
       
  2413     if (tb)  // This sampler used a ps_1_1 TEXBEM opcode?
       
  2414     {
       
  2415         char name[64];
       
  2416         const int index = ctx->uniform_float4_count;
       
  2417         ctx->uniform_float4_count += 2;
       
  2418         get_GLSL_uniform_array_varname(ctx, REG_TYPE_CONST, name, sizeof (name));
       
  2419         output_line(ctx, "#define %s_texbem %s[%d]", var, name, index);
       
  2420         output_line(ctx, "#define %s_texbeml %s[%d]", var, name, index+1);
       
  2421     } // if
  2410     pop_output(ctx);
  2422     pop_output(ctx);
  2411 } // emit_GLSL_sampler
  2423 } // emit_GLSL_sampler
  2412 
  2424 
  2413 static void emit_GLSL_attribute(Context *ctx, RegisterType regtype, int regnum,
  2425 static void emit_GLSL_attribute(Context *ctx, RegisterType regtype, int regnum,
  2414                                 MOJOSHADER_usage usage, int index, int wmask,
  2426                                 MOJOSHADER_usage usage, int index, int wmask,
  3327 {
  3339 {
  3328      glsl_texld(ctx, 0);
  3340      glsl_texld(ctx, 0);
  3329 } // emit_GLSL_TEXLD
  3341 } // emit_GLSL_TEXLD
  3330     
  3342     
  3331 
  3343 
  3332 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXBEM)  // !!! FIXME
  3344 static void emit_GLSL_TEXBEM(Context *ctx)
  3333 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXBEML) // !!! FIXME
  3345 {
       
  3346     DestArgInfo *info = &ctx->dest_arg;
       
  3347     char dst[64]; get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
       
  3348     char src[64]; get_GLSL_srcarg_varname(ctx, 0, src, sizeof (src));
       
  3349     char sampler[64];
       
  3350     char code[512];
       
  3351 
       
  3352     // Note that this code counts on the register not having swizzles, etc.
       
  3353     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
       
  3354                             sampler, sizeof (sampler));
       
  3355 
       
  3356     make_GLSL_destarg_assign(ctx, code, sizeof (code),
       
  3357         "texture2D(%s, vec2(%s.x + (%s_texbem.x * %s.x) + (%s_texbem.z * %s.y),"
       
  3358         " %s.y + (%s_texbem.y * %s.x) + (%s_texbem.w * %s.y)))",
       
  3359         sampler,
       
  3360         dst, sampler, src, sampler, src,
       
  3361         dst, sampler, src, sampler, src);
       
  3362 
       
  3363     output_line(ctx, "%s", code);
       
  3364 } // emit_GLSL_TEXBEM
       
  3365 
       
  3366 
       
  3367 static void emit_GLSL_TEXBEML(Context *ctx)
       
  3368 {
       
  3369     // Note that this code counts on the register not having swizzles, etc.
       
  3370     DestArgInfo *info = &ctx->dest_arg;
       
  3371     char dst[64]; get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
       
  3372     char src[64]; get_GLSL_srcarg_varname(ctx, 0, src, sizeof (src));
       
  3373     char sampler[64];
       
  3374     char code[512];
       
  3375 
       
  3376     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
       
  3377                             sampler, sizeof (sampler));
       
  3378 
       
  3379     make_GLSL_destarg_assign(ctx, code, sizeof (code),
       
  3380         "(texture2D(%s, vec2(%s.x + (%s_texbem.x * %s.x) + (%s_texbem.z * %s.y),"
       
  3381         " %s.y + (%s_texbem.y * %s.x) + (%s_texbem.w * %s.y)))) *"
       
  3382         " ((%s.z * %s_texbeml.x) + %s_texbem.y)",
       
  3383         sampler,
       
  3384         dst, sampler, src, sampler, src,
       
  3385         dst, sampler, src, sampler, src,
       
  3386         src, sampler, sampler);
       
  3387 
       
  3388     output_line(ctx, "%s", code);
       
  3389 } // emit_GLSL_TEXBEML
       
  3390 
  3334 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2AR) // !!! FIXME
  3391 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2AR) // !!! FIXME
  3335 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2GB) // !!! FIXME
  3392 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2GB) // !!! FIXME
  3336 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2PAD) // !!! FIXME
  3393 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2PAD) // !!! FIXME
  3337 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2TEX) // !!! FIXME
  3394 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2TEX) // !!! FIXME
  3338 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3PAD) // !!! FIXME
  3395 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3PAD) // !!! FIXME
  4301 
  4358 
  4302     output_line(ctx, "PARAM %s = %s[%d];", varname, arrayname, index);
  4359     output_line(ctx, "PARAM %s = %s[%d];", varname, arrayname, index);
  4303     pop_output(ctx);
  4360     pop_output(ctx);
  4304 } // emit_ARB1_uniform
  4361 } // emit_ARB1_uniform
  4305 
  4362 
  4306 static void emit_ARB1_sampler(Context *ctx, int stage, TextureType ttype)
  4363 static void emit_ARB1_sampler(Context *ctx,int stage,TextureType ttype,int tb)
  4307 {
  4364 {
  4308     // this is a no-op...you don't predeclare samplers in arb1.
  4365     // this is mostly a no-op...you don't predeclare samplers in arb1.
       
  4366 
       
  4367     if (tb)  // This sampler used a ps_1_1 TEXBEM opcode?
       
  4368     {
       
  4369         const int index = ctx->uniform_float4_count + ctx->uniform_int4_count +
       
  4370                           ctx->uniform_bool_count;
       
  4371         char var[64];
       
  4372         get_ARB1_varname_in_buf(ctx, REG_TYPE_SAMPLER, stage, var, sizeof(var));
       
  4373         push_output(ctx, &ctx->globals);
       
  4374         output_line(ctx, "PARAM %s_texbem = program.local[%d];", var, index);
       
  4375         output_line(ctx, "PARAM %s_texbeml = program.local[%d];", var, index+1);
       
  4376         pop_output(ctx);
       
  4377         ctx->uniform_float4_count += 2;
       
  4378     } // if
  4309 } // emit_ARB1_sampler
  4379 } // emit_ARB1_sampler
  4310 
  4380 
  4311 // !!! FIXME: a lot of cut-and-paste here from emit_GLSL_attribute().
  4381 // !!! FIXME: a lot of cut-and-paste here from emit_GLSL_attribute().
  4312 static void emit_ARB1_attribute(Context *ctx, RegisterType regtype, int regnum,
  4382 static void emit_ARB1_attribute(Context *ctx, RegisterType regtype, int regnum,
  4313                                 MOJOSHADER_usage usage, int index, int wmask,
  4383                                 MOJOSHADER_usage usage, int index, int wmask,
  5169     char dst[64];
  5239     char dst[64];
  5170     get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
  5240     get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
  5171     output_line(ctx, "KIL %s.xyzx;", dst);
  5241     output_line(ctx, "KIL %s.xyzx;", dst);
  5172 } // emit_ARB1_TEXKILL
  5242 } // emit_ARB1_TEXKILL
  5173 
  5243 
  5174 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXBEM)
  5244 static void arb1_texbem(Context *ctx, const int luminance)
  5175 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXBEML)
  5245 {
       
  5246     // Note that this code counts on the register not having swizzles, etc.
       
  5247     const int stage = ctx->dest_arg.regnum;
       
  5248     char dst[64]; get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
       
  5249     char src[64]; get_ARB1_srcarg_varname(ctx, 0, src, sizeof (src));
       
  5250     char tmp[64]; allocate_ARB1_scratch_reg_name(ctx, tmp, sizeof (tmp));
       
  5251     char sampler[64];
       
  5252     get_ARB1_varname_in_buf(ctx, REG_TYPE_SAMPLER, stage,
       
  5253                             sampler, sizeof (sampler));
       
  5254 
       
  5255     output_line(ctx, "MUL %s, %s_texbem.xzyw, %s.xyxy;", tmp, sampler, src);
       
  5256     output_line(ctx, "ADD %s.xy, %s.xzxx, %s.ywxx;", tmp, tmp, tmp);
       
  5257     output_line(ctx, "ADD %s.xy, %s, %s;", tmp, tmp, dst);
       
  5258     output_line(ctx, "TEX %s, %s, texture[%d], 2D;", dst, tmp, stage);
       
  5259 
       
  5260     if (luminance)  // TEXBEML, not just TEXBEM?
       
  5261     {
       
  5262         output_line(ctx, "MAD %s, %s.zzzz, %s_texbeml.xxxx, %s_texbeml.yyyy;",
       
  5263                     tmp, src, sampler, sampler);
       
  5264         output_line(ctx, "MUL %s, %s, %s;", dst, dst, tmp);
       
  5265     } // if
       
  5266 } // arb1_texbem
       
  5267 
       
  5268 static void emit_ARB1_TEXBEM(Context *ctx)
       
  5269 {
       
  5270     arb1_texbem(ctx, 0);
       
  5271 } // emit_ARB1_TEXBEM
       
  5272 
       
  5273 static void emit_ARB1_TEXBEML(Context *ctx)
       
  5274 {
       
  5275     arb1_texbem(ctx, 1);
       
  5276 } // emit_ARB1_TEXBEML
       
  5277 
  5176 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2AR)
  5278 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2AR)
  5177 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2GB)
  5279 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2GB)
  5178 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2PAD)
  5280 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2PAD)
  5179 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2TEX)
  5281 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2TEX)
  5180 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3PAD)
  5282 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3PAD)
  6409     } // if
  6511     } // if
  6410 
  6512 
  6411     else if (shader_is_pixel(ctx))
  6513     else if (shader_is_pixel(ctx))
  6412     {
  6514     {
  6413         if (regtype == REG_TYPE_SAMPLER)
  6515         if (regtype == REG_TYPE_SAMPLER)
  6414             add_sampler(ctx, regtype, regnum, (TextureType) ctx->dwords[0]);
  6516             add_sampler(ctx, regtype, regnum, (TextureType) ctx->dwords[0], 0);
  6415         else
  6517         else
  6416         {
  6518         {
  6417             const MOJOSHADER_usage usage = (MOJOSHADER_usage) ctx->dwords[0];
  6519             const MOJOSHADER_usage usage = (MOJOSHADER_usage) ctx->dwords[0];
  6418             const int index = ctx->dwords[1];
  6520             const int index = ctx->dwords[1];
  6419             add_attribute_register(ctx, regtype, regnum, usage, index, wmask, mods);
  6521             add_attribute_register(ctx, regtype, regnum, usage, index, wmask, mods);
  6820     // !!! FIXME: "If a temporary register is used, all components must have been previously written."
  6922     // !!! FIXME: "If a temporary register is used, all components must have been previously written."
  6821     // !!! FIXME: "If a texture register is used, all components that are read must have been declared."
  6923     // !!! FIXME: "If a texture register is used, all components that are read must have been declared."
  6822     // !!! FIXME: there are further limitations in ps_1_3 and earlier.
  6924     // !!! FIXME: there are further limitations in ps_1_3 and earlier.
  6823 } // state_TEXKILL
  6925 } // state_TEXKILL
  6824 
  6926 
       
  6927 static void state_texbem(Context *ctx, const char *opcode)
       
  6928 {
       
  6929     // The TEXBEM equasion, according to MSDN:
       
  6930     //u' = TextureCoordinates(stage m)u + D3DTSS_BUMPENVMAT00(stage m)*t(n)R
       
  6931     //         + D3DTSS_BUMPENVMAT10(stage m)*t(n)G
       
  6932     //v' = TextureCoordinates(stage m)v + D3DTSS_BUMPENVMAT01(stage m)*t(n)R
       
  6933     //         + D3DTSS_BUMPENVMAT11(stage m)*t(n)G
       
  6934     //t(m)RGBA = TextureSample(stage m)
       
  6935     //
       
  6936     // ...TEXBEML adds this at the end:
       
  6937     //t(m)RGBA = t(m)RGBA * [(t(n)B * D3DTSS_BUMPENVLSCALE(stage m)) +
       
  6938     //           D3DTSS_BUMPENVLOFFSET(stage m)]
       
  6939 
       
  6940     if (shader_version_atleast(ctx, 1, 4))
       
  6941         failf(ctx, "%s opcode not available after Shader Model 1.3", opcode);
       
  6942 
       
  6943     if (!shader_version_atleast(ctx, 1, 2))
       
  6944     {
       
  6945         if (ctx->source_args[0].src_mod == SRCMOD_SIGN)
       
  6946             failf(ctx, "%s forbids _bx2 on source reg before ps_1_2", opcode);
       
  6947     } // if
       
  6948 
       
  6949     // !!! FIXME: MSDN:
       
  6950     // !!! FIXME: Register data that has been read by a texbem
       
  6951     // !!! FIXME:  or texbeml instruction cannot be read later,
       
  6952     // !!! FIXME:  except by another texbem or texbeml.
       
  6953 
       
  6954     const DestArgInfo *dst = &ctx->dest_arg;
       
  6955     const SourceArgInfo *src = &ctx->source_args[0];
       
  6956     if (dst->regtype != REG_TYPE_TEXTURE)
       
  6957         failf(ctx, "%s destination must be a texture register", opcode);
       
  6958     if (src->regtype != REG_TYPE_TEXTURE)
       
  6959         failf(ctx, "%s source must be a texture register", opcode);
       
  6960     if (src->regnum >= dst->regnum)  // so says MSDN.
       
  6961         failf(ctx, "%s dest must be a higher register than source", opcode);
       
  6962 
       
  6963     add_sampler(ctx, REG_TYPE_SAMPLER, dst->regnum, TEXTURE_TYPE_2D, 1);
       
  6964     add_attribute_register(ctx, REG_TYPE_TEXTURE, dst->regnum,
       
  6965                            MOJOSHADER_USAGE_TEXCOORD, dst->regnum, 0xF, 0);
       
  6966 
       
  6967     // Strictly speaking, there should be a TEX opcode prior to this call that
       
  6968     //  should fill in this metadata, but I'm not sure that's required for the
       
  6969     //  shader to assemble in D3D, so we'll do this so we don't fail with a
       
  6970     //  cryptic error message even if the developer didn't do the TEX.
       
  6971     add_sampler(ctx, REG_TYPE_SAMPLER, src->regnum, TEXTURE_TYPE_2D, 0);
       
  6972     add_attribute_register(ctx, REG_TYPE_TEXTURE, src->regnum,
       
  6973                            MOJOSHADER_USAGE_TEXCOORD, src->regnum, 0xF, 0);
       
  6974 } // state_texbem
       
  6975 
       
  6976 static void state_TEXBEM(Context *ctx)
       
  6977 {
       
  6978     state_texbem(ctx, "TEXBEM");
       
  6979 } // state_TEXBEM
       
  6980 
       
  6981 static void state_TEXBEML(Context *ctx)
       
  6982 {
       
  6983     state_texbem(ctx, "TEXBEML");
       
  6984 } // state_TEXBEML
       
  6985 
  6825 static void state_TEXLD(Context *ctx)
  6986 static void state_TEXLD(Context *ctx)
  6826 {
  6987 {
  6827     if (shader_version_atleast(ctx, 2, 0))
  6988     if (shader_version_atleast(ctx, 2, 0))
  6828     {
  6989     {
  6829         const SourceArgInfo *src0 = &ctx->source_args[0];
  6990         const SourceArgInfo *src0 = &ctx->source_args[0];
  6883         // !!! FIXME: add (other?) checks for ps_1_1 version here...
  7044         // !!! FIXME: add (other?) checks for ps_1_1 version here...
  6884         const DestArgInfo *info = &ctx->dest_arg;
  7045         const DestArgInfo *info = &ctx->dest_arg;
  6885         const int sampler = info->regnum;
  7046         const int sampler = info->regnum;
  6886         if (info->regtype != REG_TYPE_TEXTURE)
  7047         if (info->regtype != REG_TYPE_TEXTURE)
  6887             fail(ctx, "TEX param must be a texture register");
  7048             fail(ctx, "TEX param must be a texture register");
  6888         add_sampler(ctx, REG_TYPE_SAMPLER, sampler, TEXTURE_TYPE_2D);
  7049         add_sampler(ctx, REG_TYPE_SAMPLER, sampler, TEXTURE_TYPE_2D, 0);
  6889         add_attribute_register(ctx, REG_TYPE_TEXTURE, sampler,
  7050         add_attribute_register(ctx, REG_TYPE_TEXTURE, sampler,
  6890                                MOJOSHADER_USAGE_TEXCOORD, sampler, 0xF, 0);
  7051                                MOJOSHADER_USAGE_TEXCOORD, sampler, 0xF, 0);
  6891     } // else
  7052     } // else
  6892 } // state_TEXLD
  7053 } // state_TEXLD
  6893 
  7054 
  8051             } // switch
  8212             } // switch
  8052 
  8213 
  8053             retval[i].type = type;
  8214             retval[i].type = type;
  8054             retval[i].index = item->regnum;
  8215             retval[i].index = item->regnum;
  8055             retval[i].name = alloc_varname(ctx, item);
  8216             retval[i].name = alloc_varname(ctx, item);
       
  8217             retval[i].texbem = (item->misc != 0) ? 1 : 0;
  8056             item = item->next;
  8218             item = item->next;
  8057         } // for
  8219         } // for
  8058     } // if
  8220     } // if
  8059 
  8221 
  8060     return retval;
  8222     return retval;
  8467     // ...and samplers...
  8629     // ...and samplers...
  8468     for (item = ctx->samplers.next; item != NULL; item = item->next)
  8630     for (item = ctx->samplers.next; item != NULL; item = item->next)
  8469     {
  8631     {
  8470         ctx->sampler_count++;
  8632         ctx->sampler_count++;
  8471         ctx->profile->sampler_emitter(ctx, item->regnum,
  8633         ctx->profile->sampler_emitter(ctx, item->regnum,
  8472                                       (TextureType) item->index);
  8634                                       (TextureType) item->index,
       
  8635                                       item->misc != 0);
  8473     } // for
  8636     } // for
  8474 
  8637 
  8475     // ...and attributes...
  8638     // ...and attributes...
  8476     for (item = ctx->attributes.next; item != NULL; item = item->next)
  8639     for (item = ctx->attributes.next; item != NULL; item = item->next)
  8477     {
  8640     {