From ba74750109e7fd321f2ebfaf543785a191f650d1 Mon Sep 17 00:00:00 2001 From: jyxiong Date: Tue, 10 Sep 2024 00:31:52 +0800 Subject: [PATCH] dev: copy & move & ctor & dtor --- src/prism/vulkan/command_buffer.cpp | 7 +++++++ src/prism/vulkan/command_buffer.h | 10 +++++++++- src/prism/vulkan/command_pool.cpp | 6 ++++++ src/prism/vulkan/command_pool.h | 9 +++++++++ src/prism/vulkan/compute_pipeline.cpp | 6 ++++++ src/prism/vulkan/compute_pipeline.h | 8 ++++++++ src/prism/vulkan/descriptor_pool.cpp | 8 ++++++++ src/prism/vulkan/descriptor_pool.h | 9 +++++++++ src/prism/vulkan/descriptor_set.cpp | 8 ++++++++ src/prism/vulkan/descriptor_set.h | 9 +++++++++ src/prism/vulkan/descriptor_set_layout.cpp | 7 +++++++ src/prism/vulkan/descriptor_set_layout.h | 9 +++++++++ src/prism/vulkan/device.h | 9 +++++++++ src/prism/vulkan/device_memory.cpp | 8 ++++++++ src/prism/vulkan/device_memory.h | 8 ++++++++ src/prism/vulkan/fence.cpp | 6 ++++++ src/prism/vulkan/fence.h | 8 ++++++++ src/prism/vulkan/image.cpp | 8 ++++++++ src/prism/vulkan/image.h | 8 ++++++++ src/prism/vulkan/image_view.cpp | 8 ++++++++ src/prism/vulkan/image_view.h | 8 ++++++++ src/prism/vulkan/instance.h | 8 ++++++++ src/prism/vulkan/physical_device.h | 8 ++++++++ src/prism/vulkan/pipeline_layout.cpp | 6 ++++++ src/prism/vulkan/pipeline_layout.h | 8 ++++++++ src/prism/vulkan/queue.cpp | 9 +++++++++ src/prism/vulkan/queue.h | 9 +++++++++ src/prism/vulkan/sampler.cpp | 7 +++++++ src/prism/vulkan/sampler.h | 8 ++++++++ src/prism/vulkan/semaphore.cpp | 6 ++++++ src/prism/vulkan/semaphore.h | 8 ++++++++ src/prism/vulkan/shader_module.cpp | 8 ++++++++ src/prism/vulkan/shader_module.h | 9 +++++++++ src/prism/vulkan/surface.h | 8 ++++++++ src/prism/vulkan/swapchain.cpp | 10 ++++++++++ src/prism/vulkan/swapchain.h | 8 ++++++++ 36 files changed, 286 insertions(+), 1 deletion(-) diff --git a/src/prism/vulkan/command_buffer.cpp b/src/prism/vulkan/command_buffer.cpp index 7d2d0d9..78c937e 100644 --- a/src/prism/vulkan/command_buffer.cpp +++ b/src/prism/vulkan/command_buffer.cpp @@ -17,6 +17,13 @@ CommandBuffer::CommandBuffer(const CommandPool &cmd_pool, VkCommandBufferLevel l VK_CHECK(vkAllocateCommandBuffers(m_device.get_handle(), &allocate_info, &m_handle)); } +CommandBuffer::CommandBuffer(CommandBuffer &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device), + m_cmd_pool(other.m_cmd_pool) +{ +} + CommandBuffer::~CommandBuffer() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/command_buffer.h b/src/prism/vulkan/command_buffer.h index 012cae7..f5a1483 100644 --- a/src/prism/vulkan/command_buffer.h +++ b/src/prism/vulkan/command_buffer.h @@ -10,9 +10,17 @@ namespace prism { public: CommandBuffer(const CommandPool &cmd_pool, VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY); - + + CommandBuffer(const CommandBuffer &) = delete; + + CommandBuffer(CommandBuffer &&other) noexcept; + ~CommandBuffer(); + CommandBuffer& operator=(const CommandBuffer &) = delete; + + CommandBuffer& operator=(CommandBuffer &&) = delete; + const VkCommandBuffer &get_handle() const; void begin(VkCommandBufferUsageFlags flags = 0); diff --git a/src/prism/vulkan/command_pool.cpp b/src/prism/vulkan/command_pool.cpp index c258258..6b5e337 100644 --- a/src/prism/vulkan/command_pool.cpp +++ b/src/prism/vulkan/command_pool.cpp @@ -15,6 +15,12 @@ CommandPool::CommandPool(const Device &device, uint32_t queue_family_index, VkCo VK_CHECK(vkCreateCommandPool(m_device.get_handle(), &pool_info, nullptr, &m_handle)); } +CommandPool::CommandPool(CommandPool &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device) +{ +} + CommandPool::~CommandPool() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/command_pool.h b/src/prism/vulkan/command_pool.h index 1d4921a..3850c6e 100644 --- a/src/prism/vulkan/command_pool.h +++ b/src/prism/vulkan/command_pool.h @@ -10,8 +10,17 @@ namespace prism { public: CommandPool(const Device &device, uint32_t queue_family_index, VkCommandPoolCreateFlags flags = 0); + + CommandPool(const CommandPool &) = delete; + + CommandPool(CommandPool &&other) noexcept; + ~CommandPool(); + CommandPool& operator=(const CommandPool &) = delete; + + CommandPool& operator=(CommandPool &&) = delete; + VkCommandPool get_handle() const; const Device &get_device() const; diff --git a/src/prism/vulkan/compute_pipeline.cpp b/src/prism/vulkan/compute_pipeline.cpp index 29dc88f..5cae65a 100644 --- a/src/prism/vulkan/compute_pipeline.cpp +++ b/src/prism/vulkan/compute_pipeline.cpp @@ -21,6 +21,12 @@ ComputePipeline::ComputePipeline(const Device &device, const PipelineLayout &pip VK_CHECK(vkCreateComputePipelines(m_device.get_handle(), VK_NULL_HANDLE, 1, &pipeline_info, nullptr, &m_handle)); } +ComputePipeline::ComputePipeline(ComputePipeline &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device) +{ +} + ComputePipeline::~ComputePipeline() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/compute_pipeline.h b/src/prism/vulkan/compute_pipeline.h index dad5fd7..2f063fa 100644 --- a/src/prism/vulkan/compute_pipeline.h +++ b/src/prism/vulkan/compute_pipeline.h @@ -11,8 +11,16 @@ namespace prism public: ComputePipeline(const Device &device, const PipelineLayout &pipeline_layout, const ShaderModule& shader_module); + ComputePipeline(const ComputePipeline &) = delete; + + ComputePipeline(ComputePipeline &&other) noexcept; + ~ComputePipeline(); + ComputePipeline& operator=(const ComputePipeline &) = delete; + + ComputePipeline& operator=(ComputePipeline &&) = delete; + const VkPipeline &get_handle() const; private: diff --git a/src/prism/vulkan/descriptor_pool.cpp b/src/prism/vulkan/descriptor_pool.cpp index 984f760..39d57db 100644 --- a/src/prism/vulkan/descriptor_pool.cpp +++ b/src/prism/vulkan/descriptor_pool.cpp @@ -17,6 +17,14 @@ DescriptorPool::DescriptorPool(const Device &device, const std::vector &pool_sizes, uint32_t max_sets); + + DescriptorPool(const DescriptorPool &) = delete; + + DescriptorPool(DescriptorPool &&other) noexcept; + ~DescriptorPool(); + DescriptorPool& operator=(const DescriptorPool &) = delete; + + DescriptorPool& operator=(DescriptorPool &&) = delete; + VkDescriptorSet allocate(const VkDescriptorSetLayout &layout); void free(const VkDescriptorSet &descriptor_set); diff --git a/src/prism/vulkan/descriptor_set.cpp b/src/prism/vulkan/descriptor_set.cpp index f822208..300a94d 100644 --- a/src/prism/vulkan/descriptor_set.cpp +++ b/src/prism/vulkan/descriptor_set.cpp @@ -17,6 +17,14 @@ DescriptorSet::DescriptorSet(const Device &device, const DescriptorSetLayout& la VK_CHECK(vkAllocateDescriptorSets(device.get_handle(), &alloc_info, &m_handle)); } +DescriptorSet::DescriptorSet(DescriptorSet &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device), + m_layout(other.m_layout), + m_pool(other.m_pool) +{ +} + DescriptorSet::~DescriptorSet() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/descriptor_set.h b/src/prism/vulkan/descriptor_set.h index 514b763..0a8071e 100644 --- a/src/prism/vulkan/descriptor_set.h +++ b/src/prism/vulkan/descriptor_set.h @@ -10,8 +10,17 @@ namespace prism { public: DescriptorSet(const Device &device, const DescriptorSetLayout& layout, const DescriptorPool& pool); + + DescriptorSet(const DescriptorSet &) = delete; + + DescriptorSet(DescriptorSet &&other) noexcept; + ~DescriptorSet(); + DescriptorSet& operator=(const DescriptorSet &) = delete; + + DescriptorSet& operator=(DescriptorSet &&) = delete; + void update(const std::vector &buffer_infos); const VkDescriptorSet& get_handle() const; diff --git a/src/prism/vulkan/descriptor_set_layout.cpp b/src/prism/vulkan/descriptor_set_layout.cpp index c6cb533..c45ad81 100644 --- a/src/prism/vulkan/descriptor_set_layout.cpp +++ b/src/prism/vulkan/descriptor_set_layout.cpp @@ -15,6 +15,13 @@ DescriptorSetLayout::DescriptorSetLayout(const Device &device, const Bindings &b VK_CHECK(vkCreateDescriptorSetLayout(m_device.get_handle(), &layout_info, nullptr, &m_handle)); } +DescriptorSetLayout::DescriptorSetLayout(DescriptorSetLayout &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device), + m_bindings(std::move(other.m_bindings)) +{ +} + DescriptorSetLayout::~DescriptorSetLayout() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/descriptor_set_layout.h b/src/prism/vulkan/descriptor_set_layout.h index 54f73d1..8d9343e 100644 --- a/src/prism/vulkan/descriptor_set_layout.h +++ b/src/prism/vulkan/descriptor_set_layout.h @@ -11,8 +11,17 @@ namespace prism public: DescriptorSetLayout(const Device &device, const Bindings &bindings); + + DescriptorSetLayout(const DescriptorSetLayout &) = delete; + + DescriptorSetLayout(DescriptorSetLayout &&other) noexcept; + ~DescriptorSetLayout(); + DescriptorSetLayout &operator=(const DescriptorSetLayout &) = delete; + + DescriptorSetLayout &operator=(DescriptorSetLayout &&) = delete; + const VkDescriptorSetLayout &get_handle() const; std::vector get_descriptor_pool_sizes() const; diff --git a/src/prism/vulkan/device.h b/src/prism/vulkan/device.h index 32a311a..b5022e1 100644 --- a/src/prism/vulkan/device.h +++ b/src/prism/vulkan/device.h @@ -14,8 +14,17 @@ namespace prism public: Device(const PhysicalDevice &physical_device, const ExtensionNames &extensions, const DeviceFeatures &features); + + Device(const Device &) = delete; + + Device(Device &&other) = delete; + ~Device(); + Device &operator=(const Device &) = delete; + + Device &operator=(Device &&) = delete; + VkDevice get_handle() const; const PhysicalDevice &get_physical_device() const; diff --git a/src/prism/vulkan/device_memory.cpp b/src/prism/vulkan/device_memory.cpp index 910d743..4cfad3d 100644 --- a/src/prism/vulkan/device_memory.cpp +++ b/src/prism/vulkan/device_memory.cpp @@ -39,6 +39,14 @@ DeviceMemory::DeviceMemory(const Device &device, const VkMemoryRequirements &req VK_CHECK(vkAllocateMemory(m_device.get_handle(), &allocate_info, nullptr, &m_handle)); } +DeviceMemory::DeviceMemory(DeviceMemory &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device), + m_requirements(other.m_requirements), + m_property_flags(other.m_property_flags) +{ +} + DeviceMemory::~DeviceMemory() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/device_memory.h b/src/prism/vulkan/device_memory.h index 02ebe08..6b3bacb 100644 --- a/src/prism/vulkan/device_memory.h +++ b/src/prism/vulkan/device_memory.h @@ -9,8 +9,16 @@ namespace prism public: DeviceMemory(const Device& device, const VkMemoryRequirements& requirements, VkMemoryPropertyFlags property_flags, VkMemoryAllocateFlags allocate_flags = 0); + DeviceMemory(const DeviceMemory&) = delete; + + DeviceMemory(DeviceMemory&& other) noexcept; + ~DeviceMemory(); + DeviceMemory& operator=(const DeviceMemory&) = delete; + + DeviceMemory& operator=(DeviceMemory&&) = delete; + void copy(VkDeviceSize offset, VkDeviceSize size, const void* src_data); void map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void** ppData); diff --git a/src/prism/vulkan/fence.cpp b/src/prism/vulkan/fence.cpp index 52d79f7..f0efa70 100644 --- a/src/prism/vulkan/fence.cpp +++ b/src/prism/vulkan/fence.cpp @@ -14,6 +14,12 @@ Fence::Fence(const Device& device, VkFenceCreateFlags flags) VK_CHECK(vkCreateFence(device.get_handle(), &create_info, nullptr, &m_handle)); } +Fence::Fence(Fence&& other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device) +{ +} + Fence::~Fence() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/fence.h b/src/prism/vulkan/fence.h index 4006239..a50b07b 100644 --- a/src/prism/vulkan/fence.h +++ b/src/prism/vulkan/fence.h @@ -9,8 +9,16 @@ namespace prism public: Fence(const Device& device, VkFenceCreateFlags flags = 0); + Fence(const Fence&) = delete; + + Fence(Fence&& other) noexcept; + ~Fence(); + Fence& operator=(const Fence&) = delete; + + Fence& operator=(Fence&&) = delete; + void wait(uint64_t timeout = UINT64_MAX); void reset(); diff --git a/src/prism/vulkan/image.cpp b/src/prism/vulkan/image.cpp index 337b5ae..a4f20a7 100644 --- a/src/prism/vulkan/image.cpp +++ b/src/prism/vulkan/image.cpp @@ -107,6 +107,14 @@ Image::Image(const Device &device, const ImageCreateInfo& info) vkGetImageMemoryRequirements(m_device.get_handle(), m_handle, &m_memory_requirements); } +Image::Image(Image &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device), + m_info(other.m_info), + m_memory_requirements(other.m_memory_requirements) +{ +} + Image::~Image() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/image.h b/src/prism/vulkan/image.h index fb495f5..6834282 100644 --- a/src/prism/vulkan/image.h +++ b/src/prism/vulkan/image.h @@ -41,8 +41,16 @@ namespace prism Image(const Device &device, const ImageCreateInfo &create_info); + Image(const Image &) = delete; + + Image(Image &&other) noexcept; + virtual ~Image(); + Image &operator=(const Image &) = delete; + + Image &operator=(Image &&) = delete; + const Device &get_device() const; VkImage get_handle() const; diff --git a/src/prism/vulkan/image_view.cpp b/src/prism/vulkan/image_view.cpp index 394d784..bdfde52 100644 --- a/src/prism/vulkan/image_view.cpp +++ b/src/prism/vulkan/image_view.cpp @@ -137,6 +137,14 @@ ImageView::ImageView(const Image &image, const ImageViewCreateInfo &info) VK_CHECK(vkCreateImageView(m_device.get_handle(), &m_info, nullptr, &m_handle)); } +ImageView::ImageView(ImageView &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device), + m_image(other.m_image), + m_info(other.m_info) +{ +} + ImageView::~ImageView() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/image_view.h b/src/prism/vulkan/image_view.h index 817beba..13b6560 100644 --- a/src/prism/vulkan/image_view.h +++ b/src/prism/vulkan/image_view.h @@ -34,8 +34,16 @@ namespace prism public: ImageView(const Image &image, const ImageViewCreateInfo& info); + ImageView(const ImageView &) = delete; + + ImageView(ImageView &&other) noexcept; + ~ImageView(); + ImageView &operator=(const ImageView &) = delete; + + ImageView &operator=(ImageView &&) = delete; + const VkImageView &get_handle() const; private: diff --git a/src/prism/vulkan/instance.h b/src/prism/vulkan/instance.h index 33d8bf2..70b1578 100644 --- a/src/prism/vulkan/instance.h +++ b/src/prism/vulkan/instance.h @@ -14,8 +14,16 @@ namespace prism public: Instance(const ExtensionNames &extensions, const LayerNames& layers); + Instance(const Instance &) = delete; + + Instance(Instance &&other) = delete; + ~Instance(); + Instance &operator=(const Instance &) = delete; + + Instance &operator=(Instance &&) = delete; + VkInstance get_handle() const; const PhysicalDevice& pick_physical_device() const; diff --git a/src/prism/vulkan/physical_device.h b/src/prism/vulkan/physical_device.h index d611e36..5096f61 100644 --- a/src/prism/vulkan/physical_device.h +++ b/src/prism/vulkan/physical_device.h @@ -7,8 +7,16 @@ namespace prism public: PhysicalDevice(VkPhysicalDevice physical_device); + PhysicalDevice(const PhysicalDevice &) = delete; + + PhysicalDevice(PhysicalDevice &&) = delete; + ~PhysicalDevice() = default; + PhysicalDevice &operator=(const PhysicalDevice &) = delete; + + PhysicalDevice &operator=(PhysicalDevice &&) = delete; + VkPhysicalDevice get_handle() const; const VkPhysicalDeviceFeatures &get_features() const; diff --git a/src/prism/vulkan/pipeline_layout.cpp b/src/prism/vulkan/pipeline_layout.cpp index c071071..67153f8 100644 --- a/src/prism/vulkan/pipeline_layout.cpp +++ b/src/prism/vulkan/pipeline_layout.cpp @@ -37,6 +37,12 @@ PipelineLayout::PipelineLayout(const Device &device, const std::vector &descriptor_set_layouts); + PipelineLayout(const PipelineLayout &) = delete; + + PipelineLayout(PipelineLayout &&other) noexcept; + ~PipelineLayout(); + PipelineLayout& operator=(const PipelineLayout &) = delete; + + PipelineLayout& operator=(PipelineLayout &&) = delete; + const VkPipelineLayout &get_handle() const; private: diff --git a/src/prism/vulkan/queue.cpp b/src/prism/vulkan/queue.cpp index d18b471..c75ecf3 100644 --- a/src/prism/vulkan/queue.cpp +++ b/src/prism/vulkan/queue.cpp @@ -10,6 +10,15 @@ Queue::Queue(VkQueue queue, uint32_t family_index, uint32_t index) { } +Queue::Queue(Queue &&other) noexcept + : m_handle(std::exchange(other.m_handle, nullptr)), + m_family_index(std::exchange(other.m_family_index, 0)), + m_index(std::exchange(other.m_index, 0)), + m_can_present(std::exchange(other.m_can_present, VK_FALSE)), + m_properties(std::exchange(other.m_properties, {})) +{ +} + Queue::~Queue() { } diff --git a/src/prism/vulkan/queue.h b/src/prism/vulkan/queue.h index cc3958f..ef421d2 100644 --- a/src/prism/vulkan/queue.h +++ b/src/prism/vulkan/queue.h @@ -8,8 +8,17 @@ namespace prism { public: Queue(VkQueue queue, uint32_t family_index, uint32_t index); + + Queue(const Queue &) = default; + + Queue(Queue &&other) noexcept; + ~Queue(); + Queue &operator=(const Queue &) = delete; + + Queue &operator=(Queue &&) = delete; + VkQueue get_handle() const; uint32_t get_family_index() const; diff --git a/src/prism/vulkan/sampler.cpp b/src/prism/vulkan/sampler.cpp index 6f91657..95ae2ae 100644 --- a/src/prism/vulkan/sampler.cpp +++ b/src/prism/vulkan/sampler.cpp @@ -128,6 +128,13 @@ Sampler::Sampler(const Device &device, const SamplerCreateInfo &create_info) VK_CHECK(vkCreateSampler(m_device.get_handle(), &m_info, nullptr, &m_handle)); } +Sampler::Sampler(Sampler &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device), + m_info(other.m_info) +{ +} + Sampler::~Sampler() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/sampler.h b/src/prism/vulkan/sampler.h index 87ef090..9cd10af 100644 --- a/src/prism/vulkan/sampler.h +++ b/src/prism/vulkan/sampler.h @@ -47,8 +47,16 @@ namespace prism public: Sampler(const Device &device, const SamplerCreateInfo &create_info); + Sampler(const Sampler &) = delete; + + Sampler(Sampler &&other) noexcept; + ~Sampler(); + Sampler &operator=(const Sampler &) = delete; + + Sampler &operator=(Sampler &&) = delete; + VkSampler get_handle() const; private: diff --git a/src/prism/vulkan/semaphore.cpp b/src/prism/vulkan/semaphore.cpp index eb2c73d..2405008 100644 --- a/src/prism/vulkan/semaphore.cpp +++ b/src/prism/vulkan/semaphore.cpp @@ -14,6 +14,12 @@ Semaphore::Semaphore(const Device& device) VK_CHECK(vkCreateSemaphore(device.get_handle(), &create_info, nullptr, &m_handle)); } +Semaphore::Semaphore(Semaphore&& other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device) +{ +} + Semaphore::~Semaphore() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/semaphore.h b/src/prism/vulkan/semaphore.h index a1c5050..f4efcd5 100644 --- a/src/prism/vulkan/semaphore.h +++ b/src/prism/vulkan/semaphore.h @@ -9,8 +9,16 @@ namespace prism public: Semaphore(const Device& device); + Semaphore(const Semaphore&) = delete; + + Semaphore(Semaphore&& other) noexcept; + ~Semaphore(); + Semaphore& operator=(const Semaphore&) = delete; + + Semaphore& operator=(Semaphore&&) = delete; + VkSemaphore get_handle() const; private: diff --git a/src/prism/vulkan/shader_module.cpp b/src/prism/vulkan/shader_module.cpp index 8226151..6fced4e 100644 --- a/src/prism/vulkan/shader_module.cpp +++ b/src/prism/vulkan/shader_module.cpp @@ -17,6 +17,14 @@ ShaderModule::ShaderModule(const Device &device, const std::string &filename, Vk VK_CHECK(vkCreateShaderModule(m_device.get_handle(), &create_info, nullptr, &m_handle)); } +ShaderModule::ShaderModule(ShaderModule &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device), + m_stage(other.m_stage), + m_entry_point(std::move(other.m_entry_point)) +{ +} + ShaderModule::~ShaderModule() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/shader_module.h b/src/prism/vulkan/shader_module.h index d0984ea..21a13d3 100644 --- a/src/prism/vulkan/shader_module.h +++ b/src/prism/vulkan/shader_module.h @@ -9,8 +9,17 @@ namespace prism { public: ShaderModule(const Device &device, const std::string &filename, VkShaderStageFlagBits stage, const std::string &entry_point = "main"); + + ShaderModule(const ShaderModule &) = delete; + + ShaderModule(ShaderModule &&other) noexcept; + ~ShaderModule(); + ShaderModule &operator=(const ShaderModule &) = delete; + + ShaderModule &operator=(ShaderModule &&) = delete; + VkShaderModule get_handle() const; VkShaderStageFlagBits get_stage() const; diff --git a/src/prism/vulkan/surface.h b/src/prism/vulkan/surface.h index 206c5cd..f616ce0 100644 --- a/src/prism/vulkan/surface.h +++ b/src/prism/vulkan/surface.h @@ -10,8 +10,16 @@ namespace prism public: Surface(const Instance& instance, const Window& window); + Surface(const Surface&) = delete; + + Surface(Surface&& other) = delete; + ~Surface(); + Surface& operator=(const Surface&) = delete; + + Surface& operator=(Surface&&) = delete; + VkSurfaceKHR get_handle() const; private: diff --git a/src/prism/vulkan/swapchain.cpp b/src/prism/vulkan/swapchain.cpp index 401d217..e777236 100644 --- a/src/prism/vulkan/swapchain.cpp +++ b/src/prism/vulkan/swapchain.cpp @@ -83,6 +83,16 @@ Swapchain::Swapchain(const Device &device, const Surface &surface, const Propert } } +Swapchain::Swapchain(Swapchain &&other) noexcept + : m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)), + m_device(other.m_device), + m_surface(other.m_surface), + m_images(std::move(other.m_images)), + m_image_views(std::move(other.m_image_views)), + m_properties(other.m_properties) +{ +} + Swapchain::~Swapchain() { if (m_handle != VK_NULL_HANDLE) diff --git a/src/prism/vulkan/swapchain.h b/src/prism/vulkan/swapchain.h index 3d275f6..42ce1ab 100644 --- a/src/prism/vulkan/swapchain.h +++ b/src/prism/vulkan/swapchain.h @@ -29,8 +29,16 @@ namespace prism public: Swapchain(const Device &device, const Surface &surface, const Properties &required, const std::optional &old_swapchain = std::nullopt); + Swapchain(const Swapchain &) = delete; + + Swapchain(Swapchain &&other) noexcept; + ~Swapchain(); + Swapchain &operator=(const Swapchain &) = delete; + + Swapchain &operator=(Swapchain &&) = delete; + VkSwapchainKHR get_handle() const; const VkFormat &get_format() const;