WIP: WebAudio Worklet shared memory #543
No reviewers
Labels
No labels
CI
all
basisu
blog
bug
build
contributor-friendly
core
correctness
deferred
dev
direct3d-headers
docs
driver-os-issue
duplicate
dxcompiler
editor
examples
experiment
feature-idea
feedback
flac
freetype
gamemode
gkurve
glfw
gpu
gpu-dawn
harfbuzz
help welcome
in-progress
infrastructure
invalid
libmach
linux-audio-headers
long-term
mach
mach.gfx
mach.math
mach.physics
mach.testing
model3d
needs-triage
object
opengl-headers
opus
os/linux
os/macos
os/wasm
os/windows
package-manager
priority
proposal
proposal-accepted
question
roadmap
slipped
stability
sysaudio
sysgpu
sysjs
validating-fix
vulkan-zig-generated
wayland-headers
website
wontfix
wrench
www
x11-headers
xcode-frameworks
zig-update
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
hexops/mach!543
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "webaudio-shared-memory"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR will make the WebAudio backend use a AudioWorkletNode that shares memory with main thread.
atomicsandbulk_memoryfeatures forwasm32targetsetLibExeObjStep.import_memory = trueforwasm32targetsLibExeObjStep.shared_memory = trueforwasm32targetsget themax_memoryof the WASM module before instantiating it, as the spec requiresmax_memorybe specified for shared memorycould write it out to the template in the build stepmight be able to retrieve the information usingWebAssembly.Module.imports, need to do more researchAudioWorkletProcessorAudioContextand create anAudioWorkletNodeand before callingwasmInitto avoid issues with initializing memory twiceThat's all stuff that would need to be done before doing the work to match the sysaudio interface. This repository demos a webassembly module that does most of these steps for a standalone module.
FYI I just merged https://github.com/hexops/mach/pull/537 which may give you some conflicts, should be easy to fix though - let me know if not
Should be good, I based this branch off of the other one.
Hm, github says there are conflicts:
Maybe it just needs a
git rebase origin/main?I just had to rebase, not exactly sure what I did to make it not recognize that. Really been struggling with git on these branch 😅
Alright, an update on this.
LLVM protects from double initialization of memory
We don't have to implement anything for this -- LLVM sets a global variable to protect from double initialization already. This means I can switch some of the code over to using
sysjsand stop worrying about it.$__stack_pointeris a instance globalThis means that we don't have to worry about the
$__stack_pointerconflicting between threads, since each thread will have it's own instance.However this is not enough since the region of memory that is the stack is still shared between threads.
We can tell LLVM to export
__stack_pointerThis allows us to modify the stack pointer from JavaScript like so:
We can use this to write an API where we allocate the stack for a new frame at runtime.
This does require one more feature to be enabled for the WASM "CPU",
mutable_globals. And we have to manually specify the symbols we want to export. But I dont't think those will be dealbreakers.I think I've gathered all the pieces of the puzzle at this point, the rest is implementation. I'll try to find some time to implement it this week.
Latest commit is generating sound as it should! There is still a bunch of cleanup to do, but it works
Sorry I haven't had a chance to dive into this yet. I am very excited about this work, but will be travelling the next few weeks so may not have a chance to look at this in depth until after. Hope that's okay!
Yep, that's okay. There's still some work to be done cleaning it up. I'll mark it ready for review once that's done.
https://github.com/hexops/mach/issues/823
Pull request closed