Sunday, February 21, 2010

Direct 7/11

I've never been a great fan of Direct3D 8)

The first version was incredibly cubersome and slow, but I have to admit that it has changed quite a bit, actually a lot, and often for the better.
Still, I don't like it as an API (or perhaps I generally don't like any APIs ;)

Recently I've been looking into going from DX10 (that's Direct3D 10) to DX11. I've been using "Effects".
An Effect is basically a file with vertex, pixel and geometry shaders, and it also takes care of handing graphics states, such as culling direction, texture filtering, etc).
The Effects system is very convenient to leave most of the shading stuff in the hands of the TAs, where it should be, really.

Now, one thing that is key at using multiple shaders is to have some form of global variables. For example a transformation matrix for a model.. load that matrix once and use it for all the shaders used by that model.
This was handled elegantly by an "Effect pool system" in DX9 and DX10, where one would load a base parent Effect with some common variables to be shared by all subsequent child Effects.

..but, apparently this pool system has been removed in DX11 !! (The link talks about some mythical "groups", which do not appear in any of the DXSDK samples, nor would solve the fundamental problem of sharing globals across effects).

The Effect system was always considered an higer level/utility kind of API, and in DX11 the source code for it has become available, so much so that to use the Effects one has to explicitly compile that library.
So, theoretically, the pools concept could be hacked back in. But I wouldn't base a project on an utility API which is obviosuly not getting much attention from Microsoft anymore.

Another solution would be to explicity refer to global variables using specific registers IDs, like one does on the 360.
However this doesn't seem to work with DX11 Effects, and looking into the code, it seems that the specified registers aren't really used (ouch).

The official answer however seems to be that one should simply compile all Effects into one big-ass megaeffect (perhaps by using includes).
This is one of the ugliest non-solutions to the problem. It's especially bad for the developmet phase where one may want to just tweak a few Effects on the fly, without having to recompile some monster file for every little change.

What bothers me is also how the new shading system is preoccupied with dynamic linkage and inheritance.. I mean, get the simple stuff working first, and worry about the OOP fanciness later, if there is any real need for it !

Frustrating... and another reason to make my own shader compiler and renderer.. power to the programmers ! Say NO to those closed-source APIs !!

wooooooo
P.S. See also my questions on the XNA forum.