# Mesa/Gallium Cell Driver

The Mesa Cell driver is part of the Gallium3D architecture. Tungsten Graphics did the original implementation of the Cell driver.

## Source Code

The latest Cell driver source code is on the master branch of the Mesa git repository.

To build the driver you'll need the IBM Cell SDK (version 2.1 or 3.0). To use the driver you'll need a Cell system, such as a PS3 running Linux, or the Cell Simulator (untested, though).

If using Cell SDK 2.1, see the configs/linux-cell file for some special changes.

To compile the code, run `make linux-cell`. Or to build in debug mode, run `make linux-cell-debug`.

To use the library, make sure your current directory is the top of the Mesa tree, then set `LD_LIBRARY_PATH` like this:

      export LD_LIBRARY_PATH=$PWD/lib/gallium:$PWD/lib/

Verify that the Cell driver is being used by running `progs/xdemos/glxinfo` and looking for:

      OpenGL renderer string: Gallium 0.3, Cell on Xlib

## Driver Implementation Summary

Rasterization is parallelized across the SPUs in a tiled-based manner. Batches of transformed triangles are sent to the SPUs (actually, pulled by from main memory by the SPUs). Each SPU loops over a set of 32x32-pixel screen tiles, rendering the triangles into each tile. Because of the limited SPU memory, framebuffer tiles are paged in/out of SPU local store as needed. Similarly, textures are tiled and brought into local store as needed.

## Status

As of October 2008, the driver runs quite a few OpenGL demos. Features that work include:

- Point/line/triangle rendering, glDrawPixels
- 2D, NPOT and cube texture maps with nearest/linear/mipmap filtering
- Dynamic SPU code generation for fragment shaders, but not complete
- Dynamic SPU code generation for fragment ops (blend, Z-test, etc), but not complete
- Dynamic PPU/PPC code generation for vertex shaders, but not complete

Performance has recently improved with the addition of PPC code generation for vertex shaders, but the code quality isn't too great yet.

Another bottleneck is SwapBuffers. It may be the limiting factor for many simple GL tests.

## Debug Options

The CELL_DEBUG env var can be set to a comma-separated list of one or more of the following debug options:

- checker - use a different background clear color for each SPU. This lets you see which SPU is rendering which screen tiles.
- sync - wait/synchronize after each DMA transfer
- asm - print generated SPU assembly code to stdout
- fragops - emit fragment ops debug messages
- fragopfallback - don't use codegen for fragment ops
- cmd - print SPU commands as their received
- cache - print texture cache statistics when program exits

Note that some of these options may only work for linux-cell-debug builds.

If the GALLIUM_NOPPC env var is set, PPC code generation will not be used and vertex shaders will be run with the TGSI interpreter.

If the GALLIUM_NOCELL env var is set, the softpipe driver will be used intead of the Cell driver. This is useful for comparison/validation.

## Contributing

If you're interested in contributing to the effort, familiarize yourself with the code, join the mesa3d-dev mailing list, and describe what you'd like to do.