From 81a4e718cb07eb74354431c37de788b19830db3b Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 27 Sep 2017 18:43:28 +0100 Subject: [PATCH] Update non-wrapping D3D11 device code --- renderdoc/driver/d3d11/d3d11_common.h | 7 +- renderdoc/driver/d3d11/d3d11_device.cpp | 643 +++++++++++++----------- renderdoc/driver/d3d11/d3d11_device.h | 410 +++++++-------- 3 files changed, 536 insertions(+), 524 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_common.h b/renderdoc/driver/d3d11/d3d11_common.h index 3ace43d9b..d3c9ba28e 100644 --- a/renderdoc/driver/d3d11/d3d11_common.h +++ b/renderdoc/driver/d3d11/d3d11_common.h @@ -242,9 +242,10 @@ public: #define IMPLEMENT_IUNKNOWN_WITH_REFCOUNTER_CUSTOMQUERY \ ULONG STDMETHODCALLTYPE AddRef() { return RefCounter::AddRef(); } \ ULONG STDMETHODCALLTYPE Release() { return RefCounter::Release(); } -#define IMPLEMENT_FUNCTION_SERIALISED(ret, func) \ - ret func; \ - bool CONCAT(Serialise_, func); +#define IMPLEMENT_FUNCTION_SERIALISED(ret, func, ...) \ + ret func(__VA_ARGS__); \ + template \ + bool CONCAT(Serialise_, func(SerialiserType &ser, __VA_ARGS__)); // A handy macros to say "is the serialiser reading and we're doing replay-mode stuff?" // The reason we check both is that checking the first allows the compiler to eliminate the other diff --git a/renderdoc/driver/d3d11/d3d11_device.cpp b/renderdoc/driver/d3d11/d3d11_device.cpp index 24db2eb55..d40eb6777 100644 --- a/renderdoc/driver/d3d11/d3d11_device.cpp +++ b/renderdoc/driver/d3d11/d3d11_device.cpp @@ -31,6 +31,7 @@ #include "driver/dxgi/dxgi_wrapped.h" #include "jpeg-compressor/jpge.h" #include "maths/formatpacking.h" +#include "serialise/rdcfile.h" #include "strings/string_utils.h" WRAPPED_POOL_INST(WrappedID3D11Device); @@ -49,30 +50,24 @@ void WrappedID3D11Device::NewSwapchainBuffer(IUnknown *backbuffer) } } -void WrappedID3D11Device::SetLogFile(const char *logfile) -{ -#if ENABLED(RDOC_RELEASE) - const bool debugSerialiser = false; -#else - const bool debugSerialiser = true; -#endif - - m_pSerialiser = new Serialiser(logfile, Serialiser::READING, debugSerialiser); - m_pSerialiser->SetChunkNameLookup(&GetChunkName); - m_pImmediateContext->SetSerialiser(m_pSerialiser); - - SAFE_DELETE(m_ResourceManager); - m_ResourceManager = new D3D11ResourceManager(m_State, m_pSerialiser, this); -} - WrappedID3D11Device::WrappedID3D11Device(ID3D11Device *realDevice, D3D11InitParams *params) - : m_RefCounter(realDevice, false), m_SoftRefCounter(NULL, false), m_pDevice(realDevice) + : m_RefCounter(realDevice, false), + m_SoftRefCounter(NULL, false), + m_pDevice(realDevice), + m_ScratchSerialiser(new StreamWriter(1024), Ownership::Stream) { if(RenderDoc::Inst().GetCrashHandler()) RenderDoc::Inst().GetCrashHandler()->RegisterMemoryRegion(this, sizeof(WrappedID3D11Device)); m_SectionVersion = D3D11InitParams::CurrentVersion; + uint32_t flags = 0; + + if(RenderDoc::Inst().GetCaptureOptions().CaptureCallstacks) + flags |= WriteSerialiser::ChunkCallstack; + + m_ScratchSerialiser.SetChunkMetadataRecording(flags); + m_pDevice1 = NULL; m_pDevice->QueryInterface(__uuidof(ID3D11Device1), (void **)&m_pDevice1); @@ -117,8 +112,7 @@ WrappedID3D11Device::WrappedID3D11Device(ID3D11Device *realDevice, D3D11InitPara if(RenderDoc::Inst().IsReplayApp()) { - m_State = READING; - m_pSerialiser = NULL; + m_State = CaptureState::LoadingReplaying; D3D11MarkerRegion::device = this; @@ -129,16 +123,12 @@ WrappedID3D11Device::WrappedID3D11Device(ID3D11Device *realDevice, D3D11InitPara } else { - m_State = WRITING_IDLE; - m_pSerialiser = new Serialiser(NULL, Serialiser::WRITING, debugSerialiser); - - m_pSerialiser->SetDebugText(true); + m_State = CaptureState::BackgroundCapturing; } - m_ResourceManager = new D3D11ResourceManager(m_State, m_pSerialiser, this); + m_ResourceManager = new D3D11ResourceManager(this); - if(m_pSerialiser) - m_pSerialiser->SetChunkNameLookup(&GetChunkName); + m_ScratchSerialiser.SetUserData(GetResourceManager()); // create a temporary and grab its resource ID m_ResourceID = ResourceIDGen::GetNewUniqueID(); @@ -160,7 +150,7 @@ WrappedID3D11Device::WrappedID3D11Device(ID3D11Device *realDevice, D3D11InitPara ID3D11DeviceContext *context = NULL; realDevice->GetImmediateContext(&context); - m_pImmediateContext = new WrappedID3D11DeviceContext(this, context, m_pSerialiser); + m_pImmediateContext = new WrappedID3D11DeviceContext(this, context); realDevice->QueryInterface(__uuidof(ID3D11InfoQueue), (void **)&m_pInfoQueue); realDevice->QueryInterface(__uuidof(ID3D11Debug), (void **)&m_WrappedDebug.m_pDebug); @@ -273,8 +263,6 @@ WrappedID3D11Device::~WrappedID3D11Device() SAFE_RELEASE(m_WrappedDebug.m_pDebug); SAFE_RELEASE(m_pDevice); - SAFE_DELETE(m_pSerialiser); - RDCASSERT(WrappedID3D11Buffer::m_BufferList.empty()); RDCASSERT(WrappedID3D11Texture1D::m_TextureList.empty()); RDCASSERT(WrappedID3D11Texture2D1::m_TextureList.empty()); @@ -293,7 +281,8 @@ void WrappedID3D11Device::CheckForDeath() { RDCASSERT(m_SoftRefCounter.GetRefCount() >= m_InternalRefcount); - if(m_SoftRefCounter.GetRefCount() <= m_InternalRefcount || m_State < WRITING) // MEGA HACK + // MEGA HACK + if(m_SoftRefCounter.GetRefCount() <= m_InternalRefcount || IsReplayMode(m_State)) { m_Alive = false; delete this; @@ -352,8 +341,7 @@ HRESULT STDMETHODCALLTYPE WrappedID3D11Debug::QueryInterface(REFIID riid, void * return S_OK; } - string guid = ToStr(riid); - RDCWARN("Querying ID3D11Debug for interface: %s", guid.c_str()); + RDCWARN("Querying ID3D11Debug for interface: %s", ToStr(riid).c_str()); return m_pDebug->QueryInterface(riid, ppvObject); } @@ -612,19 +600,18 @@ HRESULT WrappedID3D11Device::QueryInterface(REFIID riid, void **ppvObject) } else { - string guid = ToStr(riid); - RDCWARN("Querying ID3D11Device for interface: %s", guid.c_str()); + RDCWARN("Querying ID3D11Device for interface: %s", ToStr(riid).c_str()); } return m_RefCounter.QueryInterface(riid, ppvObject); } -const char *WrappedID3D11Device::GetChunkName(uint32_t idx) +std::string WrappedID3D11Device::GetChunkName(uint32_t idx) { if((SystemChunk)idx < SystemChunk::FirstDriverChunk) - return ::GetChunkName((SystemChunk)idx); + return ToStr((SystemChunk)idx); - return ::GetChunkName((D3D11Chunk)idx); + return ToStr((D3D11Chunk)idx); } void WrappedID3D11Device::LazyInit() @@ -639,10 +626,10 @@ void WrappedID3D11Device::AddDebugMessage(MessageCategory c, MessageSeverity sv, // Only add runtime warnings while executing. // While reading, add the messages from the log, and while writing add messages // we add (on top of the API debug messages) - if(m_State != EXECUTING || src == MessageSource::RuntimeWarning) + if(!IsActiveReplaying(m_State) || src == MessageSource::RuntimeWarning) { DebugMessage msg; - msg.eventID = m_State >= WRITING ? 0 : m_pImmediateContext->GetEventID(); + msg.eventID = IsCaptureMode(m_State) ? 0 : m_pImmediateContext->GetEventID(); msg.messageID = 0; msg.source = src; msg.category = c; @@ -655,20 +642,20 @@ void WrappedID3D11Device::AddDebugMessage(MessageCategory c, MessageSeverity sv, void WrappedID3D11Device::AddDebugMessage(DebugMessage msg) { - if(m_State != EXECUTING || msg.source == MessageSource::RuntimeWarning) + if(!IsActiveReplaying(m_State) || msg.source == MessageSource::RuntimeWarning) m_DebugMessages.push_back(msg); } -vector WrappedID3D11Device::GetDebugMessages() +std::vector WrappedID3D11Device::GetDebugMessages() { - vector ret; + std::vector ret; // if reading, m_DebugMessages will contain all the messages (we // don't try and fetch anything from the API). If writing, // m_DebugMessages will contain any manually-added messages. ret.swap(m_DebugMessages); - if(m_State < WRITING) + if(IsReplayMode(m_State)) return ret; if(!m_pInfoQueue) @@ -754,95 +741,133 @@ vector WrappedID3D11Device::GetDebugMessages() return ret; } -void WrappedID3D11Device::ProcessChunk(uint64_t offset, D3D11ChunkType context) +void WrappedID3D11Device::ProcessChunk(ReadSerialiser &ser, D3D11Chunk context) { switch(context) { - case DEVICE_INIT: + case D3D11Chunk::DeviceInitialisation: { - SERIALISE_ELEMENT(ResourceId, immContextId, ResourceId()); + SERIALISE_ELEMENT_LOCAL(ImmediateContext, ResourceId()); // add a reference for the resource manager - normally it takes ownership of the resource on // creation and releases it // to destruction, but we want to control our immediate context ourselves. m_pImmediateContext->AddRef(); - m_ResourceManager->AddLiveResource(immContextId, m_pImmediateContext); + m_ResourceManager->AddLiveResource(ImmediateContext, m_pImmediateContext); break; } - case SET_RESOURCE_NAME: Serialise_SetResourceName(0x0, ""); break; - case RELEASE_RESOURCE: Serialise_ReleaseResource(0x0); break; - case CREATE_SWAP_BUFFER: Serialise_WrapSwapchainBuffer(0x0, 0x0, 0, 0x0); break; - case CREATE_TEXTURE_1D: Serialise_CreateTexture1D(0x0, 0x0, 0x0); break; - case CREATE_TEXTURE_2D: Serialise_CreateTexture2D(0x0, 0x0, 0x0); break; - case CREATE_TEXTURE_2D1: Serialise_CreateTexture2D1(0x0, 0x0, 0x0); break; - case CREATE_TEXTURE_3D: Serialise_CreateTexture3D(0x0, 0x0, 0x0); break; - case CREATE_TEXTURE_3D1: Serialise_CreateTexture3D1(0x0, 0x0, 0x0); break; - case CREATE_BUFFER: Serialise_CreateBuffer(0x0, 0x0, 0x0); break; - case CREATE_VERTEX_SHADER: Serialise_CreateVertexShader(0x0, 0, 0x0, 0x0); break; - case CREATE_HULL_SHADER: Serialise_CreateHullShader(0x0, 0, 0x0, 0x0); break; - case CREATE_DOMAIN_SHADER: Serialise_CreateDomainShader(0x0, 0, 0x0, 0x0); break; - case CREATE_GEOMETRY_SHADER: Serialise_CreateGeometryShader(0x0, 0, 0x0, 0x0); break; - case CREATE_GEOMETRY_SHADER_WITH_SO: - Serialise_CreateGeometryShaderWithStreamOutput(0x0, 0, 0x0, 0, 0x0, 0, 0, 0x0, 0x0); + case D3D11Chunk::SetResourceName: Serialise_SetResourceName(ser, 0x0, ""); break; + case D3D11Chunk::ReleaseResource: Serialise_ReleaseResource(ser, 0x0); break; + case D3D11Chunk::CreateSwapBuffer: Serialise_WrapSwapchainBuffer(ser, 0x0, 0x0, 0, 0x0); break; + case D3D11Chunk::CreateTexture1D: Serialise_CreateTexture1D(ser, 0x0, 0x0, 0x0); break; + case D3D11Chunk::CreateTexture2D: Serialise_CreateTexture2D(ser, 0x0, 0x0, 0x0); break; + case D3D11Chunk::CreateTexture2D1: Serialise_CreateTexture2D1(ser, 0x0, 0x0, 0x0); break; + case D3D11Chunk::CreateTexture3D: Serialise_CreateTexture3D(ser, 0x0, 0x0, 0x0); break; + case D3D11Chunk::CreateTexture3D1: Serialise_CreateTexture3D1(ser, 0x0, 0x0, 0x0); break; + case D3D11Chunk::CreateBuffer: Serialise_CreateBuffer(ser, 0x0, 0x0, 0x0); break; + case D3D11Chunk::CreateVertexShader: Serialise_CreateVertexShader(ser, 0x0, 0, 0x0, 0x0); break; + case D3D11Chunk::CreateHullShader: Serialise_CreateHullShader(ser, 0x0, 0, 0x0, 0x0); break; + case D3D11Chunk::CreateDomainShader: Serialise_CreateDomainShader(ser, 0x0, 0, 0x0, 0x0); break; + case D3D11Chunk::CreateGeometryShader: + Serialise_CreateGeometryShader(ser, 0x0, 0, 0x0, 0x0); break; - case CREATE_PIXEL_SHADER: Serialise_CreatePixelShader(0x0, 0, 0x0, 0x0); break; - case CREATE_COMPUTE_SHADER: Serialise_CreateComputeShader(0x0, 0, 0x0, 0x0); break; - case GET_CLASS_INSTANCE: Serialise_GetClassInstance(0x0, 0, 0x0, 0x0); break; - case CREATE_CLASS_INSTANCE: Serialise_CreateClassInstance(0x0, 0, 0, 0, 0, 0x0, 0x0); break; - case CREATE_CLASS_LINKAGE: Serialise_CreateClassLinkage(0x0); break; - case CREATE_SRV: Serialise_CreateShaderResourceView(0x0, 0x0, 0x0); break; - case CREATE_SRV1: Serialise_CreateShaderResourceView1(0x0, 0x0, 0x0); break; - case CREATE_RTV: Serialise_CreateRenderTargetView(0x0, 0x0, 0x0); break; - case CREATE_RTV1: Serialise_CreateRenderTargetView1(0x0, 0x0, 0x0); break; - case CREATE_DSV: Serialise_CreateDepthStencilView(0x0, 0x0, 0x0); break; - case CREATE_UAV: Serialise_CreateUnorderedAccessView(0x0, 0x0, 0x0); break; - case CREATE_UAV1: Serialise_CreateUnorderedAccessView1(0x0, 0x0, 0x0); break; - case CREATE_INPUT_LAYOUT: Serialise_CreateInputLayout(0x0, 0, 0x0, 0, 0x0); break; - case CREATE_BLEND_STATE: Serialise_CreateBlendState(0x0, 0x0); break; - case CREATE_BLEND_STATE1: Serialise_CreateBlendState1(0x0, 0x0); break; - case CREATE_DEPTHSTENCIL_STATE: Serialise_CreateDepthStencilState(0x0, 0x0); break; - case CREATE_RASTER_STATE: Serialise_CreateRasterizerState(0x0, 0x0); break; - case CREATE_RASTER_STATE1: Serialise_CreateRasterizerState1(0x0, 0x0); break; - case CREATE_RASTER_STATE2: Serialise_CreateRasterizerState2(0x0, 0x0); break; - case CREATE_SAMPLER_STATE: Serialise_CreateSamplerState(0x0, 0x0); break; - case CREATE_QUERY: Serialise_CreateQuery(0x0, 0x0); break; - case CREATE_QUERY1: Serialise_CreateQuery1(0x0, 0x0); break; - case CREATE_PREDICATE: Serialise_CreatePredicate(0x0, 0x0); break; - case CREATE_COUNTER: Serialise_CreateCounter(0x0, 0x0); break; - case CREATE_DEFERRED_CONTEXT: Serialise_CreateDeferredContext(0, 0x0); break; - case SET_EXCEPTION_MODE: Serialise_SetExceptionMode(0); break; - case OPEN_SHARED_RESOURCE: + case D3D11Chunk::CreateGeometryShaderWithStreamOutput: + Serialise_CreateGeometryShaderWithStreamOutput(ser, 0x0, 0, 0x0, 0, 0x0, 0, 0, 0x0, 0x0); + break; + case D3D11Chunk::CreatePixelShader: Serialise_CreatePixelShader(ser, 0x0, 0, 0x0, 0x0); break; + case D3D11Chunk::CreateComputeShader: + Serialise_CreateComputeShader(ser, 0x0, 0, 0x0, 0x0); + break; + case D3D11Chunk::GetClassInstance: Serialise_GetClassInstance(ser, 0x0, 0, 0x0, 0x0); break; + case D3D11Chunk::CreateClassInstance: + Serialise_CreateClassInstance(ser, 0x0, 0, 0, 0, 0, 0x0, 0x0); + break; + case D3D11Chunk::CreateClassLinkage: Serialise_CreateClassLinkage(ser, 0x0); break; + case D3D11Chunk::CreateShaderResourceView: + Serialise_CreateShaderResourceView(ser, 0x0, 0x0, 0x0); + break; + case D3D11Chunk::CreateShaderResourceView1: + Serialise_CreateShaderResourceView1(ser, 0x0, 0x0, 0x0); + break; + case D3D11Chunk::CreateRenderTargetView: + Serialise_CreateRenderTargetView(ser, 0x0, 0x0, 0x0); + break; + case D3D11Chunk::CreateRenderTargetView1: + Serialise_CreateRenderTargetView1(ser, 0x0, 0x0, 0x0); + break; + case D3D11Chunk::CreateDepthStencilView: + Serialise_CreateDepthStencilView(ser, 0x0, 0x0, 0x0); + break; + case D3D11Chunk::CreateUnorderedAccessView: + Serialise_CreateUnorderedAccessView(ser, 0x0, 0x0, 0x0); + break; + case D3D11Chunk::CreateUnorderedAccessView1: + Serialise_CreateUnorderedAccessView1(ser, 0x0, 0x0, 0x0); + break; + case D3D11Chunk::CreateInputLayout: + Serialise_CreateInputLayout(ser, 0x0, 0, 0x0, 0, 0x0); + break; + case D3D11Chunk::CreateBlendState: Serialise_CreateBlendState(ser, 0x0, 0x0); break; + case D3D11Chunk::CreateBlendState1: Serialise_CreateBlendState1(ser, 0x0, 0x0); break; + case D3D11Chunk::CreateDepthStencilState: + Serialise_CreateDepthStencilState(ser, 0x0, 0x0); + break; + case D3D11Chunk::CreateRasterizerState: Serialise_CreateRasterizerState(ser, 0x0, 0x0); break; + case D3D11Chunk::CreateRasterizerState1: Serialise_CreateRasterizerState1(ser, 0x0, 0x0); break; + case D3D11Chunk::CreateRasterizerState2: Serialise_CreateRasterizerState2(ser, 0x0, 0x0); break; + case D3D11Chunk::CreateSamplerState: Serialise_CreateSamplerState(ser, 0x0, 0x0); break; + case D3D11Chunk::CreateQuery: Serialise_CreateQuery(ser, 0x0, 0x0); break; + case D3D11Chunk::CreateQuery1: Serialise_CreateQuery1(ser, 0x0, 0x0); break; + case D3D11Chunk::CreatePredicate: Serialise_CreatePredicate(ser, 0x0, 0x0); break; + case D3D11Chunk::CreateCounter: Serialise_CreateCounter(ser, 0x0, 0x0); break; + case D3D11Chunk::CreateDeferredContext: Serialise_CreateDeferredContext(ser, 0, 0x0); break; + case D3D11Chunk::SetExceptionMode: Serialise_SetExceptionMode(ser, 0); break; + case D3D11Chunk::OpenSharedResource: { IID nul; - Serialise_OpenSharedResource(0, nul, NULL); + Serialise_OpenSharedResource(ser, 0, nul, NULL); break; } - case CAPTURE_SCOPE: Serialise_CaptureScope(offset); break; - case SET_SHADER_DEBUG_PATH: Serialise_SetShaderDebugPath(NULL, NULL); break; + case D3D11Chunk::CaptureScope: Serialise_CaptureScope(ser); break; + case D3D11Chunk::SetShaderDebugPath: Serialise_SetShaderDebugPath(ser, NULL, NULL); break; default: - // ignore system chunks - if(context == INITIAL_CONTENTS) - Serialise_InitialState(ResourceId(), NULL); - else if(context < FIRST_CHUNK_ID) - m_pSerialiser->SkipCurrentChunk(); + { + SystemChunk system = (SystemChunk)context; + if(system == SystemChunk::DriverInit) + { + D3D11InitParams InitParams; + SERIALISE_ELEMENT(InitParams); + } + else if(system == SystemChunk::InitialContentsList) + { + GetResourceManager()->CreateInitialContents(ser); + } + else if(system == SystemChunk::InitialContents) + { + Serialise_InitialState(ser, ResourceId(), NULL); + } + else if(system < SystemChunk::FirstDriverChunk) + { + RDCERR("Unexpected system chunk in capture data: %u", system); + ser.SkipCurrentChunk(); + } else - m_pImmediateContext->ProcessChunk(offset, context, true); + { + m_pImmediateContext->ProcessChunk(ser, context, true); + } break; + } } } -void WrappedID3D11Device::Serialise_CaptureScope(uint64_t offset) +template +void WrappedID3D11Device::Serialise_CaptureScope(SerialiserType &ser) { - SERIALISE_ELEMENT(uint32_t, FrameNumber, m_FrameCounter); + SERIALISE_ELEMENT(m_FrameCounter); - if(m_State >= WRITING) + if(IsReplayMode(m_State)) { - GetResourceManager()->Serialise_InitialContentsNeeded(); - } - else - { - m_FrameRecord.frameInfo.fileOffset = offset; - m_FrameRecord.frameInfo.frameNumber = FrameNumber; + m_FrameRecord.frameInfo.frameNumber = m_FrameCounter; FrameStatistics &stats = m_FrameRecord.frameInfo.stats; RDCEraseEl(stats); @@ -873,18 +898,28 @@ void WrappedID3D11Device::Serialise_CaptureScope(uint64_t offset) stats.outputs.bindslots.resize(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT + D3D11_1_UAV_SLOT_COUNT + 1); - - GetResourceManager()->CreateInitialContents(); } } void WrappedID3D11Device::ReadLogInitialisation(RDCFile *rdc) { - uint64_t frameOffset = 0; + int sectionIdx = rdc->SectionIndex(SectionType::FrameCapture); - m_pSerialiser->SetDebugText(true); + if(sectionIdx < 0) + return; - m_pSerialiser->Rewind(); + StreamReader *reader = rdc->ReadSection(sectionIdx); + + if(reader->IsErrored()) + return; + + ReadSerialiser ser(reader, Ownership::Stream); + + ser.SetStringDatabase(&m_StringDB); + ser.SetUserData(GetResourceManager()); + + // TODO make this an option passed in + ser.ConfigureStructuredExport(&GetChunkName, false); int chunkIdx = 0; @@ -896,51 +931,49 @@ void WrappedID3D11Device::ReadLogInitialisation(RDCFile *rdc) double total; }; - map chunkInfos; + std::map chunkInfos; SCOPED_TIMER("chunk initialisation"); + uint64_t frameDataSize = 0; + for(;;) { PerformanceTimer timer; - uint64_t offset = m_pSerialiser->GetOffset(); + uint64_t offsetStart = reader->GetOffset(); - D3D11ChunkType context = (D3D11ChunkType)m_pSerialiser->PushContext(NULL, NULL, 1, false); - - if(context == CAPTURE_SCOPE) - { - // immediately read rest of log into memory - m_pSerialiser->SetPersistentBlock(offset); - } + D3D11Chunk context = ser.ReadChunk(); chunkIdx++; - ProcessChunk(offset, context); + ProcessChunk(ser, context); - m_pSerialiser->PopContext(context); + ser.EndChunk(); - RenderDoc::Inst().SetProgress(FileInitialRead, float(offset) / float(m_pSerialiser->GetSize())); + uint64_t offsetEnd = reader->GetOffset(); - if(context == CAPTURE_SCOPE) + RenderDoc::Inst().SetProgress(FileInitialRead, float(offsetEnd) / float(reader->GetSize())); + + if(context == D3D11Chunk::CaptureScope) { - frameOffset = offset; + m_FrameRecord.frameInfo.fileOffset = offsetStart; + + // read the remaining data into memory and pass to immediate context + frameDataSize = reader->GetSize() - reader->GetOffset(); + + m_pImmediateContext->SetFrameReader(new StreamReader(reader, frameDataSize)); GetResourceManager()->ApplyInitialContents(); - m_pImmediateContext->ReplayLog(READING, 0, 0, false); + m_pImmediateContext->ReplayLog(m_State, 0, 0, false); } - uint64_t offset2 = m_pSerialiser->GetOffset(); - chunkInfos[context].total += timer.GetMilliseconds(); - chunkInfos[context].totalsize += offset2 - offset; + chunkInfos[context].totalsize += offsetEnd - offsetStart; chunkInfos[context].count++; - if(context == CAPTURE_SCOPE) - break; - - if(m_pSerialiser->AtEnd()) + if(context == D3D11Chunk::CaptureScope || reader->IsErrored() || reader->AtEnd()) break; } @@ -956,29 +989,25 @@ void WrappedID3D11Device::ReadLogInitialisation(RDCFile *rdc) "% 5d chunks - Time: %9.3fms total/%9.3fms avg - Size: %8.3fMB total/%7.3fMB avg - %s (%u)", it->second.count, it->second.total, it->second.total / dcount, double(it->second.totalsize) / (1024.0 * 1024.0), - double(it->second.totalsize) / (dcount * 1024.0 * 1024.0), GetChunkName(it->first), - uint32_t(it->first)); + double(it->second.totalsize) / (dcount * 1024.0 * 1024.0), + GetChunkName((uint32_t)it->first).c_str(), uint32_t(it->first)); } #endif - m_FrameRecord.frameInfo.uncompressedFileSize = m_pSerialiser->GetSize(); - m_FrameRecord.frameInfo.compressedFileSize = m_pSerialiser->GetFileSize(); - m_FrameRecord.frameInfo.persistentSize = m_pSerialiser->GetSize() - frameOffset; - m_FrameRecord.frameInfo.initDataSize = chunkInfos[(D3D11ChunkType)INITIAL_CONTENTS].totalsize; + m_FrameRecord.frameInfo.uncompressedFileSize = + rdc->GetSectionProperties(sectionIdx).uncompressedSize; + m_FrameRecord.frameInfo.compressedFileSize = rdc->GetSectionProperties(sectionIdx).compressedSize; + m_FrameRecord.frameInfo.persistentSize = frameDataSize; + m_FrameRecord.frameInfo.initDataSize = + chunkInfos[(D3D11Chunk)SystemChunk::InitialContents].totalsize; RDCDEBUG("Allocating %llu persistant bytes of memory for the log.", - m_pSerialiser->GetSize() - frameOffset); - - m_pSerialiser->SetDebugText(false); + m_FrameRecord.frameInfo.persistentSize); } void WrappedID3D11Device::ReplayLog(uint32_t startEventID, uint32_t endEventID, ReplayLogType replayType) { - uint64_t offs = m_FrameRecord.frameInfo.fileOffset; - - m_pSerialiser->SetOffset(offs); - bool partial = true; if(startEventID == 0 && (replayType == eReplay_WithoutDraw || replayType == eReplay_Full)) @@ -987,14 +1016,6 @@ void WrappedID3D11Device::ReplayLog(uint32_t startEventID, uint32_t endEventID, partial = false; } - D3D11ChunkType header = (D3D11ChunkType)m_pSerialiser->PushContext(NULL, NULL, 1, false); - - RDCASSERTEQUAL(header, CAPTURE_SCOPE); - - m_pSerialiser->SkipCurrentChunk(); - - m_pSerialiser->PopContext(header); - if(!partial) { D3D11MarkerRegion apply("!!!!RenderDoc Internal: ApplyInitialContents"); @@ -1002,7 +1023,7 @@ void WrappedID3D11Device::ReplayLog(uint32_t startEventID, uint32_t endEventID, GetResourceManager()->ReleaseInFrameResources(); } - m_State = EXECUTING; + m_State = CaptureState::ActiveReplaying; D3D11MarkerRegion::Set(StringFormat::Fmt("!!!!RenderDoc Internal: Replay %d (%d): %u->%u", (int)replayType, (int)partial, startEventID, endEventID)); @@ -1010,11 +1031,11 @@ void WrappedID3D11Device::ReplayLog(uint32_t startEventID, uint32_t endEventID, m_ReplayEventCount = 0; if(replayType == eReplay_Full) - m_pImmediateContext->ReplayLog(EXECUTING, startEventID, endEventID, partial); + m_pImmediateContext->ReplayLog(m_State, startEventID, endEventID, partial); else if(replayType == eReplay_WithoutDraw) - m_pImmediateContext->ReplayLog(EXECUTING, startEventID, RDCMAX(1U, endEventID) - 1, partial); + m_pImmediateContext->ReplayLog(m_State, startEventID, RDCMAX(1U, endEventID) - 1, partial); else if(replayType == eReplay_OnlyDraw) - m_pImmediateContext->ReplayLog(EXECUTING, endEventID, endEventID, partial); + m_pImmediateContext->ReplayLog(m_State, endEventID, endEventID, partial); else RDCFATAL("Unexpected replay type"); @@ -1080,40 +1101,38 @@ void WrappedID3D11Device::ReleaseSwapchainResources(WrappedIDXGISwapChain4 *swap } } -bool WrappedID3D11Device::Serialise_WrapSwapchainBuffer(WrappedIDXGISwapChain4 *swap, - DXGI_SWAP_CHAIN_DESC *swapDesc, UINT buffer, +template +bool WrappedID3D11Device::Serialise_WrapSwapchainBuffer(SerialiserType &ser, + WrappedIDXGISwapChain4 *swap, + DXGI_SWAP_CHAIN_DESC *swapDesc, UINT Buffer, IUnknown *realSurface) { WrappedID3D11Texture2D1 *pTex = (WrappedID3D11Texture2D1 *)realSurface; - SERIALISE_ELEMENT(DXGI_FORMAT, swapFormat, swapDesc->BufferDesc.Format); - SERIALISE_ELEMENT(uint32_t, BuffNum, buffer); - SERIALISE_ELEMENT(ResourceId, pTexture, pTex->GetResourceID()); + SERIALISE_ELEMENT(Buffer); + SERIALISE_ELEMENT_LOCAL(SwapbufferID, pTex->GetResourceID()); - m_BBID = pTexture; + m_BBID = SwapbufferID; - if(m_State >= WRITING) - { - D3D11_TEXTURE2D_DESC desc; + D3D11_TEXTURE2D_DESC BackbufferDescriptor; - pTex->GetDesc(&desc); + if(ser.IsWriting() && pTex) + pTex->GetDesc(&BackbufferDescriptor); - SERIALISE_ELEMENT(D3D11_TEXTURE2D_DESC, Descriptor, desc); - } - else + SERIALISE_ELEMENT(BackbufferDescriptor); + + if(IsReplayingAndReading()) { ID3D11Texture2D *fakeBB; - SERIALISE_ELEMENT(D3D11_TEXTURE2D_DESC, Descriptor, D3D11_TEXTURE2D_DESC()); - - D3D11_TEXTURE2D_DESC realDescriptor = Descriptor; + D3D11_TEXTURE2D_DESC realDescriptor = BackbufferDescriptor; // DXGI swap chain back buffers can be freely cast as a special-case. // translate the format to a typeless format to allow for this. // the original type will be stored in the texture below - Descriptor.Format = GetTypelessFormat(Descriptor.Format); + BackbufferDescriptor.Format = GetTypelessFormat(BackbufferDescriptor.Format); - HRESULT hr = m_pDevice->CreateTexture2D(&Descriptor, NULL, &fakeBB); + HRESULT hr = m_pDevice->CreateTexture2D(&BackbufferDescriptor, NULL, &fakeBB); if(FAILED(hr)) { @@ -1129,7 +1148,7 @@ bool WrappedID3D11Device::Serialise_WrapSwapchainBuffer(WrappedIDXGISwapChain4 * SetDebugName(fakeBB, "Serialised Swap Chain Buffer"); - GetResourceManager()->AddLiveResource(pTexture, fakeBB); + GetResourceManager()->AddLiveResource(SwapbufferID, fakeBB); } } @@ -1167,7 +1186,7 @@ IUnknown *WrappedID3D11Device::WrapSwapchainBuffer(WrappedIDXGISwapChain4 *swap, // CreateTexture2D RDCASSERT(id != ResourceId() && !GetResourceManager()->HasResourceRecord(id)); - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { D3D11ResourceRecord *record = GetResourceManager()->AddResourceRecord(id); record->DataInSerialiser = false; @@ -1178,14 +1197,16 @@ IUnknown *WrappedID3D11Device::WrapSwapchainBuffer(WrappedIDXGISwapChain4 *swap, SCOPED_LOCK(m_D3DLock); - SCOPED_SERIALISE_CONTEXT(CREATE_SWAP_BUFFER); + WriteSerialiser &ser = m_ScratchSerialiser; - Serialise_WrapSwapchainBuffer(swap, swapDesc, buffer, pTex); + SCOPED_SERIALISE_CHUNK(D3D11Chunk::CreateSwapBuffer); + + Serialise_WrapSwapchainBuffer(ser, swap, swapDesc, buffer, pTex); record->AddChunk(scope.Get()); } - if(buffer == 0 && m_State >= WRITING) + if(buffer == 0 && IsCaptureMode(m_State)) { ID3D11RenderTargetView *rtv = NULL; HRESULT hr = m_pDevice->CreateRenderTargetView(UNWRAP(WrappedID3D11Texture2D1, pTex), NULL, &rtv); @@ -1234,14 +1255,14 @@ int WrappedID3D11Device::EndEvent() void WrappedID3D11Device::StartFrameCapture(void *dev, void *wnd) { - if(m_State != WRITING_IDLE) - return; - SCOPED_LOCK(m_D3DLock); + if(!IsBackgroundCapturing(m_State)) + return; + RenderDoc::Inst().SetCurrentDriver(RDC_D3D11); - m_State = WRITING_CAPFRAME; + m_State = CaptureState::ActiveCapturing; m_AppControlledCapture = true; @@ -1291,7 +1312,9 @@ void WrappedID3D11Device::StartFrameCapture(void *dev, void *wnd) bool WrappedID3D11Device::EndFrameCapture(void *dev, void *wnd) { - if(m_State != WRITING_CAPFRAME) + SCOPED_LOCK(m_D3DLock); + + if(!IsActiveCapturing(m_State)) return true; CaptureFailReason reason; @@ -1320,8 +1343,6 @@ bool WrappedID3D11Device::EndFrameCapture(void *dev, void *wnd) if(m_pImmediateContext->HasSuccessfulCapture(reason)) { - SCOPED_LOCK(m_D3DLock); - RDCLOG("Finished capture, Frame %u", m_FrameCounter); m_Failures = 0; @@ -1348,8 +1369,8 @@ bool WrappedID3D11Device::EndFrameCapture(void *dev, void *wnd) const uint32_t maxSize = 2048; byte *thpixels = NULL; - uint32_t thwidth = 0; - uint32_t thheight = 0; + uint16_t thwidth = 0; + uint16_t thheight = 0; if(swap != NULL) { @@ -1433,9 +1454,9 @@ bool WrappedID3D11Device::EndFrameCapture(void *dev, void *wnd) float aspect = float(desc.Width) / float(desc.Height); - thwidth = RDCMIN(maxSize, desc.Width); + thwidth = (uint16_t)RDCMIN(maxSize, desc.Width); thwidth &= ~0x7; // align down to multiple of 8 - thheight = uint32_t(float(thwidth) / aspect); + thheight = uint16_t(float(thwidth) / aspect); thpixels = new byte[3 * thwidth * thheight]; @@ -1543,66 +1564,94 @@ bool WrappedID3D11Device::EndFrameCapture(void *dev, void *wnd) } } - Serialiser *m_pFileSerialiser = RenderDoc::Inst().OpenWriteSerialiser( - m_FrameCounter, &m_InitParams, jpgbuf, len, thwidth, thheight); + RDCFile *rdc = RenderDoc::Inst().CreateRDC(m_FrameCounter, jpgbuf, len, thwidth, thheight); SAFE_DELETE_ARRAY(jpgbuf); - SAFE_DELETE(thpixels); + SAFE_DELETE_ARRAY(thpixels); + StreamWriter *captureWriter = NULL; + + if(rdc) { - SCOPED_SERIALISE_CONTEXT(DEVICE_INIT); + SectionProperties props; - SERIALISE_ELEMENT(ResourceId, immContextId, m_pImmediateContext->GetResourceID()); + // Compress with LZ4 so that it's fast + props.flags = SectionFlags::LZ4Compressed; + props.version = m_SectionVersion; + props.type = SectionType::FrameCapture; - m_pFileSerialiser->Insert(scope.Get(true)); + captureWriter = rdc->WriteSection(props); } - - RDCDEBUG("Inserting Resource Serialisers"); - - LockForChunkFlushing(); - - GetResourceManager()->InsertReferencedChunks(m_pFileSerialiser); - - GetResourceManager()->InsertInitialContentsChunks(m_pFileSerialiser); - - RDCDEBUG("Creating Capture Scope"); - + else { - SCOPED_SERIALISE_CONTEXT(CAPTURE_SCOPE); - - Serialise_CaptureScope(0); - - m_pFileSerialiser->Insert(scope.Get(true)); + captureWriter = new StreamWriter(StreamWriter::InvalidStream); } { - RDCDEBUG("Getting Resource Record"); + WriteSerialiser ser(captureWriter, Ownership::Stream); - D3D11ResourceRecord *record = - m_ResourceManager->GetResourceRecord(m_pImmediateContext->GetResourceID()); + ser.SetUserData(GetResourceManager()); - RDCDEBUG("Accumulating context resource list"); + { + // remember to update this estimated chunk length if you add more parameters + SCOPED_SERIALISE_CHUNK(SystemChunk::DriverInit, sizeof(D3D11InitParams) + 16); - map recordlist; - record->Insert(recordlist); + SERIALISE_ELEMENT(m_InitParams); + } - RDCDEBUG("Flushing %u records to file serialiser", (uint32_t)recordlist.size()); + { + // remember to update this estimated chunk length if you add more parameters + SCOPED_SERIALISE_CHUNK(D3D11Chunk::DeviceInitialisation, 16); - for(auto it = recordlist.begin(); it != recordlist.end(); ++it) - m_pFileSerialiser->Insert(it->second); + SERIALISE_ELEMENT_LOCAL(ImmediateContext, m_pImmediateContext->GetResourceID()); + } - RDCDEBUG("Done"); + RDCDEBUG("Inserting Resource Serialisers"); + + LockForChunkFlushing(); + + GetResourceManager()->ApplyInitialContentsNonChunks(ser); + + GetResourceManager()->InsertReferencedChunks(ser); + + GetResourceManager()->InsertInitialContentsChunks(ser); + + RDCDEBUG("Creating Capture Scope"); + + GetResourceManager()->Serialise_InitialContentsNeeded(ser); + + { + // remember to update this estimated chunk length if you add more parameters + SCOPED_SERIALISE_CHUNK(D3D11Chunk::CaptureScope, 16); + + Serialise_CaptureScope(ser); + } + + { + RDCDEBUG("Getting Resource Record"); + + D3D11ResourceRecord *record = + m_ResourceManager->GetResourceRecord(m_pImmediateContext->GetResourceID()); + + RDCDEBUG("Accumulating context resource list"); + + std::map recordlist; + record->Insert(recordlist); + + RDCDEBUG("Flushing %u records to file serialiser", (uint32_t)recordlist.size()); + + for(auto it = recordlist.begin(); it != recordlist.end(); ++it) + it->second->Write(ser); + + RDCDEBUG("Done"); + } + + UnlockForChunkFlushing(); } - m_pFileSerialiser->FlushToDisk(); + RenderDoc::Inst().FinishCaptureWriting(rdc, m_FrameCounter); - UnlockForChunkFlushing(); - - SAFE_DELETE(m_pFileSerialiser); - - RenderDoc::Inst().SuccessfullyWrittenLog(m_FrameCounter); - - m_State = WRITING_IDLE; + m_State = CaptureState::BackgroundCapturing; m_pImmediateContext->CleanupCapture(); @@ -1703,7 +1752,7 @@ bool WrappedID3D11Device::EndFrameCapture(void *dev, void *wnd) m_FailedFrame = m_FrameCounter; m_FailedReason = reason; - m_State = WRITING_IDLE; + m_State = CaptureState::BackgroundCapturing; for(auto it = m_DeferredContexts.begin(); it != m_DeferredContexts.end(); ++it) { @@ -1839,7 +1888,7 @@ void WrappedID3D11Device::FirstFrame(WrappedIDXGISwapChain4 *swapChain) DXGI_SWAP_CHAIN_DESC swapdesc = swapChain->GetDescWithHWND(); // if we have to capture the first frame, begin capturing immediately - if(m_State == WRITING_IDLE && RenderDoc::Inst().ShouldTriggerCapture(0)) + if(IsBackgroundCapturing(m_State) && RenderDoc::Inst().ShouldTriggerCapture(0)) { RenderDoc::Inst().StartFrameCapture((ID3D11Device *)this, swapdesc.OutputWindow); @@ -1854,7 +1903,7 @@ HRESULT WrappedID3D11Device::Present(WrappedIDXGISwapChain4 *swap, UINT SyncInte m_pCurrentWrappedDevice = this; - if(m_State == WRITING_IDLE) + if(IsBackgroundCapturing(m_State)) RenderDoc::Inst().Tick(); m_pImmediateContext->EndFrame(); @@ -1866,7 +1915,7 @@ HRESULT WrappedID3D11Device::Present(WrappedIDXGISwapChain4 *swap, UINT SyncInte DXGI_SWAP_CHAIN_DESC swapdesc = swap->GetDescWithHWND(); bool activeWindow = RenderDoc::Inst().IsActiveWindow((ID3D11Device *)this, swapdesc.OutputWindow); - if(m_State == WRITING_IDLE) + if(IsBackgroundCapturing(m_State)) { D3D11RenderState old = *m_pImmediateContext->GetCurrentPipelineState(); @@ -1913,14 +1962,14 @@ HRESULT WrappedID3D11Device::Present(WrappedIDXGISwapChain4 *swap, UINT SyncInte RenderDoc::Inst().SetCurrentDriver(RDC_D3D11); // kill any current capture that isn't application defined - if(m_State == WRITING_CAPFRAME && !m_AppControlledCapture) + if(IsActiveCapturing(m_State) && !m_AppControlledCapture) { m_pImmediateContext->Present(SyncInterval, Flags); RenderDoc::Inst().EndFrameCapture((ID3D11Device *)this, swapdesc.OutputWindow); } - if(RenderDoc::Inst().ShouldTriggerCapture(m_FrameCounter) && m_State == WRITING_IDLE) + if(IsBackgroundCapturing(m_State) && RenderDoc::Inst().ShouldTriggerCapture(m_FrameCounter)) { RenderDoc::Inst().StartFrameCapture((ID3D11Device *)this, swapdesc.OutputWindow); @@ -1976,42 +2025,44 @@ void WrappedID3D11Device::RemoveDeferredContext(WrappedID3D11DeviceContext *defc m_DeferredContexts.erase(defctx); } -bool WrappedID3D11Device::Serialise_SetShaderDebugPath(ID3D11DeviceChild *res, const char *p) +template +bool WrappedID3D11Device::Serialise_SetShaderDebugPath(SerialiserType &ser, + ID3D11DeviceChild *pResource, const char *Path) { - SERIALISE_ELEMENT(ResourceId, resource, GetIDForResource(res)); - string debugPath = p ? p : ""; - m_pSerialiser->Serialise("debugPath", debugPath); + SERIALISE_ELEMENT(pResource); + SERIALISE_ELEMENT(Path); - if(m_State < WRITING && GetResourceManager()->HasLiveResource(resource)) + if(IsReplayingAndReading() && pResource) { - auto it = WrappedShader::m_ShaderList.find(GetResourceManager()->GetLiveID(resource)); + auto it = WrappedShader::m_ShaderList.find(GetIDForResource(pResource)); if(it != WrappedShader::m_ShaderList.end()) - it->second->SetDebugInfoPath(debugPath); + it->second->SetDebugInfoPath(Path); } return true; } -HRESULT WrappedID3D11Device::SetShaderDebugPath(ID3D11DeviceChild *res, const char *path) +HRESULT WrappedID3D11Device::SetShaderDebugPath(ID3D11DeviceChild *pResource, const char *Path) { - if(m_State >= WRITING) + if(IsCaptureMode(m_State)) { - ResourceId idx = GetIDForResource(res); + ResourceId idx = GetIDForResource(pResource); D3D11ResourceRecord *record = GetResourceManager()->GetResourceRecord(idx); if(record == NULL) { - RDCERR("Setting shader debug path on object %p of type %d that has no resource record.", res, - IdentifyTypeByPtr(res)); + RDCERR("Setting shader debug path on object %p of type %d that has no resource record.", + pResource, IdentifyTypeByPtr(pResource)); return E_INVALIDARG; } RDCASSERT(idx != ResourceId()); { - SCOPED_SERIALISE_CONTEXT(SET_SHADER_DEBUG_PATH); - Serialise_SetShaderDebugPath(res, path); + WriteSerialiser &ser = m_ScratchSerialiser; + SCOPED_SERIALISE_CHUNK(D3D11Chunk::SetShaderDebugPath); + Serialise_SetShaderDebugPath(ser, pResource, Path); record->AddChunk(scope.Get()); } @@ -2021,30 +2072,29 @@ HRESULT WrappedID3D11Device::SetShaderDebugPath(ID3D11DeviceChild *res, const ch return S_OK; } -bool WrappedID3D11Device::Serialise_SetResourceName(ID3D11DeviceChild *res, const char *nm) +template +bool WrappedID3D11Device::Serialise_SetResourceName(SerialiserType &ser, + ID3D11DeviceChild *pResource, const char *Name) { - SERIALISE_ELEMENT(ResourceId, resource, GetIDForResource(res)); - string name = nm ? nm : ""; - m_pSerialiser->Serialise("name", name); + SERIALISE_ELEMENT(pResource); + SERIALISE_ELEMENT(Name); - if(m_State < WRITING && GetResourceManager()->HasLiveResource(resource)) + if(IsReplayingAndReading() && pResource) { - ID3D11DeviceChild *r = GetResourceManager()->GetLiveResource(resource); - - SetDebugName(r, name.c_str()); + SetDebugName(pResource, Name); } return true; } -void WrappedID3D11Device::SetResourceName(ID3D11DeviceChild *res, const char *name) +void WrappedID3D11Device::SetResourceName(ID3D11DeviceChild *pResource, const char *Name) { // don't allow naming device contexts or command lists so we know this chunk // is always on a pre-capture chunk. - if(m_State >= WRITING && !WrappedID3D11DeviceContext::IsAlloc(res) && - !WrappedID3D11CommandList::IsAlloc(res)) + if(IsCaptureMode(m_State) && !WrappedID3D11DeviceContext::IsAlloc(pResource) && + !WrappedID3D11CommandList::IsAlloc(pResource)) { - ResourceId idx = GetIDForResource(res); + ResourceId idx = GetIDForResource(pResource); D3D11ResourceRecord *record = GetResourceManager()->GetResourceRecord(idx); if(record == NULL) @@ -2054,9 +2104,10 @@ void WrappedID3D11Device::SetResourceName(ID3D11DeviceChild *res, const char *na SCOPED_LOCK(m_D3DLock); { - SCOPED_SERIALISE_CONTEXT(SET_RESOURCE_NAME); + WriteSerialiser &ser = m_ScratchSerialiser; + SCOPED_SERIALISE_CHUNK(D3D11Chunk::SetResourceName); - Serialise_SetResourceName(res, name); + Serialise_SetResourceName(ser, pResource, Name); LockForChunkRemoval(); @@ -2067,7 +2118,7 @@ void WrappedID3D11Device::SetResourceName(ID3D11DeviceChild *res, const char *na { Chunk *end = record->GetLastChunk(); - if(end->GetChunkType() == SET_RESOURCE_NAME) + if(end->GetChunkType() == D3D11Chunk::SetResourceName) { SAFE_DELETE(end); record->PopChunk(); @@ -2085,36 +2136,16 @@ void WrappedID3D11Device::SetResourceName(ID3D11DeviceChild *res, const char *na } } -bool WrappedID3D11Device::Serialise_ReleaseResource(ID3D11DeviceChild *res) +template +bool WrappedID3D11Device::Serialise_ReleaseResource(SerialiserType &ser, ID3D11DeviceChild *pResource) { - ResourceType resourceType = Resource_Unknown; - ResourceId resource = GetIDForResource(res); + SERIALISE_ELEMENT(pResource); - if(m_State >= WRITING) + if(IsReplayingAndReading() && pResource) { - resourceType = IdentifyTypeByPtr(res); - } - - if(m_State == WRITING_IDLE || m_State < WRITING) - { - SERIALISE_ELEMENT(ResourceId, serRes, GetIDForResource(res)); - SERIALISE_ELEMENT(ResourceType, serType, resourceType); - - resourceType = serType; - resource = serRes; - } - - if(m_State >= WRITING) - { - D3D11ResourceRecord *record = GetResourceManager()->GetResourceRecord(resource); - if(record) - record->Delete(m_ResourceManager); - } - if(m_State < WRITING && GetResourceManager()->HasLiveResource(resource)) - { - res = GetResourceManager()->GetLiveResource(resource); - GetResourceManager()->EraseLiveResource(resource); - SAFE_RELEASE(res); + GetResourceManager()->EraseLiveResource( + GetResourceManager()->GetOriginalID(GetIDForResource(pResource))); + SAFE_RELEASE(pResource); } return true; @@ -2126,7 +2157,7 @@ void WrappedID3D11Device::ReleaseResource(ID3D11DeviceChild *res) // wrapped resources get released all the time, we don't want to // try and slerp in a resource release. Just the explicit ones - if(m_State < WRITING) + if(!IsCaptureMode(m_State)) { if(GetResourceManager()->HasLiveResource(idx)) GetResourceManager()->EraseLiveResource(idx); @@ -2139,7 +2170,7 @@ void WrappedID3D11Device::ReleaseResource(ID3D11DeviceChild *res) D3D11ResourceRecord *record = m_DeviceRecord; - if(m_State == WRITING_IDLE) + if(IsBackgroundCapturing(m_State)) { if(type == Resource_ShaderResourceView || type == Resource_DepthStencilView || type == Resource_UnorderedAccessView || type == Resource_RenderTargetView || @@ -2192,14 +2223,12 @@ void WrappedID3D11Device::ReleaseResource(ID3D11DeviceChild *res) if(serialiseRelease) { - if(m_State == WRITING_CAPFRAME) + WriteSerialiser &ser = m_ScratchSerialiser; + + if(IsBackgroundCapturing(m_State)) { - Serialise_ReleaseResource(res); - } - else - { - SCOPED_SERIALISE_CONTEXT(RELEASE_RESOURCE); - Serialise_ReleaseResource(res); + SCOPED_SERIALISE_CHUNK(D3D11Chunk::ReleaseResource); + Serialise_ReleaseResource(ser, res); if(record) { @@ -2212,8 +2241,12 @@ void WrappedID3D11Device::ReleaseResource(ID3D11DeviceChild *res) // if record is NULL then we just deleted a reference-less resource. // That means it is not used and can be safely discarded, so just // throw away the serialiser contents - m_pSerialiser->Rewind(); + ser.GetWriter()->Rewind(); } + + record = GetResourceManager()->GetResourceRecord(idx); + if(record) + record->Delete(m_ResourceManager); } } diff --git a/renderdoc/driver/d3d11/d3d11_device.h b/renderdoc/driver/d3d11/d3d11_device.h index e9ec27ccd..8d70eeb17 100644 --- a/renderdoc/driver/d3d11/d3d11_device.h +++ b/renderdoc/driver/d3d11/d3d11_device.h @@ -354,11 +354,13 @@ private: // protects wrapped resource creation and serialiser access Threading::CriticalSection m_D3DLock; + WriteSerialiser m_ScratchSerialiser; + std::set m_StringDB; + ResourceId m_ResourceID; D3D11ResourceRecord *m_DeviceRecord; - Serialiser *m_pSerialiser; - LogState m_State; + CaptureState m_State; bool m_AppControlledCapture; set m_CachedStateObjects; @@ -426,7 +428,6 @@ public: void RemoveDeferredContext(WrappedID3D11DeviceContext *defctx); WrappedID3D11DeviceContext *GetDeferredContext(size_t idx); - Serialiser *GetSerialiser() { return m_pSerialiser; } ResourceId GetResourceID() { return m_ResourceID; } FrameRecord &GetFrameRecord() { return m_FrameRecord; } FrameStatistics &GetFrameStats() { return m_FrameRecord.frameInfo.stats; } @@ -441,7 +442,7 @@ public: void FirstFrame(WrappedIDXGISwapChain4 *swapChain); - vector GetDebugMessages(); + std::vector GetDebugMessages(); void AddDebugMessage(DebugMessage msg); void AddDebugMessage(MessageCategory c, MessageSeverity sv, MessageSource src, std::string d); const vector &GetLayoutDesc(ID3D11InputLayout *layout) @@ -450,7 +451,8 @@ public: } vector *GetShaderDebugInfoSearchPaths() { return &m_ShaderSearchPaths; } - void Serialise_CaptureScope(uint64_t offset); + template + void Serialise_CaptureScope(SerialiserType &ser); void StartFrameCapture(void *dev, void *wnd); bool EndFrameCapture(void *dev, void *wnd); @@ -499,35 +501,32 @@ public: void Apply_InitialState(ID3D11DeviceChild *live, D3D11ResourceManager::InitialContentData initial); void ReadLogInitialisation(RDCFile *rdc); - void ProcessChunk(uint64_t offset, D3D11Chunk context); + void ProcessChunk(ReadSerialiser &ser, D3D11Chunk context); void ReplayLog(uint32_t startEventID, uint32_t endEventID, ReplayLogType replayType); //////////////////////////////////////////////////////////////// // 'fake' interfaces // Resource - IMPLEMENT_FUNCTION_SERIALISED(void, SetResourceName(ID3D11DeviceChild *res, const char *name)); - IMPLEMENT_FUNCTION_SERIALISED(HRESULT, - SetShaderDebugPath(ID3D11DeviceChild *res, const char *name)); - IMPLEMENT_FUNCTION_SERIALISED(void, ReleaseResource(ID3D11DeviceChild *res)); + IMPLEMENT_FUNCTION_SERIALISED(void, SetResourceName, ID3D11DeviceChild *pResource, + const char *Name); + IMPLEMENT_FUNCTION_SERIALISED(HRESULT, SetShaderDebugPath, ID3D11DeviceChild *pResource, + const char *Path); + IMPLEMENT_FUNCTION_SERIALISED(void, ReleaseResource, ID3D11DeviceChild *pResource); // Class Linkage - IMPLEMENT_FUNCTION_SERIALISED(ID3D11ClassInstance *, - CreateClassInstance(LPCSTR pClassTypeName, UINT ConstantBufferOffset, - UINT ConstantVectorOffset, UINT TextureOffset, - UINT SamplerOffset, - WrappedID3D11ClassLinkage *linkage, - ID3D11ClassInstance *inst)); + IMPLEMENT_FUNCTION_SERIALISED(ID3D11ClassInstance *, CreateClassInstance, LPCSTR pClassTypeName, + UINT ConstantBufferOffset, UINT ConstantVectorOffset, + UINT TextureOffset, UINT SamplerOffset, + WrappedID3D11ClassLinkage *linkage, ID3D11ClassInstance *inst); - IMPLEMENT_FUNCTION_SERIALISED(ID3D11ClassInstance *, - GetClassInstance(LPCSTR pClassInstanceName, UINT InstanceIndex, - WrappedID3D11ClassLinkage *linkage, - ID3D11ClassInstance *inst)); + IMPLEMENT_FUNCTION_SERIALISED(ID3D11ClassInstance *, GetClassInstance, LPCSTR pClassInstanceName, + UINT InstanceIndex, WrappedID3D11ClassLinkage *linkage, + ID3D11ClassInstance *inst); // Swap Chain - IMPLEMENT_FUNCTION_SERIALISED(IUnknown *, WrapSwapchainBuffer(WrappedIDXGISwapChain4 *swap, - DXGI_SWAP_CHAIN_DESC *desc, - UINT buffer, IUnknown *realSurface)); + IMPLEMENT_FUNCTION_SERIALISED(IUnknown *, WrapSwapchainBuffer, WrappedIDXGISwapChain4 *swap, + DXGI_SWAP_CHAIN_DESC *desc, UINT buffer, IUnknown *realSurface); HRESULT Present(WrappedIDXGISwapChain4 *swap, UINT SyncInterval, UINT Flags); void NewSwapchainBuffer(IUnknown *backbuffer); @@ -566,10 +565,9 @@ public: ////////////////////////////// // implement ID3D11Device - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateBuffer(const D3D11_BUFFER_DESC *pDesc, - const D3D11_SUBRESOURCE_DATA *pInitialData, - ID3D11Buffer **ppBuffer)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateBuffer, + const D3D11_BUFFER_DESC *pDesc, + const D3D11_SUBRESOURCE_DATA *pInitialData, ID3D11Buffer **ppBuffer); template TextureDisplayType DispTypeForTexture(TexDesc &Descriptor) @@ -593,208 +591,189 @@ public: return dispType; } - vector Serialise_CreateTextureData(ID3D11Resource *tex, ResourceId id, - const D3D11_SUBRESOURCE_DATA *data, - UINT w, UINT h, UINT d, DXGI_FORMAT fmt, - UINT mips, UINT arr, bool HasData); + template + std::vector Serialise_CreateTextureData( + SerialiserType &ser, ID3D11Resource *tex, ResourceId id, const D3D11_SUBRESOURCE_DATA *data, + UINT w, UINT h, UINT d, DXGI_FORMAT fmt, UINT mips, UINT arr, bool HasData); + + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateTexture1D, + const D3D11_TEXTURE1D_DESC *pDesc, + const D3D11_SUBRESOURCE_DATA *pInitialData, + ID3D11Texture1D **ppTexture1D); + + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateTexture2D, + const D3D11_TEXTURE2D_DESC *pDesc, + const D3D11_SUBRESOURCE_DATA *pInitialData, + ID3D11Texture2D **ppTexture2D); + + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateTexture3D, + const D3D11_TEXTURE3D_DESC *pDesc, + const D3D11_SUBRESOURCE_DATA *pInitialData, + ID3D11Texture3D **ppTexture3D); + + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateShaderResourceView, + ID3D11Resource *pResource, + const D3D11_SHADER_RESOURCE_VIEW_DESC *pDesc, + ID3D11ShaderResourceView **ppSRView); + + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateUnorderedAccessView, + ID3D11Resource *pResource, + const D3D11_UNORDERED_ACCESS_VIEW_DESC *pDesc, + ID3D11UnorderedAccessView **ppUAView); + + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateRenderTargetView, + ID3D11Resource *pResource, const D3D11_RENDER_TARGET_VIEW_DESC *pDesc, + ID3D11RenderTargetView **ppRTView); + + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateDepthStencilView, + ID3D11Resource *pResource, const D3D11_DEPTH_STENCIL_VIEW_DESC *pDesc, + ID3D11DepthStencilView **ppDepthStencilView); + + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateInputLayout, + const D3D11_INPUT_ELEMENT_DESC *pInputElementDescs, + UINT NumElements, const void *pShaderBytecodeWithInputSignature, + SIZE_T BytecodeLength, ID3D11InputLayout **ppInputLayout); + + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateVertexShader, + const void *pShaderBytecode, SIZE_T BytecodeLength, + ID3D11ClassLinkage *pClassLinkage, + ID3D11VertexShader **ppVertexShader); + + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateGeometryShader, + const void *pShaderBytecode, SIZE_T BytecodeLength, + ID3D11ClassLinkage *pClassLinkage, + ID3D11GeometryShader **ppGeometryShader); IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateTexture1D(const D3D11_TEXTURE1D_DESC *pDesc, - const D3D11_SUBRESOURCE_DATA *pInitialData, - ID3D11Texture1D **ppTexture1D)); + CreateGeometryShaderWithStreamOutput, const void *pShaderBytecode, + SIZE_T BytecodeLength, + const D3D11_SO_DECLARATION_ENTRY *pSODeclaration, UINT NumEntries, + const UINT *pBufferStrides, UINT NumStrides, UINT RasterizedStream, + ID3D11ClassLinkage *pClassLinkage, + ID3D11GeometryShader **ppGeometryShader); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateTexture2D(const D3D11_TEXTURE2D_DESC *pDesc, - const D3D11_SUBRESOURCE_DATA *pInitialData, - ID3D11Texture2D **ppTexture2D)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreatePixelShader, + const void *pShaderBytecode, SIZE_T BytecodeLength, + ID3D11ClassLinkage *pClassLinkage, ID3D11PixelShader **ppPixelShader); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateTexture3D(const D3D11_TEXTURE3D_DESC *pDesc, - const D3D11_SUBRESOURCE_DATA *pInitialData, - ID3D11Texture3D **ppTexture3D)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateHullShader, + const void *pShaderBytecode, SIZE_T BytecodeLength, + ID3D11ClassLinkage *pClassLinkage, ID3D11HullShader **ppHullShader); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateShaderResourceView(ID3D11Resource *pResource, - const D3D11_SHADER_RESOURCE_VIEW_DESC *pDesc, - ID3D11ShaderResourceView **ppSRView)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateDomainShader, + const void *pShaderBytecode, SIZE_T BytecodeLength, + ID3D11ClassLinkage *pClassLinkage, + ID3D11DomainShader **ppDomainShader); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateUnorderedAccessView(ID3D11Resource *pResource, - const D3D11_UNORDERED_ACCESS_VIEW_DESC *pDesc, - ID3D11UnorderedAccessView **ppUAView)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateComputeShader, + const void *pShaderBytecode, SIZE_T BytecodeLength, + ID3D11ClassLinkage *pClassLinkage, + ID3D11ComputeShader **ppComputeShader); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateRenderTargetView(ID3D11Resource *pResource, - const D3D11_RENDER_TARGET_VIEW_DESC *pDesc, - ID3D11RenderTargetView **ppRTView)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateClassLinkage, + ID3D11ClassLinkage **ppLinkage); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateDepthStencilView(ID3D11Resource *pResource, - const D3D11_DEPTH_STENCIL_VIEW_DESC *pDesc, - ID3D11DepthStencilView **ppDepthStencilView)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateBlendState, + const D3D11_BLEND_DESC *pBlendStateDesc, + ID3D11BlendState **ppBlendState); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *pInputElementDescs, - UINT NumElements, - const void *pShaderBytecodeWithInputSignature, - SIZE_T BytecodeLength, - ID3D11InputLayout **ppInputLayout)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateDepthStencilState, + const D3D11_DEPTH_STENCIL_DESC *pDepthStencilDesc, + ID3D11DepthStencilState **ppDepthStencilState); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, - ID3D11ClassLinkage *pClassLinkage, - ID3D11VertexShader **ppVertexShader)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateRasterizerState, + const D3D11_RASTERIZER_DESC *pRasterizerDesc, + ID3D11RasterizerState **ppRasterizerState); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateGeometryShader(const void *pShaderBytecode, - SIZE_T BytecodeLength, - ID3D11ClassLinkage *pClassLinkage, - ID3D11GeometryShader **ppGeometryShader)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateSamplerState, + const D3D11_SAMPLER_DESC *pSamplerDesc, + ID3D11SamplerState **ppSamplerState); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateGeometryShaderWithStreamOutput( - const void *pShaderBytecode, SIZE_T BytecodeLength, - const D3D11_SO_DECLARATION_ENTRY *pSODeclaration, - UINT NumEntries, const UINT *pBufferStrides, UINT NumStrides, - UINT RasterizedStream, ID3D11ClassLinkage *pClassLinkage, - ID3D11GeometryShader **ppGeometryShader)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateQuery, + const D3D11_QUERY_DESC *pQueryDesc, ID3D11Query **ppQuery); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, - ID3D11ClassLinkage *pClassLinkage, - ID3D11PixelShader **ppPixelShader)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreatePredicate, + const D3D11_QUERY_DESC *pPredicateDesc, + ID3D11Predicate **ppPredicate); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateHullShader(const void *pShaderBytecode, SIZE_T BytecodeLength, - ID3D11ClassLinkage *pClassLinkage, - ID3D11HullShader **ppHullShader)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateCounter, + const D3D11_COUNTER_DESC *pCounterDesc, ID3D11Counter **ppCounter); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateDomainShader(const void *pShaderBytecode, SIZE_T BytecodeLength, - ID3D11ClassLinkage *pClassLinkage, - ID3D11DomainShader **ppDomainShader)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateDeferredContext, + UINT ContextFlags, ID3D11DeviceContext **ppDeferredContext); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateComputeShader(const void *pShaderBytecode, SIZE_T BytecodeLength, - ID3D11ClassLinkage *pClassLinkage, - ID3D11ComputeShader **ppComputeShader)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, OpenSharedResource, + HANDLE hResource, REFIID ReturnedInterface, void **ppResource); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateClassLinkage(ID3D11ClassLinkage **ppLinkage)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CheckFormatSupport, + DXGI_FORMAT Format, UINT *pFormatSupport); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateBlendState(const D3D11_BLEND_DESC *pBlendStateDesc, - ID3D11BlendState **ppBlendState)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CheckMultisampleQualityLevels, + DXGI_FORMAT Format, UINT SampleCount, UINT *pNumQualityLevels); - IMPLEMENT_FUNCTION_SERIALISED( - virtual HRESULT STDMETHODCALLTYPE, - CreateDepthStencilState(const D3D11_DEPTH_STENCIL_DESC *pDepthStencilDesc, - ID3D11DepthStencilState **ppDepthStencilState)); + IMPLEMENT_FUNCTION_SERIALISED(virtual void STDMETHODCALLTYPE, CheckCounterInfo, + D3D11_COUNTER_INFO *pCounterInfo); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateRasterizerState(const D3D11_RASTERIZER_DESC *pRasterizerDesc, - ID3D11RasterizerState **ppRasterizerState)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CheckCounter, + const D3D11_COUNTER_DESC *pDesc, D3D11_COUNTER_TYPE *pType, + UINT *pActiveCounters, LPSTR szName, UINT *pNameLength, LPSTR szUnits, + UINT *pUnitsLength, LPSTR szDescription, UINT *pDescriptionLength); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateSamplerState(const D3D11_SAMPLER_DESC *pSamplerDesc, - ID3D11SamplerState **ppSamplerState)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CheckFeatureSupport, + D3D11_FEATURE Feature, void *pFeatureSupportData, + UINT FeatureSupportDataSize); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateQuery(const D3D11_QUERY_DESC *pQueryDesc, - ID3D11Query **ppQuery)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, GetPrivateData, REFGUID guid, + UINT *pDataSize, void *pData); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreatePredicate(const D3D11_QUERY_DESC *pPredicateDesc, - ID3D11Predicate **ppPredicate)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, SetPrivateData, REFGUID guid, + UINT DataSize, const void *pData); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateCounter(const D3D11_COUNTER_DESC *pCounterDesc, - ID3D11Counter **ppCounter)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, SetPrivateDataInterface, + REFGUID guid, const IUnknown *pData); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateDeferredContext(UINT ContextFlags, - ID3D11DeviceContext **ppDeferredContext)); + IMPLEMENT_FUNCTION_SERIALISED(virtual D3D_FEATURE_LEVEL STDMETHODCALLTYPE, GetFeatureLevel); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - OpenSharedResource(HANDLE hResource, REFIID ReturnedInterface, - void **ppResource)); + IMPLEMENT_FUNCTION_SERIALISED(virtual UINT STDMETHODCALLTYPE, GetCreationFlags); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CheckFormatSupport(DXGI_FORMAT Format, UINT *pFormatSupport)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, GetDeviceRemovedReason); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CheckMultisampleQualityLevels(DXGI_FORMAT Format, UINT SampleCount, - UINT *pNumQualityLevels)); + IMPLEMENT_FUNCTION_SERIALISED(virtual void STDMETHODCALLTYPE, GetImmediateContext, + ID3D11DeviceContext **ppImmediateContext); - IMPLEMENT_FUNCTION_SERIALISED(virtual void STDMETHODCALLTYPE, - CheckCounterInfo(D3D11_COUNTER_INFO *pCounterInfo)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, SetExceptionMode, UINT RaiseFlags); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CheckCounter(const D3D11_COUNTER_DESC *pDesc, - D3D11_COUNTER_TYPE *pType, UINT *pActiveCounters, - LPSTR szName, UINT *pNameLength, LPSTR szUnits, - UINT *pUnitsLength, LPSTR szDescription, - UINT *pDescriptionLength)); - - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CheckFeatureSupport(D3D11_FEATURE Feature, void *pFeatureSupportData, - UINT FeatureSupportDataSize)); - - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - GetPrivateData(REFGUID guid, UINT *pDataSize, void *pData)); - - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - SetPrivateData(REFGUID guid, UINT DataSize, const void *pData)); - - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - SetPrivateDataInterface(REFGUID guid, const IUnknown *pData)); - - IMPLEMENT_FUNCTION_SERIALISED(virtual D3D_FEATURE_LEVEL STDMETHODCALLTYPE, GetFeatureLevel(void)); - - IMPLEMENT_FUNCTION_SERIALISED(virtual UINT STDMETHODCALLTYPE, GetCreationFlags(void)); - - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, GetDeviceRemovedReason(void)); - - IMPLEMENT_FUNCTION_SERIALISED(virtual void STDMETHODCALLTYPE, - GetImmediateContext(ID3D11DeviceContext **ppImmediateContext)); - - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, SetExceptionMode(UINT RaiseFlags)); - - IMPLEMENT_FUNCTION_SERIALISED(virtual UINT STDMETHODCALLTYPE, GetExceptionMode(void)); + IMPLEMENT_FUNCTION_SERIALISED(virtual UINT STDMETHODCALLTYPE, GetExceptionMode); ////////////////////////////// // implement ID3D11Device1 - IMPLEMENT_FUNCTION_SERIALISED(virtual void STDMETHODCALLTYPE, - GetImmediateContext1(ID3D11DeviceContext1 **ppImmediateContext)); + IMPLEMENT_FUNCTION_SERIALISED(virtual void STDMETHODCALLTYPE, GetImmediateContext1, + ID3D11DeviceContext1 **ppImmediateContext); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateDeferredContext1(UINT ContextFlags, - ID3D11DeviceContext1 **ppDeferredContext)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateDeferredContext1, + UINT ContextFlags, ID3D11DeviceContext1 **ppDeferredContext); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateBlendState1(const D3D11_BLEND_DESC1 *pBlendStateDesc, - ID3D11BlendState1 **ppBlendState)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateBlendState1, + const D3D11_BLEND_DESC1 *pBlendStateDesc, + ID3D11BlendState1 **ppBlendState); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateRasterizerState1(const D3D11_RASTERIZER_DESC1 *pRasterizerDesc, - ID3D11RasterizerState1 **ppRasterizerState)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateRasterizerState1, + const D3D11_RASTERIZER_DESC1 *pRasterizerDesc, + ID3D11RasterizerState1 **ppRasterizerState); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateDeviceContextState(UINT Flags, - const D3D_FEATURE_LEVEL *pFeatureLevels, - UINT FeatureLevels, UINT SDKVersion, - REFIID EmulatedInterface, - D3D_FEATURE_LEVEL *pChosenFeatureLevel, - ID3DDeviceContextState **ppContextState)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateDeviceContextState, + UINT Flags, const D3D_FEATURE_LEVEL *pFeatureLevels, + UINT FeatureLevels, UINT SDKVersion, REFIID EmulatedInterface, + D3D_FEATURE_LEVEL *pChosenFeatureLevel, + ID3DDeviceContextState **ppContextState); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - OpenSharedResource1(HANDLE hResource, REFIID returnedInterface, - void **ppResource)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, OpenSharedResource1, + HANDLE hResource, REFIID returnedInterface, void **ppResource); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - OpenSharedResourceByName(LPCWSTR lpName, DWORD dwDesiredAccess, - REFIID returnedInterface, void **ppResource)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, OpenSharedResourceByName, + LPCWSTR lpName, DWORD dwDesiredAccess, REFIID returnedInterface, + void **ppResource); ////////////////////////////// // implement ID3D11Device2 @@ -817,38 +796,37 @@ public: ////////////////////////////// // implement ID3D11Device3 - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateTexture2D1(const D3D11_TEXTURE2D_DESC1 *pDesc1, - const D3D11_SUBRESOURCE_DATA *pInitialData, - ID3D11Texture2D1 **ppTexture2D)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateTexture2D1, + const D3D11_TEXTURE2D_DESC1 *pDesc1, + const D3D11_SUBRESOURCE_DATA *pInitialData, + ID3D11Texture2D1 **ppTexture2D); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateTexture3D1(const D3D11_TEXTURE3D_DESC1 *pDesc1, - const D3D11_SUBRESOURCE_DATA *pInitialData, - ID3D11Texture3D1 **ppTexture3D)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateTexture3D1, + const D3D11_TEXTURE3D_DESC1 *pDesc1, + const D3D11_SUBRESOURCE_DATA *pInitialData, + ID3D11Texture3D1 **ppTexture3D); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateRasterizerState2(const D3D11_RASTERIZER_DESC2 *pRasterizerDesc, - ID3D11RasterizerState2 **ppRasterizerState)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateRasterizerState2, + const D3D11_RASTERIZER_DESC2 *pRasterizerDesc, + ID3D11RasterizerState2 **ppRasterizerState); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateShaderResourceView1(ID3D11Resource *pResource, - const D3D11_SHADER_RESOURCE_VIEW_DESC1 *pDesc1, - ID3D11ShaderResourceView1 **ppSRView1)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateShaderResourceView1, + ID3D11Resource *pResource, + const D3D11_SHADER_RESOURCE_VIEW_DESC1 *pDesc1, + ID3D11ShaderResourceView1 **ppSRView1); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateUnorderedAccessView1(ID3D11Resource *pResource, - const D3D11_UNORDERED_ACCESS_VIEW_DESC1 *pDesc1, - ID3D11UnorderedAccessView1 **ppUAView1)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateUnorderedAccessView1, + ID3D11Resource *pResource, + const D3D11_UNORDERED_ACCESS_VIEW_DESC1 *pDesc1, + ID3D11UnorderedAccessView1 **ppUAView1); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateRenderTargetView1(ID3D11Resource *pResource, - const D3D11_RENDER_TARGET_VIEW_DESC1 *pDesc1, - ID3D11RenderTargetView1 **ppRTView1)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateRenderTargetView1, + ID3D11Resource *pResource, + const D3D11_RENDER_TARGET_VIEW_DESC1 *pDesc1, + ID3D11RenderTargetView1 **ppRTView1); - IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, - CreateQuery1(const D3D11_QUERY_DESC1 *pQueryDesc1, - ID3D11Query1 **ppQuery1)); + IMPLEMENT_FUNCTION_SERIALISED(virtual HRESULT STDMETHODCALLTYPE, CreateQuery1, + const D3D11_QUERY_DESC1 *pQueryDesc1, ID3D11Query1 **ppQuery1); virtual void STDMETHODCALLTYPE GetImmediateContext3(ID3D11DeviceContext3 **ppImmediateContext); @@ -869,4 +847,4 @@ public: virtual HRESULT STDMETHODCALLTYPE RegisterDeviceRemovedEvent(HANDLE hEvent, DWORD *pdwCookie); virtual void STDMETHODCALLTYPE UnregisterDeviceRemoved(DWORD dwCookie); -}; +}; \ No newline at end of file