Parse constant definitions from Khronos registry and fixes wrong binding of array types #7
Parse constant definitions from Khronos registry and fixes wrong binding of array types #7Ybalrid wants to merge 4 commits intoEvergineTeam:mainfrom
Conversation
…ined as constants. This fixes the issue with types like XrUuid. Fix EvergineTeam#6
There was a problem hiding this comment.
Pull request overview
This PR fixes the incorrect generation of struct members that are fixed-size arrays sized by symbolic constants (specifically #define-based constants in the Khronos registry), which caused XrUuid.data to be generated as a single byte instead of a byte[16]. It also includes updated generated bindings for new OpenXR extensions (Android face tracking, BD facial simulation).
Changes:
- Extends
StructureDefinition.csto recognize symbolic constant names (not just literal integers) in array bracket notation (e.g.,name[SYMBOL]) and stores them inConstantValuefor later resolution. - Adds a
Definesdictionary toOpenXRSpecificationpopulated from#define-category types in the XML, and aTryParseDefineIntValuehelper inProgram.csto resolve their values; struct generation now falls back throughvalidConstant→enumCount→defineCountwith a proper error throw. - Regenerates the committed binding files (
Structs.cs,Handles.cs,Enums.cs,Constants.cs,Commands.cs) to fix theXrUuid/XrApiLayerCreateInfobugs and include new extension types.
Reviewed changes
Copilot reviewed 3 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
OpenXRGen/OpenXRGen/StructureDefinition.cs |
Regex updated to match symbolic constant array indices; new logic routes them to ConstantValue |
OpenXRGen/OpenXRGen/OpenXRSpecification.cs |
Adds Defines dictionary populated from #define XML types |
OpenXRGen/OpenXRGen/Program.cs |
Adds TryParseDefineIntValue helper; struct generation extended with define-based constant resolution and proper error on failure; trailing blank lines added |
OpenXRGen/Evergine.Bindings.OpenXR/Generated/Structs.cs |
Fixes XrUuid.data, XrApiLayerCreateInfo.settings_file_location, XrEyeGazesFB.gaze; adds new extension structs |
OpenXRGen/Evergine.Bindings.OpenXR/Generated/Handles.cs |
Adds XrFaceTrackerANDROID and XrFaceTrackerBD handle types |
OpenXRGen/Evergine.Bindings.OpenXR/Generated/Enums.cs |
Adds new enum types and values for ANDROID and BD face tracking extensions |
OpenXRGen/Evergine.Bindings.OpenXR/Generated/Constants.cs |
Updates spec version constants, adds XR_FACE_PARAMETER_COUNT_ANDROID and related new extension constants |
OpenXRGen/Evergine.Bindings.OpenXR/Generated/Commands.cs |
Adds function pointer declarations and load calls for new ANDROID/BD face tracking commands |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (firstIsNumeric && !secondIsPresent) | ||
| { | ||
| m.ElementCount = value1; | ||
| } | ||
| else if (firstIsNumeric && secondIsNumeric) | ||
| { | ||
| string valueString1 = match.Groups[1].Value; | ||
| string valueString2 = match.Groups[3].Value; | ||
| m.ElementCount = int.Parse(valueString1) * int.Parse(valueString2); | ||
| m.ElementCount = value1 * value2; | ||
| } | ||
| else | ||
| else if (!secondIsPresent) | ||
| { | ||
| string valueString = match.Groups[1].Value; | ||
| m.ElementCount = int.Parse(valueString); | ||
| // Handles array declarations using symbolic constants in member text. | ||
| m.ConstantValue = count1; | ||
| } |
There was a problem hiding this comment.
The new code handles four conditions for 2D array dimensions (numeric×numeric, numeric×missing, missing×missing), but the case where the first dimension is numeric and the second dimension is a symbolic constant (e.g., name[3][SYMBOL]) is not handled. Both ElementCount and ConstantValue will remain at their default values (0 and null), meaning the member will be silently treated as a scalar field. While this case may not exist in the current OpenXR spec, it is a latent logic gap that was not present in the original code (which only handled [numeric] or [numeric][numeric] patterns). It would be safer to throw or log a warning for this unrecognized combination so it doesn't silently produce incorrect output in the future.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This parses the defines in the registry, and add them as numerical constants if possible.
This also fixes the generation of struct members that are array of which the size is defined by such numerical constants.
This was mostly done to fix #6, which is a specific blocker for one of my projects.
I do not know what is the policy to update the generated bindings that are committed within the repository itself. Thus this is a separate commit, in case you did not want that.