summaryrefslogtreecommitdiff
path: root/src/video_core/shader_notify.cpp
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-06-06 00:11:36 -0300
committerGravatar ameerj2021-07-22 21:51:35 -0400
commitcffd4716c5ebf9b93505b5bfa96d9b407f349336 (patch)
treee94c3daa5420fc066695b1082b0f0af60c5cb555 /src/video_core/shader_notify.cpp
parentvk_pipeline_cache: Add asynchronous shaders (diff)
downloadyuzu-cffd4716c5ebf9b93505b5bfa96d9b407f349336.tar.gz
yuzu-cffd4716c5ebf9b93505b5bfa96d9b407f349336.tar.xz
yuzu-cffd4716c5ebf9b93505b5bfa96d9b407f349336.zip
vk_pipeline_cache,shader_notify: Add shader notifications
Diffstat (limited to 'src/video_core/shader_notify.cpp')
-rw-r--r--src/video_core/shader_notify.cpp51
1 files changed, 22 insertions, 29 deletions
diff --git a/src/video_core/shader_notify.cpp b/src/video_core/shader_notify.cpp
index 693e47158..dc6995b46 100644
--- a/src/video_core/shader_notify.cpp
+++ b/src/video_core/shader_notify.cpp
@@ -2,42 +2,35 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <mutex> 5#include <atomic>
6#include <chrono>
7#include <optional>
8
6#include "video_core/shader_notify.h" 9#include "video_core/shader_notify.h"
7 10
8using namespace std::chrono_literals; 11using namespace std::chrono_literals;
9 12
10namespace VideoCore { 13namespace VideoCore {
11namespace {
12constexpr auto UPDATE_TICK = 32ms;
13}
14
15ShaderNotify::ShaderNotify() = default;
16ShaderNotify::~ShaderNotify() = default;
17 14
18std::size_t ShaderNotify::GetShadersBuilding() { 15const auto TIME_TO_STOP_REPORTING = 2s;
19 const auto now = std::chrono::high_resolution_clock::now(); 16
20 const auto diff = now - last_update; 17int ShaderNotify::ShadersBuilding() noexcept {
21 if (diff > UPDATE_TICK) { 18 const int now_complete = num_complete.load(std::memory_order::relaxed);
22 std::shared_lock lock(mutex); 19 const int now_building = num_building.load(std::memory_order::relaxed);
23 last_updated_count = accurate_count; 20 if (now_complete == now_building) {
21 const auto now = std::chrono::high_resolution_clock::now();
22 if (completed && num_complete == num_when_completed) {
23 if (now - complete_time > TIME_TO_STOP_REPORTING) {
24 report_base = now_complete;
25 completed = false;
26 }
27 } else {
28 completed = true;
29 num_when_completed = num_complete;
30 complete_time = now;
31 }
24 } 32 }
25 return last_updated_count; 33 return now_building - report_base;
26}
27
28std::size_t ShaderNotify::GetShadersBuildingAccurate() {
29 std::shared_lock lock{mutex};
30 return accurate_count;
31}
32
33void ShaderNotify::MarkShaderComplete() {
34 std::unique_lock lock{mutex};
35 accurate_count--;
36}
37
38void ShaderNotify::MarkSharderBuilding() {
39 std::unique_lock lock{mutex};
40 accurate_count++;
41} 34}
42 35
43} // namespace VideoCore 36} // namespace VideoCore