mojoshader_common.c
changeset 1303 7a43f238f28a
parent 1301 79bbc92200dc
child 1318 ff4eb6d9c9c2
equal deleted inserted replaced
1302:974d2cc3558e 1303:7a43f238f28a
  1060 #include "spirv/GLSL.std.450.h"
  1060 #include "spirv/GLSL.std.450.h"
  1061 void MOJOSHADER_spirv_link_attributes(const MOJOSHADER_parseData *vertex,
  1061 void MOJOSHADER_spirv_link_attributes(const MOJOSHADER_parseData *vertex,
  1062                                       const MOJOSHADER_parseData *pixel)
  1062                                       const MOJOSHADER_parseData *pixel)
  1063 {
  1063 {
  1064     int i;
  1064     int i;
  1065     uint32 attr_loc = 1; // 0 is reserved for COLOR0
  1065     uint32 attr_loc = 0;
  1066     uint32 vOffset, pOffset;
  1066     uint32 vOffset, pOffset;
  1067     int vDataLen = vertex->output_len - sizeof(SpirvPatchTable);
  1067     int vDataLen = vertex->output_len - sizeof(SpirvPatchTable);
  1068     int pDataLen = pixel->output_len - sizeof(SpirvPatchTable);
  1068     int pDataLen = pixel->output_len - sizeof(SpirvPatchTable);
  1069     SpirvPatchTable *vTable = (SpirvPatchTable *) &vertex->output[vDataLen];
  1069     SpirvPatchTable *vTable = (SpirvPatchTable *) &vertex->output[vDataLen];
  1070     SpirvPatchTable *pTable = (SpirvPatchTable *) &pixel->output[pDataLen];
  1070     SpirvPatchTable *pTable = (SpirvPatchTable *) &pixel->output[pDataLen];
  1073     // We need locations for color outputs first!
  1073     // We need locations for color outputs first!
  1074     for (i = 0; i < pixel->output_count; i ++)
  1074     for (i = 0; i < pixel->output_count; i ++)
  1075     {
  1075     {
  1076         const MOJOSHADER_attribute *pAttr = &pixel->outputs[i];
  1076         const MOJOSHADER_attribute *pAttr = &pixel->outputs[i];
  1077         assert(pAttr->usage == MOJOSHADER_USAGE_COLOR);
  1077         assert(pAttr->usage == MOJOSHADER_USAGE_COLOR);
  1078         if (pAttr->index == 0)
  1078 
  1079             continue;
  1079         // Set the loc for the output declaration...
  1080 
  1080         pOffset = pTable->output_offsets[pAttr->index];
       
  1081         assert(pOffset > 0);
       
  1082         ((uint32 *) pixel->output)[pOffset] = attr_loc;
       
  1083 
       
  1084         // Set the same value for the vertex output/pixel input...
  1081         pOffset = pTable->attrib_offsets[pAttr->usage][pAttr->index];
  1085         pOffset = pTable->attrib_offsets[pAttr->usage][pAttr->index];
  1082         ((uint32 *) pixel->output)[pOffset] = attr_loc;
  1086         if (pOffset)
       
  1087             ((uint32 *) pixel->output)[pOffset] = attr_loc;
       
  1088         vOffset = vTable->attrib_offsets[pAttr->usage][pAttr->index];
       
  1089         if (vOffset)
       
  1090             ((uint32 *) vertex->output)[vOffset] = attr_loc;
       
  1091 
       
  1092         // ... increment location index, finally.
  1083         attr_loc++;
  1093         attr_loc++;
  1084     } // for
  1094     } // for
  1085 
  1095 
  1086     // Okay, now we can start linking pixel/vertex attributes
  1096     // Okay, now we can start linking pixel/vertex attributes
  1087     for (i = 0; i < pixel->attribute_count; i++)
  1097     for (i = 0; i < pixel->attribute_count; i++)
  1088     {
  1098     {
  1089         const MOJOSHADER_attribute *pAttr = &pixel->attributes[i];
  1099         const MOJOSHADER_attribute *pAttr = &pixel->attributes[i];
  1090         if (pAttr->usage == MOJOSHADER_USAGE_UNKNOWN)
  1100         if (pAttr->usage == MOJOSHADER_USAGE_UNKNOWN)
  1091             continue; // Probably something like VPOS, ignore!
  1101             continue; // Probably something like VPOS, ignore!
  1092         if (pAttr->usage == MOJOSHADER_USAGE_COLOR && pAttr->index == 0)
  1102         if (pAttr->usage == MOJOSHADER_USAGE_COLOR && pTable->output_offsets[pAttr->index])
  1093             continue;
  1103             continue;
  1094 
  1104 
  1095         // The input may not exist in the output list!
  1105         // The input may not exist in the output list!
  1096         pOffset = pTable->attrib_offsets[pAttr->usage][pAttr->index];
  1106         pOffset = pTable->attrib_offsets[pAttr->usage][pAttr->index];
  1097         vOffset = vTable->attrib_offsets[pAttr->usage][pAttr->index];
  1107         vOffset = vTable->attrib_offsets[pAttr->usage][pAttr->index];
  1108         assert(vAttr->usage != MOJOSHADER_USAGE_UNKNOWN);
  1118         assert(vAttr->usage != MOJOSHADER_USAGE_UNKNOWN);
  1109         if (vAttr->usage == MOJOSHADER_USAGE_POSITION && vAttr->index == 0)
  1119         if (vAttr->usage == MOJOSHADER_USAGE_POSITION && vAttr->index == 0)
  1110             continue;
  1120             continue;
  1111         if (vAttr->usage == MOJOSHADER_USAGE_POINTSIZE && vAttr->index == 0)
  1121         if (vAttr->usage == MOJOSHADER_USAGE_POINTSIZE && vAttr->index == 0)
  1112             continue;
  1122             continue;
  1113         if (vAttr->usage == MOJOSHADER_USAGE_COLOR && vAttr->index == 0)
  1123         if (vAttr->usage == MOJOSHADER_USAGE_COLOR && pTable->output_offsets[vAttr->index])
  1114             continue;
  1124             continue;
  1115 
  1125 
  1116         if (!pTable->attrib_offsets[vAttr->usage][vAttr->index])
  1126         if (!pTable->attrib_offsets[vAttr->usage][vAttr->index])
  1117         {
  1127         {
  1118             vOffset = vTable->attrib_offsets[vAttr->usage][vAttr->index];
  1128             vOffset = vTable->attrib_offsets[vAttr->usage][vAttr->index];