improve a few codes.
This commit is contained in:
parent
66c6072de4
commit
b222c52cc2
@ -56,7 +56,7 @@ 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);
|
||||
|
||||
@ -95,14 +95,6 @@ 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);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKInstance.h>
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
@ -8,7 +9,7 @@ constexpr uint32_t ERROR_FAMILY_INDEX=UINT32_MAX;
|
||||
|
||||
struct GPUDeviceAttribute
|
||||
{
|
||||
VkInstance instance =VK_NULL_HANDLE;
|
||||
VulkanInstance * instance =nullptr;
|
||||
const GPUPhysicalDevice * physical_device =nullptr;
|
||||
|
||||
VkPhysicalDeviceDriverPropertiesKHR driver_properties;
|
||||
@ -41,11 +42,19 @@ struct GPUDeviceAttribute
|
||||
|
||||
public:
|
||||
|
||||
GPUDeviceAttribute(VkInstance inst,const GPUPhysicalDevice *pd,VkSurfaceKHR s);
|
||||
GPUDeviceAttribute(VulkanInstance *inst,const GPUPhysicalDevice *pd,VkSurfaceKHR s);
|
||||
~GPUDeviceAttribute();
|
||||
|
||||
bool CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex) const;
|
||||
|
||||
void Refresh();
|
||||
|
||||
public:
|
||||
|
||||
template<typename T>
|
||||
T *GetDeviceProc(const char *name)
|
||||
{
|
||||
return instance->GetDeviceProc<T>(device,name);
|
||||
}
|
||||
};//class GPUDeviceAttribute
|
||||
VK_NAMESPACE_END
|
||||
|
@ -57,6 +57,10 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
ObjectList<GPUPhysicalDevice> physical_devices;
|
||||
|
||||
private:
|
||||
|
||||
PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
|
||||
|
||||
private:
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *GetDeviceProc(const char *name)
|
||||
{
|
||||
if(!GetDeviceProcAddr)return(nullptr);
|
||||
|
||||
return reinterpret_cast<T>(GetDeviceProcAddr(name));
|
||||
}
|
||||
|
||||
void DestroySurface(VkSurfaceKHR);
|
||||
};//class VulkanInstance
|
||||
|
||||
void InitVulkanInstanceProperties();
|
||||
|
@ -5,25 +5,9 @@
|
||||
#include<iostream>
|
||||
|
||||
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);
|
||||
|
||||
GPUDeviceAttribute::GPUDeviceAttribute(VkInstance inst,const GPUPhysicalDevice *pd,VkSurfaceKHR s)
|
||||
GPUDeviceAttribute::GPUDeviceAttribute(VulkanInstance *inst,const GPUPhysicalDevice *pd,VkSurfaceKHR s)
|
||||
{
|
||||
instance=inst;
|
||||
physical_device=pd;
|
||||
@ -50,7 +34,7 @@ GPUDeviceAttribute::~GPUDeviceAttribute()
|
||||
vkDestroyDevice(device,nullptr);
|
||||
|
||||
if(surface)
|
||||
vkDestroySurfaceKHR(instance,surface,nullptr);
|
||||
instance->DestroySurface(surface);
|
||||
}
|
||||
|
||||
bool GPUDeviceAttribute::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex) const
|
||||
|
@ -371,7 +371,7 @@ namespace
|
||||
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
|
||||
|
||||
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
|
||||
{
|
||||
@ -387,7 +387,7 @@ GPUDevice *CreateRenderDevice(VkInstance inst,const GPUPhysicalDevice *physical_
|
||||
if(device_attr->graphics_family==ERROR_FAMILY_INDEX)
|
||||
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)
|
||||
return(nullptr);
|
||||
@ -436,7 +436,7 @@ GPUDevice *CreateRenderDevice(VulkanInstance *inst,Window *win,const GPUPhysical
|
||||
extent.width=win->GetWidth();
|
||||
extent.height=win->GetHeight();
|
||||
|
||||
GPUDevice *device=CreateRenderDevice(*inst,pd,surface,extent);
|
||||
GPUDevice *device=CreateRenderDevice(inst,pd,surface,extent);
|
||||
|
||||
if(!device)
|
||||
{
|
||||
|
@ -87,6 +87,8 @@ VulkanInstance::VulkanInstance(VkInstance i,VKDebugOut *out)
|
||||
|
||||
delete[] pd_list;
|
||||
}
|
||||
|
||||
GetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)vkGetInstanceProcAddr(inst, "vkGetDeviceProcAddr");
|
||||
}
|
||||
|
||||
VulkanInstance::~VulkanInstance()
|
||||
@ -105,4 +107,9 @@ const GPUPhysicalDevice *VulkanInstance::GetDevice(VkPhysicalDeviceType type)con
|
||||
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
void VulkanInstance::DestroySurface(VkSurfaceKHR surface)
|
||||
{
|
||||
vkDestroySurfaceKHR(inst,surface,nullptr);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user