From c1d2ab3326d82e78c0fa8e1f2f4a5622076a49ae Mon Sep 17 00:00:00 2001 From: ronag Date: Tue, 16 Aug 2011 11:01:26 +0000 Subject: [PATCH] 2.0. ogl_device: Dynamic pool size to reduce memory usage. 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 | 4 ++-- core/mixer/gpu/host_buffer.cpp | 4 ++-- core/mixer/gpu/ogl_device.cpp | 23 ++++------------------- core/mixer/gpu/ogl_device.h | 2 -- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/core/mixer/gpu/device_buffer.cpp b/core/mixer/gpu/device_buffer.cpp index 8a60fc9ef..def7c79bd 100644 --- a/core/mixer/gpu/device_buffer.cpp +++ b/core/mixer/gpu/device_buffer.cpp @@ -66,7 +66,7 @@ public: GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); GL(glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT[stride_], width_, height_, 0, FORMAT[stride_], GL_UNSIGNED_BYTE, NULL)); GL(glBindTexture(GL_TEXTURE_2D, 0)); - CASPAR_LOG(debug) << "[device_buffer] [" << ++g_total_count << L"] allocated size:" << width*height*stride; + CASPAR_LOG(trace) << "[device_buffer] [" << ++g_total_count << L"] allocated size:" << width*height*stride; } ~implementation() @@ -74,7 +74,7 @@ public: try { GL(glDeleteTextures(1, &id_)); - CASPAR_LOG(debug) << "[device_buffer] [" << --g_total_count << L"] deallocated size:" << width_*height_*stride_; + CASPAR_LOG(trace) << "[device_buffer] [" << --g_total_count << L"] deallocated size:" << width_*height_*stride_; } catch(...) { diff --git a/core/mixer/gpu/host_buffer.cpp b/core/mixer/gpu/host_buffer.cpp index aefcb9e5b..9e129ecbb 100644 --- a/core/mixer/gpu/host_buffer.cpp +++ b/core/mixer/gpu/host_buffer.cpp @@ -63,7 +63,7 @@ public: if(!pbo_) BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer.")); - 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"); + 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"); } ~implementation() @@ -71,7 +71,7 @@ public: try { GL(glDeleteBuffers(1, &pbo_)); - 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"); + 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"); } catch(...) { diff --git a/core/mixer/gpu/ogl_device.cpp b/core/mixer/gpu/ogl_device.cpp index 34b5366f6..7196af356 100644 --- a/core/mixer/gpu/ogl_device.cpp +++ b/core/mixer/gpu/ogl_device.cpp @@ -83,7 +83,6 @@ safe_ptr ogl_device::create_device_buffer(size_t width, size_t he std::shared_ptr buffer; if(!pool->items.try_pop(buffer)) { - ++pool->total_count; executor_.invoke([&] { try @@ -103,7 +102,6 @@ safe_ptr ogl_device::create_device_buffer(size_t width, size_t he catch(...) { CASPAR_LOG(error) << L"ogl: create_device_buffer failed!"; - --pool->total_count; throw; } } @@ -126,7 +124,6 @@ safe_ptr ogl_device::create_host_buffer(size_t size, host_buffer::u std::shared_ptr buffer; if(!pool->items.try_pop(buffer)) { - ++pool->total_count; executor_.invoke([&] { try @@ -154,7 +151,6 @@ safe_ptr ogl_device::create_host_buffer(size_t size, host_buffer::u catch(...) { CASPAR_LOG(error) << L"ogl: create_host_buffer failed!"; - --pool->total_count; throw; } } @@ -180,14 +176,13 @@ safe_ptr ogl_device::create_host_buffer(size_t size, host_buffer::u template void flush_pool(buffer_pool& pool) { - if(pool.flush_count.fetch_and_increment() < 3) + if(pool.flush_count.fetch_and_increment() < 16) return; if(pool.usage_count.fetch_and_store(0) < pool.items.size()) { std::shared_ptr buffer; - if(pool.items.try_pop(buffer)) - --pool.total_count; + pool.items.try_pop(buffer); } pool.flush_count = 0; @@ -233,22 +228,12 @@ boost::unique_future ogl_device::gc() BOOST_FOREACH(auto& pools, device_pools_) { BOOST_FOREACH(auto& pool, pools) - { - auto size = pool.second->items.size(); - std::shared_ptr buffer; - for(int n = 0; n < size && pool.second->items.try_pop(buffer); ++n) - --pool.second->total_count; - } + pool.second->items.clear(); } BOOST_FOREACH(auto& pools, host_pools_) { BOOST_FOREACH(auto& pool, pools) - { - auto size = pool.second->items.size(); - std::shared_ptr buffer; - for(int n = 0; n < size && pool.second->items.try_pop(buffer); ++n) - --pool.second->total_count; - } + pool.second->items.clear(); } } catch(...) diff --git a/core/mixer/gpu/ogl_device.h b/core/mixer/gpu/ogl_device.h index 6c4425760..4b709e7ad 100644 --- a/core/mixer/gpu/ogl_device.h +++ b/core/mixer/gpu/ogl_device.h @@ -45,14 +45,12 @@ class shader; template struct buffer_pool { - tbb::atomic total_count; tbb::atomic usage_count; tbb::atomic flush_count; tbb::concurrent_bounded_queue> items; buffer_pool() { - total_count = 0; usage_count = 0; flush_count = 0; } -- 2.39.2