Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix emscripten_webgl_make_context_current under wasm64/CAN_ADDRESS_2GB #21228

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -799,10 +799,7 @@ jobs:
- run-tests-chrome:
title: "browser"
# Skip test_4gb_fail as it OOMs on the current bot
# Include an representative selection of browser_2gb
test_targets: "
browser_2gb.test_gles2_uniform_arrays
browser_2gb.test_fetch_to_memory
browser skip:browser.test_4gb_fail
"
test-browser-chrome-wasm64:
Expand All @@ -811,6 +808,16 @@ jobs:
- run-tests-chrome:
title: "browser64"
test_targets: "browser64"
test-browser-chrome-2gb:
executor: bionic
steps:
- run-tests-chrome:
title: "browser_2gb"
test_targets: "
browser_2gb.test_gles2_uniform_arrays
browser_2gb.test_fetch_to_memory
browser_2gb.test_emscripten_animate_canvas_element_size_manual_css
"
test-browser-chrome-wasm64-4gb:
executor: bionic
steps:
Expand All @@ -823,6 +830,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 Expand Up @@ -978,6 +986,9 @@ workflows:
- test-browser-chrome:
requires:
- build-linux
- test-browser-chrome-2gb:
requires:
- build-linux
- test-browser-chrome-wasm64:
requires:
- build-linux
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 profiler 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
Loading