Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Overlay as a service prototype w/in overlay sample app. #25

Open
wants to merge 5 commits into
base: zulauf_update_to_1.0.19
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Use defaults from the Google style with the following exceptions:
BasedOnStyle: Google
IndentWidth: 4
AccessModifierOffset: -2
ColumnLimit: 132
SortIncludes: false
...
1 change: 1 addition & 0 deletions api-layer/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ def dump(file, indent, depth, element):
"xrSuggestInteractionProfileBindings",
"xrAttachSessionActionSets",
"xrGetCurrentInteractionProfile",
"xrEnumerateEnvironmentBlendModes",
]

supported_commands = [
Expand Down
189 changes: 176 additions & 13 deletions api-layer/generate_placeholder_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
#
import sys

list_join_str = ",\n "

well_known_strings = set()

path_spec_list = []
# As of 1.0.11, these are the paths for input allowlist, from semantic_paths.adoc
path_specs = """
simple_controller_paths = """
Path: pathname:/interaction_profiles/khr/simple_controller
* pathname:/user/hand/left
* pathname:/user/hand/right
Expand All @@ -32,6 +35,10 @@
* subpathname:/input/grip/pose
* subpathname:/input/aim/pose
* subpathname:/output/haptic
"""
path_spec_list.append(simple_controller_paths)

daydream_paths = """
Path: pathname:/interaction_profiles/google/daydream_controller
* pathname:/user/hand/left
* pathname:/user/hand/right
Expand All @@ -42,6 +49,10 @@
* subpathname:/input/trackpad/touch
* subpathname:/input/grip/pose
* subpathname:/input/aim/pose
"""
path_spec_list.append(daydream_paths)

vive_paths = """
Path: pathname:/interaction_profiles/htc/vive_controller
* pathname:/user/hand/left
* pathname:/user/hand/right
Expand All @@ -63,7 +74,19 @@
* subpathname:/input/volume_up/click
* subpathname:/input/volume_down/click
* subpathname:/input/mute_mic/click
"""
path_spec_list.append(vive_paths)

microsoft_top_path = """
Path: pathname:/interaction_profiles/microsoft/motion_controller
"""

samsung_top_path = """
Path: pathname:/interaction_profiles/samsung/odyssey_controller
EXTENSION:XR_EXT_SAMSUNG_ODYSSEY_CONTROLLER_EXTENSION_NAME
"""

microsoft_samsung_common_paths = """
* pathname:/user/hand/left
* pathname:/user/hand/right
* subpathname:/input/menu/click
Expand All @@ -79,6 +102,11 @@
* subpathname:/input/grip/pose
* subpathname:/input/aim/pose
* subpathname:/output/haptic
"""

path_spec_list.extend([microsoft_top_path, microsoft_samsung_common_paths, samsung_top_path, microsoft_samsung_common_paths]);

xbox_paths = """
Path: pathname:/interaction_profiles/microsoft/xbox_controller
* pathname:/user/gamepad
* subpathname:/input/menu/click
Expand All @@ -105,6 +133,10 @@
* subpathname:/output/haptic_right
* subpathname:/output/haptic_left_trigger
* subpathname:/output/haptic_right_trigger
"""
path_spec_list.append(xbox_paths)

occulus_paths = """
Path: pathname:/interaction_profiles/oculus/go_controller
* pathname:/user/hand/left
* pathname:/user/hand/right
Expand Down Expand Up @@ -143,6 +175,10 @@
* subpathname:/input/grip/pose
* subpathname:/input/aim/pose
* subpathname:/output/haptic
"""
path_spec_list.append(occulus_paths)

valve_paths = """
Path: pathname:/interaction_profiles/valve/index_controller
* pathname:/user/hand/left
* pathname:/user/hand/right
Expand All @@ -169,12 +205,14 @@
* subpathname:/input/aim/pose
* subpathname:/output/haptic
"""
path_spec_list.append(valve_paths)

# From XR_EXT_hp_mixed_reality_controller (which the MSFT "Demo Scene"
# provides profile bindings for and is chosen for the Samsung Odyssey
# controllers, edited to match what this script expects
path_specs = path_specs + """
hp_mrc_paths = """
Path: pathname:/interaction_profiles/hp/mixed_reality_controller
EXTENSION:XR_EXT_HP_MIXED_REALITY_CONTROLLER_EXTENSION_NAME
* pathname:/user/hand/left
* pathname:/user/hand/right
* On pathname:/user/hand/left only
Expand All @@ -194,15 +232,72 @@
* subpathname:/input/aim/pose
* subpathname:/output/haptic
"""
path_spec_list.append(hp_mrc_paths)

eye_gaze_paths = """
Path: pathname:/interaction_profiles/ext/eye_gaze_interaction
EXTENSION:XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME
* pathname:/user/eyes_ext
* subpathname:/input/gaze_ext/pose
"""
path_spec_list.append(eye_gaze_paths)

vive_cosmos_paths = """
Path: pathname:/interaction_profiles/htc/vive_cosmos_controller
EXTENSION:XR_HTC_VIVE_COSMOS_CONTROLLER_INTERACTION_EXTENSION_NAME
* pathname:/user/hand/left
* pathname:/user/hand/right
* On pathname:/user/hand/left only:
** subpathname:/input/x/click
** subpathname:/input/y/click
** subpathname:/input/menu/click
* On pathname:/user/hand/right only:
** subpathname:/input/a/click
** subpathname:/input/b/click
** subpathname:/input/system/click
use)
* subpathname:/input/shoulder/click
* subpathname:/input/squeeze/click
* subpathname:/input/trigger/click
* subpathname:/input/trigger/value
* subpathname:/input/thumbstick/x
* subpathname:/input/thumbstick/y
* subpathname:/input/thumbstick/click
* subpathname:/input/thumbstick/touch
* subpathname:/input/grip/pose
* subpathname:/input/aim/pose
* subpathname:/output/haptic
"""
path_spec_list.append(vive_cosmos_paths)

# Microsoft Hand Controller -- Hand interaction profile
msft_hand_controller = """
Path: pathname:/interaction_profiles/microsoft/hand_interaction
EXTENSION:XR_MSFT_HAND_INTERACTION_EXTENSION_NAME
* pathname:/user/hand/left
* pathname:/user/hand/right
* subpathname:/input/select/value
* subpathname:/input/squeeze/value
* subpathname:/input/aim/pose
* subpathname/input/grip/pose
"""
path_spec_list.append(msft_hand_controller)

placeholder_profiles = {}
for l in path_specs.splitlines():
profile_extension = {}
extensions = set()
for l in "\n".join(path_spec_list).splitlines():
if l.startswith("Path: pathname:"):
profile = l.split(":")[2]
# print("profile %s" % profile)
well_known_strings.add(profile)
placeholder_profiles[profile] = {}
pathnames = []
profile_extension[profile] = []
elif l.startswith("EXTENSION:"):
extension_name = l.split(":")[1]
profile_extension[profile].append(extension_name)
extensions.add(extension_name)
elif l.startswith("* pathname:"):
top_level = l.split(":")[1]
# print(" top level path %s" % top_level)
Expand Down Expand Up @@ -239,22 +334,63 @@
# don't add upper component for vector2f here
# that's added below, once, for just .x


def to_upper_snake(str) :
return "_".join([s.upper() for s in str[1:].split("/")])

# Construct the well known string enum and map
num = 1
well_known_enums = ""
well_known_mappings = ""
for str in well_known_strings:
well_known_enums += " " + to_upper_snake(str) + " = %d,\n" % num
well_known_mappings += " {" + to_upper_snake(str) + ', "' + str + '"},\n'
well_known_dict = {} # The extension enum will find this useful
for str in sorted(well_known_strings):
enum_name = to_upper_snake(str)
well_known_dict[str] = enum_name
well_known_enums += " " + enum_name + " = %d,\n" % num
well_known_mappings += " {" + enum_name + ', "' + str + '"},\n'
num += 1

# Construct the extension mask enum and map
ext_none_bit = "REQ_EXTENSION_NONE_MASK"
ext_masks = list()
ext_masks.append(f"{ext_none_bit} = 0")
ext_bit = 0;
ext_bits = {}
ext_bit_list = []
for ext in sorted(extensions):
bit_name = "REQ_" + ext[3:-15] + "_BIT"
ext_bits[ext] = bit_name
ext_masks.append(f"{bit_name} = (1 << {ext_bit})")
ext_bit_list.append(f'{{{ext}, {bit_name}}}') # No quotes because the ext is the name of a #define string literal
ext_bit += 1

def profile_extension_mask(profile):
return "REQ_" + well_known_dict[profile] + "_MASK"

for profile in sorted(profile_extension.keys()):
ext_list = profile_extension[profile]
enum_name = profile_extension_mask(profile)
if (ext_list):
ext_mask = " | ".join([ext_bits[e] for e in ext_list])
if len(ext_list) > 1 :
ext_mask = "(" + ext_mask + ")"
else:
ext_mask = ext_none_bit
ext_masks.append(f"{enum_name} = {ext_mask}")



# Construct the placeholder entries
placeholder_ids = ""

for (profile, top_levels) in placeholder_profiles.items():
for (top_level, components) in top_levels.items():
for component in components:
extension_map_list = []
for profile in sorted(placeholder_profiles.keys()):
top_levels = placeholder_profiles[profile]
ext_list = ", ".join(profile_extension[profile])
extension_map_list.append(f"{{{well_known_dict[profile]}, {profile_extension_mask(profile)}}}")
for top_level in sorted(top_levels.keys()):
components = top_levels[top_level]
for component in sorted(components):
if component.endswith("value") or component.endswith("x") or component.endswith("y") or component.endswith("force") or component.endswith("touch"):
type = "XR_ACTION_TYPE_FLOAT_INPUT"
elif component.endswith("click"):
Expand All @@ -271,20 +407,43 @@ def to_upper_snake(str) :
placeholder_ids += ' {"' + profile + top_level + component[:-2] + '", XR_ACTION_TYPE_VECTOR2F_INPUT, ' + to_upper_snake(profile) + ", " + to_upper_snake(top_level) + ", " + to_upper_snake(component[:-2]) + ", " + to_upper_snake(top_level + component[:-2]) + "},\n"


well_known = f"""
well_known_decl = f"""
// All applications within an overlay session must use the same version of the overlay layer to ensure compatibility, or the some
// RPC to share the main overlay's enum -> string map must be added.
enum WellKnownStringIndex {{
NULL_PATH = 0,
{well_known_enums}
}}; // Existing entries will need to not change for subsequent versions for backward compatibility after the first public release
}};

"""

ext_req_type = "ProfileExtensionReqMask"
ext_enum_decl = f"""
enum {ext_req_type} {{
{list_join_str.join(ext_masks)}
}};

"""

well_known_def = f"""
std::unordered_map<WellKnownStringIndex, const char *> OverlaysLayerWellKnownStrings = {{
{well_known_mappings}
}};

"""

placeholders = f"""
extension_map_def = f"""
std::unordered_map<std::string, {ext_req_type}> ExtensionsBits = {{
{list_join_str.join(ext_bit_list)}
}};

std::unordered_map<WellKnownStringIndex, {ext_req_type}> ProfileExtensions = {{
{list_join_str.join(extension_map_list)}
}};

"""

placeholders = f"""
struct PlaceholderActionId
{{
std::string name;
Expand All @@ -299,8 +458,12 @@ def to_upper_snake(str) :
{{
{placeholder_ids}
}};

"""

print(well_known,)
print(well_known_decl)
print(ext_enum_decl)
print(extension_map_def)
print(well_known_def)
print(placeholders)

Loading