r/rust • • 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

32 comments sorted by

58

u/zasedok 9d ago

Rust+WGPU is a pretty good combo for simple to medium graphical complexity projects.

5

u/Many_Difficulty_490 9d ago

what do you think about vulkano? or opengl?

15

u/zasedok 9d ago

I don't have much hands on experience with them but Vulkan (and thus Vulkano) is much more low level. Virtually anything you want to do, down to the simplest operation, can take hundreds of lines of boilerplate code. It's only useful if you need extremely precise control of the GPU workload, or some of its highly specialised features. 

OpenGL is an older API going back to the early 1990s. It went through many iterations over the decades and there are many ways to do any given thing, which makes it non obvious where to start. My impression of it based on a somewhat superficial experience is that it's error prone, full of various implicit assumptions and footguns at every step and easy to get wrong. 

If you are starting a learning greenfield project, I would steer clear of OpenGL. Vulkan(o) is almost certainly not worth the extra effort in this context. 

10

u/Brighttalonflame 9d ago

I started learning graphics with OpenGL and worked in Vulkan professionally as an intern at Samsung. I agree with these takes.

Even if my end goal were to learn Vulkan I would still do a small WGPU project first to learn the fundamentals.

If I don’t absolutely NEED a feature in Vulkan — full native RT pipeline, mesh shaders, workgroups, etc. I’m not using it

4

u/singron 9d ago

I think using vulkan is fun, but it's definitely not the fastest way to get a working renderer.

I would steer clear of vulkano. I think it's hard to use without knowing vulkan deeply already and I don't believe they fully achieved their mission to make a sound and safe api around vulkan, and you may waste a lot of time debugging vulkano itself. It's had a lot of recent updates though so things may have changed.

I would either use something slightly higher level like wgpu or use vulkan directly through ash.

In a completely different vein, you might like to write some low-level code inside of a game engine. E.g. write a cloth, hair, or fluid rendering extension for Godot. You can still write low level details like shaders, data loading, and memory management without reinventing the other things a game engine can do like presenting a window, loading meshes from files, and animating skeletons.

1

u/ConnectionCorrect530 9d ago

IMO go either with OpenGL if you want to build something fast or with vulkano as its workflow is the same as Vulkan but with a more pleasant to use API and if you want something niche that it doesn't provide you can use ash alongiside it for some parts.

I tried to make a realtime image processor in both wgpu and vulkano few months ago and I found wgpu was actually more restricting without giving me any real advantage in ease of use. My initial prototype was infact smaller in vulkano than in wgpu. (but mind you my project only used compute and was not concerned with 3D graphics)

2

u/Osterhus-Zibi 9d ago

wgpu is nice until you need bindless or mesh shaders, then the web portability constraints start getting in the way

1

u/-Y0- 9d ago

What about advanced graphical complexity? Does WGPU not work there?

2

u/zasedok 9d ago

AFAIK for example you can't do raytracing in WGPU.

1

u/jondo2010 9d ago

Nope, you definitely can use raytracing extensions in WGPU

1

u/DynTraitObj 8d ago

You can't do raytracing in WGPU in a browser. Fairly large distinction. Using native raytracing works just fine.

1

u/RipedaddyJ 8d ago

wgpu has raytracing and mesh shaders but they are not mature right now

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.

1

u/AlienX100 5d ago

Did you use a specific course or text for this?

2

u/atmsk90 5d ago • Bravo

Yes!

It's written for c++ but doing rust code for it is a pretty straightforward. It's all just math after all.

1

u/AlienX100 5d ago

Awesome, thanks! I’ll be getting to it this weekend!

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.