Skip to content

GLSL compiling error when using MESA llvm driver

Hi,

My user experienced GLSL compiling error when using MESA software rendering. The error message is:

ERROR::SHADER::VERTEX::COMPILATION_FAILED
0:14(10): error: `gl_Position' redeclared

ERROR::SHADER::PROGRAM::LINKING_FAILED
error: linking with uncompiled/unspecialized shader
ERROR::SHADER::VERTEX::COMPILATION_FAILED
0:2(12): warning: extension `GL_EXT_clip_cull_distance' unsupported in vertex shader
0:5(7): error: redeclaration cannot change qualification of `gl_ClipDistance'

Here is my setup:

Extended renderer info (GLX_MESA_query_renderer):
  ┊ Vendor: Mesa/X.org (0xffffffff)
  ┊ Device: llvmpipe (LLVM 10.0.1, 256 bits) (0xffffffff)
  ┊ Version: 20.2.3
  ┊ Accelerated: no
  ┊ Video memory: 128832MB
  ┊ Unified memory: no
  ┊ Preferred profile: core (0x1)
  ┊ Max core profile version: 4.5
  ┊ Max compat profile version: 3.1
  ┊ Max GLES1 profile version: 1.1
  ┊ Max GLES[23] profile version: 3.2
OpenGL vendor string: Mesa/X.org
OpenGL renderer string: llvmpipe (LLVM 10.0.1, 256 bits)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 20.2.3
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

I can also confirm that the profile and extension required by the shaders are available:

OpenGL ES profile version string: OpenGL ES 3.2 Mesa 20.2.3
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:
...
  ┊ GL_EXT_clip_control, GL_EXT_clip_cull_distance, GL_EXT_color_buffer_float,
  ┊ GL_EXT_separate_shader_objects,
...

Here is my fix:

diff -ur src/render_func.h src.b/render_func.h
--- src/render_func.h	2021-03-09 08:34:49.000000000 -0500
+++ src.b/render_func.h	2021-04-14 23:53:32.361493921 -0400
@@ -184,7 +184,6 @@
     "out vec3  Color;\n"
     "out float Opaque;\n"
     "out vec4  matProps;\n"
-    "out vec4  gl_Position;\n"
     "out vec3  LightDir;\n"
     "out float ptSz;\n"
     "\n"
diff -ur src/select_util.h src.b/select_util.h
--- src/select_util.h	2021-03-09 08:34:49.000000000 -0500
+++ src.b/select_util.h	2021-04-14 23:45:11.682603441 -0400
@@ -8,11 +8,11 @@
 inline int get_select_shader()
 {
   const char *vertexShaderSource =
-    "#version 400 core\n"
+    "#version 410 core\n"
     "#extension GL_EXT_clip_cull_distance : enable\n"
     "layout (location = 0) in vec3  aPos;\n"
     "layout (location = 1) in vec4  aColor;\n"
-    "float gl_ClipDistance[6];\n"
+    "out float gl_ClipDistance[6];\n"
     "\n"
     "out vec3  Pos;\n"
     "out vec3  FragPos;\n"

meshalyzer_2.2_mesa_software_rendering.patch

I very rarely do OpenGL coding, so i do not know if my fix will cause other issue. But I hope it save you guys some time troubleshooting.

Best,
Min Dong