Search Unity

Shader Compiler Error when SV_POSITION is a Half4 on Mali GPUs

Discussion in 'Shaders' started by Dorodo, Oct 12, 2019.

  1. Dorodo

    Dorodo

    Joined:
    Mar 8, 2015
    Posts:
    44
    I found a very specific shader error when testing a shader on android, causing it to render magenta on the device.

    upload_2019-10-12_12-41-28.png

    I tested on 3 devices: two Galaxy S8 with different GPUs (Mali-G71 and Adreno 540), and a Galaxy S7 with a Mali-T880. The shader works fine on Adreno, but doesn't work on the Mali devices.

    Here's a test shader which you can use to reproduce the error. In order to trigger the issue, you need 3 or more TEXCOORDs in your V2F and have SV_POSITION be declared as a Half4.

    Code (HLSL):
    1. Shader "Unlit/testHalf"
    2. {
    3.     Properties
    4.     {
    5.     }
    6.     SubShader
    7.     {
    8.         Tags { "RenderType"="Opaque" }
    9.  
    10.         Pass
    11.         {
    12.             CGPROGRAM
    13.             #pragma vertex vert
    14.             #pragma fragment frag
    15.  
    16.             #include "UnityCG.cginc"
    17.  
    18.             struct appdata
    19.             {
    20.                 half4 vertex : POSITION;
    21.             };
    22.  
    23.             struct v2f
    24.             {
    25.                 half2 uv : TEXCOORD0;
    26.                 half2 uv1 : TEXCOORD1;
    27.                 half2 uv2 : TEXCOORD2;
    28.                 half4 vertex : SV_POSITION;
    29.             };
    30.  
    31.             v2f vert (appdata v)
    32.             {
    33.                 v2f o;
    34.                 o.vertex = UnityObjectToClipPos(v.vertex);
    35.                 return o;
    36.             }
    37.  
    38.             half4 frag (v2f i) : SV_Target
    39.             {
    40.                 half4 col = half4(1,1,1,1);
    41.                 return col;
    42.             }
    43.             ENDCG
    44.         }
    45.     }
    46. }
    47.  
    Changing SV_POSITION to a float4 or having 2 or less TEXCOORDs solves the issue:

    upload_2019-10-12_12-41-59.png

    but this is boggling my mind. What could be the cause for this behaviour?
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,019
    Hi!
    Can you please report a bug so that we can investigate this?
    Thanks!
     
  3. Paul_H23

    Paul_H23

    Joined:
    Jun 19, 2019
    Posts:
    45
    Just hit this same issue in 2019.4.6f1, it seems having 2 TEXCOORDS and SV_POSITION suddenly introduces a requirement for gl_ClipDistance in the compiled shader that breaks some compilers, in my case, the Apple simulator.

    Was a bug ever recorded for this and fixed, or am I seeing something similar but unrelated?
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,019
    I don't think I've seen this reported.