Reputation: 41
I'm trying to write an video filtering application using GPUImage on iOS. In general, my processing chain looks like:
GPUImageVideoCamera->CustomFilter->[CPU processing block]
where the CPU processing block looks like:
{
glReadPixels(...)
do_some_processing()
}
The current performance I get on iPad is 5-7 FPS, which I'm trying to improve.
I'm aware of GPUImageRawDataInput
which should be used instead of glReadPixels
, but my question is whether there is a way/code-example to parallelize the CPU and the GPU work such that while the GPU is processing frame N, the CPU will process Frame N-1.
Upvotes: 1
Views: 751
Reputation: 170317
I know you already know this, but I still recommend using the GPUImageRawDataOutput to extract the raw pixel data. The reason for this is that you can set the newFrameAvailableBlock
to be triggered every time a new video frame is available. This block is run from the video processing queue, which operates on a background thread. I use a background queue for the video processing, which already parallelizes some of the work between the CPU and GPU.
Within this block, you could then fire off another asynchronous block on a second background queue. That would then cause this CPU-bound block to run in parallel with the GPUImage queue.
However, if GPUImage can process frames faster than your CPU-bound processing, you're going to need to apply some sort of rate limiting in order to prevent CPU blocks from building up in your second queue. I use a dispatch semaphore to drop frames when my processing can't keep up.
Unless you're running a very intensive shader in GPUImage, you might not see much in the way of a performance gain by parallelizing this, but it's easy enough to try.
Upvotes: 3