From da441b675cf3819466a1a3664072b748ab9bc37c Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 28 Sep 2017 19:22:18 +0100 Subject: [PATCH] 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. --- renderdoc/driver/d3d11/d3d11_common.h | 36 ++++++++++++++++++++++ renderdoc/driver/d3d11/d3d11_serialise.cpp | 35 +++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/renderdoc/driver/d3d11/d3d11_common.h b/renderdoc/driver/d3d11/d3d11_common.h index f89894ad5..3ace43d9b 100644 --- a/renderdoc/driver/d3d11/d3d11_common.h +++ b/renderdoc/driver/d3d11/d3d11_common.h @@ -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); diff --git a/renderdoc/driver/d3d11/d3d11_serialise.cpp b/renderdoc/driver/d3d11/d3d11_serialise.cpp index c24be88bc..8ab65cd31 100644 --- a/renderdoc/driver/d3d11/d3d11_serialise.cpp +++ b/renderdoc/driver/d3d11/d3d11_serialise.cpp @@ -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 +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 \ + void DoSerialise(SerialiserType &ser, iface *&el) \ + { \ + DoSerialiseViaResourceId(ser, el); \ + } \ + INSTANTIATE_SERIALISE_TYPE(iface *); + +SERIALISE_D3D_INTERFACES(); template void DoSerialise(SerialiserType &ser, D3D11_BUFFER_DESC &el)