Skip to content

Commit

Permalink
opengl support for memory64
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippMuigg committed Mar 21, 2023
1 parent 6f793af commit 6d06901
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 241 deletions.
9 changes: 5 additions & 4 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2847,10 +2847,11 @@ def get_full_import_name(name):

# check if we can address the 2GB mark and higher: either if we start at
# 2GB, or if we allow growth to either any amount or to 2GB or more.
if settings.INITIAL_MEMORY > 2 * 1024 * 1024 * 1024 or \
(settings.ALLOW_MEMORY_GROWTH and
(settings.MAXIMUM_MEMORY < 0 or
settings.MAXIMUM_MEMORY > 2 * 1024 * 1024 * 1024)):
if settings.MEMORY64 == 0 and \
(settings.INITIAL_MEMORY > 2 * 1024 * 1024 * 1024 or
(settings.ALLOW_MEMORY_GROWTH and
(settings.MAXIMUM_MEMORY < 0 or
settings.MAXIMUM_MEMORY > 2 * 1024 * 1024 * 1024))):
settings.CAN_ADDRESS_2GB = 1

settings.EMSCRIPTEN_VERSION = shared.EMSCRIPTEN_VERSION
Expand Down
6 changes: 6 additions & 0 deletions src/embind/embind.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.
// SPDX-FileCopyrightText: Portions Copyright 2023 Siemens
// Modified on February 2023 by Siemens and/or its affiliates to improve memory64 support

/*global LibraryManager, mergeInto*/

Expand Down Expand Up @@ -447,7 +449,11 @@ var LibraryEmbind = {
} else {
throw new TypeError("Unknown boolean type size: " + name);
}
#if MEMORY64
return this['fromWireType'](heap[pointer / (1 << shift)]);
#else
return this['fromWireType'](heap[pointer >> shift]);
#endif
},
destructorFunction: null, // This type does not need a destructor
});
Expand Down
42 changes: 22 additions & 20 deletions src/library_egl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @license
* Copyright 2012 The Emscripten Authors
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: Portions Copyright 2023 Siemens
* Modified on February 2023 by Siemens and/or its affiliates to improve memory64 support
*/

/*
Expand Down Expand Up @@ -91,7 +93,7 @@ var LibraryEGL = {

// EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id);
eglGetDisplay__proxy: 'sync',
eglGetDisplay__sig: 'ii',
eglGetDisplay__sig: 'pp',
eglGetDisplay: function(nativeDisplayType) {
EGL.setErrorCode(0x3000 /* EGL_SUCCESS */);
// Note: As a 'conformant' implementation of EGL, we would prefer to init here only if the user
Expand All @@ -110,7 +112,7 @@ var LibraryEGL = {

// EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor);
eglInitialize__proxy: 'sync',
eglInitialize__sig: 'iiii',
eglInitialize__sig: 'ippp',
eglInitialize: function(display, majorVersion, minorVersion) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand All @@ -129,7 +131,7 @@ var LibraryEGL = {

// EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy);
eglTerminate__proxy: 'sync',
eglTerminate__sig: 'ii',
eglTerminate__sig: 'ip',
eglTerminate: function(display) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand All @@ -145,21 +147,21 @@ var LibraryEGL = {

// EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
eglGetConfigs__proxy: 'sync',
eglGetConfigs__sig: 'iiiii',
eglGetConfigs__sig: 'ippip',
eglGetConfigs: function(display, configs, config_size, numConfigs) {
return EGL.chooseConfig(display, 0, configs, config_size, numConfigs);
},

// EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
eglChooseConfig__proxy: 'sync',
eglChooseConfig__sig: 'iiiiii',
eglChooseConfig__sig: 'ipppip',
eglChooseConfig: function(display, attrib_list, configs, config_size, numConfigs) {
return EGL.chooseConfig(display, attrib_list, configs, config_size, numConfigs);
},

// EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
eglGetConfigAttrib__proxy: 'sync',
eglGetConfigAttrib__sig: 'iiiii',
eglGetConfigAttrib__sig: 'ippip',
eglGetConfigAttrib: function(display, config, attribute, value) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand Down Expand Up @@ -277,7 +279,7 @@ var LibraryEGL = {

// EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
eglCreateWindowSurface__proxy: 'sync',
eglCreateWindowSurface__sig: 'iiiii',
eglCreateWindowSurface__sig: 'ppppp',
eglCreateWindowSurface: function(display, config, win, attrib_list) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand All @@ -297,7 +299,7 @@ var LibraryEGL = {

// EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay display, EGLSurface surface);
eglDestroySurface__proxy: 'sync',
eglDestroySurface__sig: 'iii',
eglDestroySurface__sig: 'ipp',
eglDestroySurface: function(display, surface) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand All @@ -321,7 +323,7 @@ var LibraryEGL = {

// EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
eglCreateContext__proxy: 'sync',
eglCreateContext__sig: 'iiiii',
eglCreateContext__sig: 'ppppp',
eglCreateContext: function(display, config, hmm, contextAttribs) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand Down Expand Up @@ -386,7 +388,7 @@ var LibraryEGL = {

// EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext context);
eglDestroyContext__proxy: 'sync',
eglDestroyContext__sig: 'iii',
eglDestroyContext__sig: 'ipp',
eglDestroyContext: function(display, context) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand All @@ -407,7 +409,7 @@ var LibraryEGL = {

// EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
eglQuerySurface__proxy: 'sync',
eglQuerySurface__sig: 'iiiii',
eglQuerySurface__sig: 'ippip',
eglQuerySurface: function(display, surface, attribute, value) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand Down Expand Up @@ -474,7 +476,7 @@ var LibraryEGL = {

// EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value);
eglQueryContext__proxy: 'sync',
eglQueryContext__sig: 'iiiii',
eglQueryContext__sig: 'ippip',
eglQueryContext: function(display, context, attribute, value) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand Down Expand Up @@ -522,7 +524,7 @@ var LibraryEGL = {
// EGLAPI const char * EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name);
eglQueryString__deps: ['$allocateUTF8'],
eglQueryString__proxy: 'sync',
eglQueryString__sig: 'iii',
eglQueryString__sig: 'ppi',
eglQueryString: function(display, name) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand Down Expand Up @@ -589,7 +591,7 @@ var LibraryEGL = {
// EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval);
eglSwapInterval__deps: ['emscripten_set_main_loop_timing'],
eglSwapInterval__proxy: 'sync',
eglSwapInterval__sig: 'iii',
eglSwapInterval__sig: 'ipi',
eglSwapInterval: function(display, interval) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand All @@ -605,7 +607,7 @@ var LibraryEGL = {
// EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
eglMakeCurrent__deps: ['$GL'],
eglMakeCurrent__proxy: 'sync',
eglMakeCurrent__sig: 'iiiii',
eglMakeCurrent__sig: 'ipppp',
eglMakeCurrent: function(display, draw, read, context) {
if (display != 62000 /* Magic ID for Emscripten 'default display' */) {
EGL.setErrorCode(0x3008 /* EGL_BAD_DISPLAY */);
Expand All @@ -632,14 +634,14 @@ var LibraryEGL = {

// EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void);
eglGetCurrentContext__proxy: 'sync',
eglGetCurrentContext__sig: 'i',
eglGetCurrentContext__sig: 'p',
eglGetCurrentContext: function() {
return EGL.currentContext;
},

// EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw);
eglGetCurrentSurface__proxy: 'sync',
eglGetCurrentSurface__sig: 'ii',
eglGetCurrentSurface__sig: 'pi',
eglGetCurrentSurface: function(readdraw) {
if (readdraw == 0x305A /* EGL_READ */) {
return EGL.currentReadSurface;
Expand All @@ -653,15 +655,15 @@ var LibraryEGL = {

// EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void);
eglGetCurrentDisplay__proxy: 'sync',
eglGetCurrentDisplay__sig: 'i',
eglGetCurrentDisplay__sig: 'p',
eglGetCurrentDisplay: function() {
return EGL.currentContext ? 62000 /* Magic ID for Emscripten 'default display' */ : 0;
},

// EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface);
eglSwapBuffers__proxy: 'sync',
eglSwapBuffers__sig: 'iii',
eglSwapBuffers: function() {
eglSwapBuffers__sig: 'ipp',
eglSwapBuffers: function(dpy, surface) {
#if PROXY_TO_WORKER
if (Browser.doSwapBuffers) Browser.doSwapBuffers();
#endif
Expand Down
14 changes: 10 additions & 4 deletions src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @license
* Copyright 2014 The Emscripten Authors
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: Portions Copyright 2023 Siemens
* Modified on February 2023 by Siemens and/or its affiliates to improve memory64 support
*/

var LibraryHTML5 = {
Expand Down Expand Up @@ -314,7 +316,11 @@ var LibraryHTML5 = {
// values we accept here, EMSCRIPTEN_EVENT_TARGET_* (which map to 0, 1, 2).
// In other words, if cString > 2 then it's a pointer to a valid place in
// memory, and points to a C string.
#if MEMORY64
return cString > 2 ? UTF8ToString(Number(cString)) : cString;
#else
return cString > 2 ? UTF8ToString(cString) : cString;
#endif
},

$findEventTarget__deps: ['$maybeCStringToJsString', '$specialHTMLTargets'],
Expand Down Expand Up @@ -522,10 +528,10 @@ var LibraryHTML5 = {
if (targetThread) {
var mouseEventData = _malloc( {{{ C_STRUCTS.EmscriptenMouseEvent.__size__ }}} ); // This allocated block is passed as satellite data to the proxied function call, so the call frees up the data block when done.
fillMouseEventData(mouseEventData, e, target);
JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, mouseEventData, userData);
JSEvents.queueEventHandlerOnThread_iipp(targetThread, callbackfunc, eventTypeId, mouseEventData, userData);
} else
#endif
if ({{{ makeDynCall('iiii', 'callbackfunc') }}}(eventTypeId, JSEvents.mouseEvent, userData)) e.preventDefault();
if ({{{ makeDynCall('iipp', 'callbackfunc') }}}(eventTypeId, JSEvents.mouseEvent, userData)) e.preventDefault();
};

var eventHandler = {
Expand Down Expand Up @@ -652,7 +658,7 @@ var LibraryHTML5 = {
if (targetThread) JSEvents.queueEventHandlerOnThread_iiii(targetThread, callbackfunc, eventTypeId, wheelEvent, userData);
else
#endif
if ({{{ makeDynCall('iiii', 'callbackfunc') }}}(eventTypeId, wheelEvent, userData)) e.preventDefault();
if ({{{ makeDynCall('iipp', 'callbackfunc') }}}(eventTypeId, wheelEvent, userData)) e.preventDefault();
};
#if MIN_IE_VERSION <= 8 || MIN_SAFARI_VERSION < 60100 // Browsers that do not support https://caniuse.com/#feat=mdn-api_wheelevent
// The 'mousewheel' event as implemented in Safari 6.0.5
Expand All @@ -664,7 +670,7 @@ var LibraryHTML5 = {
{{{ makeSetValue('JSEvents.wheelEvent', C_STRUCTS.EmscriptenWheelEvent.deltaY, 'wheelDeltaY', 'double') }}};
{{{ makeSetValue('JSEvents.wheelEvent', C_STRUCTS.EmscriptenWheelEvent.deltaZ, '0 /* Not available */', 'double') }}};
{{{ makeSetValue('JSEvents.wheelEvent', C_STRUCTS.EmscriptenWheelEvent.deltaMode, '0 /* DOM_DELTA_PIXEL */', 'i32') }}};
var shouldCancel = {{{ makeDynCall('iiii', 'callbackfunc') }}}( eventTypeId, JSEvents.wheelEvent, userData);
var shouldCancel = {{{ makeDynCall('iipp', 'callbackfunc') }}}( eventTypeId, JSEvents.wheelEvent, userData);
if (shouldCancel) {
e.preventDefault();
}
Expand Down
Loading

0 comments on commit 6d06901

Please sign in to comment.