# Mesa/Gallium Cell Driver

The Mesa Cell driver is part of the Gallium3D architecture.

Tungsten Graphics is leading the project. Two phases are planned. First, to implement the framework for parallel rasterization using the Cell SPEs, including texture mapping. Second, to implement a full-featured OpenGL driver with support for GLSL, etc. The second phase is now underway.

## Source Code

The latest Cell driver source code is on the `gallium-0.2` branch of the Mesa git repository. After you've cloned the repository, check out the branch with:

       git-checkout -b gallium-0.2 origin/gallium-0.2

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`. To build in debug mode, run `make linux-cell-debug`.

To use the library, make sure `LD_LIBRARY_PATH` points the Mesa/lib/ directory that contains `libGL.so`.

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

      OpenGL renderer string: Gallium 0.2, 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 September 2008, the driver supports smooth/flat shaded triangle rendering with Z testing and simple texture mapping. Simple demos like gears run successfully. To test texture mapping, try progs/demos/texcyl (press right mouse button for rendering options).

Runtime/dynamic code generation is being done for per-fragment operations (Z test, blend, etc) and for fragment programs (though only a few opcodes are implemented now).

In general, however, the driver is rather slow because all vertex transformation is being done by an interpreter running on the PPU. Programs with many vertices or complex vertex shaders will run especially slow. This will be addressed in the future.

## 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

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.