Skip to content

Commit c5aae72

Browse files
committed
OpenXR: Add support for frame synthesis
1 parent 8327dfa commit c5aae72

11 files changed

+653
-20
lines changed

doc/classes/ProjectSettings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,6 +3518,10 @@
35183518
<member name="xr/openxr/extensions/eye_gaze_interaction" type="bool" setter="" getter="" default="false">
35193519
Specify whether to enable eye tracking for this project. Depending on the platform, additional export configuration may be needed.
35203520
</member>
3521+
<member name="xr/openxr/extensions/frame_synthesis" type="bool" setter="" getter="" default="false">
3522+
If [code]true[/code] the frame synthesis extension will be activated if supported by the platform.
3523+
[b]Note:[/b] This feature should not be enabled in conjunction with Application Space Warp, if supported this replaces ASW.
3524+
</member>
35213525
<member name="xr/openxr/extensions/hand_interaction_profile" type="bool" setter="" getter="" default="false">
35223526
If [code]true[/code] the hand interaction profile extension will be activated if supported by the platform.
35233527
</member>

main/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
27102710
// OpenXR project extensions settings.
27112711
GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/extensions/debug_utils", PROPERTY_HINT_ENUM, "Disabled,Error,Warning,Info,Verbose"), "0");
27122712
GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "xr/openxr/extensions/debug_message_types", PROPERTY_HINT_FLAGS, "General,Validation,Performance,Conformance"), "15");
2713+
GLOBAL_DEF_BASIC("xr/openxr/extensions/frame_synthesis", false);
27132714
GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking", false);
27142715
GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking_unobstructed_data_source", false); // XR_HAND_TRACKING_DATA_SOURCE_UNOBSTRUCTED_EXT
27152716
GLOBAL_DEF_BASIC("xr/openxr/extensions/hand_tracking_controller_data_source", false); // XR_HAND_TRACKING_DATA_SOURCE_CONTROLLER_EXT

modules/openxr/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def get_doc_classes():
1919
"OpenXRAPIExtension",
2020
"OpenXRExtensionWrapper",
2121
"OpenXRExtensionWrapperExtension",
22+
"OpenXRFrameSynthesisExtension",
2223
"OpenXRFutureResult",
2324
"OpenXRFutureExtension",
2425
"OpenXRInteractionProfile",

modules/openxr/doc_classes/OpenXRExtensionWrapper.xml

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,26 @@
217217
[param layer] is a pointer to an [code]XrCompositionLayerBaseHeader[/code] struct.
218218
</description>
219219
</method>
220+
<method name="_prepare_view_configuration" qualifiers="virtual">
221+
<return type="void" />
222+
<param index="0" name="view_count" type="int" />
223+
<description>
224+
Called before [method _set_view_configuration_and_get_next_pointer] to allow the extension to reserve data for the given number of views.
225+
</description>
226+
</method>
227+
<method name="_print_view_configuration_info" qualifiers="virtual const">
228+
<return type="void" />
229+
<param index="0" name="view" type="int" />
230+
<description>
231+
Called to allow an extension to print additional information about its view configuration, if applicable. This will only be called if verbose output is enabled.
232+
</description>
233+
</method>
220234
<method name="_set_android_surface_swapchain_create_info_and_get_next_pointer" qualifiers="virtual">
221235
<return type="int" />
222236
<param index="0" name="property_values" type="Dictionary" />
223237
<param index="1" name="next_pointer" type="void*" />
224238
<description>
225-
Adds additional data structures to Android surface swapchains created by [OpenXRCompositionLayer].
239+
Add additional data structures to Android surface swapchains created by [OpenXRCompositionLayer].
226240
[param property_values] contains the values of the properties returned by [method _get_viewport_composition_layer_extension_properties].
227241
[b]Note:[/b] This virtual method will be called on the render thread.
228242
</description>
@@ -231,7 +245,7 @@
231245
<return type="int" />
232246
<param index="0" name="next_pointer" type="void*" />
233247
<description>
234-
Adds additional data structures to [code]XrFrameEndInfo[/code].
248+
Add additional data structures to [code]XrFrameEndInfo[/code].
235249
This will only be called if the extension previously registered itself with [method OpenXRAPIExtension.register_frame_info_extension].
236250
[b]Note:[/b] This virtual method will be called on the render thread. Additionally, the data it returns will be used shortly after this method is called, so it needs to remain valid until the next time [method _on_pre_render] runs.
237251
</description>
@@ -240,7 +254,7 @@
240254
<return type="int" />
241255
<param index="0" name="next_pointer" type="void*" />
242256
<description>
243-
Adds additional data structures to [code]XrFrameWaitInfo[/code].
257+
Add additional data structures to [code]XrFrameWaitInfo[/code].
244258
This will only be called if the extension previously registered itself with [method OpenXRAPIExtension.register_frame_info_extension].
245259
[b]Note:[/b] This virtual method will be called on the render thread.
246260
</description>
@@ -250,22 +264,22 @@
250264
<param index="0" name="hand_index" type="int" />
251265
<param index="1" name="next_pointer" type="void*" />
252266
<description>
253-
Adds additional data structures when each hand tracker is created.
267+
Add additional data structures when each hand tracker is created.
254268
</description>
255269
</method>
256270
<method name="_set_instance_create_info_and_get_next_pointer" qualifiers="virtual">
257271
<return type="int" />
258272
<param index="0" name="next_pointer" type="void*" />
259273
<description>
260-
Adds additional data structures when the OpenXR instance is created.
274+
Add additional data structures when the OpenXR instance is created.
261275
</description>
262276
</method>
263277
<method name="_set_projection_views_and_get_next_pointer" qualifiers="virtual">
264278
<return type="int" />
265279
<param index="0" name="view_index" type="int" />
266280
<param index="1" name="next_pointer" type="void*" />
267281
<description>
268-
Adds additional data structures to the projection view of the given [param view_index].
282+
Add additional data structures to the projection view of the given [param view_index].
269283
[b]Note:[/b] This virtual method will be called on the render thread. Additionally, the data it returns will be used shortly after this method is called, so it needs to remain valid until the next time [method _on_pre_render] runs.
270284
</description>
271285
</method>
@@ -274,35 +288,43 @@
274288
<param index="0" name="reference_space_type" type="int" />
275289
<param index="1" name="next_pointer" type="void*" />
276290
<description>
277-
Adds additional data structures to [code]XrReferenceSpaceCreateInfo[/code].
291+
Add additional data structures to [code]XrReferenceSpaceCreateInfo[/code].
278292
</description>
279293
</method>
280294
<method name="_set_session_create_and_get_next_pointer" qualifiers="virtual">
281295
<return type="int" />
282296
<param index="0" name="next_pointer" type="void*" />
283297
<description>
284-
Adds additional data structures when the OpenXR session is created.
298+
Add additional data structures when the OpenXR session is created.
285299
</description>
286300
</method>
287301
<method name="_set_swapchain_create_info_and_get_next_pointer" qualifiers="virtual">
288302
<return type="int" />
289303
<param index="0" name="next_pointer" type="void*" />
290304
<description>
291-
Adds additional data structures when creating OpenXR swapchains.
305+
Add additional data structures when creating OpenXR swapchains.
292306
</description>
293307
</method>
294308
<method name="_set_system_properties_and_get_next_pointer" qualifiers="virtual">
295309
<return type="int" />
296310
<param index="0" name="next_pointer" type="void*" />
297311
<description>
298-
Adds additional data structures when querying OpenXR system abilities.
312+
Add additional data structures when querying OpenXR system abilities.
313+
</description>
314+
</method>
315+
<method name="_set_view_configuration_and_get_next_pointer" qualifiers="virtual">
316+
<return type="int" />
317+
<param index="0" name="view" type="int" />
318+
<param index="1" name="next_pointer" type="void*" />
319+
<description>
320+
Add additional data structures when querying OpenXR view configuration.
299321
</description>
300322
</method>
301323
<method name="_set_view_locate_info_and_get_next_pointer" qualifiers="virtual">
302324
<return type="int" />
303325
<param index="0" name="next_pointer" type="void*" />
304326
<description>
305-
Adds additional data structures to [code]XrViewLocateInfo[/code].
327+
Add additional data structures to [code]XrViewLocateInfo[/code].
306328
This will only be called if the extension previously registered itself with [method OpenXRAPIExtension.register_frame_info_extension].
307329
[b]Note:[/b] This virtual method will be called on the render thread. Additionally, the data it returns will be used shortly after this method is called, so it needs to remain valid until the next time [method _on_pre_render] runs.
308330
</description>
@@ -313,7 +335,7 @@
313335
<param index="1" name="property_values" type="Dictionary" />
314336
<param index="2" name="next_pointer" type="void*" />
315337
<description>
316-
Adds additional data structures to composition layers created by [OpenXRCompositionLayer].
338+
Add additional data structures to composition layers created by [OpenXRCompositionLayer].
317339
[param property_values] contains the values of the properties returned by [method _get_viewport_composition_layer_extension_properties].
318340
[param layer] is a pointer to an [code]XrCompositionLayerBaseHeader[/code] struct.
319341
[b]Note:[/b] This virtual method will be called on the render thread. Additionally, the data it returns will be used shortly after this method is called, so it needs to remain valid until the next time [method _on_pre_render] runs.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="OpenXRFrameSynthesisExtension" inherits="OpenXRExtensionWrapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
3+
<brief_description>
4+
The OpenXR Frame synthesis extension allows for advanced reprojection at low(er) framerates.
5+
</brief_description>
6+
<description>
7+
This class implements the [url=https://registry.khronos.org/OpenXR/specs/1.1/html/xrspec.html#XR_EXT_frame_synthesis]OpenXR Frame synthesis extension[/url]. When enabled in the project settings and supported by the XR runtime in use, frame synthesis uses advanced reprojection techniques to inject additional frames so that your XR experience hits the full frame rate of the device.
8+
</description>
9+
<tutorials>
10+
</tutorials>
11+
<methods>
12+
<method name="is_available" qualifiers="const">
13+
<return type="bool" />
14+
<description>
15+
Returns [code]true[/code] if frame synthesis is enabled in the project settings and the current XR runtime supports frame synthesis. The value returned will only be valid once OpenXR has been initialized.
16+
</description>
17+
</method>
18+
<method name="skip_next_frame">
19+
<return type="void" />
20+
<description>
21+
Queues the next frame to be skipped when supplying motion vector and depth data. Call this after teleporting your player or a similar action has moved the player to prevent incorrect reprojection results due to this movement.
22+
</description>
23+
</method>
24+
</methods>
25+
<members>
26+
<member name="enabled" type="bool" setter="set_enabled" getter="is_enabled" default="false">
27+
Enable frame synthesis. When [code]true[/code] motion vector and depth data is provided to the XR runtime.
28+
</member>
29+
<member name="relax_frame_interval" type="bool" setter="set_relax_frame_interval" getter="get_relax_frame_interval" default="false">
30+
If [code]true[/code] this informs the XR runtime we will be providing frames at a greatly reduced rate. Enable this when you expect your application to run at low framerates and wish to inject multiple reprojected frames.
31+
</member>
32+
</members>
33+
</class>

modules/openxr/extensions/openxr_extension_wrapper.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ void OpenXRExtensionWrapper::_bind_methods() {
4545
GDVIRTUAL_BIND(_set_frame_end_info_and_get_next_pointer, "next_pointer");
4646
GDVIRTUAL_BIND(_set_view_locate_info_and_get_next_pointer, "next_pointer");
4747
GDVIRTUAL_BIND(_set_reference_space_create_info_and_get_next_pointer, "reference_space_type", "next_pointer");
48+
GDVIRTUAL_BIND(_prepare_view_configuration, "view_count");
49+
GDVIRTUAL_BIND(_set_view_configuration_and_get_next_pointer, "view", "next_pointer");
50+
GDVIRTUAL_BIND(_print_view_configuration_info, "view");
4851
GDVIRTUAL_BIND(_get_composition_layer_count);
4952
GDVIRTUAL_BIND(_get_composition_layer, "index");
5053
GDVIRTUAL_BIND(_get_composition_layer_order, "index");
@@ -185,6 +188,24 @@ void *OpenXRExtensionWrapper::set_frame_end_info_and_get_next_pointer(void *p_ne
185188
return nullptr;
186189
}
187190

191+
void OpenXRExtensionWrapper::prepare_view_configuration(uint32_t p_view_count) {
192+
GDVIRTUAL_CALL(_prepare_view_configuration, p_view_count);
193+
}
194+
195+
void *OpenXRExtensionWrapper::set_view_configuration_and_get_next_pointer(uint32_t p_view, void *p_next_pointer) {
196+
uint64_t pointer = 0;
197+
198+
if (GDVIRTUAL_CALL(_set_view_configuration_and_get_next_pointer, p_view, GDExtensionPtr<void>(p_next_pointer), pointer)) {
199+
return reinterpret_cast<void *>(pointer);
200+
}
201+
202+
return nullptr;
203+
}
204+
205+
void OpenXRExtensionWrapper::print_view_configuration_info(uint32_t p_view) const {
206+
GDVIRTUAL_CALL(_print_view_configuration_info, p_view);
207+
}
208+
188209
void *OpenXRExtensionWrapper::set_view_locate_info_and_get_next_pointer(void *p_next_pointer) {
189210
uint64_t pointer = 0;
190211

modules/openxr/extensions/openxr_extension_wrapper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class OpenXRExtensionWrapper : public Object {
8585
virtual void *set_view_locate_info_and_get_next_pointer(void *p_next_pointer); // Add additional data structures when calling xrLocateViews
8686
virtual void *set_frame_end_info_and_get_next_pointer(void *p_next_pointer); // Add additional data structures when calling xrEndFrame
8787

88+
virtual void prepare_view_configuration(uint32_t p_view_count);
89+
virtual void *set_view_configuration_and_get_next_pointer(uint32_t p_view, void *p_next_pointer); // Add additional data structures when calling xrEnumerateViewConfiguration
90+
virtual void print_view_configuration_info(uint32_t p_view) const;
91+
8892
//TODO workaround as GDExtensionPtr<void> return type results in build error in godot-cpp
8993
GDVIRTUAL1R(uint64_t, _set_system_properties_and_get_next_pointer, GDExtensionPtr<void>);
9094
GDVIRTUAL1R(uint64_t, _set_instance_create_info_and_get_next_pointer, GDExtensionPtr<void>);
@@ -99,6 +103,9 @@ class OpenXRExtensionWrapper : public Object {
99103
GDVIRTUAL0R(int, _get_composition_layer_count);
100104
GDVIRTUAL1R(uint64_t, _get_composition_layer, int);
101105
GDVIRTUAL1R(int, _get_composition_layer_order, int);
106+
GDVIRTUAL1(_prepare_view_configuration, int);
107+
GDVIRTUAL2R(uint64_t, _set_view_configuration_and_get_next_pointer, uint32_t, GDExtensionPtr<void>);
108+
GDVIRTUAL1C(_print_view_configuration_info, int);
102109

103110
virtual PackedStringArray get_suggested_tracker_names();
104111

0 commit comments

Comments
 (0)