mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-15 07:29:17 +01:00
[d3d11] Introduce D3D11CommonContext
This commit is contained in:
parent
0315997fcd
commit
e4204f76e6
26
src/d3d11/d3d11_context_common.cpp
Normal file
26
src/d3d11/d3d11_context_common.cpp
Normal 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>;
|
||||
|
||||
}
|
71
src/d3d11/d3d11_context_common.h
Normal file
71
src/d3d11/d3d11_context_common.h
Normal 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();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -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();
|
||||
|
@ -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(
|
||||
|
@ -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) {
|
||||
|
@ -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(
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user