added CopyBufferToImage.h
This commit is contained in:
60
src/SceneGraph/Vulkan/Texture/CopyBufferToImage.h
Normal file
60
src/SceneGraph/Vulkan/Texture/CopyBufferToImage.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#include"BufferImageCopy2D.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct CopyBufferToImageInfo
|
||||
{
|
||||
VkImage image;
|
||||
VkBuffer buffer;
|
||||
|
||||
VkImageSubresourceRange isr;
|
||||
|
||||
const VkBufferImageCopy * bic_list;
|
||||
uint32_t bic_count;
|
||||
|
||||
public:
|
||||
|
||||
CopyBufferToImageInfo()
|
||||
{
|
||||
hgl_zero(*this);
|
||||
}
|
||||
|
||||
CopyBufferToImageInfo(Texture *tex,VkBuffer buf,const VkBufferImageCopy *bic)
|
||||
{
|
||||
image =tex->GetImage();
|
||||
buffer =buf;
|
||||
|
||||
isr.aspectMask =tex->GetAspect();
|
||||
|
||||
isr.baseMipLevel =0;
|
||||
isr.levelCount =tex->GetMipLevel();
|
||||
|
||||
isr.baseArrayLayer =0;
|
||||
isr.layerCount =1;
|
||||
|
||||
bic_list =bic;
|
||||
bic_count =1;
|
||||
}
|
||||
};
|
||||
|
||||
struct CopyBufferToImageMipmapsInfo:public CopyBufferToImageInfo
|
||||
{
|
||||
CopyBufferToImageMipmapsInfo(Texture2D *tex,VkBuffer buf,const VkBufferImageCopy *bic,const uint32_t miplevel)
|
||||
{
|
||||
image =tex->GetImage();
|
||||
buffer =buf;
|
||||
|
||||
isr.aspectMask =tex->GetAspect();
|
||||
|
||||
isr.baseMipLevel =0;
|
||||
isr.levelCount =tex->GetMipLevel();
|
||||
|
||||
isr.baseArrayLayer =0;
|
||||
isr.layerCount =1;
|
||||
|
||||
bic_list =bic;
|
||||
bic_count =miplevel;
|
||||
}
|
||||
};
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -1,6 +1,7 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include"CopyBufferToImage.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
bool GPUDevice::CheckFormatSupport(const VkFormat format,const uint32_t bits,ImageTiling tiling) const
|
||||
@@ -94,52 +95,6 @@ bool GPUDevice::CopyBufferToImage(Texture *tex,DeviceBuffer *buf,const VkBufferI
|
||||
info.bic_count =count;
|
||||
|
||||
return CopyBufferToImage(&info,destinationStage);
|
||||
|
||||
//下面这段是原始能跑的,上面的是走新的接口的,本质一样,待完全测试后,删掉下面的。
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
//ImageSubresourceRange subresourceRange(tex->GetAspect(),tex->GetMipLevel(),layer_count);
|
||||
|
||||
//texture_cmd_buf->ImageMemoryBarrier(tex->GetImage(),
|
||||
// VK_PIPELINE_STAGE_HOST_BIT,
|
||||
// VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
// 0,
|
||||
// VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
// VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
// VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
// subresourceRange);
|
||||
|
||||
//texture_cmd_buf->CopyBufferToImage(
|
||||
// buf->GetBuffer(),
|
||||
// tex->GetImage(),
|
||||
// VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
// count,
|
||||
// buffer_image_copy);
|
||||
|
||||
//if(destinationStage==VK_PIPELINE_STAGE_TRANSFER_BIT) //接下来还有,一般是给自动生成mipmaps
|
||||
//{
|
||||
// //texture_cmd_buf->ImageMemoryBarrier(tex->GetImage(),
|
||||
// // VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
// // VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
// // VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
// // VK_ACCESS_TRANSFER_READ_BIT,
|
||||
// // VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
// // VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
// // subresourceRange);
|
||||
//}
|
||||
//else// if(destinationStage==VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT) //接下来就给fragment shader用了,证明是最后一步
|
||||
//{
|
||||
// texture_cmd_buf->ImageMemoryBarrier(tex->GetImage(),
|
||||
// VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
// VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
|
||||
// VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
// VK_ACCESS_SHADER_READ_BIT,
|
||||
// VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
// VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
// subresourceRange);
|
||||
//}
|
||||
|
||||
//return(true);
|
||||
}
|
||||
|
||||
bool GPUDevice::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
||||
|
@@ -2,7 +2,8 @@
|
||||
#include<hgl/graph/VKImageCreateInfo.h>
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include"BufferImageCopy2D.h"
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include"CopyBufferToImage.h"
|
||||
VK_NAMESPACE_BEGIN
|
||||
void GenerateMipmaps(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels,const uint32_t layer_count);
|
||||
|
||||
@@ -94,7 +95,9 @@ bool GPUDevice::CommitTexture2D(Texture2D *tex,DeviceBuffer *buf,VkPipelineStage
|
||||
|
||||
BufferImageCopy buffer_image_copy(tex);
|
||||
|
||||
return CopyBufferToImage(tex,buf,&buffer_image_copy,1,1,destinationStage);
|
||||
CopyBufferToImageInfo info(tex,buf->GetBuffer(),&buffer_image_copy);
|
||||
|
||||
return CopyBufferToImage(&info,destinationStage);
|
||||
}
|
||||
|
||||
bool GPUDevice::CommitTexture2DMipmaps(Texture2D *tex,DeviceBuffer *buf,const VkExtent3D &extent,uint32_t total_bytes)
|
||||
@@ -140,7 +143,9 @@ bool GPUDevice::CommitTexture2DMipmaps(Texture2D *tex,DeviceBuffer *buf,const Vk
|
||||
if(height>1){height>>=1;total_bytes>>=1;}
|
||||
}
|
||||
|
||||
return CopyBufferToImage(tex,buf,buffer_image_copy,miplevel,1,VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
CopyBufferToImageMipmapsInfo info(tex,buf->GetBuffer(),buffer_image_copy,miplevel);
|
||||
|
||||
return CopyBufferToImage(&info,VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
}
|
||||
|
||||
bool GPUDevice::ChangeTexture2D(Texture2D *tex,DeviceBuffer *buf,const List<Image2DRegion> &ir_list,VkPipelineStageFlags destinationStage)
|
||||
|
Reference in New Issue
Block a user