CesiumGS / CesiumGS/cesium

Duplicate uniforms shared between vertex and fragment programs on mediump-only devices

Open
#817 11 comments 0 reactions 1 assignee Claimed by @kring View on GitHub
type - bug
Dominant language
JavaScript
Stars
15.7k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

The GLSL ES Spec (http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf) says:

> Do precision qualifiers for uniforms need to match?
> Option 1: Yes.
> Uniforms are defined to behave as if they are using the same storage in the vertex and fragment processors and may be implemented this way.
> If uniforms are used in both the vertex and fragment shaders, developers should be warned if the precisions are different. Conversion of precision should never be implicit.
> Option 2: No.
> Uniforms may be used by both shaders but the same precision may not be available in both so there is a justification for allowing them to be different.
> Using the same uniform in the vertex and fragment shaders will always require the precision to be specified in the vertex shader (since the default precision is highp). This is an unnecessary burden on developers.
> RESOLUTION: Yes, precision qualifiers for uniforms must match.

So, on a device that only supports `mediump` precision in the fragment shader, it is not legal to declare a single uniform as `highp` in the vertex shader (the default) and `mediump` in the fragment shader. One way to resolve this is to declare it `mediump` everywhere, but this could cause artifacts in some situations. A safer solution is to duplicate the uniform, so the vertex shader gets a `highp` version and the fragment shader gets a `mediump` version. The Cesium renderer could do this automatically with a little bit of work.

We saw this problem in Chrome on a Samsung Galaxy Note 10.1, which has a Mali-400MP GPU. On that device, the shader failed to link as a result of the mismatched precision of the `czm_viewport` uniform (and probably others).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.