Minor C++ fixes

This commit is contained in:
Lynix 2020-03-17 17:13:27 +01:00
parent 5fde1e335b
commit 9cc206b33e
10 changed files with 72 additions and 77 deletions

View File

@ -81,7 +81,7 @@ namespace Nz
inline VkResult GetLastErrorCode() const; inline VkResult GetLastErrorCode() const;
CommandBuffer& operator=(const CommandBuffer&) = delete; CommandBuffer& operator=(const CommandBuffer&) = delete;
CommandBuffer& operator=(CommandBuffer&& commandBuffer); CommandBuffer& operator=(CommandBuffer&& commandBuffer) noexcept;
inline operator VkCommandBuffer() const; inline operator VkCommandBuffer() const;

View File

@ -26,7 +26,6 @@ namespace Nz
inline CommandBuffer::CommandBuffer(CommandBuffer&& commandBuffer) : inline CommandBuffer::CommandBuffer(CommandBuffer&& commandBuffer) :
m_pool(commandBuffer.m_pool), m_pool(commandBuffer.m_pool),
m_allocator(commandBuffer.m_allocator),
m_handle(commandBuffer.m_handle), m_handle(commandBuffer.m_handle),
m_lastErrorCode(commandBuffer.m_lastErrorCode) m_lastErrorCode(commandBuffer.m_lastErrorCode)
{ {
@ -258,8 +257,14 @@ namespace Nz
inline void CommandBuffer::SetScissor(const Recti& scissorRegion) inline void CommandBuffer::SetScissor(const Recti& scissorRegion)
{ {
VkRect2D rect = { 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); SetScissor(rect);
@ -288,11 +293,11 @@ namespace Nz
inline void CommandBuffer::SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout) inline void CommandBuffer::SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout)
{ {
VkImageSubresourceRange imageRange = { VkImageSubresourceRange imageRange = {
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask VK_IMAGE_ASPECT_COLOR_BIT,
0, // uint32_t baseMipLevel 0, //< baseMipLevel
1, // uint32_t levelCount 1, //< levelCount
0, // uint32_t baseArrayLayer 0, //< baseArrayLayer
1 // uint32_t layerCount 1 //< layerCount
}; };
return SetImageLayout(image, srcStageMask, dstStageMask, oldImageLayout, newImageLayout, imageRange); 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) inline void CommandBuffer::SetViewport(const Rectf& viewport, float minDepth, float maxDepth)
{ {
VkViewport rect = { VkViewport rect = {
viewport.x, // float x; viewport.x,
viewport.y, // float y; viewport.y,
viewport.width, // float width; viewport.width,
viewport.height, // float height; viewport.height,
minDepth, // float minDepth; minDepth,
maxDepth // float maxDepth; maxDepth
}; };
SetViewport(rect); SetViewport(rect);
@ -410,15 +415,12 @@ namespace Nz
return m_lastErrorCode; 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_lastErrorCode = commandBuffer.m_lastErrorCode;
m_pool = commandBuffer.m_pool; m_pool = commandBuffer.m_pool;
m_handle = commandBuffer.m_handle;
std::swap(m_handle, commandBuffer.m_handle);
commandBuffer.m_handle = VK_NULL_HANDLE;
return *this; return *this;
} }

View File

@ -23,7 +23,7 @@ namespace Nz
public: public:
DescriptorPool() = default; DescriptorPool() = default;
DescriptorPool(const DescriptorPool&) = delete; DescriptorPool(const DescriptorPool&) = delete;
DescriptorPool(DescriptorPool&&) = default; DescriptorPool(DescriptorPool&&) noexcept = default;
~DescriptorPool() = default; ~DescriptorPool() = default;
DescriptorSet AllocateDescriptorSet(const VkDescriptorSetLayout& setLayouts); DescriptorSet AllocateDescriptorSet(const VkDescriptorSetLayout& setLayouts);

View File

@ -23,12 +23,12 @@ namespace Nz
public: public:
inline DescriptorSet(); inline DescriptorSet();
DescriptorSet(const DescriptorSet&) = delete; DescriptorSet(const DescriptorSet&) = delete;
inline DescriptorSet(DescriptorSet&& descriptorSet); inline DescriptorSet(DescriptorSet&& descriptorSet) noexcept;
inline ~DescriptorSet(); inline ~DescriptorSet();
inline void Free(); 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, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range);
inline void WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo); 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); inline void WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo);
DescriptorSet& operator=(const DescriptorSet&) = delete; DescriptorSet& operator=(const DescriptorSet&) = delete;
DescriptorSet& operator=(DescriptorSet&& descriptorSet); inline DescriptorSet& operator=(DescriptorSet&& descriptorSet) noexcept;
inline explicit operator bool() const;
inline operator VkDescriptorSet() const; inline operator VkDescriptorSet() const;
private: private:
inline DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle); inline DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle);
DescriptorPool* m_pool; DescriptorPool* m_pool;
VkAllocationCallbacks m_allocator;
VkDescriptorSet m_handle; VkDescriptorSet m_handle;
VkResult m_lastErrorCode;
}; };
} }
} }

View File

@ -24,11 +24,9 @@ namespace Nz
{ {
} }
inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) : inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) noexcept :
m_pool(descriptorSet.m_pool), m_pool(descriptorSet.m_pool),
m_allocator(descriptorSet.m_allocator), m_handle(descriptorSet.m_handle)
m_handle(descriptorSet.m_handle),
m_lastErrorCode(descriptorSet.m_lastErrorCode)
{ {
descriptorSet.m_handle = VK_NULL_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) 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) inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range)
{ {
VkDescriptorBufferInfo bufferInfo = VkDescriptorBufferInfo bufferInfo = {
{ buffer,
buffer, // VkBuffer buffer; offset,
offset, // VkDeviceSize offset; range
range // VkDeviceSize range;
}; };
return WriteUniformDescriptor(binding, arrayElement, bufferInfo); return WriteUniformDescriptor(binding, arrayElement, bufferInfo);
@ -86,36 +83,36 @@ namespace Nz
inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo) inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo)
{ {
VkWriteDescriptorSet writeDescriptorSet = VkWriteDescriptorSet writeDescriptorSet = {
{ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, // VkStructureType sType; nullptr,
nullptr, // const void* pNext; m_handle,
m_handle, // VkDescriptorSet dstSet; binding,
binding, // uint32_t dstBinding; arrayElement,
arrayElement, // uint32_t dstArrayElement; descriptorCount,
descriptorCount, // uint32_t descriptorCount; VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType descriptorType; nullptr,
nullptr, // const VkDescriptorImageInfo* pImageInfo; bufferInfo,
bufferInfo, // const VkDescriptorBufferInfo* pBufferInfo; nullptr
nullptr // const VkBufferView* pTexelBufferView;
}; };
return m_pool->GetDevice()->vkUpdateDescriptorSets(*m_pool->GetDevice(), 1U, &writeDescriptorSet, 0U, 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_pool = descriptorSet.m_pool;
m_handle = descriptorSet.m_handle;
std::swap(m_handle, descriptorSet.m_handle);
descriptorSet.m_handle = VK_NULL_HANDLE;
return *this; return *this;
} }
inline DescriptorSet::operator bool() const
{
return IsValid();
}
inline DescriptorSet::operator VkDescriptorSet() const inline DescriptorSet::operator VkDescriptorSet() const
{ {
return m_handle; return m_handle;

View File

@ -22,7 +22,7 @@ namespace Nz
public: public:
DeviceObject(); DeviceObject();
DeviceObject(const DeviceObject&) = delete; DeviceObject(const DeviceObject&) = delete;
DeviceObject(DeviceObject&& object); DeviceObject(DeviceObject&& object) noexcept;
~DeviceObject(); ~DeviceObject();
bool Create(Device& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); bool Create(Device& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);

View File

@ -20,7 +20,7 @@ namespace Nz
} }
template<typename C, typename VkType, typename CreateInfo> template<typename C, typename VkType, typename CreateInfo>
DeviceObject<C, VkType, CreateInfo>::DeviceObject(DeviceObject&& object) : DeviceObject<C, VkType, CreateInfo>::DeviceObject(DeviceObject&& object) noexcept :
m_device(std::move(object.m_device)), m_device(std::move(object.m_device)),
m_allocator(object.m_allocator), m_allocator(object.m_allocator),
m_handle(object.m_handle), m_handle(object.m_handle),

View File

@ -19,7 +19,7 @@ namespace Nz
public: public:
inline Pipeline(); inline Pipeline();
Pipeline(const Pipeline&) = delete; Pipeline(const Pipeline&) = delete;
Pipeline(Pipeline&&); Pipeline(Pipeline&&) noexcept;
inline ~Pipeline(); inline ~Pipeline();
inline bool CreateCompute(Device& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache = VK_NULL_HANDLE, const VkAllocationCallbacks* allocator = nullptr); inline bool CreateCompute(Device& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache = VK_NULL_HANDLE, const VkAllocationCallbacks* allocator = nullptr);

View File

@ -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_device(std::move(object.m_device)),
m_allocator(object.m_allocator), m_allocator(object.m_allocator),
m_handle(object.m_handle), m_handle(object.m_handle),

View File

@ -12,13 +12,12 @@ namespace Nz
{ {
DescriptorSet DescriptorPool::AllocateDescriptorSet(const VkDescriptorSetLayout& setLayouts) DescriptorSet DescriptorPool::AllocateDescriptorSet(const VkDescriptorSetLayout& setLayouts)
{ {
VkDescriptorSetAllocateInfo createInfo = VkDescriptorSetAllocateInfo createInfo = {
{ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType; nullptr,
nullptr, // const void* pNext; m_handle,
m_handle, // VkDescriptorPool descriptorPool; 1U,
1U, // uint32_t descriptorSetCount; & setLayouts
&setLayouts // const VkDescriptorSetLayout* pSetLayouts;
}; };
VkDescriptorSet handle = VK_NULL_HANDLE; VkDescriptorSet handle = VK_NULL_HANDLE;
@ -29,19 +28,18 @@ namespace Nz
std::vector<DescriptorSet> DescriptorPool::AllocateDescriptorSets(UInt32 descriptorSetCount, const VkDescriptorSetLayout* setLayouts) std::vector<DescriptorSet> DescriptorPool::AllocateDescriptorSets(UInt32 descriptorSetCount, const VkDescriptorSetLayout* setLayouts)
{ {
VkDescriptorSetAllocateInfo createInfo = VkDescriptorSetAllocateInfo createInfo = {
{ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType; nullptr,
nullptr, // const void* pNext; m_handle,
m_handle, // VkDescriptorPool descriptorPool; descriptorSetCount,
descriptorSetCount, // uint32_t descriptorSetCount; setLayouts
setLayouts // const VkDescriptorSetLayout* pSetLayouts;
}; };
std::vector<VkDescriptorSet> handles(descriptorSetCount, VK_NULL_HANDLE); std::vector<VkDescriptorSet> handles(descriptorSetCount, VK_NULL_HANDLE);
m_lastErrorCode = m_device->vkAllocateDescriptorSets(*m_device, &createInfo, handles.data()); m_lastErrorCode = m_device->vkAllocateDescriptorSets(*m_device, &createInfo, handles.data());
if (m_lastErrorCode != VkResult::VK_SUCCESS) if (m_lastErrorCode != VkResult::VK_SUCCESS)
return std::vector<DescriptorSet>(); return {};
std::vector<DescriptorSet> descriptorSets; std::vector<DescriptorSet> descriptorSets;
for (UInt32 i = 0; i < descriptorSetCount; ++i) for (UInt32 i = 0; i < descriptorSetCount; ++i)