diff --git a/include/boo/graphicsdev/Metal.hpp b/include/boo/graphicsdev/Metal.hpp index d1c957d..8af0d15 100644 --- a/include/boo/graphicsdev/Metal.hpp +++ b/include/boo/graphicsdev/Metal.hpp @@ -31,6 +31,7 @@ class MetalDataFactory : public IGraphicsDataFactory void destroyPool(IGraphicsBufferPool*); IGraphicsBufferD* newPoolBuffer(IGraphicsBufferPool* pool, BufferUse use, size_t stride, size_t count); + void deletePoolBuffer(IGraphicsBufferPool* p, IGraphicsBufferD* buf); public: MetalDataFactory(IGraphicsContext* parent, MetalContext* ctx, uint32_t sampleCount); ~MetalDataFactory() {} diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 9795698..8ddec18 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -739,7 +739,7 @@ IGraphicsBufferD* GLDataFactory::newPoolBuffer(IGraphicsBufferPool* p, BufferUse { GLPool* pool = static_cast(p); GLGraphicsBufferD* retval = new GLGraphicsBufferD(use, stride * count); - pool->m_DBufs.emplace(std::make_pair(retval, retval)); + pool->m_DBufs.emplace(std::make_pair(retval, std::unique_ptr(retval))); return retval; } diff --git a/lib/graphicsdev/Metal.mm b/lib/graphicsdev/Metal.mm index 49e845a..e5e27e2 100644 --- a/lib/graphicsdev/Metal.mm +++ b/lib/graphicsdev/Metal.mm @@ -33,7 +33,7 @@ struct MetalData : IGraphicsData struct MetalPool : IGraphicsBufferPool { - std::vector> m_DBufs; + std::unordered_map> m_DBufs; }; #define MTL_STATIC MTLResourceCPUCacheModeWriteCombined|MTLResourceStorageModeShared @@ -888,8 +888,8 @@ struct MetalCommandQueue : IGraphicsCommandQueue } for (MetalPool* p : gfxF->m_committedPools) { - for (std::unique_ptr& b : p->m_DBufs) - b->update(m_fillBuf); + for (auto& b : p->m_DBufs) + b.second->update(m_fillBuf); } datalk.unlock(); @@ -1184,10 +1184,16 @@ IGraphicsBufferD* MetalDataFactory::newPoolBuffer(IGraphicsBufferPool* p, Buffer MetalPool* pool = static_cast(p); MetalCommandQueue* q = static_cast(m_parent->getCommandQueue()); MetalGraphicsBufferD* retval = new MetalGraphicsBufferD(q, use, m_ctx, stride, count); - pool->m_DBufs.emplace_back(retval); + pool->m_DBufs.emplace(std::make_pair(retval, std::unique_ptr(retval))); return retval; } +void MetalDataFactory::deletePoolBuffer(IGraphicsBufferPool* p, IGraphicsBufferD* buf) +{ + MetalPool* pool = static_cast(p); + pool->m_DBufs.erase(static_cast(buf)); +} + IGraphicsCommandQueue* _NewMetalCommandQueue(MetalContext* ctx, IWindow* parentWindow, IGraphicsContext* parent) {