Search Unity

Question Shader precision problem in iOS frame debugger

Discussion in 'Shader Graph' started by Ahmadhp, May 14, 2020.

  1. Ahmadhp

    Ahmadhp

    Joined:
    May 31, 2013
    Posts:
    33
    Hi All,

    So there is this precision setting for shaders in the shader graph which it's recommended to set to half for mobiles.
    But the generated code is still has a lot of variables defined in float and when I look at the shader in the xcode's frame debugger there is always this warning which is saying like ~70% of the floating point operations are in 32bit or something similar and it recommends changing it to 16bit.

    I wonder if there is a way to change this? and how much performance gain is here in mobiles?

    Thanks
     
  2. yzhuangaa

    yzhuangaa

    Joined:
    Feb 27, 2019
    Posts:
    22
    "One complication of float/half/fixed data type usage is that PC GPUs are always high precision. That is, for all the PC (Windows/Mac/Linux) GPUs, it does not matter whether you write float, half or fixed data types in your shaders. They always compute everything in full 32-bit floating point precision".(from https://docs.unity3d.com/560/Documentation/Manual/SL-DataTypesAndPrecision.html)
     
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    He is talking mobile (iOS) though, so that is completely and absolutely irrelevant.

    Not really, even when explicitly writing shaders manually, and setting precision for each variables, often times Unity just casts to another precision (and maybe even back to what you had), wasting a ton of performance.

    Just accept that Unity doesn't really let you set precisions as you want them and does a lot of stupid conversion no matter what you do.
     
  4. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    727
    It really is too bad. The generated shaders for iOS are a mess of conversions from halfs to floats and floats to halfs. Is there any Unity dev that can weigh in on why this happens? It doesn't seem necessary at all from what I have seen.
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,735
    It has been like that for years, I wouldn’t count on the situation improving.