Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mesa drivers] Error: #extension directive is not allowed in the middle of a shader #10

Open
Dragorn421 opened this issue Aug 24, 2024 · 0 comments

Comments

@Dragorn421
Copy link
Contributor

Environment: Mesa driver

Note this issue has only popped up with Mesa drivers so far but it's not a Mesa drivers bug/problem, it's a Blender limitation / consequence of a f64render hack. See Explanation below for more details

Compiling shader
ERROR (gpu.shader): pyGPU_Shader FragShader: 
      | 
  538 |   #extension GL_ARB_fragment_shader_interlock : enable
      |  ^
      | Error: #extension directive is not allowed in the middle of a shader

Traceback (most recent call last):
    [...]
    self.shader = gpu.shader.create_from_info(shader_info)      
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: Shader Compile Error, see console for more details

Workarounds

Workaround 1: Allow mid-shader extension directives

Set environment variable allow_glsl_extension_directive_midshader=true (source: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7850 )

For example, allow_glsl_extension_directive_midshader=true blender

Workaround 2: Make f64render not use the extension

Change shader_interlock_support to False

self.shader_interlock_support = 'GL_ARB_fragment_shader_interlock' in ext_list

->

    self.shader_interlock_support = False

Explanation

The Blender gpu Python module prepends some stuff to the shader source, causing the #extension directive from f64render to not be at the start of the final shader source that's sent to the driver.
However per spec the #extension directives should be at the start of the shader.
Some drivers are lax enough to allow #extension anywhere, which is not the case of Mesa drivers by default. This can be overriden with the allow_glsl_extension_directive_midshader environment variable as indicated in the Workaround 1 above.

The Blender gpu Python module does not support enabling extensions like this in the shader source, because shaders should be platform agnostic. And using #extension only works with OpenGL, not Metal nor Vulkan apparently. (source: https://projects.blender.org/blender/blender/issues/126071 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant