Skip to content

BasicConcept

Youness KAFIA edited this page Sep 17, 2023 · 1 revision

Basic Concept

Summary

  1. The language
  2. Why using SDSL
  3. Understanding SDSL

SDSL (StriDe engine Shading Language) is a language for shaders used in the Stride game engine. It was originally meant to be a superset of HLSL, sharing every aspect of HLSL and was translated to GLSL when needed.

This specification will cover the reimplementation of SDSL's compiler in order to compile directly to SPIR-V. The implementation will be closely tied to the SPIR-V specification and understanding SPIR-V will help you understanding this implementation.

SDSL implements a mixin system helping the user compose shaders using a powerful composition system. It works like a SPIR-V linker with more features to allow more complex composition.

The user can write snippets of code and ask the compiler to produce a SPIR-V byte using the shader mixer. Naturally this also helps the engine generate shader code when mixins are attached to sub-render-passes.

Example :

// We define a mixin using a shader keyword, very similar to object definition in C#
shader ColorMixin 
{
    // A variable can have a storage decoration (here stream) to indicate where it should be stored.
    stream float4 color : SV_COLOR;

    // A mixin can also contain static methods
    float4 AddColors(float4 a, float4 b)
    {
        return a + b;
    }
    // And non static method making use of the variable "streams"
    void DivideColorBy2()
    {
        streams.color /= 2;
    }
}

// Our main mixin, containing the main method 
shader MainMixin : ColorMixin
{
    
    // Our main method for the fragment/pixel stage
    // Thanks to our mixin inheritance, we can make use of the color 
    // variable (through the "streams" variable) and 
    // the "DivideColorBy2" method.
    void PSMain()
    {
        streams.color = float4(1,0.8,0.2,1)
        DivideColorBy2();
    }
}
  1. Types
  2. Statements
  3. Mixin system
  4. Compilation
Clone this wiki locally