diff --git a/include/merian/vk/descriptors/descriptor_set_update.hpp b/include/merian/vk/descriptors/descriptor_set_update.hpp index 436f3d8..f341334 100644 --- a/include/merian/vk/descriptors/descriptor_set_update.hpp +++ b/include/merian/vk/descriptors/descriptor_set_update.hpp @@ -34,6 +34,7 @@ class DescriptorSetUpdate { const vk::DeviceSize range = VK_WHOLE_SIZE, const uint32_t dst_array_element = 0, const uint32_t descriptor_count = 1) { + resources.emplace_back(buffer); return write_descriptor_buffer_type(binding, *buffer, set->get_type_for_binding(binding), offset, range, dst_array_element, descriptor_count); } @@ -100,11 +101,11 @@ class DescriptorSetUpdate { // the descriptor". If std::nullopt the current layout is used. DescriptorSetUpdate& write_descriptor_texture(const uint32_t binding, - const TextureHandle texture, + const TextureHandle& texture, const uint32_t dst_array_element = 0, const uint32_t descriptor_count = 1, const std::optional access_layout = std::nullopt) { - textures.emplace_back(texture); + resources.emplace_back(texture); return write_descriptor_image_type( binding, set->get_type_for_binding(binding), texture->get_view(), access_layout.value_or(texture->get_current_layout()), *texture->get_sampler(), @@ -171,14 +172,14 @@ class DescriptorSetUpdate { write_buffer_infos.clear(); write_image_infos.clear(); write_acceleration_structures.clear(); - textures.clear(); + resources.clear(); } private: std::shared_ptr set; std::vector writes; - std::vector textures; + std::vector resources; // vk::WriteDescriptorSet takes pointers. We must ensure that these stay valid until update() -> // use unique ptrs diff --git a/include/merian/vk/memory/resource_allocations.hpp b/include/merian/vk/memory/resource_allocations.hpp index 348671e..b6cb6b4 100644 --- a/include/merian/vk/memory/resource_allocations.hpp +++ b/include/merian/vk/memory/resource_allocations.hpp @@ -13,13 +13,16 @@ namespace merian { +class Resource {}; +using ResourceHandle = std::shared_ptr; + // Forward def class MemoryAllocation; using MemoryAllocationHandle = std::shared_ptr; class Buffer; using BufferHandle = std::shared_ptr; -class Buffer : public std::enable_shared_from_this { +class Buffer : public std::enable_shared_from_this, public Resource { public: constexpr static vk::BufferUsageFlags SCRATCH_BUFFER_USAGE = @@ -116,7 +119,7 @@ using ImageHandle = std::shared_ptr; * * Use the barrier() function to perform layout transitions to keep the internal state valid. */ -class Image : public std::enable_shared_from_this { +class Image : public std::enable_shared_from_this, public Resource { public: // Creates a Image objects that automatically destroys Image when destructed. @@ -281,7 +284,7 @@ class Image : public std::enable_shared_from_this { * Try to only use the barrier() function to perform layout transitions, * to keep the internal state valid. */ -class Texture : public std::enable_shared_from_this { +class Texture : public std::enable_shared_from_this, public Resource { public: Texture(const vk::ImageView& view, const ImageHandle& image, const SamplerHandle& sampler); @@ -340,7 +343,8 @@ class Texture : public std::enable_shared_from_this { using TextureHandle = std::shared_ptr; -class AccelerationStructure : public std::enable_shared_from_this { +class AccelerationStructure : public std::enable_shared_from_this, + public Resource { public: // Creats a AccelerationStructure objects that automatically destroys `as` when destructed. // The memory is not freed explicitly to let it free itself.