Global vars for GLSL profile. trunk
authorRyan C. Gordon <icculus@icculus.org>
Thu, 03 Apr 2008 09:33:55 -0400
branchtrunk
changeset 74 935af85774dc
parent 73 c368f50d89d2
child 75 1bbb06b40588
Global vars for GLSL profile. Declare global variables for address and predicate registers in GLSL profile, but only if the shader references them.
mojoshader.c
--- a/mojoshader.c	Thu Apr 03 09:31:13 2008 -0400
+++ b/mojoshader.c	Thu Apr 03 09:33:55 2008 -0400
@@ -263,9 +263,14 @@
 
 typedef enum
 {
-    CTX_FLAGS_GLSL_LIT_OPCODE = (1 << 0),
-    CTX_FLAGS_GLSL_DST_OPCODE = (1 << 1),
-    CTX_FLAGS_GLSL_LRP_OPCODE = (1 << 2),
+    // May apply to any profile...
+    CTX_FLAGS_USED_ADDR_REG   = (1 << 0),
+    CTX_FLAGS_USED_PRED_REG   = (1 << 1),
+
+    // Specific to GLSL profile...
+    CTX_FLAGS_GLSL_LIT_OPCODE = (1 << 2),
+    CTX_FLAGS_GLSL_DST_OPCODE = (1 << 3),
+    CTX_FLAGS_GLSL_LRP_OPCODE = (1 << 4),
     CTX_FLAGS_MASK = 0xFFFFFFFF
 } ContextFlags;
 
@@ -1498,6 +1503,13 @@
     // force a RET opcode if we're at the end of the stream without one.
     if (ctx->previous_opcode != OPCODE_RET)
         emit_GLSL_RET(ctx);
+
+    push_output(ctx, &ctx->globals);
+    if (ctx->flags & CTX_FLAGS_USED_ADDR_REG)
+        output_line(ctx, "ivec a0;");
+    if (ctx->flags & CTX_FLAGS_USED_PRED_REG)
+        output_line(ctx, "bvec p0;");
+    pop_output(ctx);
 } // emit_GLSL_end
 
 static void emit_GLSL_comment(Context *ctx, const char *str)
@@ -2377,6 +2389,14 @@
     if ( ((SourceMod) info->src_mod) >= SRCMOD_TOTAL )
         return fail(ctx, "Unknown source modifier");
 
+    // !!! FIXME: make sure there were def/dcl for all referenced vars?
+    switch (info->regtype)
+    {
+        case REG_TYPE_ADDRESS: ctx->flags |= CTX_FLAGS_USED_ADDR_REG; break;
+        case REG_TYPE_PREDICATE: ctx->flags |= CTX_FLAGS_USED_PRED_REG; break;
+        default: break;  // don't care.
+    } // switch
+
     return 1;
 } // parse_source_token