Blender V5.3
vk_copy_image_node.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
14#include "vk_node_info.hh"
15
21 VkImage src_image;
22 VkImage dst_image;
23 VkImageCopy region;
30};
31
36
37class VKCopyImageNode : public VKNodeInfo<VKNodeType::COPY_IMAGE,
38 VKCopyImageCreateInfo,
39 VKCopyImageData,
40 VK_PIPELINE_STAGE_TRANSFER_BIT,
41 VKResourceType::IMAGE> {
42 public:
50 template<typename Node, typename Storage>
51 static void set_node_data(Node &node, Storage &storage, const CreateInfo &create_info)
52 {
53 BLI_assert(create_info.node_data.mip_levels > 0);
54 node.storage_index = storage.copy_image.append_and_get_index(create_info.node_data);
55 }
56
61 VKRenderGraphLinks &links,
62 const CreateInfo &create_info) override
63 {
64 ResourceWithStamp src_resource = resources.get_image(create_info.node_data.src_image);
65 ResourceWithStamp dst_resource = resources.get_image_and_increase_stamp(
66 create_info.node_data.dst_image);
67 links.images.append({{src_resource, VK_ACCESS_TRANSFER_READ_BIT},
68 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
69 create_info.vk_image_aspect});
70 links.images.append({{dst_resource, VK_ACCESS_TRANSFER_WRITE_BIT},
71 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
72 create_info.vk_image_aspect});
73 }
74
79 Data &data,
80 Span<uint8_t> /*storage_push_constants*/,
81 VKBoundPipelines & /*r_bound_pipelines*/) override
82 {
83 /* Expand the regions to contain all requested mipmap levels. */
84 Array<VkImageCopy> regions(data.mip_levels);
85 regions.fill(data.region);
86 const VkImageCopy &src_region = regions[0];
87 for (int index : regions.index_range().drop_front(1)) {
88 regions[index].extent.width = std::max(src_region.extent.width >> index, 1u);
89 regions[index].extent.height = std::max(src_region.extent.height >> index, 1u);
90 regions[index].extent.depth = std::max(src_region.extent.depth >> index, 1u);
91 regions[index].srcSubresource.mipLevel = src_region.srcSubresource.mipLevel + index;
92 regions[index].dstSubresource.mipLevel = src_region.dstSubresource.mipLevel + index;
93 }
94
95 command_buffer.copy_image(data.src_image,
96 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
97 data.dst_image,
98 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
99 uint32_t(regions.size()),
100 regions.data());
101 }
102};
103} // namespace blender::gpu::render_graph
int64_t size() const
Definition BLI_array.hh:267
const T * data() const
Definition BLI_array.hh:323
IndexRange index_range() const
Definition BLI_array.hh:371
void fill(const T &value) const
Definition BLI_array.hh:283
constexpr IndexRange drop_front(int64_t n) const
virtual void copy_image(VkImage src_image, VkImageLayout src_image_layout, VkImage dst_image, VkImageLayout dst_image_layout, uint32_t region_count, const VkImageCopy *p_regions)=0
static void set_node_data(Node &node, Storage &storage, const CreateInfo &create_info)
void build_commands(VKCommandBufferInterface &command_buffer, Data &data, Span< uint8_t >, VKBoundPipelines &) override
void build_links(VKResourceStateTracker &resources, VKRenderGraphLinks &links, const CreateInfo &create_info) override
ResourceWithStamp get_image_and_increase_stamp(VkImage vk_image)
ResourceWithStamp get_image(VkImage vk_image) const
#define storage(slot, qualifiers)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned int uint32_t
Definition BKE_text.h:81
BMesh const char void * data
signed int int32_t
Definition BKE_text.h:78
int32_t mip_levels
The number of mip-levels to copy.