Add new Renderer architecture (far from complete)
Former-commit-id: 52226793d7a087dfe0523315d3303934daffee49 [formerly 9de1c04df6b371f861a2eee8bba38902ee5041cd] [formerly ecd3099df5498722f6390447f40bd3907b8e40c4 [formerly 3076df585565fc9759ab3e718270f2e5ef620840]] Former-commit-id: 92d52f967d0b088d1271afef26069e08cacd6b0f [formerly 5fe27e2ead104278951c772c2121a7b677f88d4d] Former-commit-id: fb6c2456d8edd3ec022d5d953f79fecdd4f2b8f4
This commit is contained in:
53
include/Nazara/VulkanRenderer/Config.hpp
Normal file
53
include/Nazara/VulkanRenderer/Config.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Nazara Engine - Vulkan
|
||||
|
||||
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONFIG_VULKANRENDERER_HPP
|
||||
#define NAZARA_CONFIG_VULKANRENDERER_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
|
||||
// Utilise le MemoryManager pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
|
||||
#define NAZARA_VULKANRENDERER_MANAGE_MEMORY 0
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_VULKANRENDERER_SAFE 1
|
||||
|
||||
/// Chaque modification d'un paramètre ci-dessous implique une modification (souvent mineure) du code
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/VulkanRenderer/ConfigCheck.hpp>
|
||||
|
||||
#if !defined(NAZARA_STATIC)
|
||||
#ifdef NAZARA_VULKANRENDERER_BUILD
|
||||
#define NAZARA_VULKANRENDERER_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_VULKANRENDERER_API NAZARA_IMPORT
|
||||
#endif
|
||||
#else
|
||||
#define NAZARA_VULKANRENDERER_API
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CONFIG_MODULENAME_HPP
|
||||
22
include/Nazara/VulkanRenderer/ConfigCheck.hpp
Normal file
22
include/Nazara/VulkanRenderer/ConfigCheck.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONFIG_CHECK_VULKANE_HPP
|
||||
#define NAZARA_CONFIG_CHECK_VULKANE_HPP
|
||||
|
||||
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
|
||||
|
||||
#include <type_traits>
|
||||
#define CheckType(name, type, err) static_assert(std::is_ ##type <decltype(name)>::value, #type err)
|
||||
#define CheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
|
||||
|
||||
// On force la valeur de MANAGE_MEMORY en mode debug
|
||||
#if defined(NAZARA_DEBUG) && !NAZARA_VULKANRENDERER_MANAGE_MEMORY
|
||||
#undef NAZARA_MODULENAME_MANAGE_MEMORY
|
||||
#define NAZARA_MODULENAME_MANAGE_MEMORY 0
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CONFIG_CHECK_VULKANRENDERER_HPP
|
||||
8
include/Nazara/VulkanRenderer/Debug.hpp
Normal file
8
include/Nazara/VulkanRenderer/Debug.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#if NAZARA_MODULENAME_MANAGE_MEMORY
|
||||
#include <Nazara/Core/Debug/NewRedefinition.hpp>
|
||||
#endif
|
||||
9
include/Nazara/VulkanRenderer/DebugOff.hpp
Normal file
9
include/Nazara/VulkanRenderer/DebugOff.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
|
||||
#if NAZARA_MODULENAME_MANAGE_MEMORY
|
||||
#undef delete
|
||||
#undef new
|
||||
#endif
|
||||
60
include/Nazara/VulkanRenderer/RenderTarget.hpp
Normal file
60
include/Nazara/VulkanRenderer/RenderTarget.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (C) 201 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_RENDERTARGET_HPP
|
||||
#define NAZARA_RENDERTARGET_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkFrameBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkRenderPass.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSemaphore.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Renderer;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API RenderTarget
|
||||
{
|
||||
friend Renderer;
|
||||
|
||||
public:
|
||||
RenderTarget() = default;
|
||||
RenderTarget(const RenderTarget&) = delete;
|
||||
RenderTarget(RenderTarget&&) = delete; ///TOOD?
|
||||
virtual ~RenderTarget();
|
||||
|
||||
virtual bool Acquire(UInt32* imageIndex) const = 0;
|
||||
|
||||
virtual void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) = 0;
|
||||
virtual void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) = 0;
|
||||
|
||||
virtual const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const = 0;
|
||||
virtual UInt32 GetFramebufferCount() const = 0;
|
||||
|
||||
const Vk::RenderPass& GetRenderPass() const { return m_renderPass; }
|
||||
|
||||
const Vk::Semaphore& GetRenderSemaphore() const { return m_imageReadySemaphore; }
|
||||
|
||||
virtual void Present(UInt32 imageIndex) = 0;
|
||||
|
||||
RenderTarget& operator=(const RenderTarget&) = delete;
|
||||
RenderTarget& operator=(RenderTarget&&) = delete; ///TOOD?
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnRenderTargetRelease, const RenderTarget* /*renderTarget*/);
|
||||
NazaraSignal(OnRenderTargetSizeChange, const RenderTarget* /*renderTarget*/);
|
||||
|
||||
protected:
|
||||
Vk::RenderPass m_renderPass;
|
||||
Vk::Semaphore m_imageReadySemaphore;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERTARGET_HPP
|
||||
91
include/Nazara/VulkanRenderer/RenderWindow.hpp
Normal file
91
include/Nazara/VulkanRenderer/RenderWindow.hpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_RENDERWINDOW_HPP
|
||||
#define NAZARA_RENDERWINDOW_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/RenderTarget.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkCommandBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceMemory.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkFramebuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkImage.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSurface.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSwapchain.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API RenderWindow : public RenderTarget, public Window
|
||||
{
|
||||
public:
|
||||
RenderWindow();
|
||||
RenderWindow(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
||||
RenderWindow(WindowHandle handle);
|
||||
RenderWindow(const RenderWindow&) = delete;
|
||||
RenderWindow(RenderWindow&&) = delete; ///TODO
|
||||
virtual ~RenderWindow();
|
||||
|
||||
bool Acquire(UInt32* index) const override;
|
||||
|
||||
void BuildPreRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
||||
void BuildPostRenderCommands(UInt32 imageIndex, Vk::CommandBuffer& commandBuffer) override;
|
||||
|
||||
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
||||
bool Create(WindowHandle handle);
|
||||
|
||||
const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const override;
|
||||
UInt32 GetFramebufferCount() const;
|
||||
const Vk::DeviceHandle& GetDevice() const;
|
||||
UInt32 GetPresentableFamilyQueue() const;
|
||||
const Vk::Surface& GetSurface() const;
|
||||
const Vk::Swapchain& GetSwapchain() const;
|
||||
|
||||
void Present(UInt32 imageIndex) override;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void SetDepthStencilFormats(std::vector<PixelFormatType> pixelFormat);
|
||||
void SetPhysicalDevice(VkPhysicalDevice device);
|
||||
|
||||
RenderWindow& operator=(const RenderWindow&) = delete;
|
||||
RenderWindow& operator=(RenderWindow&&) = delete; ///TODO
|
||||
|
||||
private:
|
||||
bool OnWindowCreated() override;
|
||||
void OnWindowDestroy() override;
|
||||
void OnWindowResized() override;
|
||||
|
||||
bool SetupDepthBuffer();
|
||||
bool SetupRenderPass();
|
||||
bool SetupSwapchain();
|
||||
|
||||
Clock m_clock;
|
||||
VkColorSpaceKHR m_colorSpace;
|
||||
VkFormat m_colorFormat;
|
||||
VkFormat m_depthStencilFormat;
|
||||
VkPhysicalDevice m_forcedPhysicalDevice;
|
||||
std::vector<PixelFormatType> m_wantedDepthStencilFormats;
|
||||
std::vector<Vk::Framebuffer> m_frameBuffers;
|
||||
Vk::DeviceHandle m_device;
|
||||
Vk::DeviceMemory m_depthBufferMemory;
|
||||
Vk::Image m_depthBuffer;
|
||||
Vk::ImageView m_depthBufferView;
|
||||
Vk::Queue m_presentQueue;
|
||||
Vk::Surface m_surface;
|
||||
Vk::Swapchain m_swapchain;
|
||||
UInt32 m_presentableFamilyQueue;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RENDERWINDOW_HPP
|
||||
46
include/Nazara/VulkanRenderer/VkBuffer.hpp
Normal file
46
include/Nazara/VulkanRenderer/VkBuffer.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKBUFFER_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Buffer : public DeviceObject<Buffer, VkBuffer, VkBufferCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
Buffer() = default;
|
||||
Buffer(const Buffer&) = delete;
|
||||
Buffer(Buffer&&) = default;
|
||||
~Buffer() = default;
|
||||
|
||||
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);
|
||||
|
||||
VkMemoryRequirements GetMemoryRequirements() const;
|
||||
|
||||
Buffer& operator=(const Buffer&) = delete;
|
||||
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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkBuffer.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKBUFFER_HPP
|
||||
62
include/Nazara/VulkanRenderer/VkBuffer.inl
Normal file
62
include/Nazara/VulkanRenderer/VkBuffer.inl
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Buffer::BindBufferMemory(VkDeviceMemory memory, VkDeviceSize offset)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkBindBufferMemory(*m_device, m_handle, memory, offset);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to bind buffer memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Buffer::Create(const DeviceHandle& device, VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkBufferCreateInfo createInfo = {
|
||||
VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
flags, // VkBufferCreateFlags flags;
|
||||
size, // VkDeviceSize size;
|
||||
usage, // VkBufferUsageFlags usage;
|
||||
VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
|
||||
0, // uint32_t queueFamilyIndexCount;
|
||||
nullptr // const uint32_t* pQueueFamilyIndices;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkMemoryRequirements Buffer::GetMemoryRequirements() const
|
||||
{
|
||||
NazaraAssert(IsValid(), "Invalid buffer");
|
||||
|
||||
VkMemoryRequirements memoryRequirements;
|
||||
m_device->vkGetBufferMemoryRequirements(*m_device, m_handle, &memoryRequirements);
|
||||
|
||||
return memoryRequirements;
|
||||
}
|
||||
|
||||
inline VkResult Buffer::CreateHelper(const DeviceHandle& device, const VkBufferCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkBuffer* handle)
|
||||
{
|
||||
return device->vkCreateBuffer(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Buffer::DestroyHelper(const DeviceHandle& device, VkBuffer handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyBuffer(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
100
include/Nazara/VulkanRenderer/VkCommandBuffer.hpp
Normal file
100
include/Nazara/VulkanRenderer/VkCommandBuffer.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKCOMMANDBUFFER_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKCOMMANDBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class CommandBuffer
|
||||
{
|
||||
friend CommandPool;
|
||||
|
||||
public:
|
||||
inline CommandBuffer();
|
||||
CommandBuffer(const CommandBuffer&) = delete;
|
||||
inline CommandBuffer(CommandBuffer&& commandBuffer);
|
||||
inline ~CommandBuffer();
|
||||
|
||||
inline bool Begin(const VkCommandBufferBeginInfo& info);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo& inheritanceInfo);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags, VkRenderPass renderPass, UInt32 subpass, VkFramebuffer framebuffer, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics);
|
||||
|
||||
inline void BeginRenderPass(const VkRenderPassBeginInfo& beginInfo, VkSubpassContents contents = VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
inline void BindDescriptorSet(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, const VkDescriptorSet& descriptorSets);
|
||||
inline void BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets);
|
||||
inline void BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets, UInt32 dynamicOffsetCount, const UInt32* dynamicOffsets);
|
||||
inline void BindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType);
|
||||
inline void BindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline);
|
||||
inline void BindVertexBuffer(UInt32 binding, const VkBuffer buffer, const VkDeviceSize offset);
|
||||
inline void BindVertexBuffers(UInt32 firstBinding, UInt32 bindingCount, const VkBuffer* buffer, const VkDeviceSize* offset);
|
||||
|
||||
inline void ClearAttachment(const VkClearAttachment& attachment, const VkClearRect& rect);
|
||||
inline void ClearAttachments(UInt32 attachmentCount, const VkClearAttachment* attachments, UInt32 rectCount, const VkClearRect* rects);
|
||||
|
||||
inline void ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, const VkImageSubresourceRange& range);
|
||||
inline void ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, UInt32 rangeCount, const VkImageSubresourceRange* ranges);
|
||||
|
||||
inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, const VkImageSubresourceRange& range);
|
||||
inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, UInt32 rangeCount, const VkImageSubresourceRange* ranges);
|
||||
|
||||
inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
|
||||
inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0);
|
||||
|
||||
inline bool End();
|
||||
|
||||
inline void EndRenderPass();
|
||||
|
||||
inline void Free();
|
||||
|
||||
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier);
|
||||
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkMemoryBarrier& memoryBarrier, const VkBufferMemoryBarrier& bufferMemoryBarrier, const VkImageMemoryBarrier& imageMemoryBarrier);
|
||||
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, UInt32 memoryBarrierCount, const VkMemoryBarrier* memoryBarriers, UInt32 bufferMemoryBarrierCount, const VkBufferMemoryBarrier* bufferMemoryBarriers, UInt32 imageMemoryBarrierCount, const VkImageMemoryBarrier* imageMemoryBarriers);
|
||||
|
||||
inline void SetScissor(const Recti& scissorRegion);
|
||||
inline void SetScissor(const VkRect2D& scissorRegion);
|
||||
inline void SetScissor(UInt32 firstScissor, UInt32 scissorCount, const VkRect2D* scissors);
|
||||
inline void SetViewport(const Rectf& viewport, float minDepth, float maxDepth);
|
||||
inline void SetViewport(const VkViewport& viewport);
|
||||
inline void SetViewport(UInt32 firstViewport, UInt32 viewportCount, const VkViewport* viewports);
|
||||
|
||||
inline void SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout);
|
||||
inline void SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange);
|
||||
inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout);
|
||||
inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange);
|
||||
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
CommandBuffer& operator=(const CommandBuffer&) = delete;
|
||||
CommandBuffer& operator=(CommandBuffer&& commandBuffer);
|
||||
|
||||
inline operator VkCommandBuffer() const;
|
||||
|
||||
private:
|
||||
inline CommandBuffer(CommandPool& pool, VkCommandBuffer handle);
|
||||
|
||||
CommandPoolHandle m_pool;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkCommandBuffer m_handle;
|
||||
VkResult m_lastErrorCode;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkCommandBuffer.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKCOMMANDBUFFER_HPP
|
||||
419
include/Nazara/VulkanRenderer/VkCommandBuffer.inl
Normal file
419
include/Nazara/VulkanRenderer/VkCommandBuffer.inl
Normal file
@@ -0,0 +1,419 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkCommandBuffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline CommandBuffer::CommandBuffer() :
|
||||
m_pool(),
|
||||
m_handle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline CommandBuffer::CommandBuffer(CommandPool& pool, VkCommandBuffer handle) :
|
||||
m_pool(&pool),
|
||||
m_handle(handle)
|
||||
{
|
||||
}
|
||||
|
||||
inline CommandBuffer::CommandBuffer(CommandBuffer&& commandBuffer) :
|
||||
m_pool(std::move(commandBuffer.m_pool)),
|
||||
m_allocator(commandBuffer.m_allocator),
|
||||
m_handle(commandBuffer.m_handle),
|
||||
m_lastErrorCode(commandBuffer.m_lastErrorCode)
|
||||
{
|
||||
commandBuffer.m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
inline CommandBuffer::~CommandBuffer()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(const VkCommandBufferBeginInfo& info)
|
||||
{
|
||||
m_lastErrorCode = m_pool->GetDevice()->vkBeginCommandBuffer(m_handle, &info);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to begin command buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags)
|
||||
{
|
||||
VkCommandBufferBeginInfo beginInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
nullptr
|
||||
};
|
||||
|
||||
return Begin(beginInfo);
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo& inheritanceInfo)
|
||||
{
|
||||
VkCommandBufferBeginInfo beginInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
&inheritanceInfo
|
||||
};
|
||||
|
||||
return Begin(beginInfo);
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags, VkRenderPass renderPass, UInt32 subpass, VkFramebuffer framebuffer, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics)
|
||||
{
|
||||
NazaraAssert(flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, "Continue bit is required to ignore renderPass, subpass and framebuffer");
|
||||
|
||||
VkCommandBufferInheritanceInfo inheritanceInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
|
||||
nullptr,
|
||||
renderPass,
|
||||
subpass,
|
||||
framebuffer,
|
||||
VkBool32((occlusionQueryEnable) ? VK_TRUE : VK_FALSE),
|
||||
queryFlags,
|
||||
pipelineStatistics
|
||||
};
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
&inheritanceInfo
|
||||
};
|
||||
|
||||
return Begin(beginInfo);
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::Begin(VkCommandBufferUsageFlags flags, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics)
|
||||
{
|
||||
NazaraAssert(flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, "Continue bit is required to ignore renderPass, subpass and framebuffer");
|
||||
|
||||
VkCommandBufferInheritanceInfo inheritanceInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
|
||||
nullptr,
|
||||
VK_NULL_HANDLE,
|
||||
0,
|
||||
VK_NULL_HANDLE,
|
||||
VkBool32((occlusionQueryEnable) ? VK_TRUE : VK_FALSE),
|
||||
queryFlags,
|
||||
pipelineStatistics
|
||||
};
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
&inheritanceInfo
|
||||
};
|
||||
|
||||
return Begin(beginInfo);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BeginRenderPass(const VkRenderPassBeginInfo& beginInfo, VkSubpassContents contents)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBeginRenderPass(m_handle, &beginInfo, contents);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindDescriptorSet(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, const VkDescriptorSet& descriptorSets)
|
||||
{
|
||||
return BindDescriptorSets(pipelineBindPoint, layout, firstSet, 1U, &descriptorSets);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets)
|
||||
{
|
||||
return BindDescriptorSets(pipelineBindPoint, layout, firstSet, descriptorSetCount, descriptorSets, 0U, nullptr);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, const VkDescriptorSet* descriptorSets, UInt32 dynamicOffsetCount, const UInt32* dynamicOffsets)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindDescriptorSets(m_handle, pipelineBindPoint, layout, firstSet, descriptorSetCount, descriptorSets, dynamicOffsetCount, dynamicOffsets);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindIndexBuffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindIndexBuffer(m_handle, buffer, offset, indexType);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindPipeline(m_handle, pipelineBindPoint, pipeline);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindVertexBuffer(UInt32 binding, const VkBuffer buffer, const VkDeviceSize offset)
|
||||
{
|
||||
return BindVertexBuffers(binding, 1, &buffer, &offset);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::BindVertexBuffers(UInt32 firstBinding, UInt32 bindingCount, const VkBuffer* buffer, const VkDeviceSize* offset)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdBindVertexBuffers(m_handle, firstBinding, bindingCount, buffer, offset);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearAttachment(const VkClearAttachment& attachment, const VkClearRect& rect)
|
||||
{
|
||||
return ClearAttachments(1U, &attachment, 1U, &rect);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearAttachments(UInt32 attachmentCount, const VkClearAttachment* attachments, UInt32 rectCount, const VkClearRect* rects)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdClearAttachments(m_handle, attachmentCount, attachments, rectCount, rects);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, const VkImageSubresourceRange& range)
|
||||
{
|
||||
return ClearColorImage(image, imageLayout, color, 1U, &range);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearColorImage(VkImage image, VkImageLayout imageLayout, const VkClearColorValue& color, UInt32 rangeCount, const VkImageSubresourceRange* ranges)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdClearColorImage(m_handle, image, imageLayout, &color, rangeCount, ranges);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, const VkImageSubresourceRange& range)
|
||||
{
|
||||
return ClearDepthStencilImage(image, imageLayout, depthStencil, 1U, &range);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, UInt32 rangeCount, const VkImageSubresourceRange * ranges)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdClearDepthStencilImage(m_handle, image, imageLayout, &depthStencil, rangeCount, ranges);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::Draw(UInt32 vertexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdDraw(m_handle, vertexCount, instanceCount, firstVertex, firstInstance);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::DrawIndexed(UInt32 indexCount, UInt32 instanceCount, UInt32 firstVertex, Int32 vertexOffset, UInt32 firstInstance)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdDrawIndexed(m_handle, indexCount, instanceCount, firstVertex, vertexOffset, firstInstance);
|
||||
}
|
||||
|
||||
inline bool CommandBuffer::End()
|
||||
{
|
||||
m_lastErrorCode = m_pool->GetDevice()->vkEndCommandBuffer(m_handle);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to end command buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void CommandBuffer::EndRenderPass()
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdEndRenderPass(m_handle);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::Free()
|
||||
{
|
||||
if (m_handle)
|
||||
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)
|
||||
{
|
||||
return PipelineBarrier(srcStageMask, dstStageMask, dependencyFlags, 0, nullptr, 0, nullptr, 1, &imageMemoryBarrier);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkMemoryBarrier& memoryBarrier, const VkBufferMemoryBarrier& bufferMemoryBarrier, const VkImageMemoryBarrier& imageMemoryBarrier)
|
||||
{
|
||||
return PipelineBarrier(srcStageMask, dstStageMask, dependencyFlags, 1, &memoryBarrier, 1, &bufferMemoryBarrier, 1, &imageMemoryBarrier);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, UInt32 memoryBarrierCount, const VkMemoryBarrier* memoryBarriers, UInt32 bufferMemoryBarrierCount, const VkBufferMemoryBarrier* bufferMemoryBarriers, UInt32 imageMemoryBarrierCount, const VkImageMemoryBarrier* imageMemoryBarriers)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdPipelineBarrier(m_handle, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, memoryBarriers, bufferMemoryBarrierCount, bufferMemoryBarriers, imageMemoryBarrierCount, imageMemoryBarriers);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetScissor(const Recti& scissorRegion)
|
||||
{
|
||||
VkRect2D rect = {
|
||||
{scissorRegion.x, scissorRegion.y}, // VkOffset2D offset
|
||||
{UInt32(scissorRegion.width), UInt32(scissorRegion.height)} // VkExtent2D extent
|
||||
};
|
||||
|
||||
SetScissor(rect);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetScissor(const VkRect2D& scissorRegion)
|
||||
{
|
||||
return SetScissor(0, 1, &scissorRegion);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetScissor(UInt32 firstScissor, UInt32 scissorCount, const VkRect2D* scissors)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdSetScissor(m_handle, firstScissor, scissorCount, scissors);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout)
|
||||
{
|
||||
return SetImageLayout(image, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, oldImageLayout, newImageLayout);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange)
|
||||
{
|
||||
return SetImageLayout(image, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, oldImageLayout, newImageLayout, subresourceRange);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout)
|
||||
{
|
||||
VkImageSubresourceRange imageRange = {
|
||||
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask
|
||||
0, // uint32_t baseMipLevel
|
||||
1, // uint32_t levelCount
|
||||
0, // uint32_t baseArrayLayer
|
||||
1 // uint32_t layerCount
|
||||
};
|
||||
|
||||
return SetImageLayout(image, srcStageMask, dstStageMask, oldImageLayout, newImageLayout, imageRange);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange)
|
||||
{
|
||||
VkAccessFlags srcAccessMask;
|
||||
switch (oldImageLayout)
|
||||
{
|
||||
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
|
||||
srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_PREINITIALIZED:
|
||||
srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_GENERAL:
|
||||
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
|
||||
case VK_IMAGE_LAYOUT_UNDEFINED:
|
||||
default:
|
||||
srcAccessMask = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
VkAccessFlags dstAccessMask;
|
||||
switch (newImageLayout)
|
||||
{
|
||||
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
|
||||
if (oldImageLayout != VK_IMAGE_LAYOUT_UNDEFINED)
|
||||
srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
|
||||
dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
|
||||
dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
|
||||
if (srcAccessMask == 0)
|
||||
srcAccessMask = VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
|
||||
dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
|
||||
dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
|
||||
srcAccessMask |= VK_ACCESS_TRANSFER_READ_BIT;
|
||||
dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_GENERAL:
|
||||
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
|
||||
case VK_IMAGE_LAYOUT_UNDEFINED:
|
||||
default:
|
||||
dstAccessMask = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
VkImageMemoryBarrier imageBarrier = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType
|
||||
nullptr, // const void* pNext
|
||||
srcAccessMask, // VkAccessFlags srcAccessMask
|
||||
dstAccessMask, // VkAccessFlags dstAccessMask
|
||||
oldImageLayout, // VkImageLayout oldLayout
|
||||
newImageLayout, // VkImageLayout newLayout
|
||||
VK_QUEUE_FAMILY_IGNORED, // uint32_t srcQueueFamilyIndex
|
||||
VK_QUEUE_FAMILY_IGNORED, // uint32_t dstQueueFamilyIndex
|
||||
image, // VkImage image
|
||||
subresourceRange // VkImageSubresourceRange subresourceRange
|
||||
};
|
||||
|
||||
return PipelineBarrier(srcStageMask, dstStageMask, 0, imageBarrier);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetViewport(const Rectf& viewport, float minDepth, float maxDepth)
|
||||
{
|
||||
VkViewport rect = {
|
||||
viewport.x, // float x;
|
||||
viewport.y, // float y;
|
||||
viewport.width, // float width;
|
||||
viewport.height, // float height;
|
||||
minDepth, // float minDepth;
|
||||
maxDepth // float maxDepth;
|
||||
};
|
||||
|
||||
SetViewport(rect);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetViewport(const VkViewport& viewport)
|
||||
{
|
||||
return SetViewport(0, 1, &viewport);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::SetViewport(UInt32 firstViewport, UInt32 viewportCount, const VkViewport* viewports)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdSetViewport(m_handle, firstViewport, viewportCount, viewports);
|
||||
}
|
||||
|
||||
inline VkResult CommandBuffer::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline CommandBuffer& CommandBuffer::operator=(CommandBuffer&& commandBuffer)
|
||||
{
|
||||
m_allocator = commandBuffer.m_allocator;
|
||||
m_handle = commandBuffer.m_handle;
|
||||
m_lastErrorCode = commandBuffer.m_lastErrorCode;
|
||||
m_pool = std::move(commandBuffer.m_pool);
|
||||
m_handle = commandBuffer.m_handle;
|
||||
|
||||
commandBuffer.m_handle = VK_NULL_HANDLE;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline CommandBuffer::operator VkCommandBuffer() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
53
include/Nazara/VulkanRenderer/VkCommandPool.hpp
Normal file
53
include/Nazara/VulkanRenderer/VkCommandPool.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKCOMMANDPOOL_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKCOMMANDPOOL_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class CommandBuffer;
|
||||
class CommandPool;
|
||||
|
||||
using CommandPoolHandle = ObjectHandle<CommandPool>;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API CommandPool : public DeviceObject<CommandPool, VkCommandPool, VkCommandPoolCreateInfo>, public HandledObject<CommandPool>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
CommandPool() = default;
|
||||
CommandPool(const CommandPool&) = delete;
|
||||
CommandPool(CommandPool&&) = default;
|
||||
~CommandPool() = default;
|
||||
|
||||
CommandBuffer AllocateCommandBuffer(VkCommandBufferLevel level);
|
||||
std::vector<CommandBuffer> 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 Reset(VkCommandPoolResetFlags flags);
|
||||
|
||||
CommandPool& operator=(const CommandPool&) = delete;
|
||||
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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKCOMMANDPOOL_HPP
|
||||
48
include/Nazara/VulkanRenderer/VkCommandPool.inl
Normal file
48
include/Nazara/VulkanRenderer/VkCommandPool.inl
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool CommandPool::Create(const DeviceHandle& device, UInt32 queueFamilyIndex, VkCommandPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkCommandPoolCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||
nullptr,
|
||||
flags,
|
||||
queueFamilyIndex
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool CommandPool::Reset(VkCommandPoolResetFlags flags)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkResetCommandPool(*m_device, m_handle, flags);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline VkResult CommandPool::CreateHelper(const DeviceHandle& device, const VkCommandPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkCommandPool* handle)
|
||||
{
|
||||
return device->vkCreateCommandPool(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void CommandPool::DestroyHelper(const DeviceHandle& device, VkCommandPool handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyCommandPool(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
52
include/Nazara/VulkanRenderer/VkDescriptorPool.hpp
Normal file
52
include/Nazara/VulkanRenderer/VkDescriptorPool.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDESCRIPTORPOOL_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDESCRIPTORPOOL_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class DescriptorPool;
|
||||
class DescriptorSet;
|
||||
|
||||
using DescriptorPoolHandle = ObjectHandle<DescriptorPool>;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API DescriptorPool : public DeviceObject<DescriptorPool, VkDescriptorPool, VkDescriptorPoolCreateInfo>, public HandledObject<DescriptorPool>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
DescriptorPool() = default;
|
||||
DescriptorPool(const DescriptorPool&) = delete;
|
||||
DescriptorPool(DescriptorPool&&) = default;
|
||||
~DescriptorPool() = default;
|
||||
|
||||
DescriptorSet AllocateDescriptorSet(const VkDescriptorSetLayout& setLayouts);
|
||||
std::vector<DescriptorSet> 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);
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorPool.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDESCRIPTORPOOL_HPP
|
||||
54
include/Nazara/VulkanRenderer/VkDescriptorPool.inl
Normal file
54
include/Nazara/VulkanRenderer/VkDescriptorPool.inl
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool DescriptorPool::Create(const DeviceHandle& device, UInt32 maxSets, const VkDescriptorPoolSize& poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorPoolCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
flags, // VkDescriptorPoolCreateFlags flags;
|
||||
maxSets, // uint32_t maxSets;
|
||||
1U, // uint32_t poolSizeCount;
|
||||
&poolSize // const VkDescriptorPoolSize* pPoolSizes;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool DescriptorPool::Create(const DeviceHandle& device, UInt32 maxSets, UInt32 poolSizeCount, const VkDescriptorPoolSize* poolSize, VkDescriptorPoolCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorPoolCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
flags, // VkDescriptorPoolCreateFlags flags;
|
||||
maxSets, // uint32_t maxSets;
|
||||
poolSizeCount, // uint32_t poolSizeCount;
|
||||
poolSize // const VkDescriptorPoolSize* pPoolSizes;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult DescriptorPool::CreateHelper(const DeviceHandle& device, const VkDescriptorPoolCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorPool* handle)
|
||||
{
|
||||
return device->vkCreateDescriptorPool(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void DescriptorPool::DestroyHelper(const DeviceHandle& device, VkDescriptorPool handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyDescriptorPool(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
59
include/Nazara/VulkanRenderer/VkDescriptorSet.hpp
Normal file
59
include/Nazara/VulkanRenderer/VkDescriptorSet.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDESCRIPTORSET_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDESCRIPTORSET_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorPool.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class DescriptorSet
|
||||
{
|
||||
friend DescriptorPool;
|
||||
|
||||
public:
|
||||
inline DescriptorSet();
|
||||
DescriptorSet(const DescriptorSet&) = delete;
|
||||
inline DescriptorSet(DescriptorSet&& descriptorSet);
|
||||
inline ~DescriptorSet();
|
||||
|
||||
inline void Free();
|
||||
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
inline void WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range);
|
||||
inline void WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo);
|
||||
inline void WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range);
|
||||
inline void WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorBufferInfo& bufferInfo);
|
||||
inline void WriteUniformDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo);
|
||||
inline void WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo);
|
||||
|
||||
DescriptorSet& operator=(const DescriptorSet&) = delete;
|
||||
DescriptorSet& operator=(DescriptorSet&& descriptorSet);
|
||||
|
||||
inline operator VkDescriptorSet() const;
|
||||
|
||||
private:
|
||||
inline DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle);
|
||||
|
||||
DescriptorPoolHandle m_pool;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkDescriptorSet m_handle;
|
||||
VkResult m_lastErrorCode;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorSet.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDESCRIPTORSET_HPP
|
||||
122
include/Nazara/VulkanRenderer/VkDescriptorSet.inl
Normal file
122
include/Nazara/VulkanRenderer/VkDescriptorSet.inl
Normal file
@@ -0,0 +1,122 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorSet.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline DescriptorSet::DescriptorSet() :
|
||||
m_pool(),
|
||||
m_handle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline DescriptorSet::DescriptorSet(DescriptorPool& pool, VkDescriptorSet handle) :
|
||||
m_pool(&pool),
|
||||
m_handle(handle)
|
||||
{
|
||||
}
|
||||
|
||||
inline DescriptorSet::DescriptorSet(DescriptorSet&& descriptorSet) :
|
||||
m_pool(std::move(descriptorSet.m_pool)),
|
||||
m_allocator(descriptorSet.m_allocator),
|
||||
m_handle(descriptorSet.m_handle),
|
||||
m_lastErrorCode(descriptorSet.m_lastErrorCode)
|
||||
{
|
||||
descriptorSet.m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
inline DescriptorSet::~DescriptorSet()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
inline void DescriptorSet::Free()
|
||||
{
|
||||
if (m_handle)
|
||||
m_pool->GetDevice()->vkFreeDescriptorSets(*m_pool->GetDevice(), *m_pool, 1, &m_handle);
|
||||
}
|
||||
|
||||
inline VkResult DescriptorSet::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range)
|
||||
{
|
||||
return WriteUniformDescriptor(binding, 0U, buffer, offset, range);
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, const VkDescriptorBufferInfo& bufferInfo)
|
||||
{
|
||||
return WriteUniformDescriptors(binding, 0U, 1U, &bufferInfo);
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range)
|
||||
{
|
||||
VkDescriptorBufferInfo bufferInfo =
|
||||
{
|
||||
buffer, // VkBuffer buffer;
|
||||
offset, // VkDeviceSize offset;
|
||||
range // VkDeviceSize range;
|
||||
};
|
||||
|
||||
return WriteUniformDescriptor(binding, arrayElement, bufferInfo);
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptor(UInt32 binding, UInt32 arrayElement, const VkDescriptorBufferInfo& bufferInfo)
|
||||
{
|
||||
return WriteUniformDescriptors(binding, arrayElement, 1U, &bufferInfo);
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo)
|
||||
{
|
||||
return WriteUniformDescriptors(binding, 0U, descriptorCount, bufferInfo);
|
||||
}
|
||||
|
||||
inline void DescriptorSet::WriteUniformDescriptors(UInt32 binding, UInt32 arrayElement, UInt32 descriptorCount, const VkDescriptorBufferInfo* bufferInfo)
|
||||
{
|
||||
VkWriteDescriptorSet writeDescriptorSet =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
m_handle, // VkDescriptorSet dstSet;
|
||||
binding, // uint32_t dstBinding;
|
||||
arrayElement, // uint32_t dstArrayElement;
|
||||
descriptorCount, // uint32_t descriptorCount;
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType descriptorType;
|
||||
nullptr, // const VkDescriptorImageInfo* pImageInfo;
|
||||
bufferInfo, // const VkDescriptorBufferInfo* pBufferInfo;
|
||||
nullptr // const VkBufferView* pTexelBufferView;
|
||||
};
|
||||
|
||||
return m_pool->GetDevice()->vkUpdateDescriptorSets(*m_pool->GetDevice(), 1U, &writeDescriptorSet, 0U, nullptr);
|
||||
}
|
||||
|
||||
inline DescriptorSet& DescriptorSet::operator=(DescriptorSet&& descriptorSet)
|
||||
{
|
||||
m_allocator = descriptorSet.m_allocator;
|
||||
m_handle = descriptorSet.m_handle;
|
||||
m_lastErrorCode = descriptorSet.m_lastErrorCode;
|
||||
m_pool = std::move(descriptorSet.m_pool);
|
||||
m_handle = descriptorSet.m_handle;
|
||||
|
||||
descriptorSet.m_handle = VK_NULL_HANDLE;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline DescriptorSet::operator VkDescriptorSet() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
43
include/Nazara/VulkanRenderer/VkDescriptorSetLayout.hpp
Normal file
43
include/Nazara/VulkanRenderer/VkDescriptorSetLayout.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDESCRIPTORSETLAYOUT_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDESCRIPTORSETLAYOUT_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class DescriptorSetLayout : public DeviceObject<DescriptorSetLayout, VkDescriptorSetLayout, VkDescriptorSetLayoutCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
DescriptorSetLayout() = default;
|
||||
DescriptorSetLayout(const DescriptorSetLayout&) = delete;
|
||||
DescriptorSetLayout(DescriptorSetLayout&&) = default;
|
||||
~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);
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorSetLayout.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDESCRIPTORSETLAYOUT_HPP
|
||||
43
include/Nazara/VulkanRenderer/VkDescriptorSetLayout.inl
Normal file
43
include/Nazara/VulkanRenderer/VkDescriptorSetLayout.inl
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDescriptorSetLayout.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool DescriptorSetLayout::Create(const DeviceHandle& device, const VkDescriptorSetLayoutBinding& binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return Create(device, 1U, &binding, flags, allocator);
|
||||
}
|
||||
|
||||
inline bool DescriptorSetLayout::Create(const DeviceHandle& device, UInt32 bindingCount, const VkDescriptorSetLayoutBinding* binding, VkDescriptorSetLayoutCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkDescriptorSetLayoutCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
flags, // VkDescriptorSetLayoutCreateFlags flags;
|
||||
bindingCount, // uint32_t bindingCount;
|
||||
binding // const VkDescriptorSetLayoutBinding* pBindings;
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult DescriptorSetLayout::CreateHelper(const DeviceHandle& device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkDescriptorSetLayout* handle)
|
||||
{
|
||||
return device->vkCreateDescriptorSetLayout(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void DescriptorSetLayout::DestroyHelper(const DeviceHandle& device, VkDescriptorSetLayout handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyDescriptorSetLayout(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
232
include/Nazara/VulkanRenderer/VkDevice.hpp
Normal file
232
include/Nazara/VulkanRenderer/VkDevice.hpp
Normal file
@@ -0,0 +1,232 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDEVICE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDEVICE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkLoader.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Device;
|
||||
class Queue;
|
||||
class Instance;
|
||||
|
||||
using DeviceHandle = ObjectHandle<Device>;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API Device : public HandledObject<Device>
|
||||
{
|
||||
public:
|
||||
struct QueueFamilyInfo;
|
||||
struct QueueInfo;
|
||||
using QueueList = std::vector<QueueInfo>;
|
||||
|
||||
inline Device(Instance& instance);
|
||||
Device(const Device&) = delete;
|
||||
Device(Device&&) = delete;
|
||||
inline ~Device();
|
||||
|
||||
bool Create(VkPhysicalDevice device, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
inline const std::vector<QueueFamilyInfo>& GetEnabledQueues() const;
|
||||
inline const QueueList& GetEnabledQueues(UInt32 familyQueue) const;
|
||||
|
||||
inline Queue GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex);
|
||||
inline Instance& GetInstance();
|
||||
inline const Instance& GetInstance() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
inline VkPhysicalDevice GetPhysicalDevice() const;
|
||||
|
||||
inline bool IsExtensionLoaded(const String& extensionName);
|
||||
inline bool IsLayerLoaded(const String& layerName);
|
||||
|
||||
inline bool WaitForIdle();
|
||||
|
||||
Device& operator=(const Device&) = delete;
|
||||
Device& operator=(Device&&) = delete;
|
||||
|
||||
inline operator VkDevice();
|
||||
|
||||
// Vulkan functions
|
||||
#define NAZARA_VULKANRENDERER_DEVICE_FUNCTION(func) PFN_##func func
|
||||
|
||||
// Vulkan core
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkAllocateCommandBuffers);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkAllocateDescriptorSets);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkAllocateMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkBeginCommandBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkBindBufferMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkBindImageMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBeginQuery);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBeginRenderPass);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBindDescriptorSets);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBindIndexBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBindPipeline);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBindVertexBuffers);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdBlitImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdClearAttachments);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdClearColorImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdClearDepthStencilImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdCopyBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdCopyBufferToImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdCopyImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdCopyImageToBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdCopyQueryPoolResults);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDispatch);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDispatchIndirect);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDraw);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDrawIndexed);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDrawIndexedIndirect);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdDrawIndirect);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdEndQuery);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdEndRenderPass);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdExecuteCommands);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdFillBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdNextSubpass);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdPipelineBarrier);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdPushConstants);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdResetEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdResetQueryPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdResolveImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetBlendConstants);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetDepthBias);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetDepthBounds);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetLineWidth);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetScissor);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetStencilCompareMask);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetStencilReference);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetStencilWriteMask);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdSetViewport);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdUpdateBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdWaitEvents);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCmdWriteTimestamp);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateBufferView);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateCommandPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateComputePipelines);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateDescriptorPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateDescriptorSetLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateFramebuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateGraphicsPipelines);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateImageView);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreatePipelineCache);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreatePipelineLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateRenderPass);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateSampler);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateSemaphore);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateShaderModule);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyBufferView);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyCommandPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyDescriptorPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyDescriptorSetLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyDevice);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyFramebuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyImageView);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyPipeline);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyPipelineCache);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyPipelineLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyRenderPass);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroySampler);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroySemaphore);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyShaderModule);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDeviceWaitIdle);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkEndCommandBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkFreeCommandBuffers);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkFreeDescriptorSets);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkFreeMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkFlushMappedMemoryRanges);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetBufferMemoryRequirements);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetDeviceMemoryCommitment);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetDeviceQueue);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetEventStatus);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetFenceStatus);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetImageMemoryRequirements);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetImageSparseMemoryRequirements);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetImageSubresourceLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetRenderAreaGranularity);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkInvalidateMappedMemoryRanges);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkMapMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkMergePipelineCaches);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkQueueSubmit);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkQueueWaitIdle);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkResetCommandBuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkResetCommandPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkResetDescriptorPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkResetFences);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkResetEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkSetEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkUnmapMemory);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkUpdateDescriptorSets);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkWaitForFences);
|
||||
|
||||
// VK_KHR_display_swapchain
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateSharedSwapchainsKHR);
|
||||
|
||||
// VK_KHR_surface
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroySurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfaceFormatsKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfacePresentModesKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetPhysicalDeviceSurfaceSupportKHR);
|
||||
|
||||
// VK_KHR_swapchain
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkAcquireNextImageKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateSwapchainKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroySwapchainKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkGetSwapchainImagesKHR);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkQueuePresentKHR);
|
||||
|
||||
#undef NAZARA_VULKANRENDERER_DEVICE_FUNCTION
|
||||
|
||||
struct QueueInfo
|
||||
{
|
||||
QueueFamilyInfo* familyInfo;
|
||||
VkQueue queue;
|
||||
float priority;
|
||||
};
|
||||
|
||||
struct QueueFamilyInfo
|
||||
{
|
||||
QueueList queues;
|
||||
VkExtent3D minImageTransferGranularity;
|
||||
VkQueueFlags flags;
|
||||
UInt32 familyIndex;
|
||||
UInt32 timestampValidBits;
|
||||
};
|
||||
|
||||
private:
|
||||
inline PFN_vkVoidFunction GetProcAddr(const char* name);
|
||||
|
||||
Instance& m_instance;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkDevice m_device;
|
||||
VkPhysicalDevice m_physicalDevice;
|
||||
VkResult m_lastErrorCode;
|
||||
std::unordered_set<String> m_loadedExtensions;
|
||||
std::unordered_set<String> m_loadedLayers;
|
||||
std::vector<QueueFamilyInfo> m_enabledQueuesInfos;
|
||||
std::vector<const QueueList*> m_queuesByFamily;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDevice.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDEVICE_HPP
|
||||
117
include/Nazara/VulkanRenderer/VkDevice.inl
Normal file
117
include/Nazara/VulkanRenderer/VkDevice.inl
Normal file
@@ -0,0 +1,117 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkQueue.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Device::Device(Instance& instance) :
|
||||
m_instance(instance),
|
||||
m_device(VK_NULL_HANDLE),
|
||||
m_physicalDevice(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 = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
inline const std::vector<Device::QueueFamilyInfo>& Device::GetEnabledQueues() const
|
||||
{
|
||||
return m_enabledQueuesInfos;
|
||||
}
|
||||
|
||||
inline const Device::QueueList& Device::GetEnabledQueues(UInt32 familyQueue) const
|
||||
{
|
||||
NazaraAssert(familyQueue < m_enabledQueuesInfos.size(), "Invalid family queue");
|
||||
|
||||
return *m_queuesByFamily[familyQueue];
|
||||
}
|
||||
|
||||
inline Queue Device::GetQueue(UInt32 queueFamilyIndex, UInt32 queueIndex)
|
||||
{
|
||||
VkQueue queue;
|
||||
vkGetDeviceQueue(m_device, queueFamilyIndex, queueIndex, &queue);
|
||||
|
||||
return Queue(CreateHandle(), queue);
|
||||
}
|
||||
|
||||
inline Instance& Device::GetInstance()
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
inline const Instance& Device::GetInstance() const
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
inline VkResult Device::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline VkPhysicalDevice Device::GetPhysicalDevice() const
|
||||
{
|
||||
return m_physicalDevice;
|
||||
}
|
||||
|
||||
inline bool Device::IsExtensionLoaded(const String& extensionName)
|
||||
{
|
||||
return m_loadedExtensions.count(extensionName) > 0;
|
||||
}
|
||||
|
||||
inline bool Device::IsLayerLoaded(const String& layerName)
|
||||
{
|
||||
return m_loadedLayers.count(layerName) > 0;
|
||||
}
|
||||
|
||||
inline bool Device::WaitForIdle()
|
||||
{
|
||||
m_lastErrorCode = vkDeviceWaitIdle(m_device);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to wait for device idle");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Device::operator VkDevice()
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
inline PFN_vkVoidFunction Device::GetProcAddr(const char* name)
|
||||
{
|
||||
PFN_vkVoidFunction func = m_instance.GetDeviceProcAddr(m_device, name);
|
||||
if (!func)
|
||||
NazaraError("Failed to get " + String(name) + " address");
|
||||
|
||||
return func;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
51
include/Nazara/VulkanRenderer/VkDeviceMemory.hpp
Normal file
51
include/Nazara/VulkanRenderer/VkDeviceMemory.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDEVICEMEMORY_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDEVICEMEMORY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class DeviceMemory : public DeviceObject<DeviceMemory, VkDeviceMemory, VkMemoryAllocateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
DeviceMemory();
|
||||
DeviceMemory(const DeviceMemory&) = delete;
|
||||
DeviceMemory(DeviceMemory&& memory);
|
||||
~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 void* GetMappedPointer();
|
||||
|
||||
inline bool Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags = 0);
|
||||
|
||||
inline void Unmap();
|
||||
|
||||
DeviceMemory& operator=(const DeviceMemory&) = delete;
|
||||
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);
|
||||
|
||||
void* m_mappedPtr;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDeviceMemory.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDEVICEMEMORY_HPP
|
||||
96
include/Nazara/VulkanRenderer/VkDeviceMemory.inl
Normal file
96
include/Nazara/VulkanRenderer/VkDeviceMemory.inl
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDeviceMemory.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkPhysicalDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Vulkan.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline DeviceMemory::DeviceMemory() :
|
||||
m_mappedPtr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
DeviceMemory::DeviceMemory(DeviceMemory&& memory) :
|
||||
DeviceObject(std::move(memory))
|
||||
{
|
||||
m_mappedPtr = memory.m_mappedPtr;
|
||||
memory.m_mappedPtr = nullptr;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkMemoryAllocateInfo allocInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
size, // VkDeviceSize allocationSize;
|
||||
memoryType // uint32_t memoryTypeIndex;
|
||||
};
|
||||
|
||||
return Create(device, allocInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Create(const DeviceHandle& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
const Vk::PhysicalDevice& deviceInfo = Vulkan::GetPhysicalDeviceInfo(device->GetPhysicalDevice());
|
||||
|
||||
UInt32 typeMask = 1;
|
||||
for (UInt32 i = 0; i < VK_MAX_MEMORY_TYPES; ++i)
|
||||
{
|
||||
if (typeBits & typeMask)
|
||||
{
|
||||
if ((deviceInfo.memoryProperties.memoryTypes[i].propertyFlags & properties) == properties)
|
||||
return Create(device, size, i, allocator);
|
||||
}
|
||||
|
||||
typeMask <<= 1;
|
||||
}
|
||||
|
||||
NazaraError("Failed to find a memory type suitable for typeBits: " + String::Number(typeBits) + " and properties: 0x" + String::Number(properties, 16));
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void* DeviceMemory::GetMappedPointer()
|
||||
{
|
||||
return m_mappedPtr;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkMapMemory(*m_device, m_handle, offset, size, flags, &m_mappedPtr);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to map device memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void DeviceMemory::Unmap()
|
||||
{
|
||||
NazaraAssert(m_mappedPtr != nullptr, "Memory is not mapped");
|
||||
|
||||
m_device->vkUnmapMemory(*m_device, m_handle);
|
||||
m_mappedPtr = nullptr;
|
||||
}
|
||||
|
||||
inline VkResult DeviceMemory::CreateHelper(const DeviceHandle& device, const VkMemoryAllocateInfo* allocInfo, const VkAllocationCallbacks* allocator, VkDeviceMemory* handle)
|
||||
{
|
||||
return device->vkAllocateMemory(*device, allocInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void DeviceMemory::DestroyHelper(const DeviceHandle& device, VkDeviceMemory handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkFreeMemory(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
51
include/Nazara/VulkanRenderer/VkDeviceObject.hpp
Normal file
51
include/Nazara/VulkanRenderer/VkDeviceObject.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKDEVICEOBJECT_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKDEVICEOBJECT_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
class DeviceObject
|
||||
{
|
||||
public:
|
||||
inline DeviceObject();
|
||||
DeviceObject(const DeviceObject&) = delete;
|
||||
DeviceObject(DeviceObject&&);
|
||||
inline ~DeviceObject();
|
||||
|
||||
inline bool Create(const DeviceHandle& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
inline bool IsValid() const;
|
||||
|
||||
inline const DeviceHandle& GetDevice() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
DeviceObject& operator=(const DeviceObject&) = delete;
|
||||
DeviceObject& operator=(DeviceObject&&) = delete;
|
||||
|
||||
inline operator VkType() const;
|
||||
|
||||
protected:
|
||||
DeviceHandle m_device;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkType m_handle;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKDEVICEOBJECT_HPP
|
||||
93
include/Nazara/VulkanRenderer/VkDeviceObject.inl
Normal file
93
include/Nazara/VulkanRenderer/VkDeviceObject.inl
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkCommandPool.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline DeviceObject<C, VkType, CreateInfo>::DeviceObject() :
|
||||
m_handle(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline DeviceObject<C, VkType, CreateInfo>::DeviceObject(DeviceObject&& 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;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline DeviceObject<C, VkType, CreateInfo>::~DeviceObject()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline bool DeviceObject<C, VkType, CreateInfo>::Create(const DeviceHandle& device, const CreateInfo& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
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");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the allocator to access them when needed
|
||||
if (allocator)
|
||||
m_allocator = *allocator;
|
||||
else
|
||||
m_allocator.pfnAllocation = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline void DeviceObject<C, VkType, CreateInfo>::Destroy()
|
||||
{
|
||||
if (IsValid())
|
||||
{
|
||||
C::DestroyHelper(m_device, m_handle, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
m_handle = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline bool DeviceObject<C, VkType, CreateInfo>::IsValid() const
|
||||
{
|
||||
return m_handle != VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline const DeviceHandle& DeviceObject<C, VkType, CreateInfo>::GetDevice() const
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline VkResult DeviceObject<C, VkType, CreateInfo>::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
template<typename C, typename VkType, typename CreateInfo>
|
||||
inline DeviceObject<C, VkType, CreateInfo>::operator VkType() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
#include "VkDeviceObject.hpp"
|
||||
39
include/Nazara/VulkanRenderer/VkFramebuffer.hpp
Normal file
39
include/Nazara/VulkanRenderer/VkFramebuffer.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKFRAMEBUFFER_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKFRAMEBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/VkFramebuffer.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKFRAMEBUFFER_HPP
|
||||
24
include/Nazara/VulkanRenderer/VkFramebuffer.inl
Normal file
24
include/Nazara/VulkanRenderer/VkFramebuffer.inl
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkFramebuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/DebugOff.hpp>
|
||||
43
include/Nazara/VulkanRenderer/VkImage.hpp
Normal file
43
include/Nazara/VulkanRenderer/VkImage.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKIMAGE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKIMAGE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Image : public DeviceObject<Image, VkImage, VkImageCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
Image() = default;
|
||||
Image(const Image&) = delete;
|
||||
Image(Image&&) = default;
|
||||
~Image() = default;
|
||||
|
||||
bool BindImageMemory(VkDeviceMemory memory, VkDeviceSize offset = 0);
|
||||
|
||||
VkMemoryRequirements GetMemoryRequirements() const;
|
||||
|
||||
Image& operator=(const Image&) = delete;
|
||||
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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkImage.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKIMAGE_HPP
|
||||
46
include/Nazara/VulkanRenderer/VkImage.inl
Normal file
46
include/Nazara/VulkanRenderer/VkImage.inl
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkImage.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Image::BindImageMemory(VkDeviceMemory memory, VkDeviceSize offset)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkBindImageMemory(*m_device, m_handle, memory, offset);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to bind buffer memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline VkMemoryRequirements Image::GetMemoryRequirements() const
|
||||
{
|
||||
NazaraAssert(IsValid(), "Invalid image");
|
||||
|
||||
VkMemoryRequirements memoryRequirements;
|
||||
m_device->vkGetImageMemoryRequirements(*m_device, m_handle, &memoryRequirements);
|
||||
|
||||
return memoryRequirements;
|
||||
}
|
||||
|
||||
inline VkResult Image::CreateHelper(const DeviceHandle& device, const VkImageCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkImage* handle)
|
||||
{
|
||||
return device->vkCreateImage(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Image::DestroyHelper(const DeviceHandle& device, VkImage handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyImage(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
39
include/Nazara/VulkanRenderer/VkImageView.hpp
Normal file
39
include/Nazara/VulkanRenderer/VkImageView.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKIMAGEVIEW_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKIMAGEVIEW_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/VkImageView.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKIMAGEVIEW_HPP
|
||||
24
include/Nazara/VulkanRenderer/VkImageView.inl
Normal file
24
include/Nazara/VulkanRenderer/VkImageView.inl
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkImageView.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/DebugOff.hpp>
|
||||
141
include/Nazara/VulkanRenderer/VkInstance.hpp
Normal file
141
include/Nazara/VulkanRenderer/VkInstance.hpp
Normal file
@@ -0,0 +1,141 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKINSTANCE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKINSTANCE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkLoader.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API Instance
|
||||
{
|
||||
public:
|
||||
inline Instance();
|
||||
Instance(const Instance&) = delete;
|
||||
Instance(Instance&&) = delete;
|
||||
inline ~Instance();
|
||||
|
||||
bool Create(const VkInstanceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool 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 = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
bool EnumeratePhysicalDevices(std::vector<VkPhysicalDevice>* physicalDevices);
|
||||
|
||||
inline PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* name);
|
||||
|
||||
inline VkPhysicalDeviceFeatures GetPhysicalDeviceFeatures(VkPhysicalDevice device);
|
||||
inline VkFormatProperties GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format);
|
||||
inline bool GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties);
|
||||
inline VkPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device);
|
||||
inline VkPhysicalDeviceProperties GetPhysicalDeviceProperties(VkPhysicalDevice device);
|
||||
bool GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector<VkQueueFamilyProperties>* queueFamilyProperties);
|
||||
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
inline bool IsExtensionLoaded(const String& extensionName);
|
||||
inline bool IsLayerLoaded(const String& layerName);
|
||||
|
||||
Instance& operator=(const Instance&) = delete;
|
||||
Instance& operator=(Instance&&) = delete;
|
||||
|
||||
inline operator VkInstance();
|
||||
|
||||
// Vulkan functions
|
||||
#define NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(func) PFN_##func func
|
||||
|
||||
// Vulkan core
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateDevice);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkDestroyInstance);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkEnumeratePhysicalDevices);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetDeviceProcAddr);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceFeatures);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceFormatProperties);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceImageFormatProperties);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceMemoryProperties);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceProperties);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceQueueFamilyProperties);
|
||||
|
||||
// VK_KHR_display
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateDisplayModeKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateDisplayPlaneSurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetDisplayModePropertiesKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetDisplayPlaneCapabilitiesKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetDisplayPlaneSupportedDisplaysKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPlanePropertiesKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceDisplayPropertiesKHR);
|
||||
|
||||
// VK_KHR_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkDestroySurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceFormatsKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfacePresentModesKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceSurfaceSupportKHR);
|
||||
|
||||
// VK_EXT_debug_report
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateDebugReportCallbackEXT);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkDestroyDebugReportCallbackEXT);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkDebugReportMessageEXT);
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
// VK_KHR_android_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateAndroidSurfaceKHR);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
// VK_KHR_mir_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateMirSurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceMirPresentationSupportKHR);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
// VK_KHR_xcb_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateXcbSurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceXcbPresentationSupportKHR);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
// VK_KHR_xlib_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateXlibSurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceXlibPresentationSupportKHR);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
// VK_KHR_wayland_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateWaylandSurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceWaylandPresentationSupportKHR);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
// VK_KHR_win32_surface
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateWin32SurfaceKHR);
|
||||
NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceWin32PresentationSupportKHR);
|
||||
#endif
|
||||
|
||||
#undef NAZARA_VULKANRENDERER_INSTANCE_FUNCTION
|
||||
|
||||
private:
|
||||
inline PFN_vkVoidFunction GetProcAddr(const char* name);
|
||||
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkInstance m_instance;
|
||||
VkResult m_lastErrorCode;
|
||||
std::unordered_set<String> m_loadedExtensions;
|
||||
std::unordered_set<String> m_loadedLayers;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkInstance.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKINSTANCE_HPP
|
||||
143
include/Nazara/VulkanRenderer/VkInstance.inl
Normal file
143
include/Nazara/VulkanRenderer/VkInstance.inl
Normal file
@@ -0,0 +1,143 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Instance::Instance() :
|
||||
m_instance(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
inline Instance::~Instance()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
VkApplicationInfo appInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
nullptr,
|
||||
appName.GetConstBuffer(),
|
||||
appVersion,
|
||||
engineName.GetConstBuffer(),
|
||||
engineVersion
|
||||
};
|
||||
|
||||
VkInstanceCreateInfo instanceInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||
nullptr,
|
||||
0,
|
||||
&appInfo,
|
||||
static_cast<UInt32>(layers.size()),
|
||||
(!layers.empty()) ? layers.data() : nullptr,
|
||||
static_cast<UInt32>(extensions.size()),
|
||||
(!extensions.empty()) ? extensions.data() : nullptr
|
||||
};
|
||||
|
||||
return Create(instanceInfo, allocator);
|
||||
}
|
||||
|
||||
inline void Instance::Destroy()
|
||||
{
|
||||
if (m_instance)
|
||||
{
|
||||
vkDestroyInstance(m_instance, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
m_instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
inline PFN_vkVoidFunction Instance::GetDeviceProcAddr(VkDevice device, const char* name)
|
||||
{
|
||||
PFN_vkVoidFunction func = vkGetDeviceProcAddr(device, name);
|
||||
if (!func)
|
||||
NazaraError("Failed to get " + String(name) + " address");
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
inline VkResult Instance::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline bool Instance::IsExtensionLoaded(const String& extensionName)
|
||||
{
|
||||
return m_loadedExtensions.count(extensionName) > 0;
|
||||
}
|
||||
|
||||
inline bool Instance::IsLayerLoaded(const String& layerName)
|
||||
{
|
||||
return m_loadedLayers.count(layerName) > 0;
|
||||
}
|
||||
|
||||
inline Instance::operator VkInstance()
|
||||
{
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
inline VkPhysicalDeviceFeatures Instance::GetPhysicalDeviceFeatures(VkPhysicalDevice device)
|
||||
{
|
||||
VkPhysicalDeviceFeatures features;
|
||||
vkGetPhysicalDeviceFeatures(device, &features);
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
inline VkFormatProperties Instance::GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format)
|
||||
{
|
||||
VkFormatProperties formatProperties;
|
||||
vkGetPhysicalDeviceFormatProperties(device, format, &formatProperties);
|
||||
|
||||
return formatProperties;
|
||||
}
|
||||
|
||||
inline bool Instance::GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties)
|
||||
{
|
||||
m_lastErrorCode = vkGetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, imageFormatProperties);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to get physical device image format properties");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline VkPhysicalDeviceMemoryProperties Instance::GetPhysicalDeviceMemoryProperties(VkPhysicalDevice device)
|
||||
{
|
||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||
vkGetPhysicalDeviceMemoryProperties(device, &memoryProperties);
|
||||
|
||||
return memoryProperties;
|
||||
}
|
||||
|
||||
inline VkPhysicalDeviceProperties Instance::GetPhysicalDeviceProperties(VkPhysicalDevice device)
|
||||
{
|
||||
VkPhysicalDeviceProperties properties;
|
||||
vkGetPhysicalDeviceProperties(device, &properties);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
inline PFN_vkVoidFunction Instance::GetProcAddr(const char* name)
|
||||
{
|
||||
PFN_vkVoidFunction func = Loader::GetInstanceProcAddr(m_instance, name);
|
||||
if (!func)
|
||||
NazaraError("Failed to get " + String(name) + " address");
|
||||
|
||||
return func;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
52
include/Nazara/VulkanRenderer/VkLoader.hpp
Normal file
52
include/Nazara/VulkanRenderer/VkLoader.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKLOADER_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKLOADER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/DynLib.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API Loader
|
||||
{
|
||||
public:
|
||||
Loader() = delete;
|
||||
~Loader() = delete;
|
||||
|
||||
static bool EnumerateInstanceExtensionProperties(std::vector<VkExtensionProperties>* properties, const char* layerName = nullptr);
|
||||
static bool EnumerateInstanceLayerProperties(std::vector<VkLayerProperties>* properties);
|
||||
|
||||
static inline PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
// Vulkan functions
|
||||
#define NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(func) static PFN_##func func
|
||||
|
||||
NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(vkCreateInstance);
|
||||
NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(vkEnumerateInstanceExtensionProperties);
|
||||
NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(vkEnumerateInstanceLayerProperties);
|
||||
NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(vkGetInstanceProcAddr);
|
||||
|
||||
#undef NAZARA_VULKANRENDERER_GLOBAL_FUNCTION
|
||||
|
||||
private:
|
||||
static DynLib s_vulkanLib;
|
||||
static VkResult s_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkLoader.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKLOADER_HPP
|
||||
19
include/Nazara/VulkanRenderer/VkLoader.inl
Normal file
19
include/Nazara/VulkanRenderer/VkLoader.inl
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkLoader.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline PFN_vkVoidFunction Loader::GetInstanceProcAddr(VkInstance instance, const char* name)
|
||||
{
|
||||
return vkGetInstanceProcAddr(instance, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
28
include/Nazara/VulkanRenderer/VkPhysicalDevice.hpp
Normal file
28
include/Nazara/VulkanRenderer/VkPhysicalDevice.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKPHYSICALDEVICE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKPHYSICALDEVICE_HPP
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
struct PhysicalDevice
|
||||
{
|
||||
VkPhysicalDevice device;
|
||||
VkPhysicalDeviceFeatures features;
|
||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||
VkPhysicalDeviceProperties properties;
|
||||
std::vector<VkQueueFamilyProperties> queues;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKPHYSICALDEVICE_HPP
|
||||
50
include/Nazara/VulkanRenderer/VkPipeline.hpp
Normal file
50
include/Nazara/VulkanRenderer/VkPipeline.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKPIPELINE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKPIPELINE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/VkPipeline.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKPIPELINE_HPP
|
||||
86
include/Nazara/VulkanRenderer/VkPipeline.inl
Normal file
86
include/Nazara/VulkanRenderer/VkPipeline.inl
Normal file
@@ -0,0 +1,86 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkPipeline.hpp>
|
||||
#include <Nazara/VulkanRenderer/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;
|
||||
m_lastErrorCode = result;
|
||||
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/VulkanRenderer/DebugOff.hpp>
|
||||
39
include/Nazara/VulkanRenderer/VkPipelineCache.hpp
Normal file
39
include/Nazara/VulkanRenderer/VkPipelineCache.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKPIPELINECACHE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKPIPELINECACHE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/VkPipelineCache.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKPIPELINECACHE_HPP
|
||||
24
include/Nazara/VulkanRenderer/VkPipelineCache.inl
Normal file
24
include/Nazara/VulkanRenderer/VkPipelineCache.inl
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkPipelineCache.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/DebugOff.hpp>
|
||||
39
include/Nazara/VulkanRenderer/VkPipelineLayout.hpp
Normal file
39
include/Nazara/VulkanRenderer/VkPipelineLayout.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKPIPELINELAYOUT_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKPIPELINELAYOUT_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/VkPipelineLayout.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKPIPELINELAYOUT_HPP
|
||||
24
include/Nazara/VulkanRenderer/VkPipelineLayout.inl
Normal file
24
include/Nazara/VulkanRenderer/VkPipelineLayout.inl
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkPipelineLayout.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/DebugOff.hpp>
|
||||
53
include/Nazara/VulkanRenderer/VkQueue.hpp
Normal file
53
include/Nazara/VulkanRenderer/VkQueue.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKQUEUE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKQUEUE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Queue
|
||||
{
|
||||
public:
|
||||
inline Queue();
|
||||
inline Queue(const DeviceHandle& device, VkQueue queue);
|
||||
inline Queue(const Queue& queue);
|
||||
inline Queue(Queue&& queue);
|
||||
inline ~Queue() = default;
|
||||
|
||||
inline const DeviceHandle& GetDevice() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
inline bool Present(const VkPresentInfoKHR& presentInfo) const;
|
||||
inline bool Present(VkSwapchainKHR swapchain, UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE) const;
|
||||
|
||||
inline bool Submit(const VkSubmitInfo& submit, VkFence fence = VK_NULL_HANDLE) const;
|
||||
inline bool Submit(UInt32 submitCount, const VkSubmitInfo* submits, VkFence fence = VK_NULL_HANDLE) const;
|
||||
|
||||
inline bool WaitIdle() const;
|
||||
|
||||
Queue& operator=(const Queue& queue) = delete;
|
||||
inline Queue& operator=(Queue&&);
|
||||
|
||||
inline operator VkQueue();
|
||||
|
||||
protected:
|
||||
DeviceHandle m_device;
|
||||
VkQueue m_handle;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkQueue.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKQUEUE_HPP
|
||||
115
include/Nazara/VulkanRenderer/VkQueue.inl
Normal file
115
include/Nazara/VulkanRenderer/VkQueue.inl
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkQueue.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Queue::Queue() :
|
||||
Queue(DeviceHandle(), VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline Queue::Queue(const DeviceHandle& 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 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;
|
||||
}
|
||||
|
||||
inline VkResult Queue::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline bool Queue::Present(const VkPresentInfoKHR& presentInfo) const
|
||||
{
|
||||
m_lastErrorCode = m_device->vkQueuePresentKHR(m_handle, &presentInfo);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Queue::Present(VkSwapchainKHR swapchain, UInt32 imageIndex, VkSemaphore waitSemaphore) const
|
||||
{
|
||||
VkPresentInfoKHR presentInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
|
||||
nullptr,
|
||||
(waitSemaphore) ? 1U : 0U,
|
||||
&waitSemaphore,
|
||||
1U,
|
||||
&swapchain,
|
||||
&imageIndex,
|
||||
nullptr
|
||||
};
|
||||
|
||||
return Present(presentInfo);
|
||||
}
|
||||
|
||||
inline bool Queue::Submit(const VkSubmitInfo& submit, VkFence fence) const
|
||||
{
|
||||
return Submit(1, &submit, fence);
|
||||
}
|
||||
|
||||
inline bool Queue::Submit(UInt32 submitCount, const VkSubmitInfo* submits, VkFence fence) const
|
||||
{
|
||||
m_lastErrorCode = m_device->vkQueueSubmit(m_handle, submitCount, submits, fence);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Queue::WaitIdle() const
|
||||
{
|
||||
m_lastErrorCode = m_device->vkQueueWaitIdle(m_handle);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Queue& Queue::operator=(Queue&& queue)
|
||||
{
|
||||
m_device = std::move(queue.m_device);
|
||||
m_handle = queue.m_handle;
|
||||
m_lastErrorCode = queue.m_lastErrorCode;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Queue::operator VkQueue()
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
39
include/Nazara/VulkanRenderer/VkRenderPass.hpp
Normal file
39
include/Nazara/VulkanRenderer/VkRenderPass.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKRENDERPASS_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKRENDERPASS_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/VkRenderPass.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKRENDERPASS_HPP
|
||||
24
include/Nazara/VulkanRenderer/VkRenderPass.inl
Normal file
24
include/Nazara/VulkanRenderer/VkRenderPass.inl
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkRenderPass.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/DebugOff.hpp>
|
||||
42
include/Nazara/VulkanRenderer/VkSemaphore.hpp
Normal file
42
include/Nazara/VulkanRenderer/VkSemaphore.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKSEMAPHORE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKSEMAPHORE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Semaphore : public DeviceObject<Semaphore, VkSemaphore, VkSemaphoreCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
Semaphore() = default;
|
||||
Semaphore(const Semaphore&) = delete;
|
||||
Semaphore(Semaphore&&) = default;
|
||||
~Semaphore() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(const DeviceHandle& 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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSemaphore.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKSEMAPHORE_HPP
|
||||
36
include/Nazara/VulkanRenderer/VkSemaphore.inl
Normal file
36
include/Nazara/VulkanRenderer/VkSemaphore.inl
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSemaphore.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Semaphore::Create(const DeviceHandle& device, VkSemaphoreCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkSemaphoreCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
||||
nullptr,
|
||||
flags
|
||||
};
|
||||
|
||||
return Create(device, createInfo, allocator);
|
||||
}
|
||||
|
||||
inline VkResult Semaphore::CreateHelper(const DeviceHandle& device, const VkSemaphoreCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkSemaphore* handle)
|
||||
{
|
||||
return device->vkCreateSemaphore(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Semaphore::DestroyHelper(const DeviceHandle& device, VkSemaphore handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroySemaphore(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
42
include/Nazara/VulkanRenderer/VkShaderModule.hpp
Normal file
42
include/Nazara/VulkanRenderer/VkShaderModule.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKSHADERMODULE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKSHADERMODULE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/VkShaderModule.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKSHADERMODULE_HPP
|
||||
38
include/Nazara/VulkanRenderer/VkShaderModule.inl
Normal file
38
include/Nazara/VulkanRenderer/VkShaderModule.inl
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkShaderModule.hpp>
|
||||
#include <Nazara/VulkanRenderer/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/VulkanRenderer/DebugOff.hpp>
|
||||
94
include/Nazara/VulkanRenderer/VkSurface.hpp
Normal file
94
include/Nazara/VulkanRenderer/VkSurface.hpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKSURFACE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKSURFACE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkLoader.hpp>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Instance;
|
||||
|
||||
class Surface
|
||||
{
|
||||
public:
|
||||
inline Surface(Instance& instance);
|
||||
Surface(const Surface&) = delete;
|
||||
Surface(Surface&& surface);
|
||||
inline ~Surface();
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
// VK_KHR_android_surface
|
||||
inline bool Create(const VkAndroidSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
// VK_KHR_mir_surface
|
||||
inline bool Create(const VkMirSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(MirConnection* connection, MirSurface* surface, VkMirSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
// VK_KHR_xcb_surface
|
||||
inline bool Create(const VkXcbSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
// VK_KHR_xlib_surface
|
||||
inline bool Create(const VkXlibSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
// VK_KHR_wayland_surface
|
||||
inline bool Create(const VkWaylandSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
// VK_KHR_win32_surface
|
||||
inline bool Create(const VkWin32SurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
#endif
|
||||
|
||||
inline void Destroy();
|
||||
|
||||
bool GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities) const;
|
||||
bool GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats) const;
|
||||
bool GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes) const;
|
||||
bool GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported) const;
|
||||
|
||||
inline bool IsSupported() const;
|
||||
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
|
||||
Surface& operator=(const Surface&) = delete;
|
||||
Surface& operator=(Surface&&) = delete;
|
||||
|
||||
inline operator VkSurfaceKHR() const;
|
||||
|
||||
private:
|
||||
inline bool Create(const VkAllocationCallbacks* allocator);
|
||||
|
||||
Instance& m_instance;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkSurfaceKHR m_surface;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSurface.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKSURFACE_HPP
|
||||
314
include/Nazara/VulkanRenderer/VkSurface.inl
Normal file
314
include/Nazara/VulkanRenderer/VkSurface.inl
Normal file
@@ -0,0 +1,314 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSurface.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline Surface::Surface(Instance& instance) :
|
||||
m_instance(instance),
|
||||
m_surface(VK_NULL_HANDLE)
|
||||
{
|
||||
}
|
||||
|
||||
inline Surface::Surface(Surface&& surface) :
|
||||
m_instance(surface.m_instance),
|
||||
m_allocator(surface.m_allocator),
|
||||
m_surface(surface.m_surface),
|
||||
m_lastErrorCode(surface.m_lastErrorCode)
|
||||
{
|
||||
surface.m_surface = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
inline Surface::~Surface()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
inline bool Surface::Create(const VkAndroidSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateAndroidSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(ANativeWindow* window, VkAndroidSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkAndroidSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
window
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
inline bool Surface::Create(const VkMirSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateMirSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(MirConnection* connection, MirSurface* surface, VkMirSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkMirSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
connection,
|
||||
surface
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
inline bool Surface::Create(const VkXcbSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateXcbSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(xcb_connection_t* connection, xcb_window_t window, VkXcbSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkXcbSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
connection,
|
||||
window
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
inline bool Surface::Create(const VkXlibSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateXlibSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(Display* display, Window window, VkXlibSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkXlibSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
display,
|
||||
window
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
inline bool Surface::Create(const VkWaylandSurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateWaylandSurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(wl_display* display, wl_surface* surface, VkWaylandSurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkWaylandSurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
display,
|
||||
surface
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
inline bool Surface::Create(const VkWin32SurfaceCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkCreateWin32SurfaceKHR(m_instance, &createInfo, allocator, &m_surface);
|
||||
return Create(allocator);
|
||||
}
|
||||
|
||||
inline bool Surface::Create(HINSTANCE instance, HWND handle, VkWin32SurfaceCreateFlagsKHR flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkWin32SurfaceCreateInfoKHR createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
|
||||
nullptr,
|
||||
flags,
|
||||
instance,
|
||||
handle
|
||||
};
|
||||
|
||||
return Create(createInfo, allocator);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void Surface::Destroy()
|
||||
{
|
||||
if (m_surface != VK_NULL_HANDLE)
|
||||
{
|
||||
m_instance.vkDestroySurfaceKHR(m_instance, m_surface, (m_allocator.pfnAllocation) ? &m_allocator : nullptr);
|
||||
m_surface = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
inline VkResult Surface::GetLastErrorCode() const
|
||||
{
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline bool Surface::GetCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceCapabilitiesKHR* surfaceCapabilities) const
|
||||
{
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, m_surface, surfaceCapabilities);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query surface capabilities");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Surface::GetFormats(VkPhysicalDevice physicalDevice, std::vector<VkSurfaceFormatKHR>* surfaceFormats) const
|
||||
{
|
||||
// First, query format count
|
||||
UInt32 surfaceCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, nullptr);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS || surfaceCount == 0)
|
||||
{
|
||||
NazaraError("Failed to query format count");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now we can get the list of the available physical device
|
||||
surfaceFormats->resize(surfaceCount);
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &surfaceCount, surfaceFormats->data());
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query formats");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Surface::GetPresentModes(VkPhysicalDevice physicalDevice, std::vector<VkPresentModeKHR>* presentModes) const
|
||||
{
|
||||
// First, query present modes count
|
||||
UInt32 presentModeCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, nullptr);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS || presentModeCount == 0)
|
||||
{
|
||||
NazaraError("Failed to query present mode count");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now we can get the list of the available physical device
|
||||
presentModes->resize(presentModeCount);
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, m_surface, &presentModeCount, presentModes->data());
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query present modes");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Surface::GetSupportPresentation(VkPhysicalDevice physicalDevice, UInt32 queueFamilyIndex, bool* supported) const
|
||||
{
|
||||
VkBool32 presentationSupported = VK_FALSE;
|
||||
m_lastErrorCode = m_instance.vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, m_surface, &presentationSupported);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query surface capabilities");
|
||||
return false;
|
||||
}
|
||||
|
||||
*supported = (presentationSupported == VK_TRUE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Surface::IsSupported() const
|
||||
{
|
||||
if (!m_instance.IsExtensionLoaded("VK_KHR_surface"))
|
||||
return false;
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_android_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_mir_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_xcb_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_xlib_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_wayland_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
if (m_instance.IsExtensionLoaded("VK_KHR_win32_surface"))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline Surface::operator VkSurfaceKHR() const
|
||||
{
|
||||
return m_surface;
|
||||
}
|
||||
|
||||
inline bool Surface::Create(const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to create Vulkan surface");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the allocator to access them when needed
|
||||
if (allocator)
|
||||
m_allocator = *allocator;
|
||||
else
|
||||
m_allocator.pfnAllocation = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
60
include/Nazara/VulkanRenderer/VkSwapchain.hpp
Normal file
60
include/Nazara/VulkanRenderer/VkSwapchain.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKSWAPCHAIN_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKSWAPCHAIN_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDeviceObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkImageView.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Swapchain : public DeviceObject<Swapchain, VkSwapchainKHR, VkSwapchainCreateInfoKHR>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
struct Buffer;
|
||||
|
||||
Swapchain() = default;
|
||||
Swapchain(const Swapchain&) = delete;
|
||||
Swapchain(Swapchain&&) = default;
|
||||
~Swapchain() = default;
|
||||
|
||||
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 const Buffer& GetBuffer(UInt32 index) const;
|
||||
inline const std::vector<Buffer>& GetBuffers() const;
|
||||
inline UInt32 GetBufferCount() const;
|
||||
|
||||
inline bool IsSupported() const;
|
||||
|
||||
Swapchain& operator=(const Swapchain&) = delete;
|
||||
Swapchain& operator=(Swapchain&&) = delete;
|
||||
|
||||
struct Buffer
|
||||
{
|
||||
VkImage image;
|
||||
ImageView view;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
std::vector<Buffer> m_buffers;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSwapchain.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKSWAPCHAIN_HPP
|
||||
121
include/Nazara/VulkanRenderer/VkSwapchain.inl
Normal file
121
include/Nazara/VulkanRenderer/VkSwapchain.inl
Normal file
@@ -0,0 +1,121 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VkSwapchain.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Swapchain::AcquireNextImage(Nz::UInt64 timeout, VkSemaphore semaphore, VkFence fence, UInt32* imageIndex) const
|
||||
{
|
||||
m_lastErrorCode = m_device->vkAcquireNextImageKHR(*m_device, m_handle, timeout, semaphore, fence, imageIndex);
|
||||
switch (m_lastErrorCode)
|
||||
{
|
||||
case VkResult::VK_SUBOPTIMAL_KHR:
|
||||
case VkResult::VK_SUCCESS:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool Swapchain::Create(const DeviceHandle& device, const VkSwapchainCreateInfoKHR& createInfo, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
if (!DeviceObject::Create(device, createInfo, allocator))
|
||||
return false;
|
||||
|
||||
UInt32 imageCount = 0;
|
||||
m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, nullptr);
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS || imageCount == 0)
|
||||
{
|
||||
NazaraError("Failed to query swapchain image count");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<VkImage> images(imageCount);
|
||||
m_lastErrorCode = m_device->vkGetSwapchainImagesKHR(*m_device, m_handle, &imageCount, images.data());
|
||||
if (m_lastErrorCode != VkResult::VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to query swapchain images");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_buffers.resize(imageCount);
|
||||
for (UInt32 i = 0; i < imageCount; ++i)
|
||||
{
|
||||
m_buffers[i].image = images[i];
|
||||
|
||||
VkImageViewCreateInfo imageViewCreateInfo = {
|
||||
VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
|
||||
nullptr, // const void* pNext;
|
||||
0, // VkImageViewCreateFlags flags;
|
||||
m_buffers[i].image, // VkImage image;
|
||||
VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
|
||||
createInfo.imageFormat, // VkFormat format;
|
||||
{ // VkComponentMapping components;
|
||||
VK_COMPONENT_SWIZZLE_R, // VkComponentSwizzle .r;
|
||||
VK_COMPONENT_SWIZZLE_G, // VkComponentSwizzle .g;
|
||||
VK_COMPONENT_SWIZZLE_B, // VkComponentSwizzle .b;
|
||||
VK_COMPONENT_SWIZZLE_A // VkComponentSwizzle .a;
|
||||
},
|
||||
{ // VkImageSubresourceRange subresourceRange;
|
||||
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags .aspectMask;
|
||||
0, // uint32_t .baseMipLevel;
|
||||
1, // uint32_t .levelCount;
|
||||
0, // uint32_t .baseArrayLayer;
|
||||
1 // uint32_t .layerCount;
|
||||
}
|
||||
};
|
||||
|
||||
if (!m_buffers[i].view.Create(m_device, imageViewCreateInfo))
|
||||
{
|
||||
NazaraError("Failed to create image view for image #" + String::Number(i));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline const Swapchain::Buffer& Swapchain::GetBuffer(UInt32 index) const
|
||||
{
|
||||
return m_buffers[index];
|
||||
}
|
||||
|
||||
inline const std::vector<Swapchain::Buffer>& Swapchain::GetBuffers() const
|
||||
{
|
||||
return m_buffers;
|
||||
}
|
||||
|
||||
inline UInt32 Swapchain::GetBufferCount() const
|
||||
{
|
||||
return static_cast<UInt32>(m_buffers.size());
|
||||
}
|
||||
|
||||
inline bool Swapchain::IsSupported() const
|
||||
{
|
||||
if (!m_device->IsExtensionLoaded("VK_KHR_swapchain"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline VkResult Swapchain::CreateHelper(const DeviceHandle& device, const VkSwapchainCreateInfoKHR* createInfo, const VkAllocationCallbacks* allocator, VkSwapchainKHR* handle)
|
||||
{
|
||||
return device->vkCreateSwapchainKHR(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Swapchain::DestroyHelper(const DeviceHandle& device, VkSwapchainKHR handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroySwapchainKHR(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
55
include/Nazara/VulkanRenderer/Vulkan.hpp
Normal file
55
include/Nazara/VulkanRenderer/Vulkan.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKAN_HPP
|
||||
#define NAZARA_VULKAN_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
#include <Nazara/Core/ParameterList.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkPhysicalDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkSurface.hpp>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API Vulkan
|
||||
{
|
||||
public:
|
||||
Vulkan() = delete;
|
||||
~Vulkan() = delete;
|
||||
|
||||
static Vk::DeviceHandle CreateDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
||||
|
||||
static Vk::Instance& GetInstance();
|
||||
|
||||
static const std::vector<Vk::PhysicalDevice>& GetPhysicalDevices();
|
||||
static const Vk::PhysicalDevice& GetPhysicalDeviceInfo(VkPhysicalDevice physDevice);
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static Vk::DeviceHandle SelectDevice(VkPhysicalDevice gpu, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
||||
|
||||
static void SetParameters(const ParameterList& parameters);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static std::list<Vk::Device> s_devices;
|
||||
static std::vector<Vk::PhysicalDevice> s_physDevices;
|
||||
static Vk::Instance s_instance;
|
||||
static ParameterList s_initializationParameters;
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_VULKAN_HPP
|
||||
42
include/Nazara/VulkanRenderer/VulkanRenderer.hpp
Normal file
42
include/Nazara/VulkanRenderer/VulkanRenderer.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_HPP
|
||||
#define NAZARA_VULKANRENDERER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/RendererImpl.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkInstance.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkPhysicalDevice.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API VulkanRenderer : public RendererImpl
|
||||
{
|
||||
public:
|
||||
VulkanRenderer() = default;
|
||||
~VulkanRenderer() = default;
|
||||
|
||||
bool IsBetterThan(const RendererImpl* other) const override;
|
||||
|
||||
RenderAPI QueryAPI() const override;
|
||||
String QueryAPIString() const override;
|
||||
UInt32 QueryAPIVersion() const override;
|
||||
std::vector<RenderDevice> QueryRenderDevices() const override;
|
||||
|
||||
bool Prepare(const ParameterList& parameters) override;
|
||||
|
||||
static constexpr UInt32 APIVersion = VK_API_VERSION_1_0;
|
||||
|
||||
private:
|
||||
Vk::Instance m_instance;
|
||||
std::vector<Vk::PhysicalDevice> m_physDevices;
|
||||
UInt32 m_apiVersion;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_HPP
|
||||
Reference in New Issue
Block a user