Skip to content

Commit ec2ce4c

Browse files
authored
Fix emscripten_webgl_make_context_current under wasm64/CAN_ADDRESS_2GB (#21228)
The first problem here was that emscripten_webgl_make_context_current_calling_thread had the wrong signature. The second issue was use of `>> 2` on a pointer in `emscripten_webgl_do_create_context` which doesn't work under wasm64 or CAN_ADDRESS_2GB.
1 parent 2e77af2 commit ec2ce4c

File tree

5 files changed

+37
-19
lines changed

5 files changed

+37
-19
lines changed

.circleci/config.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,7 @@ jobs:
799799
- run-tests-chrome:
800800
title: "browser"
801801
# Skip test_4gb_fail as it OOMs on the current bot
802-
# Include an representative selection of browser_2gb
803802
test_targets: "
804-
browser_2gb.test_gles2_uniform_arrays
805-
browser_2gb.test_fetch_to_memory
806803
browser skip:browser.test_4gb_fail
807804
"
808805
test-browser-chrome-wasm64:
@@ -811,6 +808,16 @@ jobs:
811808
- run-tests-chrome:
812809
title: "browser64"
813810
test_targets: "browser64"
811+
test-browser-chrome-2gb:
812+
executor: bionic
813+
steps:
814+
- run-tests-chrome:
815+
title: "browser_2gb"
816+
test_targets: "
817+
browser_2gb.test_gles2_uniform_arrays
818+
browser_2gb.test_fetch_to_memory
819+
browser_2gb.test_emscripten_animate_canvas_element_size_manual_css
820+
"
814821
test-browser-chrome-wasm64-4gb:
815822
executor: bionic
816823
steps:
@@ -823,6 +830,7 @@ jobs:
823830
browser64_4gb.test_emscripten_log
824831
browser64_4gb.test_clientside_vertex_arrays_es3
825832
browser64_4gb.test_fetch*
833+
browser64_4gb.test_emscripten_animate_canvas_element_size_manual_css
826834
"
827835
test-browser-firefox:
828836
executor: bionic
@@ -978,6 +986,9 @@ workflows:
978986
- test-browser-chrome:
979987
requires:
980988
- build-linux
989+
- test-browser-chrome-2gb:
990+
requires:
991+
- build-linux
981992
- test-browser-chrome-wasm64:
982993
requires:
983994
- build-linux

src/library_html5_webgl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var LibraryHtml5WebGL = {
5757
#if ASSERTIONS
5858
assert(attributes);
5959
#endif
60-
var a = attributes >> 2;
60+
var a = {{{ getHeapOffset('attributes', 'i32') }}};
6161
var powerPreference = HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.powerPreference }}}>>2)];
6262
var contextAttributes = {
6363
'alpha': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}}>>2)],
@@ -184,7 +184,7 @@ var LibraryHtml5WebGL = {
184184
},
185185
#if PTHREADS && OFFSCREEN_FRAMEBUFFER
186186
// Runs on the calling thread, proxies if needed.
187-
emscripten_webgl_make_context_current_calling_thread__sig: 'ii',
187+
emscripten_webgl_make_context_current_calling_thread__sig: 'ip',
188188
emscripten_webgl_make_context_current_calling_thread: (contextHandle) => {
189189
var success = GL.makeContextCurrent(contextHandle);
190190
if (success) GL.currentContextIsProxied = false; // If succeeded above, we will have a local GL context from this thread (worker or main).

test/canvas_animate_resize.cpp renamed to test/canvas_animate_resize.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdbool.h>
12
#include <stdio.h>
23
#include <string.h>
34
#include <pthread.h>
@@ -33,8 +34,7 @@ int program;
3334
int frameNumber = 0;
3435
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx;
3536

36-
void tick()
37-
{
37+
void tick() {
3838
double sizeScale = 21.0 + 20.0 * sin(emscripten_get_now()*0.001);
3939
double w = 18.0*sizeScale;
4040
double h = 11.0*sizeScale;
@@ -73,8 +73,7 @@ void tick()
7373
#endif
7474

7575
++frameNumber;
76-
if (frameNumber >= NUM_FRAMES_TO_RENDER)
77-
{
76+
if (frameNumber >= NUM_FRAMES_TO_RENDER) {
7877
#if TEST_EMSCRIPTEN_SET_MAIN_LOOP
7978
emscripten_cancel_main_loop();
8079
#endif
@@ -85,8 +84,8 @@ void tick()
8584
}
8685
}
8786

88-
void init()
89-
{
87+
void init() {
88+
printf("init\n");
9089
glGenBuffers(1, &vb);
9190
glBindBuffer(GL_ARRAY_BUFFER, vb);
9291
float vertices[] = { -1, -1, -1, 1, 1, -1, 1, 1 };
@@ -123,9 +122,8 @@ int main()
123122
attr.explicitSwapControl = EM_TRUE;
124123
#endif
125124
ctx = emscripten_webgl_create_context("#canvas", &attr);
126-
printf("Created context with handle %u\n", (unsigned int)ctx);
127-
if (!ctx)
128-
{
125+
printf("Created context with handle %#lx\n", ctx);
126+
if (!ctx) {
129127
if (!emscripten_supports_offscreencanvas()) {
130128
EM_ASM({
131129
xhr = new XMLHttpRequest();
@@ -144,8 +142,7 @@ int main()
144142
#if TEST_EMSCRIPTEN_SET_MAIN_LOOP
145143
emscripten_set_main_loop(tick, 0, 0);
146144
#else
147-
for(int i = 0; i < NUM_FRAMES_TO_RENDER; ++i)
148-
{
145+
for (int i = 0; i < NUM_FRAMES_TO_RENDER; ++i) {
149146
tick();
150147
emscripten_current_thread_process_queued_calls();
151148
usleep(16*1000);

test/common.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def decorator(f):
227227

228228
@wraps(f)
229229
def decorated(self, *args, **kwargs):
230-
if self.get_setting('INITIAL_MEMORY') == '4200mb':
230+
if self.is_4gb():
231231
self.skipTest(note)
232232
f(self, *args, **kwargs)
233233
return decorated
@@ -659,6 +659,12 @@ def is_browser_test(self):
659659
def is_wasm64(self):
660660
return self.get_setting('MEMORY64')
661661

662+
def is_4gb(self):
663+
return self.get_setting('INITIAL_MEMORY') == '4200mb'
664+
665+
def is_2gb(self):
666+
return self.get_setting('INITIAL_MEMORY') == '2200mb'
667+
662668
def check_dylink(self):
663669
if self.get_setting('ALLOW_MEMORY_GROWTH') == 1 and not self.is_wasm():
664670
self.skipTest('no dynamic linking with memory growth (without wasm)')

test/test_browser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4987,10 +4987,14 @@ def test_pthread_run_script(self, args):
49874987
'manual_css': (['-sPROXY_TO_PTHREAD', '-pthread', '-sOFFSCREEN_FRAMEBUFFER', '-DTEST_EXPLICIT_CONTEXT_SWAP=1', '-DTEST_MANUALLY_SET_ELEMENT_CSS_SIZE=1'], False),
49884988
})
49894989
def test_emscripten_animate_canvas_element_size(self, args, main_loop):
4990-
cmd = ['-lGL', '-O3', '-g2', '--shell-file', test_file('canvas_animate_resize_shell.html'), '-sGL_DEBUG', '--threadprofiler', '-sASSERTIONS'] + args
4990+
cmd = ['-lGL', '-O3', '-g2', '--shell-file', test_file('canvas_animate_resize_shell.html'), '-sGL_DEBUG', '-sASSERTIONS'] + args
4991+
if not self.is_2gb() and not self.is_4gb():
4992+
# Thread profiler does not yet work with large pointers.
4993+
# https://github.com/emscripten-core/emscripten/issues/21229
4994+
cmd.append('--threadprofiler')
49914995
if main_loop:
49924996
cmd.append('-DTEST_EMSCRIPTEN_SET_MAIN_LOOP=1')
4993-
self.btest_exit('canvas_animate_resize.cpp', args=cmd)
4997+
self.btest_exit('canvas_animate_resize.c', args=cmd)
49944998

49954999
# Tests the absolute minimum pthread-enabled application.
49965000
@parameterized({

0 commit comments

Comments
 (0)