Serialise ID3D11Interface * pointers directly, with internal ID conv

* The serialise function handles fetching the ID on write, and looking
  up the resource manager to fetch the handle on read.
* This allows us to do nice things like:
  Serialise_SetConstBufs(SerialiserType &ser, UINT NumBuffers,
      ID3D11Buffer *const *ppConstantBuffers)
  {
    SERIALISE_ELEMENT_ARRAY(ppConstantBuffers, NumBuffers);
    // ...
  }
  And the array handling and serialise recursion will correctly iterate
  and serialise the array as a series of ResourceIds, then restore it
  as a series of handles.
This commit is contained in:
baldurk
2017-09-28 19:22:18 +01:00
parent aafdc88fd2
commit da441b675c
2 changed files with 71 additions and 0 deletions
+36
View File
@@ -391,6 +391,42 @@ enum class D3D11Chunk : uint32_t
DECLARE_REFLECTION_ENUM(D3D11Chunk);
// this is special - these serialise overloads will fetch the ID during capture, serialise the ID
// directly as-if it were the original type, then on replay load up the resource if available.
// Really this is only one type of serialisation, but we declare a couple of overloads to account
// for resources being accessed through different interfaces in different functions
#define SERIALISE_D3D_INTERFACES() \
SERIALISE_INTERFACE(ID3D11DeviceChild); \
SERIALISE_INTERFACE(ID3D11Resource); \
SERIALISE_INTERFACE(ID3D11View); \
SERIALISE_INTERFACE(ID3D11UnorderedAccessView); \
SERIALISE_INTERFACE(ID3D11ShaderResourceView); \
SERIALISE_INTERFACE(ID3D11RenderTargetView); \
SERIALISE_INTERFACE(ID3D11DepthStencilView); \
SERIALISE_INTERFACE(ID3D11BlendState); \
SERIALISE_INTERFACE(ID3D11DepthStencilState); \
SERIALISE_INTERFACE(ID3D11RasterizerState); \
SERIALISE_INTERFACE(ID3D11SamplerState); \
SERIALISE_INTERFACE(ID3D11Buffer); \
SERIALISE_INTERFACE(ID3D11ClassInstance); \
SERIALISE_INTERFACE(ID3D11ClassLinkage); \
SERIALISE_INTERFACE(ID3D11InputLayout); \
SERIALISE_INTERFACE(ID3D11VertexShader); \
SERIALISE_INTERFACE(ID3D11HullShader); \
SERIALISE_INTERFACE(ID3D11DomainShader); \
SERIALISE_INTERFACE(ID3D11GeometryShader); \
SERIALISE_INTERFACE(ID3D11PixelShader); \
SERIALISE_INTERFACE(ID3D11ComputeShader); \
SERIALISE_INTERFACE(ID3D11CommandList); \
SERIALISE_INTERFACE(ID3D11Counter); \
SERIALISE_INTERFACE(ID3D11Predicate); \
SERIALISE_INTERFACE(ID3D11Query); \
SERIALISE_INTERFACE(ID3D11Asynchronous);
#define SERIALISE_INTERFACE(iface) DECLARE_REFLECTION_STRUCT(iface *)
SERIALISE_D3D_INTERFACES();
DECLARE_REFLECTION_ENUM(D3D11_BIND_FLAG);
DECLARE_REFLECTION_ENUM(D3D11_CPU_ACCESS_FLAG);
DECLARE_REFLECTION_ENUM(D3D11_RESOURCE_MISC_FLAG);
@@ -25,6 +25,41 @@
#include "common/common.h"
#include "serialise/serialiser.h"
#include "d3d11_common.h"
#include "d3d11_manager.h"
#include "d3d11_resources.h"
// serialisation of object handles via IDs.
template <class SerialiserType, class Interface>
void DoSerialiseViaResourceId(SerialiserType &ser, Interface *&el)
{
D3D11ResourceManager *rm = (D3D11ResourceManager *)ser.GetUserData();
ResourceId id;
if(ser.IsWriting() && rm)
id = GetIDForResource(el);
DoSerialise(ser, id);
if(ser.IsReading())
{
if(id != ResourceId() && rm && rm->HasLiveResource(id))
el = (Interface *)rm->GetLiveResource(id);
else
el = NULL;
}
}
#undef SERIALISE_INTERFACE
#define SERIALISE_INTERFACE(iface) \
template <class SerialiserType> \
void DoSerialise(SerialiserType &ser, iface *&el) \
{ \
DoSerialiseViaResourceId(ser, el); \
} \
INSTANTIATE_SERIALISE_TYPE(iface *);
SERIALISE_D3D_INTERFACES();
template <class SerialiserType>
void DoSerialise(SerialiserType &ser, D3D11_BUFFER_DESC &el)