The GLES 3.2 renderer for the H700 (design, 2026-12-04)
Why GLES
- The CubeXX’s Mali-G31 driver (
libmali.so.0.20.0, r20p0) exports no Vulkan entry points (its ICD json says Vulkan 1.0.108, butvk_icdGetInstanceProcAddrandvkGetInstanceProcAddrare absent): OpenGL ES 3.2 is the only API. - The port’s renderer has a backend seam (
port/sdk/d3d/gpu_backend.h): the Xenos frontend (vulkan_device.cpp: EDRAM, resolves, texture cache, constant blocks, vertex fetch tables) talks to an API only throughs_gpu_backend_ops. The GLES backend is a third backend beside Vulkan and Direct3D 12 (port/sdk/d3d/gles_backend.cpp).
The Mali (tools/device/glesprobe.c, runs/glesprobe.txt)
| Limit | Value | Consequence | | — | — | — | | Vertex-stage SSBOs / images | 0 / 0 | vertex fetch cannot read storage buffers: vertex attributes (and texture buffers) | | Fragment / compute SSBOs | 35 | memexport shaders run as compute; fragment storage reads are fine | | Texture buffer texels | 65536 | 1 MB windows of RGBA32UI at most: not for whole vertex streams | | Uniform block size / per stage | 16 KB / 12 | the six Xenos blocks fit (XeFloatVS/PS 4 KB each) | | Texture units per stage / combined | 16 / 96 | Halo shaders fetch 1-6 textures | | VS outputs / FS inputs | 64 / 60 components | the ABI’s 28 fixed interface slots do not fit: compact locations per program | | Color attachments | 4 | the Xenos 4 RTs | | Renderable | RGBA16F, R11G11B10F, RG16F, R32F, RGBA32F, RGB10A2, RGBA8, RGB565 | the HDR targets map directly | | Compression | ETC2/EAC, ASTC LDR/HDR, no BC | DXT/DXN/CTX1 decode or transcode | | Extras | ARM_shader_framebuffer_fetch(+depth), EXT_shader_pixel_local_storage, EXT_buffer_storage, copy_image, geometry, tessellation, KHR_debug, get_program_binary (1 format) | tile-local resolves, persistent mapping, program cache |
What a frame is (lavapipe trace, 010_jungle opening, frame 300; tools/trace_frame.py)
544 draws and 21 resolves in ~18 render-target runs; 49 pixel and 30 vertex shaders.
- 117
particle_updatedraws with no target: memexport (GPU particle simulation) -> compute dispatches. - G-buffer-like pass: 139 draws into RGBA16 unorm + RGB10A2 + D32S8 (1152x640).
- Two lighting / material passes: 102 and 110 draws (RGBA16 + BGRA8 / RGBA16).
- Shadow map: 20 draws, 1024x1024 depth.
- Bloom / luminance chain: 288x160, 72x40, 18x10, 1x1 (RGBA16F); composite and HUD: 22 draws. GL CPU at the Halo CE port’s ~17-28 us per draw: ~11-15 ms for 544 draws, on its own core.
CPU budget (measured, headless null GPU, CubeXX)
main thread 15-18 ms/frame, presenting thread 5-11 ms, all threads ~31 ms/frame at 30 fps; rss 347 MB. One core is free for the GL thread and the Mali driver’s own threads.
Shader contract for the GLSL ES emitter (built 2026-12-04: port/tools/xenos_spirv glsl*.odin; pack version 5)
shaderpack --glsl writes it (tools/patch_gles_shaders.py adds it to the checkout); port/shaders/shader_pack.h
(“version 5”) has the full contract and the binary layout. The HLSL emitter statement for statement (same Meta,
checked against the SPIR-V translation for every shader), GLSL ES 3.20 syntax, and:
- Constant blocks: std140 uniform blocks with the HLSL cbuffer members, bindings 0-5 (XeSystem, XeFloatVS,
XeFloatPS, XeBoolLoop, XeFetch, XeVertexFetch); the float banks are
xe_c_vs/xe_c_ps(one name per stage: a program shares one uniform namespace). - Textures: one combined sampler per (fetch constant, kind, variant), the module’s units in its record. Fragment /
compute:
layout(binding = n); vertex / TES:layout(binding = XE_VS_UNIT_n)(default n; GLSL ES layout qualifiers take literals only, so there is no XE_VS_UNIT_BASE + n). A tfetch3D binds a 3D and a 2D-array unit;XE_TF<n>_3D/XE_TF<n>_STACKEDkeep one (5 pixel shaders need that to fit 16 units). - Vertex fetch: at the vertex index:
in uvec4 xe_attr_katXE_ATTR_k(max 12 per shader; vertex index = gl_VertexID + XeSystem.vertex.x); any other index:usamplerBuffer xe_vertex_buffer_k(R32UI, VS / TES) or an SSBO (compute), named by vertex element, not stream: the stream an element reads is the draw’s (xe_element[k].x), so the backend binds element k’s stream there and puts vertex 0’s byte offset in that stream’s xe_stream[s].x. Elements of the same usage / index share one (the water TES: 24 elements, 10 buffers). - Interface:
xe_l<n>(HLSL slot n) atXE_LOC_L<n>; withoutXE_LINKEDevery slot defaults to n; with it the backend defines dense locations for the slots the pair connects and the rest disconnect (VS output private, FS input zero). Retail maximum: 12 VS outputs, 12 FS inputs, 12 connected (+2 with user clip): every pair fits 15. - Position: y negated and z from [0, w] to [-w, w] at the end of VS / TES (invariant, precise); gl_FragCoord.xy is the D3D pixel, sprites use (s, 1 - t) of gl_PointCoord; the rectangle GS passes positions through.
- User clip planes:
XE_USER_CLIP(+XE_LOC_CLIP0/1): VS / TES writexe_clip0(vec4) /xe_clip1(vec2), the FS discards below zero. Alpha test: compiled whileXE_ALPHA_TEST(default 1); anXE_ALPHA_TEST 0variant keeps discard out of opaque draws (Mali early ZS / FPK). - Memexport: SSBO array
xe_memexport[4]at bindings 0-3; computelocal_size_x = 64. Helpers: tess VS + TCS (vertices 1), the TES (triangles, fractional_even, cw), one rectangle-list GS per VS output set; no point GS. - LOD bias: GLES samplers have none, so every fetch adds the fetch constant’s (XeFetch dword 4 bits 12-21, /32), as Vulkan’s mipLodBias would (gradient fetches scale their gradients).
- Zero rule: HLSL’s exact
a == 0 || x == 0;XE_ZERO_RULE_MINswitches to the SPIR-V formmin(|a|,|x|) == 0(fragment longest path median 54 -> 51 cycles, p90 126 -> 116 by malioc), valid if the Mali’s min returns the non-NaN operand: check on the device before turning it on. - Validation (PC): all 2896 modules compile and link alone on Mesa 25.2 llvmpipe (GLES 3.2), also with
XE_ZERO_RULE_MIN,XE_ALPHA_TEST 0andXE_USER_CLIP; 2942 programs link (2887 VS/FS pairs by tag, 23 with the rectangle GS, 12 tessellation pipelines, 20 without XE_LINKED);tools/glsl_check/(glsl_check.c, pairs.py, malioc_run.py). SPIR-V and HLSL outputs byte-identical to upstream. - Mali-G31 (malioc 8.8, r51p0 compiler): all 2896 compile. Fragment: 1070 loop-free shaders, longest path median 54 / p90 126 / max 273 cycles (arithmetic-bound); 1654 have loops (total cycles median 135, p90 258); 2493 of 2724 use more than 32 work registers (half occupancy) and 1418 spill. Vertex: median 25, p90 91, max 271. The same shaders as the SPIR-V pack’s modules (Vulkan, a 1-in-8 sample) are ~15% cheaper: 7 points from the zero rule’s form, 2 from the LOD bias, the rest unexplained. Size: 143.6 MB of GLSL (median 47 KB per module): compile on worker threads and keep program binaries.
Backend plan
- Skeleton (
gles_backend.cpp): EGL (PC: Mesa llvmpipe surfaceless; device: Mali fbdev window), buffers (EXT_buffer_storage persistent maps), images, samplers, render targets (FBO cache), clears, present. - Programs from the pack (GLSL text), program binary cache in the data folder, compile on worker threads with shared contexts (the Halo CE port’s approach).
- Draws: VAO per program vertex layout, attribute bindings per draw, UBO ring (glBindBufferRange), texture units.
- Resolves and the frontend’s helper passes (edram_7e3, pwl_convert, depth_pack, display_gamma, resolve_scale, resolve_downscale) as compute or fragment passes; framebuffer fetch where it saves a pass.
- Textures: DXT/DXN/CTX1 decode on load (dropped top mips) first; ETC2/ASTC at install time later.
- A GL thread fed by a command ring (the frontend records on one thread; GL calls move off it), pacing on the TCON scanline (Halo CE port).
- Performance: internal resolution well below 1152x640, pass cuts, program binary prewarm.