From b71e59858a5af3321c7d5cd415cbbbea7a40710e Mon Sep 17 00:00:00 2001 From: qiuguohua Date: Fri, 8 Dec 2023 09:29:05 +0800 Subject: [PATCH 01/32] Fix the error when exiting audio on Xiaomi platform. (#16577) Co-authored-by: qiuguohua --- pal/audio/minigame/player-minigame.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pal/audio/minigame/player-minigame.ts b/pal/audio/minigame/player-minigame.ts index 837dce8d785..78adb0e7e79 100644 --- a/pal/audio/minigame/player-minigame.ts +++ b/pal/audio/minigame/player-minigame.ts @@ -199,6 +199,9 @@ export class AudioPlayerMinigame implements OperationQueueable { this._innerAudioContext.destroy(); // NOTE: Type 'null' is not assignable to type 'InnerAudioContext' this._innerAudioContext = null as any; + // Restore the state of the audio, otherwise it will cause 'destroy' to be called first and 'stop' to be called later. + // this will cause a error. + this._state = AudioState.INIT; } } private _onInterruptedBegin (): void { From 477047f9e4552c50690c65da2aa02cef481a6830 Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Fri, 8 Dec 2023 10:35:55 +0800 Subject: [PATCH 02/32] V3.8.2 pipeline simplify (#16578) --- cocos/rendering/custom/web-pipeline.ts | 45 +++++++++++ .../pipeline/custom/NativePipeline.cpp | 79 ++++++++++++++++++- 2 files changed, 120 insertions(+), 4 deletions(-) diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index c67a25c5d63..70166c75658 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -1892,6 +1892,11 @@ export class WebPipeline implements BasicPipeline { throw new Error('Method not implemented.'); } addRenderWindow (name: string, format: Format, width: number, height: number, renderWindow: RenderWindow): number { + const resID = this._resourceGraph.find(name); + if (resID !== 0xFFFFFFFF) { + this.updateRenderWindow(name, renderWindow); + return resID; + } // Objects need to be held for a long time, so there is no need to use pool management const desc = new ResourceDesc(); desc.dimension = ResourceDimension.TEXTURE2D; @@ -1978,6 +1983,11 @@ export class WebPipeline implements BasicPipeline { } public addBuffer (name: string, size: number, flags: ResourceFlags, residency: ResourceResidency): number { + const resID = this._resourceGraph.find(name); + if (resID !== 0xFFFFFFFF) { + this.updateBuffer(name, size); + return resID; + } const desc = new ResourceDesc(); desc.dimension = ResourceDimension.BUFFER; desc.width = size; @@ -2007,6 +2017,11 @@ export class WebPipeline implements BasicPipeline { } public addTexture (name: string, textureType: TextureType, format: Format, width: number, height: number, depth: number, arraySize: number, mipLevels: number, sampleCount: SampleCount, flags: ResourceFlags, residency: ResourceResidency): number { + const resID = this._resourceGraph.find(name); + if (resID !== 0xFFFFFFFF) { + this.updateTexture(name, format, width, height, depth, arraySize, mipLevels, sampleCount); + return resID; + } const desc = new ResourceDesc(); desc.dimension = getResourceDimension(textureType); desc.width = width; @@ -2034,6 +2049,11 @@ export class WebPipeline implements BasicPipeline { } public addResource (name: string, dimension: ResourceDimension, format: Format, width: number, height: number, depth: number, arraySize: number, mipLevels: number, sampleCount: SampleCount, flags: ResourceFlags, residency: ResourceResidency): number { + const resID = this._resourceGraph.find(name); + if (resID !== 0xFFFFFFFF) { + this.updateResource(name, format, width, height, depth, arraySize, mipLevels, sampleCount); + return resID; + } if (dimension === ResourceDimension.BUFFER) { return this.addBuffer(name, width, flags, residency); } else { @@ -2334,6 +2354,11 @@ export class WebPipeline implements BasicPipeline { this.compile(); } addStorageBuffer (name: string, format: Format, size: number, residency = ResourceResidency.MANAGED): number { + const resID = this._resourceGraph.find(name); + if (resID !== 0xFFFFFFFF) { + this.updateStorageBuffer(name, size, format); + return resID; + } const desc = new ResourceDesc(); desc.dimension = ResourceDimension.BUFFER; desc.width = size; @@ -2366,6 +2391,11 @@ export class WebPipeline implements BasicPipeline { ); } addRenderTarget (name: string, format: Format, width: number, height: number, residency = ResourceResidency.MANAGED): number { + const resID = this._resourceGraph.find(name); + if (resID !== 0xFFFFFFFF) { + this.updateRenderTarget(name, width, height, format); + return resID; + } const desc = new ResourceDesc(); desc.dimension = ResourceDimension.TEXTURE2D; desc.width = width; @@ -2388,6 +2418,11 @@ export class WebPipeline implements BasicPipeline { ); } addDepthStencil (name: string, format: Format, width: number, height: number, residency = ResourceResidency.MANAGED): number { + const resID = this._resourceGraph.find(name); + if (resID !== 0xFFFFFFFF) { + this.updateDepthStencil(name, width, height, format); + return resID; + } const desc = new ResourceDesc(); desc.dimension = ResourceDimension.TEXTURE2D; desc.width = width; @@ -2409,6 +2444,11 @@ export class WebPipeline implements BasicPipeline { ); } addStorageTexture (name: string, format: Format, width: number, height: number, residency = ResourceResidency.MANAGED): number { + const resID = this._resourceGraph.find(name); + if (resID !== 0xFFFFFFFF) { + this.updateStorageTexture(name, width, height, format); + return resID; + } const desc = new ResourceDesc(); desc.dimension = ResourceDimension.TEXTURE2D; desc.width = width; @@ -2429,6 +2469,11 @@ export class WebPipeline implements BasicPipeline { ); } addShadingRateTexture (name: string, width: number, height: number, residency = ResourceResidency.MANAGED): number { + const resID = this._resourceGraph.find(name); + if (resID !== 0xFFFFFFFF) { + this.addShadingRateTexture(name, width, height); + return resID; + } const desc = new ResourceDesc(); desc.dimension = ResourceDimension.TEXTURE2D; desc.width = width; diff --git a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp index ae616096430..5af972a146f 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp @@ -143,6 +143,12 @@ bool NativePipeline::containsResource(const ccstd::string &name) const { } uint32_t NativePipeline::addExternalTexture(const ccstd::string &name, gfx::Texture *texture, ResourceFlags flags) { + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateExternalTexture(name, texture); + return resID; + } + const auto &texInfo = texture->getInfo(); ResourceDesc desc{}; desc.dimension = getResourceDimension(texInfo.type); @@ -185,6 +191,12 @@ void NativePipeline::updateExternalTexture(const ccstd::string &name, gfx::Textu // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) uint32_t NativePipeline::addRenderWindow(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, scene::RenderWindow *renderWindow) { + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateRenderWindow(name, renderWindow); + return resID; + } + ResourceDesc desc{}; desc.dimension = ResourceDimension::TEXTURE2D; desc.width = width; @@ -234,6 +246,11 @@ uint32_t NativePipeline::addRenderWindow(const ccstd::string &name, gfx::Format // NOLINTNEXTLINE uint32_t NativePipeline::addStorageBuffer(const ccstd::string &name, gfx::Format format, uint32_t size, ResourceResidency residency) { + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateStorageBuffer(name, size, format); + return resID; + } ResourceDesc desc{}; desc.dimension = ResourceDimension::BUFFER; desc.width = size; @@ -258,6 +275,11 @@ uint32_t NativePipeline::addStorageBuffer(const ccstd::string &name, gfx::Format // NOLINTNEXTLINE uint32_t NativePipeline::addRenderTarget(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) { + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateRenderTarget(name, width, height, format); + return resID; + } ResourceDesc desc{}; desc.dimension = ResourceDimension::TEXTURE2D; desc.width = width; @@ -283,6 +305,11 @@ uint32_t NativePipeline::addRenderTarget(const ccstd::string &name, gfx::Format // NOLINTNEXTLINE uint32_t NativePipeline::addDepthStencil(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) { + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateDepthStencil(name, width, height, format); + return resID; + } ResourceDesc desc{}; desc.dimension = ResourceDimension::TEXTURE2D; desc.width = width; @@ -302,7 +329,7 @@ uint32_t NativePipeline::addDepthStencil(const ccstd::string &name, gfx::Format samplerInfo.minFilter = gfx::Filter::POINT; samplerInfo.mipFilter = gfx::Filter::NONE; - auto resID = addVertex( + resID = addVertex( ManagedTextureTag{}, std::forward_as_tuple(name.c_str()), std::forward_as_tuple(desc), @@ -317,6 +344,11 @@ uint32_t NativePipeline::addDepthStencil(const ccstd::string &name, gfx::Format } uint32_t NativePipeline::addTexture(const ccstd::string &name, gfx::TextureType type, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) { + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateTexture(name, format, width, height, depth, arraySize, mipLevels, sampleCount); + return resID; + } const auto dimension = getResourceDimension(type); ResourceDesc desc{ dimension, @@ -347,6 +379,11 @@ void NativePipeline::updateTexture(const ccstd::string &name, gfx::Format format } uint32_t NativePipeline::addBuffer(const ccstd::string &name, uint32_t size, ResourceFlags flags, ResourceResidency residency) { + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateBuffer(name, size); + return resID; + } ResourceDesc desc = {}; desc.dimension = ResourceDimension::BUFFER; desc.width = size; @@ -371,7 +408,19 @@ uint32_t NativePipeline::addResource( gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) { - return dimension == ResourceDimension::BUFFER ? addBuffer(name, width, flags, residency) : addTexture(name, getTextureType(dimension, arraySize), format, width, height, depth, arraySize, mipLevels, sampleCount, flags, residency); + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateResource(name, format, width, height, depth, arraySize, mipLevels, sampleCount); + return resID; + } + return dimension == ResourceDimension::BUFFER + ? addBuffer(name, width, flags, residency) + : addTexture( + name, + getTextureType(dimension, arraySize), + format, width, height, depth, + arraySize, mipLevels, sampleCount, + flags, residency); } void NativePipeline::updateResource( @@ -414,6 +463,11 @@ void NativePipeline::updateResource( // NOLINTNEXTLINE uint32_t NativePipeline::addStorageTexture(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) { + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateStorageTexture(name, width, height, format); + return resID; + } ResourceDesc desc{}; desc.dimension = ResourceDimension::TEXTURE2D; desc.width = width; @@ -443,6 +497,11 @@ uint32_t NativePipeline::addStorageTexture(const ccstd::string &name, gfx::Forma } // NOLINTNEXTLINE uint32_t NativePipeline::addShadingRateTexture(const ccstd::string &name, uint32_t width, uint32_t height, ResourceResidency residency) { + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateShadingRateTexture(name, width, height); + return resID; + } ResourceDesc desc{}; desc.dimension = ResourceDimension::TEXTURE2D; desc.width = width; @@ -477,6 +536,11 @@ uint32_t NativePipeline::addCustomBuffer( if (!custom.currentContext) { return ResourceGraph::null_vertex(); } + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateBuffer(name, info.size); + return resID; + } auto &ctx = *custom.currentContext; ResourceDesc desc{}; @@ -509,6 +573,13 @@ uint32_t NativePipeline::addCustomTexture( if (!custom.currentContext) { return ResourceGraph::null_vertex(); } + auto resID = findVertex(ccstd::pmr::string(name, get_allocator()), resourceGraph); + if (resID != ResourceGraph::null_vertex()) { + updateTexture(name, + info.format, info.width, info.height, info.depth, + info.layerCount, info.levelCount, info.samples); + return resID; + } auto &ctx = *custom.currentContext; ResourceDesc desc{}; @@ -553,7 +624,7 @@ void NativePipeline::updateRenderWindow(const ccstd::string &name, scene::Render }, [&](RenderSwapchain &sc) { auto *newSwapchain = renderWindow->getSwapchain(); - const auto& oldTexture = resourceGraph.getTexture(resID); + const auto &oldTexture = resourceGraph.getTexture(resID); resourceGraph.invalidatePersistentRenderPassAndFramebuffer(oldTexture); if (newSwapchain) { desc.width = newSwapchain->getWidth(); @@ -567,7 +638,7 @@ void NativePipeline::updateRenderWindow(const ccstd::string &name, scene::Render CC_EXPECTS(renderWindow->getFramebuffer()->getColorTextures().size() == 1); CC_EXPECTS(renderWindow->getFramebuffer()->getColorTextures().front()); - const auto& texture = renderWindow->getFramebuffer()->getColorTextures().front(); + const auto &texture = renderWindow->getFramebuffer()->getColorTextures().front(); desc.width = texture->getWidth(); desc.height = texture->getHeight(); From d3b6a62aad91c3c681ca036dd3c916a74446251d Mon Sep 17 00:00:00 2001 From: Knox Date: Fri, 8 Dec 2023 17:26:50 +0800 Subject: [PATCH 03/32] Fix label outline error causing ineffective outline. (#16583) --- cocos/2d/assembler/label/letter-font.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/assembler/label/letter-font.ts b/cocos/2d/assembler/label/letter-font.ts index c189b39fb2a..95e00f74448 100644 --- a/cocos/2d/assembler/label/letter-font.ts +++ b/cocos/2d/assembler/label/letter-font.ts @@ -52,7 +52,7 @@ export const letterFont = js.mixin(bmfontUtils, { shareLabelInfo.isOutlined = true; shareLabelInfo.margin = comp.outlineWidth; shareLabelInfo.out = comp.outlineColor.clone(); - shareLabelInfo.out.a = comp.outlineColor.color.a * comp.color.a / 255.0; + shareLabelInfo.out.a = comp.outlineColor.a * comp.color.a / 255.0; } else { shareLabelInfo.isOutlined = false; shareLabelInfo.margin = 0; From 0ec93f11b03a571da20ee6bac8a97be5680fc0fc Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Fri, 8 Dec 2023 19:02:33 +0800 Subject: [PATCH 04/32] V3.8.2 comment (#16581) --- cocos/rendering/custom/pipeline.ts | 294 +++++++++++++++++- .../pipeline/custom/RenderInterfaceTypes.h | 284 ++++++++++++++++- 2 files changed, 550 insertions(+), 28 deletions(-) diff --git a/cocos/rendering/custom/pipeline.ts b/cocos/rendering/custom/pipeline.ts index 652c711b1e6..e50ae821bff 100644 --- a/cocos/rendering/custom/pipeline.ts +++ b/cocos/rendering/custom/pipeline.ts @@ -129,7 +129,14 @@ export interface PipelineRuntime { /** * @en Get shading scale. * Shading scale affects shading texels per pixel. + * Currently it affects classic native forward pipeline and builtin custom pipeline. + * Users can change the size of the render targets according to the shading scale, + * when writing their own custom pipelines. + * To change screen size, please check director.root.resize. * @zh 获得渲染倍率(ShadingScale),每像素(pixel)绘制的纹素(texel)会根据渲染倍率进行调整。 + * 目前仅对原有原生Forward管线以及内置自定义管线生效。 + * 用户编写自定义管线时,可以根据渲染倍率进行渲染目标尺寸大小的调整。 + * 如果要修改屏幕大小,详见director.root.resize。 */ shadingScale: number; /** @@ -378,21 +385,107 @@ export interface Setter extends RenderNode { * @param name @en descriptor name in shader. @zh 填写着色器中的描述符(descriptor)名字 */ setSampler (name: string, sampler: Sampler): void; + /** + * @en Set builtin camera constants of CCCamera, such as cc_matView. + * For list of constants, please check CCCamera in cc-global.chunk. + * @zh 设置内置相机常量,例如cc_matView。 + * 具体常量见cc-global.chunk中的CCCamera. + * @param camera @en The camera instance to be set. @zh 当前相机 + */ setBuiltinCameraConstants (camera: Camera): void; + /** + * @deprecated Method will be removed in 3.9.0 + * @en Same as setBuiltinDirectionalLightConstants + * @zh 同setBuiltinDirectionalLightConstants + * @param light @en The main light. @zh 主光 + */ setBuiltinShadowMapConstants (light: DirectionalLight): void; + /** + * @en Set builtin directional light and shadow constants. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCCamera in cc-global.chunk. + * @zh 设置内置方向光与阴影常量。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-global.chunk中的CCCamera。 + * @param light @en The main light. @zh 主光 + * @param camera @en The camera instance to be set. @zh 当前相机 + */ setBuiltinDirectionalLightConstants (light: DirectionalLight, camera: Camera): void; + /** + * @en Set builtin sphere light and shadow constants. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCForwardLight in cc-forward-light.chunk. + * @zh 设置内置球形光与阴影常量。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-forward-light.chunk中的CCForwardLight。 + * @param light @en The sphere light. @zh 球形光源 + * @param camera @en The camera instance to be set. @zh 当前相机 + */ setBuiltinSphereLightConstants (light: SphereLight, camera: Camera): void; + /** + * @en Set builtin spot light and shadow constants. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCForwardLight in cc-forward-light.chunk. + * @zh 设置内置探照光与阴影常量。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-forward-light.chunk中的CCForwardLight。 + * @param light @en The spot light. @zh 探照光源 + * @param camera @en The camera instance to be set. @zh 当前相机 + */ setBuiltinSpotLightConstants (light: SpotLight, camera: Camera): void; + /** + * @en Set builtin point light and shadow constants. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCForwardLight in cc-forward-light.chunk. + * @zh 设置内置点光与阴影常量。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-forward-light.chunk中的CCForwardLight。 + * @param light @en The point light. @zh 点光源 + * @param camera @en The camera instance to be set. @zh 当前相机 + */ setBuiltinPointLightConstants (light: PointLight, camera: Camera): void; + /** + * @en Set builtin ranged directional light and shadow constants. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCForwardLight in cc-forward-light.chunk. + * @zh 设置内置区间平行光与阴影常量。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-forward-light.chunk中的CCForwardLight。 + * @param light @en The ranged directional light. @zh 区间平行光源 + * @param camera @en The camera instance to be set. @zh 当前相机 + */ setBuiltinRangedDirectionalLightConstants (light: RangedDirectionalLight, camera: Camera): void; + /** + * @en Set builtin directional light frustum and shadow constants. + * These constants are used in builtin shadow map, cascaded shadow map and planar shadow. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCCSM in cc-csm.chunk. + * @zh 设置内置平行光视锥与阴影常量。 + * 这些常量用于内置的阴影、级联阴影与平面阴影。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-csm.chunk中的CCCSM。 + * @param light @en The directional light. @zh 平行光源 + * @param camera @en The camera instance to be set. @zh 当前相机 + * @param csmLevel @en Curent level of cascaded shadow map @zh 级联阴影等级 + */ setBuiltinDirectionalLightFrustumConstants ( camera: Camera, light: DirectionalLight, csmLevel?: number): void; + /** + * @en Set builtin spot light frustum and shadow constants. + * These constants are used in builtin shadow map. + * For list of constants, please check CCShadow in cc-shadow.chunk. + * @zh 设置内置探照光视锥与阴影常量。 + * 这些常量用于内置的阴影。 + * 具体常量见cc-shadow.chunk中的CCShadow。 + * @param light @en The spot light. @zh 探照光源 + */ setBuiltinSpotLightFrustumConstants (light: SpotLight): void; } +/** + * @en Scene + * A scene is an abstraction of content for rendering. + * @zh 场景。需要绘制的场景内容。 + */ export interface SceneBuilder extends Setter { + /** + * @en Use the frustum information of light instead of camera. + * Often used in building shadow map. + * @zh 使用光源视锥进行投影,而不是用相机。常用于shadow map的生成。 + * @param light @en The light used for projection @zh 用于投影的光源 + * @param csmLevel @en Curent level of cascaded shadow map @zh 级联阴影等级 + * @param optCamera @en Additional scene culling camera. @zh 额外的场景裁切相机 + */ useLightFrustum ( light: Light, csmLevel?: number, @@ -420,6 +513,16 @@ export interface RenderQueueBuilder extends Setter { camera: Camera, light: LightInfo, sceneFlags?: SceneFlags): void; + /** + * @en Add the scene to be rendered. + * If SceneFlags.NON_BUILTIN is specified, no builtin constants will be set. + * Otherwise, related builtin constants will be set automatically. + * @zh 添加需要绘制的场景。 + * 如果设置了SceneFlags.NON_BUILTIN,那么不会自动设置内置常量。 + * @param camera @en Camera used for projection @zh 用于投影的相机 + * @param sceneFlags @en Rendering flags of the scene @zh 场景渲染标志位 + * @param light @en Light used for lighting computation @zh 用于光照的光源 + */ addScene ( camera: Camera, sceneFlags: SceneFlags, @@ -561,8 +664,27 @@ export interface BasicRenderPassBuilder extends Setter { showStatistics: boolean; } +/** + * @en Basic multisample render pass builder + * Support resolve render targets and depth stencil. + * This render pass only contains one render subpass. + * If resolve targets are specified, they will be resolved at the end of the render pass. + * After resolving, the contents of multisample render targets and depth stencils are unspecified. + * @zh 基础的多重采样渲染通道。支持决算(Resolve)渲染目标与深度缓冲。 + * 此渲染通道只包含一个渲染子通道。 + * 如果添加了决算对象,那么在渲染通道结束时,会进行决算。 + * 决算后多重采样渲染目标与深度缓冲的内容是未定义的。 + */ export interface BasicMultisampleRenderPassBuilder extends BasicRenderPassBuilder { + /** + * @en Set resolve render target + * @zh 设置决算渲染目标 + */ resolveRenderTarget (source: string, target: string): void; + /** + * @en Set resolve depth stencil + * @zh 设置决算深度模板缓冲 + */ resolveDepthStencil ( source: string, target: string, @@ -575,11 +697,13 @@ export interface BasicMultisampleRenderPassBuilder extends BasicRenderPassBuilde * Basic pipeline provides basic rendering features which are supported on all platforms. * User can register resources which will be used in the render graph. * Theses resources are generally read and write, and will be managed by the pipeline. + * The residency information of resource should not be changed after registration. * In each frame, user can create a render graph to be executed by the pipeline. * @zh 基础渲染管线。 * 基础渲染管线提供基础的渲染能力,能在全平台使用。 * 用户可以在渲染管线中注册资源,这些资源将由管线托管,用于render graph。 * 这些资源一般是可读写的资源。 + * 资源在注册后,不能更改驻留属性。 * 用户可以每帧构建一个render graph,然后交由管线执行。 */ export interface BasicPipeline extends PipelineRuntime { @@ -597,6 +721,10 @@ export interface BasicPipeline extends PipelineRuntime { * @zh 结束管线构建 */ endSetup (): void; + /** + * @en Enable cpu culling of objects affected by the light. Enabled by default. + * @zh 光照计算时,裁切受光源影响的物件。默认开启。 + */ enableCpuLightCulling: boolean; /** * @en Check whether the resource has been registered in the pipeline. @@ -606,8 +734,8 @@ export interface BasicPipeline extends PipelineRuntime { */ containsResource (name: string): boolean; /** - * @en Add render window to the pipeline. - * @zh 注册渲染窗口(RenderWindow) + * @en Add or update render window to the pipeline. + * @zh 注册或更新渲染窗口(RenderWindow) * @param name @en Resource name @zh 资源名字 * @param format @en Expected format of the render window @zh 期望的渲染窗口格式 * @param width @en Expected width of the render window @zh 期望的渲染窗口宽度 @@ -622,6 +750,7 @@ export interface BasicPipeline extends PipelineRuntime { height: number, renderWindow: RenderWindow): number; /** + * @deprecated Method will be removed in 3.9.0 * @en Update render window information. * When render window information is updated, such as resized, user should notify the pipeline. * @zh 更新渲染窗口信息。当渲染窗口发生更新时,用户应通知管线。 @@ -629,8 +758,8 @@ export interface BasicPipeline extends PipelineRuntime { */ updateRenderWindow (name: string, renderWindow: RenderWindow): void; /** - * @en Add 2D render target. - * @zh 添加2D渲染目标 + * @en Add or update 2D render target. + * @zh 添加或更新2D渲染目标 * @param name @en Resource name @zh 资源名字 * @param format @en Format of the resource @zh 资源的格式 * @param width @en Width of the resource @zh 资源的宽度 @@ -645,8 +774,8 @@ export interface BasicPipeline extends PipelineRuntime { height: number, residency?: ResourceResidency): number; /** - * @en Add 2D depth stencil. - * @zh 添加2D深度模板缓冲 + * @en Add or update 2D depth stencil. + * @zh 添加或更新2D深度模板缓冲 * @param name @en Resource name @zh 资源名字 * @param format @en Format of the resource @zh 资源的格式 * @param width @en Width of the resource @zh 资源的宽度 @@ -661,6 +790,7 @@ export interface BasicPipeline extends PipelineRuntime { height: number, residency?: ResourceResidency): number; /** + * @deprecated Method will be removed in 3.9.0 * @en Update render target information. * @zh 更新渲染目标的信息 * @param name @en Resource name @zh 资源名字 @@ -674,6 +804,7 @@ export interface BasicPipeline extends PipelineRuntime { height: number, format?: Format): void; /** + * @deprecated Method will be removed in 3.9.0 * @en Update depth stencil information. * @zh 更新深度模板缓冲的信息 * @param name @en Resource name @zh 资源名字 @@ -686,17 +817,65 @@ export interface BasicPipeline extends PipelineRuntime { width: number, height: number, format?: Format): void; + /** + * @en Add or update buffer. + * @zh 添加或更新缓冲 + * @param name @en Resource name @zh 资源名字 + * @param size @en Size of the resource in bytes @zh 资源的大小 + * @param flags @en Flags of the resource @zh 资源的标志位 + * @param residency @en Residency of the resource. @zh 资源的驻留性 + * @returns Resource ID + */ addBuffer ( name: string, size: number, flags: ResourceFlags, residency: ResourceResidency): number; + /** + * @deprecated Method will be removed in 3.9.0 + * @en Update buffer information. + * @zh 更新缓冲的信息 + * @param name @en Resource name @zh 资源名字 + * @param size @en Size of the resource in bytes @zh 资源的大小 + */ updateBuffer (name: string, size: number): void; + /** + * @en Add or update external texture. + * Must be readonly. + * @zh 添加或更新外部的贴图。贴图必须是只读的。 + * @param name @en Resource name @zh 资源名字 + * @param texture @en External unmanaged texture @zh 外部不受管理的贴图 + * @param flags @en Flags of the resource @zh 资源的标志位 + * @returns Resource ID + */ addExternalTexture ( name: string, texture: Texture, flags: ResourceFlags): number; + /** + * @deprecated Method will be removed in 3.9.0 + * @en Update external texture information. + * @zh 更新外部的贴图信息 + * @param name @en Resource name @zh 资源名字 + * @param texture @en External unmanaged texture @zh 外部不受管理的贴图 + */ updateExternalTexture (name: string, texture: Texture): void; + /** + * @en Add or update texture. + * @zh 添加或更新外部的贴图。 + * @param name @en Resource name @zh 资源名字 + * @param type @en Type of the texture @zh 贴图的类型 + * @param format @en Format of the texture @zh 贴图的格式 + * @param width @en Width of the resource @zh 资源的宽度 + * @param height @en Height of the resource @zh 资源的高度 + * @param depth @en Depth of the resource @zh 资源的深度 + * @param arraySize @en Size of the array @zh 资源数组的大小 + * @param mipLevels @en Mip levels of the texture @zh 贴图的Mipmap数目 + * @param sampleCount @en Sample count of the texture @zh 贴图的采样数目 + * @param flags @en Flags of the resource @zh 资源的标志位 + * @param residency @en Residency of the resource. @zh 资源的驻留性 + * @returns Resource ID + */ addTexture ( name: string, type: TextureType, @@ -709,6 +888,19 @@ export interface BasicPipeline extends PipelineRuntime { sampleCount: SampleCount, flags: ResourceFlags, residency: ResourceResidency): number; + /** + * @deprecated Method will be removed in 3.9.0 + * @en Update texture information. + * @zh 更新贴图信息 + * @param name @en Resource name @zh 资源名字 + * @param format @en Format of the texture @zh 贴图的格式 + * @param width @en Width of the resource @zh 资源的宽度 + * @param height @en Height of the resource @zh 资源的高度 + * @param depth @en Depth of the resource @zh 资源的深度 + * @param arraySize @en Size of the array @zh 资源数组的大小 + * @param mipLevels @en Mip levels of the texture @zh 贴图的Mipmap数目 + * @param sampleCount @en Sample count of the texture @zh 贴图的采样数目 + */ updateTexture ( name: string, format: Format, @@ -718,6 +910,22 @@ export interface BasicPipeline extends PipelineRuntime { arraySize: number, mipLevels: number, sampleCount: SampleCount): void; + /** + * @en Add or update resource. + * @zh 添加或更新资源 + * @param name @en Resource name @zh 资源名字 + * @param dimension @en Dimension of the resource @zh 资源的维度 + * @param format @en Format of the texture @zh 资源的格式 + * @param width @en Width of the resource @zh 资源的宽度 + * @param height @en Height of the resource @zh 资源的高度 + * @param depth @en Depth of the resource @zh 资源的深度 + * @param arraySize @en Size of the array @zh 资源数组的大小 + * @param mipLevels @en Mip levels of the texture @zh 资源的Mipmap数目 + * @param sampleCount @en Sample count of the texture @zh 资源的采样数目 + * @param flags @en Flags of the resource @zh 资源的标志位 + * @param residency @en Residency of the resource. @zh 资源的驻留性 + * @returns Resource ID + */ addResource ( name: string, dimension: ResourceDimension, @@ -730,6 +938,19 @@ export interface BasicPipeline extends PipelineRuntime { sampleCount: SampleCount, flags: ResourceFlags, residency: ResourceResidency): number; + /** + * @deprecated Method will be removed in 3.9.0 + * @en Update resource information. + * @zh 更新资源信息 + * @param name @en Resource name @zh 资源名字 + * @param format @en Format of the texture @zh 资源的格式 + * @param width @en Width of the resource @zh 资源的宽度 + * @param height @en Height of the resource @zh 资源的高度 + * @param depth @en Depth of the resource @zh 资源的深度 + * @param arraySize @en Size of the array @zh 资源数组的大小 + * @param mipLevels @en Mip levels of the texture @zh 资源的Mipmap数目 + * @param sampleCount @en Sample count of the texture @zh 资源的采样数目 + */ updateResource ( name: string, format: Format, @@ -812,6 +1033,11 @@ export interface BasicPipeline extends PipelineRuntime { * @param copyPairs @en Array of copy source and target @zh 拷贝来源与目标的数组 */ addCopyPass (copyPairs: CopyPair[]): void; + /** + * @en Builtin reflection probe pass + * @zh 添加内置环境光反射通道 + * @param camera @en Capturing camera @zh 用于捕捉的相机 + */ addBuiltinReflectionProbePass (camera: Camera): void; /** * @engineInternal @@ -1151,11 +1377,29 @@ export interface RenderPassBuilder extends BasicRenderPassBuilder { setCustomShaderStages (name: string, stageFlags: ShaderStageFlagBit): void; } +/** + * @en Multisample render pass builder + * @zh 多重采样渲染通道。 + */ export interface MultisampleRenderPassBuilder extends BasicMultisampleRenderPassBuilder { + /** + * @en Add storage buffer + * @zh 添加存储缓冲 + * @param name @en Name of the storage buffer @zh 存储缓冲的名字 + * @param accessType @en Access type of the buffer in the render pass @zh 渲染通道中缓冲的读写状态 + * @param slotName @en name of the descriptor in shader @zh 着色器中描述符的名字 + */ addStorageBuffer ( name: string, accessType: AccessType, slotName: string): void; + /** + * @en Add storage image + * @zh 添加存储贴图 + * @param name @en Name of the storage texture @zh 存储贴图的名字 + * @param accessType @en Access type of the texture in the render pass @zh 渲染通道中贴图的读写状态 + * @param slotName @en name of the descriptor in shader @zh 着色器中描述符的名字 + */ addStorageImage ( name: string, accessType: AccessType, @@ -1247,11 +1491,11 @@ export interface ComputePassBuilder extends Setter { */ export interface Pipeline extends BasicPipeline { /** - * @en Add storage buffer. - * @zh 添加存储缓冲 + * @en Add or update storage buffer. + * @zh 添加或更新存储缓冲 * @param name @en Resource name @zh 资源名字 * @param format @en Format of the resource @zh 资源的格式 - * @param size @en Size of the resource @zh 资源的大小 + * @param size @en Size of the resource in bytes @zh 资源的大小 * @param residency @en Residency of the resource. @zh 资源的驻留性 */ addStorageBuffer ( @@ -1260,8 +1504,8 @@ export interface Pipeline extends BasicPipeline { size: number, residency?: ResourceResidency): number; /** - * @en Add 2D storage texture - * @zh 添加2D存储贴图 + * @en Add or update 2D storage texture + * @zh 添加或更新2D存储贴图 * @param name @en Resource name @zh 资源名字 * @param format @en Format of the resource @zh 资源的格式 * @param width @en Width of the resource @zh 资源的宽度 @@ -1276,8 +1520,8 @@ export interface Pipeline extends BasicPipeline { residency?: ResourceResidency): number; /** * @experimental - * @en Add 2D shading rate texture - * @zh 添加2D着色率贴图 + * @en Add or update 2D shading rate texture + * @zh 添加或更新2D着色率贴图 * @param name @en Resource name @zh 资源名字 * @param width @en Width of the resource @zh 资源的宽度 * @param height @en Height of the resource @zh 资源的高度 @@ -1292,7 +1536,7 @@ export interface Pipeline extends BasicPipeline { * @en Update storage buffer information. * @zh 更新存储缓冲的信息 * @param name @en Resource name @zh 资源名字 - * @param size @en Size of the resource @zh 资源的大小 + * @param size @en Size of the resource in bytes @zh 资源的大小 * @param format @en Format of the resource @zh 资源的格式 */ updateStorageBuffer ( @@ -1335,6 +1579,16 @@ export interface Pipeline extends BasicPipeline { width: number, height: number, passName: string): RenderPassBuilder; + /** + * @en Add multisample render pass + * @zh 添加多重采样渲染通道 + * @param width @en Width of the render pass @zh 渲染通道的宽度 + * @param height @en Height of the render pass @zh 渲染通道的高度 + * @param count @en Sample count @zh 采样数目 + * @param quality @en Sample quality (default is 0) @zh 采样质量(默认为0) + * @param passName @en Pass name declared in the effect. Default value is 'default' @zh effect中的pass name,缺省为'default' + * @returns Multisample render pass builder + */ addMultisampleRenderPass ( width: number, height: number, @@ -1390,10 +1644,18 @@ export interface Pipeline extends BasicPipeline { * @param movePairs @en Array of move source and target @zh 移动来源与目标的数组 */ addMovePass (movePairs: MovePair[]): void; + /** + * @experimental + * @engineInternal + */ addBuiltinGpuCullingPass ( camera: Camera, hzbName?: string, light?: Light): void; + /** + * @experimental + * @engineInternal + */ addBuiltinHzbGenerationPass (sourceDepthStencilName: string, targetHzbName: string): void; /** * @experimental @@ -1427,6 +1689,10 @@ export interface PipelineBuilder { * @param pipeline @en Current render pipeline @zh 当前管线 */ setup (cameras: Camera[], pipeline: BasicPipeline): void; + /** + * @en Callback of pipeline state changed + * @zh 渲染管线状态更新的回调 + */ onGlobalPipelineStateChanged? (): void; } diff --git a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h index 09dd08e0c27..69579a3de62 100644 --- a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h @@ -173,7 +173,14 @@ class PipelineRuntime { /** * @en Get shading scale. * Shading scale affects shading texels per pixel. + * Currently it affects classic native forward pipeline and builtin custom pipeline. + * Users can change the size of the render targets according to the shading scale, + * when writing their own custom pipelines. + * To change screen size, please check director.root.resize. * @zh 获得渲染倍率(ShadingScale),每像素(pixel)绘制的纹素(texel)会根据渲染倍率进行调整。 + * 目前仅对原有原生Forward管线以及内置自定义管线生效。 + * 用户编写自定义管线时,可以根据渲染倍率进行渲染目标尺寸大小的调整。 + * 如果要修改屏幕大小,详见director.root.resize。 */ virtual float getShadingScale() const = 0; virtual void setShadingScale(float scale) = 0; @@ -457,24 +464,110 @@ class Setter : public RenderNode { * @param name @en descriptor name in shader. @zh 填写着色器中的描述符(descriptor)名字 */ virtual void setSampler(const ccstd::string &name, gfx::Sampler *sampler) = 0; + /** + * @en Set builtin camera constants of CCCamera, such as cc_matView. + * For list of constants, please check CCCamera in cc-global.chunk. + * @zh 设置内置相机常量,例如cc_matView。 + * 具体常量见cc-global.chunk中的CCCamera. + * @param camera @en The camera instance to be set. @zh 当前相机 + */ virtual void setBuiltinCameraConstants(const scene::Camera *camera) = 0; + /** + * @deprecated Method will be removed in 3.9.0 + * @en Same as setBuiltinDirectionalLightConstants + * @zh 同setBuiltinDirectionalLightConstants + * @param light @en The main light. @zh 主光 + */ virtual void setBuiltinShadowMapConstants(const scene::DirectionalLight *light) = 0; + /** + * @en Set builtin directional light and shadow constants. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCCamera in cc-global.chunk. + * @zh 设置内置方向光与阴影常量。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-global.chunk中的CCCamera。 + * @param light @en The main light. @zh 主光 + * @param camera @en The camera instance to be set. @zh 当前相机 + */ virtual void setBuiltinDirectionalLightConstants(const scene::DirectionalLight *light, const scene::Camera *camera) = 0; + /** + * @en Set builtin sphere light and shadow constants. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCForwardLight in cc-forward-light.chunk. + * @zh 设置内置球形光与阴影常量。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-forward-light.chunk中的CCForwardLight。 + * @param light @en The sphere light. @zh 球形光源 + * @param camera @en The camera instance to be set. @zh 当前相机 + */ virtual void setBuiltinSphereLightConstants(const scene::SphereLight *light, const scene::Camera *camera) = 0; + /** + * @en Set builtin spot light and shadow constants. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCForwardLight in cc-forward-light.chunk. + * @zh 设置内置探照光与阴影常量。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-forward-light.chunk中的CCForwardLight。 + * @param light @en The spot light. @zh 探照光源 + * @param camera @en The camera instance to be set. @zh 当前相机 + */ virtual void setBuiltinSpotLightConstants(const scene::SpotLight *light, const scene::Camera *camera) = 0; + /** + * @en Set builtin point light and shadow constants. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCForwardLight in cc-forward-light.chunk. + * @zh 设置内置点光与阴影常量。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-forward-light.chunk中的CCForwardLight。 + * @param light @en The point light. @zh 点光源 + * @param camera @en The camera instance to be set. @zh 当前相机 + */ virtual void setBuiltinPointLightConstants(const scene::PointLight *light, const scene::Camera *camera) = 0; + /** + * @en Set builtin ranged directional light and shadow constants. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCForwardLight in cc-forward-light.chunk. + * @zh 设置内置区间平行光与阴影常量。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-forward-light.chunk中的CCForwardLight。 + * @param light @en The ranged directional light. @zh 区间平行光源 + * @param camera @en The camera instance to be set. @zh 当前相机 + */ virtual void setBuiltinRangedDirectionalLightConstants(const scene::RangedDirectionalLight *light, const scene::Camera *camera) = 0; + /** + * @en Set builtin directional light frustum and shadow constants. + * These constants are used in builtin shadow map, cascaded shadow map and planar shadow. + * For list of constants, please check CCShadow in cc-shadow.chunk and CCCSM in cc-csm.chunk. + * @zh 设置内置平行光视锥与阴影常量。 + * 这些常量用于内置的阴影、级联阴影与平面阴影。 + * 具体常量见cc-shadow.chunk中的CCShadow与cc-csm.chunk中的CCCSM。 + * @param light @en The directional light. @zh 平行光源 + * @param camera @en The camera instance to be set. @zh 当前相机 + * @param csmLevel @en Curent level of cascaded shadow map @zh 级联阴影等级 + */ virtual void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light, uint32_t csmLevel) = 0; + /** + * @en Set builtin spot light frustum and shadow constants. + * These constants are used in builtin shadow map. + * For list of constants, please check CCShadow in cc-shadow.chunk. + * @zh 设置内置探照光视锥与阴影常量。 + * 这些常量用于内置的阴影。 + * 具体常量见cc-shadow.chunk中的CCShadow。 + * @param light @en The spot light. @zh 探照光源 + */ virtual void setBuiltinSpotLightFrustumConstants(const scene::SpotLight *light) = 0; void setBuiltinDirectionalLightFrustumConstants(const scene::Camera *camera, const scene::DirectionalLight *light) { setBuiltinDirectionalLightFrustumConstants(camera, light, 0); } }; +/** + * @en Scene + * A scene is an abstraction of content for rendering. + * @zh 场景。需要绘制的场景内容。 + */ class SceneBuilder : public Setter { public: SceneBuilder() noexcept = default; + /** + * @en Use the frustum information of light instead of camera. + * Often used in building shadow map. + * @zh 使用光源视锥进行投影,而不是用相机。常用于shadow map的生成。 + * @param light @en The light used for projection @zh 用于投影的光源 + * @param csmLevel @en Curent level of cascaded shadow map @zh 级联阴影等级 + * @param optCamera @en Additional scene culling camera. @zh 额外的场景裁切相机 + */ virtual void useLightFrustum(IntrusivePtr light, uint32_t csmLevel, const scene::Camera *optCamera) = 0; void useLightFrustum(IntrusivePtr light) { useLightFrustum(std::move(light), 0, nullptr); @@ -505,6 +598,16 @@ class RenderQueueBuilder : public Setter { * @param sceneFlags @en Rendering flags of the scene @zh 场景渲染标志位 */ virtual void addSceneOfCamera(scene::Camera *camera, LightInfo light, SceneFlags sceneFlags) = 0; + /** + * @en Add the scene to be rendered. + * If SceneFlags.NON_BUILTIN is specified, no builtin constants will be set. + * Otherwise, related builtin constants will be set automatically. + * @zh 添加需要绘制的场景。 + * 如果设置了SceneFlags.NON_BUILTIN,那么不会自动设置内置常量。 + * @param camera @en Camera used for projection @zh 用于投影的相机 + * @param sceneFlags @en Rendering flags of the scene @zh 场景渲染标志位 + * @param light @en Light used for lighting computation @zh 用于光照的光源 + */ virtual SceneBuilder *addScene(const scene::Camera *camera, SceneFlags sceneFlags, scene::Light *light) = 0; /** * @en Render a full-screen quad. @@ -677,11 +780,30 @@ class BasicRenderPassBuilder : public Setter { } }; +/** + * @en Basic multisample render pass builder + * Support resolve render targets and depth stencil. + * This render pass only contains one render subpass. + * If resolve targets are specified, they will be resolved at the end of the render pass. + * After resolving, the contents of multisample render targets and depth stencils are unspecified. + * @zh 基础的多重采样渲染通道。支持决算(Resolve)渲染目标与深度缓冲。 + * 此渲染通道只包含一个渲染子通道。 + * 如果添加了决算对象,那么在渲染通道结束时,会进行决算。 + * 决算后多重采样渲染目标与深度缓冲的内容是未定义的。 + */ class BasicMultisampleRenderPassBuilder : public BasicRenderPassBuilder { public: BasicMultisampleRenderPassBuilder() noexcept = default; + /** + * @en Set resolve render target + * @zh 设置决算渲染目标 + */ virtual void resolveRenderTarget(const ccstd::string &source, const ccstd::string &target) = 0; + /** + * @en Set resolve depth stencil + * @zh 设置决算深度模板缓冲 + */ virtual void resolveDepthStencil(const ccstd::string &source, const ccstd::string &target, gfx::ResolveMode depthMode, gfx::ResolveMode stencilMode) = 0; void resolveDepthStencil(const ccstd::string &source, const ccstd::string &target) { resolveDepthStencil(source, target, gfx::ResolveMode::SAMPLE_ZERO, gfx::ResolveMode::SAMPLE_ZERO); @@ -696,11 +818,13 @@ class BasicMultisampleRenderPassBuilder : public BasicRenderPassBuilder { * Basic pipeline provides basic rendering features which are supported on all platforms. * User can register resources which will be used in the render graph. * Theses resources are generally read and write, and will be managed by the pipeline. + * The residency information of resource should not be changed after registration. * In each frame, user can create a render graph to be executed by the pipeline. * @zh 基础渲染管线。 * 基础渲染管线提供基础的渲染能力,能在全平台使用。 * 用户可以在渲染管线中注册资源,这些资源将由管线托管,用于render graph。 * 这些资源一般是可读写的资源。 + * 资源在注册后,不能更改驻留属性。 * 用户可以每帧构建一个render graph,然后交由管线执行。 */ class BasicPipeline : public PipelineRuntime { @@ -721,6 +845,10 @@ class BasicPipeline : public PipelineRuntime { * @zh 结束管线构建 */ virtual void endSetup() = 0; + /** + * @en Enable cpu culling of objects affected by the light. Enabled by default. + * @zh 光照计算时,裁切受光源影响的物件。默认开启。 + */ virtual bool getEnableCpuLightCulling() const = 0; virtual void setEnableCpuLightCulling(bool enable) = 0; /** @@ -731,8 +859,8 @@ class BasicPipeline : public PipelineRuntime { */ virtual bool containsResource(const ccstd::string &name) const = 0; /** - * @en Add render window to the pipeline. - * @zh 注册渲染窗口(RenderWindow) + * @en Add or update render window to the pipeline. + * @zh 注册或更新渲染窗口(RenderWindow) * @param name @en Resource name @zh 资源名字 * @param format @en Expected format of the render window @zh 期望的渲染窗口格式 * @param width @en Expected width of the render window @zh 期望的渲染窗口宽度 @@ -742,6 +870,7 @@ class BasicPipeline : public PipelineRuntime { */ virtual uint32_t addRenderWindow(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, scene::RenderWindow *renderWindow) = 0; /** + * @deprecated Method will be removed in 3.9.0 * @en Update render window information. * When render window information is updated, such as resized, user should notify the pipeline. * @zh 更新渲染窗口信息。当渲染窗口发生更新时,用户应通知管线。 @@ -749,8 +878,8 @@ class BasicPipeline : public PipelineRuntime { */ virtual void updateRenderWindow(const ccstd::string &name, scene::RenderWindow *renderWindow) = 0; /** - * @en Add 2D render target. - * @zh 添加2D渲染目标 + * @en Add or update 2D render target. + * @zh 添加或更新2D渲染目标 * @param name @en Resource name @zh 资源名字 * @param format @en Format of the resource @zh 资源的格式 * @param width @en Width of the resource @zh 资源的宽度 @@ -760,8 +889,8 @@ class BasicPipeline : public PipelineRuntime { */ virtual uint32_t addRenderTarget(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) = 0; /** - * @en Add 2D depth stencil. - * @zh 添加2D深度模板缓冲 + * @en Add or update 2D depth stencil. + * @zh 添加或更新2D深度模板缓冲 * @param name @en Resource name @zh 资源名字 * @param format @en Format of the resource @zh 资源的格式 * @param width @en Width of the resource @zh 资源的宽度 @@ -771,6 +900,7 @@ class BasicPipeline : public PipelineRuntime { */ virtual uint32_t addDepthStencil(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) = 0; /** + * @deprecated Method will be removed in 3.9.0 * @en Update render target information. * @zh 更新渲染目标的信息 * @param name @en Resource name @zh 资源名字 @@ -780,6 +910,7 @@ class BasicPipeline : public PipelineRuntime { */ virtual void updateRenderTarget(const ccstd::string &name, uint32_t width, uint32_t height, gfx::Format format) = 0; /** + * @deprecated Method will be removed in 3.9.0 * @en Update depth stencil information. * @zh 更新深度模板缓冲的信息 * @param name @en Resource name @zh 资源名字 @@ -788,13 +919,103 @@ class BasicPipeline : public PipelineRuntime { * @param format @en Format of the resource @zh 资源的格式 */ virtual void updateDepthStencil(const ccstd::string &name, uint32_t width, uint32_t height, gfx::Format format) = 0; + /** + * @en Add or update buffer. + * @zh 添加或更新缓冲 + * @param name @en Resource name @zh 资源名字 + * @param size @en Size of the resource in bytes @zh 资源的大小 + * @param flags @en Flags of the resource @zh 资源的标志位 + * @param residency @en Residency of the resource. @zh 资源的驻留性 + * @returns Resource ID + */ virtual uint32_t addBuffer(const ccstd::string &name, uint32_t size, ResourceFlags flags, ResourceResidency residency) = 0; + /** + * @deprecated Method will be removed in 3.9.0 + * @en Update buffer information. + * @zh 更新缓冲的信息 + * @param name @en Resource name @zh 资源名字 + * @param size @en Size of the resource in bytes @zh 资源的大小 + */ virtual void updateBuffer(const ccstd::string &name, uint32_t size) = 0; + /** + * @en Add or update external texture. + * Must be readonly. + * @zh 添加或更新外部的贴图。贴图必须是只读的。 + * @param name @en Resource name @zh 资源名字 + * @param texture @en External unmanaged texture @zh 外部不受管理的贴图 + * @param flags @en Flags of the resource @zh 资源的标志位 + * @returns Resource ID + */ virtual uint32_t addExternalTexture(const ccstd::string &name, gfx::Texture *texture, ResourceFlags flags) = 0; + /** + * @deprecated Method will be removed in 3.9.0 + * @en Update external texture information. + * @zh 更新外部的贴图信息 + * @param name @en Resource name @zh 资源名字 + * @param texture @en External unmanaged texture @zh 外部不受管理的贴图 + */ virtual void updateExternalTexture(const ccstd::string &name, gfx::Texture *texture) = 0; + /** + * @en Add or update texture. + * @zh 添加或更新外部的贴图。 + * @param name @en Resource name @zh 资源名字 + * @param type @en Type of the texture @zh 贴图的类型 + * @param format @en Format of the texture @zh 贴图的格式 + * @param width @en Width of the resource @zh 资源的宽度 + * @param height @en Height of the resource @zh 资源的高度 + * @param depth @en Depth of the resource @zh 资源的深度 + * @param arraySize @en Size of the array @zh 资源数组的大小 + * @param mipLevels @en Mip levels of the texture @zh 贴图的Mipmap数目 + * @param sampleCount @en Sample count of the texture @zh 贴图的采样数目 + * @param flags @en Flags of the resource @zh 资源的标志位 + * @param residency @en Residency of the resource. @zh 资源的驻留性 + * @returns Resource ID + */ virtual uint32_t addTexture(const ccstd::string &name, gfx::TextureType type, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) = 0; + /** + * @deprecated Method will be removed in 3.9.0 + * @en Update texture information. + * @zh 更新贴图信息 + * @param name @en Resource name @zh 资源名字 + * @param format @en Format of the texture @zh 贴图的格式 + * @param width @en Width of the resource @zh 资源的宽度 + * @param height @en Height of the resource @zh 资源的高度 + * @param depth @en Depth of the resource @zh 资源的深度 + * @param arraySize @en Size of the array @zh 资源数组的大小 + * @param mipLevels @en Mip levels of the texture @zh 贴图的Mipmap数目 + * @param sampleCount @en Sample count of the texture @zh 贴图的采样数目 + */ virtual void updateTexture(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount) = 0; + /** + * @en Add or update resource. + * @zh 添加或更新资源 + * @param name @en Resource name @zh 资源名字 + * @param dimension @en Dimension of the resource @zh 资源的维度 + * @param format @en Format of the texture @zh 资源的格式 + * @param width @en Width of the resource @zh 资源的宽度 + * @param height @en Height of the resource @zh 资源的高度 + * @param depth @en Depth of the resource @zh 资源的深度 + * @param arraySize @en Size of the array @zh 资源数组的大小 + * @param mipLevels @en Mip levels of the texture @zh 资源的Mipmap数目 + * @param sampleCount @en Sample count of the texture @zh 资源的采样数目 + * @param flags @en Flags of the resource @zh 资源的标志位 + * @param residency @en Residency of the resource. @zh 资源的驻留性 + * @returns Resource ID + */ virtual uint32_t addResource(const ccstd::string &name, ResourceDimension dimension, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount, ResourceFlags flags, ResourceResidency residency) = 0; + /** + * @deprecated Method will be removed in 3.9.0 + * @en Update resource information. + * @zh 更新资源信息 + * @param name @en Resource name @zh 资源名字 + * @param format @en Format of the texture @zh 资源的格式 + * @param width @en Width of the resource @zh 资源的宽度 + * @param height @en Height of the resource @zh 资源的高度 + * @param depth @en Depth of the resource @zh 资源的深度 + * @param arraySize @en Size of the array @zh 资源数组的大小 + * @param mipLevels @en Mip levels of the texture @zh 资源的Mipmap数目 + * @param sampleCount @en Sample count of the texture @zh 资源的采样数目 + */ virtual void updateResource(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t arraySize, uint32_t mipLevels, gfx::SampleCount sampleCount) = 0; /** * @engineInternal @@ -861,6 +1082,11 @@ class BasicPipeline : public PipelineRuntime { * @param copyPairs @en Array of copy source and target @zh 拷贝来源与目标的数组 */ virtual void addCopyPass(const ccstd::vector ©Pairs) = 0; + /** + * @en Builtin reflection probe pass + * @zh 添加内置环境光反射通道 + * @param camera @en Capturing camera @zh 用于捕捉的相机 + */ virtual void addBuiltinReflectionProbePass(const scene::Camera *camera) = 0; /** * @engineInternal @@ -1253,11 +1479,29 @@ class RenderPassBuilder : public BasicRenderPassBuilder { } }; +/** + * @en Multisample render pass builder + * @zh 多重采样渲染通道。 + */ class MultisampleRenderPassBuilder : public BasicMultisampleRenderPassBuilder { public: MultisampleRenderPassBuilder() noexcept = default; + /** + * @en Add storage buffer + * @zh 添加存储缓冲 + * @param name @en Name of the storage buffer @zh 存储缓冲的名字 + * @param accessType @en Access type of the buffer in the render pass @zh 渲染通道中缓冲的读写状态 + * @param slotName @en name of the descriptor in shader @zh 着色器中描述符的名字 + */ virtual void addStorageBuffer(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) = 0; + /** + * @en Add storage image + * @zh 添加存储贴图 + * @param name @en Name of the storage texture @zh 存储贴图的名字 + * @param accessType @en Access type of the texture in the render pass @zh 渲染通道中贴图的读写状态 + * @param slotName @en name of the descriptor in shader @zh 着色器中描述符的名字 + */ virtual void addStorageImage(const ccstd::string &name, AccessType accessType, const ccstd::string &slotName) = 0; }; @@ -1354,17 +1598,17 @@ class Pipeline : public BasicPipeline { Pipeline() noexcept = default; /** - * @en Add storage buffer. - * @zh 添加存储缓冲 + * @en Add or update storage buffer. + * @zh 添加或更新存储缓冲 * @param name @en Resource name @zh 资源名字 * @param format @en Format of the resource @zh 资源的格式 - * @param size @en Size of the resource @zh 资源的大小 + * @param size @en Size of the resource in bytes @zh 资源的大小 * @param residency @en Residency of the resource. @zh 资源的驻留性 */ virtual uint32_t addStorageBuffer(const ccstd::string &name, gfx::Format format, uint32_t size, ResourceResidency residency) = 0; /** - * @en Add 2D storage texture - * @zh 添加2D存储贴图 + * @en Add or update 2D storage texture + * @zh 添加或更新2D存储贴图 * @param name @en Resource name @zh 资源名字 * @param format @en Format of the resource @zh 资源的格式 * @param width @en Width of the resource @zh 资源的宽度 @@ -1374,8 +1618,8 @@ class Pipeline : public BasicPipeline { virtual uint32_t addStorageTexture(const ccstd::string &name, gfx::Format format, uint32_t width, uint32_t height, ResourceResidency residency) = 0; /** * @experimental - * @en Add 2D shading rate texture - * @zh 添加2D着色率贴图 + * @en Add or update 2D shading rate texture + * @zh 添加或更新2D着色率贴图 * @param name @en Resource name @zh 资源名字 * @param width @en Width of the resource @zh 资源的宽度 * @param height @en Height of the resource @zh 资源的高度 @@ -1386,7 +1630,7 @@ class Pipeline : public BasicPipeline { * @en Update storage buffer information. * @zh 更新存储缓冲的信息 * @param name @en Resource name @zh 资源名字 - * @param size @en Size of the resource @zh 资源的大小 + * @param size @en Size of the resource in bytes @zh 资源的大小 * @param format @en Format of the resource @zh 资源的格式 */ virtual void updateStorageBuffer(const ccstd::string &name, uint32_t size, gfx::Format format) = 0; @@ -1458,7 +1702,15 @@ class Pipeline : public BasicPipeline { * @param movePairs @en Array of move source and target @zh 移动来源与目标的数组 */ virtual void addMovePass(const ccstd::vector &movePairs) = 0; + /** + * @experimental + * @engineInternal + */ virtual void addBuiltinGpuCullingPass(const scene::Camera *camera, const std::string &hzbName, const scene::Light *light) = 0; + /** + * @experimental + * @engineInternal + */ virtual void addBuiltinHzbGenerationPass(const std::string &sourceDepthStencilName, const std::string &targetHzbName) = 0; /** * @experimental @@ -1515,6 +1767,10 @@ class PipelineBuilder { * @param pipeline @en Current render pipeline @zh 当前管线 */ virtual void setup(const ccstd::vector &cameras, BasicPipeline *pipeline) = 0; + /** + * @en Callback of pipeline state changed + * @zh 渲染管线状态更新的回调 + */ virtual void onGlobalPipelineStateChanged() = 0; }; From fb8c7d6613a54691db0bef0f28f7e3c3e03e5cfd Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Mon, 11 Dec 2023 21:23:45 +0800 Subject: [PATCH 05/32] Modify uniform offset (#16588) --- cocos/rendering/custom/web-pipeline.ts | 786 ++++++++++--------------- 1 file changed, 305 insertions(+), 481 deletions(-) diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index 70166c75658..c6dc4d04f2a 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -66,7 +66,7 @@ const _uboVec3 = new Vec3(); const _uboCol = new Color(); const _matView = new Mat4(); const _mulMatView = new Mat4(); -let uniformOffset = -1; +const uniformOffset = -1; const _samplerPointInfo = new SamplerInfo( Filter.POINT, Filter.POINT, @@ -396,34 +396,27 @@ export class WebSetter implements Setter { const pipeline = (director.root as Root).pipeline; const sceneData = pipeline.pipelineSceneData; if (!this.addConstant('CCForwardLight', this.getParentLayout(), UpdateFrequency.PER_BATCH)) return; - uniformOffset = this.getUniformOffset('cc_lightPos', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.position.x, light.position.y, light.position.z, LightType.SPHERE); - this.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = this.getUniformOffset('cc_lightSizeRangeAngle', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.size, light.range, 0.0, 0.0); - this.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(light.position.x, light.position.y, light.position.z, LightType.SPHERE); + setUniformOffset(this, 'cc_lightPos', Type.FLOAT4, _uboVec); + + _uboVec.set(light.size, light.range, 0.0, 0.0); + setUniformOffset(this, 'cc_lightSizeRangeAngle', Type.FLOAT4, _uboVec); + const isHDR = sceneData.isHDR; const lightMeterScale = 10000.0; - uniformOffset = this.getUniformOffset('cc_lightColor', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.color.x, light.color.y, light.color.z, 0); - if (light.useColorTemperature) { - const finalColor = light.finalColor; - _uboVec.x = finalColor.x; - _uboVec.y = finalColor.y; - _uboVec.z = finalColor.z; - } - if (isHDR) { - _uboVec.w = (light).luminance * camera.exposure * lightMeterScale; - } else { - _uboVec.w = (light).luminance; - } - this.offsetVec4(_uboVec, uniformOffset); + _uboVec.set(light.color.x, light.color.y, light.color.z, 0); + if (light.useColorTemperature) { + const finalColor = light.finalColor; + _uboVec.x = finalColor.x; + _uboVec.y = finalColor.y; + _uboVec.z = finalColor.z; + } + if (isHDR) { + _uboVec.w = (light).luminance * camera.exposure * lightMeterScale; + } else { + _uboVec.w = (light).luminance; } + setUniformOffset(this, 'cc_lightColor', Type.FLOAT4, _uboVec); } public setBuiltinSpotLightConstants (light: SpotLight, camera: Camera): void { const director = cclegacy.director; @@ -432,117 +425,89 @@ export class WebSetter implements Setter { const shadowInfo = sceneData.shadows; if (!this.addConstant('CCForwardLight', this.getParentLayout(), UpdateFrequency.PER_BATCH)) return; - uniformOffset = this.getUniformOffset('cc_lightPos', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.position.x, light.position.y, light.position.z, LightType.SPOT); - this.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = this.getUniformOffset('cc_lightSizeRangeAngle', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.size, light.range, light.spotAngle, (shadowInfo.enabled && light.shadowEnabled && shadowInfo.type === ShadowType.ShadowMap) ? 1 : 0); - this.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = this.getUniformOffset('cc_lightDir', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.direction.x, light.direction.y, light.direction.z, 0); - this.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(light.position.x, light.position.y, light.position.z, LightType.SPOT); + setUniformOffset(this, 'cc_lightPos', Type.FLOAT4, _uboVec); + + _uboVec.set(light.size, light.range, light.spotAngle, (shadowInfo.enabled && light.shadowEnabled && shadowInfo.type === ShadowType.ShadowMap) ? 1 : 0); + setUniformOffset(this, 'cc_lightSizeRangeAngle', Type.FLOAT4, _uboVec); + + _uboVec.set(light.direction.x, light.direction.y, light.direction.z, 0); + setUniformOffset(this, 'cc_lightDir', Type.FLOAT4, _uboVec); + const isHDR = sceneData.isHDR; const lightMeterScale = 10000.0; - uniformOffset = this.getUniformOffset('cc_lightColor', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.color.x, light.color.y, light.color.z, 0); - if (light.useColorTemperature) { - const finalColor = light.finalColor; - _uboVec.x = finalColor.x; - _uboVec.y = finalColor.y; - _uboVec.z = finalColor.z; - } - if (isHDR) { - _uboVec.w = (light).luminance * camera.exposure * lightMeterScale; - } else { - _uboVec.w = (light).luminance; - } - this.offsetVec4(_uboVec, uniformOffset); + _uboVec.set(light.color.x, light.color.y, light.color.z, 0); + if (light.useColorTemperature) { + const finalColor = light.finalColor; + _uboVec.x = finalColor.x; + _uboVec.y = finalColor.y; + _uboVec.z = finalColor.z; + } + if (isHDR) { + _uboVec.w = (light).luminance * camera.exposure * lightMeterScale; + } else { + _uboVec.w = (light).luminance; } + setUniformOffset(this, 'cc_lightColor', Type.FLOAT4, _uboVec); } public setBuiltinPointLightConstants (light: PointLight, camera: Camera): void { const director = cclegacy.director; const pipeline = (director.root as Root).pipeline; const sceneData = pipeline.pipelineSceneData; if (!this.addConstant('CCForwardLight', this.getParentLayout(), UpdateFrequency.PER_BATCH)) return; - uniformOffset = this.getUniformOffset('cc_lightPos', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.position.x, light.position.y, light.position.z, LightType.POINT); - this.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = this.getUniformOffset('cc_lightSizeRangeAngle', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(0.0, light.range, 0.0, 0.0); - this.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(light.position.x, light.position.y, light.position.z, LightType.POINT); + setUniformOffset(this, 'cc_lightPos', Type.FLOAT4, _uboVec); + + _uboVec.set(0.0, light.range, 0.0, 0.0); + setUniformOffset(this, 'cc_lightSizeRangeAngle', Type.FLOAT4, _uboVec); const isHDR = sceneData.isHDR; const lightMeterScale = 10000.0; - uniformOffset = this.getUniformOffset('cc_lightColor', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.color.x, light.color.y, light.color.z, 0); - if (light.useColorTemperature) { - const finalColor = light.finalColor; - _uboVec.x = finalColor.x; - _uboVec.y = finalColor.y; - _uboVec.z = finalColor.z; - } - if (isHDR) { - _uboVec.w = (light).luminance * camera.exposure * lightMeterScale; - } else { - _uboVec.w = (light).luminance; - } - this.offsetVec4(_uboVec, uniformOffset); + if (light.useColorTemperature) { + const finalColor = light.finalColor; + _uboVec.x = finalColor.x; + _uboVec.y = finalColor.y; + _uboVec.z = finalColor.z; + } + if (isHDR) { + _uboVec.w = (light).luminance * camera.exposure * lightMeterScale; + } else { + _uboVec.w = (light).luminance; } + _uboVec.set(light.color.x, light.color.y, light.color.z, 0); + setUniformOffset(this, 'cc_lightColor', Type.FLOAT4, _uboVec); } public setBuiltinRangedDirectionalLightConstants (light: RangedDirectionalLight, camera: Camera): void { const director = cclegacy.director; const pipeline = (director.root as Root).pipeline; const sceneData = pipeline.pipelineSceneData; if (!this.addConstant('CCForwardLight', this.getParentLayout(), UpdateFrequency.PER_BATCH)) return; - uniformOffset = this.getUniformOffset('cc_lightPos', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.position.x, light.position.y, light.position.z, LightType.RANGED_DIRECTIONAL); - this.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = this.getUniformOffset('cc_lightSizeRangeAngle', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.right.x, light.right.y, light.right.z, 0.0); - this.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = this.getUniformOffset('cc_lightDir', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.direction.x, light.direction.y, light.direction.z, 0); - this.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = this.getUniformOffset('cc_lightBoundingSizeVS', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - const scale = light.scale; - _uboVec.set(scale.x * 0.5, scale.y * 0.5, scale.z * 0.5, 0); - this.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(light.position.x, light.position.y, light.position.z, LightType.RANGED_DIRECTIONAL); + setUniformOffset(this, 'cc_lightPos', Type.FLOAT4, _uboVec); + + _uboVec.set(light.right.x, light.right.y, light.right.z, 0.0); + setUniformOffset(this, 'cc_lightSizeRangeAngle', Type.FLOAT4, _uboVec); + + _uboVec.set(light.direction.x, light.direction.y, light.direction.z, 0); + setUniformOffset(this, 'cc_lightDir', Type.FLOAT4, _uboVec); + + const scale = light.scale; + _uboVec.set(scale.x * 0.5, scale.y * 0.5, scale.z * 0.5, 0); + setUniformOffset(this, 'cc_lightBoundingSizeVS', Type.FLOAT4, _uboVec); + const isHDR = sceneData.isHDR; - uniformOffset = this.getUniformOffset('cc_lightColor', Type.FLOAT4); - if (this.hasUniform(uniformOffset)) { - _uboVec.set(light.color.x, light.color.y, light.color.z, 0); - if (light.useColorTemperature) { - const finalColor = light.finalColor; - _uboVec.x = finalColor.x; - _uboVec.y = finalColor.y; - _uboVec.z = finalColor.z; - } - if (isHDR) { - _uboVec.w = light.illuminance * camera.exposure; - } else { - _uboVec.w = light.illuminance; - } - this.offsetVec4(_uboVec, uniformOffset); + _uboVec.set(light.color.x, light.color.y, light.color.z, 0); + if (light.useColorTemperature) { + const finalColor = light.finalColor; + _uboVec.x = finalColor.x; + _uboVec.y = finalColor.y; + _uboVec.z = finalColor.z; + } + if (isHDR) { + _uboVec.w = light.illuminance * camera.exposure; + } else { + _uboVec.w = light.illuminance; } + setUniformOffset(this, 'cc_lightColor', Type.FLOAT4, _uboVec); } public hasSampler (name: string): boolean { const id = this._lg.attributeIndex.get(name); @@ -573,6 +538,23 @@ export class WebSetter implements Setter { protected _currConstant: number[] = []; } +function setUniformOffset (setter: WebSetter, uniformName: string, uniformType: Type, value, idx = 0): void { + const uniformOffset = setter.getUniformOffset(uniformName, uniformType, idx); + if (setter.hasUniform(uniformOffset)) { + switch (uniformType) { + case Type.MAT4: + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + setter.offsetMat4(value, uniformOffset); + break; + case Type.FLOAT4: + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + setter.offsetVec4(value, uniformOffset); + break; + default: + } + } +} + function setShadowUBOLightView ( setter: WebSetter, camera: Camera | null, @@ -627,11 +609,8 @@ function setShadowUBOLightView ( far = csmLayers.specialLayer.shadowCameraFar; levelCount = 1; } - uniformOffset = setter.getUniformOffset('cc_shadowLPNNInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(LightType.DIRECTIONAL, packing, mainLight.shadowNormalBias, 0); - setter.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(LightType.DIRECTIONAL, packing, mainLight.shadowNormalBias, 0); + setUniformOffset(setter, 'cc_shadowLPNNInfo', Type.FLOAT4, _uboVec); } else { const layer = csmLayers.layers[csmLevel]; matShadowView = layer.matShadowView; @@ -642,39 +621,23 @@ function setShadowUBOLightView ( far = layer.splitCameraFar; levelCount = mainLight.csmLevel; } - uniformOffset = setter.getUniformOffset('cc_matLightView', Type.MAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetMat4(matShadowView, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowProjDepthInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowProj.m10, matShadowProj.m14, matShadowProj.m11, matShadowProj.m15); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowProjInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowProj.m00, matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_matLightViewProj', Type.MAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetMat4(matShadowViewProj, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowNFLSInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(near, far, 0, 1.0 - mainLight.shadowSaturation); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowLPNNInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(LightType.DIRECTIONAL, packing, mainLight.shadowNormalBias, levelCount); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowWHPBInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, mainLight.shadowPcf, mainLight.shadowBias); - setter.offsetVec4(_uboVec, uniformOffset); - } + setUniformOffset(setter, 'cc_matLightView', Type.MAT4, matShadowView); + _uboVec.set(matShadowProj.m10, matShadowProj.m14, matShadowProj.m11, matShadowProj.m15); + setUniformOffset(setter, 'cc_shadowProjDepthInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(matShadowProj.m00, matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05); + setUniformOffset(setter, 'cc_shadowProjInfo', Type.FLOAT4, _uboVec); + + setUniformOffset(setter, 'cc_matLightViewProj', Type.MAT4, matShadowViewProj); + + _uboVec.set(near, far, 0, 1.0 - mainLight.shadowSaturation); + setUniformOffset(setter, 'cc_shadowNFLSInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(LightType.DIRECTIONAL, packing, mainLight.shadowNormalBias, levelCount); + setUniformOffset(setter, 'cc_shadowLPNNInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, mainLight.shadowPcf, mainLight.shadowBias); + setUniformOffset(setter, 'cc_shadowWHPBInfo', Type.FLOAT4, _uboVec); } } break; @@ -682,97 +645,63 @@ function setShadowUBOLightView ( case LightType.SPOT: { const spotLight = light as SpotLight; if (shadowInfo.enabled && spotLight && spotLight.shadowEnabled) { - const matViewOffset = setter.getUniformOffset('cc_matLightView', Type.MAT4); - const matViewProOffset = setter.getUniformOffset('cc_matLightViewProj', Type.MAT4); - if (setter.hasUniform(matViewOffset) || setter.hasUniform(matViewProOffset)) { - Mat4.invert(_matView, spotLight.node!.getWorldMatrix()); - } - if (setter.hasUniform(matViewOffset)) setter.offsetMat4(_matView, matViewOffset); - let matShadowInvProj!: Mat4; - let matShadowProj!: Mat4; - if (setter.hasUniform(matViewProOffset)) { - Mat4.perspective( - _mulMatView, - spotLight.angle, - 1.0, - 0.001, - spotLight.range, - true, - cap.clipSpaceMinZ, - cap.clipSpaceSignY, - 0, - ); - matShadowProj = _mulMatView.clone(); - matShadowInvProj = _mulMatView.clone().invert(); - Mat4.multiply(_matView, _mulMatView, _matView); - setter.offsetMat4(_matView, matViewProOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowNFLSInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(0.01, (light as SpotLight).range, 0.0, 0.0); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowWHPBInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, spotLight.shadowPcf, spotLight.shadowBias); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowLPNNInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(LightType.SPOT, packing, spotLight.shadowNormalBias, 0.0); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowProjDepthInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowProj.m10, matShadowProj.m14, matShadowProj.m11, matShadowProj.m15); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowInvProjDepthInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowInvProj.m10, matShadowInvProj.m14, matShadowInvProj.m11, matShadowInvProj.m15); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowProjInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowProj.m00, matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05); - setter.offsetVec4(_uboVec, uniformOffset); - } + Mat4.invert(_matView, spotLight.node!.getWorldMatrix()); + setUniformOffset(setter, 'cc_matLightView', Type.MAT4, _matView); + Mat4.perspective( + _mulMatView, + spotLight.angle, + 1.0, + 0.001, + spotLight.range, + true, + cap.clipSpaceMinZ, + cap.clipSpaceSignY, + 0, + ); + const matShadowInvProj: Mat4 = _mulMatView.clone().invert(); + const matShadowProj: Mat4 = _mulMatView.clone(); + + Mat4.multiply(_matView, _mulMatView, _matView); + setUniformOffset(setter, 'cc_matLightViewProj', Type.MAT4, _matView); + + _uboVec.set(0.01, (light as SpotLight).range, 0.0, 0.0); + setUniformOffset(setter, 'cc_shadowNFLSInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, spotLight.shadowPcf, spotLight.shadowBias); + setUniformOffset(setter, 'cc_shadowWHPBInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(LightType.SPOT, packing, spotLight.shadowNormalBias, 0.0); + setUniformOffset(setter, 'cc_shadowLPNNInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(matShadowProj.m10, matShadowProj.m14, matShadowProj.m11, matShadowProj.m15); + setUniformOffset(setter, 'cc_shadowProjDepthInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(matShadowInvProj.m10, matShadowInvProj.m14, matShadowInvProj.m11, matShadowInvProj.m15); + setUniformOffset(setter, 'cc_shadowInvProjDepthInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(matShadowProj.m00, matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05); + setUniformOffset(setter, 'cc_shadowProjInfo', Type.FLOAT4, _uboVec); } break; } case LightType.SPHERE: { - uniformOffset = setter.getUniformOffset('cc_shadowWHPBInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, 1.0, 0.0); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowLPNNInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(LightType.SPHERE, packing, 0.0, 0.0); - setter.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, 1.0, 0.0); + setUniformOffset(setter, 'cc_shadowWHPBInfo', Type.FLOAT4, _uboVec); + _uboVec.set(LightType.SPHERE, packing, 0.0, 0.0); + setUniformOffset(setter, 'cc_shadowLPNNInfo', Type.FLOAT4, _uboVec); break; } case LightType.POINT: { - uniformOffset = setter.getUniformOffset('cc_shadowWHPBInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, 1.0, 0.0); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowLPNNInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(LightType.POINT, packing, 0.0, 0.0); - setter.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, 1.0, 0.0); + setUniformOffset(setter, 'cc_shadowWHPBInfo', Type.FLOAT4, _uboVec); + _uboVec.set(LightType.POINT, packing, 0.0, 0.0); + setUniformOffset(setter, 'cc_shadowLPNNInfo', Type.FLOAT4, _uboVec); break; } default: } - uniformOffset = setter.getUniformOffset('cc_shadowColor', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboCol.set(shadowInfo.shadowColor.x, shadowInfo.shadowColor.y, shadowInfo.shadowColor.z, shadowInfo.shadowColor.w); - setter.offsetColor(_uboCol, uniformOffset); - } + _uboCol.set(shadowInfo.shadowColor.x, shadowInfo.shadowColor.y, shadowInfo.shadowColor.z, shadowInfo.shadowColor.w); + setUniformOffset(setter, 'cc_shadowColor', Type.FLOAT4, _uboCol); } function getPCFRadius (shadowInfo: Shadows, mainLight: DirectionalLight): number { @@ -815,34 +744,21 @@ function setShadowUBOView (setter: WebSetter, camera: Camera | null, layout = 'd const matShadowViewProj: Mat4 = csmLayers.specialLayer.matShadowViewProj; const near: number = mainLight.shadowNear; const far: number = mainLight.shadowFar; - uniformOffset = setter.getUniformOffset('cc_matLightView', Type.MAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetMat4(matShadowView, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowProjDepthInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowProj.m10, matShadowProj.m14, matShadowProj.m11, matShadowProj.m15); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowProjInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowProj.m00, matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_matLightViewProj', Type.MAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetMat4(matShadowViewProj, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowNFLSInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(near, far, 0, 1.0 - mainLight.shadowSaturation); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowLPNNInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(LightType.DIRECTIONAL, packing, mainLight.shadowNormalBias, 0); - setter.offsetVec4(_uboVec, uniformOffset); - } + setUniformOffset(setter, 'cc_matLightView', Type.MAT4, matShadowView); + + _uboVec.set(matShadowProj.m10, matShadowProj.m14, matShadowProj.m11, matShadowProj.m15); + setUniformOffset(setter, 'cc_shadowProjDepthInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(matShadowProj.m00, matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05); + setUniformOffset(setter, 'cc_shadowProjInfo', Type.FLOAT4, _uboVec); + + setUniformOffset(setter, 'cc_matLightViewProj', Type.MAT4, matShadowViewProj); + + _uboVec.set(near, far, 0, 1.0 - mainLight.shadowSaturation); + setUniformOffset(setter, 'cc_shadowNFLSInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(LightType.DIRECTIONAL, packing, mainLight.shadowNormalBias, 0); + setUniformOffset(setter, 'cc_shadowLPNNInfo', Type.FLOAT4, _uboVec); } } else { if (hasCCCSM) { @@ -851,92 +767,58 @@ function setShadowUBOView (setter: WebSetter, camera: Camera | null, layout = 'd for (let i = 0; i < mainLight.csmLevel; i++) { const layer: CSMShadowLayer = csmLayers.layers[i]; const matShadowView: Mat4 = layer.matShadowView; - uniformOffset = setter.getUniformOffset('cc_csmViewDir0', Type.FLOAT4, i); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowView.m00, matShadowView.m04, matShadowView.m08, layerThreshold); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_csmViewDir1', Type.FLOAT4, i); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowView.m01, matShadowView.m05, matShadowView.m09, layer.splitCameraNear); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_csmViewDir2', Type.FLOAT4, i); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowView.m02, matShadowView.m06, matShadowView.m10, layer.splitCameraFar); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_csmAtlas', Type.FLOAT4, i); - if (setter.hasUniform(uniformOffset)) { - const csmAtlas = layer.csmAtlas; - setter.offsetVec4(csmAtlas, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_matCSMViewProj', Type.MAT4, i); - if (setter.hasUniform(uniformOffset)) { - const matShadowViewProj = layer.matShadowViewProj; - setter.offsetMat4(matShadowViewProj, uniformOffset); - } + _uboVec.set(matShadowView.m00, matShadowView.m04, matShadowView.m08, layerThreshold); + setUniformOffset(setter, 'cc_csmViewDir0', Type.FLOAT4, _uboVec, i); + + _uboVec.set(matShadowView.m01, matShadowView.m05, matShadowView.m09, layer.splitCameraNear); + setUniformOffset(setter, 'cc_csmViewDir1', Type.FLOAT4, _uboVec, i); + + _uboVec.set(matShadowView.m02, matShadowView.m06, matShadowView.m10, layer.splitCameraFar); + setUniformOffset(setter, 'cc_csmViewDir2', Type.FLOAT4, _uboVec, i); + + const csmAtlas = layer.csmAtlas; + setUniformOffset(setter, 'cc_csmAtlas', Type.FLOAT4, csmAtlas, i); + + const matShadowViewProj = layer.matShadowViewProj; + setUniformOffset(setter, 'cc_matCSMViewProj', Type.MAT4, matShadowViewProj, i); + const matShadowProj = layer.matShadowProj; - uniformOffset = setter.getUniformOffset('cc_csmProjDepthInfo', Type.FLOAT4, i); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowProj.m10, matShadowProj.m14, matShadowProj.m11, matShadowProj.m15); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_csmProjInfo', Type.FLOAT4, i); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(matShadowProj.m00, matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05); - setter.offsetVec4(_uboVec, uniformOffset); - } - } - uniformOffset = setter.getUniformOffset('cc_csmSplitsInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(mainLight.csmTransitionRange, 0, 0, 0); - setter.offsetVec4(_uboVec, uniformOffset); + _uboVec.set(matShadowProj.m10, matShadowProj.m14, matShadowProj.m11, matShadowProj.m15); + setUniformOffset(setter, 'cc_csmProjDepthInfo', Type.FLOAT4, _uboVec, i); + + _uboVec.set(matShadowProj.m00, matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05); + setUniformOffset(setter, 'cc_csmProjInfo', Type.FLOAT4, _uboVec, i); } + _uboVec.set(mainLight.csmTransitionRange, 0, 0, 0); + setUniformOffset(setter, 'cc_csmSplitsInfo', Type.FLOAT4, _uboVec); } if (hasCCShadow) { setter.setCurrConstant('CCShadow', layout); - uniformOffset = setter.getUniformOffset('cc_shadowNFLSInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(0, 0, 0, 1.0 - mainLight.shadowSaturation); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowLPNNInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(LightType.DIRECTIONAL, packing, mainLight.shadowNormalBias, mainLight.csmLevel); - setter.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(0, 0, 0, 1.0 - mainLight.shadowSaturation); + setUniformOffset(setter, 'cc_shadowNFLSInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(LightType.DIRECTIONAL, packing, mainLight.shadowNormalBias, mainLight.csmLevel); + setUniformOffset(setter, 'cc_shadowLPNNInfo', Type.FLOAT4, _uboVec); } } if (hasCCShadow) { setter.setCurrConstant('CCShadow', layout); - uniformOffset = setter.getUniformOffset('cc_shadowWHPBInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, mainLight.shadowPcf, mainLight.shadowBias); - setter.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(shadowInfo.size.x, shadowInfo.size.y, mainLight.shadowPcf, mainLight.shadowBias); + setUniformOffset(setter, 'cc_shadowWHPBInfo', Type.FLOAT4, _uboVec); } } } else if (hasCCShadow) { setter.setCurrConstant('CCShadow', layout); - uniformOffset = setter.getUniformOffset('cc_planarNDInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - Vec3.normalize(_uboVec3, shadowInfo.normal); - _uboVec.set(_uboVec3.x, _uboVec3.y, _uboVec3.z, -shadowInfo.distance); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_shadowWHPBInfo', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(0, 0, 0, shadowInfo.planeBias); - setter.offsetVec4(_uboVec, uniformOffset); - } + Vec3.normalize(_uboVec3, shadowInfo.normal); + _uboVec.set(_uboVec3.x, _uboVec3.y, _uboVec3.z, -shadowInfo.distance); + setUniformOffset(setter, 'cc_planarNDInfo', Type.FLOAT4, _uboVec); + + _uboVec.set(0, 0, 0, shadowInfo.planeBias); + setUniformOffset(setter, 'cc_shadowWHPBInfo', Type.FLOAT4, _uboVec); } if (hasCCShadow) { setter.setCurrConstant('CCShadow', layout); - uniformOffset = setter.getUniformOffset('cc_shadowColor', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetColor(shadowInfo.shadowColor, uniformOffset); - } + setUniformOffset(setter, 'cc_shadowColor', Type.FLOAT4, shadowInfo.shadowColor); } } } @@ -964,134 +846,87 @@ function setCameraUBOValues ( // Camera if (!setter.addConstant('CCCamera', layoutName)) return; if (camera) { - uniformOffset = setter.getUniformOffset('cc_matView', Type.MAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetMat4(camera.matView, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_matViewInv', Type.MAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetMat4(camera.node.worldMatrix, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_matProj', Type.MAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetMat4(camera.matProj, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_matProjInv', Type.MAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetMat4(camera.matProjInv, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_matViewProj', Type.MAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetMat4(camera.matViewProj, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_matViewProjInv', Type.MAT4); - if (setter.hasUniform(uniformOffset)) { - setter.offsetMat4(camera.matViewProjInv, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_surfaceTransform', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(camera.surfaceTransform, camera.cameraUsage, Math.cos(toRadian(skybox.getRotationAngle())), Math.sin(toRadian(skybox.getRotationAngle()))); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_exposure', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(camera.exposure, 1.0 / camera.exposure, cfg.isHDR ? 1.0 : 0.0, 1.0 / Camera.standardExposureValue); - setter.offsetVec4(_uboVec, uniformOffset); - } - } - uniformOffset = setter.getUniformOffset('cc_cameraPos', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - if (camera) { _uboVec.set(camera.position.x, camera.position.y, camera.position.z, pipeline.getCombineSignY()); } else { _uboVec.set(0, 0, 0, pipeline.getCombineSignY()); } - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_screenScale', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(cfg.shadingScale, cfg.shadingScale, 1.0 / cfg.shadingScale, 1.0 / cfg.shadingScale); - setter.offsetVec4(_uboVec, uniformOffset); + setUniformOffset(setter, 'cc_matView', Type.MAT4, camera.matView); + + setUniformOffset(setter, 'cc_matViewInv', Type.MAT4, camera.node.worldMatrix); + + setUniformOffset(setter, 'cc_matProj', Type.MAT4, camera.matProj); + + setUniformOffset(setter, 'cc_matProjInv', Type.MAT4, camera.matProjInv); + + setUniformOffset(setter, 'cc_matViewProj', Type.MAT4, camera.matViewProj); + + setUniformOffset(setter, 'cc_matViewProjInv', Type.MAT4, camera.matViewProjInv); + + _uboVec.set(camera.surfaceTransform, camera.cameraUsage, Math.cos(toRadian(skybox.getRotationAngle())), Math.sin(toRadian(skybox.getRotationAngle()))); + setUniformOffset(setter, 'cc_surfaceTransform', Type.FLOAT4, _uboVec); + + _uboVec.set(camera.exposure, 1.0 / camera.exposure, cfg.isHDR ? 1.0 : 0.0, 1.0 / Camera.standardExposureValue); + setUniformOffset(setter, 'cc_exposure', Type.FLOAT4, _uboVec); } + if (camera) { _uboVec.set(camera.position.x, camera.position.y, camera.position.z, pipeline.getCombineSignY()); } else { _uboVec.set(0, 0, 0, pipeline.getCombineSignY()); } + setUniformOffset(setter, 'cc_cameraPos', Type.FLOAT4, _uboVec); + + _uboVec.set(cfg.shadingScale, cfg.shadingScale, 1.0 / cfg.shadingScale, 1.0 / cfg.shadingScale); + setUniformOffset(setter, 'cc_screenScale', Type.FLOAT4, _uboVec); + const mainLight = scene && scene.mainLight; if (mainLight) { - uniformOffset = setter.getUniformOffset('cc_mainLitDir', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - const shadowEnable = (mainLight.shadowEnabled && shadowInfo.type === ShadowType.ShadowMap) ? 1.0 : 0.0; - _uboVec.set(mainLight.direction.x, mainLight.direction.y, mainLight.direction.z, shadowEnable); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_mainLitColor', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - let r = mainLight.color.x; - let g = mainLight.color.y; - let b = mainLight.color.z; - if (mainLight.useColorTemperature) { - r *= mainLight.colorTemperatureRGB.x; - g *= mainLight.colorTemperatureRGB.y; - b *= mainLight.colorTemperatureRGB.z; - } - let w = mainLight.illuminance; - if (cfg.isHDR && camera) { - w *= camera.exposure; - } - _uboVec.set(r, g, b, w); - setter.offsetVec4(_uboVec, uniformOffset); - } + const shadowEnable = (mainLight.shadowEnabled && shadowInfo.type === ShadowType.ShadowMap) ? 1.0 : 0.0; + _uboVec.set(mainLight.direction.x, mainLight.direction.y, mainLight.direction.z, shadowEnable); + setUniformOffset(setter, 'cc_mainLitDir', Type.FLOAT4, _uboVec); + + let r = mainLight.color.x; + let g = mainLight.color.y; + let b = mainLight.color.z; + if (mainLight.useColorTemperature) { + r *= mainLight.colorTemperatureRGB.x; + g *= mainLight.colorTemperatureRGB.y; + b *= mainLight.colorTemperatureRGB.z; + } + let w = mainLight.illuminance; + if (cfg.isHDR && camera) { + w *= camera.exposure; + } + _uboVec.set(r, g, b, w); + setUniformOffset(setter, 'cc_mainLitColor', Type.FLOAT4, _uboVec); } else { - uniformOffset = setter.getUniformOffset('cc_mainLitDir', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(0, 0, 1, 0); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_mainLitColor', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(0, 0, 0, 0); - setter.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(0, 0, 1, 0); + setUniformOffset(setter, 'cc_mainLitDir', Type.FLOAT4, _uboVec); + + _uboVec.set(0, 0, 0, 0); + setUniformOffset(setter, 'cc_mainLitColor', Type.FLOAT4, _uboVec); } const ambient = cfg.ambient; - uniformOffset = setter.getUniformOffset('cc_ambientSky', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - const skyColor = ambient.skyColor; - if (cfg.isHDR) { - skyColor.w = ambient.skyIllum * (camera ? camera.exposure : 1); - } else { - skyColor.w = ambient.skyIllum; - } - _uboVec.set(skyColor.x, skyColor.y, skyColor.z, skyColor.w); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_ambientGround', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(ambient.groundAlbedo.x, ambient.groundAlbedo.y, ambient.groundAlbedo.z, skybox.envmap ? skybox.envmap?.mipmapLevel : 1.0); - setter.offsetVec4(_uboVec, uniformOffset); + const skyColor = ambient.skyColor; + if (cfg.isHDR) { + skyColor.w = ambient.skyIllum * (camera ? camera.exposure : 1); + } else { + skyColor.w = ambient.skyIllum; } + _uboVec.set(skyColor.x, skyColor.y, skyColor.z, skyColor.w); + setUniformOffset(setter, 'cc_ambientSky', Type.FLOAT4, _uboVec); + + _uboVec.set(ambient.groundAlbedo.x, ambient.groundAlbedo.y, ambient.groundAlbedo.z, skybox.envmap ? skybox.envmap?.mipmapLevel : 1.0); + setUniformOffset(setter, 'cc_ambientGround', Type.FLOAT4, _uboVec); + const fog = cfg.fog; - uniformOffset = setter.getUniformOffset('cc_fogColor', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - const colorTempRGB = fog.colorArray; - _uboVec.set(colorTempRGB.x, colorTempRGB.y, colorTempRGB.z, colorTempRGB.z); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_fogBase', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(fog.fogStart, fog.fogEnd, fog.fogDensity, 0.0); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_fogAdd', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(fog.fogTop, fog.fogRange, fog.fogAtten, 0.0); - setter.offsetVec4(_uboVec, uniformOffset); - } + const colorTempRGB = fog.colorArray; + _uboVec.set(colorTempRGB.x, colorTempRGB.y, colorTempRGB.z, colorTempRGB.z); + setUniformOffset(setter, 'cc_fogColor', Type.FLOAT4, _uboVec); + + _uboVec.set(fog.fogStart, fog.fogEnd, fog.fogDensity, 0.0); + setUniformOffset(setter, 'cc_fogBase', Type.FLOAT4, _uboVec); + + _uboVec.set(fog.fogTop, fog.fogRange, fog.fogAtten, 0.0); + setUniformOffset(setter, 'cc_fogAdd', Type.FLOAT4, _uboVec); if (camera) { - uniformOffset = setter.getUniformOffset('cc_nearFar', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(camera.nearClip, camera.farClip, camera.getClipSpaceMinz(), 0.0); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_viewPort', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(camera.viewport.x, camera.viewport.y, shadingScale * camera.window.width * camera.viewport.z, shadingScale * camera.window.height * camera.viewport.w); - setter.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(camera.nearClip, camera.farClip, camera.getClipSpaceMinz(), 0.0); + setUniformOffset(setter, 'cc_nearFar', Type.FLOAT4, _uboVec); + + _uboVec.set(camera.viewport.x, camera.viewport.y, shadingScale * camera.window.width * camera.viewport.z, shadingScale * camera.window.height * camera.viewport.w); + setUniformOffset(setter, 'cc_viewPort', Type.FLOAT4, _uboVec); } } @@ -2645,40 +2480,29 @@ export class WebPipeline implements BasicPipeline { const layoutGraph = pipeline.layoutGraph; // Global if (!setter.addConstant('CCGlobal', layoutName)) return; - uniformOffset = setter.getUniformOffset('cc_time', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(root.cumulativeTime, root.frameTime, director.getTotalFrames()); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_screenSize', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(shadingWidth, shadingHeight, 1.0 / shadingWidth, 1.0 / shadingHeight); - setter.offsetVec4(_uboVec, uniformOffset); - } - uniformOffset = setter.getUniformOffset('cc_nativeSize', Type.FLOAT4); - if (setter.hasUniform(uniformOffset)) { - _uboVec.set(shadingWidth, shadingHeight, 1.0 / shadingWidth, 1.0 / shadingHeight); - setter.offsetVec4(_uboVec, uniformOffset); - } + _uboVec.set(root.cumulativeTime, root.frameTime, director.getTotalFrames()); + setUniformOffset(setter, 'cc_time', Type.FLOAT4, _uboVec); + + _uboVec.set(shadingWidth, shadingHeight, 1.0 / shadingWidth, 1.0 / shadingHeight); + setUniformOffset(setter, 'cc_screenSize', Type.FLOAT4, _uboVec); + + _uboVec.set(shadingWidth, shadingHeight, 1.0 / shadingWidth, 1.0 / shadingHeight); + setUniformOffset(setter, 'cc_nativeSize', Type.FLOAT4, _uboVec); + const debugView = root.debugView; - uniformOffset = setter.getUniformOffset('cc_debug_view_mode', Type.FLOAT4); + _uboVec.set(0.0, 0.0, 0.0, 0.0); if (debugView) { - if (setter.hasUniform(uniformOffset)) { - const debugPackVec: number[] = [debugView.singleMode as number, 0.0, 0.0, 0.0]; - for (let i = DebugViewCompositeType.DIRECT_DIFFUSE as number; i < (DebugViewCompositeType.MAX_BIT_COUNT as number); i++) { - const idx = i >> 3; - const bit = i % 8; - debugPackVec[idx + 1] += (debugView.isCompositeModeEnabled(i) ? 1.0 : 0.0) * (10.0 ** bit); - } - debugPackVec[3] += (debugView.lightingWithAlbedo ? 1.0 : 0.0) * (10.0 ** 6.0); - debugPackVec[3] += (debugView.csmLayerColoration ? 1.0 : 0.0) * (10.0 ** 7.0); - _uboVec.set(debugPackVec[0], debugPackVec[1], debugPackVec[2], debugPackVec[3]); - setter.offsetVec4(_uboVec, uniformOffset); + const debugPackVec: number[] = [debugView.singleMode as number, 0.0, 0.0, 0.0]; + for (let i = DebugViewCompositeType.DIRECT_DIFFUSE as number; i < (DebugViewCompositeType.MAX_BIT_COUNT as number); i++) { + const idx = i >> 3; + const bit = i % 8; + debugPackVec[idx + 1] += (debugView.isCompositeModeEnabled(i) ? 1.0 : 0.0) * (10.0 ** bit); } - } else if (setter.hasUniform(uniformOffset)) { - _uboVec.set(0.0, 0.0, 0.0, 0.0); - setter.offsetVec4(_uboVec, uniformOffset); + debugPackVec[3] += (debugView.lightingWithAlbedo ? 1.0 : 0.0) * (10.0 ** 6.0); + debugPackVec[3] += (debugView.csmLayerColoration ? 1.0 : 0.0) * (10.0 ** 7.0); + _uboVec.set(debugPackVec[0], debugPackVec[1], debugPackVec[2], debugPackVec[3]); } + setUniformOffset(setter, 'cc_debug_view_mode', Type.FLOAT4, _uboVec); } public static MAX_BLOOM_FILTER_PASS_NUM = 6; From 1bdd90b5d384a90c05fb2b2b5e29f486158b56d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AA=9B=E5=AA=9B?= Date: Wed, 13 Dec 2023 09:31:06 +0800 Subject: [PATCH 06/32] fix compressZip in invaild in native platform (#16596) --- scripts/native-pack-tool/source/base/default.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/native-pack-tool/source/base/default.ts b/scripts/native-pack-tool/source/base/default.ts index b7e5a994980..5f65bd80cc1 100644 --- a/scripts/native-pack-tool/source/base/default.ts +++ b/scripts/native-pack-tool/source/base/default.ts @@ -615,6 +615,7 @@ export class CocosParams { this.buildDir = params.buildDir; this.xxteaKey = params.xxteaKey; this.encrypted = params.encrypted; + this.compressZip = params.compressZip; this.executableName = params.executableName; Object.assign(this.cMakeConfig, params.cMakeConfig); this.platformParams = params.platformParams; From 91dd0c76a0779ff00bbe6060f8fd39e116f8b203 Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Wed, 13 Dec 2023 16:54:46 +0800 Subject: [PATCH 07/32] Fix errors caused by reusing previously freed objects(skeletonInfo.skeleton) (#16605) --- cocos/spine/skeleton.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index d4b1ad8ffd5..8d8f0ec05ae 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -353,6 +353,9 @@ export class Skeleton extends UIRenderer { set skeletonData (value: SkeletonData | null) { if (value) value.resetEnums(); if (this._skeletonData !== value) { + if (this._skeletonCache && this._skeletonData) { + this._skeletonCache.removeSkeleton(this._skeletonData.uuid); + } this.destroyRenderData(); this._skeletonData = value as any; this.defaultSkin = ''; @@ -712,6 +715,9 @@ export class Skeleton extends UIRenderer { if (!JSB) { spine.SkeletonSystem.destroySpineInstance(this._instance); } + if (this._skeletonCache && this._skeletonData) { + this._skeletonCache.removeSkeleton(this._skeletonData.uuid); + } super.onDestroy(); } /** From c44eb3d89c0be39513a5f62f5127f76ef71d1932 Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Wed, 13 Dec 2023 16:55:45 +0800 Subject: [PATCH 08/32] Fix setAnimation can not work normally at cache mode while animation's name different with default. (#16603) --- cocos/spine/skeleton.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 8d8f0ec05ae..6821f129b73 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -897,6 +897,7 @@ export class Skeleton extends UIRenderer { let cache = this._skeletonCache.getAnimationCache(this._skeletonData!.uuid, name); if (!cache) { cache = this._skeletonCache.initAnimationCache(this.skeletonData!.uuid, this._skeletonData!, name); + cache?.setSkin(this._skinName); } if (cache) { this._animationName = name; @@ -996,6 +997,7 @@ export class Skeleton extends UIRenderer { this._animCache.setSkin(name); } } + this._skinName = name; this.invalidAnimationCache(); } From 5ce7637757bbedc16b60feca6d1512673d39c8d2 Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Fri, 15 Dec 2023 09:47:08 +0800 Subject: [PATCH 09/32] Fix instanced buffer memory leak problem (#16609) --- cocos/rendering/custom/web-pipeline-types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/cocos/rendering/custom/web-pipeline-types.ts b/cocos/rendering/custom/web-pipeline-types.ts index 28024fe8e46..7aeb016db11 100644 --- a/cocos/rendering/custom/web-pipeline-types.ts +++ b/cocos/rendering/custom/web-pipeline-types.ts @@ -255,7 +255,6 @@ export class RenderInstancingQueue { instanceBuffers.forEach((instance) => { instance.clear(); }); - this.instanceBuffers.length = 0; } sort (): void { From 10351809a1b59092bd70907fcbce481d771a1af1 Mon Sep 17 00:00:00 2001 From: dream93 Date: Fri, 15 Dec 2023 16:04:50 +0800 Subject: [PATCH 10/32] Update MiddlewareManager.cpp (#16597) fix spine crash --- native/cocos/editor-support/MiddlewareManager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/native/cocos/editor-support/MiddlewareManager.cpp b/native/cocos/editor-support/MiddlewareManager.cpp index cad1376e50e..56b205d0434 100644 --- a/native/cocos/editor-support/MiddlewareManager.cpp +++ b/native/cocos/editor-support/MiddlewareManager.cpp @@ -78,10 +78,14 @@ void MiddlewareManager::update(float dt) { if (!_removeList.empty()) { auto removeIt = std::find(_removeList.begin(), _removeList.end(), editor); if (removeIt == _removeList.end()) { - editor->update(dt); + if (editor) { + editor->update(dt); + } } } else { - editor->update(dt); + if (editor) { + editor->update(dt); + } } } From 7eb06c9da7787b01c65ce7a0ab87071284681549 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 15 Dec 2023 16:06:15 +0800 Subject: [PATCH 11/32] Fix cc.assetManager.downloader.maxConcurrency is overrode by mistake on mini-game platforms. (#16565) --- platforms/minigame/common/engine/index.js | 1 - platforms/minigame/common/engine/misc.js | 1 - 2 files changed, 2 deletions(-) delete mode 100644 platforms/minigame/common/engine/misc.js diff --git a/platforms/minigame/common/engine/index.js b/platforms/minigame/common/engine/index.js index be4737515a6..36c1cbb1c82 100644 --- a/platforms/minigame/common/engine/index.js +++ b/platforms/minigame/common/engine/index.js @@ -1,3 +1,2 @@ require('./Editbox'); require('./AssetManager'); -require('./misc'); diff --git a/platforms/minigame/common/engine/misc.js b/platforms/minigame/common/engine/misc.js deleted file mode 100644 index 15843d4e6f0..00000000000 --- a/platforms/minigame/common/engine/misc.js +++ /dev/null @@ -1 +0,0 @@ -cc.macro.DOWNLOAD_MAX_CONCURRENT = 10; \ No newline at end of file From c2e1abe49c20e70e0c1b222c9e9afff95e3881bb Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Mon, 18 Dec 2023 10:00:30 +0800 Subject: [PATCH 12/32] Refine: make multi skeleton component shared one instance of spine.Skeleton while spine working at sharedCache mode (#16593) * Refine: make multi skeleton component shared one instance of spine.Skeleton while spine working at sharedCache mode --- cocos/spine/lib/spine-core.d.ts | 1 + cocos/spine/skeleton-cache.ts | 89 ++++++++++++++----- cocos/spine/skeleton.ts | 38 +++++--- .../spine-wasm/spine-type-export.cpp | 1 + .../editor-support/spine-wasm/spine-wasm.cpp | 6 ++ .../editor-support/spine-wasm/spine-wasm.h | 1 + native/external-config.json | 2 +- 7 files changed, 102 insertions(+), 36 deletions(-) diff --git a/cocos/spine/lib/spine-core.d.ts b/cocos/spine/lib/spine-core.d.ts index 9fdecf2ed5b..8211706e3be 100644 --- a/cocos/spine/lib/spine-core.d.ts +++ b/cocos/spine/lib/spine-core.d.ts @@ -1220,6 +1220,7 @@ declare namespace spine { static createSpineSkeletonDataWithBinary(byteSize: number, atlasText: string): SkeletonData; static registerSpineSkeletonDataWithUUID(data: SkeletonData, uuid: string); static destroySpineSkeletonDataWithUUID(uuid: string); + static destroySpineSkeleton(skeleton: Skeleton): void; static getCurrentListenerID(): number; static getCurrentEventType(): EventType; static getCurrentTrackEntry(): TrackEntry; diff --git a/cocos/spine/skeleton-cache.ts b/cocos/spine/skeleton-cache.ts index c39e8d76f83..9d71d88fb98 100644 --- a/cocos/spine/skeleton-cache.ts +++ b/cocos/spine/skeleton-cache.ts @@ -28,6 +28,7 @@ import { SPINE_WASM } from './lib/instantiated'; import spine from './lib/spine-core.js'; import { SkeletonData } from './skeleton-data'; import { warn } from '../core/platform/debug'; +import { Skeleton } from './skeleton'; const MaxCacheTime = 30; const FrameTime = 1 / 60; @@ -52,6 +53,7 @@ export interface SkeletonCacheItemInfo { listener: TrackEntryListeners; curAnimationCache: AnimationCache | null; animationsCache: { [key: string]: AnimationCache }; + assetUUID: string; } class SpineModel { @@ -310,7 +312,11 @@ class SkeletonCache { protected _privateMode: boolean; protected _skeletonCache: { [key: string]: SkeletonCacheItemInfo }; + + //for shared mode only protected _animationPool: { [key: string]: AnimationCache }; + //for shared mode only, key is asset uuid and value is ref count. + private _sharedCacheMap: Map = new Map(); constructor () { this._privateMode = false; this._animationPool = {}; @@ -338,8 +344,28 @@ class SkeletonCache { } } - public removeSkeleton (uuid: string): void { - const skeletonInfo = this._skeletonCache[uuid]; + public destroySkeleton (assetUuid: string): void { + if (!this._privateMode) { + let refCount = this._sharedCacheMap.get(assetUuid); + if (refCount) { + refCount -= 1; + if (refCount > 0) { + return; + } + this._sharedCacheMap.delete(assetUuid); + } + } + + const sharedOperate = (aniKey: string, animationCache: AnimationCache): void => { + this._animationPool[`${assetUuid}#${aniKey}`] = animationCache; + animationCache.clear(); + }; + const privateOperate = (aniKey: string, animationCache: AnimationCache): void => { + animationCache.destroy(); + }; + const operate = this._privateMode ? privateOperate : sharedOperate; + + const skeletonInfo = this._skeletonCache[assetUuid]; if (!skeletonInfo) return; const animationsCache = skeletonInfo.animationsCache; for (const aniKey in animationsCache) { @@ -347,35 +373,52 @@ class SkeletonCache { // No need to create TypedArray next time. const animationCache = animationsCache[aniKey]; if (!animationCache) continue; - this._animationPool[`${uuid}#${aniKey}`] = animationCache; - animationCache.clear(); + operate(aniKey, animationCache); } - delete this._skeletonCache[uuid]; + if (skeletonInfo.skeleton) { + spine.wasmUtil.destroySpineSkeleton(skeletonInfo.skeleton); + } + delete this._skeletonCache[assetUuid]; } - public getSkeletonCache (uuid: string, skeletonData: spine.SkeletonData): SkeletonCacheItemInfo { - let skeletonInfo = this._skeletonCache[uuid]; - if (!skeletonInfo) { - const skeleton = null; - const clipper = null; - const state = null; - const listener = new TrackEntryListeners(); - - this._skeletonCache[uuid] = skeletonInfo = { - skeleton, - clipper, - state, - listener, - // Cache all kinds of animation frame. - // When skeleton is dispose, clear all animation cache. - animationsCache: {} as any, - curAnimationCache: null, - }; + public createSkeletonInfo (skeletonAsset: SkeletonData): SkeletonCacheItemInfo { + const uuid = skeletonAsset.uuid; + const runtimeData = skeletonAsset.getRuntimeData(); + if (!this._privateMode) { + let refCount = this._sharedCacheMap.get(uuid); + if (!refCount) { + refCount = 1; + } else { + refCount += 1; + } + this._sharedCacheMap.set(uuid, refCount); } + + const skeleton = new spine.Skeleton(runtimeData!); + const clipper = null; + const state = null; + const listener = new TrackEntryListeners(); + + const skeletonInfo = this._skeletonCache[uuid] = { + skeleton, + clipper, + state, + listener, + // Cache all kinds of animation frame. + // When skeleton is dispose, clear all animation cache. + animationsCache: {} as any, + curAnimationCache: null, + assetUUID: uuid, + }; return skeletonInfo; } + public getSkeletonInfo (skeletonAsset: SkeletonData): null | SkeletonCacheItemInfo { + const uuid = skeletonAsset.uuid; + return this._skeletonCache[uuid]; + } + public getAnimationCache (uuid: string, animationName: string): null | AnimationCache { const skeletonInfo = this._skeletonCache[uuid]; if (!skeletonInfo) return null; diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 6821f129b73..64b270e14ab 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -41,7 +41,7 @@ import { AttachUtil } from './attach-util'; import { SPINE_WASM } from './lib/instantiated'; import spine from './lib/spine-core.js'; import { VertexEffectDelegate } from './vertex-effect-delegate'; -import SkeletonCache, { AnimationCache, AnimationFrame } from './skeleton-cache'; +import SkeletonCache, { AnimationCache, AnimationFrame, SkeletonCacheItemInfo } from './skeleton-cache'; import { TrackEntryListeners } from './track-entry-listeners'; import { setPropertyEnumType } from '../core/internal-index'; @@ -240,6 +240,7 @@ export class Skeleton extends UIRenderer { protected _instance: spine.SkeletonInstance = null!; protected _state: spine.AnimationState = null!; protected _textures: Texture2D[] = []; + private _skeletonInfo: SkeletonCacheItemInfo | null = null; // Animation name protected _animationName = ''; protected _skinName = ''; @@ -353,9 +354,6 @@ export class Skeleton extends UIRenderer { set skeletonData (value: SkeletonData | null) { if (value) value.resetEnums(); if (this._skeletonData !== value) { - if (this._skeletonCache && this._skeletonData) { - this._skeletonCache.removeSkeleton(this._skeletonData.uuid); - } this.destroyRenderData(); this._skeletonData = value as any; this.defaultSkin = ''; @@ -715,11 +713,11 @@ export class Skeleton extends UIRenderer { if (!JSB) { spine.SkeletonSystem.destroySpineInstance(this._instance); } - if (this._skeletonCache && this._skeletonData) { - this._skeletonCache.removeSkeleton(this._skeletonData.uuid); - } + this._destroySkeletonInfo(this._skeletonCache); + this._skeletonCache = null; super.onDestroy(); } + /** * @en Clear animation and set to setup pose. * @zh 清除动画并还原到初始姿势。 @@ -777,23 +775,32 @@ export class Skeleton extends UIRenderer { */ public setSkeletonData (skeletonData: spine.SkeletonData): void { if (!EDITOR_NOT_IN_PREVIEW) { + const preSkeletonCache = this._skeletonCache; if (this._cacheMode === AnimationCacheMode.SHARED_CACHE) { this._skeletonCache = SkeletonCache.sharedCache; } else if (this._cacheMode === AnimationCacheMode.PRIVATE_CACHE) { this._skeletonCache = new SkeletonCache(); this._skeletonCache.enablePrivateMode(); + } else { + this._skeletonCache = null; + } + //cache mode may be changed + if (preSkeletonCache !== this._skeletonCache) { + this._destroySkeletonInfo(preSkeletonCache); } } if (this.isAnimationCached()) { if (this.debugBones || this.debugSlots) { warn('Debug bones or slots is invalid in cached mode'); } - if (this.skeletonData) { - const skeletonInfo = this._skeletonCache!.getSkeletonCache(this.skeletonData.uuid, skeletonData); - if (!skeletonInfo.skeleton) { - skeletonInfo.skeleton = this._instance.initSkeleton(skeletonData); + let skeletonInfo = this._skeletonCache!.getSkeletonInfo(this._skeletonData!); + if (this._skeletonInfo !== skeletonInfo) { + this._destroySkeletonInfo(this._skeletonCache); + if (!skeletonInfo) { + skeletonInfo = this._skeletonCache!.createSkeletonInfo(this._skeletonData!); } - this._skeleton = skeletonInfo.skeleton!; + this._skeletonInfo = skeletonInfo; + this._skeleton = this._skeletonInfo.skeleton!; } } else { this._skeleton = this._instance.initSkeleton(skeletonData); @@ -1848,6 +1855,13 @@ export class Skeleton extends UIRenderer { } this._instance.setSlotTexture(slotName, textureID); } + + private _destroySkeletonInfo (skeletonCache: SkeletonCache | null): void { + if (skeletonCache && this._skeletonInfo) { + skeletonCache.destroySkeleton(this._skeletonInfo.assetUUID); + this._skeletonInfo = null; + } + } } legacyCC.internal.SpineSkeleton = Skeleton; diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 7fbb4e71557..83133336b98 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -1626,6 +1626,7 @@ EMSCRIPTEN_BINDINGS(cocos_spine) { .class_function("createSpineSkeletonDataWithBinary", &SpineWasmUtil::createSpineSkeletonDataWithBinary, allow_raw_pointers()) .class_function("registerSpineSkeletonDataWithUUID", &SpineWasmUtil::registerSpineSkeletonDataWithUUID, allow_raw_pointers()) .class_function("destroySpineSkeletonDataWithUUID", &SpineWasmUtil::destroySpineSkeletonDataWithUUID) + .class_function("destroySpineSkeleton", &SpineWasmUtil::destroySpineSkeleton, allow_raw_pointers()) .class_function("getCurrentListenerID", &SpineWasmUtil::getCurrentListenerID) .class_function("getCurrentEventType", &SpineWasmUtil::getCurrentEventType) .class_function("getCurrentTrackEntry", &SpineWasmUtil::getCurrentTrackEntry, allow_raw_pointers()) diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp index ec59ef8b939..4fa26f2004b 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.cpp @@ -82,6 +82,12 @@ void SpineWasmUtil::destroySpineSkeletonDataWithUUID(const std::string& uuid) { } } +void SpineWasmUtil::destroySpineSkeleton(Skeleton* skeleton) { + if (skeleton) { + delete skeleton; + } +} + uint32_t SpineWasmUtil::queryStoreMemory(uint32_t size) { if (s_mem) { if (s_memSize < size) { diff --git a/native/cocos/editor-support/spine-wasm/spine-wasm.h b/native/cocos/editor-support/spine-wasm/spine-wasm.h index e1e0cb6fb66..993e2c97eca 100644 --- a/native/cocos/editor-support/spine-wasm/spine-wasm.h +++ b/native/cocos/editor-support/spine-wasm/spine-wasm.h @@ -18,6 +18,7 @@ class SpineWasmUtil { static SkeletonData* createSpineSkeletonDataWithBinary(uint32_t byteSize, const std::string& altasStr); static void registerSpineSkeletonDataWithUUID(SkeletonData* data, const std::string& uuid); static void destroySpineSkeletonDataWithUUID(const std::string& uuid); + static void destroySpineSkeleton(Skeleton* skeleton); static uint32_t getCurrentListenerID(); static EventType getCurrentEventType(); diff --git a/native/external-config.json b/native/external-config.json index 2531b1bbc80..89a1e20ef94 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-21" + "checkout": "v3.8.2-22" } } \ No newline at end of file From 19c19c595d5dae5010b9fc1ca2f14b48ebc0248b Mon Sep 17 00:00:00 2001 From: Y-way Date: Mon, 18 Dec 2023 11:49:02 +0800 Subject: [PATCH 13/32] Fix building error for simulator. (#16612) * Update .cocos-project.json * Fix build error --- native/tools/simulator/.cocos-project.json | 6 +++--- .../frameworks/runtime-src/proj.win32/SimulatorApp.cpp | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/native/tools/simulator/.cocos-project.json b/native/tools/simulator/.cocos-project.json index 6e3b5582281..582f37c3e19 100755 --- a/native/tools/simulator/.cocos-project.json +++ b/native/tools/simulator/.cocos-project.json @@ -1,4 +1,4 @@ { - "has_native": true, - "project_type": "lua" -} \ No newline at end of file + "has_native": true, + "project_type": "js" +} diff --git a/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorApp.cpp b/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorApp.cpp index eabdca3f084..a8c07c91a6d 100644 --- a/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorApp.cpp +++ b/native/tools/simulator/frameworks/runtime-src/proj.win32/SimulatorApp.cpp @@ -343,6 +343,7 @@ int SimulatorApp::init() { } _project.setFrameScale(frameScale); CC_LOG_DEBUG("FRAME SCALE = %0.2f", frameScale); + return 0; } int SimulatorApp::run() { From da9fc3f24b05d792f66082a161705ccee030eeb4 Mon Sep 17 00:00:00 2001 From: Knox Date: Tue, 19 Dec 2023 09:55:33 +0800 Subject: [PATCH 14/32] Fix baking data being emptied when switching scenes (#16613) Fixed that when switching scenes, re-adding the light probe group component will empty the baking data. --- cocos/gi/light-probe/light-probe.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cocos/gi/light-probe/light-probe.ts b/cocos/gi/light-probe/light-probe.ts index 585f2408a7b..8578b10249c 100644 --- a/cocos/gi/light-probe/light-probe.ts +++ b/cocos/gi/light-probe/light-probe.ts @@ -66,11 +66,16 @@ export class LightProbesData { } public updateProbes (points: Vec3[]): void { - this._probes.length = 0; + this._probes.length = points.length; - const pointCount = points.length; + const pointCount = this._probes.length; for (let i = 0; i < pointCount; i++) { - this._probes.push(new Vertex(points[i])); + let probe = this._probes[i]; + if (!probe) { + probe = new Vertex(points[i]); + } else { + probe.position.set(points[i]); + } } } From a5d091cb5706f5632def372a433b8c8b9b96920b Mon Sep 17 00:00:00 2001 From: qiuguohua Date: Tue, 19 Dec 2023 09:56:33 +0800 Subject: [PATCH 15/32] Fixed an issue where fntConfig may be null and report an error. (#16618) Co-authored-by: qiuguohua --- cocos/2d/assembler/label/text-processing.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cocos/2d/assembler/label/text-processing.ts b/cocos/2d/assembler/label/text-processing.ts index fa0d61c90ed..ed6e61be9eb 100644 --- a/cocos/2d/assembler/label/text-processing.ts +++ b/cocos/2d/assembler/label/text-processing.ts @@ -752,8 +752,11 @@ export class TextProcessing { letterDef = shareLabelInfo.fontAtlas!.getLetterDefinitionForChar(character, shareLabelInfo); if (!letterDef) { this._recordPlaceholderInfo(letterIndex, character); - log(`Can't find letter definition in texture atlas ${ - style.fntConfig!.atlasName} for letter:${character}`); + if (style.fntConfig != null) { + log(`Can't find letter definition in texture atlas ${style.fntConfig.atlasName} for letter:${character}`); + } else { + log(`Can't find letter definition in font family ${style.fontFamily} for letter:${character}`); + } continue; } From d978a22b92b13bc1f73d7076df6f69aaee9e4432 Mon Sep 17 00:00:00 2001 From: Knox Date: Tue, 19 Dec 2023 09:59:09 +0800 Subject: [PATCH 16/32] Fix scene dirty after ReflectionProbe Bake. (#16619) --- cocos/3d/reflection-probe/reflection-probe-component.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos/3d/reflection-probe/reflection-probe-component.ts b/cocos/3d/reflection-probe/reflection-probe-component.ts index a4fe36a18c8..4e00b7df9b4 100644 --- a/cocos/3d/reflection-probe/reflection-probe-component.ts +++ b/cocos/3d/reflection-probe/reflection-probe-component.ts @@ -270,7 +270,8 @@ export class ReflectionProbe extends Component { this.probe.cubemap = val; ReflectionProbeManager.probeManager.onUpdateProbes(); } - + @type(TextureCube) + @visible(false) get cubemap (): TextureCube | null { return this._cubemap; } From adfa22d38d9c7857aac090ce1e3cfa2b545e418f Mon Sep 17 00:00:00 2001 From: Knox Date: Tue, 19 Dec 2023 10:04:06 +0800 Subject: [PATCH 17/32] fix unregister child events when removing 'light-probe-group-footer' (#16617) * fix unregister child events when removing 'light-probe-group-footer' * refine code --- .../components/light-probe-group-footer.js | 87 ++++++++++--------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/editor/inspector/components/light-probe-group-footer.js b/editor/inspector/components/light-probe-group-footer.js index bdfe0961709..030dceae834 100644 --- a/editor/inspector/components/light-probe-group-footer.js +++ b/editor/inspector/components/light-probe-group-footer.js @@ -52,50 +52,17 @@ exports.update = async function(dump) { exports.ready = function() { const panel = this; - panel.$.generate.addEventListener('confirm', async () => { - const result = await Editor.Dialog.warn(Editor.I18n.t('ENGINE.components.lightProbeGroup.generateWarnTip'), { - buttons: [Editor.I18n.t('ENGINE.dialog.confirm'), Editor.I18n.t('ENGINE.dialog.cancel')], - default: 0, - cancel: 1, - }); + panel.onGenerateConfirmBind = panel.onGenerateConfirm.bind(panel); + panel.$.generate.addEventListener('confirm', panel.onGenerateConfirmBind); - if (result.response === 0) { - // 先关闭盒子模式 - if (panel.sceneProbeBoxMode) { - await Editor.Message.request(getMessageProtocolScene(this.$this), 'toggle-light-probe-bounding-box-edit-mode', !panel.sceneProbeBoxMode); - } - - const uuidObject = panel.dump.value.uuid; - const uuids = uuidObject.values ? uuidObject.values : [uuidObject.value]; - const undoID = await Editor.Message.request(getMessageProtocolScene(this.$this), 'begin-recording', uuids); - for (const uuid of uuids) { - Editor.Message.send(getMessageProtocolScene(this.$this), 'execute-component-method', { - uuid: uuid, - name: 'generateLightProbes', - args: [], - }); - } - - trackEventWithTimer('bakingSystem', 'A100006'); - - await Editor.Message.request(getMessageProtocolScene(this.$this), 'end-recording', undoID); - } - }); - - panel.$.edit.addEventListener('confirm', async () => { - await Editor.Message.request(getMessageProtocolScene(this.$this), 'toggle-light-probe-edit-mode', !panel.sceneProbeMode); - trackEventWithTimer('bakingSystem', 'A100008'); - Editor.Panel.focus('scene'); - }); + panel.onEditConfirmBind = panel.onEditConfirm.bind(panel); + panel.$.edit.addEventListener('confirm', panel.onEditConfirmBind); panel.changeProbeModeBind = panel.changeProbeMode.bind(panel); Editor.Message.addBroadcastListener('scene:light-probe-edit-mode-changed', panel.changeProbeModeBind); - panel.$.box.addEventListener('confirm', async () => { - await Editor.Message.request(getMessageProtocolScene(this.$this), 'toggle-light-probe-bounding-box-edit-mode', !panel.sceneProbeBoxMode); - trackEventWithTimer('bakingSystem', 'A100007'); - Editor.Panel.focus('scene'); - }); + panel.onBoxConfirmBind = panel.onBoxConfirm.bind(panel); + panel.$.box.addEventListener('confirm', panel.onBoxConfirmBind); panel.changeProbeBoxModeBind = panel.changeProbeBoxMode.bind(panel); Editor.Message.addBroadcastListener('scene:light-probe-bounding-box-edit-mode-changed', panel.changeProbeBoxModeBind); @@ -104,6 +71,9 @@ exports.ready = function() { exports.close = function() { const panel = this; + panel.$.generate.removeEventListener('confirm', panel.onGenerateConfirmBind); + panel.$.edit.removeEventListener('confirm', panel.onEditConfirmBind); + panel.$.box.removeEventListener('confirm', panel.onBoxConfirmBind); Editor.Message.removeBroadcastListener('scene:light-probe-edit-mode-changed', panel.changeProbeModeBind); Editor.Message.removeBroadcastListener('scene:light-probe-bounding-box-edit-mode-changed', panel.changeProbeBoxModeBind); }; @@ -137,4 +107,43 @@ exports.methods = { panel.$.box.classList.remove('red'); } }, + async onGenerateConfirm() { + const result = await Editor.Dialog.warn(Editor.I18n.t('ENGINE.components.lightProbeGroup.generateWarnTip'), { + buttons: [Editor.I18n.t('ENGINE.dialog.confirm'), Editor.I18n.t('ENGINE.dialog.cancel')], + default: 0, + cancel: 1, + }); + + if (result.response === 0) { + // Turn off the box mode first + if (this.sceneProbeBoxMode) { + await Editor.Message.request(getMessageProtocolScene(this.$this), 'toggle-light-probe-bounding-box-edit-mode', !this.sceneProbeBoxMode); + } + + const uuidObject = this.dump.value.uuid; + const uuids = uuidObject.values ? uuidObject.values : [uuidObject.value]; + const undoID = await Editor.Message.request(getMessageProtocolScene(this.$this), 'begin-recording', uuids); + for (const uuid of uuids) { + Editor.Message.send(getMessageProtocolScene(this.$this), 'execute-component-method', { + uuid: uuid, + name: 'generateLightProbes', + args: [], + }); + } + + trackEventWithTimer('bakingSystem', 'A100006'); + + await Editor.Message.request(getMessageProtocolScene(this.$this), 'end-recording', undoID); + } + }, + async onEditConfirm() { + await Editor.Message.request(getMessageProtocolScene(this.$this), 'toggle-light-probe-edit-mode', !this.sceneProbeMode); + trackEventWithTimer('bakingSystem', 'A100008'); + Editor.Panel.focus('scene'); + }, + async onBoxConfirm() { + await Editor.Message.request(getMessageProtocolScene(this.$this), 'toggle-light-probe-bounding-box-edit-mode', !this.sceneProbeBoxMode); + trackEventWithTimer('bakingSystem', 'A100007'); + Editor.Panel.focus('scene'); + }, }; From 18247aff2b04e0d80bd0140a6d224dd84556386f Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 19 Dec 2023 10:37:38 +0800 Subject: [PATCH 18/32] Update web templates, check wether polyfill file exists in index.html. (#16614) --- templates/web-desktop/index-plugin.ejs | 4 +++- templates/web-mobile/index-plugin.ejs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/templates/web-desktop/index-plugin.ejs b/templates/web-desktop/index-plugin.ejs index 3535fec770b..d72e53d03ef 100644 --- a/templates/web-desktop/index-plugin.ejs +++ b/templates/web-desktop/index-plugin.ejs @@ -1,5 +1,7 @@ - +<% if(polyfillsBundleFile) { %> + +<% } %> diff --git a/templates/web-mobile/index-plugin.ejs b/templates/web-mobile/index-plugin.ejs index 4206b536741..b85d44b0c6e 100644 --- a/templates/web-mobile/index-plugin.ejs +++ b/templates/web-mobile/index-plugin.ejs @@ -5,8 +5,11 @@ window.VConsole && (window.vConsole = new VConsole()); <% } %> + +<% if(polyfillsBundleFile) { %> +<% } %> From 0527eb59d35bf8938bcd18e9bb7b591c4dad716f Mon Sep 17 00:00:00 2001 From: Zeqiang Li Date: Tue, 19 Dec 2023 11:27:40 +0800 Subject: [PATCH 19/32] missing shader visibility for CCLocal (#16506) --- cocos/rendering/define.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/rendering/define.ts b/cocos/rendering/define.ts index 6b9c1a3593d..3968f4440c1 100644 --- a/cocos/rendering/define.ts +++ b/cocos/rendering/define.ts @@ -384,7 +384,7 @@ export class UBOLocal { public static readonly NAME = 'CCLocal'; public static readonly BINDING = ModelLocalBindings.UBO_LOCAL; - public static readonly DESCRIPTOR = new DescriptorSetLayoutBinding(UBOLocal.BINDING, DescriptorType.UNIFORM_BUFFER, 1, ShaderStageFlagBit.VERTEX | ShaderStageFlagBit.COMPUTE); + public static readonly DESCRIPTOR = new DescriptorSetLayoutBinding(UBOLocal.BINDING, DescriptorType.UNIFORM_BUFFER, 1, ShaderStageFlagBit.VERTEX | ShaderStageFlagBit.FRAGMENT | ShaderStageFlagBit.COMPUTE); public static readonly LAYOUT = new UniformBlock(SetIndex.LOCAL, UBOLocal.BINDING, UBOLocal.NAME, [ new Uniform('cc_matWorld', Type.MAT4, 1), new Uniform('cc_matWorldIT', Type.MAT4, 1), From 09f940a5d8e10902ef285b51af0c577c5fbfc5d0 Mon Sep 17 00:00:00 2001 From: Knox Date: Wed, 20 Dec 2023 10:07:27 +0800 Subject: [PATCH 20/32] fix coefficients array not init when "updateProbes" needs to add a new probe (#16627) --- cocos/gi/light-probe/light-probe.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cocos/gi/light-probe/light-probe.ts b/cocos/gi/light-probe/light-probe.ts index 8578b10249c..7248a9b8bba 100644 --- a/cocos/gi/light-probe/light-probe.ts +++ b/cocos/gi/light-probe/light-probe.ts @@ -73,6 +73,10 @@ export class LightProbesData { let probe = this._probes[i]; if (!probe) { probe = new Vertex(points[i]); + for (let j = 0; j < SH.getBasisCount(); j++) { + probe.coefficients[j] = Vec3.ZERO; + } + this._probes[i] = probe; } else { probe.position.set(points[i]); } From 611d5ac4c841c7f45170b9afc250d19dec0ee38e Mon Sep 17 00:00:00 2001 From: finscn Date: Wed, 20 Dec 2023 17:17:19 +0800 Subject: [PATCH 21/32] improve `cc.Color.fromHEX()` (#16561) * improve `cc.Color.fromHEX()` * support hex-number * better performance --- cocos/core/math/color.ts | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/cocos/core/math/color.ts b/cocos/core/math/color.ts index d5393128af5..716f2d88e2d 100644 --- a/cocos/core/math/color.ts +++ b/cocos/core/math/color.ts @@ -126,16 +126,38 @@ export class Color extends ValueType { } /** * @en Converts the hexadecimal formal color into rgb formal and save the results to out color. + * the argument `hex` could be hex-string or hex-number (8-digit or 6-digit). + * the hex-string should be like : '#12345678' '#123456', '123456', '12345678'. + * the hex-number should be like : 0x12345678, 0x123456 . * @zh 从十六进制颜色字符串中读入颜色到 out 中 - */ - public static fromHEX (out: Out, hexString: string): Out { - hexString = (hexString.indexOf('#') === 0) ? hexString.substring(1) : hexString; - out.r = parseInt(hexString.substr(0, 2), 16) || 0; - out.g = parseInt(hexString.substr(2, 2), 16) || 0; - out.b = parseInt(hexString.substr(4, 2), 16) || 0; - const a = parseInt(hexString.substr(6, 2), 16); - out.a = !Number.isNaN(a) ? a : 255; + * 参数 hex 支持 16进制字符串 或者 16进制数值 (8位数字 或者 6位数字). + * 16进制字符串的格式应该类似: '#12345678' '#123456', '123456', '12345678'. + * 16进制数值的格式应该类似: 0x12345678, 0x123456 . + */ + public static fromHEX (out: Out, hex: string | number): Out { + let hexNumber: number; + if (typeof hex === 'string') { + hex = hex[0] === '#' ? hex.substring(1) : hex; + if (hex.length === 6) { + hex += 'FF'; + } else if (hex.length === 3) { + hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + 'FF'; + } else if (hex.length === 4) { + hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]; + } + hexNumber = Number('0x' + hex); + } else { + if (hex < 0x1000000) { + hex = (hex << 8) + 0xff; + } + hexNumber = hex; + } + out.r = hexNumber >>> 24; + out.g = (hexNumber & 0x00ff0000) >>> 16; + out.b = (hexNumber & 0x0000ff00) >>> 8; + out.a = hexNumber & 0x000000ff; out._val = ((out.a << 24) >>> 0) + (out.b << 16) + (out.g << 8) + out.r; + return out; } From 9599aa9c10a6a46a177b83258027b9eb7483d496 Mon Sep 17 00:00:00 2001 From: finscn Date: Fri, 22 Dec 2023 09:23:28 +0800 Subject: [PATCH 22/32] Use `clearTracks()` instead of `clearTrack(0)` (#16606) --- cocos/spine/skeleton.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 64b270e14ab..b480b730f74 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -626,7 +626,7 @@ export class Skeleton extends UIRenderer { if (value) { this.setAnimation(0, value, this.loop); } else { - this.clearAnimation(); + this.clearAnimation(0); } } @@ -719,12 +719,24 @@ export class Skeleton extends UIRenderer { } /** - * @en Clear animation and set to setup pose. - * @zh 清除动画并还原到初始姿势。 + * @en Clear animation and set to setup pose, default value of track index is 0. + * @zh 清除指定动画并还原到初始姿势, 默认清除 track索引 为0的动画。 + * @param {NUmber} [trackIndex] @en track index. @zh track 的索引。 */ - public clearAnimation (): void { + public clearAnimation (trackIndex?: number): void { if (!this.isAnimationCached()) { - this.clearTrack(0); + this.clearTrack(trackIndex || 0); + this.setToSetupPose(); + } + } + + /** + * @en Clear all animations and set to setup pose. + * @zh 清除所有动画并还原到初始姿势。 + */ + public clearAnimations (): void { + if (!this.isAnimationCached()) { + this.clearTracks(); this.setToSetupPose(); } } From be3507c4c4718e910fe4606a5b3a66ccbf62d506 Mon Sep 17 00:00:00 2001 From: qiuguohua Date: Fri, 22 Dec 2023 09:26:15 +0800 Subject: [PATCH 23/32] Update the position of the input if the size changes. (#16634) Co-authored-by: qiuguohua --- cocos/ui/editbox/edit-box-impl.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cocos/ui/editbox/edit-box-impl.ts b/cocos/ui/editbox/edit-box-impl.ts index eeec2ad8cb8..8eca9ae9aa5 100644 --- a/cocos/ui/editbox/edit-box-impl.ts +++ b/cocos/ui/editbox/edit-box-impl.ts @@ -30,7 +30,7 @@ import { BitmapFont } from '../../2d/assets'; import { director } from '../../game/director'; import { game } from '../../game'; import { Mat4, Vec3, visibleRect, sys } from '../../core'; -import { view } from '../view'; +import { view, View } from '../view'; import { KeyCode } from '../../input/types'; import { contains } from '../../core/utils/misc'; import { Label } from '../../2d/components/label'; @@ -120,6 +120,7 @@ export class EditBoxImpl extends EditBoxImplBase { this._initStyleSheet(); this._registerEventListeners(); this._addDomToGameContainer(); + View.instance.on('canvas-resize', this._resize, this); } public clear (): void { @@ -136,6 +137,10 @@ export class EditBoxImpl extends EditBoxImplBase { this._delegate = null; } + private _resize (): void { + this._delegate!.node.hasChangedFlags = 1; + } + public update (): void { const node = this._delegate!.node; if (!node.hasChangedFlags) { From d86d6c6bc7151cf690330a9e72c6b5dda5eb1df4 Mon Sep 17 00:00:00 2001 From: Knox Date: Mon, 25 Dec 2023 14:49:26 +0800 Subject: [PATCH 24/32] upgraded default asset scene version to 1.1.50 (#16636) --- editor/assets/default_prefab/2d/Camera.prefab.meta | 2 +- editor/assets/default_prefab/2d/ui/Canvas.prefab.meta | 2 +- editor/assets/default_prefab/3d/Capsule.prefab.meta | 2 +- editor/assets/default_prefab/3d/Cone.prefab.meta | 2 +- editor/assets/default_prefab/3d/Cube.prefab.meta | 2 +- editor/assets/default_prefab/3d/Cylinder.prefab.meta | 2 +- editor/assets/default_prefab/3d/Plane.prefab.meta | 2 +- editor/assets/default_prefab/3d/Quad.prefab.meta | 2 +- editor/assets/default_prefab/3d/Sphere.prefab.meta | 2 +- editor/assets/default_prefab/3d/Torus.prefab.meta | 2 +- editor/assets/default_prefab/Camera.prefab.meta | 2 +- editor/assets/default_prefab/Terrain.prefab.meta | 2 +- .../assets/default_prefab/effects/Particle System.prefab.meta | 2 +- .../assets/default_prefab/light/Directional Light.prefab.meta | 2 +- .../assets/default_prefab/light/Light Probe Group.prefab.meta | 2 +- editor/assets/default_prefab/light/Point Light.prefab.meta | 2 +- .../default_prefab/light/Ranged Directional Light.prefab.meta | 2 +- editor/assets/default_prefab/light/Reflection Probe.prefab.meta | 2 +- editor/assets/default_prefab/light/Sphere Light.prefab.meta | 2 +- editor/assets/default_prefab/light/Spot Light.prefab.meta | 2 +- editor/assets/default_prefab/ui/Button.prefab.meta | 2 +- editor/assets/default_prefab/ui/Canvas.prefab.meta | 2 +- editor/assets/default_prefab/ui/EditBox.prefab.meta | 2 +- editor/assets/default_prefab/ui/Graphics.prefab.meta | 2 +- editor/assets/default_prefab/ui/Label.prefab.meta | 2 +- editor/assets/default_prefab/ui/Layout.prefab.meta | 2 +- editor/assets/default_prefab/ui/Mask.prefab.meta | 2 +- editor/assets/default_prefab/ui/ParticleSystem2D.prefab.meta | 2 +- editor/assets/default_prefab/ui/ProgressBar.prefab.meta | 2 +- editor/assets/default_prefab/ui/RichText.prefab.meta | 2 +- editor/assets/default_prefab/ui/ScrollView.prefab.meta | 2 +- editor/assets/default_prefab/ui/Slider.prefab.meta | 2 +- editor/assets/default_prefab/ui/Sprite.prefab.meta | 2 +- editor/assets/default_prefab/ui/SpriteRenderer.prefab.meta | 2 +- editor/assets/default_prefab/ui/SpriteSplash.prefab.meta | 2 +- editor/assets/default_prefab/ui/TiledMap.prefab.meta | 2 +- editor/assets/default_prefab/ui/Toggle.prefab.meta | 2 +- editor/assets/default_prefab/ui/ToggleContainer.prefab.meta | 2 +- editor/assets/default_prefab/ui/VideoPlayer.prefab.meta | 2 +- editor/assets/default_prefab/ui/WebView.prefab.meta | 2 +- editor/assets/default_prefab/ui/Widget.prefab.meta | 2 +- editor/assets/default_prefab/ui/pageView.prefab.meta | 2 +- editor/assets/tools/debug-view-runtime-control.prefab.meta | 2 +- 43 files changed, 43 insertions(+), 43 deletions(-) diff --git a/editor/assets/default_prefab/2d/Camera.prefab.meta b/editor/assets/default_prefab/2d/Camera.prefab.meta index ad7cdf57623..545e2c36478 100644 --- a/editor/assets/default_prefab/2d/Camera.prefab.meta +++ b/editor/assets/default_prefab/2d/Camera.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "3487d118-0158-4983-93fe-c3822790e7c5", diff --git a/editor/assets/default_prefab/2d/ui/Canvas.prefab.meta b/editor/assets/default_prefab/2d/ui/Canvas.prefab.meta index f33a54cb75e..20a5075b62d 100644 --- a/editor/assets/default_prefab/2d/ui/Canvas.prefab.meta +++ b/editor/assets/default_prefab/2d/ui/Canvas.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "4c33600e-9ca9-483b-b734-946008261697", diff --git a/editor/assets/default_prefab/3d/Capsule.prefab.meta b/editor/assets/default_prefab/3d/Capsule.prefab.meta index 76db4af8e75..77d18f24f7e 100644 --- a/editor/assets/default_prefab/3d/Capsule.prefab.meta +++ b/editor/assets/default_prefab/3d/Capsule.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "73ce1f7f-d1f4-4942-ad93-66ca3b3041ab", diff --git a/editor/assets/default_prefab/3d/Cone.prefab.meta b/editor/assets/default_prefab/3d/Cone.prefab.meta index b34605a1e5a..a0f8d998906 100644 --- a/editor/assets/default_prefab/3d/Cone.prefab.meta +++ b/editor/assets/default_prefab/3d/Cone.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "6350d660-e888-4acf-a552-f3b719ae9110", diff --git a/editor/assets/default_prefab/3d/Cube.prefab.meta b/editor/assets/default_prefab/3d/Cube.prefab.meta index 0155ae18b60..d9db4926521 100644 --- a/editor/assets/default_prefab/3d/Cube.prefab.meta +++ b/editor/assets/default_prefab/3d/Cube.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "30da77a1-f02d-4ede-aa56-403452ee7fde", diff --git a/editor/assets/default_prefab/3d/Cylinder.prefab.meta b/editor/assets/default_prefab/3d/Cylinder.prefab.meta index 23303d97fc7..8649ae0e22d 100644 --- a/editor/assets/default_prefab/3d/Cylinder.prefab.meta +++ b/editor/assets/default_prefab/3d/Cylinder.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "ab3e16f9-671e-48a7-90b7-d0884d9cbb85", diff --git a/editor/assets/default_prefab/3d/Plane.prefab.meta b/editor/assets/default_prefab/3d/Plane.prefab.meta index 28f5dda5f49..840d1d618b2 100644 --- a/editor/assets/default_prefab/3d/Plane.prefab.meta +++ b/editor/assets/default_prefab/3d/Plane.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "40563723-f8fc-4216-99ea-a81636435c10", diff --git a/editor/assets/default_prefab/3d/Quad.prefab.meta b/editor/assets/default_prefab/3d/Quad.prefab.meta index 8e16ec5e9e8..13f7ab64ea9 100644 --- a/editor/assets/default_prefab/3d/Quad.prefab.meta +++ b/editor/assets/default_prefab/3d/Quad.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "34a07346-9f62-4a84-90ae-cb83f7a426c1", diff --git a/editor/assets/default_prefab/3d/Sphere.prefab.meta b/editor/assets/default_prefab/3d/Sphere.prefab.meta index 2226e2e1585..d8e87d0ff18 100644 --- a/editor/assets/default_prefab/3d/Sphere.prefab.meta +++ b/editor/assets/default_prefab/3d/Sphere.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "655c9519-1a37-472b-bae6-29fefac0b550", diff --git a/editor/assets/default_prefab/3d/Torus.prefab.meta b/editor/assets/default_prefab/3d/Torus.prefab.meta index 03be60e79be..acfdf5cbf3f 100644 --- a/editor/assets/default_prefab/3d/Torus.prefab.meta +++ b/editor/assets/default_prefab/3d/Torus.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "d47f5d5e-c931-4ff4-987b-cc818a728b82", diff --git a/editor/assets/default_prefab/Camera.prefab.meta b/editor/assets/default_prefab/Camera.prefab.meta index 92ea57a3a5a..495976747a6 100644 --- a/editor/assets/default_prefab/Camera.prefab.meta +++ b/editor/assets/default_prefab/Camera.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "bb0a6472-cd67-4afb-a031-94fca8f4cc92", diff --git a/editor/assets/default_prefab/Terrain.prefab.meta b/editor/assets/default_prefab/Terrain.prefab.meta index 7b34955b2f4..f3dc9dddd72 100644 --- a/editor/assets/default_prefab/Terrain.prefab.meta +++ b/editor/assets/default_prefab/Terrain.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "90e8b0d4-12dc-412d-9156-ea1fdb18c15b", diff --git a/editor/assets/default_prefab/effects/Particle System.prefab.meta b/editor/assets/default_prefab/effects/Particle System.prefab.meta index ac7961c5284..0c12a6da974 100644 --- a/editor/assets/default_prefab/effects/Particle System.prefab.meta +++ b/editor/assets/default_prefab/effects/Particle System.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "f09a0597-10e6-49e5-8759-a148b5e85395", diff --git a/editor/assets/default_prefab/light/Directional Light.prefab.meta b/editor/assets/default_prefab/light/Directional Light.prefab.meta index b92f75d0535..242d7bba80e 100644 --- a/editor/assets/default_prefab/light/Directional Light.prefab.meta +++ b/editor/assets/default_prefab/light/Directional Light.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "a0e9756d-9128-4f49-8097-e041c8b733b8", diff --git a/editor/assets/default_prefab/light/Light Probe Group.prefab.meta b/editor/assets/default_prefab/light/Light Probe Group.prefab.meta index 359cec2c3c4..d785f93962c 100644 --- a/editor/assets/default_prefab/light/Light Probe Group.prefab.meta +++ b/editor/assets/default_prefab/light/Light Probe Group.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "50dfda40-7c45-4868-a876-2fe2a4c782f4", diff --git a/editor/assets/default_prefab/light/Point Light.prefab.meta b/editor/assets/default_prefab/light/Point Light.prefab.meta index 7d1909c9a08..810b4b0fd01 100644 --- a/editor/assets/default_prefab/light/Point Light.prefab.meta +++ b/editor/assets/default_prefab/light/Point Light.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "03029371-ee64-4f14-820a-d495ad7cdc29", diff --git a/editor/assets/default_prefab/light/Ranged Directional Light.prefab.meta b/editor/assets/default_prefab/light/Ranged Directional Light.prefab.meta index 925508bc6e4..e266597bb34 100644 --- a/editor/assets/default_prefab/light/Ranged Directional Light.prefab.meta +++ b/editor/assets/default_prefab/light/Ranged Directional Light.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "df72d0f6-49d3-452a-b082-8b23d38b33af", diff --git a/editor/assets/default_prefab/light/Reflection Probe.prefab.meta b/editor/assets/default_prefab/light/Reflection Probe.prefab.meta index c38fbdde580..92d7a011194 100644 --- a/editor/assets/default_prefab/light/Reflection Probe.prefab.meta +++ b/editor/assets/default_prefab/light/Reflection Probe.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "d8b49b64-cfba-4cfa-be53-1e469547b28b", diff --git a/editor/assets/default_prefab/light/Sphere Light.prefab.meta b/editor/assets/default_prefab/light/Sphere Light.prefab.meta index 77bee59cc15..8224dc8c029 100644 --- a/editor/assets/default_prefab/light/Sphere Light.prefab.meta +++ b/editor/assets/default_prefab/light/Sphere Light.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "4182ee46-ffa0-4de2-b66b-c93cc6c7e9b8", diff --git a/editor/assets/default_prefab/light/Spot Light.prefab.meta b/editor/assets/default_prefab/light/Spot Light.prefab.meta index 5a000536c5a..31f5175fe7c 100644 --- a/editor/assets/default_prefab/light/Spot Light.prefab.meta +++ b/editor/assets/default_prefab/light/Spot Light.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "7a49aa24-bd7a-40a8-b31a-b2a9da85abcd", diff --git a/editor/assets/default_prefab/ui/Button.prefab.meta b/editor/assets/default_prefab/ui/Button.prefab.meta index ad185655c69..0261cde72ed 100644 --- a/editor/assets/default_prefab/ui/Button.prefab.meta +++ b/editor/assets/default_prefab/ui/Button.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "90bdd2a9-2838-4888-b66c-e94c8b7a5169", diff --git a/editor/assets/default_prefab/ui/Canvas.prefab.meta b/editor/assets/default_prefab/ui/Canvas.prefab.meta index 7b7c6384ab0..160450d3887 100644 --- a/editor/assets/default_prefab/ui/Canvas.prefab.meta +++ b/editor/assets/default_prefab/ui/Canvas.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "f773db21-62b8-4540-956a-29bacf5ddbf5", diff --git a/editor/assets/default_prefab/ui/EditBox.prefab.meta b/editor/assets/default_prefab/ui/EditBox.prefab.meta index 7661b7f8c90..90ea755e9d3 100644 --- a/editor/assets/default_prefab/ui/EditBox.prefab.meta +++ b/editor/assets/default_prefab/ui/EditBox.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "05e79121-8675-4551-9ad7-1b901a4025db", diff --git a/editor/assets/default_prefab/ui/Graphics.prefab.meta b/editor/assets/default_prefab/ui/Graphics.prefab.meta index 7b4463acc28..5850c592155 100644 --- a/editor/assets/default_prefab/ui/Graphics.prefab.meta +++ b/editor/assets/default_prefab/ui/Graphics.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "c96e159e-43ea-4a16-8279-05bc39119d1a", diff --git a/editor/assets/default_prefab/ui/Label.prefab.meta b/editor/assets/default_prefab/ui/Label.prefab.meta index 881efa9de41..2f62ea97c66 100644 --- a/editor/assets/default_prefab/ui/Label.prefab.meta +++ b/editor/assets/default_prefab/ui/Label.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "36008810-7ad3-47c0-8112-e30aee089e45", diff --git a/editor/assets/default_prefab/ui/Layout.prefab.meta b/editor/assets/default_prefab/ui/Layout.prefab.meta index 5d691e90730..610cd7c2447 100644 --- a/editor/assets/default_prefab/ui/Layout.prefab.meta +++ b/editor/assets/default_prefab/ui/Layout.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "a9ef7dfc-ea8b-4cf8-918e-36da948c4de0", diff --git a/editor/assets/default_prefab/ui/Mask.prefab.meta b/editor/assets/default_prefab/ui/Mask.prefab.meta index 3792c4b84bc..a0b53e41fea 100644 --- a/editor/assets/default_prefab/ui/Mask.prefab.meta +++ b/editor/assets/default_prefab/ui/Mask.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "7fa63aed-f3e2-46a5-8a7c-c1a1adf6cea6", diff --git a/editor/assets/default_prefab/ui/ParticleSystem2D.prefab.meta b/editor/assets/default_prefab/ui/ParticleSystem2D.prefab.meta index 7fc1b6ea004..6c4e8264ce2 100644 --- a/editor/assets/default_prefab/ui/ParticleSystem2D.prefab.meta +++ b/editor/assets/default_prefab/ui/ParticleSystem2D.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "f396261e-3e06-41ec-bdd6-9a8b6d99026f", diff --git a/editor/assets/default_prefab/ui/ProgressBar.prefab.meta b/editor/assets/default_prefab/ui/ProgressBar.prefab.meta index 8f13645d809..cf9c644dc50 100644 --- a/editor/assets/default_prefab/ui/ProgressBar.prefab.meta +++ b/editor/assets/default_prefab/ui/ProgressBar.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "0d9353c4-6fb9-49bb-bc62-77f1750078c2", diff --git a/editor/assets/default_prefab/ui/RichText.prefab.meta b/editor/assets/default_prefab/ui/RichText.prefab.meta index 73797af04e4..e6e758a76e1 100644 --- a/editor/assets/default_prefab/ui/RichText.prefab.meta +++ b/editor/assets/default_prefab/ui/RichText.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "fc6bfcfa-8086-4326-809b-0ba1226bac7d", diff --git a/editor/assets/default_prefab/ui/ScrollView.prefab.meta b/editor/assets/default_prefab/ui/ScrollView.prefab.meta index 92ae53d13fe..f2b3b34c19c 100644 --- a/editor/assets/default_prefab/ui/ScrollView.prefab.meta +++ b/editor/assets/default_prefab/ui/ScrollView.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "c1baa707-78d6-4b89-8d5d-0b7fdf0c39bc", diff --git a/editor/assets/default_prefab/ui/Slider.prefab.meta b/editor/assets/default_prefab/ui/Slider.prefab.meta index 14586825920..4ad42ef7722 100644 --- a/editor/assets/default_prefab/ui/Slider.prefab.meta +++ b/editor/assets/default_prefab/ui/Slider.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "2bd7e5b6-cd8c-41a1-8136-ddb8efbf6326", diff --git a/editor/assets/default_prefab/ui/Sprite.prefab.meta b/editor/assets/default_prefab/ui/Sprite.prefab.meta index c0f94735dbb..9b88095b8dd 100644 --- a/editor/assets/default_prefab/ui/Sprite.prefab.meta +++ b/editor/assets/default_prefab/ui/Sprite.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "9db8cd0b-cbe4-42e7-96a9-a239620c0a9d", diff --git a/editor/assets/default_prefab/ui/SpriteRenderer.prefab.meta b/editor/assets/default_prefab/ui/SpriteRenderer.prefab.meta index 77bbcb0ab98..083297f98f1 100644 --- a/editor/assets/default_prefab/ui/SpriteRenderer.prefab.meta +++ b/editor/assets/default_prefab/ui/SpriteRenderer.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "279ed042-5a65-4efe-9afb-2fc23c61e15a", diff --git a/editor/assets/default_prefab/ui/SpriteSplash.prefab.meta b/editor/assets/default_prefab/ui/SpriteSplash.prefab.meta index 2727ee85ff7..6574c096627 100644 --- a/editor/assets/default_prefab/ui/SpriteSplash.prefab.meta +++ b/editor/assets/default_prefab/ui/SpriteSplash.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "e5f21aad-3a69-4011-ac62-b74352ac025e", diff --git a/editor/assets/default_prefab/ui/TiledMap.prefab.meta b/editor/assets/default_prefab/ui/TiledMap.prefab.meta index 3072ca81b17..eabd4b35400 100644 --- a/editor/assets/default_prefab/ui/TiledMap.prefab.meta +++ b/editor/assets/default_prefab/ui/TiledMap.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "3139fa4f-8c42-4ce6-98be-15e848d9734c", diff --git a/editor/assets/default_prefab/ui/Toggle.prefab.meta b/editor/assets/default_prefab/ui/Toggle.prefab.meta index 4aece91b233..584a1fbb84f 100644 --- a/editor/assets/default_prefab/ui/Toggle.prefab.meta +++ b/editor/assets/default_prefab/ui/Toggle.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "0e89afe7-56de-4f99-96a1-cba8a75bedd2", diff --git a/editor/assets/default_prefab/ui/ToggleContainer.prefab.meta b/editor/assets/default_prefab/ui/ToggleContainer.prefab.meta index 9c6c100db85..b577139c4d3 100644 --- a/editor/assets/default_prefab/ui/ToggleContainer.prefab.meta +++ b/editor/assets/default_prefab/ui/ToggleContainer.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "2af73429-41d1-4346-9062-7798e42945dd", diff --git a/editor/assets/default_prefab/ui/VideoPlayer.prefab.meta b/editor/assets/default_prefab/ui/VideoPlayer.prefab.meta index fa11ee31a45..f0394403577 100644 --- a/editor/assets/default_prefab/ui/VideoPlayer.prefab.meta +++ b/editor/assets/default_prefab/ui/VideoPlayer.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "7e089eaf-fa97-40d7-8a20-741a152585df", diff --git a/editor/assets/default_prefab/ui/WebView.prefab.meta b/editor/assets/default_prefab/ui/WebView.prefab.meta index 2085c013dbb..2197837ae63 100644 --- a/editor/assets/default_prefab/ui/WebView.prefab.meta +++ b/editor/assets/default_prefab/ui/WebView.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "9c541fa2-1dc8-4d8b-813a-aec89133f5b1", diff --git a/editor/assets/default_prefab/ui/Widget.prefab.meta b/editor/assets/default_prefab/ui/Widget.prefab.meta index 68560828750..2141f53d296 100644 --- a/editor/assets/default_prefab/ui/Widget.prefab.meta +++ b/editor/assets/default_prefab/ui/Widget.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "36ed4422-3542-4cc4-bf02-dc4bfc590836", diff --git a/editor/assets/default_prefab/ui/pageView.prefab.meta b/editor/assets/default_prefab/ui/pageView.prefab.meta index 000fc2d496c..c81dd293792 100644 --- a/editor/assets/default_prefab/ui/pageView.prefab.meta +++ b/editor/assets/default_prefab/ui/pageView.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "20a5d8cb-ccad-4543-a937-fccd98c9f3de", diff --git a/editor/assets/tools/debug-view-runtime-control.prefab.meta b/editor/assets/tools/debug-view-runtime-control.prefab.meta index f9cb4c0b18f..dd0a62571c8 100644 --- a/editor/assets/tools/debug-view-runtime-control.prefab.meta +++ b/editor/assets/tools/debug-view-runtime-control.prefab.meta @@ -1,5 +1,5 @@ { - "ver": "1.1.49", + "ver": "1.1.50", "importer": "prefab", "imported": true, "uuid": "7f4ddeab-efa9-4b76-bf6a-029520f68461", From b781fe2ad96d136a9227917c0e10735fdf68a7f3 Mon Sep 17 00:00:00 2001 From: Knox Date: Mon, 25 Dec 2023 14:52:20 +0800 Subject: [PATCH 25/32] update label outline and shadow deprecated log (#16637) * update label outline and shadow deprecated log --- cocos/2d/components/deprecated.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cocos/2d/components/deprecated.ts b/cocos/2d/components/deprecated.ts index cd2ed98e9d1..556525e8998 100644 --- a/cocos/2d/components/deprecated.ts +++ b/cocos/2d/components/deprecated.ts @@ -127,28 +127,28 @@ replaceProperty(MaskType, 'MaskType', [ }, ]); -markAsWarning(LabelOutline.prototype, 'LabelOutline.prototype', [ +markAsWarning(LabelOutline.prototype, 'LabelOutline', [ { name: 'width', - suggest: 'Please use Label.prototype.outlineWidth instead.', + suggest: 'Please use Label.outlineWidth instead.', }, { name: 'color', - suggest: 'Please use Label.prototype.outlineColor instead.', + suggest: 'Please use Label.outlineColor instead.', }, ]); -markAsWarning(LabelShadow.prototype, 'LabelShadow.prototype', [ +markAsWarning(LabelShadow.prototype, 'LabelShadow', [ { name: 'color', - suggest: 'Please use Label.prototype.shadowColor instead.', + suggest: 'Please use Label.shadowColor instead.', }, { name: 'offset', - suggest: 'Please use Label.prototype.shadowOffset instead.', + suggest: 'Please use Label.shadowOffset instead.', }, { name: 'blur', - suggest: 'Please use Label.prototype.shadowBlur instead.', + suggest: 'Please use Label.shadowBlur instead.', }, ]); From a55c0aab349b22864c775925f38519125ba3ece3 Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Tue, 26 Dec 2023 13:40:51 +0800 Subject: [PATCH 26/32] Fix the issue of incorrect updating of the Spine shared-cache reference count. (#16639) --- cocos/spine/skeleton-cache.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/spine/skeleton-cache.ts b/cocos/spine/skeleton-cache.ts index 9d71d88fb98..e83d69b6e41 100644 --- a/cocos/spine/skeleton-cache.ts +++ b/cocos/spine/skeleton-cache.ts @@ -350,6 +350,7 @@ class SkeletonCache { if (refCount) { refCount -= 1; if (refCount > 0) { + this._sharedCacheMap.set(assetUuid, refCount); return; } this._sharedCacheMap.delete(assetUuid); From 6dc6feda9d16978b483b4c6eaea135f3007e7a4f Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Wed, 3 Jan 2024 10:18:52 +0800 Subject: [PATCH 27/32] improve performance (#16650) * improve performance * fix typo --- .../post-process/utils/pass-context.ts | 37 +++++++++++++++---- .../pipeline/custom/RenderGraphTypes.h | 8 ++-- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/cocos/rendering/post-process/utils/pass-context.ts b/cocos/rendering/post-process/utils/pass-context.ts index e6c2a755e1b..10df668fe5d 100644 --- a/cocos/rendering/post-process/utils/pass-context.ts +++ b/cocos/rendering/post-process/utils/pass-context.ts @@ -40,6 +40,11 @@ export class PassContext { forwardPass: any = undefined; postProcess: PostProcess | undefined; + maxSpotLights = 0xFFFFFFFF; + maxSphereLights = 0xFFFFFFFF; + maxPointLights = 0xFFFFFFFF; + maxRangedDirLights = 0xFFFFFFFF; + setClearFlag (clearFlag: ClearFlagBit): PassContext { this.clearFlag = clearFlag; return this; @@ -85,9 +90,25 @@ export class PassContext { } addSceneLights (queue: RenderQueueBuilder, camera: Camera, flags: SceneFlags = SceneFlags.BLEND): void { + if (this.maxPointLights === 0 + && this.maxSphereLights === 0 + && this.maxSpotLights === 0 + && this.maxRangedDirLights === 0) { + return; + } const scene = camera.scene!; - for (let i = 0; i < scene.spotLights.length; i++) { - const light = scene.spotLights[i]; + const spotLights = scene.spotLights; + const sphereLights = scene.sphereLights; + const pointLights = scene.pointLights; + const rangedDirLights = scene.rangedDirLights; + + const numSpotLights = Math.min(spotLights.length, this.maxSpotLights); + const numSphereLights = Math.min(sphereLights.length, this.maxSphereLights); + const numPointLights = Math.min(pointLights.length, this.maxPointLights); + const numRangedDirLights = Math.min(rangedDirLights.length, this.maxRangedDirLights); + + for (let i = 0; i < numSpotLights; i++) { + const light = spotLights[i]; if (light.baked) { continue; } @@ -97,8 +118,8 @@ export class PassContext { } } // sphere lights - for (let i = 0; i < scene.sphereLights.length; i++) { - const light = scene.sphereLights[i]; + for (let i = 0; i < numSphereLights; i++) { + const light = sphereLights[i]; if (light.baked) { continue; } @@ -108,8 +129,8 @@ export class PassContext { } } // point lights - for (let i = 0; i < scene.pointLights.length; i++) { - const light = scene.pointLights[i]; + for (let i = 0; i < numPointLights; i++) { + const light = pointLights[i]; if (light.baked) { continue; } @@ -119,8 +140,8 @@ export class PassContext { } } // ranged dir lights - for (let i = 0; i < scene.rangedDirLights.length; i++) { - const light = scene.rangedDirLights[i]; + for (let i = 0; i < numRangedDirLights; i++) { + const light = rangedDirLights[i]; geometry.AABB.transform(boundingBox, rangedDirLightBoundingBox, light.node!.getWorldMatrix()); if (geometry.intersect.aabbFrustum(boundingBox, camera.frustum)) { queue.addSceneOfCamera(camera, new LightInfo(light), flags); diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h index 300a53b8c6b..3809d968745 100644 --- a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h @@ -965,10 +965,10 @@ struct RenderData { RenderData& operator=(RenderData&& rhs) = default; RenderData& operator=(RenderData const& rhs) = delete; - PmrUnorderedMap> constants; - PmrUnorderedMap> buffers; - PmrUnorderedMap> textures; - PmrUnorderedMap samplers; + PmrFlatMap> constants; + PmrFlatMap> buffers; + PmrFlatMap> textures; + PmrFlatMap samplers; ccstd::pmr::string custom; }; From c9d7339e55a34b4fd4b09a096b434a676a3fbde0 Mon Sep 17 00:00:00 2001 From: Cocos Robot <48829427+cocos-robot@users.noreply.github.com> Date: Wed, 3 Jan 2024 16:18:50 +0800 Subject: [PATCH 28/32] [ci skip][AUTO]: Automated code generating update: e31656893aca28cf32daa0d8277d7596b5a63bbd (#16650) (#16655) Co-authored-by: cocos-robot --- native/cocos/cocos-version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/cocos-version.h b/native/cocos/cocos-version.h index 0d7098a9d4a..a81c2447fb0 100644 --- a/native/cocos/cocos-version.h +++ b/native/cocos/cocos-version.h @@ -1,5 +1,5 @@ /**************************************************************************** -Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2022-2024 Xiamen Yaji Software Co., Ltd. http://www.cocos.com From a98500105c5ed47a60da56132bcebeba2a6b9346 Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Thu, 4 Jan 2024 16:52:45 +0800 Subject: [PATCH 29/32] Fixing the reference counting bug in Spine. (#16663) --- cocos/spine/skeleton-cache.ts | 3 +++ cocos/spine/skeleton.ts | 7 ++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos/spine/skeleton-cache.ts b/cocos/spine/skeleton-cache.ts index e83d69b6e41..4fd1b219b55 100644 --- a/cocos/spine/skeleton-cache.ts +++ b/cocos/spine/skeleton-cache.ts @@ -395,6 +395,9 @@ class SkeletonCache { } this._sharedCacheMap.set(uuid, refCount); } + if (this._skeletonCache[uuid]) { + return this._skeletonCache[uuid]; + } const skeleton = new spine.Skeleton(runtimeData!); const clipper = null; diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index b480b730f74..5f47a2cdee9 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -805,13 +805,10 @@ export class Skeleton extends UIRenderer { if (this.debugBones || this.debugSlots) { warn('Debug bones or slots is invalid in cached mode'); } - let skeletonInfo = this._skeletonCache!.getSkeletonInfo(this._skeletonData!); + const skeletonInfo = this._skeletonCache!.getSkeletonInfo(this._skeletonData!); if (this._skeletonInfo !== skeletonInfo) { this._destroySkeletonInfo(this._skeletonCache); - if (!skeletonInfo) { - skeletonInfo = this._skeletonCache!.createSkeletonInfo(this._skeletonData!); - } - this._skeletonInfo = skeletonInfo; + this._skeletonInfo = this._skeletonCache!.createSkeletonInfo(this._skeletonData!); this._skeleton = this._skeletonInfo.skeleton!; } } else { From 518bdbb040ec02c34505ef03edcbaea3a1a7bf4a Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Thu, 4 Jan 2024 18:23:38 +0800 Subject: [PATCH 30/32] V3.8.2 gfx (#16664) * fix glsl macro bug * lint --- native/cocos/renderer/gfx-base/SPIRVUtils.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/native/cocos/renderer/gfx-base/SPIRVUtils.cpp b/native/cocos/renderer/gfx-base/SPIRVUtils.cpp index f47730a28fb..fbb32eda5b1 100644 --- a/native/cocos/renderer/gfx-base/SPIRVUtils.cpp +++ b/native/cocos/renderer/gfx-base/SPIRVUtils.cpp @@ -31,6 +31,11 @@ #include "glslang/StandAlone/ResourceLimits.h" #include "spirv/spirv.h" +#define CC_GLSLANG_VERSION_GREATOR_OR_EQUAL_TO(major, minor, patch) \ + (((major) < GLSLANG_VERSION_MAJOR) || ((major) == GLSLANG_VERSION_MAJOR && \ + (((minor) < GLSLANG_VERSION_MINOR) || ((minor) == GLSLANG_VERSION_MINOR && \ + ((patch) <= GLSLANG_VERSION_PATCH))))) + namespace cc { namespace gfx { @@ -57,10 +62,7 @@ glslang::EShTargetClientVersion getClientVersion(int vulkanMinorVersion) { case 0: return glslang::EShTargetVulkan_1_0; case 1: return glslang::EShTargetVulkan_1_1; case 2: return glslang::EShTargetVulkan_1_2; -#if GLSLANG_VERSION_LESS_OR_EQUAL_TO(11, 10, 0) - // This macro is defined in glslang/build_info.h. This expression means that the - // lib version is greater than or equal to 11.10.0 (not less than or equal to), - // which is very counterintuitive. But it's the only way to do it. +#if CC_GLSLANG_VERSION_GREATOR_OR_EQUAL_TO(11, 10, 0) case 3: return glslang::EShTargetVulkan_1_3; #else case 3: return glslang::EShTargetVulkan_1_2; @@ -77,10 +79,7 @@ glslang::EShTargetLanguageVersion getTargetVersion(int vulkanMinorVersion) { case 0: return glslang::EShTargetSpv_1_0; case 1: return glslang::EShTargetSpv_1_3; case 2: return glslang::EShTargetSpv_1_5; -#if GLSLANG_VERSION_LESS_OR_EQUAL_TO(11, 10, 0) - // This macro is defined in glslang/build_info.h. This expression means that the - // lib version is greater than or equal to 11.10.0 (not less than or equal to), - // which is very counterintuitive. But it's the only way to do it. +#if CC_GLSLANG_VERSION_GREATOR_OR_EQUAL_TO(11, 10, 0) case 3: return glslang::EShTargetSpv_1_6; #else case 3: return glslang::EShTargetSpv_1_5; From 288a14963f6d2c6b09eb746248a5774f04175bcc Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 8 Jan 2024 10:58:28 +0800 Subject: [PATCH 31/32] Update ccbuild to 2.0.3-alpha.19 (#16668) --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 264de2573fe..2e22716b379 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@babel/plugin-proposal-class-properties": "^7.18.6", "@cocos/box2d": "1.0.1", "@cocos/cannon": "1.2.8", - "@cocos/ccbuild": "2.0.3-alpha.18", + "@cocos/ccbuild": "2.0.3-alpha.19", "@cocos/dragonbones-js": "^1.0.1" }, "devDependencies": { @@ -2330,9 +2330,9 @@ } }, "node_modules/@cocos/ccbuild": { - "version": "2.0.3-alpha.18", - "resolved": "https://registry.npmjs.org/@cocos/ccbuild/-/ccbuild-2.0.3-alpha.18.tgz", - "integrity": "sha512-+IS27zu4RfP2prvrVjze5vbowTOfiEZKXoV0L4MCS8lPBP1zBBiUFs0wF6KoCzuiWbvuxl2kF6pa7/4NLnu0Ew==", + "version": "2.0.3-alpha.19", + "resolved": "https://registry.npmjs.org/@cocos/ccbuild/-/ccbuild-2.0.3-alpha.19.tgz", + "integrity": "sha512-KIQ3fjMjk6VF6nUBaDjXbMWT8FXzynympYGmrm8Fdhht9mE0WY7bYIVu0irVJjQTcFgW39LeLev+eXQrKKfTRg==", "dependencies": { "@babel/core": "^7.20.12", "@babel/helper-module-imports": "7.18.6", diff --git a/package.json b/package.json index 3271082b90b..c444159c847 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "@babel/plugin-proposal-class-properties": "^7.18.6", "@cocos/box2d": "1.0.1", "@cocos/cannon": "1.2.8", - "@cocos/ccbuild": "2.0.3-alpha.18", + "@cocos/ccbuild": "2.0.3-alpha.19", "@cocos/dragonbones-js": "^1.0.1" } } From ddd45f96d0b4ddb6b3cffaf5aebf3bf9a14d6c63 Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Wed, 10 Jan 2024 13:40:21 +0800 Subject: [PATCH 32/32] Fix spine can not be paused while working at realTime mode (#16672) * Fix spine can not be paused while running in realTime mode --- cocos/spine/lib/spine-core.d.ts | 1 + cocos/spine/skeleton-cache.ts | 17 +++-- cocos/spine/skeleton-system.ts | 1 - cocos/spine/skeleton.ts | 64 ++++++++++--------- .../spine-wasm/spine-skeleton-instance.cpp | 6 +- .../spine-wasm/spine-skeleton-instance.h | 1 + .../spine-wasm/spine-skeleton-system.cpp | 42 ------------ .../spine-wasm/spine-skeleton-system.h | 15 ----- .../spine-wasm/spine-type-export.cpp | 8 +-- native/external-config.json | 2 +- 10 files changed, 53 insertions(+), 104 deletions(-) delete mode 100644 native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp delete mode 100644 native/cocos/editor-support/spine-wasm/spine-skeleton-system.h diff --git a/cocos/spine/lib/spine-core.d.ts b/cocos/spine/lib/spine-core.d.ts index 8211706e3be..721a3908397 100644 --- a/cocos/spine/lib/spine-core.d.ts +++ b/cocos/spine/lib/spine-core.d.ts @@ -1191,6 +1191,7 @@ declare namespace spine { isDelete: boolean; enable: boolean; setTrackEntryListener: any; + destroy(); initSkeleton(data: SkeletonData); getAnimationState(); setAnimation(trackIndex: number, name: string, loop: boolean): spine.TrackEntry | null; diff --git a/cocos/spine/skeleton-cache.ts b/cocos/spine/skeleton-cache.ts index 4fd1b219b55..869137a5eaa 100644 --- a/cocos/spine/skeleton-cache.ts +++ b/cocos/spine/skeleton-cache.ts @@ -76,7 +76,7 @@ export interface AnimationFrame { } export class AnimationCache { - protected _instance: spine.SkeletonInstance = null!; + protected _instance: spine.SkeletonInstance | null = null; protected _state: spine.AnimationState = null!; protected _skeletonData: spine.SkeletonData = null!; protected _skeleton: spine.Skeleton = null!; @@ -117,7 +117,7 @@ export class AnimationCache { public setSkin (skinName: string): void { if (this._skeleton) this._skeleton.setSkinByName(skinName); - this._instance.setSkin(skinName); + this._instance!.setSkin(skinName); } public setAnimation (animationName: string): void { @@ -134,7 +134,7 @@ export class AnimationCache { } this._maxFrameIdex = Math.floor((animation as any).duration / FrameTime); if (this._maxFrameIdex <= 0) this._maxFrameIdex = 1; - this._instance.setAnimation(0, animationName, false); + this._instance!.setAnimation(0, animationName, false); } public updateToFrame (frameIdx: number): void { @@ -145,8 +145,8 @@ export class AnimationCache { // Solid update frame rate 1/60. this._frameIdx++; this.totalTime += FrameTime; - this._instance.updateAnimation(FrameTime); - const model = this._instance.updateRenderData(); + this._instance!.updateAnimation(FrameTime); + const model = this._instance!.updateRenderData(); this.updateRenderData(this._frameIdx, model); if (this._frameIdx >= this._maxFrameIdex) { this.isCompleted = true; @@ -234,7 +234,7 @@ export class AnimationCache { } } const listener = skeletonInfo?.listener; - this._instance.setAnimation(0, this._animationName!, false); + this._instance!.setAnimation(0, this._animationName!, false); this.bind(listener!); // record cur animation cache @@ -302,7 +302,10 @@ export class AnimationCache { } public destroy (): void { - spine.SkeletonSystem.destroySpineInstance(this._instance); + if (this._instance) { + this._instance.destroy(); + this._instance = null; + } } } diff --git a/cocos/spine/skeleton-system.ts b/cocos/spine/skeleton-system.ts index 3d4a1e40606..109f6b7b3cd 100644 --- a/cocos/spine/skeleton-system.ts +++ b/cocos/spine/skeleton-system.ts @@ -78,7 +78,6 @@ export class SkeletonSystem extends System { if (!this._skeletons) { return; } - if (!EDITOR_NOT_IN_PREVIEW && !JSB) spine.SkeletonSystem.updateAnimation(dt); this._skeletons.forEach((skeleton) => { skeleton.updateAnimation(dt); }); diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 5f47a2cdee9..52ca9bd1f01 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -237,7 +237,7 @@ export class Skeleton extends UIRenderer { protected _runtimeData: spine.SkeletonData | null = null; public _skeleton: spine.Skeleton = null!; - protected _instance: spine.SkeletonInstance = null!; + protected _instance: spine.SkeletonInstance | null = null; protected _state: spine.AnimationState = null!; protected _textures: Texture2D[] = []; private _skeletonInfo: SkeletonCacheItemInfo | null = null; @@ -491,7 +491,7 @@ export class Skeleton extends UIRenderer { set premultipliedAlpha (v: boolean) { if (v !== this._premultipliedAlpha) { this._premultipliedAlpha = v; - this._instance.setPremultipliedAlpha(v); + this._instance!.setPremultipliedAlpha(v); this.markForUpdateRenderData(); } } @@ -710,8 +710,9 @@ export class Skeleton extends UIRenderer { //if (this._cacheMode == AnimationCacheMode.PRIVATE_CACHE) this._animCache?.destroy(); this._animCache = null; SkeletonSystem.getInstance().remove(this); - if (!JSB) { - spine.SkeletonSystem.destroySpineInstance(this._instance); + if (!JSB && this._instance) { + this._instance.destroy(); + this._instance = null; } this._destroySkeletonInfo(this._skeletonCache); this._skeletonCache = null; @@ -812,9 +813,9 @@ export class Skeleton extends UIRenderer { this._skeleton = this._skeletonInfo.skeleton!; } } else { - this._skeleton = this._instance.initSkeleton(skeletonData); - this._state = this._instance.getAnimationState(); - this._instance.setPremultipliedAlpha(this._premultipliedAlpha); + this._skeleton = this._instance!.initSkeleton(skeletonData); + this._state = this._instance!.getAnimationState(); + this._instance!.setPremultipliedAlpha(this._premultipliedAlpha); } // Recreate render data and mark dirty this._flushAssembler(); @@ -929,7 +930,7 @@ export class Skeleton extends UIRenderer { } } else { this._animationName = name; - trackEntry = this._instance.setAnimation(trackIndex, name, loop); + trackEntry = this._instance!.setAnimation(trackIndex, name, loop); } this.markForUpdateRenderData(); return trackEntry; @@ -1007,7 +1008,7 @@ export class Skeleton extends UIRenderer { */ public setSkin (name: string): void { if (this._skeleton) this._skeleton.setSkinByName(name); - this._instance.setSkin(name); + this._instance!.setSkin(name); if (this.isAnimationCached()) { if (this._animCache) { this._animCache.setSkin(name); @@ -1050,6 +1051,8 @@ export class Skeleton extends UIRenderer { return; } this._updateCache(dt); + } else { + this._instance!.updateAnimation(dt); } } @@ -1112,7 +1115,7 @@ export class Skeleton extends UIRenderer { const model = this._curFrame.model; return model; } else { - const model = this._instance.updateRenderData(); + const model = this._instance!.updateRenderData(); return model; } } @@ -1444,7 +1447,7 @@ export class Skeleton extends UIRenderer { return; } if (this._state) { - this._instance.setMix(fromAnimation, toAnimation, duration); + this._instance!.setMix(fromAnimation, toAnimation, duration); //this._state.data.setMix(fromAnimation, toAnimation, duration); } } @@ -1577,7 +1580,7 @@ export class Skeleton extends UIRenderer { this.destroyRenderData(); if (!JSB) { if (!this.isAnimationCached()) { - this._instance.setUseTint(this._useTint); + this._instance!.setUseTint(this._useTint); } } if (this._assembler && this._skeleton) { @@ -1607,7 +1610,7 @@ export class Skeleton extends UIRenderer { if (this.isAnimationCached()) { warn('Debug bones or slots is invalid in cached mode'); } else if (!JSB) { - this._instance.setDebugMode(true); + this._instance!.setDebugMode(true); } } else if (this._debugRenderer) { this._debugRenderer.node.destroy(); @@ -1655,7 +1658,7 @@ export class Skeleton extends UIRenderer { const r = this._color.r / 255.0; const g = this._color.g / 255.0; const b = this._color.b / 255.0; - this._instance.setColor(r, g, b, a); + this._instance!.setColor(r, g, b, a); } /** @@ -1664,6 +1667,9 @@ export class Skeleton extends UIRenderer { * @param effectDelegate @en Vertex effect delegate. @zh 顶点特效代理。 */ public setVertexEffectDelegate (effectDelegate: VertexEffectDelegate | null | undefined): void { + if (!this._instance) { + return; + } if (!effectDelegate) { this._instance.clearEffect(); return; @@ -1692,7 +1698,7 @@ export class Skeleton extends UIRenderer { public setStartListener (listener: TrackListener): void { this._ensureListener(); const listenerID = TrackEntryListeners.addListener(listener); - this._instance.setListener(listenerID, spine.EventType.start); + this._instance!.setListener(listenerID, spine.EventType.start); this._listener!.start = listener; } @@ -1704,7 +1710,7 @@ export class Skeleton extends UIRenderer { public setInterruptListener (listener: TrackListener): void { this._ensureListener(); const listenerID = TrackEntryListeners.addListener(listener); - this._instance.setListener(listenerID, spine.EventType.interrupt); + this._instance!.setListener(listenerID, spine.EventType.interrupt); this._listener!.interrupt = listener; } @@ -1716,7 +1722,7 @@ export class Skeleton extends UIRenderer { public setEndListener (listener: TrackListener): void { this._ensureListener(); const listenerID = TrackEntryListeners.addListener(listener); - this._instance.setListener(listenerID, spine.EventType.end); + this._instance!.setListener(listenerID, spine.EventType.end); this._listener!.end = listener; } @@ -1728,7 +1734,7 @@ export class Skeleton extends UIRenderer { public setDisposeListener (listener: TrackListener): void { this._ensureListener(); const listenerID = TrackEntryListeners.addListener(listener); - this._instance.setListener(listenerID, spine.EventType.dispose); + this._instance!.setListener(listenerID, spine.EventType.dispose); this._listener!.dispose = listener; } @@ -1740,7 +1746,7 @@ export class Skeleton extends UIRenderer { public setCompleteListener (listener: TrackListener): void { this._ensureListener(); const listenerID = TrackEntryListeners.addListener(listener); - this._instance.setListener(listenerID, spine.EventType.complete); + this._instance!.setListener(listenerID, spine.EventType.complete); this._listener!.complete = listener; } @@ -1752,7 +1758,7 @@ export class Skeleton extends UIRenderer { public setEventListener (listener: TrackListener2): void { this._ensureListener(); const listenerID = TrackEntryListeners.addListener(listener); - this._instance.setListener(listenerID, spine.EventType.event); + this._instance!.setListener(listenerID, spine.EventType.event); this._listener!.event = listener; } @@ -1763,7 +1769,7 @@ export class Skeleton extends UIRenderer { * @param listener @en Listener for registering callback functions. @zh 监听器对象,可注册回调方法。 */ public setTrackStartListener (entry: spine.TrackEntry, listener: TrackListener): void { - TrackEntryListeners.getListeners(entry, this._instance).start = listener; + TrackEntryListeners.getListeners(entry, this._instance!).start = listener; } /** @@ -1773,7 +1779,7 @@ export class Skeleton extends UIRenderer { * @param listener @en Listener for registering callback functions. @zh 监听器对象,可注册回调方法。 */ public setTrackInterruptListener (entry: spine.TrackEntry, listener: TrackListener): void { - TrackEntryListeners.getListeners(entry, this._instance).interrupt = listener; + TrackEntryListeners.getListeners(entry, this._instance!).interrupt = listener; } /** @@ -1783,7 +1789,7 @@ export class Skeleton extends UIRenderer { * @param listener @en Listener for registering callback functions. @zh 监听器对象,可注册回调方法。 */ public setTrackEndListener (entry: spine.TrackEntry, listener: TrackListener): void { - TrackEntryListeners.getListeners(entry, this._instance).end = listener; + TrackEntryListeners.getListeners(entry, this._instance!).end = listener; } /** @@ -1793,7 +1799,7 @@ export class Skeleton extends UIRenderer { * @param listener @en Listener for registering callback functions. @zh 监听器对象,可注册回调方法。 */ public setTrackDisposeListener (entry: spine.TrackEntry, listener: TrackListener): void { - TrackEntryListeners.getListeners(entry, this._instance).dispose = listener; + TrackEntryListeners.getListeners(entry, this._instance!).dispose = listener; } /** @@ -1810,7 +1816,7 @@ export class Skeleton extends UIRenderer { // this._instance.setListener(listenerID, spine.EventType.event); // this._listener!.event = listener; }; - TrackEntryListeners.getListeners(entry, this._instance).complete = onComplete; + TrackEntryListeners.getListeners(entry, this._instance!).complete = onComplete; } /** @@ -1820,14 +1826,14 @@ export class Skeleton extends UIRenderer { * @param listener @en Listener for registering callback functions. @zh 监听器对象,可注册回调方法。 */ public setTrackEventListener (entry: spine.TrackEntry, listener: TrackListener|TrackListener2): void { - TrackEntryListeners.getListeners(entry, this._instance).event = listener; + TrackEntryListeners.getListeners(entry, this._instance!).event = listener; } /** * @engineInternal */ public getDebugShapes (): any { - return this._instance.getDebugShapes(); + return this._instance!.getDebugShapes(); } /** @@ -1852,7 +1858,7 @@ export class Skeleton extends UIRenderer { const width = tex2d.width; const height = tex2d.height; const createNewAttachment = createNew || false; - this._instance.resizeSlotRegion(slotName, width, height, createNewAttachment); + this._instance!.resizeSlotRegion(slotName, width, height, createNewAttachment); if (!this._slotTextures) this._slotTextures = new Map(); let textureID = 0; this._slotTextures.forEach((value, key) => { @@ -1862,7 +1868,7 @@ export class Skeleton extends UIRenderer { textureID = ++_slotTextureID; this._slotTextures.set(textureID, tex2d); } - this._instance.setSlotTexture(slotName, textureID); + this._instance!.setSlotTexture(slotName, textureID); } private _destroySkeletonInfo (skeletonCache: SkeletonCache | null): void { diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp index 08192bf0aea..8b171a4c750 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp @@ -5,7 +5,6 @@ #include "spine-mesh-data.h" #include "spine-wasm.h" #include "util-function.h" -#include "spine-skeleton-system.h" SlotMesh globalMesh(nullptr, nullptr, 0, 0); @@ -34,7 +33,6 @@ static void trackEntryCallback(AnimationState *state, EventType type, TrackEntry SpineSkeletonInstance::SpineSkeletonInstance() { _model = new SpineModel(); - SpineSkeletonSystem::addSpineInstance(this); } SpineSkeletonInstance::~SpineSkeletonInstance() { @@ -46,6 +44,10 @@ SpineSkeletonInstance::~SpineSkeletonInstance() { if (_model) delete _model; } +void SpineSkeletonInstance::destroy() { + delete this; +} + Skeleton *SpineSkeletonInstance::initSkeleton(SkeletonData *data) { if (_clipper) delete _clipper; if (_animState) delete _animState; diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h index cb8190cbf1c..c1b53149ebf 100644 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h +++ b/native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h @@ -58,6 +58,7 @@ class SpineSkeletonInstance { std::vector &getDebugShapes(); void resizeSlotRegion(const std::string &slotName, uint32_t width, uint32_t height, bool createNew = false); void setSlotTexture(const std::string &slotName, uint32_t index); + void destroy(); bool isCache{false}; bool enable{true}; float dtRate{1.0F}; diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp b/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp deleted file mode 100644 index 5c2ead7f4a1..00000000000 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-system.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "spine-skeleton-system.h" -#include "spine-skeleton-instance.h" -#include "spine-mesh-data.h" - -using namespace spine; - -std::vector SpineSkeletonSystem::vectorSpines; - -void SpineSkeletonSystem::updateAnimation(float deltaTime) { - auto count = static_cast(vectorSpines.size()); - for (int i = count - 1; i >= 0; --i) { - SpineSkeletonInstance* spineInstance = vectorSpines[i]; - if(!spineInstance->enable) continue; - if (!spineInstance->isCache) { - spineInstance->updateAnimation(deltaTime); - } - } -} - -int SpineSkeletonSystem::getCount() { - auto count = vectorSpines.size(); - return count; -} - -void SpineSkeletonSystem::updateRenderData() { - SpineMeshData::reset(); -} - -void SpineSkeletonSystem::addSpineInstance(SpineSkeletonInstance* instance) { - if(vectorSpines.size() == vectorSpines.capacity()){ - vectorSpines.reserve(vectorSpines.size() + 20); - } - vectorSpines.push_back(instance); -} - -void SpineSkeletonSystem::destroySpineInstance(SpineSkeletonInstance* instance) { - auto it = std::find(vectorSpines.begin(), vectorSpines.end(), instance); - if (it != vectorSpines.end()) { - vectorSpines.erase(it); - delete instance; - } -} \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/spine-skeleton-system.h b/native/cocos/editor-support/spine-wasm/spine-skeleton-system.h deleted file mode 100644 index 6be9cd9e860..00000000000 --- a/native/cocos/editor-support/spine-wasm/spine-skeleton-system.h +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "spine-skeleton-instance.h" - -using namespace spine; -class SpineSkeletonSystem -{ -public: - static void updateAnimation(float deltaTime); - static void updateRenderData(); - static int getCount(); - static void addSpineInstance(SpineSkeletonInstance* instance); - static void destroySpineInstance(SpineSkeletonInstance* instance); -private: - static std::vector vectorSpines; -}; \ No newline at end of file diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 83133336b98..4fc0eac3c8d 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -3,7 +3,6 @@ #include #include #include -#include "spine-skeleton-system.h" #include "spine-skeleton-instance.h" #include "spine-wasm.h" #include "Vector2.h" @@ -1607,13 +1606,8 @@ EMSCRIPTEN_BINDINGS(spine) { .function("setDebugMode", &SpineSkeletonInstance::setDebugMode) .function("getDebugShapes", &SpineSkeletonInstance::getDebugShapes) .function("resizeSlotRegion", &SpineSkeletonInstance::resizeSlotRegion) + .function("destroy", &SpineSkeletonInstance::destroy) .function("setSlotTexture", &SpineSkeletonInstance::setSlotTexture); - - class_("SkeletonSystem") - .class_function("getCount", &SpineSkeletonSystem::getCount) - .class_function("updateAnimation", &SpineSkeletonSystem::updateAnimation) - .class_function("updateRenderData", &SpineSkeletonSystem::updateRenderData) - .class_function("destroySpineInstance", &SpineSkeletonSystem::destroySpineInstance, allow_raw_pointers()); } EMSCRIPTEN_BINDINGS(cocos_spine) { diff --git a/native/external-config.json b/native/external-config.json index 89a1e20ef94..78ca7978643 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-22" + "checkout": "v3.8.2-23" } } \ No newline at end of file