Live data from Hacker News

Porting WebGL Shaders to WebGPU

construct.net

41–50 of 64 posts

Re: Porting WebGL Shaders to WebGPU

#41
As someone who's never used this API: is there some kind of permission prompt for this before websites start trying to use my GPU for crypto mining? Most CPU crypto miners were basically worthless, but GPU power is a whole lot more powerful.

Re: Porting WebGL Shaders to WebGPU

#42

> GLSL supports the ternary ?: operator. WGSL does not support this, but provides the built-in function select(falseValue, trueValue, condition) which does much the same thing (although mind that parameter order!). I'd really like to hear a justification for that parameter order. To me it seems like the 4th best option out of 6.

It could be because it matches the order of glsl's `mix()`. Not sure why glsl chose that order, though perhaps you might find it less unintuitive for an interpolation than a select. (Mix acts as a select rather than interpolation when the third argument is a boolean)

Re: Porting WebGL Shaders to WebGPU

#43

> GLSL supports the ternary ?: operator. WGSL does not support this, but provides the built-in function select(falseValue, trueValue, condition) which does much the same thing (although mind that parameter order!). I'd really like to hear a justification for that parameter order. To me it seems like the 4th best option out of 6.

lerp(zero, one, t) -> select(falseValue, trueValue, condition ? 1.0 : 0.0)

Re: Porting WebGL Shaders to WebGPU

#44

> GLSL supports the ternary ?: operator. WGSL does not support this, but provides the built-in function select(falseValue, trueValue, condition) which does much the same thing (although mind that parameter order!). I'd really like to hear a justification for that parameter order. To me it seems like the 4th best option out of 6.

It could be because it matches the order of glsl's `mix()`. Not sure why glsl chose that order, though perhaps you might find it less unintuitive for an interpolation than a select. (Mix acts as a select rather than interpolation when the third argument is a boolean)

That makes much sense, thanks! But then why didn't they call it mix() or lerp() or interpolate()? I would have immediately spotted the logic behind it.

EDIT: I think I get it, there also a mix() with a different type signature but same parameter order.

Re: Porting WebGL Shaders to WebGPU

#45

As someone who's never used this API: is there some kind of permission prompt for this before websites start trying to use my GPU for crypto mining? Most CPU crypto miners were basically worthless, but GPU power is a whole lot more powerful.

No permission prompt, just as there is no permission prompt for WebGL (which already enables crypto mining on your GPU).

https://arxiv.org/pdf/1904.13071&ved=2ahUKEwipqPGblenzAhWDbs...

Re: Porting WebGL Shaders to WebGPU

#46
post #27

Earlier quoted context omitted.

It is currently shipping behind a flag in desktop versions of Chrome (and all its derivatives), Safari, and Firefox. It is also shipping behind a flag in Firefox for Android. I don't think it's too far out from finally shipping. The biggest boon would be for mobile devs to help avoid the 30% store tax, but this is also the reason why mobile Chrome and mobile Safari (especially Safari) tend to lag behind in major ways…

What Safari is shipping behind a flag is not anything like the current version of WebGPU. I don't think it supports WGSL, for example. It's going to be a long time before all three browsers have shipped implementations that are interoperable and not behind flags. I don't think WebGPU is the biggest thing that's going to let mobile game devs start shipping on the web. WebGL 2 can do graphics well enough today. Other t…

I play a lot of web games without any of that stuff now

Re: Porting WebGL Shaders to WebGPU

#47

Our team is working to build out support for Unreal Engine 4 and Unreal Engine 5 to support WebGPU, so game developers and real-time 3D developers can export their creations to the web at near native performance and access features like computer shaders. Long term goal is to disrupt Steam and the App Stores. We're also working on WebXR support to enable UE VR apps on the web. If anyone is interested and wants to lear…

As a gamer though, why would I want to play any of these developers' games through the browser instead of Steam?

Yep. I don't see this game-in-the-browser thing taking off anytime soon for anything serious. Player retention, and immersion, are terrible. Casual 'adware' games, maybe.

Re: Porting WebGL Shaders to WebGPU

#50
post #33
post #8

I took a very different approach for porting my WebGPU shaders over: I have far too many shaders to port (sometimes pretty massive ones! [0]), so I used Naga [1] at to runtime-translate my GLSL shaders to WGSL. I had to get involved a bit upstream to fix quite a few different bugs in the implementation, but once I got it working I was really happy with the result. It's quite fast, it compiles to a pretty light-weight…

Why do you do this translation at runtime--causing every user to have to re-execute it--instead of at compile-time? Is there some kind of per-user optimization this makes possible?

Not GP, but shader translation depends heavily on device capabilities and the current pipeline state. In principle I think it's possible to cache a lot of this on the client, so that it only has to be run once per install (or per device fingerprint change) rather than once per execution, but I don't think that's implemented yet.
Post reply on HN