-
Notifications
You must be signed in to change notification settings - Fork 47
/
dx_utils.cc
120 lines (101 loc) · 3.47 KB
/
dx_utils.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//==============================================================================
// Copyright (c) 2015-2020 Advanced Micro Devices, Inc. All rights reserved.
/// @author AMD Developer Tools Team
/// @file
/// @brief Common DX utility function implementations
//==============================================================================
#include "dx_utils.h"
GpaStatus DxGetAdapterDesc(IUnknown* device, DXGI_ADAPTER_DESC& adapter_desc)
{
GpaStatus status = kGpaStatusOk;
if (nullptr == device)
{
GPA_LOG_ERROR("NULL device.");
status = kGpaStatusErrorNullPointer;
}
else
{
IDXGIDevice1* dxgi_device = nullptr;
HRESULT hr = device->QueryInterface(__uuidof(IDXGIDevice1), reinterpret_cast<void**>(&dxgi_device));
if (FAILED(hr) || (nullptr == dxgi_device))
{
GPA_LOG_ERROR("Unable to get IDXGIDevice1 interface from ID3D11Device.");
status = kGpaStatusErrorFailed;
}
else
{
IDXGIAdapter* adapter = nullptr;
hr = dxgi_device->GetAdapter(&adapter);
if (FAILED(hr) || (nullptr == adapter))
{
GPA_LOG_ERROR("Unable to get Adapter from IDXGIDevice1.");
status = kGpaStatusErrorFailed;
}
else
{
memset(&adapter_desc, 0, sizeof(adapter_desc));
hr = adapter->GetDesc(&adapter_desc);
if (S_OK != hr)
{
GPA_LOG_ERROR("Could not get adapter description, hardware cannot be supported.");
status = kGpaStatusErrorHardwareNotSupported;
}
adapter->Release();
}
dxgi_device->Release();
}
}
return status;
}
HMONITOR DxGetDeviceMonitor(IUnknown* device)
{
HMONITOR h_monitor = nullptr;
if (nullptr == device)
{
GPA_LOG_ERROR("NULL device.");
}
else
{
IDXGIDevice1* dxgi_device = nullptr;
HRESULT hr = device->QueryInterface(__uuidof(IDXGIDevice1), reinterpret_cast<void**>(&dxgi_device));
if (FAILED(hr) || (nullptr == dxgi_device))
{
GPA_LOG_ERROR("Unable to get IDXGIDevice1 interface from ID3D11Device.");
}
else
{
IDXGIAdapter* adapter = nullptr;
hr = dxgi_device->GetAdapter(&adapter);
if (FAILED(hr) || (nullptr == adapter))
{
GPA_LOG_ERROR("Unable to get Adapter from IDXGIDevice1.");
}
else
{
IDXGIOutput* output = nullptr;
hr = adapter->EnumOutputs(0, &output);
if (S_OK != hr)
{
GPA_LOG_ERROR("Unable to get Adapter outputs.");
}
else
{
DXGI_OUTPUT_DESC output_desc;
hr = output->GetDesc(&output_desc);
if (S_OK != hr)
{
GPA_LOG_ERROR("Failed to get output description.");
}
else
{
h_monitor = output_desc.Monitor;
}
output->Release();
}
adapter->Release();
}
dxgi_device->Release();
}
}
return h_monitor;
}