Skip to content

Commit

Permalink
Merge branch 'v3.8.2-pipeline' of github.com:star-e/cocos-engine into…
Browse files Browse the repository at this point in the history
… v3.8.2-pipeline-0912
  • Loading branch information
GengineJS committed Sep 15, 2023
2 parents 9fc62b4 + 36a8efb commit ffe4e66
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 20 deletions.
4 changes: 2 additions & 2 deletions cocos/rendering/custom/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ export interface PipelineRuntime {
* This model is used to render profile information in Debug mode.
* @zh 获得分析工具(Profiler)的渲染实例,用于Debug模式下显示调试与性能检测信息
*/
profiler: Model | undefined;
profiler: Model | null;
/**
* @en Get geometry renderer.
* Geometry renderer is used to render procedural geometries.
* @zh 获得几何渲染器(GeometryRenderer),几何渲染器用于程序化渲染基础几何图形
*/
readonly geometryRenderer: GeometryRenderer | undefined;
readonly geometryRenderer: GeometryRenderer | null;
/**
* @en Get shading scale.
* Shading scale affects shading texels per pixel.
Expand Down
2 changes: 1 addition & 1 deletion cocos/rendering/custom/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface ProgramLibrary {
phaseID: number,
name: string,
defines: MacroRecord,
key?: string): ProgramProxy | undefined;
key?: string): ProgramProxy | null;
getBlockSizes (phaseID: number, programName: string): number[];
getHandleMap (phaseID: number, programName: string): Record<string, number>;
getProgramID (phaseID: number, programName: string): number;
Expand Down
9 changes: 8 additions & 1 deletion cocos/rendering/custom/render-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { AccessFlagBit, Buffer, ClearFlagBit, Color, Format, Framebuffer, LoadOp
import { AccessType, AttachmentType, ClearValueType, CopyPair, LightInfo, MovePair, QueueHint, ResolvePair, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UploadPair, RenderCommonObjectPool } from './types';
import { RenderScene } from '../../render-scene/core/render-scene';
import { RenderWindow } from '../../render-scene/core/render-window';
import { Light } from '../../render-scene/scene';
import { RecyclePool } from '../../core/memop';

export class ClearValue {
Expand Down Expand Up @@ -1532,30 +1533,35 @@ export class SceneData {
flags: SceneFlags = SceneFlags.NONE,
light: LightInfo = new LightInfo(),
cullingFlags: CullingFlags = CullingFlags.CAMERA_FRUSTUM,
shadingLight: Light | null = null,
) {
this.scene = scene;
this.camera = camera;
this.light = light;
this.flags = flags;
this.cullingFlags = cullingFlags;
this.shadingLight = shadingLight;
}
reset (
scene: RenderScene | null = null,
camera: Camera | null = null,
flags: SceneFlags = SceneFlags.NONE,
cullingFlags: CullingFlags = CullingFlags.CAMERA_FRUSTUM,
shadingLight: Light | null = null,
): void {
this.scene = scene;
this.camera = camera;
this.light.reset();
this.flags = flags;
this.cullingFlags = cullingFlags;
this.shadingLight = shadingLight;
}
/*pointer*/ scene: RenderScene | null;
/*pointer*/ camera: Camera | null;
readonly light: LightInfo;
flags: SceneFlags;
cullingFlags: CullingFlags;
/*refcount*/ shadingLight: Light | null;
}

export class Dispatch {
Expand Down Expand Up @@ -2844,9 +2850,10 @@ export class RenderGraphObjectPool {
camera: Camera | null = null,
flags: SceneFlags = SceneFlags.NONE,
cullingFlags: CullingFlags = CullingFlags.CAMERA_FRUSTUM,
shadingLight: Light | null = null,
): SceneData {
const v = this._sceneData.add();
v.reset(scene, camera, flags, cullingFlags);
v.reset(scene, camera, flags, cullingFlags, shadingLight);
return v;
}
createDispatch (
Expand Down
12 changes: 5 additions & 7 deletions cocos/rendering/custom/web-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2031,15 +2031,13 @@ export class WebPipeline implements BasicPipeline {
public get constantMacros (): string {
return this._constantMacros;
}
public get profiler (): Model | undefined {
return this._profiler ? this._profiler : undefined;
public get profiler (): Model | null {
return this._profiler;
}
public set profiler (profiler: Model | undefined) {
if (profiler) {
this._profiler = profiler;
}
public set profiler (profiler: Model | null) {
this._profiler = profiler;
}
public get geometryRenderer (): GeometryRenderer | undefined {
public get geometryRenderer (): GeometryRenderer | null {
throw new Error('Method not implemented.');
}
public get shadingScale (): number {
Expand Down
4 changes: 2 additions & 2 deletions cocos/rendering/post-process/passes/base-pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export function disablePostProcessForDebugView (): boolean {
return debugView.singleMode as number > 0;
}

export function getShadowMapSampler (): Sampler | null {
export function getShadowMapSampler (): Sampler | undefined {
if (!_pointSampler) {
const director = cclegacy.director;
const pipeline = director.root.pipeline;
const device = pipeline.device;
_pointSampler = device.getSampler(_samplerPointInfo);
}
return _pointSampler;
return _pointSampler || undefined;
}

export abstract class BasePass {
Expand Down
3 changes: 3 additions & 0 deletions native/cocos/renderer/pipeline/custom/NativeExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,9 @@ struct RenderGraphUploadVisitor : boost::dfs_visitor<> {
updateAndCreatePerPassDescriptorSet(vertID);
ctx.currentProjMatrix = sceneData.camera->getMatProj();
}
if (sceneData.shadingLight && !dynamic_cast<const scene::DirectionalLight*>(sceneData.shadingLight.get())) {

}
} else if (holds<BlitTag>(vertID, ctx.g)) {
const auto& blit = get(BlitTag{}, vertID, ctx.g);
if (blit.camera) {
Expand Down
14 changes: 11 additions & 3 deletions native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ CullingFlags makeCullingFlags(const LightInfo &light) {
void NativeRenderQueueBuilder::addSceneOfCamera(
scene::Camera *camera, LightInfo light, SceneFlags sceneFlags) {
const auto *pLight = light.light.get();
SceneData scene(camera->getScene(), camera, sceneFlags, light, makeCullingFlags(light));
SceneData scene(camera->getScene(), camera, sceneFlags, light, makeCullingFlags(light), light.light);
auto sceneID = addVertex2(
SceneTag{},
std::forward_as_tuple("Camera"),
Expand Down Expand Up @@ -768,6 +768,13 @@ void NativeSceneBuilder::useLightFrustum(
if (optCamera) {
sceneData.camera = optCamera;
}

// 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;
}
Expand All @@ -792,10 +799,11 @@ SceneBuilder *NativeRenderQueueBuilder::addScene(
camera->getScene(), // Scene and camera should be decoupled.
camera, // They are coupled for now.
sceneFlags,
LightInfo{light, 0}, // When doing rendering, csmLevel is irrelevant, set to zero.
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),
: CullingFlags::CAMERA_FRUSTUM,
light),
*renderGraph, nodeID);
CC_ENSURES(sceneID != RenderGraph::null_vertex());

Expand Down
4 changes: 2 additions & 2 deletions native/cocos/renderer/pipeline/custom/NativeSceneCulling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ LightBoundsCullingID SceneCulling::getOrCreateLightBoundsCulling(
return {};
}

CC_EXPECTS(sceneData.light.light);
CC_EXPECTS(sceneData.shadingLight);
const auto* const scene = sceneData.scene;
CC_EXPECTS(scene);

Expand All @@ -86,7 +86,7 @@ LightBoundsCullingID SceneCulling::getOrCreateLightBoundsCulling(
frustumCullingID,
sceneData.camera,
sceneData.light.probe,
sceneData.light.light,
sceneData.shadingLight,
};

// find query source
Expand Down
12 changes: 12 additions & 0 deletions native/cocos/renderer/pipeline/custom/RenderCommonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,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;
}
Expand Down Expand Up @@ -192,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;
}
Expand Down Expand Up @@ -320,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;
}
Expand Down
10 changes: 8 additions & 2 deletions native/cocos/renderer/pipeline/custom/RenderGraphTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,24 +895,30 @@ 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, CullingFlags cullingFlagsIn) 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),
cullingFlags(cullingFlagsIn) {}
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 {
Expand Down
4 changes: 4 additions & 0 deletions native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ffe4e66

Please sign in to comment.