Mir

Merge lp:~albaguirre/mir/fix-eglplasma-example-animation-slowdown into lp:mir

Proposed by Alberto Aguirre
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 1448
Proposed branch: lp:~albaguirre/mir/fix-eglplasma-example-animation-slowdown
Merge into: lp:mir
Diff against target: 41 lines (+9/-7)
1 file modified
examples/eglplasma.c (+9/-7)
To merge this branch: bzr merge lp:~albaguirre/mir/fix-eglplasma-example-animation-slowdown
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Daniel van Vugt Approve
Kevin DuBois (community) Approve
Alan Griffiths Approve
Review via email: mp+209289@code.launchpad.net

Commit message

Avoid degradation of floating point precision as the parameter of the mod
function increases. That was causing eglplasma to stutter after some time
on some GPUs (LP: #1189753)

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

okay

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

I'll have to check this. I thought I had eliminated all such continuity artefacts. Also, it's sub-optimal moving math outside of the shader.

This needs fixing too:
if (angle > pi2) angle = 0.0f;
angle is no longer smoothly continuous and could stutter slightly when it reaches pi2.

review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Could you log a bug with instructions on how to reproduce the problem?

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Elaborating; the problem with:
  if (angle > pi2) angle = 0.0f;
is that the increment 0.005 does not divide evenly into the period 6.283185308. That will lead to regular visible frame skip kind of artefacts.

The solution is to wrap around smoothly to the correct next angle, which is:
    angle = fmod(angle, pi2);
However that's exactly the same as the old code which does the same more efficiently in the shader with "mod(theta, pi2)". So what I'm saying is the existing code is both more correct and more efficient.

If you've observed bugs, can you detail them in a bug report? Unless it's bug 1189753 ?

review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Hmm, OK, maybe not more efficient with the added logic in the shader being per-fragment instead of your per-frame. But certainly this proposal is less correct and would be expected to cause glitches.

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> I'll have to check this. I thought I had eliminated all such continuity
> artefacts. Also, it's sub-optimal moving math outside of the shader.
>
You can see this in android devices.

> This needs fixing too:
> if (angle > pi2) angle = 0.0f;
> angle is no longer smoothly continuous and could stutter slightly when it
> reaches pi2.

I don't see any stutter.

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> Could you log a bug with instructions on how to reproduce the problem?

https://bugs.launchpad.net/mir/+bug/1288059

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> Elaborating; the problem with:
> if (angle > pi2) angle = 0.0f;
> is that the increment 0.005 does not divide evenly into the period
> 6.283185308. That will lead to regular visible frame skip kind of artefacts.
>
> The solution is to wrap around smoothly to the correct next angle, which is:
> angle = fmod(angle, pi2);
> However that's exactly the same as the old code which does the same more
> efficiently in the shader with "mod(theta, pi2)". So what I'm saying is the
> existing code is both more correct and more efficient.
>

I understand that. But in android devices, with large angles, the mod operation will return coarse values, which leads to the "stuttering" or "slowdown" effect.

> If you've observed bugs, can you detail them in a bug report? Unless it's bug
> 1189753 ?

Actually yes it's does look like #1189753

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> This needs fixing too:
> if (angle > pi2) angle = 0.0f;

fixed.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Oh, I see. So it's a bug in droid/mobile GLSL/GPU implementations. All makes sense now. In that case a simple fix should suffice. Replace:
   if (angle > pi2) angle = 0.0f;
with:
   angle = fmod(angle, pi2);

Excitingly, this sounds like a resolution for bug 1189753. Should we link it?

review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Ah. The subtraction approach is good too.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/eglplasma.c'
2--- examples/eglplasma.c 2013-09-19 13:24:22 +0000
3+++ examples/eglplasma.c 2014-03-05 06:12:02 +0000
4@@ -85,14 +85,13 @@
5 " const float pi2 = 6.283185308; \n"
6 " float u = texcoord.x * pi2; \n"
7 " float v = texcoord.y * pi2; \n"
8- " float t = mod(theta, pi2); \n"
9- " float us = (cos(1.1 * u + 7.0 * t) + \n"
10- " cos(2.3 * v * cos(1.0 * t)) + \n"
11- " cos(0.3 * u * cos(3.0 * t)) \n"
12+ " float us = (cos(1.1 * u + 7.0 * theta) + \n"
13+ " cos(2.3 * v * cos(1.0 * theta)) + \n"
14+ " cos(0.3 * u * cos(3.0 * theta)) \n"
15 " ) / 3.0; \n"
16- " float vs = (cos(2.3 * v + 8.0 * t) + \n"
17- " cos(1.3 * u * cos(3.0 * t)) + \n"
18- " cos(1.7 * v * cos(2.0 * t)) \n"
19+ " float vs = (cos(2.3 * v + 8.0 * theta) + \n"
20+ " cos(1.3 * u * cos(3.0 * theta)) + \n"
21+ " cos(1.7 * v * cos(2.0 * theta)) \n"
22 " ) / 3.0; \n"
23 " float x = (us * vs + 1.0) / 2.0; \n"
24 " gl_FragColor = vec4(gradient(x), 1.0); \n"
25@@ -105,6 +104,7 @@
26 1.0f,-1.0f,
27 -1.0f,-1.0f,
28 };
29+ const float pi2 = 6.283185308f;
30 GLuint vshader, fshader, prog;
31 GLint linked, low_color, high_color, vpos, theta;
32 unsigned int width = 0, height = 0;
33@@ -151,6 +151,8 @@
34 {
35 glUniform1f(theta, angle);
36 angle += 0.005f;
37+ if (angle > pi2)
38+ angle -= pi2;
39 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
40 mir_eglapp_swap_buffers();
41 }

Subscribers

People subscribed via source and target branches