Skip to content

Commit

Permalink
Merge pull request #1273 from billhollings/simulator-buffer-alignment
Browse files Browse the repository at this point in the history
Set Metal buffer alignment to 256 on non-Apple Silicon iOS/tvOS simulators.
  • Loading branch information
billhollings committed Feb 21, 2021
2 parents ef64dc4 + 4675481 commit 3058a13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Common/MVKCommonEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1545,6 +1545,11 @@
break;
#endif
}

// 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
}

// Initializes the physical device features of this instance.
Expand Down

0 comments on commit 3058a13

Please sign in to comment.