improve a few codes.

This commit is contained in:
hyzboy 2021-09-23 22:13:57 +08:00
parent 66c6072de4
commit b222c52cc2
6 changed files with 38 additions and 32 deletions

View File

@ -56,7 +56,7 @@ private:
private: private:
friend GPUDevice *CreateRenderDevice(VkInstance inst,const GPUPhysicalDevice *physical_device,VkSurfaceKHR surface,const VkExtent2D &extent); friend GPUDevice *CreateRenderDevice(VulkanInstance *inst,const GPUPhysicalDevice *physical_device,VkSurfaceKHR surface,const VkExtent2D &extent);
GPUDevice(GPUDeviceAttribute *da); GPUDevice(GPUDeviceAttribute *da);
@ -95,14 +95,6 @@ public:
return Resize(extent); return Resize(extent);
} }
public: //
template<typename T>
T *GetProc(const char *name)
{
return reinterpret_cast<T>(vkGetDeviceProcAddr(attr->device,name));
}
public: //内存相关 public: //内存相关
GPUMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties); GPUMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties);

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include<hgl/graph/VKInstance.h>
#include<hgl/graph/VKTexture.h> #include<hgl/graph/VKTexture.h>
VK_NAMESPACE_BEGIN VK_NAMESPACE_BEGIN
@ -8,7 +9,7 @@ constexpr uint32_t ERROR_FAMILY_INDEX=UINT32_MAX;
struct GPUDeviceAttribute struct GPUDeviceAttribute
{ {
VkInstance instance =VK_NULL_HANDLE; VulkanInstance * instance =nullptr;
const GPUPhysicalDevice * physical_device =nullptr; const GPUPhysicalDevice * physical_device =nullptr;
VkPhysicalDeviceDriverPropertiesKHR driver_properties; VkPhysicalDeviceDriverPropertiesKHR driver_properties;
@ -41,11 +42,19 @@ struct GPUDeviceAttribute
public: public:
GPUDeviceAttribute(VkInstance inst,const GPUPhysicalDevice *pd,VkSurfaceKHR s); GPUDeviceAttribute(VulkanInstance *inst,const GPUPhysicalDevice *pd,VkSurfaceKHR s);
~GPUDeviceAttribute(); ~GPUDeviceAttribute();
bool CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex) const; bool CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex) const;
void Refresh(); void Refresh();
public:
template<typename T>
T *GetDeviceProc(const char *name)
{
return instance->GetDeviceProc<T>(device,name);
}
};//class GPUDeviceAttribute };//class GPUDeviceAttribute
VK_NAMESPACE_END VK_NAMESPACE_END

View File

@ -57,6 +57,10 @@ VK_NAMESPACE_BEGIN
ObjectList<GPUPhysicalDevice> physical_devices; ObjectList<GPUPhysicalDevice> physical_devices;
private:
PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
private: private:
friend VulkanInstance *CreateInstance(const AnsiString &app_name,VKDebugOut *out=nullptr,CreateInstanceLayerInfo *cili=nullptr); friend VulkanInstance *CreateInstance(const AnsiString &app_name,VKDebugOut *out=nullptr,CreateInstanceLayerInfo *cili=nullptr);
@ -77,6 +81,16 @@ VK_NAMESPACE_BEGIN
{ {
return reinterpret_cast<T>(vkGetInstanceProcAddr(inst,name)); return reinterpret_cast<T>(vkGetInstanceProcAddr(inst,name));
} }
template<typename T>
T *GetDeviceProc(const char *name)
{
if(!GetDeviceProcAddr)return(nullptr);
return reinterpret_cast<T>(GetDeviceProcAddr(name));
}
void DestroySurface(VkSurfaceKHR);
};//class VulkanInstance };//class VulkanInstance
void InitVulkanInstanceProperties(); void InitVulkanInstanceProperties();

View File

@ -5,25 +5,9 @@
#include<iostream> #include<iostream>
VK_NAMESPACE_BEGIN VK_NAMESPACE_BEGIN
namespace
{
PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR vkGetPhysicalDeviceSurfaceCapabilities2KHR = NULL;
PFN_vkGetPhysicalDeviceSurfaceFormats2KHR vkGetPhysicalDeviceSurfaceFormats2KHR = NULL;
PFN_vkSetHdrMetadataEXT vkSetHdrMetadataEXT = NULL;
PFN_vkAcquireFullScreenExclusiveModeEXT vkAcquireFullScreenExclusiveModeEXT = NULL;
PFN_vkReleaseFullScreenExclusiveModeEXT vkReleaseFullScreenExclusiveModeEXT = NULL;
}
bool InitPhysicsDeviceSurfaceAPI2()
{
return(false);
}
void SavePipelineCacheData(VkDevice device,VkPipelineCache cache,const VkPhysicalDeviceProperties &pdp); void SavePipelineCacheData(VkDevice device,VkPipelineCache cache,const VkPhysicalDeviceProperties &pdp);
GPUDeviceAttribute::GPUDeviceAttribute(VkInstance inst,const GPUPhysicalDevice *pd,VkSurfaceKHR s) GPUDeviceAttribute::GPUDeviceAttribute(VulkanInstance *inst,const GPUPhysicalDevice *pd,VkSurfaceKHR s)
{ {
instance=inst; instance=inst;
physical_device=pd; physical_device=pd;
@ -50,7 +34,7 @@ GPUDeviceAttribute::~GPUDeviceAttribute()
vkDestroyDevice(device,nullptr); vkDestroyDevice(device,nullptr);
if(surface) if(surface)
vkDestroySurfaceKHR(instance,surface,nullptr); instance->DestroySurface(surface);
} }
bool GPUDeviceAttribute::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex) const bool GPUDeviceAttribute::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex) const

View File

@ -371,7 +371,7 @@ namespace
constexpr size_t VK_DRIVER_ID_RANGE_SIZE=VK_DRIVER_ID_END_RANGE-VK_DRIVER_ID_BEGIN_RANGE+1; constexpr size_t VK_DRIVER_ID_RANGE_SIZE=VK_DRIVER_ID_END_RANGE-VK_DRIVER_ID_BEGIN_RANGE+1;
#endif//VK_DRIVER_ID_RANGE_SIZE #endif//VK_DRIVER_ID_RANGE_SIZE
GPUDevice *CreateRenderDevice(VkInstance inst,const GPUPhysicalDevice *physical_device,VkSurfaceKHR surface,const VkExtent2D &extent) GPUDevice *CreateRenderDevice(VulkanInstance *inst,const GPUPhysicalDevice *physical_device,VkSurfaceKHR surface,const VkExtent2D &extent)
{ {
#ifdef _DEBUG #ifdef _DEBUG
{ {
@ -387,7 +387,7 @@ GPUDevice *CreateRenderDevice(VkInstance inst,const GPUPhysicalDevice *physical_
if(device_attr->graphics_family==ERROR_FAMILY_INDEX) if(device_attr->graphics_family==ERROR_FAMILY_INDEX)
return(nullptr); return(nullptr);
device_attr->device=CreateDevice(inst,physical_device,device_attr->graphics_family); device_attr->device=CreateDevice(*inst,physical_device,device_attr->graphics_family);
if(!device_attr->device) if(!device_attr->device)
return(nullptr); return(nullptr);
@ -436,7 +436,7 @@ GPUDevice *CreateRenderDevice(VulkanInstance *inst,Window *win,const GPUPhysical
extent.width=win->GetWidth(); extent.width=win->GetWidth();
extent.height=win->GetHeight(); extent.height=win->GetHeight();
GPUDevice *device=CreateRenderDevice(*inst,pd,surface,extent); GPUDevice *device=CreateRenderDevice(inst,pd,surface,extent);
if(!device) if(!device)
{ {

View File

@ -87,6 +87,8 @@ VulkanInstance::VulkanInstance(VkInstance i,VKDebugOut *out)
delete[] pd_list; delete[] pd_list;
} }
GetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)vkGetInstanceProcAddr(inst, "vkGetDeviceProcAddr");
} }
VulkanInstance::~VulkanInstance() VulkanInstance::~VulkanInstance()
@ -105,4 +107,9 @@ const GPUPhysicalDevice *VulkanInstance::GetDevice(VkPhysicalDeviceType type)con
return(nullptr); return(nullptr);
} }
void VulkanInstance::DestroySurface(VkSurfaceKHR surface)
{
vkDestroySurfaceKHR(inst,surface,nullptr);
}
VK_NAMESPACE_END VK_NAMESPACE_END