potential bug in glGetActiveUniform

Hi,


I have been having a hard crash when I run my application on device but not on PC.

I have found the source of the problem to be with “glGetActiveUniform"

I use this function to get the array size of the uniform from the shader and allocate memory on the CPU side.

GLsizei lengthWrittenTonamef;<span =“apple-tab-span”=”" style=“white-space:pre”> GLint arrsize;<span =“apple-tab-span”="" style=“white-space:pre”> GLenum datatype;<span =“apple-tab-span”="" style=“white-space:pre”>
glGetActiveUniform(m_uiProgram, location,256, &lengthWrittenTonamef, &arrsize, &datatype, uniformname);

Now on PC , calling glGetActiveUniform will return "

uniformname " for the “location” value I pass in.
When I pass this “

uniformname " to “glGetUniformLocation”, I get back the exact “location” value.
While on device (on Android galaxy S1 -GTI9000) these values are not the same. Basically “glGetActiveUniform " is not returning the same uniform information of the “location” I am asking for. I use CPVRTPFXEffect.Load to load my pfx and as said, this works flawlessly on the PC.

This is causing wrong allocation to another uniform and thus I am crossing array size of a uniform and leading to a crash.

My basic need is to query for the array size of a uniform. Could you help me understand how to implement my above functionality correctly if I am doing something wrong ?

[ADDITIONAL OBSERVATION]
for my uniform in shader like this
uniform lowp vec4 texToUseForFace[6];

glGetActiveUniform is returning “texToUseForFace” on the PC while its returning “texToUseForFace[0]” on the device (please do note that your SPVRTPFXParserEffect.psUniform.pszName= “texTouseForFace” in both PC and device thus leading to more confusion) . This is core reason for my crash. hard coding to replace the excess “[0]” solved my crash. Please confirm the source of this difference in the string.


Thanks,
Madan



<br =“apple-interchange-newline”=””>








mkandula2012-08-22 20:32:01

can I get some update about this ?


Hi Madan,

This is actually down to a spec bug in OpenGL ES. The behaviour of this case for arrays was highly underspecified in the original GL ES specification, but has been recently changed to clarify the point. Subsequently, whether a particular platform can query with or without the [0] is unfortunately platform dependent. Regardless, an incorrect query should return -1, so I will look into the codebase for the PFX loading code to see if there's some way we can modify the behaviour to handle this properly. I'll let you know as soon as we have some sort of fix.

Thanks,

Tobias





Tobias2012-09-25 12:50:13







Hi Madan,


Ok I've looked at the code with one of my colleagues, and we came to the
conclusion that the simplest fix is to check if the uniform locations found are
-1, and try again with the value with [0] appended. There's currently no way to
track if a uniform is an array value in the PFX code, but it's something we'll
look into adding specifically for a future release, which will allow us to do
this a bit more selectively.



To do the same fix in the tools on your end, you'll need to look at the file
"PVRTPFXParserAPI.cpp", lines 815 and 518. Add the following code and
it should just work:



// Check for array.
Workaround for some OpenGL:ES implementations which require array element
appended to uniform name

// in order to
return the correct location.



if(nLocation == -1)



{



char szTmpUniformName[2048];



strcpy(szTmpUniformName, pszName);



strcat(szTmpUniformName, "[0]");



nLocation = glGetUniformLocation(m_uiProgram, szTmpUniformName);



}



You’ll
also need to do the same if you choose to get uniform locations manually. Hope
that helps!



 



Thanks,



Tobias





Normal
0




false
false
false

EN-GB
X-NONE
X-NONE






































































































































































/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-fareast-language:EN-US;}

Hi Tobias,


Currently I have a fix that goes along what you have suggested. I guess I can live with it :slight_smile:
Thanks for checking and confirming !!

-madan