Skip to content

Commit 86c58da

Browse files
committed
workerized RA
1 parent ed1810d commit 86c58da

File tree

9 files changed

+349
-41
lines changed

9 files changed

+349
-41
lines changed

Makefile.common

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,10 @@ ifeq ($(HAVE_GL_CONTEXT), 1)
15261526
endif
15271527

15281528
ifeq ($(HAVE_EMSCRIPTEN), 1)
1529-
OBJ += gfx/drivers_context/emscriptenegl_ctx.o
1529+
ifeq ($(HAVE_EGL), 1)
1530+
OBJ += gfx/drivers_context/emscriptenegl_ctx.o
1531+
endif
1532+
OBJ += gfx/drivers_context/emscriptenwebgl_ctx.o
15301533
endif
15311534

15321535
ifeq ($(HAVE_MALI_FBDEV), 1)

Makefile.emscripten

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ HAVE_SCREENSHOTS = 1
2424
HAVE_REWIND = 1
2525
HAVE_AUDIOMIXER = 1
2626
HAVE_CC_RESAMPLER = 1
27-
HAVE_EGL = 1
27+
HAVE_EGL ?= 0
28+
HAVE_OPENGLES = 1
2829
HAVE_RJPEG = 0
2930
HAVE_RPNG = 1
3031
HAVE_EMSCRIPTEN = 1
@@ -48,6 +49,8 @@ HAVE_7ZIP = 1
4849
HAVE_BSV_MOVIE = 1
4950
HAVE_AL = 1
5051
HAVE_CHD ?= 0
52+
HAVE_WASMFS ?= 1
53+
HAVE_WORKER ?= 1
5154

5255
# WARNING -- READ BEFORE ENABLING
5356
# The rwebaudio driver is known to have several audio bugs, such as
@@ -68,7 +71,7 @@ HAVE_OPENGLES3 ?= 0
6871

6972
ASYNC ?= 0
7073
LTO ?= 0
71-
PTHREAD ?= 0
74+
PTHREAD ?= 4
7275

7376
STACK_SIZE ?= 4194304
7477
INITIAL_HEAP ?= 134217728
@@ -93,10 +96,48 @@ _cmd_set_volume,_cmd_set_shader,_cmd_cheat_set_code,_cmd_cheat_get_code,_cmd_che
9396
_cmd_cheat_get_size,_cmd_cheat_apply_cheats
9497

9598
LIBS := -s USE_ZLIB=1
99+
100+
ifeq ($(HAVE_WASMFS), 1)
101+
LIBS += -s WASMFS -s FORCE_FILESYSTEM=1
102+
endif
103+
104+
ifeq ($(HAVE_WORKER), 1)
105+
LIBS += -s PROXY_TO_PTHREAD -s USE_ES6_IMPORT_META=0 -sENVIRONMENT=worker,web
106+
else
107+
ifeq ($(HAVE_AL), 1)
108+
override ASYNC = 1
109+
endif
110+
endif
111+
112+
ifeq ($(HAVE_OPENGLES), 1)
113+
ifeq ($(HAVE_OPENGLES3), 1)
114+
LDFLAGS += -s FULL_ES3=1 -s MIN_WEBGL_VERSION=2 -s MAX_WEBGL_VERSION=2
115+
else
116+
LDFLAGS += -s FULL_ES2=1
117+
endif
118+
endif
119+
120+
ifeq ($(GL_DEBUG), 1)
121+
LDFLAGS += -s GL_ASSERTIONS=1 -s GL_DEBUG=1
122+
endif
123+
124+
ifeq ($(FS_DEBUG), 1)
125+
LDFLAGS += -s FS_DEBUG=1
126+
endif
127+
128+
ifeq ($(HAVE_SDL2), 1)
129+
LIBS += -s USE_SDL=2
130+
DEFINES += -DHAVE_SDL2
131+
endif
132+
133+
96134
LDFLAGS := -L. --no-heap-copy -s $(LIBS) -s STACK_SIZE=$(STACK_SIZE) -s INITIAL_MEMORY=$(INITIAL_HEAP) \
97135
-s EXPORTED_RUNTIME_METHODS=callMain,FS,PATH,ERRNO_CODES,stringToNewUTF8,UTF8ToString \
98136
-s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_FUNCTIONS="$(EXPORTED_FUNCTIONS)" \
99137
-s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORT_NAME="libretro_$(subst -,_,$(LIBRETRO))" \
138+
-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 \
139+
-s OFFSCREENCANVAS_SUPPORT \
140+
-s OFFSCREEN_FRAMEBUFFER \
100141
--extern-pre-js emscripten/pre.js \
101142
--js-library emscripten/library_rwebcam.js \
102143
--js-library emscripten/library_platform_emscripten.js
@@ -105,48 +146,29 @@ ifeq ($(HAVE_RWEBAUDIO), 1)
105146
LDFLAGS += --js-library emscripten/library_rwebaudio.js
106147
DEFINES += -DHAVE_RWEBAUDIO
107148
endif
149+
108150
ifeq ($(HAVE_AL), 1)
109151
LDFLAGS += -lopenal
110152
DEFINES += -DHAVE_AL
111-
override ASYNC = 1
112153
endif
113154

114155
ifneq ($(PTHREAD), 0)
115-
LDFLAGS += -s MAXIMUM_MEMORY=1073741824 -pthread -s PTHREAD_POOL_SIZE=$(PTHREAD)
116-
CFLAGS += -pthread
156+
LDFLAGS += -s WASM_MEM_MAX=1073741824 -pthread -s PTHREAD_POOL_SIZE=$(PTHREAD)
157+
CFLAGS += -pthread -s SHARED_MEMORY
117158
HAVE_THREADS=1
118159
else
119160
HAVE_THREADS=0
120161
endif
121162

163+
122164
ifeq ($(ASYNC), 1)
165+
DEFINES += -DEMSCRIPTEN_ASYNCIFY
123166
LDFLAGS += -s ASYNCIFY=$(ASYNC) -s ASYNCIFY_STACK_SIZE=8192
124167
ifeq ($(DEBUG), 1)
125168
LDFLAGS += -s ASYNCIFY_DEBUG=1 # -s ASYNCIFY_ADVISE
126169
endif
127170
endif
128171

129-
ifeq ($(HAVE_OPENGLES), 1)
130-
ifeq ($(HAVE_OPENGLES3), 1)
131-
LDFLAGS += -s FULL_ES3=1 -s MIN_WEBGL_VERSION=2 -s MAX_WEBGL_VERSION=2
132-
else
133-
LDFLAGS += -s FULL_ES2=1
134-
endif
135-
endif
136-
137-
ifeq ($(GL_DEBUG), 1)
138-
LDFLAGS += -s GL_ASSERTIONS=1 -s GL_DEBUG=1
139-
endif
140-
141-
ifeq ($(FS_DEBUG), 1)
142-
LDFLAGS += -s FS_DEBUG=1
143-
endif
144-
145-
ifeq ($(HAVE_SDL2), 1)
146-
LIBS += -s USE_SDL=2
147-
DEFINES += -DHAVE_SDL2
148-
endif
149-
150172
include Makefile.common
151173

152174
CFLAGS += $(DEF_FLAGS) -Ideps -Ideps/stb

frontend/drivers/platform_emscripten.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ int main(int argc, char *argv[])
308308
specialHTMLTargets["!canvas"] = Module.canvas;
309309
});
310310

311+
emscripten_set_canvas_element_size("!canvas", 800, 600);
312+
emscripten_set_element_css_size("!canvas", 800.0, 600.0);
311313
emscripten_set_main_loop(emscripten_mainloop, 0, 0);
314+
emscripten_set_main_loop_timing(EM_TIMING_RAF, 1);
312315
rarch_main(argc, argv, NULL);
313316

314317
return 0;

gfx/drivers_context/emscriptenegl_ctx.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ static void gfx_ctx_emscripten_destroy(void *data)
124124

125125
if (!emscripten)
126126
return;
127-
128127
#ifdef HAVE_EGL
129128
egl_destroy(&emscripten->egl);
130129
#endif
131-
132130
free(data);
133131
}
134132

@@ -191,7 +189,6 @@ static void *gfx_ctx_emscripten_init(void *video_driver)
191189
#endif
192190

193191
return emscripten;
194-
195192
error:
196193
gfx_ctx_emscripten_destroy(video_driver);
197194
return NULL;

0 commit comments

Comments
 (0)