Live data from Hacker News

I learned Vulkan and wrote a small game engine with it

edw.is

41–50 of 268 posts

Re: I learned Vulkan and wrote a small game engine with it

#41

Earlier quoted context omitted.

A middle ground is webgpu. It is much less verbose than Vulkan and is guaranteed to run anywhere, including the browser. At the same time, it has access to "modern" features like compute shaders which would not be available in webgl. It also doesn't have much legacy cruft leading to multiple ways of doing the same thing, unlike opengl. The main advantage is that it's new, so there are many fewer tutorials available f…

I thought its browser support was pretty bad? https://caniuse.com/webgpu Firefox and Safari don't support it yet. And how would you even deploy it to Steam (edit: or rather, make a desktop or mobile game with it)? Can you wrap it in a webview? Doesn't seem mature...

There is a native API too, not just JS. You can link it into your game like any other library.

Re: I learned Vulkan and wrote a small game engine with it

#42

Earlier quoted context omitted.

That's just not true. https://wgpu.rs/ I'm literally writing native code running on linux with winit and wgpu right now.

Wait, is that the same as using WebGPU? It says outside of browsers it uses opengl and vulkan and directx.

Yea, wgpu is basically an adapting layer between the WebGPU API and opengl, vulkan, directx. So it's the same† API.

But WebGPU in the browser is also an adapting layer between those technologies, it's just the browser that does the adapting instead of the wgpu library. For Firefox, WebGPU is adapted to those underlying systems by wgpu: https://github.com/gpuweb/gpuweb/wiki/Implementation-Status

† There are some "native-only" extensions beyond the WebGPU spec that gpu provides, so it does go a little beyond WebGPU. But for the most part, it's very similar.

Re: I learned Vulkan and wrote a small game engine with it

#43
post #41

Earlier quoted context omitted.

I thought its browser support was pretty bad? https://caniuse.com/webgpu Firefox and Safari don't support it yet. And how would you even deploy it to Steam (edit: or rather, make a desktop or mobile game with it)? Can you wrap it in a webview? Doesn't seem mature...

There is a native API too, not just JS. You can link it into your game like any other library.

I'm confused now. I thought by definition it's a browser API that allows them to make Vulkan/OpenGL/DirectX calls, like an abstraction layer. Am I wrong?

Edit: wgpu is a reimplementation of the WebGPU api for use with desktop apps outside of browsers. See sibling thread by another poster for an explanation: https://news.ycombinator.com/item?id=40598416

Re: I learned Vulkan and wrote a small game engine with it

#44

Earlier quoted context omitted.

Wait, is that the same as using WebGPU? It says outside of browsers it uses opengl and vulkan and directx.

Yea, wgpu is basically an adapting layer between the WebGPU API and opengl, vulkan, directx. So it's the same† API. But WebGPU in the browser is also an adapting layer between those technologies, it's just the browser that does the adapting instead of the wgpu library. For Firefox, WebGPU is adapted to those underlying systems by wgpu: https://github.com/gpuweb/gpuweb/wiki/Implementation-Status † There are some "nati…

Wait... so if webgpu (the API) is to allow browsers to use the underlying graphics libs... but desktop apps can access those directly... why would they want to go through the browser abstraction API instead? Better dev ex and ergonomics?

Re: I learned Vulkan and wrote a small game engine with it

#45

Earlier quoted context omitted.

Yea, wgpu is basically an adapting layer between the WebGPU API and opengl, vulkan, directx. So it's the same† API. But WebGPU in the browser is also an adapting layer between those technologies, it's just the browser that does the adapting instead of the wgpu library. For Firefox, WebGPU is adapted to those underlying systems by wgpu: https://github.com/gpuweb/gpuweb/wiki/Implementation-Status † There are some "nati…

Wait... so if webgpu (the API) is to allow browsers to use the underlying graphics libs... but desktop apps can access those directly... why would they want to go through the browser abstraction API instead? Better dev ex and ergonomics?

> why would they want to go through the browser abstraction API instead? Better dev ex and ergonomics?

That and portability. The ergonomics are always up for debate, but I find it a much more modern and nicer interface than OpenGL which feels...quite dated. How it compares to something like Vulkan or Metal is up for debate.

But for portability if I write my code using directx, then I can only run it on systems with directx. If I write it for vulkan, I can only target systems with vulkan. If I write for metal, I can only target systems with metal.

However, if I use wgpu and the WebGPU API, I can target any system that has directx or vulkan or metal or OpenGL. I can also target wasm and compile my application for the web.

So, I can really easily write code that will run natively on linux, on osx, on windows and the web and will use the graphics library native to that platform.

Re: I learned Vulkan and wrote a small game engine with it

#46
post #37

This might come off as a surprise to some people but getting good performance with Vulkan (compared to say OpenGL) isn't trivial because: the Vulkan driver is missing that ~20k loc of code that OpenGL driver does for you to set up the rendering pipelines, render targets etc. This is all code that already exists in the OpenGL driver and has been optimized for +20 years by the best people in the industry. So when you s…

the biggest part for me is the shader compiler. opengl has one built in, vulkan requires me to pull in yet another dependency

i've heard that vulkan allows bindless textures now, so the descriptor nonsense is a bit less awful that it used to be

vulkan is appealing, but there's a high initial cost that i don't want to pay

Re: I learned Vulkan and wrote a small game engine with it

#47

Earlier quoted context omitted.

Wait... so if webgpu (the API) is to allow browsers to use the underlying graphics libs... but desktop apps can access those directly... why would they want to go through the browser abstraction API instead? Better dev ex and ergonomics?

> why would they want to go through the browser abstraction API instead? Better dev ex and ergonomics? That and portability. The ergonomics are always up for debate, but I find it a much more modern and nicer interface than OpenGL which feels...quite dated. How it compares to something like Vulkan or Metal is up for debate. But for portability if I write my code using directx, then I can only run it on systems with d…

I see now. Thanks for explaining! That makes a lot of sense.

Re: I learned Vulkan and wrote a small game engine with it

#48
post #14

I think vulkan is great, but its only purpose is to take full advantage of advanced GPU features. It also leads to better performance when using advanced GPU features compared to OpenGL. Generally, I feel OpenGL is the recommended route if you don't really aim for advanced rendering techniques. There are plenty 2D /lowpoly/ps1-graphics games right now, and those don't need to use vulkan. Vulkan is an example of how t…

Another good option is Direct3D 11. It’s IMO even easier to use than OpenGL but still allows to implement pretty good visuals, see GTA 5 or Baldur’s Gate 3.

Re: I learned Vulkan and wrote a small game engine with it

#49
I've been trying to learn Vulkan on and off for years (I used to know OpenGL ES 2&3 pretty well).

One thing I found difficult is understanding how to use things in a real engine rather than a sample. A lot of samples will allocate exactly what they need or allocate hundreds of something so that they're unlikely to run out. When I was trying to learn DirectX, I found Microsoft's MiniEngine helpful because it wasn't overly complex but had things like a DescriptorAllocator that would manage allocating descriptors. Is there something similar for Vulkan?

Another thing I struggle with is knowing how to create good abstractions like materials, meshes, and how to decide in what order to render things. Are there any good engines or frameworks I should study in order to move beyond tutorials?

Re: I learned Vulkan and wrote a small game engine with it

#50
post #37

This might come off as a surprise to some people but getting good performance with Vulkan (compared to say OpenGL) isn't trivial because: the Vulkan driver is missing that ~20k loc of code that OpenGL driver does for you to set up the rendering pipelines, render targets etc. This is all code that already exists in the OpenGL driver and has been optimized for +20 years by the best people in the industry. So when you s…

I've heard the same thing about DirectX 12 vs DirectX 11. One book basically said that you will probably have worse performance in DirectX 12 vs DirectX 11 if you don't know what you're doing.
Post reply on HN