added VulkanDeviceCreater::ChooseSurfaceFormat
This commit is contained in:
parent
71c543413a
commit
05885e443a
@ -32,7 +32,6 @@ struct GPUDeviceAttribute
|
|||||||
List<VkQueueFamilyProperties> family_properties;
|
List<VkQueueFamilyProperties> family_properties;
|
||||||
List<VkBool32> supports_present;
|
List<VkBool32> supports_present;
|
||||||
|
|
||||||
List<VkSurfaceFormatKHR> surface_formats_list;
|
|
||||||
VkSurfaceFormatKHR surface_format;
|
VkSurfaceFormatKHR surface_format;
|
||||||
List<VkPresentModeKHR> present_modes;
|
List<VkPresentModeKHR> present_modes;
|
||||||
|
|
||||||
|
@ -140,6 +140,17 @@ struct PreferFormats
|
|||||||
//偏好格式需从低质量到高质量排列
|
//偏好格式需从低质量到高质量排列
|
||||||
const VkFormat *formats;
|
const VkFormat *formats;
|
||||||
uint count;
|
uint count;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
const int Find(const VkFormat fmt)const
|
||||||
|
{
|
||||||
|
for(int i=0;i<count;i++)
|
||||||
|
if(fmt==formats[i])
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr const PreferFormats PreferLDR {SwapchainPreferFormatsLDR, sizeof(SwapchainPreferFormatsLDR )/sizeof(VkFormat)};
|
constexpr const PreferFormats PreferLDR {SwapchainPreferFormatsLDR, sizeof(SwapchainPreferFormatsLDR )/sizeof(VkFormat)};
|
||||||
@ -168,11 +179,16 @@ protected:
|
|||||||
|
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
|
|
||||||
|
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 +212,8 @@ public:
|
|||||||
|
|
||||||
virtual bool RequirementCheck();
|
virtual bool RequirementCheck();
|
||||||
|
|
||||||
|
virtual void ChooseSurfaceFormat();
|
||||||
|
|
||||||
virtual GPUDevice *CreateRenderDevice();
|
virtual GPUDevice *CreateRenderDevice();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -11,27 +11,6 @@
|
|||||||
#include<hgl/graph/VKDeviceRenderPassManage.h>
|
#include<hgl/graph/VKDeviceRenderPassManage.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
void LogSurfaceFormat(const List<VkSurfaceFormatKHR> &surface_format_list)
|
|
||||||
{
|
|
||||||
const uint32_t format_count=surface_format_list.GetCount();
|
|
||||||
const VkSurfaceFormatKHR *sf=surface_format_list.GetData();
|
|
||||||
|
|
||||||
LOG_INFO(OS_TEXT("Current physics device support ")+OSString::numberOf(format_count)+OS_TEXT(" surface format"));
|
|
||||||
|
|
||||||
const VulkanFormat *vf;
|
|
||||||
const VulkanColorSpace *cs;
|
|
||||||
|
|
||||||
for(uint32_t i=0;i<format_count;i++)
|
|
||||||
{
|
|
||||||
vf=GetVulkanFormat(sf->format);
|
|
||||||
cs=GetVulkanColorSpace(sf->colorSpace);
|
|
||||||
|
|
||||||
LOG_INFO(" "+AnsiString::numberOf(i)+": "+AnsiString(vf->name)+", "+AnsiString(cs->name));
|
|
||||||
|
|
||||||
++sf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GPUDevice::GPUDevice(GPUDeviceAttribute *da)
|
GPUDevice::GPUDevice(GPUDeviceAttribute *da)
|
||||||
{
|
{
|
||||||
attr=da;
|
attr=da;
|
||||||
@ -46,8 +25,6 @@ GPUDevice::GPUDevice(GPUDeviceAttribute *da)
|
|||||||
|
|
||||||
texture_cmd_buf=CreateTextureCommandBuffer();
|
texture_cmd_buf=CreateTextureCommandBuffer();
|
||||||
texture_queue=CreateQueue();
|
texture_queue=CreateQueue();
|
||||||
|
|
||||||
LogSurfaceFormat(attr->surface_formats_list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GPUDevice::~GPUDevice()
|
GPUDevice::~GPUDevice()
|
||||||
|
@ -14,7 +14,6 @@ GPUDeviceAttribute::GPUDeviceAttribute(VulkanInstance *inst,const GPUPhysicalDev
|
|||||||
surface=s;
|
surface=s;
|
||||||
|
|
||||||
RefreshSurfaceCaps();
|
RefreshSurfaceCaps();
|
||||||
GetSurfaceFormatList();
|
|
||||||
GetSurfacePresentMode();
|
GetSurfacePresentMode();
|
||||||
GetQueueFamily();
|
GetQueueFamily();
|
||||||
}
|
}
|
||||||
@ -83,49 +82,6 @@ void GPUDeviceAttribute::RefreshSurfaceCaps()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPUDeviceAttribute::GetSurfaceFormatList()
|
|
||||||
{
|
|
||||||
VkPhysicalDevice pdevice = *physical_device;
|
|
||||||
|
|
||||||
{
|
|
||||||
uint32_t format_count;
|
|
||||||
|
|
||||||
surface_format.format = PF_A2BGR10UN;
|
|
||||||
surface_format.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
|
||||||
|
|
||||||
if (vkGetPhysicalDeviceSurfaceFormatsKHR(pdevice, surface, &format_count, nullptr) == VK_SUCCESS)
|
|
||||||
{
|
|
||||||
surface_formats_list.SetCount(format_count);
|
|
||||||
|
|
||||||
if (vkGetPhysicalDeviceSurfaceFormatsKHR(pdevice, surface, &format_count, surface_formats_list.GetData()) != VK_SUCCESS)
|
|
||||||
{
|
|
||||||
surface_formats_list.Clear();
|
|
||||||
}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// VkSurfaceFormatKHR *sf = surface_formats_list.GetData();
|
|
||||||
|
|
||||||
// if (format_count == 1 && sf->format == VK_FORMAT_UNDEFINED)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// surface_format.format=VK_FORMAT_UNDEFINED;
|
|
||||||
|
|
||||||
// for(uint32_t i=0;i<format_count;i++)
|
|
||||||
// {
|
|
||||||
// if(sf->format>surface_format.format
|
|
||||||
// &&sf->colorSpace==VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
|
|
||||||
// surface_format=*sf;
|
|
||||||
|
|
||||||
// ++sf;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPUDeviceAttribute::GetSurfacePresentMode()
|
void GPUDeviceAttribute::GetSurfacePresentMode()
|
||||||
{
|
{
|
||||||
uint32_t mode_count;
|
uint32_t mode_count;
|
||||||
|
@ -16,6 +16,29 @@ VkPipelineCache CreatePipelineCache(VkDevice device,const VkPhysicalDeviceProper
|
|||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
DebugMaker *CreateDebugMaker(VkDevice);
|
DebugMaker *CreateDebugMaker(VkDevice);
|
||||||
DebugUtils *CreateDebugUtils(VkDevice);
|
DebugUtils *CreateDebugUtils(VkDevice);
|
||||||
|
|
||||||
|
void LogSurfaceFormat(const VkSurfaceFormatKHR *surface_format_list,const uint32_t format_count,const uint32_t select)
|
||||||
|
{
|
||||||
|
const VkSurfaceFormatKHR *sf=surface_format_list;
|
||||||
|
|
||||||
|
std::cout<<"Current physics device support "<<format_count<<" surface format"<<std::endl;
|
||||||
|
|
||||||
|
const VulkanFormat *vf;
|
||||||
|
const VulkanColorSpace *cs;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<format_count;i++)
|
||||||
|
{
|
||||||
|
vf=GetVulkanFormat(sf->format);
|
||||||
|
cs=GetVulkanColorSpace(sf->colorSpace);
|
||||||
|
|
||||||
|
if(select==i)
|
||||||
|
std::cout<<" * "<<i<<": "<<vf->name<<", "<<cs->name<<std::endl;
|
||||||
|
else
|
||||||
|
std::cout<<" "<<i<<": "<<vf->name<<", "<<cs->name<<std::endl;
|
||||||
|
|
||||||
|
++sf;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif//_DEBUG
|
#endif//_DEBUG
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -197,6 +220,46 @@ VkDevice VulkanDeviceCreater::CreateDevice(const uint32_t graphics_family)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VulkanDeviceCreater::ChooseSurfaceFormat()
|
||||||
|
{
|
||||||
|
uint32_t format_count;
|
||||||
|
|
||||||
|
if (vkGetPhysicalDeviceSurfaceFormatsKHR(*physical_device, surface, &format_count, nullptr) != VK_SUCCESS)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AutoDeleteArray<VkSurfaceFormatKHR> surface_formats_list(format_count);
|
||||||
|
|
||||||
|
if (vkGetPhysicalDeviceSurfaceFormatsKHR(*physical_device, surface, &format_count, surface_formats_list) == VK_SUCCESS)
|
||||||
|
{
|
||||||
|
int index=-1;
|
||||||
|
int result;
|
||||||
|
uint32_t sel=0;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<format_count;i++)
|
||||||
|
{
|
||||||
|
result=perfer_color_formats->Find(surface_formats_list[i].format);
|
||||||
|
|
||||||
|
if(result>index)
|
||||||
|
{
|
||||||
|
surface_format=surface_formats_list[i];
|
||||||
|
|
||||||
|
index=result;
|
||||||
|
sel=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
LogSurfaceFormat(surface_formats_list,format_count,sel);
|
||||||
|
#endif//_DEBUG
|
||||||
|
|
||||||
|
if(index!=-1)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
surface_format.format=PF_RGBA8s;
|
||||||
|
surface_format.colorSpace=VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
||||||
|
}
|
||||||
|
|
||||||
GPUDevice *VulkanDeviceCreater::CreateRenderDevice()
|
GPUDevice *VulkanDeviceCreater::CreateRenderDevice()
|
||||||
{
|
{
|
||||||
GPUDeviceAttribute *device_attr=new GPUDeviceAttribute(instance,physical_device,surface);
|
GPUDeviceAttribute *device_attr=new GPUDeviceAttribute(instance,physical_device,surface);
|
||||||
@ -209,6 +272,10 @@ GPUDevice *VulkanDeviceCreater::CreateRenderDevice()
|
|||||||
SetDeviceExtension(&ext_list,physical_device,require);
|
SetDeviceExtension(&ext_list,physical_device,require);
|
||||||
SetDeviceFeatures(&features,physical_device->GetFeatures10(),require);
|
SetDeviceFeatures(&features,physical_device->GetFeatures10(),require);
|
||||||
|
|
||||||
|
ChooseSurfaceFormat();
|
||||||
|
|
||||||
|
device_attr->surface_format=surface_format;
|
||||||
|
|
||||||
device_attr->device=CreateDevice(device_attr->graphics_family);
|
device_attr->device=CreateDevice(device_attr->graphics_family);
|
||||||
|
|
||||||
if(!device_attr->device)
|
if(!device_attr->device)
|
||||||
@ -322,7 +389,6 @@ GPUDevice *VulkanDeviceCreater::Create()
|
|||||||
OutputPhysicalDeviceCaps(physical_device);
|
OutputPhysicalDeviceCaps(physical_device);
|
||||||
#endif//_DEBUG
|
#endif//_DEBUG
|
||||||
|
|
||||||
|
|
||||||
if(!RequirementCheck())
|
if(!RequirementCheck())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
|
@ -136,12 +136,12 @@ Material *GPUDevice::CreateMaterial(const UTF8String &mtl_name,ShaderModuleMap *
|
|||||||
|
|
||||||
// 但只要我们限制一个MI数据不超过64/256字节,一次渲染不超过256种材质实例,就无需解决此问题。
|
// 但只要我们限制一个MI数据不超过64/256字节,一次渲染不超过256种材质实例,就无需解决此问题。
|
||||||
|
|
||||||
if(desc_manager->hasSet(DescriptorSetType::PerMaterial))
|
//if(desc_manager->hasSet(DescriptorSetType::PerMaterial))
|
||||||
{
|
//{
|
||||||
data->mi_size
|
// data->mi_size
|
||||||
data->mi_data=new uint8[data->mi_size*256];
|
// data->mi_data=new uint8[data->mi_size*256];
|
||||||
}
|
//}
|
||||||
else
|
//else
|
||||||
{
|
{
|
||||||
data->mi_size=0;
|
data->mi_size=0;
|
||||||
data->mi_data=nullptr;
|
data->mi_data=nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user