From b9efaff10c1885c7edb4ce3ce34bb7efaabeaf53 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 26 Jun 2019 18:38:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=B4=E6=8E=A5=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEbuffer=E5=88=9B=E5=BB=BA=E7=BA=B9=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/vulkan/VKDevice.h | 8 +++- src/RenderDevice/Vulkan/VKDeviceBuffer.cpp | 2 + src/RenderDevice/Vulkan/VKDeviceTexture.cpp | 45 ++++++++++++++++----- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/inc/hgl/graph/vulkan/VKDevice.h b/inc/hgl/graph/vulkan/VKDevice.h index 41afad94..ab6824f9 100644 --- a/inc/hgl/graph/vulkan/VKDevice.h +++ b/inc/hgl/graph/vulkan/VKDevice.h @@ -67,8 +67,6 @@ public: public: const uint32_t GetSwapChainImageCount ()const {return attr->sc_texture.GetCount();} - //ImageView *GetColorImageView (int index) {return attr->sc_image_views[index];} - //ImageView *GetDepthImageView () {return attr->depth.view;} RenderPass * GetRenderPass () {return main_rp;} Framebuffer * GetFramebuffer (int index) {return render_frame[index];} @@ -148,11 +146,17 @@ public: //material相关 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); } + Texture2D *CreateTexture2D( const VkFormat video_format,Buffer *buf,uint32_t width,uint32_t height, + const VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT, + const uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT, + const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + Texture2D *CreateTexture2D( const VkFormat video_format,void *data,uint32_t width,uint32_t height,uint32_t size, const VkImageAspectFlags aspectMask =VK_IMAGE_ASPECT_COLOR_BIT, const uint usage =VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT, const VkImageLayout image_layout=VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + bool ChangeTexture2D(Texture2D *,Buffer *buf,uint32_t left,uint32_t top,uint32_t width,uint32_t height); bool ChangeTexture2D(Texture2D *,void *data,uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size); Sampler *CreateSampler(VkSamplerCreateInfo *); diff --git a/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp b/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp index b25b6c4f..4d487168 100644 --- a/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp +++ b/src/RenderDevice/Vulkan/VKDeviceBuffer.cpp @@ -30,6 +30,8 @@ namespace vb.info.offset =0; vb.info.range =size; + vb.memory =dm; + if(!data) return(true); diff --git a/src/RenderDevice/Vulkan/VKDeviceTexture.cpp b/src/RenderDevice/Vulkan/VKDeviceTexture.cpp index 50bea1a1..dfccd0fc 100644 --- a/src/RenderDevice/Vulkan/VKDeviceTexture.cpp +++ b/src/RenderDevice/Vulkan/VKDeviceTexture.cpp @@ -31,28 +31,39 @@ Texture2D *Device::CreateTexture2D(const VkFormat format,uint32_t width,uint32_t return VK_NAMESPACE::CreateTexture2D(attr->device,attr->physical_device,format,width,height,aspectMask,usage,image_layout,(fp.optimalTilingFeatures&VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)?VK_IMAGE_TILING_OPTIMAL:VK_IMAGE_TILING_LINEAR); } -Texture2D *Device::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) +Texture2D *Device::CreateTexture2D(const VkFormat format,Buffer *buf,uint32_t width,uint32_t height,const VkImageAspectFlags aspectMask,const uint usage,const VkImageLayout image_layout) { + if(!buf)return(nullptr); + Texture2D *tex=CreateTexture2D(format,width,height,aspectMask,usage,image_layout); if(!tex)return(nullptr); - ChangeTexture2D(tex,data,0,0,width,height,size); + ChangeTexture2D(tex,buf,0,0,width,height); return(tex); } -bool Device::ChangeTexture2D(Texture2D *tex,void *data,uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size) +Texture2D *Device::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) { - if(!tex||!data + Buffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data); + + if(!buf)return(nullptr); + + Texture2D *tex=CreateTexture2D(format,buf,width,height,aspectMask,image_layout); + + delete buf; + return(tex); +} + +bool Device::ChangeTexture2D(Texture2D *tex,Buffer *buf,uint32_t left,uint32_t top,uint32_t width,uint32_t height) +{ + if(!tex||!buf ||left<0||left+width>tex->GetWidth() ||top<0||top+height>tex->GetHeight() - ||width<=0||height<=0 - ||size<=0) + ||width<=0||height<=0) return(false); - Buffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data); - VkBufferImageCopy buffer_image_copy; buffer_image_copy.bufferOffset = 0; buffer_image_copy.bufferRowLength = 0; @@ -118,9 +129,25 @@ bool Device::ChangeTexture2D(Texture2D *tex,void *data,uint32_t left,uint32_t to texture_cmd_buf->End(); SubmitTexture(*texture_cmd_buf); + return(true); +} + +bool Device::ChangeTexture2D(Texture2D *tex,void *data,uint32_t left,uint32_t top,uint32_t width,uint32_t height,uint32_t size) +{ + if(!tex||!data + ||left<0||left+width>tex->GetWidth() + ||top<0||top+height>tex->GetHeight() + ||width<=0||height<=0 + ||size<=0) + return(false); + + Buffer *buf=CreateBuffer(VK_BUFFER_USAGE_TRANSFER_SRC_BIT,size,data); + + bool result=ChangeTexture2D(tex,buf,left,top,width,height); delete buf; - return(true); + + return(result); } bool Device::SubmitTexture(const VkCommandBuffer *cmd_bufs,const uint32_t count)