diff options
| author | 2022-03-19 21:52:08 -0700 | |
|---|---|---|
| committer | 2022-03-24 18:13:33 -0700 | |
| commit | 650c9d0d627b1c926a07d82d0248f283ccbd8a1b (patch) | |
| tree | 645d5594c010ab7ee1a334ba1ff1176c465c6798 /src | |
| parent | hle: nvflinger: Migrate android namespace -> Service::android. (diff) | |
| download | yuzu-650c9d0d627b1c926a07d82d0248f283ccbd8a1b.tar.gz yuzu-650c9d0d627b1c926a07d82d0248f283ccbd8a1b.tar.xz yuzu-650c9d0d627b1c926a07d82d0248f283ccbd8a1b.zip | |
hle: nvflinger: Use std::chrono for present_ns.
Diffstat (limited to 'src')
7 files changed, 30 insertions, 25 deletions
diff --git a/src/core/hle/service/nvflinger/buffer_item_consumer.cpp b/src/core/hle/service/nvflinger/buffer_item_consumer.cpp index 508df3a12..7f32c0775 100644 --- a/src/core/hle/service/nvflinger/buffer_item_consumer.cpp +++ b/src/core/hle/service/nvflinger/buffer_item_consumer.cpp | |||
| @@ -15,7 +15,7 @@ namespace Service::android { | |||
| 15 | BufferItemConsumer::BufferItemConsumer(std::unique_ptr<BufferQueueConsumer> consumer_) | 15 | BufferItemConsumer::BufferItemConsumer(std::unique_ptr<BufferQueueConsumer> consumer_) |
| 16 | : ConsumerBase{std::move(consumer_)} {} | 16 | : ConsumerBase{std::move(consumer_)} {} |
| 17 | 17 | ||
| 18 | Status BufferItemConsumer::AcquireBuffer(BufferItem* item, u64 present_when_ns, | 18 | Status BufferItemConsumer::AcquireBuffer(BufferItem* item, std::chrono::nanoseconds present_when, |
| 19 | bool wait_for_fence) { | 19 | bool wait_for_fence) { |
| 20 | if (!item) { | 20 | if (!item) { |
| 21 | return Status::BadValue; | 21 | return Status::BadValue; |
| @@ -23,7 +23,7 @@ Status BufferItemConsumer::AcquireBuffer(BufferItem* item, u64 present_when_ns, | |||
| 23 | 23 | ||
| 24 | std::unique_lock lock(mutex); | 24 | std::unique_lock lock(mutex); |
| 25 | 25 | ||
| 26 | if (const auto status = AcquireBufferLocked(item, present_when_ns); status != Status::NoError) { | 26 | if (const auto status = AcquireBufferLocked(item, present_when); status != Status::NoError) { |
| 27 | if (status != Status::NoBufferAvailable) { | 27 | if (status != Status::NoBufferAvailable) { |
| 28 | LOG_ERROR(Service_NVFlinger, "Failed to acquire buffer: {}", status); | 28 | LOG_ERROR(Service_NVFlinger, "Failed to acquire buffer: {}", status); |
| 29 | } | 29 | } |
diff --git a/src/core/hle/service/nvflinger/buffer_item_consumer.h b/src/core/hle/service/nvflinger/buffer_item_consumer.h index 99d592960..536db81e2 100644 --- a/src/core/hle/service/nvflinger/buffer_item_consumer.h +++ b/src/core/hle/service/nvflinger/buffer_item_consumer.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #pragma once | 7 | #pragma once |
| 8 | 8 | ||
| 9 | #include <chrono> | ||
| 9 | #include <memory> | 10 | #include <memory> |
| 10 | 11 | ||
| 11 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| @@ -19,7 +20,8 @@ class BufferItem; | |||
| 19 | class BufferItemConsumer final : public ConsumerBase { | 20 | class BufferItemConsumer final : public ConsumerBase { |
| 20 | public: | 21 | public: |
| 21 | explicit BufferItemConsumer(std::unique_ptr<BufferQueueConsumer> consumer); | 22 | explicit BufferItemConsumer(std::unique_ptr<BufferQueueConsumer> consumer); |
| 22 | Status AcquireBuffer(BufferItem* item, u64 present_when_ns, bool wait_for_fence = true); | 23 | Status AcquireBuffer(BufferItem* item, std::chrono::nanoseconds present_when, |
| 24 | bool wait_for_fence = true); | ||
| 23 | Status ReleaseBuffer(const BufferItem& item, Fence& release_fence); | 25 | Status ReleaseBuffer(const BufferItem& item, Fence& release_fence); |
| 24 | }; | 26 | }; |
| 25 | 27 | ||
diff --git a/src/core/hle/service/nvflinger/buffer_queue_consumer.cpp b/src/core/hle/service/nvflinger/buffer_queue_consumer.cpp index 865f696d7..5184d876a 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_consumer.cpp +++ b/src/core/hle/service/nvflinger/buffer_queue_consumer.cpp | |||
| @@ -17,7 +17,8 @@ BufferQueueConsumer::BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_) | |||
| 17 | 17 | ||
| 18 | BufferQueueConsumer::~BufferQueueConsumer() = default; | 18 | BufferQueueConsumer::~BufferQueueConsumer() = default; |
| 19 | 19 | ||
| 20 | Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, s64 expected_presenst_ns, | 20 | Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, |
| 21 | std::chrono::nanoseconds expected_present, | ||
| 21 | u64 max_frame_number) { | 22 | u64 max_frame_number) { |
| 22 | s32 num_dropped_buffers{}; | 23 | s32 num_dropped_buffers{}; |
| 23 | 24 | ||
| @@ -26,12 +27,10 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, s64 expected_p | |||
| 26 | std::unique_lock lock(core->mutex); | 27 | std::unique_lock lock(core->mutex); |
| 27 | 28 | ||
| 28 | // Check that the consumer doesn't currently have the maximum number of buffers acquired. | 29 | // Check that the consumer doesn't currently have the maximum number of buffers acquired. |
| 29 | s32 num_acquired_buffers{}; | 30 | const s32 num_acquired_buffers{ |
| 30 | for (const auto& slot : slots) { | 31 | static_cast<s32>(std::count_if(slots.begin(), slots.end(), [](const auto& slot) { |
| 31 | if (slot.buffer_state == BufferState::Acquired) { | 32 | return slot.buffer_state == BufferState::Acquired; |
| 32 | ++num_acquired_buffers; | 33 | }))}; |
| 33 | } | ||
| 34 | } | ||
| 35 | 34 | ||
| 36 | if (num_acquired_buffers >= core->max_acquired_buffer_count + 1) { | 35 | if (num_acquired_buffers >= core->max_acquired_buffer_count + 1) { |
| 37 | LOG_ERROR(Service_NVFlinger, "max acquired buffer count reached: {} (max {})", | 36 | LOG_ERROR(Service_NVFlinger, "max acquired buffer count reached: {} (max {})", |
| @@ -46,8 +45,8 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, s64 expected_p | |||
| 46 | 45 | ||
| 47 | auto front(core->queue.begin()); | 46 | auto front(core->queue.begin()); |
| 48 | 47 | ||
| 49 | // If expected_presenst_ns is specified, we may not want to return a buffer yet. | 48 | // If expected_present is specified, we may not want to return a buffer yet. |
| 50 | if (expected_presenst_ns != 0) { | 49 | if (expected_present.count() != 0) { |
| 51 | constexpr auto MAX_REASONABLE_NSEC = 1000000000LL; // 1 second | 50 | constexpr auto MAX_REASONABLE_NSEC = 1000000000LL; // 1 second |
| 52 | 51 | ||
| 53 | // The expected_presenst_ns argument indicates when the buffer is expected to be | 52 | // The expected_presenst_ns argument indicates when the buffer is expected to be |
| @@ -63,17 +62,17 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, s64 expected_p | |||
| 63 | 62 | ||
| 64 | // If entry[1] is timely, drop entry[0] (and repeat). | 63 | // If entry[1] is timely, drop entry[0] (and repeat). |
| 65 | const auto desired_present = buffer_item.timestamp; | 64 | const auto desired_present = buffer_item.timestamp; |
| 66 | if (desired_present < expected_presenst_ns - MAX_REASONABLE_NSEC || | 65 | if (desired_present < expected_present.count() - MAX_REASONABLE_NSEC || |
| 67 | desired_present > expected_presenst_ns) { | 66 | desired_present > expected_present.count()) { |
| 68 | // This buffer is set to display in the near future, or desired_present is | 67 | // This buffer is set to display in the near future, or desired_present is |
| 69 | // garbage. | 68 | // garbage. |
| 70 | LOG_DEBUG(Service_NVFlinger, "nodrop desire={} expect={}", desired_present, | 69 | LOG_DEBUG(Service_NVFlinger, "nodrop desire={} expect={}", desired_present, |
| 71 | expected_presenst_ns); | 70 | expected_present.count()); |
| 72 | break; | 71 | break; |
| 73 | } | 72 | } |
| 74 | 73 | ||
| 75 | LOG_DEBUG(Service_NVFlinger, "drop desire={} expect={} size={}", desired_present, | 74 | LOG_DEBUG(Service_NVFlinger, "drop desire={} expect={} size={}", desired_present, |
| 76 | expected_presenst_ns, core->queue.size()); | 75 | expected_present.count(), core->queue.size()); |
| 77 | 76 | ||
| 78 | if (core->StillTracking(&*front)) { | 77 | if (core->StillTracking(&*front)) { |
| 79 | // Front buffer is still in mSlots, so mark the slot as free | 78 | // Front buffer is still in mSlots, so mark the slot as free |
| @@ -89,19 +88,20 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer, s64 expected_p | |||
| 89 | 88 | ||
| 90 | // See if the front buffer is ready to be acquired. | 89 | // See if the front buffer is ready to be acquired. |
| 91 | const auto desired_present = front->timestamp; | 90 | const auto desired_present = front->timestamp; |
| 92 | const auto buffer_is_due = desired_present <= expected_presenst_ns || | 91 | const auto buffer_is_due = |
| 93 | desired_present > expected_presenst_ns + MAX_REASONABLE_NSEC; | 92 | desired_present <= expected_present.count() || |
| 93 | desired_present > expected_present.count() + MAX_REASONABLE_NSEC; | ||
| 94 | const auto consumer_is_ready = | 94 | const auto consumer_is_ready = |
| 95 | max_frame_number > 0 ? front->frame_number <= max_frame_number : true; | 95 | max_frame_number > 0 ? front->frame_number <= max_frame_number : true; |
| 96 | 96 | ||
| 97 | if (!buffer_is_due || !consumer_is_ready) { | 97 | if (!buffer_is_due || !consumer_is_ready) { |
| 98 | LOG_DEBUG(Service_NVFlinger, "defer desire={} expect={}", desired_present, | 98 | LOG_DEBUG(Service_NVFlinger, "defer desire={} expect={}", desired_present, |
| 99 | expected_presenst_ns); | 99 | expected_present.count()); |
| 100 | return Status::PresentLater; | 100 | return Status::PresentLater; |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | LOG_DEBUG(Service_NVFlinger, "accept desire={} expect={}", desired_present, | 103 | LOG_DEBUG(Service_NVFlinger, "accept desire={} expect={}", desired_present, |
| 104 | expected_presenst_ns); | 104 | expected_present.count()); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | const auto slot = front->slot; | 107 | const auto slot = front->slot; |
diff --git a/src/core/hle/service/nvflinger/buffer_queue_consumer.h b/src/core/hle/service/nvflinger/buffer_queue_consumer.h index 26981ed19..f22854394 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_consumer.h +++ b/src/core/hle/service/nvflinger/buffer_queue_consumer.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #pragma once | 7 | #pragma once |
| 8 | 8 | ||
| 9 | #include <chrono> | ||
| 9 | #include <memory> | 10 | #include <memory> |
| 10 | 11 | ||
| 11 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| @@ -23,7 +24,7 @@ public: | |||
| 23 | explicit BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_); | 24 | explicit BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_); |
| 24 | ~BufferQueueConsumer(); | 25 | ~BufferQueueConsumer(); |
| 25 | 26 | ||
| 26 | Status AcquireBuffer(BufferItem* out_buffer, s64 expected_presenst_ns, | 27 | Status AcquireBuffer(BufferItem* out_buffer, std::chrono::nanoseconds expected_present, |
| 27 | u64 max_frame_number = 0); | 28 | u64 max_frame_number = 0); |
| 28 | Status ReleaseBuffer(s32 slot, u64 frame_number, const Fence& release_fence); | 29 | Status ReleaseBuffer(s32 slot, u64 frame_number, const Fence& release_fence); |
| 29 | Status Connect(std::shared_ptr<IConsumerListener> consumer_listener, bool controlled_by_app); | 30 | Status Connect(std::shared_ptr<IConsumerListener> consumer_listener, bool controlled_by_app); |
diff --git a/src/core/hle/service/nvflinger/consumer_base.cpp b/src/core/hle/service/nvflinger/consumer_base.cpp index c752ffc8e..0524463bd 100644 --- a/src/core/hle/service/nvflinger/consumer_base.cpp +++ b/src/core/hle/service/nvflinger/consumer_base.cpp | |||
| @@ -52,14 +52,14 @@ void ConsumerBase::OnBuffersReleased() { | |||
| 52 | 52 | ||
| 53 | void ConsumerBase::OnSidebandStreamChanged() {} | 53 | void ConsumerBase::OnSidebandStreamChanged() {} |
| 54 | 54 | ||
| 55 | Status ConsumerBase::AcquireBufferLocked(BufferItem* item, u64 present_when_ns, | 55 | Status ConsumerBase::AcquireBufferLocked(BufferItem* item, std::chrono::nanoseconds present_when, |
| 56 | u64 max_frame_number) { | 56 | u64 max_frame_number) { |
| 57 | if (is_abandoned) { | 57 | if (is_abandoned) { |
| 58 | LOG_ERROR(Service_NVFlinger, "consumer is abandoned!"); | 58 | LOG_ERROR(Service_NVFlinger, "consumer is abandoned!"); |
| 59 | return Status::NoInit; | 59 | return Status::NoInit; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | Status err = consumer->AcquireBuffer(item, present_when_ns, max_frame_number); | 62 | Status err = consumer->AcquireBuffer(item, present_when, max_frame_number); |
| 63 | if (err != Status::NoError) { | 63 | if (err != Status::NoError) { |
| 64 | return err; | 64 | return err; |
| 65 | } | 65 | } |
diff --git a/src/core/hle/service/nvflinger/consumer_base.h b/src/core/hle/service/nvflinger/consumer_base.h index ae34ea0a9..453a47349 100644 --- a/src/core/hle/service/nvflinger/consumer_base.h +++ b/src/core/hle/service/nvflinger/consumer_base.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #pragma once | 7 | #pragma once |
| 8 | 8 | ||
| 9 | #include <array> | 9 | #include <array> |
| 10 | #include <chrono> | ||
| 10 | #include <memory> | 11 | #include <memory> |
| 11 | #include <mutex> | 12 | #include <mutex> |
| 12 | 13 | ||
| @@ -34,7 +35,8 @@ protected: | |||
| 34 | virtual void OnSidebandStreamChanged() override; | 35 | virtual void OnSidebandStreamChanged() override; |
| 35 | 36 | ||
| 36 | void FreeBufferLocked(s32 slot_index); | 37 | void FreeBufferLocked(s32 slot_index); |
| 37 | Status AcquireBufferLocked(BufferItem* item, u64 present_when_ns, u64 max_frame_number = 0); | 38 | Status AcquireBufferLocked(BufferItem* item, std::chrono::nanoseconds present_when, |
| 39 | u64 max_frame_number = 0); | ||
| 38 | Status ReleaseBufferLocked(s32 slot, const std::shared_ptr<GraphicBuffer> graphic_buffer); | 40 | Status ReleaseBufferLocked(s32 slot, const std::shared_ptr<GraphicBuffer> graphic_buffer); |
| 39 | bool StillTracking(s32 slot, const std::shared_ptr<GraphicBuffer> graphic_buffer); | 41 | bool StillTracking(s32 slot, const std::shared_ptr<GraphicBuffer> graphic_buffer); |
| 40 | Status AddReleaseFenceLocked(s32 slot, const std::shared_ptr<GraphicBuffer> graphic_buffer, | 42 | Status AddReleaseFenceLocked(s32 slot, const std::shared_ptr<GraphicBuffer> graphic_buffer, |
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index e21dc902a..76ce1fbfd 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp | |||
| @@ -240,7 +240,7 @@ void NVFlinger::Compose() { | |||
| 240 | VI::Layer& layer = display.GetLayer(0); | 240 | VI::Layer& layer = display.GetLayer(0); |
| 241 | 241 | ||
| 242 | android::BufferItem buffer{}; | 242 | android::BufferItem buffer{}; |
| 243 | const auto status = layer.GetConsumer().AcquireBuffer(&buffer, 0, false); | 243 | const auto status = layer.GetConsumer().AcquireBuffer(&buffer, {}, false); |
| 244 | 244 | ||
| 245 | if (status != android::Status::NoError) { | 245 | if (status != android::Status::NoError) { |
| 246 | continue; | 246 | continue; |