From: ronag Date: Fri, 6 Apr 2012 16:50:30 +0000 (+0000) Subject: 2.1.0: Don't use separate opengl allocation context as this seems to cause long block... X-Git-Tag: 2.1.0_Beta1~534 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=27ad13001cd92f83fa9682eab5841935b1e9ce58;p=casparcg 2.1.0: Don't use separate opengl allocation context as this seems to cause long blocking allocations in some scenarios. git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@2801 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- diff --git a/accelerator/ogl/util/buffer.cpp b/accelerator/ogl/util/buffer.cpp index 3d9e5a81e..5efdd2f4c 100644 --- a/accelerator/ogl/util/buffer.cpp +++ b/accelerator/ogl/util/buffer.cpp @@ -67,6 +67,7 @@ public: if(timer.elapsed() > 0.02) CASPAR_LOG(debug) << L"[buffer] Performance warning. Buffer allocation blocked more than 20 ms: " << timer.elapsed(); + //CASPAR_LOG(trace) << "[buffer] [" << ++(usage_ == buffer::usage::write_only ? g_w_total_count : g_r_total_count) << L"] allocated size:" << size_ << " usage: " << (usage == buffer::usage::write_only ? "write_only" : "read_only"); } diff --git a/accelerator/ogl/util/device.cpp b/accelerator/ogl/util/device.cpp index 9b463ea45..f09c0ad9a 100644 --- a/accelerator/ogl/util/device.cpp +++ b/accelerator/ogl/util/device.cpp @@ -63,26 +63,22 @@ struct device::impl : public std::enable_shared_from_this tbb::concurrent_hash_map> texture_cache_; std::unique_ptr device_; - std::unique_ptr host_alloc_device_; std::array>>, 4> device_pools_; std::array>>, 2> host_pools_; GLuint fbo_; - executor& render_executor_; - executor alloc_executor_; + executor& executor_; impl(executor& executor) - : render_executor_(executor) - , alloc_executor_(L"OpenGL allocation context") + : executor_(executor) { - render_executor_.set_capacity(128); - alloc_executor_.set_capacity(256); + executor_.set_capacity(256); CASPAR_LOG(info) << L"Initializing OpenGL Device."; - auto ctx1 = render_executor_.invoke([=]() -> HGLRC + executor_.invoke([=] { device_.reset(new sf::Context()); device_->SetActive(true); @@ -95,27 +91,6 @@ struct device::impl : public std::enable_shared_from_this glGenFramebuffers(1, &fbo_); glBindFramebuffer(GL_FRAMEBUFFER, fbo_); - - auto ctx1 = wglGetCurrentContext(); - - device_->SetActive(false); - - return ctx1; - }); - - alloc_executor_.invoke([=] - { - host_alloc_device_.reset(new sf::Context()); - host_alloc_device_->SetActive(true); - auto ctx2 = wglGetCurrentContext(); - - if(!wglShareLists(ctx1, ctx2)) - CASPAR_THROW_EXCEPTION(gl::ogl_exception() << msg_info("Failed to share OpenGL devices.")); - }); - - render_executor_.invoke([=] - { - device_->SetActive(true); }); CASPAR_LOG(info) << L"Successfully initialized OpenGL " << version(); @@ -123,14 +98,7 @@ struct device::impl : public std::enable_shared_from_this ~impl() { - alloc_executor_.invoke([=] - { - host_alloc_device_.reset(); - BOOST_FOREACH(auto& pool, host_pools_) - pool.clear(); - }); - - render_executor_.invoke([=] + executor_.invoke([=] { BOOST_FOREACH(auto& pool, device_pools_) pool.clear(); @@ -144,7 +112,7 @@ struct device::impl : public std::enable_shared_from_this { try { - return alloc_executor_.invoke([] + return executor_.invoke([] { return u16(reinterpret_cast(GL2(glGetString(GL_VERSION)))) + L" " + u16(reinterpret_cast(GL2(glGetString(GL_VENDOR)))); }); @@ -160,7 +128,7 @@ struct device::impl : public std::enable_shared_from_this CASPAR_VERIFY(stride > 0 && stride < 5); CASPAR_VERIFY(width > 0 && height > 0); - if(!render_executor_.is_current()) + if(!executor_.is_current()) CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Operation only valid in an OpenGL Context.")); auto pool = &device_pools_[stride-1][((width << 16) & 0xFFFF0000) | (height & 0x0000FFFF)]; @@ -187,7 +155,7 @@ struct device::impl : public std::enable_shared_from_this std::shared_ptr buf; if(!pool->try_pop(buf)) { - buf = alloc_executor_.invoke([&] + buf = executor_.invoke([&] { return spl::make_shared(size, usage); }, task_priority::high_priority); @@ -232,7 +200,7 @@ struct device::impl : public std::enable_shared_from_this { std::shared_ptr buf = copy_to_buf(source); - return render_executor_.begin_invoke([=]() -> spl::shared_ptr + return executor_.begin_invoke([=]() -> spl::shared_ptr { tbb::concurrent_hash_map>::const_accessor a; if(texture_cache_.find(a, buf.get())) @@ -251,7 +219,7 @@ struct device::impl : public std::enable_shared_from_this { std::shared_ptr buf = copy_to_buf(source); - return render_executor_.begin_invoke([=]() -> spl::shared_ptr + return executor_.begin_invoke([=]() -> spl::shared_ptr { auto texture = create_texture(width, height, stride, false); texture->copy_from(*buf); @@ -261,7 +229,7 @@ struct device::impl : public std::enable_shared_from_this boost::unique_future> copy_async(const spl::shared_ptr& source) { - if(!render_executor_.is_current()) + if(!executor_.is_current()) CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info("Operation only valid in an OpenGL Context.")); auto buffer = create_buffer(source->size(), buffer::usage::read_only); @@ -270,7 +238,7 @@ struct device::impl : public std::enable_shared_from_this auto self = shared_from_this(); return async(launch::deferred, [self, buffer]() mutable -> array { - self->alloc_executor_.invoke(std::bind(&buffer::map, std::ref(buffer))); // Defer blocking "map" call until data is needed. + self->executor_.invoke(std::bind(&buffer::map, std::ref(buffer))); // Defer blocking "map" call until data is needed. return array(buffer->data(), buffer->size(), true, buffer); }); } diff --git a/core/consumer/output.cpp b/core/consumer/output.cpp index 6aaaa61be..59f749d96 100644 --- a/core/consumer/output.cpp +++ b/core/consumer/output.cpp @@ -153,11 +153,12 @@ public: void operator()(const_frame input_frame, const core::video_format_desc& format_desc) { - video_format_desc(format_desc); + boost::timer frame_timer; + + video_format_desc(format_desc); executor_.invoke([=] { - boost::timer frame_timer; if(!has_synchronization_clock()) sync_timer_.tick(1.0/format_desc_.fps); @@ -194,9 +195,9 @@ public: ports_.erase(it++); } } - - graph_->set_value("consume-time", frame_timer.elapsed()*format_desc.fps*0.5); }); + + graph_->set_value("consume-time", frame_timer.elapsed()*format_desc.fps*0.5); } std::wstring print() const diff --git a/core/mixer/mixer.cpp b/core/mixer/mixer.cpp index 2a0adbd62..0a423fb20 100644 --- a/core/mixer/mixer.cpp +++ b/core/mixer/mixer.cpp @@ -75,12 +75,12 @@ public: const_frame operator()(std::map frames, const video_format_desc& format_desc) { - return executor_.invoke([=]() mutable -> const_frame + boost::timer frame_timer; + + auto frame = executor_.invoke([=]() mutable -> const_frame { try { - boost::timer frame_timer; - BOOST_FOREACH(auto& frame, frames) { auto blend_it = blend_modes_.find(frame.first); @@ -94,8 +94,6 @@ public: auto image = (*image_mixer_)(format_desc); auto audio = audio_mixer_(format_desc); - - graph_->set_value("mix-time", frame_timer.elapsed()*format_desc.fps*0.5); auto desc = core::pixel_format_desc(core::pixel_format::bgra); desc.planes.push_back(core::pixel_format_desc::plane(format_desc.width, format_desc.height, 4)); @@ -107,6 +105,10 @@ public: return const_frame::empty(); } }); + + graph_->set_value("mix-time", frame_timer.elapsed()*format_desc.fps*0.5); + + return frame; } void set_blend_mode(int index, blend_mode value) diff --git a/core/producer/layer.cpp b/core/producer/layer.cpp index 40defdbc3..d53f28242 100644 --- a/core/producer/layer.cpp +++ b/core/producer/layer.cpp @@ -111,8 +111,13 @@ public: { try { + boost::timer timer; + auto frame = foreground_->receive(); + if(timer.elapsed() > 1.0/format_desc.fps*0.9) + CASPAR_LOG(trace) << foreground_->print() << L" Is slowing down channel."; + if(frame == core::draw_frame::late()) return foreground_->last_frame(); diff --git a/core/producer/stage.cpp b/core/producer/stage.cpp index b1ed3461d..bfc83750b 100644 --- a/core/producer/stage.cpp +++ b/core/producer/stage.cpp @@ -66,9 +66,10 @@ public: std::map operator()(const struct video_format_desc& format_desc) { + boost::timer frame_timer; + auto frames = executor_.invoke([=]() -> std::map { - boost::timer frame_timer; std::map frames; @@ -91,13 +92,15 @@ public: CASPAR_LOG_CURRENT_EXCEPTION(); } - graph_->set_value("produce-time", frame_timer.elapsed()*format_desc.fps*0.5); - event_subject_ << monitor::event("profiler/time") % frame_timer.elapsed() % (1.0/format_desc.fps); return frames; }); frames_subject_ << frames; + + graph_->set_value("produce-time", frame_timer.elapsed()*format_desc.fps*0.5); + event_subject_ << monitor::event("profiler/time") % frame_timer.elapsed() % (1.0/format_desc.fps); + return frames; } diff --git a/core/video_channel.cpp b/core/video_channel.cpp index 7ef5787c6..57753c077 100644 --- a/core/video_channel.cpp +++ b/core/video_channel.cpp @@ -108,26 +108,43 @@ public: { try { - auto format_desc = video_format_desc(); + boost::timer t; + auto format_desc = video_format_desc(); + boost::timer frame_timer; // Produce auto stage_frames = stage_(format_desc); + if(t.elapsed() > 1.0/format_desc.fps*0.9) + CASPAR_LOG(trace) << print() << L" Stage is slowing down channel: " << t.elapsed(); + + t.restart(); // Mix auto mixed_frame = mixer_(std::move(stage_frames), format_desc); + + if(t.elapsed() > 1.0/format_desc.fps*0.9) + CASPAR_LOG(trace) << print() << L"Mixer is slowing down channel: " << t.elapsed(); + t.restart(); // Consume output_(std::move(mixed_frame), format_desc); + t.restart(); + graph_->set_value("tick-time", frame_timer.elapsed()*format_desc.fps*0.5); event_subject_ << monitor::event("profiler/time") % frame_timer.elapsed() % (1.0/format_desc_.fps) << monitor::event("format") % format_desc.name; + + if(t.elapsed() > 0.001) + CASPAR_LOG(trace) << L"4## " << t.elapsed(); + + t.restart(); } catch(...) { diff --git a/shell/casparcg.config b/shell/casparcg.config index 76bbffeeb..30f5f5b6a 100644 --- a/shell/casparcg.config +++ b/shell/casparcg.config @@ -13,7 +13,7 @@ - NTSC + 720p5000 1