Store pixel shader input attributes, add type data to vertex attributes
authorCaleb Cornett <caleb.cornett@outlook.com>
Mon, 04 May 2020 09:55:32 -0400
changeset 1254 422f68756c9f
parent 1253 c84325b641cc
child 1255 0135d797e287
Store pixel shader input attributes, add type data to vertex attributes
mojoshader.c
--- a/mojoshader.c	Sun May 03 09:52:42 2020 +0200
+++ b/mojoshader.c	Mon May 04 09:55:32 2020 -0400
@@ -3240,11 +3240,6 @@
                 case REG_TYPE_DEPTHOUT:
                     ignore = 1;
                     break;
-                case REG_TYPE_TEXTURE:
-                case REG_TYPE_MISCTYPE:
-                case REG_TYPE_INPUT:
-                    ignore = shader_is_pixel(ctx);
-                    break;
                 default:
                     ignore = 0;
                     break;
@@ -3252,16 +3247,11 @@
 
             if (!ignore)
             {
-                if (shader_is_pixel(ctx))
-                    fail(ctx, "BUG: pixel shader with vertex attributes");
-                else
-                {
-                    wptr->usage = item->usage;
-                    wptr->index = item->index;
-                    wptr->name = alloc_varname(ctx, item);
-                    wptr++;
-                    count++;
-                } // else
+                wptr->usage = item->usage;
+                wptr->index = item->index;
+                wptr->name = alloc_varname(ctx, item);
+                wptr++;
+                count++;
             } // if
 
             item = item->next;
@@ -3516,6 +3506,7 @@
         RegisterList *next = item->next;
         const RegisterType regtype = item->regtype;
         const int regnum = item->regnum;
+        MOJOSHADER_usage usage;
 
         if (!get_defined_register(ctx, regtype, regnum))
         {
@@ -3537,9 +3528,27 @@
 
                     // Apparently this is an attribute that wasn't DCL'd.
                     //  Add it to the attribute list; deal with it later.
-                    // !!! FIXME: we should use something other than UNKNOWN here.
-                    add_attribute_register(ctx, regtype, regnum,
-                                           MOJOSHADER_USAGE_UNKNOWN, 0, 0xF, 0);
+                    if (regtype == REG_TYPE_RASTOUT)
+                    {
+                        if ((RastOutType) regnum == RASTOUT_TYPE_POSITION)
+                            usage = MOJOSHADER_USAGE_POSITION;
+                        else if ((RastOutType) regnum == RASTOUT_TYPE_FOG)
+                            usage = MOJOSHADER_USAGE_FOG;
+                        else if ((RastOutType) regnum==RASTOUT_TYPE_POINT_SIZE)
+                            usage = MOJOSHADER_USAGE_POINTSIZE;
+                    } // if
+                    else if (regtype == REG_TYPE_ATTROUT ||
+                             regtype == REG_TYPE_COLOROUT)
+                    {
+                        usage = MOJOSHADER_USAGE_COLOR;
+                    } // else if
+                    else if (regtype == REG_TYPE_TEXCRDOUT)
+                        usage = MOJOSHADER_USAGE_TEXCOORD;
+                    else if (regtype == REG_TYPE_DEPTHOUT)
+                        usage = MOJOSHADER_USAGE_DEPTH;
+
+                    add_attribute_register(ctx, regtype, regnum, usage,
+                                           regnum, 0xF, 0);
                     break;
 
                 case REG_TYPE_ADDRESS: