Skip to content

Commit

Permalink
Fix emscripten_webgl_make_context_current under wasm64/CAN_ADDRESS_2GB
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Jan 31, 2024
1 parent 876ae7c commit 518be0c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ jobs:
test_targets: "
browser_2gb.test_gles2_uniform_arrays
browser_2gb.test_fetch_to_memory
browser_2gb.test_emscripten_animate_canvas_element_size_manual_css
browser skip:browser.test_4gb_fail
"
test-browser-chrome-wasm64:
Expand All @@ -823,6 +824,7 @@ jobs:
browser64_4gb.test_emscripten_log
browser64_4gb.test_clientside_vertex_arrays_es3
browser64_4gb.test_fetch*
browser64_4gb.test_emscripten_animate_canvas_element_size_manual_css
"
test-browser-firefox:
executor: bionic
Expand Down
4 changes: 2 additions & 2 deletions src/library_html5_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var LibraryHtml5WebGL = {
#if ASSERTIONS
assert(attributes);
#endif
var a = attributes >> 2;
var a = {{{ getHeapOffset('attributes', 'i32') }}};
var powerPreference = HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.powerPreference }}}>>2)];
var contextAttributes = {
'alpha': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.alpha }}}>>2)],
Expand Down Expand Up @@ -184,7 +184,7 @@ var LibraryHtml5WebGL = {
},
#if PTHREADS && OFFSCREEN_FRAMEBUFFER
// Runs on the calling thread, proxies if needed.
emscripten_webgl_make_context_current_calling_thread__sig: 'ii',
emscripten_webgl_make_context_current_calling_thread__sig: 'ip',
emscripten_webgl_make_context_current_calling_thread: (contextHandle) => {
var success = GL.makeContextCurrent(contextHandle);
if (success) GL.currentContextIsProxied = false; // If succeeded above, we will have a local GL context from this thread (worker or main).
Expand Down
19 changes: 8 additions & 11 deletions test/canvas_animate_resize.cpp → test/canvas_animate_resize.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
Expand Down Expand Up @@ -33,8 +34,7 @@ int program;
int frameNumber = 0;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx;

void tick()
{
void tick() {
double sizeScale = 21.0 + 20.0 * sin(emscripten_get_now()*0.001);
double w = 18.0*sizeScale;
double h = 11.0*sizeScale;
Expand Down Expand Up @@ -73,8 +73,7 @@ void tick()
#endif

++frameNumber;
if (frameNumber >= NUM_FRAMES_TO_RENDER)
{
if (frameNumber >= NUM_FRAMES_TO_RENDER) {
#if TEST_EMSCRIPTEN_SET_MAIN_LOOP
emscripten_cancel_main_loop();
#endif
Expand All @@ -85,8 +84,8 @@ void tick()
}
}

void init()
{
void init() {
printf("init\n");
glGenBuffers(1, &vb);
glBindBuffer(GL_ARRAY_BUFFER, vb);
float vertices[] = { -1, -1, -1, 1, 1, -1, 1, 1 };
Expand Down Expand Up @@ -123,9 +122,8 @@ int main()
attr.explicitSwapControl = EM_TRUE;
#endif
ctx = emscripten_webgl_create_context("#canvas", &attr);
printf("Created context with handle %u\n", (unsigned int)ctx);
if (!ctx)
{
printf("Created context with handle %#lx\n", ctx);
if (!ctx) {
if (!emscripten_supports_offscreencanvas()) {
EM_ASM({
xhr = new XMLHttpRequest();
Expand All @@ -144,8 +142,7 @@ int main()
#if TEST_EMSCRIPTEN_SET_MAIN_LOOP
emscripten_set_main_loop(tick, 0, 0);
#else
for(int i = 0; i < NUM_FRAMES_TO_RENDER; ++i)
{
for (int i = 0; i < NUM_FRAMES_TO_RENDER; ++i) {
tick();
emscripten_current_thread_process_queued_calls();
usleep(16*1000);
Expand Down
8 changes: 7 additions & 1 deletion test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def decorator(f):

@wraps(f)
def decorated(self, *args, **kwargs):
if self.get_setting('INITIAL_MEMORY') == '4200mb':
if self.is_4gb():
self.skipTest(note)
f(self, *args, **kwargs)
return decorated
Expand Down Expand Up @@ -659,6 +659,12 @@ def is_browser_test(self):
def is_wasm64(self):
return self.get_setting('MEMORY64')

def is_4gb(self):
return self.get_setting('INITIAL_MEMORY') == '4200mb'

def is_2gb(self):
return self.get_setting('INITIAL_MEMORY') == '2200mb'

def check_dylink(self):
if self.get_setting('ALLOW_MEMORY_GROWTH') == 1 and not self.is_wasm():
self.skipTest('no dynamic linking with memory growth (without wasm)')
Expand Down
8 changes: 6 additions & 2 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4987,10 +4987,14 @@ def test_pthread_run_script(self, args):
'manual_css': (['-sPROXY_TO_PTHREAD', '-pthread', '-sOFFSCREEN_FRAMEBUFFER', '-DTEST_EXPLICIT_CONTEXT_SWAP=1', '-DTEST_MANUALLY_SET_ELEMENT_CSS_SIZE=1'], False),
})
def test_emscripten_animate_canvas_element_size(self, args, main_loop):
cmd = ['-lGL', '-O3', '-g2', '--shell-file', test_file('canvas_animate_resize_shell.html'), '-sGL_DEBUG', '--threadprofiler', '-sASSERTIONS'] + args
cmd = ['-lGL', '-O3', '-g2', '--shell-file', test_file('canvas_animate_resize_shell.html'), '-sGL_DEBUG', '-sASSERTIONS'] + args
if not self.is_2gb() and not self.is_4gb():
# Thread profiles does not yet work with large pointers.
# https://github.com/emscripten-core/emscripten/issues/21229
cmd.append('--threadprofiler')
if main_loop:
cmd.append('-DTEST_EMSCRIPTEN_SET_MAIN_LOOP=1')
self.btest_exit('canvas_animate_resize.cpp', args=cmd)
self.btest_exit('canvas_animate_resize.c', args=cmd)

# Tests the absolute minimum pthread-enabled application.
@parameterized({
Expand Down

0 comments on commit 518be0c

Please sign in to comment.