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

  • Havor - Saturday, January 31, 2009 - link

    DX10 is Vista only ware XP and 98SE/win2k shared a common DX

    And yeah XP was Win2K but it had better gaming support then W2K so there was no reason not to use XP over W2K, and only very old games gave some problems whit XP over 98SE.

    Ware Vista almost had no RL benefits over XP just a high resource hog and steep learning curve.

    If people could had a those between XP and vista i think Vista Nr's would have bin 75% lower

    Other then DX10 and x64 there is no reason for me to go to Vista, so i will wait for Win7 and upgrade to i7/i5 till then my X2 6000+ and XP sp3 will do
  • michal1980 - Friday, January 30, 2009 - link

    i agree with most of your logic. And it makes sense. It didn't feel right with the rest of the article though.

    I will however disagree with it being compared to Win ME.

    Win ME was just junk, unstable, worthless, and never improving. And while vista had teething issues, alot of it was due to a huge shift in the actual OS.

    I haven't tired 7 yet, but from all I read,it seems like vista re-tuned. However I doubt Win7 could have ever gotten to where it is without Vista. Vista was a trail by fire, and in most cases it made it. A huge problem early on was hardware specs to run it were set too low, and it was hell for people on cheap low end hardware.

    My experance has been overall very postive, esspically when I moved to 4gb's of ram. Driver problems now are minimal (x64), and no matter how stable XP ever was. IMHO, and in my experance, vista has been leaps and bounds more stable. I can't recall having an OS crash/lock up that required a reboot. If not for hardware changes/updates, my vista box would never reboot.
  • Havor - Saturday, January 31, 2009 - link

    The compering to ME holds up some bid, do vista is not as bad as ME was.

    How ever on my computer club there was a 100% return to 98SE ore win2k, most users(70%) here that run dual-boot Vista/XP machine, returned to XP after trying Vista for a wile (me included)

    And there has never bin Any love for the OS especially compared to XP.

    The bigger problem for dev. is that DX10 is Vista only, and there are way to many XP machines out there to develop DX10 only games, so from a dev. point of view Vista was/still is the next ME.
  • just4U - Wednesday, February 4, 2009 - link

    WinME is what Vista will eventually be compared to no matter what. I had less problems with WinME then I did with 98, or 95 but it got a bad rap.. Nowadays people just all say it was crap. Im sure 5-7+ years from now they will say the exact same thing about Vista. (shrug) Reply
  • marsbound2024 - Friday, January 30, 2009 - link

    I agree with what you have said. Microsoft had years to develop Vista where previously its OS releases came within two years of each other. It should have been optimized at the very least and we have seen that it is resource-intensive and one might even say "bloated." While Vista does work and I rather like working with Vista 64-bit, I think it should have been more than what it is for having such a lengthy development timeframe. While many of us superbly informed on computer operating systems and application support, the average consumer seems to really dislike Vista. From UAC to horrible startup times on occasion (usually due to services such as Cyberlink), to the network connectivity problems that seem to be related to IPv6 and the fact that it used to bring budget systems to their knees (when they were manufactured with the purpose of running Vista), most people have a bad taste in their mouths from running Vista. Vista had a lot of promise on the table from what was on paper, but in execution it simply generated more headaches than it should have. Windows 7 should hopefully be getting back to what an operating system should be: streamlined GUI with robust, yet optimally programmed features that range from security to file management on NTFS. Reply
  • srp49ers - Friday, January 30, 2009 - link

    The vista comments seemed out of place considering the tone of the rest of the article. Reply
  • Cuhulainn - Friday, January 30, 2009 - link

    Agreed. Even if you think it sucks, give the reasons related to the article. I would like to know what issues there are between Vista/DirectX, as I am a current user. Rather than being told that what I am running sucks, tell me what is wrong with it, or what is right with 7 that is an improvement over Vista.

    That being said, I have little to no knowledge of these things and still found this to be an interesting read. Much appreciated.
  • Staples - Saturday, January 31, 2009 - link

    And the fact that a year ago, most people who said that Vista sucks are ones who unsurprisingly never actually used it. When someone says Vista sucks, I always think there is a high probablility that they are someone who has never used it (and therefore stupid for saying something like that). Anyway, I have been using Vista since it came out and except for the fixes which made it use less resources, there never has been anything wrong with the OS despite what the legion of "I read it on the internet so it must be true" people would have you believe. Seems like the majority of geeks thought it sucked without having ever used it which is just idiotic. When I realized this, it was sad to know how gulible people really are. Reply
  • ssj4Gogeta - Friday, January 30, 2009 - link

    It will be great if MS releases DX11 for XP. I multi-boot XP and Vista and Ubuntu. I think I'll replace Vista with Win 7 and not XP.

    By the way, why haven't we heard anything about Larrabee? Intel said that the first samples would be ready by the end of 2008. It seems to me like it will be a revolutionary step in graphics computing.
  • Ryan Smith - Friday, January 30, 2009 - link

    It won't happen, it can't happen. DX10 goes hand-in-hand with a massive rearchitecting of GPU threading and memory management, which is why we transitioned from the XPDM to WDDM for Vista. You can't backport that kind of stuff, it's a fundamental change in how the OS addresses the GPU and allocates work & resources for it. Reply

Log in

Don't have an account? Sign up now