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;
CommandBuffer& operator=(const CommandBuffer&) = delete;
CommandBuffer& operator=(CommandBuffer&& commandBuffer);
CommandBuffer& operator=(CommandBuffer&& commandBuffer) noexcept;
inline operator VkCommandBuffer() const;

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
};
}
}

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_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;

View File

@ -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);

View File

@ -20,7 +20,7 @@ namespace Nz
}
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_allocator(object.m_allocator),
m_handle(object.m_handle),

View File

@ -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);

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_allocator(object.m_allocator),
m_handle(object.m_handle),

View File

@ -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<DescriptorSet> 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<VkDescriptorSet> handles(descriptorSetCount, VK_NULL_HANDLE);
m_lastErrorCode = m_device->vkAllocateDescriptorSets(*m_device, &createInfo, handles.data());
if (m_lastErrorCode != VkResult::VK_SUCCESS)
return std::vector<DescriptorSet>();
return {};
std::vector<DescriptorSet> descriptorSets;
for (UInt32 i = 0; i < descriptorSetCount; ++i)