Replace DeviceHandle by references
and keep device alive until Vulkan is freed
This commit is contained in:
parent
4cf24cde7d
commit
63547fcd4e
|
|
@ -154,7 +154,7 @@ int main()
|
|||
Nz::VulkanDevice& vulkanDevice = vulkanWindow.GetDevice();
|
||||
|
||||
Nz::Vk::DescriptorPool descriptorPool;
|
||||
if (!descriptorPool.Create(vulkanDevice.shared_from_this(), 1, poolSize, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT))
|
||||
if (!descriptorPool.Create(vulkanDevice, 1, poolSize, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT))
|
||||
{
|
||||
NazaraError("Failed to create descriptor pool");
|
||||
return __LINE__;
|
||||
|
|
@ -165,7 +165,7 @@ int main()
|
|||
Nz::RenderBuffer* renderBufferUB = static_cast<Nz::RenderBuffer*>(uniformBuffer.GetBuffer()->GetImpl());
|
||||
if (!renderBufferUB->Synchronize(&vulkanDevice))
|
||||
{
|
||||
NazaraError("Failed to synchronize render buffer");
|
||||
NazaraError("Failed to create uniform buffer");
|
||||
return __LINE__;
|
||||
}
|
||||
Nz::VulkanBuffer* uniformBufferImpl = static_cast<Nz::VulkanBuffer*>(renderBufferUB->GetHardwareBuffer(&vulkanDevice));
|
||||
|
|
@ -188,7 +188,7 @@ int main()
|
|||
pipelineCreateInfo.pipelineInfo.renderPass = vulkanWindow.GetRenderPass();
|
||||
|
||||
Nz::Vk::CommandPool cmdPool;
|
||||
if (!cmdPool.Create(vulkanDevice.shared_from_this(), 0, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT))
|
||||
if (!cmdPool.Create(vulkanDevice, 0, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT))
|
||||
{
|
||||
NazaraError("Failed to create rendering cmd pool");
|
||||
return __LINE__;
|
||||
|
|
@ -198,7 +198,7 @@ int main()
|
|||
clearValues[0].color = {1.0f, 0.8f, 0.4f, 0.0f};
|
||||
clearValues[1].depthStencil = {1.f, 0};
|
||||
|
||||
Nz::Vk::Queue graphicsQueue(vulkanDevice.shared_from_this(), vulkanDevice.GetEnabledQueues()[0].queues[0].queue);
|
||||
Nz::Vk::Queue graphicsQueue(vulkanDevice, vulkanDevice.GetEnabledQueues()[0].queues[0].queue);
|
||||
|
||||
Nz::UInt32 imageCount = vulkanWindow.GetFramebufferCount();
|
||||
std::vector<Nz::Vk::CommandBuffer> renderCmds = cmdPool.AllocateCommandBuffers(imageCount, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
|
||||
|
|
@ -286,10 +286,10 @@ int main()
|
|||
std::vector<ImageSync> frameSync(MaxConcurrentImage);
|
||||
for (ImageSync& syncData : frameSync)
|
||||
{
|
||||
syncData.imageAvailableSemaphore.Create(vulkanDevice.shared_from_this());
|
||||
syncData.renderFinishedSemaphore.Create(vulkanDevice.shared_from_this());
|
||||
syncData.imageAvailableSemaphore.Create(vulkanDevice);
|
||||
syncData.renderFinishedSemaphore.Create(vulkanDevice);
|
||||
|
||||
syncData.inflightFence.Create(vulkanDevice.shared_from_this(), VK_FENCE_CREATE_SIGNALED_BIT);
|
||||
syncData.inflightFence.Create(vulkanDevice, VK_FENCE_CREATE_SIGNALED_BIT);
|
||||
}
|
||||
|
||||
std::vector<Nz::Vk::Fence*> inflightFences(imageCount, nullptr);
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ namespace Nz
|
|||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static std::vector<std::weak_ptr<VulkanDevice>> s_devices;
|
||||
static std::vector<std::shared_ptr<VulkanDevice>> s_devices;
|
||||
static std::vector<Vk::PhysicalDevice> s_physDevices;
|
||||
static Vk::Instance s_instance;
|
||||
static ParameterList s_initializationParameters;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Buffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceMemory.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Fence.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -21,7 +23,7 @@ namespace Nz
|
|||
class NAZARA_VULKANRENDERER_API VulkanBuffer : public AbstractBuffer
|
||||
{
|
||||
public:
|
||||
inline VulkanBuffer(const Vk::DeviceHandle& device, Buffer* parent, BufferType type);
|
||||
inline VulkanBuffer(Vk::Device& device, Buffer* parent, BufferType type);
|
||||
VulkanBuffer(const VulkanBuffer&) = delete;
|
||||
VulkanBuffer(VulkanBuffer&&) = delete; ///TODO
|
||||
virtual ~VulkanBuffer();
|
||||
|
|
@ -43,8 +45,8 @@ namespace Nz
|
|||
Buffer* m_parent;
|
||||
BufferType m_type;
|
||||
Nz::Vk::Buffer m_buffer;
|
||||
Nz::Vk::DeviceHandle m_device;
|
||||
Nz::Vk::DeviceMemory m_memory;
|
||||
Vk::Device& m_device;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
inline VulkanBuffer::VulkanBuffer(const Vk::DeviceHandle& device, Buffer* parent, BufferType type) :
|
||||
inline VulkanBuffer::VulkanBuffer(Vk::Device& device, Buffer* /*parent*/, BufferType type) :
|
||||
m_device(device),
|
||||
m_parent(parent),
|
||||
m_type(type)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#define NAZARA_VULKANRENDERER_VULKANRENDERPIPELINE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Renderer/RenderPipeline.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
|
||||
|
|
@ -22,7 +23,7 @@ namespace Nz
|
|||
public:
|
||||
struct CreateInfo;
|
||||
|
||||
VulkanRenderPipeline(Vk::DeviceHandle device, RenderPipelineInfo pipelineInfo);
|
||||
VulkanRenderPipeline(Vk::Device& device, RenderPipelineInfo pipelineInfo);
|
||||
~VulkanRenderPipeline() = default;
|
||||
|
||||
VkPipeline Get(const Vk::RenderPass& renderPass);
|
||||
|
|
@ -69,7 +70,7 @@ namespace Nz
|
|||
|
||||
private:
|
||||
std::unordered_map<VkRenderPass, Vk::Pipeline> m_pipelines;
|
||||
Vk::DeviceHandle m_device;
|
||||
MovablePtr<Vk::Device> m_device;
|
||||
CreateInfo m_pipelineCreateInfo;
|
||||
RenderPipelineInfo m_pipelineInfo;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,13 +23,13 @@ namespace Nz
|
|||
VulkanRenderPipelineLayout() = default;
|
||||
~VulkanRenderPipelineLayout() = default;
|
||||
|
||||
bool Create(Vk::DeviceHandle device, RenderPipelineLayoutInfo layoutInfo);
|
||||
bool Create(Vk::Device& device, RenderPipelineLayoutInfo layoutInfo);
|
||||
|
||||
inline const Vk::DescriptorSetLayout& GetDescriptorSetLayout() const;
|
||||
inline const Vk::PipelineLayout& GetPipelineLayout() const;
|
||||
|
||||
private:
|
||||
Vk::DeviceHandle m_device;
|
||||
MovablePtr<Vk::Device> m_device;
|
||||
Vk::DescriptorSetLayout m_descriptorSetLayout;
|
||||
Vk::PipelineLayout m_pipelineLayout;
|
||||
RenderPipelineLayoutInfo m_layoutInfo;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Nz
|
|||
VulkanShaderStage(VulkanShaderStage&&) noexcept = default;
|
||||
~VulkanShaderStage() = default;
|
||||
|
||||
bool Create(const Vk::DeviceHandle& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize);
|
||||
bool Create(Vk::Device& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize);
|
||||
|
||||
inline const Vk::ShaderModule& GetHandle() const;
|
||||
inline ShaderStageType GetStageType() const;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Nz
|
|||
bool BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset = 0);
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(DeviceHandle device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Device& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
VkMemoryRequirements GetMemoryRequirements() const;
|
||||
|
||||
|
|
@ -35,8 +35,8 @@ namespace Nz
|
|||
Buffer& operator=(Buffer&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkBufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkBuffer* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkBuffer handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkBufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkBuffer* handle);
|
||||
static inline void DestroyHelper(Device& device, VkBuffer handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
inline bool Buffer::Create(DeviceHandle device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator)
|
||||
inline bool Buffer::Create(Device& 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(std::move(device), createInfo, allocator);
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkMemoryRequirements Buffer::GetMemoryRequirements() const
|
||||
|
|
@ -47,14 +47,14 @@ namespace Nz
|
|||
return memoryRequirements;
|
||||
}
|
||||
|
||||
inline VkResult Buffer::CreateHelper(const DeviceHandle& device, const VkBufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkBuffer* handle)
|
||||
inline VkResult Buffer::CreateHelper(Device& device, const VkBufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkBuffer* handle)
|
||||
{
|
||||
return device->vkCreateBuffer(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateBuffer(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Buffer::DestroyHelper(const DeviceHandle& device, VkBuffer handle, const VkAllocationCallbacks* allocator)
|
||||
inline void Buffer::DestroyHelper(Device& device, VkBuffer handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyBuffer(*device, handle, allocator);
|
||||
return device.vkDestroyBuffer(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Nz
|
|||
std::vector<CommandBuffer> AllocateCommandBuffers(UInt32 commandBufferCount, VkCommandBufferLevel level);
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(DeviceHandle device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Device& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline bool Reset(VkCommandPoolResetFlags flags);
|
||||
|
||||
|
|
@ -38,8 +38,8 @@ namespace Nz
|
|||
CommandPool& operator=(CommandPool&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkCommandPool handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle);
|
||||
static inline void DestroyHelper(Device& device, VkCommandPool handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool CommandPool::Create(DeviceHandle device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool CommandPool::Create(Device& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkCommandPoolCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -21,7 +21,7 @@ namespace Nz
|
|||
queueFamilyIndex
|
||||
};
|
||||
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool CommandPool::Reset(VkCommandPoolResetFlags flags)
|
||||
|
|
@ -33,14 +33,14 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
inline VkResult CommandPool::CreateHelper(const DeviceHandle& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle)
|
||||
inline VkResult CommandPool::CreateHelper(Device& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle)
|
||||
{
|
||||
return device->vkCreateCommandPool(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateCommandPool(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void CommandPool::DestroyHelper(const DeviceHandle& device, VkCommandPool handle, const VkAllocationCallbacks* allocator)
|
||||
inline void CommandPool::DestroyHelper(Device& device, VkCommandPool handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyCommandPool(*device, handle, allocator);
|
||||
return device.vkDestroyCommandPool(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,15 +30,15 @@ namespace Nz
|
|||
std::vector<DescriptorSet> AllocateDescriptorSets(UInt32 descriptorSetCount, const VkDescriptorSetLayout* setLayouts);
|
||||
|
||||
using DeviceObject::Create;
|
||||
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);
|
||||
inline bool Create(Device& device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Device& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
DescriptorPool& operator=(const DescriptorPool&) = delete;
|
||||
DescriptorPool& operator=(DescriptorPool&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkDescriptorPool handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle);
|
||||
static inline void DestroyHelper(Device& device, VkDescriptorPool handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool DescriptorPool::Create(DeviceHandle device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool DescriptorPool::Create(Device& 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(std::move(device), createInfo, allocator);
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool DescriptorPool::Create(DeviceHandle device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool DescriptorPool::Create(Device& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorPoolCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -36,17 +36,17 @@ namespace Nz
|
|||
poolSize // const VkDescriptorPoolSize* pPoolSizes;
|
||||
};
|
||||
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult DescriptorPool::CreateHelper(const DeviceHandle& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle)
|
||||
inline VkResult DescriptorPool::CreateHelper(Device& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle)
|
||||
{
|
||||
return device->vkCreateDescriptorPool(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateDescriptorPool(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void DescriptorPool::DestroyHelper(const DeviceHandle& device, VkDescriptorPool handle, const VkAllocationCallbacks* allocator)
|
||||
inline void DescriptorPool::DestroyHelper(Device& device, VkDescriptorPool handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyDescriptorPool(*device, handle, allocator);
|
||||
return device.vkDestroyDescriptorPool(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,15 +25,15 @@ namespace Nz
|
|||
~DescriptorSetLayout() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
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);
|
||||
inline bool Create(Device& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Device& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
DescriptorSetLayout& operator=(const DescriptorSetLayout&) = delete;
|
||||
DescriptorSetLayout& operator=(DescriptorSetLayout&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkDescriptorSetLayout handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle);
|
||||
static inline void DestroyHelper(Device& device, VkDescriptorSetLayout handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool DescriptorSetLayout::Create(DeviceHandle device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool DescriptorSetLayout::Create(Device& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return Create(std::move(device), 1U, &binding, flags, allocator);
|
||||
return Create(device, 1U, &binding, flags, allocator);
|
||||
}
|
||||
|
||||
inline bool DescriptorSetLayout::Create(DeviceHandle device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool DescriptorSetLayout::Create(Device& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorSetLayoutCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -25,17 +25,17 @@ namespace Nz
|
|||
binding // const VkDescriptorSetLayoutBinding* pBindings;
|
||||
};
|
||||
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult DescriptorSetLayout::CreateHelper(const DeviceHandle& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle)
|
||||
inline VkResult DescriptorSetLayout::CreateHelper(Device& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle)
|
||||
{
|
||||
return device->vkCreateDescriptorSetLayout(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateDescriptorSetLayout(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void DescriptorSetLayout::DestroyHelper(const DeviceHandle& device, VkDescriptorSetLayout handle, const VkAllocationCallbacks* allocator)
|
||||
inline void DescriptorSetLayout::DestroyHelper(Device& device, VkDescriptorSetLayout handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyDescriptorSetLayout(*device, handle, allocator);
|
||||
return device.vkDestroyDescriptorSetLayout(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,9 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Device;
|
||||
class Instance;
|
||||
class Queue;
|
||||
|
||||
using DeviceHandle = std::shared_ptr<Device>;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API Device : public std::enable_shared_from_this<Device>
|
||||
{
|
||||
public:
|
||||
|
|
@ -32,10 +29,10 @@ namespace Nz
|
|||
struct QueueInfo;
|
||||
using QueueList = std::vector<QueueInfo>;
|
||||
|
||||
inline Device(Instance& instance);
|
||||
Device(Instance& instance);
|
||||
Device(const Device&) = delete;
|
||||
Device(Device&&) = delete;
|
||||
inline ~Device();
|
||||
~Device();
|
||||
|
||||
bool Create(const Vk::PhysicalDevice& deviceInfo, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
|
@ -63,7 +60,7 @@ namespace Nz
|
|||
// Vulkan functions
|
||||
#define NAZARA_VULKANRENDERER_DEVICE_EXT_BEGIN(ext)
|
||||
#define NAZARA_VULKANRENDERER_DEVICE_EXT_END()
|
||||
#define NAZARA_VULKANRENDERER_DEVICE_FUNCTION(func) PFN_##func func;
|
||||
#define NAZARA_VULKANRENDERER_DEVICE_FUNCTION(func) PFN_##func func = nullptr;
|
||||
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceFunctions.hpp>
|
||||
|
||||
|
|
@ -88,6 +85,9 @@ namespace Nz
|
|||
};
|
||||
|
||||
private:
|
||||
void WaitAndDestroyDevice();
|
||||
void ResetPointers();
|
||||
|
||||
inline PFN_vkVoidFunction GetProcAddr(const char* name);
|
||||
|
||||
Instance& m_instance;
|
||||
|
|
|
|||
|
|
@ -12,30 +12,6 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Device::Device(Instance& instance) :
|
||||
m_instance(instance),
|
||||
m_physicalDevice(nullptr),
|
||||
m_device(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline Device::~Device()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
inline void Device::Destroy()
|
||||
{
|
||||
if (m_device != VK_NULL_HANDLE)
|
||||
{
|
||||
vkDeviceWaitIdle(m_device);
|
||||
vkDestroyDevice(m_device, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
|
||||
m_device = VK_NULL_HANDLE;
|
||||
m_physicalDevice = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
inline const std::vector<Device::QueueFamilyInfo>& Device::GetEnabledQueues() const
|
||||
{
|
||||
return m_enabledQueuesInfos;
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ namespace Nz
|
|||
~DeviceMemory() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
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 bool Create(Device& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Device& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline void* GetMappedPointer();
|
||||
|
||||
|
|
@ -38,8 +38,8 @@ namespace Nz
|
|||
DeviceMemory& operator=(DeviceMemory&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle);
|
||||
static inline void DestroyHelper(Device& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator);
|
||||
|
||||
void* m_mappedPtr;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Nz
|
|||
memory.m_mappedPtr = nullptr;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Create(DeviceHandle device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator)
|
||||
inline bool DeviceMemory::Create(Device& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkMemoryAllocateInfo allocInfo =
|
||||
{
|
||||
|
|
@ -34,12 +34,12 @@ namespace Nz
|
|||
memoryType // uint32_t memoryTypeIndex;
|
||||
};
|
||||
|
||||
return Create(std::move(device), allocInfo, allocator);
|
||||
return Create(device, allocInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Create(DeviceHandle device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator)
|
||||
inline bool DeviceMemory::Create(Device& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
const Vk::PhysicalDevice& deviceInfo = Vulkan::GetPhysicalDeviceInfo(device->GetPhysicalDevice());
|
||||
const Vk::PhysicalDevice& deviceInfo = Vulkan::GetPhysicalDeviceInfo(device.GetPhysicalDevice());
|
||||
|
||||
UInt32 typeMask = 1;
|
||||
for (UInt32 i = 0; i < VK_MAX_MEMORY_TYPES; ++i)
|
||||
|
|
@ -47,7 +47,7 @@ namespace Nz
|
|||
if (typeBits & typeMask)
|
||||
{
|
||||
if ((deviceInfo.memoryProperties.memoryTypes[i].propertyFlags & properties) == properties)
|
||||
return Create(std::move(device), size, i, allocator);
|
||||
return Create(device, size, i, allocator);
|
||||
}
|
||||
|
||||
typeMask <<= 1;
|
||||
|
|
@ -82,14 +82,14 @@ namespace Nz
|
|||
m_mappedPtr = nullptr;
|
||||
}
|
||||
|
||||
inline VkResult DeviceMemory::CreateHelper(const DeviceHandle& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle)
|
||||
inline VkResult DeviceMemory::CreateHelper(Device& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle)
|
||||
{
|
||||
return device->vkAllocateMemory(*device, allocInfo, allocator, handle);
|
||||
return device.vkAllocateMemory(device, allocInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void DeviceMemory::DestroyHelper(const DeviceHandle& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator)
|
||||
inline void DeviceMemory::DestroyHelper(Device& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkFreeMemory(*device, handle, allocator);
|
||||
return device.vkFreeMemory(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#define NAZARA_VULKANRENDERER_VKDEVICEOBJECT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
|
|
@ -24,12 +25,12 @@ namespace Nz
|
|||
DeviceObject(DeviceObject&& object);
|
||||
~DeviceObject();
|
||||
|
||||
bool Create(DeviceHandle device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
bool Create(Device& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
void Destroy();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
const DeviceHandle& GetDevice() const;
|
||||
Device* GetDevice() const;
|
||||
VkResult GetLastErrorCode() const;
|
||||
|
||||
DeviceObject& operator=(const DeviceObject&) = delete;
|
||||
|
|
@ -38,7 +39,7 @@ namespace Nz
|
|||
operator VkType() const;
|
||||
|
||||
protected:
|
||||
DeviceHandle m_device;
|
||||
MovablePtr<Device> m_device;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkType m_handle;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@ namespace Nz
|
|||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
bool DeviceObject<C, VkType, CreateInfo>::Create(DeviceHandle device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
||||
bool DeviceObject<C, VkType, CreateInfo>::Create(Device& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_device = std::move(device);
|
||||
m_lastErrorCode = C::CreateHelper(m_device, &createInfo, allocator, &m_handle);
|
||||
m_device = &device;
|
||||
m_lastErrorCode = C::CreateHelper(*m_device, &createInfo, allocator, &m_handle);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to create Vulkan object: " + TranslateVulkanError(m_lastErrorCode));
|
||||
|
|
@ -60,7 +60,7 @@ namespace Nz
|
|||
{
|
||||
if (IsValid())
|
||||
{
|
||||
C::DestroyHelper(m_device, m_handle, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
C::DestroyHelper(*m_device, m_handle, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ namespace Nz
|
|||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
const DeviceHandle& DeviceObject<C, VkType, CreateInfo>::GetDevice() const
|
||||
Device* DeviceObject<C, VkType, CreateInfo>::GetDevice() const
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Nz
|
|||
~Fence() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(DeviceHandle device, VkFenceCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Device& device, VkFenceCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline bool Reset();
|
||||
|
||||
|
|
@ -36,8 +36,8 @@ namespace Nz
|
|||
Fence& operator=(Fence&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkFenceCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFence* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkFence handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkFenceCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFence* handle);
|
||||
static inline void DestroyHelper(Device& device, VkFence handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Fence::Create(DeviceHandle device, VkFenceCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool Fence::Create(Device& device, VkFenceCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkFenceCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -18,7 +18,7 @@ namespace Nz
|
|||
flags
|
||||
};
|
||||
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool Fence::Reset()
|
||||
|
|
@ -53,14 +53,14 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
inline VkResult Fence::CreateHelper(const DeviceHandle& device, const VkFenceCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFence* handle)
|
||||
inline VkResult Fence::CreateHelper(Device& device, const VkFenceCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFence* handle)
|
||||
{
|
||||
return device->vkCreateFence(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateFence(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Fence::DestroyHelper(const DeviceHandle& device, VkFence handle, const VkAllocationCallbacks* allocator)
|
||||
inline void Fence::DestroyHelper(Device& device, VkFence handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyFence(*device, handle, allocator);
|
||||
return device.vkDestroyFence(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ namespace Nz
|
|||
Framebuffer& operator=(Framebuffer&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkFramebufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFramebuffer* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkFramebuffer handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkFramebufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFramebuffer* handle);
|
||||
static inline void DestroyHelper(Device& device, VkFramebuffer handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline VkResult Framebuffer::CreateHelper(const DeviceHandle& device, const VkFramebufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFramebuffer* handle)
|
||||
inline VkResult Framebuffer::CreateHelper(Device& device, const VkFramebufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFramebuffer* handle)
|
||||
{
|
||||
return device->vkCreateFramebuffer(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateFramebuffer(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Framebuffer::DestroyHelper(const DeviceHandle& device, VkFramebuffer handle, const VkAllocationCallbacks* allocator)
|
||||
inline void Framebuffer::DestroyHelper(Device& device, VkFramebuffer handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyFramebuffer(*device, handle, allocator);
|
||||
return device.vkDestroyFramebuffer(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ namespace Nz
|
|||
Image& operator=(Image&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkImage handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle);
|
||||
static inline void DestroyHelper(Device& device, VkImage handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,14 +32,14 @@ namespace Nz
|
|||
return memoryRequirements;
|
||||
}
|
||||
|
||||
inline VkResult Image::CreateHelper(const DeviceHandle& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle)
|
||||
inline VkResult Image::CreateHelper(Device& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle)
|
||||
{
|
||||
return device->vkCreateImage(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateImage(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Image::DestroyHelper(const DeviceHandle& device, VkImage handle, const VkAllocationCallbacks* allocator)
|
||||
inline void Image::DestroyHelper(Device& device, VkImage handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyImage(*device, handle, allocator);
|
||||
return device.vkDestroyImage(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ namespace Nz
|
|||
ImageView& operator=(ImageView&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkImageViewCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImageView* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkImageView handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkImageViewCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImageView* handle);
|
||||
static inline void DestroyHelper(Device& device, VkImageView handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline VkResult ImageView::CreateHelper(const DeviceHandle& device, const VkImageViewCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImageView* handle)
|
||||
inline VkResult ImageView::CreateHelper(Device& device, const VkImageViewCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImageView* handle)
|
||||
{
|
||||
return device->vkCreateImageView(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateImageView(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void ImageView::DestroyHelper(const DeviceHandle& device, VkImageView handle, const VkAllocationCallbacks* allocator)
|
||||
inline void ImageView::DestroyHelper(Device& device, VkImageView handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyImageView(*device, handle, allocator);
|
||||
return device.vkDestroyImageView(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,9 @@ namespace Nz
|
|||
#undef NAZARA_VULKANRENDERER_INSTANCE_FUNCTION
|
||||
|
||||
private:
|
||||
inline void DestroyInstance();
|
||||
void ResetPointers();
|
||||
|
||||
inline PFN_vkVoidFunction GetProcAddr(const char* name);
|
||||
|
||||
VkAllocationCallbacks m_allocator;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/VulkanRenderer/Wrapper/Instance.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/Utils.hpp>
|
||||
#include <cassert>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -18,7 +19,7 @@ namespace Nz
|
|||
|
||||
inline Instance::~Instance()
|
||||
{
|
||||
Destroy();
|
||||
DestroyInstance();
|
||||
}
|
||||
|
||||
inline bool Instance::Create(const String& appName, UInt32 appVersion, const String& engineName, UInt32 engineVersion, const std::vector<const char*>& layers, const std::vector<const char*>& extensions, const VkAllocationCallbacks* allocator)
|
||||
|
|
@ -52,8 +53,8 @@ namespace Nz
|
|||
{
|
||||
if (m_instance)
|
||||
{
|
||||
vkDestroyInstance(m_instance, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
m_instance = nullptr;
|
||||
DestroyInstance();
|
||||
ResetPointers();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -135,6 +136,14 @@ namespace Nz
|
|||
return properties;
|
||||
}
|
||||
|
||||
inline void Instance::DestroyInstance()
|
||||
{
|
||||
assert(m_instance != VK_NULL_HANDLE);
|
||||
|
||||
if (vkDestroyInstance)
|
||||
vkDestroyInstance(m_instance, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
}
|
||||
|
||||
inline PFN_vkVoidFunction Instance::GetProcAddr(const char* name)
|
||||
{
|
||||
PFN_vkVoidFunction func = Loader::GetInstanceProcAddr(m_instance, name);
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ namespace Nz
|
|||
Pipeline(Pipeline&&);
|
||||
inline ~Pipeline();
|
||||
|
||||
inline bool CreateCompute(const DeviceHandle& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache = VK_NULL_HANDLE, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool CreateGraphics(const DeviceHandle& device, const VkGraphicsPipelineCreateInfo& 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);
|
||||
inline bool CreateGraphics(Device& device, const VkGraphicsPipelineCreateInfo& createInfo, VkPipelineCache cache = VK_NULL_HANDLE, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
inline const DeviceHandle& GetDevice() const;
|
||||
inline Device& GetDevice() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
Pipeline& operator=(const Pipeline&) = delete;
|
||||
|
|
@ -35,9 +35,9 @@ namespace Nz
|
|||
inline operator VkPipeline() const;
|
||||
|
||||
protected:
|
||||
inline bool Create(DeviceHandle device, VkResult result, const VkAllocationCallbacks* allocator);
|
||||
inline bool Create(Device& device, VkResult result, const VkAllocationCallbacks* allocator);
|
||||
|
||||
DeviceHandle m_device;
|
||||
MovablePtr<Device> m_device;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkPipeline m_handle;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ namespace Nz
|
|||
Destroy();
|
||||
}
|
||||
|
||||
inline bool Pipeline::CreateCompute(const DeviceHandle& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator)
|
||||
inline bool Pipeline::CreateCompute(Device& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return Create(std::move(device), device->vkCreateComputePipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
||||
return Create(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)
|
||||
inline bool Pipeline::CreateGraphics(Device& device, const VkGraphicsPipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return Create(std::move(device), device->vkCreateGraphicsPipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
||||
return Create(device, device.vkCreateGraphicsPipelines(device, cache, 1U, &createInfo, allocator, &m_handle), allocator);
|
||||
}
|
||||
|
||||
inline void Pipeline::Destroy()
|
||||
|
|
@ -48,9 +48,9 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
inline const DeviceHandle& Pipeline::GetDevice() const
|
||||
inline Device& Pipeline::GetDevice() const
|
||||
{
|
||||
return m_device;
|
||||
return *m_device;
|
||||
}
|
||||
|
||||
inline VkResult Pipeline::GetLastErrorCode() const
|
||||
|
|
@ -63,9 +63,9 @@ namespace Nz
|
|||
return m_handle;
|
||||
}
|
||||
|
||||
inline bool Pipeline::Create(DeviceHandle device, VkResult result, const VkAllocationCallbacks* allocator)
|
||||
inline bool Pipeline::Create(Device& device, VkResult result, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_device = device;
|
||||
m_device = &device;
|
||||
m_lastErrorCode = result;
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ namespace Nz
|
|||
PipelineCache& operator=(PipelineCache&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkPipelineCacheCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineCache* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkPipelineCache handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkPipelineCacheCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineCache* handle);
|
||||
static inline void DestroyHelper(Device& device, VkPipelineCache handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline VkResult PipelineCache::CreateHelper(const DeviceHandle& device, const VkPipelineCacheCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineCache* handle)
|
||||
inline VkResult PipelineCache::CreateHelper(Device& device, const VkPipelineCacheCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineCache* handle)
|
||||
{
|
||||
return device->vkCreatePipelineCache(*device, createInfo, allocator, handle);
|
||||
return device.vkCreatePipelineCache(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void PipelineCache::DestroyHelper(const DeviceHandle& device, VkPipelineCache handle, const VkAllocationCallbacks* allocator)
|
||||
inline void PipelineCache::DestroyHelper(Device& device, VkPipelineCache handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyPipelineCache(*device, handle, allocator);
|
||||
return device.vkDestroyPipelineCache(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,15 +25,15 @@ namespace Nz
|
|||
~PipelineLayout() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
bool Create(DeviceHandle device, VkDescriptorSetLayout layout, VkPipelineLayoutCreateFlags flags = 0);
|
||||
bool Create(DeviceHandle device, UInt32 layoutCount, const VkDescriptorSetLayout* layouts, VkPipelineLayoutCreateFlags flags = 0);
|
||||
bool Create(Device& device, VkDescriptorSetLayout layout, VkPipelineLayoutCreateFlags flags = 0);
|
||||
bool Create(Device& device, UInt32 layoutCount, const VkDescriptorSetLayout* layouts, VkPipelineLayoutCreateFlags flags = 0);
|
||||
|
||||
PipelineLayout& operator=(const PipelineLayout&) = delete;
|
||||
PipelineLayout& operator=(PipelineLayout&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineLayout* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkPipelineLayout handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineLayout* handle);
|
||||
static inline void DestroyHelper(Device& device, VkPipelineLayout handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool PipelineLayout::Create(DeviceHandle device, VkDescriptorSetLayout layout, VkPipelineLayoutCreateFlags flags)
|
||||
inline bool PipelineLayout::Create(Device& device, VkDescriptorSetLayout layout, VkPipelineLayoutCreateFlags flags)
|
||||
{
|
||||
return Create(std::move(device), 1U, &layout, flags);
|
||||
return Create(device, 1U, &layout, flags);
|
||||
}
|
||||
|
||||
inline bool PipelineLayout::Create(DeviceHandle device, UInt32 layoutCount, const VkDescriptorSetLayout* layouts, VkPipelineLayoutCreateFlags flags)
|
||||
inline bool PipelineLayout::Create(Device& device, UInt32 layoutCount, const VkDescriptorSetLayout* layouts, VkPipelineLayoutCreateFlags flags)
|
||||
{
|
||||
VkPipelineLayoutCreateInfo createInfo = {
|
||||
VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||
|
|
@ -26,17 +26,17 @@ namespace Nz
|
|||
nullptr
|
||||
};
|
||||
|
||||
return Create(std::move(device), createInfo);
|
||||
return Create(device, createInfo);
|
||||
}
|
||||
|
||||
inline VkResult PipelineLayout::CreateHelper(const DeviceHandle& device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineLayout* handle)
|
||||
inline VkResult PipelineLayout::CreateHelper(Device& device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineLayout* handle)
|
||||
{
|
||||
return device->vkCreatePipelineLayout(*device, createInfo, allocator, handle);
|
||||
return device.vkCreatePipelineLayout(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void PipelineLayout::DestroyHelper(const DeviceHandle& device, VkPipelineLayout handle, const VkAllocationCallbacks* allocator)
|
||||
inline void PipelineLayout::DestroyHelper(Device& device, VkPipelineLayout handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyPipelineLayout(*device, handle, allocator);
|
||||
return device.vkDestroyPipelineLayout(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ namespace Nz
|
|||
{
|
||||
public:
|
||||
inline Queue();
|
||||
inline Queue(const DeviceHandle& device, VkQueue queue);
|
||||
inline Queue(Device& device, VkQueue queue);
|
||||
inline Queue(const Queue& queue);
|
||||
inline Queue(Queue&& queue);
|
||||
inline ~Queue() = default;
|
||||
|
||||
inline const DeviceHandle& GetDevice() const;
|
||||
inline Device& GetDevice() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
inline bool Present(const VkPresentInfoKHR& presentInfo) const;
|
||||
|
|
@ -43,7 +43,7 @@ namespace Nz
|
|||
inline operator VkQueue();
|
||||
|
||||
protected:
|
||||
DeviceHandle m_device;
|
||||
Device* m_device;
|
||||
VkQueue m_handle;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,34 +12,21 @@ namespace Nz
|
|||
namespace Vk
|
||||
{
|
||||
inline Queue::Queue() :
|
||||
Queue(DeviceHandle(), VK_NULL_HANDLE)
|
||||
m_handle(VK_NULL_HANDLE),
|
||||
m_lastErrorCode(VkResult::VK_SUCCESS)
|
||||
{
|
||||
}
|
||||
|
||||
inline Queue::Queue(const DeviceHandle& device, VkQueue queue) :
|
||||
m_device(device),
|
||||
inline Queue::Queue(Device& device, VkQueue queue) :
|
||||
m_device(&device),
|
||||
m_handle(queue),
|
||||
m_lastErrorCode(VkResult::VK_SUCCESS)
|
||||
{
|
||||
}
|
||||
|
||||
inline Queue::Queue(const Queue& queue) :
|
||||
m_device(queue.m_device),
|
||||
m_handle(queue.m_handle),
|
||||
m_lastErrorCode(queue.m_lastErrorCode)
|
||||
inline Device& Queue::GetDevice() const
|
||||
{
|
||||
}
|
||||
|
||||
inline Queue::Queue(Queue&& queue) :
|
||||
m_device(queue.m_device),
|
||||
m_handle(queue.m_handle),
|
||||
m_lastErrorCode(queue.m_lastErrorCode)
|
||||
{
|
||||
}
|
||||
|
||||
inline const DeviceHandle& Queue::GetDevice() const
|
||||
{
|
||||
return m_device;
|
||||
return *m_device;
|
||||
}
|
||||
|
||||
inline VkResult Queue::GetLastErrorCode() const
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ namespace Nz
|
|||
RenderPass& operator=(RenderPass&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkRenderPassCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkRenderPass* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkRenderPass handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkRenderPassCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkRenderPass* handle);
|
||||
static inline void DestroyHelper(Device& device, VkRenderPass handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline VkResult RenderPass::CreateHelper(const DeviceHandle& device, const VkRenderPassCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkRenderPass* handle)
|
||||
inline VkResult RenderPass::CreateHelper(Device& device, const VkRenderPassCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkRenderPass* handle)
|
||||
{
|
||||
return device->vkCreateRenderPass(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateRenderPass(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void RenderPass::DestroyHelper(const DeviceHandle& device, VkRenderPass handle, const VkAllocationCallbacks* allocator)
|
||||
inline void RenderPass::DestroyHelper(Device& device, VkRenderPass handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyRenderPass(*device, handle, allocator);
|
||||
return device.vkDestroyRenderPass(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,14 +25,14 @@ namespace Nz
|
|||
~Semaphore() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(DeviceHandle device, VkSemaphoreCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Device& device, VkSemaphoreCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
Semaphore& operator=(const Semaphore&) = delete;
|
||||
Semaphore& operator=(Semaphore&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkSemaphore handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle);
|
||||
static inline void DestroyHelper(Device& device, VkSemaphore handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Semaphore::Create(DeviceHandle device, VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool Semaphore::Create(Device& device, VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkSemaphoreCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -18,17 +18,17 @@ namespace Nz
|
|||
flags
|
||||
};
|
||||
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult Semaphore::CreateHelper(const DeviceHandle& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle)
|
||||
inline VkResult Semaphore::CreateHelper(Device& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle)
|
||||
{
|
||||
return device->vkCreateSemaphore(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateSemaphore(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Semaphore::DestroyHelper(const DeviceHandle& device, VkSemaphore handle, const VkAllocationCallbacks* allocator)
|
||||
inline void Semaphore::DestroyHelper(Device& device, VkSemaphore handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroySemaphore(*device, handle, allocator);
|
||||
return device.vkDestroySemaphore(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,14 +25,14 @@ namespace Nz
|
|||
~ShaderModule() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(DeviceHandle device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Device& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
ShaderModule& operator=(const ShaderModule&) = delete;
|
||||
ShaderModule& operator=(ShaderModule&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkShaderModule handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle);
|
||||
static inline void DestroyHelper(Device& device, VkShaderModule handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool ShaderModule::Create(DeviceHandle device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
inline bool ShaderModule::Create(Device& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkShaderModuleCreateInfo createInfo =
|
||||
{
|
||||
|
|
@ -20,17 +20,17 @@ namespace Nz
|
|||
code
|
||||
};
|
||||
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult ShaderModule::CreateHelper(const DeviceHandle& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle)
|
||||
inline VkResult ShaderModule::CreateHelper(Device& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle)
|
||||
{
|
||||
return device->vkCreateShaderModule(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateShaderModule(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void ShaderModule::DestroyHelper(const DeviceHandle& device, VkShaderModule handle, const VkAllocationCallbacks* allocator)
|
||||
inline void ShaderModule::DestroyHelper(Device& device, VkShaderModule handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyShaderModule(*device, handle, allocator);
|
||||
return device.vkDestroyShaderModule(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace Nz
|
|||
|
||||
inline bool AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex) const;
|
||||
|
||||
inline bool Create(DeviceHandle device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Device& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline const Buffer& GetBuffer(UInt32 index) const;
|
||||
inline const std::vector<Buffer>& GetBuffers() const;
|
||||
|
|
@ -47,8 +47,8 @@ namespace Nz
|
|||
};
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator);
|
||||
static inline VkResult CreateHelper(Device& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle);
|
||||
static inline void DestroyHelper(Device& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator);
|
||||
|
||||
std::vector<Buffer> m_buffers;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
inline bool Swapchain::Create(DeviceHandle device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
inline bool Swapchain::Create(Device& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
if (!DeviceObject::Create(std::move(device), createInfo, allocator))
|
||||
if (!DeviceObject::Create(device, createInfo, allocator))
|
||||
return false;
|
||||
|
||||
UInt32 imageCount = 0;
|
||||
|
|
@ -77,7 +77,7 @@ namespace Nz
|
|||
}
|
||||
};
|
||||
|
||||
if (!m_buffers[i].view.Create(m_device, imageViewCreateInfo))
|
||||
if (!m_buffers[i].view.Create(*m_device, imageViewCreateInfo))
|
||||
{
|
||||
NazaraError("Failed to create image view for image #" + String::Number(i));
|
||||
return false;
|
||||
|
|
@ -110,14 +110,14 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
inline VkResult Swapchain::CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle)
|
||||
inline VkResult Swapchain::CreateHelper(Device& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle)
|
||||
{
|
||||
return device->vkCreateSwapchainKHR(*device, createInfo, allocator, handle);
|
||||
return device.vkCreateSwapchainKHR(device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Swapchain::DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator)
|
||||
inline void Swapchain::DestroyHelper(Device& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroySwapchainKHR(*device, handle, allocator);
|
||||
return device.vkDestroySwapchainKHR(device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
#include <Nazara/VulkanRenderer/Vulkan.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanSurface.hpp>
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
|
|
@ -43,7 +44,7 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
bool VkRenderWindow::Create(RendererImpl* renderer, RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters)
|
||||
bool VkRenderWindow::Create(RendererImpl* /*renderer*/, RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters)
|
||||
{
|
||||
m_physicalDevice = Vulkan::GetPhysicalDevices()[0].device;
|
||||
|
||||
|
|
@ -74,8 +75,6 @@ namespace Nz
|
|||
|
||||
if (!parameters.depthFormats.empty())
|
||||
{
|
||||
const Vk::PhysicalDevice& deviceInfo = Vulkan::GetPhysicalDeviceInfo(m_physicalDevice);
|
||||
|
||||
for (PixelFormatType format : parameters.depthFormats)
|
||||
{
|
||||
switch (format)
|
||||
|
|
@ -163,7 +162,7 @@ namespace Nz
|
|||
1U // uint32_t layers;
|
||||
};
|
||||
|
||||
if (!m_frameBuffers[i].Create(m_device, frameBufferCreate))
|
||||
if (!m_frameBuffers[i].Create(*m_device, frameBufferCreate))
|
||||
{
|
||||
NazaraError("Failed to create framebuffer for image #" + String::Number(i));
|
||||
return false;
|
||||
|
|
@ -195,14 +194,14 @@ namespace Nz
|
|||
VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
|
||||
};
|
||||
|
||||
if (!m_depthBuffer.Create(m_device, 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, 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;
|
||||
|
|
@ -236,7 +235,7 @@ namespace Nz
|
|||
}
|
||||
};
|
||||
|
||||
if (!m_depthBufferView.Create(m_device, imageViewCreateInfo))
|
||||
if (!m_depthBufferView.Create(*m_device, imageViewCreateInfo))
|
||||
{
|
||||
NazaraError("Failed to create depth buffer view");
|
||||
return false;
|
||||
|
|
@ -330,7 +329,7 @@ namespace Nz
|
|||
dependencies.data() // const VkSubpassDependency* pDependencies;
|
||||
};
|
||||
|
||||
return m_renderPass.Create(m_device, createInfo);
|
||||
return m_renderPass.Create(*m_device, createInfo);
|
||||
}
|
||||
|
||||
bool VkRenderWindow::SetupSwapchain(Vk::Surface& surface, const Vector2ui& size)
|
||||
|
|
@ -395,7 +394,7 @@ namespace Nz
|
|||
0
|
||||
};
|
||||
|
||||
if (!m_swapchain.Create(m_device, swapchainInfo))
|
||||
if (!m_swapchain.Create(*m_device, swapchainInfo))
|
||||
{
|
||||
NazaraError("Failed to create swapchain");
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -444,13 +444,7 @@ namespace Nz
|
|||
{
|
||||
for (auto it = s_devices.begin(); it != s_devices.end();)
|
||||
{
|
||||
auto devicePtr = it->lock();
|
||||
if (!devicePtr)
|
||||
{
|
||||
it = s_devices.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& devicePtr = *it;
|
||||
if (devicePtr->GetPhysicalDevice() == gpu)
|
||||
return devicePtr;
|
||||
}
|
||||
|
|
@ -463,13 +457,7 @@ namespace Nz
|
|||
// First, try to find a device compatible with that surface
|
||||
for (auto it = s_devices.begin(); it != s_devices.end();)
|
||||
{
|
||||
auto devicePtr = it->lock();
|
||||
if (!devicePtr)
|
||||
{
|
||||
it = s_devices.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& devicePtr = *it;
|
||||
if (devicePtr->GetPhysicalDevice() == gpu)
|
||||
{
|
||||
const std::vector<Vk::Device::QueueFamilyInfo>& queueFamilyInfo = devicePtr->GetEnabledQueues();
|
||||
|
|
@ -511,7 +499,7 @@ namespace Nz
|
|||
Vk::Loader::Uninitialize();
|
||||
}
|
||||
|
||||
std::vector<std::weak_ptr<VulkanDevice>> Vulkan::s_devices;
|
||||
std::vector<std::shared_ptr<VulkanDevice>> Vulkan::s_devices;
|
||||
std::vector<Vk::PhysicalDevice> Vulkan::s_physDevices;
|
||||
Vk::Instance Vulkan::s_instance;
|
||||
ParameterList Vulkan::s_initializationParameters;
|
||||
|
|
|
|||
|
|
@ -12,20 +12,20 @@ namespace Nz
|
|||
{
|
||||
VulkanDevice::~VulkanDevice() = default;
|
||||
|
||||
std::unique_ptr<AbstractBuffer> VulkanDevice::InstantiateBuffer(Buffer* parent, BufferType type)
|
||||
std::unique_ptr<AbstractBuffer> VulkanDevice::InstantiateBuffer(BufferType type)
|
||||
{
|
||||
return std::make_unique<VulkanBuffer>(shared_from_this(), parent, type);
|
||||
return std::make_unique<VulkanBuffer>(*this, type);
|
||||
}
|
||||
|
||||
std::unique_ptr<RenderPipeline> VulkanDevice::InstantiateRenderPipeline(RenderPipelineInfo pipelineInfo)
|
||||
{
|
||||
return std::make_unique<VulkanRenderPipeline>(shared_from_this(), std::move(pipelineInfo));
|
||||
return std::make_unique<VulkanRenderPipeline>(*this, std::move(pipelineInfo));
|
||||
}
|
||||
|
||||
std::shared_ptr<RenderPipelineLayout> VulkanDevice::InstantiateRenderPipelineLayout(RenderPipelineLayoutInfo pipelineLayoutInfo)
|
||||
{
|
||||
auto pipelineLayout = std::make_shared<VulkanRenderPipelineLayout>();
|
||||
if (!pipelineLayout->Create(shared_from_this(), std::move(pipelineLayoutInfo)))
|
||||
if (!pipelineLayout->Create(*this, std::move(pipelineLayoutInfo)))
|
||||
return {};
|
||||
|
||||
return pipelineLayout;
|
||||
|
|
@ -34,7 +34,7 @@ namespace Nz
|
|||
std::shared_ptr<ShaderStageImpl> VulkanDevice::InstantiateShaderStage(ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
auto stage = std::make_shared<VulkanShaderStage>();
|
||||
if (!stage->Create(shared_from_this(), type, lang, source, sourceSize))
|
||||
if (!stage->Create(*this, type, lang, source, sourceSize))
|
||||
return {};
|
||||
|
||||
return stage;
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
VulkanRenderPipeline::VulkanRenderPipeline(Vk::DeviceHandle device, RenderPipelineInfo pipelineInfo) :
|
||||
m_device(std::move(device)),
|
||||
VulkanRenderPipeline::VulkanRenderPipeline(Vk::Device& device, RenderPipelineInfo pipelineInfo) :
|
||||
m_device(&device),
|
||||
m_pipelineInfo(std::move(pipelineInfo))
|
||||
{
|
||||
m_pipelineCreateInfo = BuildCreateInfo(m_pipelineInfo);
|
||||
|
|
@ -29,7 +29,7 @@ namespace Nz
|
|||
pipelineCreateInfo.renderPass = renderPass;
|
||||
|
||||
Vk::Pipeline newPipeline;
|
||||
if (!newPipeline.CreateGraphics(m_device, pipelineCreateInfo))
|
||||
if (!newPipeline.CreateGraphics(*m_device, pipelineCreateInfo))
|
||||
return VK_NULL_HANDLE;
|
||||
|
||||
auto it = m_pipelines.emplace(renderPass, std::move(newPipeline)).first;
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
bool VulkanRenderPipelineLayout::Create(Vk::DeviceHandle device, RenderPipelineLayoutInfo layoutInfo)
|
||||
bool VulkanRenderPipelineLayout::Create(Vk::Device& device, RenderPipelineLayoutInfo layoutInfo)
|
||||
{
|
||||
m_device = std::move(device);
|
||||
m_device = &device;
|
||||
m_layoutInfo = std::move(layoutInfo);
|
||||
|
||||
StackVector<VkDescriptorSetLayoutBinding> layoutBindings = NazaraStackVector(VkDescriptorSetLayoutBinding, m_layoutInfo.bindings.size());
|
||||
|
|
@ -28,10 +28,10 @@ namespace Nz
|
|||
layoutBinding.stageFlags = ToVulkan(bindingInfo.shaderStageFlags);
|
||||
}
|
||||
|
||||
if (!m_descriptorSetLayout.Create(m_device, layoutBindings.size(), layoutBindings.data()))
|
||||
if (!m_descriptorSetLayout.Create(*m_device, UInt32(layoutBindings.size()), layoutBindings.data()))
|
||||
return false;
|
||||
|
||||
if (!m_pipelineLayout.Create(m_device, m_descriptorSetLayout))
|
||||
if (!m_pipelineLayout.Create(*m_device, m_descriptorSetLayout))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ namespace Nz
|
|||
|
||||
for (const Vk::PhysicalDevice& physDevice : m_physDevices)
|
||||
{
|
||||
RenderDeviceInfo device;
|
||||
RenderDeviceInfo& device = devices.emplace_back();
|
||||
device.name = physDevice.properties.deviceName;
|
||||
|
||||
switch (physDevice.properties.deviceType)
|
||||
|
|
@ -100,8 +100,6 @@ namespace Nz
|
|||
device.type = RenderDeviceType::Unknown;
|
||||
break;
|
||||
}
|
||||
|
||||
devices.emplace_back(std::move(device));
|
||||
}
|
||||
|
||||
return devices;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
bool VulkanShaderStage::Create(const Vk::DeviceHandle& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
bool VulkanShaderStage::Create(Vk::Device& device, ShaderStageType type, ShaderLanguage lang, const void* source, std::size_t sourceSize)
|
||||
{
|
||||
if (lang != ShaderLanguage::SpirV)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Queue.hpp>
|
||||
|
|
@ -12,6 +13,28 @@ namespace Nz
|
|||
{
|
||||
namespace Vk
|
||||
{
|
||||
Device::Device(Instance& instance) :
|
||||
m_instance(instance),
|
||||
m_physicalDevice(nullptr),
|
||||
m_device(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
Device::~Device()
|
||||
{
|
||||
if (m_device != VK_NULL_HANDLE)
|
||||
WaitAndDestroyDevice();
|
||||
}
|
||||
|
||||
void Device::Destroy()
|
||||
{
|
||||
if (m_device != VK_NULL_HANDLE)
|
||||
{
|
||||
WaitAndDestroyDevice();
|
||||
ResetPointers();
|
||||
}
|
||||
}
|
||||
|
||||
bool Device::Create(const Vk::PhysicalDevice& deviceInfo, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateDevice(deviceInfo.device, &createInfo, allocator, &m_device);
|
||||
|
|
@ -21,6 +44,8 @@ namespace Nz
|
|||
return false;
|
||||
}
|
||||
|
||||
CallOnExit destroyOnFailure([this] { Destroy(); });
|
||||
|
||||
m_physicalDevice = &deviceInfo;
|
||||
|
||||
// Store the allocator to access them when needed
|
||||
|
|
@ -53,7 +78,7 @@ namespace Nz
|
|||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError(String("Failed to query device function: ") + e.what());
|
||||
NazaraError(std::string("Failed to query device function: ") + e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -88,6 +113,8 @@ namespace Nz
|
|||
for (const QueueFamilyInfo& familyInfo : m_enabledQueuesInfos)
|
||||
m_queuesByFamily[familyInfo.familyIndex] = &familyInfo.queues;
|
||||
|
||||
destroyOnFailure.Reset();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -96,8 +123,37 @@ namespace Nz
|
|||
VkQueue queue;
|
||||
vkGetDeviceQueue(m_device, queueFamilyIndex, queueIndex, &queue);
|
||||
|
||||
return Queue(shared_from_this(), queue);
|
||||
return Queue(*this, queue);
|
||||
}
|
||||
|
||||
void Device::WaitAndDestroyDevice()
|
||||
{
|
||||
assert(m_device != VK_NULL_HANDLE);
|
||||
|
||||
if (vkDeviceWaitIdle)
|
||||
vkDeviceWaitIdle(m_device);
|
||||
|
||||
m_internalData.reset();
|
||||
|
||||
if (vkDestroyDevice)
|
||||
vkDestroyDevice(m_device, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
}
|
||||
|
||||
void Device::ResetPointers()
|
||||
{
|
||||
m_device = VK_NULL_HANDLE;
|
||||
m_physicalDevice = nullptr;
|
||||
|
||||
// Reset functions pointers
|
||||
#define NAZARA_VULKANRENDERER_DEVICE_EXT_BEGIN(ext)
|
||||
#define NAZARA_VULKANRENDERER_DEVICE_EXT_END()
|
||||
#define NAZARA_VULKANRENDERER_DEVICE_FUNCTION(func) func = nullptr;
|
||||
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceFunctions.hpp>
|
||||
|
||||
#undef NAZARA_VULKANRENDERER_DEVICE_EXT_BEGIN
|
||||
#undef NAZARA_VULKANRENDERER_DEVICE_EXT_END
|
||||
#undef NAZARA_VULKANRENDERER_DEVICE_FUNCTION
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,5 +103,20 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
void Instance::ResetPointers()
|
||||
{
|
||||
assert(m_instance != VK_NULL_HANDLE);
|
||||
m_instance = VK_NULL_HANDLE;
|
||||
|
||||
#define NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN(ext)
|
||||
#define NAZARA_VULKANRENDERER_INSTANCE_EXT_END()
|
||||
#define NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(func) func = nullptr;
|
||||
|
||||
#include <Nazara/VulkanRenderer/Wrapper/InstanceFunctions.hpp>
|
||||
|
||||
#undef NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN
|
||||
#undef NAZARA_VULKANRENDERER_INSTANCE_EXT_END
|
||||
#undef NAZARA_VULKANRENDERER_INSTANCE_FUNCTION
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue