Forums - Array of texture arrays

1 post / 0 new
Array of texture arrays
alexander_1
Join Date: 4 Dec 20
Posts: 7
Posted: Fri, 2020-12-04 11:12

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

  • Up0
  • Down0

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.