Graphics/FrameGraph: Add support for cubemap and slice rendering

This commit is contained in:
SirLynix
2022-12-02 23:00:44 +01:00
committed by Jérôme Leclercq
parent 4ae3f51174
commit 5a57976b4b
6 changed files with 229 additions and 61 deletions

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/FrameGraphStructs.hpp>
#include <Nazara/Graphics/FramePass.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
@@ -81,15 +82,10 @@ namespace Nz
bool forceCommandBufferRegeneration = true;
};
struct TextureData
struct TextureData : FrameGraphTextureData
{
std::string name;
std::shared_ptr<Texture> texture;
FramePassAttachmentSize size;
PixelFormat format;
TextureUsageFlags usage;
unsigned int width;
unsigned int height;
};
std::shared_ptr<CommandPool> m_commandPool;

View File

@@ -10,6 +10,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/BakedFrameGraph.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/FrameGraphStructs.hpp>
#include <Nazara/Graphics/FramePass.hpp>
#include <Nazara/Graphics/FramePassAttachment.hpp>
#include <Nazara/Renderer/Enums.hpp>
@@ -32,6 +33,8 @@ namespace Nz
~FrameGraph() = default;
inline std::size_t AddAttachment(FramePassAttachment attachment);
inline std::size_t AddAttachmentCube(FramePassAttachment attachment);
inline std::size_t AddAttachmentCubeFace(std::size_t attachmentId, CubemapFace face);
inline std::size_t AddAttachmentProxy(std::string name, std::size_t attachmentId);
inline void AddBackbufferOutput(std::size_t backbufferOutput);
inline FramePass& AddPass(std::string name);
@@ -52,6 +55,16 @@ namespace Nz
using PassIdToPhysicalPassIndex = std::unordered_map<std::size_t /*passId*/, std::size_t /*physicalPassId*/>;
using TextureBarrier = BakedFrameGraph::TextureBarrier;
struct AttachmentCube : FramePassAttachment
{
};
struct AttachmentLayer
{
std::size_t attachmentId;
std::size_t layerIndex;
};
struct AttachmentProxy
{
std::size_t attachmentId;
@@ -84,22 +97,13 @@ namespace Nz
std::vector<Subpass> passes;
};
struct TextureData
{
std::string name;
PixelFormat format;
FramePassAttachmentSize size;
TextureUsageFlags usage;
unsigned int width;
unsigned int height;
};
struct WorkData
{
std::vector<std::shared_ptr<RenderPass>> renderPasses;
std::vector<PhysicalPassData> physicalPasses;
std::vector<TextureData> textures;
std::vector<std::size_t> texturePool;
std::vector<FrameGraphTextureData> textures;
std::vector<std::size_t> texture2DPool;
std::vector<std::size_t> textureCubePool;
AttachmentIdToPassId attachmentLastUse;
AttachmentIdToPassMap attachmentReadList;
AttachmentIdToPassMap attachmentWriteList;
@@ -123,9 +127,11 @@ namespace Nz
void ReorderPasses();
void TraverseGraph(std::size_t passIndex);
using AttachmentType = std::variant<FramePassAttachment, AttachmentProxy, AttachmentCube, AttachmentLayer>;
std::vector<std::size_t> m_backbufferOutputs;
std::vector<FramePass> m_framePasses;
std::vector<std::variant<FramePassAttachment, AttachmentProxy>> m_attachments;
std::vector<AttachmentType> m_attachments;
WorkData m_pending;
};
}

View File

@@ -16,10 +16,32 @@ namespace Nz
return id;
}
inline std::size_t FrameGraph::AddAttachmentCube(FramePassAttachment attachment)
{
std::size_t id = m_attachments.size();
m_attachments.emplace_back(AttachmentCube{ std::move(attachment) });
return id;
}
inline std::size_t FrameGraph::AddAttachmentCubeFace(std::size_t attachmentId, CubemapFace face)
{
attachmentId = ResolveAttachmentIndex(attachmentId);
assert(std::holds_alternative<AttachmentCube>(m_attachments[attachmentId]));
std::size_t id = m_attachments.size();
m_attachments.emplace_back(AttachmentLayer{
attachmentId,
SafeCast<std::size_t>(face)
});
return id;
}
inline std::size_t FrameGraph::AddAttachmentProxy(std::string name, std::size_t attachmentId)
{
assert(attachmentId < m_attachments.size());
assert(std::holds_alternative<FramePassAttachment>(m_attachments[attachmentId]));
std::size_t id = m_attachments.size();
m_attachments.emplace_back(AttachmentProxy {

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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_GRAPHICS_FRAMEGRAPHSTRUCTS_HPP
#define NAZARA_GRAPHICS_FRAMEGRAPHSTRUCTS_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/FramePassAttachment.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <optional>
#include <string>
namespace Nz
{
struct FrameGraphTextureData
{
struct ViewData
{
std::size_t parentTextureId;
std::size_t arrayLayer;
};
std::optional<ViewData> viewData;
std::string name;
ImageType type;
PixelFormat format;
FramePassAttachmentSize size;
TextureUsageFlags usage;
unsigned int width;
unsigned int height;
};
}
#endif // NAZARA_GRAPHICS_FRAMEGRAPHSTRUCTS_HPP