Search Unity

Vertex shader input/output performance

Discussion in 'Shaders' started by exltus, Aug 11, 2020.

  1. exltus

    exltus

    Joined:
    Oct 10, 2015
    Posts:
    58
    I found that Unity have predefined some vertex input structs https://docs.unity3d.com/Manual/SL-VertexProgramInputs.html They are multiple variants like appdata_base and appdata_full. Now Iam wondering if there is any performance difference between using each other? Because otherwise I dont see any reason why to not use appdata_full everywhere
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The only real difference between using
    appdata_base
    and
    appdata_full
    for the vertex shader input is minor improvements in shader compilation time. Any unused shader input gets stripped from the shader by the compiler, so the resulting shader used by the game is functionally and performance wise identical.

    Vertex shader outputs and fragment shader inputs & outputs are a different story. The compiler will not strip any of those. It is up to you to make sure you assign any vertex shader output you need, and remove any vertex shader output you don't. Technically the fragment shader will strip any inputs it doesn't use, but generally you want to make sure the vertex shader outputs match what the fragment shader actually uses. Some platforms will error if they don't match perfectly (ignoring the
    SV_Position
    ), and on platforms it doesn't error on there is some wasted performance in outputting those extra properties, especially if they take some amount of work in the vertex shader to compute.