This commit is contained in:
Jack Andersen 2015-12-05 15:26:02 -10:00
commit b579e20bc6
5 changed files with 85 additions and 40 deletions

View File

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

View File

@ -25,6 +25,9 @@ class MetalDataFactory : public IGraphicsDataFactory
struct MetalData* m_deferredData = nullptr;
std::unordered_set<struct MetalData*> m_committedData;
struct MetalContext* m_ctx;
void destroyData(IGraphicsData*);
void destroyAllData();
public:
MetalDataFactory(IGraphicsContext* parent, MetalContext* ctx);
~MetalDataFactory() {}
@ -61,9 +64,7 @@ public:
size_t texCount, ITexture** texs);
void reset();
IGraphicsData* commit();
void destroyData(IGraphicsData*);
void destroyAllData();
IGraphicsDataToken commit();
};
}

View File

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

View File

@ -888,6 +888,9 @@ struct D3D12CommandQueue : IGraphicsCommandQueue
HANDLE m_dynamicBufFenceHandle;
bool m_dynamicNeedsReset = false;
HANDLE m_renderFenceHandle;
bool m_running = true;
size_t m_fillBuf = 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->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, ctx->m_qalloc[0].Get(),
nullptr, __uuidof(ID3D12GraphicsCommandList), &m_cmdList));
m_renderFenceHandle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
m_cmdList->SetGraphicsRootSignature(m_ctx->m_rs.Get());
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));
}
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)
{
D3D12ShaderDataBinding* cbind = static_cast<D3D12ShaderDataBinding*>(binding);
@ -1200,6 +1219,20 @@ class D3D12DataFactory : public ID3DDataFactory
D3D12Data* m_deferredData = nullptr;
struct D3D12Context* m_ctx;
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:
D3D12DataFactory(IGraphicsContext* parent, D3D12Context* 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(),
rsOutBlob->GetBufferSize(), __uuidof(ID3D12RootSignature), &ctx->m_rs));
}
~D3D12DataFactory() = default;
~D3D12DataFactory() {destroyAllData();}
Platform platform() const {return Platform::D3D12;}
const SystemChar* platformName() const {return _S("D3D12");}
@ -1360,7 +1393,7 @@ public:
m_deferredData = new struct D3D12Data();
}
IGraphicsData* commit()
IGraphicsDataToken commit()
{
D3D12Data* retval = static_cast<D3D12Data*>(m_deferredData);
@ -1461,26 +1494,15 @@ public:
/* All set! */
m_deferredData = new struct D3D12Data();
m_committedData.insert(retval);
return 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();
return IGraphicsDataToken(this, retval);
}
};
void D3D12CommandQueue::execute()
{
if (!m_running)
return;
/* Stage dynamic uploads */
D3D12DataFactory* gfxF = static_cast<D3D12DataFactory*>(m_parent->getDataFactory());
for (D3D12Data* d : gfxF->m_committedData)

View File

@ -544,6 +544,7 @@ struct MetalCommandQueue : IGraphicsCommandQueue
IGraphicsContext* m_parent;
NSPtr<id<MTLCommandBuffer>> m_cmdBuf;
NSPtr<id<MTLRenderCommandEncoder>> m_enc;
bool m_running = true;
size_t m_fillBuf = 0;
size_t m_drawBuf = 0;
@ -557,6 +558,18 @@ struct MetalCommandQueue : IGraphicsCommandQueue
}
}
void stopRenderer()
{
m_running = false;
if (m_inProgress)
[m_cmdBuf.get() waitUntilCompleted];
}
~MetalCommandQueue()
{
if (m_running) stopRenderer();
}
MetalShaderDataBinding* m_boundData = nullptr;
void setShaderDataBinding(IShaderDataBinding* binding)
{
@ -686,6 +699,9 @@ struct MetalCommandQueue : IGraphicsCommandQueue
bool m_inProgress = false;
void execute()
{
if (!m_running)
return;
/* Update dynamic data here */
MetalDataFactory* gfxF = static_cast<MetalDataFactory*>(m_parent->getDataFactory());
for (MetalData* d : gfxF->m_committedData)
@ -900,12 +916,12 @@ void MetalDataFactory::reset()
delete static_cast<MetalData*>(m_deferredData);
m_deferredData = new struct MetalData();
}
IGraphicsData* MetalDataFactory::commit()
IGraphicsDataToken MetalDataFactory::commit()
{
MetalData* retval = static_cast<MetalData*>(m_deferredData);
m_deferredData = new struct MetalData();
m_committedData.insert(retval);
return retval;
return IGraphicsDataToken(this, retval);
}
void MetalDataFactory::destroyData(IGraphicsData* d)
{