Quantcast
Channel: Games for Windows and the DirectX SDK
Viewing all 44 articles
Browse latest View live

Object Naming

$
0
0

One of the new features for the PIX for Windows tool for the upcoming June 2010 DirectX SDK release is support for object naming. This is a long-standing feature of the Direct3D 10.x and Direct3D 11 SDK Debug Layers, but not a well advertised one. We've mentioned it in a few talks (including in the appendix to my recent Gamefest 2010 and GDC 2010 DirectX 11 Technology Update), but as we are still going through the process of posting this material I thought I would take a few moments to highlight it.

When using the SDK Debug Layer, you will get diagnostic messages about resources like:

D3D11: INFO: Destroy Buffer: Name="unnamed", Addr=0x002A55A4 [ STATE_CREATION INFO #2097230: DESTROY_BUFFER ]

While I'm sure everyone finds hexidecimal dumps of pointers incredibly informative, it would be nice if you had an easy way to associate a label with it for debugging purposes. That's where Object Naming comes in. You see the Name="unnamed" part? That's because the default name is being used here and looks like every other unnamed object in your application.

To name objects for the SDK Debug Layer, you make use of the SetPrivateData API that is part of the root interface for both Direct3D 10.x and 11. The method's signature is:

HRESULT SetPrivateData(  REFGUID guid, UINT DataSize,  const void *pData );

Which as you can see is very generic. The runtime itself does not recognize any GUID here, but the SDK's Debug Layer does intercept it when using certain special GUIDs. The only one currently defined is WKPDID_D3DDebugObjectName (the "WK" standing for, somewhat ironically in this case, "Well Known"), defined in the D3DCommon.h header. It takes a pointer to an ASCII (not Unicode) buffer, and the size should be the length of the string ignoring the terminating NUL. Something like the following:

#if defined(_DEBUG) || defined(PROFILE)
// Only works if device is created with the D3D10 or D3D11 debug layer, or when attached to PIX for Windows
const char c_szName[] = "texture.jpg";
pObject->SetPrivateData( WKPDID_D3DDebugObjectName,
 sizeof( c_szName ) - 1, c_szName );
#endif

This ASCII string is captured by the SDK Debug Layer and included in diganostic messages using that object.

Neat!

The new PIX for Windows feature for June 2010 is that it too recognizes these names and includes them in the buffer views, making them useful for both the debug layer as well as PIX debugging and performance work. This could also be used by other third-party tools as well since it is a "well-known" GUID. To make this feature easier to use, we've also added a helper macro DXUT_SetDebugName() to both DXUT and DXUT11 in the DXUTmisc.h header for June 2010, as well as defining the GUID in the DXGUID.LIB library.

Update: Note that we also updated the Direct3D 11 samples, DXUT, and DXUT11 to populate debug names (in DEBUG and PROFILE configurations). Running PIX for WIndows on these samples should show object names for most items in the "Objects" window.

Additional: There is also a nice C++ way to do this as well:

template<UINT TNameLength>
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource,
_In_z_ const char (&name)[TNameLength])
{
  #if defined(_DEBUG) || defined(PROFILE)
     resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
  #endif
}

SetDebugObjectName( pObject, "texture.jpg" );

Direct3D 12: There is a SetName method you can use for object naming. Note that it takes a Unicode rather than ANSI string.


Announcement: DirectX SDK (June 2010) is live

$
0
0

The June 2010 release of the DirectX SDK is now available on Microsoft Downloads. This release introduces official support for Visual Studio 2010, an updated version of the HLSL compiler with numerous fixes and minor improvements, improved documentation and samples, XNAMath C++ SIMD library version 2.03, and PIX for Windows usability improvements.

For download details, see the DirectX Developer Center and What’s New and Release Notes for June 2010.

The updated DirectX SDK documentation and Windows DirectX Graphics documentation are both currently posted to MSDN.

The corresponding DirectX End-User Runtime with the June 2010 updated DLLs for D3DX9/10/11, D3DCSX, D3DCompiler, XAUDIO2, and XACT is also available online (Web or stand-alone).

Update: Please note that the REDIST folder for the DirectX SDK (June 2010) is slightly out of date now. You should make use of the refreshed version of DirectSetup if you need the REDIST.

Known Issues: Be sure to read this article for known issues trying to install the DirectX SDK (June 2010) due to a problem with the Visual Studio 2010 CRT.

Note: The DirectX SDK is now legacy. You should use the Windows 8.1 SDK instead, or at least prefer the Windows 8.1 SDK over the legacy DirectX SDK as much as possible.

Related:DirectX SDKs of a certain age, The Zombie DirectX SDK, Living without D3DX, DirectX SDK Tools Catalog, and DirectX SDK Samples Catalog

DirectX 11.1 and Windows 7

$
0
0

Windows 8 includes an updated “DirectX 11.1 Runtime” that supports Direct3D 11.1, updates Direct2D and DirectWrite, DXGI 1.2, and a revision of the Windows Imaging Component (WIC).

Portions of the “DirectX 11.1 Runtime” are being made available on Windows 7 Service Pack 1 via the Platform Update for Windows 7 Service Pack 1 and Windows Server 2008 R2 Service Pack 1 (KB 2670838) included with Internet Explorer 10 for Windows 7. This includes the updated components above, but is limited to WDDM 1.1 drivers on Windows 7.

Full technical details on what is and is not included in the update are available on MSDN. For information about IE10 compatibility, see this article.

Note: KB 2670838 does not include XINPUT 1.4 or XAudio 2.8 on Windows 7. These remain Windows 8 exclusive. See XINPUT and Windows 8 and XAudio2 and Windows 8 for guidance on handling this difference in Win32 desktop applications.

Update:KB 2670838 and Internet Explorer 10 for Windows 7 are now available. Users with the prerelease version installed should update their systems (DirectX 11.1 and Windows 7 Update).

Notes for users of the DirectX SDK

The updated headers and link libraries needed to target the new components on Windows 8 and Windows 7 are in the Windows 8.x SDK as indicated in previous posts (see Where is the DirectX SDK?). See MSDN for details on ‘mixing’ the Windows 8.x SDK and legacy DirectX SDK if needed.

It is also important to note that the updated “Debug Runtime” components in the Windows 8.x SDK are required on Windows 7 once KB 2670838 is installed. The legacy DirectX SDK (June 2010)“Debug Runtime” for Direct3D 10.x and Direct3D 11.0 is not compatible with Windows 10, Windows 8.x or Windows 7 once this update is applied. You can install the Windows 8.x SDK standalone, VS 2012 or VS 2013 which includes the Windows 8.x SDK, or the VS 2013 Remote Debugging Tools (x86 or x64) to get the updated SDK Debug Layers files.

The legacy PIX for Windows tool in the DirectX SDK (June 2010) release does not support Direct3D 10.x or Direct3D 11.x applications on Windows 8, and after this update is applied it will no longer support these applications on Windows 7. Direct3D 9 application debugging continues to function.

Related:DirectX SDK Tools Catalog

Notes for users of VS 2012

Visual Studio 2012’s Graphics Debugger supports Direct3D 11.0 applications on Windows 7 and DirectX 11.x applications on Windows 8. Improved support for KB 2670838 is in VS 2012 Update 2.

When using VS 2012 Update 1's new "v110_xp" Platform Toolset the DirectX 11.1, WIC2, and related headers are not available.

DirectX 11.1 and Windows 7 Update

$
0
0

As of today, IE 10 for Windows 7 has been officially released. IE10 for Windows 7 includes portions of the DirectX 11.1 runtime for Windows 7 Service Pack 1 and Windows Server 2008 R2 Service Pack 1 via KB 2670838.

Full technical details of what's included in KB 2670838 are covered on MSDN. The primary difference between the prerelease and the final version is that WARP supports Feature Level 11.0 with the updated runtime.

See DirectX 11.1 and Windows 7 for some additional notes about KB 2670838 as it impacts PIX for Windows, the debug runtime, and VS 2012 Graphics Diagnostics. The key issue is that the legacy DirectX SDK (June 2010) release version of the Debug Runtime is not compatible with KB 2670838. You can resolve this by installing the Windows 8.0 SDK standalone, VS 2012 which includes the Windows 8.0 SDK, or the VS 2012 Remote Debugging Tools (x86 or x64).

Note: If you have the prerelease of either IE10 or KB 2670838 installed, you should update your system. Windows Update will be offering an update soon, but you can manually install it as well.

IE11: There is an IE11 Preview for Windows 7 now available. It requires KB 2670838 as well.

DXDIAG: Even after applying KB 2670838 to Windows 7 SP1, DXDIAG will still report it as "DirectX 11".

XINPUT and XAUDIO2: KB 2670838 does not include XINPUT 1.4 or XAudio 2.8 on Windows 7. These remain Windows 8 exclusive. See XINPUT and Windows 8 and XAudio2 and Windows 8 for guidance on handling this difference in Win32 desktop applications. 

WIC: KB 2670838 includes WIC2 for Windows 7. See Windows Imaging Component and Windows 8 for details.

Media Foundation: KB 2670838 does not include the updates to Media Foundation to use DirectX 11 Video support. To render video to a texture, you must use DXGI shared surfaces prior to Windows 8.0.

DirectX 11 vs. 11.1: For Windows 7 and Windows Vista, you can continue to use the same DirectX 11.0 APIs as always even with this update installed. The only thing you have to do is to install the updated SDK Debug Layers to restore D3D11_CREATE_DEVICE_DEBUG functionality. If you want to take advantage of some of the new DirectX 11.1 APIs now available on Windows 7 as well, you need to use the Windows 8.0 SDK with VS 2010 or VS 2012 rather than continuing to use the legacy DirectX SDK. See Where is the DirectX SDK? and DirectX SDKs of a certain age for details.

VS 2012: There is improved support for using VS 2012 Graphics Diagnostics on Windows 7 with KB 2670838 installed in the VS 2012 Update 2. Installing the KB also enables GPU debugging for C++ AMP programs.

VS 2013: The original release of VS 2013 RTM had a prerequisite of installing IE10, which in turn required KB 2670838. This setup requirement has been removed for Windows 7 systems in a refreshed setup, but may result in some reduced functionality (see KB 2906882).

Visual Studio 2015 RTM

$
0
0

Visual Studio 2015 RTM is now available for download, including the updated Community edition. The VS 2015 RTM Redistribution packages are also available (x86, x64), as well as the Remote Debugging Tools (x86, x64, ARM). For more information, see the Visual C++ Team blogBrian Harry’s blog, Somasegar’s blog, and the Visual Studio Team blog.

The C++11 language and standard library tables in the Dual-use Coding Techniques for Games article has been updated for VS 2015 RTM, and you can find much more information about these changes for VS 2015 on the Visual C++ Team blog. Be sure to read the MSDN page Breaking Changes in Visual C++ as well. There are also a number of new warnings in place including format specifier checking that previously required the use of /analyze.

REDIST: VS 2015 can target Windows 10, Windows 8.1, Windows 8.0, Windows 7 Service Pack 1, Windows Vista Service Pack 2, and optionally Windows XP Service Pack 3. Note that the Visual C++ 2015 REDIST does not support 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 KB2661358.

Visual C++: Note that with VS 2015 RTM, the C++ toolset is not included in the Typical installation. You must select it through the Custom selection. See the Visual C++ Team blog.

Windows 10 DirectX Development: Be sure to read this post on how to enable the DirectX debug device for Windows 10. Installing VS 2015 RTM (or VS 2013 Update 5) on Windows 10 will automatically enable the Graphics Tools Windows optional feature.

Windows XP: When building using the “v140_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 2015, 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, and DirectX SDK Samples Catalog

Windows 8.1 SDK: VS 2015 RTM includes the Windows 8.1 SDK Spring Update 2015 with DirectXMath 3.07. You can also download the standalone Windows 8.1 SDK Spring 2015 update.

Windows 10 SDK: Universal Windows apps (UWA) developers should stick with using VS 2015 RC until the final Visual Studio Tools and Windows 10 SDK packages are released next week. See this blog post about adding the Windows 10 SDK 10240 tools to VS 2015 RTM.

VS Content Pipeline: The built-in mesh content exporter in VS 2015 makes use of Autodesk FBX 2015.1–VS 2012 and 2013 used 2013.1.

Related: VS 2015 Update 1

DXGI Debug Device

$
0
0

In my original post on using the debug layer, I mentioned several tricks for getting helpful behavior out of the Direct3D SDK debug layer for your applications. This best practice is demonstrated in my Visual C++ Game templates as follows:

 #ifndef NDEBUG
Microsoft::ComPtr<ID3D11Debug> d3dDebug;
hr = m_d3dDevice.As(&d3dDebug);
if (SUCCEEDED(hr))
{
       ComPtr<ID3D11InfoQueue> d3dInfoQueue;
       hr = d3dDebug.As(&d3dInfoQueue);
       if (SUCCEEDED(hr))
       {
#ifdef _DEBUG
              d3dInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
              d3dInfoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
#endif
              D3D11_MESSAGE_ID hide [] =
              {
                     D3D11_MESSAGE_ID_SETPRIVATEDATA_CHANGINGPARAMS,
              // TODO: Add more message IDs here as needed
              };
              D3D11_INFO_QUEUE_FILTER filter;
              memset(&filter, 0, sizeof(filter));
              filter.DenyList.NumIDs = _countof(hide);
              filter.DenyList.pIDList = hide;
              d3dInfoQueue->AddStorageFilterEntries(&filter);
       }
}
#endif

This snippet ensures that a common but harmless warning message is suppressed in non-Production builds, and enables ‘break on’ functionality in Debug builds if there are any serious corruption or error messages.

With the Direct3D 11.1 Runtime or later, you can also use a DXGI debug interface to track down additional leaks that are not known to your Direct3D 11 device. How this new interface is exposed, however, is a bit confusing.

For traditional Windows desktop apps, you are expected to use explicit linking. Since the DXGI debug layer is not present on end-user machines, this pattern encourages being able to handle the case of it not being present on the system. The confusing part is that the function you need, DXGIGetDebugInterface is not defined in any header and is not present in any import library.

#include <dxgidebug.h>
#if defined(_DEBUG)
    Microsoft::WRL::ComPtr<IDXGIInfoQueue> dxgiInfoQueue;
 
    typedef HRESULT (WINAPI * LPDXGIGETDEBUGINTERFACE)(REFIID, void ** );
 
    HMODULE dxgidebug = LoadLibraryEx( L"dxgidebug.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32 );
    if ( dxgidebug )
    {
        auto dxgiGetDebugInterface = reinterpret_cast<LPDXGIGETDEBUGINTERFACE>(
            reinterpret_cast<void*>( GetProcAddress( dxgidebug, "DXGIGetDebugInterface" ) ) );
 
        if ( SUCCEEDED( dxgiGetDebugInterface( IID_PPV_ARGS( dxgiInfoQueue.GetAddressOf() ) ) ) )
        {
            dxgiInfoQueue->SetBreakOnSeverity( DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR, true );
            dxgiInfoQueue->SetBreakOnSeverity( DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION, true );
        }
    }
#endif
 

One issue with this pattern is that you can’t use it for Windows Store or universal Windows apps since LoadPackagedLibrary cannot load a system DLL as a security measure. In the DirectX 11.2 Runtime (Windows 8.1 and Windows 10), there is now a DXGIGetDebugInterface1 defined in the dxgi1_3.h header and in the dxgi.lib import library. This implicit linking works fine for Windows Store apps and UWP, but for desktop apps you should stick with the explicit method particularly if you need Windows 7 support as this function is not present in the 11.1 or 11.0 runtime.

#if defined(_DEBUG)
Microsoft::WRL::ComPtr<IDXGIInfoQueue> dxgiInfoQueue;
if ( SUCCEEDED( DXGIGetDebugInterface1( 0, IID_PPV_ARGS( dxgiInfoQueue.GetAddressOf() ) ) ) )
{
       dxgiInfoQueue->SetBreakOnSeverity( DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR, true );
       dxgiInfoQueue->SetBreakOnSeverity( DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION, true );
}
#endif

As with the Direct3D debug layer, there is a method for reporting live DXGI objects as well for tracking down resource leaks. You obtain a IDXGIDevice instance the same was as you do a IDXGIInfoQueue interface above, and then call ReportLiveObjects.

DXGUID: One other issue of note is that the various DXGI debug control GUIDs (i.e. DXGI_DEBUG_ALL) are missing from DXGUID.LIB. You have to define it yourself using INITGUID. This is fixed for the Windows 10 SDK.

Related: Direct3D SDK Debug Layer Tricks, DirectX 11.1 and Windows 7 Update

Windows 10 SDK RTM

$
0
0

Last week saw the release of the final version of VS 2015, and yesterday was the release of the Windows 10 SDK (build 10240). The Windows 10 SDK is installed via VS 2015 Custom install options or as a standalone installer. This includes DirectXMath 3.07, Direct3D 11.3, Direct3D 12.0, DXGI 1.4, Direct2D/DirectWrite 1.3, and XAudio 2.9.

VS 2015 Users: Be sure to read this blog post about configuring your VS 2015 projects to use the 10240 build of the Windows 10 SDK–remember that Windows desktop applications with VS 2015 default to building with the Windows 8.1 SDK Spring 2015 release.

GitHub: All of my open source project have new releases to support VS 2015 and Windows 10 SDK RTM: DirectXTK, DirectXTex, DirectXMesh, UVAtlas, Effects11, and DXUT11.

Direct3D 12: The samples for Windows desktop development using Direct3D 12 are on GitHub. Note that WARP12 is part of the Graphics Tools optional feature as it’s currently intended only for use by developers.

XInput: For UWP, you can continue to use the XInput 1.4 API but need to change from linking to xinput.lib to xinputuap.lib. Alternatively, you can make use of the GamePad class in DirectX Tool Kit which uses the new Windows.Gaming.Input API. See XInput and Windows 8.

XAudio: With the Windows 10 SDK, if you are linking with xaudio2.lib you are linking against XAudio 2.9 and should build your application using _WIN32_WINNT=0x0A00. If you want to use XAudio 2.8 with the Windows 10 SDK, you need to set _WIN32_WINNT=0x0602 or _WIN32_WINNT=0x0603 and link against xaudio2_8.lib. See XAudio2 and Windows 8 for more details.

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

Samples: Official Windows samples are hosted on GitHub: Windows-universal-samplesWindows-classic-samples, Windows-driver-samples. See also DirectX SDK Samples Catalog.

Related: Windows 10 SDK (November 2015)

Windows10SDKVS13.zip

Where is the DirectX SDK (2015 Edition)?

$
0
0

As noted on MSDN, the DirectX SDK is deprecated. The June 2010 release is the last release, and “DirectX” is now part of the Windows SDK. There are really only three scenarios where you should continue to use the old DirectX SDK:

  1. You have code (or perhaps an older book) that makes use of D3DX9, D3DX10, D3DX11, or XACT Engine.
  2. Your application uses use XAudio2 and supports Windows 7 systems.
  3. You are targeting Windows XP with the alternate v1x0_xp Platform Toolset.

Developer Runtime: The Windows 8.1 SDK or Windows 10 SDK is where you obtain the latest DirectX Developer Runtime that is compatible with Windows 7, Windows 8.0, and Windows 8.1. The DirectX Developer Runtime for Windows 10 is an optional Windows feature you enable in the operating system. You can also enable it on Windows 10 via the command-line using an admin prompt:

Dism /online /add-capability /capabilityname:Tools.Graphics.DirectX~~~~0.0.1.0

D3DX: All versions of D3DX are deprecated including D3DX9, D3DX10, and D3DX11. See Living without D3DX for replacements and recommendations including DirectX Tool Kit, DirectXTex, DirectXMesh, and UVAtlas on GitHub.

FX: The latest version of Effects for Direct3D 11 is available on GitHub and does not require the legacy DirectX SDK or any version of D3DX.

DXUT: The latest version of DXUT for Direct3D 11 is available on GitHub and does not require the legacy DirectX SDK or any version of D3DX.

Tools: Some of the developer tools are in the Windows SDK others are not. See DirectX SDK Tools Catalog for a complete inventory.

Samples: A number of samples from the DirectX SDK (June 2010) release have been updated and posted to GitHub. They do not require the legacy DirectX SDK or any version of D3DX. See DirectX SDK Samples Catalog.

The Windows 10 SDK includes the latest headers and link libraries for DirectX including Direct3D 12.0, Direct3D 11.3, DXGI 1.4, Direct2D/DirectWrite 1.3, and XAudio 2.9.

Both the Windows 8.1 SDK Spring 2015 update and the Windows 10 SDK include Direct3D 11.0/11.1/11.2, DXGI 1.0/1.1/1.2/1.3, DirectXMath 3.07, and Direct2D/DirectWrite 1.0/1.1/1.2. They also include the legacy Direct3D 10.0/10.1, Direct3D9Ex, Direct3D 9 headers, DirectSound8, DirectInput8, and DirectMusic “core” APIs. See DirectX SDKs of a certain age for a full catalog of older DirectX APIs and their locations.

XInput: The Windows 10 SDK includes the Windows.Gaming.Input WinRT API which is supported on Windows 10. Both the Windows 8.1 SDK and Windows 10 SDK include XInput 1.4 which is supported on Windows 8.x and Windows 10. You should use XInput 9.1.0 to support Windows 7. See XINPUT and Windows 8 and DirectX Tool Kit: Now with GamePads.

XAudio: The Windows 10 SDK includes XAudio 2.9 which is supported on Windows 10. The Windows 8.1 SDK and Windows 10 SDK include XAudio 2.8 which is supported on Windows 8.x and Windows 10. You have to use the legacy DirectX SDK and XAudio 2.7 to support Windows 7. See XAudio2 and Windows 8 and Known Issues: XAudio 2.7.

DirectX SDK: If you need to make use of legacy DirectX SDK components such as D3DX9, D3DX10, D3DX11, or XAudio 2.7 with VS 2012, VS 2013 or VS 2015, see MSDN for details on mixing the Windows 8 or Windows 10 SDK correctly with the legacy DirectX SDK. Be sure to The Zombie DirectX SDK as well. If you are targeting Windows XP which makes use of the Windows 7.1A SDK, see Visual Studio 2012 Update 1.

DirectX 12

There is something called the DirectX 12 SDK which was used as a beta vehicle for the development of DirectX 12 through the Early Access Program. Now that the Windows 10 SDK is final, you don’t need access to the DirectX 12 SDK at all. The DirectX 12 samples are on GitHub. Note that there is also a header file called d3dx12.h which is an all inline header with some utility code shipped in the GitHub samples.

Related: Where is the DirectX SDK (2013 Edition)?

See also: Where is DXERR.LIB?, GDF Tools, XDSP.H, SH Math


DirectX Tool Kit: Keyboard and Mouse support

$
0
0

The GamePad abstraction in DirectX Tool Kit was designed to simplify implementing game controller input across the spectrum of platforms supported by DirectX Tool Kit: Windows desktop, Xbox One, Windows 8 Store, and now universal Windows Apps for Windows 10. In a similar vein, the July 2015 release of DirectX Tool Kit includes two new classes for handling keyboard and mouse input across Windows desktop, Windows 8 Store, and universal Windows apps for Windows 10.

Keyboard

The Keyboard class is as usual based on the XNA Game Studio design, with the primary difference being that I needed to use a singleton rather than a static class. As with the XNA Game Studio class, this is intended for using the keyboard as a ‘game controller’ mapping keys to game input events. To support full text input for chat or text editing, you should make use of the underlying platform’s keyboard support to fully handle international input. Integration of the Keyboard class is slightly more complicated than GamePad in that after creating the class instance, you need to make the appropriate calls from either your Win32 message pump for keyboard messages in Windows desktop apps, or you need to provide your application’s CoreWindow so that Keyboard can register for the needed callbacks.

For Windows desktop applications, Keyboard takes input from WM_KEYUP, WM_KEYDOWN, WM_SYSKEYUP, and WM_SYSKEYDOWN Win32 messages. For Windows 8 Store and universal Windows apps, it makes use of CoreDispatcher::AcceleratorKeyActivated. As with XNA Game Studio, the Keyboard::State object encodes the virtual keys (rather than scan codes). This works well for most key combinations, but this is a bit quirky when handling Left vs. Right Shift keys (details in the class documentation).

The abstraction makes writing keyboard-based controls quite simple and portable across the supported platforms:

void Game::Update(DX::StepTimer const& timer)
{

auto kb = m_keyboard->GetState();

if (kb.Up || kb.W)
move.y += 1.f;

if (kb.Down || kb.S)
move.y -= 1.f;

if (kb.Left || kb.A)
move.x += 1.f;

if (kb.Right || kb.D)
move.x -= 1.f;
}

See the documentation wiki page on the new class for details, and the related tutorial.

Mouse

The basics of the Mouse class are borrowed from XNA Game Studio, but is also singleton rather than a static class as well as having explicit support for a ‘relative’ or ‘mouse-look’ input mode. Integration of the Mouse class is slightly more complicated than GamePad in that you need to make the appropriate calls from either your Win32 message pump for mouse messages in Windows desktop apps, or you need to provide your application’s CoreWindow so that Mouse can register for the needed callbacks.

For Windows desktop applications, Mouse uses WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_MOUSEWHEEL, etc. events for handling the default ‘absolute’ mouse position mode. When in the ‘relative’ mode, it uses WM_INPUT per the Taking Advantage of High-Definition Mouse Movement article.

For Windows 8 Store and universal Windows apps, Mouse makes use of the standard CoreWindow::PointerMoved, CoreWindow::PointerPressed, etc. events for handling the default ‘absolutely’ mouse position mode per Responding to touch input (DirectX and C++). For these platforms, the Mouse class also handles the conversion of DIPs to pixels, so be sure to call SetDPI appropriately. When in ‘relative’ mode, it uses CoreWindow::MouseMoved per Developing mouse controls (DirectX and C++).

The abstraction makes implementing mouse controls simple and reasonably portable between the supported platforms:

void Game::Update(DX::StepTimer const& timer)
{
auto state = g_mouse->GetState();
if (state.positionMode == Mouse::MODE_RELATIVE)
{
// state.x and state.y are relative values; system cursor is not visible
}
else
{
// state.x and state.y are absolute pixel values; system cursor is visible
}

tracker.Update(state);

if (tracker.leftButton == Mouse::ButtonStateTracker::ButtonState::PRESSED)
{
mouse->SetMode(Mouse::MODE_RELATIVE);
}
else if (tracker.leftButton == Mouse::ButtonStateTracker::ButtonState::RELEASED)
{
mouse->SetMode(Mouse::MODE_ABSOLUTE);
}

}

See the documentation wiki page on the new class for details, and the related tutorial.

DirectInput: Developers are strongly discouraged from using legacy DirectInput for handling keyboard and mouse processing as far back as Windows XP. DirectInput should really only be used for supporting legacy HID game controllers and joysticks.

Known Issues: XAudio 2.7

$
0
0

The XAudio2 library in the legacy DirectX SDK makes use of COM creation and reference counting for lifetime management, and a recent investigation has found a problem in this implementation. In short: in some situations the XAudio DLL itself is unloaded before the XAudio2 objects are completely destroyed, thus leading to an access violation. This normally happens on exit, although the exact details of when it might be evident depends on exactly which version of Windows you are using and the overall process layout for your application.

This issue does not affect XAudio 2.8 (Windows 8 SDK), XAudio 2.9 (Windows 10 SDK), XAudio2 on Xbox 360, or XAudio2 on Xbox One.

An application level workaround is very easy to implement, and is already implemented in DirectX Tool Kit for Audio and in the XAudio2 DirectX SDK refreshed samples on GitHub.

Before your first XAudio object creation, you should create an explicit reference to the DLL and hold on to it.

 #if ( _WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
HMODULE g_XAudioDLL = nullptr;
#endif

...

#if ( _WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
#ifdef _DEBUG
g_XAudioDLL = LoadLibraryExW( L"XAudioD2_7.DLL", nullptr, 0x00000800 /* LOAD_LIBRARY_SEARCH_SYSTEM32 */ );
#else
g_XAudioDLL = LoadLibraryExW( L"XAudio2_7.DLL", nullptr, 0x00000800 /* LOAD_LIBRARY_SEARCH_SYSTEM32 */ );
#endif
if ( !mXAudioDLL )
// error
#endif

...

DWORD creationFlags = 0;
#if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) && defined(_DEBUG)
creationFlags |= XAUDIO2_DEBUG_ENGINE;
#endif
IXAudio2* pXAudio2 = nullptr;
HRESULT hr = XAudio2Create( &pXAudio2, creationFlags, XAUDIO2_DEFAULT_PROCESSOR );
if ( FAILED(hr) )
// error

From here on, you work with XAudio2 as normal, delete objects, etc. Later after you do all cleanup and are fully done with working with XAudio2, you release the “extra” DLL reference:

 if (pXAudio2)
pXAudio2->Release();

...

#if ( _WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
if (g_XAudioDLL)
{
FreeLibrary(g_XAudioDLL);
g_XAudioDLL = nullptr;
}
#endif

This ensures that the DLL is not unloaded while XAudio2 objects are active.

See also: XAudio2 and Windows 8, Learning XAudio2, Windows 10 SDK RTM

Visual Studio 2015 Update 1

$
0
0

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

Compiler and CRT

VS 2015 Update 1 includes a new version of the C/C++ compiler (19.00.23506). There is also a new version of the C/C++ Runtime (14.0.23506). Here are a list of STL fixes included in VS 2015 Update 1. The new compiler also includes support for the C++11 language feature Expression SFINAE.

Note that VS 2015 can target Windows 10, Windows 8.1, Windows 8.0, Windows 7 Service Pack 1, Windows Vista Service Pack 2, and optionally Windows XP Service Pack 3. The Visual C++ 2015 REDIST does not support 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 KB2661358.

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

.NET: There is now a 4.6.1 release including a number of Windows Presentation Foundation (WPF) improvements including a D3DImage for Direct3D 11 available on GitHub.

Related: Visual Studio 2015 RTM

Windows 10 SDK (November 2015)

$
0
0

The Windows 10 SDK for the November 2015 update of Windows 10 (build 10586) is now available. It can be installed via an optional install with VS 2015 Update 1 or as a standalone installer. This includes DirectXMath 3.08, Direct3D 11.4, Direct3D 12.0, DXGI 1.5, Direct2D/DirectWrite 1.3, and XAudio 2.9.

GitHub: All of my open source project have new releases to support VS 2015 Update 1 and the Windows 10 SDK (10586): DirectXTK, DirectXTex, DirectXMesh, UVAtlas, Effects11, and 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 10240 to 10586, 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.

XInput: For UWP, you can continue to use the XInput 1.4 API but need to change from linking to xinput.lib to xinputuap.lib. Alternatively, you can make use of the GamePad class in DirectX Tool Kit which uses the new Windows.Gaming.Input API. See XInput and Windows 8.

XAudio: With the Windows 10 SDK, if you are linking with xaudio2.lib you are linking against XAudio 2.9 and should build your application using _WIN32_WINNT=0x0A00. If you want to use XAudio 2.8 with the Windows 10 SDK, you need to set _WIN32_WINNT=0x0602 or _WIN32_WINNT=0x0603 and link against xaudio2_8.lib. See XAudio2 and Windows 8 for more details.

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

Samples: As with the Windows 10 SDK RTM, 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

Windows10SDKVS13-10586.zip

DirectXMath 3.08

$
0
0

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)

Related: Known Issues: DirectXMath 3.03, DirectXMath 3.06

Direct3D Game Visual Studio templates (Redux)

$
0
0

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.

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

$
0
0

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

$
0
0

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.

Compiler and CRT

VS 2015 Update 3 includes a new version of the C/C++ compiler (19.00.24210.0). There is also a new version of the C/C++ Runtime (14.0.24212). See these posts for details about the compiler, optimizer, 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

$
0
0

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.

Windows 10 Anniversary Update SDK

$
0
0

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.

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.

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

$
0
0

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

$
0
0

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

Viewing all 44 articles
Browse latest View live


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