summaryrefslogtreecommitdiffstats
path: root/src/video_core/shader_notify.cpp
blob: bcaf5f5754725c73dd14760a6da29771ebc4a5a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <atomic>
#include <chrono>
#include <optional>

#include "video_core/shader_notify.h"

using namespace std::chrono_literals;

namespace VideoCore {

const auto TIME_TO_STOP_REPORTING = 2s;

int ShaderNotify::ShadersBuilding() noexcept {
    const int now_complete = num_complete.load(std::memory_order::relaxed);
    const int now_building = num_building.load(std::memory_order::relaxed);
    if (now_complete == now_building) {
        const auto now = std::chrono::steady_clock::now();
        if (completed && num_complete == num_when_completed) {
            if (now - complete_time > TIME_TO_STOP_REPORTING) {
                report_base = now_complete;
                completed = false;
            }
        } else {
            completed = true;
            num_when_completed = num_complete;
            complete_time = now;
        }
    }
    return now_building - report_base;
}

} // namespace VideoCore