# glsl code limit size

**URL:** <https://forums.imgtec.com/t/glsl-code-limit-size/1891>\
**Category:** PowerVR Insider\
**Tags:** pvrshadereditor\
**Created:** [September 6, 2013, 3:52am UTC](https://forums.imgtec.com/t/glsl-code-limit-size/1891 "2013-09-06T03:52:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rory\_yin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@rory\_yin](https://forums.imgtec.com/u/rory_yin)\
**Post date:** [September 6, 2013, 3:52am UTC](https://forums.imgtec.com/t/glsl-code-limit-size/1891/1 "2013-09-06T03:52:39Z")

</div>

we are developing video process in powerVR. and we implement our filters in GLSL. there is one filter have about 600 line shader code. when we enable it, glDrawArray  
  
seems failed. so i want to know if there is a shader code size limitation? thanks!

---

<div class="post-metadata">

**Author:** ![JoeDavis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/joedavis/32/71_2.png) [@JoeDavis](https://forums.imgtec.com/u/JoeDavis)\
**Post date:** [September 6, 2013, 9:21am UTC](https://forums.imgtec.com/t/glsl-code-limit-size/1891/2 "2013-09-06T09:21:31Z")

</div>

There aren’t any limitations of shader code size. Have you checked that your shader compilation and linking succeeded?  
  
  
  
If you share the code with us on this thread, or email it to [devtech@imgtec.com](mailto:devtech@imgtec.com), we can look into the issue for you.  
  
  
  
Regards,  
  
Joe

---

<div class="post-metadata">

**Author:** ![rory\_yin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@rory\_yin](https://forums.imgtec.com/u/rory_yin)\
**Post date:** [September 8, 2013, 11:12pm UTC](https://forums.imgtec.com/t/glsl-code-limit-size/1891/3 "2013-09-08T23:12:59Z")

</div>

hi, joe  
  
  
  
thanks for your kindly reply. below is our shader code, i am sure we can run it on Ipad and Iphone5, however, it always failed at Iphone4. would you please also share with me some tips about optimize this shader code? i am really a newbie about optimizing shader code. thanks!  
  
  
  
  
  
precision highp float;  
  
  
  
uniform float inv\_h;  
  
uniform float texelWidthScale;  
  
uniform float texelHeightScale;  
  
uniform sampler2D inputTexture0;  
  
  
  
const float norValue = 255.0 \* 255.0 / (1024.0_32.0);_  
  
_const float norexp = -1.0/32.0;_  
  
   
  
_float computeWeight(mat3 m1,mat3 m2)_  
  
_{_  
  
_float distance = 0.0;_  
  
_mat3 kernel1 = mat3(114.0,114.0,114.0,0.0,0.0,0.0,0.0,0.0,0.0);_  
  
_mat3 kernel2 = mat3(1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0);_  
  
_mat3 diff = m1 - m2;_  
  
_diff = matrixCompMult(diff,diff);_  
  
_diff = kernel2 \* diff \* kernel1;_  
  
_//float d = 114.0 \* (diff[0][0]diff[0][0] + diff[0][1]diff[0][1] + diff[0][2]diff[0][2] + diff[1][0]diff[1][0] + diff[1][1]diff[1][1] + diff[1][2]diff[1][2] + diff[0][2]diff[0][2] + diff[1][2]diff[1][2] + diff[2][2]diff[2][2]);_  
  
_distance = diff[0][0] \* inv\_h \* norValue;_  
  
_float weight = step(distance,255.0) \* pow(2.718281828,distancenorexp) \* 1024.0;_  
  
_return weight;_  
  
_}_  
  
   
  
_void main()_  
  
_{_  
  
_vec2 pt = vec2(gl\_FragCoord);_  
  
_vec2 scale = vec2(texelWidthScale, texelHeightScale);_  
  
_vec4 cur = texture2D(inputTexture0, pt \* scale);_  
  
   
  
_vec4 ll1 = texture2D(inputTexture0, (pt+vec2(-1.0,0.0)) \* scale);_  
  
_vec4 tt1 = texture2D(inputTexture0, (pt+vec2(0.0,-1.0)) \* scale);_  
  
_vec4 tt2 = texture2D(inputTexture0, (pt+vec2(0.0,-2.0)) \* scale);_  
  
_vec4 tt3 = texture2D(inputTexture0, (pt+vec2(0.0,-3.0)) \* scale);_  
  
_vec4 rr1 = texture2D(inputTexture0, (pt+vec2(1.0,0.0)) \* scale);_  
  
_vec4 bb1 = texture2D(inputTexture0, (pt+vec2(0.0,1.0)) \* scale);_  
  
_vec4 bb2 = texture2D(inputTexture0, (pt+vec2(0.0,2.0)) \* scale);_  
  
_vec4 bb3 = texture2D(inputTexture0, (pt+vec2(0.0,3.0)) \* scale);_  
  
   
  
_vec4 lt13 = texture2D(inputTexture0, (pt+vec2(-1.0,-3.0)) \* scale);_  
  
_vec4 lt12 = texture2D(inputTexture0, (pt+vec2(-1.0,-2.0)) \* scale);_  
  
_vec4 lt11 = texture2D(inputTexture0, (pt+vec2(-1.0,-1.0)) \* scale);_  
  
   
  
_vec4 rt11 = texture2D(inputTexture0, (pt+vec2(1.0,-1.0)) \* scale);_  
  
_vec4 rt12 = texture2D(inputTexture0, (pt+vec2(1.0,-2.0)) \* scale);_  
  
_vec4 rt13 = texture2D(inputTexture0, (pt+vec2(1.0,-3.0)) \* scale);_  
  
   
  
_vec4 rb11 = texture2D(inputTexture0, (pt+vec2(1.0,1.0)) \* scale);_  
  
_vec4 rb12 = texture2D(inputTexture0, (pt+vec2(1.0,2.0)) \* scale);_  
  
_vec4 rb13 = texture2D(inputTexture0, (pt+vec2(1.0,3.0)) \* scale);_  
  
   
  
_vec4 lb11 = texture2D(inputTexture0, (pt+vec2(-1.0,1.0)) \* scale);_  
  
_vec4 lb12 = texture2D(inputTexture0, (pt+vec2(-1.0,2.0)) \* scale);_  
  
_vec4 lb13 = texture2D(inputTexture0, (pt+vec2(-1.0,3.0)) \* scale);_  
  
   
  
_mat3 cur3\_r = mat3(lt11.a,tt1.r,tt1.g,ll1.a,cur.r,cur.g,lb11.a,bb1.r,bb1.g);_  
  
_mat3 cur3\_g = mat3(tt1.rgb,cur.rgb,bb1.rgb);_  
  
_mat3 cur3\_b = mat3(tt1.gba,cur.gba,bb1.gba);_  
  
_mat3 cur3\_a = mat3(tt1.b,tt1.a,rt11.r,cur.b,cur.a,rr1.r,bb1.b,bb1.a,rb11.r);_  
  
   
  
_vec4 average = vec4(0.0);_  
  
_vec4 weight = vec4(0.0);_  
  
   
  
_//first line_  
  
_///////////////////////////////_  
  
_//point 1_  
  
_mat3 other = mat3(lt13.gba,lt12.gba,lt11.gba);_  
  
_float fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweightlt12.b;_  
  
_weight.r += fweight;_  
  
   
  
_//point 2_  
  
_other = mat3(lt13.b,lt13.a,tt3.r,lt12.b,lt12.a,tt2.r,lt11.b,lt11.a,tt1.r);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweightlt12.a;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweightlt12.a;_  
  
_weight.g += fweight;_  
  
   
  
_//point 3_  
  
_other = mat3(lt13.a,tt3.r,tt3.g,lt12.a,tt2.r,tt2.g,lt11.a,tt1.r,tt1.g);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight \* tt2.r;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweighttt2.r;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweighttt2.r;_  
  
_weight.b += fweight;_  
  
   
  
_//point 4_  
  
_other = mat3(tt3.rgb,tt2.rgb,tt1.rgb);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweighttt2.g;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweighttt2.g;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweighttt2.g;_  
  
_weight.b += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_tt2.g;  
  
weight.a += fweight;  
  
  
  
//point 5  
  
other = mat3(tt3.gba,tt2.gba,tt1.gba);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight_tt2.b;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_tt2.b;  
  
weight.g += fweight;  
  
  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_tt2.b;_  
  
_weight.b += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_tt2.b;  
  
weight.a += fweight;  
  
  
  
//point  
  
other = mat3(tt3.b,tt3.a,rt13.r,tt2.b,tt2.a,rt12.r,tt1.b,tt1.a,rt11.r);  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_tt2.a;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_tt2.a;  
  
weight.b += fweight;  
  
  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_tt2.a;_  
  
_weight.a += fweight;_  
  
   
  
_//point_  
  
_other = mat3(tt3.a,rt13.r,rt13.g,tt2.a,rt12.r,rt12.g,tt1.a,rt11.r,rt11.g);_  
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_rt12.r;  
  
weight.b += fweight;  
  
  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_rt12.r;_  
  
_weight.a += fweight;_  
  
   
  
_//point_  
  
_other = mat3(rt13.rgb,rt12.rgb,rt11.rgb);_  
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_rt12.g;  
  
weight.a += fweight;  
  
  
  
//second line  
  
///////////////////////////////  
  
//point 6  
  
other = mat3(lt12.gba,lt11.gba,ll1.gba);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight_lt11.b;_  
  
_weight.r += fweight;_  
  
   
  
_//point 7_  
  
_other = mat3(lt12.b,lt12.a,tt2.r,lt11.b,lt11.a,tt1.r,ll1.b,ll1.a,cur.r);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight_lt11.a;  
  
weight.r += fweight;  
  
  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_lt11.a;_  
  
_weight.g += fweight;_  
  
   
  
_//point 8_  
  
_other = mat3(lt12.a,tt2.r,tt2.g,lt11.a,tt1.r,tt1.g,ll1.a,cur.r,cur.g);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight \* tt1.r;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_tt1.r;  
  
weight.g += fweight;  
  
  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_tt1.r;_  
  
_weight.b += fweight;_  
  
   
  
_//point 9_  
  
_other = mat3(tt2.rgb,tt1.rgb,cur.rgb);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight_tt1.g;  
  
weight.r += fweight;  
  
  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_tt1.g;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_tt1.g;  
  
weight.b += fweight;  
  
  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_tt1.g;_  
  
_weight.a += fweight;_  
  
   
  
_//point 10_  
  
_other = mat3(tt2.gba,tt1.gba,cur.gba);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight_tt1.b;  
  
weight.r += fweight;  
  
  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_tt1.b;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_tt1.b;  
  
weight.b += fweight;  
  
  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_tt1.b;_  
  
_weight.a += fweight;_  
  
   
  
_//point_  
  
_other = mat3(tt2.b,tt2.a,rt12.r,tt1.b,tt1.a,rt11.r,cur.b,cur.a,rr1.r);_  
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_tt1.a;  
  
weight.g += fweight;  
  
  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_tt1.a;_  
  
_weight.b += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_tt1.a;  
  
weight.a += fweight;  
  
  
  
//point  
  
other = mat3(tt2.a,rt12.r,rt12.g,tt1.a,rt11.r,rt11.g,cur.a,rr1.r,rr1.g);  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_rt11.r;_  
  
_weight.b += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_rt11.r;  
  
weight.a += fweight;  
  
  
  
//point  
  
other = mat3(rt12.rgb,rt11.rgb,rr1.rgb);  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_rt11.g;_  
  
_weight.a += fweight;_  
  
   
  
_//third line_  
  
_///////////////////////////////_  
  
_//point 11_  
  
_other = mat3(lt11.gba,ll1.gba,lb11.gba);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight_ll1.b;  
  
weight.r += fweight;  
  
  
  
//point 12  
  
other = mat3(lt11.b,lt11.a,tt1.r,ll1.b,ll1.a,cur.r,lb11.b,lb11.a,bb1.r);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight_ll1.a;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_ll1.a;  
  
weight.g += fweight;  
  
  
  
//point 13  
  
other = mat3(lt11.a,tt1.r,tt1.g,ll1.a,cur.r,cur.g,lb11.a,bb1.r,bb1.g);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight \* cur.r;  
  
weight.r += fweight;  
  
  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_cur.r;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_cur.r;  
  
weight.b += fweight;  
  
  
  
//point 14  
  
other = mat3(tt1.rgb,cur.rgb,bb1.rgb);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight_cur.g;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_cur.g;  
  
weight.g += fweight;  
  
  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_cur.g;_  
  
_weight.b += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_cur.g;  
  
weight.a += fweight;  
  
  
  
//point 15  
  
other = mat3(tt1.gba,cur.gba,bb1.gba);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight_cur.b;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_cur.b;  
  
weight.g += fweight;  
  
  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_cur.b;_  
  
_weight.b += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_cur.b;  
  
weight.a += fweight;  
  
  
  
//point  
  
other = mat3(tt1.b,tt1.a,rt11.r,cur.b,cur.a,rr1.r,bb1.b,bb1.a,rb11.r);  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_cur.a;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_cur.a;  
  
weight.b += fweight;  
  
  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_cur.a;_  
  
_weight.a += fweight;_  
  
   
  
_//point_  
  
_other = mat3(tt1.a,rt11.r,rt11.g,cur.a,rr1.r,rr1.g,bb1.a,rb11.r,rb11.g);_  
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_rr1.r;  
  
weight.b += fweight;  
  
  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_rr1.r;_  
  
_weight.a += fweight;_  
  
   
  
_//point_  
  
_other = mat3(rt11.rgb,rr1.rgb,rb11.rgb);_  
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_rr1.g;  
  
weight.a += fweight;  
  
  
  
//fouth line  
  
///////////////////////////////  
  
//point 16  
  
other = mat3(ll1.gba,lb11.gba,lb12.gba);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight_lb11.b;_  
  
_weight.r += fweight;_  
  
   
  
_//point 17_  
  
_other = mat3(ll1.b,ll1.a,cur.r,lb11.b,lb11.a,bb1.r,lb12.b,lb12.a,bb2.r);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight_lb11.a;  
  
weight.r += fweight;  
  
  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_lb11.a;_  
  
_weight.g += fweight;_  
  
   
  
_//point 18_  
  
_other = mat3(ll1.a,cur.r,cur.g,lb11.a,bb1.r,bb1.g,lb12.a,bb2.r,bb2.g);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight \* bb1.r;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_bb1.r;  
  
weight.g += fweight;  
  
  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_bb1.r;_  
  
_weight.b += fweight;_  
  
   
  
_//point 19_  
  
_other = mat3(cur.rgb,bb1.rgb,bb2.rgb);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight_bb1.g;  
  
weight.r += fweight;  
  
  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_bb1.g;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_bb1.g;  
  
weight.b += fweight;  
  
  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_bb1.g;_  
  
_weight.a += fweight;_  
  
   
  
_//point 20_  
  
_other = mat3(cur.gba,bb1.gba,bb2.gba);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight_bb1.b;  
  
weight.r += fweight;  
  
  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_bb1.b;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_bb1.b;  
  
weight.b += fweight;  
  
  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_bb1.b;_  
  
_weight.a += fweight;_  
  
   
  
_//point_  
  
_other = mat3(cur.b,cur.a,rr1.r,bb1.b,bb1.a,rb11.r,bb2.b,bb2.a,rb12.r);_  
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_bb1.a;  
  
weight.g += fweight;  
  
  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_bb1.a;_  
  
_weight.b += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_bb1.a;  
  
weight.a += fweight;  
  
  
  
//point  
  
other = mat3(cur.a,rr1.r,rr1.g,bb1.a,rb11.r,rb11.g,bb2.a,rb12.r,rb12.g);  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_rb11.r;_  
  
_weight.b += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_rb11.r;  
  
weight.a += fweight;  
  
  
  
//point  
  
other = mat3(rr1.rgb,rb11.rgb,rb12.rgb);  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_rb11.g;_  
  
_weight.a += fweight;_  
  
   
  
_//fifth line_  
  
_///////////////////////////////_  
  
_//point 21_  
  
_other = mat3(lb11.gba,lb12.gba,lb13.gba);_  
  
_fweight = computeWeight(cur3\_r,other);_  
  
_average.r += fweight_lb12.b;  
  
weight.r += fweight;  
  
  
  
//point 22  
  
other = mat3(lb11.b,lb11.a,bb1.r,lb12.b,lb12.a,bb2.r,lb13.b,lb13.a,bb3.r);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight_lb12.a;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_lb12.a;  
  
weight.g += fweight;  
  
  
  
//point 23  
  
other = mat3(lb11.a,bb1.r,bb1.g,lb12.a,bb2.r,bb2.g,lb13.a,bb3.r,bb3.g);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight \* bb2.r;  
  
weight.r += fweight;  
  
  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_bb2.r;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_bb2.r;  
  
weight.b += fweight;  
  
  
  
//point 24  
  
other = mat3(bb1.rgb,bb2.rgb,bb3.rgb);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight_bb2.g;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_bb2.g;  
  
weight.g += fweight;  
  
  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_bb2.g;_  
  
_weight.b += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_bb2.g;  
  
weight.a += fweight;  
  
  
  
//point 25  
  
other = mat3(bb1.gba,bb2.gba,bb3.gba);  
  
fweight = computeWeight(cur3\_r,other);  
  
average.r += fweight_bb2.b;_  
  
_weight.r += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_g,other);_  
  
_average.g += fweight_bb2.b;  
  
weight.g += fweight;  
  
  
  
fweight = computeWeight(cur3\_b,other);  
  
average.b += fweight_bb2.b;_  
  
_weight.b += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_bb2.b;  
  
weight.a += fweight;  
  
  
  
//point  
  
other = mat3(bb1.b,bb1.a,rb11.r,bb2.b,bb2.a,rb12.r,bb3.b,bb3.a,rb13.r);  
  
fweight = computeWeight(cur3\_g,other);  
  
average.g += fweight_bb2.a;_  
  
_weight.g += fweight;_  
  
   
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_bb2.a;  
  
weight.b += fweight;  
  
  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_bb2.a;_  
  
_weight.a += fweight;_  
  
   
  
_//rt_  
  
_other = mat3(bb1.a,rb11.r,rb11.g,bb2.a,rb12.r,rb12.g,bb3.a,rb13.r,rb13.g);_  
  
_fweight = computeWeight(cur3\_b,other);_  
  
_average.b += fweight_rb12.r;  
  
weight.b += fweight;  
  
  
  
fweight = computeWeight(cur3\_a,other);  
  
average.a += fweight_rb12.r;_  
  
_weight.a += fweight;_  
  
   
  
_//point_  
  
_other = mat3(rb11.rgb,rb12.rgb,rb13.rgb);_  
  
_fweight = computeWeight(cur3\_a,other);_  
  
_average.a += fweight_rb12.g;  
  
weight.a += fweight;  
  
  
  
vec4 tmp1 = step(weight,vec4(0.0));  
  
vec4 tmp2 = average/weight;  
  
tmp2 = clamp(tmp2,0.0,1.0);  
  
gl\_FragColor = (vec4(1.0)-tmp1) \* tmp2 + tmp1\*cur;  
  
}

---

<div class="post-metadata">

**Author:** ![JoeDavis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/joedavis/32/71_2.png) [@JoeDavis](https://forums.imgtec.com/u/JoeDavis)\
**Post date:** [October 16, 2013, 11:42am UTC](https://forums.imgtec.com/t/glsl-code-limit-size/1891/4 "2013-10-16T11:42:14Z")

</div>

Hi,  
  
  
  
The shader is extremely expensive. When targeting an SGX540 instruction set, our PVRShaderEditor tool reports the best case is 2712 instructions, the worst is 5284. As a comparison, a current high-end mobile game will usually have fragment shaders that are between 5-40 instructions.  
  
  
  
Although there isn’t a limit on the size of GLSL ES shader source, there is a limit to the number of instructions that can be processed by a given GPU. This limit will vary depending on the target GPU. If you hit this limit, the compiler should produce an error.  
  
  
  
I suspect the problem you’re seeing on the target is purely compilation time. On my desktop machine, the shader takes 2-3 seconds to compile. On a mobile device, this compilation time will be much higher. This high compile time may cause iOS to kill the compiler as it may appear unresponsive for a very long time. You would have to discuss the issue with Apple to understand why compilation doesn’t succeed on the iPhone 4.  
  
  
  
My recommendation would be to revisit your algorithm and see if there’s anyway it can be simplified. If it’s not possible to find a compromise between speed and quality of your output, you could split the render into multiple passes (i.e. output texture of pass 1 is read in by pass 2, and so on).  
  
  
  
Regards,  
  
Joe
