diff --git a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp index 80ff5b7f4..ab5f54eae 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp @@ -81,7 +81,7 @@ namespace Nz inline VkResult GetLastErrorCode() const; CommandBuffer& operator=(const CommandBuffer&) = delete; - CommandBuffer& operator=(CommandBuffer&& commandBuffer); + CommandBuffer& operator=(CommandBuffer&& commandBuffer) noexcept; inline operator VkCommandBuffer() const; diff --git a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl index bd2c4ce76..574cb90a5 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl @@ -26,7 +26,6 @@ namespace Nz inline CommandBuffer::CommandBuffer(CommandBuffer&& commandBuffer) : m_pool(commandBuffer.m_pool), - m_allocator(commandBuffer.m_allocator), m_handle(commandBuffer.m_handle), m_lastErrorCode(commandBuffer.m_lastErrorCode) { @@ -258,8 +257,14 @@ namespace Nz inline void CommandBuffer::SetScissor(const Recti& scissorRegion) { VkRect2D rect = { - {scissorRegion.x, scissorRegion.y}, // VkOffset2D offset - {UInt32(scissorRegion.width), UInt32(scissorRegion.height)} // VkExtent2D extent + { + scissorRegion.x, + scissorRegion.y + }, + { + UInt32(scissorRegion.width), + UInt32(scissorRegion.height) + } }; SetScissor(rect); @@ -288,11 +293,11 @@ namespace Nz inline void CommandBuffer::SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout) { VkImageSubresourceRange imageRange = { - VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask - 0, // uint32_t baseMipLevel - 1, // uint32_t levelCount - 0, // uint32_t baseArrayLayer - 1 // uint32_t layerCount + VK_IMAGE_ASPECT_COLOR_BIT, + 0, //< baseMipLevel + 1, //< levelCount + 0, //< baseArrayLayer + 1 //< layerCount }; return SetImageLayout(image, srcStageMask, dstStageMask, oldImageLayout, newImageLayout, imageRange); @@ -384,12 +389,12 @@ namespace Nz inline void CommandBuffer::SetViewport(const Rectf& viewport, float minDepth, float maxDepth) { VkViewport rect = { - viewport.x, // float x; - viewport.y, // float y; - viewport.width, // float width; - viewport.height, // float height; - minDepth, // float minDepth; - maxDepth // float maxDepth; + viewport.x, + viewport.y, + viewport.width, + viewport.height, + minDepth, + maxDepth }; SetViewport(rect); @@ -410,15 +415,12 @@ namespace Nz return m_lastErrorCode; } - inline CommandBuffer& CommandBuffer::operator=(CommandBuffer&& commandBuffer) + inline CommandBuffer& CommandBuffer::operator=(CommandBuffer&& commandBuffer) noexcept { - m_allocator = commandBuffer.m_allocator; - m_handle = commandBuffer.m_handle; m_lastErrorCode = commandBuffer.m_lastErrorCode; m_pool = commandBuffer.m_pool; - m_handle = commandBuffer.m_handle; - - commandBuffer.m_handle = VK_NULL_HANDLE; + + std::swap(m_handle, commandBuffer.m_handle); return *this; } diff --git a/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.hpp b/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.hpp index 06f64d185..890b882d2 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.hpp @@ -23,7 +23,7 @@ namespace Nz public: DescriptorPool() = default; DescriptorPool(const DescriptorPool&) = delete; - DescriptorPool(DescriptorPool&&) = default; + DescriptorPool(DescriptorPool&&) noexcept = default; ~DescriptorPool() = default; DescriptorSet AllocateDescriptorSet(const VkDescriptorSetLayout& setLayouts); diff --git a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp index 8fd14fcba..42bc26721 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp @@ -23,12 +23,12 @@ namespace Nz public: inline DescriptorSet(); DescriptorSet(const DescriptorSet&) = delete; - inline DescriptorSet(DescriptorSet&& descriptorSet); + inline DescriptorSet(DescriptorSet&& descriptorSet) noexcept; inline ~DescriptorSet(); inline void Free(); - inline VkResult GetLastErrorCode() const; + inline bool IsValid() const; inline void WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range); inline void WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo); @@ -38,18 +38,16 @@ namespace Nz inline void WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo); DescriptorSet& operator=(const DescriptorSet&) = delete; - DescriptorSet& operator=(DescriptorSet&& descriptorSet); + inline DescriptorSet& operator=(DescriptorSet&& descriptorSet) noexcept; + inline explicit operator bool() const; inline operator VkDescriptorSet() const; private: inline DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle); DescriptorPool* m_pool; - VkAllocationCallbacks m_allocator; VkDescriptorSet m_handle; - VkResult m_lastErrorCode; - }; } } diff --git a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl index 9a0267cf1..5e5943bd3 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl @@ -24,11 +24,9 @@ namespace Nz { } - inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) : + inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) noexcept : m_pool(descriptorSet.m_pool), - m_allocator(descriptorSet.m_allocator), - m_handle(descriptorSet.m_handle), - m_lastErrorCode(descriptorSet.m_lastErrorCode) + m_handle(descriptorSet.m_handle) { descriptorSet.m_handle = VK_NULL_HANDLE; } @@ -47,9 +45,9 @@ namespace Nz } } - inline VkResult DescriptorSet::GetLastErrorCode() const + inline bool DescriptorSet::IsValid() const { - return m_lastErrorCode; + return m_handle != VK_NULL_HANDLE; } inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range) @@ -64,11 +62,10 @@ namespace Nz inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range) { - VkDescriptorBufferInfo bufferInfo = - { - buffer, // VkBuffer buffer; - offset, // VkDeviceSize offset; - range // VkDeviceSize range; + VkDescriptorBufferInfo bufferInfo = { + buffer, + offset, + range }; return WriteUniformDescriptor(binding, arrayElement, bufferInfo); @@ -86,36 +83,36 @@ namespace Nz inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo) { - VkWriteDescriptorSet writeDescriptorSet = - { - VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, // VkStructureType sType; - nullptr, // const void* pNext; - m_handle, // VkDescriptorSet dstSet; - binding, // uint32_t dstBinding; - arrayElement, // uint32_t dstArrayElement; - descriptorCount, // uint32_t descriptorCount; - VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType descriptorType; - nullptr, // const VkDescriptorImageInfo* pImageInfo; - bufferInfo, // const VkDescriptorBufferInfo* pBufferInfo; - nullptr // const VkBufferView* pTexelBufferView; + VkWriteDescriptorSet writeDescriptorSet = { + VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + nullptr, + m_handle, + binding, + arrayElement, + descriptorCount, + VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, + nullptr, + bufferInfo, + nullptr }; return m_pool->GetDevice()->vkUpdateDescriptorSets(*m_pool->GetDevice(), 1U, &writeDescriptorSet, 0U, nullptr); } - inline DescriptorSet& DescriptorSet::operator=(DescriptorSet&& descriptorSet) + inline DescriptorSet& DescriptorSet::operator=(DescriptorSet&& descriptorSet) noexcept { - m_allocator = descriptorSet.m_allocator; - m_handle = descriptorSet.m_handle; - m_lastErrorCode = descriptorSet.m_lastErrorCode; m_pool = descriptorSet.m_pool; - m_handle = descriptorSet.m_handle; - - descriptorSet.m_handle = VK_NULL_HANDLE; + + std::swap(m_handle, descriptorSet.m_handle); return *this; } + inline DescriptorSet::operator bool() const + { + return IsValid(); + } + inline DescriptorSet::operator VkDescriptorSet() const { return m_handle; diff --git a/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp b/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp index 887b05563..4ce478418 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp @@ -22,7 +22,7 @@ namespace Nz public: DeviceObject(); DeviceObject(const DeviceObject&) = delete; - DeviceObject(DeviceObject&& object); + DeviceObject(DeviceObject&& object) noexcept; ~DeviceObject(); bool Create(Device& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); diff --git a/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.inl b/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.inl index 91c671ce4..fcc5245d1 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.inl @@ -20,7 +20,7 @@ namespace Nz } template - DeviceObject::DeviceObject(DeviceObject&& object) : + DeviceObject::DeviceObject(DeviceObject&& object) noexcept : m_device(std::move(object.m_device)), m_allocator(object.m_allocator), m_handle(object.m_handle), diff --git a/include/Nazara/VulkanRenderer/Wrapper/Pipeline.hpp b/include/Nazara/VulkanRenderer/Wrapper/Pipeline.hpp index d63abadac..995a9e0ca 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Pipeline.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/Pipeline.hpp @@ -19,7 +19,7 @@ namespace Nz public: inline Pipeline(); Pipeline(const Pipeline&) = delete; - Pipeline(Pipeline&&); + Pipeline(Pipeline&&) noexcept; inline ~Pipeline(); inline bool CreateCompute(Device& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache = VK_NULL_HANDLE, const VkAllocationCallbacks* allocator = nullptr); diff --git a/include/Nazara/VulkanRenderer/Wrapper/Pipeline.inl b/include/Nazara/VulkanRenderer/Wrapper/Pipeline.inl index e91fe8107..ab865a777 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Pipeline.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/Pipeline.inl @@ -15,7 +15,7 @@ namespace Nz { } - inline Pipeline::Pipeline(Pipeline&& object) : + inline Pipeline::Pipeline(Pipeline&& object) noexcept : m_device(std::move(object.m_device)), m_allocator(object.m_allocator), m_handle(object.m_handle), diff --git a/src/Nazara/VulkanRenderer/Wrapper/DescriptorPool.cpp b/src/Nazara/VulkanRenderer/Wrapper/DescriptorPool.cpp index 488ec27a4..ddcc30002 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/DescriptorPool.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/DescriptorPool.cpp @@ -12,13 +12,12 @@ namespace Nz { DescriptorSet DescriptorPool::AllocateDescriptorSet(const VkDescriptorSetLayout& setLayouts) { - VkDescriptorSetAllocateInfo createInfo = - { - VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType; - nullptr, // const void* pNext; - m_handle, // VkDescriptorPool descriptorPool; - 1U, // uint32_t descriptorSetCount; - &setLayouts // const VkDescriptorSetLayout* pSetLayouts; + VkDescriptorSetAllocateInfo createInfo = { + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, + nullptr, + m_handle, + 1U, + & setLayouts }; VkDescriptorSet handle = VK_NULL_HANDLE; @@ -29,19 +28,18 @@ namespace Nz std::vector DescriptorPool::AllocateDescriptorSets(UInt32 descriptorSetCount, const VkDescriptorSetLayout* setLayouts) { - VkDescriptorSetAllocateInfo createInfo = - { - VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType; - nullptr, // const void* pNext; - m_handle, // VkDescriptorPool descriptorPool; - descriptorSetCount, // uint32_t descriptorSetCount; - setLayouts // const VkDescriptorSetLayout* pSetLayouts; + VkDescriptorSetAllocateInfo createInfo = { + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, + nullptr, + m_handle, + descriptorSetCount, + setLayouts }; std::vector handles(descriptorSetCount, VK_NULL_HANDLE); m_lastErrorCode = m_device->vkAllocateDescriptorSets(*m_device, &createInfo, handles.data()); if (m_lastErrorCode != VkResult::VK_SUCCESS) - return std::vector(); + return {}; std::vector descriptorSets; for (UInt32 i = 0; i < descriptorSetCount; ++i)