From 14d62a29887619e51b6064454306cc288bacdb75 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 29 May 2012 04:58:11 -0400 Subject: [PATCH] More work on sampler remapping...3D should probably default to cubemaps, etc. --- mojoshader.c | 19 +++++++++++++++++-- mojoshader.h | 13 +++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 826dbdb9..37710189 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -3452,7 +3452,6 @@ static void emit_GLSL_TEXM3X2TEX(Context *ctx) // !!! 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 @@ static void state_texops(Context *ctx, const char *opcode, 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 @@ static void state_TEXM3X2TEX(Context *ctx) // !!! 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 @@ static void state_texm3x3(Context *ctx, const char *opcode, const int dims) 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) diff --git a/mojoshader.h b/mojoshader.h index 6c09fec9..983eb343 100644 --- a/mojoshader.h +++ b/mojoshader.h @@ -715,12 +715,13 @@ int MOJOSHADER_maxShaderModel(const char *profile); * 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