diff --git a/inc/hgl/graph/VKDevice.h b/inc/hgl/graph/VKDevice.h index 1592a328..3511a4ec 100644 --- a/inc/hgl/graph/VKDevice.h +++ b/inc/hgl/graph/VKDevice.h @@ -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 - T *GetProc(const char *name) - { - return reinterpret_cast(vkGetDeviceProcAddr(attr->device,name)); - } - public: //内存相关 GPUMemory *CreateMemory(const VkMemoryRequirements &,const uint32_t properties); diff --git a/inc/hgl/graph/VKDeviceAttribute.h b/inc/hgl/graph/VKDeviceAttribute.h index ddf13877..b65633b0 100644 --- a/inc/hgl/graph/VKDeviceAttribute.h +++ b/inc/hgl/graph/VKDeviceAttribute.h @@ -1,5 +1,6 @@ #pragma once +#include #include 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 + T *GetDeviceProc(const char *name) + { + return instance->GetDeviceProc(device,name); + } };//class GPUDeviceAttribute VK_NAMESPACE_END diff --git a/inc/hgl/graph/VKInstance.h b/inc/hgl/graph/VKInstance.h index 57080469..5187d71d 100644 --- a/inc/hgl/graph/VKInstance.h +++ b/inc/hgl/graph/VKInstance.h @@ -57,6 +57,10 @@ VK_NAMESPACE_BEGIN ObjectList 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(vkGetInstanceProcAddr(inst,name)); } + + template + T *GetDeviceProc(const char *name) + { + if(!GetDeviceProcAddr)return(nullptr); + + return reinterpret_cast(GetDeviceProcAddr(name)); + } + + void DestroySurface(VkSurfaceKHR); };//class VulkanInstance void InitVulkanInstanceProperties(); diff --git a/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp b/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp index 32c1520a..86fe13d2 100644 --- a/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp @@ -5,25 +5,9 @@ #include 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 diff --git a/src/SceneGraph/Vulkan/VKDeviceCreater.cpp b/src/SceneGraph/Vulkan/VKDeviceCreater.cpp index 12dfe501..cea75a78 100644 --- a/src/SceneGraph/Vulkan/VKDeviceCreater.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceCreater.cpp @@ -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) { diff --git a/src/SceneGraph/Vulkan/VKInstance.cpp b/src/SceneGraph/Vulkan/VKInstance.cpp index 70889b9f..dd0483ee 100644 --- a/src/SceneGraph/Vulkan/VKInstance.cpp +++ b/src/SceneGraph/Vulkan/VKInstance.cpp @@ -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