From 3daa5df720daa043b6078096bdd29b1b04d1eeab Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 4 Dec 2015 15:12:52 -1000 Subject: [PATCH] Brought Metal renderer in sync --- include/boo/graphicsdev/Metal.hpp | 7 ++++--- lib/graphicsdev/Metal.mm | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/boo/graphicsdev/Metal.hpp b/include/boo/graphicsdev/Metal.hpp index 30ce65f..fec21eb 100644 --- a/include/boo/graphicsdev/Metal.hpp +++ b/include/boo/graphicsdev/Metal.hpp @@ -25,6 +25,9 @@ class MetalDataFactory : public IGraphicsDataFactory struct MetalData* m_deferredData = nullptr; std::unordered_set 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(); }; } diff --git a/lib/graphicsdev/Metal.mm b/lib/graphicsdev/Metal.mm index fb28e2c..0dab6b2 100644 --- a/lib/graphicsdev/Metal.mm +++ b/lib/graphicsdev/Metal.mm @@ -544,6 +544,7 @@ struct MetalCommandQueue : IGraphicsCommandQueue IGraphicsContext* m_parent; NSPtr> m_cmdBuf; NSPtr> 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(m_parent->getDataFactory()); for (MetalData* d : gfxF->m_committedData) @@ -900,12 +916,12 @@ void MetalDataFactory::reset() delete static_cast(m_deferredData); m_deferredData = new struct MetalData(); } -IGraphicsData* MetalDataFactory::commit() +IGraphicsDataToken MetalDataFactory::commit() { MetalData* retval = static_cast(m_deferredData); m_deferredData = new struct MetalData(); m_committedData.insert(retval); - return retval; + return IGraphicsDataToken(this, retval); } void MetalDataFactory::destroyData(IGraphicsData* d) {