Skip to content

Instantly share code, notes, and snippets.

@rb6502
Created May 19, 2023 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rb6502/8a1736ee3775f998e8e71faa47ae4b59 to your computer and use it in GitHub Desktop.
Save rb6502/8a1736ee3775f998e8e71faa47ae4b59 to your computer and use it in GitHub Desktop.
Experimental MAME patch for macOS 10.14/10.15
diff --git a/3rdparty/bgfx/src/renderer_mtl.mm b/3rdparty/bgfx/src/renderer_mtl.mm
index 2317c16d6b5..7d97f1c5d78 100644
--- a/3rdparty/bgfx/src/renderer_mtl.mm
+++ b/3rdparty/bgfx/src/renderer_mtl.mm
@@ -14,6 +14,12 @@
# include <Cocoa/Cocoa.h>
#endif
+#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 110000
+#undef OLD_MACOS
+#else
+#define OLD_MACOS
+#endif
+
#import <Foundation/Foundation.h>
#define UNIFORM_BUFFER_SIZE (8*1024*1024)
@@ -212,18 +218,31 @@ inline void setViewType(ViewId _view, const bx::StringView _str)
MTLPixelFormat m_fmt;
MTLPixelFormat m_fmtSrgb;
MTLReadWriteTextureTier m_rwTier;
+#ifdef OLD_MACOS
+ uint8_t m_mapping[4];
+#else
MTLTextureSwizzleChannels m_mapping;
+#endif
bool m_autoGetMipmap;
};
static TextureFormatInfo s_textureFormat[] =
{
+#ifdef OLD_MACOS
+#define $0 0
+#define $1 1
+#define $R 2
+#define $G 3
+#define $B 4
+#define $A 5
+#else
#define $0 MTLTextureSwizzleZero
#define $1 MTLTextureSwizzleOne
#define $R MTLTextureSwizzleRed
#define $G MTLTextureSwizzleGreen
#define $B MTLTextureSwizzleBlue
#define $A MTLTextureSwizzleAlpha
+#endif
{ MTLPixelFormat(130/*BC1_RGBA*/), MTLPixelFormat(131/*BC1_RGBA_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BC1
{ MTLPixelFormat(132/*BC2_RGBA*/), MTLPixelFormat(133/*BC2_RGBA_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BC2
{ MTLPixelFormat(134/*BC3_RGBA*/), MTLPixelFormat(135/*BC3_RGBA_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BC3
@@ -2917,8 +2936,9 @@ void writeString(bx::WriterI* _writer, const char* _str)
desc.mipmapLevelCount = ti.numMips;
desc.sampleCount = 1;
desc.arrayLength = ti.numLayers;
+#ifndef OLD_MACOS
desc.swizzle = tfi.m_mapping;
-
+#endif
if (s_renderMtl->m_iOS9Runtime
|| s_renderMtl->m_macOS11Runtime)
{
@mac-a-r0ni
Copy link

mac-a-r0ni commented Jun 12, 2023

bash-3.2$ patch -p1 <bgfx.diff
patching file 3rdparty/bgfx/src/renderer_mtl.mm
Hunk #1 succeeded at 14 with fuzz 1.
Hunk #2 FAILED at 218.
Hunk #3 FAILED at 2936.
2 out of 3 hunks FAILED -- saving rejects to file 3rdparty/bgfx/src/renderer_mtl.mm.rej

This fails to patch on 0.255. Applying the patches manually also fails building on 10.14 with the command line tools for xcode 11.3.1.

@mac-a-r0ni
Copy link

I’m getting a error:‘MTLPixelFormatBGR5A1Unorm’ is unavailable: not available on macOS
This is with NOWERROR=1 specified on the make command

@rb6502
Copy link
Author

rb6502 commented Jun 12, 2023

Try this revised version, which applies cleanly to 0.255 and fixes the MTLPixelFormatBGR5A1Unorm thing.

https://gist.github.com/rb6502/f27ae0c6f3ec961d229baee77caf5dcc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment