bug of unity 4.1.2 f2? built in shader and separate shader work different on android

Hi everyone, i have a big trouble with unity 4.1.2f1:
My phone is android 4.1, and the gpu is vivante GC400.
I create a simple project: two simple scenes, the first scene just have a GUI.Button which load the second scene when be clicked; the second scene has an unity sphere with a specular shader, and a GUI.Button which return to the first scene when be clicked.
1220945--50331--$first scene.png

The problem is:When I switch between the first and the second scene(press first scene’s button and press second scene’s button)many times,if I use the built in shader(select it from the drop list of unity editor), it works well; but if I copy coresponding shader code from the unity built-in shader folder(builtin_shaders-4.1.2,download from unity) into a seperate shader file, then give it to the sphere, it does not work well, sometimes the sphere looks to be strange.

But, when i test this project at unity 4.0.1f2, it works well in both scenarios.

It’s this a bug of 4.1.2f1?
Any suggestions?

Thanks!

Any help, please.
Thanks very very much.

Hi, have you submitted a bug report on this? Do you have a case number?

Hi,No, i have no case number.
How can i have a case number?
thanks.

Hi, JuliusM, how to get a case number?

I finally found a way to avoid this problem: I do not destroy the sphere when scene unload, so when i switch between the two scenes, the sphere not need to destroy and recreate, it always be there. and the shader not go wrong.

Ok, i’ll post resolution here for other people to see. The problem lies in vivante gpu drivers. In 4.1 we’ve added shader caching - after compiling once, if the gpu supports binary shaders (GL_OES_get_program_binary) we get the binary and save it to cache - so next time you try to load it (even on subsequent runs) you wont need to compile it - meaning way faster loading times. It turns out that vivante gpu have some bug in there ;-). For next unity release we will just blacklist this gpu from caching shaders, but for now the better workaround would be to add

before loading new level.
This will clear shader cache effectively forcing to recompile shaders (sure, if you keep shader object alive then no need to recompile, so keeping sphere/its material around will help too ;-))
Hope this makes sense 8)

Hi Alexey, your resolution work great, thank you very much.
You are so handsome, you are so smart!

is there any way for me to detect this GPU, or is there a list of them i can look for, or do i just have to suck it up and make it slower on all devices?

Is the fix for this in 4.1.5, the recently released version or do we still need to do this?

no, it will be out with 4.2

So, while this does seem to fix the exploding mesh issue, on some devices (ie HTC Incredible), we are experiencing a slew of texture issues. Sometimes random things render black, or as a tester puts it “corrupt” or “glitched”. This also occurs with less frequency on the brand new HTC One, but still sometimes things appear black.

I don’t know if it’s related to this shader cache thing or not.

hm, it’s complicated issue. For now (4.2) we are disabling cache in these cases:

  • if running on pre-HoneyComb OS (we had too much of bugs in there)
  • if running on Immersion GPU (as of now all phones we tested on were buggy)
    as for HTC One - if disabling shader cache helps - please submit bug report about it (if it doesnt help - still bug report with repro project - i dont like the idea of graphical artefacts ;-))

Disabling shader cache doesn’t help (the black texture issue). i just confirmed building game in 4.0.1 makes all the black texture stuff stop happening on the HTC Incredible. will verify for HTC one in a bit. I have a submitted project that previously had “exploding meshes” which was fixed w/ the shader cache thing, i haven’t confirmed the black texture stuff happens in there yet, will do that when i can, but it might take a day or two. that is bug 544782, which is marked as closed.

  • addendum - confirmed it made the blackness stop on the HTC One as well

Question about ClearShaderCache()…
if I call ClearShaderCache, and then call Application.LoadLevelAsync(“something”); won’t the shader cache just get re-filled by rendering the current level again while the async load is happening? If so this solution isn’t going to work for those of us using this, will it?

Just to add that We’re also having problems with the shaders on Android Galaxy Nexus (4.2.2), Nexus 4 (4.2.2), Same project on Unity 4.1.2 works perfect but on 4.1.5 fails, it even crash on the Galaxy Nexus. ClearShaderCache() doesn’t helps

why do you hijack this thread then? 8)
bug report with repro project

Looks like the same problem in my game on Galaxy S i9000 (S1) with PowerVR SGX540 and with Android 2.3.6 Gingerbread. Some textures looks like broken in some conditions when i start the APK second time after shaders recompiling. ClearShaderCache() work’s good to me and solve the problem.

i just submitted a new project that reproduces the black texture issue i noted on this thread on both our HTC devices. this is now Case
549562

thanks

Did anyone find a resolution to the black texture issue. I just had this start happening to me in 4.2.1 and I can’t find a solution.

I was having similar issues with building to iOS, I tried the Handheld.ClearShaderCache(), but it did nothing. I found a workaround, after instantiation I reapply whatever shader the model is using. Not ideal at all but it fixed my issue, I also have to submit a bug report with a test scene about this as I see no mention of it happening on iOS.

A sample of the code.

if(obj.renderer != null)
		{
			for(int i = 0; i < obj.renderer.sharedMaterials.Length; i++)
			{
				if(obj.renderer.sharedMaterials[i].shader.name == "DiffuseStaticOutline")
					obj.renderer.sharedMaterials[i].shader = Shader.Find("DiffuseStaticOutline");
			}
		}