Dear all,
I want to compare the performance of online shader compiler and offline shader compiler.
I compiled shader source with mali offline shader compiler and the output are two files named *.out.non-prerotate and *.out.prerotate.
However I have difficulties in how to use these two binary file in my opengl es program. I searched examples in mali SDK but there's no example case found.
Is there anyone who has successfully use binary shader in opengl es program? Is there any other references?
Hi seufanghao,
Please have a look at the following example from Prerotate section of the Usage chapter in the User Guide:
vertex_shader = glCreateShader(GL_VERTEX_SHADER); glShaderBinary(1, &vertex_shader, GL_MALI_SHADER_BINARY_ARM, non_prerotate_binary, length); error = glGetError(); if(error == GL_INVALID_VALUE) { int errorlog_length; glGetShaderiv(vs, GL_INFO_LOG_LENGTH, &errorlog_length); char* errorlog = malloc(errorlog_length * sizeof(char)); glGetShaderInfoLog(vertex_shader, errorlog_length, NULL, errorlog); /* * If the non-prerotate binary is not supported then you will see the * following message in the errorlog: * ---- "The driver is too new for the shader. Try to upgrade your * compiler." * in this case you should use the prerotate binary instead, e.g. * glShaderBinary(1, &vertex_shader, GL_MALI_SHADER_BINARY_ARM, * prerotate_binary, length); */ }
Does it answer your question?
Jacek
Hi, kubacki,
Thanks for your advice! Actually I have difficulties in loading binary shader. Below is my code. It is a binary vertex shader. The file "simpletrianglevert" is generated by mali offline shader compiler (via command "malisc --vertex -c Mali-T600 simpletriangle.vert -o simpletrianglevert"). GPU is mali-T628.
int size = 1096; // the size of binary shader " simpletrianglevert "
FILE * file = fopen("/data/data/com.arm.malideveloper.openglessdk.simpletriangle/simpletrianglevert", "r");
char * fileContent =(char *) malloc(sizeof(char) * size);
if(file == NULL)
{
LOGE("Failure to load the file");
return 0;
}
fread(fileContent, size, 1, file);
LOGI("%s",fileContent);
free(fileContent);
fclose(file);
glShaderBinary(1, &vertexShader, GL_MALI_SHADER_BINARY_ARM, (void*)fileContent, sizeof(char)*sizeof(fileContent));
However, there is an error "Link failed because of invalid vertex shader". Is the method used to loading "simpletrianglevert" wrong? Or the binary shader can not be used directly?(need some extra operation?)
via command "malisc --vertex -c Mali-T600 simpletriangle.vert -o simpletrianglevert" GPU is mali-T628.
via command "malisc --vertex -c Mali-T600 simpletriangle.vert -o simpletrianglevert"
GPU is mali-T628.
Mali-T60x and Mali-T62x are different GPUs - try compiling for the right one .
Remember that binary shaders generally require an *exact* match for GPU and driver version, or they are highly likely to fail. For this reason we really don't recommend using them in commercial applications; they are very fragile and applications using them are prone to stop working when drivers are updated over-the-air.
HTH, Pete
Thanks! Samples in Mali SDK use online shader compiler to compile shaders. My task is to compare the performance difference of gpu using online shader compiler and offline shader compiler. Offline shader compiler loads pre-compiled shader and it will do some optimization during compilation(?), so it is thought to be more efficient.
I checked mali offline shader compiler and Midgard series GPU being supported are Mali-T600, Mali-T620, Mali-T720, Mali-T760, Mali-T820, Mali-T830, Mali-T860, Mali-T880. I choose Mali-T620 for compiling (because Mali-T628 is not avaliable). Platform is Odroid-xu3 and gpu driver is r4p0 so GPU HWREV is r0p1 (noted in ARM® Mali™ Midgard GPU User-Space Binary Drivers - Mali Developer Center ). I compile the shader with command "malisc --vertex -c Mali-T620 -r r0p1 simpletriangle.vert -o simpletrianglevert".
However, the error is still there, "Link failed because of invalid vertex shader". I think I failed to load binary shader file. Below is my loading code. Is it true?
You're calling "free(fileContent);" before uploading to glShaderBinary so you've at least got a use-after-free bug there. Move the free after the GL call to avoid that one.
I suspect one issue is that the driver version on your platform may be different to the version you are compiling for (the shader binary format has changed over time); the offline compiler lets you specify the DDK version in addition to the hardware version - can you check that?
Cheers, Pete