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

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