Renderer/RenderPass: Implement RenderPass correctly

This commit is contained in:
Jérôme Leclercq
2021-02-15 18:14:47 +01:00
parent 3d84479d0e
commit d058a127e1
11 changed files with 543 additions and 133 deletions

View File

@@ -11,6 +11,96 @@
namespace Nz
{
enum class AttachmentLoadOp
{
Clear,
Discard,
Load
};
enum class AttachmentStoreOp
{
Discard,
Store
};
enum class MemoryAccess
{
ColorRead,
ColorWrite,
DepthStencilRead,
DepthStencilWrite,
IndexBufferRead,
IndirectCommandRead,
HostRead,
HostWrite,
MemoryRead,
MemoryWrite,
ShaderRead,
ShaderWrite,
TransferRead,
TransferWrite,
UniformBufferRead,
VertexBufferRead,
Max = VertexBufferRead
};
template<>
struct EnumAsFlags<MemoryAccess>
{
static constexpr MemoryAccess max = MemoryAccess::Max;
};
using MemoryAccessFlags = Flags<MemoryAccess>;
enum class PipelineStage
{
TopOfPipe,
ColorOutput,
DrawIndirect,
FragmentShader,
FragmentTestsEarly,
FragmentTestsLate,
GeometryShader,
TessellationControlShader,
TessellationEvaluationShader,
Transfer,
TransformFeedback,
VertexInput,
VertexShader,
BottomOfPipe,
Max = BottomOfPipe
};
template<>
struct EnumAsFlags<PipelineStage>
{
static constexpr PipelineStage max = PipelineStage::Max;
};
using PipelineStageFlags = Flags<PipelineStage>;
enum class QueueType
{
Compute,
Graphics,
Transfer,
Max = Transfer
};
template<>
struct EnumAsFlags<QueueType>
{
static constexpr QueueType max = QueueType::Max;
};
using QueueTypeFlags = Flags<QueueType>;
enum class RenderAPI
{
Direct3D, ///< Microsoft Render API, only works on MS platforms
@@ -53,22 +143,17 @@ namespace Nz
SpirV
};
enum class QueueType
enum class TextureLayout
{
Compute,
Graphics,
Transfer,
Max = Transfer
ColorInput,
ColorOutput,
DepthStencilInput,
DepthStencilOutput,
Present,
TransferSource,
TransferDestination,
Undefined
};
template<>
struct EnumAsFlags<QueueType>
{
static constexpr QueueType max = QueueType::Max;
};
using QueueTypeFlags = Flags<QueueType>;
}
#endif // NAZARA_ENUMS_RENDERER_HPP

View File

@@ -11,6 +11,9 @@
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <limits>
#include <optional>
#include <vector>
namespace Nz
{
@@ -18,20 +21,64 @@ namespace Nz
{
public:
struct Attachment;
struct SubpassDependency;
struct SubpassDescription;
RenderPass() = default;
inline RenderPass(std::vector<Attachment> attachments, std::vector<SubpassDescription> subpassDescriptions, std::vector<SubpassDependency> subpassDependencies);
RenderPass(const RenderPass&) = delete;
RenderPass(RenderPass&&) noexcept = default;
virtual ~RenderPass();
inline const Attachment& GetAttachment(std::size_t attachmentIndex) const;
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;
RenderPass& operator=(const RenderPass&) = delete;
RenderPass& operator=(RenderPass&&) noexcept = default;
struct Attachment
{
PixelFormat format;
// TODO
AttachmentLoadOp loadOp = AttachmentLoadOp::Load;
AttachmentLoadOp stencilLoadOp = AttachmentLoadOp::Load;
AttachmentStoreOp storeOp = AttachmentStoreOp::Store;
AttachmentStoreOp stencilStoreOp = AttachmentStoreOp::Store;
TextureLayout initialLayout = TextureLayout::Undefined;
TextureLayout finalLayout = TextureLayout::Present;
};
struct AttachmentReference
{
std::size_t attachmentIndex;
TextureLayout attachmentLayout = TextureLayout::ColorInput;
};
struct SubpassDependency
{
std::size_t fromSubpassIndex;
PipelineStageFlags fromStages;
MemoryAccessFlags fromAccessFlags;
std::size_t toSubpassIndex;
PipelineStageFlags toStages;
MemoryAccessFlags toAccessFlags;
bool tilable = false;
};
struct SubpassDescription
{
std::vector<AttachmentReference> colorAttachment;
std::vector<AttachmentReference> inputAttachments;
std::optional<AttachmentReference> depthStencilAttachment;
};
static constexpr std::size_t ExternalSubpassIndex = std::numeric_limits<std::size_t>::max();
protected:
std::vector<Attachment> m_attachments;
std::vector<SubpassDependency> m_subpassDependencies;
std::vector<SubpassDescription> m_subpassDescriptions;
};
}

View File

@@ -3,10 +3,43 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/RenderPass.hpp>
#include <cassert>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
inline RenderPass::RenderPass(std::vector<Attachment> attachments, std::vector<SubpassDescription> subpassDescriptions, std::vector<SubpassDependency> subpassDependencies) :
m_attachments(std::move(attachments)),
m_subpassDescriptions(std::move(subpassDescriptions)),
m_subpassDependencies(std::move(subpassDependencies))
{
}
inline auto Nz::RenderPass::GetAttachment(std::size_t attachmentIndex) const -> const Attachment&
{
assert(attachmentIndex < m_attachments.size());
return m_attachments[attachmentIndex];
}
inline std::size_t RenderPass::GetAttachmentCount() const
{
return m_attachments.size();
}
inline auto RenderPass::GetAttachments() const -> const std::vector<Attachment>&
{
return m_attachments;
}
inline auto RenderPass::GetSubpassDescriptions() const -> const std::vector<SubpassDescription>&
{
return m_subpassDescriptions;
}
inline auto RenderPass::GetsubpassDependencies() const -> const std::vector<SubpassDependency>&
{
return m_subpassDependencies;
}
}
#include <Nazara/Renderer/DebugOff.hpp>