From 7153168a2cdb43062394fa64bb365828c25dde57 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 17 Dec 2015 18:55:06 -1000 Subject: [PATCH] Added debug assert to D3D --- lib/graphicsdev/D3D11.cpp | 22 +++++++++++++++++++--- lib/graphicsdev/D3D12.cpp | 20 +++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/graphicsdev/D3D11.cpp b/lib/graphicsdev/D3D11.cpp index e306585..9bf7050 100644 --- a/lib/graphicsdev/D3D11.cpp +++ b/lib/graphicsdev/D3D11.cpp @@ -485,6 +485,12 @@ struct D3D11ShaderDataBinding : IShaderDataBinding std::unique_ptr m_ubufs; size_t m_texCount; std::unique_ptr m_texs; + +#ifndef NDEBUG + /* Debugging aids */ + bool m_committed = false; +#endif + D3D11ShaderDataBinding(D3D11Context* ctx, IShaderPipeline* pipeline, IGraphicsBuffer* vbuf, IGraphicsBuffer* instVbuf, IGraphicsBuffer* ibuf, @@ -507,6 +513,12 @@ struct D3D11ShaderDataBinding : IShaderDataBinding void bind(ID3D11DeviceContext* ctx, int b) { +#ifndef NDEBUG + if (!m_committed) + Log.report(LogVisor::FatalError, + "attempted to use uncommitted D3D11ShaderDataBinding"); +#endif + m_pipeline->bind(ctx); ID3D11Buffer* bufs[2] = {}; @@ -1114,14 +1126,18 @@ public: m_deferredData = nullptr; } - IGraphicsDataToken commit() + GraphicsDataToken commit() { if (!m_deferredData) - return IGraphicsDataToken(this, nullptr); + return GraphicsDataToken(this, nullptr); D3D11Data* retval = m_deferredData; +#ifndef NDEBUG + for (std::unique_ptr& b : retval->m_SBinds) + b->m_committed = true; +#endif m_deferredData = nullptr; m_committedData.insert(retval); - return IGraphicsDataToken(this, retval); + return GraphicsDataToken(this, retval); } }; diff --git a/lib/graphicsdev/D3D12.cpp b/lib/graphicsdev/D3D12.cpp index cfa8b51..faccfab 100644 --- a/lib/graphicsdev/D3D12.cpp +++ b/lib/graphicsdev/D3D12.cpp @@ -809,6 +809,12 @@ struct D3D12ShaderDataBinding : IShaderDataBinding std::unique_ptr m_texs; D3D12_VERTEX_BUFFER_VIEW m_vboView[2][2] = {{},{}}; D3D12_INDEX_BUFFER_VIEW m_iboView[2]; + +#ifndef NDEBUG + /* Debugging aids */ + bool m_committed = false; +#endif + D3D12ShaderDataBinding(D3D12Context* ctx, IShaderPipeline* pipeline, IGraphicsBuffer* vbuf, IGraphicsBuffer* instVbuf, IGraphicsBuffer* ibuf, @@ -872,10 +878,18 @@ struct D3D12ShaderDataBinding : IShaderDataBinding handle.Offset(1, incSz); } } + + m_committed = true; } void bind(ID3D12GraphicsCommandList* list, int b) { +#ifndef NDEBUG + if (!m_committed) + Log.report(LogVisor::FatalError, + "attempted to use uncommitted D3D12ShaderDataBinding"); +#endif + ID3D12DescriptorHeap* heap[] = {m_descHeap[b].Get()}; list->SetDescriptorHeaps(1, heap); list->SetGraphicsRootDescriptorTable(0, m_descHeap[b]->GetGPUDescriptorHandleForHeapStart()); @@ -1451,10 +1465,10 @@ public: m_deferredData = nullptr; } - IGraphicsDataToken commit() + GraphicsDataToken commit() { if (!m_deferredData) - return IGraphicsDataToken(this, nullptr); + return GraphicsDataToken(this, nullptr); D3D12Data* retval = static_cast(m_deferredData); @@ -1555,7 +1569,7 @@ public: /* All set! */ m_deferredData = nullptr; m_committedData.insert(retval); - return IGraphicsDataToken(this, retval); + return GraphicsDataToken(this, retval); } };