Skip to content

Commit 78c2a08

Browse files
adamscottFaless
andcommitted
Add proxy_to_pthread option to platform=web
Co-authored-by: Fabio Alessandrelli <fabio.alessandrelli@gmail.com>
1 parent c2b9167 commit 78c2a08

20 files changed

+420
-39
lines changed

drivers/gles3/storage/particles_storage.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ void ParticlesStorage::particles_set_view_axis(RID p_particles, const Vector3 &p
775775
LocalVector<ParticleInstanceData3D> particle_vector;
776776
particle_vector.resize(particles->amount);
777777
particle_array = particle_vector.ptr();
778-
glGetBufferSubData(GL_ARRAY_BUFFER, 0, particles->amount * sizeof(ParticleInstanceData3D), particle_array);
778+
godot_webgl2_glGetBufferSubData(GL_ARRAY_BUFFER, 0, particles->amount * sizeof(ParticleInstanceData3D), particle_array);
779779
#endif
780780
SortArray<ParticleInstanceData3D, ParticlesViewSort> sorter;
781781
sorter.compare.z_dir = axis;
@@ -1133,7 +1133,7 @@ void ParticlesStorage::_particles_reverse_lifetime_sort(Particles *particles) {
11331133
LocalVector<ParticleInstanceData> particle_vector;
11341134
particle_vector.resize(particles->amount);
11351135
particle_array = particle_vector.ptr();
1136-
glGetBufferSubData(GL_ARRAY_BUFFER, 0, buffer_size, particle_array);
1136+
godot_webgl2_glGetBufferSubData(GL_ARRAY_BUFFER, 0, buffer_size, particle_array);
11371137
#endif
11381138

11391139
uint32_t lifetime_split = (MIN(int(particles->amount * particles->sort_buffer_phase), particles->amount - 1) + 1) % particles->amount;

drivers/gles3/storage/utilities.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Vector<uint8_t> Utilities::buffer_get_data(GLenum p_target, GLuint p_buffer, uin
115115
#if defined(__EMSCRIPTEN__)
116116
{
117117
uint8_t *w = ret.ptrw();
118-
glGetBufferSubData(p_target, 0, p_buffer_size, w);
118+
godot_webgl2_glGetBufferSubData(p_target, 0, p_buffer_size, w);
119119
}
120120
#else
121121
void *data = glMapBufferRange(p_target, 0, p_buffer_size, GL_MAP_READ_BIT);

modules/webrtc/library_godot_webrtc.js

+20
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const GodotRTCDataChannel = {
9090
},
9191
},
9292

93+
godot_js_rtc_datachannel_ready_state_get__proxy: 'sync',
9394
godot_js_rtc_datachannel_ready_state_get__sig: 'ii',
9495
godot_js_rtc_datachannel_ready_state_get: function (p_id) {
9596
const ref = IDHandler.get(p_id);
@@ -110,6 +111,7 @@ const GodotRTCDataChannel = {
110111
}
111112
},
112113

114+
godot_js_rtc_datachannel_send__proxy: 'sync',
113115
godot_js_rtc_datachannel_send__sig: 'iiiii',
114116
godot_js_rtc_datachannel_send: function (p_id, p_buffer, p_length, p_raw) {
115117
const ref = IDHandler.get(p_id);
@@ -131,16 +133,19 @@ const GodotRTCDataChannel = {
131133
return 0;
132134
},
133135

136+
godot_js_rtc_datachannel_is_ordered__proxy: 'sync',
134137
godot_js_rtc_datachannel_is_ordered__sig: 'ii',
135138
godot_js_rtc_datachannel_is_ordered: function (p_id) {
136139
return GodotRTCDataChannel.get_prop(p_id, 'ordered', true);
137140
},
138141

142+
godot_js_rtc_datachannel_id_get__proxy: 'sync',
139143
godot_js_rtc_datachannel_id_get__sig: 'ii',
140144
godot_js_rtc_datachannel_id_get: function (p_id) {
141145
return GodotRTCDataChannel.get_prop(p_id, 'id', 65535);
142146
},
143147

148+
godot_js_rtc_datachannel_max_packet_lifetime_get__proxy: 'sync',
144149
godot_js_rtc_datachannel_max_packet_lifetime_get__sig: 'ii',
145150
godot_js_rtc_datachannel_max_packet_lifetime_get: function (p_id) {
146151
const ref = IDHandler.get(p_id);
@@ -156,21 +161,25 @@ const GodotRTCDataChannel = {
156161
return 65535;
157162
},
158163

164+
godot_js_rtc_datachannel_max_retransmits_get__proxy: 'sync',
159165
godot_js_rtc_datachannel_max_retransmits_get__sig: 'ii',
160166
godot_js_rtc_datachannel_max_retransmits_get: function (p_id) {
161167
return GodotRTCDataChannel.get_prop(p_id, 'maxRetransmits', 65535);
162168
},
163169

170+
godot_js_rtc_datachannel_is_negotiated__proxy: 'sync',
164171
godot_js_rtc_datachannel_is_negotiated__sig: 'ii',
165172
godot_js_rtc_datachannel_is_negotiated: function (p_id) {
166173
return GodotRTCDataChannel.get_prop(p_id, 'negotiated', 65535);
167174
},
168175

176+
godot_js_rtc_datachannel_get_buffered_amount__proxy: 'sync',
169177
godot_js_rtc_datachannel_get_buffered_amount__sig: 'ii',
170178
godot_js_rtc_datachannel_get_buffered_amount: function (p_id) {
171179
return GodotRTCDataChannel.get_prop(p_id, 'bufferedAmount', 0);
172180
},
173181

182+
godot_js_rtc_datachannel_label_get__proxy: 'sync',
174183
godot_js_rtc_datachannel_label_get__sig: 'ii',
175184
godot_js_rtc_datachannel_label_get: function (p_id) {
176185
const ref = IDHandler.get(p_id);
@@ -189,12 +198,14 @@ const GodotRTCDataChannel = {
189198
return GodotRuntime.allocString(ref.protocol);
190199
},
191200

201+
godot_js_rtc_datachannel_destroy__proxy: 'sync',
192202
godot_js_rtc_datachannel_destroy__sig: 'vi',
193203
godot_js_rtc_datachannel_destroy: function (p_id) {
194204
GodotRTCDataChannel.close(p_id);
195205
IDHandler.remove(p_id);
196206
},
197207

208+
godot_js_rtc_datachannel_connect__proxy: 'sync',
198209
godot_js_rtc_datachannel_connect__sig: 'viiiiii',
199210
godot_js_rtc_datachannel_connect: function (p_id, p_ref, p_on_open, p_on_message, p_on_error, p_on_close) {
200211
const onopen = GodotRuntime.get_func(p_on_open).bind(null, p_ref);
@@ -204,6 +215,7 @@ const GodotRTCDataChannel = {
204215
GodotRTCDataChannel.connect(p_id, onopen, onmessage, onerror, onclose);
205216
},
206217

218+
godot_js_rtc_datachannel_close__proxy: 'sync',
207219
godot_js_rtc_datachannel_close__sig: 'vi',
208220
godot_js_rtc_datachannel_close: function (p_id) {
209221
const ref = IDHandler.get(p_id);
@@ -356,6 +368,7 @@ const GodotRTCPeerConnection = {
356368
},
357369
},
358370

371+
godot_js_rtc_pc_create__proxy: 'sync',
359372
godot_js_rtc_pc_create__sig: 'iiiiiiii',
360373
godot_js_rtc_pc_create: function (p_config, p_ref, p_on_connection_state_change, p_on_ice_gathering_state_change, p_on_signaling_state_change, p_on_ice_candidate, p_on_datachannel) {
361374
const wrap = function (p_func) {
@@ -371,6 +384,7 @@ const GodotRTCPeerConnection = {
371384
);
372385
},
373386

387+
godot_js_rtc_pc_close__proxy: 'sync',
374388
godot_js_rtc_pc_close__sig: 'vi',
375389
godot_js_rtc_pc_close: function (p_id) {
376390
const ref = IDHandler.get(p_id);
@@ -380,11 +394,13 @@ const GodotRTCPeerConnection = {
380394
ref.close();
381395
},
382396

397+
godot_js_rtc_pc_destroy__proxy: 'sync',
383398
godot_js_rtc_pc_destroy__sig: 'vi',
384399
godot_js_rtc_pc_destroy: function (p_id) {
385400
GodotRTCPeerConnection.destroy(p_id);
386401
},
387402

403+
godot_js_rtc_pc_offer_create__proxy: 'sync',
388404
godot_js_rtc_pc_offer_create__sig: 'viiii',
389405
godot_js_rtc_pc_offer_create: function (p_id, p_obj, p_on_session, p_on_error) {
390406
const ref = IDHandler.get(p_id);
@@ -400,6 +416,7 @@ const GodotRTCPeerConnection = {
400416
});
401417
},
402418

419+
godot_js_rtc_pc_local_description_set__proxy: 'sync',
403420
godot_js_rtc_pc_local_description_set__sig: 'viiiii',
404421
godot_js_rtc_pc_local_description_set: function (p_id, p_type, p_sdp, p_obj, p_on_error) {
405422
const ref = IDHandler.get(p_id);
@@ -417,6 +434,7 @@ const GodotRTCPeerConnection = {
417434
});
418435
},
419436

437+
godot_js_rtc_pc_remote_description_set__proxy: 'sync',
420438
godot_js_rtc_pc_remote_description_set__sig: 'viiiiii',
421439
godot_js_rtc_pc_remote_description_set: function (p_id, p_type, p_sdp, p_obj, p_session_created, p_on_error) {
422440
const ref = IDHandler.get(p_id);
@@ -442,6 +460,7 @@ const GodotRTCPeerConnection = {
442460
});
443461
},
444462

463+
godot_js_rtc_pc_ice_candidate_add__proxy: 'sync',
445464
godot_js_rtc_pc_ice_candidate_add__sig: 'viiii',
446465
godot_js_rtc_pc_ice_candidate_add: function (p_id, p_mid_name, p_mline_idx, p_sdp) {
447466
const ref = IDHandler.get(p_id);
@@ -458,6 +477,7 @@ const GodotRTCPeerConnection = {
458477
},
459478

460479
godot_js_rtc_pc_datachannel_create__deps: ['$GodotRTCDataChannel'],
480+
godot_js_rtc_pc_datachannel_create__proxy: 'sync',
461481
godot_js_rtc_pc_datachannel_create__sig: 'iiii',
462482
godot_js_rtc_pc_datachannel_create: function (p_id, p_label, p_config) {
463483
try {

modules/websocket/library_godot_websocket.js

+5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ const GodotWebSocket = {
144144
},
145145
},
146146

147+
godot_js_websocket_create__proxy: 'sync',
147148
godot_js_websocket_create__sig: 'iiiiiiii',
148149
godot_js_websocket_create: function (p_ref, p_url, p_proto, p_on_open, p_on_message, p_on_error, p_on_close) {
149150
const on_open = GodotRuntime.get_func(p_on_open).bind(null, p_ref);
@@ -166,6 +167,7 @@ const GodotWebSocket = {
166167
return GodotWebSocket.create(socket, on_open, on_message, on_error, on_close);
167168
},
168169

170+
godot_js_websocket_send__proxy: 'sync',
169171
godot_js_websocket_send__sig: 'iiiii',
170172
godot_js_websocket_send: function (p_id, p_buf, p_buf_len, p_raw) {
171173
const bytes_array = new Uint8Array(p_buf_len);
@@ -180,18 +182,21 @@ const GodotWebSocket = {
180182
return GodotWebSocket.send(p_id, out);
181183
},
182184

185+
godot_js_websocket_buffered_amount__proxy: 'sync',
183186
godot_js_websocket_buffered_amount__sig: 'ii',
184187
godot_js_websocket_buffered_amount: function (p_id) {
185188
return GodotWebSocket.bufferedAmount(p_id);
186189
},
187190

191+
godot_js_websocket_close__proxy: 'sync',
188192
godot_js_websocket_close__sig: 'viii',
189193
godot_js_websocket_close: function (p_id, p_code, p_reason) {
190194
const code = p_code;
191195
const reason = GodotRuntime.parseString(p_reason);
192196
GodotWebSocket.close(p_id, code, reason);
193197
},
194198

199+
godot_js_websocket_destroy__proxy: 'sync',
195200
godot_js_websocket_destroy__sig: 'vi',
196201
godot_js_websocket_destroy: function (p_id) {
197202
GodotWebSocket.destroy(p_id);

platform/web/detect.py

+19
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def get_opts():
4141
"dlink_enabled", "Enable WebAssembly dynamic linking (GDExtension support). Produces bigger binaries", False
4242
),
4343
BoolVariable("use_closure_compiler", "Use closure compiler to minimize JavaScript code", False),
44+
BoolVariable(
45+
"proxy_to_pthread",
46+
"Use Emscripten PROXY_TO_PTHREAD option to run the main application code to a separate thread",
47+
True,
48+
),
4449
]
4550

4651

@@ -211,6 +216,10 @@ def configure(env: "Environment"):
211216
env.Append(LINKFLAGS=["-Wl,-u,scalbnf"])
212217

213218
if env["dlink_enabled"]:
219+
if env["proxy_to_pthread"]:
220+
print("GDExtension support requires proxy_to_pthread=no, disabling")
221+
env["proxy_to_pthread"] = False
222+
214223
if cc_semver < (3, 1, 14):
215224
print("GDExtension support requires emscripten >= 3.1.14, detected: %s.%s.%s" % cc_semver)
216225
sys.exit(255)
@@ -221,6 +230,16 @@ def configure(env: "Environment"):
221230
env.Append(LINKFLAGS=["-fvisibility=hidden"])
222231
env.extra_suffix = ".dlink" + env.extra_suffix
223232

233+
# Run the main application in a web worker
234+
if env["proxy_to_pthread"]:
235+
env.Append(LINKFLAGS=["-s", "PROXY_TO_PTHREAD=1"])
236+
env.Append(CPPDEFINES=["PROXY_TO_PTHREAD_ENABLED"])
237+
env.Append(LINKFLAGS=["-s", "EXPORTED_RUNTIME_METHODS=['_emscripten_proxy_main']"])
238+
# https://github.com/emscripten-core/emscripten/issues/18034#issuecomment-1277561925
239+
env.Append(LINKFLAGS=["-s", "TEXTDECODER=0"])
240+
# BigInt support to pass object pointers between contexts
241+
env.Append(LINKFLAGS=["-s", "WASM_BIGINT"])
242+
224243
# Reduce code size by generating less support code (e.g. skip NodeJS support).
225244
env.Append(LINKFLAGS=["-s", "ENVIRONMENT=web,worker"])
226245

0 commit comments

Comments
 (0)