More work on sampler remapping...3D should probably default to cubemaps, etc.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 29 May 2012 04:58:11 -0400
changeset 1106 2bef26cc20f9
parent 1105 57e255c3b243
child 1107 b18605919c3c
More work on sampler remapping...3D should probably default to cubemaps, etc.
mojoshader.c
mojoshader.h
--- a/mojoshader.c	Tue May 29 03:20:28 2012 -0400
+++ b/mojoshader.c	Tue May 29 04:58:11 2012 -0400
@@ -3452,7 +3452,6 @@
     // !!! FIXME: this code counts on the register not having swizzles, etc.
     get_GLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum,
                             sampler, sizeof (sampler));
-
     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_src0,
                             src0, sizeof (src0));
     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_dst0,
@@ -7464,7 +7463,7 @@
 
     if (dims)
     {
-        TextureType ttyp = (dims == 2) ? TEXTURE_TYPE_2D : TEXTURE_TYPE_VOLUME;
+        TextureType ttyp = (dims == 2) ? TEXTURE_TYPE_2D : TEXTURE_TYPE_CUBE;
         add_sampler(ctx, dst->regnum, ttyp, texbem);
     } // if
 
@@ -7538,6 +7537,14 @@
     // !!! FIXME: check for correct opcode existance and order more rigorously?
     state_texops(ctx, "TEXM3X2TEX", 2, 0);
     ctx->reset_texmpad = 1;
+
+    RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
+                                      ctx->dest_arg.regnum);
+    const TextureType ttype = (TextureType) (sreg ? sreg->index : 0);
+
+    // A samplermap might change this to something nonsensical.
+    if (ttype != TEXTURE_TYPE_2D)
+        fail(ctx, "TEXM3X2TEX needs a 2D sampler");
 } // state_TEXM3X2TEX
 
 static void state_TEXM3X3PAD(Context *ctx)
@@ -7568,6 +7575,14 @@
         failf(ctx, "%s opcode without matching TEXM3X3PADs", opcode);
     state_texops(ctx, opcode, dims, 0);
     ctx->reset_texmpad = 1;
+
+    RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
+                                      ctx->dest_arg.regnum);
+    const TextureType ttype = (TextureType) (sreg ? sreg->index : 0);
+
+    // A samplermap might change this to something nonsensical.
+    if ((ttype != TEXTURE_TYPE_VOLUME) && (ttype != TEXTURE_TYPE_CUBE))
+        failf(ctx, "%s needs a 3D or Cubemap sampler", opcode);
 } // state_texm3x3
 
 static void state_TEXM3X3(Context *ctx)
--- a/mojoshader.h	Tue May 29 03:20:28 2012 -0400
+++ b/mojoshader.h	Tue May 29 04:58:11 2012 -0400
@@ -715,12 +715,13 @@
  *  expect samplers to be (2D, cubemap, etc). Shader Model 1, however, just
  *  uses whatever is bound to a given sampler at draw time, but this doesn't
  *  work in OpenGL, etc. In these cases, MojoShader will default to
- *  2D texture sampling, which works 75% of the time, but if you really
- *  needed something else, you'll need to specify it here. This can also be
- *  used, at your own risk, to override DCL opcodes in shaders: if the
- *  shader explicit says 2D, but you want Cubemap, for example, you can use
- *  this to override. If you aren't sure about any of this stuff, you can
- *  almost certainly ignore it: (smap) can be NULL.
+ *  2D texture sampling (or cubemap sampling, in cases where it makes sense,
+ *  like the TEXM3X3TEX opcode), which works 75% of the time, but if you
+ *  really needed something else, you'll need to specify it here. This can
+ *  also be used, at your own risk, to override DCL opcodes in shaders: if
+ *  the shader explicit says 2D, but you want Cubemap, for example, you can
+ *  use this to override. If you aren't sure about any of this stuff, you can
+ *  (and should) almost certainly ignore it: (smap) can be NULL.
  *
  * This function is thread safe, so long as (m) and (f) are too, and that
  *  (tokenbuf) remains intact for the duration of the call. This allows you