Wildly poor performance for Texture2D.Apply on some devices

I have a very simple application that does little more than write out a single 640x480 texture2d every frame, and push that down to the graphics card.

This app is for Windows only (in fact, it is only run by Mac’s running Windows via Bootcamp) and maintains a smooth 60fps on most devices except for 2 Mac’s which start out at 20fps and then slowly degrade to just 3/4fps.

I’ve updated my graphics drivers with no improvement.

I have tried forcing the texture to be a square^2 texture (1024x1024) and actually got worse performance (presumably due to pushing additional pixels).

I’m not sure what to try next. I am aware that Texture2D.Apply() is an expensive operation but getting just 4fps is an absurdly bad result for an App that does practically nothing else.

Any pointers / suggestions?

Here is my apply code:

Color[] pixels;
Texture2D texture;

void Start()
{
 pixels = new Color[640*480];
 texture = new Texture2D(640, 480, TextureFormat.RGBA32, false);
}

void Update()
{
 for (int i = 0; i < pixels.Length; ++i)
 {
   //cheap ternary operation to decide what color the pixel should be
   //similar to:
   pixels *= (player1) ? player1Color : player2Color;*

}

texture.SetPixels(pixels);
texture.Apply(); //commenting out this line returns performance to 60fps
}

Hi Tomka

FPS goes down due to only one line and it’s only texture.apply(); your for loop or your condition to set value in color array is not expensive for performance in device.

when you execute texture.Apply(); it’s actually write new texture on disk and then it’s in you game scene. if you want to performance you have to reduce size of texture.

void Start()
{
 pixels = new Color[128*128];
 texture = new Texture2D(128, 128, TextureFormat.RGBA32, false);
}

128 x 128 is highest resolution for getting good performance even iPad 1 and iPod 3G. we have used even small sized texture in our a client game for scratch effect in it’s seems good in point of view on iPad3 and iPhone5, and have good performance in point of view FPS in iPad 1 and iPod 3G.

Check this game

I found the solution to my problem.

A lerp was occuring on the player colors that would more them close to, but never quite, to 0.

The graphics card seemed to be freaking out when it started to received very-close-to-0 values. Clamping the values to 0 when they got below a certain value (0.00001) fixed the issue.

A maddening problem fixed with Holistic Programming ™