Skip to content

Commit d04f9be

Browse files
committed
Introduce 'visionos' platform derived from 'apple_embedded'
1 parent adfd0e3 commit d04f9be

Some content is hidden

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

63 files changed

+2618
-18
lines changed

core/os/os.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ bool OS::has_feature(const String &p_feature) {
585585
}
586586
#endif
587587

588-
#if defined(IOS_SIMULATOR)
588+
#if defined(IOS_SIMULATOR) || defined(VISIONOS_SIMULATOR)
589589
if (p_feature == "simulator") {
590590
return true;
591591
}

doc/classes/ProjectSettings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,9 @@
900900
<member name="display/display_server/driver.macos" type="String" setter="" getter="">
901901
MacOS override for [member display/display_server/driver].
902902
</member>
903+
<member name="display/display_server/driver.visionos" type="String" setter="" getter="">
904+
visionOS override for [member display/display_server/driver].
905+
</member>
903906
<member name="display/display_server/driver.windows" type="String" setter="" getter="">
904907
Windows override for [member display/display_server/driver].
905908
</member>
@@ -3163,6 +3166,11 @@
31633166
- [code]metal[/code] (default), Metal from native drivers, only supported on Apple Silicon Macs. On Intel Macs, it will automatically fall back to [code]vulkan[/code] as Metal support is not implemented.
31643167
- [code]vulkan[/code], Vulkan over Metal via MoltenVK, supported on both Apple Silicon and Intel Macs.
31653168
</member>
3169+
<member name="rendering/rendering_device/driver.visionos" type="String" setter="" getter="" default="&quot;metal&quot;">
3170+
visionOS override for [member rendering/rendering_device/driver].
3171+
Only one option is supported:
3172+
- [code]metal[/code] (default), Metal from native drivers.
3173+
</member>
31663174
<member name="rendering/rendering_device/driver.windows" type="String" setter="" getter="" default="&quot;vulkan&quot;">
31673175
Windows override for [member rendering/rendering_device/driver].
31683176
Two options are supported:

drivers/SCsub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ if env["xaudio2"]:
2626
SConscript("xaudio2/SCsub")
2727

2828
# Shared Apple platform drivers
29-
if env["platform"] in ["macos", "ios"]:
29+
if env["platform"] in ["macos", "ios", "visionos"]:
3030
SConscript("apple/SCsub")
3131
SConscript("coreaudio/SCsub")
32-
if env["platform"] in ["ios"]:
32+
if env["platform"] in ["ios", "visionos"]:
3333
SConscript("apple_embedded/SCsub")
3434

3535
# Accessibility

drivers/metal/metal_device_properties.mm

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
#import "metal_device_properties.h"
5252

53+
#include "servers/rendering/renderer_rd/effects/metal_fx.h"
54+
5355
#import <Metal/Metal.h>
5456
#import <MetalFX/MetalFX.h>
5557
#import <spirv_cross.hpp>
@@ -63,7 +65,7 @@
6365
#define MTLGPUFamilyApple9 (MTLGPUFamily)1009
6466
#endif
6567

66-
API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0))
68+
API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0), visionos(1.0))
6769
MTLGPUFamily &operator--(MTLGPUFamily &p_family) {
6870
p_family = static_cast<MTLGPUFamily>(static_cast<int>(p_family) - 1);
6971
if (p_family < MTLGPUFamilyApple1) {
@@ -126,7 +128,11 @@
126128

127129
if (@available(macOS 13.0, iOS 16.0, tvOS 16.0, *)) {
128130
features.metal_fx_spatial = [MTLFXSpatialScalerDescriptor supportsDevice:p_device];
131+
#if !defined(VISIONOS_ENABLED)
129132
features.metal_fx_temporal = [MTLFXTemporalScalerDescriptor supportsDevice:p_device];
133+
#else
134+
features.metal_fx_temporal = false;
135+
#endif
130136
}
131137

132138
MTLCompileOptions *opts = [MTLCompileOptions new];
@@ -136,7 +142,7 @@
136142
features.mslVersion = SPIRV_CROSS_NAMESPACE::CompilerMSL::Options::make_msl_version(m_maj, m_min)
137143

138144
switch (features.mslVersionEnum) {
139-
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 150000 || __IPHONE_OS_VERSION_MAX_ALLOWED >= 180000 || __TV_OS_VERSION_MAX_ALLOWED >= 180000
145+
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 150000 || __IPHONE_OS_VERSION_MAX_ALLOWED >= 180000 || __TV_OS_VERSION_MAX_ALLOWED >= 180000 || __VISION_OS_VERSION_MAX_ALLOWED >= 20000
140146
case MTLLanguageVersion3_2:
141147
setMSLVersion(3, 2);
142148
break;
@@ -170,7 +176,7 @@
170176
case MTLLanguageVersion1_1:
171177
setMSLVersion(1, 1);
172178
break;
173-
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST
179+
#if TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST && !TARGET_OS_VISION
174180
case MTLLanguageVersion1_0:
175181
setMSLVersion(1, 0);
176182
break;
@@ -324,6 +330,7 @@
324330

325331
limits.maxDrawIndexedIndexValue = std::numeric_limits<uint32_t>::max() - 1;
326332

333+
#if METAL_MFXTEMPORAL_ENABLED
327334
if (@available(macOS 14.0, iOS 17.0, tvOS 17.0, *)) {
328335
limits.temporalScalerInputContentMinScale = (double)[MTLFXTemporalScalerDescriptor supportedInputContentMinScaleForDevice:p_device];
329336
limits.temporalScalerInputContentMaxScale = (double)[MTLFXTemporalScalerDescriptor supportedInputContentMaxScaleForDevice:p_device];
@@ -332,6 +339,11 @@
332339
limits.temporalScalerInputContentMinScale = 1.0;
333340
limits.temporalScalerInputContentMaxScale = 3.0;
334341
}
342+
#else
343+
// Defaults taken from macOS 14+
344+
limits.temporalScalerInputContentMinScale = 1.0;
345+
limits.temporalScalerInputContentMaxScale = 3.0;
346+
#endif
335347
}
336348

337349
MetalDeviceProperties::MetalDeviceProperties(id<MTLDevice> p_device) {

drivers/metal/pixel_formats.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ void clear(T *p_val, size_t p_count = 1) {
114114
}
115115

116116
bool PixelFormats::isPVRTCFormat(MTLPixelFormat p_format) {
117+
#if defined(VISIONOS_ENABLED)
118+
return false;
119+
#else
117120
switch (p_format) {
118121
case MTLPixelFormatPVRTC_RGBA_2BPP:
119122
case MTLPixelFormatPVRTC_RGBA_2BPP_sRGB:
@@ -127,6 +130,7 @@ void clear(T *p_val, size_t p_count = 1) {
127130
default:
128131
return false;
129132
}
133+
#endif
130134
}
131135

132136
MTLFormatType PixelFormats::getFormatType(DataFormat p_format) {
@@ -668,11 +672,13 @@ void clear(T *p_val, size_t p_count = 1) {
668672
addMTLPixelFormatDesc(RGBA32Sint, Color128, RWC);
669673
addMTLPixelFormatDesc(RGBA32Float, Color128, All);
670674

675+
#if !defined(VISIONOS_ENABLED)
671676
// Compressed pixel formats
672677
addMTLPixelFormatDesc(PVRTC_RGBA_2BPP, PVRTC_RGBA_2BPP, RF);
673678
addMTLPixelFormatDescSRGB(PVRTC_RGBA_2BPP_sRGB, PVRTC_RGBA_2BPP, RF, PVRTC_RGBA_2BPP);
674679
addMTLPixelFormatDesc(PVRTC_RGBA_4BPP, PVRTC_RGBA_4BPP, RF);
675680
addMTLPixelFormatDescSRGB(PVRTC_RGBA_4BPP_sRGB, PVRTC_RGBA_4BPP, RF, PVRTC_RGBA_4BPP);
681+
#endif
676682

677683
addMTLPixelFormatDesc(ETC2_RGB8, ETC2_RGB8, RF);
678684
addMTLPixelFormatDescSRGB(ETC2_RGB8_sRGB, ETC2_RGB8, RF, ETC2_RGB8);

drivers/metal/rendering_device_driver_metal.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,11 @@ _FORCE_INLINE_ MTLSize mipmapLevelSizeFromSize(MTLSize p_size, NSUInteger p_leve
290290
// Usage.
291291

292292
MTLResourceOptions options = 0;
293+
#if defined(VISIONOS_ENABLED)
294+
const bool supports_memoryless = true;
295+
#else
293296
const bool supports_memoryless = (*device_properties).features.highestFamily >= MTLGPUFamilyApple2 && (*device_properties).features.highestFamily < MTLGPUFamilyMac1;
297+
#endif
294298
if (supports_memoryless && p_format.usage_bits & TEXTURE_USAGE_TRANSIENT_BIT) {
295299
options = MTLResourceStorageModeMemoryless | MTLResourceHazardTrackingModeTracked;
296300
desc.storageMode = MTLStorageModeMemoryless;
@@ -2493,7 +2497,11 @@ void deserialize(BufReader &p_reader) {
24932497
cd->name = binary_data.shader_name;
24942498
cd->stage = shader_data.stage;
24952499
options.preserveInvariance = shader_data.is_position_invariant;
2500+
#if defined(VISIONOS_ENABLED)
2501+
options.mathMode = MTLMathModeFast;
2502+
#else
24962503
options.fastMathEnabled = YES;
2504+
#endif
24972505
MDLibrary *library = [MDLibrary newLibraryWithCacheEntry:cd
24982506
device:device
24992507
source:source

editor/SCsub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if env.editor_build:
2525
# Add all .cpp files in export folder
2626
env.add_source_files(env.editor_sources, f"../platform/{e}/export/*.cpp")
2727

28-
if "ios" in env.platform_exporters:
28+
if "ios" in env.platform_exporters or "visionos" in env.platform_exporters:
2929
env.add_source_files(env.editor_sources, "../drivers/apple_embedded/export/*.cpp")
3030

3131
# Core API documentation.

editor/export/macho.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class MachO : public RefCounted {
111111
PLATFORM_TVOSSIMULATOR = 8,
112112
PLATFORM_WATCHOSSIMULATOR = 9,
113113
PLATFORM_DRIVERKIT = 10,
114+
PLATFORM_VISIONOS = 11,
115+
PLATFORM_VISIONOSSIMULATOR = 12,
114116
};
115117

116118
struct LoadCommandHeader {

main/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
21912191
GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.linuxbsd", PROPERTY_HINT_ENUM, "vulkan"), "vulkan");
21922192
GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.android", PROPERTY_HINT_ENUM, "vulkan"), "vulkan");
21932193
GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.ios", PROPERTY_HINT_ENUM, "metal,vulkan"), "metal");
2194+
GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.visionos", PROPERTY_HINT_ENUM, "metal"), "metal");
21942195
GLOBAL_DEF_RST(PropertyInfo(Variant::STRING, "rendering/rendering_device/driver.macos", PROPERTY_HINT_ENUM, "metal,vulkan"), "metal");
21952196

21962197
GLOBAL_DEF_RST("rendering/rendering_device/fallback_to_vulkan", true);
@@ -2672,6 +2673,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
26722673
GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.linuxbsd", PROPERTY_HINT_ENUM_SUGGESTION, "default,x11,wayland,headless"), "default");
26732674
GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.android", PROPERTY_HINT_ENUM_SUGGESTION, "default,android,headless"), "default");
26742675
GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.ios", PROPERTY_HINT_ENUM_SUGGESTION, "default,iOS,headless"), "default");
2676+
GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.visionos", PROPERTY_HINT_ENUM_SUGGESTION, "default,visionOS,headless"), "default");
26752677
GLOBAL_DEF_NOVAL(PropertyInfo(Variant::STRING, "display/display_server/driver.macos", PROPERTY_HINT_ENUM_SUGGESTION, "default,macos,headless"), "default");
26762678

26772679
GLOBAL_DEF_RST_NOVAL("audio/driver/driver", AudioDriverManager::get_driver(0)->get_name());

methods.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,14 @@ def detect_darwin_sdk_path(platform, env):
636636
sdk_name = "iphonesimulator"
637637
var_name = "IOS_SDK_PATH"
638638

639+
elif platform == "visionos":
640+
sdk_name = "xros"
641+
var_name = "VISIONOS_SDK_PATH"
642+
643+
elif platform == "visionossimulator":
644+
sdk_name = "xrsimulator"
645+
var_name = "VISIONOS_SDK_PATH"
646+
639647
else:
640648
raise Exception("Invalid platform argument passed to detect_darwin_sdk_path")
641649

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSPrivacyAccessedAPITypes</key>
6+
$priv_api_types
7+
$priv_tracking
8+
$priv_collection
9+
</dict>
10+
</plist>

misc/dist/visionos_xcode/data.pck

Whitespace-only changes.

0 commit comments

Comments
 (0)