From 5370e2ad6ec78aefe764dd16156ef69d2e53bacc Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 6 Jul 2022 02:02:22 +0100 Subject: [PATCH] More wasm details, basics mostly work now Signed-off-by: falkTX --- deps/Makefile | 12 ++++++--- dpf | 2 +- include/simd-compat/mmintrin.h | 27 +++++++++++++++++++ .../{neon-compat => simd-compat}/pmmintrin.h | 24 +++++++++++++++-- plugins/Makefile | 22 +++++++-------- plugins/plugins.cpp | 12 --------- src/AsyncDialog.cpp | 10 +++---- src/Makefile | 15 ++++++----- src/Makefile.cardinal.mk | 21 ++++++++++----- src/emscripten/shell.html | 7 +++++ 10 files changed, 103 insertions(+), 49 deletions(-) create mode 100644 include/simd-compat/mmintrin.h rename include/{neon-compat => simd-compat}/pmmintrin.h (69%) diff --git a/deps/Makefile b/deps/Makefile index 4e9db26..522e83d 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -31,7 +31,7 @@ endif # custom build flags BASE_FLAGS += -I../include -BASE_FLAGS += -I../include/neon-compat +BASE_FLAGS += -I../include/simd-compat ifeq ($(HEADLESS),true) ifeq ($(WITH_LTO),true) @@ -43,11 +43,11 @@ ifneq ($(SYSDEPS),true) BASE_FLAGS += -DZSTDLIB_VISIBILITY= endif -ifeq ($(WASM),true) -BASE_FLAGS += -msse -msse2 -msse3 -msimd128 -else ifneq ($(HAIKU),true) +ifneq ($(HAIKU),true) +ifneq ($(WASM),true) BASE_FLAGS += -pthread endif +endif ifeq ($(WINDOWS),true) BASE_FLAGS += -D_USE_MATH_DEFINES @@ -62,6 +62,10 @@ BUILD_CXX_FLAGS += -fno-finite-math-only -fno-strict-aliasing # Rack code is not tested for this flag, unset it BUILD_CXX_FLAGS += -U_GLIBCXX_ASSERTIONS -Wp,-U_GLIBCXX_ASSERTIONS +ifeq ($(WASM),true) +BUILD_CXX_FLAGS += -fexceptions +endif + # -------------------------------------------------------------- # override VCV arch.mk stuff so we can build more architectures diff --git a/dpf b/dpf index 614eeaf..c2938c0 160000 --- a/dpf +++ b/dpf @@ -1 +1 @@ -Subproject commit 614eeaf0ef0390d4956feb991e9038980cf50371 +Subproject commit c2938c02994988bd5dde4c4cbba9951709789ee8 diff --git a/include/simd-compat/mmintrin.h b/include/simd-compat/mmintrin.h new file mode 100644 index 0000000..e0854bc --- /dev/null +++ b/include/simd-compat/mmintrin.h @@ -0,0 +1,27 @@ +/* + * DISTRHO Cardinal Plugin + * Copyright (C) 2021-2022 Filipe Coelho + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the LICENSE file. + */ + +#pragma once + +#if defined(__i386__) || defined(__x86_64__) +# include_next +#elif defined(__EMSCRIPTEN__) +# include +// # include_next +#else +# include "../sse2neon/sse2neon.h" +#endif diff --git a/include/neon-compat/pmmintrin.h b/include/simd-compat/pmmintrin.h similarity index 69% rename from include/neon-compat/pmmintrin.h rename to include/simd-compat/pmmintrin.h index de10d32..6ed77fb 100644 --- a/include/neon-compat/pmmintrin.h +++ b/include/simd-compat/pmmintrin.h @@ -1,6 +1,6 @@ /* * DISTRHO Cardinal Plugin - * Copyright (C) 2021 Filipe Coelho + * Copyright (C) 2021-2022 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -17,8 +17,28 @@ #pragma once -#if defined(__i386__) || defined(__x86_64__) || defined(__EMSCRIPTEN__) +#if defined(__i386__) || defined(__x86_64__) # include_next + +#elif defined(__EMSCRIPTEN__) +# include_next + +// NOTE these have been verified to be unused (included for ValleyAudio builds) +// static inline +// __m64 _mm_and_si64(__m64 a, __m64 b) { return a; } +// +// static inline +// __m64 _mm_andnot_si64(__m64 a, __m64 b) { return a; } +// +// static inline +// __m64 _mm_or_si64(__m64 a, __m64 b) { return a; } + +static inline +__m64 _mm_set1_pi16(short w) +{ + return __extension__ (__m64){ static_cast(w), static_cast(w) }; +} + #else # include "../sse2neon/sse2neon.h" diff --git a/plugins/Makefile b/plugins/Makefile index 73a6ec8..cb7112d 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -490,12 +490,9 @@ BOGAUDIO_CUSTOM_PER_FILE = ARQuantity AttackMenuItem ReleaseMenuItem # -------------------------------------------------------------- # ChowDSP -# FIXME -ifneq ($(WASM),true) PLUGIN_FILES += $(wildcard ChowDSP/src/*/*.cpp) PLUGIN_FILES += $(wildcard ChowDSP/src/*/*/*.cpp) PLUGIN_FILES += $(wildcard ChowDSP/lib/r8lib/*.cpp) -endif # -------------------------------------------------------------- # CatroModulo @@ -828,8 +825,6 @@ UNLESS_MODULES_CUSTOM = Selection # -------------------------------------------------------------- # ValleyAudio -# FIXME -ifneq ($(WASM),true) PLUGIN_FILES += $(filter-out ValleyAudio/src/Valley.cpp,$(wildcard ValleyAudio/src/*.cpp)) PLUGIN_FILES += $(wildcard ValleyAudio/src/*/*.cpp) PLUGIN_FILES += $(wildcard ValleyAudio/src/*/*/*.cpp) @@ -902,7 +897,6 @@ PLUGIN_BINARIES += ValleyAudio/src/XFADE.bin # modules/types which are present in other plugins VALLEYAUDIO_CUSTOM = $(DRWAV) DigitalDisplay VALLEYAUDIO_CUSTOM_PER_FILE = TempoKnob -endif # -------------------------------------------------------------- # Voxglitch @@ -955,8 +949,8 @@ BASE_FLAGS += -I../dpf/dgl/src/nanovg BASE_FLAGS += -I../dpf/distrho BASE_FLAGS += -I../include -BASE_FLAGS += -I../include/neon-compat BASE_FLAGS += -I../include/osdialog-stub +BASE_FLAGS += -I../include/simd-compat ifeq ($(HAVE_X11),true) BASE_FLAGS += -DHAVE_X11 @@ -995,14 +989,16 @@ endif ifeq ($(BSD),true) BASE_FLAGS += -D'aligned_alloc_16(ptr)'='aligned_alloc(16,ptr)' BASE_FLAGS += -D'aligned_free_16(ptr)'='free(ptr)' +else ifeq ($(WASM),true) +BASE_FLAGS += -D'aligned_alloc_16(ptr)'='aligned_alloc(16,ptr)' +BASE_FLAGS += -D'aligned_free_16(ptr)'='free(ptr)' endif -ifeq ($(WASM),true) -BASE_FLAGS += -DNANOVG_GLES2=1 -BASE_FLAGS += -msse -msse2 -msse3 -msimd128 -else ifneq ($(HAIKU),true) +ifneq ($(WASM),true) +ifneq ($(HAIKU),true) BASE_FLAGS += -pthread endif +endif ifeq ($(WINDOWS),true) BASE_FLAGS += -D_USE_MATH_DEFINES @@ -1036,6 +1032,10 @@ endif # Rack code is not tested for this flag, unset it BUILD_CXX_FLAGS += -U_GLIBCXX_ASSERTIONS -Wp,-U_GLIBCXX_ASSERTIONS +ifeq ($(WASM),true) +BUILD_CXX_FLAGS += -fexceptions +endif + # -------------------------------------------------------------- # lots of warnings from VCV side diff --git a/plugins/plugins.cpp b/plugins/plugins.cpp index 91195b4..b38d1b6 100644 --- a/plugins/plugins.cpp +++ b/plugins/plugins.cpp @@ -1622,8 +1622,6 @@ static void initStatic__cf() } } -// FIXME -#ifndef DISTRHO_OS_WASM static void initStatic__ChowDSP() { Plugin* const p = new Plugin; @@ -1650,7 +1648,6 @@ static void initStatic__ChowDSP() p->addModel(modelChowChorus); } } -#endif static void initStatic__DrumKit() { @@ -2589,8 +2586,6 @@ static void initStatic__unless_modules() } } -// FIXME -#ifndef DISTRHO_OS_WASM static void initStatic__ValleyAudio() { Plugin* const p = new Plugin; @@ -2609,7 +2604,6 @@ static void initStatic__ValleyAudio() p->addModel(modelTerrorform); } } -#endif static void initStatic__Voxglitch() { @@ -2725,10 +2719,7 @@ void initStaticPlugins() initStatic__BogaudioModules(); initStatic__CatroModulo(); initStatic__cf(); -// FIXME -#ifndef DISTRHO_OS_WASM initStatic__ChowDSP(); -#endif initStatic__DrumKit(); initStatic__ESeries(); initStatic__ExpertSleepersEncoders(); @@ -2768,10 +2759,7 @@ void initStaticPlugins() initStatic__sonusmodular(); initStatic__stocaudio(); initStatic__unless_modules(); -// FIXME -#ifndef DISTRHO_OS_WASM initStatic__ValleyAudio(); -#endif initStatic__Voxglitch(); initStatic__WhatTheRack(); initStatic__ZetaCarinaeModules(); diff --git a/src/AsyncDialog.cpp b/src/AsyncDialog.cpp index 3c046e5..1009eac 100644 --- a/src/AsyncDialog.cpp +++ b/src/AsyncDialog.cpp @@ -44,7 +44,7 @@ struct AsyncDialog : OpaqueWidget Label* label; AsyncDialog(const char* const message) - { + { setup(message); struct AsyncDismissButton : Button { @@ -61,7 +61,7 @@ struct AsyncDialog : OpaqueWidget } AsyncDialog(const char* const message, const std::function action) - { + { setup(message); struct AsyncCancelButton : Button { @@ -131,7 +131,7 @@ struct AsyncDialog : OpaqueWidget } void draw(const DrawArgs& args) override - { + { bndMenuBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y, 0); Widget::draw(args); } @@ -261,13 +261,13 @@ struct AsyncTextInput : OpaqueWidget } void step() override - { + { OpaqueWidget::step(); box.pos = parent->box.size.minus(box.size).div(2).round(); } void draw(const DrawArgs& args) override - { + { bndMenuBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y, 0); Widget::draw(args); } diff --git a/src/Makefile b/src/Makefile index 0ef8eb0..2308b05 100644 --- a/src/Makefile +++ b/src/Makefile @@ -44,7 +44,7 @@ BASE_FLAGS += -DPRIVATE= BASE_FLAGS += -I../dpf/dgl/src/nanovg BASE_FLAGS += -I../dpf/distrho BASE_FLAGS += -I../include -BASE_FLAGS += -I../include/neon-compat +BASE_FLAGS += -I../include/simd-compat BASE_FLAGS += -IRack/include ifeq ($(SYSDEPS),true) BASE_FLAGS += -DCARDINAL_SYSDEPS @@ -81,14 +81,11 @@ ifeq ($(HAIKU),true) BASE_FLAGS += -DCLOCK_MONOTONIC_RAW=CLOCK_MONOTONIC endif -ifeq ($(WASM),true) -BASE_FLAGS += -DNANOVG_GLES2=1 -BASE_FLAGS += -msse -msse2 -msse3 -msimd128 -# FIXME -BASE_FLAGS += -DRTLD_DEEPBIND=0 -else ifneq ($(HAIKU),true) +ifneq ($(WASM),true) +ifneq ($(HAIKU),true) BASE_FLAGS += -pthread endif +endif ifeq ($(WINDOWS),true) BASE_FLAGS += -D_USE_MATH_DEFINES @@ -117,6 +114,10 @@ BUILD_CXX_FLAGS += -DnsvgParseFromFile=nsvgParseFromFileCardinal # Rack code is not tested for this flag, unset it BUILD_CXX_FLAGS += -U_GLIBCXX_ASSERTIONS -Wp,-U_GLIBCXX_ASSERTIONS +ifeq ($(WASM),true) +BUILD_CXX_FLAGS += -fexceptions +endif + # -------------------------------------------------------------- # Rack files to build diff --git a/src/Makefile.cardinal.mk b/src/Makefile.cardinal.mk index 6acf199..b408cdd 100644 --- a/src/Makefile.cardinal.mk +++ b/src/Makefile.cardinal.mk @@ -143,7 +143,7 @@ BASE_FLAGS += -DPRIVATE= BASE_FLAGS += -I.. BASE_FLAGS += -I../../dpf/dgl/src/nanovg BASE_FLAGS += -I../../include -BASE_FLAGS += -I../../include/neon-compat +BASE_FLAGS += -I../../include/simd-compat BASE_FLAGS += -I../Rack/include ifeq ($(SYSDEPS),true) BASE_FLAGS += -DCARDINAL_SYSDEPS @@ -164,12 +164,11 @@ ifeq ($(MOD_BUILD),true) BASE_FLAGS += -DDISTRHO_PLUGIN_USES_MODGUI=1 -DDISTRHO_PLUGIN_MINIMUM_BUFFER_SIZE=0xffff endif -ifeq ($(WASM),true) -BASE_FLAGS += -DNANOVG_GLES2=1 -BASE_FLAGS += -msse -msse2 -msse3 -msimd128 -else ifneq ($(HAIKU),true) +ifneq ($(WASM),true) +ifneq ($(HAIKU),true) BASE_FLAGS += -pthread endif +endif ifeq ($(WINDOWS),true) BASE_FLAGS += -D_USE_MATH_DEFINES @@ -195,6 +194,10 @@ endif # Rack code is not tested for this flag, unset it BUILD_CXX_FLAGS += -U_GLIBCXX_ASSERTIONS -Wp,-U_GLIBCXX_ASSERTIONS +ifeq ($(WASM),true) +BUILD_CXX_FLAGS += -fexceptions +endif + # -------------------------------------------------------------- # FIXME lots of warnings from VCV side @@ -205,8 +208,12 @@ BASE_FLAGS += -Wno-unused-variable # extra linker flags ifeq ($(WASM),true) -LINK_FLAGS += --preload-file=./resources -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=32Mb -sLZ4=1 --shell-file=../emscripten/shell.html -# -sDISABLE_EXCEPTION_CATCHING=1 +LINK_FLAGS += --preload-file=./resources +LINK_FLAGS += -sALLOW_MEMORY_GROWTH +LINK_FLAGS += -sEXPORTED_RUNTIME_METHODS=FS,ccall +LINK_FLAGS += -sINITIAL_MEMORY=64Mb +LINK_FLAGS += -sLZ4=1 +LINK_FLAGS += --shell-file=../emscripten/shell.html else ifeq ($(HAIKU),true) LINK_FLAGS += -lpthread else diff --git a/src/emscripten/shell.html b/src/emscripten/shell.html index f3d8947..ce061a3 100644 --- a/src/emscripten/shell.html +++ b/src/emscripten/shell.html @@ -14,6 +14,11 @@ margin: 0; } + #canvas_file_open, + #canvas_file_save { + display: none; + } + #canvas_wrapper { display: none; width: 100vw; @@ -73,6 +78,8 @@
+ +