Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable GLSL compiler optimization

Tags:

opengl

glsl

I am using OpenGL 4.2 with GLSL 420 .I need to prevent the GLSL compiler from optimizing out unused uniforms as those serve for occasional tests. I have tried to put:

#version 420
#pragma optimize (off)
...
......

But it seems to have no effect.The compiler still cleans all the unused uniforms.I am running on NVidia drivers v319 on Linux with GeForce 680GTX

like image 689
Michael IV Avatar asked Jan 09 '14 09:01

Michael IV


1 Answers

Inactive uniform determination is not an optimization. It is a consequence of how unextended GLSL programs work, they are compiled and then linked together and because of this implementations know exactly which paths contribute to actual pipeline output. Some implementations are smarter about this than others and will eliminate code paths (including uniforms) across each stage of the program if it produces no output in the fragment shader/transform feedback.

OpenGL 4.4 Core Profile Specification - 7.6 Uniform Variables - pp. 117

7.6 Uniform Variables

Shaders can declare named uniform variables, as described in the OpenGL Shading Language Specification . A uniform is considered an active uniform if the compiler and linker determine that the uniform will actually be accessed when the executable code is executed. In cases where the compiler and linker cannot make a conclusive determination, the uniform will be considered active.

How far an implementation takes this definition of an active uniform could be considered an optimization... but the actual process of doing this is not. I have an explanation of how NV's implementation of GLSL effectively does active uniform determination here.

I mentioned unextended GLSL programs, because Separate Shader Objects really throws a wrench into things. Using that extension, each program may represent exactly 1 stage of the pipeline and there is no way to determine whether a uniform used in one stage actually has an affect on the final output. Going by the formal definition of an active uniform, when SSOs are used the implementation must assume that if it is used in one stage it is active.

The bottom line is, changing the optimization level is not going to change this behavior.

like image 191
Andon M. Coleman Avatar answered Nov 11 '22 04:11

Andon M. Coleman