Loading .gitignore +3 −2 Original line number Diff line number Diff line Loading @@ -28,8 +28,9 @@ Release x64 Kits/DirectXTK/Src/Shaders/Compiled/XboxOne*.* Kits/DirectXTK12/Src/Shaders/Compiled/XboxOne*.* Samples/Graphics/SimplePBR12/Compiled/ Samples/Tools/errorlookup/errorlookup/project.lock.json UWPSamples/Graphics/SimplePBR12/Compiled/ UWPSamples/Tools/errorlookup/errorlookup/obj/ UWPSamples/Tools/errorlookup/errorlookup/project.lock.json /wiki AppPackages packages Loading Kits/ATGTK/ATGColors.h +12 −0 Original line number Diff line number Diff line Loading @@ -41,4 +41,16 @@ namespace ATG XMGLOBALCONST DirectX::XMVECTORF32 OffWhite = { 0.361306787f, 0.361306787f, 0.361306787f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 White = { 0.955973506f, 0.955973506f, 0.955973506f, 1.f }; }; namespace ColorsHDR { XMGLOBALCONST DirectX::XMVECTORF32 Background = { 0.052860655f * 2.f, 0.052860655f * 2.f, 0.052860655f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 Green = { 0.005181516f * 2.f, 0.201556236f * 2.f, 0.005181516f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 Blue = { 0.001517635f * 2.f, 0.114435382f * 2.f, 0.610495627f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 Orange = { 0.545724571f * 2.f, 0.026241219f * 2.f, 0.001517635f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 DarkGrey = { 0.033104762f * 2.f, 0.033104762f * 2.f, 0.033104762f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 LightGrey = { 0.194617808f * 2.f, 0.194617808f * 2.f, 0.194617808f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 OffWhite = { 0.361306787f * 2.f, 0.361306787f * 2.f, 0.361306787f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 White = { 0.955973506f * 2.f, 0.955973506f * 2.f, 0.955973506f * 2.f, 1.f }; }; } No newline at end of file Kits/ATGTK/ControllerFont.h +4 −4 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ namespace DX float offsetY = buttonScale / 2.f; size_t j = 0; wchar_t strBuffer[4096] = {0}; wchar_t strBuffer[4096] = {}; bool buttonText = false; Loading @@ -67,7 +67,7 @@ namespace DX if (text[ch] == L']') { wchar_t button[2] = { 0 }; wchar_t button[2] = {}; if (_wcsicmp(strBuffer, L"[A]") == 0) { Loading Loading @@ -204,7 +204,7 @@ namespace DX float offsetY = buttonScale / 2.f; size_t j = 0; wchar_t strBuffer[4096] = { 0 }; wchar_t strBuffer[4096] = {}; bool buttonText = false; Loading @@ -219,7 +219,7 @@ namespace DX if (text[ch] == L']') { wchar_t button[2] = { 0 }; wchar_t button[2] = {}; if (_wcsicmp(strBuffer, L"[A]") == 0) { Loading Kits/ATGTK/WAVFileReader.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -496,7 +496,7 @@ static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std: } // Get the file size LARGE_INTEGER FileSize = { 0 }; LARGE_INTEGER FileSize = {}; #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA) FILE_STANDARD_INFO fileInfo; Loading UWPSamples/Audio/AdvancedSpatialSoundsUWP/DeviceResources.cpp +160 −77 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ #include "DeviceResources.h" using namespace DirectX; using namespace DX; using Microsoft::WRL::ComPtr; Loading Loading @@ -83,7 +84,7 @@ namespace ScreenRotation }; // Constructor for DeviceResources. DX::DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel) : DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel, unsigned int flags) : m_screenViewport{}, m_backBufferFormat(backBufferFormat), m_depthBufferFormat(depthBufferFormat), Loading @@ -92,14 +93,17 @@ DX::DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat, DXGI_FORMAT d m_window(nullptr), m_d3dFeatureLevel(D3D_FEATURE_LEVEL_9_1), m_rotation(DXGI_MODE_ROTATION_IDENTITY), m_dxgiFactoryFlags(0), m_outputSize{0, 0, 1, 1}, m_orientationTransform3D(ScreenRotation::Rotation0), m_colorSpace(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709), m_options(flags), m_deviceNotify(nullptr) { } // Configures the Direct3D device, and stores handles to it and the device context. void DX::DeviceResources::CreateDeviceResources() void DeviceResources::CreateDeviceResources() { UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; Loading @@ -115,6 +119,42 @@ void DX::DeviceResources::CreateDeviceResources() } #endif #if defined(_DEBUG) { ComPtr<IDXGIInfoQueue> dxgiInfoQueue; if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(dxgiInfoQueue.GetAddressOf())))) { m_dxgiFactoryFlags = DXGI_CREATE_FACTORY_DEBUG; 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 ThrowIfFailed(CreateDXGIFactory2(m_dxgiFactoryFlags, IID_PPV_ARGS(m_dxgiFactory.ReleaseAndGetAddressOf()))); // Determines whether tearing support is available for fullscreen borderless windows. if (m_options & c_AllowTearing) { BOOL allowTearing = FALSE; ComPtr<IDXGIFactory5> factory5; HRESULT hr = m_dxgiFactory.As(&factory5); if (SUCCEEDED(hr)) { hr = factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allowTearing, sizeof(allowTearing)); } if (FAILED(hr) || !allowTearing) { m_options &= ~c_AllowTearing; #ifdef _DEBUG OutputDebugStringA("WARNING: Variable refresh rate displays not supported"); #endif } } // Determine DirectX hardware feature levels this app will support. static const D3D_FEATURE_LEVEL s_featureLevels[] = { Loading Loading @@ -195,7 +235,7 @@ void DX::DeviceResources::CreateDeviceResources() } #endif DX::ThrowIfFailed(hr); ThrowIfFailed(hr); #ifndef NDEBUG ComPtr<ID3D11Debug> d3dDebug; Loading @@ -220,12 +260,12 @@ void DX::DeviceResources::CreateDeviceResources() } #endif DX::ThrowIfFailed(device.As(&m_d3dDevice)); DX::ThrowIfFailed(context.As(&m_d3dContext)); ThrowIfFailed(device.As(&m_d3dDevice)); ThrowIfFailed(context.As(&m_d3dContext)); } // These resources need to be recreated every time the window size is changed. void DX::DeviceResources::CreateWindowSizeDependentResources() void DeviceResources::CreateWindowSizeDependentResources() { if (!m_window) { Loading Loading @@ -254,7 +294,7 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() backBufferWidth, backBufferHeight, backBufferFormat, 0 (m_options & c_AllowTearing) ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0 ); if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) Loading @@ -273,23 +313,12 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() } else { DX::ThrowIfFailed(hr); ThrowIfFailed(hr); } } else { // Otherwise, create a new one using the same adapter as the existing Direct3D device. // This sequence obtains the DXGI factory that was used to create the Direct3D device above. ComPtr<IDXGIDevice3> dxgiDevice; DX::ThrowIfFailed(m_d3dDevice.As(&dxgiDevice)); ComPtr<IDXGIAdapter> dxgiAdapter; DX::ThrowIfFailed(dxgiDevice->GetAdapter(dxgiAdapter.GetAddressOf())); ComPtr<IDXGIFactory2> dxgiFactory; DX::ThrowIfFailed(dxgiAdapter->GetParent(IID_PPV_ARGS(dxgiFactory.GetAddressOf()))); // Create a descriptor for the swap chain. DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {}; swapChainDesc.Width = backBufferWidth; swapChainDesc.Height = backBufferHeight; Loading @@ -301,9 +330,11 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() swapChainDesc.Scaling = DXGI_SCALING_ASPECT_RATIO_STRETCH; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE; swapChainDesc.Flags = (m_options & c_AllowTearing) ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0; // Create a swap chain for the window. ComPtr<IDXGISwapChain1> swapChain; DX::ThrowIfFailed(dxgiFactory->CreateSwapChainForCoreWindow( ThrowIfFailed(m_dxgiFactory->CreateSwapChainForCoreWindow( m_d3dDevice.Get(), m_window, &swapChainDesc, Loading @@ -311,13 +342,18 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() swapChain.GetAddressOf() )); DX::ThrowIfFailed(swapChain.As(&m_swapChain)); ThrowIfFailed(swapChain.As(&m_swapChain)); // Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and // ensures that the application will only render after each VSync, minimizing power consumption. DX::ThrowIfFailed(dxgiDevice->SetMaximumFrameLatency(1)); ComPtr<IDXGIDevice3> dxgiDevice; ThrowIfFailed(m_d3dDevice.As(&dxgiDevice)); ThrowIfFailed(dxgiDevice->SetMaximumFrameLatency(1)); } // Handle color space settings for HDR UpdateColorSpace(); // Set the proper orientation for the swap chain, and generate // matrix transformations for rendering to the rotated swap chain. switch (m_rotation) Loading @@ -340,13 +376,13 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() break; } DX::ThrowIfFailed(m_swapChain->SetRotation(m_rotation)); ThrowIfFailed(m_swapChain->SetRotation(m_rotation)); // Create a render target view of the swap chain back buffer. DX::ThrowIfFailed(m_swapChain->GetBuffer(0, IID_PPV_ARGS(m_renderTarget.ReleaseAndGetAddressOf()))); ThrowIfFailed(m_swapChain->GetBuffer(0, IID_PPV_ARGS(m_renderTarget.ReleaseAndGetAddressOf()))); CD3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc(D3D11_RTV_DIMENSION_TEXTURE2D, m_backBufferFormat); DX::ThrowIfFailed(m_d3dDevice->CreateRenderTargetView( ThrowIfFailed(m_d3dDevice->CreateRenderTargetView( m_renderTarget.Get(), &renderTargetViewDesc, m_d3dRenderTargetView.ReleaseAndGetAddressOf() Loading @@ -364,14 +400,14 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() D3D11_BIND_DEPTH_STENCIL ); DX::ThrowIfFailed(m_d3dDevice->CreateTexture2D( ThrowIfFailed(m_d3dDevice->CreateTexture2D( &depthStencilDesc, nullptr, m_depthStencil.ReleaseAndGetAddressOf() )); CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D); DX::ThrowIfFailed(m_d3dDevice->CreateDepthStencilView( ThrowIfFailed(m_d3dDevice->CreateDepthStencilView( m_depthStencil.Get(), &depthStencilViewDesc, m_d3dDepthStencilView.ReleaseAndGetAddressOf() Loading @@ -388,7 +424,7 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() } // This method is called when the CoreWindow is created (or re-created). void DX::DeviceResources::SetWindow(IUnknown* window, int width, int height, DXGI_MODE_ROTATION rotation) void DeviceResources::SetWindow(IUnknown* window, int width, int height, DXGI_MODE_ROTATION rotation) { m_window = window; Loading @@ -400,7 +436,7 @@ void DX::DeviceResources::SetWindow(IUnknown* window, int width, int height, DXG } // This method is called when the window changes size bool DX::DeviceResources::WindowSizeChanged(int width, int height, DXGI_MODE_ROTATION rotation) bool DeviceResources::WindowSizeChanged(int width, int height, DXGI_MODE_ROTATION rotation) { RECT newRc; newRc.left = newRc.top = 0; Loading @@ -408,6 +444,9 @@ bool DX::DeviceResources::WindowSizeChanged(int width, int height, DXGI_MODE_ROT newRc.bottom = height; if (newRc == m_outputSize && rotation == m_rotation) { // Handle color space settings for HDR UpdateColorSpace(); return false; } Loading @@ -418,37 +457,28 @@ bool DX::DeviceResources::WindowSizeChanged(int width, int height, DXGI_MODE_ROT } // This method is called in the event handler for the DisplayContentsInvalidated event. void DX::DeviceResources::ValidateDevice() void DeviceResources::ValidateDevice() { // The D3D Device is no longer valid if the default adapter changed since the device // was created or if the device has been removed. DXGI_ADAPTER_DESC previousDesc; { ComPtr<IDXGIDevice3> dxgiDevice; DX::ThrowIfFailed(m_d3dDevice.As(&dxgiDevice)); ComPtr<IDXGIAdapter> deviceAdapter; DX::ThrowIfFailed(dxgiDevice->GetAdapter(deviceAdapter.GetAddressOf())); ComPtr<IDXGIFactory2> deviceFactory; DX::ThrowIfFailed(deviceAdapter->GetParent(IID_PPV_ARGS(deviceFactory.GetAddressOf()))); ComPtr<IDXGIAdapter1> previousDefaultAdapter; DX::ThrowIfFailed(deviceFactory->EnumAdapters1(0, previousDefaultAdapter.GetAddressOf())); ThrowIfFailed(m_dxgiFactory->EnumAdapters1(0, previousDefaultAdapter.GetAddressOf())); DX::ThrowIfFailed(previousDefaultAdapter->GetDesc(&previousDesc)); ThrowIfFailed(previousDefaultAdapter->GetDesc(&previousDesc)); } DXGI_ADAPTER_DESC currentDesc; { ComPtr<IDXGIFactory2> currentFactory; DX::ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(currentFactory.GetAddressOf()))); ThrowIfFailed(CreateDXGIFactory2(m_dxgiFactoryFlags, IID_PPV_ARGS(currentFactory.GetAddressOf()))); ComPtr<IDXGIAdapter1> currentDefaultAdapter; DX::ThrowIfFailed(currentFactory->EnumAdapters1(0, currentDefaultAdapter.GetAddressOf())); ThrowIfFailed(currentFactory->EnumAdapters1(0, currentDefaultAdapter.GetAddressOf())); DX::ThrowIfFailed(currentDefaultAdapter->GetDesc(¤tDesc)); ThrowIfFailed(currentDefaultAdapter->GetDesc(¤tDesc)); } // If the adapter LUIDs don't match, or if the device reports that it has been removed, Loading @@ -468,7 +498,7 @@ void DX::DeviceResources::ValidateDevice() } // Recreate all device resources and set them back to the current state. void DX::DeviceResources::HandleDeviceLost() void DeviceResources::HandleDeviceLost() { if (m_deviceNotify) { Loading @@ -482,6 +512,7 @@ void DX::DeviceResources::HandleDeviceLost() m_swapChain.Reset(); m_d3dContext.Reset(); m_d3dDevice.Reset(); m_dxgiFactory.Reset(); #ifdef _DEBUG { Loading @@ -504,7 +535,7 @@ void DX::DeviceResources::HandleDeviceLost() // Call this method when the app suspends. It provides a hint to the driver that the app // is entering an idle state and that temporary buffers can be reclaimed for use by other apps. void DX::DeviceResources::Trim() void DeviceResources::Trim() { ComPtr<IDXGIDevice3> dxgiDevice; if (SUCCEEDED(m_d3dDevice.As(&dxgiDevice))) Loading @@ -514,12 +545,21 @@ void DX::DeviceResources::Trim() } // Present the contents of the swap chain to the screen. void DX::DeviceResources::Present() void DeviceResources::Present() { HRESULT hr; if (m_options & c_AllowTearing) { // Recommended to always use tearing if supported when using a sync interval of 0. hr = m_swapChain->Present(0, DXGI_PRESENT_ALLOW_TEARING); } else { // The first argument instructs DXGI to block until VSync, putting the application // to sleep until the next VSync. This ensures we don't waste any cycles rendering // frames that will never be displayed to the screen. HRESULT hr = m_swapChain->Present(1, 0); hr = m_swapChain->Present(1, 0); } // Discard the contents of the render target. // This is a valid operation only when the existing contents will be entirely Loading @@ -545,39 +585,24 @@ void DX::DeviceResources::Present() } else { DX::ThrowIfFailed(hr); ThrowIfFailed(hr); if (!m_dxgiFactory->IsCurrent()) { // Output information is cached on the DXGI Factory. If it is stale we need to create a new factory. ThrowIfFailed(CreateDXGIFactory2(m_dxgiFactoryFlags, IID_PPV_ARGS(m_dxgiFactory.ReleaseAndGetAddressOf()))); } } } // This method acquires the first available hardware adapter. // If no such adapter can be found, *ppAdapter will be set to nullptr. void DX::DeviceResources::GetHardwareAdapter(IDXGIAdapter1** ppAdapter) void DeviceResources::GetHardwareAdapter(IDXGIAdapter1** ppAdapter) { *ppAdapter = nullptr; ComPtr<IDXGIFactory2> dxgiFactory; #ifdef _DEBUG bool debugDXGI = false; { ComPtr<IDXGIInfoQueue> dxgiInfoQueue; if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(dxgiInfoQueue.GetAddressOf())))) { debugDXGI = true; DX::ThrowIfFailed(CreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG, IID_PPV_ARGS(dxgiFactory.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); } } if (!debugDXGI) #endif DX::ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(dxgiFactory.GetAddressOf()))); ComPtr<IDXGIAdapter1> adapter; for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != dxgiFactory->EnumAdapters1(adapterIndex, adapter.ReleaseAndGetAddressOf()); adapterIndex++) for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1(adapterIndex, adapter.ReleaseAndGetAddressOf()); adapterIndex++) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); Loading @@ -599,3 +624,61 @@ void DX::DeviceResources::GetHardwareAdapter(IDXGIAdapter1** ppAdapter) *ppAdapter = adapter.Detach(); } // Sets the color space for the swap chain in order to handle HDR output. void DeviceResources::UpdateColorSpace() { DXGI_COLOR_SPACE_TYPE colorSpace = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709; bool isdisplayhdr10 = false; #if defined(NTDDI_WIN10_RS2) if (m_swapChain) { ComPtr<IDXGIOutput> output; if (SUCCEEDED(m_swapChain->GetContainingOutput(output.GetAddressOf()))) { ComPtr<IDXGIOutput6> output6; if (SUCCEEDED(output.As(&output6))) { DXGI_OUTPUT_DESC1 desc; ThrowIfFailed(output6->GetDesc1(&desc)); if (desc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020) { // Display output is HDR10. isdisplayhdr10 = true; } } } } #endif if ((m_options & c_EnableHDR) && isdisplayhdr10) { switch (m_backBufferFormat) { case DXGI_FORMAT_R10G10B10A2_UNORM: // The application creates the HDR10 signal. colorSpace = DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020; break; case DXGI_FORMAT_R16G16B16A16_FLOAT: // The system creates the HDR10 signal; application uses linear values. colorSpace = DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709; break; default: break; } } m_colorSpace = colorSpace; UINT colorSpaceSupport = 0; if (SUCCEEDED(m_swapChain->CheckColorSpaceSupport(colorSpace, &colorSpaceSupport)) && (colorSpaceSupport & DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_PRESENT)) { ThrowIfFailed(m_swapChain->SetColorSpace1(colorSpace)); } } Loading
.gitignore +3 −2 Original line number Diff line number Diff line Loading @@ -28,8 +28,9 @@ Release x64 Kits/DirectXTK/Src/Shaders/Compiled/XboxOne*.* Kits/DirectXTK12/Src/Shaders/Compiled/XboxOne*.* Samples/Graphics/SimplePBR12/Compiled/ Samples/Tools/errorlookup/errorlookup/project.lock.json UWPSamples/Graphics/SimplePBR12/Compiled/ UWPSamples/Tools/errorlookup/errorlookup/obj/ UWPSamples/Tools/errorlookup/errorlookup/project.lock.json /wiki AppPackages packages Loading
Kits/ATGTK/ATGColors.h +12 −0 Original line number Diff line number Diff line Loading @@ -41,4 +41,16 @@ namespace ATG XMGLOBALCONST DirectX::XMVECTORF32 OffWhite = { 0.361306787f, 0.361306787f, 0.361306787f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 White = { 0.955973506f, 0.955973506f, 0.955973506f, 1.f }; }; namespace ColorsHDR { XMGLOBALCONST DirectX::XMVECTORF32 Background = { 0.052860655f * 2.f, 0.052860655f * 2.f, 0.052860655f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 Green = { 0.005181516f * 2.f, 0.201556236f * 2.f, 0.005181516f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 Blue = { 0.001517635f * 2.f, 0.114435382f * 2.f, 0.610495627f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 Orange = { 0.545724571f * 2.f, 0.026241219f * 2.f, 0.001517635f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 DarkGrey = { 0.033104762f * 2.f, 0.033104762f * 2.f, 0.033104762f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 LightGrey = { 0.194617808f * 2.f, 0.194617808f * 2.f, 0.194617808f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 OffWhite = { 0.361306787f * 2.f, 0.361306787f * 2.f, 0.361306787f * 2.f, 1.f }; XMGLOBALCONST DirectX::XMVECTORF32 White = { 0.955973506f * 2.f, 0.955973506f * 2.f, 0.955973506f * 2.f, 1.f }; }; } No newline at end of file
Kits/ATGTK/ControllerFont.h +4 −4 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ namespace DX float offsetY = buttonScale / 2.f; size_t j = 0; wchar_t strBuffer[4096] = {0}; wchar_t strBuffer[4096] = {}; bool buttonText = false; Loading @@ -67,7 +67,7 @@ namespace DX if (text[ch] == L']') { wchar_t button[2] = { 0 }; wchar_t button[2] = {}; if (_wcsicmp(strBuffer, L"[A]") == 0) { Loading Loading @@ -204,7 +204,7 @@ namespace DX float offsetY = buttonScale / 2.f; size_t j = 0; wchar_t strBuffer[4096] = { 0 }; wchar_t strBuffer[4096] = {}; bool buttonText = false; Loading @@ -219,7 +219,7 @@ namespace DX if (text[ch] == L']') { wchar_t button[2] = { 0 }; wchar_t button[2] = {}; if (_wcsicmp(strBuffer, L"[A]") == 0) { Loading
Kits/ATGTK/WAVFileReader.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -496,7 +496,7 @@ static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std: } // Get the file size LARGE_INTEGER FileSize = { 0 }; LARGE_INTEGER FileSize = {}; #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA) FILE_STANDARD_INFO fileInfo; Loading
UWPSamples/Audio/AdvancedSpatialSoundsUWP/DeviceResources.cpp +160 −77 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ #include "DeviceResources.h" using namespace DirectX; using namespace DX; using Microsoft::WRL::ComPtr; Loading Loading @@ -83,7 +84,7 @@ namespace ScreenRotation }; // Constructor for DeviceResources. DX::DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel) : DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel, unsigned int flags) : m_screenViewport{}, m_backBufferFormat(backBufferFormat), m_depthBufferFormat(depthBufferFormat), Loading @@ -92,14 +93,17 @@ DX::DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat, DXGI_FORMAT d m_window(nullptr), m_d3dFeatureLevel(D3D_FEATURE_LEVEL_9_1), m_rotation(DXGI_MODE_ROTATION_IDENTITY), m_dxgiFactoryFlags(0), m_outputSize{0, 0, 1, 1}, m_orientationTransform3D(ScreenRotation::Rotation0), m_colorSpace(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709), m_options(flags), m_deviceNotify(nullptr) { } // Configures the Direct3D device, and stores handles to it and the device context. void DX::DeviceResources::CreateDeviceResources() void DeviceResources::CreateDeviceResources() { UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; Loading @@ -115,6 +119,42 @@ void DX::DeviceResources::CreateDeviceResources() } #endif #if defined(_DEBUG) { ComPtr<IDXGIInfoQueue> dxgiInfoQueue; if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(dxgiInfoQueue.GetAddressOf())))) { m_dxgiFactoryFlags = DXGI_CREATE_FACTORY_DEBUG; 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 ThrowIfFailed(CreateDXGIFactory2(m_dxgiFactoryFlags, IID_PPV_ARGS(m_dxgiFactory.ReleaseAndGetAddressOf()))); // Determines whether tearing support is available for fullscreen borderless windows. if (m_options & c_AllowTearing) { BOOL allowTearing = FALSE; ComPtr<IDXGIFactory5> factory5; HRESULT hr = m_dxgiFactory.As(&factory5); if (SUCCEEDED(hr)) { hr = factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allowTearing, sizeof(allowTearing)); } if (FAILED(hr) || !allowTearing) { m_options &= ~c_AllowTearing; #ifdef _DEBUG OutputDebugStringA("WARNING: Variable refresh rate displays not supported"); #endif } } // Determine DirectX hardware feature levels this app will support. static const D3D_FEATURE_LEVEL s_featureLevels[] = { Loading Loading @@ -195,7 +235,7 @@ void DX::DeviceResources::CreateDeviceResources() } #endif DX::ThrowIfFailed(hr); ThrowIfFailed(hr); #ifndef NDEBUG ComPtr<ID3D11Debug> d3dDebug; Loading @@ -220,12 +260,12 @@ void DX::DeviceResources::CreateDeviceResources() } #endif DX::ThrowIfFailed(device.As(&m_d3dDevice)); DX::ThrowIfFailed(context.As(&m_d3dContext)); ThrowIfFailed(device.As(&m_d3dDevice)); ThrowIfFailed(context.As(&m_d3dContext)); } // These resources need to be recreated every time the window size is changed. void DX::DeviceResources::CreateWindowSizeDependentResources() void DeviceResources::CreateWindowSizeDependentResources() { if (!m_window) { Loading Loading @@ -254,7 +294,7 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() backBufferWidth, backBufferHeight, backBufferFormat, 0 (m_options & c_AllowTearing) ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0 ); if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) Loading @@ -273,23 +313,12 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() } else { DX::ThrowIfFailed(hr); ThrowIfFailed(hr); } } else { // Otherwise, create a new one using the same adapter as the existing Direct3D device. // This sequence obtains the DXGI factory that was used to create the Direct3D device above. ComPtr<IDXGIDevice3> dxgiDevice; DX::ThrowIfFailed(m_d3dDevice.As(&dxgiDevice)); ComPtr<IDXGIAdapter> dxgiAdapter; DX::ThrowIfFailed(dxgiDevice->GetAdapter(dxgiAdapter.GetAddressOf())); ComPtr<IDXGIFactory2> dxgiFactory; DX::ThrowIfFailed(dxgiAdapter->GetParent(IID_PPV_ARGS(dxgiFactory.GetAddressOf()))); // Create a descriptor for the swap chain. DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {}; swapChainDesc.Width = backBufferWidth; swapChainDesc.Height = backBufferHeight; Loading @@ -301,9 +330,11 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() swapChainDesc.Scaling = DXGI_SCALING_ASPECT_RATIO_STRETCH; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE; swapChainDesc.Flags = (m_options & c_AllowTearing) ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0; // Create a swap chain for the window. ComPtr<IDXGISwapChain1> swapChain; DX::ThrowIfFailed(dxgiFactory->CreateSwapChainForCoreWindow( ThrowIfFailed(m_dxgiFactory->CreateSwapChainForCoreWindow( m_d3dDevice.Get(), m_window, &swapChainDesc, Loading @@ -311,13 +342,18 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() swapChain.GetAddressOf() )); DX::ThrowIfFailed(swapChain.As(&m_swapChain)); ThrowIfFailed(swapChain.As(&m_swapChain)); // Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and // ensures that the application will only render after each VSync, minimizing power consumption. DX::ThrowIfFailed(dxgiDevice->SetMaximumFrameLatency(1)); ComPtr<IDXGIDevice3> dxgiDevice; ThrowIfFailed(m_d3dDevice.As(&dxgiDevice)); ThrowIfFailed(dxgiDevice->SetMaximumFrameLatency(1)); } // Handle color space settings for HDR UpdateColorSpace(); // Set the proper orientation for the swap chain, and generate // matrix transformations for rendering to the rotated swap chain. switch (m_rotation) Loading @@ -340,13 +376,13 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() break; } DX::ThrowIfFailed(m_swapChain->SetRotation(m_rotation)); ThrowIfFailed(m_swapChain->SetRotation(m_rotation)); // Create a render target view of the swap chain back buffer. DX::ThrowIfFailed(m_swapChain->GetBuffer(0, IID_PPV_ARGS(m_renderTarget.ReleaseAndGetAddressOf()))); ThrowIfFailed(m_swapChain->GetBuffer(0, IID_PPV_ARGS(m_renderTarget.ReleaseAndGetAddressOf()))); CD3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc(D3D11_RTV_DIMENSION_TEXTURE2D, m_backBufferFormat); DX::ThrowIfFailed(m_d3dDevice->CreateRenderTargetView( ThrowIfFailed(m_d3dDevice->CreateRenderTargetView( m_renderTarget.Get(), &renderTargetViewDesc, m_d3dRenderTargetView.ReleaseAndGetAddressOf() Loading @@ -364,14 +400,14 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() D3D11_BIND_DEPTH_STENCIL ); DX::ThrowIfFailed(m_d3dDevice->CreateTexture2D( ThrowIfFailed(m_d3dDevice->CreateTexture2D( &depthStencilDesc, nullptr, m_depthStencil.ReleaseAndGetAddressOf() )); CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D); DX::ThrowIfFailed(m_d3dDevice->CreateDepthStencilView( ThrowIfFailed(m_d3dDevice->CreateDepthStencilView( m_depthStencil.Get(), &depthStencilViewDesc, m_d3dDepthStencilView.ReleaseAndGetAddressOf() Loading @@ -388,7 +424,7 @@ void DX::DeviceResources::CreateWindowSizeDependentResources() } // This method is called when the CoreWindow is created (or re-created). void DX::DeviceResources::SetWindow(IUnknown* window, int width, int height, DXGI_MODE_ROTATION rotation) void DeviceResources::SetWindow(IUnknown* window, int width, int height, DXGI_MODE_ROTATION rotation) { m_window = window; Loading @@ -400,7 +436,7 @@ void DX::DeviceResources::SetWindow(IUnknown* window, int width, int height, DXG } // This method is called when the window changes size bool DX::DeviceResources::WindowSizeChanged(int width, int height, DXGI_MODE_ROTATION rotation) bool DeviceResources::WindowSizeChanged(int width, int height, DXGI_MODE_ROTATION rotation) { RECT newRc; newRc.left = newRc.top = 0; Loading @@ -408,6 +444,9 @@ bool DX::DeviceResources::WindowSizeChanged(int width, int height, DXGI_MODE_ROT newRc.bottom = height; if (newRc == m_outputSize && rotation == m_rotation) { // Handle color space settings for HDR UpdateColorSpace(); return false; } Loading @@ -418,37 +457,28 @@ bool DX::DeviceResources::WindowSizeChanged(int width, int height, DXGI_MODE_ROT } // This method is called in the event handler for the DisplayContentsInvalidated event. void DX::DeviceResources::ValidateDevice() void DeviceResources::ValidateDevice() { // The D3D Device is no longer valid if the default adapter changed since the device // was created or if the device has been removed. DXGI_ADAPTER_DESC previousDesc; { ComPtr<IDXGIDevice3> dxgiDevice; DX::ThrowIfFailed(m_d3dDevice.As(&dxgiDevice)); ComPtr<IDXGIAdapter> deviceAdapter; DX::ThrowIfFailed(dxgiDevice->GetAdapter(deviceAdapter.GetAddressOf())); ComPtr<IDXGIFactory2> deviceFactory; DX::ThrowIfFailed(deviceAdapter->GetParent(IID_PPV_ARGS(deviceFactory.GetAddressOf()))); ComPtr<IDXGIAdapter1> previousDefaultAdapter; DX::ThrowIfFailed(deviceFactory->EnumAdapters1(0, previousDefaultAdapter.GetAddressOf())); ThrowIfFailed(m_dxgiFactory->EnumAdapters1(0, previousDefaultAdapter.GetAddressOf())); DX::ThrowIfFailed(previousDefaultAdapter->GetDesc(&previousDesc)); ThrowIfFailed(previousDefaultAdapter->GetDesc(&previousDesc)); } DXGI_ADAPTER_DESC currentDesc; { ComPtr<IDXGIFactory2> currentFactory; DX::ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(currentFactory.GetAddressOf()))); ThrowIfFailed(CreateDXGIFactory2(m_dxgiFactoryFlags, IID_PPV_ARGS(currentFactory.GetAddressOf()))); ComPtr<IDXGIAdapter1> currentDefaultAdapter; DX::ThrowIfFailed(currentFactory->EnumAdapters1(0, currentDefaultAdapter.GetAddressOf())); ThrowIfFailed(currentFactory->EnumAdapters1(0, currentDefaultAdapter.GetAddressOf())); DX::ThrowIfFailed(currentDefaultAdapter->GetDesc(¤tDesc)); ThrowIfFailed(currentDefaultAdapter->GetDesc(¤tDesc)); } // If the adapter LUIDs don't match, or if the device reports that it has been removed, Loading @@ -468,7 +498,7 @@ void DX::DeviceResources::ValidateDevice() } // Recreate all device resources and set them back to the current state. void DX::DeviceResources::HandleDeviceLost() void DeviceResources::HandleDeviceLost() { if (m_deviceNotify) { Loading @@ -482,6 +512,7 @@ void DX::DeviceResources::HandleDeviceLost() m_swapChain.Reset(); m_d3dContext.Reset(); m_d3dDevice.Reset(); m_dxgiFactory.Reset(); #ifdef _DEBUG { Loading @@ -504,7 +535,7 @@ void DX::DeviceResources::HandleDeviceLost() // Call this method when the app suspends. It provides a hint to the driver that the app // is entering an idle state and that temporary buffers can be reclaimed for use by other apps. void DX::DeviceResources::Trim() void DeviceResources::Trim() { ComPtr<IDXGIDevice3> dxgiDevice; if (SUCCEEDED(m_d3dDevice.As(&dxgiDevice))) Loading @@ -514,12 +545,21 @@ void DX::DeviceResources::Trim() } // Present the contents of the swap chain to the screen. void DX::DeviceResources::Present() void DeviceResources::Present() { HRESULT hr; if (m_options & c_AllowTearing) { // Recommended to always use tearing if supported when using a sync interval of 0. hr = m_swapChain->Present(0, DXGI_PRESENT_ALLOW_TEARING); } else { // The first argument instructs DXGI to block until VSync, putting the application // to sleep until the next VSync. This ensures we don't waste any cycles rendering // frames that will never be displayed to the screen. HRESULT hr = m_swapChain->Present(1, 0); hr = m_swapChain->Present(1, 0); } // Discard the contents of the render target. // This is a valid operation only when the existing contents will be entirely Loading @@ -545,39 +585,24 @@ void DX::DeviceResources::Present() } else { DX::ThrowIfFailed(hr); ThrowIfFailed(hr); if (!m_dxgiFactory->IsCurrent()) { // Output information is cached on the DXGI Factory. If it is stale we need to create a new factory. ThrowIfFailed(CreateDXGIFactory2(m_dxgiFactoryFlags, IID_PPV_ARGS(m_dxgiFactory.ReleaseAndGetAddressOf()))); } } } // This method acquires the first available hardware adapter. // If no such adapter can be found, *ppAdapter will be set to nullptr. void DX::DeviceResources::GetHardwareAdapter(IDXGIAdapter1** ppAdapter) void DeviceResources::GetHardwareAdapter(IDXGIAdapter1** ppAdapter) { *ppAdapter = nullptr; ComPtr<IDXGIFactory2> dxgiFactory; #ifdef _DEBUG bool debugDXGI = false; { ComPtr<IDXGIInfoQueue> dxgiInfoQueue; if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(dxgiInfoQueue.GetAddressOf())))) { debugDXGI = true; DX::ThrowIfFailed(CreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG, IID_PPV_ARGS(dxgiFactory.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); } } if (!debugDXGI) #endif DX::ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(dxgiFactory.GetAddressOf()))); ComPtr<IDXGIAdapter1> adapter; for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != dxgiFactory->EnumAdapters1(adapterIndex, adapter.ReleaseAndGetAddressOf()); adapterIndex++) for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1(adapterIndex, adapter.ReleaseAndGetAddressOf()); adapterIndex++) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); Loading @@ -599,3 +624,61 @@ void DX::DeviceResources::GetHardwareAdapter(IDXGIAdapter1** ppAdapter) *ppAdapter = adapter.Detach(); } // Sets the color space for the swap chain in order to handle HDR output. void DeviceResources::UpdateColorSpace() { DXGI_COLOR_SPACE_TYPE colorSpace = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709; bool isdisplayhdr10 = false; #if defined(NTDDI_WIN10_RS2) if (m_swapChain) { ComPtr<IDXGIOutput> output; if (SUCCEEDED(m_swapChain->GetContainingOutput(output.GetAddressOf()))) { ComPtr<IDXGIOutput6> output6; if (SUCCEEDED(output.As(&output6))) { DXGI_OUTPUT_DESC1 desc; ThrowIfFailed(output6->GetDesc1(&desc)); if (desc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020) { // Display output is HDR10. isdisplayhdr10 = true; } } } } #endif if ((m_options & c_EnableHDR) && isdisplayhdr10) { switch (m_backBufferFormat) { case DXGI_FORMAT_R10G10B10A2_UNORM: // The application creates the HDR10 signal. colorSpace = DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020; break; case DXGI_FORMAT_R16G16B16A16_FLOAT: // The system creates the HDR10 signal; application uses linear values. colorSpace = DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709; break; default: break; } } m_colorSpace = colorSpace; UINT colorSpaceSupport = 0; if (SUCCEEDED(m_swapChain->CheckColorSpaceSupport(colorSpace, &colorSpaceSupport)) && (colorSpaceSupport & DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_PRESENT)) { ThrowIfFailed(m_swapChain->SetColorSpace1(colorSpace)); } }