Skip to content

[GL] Fix unused and overly-broad __deps entries in WebGL JS libraries. NFC - #28037

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:fix_webgl_deps
Oct 21, 2026
Merged

sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:fix_webgl_deps

Conversation

@sbc100

@sbc100 sbc100 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

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 #27999

…es. 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 emscripten-core#27995

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors WebGL and WebGL2 library dependencies in Emscripten. It replaces checks for MAX_WEBGL_VERSION >= 2 with WEBGL_USE_GARBAGE_FREE_APIS for garbage-free API dependencies, optimizes conditional dependency inclusions for FULL_ES2 and GL_EXPLICIT_UNIFORM_LOCATION, and removes an unused dependency declaration for glGetVertexAttribIuiv. There are no review comments, so I have no feedback to provide.

@sbc100
sbc100 merged commit be0bb95 into emscripten-core:main Oct 21, 2026
42 checks passed
@sbc100
sbc100 deleted the fix_webgl_deps branch October 21, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants