Skip to content

Commit

Permalink
fix iOS 14 performance issue
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e committed Sep 18, 2024
1 parent 9b82eef commit 722540e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cocos/gfx/webgl/webgl-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,10 @@ export function WebGLCmdFuncUpdateBuffer (
}

if ((gpuBuffer.memUsage & MemoryUsageBit.HOST) && offset === 0 && size === buff.byteLength) {
// Fix performance issue on iOS.
// TODO(zhouzhenglong): glBufferSubData is faster than glBufferData in most cases.
// We should use multiple buffers to avoid stall (cpu write conflicts with gpu read).
// Before that, we will use glBufferData instead of glBufferSubData.
gl.bufferData(gpuBuffer.glTarget, buff, gl.DYNAMIC_DRAW);
} else if (size === buff.byteLength) {
gl.bufferSubData(gpuBuffer.glTarget, offset, buff);
Expand Down
12 changes: 12 additions & 0 deletions cocos/gfx/webgl2/webgl2-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,10 @@ export function WebGL2CmdFuncUpdateBuffer (
}

if ((gpuBuffer.memUsage & MemoryUsageBit.HOST) && offset === 0 && size === buff.byteLength) {
// Fix performance issue on iOS.
// TODO(zhouzhenglong): glBufferSubData is faster than glBufferData in most cases.
// We should use multiple buffers to avoid stall (cpu write conflicts with gpu read).
// Before that, we will use glBufferData instead of glBufferSubData.
gl.bufferData(gpuBuffer.glTarget, buff, gl.DYNAMIC_DRAW);
} else if (size === buff.byteLength) {
gl.bufferSubData(gpuBuffer.glTarget, offset, buff);
Expand All @@ -1025,6 +1029,10 @@ export function WebGL2CmdFuncUpdateBuffer (
}

if ((gpuBuffer.memUsage & MemoryUsageBit.HOST) && offset === 0 && size === buff.byteLength) {
// Fix performance issue on iOS.
// TODO(zhouzhenglong): glBufferSubData is faster than glBufferData in most cases.
// We should use multiple buffers to avoid stall (cpu write conflicts with gpu read).
// Before that, we will use glBufferData instead of glBufferSubData.
gl.bufferData(gpuBuffer.glTarget, buff, gl.DYNAMIC_DRAW);
} else if (size === buff.byteLength) {
gl.bufferSubData(gpuBuffer.glTarget, offset, buff);
Expand All @@ -1040,6 +1048,10 @@ export function WebGL2CmdFuncUpdateBuffer (
}

if ((gpuBuffer.memUsage & MemoryUsageBit.HOST) && offset === 0 && size === buff.byteLength) {
// Fix performance issue on iOS.
// TODO(zhouzhenglong): glBufferSubData is faster than glBufferData in most cases.
// We should use multiple buffers to avoid stall (cpu write conflicts with gpu read).
// Before that, we will use glBufferData instead of glBufferSubData.
gl.bufferData(gpuBuffer.glTarget, buff, gl.DYNAMIC_DRAW);
} else if (size === buff.byteLength) {
gl.bufferSubData(gpuBuffer.glTarget, offset, buff);
Expand Down

0 comments on commit 722540e

Please sign in to comment.