summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ameerj2021-05-06 11:20:52 -0400
committerGravatar ameerj2021-05-06 11:20:52 -0400
commitda62e92784fbae15942ae4be57fb7eb3b4a9b5b5 (patch)
tree6b78d4a32f52cf3bdacafb4bf1b84aeca80dc530 /src
parentMerge pull request #6279 from ogniK5377/nvhost-prof (diff)
downloadyuzu-da62e92784fbae15942ae4be57fb7eb3b4a9b5b5.tar.gz
yuzu-da62e92784fbae15942ae4be57fb7eb3b4a9b5b5.tar.xz
yuzu-da62e92784fbae15942ae4be57fb7eb3b4a9b5b5.zip
nvflinger: Create layers when they are queried but not found
Fixes Shantae softlock on boot.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp30
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.h10
2 files changed, 35 insertions, 5 deletions
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index c43593e7f..810312dc4 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -139,11 +139,15 @@ std::optional<u64> NVFlinger::CreateLayer(u64 display_id) {
139 } 139 }
140 140
141 const u64 layer_id = next_layer_id++; 141 const u64 layer_id = next_layer_id++;
142 CreateLayerAtId(*display, layer_id);
143 return layer_id;
144}
145
146void NVFlinger::CreateLayerAtId(VI::Display& display, u64 layer_id) {
142 const u32 buffer_queue_id = next_buffer_queue_id++; 147 const u32 buffer_queue_id = next_buffer_queue_id++;
143 buffer_queues.emplace_back( 148 buffer_queues.emplace_back(
144 std::make_unique<BufferQueue>(system.Kernel(), buffer_queue_id, layer_id)); 149 std::make_unique<BufferQueue>(system.Kernel(), buffer_queue_id, layer_id));
145 display->CreateLayer(layer_id, *buffer_queues.back()); 150 display.CreateLayer(layer_id, *buffer_queues.back());
146 return layer_id;
147} 151}
148 152
149void NVFlinger::CloseLayer(u64 layer_id) { 153void NVFlinger::CloseLayer(u64 layer_id) {
@@ -154,9 +158,9 @@ void NVFlinger::CloseLayer(u64 layer_id) {
154 } 158 }
155} 159}
156 160
157std::optional<u32> NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) const { 161std::optional<u32> NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) {
158 const auto lock_guard = Lock(); 162 const auto lock_guard = Lock();
159 const auto* const layer = FindLayer(display_id, layer_id); 163 const auto* const layer = FindOrCreateLayer(display_id, layer_id);
160 164
161 if (layer == nullptr) { 165 if (layer == nullptr) {
162 return std::nullopt; 166 return std::nullopt;
@@ -232,6 +236,24 @@ const VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const {
232 return display->FindLayer(layer_id); 236 return display->FindLayer(layer_id);
233} 237}
234 238
239VI::Layer* NVFlinger::FindOrCreateLayer(u64 display_id, u64 layer_id) {
240 auto* const display = FindDisplay(display_id);
241
242 if (display == nullptr) {
243 return nullptr;
244 }
245
246 auto* layer = display->FindLayer(layer_id);
247
248 if (layer == nullptr) {
249 LOG_DEBUG(Service, "Layer at id {} not found. Trying to create it.", layer_id);
250 CreateLayerAtId(*display, layer_id);
251 return display->FindLayer(layer_id);
252 }
253
254 return layer;
255}
256
235void NVFlinger::Compose() { 257void NVFlinger::Compose() {
236 for (auto& display : displays) { 258 for (auto& display : displays) {
237 // Trigger vsync for this display at the end of drawing 259 // 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 6fe2c7f2a..ebc82c688 100644
--- a/src/core/hle/service/nvflinger/nvflinger.h
+++ b/src/core/hle/service/nvflinger/nvflinger.h
@@ -67,7 +67,7 @@ public:
67 /// Finds the buffer queue ID of the specified layer in the specified display. 67 /// Finds the buffer queue ID of the specified layer in the specified display.
68 /// 68 ///
69 /// If an invalid display ID or layer ID is provided, then an empty optional is returned. 69 /// If an invalid display ID or layer ID is provided, then an empty optional is returned.
70 [[nodiscard]] std::optional<u32> FindBufferQueueId(u64 display_id, u64 layer_id) const; 70 [[nodiscard]] std::optional<u32> FindBufferQueueId(u64 display_id, u64 layer_id);
71 71
72 /// Gets the vsync event for the specified display. 72 /// Gets the vsync event for the specified display.
73 /// 73 ///
@@ -100,6 +100,14 @@ private:
100 /// Finds the layer identified by the specified ID in the desired display. 100 /// Finds the layer identified by the specified ID in the desired display.
101 [[nodiscard]] const VI::Layer* FindLayer(u64 display_id, u64 layer_id) const; 101 [[nodiscard]] const VI::Layer* FindLayer(u64 display_id, u64 layer_id) const;
102 102
103 /// Finds the layer identified by the specified ID in the desired display,
104 /// or creates the layer if it is not found.
105 /// To be used when the system expects the specified ID to already exist.
106 [[nodiscard]] VI::Layer* FindOrCreateLayer(u64 display_id, u64 layer_id);
107
108 /// Creates a layer with the specified layer ID in the desired display.
109 void CreateLayerAtId(VI::Display& display, u64 layer_id);
110
103 static void VSyncThread(NVFlinger& nv_flinger); 111 static void VSyncThread(NVFlinger& nv_flinger);
104 112
105 void SplitVSync(); 113 void SplitVSync();