-
Notifications
You must be signed in to change notification settings - Fork 664
More unnecessary promotions to highp #1787
Description
Using the attached source shaders and the following optimization passes (which are lifted straight from Optimizer::RegisterPerformancePasses()), I notice several unnecessary promotions to highp.
The fragment shader uses a default precision of mediump and there are a couple of notable promotions.
Here _857 promotes the alpha component of _708 to highp but is used only in a mediump expression/assignment:
vec4 _708 = textureLod(postProcess_colorBuffer, vertex_uv, 0.0);
highp float _857 = _708.w;
// ...
float _725 = // ...
float _728 = // ...
float _748 = max(_725, _857) - min(_728, _857);
Later something similar happens:
highp float _867 = _828.w;
// _728 is mediump
bool _832 = _867 < _728;
A mediump vector is assigned to a highp vector and later mixed with a mediump vector to be stored in a mediump:
highp vec4 _876;
if (_840)
{
vec3 _846 = _821.xyz * 0.5;
// _828 is mediump
_876 = vec4(_846.x, _846.y, _846.z, _828.w);
}
else
{
// _828 is mediump
_876 = _828;
}
// _877 and _708 are mediump, but _876 is highp
_877 = mix(_876, _708, vec4(0.25));
And at the end of the shader. fragColor should be mediump but a promotion happens anyway:
highp vec4 _871 = _877;
_871.w = 1.0;
fragColor = _871;
Optimized shaders compiled back to GLSL with spirv-cross:
fragment-unnecessary-highp.vkglsl.txt
Shaders:
postprocess.frag.txt
postprocess.vert.txt
Optimization passes:
optimizer
.RegisterPass(CreateMergeReturnPass())
.RegisterPass(CreateInlineExhaustivePass())
.RegisterPass(CreateAggressiveDCEPass())
.RegisterPass(CreatePrivateToLocalPass())
.RegisterPass(CreateLocalSingleBlockLoadStoreElimPass())
.RegisterPass(CreateLocalSingleStoreElimPass())
.RegisterPass(CreateAggressiveDCEPass())
.RegisterPass(CreateScalarReplacementPass())
.RegisterPass(CreateLocalAccessChainConvertPass())
.RegisterPass(CreateLocalSingleBlockLoadStoreElimPass())
.RegisterPass(CreateLocalSingleStoreElimPass())
.RegisterPass(CreateAggressiveDCEPass())
.RegisterPass(CreateLocalMultiStoreElimPass())
.RegisterPass(CreateAggressiveDCEPass())
.RegisterPass(CreateCCPPass())
.RegisterPass(CreateAggressiveDCEPass())
.RegisterPass(CreateRedundancyEliminationPass())
.RegisterPass(CreateSimplificationPass())
.RegisterPass(CreateVectorDCEPass())
.RegisterPass(CreateDeadInsertElimPass())
.RegisterPass(CreateDeadBranchElimPass())
.RegisterPass(CreateSimplificationPass())
.RegisterPass(CreateIfConversionPass())
.RegisterPass(CreateCopyPropagateArraysPass())
.RegisterPass(CreateReduceLoadSizePass())
.RegisterPass(CreateAggressiveDCEPass())
.RegisterPass(CreateBlockMergePass())
.RegisterPass(CreateRedundancyEliminationPass())
.RegisterPass(CreateDeadBranchElimPass())
.RegisterPass(CreateBlockMergePass())
.RegisterPass(CreateSimplificationPass());