Skip to content

Commit cfdc30e

Browse files
authored
Move emscripten_webgl_init_context_attributes to native code. NFC (#21189)
1 parent 4eb71a2 commit cfdc30e

9 files changed

+46
-50
lines changed

src/library_html5_webgl.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,6 @@ var LibraryHtml5WebGL = {
2020
return len;
2121
},
2222

23-
// Execute in calling thread without proxying needed.
24-
emscripten_webgl_init_context_attributes: (attributes) => {
25-
#if ASSERTIONS
26-
assert(attributes);
27-
#endif
28-
var a = attributes >> 2;
29-
for (var i = 0; i < ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.__size__ }}}>>2); ++i) {
30-
HEAP32[a+i] = 0;
31-
}
32-
33-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}}>>2)] =
34-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.depth }}}>>2)] =
35-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.antialias }}}>>2)] =
36-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.premultipliedAlpha }}}>>2)] =
37-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}}>>2)] =
38-
HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.enableExtensionsByDefault }}}>>2)] = 1;
39-
40-
#if PTHREADS
41-
// Default context initialization state (user can override):
42-
// - if main thread is creating the context, default to the context not being shared between threads - enabling sharing has performance overhead, because it forces the context to be OffscreenCanvas or OffscreenFramebuffer.
43-
// - if a web worker is creating the context, default to using OffscreenCanvas if available, or proxying via Offscreen Framebuffer if not
44-
if (ENVIRONMENT_IS_WORKER) {{{ makeSetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.proxyContextToMainThread, 1/*EMSCRIPTEN_WEBGL_CONTEXT_PROXY_FALLBACK*/, 'i32') }}};
45-
#endif
46-
},
47-
4823
$emscripten_webgl_power_preferences: "['default', 'low-power', 'high-performance']",
4924

5025
#if PTHREADS && OFFSCREEN_FRAMEBUFFER

src/library_sigs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,6 @@ sigs = {
884884
emscripten_webgl_get_vertex_attrib_d__sig: 'dii',
885885
emscripten_webgl_get_vertex_attrib_o__sig: 'iii',
886886
emscripten_webgl_get_vertex_attrib_v__sig: 'iiipii',
887-
emscripten_webgl_init_context_attributes__sig: 'vp',
888887
emscripten_webgl_make_context_current__sig: 'ip',
889888
emscripten_webgpu_export_bind_group__sig: 'ip',
890889
emscripten_webgpu_export_bind_group_layout__sig: 'ip',

system/lib/gl/webgl1.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,28 @@
1717

1818
#include "webgl_internal.h"
1919

20+
void emscripten_webgl_init_context_attributes(EmscriptenWebGLContextAttributes *attributes) {
21+
memset(attributes, 0, sizeof(*attributes));
22+
23+
attributes->alpha = 1;
24+
attributes->depth = 1;
25+
attributes->antialias = 1;
26+
attributes->premultipliedAlpha = 1;
27+
attributes->majorVersion = 1;
28+
attributes->enableExtensionsByDefault = 1;
29+
30+
// Default context initialization state (user can override):
31+
// - if main thread is creating the context, default to the context not being
32+
// shared between threads - enabling sharing has performance overhead,
33+
// because it forces the context to be OffscreenCanvas or
34+
// OffscreenFramebuffer.
35+
// - if a web worker is creating the context, default to using OffscreenCanvas
36+
// if available, or proxying via Offscreen Framebuffer if not
37+
if (!emscripten_is_main_runtime_thread()) {
38+
attributes->proxyContextToMainThread = EMSCRIPTEN_WEBGL_CONTEXT_PROXY_FALLBACK;
39+
}
40+
}
41+
2042
#if defined(__EMSCRIPTEN_PTHREADS__) && defined(__EMSCRIPTEN_OFFSCREEN_FRAMEBUFFER__)
2143

2244
static pthread_key_t currentActiveWebGLContext;

test/code_size/hello_webgl2_wasm.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 569,
33
"a.html.gz": 379,
4-
"a.js": 4681,
5-
"a.js.gz": 2412,
6-
"a.wasm": 10388,
7-
"a.wasm.gz": 6692,
8-
"total": 15638,
9-
"total_gz": 9483
4+
"a.js": 4593,
5+
"a.js.gz": 2372,
6+
"a.wasm": 10451,
7+
"a.wasm.gz": 6724,
8+
"total": 15613,
9+
"total_gz": 9475
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17917,
5-
"a.js.gz": 8089,
4+
"a.js": 17937,
5+
"a.js.gz": 8077,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 21607,
9-
"total_gz": 11161
8+
"total": 21627,
9+
"total_gz": 11149
1010
}

test/code_size/hello_webgl_wasm.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 569,
33
"a.html.gz": 379,
4-
"a.js": 4167,
5-
"a.js.gz": 2236,
6-
"a.wasm": 10388,
7-
"a.wasm.gz": 6692,
8-
"total": 15124,
9-
"total_gz": 9307
4+
"a.js": 4080,
5+
"a.js.gz": 2201,
6+
"a.wasm": 10451,
7+
"a.wasm.gz": 6724,
8+
"total": 15100,
9+
"total_gz": 9304
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17395,
5-
"a.js.gz": 7900,
4+
"a.js": 17415,
5+
"a.js.gz": 7894,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 21085,
9-
"total_gz": 10972
8+
"total": 21105,
9+
"total_gz": 10966
1010
}

test/test_browser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4690,9 +4690,9 @@ def test_webgl_timer_query(self, args):
46904690
'threads': (['-pthread', '-sPROXY_TO_PTHREAD'],)
46914691
})
46924692
@parameterized({
4693-
'v1': ([],),
4694-
'v2': (['-sFULL_ES2'],),
4695-
'v3': (['-sFULL_ES3'],),
4693+
'': ([],),
4694+
'es2': (['-sFULL_ES2'],),
4695+
'es3': (['-sFULL_ES3'],),
46964696
})
46974697
def test_webgl_offscreen_framebuffer(self, version, threads):
46984698
# Tests all the different possible versions of libgl

test/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10545,7 +10545,7 @@ def test_minimal_runtime_code_size(self, test_name, js, compare_js_output=False)
1054510545
hello_webgl_sources = [test_file('minimal_webgl/main.c'),
1054610546
test_file('minimal_webgl/webgl.c'),
1054710547
'--js-library', test_file('minimal_webgl/library_js.js'),
10548-
'-lwebgl.js',
10548+
'-lGL',
1054910549
'-sMODULARIZE']
1055010550
hello_webgl2_sources = hello_webgl_sources + ['-sMAX_WEBGL_VERSION=2']
1055110551
hello_wasm_worker_sources = [test_file('wasm_worker/wasm_worker_code_size.c'), '-sWASM_WORKERS', '-sENVIRONMENT=web,worker']

0 commit comments

Comments
 (0)