-
Notifications
You must be signed in to change notification settings - Fork 2k
Supports configuring a larger BATCHER2D_MEM_INCREMENT #19009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3.8.8
Are you sure you want to change the base?
Supports configuring a larger BATCHER2D_MEM_INCREMENT #19009
Conversation
Code Size Check Report
Interface Check Report! WARNING this pull request has changed these public interfaces:
@@ -206,19 +206,27 @@
* @default false
*/
ENABLE_WEBGL_HIGHP_STRUCT_VALUES: boolean;
/**
- * @zh Batcher2D 中内存增量的大小(KB)
- * 这个值决定了当场景中存在的 2d 渲染组件的顶点数量超过当前 batcher2D 中可容纳的顶点数量时,内存扩充的增加量
- * 这个值越大,共用同一个 meshBuffer 的 2d 渲染组件数量会更多,但每次扩充所占用的内存也会更大
- * 默认值在标准格式([[VertexFormat.vfmtPosUvColor]])下可容纳 4096 个顶点(4096*9*4/1024),你可以增加容量来提升每个批次可容纳的元素数量
- * @en The MeshBuffer chunk size in Batcher2D (KB)
- * This value determines the increase in memory expansion,
- * when the number of vertices of 2d rendering components present in the scene exceeds the number of vertices,
- * that can be accommodated in the current batcher2D.
- * The larger this value is, the more 2d rendering components will share the same meshBuffer, but the more memory will be used for each expansion
- * The default size can contain 4096 standard vertex ([[VertexFormat.vfmtPosUvColor]]) in one buffer,
- * you can user larger buffer size to increase the elements count per 2d draw batch.
+ * @zh Batcher2D 中每个渲染批次的内存增量(KB)
+ * 增大此值能使参与渲染合批的 2d 渲染组件数量增加,但是每次增加渲染批次的内存增量也会变大。
+ * 这个值决定每个 2D 渲染批次的顶点数量,计算公式为 vCount = Math.floor(macro.BATCHER2D_MEM_INCREMENT * 1024 / 9 * 4);
+ * WebGL2 & WebGPU 等渲染后端的最大顶点数量通常是 2^32 - 1,即 4294967295。
+ * WebGL1 渲染后端的最大顶点数量通常是 2^16 - 1,即 65535。引擎使用拓展 OES_element_index_uint 突破了这个限制,最大顶点数量也可达到 2^32 - 1。
+ * 所以 macro.BATCHER2D_MEM_INCREMENT 的理论最大值为 150994943,但是因为所运行平台的 js 引擎对 Float32Array|Uint16Array 的最大长度有限制,实际最大值往往会小于 2^32 - 1。
+ * 建议最大值不超过 1048576 kb (1GB),否则会因为 js 引擎的限制而导致 buffer 创建失败。
+ * @en Memory increment (KB) for each rendering batch in Batcher2D
+ * Increasing this value can increase the number of 2D rendering components involved in rendering batching, but the memory increment for each additional rendering batch will also become larger.
+ * This value determines the number of vertices in each 2D rendering batch, calculated as vCount = Math.floor(macro.BATCHER2D_MEM_INCREMENT * 1024 / 9 * 4);
+ * The maximum number of vertices for rendering backends such as WebGL2 & WebGPU is usually 2^32 - 1, which is 4294967295.
+ * The maximum number of vertices for the WebGL1 rendering backend is usually 2^16 - 1, which is 65535. The engine uses the extension OES_element_index_uint to break this limit, and the maximum number of vertices can also reach 2^32 - 1.
+ * Therefore, the theoretical maximum value of macro.BATCHER2D_MEM_INCREMENT is 150994943. However, due to the limitations of the JS engine on the maximum length of Float32Array|Uint16Array on the running platform, the actual maximum value is often less than 2^32 - 1.
+ * It is recommended that the maximum value does not exceed 1048576 kb (1GB); otherwise, buffer creation will fail due to JS engine limitations.
+ * @example
+ * ```typescript
+ * import { macro } from 'cc';
+ * macro.BATCHER2D_MEM_INCREMENT = 4096; //4096 KB
+ * ```
* @default 144 KB
*/
BATCHER2D_MEM_INCREMENT: number;
/**
|
@cocos-robot run-test-cases-custom |
cocos/2d/renderer/mesh-buffer.ts
Outdated
assertIsTrue(this._initVDataCount / this._floatsPerVertex < 65536, getError(9005)); | ||
var vDataCountLimit = 65536; // 2^16 - 1 | ||
if (cclegacy.director.root) { | ||
if (cclegacy.director.root.device.gfxAPI === cclegacy.gfx.API.WEBGPU || cclegacy.director.root.device.gfxAPI === cclegacy.gfx.API.WEBGL2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change cclegacy.gfx.API.WEBGPU
to API.WEBGPU
? So as API.WEBGL2
cocos/2d/renderer/mesh-buffer.ts
Outdated
import { sys, getError, warnID, assertIsTrue } from '../../core'; | ||
import { cclegacy, sys, getError, warnID, assertIsTrue } from '../../core'; | ||
import { NativeUIMeshBuffer } from './native-2d'; | ||
import { Feature } from '../../gfx/base/define'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we import Feature
from the above '../../gfx'
?
@cocos-robot run test cases |
@cocos-robot run test cases |
RT