From 56038db50a7cbceeda544ab26abddcc558347e2f Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Thu, 16 Sep 2021 10:28:27 +0800 Subject: [PATCH] gfx: states store hashes (#9325) * gfx: states store hashes * profiler uses fixed viewport --- cocos/core/gfx/base/define.ts | 31 ++++++++++++----- cocos/core/gfx/base/states/global-barrier.ts | 5 ++- cocos/core/gfx/base/states/sampler.ts | 5 ++- cocos/core/gfx/base/states/texture-barrier.ts | 5 ++- cocos/core/gfx/empty/empty-device.ts | 6 ++-- cocos/core/gfx/webgl/states/webgl-sampler.ts | 4 +-- cocos/core/gfx/webgl/webgl-commands.ts | 30 ---------------- cocos/core/gfx/webgl/webgl-device.ts | 6 ++-- .../gfx/webgl/webgl-primary-command-buffer.ts | 34 ++++++++++++++++++- .../core/gfx/webgl2/states/webgl2-sampler.ts | 4 +-- cocos/core/gfx/webgl2/webgl2-commands.ts | 30 ---------------- cocos/core/gfx/webgl2/webgl2-device.ts | 6 ++-- .../webgl2/webgl2-primary-command-buffer.ts | 34 ++++++++++++++++++- .../pipeline/deferred/postprocess-stage.ts | 4 ++- cocos/core/pipeline/forward/forward-stage.ts | 3 +- cocos/core/pipeline/forward/ui-phase.ts | 11 ------ cocos/core/pipeline/pipeline-funcs.ts | 24 +++++++++++++ cocos/core/pipeline/pipeline-state-manager.ts | 2 +- .../editor/terrain-select-brush.effect.meta | 2 +- 19 files changed, 144 insertions(+), 102 deletions(-) diff --git a/cocos/core/gfx/base/define.ts b/cocos/core/gfx/base/define.ts index e234591455..29edba2d02 100644 --- a/cocos/core/gfx/base/define.ts +++ b/cocos/core/gfx/base/define.ts @@ -121,6 +121,21 @@ export enum Feature { MULTIPLE_RENDER_TARGETS, BLEND_MINMAX, COMPUTE_SHADER, + // This flag indicates whether the device can benefit from subpass-style usages. + // Specifically, this only differs on the GLES backends: the Framebuffer Fetch + // extension is used to simulate input attachments, so the flag is not set when + // the extension is not supported, and you should switch to the fallback branch + // (without the extension requirement) in GLSL shader sources accordingly. + // Everything else can remain the same. + // + // Another caveat when using the Framebuffer Fetch extensions in shaders is that + // for subpasses with exactly 4 inout attachments the output is automatically set + // to the last attachment (taking advantage of 'inout' property), and a separate + // blit operation (if needed) will be added for you afterwards to transfer the + // rendering result to the corrent subpass output texture. This is to ameliorate + // the max number of attachment limit(4) situation for many devices, and shader + // sources inside this kind of subpass must match this behavior. + INPUT_ATTACHMENT_BENEFIT, COUNT, } @@ -608,14 +623,12 @@ export enum CullMode { export enum DynamicStateFlagBit { NONE = 0x0, - VIEWPORT = 0x1, - SCISSOR = 0x2, - LINE_WIDTH = 0x4, - DEPTH_BIAS = 0x8, - BLEND_CONSTANTS = 0x10, - DEPTH_BOUNDS = 0x20, - STENCIL_WRITE_MASK = 0x40, - STENCIL_COMPARE_MASK = 0x80, + LINE_WIDTH = 0x1, + DEPTH_BIAS = 0x2, + BLEND_CONSTANTS = 0x4, + DEPTH_BOUNDS = 0x8, + STENCIL_WRITE_MASK = 0x10, + STENCIL_COMPARE_MASK = 0x20, } export enum StencilFace { @@ -955,7 +968,7 @@ export class SwapchainInfo { constructor ( public windowHandle: HTMLCanvasElement = null!, - public vsyncMode: VsyncMode = VsyncMode.RELAXED, + public vsyncMode: VsyncMode = VsyncMode.ON, public width: number = 0, public height: number = 0, ) {} diff --git a/cocos/core/gfx/base/states/global-barrier.ts b/cocos/core/gfx/base/states/global-barrier.ts index 9f4566b962..34f695a76c 100644 --- a/cocos/core/gfx/base/states/global-barrier.ts +++ b/cocos/core/gfx/base/states/global-barrier.ts @@ -37,12 +37,15 @@ import { GFXObject, ObjectType, GlobalBarrierInfo } from '../define'; */ export class GlobalBarrier extends GFXObject { get info (): Readonly { return this._info; } + get hash (): number { return this._hash; } protected _info: GlobalBarrierInfo = new GlobalBarrierInfo(); + protected _hash = 0; - constructor (info: GlobalBarrierInfo) { + constructor (info: GlobalBarrierInfo, hash: number) { super(ObjectType.GLOBAL_BARRIER); this._info.copy(info); + this._hash = hash; } static computeHash (info: GlobalBarrierInfo) { diff --git a/cocos/core/gfx/base/states/sampler.ts b/cocos/core/gfx/base/states/sampler.ts index faa2753ab3..0888c51a7d 100644 --- a/cocos/core/gfx/base/states/sampler.ts +++ b/cocos/core/gfx/base/states/sampler.ts @@ -36,12 +36,15 @@ import { GFXObject, ObjectType, SamplerInfo } from '../define'; */ export class Sampler extends GFXObject { get info (): Readonly { return this._info; } + get hash (): number { return this._hash; } protected _info: SamplerInfo = new SamplerInfo(); + protected _hash = 0; - constructor (info: SamplerInfo) { + constructor (info: SamplerInfo, hash: number) { super(ObjectType.SAMPLER); this._info.copy(info); + this._hash = hash; } static computeHash (info: SamplerInfo) { diff --git a/cocos/core/gfx/base/states/texture-barrier.ts b/cocos/core/gfx/base/states/texture-barrier.ts index 4b0afc6a43..959942dcc3 100644 --- a/cocos/core/gfx/base/states/texture-barrier.ts +++ b/cocos/core/gfx/base/states/texture-barrier.ts @@ -37,12 +37,15 @@ import { GFXObject, ObjectType, TextureBarrierInfo } from '../define'; */ export class TextureBarrier extends GFXObject { get info (): Readonly { return this._info; } + get hash (): number { return this._hash; } protected _info: TextureBarrierInfo = new TextureBarrierInfo(); + protected _hash = 0; - constructor (info: TextureBarrierInfo) { + constructor (info: TextureBarrierInfo, hash: number) { super(ObjectType.TEXTURE_BARRIER); this._info.copy(info); + this._hash = hash; } static computeHash (info: TextureBarrierInfo) { diff --git a/cocos/core/gfx/empty/empty-device.ts b/cocos/core/gfx/empty/empty-device.ts index 7817562aea..1139a8803c 100644 --- a/cocos/core/gfx/empty/empty-device.ts +++ b/cocos/core/gfx/empty/empty-device.ts @@ -174,7 +174,7 @@ export class EmptyDevice extends Device { public getSampler (info: SamplerInfo): Sampler { const hash = Sampler.computeHash(info); if (!this._samplers.has(hash)) { - this._samplers.set(hash, new Sampler(info)); + this._samplers.set(hash, new Sampler(info, hash)); } return this._samplers.get(hash)!; } @@ -182,7 +182,7 @@ export class EmptyDevice extends Device { public getGlobalBarrier (info: GlobalBarrierInfo) { const hash = GlobalBarrier.computeHash(info); if (!this._globalBarriers.has(hash)) { - this._globalBarriers.set(hash, new GlobalBarrier(info)); + this._globalBarriers.set(hash, new GlobalBarrier(info, hash)); } return this._globalBarriers.get(hash)!; } @@ -190,7 +190,7 @@ export class EmptyDevice extends Device { public getTextureBarrier (info: TextureBarrierInfo) { const hash = TextureBarrier.computeHash(info); if (!this._textureBarriers.has(hash)) { - this._textureBarriers.set(hash, new TextureBarrier(info)); + this._textureBarriers.set(hash, new TextureBarrier(info, hash)); } return this._textureBarriers.get(hash)!; } diff --git a/cocos/core/gfx/webgl/states/webgl-sampler.ts b/cocos/core/gfx/webgl/states/webgl-sampler.ts index ae51b79d4b..0c4dc153f2 100644 --- a/cocos/core/gfx/webgl/states/webgl-sampler.ts +++ b/cocos/core/gfx/webgl/states/webgl-sampler.ts @@ -41,8 +41,8 @@ export class WebGLSampler extends Sampler { private _gpuSampler: IWebGLGPUSampler | null = null; - constructor (info: SamplerInfo) { - super(info); + constructor (info: SamplerInfo, hash: number) { + super(info, hash); let glMinFilter = 0; let glMagFilter = 0; diff --git a/cocos/core/gfx/webgl/webgl-commands.ts b/cocos/core/gfx/webgl/webgl-commands.ts index fb1c05ce19..bf59cf8671 100644 --- a/cocos/core/gfx/webgl/webgl-commands.ts +++ b/cocos/core/gfx/webgl/webgl-commands.ts @@ -2384,36 +2384,6 @@ export function WebGLCmdFuncBindStates ( for (let j = 0; j < dsLen; j++) { const dynamicState = gpuPipelineState.dynamicStates[j]; switch (dynamicState) { - case DynamicStateFlagBit.VIEWPORT: { - const viewport = dynamicStates.viewport; - if (cache.viewport.left !== viewport.left - || cache.viewport.top !== viewport.top - || cache.viewport.width !== viewport.width - || cache.viewport.height !== viewport.height) { - gl.viewport(viewport.left, viewport.top, viewport.width, viewport.height); - - cache.viewport.left = viewport.left; - cache.viewport.top = viewport.top; - cache.viewport.width = viewport.width; - cache.viewport.height = viewport.height; - } - break; - } - case DynamicStateFlagBit.SCISSOR: { - const scissor = dynamicStates.scissor; - if (cache.scissorRect.x !== scissor.x - || cache.scissorRect.y !== scissor.y - || cache.scissorRect.width !== scissor.width - || cache.scissorRect.height !== scissor.height) { - gl.scissor(scissor.x, scissor.y, scissor.width, scissor.height); - - cache.scissorRect.x = scissor.x; - cache.scissorRect.y = scissor.y; - cache.scissorRect.width = scissor.width; - cache.scissorRect.height = scissor.height; - } - break; - } case DynamicStateFlagBit.LINE_WIDTH: { if (cache.rs.lineWidth !== dynamicStates.lineWidth) { gl.lineWidth(dynamicStates.lineWidth); diff --git a/cocos/core/gfx/webgl/webgl-device.ts b/cocos/core/gfx/webgl/webgl-device.ts index 1f6c937870..de9876742c 100644 --- a/cocos/core/gfx/webgl/webgl-device.ts +++ b/cocos/core/gfx/webgl/webgl-device.ts @@ -334,7 +334,7 @@ export class WebGLDevice extends Device { public getSampler (info: SamplerInfo): Sampler { const hash = Sampler.computeHash(info); if (!this._samplers.has(hash)) { - this._samplers.set(hash, new WebGLSampler(info)); + this._samplers.set(hash, new WebGLSampler(info, hash)); } return this._samplers.get(hash)!; } @@ -342,7 +342,7 @@ export class WebGLDevice extends Device { public getGlobalBarrier (info: GlobalBarrierInfo) { const hash = GlobalBarrier.computeHash(info); if (!this._globalBarriers.has(hash)) { - this._globalBarriers.set(hash, new GlobalBarrier(info)); + this._globalBarriers.set(hash, new GlobalBarrier(info, hash)); } return this._globalBarriers.get(hash)!; } @@ -350,7 +350,7 @@ export class WebGLDevice extends Device { public getTextureBarrier (info: TextureBarrierInfo) { const hash = TextureBarrier.computeHash(info); if (!this._textureBarriers.has(hash)) { - this._textureBarriers.set(hash, new TextureBarrier(info)); + this._textureBarriers.set(hash, new TextureBarrier(info, hash)); } return this._textureBarriers.get(hash)!; } diff --git a/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts b/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts index e0982ab407..d707adcaf4 100644 --- a/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts +++ b/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts @@ -25,7 +25,7 @@ import { Buffer } from '../base/buffer'; import { CommandBuffer } from '../base/command-buffer'; -import { BufferSource, DrawInfo, BufferTextureCopy, Color, Rect, BufferUsageBit } from '../base/define'; +import { BufferSource, DrawInfo, BufferTextureCopy, Color, Rect, BufferUsageBit, Viewport } from '../base/define'; import { Framebuffer } from '../base/framebuffer'; import { InputAssembler } from '../base/input-assembler'; import { Texture } from '../base/texture'; @@ -91,6 +91,38 @@ export class WebGLPrimaryCommandBuffer extends WebGLCommandBuffer { } } + public setViewport (viewport: Viewport) { + const { stateCache: cache, gl } = WebGLDeviceManager.instance; + + if (cache.viewport.left !== viewport.left + || cache.viewport.top !== viewport.top + || cache.viewport.width !== viewport.width + || cache.viewport.height !== viewport.height) { + gl.viewport(viewport.left, viewport.top, viewport.width, viewport.height); + + cache.viewport.left = viewport.left; + cache.viewport.top = viewport.top; + cache.viewport.width = viewport.width; + cache.viewport.height = viewport.height; + } + } + + public setScissor (scissor: Rect) { + const { stateCache: cache, gl } = WebGLDeviceManager.instance; + + if (cache.scissorRect.x !== scissor.x + || cache.scissorRect.y !== scissor.y + || cache.scissorRect.width !== scissor.width + || cache.scissorRect.height !== scissor.height) { + gl.scissor(scissor.x, scissor.y, scissor.width, scissor.height); + + cache.scissorRect.x = scissor.x; + cache.scissorRect.y = scissor.y; + cache.scissorRect.width = scissor.width; + cache.scissorRect.height = scissor.height; + } + } + public updateBuffer (buffer: Buffer, data: BufferSource, size?: number) { if (!this._isInRenderPass) { const gpuBuffer = (buffer as WebGLBuffer).gpuBuffer; diff --git a/cocos/core/gfx/webgl2/states/webgl2-sampler.ts b/cocos/core/gfx/webgl2/states/webgl2-sampler.ts index 079411b672..c3d5e348e8 100644 --- a/cocos/core/gfx/webgl2/states/webgl2-sampler.ts +++ b/cocos/core/gfx/webgl2/states/webgl2-sampler.ts @@ -36,8 +36,8 @@ export class WebGL2Sampler extends Sampler { private _gpuSampler: IWebGL2GPUSampler | null = null; - constructor (info: SamplerInfo) { - super(info); + constructor (info: SamplerInfo, hash: number) { + super(info, hash); this._gpuSampler = { glSampler: null, diff --git a/cocos/core/gfx/webgl2/webgl2-commands.ts b/cocos/core/gfx/webgl2/webgl2-commands.ts index aa934afff9..bf8674a22e 100644 --- a/cocos/core/gfx/webgl2/webgl2-commands.ts +++ b/cocos/core/gfx/webgl2/webgl2-commands.ts @@ -2347,36 +2347,6 @@ export function WebGL2CmdFuncBindStates ( for (let k = 0; k < dsLen; k++) { const dynamicState = gpuPipelineState.dynamicStates[k]; switch (dynamicState) { - case DynamicStateFlagBit.VIEWPORT: { - const viewport = dynamicStates.viewport; - if (cache.viewport.left !== viewport.left - || cache.viewport.top !== viewport.top - || cache.viewport.width !== viewport.width - || cache.viewport.height !== viewport.height) { - gl.viewport(viewport.left, viewport.top, viewport.width, viewport.height); - - cache.viewport.left = viewport.left; - cache.viewport.top = viewport.top; - cache.viewport.width = viewport.width; - cache.viewport.height = viewport.height; - } - break; - } - case DynamicStateFlagBit.SCISSOR: { - const scissor = dynamicStates.scissor; - if (cache.scissorRect.x !== scissor.x - || cache.scissorRect.y !== scissor.y - || cache.scissorRect.width !== scissor.width - || cache.scissorRect.height !== scissor.height) { - gl.scissor(scissor.x, scissor.y, scissor.width, scissor.height); - - cache.scissorRect.x = scissor.x; - cache.scissorRect.y = scissor.y; - cache.scissorRect.width = scissor.width; - cache.scissorRect.height = scissor.height; - } - break; - } case DynamicStateFlagBit.LINE_WIDTH: { if (cache.rs.lineWidth !== dynamicStates.lineWidth) { gl.lineWidth(dynamicStates.lineWidth); diff --git a/cocos/core/gfx/webgl2/webgl2-device.ts b/cocos/core/gfx/webgl2/webgl2-device.ts index 97713d9f15..3189caf66c 100644 --- a/cocos/core/gfx/webgl2/webgl2-device.ts +++ b/cocos/core/gfx/webgl2/webgl2-device.ts @@ -322,7 +322,7 @@ export class WebGL2Device extends Device { public getSampler (info: SamplerInfo): Sampler { const hash = Sampler.computeHash(info); if (!this._samplers.has(hash)) { - this._samplers.set(hash, new WebGL2Sampler(info)); + this._samplers.set(hash, new WebGL2Sampler(info, hash)); } return this._samplers.get(hash)!; } @@ -330,7 +330,7 @@ export class WebGL2Device extends Device { public getGlobalBarrier (info: GlobalBarrierInfo) { const hash = GlobalBarrier.computeHash(info); if (!this._globalBarriers.has(hash)) { - this._globalBarriers.set(hash, new GlobalBarrier(info)); + this._globalBarriers.set(hash, new GlobalBarrier(info, hash)); } return this._globalBarriers.get(hash)!; } @@ -338,7 +338,7 @@ export class WebGL2Device extends Device { public getTextureBarrier (info: TextureBarrierInfo) { const hash = TextureBarrier.computeHash(info); if (!this._textureBarriers.has(hash)) { - this._textureBarriers.set(hash, new TextureBarrier(info)); + this._textureBarriers.set(hash, new TextureBarrier(info, hash)); } return this._textureBarriers.get(hash)!; } diff --git a/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts b/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts index 29aebe5d65..aa4903f40f 100644 --- a/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts +++ b/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts @@ -25,7 +25,7 @@ import { Buffer } from '../base/buffer'; import { CommandBuffer } from '../base/command-buffer'; -import { BufferUsageBit, BufferTextureCopy, Color, Rect, BufferSource, DrawInfo } from '../base/define'; +import { BufferUsageBit, BufferTextureCopy, Color, Rect, BufferSource, DrawInfo, Viewport } from '../base/define'; import { Framebuffer } from '../base/framebuffer'; import { InputAssembler } from '../base/input-assembler'; import { Texture } from '../base/texture'; @@ -91,6 +91,38 @@ export class WebGL2PrimaryCommandBuffer extends WebGL2CommandBuffer { } } + public setViewport (viewport: Viewport) { + const { stateCache: cache, gl } = WebGL2DeviceManager.instance; + + if (cache.viewport.left !== viewport.left + || cache.viewport.top !== viewport.top + || cache.viewport.width !== viewport.width + || cache.viewport.height !== viewport.height) { + gl.viewport(viewport.left, viewport.top, viewport.width, viewport.height); + + cache.viewport.left = viewport.left; + cache.viewport.top = viewport.top; + cache.viewport.width = viewport.width; + cache.viewport.height = viewport.height; + } + } + + public setScissor (scissor: Rect) { + const { stateCache: cache, gl } = WebGL2DeviceManager.instance; + + if (cache.scissorRect.x !== scissor.x + || cache.scissorRect.y !== scissor.y + || cache.scissorRect.width !== scissor.width + || cache.scissorRect.height !== scissor.height) { + gl.scissor(scissor.x, scissor.y, scissor.width, scissor.height); + + cache.scissorRect.x = scissor.x; + cache.scissorRect.y = scissor.y; + cache.scissorRect.width = scissor.width; + cache.scissorRect.height = scissor.height; + } + } + public updateBuffer (buffer: Buffer, data: BufferSource, size?: number) { if (!this._isInRenderPass) { const gpuBuffer = (buffer as WebGL2Buffer).gpuBuffer; diff --git a/cocos/core/pipeline/deferred/postprocess-stage.ts b/cocos/core/pipeline/deferred/postprocess-stage.ts index 2725e03149..019cc36199 100644 --- a/cocos/core/pipeline/deferred/postprocess-stage.ts +++ b/cocos/core/pipeline/deferred/postprocess-stage.ts @@ -40,6 +40,7 @@ import { UIPhase } from '../forward/ui-phase'; import { MainFlow } from './main-flow'; import { RenderQueueDesc } from '../pipeline-serialization'; import { DeferredPipelineSceneData } from './deferred-pipeline-scene-data'; +import { renderProfiler } from '../pipeline-funcs'; const colors: Color[] = [new Color(0, 0, 0, 1)]; @@ -131,7 +132,7 @@ export class PostprocessStage extends RenderStage { cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, pass.descriptorSet); const inputAssembler = camera.window!.swapchain ? pipeline.quadIAOnscreen : pipeline.quadIAOffscreen; - let pso:PipelineState|null = null; + let pso: PipelineState | null = null; if (pass != null && shader != null && inputAssembler != null) { pso = PipelineStateManager.getOrCreatePipelineState(device, pass, shader, renderPass, inputAssembler); } @@ -144,6 +145,7 @@ export class PostprocessStage extends RenderStage { } this._uiPhase.render(camera, renderPass); + renderProfiler(device, renderPass, cmdBuff, pipeline.profiler, swapchain); cmdBuff.endRenderPass(); } diff --git a/cocos/core/pipeline/forward/forward-stage.ts b/cocos/core/pipeline/forward/forward-stage.ts index a3232443de..088c8e0954 100644 --- a/cocos/core/pipeline/forward/forward-stage.ts +++ b/cocos/core/pipeline/forward/forward-stage.ts @@ -33,7 +33,7 @@ import { SetIndex } from '../define'; import { getPhaseID } from '../pass-phase'; import { renderQueueClearFunc, RenderQueue, convertRenderQueue, renderQueueSortFunc } from '../render-queue'; import { ClearFlagBit, Color, Rect } from '../../gfx'; -import { SRGBToLinear } from '../pipeline-funcs'; +import { renderProfiler, SRGBToLinear } from '../pipeline-funcs'; import { RenderBatchedQueue } from '../render-batched-queue'; import { RenderInstancedQueue } from '../render-instanced-queue'; import { IRenderStageInfo, RenderStage } from '../render-stage'; @@ -198,6 +198,7 @@ export class ForwardStage extends RenderStage { this._planarQueue.recordCommandBuffer(device, renderPass, cmdBuff); this._renderQueues[1].recordCommandBuffer(device, renderPass, cmdBuff); this._uiPhase.render(camera, renderPass); + renderProfiler(device, renderPass, cmdBuff, pipeline.profiler, swapchain); cmdBuff.endRenderPass(); } diff --git a/cocos/core/pipeline/forward/ui-phase.ts b/cocos/core/pipeline/forward/ui-phase.ts index cb6f082323..fa30c82ab2 100644 --- a/cocos/core/pipeline/forward/ui-phase.ts +++ b/cocos/core/pipeline/forward/ui-phase.ts @@ -27,7 +27,6 @@ import { RenderPass } from '../../gfx'; import { PipelineStateManager } from '../pipeline-state-manager'; import { SetIndex } from '../define'; import { Camera } from '../../renderer/scene/camera'; -import { ForwardPipeline } from './forward-pipeline'; import { RenderPipeline } from '../render-pipeline'; import { getPhaseID } from '../pass-phase'; @@ -69,15 +68,5 @@ export class UIPhase { cmdBuff.draw(inputAssembler!); } } - - if (pipeline.profiler && pipeline.profiler.enabled && camera.window!.swapchain) { - const { inputAssembler, passes, shaders, descriptorSet } = pipeline.profiler.subModels[0]; - const pso = PipelineStateManager.getOrCreatePipelineState(device, passes[0], shaders[0], renderPass, inputAssembler); - cmdBuff.bindPipelineState(pso); - cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, passes[0].descriptorSet); - cmdBuff.bindDescriptorSet(SetIndex.LOCAL, descriptorSet); - cmdBuff.bindInputAssembler(inputAssembler); - cmdBuff.draw(inputAssembler); - } } } diff --git a/cocos/core/pipeline/pipeline-funcs.ts b/cocos/core/pipeline/pipeline-funcs.ts index 014623586c..5d5893f26b 100644 --- a/cocos/core/pipeline/pipeline-funcs.ts +++ b/cocos/core/pipeline/pipeline-funcs.ts @@ -28,7 +28,14 @@ * @module pipeline */ +import { CommandBuffer, Device, Rect, RenderPass, Swapchain, Viewport } from '../gfx'; import { IVec4Like } from '../math'; +import { Model } from '../renderer/scene'; +import { PipelineStateManager } from './pipeline-state-manager'; +import { SetIndex } from './define'; + +const profilerViewport = new Viewport(); +const profilerScissor = new Rect(); /** * @en Convert color in SRGB space to linear space @@ -59,3 +66,20 @@ export function LinearToSRGB (out: IVec4Like, linear: IVec4Like) { out.y = Math.sqrt(linear.y); out.z = Math.sqrt(linear.z); } + +export function renderProfiler (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer, profiler: Model | null, swapchain: Swapchain | null) { + if (profiler && profiler.enabled && swapchain) { + const { inputAssembler, passes, shaders, descriptorSet } = profiler.subModels[0]; + profilerViewport.width = profilerScissor.width = swapchain.width; + profilerViewport.height = profilerScissor.height = swapchain.height; + const pso = PipelineStateManager.getOrCreatePipelineState(device, passes[0], shaders[0], renderPass, inputAssembler); + + cmdBuff.setViewport(profilerViewport); + cmdBuff.setScissor(profilerScissor); + cmdBuff.bindPipelineState(pso); + cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, passes[0].descriptorSet); + cmdBuff.bindDescriptorSet(SetIndex.LOCAL, descriptorSet); + cmdBuff.bindInputAssembler(inputAssembler); + cmdBuff.draw(inputAssembler); + } +} diff --git a/cocos/core/pipeline/pipeline-state-manager.ts b/cocos/core/pipeline/pipeline-state-manager.ts index f3149a9e8e..bdf04f634f 100644 --- a/cocos/core/pipeline/pipeline-state-manager.ts +++ b/cocos/core/pipeline/pipeline-state-manager.ts @@ -47,7 +47,7 @@ export class PipelineStateManager { const pipelineLayout = pass.pipelineLayout; const inputState = new InputState(ia.attributes); const psoInfo = new PipelineStateInfo( - shader, pass.pipelineLayout, renderPass, inputState, + shader, pipelineLayout, renderPass, inputState, pass.rasterizerState, pass.depthStencilState, pass.blendState, diff --git a/editor/assets/effects/editor/terrain-select-brush.effect.meta b/editor/assets/effects/editor/terrain-select-brush.effect.meta index bec8890927..7a698ddddc 100644 --- a/editor/assets/effects/editor/terrain-select-brush.effect.meta +++ b/editor/assets/effects/editor/terrain-select-brush.effect.meta @@ -1,5 +1,5 @@ { - "ver": "1.4.6", + "ver": "1.4.7", "importer": "effect", "imported": true, "uuid": "9b4d3fa5-89bf-4715-b69a-dbbd1efaf6a5",