Going Deeper: The DX11 Compute Shader and OpenCL/OpenGL

Many developers are excited about the added flexibility of the Compute Shader (also referred to as the CS). This addition to the pipeline steps further from a render-centric API and enables more general purpose algorithms. We see added flexibility in both the type of operations that can be preformed on data and the type of data that can be operated on.

In other pipeline stages, we see limitations imposed that are designed to speed up execution that get in the way of general purpose code. Although we can shoehorn general purpose algorithms into a pixel shader program, we don't have the freedom to use data structures like trees, sharing data between pixels (and thus threads) is difficult and costly, and we have to go through the motions of drawing triangles and mapping solutions onto this.

Enter DirectX11 and the CS. Developers have the option to pass data structures over to the Compute Shader and run more general purpose algorithms on them. The Compute Shader, like the other fully programmable stages of the DX10 and DX11 pipeline, will share a single set of physical resources (shader processors).

This hardware will need to be a little more flexible than it currently is as when it runs CS code it will have to support random reads and writes and irregular arrays (rather than simple streams or fixed size 2D arrays), multiple outputs, direct invocation of individual or groups of threads as per the programmer's needs, 32k of shared register space and thread group management, atomic instructions, synchronization constructs, and the ability to perform unordered IO operations.

At the same time, the CS loses some features as well. As each thread is no longer treated as a pixel, so the association with geometry is lost (unless specifically passed in a data structure). This means that, although CS programs can still use texture samplers, automatic trilinear LOD calculations are not automatic (LOD must be specified). Additionally, depth culling, anti-aliasing, alpha blending, and other operations that have no meaning to generic data cannot be performed inside a CS program.

The type of new applications opened up by the CS are actually infinite, but the most immediate interest will come from game developers looking to augment their graphics engines with fancy techniques not possible in the Pixel Shader. Some of these applications include A-Buffer techniques to allow very high quality anti-aliasing and order independent transparency, more advanced deferred shading techniques, advanced post processing effects and convolution, FFTs (fast Fourier transforms) for frequency domain operations, and summed area tables.

Beyond the rendering specific applications, game developers may wish to do things like IK (inverse kinematics), physics, AI, and other traditionally CPU specific tasks on the GPU. Having this data on the GPU by performing calculations in the CS means that the data is more quickly available for use in rendering and some algorithms may be much faster on the GPU as well. It might even be an option to run things like AI or physics on both the GPU and the CPU if algorithms that always yield the same result on both types of processors can be found (which would essentially substitute compute power for bandwidth).

Even though the code will run on the same hardware, PS and CS code will perform very differently based on the algorithms being implemented. One of the interesting things to look at is exposure and histogram data often used in HDR rendering. Calculating this data in the PS requires several passes and tricks to take all the pixels and either bin them or average them. Despite the fact that sharing data is going to slow things down quite a bit, sharing data can be much faster than running many passes and this makes the CS an ideal stage for such algorithms.

A while back we took a look at OpenCL, and we know that OpenCL will be able to share data structures with OpenGL. We haven't yet gotten a developer's take on comparing OpenCL and the DX11 CS, but at first blush it seems that the possibilities opened up for game developers and graphics processing with DX11 and the Compute Shader will also be possible with OpenGL+OpenCL. Although the CS can be used as a general purpose hardware accelerated GPU computing interface, OpenCL is targeted more at that arena and its independence from Microsoft and DirectX will likely mean wider adoption as a GPU compute language for general purpose tasks.

The use of OpenGL has declined significantly in the game developer community over the last five years. While OpenCL may enable DX11 like applications to be written in combination with OpenGL, it is more likely that this will be the venue of workstation applications like CAD/CAM and simulations that require visualization. While I'm a fan of OpenGL myself, I don't see the flexibility of OpenCL as a significant boon to its adoption in game engines.

Drilling Down: DX11 And The Multi-Threaded Game Engine So What's a Tessellator?


View All Comments

  • DerekWilson - Saturday, January 31, 2009 - link

    These figures include "shipped" versions of Vista that people chose to downgrade to XP. It includes systems that came preinstalled, even the "vista capable" systems that people might have chosen to replace with another OS out of the box or after it didn't deliver what they expected.

    No Vista isn't as bad now as it was at first, but that first impression really does matter and significantly affected DirectX10 adoption, development efforts, perception, and all sorts of things that have a lasting impact on the entire industry.

    Also, MS designed DX10 to be tied to the WDDM when they didn't need to in order to expose functionality for developers to use the new features of hardware. They didn't need to do this at all, and we could have had DX10 and DX11 on XP if MS hadn't wanted to push sales of Vista through needless requirements that tied future versions of DirectX to it.
  • michal1980 - Friday, January 30, 2009 - link

    Vista bigger problem was Image. It started a bit rocky, and by the time it was 'fixed' people allready wrote it off. M$ was/is smart enough to know a damaged brand, and instead of releasing Vista Sp2, they slapped a new name on it.

    I do have a bit of a chip on my should about win7, from what I read, i'd love to upgrade.

    But good lord, I own 2 ultimate, and 3 home preimum licenses. I hope M$ has some nice deals for vista users, because i'm going to feel a bit ripped of having an OS with a 2 year life span.
  • frozentundra123456 - Sunday, February 1, 2009 - link

    I agree that it is a ripoff to have an OS with such a short life span. Is the "planned obsolescence" in the worst form?? Reply
  • LeStuka - Saturday, January 31, 2009 - link

    I read somewhere that Vista Ultimate owners will get a free/reduced price upgrade.. Not sure how reputable that is (my memory is a bit hazy on it) but is defiantely worth some research. Reply
  • marsbound2024 - Friday, January 30, 2009 - link

    Let me start off by saying I was enthralled by this article. Very well detailed and well explained. There were a few occasions, however, where I wished for more explanation (or maybe my eyes skipped over an explanation you might have provided earlier in the article). I will admit, I am not as highly inclined on software as many people might be here. I am a great deal more interested in hardware usually, but when it comes to APIs such as DirectX and operating systems and their features such as Windows 7, then I am usually engrossed in those. What exactly are LODs and what is OOP constructs and what is HLSL? Now admittedly I can use Google to find all of this out, but it would be nice to have this consolidated into your article (if it was, but my eyes skimmed over that part, then I apologize; though I read your article pretty much word for word).

    There are a few grammatical errors such as instead of "that" you put "than" or maybe it was "then" and you said "a architectures" or something to that effect. This doesn't really matter but I thought I'd throw that out there.

    I'd really like to know if the upcoming generation GPUs in June/July will make use of DirectX11? I suppose this depends on how quickly Microsoft can a good, full-featured SDK out there, perhaps. Also, albeit a bit off-topic, but any thoughts on when Windows 7 might be released to consumers? Are we still thinking later this year in time for the holiday season or the old Microsoft "by the first quarter of 2010" or whatever it was (i.e.: January possibly)?
  • DerekWilson - Saturday, January 31, 2009 - link

    Sorry about leaving out some definitions there ... I went back and added in some explanation of what HLSL and OOP stand for and what LOD is.

    We suspect that the first round of hardware that comes out after Windows 7 is available will support DX11 ... We haven't had confirmation on that from either vendor yet, but that's our strong feeling at this point.
  • michal1980 - Friday, January 30, 2009 - link

    Author just seems to have a huge chip on his shoulder.

    good article, that quite frankly left a bad taste in my mouth because of the unexplained, and un-needed vista bashing
  • tommy2q - Saturday, January 31, 2009 - link

    vista 64 bit has been great for me. it's faster than xp pro on my computer and more stable. Reply
  • DerekWilson - Friday, January 30, 2009 - link

    I don't have a problem explaining myself, I just thought it was unnecessary -- I apologize.

    It's not that I have a chip on my shoulder, it is simply a fact that Vista had and has problems that caused issues with the uptake of DX10. It's not a personal problem, it's just information.

    First, obviously an OS upgrade was required to get DX10. People were turned off to this idea because of initial problems that were resolved after a period of time. But much damage was done.

    For the first year of it's life, many drivers and applications were unstable and buggy, especially sound and graphics and especially under 64-bit Vista. MultiGPU support had its own problems, but that's a whole other barrel of monkeys. When SP1 hit most of our problems were resolved.

    Performance for many tasks are decreased under Vista, though, again, much of this has been fixed. But the problem is that uptake of Vista was damaged because of this, especially among hardcore gamers and especially because there weren't any DX10 only titles or Vista only titles that were compelling (and no, Lost Planet was not compelling). Also, in cases like Crysis, DX10 incurs a huge performance hit and many gamers prefer to run DX9 anyway for the higher performance.

    OS X also made huge strides and is a terrific OS. For usability, people have started to realize they had a choice in large part because Vista failed at the beginning to deliver what it promised. And choice is good.

    MS recognized that they had a problem and implemented and extended again and again downgrade options to Windows XP for customers who were unsatisfied with Vista. They have significantly invested in and sped up development on Windows 7 in order to deliver an option that will regain customer interest. They've also dumped tons of money into ad campaigns like mojave and seinfeld.

    Vista is not a failure in terms of total sales or market penetration as compared to other pieces of software, but it absolutely is compared to other major milestone MS OS releases. They needed to deliver a WinXP and they delivered a WinME ...

    The degree to which people hung on to XP and the problems with Vista have certainly caused a delay in a full transition to DX10 programming by game developers.

    Vista failed to be truly viable vehicle for pushing forward graphics technology on the whole not because it totally sucks, is lame, or any one person doesn't like it. It failed on its merits because it didn't come out of the gate as strong as it needed to be.

    Certainly many developers have done some cool things with DX10. Which is great. But building a platform where people like the Beta more than their current stable OS is a good start to getting people interested in dropping Vista for Windows 7 and inspiring hold outs to finally move from Windows XP to Windows 7.

    I wasn't trying to "bash" vista. I feel like I was just calling it like it is.
  • archer75 - Saturday, January 31, 2009 - link

    All of the "problems" with Vista you mentioned actually aren't even Microsoft's or Vista's fault. Drivers are applications are the responsibilities of 3rd parties. It is they who dropped the ball. Most companies grew up with XP and that is what people learned to write drivers and apps for. With the necessary change to the driver model in Vista these people had to learn a new way of writing drivers. A necessary change but it took time.

    Also everything that SP1 fixed, was fixed long before SP1. All of those updates were available on the knowledge base. All SP1 did was put them in one neat little package. People like myself had those updates long before SP1.
    I also run x64 and have since beta. My system has had quality drivers on day 1 and I never had any stability issues either.

    Obviously an OS upgrade was required for DX10. And why wouldn't it be? Do you give away all of your new features in your old products? What company does that? You put new features in new products. Apple does this. Hell, ilife 09 is leopard only. They force you to upgrade regularly.

Log in

Don't have an account? Sign up now