From c94f71b9be2d6ee19b562d8b47bfe77161b24eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=88=98?= <40414978+PatriceJiang@users.noreply.github.com> Date: Thu, 5 Aug 2021 16:06:07 +0800 Subject: [PATCH 01/21] pause tick before create surface (#3801) --- native/cocos/platform/ohos/jni/JniCocosAbility.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/platform/ohos/jni/JniCocosAbility.cpp b/native/cocos/platform/ohos/jni/JniCocosAbility.cpp index add38aef86..398b05fcc7 100644 --- a/native/cocos/platform/ohos/jni/JniCocosAbility.cpp +++ b/native/cocos/platform/ohos/jni/JniCocosAbility.cpp @@ -156,7 +156,7 @@ void glThreadEntry() { std::this_thread::yield(); } - if (game) { + if (game && cc::cocosApp.animating) { // Handle java events send by UI thread. Input events are handled here too. cc::JniHelper::callStaticVoidMethod("com.cocos.lib.CocosHelper", "flushTasksOnGameThread"); From b9ed0af4fa24c42ef36620d5bbc240180949126d Mon Sep 17 00:00:00 2001 From: timlyeee <43355299+timlyeee@users.noreply.github.com> Date: Thu, 5 Aug 2021 17:22:46 +0800 Subject: [PATCH 02/21] Fix glslang errors and Edit-box errors (#3802) * Update cmake list for dynamic library update * as glslang and tbb become dynamic library, the cmake should copy dll from glslang folder too. * "gulp gen simulator" command will automatically generate by user's comupter so sometime it will generate x64 version's simulator. no it's update to generate Win32 version * Edit-Box was using wrong parameters GWL_WNDPROC, so x64 version will hit an error. details below:https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlongptra * small optimize gulp * change config * Update cmake list for dynamic library update * as glslang and tbb become dynamic library, the cmake should copy dll from glslang folder too. * "gulp gen simulator" command will automatically generate by user's comupter so sometime it will generate x64 version's simulator. no it's update to generate Win32 version * Edit-Box was using wrong parameters GWL_WNDPROC, so x64 version will hit an error. details below:https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlongptra * add glslang header * Revert "Update cmake list for dynamic library update" This reverts commit 5eceb132c2411d7e479f6744e33048fabaafe780. * fix rebase error --- native/CMakeLists.txt | 2 ++ native/cocos/renderer/gfx-metal/MTLUtils.mm | 2 +- native/cocos/renderer/gfx-vulkan/VKSPIRV.h | 2 +- native/cocos/ui/edit-box/EditBox-win32.cpp | 8 ++----- native/external/config.json | 4 ++-- native/gulpfile.js | 23 +++++++++++++------ .../runtime-src/proj.win32/SimulatorWin.cpp | 2 +- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index b3c32a87bb..940d18dca6 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -2146,11 +2146,13 @@ if(MSVC) file(GLOB_RECURSE WIN32_DLLS ${CWD}/external/win32/libs/*.dll ${CWD}/external/win32/libs/Debug/*.dll + ${CWD}/external/win32/libs/glslang/*.dll ) else() file(GLOB_RECURSE WIN32_DLLS ${CWD}/external/win64/libs/*.dll ${CWD}/external/win64/libs/Debug/*.dll + ${CWD}/external/win64/libs/glslang/*.dll ) endif() target_compile_options(cocos2d PUBLIC /MP) diff --git a/native/cocos/renderer/gfx-metal/MTLUtils.mm b/native/cocos/renderer/gfx-metal/MTLUtils.mm index aa6dc78004..57a3b1398d 100644 --- a/native/cocos/renderer/gfx-metal/MTLUtils.mm +++ b/native/cocos/renderer/gfx-metal/MTLUtils.mm @@ -31,7 +31,7 @@ #include "MTLPipelineState.h" #include "MTLRenderPass.h" #include "MTLShader.h" -#include "StandAlone/ResourceLimits.h" +#include "glslang/StandAlone/ResourceLimits.h" #include "glslang/SPIRV/GlslangToSpv.h" #include "spirv_cross/spirv_msl.hpp" #include "TargetConditionals.h" diff --git a/native/cocos/renderer/gfx-vulkan/VKSPIRV.h b/native/cocos/renderer/gfx-vulkan/VKSPIRV.h index b3107d3b35..22503b678b 100644 --- a/native/cocos/renderer/gfx-vulkan/VKSPIRV.h +++ b/native/cocos/renderer/gfx-vulkan/VKSPIRV.h @@ -28,7 +28,7 @@ #include "base/Log.h" #include "gfx-base/GFXDef.h" -#include "StandAlone/ResourceLimits.h" +#include "glslang/StandAlone/ResourceLimits.h" #include "glslang/Public/ShaderLang.h" #include "glslang/SPIRV/GlslangToSpv.h" diff --git a/native/cocos/ui/edit-box/EditBox-win32.cpp b/native/cocos/ui/edit-box/EditBox-win32.cpp index c6039caaf7..2e1784b7bf 100644 --- a/native/cocos/ui/edit-box/EditBox-win32.cpp +++ b/native/cocos/ui/edit-box/EditBox-win32.cpp @@ -34,10 +34,6 @@ #include #include -#ifdef _WIN64 - #define GWL_WNDPROC (-4) -#endif - extern std::shared_ptr cc_get_application_view(); namespace cc { @@ -187,8 +183,8 @@ void EditBox::show(const EditBox::ShowInfo &showInfo) { return; } - g_prevMainWindowProc = (WNDPROC)SetWindowLongPtr(parent, GWL_WNDPROC, (LONG_PTR)mainWindowProc); - g_prevEditWindowProc = (WNDPROC)SetWindowLongPtr(g_hwndEditBox, GWL_WNDPROC, (LONG_PTR)editWindowProc); + g_prevMainWindowProc = (WNDPROC)SetWindowLongPtr(parent, GWLP_WNDPROC, (LONG_PTR)mainWindowProc); + g_prevEditWindowProc = (WNDPROC)SetWindowLongPtr(g_hwndEditBox, GWLP_WNDPROC, (LONG_PTR)editWindowProc); } ::SendMessageW(g_hwndEditBox, EM_LIMITTEXT, showInfo.maxLength, 0); diff --git a/native/external/config.json b/native/external/config.json index 68bbc50a45..761dde533b 100644 --- a/native/external/config.json +++ b/native/external/config.json @@ -1,9 +1,9 @@ { - "version": "v3d-gfx-55", + "version": "v3d-gfx-62", "from": { "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3d-gfx-55" + "checkout": "v3d-gfx-62" } } \ No newline at end of file diff --git a/native/gulpfile.js b/native/gulpfile.js index 8f7d6bee65..75f0a866d9 100644 --- a/native/gulpfile.js +++ b/native/gulpfile.js @@ -36,7 +36,7 @@ var fs = require('fs-extra'); const which = require('which'); const del = require('del'); -function absolutePath (relativePath) { +function absolutePath(relativePath) { return Path.join(__dirname, relativePath); } @@ -54,7 +54,7 @@ else { gulp.task('publish', gulpSequence('update', 'init', 'bump-version', 'make-simulator')); } -function execSync (cmd, workPath) { +function execSync(cmd, workPath) { var execOptions = { cwd: workPath || '.', stdio: 'inherit' @@ -62,7 +62,7 @@ function execSync (cmd, workPath) { ExecSync(cmd, execOptions); } -function upload2Ftp (localPath, ftpPath, config, cb) { +function upload2Ftp(localPath, ftpPath, config, cb) { var ftpClient = new Ftp(); ftpClient.on('error', function (err) { if (err) { @@ -96,7 +96,7 @@ function upload2Ftp (localPath, ftpPath, config, cb) { ftpClient.connect(config); } -function uploadZipFile (zipFileName, path, cb) { +function uploadZipFile(zipFileName, path, cb) { var branch = getCurrentBranch(); if (branch === 'develop') { branch = 'dev'; @@ -110,14 +110,14 @@ function uploadZipFile (zipFileName, path, cb) { }, cb); } -function getCurrentBranch () { +function getCurrentBranch() { var spawnSync = require('child_process').spawnSync; var output = spawnSync('git', ['symbolic-ref', '--short', '-q', 'HEAD']); // console.log(output); return output.stdout.toString().trim(); } -function formatPath (p) { +function formatPath(p) { return p.replace(/\\/g, '/'); } @@ -161,7 +161,16 @@ gulp.task('gen-simulator', async function () { console.log('make project\n'); console.log('=====================================\n'); await new Promise((resolve, reject) => { - let cmakeProcess = spawn(cmakeBin, ['-G', isWin32 ? 'Visual Studio 15 2017' : 'Xcode', absolutePath('./tools/simulator/frameworks/runtime-src/')], { + var args = []; + args.push('-G'); + if (isWin32) { + args.push('Visual Studio 15 2017','-A','Win32'); + } + else { + args.push('Xcode'); + } + args.push(absolutePath('./tools/simulator/frameworks/runtime-src/')); + let cmakeProcess = spawn(cmakeBin, args, { cwd: simulatorProject, }); cmakeProcess.on('close', () => { diff --git a/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorWin.cpp b/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorWin.cpp index 363f48fb51..8e09e1e2c3 100755 --- a/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorWin.cpp +++ b/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorWin.cpp @@ -514,7 +514,7 @@ int SimulatorWin::run() // prepare _project.dump(); - g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWL_WNDPROC, (LONG)SimulatorWin::windowProc); + g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWLP_WNDPROC, (LONG)SimulatorWin::windowProc); // update window title updateWindowTitle(); From e0126cae98684e04ef678dde801a9678a4847d43 Mon Sep 17 00:00:00 2001 From: timlyeee <43355299+timlyeee@users.noreply.github.com> Date: Fri, 6 Aug 2021 11:44:44 +0800 Subject: [PATCH 03/21] Update config.json (#3804) --- native/external/config.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/native/external/config.json b/native/external/config.json index 761dde533b..7249e58d85 100644 --- a/native/external/config.json +++ b/native/external/config.json @@ -1,9 +1,9 @@ { - "version": "v3d-gfx-62", + "version": "v3d-gfx-63", "from": { "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3d-gfx-62" + "checkout": "v3d-gfx-63" } -} \ No newline at end of file +} From 60e7c2f2abfb906c153c5455ef3bb548205b6a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=88=98?= <40414978+PatriceJiang@users.noreply.github.com> Date: Fri, 6 Aug 2021 11:45:37 +0800 Subject: [PATCH 04/21] 3.3 auto select bind port (#3803) --- .../cocos/bindings/manual/jsb_global_init.cpp | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/native/cocos/bindings/manual/jsb_global_init.cpp b/native/cocos/bindings/manual/jsb_global_init.cpp index 3e585d1551..539ffef4aa 100644 --- a/native/cocos/bindings/manual/jsb_global_init.cpp +++ b/native/cocos/bindings/manual/jsb_global_init.cpp @@ -23,6 +23,14 @@ THE SOFTWARE. ****************************************************************************/ +// clang-format: off +#if CC_PLATFORM == CC_PLATFORM_WINDOWS +// Fix ssize_t defination +#include "cocos/bindings/jswrapper/config.h" +#endif +#include "uv.h" +// clang-format: on + #include "base/CoreStd.h" #include "base/Scheduler.h" #include "base/ZipUtils.h" @@ -55,6 +63,31 @@ static std::string removeFileExt(const std::string &filePath) { return filePath; } +static int selectPort(int port) { + uv_tcp_t server; + struct sockaddr_in addr; + uv_loop_t * loop = uv_default_loop(); + int tryTimes = 200; + int startPort = port; + uv_tcp_init(loop, &server); + while (true) { + if (tryTimes-- < 0) { + return port; // allow failure + } + uv_ip4_addr("0.0.0.0", startPort, &addr); + uv_tcp_bind(&server, reinterpret_cast(&addr), 0); + int r = uv_listen(reinterpret_cast(&server), 5, nullptr); + if (r) { + SE_LOGD("Failed to listen port %d, error: %s. Try next port\n", startPort, uv_strerror(r)); + startPort += 1; + uv_close(reinterpret_cast(&server), nullptr); + } else { + uv_close(reinterpret_cast(&server), nullptr); + return startPort; + } + } +} + void jsb_init_file_operation_delegate() { //NOLINT static se::ScriptEngine::FileOperationDelegate delegate; @@ -170,7 +203,9 @@ bool jsb_enable_debugger(const std::string &debuggerServerAddr, uint32_t port, b return false; } - auto se = se::ScriptEngine::getInstance(); + port = static_cast(selectPort(static_cast(port))); + + auto *se = se::ScriptEngine::getInstance(); se->enableDebugger(debuggerServerAddr, port, isWaitForConnect); // For debugger main loop From 0e23ff79f1fbb850256534cd61ff66bf5bdff305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=88=98?= <40414978+PatriceJiang@users.noreply.github.com> Date: Fri, 6 Aug 2021 16:29:59 +0800 Subject: [PATCH 05/21] 3.3 fix mq restart (#3805) * fix mq restart --- native/cocos/bindings/manual/jsb_scene_manual_ext.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/native/cocos/bindings/manual/jsb_scene_manual_ext.cpp b/native/cocos/bindings/manual/jsb_scene_manual_ext.cpp index 3c49bad24a..a5c8a2aa3d 100644 --- a/native/cocos/bindings/manual/jsb_scene_manual_ext.cpp +++ b/native/cocos/bindings/manual/jsb_scene_manual_ext.cpp @@ -1,5 +1,7 @@ #include "bindings/auto/jsb_scene_auto.h" +#include "bindings/event/CustomEventTypes.h" +#include "bindings/event/EventDispatcher.h" #include "jsb_scene_manual.h" #include "scene/Model.h" #include "scene/Node.h" @@ -210,6 +212,10 @@ bool register_all_scene_ext_manual(se::Object *obj) { //NOLINT msgQueue = se::Object::createArrayObject(1); msgQueueInfo = se::Object::createTypedArray(se::Object::TypedArrayType::UINT32, nullptr, sizeof(uint32_t) * 2); + cc::EventDispatcher::addCustomEventListener(EVENT_RESTART_VM, [&](const cc::CustomEvent & /*e*/) { + msgQueuePtrs.clear(); + }); + { uint8_t *data{nullptr}; msgArrayBuffer->getArrayBufferData(&data, nullptr); From edcf75ec9d8d392c87fe646e907798426211e406 Mon Sep 17 00:00:00 2001 From: zhakesi Date: Fri, 6 Aug 2021 16:33:56 +0800 Subject: [PATCH 06/21] fix:when skelton data destory clean all data. (#3800) --- .../SkeletonAnimation.cpp | 1 - .../spine-creator-support/SkeletonDataMgr.cpp | 23 +++++++----------- .../spine-creator-support/SkeletonDataMgr.h | 24 ++++++++++--------- .../SkeletonRenderer.cpp | 1 - 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.cpp index 5b2124a1a4..d2f7eb30b0 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonAnimation.cpp @@ -118,7 +118,6 @@ SkeletonAnimation::~SkeletonAnimation() { _eventListener = nullptr; if (_state) { - clearTracks(); if (_ownsAnimationStateData) delete _state->getData(); delete _state; } diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp index 4e3614d23f..3664ce0376 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.cpp @@ -31,11 +31,11 @@ #include #include -using namespace spine; +using namespace spine; //NOLINT namespace spine { -class SkeletonDataInfo : public cc::Ref { +class SkeletonDataInfo { public: SkeletonDataInfo() = default; @@ -64,7 +64,7 @@ public: } // namespace spine -SkeletonDataMgr *SkeletonDataMgr::_instance = nullptr; +SkeletonDataMgr *SkeletonDataMgr::instance = nullptr; bool SkeletonDataMgr::hasSkeletonData(const std::string &uuid) { auto it = _dataMap.find(uuid); @@ -76,7 +76,7 @@ void SkeletonDataMgr::setSkeletonData(const std::string &uuid, SkeletonData *dat if (it != _dataMap.end()) { releaseByUUID(uuid); } - SkeletonDataInfo *info = new SkeletonDataInfo(); + auto *info = new SkeletonDataInfo(); info->data = data; info->atlas = atlas; info->attachmentLoader = attachmentLoader; @@ -89,7 +89,6 @@ SkeletonData *SkeletonDataMgr::retainByUUID(const std::string &uuid) { if (dataIt == _dataMap.end()) { return nullptr; } - dataIt->second->retain(); return dataIt->second->data; } @@ -99,15 +98,11 @@ void SkeletonDataMgr::releaseByUUID(const std::string &uuid) { return; } SkeletonDataInfo *info = dataIt->second; - // If info reference count is 1, then info will be destroy. - if (info->getReferenceCount() == 1) { - _dataMap.erase(dataIt); - if (_destroyCallback) { - auto &texturesIndex = info->texturesIndex; - for (auto it = texturesIndex.begin(); it != texturesIndex.end(); it++) { - _destroyCallback(*it); - } + _dataMap.erase(dataIt); + if (_destroyCallback) { + for (auto &item : info->texturesIndex) { + _destroyCallback(item); } } - info->release(); + delete info; } diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.h b/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.h index 8a2189c043..2355adb18a 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.h +++ b/native/cocos/editor-support/spine-creator-support/SkeletonDataMgr.h @@ -47,36 +47,38 @@ class SkeletonDataInfo; class SkeletonDataMgr { public: static SkeletonDataMgr *getInstance() { - if (_instance == nullptr) { - _instance = new SkeletonDataMgr(); + if (instance == nullptr) { + instance = new SkeletonDataMgr(); } - return _instance; + return instance; } static void destroyInstance() { - if (_instance) { - delete _instance; - _instance = nullptr; + if (instance) { + delete instance; + instance = nullptr; } } - SkeletonDataMgr() {} + SkeletonDataMgr() = default; virtual ~SkeletonDataMgr() { - _destroyCallback = NULL; + _destroyCallback = nullptr; } bool hasSkeletonData(const std::string &uuid); void setSkeletonData(const std::string &uuid, SkeletonData *data, Atlas *atlas, AttachmentLoader *attachmentLoader, const std::vector &texturesIndex); + // equal to 'findByUUID' SkeletonData *retainByUUID(const std::string &uuid); + // equal to 'deleteByUUID' void releaseByUUID(const std::string &uuid); - typedef std::function destroyCallback; + using destroyCallback = std::function; void setDestroyCallback(destroyCallback callback) { - _destroyCallback = callback; + _destroyCallback = std::move(callback); } private: - static SkeletonDataMgr *_instance; + static SkeletonDataMgr* instance; destroyCallback _destroyCallback = nullptr; std::map _dataMap; }; diff --git a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp index 1437cfb20d..62409b76df 100644 --- a/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp +++ b/native/cocos/editor-support/spine-creator-support/SkeletonRenderer.cpp @@ -156,7 +156,6 @@ SkeletonRenderer::~SkeletonRenderer() { if (_ownsSkeleton) delete _skeleton; if (_ownsAtlas && _atlas) delete _atlas; delete _attachmentLoader; - if (!_uuid.empty()) SkeletonDataMgr::getInstance()->releaseByUUID(_uuid); delete _clipper; if (_debugBuffer) { From 44a13a2a5889ea576c6725898cb3cf1f37c13d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=88=98?= <40414978+PatriceJiang@users.noreply.github.com> Date: Fri, 6 Aug 2021 18:00:15 +0800 Subject: [PATCH 07/21] V3.3 fix ohos tick (#3806) * fix mq restart * simplify loop --- native/cocos/bindings/manual/jsb_scene_manual_ext.cpp | 7 +------ native/cocos/platform/Application.cpp | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/native/cocos/bindings/manual/jsb_scene_manual_ext.cpp b/native/cocos/bindings/manual/jsb_scene_manual_ext.cpp index a5c8a2aa3d..7f617cc378 100644 --- a/native/cocos/bindings/manual/jsb_scene_manual_ext.cpp +++ b/native/cocos/bindings/manual/jsb_scene_manual_ext.cpp @@ -1,7 +1,5 @@ #include "bindings/auto/jsb_scene_auto.h" -#include "bindings/event/CustomEventTypes.h" -#include "bindings/event/EventDispatcher.h" #include "jsb_scene_manual.h" #include "scene/Model.h" #include "scene/Node.h" @@ -211,10 +209,7 @@ bool register_all_scene_ext_manual(se::Object *obj) { //NOLINT globalThis = se::ScriptEngine::getInstance()->getGlobalObject(); msgQueue = se::Object::createArrayObject(1); msgQueueInfo = se::Object::createTypedArray(se::Object::TypedArrayType::UINT32, nullptr, sizeof(uint32_t) * 2); - - cc::EventDispatcher::addCustomEventListener(EVENT_RESTART_VM, [&](const cc::CustomEvent & /*e*/) { - msgQueuePtrs.clear(); - }); + msgQueuePtrs.clear(); { uint8_t *data{nullptr}; diff --git a/native/cocos/platform/Application.cpp b/native/cocos/platform/Application.cpp index 281d056642..02fb176655 100644 --- a/native/cocos/platform/Application.cpp +++ b/native/cocos/platform/Application.cpp @@ -107,7 +107,7 @@ void Application::tick() { ++_totalFrames; // iOS/macOS use its own fps limitation algorithm. -#if (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_WINDOWS) +#if (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_OHOS) if (dtNS < static_cast(_prefererredNanosecondsPerFrame)) { std::this_thread::sleep_for( std::chrono::nanoseconds(_prefererredNanosecondsPerFrame - static_cast(dtNS))); From 19690d04c85a39931ab2f22f34b23222e46d8edc Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Sun, 8 Aug 2021 07:40:32 +0800 Subject: [PATCH 08/21] Fixed the restart crash (#3808) --- native/cocos/scene/Node.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/native/cocos/scene/Node.cpp b/native/cocos/scene/Node.cpp index 77775c728e..8e9ba4be0d 100644 --- a/native/cocos/scene/Node.cpp +++ b/native/cocos/scene/Node.cpp @@ -173,6 +173,7 @@ void Node::initWithData(uint8_t *data, uint8_t *flagChunk, const se::Value &dirt dirtyNodes->incRef(); se::ScriptEngine::getInstance()->addBeforeCleanupHook([]() { dirtyNodes->decRef(); + dirtyNodes = nullptr; }); } } From 5bae0ea77268dde1594d710a2a0db5f4cf03fa3d Mon Sep 17 00:00:00 2001 From: timlyeee <43355299+timlyeee@users.noreply.github.com> Date: Sun, 8 Aug 2021 07:41:11 +0800 Subject: [PATCH 09/21] V3.3.0 restart issue (#3807) * add restart custom event * tidy --- native/cocos/platform/Application.cpp | 2 ++ native/cocos/renderer/GFXDeviceManager.h | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/native/cocos/platform/Application.cpp b/native/cocos/platform/Application.cpp index 02fb176655..c9d73139cf 100644 --- a/native/cocos/platform/Application.cpp +++ b/native/cocos/platform/Application.cpp @@ -26,6 +26,7 @@ #include "cocos/platform/Application.h" #include "cocos/bindings/jswrapper/SeApi.h" #include "pipeline/RenderPipeline.h" +#include "cocos/renderer/GFXDeviceManager.h" #if USE_AUDIO #include "cocos/audio/include/AudioEngine.h" @@ -64,6 +65,7 @@ void Application::restartVM() { cc::EventDispatcher::init(); init(); + cc::gfx::DeviceManager::addCustomEvent(); } void Application::close() { // NOLINT diff --git a/native/cocos/renderer/GFXDeviceManager.h b/native/cocos/renderer/GFXDeviceManager.h index 6227a5eed1..fb07145ad8 100644 --- a/native/cocos/renderer/GFXDeviceManager.h +++ b/native/cocos/renderer/GFXDeviceManager.h @@ -89,6 +89,16 @@ public: static void destroy() { CC_SAFE_DESTROY(Device::instance); } + static void addCustomEvent() { + Device *device = Device::instance; + EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [device](const CustomEvent &e) -> void { + device->releaseSurface(reinterpret_cast(e.args->ptrVal)); + }); + + EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [device](const CustomEvent &e) -> void { + device->acquireSurface(reinterpret_cast(e.args->ptrVal)); + }); + } private: template ::value>> @@ -108,14 +118,7 @@ private: return false; } - EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [device](const CustomEvent &e) -> void { - device->releaseSurface(reinterpret_cast(e.args->ptrVal)); - }); - - EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [device](const CustomEvent &e) -> void { - device->acquireSurface(reinterpret_cast(e.args->ptrVal)); - }); - + addCustomEvent(); *pDevice = device; return true; From b249589ab02951ee03cda6cb31292dfa460b5bd9 Mon Sep 17 00:00:00 2001 From: cary <39078800+caryliu1999@users.noreply.github.com> Date: Mon, 9 Aug 2021 15:21:55 +0800 Subject: [PATCH 10/21] Fix capture to web scene crash on IOS. (#3809) --- native/cocos/renderer/pipeline/deferred/LightingStage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index ba2a720d30..d1d814ecc2 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -274,7 +274,7 @@ void LightingStage::activate(RenderPipeline *pipeline, RenderFlow *flow) { _reflectionComp = new ReflectionComp(); gfx::ColorAttachment cAttch = { - gfx::Format::RGBA8, + gfx::Format::RGBA16F, gfx::SampleCount::X1, gfx::LoadOp::LOAD, gfx::StoreOp::STORE, From e40e36ab01b231d36aad7b19be0ea8e1ef9fece9 Mon Sep 17 00:00:00 2001 From: Cocos Robot <48829427+cocos-robot@users.noreply.github.com> Date: Mon, 9 Aug 2021 15:41:44 +0800 Subject: [PATCH 11/21] [ci skip][AUTO]: updating jsbinding automatically: b249589a (#3812) Co-authored-by: cocos-robot --- native/cocos/bindings/auto/jsb_gfx_auto.cpp | 14 ++++++++++++++ native/cocos/bindings/auto/jsb_gfx_auto.h | 1 + 2 files changed, 15 insertions(+) diff --git a/native/cocos/bindings/auto/jsb_gfx_auto.cpp b/native/cocos/bindings/auto/jsb_gfx_auto.cpp index 7f229c7e1b..6056ac1949 100644 --- a/native/cocos/bindings/auto/jsb_gfx_auto.cpp +++ b/native/cocos/bindings/auto/jsb_gfx_auto.cpp @@ -20851,6 +20851,19 @@ static bool js_gfx_DeviceManager_create(se::State& s) // NOLINT(readability-iden } SE_BIND_FUNC(js_gfx_DeviceManager_create) +static bool js_gfx_DeviceManager_addCustomEvent(se::State& s) // NOLINT(readability-identifier-naming) +{ + const auto& args = s.args(); + size_t argc = args.size(); + if (argc == 0) { + cc::gfx::DeviceManager::addCustomEvent(); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_FUNC(js_gfx_DeviceManager_addCustomEvent) + static bool js_cc_gfx_DeviceManager_finalize(se::State& s) // NOLINT(readability-identifier-naming) { @@ -20871,6 +20884,7 @@ bool js_register_gfx_DeviceManager(se::Object* obj) // NOLINT(readability-identi cls->defineStaticFunction("destroy", _SE(js_gfx_DeviceManager_destroy)); cls->defineStaticFunction("create", _SE(js_gfx_DeviceManager_create)); + cls->defineStaticFunction("addCustomEvent", _SE(js_gfx_DeviceManager_addCustomEvent)); cls->defineFinalizeFunction(_SE(js_cc_gfx_DeviceManager_finalize)); cls->install(); JSBClassType::registerClass(cls); diff --git a/native/cocos/bindings/auto/jsb_gfx_auto.h b/native/cocos/bindings/auto/jsb_gfx_auto.h index 4c9f882541..7a7329e7bf 100644 --- a/native/cocos/bindings/auto/jsb_gfx_auto.h +++ b/native/cocos/bindings/auto/jsb_gfx_auto.h @@ -846,4 +846,5 @@ bool register_all_gfx(se::Object* obj); JSB_REGISTER_OBJECT_TYPE(cc::gfx::DeviceManager); SE_DECLARE_FUNC(js_gfx_DeviceManager_destroy); SE_DECLARE_FUNC(js_gfx_DeviceManager_create); +SE_DECLARE_FUNC(js_gfx_DeviceManager_addCustomEvent); From 2056271baceefc5b58198c9c0816906774735674 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Tue, 10 Aug 2021 09:49:18 +0800 Subject: [PATCH 12/21] misc pipeline fixes (#3811) --- native/cocos/base/Utils.cpp | 4 + native/cocos/base/Utils.h | 2 + native/cocos/renderer/gfx-base/GFXBuffer.h | 3 + .../cocos/renderer/gfx-base/GFXDef-common.h | 2 +- .../renderer/gfx-gles3/GLES3Commands.cpp | 3 + .../gfx-validator/CommandBufferValidator.cpp | 8 + .../gfx-validator/DescriptorSetValidator.cpp | 3 + native/cocos/renderer/gfx-vulkan/VKBuffer.cpp | 25 +-- .../renderer/gfx-vulkan/VKCommandBuffer.cpp | 16 +- .../renderer/gfx-vulkan/VKCommandBuffer.h | 3 +- .../cocos/renderer/gfx-vulkan/VKCommands.cpp | 19 ++- .../renderer/gfx-vulkan/VKDescriptorSet.cpp | 4 +- .../cocos/renderer/gfx-vulkan/VKGPUObjects.h | 14 ++ native/cocos/renderer/gfx-vulkan/VKUtils.h | 2 +- native/cocos/renderer/pipeline/Define.h | 1 + .../cocos/renderer/pipeline/PipelineUBO.cpp | 159 +++++++++--------- native/cocos/renderer/pipeline/PipelineUBO.h | 9 +- .../pipeline/deferred/DeferredPipeline.cpp | 23 ++- .../pipeline/deferred/LightingStage.cpp | 23 +-- .../pipeline/deferred/PostprocessStage.cpp | 4 +- .../pipeline/forward/ForwardPipeline.cpp | 5 +- native/cocos/scene/SubModel.cpp | 16 +- native/cocos/scene/SubModel.h | 12 +- native/cocos/ui/edit-box/EditBox-win32.cpp | 4 +- 24 files changed, 212 insertions(+), 152 deletions(-) diff --git a/native/cocos/base/Utils.cpp b/native/cocos/base/Utils.cpp index b4d9fdcb08..cfd3ef70bd 100644 --- a/native/cocos/base/Utils.cpp +++ b/native/cocos/base/Utils.cpp @@ -70,6 +70,10 @@ uint nextPOT(uint x) { return x + 1; } +uint alignTo(uint size, uint alignment) { + return ((size - 1) / alignment + 1) * alignment; +} + // painfully slow to execute, use with caution std::string getStacktrace(uint skip, uint maxDepth) { return boost::stacktrace::to_string(boost::stacktrace::stacktrace(skip, maxDepth)); diff --git a/native/cocos/base/Utils.h b/native/cocos/base/Utils.h index 5a832c8354..f1b500145d 100644 --- a/native/cocos/base/Utils.h +++ b/native/cocos/base/Utils.h @@ -62,6 +62,8 @@ CC_DLL uint nextPOT(uint x); */ CC_DLL double atof(const char *str); +CC_DLL uint alignTo(uint size, uint alignment); + template char (*countOfHelper(T (&array)[Size]))[Size]; diff --git a/native/cocos/renderer/gfx-base/GFXBuffer.h b/native/cocos/renderer/gfx-base/GFXBuffer.h index 7ec3d28ca3..69951edd20 100644 --- a/native/cocos/renderer/gfx-base/GFXBuffer.h +++ b/native/cocos/renderer/gfx-base/GFXBuffer.h @@ -44,12 +44,15 @@ public: virtual void update(const void *buffer, uint size) = 0; + inline void update(const void *buffer) { update(buffer, _size); } + inline BufferUsage getUsage() const { return _usage; } inline MemoryUsage getMemUsage() const { return _memUsage; } inline uint getStride() const { return _stride; } inline uint getCount() const { return _count; } inline uint getSize() const { return _size; } inline BufferFlags getFlags() const { return _flags; } + inline bool isBufferView() const { return _isBufferView; } protected: virtual void doInit(const BufferInfo &info) = 0; diff --git a/native/cocos/renderer/gfx-base/GFXDef-common.h b/native/cocos/renderer/gfx-base/GFXDef-common.h index bda2ac3e77..81ad50df8f 100644 --- a/native/cocos/renderer/gfx-base/GFXDef-common.h +++ b/native/cocos/renderer/gfx-base/GFXDef-common.h @@ -1078,7 +1078,7 @@ struct ColorAttachment { LoadOp loadOp = LoadOp::CLEAR; StoreOp storeOp = StoreOp::STORE; std::vector beginAccesses; - std::vector endAccesses{AccessType::PRESENT}; + std::vector endAccesses{AccessType::COLOR_ATTACHMENT_WRITE}; bool isGeneralLayout = false; }; diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp index 01aff07265..f4683b1228 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp @@ -2265,6 +2265,9 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli if (cache->glBindUBOs[glBuffer.glBinding] != gpuDescriptor.gpuBuffer->glBuffer || cache->glBindUBOOffsets[glBuffer.glBinding] != offset) { if (offset) { + GLint size{0}; + glGetIntegeri_v(GL_UNIFORM_BUFFER_SIZE, glBuffer.glBinding, &size); + GL_CHECK(glBindBufferRange(GL_UNIFORM_BUFFER, glBuffer.glBinding, gpuDescriptor.gpuBuffer->glBuffer, offset, gpuDescriptor.gpuBuffer->size)); } else { diff --git a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp index 7d93582afc..bb7713ce78 100644 --- a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp @@ -289,6 +289,14 @@ void CommandBufferValidator::draw(const DrawInfo &info) { _recorder.recordDrawcall(_curStates); } + const auto &psoLayouts = _curStates.pipelineState->getPipelineLayout()->getSetLayouts(); + for (size_t i = 0; i < psoLayouts.size(); ++i) { + if (!_curStates.descriptorSets[i]) continue; // there may be inactive sets + const auto &dsBindings = _curStates.descriptorSets[i]->getLayout()->getBindings(); + const auto &psoBindings = psoLayouts[i]->getBindings(); + CCASSERT(psoBindings.size() == dsBindings.size(), "Descriptor set layout mismatch"); + } + /////////// execute /////////// _actor->draw(info); diff --git a/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp b/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp index 0934d2d383..0e410604da 100644 --- a/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp @@ -75,6 +75,9 @@ void DescriptorSetValidator::bindBuffer(uint binding, Buffer *buffer, uint index CCASSERT(binding < bindingIndices.size() && bindingIndices[binding] < bindings.size(), "Illegal binding"); const DescriptorSetLayoutBinding &info = bindings[bindingIndices[binding]]; + if (hasAnyFlags(info.descriptorType, DESCRIPTOR_DYNAMIC_TYPE)) { + CCASSERT(buffer->isBufferView(), "Should bind buffer views for dynamic descriptors"); + } CCASSERT(hasAnyFlags(info.descriptorType, DESCRIPTOR_BUFFER_TYPE), "Setting binding is not DESCRIPTOR_BUFFER_TYPE"); /////////// execute /////////// diff --git a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp index 33d9d5bff3..bdd1aa1e40 100644 --- a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp @@ -40,12 +40,12 @@ CCVKBuffer::~CCVKBuffer() { } void CCVKBuffer::doInit(const BufferInfo & /*info*/) { - _gpuBuffer = CC_NEW(CCVKGPUBuffer); - _gpuBuffer->usage = _usage; + _gpuBuffer = CC_NEW(CCVKGPUBuffer); + _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; - _gpuBuffer->size = _size; - _gpuBuffer->stride = _stride; - _gpuBuffer->count = _count; + _gpuBuffer->size = _size; + _gpuBuffer->stride = _stride; + _gpuBuffer->count = _count; if (hasFlag(_usage, BufferUsageBit::INDIRECT)) { const size_t drawInfoCount = _size / sizeof(DrawInfo); @@ -61,16 +61,16 @@ void CCVKBuffer::doInit(const BufferInfo & /*info*/) { } void CCVKBuffer::doInit(const BufferViewInfo &info) { - auto *buffer = static_cast(info.buffer); - _gpuBuffer = buffer->gpuBuffer(); + auto *buffer = static_cast(info.buffer); + _gpuBuffer = buffer->gpuBuffer(); _gpuBufferView = CC_NEW(CCVKGPUBufferView); createBufferView(); } void CCVKBuffer::createBufferView() { _gpuBufferView->gpuBuffer = _gpuBuffer; - _gpuBufferView->offset = _offset; - _gpuBufferView->range = _size; + _gpuBufferView->offset = _offset; + _gpuBufferView->range = _size; CCVKDevice::getInstance()->gpuDescriptorHub()->update(_gpuBufferView); } @@ -94,14 +94,17 @@ void CCVKBuffer::doDestroy() { } void CCVKBuffer::doResize(uint size, uint count) { + uint oldStartOffset = _gpuBuffer->startOffset; + CCVKDevice::getInstance()->getMemoryStatus().bufferSize -= _size; CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuBuffer); - _gpuBuffer->size = size; + _gpuBuffer->size = size; _gpuBuffer->count = count; cmdFuncCCVKCreateBuffer(CCVKDevice::getInstance(), _gpuBuffer); - createBufferView(); + _gpuBufferView->range = size; + CCVKDevice::getInstance()->gpuDescriptorHub()->update(_gpuBuffer, oldStartOffset); if (hasFlag(_usage, BufferUsageBit::INDIRECT)) { const size_t drawInfoCount = _size / sizeof(DrawInfo); diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp index 738cfec328..2ea54a7709 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp @@ -57,8 +57,7 @@ void CCVKCommandBuffer::doInit(const CommandBufferInfo & /*info*/) { size_t setCount = CCVKDevice::getInstance()->bindingMappingInfo().bufferOffsets.size(); _curGPUDescriptorSets.resize(setCount); _curVkDescriptorSets.resize(setCount); - _curDynamicOffsetPtrs.resize(setCount); - _curDynamicOffsetCounts.resize(setCount); + _curDynamicOffsetsArray.resize(setCount); } void CCVKCommandBuffer::doDestroy() { @@ -76,7 +75,7 @@ void CCVKCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); - _curDynamicOffsetCounts.assign(_curDynamicOffsetCounts.size(), 0U); + _curDynamicOffsetsArray.assign(_curDynamicOffsetsArray.size(), {}); _firstDirtyDescriptorSet = UINT_MAX; _numDrawCalls = 0; @@ -127,10 +126,10 @@ void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo // guard against RAW hazard VkMemoryBarrier vkBarrier{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; vkBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - vkBarrier.dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT; + vkBarrier.dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; vkCmdPipelineBarrier(_gpuCommandBuffer->vkCommandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + VK_PIPELINE_STAGE_VERTEX_INPUT_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 1, &vkBarrier, 0, nullptr, 0, nullptr); #endif @@ -218,8 +217,7 @@ void CCVKCommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet if (set < _firstDirtyDescriptorSet) _firstDirtyDescriptorSet = set; } if (dynamicOffsetCount) { - _curDynamicOffsetPtrs[set] = dynamicOffsets; - _curDynamicOffsetCounts[set] = dynamicOffsetCount; + _curDynamicOffsetsArray[set].assign(dynamicOffsets, dynamicOffsets + dynamicOffsetCount); if (set < _firstDirtyDescriptorSet) _firstDirtyDescriptorSet = set; } } @@ -568,8 +566,8 @@ void CCVKCommandBuffer::bindDescriptorSets(VkPipelineBindPoint bindPoint) { } uint count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsetCounts[i] >= count, "missing dynamic offsets?"); - count = std::min(count, _curDynamicOffsetCounts[i]); - if (count > 0) memcpy(&_curDynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsetPtrs[i], count * sizeof(uint)); + count = std::min(count, utils::toUint(_curDynamicOffsetsArray[i].size())); + if (count > 0) memcpy(&_curDynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsetsArray[i].data(), count * sizeof(uint)); } uint dynamicOffsetStartIndex = dynamicOffsetOffsets[_firstDirtyDescriptorSet]; diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h index a57c9e9df9..9b4c0b566d 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h @@ -77,8 +77,7 @@ protected: vector _curGPUDescriptorSets; vector _curVkDescriptorSets; vector _curDynamicOffsets; - vector _curDynamicOffsetPtrs; - vector _curDynamicOffsetCounts; + vector> _curDynamicOffsetsArray; uint _firstDirtyDescriptorSet = UINT_MAX; CCVKGPUInputAssembler *_curGPUInputAssember = nullptr; diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp index d08642b6dc..40b70d1033 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp @@ -107,6 +107,10 @@ void cmdFuncCCVKCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) { if (!gpuTexture->size) return; gpuTexture->aspectMask = mapVkImageAspectFlags(gpuTexture->format); + // storage images has to be in general layout + if (hasFlag(gpuTexture->usage, TextureUsageBit::STORAGE)) gpuTexture->flags |= TextureFlagBit::GENERAL_LAYOUT; + // remove stencil aspect for depth textures with sampled usage + if (hasFlag(gpuTexture->usage, TextureUsageBit::SAMPLED)) gpuTexture->aspectMask &= ~VK_IMAGE_ASPECT_STENCIL_BIT; VkFormat format = mapVkFormat(gpuTexture->format); VkFormatFeatureFlags features = mapVkFormatFeatureFlags(gpuTexture->usage); @@ -227,9 +231,9 @@ void cmdFuncCCVKCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) { bufferInfo.usage |= VK_BUFFER_USAGE_TRANSFER_DST_BIT; allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY; } else if (gpuBuffer->memUsage == (MemoryUsage::HOST | MemoryUsage::DEVICE)) { - gpuBuffer->instanceSize = roundUp(gpuBuffer->size, device->getCapabilities().uboOffsetAlignment); - bufferInfo.size = gpuBuffer->instanceSize * device->gpuDevice()->backBufferCount; - allocInfo.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT; + //gpuBuffer->instanceSize = roundUp(gpuBuffer->size, device->getCapabilities().uboOffsetAlignment); + //bufferInfo.size = gpuBuffer->instanceSize * device->gpuDevice()->backBufferCount; + //allocInfo.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT; allocInfo.usage = VMA_MEMORY_USAGE_CPU_TO_GPU; bufferInfo.usage |= VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT; } @@ -293,7 +297,7 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende attachmentDescriptions[i].storeOp = mapVkStoreOp(attachment.storeOp); attachmentDescriptions[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachmentDescriptions[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - attachmentDescriptions[i].initialLayout = beginAccessInfo.imageLayout; + attachmentDescriptions[i].initialLayout = attachment.loadOp == gfx::LoadOp::LOAD ? beginAccessInfo.imageLayout : VK_IMAGE_LAYOUT_UNDEFINED; attachmentDescriptions[i].finalLayout = endAccessInfo.imageLayout; } if (hasDepth) { @@ -323,7 +327,7 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende attachmentDescriptions[colorAttachmentCount].storeOp = mapVkStoreOp(depthStencilAttachment.depthStoreOp); attachmentDescriptions[colorAttachmentCount].stencilLoadOp = mapVkLoadOp(depthStencilAttachment.stencilLoadOp); attachmentDescriptions[colorAttachmentCount].stencilStoreOp = mapVkStoreOp(depthStencilAttachment.stencilStoreOp); - attachmentDescriptions[colorAttachmentCount].initialLayout = beginAccessInfo.imageLayout; + attachmentDescriptions[colorAttachmentCount].initialLayout = depthStencilAttachment.depthLoadOp == gfx::LoadOp::LOAD ? beginAccessInfo.imageLayout : VK_IMAGE_LAYOUT_UNDEFINED; attachmentDescriptions[colorAttachmentCount].finalLayout = endAccessInfo.imageLayout; } @@ -1165,7 +1169,7 @@ void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b CC_VULKAN_API void cmdFuncCCVKCopyTextureToBuffers(CCVKDevice *device, CCVKGPUTexture *srcTexture, CCVKGPUBuffer *destBuffer, const BufferTextureCopy *regions, uint count, const CCVKGPUCommandBuffer *gpuCommandBuffer) { (void)device; // fix clang-tidy error - + ThsvsImageBarrier barrier{}; barrier.image = srcTexture->vkImage; barrier.discardContents = false; @@ -1212,6 +1216,9 @@ CC_VULKAN_API void cmdFuncCCVKCopyTextureToBuffers(CCVKDevice *device, CCVKGPUTe } void cmdFuncCCVKDestroyRenderPass(CCVKGPUDevice *gpuDevice, CCVKGPURenderPass *gpuRenderPass) { + gpuRenderPass->beginAccesses.clear(); + gpuRenderPass->endAccesses.clear(); + if (gpuRenderPass->vkRenderPass != VK_NULL_HANDLE) { vkDestroyRenderPass(gpuDevice->vkDevice, gpuRenderPass->vkRenderPass, nullptr); gpuRenderPass->vkRenderPass = VK_NULL_HANDLE; diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp index f37bcac7b0..e019f8f7f6 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp @@ -108,7 +108,9 @@ void CCVKDescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { } else if (hasFlag(DESCRIPTOR_TEXTURE_TYPE, binding.descriptorType)) { instance.descriptorInfos[k].image.sampler = gpuDevice->defaultSampler.vkSampler; instance.descriptorInfos[k].image.imageView = gpuDevice->defaultTextureView.vkImageView; - instance.descriptorInfos[k].image.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + instance.descriptorInfos[k].image.imageLayout = hasFlag(binding.descriptorType, DescriptorType::STORAGE_IMAGE) + ? VK_IMAGE_LAYOUT_GENERAL + : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; } } } diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h index 2ce1b0de0b..2923abc343 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -935,6 +935,20 @@ public: } } } + // for resize events + void update(const CCVKGPUBuffer *buffer, uint oldStartOffset) { + for (const auto &it : _buffers) { + if (it.first->gpuBuffer != buffer) continue; + const auto &info = it.second; + for (uint i = 0U; i < info.descriptors.size(); i++) { + info.descriptors[i]->buffer = buffer->vkBuffer; + info.descriptors[i]->offset += buffer->startOffset - oldStartOffset; + } + for (const auto *set : info.sets) { + _descriptorSetHub->record(set); + } + } + } void disengage(const CCVKGPUBufferView *buffer) { auto it = _buffers.find(buffer); diff --git a/native/cocos/renderer/gfx-vulkan/VKUtils.h b/native/cocos/renderer/gfx-vulkan/VKUtils.h index 4b6bc4f252..76e980b029 100644 --- a/native/cocos/renderer/gfx-vulkan/VKUtils.h +++ b/native/cocos/renderer/gfx-vulkan/VKUtils.h @@ -37,7 +37,7 @@ #include "thsvs_simpler_vulkan_synchronization.h" -#define DEFAULT_TIMEOUT 1000000000 // 1 second +#define DEFAULT_TIMEOUT 10000000000 // 10 second #define BARRIER_DEDUCTION_LEVEL_NONE 0 #define BARRIER_DEDUCTION_LEVEL_BASIC 1 diff --git a/native/cocos/renderer/pipeline/Define.h b/native/cocos/renderer/pipeline/Define.h index 0b2c111ef5..8058d23f01 100644 --- a/native/cocos/renderer/pipeline/Define.h +++ b/native/cocos/renderer/pipeline/Define.h @@ -250,6 +250,7 @@ enum class CC_DLL SetIndex { MATERIAL, LOCAL, }; +CC_ENUM_CONVERSION_OPERATOR(SetIndex) extern CC_DLL uint globalSet; extern CC_DLL uint materialSet; diff --git a/native/cocos/renderer/pipeline/PipelineUBO.cpp b/native/cocos/renderer/pipeline/PipelineUBO.cpp index 9117bdc61a..3f41d1642d 100644 --- a/native/cocos/renderer/pipeline/PipelineUBO.cpp +++ b/native/cocos/renderer/pipeline/PipelineUBO.cpp @@ -70,8 +70,7 @@ void PipelineUBO::updateGlobalUBOView(const RenderPipeline * /*pipeline*/, std:: uboGlobalView[UBOGlobal::NATIVE_SIZE_OFFSET + 3] = 1.0F / uboGlobalView[UBOGlobal::NATIVE_SIZE_OFFSET + 1]; } -void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, std::array *bufferView, - const scene::Camera *camera) { +void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *output, const scene::Camera *camera) { const auto *const scene = camera->scene; const scene::DirectionalLight *mainLight = scene->getMainLight(); auto * sceneData = pipeline->getPipelineSceneData(); @@ -83,41 +82,40 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, std::array const auto isHDR = sharedData->isHDR; const auto shadingScale = sharedData->shadingScale; - auto *device = gfx::Device::getInstance(); - auto &uboCameraView = *bufferView; + auto *device = gfx::Device::getInstance(); const auto shadingWidth = std::floor(device->getWidth()); const auto shadingHeight = std::floor(device->getHeight()); - uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET + 0] = static_cast(camera->width / shadingWidth * shadingScale); - uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET + 1] = static_cast(camera->height / shadingHeight * shadingScale); - uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET + 2] = 1.0F / uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET]; - uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET + 3] = 1.0F / uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET + 1]; + output[UBOCamera::SCREEN_SCALE_OFFSET + 0] = static_cast(camera->width / shadingWidth * shadingScale); + output[UBOCamera::SCREEN_SCALE_OFFSET + 1] = static_cast(camera->height / shadingHeight * shadingScale); + output[UBOCamera::SCREEN_SCALE_OFFSET + 2] = 1.0F / output[UBOCamera::SCREEN_SCALE_OFFSET]; + output[UBOCamera::SCREEN_SCALE_OFFSET + 3] = 1.0F / output[UBOCamera::SCREEN_SCALE_OFFSET + 1]; - const auto exposure = camera->exposure; - uboCameraView[UBOCamera::EXPOSURE_OFFSET + 0] = exposure; - uboCameraView[UBOCamera::EXPOSURE_OFFSET + 1] = 1.0F / exposure; - uboCameraView[UBOCamera::EXPOSURE_OFFSET + 2] = isHDR ? 1.0F : 0.0F; - uboCameraView[UBOCamera::EXPOSURE_OFFSET + 3] = fpScale / exposure; + const auto exposure = camera->exposure; + output[UBOCamera::EXPOSURE_OFFSET + 0] = exposure; + output[UBOCamera::EXPOSURE_OFFSET + 1] = 1.0F / exposure; + output[UBOCamera::EXPOSURE_OFFSET + 2] = isHDR ? 1.0F : 0.0F; + output[UBOCamera::EXPOSURE_OFFSET + 3] = fpScale / exposure; if (mainLight) { - TO_VEC3(uboCameraView, mainLight->getDirection(), UBOCamera::MAIN_LIT_DIR_OFFSET); - TO_VEC3(uboCameraView, mainLight->getColor(), UBOCamera::MAIN_LIT_COLOR_OFFSET); + TO_VEC3(output, mainLight->getDirection(), UBOCamera::MAIN_LIT_DIR_OFFSET); + TO_VEC3(output, mainLight->getColor(), UBOCamera::MAIN_LIT_COLOR_OFFSET); if (mainLight->getUseColorTemperature()) { const auto &colorTempRGB = mainLight->getColorTemperatureRGB(); - uboCameraView[UBOCamera::MAIN_LIT_COLOR_OFFSET + 0] *= colorTempRGB.x; - uboCameraView[UBOCamera::MAIN_LIT_COLOR_OFFSET + 1] *= colorTempRGB.y; - uboCameraView[UBOCamera::MAIN_LIT_COLOR_OFFSET + 2] *= colorTempRGB.z; + output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 0] *= colorTempRGB.x; + output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 1] *= colorTempRGB.y; + output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 2] *= colorTempRGB.z; } if (isHDR) { - uboCameraView[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminance() * fpScale; + output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminance() * fpScale; } else { - uboCameraView[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminance() * exposure; + output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminance() * exposure; } } else { - TO_VEC3(uboCameraView, Vec3::UNIT_Z, UBOCamera::MAIN_LIT_DIR_OFFSET); - TO_VEC4(uboCameraView, Vec4::ZERO, UBOCamera::MAIN_LIT_COLOR_OFFSET); + TO_VEC3(output, Vec3::UNIT_Z, UBOCamera::MAIN_LIT_DIR_OFFSET); + TO_VEC4(output, Vec4::ZERO, UBOCamera::MAIN_LIT_COLOR_OFFSET); } Vec4 skyColor = ambient->skyColor; @@ -126,36 +124,36 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, std::array } else { skyColor.w = ambient->skyIllum * exposure; } - TO_VEC4(uboCameraView, skyColor, UBOCamera::AMBIENT_SKY_OFFSET); + TO_VEC4(output, skyColor, UBOCamera::AMBIENT_SKY_OFFSET); - uboCameraView[UBOCamera::AMBIENT_GROUND_OFFSET + 0] = ambient->groundAlbedo.x; - uboCameraView[UBOCamera::AMBIENT_GROUND_OFFSET + 1] = ambient->groundAlbedo.y; - uboCameraView[UBOCamera::AMBIENT_GROUND_OFFSET + 2] = ambient->groundAlbedo.z; - auto *const envmap = descriptorSet->getTexture(static_cast(PipelineGlobalBindings::SAMPLER_ENVIRONMENT)); + output[UBOCamera::AMBIENT_GROUND_OFFSET + 0] = ambient->groundAlbedo.x; + output[UBOCamera::AMBIENT_GROUND_OFFSET + 1] = ambient->groundAlbedo.y; + output[UBOCamera::AMBIENT_GROUND_OFFSET + 2] = ambient->groundAlbedo.z; + auto *const envmap = descriptorSet->getTexture(static_cast(PipelineGlobalBindings::SAMPLER_ENVIRONMENT)); if (envmap) { - uboCameraView[UBOCamera::AMBIENT_GROUND_OFFSET + 3] = static_cast(envmap->getLevelCount()); + output[UBOCamera::AMBIENT_GROUND_OFFSET + 3] = static_cast(envmap->getLevelCount()); } - memcpy(uboCameraView.data() + UBOCamera::MAT_VIEW_OFFSET, camera->matView.m, sizeof(cc::Mat4)); - memcpy(uboCameraView.data() + UBOCamera::MAT_VIEW_INV_OFFSET, camera->node->getWorldMatrix().m, sizeof(cc::Mat4)); - TO_VEC3(uboCameraView, camera->position, UBOCamera::CAMERA_POS_OFFSET); + memcpy(output + UBOCamera::MAT_VIEW_OFFSET, camera->matView.m, sizeof(cc::Mat4)); + memcpy(output + UBOCamera::MAT_VIEW_INV_OFFSET, camera->node->getWorldMatrix().m, sizeof(cc::Mat4)); + TO_VEC3(output, camera->position, UBOCamera::CAMERA_POS_OFFSET); - memcpy(uboCameraView.data() + UBOCamera::MAT_PROJ_OFFSET, camera->matProj.m, sizeof(cc::Mat4)); - memcpy(uboCameraView.data() + UBOCamera::MAT_PROJ_INV_OFFSET, camera->matProjInv.m, sizeof(cc::Mat4)); - memcpy(uboCameraView.data() + UBOCamera::MAT_VIEW_PROJ_OFFSET, camera->matViewProj.m, sizeof(cc::Mat4)); - memcpy(uboCameraView.data() + UBOCamera::MAT_VIEW_PROJ_INV_OFFSET, camera->matViewProjInv.m, sizeof(cc::Mat4)); - uboCameraView[UBOCamera::CAMERA_POS_OFFSET + 3] = getCombineSignY(); + memcpy(output + UBOCamera::MAT_PROJ_OFFSET, camera->matProj.m, sizeof(cc::Mat4)); + memcpy(output + UBOCamera::MAT_PROJ_INV_OFFSET, camera->matProjInv.m, sizeof(cc::Mat4)); + memcpy(output + UBOCamera::MAT_VIEW_PROJ_OFFSET, camera->matViewProj.m, sizeof(cc::Mat4)); + memcpy(output + UBOCamera::MAT_VIEW_PROJ_INV_OFFSET, camera->matViewProjInv.m, sizeof(cc::Mat4)); + output[UBOCamera::CAMERA_POS_OFFSET + 3] = getCombineSignY(); if (fog->enabled) { - TO_VEC4(uboCameraView, fog->color, UBOCamera::GLOBAL_FOG_COLOR_OFFSET); + TO_VEC4(output, fog->color, UBOCamera::GLOBAL_FOG_COLOR_OFFSET); - uboCameraView[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 0] = fog->start; - uboCameraView[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 1] = fog->end; - uboCameraView[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 2] = fog->density; + output[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 0] = fog->start; + output[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 1] = fog->end; + output[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 2] = fog->density; - uboCameraView[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 0] = fog->top; - uboCameraView[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 1] = fog->range; - uboCameraView[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 2] = fog->atten; + output[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 0] = fog->top; + output[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 1] = fog->range; + output[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 2] = fog->atten; } } @@ -173,7 +171,7 @@ void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, std::array if (shadowInfo->enabled) { if (mainLight && shadowInfo->shadowType == scene::ShadowType::SHADOWMAP) { auto *const node = mainLight->getNode(); - cc::Mat4 matShadowCamera; + cc::Mat4 matShadowCamera; // light proj float x; @@ -206,15 +204,15 @@ void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, std::array matShadowViewProj.multiply(matShadowView); memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_VIEW_PROJ_OFFSET, matShadowViewProj.m, sizeof(matShadowViewProj)); - const float linear = hFTexture ? 1.0F : 0.0F; - float shadowNFLSInfos[4] = {shadowInfo->nearValue, farClamp, linear, 1.0F - shadowInfo->saturation}; + const float linear = hFTexture ? 1.0F : 0.0F; + float shadowNFLSInfos[4] = {shadowInfo->nearValue, farClamp, linear, 1.0F - shadowInfo->saturation}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_NEAR_FAR_LINEAR_SATURATION_INFO_OFFSET, &shadowNFLSInfos, sizeof(shadowNFLSInfos)); float shadowWHPBInfos[4] = {shadowInfo->size.x, shadowInfo->size.y, static_cast(shadowInfo->pcfType), shadowInfo->bias}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_WIDTH_HEIGHT_PCF_BIAS_INFO_OFFSET, &shadowWHPBInfos, sizeof(shadowWHPBInfos)); - const float packing = hFTexture ? 0.0F : 1.0F; - float shadowLPNNInfos[4] = {0.0F, packing, shadowInfo->normalBias, 0.0F}; + const float packing = hFTexture ? 0.0F : 1.0F; + float shadowLPNNInfos[4] = {0.0F, packing, shadowInfo->normalBias, 0.0F}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET, &shadowLPNNInfos, sizeof(shadowLPNNInfos)); } else if (mainLight && shadowInfo->shadowType == scene::ShadowType::PLANAR) { updateDirLight(shadowInfo, mainLight, &shadowUBO); @@ -226,14 +224,14 @@ void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, std::array } void PipelineUBO::updateShadowUBOLightView(const RenderPipeline *pipeline, std::array *bufferView, const scene::Light *light) { - auto *const sceneData = pipeline->getPipelineSceneData(); - auto * shadowInfo = sceneData->getSharedData()->shadow; - auto * device = gfx::Device::getInstance(); - auto * sphere = sceneData->getSphere(); - auto & shadowUBO = *bufferView; - const bool hFTexture = supportsHalfFloatTexture(device); - const float linear = hFTexture ? 1.0F : 0.0F; - const float packing = hFTexture ? 0.0F : 1.0F; + auto *const sceneData = pipeline->getPipelineSceneData(); + auto * shadowInfo = sceneData->getSharedData()->shadow; + auto * device = gfx::Device::getInstance(); + auto * sphere = sceneData->getSphere(); + auto & shadowUBO = *bufferView; + const bool hFTexture = supportsHalfFloatTexture(device); + const float linear = hFTexture ? 1.0F : 0.0F; + const float packing = hFTexture ? 0.0F : 1.0F; switch (light->getType()) { case scene::LightType::DIRECTIONAL: { const auto *directionalLight = static_cast(light); @@ -330,12 +328,21 @@ void PipelineUBO::activate(gfx::Device *device, RenderPipeline *pipeline) { descriptorSet->bindBuffer(UBOGlobal::BINDING, globalUBO); _ubos.push_back(globalUBO); - auto *cameraUBO = _device->createBuffer({ + _alignedCameraUBOSize = utils::alignTo(UBOCamera::SIZE, _device->getCapabilities().uboOffsetAlignment); + + _cameraBuffer = _device->createBuffer({ gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST, gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, + _alignedCameraUBOSize, + _alignedCameraUBOSize, + }); + _ubos.push_back(_cameraBuffer); + _cameraUBOs.resize(_alignedCameraUBOSize / sizeof(float)); + + auto *cameraUBO = _device->createBuffer({ + _cameraBuffer, + 0, UBOCamera::SIZE, - UBOCamera::SIZE, - gfx::BufferFlagBit::NONE, }); descriptorSet->bindBuffer(UBOCamera::BINDING, cameraUBO); _ubos.push_back(cameraUBO); @@ -373,37 +380,29 @@ void PipelineUBO::updateCameraUBO(const scene::Camera *camera) { auto *const globalDSManager = _pipeline->getGlobalDSManager(); auto *const ds = _pipeline->getDescriptorSet(); auto *const cmdBuffer = _pipeline->getCommandBuffers()[0]; - PipelineUBO::updateCameraUBOView(_pipeline, &_cameraUBO, camera); - cmdBuffer->updateBuffer(ds->getBuffer(UBOCamera::BINDING), _cameraUBO.data(), UBOCamera::SIZE); - - globalDSManager->bindBuffer(UBOCamera::BINDING, ds->getBuffer(UBOCamera::BINDING)); - globalDSManager->update(); + PipelineUBO::updateCameraUBOView(_pipeline, _cameraUBOs.data(), camera); + cmdBuffer->updateBuffer(_cameraBuffer, _cameraUBOs.data()); } void PipelineUBO::updateMultiCameraUBO(const vector &cameras) { auto *const ds = _pipeline->getDescriptorSet(); auto * device = _pipeline->getDevice(); - auto uboAlignment = device->getCapabilities().uboOffsetAlignment; - _alignedCameraUBOSize = static_cast(std::ceil(UBOCamera::SIZE / static_cast(uboAlignment))) * uboAlignment; - auto cameraCount = cameras.size(); - auto totalUboSize = static_cast(_alignedCameraUBOSize * cameraCount); + auto cameraCount = cameras.size(); + auto totalUboSize = static_cast(_alignedCameraUBOSize * cameraCount); + + if (_cameraBuffer->getSize() < totalUboSize) { + _cameraBuffer->resize(totalUboSize); + _cameraUBOs.resize(totalUboSize / sizeof(float)); + } - _cameraUBOs.resize(totalUboSize); - _currentCameraUBOOffset = 0; for (uint cameraIdx = 0; cameraIdx < cameraCount; ++cameraIdx) { auto *camera = cameras[cameraIdx]; - PipelineUBO::updateCameraUBOView(_pipeline, &_cameraUBO, camera); - auto offset = cameraIdx * _alignedCameraUBOSize; - memcpy(&_cameraUBOs[offset], _cameraUBO.data(), UBOCamera::SIZE); + auto offset = cameraIdx * _alignedCameraUBOSize / sizeof(float); + PipelineUBO::updateCameraUBOView(_pipeline, &_cameraUBOs[offset], camera); } - auto *uboBuffer = ds->getBuffer(UBOCamera::BINDING); - if (uboBuffer->getSize() < totalUboSize) { - uboBuffer->resize(totalUboSize); - } - uboBuffer->update(_cameraUBOs.data(), totalUboSize); + _cameraBuffer->update(_cameraUBOs.data()); - ds->bindBuffer(UBOCamera::BINDING, uboBuffer); - ds->update(); + _currentCameraUBOOffset = 0; } void PipelineUBO::updateShadowUBO(const scene::Camera *camera) { diff --git a/native/cocos/renderer/pipeline/PipelineUBO.h b/native/cocos/renderer/pipeline/PipelineUBO.h index 96dc57352b..4119e67b2a 100644 --- a/native/cocos/renderer/pipeline/PipelineUBO.h +++ b/native/cocos/renderer/pipeline/PipelineUBO.h @@ -41,7 +41,7 @@ class RenderPipeline; class CC_DLL PipelineUBO : public Object { public: static void updateGlobalUBOView(const RenderPipeline *pipeline, std::array *bufferView); - static void updateCameraUBOView(const RenderPipeline *pipeline, std::array *bufferView, const scene::Camera *camera); + static void updateCameraUBOView(const RenderPipeline *pipeline, float *output, const scene::Camera *camera); static void updateShadowUBOView(const RenderPipeline *pipeline, std::array *bufferView, const scene::Camera *camera); static void updateShadowUBOLightView(const RenderPipeline *pipeline, std::array *bufferView, const scene::Light *light); static uint8_t getCombineSignY(); @@ -52,11 +52,10 @@ public: void destroy(); void updateGlobalUBO(); void updateCameraUBO(const scene::Camera *camera); - void updateMultiCameraUBO(const vector &cameras); + void updateMultiCameraUBO(const vector &cameras); void updateShadowUBO(const scene::Camera *camera); void updateShadowUBOLight(const scene::Light *light); void updateShadowUBORange(uint offset, const Mat4 *data); - void destroyShadowFrameBuffers(); uint getCurrentCameraUBOOffset() const; void incCameraUBOOffset(); @@ -66,12 +65,12 @@ private: gfx::Device * _device = nullptr; std::array _globalUBO; - std::array _cameraUBO; std::array _shadowUBO; std::vector _ubos; void initCombineSignY(); - std::vector _cameraUBOs; + std::vector _cameraUBOs; + gfx::Buffer * _cameraBuffer{nullptr}; uint _currentCameraUBOOffset{0}; uint _alignedCameraUBOSize{0}; }; diff --git a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp index d88a7aadbd..5429bd7a01 100644 --- a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp +++ b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp @@ -71,15 +71,15 @@ gfx::RenderPass *DeferredPipeline::getOrCreateRenderPass(gfx::ClearFlags clearFl colorAttachment.loadOp = gfx::LoadOp::DISCARD; } else { colorAttachment.loadOp = gfx::LoadOp::LOAD; - colorAttachment.beginAccesses = {gfx::AccessType::PRESENT}; + colorAttachment.beginAccesses = {gfx::AccessType::COLOR_ATTACHMENT_WRITE}; } } if (static_cast(clearFlags & gfx::ClearFlagBit::DEPTH_STENCIL) != gfx::ClearFlagBit::DEPTH_STENCIL) { if (!hasFlag(clearFlags, gfx::ClearFlagBit::DEPTH)) depthStencilAttachment.depthLoadOp = gfx::LoadOp::LOAD; if (!hasFlag(clearFlags, gfx::ClearFlagBit::STENCIL)) depthStencilAttachment.stencilLoadOp = gfx::LoadOp::LOAD; - depthStencilAttachment.beginAccesses = {gfx::AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE}; } + depthStencilAttachment.beginAccesses = {gfx::AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE}; auto *renderPass = device->createRenderPass({ {colorAttachment}, @@ -127,6 +127,8 @@ bool DeferredPipeline::activate() { } void DeferredPipeline::render(const vector &cameras) { + static gfx::TextureBarrier *present{_device->createTextureBarrier({{gfx::AccessType::COLOR_ATTACHMENT_WRITE}, {gfx::AccessType::PRESENT}})}; + static gfx::Texture * backBuffer{nullptr}; _commandBuffers[0]->begin(); _pipelineUBO->updateGlobalUBO(); _pipelineUBO->updateMultiCameraUBO(cameras); @@ -137,6 +139,7 @@ void DeferredPipeline::render(const vector &cameras) { } _pipelineUBO->incCameraUBOOffset(); } + _commandBuffers[0]->pipelineBarrier(nullptr, &present, &backBuffer, 1); _commandBuffers[0]->end(); _device->flushCommands(_commandBuffers); _device->getQueue()->submit(_commandBuffers); @@ -154,10 +157,12 @@ void DeferredPipeline::updateQuadVertexData(const gfx::Rect &renderArea) { } void DeferredPipeline::genQuadVertexData(gfx::SurfaceTransform /*surfaceTransform*/, const gfx::Rect &renderArea, float *vbData) { - float minX = float(renderArea.x) / _width; - float maxX = float(renderArea.x + renderArea.width) / _width; - float minY = float(renderArea.y) / _height; - float maxY = float(renderArea.y + renderArea.height) / _height; + auto width = float(_width); + auto height = float(_height); + auto minX = float(renderArea.x) / width; + auto maxX = float(renderArea.x + renderArea.width) / width; + auto minY = float(renderArea.y) / height; + auto maxY = float(renderArea.y + renderArea.height) / height; if (_device->getCapabilities().screenSpaceSignY > 0) { std::swap(minY, maxY); } @@ -290,8 +295,8 @@ bool DeferredPipeline::activeRenderer() { gfx::SampleCount::X1, gfx::LoadOp::CLEAR, gfx::StoreOp::STORE, - {}, - {gfx::AccessType::COLOR_ATTACHMENT_WRITE}, + {gfx::AccessType::FRAGMENT_SHADER_READ_TEXTURE}, + {gfx::AccessType::FRAGMENT_SHADER_READ_TEXTURE}, }; for (int i = 0; i < 4; i++) { @@ -305,6 +310,8 @@ bool DeferredPipeline::activeRenderer() { gfx::StoreOp::STORE, gfx::LoadOp::CLEAR, gfx::StoreOp::STORE, + {gfx::AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE}, + {gfx::AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE} }; gbufferPass.depthStencilAttachment = depth; diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index d1d814ecc2..6bc9266dfc 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -33,11 +33,13 @@ #include "../RenderQueue.h" #include "DeferredPipeline.h" #include "LightingFlow.h" +#include "base/Utils.h" #include "gfx-base/GFXCommandBuffer.h" #include "gfx-base/GFXDescriptorSet.h" #include "gfx-base/GFXDevice.h" #include "gfx-base/GFXFramebuffer.h" #include "gfx-base/GFXQueue.h" +#include "pipeline/Define.h" #include "scene/RenderScene.h" #include "scene/Sphere.h" #include "scene/SphereLight.h" @@ -220,8 +222,8 @@ void LightingStage::initLightingBuffer() { auto *const device = _pipeline->getDevice(); // color/pos/dir/angle 都是vec4存储, 最后一个vec4只要x存储光源个数 - uint totalSize = sizeof(Vec4) * 4 * _maxDeferredLights; - totalSize = static_cast(std::ceil(static_cast(totalSize) / device->getCapabilities().uboOffsetAlignment) * device->getCapabilities().uboOffsetAlignment); + uint stride = utils::alignTo(sizeof(Vec4) * 4, device->getCapabilities().uboOffsetAlignment); + uint totalSize = stride * _maxDeferredLights; // create lighting buffer and view if (_deferredLitsBufs == nullptr) { @@ -229,7 +231,7 @@ void LightingStage::initLightingBuffer() { gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST, gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, totalSize, - static_cast(device->getCapabilities().uboOffsetAlignment), + stride, }; _deferredLitsBufs = device->createBuffer(bfInfo); assert(_deferredLitsBufs != nullptr); @@ -327,7 +329,7 @@ void LightingStage::render(scene::Camera *camera) { _descriptorSet->update(); vector dynamicOffsets = {0}; - cmdBuff->bindDescriptorSet(static_cast(SetIndex::LOCAL), _descriptorSet, dynamicOffsets); + cmdBuff->bindDescriptorSet(localSet, _descriptorSet, dynamicOffsets); // draw quad gfx::Rect renderArea = pipeline->getRenderArea(camera, false); @@ -355,7 +357,7 @@ void LightingStage::render(scene::Camera *camera) { camera->clearDepth, camera->clearStencil); uint const globalOffsets[] = {_pipeline->getPipelineUBO()->getCurrentCameraUBOOffset()}; - cmdBuff->bindDescriptorSet(static_cast(SetIndex::GLOBAL), pipeline->getDescriptorSet(), static_cast(std::size(globalOffsets)), globalOffsets); + cmdBuff->bindDescriptorSet(globalSet, pipeline->getDescriptorSet(), static_cast(std::size(globalOffsets)), globalOffsets); // get pso and draw quad scene::Pass *pass = sceneData->getSharedData()->deferredLightPass; gfx::Shader *shader = sceneData->getSharedData()->deferredLightPassShader; @@ -367,6 +369,7 @@ void LightingStage::render(scene::Camera *camera) { cmdBuff->bindPipelineState(pState); cmdBuff->bindInputAssembler(inputAssembler); + cmdBuff->bindDescriptorSet(materialSet, pass->getDescriptorSet()); cmdBuff->draw(inputAssembler); // transparent @@ -424,16 +427,16 @@ void LightingStage::render(scene::Camera *camera) { cmdBuff->pipelineBarrier(_reflectionComp->getBarrierPre()); cmdBuff->bindPipelineState(const_cast(_reflectionComp->getPipelineState())); - cmdBuff->bindDescriptorSet(0, const_cast(_reflectionComp->getDescriptorSet())); - cmdBuff->bindDescriptorSet(1, subModel->getDescriptorSet()); + cmdBuff->bindDescriptorSet(globalSet, const_cast(_reflectionComp->getDescriptorSet())); + cmdBuff->bindDescriptorSet(materialSet, subModel->getDescriptorSet()); cmdBuff->dispatch(_reflectionComp->getDispatchInfo()); cmdBuff->pipelineBarrier(nullptr, const_cast(_reflectionComp->getBarrierBeforeDenoise()), {const_cast(_reflectionComp->getReflectionTex()), denoiseTex}); cmdBuff->bindPipelineState(const_cast(_reflectionComp->getDenoisePipelineState())); - cmdBuff->bindDescriptorSet(0, const_cast(_reflectionComp->getDenoiseDescriptorSet())); - cmdBuff->bindDescriptorSet(1, subModel->getDescriptorSet()); + cmdBuff->bindDescriptorSet(globalSet, const_cast(_reflectionComp->getDenoiseDescriptorSet())); + cmdBuff->bindDescriptorSet(materialSet, subModel->getDescriptorSet()); cmdBuff->dispatch(_reflectionComp->getDenioseDispatchInfo()); cmdBuff->pipelineBarrier(nullptr, _reflectionComp->getBarrierAfterDenoise(), {denoiseTex}); } @@ -444,7 +447,7 @@ void LightingStage::render(scene::Camera *camera) { cmdBuff->beginRenderPass(_reflectionPass, frameBuffer, renderArea, &clearColor, camera->clearDepth, camera->clearStencil); - cmdBuff->bindDescriptorSet(static_cast(SetIndex::GLOBAL), pipeline->getDescriptorSet()); + cmdBuff->bindDescriptorSet(globalSet, pipeline->getDescriptorSet()); // reflection _reflectionRenderQueue->clear(); diff --git a/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp b/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp index b258eef14e..9cd14cf472 100644 --- a/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp @@ -31,6 +31,7 @@ #include "gfx-base/GFXCommandBuffer.h" #include "gfx-base/GFXDevice.h" #include "gfx-base/GFXFramebuffer.h" +#include "pipeline/Define.h" #include "scene/SubModel.h" namespace cc { @@ -103,7 +104,7 @@ void PostprocessStage::render(scene::Camera *camera) { cmdBf->beginRenderPass(rp, fb, renderArea, _clearColors, camera->clearDepth, camera->clearStencil); uint const globalOffsets[] = {_pipeline->getPipelineUBO()->getCurrentCameraUBOOffset()}; - cmdBf->bindDescriptorSet(static_cast(SetIndex::GLOBAL), pp->getDescriptorSet(), static_cast(std::size(globalOffsets)), globalOffsets); + cmdBf->bindDescriptorSet(globalSet, pp->getDescriptorSet(), static_cast(std::size(globalOffsets)), globalOffsets); // post proces auto *const sceneData = _pipeline->getPipelineSceneData(); @@ -118,6 +119,7 @@ void PostprocessStage::render(scene::Camera *camera) { cmdBf->bindPipelineState(pso); cmdBf->bindInputAssembler(ia); + cmdBf->bindDescriptorSet(materialSet, pv->getDescriptorSet()); cmdBf->draw(ia); } diff --git a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp index 3faa4c4313..161fb29791 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp @@ -70,7 +70,7 @@ gfx::RenderPass *ForwardPipeline::getOrCreateRenderPass(gfx::ClearFlags clearFla colorAttachment.loadOp = gfx::LoadOp::DISCARD; } else { colorAttachment.loadOp = gfx::LoadOp::LOAD; - colorAttachment.beginAccesses = {gfx::AccessType::PRESENT}; + colorAttachment.beginAccesses = {gfx::AccessType::COLOR_ATTACHMENT_WRITE}; } } @@ -122,6 +122,8 @@ bool ForwardPipeline::activate() { } void ForwardPipeline::render(const vector &cameras) { + static gfx::TextureBarrier *present{_device->createTextureBarrier({{gfx::AccessType::COLOR_ATTACHMENT_WRITE}, {gfx::AccessType::PRESENT}})}; + static gfx::Texture * backBuffer{nullptr}; _commandBuffers[0]->begin(); _pipelineUBO->updateGlobalUBO(); _pipelineUBO->updateMultiCameraUBO(cameras); @@ -132,6 +134,7 @@ void ForwardPipeline::render(const vector &cameras) { } _pipelineUBO->incCameraUBOOffset(); } + _commandBuffers[0]->pipelineBarrier(nullptr, &present, &backBuffer, 1); _commandBuffers[0]->end(); _device->flushCommands(_commandBuffers); _device->getQueue()->submit(_commandBuffers); diff --git a/native/cocos/scene/SubModel.cpp b/native/cocos/scene/SubModel.cpp index a2619de2c3..19ecddad28 100644 --- a/native/cocos/scene/SubModel.cpp +++ b/native/cocos/scene/SubModel.cpp @@ -1,8 +1,8 @@ /**************************************************************************** Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. - + http://www.cocos.com - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated engine source code (the "Software"), a limited, worldwide, royalty-free, non-assignable, revocable and non-exclusive license @@ -10,10 +10,10 @@ not use Cocos Creator software for developing other software or tools that's used for developing games. You are not granted to publish, distribute, sublicense, and/or sell copies of Cocos Creator. - + The software or tools in this License Agreement are licensed, not sold. Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -39,16 +39,16 @@ SubModel::~SubModel() { delete _subMesh; } -gfx::Shader *SubModel::getShader(int index) const { - if (index >= static_cast(_shaders.size())) { +gfx::Shader *SubModel::getShader(uint index) const { + if (index >= _shaders.size()) { return nullptr; } return _shaders[index]; } -Pass *SubModel::getPass(int index) const { - if (index >= static_cast(_passes.size())) { +Pass *SubModel::getPass(uint index) const { + if (index >= _passes.size()) { return nullptr; } diff --git a/native/cocos/scene/SubModel.h b/native/cocos/scene/SubModel.h index ccc3423bad..2b95d927f5 100644 --- a/native/cocos/scene/SubModel.h +++ b/native/cocos/scene/SubModel.h @@ -1,8 +1,8 @@ /**************************************************************************** Copyright (c) 2021 Xiamen Yaji Software Co., Ltd. - + http://www.cocos.com - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated engine source code (the "Software"), a limited, worldwide, royalty-free, non-assignable, revocable and non-exclusive license @@ -10,10 +10,10 @@ not use Cocos Creator software for developing other software or tools that's used for developing games. You are not granted to publish, distribute, sublicense, and/or sell copies of Cocos Creator. - + The software or tools in this License Agreement are licensed, not sold. Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -47,8 +47,8 @@ public: void update(); - gfx::Shader *getShader(int) const; - Pass * getPass(int) const; + gfx::Shader *getShader(uint) const; + Pass * getPass(uint) const; inline void setShaders(const std::vector &shaders) { _shaders = shaders; } inline void setPasses(const std::vector &passes) { _passes = passes; } diff --git a/native/cocos/ui/edit-box/EditBox-win32.cpp b/native/cocos/ui/edit-box/EditBox-win32.cpp index 2e1784b7bf..fe415544eb 100644 --- a/native/cocos/ui/edit-box/EditBox-win32.cpp +++ b/native/cocos/ui/edit-box/EditBox-win32.cpp @@ -205,8 +205,8 @@ void EditBox::show(const EditBox::ShowInfo &showInfo) { void EditBox::hide() { DestroyWindow(g_hwndEditBox); - SetWindowLongPtr(cc_get_application_view()->getWindowHandler(), GWL_WNDPROC, (LONG_PTR)g_prevMainWindowProc); - SetWindowLongPtr(g_hwndEditBox, GWL_WNDPROC, (LONG_PTR)g_prevEditWindowProc); + SetWindowLongPtr(cc_get_application_view()->getWindowHandler(), GWLP_WNDPROC, (LONG_PTR)g_prevMainWindowProc); + SetWindowLongPtr(g_hwndEditBox, GWLP_WNDPROC, (LONG_PTR)g_prevEditWindowProc); g_hwndEditBox = nullptr; } From c9ed0a456e648a0167f68a592570f67ee22bee30 Mon Sep 17 00:00:00 2001 From: Cocos Robot <48829427+cocos-robot@users.noreply.github.com> Date: Tue, 10 Aug 2021 10:20:13 +0800 Subject: [PATCH 13/21] [ci skip][AUTO]: updating jsbinding automatically: 2056271b (#3813) Co-authored-by: cocos-robot --- native/cocos/bindings/auto/jsb_gfx_auto.cpp | 20 +++++++++++++++++++ native/cocos/bindings/auto/jsb_gfx_auto.h | 1 + native/cocos/bindings/auto/jsb_scene_auto.cpp | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/native/cocos/bindings/auto/jsb_gfx_auto.cpp b/native/cocos/bindings/auto/jsb_gfx_auto.cpp index 6056ac1949..dc634bd3c4 100644 --- a/native/cocos/bindings/auto/jsb_gfx_auto.cpp +++ b/native/cocos/bindings/auto/jsb_gfx_auto.cpp @@ -16019,6 +16019,25 @@ static bool js_gfx_Buffer_getUsage(se::State& s) // NOLINT(readability-identifie } SE_BIND_PROP_GET(js_gfx_Buffer_getUsage) +static bool js_gfx_Buffer_isBufferView(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_isBufferView : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + bool result = cobj->isBufferView(); + ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); + SE_PRECONDITION2(ok, false, "js_gfx_Buffer_isBufferView : Error processing arguments"); + SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_FUNC(js_gfx_Buffer_isBufferView) + static bool js_gfx_Buffer_resize(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); @@ -16094,6 +16113,7 @@ bool js_register_gfx_Buffer(se::Object* obj) // NOLINT(readability-identifier-na cls->defineProperty("usage", _SE(js_gfx_Buffer_getUsage), nullptr); cls->defineProperty("size", _SE(js_gfx_Buffer_getSize), nullptr); cls->defineFunction("destroy", _SE(js_gfx_Buffer_destroy)); + cls->defineFunction("isBufferView", _SE(js_gfx_Buffer_isBufferView)); cls->defineFunction("resize", _SE(js_gfx_Buffer_resize)); cls->defineStaticFunction("computeHash", _SE(js_gfx_Buffer_computeHash)); cls->defineFinalizeFunction(_SE(js_cc_gfx_Buffer_finalize)); diff --git a/native/cocos/bindings/auto/jsb_gfx_auto.h b/native/cocos/bindings/auto/jsb_gfx_auto.h index 7a7329e7bf..ab578c3db1 100644 --- a/native/cocos/bindings/auto/jsb_gfx_auto.h +++ b/native/cocos/bindings/auto/jsb_gfx_auto.h @@ -583,6 +583,7 @@ bool register_all_gfx(se::Object* obj); JSB_REGISTER_OBJECT_TYPE(cc::gfx::Buffer); SE_DECLARE_FUNC(js_gfx_Buffer_destroy); +SE_DECLARE_FUNC(js_gfx_Buffer_isBufferView); SE_DECLARE_FUNC(js_gfx_Buffer_resize); SE_DECLARE_FUNC(js_gfx_Buffer_computeHash); SE_DECLARE_FUNC(js_gfx_Buffer_Buffer); diff --git a/native/cocos/bindings/auto/jsb_scene_auto.cpp b/native/cocos/bindings/auto/jsb_scene_auto.cpp index cb58562004..2bd56ebea6 100644 --- a/native/cocos/bindings/auto/jsb_scene_auto.cpp +++ b/native/cocos/bindings/auto/jsb_scene_auto.cpp @@ -4130,7 +4130,7 @@ static bool js_scene_SubModel_getPass(se::State& s) // NOLINT(readability-identi size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - HolderType arg0 = {}; + HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_scene_SubModel_getPass : Error processing arguments"); cc::scene::Pass* result = cobj->getPass(arg0.value()); @@ -4228,7 +4228,7 @@ static bool js_scene_SubModel_getShader(se::State& s) // NOLINT(readability-iden size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 1) { - HolderType arg0 = {}; + HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_scene_SubModel_getShader : Error processing arguments"); cc::gfx::Shader* result = cobj->getShader(arg0.value()); From 8fa3d5b8d6bbf5cdf164b2117432f9e46bde367f Mon Sep 17 00:00:00 2001 From: timlyeee <43355299+timlyeee@users.noreply.github.com> Date: Tue, 10 Aug 2021 13:52:02 +0800 Subject: [PATCH 14/21] Fix simulator restart issue (#3814) * Fix simulator restart issue * fix conversion error --- native/cocos/renderer/gfx-vulkan/VKBuffer.cpp | 2 +- native/cocos/renderer/gfx-vulkan/VKGPUObjects.h | 2 +- .../frameworks/runtime-src/proj.win32/SimulatorWin.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp index bdd1aa1e40..4f1f3666e0 100644 --- a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp @@ -94,7 +94,7 @@ void CCVKBuffer::doDestroy() { } void CCVKBuffer::doResize(uint size, uint count) { - uint oldStartOffset = _gpuBuffer->startOffset; + VkDeviceSize oldStartOffset = _gpuBuffer->startOffset; CCVKDevice::getInstance()->getMemoryStatus().bufferSize -= _size; CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuBuffer); diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h index 2923abc343..9144f03271 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -936,7 +936,7 @@ public: } } // for resize events - void update(const CCVKGPUBuffer *buffer, uint oldStartOffset) { + void update(const CCVKGPUBuffer *buffer, VkDeviceSize oldStartOffset) { for (const auto &it : _buffers) { if (it.first->gpuBuffer != buffer) continue; const auto &info = it.second; diff --git a/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorWin.cpp b/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorWin.cpp index 8e09e1e2c3..4a4df0e3c1 100755 --- a/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorWin.cpp +++ b/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorWin.cpp @@ -520,7 +520,7 @@ int SimulatorWin::run() updateWindowTitle(); bool resume, pause, close; - se::ScriptEngine::getInstance()->addRegisterCallback(setCanvasCallback); + se::ScriptEngine::getInstance()->addPermanentRegisterCallback(setCanvasCallback); if (!_app->init()) return 1; _quit = false; From 4412d9d408df308db36ebd18b95341f37bc6f3fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=88=98?= <40414978+PatriceJiang@users.noreply.github.com> Date: Wed, 11 Aug 2021 08:42:47 +0800 Subject: [PATCH 15/21] revert android dbg pkg name (#3816) --- native/templates/android/template/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/templates/android/template/app/build.gradle b/native/templates/android/template/app/build.gradle index 6c274a9c70..2f524c4a9b 100644 --- a/native/templates/android/template/app/build.gradle +++ b/native/templates/android/template/app/build.gradle @@ -83,7 +83,7 @@ android { jniDebuggable true renderscriptDebuggable true resValue "string", "cc_app_name", "${PROP_APP_NAME}-dbg" - applicationIdSuffix ".debug" + // applicationIdSuffix ".debug" } } } From be243c06314601cda3bfd3b7200b2e66eb3eb339 Mon Sep 17 00:00:00 2001 From: Zeqiang Li Date: Wed, 11 Aug 2021 18:11:12 +0800 Subject: [PATCH 16/21] fix metal crash (#3817) --- native/cocos/renderer/gfx-metal/MTLBuffer.h | 9 ++-- native/cocos/renderer/gfx-metal/MTLBuffer.mm | 56 +++++++++++++------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/native/cocos/renderer/gfx-metal/MTLBuffer.h b/native/cocos/renderer/gfx-metal/MTLBuffer.h index 2c2dd8e646..ac1159d420 100644 --- a/native/cocos/renderer/gfx-metal/MTLBuffer.h +++ b/native/cocos/renderer/gfx-metal/MTLBuffer.h @@ -34,8 +34,8 @@ namespace cc { namespace gfx { -class CCMTLBuffer; class CCMTLCommandEncoder; +class CCMTLGPUBuffer; class CCMTLBuffer final : public Buffer { public: @@ -50,7 +50,9 @@ public: void encodeBuffer(CCMTLCommandEncoder &encoder, uint offset, uint binding, ShaderStageFlags stages); - inline id getMTLBuffer() const { return _mtlBuffer; } + id getMTLBuffer() const; + + inline CCMTLGPUBuffer* gpuBuffer() { return _gpuBuffer; } inline MTLIndexType getIndexType() const { return _indexType; } inline bool isDrawIndirectByIndex() const { return _isDrawIndirectByIndex; } inline const DrawInfoList &getDrawInfos() const { return _drawInfos; } @@ -64,7 +66,6 @@ protected: bool createMTLBuffer(uint size, MemoryUsage usage); void updateMTLBuffer(const void *buffer, uint offset, uint size); - id _mtlBuffer = nullptr; MTLIndexType _indexType = MTLIndexTypeUInt16; MTLResourceOptions _mtlResourceOptions = MTLResourceStorageModePrivate; bool _isIndirectDrawSupported = false; @@ -74,6 +75,8 @@ protected: vector _indexedPrimitivesIndirectArguments; vector _primitiveIndirectArguments; DrawInfoList _drawInfos; + + CCMTLGPUBuffer* _gpuBuffer = nullptr; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-metal/MTLBuffer.mm b/native/cocos/renderer/gfx-metal/MTLBuffer.mm index 5ade9fe4f2..313fff7e35 100644 --- a/native/cocos/renderer/gfx-metal/MTLBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLBuffer.mm @@ -33,6 +33,7 @@ #include "MTLDevice.h" #include "MTLRenderCommandEncoder.h" #include "MTLUtils.h" +#include "MTLGPUObjects.h" namespace cc { namespace gfx { @@ -46,6 +47,13 @@ CCMTLBuffer::~CCMTLBuffer() { } void CCMTLBuffer::doInit(const BufferInfo &info) { + _gpuBuffer = CC_NEW(CCMTLGPUBuffer); + _gpuBuffer->count = _count; + _gpuBuffer->mappedData = nullptr; + _gpuBuffer->size = _size; + _gpuBuffer->startOffset = _offset; + _gpuBuffer->stride = _stride; + _isIndirectDrawSupported = CCMTLDevice::getInstance()->isIndirectDrawSupported(); if (hasFlag(_usage, BufferUsage::INDEX)) { switch (_stride) { @@ -75,7 +83,7 @@ void CCMTLBuffer::doInit(const BufferInfo &info) { void CCMTLBuffer::doInit(const BufferViewInfo &info) { auto* ccBuffer = static_cast(info.buffer); - _mtlBuffer = ccBuffer->getMTLBuffer(); + _gpuBuffer = ccBuffer->gpuBuffer(); _indexType = ccBuffer->getIndexType(); _mtlResourceOptions = ccBuffer->_mtlResourceOptions; _isIndirectDrawSupported = ccBuffer->_isIndirectDrawSupported; @@ -90,8 +98,8 @@ void CCMTLBuffer::doInit(const BufferViewInfo &info) { bool CCMTLBuffer::createMTLBuffer(uint size, MemoryUsage usage) { _mtlResourceOptions = mu::toMTLResourceOption(usage); - if (_mtlBuffer) { - id mtlBuffer = _mtlBuffer; + if (_gpuBuffer->mtlBuffer) { + id mtlBuffer = _gpuBuffer->mtlBuffer; std::function destroyFunc = [=]() { if (mtlBuffer) { @@ -104,8 +112,8 @@ bool CCMTLBuffer::createMTLBuffer(uint size, MemoryUsage usage) { } id mtlDevice = id(CCMTLDevice::getInstance()->getMTLDevice()); - _mtlBuffer = [mtlDevice newBufferWithLength:size options:_mtlResourceOptions]; - if (_mtlBuffer == nil) { + _gpuBuffer->mtlBuffer = [mtlDevice newBufferWithLength:size options:_mtlResourceOptions]; + if (_gpuBuffer->mtlBuffer == nil) { return false; } return true; @@ -130,17 +138,21 @@ void CCMTLBuffer::doDestroy() { _drawInfos.clear(); } - id mtlBuffer = _mtlBuffer; - _mtlBuffer = nil; + if(_gpuBuffer) { + id mtlBuffer = _gpuBuffer->mtlBuffer; + _gpuBuffer->mtlBuffer = nil; - std::function destroyFunc = [=]() { - if (mtlBuffer) { - [mtlBuffer setPurgeableState:MTLPurgeableStateEmpty]; - [mtlBuffer release]; - } - }; - //gpu object only - CCMTLGPUGarbageCollectionPool::getInstance()->collect(destroyFunc); + std::function destroyFunc = [=]() { + if (mtlBuffer) { + [mtlBuffer setPurgeableState:MTLPurgeableStateEmpty]; + [mtlBuffer release]; + } + }; + //gpu object only + CCMTLGPUGarbageCollectionPool::getInstance()->collect(destroyFunc); + } + + CC_SAFE_DELETE(_gpuBuffer); } void CCMTLBuffer::doResize(uint size, uint count) { @@ -221,13 +233,13 @@ void CCMTLBuffer::update(const void *buffer, uint size) { } void CCMTLBuffer::updateMTLBuffer(const void *buffer, uint /*offset*/, uint size) { - if (_mtlBuffer) { + if (_gpuBuffer->mtlBuffer) { CommandBuffer *cmdBuffer = CCMTLDevice::getInstance()->getCommandBuffer(); cmdBuffer->begin(); static_cast(cmdBuffer)->updateBuffer(this, buffer, size); #if (CC_PLATFORM == CC_PLATFORM_MAC_OSX) if (_mtlResourceOptions == MTLResourceStorageModeManaged) { - [_mtlBuffer didModifyRange:NSMakeRange(0, _size)]; // Synchronize the managed buffer. + [_gpuBuffer->mtlBuffer didModifyRange:NSMakeRange(0, _size)]; // Synchronize the managed buffer. } #endif } @@ -240,19 +252,23 @@ void CCMTLBuffer::encodeBuffer(CCMTLCommandEncoder &encoder, uint offset, uint b if (hasFlag(stages, ShaderStageFlagBit::VERTEX)) { CCMTLRenderCommandEncoder* renderEncoder = static_cast(&encoder); - renderEncoder->setVertexBuffer(_mtlBuffer, offset, binding); + renderEncoder->setVertexBuffer(_gpuBuffer->mtlBuffer, offset, binding); } if (hasFlag(stages, ShaderStageFlagBit::FRAGMENT)) { CCMTLRenderCommandEncoder* renderEncoder = static_cast(&encoder); - renderEncoder->setFragmentBuffer(_mtlBuffer, offset, binding); + renderEncoder->setFragmentBuffer(_gpuBuffer->mtlBuffer, offset, binding); } if(hasFlag(stages, ShaderStageFlagBit::COMPUTE)) { CCMTLComputeCommandEncoder* computeEncoder = static_cast(&encoder); - computeEncoder->setBuffer(_mtlBuffer, offset, binding); + computeEncoder->setBuffer(_gpuBuffer->mtlBuffer, offset, binding); } } +id CCMTLBuffer::getMTLBuffer() const { + return _gpuBuffer->mtlBuffer; +} + } // namespace gfx } // namespace cc From 9722e25b9e2d4292b12391e8d559be528d1ebf28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=88=98?= <40414978+PatriceJiang@users.noreply.github.com> Date: Wed, 11 Aug 2021 18:13:03 +0800 Subject: [PATCH 17/21] V3.3 fix bindings source list (#3818) --- native/CMakeLists.txt | 10 +++--- native/external/config.json | 4 +-- native/tests/module-tests/bindings/.gitignore | 10 ++++++ .../module-tests/bindings/test-bindings.cpp | 31 ++++++++++++++++--- 4 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 native/tests/module-tests/bindings/.gitignore diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 940d18dca6..2567c2e80d 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -1553,8 +1553,6 @@ cocos_source_files( cocos/bindings/manual/jsb_gfx_manual.h NO_WERROR cocos/bindings/manual/jsb_global.cpp cocos/bindings/manual/jsb_global.h - NO_WERROR cocos/bindings/manual/jsb_global_init.cpp - cocos/bindings/manual/jsb_global_init.h NO_WERROR cocos/bindings/manual/jsb_helper.cpp cocos/bindings/manual/jsb_helper.h cocos/bindings/manual/jsb_module_register.h @@ -1694,7 +1692,9 @@ cocos_source_files(MODULE ccbindings cocos/bindings/jswrapper/State.cpp cocos/bindings/jswrapper/State.h cocos/bindings/jswrapper/Value.cpp - cocos/bindings/jswrapper/Value.h + cocos/bindings/jswrapper/Value.h + NO_WERROR cocos/bindings/manual/jsb_global_init.cpp + cocos/bindings/manual/jsb_global_init.h ) cocos_source_files( @@ -1823,7 +1823,7 @@ if(USE_MODULES) add_library(ccmath ${ccmath_SOURCE_LIST}) add_library(cclog ${cclog_SOURCE_LIST}) add_library(ccfilesystem ${ccfilesystem_SOURCE_LIST} ${CC_TINYDIR_SOURCES}) - add_library(ccutils ${ccutils_SOURCE_LIST} ${CC_FS_SOURCES}) + add_library(ccutils ${ccutils_SOURCE_LIST} ${CC_UTILS_SOURCES}) add_library(ccunzip ${ccunzip_SOURCE_LIST} ${CC_UNZIP_SOURCES}) add_library(ccbindings ${ccbindings_SOURCE_LIST}) @@ -1849,6 +1849,8 @@ if(USE_MODULES) ) target_include_directories(ccbindings PRIVATE ${CWD}/cocos + ${CWD}/cocos/bindings/jswrapper + ${CWD}/cocos/editor-support # TODO: refactor include path ${CWD} ${CC_EXTERNAL_INCLUDES} ) diff --git a/native/external/config.json b/native/external/config.json index 7249e58d85..acf0a7c727 100644 --- a/native/external/config.json +++ b/native/external/config.json @@ -1,9 +1,9 @@ { - "version": "v3d-gfx-63", + "version": "v3d-gfx-65", "from": { "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3d-gfx-63" + "checkout": "v3d-gfx-65" } } diff --git a/native/tests/module-tests/bindings/.gitignore b/native/tests/module-tests/bindings/.gitignore new file mode 100644 index 0000000000..cc871c45b3 --- /dev/null +++ b/native/tests/module-tests/bindings/.gitignore @@ -0,0 +1,10 @@ +oldmath/ +newmath/ +out* +dist* +index.ts +tsconfig.json +webpack.config.js +package.json +package-lock.json +node_modules/* \ No newline at end of file diff --git a/native/tests/module-tests/bindings/test-bindings.cpp b/native/tests/module-tests/bindings/test-bindings.cpp index 9bb282e518..638813abca 100644 --- a/native/tests/module-tests/bindings/test-bindings.cpp +++ b/native/tests/module-tests/bindings/test-bindings.cpp @@ -1,14 +1,37 @@ #include "cocos/bindings/jswrapper/SeApi.h" +#include "cocos/platform/FileUtils.h" +#include +#include +#include +#include "cocos/bindings/manual/jsb_global_init.h" int main(int argc, char **argv) { + std::string scriptPath = "index.js"; + + if(argc > 1) { + scriptPath = argv[1]; + } + auto *engine = se::ScriptEngine::getInstance(); - engine->init(); + auto *fu = cc::FileUtils::getInstance(); + + // TODO: replace search path + auto *currentDir = getenv("PWD"); + fu->addSearchPath(currentDir); + + jsb_set_xxtea_key(""); + jsb_init_file_operation_delegate(); + engine->start(); - engine->evalString("console.log('------------------------------------------');"); - engine->evalString("console.log('----------hello from evalString()---------');"); - engine->evalString("console.log('------------------------------------------');"); + engine->evalString("console.log('begin execute')"); + auto ret = engine->runScript(scriptPath); + engine->evalString("console.log('end')"); + if(!ret) return EXIT_FAILURE; + + se::ScriptEngine::destroyInstance(); + cc::FileUtils::destroyInstance(); return 0; } \ No newline at end of file From 12126e4ab0eceda22990b33967fabd534772480c Mon Sep 17 00:00:00 2001 From: timlyeee <43355299+timlyeee@users.noreply.github.com> Date: Thu, 12 Aug 2021 15:29:03 +0800 Subject: [PATCH 18/21] Update externals (#3822) * Change external version to 68 --- native/external/config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/external/config.json b/native/external/config.json index acf0a7c727..239c8fe456 100644 --- a/native/external/config.json +++ b/native/external/config.json @@ -1,9 +1,9 @@ { - "version": "v3d-gfx-65", + "version": "v3d-gfx-68", "from": { "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3d-gfx-65" + "checkout": "v3d-gfx-68" } } From 27a48968e7331538afeec6c5ff75be7a43e2a723 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Thu, 12 Aug 2021 15:29:45 +0800 Subject: [PATCH 19/21] ES2: fix uniform array upload & half float texture (#3823) --- .../renderer/gfx-gles2/GLES2Commands.cpp | 122 ++++++++++-------- .../renderer/gfx-gles2/GLES2GPUObjects.h | 52 ++------ .../tools/gles-wrangler-generator/generate.js | 29 +++-- 3 files changed, 96 insertions(+), 107 deletions(-) diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp b/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp index 6a9148afe2..3d128ecdc6 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp @@ -158,6 +158,10 @@ GLenum mapGLInternalFormat(Format format) { case Format::SRGB8: return GL_SRGB_EXT; case Format::RGBA8SN: return GL_RGBA8_SNORM; case Format::SRGB8_A8: return GL_SRGB_ALPHA_EXT; + case Format::R16F: return GL_R16F_EXT; + case Format::RG16F: return GL_RG16F_EXT; + case Format::RGB16F: return GL_RGB16F_EXT; + case Format::RGBA16F: return GL_RGBA16F_EXT; case Format::R32F: return GL_R32F_EXT; case Format::RG32F: return GL_RG32F_EXT; case Format::RGB32F: return GL_RGB32F_EXT; @@ -1010,12 +1014,8 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { gpuUniform.stride = GFX_TYPE_SIZES[static_cast(uniform.type)]; gpuUniform.count = uniform.count; gpuUniform.size = gpuUniform.stride * gpuUniform.count; - gpuUniform.offset = gpuBlock.size; gpuUniform.glType = mapGLType(gpuUniform.type); gpuUniform.glLoc = -1; - gpuUniform.buff = nullptr; - - gpuBlock.size += gpuUniform.size; } } } // if @@ -1049,10 +1049,10 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } // parse glUniforms - GLint glActiveUniforms; - GL_CHECK(glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_UNIFORMS, &glActiveUniforms)); + GLint glActiveUniformCount; + GL_CHECK(glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_UNIFORMS, &glActiveUniformCount)); - for (GLint i = 0; i < glActiveUniforms; ++i) { + for (GLint i = 0; i < glActiveUniformCount; ++i) { memset(glName, 0, sizeof(glName)); GL_CHECK(glGetActiveUniform(gpuShader->glProgram, i, 255, &glLength, &glSize, &glType, glName)); char *offset = strchr(glName, '['); @@ -1069,15 +1069,17 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { (glType == GL_INT_SAMPLER_CUBE_MAP_ARRAY_OES) || (glType == GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_OES); if (!isSampler) { - for (size_t b = 0; b < gpuShader->glBlocks.size(); ++b) { - GLES2GPUUniformBlock &gpuBlock = gpuShader->glBlocks[b]; - for (size_t u = 0; u < gpuBlock.glUniforms.size(); ++u) { - if (gpuBlock.glUniforms[u].name == name) { - GLES2GPUUniform &gpuUniform = gpuBlock.glUniforms[u]; - gpuUniform.glLoc = glGetUniformLocation(gpuShader->glProgram, glName); - gpuUniform.buff = static_cast(CC_MALLOC(gpuUniform.size)); + for (auto &glBlock : gpuShader->glBlocks) { + for (uint i = 0; i < glBlock.glUniforms.size(); ++i) { + auto &glUniform = glBlock.glUniforms[i]; + if (glUniform.name == name) { + glUniform.glLoc = glGetUniformLocation(gpuShader->glProgram, glName); + glUniform.count = glSize; + glUniform.size = glUniform.stride * glUniform.count; - gpuBlock.glActiveUniforms.emplace_back(gpuUniform); + auto &activeUniform = glBlock.glActiveUniforms.emplace_back(glUniform); + activeUniform.buff.resize(activeUniform.size); + glBlock.activeUniformIndices.push_back(i); break; } } @@ -1085,6 +1087,19 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } } // for + // calculate offset & size + for (auto &gpuBlock : gpuShader->glBlocks) { + for (auto &gpuUniform : gpuBlock.glUniforms) { + gpuUniform.offset = gpuBlock.size; + gpuBlock.size += gpuUniform.size; + } + for (uint i = 0; i < gpuBlock.glActiveUniforms.size(); ++i) { + auto &activeUniform = gpuBlock.glActiveUniforms[i]; + uint index = gpuBlock.activeUniformIndices[i]; + activeUniform.offset = gpuBlock.glUniforms[index].offset; + } + } + // texture unit index mapping optimization vector glActiveSamplerTextures; vector glActiveSamplerLocations; @@ -1932,13 +1947,14 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli // bind descriptor sets if (gpuPipelineState && gpuPipelineState->gpuShader && gpuPipelineState->gpuPipelineLayout) { - size_t blockLen = gpuPipelineState->gpuShader->glBlocks.size(); - const vector> &dynamicOffsetIndices = gpuPipelineState->gpuPipelineLayout->dynamicOffsetIndices; - uint8_t * uniformBuffBase = nullptr; - uint8_t * uniformBuff; + size_t blockLen{gpuPipelineState->gpuShader->glBlocks.size()}; + const vector> &dynamicOffsetIndices{gpuPipelineState->gpuPipelineLayout->dynamicOffsetIndices}; + uint8_t * uniformBuffBase{nullptr}; + uint8_t * uniformBuff{nullptr}; + uint8_t * uniformCachedBuff{nullptr}; for (size_t j = 0; j < blockLen; j++) { - const GLES2GPUUniformBlock &glBlock = gpuPipelineState->gpuShader->glBlocks[j]; + GLES2GPUUniformBlock &glBlock = gpuPipelineState->gpuShader->glBlocks[j]; const GLES2GPUDescriptorSet *gpuDescriptorSet = gpuDescriptorSets[glBlock.set]; const uint descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glBlock.binding); @@ -1964,87 +1980,89 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli uniformBuffBase = gpuDescriptor.gpuBuffer->buffer + offset; } - for (const auto &gpuUniform : glBlock.glActiveUniforms) { - uniformBuff = uniformBuffBase + gpuUniform.offset; + for (auto &gpuUniform : glBlock.glActiveUniforms) { + uniformBuff = uniformBuffBase + gpuUniform.offset; + uniformCachedBuff = gpuUniform.buff.data(); + switch (gpuUniform.glType) { case GL_BOOL: case GL_INT: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniform1iv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } case GL_BOOL_VEC2: case GL_INT_VEC2: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniform2iv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } case GL_BOOL_VEC3: case GL_INT_VEC3: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniform3iv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } case GL_BOOL_VEC4: case GL_INT_VEC4: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniform4iv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } case GL_FLOAT: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniform1fv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } case GL_FLOAT_VEC2: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniform2fv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } case GL_FLOAT_VEC3: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniform3fv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } case GL_FLOAT_VEC4: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniform4fv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } case GL_FLOAT_MAT2: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniformMatrix2fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } case GL_FLOAT_MAT3: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniformMatrix3fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } case GL_FLOAT_MAT4: { - if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) { + if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) { GL_CHECK(glUniformMatrix4fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, reinterpret_cast(uniformBuff))); - memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size); + memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size); } break; } @@ -2611,19 +2629,19 @@ void cmdFuncGLES2CopyBuffersToTexture(GLES2Device *device, const uint8_t *const CC_GLES2_API void cmdFuncGLES2CopyTextureToBuffers(GLES2Device *device, GLES2GPUTexture *gpuTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint count) { GLuint framebuffer = device->framebufferCacheMap()->getFramebufferFromTexture(gpuTexture); - auto glFormat = mapGLFormat(gpuTexture->format); - auto glType = formatToGLType(gpuTexture->format); + auto glFormat = mapGLFormat(gpuTexture->format); + auto glType = formatToGLType(gpuTexture->format); if (device->stateCache()->glFramebuffer != framebuffer) { GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, framebuffer)); device->stateCache()->glFramebuffer = framebuffer; } - for(uint32_t i = 0; i < count; ++i) { - auto region = regions[i]; - auto w = region.texExtent.width; - auto h = region.texExtent.height; - auto memSize = static_cast(formatSize(gpuTexture->format, w, h, 1)); - uint8_t* copyDst = buffers[i]; + for (uint32_t i = 0; i < count; ++i) { + auto region = regions[i]; + auto w = region.texExtent.width; + auto h = region.texExtent.height; + auto memSize = static_cast(formatSize(gpuTexture->format, w, h, 1)); + uint8_t *copyDst = buffers[i]; GL_CHECK(glReadPixels(region.texOffset.x, region.texOffset.y, region.texExtent.width, region.texExtent.height, glFormat, glType, copyDst)); } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h b/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h index b8080a3f34..a123d01429 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h +++ b/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h @@ -130,47 +130,16 @@ struct GLES2GPUInput final { using GLES2GPUInputList = vector; struct GLES2GPUUniform final { - uint binding = INVALID_BINDING; - String name; - Type type = Type::UNKNOWN; - uint stride = 0; - uint count = 0; - uint size = 0; - uint offset = 0; - GLenum glType = 0; - GLint glLoc = -1; - uint8_t *buff = nullptr; - - GLES2GPUUniform() = default; - GLES2GPUUniform(const GLES2GPUUniform &rhs) { - *this = rhs; - } - - GLES2GPUUniform &operator=(const GLES2GPUUniform &rhs) { - if (this != &rhs) { - binding = rhs.binding; - name = rhs.name; - type = rhs.type; - stride = rhs.stride; - count = rhs.count; - offset = rhs.offset; - glType = rhs.glType; - glLoc = rhs.glLoc; - if (size != rhs.size) { - size = rhs.size; - CC_SAFE_FREE(buff); - buff = static_cast(CC_MALLOC(size)); - } - if (buff && rhs.buff) { - memcpy(buff, rhs.buff, size); - } - } - return *this; - } - - ~GLES2GPUUniform() { - CC_SAFE_FREE(buff); - } + uint binding = INVALID_BINDING; + String name; + Type type = Type::UNKNOWN; + uint stride = 0; + uint count = 0; + uint size = 0; + uint offset = 0; + GLenum glType = 0; + GLint glLoc = -1; + vector buff; }; using GLES2GPUUniformList = vector; @@ -182,6 +151,7 @@ struct GLES2GPUUniformBlock final { uint size = 0; GLES2GPUUniformList glUniforms; GLES2GPUUniformList glActiveUniforms; + vector activeUniformIndices; }; using GLES2GPUUniformBlockList = vector; diff --git a/native/tools/gles-wrangler-generator/generate.js b/native/tools/gles-wrangler-generator/generate.js index 2da99e0c70..28030e837d 100644 --- a/native/tools/gles-wrangler-generator/generate.js +++ b/native/tools/gles-wrangler-generator/generate.js @@ -7,9 +7,9 @@ const eglRegistry = { local: `${specDir}/egl.xml`, remote: 'https://www.khronos. const glRegistry = { local: `${specDir}/gl.xml`, remote: 'https://www.khronos.org/registry/OpenGL/xml/gl.xml' }; const downloadSpec = async (specInfo) => { - if (fs.existsSync(specInfo.local)) return; + if (fs.existsSync(specInfo.local)) { return; } fs.writeFileSync(specInfo.local, (await axios.get(specInfo.remote)).data); -} +}; const options = { clear: false, @@ -23,7 +23,7 @@ for (let i = 2; i < argc; i++) { } (async () => { - if (!fs.existsSync(specDir)) fs.mkdirSync(specDir); + if (!fs.existsSync(specDir)) { fs.mkdirSync(specDir); } await downloadSpec(eglRegistry); await downloadSpec(glRegistry); @@ -68,9 +68,9 @@ for (let i = 2; i < argc; i++) { append(`/* ${featureName} */\n`); const feature = spec.feature.find((f) => f.name === featureName); for (const manifest of feature.require) { - if (!manifest.command) continue; + if (!manifest.command) { continue; } for (const command of manifest.command) { - if (nameRecord.has(command.name)) continue; + if (nameRecord.has(command.name)) { continue; } writeCommand(command.name); } append(`\n`); @@ -80,12 +80,12 @@ for (let i = 2; i < argc; i++) { if (!noExtension) { const featureAPI = spec.feature.find((f) => f.name === featureNames[0]).api; for (const extension of spec.extensions[0].extension) { - if (!extension.supported.includes(featureAPI) || !extension.require) continue; + if (!extension.supported.includes(featureAPI) || !extension.require) { continue; } let needDeclare = false; for (const require of extension.require) { if (require.api && !require.api.includes(featureAPI) || !require.command || !require.command.length || - require.command.every((cmd) => nameRecord.has(cmd.name))) continue; + require.command.every((cmd) => nameRecord.has(cmd.name))) { continue; } if (!needDeclare) { append(`#if defined(${extension.name})\n`); needDeclare = true; @@ -93,7 +93,7 @@ for (let i = 2; i < argc; i++) { append(`\n`); } for (const command of require.command) { - if (nameRecord.has(command.name)) continue; + if (nameRecord.has(command.name)) { continue; } writeCommand(command.name); } } @@ -103,9 +103,10 @@ for (let i = 2; i < argc; i++) { } } return { headerDecl, sourceDef, sourceLoad }; - } + }; - const eglSrc = generate(eglSpec, ['EGL_VERSION_1_0', 'EGL_VERSION_1_1', 'EGL_VERSION_1_2', 'EGL_VERSION_1_3', 'EGL_VERSION_1_4', 'EGL_VERSION_1_5'], 'eglw', ['eglGetProcAddress']); + const eglSrc = generate(eglSpec, ['EGL_VERSION_1_0', 'EGL_VERSION_1_1', 'EGL_VERSION_1_2', + 'EGL_VERSION_1_3', 'EGL_VERSION_1_4', 'EGL_VERSION_1_5'], 'eglw', ['eglGetProcAddress']); const es2Src = generate(glSpec, ['GL_ES_VERSION_2_0'], 'gles2w'); const es3Src = generate(glSpec, ['GL_ES_VERSION_3_0', 'GL_ES_VERSION_3_1', 'GL_ES_VERSION_3_2'], 'gles3w', [], true); @@ -113,11 +114,11 @@ for (let i = 2; i < argc; i++) { const flag = `/\\* ${moduleName.toUpperCase()}_GENERATE_${keyword} \\*/\n`; const flagRE = new RegExp(flag, 'g'); const indices = []; - while (flagRE.exec(source)) indices.push(flagRE.lastIndex); - if (indices.length !== 2) return source; + while (flagRE.exec(source)) { indices.push(flagRE.lastIndex); } + if (indices.length !== 2) { return source; } indices[1] -= flag.length - 2; // two escape characters - if (options.clear) content = ''; - if (indentEnd) content += ' '; + if (options.clear) { content = ''; } + if (indentEnd) { content += ' '; } return source.slice(0, indices[0]) + content + source.slice(indices[1]); }; From d4ba1fed9724705ca65596a5837108901a534c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=88=98?= <40414978+PatriceJiang@users.noreply.github.com> Date: Fri, 13 Aug 2021 16:03:48 +0800 Subject: [PATCH 20/21] Revert cc_app_name (#3826) --- native/templates/android/template/app/AndroidManifest.xml | 4 ++-- native/templates/android/template/app/build.gradle | 4 ++-- .../android/template/instantapp/AndroidManifest.xml | 4 ++-- native/templates/android/template/instantapp/build.gradle | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/native/templates/android/template/app/AndroidManifest.xml b/native/templates/android/template/app/AndroidManifest.xml index adc77889ab..934b29783c 100644 --- a/native/templates/android/template/app/AndroidManifest.xml +++ b/native/templates/android/template/app/AndroidManifest.xml @@ -9,7 +9,7 @@ @@ -21,7 +21,7 @@ android:name="com.cocos.game.AppActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden|screenSize|screenLayout" - android:label="@string/cc_app_name" + android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleTask" android:taskAffinity="" > diff --git a/native/templates/android/template/app/build.gradle b/native/templates/android/template/app/build.gradle index 2f524c4a9b..9f9d9fb1a1 100644 --- a/native/templates/android/template/app/build.gradle +++ b/native/templates/android/template/app/build.gradle @@ -75,14 +75,14 @@ android { if (project.hasProperty("RELEASE_STORE_FILE")) { signingConfig signingConfigs.release } - resValue "string", "cc_app_name", PROP_APP_NAME + // resValue "string", "app_name", PROP_APP_NAME } debug { debuggable true jniDebuggable true renderscriptDebuggable true - resValue "string", "cc_app_name", "${PROP_APP_NAME}-dbg" + // resValue "string", "app_name", "${PROP_APP_NAME}-dbg" // applicationIdSuffix ".debug" } } diff --git a/native/templates/android/template/instantapp/AndroidManifest.xml b/native/templates/android/template/instantapp/AndroidManifest.xml index 3dad167044..2432b8b52b 100644 --- a/native/templates/android/template/instantapp/AndroidManifest.xml +++ b/native/templates/android/template/instantapp/AndroidManifest.xml @@ -11,7 +11,7 @@ diff --git a/native/templates/android/template/instantapp/build.gradle b/native/templates/android/template/instantapp/build.gradle index c6706f2b85..5dc839116b 100644 --- a/native/templates/android/template/instantapp/build.gradle +++ b/native/templates/android/template/instantapp/build.gradle @@ -71,15 +71,15 @@ android { if (project.hasProperty("RELEASE_STORE_FILE")) { signingConfig signingConfigs.release } - resValue "string", "cc_app_name", PROP_APP_NAME + // resValue "string", "app_name", PROP_APP_NAME } debug { debuggable true jniDebuggable true renderscriptDebuggable true - resValue "string", "cc_app_name", "${PROP_APP_NAME}-dbg" - applicationIdSuffix ".debug" + // resValue "string", "app_name", "${PROP_APP_NAME}-dbg" + // applicationIdSuffix ".debug" } } } From 256910d137abad42249ae13cf4b7227541b33d23 Mon Sep 17 00:00:00 2001 From: timlyeee <43355299+timlyeee@users.noreply.github.com> Date: Fri, 13 Aug 2021 21:01:38 +0800 Subject: [PATCH 21/21] Update config.json (#3829) FIX ISSUE https://github.com/cocos-creator/3d-tasks/issues/8671 --- native/external/config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/external/config.json b/native/external/config.json index 239c8fe456..3d5649360f 100644 --- a/native/external/config.json +++ b/native/external/config.json @@ -1,9 +1,9 @@ { - "version": "v3d-gfx-68", + "version": "v3d-gfx-69", "from": { "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3d-gfx-68" + "checkout": "v3d-gfx-69" } }