Files
XCEngine/engine/src/Rendering/Graph/RenderGraph.cpp

121 lines
3.5 KiB
C++
Raw Normal View History

#include <XCEngine/Rendering/Graph/RenderGraph.h>
#include <utility>
namespace XCEngine {
namespace Rendering {
void RenderGraph::Reset() {
m_textures.clear();
m_passes.clear();
}
RenderGraphPassBuilder::RenderGraphPassBuilder(
RenderGraph* graph,
RenderGraphPassHandle passHandle)
: m_graph(graph)
, m_passHandle(passHandle) {
}
void RenderGraphPassBuilder::ReadTexture(RenderGraphTextureHandle texture) {
if (m_graph == nullptr || !m_passHandle.IsValid()) {
return;
}
RenderGraph::TextureAccess access = {};
access.texture = texture;
access.mode = RenderGraphAccessMode::Read;
m_graph->m_passes[m_passHandle.index].accesses.push_back(access);
}
void RenderGraphPassBuilder::WriteTexture(RenderGraphTextureHandle texture) {
if (m_graph == nullptr || !m_passHandle.IsValid()) {
return;
}
RenderGraph::TextureAccess access = {};
access.texture = texture;
access.mode = RenderGraphAccessMode::Write;
m_graph->m_passes[m_passHandle.index].accesses.push_back(access);
}
void RenderGraphPassBuilder::SetExecuteCallback(RenderGraphExecuteCallback callback) {
if (m_graph == nullptr || !m_passHandle.IsValid()) {
return;
}
m_graph->m_passes[m_passHandle.index].executeCallback = std::move(callback);
}
void RenderGraphBuilder::Reset() {
m_graph.Reset();
}
RenderGraphTextureHandle RenderGraphBuilder::ImportTexture(
const Containers::String& name,
const RenderGraphTextureDesc& desc,
RHI::RHIResourceView* importedView,
const RenderGraphImportedTextureOptions& importedOptions) {
RenderGraph::TextureResource resource = {};
resource.name = name;
resource.desc = desc;
resource.kind = RenderGraphTextureKind::Imported;
resource.importedView = importedView;
resource.importedOptions = importedOptions;
m_graph.m_textures.push_back(resource);
RenderGraphTextureHandle handle = {};
handle.index = static_cast<Core::uint32>(m_graph.m_textures.size() - 1u);
return handle;
}
RenderGraphTextureHandle RenderGraphBuilder::CreateTransientTexture(
const Containers::String& name,
const RenderGraphTextureDesc& desc) {
RenderGraph::TextureResource resource = {};
resource.name = name;
resource.desc = desc;
resource.kind = RenderGraphTextureKind::Transient;
resource.importedView = nullptr;
m_graph.m_textures.push_back(resource);
RenderGraphTextureHandle handle = {};
handle.index = static_cast<Core::uint32>(m_graph.m_textures.size() - 1u);
return handle;
}
RenderGraphPassHandle RenderGraphBuilder::AddRasterPass(
const Containers::String& name,
const std::function<void(RenderGraphPassBuilder&)>& setup) {
return AddPass(name, RenderGraphPassType::Raster, setup);
}
RenderGraphPassHandle RenderGraphBuilder::AddComputePass(
const Containers::String& name,
const std::function<void(RenderGraphPassBuilder&)>& setup) {
return AddPass(name, RenderGraphPassType::Compute, setup);
}
RenderGraphPassHandle RenderGraphBuilder::AddPass(
const Containers::String& name,
RenderGraphPassType type,
const std::function<void(RenderGraphPassBuilder&)>& setup) {
RenderGraph::PassNode pass = {};
pass.name = name;
pass.type = type;
m_graph.m_passes.push_back(pass);
RenderGraphPassHandle handle = {};
handle.index = static_cast<Core::uint32>(m_graph.m_passes.size() - 1u);
if (setup) {
RenderGraphPassBuilder passBuilder(&m_graph, handle);
setup(passBuilder);
}
return handle;
}
} // namespace Rendering
} // namespace XCEngine