added prefer colorspace
This commit is contained in:
parent
05885e443a
commit
81ab733429
@ -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<count;i++)
|
||||
if(cs==colorspaces[i])
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr const PreferFormats PreferLDR {SwapchainPreferFormatsLDR, sizeof(SwapchainPreferFormatsLDR )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferSDR {SwapchainPreferFormatsSDR, sizeof(SwapchainPreferFormatsSDR )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferHDR16{SwapchainPreferFormatsHDR16, sizeof(SwapchainPreferFormatsHDR16 )/sizeof(VkFormat)};
|
||||
constexpr const PreferFormats PreferHDR32{SwapchainPreferFormatsHDR32, sizeof(SwapchainPreferFormatsHDR32 )/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
|
||||
{
|
||||
@ -175,20 +220,18 @@ protected:
|
||||
VkExtent2D extent;
|
||||
|
||||
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);
|
||||
|
||||
@ -224,10 +268,11 @@ public:
|
||||
inline GPUDevice *CreateRenderDevice( VulkanInstance *vi,
|
||||
Window *win,
|
||||
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();
|
||||
}
|
||||
|
@ -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;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];
|
||||
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user