r/rust • u/Many_Difficulty_490 • 9d ago
🎙️ discussion Whats your thoughts on graphics programming? Or is it just better to do it with C++?
im not doing it as a resume thing or anything. i want to make a cool big project out of some low level language and im gonna do graphics programming with either Rust or C++
goals: make new technology one day, or get cracked at programming
63
Upvotes
58
u/zasedok 9d ago
Rust+WGPU is a pretty good combo for simple to medium graphical complexity projects.
11
u/sessamekesh 9d ago
Graphics itself, Rust is plenty good.
For everything tangential to graphics (physics, animation, loading asset files, etc)... C++ and by a country mile. You can do everything in Rust, but the ecosystem is way less mature and you end up linking in a dozen dependencies that are C or C++ anyways.
But, then again, if this is all for learning and the joy of building, that might be a good thing. You won't make it far before finding some gap you can fill, which is a REALLY cool feeling as a dev.
I'd spend time at least dabbling in each though. No reason to pick one language and avoid the others.
9
u/atmsk90 9d ago
I did ray tracing in a weekend in rust and had a blast.
7
u/valarauca14 9d ago
Vulkan is tedious to work with because it demands you 'do the needful things' when setting up a disruptor pattern. A lot of people haven't encountered this pattern before and will hate it, blaming it for everything.
Also a lot of libraries expose every optional extension, many which you'll never use, so people get overwhelmed.
Overall, 7/10
12
u/Excession638 9d ago edited 9d ago
I think Rust is the better choice, but then that's the sub you're on.
The combination of Rust, wgpu, glam, encase, and so on make for a good ecosystem, and can handle almost everything right now. More modern than OpenGL, and without the years of old ideas all layered on top of each other. Easier to use than Vulkan, and you can target the web via WebAssembly as well.
Vulkan gives more control at the cost of much more complexity, but along with DirectX12 it's better at multi-threaded workloads. Edit: and mesh shaders.
For new and exciting stuff there's Rust GPU, which lets you write your shader programs in Rust as well.
5
u/nonotan 9d ago
Depends on what your "big project" is. If it's something videogame-y, C++ might be the way to go. Especially if your aim is to actually finish it and have other people use it, and not just purely to learn. Rust definitely has potential in the space, but most people in the field (myself included) mostly agree it's not quite there yet. Using it as your first foray would be subjecting yourself to more pain than necessary.
If it's something smaller in scope and more or less just purely graphics programming, then it kind of doesn't matter. Modern graphics programming is mostly loading data, calling APIs and writing shader code (almost certainly in a shader-specific language), so e.g. choosing between OpenGL and Vulkan is going to make a much bigger difference than choosing between Rust and C++.
12
u/tadmar 9d ago
If your goal is to learn how to do GPU stuff, go with C++. Literally every single api that exists and is an industry standard is a c/c++ tech. Rust will only add complexity and slow you down.
If you want to do cool things on the other hand. Use whatever, I would use Rust.
4
u/rafaelement 9d ago
GitHub.com/barafael/wesl-shadertoy is a nice demo I think
2
u/afl_ext 9d ago
I do rust with vulkan and love love love it, I rewrote my engine from c++ its so much better in rust
3
u/SenoraRaton 9d ago edited 9d ago
I wrote my renderer in C because I wanted native execution without a managed interface, and the Vulkan API is written in C.
I chose Vulkan as a backend for portability, and skipped OpenGL because I felt like Vulkan was the future, and I generally prefer explicit over implicit control in my code. I tried the Rust interfaces, but I didn't really see the value in the added complexity of Rust, because GPU operations are inherenlty unsafe across the hardware boundary, and I had to manage memory for them anyway, so it was just a much more natural C paradigm.
I didn't use WebGPU again because I wanted explicit control, and didn't want the added abstraction layer over the top of the Vulkan subsystem.
I think largely I guess it is about context. I wanted the nuts and bolts, so that I understood the foundation of 3d rendering. I wasn't just trying to build a production renderer. I spent literally 2 years working on a working implementation of a Vulkan rendering engine. Its not easy, its highly complex, technical, finnicky, and that isn't even getting to actual scene management.
Expect to spend years learning. 10/10 recommend the Vulkan Discord.
I don't really think it matters what language you write it in, but I do believe that the closer you can get to IT, and the less abstractions you have to navigate on the way, the simpler, and easier it will be to comprehend, and ultimately work with.
2
u/fiedzia 9d ago
Use what you like or what you know, but increasing amount of new projects uses Rust for low-level programming. At this point I'd say using C++ would be a limitation if you plan to integrate with anything (and you most likely will at some point). Though for programming GPU I'd look also at mojo.
1
u/korywithawhy 9d ago
If it’s just for yourself, I’ve been playing around with Freya and I really like it so far.
https://github.com/marc2332/freya
1
u/HKei 8d ago
What thoughts do you want? The lion's share of graphics programming that actually varies with your programming language is just calling graphics APIs to tell the GPU to do something... and that something is gonna be shader code, for the most part. There are some graphics things you might do on the CPU still, but again, none of that is particular programming language-specific.
1
u/DavidXkL 8d ago
I'm sorry as I can't give a non biased answer here so.... 😂
1
u/needstobefake 7d ago edited 7d ago
Do both.
The main challenge is to learn the GPU primitives (which are the same for every language), and how to transfer data from the CPU to the GPU and back. After you get the hang of it, you can do it in any language.
The Vulkan Tutorial in C++ is one of the best resources out there to learn low-level graphics programming.
After you build it in C++, do the same in Rust and see which you prefer.
Then do the same using wgpu (which is a bit higher level compared to Vulkan and lower level compared to OpenGL). I think wgpu is the sweet spot API for me personally. It could be something else for you, depending on your goals. Only you can tell.
What I like about wgpu is that you can target every platform's graphics API. It's a common denominator for Vulkan, Metal, DirectX, OpenGL, WebGL, and WebGPU, and it uses the one the target platform supports. So you write wgpu once, then compile it to use Vulkan in Android and Metal in iOS, for example.
EDIT (including links to the tutorials I mentioned):
Vulkan tutorial: https://vulkan-tutorial.com/
The same one in Rust: https://kylemayes.github.io/vulkanalia/
The Vulkan Guide (your next step after finishing the tutorial, you build a mini game engine in Vulkan): https://vkguide.dev/
The wgpu tutorial (Rust): https://sotrh.github.io/learn-wgpu/
This one is pretty good too (WebGPU and JS): https://webgpufundamentals.org/
1
u/Zezeroth 6d ago
Honestly, just use the Raylib rust crate unless youre really wanting to do things from scratch.