Monday, May 20, 2024
HomeGame DevelopmentHow to implement graphics API functions like setUniform on a cross-platform shader...

How to implement graphics API functions like setUniform on a cross-platform shader in VLang?


I’ve been working on a C++ game engine for a while, but I decided to scrap the project because doing it in C++, despite my best efforts, I could feel the technical dept building. As such, I switched over to the modern, performant, VLang. I originally ignored it due to the GC, but the runtime is almost entirely gone now thanks to the awesome new autofree feature.

I decided that writing shaders in HLSL or GLSL or whatever else would be annoying, and I wanted my project to be just one language, so I threw together a VLang to SPIR-V compiler that leverages a bunch of existing tools to convert .v to .spv.

However, in doing this, I realized that there isn’t a graphics API I can use to interact with this (eg. .setUniform) because this is just IR. I’m having to make a system to do reflection on the shader and get info about what uniforms exist, and I’m struggling to find a neat way to interface with that in source code. The issue is that, to actually run these shaders, I have to get a .cso on Windows/PSN/XBox, a .ir file on MacOSX/iOS, a .spv file on modern Linux, and a .glsl file on old Linux (to compile at runtime). As such, to simplify this, I’m using SPIR-V Cross alongside the HLSL precompiler, the MSL precompiler, and the GLSL precompiler from DirectX3D, Metal, & Vulkan respectively.

Is there an easier way to do this while keeping all my shaders in one language? If not, how do I implement functions such as .setUniform and the like on my shaders?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments