4
\$\begingroup\$

I'm experiencing something really strange on an iOS mobile device. I have 4 textures, and after some profiling it seems, that doing four separate grayscale texture reads is faster, than reading the same textures from a single packed texture:

#ifdef COMBINED_METALLIC_ROUGHNESS_AO_EMISSION_TEXTURE
    fixed4 mraeTex = tex2D(_MetallicRoughnesAOEmissionTex, IN.uv_MainTex);

    fixed metallic = mraeTex.r;
    fixed roughness = mraeTex.g;
    fixed ambientOcclusion = mraeTex.b;
    fixed3 emission = mraeTex.a * albedo;
#else
    fixed metallic = tex2D(_MetallicTex, IN.uv_MainTex).r * _Metallic;
    fixed roughness = tex2D(_RoughnessTex, IN.uv_MainTex).r * _Roughness;
    fixed ambientOcclusion = tex2D(_AmbientOcclusionTex, IN.uv_MainTex).r;
    fixed3 emission = tex2D(_EmissionTex, IN.uv_MainTex).rgb;
#endif

It seems, that the second option is faster for some reason. Isn't a single texture read supposed to be faster, than doing 4 separate texture reads? Am I missing something?

Thanks!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I too am surprised and not sure of an explanation why it would be slower. If it were just equal speed I would respond that the shader compiler saw you only wanted the r component so optimized the texture read to grab only that. But slower? Not really sure. If you don't get an answer here you might ask on the computer graphics stack exchange site. \$\endgroup\$
    – Alan Wolfe
    Nov 22 '15 at 3:17
  • \$\begingroup\$ I think I found the answer: stackoverflow.com/questions/7251772/… PowerVR says "Swizzling the components of lowp vectors is expensive and should be avoided." \$\endgroup\$ Nov 22 '15 at 3:43
  • \$\begingroup\$ Apparently .r etc is swizzling and is expensive on PowerVR platforms. \$\endgroup\$ Nov 22 '15 at 3:44
  • \$\begingroup\$ that makes sense, interesting! \$\endgroup\$
    – Alan Wolfe
    Nov 22 '15 at 3:45
2
\$\begingroup\$

According to PowerVR "Swizzling the components of lowp vectors is expensive and should be avoided". Source: https://stackoverflow.com/questions/7251772/what-exactly-constitutes-swizzling-in-opengl-es-2-0-powervr-sgx-specifically

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .