Skip to content

Instantly share code, notes, and snippets.

@rb6502
Created June 13, 2023 17:05
Show Gist options
  • Save rb6502/b3091421d0fd4f75c648359ee590ab9c to your computer and use it in GitHub Desktop.
Save rb6502/b3091421d0fd4f75c648359ee590ab9c 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..1157c233f40 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
@@ -320,12 +339,21 @@ inline void setViewType(ViewId _view, const bx::StringView _str)
{ MTLPixelFormatRGBA32Sint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // RGBA32I
{ MTLPixelFormatRGBA32Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // RGBA32U
{ MTLPixelFormatRGBA32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // RGBA32F
+#ifdef OLD_MACOS
+ { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // BGR5A1
+ { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $B, $G, $R, $A }, true }, // RGB5A1
+ { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // BGR5A1
+ { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $B, $G, $R, $A }, true }, // RGB5A1
+ { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // BGR5A1
+ { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $B, $G, $R, $A }, true }, // RGB5A1
+#else
{ MTLPixelFormatB5G6R5Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // B5G6R5
{ 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
{ 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
@@ -551,6 +579,7 @@ bool init(const Init& _init)
m_screenshotBlitRenderPipelineState = m_device.newRenderPipelineStateWithDescriptor(m_renderPipelineDescriptor);
{
+ #ifndef OLD_MACOS
if ([m_device respondsToSelector: @selector(supportsFamily:)])
{
if ([m_device supportsFamily: MTLGPUFamily(1004) /*MTLGPUFamilyApple4*/])
@@ -575,6 +604,7 @@ bool init(const Init& _init)
}
}
}
+ #endif
#if BX_PLATFORM_OSX
if (0 == g_caps.vendorId)
@@ -2917,8 +2947,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

This seems promising. The build has gone further now than it has for months already, so I’m assuming it’ll actually finish this time. I’ll let you know how it goes, so far, so good.

@mac-a-r0ni
Copy link

We have a winner, winner, chicken dinner with this one! Tested and all appears in working order.

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