Skip to content

Commit

Permalink
Implement xrEnumerateInstanceExtensionProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Jul 22, 2024
1 parent 1ea8b46 commit 9d72660
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
44 changes: 38 additions & 6 deletions src/APILayer/APILayer_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,44 @@ static XrResult xrDestroyInstance(XrInstance instance) {
return result;
}

static XrResult xrEnumerateInstanceExtensionProperties(
const char* layerName,
uint32_t propertyCapacityInput,
uint32_t* propertyCountOutput,
XrExtensionProperties* properties) {
// This is installed as an implicit layer; for behavior spec, see:
// https://registry.khronos.org/OpenXR/specs/1.0/loader.html#api-layer-conventions-and-rules
if (layerName && std::string_view {layerName} == OpenXRLayerName) {
*propertyCountOutput = 0;
// We don't implement any instance extensions
return XR_SUCCESS;
}

// As we don't implement any extensions, just delegate to the runtime or next
// layer.
if (gNext && gNext->have_xrEnumerateInstanceExtensionProperties()) {
// We *could* strip the hand tracking extensions here, but we're not
// - applications wouldn't see this, as the loader just uses the manifest
// files instead
// - we can just make the extension functions report failure
// - probably best to have consistent behavior for applications and API
// layers
return gNext->raw_xrEnumerateInstanceExtensionProperties(
layerName, propertyCapacityInput, propertyCountOutput, properties);
}

if (layerName) {
// If layerName is non-null and not our layer, it should be an earlier
// layer, or we should have a `next`
return XR_ERROR_API_LAYER_NOT_PRESENT;
}

// for NULL layerName, we append our list to the next; as we have none, that
// just means we have 0 again
*propertyCountOutput = 0;
return XR_SUCCESS;
}

static XrResult xrEnumerateApiLayerProperties(
uint32_t propertyCapacityInput,
uint32_t* propertyCountOutput,
Expand Down Expand Up @@ -263,12 +301,6 @@ static XrResult xrGetInstanceProcAddr(
INTERCEPTED_OPENXR_FUNCS
#undef IT

if (name == "xrEnumerateApiLayerProperties") {
*function
= reinterpret_cast<PFN_xrVoidFunction>(&xrEnumerateApiLayerProperties);
return XR_SUCCESS;
}

if (gNext) {
const auto result
= gNext->raw_xrGetInstanceProcAddr(instance, name_cstr, function);
Expand Down
6 changes: 5 additions & 1 deletion src/lib/OpenXRNext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "DebugPrint.h"

#define INTERCEPTED_OPENXR_FUNCS \
IT(xrEnumerateApiLayerProperties) \
IT(xrEnumerateInstanceExtensionProperties) \
IT(xrGetSystemProperties) \
IT(xrDestroyInstance) \
IT(xrCreateSession) \
Expand All @@ -56,7 +58,6 @@
IT(xrDestroyHandTrackerEXT) \
IT(xrLocateHandJointsEXT) \
IT(xrGetInstanceProperties) \
IT(xrEnumerateInstanceExtensionProperties) \
IT(xrConvertTimeToWin32PerformanceCounterKHR) \
IT(xrConvertWin32PerformanceCounterToTimeKHR)

Expand Down Expand Up @@ -88,6 +89,9 @@ class OpenXRNext final {
template <class... Args> \
bool check_##func(Args&&... args) { \
return this->func(std::forward<Args>(args)...) == XR_SUCCESS; \
} \
inline bool have_##func() const noexcept { \
return m_##func != nullptr; \
}
IT(xrGetInstanceProcAddr)
NEXT_OPENXR_FUNCS
Expand Down

0 comments on commit 9d72660

Please sign in to comment.