2019-10-29 08:46:58 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-04-18 16:36:09 +00:00
|
|
|
# Copyright 2019-2022, Collabora, Ltd.
|
2019-08-19 17:37:50 +00:00
|
|
|
# SPDX-License-Identifier: BSL-1.0
|
|
|
|
"""Simple script to update oxr_extension_support.h."""
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
2022-10-19 22:54:31 +00:00
|
|
|
def _add_defined(s):
|
|
|
|
if "defined" in s:
|
|
|
|
return s
|
|
|
|
return "defined({})".format(s)
|
|
|
|
|
|
|
|
def or_(*args):
|
|
|
|
"""
|
|
|
|
Create an "OR" in the definition condition list.
|
|
|
|
|
|
|
|
Takes any number of strings directly or through e.g. "not_".
|
|
|
|
"""
|
|
|
|
return "({})".format(" || ".join(_add_defined(s) for s in args))
|
|
|
|
|
|
|
|
|
|
|
|
def not_(s):
|
|
|
|
"""
|
|
|
|
Create a "NOT" in the condition list.
|
|
|
|
|
|
|
|
Takes a single string, directly or through e.g. "or_".
|
|
|
|
"""
|
|
|
|
return "(!{})".format(_add_defined(s))
|
|
|
|
|
2019-08-19 17:37:50 +00:00
|
|
|
# Each extension that we implement gets an entry in this tuple.
|
|
|
|
# Each entry should be a list of defines that are checked for an extension:
|
|
|
|
# the first one must be the name of the extension itself.
|
2020-07-16 17:59:46 +00:00
|
|
|
# The second and later items might be modified using or_() and not_().
|
2022-01-04 18:58:35 +00:00
|
|
|
# Keep sorted, KHR, EXT, Vendor, experimental (same order).
|
2019-08-19 17:37:50 +00:00
|
|
|
EXTENSIONS = (
|
2020-08-18 20:33:21 +00:00
|
|
|
['XR_KHR_android_create_instance', 'XR_USE_PLATFORM_ANDROID'],
|
2023-09-12 06:39:09 +00:00
|
|
|
['XR_KHR_android_thread_settings', 'XR_USE_PLATFORM_ANDROID'],
|
2022-01-04 21:57:07 +00:00
|
|
|
['XR_KHR_binding_modification'],
|
2023-12-14 09:15:48 +00:00
|
|
|
['XR_KHR_composition_layer_color_scale_bias', 'XRT_FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS'],
|
2022-01-04 18:58:35 +00:00
|
|
|
['XR_KHR_composition_layer_cube', 'XRT_FEATURE_OPENXR_LAYER_CUBE'],
|
|
|
|
['XR_KHR_composition_layer_cylinder', 'XRT_FEATURE_OPENXR_LAYER_CYLINDER'],
|
|
|
|
['XR_KHR_composition_layer_depth', 'XRT_FEATURE_OPENXR_LAYER_DEPTH'],
|
|
|
|
['XR_KHR_composition_layer_equirect', 'XRT_FEATURE_OPENXR_LAYER_EQUIRECT1'],
|
|
|
|
['XR_KHR_composition_layer_equirect2', 'XRT_FEATURE_OPENXR_LAYER_EQUIRECT2'],
|
2022-10-19 21:21:16 +00:00
|
|
|
['XR_KHR_convert_timespec_time', 'XR_USE_TIMESPEC', not_('XR_USE_PLATFORM_WIN32')],
|
2021-10-21 18:48:40 +00:00
|
|
|
['XR_KHR_D3D11_enable', 'XR_USE_GRAPHICS_API_D3D11'],
|
2022-05-24 22:05:41 +00:00
|
|
|
['XR_KHR_D3D12_enable', 'XR_USE_GRAPHICS_API_D3D12'],
|
2022-01-04 18:58:35 +00:00
|
|
|
['XR_KHR_loader_init', 'XR_USE_PLATFORM_ANDROID'],
|
2022-04-18 16:36:09 +00:00
|
|
|
['XR_KHR_loader_init_android', 'OXR_HAVE_KHR_loader_init', 'XR_USE_PLATFORM_ANDROID'],
|
2019-08-19 17:37:50 +00:00
|
|
|
['XR_KHR_opengl_enable', 'XR_USE_GRAPHICS_API_OPENGL'],
|
2019-10-29 10:08:11 +00:00
|
|
|
['XR_KHR_opengl_es_enable', 'XR_USE_GRAPHICS_API_OPENGL_ES'],
|
2022-01-04 18:58:35 +00:00
|
|
|
['XR_KHR_swapchain_usage_input_attachment_bit'],
|
2023-11-13 21:35:16 +00:00
|
|
|
['XR_KHR_visibility_mask', 'XRT_FEATURE_OPENXR_VISIBILITY_MASK'],
|
2019-08-19 17:37:50 +00:00
|
|
|
['XR_KHR_vulkan_enable', 'XR_USE_GRAPHICS_API_VULKAN'],
|
2020-12-26 23:56:14 +00:00
|
|
|
['XR_KHR_vulkan_enable2', 'XR_USE_GRAPHICS_API_VULKAN'],
|
2023-11-18 02:40:11 +00:00
|
|
|
['XR_KHR_vulkan_swapchain_format_list', 'XR_USE_GRAPHICS_API_VULKAN', 'XRT_FEATURE_OPENXR_VULKAN_SWAPCHAIN_FORMAT_LIST'],
|
2022-04-27 03:06:59 +00:00
|
|
|
['XR_KHR_win32_convert_performance_counter_time', 'XR_USE_PLATFORM_WIN32'],
|
2022-05-19 12:39:39 +00:00
|
|
|
['XR_EXT_debug_utils', 'XRT_FEATURE_OPENXR_DEBUG_UTILS'],
|
2022-01-04 18:44:32 +00:00
|
|
|
['XR_EXT_dpad_binding'],
|
2023-11-13 21:00:28 +00:00
|
|
|
['XR_EXT_eye_gaze_interaction', 'XRT_FEATURE_OPENXR_INTERACTION_EXT_EYE_GAZE'],
|
|
|
|
['XR_EXT_hand_interaction', 'XRT_FEATURE_OPENXR_INTERACTION_EXT_HAND'],
|
2022-01-04 18:58:35 +00:00
|
|
|
['XR_EXT_hand_tracking'],
|
2023-11-13 21:00:28 +00:00
|
|
|
['XR_EXT_hp_mixed_reality_controller', 'XRT_FEATURE_OPENXR_INTERACTION_WINMR'],
|
2023-11-06 18:04:31 +00:00
|
|
|
['XR_EXT_local_floor', 'XRT_FEATURE_OPENXR_SPACE_LOCAL_FLOOR'],
|
2023-11-13 21:00:28 +00:00
|
|
|
['XR_EXT_palm_pose', 'XRT_FEATURE_OPENXR_INTERACTION_EXT_PALM_POSE'],
|
|
|
|
['XR_EXT_samsung_odyssey_controller', 'XRT_FEATURE_OPENXR_INTERACTION_WINMR'],
|
2023-11-13 21:35:16 +00:00
|
|
|
['XR_FB_display_refresh_rate', 'XRT_FEATURE_OPENXR_DISPLAY_REFRESH_RATE'],
|
2023-11-13 21:00:28 +00:00
|
|
|
['XR_ML_ml2_controller_interaction', 'XRT_FEATURE_OPENXR_INTERACTION_ML2'],
|
2023-11-13 21:35:16 +00:00
|
|
|
['XR_MND_headless', 'XRT_FEATURE_OPENXR_HEADLESS'],
|
2020-07-23 14:30:41 +00:00
|
|
|
['XR_MND_swapchain_usage_input_attachment_bit'],
|
2023-11-13 21:00:28 +00:00
|
|
|
['XR_MSFT_hand_interaction', 'XRT_FEATURE_OPENXR_INTERACTION_MSFT_HAND'],
|
2023-11-06 23:51:14 +00:00
|
|
|
['XR_MSFT_unbounded_reference_space', 'XRT_FEATURE_OPENXR_SPACE_UNBOUNDED'],
|
2023-11-13 21:00:28 +00:00
|
|
|
['XR_OPPO_controller_interaction', 'XRT_FEATURE_OPENXR_INTERACTION_OPPO'],
|
2023-11-13 21:35:16 +00:00
|
|
|
['XR_EXTX_overlay', 'XRT_FEATURE_OPENXR_OVERLAY'],
|
2023-06-28 23:04:58 +00:00
|
|
|
['XR_HTCX_vive_tracker_interaction', 'ALWAYS_DISABLED'],
|
2023-11-13 21:00:28 +00:00
|
|
|
['XR_MNDX_ball_on_a_stick_controller', 'XRT_FEATURE_OPENXR_INTERACTION_MNDX'],
|
2022-01-04 18:58:35 +00:00
|
|
|
['XR_MNDX_egl_enable', 'XR_USE_PLATFORM_EGL', 'XR_USE_GRAPHICS_API_OPENGL'],
|
2023-11-13 21:35:16 +00:00
|
|
|
['XR_MNDX_force_feedback_curl', 'XRT_FEATURE_OPENXR_FORCE_FEEDBACK_CURL'],
|
2023-11-13 21:00:28 +00:00
|
|
|
['XR_MNDX_hydra', 'XRT_FEATURE_OPENXR_INTERACTION_MNDX'],
|
|
|
|
['XR_MNDX_system_buttons', 'XRT_FEATURE_OPENXR_INTERACTION_MNDX'],
|
2019-08-19 17:37:50 +00:00
|
|
|
)
|
|
|
|
|
2020-07-16 17:59:46 +00:00
|
|
|
|
2019-08-19 17:37:50 +00:00
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
|
|
FN = ROOT / 'src' / 'xrt'/'state_trackers' / 'oxr' / 'oxr_extension_support.h'
|
|
|
|
|
|
|
|
INVOCATION_PREFIX = 'OXR_EXTENSION_SUPPORT'
|
2019-12-03 17:53:31 +00:00
|
|
|
BEGIN_OF_PER_EXTENSION = '// beginning of GENERATED defines - do not modify - used by scripts'
|
|
|
|
END_OF_PER_EXTENSION = '// end of GENERATED per-extension defines - do not modify - used by scripts'
|
2019-08-19 17:37:50 +00:00
|
|
|
CLANG_FORMAT_OFF = '// clang-format off'
|
|
|
|
CLANG_FORMAT_ON = '// clang-format on'
|
|
|
|
|
|
|
|
|
|
|
|
def trim_ext_name(name):
|
|
|
|
return name[3:]
|
|
|
|
|
|
|
|
|
|
|
|
def generate_first_chunk():
|
|
|
|
parts = []
|
|
|
|
for data in EXTENSIONS:
|
|
|
|
ext_name = data[0]
|
|
|
|
trimmed_name = trim_ext_name(ext_name)
|
|
|
|
upper_name = trimmed_name.upper()
|
2020-07-16 17:59:46 +00:00
|
|
|
condition = " && ".join(_add_defined(x) for x in data)
|
2019-08-19 17:37:50 +00:00
|
|
|
|
|
|
|
parts.append(f"""
|
|
|
|
/*
|
2021-10-21 20:29:41 +00:00
|
|
|
* {ext_name}
|
|
|
|
*/
|
2019-08-19 17:37:50 +00:00
|
|
|
#if {condition}
|
|
|
|
#define OXR_HAVE_{trimmed_name}
|
|
|
|
#define {INVOCATION_PREFIX}_{trimmed_name}(_) \\
|
|
|
|
_({trimmed_name}, {upper_name})
|
|
|
|
#else
|
|
|
|
#define {INVOCATION_PREFIX}_{trimmed_name}(_)
|
|
|
|
#endif
|
|
|
|
""")
|
|
|
|
return '\n'.join(parts)
|
|
|
|
|
|
|
|
|
|
|
|
def generate_second_chunk():
|
|
|
|
trimmed_names = [trim_ext_name(data[0]) for data in EXTENSIONS]
|
|
|
|
invocations = ('{}_{}(_)'.format(INVOCATION_PREFIX, name)
|
|
|
|
for name in trimmed_names)
|
|
|
|
|
|
|
|
macro_lines = ['#define OXR_EXTENSION_SUPPORT_GENERATE(_)']
|
|
|
|
macro_lines.extend(invocations)
|
|
|
|
|
|
|
|
lines = [CLANG_FORMAT_OFF]
|
|
|
|
lines.append(' \\\n '.join(macro_lines))
|
|
|
|
lines.append(CLANG_FORMAT_ON)
|
|
|
|
return '\n'.join(lines)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
with open(str(FN), 'r', encoding='utf-8') as fp:
|
|
|
|
orig = [line.rstrip() for line in fp.readlines()]
|
2019-12-03 17:53:31 +00:00
|
|
|
beginning = orig[:orig.index(BEGIN_OF_PER_EXTENSION)+1]
|
2019-08-19 17:37:50 +00:00
|
|
|
middle_start = orig.index(END_OF_PER_EXTENSION)
|
|
|
|
middle_end = orig.index(CLANG_FORMAT_OFF)
|
|
|
|
middle = orig[middle_start:middle_end]
|
|
|
|
|
|
|
|
new_contents = beginning
|
|
|
|
new_contents.append(generate_first_chunk())
|
|
|
|
new_contents.extend(middle)
|
|
|
|
new_contents.append(generate_second_chunk())
|
|
|
|
|
|
|
|
with open(str(FN), 'w', encoding='utf-8') as fp:
|
|
|
|
fp.write('\n'.join(new_contents))
|
|
|
|
fp.write('\n')
|