From 985f4fd94cb9eaed0c6ae04a008b73e671e5f657 Mon Sep 17 00:00:00 2001 From: ChiaNing Date: Tue, 2 Aug 2022 16:05:24 +0800 Subject: [PATCH] Fix pass hash when blend change (#12294) Co-authored-by: ChiaNing --- cocos/2d/framework/ui-renderer.ts | 5 ++++- cocos/core/renderer/core/pass.ts | 5 +++++ native/cocos/scene/Pass.cpp | 4 ++++ native/cocos/scene/Pass.h | 1 + native/tools/tojs/scene.ini | 2 +- 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cocos/2d/framework/ui-renderer.ts b/cocos/2d/framework/ui-renderer.ts index a086149cc4..d3216535b8 100644 --- a/cocos/2d/framework/ui-renderer.ts +++ b/cocos/2d/framework/ui-renderer.ts @@ -489,7 +489,10 @@ export class UIRenderer extends Renderer { target.blendDstAlpha = BlendFactor.ONE_MINUS_SRC_ALPHA; target.blendDst = this._dstBlendFactor; target.blendSrc = this._srcBlendFactor; - this.getMaterialInstance(0)!.passes[0].blendState.setTarget(0, target); + const targetPass = this.getMaterialInstance(0)!.passes[0]; + targetPass.blendState.setTarget(0, target); + // @ts-expect-error hack for UI use pass object + targetPass._updatePassHash(); this._dstBlendFactorCache = this._dstBlendFactor; this._srcBlendFactorCache = this._srcBlendFactor; } diff --git a/cocos/core/renderer/core/pass.ts b/cocos/core/renderer/core/pass.ts index cd9a2396c9..b5e21c8f3e 100644 --- a/cocos/core/renderer/core/pass.ts +++ b/cocos/core/renderer/core/pass.ts @@ -656,6 +656,11 @@ export class Pass { this._hash = target._hash ^ hashFactor; } + // Only for UI + private _updatePassHash () { + this._hash = Pass.getPassHash(this); + } + // infos get root (): Root { return this._root; } get device (): Device { return this._device; } diff --git a/native/cocos/scene/Pass.cpp b/native/cocos/scene/Pass.cpp index b672e6dbfa..9f7b0a0a10 100644 --- a/native/cocos/scene/Pass.cpp +++ b/native/cocos/scene/Pass.cpp @@ -656,6 +656,10 @@ void Pass::initPassFromTarget(Pass *target, const gfx::DepthStencilState &dss, c _hash = target->_hash ^ hashFactor; } +void Pass::updatePassHash() { + _hash = Pass::getPassHash(this); +} + gfx::DescriptorSetLayout *Pass::getLocalSetLayout() const { return ProgramLib::getInstance()->getDescriptorSetLayout(_device, _programName, true); } diff --git a/native/cocos/scene/Pass.h b/native/cocos/scene/Pass.h index a5124f536d..18ada8ae06 100644 --- a/native/cocos/scene/Pass.h +++ b/native/cocos/scene/Pass.h @@ -298,6 +298,7 @@ public: // Only for UI void initPassFromTarget(Pass *target, const gfx::DepthStencilState &dss, ccstd::hash_t hashFactor); + void updatePassHash(); // internal use /** diff --git a/native/tools/tojs/scene.ini b/native/tools/tojs/scene.ini index c90e2de6ec..d4a79990fd 100644 --- a/native/tools/tojs/scene.ini +++ b/native/tools/tojs/scene.ini @@ -89,7 +89,7 @@ rename_functions = Root::[initialize=_initialize], ProgramLib::[registerEffect=register], Model::[initLocalDescriptors=_initLocalDescriptors updateLocalDescriptors=_updateLocalDescriptors updateInstancedAttributes=_updateInstancedAttributes getInstancedAttributeIndex=_getInstancedAttributeIndex], Scene::[load=_load activate=_activate], - Pass::[initPassFromTarget=_initPassFromTarget] + Pass::[initPassFromTarget=_initPassFromTarget updatePassHash=_updatePassHash] getter_setter = Root::[device:_device mainWindow curWindow tempWindow windows scenes cumulativeTime frameTime frameCount fps fixedFPS useDeferredPipeline/isUsingDeferredPipeline usesCustomPipeline/usesCustomPipeline pipeline customPipeline], RenderWindow::[width height framebuffer cameras swapchain],