2013-12-30 13:22:50 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/GLInterface/GLInterface.h"
|
|
|
|
#include "VideoBackends/OGL/GLUtil.h"
|
|
|
|
#include "VideoBackends/OGL/PerfQuery.h"
|
|
|
|
#include "VideoCommon/RenderBase.h"
|
2012-06-17 11:58:29 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
namespace OGL
|
|
|
|
{
|
2012-06-17 11:58:29 +00:00
|
|
|
|
|
|
|
PerfQuery::PerfQuery()
|
2013-02-16 23:50:40 +00:00
|
|
|
: m_query_read_pos()
|
|
|
|
, m_query_count()
|
2012-06-17 11:58:29 +00:00
|
|
|
{
|
2014-02-15 06:12:13 +00:00
|
|
|
for (ActiveQuery& query : m_query_buffer)
|
|
|
|
glGenQueries(1, &query.query_id);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
ResetQuery();
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PerfQuery::~PerfQuery()
|
|
|
|
{
|
2014-02-15 06:12:13 +00:00
|
|
|
for (ActiveQuery& query : m_query_buffer)
|
|
|
|
glDeleteQueries(1, &query.query_id);
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::EnableQuery(PerfQueryGroup type)
|
|
|
|
{
|
2013-02-16 23:50:40 +00:00
|
|
|
// Is this sane?
|
2014-02-15 06:12:13 +00:00
|
|
|
if (m_query_count > m_query_buffer.size() / 2)
|
2013-02-16 23:50:40 +00:00
|
|
|
WeakFlush();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-02-15 06:12:13 +00:00
|
|
|
if (m_query_buffer.size() == m_query_count)
|
2013-02-16 23:50:40 +00:00
|
|
|
{
|
|
|
|
FlushOne();
|
2013-03-31 23:10:21 +00:00
|
|
|
//ERROR_LOG(VIDEO, "Flushed query buffer early!");
|
2013-02-16 23:50:40 +00:00
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2012-06-17 11:58:29 +00:00
|
|
|
// start query
|
|
|
|
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
|
|
|
|
{
|
2014-02-15 06:12:13 +00:00
|
|
|
auto& entry = m_query_buffer[(m_query_read_pos + m_query_count) % m_query_buffer.size()];
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-12-30 13:22:50 +00:00
|
|
|
glBeginQuery(GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL ? GL_SAMPLES_PASSED : GL_ANY_SAMPLES_PASSED, entry.query_id);
|
2013-02-16 23:50:40 +00:00
|
|
|
entry.query_type = type;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
++m_query_count;
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::DisableQuery(PerfQueryGroup type)
|
|
|
|
{
|
|
|
|
// stop query
|
|
|
|
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
|
|
|
|
{
|
2013-12-30 13:22:50 +00:00
|
|
|
glEndQuery(GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL ? GL_SAMPLES_PASSED : GL_ANY_SAMPLES_PASSED);
|
2013-02-16 23:50:40 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-17 11:58:29 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
bool PerfQuery::IsFlushed() const
|
|
|
|
{
|
|
|
|
return 0 == m_query_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::FlushOne()
|
|
|
|
{
|
|
|
|
auto& entry = m_query_buffer[m_query_read_pos];
|
2013-03-01 22:12:41 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
GLuint result = 0;
|
|
|
|
glGetQueryObjectuiv(entry.query_id, GL_QUERY_RESULT, &result);
|
2013-03-01 22:12:41 +00:00
|
|
|
|
|
|
|
// NOTE: Reported pixel metrics should be referenced to native resolution
|
2013-03-01 22:57:56 +00:00
|
|
|
m_results[entry.query_type] += (u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() * EFB_HEIGHT / g_renderer->GetTargetHeight();
|
2013-03-01 22:12:41 +00:00
|
|
|
|
2014-02-15 06:12:13 +00:00
|
|
|
m_query_read_pos = (m_query_read_pos + 1) % m_query_buffer.size();
|
2013-02-16 23:50:40 +00:00
|
|
|
--m_query_count;
|
|
|
|
}
|
2012-06-17 11:58:29 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
// TODO: could selectively flush things, but I don't think that will do much
|
|
|
|
void PerfQuery::FlushResults()
|
|
|
|
{
|
|
|
|
while (!IsFlushed())
|
|
|
|
FlushOne();
|
|
|
|
}
|
2012-06-17 11:58:29 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
void PerfQuery::WeakFlush()
|
|
|
|
{
|
|
|
|
while (!IsFlushed())
|
|
|
|
{
|
|
|
|
auto& entry = m_query_buffer[m_query_read_pos];
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
GLuint result = GL_FALSE;
|
|
|
|
glGetQueryObjectuiv(entry.query_id, GL_QUERY_RESULT_AVAILABLE, &result);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
if (GL_TRUE == result)
|
|
|
|
{
|
|
|
|
FlushOne();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::ResetQuery()
|
|
|
|
{
|
2013-02-16 23:50:40 +00:00
|
|
|
m_query_count = 0;
|
2013-09-12 00:19:36 +00:00
|
|
|
std::fill_n(m_results, ArraySize(m_results), 0);
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 PerfQuery::GetQueryResult(PerfQueryType type)
|
|
|
|
{
|
2013-02-16 23:50:40 +00:00
|
|
|
u32 result = 0;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC)
|
2012-06-17 11:58:29 +00:00
|
|
|
{
|
2013-02-16 23:50:40 +00:00
|
|
|
result = m_results[PQG_ZCOMP_ZCOMPLOC];
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
2013-02-16 23:50:40 +00:00
|
|
|
else if (type == PQ_ZCOMP_INPUT || type == PQ_ZCOMP_OUTPUT)
|
2012-06-17 11:58:29 +00:00
|
|
|
{
|
2013-02-16 23:50:40 +00:00
|
|
|
result = m_results[PQG_ZCOMP];
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
2013-02-16 23:50:40 +00:00
|
|
|
else if (type == PQ_BLEND_INPUT)
|
2012-06-17 11:58:29 +00:00
|
|
|
{
|
2013-02-16 23:50:40 +00:00
|
|
|
result = m_results[PQG_ZCOMP] + m_results[PQG_ZCOMP_ZCOMPLOC];
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
2013-02-16 23:50:40 +00:00
|
|
|
else if (type == PQ_EFB_COPY_CLOCKS)
|
2012-06-17 11:58:29 +00:00
|
|
|
{
|
2013-02-16 23:50:40 +00:00
|
|
|
result = m_results[PQG_EFB_COPY_CLOCKS];
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-16 23:50:40 +00:00
|
|
|
return result / 4;
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|