3 #include "texture3d_backend.h"
11 VulkanTexture3D::VulkanTexture3D():
12 Texture(VK_IMAGE_VIEW_TYPE_3D)
15 VulkanTexture3D::VulkanTexture3D(unsigned t):
19 void VulkanTexture3D::fill_image_info(void *ii) const
21 const Texture3D &self = *static_cast<const Texture3D *>(this);
23 VkImageCreateInfo *image_info = static_cast<VkImageCreateInfo *>(ii);
24 image_info->imageType = VK_IMAGE_TYPE_3D;
25 image_info->extent.width = self.width;
26 image_info->extent.height = self.height;
27 image_info->extent.depth = self.depth;
28 image_info->mipLevels = self.levels;
31 void VulkanTexture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsigned ht, unsigned dp, const void *data)
33 const Texture3D &self = *static_cast<const Texture3D *>(this);
35 auto level_size = self.get_level_size(level);
36 bool discard = (x==0 && y==0 && z==0 && wd==level_size.x && ht==level_size.y && dp==level_size.z);
37 change_layout(self.levels, level, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, discard);
39 size_t data_size = wd*ht*dp*get_pixel_size(storage_fmt);
40 void *staging = device.get_transfer_queue().prepare_transfer(data_size,
41 [this, level, x, y, z, wd, ht, dp](VkCommandBuffer cmd_buf, VkBuffer staging_buf, size_t src_off){
42 const VulkanFunctions &vk = device.get_functions();
44 VkBufferImageCopy region = { };
45 region.bufferOffset = src_off;
46 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
47 region.imageSubresource.mipLevel = level;
48 region.imageSubresource.baseArrayLayer = (is_array() ? z : 0);
49 region.imageSubresource.layerCount = (is_array() ? dp : 1);
50 region.imageOffset = { x, y, (is_array() ? 0 : z) };
51 region.imageExtent = { wd, ht, (is_array() ? 1 : dp) };
52 vk.CmdCopyBufferToImage(cmd_buf, staging_buf, handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
55 const char *src = static_cast<const char *>(data);
56 copy(src, src+data_size, static_cast<char *>(staging));
59 bool VulkanTexture3D::is_array() const
61 return view_type==VK_IMAGE_VIEW_TYPE_2D_ARRAY;
64 size_t VulkanTexture3D::get_data_size() const