st/oxr: Simplify path_cache pointers

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2194>
This commit is contained in:
Christoph Haag 2024-05-25 03:09:28 +02:00 committed by Marge Bot
parent 13b5792a30
commit cddf578092
4 changed files with 36 additions and 39 deletions

View file

@ -756,33 +756,23 @@ def generate_bindings_c(file, b):
f.write('}\n')
f.write(f'''
// Array of pointers to XrPath variables contained in each profile template
static XrPath *path_cache[{len(b.profiles)}] =
{{
''')
static const struct oxr_bindings_path_cache internal_path_cache = {{
\t.path_cache = {{''')
for profile_index, _ in enumerate(b.profiles):
f.write(f'\t&profile_templates[{profile_index}].path_cache,\n')
f.write(f'''
\t\t{{
\t\t\t.path_cache = &profile_templates[{profile_index}].path_cache,
\t\t\t.path_cache_name = &profile_templates[{profile_index}].path,
\t\t}},\n''')
profile_index += 1
f.write(f'''}};
f.write(f'''\t}}
}};
// Array of pointers to the location of the path cache name in each profile template.
// The name string itself is not a compile time constant.
static const char **path_cache_names[{len(b.profiles)}] =
void oxr_get_interaction_profile_path_cache(const struct oxr_bindings_path_cache **out_path_cache)
{{
''')
for profile_index, _ in enumerate(b.profiles):
f.write(f'\t&profile_templates[{profile_index}].path,\n')
profile_index += 1
f.write(f'''}};
static uint64_t path_cache_count = {len(b.profiles)};
void oxr_get_interaction_profile_path_cache(XrPath **out_path_cache[{len(b.profiles)}], const char ***out_path_cache_names[''' + str(len(b.profiles)) + '''], uint64_t *out_path_cache_count)
{
*out_path_cache = path_cache;
*out_path_cache_names = path_cache_names;
*out_path_cache_count = path_cache_count;
}
*out_path_cache = &internal_path_cache;
}}
''')
f.write("\n// clang-format on\n")
@ -806,12 +796,21 @@ typedef uint64_t XrVersion; // OpenXR typedef
struct oxr_extension_status;
/**
* @p out_path_cache Pointer to Array of XrPath pointers.
* @p out_path_cache_names Pointer to Array of string (char*) locations.
* @p out_path_cache_count Number of entries in the out_path_cache[_names] arrays.
*/
void oxr_get_interaction_profile_path_cache(XrPath **out_path_cache[{len(b.profiles)}], const char ***out_path_cache_names[''' + str(len(b.profiles)) + '''], uint64_t *out_path_cache_count);
#define OXR_BINDINGS_PROFILE_TEMPLATE_COUNT {len(b.profiles)}
struct oxr_bindings_path_cache_element {{
//! Pointer to XrPath
XrPath *path_cache;
//! Pointer to char*
const char **path_cache_name;
}};
struct oxr_bindings_path_cache {{
// wrapped in a struct solely to reduce the C pointer soup
struct oxr_bindings_path_cache_element path_cache[OXR_BINDINGS_PROFILE_TEMPLATE_COUNT];
}};
void oxr_get_interaction_profile_path_cache(const struct oxr_bindings_path_cache **out_path_cache);
// clang-format off
''')
@ -884,8 +883,7 @@ struct profile_template
\tconst char *extension_name;
}};
#define NUM_PROFILE_TEMPLATES {len(b.profiles)}
extern struct profile_template profile_templates[NUM_PROFILE_TEMPLATES];
extern struct profile_template profile_templates[OXR_BINDINGS_PROFILE_TEMPLATE_COUNT];
''')

View file

@ -115,7 +115,7 @@ interaction_profile_find_or_create_in_instance(struct oxr_logger *log,
struct profile_template *templ = NULL;
for (size_t x = 0; x < NUM_PROFILE_TEMPLATES; x++) {
for (size_t x = 0; x < OXR_BINDINGS_PROFILE_TEMPLATE_COUNT; x++) {
XrPath t_path = XR_NULL_PATH;
oxr_path_get_or_create(log, inst, profile_templates[x].path, strlen(profile_templates[x].path),

View file

@ -255,12 +255,11 @@ oxr_instance_create(struct oxr_logger *log,
#undef CACHE_SUBACTION_PATHS
XrPath **path_cache;
const char ***path_cache_names;
uint64_t path_cache_count;
oxr_get_interaction_profile_path_cache(&path_cache, &path_cache_names, &path_cache_count);
for (uint32_t i = 0; i < path_cache_count; i++) {
cache_path(log, inst, *path_cache_names[i], path_cache[i]);
const struct oxr_bindings_path_cache *path_cache;
oxr_get_interaction_profile_path_cache(&path_cache);
for (uint32_t i = 0; i < ARRAY_SIZE(path_cache->path_cache); i++) {
cache_path(log, inst, *path_cache->path_cache[i].path_cache_name, path_cache->path_cache[i].path_cache);
}
// fill in our application info - @todo - replicate all createInfo

View file

@ -648,7 +648,7 @@ public:
static struct profile_template *
get_profile_template(enum xrt_device_name device_name)
{
for (int i = 0; i < NUM_PROFILE_TEMPLATES; i++) {
for (int i = 0; i < OXR_BINDINGS_PROFILE_TEMPLATE_COUNT; i++) {
if (profile_templates[i].name == device_name)
return &profile_templates[i];
}