fixed mipmaps autogen at Cubemap
This commit is contained in:
parent
2eef520786
commit
5d608624c0
@ -57,7 +57,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
texture =db->LoadTextureCube(OS_TEXT("res/cubemap/Storforsen4.TexCube"),false);
|
texture =db->LoadTextureCube(OS_TEXT("res/cubemap/Test.TexCube"),true);
|
||||||
|
|
||||||
if(!texture)
|
if(!texture)
|
||||||
return(false);
|
return(false);
|
||||||
|
@ -156,16 +156,15 @@ public: //Image
|
|||||||
|
|
||||||
private: //texture
|
private: //texture
|
||||||
|
|
||||||
|
bool CommitTexture (Texture *,GPUBuffer *buf,const VkBufferImageCopy *,const int count,const uint32_t layer_count,VkPipelineStageFlags);//=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||||
|
|
||||||
bool CommitTexture2D (Texture2D *,GPUBuffer *buf,VkPipelineStageFlags stage);
|
bool CommitTexture2D (Texture2D *,GPUBuffer *buf,VkPipelineStageFlags stage);
|
||||||
bool CommitTexture2DMipmaps (Texture2D *,GPUBuffer *buf,const VkExtent3D &,uint32_t);
|
bool CommitTexture2DMipmaps (Texture2D *,GPUBuffer *buf,const VkExtent3D &,uint32_t);
|
||||||
bool CommitTexture2D (Texture2D *,GPUBuffer *buf,const VkBufferImageCopy *,const int count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
|
||||||
|
|
||||||
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
|
|
||||||
|
|
||||||
|
|
||||||
bool CommitTextureCube (TextureCube *,GPUBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags stage);
|
bool CommitTextureCube (TextureCube *,GPUBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags stage);
|
||||||
bool CommitTextureCubeMipmaps (TextureCube *,GPUBuffer *buf,const VkExtent3D &,uint32_t);
|
bool CommitTextureCubeMipmaps (TextureCube *,GPUBuffer *buf,const VkExtent3D &,uint32_t);
|
||||||
bool CommitTextureCube (TextureCube *,GPUBuffer *buf,const VkBufferImageCopy *,const int count,VkPipelineStageFlags=VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
|
||||||
|
bool SubmitTexture (const VkCommandBuffer *cmd_bufs,const uint32_t count=1); ///<提交纹理处理到队列
|
||||||
|
|
||||||
public: //Texture
|
public: //Texture
|
||||||
|
|
||||||
|
@ -292,23 +292,18 @@ struct SwapchainDepthTextureCreateInfo:public TextureCreateInfo
|
|||||||
|
|
||||||
struct TextureData
|
struct TextureData
|
||||||
{
|
{
|
||||||
GPUMemory * memory =nullptr;
|
GPUMemory * memory;
|
||||||
VkImage image =VK_NULL_HANDLE;
|
VkImage image;
|
||||||
VkImageLayout image_layout=VK_IMAGE_LAYOUT_UNDEFINED;
|
VkImageLayout image_layout;
|
||||||
ImageView * image_view =nullptr;
|
ImageView * image_view;
|
||||||
uint32 miplevel =0;
|
uint32 miplevel;
|
||||||
VkImageTiling tiling =VK_IMAGE_TILING_OPTIMAL;
|
VkImageTiling tiling;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TextureData()
|
TextureData()
|
||||||
{
|
{
|
||||||
memory =nullptr;
|
hgl_zero(*this);
|
||||||
image =VK_NULL_HANDLE;
|
|
||||||
image_layout=VK_IMAGE_LAYOUT_UNDEFINED;
|
|
||||||
image_view =nullptr;
|
|
||||||
miplevel =0;
|
|
||||||
tiling =VK_IMAGE_TILING_OPTIMAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureData(const TextureCreateInfo *tci)
|
TextureData(const TextureCreateInfo *tci)
|
||||||
|
@ -114,8 +114,7 @@ SET(VK_MEMORY_SOURCE ${SG_INCLUDE_PATH}/VKMemory.h
|
|||||||
)
|
)
|
||||||
|
|
||||||
SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/BufferImageCopy2D.h
|
SET(VK_DEVICE_TEXTURE_SOURCE Vulkan/Texture/BufferImageCopy2D.h
|
||||||
Vulkan/Texture/GenMipmaps2D.cpp
|
Vulkan/Texture/GenMipmaps.cpp
|
||||||
Vulkan/Texture/GenMipmapsCube.cpp
|
|
||||||
Vulkan/Texture/VKDeviceTexture.cpp
|
Vulkan/Texture/VKDeviceTexture.cpp
|
||||||
Vulkan/Texture/VKDeviceTexture2D.cpp
|
Vulkan/Texture/VKDeviceTexture2D.cpp
|
||||||
Vulkan/Texture/VKDeviceTextureCube.cpp)
|
Vulkan/Texture/VKDeviceTextureCube.cpp)
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#include<hgl/graph/VKCommandBuffer.h>
|
#include<hgl/graph/VKCommandBuffer.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
void GenerateMipmaps2D(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels)
|
void GenerateMipmaps(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels,const uint32 layer_count)
|
||||||
{
|
{
|
||||||
ImageSubresourceRange subresourceRange(aspect_mask);
|
ImageSubresourceRange subresourceRange(aspect_mask,1,layer_count);
|
||||||
|
|
||||||
VkImageBlit blit;
|
VkImageBlit blit;
|
||||||
|
|
||||||
blit.srcOffsets[0] = {0, 0, 0};
|
blit.srcOffsets[0] = {0, 0, 0};
|
||||||
blit.srcSubresource.aspectMask = aspect_mask;
|
blit.srcSubresource.aspectMask = aspect_mask;
|
||||||
blit.srcSubresource.baseArrayLayer = 0;
|
blit.srcSubresource.baseArrayLayer = 0;
|
||||||
blit.srcSubresource.layerCount = 1;
|
blit.srcSubresource.layerCount = layer_count;
|
||||||
|
|
||||||
blit.dstOffsets[0] = {0, 0, 0};
|
blit.dstOffsets[0] = {0, 0, 0};
|
||||||
blit.dstSubresource=blit.srcSubresource;
|
blit.dstSubresource=blit.srcSubresource;
|
||||||
@ -22,15 +22,6 @@ void GenerateMipmaps2D(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAs
|
|||||||
{
|
{
|
||||||
subresourceRange.baseMipLevel = i - 1;
|
subresourceRange.baseMipLevel = i - 1;
|
||||||
|
|
||||||
texture_cmd_buf->ImageMemoryBarrier(image,
|
|
||||||
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);
|
|
||||||
|
|
||||||
blit.srcOffsets[1] = {width,height,1};
|
blit.srcOffsets[1] = {width,height,1};
|
||||||
blit.srcSubresource.mipLevel = i - 1;
|
blit.srcSubresource.mipLevel = i - 1;
|
||||||
|
|
||||||
@ -40,6 +31,15 @@ void GenerateMipmaps2D(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAs
|
|||||||
blit.dstOffsets[1] = {width,height,1};
|
blit.dstOffsets[1] = {width,height,1};
|
||||||
blit.dstSubresource.mipLevel = i;
|
blit.dstSubresource.mipLevel = i;
|
||||||
|
|
||||||
|
texture_cmd_buf->ImageMemoryBarrier(image,
|
||||||
|
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);
|
||||||
|
|
||||||
texture_cmd_buf->BlitImage(
|
texture_cmd_buf->BlitImage(
|
||||||
image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||||
image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
@ -1,70 +0,0 @@
|
|||||||
#include<hgl/graph/VKCommandBuffer.h>
|
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
|
||||||
void GenerateMipmapsCube(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels)
|
|
||||||
{
|
|
||||||
ImageSubresourceRange subresourceRange(aspect_mask);
|
|
||||||
|
|
||||||
VkImageBlit blit;
|
|
||||||
|
|
||||||
blit.srcOffsets[0] = {0, 0, 0};
|
|
||||||
blit.srcSubresource.aspectMask = aspect_mask;
|
|
||||||
blit.srcSubresource.baseArrayLayer = 0;
|
|
||||||
blit.srcSubresource.layerCount = 6;
|
|
||||||
|
|
||||||
blit.dstOffsets[0] = {0, 0, 0};
|
|
||||||
blit.dstSubresource=blit.srcSubresource;
|
|
||||||
|
|
||||||
int32_t width =extent.width;
|
|
||||||
int32_t height =extent.height;
|
|
||||||
|
|
||||||
for (uint32_t i = 1; i < mipLevels; i++)
|
|
||||||
{
|
|
||||||
subresourceRange.baseMipLevel = i - 1;
|
|
||||||
|
|
||||||
texture_cmd_buf->ImageMemoryBarrier(image,
|
|
||||||
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);
|
|
||||||
|
|
||||||
blit.srcOffsets[1] = {width,height,1};
|
|
||||||
blit.srcSubresource.mipLevel = i - 1;
|
|
||||||
|
|
||||||
if(width >1)width >>=1;
|
|
||||||
if(height>1)height>>=1;
|
|
||||||
|
|
||||||
blit.dstOffsets[1] = {width,height,1};
|
|
||||||
blit.dstSubresource.mipLevel = i;
|
|
||||||
|
|
||||||
texture_cmd_buf->BlitImage(
|
|
||||||
image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
|
||||||
image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
||||||
1, &blit,
|
|
||||||
VK_FILTER_LINEAR);
|
|
||||||
|
|
||||||
texture_cmd_buf->ImageMemoryBarrier(image,
|
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
||||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
|
|
||||||
VK_ACCESS_TRANSFER_READ_BIT,
|
|
||||||
VK_ACCESS_SHADER_READ_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
|
||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
||||||
subresourceRange);
|
|
||||||
}
|
|
||||||
|
|
||||||
subresourceRange.baseMipLevel = mipLevels - 1;
|
|
||||||
|
|
||||||
texture_cmd_buf->ImageMemoryBarrier(image,
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
VK_NAMESPACE_END
|
|
@ -1,4 +1,5 @@
|
|||||||
#include<hgl/graph/VKDevice.h>
|
#include<hgl/graph/VKDevice.h>
|
||||||
|
#include<hgl/graph/VKCommandBuffer.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
bool GPUDevice::CheckFormatSupport(const VkFormat format,const uint32_t bits,ImageTiling tiling) const
|
bool GPUDevice::CheckFormatSupport(const VkFormat format,const uint32_t bits,ImageTiling tiling) const
|
||||||
@ -22,6 +23,55 @@ void GPUDevice::Clear(TextureCreateInfo *tci)
|
|||||||
delete tci;
|
delete tci;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GPUDevice::CommitTexture(Texture *tex,GPUBuffer *buf,const VkBufferImageCopy *buffer_image_copy,const int count,const uint32_t layer_count,VkPipelineStageFlags destinationStage)
|
||||||
|
{
|
||||||
|
if(!tex||!buf)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
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)
|
bool GPUDevice::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t count)
|
||||||
{
|
{
|
||||||
if(!cmd_bufs||count<=0)
|
if(!cmd_bufs||count<=0)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include<hgl/graph/VKCommandBuffer.h>
|
#include<hgl/graph/VKCommandBuffer.h>
|
||||||
#include"BufferImageCopy2D.h"
|
#include"BufferImageCopy2D.h"
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
void GenerateMipmaps2D(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels);
|
void GenerateMipmaps(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels,const uint32_t layer_count);
|
||||||
|
|
||||||
Texture2D *GPUDevice::CreateTexture2D(TextureData *tex_data)
|
Texture2D *GPUDevice::CreateTexture2D(TextureData *tex_data)
|
||||||
{
|
{
|
||||||
@ -74,7 +74,7 @@ Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
|
|||||||
if(tci->origin_mipmaps<=1) //本身不含mipmaps数据,又想要mipmaps
|
if(tci->origin_mipmaps<=1) //本身不含mipmaps数据,又想要mipmaps
|
||||||
{
|
{
|
||||||
CommitTexture2D(tex,tci->buffer,VK_PIPELINE_STAGE_TRANSFER_BIT);
|
CommitTexture2D(tex,tci->buffer,VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||||
GenerateMipmaps2D(texture_cmd_buf,tex->GetImage(),tex->GetAspect(),tci->extent,tex_data->miplevel);
|
GenerateMipmaps(texture_cmd_buf,tex->GetImage(),tex->GetAspect(),tci->extent,tex_data->miplevel,1);
|
||||||
}
|
}
|
||||||
texture_cmd_buf->End();
|
texture_cmd_buf->End();
|
||||||
|
|
||||||
@ -87,62 +87,13 @@ Texture2D *GPUDevice::CreateTexture2D(TextureCreateInfo *tci)
|
|||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GPUDevice::CommitTexture2D(Texture2D *tex,GPUBuffer *buf,const VkBufferImageCopy *buffer_image_copy,const int count,VkPipelineStageFlags destinationStage)
|
|
||||||
{
|
|
||||||
if(!tex||!buf)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
ImageSubresourceRange subresourceRange(tex->GetAspect(),tex->GetMipLevel());
|
|
||||||
|
|
||||||
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_WRITE_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_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::CommitTexture2D(Texture2D *tex,GPUBuffer *buf,VkPipelineStageFlags destinationStage)
|
bool GPUDevice::CommitTexture2D(Texture2D *tex,GPUBuffer *buf,VkPipelineStageFlags destinationStage)
|
||||||
{
|
{
|
||||||
if(!tex||!buf)return(false);
|
if(!tex||!buf)return(false);
|
||||||
|
|
||||||
BufferImageCopy buffer_image_copy(tex);
|
BufferImageCopy buffer_image_copy(tex);
|
||||||
|
|
||||||
return CommitTexture2D(tex,buf,&buffer_image_copy,1,destinationStage);
|
return CommitTexture(tex,buf,&buffer_image_copy,1,1,destinationStage);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GPUDevice::CommitTexture2DMipmaps(Texture2D *tex,GPUBuffer *buf,const VkExtent3D &extent,uint32_t total_bytes)
|
bool GPUDevice::CommitTexture2DMipmaps(Texture2D *tex,GPUBuffer *buf,const VkExtent3D &extent,uint32_t total_bytes)
|
||||||
@ -188,7 +139,7 @@ bool GPUDevice::CommitTexture2DMipmaps(Texture2D *tex,GPUBuffer *buf,const VkExt
|
|||||||
if(height>1){height>>=1;total_bytes>>=1;}
|
if(height>1){height>>=1;total_bytes>>=1;}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommitTexture2D(tex,buf,buffer_image_copy,miplevel,VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
return CommitTexture(tex,buf,buffer_image_copy,miplevel,1,VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GPUDevice::ChangeTexture2D(Texture2D *tex,GPUBuffer *buf,const List<Image2DRegion> &ir_list,VkPipelineStageFlags destinationStage)
|
bool GPUDevice::ChangeTexture2D(Texture2D *tex,GPUBuffer *buf,const List<Image2DRegion> &ir_list,VkPipelineStageFlags destinationStage)
|
||||||
@ -225,7 +176,7 @@ bool GPUDevice::ChangeTexture2D(Texture2D *tex,GPUBuffer *buf,const List<Image2D
|
|||||||
}
|
}
|
||||||
|
|
||||||
texture_cmd_buf->Begin();
|
texture_cmd_buf->Begin();
|
||||||
bool result=CommitTexture2D(tex,buf,buffer_image_copy,ir_count,destinationStage);
|
bool result=CommitTexture(tex,buf,buffer_image_copy,ir_count,1,destinationStage);
|
||||||
texture_cmd_buf->End();
|
texture_cmd_buf->End();
|
||||||
SubmitTexture(*texture_cmd_buf);
|
SubmitTexture(*texture_cmd_buf);
|
||||||
return result;
|
return result;
|
||||||
@ -242,7 +193,7 @@ bool GPUDevice::ChangeTexture2D(Texture2D *tex,GPUBuffer *buf,uint32_t left,uint
|
|||||||
BufferImageCopy buffer_image_copy(tex);
|
BufferImageCopy buffer_image_copy(tex);
|
||||||
|
|
||||||
texture_cmd_buf->Begin();
|
texture_cmd_buf->Begin();
|
||||||
bool result=CommitTexture2D(tex,buf,&buffer_image_copy,1,destinationStage);
|
bool result=CommitTexture(tex,buf,&buffer_image_copy,1,1,destinationStage);
|
||||||
texture_cmd_buf->End();
|
texture_cmd_buf->End();
|
||||||
SubmitTexture(*texture_cmd_buf);
|
SubmitTexture(*texture_cmd_buf);
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include<hgl/graph/VKCommandBuffer.h>
|
#include<hgl/graph/VKCommandBuffer.h>
|
||||||
#include"BufferImageCopy2D.h"
|
#include"BufferImageCopy2D.h"
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
void GenerateMipmapsCube(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels);
|
void GenerateMipmaps(TextureCmdBuffer *texture_cmd_buf,VkImage image,VkImageAspectFlags aspect_mask,VkExtent3D extent,const uint32_t mipLevels,const uint32_t layer_count);
|
||||||
|
|
||||||
TextureCube *GPUDevice::CreateTextureCube(TextureData *tex_data)
|
TextureCube *GPUDevice::CreateTextureCube(TextureData *tex_data)
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ TextureCube *GPUDevice::CreateTextureCube(TextureCreateInfo *tci)
|
|||||||
if(tci->origin_mipmaps<=1) //±¾Éí²»º¬mipmapsÊý¾Ý,ÓÖÏëÒªmipmaps
|
if(tci->origin_mipmaps<=1) //±¾Éí²»º¬mipmapsÊý¾Ý,ÓÖÏëÒªmipmaps
|
||||||
{
|
{
|
||||||
CommitTextureCube(tex,tci->buffer,tci->mipmap_zero_total_bytes,VK_PIPELINE_STAGE_TRANSFER_BIT);
|
CommitTextureCube(tex,tci->buffer,tci->mipmap_zero_total_bytes,VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||||
GenerateMipmapsCube(texture_cmd_buf,tex->GetImage(),tex->GetAspect(),tci->extent,tex_data->miplevel);
|
GenerateMipmaps(texture_cmd_buf,tex->GetImage(),tex->GetAspect(),tci->extent,tex_data->miplevel,6);
|
||||||
}
|
}
|
||||||
texture_cmd_buf->End();
|
texture_cmd_buf->End();
|
||||||
|
|
||||||
@ -83,55 +83,6 @@ TextureCube *GPUDevice::CreateTextureCube(TextureCreateInfo *tci)
|
|||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GPUDevice::CommitTextureCube(TextureCube *tex,GPUBuffer *buf,const VkBufferImageCopy *buffer_image_copy,const int count,VkPipelineStageFlags destinationStage)
|
|
||||||
{
|
|
||||||
if(!tex||!buf)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
ImageSubresourceRange subresourceRange(tex->GetAspect(),tex->GetMipLevel(),6);
|
|
||||||
|
|
||||||
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_WRITE_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_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::CommitTextureCube(TextureCube *tex,GPUBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags destinationStage)
|
bool GPUDevice::CommitTextureCube(TextureCube *tex,GPUBuffer *buf,const uint32_t mipmaps_zero_bytes,VkPipelineStageFlags destinationStage)
|
||||||
{
|
{
|
||||||
if(!tex||!buf||!mipmaps_zero_bytes)return(false);
|
if(!tex||!buf||!mipmaps_zero_bytes)return(false);
|
||||||
@ -161,7 +112,7 @@ bool GPUDevice::CommitTextureCube(TextureCube *tex,GPUBuffer *buf,const uint32_t
|
|||||||
offset+=mipmaps_zero_bytes;
|
offset+=mipmaps_zero_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommitTextureCube(tex,buf,bic_list,6,destinationStage);
|
return CommitTexture(tex,buf,bic_list,6,6,destinationStage);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GPUDevice::CommitTextureCubeMipmaps(TextureCube *tex,GPUBuffer *buf,const VkExtent3D &extent,uint32_t total_bytes)
|
bool GPUDevice::CommitTextureCubeMipmaps(TextureCube *tex,GPUBuffer *buf,const VkExtent3D &extent,uint32_t total_bytes)
|
||||||
@ -219,7 +170,7 @@ bool GPUDevice::CommitTextureCubeMipmaps(TextureCube *tex,GPUBuffer *buf,const V
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CommitTextureCube(tex,buf,buffer_image_copy,miplevel*6,VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
return CommitTexture(tex,buf,buffer_image_copy,miplevel*6,6,VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool GPUDevice::ChangeTexture2D(Texture2D *tex,GPUBuffer *buf,const List<Image2DRegion> &ir_list,VkPipelineStageFlags destinationStage)
|
//bool GPUDevice::ChangeTexture2D(Texture2D *tex,GPUBuffer *buf,const List<Image2DRegion> &ir_list,VkPipelineStageFlags destinationStage)
|
||||||
|
@ -62,6 +62,8 @@ public:
|
|||||||
|
|
||||||
tci->SetData(buf,extent);
|
tci->SetData(buf,extent);
|
||||||
|
|
||||||
|
tci->origin_mipmaps=file_header.mipmaps;
|
||||||
|
|
||||||
if(auto_mipmaps&&file_header.mipmaps<=1)
|
if(auto_mipmaps&&file_header.mipmaps<=1)
|
||||||
{
|
{
|
||||||
if(device->CheckFormatSupport(format,VK_FORMAT_FEATURE_BLIT_DST_BIT))
|
if(device->CheckFormatSupport(format,VK_FORMAT_FEATURE_BLIT_DST_BIT))
|
||||||
@ -72,7 +74,6 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tci->origin_mipmaps=
|
|
||||||
tci->target_mipmaps=file_header.mipmaps;
|
tci->target_mipmaps=file_header.mipmaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user