support rendering using Metal

This commit is contained in:
Struma 2022-01-16 19:57:50 -05:00
parent c2ebb1d234
commit 822b3ae550
11 changed files with 27 additions and 8 deletions

View file

@ -10,7 +10,7 @@ Despite the fact that it was made with Essentials games in mind, there is nothin
It supports Windows, Linux and both Intel and Apple Silicon versions of macOS.
Releases are [here](https://gitlab.com/mkxp-z/mkxp-z/-/releases). Requirements for running them are Windows 8.1+, Ubuntu 18.04+ (Fedora and Manjaro releases that age or newer *should* also be fine), or macOS 10.12+.
Releases are [here](https://gitlab.com/mkxp-z/mkxp-z/-/releases). Requirements for running them are Windows 8.1+, Ubuntu 18.04+ (Fedora and Manjaro releases that age or newer *should* also be fine), or macOS 10.12.2+.
I'd highly recommend [checking the gitbook](https://roza-gb.gitbook.io/mkxp-z) for more information than this readme contains.
@ -48,7 +48,7 @@ pacman -S git ruby base-devel mingw-w64-x86_64-cmake mingw-w64-x86_64-meson ming
pacman -S git ruby base-devel mingw-w64-i686-cmake mingw-w64-i686-meson mingw-w64-i686-gcc
```
+ **Linux (Ubuntu/Debian)**
+ **Linux (Ubuntu 18.04)**
```sh
sudo apt install git build-essential cmake meson autoconf automake libtool pkg-config ruby bison zlib1g-dev xorg-dev lib32z1 libasound2-dev libpulse-dev
@ -99,6 +99,6 @@ If a requested font is not found, no error is generated. Instead, a built-in fon
## What doesn't work (yet)
* Movie playback
* wma audio files
* Creating Bitmaps with sizes greater than the OpenGL texture size limit (around 16384 on modern cards).^
* Creating Bitmaps with sizes greater than your hardware's texture size limit (around 16384 on modern cards).^
^ There is an exception to this, called *mega surface*. When a Bitmap bigger than the texture limit is created from a file, it is not stored in VRAM, but regular RAM. Its sole purpose is to be used as a tileset bitmap. Any other operation to it (besides blitting to a regular Bitmap) will result in an error.

View file

@ -3,6 +3,4 @@ Here lives Google's ANGLE, which is pretty necessary right now.
On top of Apple deprecating OpenGL, MKXP has crashing issues from
the OpenGL -> Metal translation implemented in Apple Silicon macs.
Currently, the build of ANGLE here is the one provided with
Google Chrome/Chromium. Soon as ANGLE's gclient doesn't fail
on Apple Silicon macs, I'll build it myself.
This particular build of ANGLE is made using [this commit](https://github.com/google/angle/tree/0aae0d7ad535aedba34daea325269e419baead68), built with Metal support enabled. Both arm64 and x64 libraries were built using the `target_cpu` arg, then joined using the `lipo` tool.

View file

@ -458,7 +458,7 @@
3BC65DEB2584F3AD0063AFF1 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BD2B47A256534BA003DAD8A /* IOKit.framework */; };
3BC65DED2584F3AD0063AFF1 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BE081552568D3A60006849F /* Carbon.framework */; };
3BC65DEF2584F3AD0063AFF1 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BE081582568D3A60006849F /* AppKit.framework */; };
3BC65DF42584F3AD0063AFF1 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BE081542568D3A60006849F /* Metal.framework */; };
3BC65DF42584F3AD0063AFF1 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BE081542568D3A60006849F /* Metal.framework */; settings = {ATTRIBUTES = (Required, ); }; };
3BC65DF52584F3AD0063AFF1 /* ForceFeedback.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BE081572568D3A60006849F /* ForceFeedback.framework */; };
3BC65DF62584F3AD0063AFF1 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BE081532568D3A60006849F /* CoreVideo.framework */; };
3BC65DFA2584F3AD0063AFF1 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BE081562568D3A60006849F /* CoreGraphics.framework */; };

View file

@ -19,6 +19,11 @@
// (default: 0)
//
// "rgssVersion": 1,
// Render using Metal instead of OpenGL, if possible.
//
// Using Metal requires macOS 10.13+ and a compatible GPU.
// "preferMetalRenderer": true,
// Create a debug context and log
// OpenGL debug information to the console

View file

@ -88,6 +88,7 @@ Config::Config() {}
void Config::read(int argc, char *argv[]) {
auto optsJ = json::object({
{"rgssVersion", 0},
{"preferMetalRenderer", true},
{"debugMode", false},
{"printFPS", false},
{"winResizable", true},
@ -156,7 +157,8 @@ try { exp } catch (...) {}
editor.battleTest = true;
for (int i = 1; i < argc; i++) {
launchArgs.push_back(argv[i]);
if (!strcmp(argv[i], "debug"))
launchArgs.push_back(argv[i]);
}
}
@ -191,6 +193,7 @@ try { exp } catch (...) {}
#define SET_STRINGOPT(var, key) GUARD(var = std::string(opts[#key].as_string());)
SET_OPT(rgssVersion, integer);
SET_OPT(preferMetalRenderer, boolean);
SET_OPT(debugMode, boolean);
SET_OPT(printFPS, boolean);
SET_OPT(fullscreen, boolean);

View file

@ -35,6 +35,7 @@ struct Config {
int rgssVersion;
bool debugMode;
bool preferMetalRenderer;
bool printFPS;
bool winResizable;

View file

@ -325,6 +325,8 @@ int main(int argc, char *argv[]) {
// LoadLibrary properly initializes EGL, it won't work otherwise.
// Doesn't completely do it though, needs a small patch to SDL
#ifdef MKXPZ_BUILD_XCODE
// Setting OpenGL only works when building in Release mode due to the config getting re-read later
SDL_setenv("ANGLE_DEFAULT_PLATFORM", (conf.preferMetalRenderer && isMetalSupported()) ? "metal" : "opengl", true);
SDL_GL_LoadLibrary("@rpath/libEGL.dylib");
#endif
#endif

View file

@ -41,6 +41,7 @@ WineHostType getRealHostType();
#ifdef MKXPZ_BUILD_XCODE
void openSettingsWindow();
bool isMetalSupported();
#endif
namespace mkxp_sys = systemImpl;

View file

@ -6,6 +6,8 @@
//
#import <AppKit/AppKit.h>
#import <Metal/Metal.h>
#import <sys/sysctl.h>
#import "system.h"
#import "SettingsMenuController.h"
@ -53,3 +55,10 @@ void openSettingsWindow() {
}
[smenu raise];
}
bool isMetalSupported() {
if (@available(macOS 10.13.0, *)) {
return MTLCreateSystemDefaultDevice() != nil;
}
return false;
}