diff options
| author | 2021-06-06 00:11:36 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:35 -0400 | |
| commit | cffd4716c5ebf9b93505b5bfa96d9b407f349336 (patch) | |
| tree | e94c3daa5420fc066695b1082b0f0af60c5cb555 /src/video_core/shader_notify.cpp | |
| parent | vk_pipeline_cache: Add asynchronous shaders (diff) | |
| download | yuzu-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.cpp | 51 |
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 | ||
| 8 | using namespace std::chrono_literals; | 11 | using namespace std::chrono_literals; |
| 9 | 12 | ||
| 10 | namespace VideoCore { | 13 | namespace VideoCore { |
| 11 | namespace { | ||
| 12 | constexpr auto UPDATE_TICK = 32ms; | ||
| 13 | } | ||
| 14 | |||
| 15 | ShaderNotify::ShaderNotify() = default; | ||
| 16 | ShaderNotify::~ShaderNotify() = default; | ||
| 17 | 14 | ||
| 18 | std::size_t ShaderNotify::GetShadersBuilding() { | 15 | const auto TIME_TO_STOP_REPORTING = 2s; |
| 19 | const auto now = std::chrono::high_resolution_clock::now(); | 16 | |
| 20 | const auto diff = now - last_update; | 17 | int 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 | |||
| 28 | std::size_t ShaderNotify::GetShadersBuildingAccurate() { | ||
| 29 | std::shared_lock lock{mutex}; | ||
| 30 | return accurate_count; | ||
| 31 | } | ||
| 32 | |||
| 33 | void ShaderNotify::MarkShaderComplete() { | ||
| 34 | std::unique_lock lock{mutex}; | ||
| 35 | accurate_count--; | ||
| 36 | } | ||
| 37 | |||
| 38 | void ShaderNotify::MarkSharderBuilding() { | ||
| 39 | std::unique_lock lock{mutex}; | ||
| 40 | accurate_count++; | ||
| 41 | } | 34 | } |
| 42 | 35 | ||
| 43 | } // namespace VideoCore | 36 | } // namespace VideoCore |