fix chaos of Layer and extension
This commit is contained in:
parent
2e05e06b3f
commit
12b66c3e64
@ -52,8 +52,8 @@ private:
|
||||
|
||||
struct
|
||||
{
|
||||
RenderTarget *rt;
|
||||
RenderCommand *cmd;
|
||||
RenderTarget *rt=nullptr;
|
||||
RenderCommand *cmd=nullptr;
|
||||
|
||||
public:
|
||||
|
||||
@ -100,8 +100,8 @@ public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
delete gbuffer.cmd;
|
||||
delete gbuffer.rt;
|
||||
SAFE_CLEAR(gbuffer.cmd);
|
||||
SAFE_CLEAR(gbuffer.rt);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -88,7 +88,7 @@ public:
|
||||
|
||||
InitNativeWindowSystem();
|
||||
|
||||
InitVulkanProperties();
|
||||
InitVulkanInstanceProperties();
|
||||
|
||||
win=CreateRenderWindow(OS_TEXT("VulkanTest"));
|
||||
if(!win)
|
||||
|
@ -153,7 +153,14 @@ inline void copy(VkExtent3D &e3d,const VkExtent2D &e2d,const uint32 depth=1)
|
||||
e3d.depth =depth;
|
||||
}
|
||||
|
||||
inline void debug_out(const hgl::List<VkLayerProperties> &layer_properties)
|
||||
inline void debug_out_vk_version(const uint32_t version)
|
||||
{
|
||||
std::cout<<VK_VERSION_MAJOR(version)<<"."
|
||||
<<VK_VERSION_MINOR(version)<<"."
|
||||
<<VK_VERSION_PATCH(version);
|
||||
}
|
||||
|
||||
inline void debug_out(const char *front,const hgl::List<VkLayerProperties> &layer_properties)
|
||||
{
|
||||
const int property_count=layer_properties.GetCount();
|
||||
|
||||
@ -163,12 +170,18 @@ inline void debug_out(const hgl::List<VkLayerProperties> &layer_properties)
|
||||
|
||||
for(int i=0;i<property_count;i++)
|
||||
{
|
||||
std::cout<<"Layer Propertyes ["<<i<<"] : "<<lp->layerName<<" desc: "<<lp->description<<std::endl;
|
||||
std::cout<<front<<" Layer Propertyes ["<<i<<"] : "<<lp->layerName<<" [spec: ";
|
||||
debug_out_vk_version(lp->specVersion);
|
||||
|
||||
std::cout<<", impl: ";
|
||||
debug_out_vk_version(lp->implementationVersion);
|
||||
|
||||
std::cout<<"] desc: "<<lp->description<<std::endl;
|
||||
++lp;
|
||||
}
|
||||
}
|
||||
|
||||
inline void debug_out(const hgl::List<VkExtensionProperties> &extension_properties)
|
||||
inline void debug_out(const char *front,const hgl::List<VkExtensionProperties> &extension_properties)
|
||||
{
|
||||
const int extension_count=extension_properties.GetCount();
|
||||
|
||||
@ -177,7 +190,11 @@ inline void debug_out(const hgl::List<VkExtensionProperties> &extension_properti
|
||||
VkExtensionProperties *ep=extension_properties.GetData();
|
||||
for(int i=0;i<extension_count;i++)
|
||||
{
|
||||
std::cout<<"Extension Propertyes ["<<i<<"] : "<<ep->extensionName<<" ver: "<<ep->specVersion<<std::endl;
|
||||
std::cout<<front<<" Extension Propertyes ["<<i<<"] : "<<ep->extensionName<<" ver: ";
|
||||
|
||||
debug_out_vk_version(ep->specVersion);
|
||||
|
||||
std::cout<<std::endl;
|
||||
++ep;
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +84,14 @@ public:
|
||||
return Resize(extent);
|
||||
}
|
||||
|
||||
public: //
|
||||
|
||||
template<typename T>
|
||||
T *GetProc(const char *name)
|
||||
{
|
||||
return reinterpret_cast<T>(vkGetDeviceProcAddr(attr->device,name));
|
||||
}
|
||||
|
||||
public: //内存相关
|
||||
|
||||
GPUMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties);
|
||||
|
@ -11,6 +11,8 @@ struct GPUDeviceAttribute
|
||||
VkInstance instance =VK_NULL_HANDLE;
|
||||
const GPUPhysicalDevice * physical_device =nullptr;
|
||||
|
||||
VkPhysicalDeviceDriverPropertiesKHR driver_properties;
|
||||
|
||||
VkSurfaceKHR surface =VK_NULL_HANDLE;
|
||||
VkSurfaceCapabilitiesKHR surface_caps;
|
||||
|
||||
|
@ -71,12 +71,20 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
const ObjectList<GPUPhysicalDevice> &GetDeviceList ()const {return physical_devices;}
|
||||
const GPUPhysicalDevice * GetDevice (VkPhysicalDeviceType)const;
|
||||
|
||||
template<typename T>
|
||||
T *GetInstanceProc(const char *name)
|
||||
{
|
||||
return reinterpret_cast<T>(vkGetInstanceProcAddr(inst,name));
|
||||
}
|
||||
};//class VulkanInstance
|
||||
|
||||
void InitVulkanProperties();
|
||||
const List<VkLayerProperties> & GetLayerProperties();
|
||||
const List<VkExtensionProperties> & GetExtensionProperties();
|
||||
const bool CheckLayerSupport(const char *);
|
||||
void InitVulkanInstanceProperties();
|
||||
const List<VkLayerProperties> & GetInstanceLayerProperties();
|
||||
const List<VkExtensionProperties> & GetInstanceExtensionProperties();
|
||||
const bool CheckInstanceLayerSupport(const AnsiString &);
|
||||
const bool GetInstanceLayerVersion(const AnsiString &,uint32_t &spec,uint32_t &impl);
|
||||
const bool CheckInstanceExtensionSupport(const AnsiString &);
|
||||
|
||||
VulkanInstance *CreateInstance(const AnsiString &,VKDebugOut *,CreateInstanceLayerInfo *); ///<创建一个Vulkan实例
|
||||
VK_NAMESPACE_END
|
||||
|
@ -11,7 +11,6 @@ class GPUPhysicalDevice
|
||||
VkPhysicalDevice physical_device=nullptr;
|
||||
VkPhysicalDeviceFeatures features;
|
||||
VkPhysicalDeviceProperties properties;
|
||||
VkPhysicalDeviceDriverPropertiesKHR driver_properties;
|
||||
VkPhysicalDeviceMemoryProperties memory_properties;
|
||||
List<VkLayerProperties> layer_properties;
|
||||
List<VkExtensionProperties> extension_properties;
|
||||
@ -33,11 +32,8 @@ public:
|
||||
const VkPhysicalDeviceProperties & GetProperties ()const{return properties;}
|
||||
const VkPhysicalDeviceMemoryProperties &GetMemoryProperties ()const{return memory_properties;}
|
||||
|
||||
const uint32_t GetExtensionSpecVersion(const AnsiString &name)const;
|
||||
|
||||
const VkDriverIdKHR GetDriverId ()const{return driver_properties.driverID;}
|
||||
const char * GetDriverName ()const{return driver_properties.driverName;}
|
||||
const char * GetDriverInfo ()const{return driver_properties.driverInfo;}
|
||||
const bool GetLayerVersion(const AnsiString &,uint32_t &spec,uint32_t &impl)const;
|
||||
const uint32_t GetExtensionVersion(const AnsiString &name)const;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -378,20 +378,6 @@ GPUDevice *CreateRenderDevice(VkInstance inst,const GPUPhysicalDevice *physical_
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
{
|
||||
const VkDriverIdKHR driver_id=physical_device->GetDriverId();
|
||||
|
||||
if(driver_id>=VK_DRIVER_ID_BEGIN_RANGE
|
||||
&&driver_id<=VK_DRIVER_ID_END_RANGE)
|
||||
{
|
||||
std::cout<<"DriverID: "<<physical_device->GetDriverId()<<std::endl;
|
||||
std::cout<<"DriverName: "<<physical_device->GetDriverName()<<std::endl;
|
||||
std::cout<<"DriverInfo: "<<physical_device->GetDriverInfo()<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"Unknow VideoCard Driver"<<std::endl;
|
||||
}
|
||||
|
||||
DebugOut(physical_device->GetProperties());
|
||||
DebugOut(physical_device->GetFeatures());
|
||||
}
|
||||
|
@ -86,16 +86,9 @@ VulkanInstance::~VulkanInstance()
|
||||
|
||||
const GPUPhysicalDevice *VulkanInstance::GetDevice(VkPhysicalDeviceType type)const
|
||||
{
|
||||
const uint32_t count=physical_devices.GetCount();
|
||||
GPUPhysicalDevice **pd=physical_devices.GetData();
|
||||
|
||||
for(uint32_t i=0;i<count;i++)
|
||||
{
|
||||
if((*pd)->GetDeviceType()==type)
|
||||
return(*pd);
|
||||
|
||||
++pd;
|
||||
}
|
||||
for(GPUPhysicalDevice *pd:physical_devices)
|
||||
if(pd->GetDeviceType()==type)
|
||||
return(pd);
|
||||
|
||||
return(nullptr);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/VKInstance.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
||||
@ -14,7 +15,7 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
||||
layer_properties.SetCount(property_count);
|
||||
vkEnumerateDeviceLayerProperties(physical_device,&property_count,layer_properties.GetData());
|
||||
|
||||
debug_out(layer_properties);
|
||||
debug_out("PhysicalDevice",layer_properties);
|
||||
}
|
||||
|
||||
{
|
||||
@ -25,48 +26,36 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
||||
extension_properties.SetCount(exten_count);
|
||||
vkEnumerateDeviceExtensionProperties(physical_device,nullptr,&exten_count,extension_properties.GetData());
|
||||
|
||||
debug_out(extension_properties);
|
||||
debug_out("PhysicalDevice",extension_properties);
|
||||
}
|
||||
|
||||
vkGetPhysicalDeviceFeatures(physical_device,&features);
|
||||
vkGetPhysicalDeviceMemoryProperties(physical_device,&memory_properties);
|
||||
|
||||
PFN_vkGetPhysicalDeviceProperties2 GetGPUPhysicalDeviceProperties2=nullptr;
|
||||
|
||||
if(GetExtensionSpecVersion(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME))
|
||||
GetGPUPhysicalDeviceProperties2=(PFN_vkGetPhysicalDeviceProperties2KHR)vkGetInstanceProcAddr(instance,"vkGetPhysicalDeviceProperties2KHR");
|
||||
|
||||
if(!GetGPUPhysicalDeviceProperties2)
|
||||
if(GetExtensionSpecVersion(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME))
|
||||
GetGPUPhysicalDeviceProperties2=(PFN_vkGetPhysicalDeviceProperties2)vkGetInstanceProcAddr(instance,"vkGetPhysicalDeviceProperties2");
|
||||
|
||||
if(GetGPUPhysicalDeviceProperties2)
|
||||
{
|
||||
VkPhysicalDeviceProperties2KHR properties2;
|
||||
GetGPUPhysicalDeviceProperties2(physical_device,&properties2);
|
||||
|
||||
hgl_cpy(properties,properties2.properties);
|
||||
|
||||
if(properties2.pNext)
|
||||
memcpy(&driver_properties,properties2.pNext,sizeof(VkPhysicalDeviceDriverPropertiesKHR));
|
||||
}
|
||||
else
|
||||
{
|
||||
vkGetPhysicalDeviceProperties(physical_device,&properties);
|
||||
|
||||
hgl_zero(driver_properties);
|
||||
}
|
||||
}
|
||||
|
||||
const uint32_t GPUPhysicalDevice::GetExtensionSpecVersion(const AnsiString &name)const
|
||||
const bool GPUPhysicalDevice::GetLayerVersion(const AnsiString &name,uint32_t &spec,uint32_t &impl)const
|
||||
{
|
||||
const uint count=extension_properties.GetCount();
|
||||
const VkExtensionProperties *ep=extension_properties.GetData();
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
for(const VkLayerProperties &lp:layer_properties)
|
||||
{
|
||||
if(name.Comp(ep->extensionName)==0)
|
||||
return ep->specVersion;
|
||||
if(name.Comp(lp.layerName)==0)
|
||||
{
|
||||
spec=lp.specVersion;
|
||||
impl=lp.implementationVersion;
|
||||
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
const uint32_t GPUPhysicalDevice::GetExtensionVersion(const AnsiString &name)const
|
||||
{
|
||||
for(const VkExtensionProperties &ep:extension_properties)
|
||||
{
|
||||
if(name.Comp(ep.extensionName)==0)
|
||||
return ep.specVersion;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -12,7 +12,7 @@ namespace
|
||||
const List<VkLayerProperties> &GetLayerProperties(){return layer_properties;}
|
||||
const List<VkExtensionProperties> &GetExtensionProperties(){return extension_properties;}
|
||||
|
||||
void InitVulkanProperties()
|
||||
void InitVulkanInstanceProperties()
|
||||
{
|
||||
layer_properties.Clear();
|
||||
extension_properties.Clear();
|
||||
@ -24,7 +24,7 @@ void InitVulkanProperties()
|
||||
layer_properties.SetCount(layer_count);
|
||||
vkEnumerateInstanceLayerProperties(&layer_count,layer_properties.GetData());
|
||||
|
||||
debug_out(layer_properties);
|
||||
debug_out("Instance",layer_properties);
|
||||
}
|
||||
|
||||
{
|
||||
@ -34,24 +34,33 @@ void InitVulkanProperties()
|
||||
extension_properties.SetCount(prop_count);
|
||||
vkEnumerateInstanceExtensionProperties(nullptr,&prop_count,extension_properties.GetData());
|
||||
|
||||
debug_out(extension_properties);
|
||||
debug_out("Instance",extension_properties);
|
||||
}
|
||||
}
|
||||
|
||||
const bool CheckLayerSupport(const char *layer_name)
|
||||
const bool CheckInstanceLayerSupport(const AnsiString &layer_name)
|
||||
{
|
||||
if(!layer_name||!*layer_name)
|
||||
return(false);
|
||||
|
||||
const uint32_t count=layer_properties.GetCount();
|
||||
VkLayerProperties *lp=layer_properties.GetData();
|
||||
|
||||
for(uint32_t i=0;i<count;i++)
|
||||
{
|
||||
if(strcmp(layer_name,lp->layerName)==0)
|
||||
for(const VkLayerProperties &lp:layer_properties)
|
||||
if(layer_name.Comp(lp.layerName)==0)
|
||||
return(true);
|
||||
|
||||
++lp;
|
||||
return(false);
|
||||
}
|
||||
|
||||
const bool GetInstanceLayerVersion(const AnsiString &name,uint32_t &spec,uint32_t &impl)
|
||||
{
|
||||
for(const VkLayerProperties &lp:layer_properties)
|
||||
{
|
||||
if(name.Comp(lp.layerName)==0)
|
||||
{
|
||||
spec=lp.specVersion;
|
||||
impl=lp.implementationVersion;
|
||||
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
|
||||
return(false);
|
||||
@ -61,7 +70,7 @@ void CheckInstanceLayer(CharPointerList &layer_list,CreateInstanceLayerInfo *lay
|
||||
{
|
||||
#define VK_LAYER_CHECK(sname,lname,name) if(layer_info->sname.name) \
|
||||
{ \
|
||||
if(CheckLayerSupport("VK_LAYER_" lname "_" #name)) \
|
||||
if(CheckInstanceLayerSupport("VK_LAYER_" lname "_" #name)) \
|
||||
layer_list.Add("VK_LAYER_" lname "_" #name); \
|
||||
}
|
||||
|
||||
@ -95,4 +104,15 @@ void CheckInstanceLayer(CharPointerList &layer_list,CreateInstanceLayerInfo *lay
|
||||
|
||||
VK_LAYER_BANDICAM_ADD(helper)
|
||||
}
|
||||
|
||||
const bool CheckInstanceExtensionSupport(const AnsiString &name)
|
||||
{
|
||||
for(const VkExtensionProperties &ep:extension_properties)
|
||||
{
|
||||
if(name.Comp(ep.extensionName)==0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user