Vulkan: Add Framebuffer, ImageView, Pipeline, PipelineCache, PipelineLayout, RenderPass and ShaderModule wrappers

Former-commit-id: fc1269a25704d1b19192062277a3593a3e39a239 [formerly 5235f84349ba6edced65db7c60800b9b52ff1a16]
Former-commit-id: 74e6cfc61f87d61e69ca20f2fd6187c2cd48c44a
This commit is contained in:
Lynix 2016-07-04 18:13:51 +02:00
parent 7146ebcfbe
commit 0702511108
14 changed files with 530 additions and 0 deletions

View File

@ -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 <Nazara/Prerequesites.hpp>
#include <Nazara/Vulkan/VkDeviceObject.hpp>
namespace Nz
{
namespace Vk
{
class Framebuffer : public DeviceObject<Framebuffer, VkFramebuffer, VkFramebufferCreateInfo>
{
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 <Nazara/Vulkan/VkFramebuffer.inl>
#endif // NAZARA_VULKAN_VKFRAMEBUFFER_HPP

View File

@ -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 <Nazara/Vulkan/VkFramebuffer.hpp>
#include <Nazara/Vulkan/Debug.hpp>
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 <Nazara/Vulkan/DebugOff.hpp>

View File

@ -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 <Nazara/Prerequesites.hpp>
#include <Nazara/Vulkan/VkDeviceObject.hpp>
namespace Nz
{
namespace Vk
{
class ImageView : public DeviceObject<ImageView, VkImageView, VkImageViewCreateInfo>
{
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 <Nazara/Vulkan/VkImageView.inl>
#endif // NAZARA_VULKAN_VKIMAGEVIEW_HPP

View File

@ -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 <Nazara/Vulkan/VkImageView.hpp>
#include <Nazara/Vulkan/Debug.hpp>
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 <Nazara/Vulkan/DebugOff.hpp>

View File

@ -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 <Nazara/Prerequesites.hpp>
#include <Nazara/Vulkan/VkDeviceObject.hpp>
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 <Nazara/Vulkan/VkPipeline.inl>
#endif // NAZARA_VULKAN_VKPIPELINE_HPP

View File

@ -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 <Nazara/Vulkan/VkPipeline.hpp>
#include <Nazara/Vulkan/Debug.hpp>
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 <Nazara/Vulkan/DebugOff.hpp>

View File

@ -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 <Nazara/Prerequesites.hpp>
#include <Nazara/Vulkan/VkDeviceObject.hpp>
namespace Nz
{
namespace Vk
{
class PipelineCache : public DeviceObject<PipelineCache, VkPipelineCache, VkPipelineCacheCreateInfo>
{
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 <Nazara/Vulkan/VkPipelineCache.inl>
#endif // NAZARA_VULKAN_VKPIPELINECACHE_HPP

View File

@ -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 <Nazara/Vulkan/VkPipelineCache.hpp>
#include <Nazara/Vulkan/Debug.hpp>
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 <Nazara/Vulkan/DebugOff.hpp>

View File

@ -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 <Nazara/Prerequesites.hpp>
#include <Nazara/Vulkan/VkDeviceObject.hpp>
namespace Nz
{
namespace Vk
{
class PipelineLayout : public DeviceObject<PipelineLayout, VkPipelineLayout, VkPipelineLayoutCreateInfo>
{
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 <Nazara/Vulkan/VkPipelineLayout.inl>
#endif // NAZARA_VULKAN_VKPIPELINELAYOUT_HPP

View File

@ -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 <Nazara/Vulkan/VkPipelineLayout.hpp>
#include <Nazara/Vulkan/Debug.hpp>
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 <Nazara/Vulkan/DebugOff.hpp>

View File

@ -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 <Nazara/Prerequesites.hpp>
#include <Nazara/Vulkan/VkDeviceObject.hpp>
namespace Nz
{
namespace Vk
{
class RenderPass : public DeviceObject<RenderPass, VkRenderPass, VkRenderPassCreateInfo>
{
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 <Nazara/Vulkan/VkRenderPass.inl>
#endif // NAZARA_VULKAN_VKRENDERPASS_HPP

View File

@ -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 <Nazara/Vulkan/VkRenderPass.hpp>
#include <Nazara/Vulkan/Debug.hpp>
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 <Nazara/Vulkan/DebugOff.hpp>

View File

@ -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 <Nazara/Prerequesites.hpp>
#include <Nazara/Vulkan/VkDeviceObject.hpp>
namespace Nz
{
namespace Vk
{
class ShaderModule : public DeviceObject<ShaderModule, VkShaderModule, VkShaderModuleCreateInfo>
{
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 <Nazara/Vulkan/VkShaderModule.inl>
#endif // NAZARA_VULKAN_VKSHADERMODULE_HPP

View File

@ -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 <Nazara/Vulkan/VkShaderModule.hpp>
#include <Nazara/Vulkan/Debug.hpp>
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 <Nazara/Vulkan/DebugOff.hpp>