]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/texture1d_backend.cpp
InstanceArray doesn't need to refresh the vertex arrays
[libs/gl.git] / source / backends / vulkan / texture1d_backend.cpp
1 #include "device.h"
2 #include "texture1d.h"
3 #include "texture1d_backend.h"
4 #include "vulkan.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 VulkanTexture1D::VulkanTexture1D():
12         Texture(VK_IMAGE_VIEW_TYPE_1D)
13 { }
14
15 void VulkanTexture1D::fill_image_info(void *ii) const
16 {
17         const Texture1D &self = *static_cast<const Texture1D *>(this);
18
19         VkImageCreateInfo *image_info = static_cast<VkImageCreateInfo *>(ii);
20         image_info->imageType = VK_IMAGE_TYPE_1D;
21         image_info->extent.width = self.width;
22 }
23
24 void VulkanTexture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
25 {
26         const Texture1D &self = *static_cast<const Texture1D *>(this);
27
28         unsigned level_size = self.get_level_size(level);
29         bool discard = (x==0 && wd==level_size);
30
31         TransferQueue &tq = device.get_transfer_queue();
32         size_t data_size = wd*get_pixel_size(storage_fmt);
33         void *staging = tq.prepare_transfer(this, false, data_size,
34                 [this, level, discard](){
35                         change_layout(level, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, discard);
36                 },
37                 [this, level, x, wd](VkCommandBuffer cmd_buf, VkBuffer staging_buf, size_t src_off){
38                         const VulkanFunctions &vk = device.get_functions();
39
40                         VkBufferImageCopy region = { };
41                         region.bufferOffset = src_off;
42                         region.imageSubresource.aspectMask = get_vulkan_aspect(get_components(storage_fmt));
43                         region.imageSubresource.mipLevel = level;
44                         region.imageSubresource.baseArrayLayer = 0;
45                         region.imageSubresource.layerCount = 1;
46                         region.imageOffset = { x, 0, 0 };
47                         region.imageExtent = { wd, 1, 1 };
48                         vk.CmdCopyBufferToImage(cmd_buf, staging_buf, handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
49                 });
50
51         stage_pixels(staging, data, wd);
52         tq.finalize_transfer(staging);
53 }
54
55 void VulkanTexture1D::fill_mipmap_blit(unsigned level, void *b)
56 {
57         const Texture1D &self = *static_cast<const Texture1D *>(this);
58         VkImageBlit &blit = *static_cast<VkImageBlit *>(b);
59
60         int src_size = self.get_level_size(level);
61         int dst_size = self.get_level_size(level+1);
62
63         blit.srcOffsets[1] = { src_size, 1, 1 };
64         blit.dstOffsets[1] = { dst_size, 1, 1 };
65 }
66
67 size_t VulkanTexture1D::get_data_size() const
68 {
69         return 0;
70 }
71
72 } // namespace GL
73 } // namespace Msp