5 ms·
No More Shading Languages: Compiling C++ to Vulkan Shaders [pdf]
- rgbforge 1y agoThe section discussing Slang is interesting, I didn't know that function pointers were only available for Cuda targets.
- raincole 1y agoYeah, C++ is the peak language design that everyone loves...
- reactordev 1y agoIn game dev they definitely do.
- arjonagelhout 1y agoI think this is indeed the advantage of this paper taking C++ as the language to compile to SPIR-V. Game engines and other large codebases with graphics logic are commonly written in C++, and only having to learn and write a single language is great. Right now, shaders -- if not working with an off-the-shelf graphics abstraction -- are kind of annoying to work with. Cross-compiling to GLSL, HLSL and Metal Shading Language is cumbersome. Almost all game engines create their own shading language and code generate / compile that to the respective shading languages for specific platforms. This situation could be improved if GPUs were more standardized and didn't have proprietary instruction sets. Similar to how CPUs mainly have x86_64 and ARM64 as the dominant instruction sets.
- monkeyelite 1y agoThe problem with C++ isn't that core features are broken. It's that it has so many features and modes and a sprawling standard library, because of it. The alleged goal here is to match syntax of other parts of the program, and those tend to be written in C++.
- feelamee 1y ago> that core features are broken can you please explain or link some sources about this? btw, is C++ STD really bloated? There are a lot of languages that mess in std much more stuff. E.g. python. A lot of people complaining about the lack of many library features - networking, reflection, <expected> and <optional> was added too late and so on.
- monkeyelite 1y agoYour quote is missing a key word.
- pjmlp 1y agoWhile it has its issues, and it seems WG21 lost direction on where to drive C++, on the games, graphics and VFX industries, another language will have a very hard time imposing themselves. Java and C# only did thanks to tooling, the unavoidable presence on Android, previously J2ME, the market success with Minecraft, XNA and Unity. Anything else that wants to take on C and C++ for those industries had to come up with similar unavoidable tooling.
- Calavar 1y agoI've seen a few projects along the lines of shader programming in C++, shader programming in Rust, etc., but I'm not sure that I understand the point. There's a huge impedence mismatch between CPU and GPU, and if you port CPU centric code to GPU naively, it's easy to get code that slower than the CPU version thanks to the leaky abstraction. And I'm not sure you can argue pareto principle: Because if you had a scenario where 80% of the code is not performance sensitive, why would you port it to GPU in the first place? Anyway, there's a good chance that I'm missing something here because there seems to be a lot of interest in writing shaders in CPU centric languages.
- deleted 1y ago[deleted]
- jcelerier 1y agoIt's very common to write c++ in a way that will work well for GPUs. Consider that CUDA, the most used GPU language, is just a set of extensions on top of c++. Likewise for Metal shaders, or high-level dogs synthesis systems like Vitis
- ranger_danger 1y agohigh-level.. dogs?
- jcelerier 1y agowops! FPGAs*
- chaboud 1y agoI’m going to guess that they meant Directed Acyclic Graphs or DAGs, which is a useful way to represent data dependencies and transformations, allowing formulation for GPU, CPU, NNA, DSP, FPGA, etc. If the macrostructure of the operations can be represented appropriately, automatic platform-specific optimization is more approachable.
- ruined 1y ago
- genidoi 1y agoGLSL is fine. People don't understand that shaders are not just programs but literal works of art[0]. The art comes from the ability to map a canvas's (x,y) -> (r,g,b,a) coordinates in real time to create something mesmerising, and then let anyone remix the code to create something new from the browser. With IV code, that goes out the way. [0] examples Matrix 3D shader: https://www.shadertoy.com/view/4t3BWl https://www.shadertoy.com/view/4t3BWl - Very fast procedural ocean: https://www.shadertoy.com/view/4dSBDt https://www.shadertoy.com/view/4dSBDt
- pixelpoet 1y ago> GLSL is fine. How would you use shared/local memory in GLSL? What if you want to implement Kahan summation, is that possible? How's the out-of-core and multi-GPU support in GLSL? > People don't understand Careful pointing that finger, 4 fingers might point back... Shadertoy isn't some obscure thing no one has heard of, some of us are in the demoscene since over 20 years :)
- genidoi 1y agoI don't know x3 > some of us are in the demoscene since over 20 years :) Demoscene is different, though what I'm imagining with shadertoy and what it could be hasn't really been implemented. GLSL shaders are fully obscure outside of dev circles and that's a bummer.
- exDM69 1y ago> How would you use shared/local memory in GLSL? In compute shaders the `shared` keyword is for this.
- pjmlp 1y agoGLSL is dead for pratical purposes, Khronos acknowledged at Vulkanised 2024 that no one is working on either improving it, or keeping up with new Vulkan features. Hence why most companies are either using HLSL, even outside games industry, or adoption the new kid on the block Slang, which NVidia offered to Khronos as GLSL replacement. So GLSL remains for OpenGL and WebGL and that is about it.
- fuhsnn 1y ago> our renderer currently does not use any subgroup intrinsics. This is partly due to how LLVM does not provide us with the structured control flow we would need to implement Maximal Reconvergence. Augmenting the C language family with such a model and implementing it in a GPU compiler should be a priority in future research. Sounds like ispc fits the bill: https://ispc.github.io/ispc.html#gang-convergence-guarantees https://ispc.github.io/ispc.html#gang-convergence-guarantees
- danybittel 1y ago> Unfortunately, Shader programs are currently restricted to the Logical model, which disallows all of this. That is not entirely true, you can use phyiscal pointers with the "Buffer device address" feature. (https://docs.vulkan.org/samples/latest/samples/extensions/buffer_device_address/README.html https://docs.vulkan.org/samples/latest/samples/extensions/bu...) It was an extension, but now part of Vulkan. It is widely available on most GPUS. This only works in buffers though. Not for images or local arrays.
- pjmlp 1y agoNot on mobile Android powered ones.
- danybittel 1y agoIt should be, it is part of 1.2. (https://vulkan.gpuinfo.org/listfeaturescore12.php https://vulkan.gpuinfo.org/listfeaturescore12.php the first entry bufferDeviceAddress, supported by 97.89%) Or did you mean some specific feature? I haven't used it on mobile.
- pjmlp 1y agoSupported as it actually works, or gets listed as something the driver knows about, but full of issues when it gets used? There is a reason why there are some Vulkanised 2025 about improving the state of Vulkan affairs on Android.
- canyp 1y agoThis is great news for any graphics programmer. The CUDA model needs to be standardized. Programming the GPU by compiling a shader program that exists separately from the rest of the source code is very 1990.
- makotech221 1y agoStride3d engine (https://www.stride3d.net/features/#graphics https://www.stride3d.net/features/#graphics) has something kinda of similar; it allows writing in shaders in (nearly)c# and having them compile to GLSL