Description
  • Fix the cross compiler so half precision is supported
  • Add a project setting to specify the default precision to support on ES31. Be sure the shader version takes this setting into account.

User description:

We were profiling an Android build with Snapdragon Profiler and noticed that the profiler was reporting that no half-precision ALU instructions were present in the fragment shaders used, in other words, all ALU instructions were reported as full precision. This was unexpected as the materials in question did not have the 'Use Full Precision' setting ticked. We then checked a number of fragment shaders in the profiler, and noticed there were two precision statements present in the GLSL code: the first one trying to set the default precision to mediump and the second one forcing it to be highp.

After some investigation, we found these two statements are added to the GLSL code in the function ir_gen_glsl_visitor::run in GlslBackend.cpp. The first if statement in the function, with condition (bEmitPrecision && !(ShaderTarget == vertex_shader)), adds a precision statement aligned with the 'Use Full Precision' setting, but there's another if statement afterwards, with condition (state->language_version == 310) && (ShaderTarget == fragment_shader) && bEmitPrecision), which adds the second precision statement, this time forcing it to be highp.

To sum up: It appears that in Android builds using GLES 3.1, all fragment shaders use full precision. We are using a custom flavor of 4.18.3, but the same implementation of ir_gen_glsl_visitor::run appears to be present in vanilla 4.19 (see e.g. https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Developer/ShaderFormatOpenGL/Private/GlslBackend.cpp ). It is not a major issue for us as we can change this behavior by just removing the second if statement and invalidating cached shaders. However, we wanted to share this info to ask if this is something you are also seeing on your end, if this behavior happens to be intentional for some reason and, if that's not the case, to let you know about it so it can be addressed in the future.

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-57387 in the post.

2
Login to Vote

Won't Fix
ComponentUE - Platform - Mobile
Affects Versions4.20
CreatedApr 6, 2018
ResolvedAug 18, 2021
UpdatedAug 18, 2021