Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2012-01-26 19:03:06 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:32:37 +0300
commitf0dccc39cc5ea8cbe2eefa7f281c0c7280514af7 (patch)
tree580829d9aa01854c48187e5e83f1c3c72210f15b
parent482df7a7c7b2885abca03ff697d8b083f0181678 (diff)
supporting on-demand resource allocation.
-rw-r--r--base/resource_pool.cpp10
-rw-r--r--base/resource_pool.hpp87
-rw-r--r--map/basic_render_policy.cpp20
-rw-r--r--map/render_policy_mt.cpp42
-rw-r--r--map/render_policy_st.cpp28
-rw-r--r--map/test_render_policy.cpp20
-rw-r--r--map/tiling_render_policy_mt.cpp56
-rw-r--r--map/tiling_render_policy_st.cpp25
-rw-r--r--qt_tstfrm/tstwidgets.cpp24
-rw-r--r--yg/resource_manager.cpp71
-rw-r--r--yg/resource_manager.hpp55
11 files changed, 328 insertions, 110 deletions
diff --git a/base/resource_pool.cpp b/base/resource_pool.cpp
index 95eae9cab5..90220e667b 100644
--- a/base/resource_pool.cpp
+++ b/base/resource_pool.cpp
@@ -2,8 +2,8 @@
#include "resource_pool.hpp"
-BasePoolElemFactory::BasePoolElemFactory(char const * resName, size_t elemSize)
- : m_resName(resName), m_elemSize(elemSize)
+BasePoolElemFactory::BasePoolElemFactory(char const * resName, size_t elemSize, size_t batchSize)
+ : m_resName(resName), m_elemSize(elemSize), m_batchSize(batchSize)
{}
char const * BasePoolElemFactory::ResName() const
@@ -15,3 +15,9 @@ size_t BasePoolElemFactory::ElemSize() const
{
return m_elemSize;
}
+
+size_t BasePoolElemFactory::BatchSize() const
+{
+ return m_batchSize;
+}
+
diff --git a/base/resource_pool.hpp b/base/resource_pool.hpp
index 080f07d6cc..75ce3c272f 100644
--- a/base/resource_pool.hpp
+++ b/base/resource_pool.hpp
@@ -9,8 +9,11 @@ struct BasePoolElemFactory
{
string m_resName;
size_t m_elemSize;
- BasePoolElemFactory(char const * resName, size_t elemSize);
+ size_t m_batchSize;
+ BasePoolElemFactory(char const * resName, size_t elemSize, size_t batchSize);
+
+ size_t BatchSize() const;
char const * ResName() const;
size_t ElemSize() const;
};
@@ -31,27 +34,40 @@ struct BasePoolTraits
m_pool.SetName(factory.ResName());
}
- void Free(TElem const & elem)
+ virtual ~BasePoolTraits()
+ {}
+
+ virtual void Init()
+ {
+ Free(Reserve());
+ }
+
+ virtual void Free(TElem const & elem)
{
m_pool.PushBack(elem);
}
- size_t Size() const
+ virtual TElem const Reserve()
+ {
+ return m_pool.Front(true);
+ }
+
+ virtual size_t Size() const
{
return m_pool.Size();
}
- void Cancel()
+ virtual void Cancel()
{
m_pool.Cancel();
}
- bool IsCancelled() const
+ virtual bool IsCancelled() const
{
return m_pool.IsCancelled();
}
- void UpdateState()
+ virtual void UpdateState()
{
}
};
@@ -136,42 +152,73 @@ struct FixedSizePoolTraits : TBase
base_t::m_pool.PushBack(base_t::m_factory.Create());
}
- return base_t::m_pool.Front(true);
+ return base_t::Reserve();
}
};
/// This traits allocates resources on demand.
template <typename TElemFactory, typename TBase>
-struct AllocateOnDemandPoolTraits : TBase
+struct AllocateOnDemandMultiThreadedPoolTraits : TBase
{
typedef TBase base_t;
typedef typename base_t::elem_t elem_t;
+ typedef AllocateOnDemandMultiThreadedPoolTraits<TElemFactory, base_t> self_t;
size_t m_poolSize;
- AllocateOnDemandPoolTraits(TElemFactory const & factory, size_t )
+ AllocateOnDemandMultiThreadedPoolTraits(TElemFactory const & factory, size_t )
: base_t(factory),
m_poolSize(0)
{}
- void ReserveImpl(list<elem_t> & l, elem_t & elem)
+ void AllocateIfNeeded(list<elem_t> & l)
{
if (l.empty())
{
- m_poolSize += base_t::m_factory.ElemSize();
- LOG(LDEBUG, ("allocating ", base_t::m_factory.ElemSize(), "bytes for ", base_t::m_factory.ResName(), " on-demand, poolSize=", m_poolSize));
- l.push_back(base_t::m_factory.Create());
+ m_poolSize += base_t::m_factory.ElemSize() * base_t::m_factory.BatchSize();
+ LOG(LDEBUG, ("allocating ", base_t::m_factory.ElemSize(), "bytes for ", base_t::m_factory.ResName(), " on-demand, poolSize=", m_poolSize / base_t::m_factory.ElemSize()));
+ for (unsigned i = 0; i < base_t::m_factory.BatchSize(); ++i)
+ l.push_back(base_t::m_factory.Create());
}
+ }
- elem = l.back();
+ elem_t const Reserve()
+ {
+ base_t::m_pool.ProcessList(bind(&self_t::AllocateIfNeeded, this, _1));
+ return base_t::Reserve();
+ }
+};
- l.pop_back();
+template <typename TElemFactory, typename TBase>
+struct AllocateOnDemandSingleThreadedPoolTraits : TBase
+{
+ typedef TBase base_t;
+ typedef typename TBase::elem_t elem_t;
+ typedef AllocateOnDemandSingleThreadedPoolTraits<TElemFactory, TBase> self_t;
+
+ size_t m_poolSize;
+ AllocateOnDemandSingleThreadedPoolTraits(TElemFactory const & factory, size_t )
+ : base_t(factory),
+ m_poolSize(0)
+ {}
+
+ void Init()
+ {}
+
+ void AllocateIfNeeded(list<elem_t> & l)
+ {
+ if (l.empty())
+ {
+ m_poolSize += base_t::m_factory.ElemSize() * base_t::m_factory.BatchSize();
+ LOG(LDEBUG, ("allocating", base_t::m_factory.BatchSize(), "elements for ", base_t::m_factory.ResName(), "on-demand, poolSize=", m_poolSize / base_t::m_factory.ElemSize()));
+ for (unsigned i = 0; i < base_t::m_factory.BatchSize(); ++i)
+ l.push_back(base_t::m_factory.Create());
+ }
}
- elem_t const Reserve()
+ void UpdateState()
{
- elem_t elem;
- base_t::m_pool.ProcessList(bind(&AllocateOnDemandPoolTraits<elem_t, TElemFactory>::ReserveImpl, this, _1, ref(elem)));
- return elem;
+ base_t::UpdateState();
+ base_t::m_pool.ProcessList(bind(&self_t::AllocateIfNeeded, this, _1));
}
};
@@ -210,7 +257,7 @@ public:
{
/// quick trick to perform lazy initialization
/// on the same thread the pool was created.
- Free(Reserve());
+ m_traits->Init();
}
elem_t const Reserve()
diff --git a/map/basic_render_policy.cpp b/map/basic_render_policy.cpp
index 610bf0dd07..186b8c4aa9 100644
--- a/map/basic_render_policy.cpp
+++ b/map/basic_render_policy.cpp
@@ -29,7 +29,9 @@ BasicRenderPolicy::BasicRenderPolicy(VideoTimer * videoTimer,
false,
true,
1,
- "primaryStorage");
+ "primaryStorage",
+ false,
+ false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(5000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -39,7 +41,9 @@ BasicRenderPolicy::BasicRenderPolicy(VideoTimer * videoTimer,
false,
true,
1,
- "smallStorage");
+ "smallStorage",
+ false,
+ false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -49,7 +53,9 @@ BasicRenderPolicy::BasicRenderPolicy(VideoTimer * videoTimer,
true,
true,
1,
- "blitStorage");
+ "blitStorage",
+ false,
+ false);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
@@ -59,7 +65,9 @@ BasicRenderPolicy::BasicRenderPolicy(VideoTimer * videoTimer,
true,
true,
1,
- "primaryTexture");
+ "primaryTexture",
+ false,
+ false);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
@@ -69,7 +77,9 @@ BasicRenderPolicy::BasicRenderPolicy(VideoTimer * videoTimer,
true,
true,
1,
- "fontTexture");
+ "fontTexture",
+ false,
+ false);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
diff --git a/map/render_policy_mt.cpp b/map/render_policy_mt.cpp
index 9456220f29..998e17b081 100644
--- a/map/render_policy_mt.cpp
+++ b/map/render_policy_mt.cpp
@@ -30,7 +30,9 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
false,
true,
10,
- "primaryStorage");
+ "primaryStorage",
+ false,
+ false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -40,7 +42,9 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
false,
true,
5,
- "smallStorage");
+ "smallStorage",
+ false,
+ false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -50,7 +54,9 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
true,
true,
1,
- "blitStorage");
+ "blitStorage",
+ false,
+ false);
rmp.m_guiThreadStoragesParams = yg::ResourceManager::StoragePoolParams(300 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -60,7 +66,9 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
true,
true,
1,
- "guiThreadStorage");
+ "guiThreadStorage",
+ false,
+ false);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
@@ -70,7 +78,9 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
true,
true,
1,
- "primaryTexture");
+ "primaryTexture",
+ false,
+ false);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
@@ -80,17 +90,21 @@ RenderPolicyMT::RenderPolicyMT(VideoTimer * videoTimer,
true,
true,
1,
- "fontTexture");
+ "fontTexture",
+ false,
+ false);
rmp.m_guiThreadTexturesParams = yg::ResourceManager::TexturePoolParams(256,
- 128,
- 4,
- rmp.m_texFormat,
- true,
- true,
- true,
- 1,
- "guiThreadTexture");
+ 128,
+ 4,
+ rmp.m_texFormat,
+ true,
+ true,
+ true,
+ 1,
+ "guiThreadTexture",
+ false,
+ false);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
diff --git a/map/render_policy_st.cpp b/map/render_policy_st.cpp
index 11c46bc43f..4206df20f3 100644
--- a/map/render_policy_st.cpp
+++ b/map/render_policy_st.cpp
@@ -31,7 +31,9 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
true,
false,
2,
- "primaryStorage");
+ "primaryStorage",
+ false,
+ false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(2000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -41,7 +43,9 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
true,
false,
1,
- "smallStorage");
+ "smallStorage",
+ false,
+ false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -51,7 +55,9 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
true,
true,
1,
- "blitStorage");
+ "blitStorage",
+ false,
+ false);
rmp.m_guiThreadStoragesParams = yg::ResourceManager::StoragePoolParams(300 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -61,7 +67,9 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
true,
true,
1,
- "guiThreadStorage");
+ "guiThreadStorage",
+ false,
+ false);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
@@ -71,7 +79,9 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
true,
true,
1,
- "primaryTexture");
+ "primaryTexture",
+ false,
+ false);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
@@ -81,7 +91,9 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
true,
true,
1,
- "fontTextures");
+ "fontTextures",
+ false,
+ false);
rmp.m_guiThreadTexturesParams = yg::ResourceManager::TexturePoolParams(256,
128,
@@ -91,7 +103,9 @@ RenderPolicyST::RenderPolicyST(VideoTimer * videoTimer,
true,
true,
1,
- "guiThreadTexture");
+ "guiThreadTexture",
+ false,
+ false);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
diff --git a/map/test_render_policy.cpp b/map/test_render_policy.cpp
index 99a693b581..927b13f3d0 100644
--- a/map/test_render_policy.cpp
+++ b/map/test_render_policy.cpp
@@ -26,7 +26,9 @@ TestRenderPolicy::TestRenderPolicy(VideoTimer * videoTimer,
false,
true,
1,
- "primaryStorage");
+ "primaryStorage",
+ false,
+ false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(5000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -36,7 +38,9 @@ TestRenderPolicy::TestRenderPolicy(VideoTimer * videoTimer,
false,
true,
1,
- "smallStorage");
+ "smallStorage",
+ false,
+ false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -46,7 +50,9 @@ TestRenderPolicy::TestRenderPolicy(VideoTimer * videoTimer,
true,
true,
1,
- "blitStorage");
+ "blitStorage",
+ false,
+ false);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
@@ -56,7 +62,9 @@ TestRenderPolicy::TestRenderPolicy(VideoTimer * videoTimer,
true,
true,
1,
- "primaryTexture");
+ "primaryTexture",
+ false,
+ false);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
@@ -66,7 +74,9 @@ TestRenderPolicy::TestRenderPolicy(VideoTimer * videoTimer,
true,
true,
1,
- "fontTexture");
+ "fontTexture",
+ false,
+ false);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
diff --git a/map/tiling_render_policy_mt.cpp b/map/tiling_render_policy_mt.cpp
index 6d291c2111..dad8e2d1fe 100644
--- a/map/tiling_render_policy_mt.cpp
+++ b/map/tiling_render_policy_mt.cpp
@@ -30,7 +30,9 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer,
true,
true,
1,
- "primaryTexture");
+ "primaryTexture",
+ false,
+ false);
rmp.m_primaryStoragesParams = yg::ResourceManager::StoragePoolParams(50000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -40,7 +42,9 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer,
false,
true,
1,
- "primaryStorage");
+ "primaryStorage",
+ false,
+ false);
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -50,7 +54,9 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer,
true,
true,
1,
- "multiBlitStorage");
+ "multiBlitStorage",
+ false,
+ false);
rmp.m_renderTargetTexturesParams = yg::ResourceManager::TexturePoolParams(GetPlatform().TileSize(),
GetPlatform().TileSize(),
@@ -60,7 +66,9 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer,
true,
false,
5,
- "renderTargetTexture");
+ "renderTargetTexture",
+ false,
+ false);
rmp.m_styleCacheTexturesParams = yg::ResourceManager::TexturePoolParams(512,
1024,
@@ -70,27 +78,33 @@ TilingRenderPolicyMT::TilingRenderPolicyMT(VideoTimer * videoTimer,
true,
true,
1,
- "styleCacheTexture");
+ "styleCacheTexture",
+ false,
+ false);
rmp.m_guiThreadStoragesParams = yg::ResourceManager::StoragePoolParams(5000 * sizeof(yg::gl::Vertex),
- sizeof(yg::gl::Vertex),
- 10000 * sizeof(unsigned short),
- sizeof(unsigned short),
- 10,
- true,
- true,
- 1,
- "guiThreadStorage");
+ sizeof(yg::gl::Vertex),
+ 10000 * sizeof(unsigned short),
+ sizeof(unsigned short),
+ 10,
+ true,
+ true,
+ 1,
+ "guiThreadStorage",
+ false,
+ false);
rmp.m_guiThreadTexturesParams = yg::ResourceManager::TexturePoolParams(256,
- 128,
- 4,
- rmp.m_texFormat,
- true,
- true,
- true,
- 1,
- "guiThreadTexture");
+ 128,
+ 4,
+ rmp.m_texFormat,
+ true,
+ true,
+ true,
+ 1,
+ "guiThreadTexture",
+ false,
+ false);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
diff --git a/map/tiling_render_policy_st.cpp b/map/tiling_render_policy_st.cpp
index 6a48a9675f..ff124b0008 100644
--- a/map/tiling_render_policy_st.cpp
+++ b/map/tiling_render_policy_st.cpp
@@ -41,24 +41,26 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
- 4 * GetPlatform().CpuCores(),
+ 1,
rmp.m_texFormat,
true,
true,
true,
1,
"primaryTexture",
+ true,
true);
rmp.m_primaryStoragesParams = yg::ResourceManager::StoragePoolParams(5000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
10000 * sizeof(unsigned short),
sizeof(unsigned short),
- 40 * GetPlatform().CpuCores(),
+ 10,
true,
true,
2,
"primaryStorage",
+ true,
true);
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(1500 * sizeof(yg::gl::Vertex),
@@ -69,7 +71,9 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
true,
true,
1,
- "multiBlitStorage");
+ "multiBlitStorage",
+ false,
+ false);
rmp.m_renderTargetTexturesParams = yg::ResourceManager::TexturePoolParams(GetPlatform().TileSize(),
GetPlatform().TileSize(),
@@ -79,7 +83,9 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
true,
false,
4,
- "renderTargetTexture");
+ "renderTargetTexture",
+ false,
+ false);
rmp.m_styleCacheTexturesParams = yg::ResourceManager::TexturePoolParams(1024,
512,
@@ -89,7 +95,9 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
true,
true,
1,
- "styleCacheTexture");
+ "styleCacheTexture",
+ false,
+ false);
rmp.m_guiThreadStoragesParams = yg::ResourceManager::StoragePoolParams(2000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -100,7 +108,8 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
true,
1,
"guiThreadStorage",
- true);
+ true,
+ false);
rmp.m_guiThreadTexturesParams = yg::ResourceManager::TexturePoolParams(256,
128,
@@ -110,7 +119,9 @@ TilingRenderPolicyST::TilingRenderPolicyST(VideoTimer * videoTimer,
true,
true,
1,
- "guiThreadTexture");
+ "guiThreadTexture",
+ false,
+ false);
/* bool * debuggingFlags = new bool[GetPlatform().CpuCores() + 2];
for (unsigned i = 0; i < GetPlatform().CpuCores() + 2; ++i)
diff --git a/qt_tstfrm/tstwidgets.cpp b/qt_tstfrm/tstwidgets.cpp
index 4512a8f9bd..3e34da850b 100644
--- a/qt_tstfrm/tstwidgets.cpp
+++ b/qt_tstfrm/tstwidgets.cpp
@@ -50,7 +50,9 @@ void GLDrawWidget::initializeGL()
false,
true,
1,
- "primaryStorage");
+ "primaryStorage",
+ false,
+ false);
rmp.m_smallStoragesParams = yg::ResourceManager::StoragePoolParams(3000 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -60,7 +62,9 @@ void GLDrawWidget::initializeGL()
false,
true,
1,
- "smallStorage");
+ "smallStorage",
+ false,
+ false);
rmp.m_blitStoragesParams = yg::ResourceManager::StoragePoolParams(10 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -70,7 +74,9 @@ void GLDrawWidget::initializeGL()
true,
true,
1,
- "blitStorage");
+ "blitStorage",
+ false,
+ false);
rmp.m_multiBlitStoragesParams = yg::ResourceManager::StoragePoolParams(500 * sizeof(yg::gl::Vertex),
sizeof(yg::gl::Vertex),
@@ -80,7 +86,9 @@ void GLDrawWidget::initializeGL()
true,
true,
1,
- "multiBlitStorage");
+ "multiBlitStorage",
+ false,
+ false);
rmp.m_primaryTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
@@ -90,7 +98,9 @@ void GLDrawWidget::initializeGL()
true,
true,
1,
- "primaryTexture");
+ "primaryTexture",
+ false,
+ false);
rmp.m_fontTexturesParams = yg::ResourceManager::TexturePoolParams(512,
256,
@@ -100,7 +110,9 @@ void GLDrawWidget::initializeGL()
true,
true,
1,
- "fontTexture");
+ "fontTexture",
+ false,
+ false);
rmp.m_glyphCacheParams = yg::ResourceManager::GlyphCacheParams("unicode_blocks.txt",
"fonts_whitelist.txt",
diff --git a/yg/resource_manager.cpp b/yg/resource_manager.cpp
index 294c7db54c..26fa5c945b 100644
--- a/yg/resource_manager.cpp
+++ b/yg/resource_manager.cpp
@@ -35,8 +35,8 @@ namespace yg
}
}
- TTextureFactory::TTextureFactory(size_t w, size_t h, yg::DataFormat format, char const * resName)
- : BasePoolElemFactory(resName, w * h * pixelSize(format)),
+ TTextureFactory::TTextureFactory(size_t w, size_t h, yg::DataFormat format, char const * resName, size_t batchSize)
+ : BasePoolElemFactory(resName, w * h * pixelSize(format), batchSize),
m_w(w), m_h(h), m_format(format)
{}
@@ -52,8 +52,8 @@ namespace yg
}
}
- TStorageFactory::TStorageFactory(size_t vbSize, size_t ibSize, bool useVA, bool useSingleThreadedOGL, char const * resName)
- : BasePoolElemFactory(resName, vbSize + ibSize),
+ TStorageFactory::TStorageFactory(size_t vbSize, size_t ibSize, bool useVA, bool useSingleThreadedOGL, char const * resName, size_t batchSize)
+ : BasePoolElemFactory(resName, vbSize + ibSize, batchSize),
m_vbSize(vbSize),
m_ibSize(ibSize),
m_useVA(useVA),
@@ -99,7 +99,8 @@ namespace yg
m_isFixedBufferCount(true),
m_scalePriority(0),
m_poolName(poolName),
- m_isDebugging(false)
+ m_isDebugging(false),
+ m_allocateOnDemand(false)
{}
ResourceManager::StoragePoolParams::StoragePoolParams(size_t vbSize,
@@ -111,7 +112,8 @@ namespace yg
bool isFixedBufferCount,
int scalePriority,
string const & poolName,
- bool isDebugging)
+ bool isDebugging,
+ bool allocateOnDemand)
: m_vbSize(vbSize),
m_vertexSize(vertexSize),
m_ibSize(ibSize),
@@ -121,7 +123,8 @@ namespace yg
m_isFixedBufferCount(isFixedBufferCount),
m_scalePriority(scalePriority),
m_poolName(poolName),
- m_isDebugging(isDebugging)
+ m_isDebugging(isDebugging),
+ m_allocateOnDemand(allocateOnDemand)
{}
bool ResourceManager::StoragePoolParams::isFixed() const
@@ -189,7 +192,8 @@ namespace yg
m_isCountFixed(true),
m_scalePriority(0),
m_poolName(poolName),
- m_isDebugging(false)
+ m_isDebugging(false),
+ m_allocateOnDemand(false)
{}
ResourceManager::TexturePoolParams::TexturePoolParams(size_t texWidth,
@@ -201,7 +205,8 @@ namespace yg
bool isCountFixed,
int scalePriority,
string const & poolName,
- bool isDebugging)
+ bool isDebugging,
+ bool allocateOnDemand)
: m_texWidth(texWidth),
m_texHeight(texHeight),
m_texCount(texCount),
@@ -211,7 +216,8 @@ namespace yg
m_isCountFixed(isCountFixed),
m_scalePriority(scalePriority),
m_poolName(poolName),
- m_isDebugging(isDebugging)
+ m_isDebugging(isDebugging),
+ m_allocateOnDemand(allocateOnDemand)
{}
bool ResourceManager::TexturePoolParams::isFixed() const
@@ -501,10 +507,22 @@ namespace yg
{
if (p.isValid())
{
+ TStorageFactory storageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_useSingleThreadedOGL, p.m_poolName.c_str(), p.m_allocateOnDemand ? p.m_storagesCount : 0);
+
if (m_params.m_useSingleThreadedOGL)
- pool.reset(new TMergeableStoragePoolImpl(new TMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_useSingleThreadedOGL, p.m_poolName.c_str()), p.m_storagesCount)));
+ {
+ if (p.m_allocateOnDemand)
+ pool.reset(new TOnDemandSingleThreadedStoragePoolImpl(new TOnDemandSingleThreadedStoragePoolTraits(storageFactory, p.m_storagesCount)));
+ else
+ pool.reset(new TFixedSizeMergeableStoragePoolImpl(new TFixedSizeMergeableStoragePoolTraits(storageFactory, p.m_storagesCount)));
+ }
else
- pool.reset(new TNonMergeableStoragePoolImpl(new TNonMergeableStoragePoolTraits(TStorageFactory(p.m_vbSize, p.m_ibSize, m_params.m_useVA, m_params.m_useSingleThreadedOGL, p.m_poolName.c_str()), p.m_storagesCount)));
+ {
+ if (p.m_allocateOnDemand)
+ pool.reset(new TOnDemandMultiThreadedStoragePoolImpl(new TOnDemandMultiThreadedStoragePoolTraits(storageFactory, p.m_storagesCount)));
+ else
+ pool.reset(new TFixedSizeNonMergeableStoragePoolImpl(new TFixedSizeNonMergeableStoragePoolTraits(storageFactory, p.m_storagesCount)));
+ }
pool->SetIsDebugging(p.m_isDebugging);
}
@@ -516,7 +534,23 @@ namespace yg
{
if (p.isValid())
{
- pool.reset(new TTexturePoolImpl(new TTexturePoolTraits(TTextureFactory(p.m_texWidth, p.m_texHeight, p.m_format, p.m_poolName.c_str()), p.m_texCount)));
+ TTextureFactory textureFactory(p.m_texWidth, p.m_texHeight, p.m_format, p.m_poolName.c_str(), p.m_allocateOnDemand ? p.m_texCount : 0);
+
+ if (m_params.m_useSingleThreadedOGL)
+ {
+ if (p.m_allocateOnDemand)
+ pool.reset(new TOnDemandSingleThreadedTexturePoolImpl(new TOnDemandSingleThreadedTexturePoolTraits(textureFactory, p.m_texCount)));
+ else
+ pool.reset(new TFixedSizeTexturePoolImpl(new TFixedSizeTexturePoolTraits(textureFactory, p.m_texCount)));
+ }
+ else
+ {
+ if (p.m_allocateOnDemand)
+ pool.reset(new TOnDemandMultiThreadedTexturePoolImpl(new TOnDemandMultiThreadedTexturePoolTraits(textureFactory, p.m_texCount)));
+ else
+ pool.reset(new TFixedSizeTexturePoolImpl(new TFixedSizeTexturePoolTraits(textureFactory, p.m_texCount)));
+ }
+
pool->SetIsDebugging(p.m_isDebugging);
}
else
@@ -731,6 +765,17 @@ namespace yg
void ResourceManager::updatePoolState()
{
+ if (m_primaryTextures.get())
+ m_primaryTextures->UpdateState();
+ if (m_fontTextures.get())
+ m_fontTextures->UpdateState();
+ if (m_styleCacheTextures.get())
+ m_styleCacheTextures->UpdateState();
+ if (m_renderTargets.get())
+ m_renderTargets->UpdateState();
+ if (m_guiThreadTextures.get())
+ m_guiThreadTextures->UpdateState();
+
if (m_guiThreadStorages.get())
m_guiThreadStorages->UpdateState();
if (m_primaryStorages.get())
diff --git a/yg/resource_manager.hpp b/yg/resource_manager.hpp
index 8e69daf8a0..80bcf1bdfe 100644
--- a/yg/resource_manager.hpp
+++ b/yg/resource_manager.hpp
@@ -35,7 +35,7 @@ namespace yg
size_t m_w;
size_t m_h;
yg::DataFormat m_format;
- TTextureFactory(size_t w, size_t h, yg::DataFormat format, char const * resName);
+ TTextureFactory(size_t w, size_t h, yg::DataFormat format, char const * resName, size_t batchSize);
shared_ptr<gl::BaseTexture> const Create();
};
@@ -45,26 +45,57 @@ namespace yg
size_t m_ibSize;
bool m_useVA;
bool m_useSingleThreadedOGL;
- TStorageFactory(size_t vbSize, size_t ibSize, bool useVA, bool useSingleThreadedOGL, char const * resName);
+ TStorageFactory(size_t vbSize, size_t ibSize, bool useVA, bool useSingleThreadedOGL, char const * resName, size_t batchSize);
gl::Storage const Create();
void BeforeMerge(gl::Storage const & e);
};
+ /// ---- Texture Pools ----
+
+ /// Basic texture pool traits
typedef BasePoolTraits<shared_ptr<gl::BaseTexture>, TTextureFactory> TBaseTexturePoolTraits;
- typedef FixedSizePoolTraits<TTextureFactory, TBaseTexturePoolTraits > TTexturePoolTraits;
- typedef ResourcePoolImpl<TTexturePoolTraits> TTexturePoolImpl;
+ /// Fixed-Size texture pool
+ typedef FixedSizePoolTraits<TTextureFactory, TBaseTexturePoolTraits > TFixedSizeTexturePoolTraits;
+ typedef ResourcePoolImpl<TFixedSizeTexturePoolTraits> TFixedSizeTexturePoolImpl;
+
+ /// On-Demand multi-threaded texture pool
+
+ typedef AllocateOnDemandMultiThreadedPoolTraits<TTextureFactory, TBaseTexturePoolTraits> TOnDemandMultiThreadedTexturePoolTraits;
+ typedef ResourcePoolImpl<TOnDemandMultiThreadedTexturePoolTraits> TOnDemandMultiThreadedTexturePoolImpl;
+
+ /// On-Demand single-threaded texture pool
+ /// (with postponed resource allocation)
+ typedef AllocateOnDemandSingleThreadedPoolTraits<TTextureFactory, TBaseTexturePoolTraits> TOnDemandSingleThreadedTexturePoolTraits;
+ typedef ResourcePoolImpl<TOnDemandSingleThreadedTexturePoolTraits> TOnDemandSingleThreadedTexturePoolImpl;
+
+ /// Interface for texture pool
typedef ResourcePool<shared_ptr<gl::BaseTexture> > TTexturePool;
+ /// ---- Storage Pools ----
+
+ /// Basic storage traits
typedef BasePoolTraits<gl::Storage, TStorageFactory> TBaseStoragePoolTraits;
+
+ /// Fixed-Size mergeable storage pool
typedef SeparateFreePoolTraits<TStorageFactory, TBaseStoragePoolTraits> TSeparateFreeStoragePoolTraits;
+ typedef FixedSizePoolTraits<TStorageFactory, TSeparateFreeStoragePoolTraits> TFixedSizeMergeableStoragePoolTraits;
+ typedef ResourcePoolImpl<TFixedSizeMergeableStoragePoolTraits> TFixedSizeMergeableStoragePoolImpl;
+
+ /// Fixed-Size non-mergeable storage pool
+ typedef FixedSizePoolTraits<TStorageFactory, TBaseStoragePoolTraits> TFixedSizeNonMergeableStoragePoolTraits;
+ typedef ResourcePoolImpl<TFixedSizeNonMergeableStoragePoolTraits> TFixedSizeNonMergeableStoragePoolImpl;
- typedef FixedSizePoolTraits<TStorageFactory, TSeparateFreeStoragePoolTraits> TMergeableStoragePoolTraits;
- typedef ResourcePoolImpl<TMergeableStoragePoolTraits> TMergeableStoragePoolImpl;
+ /// On-Demand single-threaded storage pool
+ /// (with postponed resource allocation and separate list of freed resources)
+ typedef AllocateOnDemandSingleThreadedPoolTraits<TStorageFactory, TSeparateFreeStoragePoolTraits> TOnDemandSingleThreadedStoragePoolTraits;
+ typedef ResourcePoolImpl<TOnDemandSingleThreadedStoragePoolTraits> TOnDemandSingleThreadedStoragePoolImpl;
- typedef FixedSizePoolTraits<TStorageFactory, TBaseStoragePoolTraits> TNonMergeableStoragePoolTraits;
- typedef ResourcePoolImpl<TNonMergeableStoragePoolTraits> TNonMergeableStoragePoolImpl;
+ /// On-Demand multi-threaded storage pool
+ typedef AllocateOnDemandMultiThreadedPoolTraits<TStorageFactory, TBaseStoragePoolTraits> TOnDemandMultiThreadedStoragePoolTraits;
+ typedef ResourcePoolImpl<TOnDemandMultiThreadedStoragePoolTraits> TOnDemandMultiThreadedStoragePoolImpl;
+ /// Interface for storage pool
typedef ResourcePool<gl::Storage> TStoragePool;
class ResourceManager
@@ -88,6 +119,7 @@ namespace yg
string m_poolName;
bool m_isDebugging;
+ bool m_allocateOnDemand;
StoragePoolParams(size_t vbSize,
size_t vertexSize,
@@ -98,7 +130,8 @@ namespace yg
bool isFixedBufferCount,
int scalePriority,
string const & poolName,
- bool isDebugging = false);
+ bool isDebugging,
+ bool allocateOnDemand);
StoragePoolParams(string const & poolName);
@@ -126,6 +159,7 @@ namespace yg
string m_poolName;
bool m_isDebugging;
+ bool m_allocateOnDemand;
TexturePoolParams(size_t texWidth,
size_t texHeight,
@@ -136,7 +170,8 @@ namespace yg
bool isCountFixed,
int scalePriority,
string const & poolName,
- bool isDebugging = false);
+ bool isDebugging,
+ bool allocateOnDemand);
TexturePoolParams(string const & poolName);