]> git.sesse.net Git - casparcg/commitdiff
2.0. ogl_device: Dynamic pool size to reduce memory usage.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Tue, 16 Aug 2011 11:01:26 +0000 (11:01 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Tue, 16 Aug 2011 11:01:26 +0000 (11:01 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1196 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

core/mixer/gpu/device_buffer.cpp
core/mixer/gpu/host_buffer.cpp
core/mixer/gpu/ogl_device.cpp
core/mixer/gpu/ogl_device.h

index 8a60fc9ef69d5bddf8386f07c069849227644c2e..def7c79bd399c1cc16ad97f3164f80848b9ee5f4 100644 (file)
@@ -66,7 +66,7 @@ public:
                GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));\r
                GL(glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT[stride_], width_, height_, 0, FORMAT[stride_], GL_UNSIGNED_BYTE, NULL));\r
                GL(glBindTexture(GL_TEXTURE_2D, 0));\r
-               CASPAR_LOG(debug) << "[device_buffer] [" << ++g_total_count << L"] allocated size:" << width*height*stride;     \r
+               CASPAR_LOG(trace) << "[device_buffer] [" << ++g_total_count << L"] allocated size:" << width*height*stride;     \r
        }       \r
 \r
        ~implementation()\r
@@ -74,7 +74,7 @@ public:
                try\r
                {\r
                        GL(glDeleteTextures(1, &id_));\r
-                       CASPAR_LOG(debug) << "[device_buffer] [" << --g_total_count << L"] deallocated size:" << width_*height_*stride_;\r
+                       CASPAR_LOG(trace) << "[device_buffer] [" << --g_total_count << L"] deallocated size:" << width_*height_*stride_;\r
                }\r
                catch(...)\r
                {\r
index aefcb9e5b5f6e8b8e80e900c06dcc42d059ba413..9e129ecbb06f71fe1fec49227cc8dfba2941090e 100644 (file)
@@ -63,7 +63,7 @@ public:
                if(!pbo_)\r
                        BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer."));\r
 \r
-               CASPAR_LOG(debug) << "[host_buffer] [" << ++(usage_ == write_only ? g_w_total_count : g_r_total_count) << L"] allocated size:" << size_ << " usage: " << (usage == write_only ? "write_only" : "read_only");\r
+               CASPAR_LOG(trace) << "[host_buffer] [" << ++(usage_ == write_only ? g_w_total_count : g_r_total_count) << L"] allocated size:" << size_ << " usage: " << (usage == write_only ? "write_only" : "read_only");\r
        }       \r
 \r
        ~implementation()\r
@@ -71,7 +71,7 @@ public:
                try\r
                {\r
                        GL(glDeleteBuffers(1, &pbo_));\r
-                       CASPAR_LOG(debug) << "[host_buffer] [" << --(usage_ == write_only ? g_w_total_count : g_r_total_count) << L"] deallocated size:" << size_ << " usage: " << (usage_ == write_only ? "write_only" : "read_only");\r
+                       CASPAR_LOG(trace) << "[host_buffer] [" << --(usage_ == write_only ? g_w_total_count : g_r_total_count) << L"] deallocated size:" << size_ << " usage: " << (usage_ == write_only ? "write_only" : "read_only");\r
                }\r
                catch(...)\r
                {\r
index 34b5366f66697f25cf91bb70531f3107668385d3..7196af3560b8bb27fca9d1c97623392e0391cbc8 100644 (file)
@@ -83,7 +83,6 @@ safe_ptr<device_buffer> ogl_device::create_device_buffer(size_t width, size_t he
        std::shared_ptr<device_buffer> buffer;\r
        if(!pool->items.try_pop(buffer))                \r
        {\r
-               ++pool->total_count;\r
                executor_.invoke([&]\r
                {       \r
                        try\r
@@ -103,7 +102,6 @@ safe_ptr<device_buffer> ogl_device::create_device_buffer(size_t width, size_t he
                                catch(...)\r
                                {\r
                                        CASPAR_LOG(error) << L"ogl: create_device_buffer failed!";\r
-                                       --pool->total_count;\r
                                        throw;\r
                                }\r
                        }\r
@@ -126,7 +124,6 @@ safe_ptr<host_buffer> ogl_device::create_host_buffer(size_t size, host_buffer::u
        std::shared_ptr<host_buffer> buffer;\r
        if(!pool->items.try_pop(buffer))\r
        {\r
-               ++pool->total_count;\r
                executor_.invoke([&]\r
                {\r
                        try\r
@@ -154,7 +151,6 @@ safe_ptr<host_buffer> ogl_device::create_host_buffer(size_t size, host_buffer::u
                                catch(...)\r
                                {\r
                                        CASPAR_LOG(error) << L"ogl: create_host_buffer failed!";\r
-                                       --pool->total_count;\r
                                        throw;          \r
                                }\r
                        }\r
@@ -180,14 +176,13 @@ safe_ptr<host_buffer> ogl_device::create_host_buffer(size_t size, host_buffer::u
 template<typename T>\r
 void flush_pool(buffer_pool<T>& pool)\r
 {      \r
-       if(pool.flush_count.fetch_and_increment() < 3)\r
+       if(pool.flush_count.fetch_and_increment() < 16)\r
                return;\r
 \r
        if(pool.usage_count.fetch_and_store(0) < pool.items.size())\r
        {\r
                std::shared_ptr<T> buffer;\r
-               if(pool.items.try_pop(buffer))\r
-                       --pool.total_count;\r
+               pool.items.try_pop(buffer);\r
        }\r
 \r
        pool.flush_count = 0;\r
@@ -233,22 +228,12 @@ boost::unique_future<void> ogl_device::gc()
                        BOOST_FOREACH(auto& pools, device_pools_)\r
                        {\r
                                BOOST_FOREACH(auto& pool, pools)\r
-                               {\r
-                                       auto size = pool.second->items.size();\r
-                                       std::shared_ptr<device_buffer> buffer;\r
-                                       for(int n = 0; n < size && pool.second->items.try_pop(buffer); ++n)\r
-                                               --pool.second->total_count;\r
-                               }\r
+                                       pool.second->items.clear();\r
                        }\r
                        BOOST_FOREACH(auto& pools, host_pools_)\r
                        {\r
                                BOOST_FOREACH(auto& pool, pools)\r
-                               {\r
-                                       auto size = pool.second->items.size();\r
-                                       std::shared_ptr<host_buffer> buffer;\r
-                                       for(int n = 0; n < size && pool.second->items.try_pop(buffer); ++n)\r
-                                               --pool.second->total_count;\r
-                               }\r
+                                       pool.second->items.clear();\r
                        }\r
                }\r
                catch(...)\r
index 6c44257609e2bb6f48294229a1055ea05d27fe19..4b709e7ada646b3d91627b1f2c198507219173c5 100644 (file)
@@ -45,14 +45,12 @@ class shader;
 template<typename T>\r
 struct buffer_pool\r
 {\r
-       tbb::atomic<int> total_count;\r
        tbb::atomic<int> usage_count;\r
        tbb::atomic<int> flush_count;\r
        tbb::concurrent_bounded_queue<std::shared_ptr<T>> items;\r
 \r
        buffer_pool()\r
        {\r
-               total_count = 0;\r
                usage_count = 0;\r
                flush_count = 0;\r
        }\r