From bb8b653e4ad6e3be464fd7f30dfb52831d533c17 Mon Sep 17 00:00:00 2001 From: Caleb Cornett Date: Sat, 6 Apr 2024 13:58:49 -0500 Subject: [PATCH] Remove color relocation logic for non-glspirv profiles --- mojoshader_common.c | 58 +++++++++++++++++++++++-------------------- mojoshader_internal.h | 3 ++- mojoshader_opengl.c | 2 +- mojoshader_vulkan.c | 2 +- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/mojoshader_common.c b/mojoshader_common.c index 99e6702..39cb5c0 100644 --- a/mojoshader_common.c +++ b/mojoshader_common.c @@ -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; @@ -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++) @@ -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! @@ -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]) diff --git a/mojoshader_internal.h b/mojoshader_internal.h index 945774c..0798fd1 100644 --- a/mojoshader_internal.h +++ b/mojoshader_internal.h @@ -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_ diff --git a/mojoshader_opengl.c b/mojoshader_opengl.c index 9e7638b..04eaed0 100644 --- a/mojoshader_opengl.c +++ b/mojoshader_opengl.c @@ -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) { diff --git a/mojoshader_vulkan.c b/mojoshader_vulkan.c index 8482d64..98f7ad3 100644 --- a/mojoshader_vulkan.c +++ b/mojoshader_vulkan.c @@ -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;