Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore support for older macOS/iOS version. Determine features at init, and use at runtime. #3284

Merged
merged 4 commits into from
May 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/renderer_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ inline void setViewType(ViewId _view, const bx::StringView _str)
bool m_autoGetMipmap;
};

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
static TextureFormatInfo s_textureFormat[] =
{
#define $0 MTLTextureSwizzleZero
Expand Down Expand Up @@ -344,6 +346,7 @@ inline void setViewType(ViewId _view, const bx::StringView _str)
#undef $B
#undef $A
};
#pragma clang diagnostic pop
BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) );

int32_t s_msaa[] =
Expand Down Expand Up @@ -485,7 +488,7 @@ bool init(const Init& _init)

#define CHECK_FEATURE_AVAILABLE(feature, ...) if (@available(__VA_ARGS__)) { feature = true; } else { feature = false; }

CHECK_FEATURE_AVAILABLE(m_usesNewMetalAPI, macOS 13.0, iOS 16.0, tvOS 16.0, macCatalyst 16.0, VISION_OS_MINIMUM *);
CHECK_FEATURE_AVAILABLE(m_usesMTLBindings, macOS 13.0, iOS 16.0, tvOS 16.0, macCatalyst 16.0, VISION_OS_MINIMUM *);
CHECK_FEATURE_AVAILABLE(m_hasCPUCacheModesAndStorageModes, iOS 9.0, macOS 10.11, macCatalyst 13.1, tvOS 9.0, VISION_OS_MINIMUM *);
CHECK_FEATURE_AVAILABLE(m_hasSynchronizeResource, macOS 10.11, macCatalyst 13.0, *);
CHECK_FEATURE_AVAILABLE(m_hasVSync, macOS 10.13, macCatalyst 13.1, *);
Expand Down Expand Up @@ -1972,6 +1975,9 @@ void setDepthStencilState(uint64_t _state, uint64_t _stencil = 0)
m_renderCommandEncoder.setStencilReferenceValue(ref);
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
void processArguments(
PipelineStateMtl* ps
, NSArray<id<MTLBinding>>* _vertexArgs
Expand All @@ -1992,7 +1998,7 @@ void processArguments(
{
BX_TRACE("arg: %s type:%d", utf8String(arg.name), arg.type);

if ((!m_usesNewMetalAPI && [arg isActive]) || (m_usesNewMetalAPI && arg.used))
if ((!m_usesMTLBindings && [(MTLArgument*)arg isActive]) || (m_usesMTLBindings && arg.used))
{
if (arg.type == MTLBindingTypeBuffer)
{
Expand Down Expand Up @@ -2140,6 +2146,7 @@ void processArguments(
}
}
}
#pragma clang diagnostic pop

PipelineStateMtl* getPipelineState(
uint64_t _state
Expand Down Expand Up @@ -2397,11 +2404,15 @@ void processArguments(

if (NULL != reflection)
{
if (m_usesNewMetalAPI) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
if (m_usesMTLBindings) {
processArguments(pso, reflection.vertexBindings, reflection.fragmentBindings);
} else {
processArguments(pso, reflection.vertexArguments, reflection.fragmentArguments);
}
#pragma clang diagnostic pop
}
}

Expand Down Expand Up @@ -2449,11 +2460,15 @@ void processArguments(
, &reflection
);

if (m_usesNewMetalAPI) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
if (m_usesMTLBindings) {
processArguments(pso, reflection.bindings, NULL);
} else {
processArguments(pso, reflection.arguments, NULL);
}
#pragma clang diagnostic pop

for (uint32_t ii = 0; ii < 3; ++ii)
{
Expand Down Expand Up @@ -2554,7 +2569,7 @@ void endEncoding()
bool m_hasStoreActionStoreAndMultisampleResolve;
bool m_hasCPUCacheModesAndStorageModes;
bool m_hasSynchronizeResource;
bool m_usesNewMetalAPI;
bool m_usesMTLBindings;
bool m_hasVSync;
bool m_hasMaximumDrawableCount;

Expand Down
Loading