Ghost From the Past: DirectX

Earlier this month, gamers growled on message boards on the supposed death of DirectX. Microsoft soon released a clarification, saying that DirectX is not dead, though Microsoft’s wording left some people miffed.

This is as good a time as any to describe what DirectX is, why it came to be, and why you should care.

Origins

Before the Windows NT kernel was mainlined into commodity desktops, Microsoft Windows was basically a layer of code on top of MS-DOS. Prior to Windows 95, that layer was thin and (even more) unstable. Game programmers preferred to code for MS-DOS in order to avoid this instability and because programming for it was familiar. But there was yet another reason for avoiding early versions of Windows; those programmers wanted to take advantage of a loophole that Microsoft needed to close.

As far as 16-bit operating systems go, MS-DOS was not sophisticated. Never mind Unix; the Amiga, the early Macintosh, the Atari ST, GEOS, and other operating systems put Redmond to shame. But there was one saving grace to MS-DOS’ shortcomings. With its lack of memory protection, coders could bypass the native functions of the system and take complete control of the hardware. Hackers like Michael Abrash beat the CPUs for their cycles with their bare hands. They needed every trick that they could get in order to get acceptable performance out of computers that were officially meant for business applications. Along with the demoscene, this was the golden age of assembly language hacking. In their tutorials, these hackers emphasized “direct control” of the hardware.

The Price of Direct Control

The loophole that allowed this age of legends had a price. The slightest error could crash the computer and force a reboot since the operating system wasn’t there to enforce any bounds-checking. Combine this with the fact that those games needed every spare cycle that was available and the result was a computer that could not multitask. One of the reasons why Microsoft made Windows was to bring multitasking to the PC. Reconciling this requirement with the need to be backwards-compatible with MS-DOS applications accounts for some of the reason for Windows’ early instability.

The loophole had another price. Direct control of the hardware meant that programs would only work on the hardware configuration for which they were written. So if the developers of the latest blockbuster game hadn’t code that game for your graphics card, then you were out of luck. Programming “on the bare metal” like this even affected business applications. One of the selling points of WordPerfect was the large number of printer drivers that were included in the distribution disks. That’s right. If the programmers took “direct control” of the machine, then applications needed their own device drivers.

Microsoft Had a Plan

In order to have multitasking, Microsoft needed Windows to be the one mediator between user programs and the hardware. Microsoft also needed to give user programs a way to access the hardware in a uniform way so that developers wouldn’t have to write their own device drivers for umpteen graphics cards just to get reasonable performance. Those are, of course, the things that a modern operating system is supposed to do. But that meant that game programmers had to give up some of that “direct control.”

So Microsoft introduced a set of APIs to enable playback of sound, music, and animation. To allay the fears of the hardcore assembly language coders, Microsoft made those APIs low level enough that they could market them with the word “Direct” in their names. They were called DirectDraw, Direct3D, DirectMusic, DirectSound, DirectPlay, and so on. Everyone called them DirectX for short. Soon after that, when people said “DirectX,” they usually meant just the 3D API, Direct3D.

But there was a problem.

Here Comes OpenGL

Making Windows good for games was not a high priority. The PC was mostly a “business machine.” Microsoft was still fighting IBM over control of the platform (see the history of OS/2). The developers of DirectX only had a few months to get it ready for release on September 1995. This shows in the quality of early releases of DirectX. In particular, the fact that Microsoft hadn’t originally written all of it.

Since there was so little time to finish it, what became Direct3D began as a 3D API called Reality Lab. Microsoft bought it from the parent company RenderMorphics, and made it the basis of Direct3D.

Everybody hated it. Everybody. Direct3D was based on a programming model called an “execute buffer” that was loved by Microsoft and absolutely no one else. Graphics card vendors wouldn’t implement it in hardware. It was very awkward to program for. No one wanted it.

John Carmack of id Software opted to use the OpenGL API, instead. OpenGL was based on the native 3D capabilities of the Irix workstations of Silicon Graphics, Incorporated. Id Software, of course, was the maker of Quake and other bestselling games. Carmack’s backing of OpenGL gave it a huge following among game makers, especially after everyone saw the superior performance of Id’s Quake engine.

Fast Forward

Since OpenGL was so much better, then you may be wondering why Direct3D survived. You may also wonder why it thrives today. The answer boils down to politics. OpenGL started as fork of SGIs proprietary graphics subsystem. Silicon Graphics had embarrassed a number of incumbents in the high-end graphics workstation market and those incumbents were gaining on them. So SGI made OpenGL an open standard. Being an open standard, it is governed by a committee. Several of those committee members are representatives of corporations that compete with each other (including some of the incumbents that SGI had embarrassed). This means that there are conflicts of interest, back stabbings, and other acts of petty corporate politicking that make life worth living to suit-wearers who hold MBAs.

DirectX, on the other hand, is entirely the creature of Microsoft. Microsoft only has to please itself and developers (and, by extension, gamers). Microsoft has done a great job of improving DirectX. Granted, they had nowhere to go but up. The OpenGL standards committee, by contrast, has made decisions that have irked some people no end.

Conclusion

What does this mean to you? Unless you’re a developer, you can ignore it. Microsoft has assured everyone that DirectX will be with us for a long time to come. The whole OpenGL versus DirectX war gave a lot of nerds a reason to vent on Slashdot, but it’s mostly settled down, now. It used to be that graphics cards only supported OpenGL. Now, nearly all graphics cards support Direct3D, as well. Play games with confidence.

Useful Links

Aside from the WikiPedia pages on DirectX and OpenGL, the following links were helpful in the writing of this article:

http://programmers.stackexchange.com/questions/60544/why-do-game-developers-prefer-windows

http://news.ycombinator.com/item?id=4134426

http://news.ycombinator.com/item?id=5124476