// SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) #pragma once #include #include "language.h" #include "logger/logger.h" namespace skyline { /** * @brief The Settings class provides a simple interface to access user-defined settings, update values and subscribe callbacks to observe changes. */ class Settings { template class Setting { using Callback = std::function; std::vector callbacks; //!< Callbacks to be called when this setting changes T value; std::mutex valueMutex; std::mutex callbackMutex; /** * @brief Calls all callbacks registered for this setting * @note Locking of the setting value must be handled by the caller */ void OnSettingChanged() { std::scoped_lock lock{callbackMutex}; for (const auto &callback : callbacks) callback(value); } public: /** * @return The underlying setting value */ const T &operator*() { std::scoped_lock lock{valueMutex}; return value; } /** * @brief Sets the underlying setting value, signalling any callbacks if necessary */ void operator=(T newValue) { std::scoped_lock lock{valueMutex}; if (value != newValue) { value = std::move(newValue); OnSettingChanged(); } } /** * @brief Register a callback to be run when this setting changes */ void AddCallback(Callback callback) { std::scoped_lock lock{callbackMutex}; callbacks.push_back(std::move(callback)); } }; public: // System Setting isDocked; //!< If the emulated Switch should be handheld or docked Setting usernameValue; //!< The user name to be supplied to the guest Setting profilePictureValue; //!< The profile picture path to be supplied to the guest Setting systemLanguage; //!< The system language Setting systemRegion; //!< The system region Setting isInternetEnabled; //!< If emulator uses internet // Display Setting forceTripleBuffering; //!< If the presentation engine should always triple buffer even if the swapchain supports double buffering Setting disableFrameThrottling; //!< Allow the guest to submit frames without any blocking calls Setting disableShaderCache; //!< Prevents cached shaders from being loaded and disables caching of new shaders // GPU Setting gpuDriver; //!< The label of the GPU driver to use Setting gpuDriverLibraryName; //!< The name of the GPU driver library to use Setting executorSlotCountScale; //!< Number of GPU executor slots that can be used concurrently Setting executorFlushThreshold; //!< Number of commands that need to accumulate before they're flushed to the GPU Setting useDirectMemoryImport; //!< If buffer emulation should be done by importing guest buffer mappings Setting forceMaxGpuClocks; //!< If the GPU should be forced to run at maximum clocks Setting freeGuestTextureMemory; //!< If guest textrue memory should be freed when the owning texture is GPU dirty // Hacks Setting enableFastGpuReadbackHack; //!< If the CPU texture readback skipping hack should be used Setting enableFastReadbackWrites; //!< If buffers should be treated as CPU dirty when written with the readback hack Setting disableSubgroupShuffle; //!< If shader subgroup suffle operations should be ignored // Audio Setting isAudioOutputDisabled; //!< Disables audio output // Debug Setting logLevel; //!< The log level Setting validationLayer; //!< If the vulkan validation layer is enabled Settings() = default; virtual ~Settings() = default; /** * @brief Updates settings with the given values * @note This method is platform-specific and must be overridden */ virtual void Update() = 0; }; }