From 2b032a2b8ecb18ff8059643ce565809c039754a5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 13 Aug 2024 09:22:00 +0800 Subject: [PATCH] fixed 3d-tasks/18423: Rendering is not correct on VK backend. (#17526) * fixed 3d-tasks/18423: Rendering is not correct on VK backend. Async tasks must be executed after present. * fix unused parameter lint error. --- native/cocos/bindings/manual/jsb_scene_manual.cpp | 8 ++++++-- native/cocos/core/Root.cpp | 1 + native/cocos/core/Root.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/native/cocos/bindings/manual/jsb_scene_manual.cpp b/native/cocos/bindings/manual/jsb_scene_manual.cpp index 064817dbac6..23d11adfab1 100644 --- a/native/cocos/bindings/manual/jsb_scene_manual.cpp +++ b/native/cocos/bindings/manual/jsb_scene_manual.cpp @@ -130,10 +130,14 @@ static bool js_root_registerListeners(se::State &s) // NOLINT(readability-identi DISPATCH_EVENT_TO_JS_ARGS_0(cc::Root::BeforeCommit, _onDirectorBeforeCommit, {}); DISPATCH_EVENT_TO_JS_ARGS_0(cc::Root::BeforeRender, _onDirectorBeforeRender, {}); - DISPATCH_EVENT_TO_JS_ARGS_0(cc::Root::AfterRender, _onDirectorAfterRender, { + DISPATCH_EVENT_TO_JS_ARGS_0(cc::Root::AfterRender, _onDirectorAfterRender, {}); + DISPATCH_EVENT_TO_JS_ARGS_0(cc::Root::PipelineChanged, _onDirectorPipelineChanged, {}); + + // NOTE: Async tasks must be executed after present, otherwise it will cause render issues on VK backend. + // Refer to https://github.com/cocos/3d-tasks/issues/18423 + cobj->on([](cc::Root */*rootObj*/){ CC_CURRENT_APPLICATION()->getEngine()->getScheduler()->runFunctionsToBePerformedInCocosThread(); }); - DISPATCH_EVENT_TO_JS_ARGS_0(cc::Root::PipelineChanged, _onDirectorPipelineChanged, {}); return true; } diff --git a/native/cocos/core/Root.cpp b/native/cocos/core/Root.cpp index be2030e6983..61608ed4265 100644 --- a/native/cocos/core/Root.cpp +++ b/native/cocos/core/Root.cpp @@ -443,6 +443,7 @@ void Root::frameMoveEnd() { emit(); #endif _device->present(); + emit(); } if (_batcher != nullptr) { diff --git a/native/cocos/core/Root.h b/native/cocos/core/Root.h index 5020f11e2d9..3834fc75ecc 100644 --- a/native/cocos/core/Root.h +++ b/native/cocos/core/Root.h @@ -64,6 +64,7 @@ class Root final { TARGET_EVENT_ARG0(BeforeCommit) TARGET_EVENT_ARG0(BeforeRender) TARGET_EVENT_ARG0(AfterRender) + TARGET_EVENT_ARG0(AfterPresent) TARGET_EVENT_ARG0(PipelineChanged) DECLARE_TARGET_EVENT_END() public: