Mali-G31 (Allwinner H700) notes, measured
These are observations from porting Halo 3 to the H700 with Arm’s Mali driver (libmali r20p0, OpenGL ES 3.2) on Knulli. They may help anyone writing or porting a 3D renderer for H700 handhelds (Anbernic RG35XX, RG40XX, RG34XX, RG28XX, RG CubeXX).
The GPU
- One shader core. The driver’s
gpuinforeports “Mali-G31 1 cores” with core mask 0x1, despite the “MP2” name. Other G31 chips report the same. - 696 MHz, governed by devfreq
simple_ondemand. Writing the top frequency tomin_freqpins it; a game launcher should do so, then restore it on exit. - No Vulkan: the ICD file names Vulkan 1.0.108, but the library exports no Vulkan entry points.
- Limits:
- no storage buffers or images in vertex shaders;
- 64 vertex output components, 60 fragment input components;
- 16 KB uniform blocks, 12 per stage;
- 4 colour attachments;
- RGBA16F, R11G11B10F and RGB10A2 are renderable.
Hardware counters
The kbase driver’s hardware counters are readable from user space through the /dev/mali0 ioctls
(tools/device/mali_hwcnt.c). The G31 has four blocks:
- job manager: GPU active, fragment and vertex/compute job slots;
- tiler: triangles;
- L2;
- shader core: fragment active, compute active, warps, quads rasterised, early-ZS tests and kills.
They answer “is it vertex or fragment bound?” without guessing.
Driver behaviour that costs time
- Write-after-read waits on the CPU. Writing a texture that GPU work still in flight reads makes the driver wait on the CPU until that work is done. This held for glCopyImageSubData, glBlitFramebuffer, attaching the texture to a framebuffer, and glInvalidateFramebuffer. A full-screen pass that samples the source keeps the dependency on the GPU instead; keeping several textures per target avoids the hazard entirely.
- Readbacks: mapping a buffer that a just-submitted frame writes waits for that frame. Read the previous frame’s copy instead.
- glFinish-based profiling serialises the CPU and the GPU, and per-draw timing misleads on a tiler, because each draw becomes its own pass. Time whole passes, or leave content out for a few frames and see what it saves.
- Program compilation is slow and memory-hungry: 1-3 s per program, and very large shaders can need hundreds of MB. Cache program binaries (glGetProgramBinary) and compile ahead of play.
Shader costs
- mediump pays. Making fragment shaders’ temporaries half precision gained 12% on the hardware, more than the Mali Offline Compiler’s estimate. Watch for small values flushing to zero (1/x becomes infinity).
discarddisables early depth writes (forward pixel kill): compile it out where the draw does not alpha-test.- Run-time decoding is expensive. Specialising vertex shaders on their vertex layout as compile-time constants cut vertex cycles about 3x.
- Emulating the Xbox’s “0 × anything = 0” with
min(abs(a), abs(b)) == 0 ? 0 : a * bcosts 15-25% of a heavy shader’s cycles; use it only where NaN would show.