HLSL's, Cg and the RenderMonkey

Which HLSL?

So, having said all that, HLSLs are clearly going to be a good thing in the future. But there are some firm requirements for HLSLs before they're going to gain wide acceptance.

The most important thing is that we have a standard HLSL with wide support from APIs and graphics card manufacturers. At the moment, there is only one option, Cg, but nVidia has publicly stated that Cg should be compatible with DX9 HLSL. On top of that, nVidia has been very aggressive in pushing for Cg to become a standard, and in claiming that all graphics card manufacturers can take part. Cg could then become the HLSL of choice for both DX9 and future iterations of OpenGL.

Sounds good, but in practice there are some very real worries that people have about this idea. The biggest worry is that nVidia will gain an unfair advantage on the opposition. Every couple of years, the next generation of cards comes along, and the manufacturers have to jump through the hoops set by Microsoft. Very often, the next set of standards is designed at the same time as the next generation of graphics cards, and it is not uncommon for graphics manufacturers to be a little bit sketchy on their support for the more complex features of the API. With DX8, we saw a slightly different model, where Microsoft set about making a very clear standard (VS/ PS), but ended up mainly talking to nVidia. When we look at the concurrent development of the Xbox, it becomes clear that Microsoft had a lot to gain by working closely with nVidia, and nVidia was way ahead of the field with its GF3 class of hardware. Sometime later, Microsoft took ATI on board to develop PS1.4, the flagship piece of technology for DX8.1.

In both cases, we saw languages that were initially only supported by a single manufacturer. With PS1.1, nVidia was clearly miles ahead of the opposition; with PS1.4, ATI seems to have had a more powerful pixel pipeline on its latest cards, so pixel shaders were extended to take full advantage of this. It's interesting that many months after the release of DX8.1 we still only have one manufacturer whose drivers support PS1.4. Overall it seems a little like the API is being developed on request for manufacturers as their new hardware becomes available. It would probably be healthier if the new standards had the full backing of all manufacturers.

Anyway, imagine a world where Cg did become the standard high level language. The APIs could still be created with general standards; it's just that Cg is the way that people access the APIs. One of the fundamental issues with this is that nVidia is a commercial company. And as with any commercial company, they have to be aiming to be the dominant force in the markets of which they are a part. So if the folks at nVidia get a chance to get one up on their opponents, it would seem silly if they didn't take full advantage of the opportunity. Where Cg is concerned, this could take a number of different avenues.

If they managed to get Cg to become a standard that everybody uses, then they own the language and can modify its specifications to match their upcoming hardware perfectly. Their opposition ends up having to match the feature set that they dictate through Cg, and nVidia will have the lead in the graphics industry for the foreseeable future.

The next possibility is that the other manufacturers all add a new feature to their graphics cards, let's call it "featureX." Now, nVidia hardware doesn't support featureX, but all developers use Cg, so unless Cg is expanded to allow access to featureX, nVidia's opposition won't get any benefit. In this case, nVidia would be an intensely stupid company to introduce featureX into Cg.

But will Cg be the next standard? Personally, I think it closely resembles the standard HLSL, mainly because it's been engineered to look just like it. The DX9 HLSL is going to be coming out fairly soon, and it's going to be part of the DX9 API. This means that it has been developed by consultation with a number of different manufacturers, and with any luck, it will prove to be as powerful and flexible as Cg. Obviously, you're not going to be able to run your DX9 shaders on OpenGL, but then, how many people develop for OGL and DX at the same time?

Cg is a nice language to get to know. It would make sense for people to become familiar with the concepts and I'd recommend that every PC graphics programmer take a look at it. But don't add Cg into your graphics engine just yet. There's always a chance that it will gain wide support across the industry, particularly if ATI and Matrox write compiler backends for their hardware as well. In fact, the compiler currently produces pixel shader code that will run on all graphics cards. But it doesn't support PS1.4, which only ATI can run at the moment. Besides, ATI has its own projects, and it seems unlikely that those in charge would hand nVidia the chance to make Cg a standard, when they can just sit back and let the DX9 HLSL become the standard instead.