Skip to content

Commit

Permalink
[d3d8] Add D3D9 bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
AlpyneDreams committed Jul 26, 2021
1 parent 4b2a5e4 commit cc37fb3
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/d3d8/d3d8_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ namespace dxvk {
, m_window(hFocusWindow)
, m_behaviorFlags(BehaviorFlags) {

// Get the bridge interface to D3D9.
if (FAILED(GetD3D9()->QueryInterface(__uuidof(D3D9Bridge), (void**)&m_bridge))) {
throw DxvkError("D3D8DeviceEx: ERROR! Failed to get D3D9 Bridge. d3d9.dll might not be DXVK!");
}

m_bridge->SetD3D8Mode();

m_textures.fill(nullptr);

}
Expand Down
4 changes: 4 additions & 0 deletions src/d3d8/d3d8_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "d3d8_d3d9_util.h"
#include "d3d8_caps.h"

#include "../d3d9/d3d9_bridge.h"

#include <array>
#include <vector>
#include <type_traits>
Expand Down Expand Up @@ -819,6 +821,8 @@ namespace dxvk {

private:

D3D9Bridge* m_bridge;

Com<D3D8InterfaceEx> m_parent;

D3D8StateBlock* m_recorder = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/d3d8/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ d3d8_src = [

d3d8_dll = shared_library('d3d8'+dll_ext, d3d8_src, d3d8_res,
name_prefix : '',
dependencies : [ d3d9_dep, util_dep ],
dependencies : [ d3d9_dep, d3d9_lib_dep, util_dep, dxso_dep, dxvk_dep ],
include_directories : dxvk_include_path,
install : true,
objects : not dxvk_is_msvc ? 'd3d8'+def_spec_ext : [],
Expand Down
20 changes: 20 additions & 0 deletions src/d3d9/d3d9_bridge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#include "d3d9_bridge.h"
#include "d3d9_device.h"
#include "d3d9_swapchain.h"

namespace dxvk {

ULONG D3D9Bridge::AddRef() {
return m_device->AddRef();
}

ULONG D3D9Bridge::Release() {
return m_device->Release();
}

void D3D9Bridge::SetD3D8Mode() {
m_device->m_implicitSwapchain->SetApiName("D3D8");
}

}
27 changes: 27 additions & 0 deletions src/d3d9/d3d9_bridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <windows.h>


namespace dxvk {

class D3D9DeviceEx;

class DECLSPEC_UUID("D3D9ACAB-42A9-4C1E-AA97-DEADFADED420") D3D9Bridge;

class D3D9Bridge {


public:
D3D9Bridge(D3D9DeviceEx* pDevice) : m_device(pDevice) {}

ULONG AddRef();
ULONG Release();

void SetD3D8Mode();

private:
D3D9DeviceEx* m_device;
};

}
8 changes: 7 additions & 1 deletion src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ namespace dxvk {
, m_multithread ( BehaviorFlags & D3DCREATE_MULTITHREADED )
, m_shaderModules ( new D3D9ShaderModuleSet )
, m_d3d9Options ( dxvkDevice, pParent->GetInstance()->config() )
, m_isSWVP ( (BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING) ? TRUE : FALSE ) {
, m_isSWVP ( (BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING) ? TRUE : FALSE )
, m_bridge ( this ) {
// If we can SWVP, then we use an extended constant set
// as SWVP has many more slots available than HWVP.
bool canSWVP = CanSWVP();
Expand Down Expand Up @@ -109,6 +110,11 @@ namespace dxvk {
*ppvObject = ref(this);
return S_OK;
}

if (riid == __uuidof(D3D9Bridge)) {
*ppvObject = ref(&m_bridge);
return S_OK;
}

// We want to ignore this if the extended device is queried and we weren't made extended.
if (riid == __uuidof(IDirect3DDevice9Ex))
Expand Down
5 changes: 5 additions & 0 deletions src/d3d9/d3d9_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include "d3d9_shader_permutations.h"

#include "d3d9_bridge.h"

#include <vector>
#include <type_traits>
#include <unordered_map>
Expand Down Expand Up @@ -101,6 +103,7 @@ namespace dxvk {
constexpr static uint32_t NullStreamIdx = caps::MaxStreams;

friend class D3D9SwapChainEx;
friend class D3D9Bridge;
public:

D3D9DeviceEx(
Expand Down Expand Up @@ -943,6 +946,8 @@ namespace dxvk {
D3D9FFShaderModuleSet m_ffModules;
D3D9SWVPEmulator m_swvpEmulator;

D3D9Bridge m_bridge;

DxvkCsChunkRef AllocCsChunk() {
DxvkCsChunk* chunk = m_csChunkPool.allocChunk(DxvkCsChunkFlag::SingleUse);
return DxvkCsChunkRef(chunk, &m_csChunkPool);
Expand Down
12 changes: 10 additions & 2 deletions src/d3d9/d3d9_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,9 +1062,13 @@ namespace dxvk {
void D3D9SwapChainEx::SyncFrameLatency() {
// Wait for the sync event so that we respect the maximum frame latency
m_frameLatencySignal->wait(m_frameId - GetActualFrameLatency());
}

void D3D9SwapChainEx::SetApiName(const char* name) {
m_apiName = name;
CreateHud();
}


uint32_t D3D9SwapChainEx::GetActualFrameLatency() {
uint32_t maxFrameLatency = m_parent->GetFrameLatency();

Expand Down Expand Up @@ -1336,7 +1340,11 @@ namespace dxvk {


std::string D3D9SwapChainEx::GetApiName() {
return this->GetParent()->IsExtended() ? "D3D9Ex" : "D3D9";
if (m_apiName == nullptr) {
return this->GetParent()->IsExtended() ? "D3D9Ex" : "D3D9";
} else {
return m_apiName;
}
}

}
4 changes: 4 additions & 0 deletions src/d3d9/d3d9_swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ namespace dxvk {

void SyncFrameLatency();

void SetApiName(const char* name);

private:

enum BindingIds : uint32_t {
Expand Down Expand Up @@ -130,6 +132,8 @@ namespace dxvk {

double m_displayRefreshRate = 0.0;

const char* m_apiName = nullptr;

void PresentImage(UINT PresentInterval);

void SubmitPresent(const vk::PresenterSync& Sync, uint32_t FrameId);
Expand Down
12 changes: 11 additions & 1 deletion src/d3d9/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ d3d9_src = [
'd3d9_names.cpp',
'd3d9_swvp_emu.cpp',
'd3d9_format_helpers.cpp',
'd3d9_hud.cpp'
'd3d9_hud.cpp',
'd3d9_bridge.cpp'
]

d3d9_dll = shared_library('d3d9'+dll_ext, d3d9_src, glsl_generator.process(d3d9_shaders), d3d9_res,
Expand All @@ -52,3 +53,12 @@ d3d9_dll = shared_library('d3d9'+dll_ext, d3d9_src, glsl_generator.process(d3d9_
d3d9_dep = declare_dependency(
link_with : [ d3d9_dll ],
include_directories : [ dxvk_include_path ])


d3d9_lib = static_library('d3d9_static', d3d9_src, glsl_generator.process(d3d9_shaders), d3d9_res,
include_directories : [ dxvk_include_path ],
override_options : ['cpp_std='+dxvk_cpp_std])

d3d9_lib_dep = declare_dependency(
link_with : [ d3d9_lib ],
include_directories : [ dxvk_include_path ])

0 comments on commit cc37fb3

Please sign in to comment.