Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can Vulkan do specifically that OpenGL 4.6+ cannot?

Tags:

opengl

vulkan

I'm looking into whether it's better for me to stay with OpenGL or consider a Vulkan migration for intensive bottlenecked rendering.

However I don't want to make the jump without being informed about it. I was looking up what benefits Vulkan offers me, but with a lot of googling I wasn't able to come across exactly what gives performance boosts. People will throw around terms like "OpenGL is slow, Vulkan is way faster!" or "Low power consumption!" and say nothing more on the subject.

Because of this, it makes it difficult for me to evaluate whether or not the problems I face are something Vulkan can help me with, or if my problems are due to volume and computation (and Vulkan would in such a case not help me much).

I'm assuming Vulkan does not magically make things in the pipeline faster (as in shading in triangles is going to be approximately the same between OpenGL and Vulkan for the same buffers and uniforms and shader). I'm assuming all the things with OpenGL that cause grief (ex: framebuffer and shader program changes) are going to be equally as painful in either API.

There are a few things off the top of my head that I think Vulkan offers based on reading through countless things online (and I'm guessing this certainly is not all the advantages, or whether these are even true):

  • Texture rendering without [much? any?] binding (or rather a better version of 'bindless textures'), which I've noticed when I switched to bindless textures I gained a significant performance boost, but this might not even be worth mentioning as a point if bindless textures effectively does this and therefore am not sure if Vulkan adds anything here

  • Reduced CPU/GPU communication by composing some kind of command list that you can execute on the GPU without needing to send much data

  • Being able to interface in a multithreaded way that OpenGL can't somehow

However I don't know exactly what cases people run into in the real world that demand these, and how OpenGL limits these. All the examples so far online say "you can run faster!" but I haven't seen how people have been using it to run faster.

Where can I find information that answers this question? Or do you know some tangible examples that would answer this for me? Maybe a better question would be where are the typical pain points that people have with OpenGL (or D3D) that caused Vulkan to become a thing in the first place?

An example of answer that would not be satisfying would be a response like

You can multithread and submit things to Vulkan quicker.

but a response that would be more satisfying would be something like

In Vulkan you can multithread your submissions to the GPU. In OpenGL you can't do this because you rely on the implementation to do the appropriate locking and placing fences on your behalf which may end up creating a bottleneck. A quick example of this would be [short example here of a case where OpenGL doesn't cut it for situation X] and in Vulkan it is solved by [action Y].

The last paragraph above may not be accurate whatsoever, but I was trying to give an example of what I'd be looking for without trying to write something egregiously wrong.

like image 429
Water Avatar asked Jun 26 '19 07:06

Water


People also ask

How is Vulkan better than OpenGL?

Vulkan is intended to offer higher performance and more efficient CPU and GPU usage compared to older OpenGL and Direct3D 11 APIs. It provides a considerably lower-level API for the application than the older APIs, making Vulkan comparable to Apple's Metal API and Microsoft's Direct3D 12.

Can OpenGL be as fast as Vulkan?

Vulkan is designed specifically for speed. The Vulkan renderer is often 2 times faster than OpenGL, and performance will improve in the future. OpenGL does not provide direct access to GPU memory, making it difficult to manage memory utilization.

Is Vulkan better than OpenGL for FPS?

Our experimental results show that 1) Vulkan can save up to 24% of energy by leveraging multi-threading and parallel execution on LITTLE cores for heavy workloads; and 2) Vulkan can render at a much higher frame rate when OpenGL ES has reached its full capability.

Which is better for gaming Vulkan or OpenGL?

Vulkan offers greater performance compared to its OpenGL brothers and greater control of the hardware allowing for a boost in graphics quality do to better optimizations. But how does this translate into the real world?


2 Answers

Vulkan really has four main advantages in terms of run-time behavior:

  • Lower CPU load
  • Predictable CPU load
  • Better memory interfaces
  • Predictable memory load

Specifically lower GPU load isn't one of the advantages; the same content using the same GPU features will have very similar GPU performance with both of the APIs.

In my opinion it also has many advantages in terms of developer usability - the programmer's model is a lot cleaner than OpenGL, but there is a steeper learning curve to get to the "something working correctly" stage.

Let's look at each of the advantages in more detail:

Lower CPU load

The lower CPU load in Vulkan comes from multiple areas, but the main ones are:

  • The API encourages up-front construction of descriptors, so you're not rebuilding state on a draw-by-draw basis.
  • The API is asynchronous and can therefore move some responsibilities, such as tracking resource dependencies, to the application. A naive application implementation here will be just as slow as OpenGL, but the application has more scope to apply high level algorithmic optimizations because it can know how resources are used and how they relate to the scene structure.
  • The API moves error checking out to layer drivers, so the release drivers are as lean as possible.
  • The API encourages multithreading, which is always a great win (especially on mobile where e.g. four threads running slowly will consume a lot less energy than one thread running fast).

Predictable CPU load

OpenGL drivers do various kinds of "magic", either for performance (specializing shaders based on state only known late at draw time), or to maintain the synchronous rendering illusion (creating resource ghosts on the fly to avoid stalling the pipeline when the application modifies a resource which is still referenced by a pending command).

The Vulkan design philosophy is "no magic". You get what you ask for, when you ask for it. Hopefully this means no random slowdowns because the driver is doing something you didn't expect in the background. The downside is that the application takes on the responsibility for doing the right thing ;)

Better memory interfaces

Many parts of the OpenGL design are based on distinct CPU and GPU memory pools which require a programming model which gives the driver enough information to keep them in sync. Most modern hardware can do better with hardware-backed coherency protocols, so Vulkan enables a model where you can just map a buffer once, and then modify it adhoc and guarantee that the "other process" will see the changes. No more "map" / "unmap" / "invalidate" overhead (provided the platform supports coherent buffers, of course, it's still not universal).

Secondly Vulkan separates the concept of the memory allocation and how that memory is used (the memory view). This allows the same memory to be recycled for different things in the frame pipeline, reducing the amount of intermediate storage you need allocated.

Predictable memory load

Related to the "no magic" comment for CPU performance, Vulkan won't generate random resources (e.g. ghosted textures) on the fly to hide application problems. No more random fluctuations in resource memory footprint, but again the application has to take on the responsibility to do the right thing.

like image 94
solidpixel Avatar answered Oct 08 '22 01:10

solidpixel


This is at risk of being opinion based. I suppose I will just reiterate the Vulkan advantages that are written on the box, and hopefully uncontested.

  • You can disable validation in Vulkan. It obviously uses less CPU (or battery\power\noise) that way. In some cases this can be significant.
  • OpenGL does have poorly defined multi-threading. Vulkan has well defined multi-threading in the specification. Meaning you do not immediately lose your mind trying to code with multiple threads, as well as better performance if otherwise the single thread would be a bottleneck on CPU.
  • Vulkan is more explicit; it does not (or tries to not) expose big magic black boxes. That means e.g. you can do something about micro-stutter and hitching, and other micro-optimizations.
  • Vulkan has cleaner interface to windowing systems. No more odd contexts and default framebuffers. Vulkan does not even require window to draw (or it can achieve it without weird hacks).
  • Vulkan is cleaner and more conventional API. For me that means it is easier to learn (despite the other things) and more satisfying to use.
  • Vulkan takes binary intermediate code shaders. While OpenGL used not to. That should mean faster compilation of such code.
  • Vulkan has mobile GPUs as first class citizen. No more ES.
  • Vulkan have open source, and conventional (GitHub) public tracker(s). Meaning you can improve the ecosystem without going through hoops. E.g. you can improve\implement a validation check for error that often trips you. Or you can improve the specification so it does make sense for people that are not insiders.
like image 22
krOoze Avatar answered Oct 08 '22 03:10

krOoze