Friday, July 27, 2007

More on using GPUs to calculate physics

Just to follow up on Monday's post on using PC graphics cards to perform scientific calculations, Ryan Smith at Anandtech has an article on the status of GPU physics and dedicated physics processors for games. Note that "physics" in terms of games is rather limited in scope, largely particle effects and finite element calculations (e.g. the rag-doll motion of dead enemies) to make a game look good.

What comes out of this article is that (unlike the case of the astrophysical N-body calculations discussed previously) it appears that in terms of gaming the initial attempts for PC games to use physics processors (e.g. the AGEIA PCI card) or GPUs as physics processors (e.g. Havok's separate software package called Havok FX) have difficultly accessing the results of any calculations other than changing the display:


The second reason, and that which has the greater effect, is a slew of technical details that stem from using Havok FX. Paramount to this is what the GPU camp is calling physics is not what the rest of us would call physics with a straight face. As Havok FX was designed, the physics simulations run on the GPU are not retrievable in a practical manner, as such Havok FX is designed to be used to generate "second-order" physics. Such physics are not related to gameplay and are inserted as eye-candy. A good example of this is Ghost Recon: Advanced Warfighter, which we'll ignore was a PhysX powered title for the moment and focus on the fact that it used the PhysX hardware primarily for extra debris.

The problem with this of course is obvious, and Havok goes through a great deal of trouble in their Havok FX literature to make this clear. The extra eye-candy is nice and it's certainly an interesting solution to bypassing the problem of lots-of-little-things loading down the CPU (although Direct3D 10 has reduced the performance hit of this), but it also means that the GPU can't have any meaningful impact on gameplay. It doesn't make Havok FX entirely useless since eye-candy does serve its purpose, but it's not what most people (ourselves included) envision when we think hardware accelerated physics; we're looking for the next step in interactive physics, not more eye-candy.
Emphasis added.

Note that the CUDA software used to do the N-body simulations described by Schiveet al (astro-ph/0707.2991) package described in the is very different from the gaming-related Havok FXAnandtech article.

If you've ever worked with parallel processing yourself you'll appreciate that efficiently accessing the results of a calculation on a separate processor is the trickiest part of parallel programming, rather than actually having a calculation run on a separate processor. Even if GPU physics processing does take off (and doesn't get forgotten as the access to multi-core CPUs increases), I doubt Havok FX will see much real use before approaches closer to CUDA in nature take over.

Just for interest's sake, let us return to the issue of what kind of "physics" is dealt with in games. Here I quote from Havok's own discussion of Havok FX:

What Kinds Of Effects Does Havok FX Enable?

Havok FX enables dynamic in-game effects that are based upon rigid-body collisions and constraints – including debris, smoke, fog, and ultimately simulated liquids - but on a scale that goes well beyond the magnitude and volume of objects normally simulated in CPU-based game-play physics. By performing simulation, collision detection and rendering directly on the GPU, Havok FX avoids the transfer of large amounts of data between the CPU and GPU, enabling a level of performance of object collisions in the 1000’s occurring in real-time, without putting any additional burden on the CPU or otherwise slowing down the game.

How DoesHavok FX Work?

Havok FX supports a new type of rigid-body object called a Debris Primitive. A Debris Primitive is a compact representation of a 3D collidable object that can be processed via Shader Model 3.0 (SM3.0) in a very efficient manner. Debris Primitives can be pre-modeled as part of a game's static art content (e.g. custom/textured boulders, space junk, or collateral objects waiting for an explosive charge). They may also be generated on the fly during game play by the CPU, based on the direction and intensity of a force (e.g. brick and stone structure blown apart by a cannon blast). Once generated by the CPU, Debris Primitives can be dispatched fully to the GPU for physical simulation and final rendering - comprising a powerful blending of physics and state-of-the-art shading effects for particulate and large scale phenomenon.

No comments: