From a97ef007876ef290a292e2a4ea1455f5fcaf38dc Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Thu, 28 Aug 2025 15:18:38 +0200 Subject: [PATCH] Fix #145314: Vulkan: Disable HDR on incapable drivers This PR disables HDR when driver doesn't support `VK_EXT_swapchain_colorspace`. It could be that Windows detect support (DirectX) and allow users to enable HDR. But that it isn't supported by the Vulkan part of the driver. In case of Windows there might be an issue with using SRGB non linear on F16 swapchains where somewhere an additional transform is being performed. After adding support for other color spaces we should remove the support of this swapchain configuration. Pull Request: https://projects.blender.org/blender/blender/pulls/145325 --- intern/ghost/intern/GHOST_ContextVK.cc | 31 ++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/intern/ghost/intern/GHOST_ContextVK.cc b/intern/ghost/intern/GHOST_ContextVK.cc index 9cc79d86a9a..c8e3dccfbae 100644 --- a/intern/ghost/intern/GHOST_ContextVK.cc +++ b/intern/ghost/intern/GHOST_ContextVK.cc @@ -183,10 +183,15 @@ class GHOST_DeviceVK { std::mutex queue_mutex; bool use_vk_ext_swapchain_maintenance_1 = false; + bool use_vk_ext_swapchain_colorspace = false; public: - GHOST_DeviceVK(VkInstance vk_instance, VkPhysicalDevice vk_physical_device) - : instance(vk_instance), physical_device(vk_physical_device) + GHOST_DeviceVK(VkInstance vk_instance, + VkPhysicalDevice vk_physical_device, + const bool use_vk_ext_swapchain_colorspace) + : instance(vk_instance), + physical_device(vk_physical_device), + use_vk_ext_swapchain_colorspace(use_vk_ext_swapchain_colorspace) { properties.pNext = &properties_12; vkGetPhysicalDeviceProperties2(physical_device, &properties); @@ -458,7 +463,8 @@ static std::optional vulkan_device; static GHOST_TSuccess ensure_vulkan_device(VkInstance vk_instance, VkSurfaceKHR vk_surface, const GHOST_GPUDevice &preferred_device, - const vector &required_extensions) + const vector &required_extensions, + const bool use_vk_ext_swapchain_colorspace) { if (vulkan_device.has_value()) { return GHOST_kSuccess; @@ -475,7 +481,7 @@ static GHOST_TSuccess ensure_vulkan_device(VkInstance vk_instance, int best_device_score = -1; int device_index = -1; for (const auto &physical_device : physical_devices) { - GHOST_DeviceVK device_vk(vk_instance, physical_device); + GHOST_DeviceVK device_vk(vk_instance, physical_device, use_vk_ext_swapchain_colorspace); device_index++; if (!device_vk.has_extensions(required_extensions)) { @@ -550,7 +556,7 @@ static GHOST_TSuccess ensure_vulkan_device(VkInstance vk_instance, return GHOST_kFailure; } - vulkan_device.emplace(vk_instance, best_physical_device); + vulkan_device.emplace(vk_instance, best_physical_device, use_vk_ext_swapchain_colorspace); return GHOST_kSuccess; } @@ -650,7 +656,8 @@ GHOST_TSuccess GHOST_ContextVK::swapBuffers() } submission_frame_data.discard_pile.destroy(device); - const bool use_hdr_swapchain = hdr_info_ && hdr_info_->hdr_enabled; + const bool use_hdr_swapchain = hdr_info_ && hdr_info_->hdr_enabled && + vulkan_device->use_vk_ext_swapchain_colorspace; if (use_hdr_swapchain != use_hdr_swapchain_) { /* Re-create swapchain if HDR mode was toggled in the system settings. */ recreateSwapchain(use_hdr_swapchain); @@ -1238,6 +1245,7 @@ const char *GHOST_ContextVK::getPlatformSpecificSurfaceExtension() const GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext() { + bool use_vk_ext_swapchain_colorspace = false; #ifdef _WIN32 const bool use_window_surface = (hwnd_ != nullptr); #elif defined(__APPLE__) @@ -1293,9 +1301,9 @@ GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext() optional_device_extensions.push_back(VK_EXT_SWAPCHAIN_MAINTENANCE_1_EXTENSION_NAME); } - const bool use_swapchain_colorspace = contains_extension( + use_vk_ext_swapchain_colorspace = contains_extension( extensions_available, VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME); - if (use_swapchain_colorspace) { + if (use_vk_ext_swapchain_colorspace) { requireExtension( extensions_available, extensions_enabled, VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME); } @@ -1398,7 +1406,12 @@ GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext() #endif } - if (!ensure_vulkan_device(instance, surface_, preferred_device_, required_device_extensions)) { + if (!ensure_vulkan_device(instance, + surface_, + preferred_device_, + required_device_extensions, + use_vk_ext_swapchain_colorspace)) + { return GHOST_kFailure; }