Skip to content

Commit

Permalink
addScene simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e committed Sep 12, 2023
1 parent 3a24a36 commit 7bb1c99
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 213 deletions.
40 changes: 19 additions & 21 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 | 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.
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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 渲染全屏四边形
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -817,7 +815,7 @@ export interface BasicPipeline extends PipelineRuntime {
/**
* @engineInternal
*/
getDescriptorSetLayout (shaderName: string, freq: UpdateFrequency): DescriptorSetLayout | null;
getDescriptorSetLayout (shaderName: string, freq: UpdateFrequency): DescriptorSetLayout | undefined;
}

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
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 | null): ProgramProxy | null;
key?: string): ProgramProxy | undefined;
getBlockSizes (phaseID: number, programName: string): number[];
getHandleMap (phaseID: number, programName: string): Record<string, number>;
getProgramID (phaseID: number, programName: string): number;
Expand Down
40 changes: 35 additions & 5 deletions cocos/rendering/custom/render-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2582,7 +2592,9 @@ export class RenderGraphObjectPool {
this._renderSwapchain = new RecyclePool<RenderSwapchain>(() => new RenderSwapchain(), settings.renderSwapchainBatchSize);
this._resourceStates = new RecyclePool<ResourceStates>(() => new ResourceStates(), settings.resourceStatesBatchSize);
this._managedBuffer = new RecyclePool<ManagedBuffer>(() => new ManagedBuffer(), settings.managedBufferBatchSize);
this._persistentBuffer = new RecyclePool<PersistentBuffer>(() => new PersistentBuffer(), settings.persistentBufferBatchSize);
this._managedTexture = new RecyclePool<ManagedTexture>(() => new ManagedTexture(), settings.managedTextureBatchSize);
this._persistentTexture = new RecyclePool<PersistentTexture>(() => new PersistentTexture(), settings.persistentTextureBatchSize);
this._managedResource = new RecyclePool<ManagedResource>(() => new ManagedResource(), settings.managedResourceBatchSize);
this._subpass = new RecyclePool<Subpass>(() => new Subpass(), settings.subpassBatchSize);
this._subpassGraph = new RecyclePool<SubpassGraph>(() => new SubpassGraph(), settings.subpassGraphBatchSize);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -2704,13 +2718,27 @@ 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 {
const v = this._managedTexture.add();
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();
Expand Down Expand Up @@ -2861,7 +2889,9 @@ export class RenderGraphObjectPool {
private readonly _renderSwapchain: RecyclePool<RenderSwapchain>;
private readonly _resourceStates: RecyclePool<ResourceStates>;
private readonly _managedBuffer: RecyclePool<ManagedBuffer>;
private readonly _persistentBuffer: RecyclePool<PersistentBuffer>;
private readonly _managedTexture: RecyclePool<ManagedTexture>;
private readonly _persistentTexture: RecyclePool<PersistentTexture>;
private readonly _managedResource: RecyclePool<ManagedResource>;
private readonly _subpass: RecyclePool<Subpass>;
private readonly _subpassGraph: RecyclePool<SubpassGraph>;
Expand Down
1 change: 1 addition & 0 deletions cocos/rendering/custom/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export enum SceneFlags {
DRAW_NON_INSTANCING = 0x1000,
REFLECTION_PROBE = 0x2000,
GPU_DRIVEN = 0x4000,
NON_BUILTIN = 0x8000,
ALL = 0xFFFFFFFF,
}

Expand Down
91 changes: 65 additions & 26 deletions cocos/rendering/custom/web-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -327,7 +327,7 @@ function setShadowUBOLightView (
setter: WebSetter,
camera: Camera,
light: Light,
level: number,
csmLevel: number,
layout = 'default',
): void {
const director = cclegacy.director;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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>(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>(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>(RenderGraphValue.Scene, sceneData, 'Scene', '', renderData, false, this._vertID);
return new WebSetter(renderData, this._lg);
const sceneId = this._renderGraph.addVertex<RenderGraphValue.Scene>(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<RenderGraphValue.Blit>(
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 7bb1c99

Please sign in to comment.