Saturday, December 6, 2008

iP* programming tip #5

Let's look today at the "pixel shader" level of the hardware functionality. The iPhone Application programming guide says that the application should not use more than 24 MB for textures and surfaces. It seems like those 24 MB are not in video card memory. I assume that all of the data is stored in system memory and the graphics card memory is not used.Overall the iP* platform supports

The maximum texture size is 1024x1024

2D texture are supported; other texture formats are not

Stencil buffers aren’t available

As far as I know stencil buffer support is available in hardware. That means the Light Pre-Pass renderer can only be implemented with the help of the scissor (hopefully available). As a side note: one of the other things that do not seem to be exposed is MSAA rendering. With the unofficial SDK it seems like you can use MSAA.Texture filtering is described on page 99 of the iPhone Application programming guide. There is also an extension for anisotropic filtering supported, that I haven't tried.

The pixel shader of the iP* platform is programmed via texture combiners. There is an overview on all OpenGL ES 1.1 calls at

13 comments:

My understanding was that the iPhone used the PowerVR chipset (same as on the Dreamcast), which at least historically never supported stencil buffers, but also it doesn't support depth buffers as it uses planar intersection to determine visibility, and at least in most cases of stencil buffer usage, planar intersection can produce the same (or at least very similar) results, but at least in the case of OpenGL it was up to the drivers to convert stencil operations to planar intersections. I can see them removing this from the OpenGL driver in order to reduce the complexity and memory consumption.

I do know that several games on the Dreamcast did planar-intersection shadow volumes (such as Sonic Adventure 2 and Shenmue) so if there's a way to get at the lower-level PowerVR functionality it should be possible to at least do some limited stencil-type effects.

No problem. Keep in mind that I only know this from secondhand information and never did any Dreamcast programming myself, so I have no idea what implications this brings to e.g. multipass rendering and the like. It's also quite possible that current-generation PowerVR chips just use an ordinary zbuffer.

I don't know for sure whether this will work on iP*, but we used to use a combination of Cg and nvparse to make it easier to write texture combiners code. You could then write a simple Cg pixel shader, which most people are already familiar with, and compile it using the 'fp20' profile before feeding it through nvparse. Although this tech is all NVIDIA it works just fine on other cards that support register combiners, since both Cg and nvparse are GPU agnostic. The converseion isn't free of course, but it's very convenient.

Following POWERVR's MBX documentation there must be a stencil buffer. It is quite nicely located after the tile buffer and before everything else. Judging from the picture it looks like a huge speed-up.

Hm, where do you see that? I can't find the MBX documentation specifically but every Google hit I get for "powervr mbx stencil" says it doesn't have one, aside from a couple of press releases from 2001 which say it will.

Figure 12 doesn't refer specficially to a stencil buffer, but rolls "stencil/depth test" together. I have a feeling they're waving their hands over the way that intersection-based culling works, and just describing the planar-intersection method as equivalent to stencils.

I mean, when it comes down to it, a stencil test at its most basic is just a way of tracking CSG operations on primitives - the PowerVR architecture just does the CSG up-front, and they (probably) call this "stencil" in the diagram to explain the equivalence.

It's telling that there's no other mention of stencil anywhere else in the documentation. So I'm still pretty much positive that there's no stencil buffer, and that translating stencil operations to deferred/in-place CSG is up to the driver.

Google+ Followers

About Me

Wolfgang is the CEO of Confetti. Confetti is a think-tank for advanced real-time graphics research and a service provider for the video game and movie industry.
Before co-founding Confetti, Wolfgang worked as the lead graphics programmer in Rockstar's core technology group RAGE for more than four years.
He is the founder and editor of the ShaderX and GPU Pro books series, a Microsoft MVP, the author of several books and articles on real-time rendering and a regular contributor to websites and the GDC. One of the books he edited -ShaderX4- won the Game developer Front line award in 2006.
Wolfgang is in the advisory boards of several companies. He is an active contributor to several future standards that drive the Game Industry.
You can find him on twitter at