From 0a5befb6fcaa7453d3d7977c1656a34c23952d19 Mon Sep 17 00:00:00 2001 From: Yiwen <15225434259xue@gmail.com> Date: Wed, 20 Sep 2023 21:31:53 +0800 Subject: [PATCH 01/31] physics removes useless cone twist joint (#16285) --- cocos/physics/framework/deprecated.ts | 6 ------ cocos/physics/framework/physics-enum.ts | 8 -------- cocos/physics/framework/physics-selector.ts | 17 ++--------------- cocos/physics/spec/i-physics-constraint.ts | 5 ----- 4 files changed, 2 insertions(+), 34 deletions(-) diff --git a/cocos/physics/framework/deprecated.ts b/cocos/physics/framework/deprecated.ts index 6a9d9519d11..fdb15eec610 100644 --- a/cocos/physics/framework/deprecated.ts +++ b/cocos/physics/framework/deprecated.ts @@ -148,12 +148,6 @@ removeProperty(RigidBody.prototype, 'RigidBody.prototype', [ }, ]); -removeProperty(EConstraintType, 'EConstraintType.prototype', [ - { - name: 'CONE_TWIST', - }, -]); - /** * Alias of [[RigidBody]] * @deprecated Since v1.2 diff --git a/cocos/physics/framework/physics-enum.ts b/cocos/physics/framework/physics-enum.ts index a84d210aa48..de4bcbc3de8 100644 --- a/cocos/physics/framework/physics-enum.ts +++ b/cocos/physics/framework/physics-enum.ts @@ -270,14 +270,6 @@ export enum EConstraintType { * 铰链约束。 */ HINGE, - /** - * @en - * Cone twist constraint. - * @zh - * 锥形扭转约束。 - * @deprecated coneTwist is deprecated, please use configurable instead - */ - CONE_TWIST, /** * @en * Fixed constraint. diff --git a/cocos/physics/framework/physics-selector.ts b/cocos/physics/framework/physics-selector.ts index 9be81501389..7bb003d67e0 100644 --- a/cocos/physics/framework/physics-selector.ts +++ b/cocos/physics/framework/physics-selector.ts @@ -26,7 +26,7 @@ /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable @typescript-eslint/no-unsafe-return */ import { EDITOR, TEST } from 'internal:constants'; -import { IBaseConstraint, IPointToPointConstraint, IHingeConstraint, IConeTwistConstraint, IFixedConstraint, +import { IBaseConstraint, IPointToPointConstraint, IHingeConstraint, IFixedConstraint, IConfigurableConstraint } from '../spec/i-physics-constraint'; import { IBoxShape, ISphereShape, ICapsuleShape, ITrimeshShape, ICylinderShape, @@ -58,10 +58,6 @@ interface IPhysicsWrapperObject { PlaneShape?: Constructor, PointToPointConstraint?: Constructor, HingeConstraint?: Constructor, - /** - * @deprecated cone twist constraint is deprecated, please use configurable instead - */ - ConeTwistConstraint?: Constructor, FixedConstraint?: Constructor, ConfigurableConstraint?: Constructor, } @@ -236,10 +232,6 @@ enum ECheckType { // JOINT // PointToPointConstraint, HingeConstraint, - /** - * @deprecated cone twist constraint is deprecated, please use configurable instead - */ - ConeTwistConstraint, FixedConstraint, ConfigurableConstraint, // CHARACTER CONTROLLER // @@ -422,7 +414,7 @@ function initColliderProxy (): void { const CREATE_CONSTRAINT_PROXY = { INITED: false }; -interface IEntireConstraint extends IPointToPointConstraint, IHingeConstraint, IConeTwistConstraint, IFixedConstraint, IConfigurableConstraint { } +interface IEntireConstraint extends IPointToPointConstraint, IHingeConstraint, IFixedConstraint, IConfigurableConstraint { } const ENTIRE_CONSTRAINT: IEntireConstraint = { impl: null, initialize: FUNC, @@ -488,11 +480,6 @@ function initConstraintProxy (): void { return new selector.wrapper.HingeConstraint!(); }; - CREATE_CONSTRAINT_PROXY[EConstraintType.CONE_TWIST] = function createConeTwistConstraint (): IConeTwistConstraint { - if (check(selector.wrapper.ConeTwistConstraint, ECheckType.ConeTwistConstraint)) { return ENTIRE_CONSTRAINT; } - return new selector.wrapper.ConeTwistConstraint!(); - }; - CREATE_CONSTRAINT_PROXY[EConstraintType.FIXED] = function createFixedConstraint (): IFixedConstraint { if (check(selector.wrapper.FixedConstraint, ECheckType.FixedConstraint)) { return ENTIRE_CONSTRAINT; } return new selector.wrapper.FixedConstraint!(); diff --git a/cocos/physics/spec/i-physics-constraint.ts b/cocos/physics/spec/i-physics-constraint.ts index 91664b25717..ad6692b20e5 100644 --- a/cocos/physics/spec/i-physics-constraint.ts +++ b/cocos/physics/spec/i-physics-constraint.ts @@ -96,8 +96,3 @@ export interface IConfigurableConstraint extends IBaseConstraint { setBreakForce(v: number): void; setBreakTorque(v: number): void; } - -/** - * @deprecated ConeTwistConstraint is deprecated, please use ConfigurableConstraint instead - */ -export type IConeTwistConstraint = IBaseConstraint From 2039c33462bf299d2bd5e05e456ecceb6e01e4b0 Mon Sep 17 00:00:00 2001 From: Zeqiang Li Date: Thu, 21 Sep 2023 17:31:07 +0800 Subject: [PATCH 02/31] correct renderpass reorder logic (#16294) --- .../pipeline/custom/FrameGraphDispatcher.cpp | 188 ++++++++++-------- 1 file changed, 109 insertions(+), 79 deletions(-) diff --git a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp index 4d0f5afe176..0324502effa 100644 --- a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp +++ b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp @@ -791,15 +791,22 @@ struct AttachmentSortKey { gfx::SampleCount samples; AccessType accessType; uint32_t attachmentWeight; + uint32_t slotID; const ccstd::pmr::string name; }; -struct AttachmentComparator { +struct SubpassComparator { bool operator()(const AttachmentSortKey &lhs, const AttachmentSortKey &rhs) const { return std::tie(rhs.samples, lhs.accessType, lhs.attachmentWeight, lhs.name) < std::tie(lhs.samples, rhs.accessType, rhs.attachmentWeight, rhs.name); } }; +struct PassComparator { + bool operator()(const AttachmentSortKey &lhs, const AttachmentSortKey &rhs) const { + return lhs.slotID < rhs.slotID; + } +}; + struct ViewInfo { gfx::Format format{gfx::Format::UNKNOWN}; LayoutAccess access; @@ -808,10 +815,12 @@ struct ViewInfo { AttachmentType attachmentType; }; -using AttachmentMap = ccstd::pmr::map; +template +using AttachmentMap = ccstd::pmr::map; } // namespace -void fillRenderPassInfo(const AttachmentMap &colorMap, +template +void fillRenderPassInfo(const AttachmentMap &colorMap, FGRenderPassInfo &fgRenderpassInfo, const ResourceGraph &resg) { for (const auto &pair : colorMap) { @@ -920,11 +929,12 @@ void extractNames(const ccstd::pmr::string &resName, } } +template auto checkRasterViews(const Graphs &graphs, ResourceAccessGraph::vertex_descriptor ragVertID, ResourceAccessNode &node, const RasterViewsMap &rasterViews, - AttachmentMap &colorMap) { + AttachmentMap &colorMap) { const auto &[renderGraph, layoutGraphData, resourceGraph, resourceAccessGraph, relationGraph] = graphs; const auto passID = get(ResourceAccessGraph::PassIDTag{}, resourceAccessGraph, ragVertID); bool dependent = false; @@ -956,6 +966,7 @@ auto checkRasterViews(const Graphs &graphs, colorMap.emplace(AttachmentSortKey{desc.sampleCount, rasterView.accessType, ATTACHMENT_TYPE_WEIGHT[static_cast(rasterView.attachmentType)], + rasterView.slotID, resName}, ViewInfo{desc.format, LayoutAccess{lastAccess, accessFlag}, @@ -1018,11 +1029,12 @@ bool checkComputeViews(const Graphs &graphs, ResourceAccessGraph::vertex_descrip return dependent; } +template bool checkResolveResource(const Graphs &graphs, uint32_t ragVertID, ResourceAccessNode &node, const ccstd::pmr::vector &resolves, - AttachmentMap &colorMap) { + AttachmentMap &colorMap) { const auto &[renderGraph, layoutGraphData, resourceGraph, resourceAccessGraph, relationGraph] = graphs; const auto passID = get(ResourceAccessGraph::PassIDTag{}, resourceAccessGraph, ragVertID); bool dependent = false; @@ -1051,6 +1063,7 @@ bool checkResolveResource(const Graphs &graphs, colorMap.emplace(AttachmentSortKey{desc.sampleCount, AccessType::WRITE, ATTACHMENT_TYPE_WEIGHT[static_cast(attachmentType)], + static_cast(colorMap.size()), resolveTargetName}, ViewInfo{desc.format, LayoutAccess{lastAccess, accessFlag}, @@ -1132,7 +1145,7 @@ void startRenderPass(const Graphs &graphs, uint32_t passID, const RasterPass &pa auto &fgRenderPassInfo = get(ResourceAccessGraph::RenderPassInfoTag{}, resourceAccessGraph, vertID); if (pass.subpassGraph.subpasses.empty()) { - AttachmentMap colorMap(resourceAccessGraph.get_allocator()); + AttachmentMap colorMap(resourceAccessGraph.get_allocator()); auto &accessNode = get(ResourceAccessGraph::PassNodeTag{}, resourceAccessGraph, vertID); std::ignore = checkRasterViews(graphs, rlgVertID, accessNode, pass.rasterViews, colorMap); std::ignore = checkComputeViews(graphs, rlgVertID, accessNode, pass.computeViews); @@ -1214,90 +1227,107 @@ void startRenderSubpass(const Graphs &graphs, uint32_t passID, const RasterSubpa auto parentID = parent(passID, renderGraph); auto parentRagVertID = resourceAccessGraph.passIndex.at(parentID); auto &fgRenderpassInfo = get(ResourceAccessGraph::RenderPassInfoTag{}, resourceAccessGraph, parentRagVertID); - AttachmentMap colorMap(resourceAccessGraph.get_allocator()); - - auto [hasDep, hasDS] = checkRasterViews(graphs, rlgVertID, accessNode, pass.rasterViews, colorMap); - hasDep |= checkComputeViews(graphs, rlgVertID, accessNode, pass.computeViews); - hasDep |= checkResolveResource(graphs, rlgVertID, accessNode, pass.resolvePairs, colorMap); - fillRenderPassInfo(colorMap, fgRenderpassInfo, resourceGraph); - auto &subpassInfo = fgRenderpassInfo.rpInfo.subpasses.emplace_back(); - auto &dependencies = fgRenderpassInfo.rpInfo.dependencies; + const auto &rg = renderGraph; + auto &rag = resourceAccessGraph; + auto &resg = resourceGraph; - // subpass info & subpass dependencies - for (const auto &pair : colorMap) { - const auto &sortKey = pair.first; - const std::string_view name = sortKey.name; - auto resID = vertex(sortKey.name, resourceGraph); - const auto &desc = get(ResourceGraph::DescTag{}, resourceGraph, resID); - const auto &[ignored, cIndex, isResolveView] = fgRenderpassInfo.viewIndex.at(name.data()); - if (isResolveView) { - auto resolveIter = std::find_if(pass.resolvePairs.begin(), pass.resolvePairs.end(), [&name](const ResolvePair &resolve) { - return strcmp(resolve.target.c_str(), name.data()) == 0; - }); - if (desc.format == gfx::Format::DEPTH_STENCIL) { - subpassInfo.depthStencilResolve = getDepthStencilSlot(fgRenderpassInfo.uniqueRasterViewCount, fgRenderpassInfo.resolveCount, hasDS) + 1; - if (resolveIter->mode != gfx::ResolveMode::NONE) { - subpassInfo.depthResolveMode = resolveIter->mode; - } - if (resolveIter->mode1 != gfx::ResolveMode::NONE) { - subpassInfo.stencilResolveMode = resolveIter->mode1; + auto process = [&](auto &colorMap) { + auto [hasDep, hasDS] = checkRasterViews(graphs, rlgVertID, accessNode, pass.rasterViews, colorMap); + hasDep |= checkComputeViews(graphs, rlgVertID, accessNode, pass.computeViews); + hasDep |= checkResolveResource(graphs, rlgVertID, accessNode, pass.resolvePairs, colorMap); + fillRenderPassInfo(colorMap, fgRenderpassInfo, resg); + + auto &subpassInfo = fgRenderpassInfo.rpInfo.subpasses.emplace_back(); + auto &dependencies = fgRenderpassInfo.rpInfo.dependencies; + + // subpass info & subpass dependencies + for (const auto &pair : colorMap) { + const auto &sortKey = pair.first; + const std::string_view name = sortKey.name; + auto resID = vertex(sortKey.name, resg); + const auto &desc = get(ResourceGraph::DescTag{}, resg, resID); + const auto &[ignored, cIndex, isResolveView] = fgRenderpassInfo.viewIndex.at(name.data()); + if (isResolveView) { + auto resolveIter = std::find_if(pass.resolvePairs.begin(), pass.resolvePairs.end(), [&name](const ResolvePair &resolve) { + return strcmp(resolve.target.c_str(), name.data()) == 0; + }); + if (desc.format == gfx::Format::DEPTH_STENCIL) { + subpassInfo.depthStencilResolve = getDepthStencilSlot(fgRenderpassInfo.uniqueRasterViewCount, fgRenderpassInfo.resolveCount, hasDS) + 1; + if (resolveIter->mode != gfx::ResolveMode::NONE) { + subpassInfo.depthResolveMode = resolveIter->mode; + } + if (resolveIter->mode1 != gfx::ResolveMode::NONE) { + subpassInfo.stencilResolveMode = resolveIter->mode1; + } + } else { + if (subpassInfo.resolves.empty()) { + subpassInfo.resolves.resize(pass.rasterViews.size() - hasDS, gfx::INVALID_BINDING); + } + const auto &resolveSrc = resolveIter->source; + const auto &resourceSrcInfo = fgRenderpassInfo.viewIndex.at(resolveSrc); + subpassInfo.resolves[resourceSrcInfo.attachmentIndex] = cIndex; } } else { - if (subpassInfo.resolves.empty()) { - subpassInfo.resolves.resize(pass.rasterViews.size() - hasDS, gfx::INVALID_BINDING); + if (desc.format == gfx::Format::DEPTH_STENCIL) { + auto dsSlot = getDepthStencilSlot(fgRenderpassInfo.uniqueRasterViewCount, fgRenderpassInfo.resolveCount, hasDS); + if (sortKey.accessType != AccessType::WRITE) { + subpassInfo.inputs.emplace_back(dsSlot); + } + if (sortKey.accessType != AccessType::READ) { + subpassInfo.depthStencil = dsSlot; + } + } else { + if (sortKey.accessType != AccessType::WRITE) { + subpassInfo.inputs.emplace_back(cIndex); + } + if (sortKey.accessType != AccessType::READ) { + subpassInfo.colors.emplace_back(cIndex); + } + + if (sortKey.accessType == AccessType::READ_WRITE) { + auto &selfDependency = dependencies.emplace_back(); + selfDependency.srcSubpass = pass.subpassID; + selfDependency.dstSubpass = pass.subpassID; + selfDependency.prevAccesses = pair.second.access.nextAccess; + selfDependency.nextAccesses = pair.second.access.nextAccess; + } } - const auto &resolveSrc = resolveIter->source; - const auto &resourceSrcInfo = fgRenderpassInfo.viewIndex.at(resolveSrc); - subpassInfo.resolves[resourceSrcInfo.attachmentIndex] = cIndex; } - } else { - if (desc.format == gfx::Format::DEPTH_STENCIL) { - auto dsSlot = getDepthStencilSlot(fgRenderpassInfo.uniqueRasterViewCount, fgRenderpassInfo.resolveCount, hasDS); - if (sortKey.accessType != AccessType::WRITE) { - subpassInfo.inputs.emplace_back(dsSlot); - } - if (sortKey.accessType != AccessType::READ) { - subpassInfo.depthStencil = dsSlot; - } - } else { - if (sortKey.accessType != AccessType::WRITE) { - subpassInfo.inputs.emplace_back(cIndex); - } - if (sortKey.accessType != AccessType::READ) { - subpassInfo.colors.emplace_back(cIndex); - } - if (sortKey.accessType == AccessType::READ_WRITE) { - auto &selfDependency = dependencies.emplace_back(); - selfDependency.srcSubpass = pass.subpassID; - selfDependency.dstSubpass = pass.subpassID; - selfDependency.prevAccesses = pair.second.access.nextAccess; - selfDependency.nextAccesses = pair.second.access.nextAccess; + if (hasDep) { + auto &dependency = dependencies.emplace_back(); + auto lastIter = ++rag.resourceAccess[name.data()].rbegin(); + bool isBuffer = desc.dimension == ResourceDimension::BUFFER; + if (accessDependent(lastIter->second.accessFlag, accessNode.resourceStatus.at(name.data()).accessFlag, isBuffer) && lastIter->second.accessFlag != gfx::AccessFlagBit::NONE) { + auto lastVert = lastIter->first; + auto lastPassID = get(ResourceAccessGraph::PassIDTag{}, rag, lastVert); + auto lastPassIndex = INVALID_ID; + if (holds(lastPassID, rg) && (parent(lastPassID, rg) == parentID)) { + const auto *lastPass = get_if(lastPassID, &rg); + lastPassIndex = lastPass->subpassID; + } + + auto &dependency = dependencies.emplace_back(); + dependency.srcSubpass = lastPassIndex; + dependency.dstSubpass = pass.subpassID; + dependency.prevAccesses = lastIter->second.accessFlag; + dependency.nextAccesses = pair.second.access.nextAccess; } } } + }; - if (hasDep) { - auto &dependency = dependencies.emplace_back(); - auto lastIter = ++resourceAccessGraph.resourceAccess[name.data()].rbegin(); - bool isBuffer = desc.dimension == ResourceDimension::BUFFER; - if (accessDependent(lastIter->second.accessFlag, accessNode.resourceStatus.at(name.data()).accessFlag, isBuffer) && lastIter->second.accessFlag != gfx::AccessFlagBit::NONE) { - auto lastVert = lastIter->first; - auto lastPassID = get(ResourceAccessGraph::PassIDTag{}, resourceAccessGraph, lastVert); - auto lastPassIndex = INVALID_ID; - if (holds(lastPassID, renderGraph) && (parent(lastPassID, renderGraph) == parentID)) { - const auto *lastPass = get_if(lastPassID, &renderGraph); - lastPassIndex = lastPass->subpassID; - } + const auto *parentPass = get_if(parentID, &renderGraph); + CC_ASSERT(parentPass); - auto &dependency = dependencies.emplace_back(); - dependency.srcSubpass = lastPassIndex; - dependency.dstSubpass = pass.subpassID; - dependency.prevAccesses = lastIter->second.accessFlag; - dependency.nextAccesses = pair.second.access.nextAccess; - } - } + if (parentPass->subpassGraph.subpasses.size() == 1) { + // for those renderpass which consist of only 1 subpass + AttachmentMap colorMap(resourceAccessGraph.get_allocator()); + process(colorMap); + } else { + AttachmentMap colorMap(resourceAccessGraph.get_allocator()); + process(colorMap); } } @@ -1309,7 +1339,7 @@ void startComputeSubpass(const Graphs &graphs, uint32_t passID, const ComputeSub CC_EXPECTS(static_cast(rlgVertID) == static_cast(vertID)); auto &accessNode = get(ResourceAccessGraph::PassNodeTag{}, resourceAccessGraph, rlgVertID); - AttachmentMap colorMap(resourceAccessGraph.get_allocator()); + AttachmentMap colorMap(resourceAccessGraph.get_allocator()); auto parentID = parent(passID, renderGraph); auto parentRagVertID = resourceAccessGraph.passIndex.at(parentID); From 8c3e160846a38da8027ccc2a0abf7e9dbe28e311 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 21 Sep 2023 18:59:07 +0800 Subject: [PATCH 03/31] Fix a compilation issue and a crash issue if using Xcode 15 (#16306) * Fix crash in __cxx_global_var_init if using Xcode 15 and targeting <= iOS 14 * fixed #16190: Compilation errors if using Clang 15 with c++17 since std::unary_function has been removed (#16191) * fixed #16190: Compilation errors if using Clang 15 with c++17 since std::unary_function has been removed * Windows doesn't need to define BOOST_NO_CXX98_FUNCTION_BASE since it has already been defined. --- native/CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 3935dbbc443..0ef166479f2 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -82,6 +82,13 @@ if(USE_SERVER_MODE) add_definitions(-DCC_SERVER_MODE) endif() +# Fix the issue: https://github.com/cocos/cocos-engine/issues/16190 +# std::unary_function was removed since clang 15 +# The macro has already been defined in boost/config/stdlib/dinkumware.hpp(258,1), +# so no need to define it again to avoid 'macro redefinition' error. +if(NOT WINDOWS) + add_definitions(-DBOOST_NO_CXX98_FUNCTION_BASE) +endif() add_definitions(-DCC_NETMODE_CLIENT=0) add_definitions(-DCC_NETMODE_LISTEN_SERVER=1) @@ -3292,6 +3299,13 @@ if(APPLE) CC_KEYBOARD_SUPPORT ) elseif(IOS) + + if("${XCODE_VERSION}" VERSION_GREATER_EQUAL "15.0") + # For Xcode 15 and newer, add extra link flags to fix crash in __cxx_global_var_init. + message(STATUS "Using Xcode 15 or newer, adding extra link flags: -Wl,-ld_classic.") + target_link_options(${ENGINE_NAME} PUBLIC -Wl,-ld_classic) + endif() + target_link_libraries(${ENGINE_NAME} PUBLIC "-framework QuartzCore" "-framework MetalPerformanceShaders" From e2614859a763be46160d066dcbd90a8da0bb78e7 Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Fri, 22 Sep 2023 17:02:19 +0800 Subject: [PATCH 04/31] [Fixed] sampler synchronization issues with compute view texture (#16318) --- cocos/rendering/custom/executor.ts | 65 ++++++++++++++---------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/cocos/rendering/custom/executor.ts b/cocos/rendering/custom/executor.ts index 2ba97a70061..bc3f28ba261 100644 --- a/cocos/rendering/custom/executor.ts +++ b/cocos/rendering/custom/executor.ts @@ -584,48 +584,44 @@ class SubmitInfo { class RenderPassLayoutInfo { protected _layoutID = 0; + protected _vertID = -1; protected _stage: RenderStageData | null = null; protected _layout: PipelineLayoutData; protected _inputName: string; protected _descriptorSet: DescriptorSet | null = null; - constructor (layoutId: number, input: [string, ComputeView[]]) { + constructor (layoutId: number, vertId: number, input: [string, ComputeView[]]) { this._inputName = input[0]; this._layoutID = layoutId; + this._vertID = vertId; const lg = context.layoutGraph; this._stage = lg.getRenderStage(layoutId); this._layout = lg.getLayout(layoutId); - const layoutData = this._layout.descriptorSets.get(UpdateFrequency.PER_PASS); - const globalDesc = context.pipeline.descriptorSet; - if (layoutData) { - // find resource - const deviceTex = context.deviceTextures.get(this._inputName); - const gfxTex = deviceTex?.texture; - const layoutDesc = layoutData.descriptorSet!; - if (!gfxTex) { - throw Error(`Could not find texture with resource name ${this._inputName}`); - } - const resId = context.resourceGraph.vertex(this._inputName); - const samplerInfo = context.resourceGraph.getSampler(resId); - // bind descriptors - for (const descriptor of input[1]) { - const descriptorName = descriptor.name; - const descriptorID = lg.attributeIndex.get(descriptorName); - // find descriptor binding - for (const block of layoutData.descriptorSetLayoutData.descriptorBlocks) { - for (let i = 0; i !== block.descriptors.length; ++i) { - // const buffer = layoutDesc.getBuffer(block.offset + i); - // const texture = layoutDesc.getTexture(block.offset + i); - if (descriptorID === block.descriptors[i].descriptorID) { - layoutDesc.bindTexture(block.offset + i, gfxTex); - layoutDesc.bindSampler(block.offset + i, context.device.getSampler(samplerInfo)); - if (!this._descriptorSet) this._descriptorSet = layoutDesc; - continue; - } - // if (!buffer && !texture) { - // layoutDesc.bindBuffer(block.offset + i, globalDesc.getBuffer(block.offset + i)); - // layoutDesc.bindTexture(block.offset + i, globalDesc.getTexture(block.offset + i)); - // layoutDesc.bindSampler(block.offset + i, globalDesc.getSampler(block.offset + i)); - // } + const layoutData = this._layout.descriptorSets.get(UpdateFrequency.PER_PASS); + if (!layoutData) { + return; + } + const layoutDesc = layoutData.descriptorSet!; + // find resource + const deviceTex = context.deviceTextures.get(this._inputName); + const gfxTex = deviceTex?.texture; + if (!gfxTex) { + throw Error(`Could not find texture with resource name ${this._inputName}`); + } + const resId = context.resourceGraph.vertex(this._inputName); + const samplerInfo = context.resourceGraph.getSampler(resId); + // bind descriptors + for (const descriptor of input[1]) { + const descriptorName = descriptor.name; + const descriptorID = lg.attributeIndex.get(descriptorName); + // find descriptor binding + for (const block of layoutData.descriptorSetLayoutData.descriptorBlocks) { + for (let i = 0; i !== block.descriptors.length; ++i) { + if (descriptorID === block.descriptors[i].descriptorID) { + layoutDesc.bindTexture(block.offset + i, gfxTex); + const renderData = context.renderGraph.getData(this._vertID); + layoutDesc.bindSampler(block.offset + i, renderData.samplers.get(descriptorID) || context.device.getSampler(samplerInfo)); + if (!this._descriptorSet) this._descriptorSet = layoutDesc; + continue; } } } @@ -633,6 +629,7 @@ class RenderPassLayoutInfo { } get descriptorSet (): DescriptorSet | null { return this._descriptorSet; } get layoutID (): number { return this._layoutID; } + get vertID (): number { return this._vertID; } get stage (): RenderStageData | null { return this._stage; } get layout (): PipelineLayoutData { return this._layout; } } @@ -842,7 +839,7 @@ class DeviceRenderPass { const layoutGraph = context.layoutGraph; const stageId = layoutGraph.locateChild(layoutGraph.nullVertex(), stageName); if (stageId !== 0xFFFFFFFF) { - this._layout = new RenderPassLayoutInfo(stageId, input); + this._layout = new RenderPassLayoutInfo(stageId, this.rasterPassInfo.id, input); } } } From d75fb4e1b542efdd4a593f7d05c915aa66e48237 Mon Sep 17 00:00:00 2001 From: qiuguohua Date: Mon, 25 Sep 2023 09:59:59 +0800 Subject: [PATCH 05/31] OpenHarmony platform modification configuration update rules (#16320) * 1.Rules for modifying configuration changes 2.Update app name * Modify variable name --- scripts/native-pack-tool/source/platforms/openharmony.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/native-pack-tool/source/platforms/openharmony.ts b/scripts/native-pack-tool/source/platforms/openharmony.ts index 45af3334f3a..6dbbad129db 100644 --- a/scripts/native-pack-tool/source/platforms/openharmony.ts +++ b/scripts/native-pack-tool/source/platforms/openharmony.ts @@ -47,8 +47,8 @@ export class OpenHarmonyPackTool extends NativePackTool { // entry/build-profile.json5 const buildCfgFile = ps.join(ohosProjDir, 'entry/build-profile.json5'); await cchelper.replaceInFile([ - { reg: '={DRES_DIR}', text: `=${cchelper.fixPath(this.paths.buildDir!)}` }, - { reg: '={DCOMMON_DIR}', text: `=${cchelper.fixPath(process.env.COMMON_DIR || '')}` }, + { reg: 'DRES_DIR=[^ ]*', text: `DRES_DIR=${cchelper.fixPath(this.paths.buildDir!)}` }, + { reg: 'DCOMMON_DIR=[^ ]*', text: `DCOMMON_DIR=${cchelper.fixPath(process.env.COMMON_DIR || '')}` }, { reg: /"compileSdkVersion": *,/, text: `"compileSdkVersion": ${platformParams.apiLevel},}` }, ], buildCfgFile); @@ -94,6 +94,11 @@ export class OpenHarmonyPackTool extends NativePackTool { configJSON.app.bundleName = platformParams.packageName; outputJSONSync(cfgFile, configJSON, { spaces: 2 }); + const appScopeStringJSONPath = ps.join(ohosProjDir, 'AppScope/resources/base/element/string.json'); + const appScopeStringJSON = fs.readJSONSync(appScopeStringJSONPath); + appScopeStringJSON.string.find((item: any) => item.name === 'app_name').value = this.params.projectName; + outputJSONSync(appScopeStringJSONPath, appScopeStringJSON, { spaces: 2 }); + const stringJSONPath = ps.join(ohosProjDir, 'entry/src/main/resources/base/element/string.json'); const stringJSON = fs.readJSONSync(stringJSONPath); stringJSON.string.find((item: any) => item.name === 'MainAbility_label').value = this.params.projectName; From 312a4b294bbe760dd1972a4f7cc14ac303fe7e5b Mon Sep 17 00:00:00 2001 From: jk20012001 Date: Tue, 26 Sep 2023 14:30:35 +0800 Subject: [PATCH 06/31] better tips for float output macro (#16335) --- cocos/core/platform/macro.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/core/platform/macro.ts b/cocos/core/platform/macro.ts index c27506d7dd4..612e15e4a0e 100644 --- a/cocos/core/platform/macro.ts +++ b/cocos/core/platform/macro.ts @@ -987,9 +987,9 @@ interface Macro { /** * @en - * Used to set float output, the default value is false. + * Used to set float output render target, more accurate multiple light sources, fog, and translucent effects, custom pipeline only, the default value is false. * @zh - * 用于开启浮点格式的输出, 默认值为 false。 + * 用于开启浮点格式的RT输出, 更精确的多光源、雾化和半透明效果, 仅用于自定义管线, 默认值为 false。 * @default false */ ENABLE_FLOAT_OUTPUT: boolean; From d437903c866e23dad008ba5c1fa1373601ac0b8e Mon Sep 17 00:00:00 2001 From: Ling Zhan Date: Tue, 26 Sep 2023 17:32:54 +0800 Subject: [PATCH 07/31] [fix] box2d-wasm joint2d null check (#16337) --- cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts | 8 ++++++-- cocos/physics-2d/box2d-wasm/joints/spring-joint.ts | 9 ++++++--- cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts | 8 ++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts b/cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts index 6084d7e55c5..32ea72a8a65 100644 --- a/cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts +++ b/cocos/physics-2d/box2d-wasm/joints/fixed-joint.ts @@ -30,10 +30,14 @@ import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types'; export class B2FixedJoint extends B2Joint implements IFixedJoint { setFrequency (v: number): void { - (this._b2joint as B2.WeldJoint).SetFrequency(v); + if (this._b2joint) { + (this._b2joint as B2.WeldJoint).SetFrequency(v); + } } setDampingRatio (v: number): void { - (this._b2joint as B2.WeldJoint).SetDampingRatio(v); + if (this._b2joint) { + (this._b2joint as B2.WeldJoint).SetDampingRatio(v); + } } _createJointDef (): any { diff --git a/cocos/physics-2d/box2d-wasm/joints/spring-joint.ts b/cocos/physics-2d/box2d-wasm/joints/spring-joint.ts index e0ca9102b88..81e9451c6bf 100644 --- a/cocos/physics-2d/box2d-wasm/joints/spring-joint.ts +++ b/cocos/physics-2d/box2d-wasm/joints/spring-joint.ts @@ -30,12 +30,15 @@ import { PHYSICS_2D_PTM_RATIO } from '../../framework/physics-types'; export class B2SpringJoint extends B2Joint implements ISpringJoint { setFrequency (v: number): void { - (this._b2joint as B2.DistanceJoint).SetFrequency(v); + if (this._b2joint) { + (this._b2joint as B2.DistanceJoint).SetFrequency(v); + } } setDampingRatio (v: number): void { - //this.updateStiffnessAndDamping(); - (this._b2joint as B2.DistanceJoint).SetDampingRatio(v); + if (this._b2joint) { + (this._b2joint as B2.DistanceJoint).SetDampingRatio(v); + } } setDistance (v: number): void { diff --git a/cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts b/cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts index c2faa6e1654..9f8625ae944 100644 --- a/cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts +++ b/cocos/physics-2d/box2d-wasm/joints/wheel-joint.ts @@ -31,10 +31,14 @@ import { toRadian } from '../../../core'; export class B2WheelJoint extends B2Joint implements IWheelJoint { setFrequency (v: number): void { - (this._b2joint as B2.WheelJoint as any).SetSpringFrequencyHz(v); + if (this._b2joint) { + (this._b2joint as B2.WheelJoint as any).SetSpringFrequencyHz(v); + } } setDampingRatio (v: number): void { - (this._b2joint as B2.WheelJoint as any).SetSpringDampingRatio(v); + if (this._b2joint) { + (this._b2joint as B2.WheelJoint as any).SetSpringDampingRatio(v); + } } // motor From 91f5ea9cbf0d40ef5ad51f0bf6304ec77183faba Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 7 Oct 2023 15:33:56 +0800 Subject: [PATCH 08/31] Fix ndk version in ci script (#16357) --- .github/workflows/native-bindings.yml | 2 ++ .github/workflows/native-compile-platforms.yml | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/native-bindings.yml b/.github/workflows/native-bindings.yml index 52d014120a1..b469dcb7866 100644 --- a/.github/workflows/native-bindings.yml +++ b/.github/workflows/native-bindings.yml @@ -28,6 +28,8 @@ jobs: add-to-path: false local-cache: true - name: Generate decorators + env: + ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | cd native echo "Generate compile_commands.json & ninja target" diff --git a/.github/workflows/native-compile-platforms.yml b/.github/workflows/native-compile-platforms.yml index e17a552204b..ef25d930929 100644 --- a/.github/workflows/native-compile-platforms.yml +++ b/.github/workflows/native-compile-platforms.yml @@ -85,7 +85,7 @@ jobs: COCOS_ENGINE_DEV: 1 run: | NATIVE_ROOT=$GITHUB_WORKSPACE/native - ANDORID_NDK=$ANDROID_NDK_LATEST_HOME + ANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }} NATIVE_DIR=$GITHUB_WORKSPACE/templates/android-template echo "Compiling Android ... " cd $GITHUB_WORKSPACE/templates/ @@ -112,7 +112,7 @@ jobs: ASSET_DIR=$GITHUB_WORKSPACE/templates/android/build/build-android/ - sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDORID_NDK@g" gradle.properties + sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDROID_NDK@g" gradle.properties sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties @@ -123,7 +123,7 @@ jobs: sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=arm64-v8a@g" gradle.properties echo "Compile Android - cmake ..." - echo "ANDORID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}" + echo "ANDROID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}" # ./gradlew :CocosGame:assembleDebug --quiet ./gradlew :CocosGame:assembleRelease --quiet echo "Compile Android Debug Done!" @@ -156,7 +156,7 @@ jobs: COCOS_ENGINE_DEV: 1 run: | NATIVE_ROOT=$GITHUB_WORKSPACE/native - ANDORID_NDK=$ANDROID_NDK_LATEST_HOME + ANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }} NATIVE_DIR=$GITHUB_WORKSPACE/templates/android-template echo "Compiling Android ... " cd $GITHUB_WORKSPACE/templates/ @@ -187,7 +187,7 @@ jobs: ASSET_DIR=$GITHUB_WORKSPACE/templates/android/build/build-android/ - sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDORID_NDK@g" gradle.properties + sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDROID_NDK@g" gradle.properties sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties @@ -199,7 +199,7 @@ jobs: sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=arm64-v8a@g" gradle.properties echo "Compile Android - cmake ..." - echo "ANDORID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}" + echo "ANDROID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}" ./gradlew :CocosGame:assembleDebug --quiet df -h ./gradlew clean From 23ca385cae61e378c01d254d5e1b9dbc81d05074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Sat, 7 Oct 2023 16:13:49 +0800 Subject: [PATCH 09/31] Autofix physics lint problems (#16323) * Autofix physics lint problems * Fix lint * Opt --- .../bullet-configurable-constraint.ts | 24 +++++++++++++++---- cocos/physics/cannon/cannon-rigid-body.ts | 2 +- .../character-controller.ts | 19 +++++++++++---- .../components/colliders/collider.ts | 19 +++++++++++---- cocos/physics/framework/deprecated.ts | 2 +- .../physx/joints/physx-configurable-joint.ts | 24 +++++++++++++++---- .../physx/joints/physx-revolute-joint.ts | 20 ++++++++++++---- cocos/physics/physx/shapes/physx-box-shape.ts | 2 +- .../physx/shapes/physx-capsule-shape.ts | 2 +- .../physics/physx/shapes/physx-cone-shape.ts | 2 +- .../physx/shapes/physx-terrain-shape.ts | 2 +- cocos/physics/spec/i-rigid-body.ts | 2 +- 12 files changed, 89 insertions(+), 31 deletions(-) diff --git a/cocos/physics/bullet/constraints/bullet-configurable-constraint.ts b/cocos/physics/bullet/constraints/bullet-configurable-constraint.ts index 1715e442dc8..0a3cd59490b 100644 --- a/cocos/physics/bullet/constraints/bullet-configurable-constraint.ts +++ b/cocos/physics/bullet/constraints/bullet-configurable-constraint.ts @@ -378,11 +378,25 @@ export class BulletConfigurableConstraint extends BulletConstraint implements IC const axisY = cs.secondaryAxis; const axisZ = Vec3.cross(CC_V3_1, axisX, axisY); - const mat = Mat4.set(CC_MAT4_0, - axisX.x, axisX.y, axisX.z, 0, - axisY.x, axisY.y, axisY.z, 0, - axisZ.x, axisZ.y, axisZ.z, 0, - 0, 0, 0, 1); + const mat = Mat4.set( + CC_MAT4_0, + axisX.x, + axisX.y, + axisX.z, + 0, + axisY.x, + axisY.y, + axisY.z, + 0, + axisZ.x, + axisZ.y, + axisZ.z, + 0, + 0, + 0, + 0, + 1, + ); mat.getRotation(rot_0); cocos2BulletQuat(quat, rot_0); diff --git a/cocos/physics/cannon/cannon-rigid-body.ts b/cocos/physics/cannon/cannon-rigid-body.ts index a484fbc3732..ece520a13d7 100644 --- a/cocos/physics/cannon/cannon-rigid-body.ts +++ b/cocos/physics/cannon/cannon-rigid-body.ts @@ -102,7 +102,7 @@ export class CannonRigidBody implements IRigidBody { this._wakeUpIfSleep(); } - useCCD (value:boolean): void { + useCCD (value: boolean): void { this.impl.ccdSpeedThreshold = value ? 0.01 : -1; } diff --git a/cocos/physics/framework/components/character-controllers/character-controller.ts b/cocos/physics/framework/components/character-controllers/character-controller.ts index ef6a0509058..6f455bb709e 100644 --- a/cocos/physics/framework/components/character-controllers/character-controller.ts +++ b/cocos/physics/framework/components/character-controllers/character-controller.ts @@ -37,6 +37,8 @@ import { PhysicsSystem } from '../../physics-system'; const v3_0 = new Vec3(0, 0, 0); const scaledCenter = new Vec3(0, 0, 0); +type Callback = (...args: any[]) => any; + /** * @en * Base class for Character Controller component. @@ -374,8 +376,12 @@ export class CharacterController extends Eventify(Component) { * @param callback - The event callback, signature:`(event?:ICollisionEvent|ITriggerEvent)=>void`. * @param target - The event callback target. */ - public on void>(type: CharacterTriggerEventType | CharacterCollisionEventType, - callback: TFunction, target?, once?: boolean): any { + public on ( + type: CharacterTriggerEventType | CharacterCollisionEventType, + callback: TFunction, + target?, + once?: boolean, + ): any { const ret = super.on(type, callback, target, once); this._updateNeedEvent(type); return ret; @@ -390,7 +396,7 @@ export class CharacterController extends Eventify(Component) { * @param callback - The event callback, signature:`(event?:ICollisionEvent|ITriggerEvent)=>void`. * @param target - The event callback target. */ - public off (type: CharacterTriggerEventType | CharacterCollisionEventType, callback?: (...any) => void, target?): void { + public off (type: CharacterTriggerEventType | CharacterCollisionEventType, callback?: Callback, target?): void { super.off(type, callback, target); this._updateNeedEvent(); } @@ -404,8 +410,11 @@ export class CharacterController extends Eventify(Component) { * @param callback - The event callback, signature:`(event?:ICollisionEvent|ITriggerEvent)=>void`. * @param target - The event callback target. */ - public once void>(type: CharacterTriggerEventType | CharacterCollisionEventType, - callback: TFunction, target?): any { + public once ( + type: CharacterTriggerEventType | CharacterCollisionEventType, + callback: TFunction, + target?, + ): any { // TODO: callback invoker now is a entity, after `once` will not calling the upper `off`. const ret = super.once(type, callback, target); this._updateNeedEvent(type); diff --git a/cocos/physics/framework/components/colliders/collider.ts b/cocos/physics/framework/components/colliders/collider.ts index 8caffad63e7..01416b0be3a 100644 --- a/cocos/physics/framework/components/colliders/collider.ts +++ b/cocos/physics/framework/components/colliders/collider.ts @@ -34,6 +34,8 @@ import { IBaseShape } from '../../../spec/i-physics-shape'; import { EColliderType, EAxisDirection } from '../../physics-enum'; import { selector, createShape } from '../../physics-selector'; +type Callback = (...args: any[]) => any; + /** * @en * Base class for colliders. @@ -248,8 +250,12 @@ export class Collider extends Eventify(Component) { * @param callback - The event callback, signature:`(event?:ICollisionEvent|ITriggerEvent)=>void`. * @param target - The event callback target. */ - public on void>(type: TriggerEventType | CollisionEventType | CharacterTriggerEventType, - callback: TFunction, target?, once?: boolean): any { + public on ( + type: TriggerEventType | CollisionEventType | CharacterTriggerEventType, + callback: TFunction, + target?, + once?: boolean, + ): any { const ret = super.on(type, callback, target, once); this._updateNeedEvent(type); return ret; @@ -264,7 +270,7 @@ export class Collider extends Eventify(Component) { * @param callback - The event callback, signature:`(event?:ICollisionEvent|ITriggerEvent)=>void`. * @param target - The event callback target. */ - public off (type: TriggerEventType | CollisionEventType | CharacterTriggerEventType, callback?: (...any) => void, target?): void { + public off (type: TriggerEventType | CollisionEventType | CharacterTriggerEventType, callback?: Callback, target?): void { super.off(type, callback, target); this._updateNeedEvent(); } @@ -278,8 +284,11 @@ export class Collider extends Eventify(Component) { * @param callback - The event callback, signature:`(event?:ICollisionEvent|ITriggerEvent)=>void`. * @param target - The event callback target. */ - public once void>(type: TriggerEventType | CollisionEventType | CharacterTriggerEventType, - callback: TFunction, target?): any { + public once ( + type: TriggerEventType | CollisionEventType | CharacterTriggerEventType, + callback: TFunction, + target?, + ): any { // TODO: callback invoker now is a entity, after `once` will not calling the upper `off`. const ret = super.once(type, callback, target); this._updateNeedEvent(type); diff --git a/cocos/physics/framework/deprecated.ts b/cocos/physics/framework/deprecated.ts index 6a9d9519d11..9854068b7c8 100644 --- a/cocos/physics/framework/deprecated.ts +++ b/cocos/physics/framework/deprecated.ts @@ -150,7 +150,7 @@ removeProperty(RigidBody.prototype, 'RigidBody.prototype', [ removeProperty(EConstraintType, 'EConstraintType.prototype', [ { - name: 'CONE_TWIST', + name: 'CONE_TWIST', }, ]); diff --git a/cocos/physics/physx/joints/physx-configurable-joint.ts b/cocos/physics/physx/joints/physx-configurable-joint.ts index 76c6648c991..1415b712c19 100644 --- a/cocos/physics/physx/joints/physx-configurable-joint.ts +++ b/cocos/physics/physx/joints/physx-configurable-joint.ts @@ -374,11 +374,25 @@ export class PhysXConfigurableJoint extends PhysXJoint implements IConfigurableC const axisZ = Vec3.cross(CC_V3_0, axisX, axisY); const _rot = CC_QUAT_0; - const mat = Mat4.set(CC_MAT4_0, - axisX.x, axisX.y, axisX.z, 0, - axisY.x, axisY.y, axisY.z, 0, - axisZ.x, axisZ.y, axisZ.z, 0, - 0, 0, 0, 1); + const mat = Mat4.set( + CC_MAT4_0, + axisX.x, + axisX.y, + axisX.z, + 0, + axisY.x, + axisY.y, + axisY.z, + 0, + axisZ.x, + axisZ.y, + axisZ.z, + 0, + 0, + 0, + 0, + 1, + ); mat.getRotation(_rot); Vec3.multiply(pos, cs.node.worldScale, cs.pivotA); diff --git a/cocos/physics/physx/joints/physx-revolute-joint.ts b/cocos/physics/physx/joints/physx-revolute-joint.ts index 83d2c12aeb4..1ee3c476f4f 100644 --- a/cocos/physics/physx/joints/physx-revolute-joint.ts +++ b/cocos/physics/physx/joints/physx-revolute-joint.ts @@ -136,10 +136,22 @@ export class PhysXRevoluteJoint extends PhysXJoint implements IHingeConstraint { Vec3.normalize(v3_2, v3_2); mat_0.set( - v3_0.x, v3_0.y, v3_0.z, 0, // x - v3_1.x, v3_1.y, v3_1.z, 0, // y - v3_2.x, v3_2.y, v3_2.z, 0, // z - 0, 0, 0, 1, + v3_0.x, + v3_0.y, + v3_0.z, + 0, // x + v3_1.x, + v3_1.y, + v3_1.z, + 0, // y + v3_2.x, + v3_2.y, + v3_2.z, + 0, // z + 0, + 0, + 0, + 1, ); mat_0.getRotation(quat_0); diff --git a/cocos/physics/physx/shapes/physx-box-shape.ts b/cocos/physics/physx/shapes/physx-box-shape.ts index ddbbd684cf5..98836ffd46f 100644 --- a/cocos/physics/physx/shapes/physx-box-shape.ts +++ b/cocos/physics/physx/shapes/physx-box-shape.ts @@ -50,7 +50,7 @@ export class PhysXBoxShape extends PhysXShape implements IBoxShape { onComponentSet (): void { this.updateGeometry(); - const pxmat = this.getSharedMaterial(this._collider.sharedMaterial!); + const pxmat = this.getSharedMaterial(this._collider.sharedMaterial); this._impl = PhysXInstance.physics.createShape(PhysXBoxShape.BOX_GEOMETRY, pxmat, true, this._flags); } diff --git a/cocos/physics/physx/shapes/physx-capsule-shape.ts b/cocos/physics/physx/shapes/physx-capsule-shape.ts index a56b6972ae9..aa22f904ea1 100644 --- a/cocos/physics/physx/shapes/physx-capsule-shape.ts +++ b/cocos/physics/physx/shapes/physx-capsule-shape.ts @@ -57,7 +57,7 @@ export class PhysXCapsuleShape extends PhysXShape implements ICapsuleShape { onComponentSet (): void { this.updateGeometry(); - const pxmat = this.getSharedMaterial(this._collider.sharedMaterial!); + const pxmat = this.getSharedMaterial(this._collider.sharedMaterial); this._impl = PhysXInstance.physics.createShape(PhysXCapsuleShape.CAPSULE_GEOMETRY, pxmat, true, this._flags); } diff --git a/cocos/physics/physx/shapes/physx-cone-shape.ts b/cocos/physics/physx/shapes/physx-cone-shape.ts index 4925ef17e14..8caa2eba1a2 100644 --- a/cocos/physics/physx/shapes/physx-cone-shape.ts +++ b/cocos/physics/physx/shapes/physx-cone-shape.ts @@ -66,7 +66,7 @@ export class PhysXConeShape extends PhysXShape implements IConeShape { meshScale.setScale(Vec3.ONE); meshScale.setRotation(Quat.IDENTITY); const convexMesh = PhysXConeShape.CONVEX_MESH; - const pxmat = this.getSharedMaterial(collider.sharedMaterial!); + const pxmat = this.getSharedMaterial(collider.sharedMaterial); this.geometry = new PX.ConvexMeshGeometry(convexMesh, meshScale, createMeshGeometryFlags(0, true)); this.updateGeometry(); this._impl = physics.createShape(this.geometry, pxmat, true, this._flags); diff --git a/cocos/physics/physx/shapes/physx-terrain-shape.ts b/cocos/physics/physx/shapes/physx-terrain-shape.ts index e662b7d93a8..960300e8abc 100644 --- a/cocos/physics/physx/shapes/physx-terrain-shape.ts +++ b/cocos/physics/physx/shapes/physx-terrain-shape.ts @@ -46,7 +46,7 @@ export class PhysXTerrainShape extends PhysXShape implements ITerrainShape { PX.TERRAIN_STATIC[v._uuid] = createHeightField(v, PhysXTerrainShape.heightScale, cooking, physics); } const hf = PX.TERRAIN_STATIC[v._uuid]; - const pxmat = this.getSharedMaterial(collider.sharedMaterial!); + const pxmat = this.getSharedMaterial(collider.sharedMaterial); const geometry = createHeightFieldGeometry(hf, 0, PhysXTerrainShape.heightScale, v.tileSize, v.tileSize); this._impl = physics.createShape(geometry, pxmat, true, this._flags); this.updateByReAdd(); diff --git a/cocos/physics/spec/i-rigid-body.ts b/cocos/physics/spec/i-rigid-body.ts index d7287a3ef0b..1041b920572 100644 --- a/cocos/physics/spec/i-rigid-body.ts +++ b/cocos/physics/spec/i-rigid-body.ts @@ -53,7 +53,7 @@ export interface IRigidBody extends ILifecycle, IGroupMask { clearVelocity (): void; setSleepThreshold (v: number): void; getSleepThreshold (): number; - useCCD: (v:boolean) => void; + useCCD: (v: boolean) => void; isUsingCCD: () => boolean; getLinearVelocity (out: IVec3Like): void; From 461c4fe5ee7b3bfdf2524ede540ad64ede163b17 Mon Sep 17 00:00:00 2001 From: dogeFu <609075410@qq.com> Date: Sat, 7 Oct 2023 16:50:33 +0800 Subject: [PATCH 10/31] fix : terrain paint error after save file in editor (#16343) --- cocos/terrain/terrain.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/terrain/terrain.ts b/cocos/terrain/terrain.ts index e973a6b2e71..6711c4af64e 100644 --- a/cocos/terrain/terrain.ts +++ b/cocos/terrain/terrain.ts @@ -1997,7 +1997,7 @@ export class Terrain extends Component { if (EDITOR && this._asset) { this._asset.weights[index * 4 + 0] = w.x * 255; this._asset.weights[index * 4 + 1] = w.y * 255; - this._asset.weights[index * 4 + 2] = w.x * 255; + this._asset.weights[index * 4 + 2] = w.z * 255; this._asset.weights[index * 4 + 3] = w.w * 255; } } From 3d65154e617365171897315af79fae0b27110081 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 7 Oct 2023 16:54:41 +0800 Subject: [PATCH 11/31] Fix ndk version in ci script (#16356) * Fix ndk version in ci script * Fix typo of ANDROID_NDK in ci script * Update ci script, free space for android build * Don't clear android tools --- .github/workflows/native-bindings.yml | 2 ++ .../workflows/native-compile-platforms.yml | 31 +++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.github/workflows/native-bindings.yml b/.github/workflows/native-bindings.yml index faa4fede9c1..2a896a8a9db 100644 --- a/.github/workflows/native-bindings.yml +++ b/.github/workflows/native-bindings.yml @@ -27,6 +27,8 @@ jobs: ndk-version: r21e add-to-path: false - name: Generate decorators + env: + ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | cd native echo "Generate compile_commands.json & ninja target" diff --git a/.github/workflows/native-compile-platforms.yml b/.github/workflows/native-compile-platforms.yml index 953f4c0bcb1..f3d63c303c1 100644 --- a/.github/workflows/native-compile-platforms.yml +++ b/.github/workflows/native-compile-platforms.yml @@ -84,7 +84,7 @@ jobs: COCOS_ENGINE_DEV: 1 run: | NATIVE_ROOT=$GITHUB_WORKSPACE/native - ANDORID_NDK=$ANDROID_NDK_LATEST_HOME + ANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }} NATIVE_DIR=$GITHUB_WORKSPACE/templates/android-template echo "Compiling Android ... " cd $GITHUB_WORKSPACE/templates/ @@ -111,7 +111,7 @@ jobs: ASSET_DIR=$GITHUB_WORKSPACE/templates/android/build/build-android/ - sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDORID_NDK@g" gradle.properties + sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDROID_NDK@g" gradle.properties sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties @@ -122,7 +122,7 @@ jobs: sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=arm64-v8a@g" gradle.properties echo "Compile Android - cmake ..." - echo "ANDORID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}" + echo "ANDROID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}" # ./gradlew :CocosGame:assembleDebug --quiet ./gradlew :CocosGame:assembleRelease --quiet echo "Compile Android Debug Done!" @@ -133,6 +133,25 @@ jobs: (! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration')) runs-on: ubuntu-latest steps: + - name: Before free space + run: | + df -h + + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@d5af243ce7bacb67384aa6c5b1fc5f169e30903e + with: + tool-cache: true + android: false + dotnet: true + haskell: true + large-packages: true + docker-images: true + swap-storage: true + + - name: After free space + run: | + df -h + - uses: actions/checkout@v2 - name: Download external libraries shell: bash @@ -154,7 +173,7 @@ jobs: COCOS_ENGINE_DEV: 1 run: | NATIVE_ROOT=$GITHUB_WORKSPACE/native - ANDORID_NDK=$ANDROID_NDK_LATEST_HOME + ANDROID_NDK=${{ steps.setup-ndk.outputs.ndk-path }} NATIVE_DIR=$GITHUB_WORKSPACE/templates/android-template echo "Compiling Android ... " cd $GITHUB_WORKSPACE/templates/ @@ -185,7 +204,7 @@ jobs: ASSET_DIR=$GITHUB_WORKSPACE/templates/android/build/build-android/ - sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDORID_NDK@g" gradle.properties + sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDROID_NDK@g" gradle.properties sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties @@ -196,7 +215,7 @@ jobs: sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=armeabi-v7a:arm64-v8a@g" gradle.properties echo "Compile Android - cmake ..." - echo "ANDORID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}" + echo "ANDROID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}" ./gradlew :CocosGame:assembleDebug --quiet echo "Compile Android Debug Done!" From 7a8bde3ace9f145ab255df6e06386a3a4ee19ee0 Mon Sep 17 00:00:00 2001 From: PP Date: Sun, 8 Oct 2023 10:47:56 +0800 Subject: [PATCH 12/31] fix: load script packages before loading builtin assets (#16339) * fix: load script packages before loading builtin assets * fix eslint * fix ci * Revert "fix ci" This reverts commit 38584722e93c5823684be31dbb796bb3908b4703. * add errorID logID --- EngineErrorMap.md | 8 ++++++++ cocos/game/game.ts | 36 ++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/EngineErrorMap.md b/EngineErrorMap.md index 2302385d19e..0b373c2aa2c 100644 --- a/EngineErrorMap.md +++ b/EngineErrorMap.md @@ -168,6 +168,14 @@ Expected 'data' dict, but not found. Config file: %s Please load the resource first : %s +### 1102 + +Effect settings not found, effects will not be imported. + +### 1103 + +Success to load scene: %s + ### 1200 cocos2d: Director: Error in gettimeofday diff --git a/cocos/game/game.ts b/cocos/game/game.ts index 14086b18be7..954f9a6459e 100644 --- a/cocos/game/game.ts +++ b/cocos/game/game.ts @@ -29,7 +29,7 @@ import { findCanvas, loadJsFile } from 'pal/env'; import { Pacer } from 'pal/pacer'; import { ConfigOrientation } from 'pal/screen-adapter'; import assetManager, { IAssetManagerOptions } from '../asset/asset-manager/asset-manager'; -import { EventTarget, AsyncDelegate, sys, macro, VERSION, cclegacy, screen, Settings, settings, assert, garbageCollectionManager, DebugMode, warn, log, _resetDebugSetting } from '../core'; +import { EventTarget, AsyncDelegate, sys, macro, VERSION, cclegacy, screen, Settings, settings, assert, garbageCollectionManager, DebugMode, warn, log, _resetDebugSetting, errorID, logID } from '../core'; import { input } from '../input'; import { deviceManager, LegacyRenderMode } from '../gfx'; import { SplashScreen } from './splash-screen'; @@ -723,6 +723,7 @@ export class Game extends EventTarget { }) .then((): void => { if (DEBUG) { + // eslint-disable-next-line no-console console.time('Init Base'); } const debugMode = config.debugMode || DebugMode.NONE; @@ -735,6 +736,7 @@ export class Game extends EventTarget { .then((): Promise => settings.init(config.settingsPath, config.overrideSettings)) .then((): Promise => { if (DEBUG) { + // eslint-disable-next-line no-console console.timeEnd('Init Base'); } this.emit(Game.EVENT_POST_BASE_INIT); @@ -748,6 +750,7 @@ export class Game extends EventTarget { }) .then((): void => { if (DEBUG) { + // eslint-disable-next-line no-console console.time('Init Infrastructure'); } macro.init(); @@ -769,6 +772,7 @@ export class Game extends EventTarget { Layers.init(); this.initPacer(); if (DEBUG) { + // eslint-disable-next-line no-console console.timeEnd('Init Infrastructure'); } }) @@ -795,13 +799,21 @@ export class Game extends EventTarget { } const data = effectSettings.data; if (data === null) { - console.error('Effect settings not found, effects will not be imported.'); + errorID(1102); return; } cclegacy.rendering.init(deviceManager.gfxDevice, data); }) + .then((): Promise => { + const scriptPackages = settings.querySettings(Settings.Category.SCRIPTING, 'scriptPackages'); + if (scriptPackages) { + return Promise.all(scriptPackages.map((pack): Promise => import(pack))); + } + return Promise.resolve([]); + }) .then((): Promise => { if (DEBUG) { + // eslint-disable-next-line no-console console.time('Init SubSystem'); } director.init(); @@ -809,13 +821,14 @@ export class Game extends EventTarget { }) .then((): Promise => { if (DEBUG) { + // eslint-disable-next-line no-console console.timeEnd('Init SubSystem'); } this.emit(Game.EVENT_POST_SUBSYSTEM_INIT); return this.onPostSubsystemInitDelegate.dispatch(); }) .then((): void => { - console.log(`Cocos Creator v${VERSION}`); + log(`Cocos Creator v${VERSION}`); this.emit(Game.EVENT_ENGINE_INITED); this._engineInited = true; }) @@ -827,6 +840,7 @@ export class Game extends EventTarget { }) .then((): Promise => { if (DEBUG) { + // eslint-disable-next-line no-console console.time('Init Project'); } const jsList = settings.querySettings(Settings.Category.PLUGINS, 'jsList'); @@ -838,13 +852,6 @@ export class Game extends EventTarget { } return promise; }) - .then((): Promise => { - const scriptPackages = settings.querySettings(Settings.Category.SCRIPTING, 'scriptPackages'); - if (scriptPackages) { - return Promise.all(scriptPackages.map((pack): Promise => import(pack))); - } - return Promise.resolve([]); - }) .then((): Promise => this._loadProjectBundles()) .then((): Promise => this._loadCCEScripts()) .then((): void | Promise => this._setupRenderPipeline()) @@ -855,6 +862,7 @@ export class Game extends EventTarget { }) .then((): Promise => { if (DEBUG) { + // eslint-disable-next-line no-console console.timeEnd('Init Project'); } this.emit(Game.EVENT_POST_PROJECT_INIT); @@ -1013,11 +1021,11 @@ export class Game extends EventTarget { SplashScreen.instance.update(this._calculateDT(false)); } else if (this._shouldLoadLaunchScene) { this._shouldLoadLaunchScene = false; - const launchScene = settings.querySettings(Settings.Category.LAUNCH, 'launchScene'); + const launchScene = settings.querySettings(Settings.Category.LAUNCH, 'launchScene') as string; if (launchScene) { // load scene director.loadScene(launchScene, (): void => { - console.log(`Success to load scene: ${launchScene}`); + logID(1103, launchScene); this._initTime = performance.now(); director.startAnimation(); this.onStart?.(); @@ -1098,7 +1106,7 @@ export class Game extends EventTarget { } private _setupRenderPipeline (): void | Promise { - const renderPipeline = settings.querySettings(Settings.Category.RENDERING, 'renderPipeline'); + const renderPipeline = settings.querySettings(Settings.Category.RENDERING, 'renderPipeline') as string; if (!renderPipeline) { return this._setRenderPipeline(); } @@ -1124,7 +1132,7 @@ export class Game extends EventTarget { this._safeEmit(Game.EVENT_RENDERER_INITED); } - private _safeEmit (event): void { + private _safeEmit (event: string | number): void { if (EDITOR) { try { this.emit(event); From 956d71343efeb031d709731e20fa16f6d6767fcf Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Sun, 8 Oct 2023 11:12:50 +0800 Subject: [PATCH 13/31] [Fixed] web pipeline framebuffer resize issue. (#16321) --- cocos/gfx/base/framebuffer.ts | 10 ++++++++++ cocos/gfx/webgl/webgl-framebuffer.ts | 2 ++ cocos/gfx/webgl2/webgl2-framebuffer.ts | 2 ++ cocos/rendering/custom/executor.ts | 22 ++++++++++++++++++++-- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cocos/gfx/base/framebuffer.ts b/cocos/gfx/base/framebuffer.ts index 71c04e1f54b..d609db6bd67 100644 --- a/cocos/gfx/base/framebuffer.ts +++ b/cocos/gfx/base/framebuffer.ts @@ -55,9 +55,19 @@ export abstract class Framebuffer extends GFXObject { return this._depthStencilTexture; } + public get width (): number { + return this._width; + } + + public get height (): number { + return this._height; + } + protected _renderPass: RenderPass | null = null; protected _colorTextures: (Texture | null)[] = []; protected _depthStencilTexture: Texture | null = null; + protected _width: number = 0; + protected _height: number = 0; constructor () { super(ObjectType.FRAMEBUFFER); diff --git a/cocos/gfx/webgl/webgl-framebuffer.ts b/cocos/gfx/webgl/webgl-framebuffer.ts index aeab6338e91..448239c19c6 100644 --- a/cocos/gfx/webgl/webgl-framebuffer.ts +++ b/cocos/gfx/webgl/webgl-framebuffer.ts @@ -96,6 +96,8 @@ export class WebGLFramebuffer extends Framebuffer { }; WebGLCmdFuncCreateFramebuffer(WebGLDeviceManager.instance, this._gpuFramebuffer); + this._width = this._gpuFramebuffer.width; + this._height = this._gpuFramebuffer.height; } public destroy (): void { diff --git a/cocos/gfx/webgl2/webgl2-framebuffer.ts b/cocos/gfx/webgl2/webgl2-framebuffer.ts index 255c7a9a6b3..539857308ce 100644 --- a/cocos/gfx/webgl2/webgl2-framebuffer.ts +++ b/cocos/gfx/webgl2/webgl2-framebuffer.ts @@ -90,6 +90,8 @@ export class WebGL2Framebuffer extends Framebuffer { }; WebGL2CmdFuncCreateFramebuffer(WebGL2DeviceManager.instance, this._gpuFramebuffer); + this._width = this._gpuFramebuffer.width; + this._height = this._gpuFramebuffer.height; } public destroy (): void { diff --git a/cocos/rendering/custom/executor.ts b/cocos/rendering/custom/executor.ts index bc3f28ba261..e855f90ce53 100644 --- a/cocos/rendering/custom/executor.ts +++ b/cocos/rendering/custom/executor.ts @@ -950,6 +950,25 @@ class DeviceRenderPass { if (this.renderLayout && this.renderLayout.descriptorSet) { this.renderLayout.descriptorSet.update(); } + + const resGraph = context.resourceGraph; + const currentWidth = this._framebuffer ? this._framebuffer.width : 0; + const currentHeight = this._framebuffer ? this._framebuffer.height : 0; + + let width = 0; + let height = 0; + for (const [resName, rasterV] of this._rasterInfo.pass.rasterViews) { + if (rasterV.attachmentType === AttachmentType.SHADING_RATE) { + continue; + } + const resId = resGraph.vertex(resName); + const resDesc = resGraph.getDesc(resId); + width = resDesc.width; + height = resDesc.height; + break; + } + const needRebuild = (width !== currentWidth) || (height !== currentHeight); + for (const [resName, rasterV] of this._rasterInfo.pass.rasterViews) { let deviceTex = context.deviceTextures.get(resName)!; const currTex = deviceTex; @@ -963,8 +982,7 @@ class DeviceRenderPass { const resDesc = resGraph.getDesc(resId); if (deviceTex.framebuffer && resFbo instanceof Framebuffer && deviceTex.framebuffer !== resFbo) { framebuffer = this._framebuffer = deviceTex.framebuffer = resFbo; - } else if (!currTex || (deviceTex.texture - && (deviceTex.texture.width !== resDesc.width || deviceTex.texture.height !== resDesc.height))) { + } else if (!currTex || (deviceTex.texture && needRebuild)) { const gfxTex = deviceTex.texture!; if (currTex) gfxTex.resize(resDesc.width, resDesc.height); switch (rasterV.attachmentType) { From 602fa6062764877ba9f00a6b0604f93ed8f6637b Mon Sep 17 00:00:00 2001 From: Cocos Robot <48829427+cocos-robot@users.noreply.github.com> Date: Sun, 8 Oct 2023 13:33:49 +0800 Subject: [PATCH 14/31] [ci skip][AUTO]: Automated code generating update: 5e7e390c52d505377d699389e21304d86d7ee52d (#16339) (#16360) Co-authored-by: cocos-robot --- native/cocos/core/builtin/DebugInfos.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/native/cocos/core/builtin/DebugInfos.cpp b/native/cocos/core/builtin/DebugInfos.cpp index 31ed13ab8ee..d83f1db811f 100644 --- a/native/cocos/core/builtin/DebugInfos.cpp +++ b/native/cocos/core/builtin/DebugInfos.cpp @@ -35,6 +35,8 @@ ccstd::unordered_map debugInfos = { { 1008, "[Action reverse]. override me" }, { 1100, "Expected 'data' dict, but not found. Config file: %s" }, { 1101, "Please load the resource first : %s" }, +{ 1102, "Effect settings not found, effects will not be imported." }, +{ 1103, "Success to load scene: %s" }, { 1200, "cocos2d: Director: Error in gettimeofday" }, { 1204, "Running scene should not be null" }, { 1205, "The scene should not be null" }, From d79d09557b739aae77d9908e010995152d0b83b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=88=98?= <40414978+PatriceJiang@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:16:34 +0800 Subject: [PATCH 15/31] Memleak fix (#16354) --- native/cocos/bindings/manual/jsb_conversions.h | 1 + 1 file changed, 1 insertion(+) diff --git a/native/cocos/bindings/manual/jsb_conversions.h b/native/cocos/bindings/manual/jsb_conversions.h index 580dbfb4d44..5b20a6ce951 100644 --- a/native/cocos/bindings/manual/jsb_conversions.h +++ b/native/cocos/bindings/manual/jsb_conversions.h @@ -1235,6 +1235,7 @@ inline bool nativevalue_to_se(const ccstd::vector &from, se::Value &to, se::O if constexpr (!std::is_pointer::value && is_jsb_object_v) { auto *pFrom = ccnew T(from[i]); nativevalue_to_se(pFrom, tmp, ctx); + tmp.toObject()->getPrivateObject()->tryAllowDestroyInGC(); } else { nativevalue_to_se(from[i], tmp, ctx); } From 7ccbd91d53e4558d986640e08a7bda989e1edb04 Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Mon, 9 Oct 2023 14:45:06 +0800 Subject: [PATCH 16/31] fix web (#165) * fix web * fix fg dispatcher --- cocos/rendering/custom/executor.ts | 2 +- .../pipeline/custom/FrameGraphDispatcher.cpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cocos/rendering/custom/executor.ts b/cocos/rendering/custom/executor.ts index a8c3a4695ea..5fcf5c861da 100644 --- a/cocos/rendering/custom/executor.ts +++ b/cocos/rendering/custom/executor.ts @@ -1249,7 +1249,7 @@ class DeviceComputePass { const layoutGraph = context.layoutGraph; const stageId = layoutGraph.locateChild(layoutGraph.nullVertex(), stageName); if (stageId !== 0xFFFFFFFF) { - this._layout = new RenderPassLayoutInfo(stageId, input); + this._layout = new RenderPassLayoutInfo(stageId, this._computeInfo.id, input); } } } diff --git a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp index 109be98a321..040539105b7 100644 --- a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp +++ b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp @@ -794,10 +794,15 @@ struct AttachmentSortKey { const ccstd::pmr::string &name; }; -struct AttachmentComparator { +struct SubpassComparator { bool operator()(const AttachmentSortKey &lhs, const AttachmentSortKey &rhs) const { - return std::tie(rhs.samples, lhs.accessType, lhs.attachmentWeight, lhs.slotID, lhs.slotName, lhs.name) < - std::tie(lhs.samples, rhs.accessType, rhs.attachmentWeight, rhs.slotID, rhs.slotName, rhs.name); + return std::tie(rhs.samples, lhs.accessType, lhs.attachmentWeight, lhs.name) < std::tie(lhs.samples, rhs.accessType, rhs.attachmentWeight, rhs.name); + } +}; + +struct PassComparator { + bool operator()(const AttachmentSortKey &lhs, const AttachmentSortKey &rhs) const { + return lhs.slotID < rhs.slotID; } }; @@ -1058,7 +1063,7 @@ bool checkResolveResource(const Graphs &graphs, colorMap.emplace(AttachmentSortKey{desc.sampleCount, AccessType::WRITE, ATTACHMENT_TYPE_WEIGHT[static_cast(attachmentType)], - INVALID_ID, + static_cast(colorMap.size()), "", resolveTargetName}, ViewInfo{desc.format, From 767f44a313f9091519561c34938268c31141d2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Mon, 9 Oct 2023 16:50:25 +0800 Subject: [PATCH 17/31] Bug: deserialized scene should have node transforms invalidated at initial (#16353) * Bug: deserialized scene should have node transforms invalidated * Remove transformFlags modification in _onBatchCreated --- cocos/scene-graph/node.jsb.ts | 1 - cocos/scene-graph/node.ts | 3 +-- native/cocos/core/scene-graph/Node.h | 2 +- tests/scene-graph/scene.test.ts | 26 ++++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 tests/scene-graph/scene.test.ts diff --git a/cocos/scene-graph/node.jsb.ts b/cocos/scene-graph/node.jsb.ts index a9e05315986..ce34d282197 100644 --- a/cocos/scene-graph/node.jsb.ts +++ b/cocos/scene-graph/node.jsb.ts @@ -1258,7 +1258,6 @@ nodeProto._onActiveNode = function (shouldActiveNow: boolean) { nodeProto._onBatchCreated = function (dontSyncChildPrefab: boolean) { this.hasChangedFlags = TRANSFORMBIT_TRS; - this._transformFlags |= TRANSFORMBIT_TRS; const children = this._children; const len = children.length; let child; diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 294c8d242fa..d998e492d27 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -1525,7 +1525,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { @serializable protected _euler = new Vec3(); - protected _transformFlags = TransformBit.NONE; // does the world transform need to update? + protected _transformFlags = TransformBit.TRS; // does the world transform need to update? protected _eulerDirty = false; protected _flagChangeVersion = 0; @@ -1883,7 +1883,6 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { */ public _onBatchCreated (dontSyncChildPrefab: boolean): void { this.hasChangedFlags = TransformBit.TRS; - this._transformFlags |= TransformBit.TRS; const len = this._children.length; for (let i = 0; i < len; ++i) { this._children[i]._siblingIndex = i; diff --git a/native/cocos/core/scene-graph/Node.h b/native/cocos/core/scene-graph/Node.h index d08e12fde20..38baeed0324 100644 --- a/native/cocos/core/scene-graph/Node.h +++ b/native/cocos/core/scene-graph/Node.h @@ -657,7 +657,7 @@ class Node : public CCObject { // NOTE: TypeArray created in node.jsb.ts _ctor should have the same memory layout uint32_t _eventMask{0}; // Uint32: 0 uint32_t _layer{static_cast(Layers::LayerList::DEFAULT)}; // Uint32: 1 - uint32_t _transformFlags{0}; // Uint32: 2 + uint32_t _transformFlags{static_cast(TransformBit::TRS)}; // Uint32: 2 index_t _siblingIndex{0}; // Int32: 0 uint8_t _activeInHierarchy{0}; // Uint8: 0 uint8_t _active{1}; // Uint8: 1 diff --git a/tests/scene-graph/scene.test.ts b/tests/scene-graph/scene.test.ts new file mode 100644 index 00000000000..76e1cae9e20 --- /dev/null +++ b/tests/scene-graph/scene.test.ts @@ -0,0 +1,26 @@ +import { deserialize } from "../../cocos/serialization"; +import '../utils/matchers/value-type-asymmetric-matchers'; +import { v3 } from "../../cocos/core"; +import { Scene } from "../../cocos/scene-graph"; + +test(`Bugfix cocos/cocos-engine#16352: deserialized scene should have node transforms invalidated`, () => { + const archive = [{ + __type__: 'cc.Scene', + _children: [{ + __type__: 'cc.Node', + _name: 'Node', + _lscale: { + __type__: 'cc.Vec3', + x: 2, + y: 1, + z: 1, + }, + }], + }]; + + const scene = deserialize(archive) as Scene; + + const node = scene.getChildByPath('Node')!; + expect(node).not.toBeNull(); + expect(node.worldScale).toBeCloseToVec3(v3(2, 1, 1)); +}); \ No newline at end of file From ac4ff3870ad201aa05791364764685f1fa836ef7 Mon Sep 17 00:00:00 2001 From: Zach Lee Date: Mon, 9 Oct 2023 17:44:02 +0800 Subject: [PATCH 18/31] feat:add imutable texture flag for Webgl2 (#16332) * feat:add imutable texture flag for Webgl2 * fix lint --- cocos/gfx/base/define.ts | 1 + cocos/gfx/webgl2/webgl2-commands.ts | 5 ++++- native/cocos/renderer/gfx-base/GFXDef-common.h | 1 + .../cocos/renderer/gfx-gles3/GLES3Commands.cpp | 17 ++++++++++++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cocos/gfx/base/define.ts b/cocos/gfx/base/define.ts index 235e0880c8e..627c192b7b9 100644 --- a/cocos/gfx/base/define.ts +++ b/cocos/gfx/base/define.ts @@ -409,6 +409,7 @@ export enum TextureFlagBit { EXTERNAL_NORMAL = 0x8, // External normal texture LAZILY_ALLOCATED = 0x10, // Try lazily allocated mode. MUTABLE_VIEW_FORMAT = 0x40, // texture view as different format + MUTABLE_STORAGE = 0x80, // mutable storage for gl } export enum FormatFeatureBit { diff --git a/cocos/gfx/webgl2/webgl2-commands.ts b/cocos/gfx/webgl2/webgl2-commands.ts index 80f4caab35c..7938358dc41 100644 --- a/cocos/gfx/webgl2/webgl2-commands.ts +++ b/cocos/gfx/webgl2/webgl2-commands.ts @@ -681,6 +681,7 @@ export class WebGL2CmdDraw extends WebGL2CmdObject { } public clear (): void { + // noop } } @@ -1087,6 +1088,8 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2Device, gpuTexture: IW w = Math.max(1, w >> 1); h = Math.max(1, h >> 1); } + } else if (gpuTexture.flags & TextureFlagBit.MUTABLE_STORAGE) { + gl.texImage2D(gl.TEXTURE_2D, 0, gpuTexture.glInternalFmt, w, h, 0, gpuTexture.glFormat, gpuTexture.glType, null); } else { gl.texStorage2D(gl.TEXTURE_2D, gpuTexture.mipLevel, gpuTexture.glInternalFmt, w, h); } @@ -2849,7 +2852,7 @@ export function WebGL2CmdFuncCopyTexImagesToTexture ( switch (gpuTexture.glTarget) { case gl.TEXTURE_2D: { - if (toUseTexImage2D(texImages, regions)) { + if ((gpuTexture.flags & TextureFlagBit.MUTABLE_STORAGE) || toUseTexImage2D(texImages, regions)) { gl.texImage2D( gl.TEXTURE_2D, regions[0].texSubres.mipLevel, diff --git a/native/cocos/renderer/gfx-base/GFXDef-common.h b/native/cocos/renderer/gfx-base/GFXDef-common.h index 32712dbba97..84926c05202 100644 --- a/native/cocos/renderer/gfx-base/GFXDef-common.h +++ b/native/cocos/renderer/gfx-base/GFXDef-common.h @@ -479,6 +479,7 @@ enum class TextureFlagBit : uint32_t { EXTERNAL_NORMAL = 0x8, // External normal texture LAZILY_ALLOCATED = 0x10, // Try lazily allocated mode. MUTABLE_VIEW_FORMAT = 0x40, // texture view as different format + MUTABLE_STORAGE = 0x80, // mutable storage for gl image }; using TextureFlags = TextureFlagBit; CC_ENUM_BITWISE_OPERATORS(TextureFlagBit); diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp index 2498af22fe1..6236321fddc 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp @@ -843,7 +843,12 @@ static void textureStorage(GLES3Device *device, GLES3GPUTexture *gpuTexture) { } else { auto target = hasFlag(gpuTexture->flags, TextureFlagBit::EXTERNAL_OES) ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; GL_CHECK(glBindTexture(target, gpuTexture->glTexture)); - GL_CHECK(glTexStorage2D(target, gpuTexture->mipLevel, gpuTexture->glInternalFmt, w, h)); + if (hasFlag(gpuTexture->flags, TextureFlagBit::MUTABLE_STORAGE)) { + GL_CHECK(glTexImage2D(GL_TEXTURE_2D, gpuTexture->mipLevel, gpuTexture->glInternalFmt, w, h, 0, + gpuTexture->glFormat, gpuTexture->glType, nullptr)); + } else { + GL_CHECK(glTexStorage2D(GL_TEXTURE_2D, gpuTexture->mipLevel, gpuTexture->glInternalFmt, w, h)); + } } break; case TextureType::TEX3D: @@ -2736,6 +2741,16 @@ void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const gpuTexture->glFormat, memSize, (GLvoid *)buff)); + } else if (hasFlag(gpuTexture->flags, TextureFlagBit::MUTABLE_STORAGE)) { + GL_CHECK(glTexImage2D(GL_TEXTURE_2D, + gpuTexture->mipLevel, + gpuTexture->glInternalFmt, + destWidth, + destHeight, + 0, + gpuTexture->glFormat, + gpuTexture->glType, + (GLvoid *)buff)); } else { GL_CHECK(glTexSubImage2D(GL_TEXTURE_2D, mipLevel, From 093bc8724e87de1c7407ab336857b8ae33cb665d Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 10 Oct 2023 11:06:02 +0800 Subject: [PATCH 19/31] Update v8 to 11.6.189.22 (#16364) * Update se code to adapt v8 11.4 * Fix setter * VisitHandlesWithClassIds was added again. * Remove log in evalString * Revert in ScriptEngine.cpp * Update external-config.json * Remove unused ndkPath in libcocos2dx/build.gradle * Update external config to v3.8.2-11 --- native/cocos/bindings/jswrapper/v8/Class.cpp | 27 +++++++++++++++++-- .../bindings/jswrapper/v8/ScriptEngine.cpp | 17 +++++++++++- .../bindings/jswrapper/v8/ScriptEngine.h | 9 ++++++- .../jswrapper/v8/debugger/inspector_agent.cpp | 4 +++ .../platform/android/libcocos2dx/build.gradle | 2 -- native/external-config.json | 2 +- 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/native/cocos/bindings/jswrapper/v8/Class.cpp b/native/cocos/bindings/jswrapper/v8/Class.cpp index 821a0b79bd2..6c3536273e7 100644 --- a/native/cocos/bindings/jswrapper/v8/Class.cpp +++ b/native/cocos/bindings/jswrapper/v8/Class.cpp @@ -206,6 +206,7 @@ bool Class::defineFunction(const char *name, v8::FunctionCallback func, void *da if (jsName.IsEmpty()) { return false; } + _constructorTemplate.Get(__isolate)->PrototypeTemplate()->Set(jsName.ToLocalChecked(), v8::FunctionTemplate::New(__isolate, func, createExternal(__isolate, data))); return true; } @@ -218,7 +219,18 @@ bool Class::defineProperty(const char *name, v8::FunctionCallback getter, v8::Fu auto prototypeTemplate = _constructorTemplate.Get(__isolate)->PrototypeTemplate(); auto externalData = createExternal(__isolate, data); - prototypeTemplate->SetAccessorProperty(jsName.ToLocalChecked(), v8::FunctionTemplate::New(__isolate, getter, externalData), v8::FunctionTemplate::New(__isolate, setter, externalData)); + + v8::Local getterTemplate = v8::Local(); + v8::Local setterTemplate = v8::Local(); + + if (getter != nullptr) { + getterTemplate = v8::FunctionTemplate::New(__isolate, getter, externalData); + } + + if (setter != nullptr) { + setterTemplate = v8::FunctionTemplate::New(__isolate, setter, externalData); + } + prototypeTemplate->SetAccessorProperty(jsName.ToLocalChecked(), getterTemplate, setterTemplate); return true; } @@ -246,7 +258,18 @@ bool Class::defineStaticProperty(const char *name, v8::FunctionCallback getter, } auto externalData = createExternal(__isolate, data); - _constructorTemplate.Get(__isolate)->SetAccessorProperty(jsName.ToLocalChecked(), v8::FunctionTemplate::New(__isolate, getter, externalData), v8::FunctionTemplate::New(__isolate, setter, externalData)); + v8::Local getterTemplate = v8::Local(); + v8::Local setterTemplate = v8::Local(); + + if (getter != nullptr) { + getterTemplate = v8::FunctionTemplate::New(__isolate, getter, externalData); + } + + if (setter != nullptr) { + setterTemplate = v8::FunctionTemplate::New(__isolate, setter, externalData); + } + + _constructorTemplate.Get(__isolate)->SetAccessorProperty(jsName.ToLocalChecked(), getterTemplate, setterTemplate); return true; } diff --git a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp index 67f08968d7f..bf308fb44b6 100644 --- a/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp +++ b/native/cocos/bindings/jswrapper/v8/ScriptEngine.cpp @@ -246,7 +246,11 @@ class ScriptEngineV8Context { ~ScriptEngineV8Context() { v8::V8::Dispose(); +#if V8_MAJOR_VERSION > 9 || ( V8_MAJOR_VERSION == 9 && V8_MINOR_VERSION > 7) + v8::V8::DisposePlatform(); +#else v8::V8::ShutdownPlatform(); +#endif delete platform; } v8::Platform *platform = nullptr; @@ -279,12 +283,22 @@ void ScriptEngine::onFatalErrorCallback(const char *location, const char *messag getInstance()->callExceptionCallback(location, message, "(no stack information)"); } -void ScriptEngine::onOOMErrorCallback(const char *location, bool isHeapOom) { +void ScriptEngine::onOOMErrorCallback(const char *location, +#if V8_MAJOR_VERSION > 10 || (V8_MAJOR_VERSION == 10 && V8_MINOR_VERSION > 4) + const v8::OOMDetails& details +#else + bool isHeapOom +#endif + ) { ccstd::string errorStr = "[OOM ERROR] location: "; errorStr += location; ccstd::string message; message = "is heap out of memory: "; +#if V8_MAJOR_VERSION > 10 || (V8_MAJOR_VERSION == 10 && V8_MINOR_VERSION > 4) + if (details.is_heap_oom) { +#else if (isHeapOom) { +#endif message += "true"; } else { message += "false"; @@ -899,6 +913,7 @@ bool ScriptEngine::evalString(const char *script, uint32_t length /* = 0 */, Val if (!success) { SE_LOGE("ScriptEngine::evalString script %s, failed!\n", fileName); } + return success; } diff --git a/native/cocos/bindings/jswrapper/v8/ScriptEngine.h b/native/cocos/bindings/jswrapper/v8/ScriptEngine.h index 59940b65226..c1ada9b3777 100644 --- a/native/cocos/bindings/jswrapper/v8/ScriptEngine.h +++ b/native/cocos/bindings/jswrapper/v8/ScriptEngine.h @@ -361,7 +361,14 @@ class ScriptEngine final { private: static void privateDataFinalize(PrivateObjectBase *privateObj); static void onFatalErrorCallback(const char *location, const char *message); - static void onOOMErrorCallback(const char *location, bool isHeapOom); + + static void onOOMErrorCallback(const char *location, +#if V8_MAJOR_VERSION > 10 || (V8_MAJOR_VERSION == 10 && V8_MINOR_VERSION > 4) + const v8::OOMDetails& details +#else + bool isHeapOom +#endif + ); static void onMessageCallback(v8::Local message, v8::Local data); static void onPromiseRejectCallback(v8::PromiseRejectMessage msg); diff --git a/native/cocos/bindings/jswrapper/v8/debugger/inspector_agent.cpp b/native/cocos/bindings/jswrapper/v8/debugger/inspector_agent.cpp index 942b212f9db..6f06a12853d 100644 --- a/native/cocos/bindings/jswrapper/v8/debugger/inspector_agent.cpp +++ b/native/cocos/bindings/jswrapper/v8/debugger/inspector_agent.cpp @@ -391,7 +391,11 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel { explicit ChannelImpl(V8Inspector *inspector, InspectorSessionDelegate *delegate) : delegate_(delegate) { +#if V8_MAJOR_VERSION > 10 || (V8_MAJOR_VERSION == 10 && V8_MINOR_VERSION > 3) + session_ = inspector->connect(1, this, StringView(), v8_inspector::V8Inspector::ClientTrustLevel::kFullyTrusted); +#else session_ = inspector->connect(1, this, StringView()); +#endif } virtual ~ChannelImpl() {} diff --git a/native/cocos/platform/android/libcocos2dx/build.gradle b/native/cocos/platform/android/libcocos2dx/build.gradle index 6309734c1b2..5c47318e45b 100644 --- a/native/cocos/platform/android/libcocos2dx/build.gradle +++ b/native/cocos/platform/android/libcocos2dx/build.gradle @@ -1,9 +1,7 @@ apply plugin: 'com.android.library' android { - ndkPath PROP_NDK_PATH compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() - ndkPath PROP_NDK_PATH namespace 'com.cocos.lib' defaultConfig { minSdkVersion PROP_MIN_SDK_VERSION diff --git a/native/external-config.json b/native/external-config.json index 88416cdce72..432a1a05969 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3.8.2-9" + "checkout": "v3.8.2-11" } } \ No newline at end of file From fcb95b5a3741d6e115a8727931f6c4c64ba6272d Mon Sep 17 00:00:00 2001 From: oahc09 Date: Tue, 10 Oct 2023 13:53:38 +0800 Subject: [PATCH 20/31] feat:[xr] support dispatch xr event to ts (#16382) * feat:[xr] support dispatch xr event to ts * improve:add se::AutoHandleScope scope; --- native/cocos/platform/interfaces/modules/XRCommon.h | 1 + native/cocos/platform/java/modules/XRInterface.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/native/cocos/platform/interfaces/modules/XRCommon.h b/native/cocos/platform/interfaces/modules/XRCommon.h index 682c448c005..d33f2115081 100644 --- a/native/cocos/platform/interfaces/modules/XRCommon.h +++ b/native/cocos/platform/interfaces/modules/XRCommon.h @@ -120,6 +120,7 @@ enum class XRConfigKey { ASYNC_LOAD_ASSETS_IMAGE_RESULTS = 56, LEFT_CONTROLLER_ACTIVE = 57, RIGHT_CONTROLLER_ACTIVE= 58, + TS_EVENT_CALLBACK = 59, MAX_COUNT }; diff --git a/native/cocos/platform/java/modules/XRInterface.cpp b/native/cocos/platform/java/modules/XRInterface.cpp index b6224a9f137..b59f0447cfb 100644 --- a/native/cocos/platform/java/modules/XRInterface.cpp +++ b/native/cocos/platform/java/modules/XRInterface.cpp @@ -499,6 +499,11 @@ void XRInterface::initialize(void *javaVM, void *activity) { }); } else if (key == xr::XRConfigKey::ASYNC_LOAD_ASSETS_IMAGE && value.isInt()) { _isFlipPixelY = value.getInt() == static_cast(gfx::API::GLES3); + } else if (key == xr::XRConfigKey::TS_EVENT_CALLBACK) { + se::AutoHandleScope scope; + se::ValueArray args; + args.emplace_back(se::Value(value.getString())); + EventDispatcher::doDispatchJsEvent("onXREvent", args); } }); #if XR_OEM_PICO @@ -871,6 +876,7 @@ bool XRInterface::beginRenderEyeFrame(uint32_t eye) { #if CC_USE_XR if (IS_ENABLE_XR_LOG) CC_LOG_INFO("[XR] beginRenderEyeFrame %d", eye); if (_isEnabledEyeRenderJsCallback) { + se::AutoHandleScope scope; se::ValueArray args; args.emplace_back(se::Value(eye)); EventDispatcher::doDispatchJsEvent("onXREyeRenderBegin", args); @@ -895,6 +901,7 @@ bool XRInterface::endRenderEyeFrame(uint32_t eye) { #if CC_USE_XR if (IS_ENABLE_XR_LOG) CC_LOG_INFO("[XR] endRenderEyeFrame %d", eye); if (_isEnabledEyeRenderJsCallback) { + se::AutoHandleScope scope; se::ValueArray args; args.emplace_back(se::Value(eye)); EventDispatcher::doDispatchJsEvent("onXREyeRenderEnd", args); From 6eb501d6ab488a004453d9cb5f72e65c3404215c Mon Sep 17 00:00:00 2001 From: Zeqiang Li Date: Tue, 10 Oct 2023 16:46:54 +0800 Subject: [PATCH 21/31] geometry renderer macro in physx (#16396) --- native/cocos/physics/physx/PhysXWorld.cpp | 4 +++ native/cocos/physics/physx/PhysXWorld.h | 37 ++++++++++++++--------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/native/cocos/physics/physx/PhysXWorld.cpp b/native/cocos/physics/physx/PhysXWorld.cpp index bc19ec27eb2..a962ab35629 100644 --- a/native/cocos/physics/physx/PhysXWorld.cpp +++ b/native/cocos/physics/physx/PhysXWorld.cpp @@ -125,9 +125,12 @@ void PhysXWorld::step(float fixedTimeStep) { _mScene->simulate(fixedTimeStep); _mScene->fetchResults(true); syncPhysicsToScene(); +#if CC_USE_GEOMETRY_RENDERER debugDraw(); +#endif } +#if CC_USE_GEOMETRY_RENDERER pipeline::GeometryRenderer* PhysXWorld::getDebugRenderer () { auto cameras = Root::getInstance()->getMainWindow()->getCameras(); scene::Camera* camera = nullptr; @@ -222,6 +225,7 @@ void PhysXWorld::setDebugDrawConstraintSize(float size) { float PhysXWorld::getDebugDrawConstraintSize() { return _debugConstraintSize; } +#endif void PhysXWorld::setGravity(float x, float y, float z) { _mScene->setGravity(physx::PxVec3(x, y, z)); diff --git a/native/cocos/physics/physx/PhysXWorld.h b/native/cocos/physics/physx/PhysXWorld.h index 561fde2efaf..3315a4550fd 100644 --- a/native/cocos/physics/physx/PhysXWorld.h +++ b/native/cocos/physics/physx/PhysXWorld.h @@ -28,7 +28,6 @@ #include "base/Macros.h" #include "base/std/container/vector.h" #include "core/scene-graph/Node.h" -#include "renderer/pipeline/GeometryRenderer.h" #include "physics/physx/PhysXEventManager.h" #include "physics/physx/PhysXFilterShader.h" #include "physics/physx/PhysXInc.h" @@ -36,6 +35,7 @@ #include "physics/physx/PhysXSharedBody.h" #include "physics/physx/character-controllers/PhysXCharacterController.h" #include "physics/spec/IWorld.h" +#include "renderer/pipeline/GeometryRenderer.h" namespace cc { namespace physics { @@ -61,17 +61,17 @@ class PhysXWorld final : virtual public IPhysicsWorld { RaycastResult &raycastClosestResult() override; bool sweep(RaycastOptions &opt, const physx::PxGeometry &geometry, const physx::PxQuat &orientation); - bool sweepClosest(RaycastOptions& opt, const physx::PxGeometry& geometry, const physx::PxQuat& orientation); + bool sweepClosest(RaycastOptions &opt, const physx::PxGeometry &geometry, const physx::PxQuat &orientation); bool sweepBox(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ, - float orientationW, float orientationX, float orientationY, float orientationZ) override; + float orientationW, float orientationX, float orientationY, float orientationZ) override; bool sweepBoxClosest(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ, - float orientationW, float orientationX, float orientationY, float orientationZ) override; + float orientationW, float orientationX, float orientationY, float orientationZ) override; bool sweepSphere(RaycastOptions &opt, float radius) override; bool sweepSphereClosest(RaycastOptions &opt, float radius) override; bool sweepCapsule(RaycastOptions &opt, float radius, float height, - float orientationW, float orientationX, float orientationY, float orientationZ) override; + float orientationW, float orientationX, float orientationY, float orientationZ) override; bool sweepCapsuleClosest(RaycastOptions &opt, float radius, float height, - float orientationW, float orientationX, float orientationY, float orientationZ) override; + float orientationW, float orientationX, float orientationY, float orientationZ) override; ccstd::vector &sweepResult() override; RaycastResult &sweepClosestResult() override; @@ -86,7 +86,7 @@ class PhysXWorld final : virtual public IPhysicsWorld { inline ccstd::vector> &getContactEventPairs() override { return _mEventMgr->getConatctPairs(); } - inline ccstd::vector>& getCCTShapeEventPairs() override { + inline ccstd::vector> &getCCTShapeEventPairs() override { return _mEventMgr->getCCTShapePairs(); } inline ccstd::vector> &getCCTTriggerEventPairs() override { @@ -109,13 +109,13 @@ class PhysXWorld final : virtual public IPhysicsWorld { void removeActor(const PhysXSharedBody &sb); void addCCT(const PhysXCharacterController &cct); void removeCCT(const PhysXCharacterController &cct); - - //Mapping PhysX Object ID and Pointer + + // Mapping PhysX Object ID and Pointer uint32_t addPXObject(uintptr_t PXObjectPtr); void removePXObject(uint32_t pxObjectID); uintptr_t getPXPtrWithPXObjectID(uint32_t pxObjectID); - //Mapping Wrapper PhysX Object ID and Pointer + // Mapping Wrapper PhysX Object ID and Pointer uint32_t addWrapperObject(uintptr_t wrapperObjectPtr); void removeWrapperObject(uint32_t wrapperObjectID); uintptr_t getWrapperPtrWithObjectID(uint32_t wrapperObjectID); @@ -125,17 +125,24 @@ class PhysXWorld final : virtual public IPhysicsWorld { float getFixedTimeStep() const override { return _fixedTimeStep; } void setFixedTimeStep(float fixedTimeStep) override { _fixedTimeStep = fixedTimeStep; } - virtual void setDebugDrawFlags(EPhysicsDrawFlags flags) override; - virtual EPhysicsDrawFlags getDebugDrawFlags() override; +#if CC_USE_GEOMETRY_RENDERER + void setDebugDrawFlags(EPhysicsDrawFlags flags) override; + EPhysicsDrawFlags getDebugDrawFlags() override; - virtual void setDebugDrawConstraintSize(float size) override; - virtual float getDebugDrawConstraintSize() override; + void setDebugDrawConstraintSize(float size) override; + float getDebugDrawConstraintSize() override; private: - pipeline::GeometryRenderer* getDebugRenderer(); + pipeline::GeometryRenderer *getDebugRenderer(); void debugDraw(); void setDebugDrawMode(); +#else + void setDebugDrawFlags(EPhysicsDrawFlags flags) override{}; + EPhysicsDrawFlags getDebugDrawFlags() override { return EPhysicsDrawFlags::NONE; }; + void setDebugDrawConstraintSize(float size) override{}; + float getDebugDrawConstraintSize() override { return 0.0; }; +#endif private: static PhysXWorld *instance; physx::PxFoundation *_mFoundation; From db5779c77c72ae6a2ec7509d26b30910a74578fb Mon Sep 17 00:00:00 2001 From: Ling Zhan Date: Tue, 10 Oct 2023 16:57:01 +0800 Subject: [PATCH 22/31] V3.8.2 box2d wasm node scale performance opt (#16386) * node scale cause box2d shape recreate, low perf * box2d and polygon2d shape * WASM_OBJECT_PTR_2_TS_OBJECT WASM_OBJECT_PTR_2_WASM_OBJECT * tweak * update external-config.json to v3.8.2-12 --- cocos/physics-2d/box2d-wasm/instantiated.ts | 71 ++++++++++++++----- .../physics-2d/box2d-wasm/joints/joint-2d.ts | 10 +-- .../physics-2d/box2d-wasm/physics-contact.ts | 13 ++-- cocos/physics-2d/box2d-wasm/physics-world.ts | 34 ++++----- .../platform/physics-aabb-query-callback.ts | 16 ++--- .../platform/physics-ray-cast-callback.ts | 15 ++-- cocos/physics-2d/box2d-wasm/rigid-body.ts | 13 ++-- .../box2d-wasm/shapes/box-shape-2d.ts | 11 ++- .../box2d-wasm/shapes/circle-shape-2d.ts | 14 ++-- .../box2d-wasm/shapes/polygon-shape-2d.ts | 33 +++++---- .../physics-2d/box2d-wasm/shapes/shape-2d.ts | 58 ++++++++------- native/external-config.json | 2 +- 12 files changed, 163 insertions(+), 127 deletions(-) diff --git a/cocos/physics-2d/box2d-wasm/instantiated.ts b/cocos/physics-2d/box2d-wasm/instantiated.ts index fcb536b7263..a59969209c8 100644 --- a/cocos/physics-2d/box2d-wasm/instantiated.ts +++ b/cocos/physics-2d/box2d-wasm/instantiated.ts @@ -40,6 +40,14 @@ export function getImplPtr (wasmObject: any): number { return (wasmObject).$$.ptr as number; } +// type : Fixture, Body, Contact, Joint, ... +export const enum B2ObjectType { + Fixture = 0, + Body, + Contact, + Joint, +} + /** * mapping wasm-object-ptr to ts-object * B2.Fixture pointer -->B2Shape2D @@ -48,22 +56,35 @@ export function getImplPtr (wasmObject: any): number { * B2.Joint pointer --> B2Joint * ... */ -const WASM_OBJECT_PTR_2_TS_OBJECT = {}; -export function addImplPtrReference (TSObject: any, implPtr: number): void { - if (implPtr) { WASM_OBJECT_PTR_2_TS_OBJECT[implPtr] = TSObject; } -} -export function removeImplPtrReference (implPtr: number): void { +const WASM_OBJECT_PTR_2_TS_OBJECT = new Map>(); + +export function addImplPtrReference (Type: B2ObjectType, TSObject: any, implPtr: number): void { if (implPtr) { - delete WASM_OBJECT_PTR_2_TS_OBJECT[implPtr]; + let map = WASM_OBJECT_PTR_2_TS_OBJECT.get(Type); + if (!map) { + map = new Map(); + WASM_OBJECT_PTR_2_TS_OBJECT.set(Type, map); + } + map.set(implPtr, TSObject); } } -export function getTSObjectFromWASMObjectPtr (implPtr: number): T { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return WASM_OBJECT_PTR_2_TS_OBJECT[implPtr]; + +export function removeImplPtrReference (Type: B2ObjectType, implPtr: number): void { + if (implPtr) { + const map = WASM_OBJECT_PTR_2_TS_OBJECT.get(Type); + if (map && map.has(implPtr)) { + map.delete(implPtr); + if (map.size === 0) { + WASM_OBJECT_PTR_2_TS_OBJECT.delete(Type); + } + } + } } -export function getTSObjectFromWASMObject (impl: any): T { + +export function getTSObjectFromWASMObjectPtr (Type: B2ObjectType, implPtr: number): T { + const map = WASM_OBJECT_PTR_2_TS_OBJECT.get(Type); // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return WASM_OBJECT_PTR_2_TS_OBJECT[getImplPtr(impl)]; + return map?.get(implPtr); } /** @@ -74,20 +95,34 @@ export function getTSObjectFromWASMObject (impl: any): T { * B2.Joint pointer --> B2.Joint * ... */ -const WASM_OBJECT_PTR_2_WASM_OBJECT = {}; -export function addImplPtrReferenceWASM (WASMObject: any, implPtr: number): void { - if (implPtr) { WASM_OBJECT_PTR_2_WASM_OBJECT[implPtr] = WASMObject; } +const WASM_OBJECT_PTR_2_WASM_OBJECT = new Map>(); +export function addImplPtrReferenceWASM (Type: B2ObjectType, WASMObject: any, implPtr: number): void { + if (implPtr) { + let map = WASM_OBJECT_PTR_2_WASM_OBJECT.get(Type); + if (!map) { + map = new Map(); + WASM_OBJECT_PTR_2_WASM_OBJECT.set(Type, map); + } + map.set(implPtr, WASMObject); + } } -export function removeImplPtrReferenceWASM (implPtr: number): void { +export function removeImplPtrReferenceWASM (Type: B2ObjectType, implPtr: number): void { if (implPtr) { - delete WASM_OBJECT_PTR_2_WASM_OBJECT[implPtr]; + const map = WASM_OBJECT_PTR_2_WASM_OBJECT.get(Type); + if (map && map.has(implPtr)) { + map.delete(implPtr); + if (map.size === 0) { + WASM_OBJECT_PTR_2_WASM_OBJECT.delete(Type); + } + } } } -export function getWASMObjectFromWASMObjectPtr (implPtr: number): T { +export function getWASMObjectFromWASMObjectPtr (Type: B2ObjectType, implPtr: number): T { + const map = WASM_OBJECT_PTR_2_WASM_OBJECT.get(Type); // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return WASM_OBJECT_PTR_2_WASM_OBJECT[implPtr]; + return map?.get(implPtr); } /** diff --git a/cocos/physics-2d/box2d-wasm/joints/joint-2d.ts b/cocos/physics-2d/box2d-wasm/joints/joint-2d.ts index b0ba8173bff..841c2aa3fea 100644 --- a/cocos/physics-2d/box2d-wasm/joints/joint-2d.ts +++ b/cocos/physics-2d/box2d-wasm/joints/joint-2d.ts @@ -22,7 +22,7 @@ THE SOFTWARE. */ -import { B2, addImplPtrReference, addImplPtrReferenceWASM, getImplPtr, removeImplPtrReference, removeImplPtrReferenceWASM } from '../instantiated'; +import { B2, B2ObjectType, addImplPtrReference, addImplPtrReferenceWASM, getImplPtr, removeImplPtrReference, removeImplPtrReferenceWASM } from '../instantiated'; import { IJoint2D } from '../../spec/i-physics-joint'; import { Joint2D, PhysicsSystem2D, RigidBody2D } from '../../framework'; import { B2PhysicsWorld } from '../physics-world'; @@ -105,8 +105,8 @@ export class B2Joint implements IJoint2D { def.collideConnected = comp.collideConnected; this._b2joint = (PhysicsSystem2D.instance.physicsWorld as B2PhysicsWorld).impl.CreateJoint(def); - addImplPtrReference(this, getImplPtr(this._b2joint)); - addImplPtrReferenceWASM(this._b2joint, getImplPtr(this._b2joint)); + addImplPtrReference(B2ObjectType.Joint, this, getImplPtr(this._b2joint)); + addImplPtrReferenceWASM(B2ObjectType.Joint, this._b2joint, getImplPtr(this._b2joint)); this._inited = true; } @@ -114,8 +114,8 @@ export class B2Joint implements IJoint2D { destroy (): void { if (!this._inited) return; - removeImplPtrReference(getImplPtr(this._b2joint)); - removeImplPtrReferenceWASM(getImplPtr(this._b2joint)); + removeImplPtrReference(B2ObjectType.Joint, getImplPtr(this._b2joint)); + removeImplPtrReferenceWASM(B2ObjectType.Joint, getImplPtr(this._b2joint)); (PhysicsSystem2D.instance.physicsWorld as B2PhysicsWorld).impl.DestroyJoint(this._b2joint!); this._b2joint = null; diff --git a/cocos/physics-2d/box2d-wasm/physics-contact.ts b/cocos/physics-2d/box2d-wasm/physics-contact.ts index 85f180a9a0e..9eeceb5bcb7 100644 --- a/cocos/physics-2d/box2d-wasm/physics-contact.ts +++ b/cocos/physics-2d/box2d-wasm/physics-contact.ts @@ -22,7 +22,7 @@ THE SOFTWARE. */ -import { B2, addImplPtrReference, getTSObjectFromWASMObjectPtr, removeImplPtrReference } from './instantiated'; +import { B2, B2ObjectType, addImplPtrReference, getTSObjectFromWASMObjectPtr, removeImplPtrReference } from './instantiated'; import { Vec2 } from '../../core'; import { PHYSICS_2D_PTM_RATIO } from '../framework/physics-types'; import { Collider2D, Contact2DType, PhysicsSystem2D } from '../framework'; @@ -74,7 +74,7 @@ export class PhysicsContact implements IPhysics2DContact { } static put (b2contact: number): void { - const c = getTSObjectFromWASMObjectPtr(b2contact); + const c = getTSObjectFromWASMObjectPtr(B2ObjectType.Contact, b2contact); if (!c) return; pools.push(c); @@ -97,15 +97,16 @@ export class PhysicsContact implements IPhysics2DContact { } init (b2contact: number): void { - this.colliderA = (getTSObjectFromWASMObjectPtr(B2.ContactGetFixtureA(b2contact) as number)).collider; - this.colliderB = (getTSObjectFromWASMObjectPtr(B2.ContactGetFixtureB(b2contact) as number)).collider; + const ab = B2.ContactGetFixture(b2contact) as Vec2; + this.colliderA = (getTSObjectFromWASMObjectPtr(B2ObjectType.Fixture, ab.x)).collider; + this.colliderB = (getTSObjectFromWASMObjectPtr(B2ObjectType.Fixture, ab.y)).collider; this.disabled = false; this.disabledOnce = false; this._impulsePtr = 0; this._inverted = false; this._implPtr = b2contact; - addImplPtrReference(this, this._implPtr); + addImplPtrReference(B2ObjectType.Contact, this, this._implPtr); this._b2WorldmanifoldPtr = B2.WorldManifoldNew(); } @@ -119,7 +120,7 @@ export class PhysicsContact implements IPhysics2DContact { this.disabled = false; this._impulsePtr = 0; - removeImplPtrReference(this._implPtr); + removeImplPtrReference(B2ObjectType.Contact, this._implPtr); this._implPtr = 0; B2.WorldManifoldDelete(this._b2WorldmanifoldPtr); diff --git a/cocos/physics-2d/box2d-wasm/physics-world.ts b/cocos/physics-2d/box2d-wasm/physics-world.ts index c0997b14915..e5f7b95fa07 100644 --- a/cocos/physics-2d/box2d-wasm/physics-world.ts +++ b/cocos/physics-2d/box2d-wasm/physics-world.ts @@ -23,8 +23,8 @@ */ import { EDITOR_NOT_IN_PREVIEW } from 'internal:constants'; -import { B2, getImplPtr, addImplPtrReference, addImplPtrReferenceWASM, getTSObjectFromWASMObject, - getTSObjectFromWASMObjectPtr, removeImplPtrReference, removeImplPtrReferenceWASM } from './instantiated'; +import { B2, getImplPtr, addImplPtrReference, addImplPtrReferenceWASM, + getTSObjectFromWASMObjectPtr, removeImplPtrReference, removeImplPtrReferenceWASM, B2ObjectType } from './instantiated'; import { IPhysicsWorld } from '../spec/i-physics-world'; import { IVec2Like, Vec3, Quat, toRadian, Vec2, toDegree, Rect, CCObject, js } from '../../core'; import { PHYSICS_2D_PTM_RATIO, ERaycast2DType, ERigidBody2DType } from '../framework/physics-types'; @@ -64,6 +64,7 @@ export class B2PhysicsWorld implements IPhysicsWorld { private _temoBodyDef: B2.BodyDef; private _tempB2AABB: B2.AABB; + public tempB2FixtureDefPtr: number; get impl (): B2.World { return this._world; @@ -88,6 +89,7 @@ export class B2PhysicsWorld implements IPhysicsWorld { this._temoBodyDef = new B2.BodyDef(); this._tempB2AABB = new B2.AABB(); + this.tempB2FixtureDefPtr = B2.FixtureDefNew(); } _debugGraphics: Graphics | null = null; @@ -189,7 +191,7 @@ export class B2PhysicsWorld implements IPhysicsWorld { const results: RaycastResult2D[] = []; for (let i = 0, l = fixtures.length; i < l; i++) { const fixture = fixtures[i]; - const shape = getTSObjectFromWASMObject(fixture); + const shape = getTSObjectFromWASMObjectPtr(B2ObjectType.Fixture, fixture); const collider = shape.collider; if (type === ERaycast2DType.AllClosest) { @@ -319,8 +321,8 @@ export class B2PhysicsWorld implements IPhysicsWorld { bodyDef.angularVelocity = toRadian(compPrivate._angularVelocity as number); const b2Body = this._world.CreateBody(bodyDef); - addImplPtrReference(body, getImplPtr(b2Body)); - addImplPtrReferenceWASM(b2Body, getImplPtr(b2Body)); + addImplPtrReference(B2ObjectType.Body, body, getImplPtr(b2Body)); + addImplPtrReferenceWASM(B2ObjectType.Body, b2Body, getImplPtr(b2Body)); body._imp = b2Body; this._bodies.push(body); @@ -331,8 +333,8 @@ export class B2PhysicsWorld implements IPhysicsWorld { return; } if (body.impl) { - removeImplPtrReference(getImplPtr(body.impl)); - removeImplPtrReferenceWASM(getImplPtr(body.impl)); + removeImplPtrReference(B2ObjectType.Body, getImplPtr(body.impl)); + removeImplPtrReferenceWASM(B2ObjectType.Body, getImplPtr(body.impl)); this._world.DestroyBody(body.impl); body._imp = null; } @@ -344,11 +346,11 @@ export class B2PhysicsWorld implements IPhysicsWorld { } } - registerContactFixture (fixture: B2.Fixture): void { - this._contactListener.registerContactFixture(getImplPtr(fixture)); + registerContactFixture (fixture: number): void { //B2.Fixture ptr + this._contactListener.registerContactFixture(fixture); } - unregisterContactFixture (fixture: B2.Fixture): void { - this._contactListener.unregisterContactFixture(getImplPtr(fixture)); + unregisterContactFixture (fixture: number): void { //B2.Fixture ptr + this._contactListener.unregisterContactFixture(fixture); } testPoint (point: Vec2): readonly Collider2D[] { @@ -366,7 +368,7 @@ export class B2PhysicsWorld implements IPhysicsWorld { const fixtures = PhysicsAABBQueryCallback.getFixtures(); testResults.length = 0; for (let i = 0; i < fixtures.length; i++) { - const collider = getTSObjectFromWASMObject(fixtures[i]).collider; + const collider = getTSObjectFromWASMObjectPtr(B2ObjectType.Fixture, fixtures[i]).collider; if (!testResults.includes(collider)) { testResults.push(collider); } @@ -385,7 +387,7 @@ export class B2PhysicsWorld implements IPhysicsWorld { const fixtures = PhysicsAABBQueryCallback.getFixtures(); testResults.length = 0; for (let i = 0; i < fixtures.length; i++) { - const collider = getTSObjectFromWASMObject(fixtures[i]).collider; + const collider = getTSObjectFromWASMObjectPtr(B2ObjectType.Fixture, fixtures[i]).collider; if (!testResults.includes(collider)) { testResults.push(collider); } @@ -409,7 +411,7 @@ export class B2PhysicsWorld implements IPhysicsWorld { } _onEndContact (b2contact: number): void { - const c = getTSObjectFromWASMObjectPtr(b2contact); + const c = getTSObjectFromWASMObjectPtr(B2ObjectType.Contact, b2contact); if (!c) { return; } @@ -419,7 +421,7 @@ export class B2PhysicsWorld implements IPhysicsWorld { } _onPreSolve (b2contact: number): void { - const c = getTSObjectFromWASMObjectPtr(b2contact); + const c = getTSObjectFromWASMObjectPtr(B2ObjectType.Contact, b2contact); if (!c) { return; } @@ -428,7 +430,7 @@ export class B2PhysicsWorld implements IPhysicsWorld { } _onPostSolve (b2contact: number, impulse: number): void { - const c = getTSObjectFromWASMObjectPtr(b2contact); + const c = getTSObjectFromWASMObjectPtr(B2ObjectType.Contact, b2contact); if (!c) { return; } diff --git a/cocos/physics-2d/box2d-wasm/platform/physics-aabb-query-callback.ts b/cocos/physics-2d/box2d-wasm/platform/physics-aabb-query-callback.ts index 657dcc2b407..6cc67b023e1 100644 --- a/cocos/physics-2d/box2d-wasm/platform/physics-aabb-query-callback.ts +++ b/cocos/physics-2d/box2d-wasm/platform/physics-aabb-query-callback.ts @@ -22,14 +22,13 @@ THE SOFTWARE. */ -import { B2, getTSObjectFromWASMObject, getWASMObjectFromWASMObjectPtr } from '../instantiated'; +import { B2 } from '../instantiated'; import { Vec2 } from '../../../core'; -import { B2RigidBody2D } from '../rigid-body'; export class PhysicsAABBQueryCallback { static _point = { x: 0, y: 0 }; static _isPoint = false; - static _fixtures: B2.Fixture[] = []; + static _fixtures: number[] = [];//B2.Fixture ptr static init (point?: Vec2): void { if (point) { @@ -43,9 +42,9 @@ export class PhysicsAABBQueryCallback { this._fixtures.length = 0; } - static ReportFixture (fixture: B2.Fixture): boolean { + static ReportFixture (fixture: number): boolean { if (this._isPoint) { - if (fixture.TestPoint(this._point)) { + if (B2.FixtureTestPoint(fixture, this._point)) { this._fixtures.push(fixture); } } else { @@ -56,18 +55,17 @@ export class PhysicsAABBQueryCallback { return true; } - static getFixture (): any { + static getFixture (): number { return this._fixtures[0]; } - static getFixtures (): any[] { + static getFixtures (): number[] { return this._fixtures; } static callback = { ReportFixture (fixture: number): boolean { - const f = getWASMObjectFromWASMObjectPtr(fixture); - return PhysicsAABBQueryCallback.ReportFixture(f); + return PhysicsAABBQueryCallback.ReportFixture(fixture); }, }; } diff --git a/cocos/physics-2d/box2d-wasm/platform/physics-ray-cast-callback.ts b/cocos/physics-2d/box2d-wasm/platform/physics-ray-cast-callback.ts index 3c067a73da2..801165e8419 100644 --- a/cocos/physics-2d/box2d-wasm/platform/physics-ray-cast-callback.ts +++ b/cocos/physics-2d/box2d-wasm/platform/physics-ray-cast-callback.ts @@ -22,15 +22,13 @@ THE SOFTWARE. */ -import { B2, getTSObjectFromWASMObject, getWASMObjectFromWASMObjectPtr } from '../instantiated'; +import { B2 } from '../instantiated'; import { Vec2 } from '../../../core'; import { ERaycast2DType } from '../../framework'; -import { B2Shape2D } from '../shapes/shape-2d'; -import { B2RigidBody2D } from '../rigid-body'; export class PhysicsRayCastCallback {// extends B2.RayCastCallback { static _type = ERaycast2DType.Closest; - static _fixtures: B2.Fixture[] = []; + static _fixtures: number[] = [];//B2.Fixture ptr static _points: Vec2[] = []; static _normals: Vec2[] = []; static _fractions: number[] = []; @@ -46,8 +44,8 @@ export class PhysicsRayCastCallback {// extends B2.RayCastCallback { PhysicsRayCastCallback._fractions.length = 0; } - static ReportFixture (fixture: B2.Fixture, point: B2.Vec2, normal: B2.Vec2, fraction: number): any { - if ((fixture.GetFilterData().categoryBits & PhysicsRayCastCallback._mask) === 0) { + static ReportFixture (fixture: number, point: B2.Vec2, normal: B2.Vec2, fraction: number): any { + if ((B2.FixtureGetFilterData(fixture).categoryBits & PhysicsRayCastCallback._mask) === 0) { return 0; } @@ -73,7 +71,7 @@ export class PhysicsRayCastCallback {// extends B2.RayCastCallback { return fraction; } - static getFixtures (): B2.Fixture[] { + static getFixtures (): number[] { return PhysicsRayCastCallback._fixtures; } @@ -91,8 +89,7 @@ export class PhysicsRayCastCallback {// extends B2.RayCastCallback { static callback = { ReportFixture (fixture: number, point: B2.Vec2, normal: B2.Vec2, fraction: number): any { - const f = getWASMObjectFromWASMObjectPtr(fixture); - return PhysicsRayCastCallback.ReportFixture(f, point, normal, fraction); + return PhysicsRayCastCallback.ReportFixture(fixture, point, normal, fraction); }, }; } diff --git a/cocos/physics-2d/box2d-wasm/rigid-body.ts b/cocos/physics-2d/box2d-wasm/rigid-body.ts index 569142e0944..e8de966ef32 100644 --- a/cocos/physics-2d/box2d-wasm/rigid-body.ts +++ b/cocos/physics-2d/box2d-wasm/rigid-body.ts @@ -22,7 +22,7 @@ THE SOFTWARE. */ -import { B2, getTSObjectFromWASMObject, getTSObjectFromWASMObjectPtr } from './instantiated'; +import { B2, B2ObjectType, getTSObjectFromWASMObjectPtr } from './instantiated'; import { IRigidBody2D } from '../spec/i-rigid-body'; import { RigidBody2D } from '../framework/components/rigid-body-2d'; import { PhysicsSystem2D } from '../framework/physics-system'; @@ -32,7 +32,6 @@ import { PHYSICS_2D_PTM_RATIO, ERigidBody2DType } from '../framework/physics-typ import { Node } from '../../scene-graph/node'; import { Collider2D, Joint2D } from '../framework'; -import { NodeEventType } from '../../scene-graph/node-event'; import { B2Shape2D } from './shapes/shape-2d'; import { B2Joint } from './joints/joint-2d'; @@ -119,11 +118,11 @@ export class B2RigidBody2D implements IRigidBody2D { //collect all fixtures attached to this rigid body and process them const fixtureList = this.impl?.GetFixtureList(); if (fixtureList) { - let shapeTSObj = getTSObjectFromWASMObject(fixtureList); + let shapeTSObj = getTSObjectFromWASMObjectPtr(B2ObjectType.Fixture, fixtureList); while (shapeTSObj && shapeTSObj.impl) { shapeTSObj.destroy(); - const nextFixture = fixtureList.GetNext(); - shapeTSObj = getTSObjectFromWASMObject(nextFixture); + const nextFixture = B2.FixtureGetNext(fixtureList) as number; + shapeTSObj = getTSObjectFromWASMObjectPtr(B2ObjectType.Fixture, nextFixture); } } @@ -131,11 +130,11 @@ export class B2RigidBody2D implements IRigidBody2D { const jointListPtr = this.impl?.GetJointList(); if (jointListPtr) { let jointWASMPtr = B2.JointEdgeGetJoint(jointListPtr) as number; - let jointTSObj = getTSObjectFromWASMObjectPtr(jointWASMPtr); + let jointTSObj = getTSObjectFromWASMObjectPtr(B2ObjectType.Fixture, jointWASMPtr); while (jointTSObj) { jointTSObj.destroy(); jointWASMPtr = B2.JointEdgeGetNext(jointListPtr) as number; - jointTSObj = getTSObjectFromWASMObjectPtr(jointWASMPtr); + jointTSObj = getTSObjectFromWASMObjectPtr(B2ObjectType.Fixture, jointWASMPtr); } } diff --git a/cocos/physics-2d/box2d-wasm/shapes/box-shape-2d.ts b/cocos/physics-2d/box2d-wasm/shapes/box-shape-2d.ts index 381632fb03a..b32d55b5ba6 100644 --- a/cocos/physics-2d/box2d-wasm/shapes/box-shape-2d.ts +++ b/cocos/physics-2d/box2d-wasm/shapes/box-shape-2d.ts @@ -55,7 +55,7 @@ export class B2BoxShape extends B2Shape2D implements IBoxShape { return wps; } - _createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): B2.PolygonShape[] { + _createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): number[] { //B2.PolygonShape[] scaleX = Math.abs(scaleX); scaleY = Math.abs(scaleY); @@ -66,11 +66,8 @@ export class B2BoxShape extends B2Shape2D implements IBoxShape { const offsetX = (relativePositionX + comp.offset.x * scaleX) / PHYSICS_2D_PTM_RATIO; const offsetY = (relativePositionY + comp.offset.y * scaleY) / PHYSICS_2D_PTM_RATIO; - const shape = new B2.PolygonShape(); - tempB2Vec2_1.x = offsetX; - tempB2Vec2_1.y = offsetY; - shape.SetAsBoxWithCenterAndAngle(width, height, tempB2Vec2_1, 0); - - return [shape as unknown as B2.PolygonShape]; + const shape = B2.PolygonShapeNew() as number; + B2.PolygonShapeSetAsBoxWithCenterAndAngle(shape, width, height, offsetX, offsetY, 0); + return [shape]; } } diff --git a/cocos/physics-2d/box2d-wasm/shapes/circle-shape-2d.ts b/cocos/physics-2d/box2d-wasm/shapes/circle-shape-2d.ts index 828fa57cadd..9a4a8eae614 100644 --- a/cocos/physics-2d/box2d-wasm/shapes/circle-shape-2d.ts +++ b/cocos/physics-2d/box2d-wasm/shapes/circle-shape-2d.ts @@ -31,16 +31,16 @@ import { Vec2 } from '../../../core'; export class B2CircleShape extends B2Shape2D implements ICircleShape { get worldRadius (): number { - return (this._shapes[0]).m_radius * PHYSICS_2D_PTM_RATIO; + return B2.CircleShapeGetRadius(this._shapes[0]) * PHYSICS_2D_PTM_RATIO; } _worldPosition = new Vec2(); get worldPosition (): Vec2 { - const p = (this._shapes[0] as B2.CircleShape).m_p; + const p = B2.CircleShapeGetPosition(this._shapes[0]) as B2.Vec2; return this._worldPosition.set(p.x * PHYSICS_2D_PTM_RATIO, p.y * PHYSICS_2D_PTM_RATIO); } - _createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): B2.CircleShape[] { + _createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): number[] { //B2.CircleShape[] scaleX = Math.abs(scaleX); scaleY = Math.abs(scaleY); @@ -49,10 +49,10 @@ export class B2CircleShape extends B2Shape2D implements ICircleShape { const offsetX = (relativePositionX + comp.offset.x * scaleX) / PHYSICS_2D_PTM_RATIO; const offsetY = (relativePositionY + comp.offset.y * scaleY) / PHYSICS_2D_PTM_RATIO; - const shape = new B2.CircleShape(); - shape.m_radius = comp.radius / PHYSICS_2D_PTM_RATIO * scaleX; - shape.m_p = { x: offsetX, y: offsetY }; + const shape = B2.CircleShapeNew() as number; + B2.ShapeSetRadius(shape, comp.radius / PHYSICS_2D_PTM_RATIO * scaleX); + B2.CircleShapeSetPosition(shape, offsetX, offsetY); - return [shape as unknown as B2.CircleShape]; + return [shape]; } } diff --git a/cocos/physics-2d/box2d-wasm/shapes/polygon-shape-2d.ts b/cocos/physics-2d/box2d-wasm/shapes/polygon-shape-2d.ts index e192901f5ad..8bd31e5be25 100644 --- a/cocos/physics-2d/box2d-wasm/shapes/polygon-shape-2d.ts +++ b/cocos/physics-2d/box2d-wasm/shapes/polygon-shape-2d.ts @@ -48,8 +48,8 @@ export class B2PolygonShape extends B2Shape2D implements IPolygonShape { return this._worldPoints; } - _createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): B2.PolygonShape[] { - const shapes: B2.PolygonShape[] = []; + _createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): number[] { + const shapes: number[] = []; const comp = this.collider as PolygonCollider2D; const points = comp.points; @@ -70,44 +70,43 @@ export class B2PolygonShape extends B2Shape2D implements IPolygonShape { for (let i = 0; i < polys.length; i++) { const poly = polys[i]; - let shape: B2.PolygonShape | null = null; - const vertices = new B2.Vec2Vector(); + let shape: number = 0;//B2.PolygonShape ptr + const vertices = B2.Vec2VectorNew(); let firstVertice: B2.Vec2 | null = null; for (let j = 0, l = poly.length; j < l; j++) { if (!shape) { - shape = new B2.PolygonShape(); + shape = B2.PolygonShapeNew() as number; } const p = poly[j]; const x = (relativePositionX + (p.x + offset.x) * scaleX) / PHYSICS_2D_PTM_RATIO; const y = (relativePositionY + (p.y + offset.y) * scaleY) / PHYSICS_2D_PTM_RATIO; const v = { x, y }; - vertices.push_back(v); + B2.Vec2VectorPush(vertices, x, y); if (!firstVertice) { firstVertice = v; } - if (vertices.size() === B2.maxPolygonVertices) { - shape!.Set(vertices, vertices.size() as number); - shapes.push(shape!); - - shape = null; + if (B2.Vec2VectorSize(vertices) === B2.maxPolygonVertices) { + B2.PolygonShapeSet(shape, B2.Vec2VectorGetPtr(vertices), B2.Vec2VectorSize(vertices)); + shapes.push(shape); + shape = 0; if (j < l - 1) { - const temp = vertices.get(vertices.size() - 1); - vertices.resize(0, { x: 0, y: 0 });//clear - vertices.push_back(firstVertice); - vertices.push_back(temp); + const temp = B2.Vec2VectorGet(vertices, B2.Vec2VectorSize(vertices) - 1); + B2.Vec2VectorResize(vertices, 0, 0, 0);//clear + B2.Vec2VectorPush(vertices, firstVertice.x, firstVertice.y); + B2.Vec2VectorPush(vertices, temp.x, temp.y); } } } if (shape) { - shape.Set(vertices, vertices.size() as number); + B2.PolygonShapeSet(shape, B2.Vec2VectorGetPtr(vertices), B2.Vec2VectorSize(vertices) as number); shapes.push(shape); } - vertices.delete(); + B2.Vec2VectorDelete(vertices); } return shapes; diff --git a/cocos/physics-2d/box2d-wasm/shapes/shape-2d.ts b/cocos/physics-2d/box2d-wasm/shapes/shape-2d.ts index 84ab4a5881b..0b4d119299b 100644 --- a/cocos/physics-2d/box2d-wasm/shapes/shape-2d.ts +++ b/cocos/physics-2d/box2d-wasm/shapes/shape-2d.ts @@ -23,7 +23,8 @@ */ import { B2, getImplPtr, addImplPtrReference, addImplPtrReferenceWASM, removeImplPtrReference, - removeImplPtrReferenceWASM } from '../instantiated'; + removeImplPtrReferenceWASM, + B2ObjectType } from '../instantiated'; import { IBaseShape } from '../../spec/i-physics-shape'; import { Collider2D, PhysicsSystem2D, RigidBody2D, PHYSICS_2D_PTM_RATIO } from '../../../../exports/physics-2d-framework'; import { Rect, Vec3 } from '../../../core'; @@ -46,8 +47,8 @@ function getFilter (shape: B2Shape2D): B2.Filter { } export class B2Shape2D implements IBaseShape { - protected _shapes: B2.Shape[] = []; - protected _fixtures: B2.Fixture[] = []; + protected _shapes: number[] = []; + protected _fixtures: number[] = [];//B2.Fixture ptr protected _collider: Collider2D | null = null; protected _body: B2.Body | null = null; @@ -56,7 +57,7 @@ export class B2Shape2D implements IBaseShape { private _rect = new Rect(); - get impl (): B2.Shape[] { + get impl (): number[] { return this._shapes; } @@ -87,7 +88,7 @@ export class B2Shape2D implements IBaseShape { onGroupChanged (): void { const filter = getFilter(this); this._fixtures.forEach((f): void => { - f.SetFilterData(filter); + B2.FixtureSetFilterData(f, filter); }); } @@ -108,15 +109,16 @@ export class B2Shape2D implements IBaseShape { for (let i = 0; i < fixtures.length; i++) { const fixture = fixtures[i]; - const count = fixture.GetShape().GetChildCount(); + const shape = B2.FixtureGetShape(fixture) as number; + const count = B2.ShapeGetChildCount(shape); for (let j = 0; j < count; j++) { - const aabb = fixture.GetAABB(j); + const aabb = B2.FixtureGetAABB(fixture, j); lowerBound.x = aabb.lowerBound.x; lowerBound.y = aabb.lowerBound.y; upperBound.x = aabb.upperBound.x; upperBound.y = aabb.upperBound.y; - if (fixture.GetShape().m_type === B2.ShapeType.e_polygon) { //b2ShapeType.e_polygonShape - const skinWidth = fixture.GetShape().m_radius; + if (B2.ShapeGetType(shape) === 2) { //b2ShapeType.e_polygonShape + const skinWidth = B2.ShapeGetRadius(shape); lowerBound.x += skinWidth; lowerBound.y += skinWidth; upperBound.x += skinWidth; @@ -143,12 +145,12 @@ export class B2Shape2D implements IBaseShape { return r; } - getFixtureIndex (fixture: B2.Fixture): number { + getFixtureIndex (fixture: number): number { //B2.Fixture ptr return this._fixtures.indexOf(fixture); } //relativePositionX/Y : relative Position from shape to rigid body - _createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): B2.Shape[] { + _createShapes (scaleX: number, scaleY: number, relativePositionX: number, relativePositionY: number): number[] { return []; } @@ -177,17 +179,23 @@ export class B2Shape2D implements IBaseShape { for (let i = 0; i < shapes.length; i++) { const shape = shapes[i]; - const fixDef = new B2.FixtureDef(); - fixDef.density = comp.density; - fixDef.isSensor = comp.sensor; - fixDef.friction = comp.friction; - fixDef.restitution = comp.restitution; - fixDef.SetShape(shape); - fixDef.filter = filter; - const fixture = this._body.CreateFixture(fixDef as B2.FixtureDef); - //fixture.m_userData = this; - addImplPtrReference(this, getImplPtr(fixture)); - addImplPtrReferenceWASM(fixture, getImplPtr(fixture)); + const fixDef = (PhysicsSystem2D.instance.physicsWorld as B2PhysicsWorld).tempB2FixtureDefPtr; + B2.FixtureDefSetAll( + fixDef, + shape, + 0, + comp.friction, + comp.restitution, + comp.density, + comp.sensor, + filter.categoryBits, + filter.maskBits, + filter.groupIndex, + ); + + const fixture = B2.BodyCreateFixture(getImplPtr(this._body), fixDef) as number; + addImplPtrReference(B2ObjectType.Fixture, this, fixture); + addImplPtrReferenceWASM(B2ObjectType.Fixture, fixture, fixture); if (body?.enabledContactListener) { (PhysicsSystem2D.instance.physicsWorld as B2PhysicsWorld).registerContactFixture(fixture); @@ -209,13 +217,13 @@ export class B2Shape2D implements IBaseShape { for (let i = fixtures.length - 1; i >= 0; i--) { const fixture = fixtures[i]; //fixture.m_userData = null; - removeImplPtrReference(getImplPtr(fixture)); - removeImplPtrReferenceWASM(getImplPtr(fixture)); + removeImplPtrReference(B2ObjectType.Fixture, fixture); + removeImplPtrReferenceWASM(B2ObjectType.Fixture, fixture); (PhysicsSystem2D.instance.physicsWorld as B2PhysicsWorld).unregisterContactFixture(fixture); if (body) { - body.DestroyFixture(fixture); + B2.BodyDestroyFixture(getImplPtr(body), fixture); } } diff --git a/native/external-config.json b/native/external-config.json index 432a1a05969..bfb8870c10e 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3.8.2-11" + "checkout": "v3.8.2-12" } } \ No newline at end of file From c76c1603937212ba9ced80ee80e778600677c806 Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Tue, 10 Oct 2023 18:19:33 +0800 Subject: [PATCH 23/31] Fix the issue that after double-clicking the editbox, the editbox shifts or displays an offset on web mobile platforms (#16402) * Fix the issue that after double-clicking the editbox, the editbox shifts or displays an offset on web mobile platforms --- cocos/ui/editbox/edit-box-impl-base.ts | 5 ----- cocos/ui/editbox/edit-box-impl.ts | 20 ++++++++++++++++++-- cocos/ui/editbox/edit-box.ts | 6 ------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cocos/ui/editbox/edit-box-impl-base.ts b/cocos/ui/editbox/edit-box-impl-base.ts index 9ce78026dc9..9bc3544a6b9 100644 --- a/cocos/ui/editbox/edit-box-impl-base.ts +++ b/cocos/ui/editbox/edit-box-impl-base.ts @@ -37,11 +37,6 @@ export class EditBoxImplBase { */ public _delegate: EditBox | null = null; - /** - * @engineInternal dirty flag to update the matrix - */ - public _dirtyFlag: boolean | null = false; - public init (delegate: EditBox): void { // To be overrode } diff --git a/cocos/ui/editbox/edit-box-impl.ts b/cocos/ui/editbox/edit-box-impl.ts index f6a36d25700..eeec2ad8cb8 100644 --- a/cocos/ui/editbox/edit-box-impl.ts +++ b/cocos/ui/editbox/edit-box-impl.ts @@ -137,7 +137,10 @@ export class EditBoxImpl extends EditBoxImplBase { } public update (): void { - if (!this._dirtyFlag) return; + const node = this._delegate!.node; + if (!node.hasChangedFlags) { + return; + } this._updateMatrix(); } @@ -242,9 +245,22 @@ export class EditBoxImpl extends EditBoxImplBase { this._scrollBackWindow(); } + private _isElementInViewport (): boolean { + if (this._edTxt) { + const rect = this._edTxt.getBoundingClientRect(); + + return ( + rect.top >= 0 && rect.left >= 0 + && rect.bottom <= (ccwindow.innerHeight || ccdocument.documentElement.clientHeight) + && rect.right <= (ccwindow.innerWidth || ccdocument.documentElement.clientWidth) + ); + } + return false; + } + private _adjustWindowScroll (): void { setTimeout(() => { - if (ccwindow.scrollY < SCROLLY) { + if (ccwindow.scrollY < SCROLLY && !this._isElementInViewport()) { this._edTxt!.scrollIntoView({ block: 'start', inline: 'nearest', behavior: 'smooth' }); } }, DELAY_TIME); diff --git a/cocos/ui/editbox/edit-box.ts b/cocos/ui/editbox/edit-box.ts index 63846eeb9cb..4bca693cdc7 100644 --- a/cocos/ui/editbox/edit-box.ts +++ b/cocos/ui/editbox/edit-box.ts @@ -492,9 +492,6 @@ export class EditBox extends Component { public _editBoxEditingDidBegan (): void { ComponentEventHandler.emitEvents(this.editingDidBegan, this); this.node.emit(EventType.EDITING_DID_BEGAN, this); - if (this._impl) { - this._impl._dirtyFlag = true; - } } /** @@ -506,9 +503,6 @@ export class EditBox extends Component { public _editBoxEditingDidEnded (text?: string): void { ComponentEventHandler.emitEvents(this.editingDidEnded, this); this.node.emit(EventType.EDITING_DID_ENDED, this, text); - if (this._impl) { - this._impl._dirtyFlag = false; - } } /** From 40ec21934b9e184f675bff80c447eaa8defd7b86 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 11 Oct 2023 10:00:13 +0800 Subject: [PATCH 24/31] fixed #16355: Compilation fails in CI env if using Android NDK r26 (#16401) * fixed #16355: Compilation fails in CI env if using Android NDK r26 * Update predefine.cmake --- native/cmake/predefine.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/native/cmake/predefine.cmake b/native/cmake/predefine.cmake index ad50d295355..c071f71aa99 100644 --- a/native/cmake/predefine.cmake +++ b/native/cmake/predefine.cmake @@ -129,6 +129,8 @@ if("$ENV{COCOS_ENGINE_DEV}" EQUAL "1") set(WERROR_FLAGS " ${WERROR_FLAGS} -Wno-deprecated-declarations") elseif(LINUX) set(WERROR_FLAGS " ${WERROR_FLAGS} -Wno-nullability-completeness -Wno-deprecated-declarations") + elseif(ANDROID) + set(WERROR_FLAGS " ${WERROR_FLAGS} -Wno-deprecated-declarations -Wno-unknown-warning-option -Wno-deprecated-builtins") endif() if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") From 2831c61f0d1f5633eaf6516f984792d0091881b3 Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Wed, 11 Oct 2023 10:06:51 +0800 Subject: [PATCH 25/31] Fix webaudio's bug: calling the 'checkEnded' interface after 'destroy' has been called can trigger a JavaScript error (#16393) (cherry picked from commit a8e7f18bf7e4bc5decad9b78d1dc169c6068ce86) --- pal/audio/web/player-web.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/pal/audio/web/player-web.ts b/pal/audio/web/player-web.ts index 410e305d8d9..46fefbaf3ce 100644 --- a/pal/audio/web/player-web.ts +++ b/pal/audio/web/player-web.ts @@ -245,6 +245,7 @@ export class AudioPlayerWeb implements OperationQueueable { game.on(Game.EVENT_RESUME, this._onInterruptedEnd, this); } destroy (): void { + window.clearTimeout(this._currentTimer); this._audioTimer.destroy(); if (this._audioBuffer) { // NOTE: need to release AudioBuffer instance From 52726aa1a2724594385bad8cb3ce85c54457139c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Wed, 11 Oct 2023 13:31:57 +0800 Subject: [PATCH 26/31] physx disable unused PVD for now (#16383) * Disable unused PVD for now * Update physx dep --- cocos/physics/physx/physx-adapter.ts | 6 +----- native/external-config.json | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/cocos/physics/physx/physx-adapter.ts b/cocos/physics/physx/physx-adapter.ts index d6caf0be551..56db9bc525c 100644 --- a/cocos/physics/physx/physx-adapter.ts +++ b/cocos/physics/physx/physx-adapter.ts @@ -811,11 +811,7 @@ export function initializeWorld (world: any): void { const allocator = new PX.PxDefaultAllocator(); const defaultErrorCallback = new PX.PxDefaultErrorCallback(); const foundation = PhysXInstance.foundation = PX.PxCreateFoundation(version, allocator, defaultErrorCallback); - if (DEBUG) { - PhysXInstance.pvd = PX.PxCreatePvd(foundation); - } else { - PhysXInstance.pvd = null; - } + PhysXInstance.pvd = null; const scale = new PX.PxTolerancesScale(); PhysXInstance.physics = PX.physics = PX.PxCreatePhysics(version, foundation, scale, false, PhysXInstance.pvd); PhysXInstance.cooking = PX.PxCreateCooking(version, foundation, new PX.PxCookingParams(scale)); diff --git a/native/external-config.json b/native/external-config.json index bfb8870c10e..22ac6e57caf 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3.8.2-12" + "checkout": "v3.8.2-13" } } \ No newline at end of file From 3781d34b34bff4e112c7d128b6a63d8597e6947e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Wed, 11 Oct 2023 14:47:54 +0800 Subject: [PATCH 27/31] Label component inspector localization (#16234) * Label component inspector localization * Update editor/i18n/zh/modules/ui.js * Update --- cocos/2d/components/label.ts | 25 +----- cocos/2d/framework/ui-renderer.ts | 2 - editor/i18n/en/localization.js | 28 +------ editor/i18n/en/modules/ui.js | 124 ++++++++++++++++++++++++++++++ editor/i18n/zh/localization.js | 28 +------ editor/i18n/zh/modules/ui.js | 123 +++++++++++++++++++++++++++++ 6 files changed, 250 insertions(+), 80 deletions(-) create mode 100644 editor/i18n/en/modules/ui.js create mode 100644 editor/i18n/zh/modules/ui.js diff --git a/cocos/2d/components/label.ts b/cocos/2d/components/label.ts index 37003194c46..6bfde6b7f71 100644 --- a/cocos/2d/components/label.ts +++ b/cocos/2d/components/label.ts @@ -23,7 +23,7 @@ THE SOFTWARE. */ -import { ccclass, help, executionOrder, menu, tooltip, displayOrder, visible, multiline, type, serializable, editable } from 'cc.decorator'; +import { ccclass, help, executionOrder, menu, displayOrder, visible, multiline, type, serializable, editable } from 'cc.decorator'; import { BYTEDANCE, EDITOR, JSB } from 'internal:constants'; import { minigame } from 'pal/minigame'; import { BitmapFont, Font, SpriteFrame } from '../assets'; @@ -212,7 +212,6 @@ export class Label extends UIRenderer { * 标签显示的文本内容。 */ @displayOrder(4) - @tooltip('i18n:label.string') @multiline get string (): string { return this._string; @@ -241,7 +240,6 @@ export class Label extends UIRenderer { */ @type(HorizontalTextAlignment) @displayOrder(5) - @tooltip('i18n:label.horizontal_align') get horizontalAlign (): HorizontalTextAlignment { return this._horizontalAlign; } @@ -263,7 +261,6 @@ export class Label extends UIRenderer { */ @type(VerticalTextAlignment) @displayOrder(6) - @tooltip('i18n:label.vertical_align') get verticalAlign (): VerticalTextAlignment { return this._verticalAlign; } @@ -298,7 +295,6 @@ export class Label extends UIRenderer { * 文本字体大小。 */ @displayOrder(7) - @tooltip('i18n:label.font_size') get fontSize (): number { return this._fontSize; } @@ -319,7 +315,6 @@ export class Label extends UIRenderer { * 文本行高。 */ @displayOrder(8) - @tooltip('i18n:label.line_height') get lineHeight (): number { return this._lineHeight; } @@ -343,7 +338,6 @@ export class Label extends UIRenderer { return !this._isSystemFontUsed && this._font instanceof BitmapFont; }) @displayOrder(9) - @tooltip('i18n:label.spacing_x') get spacingX (): number { return this._spacingX; } @@ -365,7 +359,6 @@ export class Label extends UIRenderer { */ @type(Overflow) @displayOrder(10) - @tooltip('i18n:label.overflow') get overflow (): Overflow { return this._overflow; } @@ -386,7 +379,6 @@ export class Label extends UIRenderer { * 是否自动换行。 */ @displayOrder(11) - @tooltip('i18n:label.wrap') get enableWrapText (): boolean { return this._enableWrapText; } @@ -407,7 +399,6 @@ export class Label extends UIRenderer { * 是否使用系统字体。 */ @displayOrder(12) - @tooltip('i18n:label.system_font') get useSystemFont (): boolean { return this._isSystemFontUsed; } @@ -443,7 +434,6 @@ export class Label extends UIRenderer { */ @displayOrder(13) @visible(function (this: Label) { return this._isSystemFontUsed; }) - @tooltip('i18n:label.font_family') get fontFamily (): string { return this._fontFamily; } @@ -466,7 +456,6 @@ export class Label extends UIRenderer { @type(Font) @displayOrder(13) @visible(function (this: Label) { return !this._isSystemFontUsed; }) - @tooltip('i18n:label.font') get font (): Font | null { // return this._N$file; return this._font; @@ -503,7 +492,6 @@ export class Label extends UIRenderer { */ @type(CacheMode) @displayOrder(14) - @tooltip('i18n:label.cache_mode') get cacheMode (): CacheMode { return this._cacheMode; } @@ -531,7 +519,6 @@ export class Label extends UIRenderer { * 字体是否加粗。 */ @displayOrder(15) - @tooltip('i18n:label.font_bold') get isBold (): boolean { return this._isBold; } @@ -552,7 +539,6 @@ export class Label extends UIRenderer { * 字体是否倾斜。 */ @displayOrder(16) - @tooltip('i18n:label.font_italic') get isItalic (): boolean { return this._isItalic; } @@ -573,7 +559,6 @@ export class Label extends UIRenderer { * 字体是否加下划线。 */ @displayOrder(17) - @tooltip('i18n:label.font_underline') get isUnderline (): boolean { return this._isUnderline; } @@ -593,7 +578,6 @@ export class Label extends UIRenderer { @visible(function (this: Label) { return this._isUnderline; }) @editable @displayOrder(18) - @tooltip('i18n:label.underline_height') get underlineHeight (): number { return this._underlineHeight; } @@ -613,7 +597,6 @@ export class Label extends UIRenderer { @editable @visible(function (this: Label) { return !(this._font instanceof BitmapFont); }) @displayOrder(19) - @tooltip('i18n:label.outline_enable') get enableOutline (): boolean { return this._enableOutline; } @@ -633,7 +616,6 @@ export class Label extends UIRenderer { @editable @visible(function (this: Label) { return this._enableOutline && !(this._font instanceof BitmapFont); }) @displayOrder(20) - @tooltip('i18n:label.outline_color') get outlineColor (): Color { return this._outlineColor; } @@ -653,7 +635,6 @@ export class Label extends UIRenderer { @editable @visible(function (this: Label) { return this._enableOutline && !(this._font instanceof BitmapFont); }) @displayOrder(21) - @tooltip('i18n:label.outline_width') get outlineWidth (): number { return this._outlineWidth; } @@ -670,7 +651,6 @@ export class Label extends UIRenderer { @editable @visible(function (this: Label) { return !(this._font instanceof BitmapFont) && (this.cacheMode !== CacheMode.CHAR); }) @displayOrder(22) - @tooltip('i18n:label.shadow_enable') get enableShadow (): boolean { return this._enableShadow; } @@ -690,7 +670,6 @@ export class Label extends UIRenderer { @editable @visible(function (this: Label) { return this._enableShadow && !(this._font instanceof BitmapFont) && (this.cacheMode !== CacheMode.CHAR); }) @displayOrder(23) - @tooltip('i18n:label.shadow_color') get shadowColor (): Color { return this._shadowColor; } @@ -710,7 +689,6 @@ export class Label extends UIRenderer { @editable @visible(function (this: Label) { return this._enableShadow && !(this._font instanceof BitmapFont) && (this.cacheMode !== CacheMode.CHAR); }) @displayOrder(24) - @tooltip('i18n:label.shadow_offset') get shadowOffset (): Vec2 { return this._shadowOffset; } @@ -730,7 +708,6 @@ export class Label extends UIRenderer { @editable @visible(function (this: Label) { return this._enableShadow && !(this._font instanceof BitmapFont) && (this.cacheMode !== CacheMode.CHAR); }) @displayOrder(25) - @tooltip('i18n:label.shadow_blur') get shadowBlur (): number { return this._shadowBlur; } diff --git a/cocos/2d/framework/ui-renderer.ts b/cocos/2d/framework/ui-renderer.ts index d79a81d315f..d6a0e9a957c 100644 --- a/cocos/2d/framework/ui-renderer.ts +++ b/cocos/2d/framework/ui-renderer.ts @@ -168,7 +168,6 @@ export class UIRenderer extends Renderer { */ @type(Material) @displayOrder(0) - @tooltip('i18n:UIRenderer.customMaterial') @displayName('CustomMaterial') @disallowAnimation get customMaterial (): Material | null { @@ -185,7 +184,6 @@ export class UIRenderer extends Renderer { * @zh 渲染颜色,一般情况下会和贴图颜色相乘。 */ @displayOrder(1) - @tooltip('i18n:UIRenderer.color') get color (): Readonly { return this._color; } diff --git a/editor/i18n/en/localization.js b/editor/i18n/en/localization.js index 7c9e9098f80..610a0be8e76 100755 --- a/editor/i18n/en/localization.js +++ b/editor/i18n/en/localization.js @@ -384,37 +384,12 @@ module.exports = link(mixin({ space: 'Space where acceleration calculated', }, label: { - string: 'Text of the Label', - horizontal_align: 'Horizontal alignment', horizontal_align_left: 'Align Left', horizontal_align_center: 'Align Horizontal Center', horizontal_align_right: 'Align Right', - vertical_align: 'Vertical alignment', vertical_align_top: 'Align Top', vertical_align_center: 'Align Vertical Center', vertical_align_bottom: 'Align Bottom', - font_size: 'Font size, in points', - font_family: 'Font family name', - line_height: 'Line height, in points', - overflow: - 'Text layout modes:
1. CLAMP: Text nodes outside the bounding box will be truncated.
2. SHRINK: Automatically shrink text box according to the constraint node.
3. RESIZE: Automatically updates the Node based on heightof the text.', - wrap: 'Wrap text?', - font: 'What font to use', - system_font: 'Whether to use the system default font', - cache_mode: - 'Text cache modes:
1. NONE: No cache,draw once.
2. BITMAP: Text is added as a static image to the dynamic atlas for batch merging, but its content cannot be dynamically modified frequently.
3. CHAR: Split the text into characters and cache the character texture into a character atlas for reuse, which is suitable for text content with repeated character content and frequently updated.', - font_bold: 'Font bold', - font_italic: 'Font italic', - font_underline: 'Font underlined', - spacing_x: 'The spacing between text characters, only available in BMFont', - underline_height: 'The height of underline', - outline_enable: 'Whether outline is enabled', - outline_width: 'The width of outline', - outline_color: 'The color of outline', - shadow_enable: 'Whether shadow is enabled', - shadow_color: 'The color of shadow', - shadow_offset: 'Offset between font and shadow', - shadow_blur: 'A non-negative float specifying the level of shadow blur', }, labelOutline: { color: 'Outline color', @@ -500,8 +475,6 @@ module.exports = link(mixin({ UIRenderer: { srcBlendFactor: 'Source blend factor', dstBlendFactor: 'Destination blend factor', - customMaterial: 'User specified material', - color: 'Render color', }, rotationOvertimeModule: { separateAxes: 'Set rotation of X, Y and Z respectively (not supported now)', @@ -1344,6 +1317,7 @@ module.exports = link(mixin({ }, require('./modules/rendering'), +require('./modules/ui.js'), require('./animation'), )); diff --git a/editor/i18n/en/modules/ui.js b/editor/i18n/en/modules/ui.js new file mode 100644 index 00000000000..51cfde9954b --- /dev/null +++ b/editor/i18n/en/modules/ui.js @@ -0,0 +1,124 @@ +/* eslint-disable quote-props */ + +module.exports = { + classes: { + 'cc': { + 'UIRenderer': { + properties: { + customMaterial: { + displayName: 'Custom Material', + tooltip: 'Use custom material.', + }, + color: { + displayName: 'Color', + tooltip: 'Rendering color.', + }, + }, + }, + 'Label': { + properties: { + __extends__: 'classes.cc.UIRenderer.properties', + 'string': { + displayName: 'string', + tooltip: 'The label text.', + }, + 'horizontalAlign': { + displayName: 'Horizontal Alignment', + tooltip: 'Horizontal alignment mode.', + }, + 'verticalAlign': { + displayName: 'Vertical Alignment', + tooltip: 'Vertical alignment mode.', + }, + 'fontSize': { + displayName: 'Font Size', + tooltip: 'Font size, in points.', + }, + 'lineHeight': { + displayName: 'Line Height', + tooltip: 'Line height, in points.', + }, + 'spacingX': { + displayName: 'Horizontal Spacing', + tooltip: 'The spacing between text characters, only available if bitmap font was used.', + }, + 'overflow': { + displayName: 'Overflow Processing', + tooltip: 'Text layout modes:
' + + '1. CLAMP: Text nodes outside the bounding box will be truncated.
' + + '2. SHRINK: Automatically shrink text box according to the constraint node.
' + + '3. RESIZE: Automatically updates the Node based on height of the text.', + }, + 'enableWrapText': { + displayName: 'Auto Newline', + tooltip: 'Automatic newline.', + }, + 'useSystemFont': { + displayName: 'System Fonts', + tooltip: 'Whether to use system default fonts. The referenced font asset would be dereferenced once this option was checked.', + }, + 'fontFamily': { + displayName: 'Font Family', + tooltip: 'Font names.', + }, + 'font': { + displayName: 'Font', + tooltip: 'The font asset to use.', + }, + 'cacheMode': { + displayName: 'Cache Mode', + tooltip: 'Text cache modes:
' + + '1. NONE: No cache,draw once.
' + + '2. BITMAP: Text is added as a static image to the dynamic atlas for batch merging, but its content cannot be dynamically modified frequently.
' + + '3. CHAR: Split the text into characters and cache the character texture into a character atlas for reuse, ' + + 'which is suitable for text content with repeated character content and frequently updated.', + }, + 'isBold': { + displayName: 'Bold', + tooltip: 'Make words bold.', + }, + 'isItalic': { + displayName: 'Italic', + tooltip: 'Make words italic.', + }, + 'isUnderline': { + displayName: 'Underline', + tooltip: 'Underscore the words.', + }, + 'underlineHeight': { + displayName: 'Underline Height', + tooltip: 'The underline\'s height.', + }, + 'enableOutline': { + displayName: 'Enable Outline', + tooltip: 'Whether outline is enabled.', + }, + 'outlineColor': { + displayName: 'Outline Color', + tooltip: 'The color of outline.', + }, + 'outlineWidth': { + displayName: 'Outline Width', + tooltip: 'The width of outline', + }, + 'enableShadow': { + displayName: 'Enable Shadow', + tooltip: 'Whether shadow is enabled.', + }, + 'shadowColor': { + displayName: 'Enable Outline', + tooltip: 'The color of shadow.', + }, + 'shadowOffset': { + displayName: 'Shadow Offset', + tooltip: 'Offset between font and shadow.', + }, + 'shadowBlur': { + displayName: 'Shadow Blur', + tooltip: 'A non-negative float specifying the level of shadow blur.', + }, + }, + }, + }, + }, +}; diff --git a/editor/i18n/zh/localization.js b/editor/i18n/zh/localization.js index 63ad5d1e62d..85244cd7877 100755 --- a/editor/i18n/zh/localization.js +++ b/editor/i18n/zh/localization.js @@ -373,37 +373,12 @@ module.exports = link(mixin({ space: '加速度计算时采用的坐标系', }, label: { - string: 'Label 显示的文本内容字符串', - horizontal_align: '文字水平对齐模式', horizontal_align_left: '左对齐', horizontal_align_center: '水平居中对齐', horizontal_align_right: '右对齐', - vertical_align: '文字垂直对齐模式', vertical_align_top: '顶对齐', vertical_align_center: '垂直居中对齐', vertical_align_bottom: '底对齐', - font_size: '文字尺寸,以 point 为单位', - font_family: '文字字体名字', - line_height: '文字行高,以 point 为单位', - overflow: - '文字排版模式,包括以下三种:
1. CLAMP: 节点约束框之外的文字会被截断
2. SHRINK: 自动根据节点约束框缩小文字
3. RESIZE: 根据文本内容自动更新节点的 height 属性.', - wrap: '是否允许自动换行', - font: 'Label 使用的字体资源', - system_font: '是否使用系统默认字体,选中此项会将 file 属性置空', - cache_mode: - '文本缓存模式,包括以下三种:
1. NONE: 不做任何缓存,文本内容进行一次绘制
2. BITMAP: 将文本作为静态图像加入动态图集进行批次合并,但是不能频繁动态修改文本内容
3. CHAR: 将文本拆分为字符并且把字符纹理缓存到一张字符图集中进行复用,适用于字符内容重复并且频繁更新的文本内容', - font_bold: '字体加粗', - font_italic: '字体倾斜', - font_underline: '字体加下划线', - spacing_x: '文本字符之间的间距。仅在使用 BMFont 位图字体时生效', - underline_height: '下划线高度', - outline_enable: '是否启用描边', - outline_width: '描边宽度', - outline_color: '描边颜色', - shadow_enable: '是否启用阴影', - shadow_color: '阴影颜色', - shadow_offset: '阴影偏移量', - shadow_blur: '阴影模糊程度', }, labelOutline: { color: '描边的颜色', @@ -487,8 +462,6 @@ module.exports = link(mixin({ UIRenderer: { srcBlendFactor: '原始混合因子', dstBlendFactor: '目标混合因子', - customMaterial: '用户指定的材质', - color: '渲染颜色', }, rotationOvertimeModule: { separateAxes: '是否三个轴分开设定旋转(暂不支持)', @@ -1318,6 +1291,7 @@ module.exports = link(mixin({ }, require('./modules/rendering'), +require('./modules/ui.js'), require('./animation'), )); diff --git a/editor/i18n/zh/modules/ui.js b/editor/i18n/zh/modules/ui.js new file mode 100644 index 00000000000..fbf429e67fc --- /dev/null +++ b/editor/i18n/zh/modules/ui.js @@ -0,0 +1,123 @@ +/* eslint-disable quote-props */ + +module.exports = { + classes: { + 'cc': { + 'UIRenderer': { + properties: { + customMaterial: { + displayName: '自定义材质', + tooltip: '使用自定义材质。', + }, + color: { + displayName: '颜色', + tooltip: '渲染颜色。', + }, + }, + }, + 'Label': { + properties: { + __extends__: 'classes.cc.UIRenderer.properties', + 'string': { + displayName: '字符串', + tooltip: '显示的文本内容字符串。', + }, + 'horizontalAlign': { + displayName: '水平对齐', + tooltip: '文字水平对齐模式。', + }, + 'verticalAlign': { + displayName: '竖直对齐', + tooltip: '文字竖直对齐模式。', + }, + 'fontSize': { + displayName: '字体大小', + tooltip: '文字尺寸,以点为单位。', + }, + 'lineHeight': { + displayName: '行高', + tooltip: '文字行高,以点为单位。', + }, + 'spacingX': { + displayName: '水平间距', + tooltip: '文本字符之间的间距。仅在使用位图字体时生效', + }, + 'overflow': { + displayName: '溢出处理', + tooltip: '文字排版模式,包括以下三种:
' + + '1. CLAMP: 节点约束框之外的文字会被截断
' + + '2. SHRINK: 自动根据节点约束框缩小文字
' + + '3. RESIZE: 根据文本内容自动更新节点的 height 属性.', + }, + 'enableWrapText': { + displayName: '自动换行', + tooltip: '自动换行。', + }, + 'useSystemFont': { + displayName: '系统字体', + tooltip: '是否使用系统默认字体,选中此项会将引用的字体资产置空。', + }, + 'fontFamily': { + displayName: '字体族', + tooltip: '文字字体名字。', + }, + 'font': { + displayName: '字体', + tooltip: '使用的字体资源。', + }, + 'cacheMode': { + displayName: '缓存模式', + tooltip: '文本缓存模式,包括以下三种:
' + + '1. NONE: 不做任何缓存,文本内容进行一次绘制
' + + '2. BITMAP: 将文本作为静态图像加入动态图集进行批次合并,但是不能频繁动态修改文本内容
' + + '3. CHAR: 将文本拆分为字符并且把字符纹理缓存到一张字符图集中进行复用,适用于字符内容重复并且频繁更新的文本内容', + }, + 'isBold': { + displayName: '粗体', + tooltip: '使字体加粗。', + }, + 'isItalic': { + displayName: '斜体', + tooltip: '使字体倾斜。', + }, + 'isUnderline': { + displayName: '下划线', + tooltip: '为字体加下划线。', + }, + 'underlineHeight': { + displayName: '下划线高度', + tooltip: '下划线高度。', + }, + 'enableOutline': { + displayName: '启用描边', + tooltip: '是否启用描边。', + }, + 'outlineColor': { + displayName: '描边颜色', + tooltip: '描边颜色。', + }, + 'outlineWidth': { + displayName: '描边宽度', + tooltip: '描边宽度。', + }, + 'enableShadow': { + displayName: '启用阴影', + tooltip: '是否启用阴影。', + }, + 'shadowColor': { + displayName: '阴影颜色', + tooltip: '阴影颜色。', + }, + 'shadowOffset': { + displayName: '阴影偏移', + tooltip: '阴影偏移量。', + }, + 'shadowBlur': { + displayName: '阴影模糊', + tooltip: '阴影模糊程度。', + }, + }, + }, + }, + }, +}; From 59acd117372593626189fb7deb5e24c072ef5945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=85=B5?= <49358166+xubing0906@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:40:27 +0800 Subject: [PATCH 28/31] upload property from asset (#16281) --- cocos/asset/assets/effect-asset.jsb.ts | 3 ++- cocos/asset/assets/effect-asset.ts | 3 ++- cocos/render-scene/core/pass.ts | 8 ++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cocos/asset/assets/effect-asset.jsb.ts b/cocos/asset/assets/effect-asset.jsb.ts index 3cc9133abe0..da5e592f58c 100644 --- a/cocos/asset/assets/effect-asset.jsb.ts +++ b/cocos/asset/assets/effect-asset.jsb.ts @@ -29,6 +29,7 @@ import type { EffectAsset as JsbEffectAsset } from './effect-asset'; import type { BlendState, DepthStencilState, RasterizerState, DynamicStateFlags, PrimitiveMode, ShaderStageFlags, Type, Uniform, MemoryAccess, Format} from "../../gfx/index.jsb"; import type { RenderPassStage } from '../../rendering/define'; import type { MacroRecord } from '../../render-scene/core/pass-utils'; +import { TextureBase } from './texture-base'; declare const jsb: any; @@ -50,7 +51,7 @@ export declare namespace EffectAsset { type: number; // auto-extracted from shader handleInfo?: [string, number, number]; // auto-generated from 'target' samplerHash?: number; // auto-generated from 'sampler' - value?: number[] | string; // default value + value?: number[] | string | TextureBase; // default value linear?: boolean; // whether to convert the input to linear space first before applying } // Pass instance itself are compliant to IPassStates too diff --git a/cocos/asset/assets/effect-asset.ts b/cocos/asset/assets/effect-asset.ts index 06d4fac7039..ab330a8145d 100644 --- a/cocos/asset/assets/effect-asset.ts +++ b/cocos/asset/assets/effect-asset.ts @@ -34,13 +34,14 @@ import { Asset } from './asset'; import { cclegacy, warnID } from '../../core'; import { ProgramLibrary } from '../../rendering/custom/private'; import { addEffectDefaultProperties, getCombinationDefines } from '../../render-scene/core/program-utils'; +import { TextureBase } from './texture-base'; export declare namespace EffectAsset { export interface IPropertyInfo { type: number; // auto-extracted from shader handleInfo?: [string, number, number]; // auto-generated from 'target' samplerHash?: number; // auto-generated from 'sampler' - value?: number[] | string; // default value + value?: number[] | string | TextureBase; // default value linear?: boolean; // whether to convert the input to linear space first before applying } // Pass instance itself are compliant to IPassStates too diff --git a/cocos/render-scene/core/pass.ts b/cocos/render-scene/core/pass.ts index c09b83e9396..17df53bd899 100644 --- a/cocos/render-scene/core/pass.ts +++ b/cocos/render-scene/core/pass.ts @@ -432,8 +432,12 @@ export class Pass { const binding = Pass.getBindingFromHandle(handle); const info = this._properties[name]; const value = info && info.value; - const texName = value ? `${value as string}${getStringFromType(type)}` : getDefaultFromType(type) as string; - const textureBase = builtinResMgr.get(texName); + let textureBase: TextureBase; + if (typeof value === 'string') { + textureBase = builtinResMgr.get(`${value}${getStringFromType(type)}`); + } else { + textureBase = value as TextureBase || builtinResMgr.get(getDefaultFromType(type) as string); + } const texture = textureBase && textureBase.getGFXTexture()!; const samplerInfo = info && info.samplerHash !== undefined ? Sampler.unpackFromHash(info.samplerHash) : textureBase && textureBase.getSamplerInfo(); From d75496e187aee33c4555dca2c3ff05137e2b0446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Wed, 11 Oct 2023 17:37:12 +0800 Subject: [PATCH 29/31] Physics material inspector localization (#16409) * Physics material inspector localization * Document property ranges. * Revert * Update editor/i18n/en/modules/physics.js --- .../framework/assets/physics-material.ts | 7 +--- editor/i18n/en/localization.js | 7 +--- editor/i18n/en/modules/physics.js | 39 +++++++++++++++++++ editor/i18n/zh/localization.js | 7 +--- editor/i18n/zh/modules/physics.js | 34 ++++++++++++++++ 5 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 editor/i18n/en/modules/physics.js create mode 100644 editor/i18n/zh/modules/physics.js diff --git a/cocos/physics/framework/assets/physics-material.ts b/cocos/physics/framework/assets/physics-material.ts index fb48fbf6bbb..39aa39e8d49 100644 --- a/cocos/physics/framework/assets/physics-material.ts +++ b/cocos/physics/framework/assets/physics-material.ts @@ -24,7 +24,7 @@ // @ts-check -import { ccclass, editable, help, menu, serializable, tooltip, type } from 'cc.decorator'; +import { ccclass, editable, help, menu, range, serializable, type } from 'cc.decorator'; import { Asset } from '../../../asset/assets/asset'; import { CCFloat, math } from '../../../core'; @@ -61,7 +61,6 @@ export class PhysicsMaterial extends Asset { */ @editable @type(CCFloat) - @tooltip('i18n:physics3d.material.friction') get friction (): number { return this._friction; } @@ -81,7 +80,6 @@ export class PhysicsMaterial extends Asset { */ @editable @type(CCFloat) - @tooltip('i18n:physics3d.material.rollingFriction') get rollingFriction (): number { return this._rollingFriction; } @@ -101,7 +99,6 @@ export class PhysicsMaterial extends Asset { */ @editable @type(CCFloat) - @tooltip('i18n:physics3d.material.spinningFriction') get spinningFriction (): number { return this._spinningFriction; } @@ -121,7 +118,7 @@ export class PhysicsMaterial extends Asset { */ @editable @type(CCFloat) - @tooltip('i18n:physics3d.material.restitution') + @range([0, 1, 0.01]) get restitution (): number { return this._restitution; } diff --git a/editor/i18n/en/localization.js b/editor/i18n/en/localization.js index 610a0be8e76..17d70bf875d 100755 --- a/editor/i18n/en/localization.js +++ b/editor/i18n/en/localization.js @@ -1229,12 +1229,6 @@ module.exports = link(mixin({ strength: 'The strength of the driver', }, }, - material: { - friction: 'The friction coefficient of the material', - rollingFriction: 'The rolling friction coefficient of the material', - spinningFriction: 'The spinning friction coefficient of the material', - restitution: 'The coefficient of restitution of the material', - }, character_controller: { group: 'Collision Group of the character controller.', minMoveDistance: 'The minimum movement distance of the character controller.', @@ -1316,6 +1310,7 @@ module.exports = link(mixin({ }, }, +require('./modules/physics'), require('./modules/rendering'), require('./modules/ui.js'), require('./animation'), diff --git a/editor/i18n/en/modules/physics.js b/editor/i18n/en/modules/physics.js new file mode 100644 index 00000000000..12ea78c09d9 --- /dev/null +++ b/editor/i18n/en/modules/physics.js @@ -0,0 +1,39 @@ +/* eslint-disable quote-props */ + +module.exports = { + classes: { + 'cc': { + 'PhysicsMaterial': { + properties: { + 'friction': { + displayName: 'Friction', + tooltip: + 'Friction coefficient. ' + + 'As the value increases, it becomes more difficult to move the object and the speed of movement decreases more quickly. ' + + 'A friction of 0 feels like ice.', + }, + 'rollingFriction': { + displayName: 'Rolling Friction', + tooltip: 'Rolling friction coefficient. Note this property is only supported on Bullet backend.', + }, + 'spinningFriction': { + displayName: 'Spinning Friction', + tooltip: 'Spinning Friction coefficient. Note this property is only supported on Bullet backend.', + }, + 'restitution': { + displayName: 'Restitution', + tooltip: + 'Restitution coefficient. The value is in [0, 1]. ' + + 'Higher the value, less the kinetic energy loose. ' + + 'A restitution of 0 loose all the energy after collision, ' + + 'so it prevents the object from bounciness(if no other forces were applying), ' + + 'feels like sponges. ' + + 'A restitution of 1 does not looses any energy after collision, ' + + 'so it keeps the object bouncing forever(if no other forces were applying), ' + + 'feels like rubber balls.', + }, + }, + }, + }, + }, +}; diff --git a/editor/i18n/zh/localization.js b/editor/i18n/zh/localization.js index 85244cd7877..ffa5b15edd6 100755 --- a/editor/i18n/zh/localization.js +++ b/editor/i18n/zh/localization.js @@ -1203,12 +1203,6 @@ module.exports = link(mixin({ strength: '驱动器的强度', }, }, - material: { - friction: '材质的摩擦系数', - rollingFriction: '材质的滚动摩擦系数', - spinningFriction: '材质的旋转摩擦系数', - restitution: '材质的弹性系数', - }, character_controller: { group: '碰撞分组', minMoveDistance: '最小移动距离', @@ -1290,6 +1284,7 @@ module.exports = link(mixin({ }, }, +require('./modules/physics'), require('./modules/rendering'), require('./modules/ui.js'), require('./animation'), diff --git a/editor/i18n/zh/modules/physics.js b/editor/i18n/zh/modules/physics.js new file mode 100644 index 00000000000..e05b145fecc --- /dev/null +++ b/editor/i18n/zh/modules/physics.js @@ -0,0 +1,34 @@ +/* eslint-disable quote-props */ + +module.exports = { + classes: { + 'cc': { + 'PhysicsMaterial': { + properties: { + 'friction': { + displayName: '摩擦系数', + tooltip: + '摩擦系数。值越大,越难让物体在接触面移动且移动速度也会降低得更快。' + + '摩擦系数为 0 的感觉就像冰。', + }, + 'rollingFriction': { + displayName: '滚动摩擦系数', + tooltip: '滚动摩擦系数。注意,此属性仅在 Bullet 后端中支持。', + }, + 'spinningFriction': { + displayName: '自旋摩擦系数', + tooltip: '自旋摩擦系数。注意,此属性仅在 Bullet 后端中支持。', + }, + 'restitution': { + displayName: '弹性系数', + tooltip: + '弹性系数。取值范围为 [0, 1]。' + + '值越大,碰撞后动能损失越小。' + + '弹性系数为 0 的物体碰撞后损失所有动能,将不会回弹,其感觉就像海绵;' + + '弹性系数为 1 的物体碰撞后不会有动能损失,将无限次回弹,其感觉就像橡胶球。', + }, + }, + }, + }, + }, +}; From a73168142c2a7f290236c579d01449208b4661a0 Mon Sep 17 00:00:00 2001 From: Zeqiang Li Date: Thu, 12 Oct 2023 14:02:32 +0800 Subject: [PATCH 30/31] storage image usage fix (#16404) --- cocos/rendering/custom/web-pipeline.ts | 11 ++++++++-- cocos/rendering/custom/web-program-library.ts | 22 +++++++++++++------ native/cocos/renderer/gfx-base/GFXBarrier.cpp | 10 ++++----- .../cocos/renderer/gfx-vulkan/VKGPUObjects.h | 7 ++++-- .../renderer/gfx-wgpu/WGPUDescriptorSet.cpp | 12 ++++++---- .../gfx-wgpu/WGPUDescriptorSetLayout.cpp | 22 +++++++++++-------- .../gfx-wgpu/WGPUDescriptorSetLayout.h | 3 ++- .../pipeline/custom/NativeExecutor.cpp | 15 +++++++++++-- 8 files changed, 70 insertions(+), 32 deletions(-) diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index d322396155a..47ee4dff3ec 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -238,7 +238,11 @@ export class WebSetter { this._copyToBuffer(v, offset, Type.FLOAT); } public setBuffer (name: string, buffer: Buffer): void { - // TODO + if (this._getCurrDescriptorBlock(name) === -1) { + return; + } + const num = this._lg.attributeIndex.get(name)!; + this._data.buffers.set(num, buffer); } public setTexture (name: string, texture: Texture): void { if (this._getCurrDescriptorBlock(name) === -1) { @@ -1344,7 +1348,7 @@ export class WebComputePassBuilder extends WebSetter implements ComputePassBuild this._addComputeResource(name, accessType, slotName); } addStorageImage (name: string, accessType: AccessType, slotName: string): void { - throw new Error('Method not implemented.'); + this._addComputeResource(name, accessType, slotName); } addMaterialTexture (resourceName: string, flags?: ShaderStageFlagBit | undefined): void { throw new Error('Method not implemented.'); @@ -1493,6 +1497,9 @@ export class WebPipeline implements BasicPipeline { } updateRenderWindow (name: string, renderWindow: RenderWindow): void { const resId = this.resourceGraph.vertex(name); + const desc = this.resourceGraph.getDesc(resId); + desc.width = renderWindow.width; + desc.height = renderWindow.height; const currFbo = this.resourceGraph._vertices[resId]._object; if (currFbo !== renderWindow.framebuffer) { this.resourceGraph._vertices[resId]._object = renderWindow.framebuffer; diff --git a/cocos/rendering/custom/web-program-library.ts b/cocos/rendering/custom/web-program-library.ts index ba0e5e7ee51..0e8164f6b38 100644 --- a/cocos/rendering/custom/web-program-library.ts +++ b/cocos/rendering/custom/web-program-library.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /**************************************************************************** Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd. @@ -91,7 +92,7 @@ function findBinding (shaderInfo: ShaderInfo, name: string): { set: number, bind function overwriteShaderSourceBinding (shaderInfo: ShaderInfo, source: string): string { let code = source; - const samplerExp = /layout\s*\(([^\)])+\)\s+uniform\s+(\b\w+\b\s+)?sampler(\w+)\s+(\b\w+\b)/g; + const samplerExp = /layout\s*\(([^)])+\)\s+uniform\s+(\b\w+\b\s+)?sampler(\w+)\s+(\b\w+\b)/g; let samplerIter = samplerExp.exec(code); while (samplerIter) { const name = samplerIter[4]; @@ -101,13 +102,20 @@ function overwriteShaderSourceBinding (shaderInfo: ShaderInfo, source: string): code = code.replace(samplerIter[0], replaceStr); samplerIter = samplerExp.exec(code); } - const blockExp = /layout\s*\(([^\)])+\)\s*(readonly)?\s*\b(uniform|buffer)\b\s+(\b\w+\b)\s*[{;]/g; + const blockExp = /layout\s*\(([^)]+)\)\s*(readonly|writeonly)?\s*\b((uniform\s*|buffer\s*|image2D\s*){1,2})\b\s*(\b\w+\b)\s*[{;]/g; let blockIter = blockExp.exec(code); while (blockIter) { - const name = blockIter[4]; + const name = blockIter[5]; const { set, binding } = findBinding(shaderInfo, name); const accessStr = blockIter[2] ? blockIter[2] : ''; - const replaceStr = `layout(set = ${set}, binding = ${binding}) ${accessStr} ${blockIter[3]} ${blockIter[4]} {`; + let endStr = ' {'; + if (blockIter[3].includes('image')) { + endStr = `;`; + } + let desc = blockIter[1]; + desc = desc.replace(/set\s*=\s*\d+/g, `set = ${set}`); + desc = desc.replace(/binding\s*=\s*\d+/g, `binding = ${binding}`); + const replaceStr = `layout(${desc}) ${accessStr} ${blockIter[3]} ${blockIter[5]}${endStr}`; code = code.replace(blockIter[0], replaceStr); blockIter = blockExp.exec(code); } @@ -474,7 +482,7 @@ function calculateFlattenedBinding ( shaderInfo: ShaderInfo, ): void { // Descriptors of UniformBlock starts from 0, and Descriptors of SamplerTexture starts from the end of UniformBlock. - const uniformBlockCapacities = new Array(4); + const uniformBlockCapacities = new Array(4); { const passCapacity = descriptorSets[UpdateFrequency.PER_PASS]?.uniformBlockCapacity || 0; const phaseCapacity = descriptorSets[UpdateFrequency.PER_PHASE]?.uniformBlockCapacity || 0; @@ -496,7 +504,7 @@ function calculateFlattenedBinding ( const batchOffset = instanceOffset + instanceCapacity; // save uniform block offsets by set index - const uniformBlockOffsets = new Array(4); + const uniformBlockOffsets = new Array(4); uniformBlockOffsets[_setIndex[UpdateFrequency.PER_PASS]] = passOffset; uniformBlockOffsets[_setIndex[UpdateFrequency.PER_PHASE]] = phaseOffset; uniformBlockOffsets[_setIndex[UpdateFrequency.PER_BATCH]] = batchOffset; @@ -521,7 +529,7 @@ function calculateFlattenedBinding ( const batchOffset = instanceOffset + instanceCapacity; // save sampler texture offsets by set index - const samplerTextureOffsets = new Array(4); + const samplerTextureOffsets = new Array(4); samplerTextureOffsets[_setIndex[UpdateFrequency.PER_PASS]] = passOffset; samplerTextureOffsets[_setIndex[UpdateFrequency.PER_PHASE]] = phaseOffset; samplerTextureOffsets[_setIndex[UpdateFrequency.PER_BATCH]] = batchOffset; diff --git a/native/cocos/renderer/gfx-base/GFXBarrier.cpp b/native/cocos/renderer/gfx-base/GFXBarrier.cpp index b495fd4d031..1a95adf84ae 100644 --- a/native/cocos/renderer/gfx-base/GFXBarrier.cpp +++ b/native/cocos/renderer/gfx-base/GFXBarrier.cpp @@ -241,7 +241,7 @@ constexpr AccessElem ACCESS_MAP[] = { AccessFlags::VERTEX_SHADER_READ_TEXTURE}, {IGNORE_MEMUSAGE & IGNORE_RESTYPE, - ACCESS_READ | SHADERSTAGE_VERT | CMN_STORAGE, + ACCESS_READ | ACCESS_WRITE | SHADERSTAGE_VERT | CMN_STORAGE, AccessFlags::VERTEX_SHADER_READ_OTHER}, {IGNORE_MEMUSAGE, @@ -251,7 +251,7 @@ constexpr AccessElem ACCESS_MAP[] = { {CARE_MEMACCESS | CARE_RESTYPE | CARE_SHADERSTAGE | CARE_CMNUSAGE, ACCESS_READ | RES_TEXTURE | SHADERSTAGE_FRAG | CMN_ROM, AccessFlags::FRAGMENT_SHADER_READ_TEXTURE, - CMN_STORAGE | CMN_VB_OR_DS}, + CMN_VB_OR_DS}, {IGNORE_MEMUSAGE, ACCESS_READ | RES_TEXTURE | SHADERSTAGE_FRAG | CMN_IB_OR_CA | CMN_INDIRECT_OR_INPUT, @@ -262,7 +262,7 @@ constexpr AccessElem ACCESS_MAP[] = { AccessFlags::FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT}, {IGNORE_MEMUSAGE & IGNORE_RESTYPE, - ACCESS_READ | SHADERSTAGE_FRAG | CMN_STORAGE, + ACCESS_READ | ACCESS_WRITE | SHADERSTAGE_FRAG | CMN_STORAGE, AccessFlags::FRAGMENT_SHADER_READ_OTHER, CMN_SHADING_RATE}, @@ -285,9 +285,9 @@ constexpr AccessElem ACCESS_MAP[] = { // shading rate has its own flag {CARE_MEMACCESS | CARE_SHADERSTAGE | CARE_CMNUSAGE, - ACCESS_READ | SHADERSTAGE_COMP | CMN_STORAGE, + ACCESS_READ | ACCESS_WRITE | SHADERSTAGE_COMP | CMN_STORAGE, AccessFlags::COMPUTE_SHADER_READ_OTHER, - RES_TEXTURE | CMN_ROM}, + CMN_ROM}, {CARE_MEMACCESS | CARE_CMNUSAGE, ACCESS_READ | CMN_COPY_SRC, diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h index 71c4e9cbd2b..12d26e4bf7d 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -1062,8 +1062,11 @@ class CCVKGPUDescriptorHub final { if (hasFlag(texture->gpuTexture->flags, TextureFlagBit::GENERAL_LAYOUT)) { descriptor->imageLayout = VK_IMAGE_LAYOUT_GENERAL; } else { - if (hasAllFlags(flags, AccessFlagBit::FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT | AccessFlagBit::COLOR_ATTACHMENT_WRITE) || - hasAllFlags(flags, AccessFlagBit::FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT | AccessFlagBit::DEPTH_STENCIL_ATTACHMENT_WRITE)) { + bool inoutAttachment = hasAllFlags(flags, AccessFlagBit::FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT | AccessFlagBit::COLOR_ATTACHMENT_WRITE) || + hasAllFlags(flags, AccessFlagBit::FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT | AccessFlagBit::DEPTH_STENCIL_ATTACHMENT_WRITE); + bool storageWrite = hasAnyFlags(flags, AccessFlagBit::VERTEX_SHADER_WRITE | AccessFlagBit::FRAGMENT_SHADER_WRITE | AccessFlagBit::COMPUTE_SHADER_WRITE); + + if (inoutAttachment || storageWrite) { descriptor->imageLayout = VK_IMAGE_LAYOUT_GENERAL; } else if (hasFlag(texture->gpuTexture->usage, TextureUsage::DEPTH_STENCIL_ATTACHMENT)) { descriptor->imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; diff --git a/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSet.cpp b/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSet.cpp index b378027fce3..4ff72bc3177 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSet.cpp @@ -193,7 +193,7 @@ void CCWGPUDescriptorSet::update() { auto &bindGroupEntry = _gpuBindGroupObj->bindGroupEntries.emplace_back(); bindGroupEntry.binding = binding.binding; bindGroupEntry.textureView = static_cast(ccTexture->getPlaneView(0)); - dsLayout->updateTextureLayout(i, ccTexture); + dsLayout->updateSampledTextureLayout(i, ccTexture); _gpuDescriptorObj->gpuDescriptors[i].texture = ccTexture; auto &sBindGroupEntry = _gpuBindGroupObj->bindGroupEntries.emplace_back(); @@ -204,14 +204,18 @@ void CCWGPUDescriptorSet::update() { _gpuDescriptorObj->gpuDescriptors[i].sampler = ccSampler; } else if (DescriptorType::STORAGE_IMAGE == bindings[i].descriptorType || DescriptorType::TEXTURE == bindings[i].descriptorType) { auto *ccTexture = _textures[resourceIndex].ptr ? static_cast(_textures[resourceIndex].ptr) : CCWGPUTexture::defaultCommonTexture(); - auto &bindGroupEntry = _gpuBindGroupObj->bindGroupEntries[resourceIndex]; + auto &bindGroupEntry = _gpuBindGroupObj->bindGroupEntries.emplace_back(); bindGroupEntry.binding = binding.binding; bindGroupEntry.textureView = static_cast(ccTexture->getPlaneView(0)); - dsLayout->updateTextureLayout(i, ccTexture); + if (DescriptorType::STORAGE_IMAGE == bindings[i].descriptorType) { + dsLayout->updateStorageTextureLayout(i, ccTexture); + } else { + dsLayout->updateSampledTextureLayout(i, ccTexture); + } _gpuDescriptorObj->gpuDescriptors[i].texture = ccTexture; } else if (DescriptorType::SAMPLER == bindings[i].descriptorType) { auto *ccSampler = _samplers[resourceIndex].ptr ? static_cast(_samplers[resourceIndex].ptr) : CCWGPUSampler::defaultFilterableSampler(); - auto &bindGroupEntry = _gpuBindGroupObj->bindGroupEntries[resourceIndex]; + auto &bindGroupEntry = _gpuBindGroupObj->bindGroupEntries.emplace_back(); bindGroupEntry.binding = binding.binding; bindGroupEntry.sampler = ccSampler->gpuSampler(); dsLayout->updateSamplerLayout(i, ccSampler); diff --git a/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.cpp b/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.cpp index 9b2c5aa7101..0213a2e66ef 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.cpp @@ -131,21 +131,13 @@ WGPUTextureSampleType sampletypeTraits(const CCWGPUTexture *texture, uint32_t pl } } // namespace -void CCWGPUDescriptorSetLayout::updateTextureLayout(uint8_t index, const CCWGPUTexture *texture, uint32_t plane) { +void CCWGPUDescriptorSetLayout::updateSampledTextureLayout(uint8_t index, const CCWGPUTexture *texture, uint32_t plane) { WGPUBindGroupLayoutEntry textureEntry{}; textureEntry.binding = _bindings[index].binding; textureEntry.visibility = toWGPUShaderStageFlag(_bindings[index].stageFlags); CC_ASSERT(texture); - if (texture->getInfo().usage == TextureUsageBit::STORAGE) { - WGPUStorageTextureBindingLayout storageTextureLayout{}; - storageTextureLayout.access = WGPUStorageTextureAccess::WGPUStorageTextureAccess_WriteOnly; - storageTextureLayout.format = formatTraits(texture, plane); - TextureType type = texture->isTextureView() ? texture->getViewInfo().type : texture->getInfo().type; - storageTextureLayout.viewDimension = toWGPUTextureViewDimension(type); - textureEntry.storageTexture = storageTextureLayout; - } else { WGPUTextureBindingLayout textureLayout{}; textureLayout.sampleType = sampletypeTraits(texture, plane); // textureSampleTypeTrait(texture->getFormat()); const CCWGPUTexture *ccTex = static_cast(texture->isTextureView() ? texture->getViewInfo().texture : texture); @@ -153,7 +145,19 @@ void CCWGPUDescriptorSetLayout::updateTextureLayout(uint8_t index, const CCWGPUT textureLayout.viewDimension = toWGPUTextureViewDimension(type); textureLayout.multisampled = ccTex->getInfo().samples != SampleCount::X1; textureEntry.texture = textureLayout; + _gpuLayoutEntryObj->bindGroupLayoutEntries[textureEntry.binding] = textureEntry; } +void CCWGPUDescriptorSetLayout::updateStorageTextureLayout(uint8_t index, const CCWGPUTexture *texture, uint32_t plane) { + WGPUBindGroupLayoutEntry textureEntry{}; + textureEntry.binding = _bindings[index].binding; + textureEntry.visibility = toWGPUShaderStageFlag(_bindings[index].stageFlags); + CC_ASSERT(texture); + WGPUStorageTextureBindingLayout storageTextureLayout{}; + storageTextureLayout.access = WGPUStorageTextureAccess::WGPUStorageTextureAccess_WriteOnly; + storageTextureLayout.format = formatTraits(texture, plane); + TextureType type = texture->isTextureView() ? texture->getViewInfo().type : texture->getInfo().type; + storageTextureLayout.viewDimension = toWGPUTextureViewDimension(type); + textureEntry.storageTexture = storageTextureLayout; _gpuLayoutEntryObj->bindGroupLayoutEntries[textureEntry.binding] = textureEntry; } diff --git a/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.h b/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.h index 2af10719649..9b174e6cb35 100644 --- a/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.h +++ b/native/cocos/renderer/gfx-wgpu/WGPUDescriptorSetLayout.h @@ -45,7 +45,8 @@ class CCWGPUDescriptorSetLayout final : public DescriptorSetLayout { inline CCWGPUBindGroupLayoutObject *gpuLayoutEntryObject() { return _gpuLayoutEntryObj; } void updateBufferLayout(uint8_t index, const CCWGPUBuffer *buffer, AccessFlags flags); - void updateTextureLayout(uint8_t index, const CCWGPUTexture *texture, uint32_t plane = 0); + void updateSampledTextureLayout(uint8_t index, const CCWGPUTexture *texture, uint32_t plane = 0); + void updateStorageTextureLayout(uint8_t index, const CCWGPUTexture *texture, uint32_t plane = 0); void updateSamplerLayout(uint8_t index, const CCWGPUSampler *sampler); inline void setBindings(const DescriptorSetLayoutBindingList &list) { _bindings.assign(list.begin(), list.end()); } diff --git a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp index bacbc8a90a6..3e72aefa9b6 100644 --- a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp @@ -537,10 +537,20 @@ gfx::DescriptorSet* initDescriptorSet( auto iter = resourceIndex.find(d.descriptorID); if (iter != resourceIndex.end()) { + gfx::AccessFlags access = gfx::AccessFlagBit::NONE; + if (accessNode != nullptr) { + const auto& resID = iter->second; + // whole access only now. + auto parentID = parent(resID, resg); + parentID = parentID == ResourceGraph::null_vertex() ? resID : parentID; + const auto& resName = get(ResourceGraph::NameTag{}, resg, parentID); + access = accessNode->resourceStatus.at(resName).accessFlag; + } + // render graph textures auto* texture = resg.getTexture(iter->second); CC_ENSURES(texture); - newSet->bindTexture(bindID, texture); + newSet->bindTexture(bindID, texture, 0, access); } bindID += d.count; } @@ -940,11 +950,12 @@ struct RenderGraphUploadVisitor : boost::dfs_visitor<> { auto& set = iter->second; const auto& user = get(RenderGraph::DataTag{}, ctx.g, vertID); auto& node = ctx.context.layoutGraphResources.at(layoutID); + const auto& accessNode = ctx.fgd.getAccessNode(vertID); auto* perPassSet = initDescriptorSet( ctx.resourceGraph, ctx.device, ctx.cmdBuff, *ctx.context.defaultResource, ctx.lg, - resourceIndex, set, user, node); + resourceIndex, set, user, node, &accessNode); CC_ENSURES(perPassSet); ctx.renderGraphDescriptorSet[vertID] = perPassSet; } else if (holds(vertID, ctx.g)) { From f8b5d131f453948f723d3fb66ec799afbaea85fb Mon Sep 17 00:00:00 2001 From: qiuguohua Date: Fri, 13 Oct 2023 10:20:04 +0800 Subject: [PATCH 31/31] Turning off textinput when using SDL (#16421) --- native/cocos/platform/SDLHelper.cpp | 6 ++++++ native/cocos/ui/edit-box/EditBox-mac.mm | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/native/cocos/platform/SDLHelper.cpp b/native/cocos/platform/SDLHelper.cpp index 64600cca281..71896c205bc 100644 --- a/native/cocos/platform/SDLHelper.cpp +++ b/native/cocos/platform/SDLHelper.cpp @@ -158,6 +158,12 @@ int SDLHelper::init() { CC_LOG_ERROR("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); return -1; } + // (1) Disable IDE on windows platform. + // (2) On mac platform, SDL has an internal implementation of textinput , + // which internally sends the SDL_TEXTINPUT event. Causing two events to be sent. + // So we need to stop the implementation of TextInput. + // (3) Other platforms do not use textinput in sdl. + stopTextInput(); return 0; } diff --git a/native/cocos/ui/edit-box/EditBox-mac.mm b/native/cocos/ui/edit-box/EditBox-mac.mm index 8b160e5e9a4..e6280e3e664 100644 --- a/native/cocos/ui/edit-box/EditBox-mac.mm +++ b/native/cocos/ui/edit-box/EditBox-mac.mm @@ -242,10 +242,6 @@ void initTextField(const cc::EditBox::ShowInfo &showInfo) { } void init(const cc::EditBox::ShowInfo &showInfo) { - // SDL has an internal implementation of textinput , - // which internally sends the SDL_TEXTINPUT event. Causing two events to be sent. - // So we need to stop the implementation of TextInput. - cc::SDLHelper::stopTextInput(); if (showInfo.isMultiline) initTextView(showInfo); else