-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix performance issue with WebGL 2 glBufferData #15206
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1767,7 +1767,7 @@ var LibraryGL = { | |
|
||
#if MAX_WEBGL_VERSION >= 2 | ||
if ({{{ isCurrentContextWebGL2() }}}) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible. | ||
if (data) { | ||
if (data && size > 0) { | ||
GLctx.bufferData(target, HEAPU8, usage, data, size); | ||
} else { | ||
GLctx.bufferData(target, size, usage); | ||
|
@@ -1785,7 +1785,7 @@ var LibraryGL = { | |
glBufferSubData__sig: 'viiii', | ||
glBufferSubData: function(target, offset, size, data) { | ||
#if MAX_WEBGL_VERSION >= 2 | ||
if ({{{ isCurrentContextWebGL2() }}}) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible. | ||
if ({{{ isCurrentContextWebGL2() }}} && size > 0) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible. | ||
GLctx.bufferSubData(target, offset, HEAPU8, data, size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would lead to calling the WebGL 1 style function below if size <= 0. How about the following? glBufferSubData: function(target, offset, size, data) {
#if ASSERTIONS
assert(size >= 0);
#endif
#if MAX_WEBGL_VERSION >= 2
if ({{{ isCurrentContextWebGL2() }}}) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
size && GLctx.bufferSubData(target, offset, HEAPU8, data, size);
return;
}
#endif
GLctx.bufferSubData(target, offset, HEAPU8.subarray(data, data+size));
}, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was under the impression that bufferSubData could affect something in the buffer state, that's why I was letting it fall back to the webgl 1 style function, but since it doesn't affect anything... Might as well move the size check to also include webgl 1 to avoid the allocation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That does make sense.. shortest code is probably to also do size && GLctx.bufferSubData(target, offset, HEAPU8.subarray(data, data+size)); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, actually, although generally it is preferable to "diligently" call the functions so that WebGL spec related validation and GL error state etc. is properly recorded, so in the absence of other functional difference, may be good to leave that out in the WebGL 1 path. That way the target and currently bound buffer etc. will be properly validated. |
||
return; | ||
} | ||
|
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 you add at the top a
and then here do just
if (data && size)
.We do not currently support larger than 2GB buffers (that needs special handling, which I doubt anyone will use with WebGL - those use cases will be with Wasm64 and WebGPU)