diff --git a/include/Nazara/Vulkan/VkFramebuffer.hpp b/include/Nazara/Vulkan/VkFramebuffer.hpp new file mode 100644 index 000000000..9c93674b6 --- /dev/null +++ b/include/Nazara/Vulkan/VkFramebuffer.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VULKAN_VKFRAMEBUFFER_HPP +#define NAZARA_VULKAN_VKFRAMEBUFFER_HPP + +#include +#include + +namespace Nz +{ + namespace Vk + { + class Framebuffer : public DeviceObject + { + friend DeviceObject; + + public: + Framebuffer() = default; + Framebuffer(const Framebuffer&) = delete; + Framebuffer(Framebuffer&&) = default; + ~Framebuffer() = default; + + Framebuffer& operator=(const Framebuffer&) = delete; + 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); + }; + } +} + +#include + +#endif // NAZARA_VULKAN_VKFRAMEBUFFER_HPP diff --git a/include/Nazara/Vulkan/VkFramebuffer.inl b/include/Nazara/Vulkan/VkFramebuffer.inl new file mode 100644 index 000000000..67790caa9 --- /dev/null +++ b/include/Nazara/Vulkan/VkFramebuffer.inl @@ -0,0 +1,24 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + namespace Vk + { + inline VkResult Framebuffer::CreateHelper(const DeviceHandle& device, const VkFramebufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFramebuffer* handle) + { + return device->vkCreateFramebuffer(*device, createInfo, allocator, handle); + } + + inline void Framebuffer::DestroyHelper(const DeviceHandle& device, VkFramebuffer handle, const VkAllocationCallbacks* allocator) + { + return device->vkDestroyFramebuffer(*device, handle, allocator); + } + } +} + +#include diff --git a/include/Nazara/Vulkan/VkImageView.hpp b/include/Nazara/Vulkan/VkImageView.hpp new file mode 100644 index 000000000..783477182 --- /dev/null +++ b/include/Nazara/Vulkan/VkImageView.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VULKAN_VKIMAGEVIEW_HPP +#define NAZARA_VULKAN_VKIMAGEVIEW_HPP + +#include +#include + +namespace Nz +{ + namespace Vk + { + class ImageView : public DeviceObject + { + friend DeviceObject; + + public: + ImageView() = default; + ImageView(const ImageView&) = delete; + ImageView(ImageView&&) = default; + ~ImageView() = default; + + ImageView& operator=(const ImageView&) = delete; + 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); + }; + } +} + +#include + +#endif // NAZARA_VULKAN_VKIMAGEVIEW_HPP diff --git a/include/Nazara/Vulkan/VkImageView.inl b/include/Nazara/Vulkan/VkImageView.inl new file mode 100644 index 000000000..ca7617b6e --- /dev/null +++ b/include/Nazara/Vulkan/VkImageView.inl @@ -0,0 +1,24 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + namespace Vk + { + inline VkResult ImageView::CreateHelper(const DeviceHandle& device, const VkImageViewCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImageView* handle) + { + return device->vkCreateImageView(*device, createInfo, allocator, handle); + } + + inline void ImageView::DestroyHelper(const DeviceHandle& device, VkImageView handle, const VkAllocationCallbacks* allocator) + { + return device->vkDestroyImageView(*device, handle, allocator); + } + } +} + +#include diff --git a/include/Nazara/Vulkan/VkPipeline.hpp b/include/Nazara/Vulkan/VkPipeline.hpp new file mode 100644 index 000000000..f788e4f70 --- /dev/null +++ b/include/Nazara/Vulkan/VkPipeline.hpp @@ -0,0 +1,50 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VULKAN_VKPIPELINE_HPP +#define NAZARA_VULKAN_VKPIPELINE_HPP + +#include +#include + +namespace Nz +{ + namespace Vk + { + class Pipeline + { + public: + inline Pipeline(); + Pipeline(const Pipeline&) = delete; + 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 void Destroy(); + + inline const DeviceHandle& GetDevice() const; + inline VkResult GetLastErrorCode() const; + + Pipeline& operator=(const Pipeline&) = delete; + Pipeline& operator=(Pipeline&&) = delete; + + inline operator VkPipeline() const; + + protected: + inline bool Create(const DeviceHandle& device, VkResult result, const VkAllocationCallbacks* allocator); + + DeviceHandle m_device; + VkAllocationCallbacks m_allocator; + VkPipeline m_handle; + mutable VkResult m_lastErrorCode; + }; + } +} + +#include + +#endif // NAZARA_VULKAN_VKPIPELINE_HPP diff --git a/include/Nazara/Vulkan/VkPipeline.inl b/include/Nazara/Vulkan/VkPipeline.inl new file mode 100644 index 000000000..4325c5f78 --- /dev/null +++ b/include/Nazara/Vulkan/VkPipeline.inl @@ -0,0 +1,85 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + namespace Vk + { + inline Pipeline::Pipeline() : + m_handle(VK_NULL_HANDLE) + { + } + + inline Pipeline::Pipeline(Pipeline&& object) : + m_device(std::move(object.m_device)), + m_allocator(object.m_allocator), + m_handle(object.m_handle), + m_lastErrorCode(object.m_lastErrorCode) + { + object.m_handle = VK_NULL_HANDLE; + } + + inline Pipeline::~Pipeline() + { + Destroy(); + } + + 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); + } + + 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); + } + + inline void Pipeline::Destroy() + { + if (m_handle != VK_NULL_HANDLE) + { + m_device->vkDestroyPipeline(*m_device, m_handle, (m_allocator.pfnAllocation) ? &m_allocator : nullptr); + m_handle = VK_NULL_HANDLE; + } + } + + inline const DeviceHandle& Pipeline::GetDevice() const + { + return m_device; + } + + inline VkResult Pipeline::GetLastErrorCode() const + { + return m_lastErrorCode; + } + + inline Pipeline::operator VkPipeline() const + { + return m_handle; + } + + inline bool Pipeline::Create(const DeviceHandle& device, VkResult result, const VkAllocationCallbacks* allocator) + { + m_device = device; + if (m_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to create Vulkan object"); + return false; + } + + // Store the allocator to access them when needed + if (allocator) + m_allocator = *allocator; + else + m_allocator.pfnAllocation = nullptr; + + return true; + } + } +} + +#include diff --git a/include/Nazara/Vulkan/VkPipelineCache.hpp b/include/Nazara/Vulkan/VkPipelineCache.hpp new file mode 100644 index 000000000..1dac25ce1 --- /dev/null +++ b/include/Nazara/Vulkan/VkPipelineCache.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VULKAN_VKPIPELINECACHE_HPP +#define NAZARA_VULKAN_VKPIPELINECACHE_HPP + +#include +#include + +namespace Nz +{ + namespace Vk + { + class PipelineCache : public DeviceObject + { + friend DeviceObject; + + public: + PipelineCache() = default; + PipelineCache(const PipelineCache&) = delete; + PipelineCache(PipelineCache&&) = default; + ~PipelineCache() = default; + + PipelineCache& operator=(const PipelineCache&) = delete; + 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); + }; + } +} + +#include + +#endif // NAZARA_VULKAN_VKPIPELINECACHE_HPP diff --git a/include/Nazara/Vulkan/VkPipelineCache.inl b/include/Nazara/Vulkan/VkPipelineCache.inl new file mode 100644 index 000000000..9f272c41d --- /dev/null +++ b/include/Nazara/Vulkan/VkPipelineCache.inl @@ -0,0 +1,24 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + namespace Vk + { + inline VkResult PipelineCache::CreateHelper(const DeviceHandle& device, const VkPipelineCacheCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineCache* handle) + { + return device->vkCreatePipelineCache(*device, createInfo, allocator, handle); + } + + inline void PipelineCache::DestroyHelper(const DeviceHandle& device, VkPipelineCache handle, const VkAllocationCallbacks* allocator) + { + return device->vkDestroyPipelineCache(*device, handle, allocator); + } + } +} + +#include diff --git a/include/Nazara/Vulkan/VkPipelineLayout.hpp b/include/Nazara/Vulkan/VkPipelineLayout.hpp new file mode 100644 index 000000000..0d78fa23d --- /dev/null +++ b/include/Nazara/Vulkan/VkPipelineLayout.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VULKAN_VKPIPELINELAYOUT_HPP +#define NAZARA_VULKAN_VKPIPELINELAYOUT_HPP + +#include +#include + +namespace Nz +{ + namespace Vk + { + class PipelineLayout : public DeviceObject + { + friend DeviceObject; + + public: + PipelineLayout() = default; + PipelineLayout(const PipelineLayout&) = delete; + PipelineLayout(PipelineLayout&&) = default; + ~PipelineLayout() = default; + + 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); + }; + } +} + +#include + +#endif // NAZARA_VULKAN_VKPIPELINELAYOUT_HPP diff --git a/include/Nazara/Vulkan/VkPipelineLayout.inl b/include/Nazara/Vulkan/VkPipelineLayout.inl new file mode 100644 index 000000000..468bf7b0f --- /dev/null +++ b/include/Nazara/Vulkan/VkPipelineLayout.inl @@ -0,0 +1,24 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + namespace Vk + { + inline VkResult PipelineLayout::CreateHelper(const DeviceHandle& device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkPipelineLayout* handle) + { + return device->vkCreatePipelineLayout(*device, createInfo, allocator, handle); + } + + inline void PipelineLayout::DestroyHelper(const DeviceHandle& device, VkPipelineLayout handle, const VkAllocationCallbacks* allocator) + { + return device->vkDestroyPipelineLayout(*device, handle, allocator); + } + } +} + +#include diff --git a/include/Nazara/Vulkan/VkRenderPass.hpp b/include/Nazara/Vulkan/VkRenderPass.hpp new file mode 100644 index 000000000..92ab4f868 --- /dev/null +++ b/include/Nazara/Vulkan/VkRenderPass.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VULKAN_VKRENDERPASS_HPP +#define NAZARA_VULKAN_VKRENDERPASS_HPP + +#include +#include + +namespace Nz +{ + namespace Vk + { + class RenderPass : public DeviceObject + { + friend DeviceObject; + + public: + RenderPass() = default; + RenderPass(const RenderPass&) = delete; + RenderPass(RenderPass&&) = default; + ~RenderPass() = default; + + RenderPass& operator=(const RenderPass&) = delete; + 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); + }; + } +} + +#include + +#endif // NAZARA_VULKAN_VKRENDERPASS_HPP diff --git a/include/Nazara/Vulkan/VkRenderPass.inl b/include/Nazara/Vulkan/VkRenderPass.inl new file mode 100644 index 000000000..5e826cba3 --- /dev/null +++ b/include/Nazara/Vulkan/VkRenderPass.inl @@ -0,0 +1,24 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + namespace Vk + { + inline VkResult RenderPass::CreateHelper(const DeviceHandle& device, const VkRenderPassCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkRenderPass* handle) + { + return device->vkCreateRenderPass(*device, createInfo, allocator, handle); + } + + inline void RenderPass::DestroyHelper(const DeviceHandle& device, VkRenderPass handle, const VkAllocationCallbacks* allocator) + { + return device->vkDestroyRenderPass(*device, handle, allocator); + } + } +} + +#include diff --git a/include/Nazara/Vulkan/VkShaderModule.hpp b/include/Nazara/Vulkan/VkShaderModule.hpp new file mode 100644 index 000000000..588dc6a07 --- /dev/null +++ b/include/Nazara/Vulkan/VkShaderModule.hpp @@ -0,0 +1,42 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VULKAN_VKSHADERMODULE_HPP +#define NAZARA_VULKAN_VKSHADERMODULE_HPP + +#include +#include + +namespace Nz +{ + namespace Vk + { + class ShaderModule : public DeviceObject + { + friend DeviceObject; + + public: + ShaderModule() = default; + ShaderModule(const ShaderModule&) = delete; + ShaderModule(ShaderModule&&) = default; + ~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); + + 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); + }; + } +} + +#include + +#endif // NAZARA_VULKAN_VKSHADERMODULE_HPP diff --git a/include/Nazara/Vulkan/VkShaderModule.inl b/include/Nazara/Vulkan/VkShaderModule.inl new file mode 100644 index 000000000..77b189ba0 --- /dev/null +++ b/include/Nazara/Vulkan/VkShaderModule.inl @@ -0,0 +1,38 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + namespace Vk + { + inline bool ShaderModule::Create(const DeviceHandle& device, const UInt32* code, std::size_t size, VkShaderModuleCreateFlags flags, const VkAllocationCallbacks* allocator) + { + VkShaderModuleCreateInfo createInfo = + { + VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, + nullptr, + flags, + size, + code + }; + + return Create(device, createInfo, allocator); + } + + inline VkResult ShaderModule::CreateHelper(const DeviceHandle& device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkShaderModule* handle) + { + return device->vkCreateShaderModule(*device, createInfo, allocator, handle); + } + + inline void ShaderModule::DestroyHelper(const DeviceHandle& device, VkShaderModule handle, const VkAllocationCallbacks* allocator) + { + return device->vkDestroyShaderModule(*device, handle, allocator); + } + } +} + +#include