2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKPhysicalDevice.h>
|
2020-10-28 17:28:07 +08:00
|
|
|
|
#include<hgl/graph/VKInstance.h>
|
2019-04-13 21:44:26 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2020-10-21 12:39:22 +08:00
|
|
|
|
GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
2019-04-13 21:44:26 +08:00
|
|
|
|
{
|
|
|
|
|
instance=inst;
|
|
|
|
|
physical_device=pd;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
uint32_t property_count;
|
|
|
|
|
|
|
|
|
|
vkEnumerateDeviceLayerProperties(physical_device,&property_count,nullptr);
|
|
|
|
|
|
|
|
|
|
layer_properties.SetCount(property_count);
|
|
|
|
|
vkEnumerateDeviceLayerProperties(physical_device,&property_count,layer_properties.GetData());
|
|
|
|
|
|
2020-10-28 17:28:07 +08:00
|
|
|
|
debug_out("PhysicalDevice",layer_properties);
|
2019-04-13 21:44:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
uint32_t exten_count;
|
|
|
|
|
|
|
|
|
|
vkEnumerateDeviceExtensionProperties(physical_device,nullptr,&exten_count,nullptr);
|
|
|
|
|
|
|
|
|
|
extension_properties.SetCount(exten_count);
|
|
|
|
|
vkEnumerateDeviceExtensionProperties(physical_device,nullptr,&exten_count,extension_properties.GetData());
|
|
|
|
|
|
2020-10-28 17:28:07 +08:00
|
|
|
|
debug_out("PhysicalDevice",extension_properties);
|
2019-04-13 21:44:26 +08:00
|
|
|
|
}
|
2019-05-23 13:24:21 +08:00
|
|
|
|
|
|
|
|
|
vkGetPhysicalDeviceFeatures(physical_device,&features);
|
|
|
|
|
vkGetPhysicalDeviceMemoryProperties(physical_device,&memory_properties);
|
2020-10-28 17:28:07 +08:00
|
|
|
|
vkGetPhysicalDeviceProperties(physical_device,&properties);
|
|
|
|
|
}
|
2019-05-23 13:24:21 +08:00
|
|
|
|
|
2020-10-28 17:28:07 +08:00
|
|
|
|
const bool GPUPhysicalDevice::GetLayerVersion(const AnsiString &name,uint32_t &spec,uint32_t &impl)const
|
|
|
|
|
{
|
|
|
|
|
for(const VkLayerProperties &lp:layer_properties)
|
2019-05-23 13:24:21 +08:00
|
|
|
|
{
|
2020-10-28 17:28:07 +08:00
|
|
|
|
if(name.Comp(lp.layerName)==0)
|
|
|
|
|
{
|
|
|
|
|
spec=lp.specVersion;
|
|
|
|
|
impl=lp.implementationVersion;
|
2019-05-23 13:24:21 +08:00
|
|
|
|
|
2020-10-28 17:28:07 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
2019-05-23 13:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 17:28:07 +08:00
|
|
|
|
return(false);
|
2019-05-23 13:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 17:28:07 +08:00
|
|
|
|
const uint32_t GPUPhysicalDevice::GetExtensionVersion(const AnsiString &name)const
|
2019-05-23 13:24:21 +08:00
|
|
|
|
{
|
2020-10-28 17:28:07 +08:00
|
|
|
|
for(const VkExtensionProperties &ep:extension_properties)
|
2019-05-23 13:24:21 +08:00
|
|
|
|
{
|
2020-10-28 17:28:07 +08:00
|
|
|
|
if(name.Comp(ep.extensionName)==0)
|
|
|
|
|
return ep.specVersion;
|
2019-05-23 13:24:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2019-04-13 21:44:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 19:06:58 +08:00
|
|
|
|
const bool GPUPhysicalDevice::CheckExtensionSupport(const AnsiString &name)const
|
|
|
|
|
{
|
|
|
|
|
for(const VkExtensionProperties &ep:extension_properties)
|
|
|
|
|
{
|
|
|
|
|
if(name.Comp(ep.extensionName)==0)
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
const bool GPUPhysicalDevice::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex)const
|
2019-04-13 21:44:26 +08:00
|
|
|
|
{
|
|
|
|
|
// Search memtypes to find first index with those properties
|
|
|
|
|
for(uint32_t i=0; i<memory_properties.memoryTypeCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if((typeBits&1)==1)
|
|
|
|
|
{
|
|
|
|
|
// Type is available, does it match user properties?
|
2019-06-25 22:26:09 +08:00
|
|
|
|
if((memory_properties.memoryTypes[i].propertyFlags&properties)==properties)
|
2019-04-13 21:44:26 +08:00
|
|
|
|
{
|
|
|
|
|
*typeIndex=i;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
typeBits>>=1;
|
|
|
|
|
}
|
|
|
|
|
// No memory types matched, return failure
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-07-02 21:39:24 +08:00
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
VkFormat GPUPhysicalDevice::GetDepthFormat(bool lower_to_high)const
|
2019-06-19 16:54:41 +08:00
|
|
|
|
{
|
|
|
|
|
constexpr VkFormat depthFormats[] =
|
|
|
|
|
{
|
2021-06-24 19:25:43 +08:00
|
|
|
|
PF_D16UN,
|
|
|
|
|
PF_X8_D24UN,
|
|
|
|
|
PF_D16UN_S8U,
|
|
|
|
|
PF_D24UN_S8U,
|
|
|
|
|
PF_D32F,
|
|
|
|
|
PF_D32F_S8U
|
2019-06-19 16:54:41 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkFormat result=VK_FORMAT_UNDEFINED;
|
|
|
|
|
|
|
|
|
|
for (auto& format : depthFormats)
|
|
|
|
|
{
|
2019-07-02 21:52:27 +08:00
|
|
|
|
if(IsDepthAttachmentOptimal(format))
|
2019-06-19 16:54:41 +08:00
|
|
|
|
{
|
|
|
|
|
if(lower_to_high)
|
|
|
|
|
return format;
|
|
|
|
|
else
|
|
|
|
|
result=format;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:39:22 +08:00
|
|
|
|
VkFormat GPUPhysicalDevice::GetDepthStencilFormat(bool lower_to_high)const
|
2019-06-19 16:54:41 +08:00
|
|
|
|
{
|
|
|
|
|
constexpr VkFormat depthStencilFormats[] =
|
|
|
|
|
{
|
2021-06-24 19:25:43 +08:00
|
|
|
|
PF_D16UN_S8U,
|
|
|
|
|
PF_D24UN_S8U,
|
|
|
|
|
PF_D32F_S8U
|
2019-06-19 16:54:41 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkFormat result=VK_FORMAT_UNDEFINED;
|
|
|
|
|
|
|
|
|
|
for (auto& format : depthStencilFormats)
|
|
|
|
|
{
|
2019-07-02 21:52:27 +08:00
|
|
|
|
if(IsDepthAttachmentOptimal(format))
|
2019-06-19 16:54:41 +08:00
|
|
|
|
{
|
|
|
|
|
if(lower_to_high)
|
|
|
|
|
return format;
|
|
|
|
|
else
|
|
|
|
|
result=format;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2019-04-13 21:44:26 +08:00
|
|
|
|
VK_NAMESPACE_END
|