Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Samples/D3D1211On12/src/D3D1211On12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ void D3D1211on12::LoadPipeline()
}
else
{
ComPtr<IDXGIAdapter1> hardwareAdapter;
GetHardwareAdapter(factory.Get(), &hardwareAdapter);

ThrowIfFailed(D3D12CreateDevice(
nullptr,
hardwareAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_d3d12Device)
));
Expand Down Expand Up @@ -337,7 +340,7 @@ void D3D1211on12::LoadAssets()
m_fenceValues[m_frameIndex]++;

// Create an event handle to use for frame synchronization.
m_fenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (m_fenceEvent == nullptr)
{
ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
Expand Down
32 changes: 31 additions & 1 deletion Samples/D3D1211On12/src/DXSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "DXSample.h"
#include <shellapi.h>

DXSample::DXSample(UINT width, UINT height, std::wstring name):
DXSample::DXSample(UINT width, UINT height, std::wstring name) :
m_width(width),
m_height(height),
m_useWarpDevice(false)
Expand Down Expand Up @@ -100,6 +100,36 @@ std::wstring DXSample::GetAssetFullPath(LPCWSTR assetName)
return m_assetsPath + assetName;
}

// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
// If no such adapter can be found, *ppAdapter will be set to nullptr.
void DXSample::GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter)
{
IDXGIAdapter1* pAdapter = nullptr;
*ppAdapter = nullptr;

for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &pAdapter); ++adapterIndex)
{
DXGI_ADAPTER_DESC1 desc;
pAdapter->GetDesc1(&desc);

if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
{
// Don't select the Basic Render Driver adapter.
// If you want a software adapter, pass in "/warp" on the command line.
continue;
}

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

*ppAdapter = pAdapter;
}

// Helper function for setting the window's title text.
void DXSample::SetCustomWindowText(LPCWSTR text)
{
Expand Down
1 change: 1 addition & 0 deletions Samples/D3D1211On12/src/DXSample.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DXSample
virtual bool OnEvent(MSG msg) = 0;

std::wstring GetAssetFullPath(LPCWSTR assetName);
void GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter);

static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

Expand Down
7 changes: 5 additions & 2 deletions Samples/D3D12Bundles/src/D3D12Bundles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ void D3D12Bundles::LoadPipeline()
}
else
{
ComPtr<IDXGIAdapter1> hardwareAdapter;
GetHardwareAdapter(factory.Get(), &hardwareAdapter);

ThrowIfFailed(D3D12CreateDevice(
nullptr,
hardwareAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_device)
));
Expand Down Expand Up @@ -411,7 +414,7 @@ void D3D12Bundles::LoadAssets()
m_fenceValue++;

// Create an event handle to use for frame synchronization.
m_fenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (m_fenceEvent == nullptr)
{
ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
Expand Down
32 changes: 31 additions & 1 deletion Samples/D3D12Bundles/src/DXSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "DXSample.h"
#include <shellapi.h>

DXSample::DXSample(UINT width, UINT height, std::wstring name):
DXSample::DXSample(UINT width, UINT height, std::wstring name) :
m_width(width),
m_height(height),
m_useWarpDevice(false)
Expand Down Expand Up @@ -100,6 +100,36 @@ std::wstring DXSample::GetAssetFullPath(LPCWSTR assetName)
return m_assetsPath + assetName;
}

// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
// If no such adapter can be found, *ppAdapter will be set to nullptr.
void DXSample::GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter)
{
IDXGIAdapter1* pAdapter = nullptr;
*ppAdapter = nullptr;

for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &pAdapter); ++adapterIndex)
{
DXGI_ADAPTER_DESC1 desc;
pAdapter->GetDesc1(&desc);

if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
{
// Don't select the Basic Render Driver adapter.
// If you want a software adapter, pass in "/warp" on the command line.
continue;
}

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

*ppAdapter = pAdapter;
}

// Helper function for setting the window's title text.
void DXSample::SetCustomWindowText(LPCWSTR text)
{
Expand Down
1 change: 1 addition & 0 deletions Samples/D3D12Bundles/src/DXSample.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DXSample
virtual bool OnEvent(MSG msg) = 0;

std::wstring GetAssetFullPath(LPCWSTR assetName);
void GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter);

static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

Expand Down
7 changes: 5 additions & 2 deletions Samples/D3D12DynamicIndexing/src/D3D12DynamicIndexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ void D3D12DynamicIndexing::LoadPipeline()
}
else
{
ComPtr<IDXGIAdapter1> hardwareAdapter;
GetHardwareAdapter(factory.Get(), &hardwareAdapter);

ThrowIfFailed(D3D12CreateDevice(
nullptr,
hardwareAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_device)
));
Expand Down Expand Up @@ -509,7 +512,7 @@ void D3D12DynamicIndexing::LoadAssets()
m_fenceValue++;

// Create an event handle to use for frame synchronization.
m_fenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (m_fenceEvent == nullptr)
{
ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
Expand Down
32 changes: 31 additions & 1 deletion Samples/D3D12DynamicIndexing/src/DXSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "DXSample.h"
#include <shellapi.h>

DXSample::DXSample(UINT width, UINT height, std::wstring name):
DXSample::DXSample(UINT width, UINT height, std::wstring name) :
m_width(width),
m_height(height),
m_useWarpDevice(false)
Expand Down Expand Up @@ -100,6 +100,36 @@ std::wstring DXSample::GetAssetFullPath(LPCWSTR assetName)
return m_assetsPath + assetName;
}

// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
// If no such adapter can be found, *ppAdapter will be set to nullptr.
void DXSample::GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter)
{
IDXGIAdapter1* pAdapter = nullptr;
*ppAdapter = nullptr;

for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &pAdapter); ++adapterIndex)
{
DXGI_ADAPTER_DESC1 desc;
pAdapter->GetDesc1(&desc);

if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
{
// Don't select the Basic Render Driver adapter.
// If you want a software adapter, pass in "/warp" on the command line.
continue;
}

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

*ppAdapter = pAdapter;
}

// Helper function for setting the window's title text.
void DXSample::SetCustomWindowText(LPCWSTR text)
{
Expand Down
1 change: 1 addition & 0 deletions Samples/D3D12DynamicIndexing/src/DXSample.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DXSample
virtual bool OnEvent(MSG msg) = 0;

std::wstring GetAssetFullPath(LPCWSTR assetName);
void GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter);

static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

Expand Down
7 changes: 5 additions & 2 deletions Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ void D3D12ExecuteIndirect::LoadPipeline()
}
else
{
ComPtr<IDXGIAdapter1> hardwareAdapter;
GetHardwareAdapter(factory.Get(), &hardwareAdapter);

ThrowIfFailed(D3D12CreateDevice(
nullptr,
hardwareAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_device)
));
Expand Down Expand Up @@ -535,7 +538,7 @@ void D3D12ExecuteIndirect::LoadAssets()
m_fenceValues[m_frameIndex]++;

// Create an event handle to use for frame synchronization.
m_fenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (m_fenceEvent == nullptr)
{
ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
Expand Down
32 changes: 31 additions & 1 deletion Samples/D3D12ExecuteIndirect/src/DXSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "DXSample.h"
#include <shellapi.h>

DXSample::DXSample(UINT width, UINT height, std::wstring name):
DXSample::DXSample(UINT width, UINT height, std::wstring name) :
m_width(width),
m_height(height),
m_useWarpDevice(false)
Expand Down Expand Up @@ -100,6 +100,36 @@ std::wstring DXSample::GetAssetFullPath(LPCWSTR assetName)
return m_assetsPath + assetName;
}

// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
// If no such adapter can be found, *ppAdapter will be set to nullptr.
void DXSample::GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter)
{
IDXGIAdapter1* pAdapter = nullptr;
*ppAdapter = nullptr;

for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &pAdapter); ++adapterIndex)
{
DXGI_ADAPTER_DESC1 desc;
pAdapter->GetDesc1(&desc);

if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
{
// Don't select the Basic Render Driver adapter.
// If you want a software adapter, pass in "/warp" on the command line.
continue;
}

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

*ppAdapter = pAdapter;
}

// Helper function for setting the window's title text.
void DXSample::SetCustomWindowText(LPCWSTR text)
{
Expand Down
1 change: 1 addition & 0 deletions Samples/D3D12ExecuteIndirect/src/DXSample.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DXSample
virtual bool OnEvent(MSG msg) = 0;

std::wstring GetAssetFullPath(LPCWSTR assetName);
void GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter);

static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ void D3D12HelloBundles::LoadPipeline()
}
else
{
ComPtr<IDXGIAdapter1> hardwareAdapter;
GetHardwareAdapter(factory.Get(), &hardwareAdapter);

ThrowIfFailed(D3D12CreateDevice(
nullptr,
hardwareAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&m_device)
));
Expand Down Expand Up @@ -242,7 +245,7 @@ void D3D12HelloBundles::LoadAssets()
m_fenceValue = 1;

// Create an event handle to use for frame synchronization.
m_fenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (m_fenceEvent == nullptr)
{
ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
Expand Down
32 changes: 31 additions & 1 deletion Samples/D3D12HelloWorld/src/HelloBundles/DXSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "DXSample.h"
#include <shellapi.h>

DXSample::DXSample(UINT width, UINT height, std::wstring name):
DXSample::DXSample(UINT width, UINT height, std::wstring name) :
m_width(width),
m_height(height),
m_useWarpDevice(false)
Expand Down Expand Up @@ -100,6 +100,36 @@ std::wstring DXSample::GetAssetFullPath(LPCWSTR assetName)
return m_assetsPath + assetName;
}

// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
// If no such adapter can be found, *ppAdapter will be set to nullptr.
void DXSample::GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter)
{
IDXGIAdapter1* pAdapter = nullptr;
*ppAdapter = nullptr;

for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &pAdapter); ++adapterIndex)
{
DXGI_ADAPTER_DESC1 desc;
pAdapter->GetDesc1(&desc);

if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
{
// Don't select the Basic Render Driver adapter.
// If you want a software adapter, pass in "/warp" on the command line.
continue;
}

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

*ppAdapter = pAdapter;
}

// Helper function for setting the window's title text.
void DXSample::SetCustomWindowText(LPCWSTR text)
{
Expand Down
1 change: 1 addition & 0 deletions Samples/D3D12HelloWorld/src/HelloBundles/DXSample.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DXSample
virtual bool OnEvent(MSG msg) = 0;

std::wstring GetAssetFullPath(LPCWSTR assetName);
void GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter);

static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

Expand Down
Loading