diff --git a/src/closure-externs/closure-externs.js b/src/closure-externs/closure-externs.js index 8361b3879..632e18b60 100644 --- a/src/closure-externs/closure-externs.js +++ b/src/closure-externs/closure-externs.js @@ -284,3 +284,9 @@ var registerProcessor = function(name, obj) {}; var currentFrame; var currentTime; var sampleRate; + +/* + * WebGPU globals + */ +var GPUValidationError; +var GPUOutOfMemoryError; diff --git a/src/library.js b/src/library.js index 93d88deee..bc257ffa2 100644 --- a/src/library.js +++ b/src/library.js @@ -2915,6 +2915,7 @@ LibraryManager.library = { }, emscripten_get_compiler_setting: function(name) { +#if RETAIN_COMPILER_SETTINGS name = UTF8ToString(name); var ret = getCompilerSetting(name); @@ -2926,6 +2927,9 @@ LibraryManager.library = { var fullret = cache[fullname]; if (fullret) return fullret; return cache[fullname] = allocate(intArrayFromString(ret + ''), ALLOC_NORMAL); +#else + throw 'You must build with -s RETAIN_COMPILER_SETTINGS=1 for getCompilerSetting or emscripten_get_compiler_setting to work'; +#endif }, emscripten_has_asyncify: function() { @@ -2948,7 +2952,7 @@ LibraryManager.library = { emscripten_generate_pc: function(frame) { #if !USE_OFFSET_CONVERTER abort('Cannot use emscripten_generate_pc (needed by __builtin_return_address) without -s USE_OFFSET_CONVERTER'); -#endif +#else var match; if (match = /\bwasm-function\[\d+\]:(0x[0-9a-f]+)/.exec(frame)) { @@ -2968,6 +2972,7 @@ LibraryManager.library = { // return 0 if we can't find any return 0; } +#endif }, // Returns a representation of a call site of the caller of this function, in a manner @@ -3069,15 +3074,19 @@ LibraryManager.library = { }, // Look up the function name from our stack frame cache with our PC representation. - emscripten_pc_get_function__deps: ['$UNWIND_CACHE', '$withBuiltinMalloc' + emscripten_pc_get_function__deps: [ +#if USE_OFFSET_CONVERTER + '$UNWIND_CACHE', + '$withBuiltinMalloc', #if MINIMAL_RUNTIME - , '$allocateUTF8' + '$allocateUTF8', +#endif #endif ], emscripten_pc_get_function: function (pc) { #if !USE_OFFSET_CONVERTER abort('Cannot use emscripten_pc_get_function without -s USE_OFFSET_CONVERTER'); -#endif +#else var name; if (pc & 0x80000000) { // If this is a JavaScript function, try looking it up in the unwind cache. @@ -3100,6 +3109,7 @@ LibraryManager.library = { _emscripten_pc_get_function.ret = allocateUTF8(name); }); return _emscripten_pc_get_function.ret; +#endif }, emscripten_pc_get_source_js__deps: ['$UNWIND_CACHE', 'emscripten_generate_pc'], diff --git a/src/library_browser.js b/src/library_browser.js index 7917e0dc3..a8a98a003 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -1558,6 +1558,7 @@ var LibraryBrowser = { } }, +#if BUILD_AS_WORKER emscripten_worker_respond_provisionally__proxy: 'sync', emscripten_worker_respond_provisionally__sig: 'vii', emscripten_worker_respond_provisionally: function(data, size) { @@ -1590,6 +1591,7 @@ var LibraryBrowser = { postMessage(transferObject); } }, +#endif emscripten_get_worker_queue_size__proxy: 'sync', emscripten_get_worker_queue_size__sig: 'i', diff --git a/src/library_glemu.js b/src/library_glemu.js index 14b4bb969..14909ab0e 100644 --- a/src/library_glemu.js +++ b/src/library_glemu.js @@ -3447,6 +3447,75 @@ var LibraryGLEmulation = { glDeleteFramebuffersOES : 'glDeleteFramebuffers', glDeleteRenderbuffersOES : 'glDeleteRenderbuffers', glFramebufferTexture2DOES: 'glFramebufferTexture2D', + + // GLU + + gluPerspective: function(fov, aspect, near, far) { + GLImmediate.matricesModified = true; + GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0; + GLImmediate.matrix[GLImmediate.currentMatrix] = + GLImmediate.matrixLib.mat4.perspective(fov, aspect, near, far, + GLImmediate.matrix[GLImmediate.currentMatrix]); + }, + + gluLookAt: function(ex, ey, ez, cx, cy, cz, ux, uy, uz) { + GLImmediate.matricesModified = true; + GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0; + GLImmediate.matrixLib.mat4.lookAt(GLImmediate.matrix[GLImmediate.currentMatrix], [ex, ey, ez], + [cx, cy, cz], [ux, uy, uz]); + }, + + gluProject: function(objX, objY, objZ, model, proj, view, winX, winY, winZ) { + // The algorithm for this functions comes from Mesa + + var inVec = new Float32Array(4); + var outVec = new Float32Array(4); + GLImmediate.matrixLib.mat4.multiplyVec4({{{ makeHEAPView('F64', 'model', 'model+' + (16*8)) }}}, + [objX, objY, objZ, 1.0], outVec); + GLImmediate.matrixLib.mat4.multiplyVec4({{{ makeHEAPView('F64', 'proj', 'proj+' + (16*8)) }}}, + outVec, inVec); + if (inVec[3] == 0.0) { + return 0 /* GL_FALSE */; + } + inVec[0] /= inVec[3]; + inVec[1] /= inVec[3]; + inVec[2] /= inVec[3]; + // Map x, y and z to range 0-1 */ + inVec[0] = inVec[0] * 0.5 + 0.5; + inVec[1] = inVec[1] * 0.5 + 0.5; + inVec[2] = inVec[2] * 0.5 + 0.5; + // Map x, y to viewport + inVec[0] = inVec[0] * {{{ makeGetValue('view', 2*4, 'i32') }}} + {{{ makeGetValue('view', 0*4, 'i32') }}}; + inVec[1] = inVec[1] * {{{ makeGetValue('view', 3*4, 'i32') }}} + {{{ makeGetValue('view', 1*4, 'i32') }}}; + + {{{ makeSetValue('winX', '0', 'inVec[0]', 'double') }}}; + {{{ makeSetValue('winY', '0', 'inVec[1]', 'double') }}}; + {{{ makeSetValue('winZ', '0', 'inVec[2]', 'double') }}}; + + return 1 /* GL_TRUE */; + }, + + gluUnProject: function(winX, winY, winZ, model, proj, view, objX, objY, objZ) { + var result = GLImmediate.matrixLib.mat4.unproject([winX, winY, winZ], + {{{ makeHEAPView('F64', 'model', 'model+' + (16*8)) }}}, + {{{ makeHEAPView('F64', 'proj', 'proj+' + (16*8)) }}}, + {{{ makeHEAPView('32', 'view', 'view+' + (4*4)) }}}); + + if (result === null) { + return 0 /* GL_FALSE */; + } + + {{{ makeSetValue('objX', '0', 'result[0]', 'double') }}}; + {{{ makeSetValue('objY', '0', 'result[1]', 'double') }}}; + {{{ makeSetValue('objZ', '0', 'result[2]', 'double') }}}; + + return 1 /* GL_TRUE */; + }, + + gluOrtho2D__deps: ['glOrtho'], + gluOrtho2D: function(left, right, bottom, top) { + _glOrtho(left, right, bottom, top, -1, 1); + }, }; // Legacy GL emulation diff --git a/src/library_glfw.js b/src/library_glfw.js index b6330f11e..78e351031 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -1844,7 +1844,7 @@ var LibraryGLFW = { }, glfwCreateThread: function(fun, arg) { - {{{ makeDynCall('vi', 'str') }}}(fun, arg); + {{{ makeDynCall('vi', 'fun') }}}(arg); // One single thread return 0; }, diff --git a/src/library_openal.js b/src/library_openal.js index fa8d42b00..e1bbab595 100644 --- a/src/library_openal.js +++ b/src/library_openal.js @@ -2344,7 +2344,7 @@ var LibraryOpenAL = { AL.alcErr = 0xA004 /* ALC_INVALID_VALUE */; return 0; /* ALC_NONE */ } - name = UTF8ToString(pEnumName); + var name = UTF8ToString(pEnumName); // See alGetEnumValue(), but basically behave the same as OpenAL-Soft switch (name) { case 'ALC_NO_ERROR': return 0; @@ -2608,7 +2608,7 @@ var LibraryOpenAL = { } AL.paused = true; - for (ctxId in AL.contexts) { + for (var ctxId in AL.contexts) { var ctx = AL.contexts[ctxId]; if (ctx.deviceId !== deviceId) { continue; @@ -2636,7 +2636,7 @@ var LibraryOpenAL = { } AL.paused = false; - for (ctxId in AL.contexts) { + for (var ctxId in AL.contexts) { var ctx = AL.contexts[ctxId]; if (ctx.deviceId !== deviceId) { continue; @@ -2927,7 +2927,7 @@ var LibraryOpenAL = { alIsExtensionPresent__proxy: 'sync', alIsExtensionPresent__sig: 'ii', alIsExtensionPresent: function(pExtName) { - name = UTF8ToString(pExtName); + var name = UTF8ToString(pExtName); return AL.AL_EXTENSIONS[name] ? 1 : 0; }, @@ -2949,7 +2949,7 @@ var LibraryOpenAL = { AL.currentCtx.err = 0xA003 /* AL_INVALID_VALUE */; return 0 /* AL_NONE */; } - name = UTF8ToString(pEnumName); + var name = UTF8ToString(pEnumName); switch (name) { // Spec doesn't clearly state that alGetEnumValue() is required to @@ -3137,7 +3137,7 @@ var LibraryOpenAL = { #endif return; } - switch (pname) { + switch (param) { case 'AL_SOURCE_DISTANCE_MODEL': AL.currentCtx.sourceDistanceModel = false; AL.updateContextGlobal(AL.currentCtx); @@ -3160,7 +3160,7 @@ var LibraryOpenAL = { #endif return 0; } - switch (pname) { + switch (param) { case 'AL_SOURCE_DISTANCE_MODEL': return AL.currentCtx.sourceDistanceModel ? 0 /* AL_FALSE */ : 1 /* AL_TRUE */; default: @@ -4612,7 +4612,7 @@ var LibraryOpenAL = { alGetSource3i__proxy: 'sync', alGetSource3i__sig: 'viiiii', - alGetSource3i: function(source, param, pValue0, pValue1, pValue2) { + alGetSource3i: function(sourceId, param, pValue0, pValue1, pValue2) { var val = AL.getSourceParam('alGetSource3i', sourceId, param); if (val === null) { return; @@ -4835,7 +4835,7 @@ var LibraryOpenAL = { alSourceiv__proxy: 'sync', alSourceiv__sig: 'viii', - alSourceiv: function(source, param, pValues) { + alSourceiv: function(sourceId, param, pValues) { if (!AL.currentCtx) { #if OPENAL_DEBUG console.error('alSourceiv() called without a valid context'); diff --git a/src/library_pthread_stub.js b/src/library_pthread_stub.js index 53b2fe290..08a753576 100644 --- a/src/library_pthread_stub.js +++ b/src/library_pthread_stub.js @@ -27,7 +27,7 @@ var LibraryPThreadStub = { pthread_cleanup_pop__sig: 'vi', pthread_cleanup_pop: function(execute) { assert(_pthread_cleanup_push.level == __ATEXIT__.length, 'cannot pop if something else added meanwhile!'); - callback = __ATEXIT__.pop(); + var callback = __ATEXIT__.pop(); if (execute) { {{{ makeDynCall('vi', 'callback.func') }}}(callback.arg) } diff --git a/src/library_syscall.js b/src/library_syscall.js index 96d2ec0c3..c775ea49c 100644 --- a/src/library_syscall.js +++ b/src/library_syscall.js @@ -1057,7 +1057,7 @@ var SyscallsLibrary = { __sys_setregid32__nothrow: true, __sys_setregid32__proxy: false, __sys_setregid32: function(ruid, euid) { - if (uid !== 0) return -{{{ cDefine('EPERM') }}}; + if (ruid !== 0) return -{{{ cDefine('EPERM') }}}; return 0; }, __sys_setuid32__sig: 'ii', diff --git a/src/library_webgl.js b/src/library_webgl.js index 4397bfb39..ef56b6651 100644 --- a/src/library_webgl.js +++ b/src/library_webgl.js @@ -3536,81 +3536,6 @@ var LibraryGL = { glBindVertexArrayOES: 'glBindVertexArray', glIsVertexArrayOES: 'glIsVertexArray', -#if LEGACY_GL_EMULATION - // GLU - - gluPerspective__deps: ['$GLImmediate'], - gluPerspective: function(fov, aspect, near, far) { - GLImmediate.matricesModified = true; - GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0; - GLImmediate.matrix[GLImmediate.currentMatrix] = - GLImmediate.matrixLib.mat4.perspective(fov, aspect, near, far, - GLImmediate.matrix[GLImmediate.currentMatrix]); - }, - - gluLookAt__deps: ['$GLImmediate'], - gluLookAt: function(ex, ey, ez, cx, cy, cz, ux, uy, uz) { - GLImmediate.matricesModified = true; - GLImmediate.matrixVersion[GLImmediate.currentMatrix] = (GLImmediate.matrixVersion[GLImmediate.currentMatrix] + 1)|0; - GLImmediate.matrixLib.mat4.lookAt(GLImmediate.matrix[GLImmediate.currentMatrix], [ex, ey, ez], - [cx, cy, cz], [ux, uy, uz]); - }, - - gluProject__deps: ['$GLImmediate'], - gluProject: function(objX, objY, objZ, model, proj, view, winX, winY, winZ) { - // The algorithm for this functions comes from Mesa - - var inVec = new Float32Array(4); - var outVec = new Float32Array(4); - GLImmediate.matrixLib.mat4.multiplyVec4({{{ makeHEAPView('F64', 'model', 'model+' + (16*8)) }}}, - [objX, objY, objZ, 1.0], outVec); - GLImmediate.matrixLib.mat4.multiplyVec4({{{ makeHEAPView('F64', 'proj', 'proj+' + (16*8)) }}}, - outVec, inVec); - if (inVec[3] == 0.0) { - return 0 /* GL_FALSE */; - } - inVec[0] /= inVec[3]; - inVec[1] /= inVec[3]; - inVec[2] /= inVec[3]; - // Map x, y and z to range 0-1 */ - inVec[0] = inVec[0] * 0.5 + 0.5; - inVec[1] = inVec[1] * 0.5 + 0.5; - inVec[2] = inVec[2] * 0.5 + 0.5; - // Map x, y to viewport - inVec[0] = inVec[0] * {{{ makeGetValue('view', 2*4, 'i32') }}} + {{{ makeGetValue('view', 0*4, 'i32') }}}; - inVec[1] = inVec[1] * {{{ makeGetValue('view', 3*4, 'i32') }}} + {{{ makeGetValue('view', 1*4, 'i32') }}}; - - {{{ makeSetValue('winX', '0', 'inVec[0]', 'double') }}}; - {{{ makeSetValue('winY', '0', 'inVec[1]', 'double') }}}; - {{{ makeSetValue('winZ', '0', 'inVec[2]', 'double') }}}; - - return 1 /* GL_TRUE */; - }, - - gluUnProject__deps: ['$GLImmediate'], - gluUnProject: function(winX, winY, winZ, model, proj, view, objX, objY, objZ) { - var result = GLImmediate.matrixLib.mat4.unproject([winX, winY, winZ], - {{{ makeHEAPView('F64', 'model', 'model+' + (16*8)) }}}, - {{{ makeHEAPView('F64', 'proj', 'proj+' + (16*8)) }}}, - {{{ makeHEAPView('32', 'view', 'view+' + (4*4)) }}}); - - if (result === null) { - return 0 /* GL_FALSE */; - } - - {{{ makeSetValue('objX', '0', 'result[0]', 'double') }}}; - {{{ makeSetValue('objY', '0', 'result[1]', 'double') }}}; - {{{ makeSetValue('objZ', '0', 'result[2]', 'double') }}}; - - return 1 /* GL_TRUE */; - }, - - gluOrtho2D__deps: ['glOrtho'], - gluOrtho2D: function(left, right, bottom, top) { - _glOrtho(left, right, bottom, top, -1, 1); - }, -#endif // LEGACY_GL_EMULATION - // GLES2 emulation glVertexAttribPointer__sig: 'viiiiii', diff --git a/src/library_webgpu.js b/src/library_webgpu.js index 9dafbef65..56f6a4165 100644 --- a/src/library_webgpu.js +++ b/src/library_webgpu.js @@ -1582,7 +1582,7 @@ var LibraryWebGPU = { }, wgpuComputePassEncoderWriteTimestamp: function(encoderId, querySetId, queryIndex) { - var pass = WebGPU.mgrComputePassEncoder.get(passId); + var pass = WebGPU.mgrComputePassEncoder.get(encoderId); var querySet = WebGPU.mgrQuerySet.get(querySetId); pass["writeTimestamp"](querySet, queryIndex); }, @@ -1716,7 +1716,7 @@ var LibraryWebGPU = { }, wgpuRenderPassEncoderWriteTimestamp: function(encoderId, querySetId, queryIndex) { - var pass = WebGPU.mgrRenderPassEncoder.get(passId); + var pass = WebGPU.mgrRenderPassEncoder.get(encoderId); var querySet = WebGPU.mgrQuerySet.get(querySetId); pass["writeTimestamp"](querySet, queryIndex); }, diff --git a/src/support.js b/src/support.js index fb522cea6..470a5661f 100644 --- a/src/support.js +++ b/src/support.js @@ -43,12 +43,6 @@ function getCompilerSetting(name) { if (!(name in compilerSettings)) return 'invalid compiler setting: ' + name; return compilerSettings[name]; } -#else // RETAIN_COMPILER_SETTINGS -#if ASSERTIONS -function getCompilerSetting(name) { - throw 'You must build with -s RETAIN_COMPILER_SETTINGS=1 for getCompilerSetting or emscripten_get_compiler_setting to work'; -} -#endif // ASSERTIONS #endif // RETAIN_COMPILER_SETTINGS #if USE_PTHREADS diff --git a/tests/test_other.py b/tests/test_other.py index 2b58c723b..cb6dcb0fb 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -7529,10 +7529,10 @@ end # We must ignore various types of errors that are expected in this situation, as we # are including a lot of JS without corresponding compiled code for it. This still # lets us catch all other errors. - with env_modify({'EMCC_CLOSURE_ARGS': '--jscomp_off undefinedVars'}): - # USE_WEBGPU is specified here to make sure that it's closure-safe. - # It can be removed if USE_WEBGPU is later included in INCLUDE_FULL_LIBRARY. - self.run_process([EMCC, test_file('hello_world.c'), '-O1', '--closure=1', '-g1', '-s', 'INCLUDE_FULL_LIBRARY', '-s', 'USE_WEBGPU', '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=0']) + + # USE_WEBGPU is specified here to make sure that it's closure-safe. + # It can be removed if USE_WEBGPU is later included in INCLUDE_FULL_LIBRARY. + self.run_process([EMCC, test_file('hello_world.c'), '-O1', '--closure=1', '-g1', '-s', 'INCLUDE_FULL_LIBRARY', '-s', 'USE_WEBGPU', '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=0']) # Tests --closure-args command line flag def test_closure_externs(self): @@ -10180,6 +10180,10 @@ exec "$@" # be clear this is what we are testing (and in case the default ever changes). cmd = [EMCC, function + '.c', '-O2', '--minify=0', '--profiling-funcs', '-Wno-incompatible-library-redeclaration', '-sREVERSE_DEPS=auto'] print(f'compiling test program for: {function}') + if 'emscripten_get_compiler_setting' in function: + cmd.append('-sRETAIN_COMPILER_SETTINGS') + if 'emscripten_pc_get_function' in function: + cmd.append('-sUSE_OFFSET_CONVERTER') if 'embind' in function: cmd.append('--bind') if 'fetch' in function: