Skip to content

mesa-ios: expose S3TC/RGTC/BPTC through Mesa's CPU fallback in OSMesa (fixes Mewgenics black textures, #566) - #574

Merged
125hz merged 1 commit into
willfaust:mainfrom
ABTOPEMOHT:fix-gl-compressed-texture-fallback
Nov 5, 2026
Merged

125hz merged 1 commit into
willfaust:mainfrom
ABTOPEMOHT:fix-gl-compressed-texture-fallback

Conversation

@ABTOPEMOHT

Copy link
Copy Markdown
Contributor

Fixes #566 (Mewgenics: about half of the textures draw as black rectangles under Zink).

Cause

Metal on A-series iPhones and iPads has no BC texture sampling (supportsBCTextureCompression = NO, as madeira-d3d12/src/pe/mad_bcn.cpp already notes for the A16). So MoltenVK and KosmicKrisp report no BC formats, and Zink's is_format_supported(PIPE_FORMAT_DXT5_RGBA) is false.

Mesa can cover for this: with allow_compressed_fallback it still exposes GL_EXT_texture_compression_s3tc, _s3tc_srgb, ARB_texture_compression_rgtc, EXT_texture_compression_latc and ARB_texture_compression_bptc, and decodes those uploads to RGBA8 on the CPU (st_compressed_format_fallback, st_UnmapTextureImage). The DRI frontends read that option from driconf, where it defaults to true (DRI_CONF_ALLOW_COMPRESSED_FALLBACK(true) in driinfo_gallium.h). OSMesa never reads driconf: OSMesaCreateContextAttribs memsets attribs, so the option stayed false and the extensions were missing.

A game that uploads DXT data without checking for the extension (every desktop GPU has it) then gets GL_INVALID_ENUM from glCompressedTexImage2D. The texture stays incomplete and samples as opaque black. That is why switching gl-vulkan to KosmicKrisp did not help: both drivers run on the same Metal GPU without BC.

Confirmation

On the device from #566 (iPhone 12 Pro Max, A14, Madeira 0.2.0, Zink on MoltenVK), this line in Mewgenics' own config makes every texture draw correctly:

env.MESA_EXTENSION_OVERRIDE = +GL_EXT_texture_compression_s3tc +GL_EXT_texture_compression_s3tc_srgb +GL_ARB_texture_compression_rgtc +GL_ARB_texture_compression_bptc

It turns on the same extensions that this patch exposes, and the same CPU decode then runs.

Change

  • build/mesa-ios/patches/0009-osmesa-allow-compressed-fallback.patch: OSMesa sets attribs.options.allow_compressed_fallback to true, the same default the DRI frontends use. MADEIRA_GL_COMPRESSED_FALLBACK=0 turns it off. A GPU that has BC keeps the native formats, because the fallback applies only when st->has_s3tc (or has_rgtc, has_bptc, ...) is false. This covers the MoltenVK and KosmicKrisp backends alike, because both go through OSMesa + Zink.
  • build/mesa-ios/patches/README.md: entry for 0009.
  • tests/x64/gls3tc-x64.c: uploads a solid-green 4x4 block as DXT1 and as DXT5, draws it, and reads a pixel back. Expected on an A14 to A16 device: fails before the patch (extension missing, pixel blue) and passes after it.

Testing

  • The patch applies cleanly to Mesa 25.0.7 (patch -p1 --forward). It touches only src/gallium/frontends/osmesa/osmesa.c, which no other patch in the set changes.
  • gls3tc-x64.c builds with clang (x86_64) and passes on a desktop GPU (NVIDIA, native S3TC), so the test logic itself is right.
  • Not done: I could not build the iOS Mesa (build/mesa-ios/build.sh needs macOS and Xcode) or run the patched build on the device. The fix is confirmed only through the MESA_EXTENSION_OVERRIDE workaround above.

🤖 Generated with Claude Code

…willfaust#566)

Metal on A-series iPhones and iPads has no BC texture sampling, so
MoltenVK and KosmicKrisp report no BC formats to Zink. Mesa still exposes
GL_EXT_texture_compression_s3tc, _s3tc_srgb, ARB_texture_compression_rgtc,
EXT_texture_compression_latc and ARB_texture_compression_bptc, and decodes
those uploads to RGBA8 on the CPU, but only with allow_compressed_fallback.
The DRI frontends read it from driconf, where it defaults to true. OSMesa
memsets its context attribs and never reads driconf, so it stayed false.
Games that upload DXT data without checking (Mewgenics) then got
GL_INVALID_ENUM and drew those textures as opaque black.

Patch 0009 turns the option on in OSMesa (MADEIRA_GL_COMPRESSED_FALLBACK=0
turns it off). tests/x64/gls3tc-x64.c checks a DXT1 and a DXT5 upload.

Confirmed on an iPhone 12 Pro Max (A14) by forcing the same extensions on
with MESA_EXTENSION_OVERRIDE: Mewgenics' textures draw correctly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: ABTOPEMOHT <163136224+ABTOPEMOHT@users.noreply.github.com>
@125hz
125hz merged commit f2fbc1a into willfaust:main Nov 5, 2026
125hz pushed a commit that referenced this pull request Nov 5, 2026
… (fixes Mewgenics black textures, #566) (#574)

Fixes #566 (Mewgenics: about half of the textures draw as black rectangles under Zink).
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.

Mewgenics (Steam 686060, OpenGL via Zink): about half of textures render as black rectangles

2 participants