Add command buffers (WIP)
This commit is contained in:
@@ -26,15 +26,11 @@ namespace Nz
|
||||
VkRenderTarget(VkRenderTarget&&) = delete; ///TOOD?
|
||||
virtual ~VkRenderTarget();
|
||||
|
||||
virtual bool Acquire(UInt32* imageIndex, VkSemaphore signalSemaphore = VK_NULL_HANDLE, VkFence signalFence = VK_NULL_HANDLE) const = 0;
|
||||
|
||||
virtual const Vk::Framebuffer& GetFrameBuffer(UInt32 imageIndex) const = 0;
|
||||
virtual UInt32 GetFramebufferCount() const = 0;
|
||||
|
||||
inline const Vk::RenderPass& GetRenderPass() const;
|
||||
|
||||
virtual void Present(UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE) = 0;
|
||||
|
||||
VkRenderTarget& operator=(const VkRenderTarget&) = delete;
|
||||
VkRenderTarget& operator=(VkRenderTarget&&) = delete; ///TOOD?
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <Nazara/Renderer/RenderWindowImpl.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanDevice.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanRenderImage.hpp>
|
||||
#include <Nazara/VulkanRenderer/VkRenderTarget.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandPool.hpp>
|
||||
@@ -37,7 +38,9 @@ namespace Nz
|
||||
VkRenderWindow(VkRenderWindow&&) = delete; ///TODO
|
||||
virtual ~VkRenderWindow();
|
||||
|
||||
bool Acquire(UInt32* index, VkSemaphore signalSemaphore = VK_NULL_HANDLE, VkFence signalFence = VK_NULL_HANDLE) const override;
|
||||
VulkanRenderImage& Acquire() override;
|
||||
|
||||
std::unique_ptr<CommandBuffer> BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback) override;
|
||||
|
||||
bool Create(RendererImpl* renderer, RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters) override;
|
||||
|
||||
@@ -45,12 +48,12 @@ namespace Nz
|
||||
inline UInt32 GetFramebufferCount() const override;
|
||||
inline VulkanDevice& GetDevice();
|
||||
inline const VulkanDevice& GetDevice() const;
|
||||
inline UInt32 GetPresentableFamilyQueue() const;
|
||||
inline Vk::QueueHandle& GetGraphicsQueue();
|
||||
inline const Vk::Swapchain& GetSwapchain() const;
|
||||
|
||||
std::shared_ptr<RenderDevice> GetRenderDevice() override;
|
||||
|
||||
void Present(UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE) override;
|
||||
void Present(UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE);
|
||||
|
||||
VkRenderWindow& operator=(const VkRenderWindow&) = delete;
|
||||
VkRenderWindow& operator=(VkRenderWindow&&) = delete; ///TODO
|
||||
@@ -60,18 +63,27 @@ namespace Nz
|
||||
bool SetupRenderPass();
|
||||
bool SetupSwapchain(const Vk::PhysicalDevice& deviceInfo, Vk::Surface& surface, const Vector2ui& size);
|
||||
|
||||
struct ImageData
|
||||
{
|
||||
Vk::Framebuffer framebuffer;
|
||||
Vk::Fence* inFlightFence = nullptr;
|
||||
};
|
||||
|
||||
std::size_t m_currentFrame;
|
||||
Clock m_clock;
|
||||
VkColorSpaceKHR m_colorSpace;
|
||||
VkFormat m_colorFormat;
|
||||
VkFormat m_depthStencilFormat;
|
||||
std::shared_ptr<VulkanDevice> m_device;
|
||||
std::vector<Vk::Framebuffer> m_frameBuffers;
|
||||
std::vector<ImageData> m_imageData;
|
||||
std::vector<VulkanRenderImage> m_concurrentImageData;
|
||||
Vk::CommandPool m_graphicsCommandPool;
|
||||
Vk::DeviceMemory m_depthBufferMemory;
|
||||
Vk::Image m_depthBuffer;
|
||||
Vk::ImageView m_depthBufferView;
|
||||
Vk::QueueHandle m_graphicsQueue;
|
||||
Vk::QueueHandle m_presentQueue;
|
||||
Vk::Swapchain m_swapchain;
|
||||
UInt32 m_presentableFamilyQueue;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,19 +17,19 @@ namespace Nz
|
||||
return *m_device;
|
||||
}
|
||||
|
||||
inline Vk::QueueHandle& VkRenderWindow::GetGraphicsQueue()
|
||||
{
|
||||
return m_graphicsQueue;
|
||||
}
|
||||
|
||||
inline const Vk::Framebuffer& VkRenderWindow::GetFrameBuffer(UInt32 imageIndex) const
|
||||
{
|
||||
return m_frameBuffers[imageIndex];
|
||||
return m_imageData[imageIndex].framebuffer;
|
||||
}
|
||||
|
||||
inline UInt32 VkRenderWindow::GetFramebufferCount() const
|
||||
{
|
||||
return static_cast<UInt32>(m_frameBuffers.size());
|
||||
}
|
||||
|
||||
inline UInt32 VkRenderWindow::GetPresentableFamilyQueue() const
|
||||
{
|
||||
return m_presentableFamilyQueue;
|
||||
return static_cast<UInt32>(m_imageData.size());
|
||||
}
|
||||
|
||||
inline const Vk::Swapchain& VkRenderWindow::GetSwapchain() const
|
||||
@@ -44,9 +44,11 @@ namespace Nz
|
||||
|
||||
inline void VkRenderWindow::Present(UInt32 imageIndex, VkSemaphore waitSemaphore)
|
||||
{
|
||||
NazaraAssert(imageIndex < m_frameBuffers.size(), "Invalid image index");
|
||||
NazaraAssert(imageIndex < m_imageData.size(), "Invalid image index");
|
||||
|
||||
m_presentQueue.Present(m_swapchain, imageIndex, waitSemaphore);
|
||||
|
||||
m_currentFrame = (m_currentFrame + 1) % m_imageData.size();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Nz
|
||||
~Vulkan() = delete;
|
||||
|
||||
static std::shared_ptr<VulkanDevice> CreateDevice(const Vk::PhysicalDevice& deviceInfo);
|
||||
static std::shared_ptr<VulkanDevice> CreateDevice(const Vk::PhysicalDevice& deviceInfo, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
||||
static std::shared_ptr<VulkanDevice> CreateDevice(const Vk::PhysicalDevice& deviceInfo, const Vk::Surface& surface, UInt32* graphicsFamilyIndex, UInt32* presentableFamilyIndex);
|
||||
static std::shared_ptr<VulkanDevice> CreateDevice(const Vk::PhysicalDevice& deviceInfo, const QueueFamily* queueFamilies, std::size_t queueFamilyCount);
|
||||
|
||||
static Vk::Instance& GetInstance();
|
||||
@@ -49,7 +49,7 @@ namespace Nz
|
||||
static bool IsInitialized();
|
||||
|
||||
static std::shared_ptr<VulkanDevice> SelectDevice(const Vk::PhysicalDevice& deviceInfo);
|
||||
static std::shared_ptr<VulkanDevice> SelectDevice(const Vk::PhysicalDevice& deviceInfo, const Vk::Surface& surface, UInt32* presentableFamilyQueue);
|
||||
static std::shared_ptr<VulkanDevice> SelectDevice(const Vk::PhysicalDevice& deviceInfo, const Vk::Surface& surface, UInt32* graphicsFamilyIndex, UInt32* presentableFamilyIndex);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
|
||||
@@ -26,14 +26,15 @@ namespace Nz
|
||||
VulkanBuffer(VulkanBuffer&&) = delete; ///TODO
|
||||
virtual ~VulkanBuffer();
|
||||
|
||||
bool Fill(const void* data, UInt32 offset, UInt32 size) override;
|
||||
bool Fill(const void* data, UInt64 offset, UInt64 size) override;
|
||||
|
||||
bool Initialize(UInt64 size, BufferUsageFlags usage) override;
|
||||
|
||||
inline VkBuffer GetBuffer();
|
||||
bool Initialize(UInt32 size, BufferUsageFlags usage) override;
|
||||
|
||||
UInt64 GetSize() const override;
|
||||
DataStorage GetStorage() const override;
|
||||
|
||||
void* Map(BufferAccess access, UInt32 offset, UInt32 size) override;
|
||||
void* Map(BufferAccess access, UInt64 offset, UInt64 size) override;
|
||||
bool Unmap() override;
|
||||
|
||||
VulkanBuffer& operator=(const VulkanBuffer&) = delete;
|
||||
@@ -42,7 +43,7 @@ namespace Nz
|
||||
private:
|
||||
BufferType m_type;
|
||||
BufferUsageFlags m_usage;
|
||||
UInt32 m_size;
|
||||
UInt64 m_size;
|
||||
VkBuffer m_buffer;
|
||||
VkBuffer m_stagingBuffer;
|
||||
VmaAllocation m_allocation;
|
||||
|
||||
37
include/Nazara/VulkanRenderer/VulkanCommandBuffer.hpp
Normal file
37
include/Nazara/VulkanRenderer/VulkanCommandBuffer.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VULKANCOMMANDBUFFER_HPP
|
||||
#define NAZARA_VULKANRENDERER_VULKANCOMMANDBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/CommandBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API VulkanCommandBuffer final : public CommandBuffer
|
||||
{
|
||||
public:
|
||||
inline VulkanCommandBuffer(Vk::AutoCommandBuffer commandBuffer);
|
||||
VulkanCommandBuffer(const VulkanCommandBuffer&) = delete;
|
||||
VulkanCommandBuffer(VulkanCommandBuffer&&) noexcept = default;
|
||||
~VulkanCommandBuffer() = default;
|
||||
|
||||
inline Vk::CommandBuffer& GetCommandBuffer();
|
||||
|
||||
VulkanCommandBuffer& operator=(const VulkanCommandBuffer&) = delete;
|
||||
VulkanCommandBuffer& operator=(VulkanCommandBuffer&&) = delete;
|
||||
|
||||
private:
|
||||
Vk::AutoCommandBuffer m_commandBuffer;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VulkanCommandBuffer.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VULKANCOMMANDBUFFER_HPP
|
||||
21
include/Nazara/VulkanRenderer/VulkanCommandBuffer.inl
Normal file
21
include/Nazara/VulkanRenderer/VulkanCommandBuffer.inl
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2020 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/VulkanCommandBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline VulkanCommandBuffer::VulkanCommandBuffer(Vk::AutoCommandBuffer commandBuffer) :
|
||||
m_commandBuffer(std::move(commandBuffer))
|
||||
{
|
||||
}
|
||||
|
||||
inline Vk::CommandBuffer& VulkanCommandBuffer::GetCommandBuffer()
|
||||
{
|
||||
return m_commandBuffer.Get();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
57
include/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.hpp
Normal file
57
include/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VULKANCOMMANDBUFFERBUILDER_HPP
|
||||
#define NAZARA_VULKANRENDERER_VULKANCOMMANDBUFFERBUILDER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API VulkanCommandBufferBuilder final : public CommandBufferBuilder
|
||||
{
|
||||
public:
|
||||
inline VulkanCommandBufferBuilder(Vk::CommandBuffer& commandBuffer);
|
||||
VulkanCommandBufferBuilder(const VulkanCommandBufferBuilder&) = delete;
|
||||
VulkanCommandBufferBuilder(VulkanCommandBufferBuilder&&) noexcept = default;
|
||||
~VulkanCommandBufferBuilder() = default;
|
||||
|
||||
void BeginDebugRegion(const std::string_view& regionName, const Nz::Color& color) override;
|
||||
|
||||
void BindIndexBuffer(AbstractBuffer* indexBuffer, UInt64 offset = 0) override;
|
||||
void BindShaderBinding(ShaderBinding& binding) override;
|
||||
void BindVertexBuffer(UInt32 binding, Nz::AbstractBuffer* vertexBuffer, UInt64 offset = 0) override;
|
||||
|
||||
void CopyBuffer(const RenderBufferView& source, const RenderBufferView& target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0) override;
|
||||
void CopyBuffer(const UploadPool::Allocation& allocation, const RenderBufferView& target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0) override;
|
||||
|
||||
void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) override;
|
||||
void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) override;
|
||||
|
||||
void EndDebugRegion() override;
|
||||
|
||||
inline Vk::CommandBuffer& GetCommandBuffer();
|
||||
|
||||
void PreTransferBarrier() override;
|
||||
void PostTransferBarrier() override;
|
||||
|
||||
void SetScissor(Nz::Recti scissorRegion) override;
|
||||
void SetViewport(Nz::Recti viewportRegion) override;
|
||||
|
||||
VulkanCommandBufferBuilder& operator=(const VulkanCommandBufferBuilder&) = delete;
|
||||
VulkanCommandBufferBuilder& operator=(VulkanCommandBufferBuilder&&) = delete;
|
||||
|
||||
private:
|
||||
Vk::CommandBuffer& m_commandBuffer;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VulkanCommandBufferBuilder.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VULKANCOMMANDBUFFERBUILDER_HPP
|
||||
21
include/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.inl
Normal file
21
include/Nazara/VulkanRenderer/VulkanCommandBufferBuilder.inl
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2020 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/VulkanCommandBufferBuilder.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline VulkanCommandBufferBuilder::VulkanCommandBufferBuilder(Vk::CommandBuffer& commandBuffer) :
|
||||
m_commandBuffer(commandBuffer)
|
||||
{
|
||||
}
|
||||
|
||||
inline Vk::CommandBuffer& VulkanCommandBufferBuilder::GetCommandBuffer()
|
||||
{
|
||||
return m_commandBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
65
include/Nazara/VulkanRenderer/VulkanRenderImage.hpp
Normal file
65
include/Nazara/VulkanRenderer/VulkanRenderImage.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VULKANRENDERIMAGE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VULKANRENDERIMAGE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/RenderImage.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanUploadPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandBuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/CommandPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Fence.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Semaphore.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class VkRenderWindow;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API VulkanRenderImage : public RenderImage
|
||||
{
|
||||
public:
|
||||
VulkanRenderImage(VkRenderWindow& owner);
|
||||
VulkanRenderImage(const VulkanRenderImage&) = delete;
|
||||
VulkanRenderImage(VulkanRenderImage&&) noexcept = default;
|
||||
~VulkanRenderImage();
|
||||
|
||||
void Execute(const std::function<void(CommandBufferBuilder& builder)>& callback, bool isGraphical) override;
|
||||
|
||||
inline Vk::Fence& GetInFlightFence();
|
||||
inline Vk::Semaphore& GetImageAvailableSemaphore();
|
||||
inline UInt32 GetImageIndex();
|
||||
inline Vk::Semaphore& GetRenderFinishedSemaphore();
|
||||
VulkanUploadPool& GetUploadPool() override;
|
||||
|
||||
void SubmitCommandBuffer(CommandBuffer* commandBuffer, bool isGraphical) override;
|
||||
void SubmitCommandBuffer(VkCommandBuffer commandBuffer, bool isGraphical);
|
||||
|
||||
void Present() override;
|
||||
|
||||
inline void Reset(UInt32 imageIndex);
|
||||
|
||||
VulkanRenderImage& operator=(const VulkanRenderImage&) = delete;
|
||||
VulkanRenderImage& operator=(VulkanRenderImage&&) = delete;
|
||||
|
||||
private:
|
||||
std::size_t m_currentCommandBuffer;
|
||||
std::vector<Vk::AutoCommandBuffer> m_inFlightCommandBuffers;
|
||||
std::vector<VkCommandBuffer> m_graphicalCommandsBuffers;
|
||||
VkRenderWindow& m_owner;
|
||||
Vk::CommandPool m_commandPool;
|
||||
Vk::Fence m_inFlightFence;
|
||||
Vk::Semaphore m_imageAvailableSemaphore;
|
||||
Vk::Semaphore m_renderFinishedSemaphore;
|
||||
VulkanUploadPool m_uploadPool;
|
||||
UInt32 m_imageIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VulkanRenderImage.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VULKANRENDERIMAGE_HPP
|
||||
39
include/Nazara/VulkanRenderer/VulkanRenderImage.inl
Normal file
39
include/Nazara/VulkanRenderer/VulkanRenderImage.inl
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2020 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/VulkanRenderImage.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Vk::Fence& Nz::VulkanRenderImage::GetInFlightFence()
|
||||
{
|
||||
return m_inFlightFence;
|
||||
}
|
||||
|
||||
inline Vk::Semaphore& VulkanRenderImage::GetImageAvailableSemaphore()
|
||||
{
|
||||
return m_imageAvailableSemaphore;
|
||||
}
|
||||
|
||||
inline UInt32 VulkanRenderImage::GetImageIndex()
|
||||
{
|
||||
return m_imageIndex;
|
||||
}
|
||||
|
||||
inline Vk::Semaphore& VulkanRenderImage::GetRenderFinishedSemaphore()
|
||||
{
|
||||
return m_renderFinishedSemaphore;
|
||||
}
|
||||
|
||||
inline void VulkanRenderImage::Reset(UInt32 imageIndex)
|
||||
{
|
||||
m_graphicalCommandsBuffers.clear();
|
||||
m_currentCommandBuffer = 0;
|
||||
m_imageIndex = imageIndex;
|
||||
m_uploadPool.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
@@ -24,6 +24,7 @@ namespace Nz
|
||||
~VulkanShaderBinding() = default;
|
||||
|
||||
inline Vk::DescriptorSet& GetDescriptorSet();
|
||||
inline VulkanRenderPipelineLayout& GetOwner();
|
||||
|
||||
void Update(std::initializer_list<Binding> bindings) override;
|
||||
|
||||
|
||||
@@ -17,6 +17,11 @@ namespace Nz
|
||||
{
|
||||
return m_descriptorSet;
|
||||
}
|
||||
|
||||
inline VulkanRenderPipelineLayout& VulkanShaderBinding::GetOwner()
|
||||
{
|
||||
return m_owner;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Renderer/UploadPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Buffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceMemory.hpp>
|
||||
#include <optional>
|
||||
@@ -16,28 +17,23 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_VULKANRENDERER_API VulkanUploadPool
|
||||
class NAZARA_VULKANRENDERER_API VulkanUploadPool : public UploadPool
|
||||
{
|
||||
public:
|
||||
struct AllocationData;
|
||||
struct VulkanAllocation : Allocation
|
||||
{
|
||||
VkBuffer buffer;
|
||||
};
|
||||
|
||||
inline VulkanUploadPool(Vk::Device& device, UInt64 blockSize);
|
||||
VulkanUploadPool(const VulkanUploadPool&) = delete;
|
||||
VulkanUploadPool(VulkanUploadPool&&) noexcept = default;
|
||||
~VulkanUploadPool() = default;
|
||||
|
||||
std::optional<AllocationData> Allocate(UInt64 size);
|
||||
std::optional<AllocationData> Allocate(UInt64 size, UInt64 alignment);
|
||||
VulkanAllocation& Allocate(UInt64 size) override;
|
||||
VulkanAllocation& Allocate(UInt64 size, UInt64 alignment) override;
|
||||
|
||||
void Reset();
|
||||
|
||||
struct AllocationData
|
||||
{
|
||||
VkBuffer buffer;
|
||||
void* mappedPtr;
|
||||
UInt64 offset;
|
||||
UInt64 size;
|
||||
};
|
||||
void Reset() override;
|
||||
|
||||
VulkanUploadPool& operator=(const VulkanUploadPool&) = delete;
|
||||
VulkanUploadPool& operator=(VulkanUploadPool&&) = delete;
|
||||
@@ -53,6 +49,7 @@ namespace Nz
|
||||
UInt64 m_blockSize;
|
||||
Vk::Device& m_device;
|
||||
std::vector<Block> m_blocks;
|
||||
std::vector<VulkanAllocation> m_allocations;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Nz
|
||||
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 CopyBuffer(VkBuffer source, VkBuffer target, UInt32 size, UInt32 sourceOffset = 0, UInt32 targetOffset = 0);
|
||||
inline void CopyBuffer(VkBuffer source, VkBuffer target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0);
|
||||
inline void CopyBufferToImage(VkBuffer source, VkImage target, VkImageLayout targetLayout, UInt32 width, UInt32 height, UInt32 depth = 1);
|
||||
|
||||
inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
|
||||
@@ -68,6 +68,8 @@ namespace Nz
|
||||
|
||||
inline void Free();
|
||||
|
||||
inline CommandPool& GetPool();
|
||||
|
||||
inline void InsertDebugLabel(const char* label);
|
||||
inline void InsertDebugLabel(const char* label, Nz::Color color);
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace Nz
|
||||
return m_pool->GetDevice()->vkCmdClearDepthStencilImage(m_handle, image, imageLayout, &depthStencil, rangeCount, ranges);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::CopyBuffer(VkBuffer source, VkBuffer target, UInt32 size, UInt32 sourceOffset, UInt32 targetOffset)
|
||||
inline void CommandBuffer::CopyBuffer(VkBuffer source, VkBuffer target, UInt64 size, UInt64 sourceOffset, UInt64 targetOffset)
|
||||
{
|
||||
VkBufferCopy region;
|
||||
region.dstOffset = targetOffset;
|
||||
@@ -292,6 +292,11 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
inline CommandPool& CommandBuffer::GetPool()
|
||||
{
|
||||
return *m_pool;
|
||||
}
|
||||
|
||||
inline void CommandBuffer::InsertDebugLabel(const char* label)
|
||||
{
|
||||
Vk::Device* device = m_pool->GetDevice();
|
||||
|
||||
@@ -20,13 +20,14 @@ namespace Nz
|
||||
{
|
||||
public:
|
||||
inline QueueHandle();
|
||||
inline QueueHandle(Device& device, VkQueue queue);
|
||||
inline QueueHandle(Device& device, VkQueue queue, UInt32 queueFamilyIndex);
|
||||
QueueHandle(const QueueHandle& queue) = delete;
|
||||
QueueHandle(QueueHandle&& queue) noexcept = default;
|
||||
~QueueHandle() = default;
|
||||
|
||||
inline Device& GetDevice() const;
|
||||
inline VkResult GetLastErrorCode() const;
|
||||
inline UInt32 GetQueueFamilyIndex() const;
|
||||
|
||||
inline bool Present(const VkPresentInfoKHR& presentInfo) const;
|
||||
inline bool Present(VkSwapchainKHR swapchain, UInt32 imageIndex, VkSemaphore waitSemaphore = VK_NULL_HANDLE) const;
|
||||
@@ -51,6 +52,7 @@ namespace Nz
|
||||
MovablePtr<Device> m_device;
|
||||
VkQueue m_handle;
|
||||
mutable VkResult m_lastErrorCode;
|
||||
UInt32 m_queueFamilyIndex;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,11 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
inline QueueHandle::QueueHandle(Device& device, VkQueue queue) :
|
||||
inline QueueHandle::QueueHandle(Device& device, VkQueue queue, UInt32 queueFamilyIndex) :
|
||||
m_device(&device),
|
||||
m_handle(queue),
|
||||
m_lastErrorCode(VkResult::VK_SUCCESS)
|
||||
m_lastErrorCode(VkResult::VK_SUCCESS),
|
||||
m_queueFamilyIndex(queueFamilyIndex)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,6 +36,11 @@ namespace Nz
|
||||
return m_lastErrorCode;
|
||||
}
|
||||
|
||||
inline UInt32 QueueHandle::GetQueueFamilyIndex() const
|
||||
{
|
||||
return m_queueFamilyIndex;
|
||||
}
|
||||
|
||||
inline bool QueueHandle::Present(const VkPresentInfoKHR& presentInfo) const
|
||||
{
|
||||
m_lastErrorCode = m_device->vkQueuePresentKHR(m_handle, &presentInfo);
|
||||
|
||||
Reference in New Issue
Block a user