Replace DeviceHandle by references
and keep device alive until Vulkan is freed
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user