Skip to content

Commit 10218cd

Browse files
committed
[wasm64] Fix offscreen canvas and offscreen framebuffer.
1 parent 00eae74 commit 10218cd

18 files changed

+271
-137
lines changed

emscripten.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ def create_pointer_conversion_wrappers(metadata):
937937
'emscripten_proxy_finish': '_p',
938938
'emscripten_proxy_execute_queue': '_p',
939939
'_emval_coro_resume': '_pp',
940+
'emscripten_main_runtime_thread_id': 'p',
940941
}
941942

942943
for function in settings.SIGNATURE_CONVERSIONS:

src/generated_struct_info32.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
"EM_FUNC_SIG_PARAM_F": 2,
208208
"EM_FUNC_SIG_PARAM_F2I": 5,
209209
"EM_FUNC_SIG_PARAM_I": 0,
210-
"EM_FUNC_SIG_PARAM_I64": 1,
210+
"EM_FUNC_SIG_PARAM_J": 1,
211211
"EM_HTML5_LONG_STRING_LEN_BYTES": 128,
212212
"EM_HTML5_MEDIUM_STRING_LEN_BYTES": 64,
213213
"EM_HTML5_SHORT_STRING_LEN_BYTES": 32,

src/generated_struct_info64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
"EM_FUNC_SIG_PARAM_F": 2,
208208
"EM_FUNC_SIG_PARAM_F2I": 5,
209209
"EM_FUNC_SIG_PARAM_I": 0,
210-
"EM_FUNC_SIG_PARAM_I64": 1,
210+
"EM_FUNC_SIG_PARAM_J": 1,
211211
"EM_HTML5_LONG_STRING_LEN_BYTES": 128,
212212
"EM_HTML5_MEDIUM_STRING_LEN_BYTES": 64,
213213
"EM_HTML5_SHORT_STRING_LEN_BYTES": 32,

src/library_pthread.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
#error "EVAL_CTORS is not compatible with pthreads yet (passive segments)"
2424
#endif
2525

26+
{{{
27+
#if MEMORY64
28+
globalThis.MAX_PTR = Number((2n ** 64n) - 1n);
29+
#else
30+
globalThis.MAX_PTR = (2 ** 32) - 1
31+
#endif
32+
}}}
33+
2634
var LibraryPThread = {
2735
$PThread__postset: 'PThread.init();',
2836
$PThread__deps: ['_emscripten_thread_init',
@@ -763,11 +771,12 @@ var LibraryPThread = {
763771
// Comma-delimited list of CSS selectors that must identify canvases by IDs: "#canvas1, #canvas2, ..."
764772
var transferredCanvasNames = attr ? {{{ makeGetValue('attr', C_STRUCTS.pthread_attr_t._a_transferredcanvases, '*') }}} : 0;
765773
#if OFFSCREENCANVASES_TO_PTHREAD
766-
// Proxied canvases string pointer -1 is used as a special token to fetch
767-
// whatever canvases were passed to build in -s
768-
// OFFSCREENCANVASES_TO_PTHREAD= command line.
769-
if (transferredCanvasNames == (-1 >>> 0)) transferredCanvasNames = '{{{ OFFSCREENCANVASES_TO_PTHREAD }}}';
770-
else
774+
// Proxied canvases string pointer -1/MAX_PTR is used as a special token to
775+
// fetch whatever canvases were passed to build in
776+
// -sOFFSCREENCANVASES_TO_PTHREAD= command line.
777+
if (transferredCanvasNames == {{{ MAX_PTR }}}) {
778+
transferredCanvasNames = '{{{ OFFSCREENCANVASES_TO_PTHREAD }}}';
779+
} else
771780
#endif
772781
if (transferredCanvasNames) transferredCanvasNames = UTF8ToString(transferredCanvasNames).trim();
773782
if (transferredCanvasNames) transferredCanvasNames = transferredCanvasNames.split(',');
@@ -816,10 +825,10 @@ var LibraryPThread = {
816825
// Create a shared information block in heap so that we can control
817826
// the canvas size from any thread.
818827
if (!canvas.canvasSharedPtr) {
819-
canvas.canvasSharedPtr = _malloc(12);
828+
canvas.canvasSharedPtr = _malloc({{{ 8 + POINTER_SIZE }}});
820829
{{{ makeSetValue('canvas.canvasSharedPtr', 0, 'canvas.width', 'i32') }}};
821830
{{{ makeSetValue('canvas.canvasSharedPtr', 4, 'canvas.height', 'i32') }}};
822-
{{{ makeSetValue('canvas.canvasSharedPtr', 8, 0, 'i32') }}}; // pthread ptr to the thread that owns this canvas, filled in below.
831+
{{{ makeSetValue('canvas.canvasSharedPtr', 8, 0, '*') }}}; // pthread ptr to the thread that owns this canvas, filled in below.
823832
}
824833
offscreenCanvasInfo = {
825834
offscreenCanvas: canvas.transferControlToOffscreen(),

src/library_sigs.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ sigs = {
669669
emscripten_idb_read_from_blob__sig: 'viiip',
670670
emscripten_idb_store__sig: 'vpppip',
671671
emscripten_idb_store_blob__sig: 'vpppip',
672-
emscripten_is_webgl_context_lost__sig: 'ii',
672+
emscripten_is_webgl_context_lost__sig: 'ip',
673673
emscripten_lazy_load_code__sig: 'v',
674674
emscripten_lock_async_acquire__sig: 'vpppd',
675675
emscripten_lock_orientation__sig: 'ii',
@@ -850,21 +850,21 @@ sigs = {
850850
emscripten_wasm_worker_post_function_viii__sig: 'vipiii',
851851
emscripten_wasm_worker_self_id__sig: 'i',
852852
emscripten_webgl_commit_frame__sig: 'i',
853-
emscripten_webgl_create_context__sig: 'ipp',
854-
emscripten_webgl_destroy_context__sig: 'ii',
853+
emscripten_webgl_create_context__sig: 'ppp',
854+
emscripten_webgl_destroy_context__sig: 'ip',
855855
emscripten_webgl_do_commit_frame__sig: 'i',
856-
emscripten_webgl_do_create_context__sig: 'ipp',
857-
emscripten_webgl_do_get_current_context__sig: 'i',
858-
emscripten_webgl_enable_ANGLE_instanced_arrays__sig: 'ii',
859-
emscripten_webgl_enable_OES_vertex_array_object__sig: 'ii',
860-
emscripten_webgl_enable_WEBGL_draw_buffers__sig: 'ii',
861-
emscripten_webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance__sig: 'ii',
862-
emscripten_webgl_enable_WEBGL_multi_draw__sig: 'ii',
863-
emscripten_webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance__sig: 'ii',
864-
emscripten_webgl_enable_extension__sig: 'iip',
865-
emscripten_webgl_get_context_attributes__sig: 'iip',
866-
emscripten_webgl_get_current_context__sig: 'i',
867-
emscripten_webgl_get_drawing_buffer_size__sig: 'iipp',
856+
emscripten_webgl_do_create_context__sig: 'ppp',
857+
emscripten_webgl_do_get_current_context__sig: 'p',
858+
emscripten_webgl_enable_ANGLE_instanced_arrays__sig: 'ip',
859+
emscripten_webgl_enable_OES_vertex_array_object__sig: 'ip',
860+
emscripten_webgl_enable_WEBGL_draw_buffers__sig: 'ip',
861+
emscripten_webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance__sig: 'ip',
862+
emscripten_webgl_enable_WEBGL_multi_draw__sig: 'ip',
863+
emscripten_webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance__sig: 'ip',
864+
emscripten_webgl_enable_extension__sig: 'ipp',
865+
emscripten_webgl_get_context_attributes__sig: 'ipp',
866+
emscripten_webgl_get_current_context__sig: 'p',
867+
emscripten_webgl_get_drawing_buffer_size__sig: 'ippp',
868868
emscripten_webgl_get_parameter_d__sig: 'di',
869869
emscripten_webgl_get_parameter_i64v__sig: 'vip',
870870
emscripten_webgl_get_parameter_o__sig: 'ii',
@@ -882,7 +882,7 @@ sigs = {
882882
emscripten_webgl_get_vertex_attrib_o__sig: 'iii',
883883
emscripten_webgl_get_vertex_attrib_v__sig: 'iiipii',
884884
emscripten_webgl_init_context_attributes__sig: 'vp',
885-
emscripten_webgl_make_context_current__sig: 'ii',
885+
emscripten_webgl_make_context_current__sig: 'ip',
886886
emscripten_webgpu_export_bind_group__sig: 'ip',
887887
emscripten_webgpu_export_bind_group_layout__sig: 'ip',
888888
emscripten_webgpu_export_buffer__sig: 'ip',

src/library_webgl.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -991,15 +991,16 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
991991

992992
registerContext: (ctx, webGLContextAttributes) => {
993993
#if PTHREADS
994-
// with pthreads a context is a location in memory with some synchronized data between threads
995-
var handle = _malloc(8);
994+
// with pthreads a context is a location in memory with some synchronized
995+
// data between threads
996+
var handle = _malloc({{{ 2 * POINTER_SIZE }}});
996997
#if GL_ASSERTIONS
997998
assert(handle, 'malloc() failed in GL.registerContext!');
998999
#endif
9991000
#if GL_SUPPORT_EXPLICIT_SWAP_CONTROL
1000-
{{{ makeSetValue('handle', 0, 'webGLContextAttributes.explicitSwapControl', 'i32')}}}; // explicitSwapControl
1001+
{{{ makeSetValue('handle', 0, 'webGLContextAttributes.explicitSwapControl', 'i32')}}};
10011002
#endif
1002-
{{{ makeSetValue('handle', 4, '_pthread_self()', 'i32')}}}; // the thread pointer of the thread that owns the control of the context
1003+
{{{ makeSetValue('handle', POINTER_SIZE, '_pthread_self()', '*')}}}; // the thread pointer of the thread that owns the control of the context
10031004
#else // PTHREADS
10041005
// without pthreads a context is just an integer ID
10051006
var handle = GL.getNewId(GL.contexts);
@@ -1307,7 +1308,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
13071308
break;
13081309
case 0x8DF8: // GL_SHADER_BINARY_FORMATS
13091310
#if GL_TRACK_ERRORS
1310-
if (type != {{{ cDefs.EM_FUNC_SIG_PARAM_I }}} && type != {{{ cDefs.EM_FUNC_SIG_PARAM_I64 }}}) {
1311+
if (type != {{{ cDefs.EM_FUNC_SIG_PARAM_I }}} && type != {{{ cDefs.EM_FUNC_SIG_PARAM_J }}}) {
13111312
GL.recordError(0x500); // GL_INVALID_ENUM
13121313
#if GL_ASSERTIONS
13131314
err(`GL_INVALID_ENUM in glGet${type}v(GL_SHADER_BINARY_FORMATS): Invalid parameter type!`);
@@ -1464,7 +1465,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
14641465
}
14651466

14661467
switch (type) {
1467-
case {{{ cDefs.EM_FUNC_SIG_PARAM_I64 }}}: writeI53ToI64(p, ret); break;
1468+
case {{{ cDefs.EM_FUNC_SIG_PARAM_J }}}: writeI53ToI64(p, ret); break;
14681469
case {{{ cDefs.EM_FUNC_SIG_PARAM_I }}}: {{{ makeSetValue('p', '0', 'ret', 'i32') }}}; break;
14691470
case {{{ cDefs.EM_FUNC_SIG_PARAM_F }}}: {{{ makeSetValue('p', '0', 'ret', 'float') }}}; break;
14701471
case {{{ cDefs.EM_FUNC_SIG_PARAM_B }}}: {{{ makeSetValue('p', '0', 'ret ? 1 : 0', 'i8') }}}; break;

src/library_webgl2.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var LibraryWebGL2 = {
4545

4646
glGetInteger64v__deps: ['$emscriptenWebGLGet'],
4747
glGetInteger64v: (name_, p) => {
48-
emscriptenWebGLGet(name_, p, {{{ cDefs.EM_FUNC_SIG_PARAM_I64 }}});
48+
emscriptenWebGLGet(name_, p, {{{ cDefs.EM_FUNC_SIG_PARAM_J }}});
4949
},
5050

5151
glGetInternalformativ: (target, internalformat, pname, bufSize, params) => {
@@ -456,7 +456,7 @@ var LibraryWebGL2 = {
456456
}
457457

458458
switch (type) {
459-
case {{{ cDefs.EM_FUNC_SIG_PARAM_I64 }}}: writeI53ToI64(data, ret); break;
459+
case {{{ cDefs.EM_FUNC_SIG_PARAM_J }}}: writeI53ToI64(data, ret); break;
460460
case {{{ cDefs.EM_FUNC_SIG_PARAM_I }}}: {{{ makeSetValue('data', '0', 'ret', 'i32') }}}; break;
461461
case {{{ cDefs.EM_FUNC_SIG_PARAM_F }}}: {{{ makeSetValue('data', '0', 'ret', 'float') }}}; break;
462462
case {{{ cDefs.EM_FUNC_SIG_PARAM_B }}}: {{{ makeSetValue('data', '0', 'ret ? 1 : 0', 'i8') }}}; break;
@@ -470,7 +470,7 @@ var LibraryWebGL2 = {
470470

471471
glGetInteger64i_v__deps: ['$emscriptenWebGLGetIndexed'],
472472
glGetInteger64i_v: (target, index, data) =>
473-
emscriptenWebGLGetIndexed(target, index, data, {{{ cDefs.EM_FUNC_SIG_PARAM_I64 }}}),
473+
emscriptenWebGLGetIndexed(target, index, data, {{{ cDefs.EM_FUNC_SIG_PARAM_J }}}),
474474

475475
// Uniform Buffer objects
476476
glBindBufferBase: (target, index, buffer) => {

src/struct_info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@
951951
"file": "emscripten/threading.h",
952952
"defines": [
953953
"EM_FUNC_SIG_PARAM_I",
954-
"EM_FUNC_SIG_PARAM_I64",
954+
"EM_FUNC_SIG_PARAM_J",
955955
"EM_FUNC_SIG_PARAM_F",
956956
"EM_FUNC_SIG_PARAM_D",
957957
"EM_FUNC_SIG_PARAM_B",

src/threadprofiler.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ var emscriptenThreadProfiler = {
4444
var profilerBlock = Atomics.load(HEAPU32, (threadPtr + 8 /* {{{ C_STRUCTS.pthread.profilerBlock }}}*/) >> 2);
4545
var threadName = PThread.getThreadName(threadPtr);
4646
if (threadName) {
47-
threadName = '"' + threadName + '" (' + ptrToString(threadPtr) + ')';
47+
threadName = `"${threadName}" (${ptrToString(threadPtr)})`;
4848
} else {
49-
threadName = '(' + ptrToString(threadPtr) + ')';
49+
threadName = `(${ptrToString(threadPtr)}})`;
5050
}
5151

52-
console.log('Thread ' + threadName + ' now: ' + PThread.threadStatusAsString(threadPtr) + '. ');
52+
console.log(`Thread ${threadName} now: ${PThread.threadStatusAsString(threadPtr)}. `);
5353
}
5454
},
5555

@@ -72,27 +72,28 @@ var emscriptenThreadProfiler = {
7272
var profilerBlock = Atomics.load(HEAPU32, (threadPtr + 8 /* {{{ C_STRUCTS.pthread.profilerBlock }}}*/) >> 2);
7373
var threadName = PThread.getThreadName(threadPtr);
7474
if (threadName) {
75-
threadName = '"' + threadName + '" (' + ptrToString(threadPtr) + ')';
75+
threadName = `"${threadName}" (${ptrToString(threadPtr)})`;
7676
} else {
77-
threadName = '(' + ptrToString(threadPtr) + ')';
77+
threadName = `(${ptrToString(threadPtr)})`;
7878
}
7979

80-
str += 'Thread ' + threadName + ' now: ' + PThread.threadStatusAsString(threadPtr) + '. ';
80+
str += `Thread ${threadName} now: ${PThread.threadStatusAsString(threadPtr)}. `;
8181

8282
var threadTimesInStatus = [];
8383
var totalTime = 0;
84-
for (var j = 0; j < 7/*EM_THREAD_STATUS_NUMFIELDS*/; ++j) {
85-
threadTimesInStatus.push(HEAPF64[((profilerBlock + 16/*C_STRUCTS.thread_profiler_block.timeSpentInStatus*/) >> 3) + j]);
84+
var offset = profilerBlock + 16/*C_STRUCTS.thread_profiler_block.timeSpentInStatus*/;
85+
for (var j = 0; j < 7/*EM_THREAD_STATUS_NUMFIELDS*/; ++j, offset += 8) {
86+
threadTimesInStatus.push(Number(getValue(offset, 'double')));
8687
totalTime += threadTimesInStatus[j];
87-
HEAPF64[((profilerBlock + 16/*C_STRUCTS.thread_profiler_block.timeSpentInStatus*/) >> 3) + j] = 0;
88+
setValue(offset, 0, 'double');
8889
}
8990
var recent = '';
9091
if (threadTimesInStatus[1] > 0) recent += (threadTimesInStatus[1] / totalTime * 100.0).toFixed(1) + '% running. ';
9192
if (threadTimesInStatus[2] > 0) recent += (threadTimesInStatus[2] / totalTime * 100.0).toFixed(1) + '% sleeping. ';
9293
if (threadTimesInStatus[3] > 0) recent += (threadTimesInStatus[3] / totalTime * 100.0).toFixed(1) + '% waiting for futex. ';
9394
if (threadTimesInStatus[4] > 0) recent += (threadTimesInStatus[4] / totalTime * 100.0).toFixed(1) + '% waiting for mutex. ';
9495
if (threadTimesInStatus[5] > 0) recent += (threadTimesInStatus[5] / totalTime * 100.0).toFixed(1) + '% waiting for proxied ops. ';
95-
if (recent.length > 0) str += 'Recent activity: ' + recent;
96+
if (recent.length > 0) str += `Recent activity: ${recent}`;
9697
str += '<br />';
9798
}
9899
this.threadProfilerDiv.innerHTML = str;

system/include/emscripten/html5_webgl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
#pragma once
99

10+
#include <stdint.h>
1011
#include <emscripten/html5.h>
1112

1213
#ifdef __cplusplus
1314
extern "C" {
1415
#endif
1516

16-
typedef int EMSCRIPTEN_WEBGL_CONTEXT_HANDLE;
17+
typedef intptr_t EMSCRIPTEN_WEBGL_CONTEXT_HANDLE;
1718

1819
typedef int EMSCRIPTEN_WEBGL_CONTEXT_PROXY_MODE;
1920
#define EMSCRIPTEN_WEBGL_CONTEXT_PROXY_DISALLOW 0

0 commit comments

Comments
 (0)