禁用GLSL编译器优化 [英] Disable GLSL compiler optimization

查看:133
本文介绍了禁用GLSL编译器优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将OpenGL 4.2与GLSL 420配合使用.我需要防止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)
...
......

但是似乎没有作用.编译器仍会清理所有未使用的制服.我正在使用GeForce 680GTX在Linux上的NVidia驱动程序v319上运行

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

推荐答案

无效的统一确定是 不是 的一种优化.这是未扩展的GLSL程序如何工作的结果,它们被编译然后链接在一起,并且由于这种实现方式确切地知道哪些路径对实际管道输出有所贡献.一些实现比其他实现更聪明,并且如果在片段着色器/转换反馈中不产生任何输出,则将消除程序各个阶段的代码路径(包括统一).

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.

7.6统一变量

如OpenGL Shading Language Specification中所述,着色器可以声明命名的统一变量.如果编译器和链接器确定在执行可执行代码时实际上将访问该制服,则该制服被视为活动制服.如果编译器和链接器无法做出确定的确定,则该制服将被视为有效.

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.

实现在多大程度上可以定义这种活动制服,这可以被认为是一种优化……但是,这样做的实际过程却并非如此.我已经解释了NV的GLSL实施如何有效地进行主动统一确定此处

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.

我提到了未扩展的GLSL程序,因为单独的着色器对象确实使事情陷入了困境.使用该扩展名,每个程序都可以恰好代表流水线的一个阶段,并且无法确定一个阶段中使用的制服是否确实对最终输出产生影响.按照 active 制服的正式定义,使用SSO时,实现必须假定如果在一个阶段中使用它,则它是激活的.

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.

这篇关于禁用GLSL编译器优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆