4.4.2 Measuring Unity shaders with the Mali Offline Shader Compiler

You write Unity shaders in the programming language C for Graphics (Cg). Cg is based on the C programming language with some modifications to make it more suitable for GPU programming.

Unity translates the Cg to OpenGL, OpenGL ES, or DirectX during the build process.
To retrieve the OpenGL ES shader code:
  1. Select the shader you want to analyze in Unity.
  2. Choose OpenGLES30 or OpenGLES20 as the Custom Platform you want to build for.
  3. Click the Compile and show button.
The result is displayed in your development environment.


  • The Mali Offline Shader Compiler only supports OpenGL ES shaders.
  • If your build platform is set to Android, Unity builds OpenGLES30 shaders by default.
Vertex and fragment sessions are typically delimited by #ifdef VERTEX or #ifdef FRAGMENT. If you use an option such as #pragma multi_compile <FEATURE_OFF> <FEATURE_ON>, multiple shader variants are built in the file.
Typically there are multiple VERTEX and FRAGMENT sections. Each variant is compiled separately by Unity starts your application. When you enable a feature, the relevant variant is selected.
Because the code has been translated into OpenGL ES, you can copy the vertex and fragment shader code into two separate files and compile them with the Mali Offline Shader Compiler.
Compile the shaders with one of the following options:
The following figure shows the output of the Mali Offline Shader Compiler:
Figure 4-23 Output of the Mali Offline Shader Compiler

Non-ConfidentialPDF file icon PDF versionARM 100140_0201_00_en
Copyright © 2014, 2015 ARM. All rights reserved.