Loading Kits/ATGTK/WAVFileReader.cpp +480 −464 Original line number Diff line number Diff line Loading @@ -19,9 +19,9 @@ typedef public std::unique_ptr<void, handle_closer> ScopedHandle; inline HANDLE safe_handle(HANDLE h) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; } //-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- // .WAV files //-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- const uint32_t FOURCC_RIFF_TAG = 'FFIR'; const uint32_t FOURCC_FORMAT_TAG = ' tmf'; const uint32_t FOURCC_DATA_TAG = 'atad'; Loading Loading @@ -105,11 +105,11 @@ static_assert( sizeof(RIFFDLSSample) == 20, "structure size mismatch"); static_assert(sizeof(MIDILoop) == 24, "structure size mismatch"); static_assert(sizeof(RIFFMIDISample) == 36, "structure size mismatch"); }; //-------------------------------------------------------------------------------------- static const RIFFChunk* FindChunk( _In_reads_bytes_(sizeBytes) const uint8_t* data, _In_ size_t sizeBytes, _In_ uint32_t tag ) //--------------------------------------------------------------------------------- const RIFFChunk* FindChunk( _In_reads_bytes_(sizeBytes) const uint8_t* data, _In_ size_t sizeBytes, _In_ uint32_t tag) { if (!data) return nullptr; Loading @@ -131,10 +131,15 @@ static const RIFFChunk* FindChunk( _In_reads_bytes_(sizeBytes) const uint8_t* da } //-------------------------------------------------------------------------------------- static HRESULT WaveFindFormatAndData( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Outptr_ const WAVEFORMATEX** pwfx, _Outptr_ const uint8_t** pdata, _Out_ uint32_t* dataSize, _Out_ bool& dpds, _Out_ bool& seek ) //--------------------------------------------------------------------------------- HRESULT WaveFindFormatAndData( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Outptr_ const WAVEFORMATEX** pwfx, _Outptr_ const uint8_t** pdata, _Out_ uint32_t* dataSize, _Out_ bool& dpds, _Out_ bool& seek) { if (!wavData || !pwfx) return E_POINTER; Loading Loading @@ -296,9 +301,12 @@ static HRESULT WaveFindFormatAndData( _In_reads_bytes_(wavDataSize) const uint8_ } //-------------------------------------------------------------------------------------- static HRESULT WaveFindLoopInfo( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Out_ uint32_t* pLoopStart, _Out_ uint32_t* pLoopLength ) //--------------------------------------------------------------------------------- HRESULT WaveFindLoopInfo( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Out_ uint32_t* pLoopStart, _Out_ uint32_t* pLoopLength) { if (!wavData || !pLoopStart || !pLoopLength) return E_POINTER; Loading Loading @@ -404,9 +412,13 @@ static HRESULT WaveFindLoopInfo( _In_reads_bytes_(wavDataSize) const uint8_t* wa } //-------------------------------------------------------------------------------------- static HRESULT WaveFindTable( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _In_ uint32_t tag, _Outptr_result_maybenull_ const uint32_t** pData, _Out_ uint32_t* dataCount ) //--------------------------------------------------------------------------------- HRESULT WaveFindTable( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _In_ uint32_t tag, _Outptr_result_maybenull_ const uint32_t** pData, _Out_ uint32_t* dataCount) { if (!wavData || !pData || !dataCount) return E_POINTER; Loading Loading @@ -463,8 +475,11 @@ static HRESULT WaveFindTable( _In_reads_bytes_(wavDataSize) const uint8_t* wavDa } //-------------------------------------------------------------------------------------- static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<uint8_t[]>& wavData, _Out_ DWORD* bytesRead ) //--------------------------------------------------------------------------------- HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<uint8_t[]>& wavData, _Out_ DWORD* bytesRead) { if (!szFileName) return E_INVALIDARG; Loading Loading @@ -492,33 +507,26 @@ static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std: } // Get the file size LARGE_INTEGER FileSize = {}; #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA) FILE_STANDARD_INFO fileInfo; if (!GetFileInformationByHandleEx(hFile.get(), FileStandardInfo, &fileInfo, sizeof(fileInfo))) { return HRESULT_FROM_WIN32(GetLastError()); } FileSize = fileInfo.EndOfFile; #else GetFileSizeEx( hFile.get(), &FileSize ); #endif // File is too big for 32-bit allocation, so reject read if (FileSize.HighPart > 0) if (fileInfo.EndOfFile.HighPart > 0) { return E_FAIL; } // Need at least enough data to have a valid minimal WAV file if (FileSize.LowPart < ( sizeof(RIFFChunk)*2 + sizeof(DWORD) + sizeof(WAVEFORMAT) ) ) if (fileInfo.EndOfFile.LowPart < (sizeof(RIFFChunk) * 2 + sizeof(DWORD) + sizeof(WAVEFORMAT))) { return E_FAIL; } // create enough space for the file data wavData.reset( new (std::nothrow) uint8_t[ FileSize.LowPart ] ); wavData.reset(new (std::nothrow) uint8_t[fileInfo.EndOfFile.LowPart]); if (!wavData) { return E_OUTOFMEMORY; Loading @@ -527,7 +535,7 @@ static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std: // read the data in if (!ReadFile(hFile.get(), wavData.get(), FileSize.LowPart, fileInfo.EndOfFile.LowPart, bytesRead, nullptr )) Loading @@ -535,13 +543,14 @@ static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std: return HRESULT_FROM_WIN32(GetLastError()); } return (*bytesRead < FileSize.LowPart) ? E_FAIL : S_OK; return (*bytesRead < fileInfo.EndOfFile.LowPart) ? E_FAIL : S_OK; } } //-------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DX::LoadWAVAudioInMemory( const uint8_t* wavData, HRESULT DX::LoadWAVAudioInMemory( const uint8_t* wavData, size_t wavDataSize, const WAVEFORMATEX** wfx, const uint8_t** startAudio, Loading Loading @@ -569,9 +578,10 @@ HRESULT DX::LoadWAVAudioInMemory( const uint8_t* wavData, } //-------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DX::LoadWAVAudioFromFile( const wchar_t* szFileName, HRESULT DX::LoadWAVAudioFromFile( const wchar_t* szFileName, std::unique_ptr<uint8_t[]>& wavData, const WAVEFORMATEX** wfx, const uint8_t** startAudio, Loading Loading @@ -600,9 +610,12 @@ HRESULT DX::LoadWAVAudioFromFile( const wchar_t* szFileName, } //-------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DX::LoadWAVAudioInMemoryEx( const uint8_t* wavData, size_t wavDataSize, DX::WAVData& result ) HRESULT DX::LoadWAVAudioInMemoryEx( const uint8_t* wavData, size_t wavDataSize, DX::WAVData& result) { if (!wavData) return E_INVALIDARG; Loading Loading @@ -641,9 +654,12 @@ HRESULT DX::LoadWAVAudioInMemoryEx( const uint8_t* wavData, size_t wavDataSize, } //-------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DX::LoadWAVAudioFromFileEx( const wchar_t* szFileName, std::unique_ptr<uint8_t[]>& wavData, DX::WAVData& result ) HRESULT DX::LoadWAVAudioFromFileEx( const wchar_t* szFileName, std::unique_ptr<uint8_t[]>& wavData, DX::WAVData& result) { if (!szFileName) return E_INVALIDARG; Loading Kits/ATGTK/WAVFileReader.h +51 −46 Original line number Diff line number Diff line Loading @@ -46,13 +46,15 @@ namespace DX } } HRESULT LoadWAVAudioInMemory( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, HRESULT LoadWAVAudioInMemory( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Outptr_ const WAVEFORMATEX** wfx, _Outptr_ const uint8_t** startAudio, _Out_ uint32_t* audioBytes); HRESULT LoadWAVAudioFromFile( _In_z_ const wchar_t* szFileName, HRESULT LoadWAVAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<uint8_t[]>& wavData, _Outptr_ const WAVEFORMATEX** wfx, _Outptr_ const uint8_t** startAudio, Loading Loading @@ -129,10 +131,13 @@ namespace DX } }; HRESULT LoadWAVAudioInMemoryEx( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Out_ WAVData& result ); HRESULT LoadWAVAudioInMemoryEx( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Out_ WAVData& result); HRESULT LoadWAVAudioFromFileEx( _In_z_ const wchar_t* szFileName, HRESULT LoadWAVAudioFromFileEx( _In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<uint8_t[]>& wavData, _Out_ WAVData& result); } No newline at end of file PCSamples/IntroGraphics/DirectXTKSimpleSamplePC/DeviceResources.cpp +55 −13 Original line number Diff line number Diff line Loading @@ -47,7 +47,12 @@ namespace }; // Constructor for DeviceResources. DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel, unsigned int flags) : DeviceResources::DeviceResources( DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel, unsigned int flags) noexcept : m_screenViewport{}, m_backBufferFormat(backBufferFormat), m_depthBufferFormat(depthBufferFormat), Loading Loading @@ -517,7 +522,44 @@ void DeviceResources::GetHardwareAdapter(IDXGIAdapter1** ppAdapter) *ppAdapter = nullptr; ComPtr<IDXGIAdapter1> adapter; for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1(adapterIndex, adapter.ReleaseAndGetAddressOf()); adapterIndex++) #if defined(__dxgi1_6_h__) && defined(NTDDI_WIN10_RS4) ComPtr<IDXGIFactory6> factory6; HRESULT hr = m_dxgiFactory.As(&factory6); if (SUCCEEDED(hr)) { for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != factory6->EnumAdapterByGpuPreference( adapterIndex, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(adapter.ReleaseAndGetAddressOf())); adapterIndex++) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) { // Don't select the Basic Render Driver adapter. continue; } #ifdef _DEBUG wchar_t buff[256] = {}; swprintf_s(buff, L"Direct3D Adapter (%u): VID:%04X, PID:%04X - %ls\n", adapterIndex, desc.VendorId, desc.DeviceId, desc.Description); OutputDebugStringW(buff); #endif break; } } else #endif for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1( adapterIndex, adapter.ReleaseAndGetAddressOf()); adapterIndex++) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); Loading PCSamples/IntroGraphics/DirectXTKSimpleSamplePC/DeviceResources.h +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ namespace DX DXGI_FORMAT depthBufferFormat = DXGI_FORMAT_D32_FLOAT, UINT backBufferCount = 2, D3D_FEATURE_LEVEL minFeatureLevel = D3D_FEATURE_LEVEL_10_0, unsigned int flags = c_FlipPresent); unsigned int flags = c_FlipPresent) noexcept; void CreateDeviceResources(); void CreateWindowSizeDependentResources(); Loading PCSamples/IntroGraphics/DirectXTKSimpleSamplePC12/DeviceResources.cpp +75 −20 Original line number Diff line number Diff line Loading @@ -25,7 +25,12 @@ namespace }; // Constructor for DeviceResources. DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel, unsigned int flags) : DeviceResources::DeviceResources( DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel, unsigned int flags) noexcept(false) : m_backBufferIndex(0), m_fenceValues{}, m_rtvDescriptorSize(0), Loading Loading @@ -123,6 +128,8 @@ void DeviceResources::CreateDeviceResources() IID_PPV_ARGS(m_d3dDevice.ReleaseAndGetAddressOf()) )); m_d3dDevice->SetName(L"DeviceResources"); #ifndef NDEBUG // Configure debug device (if active). ComPtr<ID3D12InfoQueue> d3dInfoQueue; Loading Loading @@ -175,6 +182,8 @@ void DeviceResources::CreateDeviceResources() ThrowIfFailed(m_d3dDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(m_commandQueue.ReleaseAndGetAddressOf()))); m_commandQueue->SetName(L"DeviceResources"); // Create descriptor heaps for render target views and depth stencil views. D3D12_DESCRIPTOR_HEAP_DESC rtvDescriptorHeapDesc = {}; rtvDescriptorHeapDesc.NumDescriptors = m_backBufferCount; Loading @@ -201,12 +210,18 @@ void DeviceResources::CreateDeviceResources() for (UINT n = 0; n < m_backBufferCount; n++) { ThrowIfFailed(m_d3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(m_commandAllocators[n].ReleaseAndGetAddressOf()))); wchar_t name[25] = {}; swprintf_s(name, L"Render target %u", n); m_commandAllocators[n]->SetName(name); } // Create a command list for recording graphics commands. ThrowIfFailed(m_d3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocators[0].Get(), nullptr, IID_PPV_ARGS(m_commandList.ReleaseAndGetAddressOf()))); ThrowIfFailed(m_commandList->Close()); m_commandList->SetName(L"DeviceResources"); // Create a fence for tracking GPU execution progress. ThrowIfFailed(m_d3dDevice->CreateFence(m_fenceValues[m_backBufferIndex], D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(m_fence.ReleaseAndGetAddressOf()))); m_fenceValues[m_backBufferIndex]++; Loading Loading @@ -577,7 +592,47 @@ void DeviceResources::GetAdapter(IDXGIAdapter1** ppAdapter) *ppAdapter = nullptr; ComPtr<IDXGIAdapter1> adapter; for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1(adapterIndex, adapter.ReleaseAndGetAddressOf()); ++adapterIndex) #if defined(__dxgi1_6_h__) && defined(NTDDI_WIN10_RS4) ComPtr<IDXGIFactory6> factory6; HRESULT hr = m_dxgiFactory.As(&factory6); if (SUCCEEDED(hr)) { for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != factory6->EnumAdapterByGpuPreference( adapterIndex, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(adapter.ReleaseAndGetAddressOf())); adapterIndex++) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); 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(), m_d3dMinFeatureLevel, _uuidof(ID3D12Device), nullptr))) { #ifdef _DEBUG wchar_t buff[256] = {}; swprintf_s(buff, L"Direct3D Adapter (%u): VID:%04X, PID:%04X - %ls\n", adapterIndex, desc.VendorId, desc.DeviceId, desc.Description); OutputDebugStringW(buff); #endif break; } } } else #endif for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1( adapterIndex, adapter.ReleaseAndGetAddressOf()); ++adapterIndex) { DXGI_ADAPTER_DESC1 desc; ThrowIfFailed(adapter->GetDesc1(&desc)); Loading Loading
Kits/ATGTK/WAVFileReader.cpp +480 −464 Original line number Diff line number Diff line Loading @@ -19,9 +19,9 @@ typedef public std::unique_ptr<void, handle_closer> ScopedHandle; inline HANDLE safe_handle(HANDLE h) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; } //-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- // .WAV files //-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- const uint32_t FOURCC_RIFF_TAG = 'FFIR'; const uint32_t FOURCC_FORMAT_TAG = ' tmf'; const uint32_t FOURCC_DATA_TAG = 'atad'; Loading Loading @@ -105,11 +105,11 @@ static_assert( sizeof(RIFFDLSSample) == 20, "structure size mismatch"); static_assert(sizeof(MIDILoop) == 24, "structure size mismatch"); static_assert(sizeof(RIFFMIDISample) == 36, "structure size mismatch"); }; //-------------------------------------------------------------------------------------- static const RIFFChunk* FindChunk( _In_reads_bytes_(sizeBytes) const uint8_t* data, _In_ size_t sizeBytes, _In_ uint32_t tag ) //--------------------------------------------------------------------------------- const RIFFChunk* FindChunk( _In_reads_bytes_(sizeBytes) const uint8_t* data, _In_ size_t sizeBytes, _In_ uint32_t tag) { if (!data) return nullptr; Loading @@ -131,10 +131,15 @@ static const RIFFChunk* FindChunk( _In_reads_bytes_(sizeBytes) const uint8_t* da } //-------------------------------------------------------------------------------------- static HRESULT WaveFindFormatAndData( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Outptr_ const WAVEFORMATEX** pwfx, _Outptr_ const uint8_t** pdata, _Out_ uint32_t* dataSize, _Out_ bool& dpds, _Out_ bool& seek ) //--------------------------------------------------------------------------------- HRESULT WaveFindFormatAndData( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Outptr_ const WAVEFORMATEX** pwfx, _Outptr_ const uint8_t** pdata, _Out_ uint32_t* dataSize, _Out_ bool& dpds, _Out_ bool& seek) { if (!wavData || !pwfx) return E_POINTER; Loading Loading @@ -296,9 +301,12 @@ static HRESULT WaveFindFormatAndData( _In_reads_bytes_(wavDataSize) const uint8_ } //-------------------------------------------------------------------------------------- static HRESULT WaveFindLoopInfo( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Out_ uint32_t* pLoopStart, _Out_ uint32_t* pLoopLength ) //--------------------------------------------------------------------------------- HRESULT WaveFindLoopInfo( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Out_ uint32_t* pLoopStart, _Out_ uint32_t* pLoopLength) { if (!wavData || !pLoopStart || !pLoopLength) return E_POINTER; Loading Loading @@ -404,9 +412,13 @@ static HRESULT WaveFindLoopInfo( _In_reads_bytes_(wavDataSize) const uint8_t* wa } //-------------------------------------------------------------------------------------- static HRESULT WaveFindTable( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _In_ uint32_t tag, _Outptr_result_maybenull_ const uint32_t** pData, _Out_ uint32_t* dataCount ) //--------------------------------------------------------------------------------- HRESULT WaveFindTable( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _In_ uint32_t tag, _Outptr_result_maybenull_ const uint32_t** pData, _Out_ uint32_t* dataCount) { if (!wavData || !pData || !dataCount) return E_POINTER; Loading Loading @@ -463,8 +475,11 @@ static HRESULT WaveFindTable( _In_reads_bytes_(wavDataSize) const uint8_t* wavDa } //-------------------------------------------------------------------------------------- static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<uint8_t[]>& wavData, _Out_ DWORD* bytesRead ) //--------------------------------------------------------------------------------- HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<uint8_t[]>& wavData, _Out_ DWORD* bytesRead) { if (!szFileName) return E_INVALIDARG; Loading Loading @@ -492,33 +507,26 @@ static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std: } // Get the file size LARGE_INTEGER FileSize = {}; #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA) FILE_STANDARD_INFO fileInfo; if (!GetFileInformationByHandleEx(hFile.get(), FileStandardInfo, &fileInfo, sizeof(fileInfo))) { return HRESULT_FROM_WIN32(GetLastError()); } FileSize = fileInfo.EndOfFile; #else GetFileSizeEx( hFile.get(), &FileSize ); #endif // File is too big for 32-bit allocation, so reject read if (FileSize.HighPart > 0) if (fileInfo.EndOfFile.HighPart > 0) { return E_FAIL; } // Need at least enough data to have a valid minimal WAV file if (FileSize.LowPart < ( sizeof(RIFFChunk)*2 + sizeof(DWORD) + sizeof(WAVEFORMAT) ) ) if (fileInfo.EndOfFile.LowPart < (sizeof(RIFFChunk) * 2 + sizeof(DWORD) + sizeof(WAVEFORMAT))) { return E_FAIL; } // create enough space for the file data wavData.reset( new (std::nothrow) uint8_t[ FileSize.LowPart ] ); wavData.reset(new (std::nothrow) uint8_t[fileInfo.EndOfFile.LowPart]); if (!wavData) { return E_OUTOFMEMORY; Loading @@ -527,7 +535,7 @@ static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std: // read the data in if (!ReadFile(hFile.get(), wavData.get(), FileSize.LowPart, fileInfo.EndOfFile.LowPart, bytesRead, nullptr )) Loading @@ -535,13 +543,14 @@ static HRESULT LoadAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std: return HRESULT_FROM_WIN32(GetLastError()); } return (*bytesRead < FileSize.LowPart) ? E_FAIL : S_OK; return (*bytesRead < fileInfo.EndOfFile.LowPart) ? E_FAIL : S_OK; } } //-------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DX::LoadWAVAudioInMemory( const uint8_t* wavData, HRESULT DX::LoadWAVAudioInMemory( const uint8_t* wavData, size_t wavDataSize, const WAVEFORMATEX** wfx, const uint8_t** startAudio, Loading Loading @@ -569,9 +578,10 @@ HRESULT DX::LoadWAVAudioInMemory( const uint8_t* wavData, } //-------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DX::LoadWAVAudioFromFile( const wchar_t* szFileName, HRESULT DX::LoadWAVAudioFromFile( const wchar_t* szFileName, std::unique_ptr<uint8_t[]>& wavData, const WAVEFORMATEX** wfx, const uint8_t** startAudio, Loading Loading @@ -600,9 +610,12 @@ HRESULT DX::LoadWAVAudioFromFile( const wchar_t* szFileName, } //-------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DX::LoadWAVAudioInMemoryEx( const uint8_t* wavData, size_t wavDataSize, DX::WAVData& result ) HRESULT DX::LoadWAVAudioInMemoryEx( const uint8_t* wavData, size_t wavDataSize, DX::WAVData& result) { if (!wavData) return E_INVALIDARG; Loading Loading @@ -641,9 +654,12 @@ HRESULT DX::LoadWAVAudioInMemoryEx( const uint8_t* wavData, size_t wavDataSize, } //-------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT DX::LoadWAVAudioFromFileEx( const wchar_t* szFileName, std::unique_ptr<uint8_t[]>& wavData, DX::WAVData& result ) HRESULT DX::LoadWAVAudioFromFileEx( const wchar_t* szFileName, std::unique_ptr<uint8_t[]>& wavData, DX::WAVData& result) { if (!szFileName) return E_INVALIDARG; Loading
Kits/ATGTK/WAVFileReader.h +51 −46 Original line number Diff line number Diff line Loading @@ -46,13 +46,15 @@ namespace DX } } HRESULT LoadWAVAudioInMemory( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, HRESULT LoadWAVAudioInMemory( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Outptr_ const WAVEFORMATEX** wfx, _Outptr_ const uint8_t** startAudio, _Out_ uint32_t* audioBytes); HRESULT LoadWAVAudioFromFile( _In_z_ const wchar_t* szFileName, HRESULT LoadWAVAudioFromFile( _In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<uint8_t[]>& wavData, _Outptr_ const WAVEFORMATEX** wfx, _Outptr_ const uint8_t** startAudio, Loading Loading @@ -129,10 +131,13 @@ namespace DX } }; HRESULT LoadWAVAudioInMemoryEx( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Out_ WAVData& result ); HRESULT LoadWAVAudioInMemoryEx( _In_reads_bytes_(wavDataSize) const uint8_t* wavData, _In_ size_t wavDataSize, _Out_ WAVData& result); HRESULT LoadWAVAudioFromFileEx( _In_z_ const wchar_t* szFileName, HRESULT LoadWAVAudioFromFileEx( _In_z_ const wchar_t* szFileName, _Inout_ std::unique_ptr<uint8_t[]>& wavData, _Out_ WAVData& result); } No newline at end of file
PCSamples/IntroGraphics/DirectXTKSimpleSamplePC/DeviceResources.cpp +55 −13 Original line number Diff line number Diff line Loading @@ -47,7 +47,12 @@ namespace }; // Constructor for DeviceResources. DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel, unsigned int flags) : DeviceResources::DeviceResources( DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel, unsigned int flags) noexcept : m_screenViewport{}, m_backBufferFormat(backBufferFormat), m_depthBufferFormat(depthBufferFormat), Loading Loading @@ -517,7 +522,44 @@ void DeviceResources::GetHardwareAdapter(IDXGIAdapter1** ppAdapter) *ppAdapter = nullptr; ComPtr<IDXGIAdapter1> adapter; for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1(adapterIndex, adapter.ReleaseAndGetAddressOf()); adapterIndex++) #if defined(__dxgi1_6_h__) && defined(NTDDI_WIN10_RS4) ComPtr<IDXGIFactory6> factory6; HRESULT hr = m_dxgiFactory.As(&factory6); if (SUCCEEDED(hr)) { for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != factory6->EnumAdapterByGpuPreference( adapterIndex, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(adapter.ReleaseAndGetAddressOf())); adapterIndex++) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) { // Don't select the Basic Render Driver adapter. continue; } #ifdef _DEBUG wchar_t buff[256] = {}; swprintf_s(buff, L"Direct3D Adapter (%u): VID:%04X, PID:%04X - %ls\n", adapterIndex, desc.VendorId, desc.DeviceId, desc.Description); OutputDebugStringW(buff); #endif break; } } else #endif for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1( adapterIndex, adapter.ReleaseAndGetAddressOf()); adapterIndex++) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); Loading
PCSamples/IntroGraphics/DirectXTKSimpleSamplePC/DeviceResources.h +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ namespace DX DXGI_FORMAT depthBufferFormat = DXGI_FORMAT_D32_FLOAT, UINT backBufferCount = 2, D3D_FEATURE_LEVEL minFeatureLevel = D3D_FEATURE_LEVEL_10_0, unsigned int flags = c_FlipPresent); unsigned int flags = c_FlipPresent) noexcept; void CreateDeviceResources(); void CreateWindowSizeDependentResources(); Loading
PCSamples/IntroGraphics/DirectXTKSimpleSamplePC12/DeviceResources.cpp +75 −20 Original line number Diff line number Diff line Loading @@ -25,7 +25,12 @@ namespace }; // Constructor for DeviceResources. DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel, unsigned int flags) : DeviceResources::DeviceResources( DXGI_FORMAT backBufferFormat, DXGI_FORMAT depthBufferFormat, UINT backBufferCount, D3D_FEATURE_LEVEL minFeatureLevel, unsigned int flags) noexcept(false) : m_backBufferIndex(0), m_fenceValues{}, m_rtvDescriptorSize(0), Loading Loading @@ -123,6 +128,8 @@ void DeviceResources::CreateDeviceResources() IID_PPV_ARGS(m_d3dDevice.ReleaseAndGetAddressOf()) )); m_d3dDevice->SetName(L"DeviceResources"); #ifndef NDEBUG // Configure debug device (if active). ComPtr<ID3D12InfoQueue> d3dInfoQueue; Loading Loading @@ -175,6 +182,8 @@ void DeviceResources::CreateDeviceResources() ThrowIfFailed(m_d3dDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(m_commandQueue.ReleaseAndGetAddressOf()))); m_commandQueue->SetName(L"DeviceResources"); // Create descriptor heaps for render target views and depth stencil views. D3D12_DESCRIPTOR_HEAP_DESC rtvDescriptorHeapDesc = {}; rtvDescriptorHeapDesc.NumDescriptors = m_backBufferCount; Loading @@ -201,12 +210,18 @@ void DeviceResources::CreateDeviceResources() for (UINT n = 0; n < m_backBufferCount; n++) { ThrowIfFailed(m_d3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(m_commandAllocators[n].ReleaseAndGetAddressOf()))); wchar_t name[25] = {}; swprintf_s(name, L"Render target %u", n); m_commandAllocators[n]->SetName(name); } // Create a command list for recording graphics commands. ThrowIfFailed(m_d3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocators[0].Get(), nullptr, IID_PPV_ARGS(m_commandList.ReleaseAndGetAddressOf()))); ThrowIfFailed(m_commandList->Close()); m_commandList->SetName(L"DeviceResources"); // Create a fence for tracking GPU execution progress. ThrowIfFailed(m_d3dDevice->CreateFence(m_fenceValues[m_backBufferIndex], D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(m_fence.ReleaseAndGetAddressOf()))); m_fenceValues[m_backBufferIndex]++; Loading Loading @@ -577,7 +592,47 @@ void DeviceResources::GetAdapter(IDXGIAdapter1** ppAdapter) *ppAdapter = nullptr; ComPtr<IDXGIAdapter1> adapter; for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1(adapterIndex, adapter.ReleaseAndGetAddressOf()); ++adapterIndex) #if defined(__dxgi1_6_h__) && defined(NTDDI_WIN10_RS4) ComPtr<IDXGIFactory6> factory6; HRESULT hr = m_dxgiFactory.As(&factory6); if (SUCCEEDED(hr)) { for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != factory6->EnumAdapterByGpuPreference( adapterIndex, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(adapter.ReleaseAndGetAddressOf())); adapterIndex++) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); 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(), m_d3dMinFeatureLevel, _uuidof(ID3D12Device), nullptr))) { #ifdef _DEBUG wchar_t buff[256] = {}; swprintf_s(buff, L"Direct3D Adapter (%u): VID:%04X, PID:%04X - %ls\n", adapterIndex, desc.VendorId, desc.DeviceId, desc.Description); OutputDebugStringW(buff); #endif break; } } } else #endif for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1( adapterIndex, adapter.ReleaseAndGetAddressOf()); ++adapterIndex) { DXGI_ADAPTER_DESC1 desc; ThrowIfFailed(adapter->GetDesc1(&desc)); Loading