16 ms·
WebGPU Fundamentals
- bhouston 3y agoTo see the spreading support for webgpu check out https://web3dsurvey.com https://web3dsurvey.com
- capableweb 3y agoUnfortunately no source published as far as I can see. Would be handy to have available + issue tracker. Since you seem to be the one responsible, I'll write my feedback here instead of a issue tracker: It shouldn't recommend hot-linking the script, but rather to include the script into your project (or at least include a Subresource Integrity attribute so it doesn't change unexpectedly). Also feels like it's unnecessarily minified as it's so small, hardly makes a difference in payload size, but makes it a lot harder to review.
- bhouston 3y agoI purposely didn’t mangle the collection script. You can read it easily with all original variable names. Just format it which many browsers do automatically these days. I did this so you can verify its behavior. I can add a npm package as well so people can embed the collection script as well. I will also add an integrity check as well.
- roschdal 3y agoI have been trying to add WebGPU support to https://www.fciv.net https://www.fciv.net - however the Three.js 3D engine I'm using isn't ready for WebGPU yet, and no current browsers support WebGPU yet.
- charcircuit 3y agoChrome supports webgpu on desktop.
- xchkr1337 3y agoRight now it's in beta (Chromium 113), stable support is planned for 26th of April
- esperent 3y agoThe Three.js people have been working on WebGPU support for several years now. I'm not how far they've got but there were already some cool demos a year or more ago.
- upchuck540 3y agoworks for me https://threejs.org/examples/?q=webgpu https://threejs.org/examples/?q=webgpu
- everdrive 3y agoI haven't kept up with WebGPU. As a more casual web user (and not a web developer) usually these features introduce more annoying webpages, as well as some new way to be fingerprinted as you move across the internet. Can anyone comment on this? Are there privacy mitigations that users should be enforcing to ensure their privacy is kept intact?
- fulafel 3y agoYou can disable JavaScript or WebGPU in browser prefs. (Once it ships...)
- midland_trucker 3y agoThe WebGL equivalent sites were a delight to go through; So well structured and thoughtfully displayed. It's so great to find a resource you can put some trust in amongst all the outdated and fragmented code out there. Looking forward to ploughing through this when I have the free time to.
- butz 3y agoGreat resource, but this website really doesn't want you going back to previous page.
- itsuka 3y agoIt appears that the issue only affects pages containing a code editor (and Firefox-only). I did a quick check and found that the editor is based on gfxfundamentals/live-editor, and it is doing stuff I'm not familiar with, such as injecting a blob for each editor and using some URL params hacks. I'm not sure what the issue is, but you can take a look at editor.js if you want to dig deeper. What's certain is that you'll need to hit the back button 1 + n times (n being the number of editors on the page). [edit] I have opened a GitHub issue for this
- greggman4 3y agoThis appears to be a bug in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1828286 https://bugzilla.mozilla.org/show_bug.cgi?id=1828286 Trying to find a workaround
- TachyonicBytes 3y agoThis is great! I have been meaning to get more into WebGPU! One question: Does anyone know more details about the Firefox WebGPU story? Even on this site's homepage, if you access it from Chromium with WebGPU enabled, you get nice floating rotating triangles, if you access it from Firefox stable, you get, understandably, static triangles. But if you access from Firefox nightly, with WebGPU enabled, you get a dark background and the error: TypeError: navigator.gpu.getPreferredCanvasFormat is not a function
- jeroenhd 3y agoFirefox doesn't implement that method yet: https://developer.mozilla.org/en-US/docs/Web/API/GPU/getPreferredCanvasFormat#browser_compatibility https://developer.mozilla.org/en-US/docs/Web/API/GPU/getPref... You can probably use "bgra8unorm" where getPreferredCanvasFormat isn't available, that seems to be the preference for at least Blink and WebKit. Chrome doesn't support rgba8unorm on Mac, probably because Apple seems to have chosen bgra8unorm as their format for their Metal API for some reason, so you'll have to use BRG rather than RGB if you want to support Apple hardware at the moment.
- vbezhenar 3y agoHow do I render text with GPU? Do I render text on texture with CPU and then send that texture to GPU? Do I vectorize it and draw millions of tiny triangles to approximate those vectors? It's interesting for me to explore WebGPU as a canvas for app development, but it's not obvious to me how to draw text and text is everywhere.
- itronitron 3y agoSome people have been using signed distance fields (sdf) to define fonts on the GPU.
- pavlov 3y agoNote that this approach is useless on its own if your app needs to render user-created text because nowadays everybody expects emojis to work and look roughly the same as on Apple’s platforms, which means detailed multi-colored layered vector shapes that SDF font renderers can’t handle.
- esperent 3y agoThe solution I've used for this, which was a bit tedious but not that hard to implement, was sprites for the icons/emojis and SDF for everything else. I'm sure there would be other solutions too, like layering. So it's not useless, you just need to get creative to overcome the limitations. Like everything else in 3D graphics.
- pavlov 3y agoYes, I agree — I did write “useless on its own” to highlight that you need to extend the SDF rendering model with a different one to handle actual user-generated text.
- unconed 3y agoUse.GPU handles this just fine: it uses a subpixel SDF mask with a plain color image. You get crisp edges, just the interior is a bit blurry.
- rvz 3y ago[flagged]
- flohofwoe 3y agoEh, AFAIK the WebGPU teams for Chrome, Firefox and Safari have been working closely together. Neither Firefox nor Safari are first, but I don't expect them to be much behind either. And as far as Chrome is concerned: WebGPU support for Android "isn't existent" either so far, currently it only works on desktop.
- illiarian 3y ago> Neither Firefox nor Safari are first, WebGPU is literally built in top of work done by Safari and Firefox.
- flohofwoe 3y agoApple and Mozilla were the first to have prototypes (one "inspired" by Metal, the other by Vulkan), both looked quite different from the final WebGPU spec though.
- illiarian 3y ago--- start quote --- On January 24, 2017, Khronos hosted an IP-free meeting dedicated to discussion of "WebGL Next" ideas, collided with WebGL working group meeting in Vancouver.[8] Google team presented the NXT prototype implementing a new API that could run in Chromium with OpenGL, or standalone with OpenGL and Metal. NXT borrowed concepts from all of Vulkan, Direct3D 12, and Metal native APIs. Apple and Mozilla representatives also showed their prototypes built on Safari and Servo correspondingly, both of which closely replicated the Metal API --- end quote --- (Note: Unlike Chrome, Apple and Mozilla followed the actual standards route: two independent implementations) --- start quote --- On February 7, 2017, Apple's WebKit team proposed the creation of the W3C community group to design the API. At the same time they announced a technical proof of concept and proposal under the name "WebGPU", based on concepts in Apple's Metal. --- end quote --- And so on https://en.wikipedia.org/wiki/WebGPU https://en.wikipedia.org/wiki/WebGPU Apple is literally at the forefront of this entire initiative with Mozilla close second. Chrome grudgingly agreed to join the others a full year later.
- mpldr 3y agoQuestion for discussion: when have we reached the point where the Browser Feature-creep is too much and we say "okay, a browser probably doesn't need this"? Because after seeing WebUSB and WebGPU I think my personal limit has been reached.
- dvngnt_ 3y agoI don't see a problem you don't have to use it
- chii 3y agothe more important question is whether the browser's surface area for bugs and perhaps security vulnerabilities are worth the marginal increase in features that most people might not use!
- throwaway60134 3y ago[dead]
- abirch 3y agoYou can find a security focused browser that don't implement these.
- mpldr 3y agoPlease, let me know which one!
- yellowapple 3y agoFirefox doesn't by default (and when that eventually changes, disabling it is an about:config tweak away).
- moron4hire 3y agoIt's not like native OS features don't have security vulnerabilities. At least all the major browser have at some major portion of their implementations that are open source projects. So if you're stuck working on Windows or MacOS, at least you can know that Web browsers aren't limited to one vendor finding and fixing those defects.
- baalimago 3y agoHighly unavailable still, but it seems to be non-experimental in chrome 113-115, as of writing this https://caniuse.com/?search=webgpu https://caniuse.com/?search=webgpu
- doodlesdev 3y agoSupport should land in stable in 11 days
- pmoriarty 3y agoCan this somehow be leveraged to crowd-train LLMs or maybe do something like SETI@home within the browser?
- icedrift 3y agoFrom what I understand not at this time but potentially in the future with different algorithms. DL training requires long sequential computations that can't be done in parallel the way folding at home could.
- wongarsu 3y agoNo, distributed training is one of these holy grails nobody has quite figured out yet. You can split training across multiple GPUs in the same computer, or multiple computers in close proximity connected by infiniband, but that's about as much latency as we can handle right now. We need some breakthrough to make it possible for internet-connected computers to usefully collaborate. If it did work we wouldn't be waiting around for WebGPU, it would already exist as a desktop program.
- sgc 3y agoPardon my naivety. The only reason individuals would willingly participate at a large scale, would be for an open source AI project. Does that mean once the problem is solved, everybody will likely be able to run their own state of the art AI, or are the real-time calculations too intensive for a single server?
- wongarsu 3y agoAs a reference point, the large version of facebook's LLaMA was originally designed to be run on 4 server-grade GPUs, but after it was leaked people managed to make it run on a normal computer with just a CPU and 40GB RAM or so, though it's somewhat slow when running that way. GPT 3 is about 3 times larger than that. But at least for LLMs we have mostly explored how to either make really big models with the best capabilities (OpenAI etc) or models that are faster to train for comparable capabilities (facebook etc). There's comparative little work done so far on models that are able to run with the least amount of resources possible, though there are indications that you can invest more resources in training to get models that are much easier to run (training a small model for really long to get the same capabilities as a larger model). That might be a great route for an open source project, spending great combined effort to make something everyone can more easily run at home. Of course that's mostly LLMs, for image generation you can easily run Stable Diffusion on any somewhat decent GPU, and being able to collaboratively train better models might be a huge boon there too.
- Razengan 3y agoRegarding all the arguments about ever-increasing browser complexity and the resulting inefficiency: Why is nobody asking the reverse question: How to make operating systems more like browsers?? From the end user's PoV (consider someone who isn't computer savvy) what are the actual objective differences in usability, between the OS and browser? -- • OS: Apps have their own windows and menu bars. • Browser: Multiple apps run in a single window, and have no menu bar. - • OS: Need to download and "install" apps before you can use them. • Browser: Just type the app's "name". - • OS: Need to make sure apps are compatible with your OS and hardware. Need to keep apps updated. Need to delete apps when out of local storage space. • Browser: Nope. - • Browser: Lets you share links with people to show them exactly what you're seeing in an app (YouTube, HN, Reddit) • OS: Nope. -- SO. Instead of constantly reinventing the wheels that have been perfected by operating systems for centuries, and then machete'ing through the resulting struggles of power and politics between the OS and browser, WHY NOT REMOVE THOSE HURDLES FROM THE OS?
- lacasito25 3y agoone can hope that with web assembly we can get closer to that dream, and eventually just remove the whole web browser.
- jeroenhd 3y ago.jar files exist and so far they haven't replaced any browsers as far as I can tell.
- jeroenhd 3y agoAll of this is perfectly possible. End users don't seem to want to use these features for native apps for some reason, though, and developers seem to have all switched to the web instead of building native experiences. It makes sense: native apps need to be developed for Windows, macOS, Android, iOS, and maybe Linux. Web apps need to be developed once. Android apps will work on Android, ChromeOS, Linux (after some setup), and Windows, but I doubt Apple is going to add an Android runtime to their platform any time soon. App stores are on every major platform and custom URIs for sharing app state and views are implemented on phones already. Most people seem to run their desktop applications either full screen or nearly full screen. Pin the Windows task bar to the top of the screen and you've basically got yourself a tab bar. I don't know about macOS, but Android and Windows will start clearing caches and temporary files automatically under storage pressure. Sandboxing applications is available on all platforms as well. I don't want every website to become a native application, though. I don't trust most websites enough to download native code from them. Let's not go back to the ActiveX/Java applet days where you needed to download some scary code for every website you wanted to visit. I don't see why I would benefit from WebGPU support, I think I'll leave it disabled by default. It's probably one of those technologies that'll be useful for platforms with overbearing control (i.e. how game streaming on iOS is made possible). Maybe some small itch.io games will make use of it so I don't need to download Some Guy(TM)'s native executable every time I want to try a small experimental game.
- geenat 3y agoCompute on WebGPU is gonna be interesting- "crowd sourced" model training.
- archerx 3y agoI wish they had kept the c/c++ syntax style for WGSL, the rust syntax is just awful and alienating.
- jeroenhd 3y agoI much prefer the new syntax. The C based shader languages always end up in some kind of uncanny valley where it looks like C and C++ but behaves completely differently. It's not exactly Rust either, the @annotations aren't written like that in Rust for example. The let-syntax is closer to Javascript with type annotations, so that makes more sense for web programming than doing C style variable definitions. Using let and var instead of let and cons is a bit of a weird choice, though. Other than the variable definition syntax, this syntax may as well have been C++-based without all the verbose names that C++ likes to add to its namespaces. Shades will usually mostly be math code, though, so it shouldn't even matter all that much in practice.
- archerx 3y agoI feel like they made a lot of weird choices like let being the new const, while still having constants, that won’t be confusing at all. While disappointing I will try and port over some of my webgl stuff and see how I feel about it.
- FL33TW00D 3y agoNot if you're a rust programmer!
- archerx 3y agoThankfully I am not and never will be.
- hatuthecat 3y agoNot sure how it remotely looks “awful and alienating”. It looks like basically every recent language to me (swift/kotlin/rust/typescript). I feel like you just saw something that has the same numeric type names as Rust and jumped to conclusions.
- billti 3y agoThis looks heavily geared towards graphics. I’m interested in the compute capabilities of WebGPU to build an in-browser simulator (e.g. physics/quantum). Anyone know of any good resources for that? (Samples, best practices, etc.)
- qz_kb 3y agoThis is usually done with shaders and a circle of buffers which maintain state.
- superzamp 3y agoTotal graphics / shaders / GPU noob here. Does that mean you'll essentially get free visualisations (albeit non-sensical ones) as a byproduct of your computations?
- jesse__ 3y agoI think it depends, but given an arbitrary compute pipeline, you should be able to write the results (or intermediary results) to the screen with minimal effort.
- sva_ 3y agoNo, it's an @compute shader rather than a combination of @vertex and @fragment shaders (which would do graphics) in the case of WebGPU. Surely you could visualize it but not as a side effect.
- AgentME 3y agoIf you wanted to do compute in a shader before WebGPU with WebGL instead, then I think the answer is kind of yes. It wasn't "for free" without any code but it was required to do. But now WebGPU supports compute shaders properly so you don't have to do compute in a shader that produces textures.
- fulafel 3y agoA texture in WebGL is just a memory buffer that can be accessed by shaders. It doesn't end up on screen automatically.
- thewebcount 3y ago> It is expected you already know JavaScript before you read this article. Concepts like mapping arrays, destructuring assignment, spreading values, async/await, es6 modules, and more will be used extensively. So in other words, it’s just like Vulkan where the beginner tutorials have you set up your own allocators, deal with fencing, and use a swap chain just to put a single triangle on the screen? What the actual fuck? This doesn’t sound at all like “fundamentals” and makes me not want to ever use it if the very basics require all of the above. I think your average programmer, even one who does 3D graphics, is going to look at this and just be turned off.
- waboremo 3y agoMost of those concepts are foundational to web programming, yes. I also believe that for most people who "just want a triangle on the screen" they'll be utilizing other higher level tools to do so, and those tools will then do the "dirty" work of using WebGPU. Think, Figma making it easy for people to design but behind the scenes it's incredibly complex using C++ (might be outdated on this) compiled to WebAssembly. Same will apply here, most people who want lower level access to the GPU aren't really doing so just because of simple triangles or basic graphics work. There are already engines and frameworks for them.
- shepherdjerred 3y agoThis is a beginner tutorial for WebGPU, not JavaScript. It's entirely reasonable to assume knowledge of language features.
- spiralganglion 3y agoWebGPU is not meant to be a high-level, beginner-accessible graphics API. It's meant to be a low-level GPU API that expert users can build nice tooling atop. It's an embodiment of the extensible web manifesto's principle that browsers ought to expose lower level hooks to enable API experimentation in user space, like we had with Promises starting out as a constellation of competing approaches in libraries.
- MrResearcher 3y agoIt's a pity that tfjs never truly developed any decent ops. E.g. you need lgamma to implement the cap for zero-inflated poisson regression and tfjs simply doesn't have that: https://github.com/tensorflow/tfjs/issues/2011 https://github.com/tensorflow/tfjs/issues/2011 Those guys simply dropped the ball on the floor, and the further framework development fizzled out. I tried to find if WebGPU could be a replacement, but it's very hard to find a good description of the API surface. MDN also doesn't seem to help much – https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API I really hope that one day I'll find something similar to pytorch, only in typescript. Tell me I'll live long enough to enjoy that day.
- catwell 3y agoWebGPU does not play in the same league as tfjs, it is a successor to WebGL, the technology tfjs is implemented with. There is already a WebGPU backend for tfjs: https://www.npmjs.com/package/@tensorflow/tfjs-backend-webgpu https://www.npmjs.com/package/@tensorflow/tfjs-backend-webgp... There are also several ONNX runtimes using WebGPU in case you want to run models written with PyTorch.
- MrResearcher 3y agoExactly, the lack of the deep learning frameworks to train decent models on the client side forces us to use pytorch on the server, leading to centralized data collection, privacy concerns, copyright and data ownership issues. Imagine the world where you could trivially train a model entirely on the client side, without uploading all that data to the cloud. Then we can settle on federated learning or simply use ensembles of models trained on different clients, all without sharing data with the server. BTW, I did have some experience with ONNX, also ran into problems with some ops (like nn.SELU not working correctly in the browser - https://pytorch.org/docs/stable/generated/torch.nn.SELU.html#torch.nn.SELU https://pytorch.org/docs/stable/generated/torch.nn.SELU.html...).
- visarga 3y ago> Imagine the world where you could trivially train a model entirely on the client side, without uploading all that data to the cloud. You just rediscovered "Federated Learning", but FL also allows you to benefit from the training being executed in other edge nodes, all without disclosing any data. Instead of sending the data to the training server, they send the model to the users to train on a few batches of user data, then average the models from everyone.
- rastette 3y ago[flagged]
- sva_ 3y agoIt is sad that WebGPU has pretty poor support under Linux apparently. Even more so, that it builds on Vulkan which isn't fully supported on older architectures (like Haswell.)
- wilg 3y agoAh, this brings back memories of being blocked by Jonathan Blow on Twitter for poking fun at him for being really mean to the people who worked on WebGPU. https://i.imgur.com/ZDgXBXH.png https://i.imgur.com/ZDgXBXH.png
- blurbleblurble 3y agoOne of my favorite fundamentals I'm hoping for with WebGPU is for it to finally work on Linux/chromium.
- deleted 3y ago[deleted]