Building a Windows Store App with C++/CX and DirectX 11

Building a Windows Store App with C++/CX and DirectX 11

posted in: Graphics | 3

I recently took the plunge and upgraded to Windows 8, primarily so that I can develop an App for the soon-to-be-launched Windows Store. I’m going to be using C++/CX and DirectX 11 (and probably XAML) with Visual Studio 2012 as my development environment.

While I’m at it I thought it might be useful to keep a log of problems (relating to DX11, C++/CX, WinRT, etc.) that I hit along the way. At the very least I hope to solidify my own understanding through elucidation, but maybe there’ll be some useful tidbits for other developers as well.

I’ll continue to update this post over the coming weeks.

DirectX 11 – Tessellation

Problem: Vertex shader won’t compile alongside hull and domain shaders. Specifically, attempting to compile results in: “error X4541: vertex shader must minimally write all four components of POSITION”

Solution: The vertex shader was being compiled against an old Shader Model.

Prior to the introduction of domain shaders, a vertex shader had to (as a bare minimum) output 2D screen coordinates (and depth values) for all 3D vertex positions it was fed. In DirectX 11, however, the domain shader can fulfill that responsibility for applications making use of tessellation (which occurs after the vertex shader phase in the graphics pipeline).

Visual Studio 2012 now compiles shaders as part of its regular build process (very cool), but it must be told which Shader Model to compile against. Using tessellation with DirectX 11 requires that the .hlsl files (including the vertex shader) be compiled against Shader Model 5.

The HLSL compiler settings can be set at the project and/or individual .hlsl file level. In either case it’s achieved by right-clicking on said item in the Solution Explorer and hitting Properties -> HLSL Compiler.

Shader Model Compile Options (Visual Studio 20120)

Problem: “E_ACCESSDENIED General access denied error” upon making Direct3D calls while a domain shader is active.

Solution: This was a bug in my C++ code. Tessellation shaders work on control point patches rather than more traditional primitives (such as triangles). The Direct3D context must be informed of such with a call to IASetPrimitiveTopology like so:


3 Responses

  1. Chris Fisher
    | Reply

    “Visual Studio 2012 now compiles shaders as part of its regular build process (very cool)”

    That is pretty cool! How have you found VS2012 so far?

    • Karn Bianco
      | Reply

      I’m liking it! Writing C++ feels very slick. This page summaries a lot of the cool new features for C++ specifically:

      Notably: improved intellisense (although I have Visual Assist X as well) and better parallel/asynchronous programming support at various levels, plus better C++ 11 standard compliancy in general.

      Writing a Windows (Store) App with WinRT rather than Win32 is nice too – there isn’t nearly as much of that boring boilerplate code now. And there’s scarcely a raw pointer in sight – it’s all reference counted smart pointers. Very friendly.

      • Alex
        | Reply

        So does this mean IF implemented that Cards wiuthot pixel shaders will no longer be able to run X-plane? NO!The decision on minimum hardware requirements and the decision on rendering effects are separate.- If we continue to support non-shader cards AND we do per-pixel lighting, then you simply won’t get per pixel lighting on old cards.- I cannot say what future requirements will be.- I can say we are NOT going to CHANGE the hardware requirements in the MIDDLE of a version run to DISALLOW cards that used to work.If your card works in v9, it will work for the rest of v9. I can say absolutely nothing about what will happen in v10, v11, v12, etc.Actually, I can say this: I think it will be relatively unlikely for us to REQUIRE shaders too many cards have too many problems with their drivers I expect we will always support some kind of really primitive no features required mode that works, so that users don’t get stuck with a DVD they can’t run at all, no matter how toasted their drivers are.But I don’t think we’ll do any more new eye candy that doesn’t require shaders the non-shader pipeline is just about as maxed out as it can be already we’re not going to invest more work in 1990 s graphics technology.The future is shaders even if they are not required for compatibility/troubleshooting reasons. You’d certainly be insane to pick up a new graphics card wiuthot them.

Leave a Reply