Add FrameGraph (WIP)

This commit is contained in:
Jérôme Leclercq
2021-05-02 13:58:35 +02:00
parent 377129586b
commit 55c2dd8485
29 changed files with 1749 additions and 36 deletions

View File

@@ -0,0 +1,98 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_BAKEDFRAMEGRAPH_HPP
#define NAZARA_BAKEDFRAMEGRAPH_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/FramePass.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Renderer/CommandPool.hpp>
#include <Nazara/Renderer/Framebuffer.hpp>
#include <Nazara/Renderer/RenderPass.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <vector>
namespace Nz
{
class RenderFrame;
class NAZARA_GRAPHICS_API BakedFrameGraph
{
friend class FrameGraph;
public:
BakedFrameGraph(const BakedFrameGraph&) = delete;
BakedFrameGraph(BakedFrameGraph&&) noexcept = default;
~BakedFrameGraph() = default;
void Execute(RenderFrame& renderFrame);
const std::shared_ptr<Texture>& GetAttachmentTexture(std::size_t attachmentIndex) const;
const std::shared_ptr<RenderPass>& GetRenderPass(std::size_t passIndex) const;
void Resize(unsigned int width, unsigned int height);
BakedFrameGraph& operator=(const BakedFrameGraph&) = delete;
BakedFrameGraph& operator=(BakedFrameGraph&&) noexcept = default;
private:
struct PassData;
struct TextureData;
using AttachmentIdToTextureId = std::unordered_map<std::size_t /*attachmentId*/, std::size_t /*textureId*/>;
using PassIdToPhysicalPassIndex = std::unordered_map<std::size_t /*passId*/, std::size_t /*physicalPassId*/>;
BakedFrameGraph(std::vector<PassData> passes, std::vector<TextureData> textures, AttachmentIdToTextureId attachmentIdToTextureMapping, PassIdToPhysicalPassIndex passIdToPhysicalPassMapping);
struct TextureTransition
{
std::size_t textureId;
MemoryAccessFlags dstAccessMask;
MemoryAccessFlags srcAccessMask;
PipelineStageFlags dstStageMask;
PipelineStageFlags srcStageMask;
TextureLayout newLayout;
TextureLayout oldLayout;
};
struct SubpassData
{
FramePass::CommandCallback commandCallback;
};
struct PassData
{
CommandBufferPtr commandBuffer;
std::shared_ptr<Framebuffer> framebuffer;
std::shared_ptr<RenderPass> renderPass;
std::vector<std::size_t> outputTextureIndices;
std::vector<SubpassData> subpasses;
std::vector<TextureTransition> transitions;
FramePass::ExecutionCallback executionCallback;
Recti renderRect;
};
struct TextureData
{
std::shared_ptr<Texture> texture;
PixelFormat format;
TextureUsageFlags usage;
unsigned int width;
unsigned int height;
};
std::shared_ptr<CommandPool> m_commandPool;
std::vector<PassData> m_passes;
std::vector<TextureData> m_textures;
AttachmentIdToTextureId m_attachmentToTextureMapping;
PassIdToPhysicalPassIndex m_passIdToPhysicalPassMapping;
};
}
#include <Nazara/Graphics/BakedFrameGraph.inl>
#endif

View File

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

View File

@@ -0,0 +1,120 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FRAMEGRAPH_HPP
#define NAZARA_FRAMEGRAPH_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/BakedFrameGraph.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/FramePass.hpp>
#include <Nazara/Graphics/FramePassAttachment.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/RenderPass.hpp>
#include <optional>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
namespace Nz
{
class NAZARA_GRAPHICS_API FrameGraph
{
public:
FrameGraph() = default;
FrameGraph(const FrameGraph&) = delete;
FrameGraph(FrameGraph&&) noexcept = default;
~FrameGraph() = default;
inline std::size_t AddAttachment(FramePassAttachment attachment);
inline FramePass& AddPass(std::string name);
BakedFrameGraph Bake();
inline void SetBackbufferOutput(std::size_t backbufferOutput);
FrameGraph& operator=(const FrameGraph&) = delete;
FrameGraph& operator=(FrameGraph&&) noexcept = default;
private:
struct PassBarriers;
using BarrierList = std::vector<PassBarriers>;
using PassList = std::vector<std::size_t /*PassIndex*/>;
using AttachmentIdToPassMap = std::unordered_map<std::size_t /*resourceIndex*/, PassList /*passIndexes*/>;
using AttachmentIdToTextureId = std::unordered_map<std::size_t /*attachmentId*/, std::size_t /*textureId*/>;
using PassIdToPhysicalPassIndex = std::unordered_map<std::size_t /*passId*/, std::size_t /*physicalPassId*/>;
using TextureTransition = BakedFrameGraph::TextureTransition;
struct Barrier
{
std::size_t textureId;
MemoryAccessFlags access;
PipelineStageFlags stages;
TextureLayout layout;
};
struct PassBarriers
{
std::vector<Barrier> invalidationBarriers;
std::vector<Barrier> flushBarriers;
};
struct PhysicalPassData
{
struct Subpass
{
std::size_t passIndex;
};
std::vector<TextureTransition> textureTransitions;
std::vector<Subpass> passes;
};
struct TextureData
{
PixelFormat format;
TextureUsageFlags usage;
unsigned int width;
unsigned int height;
};
struct WorkData
{
std::size_t backbufferResourceIndex;
std::vector<std::shared_ptr<RenderPass>> renderPasses;
std::vector<PhysicalPassData> physicalPasses;
std::vector<TextureData> textures;
AttachmentIdToPassMap attachmentReadList;
AttachmentIdToPassMap attachmentWriteList;
AttachmentIdToTextureId attachmentToTextures;
BarrierList barrierList;
PassList passList;
PassIdToPhysicalPassIndex passIdToPhysicalPassIndex;
};
void AssignPhysicalPasses();
void AssignPhysicalTextures();
void BuildBarriers();
void BuildPhysicalBarriers();
void BuildPhysicalPassDependencies(std::size_t colorAttachmentCount, bool hasDepthStencilAttachment, std::vector<RenderPass::Attachment>& renderPassAttachments, std::vector<RenderPass::SubpassDescription>& subpasses, std::vector<RenderPass::SubpassDependency>& dependencies);
void BuildPhysicalPasses();
void BuildReadWriteList();
void RemoveDuplicatePasses();
void ReorderPasses();
void TraverseGraph(std::size_t passIndex);
std::optional<std::size_t> m_backbufferOutput;
std::vector<FramePass> m_framePasses;
std::vector<FramePassAttachment> m_attachments;
WorkData m_pending;
};
}
#include <Nazara/Graphics/FrameGraph.inl>
#endif

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/FrameGraph.hpp>
#include <cassert>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
inline std::size_t FrameGraph::AddAttachment(FramePassAttachment attachment)
{
std::size_t id = m_attachments.size();
m_attachments.emplace_back(std::move(attachment));
return id;
}
inline FramePass& FrameGraph::AddPass(std::string name)
{
std::size_t id = m_framePasses.size();
return m_framePasses.emplace_back(*this, id, std::move(name));
}
inline void FrameGraph::SetBackbufferOutput(std::size_t backbufferOutput)
{
m_backbufferOutput = backbufferOutput;
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -0,0 +1,102 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FRAMEPASS_HPP
#define NAZARA_FRAMEPASS_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/FramePassAttachment.hpp>
#include <limits>
#include <optional>
#include <string>
namespace Nz
{
class CommandBufferBuilder;
class FrameGraph;
enum class FramePassExecution
{
Execute,
Skip,
UpdateAndExecute
};
class NAZARA_GRAPHICS_API FramePass
{
public:
using CommandCallback = std::function<void(CommandBufferBuilder& builder)>;
using ExecutionCallback = std::function<FramePassExecution()>;
struct DepthStencilClear;
struct Input;
struct Output;
inline FramePass(FrameGraph& owner, std::size_t passId, std::string name);
FramePass(const FramePass&) = delete;
FramePass(FramePass&&) noexcept = default;
~FramePass() = default;
inline std::size_t AddInput(std::size_t attachmentId);
inline std::size_t AddOutput(std::size_t attachmentId);
inline const CommandCallback& GetCommandCallback() const;
inline const std::optional<DepthStencilClear>& GetDepthStencilClear() const;
inline std::size_t GetDepthStencilInput() const;
inline std::size_t GetDepthStencilOutput() const;
inline const ExecutionCallback& GetExecutionCallback() const;
inline const std::vector<Input>& GetInputs() const;
inline const std::vector<Output>& GetOutputs() const;
inline std::size_t GetPassId() const;
inline void SetCommandCallback(CommandCallback callback);
inline void SetClearColor(std::size_t outputIndex, const std::optional<Color>& color);
inline void SetDepthStencilClear(float depth, UInt32 stencil);
inline void SetExecutionCallback(CommandCallback callback);
inline void SetDepthStencilInput(std::size_t attachmentId);
inline void SetDepthStencilOutput(std::size_t attachmentId);
FramePass& operator=(const FramePass&) = delete;
FramePass& operator=(FramePass&&) noexcept = default;
static constexpr std::size_t InvalidAttachmentId = std::numeric_limits<std::size_t>::max();
struct DepthStencilClear
{
float depth;
UInt32 stencil;
};
struct Input
{
std::size_t attachmentId;
};
struct Output
{
std::size_t attachmentId;
std::optional<Color> clearColor;
};
private:
std::optional<DepthStencilClear> m_depthStencilClear;
std::size_t m_depthStencilInput;
std::size_t m_depthStencilOutput;
std::size_t m_passId;
std::string m_name;
std::vector<Input> m_inputs;
std::vector<Output> m_outputs;
FrameGraph& m_owner;
CommandCallback m_commandCallback;
ExecutionCallback m_executionCallback;
};
}
#include <Nazara/Graphics/FramePass.inl>
#endif

View File

@@ -0,0 +1,116 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/FramePass.hpp>
#include <cassert>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
inline FramePass::FramePass(FrameGraph& owner, std::size_t passId, std::string name) :
m_depthStencilInput(InvalidAttachmentId),
m_depthStencilOutput(InvalidAttachmentId),
m_passId(passId),
m_name(std::move(name)),
m_owner(owner)
{
}
inline std::size_t FramePass::AddInput(std::size_t attachmentId)
{
assert(attachmentId != InvalidAttachmentId);
std::size_t inputIndex = m_inputs.size();
auto& input = m_inputs.emplace_back();
input.attachmentId = attachmentId;
return inputIndex;
}
inline std::size_t FramePass::AddOutput(std::size_t attachmentId)
{
assert(attachmentId != InvalidAttachmentId);
std::size_t outputIndex = m_outputs.size();
auto& output = m_outputs.emplace_back();
output.attachmentId = attachmentId;
return outputIndex;
}
inline auto FramePass::GetCommandCallback() const -> const CommandCallback&
{
return m_commandCallback;
}
inline auto FramePass::GetDepthStencilClear() const -> const std::optional<DepthStencilClear>&
{
return m_depthStencilClear;
}
inline std::size_t FramePass::GetDepthStencilInput() const
{
return m_depthStencilInput;
}
inline std::size_t FramePass::GetDepthStencilOutput() const
{
return m_depthStencilOutput;
}
inline auto FramePass::GetExecutionCallback() const -> const ExecutionCallback&
{
return m_executionCallback;
}
inline auto FramePass::GetInputs() const -> const std::vector<Input>&
{
return m_inputs;
}
inline auto FramePass::GetOutputs() const -> const std::vector<Output>&
{
return m_outputs;
}
inline std::size_t FramePass::GetPassId() const
{
return m_passId;
}
inline void FramePass::SetCommandCallback(CommandCallback callback)
{
m_commandCallback = std::move(callback);
}
inline void FramePass::SetClearColor(std::size_t outputIndex, const std::optional<Color>& color)
{
assert(outputIndex < m_outputs.size());
m_outputs[outputIndex].clearColor = color;
}
inline void FramePass::SetDepthStencilClear(float depth, UInt32 stencil)
{
auto& dsClear = m_depthStencilClear.emplace();
dsClear.depth = depth;
dsClear.stencil = stencil;
}
inline void FramePass::SetExecutionCallback(CommandCallback callback)
{
m_commandCallback = std::move(callback);
}
inline void FramePass::SetDepthStencilInput(std::size_t attachmentId)
{
m_depthStencilInput = attachmentId;
}
inline void FramePass::SetDepthStencilOutput(std::size_t attachmentId)
{
m_depthStencilOutput = attachmentId;
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FRAMEPASSATTACHMENT_HPP
#define NAZARA_FRAMEPASSATTACHMENT_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <string>
namespace Nz
{
struct FramePassAttachment
{
std::string name;
PixelFormat format;
};
}
#include <Nazara/Graphics/FramePassAttachment.inl>
#endif

View File

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

View File

@@ -55,7 +55,7 @@ namespace Nz
inline std::size_t GetPoolIndex() const;
inline const OpenGLCommandPool& GetOwner() const;
inline void SetFramebuffer(const OpenGLFramebuffer& framebuffer, const RenderPass& renderPass, std::initializer_list<CommandBufferBuilder::ClearValues> clearValues);
inline void SetFramebuffer(const OpenGLFramebuffer& framebuffer, const RenderPass& renderPass, const CommandBufferBuilder::ClearValues* clearValues, std::size_t clearValueCount);
inline void SetScissor(Nz::Recti scissorRegion);
inline void SetViewport(Nz::Recti viewportRegion);

View File

@@ -133,13 +133,13 @@ namespace Nz
return *m_owner;
}
inline void OpenGLCommandBuffer::SetFramebuffer(const OpenGLFramebuffer& framebuffer, const RenderPass& /*renderPass*/, std::initializer_list<CommandBufferBuilder::ClearValues> clearValues)
inline void OpenGLCommandBuffer::SetFramebuffer(const OpenGLFramebuffer& framebuffer, const RenderPass& /*renderPass*/, const CommandBufferBuilder::ClearValues* clearValues, std::size_t clearValueCount)
{
SetFrameBufferData setFramebuffer;
setFramebuffer.framebuffer = &framebuffer;
assert(clearValues.size() < setFramebuffer.clearValues.size());
std::copy(clearValues.begin(), clearValues.end(), setFramebuffer.clearValues.begin());
assert(clearValueCount < setFramebuffer.clearValues.size());
std::copy(clearValues, clearValues + clearValueCount, setFramebuffer.clearValues.begin());
m_commands.emplace_back(std::move(setFramebuffer));

View File

@@ -24,7 +24,7 @@ namespace Nz
~OpenGLCommandBufferBuilder() = default;
void BeginDebugRegion(const std::string_view& regionName, const Nz::Color& color) override;
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, Nz::Recti renderRect, std::initializer_list<ClearValues> clearValues) override;
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, Nz::Recti renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
void BindIndexBuffer(AbstractBuffer* indexBuffer, UInt64 offset = 0) override;
void BindPipeline(const RenderPipeline& pipeline) override;
@@ -40,12 +40,16 @@ namespace Nz
void EndDebugRegion() override;
void EndRenderPass() override;
void NextSubpass() override;
void PreTransferBarrier() override;
void PostTransferBarrier() override;
void SetScissor(Nz::Recti scissorRegion) override;
void SetViewport(Nz::Recti viewportRegion) override;
void TextureBarrier(PipelineStageFlags srcStageMask, PipelineStageFlags dstStageMask, MemoryAccessFlags srcAccessMask, MemoryAccessFlags dstAccessMask, TextureLayout oldLayout, TextureLayout newLayout, const Texture& texture) override;
OpenGLCommandBufferBuilder& operator=(const OpenGLCommandBufferBuilder&) = delete;
OpenGLCommandBufferBuilder& operator=(OpenGLCommandBufferBuilder&&) = delete;

View File

@@ -15,12 +15,12 @@ namespace Nz
// TODO: Fill this switch
switch (pixelFormat)
{
case PixelFormat_A8: return GLTextureFormat{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, GL_ZERO, GL_ZERO, GL_ZERO, GL_RED };
case PixelFormat_A8: return GLTextureFormat{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, GL_ZERO, GL_ZERO, GL_ZERO, GL_RED };
case PixelFormat_BGR8: return GLTextureFormat{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE };
case PixelFormat_BGR8_SRGB: return GLTextureFormat{ GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE };
case PixelFormat_BGRA8: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
case PixelFormat_BGRA8_SRGB: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
case PixelFormat_Depth24Stencil8: return GLTextureFormat{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_RED, GL_GREEN, GL_ZERO, GL_ZERO };
case PixelFormat_Depth24Stencil8: return GLTextureFormat{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_RED, GL_GREEN, GL_ZERO, GL_ZERO };
case PixelFormat_RGB8: return GLTextureFormat{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE };
case PixelFormat_RGB8_SRGB: return GLTextureFormat{ GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE };
case PixelFormat_RGBA8: return GLTextureFormat{ GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };

View File

@@ -11,6 +11,7 @@
#include <Nazara/Core/Color.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/RenderBufferView.hpp>
#include <Nazara/Renderer/UploadPool.hpp>
#include <string_view>
@@ -21,6 +22,7 @@ namespace Nz
class RenderPass;
class RenderPipeline;
class ShaderBinding;
class Texture;
class NAZARA_RENDERER_API CommandBufferBuilder
{
@@ -33,7 +35,9 @@ namespace Nz
virtual ~CommandBufferBuilder();
virtual void BeginDebugRegion(const std::string_view& regionName, const Nz::Color& color) = 0;
virtual void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, Nz::Recti renderRect, std::initializer_list<ClearValues> clearValues) = 0;
virtual void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, Nz::Recti renderRect, const ClearValues* clearValues, std::size_t clearValueCount) = 0;
inline void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, Nz::Recti renderRect);
inline void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, Nz::Recti renderRect, std::initializer_list<ClearValues> clearValues);
virtual void BindIndexBuffer(Nz::AbstractBuffer* indexBuffer, UInt64 offset = 0) = 0;
virtual void BindPipeline(const RenderPipeline& pipeline) = 0;
@@ -51,20 +55,24 @@ namespace Nz
virtual void EndDebugRegion() = 0;
virtual void EndRenderPass() = 0;
virtual void NextSubpass() = 0;
virtual void PreTransferBarrier() = 0;
virtual void PostTransferBarrier() = 0;
virtual void SetScissor(Nz::Recti scissorRegion) = 0;
virtual void SetViewport(Nz::Recti viewportRegion) = 0;
virtual void TextureBarrier(PipelineStageFlags srcStageMask, PipelineStageFlags dstStageMask, MemoryAccessFlags srcAccessMask, MemoryAccessFlags dstAccessMask, TextureLayout oldLayout, TextureLayout newLayout, const Texture& texture) = 0;
CommandBufferBuilder& operator=(const CommandBufferBuilder&) = delete;
CommandBufferBuilder& operator=(CommandBufferBuilder&&) = default;
struct ClearValues
{
Nz::Color color;
float depth;
UInt32 stencil;
Nz::Color color = Nz::Color::Black;
float depth = 1.f;
UInt32 stencil = 0;
};
};
}

View File

@@ -7,6 +7,16 @@
namespace Nz
{
inline void CommandBufferBuilder::BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, Nz::Recti renderRect)
{
return BeginRenderPass(framebuffer, renderPass, renderRect, nullptr, 0);
}
inline void CommandBufferBuilder::BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, Nz::Recti renderRect, std::initializer_list<ClearValues> clearValues)
{
return BeginRenderPass(framebuffer, renderPass, renderRect, clearValues.begin(), clearValues.size());
}
inline void CommandBufferBuilder::CopyBuffer(const RenderBufferView& from, const RenderBufferView& to)
{
return CopyBuffer(from, to, from.GetSize());

View File

@@ -33,7 +33,7 @@ namespace Nz
inline std::size_t GetAttachmentCount() const;
inline const std::vector<Attachment>& GetAttachments() const;
inline const std::vector<SubpassDescription>& GetSubpassDescriptions() const;
inline const std::vector<SubpassDependency>& GetsubpassDependencies() const;
inline const std::vector<SubpassDependency>& GetSubpassDependencies() const;
RenderPass& operator=(const RenderPass&) = delete;
RenderPass& operator=(RenderPass&&) noexcept = default;
@@ -60,6 +60,7 @@ namespace Nz
std::size_t fromSubpassIndex;
PipelineStageFlags fromStages;
MemoryAccessFlags fromAccessFlags;
std::size_t toSubpassIndex;
PipelineStageFlags toStages;
MemoryAccessFlags toAccessFlags;
@@ -70,6 +71,7 @@ namespace Nz
{
std::vector<AttachmentReference> colorAttachment;
std::vector<AttachmentReference> inputAttachments;
std::vector<std::size_t> preserveAttachments;
std::optional<AttachmentReference> depthStencilAttachment;
};

View File

@@ -36,7 +36,7 @@ namespace Nz
return m_subpassDescriptions;
}
inline auto RenderPass::GetsubpassDependencies() const -> const std::vector<SubpassDependency>&
inline auto RenderPass::GetSubpassDependencies() const -> const std::vector<SubpassDependency>&
{
return m_subpassDependencies;
}

View File

@@ -338,14 +338,14 @@ namespace Nz
{
switch (textureLayout)
{
case TextureLayout::ColorInput: return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
case TextureLayout::ColorOutput: return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
case TextureLayout::DepthStencilInput: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
case TextureLayout::DepthStencilOutput: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
case TextureLayout::Present: return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
case TextureLayout::TransferSource: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
case TextureLayout::TransferDestination: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
case TextureLayout::Undefined: return VK_IMAGE_LAYOUT_UNDEFINED;
case TextureLayout::ColorInput: return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
case TextureLayout::ColorOutput: return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
case TextureLayout::DepthStencilReadOnly: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
case TextureLayout::DepthStencilReadWrite: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
case TextureLayout::Present: return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
case TextureLayout::TransferSource: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
case TextureLayout::TransferDestination: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
case TextureLayout::Undefined: return VK_IMAGE_LAYOUT_UNDEFINED;
}
NazaraError("Unhandled TextureLayout 0x" + NumberToString(UnderlyingCast(textureLayout), 16));

View File

@@ -33,6 +33,10 @@ namespace Nz
inline Vk::CommandBuffer& VulkanCommandBuffer::GetCommandBuffer(std::size_t imageIndex)
{
if (m_commandBuffers.size() == 1)
return m_commandBuffers.front();
assert(imageIndex < m_commandBuffers.size());
return m_commandBuffers[imageIndex].Get();
}

View File

@@ -25,7 +25,7 @@ namespace Nz
~VulkanCommandBufferBuilder() = default;
void BeginDebugRegion(const std::string_view& regionName, const Nz::Color& color) override;
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, Nz::Recti renderRect, std::initializer_list<ClearValues> clearValues) override;
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, Nz::Recti renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
void BindIndexBuffer(AbstractBuffer* indexBuffer, UInt64 offset = 0) override;
void BindPipeline(const RenderPipeline& pipeline) override;
@@ -44,12 +44,16 @@ namespace Nz
inline Vk::CommandBuffer& GetCommandBuffer();
inline std::size_t GetMaxFramebufferCount() const;
void NextSubpass() override;
void PreTransferBarrier() override;
void PostTransferBarrier() override;
void SetScissor(Nz::Recti scissorRegion) override;
void SetViewport(Nz::Recti viewportRegion) override;
void TextureBarrier(PipelineStageFlags srcStageMask, PipelineStageFlags dstStageMask, MemoryAccessFlags srcAccessMask, MemoryAccessFlags dstAccessMask, TextureLayout oldLayout, TextureLayout newLayout, const Texture& texture) override;
VulkanCommandBufferBuilder& operator=(const VulkanCommandBufferBuilder&) = delete;
VulkanCommandBufferBuilder& operator=(VulkanCommandBufferBuilder&&) = delete;

View File

@@ -70,11 +70,15 @@ namespace Nz
inline CommandPool& GetPool();
inline void ImageBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout, VkImage image, VkImageAspectFlags aspectFlags);
inline void InsertDebugLabel(const char* label);
inline void InsertDebugLabel(const char* label, Nz::Color color);
inline void MemoryBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask);
inline void NextSubpass(VkSubpassContents contents = VK_SUBPASS_CONTENTS_INLINE);
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier);
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkMemoryBarrier& memoryBarrier);
inline void PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, UInt32 memoryBarrierCount, const VkMemoryBarrier* memoryBarriers, UInt32 bufferMemoryBarrierCount, const VkBufferMemoryBarrier* bufferMemoryBarriers, UInt32 imageMemoryBarrierCount, const VkImageMemoryBarrier* imageMemoryBarriers);

View File

@@ -295,6 +295,28 @@ namespace Nz
return *m_pool;
}
inline void CommandBuffer::ImageBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout, VkImage image, VkImageAspectFlags aspectFlags)
{
VkImageMemoryBarrier imageBarrier = {
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
nullptr,
srcAccessMask,
dstAccessMask,
oldLayout,
newLayout,
VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED,
image,
{
aspectFlags,
0, 1,
0, 1
}
};
return PipelineBarrier(srcStageMask, dstStageMask, dependencyFlags, imageBarrier);
}
inline void CommandBuffer::InsertDebugLabel(const char* label)
{
return InsertDebugLabel(label, Nz::Color(0, 0, 0, 0));
@@ -333,6 +355,11 @@ namespace Nz
return PipelineBarrier(srcStageMask, dstStageMask, 0U, memoryBarrier);
}
inline void CommandBuffer::NextSubpass(VkSubpassContents contents)
{
return m_pool->GetDevice()->vkCmdNextSubpass(m_handle, contents);
}
inline void CommandBuffer::PipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, const VkImageMemoryBarrier& imageMemoryBarrier)
{
return PipelineBarrier(srcStageMask, dstStageMask, dependencyFlags, 0, nullptr, 0, nullptr, 1, &imageMemoryBarrier);