forked from crosire/reshade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdxgi_device.cpp
173 lines (145 loc) · 4.86 KB
/
dxgi_device.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* Copyright (C) 2014 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/reshade#license
*/
#include "log.hpp"
#include "dxgi_device.hpp"
#include "dxgi_swapchain.hpp"
// IDXGIDevice
HRESULT STDMETHODCALLTYPE DXGIDevice::QueryInterface(REFIID riid, void **ppvObj)
{
if (ppvObj == nullptr)
{
return E_POINTER;
}
else if (
riid == __uuidof(this) ||
riid == __uuidof(IUnknown) ||
riid == __uuidof(IDXGIObject) ||
riid == __uuidof(IDXGIDevice) ||
riid == __uuidof(IDXGIDevice1) ||
riid == __uuidof(IDXGIDevice2) ||
riid == __uuidof(IDXGIDevice3))
{
#pragma region Update to IDXGIDevice2 interface
if (riid == __uuidof(IDXGIDevice2) && _interface_version < 2)
{
IDXGIDevice2 *device2 = nullptr;
if (FAILED(_orig->QueryInterface(&device2)))
{
return E_NOINTERFACE;
}
_orig->Release();
LOG(INFO) << "Upgraded 'IDXGIDevice" << (_interface_version > 0 ? std::to_string(_interface_version) : "") << "' object " << this << " to 'IDXGIDevice2'.";
_orig = device2;
_interface_version = 2;
}
#pragma endregion
#pragma region Update to IDXGIDevice3 interface
if (riid == __uuidof(IDXGIDevice3) && _interface_version < 3)
{
IDXGIDevice3 *device3 = nullptr;
if (FAILED(_orig->QueryInterface(&device3)))
{
return E_NOINTERFACE;
}
_orig->Release();
LOG(INFO) << "Upgraded 'IDXGIDevice" << (_interface_version > 0 ? std::to_string(_interface_version) : "") << "' object " << this << " to 'IDXGIDevice3'.";
_orig = device3;
_interface_version = 3;
}
#pragma endregion
AddRef();
*ppvObj = this;
return S_OK;
}
return _direct3d_device->QueryInterface(riid, ppvObj);
}
ULONG STDMETHODCALLTYPE DXGIDevice::AddRef()
{
_ref++;
return _orig->AddRef();
}
ULONG STDMETHODCALLTYPE DXGIDevice::Release()
{
ULONG ref = _orig->Release();
if (--_ref == 0 && ref != 1)
{
LOG(WARNING) << "Reference count for 'IDXGIDevice" << (_interface_version > 0 ? std::to_string(_interface_version) : "") << "' object " << this << " is inconsistent: " << ref << ", but expected 1.";
ref = 1;
}
if (ref == 1)
{
assert(_ref <= 0);
LOG(INFO) << "Destroyed 'IDXGIDevice" << (_interface_version > 0 ? std::to_string(_interface_version) : "") << "' object " << this << ".";
delete this;
}
return ref;
}
HRESULT STDMETHODCALLTYPE DXGIDevice::SetPrivateData(REFGUID Name, UINT DataSize, const void *pData)
{
return _orig->SetPrivateData(Name, DataSize, pData);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::SetPrivateDataInterface(REFGUID Name, const IUnknown *pUnknown)
{
return _orig->SetPrivateDataInterface(Name, pUnknown);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::GetPrivateData(REFGUID Name, UINT *pDataSize, void *pData)
{
return _orig->GetPrivateData(Name, pDataSize, pData);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::GetParent(REFIID riid, void **ppParent)
{
return _orig->GetParent(riid, ppParent);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::GetAdapter(IDXGIAdapter **pAdapter)
{
return _orig->GetAdapter(pAdapter);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::CreateSurface(const DXGI_SURFACE_DESC *pDesc, UINT NumSurfaces, DXGI_USAGE Usage, const DXGI_SHARED_RESOURCE *pSharedResource, IDXGISurface **ppSurface)
{
return _orig->CreateSurface(pDesc, NumSurfaces, Usage, pSharedResource, ppSurface);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::QueryResourceResidency(IUnknown *const *ppResources, DXGI_RESIDENCY *pResidencyStatus, UINT NumResources)
{
return _orig->QueryResourceResidency(ppResources, pResidencyStatus, NumResources);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::SetGPUThreadPriority(INT Priority)
{
return _orig->SetGPUThreadPriority(Priority);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::GetGPUThreadPriority(INT *pPriority)
{
return _orig->GetGPUThreadPriority(pPriority);
}
// IDXGIDevice1
HRESULT STDMETHODCALLTYPE DXGIDevice::SetMaximumFrameLatency(UINT MaxLatency)
{
return _orig->SetMaximumFrameLatency(MaxLatency);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::GetMaximumFrameLatency(UINT *pMaxLatency)
{
return _orig->GetMaximumFrameLatency(pMaxLatency);
}
// IDXGIDevice2
HRESULT STDMETHODCALLTYPE DXGIDevice::OfferResources(UINT NumResources, IDXGIResource *const *ppResources, DXGI_OFFER_RESOURCE_PRIORITY Priority)
{
assert(_interface_version >= 2);
return static_cast<IDXGIDevice2 *>(_orig)->OfferResources(NumResources, ppResources, Priority);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::ReclaimResources(UINT NumResources, IDXGIResource *const *ppResources, BOOL *pDiscarded)
{
assert(_interface_version >= 2);
return static_cast<IDXGIDevice2 *>(_orig)->ReclaimResources(NumResources, ppResources, pDiscarded);
}
HRESULT STDMETHODCALLTYPE DXGIDevice::EnqueueSetEvent(HANDLE hEvent)
{
assert(_interface_version >= 2);
return static_cast<IDXGIDevice2 *>(_orig)->EnqueueSetEvent(hEvent);
}
// IDXGIDevice3
void STDMETHODCALLTYPE DXGIDevice::Trim()
{
assert(_interface_version >= 3);
return static_cast<IDXGIDevice3 *>(_orig)->Trim();
}