Skip to content

Commit

Permalink
Various review tweaks, enabled Metal by default
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga committed Aug 20, 2024
1 parent ec6ab1b commit a2ca5bc
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ios_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
env:
# Used for the cache key. Add version suffix to force clean build.
GODOT_BASE_BRANCH: master
SCONSFLAGS: verbose=yes warnings=extra werror=yes debug_symbols=no module_text_server_fb_enabled=yes metal=yes
SCONSFLAGS: verbose=yes warnings=extra werror=yes debug_symbols=no module_text_server_fb_enabled=yes

concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-ios
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
env:
# Used for the cache key. Add version suffix to force clean build.
GODOT_BASE_BRANCH: master
SCONSFLAGS: verbose=yes warnings=extra werror=yes module_text_server_fb_enabled=yes metal=yes
SCONSFLAGS: verbose=yes warnings=extra werror=yes module_text_server_fb_enabled=yes

concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-macos
Expand Down
37 changes: 16 additions & 21 deletions drivers/metal/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Import("env")

env_metal = env.Clone()

# SPIRV-Cross
env_thirdparty = env.Clone()
env_thirdparty.disable_warnings()
# Thirdparty source files

thirdparty_obj = []

thirdparty_dir = "#thirdparty/spirv-cross/"
thirdparty_sources = [
"spirv_cfg.cpp",
Expand All @@ -20,35 +21,29 @@ thirdparty_sources = [
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]

# Must enable exceptions for SPIRV-Cross; otherwise, it will abort the process on errors
if "-fno-exceptions" in env_thirdparty["CXXFLAGS"]:
env_thirdparty["CXXFLAGS"].remove("-fno-exceptions")
env_thirdparty.Append(CXXFLAGS=["-fexceptions"])
thirdparty_obj = []
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
env_metal.drivers_sources += thirdparty_obj
env_metal.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include"])

# Must enable exceptions for SPIRV-Cross; otherwise, it will abort the process on errors.
if "-fno-exceptions" in env_metal["CXXFLAGS"]:
env_metal["CXXFLAGS"].remove("-fno-exceptions")
if "-std=gnu++17" in env_metal["CXXFLAGS"]:
env_metal["CXXFLAGS"].remove("-std=gnu++17")
env_metal.Append(CXXFLAGS=["-fexceptions"])

# Changes to the compiler flags for the Metal driver.
#
# * enable exceptions for spirv-cross
# * enable C++20 for the Objective-C++ Metal code, which uses C++20 concepts
env_metal.Append(CXXFLAGS=["-fexceptions", "-std=c++20"])
env_thirdparty = env_metal.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
env_metal.drivers_sources += thirdparty_obj

env_metal.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include"])
# Enable C++20 for the Objective-C++ Metal code, which uses C++20 concepts.
if "-std=gnu++17" in env_metal["CXXFLAGS"]:
env_metal["CXXFLAGS"].remove("-std=gnu++17")
env_metal.Append(CXXFLAGS=["-std=c++20"])

# Driver source files

driver_obj = []

# Driver source files
env_metal.add_source_files(driver_obj, "*.mm")

env_metal.drivers_sources += driver_obj
env.drivers_sources += driver_obj

# Needed to force rebuilding the driver files when the thirdparty library is updated.
env.Depends(driver_obj, thirdparty_obj)
2 changes: 0 additions & 2 deletions drivers/metal/metal_device_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
#ifndef METAL_DEVICE_PROPERTIES_H
#define METAL_DEVICE_PROPERTIES_H

#import "core/string/ustring.h"
#import "core/templates/hash_map.h"
#import "servers/rendering/rendering_device.h"

#import <Foundation/Foundation.h>
Expand Down
1 change: 1 addition & 0 deletions drivers/metal/metal_objects.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
/**************************************************************************/

#import "metal_objects.h"

#import "pixel_formats.h"
#import "rendering_device_driver_metal.h"

Expand Down
1 change: 1 addition & 0 deletions drivers/metal/pixel_formats.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
/**************************************************************************/

#import "pixel_formats.h"

#import "metal_utils.h"

#if TARGET_OS_IPHONE || TARGET_OS_TV
Expand Down
6 changes: 0 additions & 6 deletions drivers/metal/rendering_context_driver_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@

#import "rendering_context_driver_metal.h"

#import "core/config/project_settings.h"
#import "core/string/ustring.h"
#import "core/templates/local_vector.h"
#import "core/version.h"
#import "servers/rendering/rendering_device.h"

@protocol MTLDeviceEx <MTLDevice>
#if TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED < 130300
- (void)setShouldMaximizeConcurrentCompilation:(BOOL)v;
Expand Down
1 change: 0 additions & 1 deletion drivers/metal/rendering_device_driver_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

#import "metal_objects.h"

#import "core/templates/hash_map.h"
#import "servers/rendering/rendering_device_driver.h"

#import <Metal/Metal.h>
Expand Down
4 changes: 2 additions & 2 deletions drivers/metal/rendering_device_driver_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@
/**************************************************************************/

#import "rendering_device_driver_metal.h"

#import "pixel_formats.h"
#import "rendering_context_driver_metal.h"

#import "core/config/project_settings.h"
#import "core/io/compression.h"
#import "core/io/marshalls.h"
#import "core/string/ustring.h"
#import "core/templates/hash_map.h"

#import <Metal/MTLTexture.h>
#import <Metal/Metal.h>
#import <compression.h>
#import <spirv_msl.hpp>
#import <spirv_parser.hpp>

Expand Down
2 changes: 1 addition & 1 deletion modules/glslang/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def can_build(env, platform):
# glslang is only needed when Vulkan, Direct3D 12 or metal-based renderers are available,
# glslang is only needed when Vulkan, Direct3D 12 or Metal-based renderers are available,
# as OpenGL doesn't use glslang.
return env["vulkan"] or env["d3d12"] or env["metal"]

Expand Down
5 changes: 5 additions & 0 deletions platform/ios/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def get_flags():
"arch": "arm64",
"target": "template_debug",
"use_volk": False,
"metal": True,
"supported": ["mono"],
"builtin_pcre2_with_jit": False,
}
Expand Down Expand Up @@ -154,6 +155,10 @@ def configure(env: "SConsEnvironment"):
env.Prepend(CPPPATH=["#platform/ios"])
env.Append(CPPDEFINES=["IOS_ENABLED", "UNIX_ENABLED", "COREAUDIO_ENABLED"])

if env["metal"] and env["arch"] != "arm64":
# Only supported on arm64, so skip it for x86_64 builds.
env["metal"] = False

if env["metal"]:
env.AppendUnique(CPPDEFINES=["METAL_ENABLED", "RD_ENABLED"])
env.Prepend(
Expand Down
2 changes: 1 addition & 1 deletion platform/ios/display_server_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#ifdef METAL_ENABLED
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability"
// eliminate "RenderingContextDriverMetal is only available on iOS 14.0 or newer
// Eliminate "RenderingContextDriverMetal is only available on iOS 14.0 or newer".
RenderingContextDriverMetal::WindowPlatformData metal;
#pragma clang diagnostic pop
#endif
Expand Down
3 changes: 2 additions & 1 deletion platform/macos/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def get_flags():
return {
"arch": detect_arch(),
"use_volk": False,
"metal": True,
"supported": ["mono"],
}

Expand Down Expand Up @@ -240,7 +241,7 @@ def configure(env: "SConsEnvironment"):
env.Append(LINKFLAGS=["-rpath", "@executable_path/../Frameworks", "-rpath", "@executable_path"])

if env["metal"] and env["arch"] != "arm64":
print("Metal is only supported on arm64, so it will be skipped for x86 builds.")
# Only supported on arm64, so skip it for x86_64 builds.
env["metal"] = False

extra_frameworks = set()
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ Files extracted from upstream source:
- `include/` folder
- `LICENSE` and `LICENSES/` folder, minus `CC-BY-4.0.txt`

Versions of this SDK do not have to match the `vulkan` section, as this SDK is required
Versions of this SDK do not have to match the `vulkan` section, as this SDK is required
to generate Metal source from Vulkan SPIR-V.


Expand Down

0 comments on commit a2ca5bc

Please sign in to comment.