diff options
Diffstat (limited to 'src/core')
19 files changed, 132 insertions, 59 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 555807e19..597890655 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -725,6 +725,7 @@ add_library(core STATIC | |||
| 725 | hle/service/nvnflinger/producer_listener.h | 725 | hle/service/nvnflinger/producer_listener.h |
| 726 | hle/service/nvnflinger/status.h | 726 | hle/service/nvnflinger/status.h |
| 727 | hle/service/nvnflinger/ui/fence.h | 727 | hle/service/nvnflinger/ui/fence.h |
| 728 | hle/service/nvnflinger/ui/graphic_buffer.cpp | ||
| 728 | hle/service/nvnflinger/ui/graphic_buffer.h | 729 | hle/service/nvnflinger/ui/graphic_buffer.h |
| 729 | hle/service/nvnflinger/window.h | 730 | hle/service/nvnflinger/window.h |
| 730 | hle/service/olsc/olsc.cpp | 731 | hle/service/olsc/olsc.cpp |
diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index 56f26a14a..9caed6541 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp | |||
| @@ -1563,7 +1563,7 @@ void IHidServer::CreateActiveVibrationDeviceList(HLERequestContext& ctx) { | |||
| 1563 | 1563 | ||
| 1564 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 1564 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 1565 | rb.Push(ResultSuccess); | 1565 | rb.Push(ResultSuccess); |
| 1566 | rb.PushIpcInterface<IActiveVibrationDeviceList>(system, resource_manager); | 1566 | rb.PushIpcInterface<IActiveVibrationDeviceList>(system, GetResourceManager()); |
| 1567 | } | 1567 | } |
| 1568 | 1568 | ||
| 1569 | void IHidServer::PermitVibration(HLERequestContext& ctx) { | 1569 | void IHidServer::PermitVibration(HLERequestContext& ctx) { |
diff --git a/src/core/hle/service/nvnflinger/buffer_item.h b/src/core/hle/service/nvnflinger/buffer_item.h index 3da8cc3aa..7fd808f54 100644 --- a/src/core/hle/service/nvnflinger/buffer_item.h +++ b/src/core/hle/service/nvnflinger/buffer_item.h | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | namespace Service::android { | 16 | namespace Service::android { |
| 17 | 17 | ||
| 18 | struct GraphicBuffer; | 18 | class GraphicBuffer; |
| 19 | 19 | ||
| 20 | class BufferItem final { | 20 | class BufferItem final { |
| 21 | public: | 21 | public: |
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp b/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp index 51291539d..d91886bed 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | // https://cs.android.com/android/platform/superproject/+/android-5.1.1_r38:frameworks/native/libs/gui/BufferQueueConsumer.cpp | 5 | // https://cs.android.com/android/platform/superproject/+/android-5.1.1_r38:frameworks/native/libs/gui/BufferQueueConsumer.cpp |
| 6 | 6 | ||
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "core/hle/service/nvdrv/core/nvmap.h" | ||
| 9 | #include "core/hle/service/nvnflinger/buffer_item.h" | 8 | #include "core/hle/service/nvnflinger/buffer_item.h" |
| 10 | #include "core/hle/service/nvnflinger/buffer_queue_consumer.h" | 9 | #include "core/hle/service/nvnflinger/buffer_queue_consumer.h" |
| 11 | #include "core/hle/service/nvnflinger/buffer_queue_core.h" | 10 | #include "core/hle/service/nvnflinger/buffer_queue_core.h" |
| @@ -14,9 +13,8 @@ | |||
| 14 | 13 | ||
| 15 | namespace Service::android { | 14 | namespace Service::android { |
| 16 | 15 | ||
| 17 | BufferQueueConsumer::BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_, | 16 | BufferQueueConsumer::BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_) |
| 18 | Service::Nvidia::NvCore::NvMap& nvmap_) | 17 | : core{std::move(core_)}, slots{core->slots} {} |
| 19 | : core{std::move(core_)}, slots{core->slots}, nvmap(nvmap_) {} | ||
| 20 | 18 | ||
| 21 | BufferQueueConsumer::~BufferQueueConsumer() = default; | 19 | BufferQueueConsumer::~BufferQueueConsumer() = default; |
| 22 | 20 | ||
| @@ -136,8 +134,6 @@ Status BufferQueueConsumer::ReleaseBuffer(s32 slot, u64 frame_number, const Fenc | |||
| 136 | 134 | ||
| 137 | slots[slot].buffer_state = BufferState::Free; | 135 | slots[slot].buffer_state = BufferState::Free; |
| 138 | 136 | ||
| 139 | nvmap.FreeHandle(slots[slot].graphic_buffer->BufferId(), true); | ||
| 140 | |||
| 141 | listener = core->connected_producer_listener; | 137 | listener = core->connected_producer_listener; |
| 142 | 138 | ||
| 143 | LOG_DEBUG(Service_Nvnflinger, "releasing slot {}", slot); | 139 | LOG_DEBUG(Service_Nvnflinger, "releasing slot {}", slot); |
| @@ -175,6 +171,25 @@ Status BufferQueueConsumer::Connect(std::shared_ptr<IConsumerListener> consumer_ | |||
| 175 | return Status::NoError; | 171 | return Status::NoError; |
| 176 | } | 172 | } |
| 177 | 173 | ||
| 174 | Status BufferQueueConsumer::Disconnect() { | ||
| 175 | LOG_DEBUG(Service_Nvnflinger, "called"); | ||
| 176 | |||
| 177 | std::scoped_lock lock{core->mutex}; | ||
| 178 | |||
| 179 | if (core->consumer_listener == nullptr) { | ||
| 180 | LOG_ERROR(Service_Nvnflinger, "no consumer is connected"); | ||
| 181 | return Status::BadValue; | ||
| 182 | } | ||
| 183 | |||
| 184 | core->is_abandoned = true; | ||
| 185 | core->consumer_listener = nullptr; | ||
| 186 | core->queue.clear(); | ||
| 187 | core->FreeAllBuffersLocked(); | ||
| 188 | core->SignalDequeueCondition(); | ||
| 189 | |||
| 190 | return Status::NoError; | ||
| 191 | } | ||
| 192 | |||
| 178 | Status BufferQueueConsumer::GetReleasedBuffers(u64* out_slot_mask) { | 193 | Status BufferQueueConsumer::GetReleasedBuffers(u64* out_slot_mask) { |
| 179 | if (out_slot_mask == nullptr) { | 194 | if (out_slot_mask == nullptr) { |
| 180 | LOG_ERROR(Service_Nvnflinger, "out_slot_mask may not be nullptr"); | 195 | LOG_ERROR(Service_Nvnflinger, "out_slot_mask may not be nullptr"); |
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_consumer.h b/src/core/hle/service/nvnflinger/buffer_queue_consumer.h index 50ed0bb5f..0a61e8dbd 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_consumer.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_consumer.h | |||
| @@ -13,10 +13,6 @@ | |||
| 13 | #include "core/hle/service/nvnflinger/buffer_queue_defs.h" | 13 | #include "core/hle/service/nvnflinger/buffer_queue_defs.h" |
| 14 | #include "core/hle/service/nvnflinger/status.h" | 14 | #include "core/hle/service/nvnflinger/status.h" |
| 15 | 15 | ||
| 16 | namespace Service::Nvidia::NvCore { | ||
| 17 | class NvMap; | ||
| 18 | } // namespace Service::Nvidia::NvCore | ||
| 19 | |||
| 20 | namespace Service::android { | 16 | namespace Service::android { |
| 21 | 17 | ||
| 22 | class BufferItem; | 18 | class BufferItem; |
| @@ -25,19 +21,18 @@ class IConsumerListener; | |||
| 25 | 21 | ||
| 26 | class BufferQueueConsumer final { | 22 | class BufferQueueConsumer final { |
| 27 | public: | 23 | public: |
| 28 | explicit BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_, | 24 | explicit BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_); |
| 29 | Service::Nvidia::NvCore::NvMap& nvmap_); | ||
| 30 | ~BufferQueueConsumer(); | 25 | ~BufferQueueConsumer(); |
| 31 | 26 | ||
| 32 | Status AcquireBuffer(BufferItem* out_buffer, std::chrono::nanoseconds expected_present); | 27 | Status AcquireBuffer(BufferItem* out_buffer, std::chrono::nanoseconds expected_present); |
| 33 | Status ReleaseBuffer(s32 slot, u64 frame_number, const Fence& release_fence); | 28 | Status ReleaseBuffer(s32 slot, u64 frame_number, const Fence& release_fence); |
| 34 | Status Connect(std::shared_ptr<IConsumerListener> consumer_listener, bool controlled_by_app); | 29 | Status Connect(std::shared_ptr<IConsumerListener> consumer_listener, bool controlled_by_app); |
| 30 | Status Disconnect(); | ||
| 35 | Status GetReleasedBuffers(u64* out_slot_mask); | 31 | Status GetReleasedBuffers(u64* out_slot_mask); |
| 36 | 32 | ||
| 37 | private: | 33 | private: |
| 38 | std::shared_ptr<BufferQueueCore> core; | 34 | std::shared_ptr<BufferQueueCore> core; |
| 39 | BufferQueueDefs::SlotsType& slots; | 35 | BufferQueueDefs::SlotsType& slots; |
| 40 | Service::Nvidia::NvCore::NvMap& nvmap; | ||
| 41 | }; | 36 | }; |
| 42 | 37 | ||
| 43 | } // namespace Service::android | 38 | } // namespace Service::android |
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_core.cpp b/src/core/hle/service/nvnflinger/buffer_queue_core.cpp index ed66f6f5b..4ed5e5978 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_core.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_core.cpp | |||
| @@ -14,24 +14,12 @@ BufferQueueCore::BufferQueueCore() = default; | |||
| 14 | 14 | ||
| 15 | BufferQueueCore::~BufferQueueCore() = default; | 15 | BufferQueueCore::~BufferQueueCore() = default; |
| 16 | 16 | ||
| 17 | void BufferQueueCore::NotifyShutdown() { | ||
| 18 | std::scoped_lock lock{mutex}; | ||
| 19 | |||
| 20 | is_shutting_down = true; | ||
| 21 | |||
| 22 | SignalDequeueCondition(); | ||
| 23 | } | ||
| 24 | |||
| 25 | void BufferQueueCore::SignalDequeueCondition() { | 17 | void BufferQueueCore::SignalDequeueCondition() { |
| 26 | dequeue_possible.store(true); | 18 | dequeue_possible.store(true); |
| 27 | dequeue_condition.notify_all(); | 19 | dequeue_condition.notify_all(); |
| 28 | } | 20 | } |
| 29 | 21 | ||
| 30 | bool BufferQueueCore::WaitForDequeueCondition(std::unique_lock<std::mutex>& lk) { | 22 | bool BufferQueueCore::WaitForDequeueCondition(std::unique_lock<std::mutex>& lk) { |
| 31 | if (is_shutting_down) { | ||
| 32 | return false; | ||
| 33 | } | ||
| 34 | |||
| 35 | dequeue_condition.wait(lk, [&] { return dequeue_possible.load(); }); | 23 | dequeue_condition.wait(lk, [&] { return dequeue_possible.load(); }); |
| 36 | dequeue_possible.store(false); | 24 | dequeue_possible.store(false); |
| 37 | 25 | ||
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_core.h b/src/core/hle/service/nvnflinger/buffer_queue_core.h index 9164f08a0..e513d183b 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_core.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_core.h | |||
| @@ -34,8 +34,6 @@ public: | |||
| 34 | BufferQueueCore(); | 34 | BufferQueueCore(); |
| 35 | ~BufferQueueCore(); | 35 | ~BufferQueueCore(); |
| 36 | 36 | ||
| 37 | void NotifyShutdown(); | ||
| 38 | |||
| 39 | private: | 37 | private: |
| 40 | void SignalDequeueCondition(); | 38 | void SignalDequeueCondition(); |
| 41 | bool WaitForDequeueCondition(std::unique_lock<std::mutex>& lk); | 39 | bool WaitForDequeueCondition(std::unique_lock<std::mutex>& lk); |
| @@ -74,7 +72,6 @@ private: | |||
| 74 | u32 transform_hint{}; | 72 | u32 transform_hint{}; |
| 75 | bool is_allocating{}; | 73 | bool is_allocating{}; |
| 76 | mutable std::condition_variable_any is_allocating_condition; | 74 | mutable std::condition_variable_any is_allocating_condition; |
| 77 | bool is_shutting_down{}; | ||
| 78 | }; | 75 | }; |
| 79 | 76 | ||
| 80 | } // namespace Service::android | 77 | } // namespace Service::android |
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp b/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp index 6e7a49658..5d8762d25 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp | |||
| @@ -13,7 +13,6 @@ | |||
| 13 | #include "core/hle/kernel/kernel.h" | 13 | #include "core/hle/kernel/kernel.h" |
| 14 | #include "core/hle/service/hle_ipc.h" | 14 | #include "core/hle/service/hle_ipc.h" |
| 15 | #include "core/hle/service/kernel_helpers.h" | 15 | #include "core/hle/service/kernel_helpers.h" |
| 16 | #include "core/hle/service/nvdrv/core/nvmap.h" | ||
| 17 | #include "core/hle/service/nvnflinger/buffer_queue_core.h" | 16 | #include "core/hle/service/nvnflinger/buffer_queue_core.h" |
| 18 | #include "core/hle/service/nvnflinger/buffer_queue_producer.h" | 17 | #include "core/hle/service/nvnflinger/buffer_queue_producer.h" |
| 19 | #include "core/hle/service/nvnflinger/consumer_listener.h" | 18 | #include "core/hle/service/nvnflinger/consumer_listener.h" |
| @@ -533,8 +532,6 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input, | |||
| 533 | item.is_droppable = core->dequeue_buffer_cannot_block || async; | 532 | item.is_droppable = core->dequeue_buffer_cannot_block || async; |
| 534 | item.swap_interval = swap_interval; | 533 | item.swap_interval = swap_interval; |
| 535 | 534 | ||
| 536 | nvmap.DuplicateHandle(item.graphic_buffer->BufferId(), true); | ||
| 537 | |||
| 538 | sticky_transform = sticky_transform_; | 535 | sticky_transform = sticky_transform_; |
| 539 | 536 | ||
| 540 | if (core->queue.empty()) { | 537 | if (core->queue.empty()) { |
| @@ -744,19 +741,13 @@ Status BufferQueueProducer::Disconnect(NativeWindowApi api) { | |||
| 744 | return Status::NoError; | 741 | return Status::NoError; |
| 745 | } | 742 | } |
| 746 | 743 | ||
| 747 | // HACK: We are not Android. Remove handle for items in queue, and clear queue. | ||
| 748 | // Allows synchronous destruction of nvmap handles. | ||
| 749 | for (auto& item : core->queue) { | ||
| 750 | nvmap.FreeHandle(item.graphic_buffer->BufferId(), true); | ||
| 751 | } | ||
| 752 | core->queue.clear(); | ||
| 753 | |||
| 754 | switch (api) { | 744 | switch (api) { |
| 755 | case NativeWindowApi::Egl: | 745 | case NativeWindowApi::Egl: |
| 756 | case NativeWindowApi::Cpu: | 746 | case NativeWindowApi::Cpu: |
| 757 | case NativeWindowApi::Media: | 747 | case NativeWindowApi::Media: |
| 758 | case NativeWindowApi::Camera: | 748 | case NativeWindowApi::Camera: |
| 759 | if (core->connected_api == api) { | 749 | if (core->connected_api == api) { |
| 750 | core->queue.clear(); | ||
| 760 | core->FreeAllBuffersLocked(); | 751 | core->FreeAllBuffersLocked(); |
| 761 | core->connected_producer_listener = nullptr; | 752 | core->connected_producer_listener = nullptr; |
| 762 | core->connected_api = NativeWindowApi::NoConnectedApi; | 753 | core->connected_api = NativeWindowApi::NoConnectedApi; |
| @@ -785,7 +776,7 @@ Status BufferQueueProducer::Disconnect(NativeWindowApi api) { | |||
| 785 | } | 776 | } |
| 786 | 777 | ||
| 787 | Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, | 778 | Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, |
| 788 | const std::shared_ptr<GraphicBuffer>& buffer) { | 779 | const std::shared_ptr<NvGraphicBuffer>& buffer) { |
| 789 | LOG_DEBUG(Service_Nvnflinger, "slot {}", slot); | 780 | LOG_DEBUG(Service_Nvnflinger, "slot {}", slot); |
| 790 | 781 | ||
| 791 | if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { | 782 | if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { |
| @@ -796,7 +787,7 @@ Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, | |||
| 796 | 787 | ||
| 797 | slots[slot] = {}; | 788 | slots[slot] = {}; |
| 798 | slots[slot].fence = Fence::NoFence(); | 789 | slots[slot].fence = Fence::NoFence(); |
| 799 | slots[slot].graphic_buffer = buffer; | 790 | slots[slot].graphic_buffer = std::make_shared<GraphicBuffer>(nvmap, buffer); |
| 800 | slots[slot].frame_number = 0; | 791 | slots[slot].frame_number = 0; |
| 801 | 792 | ||
| 802 | // Most games preallocate a buffer and pass a valid buffer here. However, it is possible for | 793 | // Most games preallocate a buffer and pass a valid buffer here. However, it is possible for |
| @@ -839,7 +830,7 @@ void BufferQueueProducer::Transact(HLERequestContext& ctx, TransactionId code, u | |||
| 839 | } | 830 | } |
| 840 | case TransactionId::SetPreallocatedBuffer: { | 831 | case TransactionId::SetPreallocatedBuffer: { |
| 841 | const auto slot = parcel_in.Read<s32>(); | 832 | const auto slot = parcel_in.Read<s32>(); |
| 842 | const auto buffer = parcel_in.ReadObject<GraphicBuffer>(); | 833 | const auto buffer = parcel_in.ReadObject<NvGraphicBuffer>(); |
| 843 | 834 | ||
| 844 | status = SetPreallocatedBuffer(slot, buffer); | 835 | status = SetPreallocatedBuffer(slot, buffer); |
| 845 | break; | 836 | break; |
| @@ -867,7 +858,7 @@ void BufferQueueProducer::Transact(HLERequestContext& ctx, TransactionId code, u | |||
| 867 | 858 | ||
| 868 | status = RequestBuffer(slot, &buf); | 859 | status = RequestBuffer(slot, &buf); |
| 869 | 860 | ||
| 870 | parcel_out.WriteFlattenedObject(buf); | 861 | parcel_out.WriteFlattenedObject<NvGraphicBuffer>(buf.get()); |
| 871 | break; | 862 | break; |
| 872 | } | 863 | } |
| 873 | case TransactionId::QueueBuffer: { | 864 | case TransactionId::QueueBuffer: { |
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_producer.h b/src/core/hle/service/nvnflinger/buffer_queue_producer.h index d4201c104..64c17d56c 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_producer.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_producer.h | |||
| @@ -38,6 +38,7 @@ namespace Service::android { | |||
| 38 | 38 | ||
| 39 | class BufferQueueCore; | 39 | class BufferQueueCore; |
| 40 | class IProducerListener; | 40 | class IProducerListener; |
| 41 | struct NvGraphicBuffer; | ||
| 41 | 42 | ||
| 42 | class BufferQueueProducer final : public IBinder { | 43 | class BufferQueueProducer final : public IBinder { |
| 43 | public: | 44 | public: |
| @@ -65,7 +66,7 @@ public: | |||
| 65 | bool producer_controlled_by_app, QueueBufferOutput* output); | 66 | bool producer_controlled_by_app, QueueBufferOutput* output); |
| 66 | 67 | ||
| 67 | Status Disconnect(NativeWindowApi api); | 68 | Status Disconnect(NativeWindowApi api); |
| 68 | Status SetPreallocatedBuffer(s32 slot, const std::shared_ptr<GraphicBuffer>& buffer); | 69 | Status SetPreallocatedBuffer(s32 slot, const std::shared_ptr<NvGraphicBuffer>& buffer); |
| 69 | 70 | ||
| 70 | private: | 71 | private: |
| 71 | BufferQueueProducer(const BufferQueueProducer&) = delete; | 72 | BufferQueueProducer(const BufferQueueProducer&) = delete; |
diff --git a/src/core/hle/service/nvnflinger/buffer_slot.h b/src/core/hle/service/nvnflinger/buffer_slot.h index d8c9dec3b..d25bca049 100644 --- a/src/core/hle/service/nvnflinger/buffer_slot.h +++ b/src/core/hle/service/nvnflinger/buffer_slot.h | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | namespace Service::android { | 14 | namespace Service::android { |
| 15 | 15 | ||
| 16 | struct GraphicBuffer; | 16 | class GraphicBuffer; |
| 17 | 17 | ||
| 18 | enum class BufferState : u32 { | 18 | enum class BufferState : u32 { |
| 19 | Free = 0, | 19 | Free = 0, |
diff --git a/src/core/hle/service/nvnflinger/consumer_base.cpp b/src/core/hle/service/nvnflinger/consumer_base.cpp index 4dcda8dac..1059e72bf 100644 --- a/src/core/hle/service/nvnflinger/consumer_base.cpp +++ b/src/core/hle/service/nvnflinger/consumer_base.cpp | |||
| @@ -27,6 +27,26 @@ void ConsumerBase::Connect(bool controlled_by_app) { | |||
| 27 | consumer->Connect(shared_from_this(), controlled_by_app); | 27 | consumer->Connect(shared_from_this(), controlled_by_app); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | void ConsumerBase::Abandon() { | ||
| 31 | LOG_DEBUG(Service_Nvnflinger, "called"); | ||
| 32 | |||
| 33 | std::scoped_lock lock{mutex}; | ||
| 34 | |||
| 35 | if (!is_abandoned) { | ||
| 36 | this->AbandonLocked(); | ||
| 37 | is_abandoned = true; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | void ConsumerBase::AbandonLocked() { | ||
| 42 | for (int i = 0; i < BufferQueueDefs::NUM_BUFFER_SLOTS; i++) { | ||
| 43 | this->FreeBufferLocked(i); | ||
| 44 | } | ||
| 45 | // disconnect from the BufferQueue | ||
| 46 | consumer->Disconnect(); | ||
| 47 | consumer = nullptr; | ||
| 48 | } | ||
| 49 | |||
| 30 | void ConsumerBase::FreeBufferLocked(s32 slot_index) { | 50 | void ConsumerBase::FreeBufferLocked(s32 slot_index) { |
| 31 | LOG_DEBUG(Service_Nvnflinger, "slot_index={}", slot_index); | 51 | LOG_DEBUG(Service_Nvnflinger, "slot_index={}", slot_index); |
| 32 | 52 | ||
diff --git a/src/core/hle/service/nvnflinger/consumer_base.h b/src/core/hle/service/nvnflinger/consumer_base.h index 264829414..ea3e9e97a 100644 --- a/src/core/hle/service/nvnflinger/consumer_base.h +++ b/src/core/hle/service/nvnflinger/consumer_base.h | |||
| @@ -24,6 +24,7 @@ class BufferQueueConsumer; | |||
| 24 | class ConsumerBase : public IConsumerListener, public std::enable_shared_from_this<ConsumerBase> { | 24 | class ConsumerBase : public IConsumerListener, public std::enable_shared_from_this<ConsumerBase> { |
| 25 | public: | 25 | public: |
| 26 | void Connect(bool controlled_by_app); | 26 | void Connect(bool controlled_by_app); |
| 27 | void Abandon(); | ||
| 27 | 28 | ||
| 28 | protected: | 29 | protected: |
| 29 | explicit ConsumerBase(std::unique_ptr<BufferQueueConsumer> consumer_); | 30 | explicit ConsumerBase(std::unique_ptr<BufferQueueConsumer> consumer_); |
| @@ -34,6 +35,7 @@ protected: | |||
| 34 | void OnBuffersReleased() override; | 35 | void OnBuffersReleased() override; |
| 35 | void OnSidebandStreamChanged() override; | 36 | void OnSidebandStreamChanged() override; |
| 36 | 37 | ||
| 38 | void AbandonLocked(); | ||
| 37 | void FreeBufferLocked(s32 slot_index); | 39 | void FreeBufferLocked(s32 slot_index); |
| 38 | Status AcquireBufferLocked(BufferItem* item, std::chrono::nanoseconds present_when); | 40 | Status AcquireBufferLocked(BufferItem* item, std::chrono::nanoseconds present_when); |
| 39 | Status ReleaseBufferLocked(s32 slot, const std::shared_ptr<GraphicBuffer>& graphic_buffer); | 41 | Status ReleaseBufferLocked(s32 slot, const std::shared_ptr<GraphicBuffer>& graphic_buffer); |
diff --git a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp index 6dc327b8b..d7db24f42 100644 --- a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp +++ b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp | |||
| @@ -166,7 +166,7 @@ constexpr SharedMemoryPoolLayout SharedBufferPoolLayout = [] { | |||
| 166 | }(); | 166 | }(); |
| 167 | 167 | ||
| 168 | void MakeGraphicBuffer(android::BufferQueueProducer& producer, u32 slot, u32 handle) { | 168 | void MakeGraphicBuffer(android::BufferQueueProducer& producer, u32 slot, u32 handle) { |
| 169 | auto buffer = std::make_shared<android::GraphicBuffer>(); | 169 | auto buffer = std::make_shared<android::NvGraphicBuffer>(); |
| 170 | buffer->width = SharedBufferWidth; | 170 | buffer->width = SharedBufferWidth; |
| 171 | buffer->height = SharedBufferHeight; | 171 | buffer->height = SharedBufferHeight; |
| 172 | buffer->stride = SharedBufferBlockLinearStride; | 172 | buffer->stride = SharedBufferBlockLinearStride; |
diff --git a/src/core/hle/service/nvnflinger/nvnflinger.cpp b/src/core/hle/service/nvnflinger/nvnflinger.cpp index bebb45eae..0745434c5 100644 --- a/src/core/hle/service/nvnflinger/nvnflinger.cpp +++ b/src/core/hle/service/nvnflinger/nvnflinger.cpp | |||
| @@ -47,7 +47,10 @@ void Nvnflinger::SplitVSync(std::stop_token stop_token) { | |||
| 47 | vsync_signal.Wait(); | 47 | vsync_signal.Wait(); |
| 48 | 48 | ||
| 49 | const auto lock_guard = Lock(); | 49 | const auto lock_guard = Lock(); |
| 50 | Compose(); | 50 | |
| 51 | if (!is_abandoned) { | ||
| 52 | Compose(); | ||
| 53 | } | ||
| 51 | } | 54 | } |
| 52 | } | 55 | } |
| 53 | 56 | ||
| @@ -98,7 +101,6 @@ Nvnflinger::~Nvnflinger() { | |||
| 98 | } | 101 | } |
| 99 | 102 | ||
| 100 | ShutdownLayers(); | 103 | ShutdownLayers(); |
| 101 | vsync_thread = {}; | ||
| 102 | 104 | ||
| 103 | if (nvdrv) { | 105 | if (nvdrv) { |
| 104 | nvdrv->Close(disp_fd); | 106 | nvdrv->Close(disp_fd); |
| @@ -106,12 +108,20 @@ Nvnflinger::~Nvnflinger() { | |||
| 106 | } | 108 | } |
| 107 | 109 | ||
| 108 | void Nvnflinger::ShutdownLayers() { | 110 | void Nvnflinger::ShutdownLayers() { |
| 109 | const auto lock_guard = Lock(); | 111 | // Abandon consumers. |
| 110 | for (auto& display : displays) { | 112 | { |
| 111 | for (size_t layer = 0; layer < display.GetNumLayers(); ++layer) { | 113 | const auto lock_guard = Lock(); |
| 112 | display.GetLayer(layer).Core().NotifyShutdown(); | 114 | for (auto& display : displays) { |
| 115 | for (size_t layer = 0; layer < display.GetNumLayers(); ++layer) { | ||
| 116 | display.GetLayer(layer).GetConsumer().Abandon(); | ||
| 117 | } | ||
| 113 | } | 118 | } |
| 119 | |||
| 120 | is_abandoned = true; | ||
| 114 | } | 121 | } |
| 122 | |||
| 123 | // Join the vsync thread, if it exists. | ||
| 124 | vsync_thread = {}; | ||
| 115 | } | 125 | } |
| 116 | 126 | ||
| 117 | void Nvnflinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) { | 127 | void Nvnflinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) { |
diff --git a/src/core/hle/service/nvnflinger/nvnflinger.h b/src/core/hle/service/nvnflinger/nvnflinger.h index 959d8b46b..f5d73acdb 100644 --- a/src/core/hle/service/nvnflinger/nvnflinger.h +++ b/src/core/hle/service/nvnflinger/nvnflinger.h | |||
| @@ -140,6 +140,8 @@ private: | |||
| 140 | 140 | ||
| 141 | s32 swap_interval = 1; | 141 | s32 swap_interval = 1; |
| 142 | 142 | ||
| 143 | bool is_abandoned = false; | ||
| 144 | |||
| 143 | /// Event that handles screen composition. | 145 | /// Event that handles screen composition. |
| 144 | std::shared_ptr<Core::Timing::EventType> multi_composition_event; | 146 | std::shared_ptr<Core::Timing::EventType> multi_composition_event; |
| 145 | std::shared_ptr<Core::Timing::EventType> single_composition_event; | 147 | std::shared_ptr<Core::Timing::EventType> single_composition_event; |
diff --git a/src/core/hle/service/nvnflinger/status.h b/src/core/hle/service/nvnflinger/status.h index 7af166c40..3fa0fe15b 100644 --- a/src/core/hle/service/nvnflinger/status.h +++ b/src/core/hle/service/nvnflinger/status.h | |||
| @@ -19,7 +19,7 @@ enum class Status : s32 { | |||
| 19 | Busy = -16, | 19 | Busy = -16, |
| 20 | NoInit = -19, | 20 | NoInit = -19, |
| 21 | BadValue = -22, | 21 | BadValue = -22, |
| 22 | InvalidOperation = -37, | 22 | InvalidOperation = -38, |
| 23 | BufferNeedsReallocation = 1, | 23 | BufferNeedsReallocation = 1, |
| 24 | ReleaseAllBuffers = 2, | 24 | ReleaseAllBuffers = 2, |
| 25 | }; | 25 | }; |
diff --git a/src/core/hle/service/nvnflinger/ui/graphic_buffer.cpp b/src/core/hle/service/nvnflinger/ui/graphic_buffer.cpp new file mode 100644 index 000000000..ce70946ec --- /dev/null +++ b/src/core/hle/service/nvnflinger/ui/graphic_buffer.cpp | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #include "core/hle/service/nvdrv/core/nvmap.h" | ||
| 5 | #include "core/hle/service/nvnflinger/ui/graphic_buffer.h" | ||
| 6 | |||
| 7 | namespace Service::android { | ||
| 8 | |||
| 9 | static NvGraphicBuffer GetBuffer(std::shared_ptr<NvGraphicBuffer>& buffer) { | ||
| 10 | if (buffer) { | ||
| 11 | return *buffer; | ||
| 12 | } else { | ||
| 13 | return {}; | ||
| 14 | } | ||
| 15 | } | ||
| 16 | |||
| 17 | GraphicBuffer::GraphicBuffer(u32 width_, u32 height_, PixelFormat format_, u32 usage_) | ||
| 18 | : NvGraphicBuffer(width_, height_, format_, usage_), m_nvmap(nullptr) {} | ||
| 19 | |||
| 20 | GraphicBuffer::GraphicBuffer(Service::Nvidia::NvCore::NvMap& nvmap, | ||
| 21 | std::shared_ptr<NvGraphicBuffer> buffer) | ||
| 22 | : NvGraphicBuffer(GetBuffer(buffer)), m_nvmap(std::addressof(nvmap)) { | ||
| 23 | if (this->BufferId() > 0) { | ||
| 24 | m_nvmap->DuplicateHandle(this->BufferId(), true); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | GraphicBuffer::~GraphicBuffer() { | ||
| 29 | if (m_nvmap != nullptr && this->BufferId() > 0) { | ||
| 30 | m_nvmap->FreeHandle(this->BufferId(), true); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | } // namespace Service::android | ||
diff --git a/src/core/hle/service/nvnflinger/ui/graphic_buffer.h b/src/core/hle/service/nvnflinger/ui/graphic_buffer.h index 3eac5cedd..da430aa75 100644 --- a/src/core/hle/service/nvnflinger/ui/graphic_buffer.h +++ b/src/core/hle/service/nvnflinger/ui/graphic_buffer.h | |||
| @@ -6,16 +6,22 @@ | |||
| 6 | 6 | ||
| 7 | #pragma once | 7 | #pragma once |
| 8 | 8 | ||
| 9 | #include <memory> | ||
| 10 | |||
| 9 | #include "common/common_funcs.h" | 11 | #include "common/common_funcs.h" |
| 10 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 11 | #include "core/hle/service/nvnflinger/pixel_format.h" | 13 | #include "core/hle/service/nvnflinger/pixel_format.h" |
| 12 | 14 | ||
| 15 | namespace Service::Nvidia::NvCore { | ||
| 16 | class NvMap; | ||
| 17 | } // namespace Service::Nvidia::NvCore | ||
| 18 | |||
| 13 | namespace Service::android { | 19 | namespace Service::android { |
| 14 | 20 | ||
| 15 | struct GraphicBuffer final { | 21 | struct NvGraphicBuffer { |
| 16 | constexpr GraphicBuffer() = default; | 22 | constexpr NvGraphicBuffer() = default; |
| 17 | 23 | ||
| 18 | constexpr GraphicBuffer(u32 width_, u32 height_, PixelFormat format_, u32 usage_) | 24 | constexpr NvGraphicBuffer(u32 width_, u32 height_, PixelFormat format_, u32 usage_) |
| 19 | : width{static_cast<s32>(width_)}, height{static_cast<s32>(height_)}, format{format_}, | 25 | : width{static_cast<s32>(width_)}, height{static_cast<s32>(height_)}, format{format_}, |
| 20 | usage{static_cast<s32>(usage_)} {} | 26 | usage{static_cast<s32>(usage_)} {} |
| 21 | 27 | ||
| @@ -93,6 +99,17 @@ struct GraphicBuffer final { | |||
| 93 | u32 offset{}; | 99 | u32 offset{}; |
| 94 | INSERT_PADDING_WORDS(60); | 100 | INSERT_PADDING_WORDS(60); |
| 95 | }; | 101 | }; |
| 96 | static_assert(sizeof(GraphicBuffer) == 0x16C, "GraphicBuffer has wrong size"); | 102 | static_assert(sizeof(NvGraphicBuffer) == 0x16C, "NvGraphicBuffer has wrong size"); |
| 103 | |||
| 104 | class GraphicBuffer final : public NvGraphicBuffer { | ||
| 105 | public: | ||
| 106 | explicit GraphicBuffer(u32 width, u32 height, PixelFormat format, u32 usage); | ||
| 107 | explicit GraphicBuffer(Service::Nvidia::NvCore::NvMap& nvmap, | ||
| 108 | std::shared_ptr<NvGraphicBuffer> buffer); | ||
| 109 | ~GraphicBuffer(); | ||
| 110 | |||
| 111 | private: | ||
| 112 | Service::Nvidia::NvCore::NvMap* m_nvmap{}; | ||
| 113 | }; | ||
| 97 | 114 | ||
| 98 | } // namespace Service::android | 115 | } // namespace Service::android |
diff --git a/src/core/hle/service/vi/display/vi_display.cpp b/src/core/hle/service/vi/display/vi_display.cpp index f0b5eff8a..d30f49877 100644 --- a/src/core/hle/service/vi/display/vi_display.cpp +++ b/src/core/hle/service/vi/display/vi_display.cpp | |||
| @@ -35,7 +35,7 @@ static BufferQueue CreateBufferQueue(KernelHelpers::ServiceContext& service_cont | |||
| 35 | return { | 35 | return { |
| 36 | buffer_queue_core, | 36 | buffer_queue_core, |
| 37 | std::make_unique<android::BufferQueueProducer>(service_context, buffer_queue_core, nvmap), | 37 | std::make_unique<android::BufferQueueProducer>(service_context, buffer_queue_core, nvmap), |
| 38 | std::make_unique<android::BufferQueueConsumer>(buffer_queue_core, nvmap)}; | 38 | std::make_unique<android::BufferQueueConsumer>(buffer_queue_core)}; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | Display::Display(u64 id, std::string name_, | 41 | Display::Display(u64 id, std::string name_, |