optimized codes of VkImageView.

This commit is contained in:
hyzboy 2022-01-07 11:56:32 +08:00
parent 967f03992f
commit e5ec4c594d
2 changed files with 37 additions and 41 deletions

View File

@ -9,27 +9,20 @@ protected:
VkDevice device;
VkImageView image_view;
ImageViewCreateInfo *ivci;
VkImageViewType view_type;
VkFormat format;
VkImageAspectFlags aspect_mask;
VkExtent3D extent;
uint32_t miplevel;
private:
friend ImageView *CreateImageView(VkDevice device,VkImageViewType type,VkFormat format,const VkExtent3D &ext,const uint32_t &miplevel,VkImageAspectFlags aspectMask,VkImage img);
ImageView(VkDevice dev,VkImageView iv,const VkImageViewType vt,const VkFormat fmt,const VkExtent3D &ext,const uint32_t &ml,const VkImageAspectFlags am)
ImageView(VkDevice dev,VkImageView iv,ImageViewCreateInfo *ci,const VkExtent3D &ext)
{
device =dev;
image_view =iv;
view_type =vt;
format =fmt;
aspect_mask =am;
ivci =ci;
extent =ext;
miplevel =ml;
}
public:
@ -40,16 +33,16 @@ public:
public:
const VkImageViewType GetViewType ()const{return view_type;}
const VkFormat GetFormat ()const{return format;}
const VkImageViewType GetViewType ()const{return ivci->viewType;}
const VkFormat GetFormat ()const{return ivci->format;}
const VkExtent3D & GetExtent ()const{return extent;}
const uint32_t & GetMipLevel ()const{return miplevel;}
const VkImageAspectFlags GetAspectFlags ()const{return aspect_mask;}
const VkImageAspectFlags GetAspectFlags ()const{return ivci->subresourceRange.aspectMask;}
const uint32_t GetLayerCount ()const{return ivci->subresourceRange.layerCount;}
const bool hasColor ()const{return aspect_mask&VK_IMAGE_ASPECT_COLOR_BIT;}
const bool hasDepth ()const{return aspect_mask&VK_IMAGE_ASPECT_DEPTH_BIT;}
const bool hasStencil ()const{return aspect_mask&VK_IMAGE_ASPECT_STENCIL_BIT;}
const bool hasDepthStencil ()const{return aspect_mask&(VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT);}
const bool hasColor ()const{return ivci->subresourceRange.aspectMask&VK_IMAGE_ASPECT_COLOR_BIT;}
const bool hasDepth ()const{return ivci->subresourceRange.aspectMask&VK_IMAGE_ASPECT_DEPTH_BIT;}
const bool hasStencil ()const{return ivci->subresourceRange.aspectMask&VK_IMAGE_ASPECT_STENCIL_BIT;}
const bool hasDepthStencil ()const{return ivci->subresourceRange.aspectMask&(VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT);}
};//class ImageView
ImageView *CreateImageView(VkDevice device,VkImageViewType type,VkFormat format,const VkExtent3D &ext,const uint32_t &miplevel,VkImageAspectFlags aspectMask,VkImage img);

View File

@ -3,53 +3,56 @@
VK_NAMESPACE_BEGIN
ImageView::~ImageView()
{
delete ivci;
vkDestroyImageView(device,image_view,nullptr);
}
ImageView *CreateImageView(VkDevice device,VkImageViewType type,VkFormat format,const VkExtent3D &ext,const uint32_t &miplevel,VkImageAspectFlags aspectMask,VkImage img)
{
ImageViewCreateInfo iv_createinfo;
ImageViewCreateInfo *iv_createinfo=new ImageViewCreateInfo;
iv_createinfo.image =img;
iv_createinfo.format =format;
iv_createinfo.viewType =type;
iv_createinfo.subresourceRange.aspectMask =aspectMask;
iv_createinfo.subresourceRange.baseMipLevel =0;
iv_createinfo.subresourceRange.levelCount =miplevel;
iv_createinfo.subresourceRange.baseArrayLayer =0;
iv_createinfo->image =img;
iv_createinfo->format =format;
iv_createinfo->viewType =type;
iv_createinfo->subresourceRange.aspectMask =aspectMask;
iv_createinfo->subresourceRange.baseMipLevel =0;
iv_createinfo->subresourceRange.levelCount =miplevel;
iv_createinfo->subresourceRange.baseArrayLayer =0;
if(type==VK_IMAGE_VIEW_TYPE_CUBE)
iv_createinfo.subresourceRange.layerCount =6;
iv_createinfo->subresourceRange.layerCount =6;
else
if(type==VK_IMAGE_VIEW_TYPE_CUBE_ARRAY)
iv_createinfo.subresourceRange.layerCount =6*ext.depth;
iv_createinfo->subresourceRange.layerCount =6*ext.depth;
else
iv_createinfo.subresourceRange.layerCount =ext.depth;
iv_createinfo->subresourceRange.layerCount =ext.depth;
if(aspectMask&VK_IMAGE_ASPECT_DEPTH_BIT)
{
if(format>=VK_FORMAT_D16_UNORM_S8_UINT)
iv_createinfo.subresourceRange.aspectMask|=VK_IMAGE_ASPECT_STENCIL_BIT;
iv_createinfo->subresourceRange.aspectMask|=VK_IMAGE_ASPECT_STENCIL_BIT;
iv_createinfo.components.r=VK_COMPONENT_SWIZZLE_IDENTITY;
iv_createinfo.components.g=VK_COMPONENT_SWIZZLE_IDENTITY;
iv_createinfo.components.b=VK_COMPONENT_SWIZZLE_IDENTITY;
iv_createinfo.components.a=VK_COMPONENT_SWIZZLE_IDENTITY;
iv_createinfo->components.r=VK_COMPONENT_SWIZZLE_IDENTITY;
iv_createinfo->components.g=VK_COMPONENT_SWIZZLE_IDENTITY;
iv_createinfo->components.b=VK_COMPONENT_SWIZZLE_IDENTITY;
iv_createinfo->components.a=VK_COMPONENT_SWIZZLE_IDENTITY;
}
else
{
iv_createinfo.components.r=VK_COMPONENT_SWIZZLE_R;
iv_createinfo.components.g=VK_COMPONENT_SWIZZLE_G;
iv_createinfo.components.b=VK_COMPONENT_SWIZZLE_B;
iv_createinfo.components.a=VK_COMPONENT_SWIZZLE_A;
iv_createinfo->components.r=VK_COMPONENT_SWIZZLE_R;
iv_createinfo->components.g=VK_COMPONENT_SWIZZLE_G;
iv_createinfo->components.b=VK_COMPONENT_SWIZZLE_B;
iv_createinfo->components.a=VK_COMPONENT_SWIZZLE_A;
}
VkImageView img_view;
if(vkCreateImageView(device,&iv_createinfo,nullptr,&img_view)!=VK_SUCCESS)
if(vkCreateImageView(device,iv_createinfo,nullptr,&img_view)!=VK_SUCCESS)
{
delete iv_createinfo;
return(nullptr);
}
return(new ImageView(device,img_view,type,format,ext,miplevel,aspectMask));
return(new ImageView(device,img_view,iv_createinfo,ext));
}
VK_NAMESPACE_END