Skip to content

zink: GL 3.3 on Mali without dualSrcBlend or packed 10/10/10/2 vertex formats - #67

Merged
utkarshdalal merged 2 commits into
zink-mesa-xlib-pipettofrom
zink-gl33-mali-lowering
Nov 20, 2026
Merged

utkarshdalal merged 2 commits into
zink-mesa-xlib-pipettofrom
zink-gl33-mali-lowering

Conversation

@utkarshdalal

@utkarshdalal utkarshdalal commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On Mali-G615 (r44p1, Vulkan 1.3.247) and Mali-G68 (r38p1, Vulkan 1.3.219), with the wrapper's depth clip emulation from #66, zink now reaches GL 3.2 core, but a 3.3 core context still fails. Two GL 3.3 requirements are missing:

  • GL_ARB_blend_func_extended: the driver reports dualSrcBlend = false, so zink reports no dual-source render target.
  • GL_ARB_vertex_type_2_10_10_10_rev: the driver does not list the A2B10G10R10 / A2R10G10B10 UNORM, SNORM, USCALED and SSCALED formats as vertex buffer formats, and zink's attribute decomposition only handles array formats.

On these devices zink runs without optimal keys, without graphics pipeline libraries or shader objects, without dynamic vertex input or extended dynamic state, and with legacy render passes. The driver has coherent framebuffer fetch (VK_EXT_rasterization_order_attachment_access).

Change

Two commits, one per extension. Both apply only when the driver lacks the feature; drivers that have it keep the native path.

Packed 10/10/10/2 vertex formats. An attribute in one of the eight formats the driver lacks is declared as R32_UINT at the same offset and stride (pipeline vertex input and dynamic vertex input alike). The vertex shader key records which attributes are packed and whether each is BGRA, signed or scaled. A compile pass swaps the float input for a uint input and unpacks it: 10-bit fields at bits 0/10/20 and the 2-bit field at bit 30, red in the low bits for the RGBA formats and blue for the BGRA ones, UNORM as x/1023 and a/3, SNORM sign-extended and clamped at -1, SCALED converted as integers. This is only offered without optimal keys, because the shader key it needs only exists there. Pipeline libraries and shader objects require optimal keys, so they never see it.

Dual-source blending through framebuffer fetch. The cap is reported as 1 only when all of these hold: no dualSrcBlend, coherent fetch, no optimal keys, and no full dynamic blend state. Otherwise it stays 0, and with only non-coherent fetch it stays 0 too.

  • A fragment shader that writes a dual-source color is marked as an fbfetch shader when it is created. Its programs then always get the input attachment in the descriptor layout, the rasterization-order render pass and pipeline, and per-sample shading on multisampled targets, even when the program is built before the blend state is bound.
  • A blend state with src1 factors on color 0 turns hardware blending off for color 0 (the write mask is kept) and puts the equation into a new part of the fragment shader key. That shader variant collects both color 0 outputs, runs nir_lower_blend reading the destination through fbfetch, and writes the blended color. The blend constant comes from a new push constant.
  • Blend clamping follows color buffer 0. UNORM and sRGB clamp to [0, 1]; sRGB is read and written through the sRGB view, so the blend happens in linear. SNORM clamps to [-1, 1] and float does not clamp. Integer buffers are not blended. The key is refreshed when the blend state or the framebuffer changes.
  • Alpha-to-coverage and alpha-to-one have to use the source alpha. In this case they are done in the shader and turned off in the pipeline. Coverage is decided per sample from the source alpha.
  • A shader that does not write a dual-source color while such a blend state is bound uses the hardware blend, with src1 factors reading zero.
  • With logic op enabled, blending is off anyway, so src1 factors are replaced and nothing is lowered.

Testing

  • The device-tested binary, which is also the one to ship, is built from branch zink-gl33-mali-lowering-shipped-base. That branch is c1567e9 (the shipped base) + glx/xlib: count the alpha channel in GLX_BUFFER_SIZE (Tomb Raider I-III under gamescope) #58's fix + these two commits, ending at 9b8c6bf6f8, plus one build-only commit on its tip (ce0beecdce2: idep_xmlconfig on the libgl-xlib target and the Android memfd path in anon_file.c, the same changes the 20261104 build used). The two commits there are identical to the two on this branch (git range-diff shows no change). Recipe: the "Two Mesas: glamor's and the guest's" section of the gamescope android/README.md (NDK 27.3 + termux aarch64 sysroot, -Dglx=xlib, zink only, -fno-emulated-tls). NEEDED matches the shipped library and _glapi_tls_Context is ELF TLS. The library reports Mesa 24.3.0-devel (git-9b8c6bf6f8). It is repacked as extra_libs-20261120.tzst from the shipped archive with only usr/lib/libGL.so.1.5.0 replaced: archive sha256 6f4914c0fa005b167270f26a2f176ff9a851b741f9fe3b3f969459d93e4644bc, libGL sha256 45b8577a62f682e8947ff17168d042d8de605ee68d467cf7b27568a9e25e3687.
  • No CI on this branch builds the guest libGL. The branch's only workflow (macOS-CI, macos-11) waits for a runner that no longer exists.
  • This branch's head is ahead of what ships. Besides the two commits, it contains five commits that have never been in a shipped libGL: 12ef937 (disable a broken NIR SPIR-V pass on Mali), 6aa8ce4 (conditional rendering only if the extension is present), e5017e1 (HACK: disable dri options query), db045bf (Winlator-specific X server properties in glx_api) and ccacc8a (README). Merging this PR does not by itself change what the shipped library is built from.

Device results

Run on BrowserStack devices with the wrapper from #66 (wrapper-gamenative-20261120.tzst, sha256 4443e109...43ff) and the guest libGL from #67 (extra_libs-20261120.tzst, sha256 6f4914c0...44bc, reports git-9b8c6bf6f8), X11, xlib zink, no version or extension overrides. A WGL test program requests each context version, then draws and reads pixels back: depth clamp on and off (19 cases), all eight packed 10/10/10/2 vertex formats with plain, instanced and interleaved layouts (59 cases), and dual-source blending with every src1 factor and equation, constant color, color masks, sRGB, RGBA16F, RGB565, the default framebuffer, overlapping primitives in one draw, 4x MSAA and alpha-to-coverage (63 cases). The testbed's GL texture suite runs as a second step.

Device Driver GL with shipped parts GL with both changes Packed formats Dual-source blending Depth clamp GL texture suite
Vivo T4x 5G Mali-G615 r44p1, Vulkan 1.3 3.1 4.0 59/59 63/63 19/19 12/12
Galaxy A35 Mali-G68 r38p1, Vulkan 1.3 not run 4.0 59/59 63/63 19/19 12/12
Pixel 7 Mali-G710 r36p0, Vulkan 1.1 3.1 4.0 59/59 63/63 19/19 12/12
Pixel 9 Mali-G715 r48p0 3.2 4.0 59/59 63/63 (native) 19/19 12/12
Pixel 10 PowerVR DXT-48-1536 4.6 (earlier run) 4.6 59/59 (native) 63/63 (native) 19/19 12/12
Galaxy S24 Xclipse 940 4.6 (earlier run) 4.6 55/59 (native, see below) 63/63 (native) 19/19 12/12
Galaxy M32 Mali-G57 r26p0, Vulkan 1.1 3.1 3.2 59/59 (through the extension) not offered see below 12/12
  • "Shipped parts" is wrapper-gamenative-20261027 with extra_libs-20261104.
  • Galaxy M32 stays at 3.2: the driver has no dualSrcBlend, no rasterization order attachment access and no queue timestamps (GL_ARB_timer_query).
  • After 4.0 the Mali phones stop at 4.1 (GL_ARB_viewport_array, maxViewports is 1).

Found during these runs and not caused by these changes (both reproduce with the shipped parts):

  • Pixel 7 and Galaxy M32: after glReadPixels(GL_DEPTH_COMPONENT, GL_FLOAT) on a 24-bit depth renderbuffer, later draws to that framebuffer no longer show in readbacks. Integer reads, other depth formats and a new framebuffer work.
  • Pixel 9: after a draw with src1 blend factors and a shader that writes only one color (undefined in GL), every later readback is zero.
  • Galaxy S24: the four packed-format failures are one layout. The last four bytes of a vertex buffer that ends exactly at the last attribute read as zero, whichever attribute is stored there; four bytes of padding avoid it. The shipped parts give the same 55/59.

Adreno 740 (Retroid Pocket 6), new libGL: with Turnip, OpenGL 4.6, packed formats 59/59, dual-source 63/63, depth clamp 19/19, and Balatro renders its menu and exits cleanly. With the Qualcomm system driver the version rises from 3.2 to 4.5, because that driver lacks the four SCALED packed formats. On that driver every draw whose vertex shader has two or more inputs reads wrong values, with the shipped libGL too (same values in both), so its failures there are not from this change.

Not covered: on the Mali, PowerVR and Xclipse devices only the test programs ran, no game. The GL 4.0 features that are now reachable on Mali (tessellation, doubles) were not drawn.

@utkarshdalal
utkarshdalal force-pushed the zink-gl33-mali-lowering branch 2 times, most recently from 766b725 to 41fd5c2 Compare November 20, 2026 07:29
Utkarsh Dalal added 2 commits November 20, 2026 13:39
…ks them

Mali drivers do not list the A2B10G10R10/A2R10G10B10 UNORM, SNORM, USCALED
and SSCALED formats as vertex buffer formats, so GL_ARB_vertex_type_2_10_10_10_rev
and with it GL 3.3 were missing.

Without optimal_keys, such an attribute is now declared as R32_UINT at the
same offset and stride, and the vertex shader key records which attributes
need unpacking and how (channel order, signedness, normalization). A compile
pass replaces the float input with a uint input and unpacks it. Formats the
driver supports keep the native path, and with optimal_keys (the only mode
that uses pipeline libraries or shader objects) nothing changes.
… dualSrcBlend

Mali drivers report dualSrcBlend = false, so GL_ARB_blend_func_extended
and with it GL 3.3 were missing. They do have coherent framebuffer fetch
(VK_EXT_rasterization_order_attachment_access).

When the driver has no dualSrcBlend but has coherent fetch, and zink runs
without optimal_keys and without dynamic blend state, zink now reports one
dual-source render target:

- A fragment shader that writes a dual-source color is marked as an fbfetch
  shader when it is created, so its programs get the input attachment
  layout, the rasterization-order render pass and per-sample shading for
  multisampled targets no matter when the blend state arrives.
- A blend state that uses src1 factors on color 0 turns hardware blending
  off for color 0 (write mask kept) and puts the equation into a new part
  of the fragment shader key. That variant gathers both color 0 outputs,
  applies alpha-to-coverage (per sample, from the source alpha) and
  alpha-to-one, and runs nir_lower_blend with the destination read through
  fbfetch. The blend constant comes from a new push constant. The clamp
  follows cbuf 0: unorm and sRGB (blended in linear through the sRGB view),
  snorm, or none for float; integer buffers are not blended.
- A shader that writes no dual-source color while such a blend state is
  bound gets the hardware blend with src1 factors reading zero.

Drivers with dualSrcBlend keep the native path. With optimal_keys (and so
pipeline libraries and shader objects) or full dynamic blend state, or
without coherent fetch, the cap stays 0.
@utkarshdalal
utkarshdalal force-pushed the zink-gl33-mali-lowering branch from 41fd5c2 to 2bc9b7a Compare November 20, 2026 08:09
@utkarshdalal
utkarshdalal marked this pull request as ready for review November 20, 2026 11:45
@utkarshdalal
utkarshdalal merged commit 6d4ecd6 into zink-mesa-xlib-pipetto Nov 20, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant