上传YomovSDK

This commit is contained in:
Sora丶kong
2026-03-03 03:15:46 +08:00
parent 9096da7e6c
commit eb97f31065
6477 changed files with 1932208 additions and 3 deletions

View File

@@ -0,0 +1,2 @@
DisableFormat: true
SortIncludes: false

View File

@@ -0,0 +1,485 @@
diff --git a/specification/scripts/creflectiongenerator.py b/specification/scripts/creflectiongenerator.py
index a1beca84a..fa08160ee 100644
--- a/specification/scripts/creflectiongenerator.py
+++ b/specification/scripts/creflectiongenerator.py
@@ -35,11 +35,13 @@ class CommandData:
class StructData:
"""Represents a OpenXR struct type"""
- def __init__(self, typeName, structTypeName, members, protect):
+ def __init__(self, typeName, structTypeName, members, arrays, protect, parent):
self.typeName = typeName
self.members = members
+ self.arrays = arrays
self.structTypeName = structTypeName
self.protect = protect
+ self.parent = parent
@property
def protect_value(self) -> bool:
@@ -64,12 +66,42 @@ class BitmaskData:
class EnumData:
"""Represents a OpenXR group enum type"""
- def __init__(self, typeName, typeNamePrefix, typeNameSuffix, enumTuples):
+ def __init__(self, typeName, typeNamePrefix, typeNameSuffix, enumTuples, protect):
self.typeName = typeName
self.typeNamePrefix = typeNamePrefix
self.typeNameSuffix = typeNameSuffix
self.enumTuples = enumTuples
+ self.protect = protect
+
+ @property
+ def protect_value(self):
+ return self.protect is not None
+
+ @property
+ def protect_string(self):
+ if self.protect:
+ return " && ".join("defined({})".format(x) for x in self.protect)
+
+class CCmd:
+ """Represents an OpenXR function"""
+
+ def __init__(self, cmdName, returnType, members, members_non_array, arrays, sig, protect):
+ self.cmdName = cmdName
+ self.returnType = returnType
+ self.members = members
+ self.members_non_array = members_non_array
+ self.arrays = arrays
+ self.sig = sig
+ self.protect = protect
+
+ @property
+ def protect_value(self):
+ return self.protect is not None
+ @property
+ def protect_string(self):
+ if self.protect:
+ return " && ".join("defined({})".format(x) for x in self.protect)
class CReflectionOutputGenerator(OutputGenerator):
"""Generate specified API interfaces in a specific style, such as a C header"""
@@ -81,6 +113,8 @@ class CReflectionOutputGenerator(OutputGenerator):
self.commands = []
self.enums = []
self.bitmasks = []
+ self.cmds = []
+ self.handles = []
self.protects = set()
self.template: Optional[JinjaTemplate] = None
self.parents = {}
@@ -97,14 +131,42 @@ class CReflectionOutputGenerator(OutputGenerator):
if x.protect == protect and x.structTypeName is not None]
return ret
+ def getCmdsForProtect(self, protect=None):
+ return [x for x in self.cmds
+ if x.protect == protect]
+
+ def getEnumsForProtect(self, protect=None):
+ return [x for x in self.enums
+ if x.protect == protect]
+
+ def getCmdsForProtect(self, protect=None):
+ return [x for x in self.cmds
+ if x.protect == protect]
+
+ def getEnumsForProtect(self, protect=None):
+ return [x for x in self.enums
+ if x.protect == protect]
+
def endFile(self):
assert self.template
assert self.registry
file_data = ''
+ # UNITY: specialization filter
+ self.cmds = [x for x in self.cmds if x.cmdName not in ('xrGetInstanceProcAddr')]
+ self.structs = [x for x in self.structs if x.typeName not in ('XrBaseInStructure', 'XrBaseOutStructure', 'XrEventDataBuffer', 'XrDebugUtilsMessengerCreateInfoEXT', 'XrSpatialGraphNodeSpaceCreateInfoMSFT', 'XrInteractionProfileAnalogThresholdVALVE', 'XrWorldMeshBufferML')]
+
unprotected_structs = self._get_structs_for_protect()
protected_structs = [(x, self._get_structs_for_protect(protect=x))
for x in sorted(self.protects)]
+ base_structs = list(set([x.parent for x in self.structs if x.parent is not None]))
+ basic_structs = [x for x in self.structs if x.structTypeName is None and x.typeName not in base_structs]
+
+ unprotected_cmds = self.getCmdsForProtect()
+ protected_cmds = [(x, self.getCmdsForProtect(x)) for x in sorted(self.protects)]
+
+ unprotected_enums = self.getEnumsForProtect()
+ protected_enums = [(x, self.getEnumsForProtect(x)) for x in sorted(self.protects)]
# drop empty collections
protected_structs = [(x, y) for x, y in protected_structs if y]
@@ -138,7 +200,15 @@ class CReflectionOutputGenerator(OutputGenerator):
unprotectedStructs=unprotected_structs,
protectedStructs=protected_structs,
structs=self.structs,
+ basic_structs=basic_structs,
+ base_structs=base_structs,
+ unprotectedCmds=unprotected_cmds,
+ protectedCmds=protected_cmds,
+ cmds=self.cmds,
+ unprotectedEnums=unprotected_enums,
+ protectedEnums=protected_enums,
enums=self.enums,
+ handles=self.handles,
bitmasks=self.bitmasks,
extensions=extensions,
polymorphic_struct_families=polymorphic_struct_families,
@@ -159,6 +229,8 @@ class CReflectionOutputGenerator(OutputGenerator):
# If the type is a struct type, generate it using the
# special-purpose generator.
self.genStruct(typeinfo, name, alias)
+ if category == 'handle':
+ self.handles.append(name)
parent_struct = typeElem.get('parentstruct')
if parent_struct is not None:
@@ -174,12 +246,75 @@ class CReflectionOutputGenerator(OutputGenerator):
self.commands.append(CommandData(name, self.featureName))
+ def genCmd(self, cmd, cmdinfo, alias):
+ OutputGenerator.genCmd(self, cmd, cmdinfo, alias)
+
+ if alias:
+ return
+
+ #print(f'{dump(cmd.elem)}')
+
+ ret = cmd.elem.find('proto').find('type').text
+ #print(ret)
+
+ members = []
+ members_non_array = []
+ sig = ''
+
+
+ arrays = {}
+ for m in cmd.elem.findall('./param[@len]'):
+ lenName = m.get('len')
+ if lenName != 'null-terminated':
+ if m.find('type').text == 'char' and 'null-terminated' not in lenName:
+ continue
+ lenName = lenName.replace(',null-terminated','')
+ print(f"{m.find('name').text} len={lenName}")
+ arrays[m.find('name').text] = lenName
+
+ for m in cmd.elem.iterfind('param'):
+ sig += ', ' + self.makeCParamDecl(m, 0)
+ member = m.find('name').text
+ members.append(m.find('name').text)
+ if member not in arrays:
+ members_non_array.append(m.find('name').text)
+
+ sig = sig[2:]
+
+ #import pprint
+ #pprint.pprint(members)
+
+ protect = set()
+ if self.featureExtraProtect:
+ protect.update(self.featureExtraProtect.split(','))
+ localProtect = cmd.elem.get('protect')
+ if localProtect:
+ protect.update(localProtect.split(','))
+
+ if protect:
+ protect = tuple(protect)
+ else:
+ protect = None
+
+ self.cmds.append(CCmd(cmd.elem.attrib['name'], ret, members, members_non_array, arrays, sig, protect))
+
+
def genStruct(self, typeinfo, typeName, alias):
OutputGenerator.genStruct(self, typeinfo, typeName, alias)
if alias:
return
+ arrays = {}
+ for m in typeinfo.elem.findall('./member[@len]'):
+ lenName = m.get('len')
+ if lenName != 'null-terminated':
+ if m.find('type').text == 'char' and 'null-terminated' not in lenName:
+ continue
+ lenName = lenName.replace(',null-terminated','')
+ print(f"{m.find('name').text} len={lenName}")
+ arrays[m.find('name').text] = lenName
+
structTypeEnum = None
members = []
for member in typeinfo.getMembers():
@@ -188,7 +323,8 @@ class CReflectionOutputGenerator(OutputGenerator):
if self.conventions.is_structure_type_member(memberType, memberName):
structTypeEnum = member.get("values")
- members.append(memberName)
+ if memberName not in arrays:
+ members.append(memberName)
protect = set()
if self.featureExtraProtect:
@@ -202,7 +338,9 @@ class CReflectionOutputGenerator(OutputGenerator):
else:
protect = None
- self.structs.append(StructData(typeName, structTypeEnum, members, protect))
+ parent = typeinfo.elem.get('parentstruct')
+
+ self.structs.append(StructData(typeName, structTypeEnum, members, arrays, protect, parent))
if protect:
self.protects.add(protect)
@@ -242,4 +380,16 @@ class CReflectionOutputGenerator(OutputGenerator):
continue
enumTuples.append((getElemName(elem), strVal))
- self.enums.append(EnumData(groupName, expandPrefix, expandSuffix, enumTuples))
+ protect = set()
+ if self.featureExtraProtect:
+ protect.update(self.featureExtraProtect.split(','))
+ localProtect = groupinfo.elem.get('protect')
+ if localProtect:
+ protect.update(localProtect.split(','))
+
+ if protect:
+ protect = tuple(protect)
+ else:
+ protect = None
+
+ self.enums.append(EnumData(groupName, expandPrefix, expandSuffix, enumTuples, protect))
diff --git a/specification/scripts/template_openxr_reflection.h b/specification/scripts/template_openxr_reflection.h
index 11ec318d1..9ddbbc8e1 100644
--- a/specification/scripts/template_openxr_reflection.h
+++ b/specification/scripts/template_openxr_reflection.h
@@ -12,7 +12,7 @@
**
*/
-#include "openxr.h"
+// #include "openxr.h"
/*
This file contains expansion macros (X Macros) for OpenXR enumerations and structures.
@@ -30,6 +30,13 @@ Example of how to use expansion macros to make an enum-to-string function:
XR_ENUM_STR(XrResult);
*/
+#define XR_LIST_HANDLES(_) \
+//# for handle in handles
+ _(/*{handle}*/) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
//# for enum in enums
#define XR_LIST_ENUM_/*{enum.typeName}*/(_) \
@@ -40,6 +47,39 @@ XR_ENUM_STR(XrResult);
//# endfor
+//## Used when making structure type macros
+/*% macro makeEnumTypes(typedEnums) -%*/
+//# for enum in typedEnums
+ _(/*{enum.typeName}*/) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+/*% endmacro %*/
+
+#define XR_LIST_ENUM_TYPES_CORE(_) \
+/*{ makeEnumTypes(unprotectedEnums) }*/
+
+
+//# for protect, enumTypes in protectedEnums if enumTypes|length > 0
+
+/*{ protect_begin(enumTypes[0]) }*/
+#define XR_LIST_ENUM_TYPES_/*{protect | join("_")}*/(_) \
+/*{ makeEnumTypes(enumTypes) }*/
+#else
+#define XR_LIST_ENUM_TYPES_/*{protect | join("_")}*/(_)
+#endif
+
+//# endfor
+
+
+#define XR_LIST_ENUM_TYPES(_) \
+ XR_LIST_ENUM_TYPES_CORE(_) \
+//# for protect, enumTypes in protectedEnums if enumTypes|length > 0
+ XR_LIST_ENUM_TYPES_/*{protect | join("_")}*/(_) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
//# for bitmask in bitmasks
#define XR_LIST_BITS_/*{bitmask.typeName}*/(_)/*{" \\" if bitmask.maskTuples}*/
@@ -61,6 +101,16 @@ XR_ENUM_STR(XrResult);
//## Preceding line intentionally left blank to absorb the trailing backslash
//# endfor
+//# for struct in structs
+
+#define XR_LIST_STRUCT_ARRAYS_/*{struct.typeName}*/(_) \
+//# for memberName, lenName in struct.arrays.items()
+ _(/*{memberName}*/, /*{lenName}*/) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+//# endfor
+
//## Used when making structure type macros
/*% macro makeStructTypes(typedStructs, funcName="_") -%*/
//# for struct in typedStructs
@@ -98,6 +148,62 @@ XR_ENUM_STR(XrResult);
//# endfor
+
+#define XR_LIST_BASE_STRUCTS(_) \
+//# for structTypeName in base_structs
+ _(/*{structTypeName}*/) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+//# for structName in base_structs
+
+#define XR_LIST_BASE_STRUCT_TYPES_CORE_/*{structName}*/(_) \
+//# for struct in unprotectedStructs if struct.parent == structName
+ _(/*{struct.typeName}*/, /*{struct.structTypeName}*/) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+//# for protect, structTypes in protectedStructs
+/*{ protect_begin(structTypes[0]) }*/
+#define XR_LIST_BASE_STRUCT_TYPES_/*{structName}*/_/*{protect | join("_")}*/(_) \
+//# for struct in structTypes if struct.parent == structName
+ _(/*{struct.typeName}*/, /*{struct.structTypeName}*/) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+#else
+#define XR_LIST_BASE_STRUCT_TYPES_/*{structName}*/_/*{protect | join("_")}*/(_)
+#endif
+
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+#define XR_LIST_BASE_STRUCT_TYPES_/*{structName}*/(_) \
+ XR_LIST_BASE_STRUCT_TYPES_CORE_/*{structName}*/(_) \
+//# for protect, structTypes in protectedStructs
+ XR_LIST_BASE_STRUCT_TYPES_/*{structName}*/_/*{protect | join("_")}*/(_) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+
+
+#define XR_LIST_BASIC_STRUCTS(_) \
+//# for s in basic_structs
+ _(/*{s.typeName}*/) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+
//## Preceding line intentionally left blank to absorb the trailing backslash
/// Calls your macro with the name and extension number of all known
@@ -126,4 +232,82 @@ XR_ENUM_STR(XrResult);
//## Preceding line intentionally left blank to absorb the trailing backslash
+
+//## Used when making cmd type macros
+/*% macro makeCmdTypes(cmds) -%*/
+//# for cmd in cmds
+ _(/*{cmd.cmdName}*/, /*{cmd.sig}*/) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+/*% endmacro %*/
+
+#define XR_LIST_FUNCS_CORE(_) \
+/*{ makeCmdTypes(unprotectedCmds) }*/
+
+
+//# for protect, cmdTypes in protectedCmds if cmdTypes|length > 0
+
+/*{ protect_begin(cmdTypes[0]) }*/
+#define XR_LIST_FUNCS_/*{protect | join("_")}*/(_) \
+/*{ makeCmdTypes(cmdTypes) }*/
+#else
+#define XR_LIST_FUNCS_/*{protect | join("_")}*/(_)
+#endif
+
+//# endfor
+
+
+#define XR_LIST_FUNCS(_) \
+ XR_LIST_FUNCS_CORE(_) \
+//# for protect, cmdTypes in protectedCmds if cmdTypes|length > 0
+ XR_LIST_FUNCS_/*{protect | join("_")}*/(_) \
+//# endfor
+
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+//# for cmd in cmds
+
+#define XR_LIST_FUNC_/*{cmd.cmdName}*/(_) \
+//# for member in cmd.members_non_array
+ _(/*{member}*/) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+//# endfor
+
+//# for cmd in cmds
+
+#define XR_LIST_FUNC_ARRAYS_/*{cmd.cmdName}*/(_) \
+//# for member, len_member in cmd.arrays.items()
+ _(/*{member}*/, /*{len_member}*/) \
+//# endfor
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+//# endfor
+
+//# for cmd in cmds
+
+#define XR_LIST_FUNC_PARAM_NAMES_/*{cmd.cmdName}*/(_) \
+ _(/*{', '.join(cmd.members)}*/) \
+
+//## Preceding line intentionally left blank to absorb the trailing backslash
+
+//# endfor
+
+//# for cmd in cmds
+#define XR_BEFORE_/*{cmd.cmdName}*/(funcName)
+//#endfor
+
+//## Preceding line intentionally left blank
+
+//# for cmd in cmds
+#define XR_AFTER_/*{cmd.cmdName}*/(funcName)
+//#endfor
+
+//## Preceding line intentionally left blank
+
#endif