VulkanRenderer: Move vulkan wrappers to a separate directory

This commit is contained in:
Lynix
2016-10-29 01:59:06 +02:00
parent 8d06c57d0d
commit e61c6d0a8e
58 changed files with 108 additions and 108 deletions

View 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/Wrapper/DeviceObject.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/Wrapper/Buffer.inl>
#endif // NAZARA_VULKANRENDERER_VKBUFFER_HPP

View 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/Wrapper/Buffer.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>

View 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/Wrapper/CommandPool.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/Wrapper/CommandBuffer.inl>
#endif // NAZARA_VULKANRENDERER_VKCOMMANDBUFFER_HPP

View 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/Wrapper/CommandBuffer.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Instance.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: " + TranslateVulkanError(m_lastErrorCode));
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: " + TranslateVulkanError(m_lastErrorCode));
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>

View 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/Wrapper/DeviceObject.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/Wrapper/CommandPool.inl>
#endif // NAZARA_VULKANRENDERER_VKCOMMANDPOOL_HPP

View 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/Wrapper/CommandPool.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Device.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>

View 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/Wrapper/DeviceObject.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/Wrapper/DescriptorPool.inl>
#endif // NAZARA_VULKANRENDERER_VKDESCRIPTORPOOL_HPP

View 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/Wrapper/DescriptorPool.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>

View 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/Wrapper/DescriptorPool.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/Wrapper/DescriptorSet.inl>
#endif // NAZARA_VULKANRENDERER_VKDESCRIPTORSET_HPP

View 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/Wrapper/DescriptorSet.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Instance.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>

View 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/Wrapper/DeviceObject.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/Wrapper/DescriptorSetLayout.inl>
#endif // NAZARA_VULKANRENDERER_VKDESCRIPTORSETLAYOUT_HPP

View 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/Wrapper/DescriptorSetLayout.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>

View 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/Wrapper/Loader.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/Wrapper/Device.inl>
#endif // NAZARA_VULKANRENDERER_VKDEVICE_HPP

View File

@@ -0,0 +1,118 @@
// 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/Wrapper/Device.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Instance.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Queue.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: " + TranslateVulkanError(m_lastErrorCode));
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>

View 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/Wrapper/DeviceObject.hpp>
namespace Nz
{
namespace Vk
{
class DeviceMemory : public DeviceObject<DeviceMemory, VkDeviceMemory, VkMemoryAllocateInfo>
{
friend DeviceObject;
public:
DeviceMemory();
DeviceMemory(const DeviceMemory&) = delete;
inline 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/Wrapper/DeviceMemory.inl>
#endif // NAZARA_VULKANRENDERER_VKDEVICEMEMORY_HPP

View File

@@ -0,0 +1,97 @@
// 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/Wrapper/DeviceMemory.hpp>
#include <Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Vulkan.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
{
namespace Vk
{
inline DeviceMemory::DeviceMemory() :
m_mappedPtr(nullptr)
{
}
inline 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: " + TranslateVulkanError(m_lastErrorCode));
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>

View 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/Wrapper/Device.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;
inline DeviceObject(DeviceObject&& object);
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/Wrapper/DeviceObject.inl>
#endif // NAZARA_VULKANRENDERER_VKDEVICEOBJECT_HPP

View 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
#include <Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Wrapper/CommandPool.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Device.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: " + TranslateVulkanError(m_lastErrorCode));
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>

View 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/Wrapper/DeviceObject.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/Wrapper/Framebuffer.inl>
#endif // NAZARA_VULKANRENDERER_VKFRAMEBUFFER_HPP

View 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/Wrapper/Framebuffer.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>

View 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/Wrapper/DeviceObject.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/Wrapper/Image.inl>
#endif // NAZARA_VULKANRENDERER_VKIMAGE_HPP

View File

@@ -0,0 +1,47 @@
// 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/Wrapper/Image.hpp>
#include <Nazara/VulkanRenderer/Utils.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 image memory: " + TranslateVulkanError(m_lastErrorCode));
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>

View 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/Wrapper/DeviceObject.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/Wrapper/ImageView.inl>
#endif // NAZARA_VULKANRENDERER_VKIMAGEVIEW_HPP

View 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/Wrapper/ImageView.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>

View File

@@ -0,0 +1,142 @@
// 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/Wrapper/Loader.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);
inline bool IsValid() const;
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/Wrapper/Instance.inl>
#endif // NAZARA_VULKANRENDERER_VKINSTANCE_HPP

View File

@@ -0,0 +1,149 @@
// 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/Wrapper/Instance.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.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 bool Instance::IsValid() const
{
return m_instance != nullptr;
}
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: " + TranslateVulkanError(m_lastErrorCode));
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>

View 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/Wrapper/Loader.inl>
#endif // NAZARA_VULKANRENDERER_VKLOADER_HPP

View 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/Wrapper/Loader.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>

View 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

View 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/Wrapper/DeviceObject.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/Wrapper/Pipeline.inl>
#endif // NAZARA_VULKANRENDERER_VKPIPELINE_HPP

View File

@@ -0,0 +1,87 @@
// 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/Wrapper/Pipeline.hpp>
#include <Nazara/VulkanRenderer/Utils.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: " + TranslateVulkanError(m_lastErrorCode));
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>

View 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/Wrapper/DeviceObject.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/Wrapper/PipelineCache.inl>
#endif // NAZARA_VULKANRENDERER_VKPIPELINECACHE_HPP

View 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/Wrapper/PipelineCache.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>

View 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/Wrapper/DeviceObject.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/Wrapper/PipelineLayout.inl>
#endif // NAZARA_VULKANRENDERER_VKPIPELINELAYOUT_HPP

View 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/Wrapper/PipelineLayout.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>

View 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/Wrapper/Device.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/Wrapper/Queue.inl>
#endif // NAZARA_VULKANRENDERER_VKQUEUE_HPP

View File

@@ -0,0 +1,125 @@
// 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/Wrapper/Queue.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Device.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)
{
NazaraError("Failed to present queue: " + TranslateVulkanError(m_lastErrorCode));
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)
{
NazaraError("Failed to submit queue: " + TranslateVulkanError(m_lastErrorCode));
return false;
}
return true;
}
inline bool Queue::WaitIdle() const
{
m_lastErrorCode = m_device->vkQueueWaitIdle(m_handle);
if (m_lastErrorCode != VkResult::VK_SUCCESS)
{
NazaraError("Failed to wait for queue: " + TranslateVulkanError(m_lastErrorCode));
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>

View 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/Wrapper/DeviceObject.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/Wrapper/RenderPass.inl>
#endif // NAZARA_VULKANRENDERER_VKRENDERPASS_HPP

View 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/Wrapper/RenderPass.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>

View 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/Wrapper/DeviceObject.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/Wrapper/Semaphore.inl>
#endif // NAZARA_VULKANRENDERER_VKSEMAPHORE_HPP

View 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/Wrapper/Semaphore.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>

View 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/Wrapper/DeviceObject.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/Wrapper/ShaderModule.inl>
#endif // NAZARA_VULKANRENDERER_VKSHADERMODULE_HPP

View 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/Wrapper/ShaderModule.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>

View 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/Wrapper/Loader.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/Wrapper/Surface.inl>
#endif // NAZARA_VULKANRENDERER_VKSURFACE_HPP

View File

@@ -0,0 +1,315 @@
// 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/Wrapper/Surface.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Instance.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: " + TranslateVulkanError(m_lastErrorCode));
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: " + TranslateVulkanError(m_lastErrorCode));
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: " + TranslateVulkanError(m_lastErrorCode));
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: " + TranslateVulkanError(m_lastErrorCode));
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: " + TranslateVulkanError(m_lastErrorCode));
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: " + TranslateVulkanError(m_lastErrorCode));
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>

View 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/Wrapper/DeviceObject.hpp>
#include <Nazara/VulkanRenderer/Wrapper/ImageView.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/Wrapper/Swapchain.inl>
#endif // NAZARA_VULKANRENDERER_VKSWAPCHAIN_HPP

View File

@@ -0,0 +1,125 @@
// 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/Wrapper/Swapchain.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Device.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:
{
NazaraError("Failed to acquire next swapchain image: " + TranslateVulkanError(m_lastErrorCode));
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: " + TranslateVulkanError(m_lastErrorCode));
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: " + TranslateVulkanError(m_lastErrorCode));
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>