Skip to content

Commit 9c5c3ab

Browse files
committed
Merge pull request #19 from Microsoft/develop
Merge recent bug fixes to master
2 parents ea41ec7 + 7991b5d commit 9c5c3ab

39 files changed

+483
-41
lines changed

Samples/D3D1211On12/src/D3D1211On12.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ void D3D1211on12::LoadPipeline()
7373
}
7474
else
7575
{
76+
ComPtr<IDXGIAdapter1> hardwareAdapter;
77+
GetHardwareAdapter(factory.Get(), &hardwareAdapter);
78+
7679
ThrowIfFailed(D3D12CreateDevice(
77-
nullptr,
80+
hardwareAdapter.Get(),
7881
D3D_FEATURE_LEVEL_11_0,
7982
IID_PPV_ARGS(&m_d3d12Device)
8083
));
@@ -337,7 +340,7 @@ void D3D1211on12::LoadAssets()
337340
m_fenceValues[m_frameIndex]++;
338341

339342
// Create an event handle to use for frame synchronization.
340-
m_fenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
343+
m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
341344
if (m_fenceEvent == nullptr)
342345
{
343346
ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));

Samples/D3D1211On12/src/DXSample.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "DXSample.h"
1414
#include <shellapi.h>
1515

16-
DXSample::DXSample(UINT width, UINT height, std::wstring name):
16+
DXSample::DXSample(UINT width, UINT height, std::wstring name) :
1717
m_width(width),
1818
m_height(height),
1919
m_useWarpDevice(false)
@@ -100,6 +100,36 @@ std::wstring DXSample::GetAssetFullPath(LPCWSTR assetName)
100100
return m_assetsPath + assetName;
101101
}
102102

103+
// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
104+
// If no such adapter can be found, *ppAdapter will be set to nullptr.
105+
void DXSample::GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter)
106+
{
107+
IDXGIAdapter1* pAdapter = nullptr;
108+
*ppAdapter = nullptr;
109+
110+
for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &pAdapter); ++adapterIndex)
111+
{
112+
DXGI_ADAPTER_DESC1 desc;
113+
pAdapter->GetDesc1(&desc);
114+
115+
if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
116+
{
117+
// Don't select the Basic Render Driver adapter.
118+
// If you want a software adapter, pass in "/warp" on the command line.
119+
continue;
120+
}
121+
122+
// Check to see if the adapter supports Direct3D 12, but don't create the
123+
// actual device yet.
124+
if (SUCCEEDED(D3D12CreateDevice(pAdapter, D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr)))
125+
{
126+
break;
127+
}
128+
}
129+
130+
*ppAdapter = pAdapter;
131+
}
132+
103133
// Helper function for setting the window's title text.
104134
void DXSample::SetCustomWindowText(LPCWSTR text)
105135
{

Samples/D3D1211On12/src/DXSample.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DXSample
3030
virtual bool OnEvent(MSG msg) = 0;
3131

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

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

Samples/D3D12Bundles/src/D3D12Bundles.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ void D3D12Bundles::LoadPipeline()
7070
}
7171
else
7272
{
73+
ComPtr<IDXGIAdapter1> hardwareAdapter;
74+
GetHardwareAdapter(factory.Get(), &hardwareAdapter);
75+
7376
ThrowIfFailed(D3D12CreateDevice(
74-
nullptr,
77+
hardwareAdapter.Get(),
7578
D3D_FEATURE_LEVEL_11_0,
7679
IID_PPV_ARGS(&m_device)
7780
));
@@ -411,7 +414,7 @@ void D3D12Bundles::LoadAssets()
411414
m_fenceValue++;
412415

413416
// Create an event handle to use for frame synchronization.
414-
m_fenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
417+
m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
415418
if (m_fenceEvent == nullptr)
416419
{
417420
ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));

Samples/D3D12Bundles/src/DXSample.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "DXSample.h"
1414
#include <shellapi.h>
1515

16-
DXSample::DXSample(UINT width, UINT height, std::wstring name):
16+
DXSample::DXSample(UINT width, UINT height, std::wstring name) :
1717
m_width(width),
1818
m_height(height),
1919
m_useWarpDevice(false)
@@ -100,6 +100,36 @@ std::wstring DXSample::GetAssetFullPath(LPCWSTR assetName)
100100
return m_assetsPath + assetName;
101101
}
102102

103+
// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
104+
// If no such adapter can be found, *ppAdapter will be set to nullptr.
105+
void DXSample::GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter)
106+
{
107+
IDXGIAdapter1* pAdapter = nullptr;
108+
*ppAdapter = nullptr;
109+
110+
for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &pAdapter); ++adapterIndex)
111+
{
112+
DXGI_ADAPTER_DESC1 desc;
113+
pAdapter->GetDesc1(&desc);
114+
115+
if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
116+
{
117+
// Don't select the Basic Render Driver adapter.
118+
// If you want a software adapter, pass in "/warp" on the command line.
119+
continue;
120+
}
121+
122+
// Check to see if the adapter supports Direct3D 12, but don't create the
123+
// actual device yet.
124+
if (SUCCEEDED(D3D12CreateDevice(pAdapter, D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr)))
125+
{
126+
break;
127+
}
128+
}
129+
130+
*ppAdapter = pAdapter;
131+
}
132+
103133
// Helper function for setting the window's title text.
104134
void DXSample::SetCustomWindowText(LPCWSTR text)
105135
{

Samples/D3D12Bundles/src/DXSample.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DXSample
3030
virtual bool OnEvent(MSG msg) = 0;
3131

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

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

Samples/D3D12DynamicIndexing/src/D3D12DynamicIndexing.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ void D3D12DynamicIndexing::LoadPipeline()
7474
}
7575
else
7676
{
77+
ComPtr<IDXGIAdapter1> hardwareAdapter;
78+
GetHardwareAdapter(factory.Get(), &hardwareAdapter);
79+
7780
ThrowIfFailed(D3D12CreateDevice(
78-
nullptr,
81+
hardwareAdapter.Get(),
7982
D3D_FEATURE_LEVEL_11_0,
8083
IID_PPV_ARGS(&m_device)
8184
));
@@ -509,7 +512,7 @@ void D3D12DynamicIndexing::LoadAssets()
509512
m_fenceValue++;
510513

511514
// Create an event handle to use for frame synchronization.
512-
m_fenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
515+
m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
513516
if (m_fenceEvent == nullptr)
514517
{
515518
ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));

Samples/D3D12DynamicIndexing/src/DXSample.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "DXSample.h"
1414
#include <shellapi.h>
1515

16-
DXSample::DXSample(UINT width, UINT height, std::wstring name):
16+
DXSample::DXSample(UINT width, UINT height, std::wstring name) :
1717
m_width(width),
1818
m_height(height),
1919
m_useWarpDevice(false)
@@ -100,6 +100,36 @@ std::wstring DXSample::GetAssetFullPath(LPCWSTR assetName)
100100
return m_assetsPath + assetName;
101101
}
102102

103+
// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
104+
// If no such adapter can be found, *ppAdapter will be set to nullptr.
105+
void DXSample::GetHardwareAdapter(_In_ IDXGIFactory4* pFactory, _Outptr_result_maybenull_ IDXGIAdapter1** ppAdapter)
106+
{
107+
IDXGIAdapter1* pAdapter = nullptr;
108+
*ppAdapter = nullptr;
109+
110+
for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &pAdapter); ++adapterIndex)
111+
{
112+
DXGI_ADAPTER_DESC1 desc;
113+
pAdapter->GetDesc1(&desc);
114+
115+
if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
116+
{
117+
// Don't select the Basic Render Driver adapter.
118+
// If you want a software adapter, pass in "/warp" on the command line.
119+
continue;
120+
}
121+
122+
// Check to see if the adapter supports Direct3D 12, but don't create the
123+
// actual device yet.
124+
if (SUCCEEDED(D3D12CreateDevice(pAdapter, D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr)))
125+
{
126+
break;
127+
}
128+
}
129+
130+
*ppAdapter = pAdapter;
131+
}
132+
103133
// Helper function for setting the window's title text.
104134
void DXSample::SetCustomWindowText(LPCWSTR text)
105135
{

Samples/D3D12DynamicIndexing/src/DXSample.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DXSample
3030
virtual bool OnEvent(MSG msg) = 0;
3131

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

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

Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ void D3D12ExecuteIndirect::LoadPipeline()
8585
}
8686
else
8787
{
88+
ComPtr<IDXGIAdapter1> hardwareAdapter;
89+
GetHardwareAdapter(factory.Get(), &hardwareAdapter);
90+
8891
ThrowIfFailed(D3D12CreateDevice(
89-
nullptr,
92+
hardwareAdapter.Get(),
9093
D3D_FEATURE_LEVEL_11_0,
9194
IID_PPV_ARGS(&m_device)
9295
));
@@ -535,7 +538,7 @@ void D3D12ExecuteIndirect::LoadAssets()
535538
m_fenceValues[m_frameIndex]++;
536539

537540
// Create an event handle to use for frame synchronization.
538-
m_fenceEvent = CreateEventEx(nullptr, FALSE, FALSE, EVENT_ALL_ACCESS);
541+
m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
539542
if (m_fenceEvent == nullptr)
540543
{
541544
ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));

0 commit comments

Comments
 (0)