question

corygiovino avatar image
corygiovino asked

GLSL GLES20 looping

Has anyone run into the "Support for loop is restricted" on the fire stick. ("unable to determine the number of iterations at compile time") This is the only GLES2.0 device I am unable to perform a loop in my shader. I removed all the breaks and fixed the loop limit and iterator per the spec. Just cant get past this error. Thanks,
fire tv
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

justin avatar image
justin answered
Hi Cory, Are you still having issues with this? If you could, please share any sample code where you believe issues may be occurring. Thanks, Justin
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

corygiovino avatar image
corygiovino answered
Thank you for following up! I boiled it down to what I feel is the simplest shader that reproduces the problem: The error during linking is: Results of linking program : 0 ERROR:OPTIMIZER-3 (line 6) Support for for loops is restricted : unable to determine the number of iterations at compile time final String fragmentShader = "precision mediump float; \n" + "varying vec4 v_Color; \n" + "void main() \n" + "{ \n" + " float i; \n" + " for (i=0.; i<1.; i+=0.01) {\n" + " if (i > gl_FragCoord.x/1000.) break;\n" + " } \n" + " gl_FragColor = vec4(i, 1.0, 1.0, 1.0);\n" // vec4(float(gl_FragCoord.x)/a, float(glFragCoord.x)/a, float(gl_FragCoord.x)/a, 1.0); \n" + "} \n"; It does NOT like me bailing out early with the break; The shader executes without the break.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

justin avatar image
justin answered
Hi corygiovino, I've seen that there are issues with nested loops having non-constant variables, but your for loop looks fine here. I'll keep looking.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

corygiovino avatar image
corygiovino answered
Thank you. I wonder if the optimization level at GLSL link time is configurable.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

corygiovino avatar image
corygiovino answered
Since this GPU is the only one I cannot get my source to run on I am looking in here: http://www.broadcom.com/blog/chip-design/android-for-all-broadcom-gives-developers-keys-to-the-videocore-kingdom/ Please let me know if you use this stack on your device for the Capri VideoCore 4. If so Please share you Android.mk so I can attempt to reproduce on my end.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

muzzinb avatar image
muzzinb answered
Control flow inside GLSL ES 1.0 shaders has some limitations based on the spec ( https://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf). See Appendix A #4. According to this, the reason your shader doesn't work with the break, is because the break is a non-constant conditional within the loop. *Most* GPU drivers don't adhere to this, and will allow any sort of control flow within a shader. However, the Broadcom driver isn't the only one that doesn't allow it. Older Adreno drivers, would also fail to compile shaders like this one.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.