From e4204f76e68825585c75d2acf3a5213ba613de9d Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 3 Aug 2022 16:33:54 +0200 Subject: [PATCH] [d3d11] Introduce D3D11CommonContext --- src/d3d11/d3d11_context_common.cpp | 26 +++++++++++ src/d3d11/d3d11_context_common.h | 71 ++++++++++++++++++++++++++++++ src/d3d11/d3d11_context_def.cpp | 2 +- src/d3d11/d3d11_context_def.h | 9 ++-- src/d3d11/d3d11_context_imm.cpp | 2 +- src/d3d11/d3d11_context_imm.h | 7 +-- src/d3d11/meson.build | 1 + 7 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 src/d3d11/d3d11_context_common.cpp create mode 100644 src/d3d11/d3d11_context_common.h diff --git a/src/d3d11/d3d11_context_common.cpp b/src/d3d11/d3d11_context_common.cpp new file mode 100644 index 00000000..8b93c36f --- /dev/null +++ b/src/d3d11/d3d11_context_common.cpp @@ -0,0 +1,26 @@ +#include "d3d11_context_common.h" +#include "d3d11_context_def.h" +#include "d3d11_context_imm.h" + +namespace dxvk { + + template + D3D11CommonContext::D3D11CommonContext( + D3D11Device* pParent, + const Rc& Device, + DxvkCsChunkFlags CsFlags) + : D3D11DeviceContext(pParent, Device, CsFlags) { + + } + + + template + D3D11CommonContext::~D3D11CommonContext() { + + } + + // Explicitly instantiate here + template class D3D11CommonContext; + template class D3D11CommonContext; + +} diff --git a/src/d3d11/d3d11_context_common.h b/src/d3d11/d3d11_context_common.h new file mode 100644 index 00000000..bb4b295f --- /dev/null +++ b/src/d3d11/d3d11_context_common.h @@ -0,0 +1,71 @@ +#pragma once + +#include +#include + +#include "d3d11_buffer.h" +#include "d3d11_context.h" +#include "d3d11_texture.h" + +namespace dxvk { + + class D3D11DeferredContext; + class D3D11ImmediateContext; + + template + struct D3D11ContextObjectForwarder; + + /** + * \brief Object forwarder for immediate contexts + * + * Binding methods can use this to efficiently bind objects + * to the DXVK context without redundant reference counting. + */ + template<> + struct D3D11ContextObjectForwarder { + template + static T&& move(T& object) { + return std::move(object); + } + }; + + /** + * \brief Object forwarder for deferred contexts + * + * This forwarder will create a copy of the object passed + * into it, so that CS chunks can be reused if necessary. + */ + template<> + struct D3D11ContextObjectForwarder { + template + static T move(const T& object) { + return object; + } + }; + + /** + * \brief Common D3D11 device context implementation + * + * Implements all common device context methods, but since this is + * templates with the actual context type (deferred or immediate), + * all methods can call back into context-specific methods without + * having to use virtual methods. + */ + template + class D3D11CommonContext : public D3D11DeviceContext { + constexpr static bool IsDeferred = std::is_same_v; + using Forwarder = D3D11ContextObjectForwarder; + public: + + D3D11CommonContext( + D3D11Device* pParent, + const Rc& Device, + DxvkCsChunkFlags CsFlags); + + ~D3D11CommonContext(); + + + + }; + +} diff --git a/src/d3d11/d3d11_context_def.cpp b/src/d3d11/d3d11_context_def.cpp index 57695bf2..1304236e 100644 --- a/src/d3d11/d3d11_context_def.cpp +++ b/src/d3d11/d3d11_context_def.cpp @@ -7,7 +7,7 @@ namespace dxvk { D3D11Device* pParent, const Rc& Device, UINT ContextFlags) - : D3D11DeviceContext(pParent, Device, GetCsChunkFlags(pParent)), + : D3D11CommonContext(pParent, Device, GetCsChunkFlags(pParent)), m_contextFlags(ContextFlags), m_commandList (CreateCommandList()) { ClearState(); diff --git a/src/d3d11/d3d11_context_def.h b/src/d3d11/d3d11_context_def.h index c5fe49c9..bda8725c 100644 --- a/src/d3d11/d3d11_context_def.h +++ b/src/d3d11/d3d11_context_def.h @@ -1,9 +1,7 @@ #pragma once -#include "d3d11_buffer.h" #include "d3d11_cmdlist.h" -#include "d3d11_context.h" -#include "d3d11_texture.h" +#include "d3d11_context_common.h" #include @@ -23,8 +21,9 @@ namespace dxvk { D3D11_MAPPED_SUBRESOURCE MapInfo; }; - class D3D11DeferredContext : public D3D11DeviceContext { - friend class D3D11DeviceContext; + class D3D11DeferredContext : public D3D11CommonContext { + template + friend class D3D11CommonContext; public: D3D11DeferredContext( diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index cbbc2d1e..de04b9ef 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -13,7 +13,7 @@ namespace dxvk { D3D11ImmediateContext::D3D11ImmediateContext( D3D11Device* pParent, const Rc& Device) - : D3D11DeviceContext(pParent, Device, DxvkCsChunkFlag::SingleUse), + : D3D11CommonContext(pParent, Device, DxvkCsChunkFlag::SingleUse), m_csThread(Device, Device->createContext(DxvkContextType::Primary)), m_maxImplicitDiscardSize(pParent->GetOptions()->maxImplicitDiscardSize), m_videoContext(this, Device) { diff --git a/src/d3d11/d3d11_context_imm.h b/src/d3d11/d3d11_context_imm.h index 6bc1e6da..2356fd50 100644 --- a/src/d3d11/d3d11_context_imm.h +++ b/src/d3d11/d3d11_context_imm.h @@ -4,7 +4,7 @@ #include "../util/sync/sync_signal.h" -#include "d3d11_context.h" +#include "d3d11_context_common.h" #include "d3d11_state_object.h" #include "d3d11_video.h" @@ -13,10 +13,11 @@ namespace dxvk { class D3D11Buffer; class D3D11CommonTexture; - class D3D11ImmediateContext : public D3D11DeviceContext { + class D3D11ImmediateContext : public D3D11CommonContext { + template + friend class D3D11CommonContext; friend class D3D11SwapChain; friend class D3D11VideoContext; - friend class D3D11DeviceContext; public: D3D11ImmediateContext( diff --git a/src/d3d11/meson.build b/src/d3d11/meson.build index 85fe7807..4600a5a5 100644 --- a/src/d3d11/meson.build +++ b/src/d3d11/meson.build @@ -30,6 +30,7 @@ d3d11_src = [ 'd3d11_class_linkage.cpp', 'd3d11_cmdlist.cpp', 'd3d11_context.cpp', + 'd3d11_context_common.cpp', 'd3d11_context_def.cpp', 'd3d11_context_ext.cpp', 'd3d11_context_imm.cpp',