2015-05-24 04:32:32 +00:00
|
|
|
// Copyright 2012 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "VideoBackends/D3D/PerfQuery.h"
|
2019-06-01 11:55:09 +00:00
|
|
|
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/Logging/Log.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
|
|
|
#include "VideoCommon/RenderBase.h"
|
2019-07-17 00:18:48 +00:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2013-03-01 18:30:37 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
namespace DX11
|
|
|
|
{
|
|
|
|
PerfQuery::PerfQuery() : m_query_read_pos()
|
2013-03-01 18:30:37 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (ActiveQuery& entry : m_query_buffer)
|
|
|
|
{
|
|
|
|
D3D11_QUERY_DESC qdesc = CD3D11_QUERY_DESC(D3D11_QUERY_OCCLUSION, 0);
|
|
|
|
D3D::device->CreateQuery(&qdesc, &entry.query);
|
|
|
|
}
|
2014-02-15 06:12:13 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ResetQuery();
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
|
|
|
|
2019-03-09 13:31:37 +00:00
|
|
|
PerfQuery::~PerfQuery() = default;
|
2013-03-01 18:30:37 +00:00
|
|
|
|
|
|
|
void PerfQuery::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)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
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()];
|
|
|
|
|
2019-03-09 13:31:37 +00:00
|
|
|
D3D::context->Begin(entry.query.Get());
|
2016-06-24 08:43:46 +00:00
|
|
|
entry.query_type = type;
|
|
|
|
|
|
|
|
++m_query_count;
|
|
|
|
}
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::DisableQuery(PerfQueryGroup type)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// stop 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() - 1) %
|
|
|
|
m_query_buffer.size()];
|
2019-03-09 13:31:37 +00:00
|
|
|
D3D::context->End(entry.query.Get());
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::ResetQuery()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_query_count = 0;
|
2019-06-01 11:55:09 +00:00
|
|
|
std::fill(std::begin(m_results), std::end(m_results), 0);
|
2013-03-01 18:30:37 +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];
|
|
|
|
|
2016-06-13 05:41:29 +00:00
|
|
|
return result;
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::FlushOne()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
auto& entry = m_query_buffer[m_query_read_pos];
|
|
|
|
|
|
|
|
UINT64 result = 0;
|
|
|
|
HRESULT hr = S_FALSE;
|
|
|
|
while (hr != S_OK)
|
|
|
|
{
|
|
|
|
// TODO: Might cause us to be stuck in an infinite loop!
|
2019-03-09 13:31:37 +00:00
|
|
|
hr = D3D::context->GetData(entry.query.Get(), &result, sizeof(result), 0);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Reported pixel metrics should be referenced to native resolution
|
2016-06-13 05:41:29 +00:00
|
|
|
// TODO: Dropping the lower 2 bits from this count should be closer to actual
|
|
|
|
// hardware behavior when drawing triangles.
|
2016-06-24 08:43:46 +00:00
|
|
|
m_results[entry.query_type] += (u32)(result * EFB_WIDTH / g_renderer->GetTargetWidth() *
|
|
|
|
EFB_HEIGHT / g_renderer->GetTargetHeight());
|
|
|
|
|
|
|
|
m_query_read_pos = (m_query_read_pos + 1) % m_query_buffer.size();
|
|
|
|
--m_query_count;
|
2013-03-01 18:30:37 +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
|
|
|
while (!IsFlushed())
|
|
|
|
FlushOne();
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::WeakFlush()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
while (!IsFlushed())
|
|
|
|
{
|
|
|
|
auto& entry = m_query_buffer[m_query_read_pos];
|
|
|
|
|
|
|
|
UINT64 result = 0;
|
2019-03-09 13:31:37 +00:00
|
|
|
HRESULT hr = D3D::context->GetData(entry.query.Get(), &result, sizeof(result),
|
|
|
|
D3D11_ASYNC_GETDATA_DONOTFLUSH);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
// NOTE: Reported pixel metrics should be referenced to native resolution
|
|
|
|
m_results[entry.query_type] += (u32)(result * EFB_WIDTH / g_renderer->GetTargetWidth() *
|
|
|
|
EFB_HEIGHT / g_renderer->GetTargetHeight());
|
|
|
|
|
|
|
|
m_query_read_pos = (m_query_read_pos + 1) % m_query_buffer.size();
|
|
|
|
--m_query_count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PerfQuery::IsFlushed() const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return 0 == m_query_count;
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
|
|
|
|
2019-03-09 13:31:37 +00:00
|
|
|
} // namespace DX11
|