From 9753201b2180c7c0236f6e18180829b788be4a6f Mon Sep 17 00:00:00 2001 From: Dunfan Lu Date: Fri, 15 Sep 2023 14:21:19 -0700 Subject: [PATCH] Always use GLSL ES 100 shaders in swift shaders Summary: OpenGL ES 3 on rainbow has a bug, which originates from a bug in swiftshaders. the issue is that swiftshaders is returning -1 when we use ``` glGetActiveUniformsiv(,..,GL_UNIFORM_OFFSET, ...) ``` to query the offset of a member in a uniform buffer. We believe this is a swift shaders bug, so we work around this by always using GLSL es 100 shaders on rainbow Reviewed By: dmannemela, syeh1 Differential Revision: D49329247 fbshipit-source-id: 54a8245704d932e7984e7521bef9d28367d1e416 --- src/igl/opengl/Version.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/igl/opengl/Version.cpp b/src/igl/opengl/Version.cpp index 6b7084cff2..3bd52fcb3d 100644 --- a/src/igl/opengl/Version.cpp +++ b/src/igl/opengl/Version.cpp @@ -223,6 +223,13 @@ GLVersion getGLVersion(const char* version, bool constrain) { } ShaderVersion getShaderVersion(GLVersion version) { +#if IGL_PLATFORM_LINUX_SWIFTSHADER + // Swiftshader has a bug when it comes to uniform blocks. When calling + // `glGetActiveUniformsiv(,..,GL_UNIFORM_OFFSET, ...)`, it always returns -1. We work around this + // by forcing GLSL ES 100 shaders in swiftshaders. + // TODO(dunfanlu): consider patching swift shaders to fix this. + return {ShaderFamily::GlslEs, 1, 0}; +#else // TODO: Return proper GLSL ES versions switch (version) { case GLVersion::v2_0_ES: @@ -263,6 +270,7 @@ ShaderVersion getShaderVersion(GLVersion version) { IGL_ASSERT_NOT_REACHED(); return {}; } +#endif } std::string getStringFromShaderVersion(ShaderVersion version) {