Skip to content

Commit a0451d2

Browse files
committed
[visionOS] Implement visionOS XR module
The visionOS XR module only supports the Mobile renderer for now, the Forward+ renderer is not supported. To use the visionOS XR module you must set the new 'application/app_role' export setting to Immersive. You can choose if you want passthrough or not by the new 'application/immersion_style' export option. Then, initialize the visionOS VR module in a script: ``` var interface = XRServer.find_interface("visionOS") if interface and interface.initialize(): var viewport : Viewport = get_viewport() viewport.use_xr = true viewport.vrs_mode = Viewport.VRS_XR ``` Implementation details: - The visionOS platform now has two different execution paths implemented by the `GodotWindowScene` and `CompositorServicesImmersiveSpace` scenes in `app_visionos.swift`. The `application/app_role` export setting controls which scene is used. - The visionOS VR interface tries to be as close to the OpenXR interface as possible, to keep main renderer code changes to a minimum. It adopts Compositor Services and ARKit APIs, which is how you render Metal content on visionOS. - `XRInterface` has these new methods to spport the platform: `get_viewports_are_hdr()` (which avoids the sRGB conversion step on the tonemapper), `get_viewport_for_view()` (which provides individual viewports for each eye, which are larger than the render area when foveation is on). - We obtain and set the head pose twice, once in `process()` so scripts can use it if needed, and another in `pre_render()`, so the pose is more accurate for rendering. - The projection matrices returned by visionOS have an inverse depth correction applied (visionOS uses the [0, 1] z space, but Godot expects the [-1, 1] z space until the rendering step). - The `rasterizationRateMap` (the structure that supports foveation on visionOS) is provided through the `get_vrs_texture()` function, using the new `XR_VRS_TEXTURE_FORMAT_RASTERIZATION_RATE_MAP` texture type. It's' passed through the renderer when creating passes/subpasses, to be ultimately set by the Metal driver. - The Metal driver now needs to be able to set several viewports (one for each eye), so the DrawListInstructions `TYPE_SET_VIEWPORT` and TYPE_SET_SCISSOR have been replaced by `TYPE_SET_VIEWPORTS` and `TYPE_SET_SCISSORS`. If you pass a single viewport to the functions, they work as it used to. - The skybox shader has a new `SKY_VERSION_BACKGROUND_MULTIVIEW_WRITE_DEPTH` variant, because visionOS in immersive mode needs to write appropriate depth values. - Apple Vision Pro's' minimum supported near plane is `0.1`. There's a new editor warning emited by `XRCamera3D` if you set it to a lower value. - `XROrigin3D` emits a new editor warning if you change the scale, as it causes the rendered depth texture values to be incongruent to what XR platforms expect to perform reprojection (this applies to OpenXR platforms as well).
1 parent 06827c9 commit a0451d2

File tree

80 files changed

+2162
-223
lines changed

Some content is hidden

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

80 files changed

+2162
-223
lines changed

doc/classes/RenderingServer.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5336,7 +5336,10 @@
53365336
<constant name="VIEWPORT_VRS_XR" value="2" enum="ViewportVRSMode">
53375337
Variable rate shading texture is supplied by the primary [XRInterface]. Note that this may override the update mode.
53385338
</constant>
5339-
<constant name="VIEWPORT_VRS_MAX" value="3" enum="ViewportVRSMode">
5339+
<constant name="VIEWPORT_VRS_XR_RASTERIZATION_RATE_MAP" value="3" enum="ViewportVRSMode">
5340+
The variable rate shading texture is actually rasterization rate map (an opaque Objective-C object), used by Metal on Apple platforms to perform foveation. The Metal rendering driver applies it on the pipeline for rendering.
5341+
</constant>
5342+
<constant name="VIEWPORT_VRS_MAX" value="4" enum="ViewportVRSMode">
53405343
Represents the size of the [enum ViewportVRSMode] enum.
53415344
</constant>
53425345
<constant name="VIEWPORT_VRS_UPDATE_DISABLED" value="0" enum="ViewportVRSUpdateMode">

doc/classes/XRInterface.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@
8686
Returns the number of views that need to be rendered for this device. 1 for Monoscopic, 2 for Stereoscopic.
8787
</description>
8888
</method>
89+
<method name="get_viewport_for_view">
90+
<return type="Rect2i" />
91+
<param index="0" name="view" type="int" />
92+
<description>
93+
Returns the viewport for the view. When using foveation on Apple platforms, the viewport is larger that the rendering area.
94+
</description>
95+
</method>
96+
<method name="get_viewports_are_hdr">
97+
<return type="bool" />
98+
<description>
99+
Returns whether the viewports are HDR for the given platform. Apple Vision Pro has HRD displays, so the engine skips sRGB conversion step on the tonemapper.
100+
</description>
101+
</method>
89102
<method name="initialize">
90103
<return type="bool" />
91104
<description>

doc/classes/XRInterfaceExtension.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@
131131
Returns the number of views this interface requires, 1 for mono, 2 for stereoscopic.
132132
</description>
133133
</method>
134+
<method name="_get_viewport_for_view" qualifiers="virtual">
135+
<return type="Rect2i" />
136+
<param index="0" name="view" type="int" />
137+
<description>
138+
</description>
139+
</method>
134140
<method name="_get_vrs_texture" qualifiers="virtual">
135141
<return type="RID" />
136142
<description>

drivers/apple_embedded/apple_embedded.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#import "apple_embedded.h"
3232

33-
#import "app_delegate_service.h"
33+
#import "godot_app_delegate_service_apple_embedded.h"
3434
#import "godot_view_controller.h"
3535

3636
#import <CoreHaptics/CoreHaptics.h>

drivers/apple_embedded/bridging_header_apple_embedded.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#pragma once
3232

33-
#import "app_delegate_service.h"
34-
#import "godot_app_delegate.h"
33+
#import "godot_app_delegate_service_apple_embedded.h"
3534
#import "godot_view_apple_embedded.h"
3635
#import "godot_view_controller.h"

drivers/apple_embedded/display_server_apple_embedded.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
#import "display_server_apple_embedded.h"
3232

33-
#import "app_delegate_service.h"
3433
#import "apple_embedded.h"
34+
#import "godot_app_delegate_service_apple_embedded.h"
3535
#import "godot_keyboard_input_view.h"
3636
#import "godot_view_apple_embedded.h"
3737
#import "godot_view_controller.h"

drivers/apple_embedded/godot_app_delegate.h renamed to drivers/apple_embedded/godot_app_delegate_apple_embedded.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**************************************************************************/
2-
/* godot_app_delegate.h */
2+
/* godot_app_delegate_apple_embedded.h */
33
/**************************************************************************/
44
/* This file is part of: */
55
/* GODOT ENGINE */
@@ -34,7 +34,7 @@
3434

3535
typedef NSObject<UIApplicationDelegate> GDTAppDelegateServiceProtocol;
3636

37-
@interface GDTApplicationDelegate : NSObject <UIApplicationDelegate>
37+
@interface GDTAppDelegate : NSObject <UIApplicationDelegate>
3838

3939
@property(class, readonly, strong) NSArray<GDTAppDelegateServiceProtocol *> *services;
4040

drivers/apple_embedded/godot_app_delegate.mm renamed to drivers/apple_embedded/godot_app_delegate_apple_embedded.mm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**************************************************************************/
2-
/* godot_app_delegate.mm */
2+
/* godot_app_delegate_apple_embedded.mm */
33
/**************************************************************************/
44
/* This file is part of: */
55
/* GODOT ENGINE */
@@ -28,12 +28,13 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#import "godot_app_delegate.h"
31+
#import "godot_app_delegate_apple_embedded.h"
32+
33+
#import "godot_app_delegate_service_apple_embedded.h"
3234

33-
#import "app_delegate_service.h"
3435
#include "core/typedefs.h"
3536

36-
@implementation GDTApplicationDelegate
37+
@implementation GDTAppDelegate
3738

3839
static NSMutableArray<GDTAppDelegateServiceProtocol *> *services = nil;
3940

@@ -43,7 +44,7 @@ @implementation GDTApplicationDelegate
4344

4445
+ (void)load {
4546
services = [NSMutableArray new];
46-
[services addObject:[GDTAppDelegateService new]];
47+
// Add the specific GDTAppDelegateService subclass in each inheriting platform
4748
}
4849

4950
+ (void)addService:(GDTAppDelegateServiceProtocol *)service {

drivers/apple_embedded/app_delegate_service.h renamed to drivers/apple_embedded/godot_app_delegate_service_apple_embedded.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**************************************************************************/
2-
/* app_delegate_service.h */
2+
/* godot_app_delegate_service_apple_embedded.h */
33
/**************************************************************************/
44
/* This file is part of: */
55
/* GODOT ENGINE */
@@ -36,6 +36,6 @@
3636

3737
@interface GDTAppDelegateService : NSObject <UIApplicationDelegate>
3838

39-
@property(strong, class, nonatomic) GDTViewController *viewController;
39+
@property(weak, class, nonatomic, nullable) GDTViewController *viewController;
4040

4141
@end

drivers/apple_embedded/app_delegate_service.mm renamed to drivers/apple_embedded/godot_app_delegate_service_apple_embedded.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**************************************************************************/
2-
/* app_delegate_service.mm */
2+
/* godot_app_delegate_service_apple_embedded.mm */
33
/**************************************************************************/
44
/* This file is part of: */
55
/* GODOT ENGINE */
@@ -28,7 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#import "app_delegate_service.h"
31+
#import "godot_app_delegate_service_apple_embedded.h"
3232

3333
#import "godot_view_apple_embedded.h"
3434
#import "godot_view_controller.h"
@@ -58,14 +58,14 @@ @implementation GDTAppDelegateService
5858
SESSION_CATEGORY_SOLO_AMBIENT
5959
};
6060

61-
static GDTViewController *mainViewController = nil;
61+
static __weak GDTViewController *_viewController = nil;
6262

6363
+ (GDTViewController *)viewController {
64-
return mainViewController;
64+
return _viewController;
6565
}
6666

6767
+ (void)setViewController:(GDTViewController *)viewController {
68-
mainViewController = viewController;
68+
_viewController = viewController;
6969
}
7070

7171
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

0 commit comments

Comments
 (0)