Skip to content

Commit 1922f81

Browse files
authored
Merge pull request #860 from siradam7th/add-warp-to-wg
Add missing warp device selection to the work graphs samples
2 parents 3ca9e76 + 7537b13 commit 1922f81

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

Samples/Desktop/D3D12HelloWorld/src/HelloWorkGraphs/D3D12HelloWorkGraphs.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323
#include "dxcapi.h"
2424
#include "d3d12.h"
2525
#include "d3dx12.h"
26+
#include <dxgi1_6.h>
2627

2728
extern "C" { __declspec(dllexport) extern const UINT D3D12SDKVersion = 613; }
2829
extern "C" { __declspec(dllexport) extern const char* D3D12SDKPath = u8".\\D3D12\\"; }
2930

3031
using namespace std;
3132
LPCWSTR g_File = L"D3D12HelloWorkGraphs.hlsl";
3233

34+
// use a warp device instead of a hardware device
35+
bool g_useWarpDevice = false;
36+
3337
//=================================================================================================================================
3438
// Helper / setup code, not specific to work graphs
3539
// Look for "Start of interesting code" further below.
@@ -176,7 +180,20 @@ void InitDeviceAndContext(D3DContext& D3D)
176180

177181
D3D_FEATURE_LEVEL FL = D3D_FEATURE_LEVEL_11_0;
178182
CComPtr<ID3D12Device> spDevice;
179-
VERIFY_SUCCEEDED(D3D12CreateDevice(NULL, FL, IID_PPV_ARGS(&spDevice)));
183+
184+
if (g_useWarpDevice)
185+
{
186+
CComPtr<IDXGIFactory4> factory;
187+
VERIFY_SUCCEEDED(CreateDXGIFactory2(0, IID_PPV_ARGS(&factory)));
188+
189+
CComPtr<IDXGIAdapter> warpAdapter;
190+
VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
191+
VERIFY_SUCCEEDED(D3D12CreateDevice(warpAdapter, FL, IID_PPV_ARGS(&spDevice)));
192+
}
193+
else
194+
{
195+
VERIFY_SUCCEEDED(D3D12CreateDevice(NULL, FL, IID_PPV_ARGS(&spDevice)));
196+
}
180197
D3D.spDevice = spDevice;
181198

182199
VERIFY_SUCCEEDED(D3D.spDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&D3D.spFence)));

Samples/Desktop/D3D12HelloWorld/src/WorkGraphsSandbox/D3D12WorkGraphsSandbox.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "dxcapi.h"
2323
#include "d3d12.h"
2424
#include "d3dx12.h"
25+
#include <dxgi1_6.h>
2526

2627
extern "C" { __declspec(dllexport) extern const UINT D3D12SDKVersion = 613; }
2728
extern "C" { __declspec(dllexport) extern const char* D3D12SDKPath = u8".\\D3D12\\"; }
@@ -31,6 +32,9 @@ const char* g_File = "D3D12WorkGraphsSandbox.hlsl";
3132
wstring g_wFile;
3233
bool g_bUseCollections = false;
3334

35+
// use a warp device instead of a hardware device
36+
bool g_useWarpDevice = false;
37+
3438
//=================================================================================================================================
3539
// Helper / setup code, not specific to work graphs
3640
// Look for "Start of interesting code" further below.
@@ -213,7 +217,20 @@ void InitDeviceAndContext(D3DContext& D3D)
213217

214218
D3D_FEATURE_LEVEL FL = D3D_FEATURE_LEVEL_11_0;
215219
CComPtr<ID3D12Device> spDevice;
216-
VERIFY_SUCCEEDED(D3D12CreateDevice(NULL, FL, IID_PPV_ARGS(&spDevice)));
220+
221+
if (g_useWarpDevice)
222+
{
223+
CComPtr<IDXGIFactory4> factory;
224+
VERIFY_SUCCEEDED(CreateDXGIFactory2(0, IID_PPV_ARGS(&factory)));
225+
226+
CComPtr<IDXGIAdapter> warpAdapter;
227+
VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
228+
VERIFY_SUCCEEDED(D3D12CreateDevice(warpAdapter, FL, IID_PPV_ARGS(&spDevice)));
229+
}
230+
else
231+
{
232+
VERIFY_SUCCEEDED(D3D12CreateDevice(NULL, FL, IID_PPV_ARGS(&spDevice)));
233+
}
217234
D3D.spDevice = spDevice;
218235

219236
D3D.spInfoQueue = spDevice;

0 commit comments

Comments
 (0)