Write locations for SPIR-V pixel shader outputs
authorEthan Lee <flibitijibibo@flibitijibibo.com>
Wed, 26 Aug 2020 14:37:18 -0400
changeset 1301 79bbc92200dc
parent 1300 f1cdc5187d53
child 1302 974d2cc3558e
Write locations for SPIR-V pixel shader outputs
mojoshader_common.c
--- a/mojoshader_common.c	Tue Aug 25 22:41:43 2020 -0400
+++ b/mojoshader_common.c	Wed Aug 26 14:37:18 2020 -0400
@@ -1070,6 +1070,20 @@
     SpirvPatchTable *pTable = (SpirvPatchTable *) &pixel->output[pDataLen];
     const uint32 texcoord0Loc = pTable->attrib_offsets[MOJOSHADER_USAGE_TEXCOORD][0];
 
+    // We need locations for color outputs first!
+    for (i = 0; i < pixel->output_count; i ++)
+    {
+        const MOJOSHADER_attribute *pAttr = &pixel->outputs[i];
+        assert(pAttr->usage == MOJOSHADER_USAGE_COLOR);
+        if (pAttr->index == 0)
+            continue;
+
+        pOffset = pTable->attrib_offsets[pAttr->usage][pAttr->index];
+        ((uint32 *) pixel->output)[pOffset] = attr_loc;
+        attr_loc++;
+    } // for
+
+    // Okay, now we can start linking pixel/vertex attributes
     for (i = 0; i < pixel->attribute_count; i++)
     {
         const MOJOSHADER_attribute *pAttr = &pixel->attributes[i];
@@ -1104,7 +1118,7 @@
             vOffset = vTable->attrib_offsets[vAttr->usage][vAttr->index];
             ((uint32 *) vertex->output)[vOffset] = attr_loc++;
         } // if
-    } // while
+    } // for
 
     // gl_PointCoord support
     if (texcoord0Loc)