mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-12-23 06:57:08 +00:00
64 lines
1.7 KiB
Plaintext
64 lines
1.7 KiB
Plaintext
// Copyright 2022 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "VideoBackends/Metal/MTLPerfQuery.h"
|
|
|
|
#include "VideoBackends/Metal/MTLStateTracker.h"
|
|
|
|
void Metal::PerfQuery::EnableQuery(PerfQueryGroup type)
|
|
{
|
|
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
|
|
g_state_tracker->EnablePerfQuery(type, m_current_query);
|
|
}
|
|
|
|
void Metal::PerfQuery::DisableQuery(PerfQueryGroup type)
|
|
{
|
|
if (type == PQG_ZCOMP_ZCOMPLOC || type == PQG_ZCOMP)
|
|
g_state_tracker->DisablePerfQuery();
|
|
}
|
|
|
|
void Metal::PerfQuery::ResetQuery()
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_results_mtx);
|
|
m_current_query++;
|
|
for (std::atomic<u32>& result : m_results)
|
|
result.store(0, std::memory_order_relaxed);
|
|
}
|
|
|
|
void Metal::PerfQuery::FlushResults()
|
|
{
|
|
if (IsFlushed())
|
|
return;
|
|
|
|
// There's a possibility that some active performance queries are unflushed
|
|
g_state_tracker->FlushEncoders();
|
|
g_state_tracker->NotifyOfCPUGPUSync();
|
|
|
|
std::unique_lock<std::mutex> lock(m_results_mtx);
|
|
while (!IsFlushed())
|
|
m_cv.wait(lock);
|
|
}
|
|
|
|
void Metal::PerfQuery::ReturnResults(const u64* data, const PerfQueryGroup* groups, size_t count,
|
|
u32 query_id)
|
|
{
|
|
{
|
|
std::lock_guard<std::mutex> lock(m_results_mtx);
|
|
if (m_current_query == query_id)
|
|
{
|
|
for (size_t i = 0; i < count; ++i)
|
|
{
|
|
u64 native_res_result =
|
|
data[i] * (EFB_WIDTH * EFB_HEIGHT) /
|
|
(g_framebuffer_manager->GetEFBWidth() * g_framebuffer_manager->GetEFBHeight());
|
|
|
|
native_res_result /= g_ActiveConfig.iMultisamples;
|
|
|
|
m_results[groups[i]].fetch_add(native_res_result, std::memory_order_relaxed);
|
|
}
|
|
}
|
|
m_query_count.fetch_sub(1, std::memory_order_release);
|
|
}
|
|
m_cv.notify_one();
|
|
}
|