sync_manager.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // MIT License
  2. //
  3. // Copyright (c) Ryujinx Team and Contributors
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  6. // associated documentation files (the "Software"), to deal in the Software without restriction,
  7. // including without limitation the rights to use, copy, modify, merge, publish, distribute,
  8. // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in all copies or
  12. // substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
  15. // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  17. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. #include <algorithm>
  21. #include "sync_manager.h"
  22. #include "video_core/gpu.h"
  23. namespace Tegra {
  24. SyncptIncrManager::SyncptIncrManager(GPU& gpu_) : gpu(gpu_) {}
  25. SyncptIncrManager::~SyncptIncrManager() = default;
  26. void SyncptIncrManager::Increment(u32 id) {
  27. increments.emplace_back(0, 0, id, true);
  28. IncrementAllDone();
  29. }
  30. u32 SyncptIncrManager::IncrementWhenDone(u32 class_id, u32 id) {
  31. const u32 handle = current_id++;
  32. increments.emplace_back(handle, class_id, id);
  33. return handle;
  34. }
  35. void SyncptIncrManager::SignalDone(u32 handle) {
  36. const auto done_incr =
  37. std::find_if(increments.begin(), increments.end(),
  38. [handle](const SyncptIncr& incr) { return incr.id == handle; });
  39. if (done_incr != increments.cend()) {
  40. done_incr->complete = true;
  41. }
  42. IncrementAllDone();
  43. }
  44. void SyncptIncrManager::IncrementAllDone() {
  45. std::size_t done_count = 0;
  46. for (; done_count < increments.size(); ++done_count) {
  47. if (!increments[done_count].complete) {
  48. break;
  49. }
  50. gpu.IncrementSyncPoint(increments[done_count].syncpt_id);
  51. }
  52. increments.erase(increments.begin(), increments.begin() + done_count);
  53. }
  54. } // namespace Tegra