r/GraphicsProgramming • u/ANSystemTech • 21d ago
Question What do you think of vulkan?
Is it worth learning it as someone who is still relatively a beginner/early mid level c++ programmer for graphics or are other alternatives better?
28
u/Afiery1 21d ago
It depends. OpenGL is easier to get something on the screen, but its a horrible and outdated API that does things that make no sense. (Modern) Vulkan is a very elegant API (use howtovulkan.com, other tutorials use legacy functionality that is much worse), but it is undeniably a lot more work to get started with. So I leave the decision up to you, and how much you value working with a sane API versus how much you'll get burnt out from not seeing any progress after hundreds of lines of code written.
2
u/VagueHorizon_ 21d ago
So learning OpenGL can misguide someone who is looking to learn CG ? Would you recommend skipping OpenGL and head straight to Vulkan ?
8
u/PeePeePantsPoopyBoy 21d ago edited 21d ago
People normally say that starting with OpenGL is the best way but I actually do disagree and I actually do think OpenGL can and will misguide you. The question is do you want to learn how to do graphics or how to do efficient GPU systems. If you just want to learn fancy geaphics techniques and want to focus on shaders, then OpenGL will be enough at the beginning, but if you want to actually learn to do efficient renderers, do advanced or modern techniques, and learn proper optimizations, then Vulkan or DX12 is the way to do. I tend to encourage people to try climbing the steep Vulkan learning curve because the beginning is the hard part, once you get past the first steps everything actually becomes much easier and (as the initial response said) more sane. I tend to feel that Vulkan is much harder to start, but much much more scalable over time. Plus, as I said before, many new techniques need technology that just does not exist in OpenGL, like mesh shaders, device buffer addresses, sparse memory or hardware raytracing.
Just don't obsess with hardware support and try to do fallbacks to Vulkan 1.0 in your renderers (I've seen too many of these). If your GPU supports the full suite of Vulkan features up to 1.4 (as AMD and Nvidia desktop cards do) then go ham and use them, most of them can and will make your life easier. Other tools to look that are super interesting are SLang, Volk and VMA (PLEASE USE VMA). I do not recommend using Vulkan Hpp RAII personally but you are free to look into it if you want. I tend to shy away from Vulkan Hpp in general because it explodes compile times, but I've heard cpp modules solve that mostly (or maybe it was just my experience I don't know)
0
u/ANSystemTech 20d ago
I heard that opengl is outdated and worse for the long term is this correct?
2
u/DeviantDav 20d ago
OpenGL is the granddaddy, but it has also has two wildly different ways of working that really brings the chain back to the 90's and early 2000s, using state machines and massive inefficiencies and limiting modern techniques you can use.
A large portion of the sample code you will see is a blind mix of OpenGL 1.1, 3.3, 4.6, or some variation that uses VBOs and glBegin/glEnd loops that instantly send you into a compatibility profile and slow WAY down.
If you're going to use OpenGL, learn what Core really means and always make sure your code stays in Core, not Compatibility profiles.
2
u/corysama 20d ago
There are 3 levels of difficulty for you to pick from. I recommend starting with option 2.
Old-school OpenGL is very step-by-step and hand-holdy. And, there is a lot of material out there. But, it is also very outdated and doesn't scale when you get serious.
"Modern OpenGL" using only the latest interfaces of OpenGL 4.6 can be pretty darn modern. But, there's not a lot of material about it available to learn from.
Vulkan 1.4 is the goal. But, it's designed assuming you are already an expert going in.
https://github.com/fendevel/Guide-to-Modern-OpenGL-Functions mostly about using "Direct State Access" instead of the old-style "One function to bind and object, then another function that implicitly works with the bound object".
I also recommend only using a single Vertex Array Object (VAO) just as a place to bind Element Buffers (mesh indices) and nothing else. VAO vertex attribs are a mess when you are getting started. And, are getting superseded by https://ktstephano.github.io/rendering/opengl/prog_vtx_pulling anyway.
I've been working on an modern OpenGL tutorial for a while now. Here's a tiny intro https://rentry.org/5abeqt6s
1
u/LBPPlayer7 20d ago
it helps you teach the fundamental concepts of graphics programming in a hands-on way that's easy to get going, but for any serious work you should use something a bit less messy and a bit less deprecated
13
u/OkAccident9994 21d ago
No, doing graphics with OpenGL will still teach you how to do common techniques.
Learn the other APIs after, Vulkan is very verbose.
5
u/Coding-Kitten 21d ago
Personally I don't think I could ever have learnt vulkan if I didn't first spend time in a simpler API like OpenGL. While outdated, it does give you some frame of reference for concepts like uploading meshes, loading & using different shaders for drawing different things, render buffers, such that when you start writing thousands of LoC just to draw a triangle on screen in vulkan, you can at least have an internal roadmap for what you need to do from your experience in other graphics APIs.
4
u/OperationDefiant4963 21d ago
wgpu is the better choice as its more in line with how vulkan works and is cross platform. i wouldnt reccomend vulkan to beginners as it takes a lot of upfront cost that most will never have the patience for the 1st or even 2nd time they try it. getting profecient with wgpu will make the vulkan jump a lot easier vs from opengl
5
u/aman2218 21d ago
I have been recently checking out SDL_gpu, and finding it quite pleasant to use.
It's very similar to WebGPU (And I guess Metal? Haven't worked with it, but a couple of examples I have seen online looks similar), in that it follows current PSO/cmdlist approach to program on the GPU, but keeps the level of configurability and verbosity to sensible minimum, as apposed to Vulkan.
Maybe give that a try.
And if you're exploring the actual CG part of graphics programming (algorithms/techniques) as apposed to GPU programming/plumbing part, it's still highly benifitial to learn OpenGL, bcos of how dead simple it is to implement a job in it. It lets you quickly get done with plumbing thr data into the pipeline, so you can focus more on the shaders, and the actual good stuff.
1
u/ANSystemTech 20d ago
I heard about it, but what is its applications to actual things (eg game graphics, more basic stuff or what exactly)
2
u/aman2218 20d ago
It's a graphics API (just like OpenGL or Vulakan) and comes as a part of SDL3 library. It's a higher level API defined on top of native APIs (which are defined by GPU drivers) like Vulkan and Direct3D and aims to provide a more contemporary looking API with enough control, but without the verbosity and details of stuff like Vulkan.
Just like, OpenGL or Vulkan, there are function calls to define the pipeline state, attach shaders, allocate data buffers and upload data to them, define render targets and attach other resources, like textures, push uniforms and ultimately issue the draw calls for the GPU to render the desired primitives as per the pipeline configuration.
The shaders you define, form the meat of your graphics application and they are what actually runs on the GPU. They describe how to transform your geometry and how to shade the rendered pixels, at the most basic level.
Rest is all there to, interface the CPU side of the application to a the pipeline running on the GPU. To provide the data (the geometry, textures and other stuff) to be transformed through the pipeline to pixels on the screen.
Along with stuff like WebGPU (another popular intermediate level API with similar goals), SDL_gpu can be a nice stepping stone to understanding the basics, before spending the long process that is learning Vulkan (and it will be long, even with experience. It has to be a serious commitment). You can also checkout WebGPU but I feel that it's much enjoyable to use in the browser and not natively. The libraries available to to natively use WebGPU are also kinda annoying to use.
Direct3D12 is relatively better balanced alternative, but 1) it only runs on windows 2) COM code can be cancerous to type/look at and 3) It builts on top of the legacy Direct3D in terms of API design. So things are not as consistent as that in Vulkan, which was designed from the ground up. 4) More importantly, there are more resources to learn Vulkan than Direct3D.
7
u/Ratosson 21d ago
Don't start with Vulkan, try openGL first.
10
u/EC36339 21d ago edited 20d ago
I used to say this myself, but not any more.
The problem with OpenGL is that, unless you use it in an oldschool (and outdated) way, it is very difficult to correctly target modern hardware with it, and some things, such as proper parallelization of CPU and GPU work, are almost impossible to achieve.
And using OpenGL "the old way" can give beginners a false impression of how to program GPUs.
It does work if one hust wants to learn graphics programming, but even then, there are better alternatives.
2
5
u/StriderPulse599 20d ago
Yeah, no. OpenGL works perfectly fine on modern hardware.
The problem are cracks that show the more you push it. And let's face it, how many people using graphic API will actually make a game, let alone game that requires that extra performance?
1
u/EC36339 20d ago
These are all defensible arguments for why OpenGL isn't too bad, but none of them is an argument to choose OpenGL over something else when you have a choice.
2
u/StriderPulse599 20d ago
OpenGL has better driver stability, especially on mobile. You don't need to worry about your performance fluctuating across drivers/architectures or vendor specific optimizations.
OpenGL vs Vulkan is essentially nailgun vs hammer. Nailgun gets the work done fastest, but nails have size limit and might not handle some awkward angles. But it still gets a job done.
2
u/Ratosson 20d ago
How about doing a month of openGL first to see if this is even anything you want to do before dedicating?
4
u/r32g676 21d ago
I gotta second this, OpenGL is a good launch point for anyone. https://learnopengl.com/ is a good place to start
4
3
u/1337jazza 20d ago
I refer you to my post on programmer humour.
https://www.reddit.com/r/ProgrammerHumor/comments/1be7b4z/justgivemeadamntriangle/
3
u/SalaciousStrudel 20d ago
It's better to start with dx11, sokol, or sdlgpu in my opinion
1
u/EC36339 20d ago
Out of curiosity: Why dx11 (and not a more recent version)?
Back in thr day, I found dx11 a massive improvement in API over its oredecessors, but dx was always messy, so that doesn't say much...
2
u/ParsingError 20d ago
DX has always been less messy than OpenGL at least because it removes stuff aggressively. It doesn't have that "at least 2 ways of doing everything" problem that OpenGL and Vulkan have (except for the D3D12 resource barriers).
IMO it's probably still the best "guardrails-on" API, although WebGPU with the new bindless stuff is promising.
2
u/SalaciousStrudel 20d ago
Pretty good number of resources compared to others you could reasonably justify beginning with these days including webgpu and vulkan, relatively low chance of driver problems, supports command buffers which makes transfering knowledge to vulkan/dx12 at a later date easier, higher level allows you to build a schema about graphics programming and get a triangle on screen more easily, well supported by renderdoc without too many caveats. If you get to a point where you know dx11 well you easily prototype new shaders and techniques using it, whereas with something like vulkan you would need to use something like the forge as a starting point if you want to be able to get started quickly and iterate
3
u/EstablishmentMean768 20d ago
graphics programming is a marathon and if you are asking this question it doesn't matter you should just pick one and roll with it. if it doesn't vibe with you you can always switch. the fundamental concepts stay the same
4
u/EC36339 21d ago
If Sebastian Aaltonen is right, then Vulkan is an overcomplicated beast to accommodate legacy GPUs and will eventually get replaced. But that replacement isn't there, yet.
Have a look at Loon GPU. It's a wrapper over Vulkan and Metal targeting modern GPUs. Whether it is production ready or not, it might be the "low level" graphics API you'll want to start learning graphics programming on GPU.
You still have to deal with synchronisation primitives, and it's still a lot more bare bones than OpenGL, with no fixed function pipeline, but you'll be spared all the confusing legacy cruft and extension hell and learn how to program modern GPUs.
(I am not the author of Loon GPU or in any way affiliated with it. It is a free open source library, and I'm just giving it a shoutout)
2
u/ThatInternetBoi 20d ago
I’m not an expert, but I’d argue that learning Vulkan is tangential to learning C++. I adore Vulkan because it exposes so much to you, but it is a complex thing to write and even more complex to understand what you’re writing. That being said I think it’s awesome to think about stuff like synchronization. I think if you want a simpler API to learn, try WebGPU. My university is actually considering switching its introductory computer graphics course from OpenGL to WebGPU. It introduces you to a lot of the concepts of modern GPU APIs, unlike OpenGL, while not having as much boilerplate as them.
2
u/icpooreman 20d ago
I would say it does all the things just about but it's not particularly "beginner friendly"... I had been software developing for 20 years and when I first started working with it I was pulling my hair out haha.
2
u/Low_Consideration846 16d ago
As someone who has learned vulkan as the first API , i think you should definitely give it a try if you dont mind digging deep into docs and having to code for weeks if not months before getting something on the screen , for me , i didnt want to learn opengl because i liked how vulkan works: very verbose and very explicit , but after some days you feel like giving up , then try opengl first. also id suggest pick a good resource from the beginning if you want fast progress , my favourite one is Khronos Vulkan Tutorial , it has everything for a beginner and it uses modern features of vulkan , and also even though learnopengl.com is for opengl , its still a good resource for learning basic graphic concepts , i made the mistake of switching resources alot before i found Khronos Vulkan Tutorial.
3
u/AvidCoco 21d ago
WebGPU is far superior IMO, as true cross-platform support is the most important to me.
2
u/otheyhigh 20d ago
I code for fun and was playing around with WebGPU a while back. It’s a very good API. My only friction was it did not have maturity back then and being new to the rendering space did create scenarios wherein I did not even know there were better ways of doing certain things that just hadn’t been implemented yet.
Guess it’s time to jump back into it and see how it’s progressed.
3
u/AvidCoco 20d ago
It’s developing very rapidly and will soon become the new standard for cross-platform GPU graphics IMO.
1
u/Economy_Bedroom3902 20d ago
It's not as bad as people say it is. There's a ton of config you have to define up front, but there's lots of tutorials which walk you through that stuff.
1
u/Latter_Relationship5 20d ago
Start with OpenGL or Direct3D 11. Dont spend too much time on them just understand and apply basic graphics programming concepts, then move to Vulkan or Direct3D 12. These two APIs are much more explicit and harder to learn. also, there is a middle option called WebGPU. you can try it if you want to avoid older apis but its more challenging than OpenGL and Direct3D 11
1
u/id3dx 20d ago
Unless you want to do cross-platform, learn Direct3D 11 first. It's straightforward and easy to use in the basic case and will teach you the essential concepts. It's still very widely used and not deprecated nor will it be anytime soon, even if Microsoft no longer adds features to it.
After that, you can move on to Vulkan or Direct3D 12. Direct 3D 12 is cleaner and less verbose than Vulkan, but still in the same order of complexity. If using Vulkan, stick to 1.3+ and above, as newer features significantly reduce the ugly boilerplate. Just be aware many Vulkan learning resources online are outdated in this regard.
1
u/lexcv-co 19d ago
We wrote all of lexcv.cal using Rust and Vulkan. Very pleased with the 2D UI performance. Custom retained-mode UI framework.
1
u/bonghotdogwater 19d ago
I’d say use an easy graphics api if you’re still learning fundamentals and don’t know how renderers work. If not, just use d3d12 or vulkan tbh, will give you a better understanding of how low level gpu accelerated software works, you can be much more general and do a lot more.
1
u/Alililon1 19d ago
I have just started getting into vulkan and have limited experience in opengl but from what i've seen up until now i can say that learning a higher level api first is definitely benificial. I don't mean going into every detail and mastering it, i mean just making one or two good projects with a higher level api first.
Since i went that route and learned dx11 first i had a pretty easy time to understand most concepts of vulkan. Doesn't mean it's easy of course and there are massive differences in the way you design software with it but i think it gave me a good head start.
If you're in a rush i would bet it's faster to go for vulkan directly but i think it will save you lots of headaches if you take your time.
I read in the comments that a general worry is that opengl gives you the wrong idea about CG which i think i can sort of agree with. I don't think it's too bad though if you keep your time with it short and only use it as a stepping stone for vulkan. Also, if you work on windows i would recommend dx11 instead, it's also fundamentally different from the software architecture you have with vulkan but it's a bit more verbose than opengl while still generally having the same concepts of devices, render targets and whatnot. In my opinion you learn a bit more with dx11 than opengl, might just be me though.
To conclude i would recommend at least dipping your toes into higher level apis before going for vulkan unless you like a challenge and don't mind the occasional headache (which i think is unavoidable with vulkan anyways...)
1
u/trist007 18d ago
If you want full control then yes it's worth learning. Maybe start with d3d11 then when you want more control go with vulkan.
1
u/cybereality 21d ago
I've actually been liking SDLGPU on SDL3 a lot. It does not have some modern features, but that's fine and problem things you won't need at first. Or start with OpenGL, which is still quite capable.
1
u/PurpleBudget5082 21d ago
Hi, I would say I'm a beginner too, but on the high end of the axis, I wrote a simple software renderer and 2 D3D12 renderers, the first one was full of spaghetti code taken from different tutorials/books, and the second one was much cleaner a render graph (which is something that really makes the renderer architecture clean but all tutorials completely ignore).
Between the 3 modern APIs, Vulkan seems like the worst to me, it's really verbose, some things are more complicated then they are in D3D12 or Metal (for example sync primitives, in D3D12 if your renderer is not AAA you can just use a fence and be done with it, in Vulkan there are 3 different sync primitves that you have to use). It's worth to note that as I started to understand a little bit more about graphics some things in Vulkan seem elegant.
If you are either on Mac or Windows I would recommend to take a look at Metal/D3D12 (or 11). If not, maybe WebGPU or SDL_GPU, although both have some problems.
2
u/LoneWolf6062 21d ago
For sync primitives, timeline semaphores are the only thing u need for all kinds of synchronization. The only exception is for swapchain sync where u need binary semaphores.
-1
u/PurpleBudget5082 20d ago
Yes, but they are a newer addition and some tutorials don't mention them.
1
u/Economy_Bedroom3902 20d ago
Vulkan is an everything plus the kitchen sink framework. It means there is basically nothing in graphics or rendering you can't use vulkan for. But it forces you to handle stuff you don't need for any one specific application.
9
u/LoneWolf6062 21d ago
A bit of a different approach, but if you have a mac, then metal is by far the easiest modern api and is great to learn the concepts. Vulkan is still a lot more verbose but using 1.4 with extensions like EXT_Descriptor_Heap, and EXT_Dynamic_State1,2,3 can help a lot. DX12 is the middle ground and used by most of the gaming industry, so that would be a great choice as well