[d3d11] Introduce D3D11CommonContext

This commit is contained in:
Philip Rebohle 2022-08-03 16:33:54 +02:00
parent 0315997fcd
commit e4204f76e6
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
7 changed files with 108 additions and 10 deletions

View File

@ -0,0 +1,26 @@
#include "d3d11_context_common.h"
#include "d3d11_context_def.h"
#include "d3d11_context_imm.h"
namespace dxvk {
template<typename ContextType>
D3D11CommonContext<ContextType>::D3D11CommonContext(
D3D11Device* pParent,
const Rc<DxvkDevice>& Device,
DxvkCsChunkFlags CsFlags)
: D3D11DeviceContext(pParent, Device, CsFlags) {
}
template<typename ContextType>
D3D11CommonContext<ContextType>::~D3D11CommonContext() {
}
// Explicitly instantiate here
template class D3D11CommonContext<D3D11DeferredContext>;
template class D3D11CommonContext<D3D11ImmediateContext>;
}

View File

@ -0,0 +1,71 @@
#pragma once
#include <type_traits>
#include <vector>
#include "d3d11_buffer.h"
#include "d3d11_context.h"
#include "d3d11_texture.h"
namespace dxvk {
class D3D11DeferredContext;
class D3D11ImmediateContext;
template<bool IsDeferred>
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<false> {
template<typename T>
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<true> {
template<typename T>
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<typename ContextType>
class D3D11CommonContext : public D3D11DeviceContext {
constexpr static bool IsDeferred = std::is_same_v<ContextType, D3D11DeferredContext>;
using Forwarder = D3D11ContextObjectForwarder<IsDeferred>;
public:
D3D11CommonContext(
D3D11Device* pParent,
const Rc<DxvkDevice>& Device,
DxvkCsChunkFlags CsFlags);
~D3D11CommonContext();
};
}

View File

@ -7,7 +7,7 @@ namespace dxvk {
D3D11Device* pParent,
const Rc<DxvkDevice>& Device,
UINT ContextFlags)
: D3D11DeviceContext(pParent, Device, GetCsChunkFlags(pParent)),
: D3D11CommonContext<D3D11DeferredContext>(pParent, Device, GetCsChunkFlags(pParent)),
m_contextFlags(ContextFlags),
m_commandList (CreateCommandList()) {
ClearState();

View File

@ -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 <vector>
@ -23,8 +21,9 @@ namespace dxvk {
D3D11_MAPPED_SUBRESOURCE MapInfo;
};
class D3D11DeferredContext : public D3D11DeviceContext {
friend class D3D11DeviceContext;
class D3D11DeferredContext : public D3D11CommonContext<D3D11DeferredContext> {
template<typename T>
friend class D3D11CommonContext;
public:
D3D11DeferredContext(

View File

@ -13,7 +13,7 @@ namespace dxvk {
D3D11ImmediateContext::D3D11ImmediateContext(
D3D11Device* pParent,
const Rc<DxvkDevice>& Device)
: D3D11DeviceContext(pParent, Device, DxvkCsChunkFlag::SingleUse),
: D3D11CommonContext<D3D11ImmediateContext>(pParent, Device, DxvkCsChunkFlag::SingleUse),
m_csThread(Device, Device->createContext(DxvkContextType::Primary)),
m_maxImplicitDiscardSize(pParent->GetOptions()->maxImplicitDiscardSize),
m_videoContext(this, Device) {

View File

@ -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<D3D11ImmediateContext> {
template<typename T>
friend class D3D11CommonContext;
friend class D3D11SwapChain;
friend class D3D11VideoContext;
friend class D3D11DeviceContext;
public:
D3D11ImmediateContext(

View File

@ -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',