Skip to content

Commit

Permalink
fix merge conflict (emscripten-core#5296)
Browse files Browse the repository at this point in the history
  • Loading branch information
buu700 committed Jun 16, 2017
2 parents 7830cc1 + 04eae7b commit 9a96344
Show file tree
Hide file tree
Showing 35 changed files with 351 additions and 102 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,4 @@ a license to everyone to use it as detailed in LICENSE.)
* Yair Levinson (copyright owned by Autodesk, Inc.)
* Matjaž Drolc <[email protected]>
* James Swift <[email protected]> (copyright owned by PSPDFKit GmbH)
* Sam Clegg <[email protected]> (copyright owned by Google, Inc.
24 changes: 11 additions & 13 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
final = None


class Intermediate:
class Intermediate(object):
counter = 0
def save_intermediate(name=None, suffix='js'):
name = os.path.join(shared.get_emscripten_temp_dir(), 'emcc-%d%s.%s' % (Intermediate.counter, '' if name is None else '-' + name, suffix))
Expand All @@ -105,7 +105,7 @@ def save_intermediate(name=None, suffix='js'):
Intermediate.counter += 1


class TimeLogger:
class TimeLogger(object):
last = time.time()

@staticmethod
Expand All @@ -120,7 +120,7 @@ def log_time(name):
TimeLogger.update()


class EmccOptions:
class EmccOptions(object):
def __init__(self):
self.opt_level = 0
self.debug_level = 0
Expand Down Expand Up @@ -166,7 +166,7 @@ def __init__(self):
self.output_eol = os.linesep


class JSOptimizer:
class JSOptimizer(object):
def __init__(self, target, options, misc_temp_files, js_transform_tempfiles):
self.queue = []
self.extra_info = {}
Expand Down Expand Up @@ -373,11 +373,10 @@ def run():
input_file = 'hello_world.c'
out, err = subprocess.Popen([shared.PYTHON] + args + [shared.path_from_root('tests', input_file), '-c', '-o', temp_target], stderr=subprocess.PIPE, env=debug_env).communicate()
lines = filter(lambda x: shared.CLANG_CC in x and input_file in x, err.split(os.linesep))
line = lines[0]
assert 'running:' in line
parts = line.split(' ')[2:]
line = re.search('running: (.*)', lines[0]).group(1)
parts = shlex.split(line)
parts = filter(lambda x: x != '-c' and x != '-o' and input_file not in x and temp_target not in x and '-emit-llvm' not in x, parts)
print ' '.join(parts)
print ' '.join(shared.Building.doublequote_spaces(parts))
exit(0)

def is_minus_s_for_emcc(newargs, i):
Expand Down Expand Up @@ -826,7 +825,7 @@ def get_last_setting_change(setting):

# If not compiling to JS, then we are compiling to an intermediate bitcode objects or library, so
# ignore dynamic linking, since multiple dynamic linkings can interfere with each other
if not filename_type_suffix(target) in JS_CONTAINING_SUFFIXES or options.ignore_dynamic_linking:
if filename_type_suffix(target) not in JS_CONTAINING_SUFFIXES or options.ignore_dynamic_linking:
def check(input_file):
if filename_type_ending(input_file) in DYNAMICLIB_ENDINGS:
if not options.ignore_dynamic_linking: logging.warning('ignoring dynamic library %s because not compiling to JS or HTML, remember to link it when compiling to JS or HTML at the end', os.path.basename(input_file))
Expand Down Expand Up @@ -1291,7 +1290,7 @@ def compile_source_file(i, input_file):
output_file = get_bitcode_file(input_file)
temp_files.append((i, output_file))
args = get_bitcode_args([input_file]) + ['-emit-llvm', '-c', '-o', output_file]
logging.debug("running: " + ' '.join(args))
logging.debug("running: " + ' '.join(shared.Building.doublequote_spaces(args))) # NOTE: Printing this line here in this specific format is important, it is parsed to implement the "emcc --cflags" command
execute(args) # let compiler frontend print directly, so colors are saved (PIPE kills that)
if not os.path.exists(output_file):
logging.error('compiler frontend failed to generate LLVM bitcode, halting')
Expand Down Expand Up @@ -1663,7 +1662,6 @@ def repl(m):
)
with ToolchainProfiler.profile_block('js opts'):
# It is useful to run several js optimizer passes together, to save on unneeded unparsing/reparsing

if shared.Settings.DEAD_FUNCTIONS:
optimizer.queue += ['eliminateDeadFuncs']
optimizer.extra_info['dead_functions'] = shared.Settings.DEAD_FUNCTIONS
Expand Down Expand Up @@ -2166,7 +2164,7 @@ def binaryen_method_sanity_check():
methods = shared.Settings.BINARYEN_METHOD.split(',')
valid_methods = ['asmjs', 'native-wasm', 'interpret-s-expr', 'interpret-binary', 'interpret-asm2wasm']
for m in methods:
if not m.strip() in valid_methods:
if m.strip() not in valid_methods:
logging.error('Unrecognized BINARYEN_METHOD "' + m.strip() + '" specified! Please pass a comma-delimited list containing one or more of: ' + ','.join(valid_methods))
sys.exit(1)

Expand Down Expand Up @@ -2533,7 +2531,7 @@ def system_js_libraries_setting_str(libs, lib_dirs, settings_changes, input_file
return 'SYSTEM_JS_LIBRARIES="' + ','.join(libraries) + '"'


class ScriptSource:
class ScriptSource(object):
def __init__(self):
self.src = None # if set, we have a script to load with a src attribute
self.inline = None # if set, we have the contents of a script to write inline in a script
Expand Down
7 changes: 5 additions & 2 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def unfloat(s):


def make_function_tables_defs(implemented_functions, all_implemented, function_table_data, settings, metadata):
class Counter:
class Counter(object):
next_bad_item = 0
next_item = 0
pre = []
Expand Down Expand Up @@ -2076,7 +2076,10 @@ def main(args, compiler_engine, cache, temp_files, DEBUG):
settings = {}
for setting in args.settings:
name, value = setting.strip().split('=', 1)
settings[name] = json.loads(value)
value = json.loads(value)
if isinstance(value, unicode):
value = value.encode('utf8')
settings[name] = value

# libraries
libraries = args.libraries[0].split(',') if len(args.libraries) > 0 else []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ OpenGL support in Emscripten

Emscripten provides three OpenGL modes:

- :ref:`opengl-support-webgl-subset` (default) — supports the set of OpenGL ES commands that map directly to WebGL.
- :ref:`opengl-support-opengl-es2-0-emulation` — support for some emulated OpenGL ES 2.0 features that are not present in WebGL.
- :ref:`opengl-support-webgl-subset` (default) — supports the set of OpenGL ES 2.0/3.0 commands that map directly to WebGL 1/2.
- :ref:`opengl-support-opengl-es2-0-emulation` — support for some emulated OpenGL ES 2.0/3.0 features that are not present in WebGL.
- :ref:`opengl-support-legacy_and_mobile` — support for a number of legacy GL 1.x features and commands.

This topic provides information about the modes, and how they are enabled.
Expand All @@ -16,21 +16,23 @@ This topic provides information about the modes, and how they are enabled.

.. _opengl-support-webgl-subset:

WebGL-friendly subset of OpenGL ES
==================================
WebGL-friendly subset of OpenGL ES 2.0/3.0
==========================================

By default, Emscripten targets the WebGL-friendly subset of OpenGL ES 2.0. This is the set of GL ES commands that map directly to WebGL, so that each GL command has a roughly direct mapping to WebGL. It includes almost all of OpenGL ES 2.0, with the notable exception of client-side arrays, and some other features that are listed in `WebGL 1.0 Specification/Chapter 6 <https://www.khronos.org/registry/webgl/specs/1.0/#6>`_.

To program against the WebGL subset of OpenGL ES, one uses the GL ES 2.0 header files and the GL ES 2.0 API, while adhering to the limitations specified in Chapter 6 of the WebGL specification.

This mode is used by default because it best matches the WebGL features brovided by browsers.

To target WebGL 2, pass the linker flag ``-s USE_WEBGL2=1``. Specifying this flag enables (and defaults to, unless otherwise specified at context creation time) the creation of WebGL 2 contexts at runtime, but it is still possible to create WebGL 1 contexts, so applications can choose whether to require WebGL 2 or whether to support a fallback to WebGL 1.

.. _opengl-support-opengl-es2-0-emulation:

OpenGL ES 2.0 emulation
=======================
OpenGL ES 2.0/3.0 emulation
===========================

This build mode emulates some features of OpenGL ES 2.0 that are not part of the core WebGL 1 specification.
This build mode emulates some features of OpenGL ES 2.0/3.0 that are not part of the core WebGL 1 specification.

In particular, this mode emulates client-side arrays that are missing [#f1]_ from the :ref:`opengl-support-webgl-subset`.

Expand All @@ -40,6 +42,8 @@ This allows you to use functions `glDrawArrays <https://www.opengl.org/sdk/docs/

To enable *OpenGL ES 2.0 emulation*, specify the :ref:`emcc <emcc-s-option-value>` option ``-s FULL_ES2=1`` when linking the final executable (.js/.html) of the project.

To enable *OpenGL ES 3.0 emulation*, specify the :ref:`emcc <emcc-s-option-value>` option ``-s FULL_ES3=1`` when linking the final executable (.js/.html) of the project. This adds emulation for mapping memory blocks to client side memory. The flags ``-s FULL_ES2=1`` and ``-s FULL_ES3=1`` are orthogonal, so either one or both can be specified to emulate different features.

.. _opengl-support-legacy_and_mobile:

Emulation of older Desktop OpenGL API features
Expand Down Expand Up @@ -72,6 +76,8 @@ When porting code, it should be noted that desktop OpenGL, OpenGL ES and WebGL e

Additionally, in WebGL, unlike in desktop or mobile OpenGL, extensions must be activated first before the features they expose take effect. If you use one of the native APIs SDL, EGL, GLUT or GLFW to create your GL context, this will be done automatically for most extensions. If instead you use the HTML5 WebGL context creation API, you must explicitly choose whether to autoenable WebGL extensions. If an extension was not automatically enabled at context creation time, the HTML5 API function `emscripten_webgl_enable_extension` can be used to activate it. Debugging related extensions, draft extensions and vendor-prefixed extensions (MOZ_*, WEBKIT_*) are never enabled automatically at context creation time, but must always be activated manually.

When migrating from WebGL 1 to WebGL 2, take note that some WebGL 1 extensions are migrated to core WebGL 2, and therefore their functionality is no longer advertised as GL extensions. This does not mean that the features would be missing, but that it is possible to utilize these features in WebGL 2 without needing to feature test the presence of a GL extension first.

Test code/examples
==================

Expand Down
4 changes: 3 additions & 1 deletion src/embind/embind.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ var LibraryEmbind = {
};
}

var isUnsignedType = (name.indexOf('unsigned') != -1);

registerType(primitiveType, {
name: name,
'fromWireType': fromWireType,
Expand All @@ -548,7 +550,7 @@ var LibraryEmbind = {
if (value < minRange || value > maxRange) {
throw new TypeError('Passing a number "' + _embind_repr(value) + '" from JS side to C/C++ side to an argument of type "' + name + '", which is outside the valid range [' + minRange + ', ' + maxRange + ']!');
}
return value | 0;
return isUnsignedType ? (value >>> 0) : (value | 0);
},
'argPackAdvance': 8,
'readValueFromPointer': integerReadValueFromPointer(name, shift, minRange !== 0),
Expand Down
2 changes: 1 addition & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ LibraryManager.library = {
totalMemory = getTotalMemory()|0;
if ((newDynamicTop|0) > (totalMemory|0)) {
if ((enlargeMemory()|0) == 0) {
___setErrNo({{{ cDefine('ENOMEM') }}});
HEAP32[DYNAMICTOP_PTR>>2] = oldDynamicTop;
___setErrNo({{{ cDefine('ENOMEM') }}});
return -1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/library_glfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ var LibraryGLFW = {
},

glfwSetTime: function(time) {
GLFW.initialTime = GLFW.getTime() + time;
GLFW.initialTime = GLFW.getTime() - time;
},

glfwExtensionSupported: function(extension) {
Expand Down
9 changes: 6 additions & 3 deletions src/library_sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3001,14 +3001,17 @@ var LibrarySDL = {
var w = SDL.estimateTextWidth(fontData, text);
var h = fontData.size;
var color = SDL.loadColorToCSSRGB(color); // XXX alpha breaks fonts?
var fontString = h + 'px ' + fontData.name;
var fontString = h + 'px ' + fontData.name + ', serif';
var surf = SDL.makeSurface(w, h, 0, false, 'text:' + text); // bogus numbers..
var surfData = SDL.surfaces[surf];
surfData.ctx.save();
surfData.ctx.fillStyle = color;
surfData.ctx.font = fontString;
surfData.ctx.textBaseline = 'top';
surfData.ctx.fillText(text, 0, 0);
// use bottom alligment, because it works
// same in all browsers, more info here:
// https://bugzilla.mozilla.org/show_bug.cgi?id=737852
surfData.ctx.textBaseline = 'bottom';
surfData.ctx.fillText(text, 0, h|0);
surfData.ctx.restore();
return surf;
},
Expand Down
26 changes: 23 additions & 3 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,8 @@ function enlargeMemory() {
Module.printErr('Expected to get back a buffer of size ' + TOTAL_MEMORY + ' bytes, but instead got back a buffer of size ' + replacement.byteLength);
}
#endif
// restore the state to before this call, we failed
TOTAL_MEMORY = OLD_TOTAL_MEMORY;
return false;
}

Expand Down Expand Up @@ -1981,7 +1983,7 @@ addOnPreRun(function() {
addRunDependency('preload_dynamicLibraries');
var binaries = [];
Module['dynamicLibraries'].forEach(function(lib) {
fetch(lib).then(function(response) {
fetch(lib, { credentials: 'same-origin' }).then(function(response) {
if (!response['ok']) {
throw "failed to load wasm binary file at '" + lib + "'";
}
Expand Down Expand Up @@ -2229,7 +2231,7 @@ function integrateWasmJS(Module) {
function getBinaryPromise() {
// if we don't have the binary yet, and have the Fetch api, use that
if (!Module['wasmBinary'] && typeof fetch === 'function') {
return fetch(wasmBinaryFile).then(function(response) {
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
if (!response['ok']) {
throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
}
Expand Down Expand Up @@ -2404,12 +2406,16 @@ function integrateWasmJS(Module) {
Module['asmPreload'] = Module['asm'];

// Memory growth integration code
Module['reallocBuffer'] = function(size) {

var asmjsReallocBuffer = Module['reallocBuffer'];

var wasmReallocBuffer = function(size) {
var PAGE_MULTIPLE = Module["usingWasm"] ? WASM_PAGE_SIZE : ASMJS_PAGE_SIZE; // In wasm, heap size must be a multiple of 64KB. In asm.js, they need to be multiples of 16MB.
size = alignUp(size, PAGE_MULTIPLE); // round up to wasm page size
var old = Module['buffer'];
var oldSize = old.byteLength;
if (Module["usingWasm"]) {
// native wasm support
try {
var result = Module['wasmMemory'].grow((size - oldSize) / wasmPageSize); // .grow() takes a delta compared to the previous size
if (result !== (-1 | 0)) {
Expand All @@ -2425,12 +2431,24 @@ function integrateWasmJS(Module) {
return null;
}
} else {
// wasm interpreter support
exports['__growWasmMemory']((size - oldSize) / wasmPageSize); // tiny wasm method that just does grow_memory
// in interpreter, we replace Module.buffer if we allocate
return Module['buffer'] !== old ? Module['buffer'] : null; // if it was reallocated, it changed
}
};

Module['reallocBuffer'] = function(size) {
if (finalMethod === 'asmjs') {
return asmjsReallocBuffer(size);
} else {
return wasmReallocBuffer(size);
}
};

// we may try more than one; this is the final one, that worked and we are using
var finalMethod = '';

// Provide an "asm.js function" for the application, called to "link" the asm.js module. We instantiate
// the wasm module at that time, and it receives imports and provides exports and so forth, the app
// doesn't need to care that it is wasm or olyfilled wasm or asm.js.
Expand Down Expand Up @@ -2475,6 +2493,8 @@ function integrateWasmJS(Module) {
Module['printErr']('trying binaryen method: ' + curr);
#endif

finalMethod = curr;

if (curr === 'native-wasm') {
if (exports = doNativeWasm(global, env, providedBuffer)) break;
} else if (curr === 'asmjs') {
Expand Down
6 changes: 3 additions & 3 deletions tests/benchmark_sse1.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ def strip_comments(text):
charts_html = {}
for result in native_results['results']:
ch = result['chart']
if not ch in charts_native: charts_native[ch] = []
if ch not in charts_native: charts_native[ch] = []
charts_native[ch] += [result]
for result in html_results['results']:
ch = result['chart']
if not ch in charts_html: charts_html[ch] = []
if ch not in charts_html: charts_html[ch] = []
charts_html[ch] += [result]

def find_result_in_category(results, category):
Expand Down Expand Up @@ -298,4 +298,4 @@ def format_comparison(a, b):
html += '</body></html>'

open('results_sse1.html', 'w').write(html)
print 'Wrote ' + str(len(html)) + ' bytes to file results_sse1.html.'
print 'Wrote ' + str(len(html)) + ' bytes to file results_sse1.html.'
47 changes: 47 additions & 0 deletions tests/core/test_memorygrowth_3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include "emscripten.h"

int get_TOTAL_MEMORY() {
return EM_ASM_INT_V({ return TOTAL_MEMORY });
}

typedef void* voidStar;

int main(int argc, char **argv)
{
int totalMemory = get_TOTAL_MEMORY();
int chunk = 1024*1024;
volatile voidStar alloc;
#ifdef FAIL_REALLOC_BUFFER
EM_ASM({
Module.seenOurReallocBuffer = false;
Module['reallocBuffer'] = function() {
Module.seenOurReallocBuffer = true;
return null;
};
});
#endif
for (int i = 0; i < (totalMemory/chunk)+2; i++) {
// make sure state remains the same if malloc fails
void* sbrk_before = sbrk(0);
alloc = malloc(chunk);
printf("%d : %d\n", i, !!alloc);
if (alloc == NULL) {
assert(sbrk(0) == sbrk_before);
assert(totalMemory == get_TOTAL_MEMORY());
break;
}
}
assert(alloc == NULL);
#ifdef FAIL_REALLOC_BUFFER
EM_ASM({
assert(Module.seenOurReallocBuffer, 'our override should have been called');
});
#endif
puts("ok.");
return 0;
}
1 change: 1 addition & 0 deletions tests/core/test_memorygrowth_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ok.
Loading

0 comments on commit 9a96344

Please sign in to comment.