diff options
| author | 2024-02-14 11:39:42 -0500 | |
|---|---|---|
| committer | 2024-02-17 18:01:41 -0500 | |
| commit | ee8eccc5fa473f2ce210eb4e242e8eca40594db7 (patch) | |
| tree | 5c38fc738e52be88eddd7733e0fdeb248ef4783f /src/core/hle/service/nvnflinger | |
| parent | am: unify display layer management (diff) | |
| download | yuzu-ee8eccc5fa473f2ce210eb4e242e8eca40594db7.tar.gz yuzu-ee8eccc5fa473f2ce210eb4e242e8eca40594db7.tar.xz yuzu-ee8eccc5fa473f2ce210eb4e242e8eca40594db7.zip | |
nvnflinger: convert to process
Diffstat (limited to 'src/core/hle/service/nvnflinger')
| -rw-r--r-- | src/core/hle/service/nvnflinger/hos_binder_driver.cpp | 56 | ||||
| -rw-r--r-- | src/core/hle/service/nvnflinger/hos_binder_driver.h | 39 | ||||
| -rw-r--r-- | src/core/hle/service/nvnflinger/nvnflinger.cpp | 53 | ||||
| -rw-r--r-- | src/core/hle/service/nvnflinger/nvnflinger.h | 6 |
4 files changed, 123 insertions, 31 deletions
diff --git a/src/core/hle/service/nvnflinger/hos_binder_driver.cpp b/src/core/hle/service/nvnflinger/hos_binder_driver.cpp new file mode 100644 index 000000000..e09d72047 --- /dev/null +++ b/src/core/hle/service/nvnflinger/hos_binder_driver.cpp | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/hle/service/cmif_serialization.h" | ||
| 5 | #include "core/hle/service/nvnflinger/binder.h" | ||
| 6 | #include "core/hle/service/nvnflinger/hos_binder_driver.h" | ||
| 7 | #include "core/hle/service/nvnflinger/hos_binder_driver_server.h" | ||
| 8 | |||
| 9 | namespace Service::Nvnflinger { | ||
| 10 | |||
| 11 | IHOSBinderDriver::IHOSBinderDriver(Core::System& system_, | ||
| 12 | std::shared_ptr<HosBinderDriverServer> server, | ||
| 13 | std::shared_ptr<Nvnflinger> surface_flinger) | ||
| 14 | : ServiceFramework{system_, "IHOSBinderDriver"}, m_server(server), | ||
| 15 | m_surface_flinger(surface_flinger) { | ||
| 16 | static const FunctionInfo functions[] = { | ||
| 17 | {0, C<&IHOSBinderDriver::TransactParcel>, "TransactParcel"}, | ||
| 18 | {1, C<&IHOSBinderDriver::AdjustRefcount>, "AdjustRefcount"}, | ||
| 19 | {2, C<&IHOSBinderDriver::GetNativeHandle>, "GetNativeHandle"}, | ||
| 20 | {3, C<&IHOSBinderDriver::TransactParcelAuto>, "TransactParcelAuto"}, | ||
| 21 | }; | ||
| 22 | RegisterHandlers(functions); | ||
| 23 | } | ||
| 24 | |||
| 25 | IHOSBinderDriver::~IHOSBinderDriver() = default; | ||
| 26 | |||
| 27 | Result IHOSBinderDriver::TransactParcel(s32 binder_id, android::TransactionId transaction_id, | ||
| 28 | InBuffer<BufferAttr_HipcMapAlias> parcel_data, | ||
| 29 | OutBuffer<BufferAttr_HipcMapAlias> parcel_reply, | ||
| 30 | u32 flags) { | ||
| 31 | LOG_DEBUG(Service_VI, "called. id={} transaction={}, flags={}", binder_id, transaction_id, | ||
| 32 | flags); | ||
| 33 | m_server->TryGetProducer(binder_id)->Transact(transaction_id, flags, parcel_data, parcel_reply); | ||
| 34 | R_SUCCEED(); | ||
| 35 | } | ||
| 36 | |||
| 37 | Result IHOSBinderDriver::AdjustRefcount(s32 binder_id, s32 addval, s32 type) { | ||
| 38 | LOG_WARNING(Service_VI, "(STUBBED) called id={}, addval={}, type={}", binder_id, addval, type); | ||
| 39 | R_SUCCEED(); | ||
| 40 | } | ||
| 41 | |||
| 42 | Result IHOSBinderDriver::GetNativeHandle(s32 binder_id, u32 type_id, | ||
| 43 | OutCopyHandle<Kernel::KReadableEvent> out_handle) { | ||
| 44 | LOG_WARNING(Service_VI, "(STUBBED) called id={}, type_id={}", binder_id, type_id); | ||
| 45 | *out_handle = &m_server->TryGetProducer(binder_id)->GetNativeHandle(); | ||
| 46 | R_SUCCEED(); | ||
| 47 | } | ||
| 48 | |||
| 49 | Result IHOSBinderDriver::TransactParcelAuto(s32 binder_id, android::TransactionId transaction_id, | ||
| 50 | InBuffer<BufferAttr_HipcAutoSelect> parcel_data, | ||
| 51 | OutBuffer<BufferAttr_HipcAutoSelect> parcel_reply, | ||
| 52 | u32 flags) { | ||
| 53 | R_RETURN(this->TransactParcel(binder_id, transaction_id, parcel_data, parcel_reply, flags)); | ||
| 54 | } | ||
| 55 | |||
| 56 | } // namespace Service::Nvnflinger | ||
diff --git a/src/core/hle/service/nvnflinger/hos_binder_driver.h b/src/core/hle/service/nvnflinger/hos_binder_driver.h new file mode 100644 index 000000000..aa9e3121a --- /dev/null +++ b/src/core/hle/service/nvnflinger/hos_binder_driver.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "core/hle/service/cmif_types.h" | ||
| 5 | #include "core/hle/service/nvnflinger/binder.h" | ||
| 6 | #include "core/hle/service/service.h" | ||
| 7 | |||
| 8 | namespace Service::Nvnflinger { | ||
| 9 | |||
| 10 | class HosBinderDriverServer; | ||
| 11 | class Nvnflinger; | ||
| 12 | |||
| 13 | class IHOSBinderDriver final : public ServiceFramework<IHOSBinderDriver> { | ||
| 14 | public: | ||
| 15 | explicit IHOSBinderDriver(Core::System& system_, std::shared_ptr<HosBinderDriverServer> server, | ||
| 16 | std::shared_ptr<Nvnflinger> surface_flinger); | ||
| 17 | ~IHOSBinderDriver() override; | ||
| 18 | |||
| 19 | std::shared_ptr<Nvnflinger> GetSurfaceFlinger() { | ||
| 20 | return m_surface_flinger; | ||
| 21 | } | ||
| 22 | |||
| 23 | private: | ||
| 24 | Result TransactParcel(s32 binder_id, android::TransactionId transaction_id, | ||
| 25 | InBuffer<BufferAttr_HipcMapAlias> parcel_data, | ||
| 26 | OutBuffer<BufferAttr_HipcMapAlias> parcel_reply, u32 flags); | ||
| 27 | Result AdjustRefcount(s32 binder_id, s32 addval, s32 type); | ||
| 28 | Result GetNativeHandle(s32 binder_id, u32 type_id, | ||
| 29 | OutCopyHandle<Kernel::KReadableEvent> out_handle); | ||
| 30 | Result TransactParcelAuto(s32 binder_id, android::TransactionId transaction_id, | ||
| 31 | InBuffer<BufferAttr_HipcAutoSelect> parcel_data, | ||
| 32 | OutBuffer<BufferAttr_HipcAutoSelect> parcel_reply, u32 flags); | ||
| 33 | |||
| 34 | private: | ||
| 35 | const std::shared_ptr<HosBinderDriverServer> m_server; | ||
| 36 | const std::shared_ptr<Nvnflinger> m_surface_flinger; | ||
| 37 | }; | ||
| 38 | |||
| 39 | } // namespace Service::Nvnflinger | ||
diff --git a/src/core/hle/service/nvnflinger/nvnflinger.cpp b/src/core/hle/service/nvnflinger/nvnflinger.cpp index 687ccc9f9..cd8062a2b 100644 --- a/src/core/hle/service/nvnflinger/nvnflinger.cpp +++ b/src/core/hle/service/nvnflinger/nvnflinger.cpp | |||
| @@ -1,33 +1,24 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | 2 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | 3 | ||
| 4 | #include <algorithm> | ||
| 5 | #include <optional> | ||
| 6 | |||
| 7 | #include "common/assert.h" | ||
| 8 | #include "common/logging/log.h" | ||
| 9 | #include "common/microprofile.h" | 4 | #include "common/microprofile.h" |
| 10 | #include "common/scope_exit.h" | 5 | #include "common/scope_exit.h" |
| 11 | #include "common/settings.h" | 6 | #include "common/settings.h" |
| 12 | #include "common/thread.h" | ||
| 13 | #include "core/core.h" | 7 | #include "core/core.h" |
| 14 | #include "core/core_timing.h" | 8 | #include "core/core_timing.h" |
| 15 | #include "core/hle/kernel/k_readable_event.h" | ||
| 16 | #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" | 9 | #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" |
| 17 | #include "core/hle/service/nvdrv/nvdrv.h" | 10 | #include "core/hle/service/nvdrv/nvdrv.h" |
| 18 | #include "core/hle/service/nvnflinger/buffer_item_consumer.h" | 11 | #include "core/hle/service/nvdrv/nvdrv_interface.h" |
| 19 | #include "core/hle/service/nvnflinger/buffer_queue_core.h" | ||
| 20 | #include "core/hle/service/nvnflinger/fb_share_buffer_manager.h" | 12 | #include "core/hle/service/nvnflinger/fb_share_buffer_manager.h" |
| 21 | #include "core/hle/service/nvnflinger/hardware_composer.h" | 13 | #include "core/hle/service/nvnflinger/hardware_composer.h" |
| 14 | #include "core/hle/service/nvnflinger/hos_binder_driver.h" | ||
| 22 | #include "core/hle/service/nvnflinger/hos_binder_driver_server.h" | 15 | #include "core/hle/service/nvnflinger/hos_binder_driver_server.h" |
| 23 | #include "core/hle/service/nvnflinger/nvnflinger.h" | 16 | #include "core/hle/service/nvnflinger/nvnflinger.h" |
| 24 | #include "core/hle/service/nvnflinger/ui/graphic_buffer.h" | 17 | #include "core/hle/service/server_manager.h" |
| 18 | #include "core/hle/service/sm/sm.h" | ||
| 25 | #include "core/hle/service/vi/display/vi_display.h" | 19 | #include "core/hle/service/vi/display/vi_display.h" |
| 26 | #include "core/hle/service/vi/layer/vi_layer.h" | 20 | #include "core/hle/service/vi/layer/vi_layer.h" |
| 27 | #include "core/hle/service/vi/vi_results.h" | 21 | #include "core/hle/service/vi/vi_results.h" |
| 28 | #include "video_core/gpu.h" | ||
| 29 | #include "video_core/host1x/host1x.h" | ||
| 30 | #include "video_core/host1x/syncpoint_manager.h" | ||
| 31 | 22 | ||
| 32 | namespace Service::Nvnflinger { | 23 | namespace Service::Nvnflinger { |
| 33 | 24 | ||
| @@ -47,6 +38,11 @@ void Nvnflinger::SplitVSync(std::stop_token stop_token) { | |||
| 47 | while (!stop_token.stop_requested()) { | 38 | while (!stop_token.stop_requested()) { |
| 48 | vsync_signal.Wait(); | 39 | vsync_signal.Wait(); |
| 49 | 40 | ||
| 41 | if (system.IsShuttingDown()) { | ||
| 42 | ShutdownLayers(); | ||
| 43 | return; | ||
| 44 | } | ||
| 45 | |||
| 50 | const auto lock_guard = Lock(); | 46 | const auto lock_guard = Lock(); |
| 51 | 47 | ||
| 52 | if (!is_abandoned) { | 48 | if (!is_abandoned) { |
| @@ -65,6 +61,9 @@ Nvnflinger::Nvnflinger(Core::System& system_, HosBinderDriverServer& hos_binder_ | |||
| 65 | displays.emplace_back(4, "Null", hos_binder_driver_server, service_context, system); | 61 | displays.emplace_back(4, "Null", hos_binder_driver_server, service_context, system); |
| 66 | guard = std::make_shared<std::mutex>(); | 62 | guard = std::make_shared<std::mutex>(); |
| 67 | 63 | ||
| 64 | nvdrv = system.ServiceManager().GetService<Nvidia::NVDRV>("nvdrv:s", true)->GetModule(); | ||
| 65 | disp_fd = nvdrv->Open("/dev/nvdisp_disp0", {}); | ||
| 66 | |||
| 68 | // Schedule the screen composition events | 67 | // Schedule the screen composition events |
| 69 | multi_composition_event = Core::Timing::CreateEvent( | 68 | multi_composition_event = Core::Timing::CreateEvent( |
| 70 | "ScreenComposition", | 69 | "ScreenComposition", |
| @@ -110,22 +109,12 @@ Nvnflinger::~Nvnflinger() { | |||
| 110 | 109 | ||
| 111 | void Nvnflinger::ShutdownLayers() { | 110 | void Nvnflinger::ShutdownLayers() { |
| 112 | // Abandon consumers. | 111 | // Abandon consumers. |
| 113 | { | 112 | const auto lock_guard = Lock(); |
| 114 | const auto lock_guard = Lock(); | 113 | for (auto& display : displays) { |
| 115 | for (auto& display : displays) { | 114 | display.Abandon(); |
| 116 | display.Abandon(); | ||
| 117 | } | ||
| 118 | |||
| 119 | is_abandoned = true; | ||
| 120 | } | 115 | } |
| 121 | 116 | ||
| 122 | // Join the vsync thread, if it exists. | 117 | is_abandoned = true; |
| 123 | vsync_thread = {}; | ||
| 124 | } | ||
| 125 | |||
| 126 | void Nvnflinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) { | ||
| 127 | nvdrv = std::move(instance); | ||
| 128 | disp_fd = nvdrv->Open("/dev/nvdisp_disp0", {}); | ||
| 129 | } | 118 | } |
| 130 | 119 | ||
| 131 | std::optional<u64> Nvnflinger::OpenDisplay(std::string_view name) { | 120 | std::optional<u64> Nvnflinger::OpenDisplay(std::string_view name) { |
| @@ -332,4 +321,14 @@ FbShareBufferManager& Nvnflinger::GetSystemBufferManager() { | |||
| 332 | return *system_buffer_manager; | 321 | return *system_buffer_manager; |
| 333 | } | 322 | } |
| 334 | 323 | ||
| 324 | void LoopProcess(Core::System& system) { | ||
| 325 | const auto binder_server = std::make_shared<HosBinderDriverServer>(system); | ||
| 326 | const auto surface_flinger = std::make_shared<Nvnflinger>(system, *binder_server); | ||
| 327 | |||
| 328 | auto server_manager = std::make_unique<ServerManager>(system); | ||
| 329 | server_manager->RegisterNamedService( | ||
| 330 | "dispdrv", std::make_shared<IHOSBinderDriver>(system, binder_server, surface_flinger)); | ||
| 331 | ServerManager::RunServer(std::move(server_manager)); | ||
| 332 | } | ||
| 333 | |||
| 335 | } // namespace Service::Nvnflinger | 334 | } // namespace Service::Nvnflinger |
diff --git a/src/core/hle/service/nvnflinger/nvnflinger.h b/src/core/hle/service/nvnflinger/nvnflinger.h index 4cf4f069d..5ed7dc317 100644 --- a/src/core/hle/service/nvnflinger/nvnflinger.h +++ b/src/core/hle/service/nvnflinger/nvnflinger.h | |||
| @@ -8,7 +8,6 @@ | |||
| 8 | #include <mutex> | 8 | #include <mutex> |
| 9 | #include <optional> | 9 | #include <optional> |
| 10 | #include <thread> | 10 | #include <thread> |
| 11 | #include <vector> | ||
| 12 | 11 | ||
| 13 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 14 | #include "common/polyfill_thread.h" | 13 | #include "common/polyfill_thread.h" |
| @@ -57,9 +56,6 @@ public: | |||
| 57 | 56 | ||
| 58 | void ShutdownLayers(); | 57 | void ShutdownLayers(); |
| 59 | 58 | ||
| 60 | /// Sets the NVDrv module instance to use to send buffers to the GPU. | ||
| 61 | void SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance); | ||
| 62 | |||
| 63 | /// Opens the specified display and returns the ID. | 59 | /// Opens the specified display and returns the ID. |
| 64 | /// | 60 | /// |
| 65 | /// If an invalid display name is provided, then an empty optional is returned. | 61 | /// If an invalid display name is provided, then an empty optional is returned. |
| @@ -169,4 +165,6 @@ private: | |||
| 169 | HosBinderDriverServer& hos_binder_driver_server; | 165 | HosBinderDriverServer& hos_binder_driver_server; |
| 170 | }; | 166 | }; |
| 171 | 167 | ||
| 168 | void LoopProcess(Core::System& system); | ||
| 169 | |||
| 172 | } // namespace Service::Nvnflinger | 170 | } // namespace Service::Nvnflinger |