From efd2ec5e23395ace372b83366fdd2ad3cd5a595e Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Mon, 28 Apr 2025 12:04:25 +0800 Subject: [PATCH] Adjust the rendering logic of the UI and profiler (#18676) --- cocos/rendering/custom/executor.ts | 63 ++++++++++--------- cocos/rendering/custom/web-pipeline.ts | 83 +++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 29 deletions(-) diff --git a/cocos/rendering/custom/executor.ts b/cocos/rendering/custom/executor.ts index a4597ca5b6..327545260d 100644 --- a/cocos/rendering/custom/executor.ts +++ b/cocos/rendering/custom/executor.ts @@ -85,6 +85,7 @@ import { DescriptorSetData, LayoutGraphData, LayoutGraphDataValue, PipelineLayou import { BasicPipeline } from './pipeline'; import { Blit, + BlitType, ClearView, ComputePass, ComputeSubpass, @@ -889,25 +890,6 @@ class DeviceRenderPass implements RecordingInterface { } } - protected _showProfiler (rect: Rect): void { - const profiler = context.pipeline.profiler!; - if (!profiler || !profiler.enabled) { - return; - } - const profilerDesc = context.profilerDescriptorSet; - const renderPass = this._renderPass; - const cmdBuff = context.commandBuffer; - const submodel = profiler.subModels[0]; - const pass = submodel.passes[0]; - const ia = submodel.inputAssembler; - profilerViewport.width = rect.width; - profilerViewport.height = rect.height; - cmdBuff.setViewport(profilerViewport); - cmdBuff.setScissor(rect); - cmdBuff.bindDescriptorSet(SetIndex.GLOBAL, profilerDesc); - recordCommand(cmdBuff, renderPass, pass, submodel.descriptorSet, submodel.shaders[0], ia); - } - beginPass (): void { const tex = this.framebuffer.colorTextures[0]!; this._applyViewport(tex); @@ -949,9 +931,6 @@ class DeviceRenderPass implements RecordingInterface { for (const queue of this._deviceQueues.values()) { queue.record(); } - if (this._rasterPass.showStatistics) { - this._showProfiler(renderPassArea); - } this.endPass(); } @@ -1155,7 +1134,7 @@ class DeviceRenderScene implements RecordingInterface { get sceneID (): number { return this._sceneID; } get camera (): Camera | null { return this._camera; } preRecord (): void { - if (this._blit) { + if (this._blit && this._blit.blitType === BlitType.FULLSCREEN_QUAD) { this._currentQueue.createBlitDesc(this._blit); this._currentQueue.blitDesc!.update(); } @@ -1171,7 +1150,7 @@ class DeviceRenderScene implements RecordingInterface { this._blit = blit; this._sceneID = sceneID; this._renderPass = queue.devicePass.renderPass; - const camera = scene && scene.camera ? scene.camera : null; + const camera = scene && scene.camera ? scene.camera : blit && blit.camera ? blit.camera : null; if (camera) { this._scene = camera.scene; this._camera = camera; @@ -1201,6 +1180,25 @@ class DeviceRenderScene implements RecordingInterface { } } + protected _showProfiler (): void { + const rect = renderPassArea; + const profiler = context.pipeline.profiler!; + if (!profiler || !profiler.enabled) { + return; + } + const profilerDesc = context.profilerDescriptorSet; + const renderPass = this._renderPass; + const cmdBuff = context.commandBuffer; + const submodel = profiler.subModels[0]; + const pass = submodel.passes[0]; + const ia = submodel.inputAssembler; + profilerViewport.width = rect.width; + profilerViewport.height = rect.height; + cmdBuff.setViewport(profilerViewport); + cmdBuff.setScissor(rect); + cmdBuff.bindDescriptorSet(SetIndex.GLOBAL, profilerDesc); + recordCommand(cmdBuff, renderPass, pass, submodel.descriptorSet, submodel.shaders[0], ia); + } private _recordBlit (): void { if (!this.blit) { return; } @@ -1270,7 +1268,19 @@ class DeviceRenderScene implements RecordingInterface { // Currently processing blit and camera first if (this.blit) { - this._recordBlit(); + switch (this.blit.blitType) { + case BlitType.FULLSCREEN_QUAD: + this._recordBlit(); + break; + case BlitType.DRAW_2D: + this._recordUI(); + break; + case BlitType.DRAW_PROFILE: + this._showProfiler(); + break; + default: + break; + } return; } const rqQuery = sceneCulling.renderQueueQueryIndex.get(this.sceneID)!; @@ -1287,9 +1297,6 @@ class DeviceRenderScene implements RecordingInterface { context.pipeline.pipelineSceneData, ); } - if (graphSceneData.flags & SceneFlags.UI) { - this._recordUI(); - } } } diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index 639872c468..c1a700228e 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -28,7 +28,7 @@ import { DEBUG, EDITOR } from 'internal:constants'; import { DescriptorSetLayout, Device, Feature, Format, FormatFeatureBit, Sampler, Swapchain, Texture, ClearFlagBit, DescriptorSet, deviceManager, Viewport, API, CommandBuffer, Type, SamplerInfo, Filter, Address, DescriptorSetInfo, LoadOp, StoreOp, ShaderStageFlagBit, BufferInfo, TextureInfo, TextureType, ResolveMode, SampleCount, Color, ComparisonFunc, Buffer } from '../../gfx'; import { Vec4, macro, cclegacy, RecyclePool, Mat4, Quat, Vec2 } from '../../core'; import { AccessType, AttachmentType, CopyPair, LightInfo, LightingMode, MovePair, QueueHint, RenderCommonObjectPool, ResolvePair, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UpdateFrequency, UploadPair } from './types'; -import { ComputePass, CopyPass, MovePass, RasterPass, RasterSubpass, RenderData, RenderGraph, RenderGraphComponent, RenderGraphValue, RenderQueue, RenderSwapchain, ResourceDesc, ResourceGraph, ResourceGraphValue, ResourceStates, ResourceTraits, SceneData, Subpass, PersistentBuffer, RenderGraphObjectPool, CullingFlags, ManagedResource, ManagedBuffer } from './render-graph'; +import { ComputePass, CopyPass, MovePass, RasterPass, RasterSubpass, RenderData, RenderGraph, RenderGraphComponent, RenderGraphValue, RenderQueue, RenderSwapchain, ResourceDesc, ResourceGraph, ResourceGraphValue, ResourceStates, ResourceTraits, SceneData, Subpass, PersistentBuffer, RenderGraphObjectPool, CullingFlags, ManagedResource, ManagedBuffer, BlitType } from './render-graph'; import { ComputePassBuilder, ComputeQueueBuilder, BasicPipeline, RenderQueueBuilder, RenderSubpassBuilder, PipelineType, BasicRenderPassBuilder, PipelineCapabilities, BasicMultisampleRenderPassBuilder, Setter, SceneBuilder } from './pipeline'; import { PipelineSceneData } from '../pipeline-scene-data'; import { Model, Camera, PCFType, ProbeType, DirectionalLight, PointLight, RangedDirectionalLight, SphereLight, SpotLight } from '../../render-scene/scene'; @@ -179,6 +179,8 @@ function getResourceDimension (type: TextureType): ResourceDimension { return ResourceDimension.TEXTURE2D; } +const emptyMaterial = new Material(); +const emptyRenderData = new RenderData(); export class WebSceneBuilder extends WebSetter implements SceneBuilder { constructor ( data: RenderData, @@ -299,6 +301,85 @@ export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuild if (light && light.type !== LightType.DIRECTIONAL) setShadowUBOLightView(this, camera, light, 0, layoutName); else if (!(sceneFlags & SceneFlags.SHADOW_CASTER)) setShadowUBOView(this, camera, layoutName); } + const passOrSubpassId = this._renderGraph.getParent(this._vertID); + if (sceneFlags & SceneFlags.UI) { + const passLayoutId = this._lg.locateChild( + this._lg.N, + 'default', + ); + const phaseLayoutId = this._lg.locateChild( + passLayoutId, + 'default', + ); + const queueId = this._renderGraph.addVertex( + RenderGraphValue.Queue, + this._queue, + 'UI Queue', + 'default', + this._data, + !DEBUG, + passOrSubpassId, + ); + + this._renderGraph.addVertex( + RenderGraphValue.Blit, + renderGraphPool.createBlit(emptyMaterial, this._renderGraph.N, SceneFlags.NONE, camera, BlitType.DRAW_2D), + 'UI', + '', + emptyRenderData, + !DEBUG, + queueId, + ); + } + if (sceneFlags & SceneFlags.PROFILER) { + let showStatistics = false; + const N = this._renderGraph.N; + if (passOrSubpassId !== N) { + const passOrNullId = this._renderGraph.getParent(passOrSubpassId); + const passId = passOrNullId === N + ? passOrSubpassId + : passOrNullId; + + if ( + passId !== N + && this._renderGraph.h(RenderGraphValue.RasterPass, passId) + ) { + const pass = this._renderGraph.value(RenderGraphValue.RasterPass, passId); + showStatistics = pass.showStatistics; + } + } + if (showStatistics) { + const passLayoutId = this._lg.locateChild( + this._lg.N, + 'default', + ); + const phaseLayoutId = this._lg.locateChild( + passLayoutId, + 'default', + ); + const queueId = this._renderGraph.addVertex( + RenderGraphValue.Queue, + this._queue, + 'UI Queue', + 'default', + this._data, + !DEBUG, + passOrSubpassId, + ); + this._renderGraph.addVertex( + RenderGraphValue.Blit, + renderGraphPool.createBlit(emptyMaterial, this._renderGraph.N, SceneFlags.NONE, camera, BlitType.DRAW_PROFILE), + 'Profiler', + '', + emptyRenderData, + !DEBUG, + queueId, + ); + + const data = renderData; + WebSetter.setMat4(this._lg, data, 'cc_matProj', camera.matProj); + } + } const sceneBuilder = pipelinePool.sceneBuilder.add(); sceneBuilder.update(renderData, this._lg, this._renderGraph, sceneId, sceneData); return sceneBuilder;