3

For example, my vertex shader:

...
attribute vec2 uTexCoord;
uniform float a, b, c;
out vec2 texCoord;
...
void main() {
    ...
    texCoord = uTexCoord * a * b * c;
    ...
}

And my fragment shader:

...
in vec2 texCoord;
uniform vec4 color;
layout(location = 0) out vec4 fragColor;
...
void main() {
    ...
    fragColor = color;

}

Which variables will be considered unnecessary and will be deleted?

Or better to use #ifdef to exclude such code portions?

congard
  • 945
  • 2
  • 10
  • 28
  • 1
    The uniforms `a`, `b`, `c` and the attribute `uTexCoord` – Rabbid76 Oct 27 '18 at 13:20
  • @Rabbid76 ie the presence of such unused variables will not affect further performance? – congard Oct 27 '18 at 13:23
  • 3
    Is this question related to OpenGL or Vulkan? In OpenGL the GLSL code is compiled and linked by the driver, so it depends on the driver. But with a modern hardware and driver, it will probably not affect the performance. – Rabbid76 Oct 27 '18 at 13:31
  • 2
    In my experience, yes, the driver will remove unused variables *and* you have to be aware of it because glGetAttribLocation("uTexCoord") will return -1. – user253751 Oct 28 '18 at 21:29
  • 1
    Most drivers at link time will analyze shader and intialize handle to uniforms not used to -1 this is will do get some performance as those variables will be removed from code. – Paritosh Kulkarni Oct 30 '18 at 01:08

0 Answers0