Brought Metal renderer in sync

This commit is contained in:
Jack Andersen 2015-12-04 15:12:52 -10:00
parent db40c2bff0
commit 3daa5df720
2 changed files with 22 additions and 5 deletions

View File

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

View File

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