profiles/mojoshader_profile_spirv.c
changeset 1303 7a43f238f28a
parent 1299 02d36217591b
child 1318 ff4eb6d9c9c2
equal deleted inserted replaced
1302:974d2cc3558e 1303:7a43f238f28a
   268     push_output(ctx, &ctx->helpers);
   268     push_output(ctx, &ctx->helpers);
   269     spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationLocation, loc);
   269     spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationLocation, loc);
   270     pop_output(ctx);
   270     pop_output(ctx);
   271     return (buffer_size(ctx->helpers) >> 2) - 1;
   271     return (buffer_size(ctx->helpers) >> 2) - 1;
   272 } // spv_output_location
   272 } // spv_output_location
       
   273 
       
   274 static void spv_output_color_location(Context *ctx, uint32 id, uint32 index)
       
   275 {
       
   276     SpirvPatchTable* table = &ctx->spirv.patch_table;
       
   277     push_output(ctx, &ctx->helpers);
       
   278     spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationLocation, index);
       
   279     pop_output(ctx);
       
   280     table->output_offsets[index] = (buffer_size(ctx->helpers) >> 2) - 1;
       
   281 } // spv_output_color_location
   273 
   282 
   274 static void spv_output_attrib_location(Context *ctx, uint32 id,
   283 static void spv_output_attrib_location(Context *ctx, uint32 id,
   275                                        MOJOSHADER_usage usage, uint32 index)
   284                                        MOJOSHADER_usage usage, uint32 index)
   276 {
   285 {
   277     SpirvPatchTable* table = &ctx->spirv.patch_table;
   286     SpirvPatchTable* table = &ctx->spirv.patch_table;
  1630     else if (usage == MOJOSHADER_USAGE_POINTSIZE && index == 0)
  1639     else if (usage == MOJOSHADER_USAGE_POINTSIZE && index == 0)
  1631     {
  1640     {
  1632         spv_output_builtin(ctx, id, SpvBuiltInPointSize);
  1641         spv_output_builtin(ctx, id, SpvBuiltInPointSize);
  1633         ctx->spirv.patch_table.attrib_offsets[usage][index] = 1;
  1642         ctx->spirv.patch_table.attrib_offsets[usage][index] = 1;
  1634     } // else if
  1643     } // else if
  1635     else if (usage == MOJOSHADER_USAGE_COLOR && index == 0)
       
  1636         spv_output_location(ctx, id, 0);
       
  1637     else
  1644     else
  1638         spv_output_attrib_location(ctx, id, usage, index);
  1645         spv_output_attrib_location(ctx, id, usage, index);
  1639 } // spv_link_vs_attributes
  1646 } // spv_link_vs_attributes
  1640 
  1647 
  1641 static void spv_link_ps_attributes(Context *ctx, uint32 id, RegisterType regtype,
  1648 static void spv_link_ps_attributes(Context *ctx, uint32 id, RegisterType regtype,
  1650             // is allowed can still write to it, but it only means to write to an output:
  1657             // is allowed can still write to it, but it only means to write to an output:
  1651             // - of the same type as gl_FragColor
  1658             // - of the same type as gl_FragColor
  1652             // - decorated with location 0
  1659             // - decorated with location 0
  1653             // - not decorated as a built-in variable.
  1660             // - not decorated as a built-in variable.
  1654             // There is no implicit broadcast.
  1661             // There is no implicit broadcast.
  1655             if (index == 0)
  1662             spv_output_color_location(ctx, id, index);
  1656                 spv_output_location(ctx, id, 0);
       
  1657             else
       
  1658                 spv_output_attrib_location(ctx, id, MOJOSHADER_USAGE_COLOR, index);
       
  1659             break;
  1663             break;
  1660         case REG_TYPE_INPUT: // v# (MOJOSHADER_USAGE_COLOR aka `oC#` in vertex shader)
  1664         case REG_TYPE_INPUT: // v# (MOJOSHADER_USAGE_COLOR aka `oC#` in vertex shader)
  1661             if (usage == MOJOSHADER_USAGE_COLOR && index == 0)
  1665             spv_output_attrib_location(ctx, id, usage, index);
  1662                 spv_output_location(ctx, id, 0);
       
  1663             else
       
  1664                 spv_output_attrib_location(ctx, id, usage, index);
       
  1665             break;
  1666             break;
  1666         case REG_TYPE_TEXTURE: // t# (MOJOSHADER_USAGE_TEXCOORD aka `oT#` in vertex shader)
  1667         case REG_TYPE_TEXTURE: // t# (MOJOSHADER_USAGE_TEXCOORD aka `oT#` in vertex shader)
  1667             spv_output_attrib_location(ctx, id, MOJOSHADER_USAGE_TEXCOORD, index);
  1668             spv_output_attrib_location(ctx, id, MOJOSHADER_USAGE_TEXCOORD, index);
  1668             break;
  1669             break;
  1669         case REG_TYPE_DEPTHOUT:
  1670         case REG_TYPE_DEPTHOUT:
  2623 
  2624 
  2624     for (i = 0; i < MOJOSHADER_USAGE_TOTAL; i++)
  2625     for (i = 0; i < MOJOSHADER_USAGE_TOTAL; i++)
  2625         for (j = 0; j < 16; j++)
  2626         for (j = 0; j < 16; j++)
  2626             if (table->attrib_offsets[i][j])
  2627             if (table->attrib_offsets[i][j])
  2627                 table->attrib_offsets[i][j] += base_offset;
  2628                 table->attrib_offsets[i][j] += base_offset;
       
  2629     for (i = 0; i < 16; i++)
       
  2630         if (table->output_offsets[i])
       
  2631             table->output_offsets[i] += base_offset;
  2628 
  2632 
  2629     push_output(ctx, &ctx->postflight);
  2633     push_output(ctx, &ctx->postflight);
  2630     buffer_append(ctx->output, &ctx->spirv.patch_table, sizeof(ctx->spirv.patch_table));
  2634     buffer_append(ctx->output, &ctx->spirv.patch_table, sizeof(ctx->spirv.patch_table));
  2631     pop_output(ctx);
  2635     pop_output(ctx);
  2632 
  2636