Skip to content

Commit

Permalink
Fixed bug 5213 - Add support to metal in iOS/tvOS simulator
Browse files Browse the repository at this point in the history
Vincent Hamm

Xcode11 and ios13 added support for metal simulator.
Here is a quick and dirty patch to enable it. Pretty early and only tested on a few samples for now. Required mostly to enable metal support on correct version of ios, generate simulator compatible shaders and enforce buffer alignments on simulator (same as osx).
  • Loading branch information
slouken committed Dec 9, 2020
1 parent cb36189 commit 7fa5e95
Show file tree
Hide file tree
Showing 8 changed files with 8,545 additions and 4,399 deletions.
6 changes: 4 additions & 2 deletions include/SDL_config_iphoneos.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@
#define SDL_VIDEO_RENDER_OGL_ES 1
#define SDL_VIDEO_RENDER_OGL_ES2 1

/* Metal supported on 64-bit devices running iOS 8.0 and tvOS 9.0 and newer */
#if !TARGET_OS_SIMULATOR && !TARGET_CPU_ARM && ((__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 90000))
/* Metal supported on 64-bit devices running iOS 8.0 and tvOS 9.0 and newer
Also supported in simulator from iOS 13.0 and tvOS 13.0
*/
#if (TARGET_OS_SIMULATOR && ((__IPHONE_OS_VERSION_MIN_REQUIRED >= 130000) || (__TV_OS_VERSION_MIN_REQUIRED >= 130000))) || (!TARGET_CPU_ARM && ((__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 90000)))
#define SDL_PLATFORM_SUPPORTS_METAL 1
#else
#define SDL_PLATFORM_SUPPORTS_METAL 0
Expand Down
10 changes: 9 additions & 1 deletion src/render/metal/SDL_render_metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@
#ifdef __MACOSX__
#include "SDL_shaders_metal_osx.h"
#elif defined(__TVOS__)
#if TARGET_OS_SIMULATOR
#include "SDL_shaders_metal_tvsimulator.h"
#else
#include "SDL_shaders_metal_tvos.h"
#endif
#else
#if TARGET_OS_SIMULATOR
#include "SDL_shaders_metal_iphonesimulator.h"
#else
#include "SDL_shaders_metal_ios.h"
#endif
#endif

/* Apple Metal renderer implementation */

Expand All @@ -51,7 +59,7 @@

/* macOS requires constants in a buffer to have a 256 byte alignment. */
/* Use native type alignments from https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf */
#ifdef __MACOSX__
#if defined(__MACOSX__) || TARGET_OS_SIMULATOR
#define CONSTANT_ALIGN(x) (256)
#else
#define CONSTANT_ALIGN(x) (x < 4 ? 4 : x)
Expand Down
2,885 changes: 1,436 additions & 1,449 deletions src/render/metal/SDL_shaders_metal_ios.h

Large diffs are not rendered by default.

2,086 changes: 2,086 additions & 0 deletions src/render/metal/SDL_shaders_metal_iphonesimulator.h

Large diffs are not rendered by default.

2,979 changes: 1,482 additions & 1,497 deletions src/render/metal/SDL_shaders_metal_osx.h

Large diffs are not rendered by default.

2,885 changes: 1,436 additions & 1,449 deletions src/render/metal/SDL_shaders_metal_tvos.h

Large diffs are not rendered by default.

2,089 changes: 2,089 additions & 0 deletions src/render/metal/SDL_shaders_metal_tvsimulator.h

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/render/metal/build-metal-shaders.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cd `dirname "$0"`

generate_shaders()
{
fileplatform=$1
fileplatform=$1
compileplatform=$2
sdkplatform=$3
minversion=$4
Expand All @@ -19,4 +19,6 @@ generate_shaders()

generate_shaders osx osx macosx 10.11
generate_shaders ios ios iphoneos 8.0
generate_shaders iphonesimulator ios iphonesimulator 8.0
generate_shaders tvos ios appletvos 9.0
generate_shaders tvsimulator ios appletvsimulator 9.0

0 comments on commit 7fa5e95

Please sign in to comment.