added prefer colorspace

This commit is contained in:
hyzboy 2023-05-11 23:33:05 +08:00
parent 05885e443a
commit 81ab733429
No known key found for this signature in database
GPG Key ID: 067EE4525D4FB6D3
2 changed files with 67 additions and 16 deletions

View File

@ -111,7 +111,7 @@ constexpr const VkFormat SwapchainPreferFormatsSDR[]=
PF_ABGR8UN,PF_ABGR8s, PF_ABGR8UN,PF_ABGR8s,
PF_A2RGB10UN, PF_A2RGB10UN,
PF_A2BGR10UN, PF_A2BGR10UN,
PF_B10GR11UF // PF_B10GR11UF
}; };
constexpr const VkFormat SwapchainPreferFormatsHDR16[]= constexpr const VkFormat SwapchainPreferFormatsHDR16[]=
@ -135,6 +135,29 @@ constexpr const VkFormat SwapchainPreferFormatsDepth[]=
PF_D32F_S8U 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 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<count;i++)
if(cs==colorspaces[i])
return i;
return -1;
}
};
constexpr const PreferFormats PreferLDR {SwapchainPreferFormatsLDR, sizeof(SwapchainPreferFormatsLDR )/sizeof(VkFormat)}; constexpr const PreferFormats PreferLDR {SwapchainPreferFormatsLDR, sizeof(SwapchainPreferFormatsLDR )/sizeof(VkFormat)};
constexpr const PreferFormats PreferSDR {SwapchainPreferFormatsSDR, sizeof(SwapchainPreferFormatsSDR )/sizeof(VkFormat)}; constexpr const PreferFormats PreferSDR {SwapchainPreferFormatsSDR, sizeof(SwapchainPreferFormatsSDR )/sizeof(VkFormat)};
constexpr const PreferFormats PreferHDR16{SwapchainPreferFormatsHDR16, sizeof(SwapchainPreferFormatsHDR16 )/sizeof(VkFormat)}; constexpr const PreferFormats PreferHDR16{SwapchainPreferFormatsHDR16, sizeof(SwapchainPreferFormatsHDR16 )/sizeof(VkFormat)};
constexpr const PreferFormats PreferHDR32{SwapchainPreferFormatsHDR32, sizeof(SwapchainPreferFormatsHDR32 )/sizeof(VkFormat)}; constexpr const PreferFormats PreferHDR32{SwapchainPreferFormatsHDR32, sizeof(SwapchainPreferFormatsHDR32 )/sizeof(VkFormat)};
constexpr const PreferFormats PreferDepth{SwapchainPreferFormatsDepth, sizeof(SwapchainPreferFormatsDepth )/sizeof(VkFormat)}; constexpr const PreferFormats PreferDepth{SwapchainPreferFormatsDepth, sizeof(SwapchainPreferFormatsDepth )/sizeof(VkFormat)};
constexpr const PreferColorSpaces PreferNonlinear {SwapchainPreferColorSpacesNonlinear, sizeof(SwapchainPreferColorSpacesNonlinear )/sizeof(VkColorSpaceKHR)};
constexpr const PreferColorSpaces PreferLinear {SwapchainPreferColorSpacesLinear, sizeof(SwapchainPreferColorSpacesLinear )/sizeof(VkColorSpaceKHR)};
/** /**
* Vulkan设备创建器 * Vulkan设备创建器<br>
* 便
*/ */
class VulkanDeviceCreater class VulkanDeviceCreater
{ {
@ -174,21 +219,19 @@ protected:
VkExtent2D extent; VkExtent2D extent;
const PreferFormats *perfer_color_formats; const PreferFormats * perfer_color_formats;
const PreferFormats *perfer_depth_formats; const PreferColorSpaces * perfer_color_spaces;
const PreferFormats * perfer_depth_formats;
VkSurfaceKHR surface; VkSurfaceKHR surface;
VkSurfaceFormatKHR surface_format; VkSurfaceFormatKHR surface_format;
VkSurfaceFormat2KHR surface_format2;
CharPointerList ext_list; CharPointerList ext_list;
VkPhysicalDeviceFeatures features={}; VkPhysicalDeviceFeatures features={};
protected: protected:
VkDevice CreateDevice(const uint32_t); VkDevice CreateDevice(const uint32_t);
public: public:
@ -196,6 +239,7 @@ public:
VulkanDeviceCreater(VulkanInstance *vi, VulkanDeviceCreater(VulkanInstance *vi,
Window *win, Window *win,
const PreferFormats *spf_color, const PreferFormats *spf_color,
const PreferColorSpaces *spf_color_space,
const PreferFormats *spf_depth, const PreferFormats *spf_depth,
const VulkanHardwareRequirement *req); const VulkanHardwareRequirement *req);
@ -223,11 +267,12 @@ public:
inline GPUDevice *CreateRenderDevice( VulkanInstance *vi, inline GPUDevice *CreateRenderDevice( VulkanInstance *vi,
Window *win, Window *win,
const PreferFormats *spf_color=&PreferSDR, const PreferFormats * spf_color =&PreferSDR,
const PreferFormats *spf_depth=&PreferDepth, const PreferColorSpaces * spf_color_space =&PreferNonlinear,
const PreferFormats * spf_depth =&PreferDepth,
const VulkanHardwareRequirement *req=nullptr) 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(); return vdc.Create();
} }

View File

@ -231,19 +231,23 @@ void VulkanDeviceCreater::ChooseSurfaceFormat()
if (vkGetPhysicalDeviceSurfaceFormatsKHR(*physical_device, surface, &format_count, surface_formats_list) == VK_SUCCESS) if (vkGetPhysicalDeviceSurfaceFormatsKHR(*physical_device, surface, &format_count, surface_formats_list) == VK_SUCCESS)
{ {
int index=-1; int fmt_index=-1;
int result; int cs_index=-1;
int fmt;
int cs;
uint32_t sel=0; uint32_t sel=0;
for(uint32_t i=0;i<format_count;i++) for(uint32_t i=0;i<format_count;i++)
{ {
result=perfer_color_formats->Find(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]; surface_format=surface_formats_list[i];
index=result; fmt_index=fmt;
cs_index=cs;
sel=i; sel=i;
} }
} }
@ -252,7 +256,7 @@ void VulkanDeviceCreater::ChooseSurfaceFormat()
LogSurfaceFormat(surface_formats_list,format_count,sel); LogSurfaceFormat(surface_formats_list,format_count,sel);
#endif//_DEBUG #endif//_DEBUG
if(index!=-1) if(fmt_index!=-1)
return; return;
} }
@ -311,6 +315,7 @@ GPUDevice *VulkanDeviceCreater::CreateRenderDevice()
VulkanDeviceCreater::VulkanDeviceCreater( VulkanInstance *vi, VulkanDeviceCreater::VulkanDeviceCreater( VulkanInstance *vi,
Window *win, Window *win,
const PreferFormats *spf_color, const PreferFormats *spf_color,
const PreferColorSpaces *spf_color_space,
const PreferFormats *spf_depth, const PreferFormats *spf_depth,
const VulkanHardwareRequirement *req) const VulkanHardwareRequirement *req)
{ {
@ -320,6 +325,7 @@ VulkanDeviceCreater::VulkanDeviceCreater( VulkanInstance *vi,
physical_device=nullptr; physical_device=nullptr;
perfer_color_formats=spf_color; perfer_color_formats=spf_color;
perfer_color_spaces =spf_color_space;
perfer_depth_formats=spf_depth; perfer_depth_formats=spf_depth;
if(req) if(req)