Skip to content

Commit

Permalink
[dxgi,d3d9] Use global singleton for DXVK instances
Browse files Browse the repository at this point in the history
No reason to have multiple of these around, and instance creation
is fairly expensive.
  • Loading branch information
doitsujin committed Jan 23, 2023
1 parent d414342 commit 61d72ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/d3d9/d3d9_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
#include "d3d9_caps.h"
#include "d3d9_device.h"

#include "../util/util_singleton.h"

#include <algorithm>

namespace dxvk {

Singleton<DxvkInstance> g_dxvkInstance;

D3D9InterfaceEx::D3D9InterfaceEx(bool bExtended)
: m_instance ( new DxvkInstance() )
: m_instance ( g_dxvkInstance.acquire() )
, m_extended ( bExtended )
, m_d3d9Options ( nullptr, m_instance->config() )
, m_d3d9Interop ( this ) {
Expand Down Expand Up @@ -64,6 +68,11 @@ namespace dxvk {
}


D3D9InterfaceEx::~D3D9InterfaceEx() {
g_dxvkInstance.release();
}


HRESULT STDMETHODCALLTYPE D3D9InterfaceEx::QueryInterface(REFIID riid, void** ppvObject) {
if (ppvObject == nullptr)
return E_POINTER;
Expand Down
2 changes: 2 additions & 0 deletions src/d3d9/d3d9_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace dxvk {

D3D9InterfaceEx(bool bExtended);

~D3D9InterfaceEx();

HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);

HRESULT STDMETHODCALLTYPE RegisterSoftwareDevice(void* pInitializeFunction);
Expand Down
8 changes: 6 additions & 2 deletions src/dxgi/dxgi_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
#include "dxgi_swapchain.h"
#include "dxgi_swapchain_dispatcher.h"

#include "../util/util_singleton.h"

namespace dxvk {

Singleton<DxvkInstance> g_dxvkInstance;

DxgiVkFactory::DxgiVkFactory(DxgiFactory* pFactory)
: m_factory(pFactory) {

Expand Down Expand Up @@ -44,7 +48,7 @@ namespace dxvk {


DxgiFactory::DxgiFactory(UINT Flags)
: m_instance (new DxvkInstance()),
: m_instance (g_dxvkInstance.acquire()),
m_interop (this),
m_options (m_instance->config()),
m_monitorInfo (this, m_options),
Expand All @@ -55,7 +59,7 @@ namespace dxvk {


DxgiFactory::~DxgiFactory() {

g_dxvkInstance.release();
}


Expand Down

0 comments on commit 61d72ee

Please sign in to comment.