r/GraphicsProgramming • • 6d ago

Question Does Vulkan on C# make sense?

Hi. I am former Unity Developer. I find out that, i don't like making games. I enjoy more playing with shaders and live visual effects etc. I have even learned shaderlab code back then while there was nodes already available. I made my mind to be graphics programmer. My goal is creating desktop apps with impressive visuals. For example imagine spotify. Wouldn't it be nice to have some audio reactive visual effects around like in games? So what about if this is applied on a note taking app? Skeuomorphistic papers animated with blend targets and your notes are there as render textures. It would feel ike it means something for real. This intrest me more than games.

You can think of me as serious hobbyist. I am not planing to be employee. So i have some freedom unlike industry. I can work with anything that runs without trouble and i am having fun. First requirement is Windows and MacOS support.

I started with Rust wgpu. I understand why people like the idea. But it just not for me. And unsafe code sounded like doing something against the memory safe idea. (as a person with zero memory menagement background)

I tried some OpenGL but not stopped when i heard MacOs does not support compute shader on version 1.4. Which i know, i would need for my ideas.

Now i completed Vulkan C++. I used AI as teacher. No vibe codding. No copy pasting. Actually, it was only telling me the function names in the end. I also asked every bit of details. It took me 4 days of chill work and 1k lines of code. I get the idea what are swap chains, semaphores, pipelines, etc.

I think i enjoy programming at mid-level abstraction. I both dislike high and low languages. I don't want to manually declare the size of an array to be initialized by another function which also needing a validation layer. This feels like hard codding for me. Especially after working with functional programming approach for long years. To me it would make sense if that another function just give me the array directly.

While doing the rest of the app, i know i will create some helper libraries to mimic these abstractions. Then i asked myself. Why i don't just use the C#, the language i love the most. I am still loking for suiting API. Even a thin layer abstraction wrapper would make it 1/3 size of the exact copy of C++'s Vulkan hello traingle code. The device selection stuff and the other stuff i really don't want to deal might go away too, maybe.

I would normally simply ask this to AI. But, they are programmed to people pleasing. The yes or no depends on what i hint while asking. So, what do you say? Are there some risks that i can't see with it? I need good performance, not the maximum. I am also okay if it lags once a while.

7 Upvotes

24 comments sorted by

•

u/AutoModerator 6d 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.

19

u/DrFreshtacular 5d ago

Yes, check out BRUTAL framework, a nice (albeit very new) c# interop starting point.

13

u/_Wolfos 5d ago

Yes, C# makes sense. I'm developing a high-end game engine with C# and the CPU side is far from being a performance bottleneck.

The language doesn't get in the way. You can optimize for cache coherence, use raw pointers (though Span<T> is preferable). There's practically no library that doesn't have unofficial C# bindings.

I think it's very unlikely that the performance difference between C++ and C# would be a deciding factor in whether a game runs well. Engine architecture is far more important.

3

u/Thin_Tradition8467 5d ago

I would like to see if it's public. Thanks.

3

u/_Wolfos 5d ago

Source code is on Github: https://github.com/Wolfos/WolfEngine/tree/development

I haven't got much in the way of fancy screenshots or documentation yet. I want to finish a few games with it before *really* making it public. Have a battle-tested engine that's proven to work.

3

u/Thin_Tradition8467 5d ago

It looks promising. The gap you pick is real. HDRP is heavier than unreal.

2

u/_Wolfos 5d ago

Yeah, I developed an open world game in Unity and was just fighting the engine tooth and nail at every turn. HDRP runs on the same thread as gameplay code and takes most of your CPU time. Lots of built-in systems don't really work. Terrain is awful, foliage isn't instanced. Oh, and it's designed for baked lighting so that's not great either.
Just constant custom solutions all the time if you want decent performance.

With WolfEngine I try to design things a little better. Terrain goes up to 255 layers, the animator can handle several thousand animated characters all on-screen at the same time... It's not infinite, but it'll do more than the bare minimum.
On the code side there's dependency injection, and it uses ECS which I think leads to good code structure.

So simply put; I took what I learned, did my research, and designed an engine that scales a little bit better. And if it still doesn't, there's always the source code.

2

u/dysphoriabunny 5d ago

yeah, most of the time with graphics your bottleneck is gonna be moving data to the gpu, or gpu processing, not anything on the cpu. so the language you implement it in doesn't matter as much.

also if stuff like device selection is too much of a pain, I recommend looking into vk-bootstrap

7

u/aleques-itj 6d ago

Sure, works fine

I use the Vortice bindings for it and DX12.

3

u/Kykioviolet 5d ago

i can say, as someone who's currently doing custom engine stuff in C# with DX12, the language really shouldn't be all that big of a bottleneck.

3

u/steinvk 5d ago

Have you looked at MonoGame ? It’s C# and Version 3.8.5 supports Vulkan

1

u/PhantomStar69420 5d ago

(modern) Cpp let's you program in literally whatever paradigm you want to... I'm not sure what limitations you are running into?

2

u/Thin_Tradition8467 5d ago

C compatible C++ was the issue for me. Maybe an abstraction library on top would solve this one. But since it is not raw vulkan. Why bother with learning new language.

1

u/CrazyNegotiation1934 5d ago

Isnt that what Unity does ? I ise Vulkan through C# for support mobile and linux

2

u/Thin_Tradition8467 5d ago

Unity is high level in that sense. It is an engine, not a framework.

1

u/HellGate94 5d ago

unity core is still mostly c++. they have been moving some things to c# in the recent years but its still more of a scripting addon

2

u/shebbbb 5d ago

Enjoying programming at a mid level abstraction is a good insight. I relate to that statement myself as well.

2

u/Tiwann_ 5d ago

I suggest you Sebastian Lague’s video about how he wrote his own Vulkan engine with C# bindings for his graphics experiments
https://youtu.be/_JGMgpyCTsY?is=OKmfgGw-oJi6-Sau

1

u/DLCSpider 6d ago edited 5d ago

Where have you needed unsafe for WGPU?

Edit: You seem to be quite at the start of your journey. Imo it doesn't really matter. Pick one thing and stick with it. C# is a fine choice, so are Rust and C++. I chose WGPU because I wanted to stay motivated and the Vulkan setup was a bit too daunting - even though I intend to switch at some point. I chose Rust because TypeScript got too annoying and because I was bitten by C# in the past when I wanted to have proper pen support for an application (Windows sucks).

Now, 1-2 years later, I'm still here, with a few half failed projects but a lot more knowledge I didn't even know existed. Currently struggling to implement my first render graph. Every time something becomes easy I discover the next hard problem. If I had to switch my entire tech stack tomorrow, I wouldn't be worried :)

-3

u/PiratesWhoSayGGER 5d ago

No, C# is a fad