3 #include "texture1d_backend.h"
11 VulkanTexture1D::VulkanTexture1D():
12 Texture(VK_IMAGE_VIEW_TYPE_1D)
15 void VulkanTexture1D::fill_image_info(void *ii) const
17 const Texture1D &self = *static_cast<const Texture1D *>(this);
19 VkImageCreateInfo *image_info = static_cast<VkImageCreateInfo *>(ii);
20 image_info->imageType = VK_IMAGE_TYPE_1D;
21 image_info->extent.width = self.width;
22 image_info->mipLevels = self.levels;
25 void VulkanTexture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
27 const Texture1D &self = *static_cast<const Texture1D *>(this);
29 unsigned level_size = self.get_level_size(level);
30 synchronize(-1, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (x==0 && wd==level_size));
32 size_t data_size = wd*get_pixel_size(storage_fmt);
33 void *staging = device.get_transfer_queue().prepare_transfer(data_size,
34 [this, level, x, wd](VkCommandBuffer cmd_buf, VkBuffer staging_buf, size_t src_off){
35 const VulkanFunctions &vk = device.get_functions();
37 VkBufferImageCopy region = { };
38 region.bufferOffset = src_off;
39 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
40 region.imageSubresource.mipLevel = level;
41 region.imageSubresource.baseArrayLayer = 0;
42 region.imageSubresource.layerCount = 1;
43 region.imageOffset = { x, 0, 0 };
44 region.imageExtent = { wd, 1, 1 };
45 vk.CmdCopyBufferToImage(cmd_buf, staging_buf, handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
48 const char *src = static_cast<const char *>(data);
49 copy(src, src+data_size, static_cast<char *>(staging));
52 size_t VulkanTexture1D::get_data_size() const