cocos-engine
cocos-engine copied to clipboard
webgl2.0 UBO bufferSubData performance loss
Cocos Creator version
3.4.2
System information
webgl2.0 iOS 14.3, iOS15.1
Issue description
This problem is caused by the difference in the use of buffersubdata, please refer to the following paragraph: "Consider using multiple buffer objects to avoid stalling the rendering pipeline during data store updates. If any rendering in the pipeline makes reference to data in the buffer object being updated by glBufferSubData, especially from the specific region being updated, that rendering must drain from the pipeline before the data store can be updated."
After the following modification, the frame rate of the demo test case reached 60 from 40.

Relevant error log output
No response
Steps to reproduce
3.4.2 demo: test342.zip
turn on the shadows。
Minimal reproduction project
No response
The problem occurs on runtime platform using GLES 3.0 backend and Wechat WebGL 2.0 backend.
If update the same Uniform Buffer multiple times using glBufferSubData, the performance will drop drastically, but if changing to glBufferData, the performance will return to normal.
@star-e please help provide insights and possible solution
When the buffer is in device memory, we need to use triple-buffer if it is updated frequently (PerFrame). Or we can use dynamic buffer, which supports fast cpu write.
Tried both on mac and ios, can't reproduce. If there's any extra step please let me known. Besides: could you have a try if does it make any difference on portrait mode and landscape mode? and phone settings->safari->advanced->WebGL via Metal, try turn it off.
for reference here: https://bugs.webkit.org/show_bug.cgi?id=228012
To my current understanding of creator ide, the native side wants to simulate may not be good simulation, need GLSE 3.0 back-end but currently in the iOS platform does not seem to support the export, you can try to package into webgl2.0 WeChat mini game will be reproduced.
same https://github.com/cocos/3d-tasks/issues/13603