Swapchain创建depth改用Texture2D
This commit is contained in:
parent
6cdb573221
commit
3b86783c53
@ -67,8 +67,8 @@ public:
|
||||
public:
|
||||
|
||||
const uint32_t GetSwapChainImageCount ()const {return attr->sc_image_views.GetCount();}
|
||||
ImageView *GetColorImageView (int index) {return attr->sc_image_views[index];}
|
||||
ImageView *GetDepthImageView () {return attr->depth.view;}
|
||||
//ImageView *GetColorImageView (int index) {return attr->sc_image_views[index];}
|
||||
//ImageView *GetDepthImageView () {return attr->depth.view;}
|
||||
|
||||
RenderPass * GetRenderPass () {return main_rp;}
|
||||
Framebuffer * GetFramebuffer (int index) {return render_frame[index];}
|
||||
|
@ -39,14 +39,7 @@ struct DeviceAttribute
|
||||
List<VkImage> sc_images;
|
||||
ObjectList<ImageView> sc_image_views;
|
||||
|
||||
struct
|
||||
{
|
||||
VkFormat format;
|
||||
|
||||
VkImage image =nullptr;
|
||||
VkDeviceMemory mem =nullptr;
|
||||
ImageView * view =nullptr;
|
||||
}depth;
|
||||
Texture2D * sc_depth =nullptr;
|
||||
|
||||
VkDescriptorPool desc_pool =nullptr;
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define HGL_GRAPH_VULKAN_TEXTURE_INCLUDE
|
||||
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<hgl/graph/vulkan/VKMemory.h>
|
||||
#include<hgl/graph/vulkan/VKImageView.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct TextureData
|
||||
@ -30,11 +31,14 @@ public:
|
||||
|
||||
operator TextureData * (){return data;}
|
||||
|
||||
operator Memory * (){return data?data->memory:nullptr;}
|
||||
operator VkDeviceMemory (){return data?data->memory->operator VkDeviceMemory():nullptr;}
|
||||
operator VkImage (){return data?data->image:nullptr;}
|
||||
operator VkImageLayout (){return data?data->image_layout:VK_IMAGE_LAYOUT_UNDEFINED;}
|
||||
operator VkImageView (){return data?data->image_view->operator VkImageView():nullptr;}
|
||||
|
||||
operator Memory * (){return data?data->memory:nullptr;}
|
||||
operator ImageView * (){return data?data->image_view:nullptr;}
|
||||
|
||||
const uint32 GetMipLevels()const{return data?data->mip_levels:0;}
|
||||
const bool IsLinear ()const{return data?data->linear:false;}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
#include<hgl/type/Pair.h>
|
||||
#include<hgl/graph/vulkan/VKTexture.h>
|
||||
#include<hgl/graph/vulkan/VKImageView.h>
|
||||
#include<hgl/graph/vulkan/VKCommandBuffer.h>
|
||||
//#include<hgl/graph/vulkan/VKDescriptorSet.h>
|
||||
@ -74,13 +75,13 @@ void Device::RecreateDevice()
|
||||
|
||||
present_info.pSwapchains=&attr->swap_chain;
|
||||
|
||||
main_rp=CreateRenderPass(attr->sc_image_views[0]->GetFormat(),attr->depth.view->GetFormat());
|
||||
main_rp=CreateRenderPass(attr->sc_image_views[0]->GetFormat(),attr->sc_depth->GetFormat());
|
||||
|
||||
swap_chain_count=attr->sc_image_views.GetCount();
|
||||
|
||||
for(uint i=0;i<swap_chain_count;i++)
|
||||
{
|
||||
render_frame.Add(vulkan::CreateFramebuffer(this,main_rp,attr->sc_image_views[i],attr->depth.view));
|
||||
render_frame.Add(vulkan::CreateFramebuffer(this,main_rp,attr->sc_image_views[i],*attr->sc_depth));
|
||||
fence_list.Add(this->CreateFence(true));
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include<hgl/graph/vulkan/VKDeviceAttribute.h>
|
||||
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/vulkan/VKImageView.h>
|
||||
#include<hgl/graph/vulkan/VKTexture.h>
|
||||
#include<iostream>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
@ -41,19 +42,7 @@ bool DeviceAttribute::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags pr
|
||||
|
||||
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;
|
||||
}
|
||||
SAFE_CLEAR(sc_depth);
|
||||
|
||||
sc_image_views.Clear();
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include<hgl/graph/vulkan/VKInstance.h>
|
||||
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||
#include<hgl/graph/vulkan/VKTexture.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include<iostream>
|
||||
@ -182,65 +183,74 @@ namespace
|
||||
|
||||
bool CreateDepthBuffer(DeviceAttribute *rsa)
|
||||
{
|
||||
VkImageCreateInfo image_info={};
|
||||
//VkImageCreateInfo image_info={};
|
||||
|
||||
const VkFormat depth_format=VK_FORMAT_D16_UNORM;
|
||||
|
||||
const VkFormatProperties props=rsa->physical_device->GetFormatProperties(depth_format);
|
||||
|
||||
if(props.linearTilingFeatures&VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
||||
image_info.tiling=VK_IMAGE_TILING_LINEAR;
|
||||
else
|
||||
if(props.optimalTilingFeatures&VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
||||
image_info.tiling=VK_IMAGE_TILING_OPTIMAL;
|
||||
else
|
||||
return(false);
|
||||
//if(props.linearTilingFeatures&VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
||||
// image_info.tiling=VK_IMAGE_TILING_LINEAR;
|
||||
//else
|
||||
//if(props.optimalTilingFeatures&VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
||||
// image_info.tiling=VK_IMAGE_TILING_OPTIMAL;
|
||||
//else
|
||||
// return(false);
|
||||
|
||||
image_info.sType=VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
image_info.pNext=nullptr;
|
||||
image_info.imageType=VK_IMAGE_TYPE_2D;
|
||||
image_info.format=depth_format;
|
||||
image_info.extent.width=rsa->swapchain_extent.width;
|
||||
image_info.extent.height=rsa->swapchain_extent.height;
|
||||
image_info.extent.depth=1;
|
||||
image_info.mipLevels=1;
|
||||
image_info.arrayLayers=1;
|
||||
image_info.samples=VK_SAMPLE_COUNT_1_BIT;
|
||||
image_info.initialLayout=VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
image_info.usage=VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
image_info.queueFamilyIndexCount=0;
|
||||
image_info.pQueueFamilyIndices=nullptr;
|
||||
image_info.sharingMode=VK_SHARING_MODE_EXCLUSIVE;
|
||||
image_info.flags=0;
|
||||
//image_info.sType=VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
//image_info.pNext=nullptr;
|
||||
//image_info.imageType=VK_IMAGE_TYPE_2D;
|
||||
//image_info.format=depth_format;
|
||||
//image_info.extent.width=rsa->swapchain_extent.width;
|
||||
//image_info.extent.height=rsa->swapchain_extent.height;
|
||||
//image_info.extent.depth=1;
|
||||
//image_info.mipLevels=1;
|
||||
//image_info.arrayLayers=1;
|
||||
//image_info.samples=VK_SAMPLE_COUNT_1_BIT;
|
||||
//image_info.initialLayout=VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
//image_info.usage=VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
//image_info.queueFamilyIndexCount=0;
|
||||
//image_info.pQueueFamilyIndices=nullptr;
|
||||
//image_info.sharingMode=VK_SHARING_MODE_EXCLUSIVE;
|
||||
//image_info.flags=0;
|
||||
|
||||
rsa->depth.format=depth_format;
|
||||
//rsa->depth.format=depth_format;
|
||||
|
||||
if(vkCreateImage(rsa->device,&image_info,nullptr,&rsa->depth.image)!=VK_SUCCESS)
|
||||
return(false);
|
||||
//if(vkCreateImage(rsa->device,&image_info,nullptr,&rsa->depth.image)!=VK_SUCCESS)
|
||||
// return(false);
|
||||
|
||||
VkMemoryRequirements mem_reqs;
|
||||
vkGetImageMemoryRequirements(rsa->device,rsa->depth.image,&mem_reqs);
|
||||
//VkMemoryRequirements mem_reqs;
|
||||
//vkGetImageMemoryRequirements(rsa->device,rsa->depth.image,&mem_reqs);
|
||||
|
||||
VkMemoryAllocateInfo mem_alloc={};
|
||||
mem_alloc.sType=VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
mem_alloc.pNext=nullptr;
|
||||
mem_alloc.allocationSize=0;
|
||||
mem_alloc.memoryTypeIndex=0;
|
||||
mem_alloc.allocationSize=mem_reqs.size;
|
||||
//VkMemoryAllocateInfo mem_alloc={};
|
||||
//mem_alloc.sType=VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
//mem_alloc.pNext=nullptr;
|
||||
//mem_alloc.allocationSize=0;
|
||||
//mem_alloc.memoryTypeIndex=0;
|
||||
//mem_alloc.allocationSize=mem_reqs.size;
|
||||
|
||||
if(!rsa->CheckMemoryType(mem_reqs.memoryTypeBits,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,&mem_alloc.memoryTypeIndex))
|
||||
return(false);
|
||||
//if(!rsa->CheckMemoryType(mem_reqs.memoryTypeBits,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,&mem_alloc.memoryTypeIndex))
|
||||
// return(false);
|
||||
|
||||
if(vkAllocateMemory(rsa->device,&mem_alloc,nullptr,&rsa->depth.mem)!=VK_SUCCESS)
|
||||
return(false);
|
||||
//if(vkAllocateMemory(rsa->device,&mem_alloc,nullptr,&rsa->depth.mem)!=VK_SUCCESS)
|
||||
// return(false);
|
||||
|
||||
if(vkBindImageMemory(rsa->device,rsa->depth.image,rsa->depth.mem,0)!=VK_SUCCESS)
|
||||
return(false);
|
||||
//if(vkBindImageMemory(rsa->device,rsa->depth.image,rsa->depth.mem,0)!=VK_SUCCESS)
|
||||
// return(false);
|
||||
|
||||
rsa->depth.view=CreateDepthImageView(rsa->device,depth_format,rsa->depth.image);
|
||||
//rsa->depth.view=CreateDepthImageView(rsa->device,depth_format,rsa->depth.image);
|
||||
|
||||
if(rsa->depth.view==nullptr)
|
||||
return(false);
|
||||
//if(rsa->depth.view==nullptr)
|
||||
// return(false);
|
||||
|
||||
rsa->sc_depth=VK_NAMESPACE::CreateTexture2D(rsa->device,rsa->physical_device,
|
||||
depth_format,
|
||||
rsa->swapchain_extent.width,
|
||||
rsa->swapchain_extent.height,
|
||||
VK_IMAGE_ASPECT_DEPTH_BIT,
|
||||
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
(props.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)?VK_IMAGE_TILING_OPTIMAL:VK_IMAGE_TILING_LINEAR);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user