diff --git a/CMakeLists.txt b/CMakeLists.txt index ec018b53a..b1f4a6123 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ endif() option(BUILD_TESTS "Build compile and runtime tests" ON) option(OPENXR_USE_LOADER "Application uses loader" ON) - +option(VULKAN_ENABLE_VALIDATION "Enable Vulkan validation for Compositor" ON) ### # Dependencies diff --git a/src/xrt/compositor/CMakeLists.txt b/src/xrt/compositor/CMakeLists.txt index 406d55041..8ea75a572 100644 --- a/src/xrt/compositor/CMakeLists.txt +++ b/src/xrt/compositor/CMakeLists.txt @@ -45,6 +45,10 @@ if (${XCB_FOUND}) add_definitions(-DVK_USE_PLATFORM_XLIB_XRANDR_EXT) endif() +if (${VULKAN_ENABLE_VALIDATION}) + add_definitions(-DXRT_ENABLE_VK_VALIDATION) +endif() + # Use OBJECT to not create a archive, since it just gets in the way. add_library(comp OBJECT ${GL_SOURCE_FILES}) set_property(TARGET comp PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index f76a5bd51..0926f21db 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -258,23 +258,24 @@ create_instance(struct comp_compositor *c) return ret; } -#ifdef XRT_ENABLE_VK_VALIDATION - const char *instance_layers[] = { - "VK_LAYER_LUNARG_standard_validation", - }; -#endif - VkInstanceCreateInfo instance_info = { .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &app_info, .enabledExtensionCount = num_extensions, .ppEnabledExtensionNames = instance_extensions, -#ifdef XRT_ENABLE_VK_VALIDATION - .enabledLayerCount = ARRAY_SIZE(instance_layers), - .ppEnabledLayerNames = instance_layers, -#endif }; +#ifdef XRT_ENABLE_VK_VALIDATION + const char *instance_layers[] = { + "VK_LAYER_LUNARG_standard_validation", + }; + + if (c->settings.validate_vulkan) { + instance_info.enabledLayerCount = ARRAY_SIZE(instance_layers); + instance_info.ppEnabledLayerNames = instance_layers; + } +#endif + ret = c->vk.vkCreateInstance(&instance_info, NULL, &c->vk.instance); if (ret != VK_SUCCESS) { COMP_ERROR(c, "vkCreateInstance: %s\n", vk_result_string(ret)); @@ -290,7 +291,8 @@ create_instance(struct comp_compositor *c) } #ifdef XRT_ENABLE_VK_VALIDATION - vk_init_validation_callback(&c->vk); + if (c->settings.validate_vulkan) + vk_init_validation_callback(&c->vk); #endif return ret; diff --git a/src/xrt/compositor/main/comp_settings.c b/src/xrt/compositor/main/comp_settings.c index 3394aacef..4993af0fc 100644 --- a/src/xrt/compositor/main/comp_settings.c +++ b/src/xrt/compositor/main/comp_settings.c @@ -15,6 +15,7 @@ DEBUG_GET_ONCE_BOOL_OPTION(print_debug, "XRT_COMPOSITOR_PRINT_DEBUG", false) DEBUG_GET_ONCE_BOOL_OPTION(force_direct, "XRT_COMPOSITOR_FORCE_DIRECT", false) DEBUG_GET_ONCE_BOOL_OPTION(force_xcb, "XRT_COMPOSITOR_FORCE_XCB", false) DEBUG_GET_ONCE_BOOL_OPTION(force_wayland, "XRT_COMPOSITOR_FORCE_WAYLAND", false) +DEBUG_GET_ONCE_BOOL_OPTION(validate_vulkan, "XRT_COMPOSITOR_VULKAN_VALIDATION", false) void comp_settings_init(struct comp_settings *s, struct xrt_device *xdev) @@ -34,6 +35,7 @@ comp_settings_init(struct comp_settings *s, struct xrt_device *xdev) xdev->screens[0].nominal_frame_interval_ns; s->print_spew = debug_get_bool_option_print_spew(); s->print_debug = debug_get_bool_option_print_debug(); + s->validate_vulkan = debug_get_bool_option_validate_vulkan(); if (debug_get_bool_option_force_direct()) { s->window_type = WINDOW_DIRECT_MODE; diff --git a/src/xrt/compositor/main/comp_settings.h b/src/xrt/compositor/main/comp_settings.h index 92a0f31f5..b5f26c6e3 100644 --- a/src/xrt/compositor/main/comp_settings.h +++ b/src/xrt/compositor/main/comp_settings.h @@ -70,6 +70,9 @@ struct comp_settings //! Nominal frame interval uint64_t nominal_frame_interval_ns; + + //! Enable vulkan validation for compositor + bool validate_vulkan; }; /*!