diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.cpp b/MobileGL/MG_Backend/DirectGLES/Managers.cpp index 12772093..5fc6d168 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Managers.cpp @@ -1104,6 +1104,7 @@ namespace MobileGL::MG_Backend::DirectGLES { source = RemoveLayoutBinding(source); source = ProcessOutColorLocations(source); + source = ForceFlatIntegerVaryings(source, glShaderType); source = ForceSupporterOutput(source); // Patch for Photon compiler precision issue diff --git a/MobileGL/MG_Backend/DirectGLES/Utils.cpp b/MobileGL/MG_Backend/DirectGLES/Utils.cpp index 2ae7f27d..bf88bc30 100644 --- a/MobileGL/MG_Backend/DirectGLES/Utils.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Utils.cpp @@ -101,6 +101,37 @@ namespace MobileGL::MG_Backend::DirectGLES { return result; } + String ForceFlatIntegerVaryings(const String& glslCode, GLenum shaderType) { +#ifdef TRACY_ENABLE + ZoneScopedC(TRACY_ZONECOLOR_BACKEND); +#endif + String result = glslCode; + const String integerType = R"((?:(?:lowp|mediump|highp)\s+)?(?:u?int|[iu]vec[234])\b)"; + + auto addFlatQualifier = [&result, &integerType](const String& qualifier) { + const std::regex pattern("(layout\\s*\\([^)]*\\)\\s*)(?!(?:flat|smooth|noperspective)\\s)(" + + qualifier + "\\s+" + integerType + ")"); + result = std::regex_replace(result, pattern, "$1flat $2"); + }; + + switch (shaderType) { + case GL_VERTEX_SHADER: + addFlatQualifier("out"); + break; + case GL_GEOMETRY_SHADER: + addFlatQualifier("in"); + addFlatQualifier("out"); + break; + case GL_FRAGMENT_SHADER: + addFlatQualifier("in"); + break; + default: + break; + } + + return result; + } + String RemoveLayoutBinding(const String& glslCode) { #ifdef TRACY_ENABLE ZoneScopedC(TRACY_ZONECOLOR_BACKEND); diff --git a/MobileGL/MG_Backend/DirectGLES/Utils.h b/MobileGL/MG_Backend/DirectGLES/Utils.h index 9d0dfbca..58c02fa3 100644 --- a/MobileGL/MG_Backend/DirectGLES/Utils.h +++ b/MobileGL/MG_Backend/DirectGLES/Utils.h @@ -43,6 +43,7 @@ namespace MobileGL::MG_Backend::DirectGLES { namespace PrgramImpl { String ProcessOutColorLocations(const String& glslCode); String ForceSupporterOutput(const String& glslCode); + String ForceFlatIntegerVaryings(const String& glslCode, GLenum shaderType); String RemoveLayoutBinding(const String& glslCode); } // namespace PrgramImpl