Skip to content

Commit

Permalink
Added TEXLDP/TEXLDP support to the assembler, cleaned up constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Dec 13, 2008
1 parent f6fe6b3 commit 3faa73c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
31 changes: 17 additions & 14 deletions mojoshader.c
Expand Up @@ -1418,11 +1418,11 @@ static void emit_D3D_TEXLD(Context *ctx)
// this opcode looks and acts differently depending on the shader model.
if (shader_version_atleast(ctx, 2, 0))
{
if (ctx->instruction_controls == 0) // texld
if (ctx->instruction_controls == CONTROL_TEXLD)
emit_D3D_opcode_dss(ctx, "texld");
else if (ctx->instruction_controls == 1) // texldp
else if (ctx->instruction_controls == CONTROL_TEXLDP)
emit_D3D_opcode_dss(ctx, "texldp");
else if (ctx->instruction_controls == 2) // texldb
else if (ctx->instruction_controls == CONTROL_TEXLDB)
emit_D3D_opcode_dss(ctx, "texldb");
} // if

Expand Down Expand Up @@ -2959,7 +2959,7 @@ static void emit_GLSL_TEXLD(Context *ctx)
// !!! FIXME: does the d3d bias value map directly to GLSL?
const char *biassep = "";
const char *bias = "";
if (ctx->instruction_controls == 2) // texldb
if (ctx->instruction_controls == CONTROL_TEXLDB)
{
biassep = ", ";
bias = make_GLSL_srcarg_string_w(ctx, 0);
Expand All @@ -2968,7 +2968,7 @@ static void emit_GLSL_TEXLD(Context *ctx)
switch ((const TextureType) sreg->index)
{
case TEXTURE_TYPE_2D:
if (ctx->instruction_controls == 1) // texldp
if (ctx->instruction_controls == CONTROL_TEXLDP)
{
funcname = "texture2DProj";
src0 = make_GLSL_srcarg_string_full(ctx, 0);
Expand All @@ -2980,13 +2980,13 @@ static void emit_GLSL_TEXLD(Context *ctx)
} // else
break;
case TEXTURE_TYPE_CUBE:
if (ctx->instruction_controls == 1) // texldp
if (ctx->instruction_controls == CONTROL_TEXLDP)
fail(ctx, "TEXLDP on a cubemap"); // !!! FIXME: is this legal?
funcname = "textureCube";
src0 = make_GLSL_srcarg_string_vec3(ctx, 0);
break;
case TEXTURE_TYPE_VOLUME:
if (ctx->instruction_controls == 1) // texldp
if (ctx->instruction_controls == CONTROL_TEXLDP)
{
funcname = "texture3DProj";
src0 = make_GLSL_srcarg_string_full(ctx, 0);
Expand Down Expand Up @@ -4886,11 +4886,11 @@ static void emit_ARB1_TEXLD(Context *ctx)
} // if

// !!! FIXME: do texldb and texldp map between OpenGL and D3D correctly?
if (ctx->instruction_controls == 0)
if (ctx->instruction_controls == CONTROL_TEXLD)
arb1_texld(ctx, "TEX");
else if (ctx->instruction_controls == 1)
else if (ctx->instruction_controls == CONTROL_TEXLDP)
arb1_texld(ctx, "TXP");
else if (ctx->instruction_controls == 2)
else if (ctx->instruction_controls == CONTROL_TEXLDB)
arb1_texld(ctx, "TXB");
} // emit_ARB1_TEXLD

Expand Down Expand Up @@ -6274,15 +6274,18 @@ static void state_TEXLD(Context *ctx)
// fail(ctx, "TEXLD src0 must be texture or temp register");
//else

// 0 == texld, 1 == texldp, 2 == texldb
if (ctx->instruction_controls > 2)
fail(ctx, "TEXLD has unknown control bits");
else if (src0->src_mod != SRCMOD_NONE)
if (src0->src_mod != SRCMOD_NONE)
fail(ctx, "TEXLD src0 must have no modifiers");
else if (src1->regtype != REG_TYPE_SAMPLER)
fail(ctx, "TEXLD src1 must be sampler register");
else if (src1->src_mod != SRCMOD_NONE)
fail(ctx, "TEXLD src0 must have no modifiers");
else if ( (ctx->instruction_controls != CONTROL_TEXLD) &&
(ctx->instruction_controls != CONTROL_TEXLDP) &&
(ctx->instruction_controls != CONTROL_TEXLDB) )
{
fail(ctx, "TEXLD has unknown control bits");
} // else if

// Shader Model 3 added swizzle support to this opcode.
if (!shader_version_atleast(ctx, 3, 0))
Expand Down
19 changes: 18 additions & 1 deletion mojoshader_assembler.c
Expand Up @@ -1416,6 +1416,22 @@ static int parse_instruction_token(Context *ctx)
return FAIL;
} // while

uint32 controls = 0;

// This might need to be TEXLD instead of TEXLDP.
if (strcasecmp(opstr, "TEXLDP") == 0)
{
controls = CONTROL_TEXLDP;
strcpy(opstr, "TEXLD");
} // if

// This might need to be TEXLD instead of TEXLDB.
if (strcasecmp(opstr, "TEXLDB") == 0)
{
controls = CONTROL_TEXLDB;
strcpy(opstr, "TEXLD");
} // else if

int i;
int valid_opcode = 0;
const Instruction *instruction = NULL;
Expand All @@ -1431,7 +1447,6 @@ static int parse_instruction_token(Context *ctx)
} // for

uint32 opcode = (uint32) i;
uint32 controls = 0;

if (!valid_opcode)
return failf(ctx, "Unknown instruction '%s'", opstr);
Expand All @@ -1445,13 +1460,15 @@ static int parse_instruction_token(Context *ctx)
} // if

// This might need to be BREAKC instead of BREAK.
// !!! FIXME: compare opcode, not string
else if (strcmp(instruction->opcode_string, "BREAK") == 0)
{
if (parse_condition(ctx, &controls))
opcode = OPCODE_BREAKC;
} // else if

// SETP has a conditional code, always.
// !!! FIXME: compare opcode, not string
else if (strcmp(instruction->opcode_string, "SETP") == 0)
{
if (!parse_condition(ctx, &controls))
Expand Down
5 changes: 5 additions & 0 deletions mojoshader_internal.h
Expand Up @@ -123,6 +123,11 @@ typedef int32_t int32;
#define OPCODE_IFC 41
#define OPCODE_BREAKC 45

// TEXLD becomes a different instruction with these instruction controls.
#define CONTROL_TEXLD 0
#define CONTROL_TEXLDP 1
#define CONTROL_TEXLDB 2

// #define this to force app to supply an allocator, so there's no reference
// to the C runtime's malloc() and free()...
#if MOJOSHADER_FORCE_ALLOCATOR
Expand Down

0 comments on commit 3faa73c

Please sign in to comment.