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?
Comments Locked

109 Comments

View All Comments

  • just4U - Wednesday, February 4, 2009 - link

    While there might be some programs out there that definitely do take advantage of 8G of ram.. I haven't noticed that for Vista. It seems to hit a sweet spot at 4Gigs (or 3.3 for 32bit) I don't think 2Gigs of ram is optimal for Vista at all tho, and always push for 4 with all my builds.
  • dzmcm - Tuesday, February 3, 2009 - link

    Do yourself the biggest favor and Google kat mouse. I used ubuntu for a while and got spoiled by the mouse wheel functionality. This little program will allow your to scroll windows not in focus. And it adds extra functionality to the middle mouse button (which I just dissable). Plus you can set up per application rules.
  • SoCalBoomer - Monday, February 2, 2009 - link

    Fail. Sigh.

    A: 2Gigs works great. 3 Works FINE. 4 works happily with 64.
    B: DECENT video cards work fine. By Decent, I mean anything in the past couple of years - nVidia 7xxx cards, for instance. PCI vid cards? Prolly not. . .
    C: Why not just do it within Windows? UAC is easy to turn off. Windows Defender actually works okay. Readyboost doesn't do anything if you don't turn it on, etc.

    "Nothing like Ubuntu though" - true. I have Ubuntu on my laptop (although it's got Win7 on it and is a TON more functional now) but then Ubuntu doesn't have ANY common use programs written for it - Open Office is about it and . . . much as I like it, it's missing stuff that I use every day on my desktop.

    Games? Well, yes, but there are things other than games - like Office. . . yeah, you know, that behemoth office suite that controls the world? Yeah, not necessarily my fav (except for OneNote - which is awesome) but you gotta do it.


    You can't make your mouse work the way you want and THEREFORE Vista fails? Dude. . . epic fail.
  • stmok - Saturday, January 31, 2009 - link

    Vista IS a marketing failure.

    * It failed to get massive adoption as expected by Microsoft. A good majority of people and businesses are sticking with XP. Go and actually search for world wide statistics, and you'll see for yourself.

    * No matter how much Microsoft spent on marketing (see Seinfield+Gates ads and Mojave), it never caught on...Viral and deceptive marketing don't work.

    * Why do you think the next one is called "Windows 7" (even though you can basically call it Windows Vista Second Edition). Simple. The name "Vista" is a marketing failure. Its kryptonite to the Windows brand name. That's why they dropped it.

    Linux works well when the user has strong motivations to learn and adopt it. When they don't, they are better off using something like Linux Mint (which has all the video codec, and Flash, etc pre-installed) or not even using Linux at all. (Which is better for all involved).

    When a user treats Linux like Windows, it just doesn't work. Hence, all the complaining about how Linux on the desktop won't happen. (Linux was never intended for the desktop. The point was to create a cheap Unix-like solution for the x86 platform).

    Many don't realise that in Linux, the people take responsibility, not a company like Apple or Microsoft. Its about getting your butt off the ground and doing things to make it happen.

    Nothing happens when all you do is sit and complain how Linux isn't this all or that. Its up to you (if you choose to), to do something about it...This is identical to life itself.
  • gochichi - Thursday, February 19, 2009 - link

    If Microsoft wants to go Windows 7 early, they need to reconsider their pricing for Vista upgraders. B/c I have 3 Vista computers and I'm unwilling to spend more than $100.00 to upgrade all 3 of them to Windows 7.

    That's $33.33 per computer as my ceiling. And I'm not going to upgrade one and not all of them. I have more than earned the right to a good price from Microsoft. If they want to charge me full price for Office 2010 (or whatever it'll be called) that's fine, but OS upgrades can't be $100+ a pop, not if Microsoft wants to change OS's every two years.

    I kind of wonder if Vista will pick up traction in the piracy circles once 7 is released. I don't even know if I'll want to upgrade period... I mean, Vista really is fine, and why fix what aint broke.

    I've tried Windows 7 and other than being unusually unstable (which is "alright" technically because it's a beta) it does offer up some decent usability improvements. I'm quite sure that most Vista users will feel like I do... namely, that we should be getting the cosmetic upgrades for free... since we're footing their bills and all. Windows 7 is just warmed over Vista... and frankly if you're excited about Windows 7 yet you "hate" Vista... you're weird b/c they're the same thing.

    Like I said, Windows 7 is UNSTABLE which given the "mission statement" is truly alarming. I mean, I'm running Windows 7 by itself (no apps installed) and yet sometimes Windows Explorer needs to restart (one of my biggest gripes (probably the only legitimate one) with Vista).

    I guess those of us even considering buying OSes separately from PCs are crazy, and now with Windows 7 we'll be even crazier (pricing pending). Hopefully Microsoft will offer us a hand so we can all leave Vista (not because it's horrible, just for uniformity) together. Otherwise, Windows 7 will probably have even worse adoption rates than Vista.

    Microsoft: Don't be greedy! Don't split your user base so much. Let me have computers with the same OS without charging me an arm and a leg. Let Vista users have access to DirectX 11 too... b/c the "gaming" community is just going to backlash and boycott 7 like they did Vista.

    We all "naturally" want the latest version of the OS, coercion isn't necessary at all.
  • x86 64 - Thursday, February 26, 2009 - link

    Nah, Vista is already easier to pirate than XP ever was. All you need is a BIOS with an SLIC table and a VLK (easily done yourself with some research). Then you activate it using Vista's Software License Service (SLsvc.exe the way big OEM's like Dell and HP mass activate PC's) and MS can't tell the difference between a bogus or a legit installation, unless they overhaul their validation methods (not likely).

    With XP you had to deal with trying to remove the WGA nagware. Also there are some WinXP Pro student editions floating around that don't need activation because they don't contain WGA. The thought was that eventually MS would ban these keys but it has yet to happen.

    I imagine Windows 7 will be just as easy as to pirate as Vista, either through a BIOS softmod or foolproof BIOS hardmod.
  • nilepez - Wednesday, February 4, 2009 - link

    WTF are you talking about? Why would MS have expected Vista to get 30 or 40% market share after 2 years?

    For all the BS that XP is God and sold like gangbusters out the door, a little research shows that XP had less than 40% market share in 2005

    You'd have to be a complete idiot to think that Businesses were transition to Vista quicker than they transitioned to XP.


  • swaaye - Monday, February 2, 2009 - link

    I think Vista has "failed" only because there's little reason for the vast majority of users to switch to it. It's very expensive to upgrade to it, and there's just little reason to. The fact of the matter is that for everyone that doesn't care about DX10 gaming, XP can do anything Vista can.

    Personally, I think Vista is ok. If Win 7 improves on it, there's nowhere to go but up. But I also have no dislike of XP, either, and certainly see that it has its place on every PC with <2GB RAM.
  • michaelklachko - Monday, February 2, 2009 - link

    That's a good post. Especially about Linux. Thanks!

Log in

Don't have an account? Sign up now