[Bf-blender-cvs] [5d5ad5d6dd6] soc-2019-openxr: Gather available OpenXR extensions and API-layers on OpenXR setup
Julian Eisel
noreply at git.blender.org
Sat Jun 1 17:17:08 CEST 2019
Commit: 5d5ad5d6dd646429f63001f773694ae73674f74b
Author: Julian Eisel
Date: Sat Jun 1 17:11:18 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rB5d5ad5d6dd646429f63001f773694ae73674f74b
Gather available OpenXR extensions and API-layers on OpenXR setup
We don't actually enable any extension or layer yet. We just put their
names into arrays and print them. The printing can be disabled via a
compiler define, later we should put them behind a proper
logging/debugging mechanism (CLOG).
Also fixes a Visual Studio compile error.
===================================================================
M extern/openxr/CMakeLists.txt
M source/blender/windowmanager/intern/wm_xr.c
===================================================================
diff --git a/extern/openxr/CMakeLists.txt b/extern/openxr/CMakeLists.txt
index 50ba3d52574..90e410f7b6f 100644
--- a/extern/openxr/CMakeLists.txt
+++ b/extern/openxr/CMakeLists.txt
@@ -40,6 +40,7 @@ add_custom_target(
${OPENXR_SDK_INCLUDES}/openxr/openxr_platform_defines.h
${OPENXR_SDK_INCLUDES}/openxr/openxr.h
${OPENXR_SDK_INCLUDES}/openxr/openxr_platform.h
+ ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index e3e1becfa65..dbefcde3c67 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -40,6 +40,10 @@
#include "WM_types.h"
#include "wm.h"
+/* Toggle printing of available OpenXR extensions and API-layers. Should probably be changed to use
+ * CLOG at some point */
+#define USE_EXT_LAYER_PRINTS
+
#if !defined(WITH_OPENXR)
static_assert(false, "WITH_OPENXR not defined, but wm_xr.c is being compiled.");
#endif
@@ -47,23 +51,120 @@ static_assert(false, "WITH_OPENXR not defined, but wm_xr.c is being compiled.");
typedef struct wmXRContext {
struct OpenXRData {
XrInstance instance;
+
+ XrExtensionProperties *extensions;
+ uint32_t extension_count;
+
+ XrApiLayerProperties *layers;
+ uint32_t layer_count;
} oxr;
} wmXRContext;
-wmXRContext *wm_xr_context_create(void)
+/**
+ * \param layer_name May be NULL for extensions not belonging to a specific layer.
+ */
+static void openxr_gather_extensions_ex(wmXRContext *context, const char *layer_name)
{
- XrInstanceCreateInfo create_info = {.type = XR_TYPE_INSTANCE_CREATE_INFO};
- XrInstance instance = {0};
+ uint32_t extension_count;
- wmXRContext *wm_context = MEM_callocN(sizeof(*wm_context), "wmXRContext");
+ context->oxr.extensions = NULL;
- BLI_assert(wm_context->oxr.instance == XR_NULL_HANDLE);
+ /* Get count for array creation/init first. */
+ xrEnumerateInstanceExtensionProperties(layer_name, 0, &extension_count, NULL);
+
+ if (extension_count == 0) {
+ /* Extensions are optional, can safely exit. */
+ return;
+ }
+
+ context->oxr.extensions = MEM_calloc_arrayN(
+ extension_count, sizeof(*context->oxr.extensions), "xrExtensionProperties");
+ for (int i = 0; i < extension_count; i++) {
+ context->oxr.extensions[i].type = XR_TYPE_EXTENSION_PROPERTIES;
+ }
+
+#ifdef USE_EXT_LAYER_PRINTS
+ if (layer_name) {
+ printf("Layer: %s\n", layer_name);
+ }
+#endif
+ /* Actually get the extensions. */
+ xrEnumerateInstanceExtensionProperties(
+ layer_name, extension_count, &extension_count, context->oxr.extensions);
+#ifdef USE_EXT_LAYER_PRINTS
+ for (int i = 0; i < extension_count; i++) {
+ printf("Extension: %s\n", context->oxr.extensions[i].extensionName);
+ }
+#endif
+}
+static void openxr_gather_extensions(wmXRContext *context)
+{
+ openxr_gather_extensions_ex(context, NULL);
+}
+
+static void openxr_gather_api_layers(wmXRContext *context)
+{
+ uint32_t layer_count;
+
+ /* Get count for array creation/init first. */
+ xrEnumerateApiLayerProperties(0, &layer_count, NULL);
+
+ if (layer_count == 0) {
+ /* Layers are optional, can safely exit. */
+ return;
+ }
+
+ context->oxr.layers = MEM_calloc_arrayN(
+ layer_count, sizeof(*context->oxr.layers), "XrApiLayerProperties");
+ for (int i = 0; i < layer_count; i++) {
+ context->oxr.layers[i].type = XR_TYPE_API_LAYER_PROPERTIES;
+ }
+
+ /* Actually get the layers. */
+ xrEnumerateApiLayerProperties(layer_count, &layer_count, context->oxr.layers);
+ for (int i = 0; i < layer_count; i++) {
+#ifdef USE_EXT_LAYER_PRINTS
+ printf("Layer: %s\n", context->oxr.layers[i]);
+#endif
+ /* Each layer may have own extensions */
+ openxr_gather_extensions_ex(context, context->oxr.layers[i].layerName);
+ }
+}
+
+static bool openxr_instance_setup(wmXRContext *context) ATTR_NONNULL()
+{
+ XrInstanceCreateInfo create_info = {.type = XR_TYPE_INSTANCE_CREATE_INFO};
+
+#ifdef USE_EXT_LAYER_PRINTS
+ puts("Available OpenXR layers/extensions:");
+#endif
+ openxr_gather_api_layers(context);
+ openxr_gather_extensions(context);
+#ifdef USE_EXT_LAYER_PRINTS
+ puts("Done printing OpenXR layers/extensions.");
+#endif
BLI_strncpy(
create_info.applicationInfo.applicationName, "Blender", XR_MAX_APPLICATION_NAME_SIZE);
create_info.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
+ // create_info.enabledExtensionCount = 1;
+ create_info.enabledExtensionCount = 0;
+ static const uchar *enabled_extensions[] = {// "XR_KHR_D3D11_enable",
+ // "XR_KHR_opengl_enable"
+ ""};
+ create_info.enabledExtensionNames = enabled_extensions;
- xrCreateInstance(&create_info, &instance);
+ xrCreateInstance(&create_info, &context->oxr.instance);
+
+ return true;
+}
+
+wmXRContext *wm_xr_context_create(void)
+{
+ wmXRContext *wm_context = MEM_callocN(sizeof(*wm_context), "wmXRContext");
+
+ BLI_assert(wm_context->oxr.instance == XR_NULL_HANDLE);
+ openxr_instance_setup(wm_context);
return wm_context;
}
@@ -71,5 +172,7 @@ wmXRContext *wm_xr_context_create(void)
void wm_xr_context_destroy(wmXRContext *wm_context)
{
xrDestroyInstance(wm_context->oxr.instance);
+ MEM_SAFE_FREE(wm_context->oxr.extensions);
+ MEM_SAFE_FREE(wm_context->oxr.layers);
MEM_SAFE_FREE(wm_context);
}
More information about the Bf-blender-cvs
mailing list