First piece of work on nv3 profile. trunk
authorRyan C. Gordon <icculus@icculus.org>
Thu, 03 Jul 2008 12:09:26 -0400
branchtrunk
changeset 421 bfd3d95273ec
parent 420 bfcebc3bf560
child 422 1d5eaf3a4c98
First piece of work on nv3 profile.
mojoshader.c
mojoshader.h
mojoshader_opengl.c
--- a/mojoshader.c	Thu Jul 03 12:08:40 2008 -0400
+++ b/mojoshader.c	Thu Jul 03 12:09:26 2008 -0400
@@ -419,6 +419,7 @@
     int determined_constants_arrays:1;
     int predicated:1;
     int support_nv2:1;
+    int support_nv3:1;
     int support_glsl120:1;
     int glsl_generated_lit_opcode:1;
 };
@@ -3877,6 +3878,16 @@
         output_line(ctx, "OPTION NV_%s_program2;", shader_full_str);
     } // else if
 
+    else if (strcmp(profilestr, MOJOSHADER_PROFILE_NV3) == 0)
+    {
+        // there's no NV_fragment_program3, so just use 2.
+        const int ver = shader_is_pixel(ctx) ? 2 : 3;
+        ctx->support_nv2 = 1;
+        ctx->support_nv3 = 1;
+        output_line(ctx, "!!ARB%s1.0", shader_str);
+        output_line(ctx, "OPTION NV_%s_program%d;", shader_full_str, ver);
+    } // else if
+
     else
     {
         failf(ctx, "Profile '%s' unsupported or unknown.", profilestr);
@@ -4815,7 +4826,66 @@
 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(DSX)
 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(DSY)
 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXLDD)
-EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXLDL)
+
+
+static void arb1_texld(Context *ctx, const char *opcode)
+{
+    // !!! FIXME: do non-RGBA textures map to same default values as D3D?
+    const char *dst = make_ARB1_destarg_string(ctx);
+    const SourceArgInfo *samp_arg = &ctx->source_args[1];
+    RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
+                                      samp_arg->regnum);
+    const char *ttype = NULL;
+    const char *src0 = make_ARB1_srcarg_string(ctx, 0);
+    //const char *src1 = get_ARB1_srcarg_varname(ctx, 1); // !!! FIXME: SRC_MOD?
+
+    // !!! FIXME: this should be in state_TEXLD, not in the arb1/glsl emitters.
+    if (sreg == NULL)
+    {
+        fail(ctx, "TEXLD using undeclared sampler");
+        return;
+    } // if
+
+    if (!no_swizzle(samp_arg->swizzle))
+    {
+        // !!! FIXME: does this ever actually happen?
+        fail(ctx, "BUG: can't handle TEXLD with sampler swizzle at the moment");
+    } // if
+
+    switch ((const TextureType) sreg->index)
+    {
+        case TEXTURE_TYPE_2D: ttype = "2D"; break; // !!! FIXME: "RECT"?
+        case TEXTURE_TYPE_CUBE: ttype = "CUBE"; break;
+        case TEXTURE_TYPE_VOLUME: ttype = "3D"; break;
+        default: fail(ctx, "unknown texture type"); return;
+    } // switch
+
+    output_line(ctx, "%s%s, %s, texture[%d], %s;", opcode, dst, src0,
+                samp_arg->regnum, ttype);
+} // arb1_texld
+
+
+static void emit_ARB1_TEXLDL(Context *ctx)
+{
+    if ((shader_is_vertex(ctx)) && (!ctx->support_nv3))
+    {
+        failf(ctx, "Vertex shader TEXLDL unsupported in %s profile",
+              ctx->profile->name);
+        return;
+    } // if
+
+    else if ((shader_is_pixel(ctx)) && (!ctx->support_nv2))
+    {
+        failf(ctx, "Pixel shader TEXLDL unsupported in %s profile",
+              ctx->profile->name);
+        return;
+    } // if
+
+    // !!! FIXME: this doesn't map exactly to TEXLDL. Review this.
+    arb1_texld(ctx, "TXL");
+} // emit_ARB1_TEXLDL
+
+
 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(BREAKP)
 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(BREAKC)
 
@@ -4896,48 +4966,14 @@
 
 static void emit_ARB1_TEXLD(Context *ctx)
 {
-    // !!! FIXME: do non-RGBA textures map to same default values as D3D?
-
     if (!shader_version_atleast(ctx, 2, 0))
     {
         // ps_1_0 and ps_1_4 are both different, too!
         fail(ctx, "TEXLD <= Shader Model 2.0 unimplemented.");  // !!! FIXME
         return;
     } // if
-    else
-    {
-        const char *dst = make_ARB1_destarg_string(ctx);
-        const SourceArgInfo *samp_arg = &ctx->source_args[1];
-        RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER,
-                                          samp_arg->regnum);
-        const char *ttype = NULL;
-        const char *src0 = make_ARB1_srcarg_string(ctx, 0);
-        //const char *src1 = get_ARB1_srcarg_varname(ctx, 1); // !!! FIXME: SRC_MOD?
-
-        // !!! FIXME: this should be in state_TEXLD, not in the arb1/glsl emitters.
-        if (sreg == NULL)
-        {
-            fail(ctx, "TEXLD using undeclared sampler");
-            return;
-        } // if
-
-        if (!no_swizzle(samp_arg->swizzle))
-        {
-            // !!! FIXME: does this ever actually happen?
-            fail(ctx, "BUG: can't handle TEXLD with sampler swizzle at the moment");
-        } // if
-
-        switch ((const TextureType) sreg->index)
-        {
-            case TEXTURE_TYPE_2D: ttype = "2D"; break; // !!! FIXME: "RECT"?
-            case TEXTURE_TYPE_CUBE: ttype = "CUBE"; break;
-            case TEXTURE_TYPE_VOLUME: ttype = "3D"; break;
-            default: fail(ctx, "unknown texture type"); return;
-        } // switch
-
-        output_line(ctx, "TEX%s, %s, texture[%d], %s;", dst, src0,
-                    samp_arg->regnum, ttype);
-    } // else
+
+    arb1_texld(ctx, "TEX");
 } // emit_ARB1_TEXLD
 
 #endif  // SUPPORT_PROFILE_ARB1
--- a/mojoshader.h	Thu Jul 03 12:08:40 2008 -0400
+++ b/mojoshader.h	Thu Jul 03 12:09:26 2008 -0400
@@ -357,7 +357,7 @@
  * Profile string for OpenGL ARB 1.0 shaders with Nvidia 3.0 extensions:
  *  GL_NV_vertex_program3 and GL_NV_fragment_program2
  */
-// Not yet. #define MOJOSHADER_PROFILE_NV3 "nv3"
+#define MOJOSHADER_PROFILE_NV3 "nv3"
 
 /*
  * Profile string for OpenGL ARB 1.0 shaders with Nvidia 4.0 extensions:
--- a/mojoshader_opengl.c	Thu Jul 03 12:08:40 2008 -0400
+++ b/mojoshader_opengl.c	Thu Jul 03 12:09:26 2008 -0400
@@ -141,6 +141,7 @@
     int have_GL_ARB_fragment_program:1;
     int have_GL_NV_vertex_program2_option:1;
     int have_GL_NV_fragment_program2:1;
+    int have_GL_NV_vertex_program3:1;
     int have_GL_ARB_shader_objects:1;
     int have_GL_ARB_vertex_shader:1;
     int have_GL_ARB_fragment_shader:1;
@@ -694,6 +695,7 @@
     ctx->have_GL_ARB_fragment_program = 1;
     ctx->have_GL_NV_vertex_program2_option = 1;
     ctx->have_GL_NV_fragment_program2 = 1;
+    ctx->have_GL_NV_vertex_program3 = 1;
     ctx->have_GL_ARB_shader_objects = 1;
     ctx->have_GL_ARB_vertex_shader = 1;
     ctx->have_GL_ARB_fragment_shader = 1;
@@ -724,6 +726,7 @@
     VERIFY_EXT(GL_ARB_shading_language_100, 2, 0);
     VERIFY_EXT(GL_NV_vertex_program2_option, -1, -1);
     VERIFY_EXT(GL_NV_fragment_program2, -1, -1);
+    VERIFY_EXT(GL_NV_vertex_program3, -1, -1);
     VERIFY_EXT(GL_NV_half_float, -1, -1);
 
     #undef VERIFY_EXT
@@ -758,6 +761,14 @@
         MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_NV_vertex_program2_option);
         MUST_HAVE(MOJOSHADER_PROFILE_NV2, GL_NV_fragment_program2);
     } // else if
+
+    else if (strcmp(profile, MOJOSHADER_PROFILE_NV3) == 0)
+    {
+        MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_ARB_vertex_program);
+        MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_ARB_fragment_program);
+        MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_NV_vertex_program3);
+        MUST_HAVE(MOJOSHADER_PROFILE_NV3, GL_NV_fragment_program2);
+    } // else if
     #endif
 
     #if SUPPORT_PROFILE_GLSL
@@ -808,6 +819,7 @@
         static const char *priority[] = {
             MOJOSHADER_PROFILE_GLSL120,
             MOJOSHADER_PROFILE_GLSL,
+            MOJOSHADER_PROFILE_NV3,
             MOJOSHADER_PROFILE_NV2,
             MOJOSHADER_PROFILE_ARB1,
         };
@@ -889,7 +901,8 @@
 
 #if SUPPORT_PROFILE_ARB1
     else if ( (strcmp(profile, MOJOSHADER_PROFILE_ARB1) == 0) ||
-              (strcmp(profile, MOJOSHADER_PROFILE_NV2) == 0) )
+              (strcmp(profile, MOJOSHADER_PROFILE_NV2) == 0) ||
+              (strcmp(profile, MOJOSHADER_PROFILE_NV3) == 0) )
     {
         ctx->profileMaxUniforms = impl_ARB1_MaxUniforms;
         ctx->profileCompileShader = impl_ARB1_CompileShader;