Skip navigation

Søren Sandmann Pedersen, maintainer of the pixman library that is at the heart of the software rasteriser in Cairo and X, argues that with all things being equal an integrated graphics processor should never be able to outperform the main processor for rendering Cairo. Ideally, when using either the GPU or CPU, we want the memory being the rate-limiting component. On the Sandybridge processor, the memory is attached to the system agent, along with the large L3 caches, and is shared between the CPU and GPU. So he argues that any performance advantage cairo-xlib might show over cairo-image whilst using Intel graphics is really an opportunity for improvement of the rasteriser and pixman kernels. (But also bear in mind that the GPU should be considerably more efficient and be able to saturate the memory bus at a fraction of the power cost of the CPU). Using SSE2, we are indeed able to fully saturate the bus to L1, L2 and main memory for a variety of common operations in pixman. However, the bilinear scaling kernels take longer to compute than it does to write the results to memory, and so fail to completely utilize the available bandwidth. Furthermore, for a slightly more complex transformation than a simple scale and translation, we do not yet have a fast SSE2 kernel that operates directly on the destination and so must incur some extra work. If we ignore, for the time being, making further optimisations to those kernels to improve performance, we can instead ask the question: if using one SSE2 unit is not enough to saturate the memory bus, what happens if we throw more cores at the problem?

To gain the most improvement from adding threads to cairo, you need to design a rasteriser and usage model with threading in mind in. One such design is the vector renderer O by Øyvind Kolås. Despite being an experiment, it does show quite a bit of promise, but in its raw form just throwing threads at the problem does not beat using the SIMD compositing routines provided by pixman. However, it did raise the question whether we can make improvements to the existing image backend without impacting upon its immediate mode nature and so could be used by existing applications without alteration. To preserve the existing semantics, we can break up the individual composite and scan conversion operations into small pieces and feed those to a pool of threads, and then wait for the threads to complete before returning back to the application. As such we then never run the threads for very long, and risk that the overhead in thread management outweighs any benefit from splitting the operation over multiple cores.

To gain the greatest advantage from adding threads, I used a desktop Sandybridge processor (an i5-2500) for benchmarking this prototype cairo-image backend:

Comparison of multiple threads

About half the test cases regress by about 10%, but around one third are improved by 2-3x. Not bad – the regressions are unacceptable, but it does offer a tantalising suggestion that we can make some significant improvements with only a minor change. (Remember not all processors are equal, and thanks to Sandybridge’s turbo some cores are more equal than others. I tried running the test cases on a Sandybridge ultrabook, and as soon as more one core was active, the entire package was throttled to keep it within its thermal constraints. The performance regression was dire.)

Having tuned the software backend to make better use of the average resources, what can we now say about the relative merits of the integrated graphics processor?

Comparison of multiple threads and SNA

Indeed, for the cases that are almost entirely GPU bound (for example the firefox-fishbowl, -fishtank, -paintball, -particles), we have virtually eliminated all the previous advantage that the GPU held. In a notable couple of cases, we have improved the image backend to outperform SNA, and for all cases now the threaded image backend beats UXA. However, as can be seen there is still plenty of room for improvement of the image backend, and we can’t let the hardware acceleration be merely equal to a software rasteriser…

Advertisement

3 Comments

  1. Thanks for the nice charts! This for most parts confirms the results of my older test with using multiple threads to speed up pixman:

    http://comments.gmane.org/gmane.comp.graphics.pixman/2008

    At that time I came to a conclusion that it’s better to still keep multi-threaded rendering as a trump card and concentrate on single-threaded performance for now, especially considering that SSE2 backend still has a lot of room for improvement. Spawning multiple rendering threads can starve the application thread, which is not very nice and may result in worse overall experience for the users (the cairo-perf-trace, while being a great benchmarking tool, does not simulate this aspect adequately). IMHO it is better to be “green” and still provide reasonably good overall performance than hogging all the CPU cores. LLVMPipe is particularly badly behaved in this respect.

    Still there is also “offloading” factor. When we are doing client side rendering (image backend), the client calls to the pixman library relayed from cairo are blocked until the operation is complete. It might make sense to try non-blocking asynchronous rendering with one (or more) worker thread doing all the heavy-lifting job with the pixel data. This is about the only real performance advantage (when the IPC overhead does not outweight it) currently offered by doing rendering in a separate X server process with the DDX drivers having purely software backend such as xf86-video-fbdev and xf86-video-modesetting.

  2. Hi ickle,

    Could you throw up an xlib comparison?

    • What type of comparison are you looking for? At the end there I tried to show that if throw more cpu cores at the problem (in order to try and saturate memory bandwidth) performance of the CPU backend is a match for the integrated GPUs – at least on this machine with a beastly CPU and weak GPU.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: