Mixedrealitytoolkit-unity: Standard Shader error on Android

Created on 1 Sep 2019  路  21Comments  路  Source: microsoft/MixedRealityToolkit-Unity

Describe the bug

I have a project running with the MRTK and for some reason, whenever I try to build for Android, I receive this error message. I'm not very good with shaders, so I have no idea how to deal with it :(

The interesting thing is, when I just build a second time after the fail, it works.

Shader error in 'Mixed Reality Toolkit/Standard': Non system-generated input signature parameter (BLENDINDICES) cannot appear after a system generated value. at line 840 (on gles3)

Compiling Vertex program with UNITY_PASS_FORWARDBASE _EMISSION STEREO_INSTANCING_ON
Platform defines: UNITY_NO_DXT5nm UNITY_NO_RGBM UNITY_ENABLE_REFLECTION_BUFFERS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_NO_CUBEMAP_ARRAY UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 SHADER_API_MOBILE UNITY_HARDWARE_TIER2 UNITY_COLORSPACE_GAMMA UNITY_LIGHTMAP_DLDR_ENCODING

which refers to:
https://github.com/microsoft/MixedRealityToolkit-Unity/blob/3e7433875fe05e8a2558a6437fa1e7d855422330/Assets/MixedRealityToolkit/StandardAssets/Shaders/MixedRealityStandard.shader#L840

To reproduce

Steps to reproduce the behavior:

I only managed to reproduce it in my project, but until I know what this means I can't really try to reproduce it in the MRKT,

Expected behavior

No shader errors

Your Setup (please complete the following information)

  • Unity Version 2018.4.6f1
  • MRTK Version mrtk_development

Target Platform (please complete the following information)

  • Android
Bug External Shaders / Materials

All 21 comments

@Cameron-Micka do you have a clue what's going on here?

Hi @Alexees, thank you for sharing these errors. They both appear to be related to single pass instanced rendering. Does your project have multi pass, single pass, or single pass instanced rendering enabled?

These errors appear to be stemming from some of Unity's pre-defined shader macros (or the way I'm using them). For instance in the second error UNITY_TRANSFER_VERTEX_OUTPUT_STEREO should initialize the last parameters in the g2f struct but it appears not to?

It's "SinglePass", "SinglePass Instanced" does not exist on Android platforms.
But it seems to be a SinglePass issue, MultiPass builds straight through.

Good to know, thank you! When I have a free moment I will try building for Android and see what's going on.

@Cameron-Micka I think I managed to fix the Wireframe shader to the best of my abilities, but the Standard shader problem is beyond me. Moving the facing parameter into the struct does not work, changing parameter order does not...
The error is so weird

@Cameron-Micka when can I expect that you managed to have a look? Is there anything I can help with?

Sorry for the delay in getting back to you. I鈥檓 tied up right now helping with another project, but I should free up next week. I鈥檒l borrow an Oculus Quest from another team and see if I can reproduce this locally. Please feel free to post any of your findings here and that will surely help kickstart my investigation.

@Cameron-Micka I managed to find out what the problem is, but I am not sure how to solve it. I guess that's up to you "resident shader bobbins" 馃樃
This is a compiling shader illustrating the problem. It seems that you cannot use a struct along with hte VFACE semantic... something like that. You might want to have a look. I guess that's either a Unity bug or VFACE must not be used this way.

To be more precise, using both paramters v2f i, fixed facing : VFACE breaks it

Shader "StereoFrontFaceTest"
{
    SubShader
    {
        Pass
        {
            CGPROGRAM

            #include "UnityCG.cginc"

            #pragma vertex vert
            #pragma fragment frag

            struct appdata_t
            {
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct v2f
            {
                UNITY_VERTEX_OUTPUT_STEREO
            };

            v2f vert(appdata_t v)
            {
                v2f o;
                UNITY_SETUP_INSTANCE_ID(v);
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
                return o;
            }

            fixed4 frag(v2f i, fixed facing : VFACE) : SV_Target
            {
                return float4(1,1,1,1);
            }
            ENDCG
        }
    }
}

To reproduce, switch to Android, use Oculus as VR SDK and compile the shader

That鈥檚 a great clue! Thanks for investigating further. I鈥檒l let you know what I find.

@Cameron-Micka any news? I can file a Unity bug report if that is what this is. I definitely would like to see this fixed as it's currently the only bug keeping me from using both, OculusGo and Quest.

@alexees, I鈥檝e finally cleared out my normal work (mostly) for this week and can start looking at this today. With your findings already hopefully we can get to a solution quickly. I鈥檒l let you know what I find!

Hi @alexees, with your help I think I see what is going on. If you look at the error:

Non system-generated input signature parameter (BLENDINDICES) cannot appear after a system generated value. at line 840 (on gles3)

It mentions the use of BLENDINDICES. When searching the Unity Shader source code you can see that UNITY_VERTEX_OUTPUT_STEREO is defined as DEFAULT_UNITY_VERTEX_OUTPUT_STEREO which is defined as:

#if defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO uint stereoTargetEyeIndexSV : SV_RenderTargetArrayIndex; uint stereoTargetEyeIndex : BLENDINDICES0;

So, stereoTargetEyeIndex is using the BLENDINDICES0 input semantic when SHADER_API_GLES3 or SHADER_API_GLCORE is defined.

Because BLENDINDICES0 doesn't begin with SV_ that means it is not a system generate value.

This is where things seem to get odd. The error says BLENDINDICES cannot appear after a system generated value. In my mind it is appearing before a system generated value:

fixed4 frag(v2f i, fixed facing : VFACE) : SV_Target

which expends to:

fixed4 frag(..., uint stereoTargetEyeIndex : BLENDINDICES0, fixed facing : VFACE) : SV_Target

so it seams BLENDINDICES0 is before a system generated value and not after?

I tried rearranging the arguments to:

fixed4 frag(fixed facing : VFACE, v2f i) : SV_Target

but then got this error:

Non system-generated input signature parameter (SV_POSITION) cannot appear after a system generated value. Non system-generated input signature parameter (TEXCOORD) cannot appear after a system generated value. at line 852 (on d3d11)

I also tried moving the facing variable into the v2f declaration but that doesn't work because the attribute can only be read in the pixel shader.

I was also able to reproduce:

The interesting thing is, when I just build a second time after the fail, it works.

So, I'm going to file a bug with Unity since the error seems erroneous or obfuscated. When you say "it works" does everything render correctly on device?

If it doesn't and you don't need "correct" two sided lighting you could remove the use of VFACE until I hear back from Unity. I'll post back here what I find out.

Thanks for confirming all of that.
I'm not actively using two sided lighting and don't know if any of the MRTK assets do, but I guess I'll just remove it for now.
Are you going to post the resolution of the Unity bug report here? (send to devs, or solved in Unity xxxx)

None of the built in MRTK UI elements use two sides lighting, just a few of the example materials do. So, you could safely remove it in your project if you don鈥檛 need it.

Of course! The case number is 1187259. I鈥檒l post back here what Unity鈥檚 response is.

Latest feedback from Unity:

We successfully reproduced this issue and have sent it for resolution with our developers.

1187259 does not show up in Unity Issue Tracker. Any news on this?

1187259 does not show up in Unity Issue Tracker. Any news on this?

They don't necessarily put everything on the public issue tracker

Looking at Unity's private issue tracker the bug is still open. I just sent them an email to see if any progress has been made.

Bug still present in MRTK v2.3.0.
I have also noticed that after failing the build for the first time due to the aforementioned error, Unity successfully builds and deploys on the second attempt, without doing any further changes, just clicking again on "Build and Run".

Thank you for reporting @vincenzorin. Unfortunately this is an issue that is currently out the MRTK's control. But, I will be sure to post here when I hear back from Unity.

Good news, Unity has fixed this issue and reported:

We have fixed this problem and it should not appear in Unity 2020.2.0a8 and above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markgrossnickle picture markgrossnickle  路  3Comments

amfdeluca picture amfdeluca  路  3Comments

provencher picture provencher  路  3Comments

StephenHodgson picture StephenHodgson  路  3Comments

brean picture brean  路  3Comments