Hello, Tesselation

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

posted in: Programming 2

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 titbits 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 fulfil 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:


2 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.