0

I'm doing some glsl fractals, and I'd like to make the calculations bail if they're taking too long to keep the frame rate up (without having to figure out what's good for each existing device and any future ones).

It would be nice if there were a timer I could check every 10 iterations or something....

Failing that, it seems the best approach might be to track how long it took to render the previous frame (or previous N frames) and change the "iterate to" number dynamically as a uniform...?

Or some other suggestion? :)

Kaolin Fire
  • 2,521
  • 28
  • 43
  • Does each iteration not take constant time? – jtbandes Sep 24 '15 at 07:25
  • Each pixel in a fractal is calculated to see if it "escapes". The color value is how many times the function was iterated before it escaped. So each pixel is going to iterate an unknown number of times (or until a bailout because of time, essentially). This all happens *each pass* of the shader. If that makes sense? If the GPU is fast enough to calculate the function 256 times in 30ms, awesome. If it's not, then I'd like to scale back.... – Kaolin Fire Sep 24 '15 at 07:35
  • 1
    It does make sense, I've written it before :) But you could just limit the number of iterations. I suppose the CPU could be responsible for checking how long the whole frame takes, if that's good enough. – jtbandes Sep 24 '15 at 07:47
  • It just feels like any CPU solution will wind up being far more complicated than a GPU solution—if a GPU solution existed. But if none does, then yes. I could ramp up the iterations from a low number (might even be a nice effect) until things seemed to stutter; or estimate from running a few frames without ramping up; or just start "slow" and scale back.... – Kaolin Fire Sep 24 '15 at 08:08

1 Answers1

1

As it appears there's no good way to do this in the GPU, one can do a simple approach to "tune" the "bail after this number of iterations" threshold outside the loop, once per frame.

CFTimeInterval previousTimestamp = CFAbsoluteTimeGetCurrent();
// gl calls here
CFTimeInterval frameDuration = CFAbsoluteTimeGetCurrent() - previousTimestamp;
float msecs = frameDuration * 1000.0;
if (msecs < 0.2) {
    _dwell = MIN(_dwell + 16., 256.);
} else if (msecs > 0.4) {
    _dwell = MAX(_dwell - 4., 32.);
}

So my "dwell" is kept between 32 and 256, and more optimistically raised than decreased, and is pushed as a uniform in the "gl calls here" section.

Kaolin Fire
  • 2,521
  • 28
  • 43