2018-01-22 17:54:58 +01:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-05-29 21:00:17 +02:00
|
|
|
#include <atomic>
|
2018-01-22 17:54:58 +01:00
|
|
|
#include <memory>
|
2020-02-27 15:47:02 +01:00
|
|
|
#include <mutex>
|
2019-02-05 22:20:04 +01:00
|
|
|
#include <optional>
|
2018-08-07 14:24:30 +02:00
|
|
|
#include <string>
|
2018-08-07 14:19:24 +02:00
|
|
|
#include <string_view>
|
2020-05-29 21:00:17 +02:00
|
|
|
#include <thread>
|
2020-06-27 16:59:51 +02:00
|
|
|
#include <vector>
|
2018-08-07 14:24:30 +02:00
|
|
|
|
|
|
|
#include "common/common_types.h"
|
2018-11-27 00:34:07 +01:00
|
|
|
#include "core/hle/kernel/object.h"
|
2018-01-22 17:54:58 +01:00
|
|
|
|
2020-05-29 21:00:17 +02:00
|
|
|
namespace Common {
|
|
|
|
class Event;
|
|
|
|
} // namespace Common
|
|
|
|
|
2019-02-12 18:32:15 +01:00
|
|
|
namespace Core::Timing {
|
2019-02-14 18:42:58 +01:00
|
|
|
class CoreTiming;
|
2018-01-22 17:54:58 +01:00
|
|
|
struct EventType;
|
2019-02-14 18:42:58 +01:00
|
|
|
} // namespace Core::Timing
|
2018-01-22 17:54:58 +01:00
|
|
|
|
2018-11-27 00:34:07 +01:00
|
|
|
namespace Kernel {
|
|
|
|
class ReadableEvent;
|
|
|
|
class WritableEvent;
|
|
|
|
} // namespace Kernel
|
|
|
|
|
2018-08-07 15:17:09 +02:00
|
|
|
namespace Service::Nvidia {
|
|
|
|
class Module;
|
2019-02-19 23:00:03 +01:00
|
|
|
} // namespace Service::Nvidia
|
|
|
|
|
|
|
|
namespace Service::VI {
|
2019-02-21 16:43:26 +01:00
|
|
|
class Display;
|
2019-02-21 16:56:20 +01:00
|
|
|
class Layer;
|
2019-02-19 23:00:03 +01:00
|
|
|
} // namespace Service::VI
|
2018-08-07 15:17:09 +02:00
|
|
|
|
2018-04-20 03:41:44 +02:00
|
|
|
namespace Service::NVFlinger {
|
2018-01-22 17:54:58 +01:00
|
|
|
|
|
|
|
class BufferQueue;
|
|
|
|
|
|
|
|
class NVFlinger final {
|
|
|
|
public:
|
2019-09-22 08:41:34 +02:00
|
|
|
explicit NVFlinger(Core::System& system);
|
2018-01-22 17:54:58 +01:00
|
|
|
~NVFlinger();
|
|
|
|
|
2018-08-07 15:17:09 +02:00
|
|
|
/// Sets the NVDrv module instance to use to send buffers to the GPU.
|
|
|
|
void SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance);
|
|
|
|
|
2019-01-30 05:30:22 +01:00
|
|
|
/// Opens the specified display and returns the ID.
|
2019-02-05 22:20:04 +01:00
|
|
|
///
|
|
|
|
/// If an invalid display name is provided, then an empty optional is returned.
|
|
|
|
std::optional<u64> OpenDisplay(std::string_view name);
|
2018-01-22 17:54:58 +01:00
|
|
|
|
2019-01-30 05:30:22 +01:00
|
|
|
/// Creates a layer on the specified display and returns the layer ID.
|
2019-02-05 22:20:04 +01:00
|
|
|
///
|
|
|
|
/// If an invalid display ID is specified, then an empty optional is returned.
|
|
|
|
std::optional<u64> CreateLayer(u64 display_id);
|
2018-01-22 17:54:58 +01:00
|
|
|
|
2020-01-04 06:45:06 +01:00
|
|
|
/// Closes a layer on all displays for the given layer ID.
|
|
|
|
void CloseLayer(u64 layer_id);
|
|
|
|
|
2019-01-30 05:30:22 +01:00
|
|
|
/// Finds the buffer queue ID of the specified layer in the specified display.
|
2019-02-05 22:20:04 +01:00
|
|
|
///
|
|
|
|
/// If an invalid display ID or layer ID is provided, then an empty optional is returned.
|
|
|
|
std::optional<u32> FindBufferQueueId(u64 display_id, u64 layer_id) const;
|
2018-01-22 17:54:58 +01:00
|
|
|
|
|
|
|
/// Gets the vsync event for the specified display.
|
2019-02-05 22:20:04 +01:00
|
|
|
///
|
|
|
|
/// If an invalid display ID is provided, then nullptr is returned.
|
2019-11-25 02:15:51 +01:00
|
|
|
std::shared_ptr<Kernel::ReadableEvent> FindVsyncEvent(u64 display_id) const;
|
2018-01-22 17:54:58 +01:00
|
|
|
|
2019-01-30 05:30:22 +01:00
|
|
|
/// Obtains a buffer queue identified by the ID.
|
2019-02-21 17:31:53 +01:00
|
|
|
BufferQueue& FindBufferQueue(u32 id);
|
|
|
|
|
|
|
|
/// Obtains a buffer queue identified by the ID.
|
|
|
|
const BufferQueue& FindBufferQueue(u32 id) const;
|
2018-01-22 17:54:58 +01:00
|
|
|
|
|
|
|
/// Performs a composition request to the emulated nvidia GPU and triggers the vsync events when
|
|
|
|
/// finished.
|
|
|
|
void Compose();
|
|
|
|
|
2019-06-19 02:53:21 +02:00
|
|
|
s64 GetNextTicks() const;
|
2019-06-04 22:10:07 +02:00
|
|
|
|
2020-07-26 00:53:25 +02:00
|
|
|
std::unique_lock<std::mutex> Lock() const {
|
2020-02-27 15:47:02 +01:00
|
|
|
return std::unique_lock{*guard};
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:54:58 +01:00
|
|
|
private:
|
2019-01-30 05:30:22 +01:00
|
|
|
/// Finds the display identified by the specified ID.
|
2019-02-19 23:00:03 +01:00
|
|
|
VI::Display* FindDisplay(u64 display_id);
|
2018-01-22 17:54:58 +01:00
|
|
|
|
2019-01-30 17:14:05 +01:00
|
|
|
/// Finds the display identified by the specified ID.
|
2019-02-19 23:00:03 +01:00
|
|
|
const VI::Display* FindDisplay(u64 display_id) const;
|
2019-01-30 17:14:05 +01:00
|
|
|
|
2019-01-30 05:30:22 +01:00
|
|
|
/// Finds the layer identified by the specified ID in the desired display.
|
2019-02-19 23:00:03 +01:00
|
|
|
VI::Layer* FindLayer(u64 display_id, u64 layer_id);
|
2018-01-22 17:54:58 +01:00
|
|
|
|
2019-01-30 17:14:05 +01:00
|
|
|
/// Finds the layer identified by the specified ID in the desired display.
|
2019-02-19 23:00:03 +01:00
|
|
|
const VI::Layer* FindLayer(u64 display_id, u64 layer_id) const;
|
2019-01-30 17:14:05 +01:00
|
|
|
|
2020-05-29 21:00:17 +02:00
|
|
|
static void VSyncThread(NVFlinger& nv_flinger);
|
|
|
|
|
|
|
|
void SplitVSync();
|
|
|
|
|
2018-08-07 15:17:09 +02:00
|
|
|
std::shared_ptr<Nvidia::Module> nvdrv;
|
|
|
|
|
2019-02-19 23:00:03 +01:00
|
|
|
std::vector<VI::Display> displays;
|
2019-02-21 17:31:53 +01:00
|
|
|
std::vector<BufferQueue> buffer_queues;
|
2018-01-22 17:54:58 +01:00
|
|
|
|
|
|
|
/// Id to use for the next layer that is created, this counter is shared among all displays.
|
|
|
|
u64 next_layer_id = 1;
|
|
|
|
/// Id to use for the next buffer queue that is created, this counter is shared among all
|
|
|
|
/// layers.
|
|
|
|
u32 next_buffer_queue_id = 1;
|
|
|
|
|
2019-06-04 22:10:07 +02:00
|
|
|
u32 swap_interval = 1;
|
|
|
|
|
2019-02-12 18:32:15 +01:00
|
|
|
/// Event that handles screen composition.
|
2019-11-27 03:48:56 +01:00
|
|
|
std::shared_ptr<Core::Timing::EventType> composition_event;
|
2019-02-14 18:42:58 +01:00
|
|
|
|
2020-02-27 15:47:02 +01:00
|
|
|
std::shared_ptr<std::mutex> guard;
|
|
|
|
|
2019-09-21 11:23:31 +02:00
|
|
|
Core::System& system;
|
2020-05-29 21:00:17 +02:00
|
|
|
|
|
|
|
std::unique_ptr<std::thread> vsync_thread;
|
|
|
|
std::unique_ptr<Common::Event> wait_event;
|
|
|
|
std::atomic<bool> is_running{};
|
2018-01-22 17:54:58 +01:00
|
|
|
};
|
|
|
|
|
2018-04-20 03:41:44 +02:00
|
|
|
} // namespace Service::NVFlinger
|