diff --git a/examples/VulkanTest/main.cpp b/examples/VulkanTest/main.cpp index 2e202b811..c579594be 100644 --- a/examples/VulkanTest/main.cpp +++ b/examples/VulkanTest/main.cpp @@ -139,14 +139,14 @@ int main() Nz::VulkanDevice& device = vulkanWindow.GetDevice(); Nz::Vk::ShaderModule vertexShader; - if (!vertexShader.Create(device.CreateHandle(), reinterpret_cast(vertexShaderCode.data()), vertexShaderCode.size())) + if (!vertexShader.Create(device.shared_from_this(), reinterpret_cast(vertexShaderCode.data()), vertexShaderCode.size())) { NazaraError("Failed to create vertex shader"); return __LINE__; } Nz::Vk::ShaderModule fragmentShader; - if (!fragmentShader.Create(device.CreateHandle(), reinterpret_cast(fragmentShaderCode.data()), fragmentShaderCode.size())) + if (!fragmentShader.Create(device.shared_from_this(), reinterpret_cast(fragmentShaderCode.data()), fragmentShaderCode.size())) { NazaraError("Failed to create fragment shader"); return __LINE__; @@ -205,7 +205,7 @@ int main() Nz::UInt32 uniformSize = sizeof(ubo); Nz::Vk::Buffer uniformBuffer; - if (!uniformBuffer.Create(device.CreateHandle(), 0, uniformSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) + if (!uniformBuffer.Create(device.shared_from_this(), 0, uniformSize, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) { NazaraError("Failed to create vertex buffer"); return __LINE__; @@ -214,7 +214,7 @@ int main() VkMemoryRequirements memRequirement = uniformBuffer.GetMemoryRequirements(); Nz::Vk::DeviceMemory uniformBufferMemory; - if (!uniformBufferMemory.Create(device.CreateHandle(), memRequirement.size, memRequirement.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) + if (!uniformBufferMemory.Create(device.shared_from_this(), memRequirement.size, memRequirement.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) { NazaraError("Failed to allocate vertex buffer memory"); return __LINE__; @@ -245,7 +245,7 @@ int main() layoutBinding.pImmutableSamplers = nullptr; Nz::Vk::DescriptorSetLayout descriptorLayout; - if (!descriptorLayout.Create(device.CreateHandle(), layoutBinding)) + if (!descriptorLayout.Create(device.shared_from_this(), layoutBinding)) { NazaraError("Failed to create descriptor set layout"); return __LINE__; @@ -256,7 +256,7 @@ int main() poolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; Nz::Vk::DescriptorPool descriptorPool; - if (!descriptorPool.Create(device.CreateHandle(), 1, poolSize, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) + if (!descriptorPool.Create(device.shared_from_this(), 1, poolSize, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) { NazaraError("Failed to create descriptor pool"); return __LINE__; @@ -405,7 +405,7 @@ int main() }; Nz::Vk::PipelineLayout pipelineLayout; - pipelineLayout.Create(device.CreateHandle(), layout_create_info); + pipelineLayout.Create(device.shared_from_this(), layout_create_info); std::array dynamicStates = { VK_DYNAMIC_STATE_SCISSOR, @@ -458,14 +458,14 @@ int main() }; Nz::Vk::Pipeline pipeline; - if (!pipeline.CreateGraphics(device.CreateHandle(), pipeline_create_info)) + if (!pipeline.CreateGraphics(device.shared_from_this(), pipeline_create_info)) { NazaraError("Failed to create pipeline"); return __LINE__; } Nz::Vk::CommandPool cmdPool; - if (!cmdPool.Create(device.CreateHandle(), 0, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)) + if (!cmdPool.Create(device.shared_from_this(), 0, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT)) { NazaraError("Failed to create rendering cmd pool"); return __LINE__; @@ -475,7 +475,7 @@ int main() clearValues[0].color = {1.0f, 0.8f, 0.4f, 0.0f}; clearValues[1].depthStencil = {1.f, 0}; - Nz::Vk::Queue graphicsQueue(device.CreateHandle(), device.GetEnabledQueues()[0].queues[0].queue); + Nz::Vk::Queue graphicsQueue(device.shared_from_this(), device.GetEnabledQueues()[0].queues[0].queue); Nz::UInt32 imageCount = vulkanWindow.GetFramebufferCount(); std::vector renderCmds = cmdPool.AllocateCommandBuffers(imageCount, VK_COMMAND_BUFFER_LEVEL_PRIMARY); diff --git a/include/Nazara/VulkanRenderer/Wrapper/Buffer.hpp b/include/Nazara/VulkanRenderer/Wrapper/Buffer.hpp index 5783791c5..53648a0f9 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Buffer.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/Buffer.hpp @@ -27,7 +27,7 @@ namespace Nz bool BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset = 0); using DeviceObject::Create; - inline bool Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator = nullptr); VkMemoryRequirements GetMemoryRequirements() const; diff --git a/include/Nazara/VulkanRenderer/Wrapper/Buffer.inl b/include/Nazara/VulkanRenderer/Wrapper/Buffer.inl index 73ad69566..9b5e41bdd 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Buffer.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/Buffer.inl @@ -21,7 +21,7 @@ namespace Nz return true; } - inline bool Buffer::Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator) + inline bool Buffer::Create(DeviceHandle device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator) { VkBufferCreateInfo createInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType; @@ -34,7 +34,7 @@ namespace Nz nullptr // const uint32_t* pQueueFamilyIndices; }; - return Create(device, createInfo, allocator); + return Create(std::move(device), createInfo, allocator); } inline VkMemoryRequirements Buffer::GetMemoryRequirements() const diff --git a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp index 5ef24bd7d..aad18cee7 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp @@ -86,7 +86,7 @@ namespace Nz private: inline CommandBuffer(CommandPool& pool, VkCommandBuffer handle); - CommandPoolHandle m_pool; + CommandPool* m_pool; VkAllocationCallbacks m_allocator; VkCommandBuffer m_handle; VkResult m_lastErrorCode; diff --git a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl index c020d284f..62db2a27a 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/CommandBuffer.inl @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace Nz @@ -12,7 +13,7 @@ namespace Nz namespace Vk { inline CommandBuffer::CommandBuffer() : - m_pool(), + m_pool(nullptr), m_handle(VK_NULL_HANDLE) { } @@ -24,7 +25,7 @@ namespace Nz } inline CommandBuffer::CommandBuffer(CommandBuffer&& commandBuffer) : - m_pool(std::move(commandBuffer.m_pool)), + m_pool(commandBuffer.m_pool), m_allocator(commandBuffer.m_allocator), m_handle(commandBuffer.m_handle), m_lastErrorCode(commandBuffer.m_lastErrorCode) @@ -223,7 +224,10 @@ namespace Nz inline void CommandBuffer::Free() { if (m_handle) + { + assert(m_pool); m_pool->GetDevice()->vkFreeCommandBuffers(*m_pool->GetDevice(), *m_pool, 1, &m_handle); + } } inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier) @@ -401,7 +405,7 @@ namespace Nz m_allocator = commandBuffer.m_allocator; m_handle = commandBuffer.m_handle; m_lastErrorCode = commandBuffer.m_lastErrorCode; - m_pool = std::move(commandBuffer.m_pool); + m_pool = commandBuffer.m_pool; m_handle = commandBuffer.m_handle; commandBuffer.m_handle = VK_NULL_HANDLE; diff --git a/include/Nazara/VulkanRenderer/Wrapper/CommandPool.hpp b/include/Nazara/VulkanRenderer/Wrapper/CommandPool.hpp index 7be788954..8d65e4fa9 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/CommandPool.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/CommandPool.hpp @@ -8,7 +8,6 @@ #define NAZARA_VULKANRENDERER_VKCOMMANDPOOL_HPP #include -#include #include namespace Nz @@ -16,11 +15,8 @@ namespace Nz namespace Vk { class CommandBuffer; - class CommandPool; - using CommandPoolHandle = ObjectHandle; - - class NAZARA_VULKANRENDERER_API CommandPool : public DeviceObject, public HandledObject + class NAZARA_VULKANRENDERER_API CommandPool : public DeviceObject { friend DeviceObject; @@ -34,7 +30,7 @@ namespace Nz std::vector AllocateCommandBuffers(UInt32 commandBufferCount, VkCommandBufferLevel level); using DeviceObject::Create; - inline bool Create(const DeviceHandle& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); inline bool Reset(VkCommandPoolResetFlags flags); diff --git a/include/Nazara/VulkanRenderer/Wrapper/CommandPool.inl b/include/Nazara/VulkanRenderer/Wrapper/CommandPool.inl index 90c952654..5ce0e58a3 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/CommandPool.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/CommandPool.inl @@ -11,7 +11,7 @@ namespace Nz { namespace Vk { - inline bool CommandPool::Create(const DeviceHandle& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags, const VkAllocationCallbacks* allocator) + inline bool CommandPool::Create(DeviceHandle device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags, const VkAllocationCallbacks* allocator) { VkCommandPoolCreateInfo createInfo = { @@ -21,7 +21,7 @@ namespace Nz queueFamilyIndex }; - return Create(device, createInfo, allocator); + return Create(std::move(device), createInfo, allocator); } inline bool CommandPool::Reset(VkCommandPoolResetFlags flags) diff --git a/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.hpp b/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.hpp index e087b58b2..0ca9a0c59 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.hpp @@ -8,19 +8,15 @@ #define NAZARA_VULKANRENDERER_VKDESCRIPTORPOOL_HPP #include -#include #include namespace Nz { namespace Vk { - class DescriptorPool; class DescriptorSet; - using DescriptorPoolHandle = ObjectHandle; - - class NAZARA_VULKANRENDERER_API DescriptorPool : public DeviceObject, public HandledObject + class NAZARA_VULKANRENDERER_API DescriptorPool : public DeviceObject { friend DeviceObject; @@ -34,8 +30,8 @@ namespace Nz std::vector AllocateDescriptorSets(UInt32 descriptorSetCount, const VkDescriptorSetLayout* setLayouts); using DeviceObject::Create; - inline bool Create(const DeviceHandle& device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); - inline bool Create(const DeviceHandle& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); DescriptorPool& operator=(const DescriptorPool&) = delete; DescriptorPool& operator=(DescriptorPool&&) = delete; diff --git a/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.inl b/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.inl index cd81effcc..f407edef0 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/DescriptorPool.inl @@ -9,7 +9,7 @@ namespace Nz { namespace Vk { - inline bool DescriptorPool::Create(const DeviceHandle& device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator) + inline bool DescriptorPool::Create(DeviceHandle device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator) { VkDescriptorPoolCreateInfo createInfo = { @@ -21,10 +21,10 @@ namespace Nz &poolSize // const VkDescriptorPoolSize* pPoolSizes; }; - return Create(device, createInfo, allocator); + return Create(std::move(device), createInfo, allocator); } - inline bool DescriptorPool::Create(const DeviceHandle& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator) + inline bool DescriptorPool::Create(DeviceHandle device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator) { VkDescriptorPoolCreateInfo createInfo = { @@ -36,7 +36,7 @@ namespace Nz poolSize // const VkDescriptorPoolSize* pPoolSizes; }; - return Create(device, createInfo, allocator); + return Create(std::move(device), createInfo, allocator); } inline VkResult DescriptorPool::CreateHelper(const DeviceHandle& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle) diff --git a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp index c9afa477e..68a8d1644 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp @@ -45,7 +45,7 @@ namespace Nz private: inline DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle); - DescriptorPoolHandle m_pool; + DescriptorPool* m_pool; VkAllocationCallbacks m_allocator; VkDescriptorSet m_handle; VkResult m_lastErrorCode; diff --git a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl index c94c48806..30d735eb5 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSet.inl @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace Nz @@ -12,7 +13,7 @@ namespace Nz namespace Vk { inline DescriptorSet::DescriptorSet() : - m_pool(), + m_pool(nullptr), m_handle(VK_NULL_HANDLE) { } @@ -24,7 +25,7 @@ namespace Nz } inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) : - m_pool(std::move(descriptorSet.m_pool)), + m_pool(descriptorSet.m_pool), m_allocator(descriptorSet.m_allocator), m_handle(descriptorSet.m_handle), m_lastErrorCode(descriptorSet.m_lastErrorCode) @@ -40,7 +41,10 @@ namespace Nz inline void DescriptorSet::Free() { if (m_handle) + { + assert(m_pool); m_pool->GetDevice()->vkFreeDescriptorSets(*m_pool->GetDevice(), *m_pool, 1, &m_handle); + } } inline VkResult DescriptorSet::GetLastErrorCode() const @@ -104,7 +108,7 @@ namespace Nz m_allocator = descriptorSet.m_allocator; m_handle = descriptorSet.m_handle; m_lastErrorCode = descriptorSet.m_lastErrorCode; - m_pool = std::move(descriptorSet.m_pool); + m_pool = descriptorSet.m_pool; m_handle = descriptorSet.m_handle; descriptorSet.m_handle = VK_NULL_HANDLE; diff --git a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSetLayout.hpp b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSetLayout.hpp index fc0c69c34..b5f1dd9ee 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSetLayout.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSetLayout.hpp @@ -25,8 +25,8 @@ namespace Nz ~DescriptorSetLayout() = default; using DeviceObject::Create; - inline bool Create(const DeviceHandle& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); - inline bool Create(const DeviceHandle& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); DescriptorSetLayout& operator=(const DescriptorSetLayout&) = delete; DescriptorSetLayout& operator=(DescriptorSetLayout&&) = delete; diff --git a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSetLayout.inl b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSetLayout.inl index 707d6ccdd..8989a4768 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DescriptorSetLayout.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/DescriptorSetLayout.inl @@ -9,12 +9,12 @@ namespace Nz { namespace Vk { - inline bool DescriptorSetLayout::Create(const DeviceHandle& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator) + inline bool DescriptorSetLayout::Create(DeviceHandle device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator) { - return Create(device, 1U, &binding, flags, allocator); + return Create(std::move(device), 1U, &binding, flags, allocator); } - inline bool DescriptorSetLayout::Create(const DeviceHandle& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator) + inline bool DescriptorSetLayout::Create(DeviceHandle device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator) { VkDescriptorSetLayoutCreateInfo createInfo = { @@ -25,7 +25,7 @@ namespace Nz binding // const VkDescriptorSetLayoutBinding* pBindings; }; - return Create(device, createInfo, allocator); + return Create(std::move(device), createInfo, allocator); } inline VkResult DescriptorSetLayout::CreateHelper(const DeviceHandle& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle) diff --git a/include/Nazara/VulkanRenderer/Wrapper/Device.hpp b/include/Nazara/VulkanRenderer/Wrapper/Device.hpp index 01e508372..3d72b4b7d 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Device.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/Device.hpp @@ -8,11 +8,10 @@ #define NAZARA_VULKANRENDERER_VKDEVICE_HPP #include -#include -#include #include #include #include +#include #include namespace Nz @@ -23,9 +22,9 @@ namespace Nz class Instance; class Queue; - using DeviceHandle = ObjectHandle; + using DeviceHandle = std::shared_ptr; - class NAZARA_VULKANRENDERER_API Device : public HandledObject + class NAZARA_VULKANRENDERER_API Device : public std::enable_shared_from_this { public: struct QueueFamilyInfo; diff --git a/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.hpp b/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.hpp index 67b319083..3a57dc1b5 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.hpp @@ -25,8 +25,8 @@ namespace Nz ~DeviceMemory() = default; using DeviceObject::Create; - inline bool Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator = nullptr); - inline bool Create(const DeviceHandle& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator = nullptr); inline void* GetMappedPointer(); diff --git a/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.inl b/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.inl index 64e2f7618..c3bb310ba 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/DeviceMemory.inl @@ -24,7 +24,7 @@ namespace Nz memory.m_mappedPtr = nullptr; } - inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator) + inline bool DeviceMemory::Create(DeviceHandle device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator) { VkMemoryAllocateInfo allocInfo = { @@ -34,10 +34,10 @@ namespace Nz memoryType // uint32_t memoryTypeIndex; }; - return Create(device, allocInfo, allocator); + return Create(std::move(device), allocInfo, allocator); } - inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator) + inline bool DeviceMemory::Create(DeviceHandle device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator) { const Vk::PhysicalDevice& deviceInfo = Vulkan::GetPhysicalDeviceInfo(device->GetPhysicalDevice()); @@ -47,7 +47,7 @@ namespace Nz if (typeBits & typeMask) { if ((deviceInfo.memoryProperties.memoryTypes[i].propertyFlags & properties) == properties) - return Create(device, size, i, allocator); + return Create(std::move(device), size, i, allocator); } typeMask <<= 1; diff --git a/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp b/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp index e807d774a..6ee48251e 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp @@ -24,7 +24,7 @@ namespace Nz inline DeviceObject(DeviceObject&& object); inline ~DeviceObject(); - inline bool Create(const DeviceHandle& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); inline void Destroy(); inline bool IsValid() const; diff --git a/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.inl b/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.inl index a68e7a469..8ea41182a 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/DeviceObject.inl @@ -36,9 +36,9 @@ namespace Nz } template - inline bool DeviceObject::Create(const DeviceHandle& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator) + inline bool DeviceObject::Create(DeviceHandle device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator) { - m_device = device; + m_device = std::move(device); m_lastErrorCode = C::CreateHelper(m_device, &createInfo, allocator, &m_handle); if (m_lastErrorCode != VkResult::VK_SUCCESS) { diff --git a/include/Nazara/VulkanRenderer/Wrapper/Pipeline.hpp b/include/Nazara/VulkanRenderer/Wrapper/Pipeline.hpp index ea323ec49..000f3de9c 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Pipeline.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/Pipeline.hpp @@ -35,7 +35,7 @@ namespace Nz inline operator VkPipeline() const; protected: - inline bool Create(const DeviceHandle& device, VkResult result, const VkAllocationCallbacks* allocator); + inline bool Create(DeviceHandle device, VkResult result, const VkAllocationCallbacks* allocator); DeviceHandle m_device; VkAllocationCallbacks m_allocator; diff --git a/include/Nazara/VulkanRenderer/Wrapper/Pipeline.inl b/include/Nazara/VulkanRenderer/Wrapper/Pipeline.inl index d55eb95d6..cecef540b 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Pipeline.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/Pipeline.inl @@ -31,12 +31,12 @@ namespace Nz inline bool Pipeline::CreateCompute(const DeviceHandle& device, const VkComputePipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator) { - return Create(device, device->vkCreateComputePipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator); + return Create(std::move(device), device->vkCreateComputePipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator); } inline bool Pipeline::CreateGraphics(const DeviceHandle& device, const VkGraphicsPipelineCreateInfo& createInfo, VkPipelineCache cache, const VkAllocationCallbacks* allocator) { - return Create(device, device->vkCreateGraphicsPipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator); + return Create(std::move(device), device->vkCreateGraphicsPipelines(*device, cache, 1U, &createInfo, allocator, &m_handle), allocator); } inline void Pipeline::Destroy() @@ -63,7 +63,7 @@ namespace Nz return m_handle; } - inline bool Pipeline::Create(const DeviceHandle& device, VkResult result, const VkAllocationCallbacks* allocator) + inline bool Pipeline::Create(DeviceHandle device, VkResult result, const VkAllocationCallbacks* allocator) { m_device = device; m_lastErrorCode = result; diff --git a/include/Nazara/VulkanRenderer/Wrapper/Semaphore.hpp b/include/Nazara/VulkanRenderer/Wrapper/Semaphore.hpp index 8dfdf1cf9..e6e21289c 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Semaphore.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/Semaphore.hpp @@ -25,7 +25,7 @@ namespace Nz ~Semaphore() = default; using DeviceObject::Create; - inline bool Create(const DeviceHandle& device, VkSemaphoreCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, VkSemaphoreCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); Semaphore& operator=(const Semaphore&) = delete; Semaphore& operator=(Semaphore&&) = delete; diff --git a/include/Nazara/VulkanRenderer/Wrapper/Semaphore.inl b/include/Nazara/VulkanRenderer/Wrapper/Semaphore.inl index 605a59c03..60f5c8afb 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Semaphore.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/Semaphore.inl @@ -9,7 +9,7 @@ namespace Nz { namespace Vk { - inline bool Semaphore::Create(const DeviceHandle& device, VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator) + inline bool Semaphore::Create(DeviceHandle device, VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator) { VkSemaphoreCreateInfo createInfo = { @@ -18,7 +18,7 @@ namespace Nz flags }; - return Create(device, createInfo, allocator); + return Create(std::move(device), createInfo, allocator); } inline VkResult Semaphore::CreateHelper(const DeviceHandle& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle) diff --git a/include/Nazara/VulkanRenderer/Wrapper/ShaderModule.hpp b/include/Nazara/VulkanRenderer/Wrapper/ShaderModule.hpp index db00805e5..fbc5bc6c2 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/ShaderModule.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/ShaderModule.hpp @@ -25,7 +25,7 @@ namespace Nz ~ShaderModule() = default; using DeviceObject::Create; - inline bool Create(const DeviceHandle& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr); ShaderModule& operator=(const ShaderModule&) = delete; ShaderModule& operator=(ShaderModule&&) = delete; diff --git a/include/Nazara/VulkanRenderer/Wrapper/ShaderModule.inl b/include/Nazara/VulkanRenderer/Wrapper/ShaderModule.inl index fa9781226..dfe55a0e3 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/ShaderModule.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/ShaderModule.inl @@ -9,7 +9,7 @@ namespace Nz { namespace Vk { - inline bool ShaderModule::Create(const DeviceHandle& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags, const VkAllocationCallbacks* allocator) + inline bool ShaderModule::Create(DeviceHandle device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags, const VkAllocationCallbacks* allocator) { VkShaderModuleCreateInfo createInfo = { @@ -20,7 +20,7 @@ namespace Nz code }; - return Create(device, createInfo, allocator); + return Create(std::move(device), createInfo, allocator); } inline VkResult ShaderModule::CreateHelper(const DeviceHandle& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle) diff --git a/include/Nazara/VulkanRenderer/Wrapper/Swapchain.hpp b/include/Nazara/VulkanRenderer/Wrapper/Swapchain.hpp index f3d2aac89..91672502e 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Swapchain.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/Swapchain.hpp @@ -29,7 +29,7 @@ namespace Nz inline bool AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex) const; - inline bool Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr); + inline bool Create(DeviceHandle device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr); inline const Buffer& GetBuffer(UInt32 index) const; inline const std::vector& GetBuffers() const; diff --git a/include/Nazara/VulkanRenderer/Wrapper/Swapchain.inl b/include/Nazara/VulkanRenderer/Wrapper/Swapchain.inl index 5561ac3f0..2ad91cdb4 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Swapchain.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/Swapchain.inl @@ -29,9 +29,9 @@ namespace Nz } } - inline bool Swapchain::Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator) + inline bool Swapchain::Create(DeviceHandle device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator) { - if (!DeviceObject::Create(device, createInfo, allocator)) + if (!DeviceObject::Create(std::move(device), createInfo, allocator)) return false; UInt32 imageCount = 0; diff --git a/src/Nazara/VulkanRenderer/VkRenderWindow.cpp b/src/Nazara/VulkanRenderer/VkRenderWindow.cpp index cc1c7de57..62056f217 100644 --- a/src/Nazara/VulkanRenderer/VkRenderWindow.cpp +++ b/src/Nazara/VulkanRenderer/VkRenderWindow.cpp @@ -187,14 +187,14 @@ namespace Nz 1U // uint32_t layers; }; - if (!m_frameBuffers[i].Create(m_device->CreateHandle(), frameBufferCreate)) + if (!m_frameBuffers[i].Create(m_device, frameBufferCreate)) { NazaraError("Failed to create framebuffer for image #" + String::Number(i)); return false; } } - m_imageReadySemaphore.Create(m_device->CreateHandle()); + m_imageReadySemaphore.Create(m_device); m_clock.Restart(); @@ -221,14 +221,14 @@ namespace Nz VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout; }; - if (!m_depthBuffer.Create(m_device->CreateHandle(), imageCreateInfo)) + if (!m_depthBuffer.Create(m_device, imageCreateInfo)) { NazaraError("Failed to create depth buffer"); return false; } VkMemoryRequirements memoryReq = m_depthBuffer.GetMemoryRequirements(); - if (!m_depthBufferMemory.Create(m_device->CreateHandle(), memoryReq.size, memoryReq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) + if (!m_depthBufferMemory.Create(m_device, memoryReq.size, memoryReq.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) { NazaraError("Failed to allocate depth buffer memory"); return false; @@ -262,7 +262,7 @@ namespace Nz } }; - if (!m_depthBufferView.Create(m_device->CreateHandle(), imageViewCreateInfo)) + if (!m_depthBufferView.Create(m_device, imageViewCreateInfo)) { NazaraError("Failed to create depth buffer view"); return false; @@ -356,7 +356,7 @@ namespace Nz dependencies.data() // const VkSubpassDependency* pDependencies; }; - return m_renderPass.Create(m_device->CreateHandle(), createInfo); + return m_renderPass.Create(m_device, createInfo); } bool VkRenderWindow::SetupSwapchain(Vk::Surface& surface, const Vector2ui& size) @@ -421,7 +421,7 @@ namespace Nz 0 }; - if (!m_swapchain.Create(m_device->CreateHandle(), swapchainInfo)) + if (!m_swapchain.Create(m_device, swapchainInfo)) { NazaraError("Failed to create swapchain"); return false; diff --git a/src/Nazara/VulkanRenderer/VulkanDevice.cpp b/src/Nazara/VulkanRenderer/VulkanDevice.cpp index 2557f28b0..d1c0e736e 100644 --- a/src/Nazara/VulkanRenderer/VulkanDevice.cpp +++ b/src/Nazara/VulkanRenderer/VulkanDevice.cpp @@ -11,6 +11,6 @@ namespace Nz std::unique_ptr VulkanDevice::InstantiateBuffer(Buffer* parent, BufferType type) { - return std::make_unique(CreateHandle(), parent, type); + return std::make_unique(shared_from_this(), parent, type); } } diff --git a/src/Nazara/VulkanRenderer/Wrapper/Device.cpp b/src/Nazara/VulkanRenderer/Wrapper/Device.cpp index 247f5a27c..88dedd878 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/Device.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/Device.cpp @@ -225,7 +225,7 @@ namespace Nz VkQueue queue; vkGetDeviceQueue(m_device, queueFamilyIndex, queueIndex, &queue); - return Queue(CreateHandle(), queue); + return Queue(shared_from_this(), queue); } }