]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/vulkan/texture2d_backend.cpp
Convert RGB pixel data to RGBA when staging
[libs/gl.git] / source / backends / vulkan / texture2d_backend.cpp
index 2d6ee131056b8975512b8a0b82c1e1e66cbb4145..3b94e766dc21ff4be2ec2b88ad4c49d7d5c7c1bf 100644 (file)
@@ -28,16 +28,20 @@ void VulkanTexture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsig
        const Texture2D &self = *static_cast<const Texture2D *>(this);
 
        auto level_size = self.get_level_size(level);
-       synchronize(-1, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (x==0 && y==0 && wd==level_size.x && ht==level_size.y));
+       bool discard = (x==0 && y==0 && wd==level_size.x && ht==level_size.y);
 
        size_t data_size = wd*ht*get_pixel_size(storage_fmt);
-       void *staging = device.get_transfer_queue().prepare_transfer(data_size,
+       void *staging = device.get_transfer_queue().prepare_transfer(this, false, data_size,
+               [this, level, discard](){
+                       unsigned n_levels = static_cast<const Texture2D *>(this)->levels;
+                       change_layout(n_levels, level, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, discard);
+               },
                [this, level, x, y, wd, ht](VkCommandBuffer cmd_buf, VkBuffer staging_buf, size_t src_off){
                        const VulkanFunctions &vk = device.get_functions();
 
                        VkBufferImageCopy region = { };
                        region.bufferOffset = src_off;
-                       region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+                       region.imageSubresource.aspectMask = get_vulkan_aspect(get_components(storage_fmt));
                        region.imageSubresource.mipLevel = level;
                        region.imageSubresource.baseArrayLayer = 0;
                        region.imageSubresource.layerCount = 1;
@@ -46,8 +50,24 @@ void VulkanTexture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsig
                        vk.CmdCopyBufferToImage(cmd_buf, staging_buf, handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
                });
 
-       const char *src = static_cast<const char *>(data);
-       copy(src, src+data_size, static_cast<char *>(staging));
+       stage_pixels(staging, data, wd*ht);
+}
+
+void VulkanTexture2D::generate_mipmap()
+{
+       generate_mipmap_levels(static_cast<const Texture2D *>(this)->levels);
+}
+
+void VulkanTexture2D::fill_mipmap_blit(unsigned level, void *b)
+{
+       const Texture2D &self = *static_cast<const Texture2D *>(this);
+       VkImageBlit &blit = *static_cast<VkImageBlit *>(b);
+
+       auto src_size = self.get_level_size(level);
+       auto dst_size = self.get_level_size(level+1);
+
+       blit.srcOffsets[1] = { static_cast<int>(src_size.x), static_cast<int>(src_size.y), 1 };
+       blit.dstOffsets[1] = { static_cast<int>(dst_size.x), static_cast<int>(dst_size.y), 1 };
 }
 
 Resource::AsyncLoader *VulkanTexture2D::load(IO::Seekable &, const Resources *)