I've optimized some math in my shader - got rid of unnecessary uniform computations by offloading them to CPU.
When testing old vs new shader against G52 and G76 targets (Bifrost) I see that `Has uniform computation` changed from `true` to `false`, and number or used uniform registers reduced from 12 to 16.
However, when target is Valhall (either 1st or 2nd gen) GPUs, the results are rather strange. For some reason, compiler still detects uniform computations, and outputs are identical for both new and old shaders.
Old shader:
#extension GL_ARM_shader_framebuffer_fetch_depth_stencil : enable precision highp float; uniform vec2 uCameraRange; uniform float uTransitionSize; float calc_depth(in float z) { return (2.0 * uCameraRange.x) / (uCameraRange.y + uCameraRange.x - z*(uCameraRange.y - uCameraRange.x)); } varying vec2 vTextureCoord; uniform sampler2D sTexture; uniform vec4 color; void main() { vec4 diffuse = texture2D(sTexture, vTextureCoord) * color; float geometryZ = calc_depth(gl_LastFragDepthARM); float sceneZ = calc_depth(gl_FragCoord.z); float a = clamp(geometryZ - sceneZ, 0.0, 1.0); float b = smoothstep(0.0, uTransitionSize, a); gl_FragColor = diffuse * b; }
New shader:
#extension GL_ARM_shader_framebuffer_fetch_depth_stencil : enable precision highp float; uniform vec3 uCameraRange; // x = 2 * near; y = far + near; z = far - near uniform float uTransitionSize; float calc_depth(in float z) { return uCameraRange.x / (uCameraRange.y - z * uCameraRange.z); } varying vec2 vTextureCoord; uniform sampler2D sTexture; uniform vec4 color; void main() { vec4 diffuse = texture2D(sTexture, vTextureCoord) * color; float geometryZ = calc_depth(gl_LastFragDepthARM); float sceneZ = calc_depth(gl_FragCoord.z); float a = clamp(geometryZ - sceneZ, 0.0, 1.0); float b = smoothstep(0.0, uTransitionSize, a); gl_FragColor = diffuse * b; }
Hello Peter.
Thank you for such quick response and for explaining possible causes of this. I hope compiler team won't find any bugs and this is an expected output.
If the cause is internally generated preamble code, it will be good to detect this and show it as another warning, differentiating it from the same issues detected in original GLSL. This will prevent such confusions.