New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal for WebGPU as a new Standard Cross-Platform Graphics API (OpenGL replacement) #295
Comments
|
Nah. |
|
I've thought a lot about this problem, and I've come to the conclusion that the modern APIs (Metal, Direct3D 12, Vulkan) leave no room for middleware. Any serious application either wants to or needs to have full control over resource allocation, shader binding models, barriers, render graphs, etc. If an app wants to use WebGPU as a cross-API modern graphics platform, there's Dawn and wgpu, but it won't solve the middleware case. |
|
My 2 cent: I think it's all about a class of small applications (and the people writing those applications) for which D3D12 and Vulkan is way too verbose (e.g. >1000 lines of code to get a triangle on screen), and where "general middleware" like Unity or Unreal is simply overkill. Such small applications are more typical for the web platform, but also make sense on mobile and desktop because they could start instantly without a long installation phase. For example take these emulators: https://floooh.github.io/tiny8bit/ These are written in C, and compiled to WASM, iOS, Android, Windows, macOS and Linux from the same code, and somewhere between 45 KBytes and 120 KBytes big. On the web those render through WebGL (on native platforms via D3D11, Metal, GL), through very minimal platform abstraction APIs (https://github.com/floooh/sokol). WebGPU would make sense here because the 3D backend code would actually be smaller and much cleaner than the GL backend, so less code to maintain for me. With a Vulkan or D3D12 backend, the opposite would be true, a lot of complex code to maintain for absolutely zero benefit (for such simple applications). Or think about small, specialized AR apps on mobile phones. In my opinion, 3D-APIs like WebGPU and Metal are the true successors to GL and D3D11 as "programmer-friendly" APIs, not Vulkan and D3D12. E.g. Metal allows to write 3D application from scratch without a "sanity layer" inbetween and without employing a whole engineering team. This idea has been lost in Vulkan and D3D12, but preserved in WebGPU. IMHO WebGPU is so far the only really serious approach to create a simple API around the modern 3D APIs, so it's in the best position to become the "standard" successor to GL and D3D11 which targets the same audience as D3D11 and Metal (Vulkan and D3D12 is a completely different target audience IMHO). A portable C implementation for WebGPU implemented in a library (ideally statically linked) for (at least) Android, iOS, macOS, Windows and Linux, and via WASM for the web makes a whole lot of sense. The main problem is indeed shaders. We need SPIRV there, otherwise it's back to offline cross-compiling solution via SPIRV-Cross. It works, but it's a hack and adds layers of complexity to IDE integrations and build systems. Finally, the main problem with "3rd-party" wrapper APIs (like I and many others have written many of so far) is that nobody will ever agree on one, otherwise such an API would already have emerged. This leads to fragmentation and much duplicated work (everybody is basically writing the exact same D3D12 and Vulkan wrapper APIs in inhouse code bases, and if not "exact same", than at least large parts of it (all the pointless initialization code for instance). |
It'll be up to Mozilla Corporation to decide which language they will choose to implement WebGPU in, not you. Now please state that you will be fine if it'll be implemented in Rust so you won't contribute to disagreement you're trying to avoid. Thank you for your cooperation. |
As long as there is a C API, I really don't care much about the language the library is implemented in. PS, link: https://dawn.googlesource.com/dawn/ |
|
@floooh you want a little 32 kilobyte C library that is easy to use and talks to a driver directly? You'll get one. Not from the people who don't care how many bytes it will take or how fast it will call a backend GPU API, tho. |
|
And generally, you people should beg for lower level GPU access (lower than Vulkan/D3D/Metal), because we already had a multi-billion dollar experiment with the best, most paid driver engineers in the world if we can pull off a simplified GPU API, the best what we got is D3D11 which pegs CPU and can be easily beaten by any modern API, the worst what we got is OpenGL clown town. Quit asking for APIs which are historically proven to be insufficient to program embarrassingly parallel hardware. |
I agree, but let's not derail the thread (3D APIs should disappear completely into the compiler, but without GPU vendors opening up their ISAs this is wishful thinking). Your information about D3D11 is objectively wrong though (look at games which have both a D3D11 and Vk backend, it's hard to find one where the Vk backend performs better). |
You want me to assume you have 'objectively right' data that shows Vulkan performance is always the same as with D3D11? You could link that 'objectively right' data if you had one, but since you don't let me link mine:
Source: https://www.battlefield.com/news/mantle-renderer-now-available-in-battlefield-4 (copy) Unless you think Mantle is different than Vulkan and performs better than Vulkan, this data shows performance difference I and people at DICE saw compared to D3D11. |
It's utopia. |
|
@floooh if you want a cross-platform graphics platform layer or renderer, there are quite a few open-source ones of those, with varying degrees of power up and down the stack. WebGPU is one way to design a platform layer, but there are lots and lots of others, and certainly not all of them will have the same constraints that WebGPU does: WebGPU makes it difficult to write an optimized render graph because of all the barrier tracking it does automatically, and sub-buffer uploads are also very in the air. Any professional renderer is going to want those things. The tradeoffs were made on the side of safety. Mozilla has tried to position wgpu as a nice open-source library if you want a graphics platform layer for your application: https://gfx-rs.github.io/2019/03/06/wgpu.html . I think it's a fine and sensible choice, but it's certainly not the only choice out there. Ultimately, you are going to be building a renderer on top of your platform layer to begin with, because you don't want to be emitting raw draw calls from your object graph, you want to sort transparent objects, you want to batch buffer uploads to the start of the frame, and so on. Also, D3D11 tends to perform better on NVIDIA because NVIDIA's driver applies plenty of game-specific heuristics and shader hacks, and for a multitude of complex reasons, those hacks have not their way to the Vulkan drivers. For other companies that did not invest millions of dollars in a driver moat, D3D12/Vulkan already outperforms D3D11. |
Yes agreed, but such an API doesn't have to be everything to everybody, it just has to provide a better cross-platform alternative to OpenGL with a drastically lower "lines of code to triangle on screen" count than Vk/D3D12. The various open source wrapper APIs (mine including) lack the extensive specification work, conformance- and compatibility-tests that WebGPU (hopefully) has. For people who need more explicit access at the cost of having to maintain a lot more code and handling all the GPU-architecture-specific peculiarities themselves, there's still Vk and D3D12. As I said above, Vk and D3D12 are not a replacement for D3D11 or OpenGL though. Just continuing to use OpenGL and D3D11 isn't an option either, since GPU vendor debugging- and profiling-tools are already starting to drop support for those APIs. The real elephant in the room is the shader question though. Yet another "high level shader language" isn't helpful.
True, but Metal 1 shows that one can still improve the OpenGL / D3D11 programming model drastically without explicit resource barriers.
Agreed, but more direct buffer / image content access could be implemented in an API extension that's only available in the native API version with relaxed security requirements. |
|
@missmah thank you for writing down this proposal! There is a strong support within this W3C community group (CG) for exposing the WebGPU API to native applications (in addition to the Web) with an aspiration for it to be come the new cross-platform API of choice for many developers, just like you requested. However, designing a native API is not in the scope of work for this CG. It's possible to form another group, possibly at another standards body (e.g. Khronos), that would research the prospect of WebGPU on native, suggest extensions, etc, but this hasn't happened yet. The main focus of W3C CG is still the Web.
Please expand on the reasons you have in mind. AFAIK, actual shader translation (from SPIRV to anything) is a drop in the water among the total time spent in pipeline creation.
I find this requirement hard to achieve. WebGPU is designed to be a safe and portable API. In order to achieve this, we need a full control of the low-level primitives. Whenever there is a breach (i.e.
The main advantage of WebGPU versus just some libraries out there could be the existence of a spec of this API that the implementations follow and conform with a rich test suite. I said "could be", because native applications don't use Web API directly, they'd need C headers specified, and this, again, is not a goal of this CG...
Swarming the API with extensions would harm portability of applications. I would prefer a cautious approach here by minimizing the number of extensions we'll have exposed.
I'm fairly sure this is an unrealistic goal, and I'm sharing the @floooh position. WebGPU is designed for the Web, which puts certain constraints and involves trade-offs on the API that aren't always best for running on native. For example, we can't return errors by Device methods, because we assume the device may live on a separate GPU process. WebGPU is good to use for small-to-medium size applications that aren't too CPU limited in their rendering code. Larger engines and applications could use WebGPU as a Web target, but it's not reasonable to expect them to use it on native targets. Established engines already support low-level APIs with less overhead (than going through WebGPU), and they can resort to help of Vulkan Portability for wider reach. @procedural |
|
Thanks @kvark that's basically hits 100% of what I was going to reply. Unfortunately this group's focus is on making a Web API, and I don't think it will be possible to expand it to cover native because at least two of the group's participants have their own native API. However it would be amazing to have the main C APIs for wgpu and Dawn match so that they are interoperable. As WebGPU implementation they would benefit from having extensive testing, tuning and working around driver bugs. The shared C API would be a de-facto standard API. |
|
@kvark, @Kangz thanks for the kind and thoughtful replies! I think I partially failed to appreciate the limitation of this CG, and also to emphasize the correct wording of the intent of my proposal. Sorry about that! I mostly agree with both of you, that ultimately what we are talking about here is another working group/project, which would be more directly based upon https://github.com/gfx-rs/wgpu and That group's goal would be to, as you pointed out, ensure that those two implementations APIs continued to match and be inter-operable going forward in time. And to ensure that there was a rich test suite for the larger native API, etc. The proposal I made about being able to directly access underlying devices, get mappings from WebGPU Objects<-->Underlying Device Objects, etc. is obviously not an API that could be exposed on the Web. It appears this proposal belongs more in a new working group than it does in this working group. However, my hope with this proposal was also to get consensus around the idea of avoiding building a Web API which would unnecessarily complicate the interplay between Native and WebGPU. If the Native API will support this paradigm, there may be changes to the way devices are enumerated and created that should ripple over into the WebGPU API, in order to keep the two from diverging too much. My point about SPIR-V was in the same vein. Having the two APIs diverge with respect to how they handle shaders is a big compatibility issue. (I believe that requiring WHLSL for the Web API would also be a bad choice for performance, but I'll address that separately in a future comment.) It sounds like a next step would be proposing a parallel CG for Native be created. But in a sense, I still don't think these CG should be completely independent of each other, or we will risk conflicting decisions being made which do unnecessarily complicate the interplay between the "Native" API vs. the "Web" API. Thoughts on this? Thanks again for the constructive feedback and discussion! |
|
whats the difference between webgpu and webgl-compute shaders from the kronos spec? |
|
Separately, I'd like to briefly address the viability and importance of of having minimal divergence between the Native And Web APIs. Assertion: End-user code shouldn't need to be littered with As an example, our current There are some places where optional more optimized codepaths are supported based on extensions and flags (things like My argument is that this is a real portability strength of the current implementations of I'd go so far as to say that we most likely would not have ported our renderer to the Finally, with respect to my proposal about the Native API being able to access the underlying device, I think |
|
@kvark
I haven't seen the performance numbers for Do you have numbers which show that the |
|
Even if WebGPU supported SPIR-V at the API level, it's not going to be "native". Some platforms will require the shader to be translated (Metal and DX12). For Vulkan, the shader will need to be validated in some form. While it looks like there will be a special subset of SPIR-V for the Web, the implementation won't be able to simply pass it on to the driver. So offline compilation will still require some online compilation. This is the same with WHLSL. It will need to be compiled on the client. The difference is that WHLSL acts both as a compile target and a human-writable language. |
|
@grorg I'm pretty unconvinced that Even if performance were a non-issue, further fragmenting the shading language landscape seems (to myself and many game developers I know) like a thing to be avoided. Moreover, |
|
@missmah WHSL compilation won't need to go through SPIR-V validation because the language is restricted to only allow Web-safe features. So the comparison is between a WHSL compiler and a SPIR-V validator. But note also that platforms other than Vulkan won't ingest SPIR-V directly, so it will have to be validated, translated then recompiled. We'll have to do measurements to know what the costs are. Anyway, I'm not really arguing either way - just pointing out that there isn't such a thing as "native" SPIR-V in this API. FWIW, on the general topic, it seems like you're mostly asking for what Vulkan portability is supposed to provide. |
This is misleading, but let's just link at the previous flamewar: #42 #43 #44
Vulkan portability is really hard to use, and you have to adapt to different types of hardware in addition to different backing APIs. It also won't target the Web so I think WebGPU in native still has value. |
|
@grorg I agree with @Kangz about A few ways
|
|
Perhaps feedback on the shortcomings of the Vulkan Portability effort should be directed at that group. |
So Vulkan portability isn't portable? (And hard to use!)
Maybe I misunderstand the request then. Making a standard programming API that can be used in native apps and the Web? And the developer would be ok with all the performance hits and programming restrictions (e.g. no bindless) that the Web requires, even if they are developing for native? If Dawn and wgpu are already going to share a C API, then is that enough? The thing I'd like to avoid is WebGPU having to be constrained by native requirements. |
What I meant is that the WHSL compiler will produce "safe" SPIR-V, in the same way it will produce "safe" MSL and HLSL. |
Indeed, see @kvark's comment or mine that say that this isn't the focus of this group, and @missmah's follow up:
What's interesting for this group is that usage of the native version of WebGPU will help with adoption on the Web. Apps using WebGPU native implementations for the ease-of-use and portability will be able to be WASMed for the Web and take advantage of WebGPU directly. |
|
The idea was to add the ability to get the native device on Native (a small slice of the API that would be Native-Only), so that you could fall-back to native for a subset of codepaths where the performance hit was important. But yes, you'd write your whole renderer in
Almost enough, again, my proposal was basically 3 things, up at the very top of my post, that might differ from where the standard is currently heading.
I'm attempting to propose that we try to minimize the divergence between |
This is a good point, but I think if you replace "native version of WebGPU" with "Dawn" or "wgpu" you get the same result. To consider a truly native API we'd have to re-open the group's charter. At the moment we're Web first: JavaScript, and possibly Web Assembly. |
100% This. We wouldn't have a I really believe in graphics on the web as a major platform of the future, and I think that having an easy pathway for Native renderers to achieve high performance on the Web will be a huge win for the Web.
Our long-term goal is to make our I caveat what I just said above with the fair point that a new CG should be created for the Native use-case. But, I continue to believe that these two CG should not be independent of each other, and should collaborate on how to have a minimally divergent set of APIs which supports both use-cases well. Again, I know that the largest companies will always throw engineers at the problem; but, |
|
Is webgpu the same as OpenGL 3.1 spec ??https://www.khronos.org/registry/OpenGL/specs/es/3.1/es_spec_3.1.pdf |
|
@jacobbogers your question is off-topic for the current discussion; please post elsewhere if you have further questions. WebGPU is a new API, not at all based on OpenGL. It is loosely based on Vulkan, Metal, and D3D12. |
|
Ok Thanks @kainino0x, I know Intel is working on webgl2 compute shaders |
|
PS: where can i get my hands dirty on this webgpu api? |
|
See https://webgpu.io. |
|
I believe this is a good breakpoint towards a new web, one that is ready for 3d and complex graphics processing. Babylon JS is already on the move (it would be great if Threejs does it too), also, all browser vendors are already working on adopting WebGPU (Chrome, Firefox, Safari, Edge). So, this is indeed a serious move. And it is a good one. Check this: |
|
If you're interested in using in WebGPU in native (ideally to prepare a WASM port ^^) you should take a look at https://github.com/webgpu-native/webgpu-headers where we are making a header that will allow targeting both wgpu-native and Dawn's implementations of WebGPU. I'll close this thread as this group isn't for native APIs. (feel free to open issues on webgpu-headers). |
* Optimize device pool lookup Replace O(n^2) with stringication+Map. * More strictly canonicalize the device descriptor * items->holders * Move default limits to constants.ts, move some files from src/common to src/webgpu
From the perspective of writing cross-platform engines, it would be nice to have a new open-source "write once, run anywhere" type graphics API. WebGPU seems like it could hopefully replace OpenGL for that purpose, and be a much lower-level, more performant baseline API.
A few important things would be vital to make this truly worthwhile:
SPIR-VNatively inWebGPU(for performance reasons)WHLSL, but the added complexity of doing so probably isn't worth having it be part of the API itselfWebGPUextensions as a first class citizen to enable the API to grow to support new use-cases not exposed by the initial spec (mesh shaders,rtx, etc.)Dawn/wgpuWebGPUdevice gets created withWebGPUAPI device is aVulkandevice behind the scenes, enable access to thatVkDevicedirectlyWebGPUobjects andVulkanobjectsWhat would this enable that's interesting?
Why isn't this just a job for
bgfxor other higher-level rendering APIs?WebGPUisn't implemented onbgfxor other such APIs!WebGPU's goal is exactly this).Unity, Unreal, and other large engines already have this abstraction layer written, and already support all the other APIs, won't simply adding a WebGPU back-end be the ideal for them?
Simple Middleware Use-case Example
BVHheuristics, etc. I want this library to work onWindows,Linux,OSX,Android,iOS, The Web, etc. This library should be used by game/graphics engines which want a quick path to optimized ray tracing.WebCLwere actually supported, I might be able to useOpenCL+WebCL.WebCLisn't supported, either...OpenGLCompute Shaders +WebGLCompute ShadersOpenGLis deprecated by Apple!WebGLCompute Shaders - Coming SoonBVHcode for every platform...OpenGL/WebGLMetalBVH shaders, or write ashader generatorsystem!Vulkan, how do I write an interop system to take their data and convert it toOpenGLand back?Again and again, at various scales within industry, this pattern plays out. So, not only does the web suffer; the majority of cross-platform graphics renderers continue to suffer. We have too many incompatible graphics APIs, none of which covers all of the important platforms, or offers suitable and broad enough inter-op with other APIs. As a result, everyone has to either re-invent a whole lot of very similar wheels, make large API complexity compromises, etc. The fact that some very large and successful companies have suffered this pain and built workarounds for it doesn't mean the situation is healthy. The sheer daunting complexity of working around a lot of these issues probably stops most would-be-cross-platform projects in their tracks, and severely limits others.
I think the industry could use a common denominator, fairly low-level, open-source/open-standard-extensible API. It seems like
WebGPUwill have to, by its very nature, be that common-denominator. It seems like with some attention to detail,WebGPUcould become something likeCommonGPU/StandardGPU/UniversalGPU.The text was updated successfully, but these errors were encountered: