WebGPU Fundamentals
webgpufundamentals.org
webgpufundamentals.org
There are also several ONNX runtimes using WebGPU in case you want to run models written with PyTorch.
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...).
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.
Surely you could visualize it but not as a side effect.
outputTexture2d[inputTexture2d[inputPosition]]++
In other words, if you have a large texture with (x,y) coordinates of points, can you draw another texture that shows a density cloud of these points? In webgl2 it becomes a phd level problem.
https://emmy-viewers.mentat.org/dev/examples/simulation/quar...
https://emmy-viewers.mentat.org/dev/examples/simulation/toro...
Use.GPU looks like it will be close to a drop-in replacement for MathBox, running on WebGPU. Maybe someday I’ll actually be able to build my general relativistic ray tracer, with explorable symbolic physics all the day down…
Looking forward to ploughing through this when I have the free time to.
The OS runs on hardware, what do you think is below the OS you're running?
Even excluding VMs, there are a lot of OSes running in a modern computer. Some chips have their own. BIOSes and Secure Enclave, networking chips, and probably a dozen more.
Try not to be a condescending dickweed, if you can.
https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=chrome
https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=firefox
https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=webkit
Those are the main reasons. And seeing how browsers are essentially designed to run other peoples code with minimal to no vetting processes, I consider this a serious issue.
How many times have _you_ as a developer, run arbitrary scripts from the internet? Blindly accepts packages that you have not vetted?
Remember Flash? ;)
Every new feature is more space for security issues to exist.
But browsers don't limit themselves to serving your needs only, and they are not in the business of promoting your approach to computing among their users. Why would they?
One example of many: Backspace no longer taking your to the previous page because that conflicts with usage in web apps.
Again, it did not happen without any reason, it happened for a reason. The purposes the modern browsers serve apparently are more important to their users than that original purpose!
Indeed, I believe there are obscure browsers that don't support any of this new stuff, and are only good for rendering plain old HTML. They remain obscure for the obvious reason: they cannot be used for what most people use the browsers most of the time.
Sure, but where do you draw the line really? For me, having WebUSB and WebMIDI for example is useful, I want to be able to interact with synths over MIDI in the browser, or be able to access other accessories. I also love the idea of GPU access, so my personal limit has not been reached.
Multiply this by every vendor, developer and user of every browser who contributes to the specifications, and you end up with probably 1000 different directions everyone wants to move in. How do you decide which is the right direction?
Right now, the choice you have is which browser you use. If you don't want WebUSB or WebGPU or anything else "new and fancy", choose a browser that doesn't implement those things.
Examples?
(Sure, it's Chrome-oriented ones. We've seen similar previously with IE, by the way.)
We have standards for the web. Real ones: the docs, which are discussed and approved in the industry. We have them for a long time!
So if some browser does not comply to the standards, it's really not the best strategy to adapt a site to the browser instead of the standards.
We are in the situation when (effectively) one company (Google/Alphabet) can lead anything to the whole market, step by step (even when changes contradict the web standards that are in place). The market is not the browsers market, of coyrse, but the internet ads through browsers control, which brings the most money to Google. By projecting its power to each and any aspect of it, Google ensures the uninterrupted market control for years ahead. So Google will continue to do. In the long run, we need to rely on standards instead of specific browsers. Otherwise it's just the monopoly of Google and web tech "market" is just their own backyard. That will bite us all hard.
It's not too good. It's just wealthiest. Because it holds ads market monopoly. Because it happens to be the popular search engine at the same time.
But it's not the best. Firefox is on par (I know they get some (most?) payments from Alphabet). And people were using Firefox/Netscape browser long before Google existed.
So it's not super frequent, but every few months there are important things I can't do in firefox.
If I used chrome daily perhaps I would see the opposite (broken on chrome, works on firefox).
I get the same feel from DuckDuckGo. I use it, till it doesn't work, then switch to google when it doesn't. Of course google would perform better, as I only use it for the cases where DDG fails.
It's a very clear trade-off in the hands of the user, which is correct.
I'm not sure I trust people who say something doesn't work in Firefox, unless they tried it in a fresh profile with default settings.
You'd need some tinkering to open a new browser window per monitor, couple of routes on 127.0.0.1 for config.
If it was something like a modern POSIX I don't think you'd have much complaining. But it's a lot heavier than that.
Help me understand why this is. Is it because there aren't native programs for the platform you're using? Is it to allow plug-ins or other abilities that wouldn't otherwise be available? Is it so that you can sync up with other musicians and play together in a way that wouldn't be possible without a browser?
choose a browser that doesn't implement those things.
The way feature creep have been going lately, in about six months that will mean Lynx.
Plus, plenty of languages have cross-platform runtimes and libraries, so not a big issue, not everything needs to be JavaScript.
Easier to create, easier to share and run. Mainly easier to create because the ones I'm sharing small MIDI sequencer experiments with are also web developers, so we just send each other links where we can run stuff direction from, and we can help each other out as we all use the same technology. Really easy to understand what the other is doing too, as you just open up the source of the page and that's it.
I've played around with other languages/runtimes for doing the same thing, but nothing is as fast to implement as with JavaScript, probably mostly due to familiarity.
It's like saying "if you don't like the laws(/taxes/whatever) where you live, go somewhere else" and acting as if I can just hop on over to Mars. I can't.
As we all spend most of our time inside of browser interfaces its not a surprise we see app, features and interfaces move to that process portal to. (Online IDEs, Cloud, Photo editing, etc.) Sure you can use your solution but in general, as always, its whats most efficient for the masses.
Eventually I'd like to see WebGL deprecated, and perhaps an extension released to reimplement it. Or it could be adapted to translate calls to WebGPU, rather than having a completely separate implementation.
Is that realistic? No, of course not. Browser vendors take backwards compatibility pretty seriously, and WebGL is used on a ton of websites. Still, that'd be my preferred solution for avoiding said feature creep.
It's nowadays also a cross-platform insta-deployment GUI application runtime environment with mostly bad native OS integration and performance characteristics (both ~improving, there's even native filesystem access now).
In any case it's Good Enough (C), so it sticks.
edit: wow, I had no idea and I've been a web dev for over a decade lol
Free yourself from the notion that a web browser should do anything more than browsing the web. native applications have existed for decades, no reason to bloat the scope of a browser.
You seem to demand that people ignore this reality, because you don't like it. This is not helpful.
I don't like this reality either, but despite that I find your statement also factually incorrect: "native applications have existed for decades, no reason to bloat the scope of a browser".
Of course there are reasons, otherwise people/companies won't do it, and users won't use bloated browser that give them no benefits.
I agree that downsides outweigh the upsides, but the upsides are obvious and immediate while the downsides are long-term and mostly subtle...
The reason is of course control. Things running in the browser gives Google control. That's why they push for everything running there. Want to compete with Google? Tough luck, no tracking for you while they give themselves IDs built into the browser. Do something Google doesn't like? Maybe your site isn't "safe" enough according to Google and won't be shown to users. Invested in your webapp but want to integrate something novel? Guess who gets to decide if you can?
Seeing a semi-technical acquaintance use in-browser software for daily productive work hurts my programmer's soul. It's alright for some light things, like vacation planning, but remote desktop or an IDE...
Then there's that other scourge of Electron-like apps with gigantic memory budgets and all. I have resigned to throwing more hardware at it when I can't guarantee a lighter replacement (i.e. in a work setting):
All my productive systems have 32GB RAM and 8+ threads now and with browser, Teams, Outlook, IDE and dev containers the air's getting thin again :/
I really dont want to see a repeat of phone apps for every company I interact with.
Seems like a perfectly reasonable new feature to me. I'm actually looking forward to people using this to build some cool stuff. Why should that not be a thing?
It seems clear to me that the main issue here is that a lot of programs aren't closely tied to the hardware or the OS. Building them to be so is an annoyance for both users and developers. As Scott McNealy said, you don't need to know how to operate a nuclear power plant to turn on the lights, and most users just want to get stuff done.
That we have three major operating systems still going relatively strong is evidence that there are differences that matters to people. But for a lot of applications those differences don't. The WebXYZ stuff thus increases usability a lot by simultaneously solving the cross-platform compatibility issues and distribution.
In my ESPHome example above literally opened the website, plugged in the USB cable to my device, clicked a button on the web page and the job was done.
So while I don't really like that the same web browser is used to surf other web sites, given that these WebXYZ components present additional security risks and fingerprinting opportunities, I can't deny that they're useful.
Excited to try it out with some ESPHome projects too now.
Though ironically maybe given that the browser can do so much is the reason that Microsoft has to focus on ‘value add’ crap instead of just a rock solid OS. Which sets up a self reinforcing cycle. Microsoft should recognize that this was intentional move by Google and not take the bait.
https://github.com/atrosinenko/qemujs
https://jamesfriend.com.au/pce-js/ibmpc-games/
https://leaningtech.com/webvm-server-less-x86-virtual-machin...
and so on...
I agree there have been some questionable 'advancements' in the web spec recently (web workers as a solution to multithreading, for example, were hilariously inadequate for quite a while), but as far as I can tell WGPU is a solid effort to unlock browsers as an actually interactive platform, instead of the fairly static image/text display devices they are today.
Maybe our visions of what browsers could or 'should' be are different
If you need to scale the text arbitrarily or render it in 3D space you can look at multi channel signed distance fields (MSDF) which also renders out each character but encodes some extra data which makes them scalable. It has pretty good results
We could have had them three years ago.
https://registry.khronos.org/webgl/specs/latest/2.0-compute/
https://github.com/9ballsyndrome/WebGL_Compute_shader
And then Google decides not implementating it after all, because of WebGPU.
https://github.com/9ballsyndrome/WebGL_Compute_shader/issues...
Here's eg one case: https://github.com/astiopin/webgl_fonts
WebGL 2.0 is kind of PlayStation 3 like in capabilities, that we seldom see that in action besides shadertoy, Google Maps/Earth, and 360° views on ecommerce sites is another matter.
That is becoming feasible, using something called mesh shaders. The millions of tiny triangles will only be created on the fly inside the GPU, you will just send the vector geometry.
Compute shaders avoid all these problems and work on WebGPU 1.0 today.
I'm a bit confused. Can't you send the shape of O as a low res rough band (a closed wide loop) and enhance it in the mesh shader? This is how previous generation tessellation shaders and sub-division surfaces worked.
Of course there's also always the option to overlay DOM elements over the WebGPU canvas if you just want to render some 2D UI on top of the 3D rendering.
Also, you can render and rasterize fonts + dynamic text to a texture and UV map it to a quad in 3D space if you need to. This is pretty inexpensive and easy to do as well.
Lastly, the most difficult but performant option is using a shader to compute the font rendering. This is basically moving the font raster from CPU to GPU and there are various shader examples for this in GLSL (popular shader format used by WebGL/OpenGL) that you can use.
I recommend the second option. Rasterize your font with stb_truetype to a bitmap, and draw quads yourself
It shouldn't matter that much if it takes a few frames to layout and/or update your ammo count or whatever.
Now, that's not to say it has to be that way; real engines have a separate render thread that would sort of solve that problem. And they run the game update code in parallel, and all kinds of other stuff. But, by the time you have all that stuff, you can probably rasterize a font and draw quads ;)
But don't take my word for it. Maybe it's better now. Make a thing that moves some divs around in a requestAnimationFrame callback and take a look at the profile. I bet 2% of the time the layout engine takes 30ms+ to do basically nothing
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 functionYou 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.
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?
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.
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.
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.
If it did work we wouldn't be waiting around for WebGPU, it would already exist as a desktop program.
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.
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.
I don't use any of these and because it just<does>
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
https://bugzilla.mozilla.org/show_bug.cgi?id=1828286
Trying to find a workaround
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.
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.