Skip to content

Commit deed337

Browse files
committed
[dxgi] Use singleton for DXGI options
Dying Light: The Beast is insane and creates a new DXGI factory every single fucking frame, and evaluating options with XeSS checks etc is not exactly cheap.
1 parent c2f9dfc commit deed337

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/dxgi/dxgi_factory.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace dxvk {
1111

1212
static Singleton<DxvkInstance> g_dxvkInstance;
13+
static Singleton<DxgiOptions> g_dxgiOptions;
1314

1415
static dxvk::mutex s_globalHDRStateMutex;
1516
static DXVK_VK_GLOBAL_HDR_STATE s_globalHDRState{};
@@ -81,8 +82,8 @@ namespace dxvk {
8182
DxgiFactory::DxgiFactory(UINT Flags)
8283
: m_instance (g_dxvkInstance.acquire(0)),
8384
m_interop (this),
84-
m_options (m_instance->config()),
85-
m_monitorInfo (this, m_options),
85+
m_options (g_dxgiOptions.acquire(m_instance->config())),
86+
m_monitorInfo (this, *m_options),
8687
m_flags (Flags),
8788
m_monitorFallback (false),
8889
m_destructionNotifier(this) {
@@ -134,6 +135,7 @@ namespace dxvk {
134135

135136

136137
DxgiFactory::~DxgiFactory() {
138+
g_dxgiOptions.release();
137139
g_dxvkInstance.release();
138140
}
139141

@@ -284,7 +286,7 @@ namespace dxvk {
284286
IDXGISwapChain1** ppSwapChain) {
285287
InitReturnPtr(ppSwapChain);
286288

287-
if (!m_options.enableDummyCompositionSwapchain) {
289+
if (!m_options->enableDummyCompositionSwapchain) {
288290
Logger::err("DxgiFactory::CreateSwapChainForComposition: Not implemented");
289291
return E_NOTIMPL;
290292
}

src/dxgi/dxgi_factory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ namespace dxvk {
182182
}
183183

184184
const DxgiOptions* GetOptions() const {
185-
return &m_options;
185+
return m_options.ptr();
186186
}
187187

188188
DxgiMonitorInfo* GetMonitorInfo() {
@@ -195,7 +195,7 @@ namespace dxvk {
195195

196196
Rc<DxvkInstance> m_instance;
197197
DxgiVkFactory m_interop;
198-
DxgiOptions m_options;
198+
Rc<DxgiOptions> m_options;
199199
DxgiMonitorInfo m_monitorInfo;
200200
UINT m_flags;
201201
BOOL m_monitorFallback;

src/dxgi/dxgi_options.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ namespace dxvk {
1717
struct DxgiOptions {
1818
DxgiOptions(const Config& config);
1919

20+
void incRef() {
21+
m_useCount.fetch_add(1u);
22+
}
23+
24+
void decRef() {
25+
if (m_useCount.fetch_sub(1u) == 1u)
26+
delete this;
27+
}
28+
2029
/// Override PCI vendor and device IDs reported to the
2130
/// application. This may make apps think they are running
2231
/// on a different GPU than they do and behave differently.
@@ -58,6 +67,11 @@ namespace dxvk {
5867

5968
/// Forced refresh rate, disable other modes
6069
uint32_t forceRefreshRate;
70+
71+
private:
72+
73+
std::atomic<uint32_t> m_useCount = { 0u };
74+
6175
};
6276

6377
}

0 commit comments

Comments
 (0)