Point of WebGPU on Native
kvark.github.io
kvark.github.io
There's "one small thing" I'd like to see in WebGPU for the native use case: an optional compile-time configuration feature which allows to pass in "backend-native" shaders so that all the runtime-shader-translation code isn't necessary.
Example size for compiling "Hello Triangle" on macOS before and after stripping, both using the Metal backend:
- with sokol-gfx: 95 KB, 91 KB
- with Google Dawn: 5.2 MB, 4.0 MB
I bet that most of that 4 MB overhead is coming from the integrated shader validation and translation code. I haven't tested with wgpu-native, but I guess the size overhead will be similar.
Since native applications don't need the strict shader validation of the web platform, this probably would also speed up pipeline creation a bit :)
PS: clarification, the executable size for Dawn is also using sokol-gfx but using its new WebGPU backend and statically linked against Dawn (which in turn is using its own Metal backend), so not a 'Hello Triangle' built directly on top of the webgpu.h API. The size difference should be negligible though (at most a few Kbytes more).
I'm feeling the same way, I'm interested in getting into doing a little graphics programming as a beginner, but the whole thing does feel impenetrable.
The hardest part for beginners is probably wrapping their head around the concept of the rendering pipeline, with it's various stages. Once this is settled, it becomes much clearer what the various shaders do and how they interact with each other. So I'd higly recommend spending some time to understand rendering pipelines first.
It's also worth getting familiar with terminology early on, because common terms in the context of graphics programming have different meanings to their common usage. e.g. I've found it helpful to think of a "vertex" first and foremost as an element of an array, which is processed SIMD-style by the "vertex shader". In most cases it is the co-ordinates of a polygon vertex, but usually with other data bundled in the element as well such as texture co-ordinates. The term "shader" seems to be used for any program that runs on the GPU, regardless of whether it does shading of any kind.
Oy vey
WebGL is better than that because it is only the useful, fast subset, and provides some objects too. Plus JavaScript is easier to work with than C, too.
Anyway modern APIs are not stateless, having an object that contains the state is the same. In the end, it is still all about bind this, bind that, do this, do that.
I wanted to play with Nvidia's real-time raytracing. They have a nice tutorial to show a triangle.
https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytrac...
https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytrac...
https://floooh.github.io/sokol-html5/
A complete Hello Triangle fits in a single source file of about 80 lines, and the API structure of sokol-gfx is close enough to modern 3D-APIs that it also serves as a useful starting point if you want to move on to Metal, D3D12 or Vulkan (or even WebGPU) later.
Then you should be looking at WebGL, not WebGPU!
https://news.ycombinator.com/newsguidelines.html
In this case specifically I'd just use the second half of your comment, the first half just detracts from the message and sounds petty.
In fact, if you think about it, what is "petty" isn't talking about downvoting, but the ability to downvote itself. Flagging is fine, because trolls will always be around.
It would be the same as using SVAlib or Allegro nowadays.
They are still there, but not longer map to existing graphics hardware.
That is false. There are already library implementations of legacy OpenGL, modern OpenGL, OpenGL ES, WebGL, legacy Direct3D, Direct3D 10/11, Direct3D 12, Vulkan and others.
Major players like Microsoft, AMD, Khronos, Valve and others already depend and employ people on providing those APIs and libraries long-term.
Those APIs are not going anywhere, even if a hardware vendor decides to only provide a low-level one (which is understandable, by the way...).
> They are still there, but not longer map to existing graphics hardware.
They have never mapped to hardware, so there is no real difference between now and then.
That is like telling someone that coding against POSIX.1 is all they will ever need for their applications.
Also, there's a lot of room for sane APIs between GLES2 and Vulkan, so much room that a single "standard" 3D-API doesn't make much sense TBH since there are many different opinions on where the "sweet spot" for a 3D-API lies between ease-of-use, feature coverage and acceptable layering overhead.
WebGPU is a low-level API is more flexible than WebGL, which means more complexity. That is why it is being introduced, after all!
Run another filter? good, switch everything on global state. Render another scene with different texture? Set everything again.
Moreover... if you forgot to reset something after change it. You got weird bug that only happen under some specific order of operation. Because everything share a global state.
And it is full sync. A shader takes long time for render also makes your whole page non responsive, which is a pain. (open the list page of shadertoy, you will know what am I saying)
The full sync is a problem of how WebGL is provided. They could easily change it to allow parallel rendering as long it is to independent contexts.
IMO, WebGL's implementation has some glaring wrinkles that REGL-like libraries can't smooth away, but at least REGL does a decent job of tackling the state problems you're discussing, while offering a more flexible approach (I think?) than the out-of-the-box WebGPU API's render pass command encoder.
Currently, both Dawn and wgpu-native use SPIRV-Cross for translation of shaders. The plan is for both is to migrate to in-house translation. In case of wgpu, that would be Naga [2]. Sometime in the future, you could be able to include it with only WGSL -> AIR (Apple's shader IR) code path compiled in, without anything else. Could be good enough for the code size? :)
[1] https://github.com/gfx-rs/gfx/issues/3117
[2] https://github.com/gfx-rs/nagaOf course in a "big" application like a 3D modeller or many games, 4..5 MB added to the exe size isn't critical, but for smaller applications it seems a bit excessive TBH.
And if there's already an offline shader compilation step in a game-engine's asset pipeline anyway, why not do the whole backend-specific shader preprocessing there as well.
Not a show-stopper of any kind of course ;)
For example, to provide MSL, there needs to be assumptions about exactly which MSL version is supported, all possible values of specialization constants if the MSL version is less than 1.2, all the details of which pipeline layouts will be used at runtime, etc. and all of these also have to match the internal logic used in Dawn or wgpu.
There's some more discussion about this in gfx and wgpu, e.g. https://github.com/gfx-rs/gfx/issues/3117#issuecomment-57045...
Fun challenge for HN: rewrite Xpra in Rust, it is currently implemented in AOT-compiled Python (Cython)
On the OS side, Google the capability-based OS Fuchsia. Someone in Google understands that user's consent over their computation resource (file/directory, network) is more important than ever.
And then there's WASI where it will enable OS to directly host WASM while allowing controllable gates over computation resources. WASI might be an important endeavor in the future and I think WebGPU design should have WASI in mind.
Those may have conflicts of space and market in the future, but all are moving into the same interest, the balance of user's consent over resources, security, and performance. It seems these standards are in good hands.
What I am missing is not a Web replacing operating systems, but better operating systems!
> What I am missing is not a Web replacing operating systems, but better operating systems!
But, that I cannot argue.
Wow. Has Vulkan failed as a standard then? I'm interested in this area but came away from the article feeling extremely confused about what the future of portable graphics programming looks like.
I know despite the hopes for WebGPU there's NWIH I will invest time learning it while everything is so up in the air.
OpenGL is great despite its warts, I've had a lot of fun programming with it over all the years.
Yet, the numbers are so tiny that Google has yet to bother to list them on Android Dashboard,
https://developer.android.com/about/dashboards
Last update was on May 1, 2020.
OpenGL was a nice API up until early 2.x versions, after that the move away from the fixed-function-pipeline would have needed a clear cut instead of the gradual stacking of new features, and since then two or three other of such "clear cuts" would also have helped, similar to how each new D3D version was incompatible with the previous version (but still supported for a long time).
Vulkan had a problem right from the start that it had to wrap an explicit low-level API over very different GPU architectures. And without the "wiggle room" of more abstract APIs this ended up in a complex API and high number of vendor-specific extensions in a very short time. As a result Vulkan was already bigger and more complex right from the start than OpenGL was after two decades.
Then you can move to low-level ones, if you really want to spend a few weeks on it! But if it is a hobby, I suggest you stay with a high-level one.
The medium term future will certainly be competing abstraction layers over varying subsets of D3D, Metal, Vulkan, OpenGL and OpenGL ES. Libraries like bgfx and game engines lead the way. Direct programming against low level APIs is too complex for mere mortals who want to create an actual application without an army of devs just for porting their graphics rendering to different devices (e.g. Vulkan allows for tons of subtle and hard to handle variations in device behaviour and these happen in practice).
"MS: Apple is not comfortable working under Khronos IP framework, because of dispute between Apple Legal & Khronos which is private. Can’t talk about the substance of this dispute. Can’t make any statement for Apple to agree to Khronos IP framework. So we’re discussing, what if we don’t fork? We can’t say whether we’re (Apple) happy with that. NT: nobody is forced to come into Khronos’ IP framework."
https://docs.google.com/document/d/1F6ns6I3zs-2JL_dT9hOkX_25...
1. It's so low level that generating HLSL and MSL from it is more painful than it could be. For example, it represents branching in the form of a Control Flow Graph (which is typical for an IR). This is lower level than either a source language people would use (e.g. GLSL), or the destination backend language we need to produce (e.g. HLSL or MSL). This is unnecessary complexity for translation.
2. It has a lot of instructions, covering wide range of hardware (somewhat similar to Vulkan). In contrast, for WebGPU it would make sense to have fewer instructions for the ease of securing it and translating to other representations.
3. Friction in the features we need, vs features Khronos needs.
There is also a situation where there is no single well specified and tested textual shading language. HLSL doesn't have a spec. MSL has documentation, but not enough for a spec, and it's not portable. GLSL kinda has a few specs, but realistically it's just specified by the implementation of glslValidator.
There’s a lot of opinions from people outside the working group for WGSL as to why it exists.
I think most of the PR damage right now comes from those people not having enough context and thus framing it in a negative light.
A blog post with more context and information would probably help imho
While moving from OpenGL to Metal was a significant technical upgrade for them, moving all their ecosystem from Metal to Vulkan is just a lot of work for very little benefit.
But yeah, sure, maybe they are just sticking with Metal to mess around with people.
Naturally for those of us around since the ARB days it hardly matters, but for teaching beginners into 3D world, or nowadays 2D was well, those bunch of useful libraries still lack the tooling experience of proprietary APIs.
And the OEM SDKs are hardly better, because they also provide better tooling for the proprietary APIs.
So in the end it all turns out into a rite of passage for everyone, getting to know which set of useful libraries, useful GPU debugging tools are to be used.
Hence why I just advise most beginners to start with middleware and only afterwards dive into the low level details.
Hopefully WebGPU can also help there.
Switch has Vulkan, but it has its own NVN, which is what middleware engines and most Switch titles actually take advantage of.
Given that Unity has shared numbers that they are responsible for 50% of the Switch titles, and there is also other middleware, there aren't many titles left.
Vulkan is supported on macOS through MoltenVK, provided by Khronos.
Whoever develops it is not really important for managers deciding on technologies to use.
But from the early days it was clear that MS and Apple will bet on their own proprietary APIs so the current situation is not news.
Other than MacOS/iOS Vulkan's future looks just fine.
Windows UWP has failed so incredibly hard that the Windows Store has begun allowing win32 app distribution, so what UWP supports is irrelevant. And Microsoft's game division has even given up on the Windows Store and releases their games on Steam now as well. So UWP is doubly irrelevant currently.
Intel's Skylake & newer support Vulkan 1.1 (which are 4 years old now). Not supporting Haswell/Broadwell is annoying as those do support D3D12, but that's the only API gap in Intel's lineup, and that's obviously something that's on a clock to stop mattering at some point. After all, Intel's iGPU primarily matters on laptops, and laptops tend to have a shorter lifespan than desktops as things other than the CPU show their age a lot more quickly.
The 50% on Android is also a thing that'll be solved with time. If Khronos doesn't do a new OpenGL ES, then eventually the driver priority on mobile will shift over to Vulkan as that's what benchmarks will begin prioritizing, and that's what sells hardware. Android's latency to supporting something new is incredibly long, but it does also keep moving forwards fairly reliably.
So MacOS/iOS is currently the only real question mark on Vulkan's future. But then again, Apple seems to only want Metal on their platform, which doesn't work anywhere else, so no "standard" will matter. You'll be forced onto a compatibility layer of some kind to work on Apple - be it MoltenVK, bgfx/sokol-gfx, or WebGPU. The article dresses up WebGPU as being superior because it's backed by a standard, but that's nonsense. The quality of the implementation is the only thing that matters, and bgfx/sokol-gfx already have quite the head-start there. There's no particular reason to think a couple of people on Firefox are going to be "strictly superior" to the couple of people on bgfx/sokol-gfx. Maybe WebGPU will end up better, in which case great! But it's the same basic thing as what already exists today. It's very firmly in the "compatibility layer" camp here, despite the article trying desperately to dress it up as something else. There's no driver support for it, there's no influence on hardware road-maps, etc...
So right now if you could only target a single driver API then Vulkan would cover more platforms than any other driver-native standard. Which is no small feat.
Also as information the WIn32 sandbox model also only allows DirectX, and Microsoft way forward is to support OpenGL on top of DirectX.
https://devblogs.microsoft.com/directx/in-the-works-opencl-a...
Expect Vulkan to get a similar treatment, the OpenGL 1.1 ICD driver model won't exist forever.
Vulkan on Android is still so meaningless that the dashboard, updated this month, still doesn't show Vulkan support.
https://developer.android.com/about/dashboards
And then there are the game consoles.
However, that's just a tiny slice of the reasons driving Unity's runaway success train. After all, if this were true, everyone would just be using ThreeJS. And don't get me wrong - ThreeJS has a massive and well-deserved user base, but few see it as a serious platform.
Unity is crushing it because they provide an almost VB6-like canvas to paint on; because they have the most outrageously comprehensive asset-store ecosystem I've seen for any platform period; and because they frequently support the cool new toys like ARKit the day that they are announced.
Unity is hands-down my favourite way to introduce day-one noobs to programming. I can take someone who has never programmed before and lead them through creating a VR experience where they can fight a giant spider with a burning sword in about an hour.
The idea to payoff pathway Unity offers someone who is deciding whether to pursue programming in real time is crazy.
And let's be honest, if you sit beginners in front of Unity they don't learn programming, instead they learn "Unity problem solving", e.g. "Unity trivia" which is hardly applicable to other contexts.
In my opinion, Unity is the Photoshop for game creation, you work on a very high level, but it's also very convenient (if you actually follow the rules and workflows).
But there are quite a few commercial games which use Unity only as a 'cross-platform wrapper', because their game client is more or less just a dumb input+rendering client, and the actual gameplay stuff all happens server-side.
It would be awfully nice if Unity could be split into a couple of standalone products (however that probably won't happen because it doesn't make much commercial sense):
- a low-level platform-abstraction library which contains all the driver-bug workarounds and behind-the-scene-fixes that have been accumulated over the years
- a 'bring-your-own-engine' asset pipeline and editor
- and finally, the actual Unity runtime engine, split into modules
And if Unity isn't in the picture, they sure as fuck aren't going to be hearing about WebGPU for the first 3-5 years of their journey.
Photoshop for game creation is a little bit loaded. I'll take it in good faith but point aggressively to how wrong you are because it's possible you just don't realize how much cutting edge engineering is being deployed.
For example, there's currently a major push towards moving everyone over to a job scheduled, burst-compiled data-driven architecture so that you can have tens of thousands of actors on screen at once. I stand by what I said about a VB6-like UI experience, but nobody is building anything real without learning a ton of C#, Quaternion math and shader language.
I agree with you, this is not the way to bring people up to speed with graphics programming.
The under-the-hood technology in Unity is definitely bleeding edge, but the user-facing workflows aren't anymore, they simply cannot "revolutionize" their workflows again as they did a decade ago, because that would alienate their own user base. Being the "industry standard" also has its downsides.
Unity, Unreal, Xenko/Stride, CryEngine, Unigine
It definitely got me excited for this new piece of technology.
Use XXX API and deal with bugs, incompatibilities, etc. etc.
What makes him think that this new API will be free of any of things he mentions above? As far as I can see this whole high performance graphics area has always been a wasps nest of various vendors each trying to pull the blanket to their side. I doubt adding "Web" to it will make life any easier.
So until that happens it is still: Use XXX API and deal with bugs, incompatibilities, etc. etc. We are back to square one.
I would really love it if we have some decent multiplatform high performance graphics API (with single shader language). I would also love said API to not require one possess PhD. However looking back the last 20 years does not inspire much optimism.
Wish you luck anyways
That is why Microsoft, Sony, NVIDIA, Apple, Xilinx, etc. create their own platforms and APIs.
Complete nonsense. All the hardware vendors except Apple support Vulkan and contributed towards it.
NVIDIA hasn't created their own graphics API since... ever, actually. They have their own APIs, of course (cuda being an obvious one, but there's also NVAPI), but they don't do graphics. Because hardware vendors have no interest or motivation in making more drivers than they need to, because drivers are hard & expensive. So much so that driver quality is a better lock-in for them.
Consoles use exclusives to drive lock-in, not APIs. Consoles have their own APIs, but historically that's always been a performance thing. They want to give game devs the rawest access they can, to make the best looking games they can. Maybe low-level APIs like Vulkan will end up changing that, maybe it won't, but it's not a "lock-in" thing. OS's use APIs to do lock-in, but they don't make hardware (Apple being the exception here, of course).
Microsoft not only does not support Vulkan, ICD drivers aren't allowed in Win32 and UWP sandbox models.
NVidia designs their hardware in collaboration with Microsoft, giving first class support to DirectX, and only afterwards they port the features as extensions to Vulkan/OpenGL.
Latest two examples, Ray Tracing and MeshShaders.
A web page does not need direct or even indirect access to your GPU, and it does not need to run a Turing-complete language.