Hello,
Could you please advise the way how to fetch a texture from a texture array by the shader-generated index?
The code with the switch is four times faster than the code with the texture array index.
The performance difference is the same under Vulkan and OpenGLES.
layout(binding = 0, set = 0) uniform texture2DArray in_textures[8];
layout(binding = 0, set = 1) uniform sampler in_sampler;
#if 1
[[branch]] switch(index) {
case 0: color = texture(sampler2DArray(in_textures[0], in_sampler), vec3(s_texcoord, layer)); break;
case 1: color = texture(sampler2DArray(in_textures[1], in_sampler), vec3(s_texcoord, layer)); break;
case 2: color = texture(sampler2DArray(in_textures[2], in_sampler), vec3(s_texcoord, layer)); break;
case 3: color = texture(sampler2DArray(in_textures[3], in_sampler), vec3(s_texcoord, layer)); break;
case 4: color = texture(sampler2DArray(in_textures[4], in_sampler), vec3(s_texcoord, layer)); break;
case 5: color = texture(sampler2DArray(in_textures[5], in_sampler), vec3(s_texcoord, layer)); break;
case 6: color = texture(sampler2DArray(in_textures[6], in_sampler), vec3(s_texcoord, layer)); break;
case 7: color = texture(sampler2DArray(in_textures[7], in_sampler), vec3(s_texcoord, layer)); break;
}
#else
color = texture(sampler2DArray(in_textures[index], in_sampler), vec3(s_texcoord, layer));
#endif
HW is Samsung Galaxy Tab S7+ (Adreno 650)
OpenGL ES 3.2 [email protected] (Date 09/01/20)
Vulkan API 1.1.124