X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbackends%2Fvulkan%2Ftexture2d_backend.cpp;h=2d6ee131056b8975512b8a0b82c1e1e66cbb4145;hp=a80e1f945e280ebcfbc422bd62eea127528aa2d3;hb=a16145549dc87c3b12671f797bd77b14bcc7786b;hpb=bbdf52425b736a59d01dda215458c3a1c9bdb320 diff --git a/source/backends/vulkan/texture2d_backend.cpp b/source/backends/vulkan/texture2d_backend.cpp index a80e1f94..2d6ee131 100644 --- a/source/backends/vulkan/texture2d_backend.cpp +++ b/source/backends/vulkan/texture2d_backend.cpp @@ -1,3 +1,5 @@ +#include "device.h" +#include "texture2d.h" #include "texture2d_backend.h" #include "vulkan.h" @@ -10,9 +12,42 @@ VulkanTexture2D::VulkanTexture2D(): Texture(VK_IMAGE_VIEW_TYPE_2D) { } -void VulkanTexture2D::sub_image(unsigned, int, int, unsigned, unsigned, const void *) +void VulkanTexture2D::fill_image_info(void *ii) const { - throw logic_error("Texture2D::sub_image is unimplemented"); + const Texture2D &self = *static_cast(this); + + VkImageCreateInfo *image_info = static_cast(ii); + image_info->imageType = VK_IMAGE_TYPE_2D; + image_info->extent.width = self.width; + image_info->extent.height = self.height; + image_info->mipLevels = self.levels; +} + +void VulkanTexture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data) +{ + const Texture2D &self = *static_cast(this); + + auto level_size = self.get_level_size(level); + synchronize(-1, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (x==0 && y==0 && wd==level_size.x && ht==level_size.y)); + + size_t data_size = wd*ht*get_pixel_size(storage_fmt); + void *staging = device.get_transfer_queue().prepare_transfer(data_size, + [this, level, x, y, wd, ht](VkCommandBuffer cmd_buf, VkBuffer staging_buf, size_t src_off){ + const VulkanFunctions &vk = device.get_functions(); + + VkBufferImageCopy region = { }; + region.bufferOffset = src_off; + region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + region.imageSubresource.mipLevel = level; + region.imageSubresource.baseArrayLayer = 0; + region.imageSubresource.layerCount = 1; + region.imageOffset = { x, y, 0 }; + region.imageExtent = { wd, ht, 1 }; + vk.CmdCopyBufferToImage(cmd_buf, staging_buf, handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); + }); + + const char *src = static_cast(data); + copy(src, src+data_size, static_cast(staging)); } Resource::AsyncLoader *VulkanTexture2D::load(IO::Seekable &, const Resources *)