2 #include "texturecube.h"
3 #include "texturecube_backend.h"
11 VulkanTextureCube::VulkanTextureCube():
12 Texture(VK_IMAGE_VIEW_TYPE_CUBE)
15 void VulkanTextureCube::fill_image_info(void *ii) const
17 const TextureCube &self = *static_cast<const TextureCube *>(this);
19 VkImageCreateInfo *image_info = static_cast<VkImageCreateInfo *>(ii);
20 image_info->flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
21 image_info->imageType = VK_IMAGE_TYPE_2D;
22 image_info->extent.width = self.size;
23 image_info->extent.height = self.size;
24 image_info->arrayLayers = 6;
27 void VulkanTextureCube::sub_image(unsigned face, unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
29 const TextureCube &self = *static_cast<const TextureCube *>(this);
31 unsigned level_size = self.get_level_size(level);
32 bool discard = (x==0 && y==0 && wd==level_size && ht==level_size);
34 TransferQueue &tq = device.get_transfer_queue();
35 size_t data_size = wd*ht*get_pixel_size(storage_fmt);
36 void *staging = tq.prepare_transfer(this, false, data_size,
37 [this, level, discard](){
38 change_layout(level, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, discard);
40 [this, face, level, x, y, wd, ht](VkCommandBuffer cmd_buf, VkBuffer staging_buf, size_t src_off){
41 const VulkanFunctions &vk = device.get_functions();
43 VkBufferImageCopy region = { };
44 region.bufferOffset = src_off;
45 region.imageSubresource.aspectMask = get_vulkan_aspect(get_components(storage_fmt));
46 region.imageSubresource.mipLevel = level;
47 region.imageSubresource.baseArrayLayer = face;
48 region.imageSubresource.layerCount = 1;
49 region.imageOffset = { x, y, 0 };
50 region.imageExtent = { wd, ht, 1 };
51 vk.CmdCopyBufferToImage(cmd_buf, staging_buf, handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
54 stage_pixels(staging, data, wd*ht);
55 tq.finalize_transfer(staging);
58 void VulkanTextureCube::fill_mipmap_blit(unsigned level, void *b)
60 const TextureCube &self = *static_cast<const TextureCube *>(this);
61 VkImageBlit &blit = *static_cast<VkImageBlit *>(b);
63 int src_size = self.get_level_size(level);
64 int dst_size = self.get_level_size(level+1);
66 blit.srcSubresource.layerCount = 6;
67 blit.dstSubresource.layerCount = 6;
68 blit.srcOffsets[1] = { src_size, src_size, 1 };
69 blit.dstOffsets[1] = { dst_size, dst_size, 1 };
72 size_t VulkanTextureCube::get_data_size() const