Skip to content

Commit cc37fb3

Browse files
committed
[d3d8] Add D3D9 bridge
1 parent 4b2a5e4 commit cc37fb3

10 files changed

+96
-5
lines changed

src/d3d8/d3d8_device.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ namespace dxvk {
8080
, m_window(hFocusWindow)
8181
, m_behaviorFlags(BehaviorFlags) {
8282

83+
// Get the bridge interface to D3D9.
84+
if (FAILED(GetD3D9()->QueryInterface(__uuidof(D3D9Bridge), (void**)&m_bridge))) {
85+
throw DxvkError("D3D8DeviceEx: ERROR! Failed to get D3D9 Bridge. d3d9.dll might not be DXVK!");
86+
}
87+
88+
m_bridge->SetD3D8Mode();
89+
8390
m_textures.fill(nullptr);
8491

8592
}

src/d3d8/d3d8_device.h

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "d3d8_d3d9_util.h"
1010
#include "d3d8_caps.h"
1111

12+
#include "../d3d9/d3d9_bridge.h"
13+
1214
#include <array>
1315
#include <vector>
1416
#include <type_traits>
@@ -819,6 +821,8 @@ namespace dxvk {
819821

820822
private:
821823

824+
D3D9Bridge* m_bridge;
825+
822826
Com<D3D8InterfaceEx> m_parent;
823827

824828
D3D8StateBlock* m_recorder = nullptr;

src/d3d8/meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ d3d8_src = [
99

1010
d3d8_dll = shared_library('d3d8'+dll_ext, d3d8_src, d3d8_res,
1111
name_prefix : '',
12-
dependencies : [ d3d9_dep, util_dep ],
12+
dependencies : [ d3d9_dep, d3d9_lib_dep, util_dep, dxso_dep, dxvk_dep ],
1313
include_directories : dxvk_include_path,
1414
install : true,
1515
objects : not dxvk_is_msvc ? 'd3d8'+def_spec_ext : [],

src/d3d9/d3d9_bridge.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
#include "d3d9_bridge.h"
3+
#include "d3d9_device.h"
4+
#include "d3d9_swapchain.h"
5+
6+
namespace dxvk {
7+
8+
ULONG D3D9Bridge::AddRef() {
9+
return m_device->AddRef();
10+
}
11+
12+
ULONG D3D9Bridge::Release() {
13+
return m_device->Release();
14+
}
15+
16+
void D3D9Bridge::SetD3D8Mode() {
17+
m_device->m_implicitSwapchain->SetApiName("D3D8");
18+
}
19+
20+
}

src/d3d9/d3d9_bridge.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include <windows.h>
4+
5+
6+
namespace dxvk {
7+
8+
class D3D9DeviceEx;
9+
10+
class DECLSPEC_UUID("D3D9ACAB-42A9-4C1E-AA97-DEADFADED420") D3D9Bridge;
11+
12+
class D3D9Bridge {
13+
14+
15+
public:
16+
D3D9Bridge(D3D9DeviceEx* pDevice) : m_device(pDevice) {}
17+
18+
ULONG AddRef();
19+
ULONG Release();
20+
21+
void SetD3D8Mode();
22+
23+
private:
24+
D3D9DeviceEx* m_device;
25+
};
26+
27+
}

src/d3d9/d3d9_device.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ namespace dxvk {
4949
, m_multithread ( BehaviorFlags & D3DCREATE_MULTITHREADED )
5050
, m_shaderModules ( new D3D9ShaderModuleSet )
5151
, m_d3d9Options ( dxvkDevice, pParent->GetInstance()->config() )
52-
, m_isSWVP ( (BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING) ? TRUE : FALSE ) {
52+
, m_isSWVP ( (BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING) ? TRUE : FALSE )
53+
, m_bridge ( this ) {
5354
// If we can SWVP, then we use an extended constant set
5455
// as SWVP has many more slots available than HWVP.
5556
bool canSWVP = CanSWVP();
@@ -109,6 +110,11 @@ namespace dxvk {
109110
*ppvObject = ref(this);
110111
return S_OK;
111112
}
113+
114+
if (riid == __uuidof(D3D9Bridge)) {
115+
*ppvObject = ref(&m_bridge);
116+
return S_OK;
117+
}
112118

113119
// We want to ignore this if the extended device is queried and we weren't made extended.
114120
if (riid == __uuidof(IDirect3DDevice9Ex))

src/d3d9/d3d9_device.h

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include "d3d9_shader_permutations.h"
2727

28+
#include "d3d9_bridge.h"
29+
2830
#include <vector>
2931
#include <type_traits>
3032
#include <unordered_map>
@@ -101,6 +103,7 @@ namespace dxvk {
101103
constexpr static uint32_t NullStreamIdx = caps::MaxStreams;
102104

103105
friend class D3D9SwapChainEx;
106+
friend class D3D9Bridge;
104107
public:
105108

106109
D3D9DeviceEx(
@@ -943,6 +946,8 @@ namespace dxvk {
943946
D3D9FFShaderModuleSet m_ffModules;
944947
D3D9SWVPEmulator m_swvpEmulator;
945948

949+
D3D9Bridge m_bridge;
950+
946951
DxvkCsChunkRef AllocCsChunk() {
947952
DxvkCsChunk* chunk = m_csChunkPool.allocChunk(DxvkCsChunkFlag::SingleUse);
948953
return DxvkCsChunkRef(chunk, &m_csChunkPool);

src/d3d9/d3d9_swapchain.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -1062,9 +1062,13 @@ namespace dxvk {
10621062
void D3D9SwapChainEx::SyncFrameLatency() {
10631063
// Wait for the sync event so that we respect the maximum frame latency
10641064
m_frameLatencySignal->wait(m_frameId - GetActualFrameLatency());
1065+
}
1066+
1067+
void D3D9SwapChainEx::SetApiName(const char* name) {
1068+
m_apiName = name;
1069+
CreateHud();
10651070
}
10661071

1067-
10681072
uint32_t D3D9SwapChainEx::GetActualFrameLatency() {
10691073
uint32_t maxFrameLatency = m_parent->GetFrameLatency();
10701074

@@ -1336,7 +1340,11 @@ namespace dxvk {
13361340

13371341

13381342
std::string D3D9SwapChainEx::GetApiName() {
1339-
return this->GetParent()->IsExtended() ? "D3D9Ex" : "D3D9";
1343+
if (m_apiName == nullptr) {
1344+
return this->GetParent()->IsExtended() ? "D3D9Ex" : "D3D9";
1345+
} else {
1346+
return m_apiName;
1347+
}
13401348
}
13411349

13421350
}

src/d3d9/d3d9_swapchain.h

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ namespace dxvk {
7878

7979
void SyncFrameLatency();
8080

81+
void SetApiName(const char* name);
82+
8183
private:
8284

8385
enum BindingIds : uint32_t {
@@ -130,6 +132,8 @@ namespace dxvk {
130132

131133
double m_displayRefreshRate = 0.0;
132134

135+
const char* m_apiName = nullptr;
136+
133137
void PresentImage(UINT PresentInterval);
134138

135139
void SubmitPresent(const vk::PresenterSync& Sync, uint32_t FrameId);

src/d3d9/meson.build

+11-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ d3d9_src = [
3838
'd3d9_names.cpp',
3939
'd3d9_swvp_emu.cpp',
4040
'd3d9_format_helpers.cpp',
41-
'd3d9_hud.cpp'
41+
'd3d9_hud.cpp',
42+
'd3d9_bridge.cpp'
4243
]
4344

4445
d3d9_dll = shared_library('d3d9'+dll_ext, d3d9_src, glsl_generator.process(d3d9_shaders), d3d9_res,
@@ -52,3 +53,12 @@ d3d9_dll = shared_library('d3d9'+dll_ext, d3d9_src, glsl_generator.process(d3d9_
5253
d3d9_dep = declare_dependency(
5354
link_with : [ d3d9_dll ],
5455
include_directories : [ dxvk_include_path ])
56+
57+
58+
d3d9_lib = static_library('d3d9_static', d3d9_src, glsl_generator.process(d3d9_shaders), d3d9_res,
59+
include_directories : [ dxvk_include_path ],
60+
override_options : ['cpp_std='+dxvk_cpp_std])
61+
62+
d3d9_lib_dep = declare_dependency(
63+
link_with : [ d3d9_lib ],
64+
include_directories : [ dxvk_include_path ])

0 commit comments

Comments
 (0)