Added TEXLDP/TEXLDP support to the assembler, cleaned up constants.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 13 Dec 2008 08:58:35 -0500
changeset 519 c9b27381c971
parent 518 8c0f80fea9ef
child 520 7195f0183d0c
Added TEXLDP/TEXLDP support to the assembler, cleaned up constants.
mojoshader.c
mojoshader_assembler.c
mojoshader_internal.h
--- a/mojoshader.c	Sat Dec 13 08:48:11 2008 -0500
+++ b/mojoshader.c	Sat Dec 13 08:58:35 2008 -0500
@@ -1418,11 +1418,11 @@
     // 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
 
@@ -2959,7 +2959,7 @@
         // !!! 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);
@@ -2968,7 +2968,7 @@
         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);
@@ -2980,13 +2980,13 @@
                 } // 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);
@@ -4886,11 +4886,11 @@
     } // 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
 
@@ -6274,15 +6274,18 @@
         //    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))
--- a/mojoshader_assembler.c	Sat Dec 13 08:48:11 2008 -0500
+++ b/mojoshader_assembler.c	Sat Dec 13 08:58:35 2008 -0500
@@ -1416,6 +1416,22 @@
             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;
@@ -1431,7 +1447,6 @@
     } // for
 
     uint32 opcode = (uint32) i;
-    uint32 controls = 0;
 
     if (!valid_opcode)
         return failf(ctx, "Unknown instruction '%s'", opstr);
@@ -1445,6 +1460,7 @@
     } // 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))
@@ -1452,6 +1468,7 @@
     } // 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))
--- a/mojoshader_internal.h	Sat Dec 13 08:48:11 2008 -0500
+++ b/mojoshader_internal.h	Sat Dec 13 08:58:35 2008 -0500
@@ -123,6 +123,11 @@
 #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