Declaring constants instead of literals in vertex shader. Standard practice, or needless rigor?

妖精的绣舞 提交于 2019-12-01 06:01:17

Regarding Kimi's mention about not finding anything in the spec, Appendix A-7 of The OpenGL® ES Shading Language spec does include the following:

When calculating the number of uniform variables used, any literal constants present in the shader source after preprocessing are included when calculating the storage requirements. Multiple instances of identical constants should count multiple times.

This is probably the source of the recommendation in OpenGL® ES 2.0 Programming Guide that Kimi quotes.

However, the spec does not mandate this restriction, and presumably any implementation is free to improve on it, but I cannot find anything either way regarding the iOS GL drivers.

I'm curious, did anyone actually follow up on the ideas of overloading a sample shader with literals, in an attempt to reach any potential maximum uniform limit?

(Sorry...I had intended to post this answer as a comment to Kimi's answer, but don't have the required 50 Rep points yet).

From the OpenGL® ES 2.0 Programming Guide

As far as literal values are concerned, the OpenGL ES 2.0 shading language spec states that no constant propagation is assumed. This means that multiple instances of the same literal value(s) will be counted multiple times. Instead of using literal values, appropriate const variables should be declared. This avoids having the same literal value count multiple times, which might cause the vertex shader to fail to compile if vertex uniform storage requirements exceed what the implementation supports.

I could not find anything related to this in the actual spec. Also there is no information specific to the iOS.

Also you can check a GLSL Optimizer tool written to tackle this issue (and lots of others).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!