From 0d1975907ed8911b9865d54e11f900c0b0820fcd Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Thu, 18 Feb 2021 17:13:34 -0500 Subject: [PATCH 1/2] Set Metal buffer alignment to 256 on non-Apple Silicon iOS/tvOS simulators. --- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 74df97de6..1396f7290 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -1428,7 +1428,7 @@ if (supportsMTLGPUFamily(Apple5)) { // This is an Apple GPU--treat it accordingly. _metalFeatures.mtlCopyBufferAlignment = 1; - _metalFeatures.mtlBufferAlignment = 16; + _metalFeatures.mtlBufferAlignment = 16; // Min float4 alignment for typical vertex buffers. MTLBuffer may go down to 4 bytes for other data. _metalFeatures.maxQueryBufferSize = (64 * KIBI); _metalFeatures.maxPerStageDynamicMTLBufferCount = _metalFeatures.maxPerStageBufferCount; _metalFeatures.postDepthCoverage = true; @@ -1545,6 +1545,15 @@ break; #endif } + + // iOS and tvOS adjustments necessary when running in the simulator on non-Apple GPUs. + // Apple1 used as baseline for detecting Apple Silicon on macOS because Apple7 not supported for tvOS. + // Must run after setting native iOS and tvOS values above. +#if MVK_OS_SIMULATOR + if ( !supportsMTLGPUFamily(Apple1) ) { + _metalFeatures.mtlBufferAlignment = 256; + } +#endif } // Initializes the physical device features of this instance. From 4675481a061397120385967484c2df252bd91016 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Sat, 20 Feb 2021 09:33:32 -0500 Subject: [PATCH 2/2] Redefine derivations of MVK_APPLE_SILICON, MVK_MACOS_APPLE_SILICON, and MVK_XCODE_12. Derive MVK_APPLE_SILICON from target CPU. Derive MVK_MACOS_APPLE_SILICON from target CPU and macOS platform. Derive MVK_XCODE_12 from macOS and iOS SDK versions. Test for simulator on non-Apple GPU using MVK_OS_SIMULATOR && !MVK_APPLE_SILICON. --- Common/MVKCommonEnvironment.h | 14 +++++++------- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 10 +++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Common/MVKCommonEnvironment.h b/Common/MVKCommonEnvironment.h index 6d72a8594..2e61f97cd 100644 --- a/Common/MVKCommonEnvironment.h +++ b/Common/MVKCommonEnvironment.h @@ -77,19 +77,19 @@ extern "C" { # define MVK_OS_SIMULATOR TARGET_OS_SIMULATOR #endif -/** Building for macOS with support for Apple Silicon. */ -#ifndef MVK_MACOS_APPLE_SILICON -# define MVK_MACOS_APPLE_SILICON (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600) +/** Building for Apple Silicon on iOS, tvOS, or macOS platform. */ +#ifndef MVK_APPLE_SILICON +# define MVK_APPLE_SILICON TARGET_CPU_ARM64 #endif -/** Building for Apple Silicon. */ -#ifndef MVK_APPLE_SILICON -# define MVK_APPLE_SILICON (MVK_IOS || MVK_TVOS || MVK_MACOS_APPLE_SILICON) +/** Building for macOS with support for Apple Silicon. */ +#ifndef MVK_MACOS_APPLE_SILICON +# define MVK_MACOS_APPLE_SILICON (MVK_MACOS && MVK_APPLE_SILICON) #endif /** Building with Xcode 12. */ #ifndef MVK_XCODE_12 -# define MVK_XCODE_12 (MVK_MACOS_APPLE_SILICON || \ +# define MVK_XCODE_12 ((__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600) || \ (__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000)) // Also covers tvOS #endif diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 1396f7290..10de87798 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -1546,13 +1546,9 @@ #endif } - // iOS and tvOS adjustments necessary when running in the simulator on non-Apple GPUs. - // Apple1 used as baseline for detecting Apple Silicon on macOS because Apple7 not supported for tvOS. - // Must run after setting native iOS and tvOS values above. -#if MVK_OS_SIMULATOR - if ( !supportsMTLGPUFamily(Apple1) ) { - _metalFeatures.mtlBufferAlignment = 256; - } +// iOS and tvOS adjustments necessary when running in the simulator on non-Apple GPUs. +#if MVK_OS_SIMULATOR && !MVK_APPLE_SILICON + _metalFeatures.mtlBufferAlignment = 256; #endif }