2015-05-24 04:32:32 +00:00
|
|
|
// Copyright 2012 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-09-15 12:50:34 +00:00
|
|
|
#include "VideoBackends/D3D/D3DPerfQuery.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
|
|
|
|
|
|
|
namespace DX11
|
|
|
|
{
|
|
|
|
PerfQuery::PerfQuery() : m_query_read_pos()
|
|
|
|
{
|
2014-02-15 06:12:13 +00:00
|
|
|
for (ActiveQuery& entry : m_query_buffer)
|
2013-03-01 18:30:37 +00:00
|
|
|
{
|
|
|
|
D3D11_QUERY_DESC qdesc = CD3D11_QUERY_DESC(D3D11_QUERY_OCCLUSION, 0);
|
2014-02-15 06:12:13 +00:00
|
|
|
D3D::device->CreateQuery(&qdesc, &entry.query);
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
2014-02-15 06:12:13 +00:00
|
|
|
|
2013-03-01 18:30:37 +00:00
|
|
|
ResetQuery();
|
|
|
|
}
|
|
|
|
|
2019-03-09 13:31:37 +00:00
|
|
|
PerfQuery::~PerfQuery() = default;
|
2013-03-01 18:30:37 +00:00
|
|
|
|
|
|
|
void PerfQuery::EnableQuery(PerfQueryGroup type)
|
|
|
|
{
|
|
|
|
// Is this sane?
|
2014-02-15 06:12:13 +00:00
|
|
|
if (m_query_count > m_query_buffer.size() / 2)
|
2013-03-01 18:30:37 +00:00
|
|
|
WeakFlush();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-02-15 06:12:13 +00:00
|
|
|
if (m_query_buffer.size() == m_query_count)
|
2013-03-01 18:30:37 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
FlushOne();
|
2020-11-09 08:01:58 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Flushed query buffer early!");
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-03-01 18:30:37 +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()];
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-03-09 13:31:37 +00:00
|
|
|
D3D::context->Begin(entry.query.Get());
|
2013-03-01 18:30:37 +00:00
|
|
|
entry.query_type = type;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-03-01 18:30:37 +00:00
|
|
|
++m_query_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::DisableQuery(PerfQueryGroup type)
|
|
|
|
{
|
|
|
|
// stop 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() - 1) %
|
|
|
|
m_query_buffer.size()];
|
2019-03-09 13:31:37 +00:00
|
|
|
D3D::context->End(entry.query.Get());
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::ResetQuery()
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
u32 result = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-03-01 18:30:37 +00:00
|
|
|
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-24 08:43:46 +00:00
|
|
|
|
2016-06-13 05:41:29 +00:00
|
|
|
return result;
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::FlushOne()
|
|
|
|
{
|
|
|
|
auto& entry = m_query_buffer[m_query_read_pos];
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-03-01 18:30:37 +00:00
|
|
|
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);
|
2013-03-01 18:30:37 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-03-01 22:12:41 +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.
|
2013-11-13 09:03:46 +00:00
|
|
|
m_results[entry.query_type] += (u32)(result * EFB_WIDTH / g_renderer->GetTargetWidth() *
|
|
|
|
EFB_HEIGHT / g_renderer->GetTargetHeight());
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-02-15 06:12:13 +00:00
|
|
|
m_query_read_pos = (m_query_read_pos + 1) % m_query_buffer.size();
|
2013-03-01 18:30:37 +00:00
|
|
|
--m_query_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: could selectively flush things, but I don't think that will do much
|
|
|
|
void PerfQuery::FlushResults()
|
|
|
|
{
|
|
|
|
while (!IsFlushed())
|
|
|
|
FlushOne();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerfQuery::WeakFlush()
|
|
|
|
{
|
|
|
|
while (!IsFlushed())
|
|
|
|
{
|
|
|
|
auto& entry = m_query_buffer[m_query_read_pos];
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-03-01 18:30:37 +00:00
|
|
|
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
|
|
|
|
2013-03-01 18:30:37 +00:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2013-03-01 22:57:56 +00:00
|
|
|
// NOTE: Reported pixel metrics should be referenced to native resolution
|
2013-11-13 09:03:46 +00:00
|
|
|
m_results[entry.query_type] += (u32)(result * EFB_WIDTH / g_renderer->GetTargetWidth() *
|
|
|
|
EFB_HEIGHT / g_renderer->GetTargetHeight());
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-02-15 06:12:13 +00:00
|
|
|
m_query_read_pos = (m_query_read_pos + 1) % m_query_buffer.size();
|
2013-03-01 18:30:37 +00:00
|
|
|
--m_query_count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PerfQuery::IsFlushed() const
|
|
|
|
{
|
|
|
|
return 0 == m_query_count;
|
|
|
|
}
|
|
|
|
|
2019-03-09 13:31:37 +00:00
|
|
|
} // namespace DX11
|