]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/texturecube_backend.cpp
Minor tweaks to MemoryAllocator
[libs/gl.git] / source / backends / vulkan / texturecube_backend.cpp
1 #include "device.h"
2 #include "texturecube.h"
3 #include "texturecube_backend.h"
4 #include "vulkan.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 VulkanTextureCube::VulkanTextureCube():
12         Texture(VK_IMAGE_VIEW_TYPE_CUBE)
13 { }
14
15 void VulkanTextureCube::fill_image_info(void *ii) const
16 {
17         const TextureCube &self = *static_cast<const TextureCube *>(this);
18
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;
25 }
26
27 void VulkanTextureCube::sub_image(unsigned face, unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
28 {
29         const TextureCube &self = *static_cast<const TextureCube *>(this);
30
31         unsigned level_size = self.get_level_size(level);
32         bool discard = (x==0 && y==0 && wd==level_size && ht==level_size);
33
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);
39                 },
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();
42
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, &region);
52                 });
53
54         stage_pixels(staging, data, wd*ht);
55         tq.finalize_transfer(staging);
56 }
57
58 void VulkanTextureCube::fill_mipmap_blit(unsigned level, void *b)
59 {
60         const TextureCube &self = *static_cast<const TextureCube *>(this);
61         VkImageBlit &blit = *static_cast<VkImageBlit *>(b);
62
63         int src_size = self.get_level_size(level);
64         int dst_size = self.get_level_size(level+1);
65
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 };
70 }
71
72 size_t VulkanTextureCube::get_data_size() const
73 {
74         return 0;
75 }
76
77 } // namespace GL
78 } // namespace Msp