It is better to use one texture or several textures for a YUV image

This question is about OpenGL ES 2.0 (on Android), but may be more general for OpenGL.

Ultimately, all performance questions are implementation dependent, but if someone can answer this question as a whole or based on their experience, that will be useful. I also write test code.

I have a YUV image (12bpp) that I load into a texture and color conversion in my fragment shader. Everything is working fine, but I would like to see where I can improve performance (in terms of frames per second).

Currently, I actually upload three textures for each image: one for the Y component (type GL_LUMINANCE), one for the U component (type GL_LUMINANCE and, of course, 1/4 the size of the Y component) and one for the V component (type GL_LUMINANCE and, of course, 1/4 the size of the Y component).

Assuming that I can get YUV pixels in any layout (for example, U and V in separate planes or interspersed), would it be better to combine three textures into only two or only one? Obviously, the same number of bytes to click on the GPU no matter how you do it, but maybe with less texture there will be less overhead. At least it will use less texture units. My ideas:

  • If the U and V pixels were interleaved with each other, I could load them into a single texture of type GL_LUMINANCE_ALPHA, which has two components.
  • I could load the entire YUV image as a single texture (like GL_LUMINANCE, but 3/2 the size of the image), and then in the fragment shader I could call texture2D () three times on the same texture, performing a bit of arithmetic, calculate the correct coordinates, to go to 2D texture to get the correct texture coordinates for components Y, U and V.
+4
source share
1 answer

I would combine the data as few textures as possible. Smaller textures are generally a better option for several reasons.

  • Less state changes to customize the drawing call.
  • The fewer texture samples in the fragment shader, the better.
  • Shorter loading times.

Sources:

I understand that some of them are focused on more specific equipment, but the principles apply to most mobile graphic architectures.

Guidelines for working with texture data

Optimize OpenGL for Tegra

Shader Performance Optimization

  • β€œTexture snapping takes time to process OpenGL ES. Applications that reduce the number of changes they make to the OpenGL ES state work better.”

  • "In my experience, the performance of a mobile GPU is roughly proportional to the number of texture2D calls texture2D " "There are two texture loads, so the minimum number of cycles for a sub-texture element is two." (Tegra has a texture block that needs to run a loop to read a texture)

  • "makes calls to the glTexSubImage and glCopyTexSubImage particularly expensive" - ​​load operations should stop the pipeline until the textures are loaded. Faster to upload them in one download than to block a bunch of individual times.

+3
source

Source: https://habr.com/ru/post/1495842/


All Articles