ULRE/inc/hgl/graph/VKPhysicalDevice.h

212 lines
11 KiB
C
Raw Normal View History

2019-05-28 21:17:18 +08:00
#pragma once
#include<hgl/graph/VK.h>
2020-09-05 17:54:21 +08:00
#include<hgl/type/String.h>
2024-11-21 01:30:42 +08:00
#include<hgl/type/SortedSet.h>
VK_NAMESPACE_BEGIN
class VulkanPhyDevice
{
VkInstance instance=nullptr;
VkPhysicalDevice physical_device=nullptr;
VkPhysicalDeviceFeatures features;
VkPhysicalDeviceVulkan11Features features11;
VkPhysicalDeviceVulkan12Features features12;
2022-02-15 16:03:27 +08:00
VkPhysicalDeviceVulkan13Features features13;
2025-01-25 01:40:08 +08:00
VkPhysicalDeviceVulkan14Features features14;
VkPhysicalDeviceProperties properties;
VkPhysicalDeviceVulkan11Properties properties11;
VkPhysicalDeviceVulkan12Properties properties12;
2022-02-15 16:03:27 +08:00
VkPhysicalDeviceVulkan13Properties properties13;
2025-01-25 01:40:08 +08:00
VkPhysicalDeviceVulkan14Properties properties14;
VkPhysicalDeviceMemoryProperties memory_properties;
ArrayList<VkLayerProperties> layer_properties;
ArrayList<VkExtensionProperties> extension_properties;
ArrayList<VkQueueFamilyProperties> queue_family_properties;
private:
2024-04-18 00:36:52 +08:00
bool support_u8_index=false;
bool dynamic_state=false;
2022-09-27 10:43:08 +08:00
public:
const VkPhysicalDeviceFeatures & GetFeatures10 ()const{return features;}
const VkPhysicalDeviceVulkan11Features &GetFeatures11 ()const{return features11;}
const VkPhysicalDeviceVulkan12Features &GetFeatures12 ()const{return features12;}
const VkPhysicalDeviceVulkan13Features &GetFeatures13 ()const{return features13;}
2025-01-25 01:40:08 +08:00
const VkPhysicalDeviceVulkan14Features &GetFeatures14 ()const{return features14;}
2022-09-27 10:43:08 +08:00
const VkPhysicalDeviceProperties & GetProperties ()const{return properties;}
const VkPhysicalDeviceMemoryProperties &GetMemoryProperties ()const{return memory_properties;}
const VkPhysicalDeviceLimits & GetLimits ()const{return properties.limits;}
public:
VulkanPhyDevice(VkInstance,VkPhysicalDevice);
~VulkanPhyDevice()=default;
2022-02-16 16:54:19 +08:00
operator VkPhysicalDevice() {return physical_device;}
operator const VkPhysicalDevice()const {return physical_device;}
2019-05-28 21:17:18 +08:00
const uint32_t GetVulkanVersion()const{return properties.apiVersion;}
2021-12-24 17:07:42 +08:00
const int GetMemoryType(uint32_t,VkMemoryPropertyFlags)const;
VkPhysicalDeviceType GetDeviceType()const{return properties.deviceType;}
const char * GetDeviceName()const{return properties.deviceName;}
2020-10-28 17:28:07 +08:00
const bool GetLayerVersion(const AnsiString &,uint32_t &spec,uint32_t &impl)const;
const uint32_t GetExtensionVersion(const AnsiString &name)const;
const bool CheckExtensionSupport(const AnsiString &name)const;
2021-03-25 20:00:19 +08:00
const uint32_t GetUBORange ()const{return properties.limits.maxUniformBufferRange;}
const VkDeviceSize GetUBOAlign ()const{return properties.limits.minUniformBufferOffsetAlignment;}
2021-03-25 20:00:19 +08:00
const uint32_t GetSSBORange ()const{return properties.limits.maxStorageBufferRange;}
const VkDeviceSize GetSSBOAlign ()const{return properties.limits.minStorageBufferOffsetAlignment;}
2025-01-25 01:40:08 +08:00
const uint32_t GetConstantSize ()const{return properties.limits.maxPushConstantsSize;}
const VkDeviceSize GetMaxBufferSize()const{return properties13.maxBufferSize;}
const uint32_t GetMaxPushDescriptors()const{return properties14.maxPushDescriptors;}
2019-05-28 21:17:18 +08:00
public:
/**
2019-05-28 21:17:18 +08:00
*
*/
const bool isGPU()const
{
if(properties.deviceType==VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)return(true);
if(properties.deviceType==VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)return(true);
if(properties.deviceType==VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU)return(true);
return(false);
}
2019-05-28 21:17:18 +08:00
const bool isDiscreteGPU ()const{return(properties.deviceType==VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU);} ///<是否是独立显卡
const bool isIntegratedGPU ()const{return(properties.deviceType==VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU);} ///<是否是集成显卡
const bool isVirtualGPU ()const{return(properties.deviceType==VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU);} ///<是否是虚拟显卡
2019-05-18 15:41:49 +08:00
2022-09-27 19:41:28 +08:00
#define HGL_VK_IS_BRAND(name) (hgl::stricmp(properties.deviceName,#name,sizeof(#name))==0)
const bool isMicrosoft ()const{return HGL_VK_IS_BRAND(Microsoft);}
const bool isMesa ()const{return HGL_VK_IS_BRAND(Mesa );}
const bool isAMD ()const{return HGL_VK_IS_BRAND(AMD )
2023-06-14 21:03:30 +08:00
||HGL_VK_IS_BRAND(ATI )
||HGL_VK_IS_BRAND(Radeon );}
const bool isNvidia ()const{return HGL_VK_IS_BRAND(nVidia )
||HGL_VK_IS_BRAND(GeForce )
||HGL_VK_IS_BRAND(Quadro )
||HGL_VK_IS_BRAND(TITAN )
||HGL_VK_IS_BRAND(Tegra );}
2022-09-27 19:41:28 +08:00
const bool isIntel ()const{return HGL_VK_IS_BRAND(Intel );}
const bool isQualcomm ()const{return HGL_VK_IS_BRAND(Adreno );}
const bool isApple ()const{return HGL_VK_IS_BRAND(Apple );}
const bool isImgTec ()const{return HGL_VK_IS_BRAND(ImgTec )
||HGL_VK_IS_BRAND(PowerVR );}
const bool isARM ()const{return HGL_VK_IS_BRAND(Arm )
||HGL_VK_IS_BRAND(Mali );}
#undef HGL_VK_IS_BRAND
2019-05-18 15:41:49 +08:00
public:
VkFormatProperties GetFormatProperties(const VkFormat format)const
{
VkFormatProperties fp;
hgl_zero(fp);
2019-05-18 15:41:49 +08:00
vkGetPhysicalDeviceFormatProperties(physical_device,format,&fp);
return fp;
}
2019-07-02 21:52:27 +08:00
bool OptimalSupport (const VkFormat format,const VkFormatFeatureFlags flag)const{VkFormatProperties fp;vkGetPhysicalDeviceFormatProperties(physical_device,format,&fp);return fp.optimalTilingFeatures&flag;}
bool LinearSupport (const VkFormat format,const VkFormatFeatureFlags flag)const{VkFormatProperties fp;vkGetPhysicalDeviceFormatProperties(physical_device,format,&fp);return fp.linearTilingFeatures&flag;}
bool BufferSupport (const VkFormat format,const VkFormatFeatureFlags flag)const{VkFormatProperties fp;vkGetPhysicalDeviceFormatProperties(physical_device,format,&fp);return fp.bufferFeatures&flag;}
2019-07-02 21:59:27 +08:00
bool IsColorAttachmentOptimal(const VkFormat format)const{return OptimalSupport(format,VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);}
bool IsDepthAttachmentOptimal(const VkFormat format)const{return OptimalSupport(format,VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);}
2019-07-05 19:56:15 +08:00
bool IsColorAttachmentLinear(const VkFormat format)const{return LinearSupport(format,VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);}
bool IsDepthAttachmentLinear(const VkFormat format)const{return LinearSupport(format,VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);}
VkFormat GetDepthFormat(bool lower_to_high=false)const;
VkFormat GetDepthStencilFormat(bool lower_to_high=false)const;
const bool IsUBOTexelSupport (const VkFormat format)const{return BufferSupport(format,VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT);}
const bool IsSTBSupport (const VkFormat format)const{return BufferSupport(format,VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT);}
const bool IsSTBAtomicSupport (const VkFormat format)const{return BufferSupport(format,VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT);}
const bool IsVBOSupport (const VkFormat format)const{return BufferSupport(format,VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT);}
2020-06-21 02:23:11 +08:00
public:
const VkBool32 SupportGeometryShader ()const{return features.geometryShader;}
2024-04-18 00:36:52 +08:00
const VkBool32 SupportTessellationShader ()const{return features.tessellationShader;}
const VkBool32 SupportCubeMapArray ()const{return features.imageCubeArray;}
2024-04-18 00:36:52 +08:00
const VkBool32 SupportU32Index ()const{return features.fullDrawIndexUint32;}
const VkBool32 SupportU8Index ()const{return support_u8_index;}
// support != open, so please don't direct use GetFeatures().
// open any features in CreateDevice()&SetDeviceFeatures() functions.
2022-09-27 10:43:08 +08:00
const bool SupportMDI ()const
{
// the device is supported MDI, but MaxDrawIndirectCount is 1.
return (features.multiDrawIndirect&&properties.limits.maxDrawIndirectCount>1);
}
2022-09-27 10:43:08 +08:00
const uint32_t GetMaxMDICount ()const
{
return properties.limits.maxDrawIndirectCount;
}
2022-09-27 10:43:08 +08:00
const uint32_t GetMaxImage1D ()const{return properties.limits.maxImageDimension1D;}
const uint32_t GetMaxImage2D ()const{return properties.limits.maxImageDimension2D;}
const uint32_t GetMaxImage3D ()const{return properties.limits.maxImageDimension3D;}
const uint32_t GetMaxImageCube ()const{return properties.limits.maxImageDimensionCube;}
const uint32_t GetMaxImageArrayLayers ()const{return properties.limits.maxImageArrayLayers;}
const uint32_t GetMaxBoundDescriptorSets ()const{return properties.limits.maxBoundDescriptorSets;}
2020-10-24 21:50:36 +08:00
const uint32_t GetMaxVertexInputAttributes ()const{return properties.limits.maxVertexInputAttributes;}
const uint32_t GetMaxVertexInputBindings ()const{return properties.limits.maxVertexInputBindings;}
2020-10-24 21:50:36 +08:00
const uint32_t GetMaxColorAttachments ()const{return properties.limits.maxColorAttachments;}
2020-10-24 21:50:36 +08:00
const VkBool32 SupportSamplerAnisotropy ()const{return features.samplerAnisotropy;}
const float GetMaxSamplerAnisotropy ()const{return properties.limits.maxSamplerAnisotropy;}
const float GetMaxSamplerLodBias ()const{return properties.limits.maxSamplerLodBias;}
2020-06-20 19:40:09 +08:00
const VkBool32 SupportYcbcrConversion ()const{return features11.samplerYcbcrConversion;}
const VkBool32 SupportClampMirrorToEdge ()const{return features12.samplerMirrorClampToEdge;}
2025-01-25 01:40:08 +08:00
const VkBool32 SupportSmoothLines ()const{return features14.smoothLines;}
const VkBool32 SupportStippledSmoothLines ()const{return features14.stippledSmoothLines;}
const void GetPointSize(float &granularity,float &min_size,float &max_size) const
2020-06-21 02:23:11 +08:00
{
granularity =properties.limits.pointSizeGranularity;
min_size =properties.limits.pointSizeRange[0];
max_size =properties.limits.pointSizeRange[1];
2020-06-21 02:23:11 +08:00
}
2020-06-20 19:40:09 +08:00
const void GetLineWidth(float &granularity,float &min_width,float &max_width) const
2020-06-21 02:23:11 +08:00
{
granularity =properties.limits.lineWidthGranularity;
min_width =properties.limits.lineWidthRange[0];
max_width =properties.limits.lineWidthRange[1];
}
const bool SupportDynamicState() const {return dynamic_state;}
};//class VulkanPhyDevice
2019-07-02 21:59:27 +08:00
VK_NAMESPACE_END