Hello Mali dev forums,
We recently had a bug pop up in our user reviews regarding mangled graphics on the Galaxy Note 10.1 2014 edition which runs the Mali-T628 GPU and decided to investigate.
After much debugging and poking around, we tracked it down to this one simple fragment shader:
uniform lowp sampler2D sampler;
varying lowp vec4 blendColor;
varying mediump vec2 texCoord;
void main()
{
lowp vec4 texColor = texture2D(sampler, texCoord);
gl_FragColor = 2.0 * blendColor * texColor;
}
Which when used, would cause the output in the BAD image attached. We found that reducing the precision of texCoord from mediump to lowp, the problem went away as in the GOOD image attached.
This particular application shipped around the time the Nexus 10 came to market and is known to have worked fine on the T604 GPU. I do suspect that the fragment shader is not alone in causing this issue since the linkage with the vertex shader could also have effects, however that side of things is relatively simple (I've attached a sample vertex shader).
One thing that makes me hesitate to point at the shader compiler as a culprit is the following odd behaviour. The BAD scene actually renders correctly for 1 frame before getting into a state where the UVs are mangled.
Though we do have a workaround to the issue, I still wanted to bring this up as using lowp UVs isn't typical but only happens to work well with our texture set. Also worry that this bug could spread in various driver branches. Any possibilities that this would be Samsung specific, or do they use ARM reference drivers.
Many thanks,
Stephane
Hi Stephane,
Please can you attach a reproducer apk directly here?
To do this, you need to go into 'Use advanced editor' then select 'Attach' in the bottom right corner.
Kind Regards,
Michael McGeagh
Hi Michael,
A version of the APK that predates the fix which is currently live is attached.
Many thanks!
Hi,
I have just found the same issue on the T604 on a Nexus 10 (Android 4.2.2) in our engine. We have used the same workaround, specifying highp for texc and color in both the vertex and fragment shaders.
Specifying lowp did not fix the problem and interestingly we only saw this issue when we reduced the complexity of the fragment shader. Originally we were testing for alpha 0 and discarding fragments and this did not show the issue.
Below is the shader which causes the issues.
Vertex shader
uniform mat4 World;
uniform mat4 View;
uniform mat4 Projection;
uniform vec4 Tint;
attribute vec3 Pos;
attribute vec2 TexCoord;
attribute vec4 Color;
varying vec2 texc;
varying vec4 color;
void main(void)
gl_Position = vec4(Pos.xyz, 1.0) * World * View * Projection;
texc = TexCoord;
color = Color * Tint;
Fragment shader
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D DiffuseMap;
gl_FragColor = color * texture2D(DiffuseMap, texc.st);
Cheers,
Richard.
Hi Richard,
Assuming the T604 and T628 are based on the same driver core, I somewhat expected the issue to creep into the Nexus 10 distro. I can also confirm your observation that the simplicity of the shader affected the issue as many of our more complex fragment shaders were mostly unaffected.
Best,
rockettree Thanks for reporting - I'll hand this over to our development team - having a second test case is always useful to make sure we have really fixed it
> Specifying lowp did not fix the problem
Mali treats lowp the same as mediump (both are fp16), so if mediump fails I would expect lowp to fail the same way.
> I somewhat expected the issue to creep into the Nexus 10 distro.
Yeah, unfortunately the latency in the driver deployment pipeline means bugs in one product sometimes crop up again later in another one if that vendor takes a little longer to push out a driver update. The original bug reported by stepjac has been fixed for a while in our driver tree - so just waiting for this one to get pulled downstream ...
Pete