Compare commits

...

13 Commits

Author SHA1 Message Date
hyde zhou 68552314c0 bump version to 4.0.0-alpha.32 (#320) 2026-09-01 21:13:19 +08:00
zxx43 550eb15641 add line updateColor function (#317)
* add line setColor function

* fix eslint

* modify setColor to updateColor
2026-08-31 11:56:37 +08:00
Ming c438c2d3f8 fix(rendering): compute render pass merge info in render graph order (#314) 2026-08-29 17:39:20 +08:00
zxx43 f5eaf97ce7 add opacity calculation to Particle System 2D (#307)
* add opacity calculation to Particle System 2D

* modify format
2026-08-25 18:37:08 +08:00
zxx43 69d3d6033a fix message error (#304) 2026-08-24 11:13:30 +08:00
yangchao 469614cf0b fix ios build problem (#292) 2026-08-23 12:01:54 +08:00
Cocos Robot f81094f226 [ci skip][AUTO]: Automated clang-format update: 6c156997c2 (#293) (#301)
Co-authored-by: cocos-robot <cocos-robot@cocos.com>
2026-08-23 11:07:26 +08:00
Ming 825362fac1 fix(webgl): correct buffer-to-texture extent height calculation (#303)
Use regionTexExtentHeight instead of regionTexExtentWidth when calculating copied texture extents to prevent incorrect row and slice strides.

Co-authored-by: vanitynie <vanitynie@qq.com>
2026-08-21 12:27:25 +08:00
ChiaNing 609512f8da fix(ui):keep destroy widgets out of the widget's active list (#302) 2026-08-21 10:04:48 +08:00
troublemaker52025 09b63786f4 fix(legacy): sync instanced buffer batching optimization to native (#293) 2026-08-20 15:56:12 +08:00
MagicXHouse 2b7b438768 Fix: Fixed the issue where custom pipeline profiler were not displaying. (#295) 2026-08-20 11:26:22 +08:00
xubing0906 6b5c8556a2 Fix Builtin reflection probe culling by passing the probe context to … (#186) 2026-08-19 17:25:21 +08:00
昌敦伟 ff436d6a27 fix: balance Texture2D image dependency references (#267) 2026-08-19 16:05:59 +08:00
27 changed files with 339 additions and 149 deletions
+1 -1
View File
@@ -3983,4 +3983,4 @@ Spine version not supported.
### 16420
Start time must bigger than end time.
End time must bigger than start time.
+3 -2
View File
@@ -76,10 +76,11 @@ simpleTextureProto._onGFXTextureUpdated = function (gfxTexture) {
simpleTextureProto._onAfterAssignImage = function (image) {
if (macro.CLEANUP_IMAGE_CACHE) {
const deps = dependUtil.getDeps(this._uuid);
const index = deps.indexOf(image._uuid);
if (index !== -1) {
let index = deps.indexOf(image._uuid);
while (index !== -1) {
js.array.fastRemoveAt(deps, index);
image.decRef();
index = deps.indexOf(image._uuid);
}
}
};
+4 -2
View File
@@ -194,10 +194,12 @@ export class SimpleTexture extends TextureBase {
if (macro.CLEANUP_IMAGE_CACHE) {
const deps = dependUtil.getDeps(this._uuid);
const index = deps.indexOf(image._uuid);
if (index !== -1) {
let index = deps.indexOf(image._uuid);
while (index !== -1) {
js.array.fastRemoveAt(deps, index);
image.decRef();
// The same UUID may occur more than once; find the next dependency edge.
index = deps.indexOf(image._uuid);
}
}
}
+2 -2
View File
@@ -2702,7 +2702,7 @@ export function WebGLCmdFuncCopyBuffersToTexture (
offset.x = regionTexOffset.x === 0 ? 0 : alignTo(regionTexOffset.x, blockSizeWidth);
offset.y = regionTexOffset.y === 0 ? 0 : alignTo(regionTexOffset.y, blockSizeHeight);
extent.width = regionTexExtentWidth < blockSizeWidth ? regionTexExtentWidth : alignTo(regionTexExtentWidth, blockSizeWidth);
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentWidth
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentHeight
: alignTo(regionTexExtentHeight, blockSizeHeight);
stride.width = regionBuffStride > 0 ? regionBuffStride : extent.width;
stride.height = region.buffTexHeight > 0 ? region.buffTexHeight : extent.height;
@@ -2773,7 +2773,7 @@ export function WebGLCmdFuncCopyBuffersToTexture (
offset.x = regionTexOffset.x === 0 ? 0 : alignTo(regionTexOffset.x, blockSizeWidth);
offset.y = regionTexOffset.y === 0 ? 0 : alignTo(regionTexOffset.y, blockSizeHeight);
extent.width = regionTexExtentWidth < blockSizeWidth ? regionTexExtentWidth : alignTo(regionTexExtentWidth, blockSizeWidth);
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentWidth
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentHeight
: alignTo(regionTexExtentHeight, blockSizeHeight);
stride.width = region.buffStride > 0 ? region.buffStride : extent.width;
stride.height = region.buffTexHeight > 0 ? region.buffTexHeight : extent.height;
+4 -4
View File
@@ -2811,7 +2811,7 @@ export function WebGL2CmdFuncCopyBuffersToTexture (
offset.x = regionTexOffset.x === 0 ? 0 : alignTo(regionTexOffset.x, blockSizeWidth);
offset.y = regionTexOffset.y === 0 ? 0 : alignTo(regionTexOffset.y, blockSizeHeight);
extent.width = regionTexExtentWidth < blockSizeWidth ? regionTexExtentWidth : alignTo(regionTexExtentWidth, blockSizeWidth);
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentWidth
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentHeight
: alignTo(regionTexExtentHeight, blockSizeHeight);
stride.width = regionBuffStride > 0 ? regionBuffStride : extent.width;
stride.height = region.buffTexHeight > 0 ? region.buffTexHeight : extent.height;
@@ -2883,7 +2883,7 @@ export function WebGL2CmdFuncCopyBuffersToTexture (
offset.x = regionTexOffset.x === 0 ? 0 : alignTo(regionTexOffset.x, blockSizeWidth);
offset.y = regionTexOffset.y === 0 ? 0 : alignTo(regionTexOffset.y, blockSizeHeight);
extent.width = regionTexExtentWidth < blockSizeWidth ? regionTexExtentWidth : alignTo(regionTexExtentWidth, blockSizeWidth);
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentWidth
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentHeight
: alignTo(regionTexExtentHeight, blockSizeHeight);
extent.depth = 1;
stride.width = regionBuffStride > 0 ? regionBuffStride : extent.width;
@@ -2965,7 +2965,7 @@ export function WebGL2CmdFuncCopyBuffersToTexture (
offset.y = regionTexOffset.y === 0 ? 0 : alignTo(regionTexOffset.y, blockSizeHeight);
offset.z = regionTexOffset.z;
extent.width = regionTexExtentWidth < blockSizeWidth ? regionTexExtentWidth : alignTo(regionTexExtentWidth, blockSizeWidth);
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentWidth
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentHeight
: alignTo(regionTexExtentHeight, blockSizeHeight);
extent.depth = regionTexExtent.depth;
stride.width = regionBuffStride > 0 ? regionBuffStride : extent.width;
@@ -3043,7 +3043,7 @@ export function WebGL2CmdFuncCopyBuffersToTexture (
offset.x = regionTexOffset.x === 0 ? 0 : alignTo(regionTexOffset.x, blockSizeWidth);
offset.y = regionTexOffset.y === 0 ? 0 : alignTo(regionTexOffset.y, blockSizeHeight);
extent.width = regionTexExtentWidth < blockSizeWidth ? regionTexExtentWidth : alignTo(regionTexExtentWidth, blockSizeWidth);
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentWidth
extent.height = regionTexExtentHeight < blockSizeHeight ? regionTexExtentHeight
: alignTo(regionTexExtentHeight, blockSizeHeight);
stride.width = regionBuffStride > 0 ? regionBuffStride : extent.width;
stride.height = region.buffTexHeight > 0 ? region.buffTexHeight : extent.height;
+27 -8
View File
@@ -52,6 +52,7 @@ class Particle {
public pos = new Vec2(0, 0);
public startPos = new Vec2(0, 0);
public color = new Color(0, 0, 0, 255);
public curColor = { r: 0, g: 0, b: 0, a: 255 };
public deltaColor = { r: 0, g: 0, b: 0, a: 255 };
public size = 0;
public deltaSize = 0;
@@ -81,6 +82,8 @@ const pool = new ParticlePool((par: Particle): void => {
par.pos.set(Vec2.ZERO);
par.startPos.set(Vec2.ZERO);
par.color.set(0, 0, 0, 255);
par.curColor.r = par.curColor.g = par.curColor.b = 0;
par.curColor.a = 255;
par.deltaColor.r = par.deltaColor.g = par.deltaColor.b = 0;
par.deltaColor.a = 255;
par.size = 0;
@@ -111,6 +114,7 @@ export class Simulator {
private elapsed = 0;
private emitCounter = 0;
private _worldRotation = 0;
private _parentAlpha = 0.0;
private declare sys: ParticleSystem2D;
constructor (system) {
@@ -169,10 +173,10 @@ export class Simulator {
const endColor = psys.endColor;
const endColorVar = psys.endColorVar;
particle.color.r = sr = clamp(startColor.r + startColorVar.r * (random() - 0.5) * 2, 0, 255);
particle.color.g = sg = clamp(startColor.g + startColorVar.g * (random() - 0.5) * 2, 0, 255);
particle.color.b = sb = clamp(startColor.b + startColorVar.b * (random() - 0.5) * 2, 0, 255);
particle.color.a = sa = clamp(startColor.a + startColorVar.a * (random() - 0.5) * 2, 0, 255);
particle.curColor.r = sr = clamp(startColor.r + startColorVar.r * (random() - 0.5) * 2, 0, 255);
particle.curColor.g = sg = clamp(startColor.g + startColorVar.g * (random() - 0.5) * 2, 0, 255);
particle.curColor.b = sb = clamp(startColor.b + startColorVar.b * (random() - 0.5) * 2, 0, 255);
particle.curColor.a = sa = clamp(startColor.a + startColorVar.a * (random() - 0.5) * 2, 0, 255);
particle.deltaColor.r = (clamp(endColor.r + endColorVar.r * (random() - 0.5) * 2, 0, 255) - sr) / timeToLive;
particle.deltaColor.g = (clamp(endColor.g + endColorVar.g * (random() - 0.5) * 2, 0, 255) - sg) / timeToLive;
particle.deltaColor.b = (clamp(endColor.b + endColorVar.b * (random() - 0.5) * 2, 0, 255) - sb) / timeToLive;
@@ -329,6 +333,14 @@ export class Simulator {
Vec4.toArray(vbuf, _col, offset + 32);
}
private _updateColor (): void {
const selfNode = this.sys.node;
const parentNode = selfNode.parent;
const uiProps = selfNode._uiProps;
const parentOpacity = parentNode ? parentNode._uiProps.opacity : 1.0;
this._parentAlpha = uiProps.localOpacity * parentOpacity;
}
public step (dt: number): void {
const assembler = this.sys.assembler as Particle2DAssembler;
const psys = this.sys;
@@ -379,6 +391,8 @@ export class Simulator {
this.updateUVs();
}
this._updateColor();
// Used to reduce memory allocation / creation within the loop
let particleIdx = 0;
while (particleIdx < particles.length) {
@@ -431,10 +445,15 @@ export class Simulator {
}
// color
particle.color.r += particle.deltaColor.r * dt;
particle.color.g += particle.deltaColor.g * dt;
particle.color.b += particle.deltaColor.b * dt;
particle.color.a += particle.deltaColor.a * dt;
particle.curColor.r += particle.deltaColor.r * dt;
particle.curColor.g += particle.deltaColor.g * dt;
particle.curColor.b += particle.deltaColor.b * dt;
particle.curColor.a += particle.deltaColor.a * dt;
particle.color.r = particle.curColor.r;
particle.color.g = particle.curColor.g;
particle.color.b = particle.curColor.b;
particle.color.a = particle.curColor.a * this._parentAlpha;
// size
particle.size += particle.deltaSize * dt;
+10 -1
View File
@@ -25,7 +25,7 @@
import { ccclass, help, executeInEditMode, menu, tooltip, displayOrder, type, serializable,
range, visible, override, displayName } from 'cc.decorator';
import { Material, Texture2D } from '../asset/assets';
import { Vec3, cclegacy, Vec4, Vec2, CCBoolean } from '../core';
import { Vec3, cclegacy, Vec4, Vec2, CCBoolean, Color } from '../core';
import { LineModel } from './models/line-model';
import { builtinResMgr } from '../asset/asset-manager';
import CurveRange from './animator/curve-range';
@@ -296,6 +296,15 @@ export class Line extends ModelRenderer {
}
}
public updateColor (): void {
if (this._color) {
if (this._models[0]) {
const lineModel = this._models[0] as LineModel;
lineModel.addLineVertexData(this._positions, this._width, this._color);
}
}
}
protected _onMaterialModified (index: number, material: Material | null): void {
super._onMaterialModified(index, material);
const matIns = this.getMaterialInstance(0);
-2
View File
@@ -22,7 +22,6 @@
THE SOFTWARE.
****************************************************************************/
import { Buffer, Framebuffer, Texture, Viewport } from '../../gfx';
import { genHashValue } from './define';
import { VectorGraphColorMap } from './effect';
import { DefaultVisitor, depthFirstSearch, ReferenceGraphView } from './graph';
import { LayoutGraphData } from './layout-graph';
@@ -199,7 +198,6 @@ class PassVisitor implements RenderGraphVisitor {
resourceGraph.visitVertex(this._resVisitor, vertID);
}
}
genHashValue(pass);
}
}
applyID (id: number, resId: number): void {
+6 -2
View File
@@ -195,10 +195,13 @@ function sceneCulling (
}
models.push(model);
} else if (probe.probeType === ProbeType.CUBE) {
if (!wBounds || !model.bakeToReflectionProbe) {
continue;
}
if (!isVisible(model, visibility)) {
continue;
}
if (wBounds && isIntersectAABB(wBounds, probe.boundingBox!)) {
if (isIntersectAABB(wBounds, probe.boundingBox!)) {
continue;
}
models.push(model);
@@ -475,7 +478,8 @@ export class SceneCulling {
);
// Get or create render queue
const renderQueueID = this.getOrCreateRenderQueue(renderQueueKey, sceneData.flags, sceneData.camera);
const renderCamera = sceneData.light.probe ? sceneData.light.probe.camera : sceneData.camera;
const renderQueueID = this.getOrCreateRenderQueue(renderQueueKey, sceneData.flags, renderCamera);
// add render queue query
const renderQueueQuery = this.cullingPools.renderQueueQueryRecycle.add();
+23 -7
View File
@@ -258,9 +258,19 @@ export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuild
addSceneOfCamera (camera: Camera, light: LightInfo, sceneFlags = SceneFlags.NONE, name = 'Camera'): void {
const lightTarget = light.light;
this.addScene(camera, sceneFlags, lightTarget);
const scene = light.probe?.node?.scene?.renderScene || undefined;
this._addScene(camera, sceneFlags, lightTarget, scene, light);
}
addScene (camera: Camera, sceneFlags = SceneFlags.NONE, light: Light | undefined | null = null, scene: RenderScene | undefined = undefined): SceneBuilder {
return this._addScene(camera, sceneFlags, light, scene);
}
private _addScene (
camera: Camera,
sceneFlags: SceneFlags,
light: Light | undefined | null,
scene: RenderScene | undefined,
lightInfo: LightInfo | null = null,
): SceneBuilder {
const sceneData = renderGraphPool.createSceneData(
scene || camera.scene,
camera,
@@ -268,6 +278,9 @@ export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuild
light && !(sceneFlags & SceneFlags.SHADOW_CASTER) ? CullingFlags.CAMERA_FRUSTUM | CullingFlags.LIGHT_BOUNDS : CullingFlags.CAMERA_FRUSTUM,
light,
);
if (lightInfo) {
sceneData.light.reset(lightInfo.light, lightInfo.level, lightInfo.culledByLight, lightInfo.probe);
}
const renderData = renderGraphPool.createRenderData();
const sceneId = this._renderGraph.addVertex<RenderGraphValue.Scene>(RenderGraphValue.Scene, sceneData, 'Scene', '', renderData, !DEBUG, this._vertID);
if (!(sceneFlags & SceneFlags.NON_BUILTIN)) {
@@ -1650,13 +1663,16 @@ export class WebPipeline extends WebSetter implements BasicPipeline {
this._compiler = new Compiler(this, this._renderGraph, this._resourceGraph, this._lg);
}
this._compiler.compile(this._renderGraph);
} else {
this._renderGraph.x.forEach((vert) => {
if (vert.t === RenderGraphValue.RasterPass) {
genHashValue(vert.j as RasterPass);
}
});
}
this._renderGraph.x.forEach((vert, v) => {
if (vert.t !== RenderGraphValue.RasterPass) {
return;
}
if (DEBUG && !this._renderGraph!.getValid(v)) {
return;
}
genHashValue(vert.j as RasterPass);
});
}
execute (): void {
+18 -2
View File
@@ -131,6 +131,11 @@ export class InstancedBuffer {
stride,
shader,
descriptorSet,
lightingMap,
useReflectionProbeType,
reflectionProbeCubemap,
reflectionProbePlanarMap,
reflectionProbeBlendCubemap,
);
}
@@ -157,14 +162,20 @@ export class InstancedBuffer {
stride: number,
shader: Shader,
descriptorSet: DescriptorSet,
lightingMap: Texture,
useReflectionProbeType: number,
reflectionProbeCubemap: Texture,
reflectionProbePlanarMap: Texture,
reflectionProbeBlendCubemap: Texture | null,
): void {
const newSize = stride * INITIAL_CAPACITY;
const vb = this._device.createBuffer(new BufferInfo(
BufferUsageBit.VERTEX | BufferUsageBit.TRANSFER_DST,
MemoryUsageBit.HOST | MemoryUsageBit.DEVICE,
stride * INITIAL_CAPACITY,
newSize,
stride,
));
const data = new Uint8Array(stride * INITIAL_CAPACITY);
const data = new Uint8Array(newSize);
const vertexBuffers = sourceIA.vertexBuffers.slice();
const attributes = sourceIA.attributes.slice();
const indexBuffer = sourceIA.indexBuffer;
@@ -188,6 +199,11 @@ export class InstancedBuffer {
stride,
shader,
descriptorSet,
lightingMap,
reflectionProbeCubemap,
reflectionProbePlanarMap,
useReflectionProbeType,
reflectionProbeBlendCubemap,
} as IInstancedItem;
this.instances.push(instance);
let mappedInstances = this._instanceMap.get(key);
+1 -1
View File
@@ -204,7 +204,7 @@ function align (node: Node, widget: Widget): void {
// TODO: type is hack, Change to the type actually used (Node or BaseNode) when BaseNode complete
function visitNode (node: any): void {
const widget = node.getComponent(Widget);
if (widget && widget.enabled) {
if (widget && widget.enabled && cclegacy.isValid(widget, true)) {
if (DEV) {
widget._validateTargetInDEV();
}
+3
View File
@@ -852,6 +852,9 @@ export class Widget extends Component {
}
public onDestroy (): void {
// `onDisable` is skipped when the component was never enabled by the scheduler
// (`IsOnEnableCalled` unset), so unregister here as well.
cclegacy._widgetManager?.remove(this);
this._removeParentEvent();
}
@@ -669,8 +669,8 @@ export class BuiltinForwardPassBuilder implements rendering.PipelinePassBuilder
// Rendering
const probePass = ppl.addRenderPass(width, height, 'default');
probePass.name = `PlanarReflectionProbe${probeID}`;
this._buildReflectionProbePass(probePass, cameraConfigs, id, reflectionCamera,
colorName, depthStencilName, mainLight, scene);
this._buildReflectionProbePass(probePass, cameraConfigs, id, reflectionCamera, probe,
colorName, depthStencilName, mainLight);
} else if (EDITOR) {
for (let faceIdx = 0; faceIdx < probe.bakedCubeTextures.length; faceIdx++) {
probe.updateCameraDir(faceIdx);
@@ -686,8 +686,8 @@ export class BuiltinForwardPassBuilder implements rendering.PipelinePassBuilder
// Rendering
const probePass = ppl.addRenderPass(width, height, 'default');
probePass.name = `CubeProbe${probeID}${faceIdx}`;
this._buildReflectionProbePass(probePass, cameraConfigs, id, probe.camera,
colorName, depthStencilName, mainLight, scene);
this._buildReflectionProbePass(probePass, cameraConfigs, id, probe.camera, probe,
colorName, depthStencilName, mainLight);
}
probe.needRender = false;
}
@@ -702,10 +702,10 @@ export class BuiltinForwardPassBuilder implements rendering.PipelinePassBuilder
cameraConfigs: Readonly<CameraConfigs & ForwardPassConfigs>,
id: number,
camera: renderer.scene.Camera,
probe: renderer.scene.ReflectionProbe,
colorName: string,
depthStencilName: string,
mainLight: renderer.scene.DirectionalLight | null,
scene: renderer.RenderScene | null = null,
): void {
const QueueHint = rendering.QueueHint;
const SceneFlags = rendering.SceneFlags;
@@ -749,11 +749,11 @@ export class BuiltinForwardPassBuilder implements rendering.PipelinePassBuilder
// TODO(zhouzhenglong): Separate OPAQUE and MASK queue
// add opaque and mask queue
const lightInfo = new rendering.LightInfo(mainLight || null, 0, false, probe);
pass.addQueue(QueueHint.NONE, 'reflect-map') // Currently we put OPAQUE and MASK into one queue, so QueueHint is NONE
.addScene(camera,
SceneFlags.OPAQUE | SceneFlags.MASK | SceneFlags.REFLECTION_PROBE,
mainLight || undefined,
scene ? scene : undefined);
.addSceneOfCamera(camera,
lightInfo,
SceneFlags.OPAQUE | SceneFlags.MASK | SceneFlags.REFLECTION_PROBE);
}
private _addForwardRadiancePasses(
ppl: rendering.BasicPipeline,
+1 -1
View File
@@ -623,7 +623,7 @@ ccstd::unordered_map<uint32_t, ccstd::string> debugInfos = {
{ 16417, "'clearTrack' interface can not be invoked in cached mode." },
{ 16418, "Debug bones or slots is invalid in cached mode." },
{ 16419, "Spine version not supported." },
{ 16420, "Start time must bigger than end time." },
{ 16420, "End time must bigger than start time." },
};
}//namespace cc
@@ -22,8 +22,11 @@
THE SOFTWARE.
****************************************************************************/
#include "InstancedBuffer.h"
#include <algorithm>
#include "Define.h"
#include "InstancedBuffer.h"
#include "base/StringUtil.h"
#include "gfx-base/GFXBuffer.h"
#include "gfx-base/GFXCommandBuffer.h"
#include "gfx-base/GFXDescriptorSet.h"
@@ -49,6 +52,7 @@ void InstancedBuffer::destroy() {
CC_FREE(instance.data);
}
_instances.clear();
_instancesMap.clear();
}
void InstancedBuffer::merge(scene::SubModel *subModel, uint32_t passIdx) {
@@ -66,9 +70,9 @@ void InstancedBuffer::merge(scene::SubModel *subModel, uint32_t passIdx, gfx::Sh
auto *lightingMap = descriptorSet->getTexture(LIGHTMAPTEXTURE::BINDING);
auto *reflectionProbeCubemap = descriptorSet->getTexture(REFLECTIONPROBECUBEMAP::BINDING);
auto *reflectionProbePlanarMap = descriptorSet->getTexture(REFLECTIONPROBEPLANARMAP::BINDING);
gfx::Texture *reflectionProbeBlendCubemap = ENABLE_PROBE_BLEND
? descriptorSet->getTexture(REFLECTIONPROBEBLENDCUBEMAP::BINDING)
: nullptr;
auto *reflectionProbeBlendCubemap = ENABLE_PROBE_BLEND
? descriptorSet->getTexture(REFLECTIONPROBEBLENDCUBEMAP::BINDING)
: nullptr;
const uint32_t reflectionProbeType = subModel->getReflectionProbeType();
auto *shader = shaderImplant;
if (!shader) {
@@ -81,65 +85,91 @@ void InstancedBuffer::merge(scene::SubModel *subModel, uint32_t passIdx, gfx::Sh
_sortRender.hash = hash;
_sortRender.shaderID = shaderId;
_sortRender.passIndex = passIdx;
for (auto &instance : _instances) {
if (instance.ia->getIndexBuffer() != sourceIA->getIndexBuffer() || instance.drawInfo.instanceCount >= MAX_CAPACITY) {
continue;
const ccstd::string key = StringUtil::format("%u/%u/%u/%u/%u/%u/%u",
sourceIA->getIndexBuffer() ? sourceIA->getIndexBuffer()->getObjectID() : 0,
lightingMap ? lightingMap->getObjectID() : 0,
reflectionProbeType,
reflectionProbeCubemap ? reflectionProbeCubemap->getObjectID() : 0,
reflectionProbePlanarMap ? reflectionProbePlanarMap->getObjectID() : 0,
reflectionProbeBlendCubemap ? reflectionProbeBlendCubemap->getObjectID() : 0,
stride);
const auto iter = _instancesMap.find(key);
if (iter != _instancesMap.end()) {
for (size_t idx : iter->second) {
auto &instance = _instances[idx];
if (instance.drawInfo.instanceCount >= MAX_CAPACITY) {
continue;
}
appendInstance(instance, attrs.buffer, shader, descriptorSet);
return;
}
// check same binding
if (instance.lightingMap != lightingMap) {
continue;
}
if (instance.reflectionProbeType != reflectionProbeType) {
continue;
}
if (instance.reflectionProbeCubemap != reflectionProbeCubemap) {
continue;
}
if (instance.reflectionProbePlanarMap != reflectionProbePlanarMap) {
continue;
}
if (instance.reflectionProbeBlendCubemap != reflectionProbeBlendCubemap) {
continue;
}
if (instance.stride != stride) {
continue;
}
if (instance.drawInfo.instanceCount >= instance.capacity) { // resize buffers
instance.capacity <<= 1;
const auto newSize = instance.stride * instance.capacity;
// NOLINTNEXTLINE(bugprone-suspicious-realloc-usage)
instance.data = static_cast<uint8_t *>(CC_REALLOC(instance.data, newSize));
instance.vb->resize(newSize);
}
if (instance.shader != shader) {
instance.shader = shader;
}
if (instance.descriptorSet != descriptorSet) {
instance.descriptorSet = descriptorSet;
}
memcpy(instance.data + static_cast<size_t>(instance.stride) * instance.drawInfo.instanceCount++, attrs.buffer.buffer()->getData(), stride);
_hasPendingModels = true;
return;
}
// Create a new instance
createInstance(
key,
sourceIA,
attrs.attributes,
attrs.buffer,
stride,
shader,
descriptorSet,
lightingMap,
reflectionProbeType,
reflectionProbeCubemap,
reflectionProbePlanarMap,
reflectionProbeBlendCubemap);
}
void InstancedBuffer::appendInstance(InstancedItem &instance,
Uint8Array &buffer,
gfx::Shader *shader,
gfx::DescriptorSet *descriptorSet) {
if (instance.drawInfo.instanceCount >= instance.capacity) { // resize buffers
instance.capacity = std::min(instance.capacity << 1, MAX_CAPACITY);
const auto newSize = instance.stride * instance.capacity;
// NOLINTNEXTLINE(bugprone-suspicious-realloc-usage)
instance.data = static_cast<uint8_t *>(CC_REALLOC(instance.data, newSize));
instance.vb->resize(newSize);
}
if (instance.shader != shader) {
instance.shader = shader;
}
if (instance.descriptorSet != descriptorSet) {
instance.descriptorSet = descriptorSet;
}
auto *destination = instance.data + static_cast<size_t>(instance.stride) * instance.drawInfo.instanceCount;
CC_ASSERT(destination);
memcpy(destination, buffer.buffer()->getData(), instance.stride);
instance.drawInfo.instanceCount++;
_hasPendingModels = true;
}
void InstancedBuffer::createInstance(const ccstd::string &key,
gfx::InputAssembler *sourceIA,
const ccstd::vector<gfx::Attribute> &attributes,
Uint8Array &buffer,
uint32_t stride,
gfx::Shader *shader,
gfx::DescriptorSet *descriptorSet,
gfx::Texture *lightingMap,
uint32_t reflectionProbeType,
gfx::Texture *reflectionProbeCubemap,
gfx::Texture *reflectionProbePlanarMap,
gfx::Texture *reflectionProbeBlendCubemap) {
const auto newSize = stride * INITIAL_CAPACITY;
auto *vb = _device->createBuffer({
gfx::BufferUsageBit::VERTEX | gfx::BufferUsageBit::TRANSFER_DST,
gfx::MemoryUsageBit::DEVICE,
gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE,
static_cast<uint32_t>(newSize),
static_cast<uint32_t>(stride),
});
auto *data = static_cast<uint8_t *>(CC_MALLOC(newSize));
auto vertexBuffers = sourceIA->getVertexBuffers();
auto attributes = sourceIA->getAttributes();
auto iaAttributes = sourceIA->getAttributes();
auto *indexBuffer = sourceIA->getIndexBuffer();
for (const auto &attribute : attrs.attributes) {
attributes.emplace_back(gfx::Attribute{
for (const auto &attribute : attributes) {
iaAttributes.emplace_back(gfx::Attribute{
attribute.name,
attribute.format,
attribute.isNormalized,
@@ -147,17 +177,22 @@ void InstancedBuffer::merge(scene::SubModel *subModel, uint32_t passIdx, gfx::Sh
true,
attribute.location});
}
CC_ASSERT(data);
memcpy(data, buffer.buffer()->getData(), stride);
auto *data = static_cast<uint8_t *>(CC_MALLOC(newSize));
memcpy(data, attrs.buffer.buffer()->getData(), stride);
vertexBuffers.emplace_back(vb);
const gfx::InputAssemblerInfo iaInfo = {attributes, vertexBuffers, indexBuffer};
const gfx::InputAssemblerInfo iaInfo = {iaAttributes, vertexBuffers, indexBuffer};
auto *ia = _device->createInputAssembler(iaInfo);
InstancedItem item = {INITIAL_CAPACITY, vb, data, ia, stride, shader, descriptorSet,
lightingMap, reflectionProbeCubemap, reflectionProbePlanarMap, reflectionProbeType, reflectionProbeBlendCubemap,
lightingMap,
reflectionProbeCubemap,
reflectionProbePlanarMap,
reflectionProbeType,
reflectionProbeBlendCubemap,
ia->getDrawInfo()};
item.drawInfo.instanceCount = 1;
_instances.emplace_back(item);
_instancesMap[key].emplace_back(_instances.size() - 1);
_hasPendingModels = true;
}
@@ -165,7 +200,16 @@ void InstancedBuffer::uploadBuffers(gfx::CommandBuffer *cmdBuff) const {
for (const auto &instance : _instances) {
if (!instance.drawInfo.instanceCount) continue;
cmdBuff->updateBuffer(instance.vb, instance.data, instance.vb->getSize());
// `instance.data` is only guaranteed to hold `instance.capacity * instance.stride` bytes.
// If `instance.vb` was resized to a larger size than the CPU-side `instance.data`
// buffer (e.g. due to a bug in the resize/append logic), copying `instance.vb->getSize()`
// bytes from `instance.data` would read out of bounds and crash. Clamp to the smaller
// of the two to avoid reading past the end of `instance.data`.
const uint32_t dataCapacity = instance.capacity * instance.stride;
const uint32_t validSize = instance.drawInfo.instanceCount * instance.stride;
CC_ASSERT(validSize <= instance.vb->getSize());
CC_ASSERT(validSize <= dataCapacity);
cmdBuff->updateBuffer(instance.vb, instance.data, validSize);
instance.ia->setInstanceCount(instance.drawInfo.instanceCount);
}
}
@@ -78,14 +78,37 @@ public:
inline const DynamicOffsetList &dynamicOffsets() const { return _dynamicOffsets; }
private:
InstancedItemList _instances;
RenderPass _sortRender;
void appendInstance(InstancedItem &instance,
Uint8Array &buffer,
gfx::Shader *shader,
gfx::DescriptorSet *descriptorSet);
void createInstance(const ccstd::string &key,
gfx::InputAssembler *sourceIA,
const ccstd::vector<gfx::Attribute> &attributes,
Uint8Array &buffer,
uint32_t stride,
gfx::Shader *shader,
gfx::DescriptorSet *descriptorSet,
gfx::Texture *lightingMap,
uint32_t reflectionProbeType,
gfx::Texture *reflectionProbeCubemap,
gfx::Texture *reflectionProbePlanarMap,
gfx::Texture *reflectionProbeBlendCubemap);
// weak reference
const scene::Pass *_pass{nullptr};
bool _hasPendingModels{false};
DynamicOffsetList _dynamicOffsets;
// weak reference
gfx::Device *_device{nullptr};
bool _hasPendingModels{false};
RenderPass _sortRender;
InstancedItemList _instances;
DynamicOffsetList _dynamicOffsets;
// Maps a merge key to the indices (into `_instances`) of items sharing that key.
// Storing indices (not copies or references) keeps this in sync with `_instances`
// and remains valid across `_instances` reallocation, since indices don't dangle.
ccstd::unordered_map<ccstd::string, ccstd::vector<size_t>> _instancesMap;
};
} // namespace pipeline
@@ -44,7 +44,9 @@
#include "details/GraphView.h"
#include "details/GslUtils.h"
#include "details/Range.h"
#if CC_USE_DEBUG_RENDERER
#include "cocos/renderer/pipeline/helper/Utils.h"
#endif
#if CC_USE_GEOMETRY_RENDERER
#include "cocos/renderer/pipeline/GeometryRenderer.h"
#endif
@@ -793,7 +795,13 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
return;
}
}
#if CC_USE_DEBUG_RENDERER
if (blit.blitType == BlitType::DRAW_PROFILE) {
auto* renderPass = ctx.currentPass;
auto* cmdBuff = ctx.cmdBuff;
renderDebugRenderer(renderPass, cmdBuff, ctx.ppl->getPipelineSceneData(), cc::pipeline::profilerCamera);
}
#endif
tryBindPassDescriptorSet(vertID);
tryBindQueueDescriptorSets(vertID);
+1 -1
View File
@@ -3,6 +3,6 @@
"type": "github",
"owner": "cocos",
"name": "cocos-engine-external",
"checkout": "v4.0.0-7"
"checkout": "v4.0.0-9"
}
}
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "cocos-creator",
"version": "4.0.0-alpha.31",
"version": "4.0.0-alpha.32",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "cocos-creator",
"version": "4.0.0-alpha.31",
"version": "4.0.0-alpha.32",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "cocos-creator",
"version": "4.0.0-alpha.31",
"version": "4.0.0-alpha.32",
"description": "Cocos Creator is a cross-platform 2D & 3D game engine written in C++ and TypeScript, licensed under MIT.",
"homepage": "http://www.cocos.com",
"license": "MIT",
@@ -1,9 +1,9 @@
import { execSync, spawn } from 'child_process';
import { execSync } from 'child_process';
import * as fs from 'fs-extra';
import * as ps from 'path';
import * as os from 'os';
import { CocosParams } from '../base/default';
import { cchelper, toolHelper, Paths } from "../utils";
import { cchelper, toolHelper } from "../utils";
import { MacOSPackTool } from "./mac-os";
export interface IOrientation {
@@ -115,13 +115,8 @@ export class IOSPackTool extends MacOSPackTool {
throw new Error("Error: Try to build iphoneos application but no developer team id was given!");
}
const nativePrjDir = this.paths.nativePrjDir;
const simulatorArch = this.getIosSimulatorArch();
const projName = this.params.projectName;
const os = require('os');
const cpus = os.cpus();
const model = (cpus && cpus[0] && cpus[0].model) ? cpus[0].model : '';
// check mac architecture
// const platform = /Apple/.test(model) ? `-arch arm64` : `-arch x86_64`;
// get xcode workspace
const regex = new RegExp(projName + '.xcworkspace$');
const files = fs.readdirSync(nativePrjDir);
@@ -145,7 +140,7 @@ export class IOSPackTool extends MacOSPackTool {
await toolHelper.runCmake([projCompileParams, '-sdk', 'iphoneos', `-arch arm64`]);
}
if (options.simulator) {
await toolHelper.runCmake([projCompileParams, '-sdk', 'iphonesimulator', `-arch x86_64`]); //force compile x86_64 app for iPhone simulator on Mac
await toolHelper.runCmake([projCompileParams, '-sdk', 'iphonesimulator', `-arch ${simulatorArch}`]);
}
}
return true;
@@ -51,10 +51,36 @@ export abstract class MacOSPackTool extends NativePackTool {
return /Apple/.test(model) && process.platform === 'darwin';
}
protected getXcodeMajorVerion(): number {
protected compareVersion(a: string, b: string): number {
const aParts = a.split('.').map((part) => Number.parseInt(part, 10) || 0);
const bParts = b.split('.').map((part) => Number.parseInt(part, 10) || 0);
const maxLength = Math.max(aParts.length, bParts.length);
for (let i = 0; i < maxLength; i++) {
const aValue = aParts[i] ?? 0;
const bValue = bParts[i] ?? 0;
if (aValue !== bValue) {
return aValue - bValue;
}
}
return 0;
}
protected getXcodeVersion(): string {
try {
const output = execSync('xcrun xcodebuild -version').toString('utf8');
return Number.parseInt(output.match(/Xcode\s(\d+)\.\d+/)![1]);
const match = output.match(/Xcode\s+(\d+(?:\.\d+)+)/);
return match?.[1] || '0.0';
} catch (e) {
console.error(e);
return '0.0';
}
}
protected getXcodeMajorVerion(): number {
try {
return Number.parseInt(this.getXcodeVersion().split('.')[0] || '0', 10);
} catch (e) {
console.error(e);
// fallback to default Xcode version
@@ -62,6 +88,14 @@ export abstract class MacOSPackTool extends NativePackTool {
}
}
protected getIosSimulatorArch(): 'arm64' | 'x86_64' {
// Xcode 14.3+ no longer supports running iOS Simulator under Rosetta on Apple Silicon.
if (this.isAppleSilicon() && this.compareVersion(this.getXcodeVersion(), '14.3') >= 0) {
return 'arm64';
}
return 'x86_64';
}
async modifyXcodeProject() {
if (this.params.platformParams.skipUpdateXcodeProject) {
if (this.getXcodeMajorVerion() < 12) {
+1 -1
View File
@@ -6,7 +6,7 @@ endif()
if(POLICY CMP0111)
# https://cmake.org/cmake/help/latest/policy/CMP0111.html
cmake_policy(SET CMP0111 OLD)
cmake_policy(SET CMP0111 NEW)
endif()
# set(CC_REGISTERED_PLUGINS)
+1 -1
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.28)
set(CMAKE_SYSTEM_NAME iOS)
set(APP_NAME "CocosGame" CACHE STRING "Project Name")
+1 -1
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.28)
set(APP_NAME "CocosGame" CACHE STRING "Project Name")
option(ENABLE_SANDBOX "enable sandbox entitlements.plist" ON)
+42 -24
View File
@@ -1,27 +1,45 @@
import { Texture2D } from "../../cocos/asset/assets/texture-2d";
import { Details } from "../../cocos/serialization/deserialize";
import { ImageAsset } from '../../cocos/asset/assets/image-asset';
import { Texture2D } from '../../cocos/asset/assets/texture-2d';
import { dependMap } from '../../cocos/asset/asset-manager/depend-maps';
import dependUtil from '../../cocos/asset/asset-manager/depend-util';
import { setProperties } from '../../cocos/asset/asset-manager/utilities';
import { macro } from '../../cocos/core';
// issue: https://github.com/cocos/cocos-engine/issues/16693
test('Texture2D serialize', function () {
const texture = new Texture2D();
texture._mipmaps = [{ _uuid: '09f4f3e7-268b-478c-a7af-bbdf574ec3c6@6c48a' }];
const ctxForExporting = {
_depends: [] as string[],
dependsOn(propName: string, uuid: string) {
this._depends.push(propName, uuid);
},
_compressUuid: this.mustCompresseUuid,
};
texture._serialize(ctxForExporting);
expect(ctxForExporting._depends).toEqual(['_textureSource', '09f4f3e7-268b-478c-a7af-bbdf574ec3c6@6c48a']);
const textureUuid = 'f41e5c8f-0e9a-4c38-bb1d-texture2d';
afterEach(() => {
dependUtil.remove(textureUuid);
});
test('Texture2D deserialize', function () {
const data = { base: '2,2,2,2,0,0', mipmaps: ['09f4f3e7-268b-478c-a7af-bbdf574ec3c6'] };
const result = new Details();
result.init();
const handle = { result };
const texture = new Texture2D();
texture._deserialize(data, handle);
expect(handle.result.uuidList).toEqual(['09f4f3e7-268b-478c-a7af-bbdf574ec3c6']);
});
test('releases every Texture2D dependency edge for an uploaded image', () => {
const cleanupImageCache = macro.CLEANUP_IMAGE_CACHE;
macro.CLEANUP_IMAGE_CACHE = true;
try {
const texture = new Texture2D();
texture._uuid = textureUuid;
const image = new ImageAsset({
_data: new Uint8Array(4),
width: 1,
height: 1,
});
image._uuid = '6d35c119-b763-4295-96e7-image';
const deps = [
{ uuid: image._uuid, owner: texture, prop: '_textureSource' },
{ uuid: image._uuid, owner: texture._mipmaps, prop: '0' },
];
const assetsMap = { [`${image._uuid}@import`]: image };
dependMap.set(texture, deps);
dependUtil._depends.add(textureUuid, { deps: deps.map((dep) => dep.uuid) });
setProperties(textureUuid, texture, assetsMap);
expect(image.refCount).toBe(2);
texture.onLoaded();
expect(image.refCount).toBe(0);
expect(dependUtil.getDeps(textureUuid)).toEqual([]);
} finally {
macro.CLEANUP_IMAGE_CACHE = cleanupImageCache;
}
});