mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
902 lines
35 KiB
C++
902 lines
35 KiB
C++
/****************************************************************************
|
|
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
|
|
|
https://www.cocos.com/
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights to
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
****************************************************************************/
|
|
|
|
#include <boost/graph/depth_first_search.hpp>
|
|
#include <boost/graph/filtered_graph.hpp>
|
|
#include "LayoutGraphGraphs.h"
|
|
#include "NativePipelineGraphs.h"
|
|
#include "NativePipelineTypes.h"
|
|
#include "RenderCommonNames.h"
|
|
#include "RenderGraphGraphs.h"
|
|
#include "details/DebugUtils.h"
|
|
#include "details/GraphView.h"
|
|
#include "gfx-base/GFXDef-common.h"
|
|
#include "pipeline/custom/RenderCommonTypes.h"
|
|
#include "pipeline/custom/RenderGraphFwd.h"
|
|
#include "pipeline/custom/RenderGraphTypes.h"
|
|
|
|
namespace cc {
|
|
|
|
namespace render {
|
|
|
|
ccstd::string NativeRasterPassBuilder::getName() const {
|
|
return std::string(get(RenderGraph::Name, *renderGraph, passID));
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setName(const ccstd::string &name) {
|
|
get(RenderGraph::Name, *renderGraph, passID) = std::string_view{name};
|
|
}
|
|
|
|
void NativeRasterPassBuilder::addRasterView(const ccstd::string &name, const RasterView &view) {
|
|
auto &pass = get(RasterTag{}, passID, *renderGraph);
|
|
pass.rasterViews.emplace(
|
|
std::piecewise_construct,
|
|
std::forward_as_tuple(name.c_str()),
|
|
std::forward_as_tuple(view));
|
|
}
|
|
|
|
void NativeRasterPassBuilder::addComputeView(const ccstd::string &name, const ComputeView &view) {
|
|
auto &pass = get(RasterTag{}, passID, *renderGraph);
|
|
auto iter = pass.computeViews.find(name.c_str());
|
|
if (iter == pass.computeViews.end()) {
|
|
bool added = false;
|
|
std::tie(iter, added) = pass.computeViews.emplace(
|
|
std::piecewise_construct,
|
|
std::forward_as_tuple(name.c_str()),
|
|
std::forward_as_tuple());
|
|
CC_ENSURES(added);
|
|
}
|
|
iter->second.emplace_back(view);
|
|
}
|
|
|
|
ccstd::string NativeRasterQueueBuilder::getName() const {
|
|
return std::string(get(RenderGraph::Name, *renderGraph, queueID));
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setName(const ccstd::string &name) {
|
|
get(RenderGraph::Name, *renderGraph, queueID) = std::string_view{name};
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::addSceneOfCamera(scene::Camera *camera, LightInfo light, SceneFlags sceneFlags) {
|
|
std::string_view name = "Camera";
|
|
SceneData scene(renderGraph->get_allocator());
|
|
scene.name = name;
|
|
scene.flags = sceneFlags;
|
|
scene.camera = camera;
|
|
scene.light = std::move(light);
|
|
auto sceneID = addVertex(
|
|
SceneTag{},
|
|
std::forward_as_tuple(name),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(std::move(scene)),
|
|
*renderGraph, queueID);
|
|
CC_ENSURES(sceneID != RenderGraph::null_vertex());
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::addScene(const ccstd::string &name, SceneFlags sceneFlags) {
|
|
SceneData scene(renderGraph->get_allocator());
|
|
scene.name = name;
|
|
scene.flags = sceneFlags;
|
|
|
|
auto sceneID = addVertex(
|
|
SceneTag{},
|
|
std::forward_as_tuple(name.c_str()),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(std::move(scene)),
|
|
*renderGraph, queueID);
|
|
CC_ENSURES(sceneID != RenderGraph::null_vertex());
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::addFullscreenQuad(
|
|
Material *material, uint32_t passID, SceneFlags sceneFlags) {
|
|
std::string_view name = "FullscreenQuad";
|
|
auto drawID = addVertex(
|
|
BlitTag{},
|
|
std::forward_as_tuple(name),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(material, passID, sceneFlags, nullptr),
|
|
*renderGraph, queueID);
|
|
CC_ENSURES(drawID != RenderGraph::null_vertex());
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::addCameraQuad(
|
|
scene::Camera *camera, cc::Material *material, uint32_t passID,
|
|
SceneFlags sceneFlags) {
|
|
std::string_view name = "CameraQuad";
|
|
auto drawID = addVertex(
|
|
BlitTag{},
|
|
std::forward_as_tuple(name),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(material, passID, sceneFlags, camera),
|
|
*renderGraph, queueID);
|
|
CC_ENSURES(drawID != RenderGraph::null_vertex());
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::clearRenderTarget(const ccstd::string &name, const gfx::Color &color) {
|
|
ccstd::pmr::vector<ClearView> clears(renderGraph->get_allocator());
|
|
clears.emplace_back(name.c_str(), gfx::ClearFlagBit::COLOR, color);
|
|
|
|
auto clearID = addVertex(
|
|
ClearTag{},
|
|
std::forward_as_tuple("ClearRenderTarget"),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(std::move(clears)),
|
|
*renderGraph, queueID);
|
|
CC_ENSURES(clearID != RenderGraph::null_vertex());
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setViewport(const gfx::Viewport &viewport) {
|
|
auto viewportID = addVertex(
|
|
ViewportTag{},
|
|
std::forward_as_tuple("Viewport"),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(viewport),
|
|
*renderGraph, queueID);
|
|
CC_ENSURES(viewportID != RenderGraph::null_vertex());
|
|
}
|
|
|
|
namespace {
|
|
|
|
render::NameLocalID getNameID(
|
|
const PmrFlatMap<ccstd::pmr::string, render::NameLocalID> &index,
|
|
std::string_view name) {
|
|
auto iter = index.find(name);
|
|
CC_EXPECTS(iter != index.end());
|
|
return iter->second;
|
|
}
|
|
|
|
void addMat4(
|
|
const LayoutGraphData &lg, std::string_view name,
|
|
const cc::Mat4 &v, RenderData &data) {
|
|
auto nameID = getNameID(lg.constantIndex, name);
|
|
static_assert(sizeof(Mat4) == 16 * 4, "sizeof(Mat4) is not 64 bytes");
|
|
data.constants[nameID.value].resize(sizeof(Mat4));
|
|
memcpy(data.constants[nameID.value].data(), v.m, sizeof(v));
|
|
}
|
|
|
|
void addQuaternion(const LayoutGraphData &lg, const ccstd::string &name, const Quaternion &quat, RenderData &data) {
|
|
auto nameID = getNameID(lg.constantIndex, name);
|
|
static_assert(sizeof(Quaternion) == 4 * 4, "sizeof(Quaternion) is not 16 bytes");
|
|
static_assert(std::is_trivially_copyable<Quaternion>::value, "Quaternion is not trivially copyable");
|
|
data.constants[nameID.value].resize(sizeof(Quaternion));
|
|
memcpy(data.constants[nameID.value].data(), &quat, sizeof(quat));
|
|
}
|
|
|
|
void addColor(const LayoutGraphData &lg, const ccstd::string &name, const gfx::Color &color, RenderData &data) {
|
|
auto nameID = getNameID(lg.constantIndex, name);
|
|
static_assert(sizeof(gfx::Color) == 4 * 4, "sizeof(Color) is not 16 bytes");
|
|
static_assert(std::is_trivially_copyable<gfx::Color>::value, "Color is not trivially copyable");
|
|
data.constants[nameID.value].resize(sizeof(gfx::Color));
|
|
memcpy(data.constants[nameID.value].data(), &color, sizeof(color));
|
|
}
|
|
|
|
void addVec4(const LayoutGraphData &lg, const ccstd::string &name, const Vec4 &vec, RenderData &data) {
|
|
auto nameID = getNameID(lg.constantIndex, name);
|
|
static_assert(sizeof(Vec4) == 4 * 4, "sizeof(Vec4) is not 16 bytes");
|
|
// static_assert(std::is_trivially_copyable<Vec4>::value, "Vec4 is not trivially copyable");
|
|
data.constants[nameID.value].resize(sizeof(Vec4));
|
|
memcpy(data.constants[nameID.value].data(), &vec.x, sizeof(vec));
|
|
}
|
|
|
|
void addVec2(const LayoutGraphData &lg, const ccstd::string &name, const Vec2 &vec, RenderData &data) {
|
|
auto nameID = getNameID(lg.constantIndex, name);
|
|
static_assert(sizeof(Vec2) == 2 * 4, "sizeof(Vec2) is not 8 bytes");
|
|
// static_assert(std::is_trivially_copyable<Vec4>::value, "Vec2 is not trivially copyable");
|
|
data.constants[nameID.value].resize(sizeof(Vec2));
|
|
memcpy(data.constants[nameID.value].data(), &vec.x, sizeof(vec));
|
|
}
|
|
|
|
void addFloat(const LayoutGraphData &lg, const ccstd::string &name, float v, RenderData &data) {
|
|
auto nameID = getNameID(lg.constantIndex, name);
|
|
static_assert(sizeof(float) == 4, "sizeof(float) is not 4 bytes");
|
|
data.constants[nameID.value].resize(sizeof(float));
|
|
memcpy(data.constants[nameID.value].data(), &v, sizeof(v));
|
|
}
|
|
|
|
void addBuffer(const LayoutGraphData &lg, const ccstd::string &name, gfx::Buffer *buffer, RenderData &data) {
|
|
auto nameID = getNameID(lg.attributeIndex, name);
|
|
data.buffers[nameID.value] = IntrusivePtr<gfx::Buffer>(buffer);
|
|
}
|
|
|
|
void addTexture(const LayoutGraphData &lg, const ccstd::string &name, gfx::Texture *texture, RenderData &data) {
|
|
auto nameID = getNameID(lg.attributeIndex, name);
|
|
data.textures[nameID.value] = IntrusivePtr<gfx::Texture>(texture);
|
|
}
|
|
|
|
void addReadWriteBuffer(const LayoutGraphData &lg, const ccstd::string &name, gfx::Buffer *buffer, RenderData &data) {
|
|
auto nameID = getNameID(lg.attributeIndex, name);
|
|
data.buffers[nameID.value] = IntrusivePtr<gfx::Buffer>(buffer);
|
|
}
|
|
|
|
void addReadWriteTexture(const LayoutGraphData &lg, const ccstd::string &name, gfx::Texture *texture, RenderData &data) {
|
|
auto nameID = getNameID(lg.attributeIndex, name);
|
|
data.textures[nameID.value] = IntrusivePtr<gfx::Texture>(texture);
|
|
}
|
|
|
|
void addSampler(const LayoutGraphData &lg, const ccstd::string &name, gfx::Sampler *sampler, RenderData &data) {
|
|
auto nameID = getNameID(lg.attributeIndex, name);
|
|
data.samplers[nameID.value].ptr = sampler;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void NativeRasterQueueBuilder::setMat4(const ccstd::string &name, const Mat4 &mat) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addMat4(*layoutGraph, name, mat, data);
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setQuaternion(const ccstd::string &name, const Quaternion &quat) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addQuaternion(*layoutGraph, name, quat, data);
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setColor(const ccstd::string &name, const gfx::Color &color) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addColor(*layoutGraph, name, color, data);
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setVec4(const ccstd::string &name, const Vec4 &vec) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addVec4(*layoutGraph, name, vec, data);
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setVec2(const ccstd::string &name, const Vec2 &vec) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addVec2(*layoutGraph, name, vec, data);
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setFloat(const ccstd::string &name, float v) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addFloat(*layoutGraph, name, v, data);
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setBuffer(const ccstd::string &name, gfx::Buffer *buffer) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addBuffer(*layoutGraph, name, buffer, data);
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setTexture(const ccstd::string &name, gfx::Texture *texture) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addTexture(*layoutGraph, name, texture, data);
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setReadWriteBuffer(const ccstd::string &name, gfx::Buffer *buffer) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addReadWriteBuffer(*layoutGraph, name, buffer, data);
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setReadWriteTexture(const ccstd::string &name, gfx::Texture *texture) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addReadWriteTexture(*layoutGraph, name, texture, data);
|
|
}
|
|
|
|
void NativeRasterQueueBuilder::setSampler(const ccstd::string &name, gfx::Sampler *sampler) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addSampler(*layoutGraph, name, sampler, data);
|
|
}
|
|
|
|
RasterQueueBuilder *NativeRasterPassBuilder::addQueue(QueueHint hint) {
|
|
std::string_view name = "Queue";
|
|
auto queueID = addVertex(
|
|
QueueTag{},
|
|
std::forward_as_tuple(name),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(hint),
|
|
*renderGraph, passID);
|
|
|
|
return new NativeRasterQueueBuilder(renderGraph, queueID, layoutGraph);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setViewport(const gfx::Viewport &viewport) {
|
|
auto &pass = get(RasterTag{}, passID, *renderGraph);
|
|
pass.viewport = viewport;
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setMat4(const ccstd::string &name, const Mat4 &mat) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addMat4(*layoutGraph, name, mat, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setQuaternion(const ccstd::string &name, const Quaternion &quat) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addQuaternion(*layoutGraph, name, quat, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setColor(const ccstd::string &name, const gfx::Color &color) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addColor(*layoutGraph, name, color, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setVec4(const ccstd::string &name, const Vec4 &vec) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addVec4(*layoutGraph, name, vec, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setVec2(const ccstd::string &name, const Vec2 &vec) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addVec2(*layoutGraph, name, vec, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setFloat(const ccstd::string &name, float v) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addFloat(*layoutGraph, name, v, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setBuffer(const ccstd::string &name, gfx::Buffer *buffer) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addBuffer(*layoutGraph, name, buffer, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setTexture(const ccstd::string &name, gfx::Texture *texture) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addTexture(*layoutGraph, name, texture, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setReadWriteBuffer(const ccstd::string &name, gfx::Buffer *buffer) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addReadWriteBuffer(*layoutGraph, name, buffer, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setReadWriteTexture(const ccstd::string &name, gfx::Texture *texture) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addReadWriteTexture(*layoutGraph, name, texture, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setSampler(const ccstd::string &name, gfx::Sampler *sampler) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addSampler(*layoutGraph, name, sampler, data);
|
|
}
|
|
|
|
void NativeRasterPassBuilder::setVersion(const ccstd::string &name, uint64_t version) {
|
|
// noop
|
|
}
|
|
|
|
// NativeComputeQueue
|
|
ccstd::string NativeComputeQueueBuilder::getName() const {
|
|
return std::string(get(RenderGraph::Name, *renderGraph, queueID));
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setName(const ccstd::string &name) {
|
|
get(RenderGraph::Name, *renderGraph, queueID) = std::string_view{name};
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::addDispatch(const ccstd::string &shader, uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCountZ) {
|
|
std::string_view name("Dispatch");
|
|
addVertex(
|
|
DispatchTag{},
|
|
std::forward_as_tuple(name),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(
|
|
shader.c_str(),
|
|
threadGroupCountX,
|
|
threadGroupCountY,
|
|
threadGroupCountZ),
|
|
*renderGraph);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setMat4(const ccstd::string &name, const Mat4 &mat) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addMat4(*layoutGraph, name, mat, data);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setQuaternion(const ccstd::string &name, const Quaternion &quat) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addQuaternion(*layoutGraph, name, quat, data);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setColor(const ccstd::string &name, const gfx::Color &color) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addColor(*layoutGraph, name, color, data);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setVec4(const ccstd::string &name, const Vec4 &vec) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addVec4(*layoutGraph, name, vec, data);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setVec2(const ccstd::string &name, const Vec2 &vec) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addVec2(*layoutGraph, name, vec, data);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setFloat(const ccstd::string &name, float v) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addFloat(*layoutGraph, name, v, data);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setBuffer(const ccstd::string &name, gfx::Buffer *buffer) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addBuffer(*layoutGraph, name, buffer, data);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setTexture(const ccstd::string &name, gfx::Texture *texture) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addTexture(*layoutGraph, name, texture, data);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setReadWriteBuffer(const ccstd::string &name, gfx::Buffer *buffer) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addReadWriteBuffer(*layoutGraph, name, buffer, data);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setReadWriteTexture(const ccstd::string &name, gfx::Texture *texture) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addReadWriteTexture(*layoutGraph, name, texture, data);
|
|
}
|
|
|
|
void NativeComputeQueueBuilder::setSampler(const ccstd::string &name, gfx::Sampler *sampler) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, queueID);
|
|
addSampler(*layoutGraph, name, sampler, data);
|
|
}
|
|
|
|
ccstd::string NativeComputePassBuilder::getName() const {
|
|
return std::string(get(RenderGraph::Name, *renderGraph, passID));
|
|
}
|
|
|
|
void NativeComputePassBuilder::setName(const ccstd::string &name) {
|
|
get(RenderGraph::Name, *renderGraph, passID) = std::string_view{name};
|
|
}
|
|
|
|
void NativeComputePassBuilder::addComputeView(const ccstd::string &name, const ComputeView &view) {
|
|
auto &pass = get(ComputeTag{}, passID, *renderGraph);
|
|
auto iter = pass.computeViews.find(name.c_str());
|
|
if (iter == pass.computeViews.end()) {
|
|
bool added = false;
|
|
std::tie(iter, added) = pass.computeViews.emplace(
|
|
std::piecewise_construct,
|
|
std::forward_as_tuple(name.c_str()),
|
|
std::forward_as_tuple());
|
|
CC_ENSURES(added);
|
|
}
|
|
iter->second.emplace_back(view);
|
|
}
|
|
|
|
ComputeQueueBuilder *NativeComputePassBuilder::addQueue() {
|
|
std::string_view name("Queue");
|
|
auto queueID = addVertex(
|
|
QueueTag{},
|
|
std::forward_as_tuple(name),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(),
|
|
std::forward_as_tuple(QueueHint::NONE),
|
|
*renderGraph, passID);
|
|
|
|
return new NativeComputeQueueBuilder(renderGraph, queueID, layoutGraph);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setMat4(const ccstd::string &name, const Mat4 &mat) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addMat4(*layoutGraph, name, mat, data);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setQuaternion(const ccstd::string &name, const Quaternion &quat) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addQuaternion(*layoutGraph, name, quat, data);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setColor(const ccstd::string &name, const gfx::Color &color) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addColor(*layoutGraph, name, color, data);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setVec4(const ccstd::string &name, const Vec4 &vec) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addVec4(*layoutGraph, name, vec, data);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setVec2(const ccstd::string &name, const Vec2 &vec) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addVec2(*layoutGraph, name, vec, data);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setFloat(const ccstd::string &name, float v) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addFloat(*layoutGraph, name, v, data);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setBuffer(const ccstd::string &name, gfx::Buffer *buffer) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addBuffer(*layoutGraph, name, buffer, data);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setTexture(const ccstd::string &name, gfx::Texture *texture) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addTexture(*layoutGraph, name, texture, data);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setReadWriteBuffer(const ccstd::string &name, gfx::Buffer *buffer) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addReadWriteBuffer(*layoutGraph, name, buffer, data);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setReadWriteTexture(const ccstd::string &name, gfx::Texture *texture) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addReadWriteTexture(*layoutGraph, name, texture, data);
|
|
}
|
|
|
|
void NativeComputePassBuilder::setSampler(const ccstd::string &name, gfx::Sampler *sampler) {
|
|
auto &data = get(RenderGraph::Data, *renderGraph, passID);
|
|
addSampler(*layoutGraph, name, sampler, data);
|
|
}
|
|
|
|
ccstd::string NativeMovePassBuilder::getName() const {
|
|
return std::string(get(RenderGraph::Name, *renderGraph, passID));
|
|
}
|
|
|
|
void NativeMovePassBuilder::setName(const ccstd::string &name) {
|
|
get(RenderGraph::Name, *renderGraph, passID) = std::string_view{name};
|
|
}
|
|
|
|
void NativeMovePassBuilder::addPair(const MovePair &pair) {
|
|
auto &movePass = get(MoveTag{}, passID, *renderGraph);
|
|
movePass.movePairs.emplace_back(pair);
|
|
}
|
|
|
|
ccstd::string NativeCopyPassBuilder::getName() const {
|
|
return std::string(get(RenderGraph::Name, *renderGraph, passID));
|
|
}
|
|
|
|
void NativeCopyPassBuilder::setName(const ccstd::string &name) {
|
|
get(RenderGraph::Name, *renderGraph, passID) = std::string_view{name};
|
|
}
|
|
|
|
void NativeCopyPassBuilder::addPair(const CopyPair &pair) {
|
|
auto ©Pass = get(CopyTag{}, passID, *renderGraph);
|
|
copyPass.copyPairs.emplace_back(pair);
|
|
}
|
|
|
|
namespace {
|
|
|
|
const char *getName(const gfx::LoadOp &op) {
|
|
switch (op) {
|
|
case gfx::LoadOp::LOAD:
|
|
return "LOAD";
|
|
case gfx::LoadOp::CLEAR:
|
|
return "CLEAR";
|
|
case gfx::LoadOp::DISCARD:
|
|
return "DISCARD";
|
|
default:
|
|
return "UNKNOWN";
|
|
}
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
const char *getName(const gfx::StoreOp &op) {
|
|
switch (op) {
|
|
case gfx::StoreOp::STORE:
|
|
return "STORE";
|
|
case gfx::StoreOp::DISCARD:
|
|
return "DISCARD";
|
|
default:
|
|
return "UNKNOWN";
|
|
}
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
std::string getName(const gfx::ClearFlagBit &flags) {
|
|
std::ostringstream oss;
|
|
int count = 0;
|
|
if (hasAnyFlags(flags, gfx::ClearFlagBit::COLOR)) {
|
|
if (count++) {
|
|
oss << "|";
|
|
}
|
|
oss << "COLOR";
|
|
}
|
|
if (hasAnyFlags(flags, gfx::ClearFlagBit::DEPTH)) {
|
|
if (count++) {
|
|
oss << "|";
|
|
}
|
|
oss << "DEPTH";
|
|
}
|
|
if (hasAnyFlags(flags, gfx::ClearFlagBit::STENCIL)) {
|
|
if (count++) {
|
|
oss << "|";
|
|
}
|
|
oss << "STENCIL";
|
|
}
|
|
if (flags == gfx::ClearFlagBit::NONE) {
|
|
oss << "NONE";
|
|
}
|
|
return oss.str();
|
|
}
|
|
|
|
struct RenderGraphPrintVisitor : boost::dfs_visitor<> {
|
|
void discover_vertex(
|
|
RenderGraph::vertex_descriptor vertID,
|
|
const AddressableView<RenderGraph> &gv) const {
|
|
const auto &g = gv.mGraph;
|
|
const auto &name = get(RenderGraph::Name, g, vertID);
|
|
visitObject(
|
|
vertID, gv.mGraph,
|
|
[&](const RasterPass &pass) {
|
|
OSS << "RasterPass \"" << name << "\" {\n";
|
|
indent(space);
|
|
for (const auto &[name, rasterView] : pass.rasterViews) {
|
|
OSS << "RasterView \"" << name << "\" {\n";
|
|
{
|
|
INDENT();
|
|
OSS << "slotName: \"" << rasterView.slotName << "\";\n";
|
|
OSS << "accessType: " << getName(rasterView.accessType) << ";\n";
|
|
OSS << "attachmentType: " << getName(rasterView.attachmentType) << ";\n";
|
|
OSS << "loadOp: " << getName(rasterView.loadOp) << ";\n";
|
|
OSS << "storeOp: " << getName(rasterView.storeOp) << ";\n";
|
|
OSS << "clearFlags: " << getName(rasterView.clearFlags) << ";\n";
|
|
const auto &c = rasterView.clearColor;
|
|
if (hasAnyFlags(rasterView.clearFlags, gfx::ClearFlagBit::COLOR)) {
|
|
OSS << "clearColor: [" << c.x << ", " << c.y << ", " << c.z << ", " << c.z << "];\n";
|
|
} else if (hasAnyFlags(rasterView.clearFlags, gfx::ClearFlagBit::DEPTH_STENCIL)) {
|
|
OSS << "clearColor: [" << c.x << ", " << c.y << "];\n";
|
|
}
|
|
}
|
|
OSS << "}\n";
|
|
}
|
|
for (const auto &[name, computeViews] : pass.computeViews) {
|
|
OSS << "ComputeViews \"" << name << "\" {\n";
|
|
{
|
|
INDENT();
|
|
for (const auto &computeView : computeViews) {
|
|
OSS << "ComputeView \"" << computeView.name << "\" {\n";
|
|
{
|
|
INDENT();
|
|
OSS << "accessType: " << getName(computeView.accessType) << ";\n";
|
|
OSS << "clearFlags: " << getName(computeView.clearFlags) << ";\n";
|
|
const auto &c = computeView.clearColor;
|
|
if (hasAnyFlags(computeView.clearFlags, gfx::ClearFlagBit::COLOR)) {
|
|
OSS << "clearColor: [" << c.x << ", " << c.y << ", " << c.z << ", " << c.z << "];\n";
|
|
} else if (hasAnyFlags(computeView.clearFlags, gfx::ClearFlagBit::DEPTH_STENCIL)) {
|
|
OSS << "clearColor: [" << c.x << ", " << c.y << "];\n";
|
|
}
|
|
}
|
|
OSS << "}\n";
|
|
}
|
|
}
|
|
OSS << "}\n";
|
|
}
|
|
},
|
|
[&](const ComputePass &pass) {
|
|
OSS << "ComputePass \"" << name << "\" {\n";
|
|
indent(space);
|
|
for (const auto &[name, computeViews] : pass.computeViews) {
|
|
OSS << "ComputeViews \"" << name << "\" {\n";
|
|
{
|
|
INDENT();
|
|
for (const auto &computeView : computeViews) {
|
|
OSS << "ComputeView \"" << computeView.name << "\" {\n";
|
|
{
|
|
INDENT();
|
|
OSS << "accessType: " << getName(computeView.accessType) << ";\n";
|
|
OSS << "clearFlags: " << getName(computeView.clearFlags) << ";\n";
|
|
const auto &c = computeView.clearColor;
|
|
if (hasAnyFlags(computeView.clearFlags, gfx::ClearFlagBit::COLOR)) {
|
|
OSS << "clearColor: [" << c.x << ", " << c.y << ", " << c.z << ", " << c.z << "];\n";
|
|
} else if (hasAnyFlags(computeView.clearFlags, gfx::ClearFlagBit::DEPTH_STENCIL)) {
|
|
OSS << "clearColor: [" << c.x << ", " << c.y << "];\n";
|
|
}
|
|
}
|
|
OSS << "}\n";
|
|
}
|
|
}
|
|
OSS << "}\n";
|
|
}
|
|
},
|
|
[&](const CopyPass &pass) {
|
|
OSS << "CopyPass \"" << name << "\" {\n";
|
|
for (const auto &pair : pass.copyPairs) {
|
|
INDENT();
|
|
OSS << "source: \"" << pair.source << "\", target: \"" << pair.target << "\"\n";
|
|
}
|
|
indent(space);
|
|
},
|
|
[&](const MovePass &pass) {
|
|
OSS << "MovePass \"" << name << "\" {\n";
|
|
for (const auto &pair : pass.movePairs) {
|
|
INDENT();
|
|
OSS << "source: \"" << pair.source << "\", target: \"" << pair.target << "\"\n";
|
|
}
|
|
indent(space);
|
|
},
|
|
[&](const PresentPass &pass) {
|
|
OSS << "PresentPass \"" << name << "\" {\n";
|
|
for (const auto &[name, present] : pass.presents) {
|
|
INDENT();
|
|
OSS << "present: \"" << name << "\", sync: " << present.syncInterval << ";\n";
|
|
}
|
|
indent(space);
|
|
},
|
|
[&](const RaytracePass &pass) {
|
|
std::ignore = pass;
|
|
OSS << "RaytracePass \"" << name << "\" {\n";
|
|
indent(space);
|
|
},
|
|
[&](const RenderQueue &queue) {
|
|
OSS << "Queue \"" << name << "\" {\n";
|
|
{
|
|
INDENT();
|
|
OSS << "hint: " << getName(queue.hint) << ";\n";
|
|
}
|
|
indent(space);
|
|
},
|
|
[&](const SceneData &scene) {
|
|
OSS << "Scene \"" << name << "\" {\n";
|
|
{
|
|
INDENT();
|
|
// OSS << "name: \"" << scene.name << "\";\n";
|
|
OSS << "scenes: [";
|
|
int count = 0;
|
|
for (const auto &sceneName : scene.scenes) {
|
|
if (count++) {
|
|
oss << ", ";
|
|
}
|
|
oss << "\"" << sceneName << "\"";
|
|
}
|
|
oss << "];\n";
|
|
// OSS << "flags: " << getName(scene.flags) << ";\n";
|
|
}
|
|
indent(space);
|
|
},
|
|
[&](const Blit &blit) {
|
|
std::ignore = blit;
|
|
OSS << "Blit \"" << name << "\";\n";
|
|
},
|
|
[&](const Dispatch &dispatch) {
|
|
OSS << "Dispatch \"" << name << "\", ["
|
|
<< dispatch.threadGroupCountX << ", "
|
|
<< dispatch.threadGroupCountY << ", "
|
|
<< dispatch.threadGroupCountZ << "];\n";
|
|
},
|
|
[&](const ccstd::pmr::vector<ClearView> &clearViews) {
|
|
OSS << "Clear \"" << name << "\" {\n";
|
|
indent(space);
|
|
for (const auto &view : clearViews) {
|
|
INDENT();
|
|
OSS << "\"" << view.slotName << "\" {\n";
|
|
{
|
|
INDENT();
|
|
OSS << "clearFlags: " << getName(view.clearFlags) << ";\n";
|
|
const auto &c = view.clearColor;
|
|
if (hasAnyFlags(view.clearFlags, gfx::ClearFlagBit::COLOR)) {
|
|
OSS << "clearColor: [" << c.x << ", " << c.y << ", " << c.z << ", " << c.z << "];\n";
|
|
} else if (hasAnyFlags(view.clearFlags, gfx::ClearFlagBit::DEPTH_STENCIL)) {
|
|
OSS << "clearColor: [" << c.x << ", " << c.y << "];\n";
|
|
}
|
|
}
|
|
OSS << "}\n";
|
|
}
|
|
},
|
|
[&](const gfx::Viewport &vp) {
|
|
OSS << "Viewport \"" << name << "\" ["
|
|
<< "left: " << vp.left << ", "
|
|
<< "top: " << vp.top << ", "
|
|
<< "width: " << vp.width << ", "
|
|
<< "height: " << vp.height << ", "
|
|
<< "minDepth: " << vp.minDepth << ", "
|
|
<< "maxDepth: " << vp.maxDepth << "]\n";
|
|
});
|
|
}
|
|
|
|
void finish_vertex(
|
|
RenderGraph::vertex_descriptor vertID,
|
|
const AddressableView<RenderGraph> &gv) const {
|
|
std::ignore = gv;
|
|
visitObject(
|
|
vertID, gv.mGraph,
|
|
[&](const RasterPass &pass) {
|
|
std::ignore = pass;
|
|
unindent(space);
|
|
OSS << "}\n";
|
|
},
|
|
[&](const ComputePass &pass) {
|
|
std::ignore = pass;
|
|
unindent(space);
|
|
OSS << "}\n";
|
|
},
|
|
[&](const CopyPass &pass) {
|
|
std::ignore = pass;
|
|
unindent(space);
|
|
OSS << "}\n";
|
|
},
|
|
[&](const MovePass &pass) {
|
|
std::ignore = pass;
|
|
unindent(space);
|
|
OSS << "}\n";
|
|
},
|
|
[&](const PresentPass &pass) {
|
|
std::ignore = pass;
|
|
unindent(space);
|
|
OSS << "}\n";
|
|
},
|
|
[&](const RaytracePass &pass) {
|
|
std::ignore = pass;
|
|
unindent(space);
|
|
OSS << "}\n";
|
|
},
|
|
[&](const RenderQueue &queue) {
|
|
std::ignore = queue;
|
|
unindent(space);
|
|
OSS << "}\n";
|
|
},
|
|
[&](const SceneData &scene) {
|
|
std::ignore = scene;
|
|
unindent(space);
|
|
OSS << "}\n";
|
|
},
|
|
[&](const Blit &blit) {
|
|
},
|
|
[&](const Dispatch &dispatch) {
|
|
},
|
|
[&](const ccstd::pmr::vector<ClearView> &clear) {
|
|
std::ignore = clear;
|
|
unindent(space);
|
|
OSS << "}\n";
|
|
},
|
|
[&](const gfx::Viewport &clear) {
|
|
});
|
|
}
|
|
|
|
std::ostringstream &oss;
|
|
ccstd::pmr::string &space;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
ccstd::string RenderGraph::print(
|
|
boost::container::pmr::memory_resource *scratch) const {
|
|
const auto &rg = *this;
|
|
std::ostringstream oss;
|
|
ccstd::pmr::string space(scratch);
|
|
oss << "\n";
|
|
OSS << "RenderGraph {\n";
|
|
{
|
|
INDENT();
|
|
RenderGraphPrintVisitor visitor{
|
|
{}, oss, space};
|
|
AddressableView<RenderGraph> graphView(rg);
|
|
auto colors = rg.colors(scratch);
|
|
boost::depth_first_search(graphView, visitor, get(colors, rg));
|
|
}
|
|
OSS << "}\n";
|
|
return oss.str();
|
|
}
|
|
|
|
} // namespace render
|
|
|
|
} // namespace cc
|