From 7bb1c99d566773ee76c323c51782cad6f81321b6 Mon Sep 17 00:00:00 2001 From: Zhou Zhenglong Date: Tue, 12 Sep 2023 11:37:09 +0800 Subject: [PATCH] addScene simplified --- cocos/rendering/custom/pipeline.ts | 40 +++--- cocos/rendering/custom/private.ts | 2 +- cocos/rendering/custom/render-graph.ts | 40 +++++- cocos/rendering/custom/types.ts | 1 + cocos/rendering/custom/web-pipeline.ts | 91 +++++++++---- .../pipeline/custom/FrameGraphDispatcher.cpp | 6 +- .../pipeline/custom/NativePipelineFwd.h | 2 +- .../pipeline/custom/NativePipelineTypes.h | 86 ++++++------ .../pipeline/custom/NativeRenderGraph.cpp | 123 +++++++++--------- .../pipeline/custom/NativeResourceGraph.cpp | 8 +- .../renderer/pipeline/custom/NativeSetter.cpp | 4 +- .../pipeline/custom/RenderCommonTypes.h | 1 + .../renderer/pipeline/custom/RenderGraphFwd.h | 2 + .../pipeline/custom/RenderGraphGraphs.h | 56 ++++---- .../pipeline/custom/RenderGraphTypes.h | 28 +++- .../pipeline/custom/RenderInterfaceFwd.h | 1 + .../pipeline/custom/RenderInterfaceTypes.h | 27 ++-- native/tools/swig-config/render.i | 2 - package-lock.json | 4 +- 19 files changed, 311 insertions(+), 213 deletions(-) diff --git a/cocos/rendering/custom/pipeline.ts b/cocos/rendering/custom/pipeline.ts index d0e1960dc6a..c749445f4f7 100644 --- a/cocos/rendering/custom/pipeline.ts +++ b/cocos/rendering/custom/pipeline.ts @@ -119,13 +119,13 @@ export interface PipelineRuntime { * This model is used to render profile information in Debug mode. * @zh 获得分析工具(Profiler)的渲染实例,用于Debug模式下显示调试与性能检测信息 */ - profiler: Model | null; + profiler: Model | undefined; /** * @en Get geometry renderer. * Geometry renderer is used to render procedural geometries. * @zh 获得几何渲染器(GeometryRenderer),几何渲染器用于程序化渲染基础几何图形 */ - readonly geometryRenderer: GeometryRenderer | null; + readonly geometryRenderer: GeometryRenderer | undefined; /** * @en Get shading scale. * Shading scale affects shading texels per pixel. @@ -385,11 +385,18 @@ export interface Setter extends RenderNode { setBuiltinSpotLightConstants (light: SpotLight, camera: Camera): void; setBuiltinPointLightConstants (light: PointLight, camera: Camera): void; setBuiltinRangedDirectionalLightConstants (light: RangedDirectionalLight, camera: Camera): void; - setBuiltinDirectionalLightViewConstants ( + setBuiltinDirectionalLightFrustumConstants ( camera: Camera, light: DirectionalLight, - level?: number): void; - setBuiltinSpotLightViewConstants (light: SpotLight): void; + csmLevel?: number): void; + setBuiltinSpotLightFrustumConstants (light: SpotLight): void; +} + +export interface SceneBuilder extends Setter { + useLightFrustum ( + light: Light, + csmLevel?: number, + optCamera?: Camera): void; } /** @@ -416,16 +423,7 @@ export interface RenderQueueBuilder extends Setter { addScene ( camera: Camera, sceneFlags: SceneFlags, - light?: Light | null): Setter; - addSceneCulledByDirectionalLight ( - camera: Camera, - sceneFlags: SceneFlags, - light: DirectionalLight, - level: number): Setter; - addSceneCulledBySpotLight ( - camera: Camera, - sceneFlags: SceneFlags, - light: SpotLight): Setter; + light?: Light): SceneBuilder; /** * @en Render a full-screen quad. * @zh 渲染全屏四边形 @@ -518,7 +516,7 @@ export interface BasicRenderPassBuilder extends Setter { addTexture ( name: string, slotName: string, - sampler?: Sampler | null, + sampler?: Sampler, plane?: number): void; /** * @en Add render queue. @@ -817,7 +815,7 @@ export interface BasicPipeline extends PipelineRuntime { /** * @engineInternal */ - getDescriptorSetLayout (shaderName: string, freq: UpdateFrequency): DescriptorSetLayout | null; + getDescriptorSetLayout (shaderName: string, freq: UpdateFrequency): DescriptorSetLayout | undefined; } /** @@ -880,7 +878,7 @@ export interface RenderSubpassBuilder extends Setter { addTexture ( name: string, slotName: string, - sampler?: Sampler | null, + sampler?: Sampler, plane?: number): void; /** * @en Add storage buffer. @@ -1024,7 +1022,7 @@ export interface ComputeSubpassBuilder extends Setter { addTexture ( name: string, slotName: string, - sampler?: Sampler | null, + sampler?: Sampler, plane?: number): void; /** * @en Add storage buffer. @@ -1180,7 +1178,7 @@ export interface ComputePassBuilder extends Setter { addTexture ( name: string, slotName: string, - sampler?: Sampler | null, + sampler?: Sampler, plane?: number): void; /** * @en Add storage buffer. @@ -1394,7 +1392,7 @@ export interface Pipeline extends BasicPipeline { addBuiltinGpuCullingPass ( camera: Camera, hzbName?: string, - light?: Light | null): void; + light?: Light): void; addBuiltinHzbGenerationPass (sourceDepthStencilName: string, targetHzbName: string): void; /** * @experimental diff --git a/cocos/rendering/custom/private.ts b/cocos/rendering/custom/private.ts index 62e2393c627..e0f40bd8b42 100644 --- a/cocos/rendering/custom/private.ts +++ b/cocos/rendering/custom/private.ts @@ -64,7 +64,7 @@ export interface ProgramLibrary { phaseID: number, name: string, defines: MacroRecord, - key?: string | null): ProgramProxy | null; + key?: string): ProgramProxy | undefined; getBlockSizes (phaseID: number, programName: string): number[]; getHandleMap (phaseID: number, programName: string): Record; getProgramID (phaseID: number, programName: string): number; diff --git a/cocos/rendering/custom/render-graph.ts b/cocos/rendering/custom/render-graph.ts index a0f7522c2c8..c7e69cd7b8f 100644 --- a/cocos/rendering/custom/render-graph.ts +++ b/cocos/rendering/custom/render-graph.ts @@ -226,6 +226,10 @@ export class PersistentBuffer { constructor (buffer: Buffer | null = null) { this.buffer = buffer; } + reset (buffer: Buffer | null = null): void { + this.buffer = buffer; + this.fenceValue = 0; + } /*refcount*/ buffer: Buffer | null; fenceValue = 0; } @@ -246,6 +250,10 @@ export class PersistentTexture { constructor (texture: Texture | null = null) { this.texture = texture; } + reset (texture: Texture | null = null): void { + this.texture = texture; + this.fenceValue = 0; + } /*refcount*/ texture: Texture | null; fenceValue = 0; } @@ -747,14 +755,12 @@ export interface ResourceGraphVisitor { export type ResourceGraphObject = ManagedResource | ManagedBuffer | ManagedTexture -| Buffer -| Texture +| PersistentBuffer +| PersistentTexture | Framebuffer | RenderSwapchain | FormatView -| SubresourceView -| PersistentBuffer -| PersistentTexture; +| SubresourceView; //----------------------------------------------------------------- // Graph Concept @@ -2514,7 +2520,9 @@ export class RenderGraphObjectPoolSettings { this.renderSwapchainBatchSize = batchSize; this.resourceStatesBatchSize = batchSize; this.managedBufferBatchSize = batchSize; + this.persistentBufferBatchSize = batchSize; this.managedTextureBatchSize = batchSize; + this.persistentTextureBatchSize = batchSize; this.managedResourceBatchSize = batchSize; this.subpassBatchSize = batchSize; this.subpassGraphBatchSize = batchSize; @@ -2546,7 +2554,9 @@ export class RenderGraphObjectPoolSettings { renderSwapchainBatchSize = 16; resourceStatesBatchSize = 16; managedBufferBatchSize = 16; + persistentBufferBatchSize = 16; managedTextureBatchSize = 16; + persistentTextureBatchSize = 16; managedResourceBatchSize = 16; subpassBatchSize = 16; subpassGraphBatchSize = 16; @@ -2582,7 +2592,9 @@ export class RenderGraphObjectPool { this._renderSwapchain = new RecyclePool(() => new RenderSwapchain(), settings.renderSwapchainBatchSize); this._resourceStates = new RecyclePool(() => new ResourceStates(), settings.resourceStatesBatchSize); this._managedBuffer = new RecyclePool(() => new ManagedBuffer(), settings.managedBufferBatchSize); + this._persistentBuffer = new RecyclePool(() => new PersistentBuffer(), settings.persistentBufferBatchSize); this._managedTexture = new RecyclePool(() => new ManagedTexture(), settings.managedTextureBatchSize); + this._persistentTexture = new RecyclePool(() => new PersistentTexture(), settings.persistentTextureBatchSize); this._managedResource = new RecyclePool(() => new ManagedResource(), settings.managedResourceBatchSize); this._subpass = new RecyclePool(() => new Subpass(), settings.subpassBatchSize); this._subpassGraph = new RecyclePool(() => new SubpassGraph(), settings.subpassGraphBatchSize); @@ -2615,7 +2627,9 @@ export class RenderGraphObjectPool { this._renderSwapchain.reset(); this._resourceStates.reset(); this._managedBuffer.reset(); + this._persistentBuffer.reset(); this._managedTexture.reset(); + this._persistentTexture.reset(); this._managedResource.reset(); this._subpass.reset(); this._subpassGraph.reset(); @@ -2704,6 +2718,13 @@ export class RenderGraphObjectPool { v.reset(buffer); return v; } + createPersistentBuffer ( + buffer: Buffer | null = null, + ): PersistentBuffer { + const v = this._persistentBuffer.add(); + v.reset(buffer); + return v; + } createManagedTexture ( texture: Texture | null = null, ): ManagedTexture { @@ -2711,6 +2732,13 @@ export class RenderGraphObjectPool { v.reset(texture); return v; } + createPersistentTexture ( + texture: Texture | null = null, + ): PersistentTexture { + const v = this._persistentTexture.add(); + v.reset(texture); + return v; + } createManagedResource (): ManagedResource { const v = this._managedResource.add(); v.reset(); @@ -2861,7 +2889,9 @@ export class RenderGraphObjectPool { private readonly _renderSwapchain: RecyclePool; private readonly _resourceStates: RecyclePool; private readonly _managedBuffer: RecyclePool; + private readonly _persistentBuffer: RecyclePool; private readonly _managedTexture: RecyclePool; + private readonly _persistentTexture: RecyclePool; private readonly _managedResource: RecyclePool; private readonly _subpass: RecyclePool; private readonly _subpassGraph: RecyclePool; diff --git a/cocos/rendering/custom/types.ts b/cocos/rendering/custom/types.ts index 47ff74a394c..577955e8017 100644 --- a/cocos/rendering/custom/types.ts +++ b/cocos/rendering/custom/types.ts @@ -210,6 +210,7 @@ export enum SceneFlags { DRAW_NON_INSTANCING = 0x1000, REFLECTION_PROBE = 0x2000, GPU_DRIVEN = 0x4000, + NON_BUILTIN = 0x8000, ALL = 0xFFFFFFFF, } diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index 133f40ca697..f1fe7cb129c 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -29,7 +29,7 @@ import { Buffer, DescriptorSetLayout, Device, Feature, Format, FormatFeatureBit, import { Mat4, Quat, toRadian, Vec2, Vec3, Vec4, assert, macro, cclegacy, IVec4Like, IMat4Like, IVec2Like, Color as CoreColor } from '../../core'; import { AccessType, AttachmentType, CopyPair, LightInfo, LightingMode, MovePair, QueueHint, ResolvePair, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UpdateFrequency, UploadPair } from './types'; import { ComputeView, RasterView, Blit, ClearView, ComputePass, CopyPass, Dispatch, ManagedBuffer, ManagedResource, MovePass, RasterPass, RasterSubpass, RenderData, RenderGraph, RenderGraphComponent, RenderGraphValue, RenderQueue, RenderSwapchain, ResourceDesc, ResourceGraph, ResourceGraphValue, ResourceStates, ResourceTraits, SceneData, Subpass, PersistentBuffer } from './render-graph'; -import { ComputePassBuilder, ComputeQueueBuilder, BasicPipeline, PipelineBuilder, RenderQueueBuilder, RenderSubpassBuilder, PipelineType, BasicRenderPassBuilder, PipelineCapabilities, BasicMultisampleRenderPassBuilder, Setter } from './pipeline'; +import { ComputePassBuilder, ComputeQueueBuilder, BasicPipeline, PipelineBuilder, RenderQueueBuilder, RenderSubpassBuilder, PipelineType, BasicRenderPassBuilder, PipelineCapabilities, BasicMultisampleRenderPassBuilder, Setter, SceneBuilder } from './pipeline'; import { PipelineSceneData } from '../pipeline-scene-data'; import { Model, Camera, ShadowType, CSMLevel, DirectionalLight, SpotLight, PCFType, Shadows, SphereLight, PointLight, RangedDirectionalLight, ProbeType } from '../../render-scene/scene'; import { Light, LightType } from '../../render-scene/scene/light'; @@ -275,10 +275,10 @@ export class WebSetter implements Setter { public setBuiltinShadowMapConstants (light: Light, numLevels?: number): void { // TODO } - public setBuiltinDirectionalLightViewConstants (camera: Camera, light: DirectionalLight, level = 0): void { - setShadowUBOLightView(this, camera, light, level); + public setBuiltinDirectionalLightFrustumConstants (camera: Camera, light: DirectionalLight, csmLevel = 0): void { + setShadowUBOLightView(this, camera, light, csmLevel); } - public setBuiltinSpotLightViewConstants (light: SpotLight): void { + public setBuiltinSpotLightFrustumConstants (light: SpotLight): void { // TODO } public setBuiltinDirectionalLightConstants (light: DirectionalLight, camera: Camera): void { @@ -327,7 +327,7 @@ function setShadowUBOLightView ( setter: WebSetter, camera: Camera, light: Light, - level: number, + csmLevel: number, layout = 'default', ): void { const director = cclegacy.director; @@ -383,7 +383,7 @@ function setShadowUBOLightView ( setter.offsetVec4(_uboVec, uniformOffset); } } else { - const layer = csmLayers.layers[level]; + const layer = csmLayers.layers[csmLevel]; matShadowView = layer.matShadowView; matShadowProj = layer.matShadowProj; matShadowViewProj = layer.matShadowViewProj; @@ -879,6 +879,39 @@ function getResourceDimension (type: TextureType): ResourceDimension { return ResourceDimension.TEXTURE2D; } +export class WebSceneBuilder extends WebSetter implements SceneBuilder { + constructor ( + data: RenderData, + layoutGraph: LayoutGraphData, + rg: RenderGraph, + sceneId: number, + scene: SceneData, + ) { + super(data, layoutGraph); + this._renderGraph = rg; + this._scene = scene; + this._sceneId = sceneId; + } + useLightFrustum (light: Light, csmLevel = 0, optCamera: Camera | undefined = undefined): void { + this._scene.light.light = light; + this._scene.light.level = csmLevel; + this._scene.light.culledByLight = true; + if (optCamera) { + this._scene.camera = optCamera; + } + if (this._scene.flags & SceneFlags.NON_BUILTIN) { + return; + } + const queueId = this._renderGraph.getParent(this._sceneId); + const passId = this._renderGraph.getParent(queueId); + const layoutName = this._renderGraph.getLayout(passId); + setShadowUBOLightView(this, this._scene.camera!, light, csmLevel, layoutName); + } + private readonly _renderGraph: RenderGraph; + private readonly _scene: SceneData; + private readonly _sceneId: number; +} + export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuilder { constructor (data: RenderData, renderGraph: RenderGraph, layoutGraph: LayoutGraphData, vertID: number, queue: RenderQueue, pipeline: PipelineSceneData) { super(data, layoutGraph); @@ -923,23 +956,27 @@ export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuild setTextureUBOView(this, camera, this._pipeline); initGlobalDescBinding(this._data, layoutName); } - addScene (camera: Camera, sceneFlags = SceneFlags.NONE): Setter { + addScene (camera: Camera, sceneFlags = SceneFlags.NONE, light: Light | undefined = undefined): SceneBuilder { const sceneData = new SceneData(camera.scene, camera, sceneFlags); + if (light) { + sceneData.light.light = light; + } const renderData = new RenderData(); - this._renderGraph.addVertex(RenderGraphValue.Scene, sceneData, 'Scene', '', renderData, false, this._vertID); - return new WebSetter(renderData, this._lg); - } - addSceneCulledByDirectionalLight (camera: Camera, sceneFlags: SceneFlags, light: DirectionalLight, level: number): Setter { - const sceneData = new SceneData(camera.scene, camera, sceneFlags, new LightInfo(light, level)); - const renderData = new RenderData(); - this._renderGraph.addVertex(RenderGraphValue.Scene, sceneData, 'Scene', '', renderData, false, this._vertID); - return new WebSetter(renderData, this._lg); - } - addSceneCulledBySpotLight (camera: Camera, sceneFlags: SceneFlags, light: SpotLight): Setter { - const sceneData = new SceneData(camera.scene, camera, sceneFlags, new LightInfo(light, 0)); - const renderData = new RenderData(); - this._renderGraph.addVertex(RenderGraphValue.Scene, sceneData, 'Scene', '', renderData, false, this._vertID); - return new WebSetter(renderData, this._lg); + const sceneId = this._renderGraph.addVertex(RenderGraphValue.Scene, sceneData, 'Scene', '', renderData, false, this._vertID); + if (!(sceneFlags & SceneFlags.NON_BUILTIN)) { + const layoutName = this.getLayoutName(); + setCameraUBOValues( + this, + camera, + this._pipeline, + camera.scene, + layoutName, + ); + setShadowUBOView(this, camera, layoutName); + setTextureUBOView(this, camera, this._pipeline); + initGlobalDescBinding(this._data, layoutName); + } + return new WebSceneBuilder(renderData, this._lg, this._renderGraph, sceneId, sceneData); } addFullscreenQuad (material: Material, passID: number, sceneFlags = SceneFlags.NONE, name = 'Quad'): void { this._renderGraph.addVertex( @@ -1838,13 +1875,15 @@ export class WebPipeline implements BasicPipeline { public get constantMacros (): string { return this._constantMacros; } - public get profiler (): Model | null { - return this._profiler; + public get profiler (): Model | undefined { + return this._profiler ? this._profiler : undefined; } - public set profiler (profiler: Model | null) { - this._profiler = profiler; + public set profiler (profiler: Model | undefined) { + if (profiler) { + this._profiler = profiler; + } } - public get geometryRenderer (): GeometryRenderer | null { + public get geometryRenderer (): GeometryRenderer | undefined { throw new Error('Method not implemented.'); } public get shadingScale (): number { diff --git a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp index 4ead5bdd8cc..f224a739172 100644 --- a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp +++ b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp @@ -314,12 +314,12 @@ RenderingInfo FrameGraphDispatcher::getRenderPassAndFrameBuffer(RenderGraph::ver CC_EXPECTS(tex.texture); fbInfo.colorTextures.emplace_back(tex.texture); }, - [&](const IntrusivePtr &res) { + [&](const PersistentBuffer &res) { std::ignore = res; CC_EXPECTS(false); }, - [&](const IntrusivePtr &tex) { - fbInfo.colorTextures.emplace_back(tex); + [&](const PersistentTexture &tex) { + fbInfo.colorTextures.emplace_back(tex.texture); }, [&](const IntrusivePtr &fb) { CC_EXPECTS(fb->getColorTextures().size() == 1); diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineFwd.h b/native/cocos/renderer/pipeline/custom/NativePipelineFwd.h index 1860969b097..29fc3204c2d 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineFwd.h +++ b/native/cocos/renderer/pipeline/custom/NativePipelineFwd.h @@ -57,7 +57,7 @@ namespace render { class NativeRenderNode; class NativeSetter; -class NativeSetterBuilder; +class NativeSceneBuilder; class NativeRenderSubpassBuilderImpl; class NativeRenderQueueBuilder; class NativeRenderSubpassBuilder; diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h b/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h index cfe8ccd47fe..06216cc2e83 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h +++ b/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h @@ -96,8 +96,8 @@ class NativeSetter : public NativeRenderNode { 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::Camera *camera, 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); @@ -109,9 +109,9 @@ class NativeSetter : public NativeRenderNode { uint32_t layoutID{LayoutGraphData::null_vertex()}; }; -class NativeSetterBuilder final : public Setter, public NativeSetter { +class NativeSceneBuilder final : public SceneBuilder, public NativeSetter { public: - NativeSetterBuilder(const PipelineRuntime* pipelineRuntimeIn, RenderGraph* renderGraphIn, uint32_t nodeIDIn, const LayoutGraphData* layoutGraphIn, uint32_t layoutIDIn) noexcept + 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 { @@ -181,12 +181,14 @@ class NativeSetterBuilder final : public Setter, public NativeSetter { void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override { NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera); } - void setBuiltinDirectionalLightViewConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t level) override { - NativeSetter::setBuiltinDirectionalLightViewConstants(camera, 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 useLightFrustum(IntrusivePtr light, uint32_t csmLevel, const scene::Camera *optCamera) override; }; class NativeRenderSubpassBuilderImpl : public NativeSetter { @@ -278,17 +280,15 @@ class NativeRenderQueueBuilder final : public RenderQueueBuilder, public NativeS void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override { NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera); } - void setBuiltinDirectionalLightViewConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t level) override { - NativeSetter::setBuiltinDirectionalLightViewConstants(camera, 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; - Setter *addScene(const scene::Camera *camera, SceneFlags sceneFlags, const scene::Light *light) override; - Setter *addSceneCulledByDirectionalLight(const scene::Camera *camera, SceneFlags sceneFlags, scene::DirectionalLight *light, uint32_t level) override; - Setter *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; @@ -368,11 +368,11 @@ class NativeRenderSubpassBuilder final : public RenderSubpassBuilder, public Nat void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override { NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera); } - void setBuiltinDirectionalLightViewConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t level) override { - NativeSetter::setBuiltinDirectionalLightViewConstants(camera, 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 { @@ -479,11 +479,11 @@ class NativeMultisampleRenderSubpassBuilder final : public MultisampleRenderSubp void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override { NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera); } - void setBuiltinDirectionalLightViewConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t level) override { - NativeSetter::setBuiltinDirectionalLightViewConstants(camera, 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 { @@ -593,11 +593,11 @@ class NativeComputeSubpassBuilder final : public ComputeSubpassBuilder, public N void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override { NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera); } - void setBuiltinDirectionalLightViewConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t level) override { - NativeSetter::setBuiltinDirectionalLightViewConstants(camera, 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; @@ -680,11 +680,11 @@ class NativeRenderPassBuilder final : public RenderPassBuilder, public NativeSet void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override { NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera); } - void setBuiltinDirectionalLightViewConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t level) override { - NativeSetter::setBuiltinDirectionalLightViewConstants(camera, 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; @@ -779,11 +779,11 @@ class NativeMultisampleRenderPassBuilder final : public MultisampleRenderPassBui void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override { NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera); } - void setBuiltinDirectionalLightViewConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t level) override { - NativeSetter::setBuiltinDirectionalLightViewConstants(camera, 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; @@ -877,11 +877,11 @@ class NativeComputeQueueBuilder final : public ComputeQueueBuilder, public Nativ void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override { NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera); } - void setBuiltinDirectionalLightViewConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t level) override { - NativeSetter::setBuiltinDirectionalLightViewConstants(camera, 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; @@ -959,11 +959,11 @@ class NativeComputePassBuilder final : public ComputePassBuilder, public NativeS void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) override { NativeSetter::setBuiltinRangedDirectionalLightConstants(light, camera); } - void setBuiltinDirectionalLightViewConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t level) override { - NativeSetter::setBuiltinDirectionalLightViewConstants(camera, 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; diff --git a/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp index 8974aaa4255..0b028506e07 100644 --- a/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp @@ -759,23 +759,75 @@ void NativeRenderQueueBuilder::addSceneOfCamera( data); } -Setter *NativeRenderQueueBuilder::addScene(const scene::Camera *camera, SceneFlags sceneFlags, const scene::Light *light) { - auto cullingFlags = CullingFlags::CAMERA_FRUSTUM; - if (light) { - cullingFlags |= CullingFlags::LIGHT_BOUNDS; +void NativeSceneBuilder::useLightFrustum( + IntrusivePtr 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; + } + if (any(sceneData.flags & SceneFlags::NON_BUILTIN)) { + return; } - SceneData data(camera->getScene(), camera, sceneFlags, LightInfo{}, cullingFlags); - auto sceneID = addVertex2( + const auto *pLight = dynamic_cast(light.get()); + if (pLight) { + setBuiltinDirectionalLightFrustumConstants(sceneData.camera, pLight, csmLevel); + } else { + CC_EXPECTS(false); + } +} + +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{light, 0}, // When doing rendering, csmLevel is irrelevant, set to zero. + // 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), *renderGraph, nodeID); CC_ENSURES(sceneID != RenderGraph::null_vertex()); + auto builder = std::make_unique( + pipelineRuntime, + renderGraph, + sceneID, + layoutGraph, + layoutID); + + if (!any(sceneFlags & SceneFlags::NON_BUILTIN)) { + // objects are projected to camera, set camera ubo + builder->setBuiltinCameraConstants(camera); + + if (const auto *pDirLight = camera->getScene()->getMainLight(); pDirLight) { + // light is directional + builder->setBuiltinDirectionalLightConstants(pDirLight, camera); + } else if (light) { + // light is non-directional + // builder->setBuiltinXxxLightConstants(light, camera); + CC_EXPECTS(false); + } + + // 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(pipelineRuntime)->nativeContext.sceneCulling.gpuCullingPassID; @@ -812,62 +864,7 @@ Setter *NativeRenderQueueBuilder::addScene(const scene::Camera *camera, SceneFla } } - return new NativeSetterBuilder( - pipelineRuntime, - renderGraph, - sceneID, - layoutGraph, - layoutID); -} - -Setter *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}, CullingFlags::LIGHT_FRUSTUM); - - 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 new NativeSetterBuilder( - pipelineRuntime, - renderGraph, - sceneID, - layoutGraph, - layoutID); -} - -Setter *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}, CullingFlags::LIGHT_FRUSTUM); - - 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 new NativeSetterBuilder( - pipelineRuntime, - renderGraph, - sceneID, - layoutGraph, - layoutID); + return builder.release(); } void NativeRenderQueueBuilder::addFullscreenQuad( diff --git a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp index 604a9aca1fa..736283688ab 100644 --- a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp @@ -207,12 +207,12 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) { CC_ENSURES(texture.texture); texture.fenceValue = nextFenceValue; }, - [&](const IntrusivePtr& buffer) { - CC_EXPECTS(buffer); + [&](const PersistentBuffer& buffer) { + CC_EXPECTS(buffer.buffer); std::ignore = buffer; }, - [&](const IntrusivePtr& texture) { - CC_EXPECTS(texture); + [&](const PersistentTexture& texture) { + CC_EXPECTS(texture.texture); std::ignore = texture; }, [&](const IntrusivePtr& fb) { diff --git a/native/cocos/renderer/pipeline/custom/NativeSetter.cpp b/native/cocos/renderer/pipeline/custom/NativeSetter.cpp index 0ff02f007b7..b06cfbbc52b 100644 --- a/native/cocos/renderer/pipeline/custom/NativeSetter.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeSetter.cpp @@ -123,7 +123,7 @@ 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); @@ -138,7 +138,7 @@ void NativeSetter::setBuiltinDirectionalLightViewConstants( 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(); diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonTypes.h b/native/cocos/renderer/pipeline/custom/RenderCommonTypes.h index 2054c2d314e..8a60f7aa6c1 100644 --- a/native/cocos/renderer/pipeline/custom/RenderCommonTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderCommonTypes.h @@ -168,6 +168,7 @@ enum class SceneFlags : uint32_t { DRAW_NON_INSTANCING = 0x1000, REFLECTION_PROBE = 0x2000, GPU_DRIVEN = 0x4000, + NON_BUILTIN = 0x8000, ALL = 0xFFFFFFFF, }; diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphFwd.h b/native/cocos/renderer/pipeline/custom/RenderGraphFwd.h index 09e8106431a..9714e8db649 100644 --- a/native/cocos/renderer/pipeline/custom/RenderGraphFwd.h +++ b/native/cocos/renderer/pipeline/custom/RenderGraphFwd.h @@ -45,7 +45,9 @@ struct ResourceTraits; struct RenderSwapchain; struct ResourceStates; struct ManagedBuffer; +struct PersistentBuffer; struct ManagedTexture; +struct PersistentTexture; struct ManagedResource; struct Subpass; struct SubpassGraph; diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphGraphs.h b/native/cocos/renderer/pipeline/custom/RenderGraphGraphs.h index e14bfd7c411..9f129ec00ea 100644 --- a/native/cocos/renderer/pipeline/custom/RenderGraphGraphs.h +++ b/native/cocos/renderer/pipeline/custom/RenderGraphGraphs.h @@ -1523,7 +1523,7 @@ holds_alternative(ResourceGraph::vertex_descriptor v, const Reso template <> inline bool -holds_alternative>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) noexcept { // NOLINT +holds_alternative(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) noexcept { // NOLINT return ccstd::holds_alternative< impl::ValueHandle>( g._vertices[v].handle); @@ -1531,7 +1531,7 @@ holds_alternative>(ResourceGraph::vertex_descriptor v, template <> inline bool -holds_alternative>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) noexcept { // NOLINT +holds_alternative(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) noexcept { // NOLINT return ccstd::holds_alternative< impl::ValueHandle>( g._vertices[v].handle); @@ -1601,8 +1601,8 @@ get(ResourceGraph::vertex_descriptor v, ResourceGraph& g) { } template <> -inline IntrusivePtr& -get>(ResourceGraph::vertex_descriptor v, ResourceGraph& g) { +inline PersistentBuffer& +get(ResourceGraph::vertex_descriptor v, ResourceGraph& g) { auto& handle = ccstd::get< impl::ValueHandle>( g._vertices[v].handle); @@ -1610,8 +1610,8 @@ get>(ResourceGraph::vertex_descriptor v, ResourceGraph } template <> -inline IntrusivePtr& -get>(ResourceGraph::vertex_descriptor v, ResourceGraph& g) { +inline PersistentTexture& +get(ResourceGraph::vertex_descriptor v, ResourceGraph& g) { auto& handle = ccstd::get< impl::ValueHandle>( g._vertices[v].handle); @@ -1686,8 +1686,8 @@ get(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) } template <> -inline const IntrusivePtr& -get>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) { +inline const PersistentBuffer& +get(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) { const auto& handle = ccstd::get< impl::ValueHandle>( g._vertices[v].handle); @@ -1695,8 +1695,8 @@ get>(ResourceGraph::vertex_descriptor v, const Resourc } template <> -inline const IntrusivePtr& -get>(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) { +inline const PersistentTexture& +get(ResourceGraph::vertex_descriptor v, const ResourceGraph& g) { const auto& handle = ccstd::get< impl::ValueHandle>( g._vertices[v].handle); @@ -1763,7 +1763,7 @@ get(ManagedTextureTag /*tag*/, ResourceGraph::vertex_descriptor v, ResourceGraph return g.managedTextures[handle.value]; } -inline IntrusivePtr& +inline PersistentBuffer& get(PersistentBufferTag /*tag*/, ResourceGraph::vertex_descriptor v, ResourceGraph& g) { auto& handle = ccstd::get< impl::ValueHandle>( @@ -1771,7 +1771,7 @@ get(PersistentBufferTag /*tag*/, ResourceGraph::vertex_descriptor v, ResourceGra return g.buffers[handle.value]; } -inline IntrusivePtr& +inline PersistentTexture& get(PersistentTextureTag /*tag*/, ResourceGraph::vertex_descriptor v, ResourceGraph& g) { auto& handle = ccstd::get< impl::ValueHandle>( @@ -1835,7 +1835,7 @@ get(ManagedTextureTag /*tag*/, ResourceGraph::vertex_descriptor v, const Resourc return g.managedTextures[handle.value]; } -inline const IntrusivePtr& +inline const PersistentBuffer& get(PersistentBufferTag /*tag*/, ResourceGraph::vertex_descriptor v, const ResourceGraph& g) { const auto& handle = ccstd::get< impl::ValueHandle>( @@ -1843,7 +1843,7 @@ get(PersistentBufferTag /*tag*/, ResourceGraph::vertex_descriptor v, const Resou return g.buffers[handle.value]; } -inline const IntrusivePtr& +inline const PersistentTexture& get(PersistentTextureTag /*tag*/, ResourceGraph::vertex_descriptor v, const ResourceGraph& g) { const auto& handle = ccstd::get< impl::ValueHandle>( @@ -1939,9 +1939,9 @@ get_if(ResourceGraph::vertex_descriptor v, ResourceGraph* pGraph } template <> -inline IntrusivePtr* -get_if>(ResourceGraph::vertex_descriptor v, ResourceGraph* pGraph) noexcept { // NOLINT - IntrusivePtr* ptr = nullptr; +inline PersistentBuffer* +get_if(ResourceGraph::vertex_descriptor v, ResourceGraph* pGraph) noexcept { // NOLINT + PersistentBuffer* ptr = nullptr; if (!pGraph) { return ptr; } @@ -1956,9 +1956,9 @@ get_if>(ResourceGraph::vertex_descriptor v, ResourceGr } template <> -inline IntrusivePtr* -get_if>(ResourceGraph::vertex_descriptor v, ResourceGraph* pGraph) noexcept { // NOLINT - IntrusivePtr* ptr = nullptr; +inline PersistentTexture* +get_if(ResourceGraph::vertex_descriptor v, ResourceGraph* pGraph) noexcept { // NOLINT + PersistentTexture* ptr = nullptr; if (!pGraph) { return ptr; } @@ -2096,9 +2096,9 @@ get_if(ResourceGraph::vertex_descriptor v, const ResourceGraph* } template <> -inline const IntrusivePtr* -get_if>(ResourceGraph::vertex_descriptor v, const ResourceGraph* pGraph) noexcept { // NOLINT - const IntrusivePtr* ptr = nullptr; +inline const PersistentBuffer* +get_if(ResourceGraph::vertex_descriptor v, const ResourceGraph* pGraph) noexcept { // NOLINT + const PersistentBuffer* ptr = nullptr; if (!pGraph) { return ptr; } @@ -2113,9 +2113,9 @@ get_if>(ResourceGraph::vertex_descriptor v, const Reso } template <> -inline const IntrusivePtr* -get_if>(ResourceGraph::vertex_descriptor v, const ResourceGraph* pGraph) noexcept { // NOLINT - const IntrusivePtr* ptr = nullptr; +inline const PersistentTexture* +get_if(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 void addVertexImpl( // NOLINT ValueT &&val, ResourceGraph &g, ResourceGraph::Vertex &vert, // NOLINT - std::enable_if_t, IntrusivePtr>::value>* dummy = nullptr) { // NOLINT + std::enable_if_t, PersistentBuffer>::value>* dummy = nullptr) { // NOLINT vert.handle = impl::ValueHandle{ gsl::narrow_cast(g.buffers.size())}; g.buffers.emplace_back(std::forward(val)); @@ -2441,7 +2441,7 @@ void addVertexImpl( // NOLINT template void addVertexImpl( // NOLINT ValueT &&val, ResourceGraph &g, ResourceGraph::Vertex &vert, // NOLINT - std::enable_if_t, IntrusivePtr>::value>* dummy = nullptr) { // NOLINT + std::enable_if_t, PersistentTexture>::value>* dummy = nullptr) { // NOLINT vert.handle = impl::ValueHandle{ gsl::narrow_cast(g.textures.size())}; g.textures.emplace_back(std::forward(val)); diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h index 2a6db6b7445..16efc9103a2 100644 --- a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h @@ -211,6 +211,15 @@ struct ManagedBuffer { uint64_t fenceValue{0}; }; +struct PersistentBuffer { + PersistentBuffer() = default; + PersistentBuffer(IntrusivePtr bufferIn) noexcept // NOLINT + : buffer(std::move(bufferIn)) {} + + IntrusivePtr buffer; + uint64_t fenceValue{0}; +}; + struct ManagedTexture { ManagedTexture() = default; ManagedTexture(IntrusivePtr textureIn) noexcept // NOLINT @@ -222,6 +231,17 @@ struct ManagedTexture { uint64_t fenceValue{0}; }; +struct PersistentTexture { + PersistentTexture() = default; + PersistentTexture(IntrusivePtr textureIn) noexcept // NOLINT + : texture(std::move(textureIn)) {} + + bool checkResource(const ResourceDesc &desc) const; + + IntrusivePtr texture; + uint64_t fenceValue{0}; +}; + struct ManagedResource { uint32_t unused{0}; }; @@ -638,8 +658,8 @@ struct ResourceGraph { // PolymorphicGraph using VertexTag = ccstd::variant; - using VertexValue = ccstd::variant*, IntrusivePtr*, IntrusivePtr*, RenderSwapchain*, FormatView*, SubresourceView*>; - using VertexConstValue = ccstd::variant*, const IntrusivePtr*, const IntrusivePtr*, const RenderSwapchain*, const FormatView*, const SubresourceView*>; + using VertexValue = ccstd::variant*, RenderSwapchain*, FormatView*, SubresourceView*>; + using VertexConstValue = ccstd::variant*, const RenderSwapchain*, const FormatView*, const SubresourceView*>; using VertexHandle = ccstd::variant< impl::ValueHandle, impl::ValueHandle, @@ -702,8 +722,8 @@ struct ResourceGraph { ccstd::pmr::vector resources; ccstd::pmr::vector managedBuffers; ccstd::pmr::vector managedTextures; - ccstd::pmr::vector> buffers; - ccstd::pmr::vector> textures; + ccstd::pmr::vector buffers; + ccstd::pmr::vector textures; ccstd::pmr::vector> framebuffers; ccstd::pmr::vector swapchains; ccstd::pmr::vector formatViews; diff --git a/native/cocos/renderer/pipeline/custom/RenderInterfaceFwd.h b/native/cocos/renderer/pipeline/custom/RenderInterfaceFwd.h index ee0505f07f2..8a6545cc0e1 100644 --- a/native/cocos/renderer/pipeline/custom/RenderInterfaceFwd.h +++ b/native/cocos/renderer/pipeline/custom/RenderInterfaceFwd.h @@ -44,6 +44,7 @@ enum class SubpassCapabilities : uint32_t; struct PipelineCapabilities; class RenderNode; class Setter; +class SceneBuilder; class RenderQueueBuilder; class BasicRenderPassBuilder; class BasicMultisampleRenderPassBuilder; diff --git a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h index 3e2078df625..3756b7c9672 100644 --- a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h @@ -460,10 +460,23 @@ class Setter : public RenderNode { 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::Camera *camera, const scene::DirectionalLight *light, uint32_t level) = 0; - virtual void setBuiltinSpotLightViewConstants(const scene::SpotLight *light) = 0; - void setBuiltinDirectionalLightViewConstants(const scene::Camera *camera, const scene::DirectionalLight *light) { - setBuiltinDirectionalLightViewConstants(camera, 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 light, uint32_t csmLevel, const scene::Camera *optCamera) = 0; + void useLightFrustum(IntrusivePtr light) { + useLightFrustum(std::move(light), 0, nullptr); + } + void useLightFrustum(IntrusivePtr light, uint32_t csmLevel) { + useLightFrustum(std::move(light), csmLevel, nullptr); } }; @@ -488,9 +501,7 @@ class RenderQueueBuilder : public Setter { * @param sceneFlags @en Rendering flags of the scene @zh 场景渲染标志位 */ virtual void addSceneOfCamera(scene::Camera *camera, LightInfo light, SceneFlags sceneFlags) = 0; - virtual Setter *addScene(const scene::Camera *camera, SceneFlags sceneFlags, const scene::Light *light) = 0; - virtual Setter *addSceneCulledByDirectionalLight(const scene::Camera *camera, SceneFlags sceneFlags, scene::DirectionalLight *light, uint32_t level) = 0; - virtual Setter *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,7 +539,7 @@ class RenderQueueBuilder : public Setter { void addSceneOfCamera(scene::Camera *camera, LightInfo light) { addSceneOfCamera(camera, std::move(light), SceneFlags::NONE); } - Setter *addScene(const scene::Camera *camera, SceneFlags sceneFlags) { + SceneBuilder *addScene(const scene::Camera *camera, SceneFlags sceneFlags) { return addScene(camera, sceneFlags, nullptr); } void addFullscreenQuad(Material *material, uint32_t passID) { diff --git a/native/tools/swig-config/render.i b/native/tools/swig-config/render.i index 044b59f10e7..877b83049fe 100644 --- a/native/tools/swig-config/render.i +++ b/native/tools/swig-config/render.i @@ -82,8 +82,6 @@ using namespace cc::render; %release_returned_cpp_object_in_gc(cc::render::RenderPassBuilder::addComputeSubpass); %release_returned_cpp_object_in_gc(cc::render::ComputePassBuilder::addQueue); %release_returned_cpp_object_in_gc(cc::render::RenderQueueBuilder::addScene); -%release_returned_cpp_object_in_gc(cc::render::RenderQueueBuilder::addSceneCulledByDirectionalLight); -%release_returned_cpp_object_in_gc(cc::render::RenderQueueBuilder::addSceneCulledBySpotLight); %release_returned_cpp_object_in_gc(cc::render::Pipeline::addRenderPass); %release_returned_cpp_object_in_gc(cc::render::Pipeline::addComputePass); diff --git a/package-lock.json b/package-lock.json index e1185a3f10c..a892eef22fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cocos-creator", - "version": "3.8.1", + "version": "3.8.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cocos-creator", - "version": "3.8.1", + "version": "3.8.2", "hasInstallScript": true, "license": "MIT", "dependencies": {