#include <common/except.h>
#include <common/gl/gl_check.h>
+#include <common/timer.h>
#include <GL/glew.h>
+#include <boost/property_tree/ptree.hpp>
+
#include <tbb/atomic.h>
namespace caspar { namespace accelerator { namespace ogl {
-static tbb::atomic<int> g_w_total_count;
-static tbb::atomic<int> g_r_total_count;
-
+static tbb::atomic<int> g_w_total_count;
+static tbb::atomic<std::size_t> g_w_total_size;
+static tbb::atomic<int> g_r_total_count;
+static tbb::atomic<std::size_t> g_r_total_size;
+
struct buffer::impl : boost::noncopyable
{
GLuint pbo_;
, target_(usage == buffer::usage::write_only ? GL_PIXEL_UNPACK_BUFFER : GL_PIXEL_PACK_BUFFER)
, usage_(usage == buffer::usage::write_only ? GL_STREAM_DRAW : GL_STREAM_READ)
{
- boost::timer timer;
+ CASPAR_LOG_CALL(trace) << "buffer::buffer() <- " << get_context();
+ caspar::timer timer;
data_ = nullptr;
GL(glGenBuffers(1, &pbo_));
if(!pbo_)
CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer."));
+
+ (usage == buffer::usage::write_only ? g_w_total_count : g_r_total_count) ++;
+ (usage == buffer::usage::write_only ? g_w_total_size : g_r_total_size) += size_;
if(timer.elapsed() > 0.02)
- CASPAR_LOG(debug) << L"[buffer] Performance warning. Buffer allocation blocked: " << timer.elapsed();
+ CASPAR_LOG(warning) << L"[buffer] Performance warning. Buffer allocation blocked: " << 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");
}
~impl()
{
+ CASPAR_LOG_CALL(trace) << "buffer::~buffer() <- " << get_context();
glDeleteBuffers(1, &pbo_);
+ (usage_ == GL_STREAM_DRAW ? g_w_total_size : g_r_total_size) -= size_;
+ (usage_ == GL_STREAM_DRAW ? g_w_total_count : g_r_total_count) --;
}
void* map()
if(data_ != nullptr)
return data_;
- boost::timer timer;
+ caspar::timer timer;
GL(glBindBuffer(target_, pbo_));
if(usage_ == GL_STREAM_DRAW)
data_ = (uint8_t*) result;
if(timer.elapsed() > 0.02)
- CASPAR_LOG(debug) << L"[buffer] Performance warning. Buffer mapping blocked: " << timer.elapsed();
+ CASPAR_LOG(warning) << L"[buffer] Performance warning. Buffer mapping blocked: " << timer.elapsed();
GL(glBindBuffer(target_, 0));
if(!data_)
std::size_t buffer::size() const { return impl_->size_; }
int buffer::id() const {return impl_->pbo_;}
+boost::property_tree::wptree buffer::info()
+{
+ boost::property_tree::wptree info;
+
+ info.add(L"total_read_count", g_r_total_count);
+ info.add(L"total_write_count", g_w_total_count);
+ info.add(L"total_read_size", g_r_total_size);
+ info.add(L"total_write_size", g_w_total_size);
+
+ return info;
+}
+
}}}