6 ms·
I'm really rooting for WebGPU as the "cross-platform 3D-API for the rest of us" (where "rest of us" is everybody who isn't a highly specialized rendering engine
by flohofwoe 7y ago
I'm really rooting for WebGPU as the "cross-platform 3D-API for the rest of us" (where "rest of us" is everybody who isn't a highly specialized rendering engineer in an AAA-game engine team).
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).
- mouldysammich 7y ago> I'm really rooting for WebGPU as the "cross-platform 3D-API for the rest of us" (where "rest of us" is everybody who isn't a highly specialized rendering engineer in an AAA-game engine team). 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.
- blauditore 7y agoI don't think getting into OpenGL is actually that hard. There are wrapper libraries, e.g. for Java, and tons of tutorials. 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.
- jameshiew 7y agoAbsolutely this. I wish I had spent more time learning about the rendering pipeline before jumping into trying out so much as a "Hello Triangle" tutorial. 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.
- neutronicus 7y agoUnless you're in CUDA, then it's a "kernel." But in OpenCL it's still a "compute shader"? Oy vey
- blcArmadillo 7y agoI agree. I recently started exploring OpenGL and found it pretty approachable. If someone is looking for a resource to help learn OpenGL, I found https://learnopengl.com/ https://learnopengl.com/ extremely helpful.
- skocznymroczny 7y agoOpenGL isn't hard, but it's API is outdated and full of surprises. Error reporting is bad (glGetError), debug context works somewhat better (error callbacks), but I had errors that reproduce on debug context only. C API is very weakly typed, so it's easy to pass GL_RGBA to a function which expects GL_RGBA8. But the worst part of OpenGL is the state machine. OpenGL is the only graphical API still remaining that has the concept of state machine, and it causes a lot of trouble when rendering. You basically have to abstract the entire state machine on your side of code, or defensively back out all state changes that you do. Modern APIs are more stateless, and state object is passed along with the drawcall, more or less, without affecting any other drawcalls in the commandbuffer.
- speedgoose 7y agoYes, it's overly complex for beginners. 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-Raytracing-tutorial-Part-1 https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytrac... https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytracing-tutorial-Part-2 https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytrac...
- flohofwoe 7y agoMight I shamelessly plug my sokol_gfx.h library (assuming your language of choice is C or C++). These are WASM samples written in C or C++, a link to the source code is in each sample: https://floooh.github.io/sokol-html5/ 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.
- jfkebwjsbx 7y ago> where "rest of us" is everybody who isn't a highly specialized rendering engineer in an AAA-game engine team Then you should be looking at WebGL, not WebGPU!
- pjmlp 7y agoThose kind of advises would make sense if they were parallel APIs, however neither WebGL 3.0 nor OpenGL 5.0 will happen.
- jfkebwjsbx 7y agoThey say they are not making an AAA engine. They are looking for a simple way to get into graphics. They have no need for parallel, low-level APIs.
- gpm 7y ago> Please don't comment about the voting on comments. It never does any good, and it makes boring reading. https://news.ycombinator.com/newsguidelines.html 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.
- jfkebwjsbx 7y agoI edited it, but let me say I don't agree with your policy, because downvoting is reserved for high-score accounts. If it would be open to (almost) everyone, then it would be fine. 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.
- pjmlp 7y agoExcept going forward, those are going to be the only APIs available, regardless of one is doing AAA or not. It would be the same as using SVAlib or Allegro nowadays. They are still there, but not longer map to existing graphics hardware.
- kvark 7y agoShipping compiled shaders is a feature request that pops up from time to time in gfx-rs land [1]. So far, we have been skeptical about this. Something like a serializable pipeline cache would help, but not entirely solve the shipping binary size. Although, is it really important? "Hello Triangle" may be a few megs, but the code for shader translation is a constant addition to it, so extrapolating this 5.2Mb value is not useful. 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/naga
- flohofwoe 7y agoYeah it will be interesting to see whether a different set of libraries for the shader translation will cut down the size a bit. Of 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 ;)
- Jasper_ 7y agoAIR is not a documented or supported endpoint. MSL is the supported endpoint. You will hear from Apple's lawyers if toy reverse engineer AIR, as one of my colleagues knows from experience.
- grovesNL 7y agoIt might be really difficult to avoid runtime shader translation without some other solution (e.g. populating pipeline caches ahead of time). 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-570458385 https://github.com/gfx-rs/gfx/issues/3117#issuecomment-57045...
- greggman3 7y agoGiven that any most implementations of WebGPU will be open source it should be trivial for you to add a way to use pre-compiled native shaders to whatever implementation you choose to use.
- raphlinus 7y agos/trivial/possible/. But yes, this is a wishlist item for me (in piet-gpu) as well, partly because of the bloat issues and partly because I want to be able to use the most advanced features (subgroup operations) that the shader languages provide, and there's currently a pretty big gap there.
- tenaciousDaniel 7y agoI've been playing Dreams on PS4 a lot recently, and it's kind of like "game development for the rest of us". I'd love to see a Dreams-like web application that allows anyone to create and share small-scale interactive experiences. Seems like WebGPU is a step in that direction.
- meheleventyone 7y agoWe're actually building something along these lines, currently in pre-alpha: https://www.dotbigbang.com https://www.dotbigbang.com
- tenaciousDaniel 7y agoLove it! Looks very promising.
- sansnomme 7y agoAnother great usage option would be for GTK Broadway. Right now Broadway does not support any form of OpenGL so pretty much any CAD or design tool written in GTK would not work with Broadway. It is quite a disadvantage if you are running heavy workloads on a compute cluster and have to resort to VNC/Xpra which is much, much more slower than Broadway. This is especially if you are doing instrumentation or ML work and your charting tool uses OpenGL for performance. Fun challenge for HN: rewrite Xpra in Rust, it is currently implemented in AOT-compiled Python (Cython)