Skip to content

Commit 34204bd

Browse files
committed
Merge pull request godotengine#114484 from stuartcarnie/metal_refactor_and_fixes
Metal: Refactor; fix dynamic uniforms; acyclic render graph support
2 parents 6136b7a + b815c88 commit 34204bd

173 files changed

Lines changed: 44714 additions & 5041 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

COPYRIGHT.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ Comment: meshoptimizer
432432
Copyright: 2016-2024, Arseny Kapoulkine
433433
License: Expat
434434

435+
Files: thirdparty/metal-cpp/*
436+
Comment: metal-cpp
437+
Copyright: 2024, Apple Inc.
438+
License: Apache-2.0
439+
435440
Files: thirdparty/mingw-std-threads/*
436441
Comment: mingw-std-threads
437442
Copyright: 2016, Mega Limited

drivers/apple/foundation_helpers.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,32 @@
3030

3131
#pragma once
3232

33+
#ifdef __OBJC__
3334
#import <Foundation/NSString.h>
35+
#else
36+
#include <Foundation/NSString.hpp>
37+
#endif
3438

3539
class String;
3640
template <typename T>
3741
class CharStringT;
3842

3943
using CharString = CharStringT<char>;
4044

45+
template <typename T>
46+
class Span;
47+
4148
namespace conv {
4249

50+
#ifdef __OBJC__
4351
/**
4452
* Converts a Godot String to an NSString without allocating an intermediate UTF-8 buffer.
4553
* */
4654
NSString *to_nsstring(const String &p_str);
55+
/**
56+
* Converts a Godot String to an NSString without allocating an intermediate UTF-8 buffer.
57+
* */
58+
NSString *to_nsstring(Span<char> p_str);
4759
/**
4860
* Converts a Godot CharString to an NSString without allocating an intermediate UTF-8 buffer.
4961
* */
@@ -52,5 +64,24 @@ NSString *to_nsstring(const CharString &p_str);
5264
* Converts an NSString to a Godot String without allocating intermediate buffers.
5365
* */
5466
String to_string(NSString *p_str);
67+
#else
68+
/**
69+
* Converts a Godot String to an NSString without allocating an intermediate UTF-8 buffer.
70+
* */
71+
NS::String *to_nsstring(const String &p_str);
72+
/**
73+
* Converts a Godot String to an NSString without allocating an intermediate UTF-8 buffer.
74+
* */
75+
NS::String *to_nsstring(Span<char> p_str);
76+
/**
77+
* Converts a Godot CharString to an NSString without allocating an intermediate UTF-8 buffer.
78+
* */
79+
NS::String *to_nsstring(const CharString &p_str);
80+
/**
81+
* Converts an NSString to a Godot String without allocating intermediate buffers.
82+
* */
83+
String to_string(NS::String *p_str);
84+
85+
#endif
5586

5687
} //namespace conv

drivers/apple/foundation_helpers.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#import "foundation_helpers.h"
3232

3333
#import "core/string/ustring.h"
34+
#import "core/templates/span.h"
3435

3536
#import <CoreFoundation/CFString.h>
3637

@@ -42,6 +43,12 @@
4243
encoding:NSUTF32LittleEndianStringEncoding];
4344
}
4445

46+
NSString *to_nsstring(Span<char> p_str) {
47+
return [[NSString alloc] initWithBytes:(const void *)p_str.ptr()
48+
length:p_str.size()
49+
encoding:NSASCIIStringEncoding];
50+
}
51+
4552
NSString *to_nsstring(const CharString &p_str) {
4653
return [[NSString alloc] initWithBytes:(const void *)p_str.ptr()
4754
length:p_str.length()

drivers/apple_embedded/SCsub

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ setup_swift_builder(
2727
vulkan_dir = "#thirdparty/vulkan"
2828
env_apple_embedded.Prepend(CPPPATH=[vulkan_dir, vulkan_dir + "/include"])
2929

30+
# Use bundled metal-cpp headers
31+
env_apple_embedded.Prepend(CPPPATH=["#thirdparty/metal-cpp"])
32+
3033
# Driver source files
3134
env_apple_embedded.add_source_files(env_apple_embedded.drivers_sources, "*.mm")
3235
env_apple_embedded.add_source_files(env_apple_embedded.drivers_sources, "*.swift")

drivers/apple_embedded/display_server_apple_embedded.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
if (rendering_driver == "metal") {
9797
if (@available(iOS 14.0, *)) {
9898
layer = [GDTAppDelegateService.viewController.godotView initializeRenderingForDriver:@"metal"];
99-
wpd.metal.layer = (CAMetalLayer *)layer;
99+
wpd.metal.layer = (__bridge CA::MetalLayer *)layer;
100100
rendering_context = memnew(RenderingContextDriverMetal);
101101
} else {
102102
OS::get_singleton()->alert("Metal is only supported on iOS 14.0 and later.");

drivers/apple_embedded/os_apple_embedded.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#import <UIKit/UIKit.h>
5252
#import <dlfcn.h>
5353
#include <sys/sysctl.h>
54+
#include <iterator>
5455

5556
#if defined(RD_ENABLED)
5657
#include "servers/rendering/renderer_rd/renderer_compositor_rd.h"

drivers/metal/SCsub

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ from misc.utility.scons_hints import *
33

44
Import("env")
55

6+
# If we're using Metal, we need metal-cpp.
7+
env.Prepend(CPPPATH=["#thirdparty/metal-cpp/"])
8+
69
env_metal = env.Clone()
710

811
# Thirdparty source files
@@ -23,6 +26,11 @@ thirdparty_sources = [
2326
]
2427
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
2528

29+
# Include metal-cpp
30+
thirdparty_sources += [
31+
"#thirdparty/metal-cpp/metal_cpp.cpp",
32+
]
33+
2634
env_metal.Prepend(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include"])
2735
env_metal.Prepend(CPPPATH=[thirdparty_spirv_headers_dir + "include/spirv/unified1"])
2836

@@ -48,7 +56,6 @@ env_metal.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
4856

4957
driver_obj = []
5058

51-
env_metal.add_source_files(driver_obj, "*.mm")
5259
env_metal.add_source_files(driver_obj, "*.cpp")
5360
env.drivers_sources += driver_obj
5461

0 commit comments

Comments
 (0)