VulkanRenderer: Replace ObjectHandle by std::shared_ptr/raw pointers
This commit is contained in:
parent
0c008236ba
commit
79f732ee8a
|
|
@ -139,14 +139,14 @@ int main()
|
|||
Nz::VulkanDevice& device = vulkanWindow.GetDevice();
|
||||
|
||||
Nz::Vk::ShaderModule vertexShader;
|
||||
if (!vertexShader.Create(device.CreateHandle(), reinterpret_cast<Nz::UInt32*>(vertexShaderCode.data()), vertexShaderCode.size()))
|
||||
if (!vertexShader.Create(device.shared_from_this(), reinterpret_cast<Nz::UInt32*>(vertexShaderCode.data()), vertexShaderCode.size()))
|
||||
{
|
||||
NazaraError("Failed to create vertex shader");
|
||||
return __LINE__;
|
||||
}
|
||||
|
||||
Nz::Vk::ShaderModule fragmentShader;
|
||||
if (!fragmentShader.Create(device.CreateHandle(), reinterpret_cast<Nz::UInt32*>(fragmentShaderCode.data()), fragmentShaderCode.size()))
|
||||
if (!fragmentShader.Create(device.shared_from_this(), reinterpret_cast<Nz::UInt32*>(fragmentShaderCode.data()), fragmentShaderCode.size()))
|
||||
{
|
||||
NazaraError("Failed to create fragment shader");
|
||||
return __LINE__;
|
||||
|
|
@ -205,7 +205,7 @@ int main()
|
|||
Nz::UInt32 uniformSize = sizeof(ubo);
|
||||
|
||||
Nz::Vk::Buffer uniformBuffer;
|
||||
if (!uniformBuffer.Create(device.CreateHandle(), 0, uniformSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT))
|
||||
if (!uniformBuffer.Create(device.shared_from_this(), 0, uniformSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT))
|
||||
{
|
||||
NazaraError("Failed to create vertex buffer");
|
||||
return __LINE__;
|
||||
|
|
@ -214,7 +214,7 @@ int main()
|
|||
VkMemoryRequirements memRequirement = uniformBuffer.GetMemoryRequirements();
|
||||
|
||||
Nz::Vk::DeviceMemory uniformBufferMemory;
|
||||
if (!uniformBufferMemory.Create(device.CreateHandle(), memRequirement.size, memRequirement.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
|
||||
if (!uniformBufferMemory.Create(device.shared_from_this(), memRequirement.size, memRequirement.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
|
||||
{
|
||||
NazaraError("Failed to allocate vertex buffer memory");
|
||||
return __LINE__;
|
||||
|
|
@ -245,7 +245,7 @@ int main()
|
|||
layoutBinding.pImmutableSamplers = nullptr;
|
||||
|
||||
Nz::Vk::DescriptorSetLayout descriptorLayout;
|
||||
if (!descriptorLayout.Create(device.CreateHandle(), layoutBinding))
|
||||
if (!descriptorLayout.Create(device.shared_from_this(), layoutBinding))
|
||||
{
|
||||
NazaraError("Failed to create descriptor set layout");
|
||||
return __LINE__;
|
||||
|
|
@ -256,7 +256,7 @@ int main()
|
|||
poolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
|
||||
Nz::Vk::DescriptorPool descriptorPool;
|
||||
if (!descriptorPool.Create(device.CreateHandle(), 1, poolSize, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT))
|
||||
if (!descriptorPool.Create(device.shared_from_this(), 1, poolSize, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT))
|
||||
{
|
||||
NazaraError("Failed to create descriptor pool");
|
||||
return __LINE__;
|
||||
|
|
@ -405,7 +405,7 @@ int main()
|
|||
};
|
||||
|
||||
Nz::Vk::PipelineLayout pipelineLayout;
|
||||
pipelineLayout.Create(device.CreateHandle(), layout_create_info);
|
||||
pipelineLayout.Create(device.shared_from_this(), layout_create_info);
|
||||
|
||||
std::array<VkDynamicState, 2> dynamicStates = {
|
||||
VK_DYNAMIC_STATE_SCISSOR,
|
||||
|
|
@ -458,14 +458,14 @@ int main()
|
|||
};
|
||||
|
||||
Nz::Vk::Pipeline pipeline;
|
||||
if (!pipeline.CreateGraphics(device.CreateHandle(), pipeline_create_info))
|
||||
if (!pipeline.CreateGraphics(device.shared_from_this(), pipeline_create_info))
|
||||
{
|
||||
NazaraError("Failed to create pipeline");
|
||||
return __LINE__;
|
||||
}
|
||||
|
||||
Nz::Vk::CommandPool cmdPool;
|
||||
if (!cmdPool.Create(device.CreateHandle(), 0, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT))
|
||||
if (!cmdPool.Create(device.shared_from_this(), 0, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT))
|
||||
{
|
||||
NazaraError("Failed to create rendering cmd pool");
|
||||
return __LINE__;
|
||||
|
|
@ -475,7 +475,7 @@ int main()
|
|||
clearValues[0].color = {1.0f, 0.8f, 0.4f, 0.0f};
|
||||
clearValues[1].depthStencil = {1.f, 0};
|
||||
|
||||
Nz::Vk::Queue graphicsQueue(device.CreateHandle(), device.GetEnabledQueues()[0].queues[0].queue);
|
||||
Nz::Vk::Queue graphicsQueue(device.shared_from_this(), device.GetEnabledQueues()[0].queues[0].queue);
|
||||
|
||||
Nz::UInt32 imageCount = vulkanWindow.GetFramebufferCount();
|
||||
std::vector<Nz::Vk::CommandBuffer> renderCmds = cmdPool.AllocateCommandBuffers(imageCount, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Nz
|
|||
bool BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset = 0);
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
VkMemoryRequirements GetMemoryRequirements() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
inline bool Buffer::Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator)
|
||||
inline bool Buffer::Create(DeviceHandle device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkBufferCreateInfo createInfo = {
|
||||
VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
|
||||
|
|
@ -34,7 +34,7 @@ namespace Nz
|
|||
nullptr // const uint32_t* pQueueFamilyIndices;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkMemoryRequirements Buffer::GetMemoryRequirements() const
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace Nz
|
|||
private:
|
||||
inline CommandBuffer(CommandPool& pool, VkCommandBuffer handle);
|
||||
|
||||
CommandPoolHandle m_pool;
|
||||
CommandPool* m_pool;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkCommandBuffer m_handle;
|
||||
VkResult m_lastErrorCode;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Instance.hpp>
|
||||
#include <cassert>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -12,7 +13,7 @@ namespace Nz
|
|||
namespace Vk
|
||||
{
|
||||
inline CommandBuffer::CommandBuffer() :
|
||||
m_pool(),
|
||||
m_pool(nullptr),
|
||||
m_handle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
|
@ -24,7 +25,7 @@ namespace Nz
|
|||
}
|
||||
|
||||
inline CommandBuffer::CommandBuffer(CommandBuffer&& commandBuffer) :
|
||||
m_pool(std::move(commandBuffer.m_pool)),
|
||||
m_pool(commandBuffer.m_pool),
|
||||
m_allocator(commandBuffer.m_allocator),
|
||||
m_handle(commandBuffer.m_handle),
|
||||
m_lastErrorCode(commandBuffer.m_lastErrorCode)
|
||||
|
|
@ -223,7 +224,10 @@ namespace Nz
|
|||
inline void CommandBuffer::Free()
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
assert(m_pool);
|
||||
m_pool->GetDevice()->vkFreeCommandBuffers(*m_pool->GetDevice(), *m_pool, 1, &m_handle);
|
||||
}
|
||||
}
|
||||
|
||||
inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier)
|
||||
|
|
@ -401,7 +405,7 @@ namespace Nz
|
|||
m_allocator = commandBuffer.m_allocator;
|
||||
m_handle = commandBuffer.m_handle;
|
||||
m_lastErrorCode = commandBuffer.m_lastErrorCode;
|
||||
m_pool = std::move(commandBuffer.m_pool);
|
||||
m_pool = commandBuffer.m_pool;
|
||||
m_handle = commandBuffer.m_handle;
|
||||
|
||||
commandBuffer.m_handle = VK_NULL_HANDLE;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#define NAZARA_VULKANRENDERER_VKCOMMANDPOOL_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -16,11 +15,8 @@ namespace Nz
|
|||
namespace Vk
|
||||
{
|
||||
class CommandBuffer;
|
||||
class CommandPool;
|
||||
|
||||
using CommandPoolHandle = ObjectHandle<CommandPool>;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API CommandPool : public DeviceObject<CommandPool, VkCommandPool, VkCommandPoolCreateInfo>, public HandledObject<CommandPool>
|
||||
class NAZARA_VULKANRENDERER_API CommandPool : public DeviceObject<CommandPool, VkCommandPool, VkCommandPoolCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
|
|
@ -34,7 +30,7 @@ namespace Nz
|
|||
std::vector<CommandBuffer> AllocateCommandBuffers(UInt32 commandBufferCount, VkCommandBufferLevel level);
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline bool Reset(VkCommandPoolResetFlags flags);
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool CommandPool::Create(const DeviceHandle& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool CommandPool::Create(DeviceHandle device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkCommandPoolCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -21,7 +21,7 @@ namespace Nz
|
|||
queueFamilyIndex
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool CommandPool::Reset(VkCommandPoolResetFlags flags)
|
||||
|
|
|
|||
|
|
@ -8,19 +8,15 @@
|
|||
#define NAZARA_VULKANRENDERER_VKDESCRIPTORPOOL_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class DescriptorPool;
|
||||
class DescriptorSet;
|
||||
|
||||
using DescriptorPoolHandle = ObjectHandle<DescriptorPool>;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API DescriptorPool : public DeviceObject<DescriptorPool, VkDescriptorPool, VkDescriptorPoolCreateInfo>, public HandledObject<DescriptorPool>
|
||||
class NAZARA_VULKANRENDERER_API DescriptorPool : public DeviceObject<DescriptorPool, VkDescriptorPool, VkDescriptorPoolCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
|
|
@ -34,8 +30,8 @@ namespace Nz
|
|||
std::vector<DescriptorSet> AllocateDescriptorSets(UInt32 descriptorSetCount, const VkDescriptorSetLayout* setLayouts);
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(const DeviceHandle& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
DescriptorPool& operator=(const DescriptorPool&) = delete;
|
||||
DescriptorPool& operator=(DescriptorPool&&) = delete;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool DescriptorPool::Create(const DeviceHandle& device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool DescriptorPool::Create(DeviceHandle device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorPoolCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -21,10 +21,10 @@ namespace Nz
|
|||
&poolSize // const VkDescriptorPoolSize* pPoolSizes;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool DescriptorPool::Create(const DeviceHandle& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool DescriptorPool::Create(DeviceHandle device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorPoolCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -36,7 +36,7 @@ namespace Nz
|
|||
poolSize // const VkDescriptorPoolSize* pPoolSizes;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult DescriptorPool::CreateHelper(const DeviceHandle& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace Nz
|
|||
private:
|
||||
inline DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle);
|
||||
|
||||
DescriptorPoolHandle m_pool;
|
||||
DescriptorPool* m_pool;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkDescriptorSet m_handle;
|
||||
VkResult m_lastErrorCode;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Instance.hpp>
|
||||
#include <cassert>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -12,7 +13,7 @@ namespace Nz
|
|||
namespace Vk
|
||||
{
|
||||
inline DescriptorSet::DescriptorSet() :
|
||||
m_pool(),
|
||||
m_pool(nullptr),
|
||||
m_handle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
|
@ -24,7 +25,7 @@ namespace Nz
|
|||
}
|
||||
|
||||
inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) :
|
||||
m_pool(std::move(descriptorSet.m_pool)),
|
||||
m_pool(descriptorSet.m_pool),
|
||||
m_allocator(descriptorSet.m_allocator),
|
||||
m_handle(descriptorSet.m_handle),
|
||||
m_lastErrorCode(descriptorSet.m_lastErrorCode)
|
||||
|
|
@ -40,7 +41,10 @@ namespace Nz
|
|||
inline void DescriptorSet::Free()
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
assert(m_pool);
|
||||
m_pool->GetDevice()->vkFreeDescriptorSets(*m_pool->GetDevice(), *m_pool, 1, &m_handle);
|
||||
}
|
||||
}
|
||||
|
||||
inline VkResult DescriptorSet::GetLastErrorCode() const
|
||||
|
|
@ -104,7 +108,7 @@ namespace Nz
|
|||
m_allocator = descriptorSet.m_allocator;
|
||||
m_handle = descriptorSet.m_handle;
|
||||
m_lastErrorCode = descriptorSet.m_lastErrorCode;
|
||||
m_pool = std::move(descriptorSet.m_pool);
|
||||
m_pool = descriptorSet.m_pool;
|
||||
m_handle = descriptorSet.m_handle;
|
||||
|
||||
descriptorSet.m_handle = VK_NULL_HANDLE;
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ namespace Nz
|
|||
~DescriptorSetLayout() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(const DeviceHandle& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
DescriptorSetLayout& operator=(const DescriptorSetLayout&) = delete;
|
||||
DescriptorSetLayout& operator=(DescriptorSetLayout&&) = delete;
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool DescriptorSetLayout::Create(const DeviceHandle& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool DescriptorSetLayout::Create(DeviceHandle device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return Create(device, 1U, &binding, flags, allocator);
|
||||
return Create(std::move(device), 1U, &binding, flags, allocator);
|
||||
}
|
||||
|
||||
inline bool DescriptorSetLayout::Create(const DeviceHandle& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool DescriptorSetLayout::Create(DeviceHandle device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorSetLayoutCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -25,7 +25,7 @@ namespace Nz
|
|||
binding // const VkDescriptorSetLayoutBinding* pBindings;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult DescriptorSetLayout::CreateHelper(const DeviceHandle& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle)
|
||||
|
|
|
|||
|
|
@ -8,11 +8,10 @@
|
|||
#define NAZARA_VULKANRENDERER_VKDEVICE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Loader.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -23,9 +22,9 @@ namespace Nz
|
|||
class Instance;
|
||||
class Queue;
|
||||
|
||||
using DeviceHandle = ObjectHandle<Device>;
|
||||
using DeviceHandle = std::shared_ptr<Device>;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API Device : public HandledObject<Device>
|
||||
class NAZARA_VULKANRENDERER_API Device : public std::enable_shared_from_this<Device>
|
||||
{
|
||||
public:
|
||||
struct QueueFamilyInfo;
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ namespace Nz
|
|||
~DeviceMemory() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(const DeviceHandle& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline void* GetMappedPointer();
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Nz
|
|||
memory.m_mappedPtr = nullptr;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator)
|
||||
inline bool DeviceMemory::Create(DeviceHandle device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkMemoryAllocateInfo allocInfo =
|
||||
{
|
||||
|
|
@ -34,10 +34,10 @@ namespace Nz
|
|||
memoryType // uint32_t memoryTypeIndex;
|
||||
};
|
||||
|
||||
return Create(device, allocInfo, allocator);
|
||||
return Create(std::move(device), allocInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator)
|
||||
inline bool DeviceMemory::Create(DeviceHandle device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
const Vk::PhysicalDevice& deviceInfo = Vulkan::GetPhysicalDeviceInfo(device->GetPhysicalDevice());
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ namespace Nz
|
|||
if (typeBits & typeMask)
|
||||
{
|
||||
if ((deviceInfo.memoryProperties.memoryTypes[i].propertyFlags & properties) == properties)
|
||||
return Create(device, size, i, allocator);
|
||||
return Create(std::move(device), size, i, allocator);
|
||||
}
|
||||
|
||||
typeMask <<= 1;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Nz
|
|||
inline DeviceObject(DeviceObject&& object);
|
||||
inline ~DeviceObject();
|
||||
|
||||
inline bool Create(const DeviceHandle& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
inline bool IsValid() const;
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ namespace Nz
|
|||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline bool DeviceObject<C, VkType, CreateInfo>::Create(const DeviceHandle& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
||||
inline bool DeviceObject<C, VkType, CreateInfo>::Create(DeviceHandle device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_device = device;
|
||||
m_device = std::move(device);
|
||||
m_lastErrorCode = C::CreateHelper(m_device, &createInfo, allocator, &m_handle);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace Nz
|
|||
inline operator VkPipeline() const;
|
||||
|
||||
protected:
|
||||
inline bool Create(const DeviceHandle& device, VkResult result, const VkAllocationCallbacks* allocator);
|
||||
inline bool Create(DeviceHandle device, VkResult result, const VkAllocationCallbacks* allocator);
|
||||
|
||||
DeviceHandle m_device;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ namespace Nz
|
|||
|
||||
inline bool Pipeline::CreateCompute(const DeviceHandle& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return Create(device, device->vkCreateComputePipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
||||
return Create(std::move(device), device->vkCreateComputePipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
||||
}
|
||||
|
||||
inline bool Pipeline::CreateGraphics(const DeviceHandle& device, const VkGraphicsPipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return Create(device, device->vkCreateGraphicsPipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
||||
return Create(std::move(device), device->vkCreateGraphicsPipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
||||
}
|
||||
|
||||
inline void Pipeline::Destroy()
|
||||
|
|
@ -63,7 +63,7 @@ namespace Nz
|
|||
return m_handle;
|
||||
}
|
||||
|
||||
inline bool Pipeline::Create(const DeviceHandle& device, VkResult result, const VkAllocationCallbacks* allocator)
|
||||
inline bool Pipeline::Create(DeviceHandle device, VkResult result, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_device = device;
|
||||
m_lastErrorCode = result;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Nz
|
|||
~Semaphore() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, VkSemaphoreCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, VkSemaphoreCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
Semaphore& operator=(const Semaphore&) = delete;
|
||||
Semaphore& operator=(Semaphore&&) = delete;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Semaphore::Create(const DeviceHandle& device, VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool Semaphore::Create(DeviceHandle device, VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkSemaphoreCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -18,7 +18,7 @@ namespace Nz
|
|||
flags
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult Semaphore::CreateHelper(const DeviceHandle& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Nz
|
|||
~ShaderModule() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
ShaderModule& operator=(const ShaderModule&) = delete;
|
||||
ShaderModule& operator=(ShaderModule&&) = delete;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool ShaderModule::Create(const DeviceHandle& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool ShaderModule::Create(DeviceHandle device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkShaderModuleCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -20,7 +20,7 @@ namespace Nz
|
|||
code
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult ShaderModule::CreateHelper(const DeviceHandle& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace Nz
|
|||
|
||||
inline bool AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex) const;
|
||||
|
||||
inline bool Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(DeviceHandle device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline const Buffer& GetBuffer(UInt32 index) const;
|
||||
inline const std::vector<Buffer>& GetBuffers() const;
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
inline bool Swapchain::Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
inline bool Swapchain::Create(DeviceHandle device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
if (!DeviceObject::Create(device, createInfo, allocator))
|
||||
if (!DeviceObject::Create(std::move(device), createInfo, allocator))
|
||||
return false;
|
||||
|
||||
UInt32 imageCount = 0;
|
||||
|
|
|
|||
|
|
@ -187,14 +187,14 @@ namespace Nz
|
|||
1U // uint32_t layers;
|
||||
};
|
||||
|
||||
if (!m_frameBuffers[i].Create(m_device->CreateHandle(), frameBufferCreate))
|
||||
if (!m_frameBuffers[i].Create(m_device, frameBufferCreate))
|
||||
{
|
||||
NazaraError("Failed to create framebuffer for image #" + String::Number(i));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_imageReadySemaphore.Create(m_device->CreateHandle());
|
||||
m_imageReadySemaphore.Create(m_device);
|
||||
|
||||
m_clock.Restart();
|
||||
|
||||
|
|
@ -221,14 +221,14 @@ namespace Nz
|
|||
VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
|
||||
};
|
||||
|
||||
if (!m_depthBuffer.Create(m_device->CreateHandle(), imageCreateInfo))
|
||||
if (!m_depthBuffer.Create(m_device, imageCreateInfo))
|
||||
{
|
||||
NazaraError("Failed to create depth buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
VkMemoryRequirements memoryReq = m_depthBuffer.GetMemoryRequirements();
|
||||
if (!m_depthBufferMemory.Create(m_device->CreateHandle(), memoryReq.size, memoryReq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
|
||||
if (!m_depthBufferMemory.Create(m_device, memoryReq.size, memoryReq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
|
||||
{
|
||||
NazaraError("Failed to allocate depth buffer memory");
|
||||
return false;
|
||||
|
|
@ -262,7 +262,7 @@ namespace Nz
|
|||
}
|
||||
};
|
||||
|
||||
if (!m_depthBufferView.Create(m_device->CreateHandle(), imageViewCreateInfo))
|
||||
if (!m_depthBufferView.Create(m_device, imageViewCreateInfo))
|
||||
{
|
||||
NazaraError("Failed to create depth buffer view");
|
||||
return false;
|
||||
|
|
@ -356,7 +356,7 @@ namespace Nz
|
|||
dependencies.data() // const VkSubpassDependency* pDependencies;
|
||||
};
|
||||
|
||||
return m_renderPass.Create(m_device->CreateHandle(), createInfo);
|
||||
return m_renderPass.Create(m_device, createInfo);
|
||||
}
|
||||
|
||||
bool VkRenderWindow::SetupSwapchain(Vk::Surface& surface, const Vector2ui& size)
|
||||
|
|
@ -421,7 +421,7 @@ namespace Nz
|
|||
0
|
||||
};
|
||||
|
||||
if (!m_swapchain.Create(m_device->CreateHandle(), swapchainInfo))
|
||||
if (!m_swapchain.Create(m_device, swapchainInfo))
|
||||
{
|
||||
NazaraError("Failed to create swapchain");
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@ namespace Nz
|
|||
|
||||
std::unique_ptr<AbstractBuffer> VulkanDevice::InstantiateBuffer(Buffer* parent, BufferType type)
|
||||
{
|
||||
return std::make_unique<VulkanBuffer>(CreateHandle(), parent, type);
|
||||
return std::make_unique<VulkanBuffer>(shared_from_this(), parent, type);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ namespace Nz
|
|||
VkQueue queue;
|
||||
vkGetDeviceQueue(m_device, queueFamilyIndex, queueIndex, &queue);
|
||||
|
||||
return Queue(CreateHandle(), queue);
|
||||
return Queue(shared_from_this(), queue);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue