ULRE/src/SceneGraph/Vulkan/VKPhysicalDevice.cpp

136 lines
3.3 KiB
C++
Raw Normal View History

#include<hgl/graph/VKPhysicalDevice.h>
2020-10-28 17:28:07 +08:00
#include<hgl/graph/VKInstance.h>
VK_NAMESPACE_BEGIN
2020-10-21 12:39:22 +08:00
GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
{
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);
}
{
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);
}
vkGetPhysicalDeviceFeatures(physical_device,&features);
vkGetPhysicalDeviceMemoryProperties(physical_device,&memory_properties);
2020-10-28 17:28:07 +08:00
vkGetPhysicalDeviceProperties(physical_device,&properties);
}
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)
{
2020-10-28 17:28:07 +08:00
if(name.Comp(lp.layerName)==0)
{
spec=lp.specVersion;
impl=lp.implementationVersion;
2020-10-28 17:28:07 +08:00
return(true);
}
}
2020-10-28 17:28:07 +08:00
return(false);
}
2020-10-28 17:28:07 +08:00
const uint32_t GPUPhysicalDevice::GetExtensionVersion(const AnsiString &name)const
{
2020-10-28 17:28:07 +08:00
for(const VkExtensionProperties &ep:extension_properties)
{
2020-10-28 17:28:07 +08:00
if(name.Comp(ep.extensionName)==0)
return ep.specVersion;
}
return 0;
}
2020-10-21 12:39:22 +08:00
const bool GPUPhysicalDevice::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex)const
{
// 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?
if((memory_properties.memoryTypes[i].propertyFlags&properties)==properties)
{
*typeIndex=i;
return true;
}
}
typeBits>>=1;
}
// No memory types matched, return failure
return false;
}
2020-10-21 12:39:22 +08:00
VkFormat GPUPhysicalDevice::GetDepthFormat(bool lower_to_high)const
{
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
};
VkFormat result=VK_FORMAT_UNDEFINED;
for (auto& format : depthFormats)
{
2019-07-02 21:52:27 +08:00
if(IsDepthAttachmentOptimal(format))
{
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
{
constexpr VkFormat depthStencilFormats[] =
{
2021-06-24 19:25:43 +08:00
PF_D16UN_S8U,
PF_D24UN_S8U,
PF_D32F_S8U
};
VkFormat result=VK_FORMAT_UNDEFINED;
for (auto& format : depthStencilFormats)
{
2019-07-02 21:52:27 +08:00
if(IsDepthAttachmentOptimal(format))
{
if(lower_to_high)
return format;
else
result=format;
}
}
return result;
}
VK_NAMESPACE_END