mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 17:42:41 +08:00
V3.8.2 pipeline (#16244)
This commit is contained in:
@@ -57,7 +57,8 @@ RenderObject genRenderObject(const scene::Model *model, const scene::Camera *cam
|
||||
if (model->getNode()) {
|
||||
const auto *node = model->getTransform();
|
||||
cc::Vec3 position;
|
||||
cc::Vec3::subtract(node->getWorldPosition(), camera->getPosition(), &position);
|
||||
const auto *bounds = model->getWorldBounds();
|
||||
Vec3::subtract(bounds ? bounds->center : node->getWorldPosition(), camera->getPosition(), &position);
|
||||
depth = position.dot(camera->getForward());
|
||||
}
|
||||
|
||||
|
||||
@@ -312,12 +312,12 @@ RenderingInfo FrameGraphDispatcher::getRenderPassAndFrameBuffer(RenderGraph::ver
|
||||
CC_EXPECTS(tex.texture);
|
||||
fbInfo.colorTextures.emplace_back(tex.texture);
|
||||
},
|
||||
[&](const IntrusivePtr<gfx::Buffer> &res) {
|
||||
[&](const PersistentBuffer &res) {
|
||||
std::ignore = res;
|
||||
CC_EXPECTS(false);
|
||||
},
|
||||
[&](const IntrusivePtr<gfx::Texture> &tex) {
|
||||
fbInfo.colorTextures.emplace_back(tex);
|
||||
[&](const PersistentTexture &tex) {
|
||||
fbInfo.colorTextures.emplace_back(tex.texture);
|
||||
},
|
||||
[&](const IntrusivePtr<gfx::Framebuffer> &fb) {
|
||||
CC_EXPECTS(fb->getColorTextures().size() == 1);
|
||||
@@ -1566,7 +1566,7 @@ gfx::SamplerInfo makePointSamplerInfo() {
|
||||
return gfx::SamplerInfo{gfx::Filter::POINT, gfx::Filter::POINT, gfx::Filter::POINT};
|
||||
}
|
||||
|
||||
SubresourceView makeSubresourceView(const ResourceDesc &srcDesc, const ResourceDesc &targetDesc, const gfx::ResourceRange &range) {
|
||||
SubresourceView makeSubresourceView(const ResourceDesc &targetDesc, const gfx::ResourceRange& range) {
|
||||
SubresourceView view{};
|
||||
view.firstArraySlice = range.firstSlice;
|
||||
view.numArraySlices = range.numSlices;
|
||||
@@ -1575,7 +1575,6 @@ SubresourceView makeSubresourceView(const ResourceDesc &srcDesc, const ResourceD
|
||||
view.firstPlane = range.basePlane;
|
||||
view.numPlanes = range.planeCount;
|
||||
view.format = targetDesc.format;
|
||||
view.viewType = srcDesc.viewType;
|
||||
view.textureView = nullptr;
|
||||
return view;
|
||||
}
|
||||
@@ -1692,7 +1691,6 @@ void subresourceAnalysis(ResourceAccessGraph &rag, ResourceGraph &resg) {
|
||||
auto descResViewID = findVertex(subres, resg);
|
||||
auto targetResID = rag.resourceIndex.at(resName);
|
||||
|
||||
const auto &srcDesc = get(ResourceGraph::DescTag{}, resg, descResViewID);
|
||||
const auto &targetName = get(ResourceGraph::NameTag{}, resg, targetResID);
|
||||
const auto &targetDesc = get(ResourceGraph::DescTag{}, resg, targetResID);
|
||||
const auto &srcResourceRange = rag.movedSourceStatus.at(subres).range;
|
||||
@@ -1700,7 +1698,7 @@ void subresourceAnalysis(ResourceAccessGraph &rag, ResourceGraph &resg) {
|
||||
const auto &indexName = concatResName(targetName, subres, rag.resource());
|
||||
auto subresID = findVertex(indexName, resg);
|
||||
if (subresID == ResourceGraph::null_vertex()) {
|
||||
const auto &subView = makeSubresourceView(srcDesc, targetDesc, srcResourceRange);
|
||||
const auto &subView = makeSubresourceView(targetDesc, srcResourceRange);
|
||||
// register to resourcegraph
|
||||
subresID = addVertex(
|
||||
SubresourceViewTag{},
|
||||
|
||||
@@ -26,14 +26,18 @@
|
||||
#include "cocos/application/ApplicationManager.h"
|
||||
#include "cocos/renderer/gfx-base/GFXDef-common.h"
|
||||
#include "cocos/renderer/gfx-base/GFXDevice.h"
|
||||
#include "cocos/renderer/pipeline/Define.h"
|
||||
#include "cocos/renderer/pipeline/PipelineSceneData.h"
|
||||
#include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativePipelineTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativeTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativeUtils.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderGraphTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/GslUtils.h"
|
||||
#include "cocos/scene/Camera.h"
|
||||
#include "cocos/scene/DirectionalLight.h"
|
||||
#include "cocos/scene/Fog.h"
|
||||
#include "cocos/scene/Shadow.h"
|
||||
#include "cocos/scene/Skybox.h"
|
||||
#include "cocos/scene/SpotLight.h"
|
||||
|
||||
@@ -254,12 +258,12 @@ float getPCFRadius(
|
||||
void setShadowUBOView(
|
||||
gfx::Device &device,
|
||||
const LayoutGraphData &layoutGraph,
|
||||
const pipeline::PipelineSceneData &sceneData,
|
||||
const pipeline::PipelineSceneData &pplSceneData,
|
||||
const scene::DirectionalLight &mainLight,
|
||||
RenderData &data) {
|
||||
const auto &shadowInfo = *sceneData.getShadows();
|
||||
const auto &csmLayers = *sceneData.getCSMLayers();
|
||||
const auto &csmSupported = sceneData.getCSMSupported();
|
||||
const auto &shadowInfo = *pplSceneData.getShadows();
|
||||
const auto &csmLayers = *pplSceneData.getCSMLayers();
|
||||
const auto &csmSupported = pplSceneData.getCSMSupported();
|
||||
const auto &packing = pipeline::supportsR32FloatTexture(&device) ? 0.0F : 1.0F;
|
||||
Vec4 vec4ShadowInfo{};
|
||||
if (shadowInfo.isEnabled()) {
|
||||
@@ -373,12 +377,12 @@ void setShadowUBOView(
|
||||
void setShadowUBOLightView(
|
||||
gfx::Device *device,
|
||||
const LayoutGraphData &layoutGraph,
|
||||
const pipeline::PipelineSceneData &sceneData,
|
||||
const pipeline::PipelineSceneData &pplSceneData,
|
||||
const BuiltinCascadedShadowMap *csm,
|
||||
const scene::Light &light,
|
||||
uint32_t level,
|
||||
RenderData &data) {
|
||||
const auto &shadowInfo = *sceneData.getShadows();
|
||||
const auto &csmLayers = *sceneData.getCSMLayers();
|
||||
const auto &shadowInfo = *pplSceneData.getShadows();
|
||||
const auto &packing = pipeline::supportsR32FloatTexture(device) ? 0.0F : 1.0F;
|
||||
const auto &cap = device->getCapabilities();
|
||||
Vec4 vec4ShadowInfo{};
|
||||
@@ -395,29 +399,31 @@ void setShadowUBOLightView(
|
||||
Mat4 matShadowProj;
|
||||
Mat4 matShadowViewProj;
|
||||
scene::CSMLevel levelCount{};
|
||||
CC_EXPECTS(csm);
|
||||
if (mainLight.isShadowFixedArea() || mainLight.getCSMLevel() == scene::CSMLevel::LEVEL_1) {
|
||||
matShadowView = csmLayers.getSpecialLayer()->getMatShadowView();
|
||||
matShadowProj = csmLayers.getSpecialLayer()->getMatShadowProj();
|
||||
matShadowViewProj = csmLayers.getSpecialLayer()->getMatShadowViewProj();
|
||||
matShadowView = csm->specialLayer.shadowView;
|
||||
matShadowProj = csm->specialLayer.shadowProj;
|
||||
matShadowViewProj = csm->specialLayer.shadowViewProj;
|
||||
if (mainLight.isShadowFixedArea()) {
|
||||
near = mainLight.getShadowNear();
|
||||
far = mainLight.getShadowFar();
|
||||
levelCount = static_cast<scene::CSMLevel>(0);
|
||||
} else {
|
||||
near = 0.1F;
|
||||
far = csmLayers.getSpecialLayer()->getShadowCameraFar();
|
||||
far = csm->specialLayer.shadowCameraFar;
|
||||
levelCount = scene::CSMLevel::LEVEL_1;
|
||||
}
|
||||
vec4ShadowInfo.set(static_cast<float>(scene::LightType::DIRECTIONAL), packing, mainLight.getShadowNormalBias(), 0);
|
||||
setVec4Impl(data, layoutGraph, "cc_shadowLPNNInfo", vec4ShadowInfo);
|
||||
} else {
|
||||
const auto &layer = *csmLayers.getLayers()[level];
|
||||
matShadowView = layer.getMatShadowView();
|
||||
matShadowProj = layer.getMatShadowProj();
|
||||
matShadowViewProj = layer.getMatShadowViewProj();
|
||||
CC_EXPECTS(level < csm->layers.size());
|
||||
const auto &layer = csm->layers[level];
|
||||
matShadowView = layer.shadowView;
|
||||
matShadowProj = layer.shadowProj;
|
||||
matShadowViewProj = layer.shadowViewProj;
|
||||
|
||||
near = layer.getSplitCameraNear();
|
||||
far = layer.getSplitCameraFar();
|
||||
near = layer.splitCameraNear;
|
||||
far = layer.splitCameraFar;
|
||||
levelCount = mainLight.getCSMLevel();
|
||||
}
|
||||
setMat4Impl(data, layoutGraph, "cc_matLightView", matShadowView);
|
||||
@@ -489,12 +495,120 @@ void setShadowUBOLightView(
|
||||
setColorImpl(data, layoutGraph, "cc_shadowColor", gfx::Color{color[0], color[1], color[2], color[3]});
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void updatePlanarNormalAndDistance(
|
||||
const LayoutGraphData &layoutGraph,
|
||||
const scene::Shadows &shadowInfo,
|
||||
RenderData &data) {
|
||||
const Vec3 normal = shadowInfo.getNormal().getNormalized();
|
||||
const Vec4 planarNDInfo{normal.x, normal.y, normal.z, -shadowInfo.getDistance()};
|
||||
setVec4Impl(data, layoutGraph, "cc_planarNDInfo", planarNDInfo);
|
||||
}
|
||||
|
||||
std::tuple<Mat4, Mat4, Mat4, Mat4>
|
||||
computeShadowMatrices(
|
||||
const gfx::DeviceCaps &cap,
|
||||
const Mat4 &matShadowCamera,
|
||||
float fov, float farPlane) {
|
||||
auto matShadowView = matShadowCamera.getInversed();
|
||||
|
||||
Mat4 matShadowProj;
|
||||
Mat4::createPerspective(
|
||||
fov, 1.0F, 0.001F, farPlane,
|
||||
true, cap.clipSpaceMinZ, cap.clipSpaceSignY,
|
||||
0, &matShadowProj);
|
||||
|
||||
Mat4 matShadowViewProj = matShadowProj;
|
||||
Mat4 matShadowInvProj = matShadowProj;
|
||||
|
||||
matShadowInvProj.inverse();
|
||||
matShadowViewProj.multiply(matShadowView);
|
||||
|
||||
return {matShadowView, matShadowViewProj, matShadowProj, matShadowInvProj};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void setPunctualLightShadowUBO(
|
||||
gfx::Device *device,
|
||||
const LayoutGraphData &layoutGraph,
|
||||
const pipeline::PipelineSceneData &pplSceneData,
|
||||
const scene::DirectionalLight *mainLight,
|
||||
const scene::Light &light,
|
||||
RenderData &data) {
|
||||
const auto &shadowInfo = *pplSceneData.getShadows();
|
||||
const auto &packing = pipeline::supportsR32FloatTexture(device) ? 0.0F : 1.0F;
|
||||
const auto &cap = device->getCapabilities();
|
||||
Vec4 vec4ShadowInfo{};
|
||||
|
||||
if (mainLight) {
|
||||
// update planar PROJ
|
||||
updatePlanarNormalAndDistance(layoutGraph, shadowInfo, data);
|
||||
}
|
||||
|
||||
// ShadowMap
|
||||
switch (light.getType()) {
|
||||
case scene::LightType::DIRECTIONAL:
|
||||
// noop
|
||||
break;
|
||||
case scene::LightType::SPHERE: {
|
||||
const auto &shadowSize = shadowInfo.getSize();
|
||||
setVec4Impl(
|
||||
data, layoutGraph, "cc_shadowWHPBInfo",
|
||||
Vec4{shadowSize.x, shadowSize.y, 1.0F, 0.0F});
|
||||
setVec4Impl(
|
||||
data, layoutGraph, "cc_shadowLPNNInfo",
|
||||
Vec4{static_cast<float>(scene::LightType::SPHERE), packing, 0.0F, 0.0F});
|
||||
} break;
|
||||
case scene::LightType::SPOT: {
|
||||
const auto &shadowSize = shadowInfo.getSize();
|
||||
const auto &spotLight = dynamic_cast<const scene::SpotLight &>(light);
|
||||
const auto &matShadowCamera = spotLight.getNode()->getWorldMatrix();
|
||||
const auto [matShadowView, matShadowViewProj, matShadowProj, matShadowInvProj] =
|
||||
computeShadowMatrices(cap, matShadowCamera, spotLight.getAngle(), spotLight.getRange());
|
||||
|
||||
setMat4Impl(data, layoutGraph, "cc_matLightView", matShadowView);
|
||||
setMat4Impl(data, layoutGraph, "cc_matLightViewProj", matShadowViewProj);
|
||||
setVec4Impl(
|
||||
data, layoutGraph, "cc_shadowNFLSInfo",
|
||||
Vec4{0.1F, spotLight.getRange(), 0.0F, 0.0F});
|
||||
setVec4Impl(
|
||||
data, layoutGraph, "cc_shadowWHPBInfo",
|
||||
Vec4{shadowSize.x, shadowSize.y, spotLight.getShadowPcf(), spotLight.getShadowBias()});
|
||||
setVec4Impl(
|
||||
data, layoutGraph, "cc_shadowLPNNInfo",
|
||||
Vec4{static_cast<float>(scene::LightType::SPOT), packing, spotLight.getShadowNormalBias(), 0.0F});
|
||||
setVec4Impl(
|
||||
data, layoutGraph, "cc_shadowInvProjDepthInfo",
|
||||
Vec4{matShadowInvProj.m[10], matShadowInvProj.m[14], matShadowInvProj.m[11], matShadowInvProj.m[15]});
|
||||
setVec4Impl(
|
||||
data, layoutGraph, "cc_shadowProjDepthInfo",
|
||||
Vec4{matShadowProj.m[10], matShadowProj.m[14], matShadowProj.m[11], matShadowProj.m[15]});
|
||||
setVec4Impl(
|
||||
data, layoutGraph, "cc_shadowProjInfo",
|
||||
Vec4{matShadowProj.m[00], matShadowProj.m[05], 1.0F / matShadowProj.m[00], 1.0F / matShadowProj.m[05]});
|
||||
} break;
|
||||
case scene::LightType::POINT: {
|
||||
const auto &shadowSize = shadowInfo.getSize();
|
||||
setVec4Impl(
|
||||
data, layoutGraph, "cc_shadowWHPBInfo",
|
||||
Vec4{shadowSize.x, shadowSize.y, 1.0F, 0.0F});
|
||||
setVec4Impl(
|
||||
data, layoutGraph, "cc_shadowLPNNInfo",
|
||||
Vec4{static_cast<float>(scene::LightType::POINT), packing, 0.0F, 0.0F});
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setLegacyTextureUBOView(
|
||||
gfx::Device &device,
|
||||
const LayoutGraphData &layoutGraph,
|
||||
const pipeline::PipelineSceneData &sceneData,
|
||||
const pipeline::PipelineSceneData &pplSceneData,
|
||||
RenderData &data) {
|
||||
const auto &skybox = *sceneData.getSkybox();
|
||||
const auto &skybox = *pplSceneData.getSkybox();
|
||||
if (skybox.getReflectionMap()) {
|
||||
auto &texture = *skybox.getReflectionMap()->getGFXTexture();
|
||||
auto *sampler = device.getSampler(skybox.getReflectionMap()->getSamplerInfo());
|
||||
@@ -536,6 +650,251 @@ void setLegacyTextureUBOView(
|
||||
// setTextureImpl(data, layoutGraph, "cc_spotShadowMap", BuiltinResMgr::getInstance()->get<Texture2D>("default-texture")->getGFXTexture());
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
float kLightMeterScale{10000.0F};
|
||||
|
||||
} // namespace
|
||||
|
||||
void setLightUBO(
|
||||
const scene::Light *light, bool bHDR, float exposure,
|
||||
const scene::Shadows *shadowInfo,
|
||||
char *buffer, size_t bufferSize) {
|
||||
CC_EXPECTS(bufferSize % sizeof(float) == 0);
|
||||
const auto maxSize = bufferSize / sizeof(float);
|
||||
auto *lightBufferData = reinterpret_cast<float *>(buffer);
|
||||
|
||||
size_t offset = 0;
|
||||
|
||||
Vec3 position = Vec3(0.0F, 0.0F, 0.0F);
|
||||
float size = 0.F;
|
||||
float range = 0.F;
|
||||
float luminanceHDR = 0.F;
|
||||
float luminanceLDR = 0.F;
|
||||
if (light->getType() == scene::LightType::SPHERE) {
|
||||
const auto *sphereLight = static_cast<const scene::SphereLight *>(light);
|
||||
position = sphereLight->getPosition();
|
||||
size = sphereLight->getSize();
|
||||
range = sphereLight->getRange();
|
||||
luminanceHDR = sphereLight->getLuminanceHDR();
|
||||
luminanceLDR = sphereLight->getLuminanceLDR();
|
||||
} else if (light->getType() == scene::LightType::SPOT) {
|
||||
const auto *spotLight = static_cast<const scene::SpotLight *>(light);
|
||||
position = spotLight->getPosition();
|
||||
size = spotLight->getSize();
|
||||
range = spotLight->getRange();
|
||||
luminanceHDR = spotLight->getLuminanceHDR();
|
||||
luminanceLDR = spotLight->getLuminanceLDR();
|
||||
} else if (light->getType() == scene::LightType::POINT) {
|
||||
const auto *pointLight = static_cast<const scene::PointLight *>(light);
|
||||
position = pointLight->getPosition();
|
||||
size = 0.0F;
|
||||
range = pointLight->getRange();
|
||||
luminanceHDR = pointLight->getLuminanceHDR();
|
||||
luminanceLDR = pointLight->getLuminanceLDR();
|
||||
} else if (light->getType() == scene::LightType::RANGED_DIRECTIONAL) {
|
||||
const auto *rangedDirLight = static_cast<const scene::RangedDirectionalLight *>(light);
|
||||
position = rangedDirLight->getPosition();
|
||||
size = 0.0F;
|
||||
range = 0.0F;
|
||||
luminanceHDR = rangedDirLight->getIlluminanceHDR();
|
||||
luminanceLDR = rangedDirLight->getIlluminanceLDR();
|
||||
}
|
||||
auto index = offset + pipeline::UBOForwardLight::LIGHT_POS_OFFSET;
|
||||
CC_EXPECTS(index + 4 < maxSize);
|
||||
lightBufferData[index++] = position.x;
|
||||
lightBufferData[index++] = position.y;
|
||||
lightBufferData[index] = position.z;
|
||||
|
||||
index = offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET;
|
||||
CC_EXPECTS(index + 4 < maxSize);
|
||||
lightBufferData[index++] = size;
|
||||
lightBufferData[index] = range;
|
||||
|
||||
index = offset + pipeline::UBOForwardLight::LIGHT_COLOR_OFFSET;
|
||||
CC_EXPECTS(index + 4 < maxSize);
|
||||
const auto &color = light->getColor();
|
||||
if (light->isUseColorTemperature()) {
|
||||
const auto &tempRGB = light->getColorTemperatureRGB();
|
||||
lightBufferData[index++] = color.x * tempRGB.x;
|
||||
lightBufferData[index++] = color.y * tempRGB.y;
|
||||
lightBufferData[index++] = color.z * tempRGB.z;
|
||||
} else {
|
||||
lightBufferData[index++] = color.x;
|
||||
lightBufferData[index++] = color.y;
|
||||
lightBufferData[index++] = color.z;
|
||||
}
|
||||
|
||||
if (bHDR) {
|
||||
lightBufferData[index] = luminanceHDR * exposure * kLightMeterScale;
|
||||
} else {
|
||||
lightBufferData[index] = luminanceLDR;
|
||||
}
|
||||
|
||||
switch (light->getType()) {
|
||||
case scene::LightType::SPHERE:
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_POS_OFFSET + 3] =
|
||||
static_cast<float>(scene::LightType::SPHERE);
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET + 2] = 0;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET + 3] = 0;
|
||||
break;
|
||||
case scene::LightType::SPOT: {
|
||||
const auto *spotLight = static_cast<const scene::SpotLight *>(light);
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_POS_OFFSET + 3] = static_cast<float>(scene::LightType::SPOT);
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET + 2] = spotLight->getSpotAngle();
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET + 3] =
|
||||
(shadowInfo->isEnabled() &&
|
||||
spotLight->isShadowEnabled() &&
|
||||
shadowInfo->getType() == scene::ShadowType::SHADOW_MAP)
|
||||
? 1.0F
|
||||
: 0.0F;
|
||||
|
||||
index = offset + pipeline::UBOForwardLight::LIGHT_DIR_OFFSET;
|
||||
const auto &direction = spotLight->getDirection();
|
||||
lightBufferData[index++] = direction.x;
|
||||
lightBufferData[index++] = direction.y;
|
||||
lightBufferData[index] = direction.z;
|
||||
} break;
|
||||
case scene::LightType::POINT:
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_POS_OFFSET + 3] = static_cast<float>(scene::LightType::POINT);
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET + 2] = 0;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET + 3] = 0;
|
||||
break;
|
||||
case scene::LightType::RANGED_DIRECTIONAL: {
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_POS_OFFSET + 3] = static_cast<float>(scene::LightType::RANGED_DIRECTIONAL);
|
||||
|
||||
const auto *rangedDirLight = static_cast<const scene::RangedDirectionalLight *>(light);
|
||||
const Vec3 &right = rangedDirLight->getRight();
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET + 0] = right.x;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET + 1] = right.y;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET + 2] = right.z;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_SIZE_RANGE_ANGLE_OFFSET + 3] = 0;
|
||||
|
||||
const auto &direction = rangedDirLight->getDirection();
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_DIR_OFFSET + 0] = direction.x;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_DIR_OFFSET + 1] = direction.y;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_DIR_OFFSET + 2] = direction.z;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_DIR_OFFSET + 3] = 0;
|
||||
|
||||
const auto &scale = rangedDirLight->getScale();
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_BOUNDING_SIZE_VS_OFFSET + 0] = scale.x * 0.5F;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_BOUNDING_SIZE_VS_OFFSET + 1] = scale.y * 0.5F;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_BOUNDING_SIZE_VS_OFFSET + 2] = scale.z * 0.5F;
|
||||
lightBufferData[offset + pipeline::UBOForwardLight::LIGHT_BOUNDING_SIZE_VS_OFFSET + 3] = 0;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const BuiltinCascadedShadowMap *getBuiltinShadowCSM(
|
||||
const PipelineRuntime &pplRuntime,
|
||||
const scene::Camera &camera,
|
||||
const scene::DirectionalLight *mainLight) {
|
||||
const auto &ppl = dynamic_cast<const NativePipeline &>(pplRuntime);
|
||||
// no main light
|
||||
if (!mainLight) {
|
||||
return nullptr;
|
||||
}
|
||||
// not attached to a node
|
||||
if (!mainLight->getNode()) {
|
||||
return nullptr;
|
||||
}
|
||||
const pipeline::PipelineSceneData &pplSceneData = *pplRuntime.getPipelineSceneData();
|
||||
auto &csmLayers = *pplSceneData.getCSMLayers();
|
||||
const auto &shadows = *pplSceneData.getShadows();
|
||||
// shadow not enabled
|
||||
if (!shadows.isEnabled()) {
|
||||
return nullptr;
|
||||
}
|
||||
// shadow type is planar
|
||||
if (shadows.getType() == scene::ShadowType::PLANAR) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// find csm
|
||||
const BuiltinCascadedShadowMapKey key{&camera, mainLight};
|
||||
auto iter = ppl.builtinCSMs.find(key);
|
||||
if (iter != ppl.builtinCSMs.end()) {
|
||||
return &iter->second;
|
||||
}
|
||||
|
||||
// add new csm info
|
||||
bool added = false;
|
||||
std::tie(iter, added) = ppl.builtinCSMs.emplace(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(key),
|
||||
std::forward_as_tuple());
|
||||
CC_ENSURES(added);
|
||||
|
||||
auto &csm = iter->second;
|
||||
|
||||
// update csm layers
|
||||
csmLayers.update(&pplSceneData, &camera);
|
||||
|
||||
// copy csm data
|
||||
CC_EXPECTS(csm.layers.size() == csmLayers.getLayers().size());
|
||||
for (uint32_t i = 0; i != csm.layers.size(); ++i) {
|
||||
const auto &src = *csmLayers.getLayers()[i];
|
||||
auto &dst = csm.layers[i];
|
||||
dst.shadowView = src.getMatShadowView();
|
||||
dst.shadowProj = src.getMatShadowProj();
|
||||
dst.shadowViewProj = src.getMatShadowViewProj();
|
||||
dst.validFrustum = src.getValidFrustum();
|
||||
dst.splitFrustum = src.getSplitFrustum();
|
||||
dst.lightViewFrustum = src.getLightViewFrustum();
|
||||
dst.castLightViewBoundingBox = src.getCastLightViewBoundingBox();
|
||||
dst.shadowCameraFar = src.getShadowCameraFar();
|
||||
dst.splitCameraNear = src.getSplitCameraNear();
|
||||
dst.splitCameraFar = src.getSplitCameraFar();
|
||||
dst.csmAtlas = src.getCSMAtlas();
|
||||
}
|
||||
|
||||
{
|
||||
const auto &src = *csmLayers.getSpecialLayer();
|
||||
auto &dst = csm.specialLayer;
|
||||
dst.shadowView = src.getMatShadowView();
|
||||
dst.shadowProj = src.getMatShadowProj();
|
||||
dst.shadowViewProj = src.getMatShadowViewProj();
|
||||
dst.validFrustum = src.getValidFrustum();
|
||||
dst.splitFrustum = src.getSplitFrustum();
|
||||
dst.lightViewFrustum = src.getLightViewFrustum();
|
||||
dst.castLightViewBoundingBox = src.getCastLightViewBoundingBox();
|
||||
dst.shadowCameraFar = src.getShadowCameraFar();
|
||||
}
|
||||
|
||||
csm.shadowDistance = mainLight->getShadowDistance();
|
||||
|
||||
return &csm;
|
||||
}
|
||||
|
||||
const geometry::Frustum &getBuiltinShadowFrustum(
|
||||
const PipelineRuntime &pplRuntime,
|
||||
const scene::Camera &camera,
|
||||
const scene::DirectionalLight *mainLight,
|
||||
uint32_t level) {
|
||||
const auto &ppl = dynamic_cast<const NativePipeline &>(pplRuntime);
|
||||
|
||||
const auto &shadows = *ppl.pipelineSceneData->getShadows();
|
||||
if (shadows.getType() == scene::ShadowType::PLANAR) {
|
||||
return camera.getFrustum();
|
||||
}
|
||||
|
||||
BuiltinCascadedShadowMapKey key{&camera, mainLight};
|
||||
auto iter = ppl.builtinCSMs.find(key);
|
||||
if (iter == ppl.builtinCSMs.end()) {
|
||||
throw std::runtime_error("Builtin shadow CSM not found");
|
||||
}
|
||||
|
||||
const auto &csmLevel = mainLight->getCSMLevel();
|
||||
const auto &csm = iter->second;
|
||||
|
||||
if (mainLight->isShadowFixedArea() || csmLevel == scene::CSMLevel::LEVEL_1) {
|
||||
return csm.specialLayer.validFrustum;
|
||||
}
|
||||
return csm.layers[level].validFrustum;
|
||||
}
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -24,17 +24,26 @@
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include "cocos/math/Vec4.h"
|
||||
#include "cocos/renderer/gfx-base/GFXDevice.h"
|
||||
#include "cocos/renderer/pipeline/custom/LayoutGraphFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativeFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativePipelineFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderGraphFwd.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace scene {
|
||||
class Camera;
|
||||
class Light;
|
||||
class DirectionalLight;
|
||||
class Shadows;
|
||||
} // namespace scene
|
||||
|
||||
namespace geometry {
|
||||
class Frustum;
|
||||
} // namespace geometry
|
||||
|
||||
namespace gfx {
|
||||
class Device;
|
||||
} // namespace gfx
|
||||
@@ -71,16 +80,43 @@ void setShadowUBOLightView(
|
||||
gfx::Device *device,
|
||||
const LayoutGraphData &layoutGraph,
|
||||
const pipeline::PipelineSceneData &sceneData,
|
||||
const BuiltinCascadedShadowMap *csm,
|
||||
const scene::Light &light,
|
||||
uint32_t level,
|
||||
RenderData &data);
|
||||
|
||||
// Additive light
|
||||
void setLightUBO(
|
||||
const scene::Light *light, bool bHDR, float exposure,
|
||||
const scene::Shadows *shadowInfo,
|
||||
char *buffer, size_t bufferSize);
|
||||
|
||||
void setPunctualLightShadowUBO(
|
||||
gfx::Device *device,
|
||||
const LayoutGraphData &layoutGraph,
|
||||
const pipeline::PipelineSceneData &pplSceneData,
|
||||
const scene::DirectionalLight *mainLight,
|
||||
const scene::Light &light,
|
||||
RenderData &data);
|
||||
|
||||
// Render graph
|
||||
void updateRasterPassConstants(uint32_t width, uint32_t height, Setter &setter);
|
||||
|
||||
// Geometry
|
||||
void setupQuadVertexBuffer(gfx::Device &device, const Vec4 &viewport, float vbData[16]);
|
||||
|
||||
// Shadow
|
||||
const BuiltinCascadedShadowMap *getBuiltinShadowCSM(
|
||||
const PipelineRuntime &pplRuntime,
|
||||
const scene::Camera &camera,
|
||||
const scene::DirectionalLight *mainLight);
|
||||
|
||||
const geometry::Frustum &getBuiltinShadowFrustum(
|
||||
const PipelineRuntime &pplRuntime,
|
||||
const scene::Camera &camera,
|
||||
const scene::DirectionalLight *mainLight,
|
||||
uint32_t level);
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -28,14 +28,15 @@
|
||||
#include "LayoutGraphGraphs.h"
|
||||
#include "LayoutGraphTypes.h"
|
||||
#include "LayoutGraphUtils.h"
|
||||
#include "NativeBuiltinUtils.h"
|
||||
#include "NativePipelineFwd.h"
|
||||
#include "NativePipelineTypes.h"
|
||||
#include "NativeRenderGraphUtils.h"
|
||||
#include "NativeUtils.h"
|
||||
#include "PrivateTypes.h"
|
||||
#include "RenderGraphGraphs.h"
|
||||
#include "RenderGraphTypes.h"
|
||||
#include "RenderingModule.h"
|
||||
#include "NativeRenderGraphUtils.h"
|
||||
#include "cocos/renderer/gfx-base/GFXBarrier.h"
|
||||
#include "cocos/renderer/gfx-base/GFXDef-common.h"
|
||||
#include "cocos/renderer/gfx-base/GFXDescriptorSetLayout.h"
|
||||
@@ -60,10 +61,11 @@ namespace {
|
||||
|
||||
constexpr uint32_t INVALID_ID = 0xFFFFFFFF;
|
||||
constexpr gfx::Color RASTER_COLOR{0.0, 1.0, 0.0, 1.0};
|
||||
constexpr gfx::Color RASTER_UPLOAD_COLOR{1.0, 1.0, 0.0, 1.0};
|
||||
constexpr gfx::Color RENDER_QUEUE_COLOR{0.0, 0.5, 0.5, 1.0};
|
||||
constexpr gfx::Color COMPUTE_COLOR{0.0, 0.0, 1.0, 1.0};
|
||||
|
||||
gfx::MarkerInfo makeMarkerInfo(const char *str, const gfx::Color &color) {
|
||||
gfx::MarkerInfo makeMarkerInfo(const char* str, const gfx::Color& color) {
|
||||
return gfx::MarkerInfo{str, color};
|
||||
}
|
||||
|
||||
@@ -1135,9 +1137,6 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
|
||||
}
|
||||
}
|
||||
void begin(const RasterPass& pass, RenderGraph::vertex_descriptor vertID) const {
|
||||
#if CC_DEBUG
|
||||
ctx.cmdBuff->beginMarker(makeMarkerInfo(get(RenderGraph::NameTag{}, ctx.g, vertID).c_str(), RASTER_COLOR));
|
||||
#endif
|
||||
const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, vertID);
|
||||
if (!renderData.custom.empty()) {
|
||||
const auto& passes = ctx.ppl->custom.renderPasses;
|
||||
@@ -1193,7 +1192,7 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
|
||||
if (subpass.subpassID) {
|
||||
ctx.cmdBuff->nextSubpass();
|
||||
}
|
||||
//ctx.cmdBuff->setViewport(subpass);
|
||||
// ctx.cmdBuff->setViewport(subpass);
|
||||
tryBindPerPassDescriptorSet(vertID);
|
||||
ctx.subpassIndex = subpass.subpassID;
|
||||
// noop
|
||||
@@ -1393,16 +1392,14 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
|
||||
tryBindPerPassDescriptorSet(sceneID);
|
||||
}
|
||||
const auto* scene = camera->getScene();
|
||||
const auto& queueDesc = ctx.context.sceneCulling.sceneQueryIndex.at(sceneID);
|
||||
const auto& queue = ctx.context.sceneCulling.renderQueues[queueDesc.renderQueueTarget];
|
||||
queue.opaqueQueue.recordCommandBuffer(
|
||||
ctx.device, camera, ctx.currentPass, ctx.cmdBuff, 0);
|
||||
queue.opaqueInstancingQueue.recordCommandBuffer(
|
||||
ctx.currentPass, ctx.cmdBuff);
|
||||
queue.transparentQueue.recordCommandBuffer(
|
||||
ctx.device, camera, ctx.currentPass, ctx.cmdBuff, 0);
|
||||
queue.transparentInstancingQueue.recordCommandBuffer(
|
||||
ctx.currentPass, ctx.cmdBuff);
|
||||
const auto& queueDesc = ctx.context.sceneCulling.renderQueueIndex.at(sceneID);
|
||||
const auto& queue = ctx.context.sceneCulling.renderQueues[queueDesc.renderQueueTarget.value];
|
||||
|
||||
queue.recordCommands(ctx.cmdBuff, ctx.currentPass, 0);
|
||||
|
||||
if (any(sceneData.flags & SceneFlags::REFLECTION_PROBE)) {
|
||||
queue.probeQueue.removeMacro();
|
||||
}
|
||||
if (any(sceneData.flags & SceneFlags::UI)) {
|
||||
submitUICommands(ctx.currentPass,
|
||||
ctx.currentPassLayoutID, camera, ctx.cmdBuff);
|
||||
@@ -1492,10 +1489,6 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
|
||||
ctx.cmdBuff->endRenderPass();
|
||||
ctx.currentPass = nullptr;
|
||||
ctx.currentPassLayoutID = LayoutGraphData::null_vertex();
|
||||
|
||||
#if CC_DEBUG
|
||||
ctx.cmdBuff->endMarker();
|
||||
#endif
|
||||
}
|
||||
void end(const RasterSubpass& subpass, RenderGraph::vertex_descriptor vertID) const { // NOLINT(readability-convert-member-functions-to-static)
|
||||
const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, vertID);
|
||||
@@ -1687,6 +1680,9 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
|
||||
visitObject(
|
||||
vertID, ctx.g,
|
||||
[&](const RasterPass& pass) {
|
||||
#if CC_DEBUG
|
||||
ctx.cmdBuff->beginMarker(makeMarkerInfo(get(RenderGraph::NameTag{}, ctx.g, vertID).c_str(), RASTER_COLOR));
|
||||
#endif
|
||||
mountResources(pass);
|
||||
{
|
||||
const auto& layoutName = get(RenderGraph::LayoutTag{}, ctx.g, vertID);
|
||||
@@ -1695,9 +1691,15 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
|
||||
}
|
||||
// update UniformBuffers and DescriptorSets in all children
|
||||
{
|
||||
#if CC_DEBUG
|
||||
ctx.cmdBuff->beginMarker(makeMarkerInfo("Upload", RASTER_UPLOAD_COLOR));
|
||||
#endif
|
||||
auto colors = ctx.g.colors(ctx.scratch);
|
||||
RenderGraphUploadVisitor visitor{{}, ctx};
|
||||
boost::depth_first_visit(gv, vertID, visitor, get(colors, ctx.g));
|
||||
#if CC_DEBUG
|
||||
ctx.cmdBuff->endMarker();
|
||||
#endif
|
||||
}
|
||||
if (pass.showStatistics) {
|
||||
const auto* profiler = ctx.ppl->getProfiler();
|
||||
@@ -1803,6 +1805,9 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
|
||||
[&](const RasterPass& pass) {
|
||||
end(pass, vertID);
|
||||
rearBarriers(vertID);
|
||||
#if CC_DEBUG
|
||||
ctx.cmdBuff->endMarker();
|
||||
#endif
|
||||
},
|
||||
[&](const RasterSubpass& subpass) {
|
||||
end(subpass, vertID);
|
||||
@@ -1987,7 +1992,7 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
|
||||
{
|
||||
auto& context = ppl.nativeContext;
|
||||
auto& sceneCulling = context.sceneCulling;
|
||||
sceneCulling.buildRenderQueues(rg, lg, *ppl.pipelineSceneData);
|
||||
sceneCulling.buildRenderQueues(rg, lg, ppl);
|
||||
auto& group = ppl.nativeContext.resourceGroups[context.nextFenceValue];
|
||||
// notice: we cannot use ranged-for of sceneCulling.renderQueues
|
||||
CC_EXPECTS(sceneCulling.numRenderQueues <= sceneCulling.renderQueues.size());
|
||||
@@ -1997,6 +2002,16 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
|
||||
}
|
||||
}
|
||||
|
||||
// light manangement
|
||||
{
|
||||
auto& ctx = ppl.nativeContext;
|
||||
ctx.lightResources.clear();
|
||||
ctx.lightResources.buildLights(
|
||||
ctx.sceneCulling,
|
||||
ppl.pipelineSceneData->isHDR(),
|
||||
ppl.pipelineSceneData->getShadows());
|
||||
}
|
||||
|
||||
// gpu driven
|
||||
if constexpr (ENABLE_GPU_DRIVEN) {
|
||||
// TODO(jilin): consider populating renderSceneResources here
|
||||
@@ -2018,6 +2033,11 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
|
||||
|
||||
// upload buffers
|
||||
{
|
||||
auto& ctx = ppl.nativeContext;
|
||||
#if CC_DEBUG
|
||||
submit.primaryCommandBuffer->beginMarker(makeMarkerInfo("Internal Upload", RASTER_UPLOAD_COLOR));
|
||||
#endif
|
||||
// scene
|
||||
const auto& sceneCulling = ppl.nativeContext.sceneCulling;
|
||||
for (uint32_t queueID = 0; queueID != sceneCulling.numRenderQueues; ++queueID) {
|
||||
// notice: we cannot use ranged-for of sceneCulling.renderQueues
|
||||
@@ -2026,6 +2046,13 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) {
|
||||
queue.opaqueInstancingQueue.uploadBuffers(submit.primaryCommandBuffer);
|
||||
queue.transparentInstancingQueue.uploadBuffers(submit.primaryCommandBuffer);
|
||||
}
|
||||
|
||||
// lights
|
||||
ctx.lightResources.buildLightBuffer(submit.primaryCommandBuffer);
|
||||
ctx.lightResources.tryUpdateRenderSceneLocalDescriptorSet(sceneCulling);
|
||||
#if CC_DEBUG
|
||||
submit.primaryCommandBuffer->endMarker();
|
||||
#endif
|
||||
}
|
||||
|
||||
ccstd::pmr::unordered_map<
|
||||
|
||||
@@ -32,8 +32,12 @@
|
||||
#include "cocos/renderer/pipeline/custom/RenderGraphGraphs.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderingModule.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/GslUtils.h"
|
||||
#include "cocos/scene/ReflectionProbe.h"
|
||||
#include "cocos/scene/ReflectionProbeManager.h"
|
||||
#include "cocos/scene/RenderScene.h"
|
||||
#include "cocos/scene/RenderWindow.h"
|
||||
#include "pipeline/custom/RenderInterfaceTypes.h"
|
||||
|
||||
#if CC_USE_DEBUG_RENDERER
|
||||
#include "profiler/DebugRenderer.h"
|
||||
#endif
|
||||
@@ -42,14 +46,14 @@ namespace cc {
|
||||
|
||||
namespace render {
|
||||
|
||||
template<gfx::Format>
|
||||
template <gfx::Format>
|
||||
void addSubresourceNode(ResourceGraph::vertex_descriptor v, const ccstd::string &name, ResourceGraph &resg);
|
||||
|
||||
template <>
|
||||
void addSubresourceNode<gfx::Format::DEPTH_STENCIL>(ResourceGraph::vertex_descriptor v, const ccstd::string &name, ResourceGraph &resg) {
|
||||
const auto& desc = get(ResourceGraph::DescTag{}, resg, v);
|
||||
const auto& traits = get(ResourceGraph::TraitsTag{}, resg, v);
|
||||
const auto& samplerInfo = get(ResourceGraph::SamplerTag{}, resg, v);
|
||||
const auto &desc = get(ResourceGraph::DescTag{}, resg, v);
|
||||
const auto &traits = get(ResourceGraph::TraitsTag{}, resg, v);
|
||||
const auto &samplerInfo = get(ResourceGraph::SamplerTag{}, resg, v);
|
||||
|
||||
SubresourceView view{
|
||||
nullptr,
|
||||
@@ -60,7 +64,6 @@ void addSubresourceNode<gfx::Format::DEPTH_STENCIL>(ResourceGraph::vertex_descri
|
||||
1, // numArraySlices
|
||||
0, // firstPlane
|
||||
1, // numPlanes
|
||||
desc.viewType,
|
||||
};
|
||||
|
||||
ccstd::string depthName{name};
|
||||
@@ -120,6 +123,7 @@ PipelineCapabilities NativePipeline::getCapabilities() const {
|
||||
|
||||
void NativePipeline::beginSetup() {
|
||||
renderGraph = RenderGraph(get_allocator());
|
||||
builtinCSMs.clear();
|
||||
}
|
||||
|
||||
void NativePipeline::endSetup() {
|
||||
@@ -314,7 +318,7 @@ uint32_t NativePipeline::addTexture(const ccstd::string &name, gfx::TextureType
|
||||
sampleCount,
|
||||
residency == ResourceResidency::MEMORYLESS ? gfx::TextureFlagBit::LAZILY_ALLOCATED : gfx::TextureFlagBit::NONE,
|
||||
flags,
|
||||
type
|
||||
type,
|
||||
};
|
||||
return addVertex(
|
||||
ManagedTextureTag{},
|
||||
@@ -351,15 +355,16 @@ void NativePipeline::updateBuffer(const ccstd::string &name, uint32_t size) {
|
||||
updateResource(name, gfx::Format::UNKNOWN, size, 0, 0, 0, 0, gfx::SampleCount::X1);
|
||||
}
|
||||
|
||||
uint32_t NativePipeline::addResource(const ccstd::string& name, ResourceDimension dimension,
|
||||
uint32_t NativePipeline::addResource(
|
||||
const ccstd::string &name, ResourceDimension dimension,
|
||||
gfx::Format format,
|
||||
uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels,
|
||||
gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) {
|
||||
return dimension == ResourceDimension::BUFFER ? addBuffer(name, width, flags, residency) :
|
||||
addTexture(name, getTextureType(dimension, arraySize), format, width, height, depth, arraySize, mipLevels, sampleCount, flags, residency);
|
||||
return dimension == ResourceDimension::BUFFER ? addBuffer(name, width, flags, residency) : addTexture(name, getTextureType(dimension, arraySize), format, width, height, depth, arraySize, mipLevels, sampleCount, flags, residency);
|
||||
}
|
||||
|
||||
void NativePipeline::updateResource(const ccstd::string& name, gfx::Format format,
|
||||
void NativePipeline::updateResource(
|
||||
const ccstd::string &name, gfx::Format format,
|
||||
uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, // NOLINT(bugprone-easily-swappable-parameters)
|
||||
gfx::SampleCount sampleCount) {
|
||||
auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph);
|
||||
@@ -390,7 +395,7 @@ void NativePipeline::updateResource(const ccstd::string& name, gfx::Format forma
|
||||
resourceGraph.invalidatePersistentRenderPassAndFramebuffer(tex.texture.get());
|
||||
}
|
||||
},
|
||||
[&](ManagedBuffer &/*buffer*/) {
|
||||
[&](ManagedBuffer & /*buffer*/) {
|
||||
desc.width = width;
|
||||
},
|
||||
[](const auto & /*res*/) {});
|
||||
@@ -407,7 +412,7 @@ uint32_t NativePipeline::addStorageTexture(const ccstd::string &name, gfx::Forma
|
||||
desc.format = format;
|
||||
desc.sampleCount = gfx::SampleCount::X1;
|
||||
desc.textureFlags = gfx::TextureFlagBit::NONE;
|
||||
desc.flags = ResourceFlags::STORAGE | ResourceFlags::SAMPLED | ResourceFlags::TRANSFER_SRC | ResourceFlags::TRANSFER_DST;;
|
||||
desc.flags = ResourceFlags::STORAGE | ResourceFlags::SAMPLED | ResourceFlags::TRANSFER_SRC | ResourceFlags::TRANSFER_DST;
|
||||
|
||||
CC_EXPECTS(residency == ResourceResidency::MANAGED || residency == ResourceResidency::MEMORYLESS);
|
||||
|
||||
@@ -684,6 +689,99 @@ void NativePipeline::endFrame() {
|
||||
// noop
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
gfx::LoadOp getLoadOpOfClearFlag(gfx::ClearFlagBit clearFlag, AttachmentType attachment) {
|
||||
gfx::LoadOp loadOp = gfx::LoadOp::CLEAR;
|
||||
if (!(clearFlag & gfx::ClearFlagBit::COLOR) && attachment == AttachmentType::RENDER_TARGET) {
|
||||
if (static_cast<uint32_t>(clearFlag) & cc::scene::Camera::SKYBOX_FLAG) {
|
||||
loadOp = gfx::LoadOp::CLEAR;
|
||||
} else {
|
||||
loadOp = gfx::LoadOp::LOAD;
|
||||
}
|
||||
}
|
||||
if ((clearFlag & gfx::ClearFlagBit::DEPTH_STENCIL) != gfx::ClearFlagBit::DEPTH_STENCIL && attachment == AttachmentType::DEPTH_STENCIL) {
|
||||
if (!(clearFlag & gfx::ClearFlagBit::DEPTH)) {
|
||||
loadOp = gfx::LoadOp::LOAD;
|
||||
}
|
||||
if (!(clearFlag & gfx::ClearFlagBit::STENCIL)) {
|
||||
loadOp = gfx::LoadOp::LOAD;
|
||||
}
|
||||
}
|
||||
return loadOp;
|
||||
}
|
||||
|
||||
void updateCameraUBO(Setter &setter, const scene::Camera *camera, NativePipeline &ppl) {
|
||||
auto sceneData = ppl.pipelineSceneData;
|
||||
auto *skybox = sceneData->getSkybox();
|
||||
setter.setBuiltinCameraConstants(camera);
|
||||
}
|
||||
|
||||
void buildReflectionProbePass(
|
||||
const scene::Camera *camera,
|
||||
render::NativePipeline *pipeline,
|
||||
const scene::ReflectionProbe *probe,
|
||||
scene::RenderWindow *renderWindow,
|
||||
int faceIdx) {
|
||||
const std::string cameraName = "Camera" + std::to_string(faceIdx);
|
||||
const auto &area = probe->renderArea();
|
||||
const auto width = static_cast<uint32_t>(area.x);
|
||||
const auto height = static_cast<uint32_t>(area.y);
|
||||
const auto *probeCamera = probe->getCamera();
|
||||
const std::string probePassRTName = "reflectionProbePassColor" + cameraName;
|
||||
const std::string probePassDSName = "reflectionProbePassDS" + cameraName;
|
||||
if (!pipeline->containsResource(probePassRTName)) {
|
||||
pipeline->addRenderWindow(probePassRTName, gfx::Format::RGBA8, width, height, renderWindow);
|
||||
pipeline->addDepthStencil(probePassDSName, gfx::Format::DEPTH_STENCIL, width, height, ResourceResidency::EXTERNAL);
|
||||
}
|
||||
pipeline->updateRenderWindow(probePassRTName, renderWindow);
|
||||
pipeline->updateDepthStencil(probePassDSName, width, height, gfx::Format::DEPTH_STENCIL);
|
||||
std::unique_ptr<RenderPassBuilder> passBuilder(pipeline->addRenderPass(width, height, "default"));
|
||||
passBuilder->setName("ReflectionProbePass" + std::to_string(faceIdx));
|
||||
gfx::Viewport currViewport{};
|
||||
currViewport.width = width;
|
||||
currViewport.height = height;
|
||||
passBuilder->setViewport(currViewport);
|
||||
gfx::Color clearColor{};
|
||||
clearColor.x = probeCamera->getClearColor().x;
|
||||
clearColor.y = probeCamera->getClearColor().y;
|
||||
clearColor.z = probeCamera->getClearColor().z;
|
||||
clearColor.w = probeCamera->getClearColor().w;
|
||||
passBuilder->addRenderTarget(
|
||||
probePassRTName,
|
||||
getLoadOpOfClearFlag(probeCamera->getClearFlag(), AttachmentType::RENDER_TARGET),
|
||||
gfx::StoreOp::STORE,
|
||||
clearColor);
|
||||
passBuilder->addDepthStencil(
|
||||
probePassDSName,
|
||||
getLoadOpOfClearFlag(probeCamera->getClearFlag(), AttachmentType::DEPTH_STENCIL),
|
||||
gfx::StoreOp::STORE,
|
||||
probeCamera->getClearDepth(),
|
||||
probeCamera->getClearStencil(),
|
||||
probeCamera->getClearFlag());
|
||||
std::unique_ptr<RenderQueueBuilder> queueBuilder(
|
||||
passBuilder->addQueue(QueueHint::RENDER_OPAQUE, "reflect-map"));
|
||||
LightInfo lightInfo{};
|
||||
lightInfo.probe = const_cast<scene::ReflectionProbe *>(probe);
|
||||
queueBuilder->addSceneOfCamera(const_cast<scene::Camera *>(camera), lightInfo, SceneFlags::REFLECTION_PROBE | SceneFlags::OPAQUE_OBJECT);
|
||||
updateCameraUBO(*queueBuilder, probeCamera, *pipeline);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void NativePipeline::addBuiltinReflectionProbePass(const scene::Camera *camera) {
|
||||
const auto *reflectProbeManager = scene::ReflectionProbeManager::getInstance();
|
||||
if (!reflectProbeManager) return;
|
||||
const auto &probes = reflectProbeManager->getAllProbes();
|
||||
for (auto *probe : probes) {
|
||||
if (probe->needRender()) {
|
||||
if (probe->getProbeType() == scene::ReflectionProbe::ProbeType::PLANAR) {
|
||||
buildReflectionProbePass(camera, this, probe, probe->getRealtimePlanarTexture()->getWindow(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RenderPassBuilder *NativePipeline::addRenderPass(
|
||||
uint32_t width, uint32_t height,
|
||||
const ccstd::string &passName) {
|
||||
@@ -782,7 +880,7 @@ void NativePipeline::addMovePass(const ccstd::vector<MovePair> &movePairs) {
|
||||
namespace {
|
||||
|
||||
void setupGpuDrivenResources(
|
||||
NativePipeline& ppl, uint32_t cullingID, ResourceGraph& resg, const std::string &hzbName) {
|
||||
NativePipeline &ppl, uint32_t cullingID, ResourceGraph &resg, const std::string &hzbName) {
|
||||
ccstd::pmr::string name(resg.get_allocator());
|
||||
{ // init resource
|
||||
name = "_GpuInit";
|
||||
@@ -859,7 +957,6 @@ void setupGpuDrivenResources(
|
||||
}
|
||||
}
|
||||
if (!hzbName.empty()) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -894,7 +991,8 @@ void NativePipeline::addBuiltinGpuCullingPass(
|
||||
copyPass.copyPairs.emplace_back(std::move(copyPair));
|
||||
}
|
||||
|
||||
auto copyID = addVertex2(CopyTag{},
|
||||
auto copyID = addVertex2(
|
||||
CopyTag{},
|
||||
std::forward_as_tuple("CopyInitialIndirectBuffer"),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(),
|
||||
@@ -911,7 +1009,7 @@ void NativePipeline::addBuiltinGpuCullingPass(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(drawIndirectBuffer),
|
||||
std::forward_as_tuple());
|
||||
auto& view = res.first->second.emplace_back();
|
||||
auto &view = res.first->second.emplace_back();
|
||||
view.name = "CCDrawIndirectBuffer";
|
||||
view.accessType = AccessType::WRITE;
|
||||
view.shaderStageFlags = gfx::ShaderStageFlagBit::COMPUTE;
|
||||
@@ -921,7 +1019,7 @@ void NativePipeline::addBuiltinGpuCullingPass(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(drawInstanceBuffer),
|
||||
std::forward_as_tuple());
|
||||
auto& view = res.first->second.emplace_back();
|
||||
auto &view = res.first->second.emplace_back();
|
||||
view.name = "CCDrawInstanceBuffer";
|
||||
view.accessType = AccessType::WRITE;
|
||||
view.shaderStageFlags = gfx::ShaderStageFlagBit::COMPUTE;
|
||||
@@ -931,13 +1029,14 @@ void NativePipeline::addBuiltinGpuCullingPass(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(visibilityBuffer),
|
||||
std::forward_as_tuple());
|
||||
auto& view = res.first->second.emplace_back();
|
||||
auto &view = res.first->second.emplace_back();
|
||||
view.name = "CCVisibilityBuffer";
|
||||
view.accessType = AccessType::WRITE;
|
||||
view.shaderStageFlags = gfx::ShaderStageFlagBit::COMPUTE;
|
||||
}
|
||||
|
||||
auto computePassID = addVertex2(ComputeTag{},
|
||||
auto computePassID = addVertex2(
|
||||
ComputeTag{},
|
||||
std::forward_as_tuple("Scene"),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(),
|
||||
@@ -1096,6 +1195,7 @@ bool NativePipeline::activate(gfx::Swapchain *swapchainIn) {
|
||||
const auto &lg = programLibrary->layoutGraph;
|
||||
const auto numNodes = num_vertices(lg);
|
||||
nativeContext.layoutGraphResources.reserve(numNodes);
|
||||
nativeContext.lightResources.init(*programLibrary, device, 16);
|
||||
|
||||
for (uint32_t i = 0; i != numNodes; ++i) {
|
||||
auto &node = nativeContext.layoutGraphResources.emplace_back();
|
||||
|
||||
@@ -29,17 +29,35 @@
|
||||
*/
|
||||
// clang-format off
|
||||
#pragma once
|
||||
#include "cocos/base/std/hash/hash.h"
|
||||
#include "cocos/base/std/variant.h"
|
||||
#include "cocos/renderer/pipeline/InstancedBuffer.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativeFwd.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace scene {
|
||||
|
||||
class ReflectionProbe;
|
||||
|
||||
} // namespace scene
|
||||
|
||||
namespace render {
|
||||
|
||||
template <class T>
|
||||
using Array4 = std::array<T, 4>;
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
#include "cocos/base/std/hash/hash.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace render {
|
||||
|
||||
class NativeRenderNode;
|
||||
class NativeSetter;
|
||||
class NativeSceneBuilder;
|
||||
class NativeRenderSubpassBuilderImpl;
|
||||
class NativeRenderQueueBuilder;
|
||||
class NativeRenderSubpassBuilder;
|
||||
@@ -51,6 +69,7 @@ class NativeComputeQueueBuilder;
|
||||
class NativeComputePassBuilder;
|
||||
struct RenderInstancingQueue;
|
||||
struct DrawInstance;
|
||||
struct ProbeHelperQueue;
|
||||
struct RenderDrawQueue;
|
||||
struct NativeRenderQueue;
|
||||
struct ResourceGroup;
|
||||
@@ -64,13 +83,23 @@ struct QuadResource;
|
||||
enum class ResourceType;
|
||||
|
||||
struct SceneResource;
|
||||
struct CullingKey;
|
||||
struct CullingQueries;
|
||||
struct FrustumCullingKey;
|
||||
struct FrustumCullingID;
|
||||
struct FrustumCulling;
|
||||
struct LightBoundsCullingID;
|
||||
struct LightBoundsCullingKey;
|
||||
struct LightBoundsCulling;
|
||||
struct NativeRenderQueueID;
|
||||
struct NativeRenderQueueDesc;
|
||||
struct LightBoundsCullingResult;
|
||||
struct SceneCulling;
|
||||
struct LightResource;
|
||||
struct NativeRenderContext;
|
||||
class NativeProgramLibrary;
|
||||
struct PipelineCustomization;
|
||||
struct BuiltinShadowTransform;
|
||||
struct BuiltinCascadedShadowMapKey;
|
||||
struct BuiltinCascadedShadowMap;
|
||||
class NativePipeline;
|
||||
class NativeProgramProxy;
|
||||
class NativeRenderingModule;
|
||||
@@ -82,8 +111,18 @@ class NativeRenderingModule;
|
||||
namespace ccstd {
|
||||
|
||||
template <>
|
||||
struct hash<cc::render::CullingKey> {
|
||||
hash_t operator()(const cc::render::CullingKey& val) const noexcept;
|
||||
struct hash<cc::render::FrustumCullingKey> {
|
||||
hash_t operator()(const cc::render::FrustumCullingKey& val) const noexcept;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<cc::render::FrustumCullingID> {
|
||||
hash_t operator()(const cc::render::FrustumCullingID& val) const noexcept;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<cc::render::LightBoundsCullingKey> {
|
||||
hash_t operator()(const cc::render::LightBoundsCullingKey& val) const noexcept;
|
||||
};
|
||||
|
||||
} // namespace ccstd
|
||||
|
||||
@@ -49,6 +49,15 @@ RenderInstancingQueue::RenderInstancingQueue(RenderInstancingQueue const& rhs, c
|
||||
passInstances(rhs.passInstances, alloc),
|
||||
instanceBuffers(rhs.instanceBuffers, alloc) {}
|
||||
|
||||
ProbeHelperQueue::ProbeHelperQueue(const allocator_type& alloc) noexcept
|
||||
: probeMap(alloc) {}
|
||||
|
||||
ProbeHelperQueue::ProbeHelperQueue(ProbeHelperQueue&& rhs, const allocator_type& alloc)
|
||||
: probeMap(std::move(rhs.probeMap), alloc) {}
|
||||
|
||||
ProbeHelperQueue::ProbeHelperQueue(ProbeHelperQueue const& rhs, const allocator_type& alloc)
|
||||
: probeMap(rhs.probeMap, alloc) {}
|
||||
|
||||
RenderDrawQueue::RenderDrawQueue(const allocator_type& alloc) noexcept
|
||||
: instances(alloc) {}
|
||||
|
||||
@@ -61,12 +70,14 @@ RenderDrawQueue::RenderDrawQueue(RenderDrawQueue const& rhs, const allocator_typ
|
||||
NativeRenderQueue::NativeRenderQueue(const allocator_type& alloc) noexcept
|
||||
: opaqueQueue(alloc),
|
||||
transparentQueue(alloc),
|
||||
probeQueue(alloc),
|
||||
opaqueInstancingQueue(alloc),
|
||||
transparentInstancingQueue(alloc) {}
|
||||
|
||||
NativeRenderQueue::NativeRenderQueue(SceneFlags sceneFlagsIn, uint32_t subpassOrPassLayoutIDIn, const allocator_type& alloc) noexcept
|
||||
: opaqueQueue(alloc),
|
||||
transparentQueue(alloc),
|
||||
probeQueue(alloc),
|
||||
opaqueInstancingQueue(alloc),
|
||||
transparentInstancingQueue(alloc),
|
||||
sceneFlags(sceneFlagsIn),
|
||||
@@ -75,10 +86,12 @@ NativeRenderQueue::NativeRenderQueue(SceneFlags sceneFlagsIn, uint32_t subpassOr
|
||||
NativeRenderQueue::NativeRenderQueue(NativeRenderQueue&& rhs, const allocator_type& alloc)
|
||||
: opaqueQueue(std::move(rhs.opaqueQueue), alloc),
|
||||
transparentQueue(std::move(rhs.transparentQueue), alloc),
|
||||
probeQueue(std::move(rhs.probeQueue), alloc),
|
||||
opaqueInstancingQueue(std::move(rhs.opaqueInstancingQueue), alloc),
|
||||
transparentInstancingQueue(std::move(rhs.transparentInstancingQueue), alloc),
|
||||
sceneFlags(rhs.sceneFlags),
|
||||
subpassOrPassLayoutID(rhs.subpassOrPassLayoutID) {}
|
||||
subpassOrPassLayoutID(rhs.subpassOrPassLayoutID),
|
||||
lightByteOffset(rhs.lightByteOffset) {}
|
||||
|
||||
ResourceGroup::ResourceGroup(const allocator_type& alloc) noexcept
|
||||
: instancingBuffers(alloc) {}
|
||||
@@ -159,36 +172,56 @@ SceneResource::SceneResource(SceneResource&& rhs, const allocator_type& alloc)
|
||||
storageBuffers(std::move(rhs.storageBuffers), alloc),
|
||||
storageImages(std::move(rhs.storageImages), alloc) {}
|
||||
|
||||
CullingQueries::CullingQueries(const allocator_type& alloc) noexcept
|
||||
: culledResultIndex(alloc) {}
|
||||
FrustumCulling::FrustumCulling(const allocator_type& alloc) noexcept
|
||||
: resultIndex(alloc) {}
|
||||
|
||||
CullingQueries::CullingQueries(CullingQueries&& rhs, const allocator_type& alloc)
|
||||
: culledResultIndex(std::move(rhs.culledResultIndex), alloc) {}
|
||||
FrustumCulling::FrustumCulling(FrustumCulling&& rhs, const allocator_type& alloc)
|
||||
: resultIndex(std::move(rhs.resultIndex), alloc) {}
|
||||
|
||||
CullingQueries::CullingQueries(CullingQueries const& rhs, const allocator_type& alloc)
|
||||
: culledResultIndex(rhs.culledResultIndex, alloc) {}
|
||||
FrustumCulling::FrustumCulling(FrustumCulling const& rhs, const allocator_type& alloc)
|
||||
: resultIndex(rhs.resultIndex, alloc) {}
|
||||
|
||||
LightBoundsCulling::LightBoundsCulling(const allocator_type& alloc) noexcept
|
||||
: resultIndex(alloc) {}
|
||||
|
||||
LightBoundsCulling::LightBoundsCulling(LightBoundsCulling&& rhs, const allocator_type& alloc)
|
||||
: resultIndex(std::move(rhs.resultIndex), alloc) {}
|
||||
|
||||
LightBoundsCulling::LightBoundsCulling(LightBoundsCulling const& rhs, const allocator_type& alloc)
|
||||
: resultIndex(rhs.resultIndex, alloc) {}
|
||||
|
||||
SceneCulling::SceneCulling(const allocator_type& alloc) noexcept
|
||||
: sceneQueries(alloc),
|
||||
culledResults(alloc),
|
||||
: frustumCullings(alloc),
|
||||
frustumCullingResults(alloc),
|
||||
lightBoundsCullings(alloc),
|
||||
lightBoundsCullingResults(alloc),
|
||||
renderQueues(alloc),
|
||||
sceneQueryIndex(alloc) {}
|
||||
renderQueueIndex(alloc) {}
|
||||
|
||||
SceneCulling::SceneCulling(SceneCulling&& rhs, const allocator_type& alloc)
|
||||
: sceneQueries(std::move(rhs.sceneQueries), alloc),
|
||||
culledResults(std::move(rhs.culledResults), alloc),
|
||||
: frustumCullings(std::move(rhs.frustumCullings), alloc),
|
||||
frustumCullingResults(std::move(rhs.frustumCullingResults), alloc),
|
||||
lightBoundsCullings(std::move(rhs.lightBoundsCullings), alloc),
|
||||
lightBoundsCullingResults(std::move(rhs.lightBoundsCullingResults), alloc),
|
||||
renderQueues(std::move(rhs.renderQueues), alloc),
|
||||
sceneQueryIndex(std::move(rhs.sceneQueryIndex), alloc),
|
||||
numCullingQueries(rhs.numCullingQueries),
|
||||
renderQueueIndex(std::move(rhs.renderQueueIndex), alloc),
|
||||
numFrustumCulling(rhs.numFrustumCulling),
|
||||
numLightBoundsCulling(rhs.numLightBoundsCulling),
|
||||
numRenderQueues(rhs.numRenderQueues),
|
||||
gpuCullingPassID(rhs.gpuCullingPassID) {}
|
||||
|
||||
LightResource::LightResource(const allocator_type& alloc) noexcept
|
||||
: cpuBuffer(alloc),
|
||||
lights(alloc),
|
||||
lightIndex(alloc) {}
|
||||
|
||||
NativeRenderContext::NativeRenderContext(std::unique_ptr<gfx::DefaultResource> defaultResourceIn, const allocator_type& alloc) noexcept
|
||||
: defaultResource(std::move(defaultResourceIn)),
|
||||
resourceGroups(alloc),
|
||||
layoutGraphResources(alloc),
|
||||
renderSceneResources(alloc),
|
||||
sceneCulling(alloc) {}
|
||||
sceneCulling(alloc),
|
||||
lightResources(alloc) {}
|
||||
|
||||
NativeProgramLibrary::NativeProgramLibrary(const allocator_type& alloc) noexcept
|
||||
: layoutGraph(alloc),
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "cocos/base/Ptr.h"
|
||||
#include "cocos/base/std/container/string.h"
|
||||
#include "cocos/base/std/hash/hash.h"
|
||||
#include "cocos/core/geometry/AABB.h"
|
||||
#include "cocos/core/geometry/Frustum.h"
|
||||
#include "cocos/renderer/gfx-base/GFXFramebuffer.h"
|
||||
#include "cocos/renderer/gfx-base/GFXRenderPass.h"
|
||||
#include "cocos/renderer/pipeline/GlobalDescriptorSetManager.h"
|
||||
@@ -41,6 +43,7 @@
|
||||
#include "cocos/renderer/pipeline/custom/NativeTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/Map.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/Set.h"
|
||||
#include "cocos/scene/ReflectionProbe.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
@@ -93,8 +96,8 @@ public:
|
||||
void setBuiltinSpotLightConstants(const scene::SpotLight *light, const scene::Camera *camera) /*implements*/;
|
||||
void setBuiltinPointLightConstants(const scene::PointLight *light, const scene::Camera *camera) /*implements*/;
|
||||
void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) /*implements*/;
|
||||
void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light, uint32_t level) /*implements*/;
|
||||
void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) /*implements*/;
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) /*implements*/;
|
||||
void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) /*implements*/;
|
||||
|
||||
void setVec4ArraySize(const ccstd::string& name, uint32_t sz);
|
||||
void setVec4ArrayElem(const ccstd::string& name, const cc::Vec4& vec, uint32_t id);
|
||||
@@ -106,6 +109,88 @@ public:
|
||||
uint32_t layoutID{LayoutGraphData::null_vertex()};
|
||||
};
|
||||
|
||||
class NativeSceneBuilder final : public SceneBuilder, public NativeSetter {
|
||||
public:
|
||||
NativeSceneBuilder(const PipelineRuntime* pipelineRuntimeIn, RenderGraph* renderGraphIn, uint32_t nodeIDIn, const LayoutGraphData* layoutGraphIn, uint32_t layoutIDIn) noexcept
|
||||
: NativeSetter(pipelineRuntimeIn, renderGraphIn, nodeIDIn, layoutGraphIn, layoutIDIn) {}
|
||||
|
||||
ccstd::string getName() const override {
|
||||
return NativeRenderNode::getName();
|
||||
}
|
||||
void setName(const ccstd::string &name) override {
|
||||
NativeRenderNode::setName(name);
|
||||
}
|
||||
void setCustomBehavior(const ccstd::string &name) override {
|
||||
NativeRenderNode::setCustomBehavior(name);
|
||||
}
|
||||
|
||||
void setMat4(const ccstd::string &name, const Mat4 &mat) override {
|
||||
NativeSetter::setMat4(name, mat);
|
||||
}
|
||||
void setQuaternion(const ccstd::string &name, const Quaternion &quat) override {
|
||||
NativeSetter::setQuaternion(name, quat);
|
||||
}
|
||||
void setColor(const ccstd::string &name, const gfx::Color &color) override {
|
||||
NativeSetter::setColor(name, color);
|
||||
}
|
||||
void setVec4(const ccstd::string &name, const Vec4 &vec) override {
|
||||
NativeSetter::setVec4(name, vec);
|
||||
}
|
||||
void setVec2(const ccstd::string &name, const Vec2 &vec) override {
|
||||
NativeSetter::setVec2(name, vec);
|
||||
}
|
||||
void setFloat(const ccstd::string &name, float v) override {
|
||||
NativeSetter::setFloat(name, v);
|
||||
}
|
||||
void setArrayBuffer(const ccstd::string &name, const ArrayBuffer *arrayBuffer) override {
|
||||
NativeSetter::setArrayBuffer(name, arrayBuffer);
|
||||
}
|
||||
void setBuffer(const ccstd::string &name, gfx::Buffer *buffer) override {
|
||||
NativeSetter::setBuffer(name, buffer);
|
||||
}
|
||||
void setTexture(const ccstd::string &name, gfx::Texture *texture) override {
|
||||
NativeSetter::setTexture(name, texture);
|
||||
}
|
||||
void setReadWriteBuffer(const ccstd::string &name, gfx::Buffer *buffer) override {
|
||||
NativeSetter::setReadWriteBuffer(name, buffer);
|
||||
}
|
||||
void setReadWriteTexture(const ccstd::string &name, gfx::Texture *texture) override {
|
||||
NativeSetter::setReadWriteTexture(name, texture);
|
||||
}
|
||||
void setSampler(const ccstd::string &name, gfx::Sampler *sampler) override {
|
||||
NativeSetter::setSampler(name, sampler);
|
||||
}
|
||||
void setBuiltinCameraConstants(const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinCameraConstants(camera);
|
||||
}
|
||||
void setBuiltinShadowMapConstants(const scene::DirectionalLight *light) override {
|
||||
NativeSetter::setBuiltinShadowMapConstants(light);
|
||||
}
|
||||
void setBuiltinDirectionalLightConstants(const scene::DirectionalLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinDirectionalLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinSphereLightConstants(const scene::SphereLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinSphereLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinSpotLightConstants(const scene::SpotLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinSpotLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinPointLightConstants(const scene::PointLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinPointLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) override {
|
||||
NativeSetter::setBuiltinDirectionalLightFrustumConstants(camera, light, csmLevel);
|
||||
}
|
||||
void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightFrustumConstants(light);
|
||||
}
|
||||
|
||||
void useLightFrustum(IntrusivePtr<scene::Light> light, uint32_t csmLevel, const scene::Camera *optCamera) override;
|
||||
};
|
||||
|
||||
class NativeRenderSubpassBuilderImpl : public NativeSetter {
|
||||
public:
|
||||
NativeRenderSubpassBuilderImpl(const PipelineRuntime* pipelineRuntimeIn, RenderGraph* renderGraphIn, uint32_t nodeIDIn, const LayoutGraphData* layoutGraphIn, uint32_t layoutIDIn)
|
||||
@@ -195,17 +280,15 @@ public:
|
||||
void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light, uint32_t level) override {
|
||||
NativeSetter::setBuiltinDirectionalLightViewConstants(light, level);
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) override {
|
||||
NativeSetter::setBuiltinDirectionalLightFrustumConstants(camera, light, csmLevel);
|
||||
}
|
||||
void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightViewConstants(light);
|
||||
void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightFrustumConstants(light);
|
||||
}
|
||||
|
||||
void addSceneOfCamera(scene::Camera *camera, LightInfo light, SceneFlags sceneFlags) override;
|
||||
void addScene(const scene::Camera *camera, SceneFlags sceneFlags, const scene::Light *light) override;
|
||||
void addSceneCulledByDirectionalLight(const scene::Camera *camera, SceneFlags sceneFlags, scene::DirectionalLight *light, uint32_t level) override;
|
||||
void addSceneCulledBySpotLight(const scene::Camera *camera, SceneFlags sceneFlags, scene::SpotLight *light) override;
|
||||
SceneBuilder *addScene(const scene::Camera *camera, SceneFlags sceneFlags, scene::Light *light) override;
|
||||
void addFullscreenQuad(Material *material, uint32_t passID, SceneFlags sceneFlags) override;
|
||||
void addCameraQuad(scene::Camera *camera, Material *material, uint32_t passID, SceneFlags sceneFlags) override;
|
||||
void clearRenderTarget(const ccstd::string &name, const gfx::Color &color) override;
|
||||
@@ -285,11 +368,11 @@ public:
|
||||
void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light, uint32_t level) override {
|
||||
NativeSetter::setBuiltinDirectionalLightViewConstants(light, level);
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) override {
|
||||
NativeSetter::setBuiltinDirectionalLightFrustumConstants(camera, light, csmLevel);
|
||||
}
|
||||
void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightViewConstants(light);
|
||||
void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightFrustumConstants(light);
|
||||
}
|
||||
|
||||
void addRenderTarget(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, gfx::LoadOp loadOp, gfx::StoreOp storeOp, const gfx::Color &color) override {
|
||||
@@ -396,11 +479,11 @@ public:
|
||||
void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light, uint32_t level) override {
|
||||
NativeSetter::setBuiltinDirectionalLightViewConstants(light, level);
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) override {
|
||||
NativeSetter::setBuiltinDirectionalLightFrustumConstants(camera, light, csmLevel);
|
||||
}
|
||||
void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightViewConstants(light);
|
||||
void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightFrustumConstants(light);
|
||||
}
|
||||
|
||||
void addRenderTarget(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName, gfx::LoadOp loadOp, gfx::StoreOp storeOp, const gfx::Color &color) override {
|
||||
@@ -510,11 +593,11 @@ public:
|
||||
void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light, uint32_t level) override {
|
||||
NativeSetter::setBuiltinDirectionalLightViewConstants(light, level);
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) override {
|
||||
NativeSetter::setBuiltinDirectionalLightFrustumConstants(camera, light, csmLevel);
|
||||
}
|
||||
void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightViewConstants(light);
|
||||
void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightFrustumConstants(light);
|
||||
}
|
||||
|
||||
void addRenderTarget(const ccstd::string &name, const ccstd::string &slotName) override;
|
||||
@@ -597,11 +680,11 @@ public:
|
||||
void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light, uint32_t level) override {
|
||||
NativeSetter::setBuiltinDirectionalLightViewConstants(light, level);
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) override {
|
||||
NativeSetter::setBuiltinDirectionalLightFrustumConstants(camera, light, csmLevel);
|
||||
}
|
||||
void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightViewConstants(light);
|
||||
void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightFrustumConstants(light);
|
||||
}
|
||||
|
||||
void addRenderTarget(const ccstd::string &name, gfx::LoadOp loadOp, gfx::StoreOp storeOp, const gfx::Color &color) override;
|
||||
@@ -696,11 +779,11 @@ public:
|
||||
void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light, uint32_t level) override {
|
||||
NativeSetter::setBuiltinDirectionalLightViewConstants(light, level);
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) override {
|
||||
NativeSetter::setBuiltinDirectionalLightFrustumConstants(camera, light, csmLevel);
|
||||
}
|
||||
void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightViewConstants(light);
|
||||
void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightFrustumConstants(light);
|
||||
}
|
||||
|
||||
void addRenderTarget(const ccstd::string &name, gfx::LoadOp loadOp, gfx::StoreOp storeOp, const gfx::Color &color) override;
|
||||
@@ -794,11 +877,11 @@ public:
|
||||
void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light, uint32_t level) override {
|
||||
NativeSetter::setBuiltinDirectionalLightViewConstants(light, level);
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) override {
|
||||
NativeSetter::setBuiltinDirectionalLightFrustumConstants(camera, light, csmLevel);
|
||||
}
|
||||
void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightViewConstants(light);
|
||||
void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightFrustumConstants(light);
|
||||
}
|
||||
|
||||
void addDispatch(uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCountZ, Material *material, uint32_t passID) override;
|
||||
@@ -876,11 +959,11 @@ public:
|
||||
void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override {
|
||||
NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera);
|
||||
}
|
||||
void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light, uint32_t level) override {
|
||||
NativeSetter::setBuiltinDirectionalLightViewConstants(light, level);
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) override {
|
||||
NativeSetter::setBuiltinDirectionalLightFrustumConstants(camera, light, csmLevel);
|
||||
}
|
||||
void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightViewConstants(light);
|
||||
void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) override {
|
||||
NativeSetter::setBuiltinSpotLightFrustumConstants(light);
|
||||
}
|
||||
|
||||
void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler, uint32_t plane) override;
|
||||
@@ -912,9 +995,9 @@ struct RenderInstancingQueue {
|
||||
void sort();
|
||||
void uploadBuffers(gfx::CommandBuffer *cmdBuffer) const;
|
||||
void recordCommandBuffer(
|
||||
gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer,
|
||||
gfx::DescriptorSet *ds = nullptr, uint32_t offset = 0,
|
||||
const ccstd::vector<uint32_t> *dynamicOffsets = nullptr) const;
|
||||
gfx::RenderPass *renderPass, uint32_t subpassIndex,
|
||||
gfx::CommandBuffer *cmdBuffer,
|
||||
uint32_t lightByteOffset = 0xFFFFFFFF) const;
|
||||
|
||||
ccstd::pmr::vector<pipeline::InstancedBuffer*> sortedBatches;
|
||||
PmrUnorderedMap<const scene::Pass*, uint32_t> passInstances;
|
||||
@@ -930,6 +1013,36 @@ struct DrawInstance {
|
||||
uint32_t passIndex{0};
|
||||
};
|
||||
|
||||
struct ProbeHelperQueue {
|
||||
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
|
||||
allocator_type get_allocator() const noexcept { // NOLINT
|
||||
return {probeMap.get_allocator().resource()};
|
||||
}
|
||||
|
||||
ProbeHelperQueue(const allocator_type& alloc) noexcept; // NOLINT
|
||||
ProbeHelperQueue(ProbeHelperQueue&& rhs, const allocator_type& alloc);
|
||||
ProbeHelperQueue(ProbeHelperQueue const& rhs, const allocator_type& alloc);
|
||||
|
||||
ProbeHelperQueue(ProbeHelperQueue&& rhs) noexcept = default;
|
||||
ProbeHelperQueue(ProbeHelperQueue const& rhs) = delete;
|
||||
ProbeHelperQueue& operator=(ProbeHelperQueue&& rhs) = default;
|
||||
ProbeHelperQueue& operator=(ProbeHelperQueue const& rhs) = default;
|
||||
|
||||
static LayoutGraphData::vertex_descriptor getDefaultId(const LayoutGraphData &lg);
|
||||
|
||||
inline void clear() noexcept {
|
||||
probeMap.clear();
|
||||
}
|
||||
|
||||
void removeMacro() const;
|
||||
|
||||
static uint32_t getPassIndexFromLayout(const IntrusivePtr<scene::SubModel>& subModel, LayoutGraphData::vertex_descriptor phaseLayoutId);
|
||||
|
||||
void applyMacro(const LayoutGraphData &lg, const scene::Model& model, LayoutGraphData::vertex_descriptor probeLayoutId);
|
||||
|
||||
ccstd::pmr::vector<scene::SubModel*> probeMap;
|
||||
};
|
||||
|
||||
struct RenderDrawQueue {
|
||||
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
|
||||
allocator_type get_allocator() const noexcept { // NOLINT
|
||||
@@ -948,9 +1061,10 @@ struct RenderDrawQueue {
|
||||
void add(const scene::Model& model, float depth, uint32_t subModelIdx, uint32_t passIdx);
|
||||
void sortOpaqueOrCutout();
|
||||
void sortTransparent();
|
||||
void recordCommandBuffer(gfx::Device *device, const scene::Camera *camera,
|
||||
gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer,
|
||||
uint32_t subpassIndex) const;
|
||||
void recordCommandBuffer(
|
||||
gfx::RenderPass *renderPass, uint32_t subpassIndex,
|
||||
gfx::CommandBuffer *cmdBuffer,
|
||||
uint32_t lightByteOffset = 0xFFFFFFFF) const;
|
||||
|
||||
ccstd::pmr::vector<DrawInstance> instances;
|
||||
};
|
||||
@@ -973,13 +1087,17 @@ struct NativeRenderQueue {
|
||||
void sort();
|
||||
void clear() noexcept;
|
||||
bool empty() const noexcept;
|
||||
void recordCommands(
|
||||
gfx::CommandBuffer *cmdBuffer, gfx::RenderPass *renderPass, uint32_t subpassIndex) const;
|
||||
|
||||
RenderDrawQueue opaqueQueue;
|
||||
RenderDrawQueue transparentQueue;
|
||||
ProbeHelperQueue probeQueue;
|
||||
RenderInstancingQueue opaqueInstancingQueue;
|
||||
RenderInstancingQueue transparentInstancingQueue;
|
||||
SceneFlags sceneFlags{SceneFlags::NONE};
|
||||
uint32_t subpassOrPassLayoutID{0xFFFFFFFF};
|
||||
uint32_t lightByteOffset{0xFFFFFFFF};
|
||||
};
|
||||
|
||||
struct ResourceGroup {
|
||||
@@ -1105,7 +1223,7 @@ struct LayoutGraphNodeResource {
|
||||
LayoutGraphNodeResource& operator=(LayoutGraphNodeResource const& rhs) = delete;
|
||||
void syncResources() noexcept;
|
||||
|
||||
PmrFlatMap<NameLocalID, UniformBlockResource> uniformBuffers;
|
||||
ccstd::pmr::unordered_map<NameLocalID, UniformBlockResource> uniformBuffers;
|
||||
DescriptorSetPool descriptorSetPool;
|
||||
PmrTransparentMap<ccstd::pmr::string, ProgramResource> programResources;
|
||||
};
|
||||
@@ -1146,56 +1264,124 @@ struct SceneResource {
|
||||
ccstd::pmr::unordered_map<NameLocalID, IntrusivePtr<gfx::Texture>> storageImages;
|
||||
};
|
||||
|
||||
struct CullingKey {
|
||||
struct FrustumCullingKey {
|
||||
const scene::Camera* camera{nullptr};
|
||||
const scene::ReflectionProbe* probe{nullptr};
|
||||
const scene::Light* light{nullptr};
|
||||
bool castShadow{false};
|
||||
uint32_t lightLevel{0xFFFFFFFF};
|
||||
bool castShadow{false};
|
||||
};
|
||||
|
||||
inline bool operator==(const CullingKey& lhs, const CullingKey& rhs) noexcept {
|
||||
return std::forward_as_tuple(lhs.camera, lhs.light, lhs.castShadow, lhs.lightLevel) ==
|
||||
std::forward_as_tuple(rhs.camera, rhs.light, rhs.castShadow, rhs.lightLevel);
|
||||
inline bool operator==(const FrustumCullingKey& lhs, const FrustumCullingKey& rhs) noexcept {
|
||||
return std::forward_as_tuple(lhs.camera, lhs.probe, lhs.light, lhs.lightLevel, lhs.castShadow) ==
|
||||
std::forward_as_tuple(rhs.camera, rhs.probe, rhs.light, rhs.lightLevel, rhs.castShadow);
|
||||
}
|
||||
|
||||
inline bool operator!=(const CullingKey& lhs, const CullingKey& rhs) noexcept {
|
||||
inline bool operator!=(const FrustumCullingKey& lhs, const FrustumCullingKey& rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
struct CullingQueries {
|
||||
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
|
||||
allocator_type get_allocator() const noexcept { // NOLINT
|
||||
return {culledResultIndex.get_allocator().resource()};
|
||||
struct FrustumCullingID {
|
||||
explicit operator uint32_t() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
CullingQueries(const allocator_type& alloc) noexcept; // NOLINT
|
||||
CullingQueries(CullingQueries&& rhs, const allocator_type& alloc);
|
||||
CullingQueries(CullingQueries const& rhs, const allocator_type& alloc);
|
||||
uint32_t value{0xFFFFFFFF};
|
||||
};
|
||||
|
||||
CullingQueries(CullingQueries&& rhs) noexcept = default;
|
||||
CullingQueries(CullingQueries const& rhs) = delete;
|
||||
CullingQueries& operator=(CullingQueries&& rhs) = default;
|
||||
CullingQueries& operator=(CullingQueries const& rhs) = default;
|
||||
inline bool operator==(const FrustumCullingID& lhs, const FrustumCullingID& rhs) noexcept {
|
||||
return std::forward_as_tuple(lhs.value) ==
|
||||
std::forward_as_tuple(rhs.value);
|
||||
}
|
||||
|
||||
ccstd::pmr::unordered_map<CullingKey, uint32_t> culledResultIndex;
|
||||
inline bool operator!=(const FrustumCullingID& lhs, const FrustumCullingID& rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
struct FrustumCulling {
|
||||
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
|
||||
allocator_type get_allocator() const noexcept { // NOLINT
|
||||
return {resultIndex.get_allocator().resource()};
|
||||
}
|
||||
|
||||
FrustumCulling(const allocator_type& alloc) noexcept; // NOLINT
|
||||
FrustumCulling(FrustumCulling&& rhs, const allocator_type& alloc);
|
||||
FrustumCulling(FrustumCulling const& rhs, const allocator_type& alloc);
|
||||
|
||||
FrustumCulling(FrustumCulling&& rhs) noexcept = default;
|
||||
FrustumCulling(FrustumCulling const& rhs) = delete;
|
||||
FrustumCulling& operator=(FrustumCulling&& rhs) = default;
|
||||
FrustumCulling& operator=(FrustumCulling const& rhs) = default;
|
||||
|
||||
ccstd::pmr::unordered_map<FrustumCullingKey, FrustumCullingID> resultIndex;
|
||||
};
|
||||
|
||||
struct LightBoundsCullingID {
|
||||
explicit operator uint32_t() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
uint32_t value{0xFFFFFFFF};
|
||||
};
|
||||
|
||||
struct LightBoundsCullingKey {
|
||||
FrustumCullingID frustumCullingID;
|
||||
const scene::Camera* camera{nullptr};
|
||||
const scene::ReflectionProbe* probe{nullptr};
|
||||
const scene::Light* cullingLight{nullptr};
|
||||
};
|
||||
|
||||
inline bool operator==(const LightBoundsCullingKey& lhs, const LightBoundsCullingKey& rhs) noexcept {
|
||||
return std::forward_as_tuple(lhs.frustumCullingID, lhs.camera, lhs.probe, lhs.cullingLight) ==
|
||||
std::forward_as_tuple(rhs.frustumCullingID, rhs.camera, rhs.probe, rhs.cullingLight);
|
||||
}
|
||||
|
||||
inline bool operator!=(const LightBoundsCullingKey& lhs, const LightBoundsCullingKey& rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
struct LightBoundsCulling {
|
||||
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
|
||||
allocator_type get_allocator() const noexcept { // NOLINT
|
||||
return {resultIndex.get_allocator().resource()};
|
||||
}
|
||||
|
||||
LightBoundsCulling(const allocator_type& alloc) noexcept; // NOLINT
|
||||
LightBoundsCulling(LightBoundsCulling&& rhs, const allocator_type& alloc);
|
||||
LightBoundsCulling(LightBoundsCulling const& rhs, const allocator_type& alloc);
|
||||
|
||||
LightBoundsCulling(LightBoundsCulling&& rhs) noexcept = default;
|
||||
LightBoundsCulling(LightBoundsCulling const& rhs) = delete;
|
||||
LightBoundsCulling& operator=(LightBoundsCulling&& rhs) = default;
|
||||
LightBoundsCulling& operator=(LightBoundsCulling const& rhs) = default;
|
||||
|
||||
ccstd::pmr::unordered_map<LightBoundsCullingKey, LightBoundsCullingID> resultIndex;
|
||||
};
|
||||
|
||||
struct NativeRenderQueueID {
|
||||
explicit operator uint32_t() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
uint32_t value{0xFFFFFFFF};
|
||||
};
|
||||
|
||||
struct NativeRenderQueueDesc {
|
||||
NativeRenderQueueDesc() = default;
|
||||
NativeRenderQueueDesc(uint32_t culledSourceIn, uint32_t renderQueueTargetIn, scene::LightType lightTypeIn) noexcept // NOLINT
|
||||
: culledSource(culledSourceIn),
|
||||
renderQueueTarget(renderQueueTargetIn),
|
||||
lightType(lightTypeIn) {}
|
||||
|
||||
uint32_t culledSource{0xFFFFFFFF};
|
||||
uint32_t renderQueueTarget{0xFFFFFFFF};
|
||||
FrustumCullingID frustumCulledResultID;
|
||||
LightBoundsCullingID lightBoundsCulledResultID;
|
||||
NativeRenderQueueID renderQueueTarget;
|
||||
scene::LightType lightType{scene::LightType::UNKNOWN};
|
||||
};
|
||||
|
||||
struct LightBoundsCullingResult {
|
||||
ccstd::vector<const scene::Model*> instances;
|
||||
uint32_t lightByteOffset{0xFFFFFFFF};
|
||||
};
|
||||
|
||||
struct SceneCulling {
|
||||
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
|
||||
allocator_type get_allocator() const noexcept { // NOLINT
|
||||
return {sceneQueries.get_allocator().resource()};
|
||||
return {frustumCullings.get_allocator().resource()};
|
||||
}
|
||||
|
||||
SceneCulling(const allocator_type& alloc) noexcept; // NOLINT
|
||||
@@ -1207,23 +1393,64 @@ struct SceneCulling {
|
||||
SceneCulling& operator=(SceneCulling const& rhs) = delete;
|
||||
|
||||
void clear() noexcept;
|
||||
void buildRenderQueues(const RenderGraph& rg, const LayoutGraphData& lg, const pipeline::PipelineSceneData& pplSceneData);
|
||||
void buildRenderQueues(const RenderGraph& rg, const LayoutGraphData& lg, const NativePipeline& ppl);
|
||||
private:
|
||||
uint32_t getOrCreateSceneCullingQuery(const SceneData& sceneData);
|
||||
uint32_t createRenderQueue(SceneFlags sceneFlags, LayoutGraphData::vertex_descriptor subpassOrPassLayoutID);
|
||||
FrustumCullingID getOrCreateFrustumCulling(const SceneData& sceneData);
|
||||
LightBoundsCullingID getOrCreateLightBoundsCulling(const SceneData& sceneData, FrustumCullingID frustumCullingID);
|
||||
NativeRenderQueueID createRenderQueue(SceneFlags sceneFlags, LayoutGraphData::vertex_descriptor subpassOrPassLayoutID);
|
||||
void collectCullingQueries(const RenderGraph& rg, const LayoutGraphData& lg);
|
||||
void batchCulling(const pipeline::PipelineSceneData& pplSceneData);
|
||||
void batchFrustumCulling(const NativePipeline& ppl);
|
||||
void batchLightBoundsCulling();
|
||||
void fillRenderQueues(const RenderGraph& rg, const pipeline::PipelineSceneData& pplSceneData);
|
||||
public:
|
||||
ccstd::pmr::unordered_map<const scene::RenderScene*, CullingQueries> sceneQueries;
|
||||
ccstd::pmr::vector<ccstd::vector<const scene::Model*>> culledResults;
|
||||
ccstd::pmr::unordered_map<const scene::RenderScene*, FrustumCulling> frustumCullings;
|
||||
ccstd::pmr::vector<ccstd::vector<const scene::Model*>> frustumCullingResults;
|
||||
ccstd::pmr::unordered_map<const scene::RenderScene*, LightBoundsCulling> lightBoundsCullings;
|
||||
ccstd::pmr::vector<LightBoundsCullingResult> lightBoundsCullingResults;
|
||||
ccstd::pmr::vector<NativeRenderQueue> renderQueues;
|
||||
PmrFlatMap<RenderGraph::vertex_descriptor, NativeRenderQueueDesc> sceneQueryIndex;
|
||||
uint32_t numCullingQueries{0};
|
||||
PmrFlatMap<RenderGraph::vertex_descriptor, NativeRenderQueueDesc> renderQueueIndex;
|
||||
uint32_t numFrustumCulling{0};
|
||||
uint32_t numLightBoundsCulling{0};
|
||||
uint32_t numRenderQueues{0};
|
||||
uint32_t gpuCullingPassID{0xFFFFFFFF};
|
||||
};
|
||||
|
||||
struct LightResource {
|
||||
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
|
||||
allocator_type get_allocator() const noexcept { // NOLINT
|
||||
return {cpuBuffer.get_allocator().resource()};
|
||||
}
|
||||
|
||||
LightResource(const allocator_type& alloc) noexcept; // NOLINT
|
||||
LightResource(LightResource&& rhs) = delete;
|
||||
LightResource(LightResource const& rhs) = delete;
|
||||
LightResource& operator=(LightResource&& rhs) = delete;
|
||||
LightResource& operator=(LightResource const& rhs) = delete;
|
||||
|
||||
void init(const NativeProgramLibrary& programLib, gfx::Device* deviceIn, uint32_t maxNumLights);
|
||||
void buildLights(
|
||||
SceneCulling& sceneCulling,
|
||||
bool bHDR,
|
||||
const scene::Shadows* shadowInfo);
|
||||
void tryUpdateRenderSceneLocalDescriptorSet(const SceneCulling& sceneCulling);
|
||||
void clear();
|
||||
|
||||
uint32_t addLight(const scene::Light* light, bool bHDR, float exposure, const scene::Shadows *shadowInfo);
|
||||
void buildLightBuffer(gfx::CommandBuffer* cmdBuffer) const;
|
||||
|
||||
ccstd::pmr::vector<char> cpuBuffer;
|
||||
const NativeProgramLibrary* programLibrary{nullptr};
|
||||
gfx::Device* device{nullptr};
|
||||
uint32_t elementSize{0};
|
||||
uint32_t maxNumLights{16};
|
||||
uint32_t binding{0xFFFFFFFF};
|
||||
bool resized{false};
|
||||
IntrusivePtr<gfx::Buffer> lightBuffer;
|
||||
IntrusivePtr<gfx::Buffer> firstLightBufferView;
|
||||
ccstd::pmr::vector<const scene::Light*> lights;
|
||||
PmrFlatMap<const scene::Light*, uint32_t> lightIndex;
|
||||
};
|
||||
|
||||
struct NativeRenderContext {
|
||||
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
|
||||
allocator_type get_allocator() const noexcept { // NOLINT
|
||||
@@ -1245,6 +1472,7 @@ struct NativeRenderContext {
|
||||
ccstd::pmr::unordered_map<const scene::RenderScene*, SceneResource> renderSceneResources;
|
||||
QuadResource fullscreenQuad;
|
||||
SceneCulling sceneCulling;
|
||||
LightResource lightResources;
|
||||
};
|
||||
|
||||
class NativeProgramLibrary final : public ProgramLibrary {
|
||||
@@ -1314,6 +1542,36 @@ struct PipelineCustomization {
|
||||
PmrTransparentMap<ccstd::pmr::string, std::shared_ptr<CustomRenderCommand>> renderCommands;
|
||||
};
|
||||
|
||||
struct BuiltinShadowTransform {
|
||||
Mat4 shadowView;
|
||||
Mat4 shadowProj;
|
||||
Mat4 shadowViewProj;
|
||||
geometry::Frustum validFrustum;
|
||||
geometry::Frustum splitFrustum;
|
||||
geometry::Frustum lightViewFrustum;
|
||||
geometry::AABB castLightViewBoundingBox;
|
||||
float shadowCameraFar{0};
|
||||
float splitCameraNear{0};
|
||||
float splitCameraFar{0};
|
||||
Vec4 csmAtlas;
|
||||
};
|
||||
|
||||
struct BuiltinCascadedShadowMapKey {
|
||||
const scene::Camera* camera{nullptr};
|
||||
const scene::DirectionalLight* light{nullptr};
|
||||
};
|
||||
|
||||
inline bool operator<(const BuiltinCascadedShadowMapKey& lhs, const BuiltinCascadedShadowMapKey& rhs) noexcept {
|
||||
return std::forward_as_tuple(lhs.camera, lhs.light) <
|
||||
std::forward_as_tuple(rhs.camera, rhs.light);
|
||||
}
|
||||
|
||||
struct BuiltinCascadedShadowMap {
|
||||
Array4<BuiltinShadowTransform> layers;
|
||||
BuiltinShadowTransform specialLayer;
|
||||
float shadowDistance{0};
|
||||
};
|
||||
|
||||
class NativePipeline final : public Pipeline {
|
||||
public:
|
||||
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
|
||||
@@ -1357,18 +1615,18 @@ public:
|
||||
void beginSetup() override;
|
||||
void endSetup() override;
|
||||
bool containsResource(const ccstd::string &name) const override;
|
||||
uint32_t addExternalTexture(const ccstd::string &name, gfx::Texture *texture, ResourceFlags flags) override;
|
||||
void updateExternalTexture(const ccstd::string &name, gfx::Texture *texture) override;
|
||||
uint32_t addRenderWindow(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, scene::RenderWindow *renderWindow) override;
|
||||
void updateRenderWindow(const ccstd::string &name, scene::RenderWindow *renderWindow) override;
|
||||
uint32_t addRenderTarget(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) override;
|
||||
uint32_t addDepthStencil(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) override;
|
||||
void updateRenderTarget(const ccstd::string &name, uint32_t width, uint32_t height, gfx::Format format) override;
|
||||
void updateDepthStencil(const ccstd::string &name, uint32_t width, uint32_t height, gfx::Format format) override;
|
||||
uint32_t addTexture(const ccstd::string &name, gfx::TextureType type, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) override;
|
||||
void updateTexture(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount) override;
|
||||
uint32_t addBuffer(const ccstd::string &name, uint32_t size, ResourceFlags flags, ResourceResidency residency) override;
|
||||
void updateBuffer(const ccstd::string &name, uint32_t size) override;
|
||||
uint32_t addExternalTexture(const ccstd::string &name, gfx::Texture *texture, ResourceFlags flags) override;
|
||||
void updateExternalTexture(const ccstd::string &name, gfx::Texture *texture) override;
|
||||
uint32_t addTexture(const ccstd::string &name, gfx::TextureType type, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) override;
|
||||
void updateTexture(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount) override;
|
||||
uint32_t addResource(const ccstd::string &name, ResourceDimension dimension, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) override;
|
||||
void updateResource(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount) override;
|
||||
void beginFrame() override;
|
||||
@@ -1376,6 +1634,7 @@ public:
|
||||
void endFrame() override;
|
||||
void addResolvePass(const ccstd::vector<ResolvePair> &resolvePairs) override;
|
||||
void addCopyPass(const ccstd::vector<CopyPair> ©Pairs) override;
|
||||
void addBuiltinReflectionProbePass(const scene::Camera *camera) override;
|
||||
gfx::DescriptorSetLayout *getDescriptorSetLayout(const ccstd::string &shaderName, UpdateFrequency freq) override;
|
||||
|
||||
uint32_t addStorageBuffer(const ccstd::string &name, gfx::Format format, uint32_t size, ResourceResidency residency) override;
|
||||
@@ -1424,6 +1683,7 @@ public:
|
||||
NativeRenderContext nativeContext;
|
||||
ResourceGraph resourceGraph;
|
||||
RenderGraph renderGraph;
|
||||
mutable PmrFlatMap<BuiltinCascadedShadowMapKey, BuiltinCascadedShadowMap> builtinCSMs;
|
||||
PipelineStatistics statistics;
|
||||
PipelineCustomization custom;
|
||||
};
|
||||
@@ -1463,12 +1723,28 @@ public:
|
||||
|
||||
namespace ccstd {
|
||||
|
||||
inline hash_t hash<cc::render::CullingKey>::operator()(const cc::render::CullingKey& val) const noexcept {
|
||||
inline hash_t hash<cc::render::FrustumCullingKey>::operator()(const cc::render::FrustumCullingKey& val) const noexcept {
|
||||
hash_t seed = 0;
|
||||
hash_combine(seed, val.camera);
|
||||
hash_combine(seed, val.probe);
|
||||
hash_combine(seed, val.light);
|
||||
hash_combine(seed, val.castShadow);
|
||||
hash_combine(seed, val.lightLevel);
|
||||
hash_combine(seed, val.castShadow);
|
||||
return seed;
|
||||
}
|
||||
|
||||
inline hash_t hash<cc::render::FrustumCullingID>::operator()(const cc::render::FrustumCullingID& val) const noexcept {
|
||||
hash_t seed = 0;
|
||||
hash_combine(seed, val.value);
|
||||
return seed;
|
||||
}
|
||||
|
||||
inline hash_t hash<cc::render::LightBoundsCullingKey>::operator()(const cc::render::LightBoundsCullingKey& val) const noexcept {
|
||||
hash_t seed = 0;
|
||||
hash_combine(seed, val.frustumCullingID);
|
||||
hash_combine(seed, val.camera);
|
||||
hash_combine(seed, val.probe);
|
||||
hash_combine(seed, val.cullingLight);
|
||||
return seed;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ void NativeRenderNode::setCustomBehavior(const ccstd::string &name) { // NOLINT(
|
||||
RenderGraph::vertex_descriptor RenderGraph::getPassID(vertex_descriptor nodeID) const {
|
||||
CC_EXPECTS(nodeID != null_vertex());
|
||||
for (auto parentID = nodeID;
|
||||
parentID != RenderGraph::null_vertex();
|
||||
parentID = parent(nodeID, *this)) {
|
||||
parentID != RenderGraph::null_vertex();
|
||||
parentID = parent(nodeID, *this)) {
|
||||
nodeID = parentID;
|
||||
}
|
||||
CC_ENSURES(nodeID != null_vertex());
|
||||
@@ -690,10 +690,27 @@ ComputeQueueBuilder *NativeComputeSubpassBuilder::addQueue(const ccstd::string &
|
||||
return new NativeComputeQueueBuilder(pipelineRuntime, renderGraph, queueID, layoutGraph, phaseLayoutID);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
CullingFlags makeCullingFlags(const LightInfo &light) {
|
||||
auto cullingFlags = CullingFlags::NONE;
|
||||
if (light.culledByLight) {
|
||||
cullingFlags |= CullingFlags::LIGHT_FRUSTUM;
|
||||
} else {
|
||||
cullingFlags |= CullingFlags::CAMERA_FRUSTUM;
|
||||
if (light.light) {
|
||||
cullingFlags |= CullingFlags::LIGHT_BOUNDS;
|
||||
}
|
||||
}
|
||||
return cullingFlags;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void NativeRenderQueueBuilder::addSceneOfCamera(
|
||||
scene::Camera *camera, LightInfo light, SceneFlags sceneFlags) {
|
||||
const auto *pLight = light.light.get();
|
||||
SceneData scene(camera->getScene(), camera, sceneFlags, light);
|
||||
SceneData scene(camera->getScene(), camera, sceneFlags, light, makeCullingFlags(light), light.light);
|
||||
auto sceneID = addVertex2(
|
||||
SceneTag{},
|
||||
std::forward_as_tuple("Camera"),
|
||||
@@ -712,12 +729,18 @@ void NativeRenderQueueBuilder::addSceneOfCamera(
|
||||
*pipelineRuntime->getPipelineSceneData(),
|
||||
camera->getScene()->getMainLight(), data);
|
||||
|
||||
// notice: if light is not directional light, csm will be nullptr
|
||||
const auto *csm = getBuiltinShadowCSM(
|
||||
*pipelineRuntime, *camera,
|
||||
dynamic_cast<const scene::DirectionalLight *>(pLight));
|
||||
|
||||
if (any(sceneFlags & SceneFlags::SHADOW_CASTER)) {
|
||||
if (pLight) {
|
||||
setShadowUBOLightView(
|
||||
pipelineRuntime->getDevice(),
|
||||
*layoutGraph,
|
||||
*pipelineRuntime->getPipelineSceneData(),
|
||||
csm, // csm might be nullptr
|
||||
*pLight, light.level, data);
|
||||
}
|
||||
} else {
|
||||
@@ -736,23 +759,108 @@ void NativeRenderQueueBuilder::addSceneOfCamera(
|
||||
data);
|
||||
}
|
||||
|
||||
void NativeRenderQueueBuilder::addScene(const scene::Camera *camera, SceneFlags sceneFlags, const scene::Light *light) {
|
||||
std::ignore = light;
|
||||
SceneData data(camera->getScene(), camera, sceneFlags, LightInfo{});
|
||||
void NativeSceneBuilder::useLightFrustum(
|
||||
IntrusivePtr<scene::Light> light, uint32_t csmLevel, const scene::Camera *optCamera) {
|
||||
auto &sceneData = get(SceneTag{}, nodeID, *renderGraph);
|
||||
sceneData.light.light = light;
|
||||
sceneData.light.level = csmLevel;
|
||||
sceneData.light.culledByLight = true;
|
||||
if (optCamera) {
|
||||
sceneData.camera = optCamera;
|
||||
}
|
||||
|
||||
auto sceneID = addVertex2(
|
||||
// Disable camera frustum projection
|
||||
sceneData.cullingFlags &= ~CullingFlags::CAMERA_FRUSTUM;
|
||||
|
||||
// Enable light frustum projection
|
||||
sceneData.cullingFlags |= CullingFlags::LIGHT_FRUSTUM;
|
||||
|
||||
if (any(sceneData.flags & SceneFlags::NON_BUILTIN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (light->getType()) {
|
||||
case scene::LightType::DIRECTIONAL: {
|
||||
setBuiltinDirectionalLightFrustumConstants(
|
||||
sceneData.camera, dynamic_cast<const scene::DirectionalLight *>(light.get()), csmLevel);
|
||||
} break;
|
||||
case scene::LightType::SPOT: {
|
||||
setBuiltinSpotLightFrustumConstants(
|
||||
dynamic_cast<const scene::SpotLight *>(light.get()));
|
||||
} break;
|
||||
default:
|
||||
// noop
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SceneBuilder *NativeRenderQueueBuilder::addScene(
|
||||
const scene::Camera *camera, SceneFlags sceneFlags, scene::Light *light) {
|
||||
const auto sceneID = addVertex2(
|
||||
SceneTag{},
|
||||
std::forward_as_tuple("Scene"),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(std::move(data)),
|
||||
std::forward_as_tuple(
|
||||
camera->getScene(), // Scene and camera should be decoupled.
|
||||
camera, // They are coupled for now.
|
||||
sceneFlags,
|
||||
LightInfo{nullptr, 0},
|
||||
// Objects are projected to camera by default and are culled further if light is available.
|
||||
light ? CullingFlags::CAMERA_FRUSTUM | CullingFlags::LIGHT_BOUNDS
|
||||
: CullingFlags::CAMERA_FRUSTUM,
|
||||
light),
|
||||
*renderGraph, nodeID);
|
||||
CC_ENSURES(sceneID != RenderGraph::null_vertex());
|
||||
|
||||
auto builder = std::make_unique<NativeSceneBuilder>(
|
||||
pipelineRuntime,
|
||||
renderGraph,
|
||||
sceneID,
|
||||
layoutGraph,
|
||||
layoutID);
|
||||
|
||||
if (!any(sceneFlags & SceneFlags::NON_BUILTIN)) {
|
||||
// objects are projected to camera, set camera ubo
|
||||
builder->setBuiltinCameraConstants(camera);
|
||||
|
||||
if (light) {
|
||||
switch (light->getType()) {
|
||||
case scene::LightType::DIRECTIONAL: {
|
||||
const auto *pDirLight = dynamic_cast<const scene::DirectionalLight *>(light);
|
||||
builder->setBuiltinDirectionalLightConstants(pDirLight, camera);
|
||||
} break;
|
||||
case scene::LightType::SPHERE: {
|
||||
const auto *pSphereLight = dynamic_cast<const scene::SphereLight *>(light);
|
||||
builder->setBuiltinSphereLightConstants(pSphereLight, camera);
|
||||
} break;
|
||||
case scene::LightType::SPOT: {
|
||||
const auto *pSpotLight = dynamic_cast<const scene::SpotLight *>(light);
|
||||
builder->setBuiltinSpotLightConstants(pSpotLight, camera);
|
||||
} break;
|
||||
case scene::LightType::POINT: {
|
||||
const auto *pPointLight = dynamic_cast<const scene::PointLight *>(light);
|
||||
builder->setBuiltinPointLightConstants(pPointLight, camera);
|
||||
} break;
|
||||
default:
|
||||
// noop
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// set builtin legacy ubo
|
||||
auto &data = get(RenderGraph::DataTag{}, *renderGraph, sceneID);
|
||||
setLegacyTextureUBOView(
|
||||
*pipelineRuntime->getDevice(),
|
||||
*layoutGraph,
|
||||
*pipelineRuntime->getPipelineSceneData(),
|
||||
data);
|
||||
}
|
||||
|
||||
if (any(sceneFlags & SceneFlags::GPU_DRIVEN)) {
|
||||
const auto passID = renderGraph->getPassID(nodeID);
|
||||
const auto cullingID = dynamic_cast<const NativePipeline*>(pipelineRuntime)->nativeContext.sceneCulling.gpuCullingPassID;
|
||||
const auto cullingID = dynamic_cast<const NativePipeline *>(pipelineRuntime)->nativeContext.sceneCulling.gpuCullingPassID;
|
||||
CC_EXPECTS(cullingID != 0xFFFFFFFF);
|
||||
if (holds<RasterPassTag>(passID, *renderGraph)) {
|
||||
ccstd::pmr::string drawIndirectBuffer("CCDrawIndirectBuffer");
|
||||
@@ -760,14 +868,14 @@ void NativeRenderQueueBuilder::addScene(const scene::Camera *camera, SceneFlags
|
||||
ccstd::pmr::string drawInstanceBuffer("CCDrawInstanceBuffer");
|
||||
drawInstanceBuffer.append(std::to_string(cullingID));
|
||||
|
||||
auto& rasterPass = get(RasterPassTag{}, passID, *renderGraph);
|
||||
auto &rasterPass = get(RasterPassTag{}, passID, *renderGraph);
|
||||
if (rasterPass.computeViews.find(drawIndirectBuffer) != rasterPass.computeViews.end()) {
|
||||
auto res = rasterPass.computeViews.emplace(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(drawIndirectBuffer),
|
||||
std::forward_as_tuple());
|
||||
CC_ENSURES(res.second);
|
||||
auto& view = res.first->second.emplace_back();
|
||||
auto &view = res.first->second.emplace_back();
|
||||
view.name = "CCDrawIndirectBuffer";
|
||||
view.accessType = AccessType::READ;
|
||||
view.shaderStageFlags = gfx::ShaderStageFlagBit::VERTEX | gfx::ShaderStageFlagBit::FRAGMENT;
|
||||
@@ -778,49 +886,15 @@ void NativeRenderQueueBuilder::addScene(const scene::Camera *camera, SceneFlags
|
||||
std::forward_as_tuple(drawInstanceBuffer),
|
||||
std::forward_as_tuple());
|
||||
CC_ENSURES(res.second);
|
||||
auto& view = res.first->second.emplace_back();
|
||||
auto &view = res.first->second.emplace_back();
|
||||
view.name = "CCDrawInstanceBuffer";
|
||||
view.accessType = AccessType::READ;
|
||||
view.shaderStageFlags = gfx::ShaderStageFlagBit::VERTEX | gfx::ShaderStageFlagBit::FRAGMENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NativeRenderQueueBuilder::addSceneCulledByDirectionalLight(
|
||||
const scene::Camera *camera, SceneFlags sceneFlags,
|
||||
scene::DirectionalLight *light, uint32_t level) {
|
||||
CC_EXPECTS(light);
|
||||
CC_EXPECTS(light->getType() != scene::LightType::UNKNOWN);
|
||||
SceneData data(camera->getScene(), camera, sceneFlags, LightInfo{light, level});
|
||||
|
||||
auto sceneID = addVertex2(
|
||||
SceneTag{},
|
||||
std::forward_as_tuple("Scene"),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(std::move(data)),
|
||||
*renderGraph, nodeID);
|
||||
CC_ENSURES(sceneID != RenderGraph::null_vertex());
|
||||
}
|
||||
|
||||
void NativeRenderQueueBuilder::addSceneCulledBySpotLight(
|
||||
const scene::Camera *camera, SceneFlags sceneFlags,
|
||||
scene::SpotLight *light) {
|
||||
CC_EXPECTS(light);
|
||||
CC_EXPECTS(light->getType() != scene::LightType::UNKNOWN);
|
||||
SceneData data(camera->getScene(), camera, sceneFlags, LightInfo{light, 0});
|
||||
|
||||
auto sceneID = addVertex2(
|
||||
SceneTag{},
|
||||
std::forward_as_tuple("Scene"),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(std::move(data)),
|
||||
*renderGraph, nodeID);
|
||||
CC_ENSURES(sceneID != RenderGraph::null_vertex());
|
||||
return builder.release();
|
||||
}
|
||||
|
||||
void NativeRenderQueueBuilder::addFullscreenQuad(
|
||||
|
||||
@@ -26,13 +26,83 @@
|
||||
#include <iterator>
|
||||
#include "NativePipelineTypes.h"
|
||||
#include "cocos/renderer/pipeline/Define.h"
|
||||
#include "cocos/renderer/pipeline/InstancedBuffer.h"
|
||||
#include "cocos/renderer/pipeline/PipelineStateManager.h"
|
||||
#include "cocos/renderer/pipeline/custom/LayoutGraphGraphs.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/GslUtils.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace render {
|
||||
|
||||
LayoutGraphData::vertex_descriptor ProbeHelperQueue::getDefaultId(const LayoutGraphData &lg) {
|
||||
const auto passID = locate(LayoutGraphData::null_vertex(), "default", lg);
|
||||
CC_ENSURES(passID != LayoutGraphData::null_vertex());
|
||||
const auto phaseID = locate(passID, "default", lg);
|
||||
CC_ENSURES(phaseID != LayoutGraphData::null_vertex());
|
||||
return phaseID;
|
||||
}
|
||||
|
||||
void ProbeHelperQueue::removeMacro() const {
|
||||
for (auto *subModel : probeMap) {
|
||||
std::vector<cc::scene::IMacroPatch> patches;
|
||||
patches.insert(patches.end(), subModel->getPatches().begin(), subModel->getPatches().end());
|
||||
|
||||
for (int j = 0; j != patches.size(); ++j) {
|
||||
const cc::scene::IMacroPatch &patch = patches[j];
|
||||
if (patch.name == "CC_USE_RGBE_OUTPUT") {
|
||||
patches.erase(patches.begin() + j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
subModel->onMacroPatchesStateChanged(patches);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ProbeHelperQueue::getPassIndexFromLayout(
|
||||
const cc::IntrusivePtr<cc::scene::SubModel> &subModel,
|
||||
LayoutGraphData::vertex_descriptor phaseLayoutId) {
|
||||
const auto &passes = subModel->getPasses();
|
||||
for (uint32_t k = 0; k != passes->size(); ++k) {
|
||||
if (passes->at(k)->getPhaseID() == phaseLayoutId) {
|
||||
return static_cast<int>(k);
|
||||
}
|
||||
}
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
void ProbeHelperQueue::applyMacro(
|
||||
const LayoutGraphData &lg, const cc::scene::Model &model,
|
||||
LayoutGraphData::vertex_descriptor probeLayoutId) {
|
||||
const std::vector<cc::IntrusivePtr<cc::scene::SubModel>> &subModels = model.getSubModels();
|
||||
for (const auto &subModel : subModels) {
|
||||
const bool isTransparent = subModel->getPasses()->at(0)->getBlendState()->targets[0].blend;
|
||||
if (isTransparent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto passIdx = getPassIndexFromLayout(subModel, probeLayoutId);
|
||||
bool bUseReflectPass = true;
|
||||
if (passIdx < 0) {
|
||||
probeLayoutId = getDefaultId(lg);
|
||||
passIdx = getPassIndexFromLayout(subModel, probeLayoutId);
|
||||
bUseReflectPass = false;
|
||||
}
|
||||
if (passIdx < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!bUseReflectPass) {
|
||||
std::vector<cc::scene::IMacroPatch> patches;
|
||||
patches.insert(patches.end(), subModel->getPatches().begin(), subModel->getPatches().end());
|
||||
const cc::scene::IMacroPatch useRGBEPatch = {"CC_USE_RGBE_OUTPUT", true};
|
||||
patches.emplace_back(useRGBEPatch);
|
||||
subModel->onMacroPatchesStateChanged(patches);
|
||||
probeMap.emplace_back(subModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
void RenderDrawQueue::add(const scene::Model &model, float depth, uint32_t subModelIdx, uint32_t passIdx) {
|
||||
const auto *subModel = model.getSubModels()[subModelIdx].get();
|
||||
@@ -62,9 +132,9 @@ void RenderDrawQueue::sortTransparent() {
|
||||
}
|
||||
|
||||
void RenderDrawQueue::recordCommandBuffer(
|
||||
gfx::Device * /*device*/, const scene::Camera * /*camera*/,
|
||||
gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuff,
|
||||
uint32_t subpassIndex) const {
|
||||
gfx::RenderPass *renderPass, uint32_t subpassIndex,
|
||||
gfx::CommandBuffer *cmdBuff,
|
||||
uint32_t lightByteOffset) const {
|
||||
for (const auto &instance : instances) {
|
||||
const auto *subModel = instance.subModel;
|
||||
|
||||
@@ -76,7 +146,11 @@ void RenderDrawQueue::recordCommandBuffer(
|
||||
|
||||
cmdBuff->bindPipelineState(pso);
|
||||
cmdBuff->bindDescriptorSet(pipeline::materialSet, pass->getDescriptorSet());
|
||||
cmdBuff->bindDescriptorSet(pipeline::localSet, subModel->getDescriptorSet());
|
||||
if (lightByteOffset != 0xFFFFFFFF) {
|
||||
cmdBuff->bindDescriptorSet(pipeline::localSet, subModel->getDescriptorSet(), 1, &lightByteOffset);
|
||||
} else {
|
||||
cmdBuff->bindDescriptorSet(pipeline::localSet, subModel->getDescriptorSet());
|
||||
}
|
||||
cmdBuff->bindInputAssembler(inputAssembler);
|
||||
cmdBuff->draw(inputAssembler);
|
||||
}
|
||||
@@ -138,8 +212,9 @@ void RenderInstancingQueue::uploadBuffers(gfx::CommandBuffer *cmdBuffer) const {
|
||||
}
|
||||
|
||||
void RenderInstancingQueue::recordCommandBuffer(
|
||||
gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer,
|
||||
gfx::DescriptorSet *ds, uint32_t offset, const ccstd::vector<uint32_t> *dynamicOffsets) const {
|
||||
gfx::RenderPass *renderPass, uint32_t subpassIndex,
|
||||
gfx::CommandBuffer *cmdBuffer,
|
||||
uint32_t lightByteOffset) const { //
|
||||
const auto &renderQueue = sortedBatches;
|
||||
for (const auto *instanceBuffer : renderQueue) {
|
||||
if (!instanceBuffer->hasPendingModels()) {
|
||||
@@ -154,16 +229,13 @@ void RenderInstancingQueue::recordCommandBuffer(
|
||||
continue;
|
||||
}
|
||||
auto *pso = pipeline::PipelineStateManager::getOrCreatePipelineState(
|
||||
drawPass, instance.shader, instance.ia, renderPass);
|
||||
drawPass, instance.shader, instance.ia, renderPass, subpassIndex);
|
||||
if (lastPSO != pso) {
|
||||
cmdBuffer->bindPipelineState(pso);
|
||||
lastPSO = pso;
|
||||
}
|
||||
if (ds) {
|
||||
cmdBuffer->bindDescriptorSet(pipeline::globalSet, ds, 1, &offset);
|
||||
}
|
||||
if (dynamicOffsets) {
|
||||
cmdBuffer->bindDescriptorSet(pipeline::localSet, instance.descriptorSet, *dynamicOffsets);
|
||||
if (lightByteOffset != 0xFFFFFFFF) {
|
||||
cmdBuffer->bindDescriptorSet(pipeline::localSet, instance.descriptorSet, 1, &lightByteOffset);
|
||||
} else {
|
||||
cmdBuffer->bindDescriptorSet(pipeline::localSet, instance.descriptorSet, instanceBuffer->dynamicOffsets());
|
||||
}
|
||||
@@ -180,6 +252,20 @@ void NativeRenderQueue::sort() {
|
||||
transparentInstancingQueue.sort();
|
||||
}
|
||||
|
||||
void NativeRenderQueue::recordCommands(
|
||||
gfx::CommandBuffer *cmdBuffer,
|
||||
gfx::RenderPass *renderPass,
|
||||
uint32_t subpassIndex) const {
|
||||
opaqueQueue.recordCommandBuffer(
|
||||
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
|
||||
opaqueInstancingQueue.recordCommandBuffer(
|
||||
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
|
||||
transparentQueue.recordCommandBuffer(
|
||||
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
|
||||
transparentInstancingQueue.recordCommandBuffer(
|
||||
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
|
||||
}
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -143,12 +143,12 @@ gfx::TextureInfo getTextureInfo(const ResourceDesc& desc) {
|
||||
};
|
||||
}
|
||||
|
||||
gfx::TextureViewInfo getTextureViewInfo(const SubresourceView& subresView) {
|
||||
gfx::TextureViewInfo getTextureViewInfo(const SubresourceView& subresView, gfx::TextureType viewType) {
|
||||
using namespace gfx; // NOLINT(google-build-using-namespace)
|
||||
|
||||
return {
|
||||
nullptr,
|
||||
subresView.viewType,
|
||||
viewType,
|
||||
subresView.format,
|
||||
subresView.indexOrFirstMipLevel,
|
||||
subresView.numMipLevels,
|
||||
@@ -207,12 +207,12 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) {
|
||||
CC_ENSURES(texture.texture);
|
||||
texture.fenceValue = nextFenceValue;
|
||||
},
|
||||
[&](const IntrusivePtr<gfx::Buffer>& buffer) {
|
||||
CC_EXPECTS(buffer);
|
||||
[&](const PersistentBuffer& buffer) {
|
||||
CC_EXPECTS(buffer.buffer);
|
||||
std::ignore = buffer;
|
||||
},
|
||||
[&](const IntrusivePtr<gfx::Texture>& texture) {
|
||||
CC_EXPECTS(texture);
|
||||
[&](const PersistentTexture& texture) {
|
||||
CC_EXPECTS(texture.texture);
|
||||
std::ignore = texture;
|
||||
},
|
||||
[&](const IntrusivePtr<gfx::Framebuffer>& fb) {
|
||||
@@ -252,7 +252,8 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) {
|
||||
mount(device, parentID); // NOLINT(misc-no-recursion)
|
||||
auto* parentTexture = resg.getTexture(parentID);
|
||||
if (!view.textureView) {
|
||||
auto textureViewInfo = getTextureViewInfo(originView);
|
||||
const auto& desc = get(ResourceGraph::DescTag{}, resg, vertID);
|
||||
auto textureViewInfo = getTextureViewInfo(originView, desc.viewType);
|
||||
textureViewInfo.texture = parentTexture;
|
||||
view.textureView = device->createTexture(textureViewInfo);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
#include "cocos/renderer/pipeline/Define.h"
|
||||
#include "cocos/renderer/pipeline/custom/LayoutGraphUtils.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativeBuiltinUtils.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativePipelineTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativeRenderGraphUtils.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/GslUtils.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/Range.h"
|
||||
#include "cocos/scene/Octree.h"
|
||||
#include "cocos/scene/ReflectionProbe.h"
|
||||
#include "cocos/scene/RenderScene.h"
|
||||
#include "cocos/scene/Skybox.h"
|
||||
#include "cocos/scene/SpotLight.h"
|
||||
|
||||
#include <boost/align/align_up.hpp>
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace render {
|
||||
|
||||
const static uint32_t REFLECTION_PROBE_DEFAULT_MASK = ~static_cast<uint32_t>(pipeline::LayerList::UI_2D) & ~static_cast<uint32_t>(pipeline::LayerList::PROFILER) & ~static_cast<uint32_t>(pipeline::LayerList::UI_3D) & ~static_cast<uint32_t>(pipeline::LayerList::GIZMOS) & ~static_cast<uint32_t>(pipeline::LayerList::SCENE_GIZMO) & ~static_cast<uint32_t>(pipeline::LayerList::EDITOR);
|
||||
|
||||
void NativeRenderQueue::clear() noexcept {
|
||||
probeQueue.clear();
|
||||
opaqueQueue.instances.clear();
|
||||
transparentQueue.instances.clear();
|
||||
opaqueInstancingQueue.clear();
|
||||
@@ -27,43 +36,84 @@ bool NativeRenderQueue::empty() const noexcept {
|
||||
transparentInstancingQueue.empty();
|
||||
}
|
||||
|
||||
uint32_t SceneCulling::getOrCreateSceneCullingQuery(const SceneData& sceneData) {
|
||||
FrustumCullingID SceneCulling::getOrCreateFrustumCulling(const SceneData& sceneData) {
|
||||
const auto* const scene = sceneData.scene;
|
||||
// get or add scene to queries
|
||||
auto& queries = sceneQueries[scene];
|
||||
auto& queries = frustumCullings[scene];
|
||||
|
||||
// check cast shadow
|
||||
const bool bCastShadow = any(sceneData.flags & SceneFlags::SHADOW_CASTER);
|
||||
|
||||
// get or create query source
|
||||
// make query key
|
||||
const auto key = CullingKey{
|
||||
const auto key = FrustumCullingKey{
|
||||
sceneData.camera,
|
||||
sceneData.light.probe,
|
||||
sceneData.light.light,
|
||||
bCastShadow,
|
||||
sceneData.light.level,
|
||||
bCastShadow,
|
||||
};
|
||||
|
||||
// find query source
|
||||
auto iter = queries.culledResultIndex.find(key);
|
||||
if (iter == queries.culledResultIndex.end()) {
|
||||
auto iter = queries.resultIndex.find(key);
|
||||
if (iter == queries.resultIndex.end()) {
|
||||
// create query source
|
||||
// make query source id
|
||||
const auto sourceID = numCullingQueries++;
|
||||
if (numCullingQueries > culledResults.size()) {
|
||||
const FrustumCullingID frustomCulledResultID{numFrustumCulling++};
|
||||
if (numFrustumCulling > frustumCullingResults.size()) {
|
||||
// space is not enough, create query source
|
||||
CC_EXPECTS(numCullingQueries == culledResults.size() + 1);
|
||||
culledResults.emplace_back();
|
||||
CC_EXPECTS(numFrustumCulling == frustumCullingResults.size() + 1);
|
||||
frustumCullingResults.emplace_back();
|
||||
}
|
||||
// add query source to query index
|
||||
bool added = false;
|
||||
std::tie(iter, added) = queries.culledResultIndex.emplace(key, sourceID);
|
||||
std::tie(iter, added) = queries.resultIndex.emplace(key, frustomCulledResultID);
|
||||
CC_ENSURES(added);
|
||||
}
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
uint32_t SceneCulling::createRenderQueue(
|
||||
LightBoundsCullingID SceneCulling::getOrCreateLightBoundsCulling(
|
||||
const SceneData& sceneData, FrustumCullingID frustumCullingID) {
|
||||
if (!any(sceneData.cullingFlags & CullingFlags::LIGHT_BOUNDS)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
CC_EXPECTS(sceneData.shadingLight);
|
||||
const auto* const scene = sceneData.scene;
|
||||
CC_EXPECTS(scene);
|
||||
|
||||
auto& queries = lightBoundsCullings[scene];
|
||||
|
||||
// get or create query source
|
||||
// make query key
|
||||
const auto key = LightBoundsCullingKey{
|
||||
frustumCullingID,
|
||||
sceneData.camera,
|
||||
sceneData.light.probe,
|
||||
sceneData.shadingLight,
|
||||
};
|
||||
|
||||
// find query source
|
||||
auto iter = queries.resultIndex.find(key);
|
||||
if (iter == queries.resultIndex.end()) {
|
||||
// create query source
|
||||
// make query source id
|
||||
const LightBoundsCullingID lightBoundsCullingID{numLightBoundsCulling++};
|
||||
if (numLightBoundsCulling > lightBoundsCullingResults.size()) {
|
||||
// space is not enough, create query source
|
||||
CC_EXPECTS(numLightBoundsCulling == lightBoundsCullingResults.size() + 1);
|
||||
lightBoundsCullingResults.emplace_back();
|
||||
}
|
||||
// add query source to query index
|
||||
bool added = false;
|
||||
std::tie(iter, added) = queries.resultIndex.emplace(key, lightBoundsCullingID);
|
||||
CC_ENSURES(added);
|
||||
}
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
NativeRenderQueueID SceneCulling::createRenderQueue(
|
||||
SceneFlags sceneFlags, LayoutGraphData::vertex_descriptor subpassOrPassLayoutID) {
|
||||
const auto targetID = numRenderQueues++;
|
||||
if (numRenderQueues > renderQueues.size()) {
|
||||
@@ -77,7 +127,7 @@ uint32_t SceneCulling::createRenderQueue(
|
||||
CC_EXPECTS(rq.subpassOrPassLayoutID == 0xFFFFFFFF);
|
||||
rq.sceneFlags = sceneFlags;
|
||||
rq.subpassOrPassLayoutID = subpassOrPassLayoutID;
|
||||
return targetID;
|
||||
return NativeRenderQueueID{targetID};
|
||||
}
|
||||
|
||||
void SceneCulling::collectCullingQueries(
|
||||
@@ -91,7 +141,8 @@ void SceneCulling::collectCullingQueries(
|
||||
CC_EXPECTS(false);
|
||||
continue;
|
||||
}
|
||||
const auto sourceID = getOrCreateSceneCullingQuery(sceneData);
|
||||
const auto frustomCulledResultID = getOrCreateFrustumCulling(sceneData);
|
||||
const auto lightBoundsCullingID = getOrCreateLightBoundsCulling(sceneData, frustomCulledResultID);
|
||||
const auto layoutID = getSubpassOrPassID(vertID, rg, lg);
|
||||
const auto targetID = createRenderQueue(sceneData.flags, layoutID);
|
||||
const auto lightType = sceneData.light.light
|
||||
@@ -99,12 +150,23 @@ void SceneCulling::collectCullingQueries(
|
||||
: scene::LightType::UNKNOWN;
|
||||
|
||||
// add render queue to query source
|
||||
sceneQueryIndex.emplace(vertID, NativeRenderQueueDesc(sourceID, targetID, lightType));
|
||||
renderQueueIndex.emplace(
|
||||
vertID,
|
||||
NativeRenderQueueDesc{
|
||||
frustomCulledResultID,
|
||||
lightBoundsCullingID,
|
||||
targetID,
|
||||
lightType,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
const pipeline::PipelineSceneData* pSceneData = nullptr;
|
||||
|
||||
const pipeline::PipelineSceneData* kPipelineSceneData = nullptr;
|
||||
|
||||
const LayoutGraphData* kLayoutGraph = nullptr;
|
||||
|
||||
bool isNodeVisible(const Node* node, uint32_t visibility) {
|
||||
return node && ((visibility & node->getLayer()) == node->getLayer());
|
||||
}
|
||||
@@ -113,46 +175,46 @@ uint32_t isModelVisible(const scene::Model& model, uint32_t visibility) {
|
||||
return visibility & static_cast<uint32_t>(model.getVisFlags());
|
||||
}
|
||||
|
||||
bool isReflectProbeMask(const scene::Model& model) {
|
||||
return ((model.getNode()->getLayer() & REFLECTION_PROBE_DEFAULT_MASK) == model.getNode()->getLayer()) || (REFLECTION_PROBE_DEFAULT_MASK & static_cast<uint32_t>(model.getVisFlags()));
|
||||
}
|
||||
|
||||
bool isIntersectAABB(const geometry::AABB& lAABB, const geometry::AABB& rAABB) {
|
||||
return !lAABB.aabbAabb(rAABB);
|
||||
}
|
||||
|
||||
bool isFrustumVisible(const scene::Model& model, const geometry::Frustum& frustum, bool castShadow) {
|
||||
const auto* const modelWorldBounds = model.getWorldBounds();
|
||||
if (!modelWorldBounds) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
geometry::AABB transWorldBounds{};
|
||||
transWorldBounds.set(modelWorldBounds->getCenter(), modelWorldBounds->getHalfExtents());
|
||||
const scene::Shadows& shadows = *pSceneData->getShadows();
|
||||
const scene::Shadows& shadows = *kPipelineSceneData->getShadows();
|
||||
if (shadows.getType() == scene::ShadowType::PLANAR && castShadow) {
|
||||
modelWorldBounds->transform(shadows.getMatLight(), &transWorldBounds);
|
||||
}
|
||||
return transWorldBounds.aabbFrustum(frustum);
|
||||
return !transWorldBounds.aabbFrustum(frustum);
|
||||
}
|
||||
|
||||
void octreeCulling(
|
||||
const scene::Octree& octree,
|
||||
const scene::Model* skyboxModelToSkip,
|
||||
const scene::Model* skyboxModel,
|
||||
const scene::RenderScene& scene,
|
||||
const scene::Camera& camera,
|
||||
const geometry::Frustum& cameraOrLightFrustum,
|
||||
bool bCastShadow,
|
||||
ccstd::vector<const scene::Model*>& models) {
|
||||
const auto visibility = camera.getVisibility();
|
||||
const auto camSkyboxFlag = (static_cast<int32_t>(camera.getClearFlag()) & scene::Camera::SKYBOX_FLAG);
|
||||
if (!bCastShadow && skyboxModel && camSkyboxFlag) {
|
||||
models.emplace_back(skyboxModel);
|
||||
}
|
||||
// add instances without world bounds
|
||||
for (const auto& pModel : scene.getModels()) {
|
||||
CC_EXPECTS(pModel);
|
||||
const auto& model = *pModel;
|
||||
if (!model.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
// has world bounds, should be in octree
|
||||
if (model.getWorldBounds()) {
|
||||
continue;
|
||||
}
|
||||
// is skybox, skip
|
||||
if (&model == skyboxModelToSkip) {
|
||||
continue;
|
||||
}
|
||||
// check cast shadow
|
||||
if (bCastShadow && !model.isCastShadow()) {
|
||||
if (!model.isEnabled() || !model.getNode() || model.getWorldBounds() || (bCastShadow && !model.isCastShadow())) {
|
||||
continue;
|
||||
}
|
||||
// filter model by view visibility
|
||||
@@ -173,113 +235,117 @@ void octreeCulling(
|
||||
}
|
||||
|
||||
void bruteForceCulling(
|
||||
const scene::Model* skyboxModelToSkip,
|
||||
const scene::Model* skyboxModel,
|
||||
const scene::RenderScene& scene,
|
||||
const scene::Camera& camera,
|
||||
const geometry::Frustum& cameraOrLightFrustum,
|
||||
bool bCastShadow,
|
||||
const scene::ReflectionProbe* probe,
|
||||
ccstd::vector<const scene::Model*>& models) {
|
||||
const auto visibility = camera.getVisibility();
|
||||
const auto camSkyboxFlag = (static_cast<int32_t>(camera.getClearFlag()) & scene::Camera::SKYBOX_FLAG);
|
||||
if (!bCastShadow && skyboxModel && camSkyboxFlag) {
|
||||
models.emplace_back(skyboxModel);
|
||||
}
|
||||
for (const auto& pModel : scene.getModels()) {
|
||||
CC_EXPECTS(pModel);
|
||||
const auto& model = *pModel;
|
||||
if (!model.isEnabled()) {
|
||||
if (!model.isEnabled() || !model.getNode() || (bCastShadow && !model.isCastShadow())) {
|
||||
continue;
|
||||
}
|
||||
if (bCastShadow && !model.isCastShadow()) {
|
||||
// lod culling
|
||||
if (scene.isCulledByLod(&camera, &model)) {
|
||||
continue;
|
||||
}
|
||||
// filter model by view visibility
|
||||
if (isNodeVisible(model.getNode(), visibility) || isModelVisible(model, visibility)) {
|
||||
// frustum culling
|
||||
if (!isFrustumVisible(model, cameraOrLightFrustum, bCastShadow)) {
|
||||
continue;
|
||||
}
|
||||
// is skybox, skip
|
||||
if (&model == skyboxModelToSkip) {
|
||||
continue;
|
||||
}
|
||||
// lod culling
|
||||
if (scene.isCulledByLod(&camera, &model)) {
|
||||
continue;
|
||||
if (!probe || (probe && probe->getProbeType() == cc::scene::ReflectionProbe::ProbeType::CUBE)) {
|
||||
// filter model by view visibility
|
||||
if (isNodeVisible(model.getNode(), visibility) || isModelVisible(model, visibility)) {
|
||||
const auto* const wBounds = model.getWorldBounds();
|
||||
// frustum culling
|
||||
if (wBounds && ((!probe && isFrustumVisible(model, cameraOrLightFrustum, bCastShadow)) ||
|
||||
(probe && isIntersectAABB(*wBounds, *probe->getBoundingBox())))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
models.emplace_back(&model);
|
||||
}
|
||||
} else if (isReflectProbeMask(model)) {
|
||||
models.emplace_back(&model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sceneCulling(
|
||||
const scene::Model* skyboxModelToSkip,
|
||||
const scene::Model* skyboxModel,
|
||||
const scene::RenderScene& scene,
|
||||
const scene::Camera& camera,
|
||||
const geometry::Frustum& cameraOrLightFrustum,
|
||||
bool bCastShadow,
|
||||
const scene::ReflectionProbe* probe,
|
||||
ccstd::vector<const scene::Model*>& models) {
|
||||
const auto* const octree = scene.getOctree();
|
||||
if (octree && octree->isEnabled()) {
|
||||
if (octree && octree->isEnabled() && !probe) {
|
||||
octreeCulling(
|
||||
*octree, skyboxModelToSkip,
|
||||
*octree, skyboxModel,
|
||||
scene, camera, cameraOrLightFrustum, bCastShadow, models);
|
||||
} else {
|
||||
bruteForceCulling(
|
||||
skyboxModelToSkip,
|
||||
scene, camera, cameraOrLightFrustum, bCastShadow, models);
|
||||
skyboxModel,
|
||||
scene, camera, cameraOrLightFrustum, bCastShadow, probe, models);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void SceneCulling::batchCulling(const pipeline::PipelineSceneData& pplSceneData) {
|
||||
void SceneCulling::batchFrustumCulling(const NativePipeline& ppl) {
|
||||
const auto& pplSceneData = *ppl.getPipelineSceneData();
|
||||
const auto* const skybox = pplSceneData.getSkybox();
|
||||
const auto* const skyboxModelToSkip = skybox ? skybox->getModel() : nullptr;
|
||||
const auto* const skyboxModel = skybox && skybox->isEnabled() ? skybox->getModel() : nullptr;
|
||||
|
||||
for (const auto& [scene, queries] : sceneQueries) {
|
||||
for (const auto& [scene, queries] : frustumCullings) {
|
||||
CC_ENSURES(scene);
|
||||
for (const auto& [key, sourceID] : queries.culledResultIndex) {
|
||||
for (const auto& [key, frustomCulledResultID] : queries.resultIndex) {
|
||||
CC_EXPECTS(key.camera);
|
||||
CC_EXPECTS(key.camera->getScene() == scene);
|
||||
const auto& camera = *key.camera;
|
||||
const auto* light = key.light;
|
||||
const auto level = key.lightLevel;
|
||||
const auto bCastShadow = key.castShadow;
|
||||
const auto* probe = key.probe;
|
||||
const auto& camera = probe ? *probe->getCamera() : *key.camera;
|
||||
CC_EXPECTS(frustomCulledResultID.value < frustumCullingResults.size());
|
||||
auto& models = frustumCullingResults[frustomCulledResultID.value];
|
||||
|
||||
CC_EXPECTS(sourceID < culledResults.size());
|
||||
auto& models = culledResults[sourceID];
|
||||
if (probe) {
|
||||
sceneCulling(
|
||||
skyboxModel,
|
||||
*scene, camera,
|
||||
camera.getFrustum(),
|
||||
bCastShadow,
|
||||
probe,
|
||||
models);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (light) {
|
||||
switch (light->getType()) {
|
||||
case scene::LightType::SPOT:
|
||||
sceneCulling(
|
||||
skyboxModelToSkip,
|
||||
skyboxModel,
|
||||
*scene, camera,
|
||||
dynamic_cast<const scene::SpotLight*>(light)->getFrustum(),
|
||||
bCastShadow,
|
||||
nullptr,
|
||||
models);
|
||||
break;
|
||||
case scene::LightType::DIRECTIONAL: {
|
||||
auto& csmLayers = *pplSceneData.getCSMLayers();
|
||||
const auto* mainLight = dynamic_cast<const scene::DirectionalLight*>(light);
|
||||
const auto& csmLevel = mainLight->getCSMLevel();
|
||||
const geometry::Frustum* frustum = nullptr;
|
||||
const auto& shadows = *pplSceneData.getShadows();
|
||||
if (shadows.getType() == scene::ShadowType::PLANAR) {
|
||||
frustum = &camera.getFrustum();
|
||||
} else {
|
||||
if (shadows.isEnabled() && shadows.getType() == scene::ShadowType::SHADOW_MAP && mainLight && mainLight->getNode()) {
|
||||
csmLayers.update(&pplSceneData, &camera);
|
||||
}
|
||||
// const
|
||||
if (mainLight->isShadowFixedArea() || csmLevel == scene::CSMLevel::LEVEL_1) {
|
||||
frustum = &csmLayers.getSpecialLayer()->getValidFrustum();
|
||||
} else {
|
||||
frustum = &csmLayers.getLayers()[level]->getValidFrustum();
|
||||
}
|
||||
}
|
||||
const auto& frustum = getBuiltinShadowFrustum(ppl, camera, mainLight, level);
|
||||
sceneCulling(
|
||||
skyboxModelToSkip,
|
||||
skyboxModel,
|
||||
*scene, camera,
|
||||
*frustum,
|
||||
frustum,
|
||||
bCastShadow,
|
||||
nullptr,
|
||||
models);
|
||||
} break;
|
||||
default:
|
||||
@@ -288,10 +354,11 @@ void SceneCulling::batchCulling(const pipeline::PipelineSceneData& pplSceneData)
|
||||
}
|
||||
} else {
|
||||
sceneCulling(
|
||||
skyboxModelToSkip,
|
||||
skyboxModel,
|
||||
*scene, camera,
|
||||
camera.getFrustum(),
|
||||
bCastShadow,
|
||||
nullptr,
|
||||
models);
|
||||
}
|
||||
}
|
||||
@@ -299,6 +366,112 @@ void SceneCulling::batchCulling(const pipeline::PipelineSceneData& pplSceneData)
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void executeSphereLightCulling(
|
||||
const scene::SphereLight& light,
|
||||
const ccstd::vector<const scene::Model*>& frustumCullingResult,
|
||||
ccstd::vector<const scene::Model*>& lightBoundsCullingResult) {
|
||||
const auto& lightAABB = light.getAABB();
|
||||
for (const auto* const model : frustumCullingResult) {
|
||||
CC_EXPECTS(model);
|
||||
const auto* const modelBounds = model->getWorldBounds();
|
||||
if (!modelBounds || modelBounds->aabbAabb(lightAABB)) {
|
||||
lightBoundsCullingResult.emplace_back(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void executeSpotLightCulling(
|
||||
const scene::SpotLight& light,
|
||||
const ccstd::vector<const scene::Model*>& frustumCullingResult,
|
||||
ccstd::vector<const scene::Model*>& lightBoundsCullingResult) {
|
||||
const auto& lightAABB = light.getAABB();
|
||||
const auto& lightFrustum = light.getFrustum();
|
||||
for (const auto* const model : frustumCullingResult) {
|
||||
CC_EXPECTS(model);
|
||||
const auto* const modelBounds = model->getWorldBounds();
|
||||
if (!modelBounds || (modelBounds->aabbAabb(lightAABB) && modelBounds->aabbFrustum(lightFrustum))) {
|
||||
lightBoundsCullingResult.emplace_back(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void executePointLightCulling(
|
||||
const scene::PointLight& light,
|
||||
const ccstd::vector<const scene::Model*>& frustumCullingResult,
|
||||
ccstd::vector<const scene::Model*>& lightBoundsCullingResult) {
|
||||
const auto& lightAABB = light.getAABB();
|
||||
for (const auto* const model : frustumCullingResult) {
|
||||
CC_EXPECTS(model);
|
||||
const auto* const modelBounds = model->getWorldBounds();
|
||||
if (!modelBounds || modelBounds->aabbAabb(lightAABB)) {
|
||||
lightBoundsCullingResult.emplace_back(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void executeRangedDirectionalLightCulling(
|
||||
const scene::RangedDirectionalLight& light,
|
||||
const ccstd::vector<const scene::Model*>& frustumCullingResult,
|
||||
ccstd::vector<const scene::Model*>& lightBoundsCullingResult) {
|
||||
const geometry::AABB rangedDirLightBoundingBox(0.0F, 0.0F, 0.0F, 0.5F, 0.5F, 0.5F);
|
||||
// when execute render graph, we should never update world matrix
|
||||
// light->getNode()->updateWorldTransform();
|
||||
geometry::AABB lightAABB{};
|
||||
rangedDirLightBoundingBox.transform(light.getNode()->getWorldMatrix(), &lightAABB);
|
||||
for (const auto* const model : frustumCullingResult) {
|
||||
CC_EXPECTS(model);
|
||||
const auto* const modelBounds = model->getWorldBounds();
|
||||
if (!modelBounds || modelBounds->aabbAabb(lightAABB)) {
|
||||
lightBoundsCullingResult.emplace_back(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void SceneCulling::batchLightBoundsCulling() {
|
||||
for (const auto& [scene, queries] : lightBoundsCullings) {
|
||||
CC_ENSURES(scene);
|
||||
for (const auto& [key, cullingID] : queries.resultIndex) {
|
||||
CC_EXPECTS(key.camera);
|
||||
CC_EXPECTS(key.camera->getScene() == scene);
|
||||
const auto& frustumCullingResult = frustumCullingResults.at(key.frustumCullingID.value);
|
||||
auto& lightBoundsCullingResult = lightBoundsCullingResults.at(cullingID.value);
|
||||
CC_EXPECTS(lightBoundsCullingResult.instances.empty());
|
||||
switch (key.cullingLight->getType()) {
|
||||
case scene::LightType::SPHERE: {
|
||||
const auto* light = dynamic_cast<const scene::SphereLight*>(key.cullingLight);
|
||||
CC_ENSURES(light);
|
||||
executeSphereLightCulling(*light, frustumCullingResult, lightBoundsCullingResult.instances);
|
||||
} break;
|
||||
case scene::LightType::SPOT: {
|
||||
const auto* light = dynamic_cast<const scene::SpotLight*>(key.cullingLight);
|
||||
CC_ENSURES(light);
|
||||
executeSpotLightCulling(*light, frustumCullingResult, lightBoundsCullingResult.instances);
|
||||
} break;
|
||||
case scene::LightType::POINT: {
|
||||
const auto* light = dynamic_cast<const scene::PointLight*>(key.cullingLight);
|
||||
CC_ENSURES(light);
|
||||
executePointLightCulling(*light, frustumCullingResult, lightBoundsCullingResult.instances);
|
||||
} break;
|
||||
case scene::LightType::RANGED_DIRECTIONAL: {
|
||||
const auto* light = dynamic_cast<const scene::RangedDirectionalLight*>(key.cullingLight);
|
||||
CC_ENSURES(light);
|
||||
executeRangedDirectionalLightCulling(*light, frustumCullingResult, lightBoundsCullingResult.instances);
|
||||
} break;
|
||||
case scene::LightType::DIRECTIONAL:
|
||||
case scene::LightType::UNKNOWN:
|
||||
default:
|
||||
// noop
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool isBlend(const scene::Pass& pass) {
|
||||
bool bBlend = false;
|
||||
for (const auto& target : pass.getBlendState()->targets) {
|
||||
@@ -314,7 +487,8 @@ float computeSortingDepth(const scene::Camera& camera, const scene::Model& model
|
||||
if (model.getNode()) {
|
||||
const auto* node = model.getTransform();
|
||||
Vec3 position;
|
||||
Vec3::subtract(node->getWorldPosition(), camera.getPosition(), &position);
|
||||
const auto* bounds = model.getWorldBounds();
|
||||
Vec3::subtract(bounds ? bounds->center : node->getWorldPosition(), camera.getPosition(), &position);
|
||||
depth = position.dot(camera.getForward());
|
||||
}
|
||||
return depth;
|
||||
@@ -324,15 +498,23 @@ void addRenderObject(
|
||||
LayoutGraphData::vertex_descriptor phaseLayoutID,
|
||||
const bool bDrawOpaqueOrMask,
|
||||
const bool bDrawBlend,
|
||||
const bool bDrawProbe,
|
||||
const scene::Camera& camera,
|
||||
const scene::Model& model,
|
||||
NativeRenderQueue& queue) {
|
||||
if (bDrawProbe) {
|
||||
queue.probeQueue.applyMacro(*kLayoutGraph, model, phaseLayoutID);
|
||||
}
|
||||
const auto& subModels = model.getSubModels();
|
||||
const auto subModelCount = subModels.size();
|
||||
for (uint32_t subModelIdx = 0; subModelIdx < subModelCount; ++subModelIdx) {
|
||||
const auto& subModel = subModels[subModelIdx];
|
||||
const auto& passes = *(subModel->getPasses());
|
||||
const auto passCount = passes.size();
|
||||
auto probeIt = std::find(queue.probeQueue.probeMap.begin(), queue.probeQueue.probeMap.end(), subModel.get());
|
||||
if (probeIt != queue.probeQueue.probeMap.end()) {
|
||||
phaseLayoutID = ProbeHelperQueue::getDefaultId(*kLayoutGraph);
|
||||
}
|
||||
for (uint32_t passIdx = 0; passIdx < passCount; ++passIdx) {
|
||||
auto& pass = *passes[passIdx];
|
||||
// check phase
|
||||
@@ -378,9 +560,10 @@ void addRenderObject(
|
||||
void SceneCulling::fillRenderQueues(
|
||||
const RenderGraph& rg, const pipeline::PipelineSceneData& pplSceneData) {
|
||||
const auto* const skybox = pplSceneData.getSkybox();
|
||||
for (auto&& [sceneID, desc] : sceneQueryIndex) {
|
||||
for (auto&& [sceneID, desc] : renderQueueIndex) {
|
||||
CC_EXPECTS(holds<SceneTag>(sceneID, rg));
|
||||
const auto sourceID = desc.culledSource;
|
||||
const auto frustomCulledResultID = desc.frustumCulledResultID;
|
||||
const auto lightBoundsCullingID = desc.lightBoundsCulledResultID;
|
||||
const auto targetID = desc.renderQueueTarget;
|
||||
const auto& sceneData = get(SceneTag{}, sceneID, rg);
|
||||
|
||||
@@ -388,8 +571,8 @@ void SceneCulling::fillRenderQueues(
|
||||
const bool bDrawBlend = any(sceneData.flags & SceneFlags::TRANSPARENT_OBJECT);
|
||||
const bool bDrawOpaqueOrMask = any(sceneData.flags & (SceneFlags::OPAQUE_OBJECT | SceneFlags::CUTOUT_OBJECT));
|
||||
const bool bDrawShadowCaster = any(sceneData.flags & SceneFlags::SHADOW_CASTER);
|
||||
|
||||
if (!bDrawShadowCaster && !bDrawBlend && !bDrawOpaqueOrMask) {
|
||||
const bool bDrawProbe = any(sceneData.flags & SceneFlags::REFLECTION_PROBE);
|
||||
if (!bDrawShadowCaster && !bDrawBlend && !bDrawOpaqueOrMask && !bDrawProbe) {
|
||||
// nothing to draw
|
||||
continue;
|
||||
}
|
||||
@@ -402,37 +585,32 @@ void SceneCulling::fillRenderQueues(
|
||||
CC_EXPECTS(phaseLayoutID != LayoutGraphData::null_vertex());
|
||||
|
||||
// culling source
|
||||
CC_EXPECTS(sourceID < culledResults.size());
|
||||
const auto& sourceModels = culledResults[sourceID];
|
||||
CC_EXPECTS(frustomCulledResultID.value < frustumCullingResults.size());
|
||||
const auto& sourceModels = [&]() -> const auto& {
|
||||
// is culled by light bounds
|
||||
if (lightBoundsCullingID.value != 0xFFFFFFFF) {
|
||||
CC_EXPECTS(lightBoundsCullingID.value < lightBoundsCullingResults.size());
|
||||
return lightBoundsCullingResults.at(lightBoundsCullingID.value).instances;
|
||||
}
|
||||
// not culled by light bounds
|
||||
return frustumCullingResults.at(frustomCulledResultID.value);
|
||||
}
|
||||
();
|
||||
|
||||
// native queue target
|
||||
CC_EXPECTS(targetID < renderQueues.size());
|
||||
auto& nativeQueue = renderQueues[targetID];
|
||||
CC_EXPECTS(targetID.value < renderQueues.size());
|
||||
auto& nativeQueue = renderQueues[targetID.value];
|
||||
CC_EXPECTS(nativeQueue.empty());
|
||||
|
||||
// skybox
|
||||
const auto* camera = sceneData.camera;
|
||||
CC_EXPECTS(camera);
|
||||
if (!any(sceneData.flags & SceneFlags::SHADOW_CASTER) &&
|
||||
skybox && skybox->isEnabled() &&
|
||||
(static_cast<int32_t>(camera->getClearFlag()) & scene::Camera::SKYBOX_FLAG)) {
|
||||
CC_EXPECTS(skybox->getModel());
|
||||
const auto& model = *skybox->getModel();
|
||||
const auto* node = model.getNode();
|
||||
float depth = 0;
|
||||
if (node) {
|
||||
Vec3 tempVec3{};
|
||||
tempVec3 = node->getWorldPosition() - camera->getPosition();
|
||||
depth = tempVec3.dot(camera->getForward());
|
||||
}
|
||||
nativeQueue.opaqueQueue.add(model, depth, 0, 0);
|
||||
}
|
||||
|
||||
// fill native queue
|
||||
for (const auto* const model : sourceModels) {
|
||||
addRenderObject(
|
||||
phaseLayoutID, bDrawOpaqueOrMask, bDrawBlend,
|
||||
*sceneData.camera, *model, nativeQueue);
|
||||
bDrawProbe, *sceneData.camera, *model, nativeQueue);
|
||||
}
|
||||
|
||||
// post-processing
|
||||
@@ -442,26 +620,188 @@ void SceneCulling::fillRenderQueues(
|
||||
|
||||
void SceneCulling::buildRenderQueues(
|
||||
const RenderGraph& rg, const LayoutGraphData& lg,
|
||||
const pipeline::PipelineSceneData& pplSceneData) {
|
||||
pSceneData = &pplSceneData;
|
||||
const NativePipeline& ppl) {
|
||||
kPipelineSceneData = ppl.pipelineSceneData;
|
||||
kLayoutGraph = ≶
|
||||
collectCullingQueries(rg, lg);
|
||||
batchCulling(pplSceneData);
|
||||
fillRenderQueues(rg, pplSceneData);
|
||||
batchFrustumCulling(ppl);
|
||||
batchLightBoundsCulling(); // cull frustum-culling's results by light bounds
|
||||
fillRenderQueues(rg, *ppl.pipelineSceneData);
|
||||
}
|
||||
|
||||
void SceneCulling::clear() noexcept {
|
||||
sceneQueries.clear();
|
||||
for (auto& c : culledResults) {
|
||||
// frustum culling
|
||||
frustumCullings.clear();
|
||||
for (auto& c : frustumCullingResults) {
|
||||
c.clear();
|
||||
}
|
||||
// light bounds culling
|
||||
lightBoundsCullings.clear();
|
||||
for (auto& c : lightBoundsCullingResults) {
|
||||
c.instances.clear();
|
||||
c.lightByteOffset = 0xFFFFFFFF;
|
||||
}
|
||||
// native render queues
|
||||
for (auto& q : renderQueues) {
|
||||
q.clear();
|
||||
}
|
||||
sceneQueryIndex.clear();
|
||||
numCullingQueries = 0;
|
||||
|
||||
// clear render graph scene vertex query index
|
||||
renderQueueIndex.clear();
|
||||
// do not clear this->renderQueues, it is reused to avoid memory allocation
|
||||
|
||||
// reset all counters
|
||||
numFrustumCulling = 0;
|
||||
numLightBoundsCulling = 0;
|
||||
numRenderQueues = 0;
|
||||
}
|
||||
|
||||
void LightResource::init(const NativeProgramLibrary& programLib, gfx::Device* deviceIn, uint32_t maxNumLightsIn) {
|
||||
CC_EXPECTS(!device);
|
||||
device = deviceIn;
|
||||
programLibrary = &programLib;
|
||||
|
||||
const auto& instanceLayout = programLibrary->localLayoutData;
|
||||
const auto attrID = at(programLib.layoutGraph.attributeIndex, std::string_view{"CCForwardLight"});
|
||||
const auto& uniformBlock = instanceLayout.uniformBlocks.at(attrID);
|
||||
|
||||
elementSize = boost::alignment::align_up(
|
||||
getUniformBlockSize(uniformBlock.members),
|
||||
device->getCapabilities().uboOffsetAlignment);
|
||||
maxNumLights = maxNumLightsIn;
|
||||
binding = programLib.localLayoutData.bindingMap.at(attrID);
|
||||
|
||||
const auto bufferSize = elementSize * maxNumLights;
|
||||
|
||||
lightBuffer = device->createBuffer(gfx::BufferInfo{
|
||||
gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST,
|
||||
gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE,
|
||||
bufferSize,
|
||||
elementSize,
|
||||
});
|
||||
firstLightBufferView = device->createBuffer({lightBuffer, 0, elementSize});
|
||||
|
||||
cpuBuffer.resize(bufferSize);
|
||||
lights.reserve(maxNumLights);
|
||||
lightIndex.reserve(maxNumLights);
|
||||
|
||||
CC_ENSURES(elementSize);
|
||||
CC_ENSURES(maxNumLights);
|
||||
|
||||
resized = true;
|
||||
}
|
||||
|
||||
uint32_t LightResource::addLight(
|
||||
const scene::Light* light,
|
||||
bool bHDR,
|
||||
float exposure,
|
||||
const scene::Shadows* shadowInfo) {
|
||||
// already added
|
||||
auto iter = lightIndex.find(light);
|
||||
if (iter != lightIndex.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
// resize buffer
|
||||
if (lights.size() == maxNumLights) {
|
||||
resized = true;
|
||||
maxNumLights *= 2;
|
||||
const auto bufferSize = elementSize * maxNumLights;
|
||||
lightBuffer->resize(bufferSize);
|
||||
firstLightBufferView = device->createBuffer({lightBuffer, 0, elementSize});
|
||||
cpuBuffer.resize(bufferSize);
|
||||
lights.reserve(maxNumLights);
|
||||
lightIndex.reserve(maxNumLights);
|
||||
}
|
||||
CC_ENSURES(lights.size() < maxNumLights);
|
||||
|
||||
// add light
|
||||
const auto lightID = static_cast<uint32_t>(lights.size());
|
||||
lights.emplace_back(light);
|
||||
auto res = lightIndex.emplace(light, lightID);
|
||||
CC_ENSURES(res.second);
|
||||
|
||||
// update buffer
|
||||
const auto offset = elementSize * lightID;
|
||||
setLightUBO(light, bHDR, exposure, shadowInfo, cpuBuffer.data() + offset, elementSize);
|
||||
|
||||
return lightID * elementSize;
|
||||
}
|
||||
|
||||
void LightResource::buildLights(
|
||||
SceneCulling& sceneCulling,
|
||||
bool bHDR,
|
||||
const scene::Shadows* shadowInfo) {
|
||||
// build light buffer
|
||||
for (const auto& [scene, lightBoundsCullings] : sceneCulling.lightBoundsCullings) {
|
||||
for (const auto& [key, lightBoundsCullingID] : lightBoundsCullings.resultIndex) {
|
||||
float exposure = 1.0F;
|
||||
if (key.camera) {
|
||||
exposure = key.camera->getExposure();
|
||||
} else if (key.probe && key.probe->getCamera()) {
|
||||
exposure = key.probe->getCamera()->getExposure();
|
||||
} else {
|
||||
CC_EXPECTS(false);
|
||||
}
|
||||
const auto lightByteOffset = addLight(
|
||||
key.cullingLight,
|
||||
bHDR,
|
||||
exposure,
|
||||
shadowInfo);
|
||||
|
||||
// save light byte offset for each light bounds culling
|
||||
auto& result = sceneCulling.lightBoundsCullingResults.at(lightBoundsCullingID.value);
|
||||
result.lightByteOffset = lightByteOffset;
|
||||
}
|
||||
}
|
||||
|
||||
// assign light byte offset to each queue
|
||||
for (const auto& [sceneID, desc] : sceneCulling.renderQueueIndex) {
|
||||
if (desc.lightBoundsCulledResultID.value == 0xFFFFFFFF) {
|
||||
continue;
|
||||
}
|
||||
const auto lightByteOffset = sceneCulling.lightBoundsCullingResults.at(
|
||||
desc.lightBoundsCulledResultID.value)
|
||||
.lightByteOffset;
|
||||
|
||||
sceneCulling.renderQueues.at(desc.renderQueueTarget.value).lightByteOffset = lightByteOffset;
|
||||
}
|
||||
}
|
||||
|
||||
void LightResource::clear() {
|
||||
std::fill(cpuBuffer.begin(), cpuBuffer.end(), 0);
|
||||
lights.clear();
|
||||
lightIndex.clear();
|
||||
}
|
||||
|
||||
void LightResource::buildLightBuffer(gfx::CommandBuffer* cmdBuffer) const {
|
||||
if (lights.empty()) {
|
||||
return;
|
||||
}
|
||||
cmdBuffer->updateBuffer(
|
||||
lightBuffer,
|
||||
cpuBuffer.data(),
|
||||
static_cast<uint32_t>(lights.size()) * elementSize);
|
||||
}
|
||||
|
||||
void LightResource::tryUpdateRenderSceneLocalDescriptorSet(const SceneCulling& sceneCulling) {
|
||||
if (!resized) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& [scene, culling] : sceneCulling.frustumCullings) {
|
||||
for (const auto& model : scene->getModels()) {
|
||||
CC_EXPECTS(model);
|
||||
for (const auto& submodel : model->getSubModels()) {
|
||||
auto* set = submodel->getDescriptorSet();
|
||||
set->bindBuffer(binding, firstLightBufferView);
|
||||
set->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
resized = false;
|
||||
}
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "cocos/renderer/pipeline/custom/NativePipelineTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativeUtils.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderGraphGraphs.h"
|
||||
#include "cocos/scene/Light.h"
|
||||
#include "cocos/scene/RenderScene.h"
|
||||
#include "cocos/scene/SpotLight.h"
|
||||
|
||||
@@ -122,21 +123,27 @@ void NativeSetter::setBuiltinCameraConstants(const scene::Camera *camera) {
|
||||
camera->getScene()->getMainLight(), data);
|
||||
}
|
||||
|
||||
void NativeSetter::setBuiltinDirectionalLightViewConstants(
|
||||
void NativeSetter::setBuiltinDirectionalLightFrustumConstants(
|
||||
const scene::Camera *camera,
|
||||
const scene::DirectionalLight *light, uint32_t level) {
|
||||
CC_EXPECTS(light);
|
||||
// if csm is actually activated, csm is not nullptr
|
||||
// update and get csm
|
||||
const auto *csm = getBuiltinShadowCSM(*pipelineRuntime, *camera, light);
|
||||
|
||||
// set data
|
||||
auto *device = pipelineRuntime->getDevice();
|
||||
const auto &sceneData = *pipelineRuntime->getPipelineSceneData();
|
||||
auto &data = get(RenderGraph::DataTag{}, *renderGraph, nodeID);
|
||||
setShadowUBOLightView(device, *layoutGraph, sceneData, *light, level, data);
|
||||
setShadowUBOLightView(device, *layoutGraph, sceneData, csm, *light, level, data);
|
||||
}
|
||||
|
||||
void NativeSetter::setBuiltinSpotLightViewConstants(const scene::SpotLight *light) {
|
||||
void NativeSetter::setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) {
|
||||
CC_EXPECTS(light);
|
||||
auto *device = pipelineRuntime->getDevice();
|
||||
const auto &sceneData = *pipelineRuntime->getPipelineSceneData();
|
||||
auto &data = get(RenderGraph::DataTag{}, *renderGraph, nodeID);
|
||||
setShadowUBOLightView(device, *layoutGraph, sceneData, *light, 0, data);
|
||||
setShadowUBOLightView(device, *layoutGraph, sceneData, nullptr, *light, 0, data);
|
||||
}
|
||||
|
||||
void NativeSetter::setBuiltinShadowMapConstants(
|
||||
@@ -148,19 +155,177 @@ void NativeSetter::setBuiltinShadowMapConstants(
|
||||
setShadowUBOView(*device, *layoutGraph, sceneData, *light, data);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr float LIGHT_METER_SCALE = 10000.0F;
|
||||
constexpr bool ENABLE_NEW_MULTI_LIGHT = false;
|
||||
|
||||
} // namespace
|
||||
|
||||
void NativeSetter::setBuiltinDirectionalLightConstants(const scene::DirectionalLight *light, const scene::Camera *camera) {
|
||||
}
|
||||
|
||||
void NativeSetter::setBuiltinSphereLightConstants(const scene::SphereLight *light, const scene::Camera *camera) {
|
||||
void NativeSetter::setBuiltinSphereLightConstants(
|
||||
const scene::SphereLight *light, const scene::Camera *camera) {
|
||||
CC_EXPECTS(light);
|
||||
const auto &sceneData = *pipelineRuntime->getPipelineSceneData();
|
||||
const auto &shadowInfo = *sceneData.getShadows();
|
||||
|
||||
auto &data = get(RenderGraph::DataTag{}, *renderGraph, nodeID);
|
||||
|
||||
if constexpr (ENABLE_NEW_MULTI_LIGHT) {
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightPos",
|
||||
toVec4(light->getPosition(), static_cast<float>(scene::LightType::SPHERE)));
|
||||
auto color = toVec4(light->getColor());
|
||||
if (light->isUseColorTemperature()) {
|
||||
const auto &rgb = light->getColorTemperatureRGB();
|
||||
color.x *= rgb.x;
|
||||
color.y *= rgb.y;
|
||||
color.z *= rgb.z;
|
||||
}
|
||||
if (sceneData.isHDR()) {
|
||||
color.w = light->getLuminance() * camera->getExposure() * LIGHT_METER_SCALE;
|
||||
} else {
|
||||
color.w = light->getLuminance();
|
||||
}
|
||||
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightColor", color);
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightSizeRangeAngle",
|
||||
Vec4(
|
||||
light->getSize(),
|
||||
light->getRange(),
|
||||
0.F,
|
||||
0.F));
|
||||
}
|
||||
setPunctualLightShadowUBO(
|
||||
pipelineRuntime->getDevice(), *layoutGraph, sceneData,
|
||||
camera->getScene()->getMainLight(), *light, data);
|
||||
}
|
||||
|
||||
void NativeSetter::setBuiltinSpotLightConstants(const scene::SpotLight *light, const scene::Camera *camera) {
|
||||
CC_EXPECTS(light);
|
||||
const auto &sceneData = *this->pipelineRuntime->getPipelineSceneData();
|
||||
const auto &shadowInfo = *sceneData.getShadows();
|
||||
|
||||
auto &data = get(RenderGraph::DataTag{}, *renderGraph, nodeID);
|
||||
|
||||
if constexpr (ENABLE_NEW_MULTI_LIGHT) {
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightPos",
|
||||
toVec4(light->getPosition(), static_cast<float>(scene::LightType::SPOT)));
|
||||
|
||||
auto color = toVec4(light->getColor());
|
||||
if (light->isUseColorTemperature()) {
|
||||
const auto &rgb = light->getColorTemperatureRGB();
|
||||
color.x *= rgb.x;
|
||||
color.y *= rgb.y;
|
||||
color.z *= rgb.z;
|
||||
}
|
||||
if (sceneData.isHDR()) {
|
||||
color.w = light->getLuminance() * camera->getExposure() * LIGHT_METER_SCALE;
|
||||
} else {
|
||||
color.w = light->getLuminance();
|
||||
}
|
||||
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightColor", color);
|
||||
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightSizeRangeAngle",
|
||||
Vec4(
|
||||
light->getSize(),
|
||||
light->getRange(),
|
||||
light->getSpotAngle(),
|
||||
shadowInfo.isEnabled() &&
|
||||
light->isShadowEnabled() &&
|
||||
shadowInfo.getType() == scene::ShadowType::SHADOW_MAP
|
||||
? 1.0F
|
||||
: 0.0F));
|
||||
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightDir",
|
||||
toVec4(light->getDirection()));
|
||||
}
|
||||
setPunctualLightShadowUBO(
|
||||
pipelineRuntime->getDevice(), *layoutGraph, sceneData,
|
||||
camera->getScene()->getMainLight(), *light, data);
|
||||
}
|
||||
|
||||
void NativeSetter::setBuiltinPointLightConstants(const scene::PointLight *light, const scene::Camera *camera) {
|
||||
CC_EXPECTS(light);
|
||||
const auto &sceneData = *this->pipelineRuntime->getPipelineSceneData();
|
||||
const auto &shadowInfo = *sceneData.getShadows();
|
||||
|
||||
auto &data = get(RenderGraph::DataTag{}, *renderGraph, nodeID);
|
||||
|
||||
if constexpr (ENABLE_NEW_MULTI_LIGHT) {
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightPos",
|
||||
toVec4(light->getPosition(), static_cast<float>(scene::LightType::POINT)));
|
||||
auto color = toVec4(light->getColor());
|
||||
if (light->isUseColorTemperature()) {
|
||||
const auto &rgb = light->getColorTemperatureRGB();
|
||||
color.x *= rgb.x;
|
||||
color.y *= rgb.y;
|
||||
color.z *= rgb.z;
|
||||
}
|
||||
if (sceneData.isHDR()) {
|
||||
color.w = light->getLuminance() * camera->getExposure() * LIGHT_METER_SCALE;
|
||||
} else {
|
||||
color.w = light->getLuminance();
|
||||
}
|
||||
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightColor", color);
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightSizeRangeAngle",
|
||||
Vec4(
|
||||
0.F,
|
||||
light->getRange(),
|
||||
0.F,
|
||||
0.F));
|
||||
}
|
||||
setPunctualLightShadowUBO(
|
||||
pipelineRuntime->getDevice(), *layoutGraph, sceneData,
|
||||
camera->getScene()->getMainLight(), *light, data);
|
||||
}
|
||||
|
||||
void NativeSetter::setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) {
|
||||
const auto &sceneData = *this->pipelineRuntime->getPipelineSceneData();
|
||||
const auto &shadowInfo = *sceneData.getShadows();
|
||||
|
||||
auto &data = get(RenderGraph::DataTag{}, *renderGraph, nodeID);
|
||||
|
||||
if constexpr (ENABLE_NEW_MULTI_LIGHT) {
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightPos",
|
||||
toVec4(light->getPosition(), static_cast<float>(scene::LightType::RANGED_DIRECTIONAL)));
|
||||
auto color = toVec4(light->getColor());
|
||||
if (light->isUseColorTemperature()) {
|
||||
const auto &rgb = light->getColorTemperatureRGB();
|
||||
color.x *= rgb.x;
|
||||
color.y *= rgb.y;
|
||||
color.z *= rgb.z;
|
||||
}
|
||||
if (sceneData.isHDR()) {
|
||||
color.w = light->getIlluminance() * camera->getExposure();
|
||||
} else {
|
||||
color.w = light->getIlluminance();
|
||||
}
|
||||
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightColor", color);
|
||||
setVec4Impl(
|
||||
data, *layoutGraph, "cc_lightSizeRangeAngle",
|
||||
Vec4(
|
||||
light->getRight().x,
|
||||
light->getRight().y,
|
||||
light->getRight().z,
|
||||
0.F));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace render
|
||||
|
||||
@@ -24,7 +24,10 @@
|
||||
|
||||
#pragma once
|
||||
#include "cocos/core/ArrayBuffer.h"
|
||||
#include "cocos/math/Vec2.h"
|
||||
#include "cocos/math/Vec3.h"
|
||||
#include "cocos/math/Vec4.h"
|
||||
#include "cocos/renderer/gfx-base/GFXDef-common.h"
|
||||
#include "cocos/renderer/pipeline/custom/LayoutGraphFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderGraphFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderInterfaceFwd.h"
|
||||
@@ -75,6 +78,10 @@ void setReadWriteTextureImpl(RenderData &data, const LayoutGraphData &lg, const
|
||||
|
||||
void setSamplerImpl(RenderData &data, const LayoutGraphData &lg, const ccstd::string &name, gfx::Sampler *sampler);
|
||||
|
||||
inline Vec4 toVec4(const Vec3 &vec, float w = 0.0F) noexcept {
|
||||
return {vec.x, vec.y, vec.z, w};
|
||||
}
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
// clang-format off
|
||||
#pragma once
|
||||
#include "cocos/base/std/variant.h"
|
||||
#include "cocos/renderer/core/ProgramLib.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderInterfaceFwd.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#pragma once
|
||||
#include "cocos/base/std/hash/hash.h"
|
||||
#include "cocos/base/std/variant.h"
|
||||
#include "cocos/renderer/gfx-base/GFXDef-common.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
|
||||
@@ -41,6 +41,9 @@ bool nativevalue_to_se(const cc::render::LightInfo &from, se::Value &to, se::Obj
|
||||
nativevalue_to_se(from.light, tmp, ctx);
|
||||
obj->setProperty("light", tmp);
|
||||
|
||||
nativevalue_to_se(from.probe, tmp, ctx);
|
||||
obj->setProperty("probe", tmp);
|
||||
|
||||
nativevalue_to_se(from.level, tmp, ctx);
|
||||
obj->setProperty("level", tmp);
|
||||
|
||||
@@ -241,6 +244,10 @@ bool sevalue_to_native<cc::render::LightInfo>(const se::Value &from, cc::render:
|
||||
if(!field.isNullOrUndefined()) {
|
||||
ok &= sevalue_to_native(field, &(to->light), ctx);
|
||||
}
|
||||
obj->getProperty("probe", &field, true);
|
||||
if(!field.isNullOrUndefined()) {
|
||||
ok &= sevalue_to_native(field, &(to->probe), ctx);
|
||||
}
|
||||
obj->getProperty("level", &field, true);
|
||||
if(!field.isNullOrUndefined()) {
|
||||
ok &= sevalue_to_native(field, &(to->level), ctx);
|
||||
|
||||
@@ -39,12 +39,14 @@ namespace render {
|
||||
|
||||
inline void save(OutputArchive& ar, const LightInfo& v) {
|
||||
// skip, light: IntrusivePtr<scene::Light>
|
||||
// skip, probe: scene::ReflectionProbe
|
||||
save(ar, v.level);
|
||||
save(ar, v.culledByLight);
|
||||
}
|
||||
|
||||
inline void load(InputArchive& ar, LightInfo& v) {
|
||||
// skip, light: IntrusivePtr<scene::Light>
|
||||
// skip, probe: scene::ReflectionProbe
|
||||
load(ar, v.level);
|
||||
load(ar, v.culledByLight);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,16 @@
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace scene {
|
||||
|
||||
class ReflectionProbe;
|
||||
|
||||
} // namespace scene
|
||||
|
||||
} // namespace cc
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace render {
|
||||
|
||||
enum class UpdateFrequency {
|
||||
@@ -126,6 +136,10 @@ constexpr bool operator!(ResourceFlags e) noexcept {
|
||||
return e == static_cast<ResourceFlags>(0);
|
||||
}
|
||||
|
||||
constexpr ResourceFlags operator~(ResourceFlags e) noexcept {
|
||||
return static_cast<ResourceFlags>(~static_cast<std::underlying_type_t<ResourceFlags>>(e));
|
||||
}
|
||||
|
||||
constexpr bool any(ResourceFlags e) noexcept {
|
||||
return !!e;
|
||||
}
|
||||
@@ -158,6 +172,7 @@ enum class SceneFlags : uint32_t {
|
||||
DRAW_NON_INSTANCING = 0x1000,
|
||||
REFLECTION_PROBE = 0x2000,
|
||||
GPU_DRIVEN = 0x4000,
|
||||
NON_BUILTIN = 0x8000,
|
||||
ALL = 0xFFFFFFFF,
|
||||
};
|
||||
|
||||
@@ -181,6 +196,10 @@ constexpr bool operator!(SceneFlags e) noexcept {
|
||||
return e == static_cast<SceneFlags>(0);
|
||||
}
|
||||
|
||||
constexpr SceneFlags operator~(SceneFlags e) noexcept {
|
||||
return static_cast<SceneFlags>(~static_cast<std::underlying_type_t<SceneFlags>>(e));
|
||||
}
|
||||
|
||||
constexpr bool any(SceneFlags e) noexcept {
|
||||
return !!e;
|
||||
}
|
||||
@@ -211,8 +230,9 @@ enum class ClearValueType {
|
||||
|
||||
struct LightInfo {
|
||||
LightInfo() = default;
|
||||
LightInfo(IntrusivePtr<scene::Light> lightIn, uint32_t levelIn, bool culledByLightIn) noexcept
|
||||
LightInfo(IntrusivePtr<scene::Light> lightIn, uint32_t levelIn, bool culledByLightIn, scene::ReflectionProbe* probeIn) noexcept
|
||||
: light(std::move(lightIn)),
|
||||
probe(probeIn),
|
||||
level(levelIn),
|
||||
culledByLight(culledByLightIn) {}
|
||||
LightInfo(IntrusivePtr<scene::Light> lightIn, uint32_t levelIn) noexcept
|
||||
@@ -220,6 +240,7 @@ struct LightInfo {
|
||||
level(levelIn) {}
|
||||
|
||||
IntrusivePtr<scene::Light> light;
|
||||
scene::ReflectionProbe* probe{nullptr};
|
||||
uint32_t level{0};
|
||||
bool culledByLight{false};
|
||||
};
|
||||
@@ -307,6 +328,10 @@ constexpr bool operator!(ResolveFlags e) noexcept {
|
||||
return e == static_cast<ResolveFlags>(0);
|
||||
}
|
||||
|
||||
constexpr ResolveFlags operator~(ResolveFlags e) noexcept {
|
||||
return static_cast<ResolveFlags>(~static_cast<std::underlying_type_t<ResolveFlags>>(e));
|
||||
}
|
||||
|
||||
constexpr bool any(ResolveFlags e) noexcept {
|
||||
return !!e;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "cocos/base/std/hash/hash.h"
|
||||
#include "cocos/base/std/variant.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderCommonFwd.h"
|
||||
#include "cocos/scene/Camera.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
@@ -46,7 +45,9 @@ struct ResourceTraits;
|
||||
struct RenderSwapchain;
|
||||
struct ResourceStates;
|
||||
struct ManagedBuffer;
|
||||
struct PersistentBuffer;
|
||||
struct ManagedTexture;
|
||||
struct PersistentTexture;
|
||||
struct ManagedResource;
|
||||
struct Subpass;
|
||||
struct SubpassGraph;
|
||||
@@ -80,6 +81,9 @@ struct ClearTag;
|
||||
struct ViewportTag;
|
||||
struct ClearView;
|
||||
struct RenderQueue;
|
||||
|
||||
enum class CullingFlags : uint32_t;
|
||||
|
||||
struct SceneData;
|
||||
struct Dispatch;
|
||||
struct Blit;
|
||||
|
||||
@@ -1523,7 +1523,7 @@ holds_alternative<ManagedTexture>(ResourceGraph::vertex_descriptor v, const Reso
|
||||
|
||||
template <>
|
||||
inline bool
|
||||
holds_alternative<IntrusivePtr<gfx::Buffer>>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) noexcept { // NOLINT
|
||||
holds_alternative<PersistentBuffer>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) noexcept { // NOLINT
|
||||
return ccstd::holds_alternative<
|
||||
impl::ValueHandle<PersistentBufferTag, ResourceGraph::vertex_descriptor>>(
|
||||
g._vertices[v].handle);
|
||||
@@ -1531,7 +1531,7 @@ holds_alternative<IntrusivePtr<gfx::Buffer>>(ResourceGraph::vertex_descriptor v,
|
||||
|
||||
template <>
|
||||
inline bool
|
||||
holds_alternative<IntrusivePtr<gfx::Texture>>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) noexcept { // NOLINT
|
||||
holds_alternative<PersistentTexture>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) noexcept { // NOLINT
|
||||
return ccstd::holds_alternative<
|
||||
impl::ValueHandle<PersistentTextureTag, ResourceGraph::vertex_descriptor>>(
|
||||
g._vertices[v].handle);
|
||||
@@ -1601,8 +1601,8 @@ get<ManagedTexture>(ResourceGraph::vertex_descriptor v, ResourceGraph& g) {
|
||||
}
|
||||
|
||||
template <>
|
||||
inline IntrusivePtr<gfx::Buffer>&
|
||||
get<IntrusivePtr<gfx::Buffer>>(ResourceGraph::vertex_descriptor v, ResourceGraph& g) {
|
||||
inline PersistentBuffer&
|
||||
get<PersistentBuffer>(ResourceGraph::vertex_descriptor v, ResourceGraph& g) {
|
||||
auto& handle = ccstd::get<
|
||||
impl::ValueHandle<PersistentBufferTag, ResourceGraph::vertex_descriptor>>(
|
||||
g._vertices[v].handle);
|
||||
@@ -1610,8 +1610,8 @@ get<IntrusivePtr<gfx::Buffer>>(ResourceGraph::vertex_descriptor v, ResourceGraph
|
||||
}
|
||||
|
||||
template <>
|
||||
inline IntrusivePtr<gfx::Texture>&
|
||||
get<IntrusivePtr<gfx::Texture>>(ResourceGraph::vertex_descriptor v, ResourceGraph& g) {
|
||||
inline PersistentTexture&
|
||||
get<PersistentTexture>(ResourceGraph::vertex_descriptor v, ResourceGraph& g) {
|
||||
auto& handle = ccstd::get<
|
||||
impl::ValueHandle<PersistentTextureTag, ResourceGraph::vertex_descriptor>>(
|
||||
g._vertices[v].handle);
|
||||
@@ -1686,8 +1686,8 @@ get<ManagedTexture>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g)
|
||||
}
|
||||
|
||||
template <>
|
||||
inline const IntrusivePtr<gfx::Buffer>&
|
||||
get<IntrusivePtr<gfx::Buffer>>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) {
|
||||
inline const PersistentBuffer&
|
||||
get<PersistentBuffer>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) {
|
||||
const auto& handle = ccstd::get<
|
||||
impl::ValueHandle<PersistentBufferTag, ResourceGraph::vertex_descriptor>>(
|
||||
g._vertices[v].handle);
|
||||
@@ -1695,8 +1695,8 @@ get<IntrusivePtr<gfx::Buffer>>(ResourceGraph::vertex_descriptor v, const Resourc
|
||||
}
|
||||
|
||||
template <>
|
||||
inline const IntrusivePtr<gfx::Texture>&
|
||||
get<IntrusivePtr<gfx::Texture>>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) {
|
||||
inline const PersistentTexture&
|
||||
get<PersistentTexture>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) {
|
||||
const auto& handle = ccstd::get<
|
||||
impl::ValueHandle<PersistentTextureTag, ResourceGraph::vertex_descriptor>>(
|
||||
g._vertices[v].handle);
|
||||
@@ -1763,7 +1763,7 @@ get(ManagedTextureTag /*tag*/, ResourceGraph::vertex_descriptor v, ResourceGraph
|
||||
return g.managedTextures[handle.value];
|
||||
}
|
||||
|
||||
inline IntrusivePtr<gfx::Buffer>&
|
||||
inline PersistentBuffer&
|
||||
get(PersistentBufferTag /*tag*/, ResourceGraph::vertex_descriptor v, ResourceGraph& g) {
|
||||
auto& handle = ccstd::get<
|
||||
impl::ValueHandle<PersistentBufferTag, ResourceGraph::vertex_descriptor>>(
|
||||
@@ -1771,7 +1771,7 @@ get(PersistentBufferTag /*tag*/, ResourceGraph::vertex_descriptor v, ResourceGra
|
||||
return g.buffers[handle.value];
|
||||
}
|
||||
|
||||
inline IntrusivePtr<gfx::Texture>&
|
||||
inline PersistentTexture&
|
||||
get(PersistentTextureTag /*tag*/, ResourceGraph::vertex_descriptor v, ResourceGraph& g) {
|
||||
auto& handle = ccstd::get<
|
||||
impl::ValueHandle<PersistentTextureTag, ResourceGraph::vertex_descriptor>>(
|
||||
@@ -1835,7 +1835,7 @@ get(ManagedTextureTag /*tag*/, ResourceGraph::vertex_descriptor v, const Resourc
|
||||
return g.managedTextures[handle.value];
|
||||
}
|
||||
|
||||
inline const IntrusivePtr<gfx::Buffer>&
|
||||
inline const PersistentBuffer&
|
||||
get(PersistentBufferTag /*tag*/, ResourceGraph::vertex_descriptor v, const ResourceGraph& g) {
|
||||
const auto& handle = ccstd::get<
|
||||
impl::ValueHandle<PersistentBufferTag, ResourceGraph::vertex_descriptor>>(
|
||||
@@ -1843,7 +1843,7 @@ get(PersistentBufferTag /*tag*/, ResourceGraph::vertex_descriptor v, const Resou
|
||||
return g.buffers[handle.value];
|
||||
}
|
||||
|
||||
inline const IntrusivePtr<gfx::Texture>&
|
||||
inline const PersistentTexture&
|
||||
get(PersistentTextureTag /*tag*/, ResourceGraph::vertex_descriptor v, const ResourceGraph& g) {
|
||||
const auto& handle = ccstd::get<
|
||||
impl::ValueHandle<PersistentTextureTag, ResourceGraph::vertex_descriptor>>(
|
||||
@@ -1939,9 +1939,9 @@ get_if<ManagedTexture>(ResourceGraph::vertex_descriptor v, ResourceGraph* pGraph
|
||||
}
|
||||
|
||||
template <>
|
||||
inline IntrusivePtr<gfx::Buffer>*
|
||||
get_if<IntrusivePtr<gfx::Buffer>>(ResourceGraph::vertex_descriptor v, ResourceGraph* pGraph) noexcept { // NOLINT
|
||||
IntrusivePtr<gfx::Buffer>* ptr = nullptr;
|
||||
inline PersistentBuffer*
|
||||
get_if<PersistentBuffer>(ResourceGraph::vertex_descriptor v, ResourceGraph* pGraph) noexcept { // NOLINT
|
||||
PersistentBuffer* ptr = nullptr;
|
||||
if (!pGraph) {
|
||||
return ptr;
|
||||
}
|
||||
@@ -1956,9 +1956,9 @@ get_if<IntrusivePtr<gfx::Buffer>>(ResourceGraph::vertex_descriptor v, ResourceGr
|
||||
}
|
||||
|
||||
template <>
|
||||
inline IntrusivePtr<gfx::Texture>*
|
||||
get_if<IntrusivePtr<gfx::Texture>>(ResourceGraph::vertex_descriptor v, ResourceGraph* pGraph) noexcept { // NOLINT
|
||||
IntrusivePtr<gfx::Texture>* ptr = nullptr;
|
||||
inline PersistentTexture*
|
||||
get_if<PersistentTexture>(ResourceGraph::vertex_descriptor v, ResourceGraph* pGraph) noexcept { // NOLINT
|
||||
PersistentTexture* ptr = nullptr;
|
||||
if (!pGraph) {
|
||||
return ptr;
|
||||
}
|
||||
@@ -2096,9 +2096,9 @@ get_if<ManagedTexture>(ResourceGraph::vertex_descriptor v, const ResourceGraph*
|
||||
}
|
||||
|
||||
template <>
|
||||
inline const IntrusivePtr<gfx::Buffer>*
|
||||
get_if<IntrusivePtr<gfx::Buffer>>(ResourceGraph::vertex_descriptor v, const ResourceGraph* pGraph) noexcept { // NOLINT
|
||||
const IntrusivePtr<gfx::Buffer>* ptr = nullptr;
|
||||
inline const PersistentBuffer*
|
||||
get_if<PersistentBuffer>(ResourceGraph::vertex_descriptor v, const ResourceGraph* pGraph) noexcept { // NOLINT
|
||||
const PersistentBuffer* ptr = nullptr;
|
||||
if (!pGraph) {
|
||||
return ptr;
|
||||
}
|
||||
@@ -2113,9 +2113,9 @@ get_if<IntrusivePtr<gfx::Buffer>>(ResourceGraph::vertex_descriptor v, const Reso
|
||||
}
|
||||
|
||||
template <>
|
||||
inline const IntrusivePtr<gfx::Texture>*
|
||||
get_if<IntrusivePtr<gfx::Texture>>(ResourceGraph::vertex_descriptor v, const ResourceGraph* pGraph) noexcept { // NOLINT
|
||||
const IntrusivePtr<gfx::Texture>* ptr = nullptr;
|
||||
inline const PersistentTexture*
|
||||
get_if<PersistentTexture>(ResourceGraph::vertex_descriptor v, const ResourceGraph* pGraph) noexcept { // NOLINT
|
||||
const PersistentTexture* ptr = nullptr;
|
||||
if (!pGraph) {
|
||||
return ptr;
|
||||
}
|
||||
@@ -2432,7 +2432,7 @@ void addVertexImpl( // NOLINT
|
||||
template <class ValueT>
|
||||
void addVertexImpl( // NOLINT
|
||||
ValueT &&val, ResourceGraph &g, ResourceGraph::Vertex &vert, // NOLINT
|
||||
std::enable_if_t<std::is_same<std::decay_t<ValueT>, IntrusivePtr<gfx::Buffer>>::value>* dummy = nullptr) { // NOLINT
|
||||
std::enable_if_t<std::is_same<std::decay_t<ValueT>, PersistentBuffer>::value>* dummy = nullptr) { // NOLINT
|
||||
vert.handle = impl::ValueHandle<PersistentBufferTag, ResourceGraph::vertex_descriptor>{
|
||||
gsl::narrow_cast<ResourceGraph::vertex_descriptor>(g.buffers.size())};
|
||||
g.buffers.emplace_back(std::forward<ValueT>(val));
|
||||
@@ -2441,7 +2441,7 @@ void addVertexImpl( // NOLINT
|
||||
template <class ValueT>
|
||||
void addVertexImpl( // NOLINT
|
||||
ValueT &&val, ResourceGraph &g, ResourceGraph::Vertex &vert, // NOLINT
|
||||
std::enable_if_t<std::is_same<std::decay_t<ValueT>, IntrusivePtr<gfx::Texture>>::value>* dummy = nullptr) { // NOLINT
|
||||
std::enable_if_t<std::is_same<std::decay_t<ValueT>, PersistentTexture>::value>* dummy = nullptr) { // NOLINT
|
||||
vert.handle = impl::ValueHandle<PersistentTextureTag, ResourceGraph::vertex_descriptor>{
|
||||
gsl::narrow_cast<ResourceGraph::vertex_descriptor>(g.textures.size())};
|
||||
g.textures.emplace_back(std::forward<ValueT>(val));
|
||||
|
||||
@@ -171,6 +171,11 @@ SubpassGraph::Vertex::Vertex(Vertex const& rhs, const allocator_type& alloc)
|
||||
: outEdges(rhs.outEdges, alloc),
|
||||
inEdges(rhs.inEdges, alloc) {}
|
||||
|
||||
RasterSubpass::RasterSubpass(const allocator_type& alloc) noexcept
|
||||
: rasterViews(alloc),
|
||||
computeViews(alloc),
|
||||
resolvePairs(alloc) {}
|
||||
|
||||
RasterSubpass::RasterSubpass(uint32_t subpassIDIn, uint32_t countIn, uint32_t qualityIn, const allocator_type& alloc) noexcept
|
||||
: rasterViews(alloc),
|
||||
computeViews(alloc),
|
||||
@@ -199,6 +204,10 @@ RasterSubpass::RasterSubpass(RasterSubpass const& rhs, const allocator_type& all
|
||||
quality(rhs.quality),
|
||||
showStatistics(rhs.showStatistics) {}
|
||||
|
||||
ComputeSubpass::ComputeSubpass(const allocator_type& alloc) noexcept
|
||||
: rasterViews(alloc),
|
||||
computeViews(alloc) {}
|
||||
|
||||
ComputeSubpass::ComputeSubpass(uint32_t subpassIDIn, const allocator_type& alloc) noexcept
|
||||
: rasterViews(alloc),
|
||||
computeViews(alloc),
|
||||
|
||||
@@ -211,6 +211,15 @@ struct ManagedBuffer {
|
||||
uint64_t fenceValue{0};
|
||||
};
|
||||
|
||||
struct PersistentBuffer {
|
||||
PersistentBuffer() = default;
|
||||
PersistentBuffer(IntrusivePtr<gfx::Buffer> bufferIn) noexcept // NOLINT
|
||||
: buffer(std::move(bufferIn)) {}
|
||||
|
||||
IntrusivePtr<gfx::Buffer> buffer;
|
||||
uint64_t fenceValue{0};
|
||||
};
|
||||
|
||||
struct ManagedTexture {
|
||||
ManagedTexture() = default;
|
||||
ManagedTexture(IntrusivePtr<gfx::Texture> textureIn) noexcept // NOLINT
|
||||
@@ -222,6 +231,17 @@ struct ManagedTexture {
|
||||
uint64_t fenceValue{0};
|
||||
};
|
||||
|
||||
struct PersistentTexture {
|
||||
PersistentTexture() = default;
|
||||
PersistentTexture(IntrusivePtr<gfx::Texture> textureIn) noexcept // NOLINT
|
||||
: texture(std::move(textureIn)) {}
|
||||
|
||||
bool checkResource(const ResourceDesc &desc) const;
|
||||
|
||||
IntrusivePtr<gfx::Texture> texture;
|
||||
uint64_t fenceValue{0};
|
||||
};
|
||||
|
||||
struct ManagedResource {
|
||||
uint32_t unused{0};
|
||||
};
|
||||
@@ -390,6 +410,7 @@ struct RasterSubpass {
|
||||
return {rasterViews.get_allocator().resource()};
|
||||
}
|
||||
|
||||
RasterSubpass(const allocator_type& alloc) noexcept; // NOLINT
|
||||
RasterSubpass(uint32_t subpassIDIn, uint32_t countIn, uint32_t qualityIn, const allocator_type& alloc) noexcept;
|
||||
RasterSubpass(RasterSubpass&& rhs, const allocator_type& alloc);
|
||||
RasterSubpass(RasterSubpass const& rhs, const allocator_type& alloc);
|
||||
@@ -415,6 +436,7 @@ struct ComputeSubpass {
|
||||
return {rasterViews.get_allocator().resource()};
|
||||
}
|
||||
|
||||
ComputeSubpass(const allocator_type& alloc) noexcept; // NOLINT
|
||||
ComputeSubpass(uint32_t subpassIDIn, const allocator_type& alloc) noexcept;
|
||||
ComputeSubpass(ComputeSubpass&& rhs, const allocator_type& alloc);
|
||||
ComputeSubpass(ComputeSubpass const& rhs, const allocator_type& alloc);
|
||||
@@ -516,7 +538,6 @@ struct SubresourceView {
|
||||
uint16_t numArraySlices{0};
|
||||
uint16_t firstPlane{0};
|
||||
uint16_t numPlanes{0};
|
||||
gfx::TextureType viewType;
|
||||
};
|
||||
|
||||
struct ResourceGraph {
|
||||
@@ -637,8 +658,8 @@ struct ResourceGraph {
|
||||
|
||||
// PolymorphicGraph
|
||||
using VertexTag = ccstd::variant<ManagedTag, ManagedBufferTag, ManagedTextureTag, PersistentBufferTag, PersistentTextureTag, FramebufferTag, SwapchainTag, FormatViewTag, SubresourceViewTag>;
|
||||
using VertexValue = ccstd::variant<ManagedResource*, ManagedBuffer*, ManagedTexture*, IntrusivePtr<gfx::Buffer>*, IntrusivePtr<gfx::Texture>*, IntrusivePtr<gfx::Framebuffer>*, RenderSwapchain*, FormatView*, SubresourceView*>;
|
||||
using VertexConstValue = ccstd::variant<const ManagedResource*, const ManagedBuffer*, const ManagedTexture*, const IntrusivePtr<gfx::Buffer>*, const IntrusivePtr<gfx::Texture>*, const IntrusivePtr<gfx::Framebuffer>*, const RenderSwapchain*, const FormatView*, const SubresourceView*>;
|
||||
using VertexValue = ccstd::variant<ManagedResource*, ManagedBuffer*, ManagedTexture*, PersistentBuffer*, PersistentTexture*, IntrusivePtr<gfx::Framebuffer>*, RenderSwapchain*, FormatView*, SubresourceView*>;
|
||||
using VertexConstValue = ccstd::variant<const ManagedResource*, const ManagedBuffer*, const ManagedTexture*, const PersistentBuffer*, const PersistentTexture*, const IntrusivePtr<gfx::Framebuffer>*, const RenderSwapchain*, const FormatView*, const SubresourceView*>;
|
||||
using VertexHandle = ccstd::variant<
|
||||
impl::ValueHandle<ManagedTag, vertex_descriptor>,
|
||||
impl::ValueHandle<ManagedBufferTag, vertex_descriptor>,
|
||||
@@ -701,8 +722,8 @@ struct ResourceGraph {
|
||||
ccstd::pmr::vector<ManagedResource> resources;
|
||||
ccstd::pmr::vector<ManagedBuffer> managedBuffers;
|
||||
ccstd::pmr::vector<ManagedTexture> managedTextures;
|
||||
ccstd::pmr::vector<IntrusivePtr<gfx::Buffer>> buffers;
|
||||
ccstd::pmr::vector<IntrusivePtr<gfx::Texture>> textures;
|
||||
ccstd::pmr::vector<PersistentBuffer> buffers;
|
||||
ccstd::pmr::vector<PersistentTexture> textures;
|
||||
ccstd::pmr::vector<IntrusivePtr<gfx::Framebuffer>> framebuffers;
|
||||
ccstd::pmr::vector<RenderSwapchain> swapchains;
|
||||
ccstd::pmr::vector<FormatView> formatViews;
|
||||
@@ -847,18 +868,57 @@ struct RenderQueue {
|
||||
gfx::Viewport viewport;
|
||||
};
|
||||
|
||||
enum class CullingFlags : uint32_t {
|
||||
NONE = 0,
|
||||
CAMERA_FRUSTUM = 0x1,
|
||||
LIGHT_FRUSTUM = 0x2,
|
||||
LIGHT_BOUNDS = 0x4,
|
||||
};
|
||||
|
||||
constexpr CullingFlags operator|(const CullingFlags lhs, const CullingFlags rhs) noexcept {
|
||||
return static_cast<CullingFlags>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
|
||||
}
|
||||
|
||||
constexpr CullingFlags operator&(const CullingFlags lhs, const CullingFlags rhs) noexcept {
|
||||
return static_cast<CullingFlags>(static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs));
|
||||
}
|
||||
|
||||
constexpr CullingFlags& operator|=(CullingFlags& lhs, const CullingFlags rhs) noexcept {
|
||||
return lhs = lhs | rhs;
|
||||
}
|
||||
|
||||
constexpr CullingFlags& operator&=(CullingFlags& lhs, const CullingFlags rhs) noexcept {
|
||||
return lhs = lhs & rhs;
|
||||
}
|
||||
|
||||
constexpr bool operator!(CullingFlags e) noexcept {
|
||||
return e == static_cast<CullingFlags>(0);
|
||||
}
|
||||
|
||||
constexpr CullingFlags operator~(CullingFlags e) noexcept {
|
||||
return static_cast<CullingFlags>(~static_cast<std::underlying_type_t<CullingFlags>>(e));
|
||||
}
|
||||
|
||||
constexpr bool any(CullingFlags e) noexcept {
|
||||
return !!e;
|
||||
}
|
||||
|
||||
struct SceneData {
|
||||
SceneData() = default;
|
||||
SceneData(const scene::RenderScene* sceneIn, const scene::Camera* cameraIn, SceneFlags flagsIn, LightInfo lightIn) noexcept
|
||||
SceneData(const scene::RenderScene* sceneIn, const scene::Camera* cameraIn, SceneFlags flagsIn, LightInfo lightIn, CullingFlags cullingFlagsIn, IntrusivePtr<scene::Light> shadingLightIn) noexcept
|
||||
: scene(sceneIn),
|
||||
camera(cameraIn),
|
||||
light(std::move(lightIn)),
|
||||
flags(flagsIn) {}
|
||||
flags(flagsIn),
|
||||
cullingFlags(cullingFlagsIn),
|
||||
shadingLight(std::move(shadingLightIn)) {}
|
||||
|
||||
const scene::RenderScene* scene{nullptr};
|
||||
const scene::Camera* camera{nullptr};
|
||||
LightInfo light;
|
||||
SceneFlags flags{SceneFlags::NONE};
|
||||
CullingFlags cullingFlags{CullingFlags::CAMERA_FRUSTUM};
|
||||
IntrusivePtr<scene::Light> shadingLight;
|
||||
};
|
||||
|
||||
struct Dispatch {
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
// clang-format off
|
||||
#pragma once
|
||||
#include "cocos/base/std/variant.h"
|
||||
#include "cocos/core/assets/EffectAsset.h"
|
||||
#include "cocos/renderer/core/PassUtils.h"
|
||||
#include "cocos/renderer/pipeline/PipelineSceneData.h"
|
||||
#include "cocos/renderer/pipeline/custom/CustomFwd.h"
|
||||
|
||||
namespace cc {
|
||||
@@ -47,6 +44,7 @@ enum class SubpassCapabilities : uint32_t;
|
||||
struct PipelineCapabilities;
|
||||
class RenderNode;
|
||||
class Setter;
|
||||
class SceneBuilder;
|
||||
class RenderQueueBuilder;
|
||||
class BasicRenderPassBuilder;
|
||||
class BasicMultisampleRenderPassBuilder;
|
||||
|
||||
@@ -320,6 +320,10 @@ constexpr bool operator!(SubpassCapabilities e) noexcept {
|
||||
return e == static_cast<SubpassCapabilities>(0);
|
||||
}
|
||||
|
||||
constexpr SubpassCapabilities operator~(SubpassCapabilities e) noexcept {
|
||||
return static_cast<SubpassCapabilities>(~static_cast<std::underlying_type_t<SubpassCapabilities>>(e));
|
||||
}
|
||||
|
||||
constexpr bool any(SubpassCapabilities e) noexcept {
|
||||
return !!e;
|
||||
}
|
||||
@@ -460,10 +464,23 @@ public:
|
||||
virtual void setBuiltinSpotLightConstants(const scene::SpotLight *light, const scene::Camera *camera) = 0;
|
||||
virtual void setBuiltinPointLightConstants(const scene::PointLight *light, const scene::Camera *camera) = 0;
|
||||
virtual void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) = 0;
|
||||
virtual void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light, uint32_t level) = 0;
|
||||
virtual void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) = 0;
|
||||
void setBuiltinDirectionalLightViewConstants(const scene::DirectionalLight *light) {
|
||||
setBuiltinDirectionalLightViewConstants(light, 0);
|
||||
virtual void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) = 0;
|
||||
virtual void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) = 0;
|
||||
void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light) {
|
||||
setBuiltinDirectionalLightFrustumConstants(camera, light, 0);
|
||||
}
|
||||
};
|
||||
|
||||
class SceneBuilder : public Setter {
|
||||
public:
|
||||
SceneBuilder() noexcept = default;
|
||||
|
||||
virtual void useLightFrustum(IntrusivePtr<scene::Light> light, uint32_t csmLevel, const scene::Camera *optCamera) = 0;
|
||||
void useLightFrustum(IntrusivePtr<scene::Light> light) {
|
||||
useLightFrustum(std::move(light), 0, nullptr);
|
||||
}
|
||||
void useLightFrustum(IntrusivePtr<scene::Light> light, uint32_t csmLevel) {
|
||||
useLightFrustum(std::move(light), csmLevel, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -488,9 +505,7 @@ public:
|
||||
* @param sceneFlags @en Rendering flags of the scene @zh 场景渲染标志位
|
||||
*/
|
||||
virtual void addSceneOfCamera(scene::Camera *camera, LightInfo light, SceneFlags sceneFlags) = 0;
|
||||
virtual void addScene(const scene::Camera *camera, SceneFlags sceneFlags, const scene::Light *light) = 0;
|
||||
virtual void addSceneCulledByDirectionalLight(const scene::Camera *camera, SceneFlags sceneFlags, scene::DirectionalLight *light, uint32_t level) = 0;
|
||||
virtual void addSceneCulledBySpotLight(const scene::Camera *camera, SceneFlags sceneFlags, scene::SpotLight *light) = 0;
|
||||
virtual SceneBuilder *addScene(const scene::Camera *camera, SceneFlags sceneFlags, scene::Light *light) = 0;
|
||||
/**
|
||||
* @en Render a full-screen quad.
|
||||
* @zh 渲染全屏四边形
|
||||
@@ -528,8 +543,8 @@ public:
|
||||
void addSceneOfCamera(scene::Camera *camera, LightInfo light) {
|
||||
addSceneOfCamera(camera, std::move(light), SceneFlags::NONE);
|
||||
}
|
||||
void addScene(const scene::Camera *camera, SceneFlags sceneFlags) {
|
||||
addScene(camera, sceneFlags, nullptr);
|
||||
SceneBuilder *addScene(const scene::Camera *camera, SceneFlags sceneFlags) {
|
||||
return addScene(camera, sceneFlags, nullptr);
|
||||
}
|
||||
void addFullscreenQuad(Material *material, uint32_t passID) {
|
||||
addFullscreenQuad(material, passID, SceneFlags::NONE);
|
||||
@@ -771,14 +786,14 @@ public:
|
||||
* @param format @en Format of the resource @zh 资源的格式
|
||||
*/
|
||||
virtual void updateDepthStencil(const ccstd::string &name, uint32_t width, uint32_t height, gfx::Format format) = 0;
|
||||
virtual uint32_t addResource(const ccstd::string &name, ResourceDimension dimension, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) = 0;
|
||||
virtual void updateResource(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount) = 0;
|
||||
virtual uint32_t addTexture(const ccstd::string &name, gfx::TextureType type, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) = 0;
|
||||
virtual void updateTexture(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount) = 0;
|
||||
virtual uint32_t addBuffer(const ccstd::string &name, uint32_t size, ResourceFlags flags, ResourceResidency residency) = 0;
|
||||
virtual void updateBuffer(const ccstd::string &name, uint32_t size) = 0;
|
||||
virtual uint32_t addExternalTexture(const ccstd::string &name, gfx::Texture *texture, ResourceFlags flags) = 0;
|
||||
virtual void updateExternalTexture(const ccstd::string &name, gfx::Texture *texture) = 0;
|
||||
virtual uint32_t addTexture(const ccstd::string &name, gfx::TextureType type, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) = 0;
|
||||
virtual void updateTexture(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount) = 0;
|
||||
virtual uint32_t addResource(const ccstd::string &name, ResourceDimension dimension, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) = 0;
|
||||
virtual void updateResource(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount) = 0;
|
||||
/**
|
||||
* @engineInternal
|
||||
* @en Begin rendering one frame
|
||||
@@ -844,6 +859,7 @@ public:
|
||||
* @param copyPairs @en Array of copy source and target @zh 拷贝来源与目标的数组
|
||||
*/
|
||||
virtual void addCopyPass(const ccstd::vector<CopyPair> ©Pairs) = 0;
|
||||
virtual void addBuiltinReflectionProbePass(const scene::Camera *camera) = 0;
|
||||
/**
|
||||
* @engineInternal
|
||||
*/
|
||||
@@ -1497,6 +1513,7 @@ public:
|
||||
* @param pipeline @en Current render pipeline @zh 当前管线
|
||||
*/
|
||||
virtual void setup(const ccstd::vector<scene::Camera*> &cameras, BasicPipeline *pipeline) = 0;
|
||||
virtual void onGlobalPipelineStateChanged() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -106,6 +106,46 @@ using PmrUnorderedStringMultiMap = std::unordered_multimap<
|
||||
TransparentStringHash<typename Key::value_type>, std::equal_to<>,
|
||||
boost::container::pmr::polymorphic_allocator<std::pair<const Key, Value>>>;
|
||||
|
||||
template <class Key, class Value, class Allocator, class KeyLike>
|
||||
inline typename std::map<Key, Value, std::less<>, Allocator>::mapped_type&
|
||||
at(std::map<Key, Value, std::less<>, Allocator>& m, const KeyLike& key) {
|
||||
auto iter = m.find(key);
|
||||
if (iter == m.end()) {
|
||||
throw std::out_of_range("at(std::map) out of range");
|
||||
}
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
template <class Key, class Value, class Allocator, class KeyLike>
|
||||
inline typename std::map<Key, Value, std::less<>, Allocator>::mapped_type const&
|
||||
at(const std::map<Key, Value, std::less<>, Allocator>& m, const KeyLike& key) {
|
||||
auto iter = m.find(key);
|
||||
if (iter == m.end()) {
|
||||
throw std::out_of_range("at(std::map) out of range");
|
||||
}
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
template <class Key, class Value, class Allocator, class KeyLike>
|
||||
inline typename boost::container::flat_map<Key, Value, std::less<>, Allocator>::mapped_type&
|
||||
at(boost::container::flat_map<Key, Value, std::less<>, Allocator>& m, const KeyLike& key) {
|
||||
auto iter = m.find(key);
|
||||
if (iter == m.end()) {
|
||||
throw std::out_of_range("at(boost::container::flat_map) out of range");
|
||||
}
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
template <class Key, class Value, class Allocator, class KeyLike>
|
||||
inline typename boost::container::flat_map<Key, Value, std::less<>, Allocator>::mapped_type const&
|
||||
at(const boost::container::flat_map<Key, Value, std::less<>, Allocator>& m, const KeyLike& key) {
|
||||
auto iter = m.find(key);
|
||||
if (iter == m.end()) {
|
||||
throw std::out_of_range("at(boost::container::flat_map) out of range");
|
||||
}
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
|
||||
namespace ccstd {
|
||||
|
||||
Reference in New Issue
Block a user