Skip to content

[Shaders] Adds TypeName generic to use type parameters in SDSL#1400

Draft
tebjan wants to merge 1 commit into
stride3d:master-4.0from
vvvv:dev/tebjan/sdsl-generic-types
Draft

[Shaders] Adds TypeName generic to use type parameters in SDSL#1400
tebjan wants to merge 1 commit into
stride3d:master-4.0from
vvvv:dev/tebjan/sdsl-generic-types

Conversation

@tebjan

@tebjan tebjan commented Apr 7, 2022

Copy link
Copy Markdown
Member

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

vvvv/VL.StandardLibs#242

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)
  • 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.

@tebjan
tebjan marked this pull request as draft April 7, 2022 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant