3

我不知道制服在记忆中是如何表示的。

制服似乎可以占用宝贵的寄存器空间,但它们最终会传入/通过/传出到全局内存中,对吧?

当制服未使用时,情况是否会发生变化?编译器可以优化它们吗?--在这种情况下,我将无效 (-1) 作为绑定位置,所以我假设是的。

4

2 回答 2

3

Uniforms are represented in whatever manor the GLSL compiler and OpenGL implementation deem fit. Some implementations make certain uniforms actual constants within the assembly, such that changing a uniform is actually patching the assembly in-situ. Some have special memory for uniforms.

It's all hardware dependent.

Compilers are allowed to optimize uniforms out; this is where the term "active uniform" comes from. The OpenGL API for querying uniform information only works for active uniforms: those that are actually detected to be in-use by the compiler.

于 2012-08-27T20:40:47.450 回答
2

首先,GLSL 规范并没有说明其概念的实际实现,因此以下阐述当然可以理解为“可以是任何方式,但现在通常是这样”。

至于我(可能是有限的)关于图形硬件的知识,制服通常存在于所谓的常量内存中,它是全局设备内存的一部分(并且在较新的硬件上甚至应该被缓存),因为它们不能被着色器更改无论如何程序,并且对于程序的所有调用都是全局的(可以并且应该在不同的多处理器上并行运行)。因此它们本身不占用任何每个多处理器的寄存器空间。

您也是对的,GLSL 编译器可以(并且通常会)优化掉任何未使用的统一(以及属性),但前提是这些不用于任何可能的执行分支,当然。因此,您在获得统一位置时所经历的-1是完全有效(并且通常是所需)的行为。

于 2012-08-27T20:34:59.093 回答