Search Unity

simple geometry shader fails on Android, works on Windows

Discussion in 'Shaders' started by fortgreeneVR, Mar 20, 2019.

  1. fortgreeneVR

    fortgreeneVR

    Joined:
    Sep 5, 2018
    Posts:
    28
    I have a simple pass-through geometry shader that works fine on windows but fails on an Android device with the following message:

    The given primitive topology does not match with the topology expected by the geometry shader


    Here's the shader:
    Code (CSharp):
    1. Shader "FG/Test"
    2. {
    3.     Properties
    4.     {
    5.         _Color("Color", Color) = (1, 1, 1, 1)
    6.     }
    7.  
    8.         SubShader
    9.         {
    10.                 Tags{ "RenderType" = "FGOpaque" }
    11.                 LOD 200
    12.  
    13.             Pass
    14.             {
    15.                 CGPROGRAM
    16.  
    17.                 #pragma vertex vert
    18.                 #pragma geometry geom
    19.                 #pragma fragment frag
    20.                 #pragma target 4.0
    21.                 #include "UnityCG.cginc"
    22.  
    23.                 struct appdata
    24.                 {
    25.                     float4 vertex : POSITION;
    26.                 };
    27.  
    28.                 struct v2f
    29.                 {
    30.                     float4 vertex : SV_POSITION;
    31.                 };
    32.  
    33.                 v2f vert (appdata v)
    34.                 {
    35.                     v2f o;
    36.                     o.vertex = UnityObjectToClipPos(v.vertex);
    37.                     return o;
    38.                 }
    39.  
    40.                 [maxvertexcount(3)]
    41.                 void geom (triangle v2f i[3], inout TriangleStream<v2f> stream)
    42.                 {
    43.                     stream.Append(i[0]);
    44.                     stream.Append(i[1]);
    45.                     stream.Append(i[2]);
    46.                 }
    47.  
    48.                 fixed4 frag(v2f i) : SV_Target
    49.                 {
    50.                     return fixed4(0.0,1.0,0.5,1.0);
    51.                 }
    52.  
    53.                 ENDCG
    54.             }
    55.         }
    56.         FallBack "Diffuse"
    57. }
    58.  
     
  2. takano_ch

    takano_ch

    Joined:
    Jan 21, 2019
    Posts:
    1
  3. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    812
    Does this happen on Windows if you switch the Editor to OpenGL?
     
  4. fortgreeneVR

    fortgreeneVR

    Joined:
    Sep 5, 2018
    Posts:
    28
    Hi Takano_ch and Aleksandrk,

    android version is [ro.build.version.release] = 7.1.1
    Unity version is 2018.3.4f1

    When I switch Edit->Project Settings->Player->Graphics APIs to OpenGLES3, Require ES3.1, Require ES3.1+AEP, and Edit->Graphics Emulation to OpenGL ES 3.0, Shader Hardware Tier 3, the shader doesn't work, it produces a gray color, but I don't see any errors in the console or in the Inspector with the shader selected. The disassembly of the compiled shader seems to have everything needed, see below.

    Thanks for looking.

    Code (CSharp):
    1. // Compiled shader for Android
    2.  
    3. //////////////////////////////////////////////////////////////////////////
    4. //
    5. // NOTE: This is *not* a valid shader file, the contents are provided just
    6. // for information and for debugging purposes only.
    7. //
    8. //////////////////////////////////////////////////////////////////////////
    9. // Skipping shader variants that would not be included into build of current scene.
    10.  
    11. Shader "FG/Test" {
    12. Properties {
    13. _Color ("Color", Color) = (1.000000,1.000000,1.000000,1.000000)
    14. }
    15. SubShader {
    16. LOD 200
    17. Tags { "RenderType"="FGOpaque" }
    18. Pass {
    19.   Tags { "RenderType"="FGOpaque" }
    20.   //////////////////////////////////
    21.   //                              //
    22.   //      Compiled programs       //
    23.   //                              //
    24.   //////////////////////////////////
    25. //////////////////////////////////////////////////////
    26. No keywords set in this variant.
    27. -- Hardware tier variant: Tier 1
    28. -- Vertex shader for "gles3":
    29. Shader Disassembly:
    30. #ifdef VERTEX
    31. #version 310 es
    32.  
    33. uniform     vec4 hlslcc_mtx4x4unity_ObjectToWorld[4];
    34. uniform     vec4 hlslcc_mtx4x4unity_MatrixVP[4];
    35. in highp vec4 in_POSITION0;
    36. vec4 u_xlat0;
    37. vec4 u_xlat1;
    38. void main()
    39. {
    40.     u_xlat0 = in_POSITION0.yyyy * hlslcc_mtx4x4unity_ObjectToWorld[1];
    41.     u_xlat0 = hlslcc_mtx4x4unity_ObjectToWorld[0] * in_POSITION0.xxxx + u_xlat0;
    42.     u_xlat0 = hlslcc_mtx4x4unity_ObjectToWorld[2] * in_POSITION0.zzzz + u_xlat0;
    43.     u_xlat0 = u_xlat0 + hlslcc_mtx4x4unity_ObjectToWorld[3];
    44.     u_xlat1 = u_xlat0.yyyy * hlslcc_mtx4x4unity_MatrixVP[1];
    45.     u_xlat1 = hlslcc_mtx4x4unity_MatrixVP[0] * u_xlat0.xxxx + u_xlat1;
    46.     u_xlat1 = hlslcc_mtx4x4unity_MatrixVP[2] * u_xlat0.zzzz + u_xlat1;
    47.     gl_Position = hlslcc_mtx4x4unity_MatrixVP[3] * u_xlat0.wwww + u_xlat1;
    48.     return;
    49. }
    50.  
    51. #endif
    52. #ifdef FRAGMENT
    53. #version 310 es
    54.  
    55. precision highp float;
    56. precision highp int;
    57. layout(location = 0) out mediump vec4 SV_Target0;
    58. void main()
    59. {
    60.     SV_Target0 = vec4(0.0, 1.0, 0.5, 1.0);
    61.     return;
    62. }
    63.  
    64. #endif
    65. #ifdef GEOMETRY
    66. #version 310 es
    67. #ifdef GL_ARB_geometry_shader
    68. #extension GL_ARB_geometry_shader : enable
    69. #endif
    70. #ifdef GL_OES_geometry_shader
    71. #extension GL_OES_geometry_shader : enable
    72. #endif
    73. #ifdef GL_EXT_geometry_shader
    74. #extension GL_EXT_geometry_shader : enable
    75. #endif
    76.  
    77. layout(triangles) in;
    78. layout(triangle_strip) out;
    79. layout(max_vertices = 3) out;
    80. void main()
    81. {
    82.     gl_Position = gl_in[0].gl_Position;
    83.     EmitVertex();
    84.     gl_Position = gl_in[1].gl_Position;
    85.     EmitVertex();
    86.     gl_Position = gl_in[2].gl_Position;
    87.     EmitVertex();
    88.     return;
    89. }
    90.  
    91. #endif
    92.  
    93.  
    94. -- Hardware tier variant: Tier 1
    95. -- Fragment shader for "gles3":
    96. Shader Disassembly:
    97. // All GLSL source is contained within the vertex program
    98.  
    99. -- Hardware tier variant: Tier 1
    100. -- Geometry shader for "gles3":
    101. Shader Disassembly:
    102. // All GLSL source is contained within the vertex program
    103.  
    104. }
    105. }
    106. Fallback "Diffuse"
    107. }
    108.  
     
  5. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    812
    This is not what suggested to check :)
    When you go to Edit->Project Settings->Player, it shows your current build target (Android in your case). Go to standalone player tab, uncheck "Auto graphics API" for Windows and set OpenGL as the first API in the list.
    It should have the same error.
     
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    812
    I suppose you're just missing
    Code (CSharp):
    1. stream.RestartStrip();
    after the last call to
    Code (CSharp):
    1. append();
     
  7. fortgreeneVR

    fortgreeneVR

    Joined:
    Sep 5, 2018
    Posts:
    28
    Hi Aleksandrk,

    Ok, got it, I was referring to the Android settings.

    So when I go to the 'pc, mac, linux standalone tab' and remove the DX options and add OpenGLES3, the shader works fine as originally listed.

    I don't have a plain OpenGL option, only OpenGLES3, OpenGLES2 and OpenGLCore.
    Using OpenGLES2 gives the gray result without errors. OpenGLCore works the same as OpenGLES3.

    Adding stream.RestartStrip doesn't make a difference in any of the cases.

    Thanks again.
     
  8. fortgreeneVR

    fortgreeneVR

    Joined:
    Sep 5, 2018
    Posts:
    28
    Ok, Good news / not so good news: In a small test example the geometry shader seems to work (to be sure I added per triangle per vertex colors), but the device log still has the same OpenGL error.
    So it seems a bit of a red-herring. Not sure if the larger app would fail because of it.
    I'll log a bug report.
     
  9. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    812
    Yes, I meant OpenGLCore.
    Thanks! We'll take a look at what's happening there :)
     
  10. fortgreeneVR

    fortgreeneVR

    Joined:
    Sep 5, 2018
    Posts:
    28
    Great. Larger app does fail to produce a viable image, mostly black with noise.
    Thanks for looking.
     
  11. fortgreeneVR

    fortgreeneVR

    Joined:
    Sep 5, 2018
    Posts:
    28
    Hi Aleksandrk,
    I filed case 1139402 last week but haven't heard back, except for the auto-reply.
    Would you mind having a look?
    Let me know if we can assist in any way as the problem occurs on a device that is not for sale yet.
     
  12. fortgreeneVR

    fortgreeneVR

    Joined:
    Sep 5, 2018
    Posts:
    28
    I also submitted a more complete example as case 1141313.
    Thanks again.
     
  13. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    812
    Hi!
    The bugs are processed by our QA team first. Someone will take a look after that.