Skip to content

Commit

Permalink
dev: copy & move & ctor & dtor
Browse files Browse the repository at this point in the history
  • Loading branch information
jyxiong committed Sep 9, 2024
1 parent c8b1fed commit ba74750
Show file tree
Hide file tree
Showing 36 changed files with 286 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/prism/vulkan/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion src/prism/vulkan/command_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/prism/vulkan/command_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/prism/vulkan/command_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/prism/vulkan/compute_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/compute_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/descriptor_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ DescriptorPool::DescriptorPool(const Device &device, const std::vector<VkDescrip
VK_CHECK(vkCreateDescriptorPool(m_device.get_handle(), &pool_info, nullptr, &m_handle));
}

DescriptorPool::DescriptorPool(DescriptorPool &&other) noexcept
: m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)),
m_device(other.m_device),
m_max_sets(other.m_max_sets),
m_sizes(std::move(other.m_sizes))
{
}

DescriptorPool::~DescriptorPool()
{
if (m_handle != VK_NULL_HANDLE)
Expand Down
9 changes: 9 additions & 0 deletions src/prism/vulkan/descriptor_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ namespace prism
{
public:
DescriptorPool(const Device &device, const std::vector<VkDescriptorPoolSize> &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);
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/descriptor_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/prism/vulkan/descriptor_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VkDescriptorBufferInfo> &buffer_infos);

const VkDescriptorSet& get_handle() const;
Expand Down
7 changes: 7 additions & 0 deletions src/prism/vulkan/descriptor_set_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/prism/vulkan/descriptor_set_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VkDescriptorPoolSize> get_descriptor_pool_sizes() const;
Expand Down
9 changes: 9 additions & 0 deletions src/prism/vulkan/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/device_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/device_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/prism/vulkan/fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/fence.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/image_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/image_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/physical_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/prism/vulkan/pipeline_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ PipelineLayout::PipelineLayout(const Device &device, const std::vector<Descripto
VK_CHECK(vkCreatePipelineLayout(m_device.get_handle(), &pipeline_layout_info, nullptr, &m_handle));
}

PipelineLayout::PipelineLayout(PipelineLayout &&other) noexcept
: m_handle(std::exchange(other.m_handle, VK_NULL_HANDLE)),
m_device(other.m_device)
{
}

PipelineLayout::~PipelineLayout()
{
if (m_handle != VK_NULL_HANDLE)
Expand Down
8 changes: 8 additions & 0 deletions src/prism/vulkan/pipeline_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ namespace prism

PipelineLayout(const Device &device, const std::vector<DescriptorSetLayout> &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:
Expand Down
Loading

0 comments on commit ba74750

Please sign in to comment.