From dcd5f525cb6ddf96c7264065d31267046c383c7b Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Thu, 6 May 2021 09:13:44 +0200 Subject: [PATCH] early-access version 1661 --- README.md | 2 +- src/core/hle/service/nvflinger/nvflinger.cpp | 27 +++++++++++++++++--- src/core/hle/service/nvflinger/nvflinger.h | 10 +++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 52a1fec1b..9d91fe543 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1660. +This is the source code for early-access 1661. ## Legal Notice diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index 7fb9133c7..1484a50f2 100755 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp @@ -139,11 +139,15 @@ std::optional NVFlinger::CreateLayer(u64 display_id) { } const u64 layer_id = next_layer_id++; + CreateLayerAtId(display, layer_id); + return layer_id; +} + +void NVFlinger::CreateLayerAtId(VI::Display* display, u64 layer_id) { const u32 buffer_queue_id = next_buffer_queue_id++; buffer_queues.emplace_back( std::make_unique(system.Kernel(), buffer_queue_id, layer_id)); display->CreateLayer(layer_id, *buffer_queues.back()); - return layer_id; } void NVFlinger::CloseLayer(u64 layer_id) { @@ -154,9 +158,9 @@ void NVFlinger::CloseLayer(u64 layer_id) { } } -std::optional NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) const { +std::optional NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) { const auto lock_guard = Lock(); - const auto* const layer = FindLayer(display_id, layer_id); + const auto* const layer = FindOrCreateLayer(display_id, layer_id); if (layer == nullptr) { return std::nullopt; @@ -232,6 +236,23 @@ const VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const { return display->FindLayer(layer_id); } +VI::Layer* Service::NVFlinger::NVFlinger::FindOrCreateLayer(u64 display_id, u64 layer_id) { + auto* const display = FindDisplay(display_id); + + if (display == nullptr) { + return nullptr; + } + + auto* layer = display->FindLayer(layer_id); + + if (layer == nullptr) { + LOG_DEBUG(Service, "Layer at id {} not found. Trying to create it.", layer_id); + CreateLayerAtId(display, layer_id); + return display->FindLayer(layer_id); + } + return layer; +} + void NVFlinger::Compose() { for (auto& display : displays) { // Trigger vsync for this display at the end of drawing diff --git a/src/core/hle/service/nvflinger/nvflinger.h b/src/core/hle/service/nvflinger/nvflinger.h index b0febdaec..403935be3 100755 --- a/src/core/hle/service/nvflinger/nvflinger.h +++ b/src/core/hle/service/nvflinger/nvflinger.h @@ -61,13 +61,16 @@ public: /// If an invalid display ID is specified, then an empty optional is returned. [[nodiscard]] std::optional CreateLayer(u64 display_id); + /// Creates a layer with the specified layer ID in the desired display. + void CreateLayerAtId(VI::Display* display, u64 layer_id); + /// Closes a layer on all displays for the given layer ID. void CloseLayer(u64 layer_id); /// Finds the buffer queue ID of the specified layer in the specified display. /// /// If an invalid display ID or layer ID is provided, then an empty optional is returned. - [[nodiscard]] std::optional FindBufferQueueId(u64 display_id, u64 layer_id) const; + [[nodiscard]] std::optional FindBufferQueueId(u64 display_id, u64 layer_id); /// Gets the vsync event for the specified display. /// @@ -100,6 +103,11 @@ private: /// Finds the layer identified by the specified ID in the desired display. [[nodiscard]] const VI::Layer* FindLayer(u64 display_id, u64 layer_id) const; + /// Finds the layer identified by the specified ID in the desired display, + /// or creates the layer if it is not found. + /// To be used when the system expects the specified ID to already exist. + [[nodiscard]] VI::Layer* FindOrCreateLayer(u64 display_id, u64 layer_id); + static void VSyncThread(NVFlinger& nv_flinger); void SplitVSync();