修正窗口调整大小后,没有重新获取vkPhysicalDevice属性的问题

This commit is contained in:
hyzboy 2019-06-13 15:23:16 +08:00
parent d13bd948aa
commit 471902223e
3 changed files with 125 additions and 117 deletions

View File

@ -60,5 +60,6 @@ public:
bool CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex) const;
void ClearSwapchain();
void Refresh();
};//class DeviceAttribute
VK_NAMESPACE_END

View File

@ -11,6 +11,61 @@ DeviceAttribute::DeviceAttribute(VkInstance inst,const PhysicalDevice *pd,VkSurf
physical_device=pd;
surface=s;
Refresh();
}
DeviceAttribute::~DeviceAttribute()
{
if(pipeline_cache)
vkDestroyPipelineCache(device,pipeline_cache,nullptr);
if(desc_pool)
vkDestroyDescriptorPool(device,desc_pool,nullptr);
ClearSwapchain();
if(cmd_pool)
vkDestroyCommandPool(device,cmd_pool,nullptr);
if(device)
vkDestroyDevice(device,nullptr);
if(surface)
vkDestroySurfaceKHR(instance,surface,nullptr);
}
bool DeviceAttribute::CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex) const
{
return physical_device->CheckMemoryType(typeBits,requirements_mask,typeIndex);
}
void DeviceAttribute::ClearSwapchain()
{
SAFE_CLEAR(depth.view);
if(depth.image)
{
vkDestroyImage(device,depth.image,nullptr);
depth.image=nullptr;
}
if(depth.mem)
{
vkFreeMemory(device,depth.mem,nullptr);
depth.mem=nullptr;
}
sc_image_views.Clear();
if(swap_chain)
{
vkDestroySwapchainKHR(device,swap_chain,nullptr);
swap_chain=nullptr;
}
}
void DeviceAttribute::Refresh()
{
VkPhysicalDevice pdevice = *physical_device;
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(pdevice, surface, &surface_caps);
@ -129,54 +184,4 @@ DeviceAttribute::DeviceAttribute(VkInstance inst,const PhysicalDevice *pd,VkSurf
}
}
}
DeviceAttribute::~DeviceAttribute()
{
if(pipeline_cache)
vkDestroyPipelineCache(device,pipeline_cache,nullptr);
if(desc_pool)
vkDestroyDescriptorPool(device,desc_pool,nullptr);
ClearSwapchain();
if(cmd_pool)
vkDestroyCommandPool(device,cmd_pool,nullptr);
if(device)
vkDestroyDevice(device,nullptr);
if(surface)
vkDestroySurfaceKHR(instance,surface,nullptr);
}
bool DeviceAttribute::CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex) const
{
return physical_device->CheckMemoryType(typeBits,requirements_mask,typeIndex);
}
void DeviceAttribute::ClearSwapchain()
{
SAFE_CLEAR(depth.view);
if(depth.image)
{
vkDestroyImage(device,depth.image,nullptr);
depth.image=nullptr;
}
if(depth.mem)
{
vkFreeMemory(device,depth.mem,nullptr);
depth.mem=nullptr;
}
sc_image_views.Clear();
if(swap_chain)
{
vkDestroySwapchainKHR(device,swap_chain,nullptr);
swap_chain=nullptr;
}
}
VK_NAMESPACE_END

View File

@ -584,6 +584,8 @@ bool ResizeRenderDevice(DeviceAttribute *attr,uint width,uint height)
attr->ClearSwapchain();
attr->Refresh();
attr->swapchain_extent=GetSwapchainExtent(attr->surface_caps,width,height);
return CreateSwapchinAndImageView(attr);