Quantcast
Viewing all 72 articles
Browse latest View live

DirectXMath 3.08

DirectXMath version 3.08 is included in the Windows 10 SDK November 2015 update (10586) that ships with VS 2015 Update 1 with the Windows Tools 1.2 for Windows 10.

This new version includes the following:

  • Added use of _mm_sfence for Stream methods
  • Fixed bug with non-uniform scaling transforms for BoundingOrientedBox
  • Added asserts for Near/FarZ in XMMatrix* methods
  • Added use of =default for PODs with VS 2013/2015
  • Additional SSE and ARM-NEON optimizations for PackedVector functions

It’s a fairly minor update compared to DirectXMath 3.07, but does have one interesting side-effect worth discussing further. Because of the use of the C++11 =default construct, existing DirectXMath code may generate new previously latent warnings when building with VS 2013 or VS 2015:

warning C4101: 'X': unreferenced local variable

warning C4701: potentially uninitialized local variable 'X' used

The warnings are easy to address, but may surprise developers when they pop up in existing code. Note that the =default construct is not merely syntactic fluff: In some use cases, it can make the compiler generate much better code by understanding the constructor does nothing at all and the type in question is in fact ‘trivial plain-old-data’. This mostly shows up in the cases of inheritance, so it may not be obviously different in simple codegen cases. It does, however, cause these compiler to notice when a variable is not actually used or initialized.

BoundingOrientedBox

The fix for non-uniform scaling transformations is trivial to apply to older versions of the library:

 inline void XM_CALLCONV BoundingOrientedBox::Transform( BoundingOrientedBox& Out, FXMMATRIX M ) const
 {
 // Load the box.
 XMVECTOR vCenter = XMLoadFloat3( &Center );
 XMVECTOR vExtents = XMLoadFloat3( &Extents );
 XMVECTOR vOrientation = XMLoadFloat4( &Orientation );

 assert( DirectX::Internal::XMQuaternionIsUnit( vOrientation ) );

 // Composite the box rotation and the transform rotation.
 XMMATRIX nM;
 nM.r[0] = XMVector3Normalize( M.r[0] );
 nM.r[1] = XMVector3Normalize( M.r[1] );
 nM.r[2] = XMVector3Normalize( M.r[2] );
 nM.r[3] = g_XMIdentityR3;
 XMVECTOR Rotation = XMQuaternionRotationMatrix( nM );
 vOrientation = XMQuaternionMultiply( vOrientation, Rotation );

 // Transform the center.
 vCenter = XMVector3Transform( vCenter, M );

 // Scale the box extents.
 XMVECTOR dX = XMVector3Length( M.r[0] );
 XMVECTOR dY = XMVector3Length( M.r[1] );
 XMVECTOR dZ = XMVector3Length( M.r[2] );

 XMVECTOR VectorScale = XMVectorSelect( dY, dX, g_XMSelect1000 ); // !!swapped dX and dY
 VectorScale = XMVectorSelect( dZ, VectorScale, g_XMSelect1100 ); // !!swapped dZ and VectorScale
 vExtents = vExtents * VectorScale;

 // Store the box.
 XMStoreFloat3( &Out.Center, vCenter );
 XMStoreFloat3( &Out.Extents, vExtents );
 XMStoreFloat4( &Out.Orientation, vOrientation );
 }
 

Xbox One: DirectXMath 3.08 shipped in the Xbox One XDK (July 2015 or later)

GitHub: Note that DirectXMath is now hosted on GitHub.

Related: Known Issues: DirectXMath 3.03, DirectXMath 3.06, DirectXMath 3.09


Direct3D Game Visual Studio templates (Redux)

Back in January, I released a D3D11Win32Game Visual Studio 2013 template for Win32 desktop development primarily to support my DirectX Tool Kit tutorials. I modeled it after the basic template that we ship with the Xbox One XDK that consist of a Game class which sets up a device, swap chain, and timed rendering loop. I’ve since updated the templates on GitHub and now have versions for VS 2015, for the universal Windows platform, for Direct3D 12, and versions with the DeviceResources abstraction that is used in the official Windows Store and UWP templates.

VS Express users: I recommend taking a look at the VS Community edition which supports Windows desktop development if you don’t have the budget for purchasing a license for the Pro+ editions

Using the VSIX

To install: VS 2013 users should run Direct3DWin32Game.vsix and VS 2015 users should run Direct3DUWPGame.vsix. These packages install all the templates supported for that version of Visual Studio under the “Visual C++” node of the New Project dialog. If you have Visual Studio open, you should shut it down and restart it. If you have an older version installed of this VSIX installed, you should uninstall the old one first.

To remove: Go to Tools / Extensions and Updates… then uninstall “Direct3DWin32Game” or “Direct3DUWPGame”.

Template VS 2013 VS 2015 Description
Direct3D Win32 Game ü ü Win32 desktop Direct3D 11 Game template
Direct3D Win32 Game DR ü ü Win32 desktop Direct3D 11 Game template with DeviceResources abstraction
Direct3D UWP Game û ü Universal Windows app Direct3D 11 Game template
Direct3D UWP Game DR û ü Universal Windows app Direct3D 11 Game template with DeviceResources abstraction
Direct3D 12 Win32 Game û ü Win32 desktop Direct3D 12 Game template
Direct3D 12 Win32 Game DR û ü Win32 desktop Direct3D 12 Game template with DeviceResources abstraction
Direct3D 12 UWP Game û ü Universal Windows app Direct3D 12 Game template
Direct3D 12 UWP Game DR û ü Universal Windows app Direct3D 12 Game template with DeviceResources abstraction

DirectX 12: The Direct3D 12 versions of the template set _WIN32_WINNT to 0x0A00 (Windows 10), while the Direct3D 11 versions still use 0x0600 (Windows Vista). You need to have the Windows 10 SDK installed to build the Direct3D 12 templates, and Windows 10 to run it.

UWP: You have to be using Windows 8.1 or Windows 10 with the Windows 10 SDK installed to build the UWP templates. You need a Windows 10 device to run it.

DeviceResources

The basic template puts all the code for creating the device and swapchain into the main Game class. This makes it very simple to reference especially in the tutorial lessons. This does have the result, however, of putting a fair amount of ‘boiler plate’ code that clutters up the main Game class. The alternative for larger projects are the “DR” versions which add a helper class called DeviceResources. This class owns the Direct3D device, the DXGI swap chain, the depth/stencil buffer, and the render views needed for basic rendering. This does requires a few changes in the Game class.

 Game::Game()
 {
 m_deviceResources = std::make_unique<DX::DeviceResources>();
 m_deviceResources->RegisterDeviceNotify(this);
 }
void Game::Initialize(HWND window, int width, int height)
{
m_deviceResources->SetWindow(window, width, height);

m_deviceResources->CreateDeviceResources();
CreateDeviceDependentResources();

m_deviceResources->CreateWindowSizeDependentResources();
CreateWindowSizeDependentResources();
...
}

...

void Game::Render()
{
// Don't try to render anything before the first Update.
if (m_timer.GetFrameCount() == 0)
{
return;
}

Clear();

// TODO: Add your rendering code here.

m_deviceResources->Present();
}

// Helper method to clear the back buffers.
void Game::Clear()
{
// Clear the views
auto context = m_deviceResources->GetD3DDeviceContext();
auto renderTarget = m_deviceResources->GetBackBufferRenderTargetView();
auto depthStencil = m_deviceResources->GetDepthStencilView();

context->ClearRenderTargetView(renderTarget, Colors::CornflowerBlue);
context->ClearDepthStencilView(depthStencil, D3D11_CLEAR_DEPTH, 1.0f, 0);
context->OMSetRenderTargets(1, &renderTarget, depthStencil);

// Set the viewport.
auto viewport = m_deviceResources->GetScreenViewport();
context->RSSetViewports(1, &viewport);
}

...

void Game::CreateDeviceDependentResources()
{
// TODO: Initialize device dependent objects here (independent of window size).
}

// Allocate all memory resources that change on a window SizeChanged event.
void Game::CreateWindowSizeDependentResources()
{
// TODO: Initialize windows-size dependent objects here.
}

void Game::OnDeviceLost()
{
// TODO: Add Direct3D resource cleanup here.
}

void Game::OnDeviceRestored()
{
CreateDeviceDependentResources();

CreateWindowSizeDependentResources();
}

A few key things to note about this code compared with the non-DR version:

  • The Game::CreateDevice method has been replaced with a call to DeviceResources::CreateDeviceResources and Game::CreateDeviceDependentResources.
  • The Game::CreateResources method has been replaced with a call to DeviceResources::CreateWindowSizeDependentResources and Game::CreateWindowSizeDependentResources.
  • The Game::OnDeviceLost method is now a callback from DeviceResources and only handles the cleanup. The Game::OnDeviceRestored call is made when the device has been re-recreated.
  • The usage difference can be seen in Game::Clear where instead of using local member variables, accessors on DeviceResources are used to obtain the device, context, etc.

Otherwise the DR version of the template is the same as the original D3DGame templates, including using StepTimer. See this page for a more detailed overview.

DirectX 12: The details of the Direct3D 12 versions of DeviceResources is different than the Direct3D 11 version since the APIs are quite different, but it’s the same design. See this page for a more detailed overview.

VS 2013 vs. 2015: Note there is one minor code difference between the VS 2013 and VS 2015 version of the templates because VS 2013 does not support C++11 uniform initialization. Otherwise the code is basically the same. VS 2015 is required for UWP development, and the Windows 10 SDK is required for Direct3D 12 development which only officially integrates with VS 2015–you can use a props solution to get it to work with VS 2013.

Visual Studio 2015 Update 2

VS 2015 Update 2 is now available for download, including the updated Community edition. The Visual C++ 2015 Update 2 Redistribution packages are also available (x86, x64), as well as the Remote Debugging Tools (x86, x64, ARM). For more information, see the Visual Studio Team blog. Be sure to read the MSDN page as well.

Compiler and CRT

VS 2015 Update 2 includes a new version of the C/C++ compiler (19.00.23918). There is also a new version of the C/C++ Runtime (14.0.23918). See these posts for details of the compiler and library improvements, along with this list of bug fixes.

Windows 10 SDK: VS 2015 Update 2 includes Windows Tools 1.3 with the Windows 10 SDK for Version 1511 (10.0.10586). As before, this is an optional install. The new Windows Tools 1.3 also adds a UI dialog when creating new UWP projects that prompts for which version of the Windows 10 SDK to use. Note that this same dialog is triggered when using my Direct3D 12 Win32 Game templates–the minimum version value is not used in Win32 projects.

Visual C++ Build Tools 2015: There is a new edition of Visual Studio available without the IDE for those just looking for the compiler toolset.

Related: Visual Studio 2015 RTM, Visual Studio 2015 Update 1, Visual Studio 2015 Update 3

Visual Studio 2015 Update 3

VS 2015 Update 3 is now available for download, including the updated Community edition. The Visual C++ 2015 Update 3 Redistribution packages are also available (x86, x64), as well as the Remote Debugging Tools (x86, x64, ARM). For more information see the Visual Studio Team Blog. Be sure to read the release notes.

Update: See the Visual C++ Porting and Upgrading Guide and the VC++ Samples GitHub.

Compiler and CRT

VS 2015 Update 3 includes a new version of the C/C++ compiler (19.00.24215.1 with the latest hot-fixes applied). There is also a new version of the C/C++ Runtime (14.0.24212). See these posts for details about the compiler, optimizer, libraries, and standards compliance including expression SFINAE.

Windows 10 SDK: VS 2015 Update 3 includes new Windows Tools 1.4 with the Windows 10 SDK for Version 1511 (10.0.10586). As before, this is an optional install.

Visual C++ Build Tools 2015: There is an edition of Visual Studio available without the IDE for those just looking for the compiler toolset.

Related: Visual Studio 2015 RTM, Visual Studio 2015 Update 1, Visual Studio Update 2

DirectX Tool Kit for DirectX 12

Since the release of DirectX Tool Kit four years ago, it has proven to be a very useful library for samples, indie and hobbyist projects, people moving from XNA Game Studio to C++, learning Direct3D 11, and for developers looking for supported replacements for the legacy D3DX library and the retiring of the legacy DirectX SDK.

Today I’m announcing the DirectX Tool Kit for DirectX 12, which is hosted as it’s own GitHub site. After much discussion and debate, we realized that both tool kits are really independent projects. While they share a lot of code (all the non-graphics stuff is 100% identical), the Direct3D 12 API is significantly different than Direct3D 11 so the graphics components ‘feel’ the same but in practice are used very differently.

DirectXTK for DirectX 12 includes the following components:

  • CommonStates – Factory for common combinations of rendering states (C++ versions modelled after the ‘public fields’ of BlendState, DepthStencilState, RasterizerState, and SampleState classes used for XNA Game Studio)
  • DDSTextureLoader – light-weight DDS file texture loader
  • DirectXHelpers – misc C++ helpers for D3D programming
  • Effects – a collection of ready-to-use common shaders (C++ versions of the BasicEffect, AlphaTestEffect, DualTextureEffect, EnvironmentMapEffect, and SkinnedEffect used for XNA Game Studio)
  • GeometricPrimitives – geometry helpers for common shapes (Cube, Sphere, GeoSphere, Cylinder, Torus, Teapot, Tetrahedron, Octahedron, Dodecahedron, and Isosahedron)
  • GraphicsMemory – helper for managing graphics memory allocation
  • Model – draws simple meshes loaded from .SDKMESH or .VBO files
  • PrimitiveBatch – simple and efficient way to draw user primitives which replicates the simplicity of the Direct3D 9 era DrawUP APIs
  • ScreenGrab – light-weight screen shot saver
  • SpriteBatch – a 2D sprite rendering class (a C++ version of the SpriteBatch used for XNA Game Studio)
  • SpriteFont – a bitmap based text rendering (a C++ version of the SpriteFont used for XNA Game Studio)
  • VertexTypes –  collection of commonly used vertex buffer data structures with a input layout descriptions (C++ versions of VertexPositionColor, VertexPositionTexture, VertexPositionColorTexture, and VertexPositionNormalTexture structures used for XNA Game Studio)
  • WICTextureLoader – WIC-based image file texture loader
DirectX Tool Kit for DirectX 12 also includes DirectX Tool Kit for Audio, GamePad, Keyboard, Mouse, and SimpleMath.  The MakeSpriteFont and XWBTool tools are identical so they are hosted on the DirectX Tool Kit for DirectX 11 GitHub. A few key differences compared to the DirectX 11 version:
  • No support for loading .CMO models or DGSL effect shaders (i.e. DGSLEffect)
  • VertexTypes does not include VertexPositionNormalTangentColorTexture or
    VertexPositionNormalTangentColorTextureSkinning
  • DirectX Tool Kit for DirectX 11 supports Feature Level 9.3, while DirectX 12 requires Direct3D Feature Level 11.0. There are no expected DirectX 12 drivers for  any lower feature level devices.
  • The library assumes it is building for Windows 10 (aka _WIN32_WINNT=0x0A00) so it makes use of XAudio 2.9 and WIC2 as well as DirectX 12.

A word of caution: DirectX 12 is an API designed for graphics experts. If you are not already an expert in using Direct3D 11, I’d recommend sticking with the Direct3D 11 API until you find yourself in need of the additional control. Direct3D 12 provides a great deal of control over memory allocation, synchronization, state management which can result in reduced CPU overhead for rendering compared to older versions of Direct3D, but that control means the API is quite unforgiving. If you are new to Direct3D entirely, definitely start with Direct3D 11 first.

DirectX Tool Kit for DirectX 12 is documented on the GitHub wiki and there are basic tutorials on it’s usage. It’s also host on NuGet for Windows Universal Platform (UWP) apps and Win32 desktop apps on Windows 10.

Both version so the DirectX Tool Kit now include support for NormalMapEffect and per-pixel lighting support for EnvironmentMapEffect.

Related: Anatomy of Direct3D 12 Create Device, Getting Started with Direct3D 12

Windows 10 Anniversary Update SDK

Windows 10 Anniversary Update (build 14393, aka Version 1607) is now available along with a new Windows 10 SDK release. The Windows 10 Anniversary Update SDK (10.0.14393) can be installed via an optional install with VS 2015 Update 3 or as a standalone installer. This includes DirectXMath 3.09 and updated versions of Direct3D 12, Direct3D 11.4, DXGI 1.5, Direct2D/DirectWrite 1.3. Note XAudio 2.9 is unchanged.

GibHub: All of my open source projects have new releases to support the Windows 10 Anniversary Update SDK: DirectXTK, DirectXTK12, DirectXTex, DirectXMesh, UVAtlas, Effects 11, DXUT11.

DirectX Developer Runtime: The DirectX Developer Runtime for Windows 10 is an optional feature called Graphics Tools as described in this blog post. When upgrading from 10586 to 14393, the optional feature can be disabled rather than updated, which can be fixed by re-enabling the optional feature. Note that WARP12 is part of the Graphics Tools optional feature as it’s currently intended only for use by developers.

DirectX 12 User: Note that the new compiler will default to writing 1.1 Root Signatures which are not supported by older versions of Windows 10. You can force the compiler to emit older signatures using a FXC compiler switch. See MSDN for details. The latest version of D3DX12 requires the new SDK, and provides a helper D3DX12SerializeVersionedRootSignature for reconstructing a 1.0 signature from a 1.1 version (which assumes you have d3d12.dll set for delay loading since it can call D3D12SerializeVersionedRootSignature which is only present on 14393 or later).

VS 2013 Users: As with the past few releases, the Windows 10 SDK only integrates with VS 2015. You can use the Windows 10 SDK with VS 2013 via the props attached per this Visual C+ Team Blog.

VS 2015 Users: Use the custom installer option (or modifying an existing install) with VS 2015 Update 3 to add the Windows Tools 1.4.1 and Windows 10 SDK (10.0.14393) feature.

Direct3D 9 Users: Note that with the updated operating system, there will be some performance impact if you are using D3DCREATE_SOFTWARE_VERTEXPROCESSING or D3DCREATE_MIXED_VERTEXPROCESSING. The solution is to make use of D3DCREATE_HARDWARE_VERTEXPROCESSING instead.

Samples: As with the previous releases of the Windows 10 SDK, official Windows samples are hosted on GitHub: Windows-universal-samplesWindows-classic-samples, Windows-driver-samples. Additional Direct3D 12 samples can be found in DirectX-Graphics-Samples. See also DirectX SDK Samples Catalog.

Related: Windows 10 SDK RTM, Windows 10 SDK (November 2015)

Windows10SDKVS13-14393

DirectXMath 3.09

DirectXMath version 3.09 is included in the Windows 10 Anniversary Update SDK (14393) that ships with VS 2015 Update 3 when you install the Windows Tools 1.4.1 and select the 10.0.14393 Target Platform Version (see this blog post).

The new version includes the following:

  • Support for additional optimizations when built with /arch:AVX or /arch:AVX2
  • Added use of constexpr for type constructors, XMConvertToRadians, and XMConvertToDegrees
  • Marked __vector4i, XMXDEC4XMDECN4XMDEC4, and associated Load & Store functions as deprecated. These are vestiges of Xbox 360 support and will be removed in a future release.
  • Renamed parameter in XMMatrixPerspectiveFov* to reduce user confusion when relying on IntelliSense
  • XMU565XMUNIBBLE4 constructors take uint8_t instead of int8_t

Arch Switch

The DirectXMath library assumes on x86 and x64 that both SSE and SSE2 are always supported. Later instruction sets are not always supported on PCs, and to avoid the penalty of additional guarded code paths or runtime selection the library avoids using them. As I’ve covered in the past, you can use specific versions in your own guarded code paths as the developer can pick a high-enough level to do the runtime selection to amortize the penalties involved.

For fixed-platforms like the Xbox One, however, the library can rely on additional instructions being present. These optimizations are now also available in the Windows version of DirectXMath when built using the /arch:AVX or /arch:AVX2 switches. Keep in mind that the resulting EXE or DLL only works correctly on systems with AVX and/or AVX2 support, so you should ensure that these binaries are only used on such systems (XMVerifyCPUSupport will perform the additional tests as appropriate when built with these switches).

GitHub

In addition to shipping with the Windows SDK and the Xbox One XDK, DirectXMath is now also available on GitHub under the MIT license. This repo also includes all the extension libraries such as Spherical Harmonics math, XDSP, etc.

The GitHub’s master branch is already host to a new revision in progress for a future DirectXMath 3.10 release.

Related: Known Issues: DirectXMath 3.03, DirectXMath 3.06, DirectXMath 3.07, DirectXMath 3.08

Anatomy of Direct3D 12 Create Device

Based on some questions I’ve been getting lately, it seems like now’s a good time to revisit my classic post Anatomy of Direct3D 11 Create Device updated for Direct3D 12!

The first thing to note is that while you can pass a nullptr for the ‘default’ device with Direct3D 12 to D3D12CreateDevice, that’s probably not the best solution. At this point, every driver on Windows 7 or later supports Direct3D 11, so you can pretty safely assume the default device is going to support Direct3D 11 at some Direct3D hardware feature level. While a lot of existing (as well as new) GPUs support Direct3D 12, this doesn’t apply to all GPUs. Specifically, a new WDDM 2 driver is required to support Direct3D 12, and there are no devices below Direct3D Feature Level 11.0 that are expected to get such updated drivers.

Another difference is that the debug device is not enabled through a creation flag like it is in Direct3D 11. Therefore, our first step is to enable debugging if available (the debug device is only present if the Graphics Tools Windows 10 optional feature is enabled). I’m making use of Microsoft::WRL::ComPtr which is recommended for both Direct3D 11 and Direct3D 12 (see this page for more information on this useful smart-pointer for COM programming).

#if defined(_DEBUG)
    // Enable the debug layer.
    {
        ComPtr<ID3D12Debug> debugController;
        if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
        {
            debugController->EnableDebugLayer();
        }
    }
#endif

Next, we create a DXGI factory:

ComPtr<IDXGIFactory1> dxgiFactory;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
if (FAILED(hr))
    // Error!

Then we scan DXGI adapters looking for one that supports Direct3D 12:

ComPtr<IDXGIAdapter1> adapter;
for (UINT adapterIndex = 0;
     DXGI_ERROR_NOT_FOUND !=
         dxgiFactory->EnumAdapters1(adapterIndex, &adapter);
     ++adapterIndex)
{
    DXGI_ADAPTER_DESC1 desc;
    hr = adapter->GetDesc1(&desc);
    if (FAILED(hr))
        continue;

    if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
    {
        // Don't select the Basic Render Driver adapter.
        continue;
    }

    // Check to see if the adapter supports Direct3D 12,
    // but don't create the actual device yet.
    if (SUCCEEDED(
        D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0,
            _uuidof(ID3D12Device), nullptr)))
    {
        break;
    }
}

Note: We are excluding the Microsoft Basic Render adapter here (aka WARP+VGA driver) since games typically don’t play well using WARP, but keep in mind that WARP12 is not present on standard Windows 10 systems; it’s only installed as part of the Graphics Tools optional feature.

If there’s no Direct3D 12-capable hardware, then for development builds it is useful to fallback to the WARP software device for Direct3D 12. Here is another difference compared to Direct3D 11: WARP12 is a specific adapter you obtain from the DXGI factory:

#if !defined(NDEBUG)
    if (!adapter)
    {
        ComPtr<IDXGIFactory4> dxgiFactory4;
        if (SUCCEEDED(dxgiFactory.As(&dxgiFactory4)))
        {
            if (FAILED(dxgiFactory4->EnumWarpAdapter(IID_PPV_ARGS(&adapter))))
            {
                adapter.Reset();
            }
        }
     }
#endif

If at this point, we still don’t have a valid adapter, then either a fatal error should be displayed, -or- if the application supports it, you should fall back to using Direct3D 11.

Otherwise, it’s time to create the device. Here’s another Direct3D 11 difference: Instead of providing an input array of every possible Direct3D feature level your application supports, you simply provide the minimum feature level you can use. Because as I noted above there’s no expected drivers for anything below Feature Level 11.0, that’s the minimum I’m using in this code and you’ll find the same in the Visual Studio DirectX 12 templates.

ComPtr<ID3D12Device> device;
hr = D3D12CreateDevice(adapter.Get(),
    D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device));
if (FAILED(hr))
    // Error!

Great, so we have a device, but how do you know if you managed to get a higher feature level than your minimum? Here we use CheckFeatureSupport to find that out:

static const D3D_FEATURE_LEVEL s_featureLevels[] =
{
    D3D_FEATURE_LEVEL_12_1,
    D3D_FEATURE_LEVEL_12_0,
    D3D_FEATURE_LEVEL_11_1,
    D3D_FEATURE_LEVEL_11_0,
};

D3D12_FEATURE_DATA_FEATURE_LEVELS featLevels =
{
    _countof(s_featureLevels), s_featureLevels, D3D_FEATURE_LEVEL_11_0
};

D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
hr = device->CheckFeatureSupport(D3D12_FEATURE_FEATURE_LEVELS,
     &featLevels, sizeof(featLevels));
if (SUCCEEDED(hr))
{
    featureLevel = featLevels.MaxSupportedFeatureLevel;
}

Swap Chain

At this point, you are ready to create the swap chain. For Win32 classic desktop apps you use CreateSwapChainForHwnd, and for Universal Windows Platform (UWP) apps you use CreateSwapChainForCoreWindow or CreateSwapChainForComposition, all of which require IDXGIFactory2 or later:

ComPtr<IDXGIFactory2> dxgiFactory2;
if (FAILED(dxgiFactory.As(&dxgiFactory2)))
    // Fatal error (shouldn't happen in practice at this point)

The key thing to note about swap chain creation is that you must use either DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL or DXGI_SWAP_EFFECT_FLIP_DISCARD for the DXGI_SWAP_CHAIN_DESC1.SwapEffect because the older swap effects are not supported for Direct3D 12.

For Universal Windows Platform (UWP) apps, you should also consider using DXGI_SCALING_ASPECT_RATIO_STRETCH for the DXGI_SWAP_CHAIN_DESC1.Scaling, but for Win32 classic desktop swap chains you need to stick with DXGI_SCALING_NONE or DXGI_SCALING_STRETCH.

One more consideration: For gamma-correct rendering to standard 8-bit per channel UNORM formats, you’ll want to create the Render Target using an sRGB format. The new flip modes, however, do not allow you to create a swap chain back buffer using an sRGB format. In this case, you create one using the non-sRGB format (i.e. DXGI_SWAP_CHAIN_DESC1.Format = DXGI_FORMAT_B8G8R8A8_UNORM) and use sRGB for the Render Target View (i.e. D3D12_RENDER_TARGET_VIEW_DESC.Format = DXGI_FORMAT_B8G8R8A8_UNORM_SRGB).

Note: With Direct3D 12, you cannot use the device.As(&dxgiDevice) sequence to obtain the DXGI factory from the Direct3D 12 device for cases where you use nullptr to create the D3D12CreateDevice instance. You must always explicitly create the DXGI factory using CreateDXGIFactory1 or CreateDXGIFactory2.

Windows SDK

To build an application using Direct3D 12 APIs, you must make use of the Windows 10 SDK. The latest version is the Windows 10 Anniversary Update SDK (14393). With Visual Studio 2015, you install it via a custom install option and for Win32 classic desktop projects you’ll need to explicitly change the project property to use it rather than the default Windows 8.1 SDK (Spring 2015).

Direct3D 12.1

With the Windows 10 Anniversary Update, newer drivers and devices can support some additional features for Direct3D 12. You can obtain the 12.1 interface from your 12.0 device by using QueryInterface or ComPtr::As–this will fail on older versions of Windows 10.

ComPtr<ID3D12Device1> device1;
if (SUCCEEDED(device.As(&device1)))
{
    // Direct3D 12.1 Runtime is available
}

Win32 desktop application notes

If your application supports Windows 8.1 or earlier, then you need to make use of explicit rather than implicit linking to the Direct3D 12 functions since they are not available before Windows 10. Implicit linking to dxgi.lib (and d3d11.lib if needed) is not a problem unless you are trying to support Windows XP as well. The code above is careful to try to use DXGI 1.1 for the initial detection to support Windows 7 systems.

HMODULE dx12 = LoadLibraryEx(L"d3d12.dll",
    nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (!dx12)
    // Fallback to using Direct3D 11

auto pD3D12CreateDevice = reinterpret_cast<PFN_D3D12_CREATE_DEVICE>(
    GetProcAddress(dx12, "D3D12CreateDevice"));
if (!pD3D12CreateDevice)
    // Fallback to using Direct3D 11

...

#if defined(_DEBUG)
    // Enable the debug layer.
    auto pD3D12GetDebugInterface =
        reinterpret_cast<PFN_D3D12_GET_DEBUG_INTERFACE>(
        GetProcAddress(dx12, "D3D12GetDebugInterface"));
    if (pD3D12GetDebugInterface)
    {
        ComPtr<ID3D12Debug> debugController;
        if (SUCCEEDED(pD3D12GetDebugInterface(
            IID_PPV_ARGS(&debugController))))
        {
            debugController->EnableDebugLayer();
        }
    }
#endif

...
// Change both cases where we use D3D12CreateDevice above to
// pD3D12CreateDevice. If you fail to find an adapter, use
// Direct3D 11 instead

Universal Windows Platform (UWP) notes

Because the minimum OS version is enforced for the platform, you can count on IDXGIFactory4 always being available. Therefore, you can simplify the code above by starting out with that version–which is exactly what you’ll find in the Visual Studio DirectX 12 UWP templates:

ComPtr<IDXGIFactory4> dxgiFactory;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
if (FAILED(hr))
    // Error!

Related: Direct3D Game Visual Studio templates (Redux), DirectX Tool Kit for DirectX 12, Getting Started with Direct3D 12


Getting Started with Direct3D 12

The first thing to do is get up to speed on Direct3D 11 (see Getting Started with Direct3D 11), especially if you are coming from a background of knowing Direct3D 9. Jumping feet-first into Direct3D 12 without a solid grounding in what a Direct3D feature level means, DXGI device-and-swapchain creation, the modern HLSL compiler story, the fate of the legacy DirectX SDK, and the Direct3D 10/Direct3D 11 state model and graphics pipeline design is a recipe for confusion and frustration.

DirectX 12 is an expert API which builds on knowing the ins & outs of DirectX 11. DirectX 12 is an extremely low-level API designed for graphic experts who have a solid understanding of the architecture of modern GPU hardware, and can essentially write the DirectX 11 Runtime from scratch. Both DirectX 11 and DirectX 12 provide access to the same hardware features on Windows 10, but drive the hardware in different ways which can allow a well-optimized DirectX 12 engine to achieve much lower CPU overhead than in DirectX 11.

With that preamble out of the way, you should familiarize yourself with the documentation on MSDN and the official samples on GitHub. Then install Visual Studio 2015 and be sure to install the Windows Tools and Windows 10 SDK component. See this blog post for details.

For introductory samples, take a look at D3D12HelloWorld (PC desktop and UWP), as well as the Xbox ATG Graphics UWP samples. DirectX Tool Kit for DirectX 12 includes some tutorials as well.

Presentations: There’ve been a number of public presentations on Direct3D 12.

DirectX: Evolving Microsoft’s Graphics Platform (GDC 2014): link

Direct3D 12 API Preview (BUILD 2014): link

Better Power, Better Performance: Your Game on DirectX12 (GDC 2015): link

Advanced DirectX12 Graphics and Performance (GDC 2015/BUILD 2015): link

Direct3D Update: (GDC 2016): link

There is also a series of YouTube videos on various aspects of Direct3D 12 you should take a look at as well.

AMD, Intel, and NVidia also have additional materials available online.

Debugging: The debug device (aka the Developer Runtime) on Windows 10 is not installed by any SDK. It is enabled as a Windows Optional Feature called “Graphics Tools”. See this post for details. You should also familiarize yourself with DXGI debugging features.

Utilities: The various Direct3D 12 templates make use of a simple header-only helper D3DX12. This does not have nearly the scope of the deprecated D3DX libraries, but is useful in taking care of many of the more mundane aspects of creating the required structures. For support in loading textures, rendering fonts & sprites, loading models, etc. see DirectX Tool Kit for DirectX 12. For graphics math, see DirectXMath. You should use DirectXTex, DirectXMesh, and UVAtlas for content processing as well.

Multi-GPU: See this blog post.

Related: Anatomy of Direct3D 12 Create Device, Direct3D Game Visual Studio templates (Redux), Windows 10 Anniversary Update SDK

DirectXTex and DirectXMesh now support Direct3D 12

As part of my multi-year personal project of providing open source replacements for the deprecated D3DX library once found in the legacy DirectX SDK, two libraries are focused on content creation tools and build pipelines. DirectXTex handles loading image files, texture processing including format conversion, mipmap generation, block-compression, and writing out ‘fully cooked’ textures into DDS files. DirectXMesh provides geometry support such as computing normals and tangent-frames, transparent vertex cache optimization, and provides utilities for extracting/inserting vertex data in vertex buffers.

These libraries were originally written for DirectX 11, and it seems likely that most tools should continue to use DirectX 11 for the simplicity and ease of developer productivity. There are, however, cases where you want to use some of this functionality ‘in-engine’, so the January 2017 releases include DirectX 12 API support as well.

DirectXTex January 2017 release on GitHub

DirectXMesh January 2017 release on GitHub

To simplify supporting all the various platforms and Windows SDK combinations, the library continues to default to using DirectX 11. If you want to use DirectX 12, you need to explicitly include the required headers before including the library header:

#include <d3d12.h>
#include "DirectXTex.h"

You also need to link with the DirectXTex_Desktop_2015_Win10.vcxproj, DirectXTex_Windows10.vcxproj, or DirectXTex_XboxOneXDK_2015.vcxproj projects which build with both DirectX 11 and DirectX 12 support.

If you want to use both DirectX 11 and DirectX 12 in the same compilation module, then you need to explicitly include both:

#include <d3d11_1.h>
#include <d3d12.h>
#include "DirectXTex.h"

The story is similar for DirectXMesh, although in this case it’s just to let you use D3D12_ input layouts enums and structures instead of D3D11_–the data itself is identical.

In case you missed it, DirectXTex was updated to support the HDR (RGBE) file format as a source for floating-point HDR texture data, as well as having ‘opt-in’ support for OpenEXR. For more details on how to enable OpenEXR, see this page.

Related: DirectX Tool Kit for DirectX 12

DirectX Tool Kit and C++/WinRT

The February 2017 releases of DirectX Tool Kit for DirectX 11 and DirectX 12 are now available on GitHub. In addition to various bug-fixes and a few minor improvements to the input classes (Mouse, Keyboard, and GamePad), the libraries now also support C++/WinRT applications for UWP and Xbox One. C++/WinRT language projections allow you to use Windows Runtime APIs without using the C++/CX language extensions (i.e. the libraries will work with applications built with or without /ZW).

For more on C++/WinRT, see:

https://moderncpp.com/

C++ – Introducing C++/WinRT (MSDN Magazine)

cppwinrt on GitHub

Migrating C++/CX source code to C++/WinRT

Embracing Standard C++ for the Windows Runtime” (CppCon 2016)

Putting Coroutines to Work with the Windows Runtime” (CppCon 2016)

VS Templates: I’ve added C++/WinRT variants of my Direct3D UWP templates for DirectX 11 and DirectX 12 to directx-vs-templates and the VS 2015 VSIX.

Samples: In addition to the samples on the cppwinrt GitHub, there’s a C++/WinRT version of some samples on Xbox-ATG-Samples.

NuGet: You can use  C++/WinRT on NuGet as an easy way to add the C++/WinRT headers for the Windows 10 Anniversary Update (14393) to the templates above or your own project.

Compiler: To use C++/WinRT, you must be use using Visual Studio 2015 Update 3 or Visual Studio 2017 and build with the /std:c++latest switch. The use of /await is also recommended.

DirectXMath, DirectXTex, DirectXMesh: These libraries are also compatible with both C++/WinRT and C++/CX applications.

Related: DirectX Tool Kit for DirectX 12, Direct3D Game Visual Studio templates (Redux)

Visual Studio 2017

Visual Studio 2017 RTM is now available for download, including the updated Community edition. The VS 2017 RTM Redistribution packages are also available (x86, x64), as well as the Remote Debugging Tools (x86, x64). For more information see the Visual C++ Team Blog and Visual Studio Team Blog.

This version of Visual Studio includes a new lightweight installer. Be sure to read this post for an overview. Note that most C++ workloads include the Windows 10 Anniversary Update SDK (14393) by default, but older versions including Windows 8.1 SDK are available as optional components.

The latest docs are located here rather than their traditional location on MSDN.  In particular, see the Visual C++ Porting and Upgrading Guide.

UWP C++ Developers:  When you select the Universal Windows Platform (UWP) workload, be sure to add the optional component C++ Universal Windows Platform tools.

Automated Installs: See this page for details on installing VS 2017 from the command-line. For example, this installs C++ toolsets for game development for Win32 classic desktop and UWP apps:

vs_community.exe --lang en-us --add Microsoft.VisualStudio.Workload.NativeGame
--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81
--add Microsoft.VisualStudio.Workload.Universal
--add Microsoft.VisualStudio.ComponentGroup.UWP.VC
--add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended -p --wait

Compiler and CRT

VS 2017 includes a new version of C/C++ compiler (19.10.25017). See this blog post and this post for details on the new compiler and standards conformance (including more work on Expression SFINAE and additional C++14 conformance). See this post for details on /analyze updates, and this post for details on the C++ Core Guidelines Checker.

The C/C++ Runtime (4.10.25008) is binary compatible with VS 2015, which means you can safely link code built with VS 2015 with VS 2017 applications. See this post and this post for details. For details on library fixes in the latest version, see this post.

VS 2017 can target Windows 10, Windows 8.1, Windows 7 Service Pack 1, Windows Vista Service Pack 2, and optionally Windows XP Service Pack 3. Note that the Visual C++ 2017 REDIST does not support Windows 8.0, Windows 7 RTM, Windows Vista RTM, Windows Vista Service Pack 1, Windows XP RTM, Windows XP Service Pack 1, or Windows XP Service Pack 2 as these platforms are all outside their support lifecycle. See Visual Studio 2017 Product Family System Requirements.

Visual ++ Build Tools 2017: There’s an edition of Visual Studio available without the IDE for those looking for just the compiler toolset or setting up a build server.

Known issues

  • Note that there are errors generated when using the new VS 2017 conformance switch with the platform headers in Windows 10 SDK (14393) or earlier. These are addressed in the upcoming Windows 10 Creators Update SDK. Microsoft Developer Insiders can try out /permissive- with the preview SDK.
  • When you upgrade a project to the v141 toolset, you are given a UI prompt to select which version of the Windows SDK to use based on all the side-by-side installed SDKs.  This is ignored for Win32 desktop projects. To use a newer Windows SDK, you should edit the project properties after the upgrade–otherwise it’s likely the 8.1 SDK will be required, which is not installed by default.

Windows XP: When building using the “v141_xp” Platform Toolset for Windows XP Service Pack 3 target support, remember this uses the Windows 7.1A SDK. The older SDK will generate some warnings in system headers with the new toolset that have to be externally suppressed. See VS 2012 Update 1 for some additional implications for DirectX development.

DirectX SDK: If you need to continue to make use of legacy DirectX SDK components such as D3DX9, D3DX10, D3DX11, or XAudio 2.7 with Visual Studio 2017, see MSDN for details on mixing the paths correctly. See also DirectX SDKs of a certain age, The Zombie DirectX SDK, Living without D3DX, DirectX SDK Tools Catalog, DirectX SDK Samples Catalog, and Where’s DXERR.LIB?

GitHub: There are VS 2017 projects in the latest releases of DirectX Tool Kit for DirectX 11, DirectX Tool Kit for DirectX 12, DirectXTex, DirectXMesh, UVAtlas, DXUT, and Effects 11. These are set up to use the Windows 10 SDK (14393) because that’s the default version for VS 2017. Because of the fact that VS 2015 and VS 2017 are binary compatible w.r.t. to the C/C++ runtime, you can use the 2015 version of the NuGet packages with VS 2017. The Direct3D Game templates have been updated to support VS 2017 as well, and the Direct3DUWPGame.vsix now supports both VS 2015 aad VS 2017.

Windows 10 Creators Update SDK

The Windows 10 Creators Update (build 15063, aka Version 1703) is now available along with a new Windows 10 SDK release. The Windows 10 Creators Update SDK (10.0.15063) can be installed via VS 2017 or as a standalone installer. This includes DirectXMath 3.10 and updated versions of Direct3D 12, Direct3D 11.4 Direct2D, and DirectWrite.

VS 2015 Users: Note that the Windows 10 SDK (15063) is officially only supported for VS 2017.

VS 2017 Users: The Windows 10 Creators Update SDK resolves a number of conformance errors in Windows system headers enabling the use of the /permissive- switch.

Related: Windows 10 SDK RTM, Windows 10 SDK (November 2015), Windows 10 Anniversary Update SDK

DirectXMath 3.10

DirectXMath version 3.10 is included in the Windows 10 Creators Update SDK (15063) which is installed with Visual Studio 2017.

The new version includes the following:

  • Added XMVectorSum for horizontal adds
  • ARMv8 intrinsics use for ARM64 platform (division, rounding, half-precision conversion)
  • Added SSE3 codepaths using opt-in _XM_SSE3_INTRINSICS_
  • XMVectorRound fix for no-intrinsics to match round-to-nearest (even)
  • XMStoreFloat3SE fix when max channel isn’t a perfect power of 2
  • constexpr conformance fix and workaround for compiler bug in VS 2015 RTM
  • Remove support for VS 2012 compilers
  • Remove __vector4i deprecated type

SSE3

For the Windows x86 and Windows x64 platforms, the DirectXMath library assumes you are using SSE/SSE2 as support for those is required by the platform (see this blog post for details). If you use the /arch switch with AVX or AVX2, it makes use of additional instruction sets including SSE3, SSE4.1, AVX, and F16C. Previously you could enable the SSE 4.1/SSE3 optimizations together, but now with DirectXMath 3.10, the SSE3 optimizations can be enabled independently. Officially SSE3 is not required by the base Windows platform, but it’s support is very wide-spread so you can choose to require SSE3 even without requiring SSE4.1 or AVX/AVX2. See this blog post.

NuGet

This version can also be obtained via NuGet which will work with Visual Studio 2013 and Visual Studio 2015. DirectXMath no longer supports VS 2012.

GitHub

In addition to shipping with the Windows SDK and the Xbox One XDK, DirectXMath is also available on GitHub under the MIT license.

Related: Known Issues: DirectXMath 3.03, DirectXMath 3.06, DirectXMath 3.07, DirectXMath 3.08, DirectXMath 3.09

A look back: Windows Vista

This is a bit of a nostalgic navel-gazing like my Windows XP post was back in October 2010, so please forgive my indulgence.

This week, Windows Vista has officially reached end-of-life. There’s been a few retrospective press pieces like this one on Ars Technica, so I thought I’d chime in with my own thoughts. I started my tenure at Microsoft the week that Windows XP Service Pack 2 shipped, so I missed much of the early over-promising of “Project Longhorn” as well as the grueling grind of the “security reset” that culminated in the Windows XP SP2 release, so I consider Windows Vista to really be my ‘first Windows release’. There was a lot of game developer education needed for Windows Vista including Direct3D 10, Game Explorer, Parental Controls, User Account Control, and Windows x64–my first public presentation on Windows Vista was back at GDC 2006.

While the RTM of Windows Vista was indeed a rough experience all around, by the time Service Pack 1 shipped things were in pretty good shape technically. This was particularly true with all the catch-up work done by 3rd party drivers that weren’t ready by original ship. The reputational issues lingered, deserved or not, but for gamers on Windows, the Windows Vista release did a lot of good which made Windows 7 and later versions of the OS better.

  • Direct3D was an essential technology for Windows instead of kind of a bolt-on thing only used by games. The WDDM driver model really drove support and stability, and Direct3D 10 set the stage for Direct3D 11 and Direct3D 12 in a big way.
  • Windows Vista made 64-bit (x64) a thing. Windows XP x64 Edition was definitely an ‘early-adopter’ OS with a lot of quirks and never had much in the way of driver or application support, but Windows Vista made x64 a broad-based consumer scenario. The decision to include both x86 and x64 media at retail was a big part of that, and with gamer machines shipping with 4 GB or more physical RAM it was desperately needed–see this article.
  • Getting games to run as Standard User instead of assuming always-on administrator rights was the right thing for security generally, but was a real slog to make happen. There was also a push to get more game publishers to code sign their binaries which started to get traction with Windows Vista.

So if you love Windows 7 or Windows 10, remember to pour one out for the unloved older sibling that paved the way with a lot of blood, sweat, toil, and tears…


DirectXMath 3.11

DirectXMath version 3.11 is now available on NuGet and GitHub. It will be included in the upcoming Windows 10 Fall Creators Update SDK (currently in Preview build 16225 or later) and the Xbox One XDK (June 2017).

  • AVX optimization of XMMatrixMultiply and XMMatrixMultiplyTranspose
  • AVX2 optimization for XMVectorSplatX
  • FMA3 optimization of XMVectorMultiplyAdd and XMVectorNegativeMultiplySubtract
  • Conformance fixes to support compilation with Clang 3.7

The main addition for this version are the control defines for _XM_AVX2_INTRINSICS_ and _XM_FMA3_INTRINSICS_, both of which are enabled when using /arch:AVX2 along with the already existing _XM_F16C_INTRINSICS_. For details on the few AVX2 optimizations applicable to DirectXMath see this blog post, and for FMA3 see this post. This means that when you build using /arch:AVX2, the XMVerifyCPUSupport function will explicitly check for AVX2, FMA3, and F16C processor support.

Down the Conformance Rabbit Hole

For this release I did a fair amount of syntax cleanup for better C++11/C++14 conformance by getting the headers to build without warnings when using the Clang 3.7 compiler with Microsoft codegen. I can't speak to the quality or correctness of the generated code, but I wanted to make sure the source code was as conforming as I could make it--VS 2017's /permissive- standard enforcement switch helps, but there's no substitute for trying to build with a different compiler toolset.

A basic issue is that intrinsics themselves are implementation dependent, and in particular the way that the type __m128 is defined is not consistent between Visual C++ and Clang. Visual C++ treats it as a union, while Clang considers it a special opaque type. Therefore, I had to modify all places where the members of the __m128 union were being manipulated. This is pretty easy because I already have portable unions that work: XMVECTORF32, XVMECTORU32, and XMVECTORI32.

A knock-on impact of the way the __m128 type is defined means that you can overload free functions based on it with Visual C++, but you cannot do so with Clang. In other words, this is legal C++ with Visual C++ but not when using Clang:

__m128 operator+(__m128 V);

Rather than break existing users of these overloads on Visual C++, I guard their definition with a new control define, _XM_NO_XMVECTOR_OVERLOADS_, which I automatically enable when building with Clang. This also meant updating all the places in the other DirectXMath implementation headers where I relied on the overloads to use explicit functions instead. Note that there's no equivalent issue with XMMATRIX overloads because this is itself a struct.

The bulk of the remaining conformance changes were fully bracing the initialization of XMVECTORF32 and related types:

static const XMVECTORF32 c_value = { 1.f, 2.f, 3.f, 4.f };

had to be changed to:

static const XMVECTORF32 c_value = { { { 1.f, 2.f, 3.f, 4.f } } };

It also turns out that the Clang compiler doesn't like the trick used by the UNREFERENCED_PARAMETER macro. Instead of having:

XMVECTOR Permute(FXMVECTOR v1, FXMVECTOR v2) { (v2); return XM_PERMUTE_PS(v1, Shuffle); }

The name of the unreferenced formal parameter has to be removed to make both compilers happy:

XMVECTOR Permute(FXMVECTOR v1, FXMVECTOR) { return XM_PERMUTE_PS(v1, Shuffle); }

I also added guards to #pragma prefast statements which Clang complains about (although it ignores other common #pragma statements such as #pragma warning)

Related: Known Issues: DirectXMath 3.03, DirectXMath 3.06, DirectXMath 3.07, DirectXMath 3.08, DirectXMath 3.09, DirectXMath 3.10

HDR Lighting and Displays

High Dynamic Range (HDR) lighting has been used in games for a long time, popularized by titles like Valve's Half-Life 2 using DirectX 9.0c. The rendering uses float-point render targets, allowing the lighting to exceed the normal 0 to 1 range. Then the final result is tone-mapped back into normal range for display. The result is much improved contrast, making it easier to see a mix of dark interiors with bright exteriors, more realistic outdoor lighting, and a host of special effects.

Recent advances in display technology are adding the ability to render a wider range of luminance directly on the display, enabling a wider gamut of colors and better handling of HDR images and scenes. The 4k Ultra High Definition (4K UHD) standard includes the HDR10 Media Profile supported by game consoles like the Xbox One S and Xbox One X, as well as by Windows PCs running the Windows 10 Creators Update. A range of HDR10 capable TVs and monitors are becoming available.

DeviceResources

The DeviceResources abstraction (DX11 and DX12) used in directx-vs-templates and Xbox-ATG-Samples now supports an options flag for HDR10 display output. To enable this support, you must build the code using the Windows 10 Creators Update SDK (15063) which also implies that you are using VS 2017--the Windows 10 SDK (15063) doesn't officially support use with VS 2015. The code will run on older versions of Windows, but you can only get HDR10 output if running on a PC with the Windows 10 Creators Update as well as the required video card, driver, and display combination.

Note the latest DeviceResources will build with VS 2015 and/or the Windows 10 Anniversary Update SDK (14393), but won't be able to detect HDR10 display output.

DirectX Tool Kit

In order to render an HDR10 swapchain on PC, UWP, and Xbox One, a postprocessing step is typically required to rotate the color space appropriately. To simplify this, I've added a ToneMapEffect (along with other post-processing support) to DirectX Tool Kit (DX11 and DX12). The ToneMapEffect class supports preparing the HDR10 swapchain (rotating from Rec.709 to Rec.2020 color primaries, and applying the ST.2084 curve), as well as traditional tone-mapping for supporting classic Standard Dynamic Range (SDR) displays.

Details on how to use these classes are on the wiki (DX11 and DX12) and in the tutorials (DX11 and DX12).

I've also added HDR10 display support and tone-mapped SDR display support to the DirectX Tool Kit Model Viewer (DX11 and DX12).

DirectXTex

Note that last year I added support for the Radiance RGBE (.hdr) file format as a source for HDR textures to DirectXTex. The texconv and texassemble tools were updated to support .hdr at this time. I also added a -tonemap switch (using a Reinhard local operator) to the command-line tools to support conversions of HDR textures to SDR range for debugging and diagnostics.

In addition to .hdr file format support, I added instructions/support for opting in to support OpenEXR (.exr) as well. See Adding OpenEXR for more information. Thanks to some community efforts, this is now easier to do by obtaining the required OpenEXR and ZLib libraries from NuGet.

This support is also include in the latest DirectX SDK Sample Content Exporter.

Visual Studio 2017 (15.3) update

Since the release of Visual Studio 2017 in March, there have been two minor updates (15.1 and 15.2) per the new release rhythm. The first update (15.1) integrated the Windows 10 Creators Update SDK (15063), and the second update (15.2) included fixes for the IDE and tools. Neither of these updates included significant changes to the C/C++ compiler beyond a few specific hotfixes. The first major revision to the Visual C++ 19.1 compiler and libraries is now available with the latest update: Visual Studio 2017 (15.3).

If you already have VS 2017 installed, run the "Visual Studio Installer" application on your system to apply the update. If you don't yet have VS 2017 installed, you can download the latest installer from here.

The latest VS 2017 Redistribution packages are available (x86, x64), as well as the Remote Debugging Tools (x86, x64). For more on the Visual Studio 2017 (15.3) update, see the release notes.

Note:  The Lightweight Solution Load option that does a partial load of projects for large C++ solutions is included in this update.

Compiler and CRT

VS 2017 (15.3) inclues a new version of the C/C++ compiler (19.11.25506). See this blog post for details on the latest Standard conformance and language/library fixes. There are a few new warnings--a few of which are currently off-by-default but quite useful for portability--detailed in this blog post. The latest update also includes support for AVX-512 intrinsics.

Note: Per this blog post, the _MSC_VER value is now 1911 instead of 1910.

The C/C++ Runtime (14.11.25325) is included in this update. Remember that VS 2015 and VS 2017 share the same runtime redistributable binaries and that VS 2015 Update 3 is binary compatible with VS 2017--code or static library built with one can be linked to the other--, so this is the latest version for both.

The C++ Core Guidelines checker has also been updated. See this blog post as well as this one.

directx-vs-templates: The VS 2017 (15.3) includes a fix with my Direct3D game templates if using them on a system without VS 2015 installed side-by-side.

Related: Visual Studio 2017 RTM

Windows 10 Fall Creators Update SDK

The Windows 10 Fall Creators Update will be released October 17 is now available. The Windows 10 Fall Creators Update SDK (10.0.16299) is now available and can be installed via VS 2017 (15.4) or as a standalone installer. This includes DirectXMath 3.11, updated DirectX 12, and updated Direct2D/DirectWrite.

The Windows 10 Fall Creators Update SDK resolves a number of conformance errors in Windows system headers enabling the use of the /permissive- switch with the latest two-phase name lookup (thus allowing you to avoid the need to use /Zc:twoPhase-).

Note: See KB4034825 for some deprecation notes for the Windows 10 Fall Creators Update

C/C++ Compiler: The VS 2017 (15.4) compiler contains a few servicing updates since the previous update (version 19.11.25547).

C++/WinRT: New C++/WinRT headers for this Windows 10 SDK are now available on GitHub and NuGet.

FXC: With the Windows 10 SDK (15063/16299), the FXC compiler and the D3DCompiler_47.DLL were made side-by-side. From the Developer Command Prompt for VS 2017, using FXC will use the Windows 10 Anniversary Update (14393) version. You need to explicitly select the side-by-side version if you want to use a newer one from the command-line: "%WindowsSdkBinPath%%WindowsSDKVersion%\x86\fxc.exe"

Samples: Windows-universal-samples and DirectX-Graphics-Samples have been updated to use the new Windows 10 SDK (16299). There is also a new version of D3DX12.H updated for the updated Direct3D 12 headers (now included in directx-vs-templates)

Related: Windows 10 SDK RTM, Windows 10 SDK (November 2015), Windows 10 Anniversary Update SDK, Windows 10 Creators Update SDK

CodePlex vs. GitHub

Note that as of today, CodePlex is now 'read-only' per this blog post and this announcement. I've been recommending people using CodePlex for DirectX Tool Kit for DirectX 11, DirectXTex, DirectXMesh, and UVAtlas move to using GitHub for some time, but it's now official. The CodePlex archive is expected to stay online as read-only, but with respect to my projects the GitHub version is now the only repo and the CodePlex version is an outdated mirror.

DirectXMesh GitHub
CodePlex (read-only, last updated September 2017)
DirectXTex GitHub
CodePlex (read-only, last updated September 2017)
DirectXMath GitHub
DirectX Tool Kit (DX11) GitHub
CodePlex (read-only, last updated September 2017)
DirectX Tool Kit (DX12) GitHub
UVAtlas GitHub
CodePlex (read-only, last updated September 2017)
DXUT GitHub
CodePlex (read-only, last updated July 2017)
Effects 11 GitHub
CodePlex (read-only, last updated March 2017)
Viewing all 72 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>