Brought D3D11/12 in sync

This commit is contained in:
Jack Andersen 2015-12-04 15:03:44 -10:00
parent d145e15ecb
commit db40c2bff0
3 changed files with 63 additions and 35 deletions

View File

@ -22,6 +22,7 @@ namespace boo
class ID3DDataFactory : public IGraphicsDataFactory class ID3DDataFactory : public IGraphicsDataFactory
{ {
public: public:
virtual ~ID3DDataFactory() {}
bool bindingNeedsVertexFormat() const {return false;} bool bindingNeedsVertexFormat() const {return false;}
virtual IShaderPipeline* newShaderPipeline(const char* vertSource, const char* fragSource, virtual IShaderPipeline* newShaderPipeline(const char* vertSource, const char* fragSource,
ComPtr<ID3DBlob>& vertBlobOut, ComPtr<ID3DBlob>& fragBlobOut, ComPtr<ID3DBlob>& vertBlobOut, ComPtr<ID3DBlob>& fragBlobOut,

View File

@ -705,13 +705,18 @@ struct D3D11CommandQueue : IGraphicsCommandQueue
ThrowIfFailed(ctx->m_dev->CreateDeferredContext1(0, &m_dynamicCtx)); ThrowIfFailed(ctx->m_dev->CreateDeferredContext1(0, &m_dynamicCtx));
} }
~D3D11CommandQueue() void stopRenderer()
{ {
m_running = false; m_running = false;
m_cv.notify_one(); m_cv.notify_one();
m_thr.join(); m_thr.join();
} }
~D3D11CommandQueue()
{
if (m_running) stopRenderer();
}
void setShaderDataBinding(IShaderDataBinding* binding) void setShaderDataBinding(IShaderDataBinding* binding)
{ {
D3D11ShaderDataBinding* cbind = static_cast<D3D11ShaderDataBinding*>(binding); D3D11ShaderDataBinding* cbind = static_cast<D3D11ShaderDataBinding*>(binding);
@ -873,11 +878,25 @@ class D3D11DataFactory : public ID3DDataFactory
D3D11Data* m_deferredData = nullptr; D3D11Data* m_deferredData = nullptr;
struct D3D11Context* m_ctx; struct D3D11Context* m_ctx;
std::unordered_set<D3D11Data*> m_committedData; std::unordered_set<D3D11Data*> m_committedData;
void destroyData(IGraphicsData* d)
{
D3D11Data* data = static_cast<D3D11Data*>(d);
m_committedData.erase(data);
delete data;
}
void destroyAllData()
{
for (IGraphicsData* data : m_committedData)
delete static_cast<D3D11Data*>(data);
m_committedData.clear();
}
public: public:
D3D11DataFactory(IGraphicsContext* parent, D3D11Context* ctx) D3D11DataFactory(IGraphicsContext* parent, D3D11Context* ctx)
: m_parent(parent), m_deferredData(new struct D3D11Data()), m_ctx(ctx) : m_parent(parent), m_deferredData(new struct D3D11Data()), m_ctx(ctx)
{} {}
~D3D11DataFactory() = default; ~D3D11DataFactory() {destroyAllData();}
Platform platform() const {return Platform::D3D11;} Platform platform() const {return Platform::D3D11;}
const SystemChar* platformName() const {return _S("D3D11");} const SystemChar* platformName() const {return _S("D3D11");}
@ -1014,26 +1033,12 @@ public:
m_deferredData = new struct D3D11Data(); m_deferredData = new struct D3D11Data();
} }
IGraphicsData* commit() IGraphicsDataToken commit()
{ {
D3D11Data* retval = m_deferredData; D3D11Data* retval = m_deferredData;
m_deferredData = new struct D3D11Data(); m_deferredData = new struct D3D11Data();
m_committedData.insert(retval); m_committedData.insert(retval);
return retval; return IGraphicsDataToken(this, retval);
}
void destroyData(IGraphicsData* d)
{
D3D11Data* data = static_cast<D3D11Data*>(d);
m_committedData.erase(data);
delete data;
}
void destroyAllData()
{
for (IGraphicsData* data : m_committedData)
delete static_cast<D3D11Data*>(data);
m_committedData.clear();
} }
}; };

View File

@ -888,6 +888,9 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
HANDLE m_dynamicBufFenceHandle; HANDLE m_dynamicBufFenceHandle;
bool m_dynamicNeedsReset = false; bool m_dynamicNeedsReset = false;
HANDLE m_renderFenceHandle;
bool m_running = true;
size_t m_fillBuf = 0; size_t m_fillBuf = 0;
size_t m_drawBuf = 0; size_t m_drawBuf = 0;
@ -940,6 +943,7 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
ThrowIfFailed(ctx->m_dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &m_fence)); ThrowIfFailed(ctx->m_dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &m_fence));
ThrowIfFailed(ctx->m_dev->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, ctx->m_qalloc[0].Get(), ThrowIfFailed(ctx->m_dev->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, ctx->m_qalloc[0].Get(),
nullptr, __uuidof(ID3D12GraphicsCommandList), &m_cmdList)); nullptr, __uuidof(ID3D12GraphicsCommandList), &m_cmdList));
m_renderFenceHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
m_cmdList->SetGraphicsRootSignature(m_ctx->m_rs.Get()); m_cmdList->SetGraphicsRootSignature(m_ctx->m_rs.Get());
ThrowIfFailed(ctx->m_dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &m_dynamicBufFence)); ThrowIfFailed(ctx->m_dev->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(ID3D12Fence), &m_dynamicBufFence));
@ -952,6 +956,21 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
nullptr, __uuidof(ID3D12GraphicsCommandList), &m_dynamicCmdList)); nullptr, __uuidof(ID3D12GraphicsCommandList), &m_dynamicCmdList));
} }
void stopRenderer()
{
m_running = false;
if (m_fence->GetCompletedValue() < m_submittedFenceVal)
{
ThrowIfFailed(m_fence->SetEventOnCompletion(m_submittedFenceVal, m_renderFenceHandle));
WaitForSingleObject(m_renderFenceHandle, INFINITE);
}
}
~D3D12CommandQueue()
{
if (m_running) stopRenderer();
}
void setShaderDataBinding(IShaderDataBinding* binding) void setShaderDataBinding(IShaderDataBinding* binding)
{ {
D3D12ShaderDataBinding* cbind = static_cast<D3D12ShaderDataBinding*>(binding); D3D12ShaderDataBinding* cbind = static_cast<D3D12ShaderDataBinding*>(binding);
@ -1200,6 +1219,20 @@ class D3D12DataFactory : public ID3DDataFactory
D3D12Data* m_deferredData = nullptr; D3D12Data* m_deferredData = nullptr;
struct D3D12Context* m_ctx; struct D3D12Context* m_ctx;
std::unordered_set<D3D12Data*> m_committedData; std::unordered_set<D3D12Data*> m_committedData;
void destroyData(IGraphicsData* d)
{
D3D12Data* data = static_cast<D3D12Data*>(d);
m_committedData.erase(data);
delete data;
}
void destroyAllData()
{
for (IGraphicsData* data : m_committedData)
delete static_cast<D3D12Data*>(data);
m_committedData.clear();
}
public: public:
D3D12DataFactory(IGraphicsContext* parent, D3D12Context* ctx) D3D12DataFactory(IGraphicsContext* parent, D3D12Context* ctx)
: m_parent(parent), m_deferredData(new struct D3D12Data()), m_ctx(ctx) : m_parent(parent), m_deferredData(new struct D3D12Data()), m_ctx(ctx)
@ -1222,7 +1255,7 @@ public:
ThrowIfFailed(ctx->m_dev->CreateRootSignature(0, rsOutBlob->GetBufferPointer(), ThrowIfFailed(ctx->m_dev->CreateRootSignature(0, rsOutBlob->GetBufferPointer(),
rsOutBlob->GetBufferSize(), __uuidof(ID3D12RootSignature), &ctx->m_rs)); rsOutBlob->GetBufferSize(), __uuidof(ID3D12RootSignature), &ctx->m_rs));
} }
~D3D12DataFactory() = default; ~D3D12DataFactory() {destroyAllData();}
Platform platform() const {return Platform::D3D12;} Platform platform() const {return Platform::D3D12;}
const SystemChar* platformName() const {return _S("D3D12");} const SystemChar* platformName() const {return _S("D3D12");}
@ -1360,7 +1393,7 @@ public:
m_deferredData = new struct D3D12Data(); m_deferredData = new struct D3D12Data();
} }
IGraphicsData* commit() IGraphicsDataToken commit()
{ {
D3D12Data* retval = static_cast<D3D12Data*>(m_deferredData); D3D12Data* retval = static_cast<D3D12Data*>(m_deferredData);
@ -1461,26 +1494,15 @@ public:
/* All set! */ /* All set! */
m_deferredData = new struct D3D12Data(); m_deferredData = new struct D3D12Data();
m_committedData.insert(retval); m_committedData.insert(retval);
return retval; return IGraphicsDataToken(this, retval);
}
void destroyData(IGraphicsData* d)
{
D3D12Data* data = static_cast<D3D12Data*>(d);
m_committedData.erase(data);
delete data;
}
void destroyAllData()
{
for (IGraphicsData* data : m_committedData)
delete static_cast<D3D12Data*>(data);
m_committedData.clear();
} }
}; };
void D3D12CommandQueue::execute() void D3D12CommandQueue::execute()
{ {
if (!m_running)
return;
/* Stage dynamic uploads */ /* Stage dynamic uploads */
D3D12DataFactory* gfxF = static_cast<D3D12DataFactory*>(m_parent->getDataFactory()); D3D12DataFactory* gfxF = static_cast<D3D12DataFactory*>(m_parent->getDataFactory());
for (D3D12Data* d : gfxF->m_committedData) for (D3D12Data* d : gfxF->m_committedData)