Add command buffers (WIP)

This commit is contained in:
Lynix
2020-04-02 21:07:01 +02:00
parent cf396b0792
commit f443bec6bc
50 changed files with 1076 additions and 215 deletions

View File

@@ -29,15 +29,19 @@
#ifndef NAZARA_GLOBAL_RENDERER_HPP
#define NAZARA_GLOBAL_RENDERER_HPP
#include <Nazara/Renderer/CommandBuffer.hpp>
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/DebugDrawer.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/GlslWriter.hpp>
#include <Nazara/Renderer/RenderBuffer.hpp>
#include <Nazara/Renderer/RenderBufferView.hpp>
#include <Nazara/Renderer/RenderDevice.hpp>
#include <Nazara/Renderer/RenderDeviceInfo.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RendererImpl.hpp>
#include <Nazara/Renderer/RenderImage.hpp>
#include <Nazara/Renderer/RenderPipeline.hpp>
#include <Nazara/Renderer/RenderPipelineLayout.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
@@ -52,5 +56,6 @@
#include <Nazara/Renderer/ShaderWriter.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
#include <Nazara/Renderer/UploadPool.hpp>
#endif // NAZARA_GLOBAL_RENDERER_HPP

View File

@@ -0,0 +1,30 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_COMMANDBUFFER_HPP
#define NAZARA_COMMANDBUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/Config.hpp>
namespace Nz
{
class NAZARA_RENDERER_API CommandBuffer
{
public:
CommandBuffer() = default;
CommandBuffer(const CommandBuffer&) = delete;
CommandBuffer(CommandBuffer&&) = default;
virtual ~CommandBuffer();
CommandBuffer& operator=(const CommandBuffer&) = delete;
CommandBuffer& operator=(CommandBuffer&&) = default;
};
}
#include <Nazara/Renderer/CommandBuffer.inl>
#endif // NAZARA_COMMANDBUFFER_HPP

View File

@@ -0,0 +1,12 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/CommandBuffer.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -0,0 +1,59 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_COMMANDBUFFERBUILDER_HPP
#define NAZARA_COMMANDBUFFERBUILDER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/RenderBufferView.hpp>
#include <Nazara/Renderer/UploadPool.hpp>
#include <string_view>
namespace Nz
{
class ShaderBinding;
class NAZARA_RENDERER_API CommandBufferBuilder
{
public:
CommandBufferBuilder() = default;
CommandBufferBuilder(const CommandBufferBuilder&) = delete;
CommandBufferBuilder(CommandBufferBuilder&&) = default;
virtual ~CommandBufferBuilder();
virtual void BeginDebugRegion(const std::string_view& regionName, const Nz::Color& color) = 0;
virtual void BindIndexBuffer(Nz::AbstractBuffer* indexBuffer, UInt64 offset = 0) = 0;
virtual void BindShaderBinding(ShaderBinding& binding) = 0;
virtual void BindVertexBuffer(UInt32 binding, Nz::AbstractBuffer* vertexBuffer, UInt64 offset = 0) = 0;
inline void CopyBuffer(const RenderBufferView& source, const RenderBufferView& target);
virtual void CopyBuffer(const RenderBufferView& source, const RenderBufferView& target, UInt64 size, UInt64 fromOffset = 0, UInt64 toOffset = 0) = 0;
inline void CopyBuffer(const UploadPool::Allocation& allocation, const RenderBufferView& target);
virtual void CopyBuffer(const UploadPool::Allocation& allocation, const RenderBufferView& target, UInt64 size, UInt64 fromOffset = 0, UInt64 toOffset = 0) = 0;
virtual void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) = 0;
virtual void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) = 0;
virtual void EndDebugRegion() = 0;
virtual void PreTransferBarrier() = 0;
virtual void PostTransferBarrier() = 0;
virtual void SetScissor(Nz::Recti scissorRegion) = 0;
virtual void SetViewport(Nz::Recti viewportRegion) = 0;
CommandBufferBuilder& operator=(const CommandBufferBuilder&) = delete;
CommandBufferBuilder& operator=(CommandBufferBuilder&&) = default;
};
}
#include <Nazara/Renderer/CommandBufferBuilder.inl>
#endif // NAZARA_COMMANDBUFFERBUILDER_HPP

View File

@@ -0,0 +1,21 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
inline void CommandBufferBuilder::CopyBuffer(const RenderBufferView& from, const RenderBufferView& to)
{
return CopyBuffer(from, to, from.GetSize());
}
inline void CommandBufferBuilder::CopyBuffer(const UploadPool::Allocation& allocation, const RenderBufferView& target)
{
return CopyBuffer(allocation, target, allocation.size);
}
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -27,14 +27,15 @@ namespace Nz
RenderBuffer(RenderBuffer&&) = default;
~RenderBuffer() = default;
bool Fill(const void* data, UInt32 offset, UInt32 size) final;
bool Fill(const void* data, UInt64 offset, UInt64 size) final;
bool Initialize(UInt32 size, BufferUsageFlags usage) override;
bool Initialize(UInt64 size, BufferUsageFlags usage) override;
AbstractBuffer* GetHardwareBuffer(RenderDevice* device);
UInt64 GetSize() const override;
DataStorage GetStorage() const override;
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) final;
void* Map(BufferAccess access, UInt64 offset = 0, UInt64 size = 0) final;
bool Unmap() final;
RenderBuffer& operator=(const RenderBuffer&) = delete;

View File

@@ -0,0 +1,41 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RENDERBUFFERVIEW_HPP
#define NAZARA_RENDERBUFFERVIEW_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Utility/AbstractBuffer.hpp>
namespace Nz
{
class RenderBufferView
{
public:
inline RenderBufferView(AbstractBuffer* buffer);
inline RenderBufferView(AbstractBuffer* buffer, UInt64 offset, UInt64 size);
RenderBufferView(const RenderBufferView&) = delete;
RenderBufferView(RenderBufferView&&) = default;
~RenderBufferView() = default;
inline AbstractBuffer* GetBuffer() const;
inline UInt64 GetOffset() const;
inline UInt64 GetSize() const;
RenderBufferView& operator=(const RenderBufferView&) = delete;
RenderBufferView& operator=(RenderBufferView&&) = default;
private:
UInt64 m_offset;
UInt64 m_size;
AbstractBuffer* m_buffer;
};
}
#include <Nazara/Renderer/RenderBufferView.inl>
#endif // NAZARA_RENDERBUFFERVIEW_HPP

View File

@@ -0,0 +1,39 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/RenderBufferView.hpp>
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
inline RenderBufferView::RenderBufferView(AbstractBuffer* buffer) :
RenderBufferView(buffer, 0, buffer->GetSize())
{
}
inline RenderBufferView::RenderBufferView(AbstractBuffer* buffer, UInt64 offset, UInt64 size) :
m_buffer(buffer),
m_offset(offset),
m_size(size)
{
}
inline AbstractBuffer* RenderBufferView::GetBuffer() const
{
return m_buffer;
}
inline UInt64 RenderBufferView::GetOffset() const
{
return m_offset;
}
inline UInt64 RenderBufferView::GetSize() const
{
return m_size;
}
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -0,0 +1,42 @@
// 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_RENDERIMAGE_HPP
#define NAZARA_RENDERIMAGE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <functional>
namespace Nz
{
class CommandBuffer;
class CommandBufferBuilder;
class UploadPool;
class NAZARA_RENDERER_API RenderImage
{
public:
RenderImage() = default;
virtual ~RenderImage();
virtual void Execute(const std::function<void(CommandBufferBuilder& builder)>& callback, bool isGraphical) = 0;
virtual UploadPool& GetUploadPool() = 0;
virtual void SubmitCommandBuffer(CommandBuffer* commandBuffer, bool isGraphical) = 0;
virtual void Present() = 0;
protected:
RenderImage(const RenderImage&) = delete;
RenderImage(RenderImage&&) = default;
};
}
#include <Nazara/Renderer/RenderImage.inl>
#endif // NAZARA_RENDERIMAGE_HPP

View File

@@ -0,0 +1,12 @@
// 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
#include <Nazara/Renderer/RenderImage.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -13,11 +13,14 @@
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/RenderDevice.hpp>
#include <Nazara/Renderer/RenderWindowParameters.hpp>
#include <vector>
#include <functional>
namespace Nz
{
class CommandBuffer;
class CommandBufferBuilder;
class RendererImpl;
class RenderImage;
class RenderSurface;
class NAZARA_RENDERER_API RenderWindowImpl
@@ -26,6 +29,10 @@ namespace Nz
RenderWindowImpl() = default;
virtual ~RenderWindowImpl();
virtual RenderImage& Acquire() = 0;
virtual std::unique_ptr<CommandBuffer> BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback) = 0;
virtual bool Create(RendererImpl* renderer, RenderSurface* surface, const Vector2ui& size, const RenderWindowParameters& parameters) = 0;
virtual std::shared_ptr<RenderDevice> GetRenderDevice() = 0;

View File

@@ -0,0 +1,52 @@
// 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_RENDERER_UPLOADPOOL_HPP
#define NAZARA_RENDERER_UPLOADPOOL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/Config.hpp>
namespace Nz
{
class NAZARA_RENDERER_API UploadPool
{
public:
struct Allocation;
UploadPool() = default;
UploadPool(const UploadPool&) = delete;
UploadPool(UploadPool&&) noexcept = default;
~UploadPool() = default;
virtual Allocation& Allocate(UInt64 size) = 0;
virtual Allocation& Allocate(UInt64 size, UInt64 alignment) = 0;
virtual void Reset() = 0;
UploadPool& operator=(const UploadPool&) = delete;
UploadPool& operator=(UploadPool&&) = delete;
struct NAZARA_RENDERER_API Allocation
{
Allocation() = default;
Allocation(const Allocation&) = delete;
Allocation(Allocation&&) = default;
~Allocation();
Allocation& operator=(const Allocation&) = delete;
Allocation& operator=(Allocation&&) = default;
void* mappedPtr;
UInt64 offset;
UInt64 size;
};
};
}
#include <Nazara/Renderer/UploadPool.inl>
#endif // NAZARA_RENDERER_UPLOADPOOL_HPP

View File

@@ -0,0 +1,12 @@
// 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/Renderer/UploadPool.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -18,13 +18,14 @@ namespace Nz
AbstractBuffer() = default;
virtual ~AbstractBuffer();
virtual bool Fill(const void* data, UInt32 offset, UInt32 size) = 0;
virtual bool Fill(const void* data, UInt64 offset, UInt64 size) = 0;
virtual bool Initialize(UInt32 size, BufferUsageFlags usage) = 0;
virtual bool Initialize(UInt64 size, BufferUsageFlags usage) = 0;
virtual UInt64 GetSize() const = 0;
virtual DataStorage GetStorage() const = 0;
virtual void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) = 0;
virtual void* Map(BufferAccess access, UInt64 offset = 0, UInt64 size = 0) = 0;
virtual bool Unmap() = 0;
};
}

View File

@@ -19,16 +19,17 @@ namespace Nz
{
public:
SoftwareBuffer(Buffer* parent, BufferType type);
~SoftwareBuffer();
~SoftwareBuffer() = default;
bool Fill(const void* data, UInt32 offset, UInt32 size) override;
bool Fill(const void* data, UInt64 offset, UInt64 size) override;
bool Initialize(UInt32 size, BufferUsageFlags usage) override;
bool Initialize(UInt64 size, BufferUsageFlags usage) override;
const UInt8* GetData() const;
UInt64 GetSize() const;
DataStorage GetStorage() const override;
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) override;
void* Map(BufferAccess access, UInt64 offset = 0, UInt64 size = 0) override;
bool Unmap() override;
private:

View File

@@ -35,8 +35,11 @@
#include <Nazara/VulkanRenderer/VkRenderWindow.hpp>
#include <Nazara/VulkanRenderer/Vulkan.hpp>
#include <Nazara/VulkanRenderer/VulkanBuffer.hpp>
#include <Nazara/VulkanRenderer/VulkanCommandBuffer.hpp>
#include <Nazara/VulkanRenderer/VulkanCommandBufferBuilder.hpp>
#include <Nazara/VulkanRenderer/VulkanDevice.hpp>
#include <Nazara/VulkanRenderer/VulkanRenderer.hpp>
#include <Nazara/VulkanRenderer/VulkanRenderImage.hpp>
#include <Nazara/VulkanRenderer/VulkanRenderPipeline.hpp>
#include <Nazara/VulkanRenderer/VulkanRenderPipelineLayout.hpp>
#include <Nazara/VulkanRenderer/VulkanShaderBinding.hpp>

View File

@@ -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?

View File

@@ -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;
};
}

View File

@@ -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();
}
}

View File

@@ -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();

View File

@@ -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;

View 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

View 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>

View 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

View 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>

View 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

View 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>

View File

@@ -24,6 +24,7 @@ namespace Nz
~VulkanShaderBinding() = default;
inline Vk::DescriptorSet& GetDescriptorSet();
inline VulkanRenderPipelineLayout& GetOwner();
void Update(std::initializer_list<Binding> bindings) override;

View File

@@ -17,6 +17,11 @@ namespace Nz
{
return m_descriptorSet;
}
inline VulkanRenderPipelineLayout& VulkanShaderBinding::GetOwner()
{
return m_owner;
}
}
#include <Nazara/VulkanRenderer/DebugOff.hpp>

View File

@@ -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;
};
}

View File

@@ -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);

View File

@@ -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();

View File

@@ -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;
};
}
}

View File

@@ -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);