2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2012 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-12-30 13:22:50 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-12-21 02:49:49 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonFuncs.h"
|
|
|
|
#include "Common/CommonTypes.h"
|
2015-09-18 16:40:00 +00:00
|
|
|
#include "Common/GL/GLInterfaceBase.h"
|
|
|
|
#include "Common/GL/GLUtil.h"
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#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
|
|
|
|
{
|
2015-12-21 02:49:49 +00:00
|
|
|
std::unique_ptr<PerfQueryBase> GetPerfQuery()
|
2015-02-21 22:58:53 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3 &&
|
|
|
|
GLExtensions::Supports("GL_NV_occlusion_query_samples"))
|
|
|
|
return std::make_unique<PerfQueryGLESNV>();
|
2015-12-21 02:49:49 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGLES3)
|
|
|
|
return std::make_unique<PerfQueryGL>(GL_ANY_SAMPLES_PASSED);
|
2015-12-21 02:49:49 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return std::make_unique<PerfQueryGL>(GL_SAMPLES_PASSED);
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
2012-06-17 11:58:29 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
PerfQuery::PerfQuery() : m_query_read_pos()
|
2015-02-21 22:58:53 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
ResetQuery();
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::EnableQuery(PerfQueryGroup type)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_query->EnableQuery(type);
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::DisableQuery(PerfQueryGroup type)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_query->DisableQuery(type);
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PerfQuery::IsFlushed() const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return 0 == m_query_count;
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: could selectively flush things, but I don't think that will do much
|
|
|
|
void PerfQuery::FlushResults()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_query->FlushResults();
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::ResetQuery()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_query_count = 0;
|
|
|
|
std::fill_n(m_results, ArraySize(m_results), 0);
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 PerfQuery::GetQueryResult(PerfQueryType type)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
u32 result = 0;
|
|
|
|
|
|
|
|
if (type == PQ_ZCOMP_INPUT_ZCOMPLOC || type == PQ_ZCOMP_OUTPUT_ZCOMPLOC)
|
|
|
|
{
|
|
|
|
result = m_results[PQG_ZCOMP_ZCOMPLOC];
|
|
|
|
}
|
|
|
|
else if (type == PQ_ZCOMP_INPUT || type == PQ_ZCOMP_OUTPUT)
|
|
|
|
{
|
|
|
|
result = m_results[PQG_ZCOMP];
|
|
|
|
}
|
|
|
|
else if (type == PQ_BLEND_INPUT)
|
|
|
|
{
|
|
|
|
result = m_results[PQG_ZCOMP] + m_results[PQG_ZCOMP_ZCOMPLOC];
|
|
|
|
}
|
|
|
|
else if (type == PQ_EFB_COPY_CLOCKS)
|
|
|
|
{
|
|
|
|
result = m_results[PQG_EFB_COPY_CLOCKS];
|
|
|
|
}
|
|
|
|
|
|
|
|
return result / 4;
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implementations
|
2016-06-24 08:43:46 +00:00
|
|
|
PerfQueryGL::PerfQueryGL(GLenum query_type) : m_query_type(query_type)
|
2012-06-17 11:58:29 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (ActiveQuery& query : m_query_buffer)
|
|
|
|
glGenQueries(1, &query.query_id);
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 22:58:53 +00:00
|
|
|
PerfQueryGL::~PerfQueryGL()
|
2012-06-17 11:58:29 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (ActiveQuery& query : m_query_buffer)
|
|
|
|
glDeleteQueries(1, &query.query_id);
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 22:58:53 +00:00
|
|
|
void PerfQueryGL::EnableQuery(PerfQueryGroup type)
|
2012-06-17 11:58:29 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// Is this sane?
|
|
|
|
if (m_query_count > m_query_buffer.size() / 2)
|
|
|
|
WeakFlush();
|
|
|
|
|
|
|
|
if (m_query_buffer.size() == m_query_count)
|
|
|
|
{
|
|
|
|
FlushOne();
|
|
|
|
// ERROR_LOG(VIDEO, "Flushed query buffer early!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// start query
|
|
|
|
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
|
|
|
|
{
|
|
|
|
auto& entry = m_query_buffer[(m_query_read_pos + m_query_count) % m_query_buffer.size()];
|
|
|
|
|
|
|
|
glBeginQuery(m_query_type, entry.query_id);
|
|
|
|
entry.query_type = type;
|
|
|
|
|
|
|
|
++m_query_count;
|
|
|
|
}
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
2015-02-21 22:58:53 +00:00
|
|
|
void PerfQueryGL::DisableQuery(PerfQueryGroup type)
|
2012-06-17 11:58:29 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// stop query
|
|
|
|
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
|
|
|
|
{
|
|
|
|
glEndQuery(m_query_type);
|
|
|
|
}
|
2013-02-16 23:50:40 +00:00
|
|
|
}
|
2012-06-17 11:58:29 +00:00
|
|
|
|
2015-02-21 22:58:53 +00:00
|
|
|
void PerfQueryGL::WeakFlush()
|
2013-02-16 23:50:40 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
while (!IsFlushed())
|
|
|
|
{
|
|
|
|
auto& entry = m_query_buffer[m_query_read_pos];
|
|
|
|
|
|
|
|
GLuint result = GL_FALSE;
|
|
|
|
glGetQueryObjectuiv(entry.query_id, GL_QUERY_RESULT_AVAILABLE, &result);
|
|
|
|
|
|
|
|
if (GL_TRUE == result)
|
|
|
|
{
|
|
|
|
FlushOne();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-02-16 23:50:40 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 22:58:53 +00:00
|
|
|
void PerfQueryGL::FlushOne()
|
2013-02-16 23:50:40 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
auto& entry = m_query_buffer[m_query_read_pos];
|
2013-03-01 22:12:41 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
GLuint result = 0;
|
|
|
|
glGetQueryObjectuiv(entry.query_id, GL_QUERY_RESULT, &result);
|
2013-03-01 22:12:41 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// NOTE: Reported pixel metrics should be referenced to native resolution
|
|
|
|
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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
m_query_read_pos = (m_query_read_pos + 1) % m_query_buffer.size();
|
|
|
|
--m_query_count;
|
2013-02-16 23:50:40 +00:00
|
|
|
}
|
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
|
2015-02-21 22:58:53 +00:00
|
|
|
void PerfQueryGL::FlushResults()
|
2013-02-16 23:50:40 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
while (!IsFlushed())
|
|
|
|
FlushOne();
|
2013-02-16 23:50:40 +00:00
|
|
|
}
|
2012-06-17 11:58:29 +00:00
|
|
|
|
2015-02-21 22:58:53 +00:00
|
|
|
PerfQueryGLESNV::PerfQueryGLESNV()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (ActiveQuery& query : m_query_buffer)
|
|
|
|
glGenOcclusionQueriesNV(1, &query.query_id);
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PerfQueryGLESNV::~PerfQueryGLESNV()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (ActiveQuery& query : m_query_buffer)
|
|
|
|
glDeleteOcclusionQueriesNV(1, &query.query_id);
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQueryGLESNV::EnableQuery(PerfQueryGroup type)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// Is this sane?
|
|
|
|
if (m_query_count > m_query_buffer.size() / 2)
|
|
|
|
WeakFlush();
|
|
|
|
|
|
|
|
if (m_query_buffer.size() == m_query_count)
|
|
|
|
{
|
|
|
|
FlushOne();
|
|
|
|
// ERROR_LOG(VIDEO, "Flushed query buffer early!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// start query
|
|
|
|
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
|
|
|
|
{
|
|
|
|
auto& entry = m_query_buffer[(m_query_read_pos + m_query_count) % m_query_buffer.size()];
|
|
|
|
|
|
|
|
glBeginOcclusionQueryNV(entry.query_id);
|
|
|
|
entry.query_type = type;
|
|
|
|
|
|
|
|
++m_query_count;
|
|
|
|
}
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
void PerfQueryGLESNV::DisableQuery(PerfQueryGroup type)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// stop query
|
|
|
|
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
|
|
|
|
{
|
|
|
|
glEndOcclusionQueryNV();
|
|
|
|
}
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQueryGLESNV::WeakFlush()
|
2013-02-16 23:50:40 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
while (!IsFlushed())
|
|
|
|
{
|
|
|
|
auto& entry = m_query_buffer[m_query_read_pos];
|
|
|
|
|
|
|
|
GLuint result = GL_FALSE;
|
|
|
|
glGetOcclusionQueryuivNV(entry.query_id, GL_PIXEL_COUNT_AVAILABLE_NV, &result);
|
|
|
|
|
|
|
|
if (GL_TRUE == result)
|
|
|
|
{
|
|
|
|
FlushOne();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
|
|
|
|
2015-02-21 22:58:53 +00:00
|
|
|
void PerfQueryGLESNV::FlushOne()
|
2012-06-17 11:58:29 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
auto& entry = m_query_buffer[m_query_read_pos];
|
2012-06-17 11:58:29 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
GLuint result = 0;
|
|
|
|
glGetOcclusionQueryuivNV(entry.query_id, GL_OCCLUSION_TEST_RESULT_HP, &result);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// NOTE: Reported pixel metrics should be referenced to native resolution
|
|
|
|
m_results[entry.query_type] += (u64)result * EFB_WIDTH / g_renderer->GetTargetWidth() *
|
|
|
|
EFB_HEIGHT / g_renderer->GetTargetHeight();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
m_query_read_pos = (m_query_read_pos + 1) % m_query_buffer.size();
|
|
|
|
--m_query_count;
|
2015-02-21 22:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: could selectively flush things, but I don't think that will do much
|
|
|
|
void PerfQueryGLESNV::FlushResults()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
while (!IsFlushed())
|
|
|
|
FlushOne();
|
2012-06-17 11:58:29 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
} // namespace
|