Shader stages

The function for each stage has a predefined name, so we recommend you don’t change it.

  • HSMain for hull shader
  • HSConstantMain for patch constant function
  • DSMain for domain shader
  • VSMain for vertex shader (takes no arguments)
  • GSMain for geometry shader
  • PSMain for pixel shader (takes no arguments)
  • CSMain for compute shader (takes no arguments)These are all void methods. Input and Output structures that are automatically generated to fit the final shader.

    Vertex shader

    SV_Position. In ShaderBase, it’s ShadingPosition. For example:
    1. override stage void VSMain(){ ... streams.ShadingPosition = ...; ...}

    Pixel shader

    SV_Target. In ShaderBase, it is ColorTarget. For example:
    1. override stage void PSMain(){ ... streams.ColorTarget = ...; ...}

    Geometry shader

    An example of geometry shader:
    1. [maxvertexcount(1)]void GSMain(triangle Input input[3], inout PointStream<Output> pointStream){ ... // fill the streams object streams = input[0]; ... // always append streams pointStream.Append(streams); ...}
    Input can be used in the method body. It behaves like the streams object and contains the same members. Output is only used in the declaration of the method. You should append the streams object to your geometry shader output stream.

    Tessellation shader

    An example of a tessellation shader:
    1. [domain("tri")][partitioning("fractional_odd")][outputtopology("triangle_cw")][outputcontrolpoints(3)][patchconstantfunc("HSConstantMain")][maxtessfactor(48.0)]void HSMain(InputPatch<Input, 3> input, out Output output, uint uCPID : SV_OutputControlPointID){ ... output = streams;}void HSConstantMain(InputPatch<Input, 3> input, const OutputPatch<Input2, 3> output, out Constants constants){ ... output = streams; ...}[domain("tri")]void DSMain(const OutputPatch<Input, 3> input, out Output output, in Constants constants, float3 f3BarycentricCoords : SV_DomainLocation){ ... output = streams; ...}
    Input and Input2 both behave like streams.
    Note
    output to streams at the end of your stage.

    Compute shader

    An example of a compute shader:
    1. [numthreads(2, 3, 5)]void CSMain(){ ...}
    ComputeShaderBase and override the Compute method.

    See also

  • Effect language
  • Shading language index
  • Shader classes, mixins, and inheritance
  • Composition
  • Templates
  • Shader stage input/output automatic management