One unique and new feature of Slang that sets it apart from existing shading languages is support for differentiation and gradient computation/propagation - while still cross-compiling generated forward and backward passes to other, platform-specific shading languages.
Before, the only way to backpropagate through shader code (such as material BRDF or lighting computation) was to either manually differentiate every function and chain them together, or rewrite it in another language or framework - such as PyTorch or a specialized language/framework like as Dr.Jit, and keeping both versions in sync after any changes.
Game developers typically don't use those, programming models are different (SIMT kernels vs array computations), it's a maintenance headache, and it was a significant blocker for a wider adoption of data-driven techniques and ML in existing renderers or game engines.
The design of generics in this one seems rather well balanced in simplicity vs power.
The part about interface-typed values [1] is interesting. They do dynamic dispatch as a fallback when the function is too polymorphic to be be specialized.
In Rust terms it's as if it picks between `dyn` and `impl` automatically. It looks convenient, but also a bit of a non-obvious performance pitfall.
It seems like the type checker could call out polymorphic functions both when compiling and even highlighting them in the editor when checking for type errors.
I've been very impressed by Slang as an open source project. The development team is quick to respond to issues and review pull requests. It's clear from their repository and their presentations that they take Slang seriously as a user-facing project, not a research demo.
I hope this becomes the standard way of writing shaders across all platforms. There is no compelling reason for having to use WGSL, HLSL, GLSL or Metal C++. Having one single feature-complete language is a huge QoL improvement.
Nobody is using all these languages at the same time, anyone who targets all these platforms already has some mechanism to turn HLSL or GLSL (or whatever) into what the target platform needs. That's why Slang will have difficulty finding adoption, it's the N+1th solution to a problem that already has been solved N times.
I think there is a compelling reason to have WGSL as a separate language (but maybe not sufficiently compelling): WebGPU is a lowest common denominator which can only have features which are in the intersection of its target platforms, and so WGSL has no “dead syntax” to memorize. If the language spec says it’s there, you can use it, and you won’t find examples online of code that just won’t work in WebGPU because of missing features.
Of course, the f16 extension immediately weakens that, and demonstrates that this situation probably won’t last.
I have to wonder how this fits in with other shader technologies that seem to have overlapping purposes. (There's Khronos' own Spir-V, SDL's SDLSL, Three's TSL, and WebGPU's WGSL)
The reflection and automatic differentiation look interesting, I just wish I understood better what problems they're trying to solve.
I actually think WebGPU/WGSL will and should become ubiquitous, though it's a shame it's not more C/GLSL-like, Slang may yet be a missing part of that solution.
I wonder if this is Khronos trying to fix the shader lang debacle with Apple that led to WGSL being what it is?
Thoughts?
- the frontend language is mostly compatible with HLSL, which is the defacto shader authoring standard in the gamedev industry
- it compiles to the 'shader language/bytecode zoo' of the different 3D APIs (since recently even WGSL/WebGPU)
So it lets you author your shaders in a single language that's already accepted by most of the industry, and target the various 3D APIs (D3D, Metal, GL, WebGPU, ...).
It is already possible to build such a tool yourself by glueing together existing libraries (like glslang, SPIRVTools, SPIRVCross and Tint), but it requires quite some work and there are little annoying details like SPIRVCross never supporting WGSL output for some non-technical reasons (so that you need a separate library like Tint just for the SPIRV-to-WGSL conversion). In fact there are tons of such engine-specific shader cross-compilers, all built around the same few Khronos libraries and doing more or less the same thing. Slang looks like it could be the standard replacement for all those custom solutions.
For my own needs, the main thing I'll need to investigate is how easy it is to add engine-specific custom annotations to Slang resources and then output those as part of the reflection information.
It does!
Both platform-specific compute shaders as well as cross-compilation to CUDA. The authors even provide some basic PyTorch bindings to help use existing shader code for gradient computation and backpropagation in ML and differentiable programming of graphics-adjacent tasks: https://github.com/shader-slang/slang-torch
(Disclaimer: this is the work of my colleagues, and I helped test-drive differentiable Slang and wrote one of the example applications/use-cases)
Don't we already have a shader language with Rust-syntax in WGSL?
It also works everywhere, given that WebGPU works wherever Vulkan, Metal & DirectX do...
...which is only a problem on Linux though (turns out that system-wide shared locations for headers and linker libraries are not a great idea). Most Slang users will probably be on Windows, and apart from that there's also most likely not much overlap with S-Lang users.
bartwr|1 year ago
lmariscal|1 year ago
dragonelite|1 year ago
mpartel|1 year ago
The part about interface-typed values [1] is interesting. They do dynamic dispatch as a fallback when the function is too polymorphic to be be specialized.
In Rust terms it's as if it picks between `dyn` and `impl` automatically. It looks convenient, but also a bit of a non-obvious performance pitfall.
[1] https://shader-slang.com/slang/user-guide/interfaces-generic...
hajile|1 year ago
Conscat|1 year ago
pjmlp|1 year ago
The main difference, with something like Cg, is that now it isn't NVidia only.
machinekob|1 year ago
coffeeaddict1|1 year ago
incrudible|1 year ago
mistercow|1 year ago
Of course, the f16 extension immediately weakens that, and demonstrates that this situation probably won’t last.
CyberDildonics|1 year ago
Cotterzz|1 year ago
flohofwoe|1 year ago
- the frontend language is mostly compatible with HLSL, which is the defacto shader authoring standard in the gamedev industry
- it compiles to the 'shader language/bytecode zoo' of the different 3D APIs (since recently even WGSL/WebGPU)
So it lets you author your shaders in a single language that's already accepted by most of the industry, and target the various 3D APIs (D3D, Metal, GL, WebGPU, ...).
It is already possible to build such a tool yourself by glueing together existing libraries (like glslang, SPIRVTools, SPIRVCross and Tint), but it requires quite some work and there are little annoying details like SPIRVCross never supporting WGSL output for some non-technical reasons (so that you need a separate library like Tint just for the SPIRV-to-WGSL conversion). In fact there are tons of such engine-specific shader cross-compilers, all built around the same few Khronos libraries and doing more or less the same thing. Slang looks like it could be the standard replacement for all those custom solutions.
For my own needs, the main thing I'll need to investigate is how easy it is to add engine-specific custom annotations to Slang resources and then output those as part of the reflection information.
jacobgorm|1 year ago
bartwr|1 year ago
Cotterzz|1 year ago
unknown|1 year ago
[deleted]
koolala|1 year ago
LegNeato|1 year ago
https://github.com/Rust-GPU/rust-gpu
Cotterzz|1 year ago
pornel|1 year ago
There's also WESL that aims to extend WGSL with modules and generics:
https://github.com/wgsl-tooling-wg/wesl-spec
and there's Naga project that can translate WGSL to other languages:
https://github.com/gfx-rs/wgpu/tree/trunk/naga
ImHereToVote|1 year ago
darkest_ruby|1 year ago
sandeepthroat|1 year ago
[deleted]
kseistrup|1 year ago
[deleted]
unknown|1 year ago
[deleted]
flohofwoe|1 year ago
otteromkram|1 year ago
We're gonna have a problem here...