stride
stride copied to clipboard
[Shaders] Adds TypeName generic to use type parameters in SDSL
PR Details
Adds TypeName
generic parameter to SDSL to instantiate shaders with type parameters.
Description
This will allow writing shaders like in a high-level programming language with generic types.
Silly Example:
// definition
shader VectorUtils<TypeName T>
{
float LengthSquared(T input)
{
return dot(input, input);
}
}
// usage
shader MyShader : VectorUtils<float2>, VectorUtils<float3>
{
void Compute()
{
...
float lenSq2d = LengthSquared(streams.Position.xy);
float lenSq3d = LengthSquared(streams.Position.xyz);
...
// or, not sure if this would work too
float lenSq2d = VectorUtils<float2>.LengthSquared(streams.Position.xy);
float lenSq3d = VectorUtils<float3>.LengthSquared(streams.Position.xyz);
...
};
}
Ping @xen2 and @xoofx before I write more code, the SDSL AST files look a bit machine-generated. Did you use some kind of tool to generate the definitions? If yes, does it still exist? Any other input/thoughts are welcome too.
Related Issue
https://github.com/vvvv/VL.Stride/issues/352
Motivation and Context
We generate a lot of little shaders to patch shaders in our visual programming language. For that, we wrote the type permutations by hand at the moment. If we can programmatically instantiate shaders with type parameters at runtime, there need to be significantly fewer shaders to be written.
Also, having generic types in a shader language is badass.
Types of changes
- [ ] Docs change / refactoring / dependency upgrade
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist
- [ ] My change requires a change to the documentation.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.