Running out of available Mobile Texture Samplers

I tried one of my mobile GearVR projects (that cooks fine on 4.11.2 Launcher version but goes black after some head movement) with the promoted branch from GitHub (which announces itself as 4.13; the exact commit is 93f30b6 for CL 2947560) and found some interresting shader compile errors:

[2016.04.23-15.37.38:320][563]MainFrameActions: Packaging (Android (ETC2)): UE4Editor-Cmd: [2016.04.23-15.37.38:319][  0]LogCook:Display: Cooking /Game/StarterContent/Materials/M_Ceramic_Tile_Checker -> C:/Users/BhaaL/Documents/Unreal Projects/AV_Test 4.13/Saved/Cooked/Android_ETC2/AV_Test/Content/StarterContent/Materials/M_Ce
[2016.04.23-15.37.38:320][563]MainFrameActions: Packaging (Android (ETC2)): ramic_Tile_Checker.uasset
[2016.04.23-15.37.38:329][564]MainFrameActions: Packaging (Android (ETC2)): UE4Editor-Cmd: [2016.04.23-15.37.38:320][  0]LogShaderCompilers:Warning: 1 Shader compiler errors compiling M_Ceramic_Tile_Checker for platform GLSL_ES2:
[2016.04.23-15.37.38:329][564]MainFrameActions: Packaging (Android (ETC2)): UE4Editor-Cmd: [2016.04.23-15.37.38:320][  0]LogShaderCompilers:Warning: Engine/Shaders/BasePassForForwardShadingPixelShader.usf(): Shader TBasePassForForwardShadingPSFDistanceFieldShadowsLightMapAndCSMLightingPolicyINT32_MAXLDRGamma32Skylight, VF FLandscapeVertexFactoryMobile:
[2016.04.23-15.37.38:329][564]MainFrameActions: Packaging (Android (ETC2)): UE4Editor-Cmd: 	shader uses 9 samplers exceeding the limit of 8
[2016.04.23-15.37.40:978][586]MainFrameActions: Packaging (Android (ETC2)): UE4Editor-Cmd: 
[2016.04.23-15.37.40:978][586]MainFrameActions: Packaging (Android (ETC2)): UE4Editor-Cmd: [2016.04.23-15.37.40:687][  0]LogShaderCompilers:Warning: Failed to compile Material /Game/StarterContent/Materials/M_Ceramic_Tile_Checker.M_Ceramic_Tile_Checker for platform GLSL_ES2, Default Material will be used in game.
[2016.04.23-15.37.40:978][586]MainFrameActions: Packaging (Android (ETC2)): UE4Editor-Cmd: [2016.04.23-15.37.40:687][  0]LogShaders:Warning: 	(): shader uses 9 samplers exceeding the limit of 8
[2016.04.23-15.37.40:979][586]MainFrameActions: Packaging (Android (ETC2)): UE4Editor-Cmd: [2016.04.23-15.37.40:691][  0]LogSavePackage:Display: Finished SavePackage C:/Users/BhaaL/Documents/Unreal Projects/AV_Test 4.13/Saved/Cooked/Android_ETC2/AV_Test/Content/StarterContent/Materials/M_Ceramic_Tile_Checker.uasset

The fun part is that the very same material yields the following Mobile stats on 4.11.2:

Info Base pass shader with static lighting: 109 instructions
Info Base pass shader with only dynamic lighting: 79 instructions
Info Vertex shader: 31 instructions
Info Texture samplers: 8/16
Info Mobile base pass shader with only dynamic lighting (LDR): 114 instructions
Info Mobile base pass vertex shader (LDR): 38 instructions
Info Mobile texture samplers: 8/8

and those on promoted:

Info Base pass shader with static lighting: 108 instructions
Info Base pass shader with only dynamic lighting: 75 instructions
Info Vertex shader: 42 instructions
Info Texture samplers: 8/16
Info Mobile base pass shader with only dynamic lighting (LDR): 131 instructions
Info Mobile base pass vertex shader (LDR): 49 instructions
Info Mobile texture samplers: 9/8

Where does this extra Texture Sampler come from?

This is probably closely related to my other report over here where moving a material node bumps the texture sampler count. What I did was changing the texture slightly (by scaling the UV coordinates) to make the tiles a bit larger.

With this increased sampler count, the material would not build any more.

I can’t seem to reproduce this on a newly created material, where the stats are similar and sampler counts are the same, but something must be going on there. Even when deleting all nodes from the graph, I still get a difference of +1 texture sampler being used.

Steps to reproduce (at least I guess; since I didn’t try with an empty project yet, and I won’t be able to do so until tomorrow):

  1. Create a new project with Desktop / Console and Maximum Quality settings, then add the Starter Content
  2. Open up StarterContent/Materials/M_Ceramic_Tiles_Checker
  3. Add a Texture Coordinates node, set the UV scale to 0.5 each (so the tiles get larger)
  4. Hook the TexCoords node to the Tile color and Normal Texture samplers
  5. Cook the project for Android ETC2 (or at least check mobile stats)

Hi BhaaL,

Generally working out of the master branch will not build or package at all. I typically have issues with this branch as well. We have the preview builds of 4.12 released now. Give it a shot in that build and let me know if you’re still seeing the same issue. It’s likely that the texture sampler issues you’ve reported here is the same one Andrew reported earlier with UE-30017 in the post you linked above.

Thank you!

Tim

Hi Tim,

I just tried 4.12 Preview, and it does the same. The interresting part however is not that the sampler count increases by one as in the other post (for UE-30017), but the fact that it is higher by one in total and therefore exceeds the limit of 8 samplers total. It was only in the process that I noticed the behavior when changing the materials on promoted because it failed to build properly.

Even with 4.12 Preview 1, that particular material fails to build. With 4.12 Preview and promoted, I see the following stats (after opening the material, not moving anything around):

Info Base pass shader with static lighting: 78 instructions
Info Base pass shader with only dynamic lighting: 46 instructions
Info Vertex shader: 42 instructions
Info Texture samplers: 6/16
Info Mobile base pass shader with only dynamic lighting (LDR): 119 instructions
Info Mobile base pass vertex shader (LDR): 49 instructions
Info Mobile texture samplers: 8/8

With 4.11.2, I get those stats which are well within the limits; even when I do the UE-30017 case and bump the sampler up by one (which is still fine with 8/8 mobile samplers):

Info Base pass shader with static lighting: 79 instructions
Info Base pass shader with only dynamic lighting: 50 instructions
Info Vertex shader: 31 instructions
Info Texture samplers: 6/16
Info Mobile base pass shader with only dynamic lighting (LDR): 102 instructions
Info Mobile base pass vertex shader (LDR): 38 instructions
Info Mobile texture samplers: 7/8

My point for opening this second post is: Somewhere between 4.11.2 and 4.12p1, an additional mobile sampler is being used for something that wasn’t there before, and may cause projects out there to fail shader compilation when they upgrade.

Enabling shader compilation debugging gets me the mentioned shader uses 9 samplers exceeding the limit of 8 message, even though the Mobile Stats preview only shows 8/8 at this point. Maybe the stats are wrong?

Running out of chars…

This is still related to the original issue reported with UE-30017 with the ultimate result that the material sits at 9/8 texture samplers, which in turn will prevent it from being compiled for packaging. While the methods of getting the samplers to jump up is different, there is still the same outcome.

You can see this in the Mobile Stats view. I start out with 8/8, then when I save/compile it gets 9/8. If i Set the material to Fully Rough (Material Attributes > Mobile) it goes down to 6/8, which will compile and package properly. If you uncheck this Fully Rough option again it will go back to 8/8, but then as soon as the material is saved/compiled it will jump back to 9/8.

(Open the Gif in a new window/tab if you need better quality view)

91048-texturesampler.gif

Alright, I’ll just wait for UE-30017 and report my results when that is sorted out. Thanks again, Tim!

Tim, please have this bug fixed before it’s become 2 years old soon. It’s a compiler bug which could probably mean that it may affect shader optimization as well. So far, it adds a hidden texture sampler and who knows if it adds more shader instructions too? Now using 4.18.2 my SM5 shaders using just 8 texture samplers wouldn’t compile for ES2 because it sees 9!