Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
step_jac
Posts: 89
Registered: ‎05-31-2012
My Device: BlackBerry Playbook
My Carrier: Bell
Accepted Solution

OpenGL ES 2 shader limitations (SGX 540)?

Hello BB NDK dev forums,

 

We are bringing a relatively large App over from iOS to Blackberry and have notices some relatively severe differences in shader behaviour on the Playbook. These same differences were also observed on some Android devices also running the SGX 540 chipset. Are there known issues or workarounds surrounding this particular chipset? I'd be happy to post example shader code if necessary.

 

Thanks!

 

Stephane Jacoby

Please use plain text.
Developer
HorizonXP
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: OpenGL ES 2 shader limitations (SGX 540)?

To be honest, what you're asking may be beyond the realm of knowledge of many on here. I know it's outside of mine.

 

What kinds of limitations are you referring to? Could you be more specific? What's creating a stumbling block for you? More specific questions tend to get answered more quickly.

 

Also, please note that the PlayBook uses a chip from TI that has errata associated with it, such that NEON instructions are disabled by default. While you can certainly use them, you need to incorporate some workaround NOP instructions to ensure that correct values are returned from the CPU/GPU. Heed this warning. Do not do what Gameloft did and just port your code straight over. Or else you'll have 200+ reviews on App World about your app being glitchy, crashing, and not being able to save (that's separate issue).


Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Please use plain text.
Developer
step_jac
Posts: 89
Registered: ‎05-31-2012
My Device: BlackBerry Playbook
My Carrier: Bell

Re: OpenGL ES 2 shader limitations (SGX 540)?

Hi Horizon XP,

 

Figured out our issue just as your answer came in.

 

The main issue we were observing was invalid vertex shader output in certain cases. This seems to be due to the fact that when multiplying vertex attributes of lower precision with higher precision uniform or temporary variables, the results seem to get truncated to the lower precision.

 

For example:

 

attribute lowp vec3 pos;

uniform highp vec4 xform[4];

 

void main()

{

     mediump xformedPos = pos.x * xform[0] + pos.y * xform[1] + pos.z * xform[2];

     /// this can yield invalid results.

}

 

The solution was to increase the precision of the attribute inputs, even though the vertex data didn't require it.

 

Hope that helps somebody else :smileyhappy:

 

 

Please use plain text.
Developer
HorizonXP
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: OpenGL ES 2 shader limitations (SGX 540)?

Glad you figured it out.

Sounds to me like that's expected behaviour. I liken it to significant digits. If you multiply two numbers together, your resulting product should have the same number of significant digits as your least precise number.

Sounds like iOS was doing it wrong and you got away with an implementation bug.

Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Please use plain text.
Developer
step_jac
Posts: 89
Registered: ‎05-31-2012
My Device: BlackBerry Playbook
My Carrier: Bell

Re: OpenGL ES 2 shader limitations (SGX 540)?

Hi Horizon XP,

 

This is actually unexpected behaviour and points to a possible bug in either the gl Shader compiler of the SGX 540 driver. According to the GSLS ES spec:

 

The precision used to internally evaluate an
operation, and the precision qualification subsequently associated with any resulting intermediate values,
must be at least as high as the highest precision qualification of the operands consumed by the operation.

 

So lowp*mediump, should be evaluated at al least mediump and not lowp as was the case here.

This is similar to the C standard regarding type promotion.

 

Not a problem working around the issue, but good to know for anyone target ES 2.0 to an SGX 540 device such as the Playbook.

 

Best.

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1154, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: OpenGL ES 2 shader limitations (SGX 540)?

Good to know, but do you know which chipset was evaluating it incorrect?

Is the iPhone doing it wrong, or is the SGX 540 doing it wrong? (Can't tell based on the posts, unless I missed something).

If it's the SGX 540, then I would recommend submitting a bug to the Issue Tracker, with source/example, as there would be a better chance of the driver issue being resolved (and for all you know, it will be pushed to Android as well).
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
step_jac
Posts: 89
Registered: ‎05-31-2012
My Device: BlackBerry Playbook
My Carrier: Bell

Re: OpenGL ES 2 shader limitations (SGX 540)?

Hi rcmaniac25,

 

The SGX 540 definitely seems to be the chipset evaluating it incorrectly. iOS and Android devices running other SGX  (tested on 535, 543, 543 MP2 and MP4) chipsets as well as other chipsets (tested on Tegra2 and 3 running GeForce) did not suffer from this issue.

 

I'll definitely log a bug in the Issue Tracker as soon as I can find it. This workaround is fine but this issue can definitely lead to mysterious bugs.

 

Cheers!

Please use plain text.
Developer
HorizonXP
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: OpenGL ES 2 shader limitations (SGX 540)?

Wow, learn something new every day. I guess it's because on my engineering backgorund, but i would assume that numbers are only as accurate as your least reliable measuremnt. Good to know that such things dont apply in the world of OpenGL. 

 

For my own edification, since im trying to get into OpenGL work myself, is the compiler for shaders implemented in the actual chip hardware, or as software in the driver? Driver-side implementation would likely make sense for the ease of it, but i can see why you might do it in hardware instead for performance reasons. 

 

Could this bug even be fixed? 


Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Please use plain text.
Developer
step_jac
Posts: 89
Registered: ‎05-31-2012
My Device: BlackBerry Playbook
My Carrier: Bell

Re: OpenGL ES 2 shader limitations (SGX 540)?

Hi Horizon XP,

 

This issue can definitely be fixed at either the shader compiler or driver level, similarly to the way a C compiler would generate arithmetically and type correct code when say, multiplying a char by an int and assigning the results to an int (e.g. (char)128*(int)200000 would overflow if arithmetic is done as char). So same applies to both CPU and GPU code.

 

As for your second question, the compiler for shaders is implemented in software. It receives the source code at runtime and converts it to GPU specific microcode. Now the reason it is done at runtime is because GPUs differ between target platforms and there is no unified microcode model for OpenGL. On other platforms such as consoles, shader compilation is usually done as an offline process and the runtime simply reads and load the precompiled shader microcode.

 

Best.

Please use plain text.
Developer
HorizonXP
Posts: 133
Registered: ‎03-28-2011
My Device: BlackBerry 9900 & PlayBook
My Carrier: Bell

Re: OpenGL ES 2 shader limitations (SGX 540)?

Very cool. Yeah, I figured software implementation of the shader compiler would make most sense so you didn't have to worry about the architecture differences. Interesting that consoles do it that way, makes sense since they can get away with it. That actually could make sense in iOS and BlackBerry, since you have a limited ecosystem of devices on which your software would run.

Also, your char * int example does clarify why OpenGL does it this way. It's just counter-intuitive to me because, again, of my engineering background. ;-)

Founder of Pulsecode Inc. and taab
Authomator - Two-factor authentication codes on BlackBerry 10 - http://www.xitijpatel.com/ - Follow @xitijpatel
Is there a helpful or useful post in this thread? Click the thumbs up on it so that other people can find it more easily!
Please use plain text.