Hello!
I have a personal project that has a plugin system based on WASM (all plugins are just *.wasm files).
I will have 2 hosts for those plugins: one is web based (in the web browser) and the other is native (using wasmtime).
The same plugin must work the same way on the two hosts, so I thought using WASI was a good idea!
My issue is that the plugins must be able to render images, so I'd like to use WebGPU (because it's available on all platforms), but WASI doesn't have WebGPU support (though discussed on this issue).
I'd like to experiment locally and add the WebGPU API to wasi-common, but I have no idea where to start and how to test it.
Maybe I should mention the fact that I'm on Windows 10 (though I have WSL 2 and a laptop running a native GNU/Linux distribution if the need arises).
Thanks!
@nasso Nice suggestion, maybe the proposal of WASI-nn (https://github.com/WebAssembly/WASI/issues/272) would help to formulate the entrypoint?
@Leon Wang what do you mean by entry point?
You can design the wit interface based on the WASI-nn proposal.
yeha my inner guess was correct then :p
Are there tools to make the process a little less repetitive? I think the interface would be very similar to this header
Sorry I'm not very familiar with the tool, but I think you can find it from the organization (https://github.com/bytecodealliance/wasm-tools or https://github.com/WebAssembly/binaryen).
Thanks! I'll look into it!
The WebGPU API has a lot of custom types, should I define those types in typenames.witx like its done for the other witx files? I guess not, since the nn proposal doesn't, but I prefer to ask!
i'd discourage adding more stuff to typenames.witx - one thing we've talked about informally is that, with a bunch of proposed extensions to wasi including your own, we are going to need namespacing of type names
so probably all typenames will end up being defined inside modules at some point, or maybe some other mechanism to allow many namespaces
at any rate, theres no reason to add them to typenames.witx if you can just put them in a separate file
so id encourage you to write all of the webgpu types and modules in a separate witx file, and only take deps on the existing wasi via (use "wasi_snapshot_preview1.witx")
, because at some point soonish typenames.witx may not exist anymore.
oh i should use the snapshot? im in the ephemeral folder right now
i can still use
it from that folder?
either way, for now i will create them in my witx
file and prefix them like in c (e.g. $gpu_adapter
)
though, what is the usual way to type opaque types in a wasi interface? like, im basically mapping the webgpu API from webgpu.h but im not sure if i should typename
pointers (e.g. on line 59) to u64
or if there's a better type for it (usize
i'd guess?)
after second thought, maybe i should model the module type after the WebGPU WebIDL instead?
sorry, was afk. yeah, rather than snapshot you should import ephemeral if you're in ephemeral.
witx describes something a lot closer to a C header file than webidl
the interface types repo contains a writeup some explanations of why webidl is not very well-suited for describing webassembly interfaces. but in short, i would stick to the c headers
the goal of witx is to eventaully describe interface types, but since there are no implementations of that proposal yet, we are still describing a C ABI. so, starting with a c header is the best way for now.
opaque types are called handle
in witx
they get represented as u32 for now. when interface types comes, itll be possible to represent them as ref types (for languages that support it), u32, u64, etc.
thanks for the info! i will stick to the C header then!
Pat Hickey said:
sorry, was afk. yeah, rather than snapshot you should import ephemeral if you're in ephemeral.
there doesn't seem to be a wasi_ephemeral_preview1.witx
, what should i import ?
also, how would i represent C enums with explicit values (like on line 85) in witx?
wgpuCreateInstance
takes a WGPUInstanceDescriptor const * descriptor
as the first parameter, should i represent that as a u32
or is there a better type for that?
Last updated: Dec 23 2024 at 13:07 UTC