From 81ab73342983a5af754f0bb66b10e27ae0a3f270 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 11 May 2023 23:33:05 +0800 Subject: [PATCH] added prefer colorspace --- inc/hgl/graph/VKDeviceCreater.h | 65 +++++++++++++++++++---- src/SceneGraph/Vulkan/VKDeviceCreater.cpp | 18 ++++--- 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/inc/hgl/graph/VKDeviceCreater.h b/inc/hgl/graph/VKDeviceCreater.h index df04b09c..c82dbafa 100644 --- a/inc/hgl/graph/VKDeviceCreater.h +++ b/inc/hgl/graph/VKDeviceCreater.h @@ -111,7 +111,7 @@ constexpr const VkFormat SwapchainPreferFormatsSDR[]= PF_ABGR8UN,PF_ABGR8s, PF_A2RGB10UN, PF_A2BGR10UN, - PF_B10GR11UF +// PF_B10GR11UF }; constexpr const VkFormat SwapchainPreferFormatsHDR16[]= @@ -135,6 +135,29 @@ constexpr const VkFormat SwapchainPreferFormatsDepth[]= PF_D32F_S8U }; +constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesNonlinear[]= +{ + VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, + VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT, + VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT, + VK_COLOR_SPACE_BT709_NONLINEAR_EXT, + VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT, + VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT, + VK_COLOR_SPACE_DISPLAY_NATIVE_AMD, +}; + +constexpr const VkColorSpaceKHR SwapchainPreferColorSpacesLinear[]= +{ + VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT, + VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT, + VK_COLOR_SPACE_BT709_LINEAR_EXT, + VK_COLOR_SPACE_BT2020_LINEAR_EXT, + VK_COLOR_SPACE_HDR10_ST2084_EXT, + VK_COLOR_SPACE_DOLBYVISION_EXT, + VK_COLOR_SPACE_HDR10_HLG_EXT, + VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT, +}; + struct PreferFormats { //偏好格式需从低质量到高质量排列 @@ -153,14 +176,36 @@ public: } }; +struct PreferColorSpaces +{ + //偏好格式需从低质量到高质量排列 + const VkColorSpaceKHR *colorspaces; + uint count; + +public: + + const int Find(const VkColorSpaceKHR cs)const + { + for(int i=0;i +* 将此功能定义为类是为了让开发者方便重载处理 */ class VulkanDeviceCreater { @@ -174,21 +219,19 @@ protected: VkExtent2D extent; - const PreferFormats *perfer_color_formats; - const PreferFormats *perfer_depth_formats; + const PreferFormats * perfer_color_formats; + const PreferColorSpaces * perfer_color_spaces; + const PreferFormats * perfer_depth_formats; VkSurfaceKHR surface; VkSurfaceFormatKHR surface_format; - VkSurfaceFormat2KHR surface_format2; CharPointerList ext_list; VkPhysicalDeviceFeatures features={}; protected: - - VkDevice CreateDevice(const uint32_t); public: @@ -196,6 +239,7 @@ public: VulkanDeviceCreater(VulkanInstance *vi, Window *win, const PreferFormats *spf_color, + const PreferColorSpaces *spf_color_space, const PreferFormats *spf_depth, const VulkanHardwareRequirement *req); @@ -223,11 +267,12 @@ public: inline GPUDevice *CreateRenderDevice( VulkanInstance *vi, Window *win, - const PreferFormats *spf_color=&PreferSDR, - const PreferFormats *spf_depth=&PreferDepth, + const PreferFormats * spf_color =&PreferSDR, + const PreferColorSpaces * spf_color_space =&PreferNonlinear, + const PreferFormats * spf_depth =&PreferDepth, const VulkanHardwareRequirement *req=nullptr) { - VulkanDeviceCreater vdc(vi,win,spf_color,spf_depth,req); + VulkanDeviceCreater vdc(vi,win,spf_color,spf_color_space,spf_depth,req); return vdc.Create(); } diff --git a/src/SceneGraph/Vulkan/VKDeviceCreater.cpp b/src/SceneGraph/Vulkan/VKDeviceCreater.cpp index b8655d2a..eb3124f3 100644 --- a/src/SceneGraph/Vulkan/VKDeviceCreater.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceCreater.cpp @@ -231,19 +231,23 @@ void VulkanDeviceCreater::ChooseSurfaceFormat() if (vkGetPhysicalDeviceSurfaceFormatsKHR(*physical_device, surface, &format_count, surface_formats_list) == VK_SUCCESS) { - int index=-1; - int result; + int fmt_index=-1; + int cs_index=-1; + int fmt; + int cs; uint32_t sel=0; for(uint32_t i=0;iFind(surface_formats_list[i].format); + fmt=perfer_color_formats->Find(surface_formats_list[i].format); + cs=perfer_color_spaces->Find(surface_formats_list[i].colorSpace); - if(result>index) + if((fmt==fmt_index&&cs>cs_index)||fmt>fmt_index) { surface_format=surface_formats_list[i]; - index=result; + fmt_index=fmt; + cs_index=cs; sel=i; } } @@ -252,7 +256,7 @@ void VulkanDeviceCreater::ChooseSurfaceFormat() LogSurfaceFormat(surface_formats_list,format_count,sel); #endif//_DEBUG - if(index!=-1) + if(fmt_index!=-1) return; } @@ -311,6 +315,7 @@ GPUDevice *VulkanDeviceCreater::CreateRenderDevice() VulkanDeviceCreater::VulkanDeviceCreater( VulkanInstance *vi, Window *win, const PreferFormats *spf_color, + const PreferColorSpaces *spf_color_space, const PreferFormats *spf_depth, const VulkanHardwareRequirement *req) { @@ -320,6 +325,7 @@ VulkanDeviceCreater::VulkanDeviceCreater( VulkanInstance *vi, physical_device=nullptr; perfer_color_formats=spf_color; + perfer_color_spaces =spf_color_space; perfer_depth_formats=spf_depth; if(req)