create a new VKTextureCreateInfo.h
This commit is contained in:
parent
d38739397e
commit
507c46cc78
@ -1 +1 @@
|
|||||||
Subproject commit 141e69143bfae08f5fd84f1bce4364f32e93e506
|
Subproject commit 59523b92969fc7f015b6d63667c7524d526db1ac
|
@ -75,6 +75,12 @@ enum class SharingMode
|
|||||||
Concurrent
|
Concurrent
|
||||||
};//
|
};//
|
||||||
|
|
||||||
|
enum class Filter
|
||||||
|
{
|
||||||
|
Nearest=0,
|
||||||
|
Linear,
|
||||||
|
};//
|
||||||
|
|
||||||
enum ImageTiling
|
enum ImageTiling
|
||||||
{
|
{
|
||||||
Optimal=0,
|
Optimal=0,
|
||||||
|
@ -64,6 +64,7 @@ public:
|
|||||||
template<typename ...ARGS> void PipelineBarrier (ARGS...args){vkCmdPipelineBarrier (cmd_buf,args...);}
|
template<typename ...ARGS> void PipelineBarrier (ARGS...args){vkCmdPipelineBarrier (cmd_buf,args...);}
|
||||||
template<typename ...ARGS> void CopyBufferToImage (ARGS...args){vkCmdCopyBufferToImage(cmd_buf,args...);}
|
template<typename ...ARGS> void CopyBufferToImage (ARGS...args){vkCmdCopyBufferToImage(cmd_buf,args...);}
|
||||||
template<typename ...ARGS> void CopyImageToBuffer (ARGS...args){vkCmdCopyImageToBuffer(cmd_buf,args...);}
|
template<typename ...ARGS> void CopyImageToBuffer (ARGS...args){vkCmdCopyImageToBuffer(cmd_buf,args...);}
|
||||||
|
template<typename ...ARGS> void BlitImage (ARGS...args){vkCmdBlitImage (cmd_buf,args...);}
|
||||||
|
|
||||||
bool BindFramebuffer(VkRenderPass rp,VkFramebuffer fb);
|
bool BindFramebuffer(VkRenderPass rp,VkFramebuffer fb);
|
||||||
bool BindFramebuffer(Framebuffer *);
|
bool BindFramebuffer(Framebuffer *);
|
||||||
|
@ -134,9 +134,9 @@ public: //Texture
|
|||||||
Texture2D *CreateTexture2D(GPUMemory *mem,VkImage image,ImageView *image_view,VkImageLayout image_layout,ImageTiling tiling);
|
Texture2D *CreateTexture2D(GPUMemory *mem,VkImage image,ImageView *image_view,VkImageLayout image_layout,ImageTiling tiling);
|
||||||
Texture2D *CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,VkImage image,VkImageLayout image_layout,ImageTiling tiling=ImageTiling::Optimal);
|
Texture2D *CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,VkImage image,VkImageLayout image_layout,ImageTiling tiling=ImageTiling::Optimal);
|
||||||
|
|
||||||
Texture2D *CreateTexture2D(const VkFormat format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,ImageTiling tiling=ImageTiling::Optimal);
|
Texture2D *CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,uint usage,VkImageLayout image_layout,ImageTiling tiling=ImageTiling::Optimal);
|
||||||
|
|
||||||
Texture2D *CreateTexture2DColor(const VkFormat video_format,uint32_t width,uint32_t height,const ImageTiling tiling=ImageTiling::Optimal)
|
Texture2D *CreateTexture2DColor(VkFormat video_format,uint32_t width,uint32_t height,ImageTiling tiling=ImageTiling::Optimal)
|
||||||
{
|
{
|
||||||
return CreateTexture2D(video_format,width,height,
|
return CreateTexture2D(video_format,width,height,
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
@ -145,7 +145,7 @@ public: //Texture
|
|||||||
tiling);
|
tiling);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *CreateTexture2DDepth(const VkFormat video_format,uint32_t width,uint32_t height,const ImageTiling tiling=ImageTiling::Optimal)
|
Texture2D *CreateTexture2DDepth(VkFormat video_format,uint32_t width,uint32_t height,ImageTiling tiling=ImageTiling::Optimal)
|
||||||
{
|
{
|
||||||
return CreateTexture2D(video_format,width,height,
|
return CreateTexture2D(video_format,width,height,
|
||||||
VK_IMAGE_ASPECT_DEPTH_BIT,
|
VK_IMAGE_ASPECT_DEPTH_BIT,
|
||||||
@ -154,12 +154,12 @@ public: //Texture
|
|||||||
tiling);
|
tiling);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *CreateAttachmentTexture(const VkFormat video_format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout)
|
Texture2D *CreateAttachmentTexture(VkFormat video_format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,uint usage,VkImageLayout image_layout)
|
||||||
{
|
{
|
||||||
return CreateTexture2D(video_format,width,height,aspectMask,usage|VK_IMAGE_USAGE_SAMPLED_BIT,image_layout);
|
return CreateTexture2D(video_format,width,height,aspectMask,usage|VK_IMAGE_USAGE_SAMPLED_BIT,image_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *CreateAttachmentTextureColor(const VkFormat video_format,uint32_t width,uint32_t height)
|
Texture2D *CreateAttachmentTextureColor(VkFormat video_format,uint32_t width,uint32_t height)
|
||||||
{
|
{
|
||||||
return CreateAttachmentTexture( video_format,width,height,
|
return CreateAttachmentTexture( video_format,width,height,
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
@ -167,7 +167,7 @@ public: //Texture
|
|||||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *CreateAttachmentTextureDepth(const VkFormat video_format,uint32_t width,uint32_t height)
|
Texture2D *CreateAttachmentTextureDepth(VkFormat video_format,uint32_t width,uint32_t height)
|
||||||
{
|
{
|
||||||
return CreateAttachmentTexture( video_format,width,height,
|
return CreateAttachmentTexture( video_format,width,height,
|
||||||
VK_IMAGE_ASPECT_DEPTH_BIT,
|
VK_IMAGE_ASPECT_DEPTH_BIT,
|
||||||
@ -175,7 +175,7 @@ public: //Texture
|
|||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *CreateAttachmentTextureDepthStencil(const VkFormat video_format,uint32_t width,uint32_t height)
|
Texture2D *CreateAttachmentTextureDepthStencil(VkFormat video_format,uint32_t width,uint32_t height)
|
||||||
{
|
{
|
||||||
return CreateAttachmentTexture( video_format,width,height,
|
return CreateAttachmentTexture( video_format,width,height,
|
||||||
VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT,
|
VK_IMAGE_ASPECT_DEPTH_BIT|VK_IMAGE_ASPECT_STENCIL_BIT,
|
||||||
@ -183,17 +183,17 @@ public: //Texture
|
|||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *CreateTexture2D( const VkFormat video_format,GPUBuffer *buf,uint32_t width,uint32_t height,
|
Texture2D *CreateTexture2D( VkFormat video_format,GPUBuffer *buf,uint32_t width,uint32_t height,
|
||||||
const VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT,
|
VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
const uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||||
const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||||
const ImageTiling tiling =ImageTiling::Optimal);
|
ImageTiling tiling =ImageTiling::Optimal);
|
||||||
|
|
||||||
Texture2D *CreateTexture2D( const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,
|
Texture2D *CreateTexture2D( VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size,
|
||||||
const VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT,
|
VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
const uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||||
const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||||
const ImageTiling tiling =ImageTiling::Optimal);
|
ImageTiling tiling =ImageTiling::Optimal);
|
||||||
|
|
||||||
bool ChangeTexture2D(Texture2D *,GPUBuffer *buf,const VkBufferImageCopy *,const int count);
|
bool ChangeTexture2D(Texture2D *,GPUBuffer *buf,const VkBufferImageCopy *,const int count);
|
||||||
bool ChangeTexture2D(Texture2D *,GPUBuffer *buf,const List<ImageRegion> &);
|
bool ChangeTexture2D(Texture2D *,GPUBuffer *buf,const List<ImageRegion> &);
|
||||||
@ -224,6 +224,8 @@ public: //Texture
|
|||||||
size);
|
size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GenerateMipmaps(Texture2D *);
|
||||||
|
|
||||||
public: //
|
public: //
|
||||||
|
|
||||||
Sampler *CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
Sampler *CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||||
|
@ -6,41 +6,11 @@
|
|||||||
#include<hgl/graph/VKImageView.h>
|
#include<hgl/graph/VKImageView.h>
|
||||||
#include<hgl/graph/Bitmap.h>
|
#include<hgl/graph/Bitmap.h>
|
||||||
#include<hgl/type/String.h>
|
#include<hgl/type/String.h>
|
||||||
|
#include<hgl/graph/VKTextureCreateInfo.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
BitmapData *LoadBitmapFromFile(const OSString &filename);
|
BitmapData *LoadBitmapFromFile(const OSString &filename);
|
||||||
|
|
||||||
struct TextureData
|
|
||||||
{
|
|
||||||
GPUMemory * memory =nullptr;
|
|
||||||
VkImage image =VK_NULL_HANDLE;
|
|
||||||
VkImageLayout image_layout=VK_IMAGE_LAYOUT_UNDEFINED;
|
|
||||||
ImageView * image_view =nullptr;
|
|
||||||
uint32 mip_levels =0;
|
|
||||||
VkImageTiling tiling =VK_IMAGE_TILING_OPTIMAL;
|
|
||||||
};//struct TextureData
|
|
||||||
|
|
||||||
struct TextureCreateInfo
|
|
||||||
{
|
|
||||||
VkExtent3D extent;
|
|
||||||
VkFormat format;
|
|
||||||
uint usage;
|
|
||||||
VkImageAspectFlags aspect;
|
|
||||||
ImageTiling tiling;
|
|
||||||
|
|
||||||
VkImage image;
|
|
||||||
GPUMemory * memory;
|
|
||||||
ImageView * image_view;
|
|
||||||
VkImageLayout image_layout;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
TextureCreateInfo()
|
|
||||||
{
|
|
||||||
hgl_zero(*this);
|
|
||||||
}
|
|
||||||
};//struct TextureCreateInfo
|
|
||||||
|
|
||||||
class Texture
|
class Texture
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
73
inc/hgl/graph/VKTextureCreateInfo.h
Normal file
73
inc/hgl/graph/VKTextureCreateInfo.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#ifndef HGL_GRAPH_VULKAN_TEXTURE_CREATE_INFO_INCLUDE
|
||||||
|
#define HGL_GRAPH_VULKAN_TEXTURE_CREATE_INFO_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/graph/VK.h>
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
struct TextureData
|
||||||
|
{
|
||||||
|
GPUMemory * memory =nullptr;
|
||||||
|
VkImage image =VK_NULL_HANDLE;
|
||||||
|
VkImageLayout image_layout=VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
ImageView * image_view =nullptr;
|
||||||
|
uint32 mip_levels =0;
|
||||||
|
VkImageTiling tiling =VK_IMAGE_TILING_OPTIMAL;
|
||||||
|
};//struct TextureData
|
||||||
|
|
||||||
|
struct TextureCreateInfo
|
||||||
|
{
|
||||||
|
VkExtent3D extent;
|
||||||
|
VkFormat format;
|
||||||
|
uint32_t usage;
|
||||||
|
uint32_t mipmap; ///<如果值>0表示提供的数据已有mipmaps,如果为0表示自动生成mipmaps
|
||||||
|
VkImageAspectFlags aspect;
|
||||||
|
ImageTiling tiling;
|
||||||
|
|
||||||
|
void * pixels;
|
||||||
|
GPUBuffer * buffer;
|
||||||
|
|
||||||
|
VkImage image;
|
||||||
|
GPUMemory * memory;
|
||||||
|
ImageView * image_view;
|
||||||
|
VkImageLayout image_layout;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
TextureCreateInfo()
|
||||||
|
{
|
||||||
|
hgl_zero(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureCreateInfo(const uint32_t aspect_bit):TextureCreateInfo()
|
||||||
|
{
|
||||||
|
usage=VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||||
|
|
||||||
|
aspect=aspect_bit;
|
||||||
|
tiling=ImageTiling::Optimal;
|
||||||
|
image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
}
|
||||||
|
};//struct TextureCreateInfo
|
||||||
|
|
||||||
|
class AttachmentTextureCreateInfo:public TextureCreateInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
AttachmentTextureCreateInfo(const uint32_t aspect_bit):TextureCreateInfo()
|
||||||
|
{
|
||||||
|
aspect=aspect_bit;
|
||||||
|
tiling=ImageTiling::Optimal;
|
||||||
|
|
||||||
|
if(aspect_bit&VK_IMAGE_ASPECT_COLOR_BIT)
|
||||||
|
{
|
||||||
|
usage=VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||||
|
image_layout=VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(aspect_bit&VK_IMAGE_ASPECT_DEPTH_BIT)
|
||||||
|
{
|
||||||
|
usage=VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||||
|
image_layout=VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
VK_NAMESPACE_END
|
||||||
|
#endif//HGL_GRAPH_VULKAN_TEXTURE_CREATE_INFO_INCLUDE
|
@ -54,6 +54,7 @@ SET(VK_SHADER_SOURCE ${VK_INCLUDE_PATH}/VKShaderModule.h
|
|||||||
|
|
||||||
SET(VK_TEXTURE_SOURCE ${VK_INCLUDE_PATH}/VKImageView.h
|
SET(VK_TEXTURE_SOURCE ${VK_INCLUDE_PATH}/VKImageView.h
|
||||||
${VK_INCLUDE_PATH}/VKTexture.h
|
${VK_INCLUDE_PATH}/VKTexture.h
|
||||||
|
${VK_INCLUDE_PATH}/VKTextureCreateInfo.h
|
||||||
${VK_INCLUDE_PATH}/VKSampler.h
|
${VK_INCLUDE_PATH}/VKSampler.h
|
||||||
VKSampler.cpp
|
VKSampler.cpp
|
||||||
VKImageView.cpp
|
VKImageView.cpp
|
||||||
|
@ -10,14 +10,9 @@
|
|||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
uint32_t GetMipLevels(uint32_t size)
|
const uint32_t GetMipLevels(const uint32_t size)
|
||||||
{
|
{
|
||||||
uint32_t level=1;
|
return static_cast<uint32_t>(std::floor(std::log2(size)))+1;
|
||||||
|
|
||||||
while(size>>=1)
|
|
||||||
++level;
|
|
||||||
|
|
||||||
return level;
|
|
||||||
}
|
}
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
||||||
@ -71,7 +66,7 @@ Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
|
|||||||
|
|
||||||
if(!tci->image)
|
if(!tci->image)
|
||||||
{
|
{
|
||||||
Image2DCreateInfo ici(tci->usage,tci->tiling,tci->format,tci->extent.width,tci->extent.height);
|
Image2DCreateInfo ici(tci->usage,tci->tiling,tci->format,tci->extent.width,tci->extent.height,tci->mipmap);
|
||||||
tci->image=CreateImage(&ici);
|
tci->image=CreateImage(&ici);
|
||||||
|
|
||||||
if(!tci->image)
|
if(!tci->image)
|
||||||
@ -117,7 +112,7 @@ Texture2D *GPUDevice::CreateTexture2D(VkFormat format,uint32_t width,uint32_t he
|
|||||||
return CreateTexture2D(tci);
|
return CreateTexture2D(tci);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *GPUDevice::CreateTexture2D(const VkFormat format,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,ImageTiling tiling)
|
Texture2D *GPUDevice::CreateTexture2D(VkFormat format,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,uint usage,VkImageLayout image_layout,ImageTiling tiling)
|
||||||
{
|
{
|
||||||
if(!CheckTextureFormatSupport(format,tiling))return(nullptr);
|
if(!CheckTextureFormatSupport(format,tiling))return(nullptr);
|
||||||
|
|
||||||
@ -136,7 +131,7 @@ Texture2D *GPUDevice::CreateTexture2D(const VkFormat format,uint32_t width,uint3
|
|||||||
return CreateTexture2D(tci);
|
return CreateTexture2D(tci);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *GPUDevice::CreateTexture2D(const VkFormat format,GPUBuffer *buf,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,const ImageTiling tiling)
|
Texture2D *GPUDevice::CreateTexture2D(VkFormat format,GPUBuffer *buf,uint32_t width,uint32_t height,VkImageAspectFlags aspectMask,uint usage,VkImageLayout image_layout,const ImageTiling tiling)
|
||||||
{
|
{
|
||||||
if(!buf)return(nullptr);
|
if(!buf)return(nullptr);
|
||||||
|
|
||||||
@ -149,7 +144,7 @@ Texture2D *GPUDevice::CreateTexture2D(const VkFormat format,GPUBuffer *buf,uint3
|
|||||||
return(tex);
|
return(tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D *GPUDevice::CreateTexture2D(const VkFormat format,void *data,uint32_t width,uint32_t height,uint32_t size,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout,const ImageTiling tiling)
|
Texture2D *GPUDevice::CreateTexture2D(VkFormat format,void *data,uint32_t width,uint32_t height,uint32_t size,VkImageAspectFlags aspectMask,uint usage,VkImageLayout image_layout,ImageTiling tiling)
|
||||||
{
|
{
|
||||||
Texture2D *tex=CreateTexture2D(format,width,height,aspectMask,usage,image_layout,tiling);
|
Texture2D *tex=CreateTexture2D(format,width,height,aspectMask,usage,image_layout,tiling);
|
||||||
|
|
||||||
@ -308,6 +303,93 @@ bool GPUDevice::ChangeTexture2D(Texture2D *tex,void *data,uint32_t left,uint32_t
|
|||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPUDevice::GenerateMipmaps(Texture2D *tex)
|
||||||
|
{
|
||||||
|
//VkImage image, VkFormat imageFormat, int32_t texWidth, int32_t texHeight, uint32_t mipLevels) {
|
||||||
|
// Check if image format supports linear blitting
|
||||||
|
|
||||||
|
const uint32_t mipLevels=GetMipLevels(std::max(tex->GetWidth(),tex->GetHeight()));
|
||||||
|
|
||||||
|
VkImage image=tex->GetImage();
|
||||||
|
|
||||||
|
VkImageMemoryBarrier barrier{};
|
||||||
|
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||||
|
barrier.image = image;
|
||||||
|
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
|
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
|
barrier.subresourceRange.aspectMask = tex->GetAspect();
|
||||||
|
barrier.subresourceRange.baseArrayLayer = 0;
|
||||||
|
barrier.subresourceRange.layerCount = 1;
|
||||||
|
barrier.subresourceRange.levelCount = 1;
|
||||||
|
|
||||||
|
int32_t mipWidth = tex->GetWidth();
|
||||||
|
int32_t mipHeight = tex->GetHeight();
|
||||||
|
|
||||||
|
texture_cmd_buf->Begin();
|
||||||
|
|
||||||
|
for (uint32_t i = 1; i < mipLevels; i++) {
|
||||||
|
barrier.subresourceRange.baseMipLevel = i - 1;
|
||||||
|
barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||||
|
barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
|
||||||
|
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||||
|
barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||||
|
|
||||||
|
texture_cmd_buf->PipelineBarrier(
|
||||||
|
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0,
|
||||||
|
0, nullptr,
|
||||||
|
0, nullptr,
|
||||||
|
1, &barrier);
|
||||||
|
|
||||||
|
VkImageBlit blit{};
|
||||||
|
blit.srcOffsets[0] = {0, 0, 0};
|
||||||
|
blit.srcOffsets[1] = {mipWidth, mipHeight, 1};
|
||||||
|
blit.srcSubresource.aspectMask = tex->GetAspect();
|
||||||
|
blit.srcSubresource.mipLevel = i - 1;
|
||||||
|
blit.srcSubresource.baseArrayLayer = 0;
|
||||||
|
blit.srcSubresource.layerCount = 1;
|
||||||
|
blit.dstOffsets[0] = {0, 0, 0};
|
||||||
|
blit.dstOffsets[1] = { mipWidth > 1 ? mipWidth / 2 : 1, mipHeight > 1 ? mipHeight / 2 : 1, 1 };
|
||||||
|
blit.dstSubresource.aspectMask = tex->GetAspect();
|
||||||
|
blit.dstSubresource.mipLevel = i;
|
||||||
|
blit.dstSubresource.baseArrayLayer = 0;
|
||||||
|
blit.dstSubresource.layerCount = 1;
|
||||||
|
|
||||||
|
texture_cmd_buf->BlitImage(
|
||||||
|
image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||||
|
image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||||
|
1, &blit,
|
||||||
|
VK_FILTER_LINEAR);
|
||||||
|
|
||||||
|
barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
|
||||||
|
barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||||
|
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||||
|
|
||||||
|
texture_cmd_buf->PipelineBarrier(
|
||||||
|
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0,
|
||||||
|
0, nullptr,
|
||||||
|
0, nullptr,
|
||||||
|
1, &barrier);
|
||||||
|
|
||||||
|
if (mipWidth > 1) mipWidth /= 2;
|
||||||
|
if (mipHeight > 1) mipHeight /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
barrier.subresourceRange.baseMipLevel = mipLevels - 1;
|
||||||
|
barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||||
|
barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||||
|
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||||
|
|
||||||
|
texture_cmd_buf->PipelineBarrier(
|
||||||
|
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0,
|
||||||
|
0, nullptr,
|
||||||
|
0, nullptr,
|
||||||
|
1, &barrier);
|
||||||
|
|
||||||
|
texture_cmd_buf->End();
|
||||||
|
}
|
||||||
|
|
||||||
bool GPUDevice::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
bool GPUDevice::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
||||||
{
|
{
|
||||||
if(!cmd_bufs||count<=0)
|
if(!cmd_bufs||count<=0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user