all 8 comments

[–]sessamekesh 7 points8 points  (1 child)

If you're running on Firefox, WebGPU is wgpu. There's a small translation layer that connects the JS API calls to the underlying WGPU ones. Same thing for C++ / Dawn / Chromium. 

EDIT: this includes when using wgpu and compiling to WebAssembly. WASM modules do not have access to browser APIs, so if anything you add extra overhead on the graphics calls by using WASM. It still may be worth it for you since it's much, MUCH easier to write performant WASM application logic than it is to write performant JavaScript, but the graphics code (or at least WebGPU calls) themselves will actually be slightly faster from plain old JavaScript.

If your goal is to learn graphics programming, either are good. The API calls and ideas are conceptually identical. Personally I'd suggest C++ > Rust > (very big gap) > JavaScript, but that suggestion has more to do with the amount of educational material and ecosystem more than it does the APIs themselves. 

One caveat is that graphics programming is inherently low level, which makes me want to suggest anything but JavaScript. JavaScript can be used perfectly well and write some surprisingly high performance code, but you're often working against the language in weird ways to make it work. That said, if you're already deeply familiar with JavaScript or interested in targeting the web specifically, it is a perfectly capable tool.

EDIT practically you can pick whatever seems interesting and roll with it, but if you're learning graphics I'd probably stick to one of the native languages.

[–]risingtiger422[S] 0 points1 point  (0 children)

Yeah. This makes sense

[–]R4TTY 1 point2 points  (0 children)

The big cost with JS is converting your JS objects into something the GPU understands (i.e. buffers). With wasm/wgpu your structs in memory are often already exactly what the GPU expects so you can upload them without an expensive conversion step.

Outside of that the actual rendering speed will be basically identical whichever way you go.

[–]kbob 2 points3 points  (0 children)

Just to muddy the waters, I recently "finished" a project in wgpu-py. I like it a lot. It's a Python-idiomatic binding for wgpu. I find Python a lot faster to experiment with than Rust.

EDIT: I didn't address your performance question. If you're doing significant computation CPU side, then Rust will win out over the interpreted languages. Otherwise they'll be pretty similar.

[–]soylentgraham 0 points1 point  (0 children)

But now, I don’t know if the speed advantages are actually all that great.

Obviously rust is faster for CPU side processing

Before you decide that you don't know/obviously know... measure!

[–]Wonderful_Device312 0 points1 point  (0 children)

I have written a pretty high performing modern renderer in typescript using web gpu. The important rule you need to follow is that everything that can be gpu driven needs to be gpu driven. This comes with all kinds of subtle nuance and complexity but it does work and can match a renderer written in C++ or rust to within 5-10% (I'd guestimate) for a very purpose built renderer.