diku-dk / futhark

:boom::computer::boom: A data-parallel functional programming language
http://futhark-lang.org
ISC License
2.38k stars 165 forks source link

Add a WebGPU backend #1403

Open athas opened 3 years ago

athas commented 3 years ago

This is a big one. Current plan is to generate C that calls native WebGPU, which Emscripten can translate to WASM+WebGPU. Two major challenges exist:

Before we can even think about starting the implementation, we need to gain more WebGPU expertise. The best starting point is to write some WebGPU compute shader programs, initially in straight JavaScript, and then in C translated with Emscripten.

On top of these significant tasks, WebGPU is also not a ratified standard and browser support is really shaky. This is a technically very challenging project in all regards.

athas commented 3 years ago

Some notes.

Apart from the blocking/polling issue, the WebGPU C API looks reasonably simple (although more complex than OpenCL and CUDA). I don't think it will present major issues. I have yet to closely study WGSL (the language for writing shaders/kernels), but I did notice that it is missing many important scalar types (integers other than 32-bit for example).

athas commented 3 years ago

It may be worth investigating how feasible it is to convert SPIR-V shaders to WGSL shaders. We already have parts of a SPIR-V codegen in the Vulkan backend branch, and we'll probably need a SPIR-V codegen eventually. The biggest question is whether we can expect such a conversion program to be available to our users.

kfl commented 3 years ago

Naga, which is used in the wgpu and gfx-rs projects, can translate SPIR-V to WGSL:

cargo run my_shader.spv my_shader.wgsl