move codes.

1.add a new construct function of TextureData, it's use TextureCreateInfo params.
2.add a new construct function of BufferImageCopy.
This commit is contained in:
hyzboy 2020-11-17 14:35:04 +08:00
parent 438ffd2d36
commit 08fb9ec6d1
2 changed files with 45 additions and 27 deletions

View File

@ -3,16 +3,6 @@
#include<hgl/graph/VK.h> #include<hgl/graph/VK.h>
VK_NAMESPACE_BEGIN 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 miplevel =0;
VkImageTiling tiling =VK_IMAGE_TILING_OPTIMAL;
};//struct TextureData
struct TextureCreateInfo struct TextureCreateInfo
{ {
VkExtent3D extent; VkExtent3D extent;
@ -297,5 +287,41 @@ struct SwapchainDepthTextureCreateInfo:public TextureCreateInfo
ImageTiling::Optimal, ImageTiling::Optimal,
VK_IMAGE_LAYOUT_UNDEFINED){} VK_IMAGE_LAYOUT_UNDEFINED){}
};//struct SwapchainColorTextureCreateInfo:public TextureCreateInfo };//struct SwapchainColorTextureCreateInfo:public TextureCreateInfo
struct TextureData
{
GPUMemory * memory =nullptr;
VkImage image =VK_NULL_HANDLE;
VkImageLayout image_layout=VK_IMAGE_LAYOUT_UNDEFINED;
ImageView * image_view =nullptr;
uint32 miplevel =0;
VkImageTiling tiling =VK_IMAGE_TILING_OPTIMAL;
public:
TextureData()
{
memory =nullptr;
image =VK_NULL_HANDLE;
image_layout=VK_IMAGE_LAYOUT_UNDEFINED;
image_view =nullptr;
miplevel =0;
tiling =VK_IMAGE_TILING_OPTIMAL;
}
TextureData(const TextureCreateInfo *tci)
{
memory =tci->memory;
image =tci->image;
image_view =tci->image_view;
miplevel =tci->target_mipmaps;
tiling =VkImageTiling(tci->tiling);
if(!tci->buffer&&!tci->pixels&&tci->image_layout==VK_IMAGE_LAYOUT_UNDEFINED)
image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
else
image_layout=tci->image_layout;
}
};//struct TextureData
VK_NAMESPACE_END VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_TEXTURE_CREATE_INFO_INCLUDE #endif//HGL_GRAPH_VULKAN_TEXTURE_CREATE_INFO_INCLUDE

View File

@ -25,6 +25,12 @@ namespace
imageSubresource.aspectMask=aspect_mask; imageSubresource.aspectMask=aspect_mask;
} }
BufferImageCopy(const Texture2D *tex):BufferImageCopy()
{
imageSubresource.aspectMask=tex->GetAspect();
SetRectScope(0,0,tex->GetWidth(),tex->GetHeight());
}
void Set(const VkImageAspectFlags aspect_mask,const uint32_t layer_count) void Set(const VkImageAspectFlags aspect_mask,const uint32_t layer_count)
{ {
imageSubresource.aspectMask=aspect_mask; imageSubresource.aspectMask=aspect_mask;
@ -186,17 +192,7 @@ Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
if(!tci->image_view) if(!tci->image_view)
tci->image_view=CreateImageView2D(attr->device,tci->format,tci->extent,tci->target_mipmaps,tci->aspect,tci->image); tci->image_view=CreateImageView2D(attr->device,tci->format,tci->extent,tci->target_mipmaps,tci->aspect,tci->image);
TextureData *tex_data=new TextureData; TextureData *tex_data=new TextureData(tci);
tex_data->memory = tci->memory;
tex_data->image_layout = tci->image_layout;
tex_data->image = tci->image;
tex_data->image_view = tci->image_view;
tex_data->miplevel = tci->target_mipmaps;
tex_data->tiling = VkImageTiling(tci->tiling);
if(!tci->buffer&&!tci->pixels&&tci->image_layout==VK_IMAGE_LAYOUT_UNDEFINED)
tex_data->image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Texture2D *tex=CreateTexture2D(tex_data); Texture2D *tex=CreateTexture2D(tex_data);
@ -305,9 +301,7 @@ bool GPUDevice::CommitTexture2D(Texture2D *tex,GPUBuffer *buf,uint32_t width,uin
{ {
if(!tex||!buf)return(false); if(!tex||!buf)return(false);
BufferImageCopy buffer_image_copy(tex->GetAspect()); BufferImageCopy buffer_image_copy(tex);
buffer_image_copy.SetRectScope(0,0,width,height);
return CommitTexture2D(tex,buf,&buffer_image_copy,1,miplevel,destinationStage); return CommitTexture2D(tex,buf,&buffer_image_copy,1,miplevel,destinationStage);
} }
@ -401,9 +395,7 @@ bool GPUDevice::ChangeTexture2D(Texture2D *tex,GPUBuffer *buf,uint32_t left,uint
||width<=0||height<=0) ||width<=0||height<=0)
return(false); return(false);
BufferImageCopy buffer_image_copy(tex->GetAspect()); BufferImageCopy buffer_image_copy(tex);
buffer_image_copy.SetRectScope(left,top,width,height);
texture_cmd_buf->Begin(); texture_cmd_buf->Begin();
bool result=CommitTexture2D(tex,buf,&buffer_image_copy,1,miplevel,destinationStage); bool result=CommitTexture2D(tex,buf,&buffer_image_copy,1,miplevel,destinationStage);