From 34b17e132aed0fd9cc6b173b2cf36bada4edb01a Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 20 Oct 2026 15:29:35 -0700 Subject: [PATCH] [GL] Fix unused and overly-broad `__deps` entries in WebGL JS libraries. NFC Align the preprocessor guards on `__deps` arrays with the actual call sites in the corresponding function bodies so symbols are only pulled in when referenced: - In `src/lib/libwebgl.js`: - Guard `'$webglBufferSubData'` in `$GL__deps` and `glDrawElements__deps` with `#if FULL_ES2`. In `$GL`, `webglBufferSubData` is only called from `preDrawHandleClientVertexAttribBindings` (which is guarded by `#if FULL_ES2`, not `LEGACY_GL_EMULATION`). Similarly, `glDrawElements` only calls `webglBufferSubData` inside its `#if FULL_ES2` client-side index buffer block. - Guard `'$heapObjectForWebGLType'` and `'$toTypedArrayIndex'` in `glTexImage2D__deps`, `glTexSubImage2D__deps`, and `glReadPixels__deps` with `#if WEBGL_USE_GARBAGE_FREE_APIS` instead of `#if MAX_WEBGL_VERSION >= 2`. Those functions only call `heapObjectForWebGLType` and `toTypedArrayIndex` directly inside `#if WEBGL_USE_GARBAGE_FREE_APIS` blocks; otherwise they delegate to `emscriptenWebGLGetTexPixelData` (which declares its own `__deps`). - Guard `$webglGetProgramUniformLocation__deps` with `#if GL_EXPLICIT_UNIFORM_LOCATION`, matching the sole call to `webglPrepareUniformLocationsBeforeFirstUse` inside `$webglGetProgramUniformLocation`. - In `src/lib/libwebgl2.js`: - Guard `'$toTypedArrayIndex'` in `glTexImage3D__deps` and `glTexSubImage3D__deps` with `#if WEBGL_USE_GARBAGE_FREE_APIS`, since `toTypedArrayIndex` is only called in that branch (the `#else` branch delegates to `emscriptenWebGLGetTexPixelData`). - Remove `glGetVertexAttribIuiv__deps`. `glGetVertexAttribIuiv` is a string alias for `'glGetVertexAttribIiv'`, which already declares `glGetVertexAttribIiv__deps: ['$emscriptenWebGLGetVertexAttrib']`. Split out from #27995 --- src/lib/libwebgl.js | 16 +++++++++++----- src/lib/libwebgl2.js | 13 ++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/lib/libwebgl.js b/src/lib/libwebgl.js index f0807ae32550d..cb3825add8b9f 100644 --- a/src/lib/libwebgl.js +++ b/src/lib/libwebgl.js @@ -249,6 +249,8 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; #endif // GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS #if FULL_ES2 || LEGACY_GL_EMULATION '$registerPreMainLoop', +#endif +#if FULL_ES2 '$webglBufferSubData', #endif ], @@ -1666,7 +1668,7 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; }, glTexImage2D__deps: ['$emscriptenWebGLGetTexPixelData' -#if MAX_WEBGL_VERSION >= 2 +#if WEBGL_USE_GARBAGE_FREE_APIS , '$heapObjectForWebGLType', '$toTypedArrayIndex' #endif ], @@ -1713,9 +1715,9 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixelData); }, - glTexSubImage2D__deps: ['$emscriptenWebGLGetTexPixelData' -#if MAX_WEBGL_VERSION >= 2 - , '$heapObjectForWebGLType', '$toTypedArrayIndex' + glTexSubImage2D__deps: ['$emscriptenWebGLGetTexPixelData', +#if WEBGL_USE_GARBAGE_FREE_APIS + '$heapObjectForWebGLType', '$toTypedArrayIndex', #endif ], glTexSubImage2D: (target, level, xoffset, yoffset, width, height, format, type, pixels) => { @@ -1751,7 +1753,7 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; #if INCLUDE_WEBGL1_FALLBACK '$emscriptenWebGLGetTexPixelData', #endif -#if MAX_WEBGL_VERSION >= 2 +#if WEBGL_USE_GARBAGE_FREE_APIS '$heapObjectForWebGLType', '$toTypedArrayIndex', #endif ], @@ -2180,7 +2182,9 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; // Returns the WebGLUniformLocation object corresponding to the location index // integer on the currently active shader in this GL context. +#if GL_EXPLICIT_UNIFORM_LOCATION $webglGetProgramUniformLocation__deps: ['$webglPrepareUniformLocationsBeforeFirstUse'], +#endif $webglGetProgramUniformLocation: (program, location) => { #if !GL_TRACK_ERRORS && ASSERTIONS // In -sGL_TRACK_ERRORS=0 build mode do not allow calling glUniform*() @@ -3881,7 +3885,9 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}}; #endif }, +#if FULL_ES2 glDrawElements__deps: ['$webglBufferSubData'], +#endif glDrawElements: (mode, count, type, indices) => { #if FULL_ES2 var buf; diff --git a/src/lib/libwebgl2.js b/src/lib/libwebgl2.js index 79b01bbc84026..d2a539bed2332 100644 --- a/src/lib/libwebgl2.js +++ b/src/lib/libwebgl2.js @@ -151,8 +151,10 @@ var LibraryWebGL2 = { GLctx.invalidateSubFramebuffer(target, list, x, y, width, height); }, - glTexImage3D__deps: ['$heapObjectForWebGLType', '$toTypedArrayIndex', -#if !WEBGL_USE_GARBAGE_FREE_APIS + glTexImage3D__deps: ['$heapObjectForWebGLType', +#if WEBGL_USE_GARBAGE_FREE_APIS + '$toTypedArrayIndex', +#else '$emscriptenWebGLGetTexPixelData', #endif ], @@ -172,8 +174,10 @@ var LibraryWebGL2 = { } }, - glTexSubImage3D__deps: ['$heapObjectForWebGLType', '$toTypedArrayIndex', -#if !WEBGL_USE_GARBAGE_FREE_APIS + glTexSubImage3D__deps: ['$heapObjectForWebGLType', +#if WEBGL_USE_GARBAGE_FREE_APIS + '$toTypedArrayIndex', +#else '$emscriptenWebGLGetTexPixelData', #endif ], @@ -757,7 +761,6 @@ var LibraryWebGL2 = { // N.B. This function may only be called if the vertex attribute was specified using the function glVertexAttribI4uiv(), // otherwise the results are undefined. (GLES3 spec 6.1.12) - glGetVertexAttribIuiv__deps: ['$emscriptenWebGLGetVertexAttrib'], glGetVertexAttribIuiv: 'glGetVertexAttribIiv', glUniform1ui__deps: ['$webglGetUniformLocation'],