mojoshader.c
changeset 1054 63dd1a46ce13
parent 1052 0ac978521113
child 1055 3295380ce6fc
--- a/mojoshader.c	Thu Jun 09 01:59:49 2011 -0400
+++ b/mojoshader.c	Mon Jun 20 15:26:34 2011 -0400
@@ -143,6 +143,7 @@
     int have_multi_color_outputs;
     int determined_constants_arrays;
     int predicated;
+    int uses_pointsize;
     int glsl_generated_lit_opcode;
     int glsl_generated_texldd_setup;
     int arb1_wrote_position;
@@ -591,6 +592,9 @@
     item->index = index;
     item->writemask = writemask;
     item->misc = flags;
+
+    if ((rtype == REG_TYPE_OUTPUT) && (usage == MOJOSHADER_USAGE_POINTSIZE))
+        ctx->uses_pointsize = 1;  // note that we have to check this later.
 } // add_attribute_register
 
 static inline void add_sampler(Context *ctx, const RegisterType rtype,
@@ -674,6 +678,19 @@
 
 // D3D stuff that's used in more than just the d3d profile...
 
+static int isscalar(Context *ctx, const MOJOSHADER_shaderType shader_type,
+                    const RegisterType rtype, const int rnum)
+{
+    if ((rtype == REG_TYPE_OUTPUT) && (ctx->uses_pointsize))
+    {
+        const RegisterList *reg = reglist_find(&ctx->attributes, rtype, rnum);
+        if (reg != NULL)
+            return (reg->usage == MOJOSHADER_USAGE_POINTSIZE);
+    } // if
+
+    return scalar_register(shader_type, rtype, rnum);
+} // isscalar
+
 static const char swizzle_channels[] = { 'x', 'y', 'z', 'w' };
 
 
@@ -902,7 +919,7 @@
 
     char swizzle_str[6];
     size_t i = 0;
-    const int scalar = scalar_register(ctx->shader_type, arg->regtype, arg->regnum);
+    const int scalar = isscalar(ctx, ctx->shader_type, arg->regtype, arg->regnum);
     if (!scalar && !no_swizzle(arg->swizzle))
     {
         swizzle_str[i++] = '.';
@@ -961,7 +978,7 @@
 
     char writemask_str[6];
     size_t i = 0;
-    const int scalar = scalar_register(ctx->shader_type, arg->regtype, arg->regnum);
+    const int scalar = isscalar(ctx, ctx->shader_type, arg->regtype, arg->regnum);
     if (!scalar && !writemask_xyzw(arg->writemask))
     {
         writemask_str[i++] = '.';
@@ -1803,7 +1820,7 @@
                                                        sizeof (regnum_str));
     char writemask_str[6];
     size_t i = 0;
-    const int scalar = scalar_register(ctx->shader_type, arg->regtype, arg->regnum);
+    const int scalar = isscalar(ctx, ctx->shader_type, arg->regtype, arg->regnum);
     if (!scalar && !writemask_xyzw(arg->writemask))
     {
         writemask_str[i++] = '.';
@@ -2001,7 +2018,7 @@
     } // if
 
     char swiz_str[6] = { '\0' };
-    if (!scalar_register(ctx->shader_type, arg->regtype, arg->regnum))
+    if (!isscalar(ctx, ctx->shader_type, arg->regtype, arg->regnum))
     {
         make_GLSL_swizzle_string(swiz_str, sizeof (swiz_str),
                                  arg->swizzle, writemask);
@@ -3201,7 +3218,7 @@
                 return;
         } // switch
 
-        assert(!scalar_register(ctx->shader_type, samp_arg->regtype, samp_arg->regnum));
+        assert(!isscalar(ctx, ctx->shader_type, samp_arg->regtype, samp_arg->regnum));
         char swiz_str[6] = { '\0' };
         make_GLSL_swizzle_string(swiz_str, sizeof (swiz_str),
                                  samp_arg->swizzle, ctx->dest_arg.writemask);
@@ -3686,7 +3703,7 @@
         } // if
     } // if
 
-    const int scalar = scalar_register(ctx->shader_type, arg->regtype, arg->regnum);
+    const int scalar = isscalar(ctx, ctx->shader_type, arg->regtype, arg->regnum);
     if (!scalar && !no_swizzle(arg->swizzle))
     {
         swizzle_str[i++] = '.';
@@ -3780,7 +3797,7 @@
 
     char writemask_str[6];
     size_t i = 0;
-    const int scalar = scalar_register(ctx->shader_type, arg->regtype, arg->regnum);
+    const int scalar = isscalar(ctx, ctx->shader_type, arg->regtype, arg->regnum);
     if (!scalar && !writemask_xyzw(arg->writemask))
     {
         writemask_str[i++] = '.';
@@ -5374,7 +5391,7 @@
     info->regtype = (RegisterType) (((token >> 28) & 0x7) | ((token >> 8) & 0x18));  // bits 28-30, 11-12
 
     int writemask;
-    if (scalar_register(ctx->shader_type, info->regtype, info->regnum))
+    if (isscalar(ctx, ctx->shader_type, info->regtype, info->regnum))
         writemask = 0x1;  // just x.
     else
         writemask = info->orig_writemask;