Skip to content

Commit

Permalink
Remove color relocation logic for non-glspirv profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpydog authored and flibitijibibo committed Apr 6, 2024
1 parent aaba69d commit bb8b653
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
58 changes: 31 additions & 27 deletions mojoshader_common.c
Expand Up @@ -1059,7 +1059,8 @@ size_t MOJOSHADER_printFloat(char *text, size_t maxlen, float arg)
#include "spirv/spirv.h"
#include "spirv/GLSL.std.450.h"
void MOJOSHADER_spirv_link_attributes(const MOJOSHADER_parseData *vertex,
const MOJOSHADER_parseData *pixel)
const MOJOSHADER_parseData *pixel,
int is_glspirv)
{
int i;
uint32 attr_loc = 0;
Expand All @@ -1070,33 +1071,36 @@ void MOJOSHADER_spirv_link_attributes(const MOJOSHADER_parseData *vertex,
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++)
if (is_glspirv)
{
const MOJOSHADER_attribute *pAttr = &pixel->outputs[i];
if (pAttr->usage != MOJOSHADER_USAGE_COLOR)
// We need locations for color outputs first!
for (i = 0; i < pixel->output_count; i++)
{
// This should be FragDepth, which is builtin
assert(pAttr->usage == MOJOSHADER_USAGE_DEPTH);
continue;
} // if

// Set the loc for the output declaration...
pOffset = pTable->output_offsets[pAttr->index];
assert(pOffset > 0);
((uint32 *) pixel->output)[pOffset] = attr_loc;

// Set the same value for the vertex output/pixel input...
pOffset = pTable->attrib_offsets[pAttr->usage][pAttr->index];
if (pOffset)
((uint32 *) pixel->output)[pOffset] = attr_loc;
vOffset = vTable->attrib_offsets[pAttr->usage][pAttr->index];
if (vOffset)
((uint32 *) vertex->output)[vOffset] = attr_loc;
const MOJOSHADER_attribute* pAttr = &pixel->outputs[i];
if (pAttr->usage != MOJOSHADER_USAGE_COLOR)
{
// This should be FragDepth, which is builtin
assert(pAttr->usage == MOJOSHADER_USAGE_DEPTH);
continue;
} // if

// ... increment location index, finally.
attr_loc++;
} // for
// Set the loc for the output declaration...
pOffset = pTable->output_offsets[pAttr->index];
assert(pOffset > 0);
((uint32*)pixel->output)[pOffset] = attr_loc;

// Set the same value for the vertex output/pixel input...
pOffset = pTable->attrib_offsets[pAttr->usage][pAttr->index];
if (pOffset)
((uint32*)pixel->output)[pOffset] = attr_loc;
vOffset = vTable->attrib_offsets[pAttr->usage][pAttr->index];
if (vOffset)
((uint32*)vertex->output)[vOffset] = attr_loc;

// ... increment location index, finally.
attr_loc++;
} // for
}

// Okay, now we can start linking pixel/vertex attributes
for (i = 0; i < pixel->attribute_count; i++)
Expand All @@ -1106,7 +1110,7 @@ void MOJOSHADER_spirv_link_attributes(const MOJOSHADER_parseData *vertex,
continue; // Probably something like VPOS, ignore!
if (pAttr->usage == MOJOSHADER_USAGE_DEPTH)
continue; // This should be FragDepth, which is builtin
if (pAttr->usage == MOJOSHADER_USAGE_COLOR && pTable->output_offsets[pAttr->index])
if (is_glspirv && pAttr->usage == MOJOSHADER_USAGE_COLOR && pTable->output_offsets[pAttr->index])
continue;

// The input may not exist in the output list!
Expand All @@ -1127,7 +1131,7 @@ void MOJOSHADER_spirv_link_attributes(const MOJOSHADER_parseData *vertex,
continue;
if (vAttr->usage == MOJOSHADER_USAGE_POINTSIZE && vAttr->index == 0)
continue;
if (vAttr->usage == MOJOSHADER_USAGE_COLOR && pTable->output_offsets[vAttr->index])
if (is_glspirv && vAttr->usage == MOJOSHADER_USAGE_COLOR && pTable->output_offsets[vAttr->index])
continue;

if (!pTable->attrib_offsets[vAttr->usage][vAttr->index])
Expand Down
3 changes: 2 additions & 1 deletion mojoshader_internal.h
Expand Up @@ -789,7 +789,8 @@ typedef struct SpirvPatchTable
} SpirvPatchTable;

void MOJOSHADER_spirv_link_attributes(const MOJOSHADER_parseData *vertex,
const MOJOSHADER_parseData *pixel);
const MOJOSHADER_parseData *pixel,
int is_glspirv);
#endif

#endif // _INCLUDE_MOJOSHADER_INTERNAL_H_
Expand Down
2 changes: 1 addition & 1 deletion mojoshader_opengl.c
Expand Up @@ -529,7 +529,7 @@ static GLuint impl_SPIRV_LinkProgram(MOJOSHADER_glShader *vshader,
// other shader stages to assign final uniform/attrib locations before
// compilation.

MOJOSHADER_spirv_link_attributes(vshader->parseData, pshader->parseData);
MOJOSHADER_spirv_link_attributes(vshader->parseData, pshader->parseData, 1);

if (vshader)
{
Expand Down
2 changes: 1 addition & 1 deletion mojoshader_vulkan.c
Expand Up @@ -668,7 +668,7 @@ MOJOSHADER_vkProgram *MOJOSHADER_vkLinkProgram(MOJOSHADER_vkContext *ctx,
return NULL;
} // if

MOJOSHADER_spirv_link_attributes(vshader->parseData, pshader->parseData);
MOJOSHADER_spirv_link_attributes(vshader->parseData, pshader->parseData, 0);
result->vertexModule = compile_shader(ctx, vshader);
result->pixelModule = compile_shader(ctx, pshader);
result->vertexShader = vshader;
Expand Down

0 comments on commit bb8b653

Please sign in to comment.