Skip to content

Instantly share code, notes, and snippets.

@rb6502
Created June 12, 2023 23:04
Show Gist options
  • Save rb6502/f27ae0c6f3ec961d229baee77caf5dcc to your computer and use it in GitHub Desktop.
Save rb6502/f27ae0c6f3ec961d229baee77caf5dcc to your computer and use it in GitHub Desktop.
diff --git a/3rdparty/bgfx/src/renderer_mtl.mm b/3rdparty/bgfx/src/renderer_mtl.mm
index 2317c16d6b5..27dccdbd7bc 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;
- MTLTextureSwizzleChannels m_mapping;
+#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
@@ -324,8 +343,13 @@ inline void setViewType(ViewId _view, const bx::StringView _str)
{ MTLPixelFormatB5G6R5Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $B, $G, $R, $A }, true }, // R5G6B5
{ MTLPixelFormatABGR4Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $G, $B, $A, $R }, true }, // BGRA4
{ MTLPixelFormatABGR4Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $A, $B, $G, $R }, true }, // RGBA4
+#ifdef OLD_MACOS
+ { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // BGR5A1
+ { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $B, $G, $R, $A }, true }, // RGB5A1
+#else
{ MTLPixelFormatBGR5A1Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // BGR5A1
{ MTLPixelFormatBGR5A1Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $B, $G, $R, $A }, true }, // RGB5A1
+#endif
{ MTLPixelFormatRGB10A2Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RGB10A2
{ MTLPixelFormatRG11B10Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RG11B10F
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // UnknownDepth
@@ -2917,8 +2941,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

Well now we have a failure at “MTLPixelFormatB5G6R5Unorm” but it applies cleanly.

@rb6502
Copy link
Author

rb6502 commented Jun 13, 2023

@mac-a-r0ni
Copy link

mac-a-r0ni commented Jun 13, 2023

Only the 4th hunk applied cleanly on the third patch, but I manually wrote the changes and it's building now.... crossing fingers, knocking on wood, etc.. I'll let you know if it succeeds.

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