Skip to content

Commit

Permalink
Default-enable -sGL_ENABLE_GET_PROC_ADDRESS (#20948)
Browse files Browse the repository at this point in the history
Add paranoia check: if developer is using GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS,
then force an allow-list upon them so they don't get new GL extensions until
they update their Emscripten compiler.
  • Loading branch information
juj authored Dec 20, 2023
1 parent 3777e12 commit 639e817
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
8 changes: 4 additions & 4 deletions embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@
'libc++-mt-noexcept',
'libdlmalloc-mt',
'libGL-emu',
'libGL-emu-webgl2',
'libGL-mt',
'libGL-emu-webgl2-getprocaddr',
'libGL-mt-getprocaddr',
'libGL-mt-emu',
'libGL-mt-emu-webgl2',
'libGL-mt-emu-webgl2-ofb',
'libGL-mt-emu-webgl2-getprocaddr',
'libGL-mt-emu-webgl2-ofb-getprocaddr',
'libsockets_proxy',
'libsockets-mt',
'crtbegin',
Expand Down
6 changes: 0 additions & 6 deletions src/library_sigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ sigs = {
SDL_GL_DeleteContext__sig: 'vp',
SDL_GL_ExtensionSupported__sig: 'ip',
SDL_GL_GetAttribute__sig: 'iip',
SDL_GL_GetProcAddress__sig: 'pp',
SDL_GL_GetSwapInterval__sig: 'i',
SDL_GL_MakeCurrent__sig: 'ipp',
SDL_GL_SetAttribute__sig: 'iii',
Expand Down Expand Up @@ -548,7 +547,6 @@ sigs = {
eglGetCurrentSurface__sig: 'pi',
eglGetDisplay__sig: 'pp',
eglGetError__sig: 'i',
eglGetProcAddress__sig: 'pp',
eglInitialize__sig: 'ippp',
eglMakeCurrent__sig: 'ipppp',
eglQueryAPI__sig: 'i',
Expand Down Expand Up @@ -851,8 +849,6 @@ sigs = {
emscripten_wasm_worker_post_function_vii__sig: 'vipii',
emscripten_wasm_worker_post_function_viii__sig: 'vipiii',
emscripten_wasm_worker_self_id__sig: 'i',
emscripten_webgl1_get_proc_address__sig: 'pp',
emscripten_webgl2_get_proc_address__sig: 'pp',
emscripten_webgl_commit_frame__sig: 'i',
emscripten_webgl_create_context__sig: 'ppp',
emscripten_webgl_destroy_context__sig: 'ip',
Expand All @@ -874,7 +870,6 @@ sigs = {
emscripten_webgl_get_parameter_o__sig: 'ii',
emscripten_webgl_get_parameter_utf8__sig: 'pi',
emscripten_webgl_get_parameter_v__sig: 'iipii',
emscripten_webgl_get_proc_address__sig: 'pp',
emscripten_webgl_get_program_info_log_utf8__sig: 'pi',
emscripten_webgl_get_program_parameter_d__sig: 'dii',
emscripten_webgl_get_shader_info_log_utf8__sig: 'pi',
Expand Down Expand Up @@ -1392,7 +1387,6 @@ sigs = {
glfwGetMouseWheel__sig: 'i',
glfwGetNumberOfProcessors__sig: 'i',
glfwGetPrimaryMonitor__sig: 'p',
glfwGetProcAddress__sig: 'pp',
glfwGetRequiredInstanceExtensions__sig: 'pp',
glfwGetThreadID__sig: 'i',
glfwGetTime__sig: 'd',
Expand Down
5 changes: 3 additions & 2 deletions src/library_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,11 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
disableHalfFloatExtensionIfBroken(ctx);
#endif

// If end user enables *glGetProcAddress() functionality, then we must filter out
// If end user enables *glGetProcAddress() functionality or
// GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS, then we must filter out
// all future WebGL extensions from being passed to the user, and only restrict to advertising
// extensions that the *glGetProcAddress() function knows to handle.
#if GL_ENABLE_GET_PROC_ADDRESS
#if GL_ENABLE_GET_PROC_ADDRESS || GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS
var _allSupportedExtensions = ctx.getSupportedExtensions;
var supportedExtensionsForGetProcAddress = [
#if MIN_WEBGL_VERSION == 1
Expand Down
4 changes: 3 additions & 1 deletion src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,16 @@ var GL_DISABLE_HALF_FLOAT_EXTENSION_IF_BROKEN = false;
// context version was passed. See https://bugs.webkit.org/show_bug.cgi?id=222758 and
// https://github.com/emscripten-core/emscripten/issues/13295.
// Set this to 0 to force-disable the workaround if you know the issue will not affect you.
// [link]
var GL_WORKAROUND_SAFARI_GETCONTEXT_BUG = true;

// If 1, link with support to glGetProcAddress() functionality.
// In WebGL, glGetProcAddress() causes a substantial code size and performance impact, since WebGL
// does not natively provide such functionality, and it must be emulated. Using glGetProcAddress()
// is not recommended. If you still need to use this, e.g. when porting an existing renderer,
// you can link with -sGL_ENABLE_GET_PROC_ADDRESS=1 to get support for this functionality.
var GL_ENABLE_GET_PROC_ADDRESS = false;
// [link]
var GL_ENABLE_GET_PROC_ADDRESS = true;

// Use JavaScript math functions like Math.tan. This saves code size as we can avoid shipping
// compiled musl code. However, it can be significantly slower as it calls out to JS. It
Expand Down
3 changes: 2 additions & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,7 @@ def test_GetProcAddress_LEGACY_GL_EMULATION(self):
# at link time they should get a helpful error message guiding them to enable
# the option.
def test_get_proc_address_error_message(self):
err = self.expect_fail([EMCC, test_file('other/test_GetProcAddress_LEGACY_GL_EMULATION.cpp')])
err = self.expect_fail([EMCC, '-sGL_ENABLE_GET_PROC_ADDRESS=0', test_file('other/test_GetProcAddress_LEGACY_GL_EMULATION.cpp')])
self.assertContained('error: linker: Undefined symbol: SDL_GL_GetProcAddress(). Please pass -sGL_ENABLE_GET_PROC_ADDRESS at link time to link in SDL_GL_GetProcAddress().', err)

def test_prepost(self):
Expand Down Expand Up @@ -10520,6 +10520,7 @@ def test_minimal_runtime_code_size(self, test_name, js, compare_js_output=False)
'-sGL_TRACK_ERRORS=0',
'-sGL_POOL_TEMP_BUFFERS=0',
'-sGL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0',
'-sGL_ENABLE_GET_PROC_ADDRESS=0',
'-sNO_FILESYSTEM',
'-sSTRICT',
'--output_eol', 'linux',
Expand Down

0 comments on commit 639e817

Please sign in to comment.