image_info->imageType = VK_IMAGE_TYPE_2D;
image_info->extent.width = self.width;
image_info->extent.height = self.height;
- image_info->mipLevels = self.levels;
}
void VulkanTexture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
{
- const Texture2D &self = *static_cast<const Texture2D *>(this);
-
- auto level_size = self.get_level_size(level);
- 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(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 = get_vulkan_aspect(get_components(storage_fmt));
- region.imageSubresource.mipLevel = level;
- region.imageSubresource.baseArrayLayer = 0;
- region.imageSubresource.layerCount = 1;
- region.imageOffset = { x, y, 0 };
- region.imageExtent = { wd, ht, 1 };
- vk.CmdCopyBufferToImage(cmd_buf, staging_buf, handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
- });
-
- stage_pixels(staging, data, wd*ht);
-}
-
-void VulkanTexture2D::generate_mipmap()
-{
- generate_mipmap_levels(static_cast<const Texture2D *>(this)->levels);
+ Texture2D::AsyncTransfer transfer(*static_cast<Texture2D *>(this), level, x, y, wd, ht);
+ stage_pixels(transfer.get_address(), data, wd*ht);
}
void VulkanTexture2D::fill_mipmap_blit(unsigned level, void *b)
blit.dstOffsets[1] = { static_cast<int>(dst_size.x), static_cast<int>(dst_size.y), 1 };
}
-Resource::AsyncLoader *VulkanTexture2D::load(IO::Seekable &, const Resources *)
-{
- throw logic_error("Texture2D::load is unimplemented");
-}
-
uint64_t VulkanTexture2D::get_data_size() const
{
return 0;
{
}
+
+void *VulkanTexture2D::AsyncTransfer::allocate()
+{
+ const Texture2D::AsyncTransfer &self = *static_cast<const Texture2D::AsyncTransfer *>(this);
+
+ Texture2D &tex = *self.texture;
+ unsigned level = self.level;
+ int x = self.x;
+ int y = self.y;
+ unsigned wd = self.width;
+ unsigned ht = self.height;
+
+ auto level_size = tex.get_level_size(level);
+ bool discard = (x==0 && y==0 && wd==level_size.x && ht==level_size.y);
+
+ TransferQueue &tq = tex.device.get_transfer_queue();
+ return tq.prepare_transfer(&tex, false, self.data_size,
+ [&tex, level, discard](){
+ tex.change_layout(level, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, discard);
+ },
+ [&tex, level, x, y, wd, ht](VkCommandBuffer cmd_buf, VkBuffer staging_buf, size_t src_off){
+ const VulkanFunctions &vk = tex.device.get_functions();
+
+ VkBufferImageCopy region = { };
+ region.bufferOffset = src_off;
+ region.imageSubresource.aspectMask = get_vulkan_aspect(get_components(tex.storage_fmt));
+ region.imageSubresource.mipLevel = level;
+ region.imageSubresource.baseArrayLayer = 0;
+ region.imageSubresource.layerCount = 1;
+ region.imageOffset = { x, y, 0 };
+ region.imageExtent = { wd, ht, 1 };
+ vk.CmdCopyBufferToImage(cmd_buf, staging_buf, tex.handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
+ });
+}
+
+void VulkanTexture2D::AsyncTransfer::finalize()
+{
+ const Texture2D::AsyncTransfer &self = *static_cast<const Texture2D::AsyncTransfer *>(this);
+ self.texture->device.get_transfer_queue().finalize_transfer(self.dest_addr);
+}
+
} // namespace GL
} // namespace Msp