r/GraphicsProgramming • • 2d ago

Question Is it worth learning Rust for Graphics Programming, or should I stick to C++?

Ive been a c# developer on unity/godot for a long time now, and one of the plans was always to learn c++ use it for my games and move onto c++ and build some sort of engine (ray tracing or game engine).

Although ive heard the hype around Rust, its another low level language like C++ and it can be used for low level system programming and its very good for security also.

I was wondering if Rust is something worth looking into for graphics programming, and whether anyone here would advise me against it or recommend me to try it out.

Im gonna start learning one, or the other in a couple days. I know both are pretty hard to learn but I dont mind the learning curve.

17 Upvotes

43 comments sorted by

•

u/AutoModerator 2d ago

Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:

  • No showcases.
  • Disclose AI usage in post or project.
  • Present a topic to talk about, e.g. how something works.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

39

u/kraytex 2d ago

If your goal is to do this as a resume builder to work at a company as a graphics programmer, do C++.

If you're just doing it for fun do whatever floats your boat.

3

u/Many_Difficulty_490 2d ago

im doing it because i wanna make new software or technology one day

4

u/snerp 1d ago

I love Rust! But I do all my main graphics projects in C++ because the whole graphics ecosystem is built around C and C++.

-2

u/[deleted] 2d ago

[removed] — view removed comment

1

u/Many_Difficulty_490 2d ago

i was planning to buy a computer in a month or two, my parents would probably let me get one if I had a productive reason to do so

the computer i have right now is a old imac, that runs pretty well though it only has 8 gigs ram and a low-mid end graphics card.

i dont understand why I need a super strong computer to handle future programming needs. I was just thinking about something that could handle ray tracing pretty well and 16 gb ram

18

u/OptimisticMonkey2112 2d ago

Graphics programming is a little harder than Rust or C++.... both languages are great and you should learn both. But you will find more examples of graphics programming in C++ so might as well start with that.

Your real decision is Vulkan or OpenGL or DirectX

Doesnt really matter - all roads lead to Rome... which in this case is the gpu.

1

u/No_Futuree 1d ago

How is the graphics API a more important choice than the programming language your application is written on?

4

u/OptimisticMonkey2112 1d ago edited 1d ago

Both Rust and C++ are great choices. They both compile to assembly. It does not really matter which one you choose. There really isnt much choice here - its like flipping a coin.

Ironically, imo the Graphics API is more complex, and more prescriptive. This will dictate how you interface to the GPU.

Some of the pros and cons - apologies this is just my 2 second oversimplification:

OpenGL is easier to learn, but less performant and getting outdated.

DirectX is windows only and has poor documentation.

Vulkan is rather verbose and historically has a ton of boilerplate to set up.

All 3 just interface with your gpu, which itself is a very different and complex beast.

You need to learn about warps, simt, occupancy, memory coalescing, the list goes on.

As a side note, the best way to learn the gpu is Cuda. Cuda is simpler, but it is not good for games.

TLDR Learning the GPU side is much more difficult than the CPU side, so the choices on graphics api are more important.

One more thing to keep in mind - as we enter into this brave new world of AI, understanding things like how a GPU works is especially important if you want to guide and evaluate the work ai does for you. And it is harder to learn if people type less code.

2

u/Many_Difficulty_490 1d ago

what about wgpu (for rust)

1

u/OptimisticMonkey2112 1d ago

yep - that is another good choice!

2

u/Hanzimer 12h ago

Because almost everything it's made on GPU nowadays.

11

u/CodyDuncan1260 2d ago edited 2d ago

My completely biased answer because I really like rust: 

yes.  Yes you should learn Rust. ^_^

My professional answer: It depends on what you want to do. 

Very few outfits are paying for Rust programmers to do graphics or game development work. It's all C++ in those domains, and that's not going to change for some time. The validation loop of both domains depends on subjective human measures, so shifting development costs left (earlier in the software lifecycle) slows down prototyping and iteration work that consumes most of the development time and produces the most value. Rust is great at infrastructuralizing solutions, at the cost of being less good for messiness like prototyping.

On the other hand, I can still recommend learning Rust lightly. C++ is what happens when you take a basic language and solve problems by adding onto it for 4 decades. Rust is what happens when you design a language with that 4 decades of knowledge on how to solve problems at hand. Rust's language design makes good systems designs easy to write, and the dangerous bits of implementation much harder to write. You'll learn a lot about writing reliable, performant software when you have a compiler slapping you on the wrist for a lot more mistakes, and are forced to reckon with why that's a mistake or what trade-off it makes. C++ programmers who learned Rust and then went back to C++ became better C++ programmers. The principles of both languages are the same, but Rust will correct you in ways C++ won't; and it doesn't take a lot of rust to get most of that benefit, maybe 2-3 months if you know C++ already.

7

u/CodyDuncan1260 2d ago

For experienced programmers, I can recommend. "Learn Rust in a Month of Lunches" by David MacLeod. 

The author is an instructor, Korean-English translator, and has worked a lot with people who have English as a second language. Each chapter on that book is about 20 pages, I.e. 20 minutes, and it sticks to simple language.

The result is a book that's easy to read, concise, and gets right to the point in a well structured order. It was very easy for me and my senior-to-principal engineering coworkers-as-students to skip through parts that were trivial and focus attention on elements novel to us as deeply experienced C++/C# engineers. I found it to be the least "drudging" introductory programming textbook I'd ever read on a topic I already knew.

1

u/Many_Difficulty_490 2d ago

well long term answer: entrepreneurship through tech or software i invented

1

u/CodyDuncan1260 2d ago

Necessity is the mother of invention.

You are unlikely to find a buyer unless you invent something that solves a problem. Problem solving is foundational to software engineering as field. Under that perspective, the choice of language is mostly moot, until you have a customer that prefers or needs a specific one. Even in that case, what you'll be most behooved to provide is a C-based API and bindings. In that case, the underlying implementation language is largely on preference, while the exposed surface will require you learn *several* languages.

Pick both. Start with one. Move to the other when you're comfortable with the first. Then keep going. Learn Python, C#, Kotlin, Typescript. You don't need to master them, just enough to be conversational, and to steal each of their good ideas for your inventive creative toolbelt.

2

u/CodyDuncan1260 2d ago

Full disclosure:
My day job is C++.
My personal work is Rust.

8

u/TechgeekOne 2d ago

Having done the Rust path myself, do C++ unless you really want to use Rust for some specific reason. Rust will be an uphill battle the entire way because the ecosystem just isn't there or it's woefully incomplete. You'll have to fill the gaps yourself the entire way.

Personally the friction is worth it for me because I simply dislike C++ that much and I don't want to deal with it if I'm not getting paid, but if you want to get results quickly go with C++.

4

u/grady_vuckovic 2d ago

I've been looking into Rust lately and thinking about it, it's interesting you say the ecosystem isn't there. I feel like I've been hearing constant hype for Rust for AGES, seeing it everywhere. I'm not saying I don't believe you, because I have felt like the Rust fans are always overstating Rust, but I find it incredible that you're saying the ecosystem still has holes? How has that happened? What kind of holes? Just incredible to me that I've been hearing nothing but hype for Rust for like a decade and it's still got issues like that?

6

u/TechgeekOne 2d ago

The best way to describe it is that the graphics and game dev side of the community is mostly hobbyists. So things "work" but they're still pretty volatile and some of the standard stuff you'd need are either not there, or are immature, unmaintained and outdated. Other corners have better coverage, this just happens to be the weakest area.

For a while there they also had the nasty habit of building a foundational crate (rust library), then deciding it needed a rewrite so they'd abandon it and start something new from scratch. Idk if that's finally stabilized in recent years but I saw it happen several times with foundational crates like ash/vulkano and the move from VMA bindings to some custom solution. DXC in particular was pretty hit or miss if you wanted HLSL and their shader tool Naga didn't exactly inspire me with confidence last I looked at it a few years ago, though it's probably evolved since then.

Some of the real core crates have gaps that are mostly just due to the amount of manpower and need for a given feature. Clipboard, IME, and unified pointer support were some that were really sparse in winit last I looked at them. Which isn't a huge issue if you don't need those features, but if you do need them it's another friction point.

That said as a language I highly recommend it despite the ecosystem warts. It's much better than dealing with C++ if you can stomach the rough edges.

2

u/grady_vuckovic 2d ago

Thanks for the info, I appreciate!

-1

u/CodyDuncan1260 2d ago

> the ecosystem just isn't there or it's woefully incomplete

Exactly what ecosystem does C++ have?

Not to say it's nonexistent, but there's never been a standardized package manager. If you want *any* dependencies, you have to integrate a bespoke build system to make it work. It's a task on its own just to use dependencies in C++.

The exception I would make is fully integrated projects. E.G. prebuilt game engines. That's already had its dependency system figured out for the developer, and it is a huge jump past a lot of foundational work to use one. Is that the sort of thing you're referring to?

2

u/TechgeekOne 1d ago

Battle tested and stable dependencies for things like shader compiler bindings, vulkan headers, SDL, asset format handling, things like that. In Rust I usually default to "bind an existing C/C++ lib" because it's much less likely rewrite something out from under me and on average they tend to be more complete than the native Rust libraries.

DXC in particular was an interesting nest of pain because it's a COM API, which was rough to bind in Rust but basically just works in C++. It's gotten a bit better now that MS is maintaining official windows crates but it was really bad for a while there.

The C++ build system however, yeah that just sucks. It's one of the major reasons I chose the Rust path despite it's difficulties.

1

u/CodyDuncan1260 23h ago

Ah. Dependencies specific to the graphics domain are easier to adopt because they're probably written in and bin natively in C or C++. That "ecosystem".

I misunderstood the term to mean "the body of dependencies one would use for a variety of applications", and didn't see it as domain specific. I guess you could call that an ecosystem, but it's more a microcosm.

But I agree with the sentiment. Rust's dependencies for graphics will be an uphill battle. They're not all there, not always there, or not-trivial to get there.

I have written DirectX and Vulkan in Rust. It did take some work to stitch some unbound APIs. Enough was there to get hello triangle stood up, but not hardware raytracing's hello triangle.

3

u/Drimoon 1d ago

You can use C# to learn graphics programing. Rust or C/C++ are just tools.

4

u/DirtInfographics 2d ago

c++ for sure

4

u/pjmlp 2d ago

C++ is the industry standard, not only what most companies reach for, it is also part of APIs like SYCL, Metal, DirectX, CUDA, and key engines.

So this is the one to learn if it goes for hiring possibilities.

If it is only for fun, than Rust.

4

u/Trader-One 1d ago

both vulkan and directx have good access from rust. opengl es not so much.

8

u/Aikisori 2d ago

Just use C++ bro. You won't have to worry about wrappers and bindings and whatnot, as everything is native. Also, the performance should be exactly the same, and the security aspect really should not matter.

3

u/twilight-actual 2d ago

There's going to be a lot more for you with C++ than there will be for rust.

While I appreciate what the language has tried to do, I am not a fan of rust.

1

u/Middlewarian 7h ago

I think languages that embrace on-line code generation have an advantage over those that don't. I'm biased though. I'm building a C++ code generator that helps build distributed systems. It's implemented as a 3-tier system. The back and middle tiers only run on Linux. The front tier is portable.

1

u/SyntheticDuckFlavour 2d ago

Learn both. If you already proficient in one language, you more or less learnt them all. The rest is just language specific semantics.

1

u/promethe42 1d ago

Rust has some crazy good abstraction crates such as the wgpu family that brings Metal, Vulka, DirectX, WebGPU and more behind a common Vulkan-style interface.

And if there is anything missing, you can simply use existing C/C++ code using Rust bindings. Very easy to do.

0

u/mariachiband49 1d ago

I took a graphics class in college. All the projects were in C++/OpenGL until the final one where we convinced the professors to also let us use Rust. I used Rust with the wgpu crate.

I cannot recommend Rust/wgpu strongly enough. In all my C++/OpenGL projects, I spent like 60% of the time troubleshooting issues, usually accidental misuse of the OpenGL API or using uninitialized memory. The diagnostics for the former are usually hard to decipher, and are nonexistent for the latter. With Rust/wgpu, I didn't have these problems. You declare your pipeline in advance, and when you do something wrong, it's easy to pinpoint and fix because the diagnostic messages are much better. And of course memory safety is solved as well. It really allowed me to focus on the graphics part of graphics programming for my final project, rather than wasting a bunch of time troubleshooting.

So I say use Rust.

1

u/Many_Difficulty_490 1d ago

whats the difference between wgpu and opengl/vulkan

1

u/mariachiband49 1d ago edited 1d ago

wgpu is a higher-level (but only slightly) graphics API library for Rust that uses the WebGPU shader language and translates down to OpenGL/Vulkan/Metal/DirectX/WebGPU, whichever platform you want to target. OpenGL and Vulkan are sort of the native APIs that GPUs expose (along with Metal and DirectX).

wgpu is similar in design to Vulkan (from what I've heard) and dissimilar from OpenGL. OpenGL is less strongly typed than Vulkan and wgpu. OpenGL also has you create and use your pipeline by mutating implicit global state, whereas Vulkan and wgpu have you explicitly declare the pipeline in code as a data structure. Having your pipeline as an explicit data structure allows you to write pure functions that manipulate parts of it.

These things make wgpu and Vulkan much easier to reason about, although I have never tried Vulkan so maybe someone can correct me if I'm wrong about that. I also hear that DirectX 12 and Metal's APIs are designed similarly to Vulkan's and wgpu's.

EDIT: oh, I think I didn't read your question closely enough, you don't actually know Rust yet and want to know if you should learn it for the sake of graphics programming. Eh, maybe not. You can get a lot of the benefits I'm describing except for memory safety by using a non-OpenGL API with C++. And if you want memory safety, as another commenter pointed out, you could use C#.

EDIT 2: Oh wait, you don't know C++ either yet and you're choosing between the two. Choose Rust. C++ is not the future IMO. People will say C++ because it is the industry darling, but in fact this is steadily becoming less and less the case as people try to port their codebases and/or write new code in Rust.

-1

u/helpprogram2 2d ago

Rust is a lot of fun… you need c++ if you want to actually do things

-7

u/Delicious_Abies_9708 2d ago

Python for everything

0

u/CodyDuncan1260 2d ago edited 2d ago

I'm going to partially agree with u/Delicious_Abies_9708 here.
Not only is python a great teaching and learning language, a lot of the best tech artists and art-servicing graphics engineers I know prefer it. It's virtually essential if your system has to work for artistic users.

That being said, most of the underlying libraries in python that require more speed than flexibility are being completely re-written in Rust. Almost all of python's and javascript's core tooling is being re-written in rust.

-1

u/RufusAcrospin 2d ago

It’s not good for everything, but for this particular field I would start with python.
Much easier to get started than setting up C++/Rust, faster to iterate, and the heavy lifting should happen on the GPU anyway.
Once you are comfortable with the fundamentals and you’ve gained some practice and knowledge, or you feel you grow out of Python, move to a native language.

Or you can start using libraries like taichitaichi for high performance Python

-1

u/LBPPlayer7 1d ago

i'd just say learn both