Files
XCEngine/engine/include/XCEngine/Rendering/Graph/RenderGraph.h

122 lines
3.4 KiB
C++

#pragma once
#include <XCEngine/Rendering/Graph/RenderGraphTypes.h>
#include <XCEngine/RHI/RHIResourceView.h>
#include <functional>
#include <vector>
namespace XCEngine {
namespace Rendering {
class RenderGraphPassBuilder;
class RenderGraphBuilder;
class RenderGraphCompiler;
class RenderGraphExecutor;
class RenderGraph {
public:
void Reset();
size_t GetTextureCount() const {
return m_textures.size();
}
size_t GetPassCount() const {
return m_passes.size();
}
private:
struct TextureResource {
Containers::String name;
RenderGraphTextureDesc desc = {};
RenderGraphTextureKind kind = RenderGraphTextureKind::Transient;
RHI::RHIResourceView* importedView = nullptr;
RHI::RHITexture* importedTexture = nullptr;
RenderGraphImportedTextureOptions importedOptions = {};
};
struct TextureAccess {
RenderGraphTextureHandle texture = {};
RenderGraphAccessMode mode = RenderGraphAccessMode::Read;
RenderGraphTextureAspect aspect = RenderGraphTextureAspect::Color;
};
struct PassNode {
Containers::String name;
RenderGraphPassType type = RenderGraphPassType::Raster;
std::vector<TextureAccess> accesses;
RenderGraphExecuteCallback executeCallback = {};
};
std::vector<TextureResource> m_textures;
std::vector<PassNode> m_passes;
friend class RenderGraphBuilder;
friend class RenderGraphPassBuilder;
friend class RenderGraphCompiler;
friend class RenderGraphExecutor;
};
class RenderGraphPassBuilder {
public:
void ReadTexture(RenderGraphTextureHandle texture);
void WriteTexture(RenderGraphTextureHandle texture);
void ReadDepthTexture(RenderGraphTextureHandle texture);
void WriteDepthTexture(RenderGraphTextureHandle texture);
void SetExecuteCallback(RenderGraphExecuteCallback callback);
private:
RenderGraphPassBuilder(RenderGraph* graph, RenderGraphPassHandle passHandle);
RenderGraph* m_graph = nullptr;
RenderGraphPassHandle m_passHandle = {};
friend class RenderGraphBuilder;
};
class RenderGraphBuilder {
public:
explicit RenderGraphBuilder(RenderGraph& graph)
: m_graph(graph) {
}
void Reset();
RenderGraphTextureHandle ImportTexture(
const Containers::String& name,
const RenderGraphImportedTextureDesc& importedDesc);
RenderGraphTextureHandle ImportTexture(
const Containers::String& name,
const RenderGraphTextureDesc& desc,
RHI::RHIResourceView* importedView = nullptr,
const RenderGraphImportedTextureOptions& importedOptions = {});
void MergeImportedTextureOptions(
RenderGraphTextureHandle handle,
const RenderGraphImportedTextureOptions& importedOptions);
RenderGraphTextureHandle CreateTransientTexture(
const Containers::String& name,
const RenderGraphTextureDesc& desc);
RenderGraphPassHandle AddRasterPass(
const Containers::String& name,
const std::function<void(RenderGraphPassBuilder&)>& setup);
RenderGraphPassHandle AddComputePass(
const Containers::String& name,
const std::function<void(RenderGraphPassBuilder&)>& setup);
private:
RenderGraphPassHandle AddPass(
const Containers::String& name,
RenderGraphPassType type,
const std::function<void(RenderGraphPassBuilder&)>& setup);
RenderGraph& m_graph;
};
} // namespace Rendering
} // namespace XCEngine