diff options
Diffstat (limited to 'src')
167 files changed, 3017 insertions, 1852 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 57922b51c..b18a2a2f5 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -53,6 +53,8 @@ add_library(common STATIC | |||
| 53 | div_ceil.h | 53 | div_ceil.h |
| 54 | dynamic_library.cpp | 54 | dynamic_library.cpp |
| 55 | dynamic_library.h | 55 | dynamic_library.h |
| 56 | error.cpp | ||
| 57 | error.h | ||
| 56 | fiber.cpp | 58 | fiber.cpp |
| 57 | fiber.h | 59 | fiber.h |
| 58 | fs/file.cpp | 60 | fs/file.cpp |
| @@ -88,7 +90,6 @@ add_library(common STATIC | |||
| 88 | microprofile.cpp | 90 | microprofile.cpp |
| 89 | microprofile.h | 91 | microprofile.h |
| 90 | microprofileui.h | 92 | microprofileui.h |
| 91 | misc.cpp | ||
| 92 | nvidia_flags.cpp | 93 | nvidia_flags.cpp |
| 93 | nvidia_flags.h | 94 | nvidia_flags.h |
| 94 | page_table.cpp | 95 | page_table.cpp |
diff --git a/src/common/alignment.h b/src/common/alignment.h index 32d796ffa..1b56569d1 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h | |||
| @@ -9,41 +9,48 @@ | |||
| 9 | namespace Common { | 9 | namespace Common { |
| 10 | 10 | ||
| 11 | template <typename T> | 11 | template <typename T> |
| 12 | requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignUp(T value, size_t size) { | 12 | requires std::is_unsigned_v<T> |
| 13 | [[nodiscard]] constexpr T AlignUp(T value, size_t size) { | ||
| 13 | auto mod{static_cast<T>(value % size)}; | 14 | auto mod{static_cast<T>(value % size)}; |
| 14 | value -= mod; | 15 | value -= mod; |
| 15 | return static_cast<T>(mod == T{0} ? value : value + size); | 16 | return static_cast<T>(mod == T{0} ? value : value + size); |
| 16 | } | 17 | } |
| 17 | 18 | ||
| 18 | template <typename T> | 19 | template <typename T> |
| 19 | requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) { | 20 | requires std::is_unsigned_v<T> |
| 21 | [[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) { | ||
| 20 | return static_cast<T>((value + ((1ULL << align_log2) - 1)) >> align_log2 << align_log2); | 22 | return static_cast<T>((value + ((1ULL << align_log2) - 1)) >> align_log2 << align_log2); |
| 21 | } | 23 | } |
| 22 | 24 | ||
| 23 | template <typename T> | 25 | template <typename T> |
| 24 | requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignDown(T value, size_t size) { | 26 | requires std::is_unsigned_v<T> |
| 27 | [[nodiscard]] constexpr T AlignDown(T value, size_t size) { | ||
| 25 | return static_cast<T>(value - value % size); | 28 | return static_cast<T>(value - value % size); |
| 26 | } | 29 | } |
| 27 | 30 | ||
| 28 | template <typename T> | 31 | template <typename T> |
| 29 | requires std::is_unsigned_v<T>[[nodiscard]] constexpr bool Is4KBAligned(T value) { | 32 | requires std::is_unsigned_v<T> |
| 33 | [[nodiscard]] constexpr bool Is4KBAligned(T value) { | ||
| 30 | return (value & 0xFFF) == 0; | 34 | return (value & 0xFFF) == 0; |
| 31 | } | 35 | } |
| 32 | 36 | ||
| 33 | template <typename T> | 37 | template <typename T> |
| 34 | requires std::is_unsigned_v<T>[[nodiscard]] constexpr bool IsWordAligned(T value) { | 38 | requires std::is_unsigned_v<T> |
| 39 | [[nodiscard]] constexpr bool IsWordAligned(T value) { | ||
| 35 | return (value & 0b11) == 0; | 40 | return (value & 0b11) == 0; |
| 36 | } | 41 | } |
| 37 | 42 | ||
| 38 | template <typename T> | 43 | template <typename T> |
| 39 | requires std::is_integral_v<T>[[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) { | 44 | requires std::is_integral_v<T> |
| 45 | [[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) { | ||
| 40 | using U = typename std::make_unsigned_t<T>; | 46 | using U = typename std::make_unsigned_t<T>; |
| 41 | const U mask = static_cast<U>(alignment - 1); | 47 | const U mask = static_cast<U>(alignment - 1); |
| 42 | return (value & mask) == 0; | 48 | return (value & mask) == 0; |
| 43 | } | 49 | } |
| 44 | 50 | ||
| 45 | template <typename T, typename U> | 51 | template <typename T, typename U> |
| 46 | requires std::is_integral_v<T>[[nodiscard]] constexpr T DivideUp(T x, U y) { | 52 | requires std::is_integral_v<T> |
| 53 | [[nodiscard]] constexpr T DivideUp(T x, U y) { | ||
| 47 | return (x + (y - 1)) / y; | 54 | return (x + (y - 1)) / y; |
| 48 | } | 55 | } |
| 49 | 56 | ||
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 53bd7da60..4c1e29de6 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h | |||
| @@ -4,9 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <algorithm> | ||
| 8 | #include <array> | 7 | #include <array> |
| 9 | #include <string> | 8 | #include <iterator> |
| 10 | 9 | ||
| 11 | #if !defined(ARCHITECTURE_x86_64) | 10 | #if !defined(ARCHITECTURE_x86_64) |
| 12 | #include <cstdlib> // for exit | 11 | #include <cstdlib> // for exit |
| @@ -49,16 +48,6 @@ __declspec(dllimport) void __stdcall DebugBreak(void); | |||
| 49 | 48 | ||
| 50 | #endif // _MSC_VER ndef | 49 | #endif // _MSC_VER ndef |
| 51 | 50 | ||
| 52 | // Generic function to get last error message. | ||
| 53 | // Call directly after the command or use the error num. | ||
| 54 | // This function might change the error code. | ||
| 55 | // Defined in misc.cpp. | ||
| 56 | [[nodiscard]] std::string GetLastErrorMsg(); | ||
| 57 | |||
| 58 | // Like GetLastErrorMsg(), but passing an explicit error code. | ||
| 59 | // Defined in misc.cpp. | ||
| 60 | [[nodiscard]] std::string NativeErrorToString(int e); | ||
| 61 | |||
| 62 | #define DECLARE_ENUM_FLAG_OPERATORS(type) \ | 51 | #define DECLARE_ENUM_FLAG_OPERATORS(type) \ |
| 63 | [[nodiscard]] constexpr type operator|(type a, type b) noexcept { \ | 52 | [[nodiscard]] constexpr type operator|(type a, type b) noexcept { \ |
| 64 | using T = std::underlying_type_t<type>; \ | 53 | using T = std::underlying_type_t<type>; \ |
| @@ -72,6 +61,14 @@ __declspec(dllimport) void __stdcall DebugBreak(void); | |||
| 72 | using T = std::underlying_type_t<type>; \ | 61 | using T = std::underlying_type_t<type>; \ |
| 73 | return static_cast<type>(static_cast<T>(a) ^ static_cast<T>(b)); \ | 62 | return static_cast<type>(static_cast<T>(a) ^ static_cast<T>(b)); \ |
| 74 | } \ | 63 | } \ |
| 64 | [[nodiscard]] constexpr type operator<<(type a, type b) noexcept { \ | ||
| 65 | using T = std::underlying_type_t<type>; \ | ||
| 66 | return static_cast<type>(static_cast<T>(a) << static_cast<T>(b)); \ | ||
| 67 | } \ | ||
| 68 | [[nodiscard]] constexpr type operator>>(type a, type b) noexcept { \ | ||
| 69 | using T = std::underlying_type_t<type>; \ | ||
| 70 | return static_cast<type>(static_cast<T>(a) >> static_cast<T>(b)); \ | ||
| 71 | } \ | ||
| 75 | constexpr type& operator|=(type& a, type b) noexcept { \ | 72 | constexpr type& operator|=(type& a, type b) noexcept { \ |
| 76 | a = a | b; \ | 73 | a = a | b; \ |
| 77 | return a; \ | 74 | return a; \ |
| @@ -84,6 +81,14 @@ __declspec(dllimport) void __stdcall DebugBreak(void); | |||
| 84 | a = a ^ b; \ | 81 | a = a ^ b; \ |
| 85 | return a; \ | 82 | return a; \ |
| 86 | } \ | 83 | } \ |
| 84 | constexpr type& operator<<=(type& a, type b) noexcept { \ | ||
| 85 | a = a << b; \ | ||
| 86 | return a; \ | ||
| 87 | } \ | ||
| 88 | constexpr type& operator>>=(type& a, type b) noexcept { \ | ||
| 89 | a = a >> b; \ | ||
| 90 | return a; \ | ||
| 91 | } \ | ||
| 87 | [[nodiscard]] constexpr type operator~(type key) noexcept { \ | 92 | [[nodiscard]] constexpr type operator~(type key) noexcept { \ |
| 88 | using T = std::underlying_type_t<type>; \ | 93 | using T = std::underlying_type_t<type>; \ |
| 89 | return static_cast<type>(~static_cast<T>(key)); \ | 94 | return static_cast<type>(~static_cast<T>(key)); \ |
diff --git a/src/common/div_ceil.h b/src/common/div_ceil.h index 95e1489a9..e1db35464 100644 --- a/src/common/div_ceil.h +++ b/src/common/div_ceil.h | |||
| @@ -11,15 +11,15 @@ namespace Common { | |||
| 11 | 11 | ||
| 12 | /// Ceiled integer division. | 12 | /// Ceiled integer division. |
| 13 | template <typename N, typename D> | 13 | template <typename N, typename D> |
| 14 | requires std::is_integral_v<N>&& std::is_unsigned_v<D>[[nodiscard]] constexpr N DivCeil(N number, | 14 | requires std::is_integral_v<N> && std::is_unsigned_v<D> |
| 15 | D divisor) { | 15 | [[nodiscard]] constexpr N DivCeil(N number, D divisor) { |
| 16 | return static_cast<N>((static_cast<D>(number) + divisor - 1) / divisor); | 16 | return static_cast<N>((static_cast<D>(number) + divisor - 1) / divisor); |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | /// Ceiled integer division with logarithmic divisor in base 2 | 19 | /// Ceiled integer division with logarithmic divisor in base 2 |
| 20 | template <typename N, typename D> | 20 | template <typename N, typename D> |
| 21 | requires std::is_integral_v<N>&& std::is_unsigned_v<D>[[nodiscard]] constexpr N DivCeilLog2( | 21 | requires std::is_integral_v<N> && std::is_unsigned_v<D> |
| 22 | N value, D alignment_log2) { | 22 | [[nodiscard]] constexpr N DivCeilLog2(N value, D alignment_log2) { |
| 23 | return static_cast<N>((static_cast<D>(value) + (D(1) << alignment_log2) - 1) >> alignment_log2); | 23 | return static_cast<N>((static_cast<D>(value) + (D(1) << alignment_log2) - 1) >> alignment_log2); |
| 24 | } | 24 | } |
| 25 | 25 | ||
diff --git a/src/common/misc.cpp b/src/common/error.cpp index 495385b9e..d4455e310 100644 --- a/src/common/misc.cpp +++ b/src/common/error.cpp | |||
| @@ -10,7 +10,9 @@ | |||
| 10 | #include <cstring> | 10 | #include <cstring> |
| 11 | #endif | 11 | #endif |
| 12 | 12 | ||
| 13 | #include "common/common_funcs.h" | 13 | #include "common/error.h" |
| 14 | |||
| 15 | namespace Common { | ||
| 14 | 16 | ||
| 15 | std::string NativeErrorToString(int e) { | 17 | std::string NativeErrorToString(int e) { |
| 16 | #ifdef _WIN32 | 18 | #ifdef _WIN32 |
| @@ -50,3 +52,5 @@ std::string GetLastErrorMsg() { | |||
| 50 | return NativeErrorToString(errno); | 52 | return NativeErrorToString(errno); |
| 51 | #endif | 53 | #endif |
| 52 | } | 54 | } |
| 55 | |||
| 56 | } // namespace Common | ||
diff --git a/src/common/error.h b/src/common/error.h new file mode 100644 index 000000000..e084d4b0f --- /dev/null +++ b/src/common/error.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <string> | ||
| 8 | |||
| 9 | namespace Common { | ||
| 10 | |||
| 11 | // Generic function to get last error message. | ||
| 12 | // Call directly after the command or use the error num. | ||
| 13 | // This function might change the error code. | ||
| 14 | // Defined in error.cpp. | ||
| 15 | [[nodiscard]] std::string GetLastErrorMsg(); | ||
| 16 | |||
| 17 | // Like GetLastErrorMsg(), but passing an explicit error code. | ||
| 18 | // Defined in error.cpp. | ||
| 19 | [[nodiscard]] std::string NativeErrorToString(int e); | ||
| 20 | |||
| 21 | } // namespace Common | ||
diff --git a/src/common/fs/fs_paths.h b/src/common/fs/fs_paths.h index b32614797..5d447f108 100644 --- a/src/common/fs/fs_paths.h +++ b/src/common/fs/fs_paths.h | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #define SCREENSHOTS_DIR "screenshots" | 21 | #define SCREENSHOTS_DIR "screenshots" |
| 22 | #define SDMC_DIR "sdmc" | 22 | #define SDMC_DIR "sdmc" |
| 23 | #define SHADER_DIR "shader" | 23 | #define SHADER_DIR "shader" |
| 24 | #define TAS_DIR "tas" | ||
| 24 | 25 | ||
| 25 | // yuzu-specific files | 26 | // yuzu-specific files |
| 26 | 27 | ||
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp index 6cdd14f13..43b79bd6d 100644 --- a/src/common/fs/path_util.cpp +++ b/src/common/fs/path_util.cpp | |||
| @@ -116,6 +116,7 @@ private: | |||
| 116 | GenerateYuzuPath(YuzuPath::ScreenshotsDir, yuzu_path / SCREENSHOTS_DIR); | 116 | GenerateYuzuPath(YuzuPath::ScreenshotsDir, yuzu_path / SCREENSHOTS_DIR); |
| 117 | GenerateYuzuPath(YuzuPath::SDMCDir, yuzu_path / SDMC_DIR); | 117 | GenerateYuzuPath(YuzuPath::SDMCDir, yuzu_path / SDMC_DIR); |
| 118 | GenerateYuzuPath(YuzuPath::ShaderDir, yuzu_path / SHADER_DIR); | 118 | GenerateYuzuPath(YuzuPath::ShaderDir, yuzu_path / SHADER_DIR); |
| 119 | GenerateYuzuPath(YuzuPath::TASDir, yuzu_path / TAS_DIR); | ||
| 119 | } | 120 | } |
| 120 | 121 | ||
| 121 | ~PathManagerImpl() = default; | 122 | ~PathManagerImpl() = default; |
diff --git a/src/common/fs/path_util.h b/src/common/fs/path_util.h index f956ac9a2..0a9e3a145 100644 --- a/src/common/fs/path_util.h +++ b/src/common/fs/path_util.h | |||
| @@ -23,6 +23,7 @@ enum class YuzuPath { | |||
| 23 | ScreenshotsDir, // Where yuzu screenshots are stored. | 23 | ScreenshotsDir, // Where yuzu screenshots are stored. |
| 24 | SDMCDir, // Where the emulated SDMC is stored. | 24 | SDMCDir, // Where the emulated SDMC is stored. |
| 25 | ShaderDir, // Where shaders are stored. | 25 | ShaderDir, // Where shaders are stored. |
| 26 | TASDir, // Where TAS scripts are stored. | ||
| 26 | }; | 27 | }; |
| 27 | 28 | ||
| 28 | /** | 29 | /** |
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 6661244cf..b44a44949 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp | |||
| @@ -314,8 +314,8 @@ private: | |||
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | void UntrackPlaceholder(boost::icl::separate_interval_set<size_t>::iterator it) { | 316 | void UntrackPlaceholder(boost::icl::separate_interval_set<size_t>::iterator it) { |
| 317 | placeholders.erase(it); | ||
| 318 | placeholder_host_pointers.erase(it->lower()); | 317 | placeholder_host_pointers.erase(it->lower()); |
| 318 | placeholders.erase(it); | ||
| 319 | } | 319 | } |
| 320 | 320 | ||
| 321 | /// Return true when a given memory region is a "nieche" and the placeholders don't have to be | 321 | /// Return true when a given memory region is a "nieche" and the placeholders don't have to be |
diff --git a/src/common/intrusive_red_black_tree.h b/src/common/intrusive_red_black_tree.h index 1f696fe80..3173cc449 100644 --- a/src/common/intrusive_red_black_tree.h +++ b/src/common/intrusive_red_black_tree.h | |||
| @@ -235,20 +235,19 @@ public: | |||
| 235 | 235 | ||
| 236 | template <typename T> | 236 | template <typename T> |
| 237 | concept HasLightCompareType = requires { | 237 | concept HasLightCompareType = requires { |
| 238 | { std::is_same<typename T::LightCompareType, void>::value } | 238 | { std::is_same<typename T::LightCompareType, void>::value } -> std::convertible_to<bool>; |
| 239 | ->std::convertible_to<bool>; | ||
| 240 | }; | 239 | }; |
| 241 | 240 | ||
| 242 | namespace impl { | 241 | namespace impl { |
| 243 | 242 | ||
| 244 | template <typename T, typename Default> | 243 | template <typename T, typename Default> |
| 245 | consteval auto* GetLightCompareType() { | 244 | consteval auto* GetLightCompareType() { |
| 246 | if constexpr (HasLightCompareType<T>) { | 245 | if constexpr (HasLightCompareType<T>) { |
| 247 | return static_cast<typename T::LightCompareType*>(nullptr); | 246 | return static_cast<typename T::LightCompareType*>(nullptr); |
| 248 | } else { | 247 | } else { |
| 249 | return static_cast<Default*>(nullptr); | 248 | return static_cast<Default*>(nullptr); |
| 249 | } | ||
| 250 | } | 250 | } |
| 251 | } | ||
| 252 | 251 | ||
| 253 | } // namespace impl | 252 | } // namespace impl |
| 254 | 253 | ||
diff --git a/src/common/settings.cpp b/src/common/settings.cpp index fd3b639cd..9dd5e3efb 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp | |||
| @@ -54,14 +54,13 @@ void LogSettings() { | |||
| 54 | log_setting("Renderer_GPUAccuracyLevel", values.gpu_accuracy.GetValue()); | 54 | log_setting("Renderer_GPUAccuracyLevel", values.gpu_accuracy.GetValue()); |
| 55 | log_setting("Renderer_UseAsynchronousGpuEmulation", | 55 | log_setting("Renderer_UseAsynchronousGpuEmulation", |
| 56 | values.use_asynchronous_gpu_emulation.GetValue()); | 56 | values.use_asynchronous_gpu_emulation.GetValue()); |
| 57 | log_setting("Renderer_UseNvdecEmulation", values.use_nvdec_emulation.GetValue()); | 57 | log_setting("Renderer_NvdecEmulation", values.nvdec_emulation.GetValue()); |
| 58 | log_setting("Renderer_AccelerateASTC", values.accelerate_astc.GetValue()); | 58 | log_setting("Renderer_AccelerateASTC", values.accelerate_astc.GetValue()); |
| 59 | log_setting("Renderer_UseVsync", values.use_vsync.GetValue()); | 59 | log_setting("Renderer_UseVsync", values.use_vsync.GetValue()); |
| 60 | log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue()); | 60 | log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue()); |
| 61 | log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); | 61 | log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); |
| 62 | log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue()); | 62 | log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue()); |
| 63 | log_setting("Audio_OutputEngine", values.sink_id.GetValue()); | 63 | log_setting("Audio_OutputEngine", values.sink_id.GetValue()); |
| 64 | log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue()); | ||
| 65 | log_setting("Audio_OutputDevice", values.audio_device_id.GetValue()); | 64 | log_setting("Audio_OutputDevice", values.audio_device_id.GetValue()); |
| 66 | log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue()); | 65 | log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue()); |
| 67 | log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir)); | 66 | log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir)); |
| @@ -70,8 +69,9 @@ void LogSettings() { | |||
| 70 | log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir)); | 69 | log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir)); |
| 71 | log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir)); | 70 | log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir)); |
| 72 | log_setting("Debugging_ProgramArgs", values.program_args.GetValue()); | 71 | log_setting("Debugging_ProgramArgs", values.program_args.GetValue()); |
| 73 | log_setting("Services_BCATBackend", values.bcat_backend.GetValue()); | 72 | log_setting("Input_EnableMotion", values.motion_enabled.GetValue()); |
| 74 | log_setting("Services_BCATBoxcatLocal", values.bcat_boxcat_local.GetValue()); | 73 | log_setting("Input_EnableVibration", values.vibration_enabled.GetValue()); |
| 74 | log_setting("Input_EnableRawInput", values.enable_raw_input.GetValue()); | ||
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | bool IsConfiguringGlobal() { | 77 | bool IsConfiguringGlobal() { |
| @@ -112,7 +112,6 @@ void RestoreGlobalState(bool is_powered_on) { | |||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | // Audio | 114 | // Audio |
| 115 | values.enable_audio_stretching.SetGlobal(true); | ||
| 116 | values.volume.SetGlobal(true); | 115 | values.volume.SetGlobal(true); |
| 117 | 116 | ||
| 118 | // Core | 117 | // Core |
| @@ -136,7 +135,7 @@ void RestoreGlobalState(bool is_powered_on) { | |||
| 136 | values.use_disk_shader_cache.SetGlobal(true); | 135 | values.use_disk_shader_cache.SetGlobal(true); |
| 137 | values.gpu_accuracy.SetGlobal(true); | 136 | values.gpu_accuracy.SetGlobal(true); |
| 138 | values.use_asynchronous_gpu_emulation.SetGlobal(true); | 137 | values.use_asynchronous_gpu_emulation.SetGlobal(true); |
| 139 | values.use_nvdec_emulation.SetGlobal(true); | 138 | values.nvdec_emulation.SetGlobal(true); |
| 140 | values.accelerate_astc.SetGlobal(true); | 139 | values.accelerate_astc.SetGlobal(true); |
| 141 | values.use_vsync.SetGlobal(true); | 140 | values.use_vsync.SetGlobal(true); |
| 142 | values.shader_backend.SetGlobal(true); | 141 | values.shader_backend.SetGlobal(true); |
diff --git a/src/common/settings.h b/src/common/settings.h index ec4d381e8..402339443 100644 --- a/src/common/settings.h +++ b/src/common/settings.h | |||
| @@ -16,7 +16,6 @@ | |||
| 16 | 16 | ||
| 17 | #include "common/common_types.h" | 17 | #include "common/common_types.h" |
| 18 | #include "common/settings_input.h" | 18 | #include "common/settings_input.h" |
| 19 | #include "input_common/udp/client.h" | ||
| 20 | 19 | ||
| 21 | namespace Settings { | 20 | namespace Settings { |
| 22 | 21 | ||
| @@ -48,6 +47,12 @@ enum class FullscreenMode : u32 { | |||
| 48 | Exclusive = 1, | 47 | Exclusive = 1, |
| 49 | }; | 48 | }; |
| 50 | 49 | ||
| 50 | enum class NvdecEmulation : u32 { | ||
| 51 | Off = 0, | ||
| 52 | CPU = 1, | ||
| 53 | GPU = 2, | ||
| 54 | }; | ||
| 55 | |||
| 51 | /** The BasicSetting class is a simple resource manager. It defines a label and default value | 56 | /** The BasicSetting class is a simple resource manager. It defines a label and default value |
| 52 | * alongside the actual value of the setting for simpler and less-error prone use with frontend | 57 | * alongside the actual value of the setting for simpler and less-error prone use with frontend |
| 53 | * configurations. Setting a default value and label is required, though subclasses may deviate from | 58 | * configurations. Setting a default value and label is required, though subclasses may deviate from |
| @@ -409,7 +414,6 @@ struct Values { | |||
| 409 | BasicSetting<std::string> audio_device_id{"auto", "output_device"}; | 414 | BasicSetting<std::string> audio_device_id{"auto", "output_device"}; |
| 410 | BasicSetting<std::string> sink_id{"auto", "output_engine"}; | 415 | BasicSetting<std::string> sink_id{"auto", "output_engine"}; |
| 411 | BasicSetting<bool> audio_muted{false, "audio_muted"}; | 416 | BasicSetting<bool> audio_muted{false, "audio_muted"}; |
| 412 | Setting<bool> enable_audio_stretching{true, "enable_audio_stretching"}; | ||
| 413 | RangedSetting<u8> volume{100, 0, 100, "volume"}; | 417 | RangedSetting<u8> volume{100, 0, 100, "volume"}; |
| 414 | 418 | ||
| 415 | // Core | 419 | // Core |
| @@ -466,7 +470,7 @@ struct Values { | |||
| 466 | RangedSetting<GPUAccuracy> gpu_accuracy{GPUAccuracy::High, GPUAccuracy::Normal, | 470 | RangedSetting<GPUAccuracy> gpu_accuracy{GPUAccuracy::High, GPUAccuracy::Normal, |
| 467 | GPUAccuracy::Extreme, "gpu_accuracy"}; | 471 | GPUAccuracy::Extreme, "gpu_accuracy"}; |
| 468 | Setting<bool> use_asynchronous_gpu_emulation{true, "use_asynchronous_gpu_emulation"}; | 472 | Setting<bool> use_asynchronous_gpu_emulation{true, "use_asynchronous_gpu_emulation"}; |
| 469 | Setting<bool> use_nvdec_emulation{true, "use_nvdec_emulation"}; | 473 | Setting<NvdecEmulation> nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"}; |
| 470 | Setting<bool> accelerate_astc{true, "accelerate_astc"}; | 474 | Setting<bool> accelerate_astc{true, "accelerate_astc"}; |
| 471 | Setting<bool> use_vsync{true, "use_vsync"}; | 475 | Setting<bool> use_vsync{true, "use_vsync"}; |
| 472 | BasicRangedSetting<u16> fps_cap{1000, 1, 1000, "fps_cap"}; | 476 | BasicRangedSetting<u16> fps_cap{1000, 1, 1000, "fps_cap"}; |
| @@ -498,14 +502,20 @@ struct Values { | |||
| 498 | 502 | ||
| 499 | Setting<bool> use_docked_mode{true, "use_docked_mode"}; | 503 | Setting<bool> use_docked_mode{true, "use_docked_mode"}; |
| 500 | 504 | ||
| 505 | BasicSetting<bool> enable_raw_input{false, "enable_raw_input"}; | ||
| 506 | |||
| 501 | Setting<bool> vibration_enabled{true, "vibration_enabled"}; | 507 | Setting<bool> vibration_enabled{true, "vibration_enabled"}; |
| 502 | Setting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"}; | 508 | Setting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"}; |
| 503 | 509 | ||
| 504 | Setting<bool> motion_enabled{true, "motion_enabled"}; | 510 | Setting<bool> motion_enabled{true, "motion_enabled"}; |
| 505 | BasicSetting<std::string> motion_device{"engine:motion_emu,update_period:100,sensitivity:0.01", | 511 | BasicSetting<std::string> motion_device{"engine:motion_emu,update_period:100,sensitivity:0.01", |
| 506 | "motion_device"}; | 512 | "motion_device"}; |
| 507 | BasicSetting<std::string> udp_input_servers{InputCommon::CemuhookUDP::DEFAULT_SRV, | 513 | BasicSetting<std::string> udp_input_servers{"127.0.0.1:26760", "udp_input_servers"}; |
| 508 | "udp_input_servers"}; | 514 | |
| 515 | BasicSetting<bool> pause_tas_on_load{true, "pause_tas_on_load"}; | ||
| 516 | BasicSetting<bool> tas_enable{false, "tas_enable"}; | ||
| 517 | BasicSetting<bool> tas_loop{false, "tas_loop"}; | ||
| 518 | BasicSetting<bool> tas_swap_controllers{true, "tas_swap_controllers"}; | ||
| 509 | 519 | ||
| 510 | BasicSetting<bool> mouse_panning{false, "mouse_panning"}; | 520 | BasicSetting<bool> mouse_panning{false, "mouse_panning"}; |
| 511 | BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"}; | 521 | BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"}; |
| @@ -558,8 +568,6 @@ struct Values { | |||
| 558 | BasicSetting<bool> use_dev_keys{false, "use_dev_keys"}; | 568 | BasicSetting<bool> use_dev_keys{false, "use_dev_keys"}; |
| 559 | 569 | ||
| 560 | // Network | 570 | // Network |
| 561 | BasicSetting<std::string> bcat_backend{"none", "bcat_backend"}; | ||
| 562 | BasicSetting<bool> bcat_boxcat_local{false, "bcat_boxcat_local"}; | ||
| 563 | BasicSetting<std::string> network_interface{std::string(), "network_interface"}; | 571 | BasicSetting<std::string> network_interface{std::string(), "network_interface"}; |
| 564 | 572 | ||
| 565 | // WebService | 573 | // WebService |
diff --git a/src/common/thread.cpp b/src/common/thread.cpp index d2c1ac60d..946a1114d 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp | |||
| @@ -2,7 +2,9 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/common_funcs.h" | 5 | #include <string> |
| 6 | |||
| 7 | #include "common/error.h" | ||
| 6 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 7 | #include "common/thread.h" | 9 | #include "common/thread.h" |
| 8 | #ifdef __APPLE__ | 10 | #ifdef __APPLE__ |
| @@ -21,8 +23,6 @@ | |||
| 21 | #include <unistd.h> | 23 | #include <unistd.h> |
| 22 | #endif | 24 | #endif |
| 23 | 25 | ||
| 24 | #include <string> | ||
| 25 | |||
| 26 | #ifdef __FreeBSD__ | 26 | #ifdef __FreeBSD__ |
| 27 | #define cpu_set_t cpuset_t | 27 | #define cpu_set_t cpuset_t |
| 28 | #endif | 28 | #endif |
diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h index 8430b9778..2c8c2b90e 100644 --- a/src/common/threadsafe_queue.h +++ b/src/common/threadsafe_queue.h | |||
| @@ -14,7 +14,7 @@ | |||
| 14 | #include <utility> | 14 | #include <utility> |
| 15 | 15 | ||
| 16 | namespace Common { | 16 | namespace Common { |
| 17 | template <typename T> | 17 | template <typename T, bool with_stop_token = false> |
| 18 | class SPSCQueue { | 18 | class SPSCQueue { |
| 19 | public: | 19 | public: |
| 20 | SPSCQueue() { | 20 | SPSCQueue() { |
| @@ -84,7 +84,7 @@ public: | |||
| 84 | void Wait() { | 84 | void Wait() { |
| 85 | if (Empty()) { | 85 | if (Empty()) { |
| 86 | std::unique_lock lock{cv_mutex}; | 86 | std::unique_lock lock{cv_mutex}; |
| 87 | cv.wait(lock, [this]() { return !Empty(); }); | 87 | cv.wait(lock, [this] { return !Empty(); }); |
| 88 | } | 88 | } |
| 89 | } | 89 | } |
| 90 | 90 | ||
| @@ -95,6 +95,19 @@ public: | |||
| 95 | return t; | 95 | return t; |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | T PopWait(std::stop_token stop_token) { | ||
| 99 | if (Empty()) { | ||
| 100 | std::unique_lock lock{cv_mutex}; | ||
| 101 | cv.wait(lock, stop_token, [this] { return !Empty(); }); | ||
| 102 | } | ||
| 103 | if (stop_token.stop_requested()) { | ||
| 104 | return T{}; | ||
| 105 | } | ||
| 106 | T t; | ||
| 107 | Pop(t); | ||
| 108 | return t; | ||
| 109 | } | ||
| 110 | |||
| 98 | // not thread-safe | 111 | // not thread-safe |
| 99 | void Clear() { | 112 | void Clear() { |
| 100 | size.store(0); | 113 | size.store(0); |
| @@ -123,13 +136,13 @@ private: | |||
| 123 | ElementPtr* read_ptr; | 136 | ElementPtr* read_ptr; |
| 124 | std::atomic_size_t size{0}; | 137 | std::atomic_size_t size{0}; |
| 125 | std::mutex cv_mutex; | 138 | std::mutex cv_mutex; |
| 126 | std::condition_variable cv; | 139 | std::conditional_t<with_stop_token, std::condition_variable_any, std::condition_variable> cv; |
| 127 | }; | 140 | }; |
| 128 | 141 | ||
| 129 | // a simple thread-safe, | 142 | // a simple thread-safe, |
| 130 | // single reader, multiple writer queue | 143 | // single reader, multiple writer queue |
| 131 | 144 | ||
| 132 | template <typename T> | 145 | template <typename T, bool with_stop_token = false> |
| 133 | class MPSCQueue { | 146 | class MPSCQueue { |
| 134 | public: | 147 | public: |
| 135 | [[nodiscard]] std::size_t Size() const { | 148 | [[nodiscard]] std::size_t Size() const { |
| @@ -166,13 +179,17 @@ public: | |||
| 166 | return spsc_queue.PopWait(); | 179 | return spsc_queue.PopWait(); |
| 167 | } | 180 | } |
| 168 | 181 | ||
| 182 | T PopWait(std::stop_token stop_token) { | ||
| 183 | return spsc_queue.PopWait(stop_token); | ||
| 184 | } | ||
| 185 | |||
| 169 | // not thread-safe | 186 | // not thread-safe |
| 170 | void Clear() { | 187 | void Clear() { |
| 171 | spsc_queue.Clear(); | 188 | spsc_queue.Clear(); |
| 172 | } | 189 | } |
| 173 | 190 | ||
| 174 | private: | 191 | private: |
| 175 | SPSCQueue<T> spsc_queue; | 192 | SPSCQueue<T, with_stop_token> spsc_queue; |
| 176 | std::mutex write_lock; | 193 | std::mutex write_lock; |
| 177 | }; | 194 | }; |
| 178 | } // namespace Common | 195 | } // namespace Common |
diff --git a/src/common/uuid.h b/src/common/uuid.h index 2353179d8..8ea01f8da 100644 --- a/src/common/uuid.h +++ b/src/common/uuid.h | |||
| @@ -58,6 +58,13 @@ struct UUID { | |||
| 58 | uuid = INVALID_UUID; | 58 | uuid = INVALID_UUID; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | [[nodiscard]] constexpr bool IsInvalid() const { | ||
| 62 | return uuid == INVALID_UUID; | ||
| 63 | } | ||
| 64 | [[nodiscard]] constexpr bool IsValid() const { | ||
| 65 | return !IsInvalid(); | ||
| 66 | } | ||
| 67 | |||
| 61 | // TODO(ogniK): Properly generate a Nintendo ID | 68 | // TODO(ogniK): Properly generate a Nintendo ID |
| 62 | [[nodiscard]] constexpr u64 GetNintendoID() const { | 69 | [[nodiscard]] constexpr u64 GetNintendoID() const { |
| 63 | return uuid[0]; | 70 | return uuid[0]; |
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 22dba3c2d..ba7c363c1 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h | |||
| @@ -667,8 +667,8 @@ template <typename T> | |||
| 667 | 667 | ||
| 668 | // linear interpolation via float: 0.0=begin, 1.0=end | 668 | // linear interpolation via float: 0.0=begin, 1.0=end |
| 669 | template <typename X> | 669 | template <typename X> |
| 670 | [[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end, | 670 | [[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) |
| 671 | const float t) { | 671 | Lerp(const X& begin, const X& end, const float t) { |
| 672 | return begin * (1.f - t) + end * t; | 672 | return begin * (1.f - t) + end * t; |
| 673 | } | 673 | } |
| 674 | 674 | ||
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 87d47e2e5..aa3b26628 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -106,8 +106,6 @@ add_library(core STATIC | |||
| 106 | file_sys/vfs_concat.h | 106 | file_sys/vfs_concat.h |
| 107 | file_sys/vfs_layered.cpp | 107 | file_sys/vfs_layered.cpp |
| 108 | file_sys/vfs_layered.h | 108 | file_sys/vfs_layered.h |
| 109 | file_sys/vfs_libzip.cpp | ||
| 110 | file_sys/vfs_libzip.h | ||
| 111 | file_sys/vfs_offset.cpp | 109 | file_sys/vfs_offset.cpp |
| 112 | file_sys/vfs_offset.h | 110 | file_sys/vfs_offset.h |
| 113 | file_sys/vfs_real.cpp | 111 | file_sys/vfs_real.cpp |
| @@ -263,6 +261,8 @@ add_library(core STATIC | |||
| 263 | hle/service/acc/acc_u0.h | 261 | hle/service/acc/acc_u0.h |
| 264 | hle/service/acc/acc_u1.cpp | 262 | hle/service/acc/acc_u1.cpp |
| 265 | hle/service/acc/acc_u1.h | 263 | hle/service/acc/acc_u1.h |
| 264 | hle/service/acc/async_context.cpp | ||
| 265 | hle/service/acc/async_context.h | ||
| 266 | hle/service/acc/errors.h | 266 | hle/service/acc/errors.h |
| 267 | hle/service/acc/profile_manager.cpp | 267 | hle/service/acc/profile_manager.cpp |
| 268 | hle/service/acc/profile_manager.h | 268 | hle/service/acc/profile_manager.h |
| @@ -651,13 +651,6 @@ add_library(core STATIC | |||
| 651 | tools/freezer.h | 651 | tools/freezer.h |
| 652 | ) | 652 | ) |
| 653 | 653 | ||
| 654 | if (YUZU_ENABLE_BOXCAT) | ||
| 655 | target_sources(core PRIVATE | ||
| 656 | hle/service/bcat/backend/boxcat.cpp | ||
| 657 | hle/service/bcat/backend/boxcat.h | ||
| 658 | ) | ||
| 659 | endif() | ||
| 660 | |||
| 661 | if (MSVC) | 654 | if (MSVC) |
| 662 | target_compile_options(core PRIVATE | 655 | target_compile_options(core PRIVATE |
| 663 | /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data | 656 | /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data |
| @@ -688,12 +681,7 @@ endif() | |||
| 688 | create_target_directory_groups(core) | 681 | create_target_directory_groups(core) |
| 689 | 682 | ||
| 690 | target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) | 683 | target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) |
| 691 | target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls Opus::Opus zip) | 684 | target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls Opus::Opus) |
| 692 | |||
| 693 | if (YUZU_ENABLE_BOXCAT) | ||
| 694 | target_compile_definitions(core PRIVATE -DYUZU_ENABLE_BOXCAT) | ||
| 695 | target_link_libraries(core PRIVATE httplib nlohmann_json::nlohmann_json) | ||
| 696 | endif() | ||
| 697 | 685 | ||
| 698 | if (ENABLE_WEB_SERVICE) | 686 | if (ENABLE_WEB_SERVICE) |
| 699 | target_compile_definitions(core PRIVATE -DENABLE_WEB_SERVICE) | 687 | target_compile_definitions(core PRIVATE -DENABLE_WEB_SERVICE) |
diff --git a/src/core/core.cpp b/src/core/core.cpp index ba4629993..bb268a319 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -83,6 +83,12 @@ FileSys::StorageId GetStorageIdForFrontendSlot( | |||
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | void KProcessDeleter(Kernel::KProcess* process) { | ||
| 87 | process->Destroy(); | ||
| 88 | } | ||
| 89 | |||
| 90 | using KProcessPtr = std::unique_ptr<Kernel::KProcess, decltype(&KProcessDeleter)>; | ||
| 91 | |||
| 86 | } // Anonymous namespace | 92 | } // Anonymous namespace |
| 87 | 93 | ||
| 88 | FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, | 94 | FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, |
| @@ -233,8 +239,8 @@ struct System::Impl { | |||
| 233 | } | 239 | } |
| 234 | 240 | ||
| 235 | telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider); | 241 | telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider); |
| 236 | auto main_process = Kernel::KProcess::Create(system.Kernel()); | 242 | main_process = KProcessPtr{Kernel::KProcess::Create(system.Kernel()), KProcessDeleter}; |
| 237 | ASSERT(Kernel::KProcess::Initialize(main_process, system, "main", | 243 | ASSERT(Kernel::KProcess::Initialize(main_process.get(), system, "main", |
| 238 | Kernel::KProcess::ProcessType::Userland) | 244 | Kernel::KProcess::ProcessType::Userland) |
| 239 | .IsSuccess()); | 245 | .IsSuccess()); |
| 240 | main_process->Open(); | 246 | main_process->Open(); |
| @@ -247,7 +253,7 @@ struct System::Impl { | |||
| 247 | static_cast<u32>(load_result)); | 253 | static_cast<u32>(load_result)); |
| 248 | } | 254 | } |
| 249 | AddGlueRegistrationForProcess(*app_loader, *main_process); | 255 | AddGlueRegistrationForProcess(*app_loader, *main_process); |
| 250 | kernel.MakeCurrentProcess(main_process); | 256 | kernel.MakeCurrentProcess(main_process.get()); |
| 251 | kernel.InitializeCores(); | 257 | kernel.InitializeCores(); |
| 252 | 258 | ||
| 253 | // Initialize cheat engine | 259 | // Initialize cheat engine |
| @@ -299,10 +305,6 @@ struct System::Impl { | |||
| 299 | is_powered_on = false; | 305 | is_powered_on = false; |
| 300 | exit_lock = false; | 306 | exit_lock = false; |
| 301 | 307 | ||
| 302 | if (gpu_core) { | ||
| 303 | gpu_core->ShutDown(); | ||
| 304 | } | ||
| 305 | |||
| 306 | services.reset(); | 308 | services.reset(); |
| 307 | service_manager.reset(); | 309 | service_manager.reset(); |
| 308 | cheat_engine.reset(); | 310 | cheat_engine.reset(); |
| @@ -311,11 +313,13 @@ struct System::Impl { | |||
| 311 | time_manager.Shutdown(); | 313 | time_manager.Shutdown(); |
| 312 | core_timing.Shutdown(); | 314 | core_timing.Shutdown(); |
| 313 | app_loader.reset(); | 315 | app_loader.reset(); |
| 314 | gpu_core.reset(); | ||
| 315 | perf_stats.reset(); | 316 | perf_stats.reset(); |
| 317 | gpu_core.reset(); | ||
| 316 | kernel.Shutdown(); | 318 | kernel.Shutdown(); |
| 317 | memory.Reset(); | 319 | memory.Reset(); |
| 318 | applet_manager.ClearAll(); | 320 | applet_manager.ClearAll(); |
| 321 | // TODO: The main process should be freed based on KAutoObject ref counting. | ||
| 322 | main_process.reset(); | ||
| 319 | 323 | ||
| 320 | LOG_DEBUG(Core, "Shutdown OK"); | 324 | LOG_DEBUG(Core, "Shutdown OK"); |
| 321 | } | 325 | } |
| @@ -374,6 +378,7 @@ struct System::Impl { | |||
| 374 | std::unique_ptr<Tegra::GPU> gpu_core; | 378 | std::unique_ptr<Tegra::GPU> gpu_core; |
| 375 | std::unique_ptr<Hardware::InterruptManager> interrupt_manager; | 379 | std::unique_ptr<Hardware::InterruptManager> interrupt_manager; |
| 376 | std::unique_ptr<Core::DeviceMemory> device_memory; | 380 | std::unique_ptr<Core::DeviceMemory> device_memory; |
| 381 | KProcessPtr main_process{nullptr, KProcessDeleter}; | ||
| 377 | Core::Memory::Memory memory; | 382 | Core::Memory::Memory memory; |
| 378 | CpuManager cpu_manager; | 383 | CpuManager cpu_manager; |
| 379 | std::atomic_bool is_powered_on{}; | 384 | std::atomic_bool is_powered_on{}; |
| @@ -416,6 +421,7 @@ struct System::Impl { | |||
| 416 | bool is_async_gpu{}; | 421 | bool is_async_gpu{}; |
| 417 | 422 | ||
| 418 | ExecuteProgramCallback execute_program_callback; | 423 | ExecuteProgramCallback execute_program_callback; |
| 424 | ExitCallback exit_callback; | ||
| 419 | 425 | ||
| 420 | std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{}; | 426 | std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{}; |
| 421 | std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_dynarmic{}; | 427 | std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_dynarmic{}; |
| @@ -793,6 +799,18 @@ void System::ExecuteProgram(std::size_t program_index) { | |||
| 793 | } | 799 | } |
| 794 | } | 800 | } |
| 795 | 801 | ||
| 802 | void System::RegisterExitCallback(ExitCallback&& callback) { | ||
| 803 | impl->exit_callback = std::move(callback); | ||
| 804 | } | ||
| 805 | |||
| 806 | void System::Exit() { | ||
| 807 | if (impl->exit_callback) { | ||
| 808 | impl->exit_callback(); | ||
| 809 | } else { | ||
| 810 | LOG_CRITICAL(Core, "exit_callback must be initialized by the frontend"); | ||
| 811 | } | ||
| 812 | } | ||
| 813 | |||
| 796 | void System::ApplySettings() { | 814 | void System::ApplySettings() { |
| 797 | if (IsPoweredOn()) { | 815 | if (IsPoweredOn()) { |
| 798 | Renderer().RefreshBaseSettings(); | 816 | Renderer().RefreshBaseSettings(); |
diff --git a/src/core/core.h b/src/core/core.h index 715ab88e7..a796472b2 100644 --- a/src/core/core.h +++ b/src/core/core.h | |||
| @@ -387,6 +387,18 @@ public: | |||
| 387 | */ | 387 | */ |
| 388 | void ExecuteProgram(std::size_t program_index); | 388 | void ExecuteProgram(std::size_t program_index); |
| 389 | 389 | ||
| 390 | /// Type used for the frontend to designate a callback for System to exit the application. | ||
| 391 | using ExitCallback = std::function<void()>; | ||
| 392 | |||
| 393 | /** | ||
| 394 | * Registers a callback from the frontend for System to exit the application. | ||
| 395 | * @param callback Callback from the frontend to exit the application. | ||
| 396 | */ | ||
| 397 | void RegisterExitCallback(ExitCallback&& callback); | ||
| 398 | |||
| 399 | /// Instructs the frontend to exit the application. | ||
| 400 | void Exit(); | ||
| 401 | |||
| 390 | /// Applies any changes to settings to this core instance. | 402 | /// Applies any changes to settings to this core instance. |
| 391 | void ApplySettings(); | 403 | void ApplySettings(); |
| 392 | 404 | ||
diff --git a/src/core/file_sys/kernel_executable.h b/src/core/file_sys/kernel_executable.h index 044c554d3..79ca82f8b 100644 --- a/src/core/file_sys/kernel_executable.h +++ b/src/core/file_sys/kernel_executable.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <string> | ||
| 8 | #include <vector> | 9 | #include <vector> |
| 9 | 10 | ||
| 10 | #include "common/common_funcs.h" | 11 | #include "common/common_funcs.h" |
diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp index 01ae1a567..35a53d36c 100644 --- a/src/core/file_sys/program_metadata.cpp +++ b/src/core/file_sys/program_metadata.cpp | |||
| @@ -77,7 +77,7 @@ void ProgramMetadata::LoadManual(bool is_64_bit, ProgramAddressSpaceType address | |||
| 77 | aci_header.title_id = title_id; | 77 | aci_header.title_id = title_id; |
| 78 | aci_file_access.permissions = filesystem_permissions; | 78 | aci_file_access.permissions = filesystem_permissions; |
| 79 | npdm_header.system_resource_size = system_resource_size; | 79 | npdm_header.system_resource_size = system_resource_size; |
| 80 | aci_kernel_capabilities = std ::move(capabilities); | 80 | aci_kernel_capabilities = std::move(capabilities); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | bool ProgramMetadata::Is64BitProgram() const { | 83 | bool ProgramMetadata::Is64BitProgram() const { |
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp index 368419eca..f5ad10b15 100644 --- a/src/core/file_sys/vfs.cpp +++ b/src/core/file_sys/vfs.cpp | |||
| @@ -273,6 +273,10 @@ VirtualFile VfsDirectory::GetFile(std::string_view name) const { | |||
| 273 | return iter == files.end() ? nullptr : *iter; | 273 | return iter == files.end() ? nullptr : *iter; |
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | FileTimeStampRaw VfsDirectory::GetFileTimeStamp([[maybe_unused]] std::string_view path) const { | ||
| 277 | return {}; | ||
| 278 | } | ||
| 279 | |||
| 276 | VirtualDir VfsDirectory::GetSubdirectory(std::string_view name) const { | 280 | VirtualDir VfsDirectory::GetSubdirectory(std::string_view name) const { |
| 277 | const auto& subs = GetSubdirectories(); | 281 | const auto& subs = GetSubdirectories(); |
| 278 | const auto iter = std::find_if(subs.begin(), subs.end(), | 282 | const auto iter = std::find_if(subs.begin(), subs.end(), |
diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index afd64e95c..ff6935da6 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h | |||
| @@ -199,6 +199,9 @@ public: | |||
| 199 | // file with name. | 199 | // file with name. |
| 200 | virtual VirtualFile GetFile(std::string_view name) const; | 200 | virtual VirtualFile GetFile(std::string_view name) const; |
| 201 | 201 | ||
| 202 | // Returns a struct containing the file's timestamp. | ||
| 203 | virtual FileTimeStampRaw GetFileTimeStamp(std::string_view path) const; | ||
| 204 | |||
| 202 | // Returns a vector containing all of the subdirectories in this directory. | 205 | // Returns a vector containing all of the subdirectories in this directory. |
| 203 | virtual std::vector<VirtualDir> GetSubdirectories() const = 0; | 206 | virtual std::vector<VirtualDir> GetSubdirectories() const = 0; |
| 204 | // Returns the directory with name matching name. Returns nullptr if directory dosen't have a | 207 | // Returns the directory with name matching name. Returns nullptr if directory dosen't have a |
diff --git a/src/core/file_sys/vfs_libzip.cpp b/src/core/file_sys/vfs_libzip.cpp deleted file mode 100644 index 00e256779..000000000 --- a/src/core/file_sys/vfs_libzip.cpp +++ /dev/null | |||
| @@ -1,88 +0,0 @@ | |||
| 1 | // Copyright 2019 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <string> | ||
| 6 | |||
| 7 | #ifdef __GNUC__ | ||
| 8 | #pragma GCC diagnostic push | ||
| 9 | #pragma GCC diagnostic ignored "-Wshadow" | ||
| 10 | #endif | ||
| 11 | #include <zip.h> | ||
| 12 | #ifdef __GNUC__ | ||
| 13 | #pragma GCC diagnostic pop | ||
| 14 | #endif | ||
| 15 | |||
| 16 | #include "common/fs/path_util.h" | ||
| 17 | #include "core/file_sys/vfs.h" | ||
| 18 | #include "core/file_sys/vfs_libzip.h" | ||
| 19 | #include "core/file_sys/vfs_vector.h" | ||
| 20 | |||
| 21 | namespace FileSys { | ||
| 22 | |||
| 23 | VirtualDir ExtractZIP(VirtualFile file) { | ||
| 24 | zip_error_t error{}; | ||
| 25 | |||
| 26 | const auto data = file->ReadAllBytes(); | ||
| 27 | std::unique_ptr<zip_source_t, decltype(&zip_source_close)> src{ | ||
| 28 | zip_source_buffer_create(data.data(), data.size(), 0, &error), zip_source_close}; | ||
| 29 | if (src == nullptr) | ||
| 30 | return nullptr; | ||
| 31 | |||
| 32 | std::unique_ptr<zip_t, decltype(&zip_close)> zip{zip_open_from_source(src.get(), 0, &error), | ||
| 33 | zip_close}; | ||
| 34 | if (zip == nullptr) | ||
| 35 | return nullptr; | ||
| 36 | |||
| 37 | std::shared_ptr<VectorVfsDirectory> out = std::make_shared<VectorVfsDirectory>(); | ||
| 38 | |||
| 39 | const auto num_entries = static_cast<std::size_t>(zip_get_num_entries(zip.get(), 0)); | ||
| 40 | |||
| 41 | zip_stat_t stat{}; | ||
| 42 | zip_stat_init(&stat); | ||
| 43 | |||
| 44 | for (std::size_t i = 0; i < num_entries; ++i) { | ||
| 45 | const auto stat_res = zip_stat_index(zip.get(), i, 0, &stat); | ||
| 46 | if (stat_res == -1) | ||
| 47 | return nullptr; | ||
| 48 | |||
| 49 | const std::string name(stat.name); | ||
| 50 | if (name.empty()) | ||
| 51 | continue; | ||
| 52 | |||
| 53 | if (name.back() != '/') { | ||
| 54 | std::unique_ptr<zip_file_t, decltype(&zip_fclose)> file2{ | ||
| 55 | zip_fopen_index(zip.get(), i, 0), zip_fclose}; | ||
| 56 | |||
| 57 | std::vector<u8> buf(stat.size); | ||
| 58 | if (zip_fread(file2.get(), buf.data(), buf.size()) != s64(buf.size())) | ||
| 59 | return nullptr; | ||
| 60 | |||
| 61 | const auto parts = Common::FS::SplitPathComponents(stat.name); | ||
| 62 | const auto new_file = std::make_shared<VectorVfsFile>(buf, parts.back()); | ||
| 63 | |||
| 64 | std::shared_ptr<VectorVfsDirectory> dtrv = out; | ||
| 65 | for (std::size_t j = 0; j < parts.size() - 1; ++j) { | ||
| 66 | if (dtrv == nullptr) | ||
| 67 | return nullptr; | ||
| 68 | const auto subdir = dtrv->GetSubdirectory(parts[j]); | ||
| 69 | if (subdir == nullptr) { | ||
| 70 | const auto temp = std::make_shared<VectorVfsDirectory>( | ||
| 71 | std::vector<VirtualFile>{}, std::vector<VirtualDir>{}, parts[j]); | ||
| 72 | dtrv->AddDirectory(temp); | ||
| 73 | dtrv = temp; | ||
| 74 | } else { | ||
| 75 | dtrv = std::dynamic_pointer_cast<VectorVfsDirectory>(subdir); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | if (dtrv == nullptr) | ||
| 80 | return nullptr; | ||
| 81 | dtrv->AddFile(new_file); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | return out; | ||
| 86 | } | ||
| 87 | |||
| 88 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/vfs_libzip.h b/src/core/file_sys/vfs_libzip.h deleted file mode 100644 index f68af576a..000000000 --- a/src/core/file_sys/vfs_libzip.h +++ /dev/null | |||
| @@ -1,13 +0,0 @@ | |||
| 1 | // Copyright 2019 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/file_sys/vfs_types.h" | ||
| 8 | |||
| 9 | namespace FileSys { | ||
| 10 | |||
| 11 | VirtualDir ExtractZIP(VirtualFile zip); | ||
| 12 | |||
| 13 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 3dad54f49..f4073b76a 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp | |||
| @@ -13,6 +13,13 @@ | |||
| 13 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 14 | #include "core/file_sys/vfs_real.h" | 14 | #include "core/file_sys/vfs_real.h" |
| 15 | 15 | ||
| 16 | // For FileTimeStampRaw | ||
| 17 | #include <sys/stat.h> | ||
| 18 | |||
| 19 | #ifdef _MSC_VER | ||
| 20 | #define stat _stat64 | ||
| 21 | #endif | ||
| 22 | |||
| 16 | namespace FileSys { | 23 | namespace FileSys { |
| 17 | 24 | ||
| 18 | namespace FS = Common::FS; | 25 | namespace FS = Common::FS; |
| @@ -392,6 +399,28 @@ std::vector<VirtualFile> RealVfsDirectory::GetFiles() const { | |||
| 392 | return IterateEntries<RealVfsFile, VfsFile>(); | 399 | return IterateEntries<RealVfsFile, VfsFile>(); |
| 393 | } | 400 | } |
| 394 | 401 | ||
| 402 | FileTimeStampRaw RealVfsDirectory::GetFileTimeStamp(std::string_view path_) const { | ||
| 403 | const auto full_path = FS::SanitizePath(path + '/' + std::string(path_)); | ||
| 404 | const auto fs_path = std::filesystem::path{FS::ToU8String(full_path)}; | ||
| 405 | struct stat file_status; | ||
| 406 | |||
| 407 | #ifdef _WIN32 | ||
| 408 | const auto stat_result = _wstat64(fs_path.c_str(), &file_status); | ||
| 409 | #else | ||
| 410 | const auto stat_result = stat(fs_path.c_str(), &file_status); | ||
| 411 | #endif | ||
| 412 | |||
| 413 | if (stat_result != 0) { | ||
| 414 | return {}; | ||
| 415 | } | ||
| 416 | |||
| 417 | return { | ||
| 418 | .created{static_cast<u64>(file_status.st_ctime)}, | ||
| 419 | .accessed{static_cast<u64>(file_status.st_atime)}, | ||
| 420 | .modified{static_cast<u64>(file_status.st_mtime)}, | ||
| 421 | }; | ||
| 422 | } | ||
| 423 | |||
| 395 | std::vector<VirtualDir> RealVfsDirectory::GetSubdirectories() const { | 424 | std::vector<VirtualDir> RealVfsDirectory::GetSubdirectories() const { |
| 396 | return IterateEntries<RealVfsDirectory, VfsDirectory>(); | 425 | return IterateEntries<RealVfsDirectory, VfsDirectory>(); |
| 397 | } | 426 | } |
diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h index e4d1bba79..746e624cb 100644 --- a/src/core/file_sys/vfs_real.h +++ b/src/core/file_sys/vfs_real.h | |||
| @@ -86,6 +86,7 @@ public: | |||
| 86 | VirtualDir CreateDirectoryRelative(std::string_view relative_path) override; | 86 | VirtualDir CreateDirectoryRelative(std::string_view relative_path) override; |
| 87 | bool DeleteSubdirectoryRecursive(std::string_view name) override; | 87 | bool DeleteSubdirectoryRecursive(std::string_view name) override; |
| 88 | std::vector<VirtualFile> GetFiles() const override; | 88 | std::vector<VirtualFile> GetFiles() const override; |
| 89 | FileTimeStampRaw GetFileTimeStamp(std::string_view path) const override; | ||
| 89 | std::vector<VirtualDir> GetSubdirectories() const override; | 90 | std::vector<VirtualDir> GetSubdirectories() const override; |
| 90 | bool IsWritable() const override; | 91 | bool IsWritable() const override; |
| 91 | bool IsReadable() const override; | 92 | bool IsReadable() const override; |
diff --git a/src/core/file_sys/vfs_types.h b/src/core/file_sys/vfs_types.h index 6215ed7af..ed0724717 100644 --- a/src/core/file_sys/vfs_types.h +++ b/src/core/file_sys/vfs_types.h | |||
| @@ -6,6 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | 8 | ||
| 9 | #include "common/common_types.h" | ||
| 10 | |||
| 9 | namespace FileSys { | 11 | namespace FileSys { |
| 10 | 12 | ||
| 11 | class VfsDirectory; | 13 | class VfsDirectory; |
| @@ -18,4 +20,11 @@ using VirtualDir = std::shared_ptr<VfsDirectory>; | |||
| 18 | using VirtualFile = std::shared_ptr<VfsFile>; | 20 | using VirtualFile = std::shared_ptr<VfsFile>; |
| 19 | using VirtualFilesystem = std::shared_ptr<VfsFilesystem>; | 21 | using VirtualFilesystem = std::shared_ptr<VfsFilesystem>; |
| 20 | 22 | ||
| 23 | struct FileTimeStampRaw { | ||
| 24 | u64 created{}; | ||
| 25 | u64 accessed{}; | ||
| 26 | u64 modified{}; | ||
| 27 | u64 padding{}; | ||
| 28 | }; | ||
| 29 | |||
| 21 | } // namespace FileSys | 30 | } // namespace FileSys |
diff --git a/src/core/frontend/applets/profile_select.cpp b/src/core/frontend/applets/profile_select.cpp index 4c58c310f..3e4f90be2 100644 --- a/src/core/frontend/applets/profile_select.cpp +++ b/src/core/frontend/applets/profile_select.cpp | |||
| @@ -13,7 +13,8 @@ ProfileSelectApplet::~ProfileSelectApplet() = default; | |||
| 13 | void DefaultProfileSelectApplet::SelectProfile( | 13 | void DefaultProfileSelectApplet::SelectProfile( |
| 14 | std::function<void(std::optional<Common::UUID>)> callback) const { | 14 | std::function<void(std::optional<Common::UUID>)> callback) const { |
| 15 | Service::Account::ProfileManager manager; | 15 | Service::Account::ProfileManager manager; |
| 16 | callback(manager.GetUser(Settings::values.current_user.GetValue()).value_or(Common::UUID{})); | 16 | callback(manager.GetUser(Settings::values.current_user.GetValue()) |
| 17 | .value_or(Common::UUID{Common::INVALID_UUID})); | ||
| 17 | LOG_INFO(Service_ACC, "called, selecting current user instead of prompting..."); | 18 | LOG_INFO(Service_ACC, "called, selecting current user instead of prompting..."); |
| 18 | } | 19 | } |
| 19 | 20 | ||
diff --git a/src/core/hle/api_version.h b/src/core/hle/api_version.h index 43d5670a9..626e30753 100644 --- a/src/core/hle/api_version.h +++ b/src/core/hle/api_version.h | |||
| @@ -28,13 +28,20 @@ constexpr char DISPLAY_TITLE[] = "NintendoSDK Firmware for NX 12.1.0-1.0"; | |||
| 28 | 28 | ||
| 29 | // Atmosphere version constants. | 29 | // Atmosphere version constants. |
| 30 | 30 | ||
| 31 | constexpr u8 ATMOSPHERE_RELEASE_VERSION_MAJOR = 0; | 31 | constexpr u8 ATMOSPHERE_RELEASE_VERSION_MAJOR = 1; |
| 32 | constexpr u8 ATMOSPHERE_RELEASE_VERSION_MINOR = 19; | 32 | constexpr u8 ATMOSPHERE_RELEASE_VERSION_MINOR = 0; |
| 33 | constexpr u8 ATMOSPHERE_RELEASE_VERSION_MICRO = 5; | 33 | constexpr u8 ATMOSPHERE_RELEASE_VERSION_MICRO = 0; |
| 34 | |||
| 35 | constexpr u32 AtmosphereTargetFirmwareWithRevision(u8 major, u8 minor, u8 micro, u8 rev) { | ||
| 36 | return u32{major} << 24 | u32{minor} << 16 | u32{micro} << 8 | u32{rev}; | ||
| 37 | } | ||
| 38 | |||
| 39 | constexpr u32 AtmosphereTargetFirmware(u8 major, u8 minor, u8 micro) { | ||
| 40 | return AtmosphereTargetFirmwareWithRevision(major, minor, micro, 0); | ||
| 41 | } | ||
| 34 | 42 | ||
| 35 | constexpr u32 GetTargetFirmware() { | 43 | constexpr u32 GetTargetFirmware() { |
| 36 | return u32{HOS_VERSION_MAJOR} << 24 | u32{HOS_VERSION_MINOR} << 16 | | 44 | return AtmosphereTargetFirmware(HOS_VERSION_MAJOR, HOS_VERSION_MINOR, HOS_VERSION_MICRO); |
| 37 | u32{HOS_VERSION_MICRO} << 8 | 0U; | ||
| 38 | } | 45 | } |
| 39 | 46 | ||
| 40 | } // namespace HLE::ApiVersion | 47 | } // namespace HLE::ApiVersion |
diff --git a/src/core/hle/kernel/k_handle_table.cpp b/src/core/hle/kernel/k_handle_table.cpp index 6a420d5b0..44d13169f 100644 --- a/src/core/hle/kernel/k_handle_table.cpp +++ b/src/core/hle/kernel/k_handle_table.cpp | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | namespace Kernel { | 7 | namespace Kernel { |
| 8 | 8 | ||
| 9 | KHandleTable::KHandleTable(KernelCore& kernel_) : kernel{kernel_} {} | 9 | KHandleTable::KHandleTable(KernelCore& kernel_) : kernel{kernel_} {} |
| 10 | KHandleTable ::~KHandleTable() = default; | 10 | KHandleTable::~KHandleTable() = default; |
| 11 | 11 | ||
| 12 | ResultCode KHandleTable::Finalize() { | 12 | ResultCode KHandleTable::Finalize() { |
| 13 | // Get the table and clear our record of it. | 13 | // Get the table and clear our record of it. |
diff --git a/src/core/hle/kernel/k_priority_queue.h b/src/core/hle/kernel/k_priority_queue.h index 4aa669d95..f4d71ad7e 100644 --- a/src/core/hle/kernel/k_priority_queue.h +++ b/src/core/hle/kernel/k_priority_queue.h | |||
| @@ -22,12 +22,10 @@ class KThread; | |||
| 22 | 22 | ||
| 23 | template <typename T> | 23 | template <typename T> |
| 24 | concept KPriorityQueueAffinityMask = !std::is_reference_v<T> && requires(T & t) { | 24 | concept KPriorityQueueAffinityMask = !std::is_reference_v<T> && requires(T & t) { |
| 25 | { t.GetAffinityMask() } | 25 | { t.GetAffinityMask() } -> Common::ConvertibleTo<u64>; |
| 26 | ->Common::ConvertibleTo<u64>; | ||
| 27 | {t.SetAffinityMask(0)}; | 26 | {t.SetAffinityMask(0)}; |
| 28 | 27 | ||
| 29 | { t.GetAffinity(0) } | 28 | { t.GetAffinity(0) } -> std::same_as<bool>; |
| 30 | ->std::same_as<bool>; | ||
| 31 | {t.SetAffinity(0, false)}; | 29 | {t.SetAffinity(0, false)}; |
| 32 | {t.SetAll()}; | 30 | {t.SetAll()}; |
| 33 | }; | 31 | }; |
| @@ -38,25 +36,20 @@ concept KPriorityQueueMember = !std::is_reference_v<T> && requires(T & t) { | |||
| 38 | {(typename T::QueueEntry()).Initialize()}; | 36 | {(typename T::QueueEntry()).Initialize()}; |
| 39 | {(typename T::QueueEntry()).SetPrev(std::addressof(t))}; | 37 | {(typename T::QueueEntry()).SetPrev(std::addressof(t))}; |
| 40 | {(typename T::QueueEntry()).SetNext(std::addressof(t))}; | 38 | {(typename T::QueueEntry()).SetNext(std::addressof(t))}; |
| 41 | { (typename T::QueueEntry()).GetNext() } | 39 | { (typename T::QueueEntry()).GetNext() } -> std::same_as<T*>; |
| 42 | ->std::same_as<T*>; | 40 | { (typename T::QueueEntry()).GetPrev() } -> std::same_as<T*>; |
| 43 | { (typename T::QueueEntry()).GetPrev() } | 41 | { t.GetPriorityQueueEntry(0) } -> std::same_as<typename T::QueueEntry&>; |
| 44 | ->std::same_as<T*>; | ||
| 45 | { t.GetPriorityQueueEntry(0) } | ||
| 46 | ->std::same_as<typename T::QueueEntry&>; | ||
| 47 | 42 | ||
| 48 | {t.GetAffinityMask()}; | 43 | {t.GetAffinityMask()}; |
| 49 | { std::remove_cvref_t<decltype(t.GetAffinityMask())>() } | 44 | { std::remove_cvref_t<decltype(t.GetAffinityMask())>() } -> KPriorityQueueAffinityMask; |
| 50 | ->KPriorityQueueAffinityMask; | ||
| 51 | 45 | ||
| 52 | { t.GetActiveCore() } | 46 | { t.GetActiveCore() } -> Common::ConvertibleTo<s32>; |
| 53 | ->Common::ConvertibleTo<s32>; | 47 | { t.GetPriority() } -> Common::ConvertibleTo<s32>; |
| 54 | { t.GetPriority() } | ||
| 55 | ->Common::ConvertibleTo<s32>; | ||
| 56 | }; | 48 | }; |
| 57 | 49 | ||
| 58 | template <typename Member, size_t NumCores_, int LowestPriority, int HighestPriority> | 50 | template <typename Member, size_t NumCores_, int LowestPriority, int HighestPriority> |
| 59 | requires KPriorityQueueMember<Member> class KPriorityQueue { | 51 | requires KPriorityQueueMember<Member> |
| 52 | class KPriorityQueue { | ||
| 60 | public: | 53 | public: |
| 61 | using AffinityMaskType = std::remove_cv_t< | 54 | using AffinityMaskType = std::remove_cv_t< |
| 62 | std::remove_reference_t<decltype(std::declval<Member>().GetAffinityMask())>>; | 55 | std::remove_reference_t<decltype(std::declval<Member>().GetAffinityMask())>>; |
diff --git a/src/core/hle/kernel/k_scheduler.h b/src/core/hle/kernel/k_scheduler.h index 12cfae919..c8ccc1ae4 100644 --- a/src/core/hle/kernel/k_scheduler.h +++ b/src/core/hle/kernel/k_scheduler.h | |||
| @@ -197,7 +197,7 @@ private: | |||
| 197 | 197 | ||
| 198 | class [[nodiscard]] KScopedSchedulerLock : KScopedLock<GlobalSchedulerContext::LockType> { | 198 | class [[nodiscard]] KScopedSchedulerLock : KScopedLock<GlobalSchedulerContext::LockType> { |
| 199 | public: | 199 | public: |
| 200 | explicit KScopedSchedulerLock(KernelCore & kernel); | 200 | explicit KScopedSchedulerLock(KernelCore& kernel); |
| 201 | ~KScopedSchedulerLock(); | 201 | ~KScopedSchedulerLock(); |
| 202 | }; | 202 | }; |
| 203 | 203 | ||
diff --git a/src/core/hle/kernel/k_scoped_lock.h b/src/core/hle/kernel/k_scoped_lock.h index 72c3b0252..4fb180fc6 100644 --- a/src/core/hle/kernel/k_scoped_lock.h +++ b/src/core/hle/kernel/k_scoped_lock.h | |||
| @@ -13,19 +13,18 @@ namespace Kernel { | |||
| 13 | 13 | ||
| 14 | template <typename T> | 14 | template <typename T> |
| 15 | concept KLockable = !std::is_reference_v<T> && requires(T & t) { | 15 | concept KLockable = !std::is_reference_v<T> && requires(T & t) { |
| 16 | { t.Lock() } | 16 | { t.Lock() } -> std::same_as<void>; |
| 17 | ->std::same_as<void>; | 17 | { t.Unlock() } -> std::same_as<void>; |
| 18 | { t.Unlock() } | ||
| 19 | ->std::same_as<void>; | ||
| 20 | }; | 18 | }; |
| 21 | 19 | ||
| 22 | template <typename T> | 20 | template <typename T> |
| 23 | requires KLockable<T> class [[nodiscard]] KScopedLock { | 21 | requires KLockable<T> |
| 22 | class [[nodiscard]] KScopedLock { | ||
| 24 | public: | 23 | public: |
| 25 | explicit KScopedLock(T * l) : lock_ptr(l) { | 24 | explicit KScopedLock(T* l) : lock_ptr(l) { |
| 26 | this->lock_ptr->Lock(); | 25 | this->lock_ptr->Lock(); |
| 27 | } | 26 | } |
| 28 | explicit KScopedLock(T & l) : KScopedLock(std::addressof(l)) {} | 27 | explicit KScopedLock(T& l) : KScopedLock(std::addressof(l)) {} |
| 29 | 28 | ||
| 30 | ~KScopedLock() { | 29 | ~KScopedLock() { |
| 31 | this->lock_ptr->Unlock(); | 30 | this->lock_ptr->Unlock(); |
| @@ -34,7 +33,7 @@ public: | |||
| 34 | KScopedLock(const KScopedLock&) = delete; | 33 | KScopedLock(const KScopedLock&) = delete; |
| 35 | KScopedLock& operator=(const KScopedLock&) = delete; | 34 | KScopedLock& operator=(const KScopedLock&) = delete; |
| 36 | 35 | ||
| 37 | KScopedLock(KScopedLock &&) = delete; | 36 | KScopedLock(KScopedLock&&) = delete; |
| 38 | KScopedLock& operator=(KScopedLock&&) = delete; | 37 | KScopedLock& operator=(KScopedLock&&) = delete; |
| 39 | 38 | ||
| 40 | private: | 39 | private: |
diff --git a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h index a86af56dd..f6c75f2d9 100644 --- a/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h +++ b/src/core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h | |||
| @@ -17,7 +17,7 @@ namespace Kernel { | |||
| 17 | 17 | ||
| 18 | class [[nodiscard]] KScopedSchedulerLockAndSleep { | 18 | class [[nodiscard]] KScopedSchedulerLockAndSleep { |
| 19 | public: | 19 | public: |
| 20 | explicit KScopedSchedulerLockAndSleep(KernelCore & kernel_, KThread * t, s64 timeout) | 20 | explicit KScopedSchedulerLockAndSleep(KernelCore& kernel_, KThread* t, s64 timeout) |
| 21 | : kernel(kernel_), thread(t), timeout_tick(timeout) { | 21 | : kernel(kernel_), thread(t), timeout_tick(timeout) { |
| 22 | // Lock the scheduler. | 22 | // Lock the scheduler. |
| 23 | kernel.GlobalSchedulerContext().scheduler_lock.Lock(); | 23 | kernel.GlobalSchedulerContext().scheduler_lock.Lock(); |
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 3a6db0b1c..901d43da9 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <functional> | ||
| 8 | #include <memory> | 9 | #include <memory> |
| 9 | #include <string> | 10 | #include <string> |
| 10 | #include <unordered_map> | 11 | #include <unordered_map> |
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 882fc1492..689b36056 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "core/hle/service/acc/acc_su.h" | 23 | #include "core/hle/service/acc/acc_su.h" |
| 24 | #include "core/hle/service/acc/acc_u0.h" | 24 | #include "core/hle/service/acc/acc_u0.h" |
| 25 | #include "core/hle/service/acc/acc_u1.h" | 25 | #include "core/hle/service/acc/acc_u1.h" |
| 26 | #include "core/hle/service/acc/async_context.h" | ||
| 26 | #include "core/hle/service/acc/errors.h" | 27 | #include "core/hle/service/acc/errors.h" |
| 27 | #include "core/hle/service/acc/profile_manager.h" | 28 | #include "core/hle/service/acc/profile_manager.h" |
| 28 | #include "core/hle/service/glue/arp.h" | 29 | #include "core/hle/service/glue/arp.h" |
| @@ -454,22 +455,6 @@ public: | |||
| 454 | : IProfileCommon{system_, "IProfileEditor", true, user_id_, profile_manager_} {} | 455 | : IProfileCommon{system_, "IProfileEditor", true, user_id_, profile_manager_} {} |
| 455 | }; | 456 | }; |
| 456 | 457 | ||
| 457 | class IAsyncContext final : public ServiceFramework<IAsyncContext> { | ||
| 458 | public: | ||
| 459 | explicit IAsyncContext(Core::System& system_) : ServiceFramework{system_, "IAsyncContext"} { | ||
| 460 | // clang-format off | ||
| 461 | static const FunctionInfo functions[] = { | ||
| 462 | {0, nullptr, "GetSystemEvent"}, | ||
| 463 | {1, nullptr, "Cancel"}, | ||
| 464 | {2, nullptr, "HasDone"}, | ||
| 465 | {3, nullptr, "GetResult"}, | ||
| 466 | }; | ||
| 467 | // clang-format on | ||
| 468 | |||
| 469 | RegisterHandlers(functions); | ||
| 470 | } | ||
| 471 | }; | ||
| 472 | |||
| 473 | class ISessionObject final : public ServiceFramework<ISessionObject> { | 458 | class ISessionObject final : public ServiceFramework<ISessionObject> { |
| 474 | public: | 459 | public: |
| 475 | explicit ISessionObject(Core::System& system_, Common::UUID) | 460 | explicit ISessionObject(Core::System& system_, Common::UUID) |
| @@ -504,16 +489,44 @@ public: | |||
| 504 | } | 489 | } |
| 505 | }; | 490 | }; |
| 506 | 491 | ||
| 492 | class EnsureTokenIdCacheAsyncInterface final : public IAsyncContext { | ||
| 493 | public: | ||
| 494 | explicit EnsureTokenIdCacheAsyncInterface(Core::System& system_) : IAsyncContext{system_} { | ||
| 495 | MarkComplete(); | ||
| 496 | } | ||
| 497 | ~EnsureTokenIdCacheAsyncInterface() = default; | ||
| 498 | |||
| 499 | void LoadIdTokenCache(Kernel::HLERequestContext& ctx) { | ||
| 500 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | ||
| 501 | |||
| 502 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 503 | rb.Push(ResultSuccess); | ||
| 504 | } | ||
| 505 | |||
| 506 | protected: | ||
| 507 | bool IsComplete() const override { | ||
| 508 | return true; | ||
| 509 | } | ||
| 510 | |||
| 511 | void Cancel() override {} | ||
| 512 | |||
| 513 | ResultCode GetResult() const override { | ||
| 514 | return ResultSuccess; | ||
| 515 | } | ||
| 516 | }; | ||
| 517 | |||
| 507 | class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { | 518 | class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { |
| 508 | public: | 519 | public: |
| 509 | explicit IManagerForApplication(Core::System& system_, Common::UUID user_id_) | 520 | explicit IManagerForApplication(Core::System& system_, Common::UUID user_id_) |
| 510 | : ServiceFramework{system_, "IManagerForApplication"}, user_id{user_id_} { | 521 | : ServiceFramework{system_, "IManagerForApplication"}, |
| 522 | ensure_token_id{std::make_shared<EnsureTokenIdCacheAsyncInterface>(system)}, | ||
| 523 | user_id{user_id_} { | ||
| 511 | // clang-format off | 524 | // clang-format off |
| 512 | static const FunctionInfo functions[] = { | 525 | static const FunctionInfo functions[] = { |
| 513 | {0, &IManagerForApplication::CheckAvailability, "CheckAvailability"}, | 526 | {0, &IManagerForApplication::CheckAvailability, "CheckAvailability"}, |
| 514 | {1, &IManagerForApplication::GetAccountId, "GetAccountId"}, | 527 | {1, &IManagerForApplication::GetAccountId, "GetAccountId"}, |
| 515 | {2, nullptr, "EnsureIdTokenCacheAsync"}, | 528 | {2, &IManagerForApplication::EnsureIdTokenCacheAsync, "EnsureIdTokenCacheAsync"}, |
| 516 | {3, nullptr, "LoadIdTokenCache"}, | 529 | {3, &IManagerForApplication::LoadIdTokenCache, "LoadIdTokenCache"}, |
| 517 | {130, &IManagerForApplication::GetNintendoAccountUserResourceCacheForApplication, "GetNintendoAccountUserResourceCacheForApplication"}, | 530 | {130, &IManagerForApplication::GetNintendoAccountUserResourceCacheForApplication, "GetNintendoAccountUserResourceCacheForApplication"}, |
| 518 | {150, nullptr, "CreateAuthorizationRequest"}, | 531 | {150, nullptr, "CreateAuthorizationRequest"}, |
| 519 | {160, &IManagerForApplication::StoreOpenContext, "StoreOpenContext"}, | 532 | {160, &IManagerForApplication::StoreOpenContext, "StoreOpenContext"}, |
| @@ -540,6 +553,20 @@ private: | |||
| 540 | rb.PushRaw<u64>(user_id.GetNintendoID()); | 553 | rb.PushRaw<u64>(user_id.GetNintendoID()); |
| 541 | } | 554 | } |
| 542 | 555 | ||
| 556 | void EnsureIdTokenCacheAsync(Kernel::HLERequestContext& ctx) { | ||
| 557 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | ||
| 558 | |||
| 559 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | ||
| 560 | rb.Push(ResultSuccess); | ||
| 561 | rb.PushIpcInterface(ensure_token_id); | ||
| 562 | } | ||
| 563 | |||
| 564 | void LoadIdTokenCache(Kernel::HLERequestContext& ctx) { | ||
| 565 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | ||
| 566 | |||
| 567 | ensure_token_id->LoadIdTokenCache(ctx); | ||
| 568 | } | ||
| 569 | |||
| 543 | void GetNintendoAccountUserResourceCacheForApplication(Kernel::HLERequestContext& ctx) { | 570 | void GetNintendoAccountUserResourceCacheForApplication(Kernel::HLERequestContext& ctx) { |
| 544 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 571 | LOG_WARNING(Service_ACC, "(STUBBED) called"); |
| 545 | 572 | ||
| @@ -562,6 +589,7 @@ private: | |||
| 562 | rb.Push(ResultSuccess); | 589 | rb.Push(ResultSuccess); |
| 563 | } | 590 | } |
| 564 | 591 | ||
| 592 | std::shared_ptr<EnsureTokenIdCacheAsyncInterface> ensure_token_id{}; | ||
| 565 | Common::UUID user_id{Common::INVALID_UUID}; | 593 | Common::UUID user_id{Common::INVALID_UUID}; |
| 566 | }; | 594 | }; |
| 567 | 595 | ||
| @@ -901,8 +929,7 @@ void Module::Interface::TrySelectUserWithoutInteraction(Kernel::HLERequestContex | |||
| 901 | } | 929 | } |
| 902 | 930 | ||
| 903 | const auto user_list = profile_manager->GetAllUsers(); | 931 | const auto user_list = profile_manager->GetAllUsers(); |
| 904 | if (std::all_of(user_list.begin(), user_list.end(), | 932 | if (std::ranges::all_of(user_list, [](const auto& user) { return user.IsInvalid(); })) { |
| 905 | [](const auto& user) { return user.uuid == Common::INVALID_UUID; })) { | ||
| 906 | rb.Push(ResultUnknown); // TODO(ogniK): Find the correct error code | 933 | rb.Push(ResultUnknown); // TODO(ogniK): Find the correct error code |
| 907 | rb.PushRaw<u128>(Common::INVALID_UUID); | 934 | rb.PushRaw<u128>(Common::INVALID_UUID); |
| 908 | return; | 935 | return; |
diff --git a/src/core/hle/service/acc/async_context.cpp b/src/core/hle/service/acc/async_context.cpp new file mode 100644 index 000000000..459323132 --- /dev/null +++ b/src/core/hle/service/acc/async_context.cpp | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | // Copyright 2021 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "core/core.h" | ||
| 6 | #include "core/hle/ipc_helpers.h" | ||
| 7 | #include "core/hle/service/acc/async_context.h" | ||
| 8 | |||
| 9 | namespace Service::Account { | ||
| 10 | IAsyncContext::IAsyncContext(Core::System& system_) | ||
| 11 | : ServiceFramework{system_, "IAsyncContext"}, compeletion_event{system_.Kernel()} { | ||
| 12 | |||
| 13 | Kernel::KAutoObject::Create(std::addressof(compeletion_event)); | ||
| 14 | compeletion_event.Initialize("IAsyncContext:CompletionEvent"); | ||
| 15 | |||
| 16 | // clang-format off | ||
| 17 | static const FunctionInfo functions[] = { | ||
| 18 | {0, &IAsyncContext::GetSystemEvent, "GetSystemEvent"}, | ||
| 19 | {1, &IAsyncContext::Cancel, "Cancel"}, | ||
| 20 | {2, &IAsyncContext::HasDone, "HasDone"}, | ||
| 21 | {3, &IAsyncContext::GetResult, "GetResult"}, | ||
| 22 | }; | ||
| 23 | // clang-format on | ||
| 24 | |||
| 25 | RegisterHandlers(functions); | ||
| 26 | } | ||
| 27 | |||
| 28 | void IAsyncContext::GetSystemEvent(Kernel::HLERequestContext& ctx) { | ||
| 29 | LOG_DEBUG(Service_ACC, "called"); | ||
| 30 | |||
| 31 | IPC::ResponseBuilder rb{ctx, 2, 1}; | ||
| 32 | rb.Push(ResultSuccess); | ||
| 33 | rb.PushCopyObjects(compeletion_event.GetReadableEvent()); | ||
| 34 | } | ||
| 35 | |||
| 36 | void IAsyncContext::Cancel(Kernel::HLERequestContext& ctx) { | ||
| 37 | LOG_DEBUG(Service_ACC, "called"); | ||
| 38 | |||
| 39 | Cancel(); | ||
| 40 | MarkComplete(); | ||
| 41 | |||
| 42 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 43 | rb.Push(ResultSuccess); | ||
| 44 | } | ||
| 45 | |||
| 46 | void IAsyncContext::HasDone(Kernel::HLERequestContext& ctx) { | ||
| 47 | LOG_DEBUG(Service_ACC, "called"); | ||
| 48 | |||
| 49 | is_complete.store(IsComplete()); | ||
| 50 | |||
| 51 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 52 | rb.Push(ResultSuccess); | ||
| 53 | rb.Push(is_complete.load()); | ||
| 54 | } | ||
| 55 | |||
| 56 | void IAsyncContext::GetResult(Kernel::HLERequestContext& ctx) { | ||
| 57 | LOG_DEBUG(Service_ACC, "called"); | ||
| 58 | |||
| 59 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 60 | rb.Push(GetResult()); | ||
| 61 | } | ||
| 62 | |||
| 63 | void IAsyncContext::MarkComplete() { | ||
| 64 | is_complete.store(true); | ||
| 65 | compeletion_event.GetWritableEvent().Signal(); | ||
| 66 | } | ||
| 67 | |||
| 68 | } // namespace Service::Account | ||
diff --git a/src/core/hle/service/acc/async_context.h b/src/core/hle/service/acc/async_context.h new file mode 100644 index 000000000..c694b4946 --- /dev/null +++ b/src/core/hle/service/acc/async_context.h | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | // Copyright 2021 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <atomic> | ||
| 8 | #include "core/hle/kernel/k_event.h" | ||
| 9 | #include "core/hle/service/service.h" | ||
| 10 | |||
| 11 | namespace Core { | ||
| 12 | class System; | ||
| 13 | } | ||
| 14 | |||
| 15 | namespace Service::Account { | ||
| 16 | |||
| 17 | class IAsyncContext : public ServiceFramework<IAsyncContext> { | ||
| 18 | public: | ||
| 19 | explicit IAsyncContext(Core::System& system_); | ||
| 20 | |||
| 21 | void GetSystemEvent(Kernel::HLERequestContext& ctx); | ||
| 22 | void Cancel(Kernel::HLERequestContext& ctx); | ||
| 23 | void HasDone(Kernel::HLERequestContext& ctx); | ||
| 24 | void GetResult(Kernel::HLERequestContext& ctx); | ||
| 25 | |||
| 26 | protected: | ||
| 27 | virtual bool IsComplete() const = 0; | ||
| 28 | virtual void Cancel() = 0; | ||
| 29 | virtual ResultCode GetResult() const = 0; | ||
| 30 | |||
| 31 | void MarkComplete(); | ||
| 32 | |||
| 33 | std::atomic<bool> is_complete{false}; | ||
| 34 | Kernel::KEvent compeletion_event; | ||
| 35 | }; | ||
| 36 | |||
| 37 | } // namespace Service::Account | ||
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 24a1c9157..568303ced 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -208,9 +208,10 @@ bool ProfileManager::UserExists(UUID uuid) const { | |||
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | bool ProfileManager::UserExistsIndex(std::size_t index) const { | 210 | bool ProfileManager::UserExistsIndex(std::size_t index) const { |
| 211 | if (index >= MAX_USERS) | 211 | if (index >= MAX_USERS) { |
| 212 | return false; | 212 | return false; |
| 213 | return profiles[index].user_uuid.uuid != Common::INVALID_UUID; | 213 | } |
| 214 | return profiles[index].user_uuid.IsValid(); | ||
| 214 | } | 215 | } |
| 215 | 216 | ||
| 216 | /// Opens a specific user | 217 | /// Opens a specific user |
| @@ -304,7 +305,7 @@ bool ProfileManager::RemoveUser(UUID uuid) { | |||
| 304 | 305 | ||
| 305 | bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) { | 306 | bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) { |
| 306 | const auto index = GetUserIndex(uuid); | 307 | const auto index = GetUserIndex(uuid); |
| 307 | if (!index || profile_new.user_uuid == UUID(Common::INVALID_UUID)) { | 308 | if (!index || profile_new.user_uuid.IsInvalid()) { |
| 308 | return false; | 309 | return false; |
| 309 | } | 310 | } |
| 310 | 311 | ||
| @@ -346,7 +347,7 @@ void ProfileManager::ParseUserSaveFile() { | |||
| 346 | } | 347 | } |
| 347 | 348 | ||
| 348 | for (const auto& user : data.users) { | 349 | for (const auto& user : data.users) { |
| 349 | if (user.uuid == UUID(Common::INVALID_UUID)) { | 350 | if (user.uuid.IsInvalid()) { |
| 350 | continue; | 351 | continue; |
| 351 | } | 352 | } |
| 352 | 353 | ||
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index a538f82e3..49e9787a4 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -275,12 +275,14 @@ ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nv | |||
| 275 | {18, nullptr, "SetRequiresCaptureButtonShortPressedMessage"}, | 275 | {18, nullptr, "SetRequiresCaptureButtonShortPressedMessage"}, |
| 276 | {19, &ISelfController::SetAlbumImageOrientation, "SetAlbumImageOrientation"}, | 276 | {19, &ISelfController::SetAlbumImageOrientation, "SetAlbumImageOrientation"}, |
| 277 | {20, nullptr, "SetDesirableKeyboardLayout"}, | 277 | {20, nullptr, "SetDesirableKeyboardLayout"}, |
| 278 | {21, nullptr, "GetScreenShotProgramId"}, | ||
| 278 | {40, &ISelfController::CreateManagedDisplayLayer, "CreateManagedDisplayLayer"}, | 279 | {40, &ISelfController::CreateManagedDisplayLayer, "CreateManagedDisplayLayer"}, |
| 279 | {41, nullptr, "IsSystemBufferSharingEnabled"}, | 280 | {41, nullptr, "IsSystemBufferSharingEnabled"}, |
| 280 | {42, nullptr, "GetSystemSharedLayerHandle"}, | 281 | {42, nullptr, "GetSystemSharedLayerHandle"}, |
| 281 | {43, nullptr, "GetSystemSharedBufferHandle"}, | 282 | {43, nullptr, "GetSystemSharedBufferHandle"}, |
| 282 | {44, &ISelfController::CreateManagedDisplaySeparableLayer, "CreateManagedDisplaySeparableLayer"}, | 283 | {44, &ISelfController::CreateManagedDisplaySeparableLayer, "CreateManagedDisplaySeparableLayer"}, |
| 283 | {45, nullptr, "SetManagedDisplayLayerSeparationMode"}, | 284 | {45, nullptr, "SetManagedDisplayLayerSeparationMode"}, |
| 285 | {46, nullptr, "SetRecordingLayerCompositionEnabled"}, | ||
| 284 | {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"}, | 286 | {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"}, |
| 285 | {51, nullptr, "ApproveToDisplay"}, | 287 | {51, nullptr, "ApproveToDisplay"}, |
| 286 | {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"}, | 288 | {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"}, |
| @@ -302,6 +304,7 @@ ISelfController::ISelfController(Core::System& system_, NVFlinger::NVFlinger& nv | |||
| 302 | {100, &ISelfController::SetAlbumImageTakenNotificationEnabled, "SetAlbumImageTakenNotificationEnabled"}, | 304 | {100, &ISelfController::SetAlbumImageTakenNotificationEnabled, "SetAlbumImageTakenNotificationEnabled"}, |
| 303 | {110, nullptr, "SetApplicationAlbumUserData"}, | 305 | {110, nullptr, "SetApplicationAlbumUserData"}, |
| 304 | {120, nullptr, "SaveCurrentScreenshot"}, | 306 | {120, nullptr, "SaveCurrentScreenshot"}, |
| 307 | {130, nullptr, "SetRecordVolumeMuted"}, | ||
| 305 | {1000, nullptr, "GetDebugStorageChannel"}, | 308 | {1000, nullptr, "GetDebugStorageChannel"}, |
| 306 | }; | 309 | }; |
| 307 | // clang-format on | 310 | // clang-format on |
| @@ -329,10 +332,10 @@ ISelfController::~ISelfController() = default; | |||
| 329 | void ISelfController::Exit(Kernel::HLERequestContext& ctx) { | 332 | void ISelfController::Exit(Kernel::HLERequestContext& ctx) { |
| 330 | LOG_DEBUG(Service_AM, "called"); | 333 | LOG_DEBUG(Service_AM, "called"); |
| 331 | 334 | ||
| 332 | system.Shutdown(); | ||
| 333 | |||
| 334 | IPC::ResponseBuilder rb{ctx, 2}; | 335 | IPC::ResponseBuilder rb{ctx, 2}; |
| 335 | rb.Push(ResultSuccess); | 336 | rb.Push(ResultSuccess); |
| 337 | |||
| 338 | system.Exit(); | ||
| 336 | } | 339 | } |
| 337 | 340 | ||
| 338 | void ISelfController::LockExit(Kernel::HLERequestContext& ctx) { | 341 | void ISelfController::LockExit(Kernel::HLERequestContext& ctx) { |
| @@ -683,6 +686,7 @@ ICommonStateGetter::ICommonStateGetter(Core::System& system_, | |||
| 683 | {91, nullptr, "GetCurrentPerformanceConfiguration"}, | 686 | {91, nullptr, "GetCurrentPerformanceConfiguration"}, |
| 684 | {100, nullptr, "SetHandlingHomeButtonShortPressedEnabled"}, | 687 | {100, nullptr, "SetHandlingHomeButtonShortPressedEnabled"}, |
| 685 | {110, nullptr, "OpenMyGpuErrorHandler"}, | 688 | {110, nullptr, "OpenMyGpuErrorHandler"}, |
| 689 | {120, nullptr, "GetAppletLaunchedHistory"}, | ||
| 686 | {200, nullptr, "GetOperationModeSystemInfo"}, | 690 | {200, nullptr, "GetOperationModeSystemInfo"}, |
| 687 | {300, nullptr, "GetSettingsPlatformRegion"}, | 691 | {300, nullptr, "GetSettingsPlatformRegion"}, |
| 688 | {400, nullptr, "ActivateMigrationService"}, | 692 | {400, nullptr, "ActivateMigrationService"}, |
| @@ -1270,7 +1274,8 @@ void ILibraryAppletCreator::CreateHandleStorage(Kernel::HLERequestContext& ctx) | |||
| 1270 | IApplicationFunctions::IApplicationFunctions(Core::System& system_) | 1274 | IApplicationFunctions::IApplicationFunctions(Core::System& system_) |
| 1271 | : ServiceFramework{system_, "IApplicationFunctions"}, gpu_error_detected_event{system.Kernel()}, | 1275 | : ServiceFramework{system_, "IApplicationFunctions"}, gpu_error_detected_event{system.Kernel()}, |
| 1272 | friend_invitation_storage_channel_event{system.Kernel()}, | 1276 | friend_invitation_storage_channel_event{system.Kernel()}, |
| 1273 | health_warning_disappeared_system_event{system.Kernel()} { | 1277 | notification_storage_channel_event{system.Kernel()}, health_warning_disappeared_system_event{ |
| 1278 | system.Kernel()} { | ||
| 1274 | // clang-format off | 1279 | // clang-format off |
| 1275 | static const FunctionInfo functions[] = { | 1280 | static const FunctionInfo functions[] = { |
| 1276 | {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"}, | 1281 | {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"}, |
| @@ -1322,7 +1327,7 @@ IApplicationFunctions::IApplicationFunctions(Core::System& system_) | |||
| 1322 | {131, nullptr, "SetDelayTimeToAbortOnGpuError"}, | 1327 | {131, nullptr, "SetDelayTimeToAbortOnGpuError"}, |
| 1323 | {140, &IApplicationFunctions::GetFriendInvitationStorageChannelEvent, "GetFriendInvitationStorageChannelEvent"}, | 1328 | {140, &IApplicationFunctions::GetFriendInvitationStorageChannelEvent, "GetFriendInvitationStorageChannelEvent"}, |
| 1324 | {141, &IApplicationFunctions::TryPopFromFriendInvitationStorageChannel, "TryPopFromFriendInvitationStorageChannel"}, | 1329 | {141, &IApplicationFunctions::TryPopFromFriendInvitationStorageChannel, "TryPopFromFriendInvitationStorageChannel"}, |
| 1325 | {150, nullptr, "GetNotificationStorageChannelEvent"}, | 1330 | {150, &IApplicationFunctions::GetNotificationStorageChannelEvent, "GetNotificationStorageChannelEvent"}, |
| 1326 | {151, nullptr, "TryPopFromNotificationStorageChannel"}, | 1331 | {151, nullptr, "TryPopFromNotificationStorageChannel"}, |
| 1327 | {160, &IApplicationFunctions::GetHealthWarningDisappearedSystemEvent, "GetHealthWarningDisappearedSystemEvent"}, | 1332 | {160, &IApplicationFunctions::GetHealthWarningDisappearedSystemEvent, "GetHealthWarningDisappearedSystemEvent"}, |
| 1328 | {170, nullptr, "SetHdcpAuthenticationActivated"}, | 1333 | {170, nullptr, "SetHdcpAuthenticationActivated"}, |
| @@ -1340,11 +1345,14 @@ IApplicationFunctions::IApplicationFunctions(Core::System& system_) | |||
| 1340 | 1345 | ||
| 1341 | Kernel::KAutoObject::Create(std::addressof(gpu_error_detected_event)); | 1346 | Kernel::KAutoObject::Create(std::addressof(gpu_error_detected_event)); |
| 1342 | Kernel::KAutoObject::Create(std::addressof(friend_invitation_storage_channel_event)); | 1347 | Kernel::KAutoObject::Create(std::addressof(friend_invitation_storage_channel_event)); |
| 1348 | Kernel::KAutoObject::Create(std::addressof(notification_storage_channel_event)); | ||
| 1343 | Kernel::KAutoObject::Create(std::addressof(health_warning_disappeared_system_event)); | 1349 | Kernel::KAutoObject::Create(std::addressof(health_warning_disappeared_system_event)); |
| 1344 | 1350 | ||
| 1345 | gpu_error_detected_event.Initialize("IApplicationFunctions:GpuErrorDetectedSystemEvent"); | 1351 | gpu_error_detected_event.Initialize("IApplicationFunctions:GpuErrorDetectedSystemEvent"); |
| 1346 | friend_invitation_storage_channel_event.Initialize( | 1352 | friend_invitation_storage_channel_event.Initialize( |
| 1347 | "IApplicationFunctions:FriendInvitationStorageChannelEvent"); | 1353 | "IApplicationFunctions:FriendInvitationStorageChannelEvent"); |
| 1354 | notification_storage_channel_event.Initialize( | ||
| 1355 | "IApplicationFunctions:NotificationStorageChannelEvent"); | ||
| 1348 | health_warning_disappeared_system_event.Initialize( | 1356 | health_warning_disappeared_system_event.Initialize( |
| 1349 | "IApplicationFunctions:HealthWarningDisappearedSystemEvent"); | 1357 | "IApplicationFunctions:HealthWarningDisappearedSystemEvent"); |
| 1350 | } | 1358 | } |
| @@ -1762,6 +1770,14 @@ void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel( | |||
| 1762 | rb.Push(ERR_NO_DATA_IN_CHANNEL); | 1770 | rb.Push(ERR_NO_DATA_IN_CHANNEL); |
| 1763 | } | 1771 | } |
| 1764 | 1772 | ||
| 1773 | void IApplicationFunctions::GetNotificationStorageChannelEvent(Kernel::HLERequestContext& ctx) { | ||
| 1774 | LOG_DEBUG(Service_AM, "called"); | ||
| 1775 | |||
| 1776 | IPC::ResponseBuilder rb{ctx, 2, 1}; | ||
| 1777 | rb.Push(ResultSuccess); | ||
| 1778 | rb.PushCopyObjects(notification_storage_channel_event.GetReadableEvent()); | ||
| 1779 | } | ||
| 1780 | |||
| 1765 | void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx) { | 1781 | void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx) { |
| 1766 | LOG_DEBUG(Service_AM, "called"); | 1782 | LOG_DEBUG(Service_AM, "called"); |
| 1767 | 1783 | ||
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 184030a8e..c13aa5787 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h | |||
| @@ -295,6 +295,7 @@ private: | |||
| 295 | void GetGpuErrorDetectedSystemEvent(Kernel::HLERequestContext& ctx); | 295 | void GetGpuErrorDetectedSystemEvent(Kernel::HLERequestContext& ctx); |
| 296 | void GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx); | 296 | void GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx); |
| 297 | void TryPopFromFriendInvitationStorageChannel(Kernel::HLERequestContext& ctx); | 297 | void TryPopFromFriendInvitationStorageChannel(Kernel::HLERequestContext& ctx); |
| 298 | void GetNotificationStorageChannelEvent(Kernel::HLERequestContext& ctx); | ||
| 298 | void GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx); | 299 | void GetHealthWarningDisappearedSystemEvent(Kernel::HLERequestContext& ctx); |
| 299 | 300 | ||
| 300 | bool launch_popped_application_specific = false; | 301 | bool launch_popped_application_specific = false; |
| @@ -302,6 +303,7 @@ private: | |||
| 302 | s32 previous_program_index{-1}; | 303 | s32 previous_program_index{-1}; |
| 303 | Kernel::KEvent gpu_error_detected_event; | 304 | Kernel::KEvent gpu_error_detected_event; |
| 304 | Kernel::KEvent friend_invitation_storage_channel_event; | 305 | Kernel::KEvent friend_invitation_storage_channel_event; |
| 306 | Kernel::KEvent notification_storage_channel_event; | ||
| 305 | Kernel::KEvent health_warning_disappeared_system_event; | 307 | Kernel::KEvent health_warning_disappeared_system_event; |
| 306 | }; | 308 | }; |
| 307 | 309 | ||
diff --git a/src/core/hle/service/am/applets/applet_profile_select.cpp b/src/core/hle/service/am/applets/applet_profile_select.cpp index bdc21778e..a6e891944 100644 --- a/src/core/hle/service/am/applets/applet_profile_select.cpp +++ b/src/core/hle/service/am/applets/applet_profile_select.cpp | |||
| @@ -60,7 +60,7 @@ void ProfileSelect::Execute() { | |||
| 60 | void ProfileSelect::SelectionComplete(std::optional<Common::UUID> uuid) { | 60 | void ProfileSelect::SelectionComplete(std::optional<Common::UUID> uuid) { |
| 61 | UserSelectionOutput output{}; | 61 | UserSelectionOutput output{}; |
| 62 | 62 | ||
| 63 | if (uuid.has_value() && uuid->uuid != Common::INVALID_UUID) { | 63 | if (uuid.has_value() && uuid->IsValid()) { |
| 64 | output.result = 0; | 64 | output.result = 0; |
| 65 | output.uuid_selected = uuid->uuid; | 65 | output.uuid_selected = uuid->uuid; |
| 66 | } else { | 66 | } else { |
diff --git a/src/core/hle/service/audio/audctl.cpp b/src/core/hle/service/audio/audctl.cpp index 8c4c49b85..2e46e7161 100644 --- a/src/core/hle/service/audio/audctl.cpp +++ b/src/core/hle/service/audio/audctl.cpp | |||
| @@ -41,6 +41,14 @@ AudCtl::AudCtl(Core::System& system_) : ServiceFramework{system_, "audctl"} { | |||
| 41 | {27, nullptr, "SetVolumeMappingTableForDev"}, | 41 | {27, nullptr, "SetVolumeMappingTableForDev"}, |
| 42 | {28, nullptr, "GetAudioOutputChannelCountForPlayReport"}, | 42 | {28, nullptr, "GetAudioOutputChannelCountForPlayReport"}, |
| 43 | {29, nullptr, "BindAudioOutputChannelCountUpdateEventForPlayReport"}, | 43 | {29, nullptr, "BindAudioOutputChannelCountUpdateEventForPlayReport"}, |
| 44 | {30, nullptr, "Unknown30"}, | ||
| 45 | {31, nullptr, "Unknown31"}, | ||
| 46 | {32, nullptr, "Unknown32"}, | ||
| 47 | {33, nullptr, "Unknown33"}, | ||
| 48 | {34, nullptr, "Unknown34"}, | ||
| 49 | {10000, nullptr, "Unknown10000"}, | ||
| 50 | {10001, nullptr, "Unknown10001"}, | ||
| 51 | {10002, nullptr, "Unknown10002"}, | ||
| 44 | }; | 52 | }; |
| 45 | // clang-format on | 53 | // clang-format on |
| 46 | 54 | ||
diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp index 3e7fd6024..570525019 100644 --- a/src/core/hle/service/audio/audin_u.cpp +++ b/src/core/hle/service/audio/audin_u.cpp | |||
| @@ -3,38 +3,65 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/logging/log.h" | 5 | #include "common/logging/log.h" |
| 6 | #include "core/core.h" | ||
| 6 | #include "core/hle/ipc_helpers.h" | 7 | #include "core/hle/ipc_helpers.h" |
| 7 | #include "core/hle/kernel/hle_ipc.h" | 8 | #include "core/hle/kernel/hle_ipc.h" |
| 9 | #include "core/hle/kernel/k_event.h" | ||
| 8 | #include "core/hle/service/audio/audin_u.h" | 10 | #include "core/hle/service/audio/audin_u.h" |
| 9 | 11 | ||
| 10 | namespace Service::Audio { | 12 | namespace Service::Audio { |
| 11 | 13 | ||
| 12 | class IAudioIn final : public ServiceFramework<IAudioIn> { | 14 | IAudioIn::IAudioIn(Core::System& system_) |
| 13 | public: | 15 | : ServiceFramework{system_, "IAudioIn"}, buffer_event{system_.Kernel()} { |
| 14 | explicit IAudioIn(Core::System& system_) : ServiceFramework{system_, "IAudioIn"} { | 16 | // clang-format off |
| 15 | // clang-format off | 17 | static const FunctionInfo functions[] = { |
| 16 | static const FunctionInfo functions[] = { | 18 | {0, nullptr, "GetAudioInState"}, |
| 17 | {0, nullptr, "GetAudioInState"}, | 19 | {1, &IAudioIn::Start, "Start"}, |
| 18 | {1, nullptr, "Start"}, | 20 | {2, nullptr, "Stop"}, |
| 19 | {2, nullptr, "Stop"}, | 21 | {3, nullptr, "AppendAudioInBuffer"}, |
| 20 | {3, nullptr, "AppendAudioInBuffer"}, | 22 | {4, &IAudioIn::RegisterBufferEvent, "RegisterBufferEvent"}, |
| 21 | {4, nullptr, "RegisterBufferEvent"}, | 23 | {5, nullptr, "GetReleasedAudioInBuffer"}, |
| 22 | {5, nullptr, "GetReleasedAudioInBuffer"}, | 24 | {6, nullptr, "ContainsAudioInBuffer"}, |
| 23 | {6, nullptr, "ContainsAudioInBuffer"}, | 25 | {7, nullptr, "AppendUacInBuffer"}, |
| 24 | {7, nullptr, "AppendUacInBuffer"}, | 26 | {8, &IAudioIn::AppendAudioInBufferAuto, "AppendAudioInBufferAuto"}, |
| 25 | {8, nullptr, "AppendAudioInBufferAuto"}, | 27 | {9, nullptr, "GetReleasedAudioInBuffersAuto"}, |
| 26 | {9, nullptr, "GetReleasedAudioInBuffersAuto"}, | 28 | {10, nullptr, "AppendUacInBufferAuto"}, |
| 27 | {10, nullptr, "AppendUacInBufferAuto"}, | 29 | {11, nullptr, "GetAudioInBufferCount"}, |
| 28 | {11, nullptr, "GetAudioInBufferCount"}, | 30 | {12, nullptr, "SetDeviceGain"}, |
| 29 | {12, nullptr, "SetDeviceGain"}, | 31 | {13, nullptr, "GetDeviceGain"}, |
| 30 | {13, nullptr, "GetDeviceGain"}, | 32 | {14, nullptr, "FlushAudioInBuffers"}, |
| 31 | {14, nullptr, "FlushAudioInBuffers"}, | 33 | }; |
| 32 | }; | 34 | // clang-format on |
| 33 | // clang-format on | 35 | |
| 34 | 36 | RegisterHandlers(functions); | |
| 35 | RegisterHandlers(functions); | 37 | |
| 36 | } | 38 | Kernel::KAutoObject::Create(std::addressof(buffer_event)); |
| 37 | }; | 39 | buffer_event.Initialize("IAudioIn:BufferEvent"); |
| 40 | } | ||
| 41 | |||
| 42 | IAudioIn::~IAudioIn() = default; | ||
| 43 | |||
| 44 | void IAudioIn::Start(Kernel::HLERequestContext& ctx) { | ||
| 45 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | ||
| 46 | |||
| 47 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 48 | rb.Push(ResultSuccess); | ||
| 49 | } | ||
| 50 | |||
| 51 | void IAudioIn::RegisterBufferEvent(Kernel::HLERequestContext& ctx) { | ||
| 52 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | ||
| 53 | |||
| 54 | IPC::ResponseBuilder rb{ctx, 2, 1}; | ||
| 55 | rb.Push(ResultSuccess); | ||
| 56 | rb.PushCopyObjects(buffer_event.GetReadableEvent()); | ||
| 57 | } | ||
| 58 | |||
| 59 | void IAudioIn::AppendAudioInBufferAuto(Kernel::HLERequestContext& ctx) { | ||
| 60 | LOG_WARNING(Service_Audio, "(STUBBED) called"); | ||
| 61 | |||
| 62 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 63 | rb.Push(ResultSuccess); | ||
| 64 | } | ||
| 38 | 65 | ||
| 39 | AudInU::AudInU(Core::System& system_) : ServiceFramework{system_, "audin:u"} { | 66 | AudInU::AudInU(Core::System& system_) : ServiceFramework{system_, "audin:u"} { |
| 40 | // clang-format off | 67 | // clang-format off |
diff --git a/src/core/hle/service/audio/audin_u.h b/src/core/hle/service/audio/audin_u.h index 0d75ae5ac..f2f7f9932 100644 --- a/src/core/hle/service/audio/audin_u.h +++ b/src/core/hle/service/audio/audin_u.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "core/hle/kernel/k_event.h" | ||
| 7 | #include "core/hle/service/service.h" | 8 | #include "core/hle/service/service.h" |
| 8 | 9 | ||
| 9 | namespace Core { | 10 | namespace Core { |
| @@ -16,6 +17,19 @@ class HLERequestContext; | |||
| 16 | 17 | ||
| 17 | namespace Service::Audio { | 18 | namespace Service::Audio { |
| 18 | 19 | ||
| 20 | class IAudioIn final : public ServiceFramework<IAudioIn> { | ||
| 21 | public: | ||
| 22 | explicit IAudioIn(Core::System& system_); | ||
| 23 | ~IAudioIn() override; | ||
| 24 | |||
| 25 | private: | ||
| 26 | void Start(Kernel::HLERequestContext& ctx); | ||
| 27 | void RegisterBufferEvent(Kernel::HLERequestContext& ctx); | ||
| 28 | void AppendAudioInBufferAuto(Kernel::HLERequestContext& ctx); | ||
| 29 | |||
| 30 | Kernel::KEvent buffer_event; | ||
| 31 | }; | ||
| 32 | |||
| 19 | class AudInU final : public ServiceFramework<AudInU> { | 33 | class AudInU final : public ServiceFramework<AudInU> { |
| 20 | public: | 34 | public: |
| 21 | explicit AudInU(Core::System& system_); | 35 | explicit AudInU(Core::System& system_); |
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index b769fe959..1a91719f5 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp | |||
| @@ -187,7 +187,8 @@ public: | |||
| 187 | {10, &IAudioDevice::GetActiveAudioDeviceName, "GetActiveAudioDeviceNameAuto"}, | 187 | {10, &IAudioDevice::GetActiveAudioDeviceName, "GetActiveAudioDeviceNameAuto"}, |
| 188 | {11, &IAudioDevice::QueryAudioDeviceInputEvent, "QueryAudioDeviceInputEvent"}, | 188 | {11, &IAudioDevice::QueryAudioDeviceInputEvent, "QueryAudioDeviceInputEvent"}, |
| 189 | {12, &IAudioDevice::QueryAudioDeviceOutputEvent, "QueryAudioDeviceOutputEvent"}, | 189 | {12, &IAudioDevice::QueryAudioDeviceOutputEvent, "QueryAudioDeviceOutputEvent"}, |
| 190 | {13, nullptr, "GetAudioSystemMasterVolumeSetting"}, | 190 | {13, nullptr, "GetActiveAudioOutputDeviceName"}, |
| 191 | {14, nullptr, "ListAudioOutputDeviceName"}, | ||
| 191 | }; | 192 | }; |
| 192 | RegisterHandlers(functions); | 193 | RegisterHandlers(functions); |
| 193 | } | 194 | } |
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp deleted file mode 100644 index 7ca7f2aac..000000000 --- a/src/core/hle/service/bcat/backend/boxcat.cpp +++ /dev/null | |||
| @@ -1,548 +0,0 @@ | |||
| 1 | // Copyright 2019 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <fmt/ostream.h> | ||
| 6 | |||
| 7 | #ifdef __GNUC__ | ||
| 8 | #pragma GCC diagnostic push | ||
| 9 | #pragma GCC diagnostic ignored "-Wshadow" | ||
| 10 | #ifndef __clang__ | ||
| 11 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" | ||
| 12 | #endif | ||
| 13 | #endif | ||
| 14 | #include <httplib.h> | ||
| 15 | #include <mbedtls/sha256.h> | ||
| 16 | #include <nlohmann/json.hpp> | ||
| 17 | #ifdef __GNUC__ | ||
| 18 | #pragma GCC diagnostic pop | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #include "common/fs/file.h" | ||
| 22 | #include "common/fs/fs.h" | ||
| 23 | #include "common/fs/path_util.h" | ||
| 24 | #include "common/hex_util.h" | ||
| 25 | #include "common/logging/log.h" | ||
| 26 | #include "common/settings.h" | ||
| 27 | #include "core/core.h" | ||
| 28 | #include "core/file_sys/vfs.h" | ||
| 29 | #include "core/file_sys/vfs_libzip.h" | ||
| 30 | #include "core/file_sys/vfs_vector.h" | ||
| 31 | #include "core/frontend/applets/error.h" | ||
| 32 | #include "core/hle/service/am/applets/applets.h" | ||
| 33 | #include "core/hle/service/bcat/backend/boxcat.h" | ||
| 34 | |||
| 35 | namespace Service::BCAT { | ||
| 36 | namespace { | ||
| 37 | |||
| 38 | // Prevents conflicts with windows macro called CreateFile | ||
| 39 | FileSys::VirtualFile VfsCreateFileWrap(FileSys::VirtualDir dir, std::string_view name) { | ||
| 40 | return dir->CreateFile(name); | ||
| 41 | } | ||
| 42 | |||
| 43 | // Prevents conflicts with windows macro called DeleteFile | ||
| 44 | bool VfsDeleteFileWrap(FileSys::VirtualDir dir, std::string_view name) { | ||
| 45 | return dir->DeleteFile(name); | ||
| 46 | } | ||
| 47 | |||
| 48 | constexpr ResultCode ERROR_GENERAL_BCAT_FAILURE{ErrorModule::BCAT, 1}; | ||
| 49 | |||
| 50 | constexpr char BOXCAT_HOSTNAME[] = "api.yuzu-emu.org"; | ||
| 51 | |||
| 52 | // Formatted using fmt with arg[0] = hex title id | ||
| 53 | constexpr char BOXCAT_PATHNAME_DATA[] = "/game-assets/{:016X}/boxcat"; | ||
| 54 | constexpr char BOXCAT_PATHNAME_LAUNCHPARAM[] = "/game-assets/{:016X}/launchparam"; | ||
| 55 | |||
| 56 | constexpr char BOXCAT_PATHNAME_EVENTS[] = "/game-assets/boxcat/events"; | ||
| 57 | |||
| 58 | constexpr char BOXCAT_API_VERSION[] = "1"; | ||
| 59 | constexpr char BOXCAT_CLIENT_TYPE[] = "yuzu"; | ||
| 60 | |||
| 61 | // HTTP status codes for Boxcat | ||
| 62 | enum class ResponseStatus { | ||
| 63 | Ok = 200, ///< Operation completed successfully. | ||
| 64 | BadClientVersion = 301, ///< The Boxcat-Client-Version doesn't match the server. | ||
| 65 | NoUpdate = 304, ///< The digest provided would match the new data, no need to update. | ||
| 66 | NoMatchTitleId = 404, ///< The title ID provided doesn't have a boxcat implementation. | ||
| 67 | NoMatchBuildId = 406, ///< The build ID provided is blacklisted (potentially because of format | ||
| 68 | ///< issues or whatnot) and has no data. | ||
| 69 | }; | ||
| 70 | |||
| 71 | enum class DownloadResult { | ||
| 72 | Success = 0, | ||
| 73 | NoResponse, | ||
| 74 | GeneralWebError, | ||
| 75 | NoMatchTitleId, | ||
| 76 | NoMatchBuildId, | ||
| 77 | InvalidContentType, | ||
| 78 | GeneralFSError, | ||
| 79 | BadClientVersion, | ||
| 80 | }; | ||
| 81 | |||
| 82 | constexpr std::array<const char*, 8> DOWNLOAD_RESULT_LOG_MESSAGES{ | ||
| 83 | "Success", | ||
| 84 | "There was no response from the server.", | ||
| 85 | "There was a general web error code returned from the server.", | ||
| 86 | "The title ID of the current game doesn't have a boxcat implementation. If you believe an " | ||
| 87 | "implementation should be added, contact yuzu support.", | ||
| 88 | "The build ID of the current version of the game is marked as incompatible with the current " | ||
| 89 | "BCAT distribution. Try upgrading or downgrading your game version or contacting yuzu support.", | ||
| 90 | "The content type of the web response was invalid.", | ||
| 91 | "There was a general filesystem error while saving the zip file.", | ||
| 92 | "The server is either too new or too old to serve the request. Try using the latest version of " | ||
| 93 | "an official release of yuzu.", | ||
| 94 | }; | ||
| 95 | |||
| 96 | std::ostream& operator<<(std::ostream& os, DownloadResult result) { | ||
| 97 | return os << DOWNLOAD_RESULT_LOG_MESSAGES.at(static_cast<std::size_t>(result)); | ||
| 98 | } | ||
| 99 | |||
| 100 | constexpr u32 PORT = 443; | ||
| 101 | constexpr u32 TIMEOUT_SECONDS = 30; | ||
| 102 | [[maybe_unused]] constexpr u64 VFS_COPY_BLOCK_SIZE = 1ULL << 24; // 4MB | ||
| 103 | |||
| 104 | std::filesystem::path GetBINFilePath(u64 title_id) { | ||
| 105 | return Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "bcat" / | ||
| 106 | fmt::format("{:016X}/launchparam.bin", title_id); | ||
| 107 | } | ||
| 108 | |||
| 109 | std::filesystem::path GetZIPFilePath(u64 title_id) { | ||
| 110 | return Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "bcat" / | ||
| 111 | fmt::format("{:016X}/data.zip", title_id); | ||
| 112 | } | ||
| 113 | |||
| 114 | // If the error is something the user should know about (build ID mismatch, bad client version), | ||
| 115 | // display an error. | ||
| 116 | void HandleDownloadDisplayResult(const AM::Applets::AppletManager& applet_manager, | ||
| 117 | DownloadResult res) { | ||
| 118 | if (res == DownloadResult::Success || res == DownloadResult::NoResponse || | ||
| 119 | res == DownloadResult::GeneralWebError || res == DownloadResult::GeneralFSError || | ||
| 120 | res == DownloadResult::NoMatchTitleId || res == DownloadResult::InvalidContentType) { | ||
| 121 | return; | ||
| 122 | } | ||
| 123 | |||
| 124 | const auto& frontend{applet_manager.GetAppletFrontendSet()}; | ||
| 125 | frontend.error->ShowCustomErrorText( | ||
| 126 | ResultUnknown, "There was an error while attempting to use Boxcat.", | ||
| 127 | DOWNLOAD_RESULT_LOG_MESSAGES[static_cast<std::size_t>(res)], [] {}); | ||
| 128 | } | ||
| 129 | |||
| 130 | bool VfsRawCopyProgress(FileSys::VirtualFile src, FileSys::VirtualFile dest, | ||
| 131 | std::string_view dir_name, ProgressServiceBackend& progress, | ||
| 132 | std::size_t block_size = 0x1000) { | ||
| 133 | if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable()) | ||
| 134 | return false; | ||
| 135 | if (!dest->Resize(src->GetSize())) | ||
| 136 | return false; | ||
| 137 | |||
| 138 | progress.StartDownloadingFile(dir_name, src->GetName(), src->GetSize()); | ||
| 139 | |||
| 140 | std::vector<u8> temp(std::min(block_size, src->GetSize())); | ||
| 141 | for (std::size_t i = 0; i < src->GetSize(); i += block_size) { | ||
| 142 | const auto read = std::min(block_size, src->GetSize() - i); | ||
| 143 | |||
| 144 | if (src->Read(temp.data(), read, i) != read) { | ||
| 145 | return false; | ||
| 146 | } | ||
| 147 | |||
| 148 | if (dest->Write(temp.data(), read, i) != read) { | ||
| 149 | return false; | ||
| 150 | } | ||
| 151 | |||
| 152 | progress.UpdateFileProgress(i); | ||
| 153 | } | ||
| 154 | |||
| 155 | progress.FinishDownloadingFile(); | ||
| 156 | |||
| 157 | return true; | ||
| 158 | } | ||
| 159 | |||
| 160 | bool VfsRawCopyDProgressSingle(FileSys::VirtualDir src, FileSys::VirtualDir dest, | ||
| 161 | ProgressServiceBackend& progress, std::size_t block_size = 0x1000) { | ||
| 162 | if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable()) | ||
| 163 | return false; | ||
| 164 | |||
| 165 | for (const auto& file : src->GetFiles()) { | ||
| 166 | const auto out_file = VfsCreateFileWrap(dest, file->GetName()); | ||
| 167 | if (!VfsRawCopyProgress(file, out_file, src->GetName(), progress, block_size)) { | ||
| 168 | return false; | ||
| 169 | } | ||
| 170 | } | ||
| 171 | progress.CommitDirectory(src->GetName()); | ||
| 172 | |||
| 173 | return true; | ||
| 174 | } | ||
| 175 | |||
| 176 | bool VfsRawCopyDProgress(FileSys::VirtualDir src, FileSys::VirtualDir dest, | ||
| 177 | ProgressServiceBackend& progress, std::size_t block_size = 0x1000) { | ||
| 178 | if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable()) | ||
| 179 | return false; | ||
| 180 | |||
| 181 | for (const auto& dir : src->GetSubdirectories()) { | ||
| 182 | const auto out = dest->CreateSubdirectory(dir->GetName()); | ||
| 183 | if (!VfsRawCopyDProgressSingle(dir, out, progress, block_size)) { | ||
| 184 | return false; | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | return true; | ||
| 189 | } | ||
| 190 | |||
| 191 | } // Anonymous namespace | ||
| 192 | |||
| 193 | class Boxcat::Client { | ||
| 194 | public: | ||
| 195 | Client(std::filesystem::path path_, u64 title_id_, u64 build_id_) | ||
| 196 | : path(std::move(path_)), title_id(title_id_), build_id(build_id_) {} | ||
| 197 | |||
| 198 | DownloadResult DownloadDataZip() { | ||
| 199 | return DownloadInternal(fmt::format(BOXCAT_PATHNAME_DATA, title_id), TIMEOUT_SECONDS, | ||
| 200 | "application/zip"); | ||
| 201 | } | ||
| 202 | |||
| 203 | DownloadResult DownloadLaunchParam() { | ||
| 204 | return DownloadInternal(fmt::format(BOXCAT_PATHNAME_LAUNCHPARAM, title_id), | ||
| 205 | TIMEOUT_SECONDS / 3, "application/octet-stream"); | ||
| 206 | } | ||
| 207 | |||
| 208 | private: | ||
| 209 | DownloadResult DownloadInternal(const std::string& resolved_path, u32 timeout_seconds, | ||
| 210 | const std::string& content_type_name) { | ||
| 211 | if (client == nullptr) { | ||
| 212 | client = std::make_unique<httplib::SSLClient>(BOXCAT_HOSTNAME, PORT); | ||
| 213 | client->set_connection_timeout(timeout_seconds); | ||
| 214 | client->set_read_timeout(timeout_seconds); | ||
| 215 | client->set_write_timeout(timeout_seconds); | ||
| 216 | } | ||
| 217 | |||
| 218 | httplib::Headers headers{ | ||
| 219 | {std::string("Game-Assets-API-Version"), std::string(BOXCAT_API_VERSION)}, | ||
| 220 | {std::string("Boxcat-Client-Type"), std::string(BOXCAT_CLIENT_TYPE)}, | ||
| 221 | {std::string("Game-Build-Id"), fmt::format("{:016X}", build_id)}, | ||
| 222 | }; | ||
| 223 | |||
| 224 | if (Common::FS::Exists(path)) { | ||
| 225 | Common::FS::IOFile file{path, Common::FS::FileAccessMode::Read, | ||
| 226 | Common::FS::FileType::BinaryFile}; | ||
| 227 | if (file.IsOpen()) { | ||
| 228 | std::vector<u8> bytes(file.GetSize()); | ||
| 229 | void(file.Read(bytes)); | ||
| 230 | const auto digest = DigestFile(bytes); | ||
| 231 | headers.insert({std::string("If-None-Match"), Common::HexToString(digest, false)}); | ||
| 232 | } | ||
| 233 | } | ||
| 234 | |||
| 235 | const auto response = client->Get(resolved_path.c_str(), headers); | ||
| 236 | if (response == nullptr) | ||
| 237 | return DownloadResult::NoResponse; | ||
| 238 | |||
| 239 | if (response->status == static_cast<int>(ResponseStatus::NoUpdate)) | ||
| 240 | return DownloadResult::Success; | ||
| 241 | if (response->status == static_cast<int>(ResponseStatus::BadClientVersion)) | ||
| 242 | return DownloadResult::BadClientVersion; | ||
| 243 | if (response->status == static_cast<int>(ResponseStatus::NoMatchTitleId)) | ||
| 244 | return DownloadResult::NoMatchTitleId; | ||
| 245 | if (response->status == static_cast<int>(ResponseStatus::NoMatchBuildId)) | ||
| 246 | return DownloadResult::NoMatchBuildId; | ||
| 247 | if (response->status != static_cast<int>(ResponseStatus::Ok)) | ||
| 248 | return DownloadResult::GeneralWebError; | ||
| 249 | |||
| 250 | const auto content_type = response->headers.find("content-type"); | ||
| 251 | if (content_type == response->headers.end() || | ||
| 252 | content_type->second.find(content_type_name) == std::string::npos) { | ||
| 253 | return DownloadResult::InvalidContentType; | ||
| 254 | } | ||
| 255 | |||
| 256 | if (!Common::FS::CreateDirs(path)) { | ||
| 257 | return DownloadResult::GeneralFSError; | ||
| 258 | } | ||
| 259 | |||
| 260 | Common::FS::IOFile file{path, Common::FS::FileAccessMode::Append, | ||
| 261 | Common::FS::FileType::BinaryFile}; | ||
| 262 | if (!file.IsOpen()) { | ||
| 263 | return DownloadResult::GeneralFSError; | ||
| 264 | } | ||
| 265 | |||
| 266 | if (!file.SetSize(response->body.size())) { | ||
| 267 | return DownloadResult::GeneralFSError; | ||
| 268 | } | ||
| 269 | |||
| 270 | if (file.Write(response->body) != response->body.size()) { | ||
| 271 | return DownloadResult::GeneralFSError; | ||
| 272 | } | ||
| 273 | |||
| 274 | return DownloadResult::Success; | ||
| 275 | } | ||
| 276 | |||
| 277 | using Digest = std::array<u8, 0x20>; | ||
| 278 | static Digest DigestFile(std::vector<u8> bytes) { | ||
| 279 | Digest out{}; | ||
| 280 | mbedtls_sha256_ret(bytes.data(), bytes.size(), out.data(), 0); | ||
| 281 | return out; | ||
| 282 | } | ||
| 283 | |||
| 284 | std::unique_ptr<httplib::SSLClient> client; | ||
| 285 | std::filesystem::path path; | ||
| 286 | u64 title_id; | ||
| 287 | u64 build_id; | ||
| 288 | }; | ||
| 289 | |||
| 290 | Boxcat::Boxcat(AM::Applets::AppletManager& applet_manager_, DirectoryGetter getter) | ||
| 291 | : Backend(std::move(getter)), applet_manager{applet_manager_} {} | ||
| 292 | |||
| 293 | Boxcat::~Boxcat() = default; | ||
| 294 | |||
| 295 | void SynchronizeInternal(AM::Applets::AppletManager& applet_manager, DirectoryGetter dir_getter, | ||
| 296 | TitleIDVersion title, ProgressServiceBackend& progress, | ||
| 297 | std::optional<std::string> dir_name = {}) { | ||
| 298 | progress.SetNeedHLELock(true); | ||
| 299 | |||
| 300 | if (Settings::values.bcat_boxcat_local) { | ||
| 301 | LOG_INFO(Service_BCAT, "Boxcat using local data by override, skipping download."); | ||
| 302 | const auto dir = dir_getter(title.title_id); | ||
| 303 | if (dir) | ||
| 304 | progress.SetTotalSize(dir->GetSize()); | ||
| 305 | progress.FinishDownload(ResultSuccess); | ||
| 306 | return; | ||
| 307 | } | ||
| 308 | |||
| 309 | const auto zip_path = GetZIPFilePath(title.title_id); | ||
| 310 | Boxcat::Client client{zip_path, title.title_id, title.build_id}; | ||
| 311 | |||
| 312 | progress.StartConnecting(); | ||
| 313 | |||
| 314 | const auto res = client.DownloadDataZip(); | ||
| 315 | if (res != DownloadResult::Success) { | ||
| 316 | LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res); | ||
| 317 | |||
| 318 | if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) { | ||
| 319 | Common::FS::RemoveFile(zip_path); | ||
| 320 | } | ||
| 321 | |||
| 322 | HandleDownloadDisplayResult(applet_manager, res); | ||
| 323 | progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE); | ||
| 324 | return; | ||
| 325 | } | ||
| 326 | |||
| 327 | progress.StartProcessingDataList(); | ||
| 328 | |||
| 329 | Common::FS::IOFile zip{zip_path, Common::FS::FileAccessMode::Read, | ||
| 330 | Common::FS::FileType::BinaryFile}; | ||
| 331 | const auto size = zip.GetSize(); | ||
| 332 | std::vector<u8> bytes(size); | ||
| 333 | if (!zip.IsOpen() || size == 0 || zip.Read(bytes) != bytes.size()) { | ||
| 334 | LOG_ERROR(Service_BCAT, "Boxcat failed to read ZIP file at path '{}'!", | ||
| 335 | Common::FS::PathToUTF8String(zip_path)); | ||
| 336 | progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE); | ||
| 337 | return; | ||
| 338 | } | ||
| 339 | |||
| 340 | const auto extracted = FileSys::ExtractZIP(std::make_shared<FileSys::VectorVfsFile>(bytes)); | ||
| 341 | if (extracted == nullptr) { | ||
| 342 | LOG_ERROR(Service_BCAT, "Boxcat failed to extract ZIP file!"); | ||
| 343 | progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE); | ||
| 344 | return; | ||
| 345 | } | ||
| 346 | |||
| 347 | if (dir_name == std::nullopt) { | ||
| 348 | progress.SetTotalSize(extracted->GetSize()); | ||
| 349 | |||
| 350 | const auto target_dir = dir_getter(title.title_id); | ||
| 351 | if (target_dir == nullptr || !VfsRawCopyDProgress(extracted, target_dir, progress)) { | ||
| 352 | LOG_ERROR(Service_BCAT, "Boxcat failed to copy extracted ZIP to target directory!"); | ||
| 353 | progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE); | ||
| 354 | return; | ||
| 355 | } | ||
| 356 | } else { | ||
| 357 | const auto target_dir = dir_getter(title.title_id); | ||
| 358 | if (target_dir == nullptr) { | ||
| 359 | LOG_ERROR(Service_BCAT, "Boxcat failed to get directory for title ID!"); | ||
| 360 | progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE); | ||
| 361 | return; | ||
| 362 | } | ||
| 363 | |||
| 364 | const auto target_sub = target_dir->GetSubdirectory(*dir_name); | ||
| 365 | const auto source_sub = extracted->GetSubdirectory(*dir_name); | ||
| 366 | |||
| 367 | progress.SetTotalSize(source_sub->GetSize()); | ||
| 368 | |||
| 369 | std::vector<std::string> filenames; | ||
| 370 | { | ||
| 371 | const auto files = target_sub->GetFiles(); | ||
| 372 | std::transform(files.begin(), files.end(), std::back_inserter(filenames), | ||
| 373 | [](const auto& vfile) { return vfile->GetName(); }); | ||
| 374 | } | ||
| 375 | |||
| 376 | for (const auto& filename : filenames) { | ||
| 377 | VfsDeleteFileWrap(target_sub, filename); | ||
| 378 | } | ||
| 379 | |||
| 380 | if (target_sub == nullptr || source_sub == nullptr || | ||
| 381 | !VfsRawCopyDProgressSingle(source_sub, target_sub, progress)) { | ||
| 382 | LOG_ERROR(Service_BCAT, "Boxcat failed to copy extracted ZIP to target directory!"); | ||
| 383 | progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE); | ||
| 384 | return; | ||
| 385 | } | ||
| 386 | } | ||
| 387 | |||
| 388 | progress.FinishDownload(ResultSuccess); | ||
| 389 | } | ||
| 390 | |||
| 391 | bool Boxcat::Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) { | ||
| 392 | is_syncing.exchange(true); | ||
| 393 | |||
| 394 | std::thread([this, title, &progress] { | ||
| 395 | SynchronizeInternal(applet_manager, dir_getter, title, progress); | ||
| 396 | }).detach(); | ||
| 397 | |||
| 398 | return true; | ||
| 399 | } | ||
| 400 | |||
| 401 | bool Boxcat::SynchronizeDirectory(TitleIDVersion title, std::string name, | ||
| 402 | ProgressServiceBackend& progress) { | ||
| 403 | is_syncing.exchange(true); | ||
| 404 | |||
| 405 | std::thread([this, title, name, &progress] { | ||
| 406 | SynchronizeInternal(applet_manager, dir_getter, title, progress, name); | ||
| 407 | }).detach(); | ||
| 408 | |||
| 409 | return true; | ||
| 410 | } | ||
| 411 | |||
| 412 | bool Boxcat::Clear(u64 title_id) { | ||
| 413 | if (Settings::values.bcat_boxcat_local) { | ||
| 414 | LOG_INFO(Service_BCAT, "Boxcat using local data by override, skipping clear."); | ||
| 415 | return true; | ||
| 416 | } | ||
| 417 | |||
| 418 | const auto dir = dir_getter(title_id); | ||
| 419 | |||
| 420 | std::vector<std::string> dirnames; | ||
| 421 | |||
| 422 | for (const auto& subdir : dir->GetSubdirectories()) | ||
| 423 | dirnames.push_back(subdir->GetName()); | ||
| 424 | |||
| 425 | for (const auto& subdir : dirnames) { | ||
| 426 | if (!dir->DeleteSubdirectoryRecursive(subdir)) | ||
| 427 | return false; | ||
| 428 | } | ||
| 429 | |||
| 430 | return true; | ||
| 431 | } | ||
| 432 | |||
| 433 | void Boxcat::SetPassphrase(u64 title_id, const Passphrase& passphrase) { | ||
| 434 | LOG_DEBUG(Service_BCAT, "called, title_id={:016X}, passphrase={}", title_id, | ||
| 435 | Common::HexToString(passphrase)); | ||
| 436 | } | ||
| 437 | |||
| 438 | std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title) { | ||
| 439 | const auto bin_file_path = GetBINFilePath(title.title_id); | ||
| 440 | |||
| 441 | if (Settings::values.bcat_boxcat_local) { | ||
| 442 | LOG_INFO(Service_BCAT, "Boxcat using local data by override, skipping download."); | ||
| 443 | } else { | ||
| 444 | Client launch_client{bin_file_path, title.title_id, title.build_id}; | ||
| 445 | |||
| 446 | const auto res = launch_client.DownloadLaunchParam(); | ||
| 447 | if (res != DownloadResult::Success) { | ||
| 448 | LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res); | ||
| 449 | |||
| 450 | if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) { | ||
| 451 | Common::FS::RemoveFile(bin_file_path); | ||
| 452 | } | ||
| 453 | |||
| 454 | HandleDownloadDisplayResult(applet_manager, res); | ||
| 455 | return std::nullopt; | ||
| 456 | } | ||
| 457 | } | ||
| 458 | |||
| 459 | Common::FS::IOFile bin{bin_file_path, Common::FS::FileAccessMode::Read, | ||
| 460 | Common::FS::FileType::BinaryFile}; | ||
| 461 | const auto size = bin.GetSize(); | ||
| 462 | std::vector<u8> bytes(size); | ||
| 463 | if (!bin.IsOpen() || size == 0 || bin.Read(bytes) != bytes.size()) { | ||
| 464 | LOG_ERROR(Service_BCAT, "Boxcat failed to read launch parameter binary at path '{}'!", | ||
| 465 | Common::FS::PathToUTF8String(bin_file_path)); | ||
| 466 | return std::nullopt; | ||
| 467 | } | ||
| 468 | |||
| 469 | return bytes; | ||
| 470 | } | ||
| 471 | |||
| 472 | Boxcat::StatusResult Boxcat::GetStatus(std::optional<std::string>& global, | ||
| 473 | std::map<std::string, EventStatus>& games) { | ||
| 474 | httplib::SSLClient client{BOXCAT_HOSTNAME, static_cast<int>(PORT)}; | ||
| 475 | client.set_connection_timeout(static_cast<int>(TIMEOUT_SECONDS)); | ||
| 476 | client.set_read_timeout(static_cast<int>(TIMEOUT_SECONDS)); | ||
| 477 | client.set_write_timeout(static_cast<int>(TIMEOUT_SECONDS)); | ||
| 478 | |||
| 479 | httplib::Headers headers{ | ||
| 480 | {std::string("Game-Assets-API-Version"), std::string(BOXCAT_API_VERSION)}, | ||
| 481 | {std::string("Boxcat-Client-Type"), std::string(BOXCAT_CLIENT_TYPE)}, | ||
| 482 | }; | ||
| 483 | |||
| 484 | if (!client.is_valid()) { | ||
| 485 | LOG_ERROR(Service_BCAT, "Client is invalid, going offline!"); | ||
| 486 | return StatusResult::Offline; | ||
| 487 | } | ||
| 488 | |||
| 489 | if (!client.is_socket_open()) { | ||
| 490 | LOG_ERROR(Service_BCAT, "Failed to open socket, going offline!"); | ||
| 491 | return StatusResult::Offline; | ||
| 492 | } | ||
| 493 | |||
| 494 | const auto response = client.Get(BOXCAT_PATHNAME_EVENTS, headers); | ||
| 495 | if (response == nullptr) | ||
| 496 | return StatusResult::Offline; | ||
| 497 | |||
| 498 | if (response->status == static_cast<int>(ResponseStatus::BadClientVersion)) | ||
| 499 | return StatusResult::BadClientVersion; | ||
| 500 | |||
| 501 | try { | ||
| 502 | nlohmann::json json = nlohmann::json::parse(response->body); | ||
| 503 | |||
| 504 | if (!json["online"].get<bool>()) | ||
| 505 | return StatusResult::Offline; | ||
| 506 | |||
| 507 | if (json["global"].is_null()) | ||
| 508 | global = std::nullopt; | ||
| 509 | else | ||
| 510 | global = json["global"].get<std::string>(); | ||
| 511 | |||
| 512 | if (json["games"].is_array()) { | ||
| 513 | for (const auto& object : json["games"]) { | ||
| 514 | if (object.is_object() && object.find("name") != object.end()) { | ||
| 515 | EventStatus detail{}; | ||
| 516 | if (object["header"].is_string()) { | ||
| 517 | detail.header = object["header"].get<std::string>(); | ||
| 518 | } else { | ||
| 519 | detail.header = std::nullopt; | ||
| 520 | } | ||
| 521 | |||
| 522 | if (object["footer"].is_string()) { | ||
| 523 | detail.footer = object["footer"].get<std::string>(); | ||
| 524 | } else { | ||
| 525 | detail.footer = std::nullopt; | ||
| 526 | } | ||
| 527 | |||
| 528 | if (object["events"].is_array()) { | ||
| 529 | for (const auto& event : object["events"]) { | ||
| 530 | if (!event.is_string()) | ||
| 531 | continue; | ||
| 532 | detail.events.push_back(event.get<std::string>()); | ||
| 533 | } | ||
| 534 | } | ||
| 535 | |||
| 536 | games.insert_or_assign(object["name"], std::move(detail)); | ||
| 537 | } | ||
| 538 | } | ||
| 539 | } | ||
| 540 | |||
| 541 | return StatusResult::Success; | ||
| 542 | } catch (const nlohmann::json::parse_error& error) { | ||
| 543 | LOG_ERROR(Service_BCAT, "{}", error.what()); | ||
| 544 | return StatusResult::ParseError; | ||
| 545 | } | ||
| 546 | } | ||
| 547 | |||
| 548 | } // namespace Service::BCAT | ||
diff --git a/src/core/hle/service/bcat/backend/boxcat.h b/src/core/hle/service/bcat/backend/boxcat.h deleted file mode 100644 index d65b42e58..000000000 --- a/src/core/hle/service/bcat/backend/boxcat.h +++ /dev/null | |||
| @@ -1,64 +0,0 @@ | |||
| 1 | // Copyright 2019 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <atomic> | ||
| 8 | #include <map> | ||
| 9 | #include <optional> | ||
| 10 | #include "core/hle/service/bcat/backend/backend.h" | ||
| 11 | |||
| 12 | namespace Service::AM::Applets { | ||
| 13 | class AppletManager; | ||
| 14 | } | ||
| 15 | |||
| 16 | namespace Service::BCAT { | ||
| 17 | |||
| 18 | struct EventStatus { | ||
| 19 | std::optional<std::string> header; | ||
| 20 | std::optional<std::string> footer; | ||
| 21 | std::vector<std::string> events; | ||
| 22 | }; | ||
| 23 | |||
| 24 | /// Boxcat is yuzu's custom backend implementation of Nintendo's BCAT service. It is free to use and | ||
| 25 | /// doesn't require a switch or nintendo account. The content is controlled by the yuzu team. | ||
| 26 | class Boxcat final : public Backend { | ||
| 27 | friend void SynchronizeInternal(AM::Applets::AppletManager& applet_manager, | ||
| 28 | DirectoryGetter dir_getter, TitleIDVersion title, | ||
| 29 | ProgressServiceBackend& progress, | ||
| 30 | std::optional<std::string> dir_name); | ||
| 31 | |||
| 32 | public: | ||
| 33 | explicit Boxcat(AM::Applets::AppletManager& applet_manager_, DirectoryGetter getter); | ||
| 34 | ~Boxcat() override; | ||
| 35 | |||
| 36 | bool Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) override; | ||
| 37 | bool SynchronizeDirectory(TitleIDVersion title, std::string name, | ||
| 38 | ProgressServiceBackend& progress) override; | ||
| 39 | |||
| 40 | bool Clear(u64 title_id) override; | ||
| 41 | |||
| 42 | void SetPassphrase(u64 title_id, const Passphrase& passphrase) override; | ||
| 43 | |||
| 44 | std::optional<std::vector<u8>> GetLaunchParameter(TitleIDVersion title) override; | ||
| 45 | |||
| 46 | enum class StatusResult { | ||
| 47 | Success, | ||
| 48 | Offline, | ||
| 49 | ParseError, | ||
| 50 | BadClientVersion, | ||
| 51 | }; | ||
| 52 | |||
| 53 | static StatusResult GetStatus(std::optional<std::string>& global, | ||
| 54 | std::map<std::string, EventStatus>& games); | ||
| 55 | |||
| 56 | private: | ||
| 57 | std::atomic_bool is_syncing{false}; | ||
| 58 | |||
| 59 | class Client; | ||
| 60 | std::unique_ptr<Client> client; | ||
| 61 | AM::Applets::AppletManager& applet_manager; | ||
| 62 | }; | ||
| 63 | |||
| 64 | } // namespace Service::BCAT | ||
diff --git a/src/core/hle/service/bcat/bcat_module.cpp b/src/core/hle/service/bcat/bcat_module.cpp index 72294eb2e..701f634f8 100644 --- a/src/core/hle/service/bcat/bcat_module.cpp +++ b/src/core/hle/service/bcat/bcat_module.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include <cctype> | 5 | #include <cctype> |
| 6 | #include <mbedtls/md5.h> | 6 | #include <mbedtls/md5.h> |
| 7 | #include "backend/boxcat.h" | ||
| 8 | #include "common/hex_util.h" | 7 | #include "common/hex_util.h" |
| 9 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 10 | #include "common/settings.h" | 9 | #include "common/settings.h" |
| @@ -578,12 +577,6 @@ void Module::Interface::CreateDeliveryCacheStorageServiceWithApplicationId( | |||
| 578 | 577 | ||
| 579 | std::unique_ptr<Backend> CreateBackendFromSettings([[maybe_unused]] Core::System& system, | 578 | std::unique_ptr<Backend> CreateBackendFromSettings([[maybe_unused]] Core::System& system, |
| 580 | DirectoryGetter getter) { | 579 | DirectoryGetter getter) { |
| 581 | #ifdef YUZU_ENABLE_BOXCAT | ||
| 582 | if (Settings::values.bcat_backend.GetValue() == "boxcat") { | ||
| 583 | return std::make_unique<Boxcat>(system.GetAppletManager(), std::move(getter)); | ||
| 584 | } | ||
| 585 | #endif | ||
| 586 | |||
| 587 | return std::make_unique<NullBackend>(std::move(getter)); | 580 | return std::make_unique<NullBackend>(std::move(getter)); |
| 588 | } | 581 | } |
| 589 | 582 | ||
diff --git a/src/core/hle/service/btdrv/btdrv.cpp b/src/core/hle/service/btdrv/btdrv.cpp index 46da438ef..acf791de2 100644 --- a/src/core/hle/service/btdrv/btdrv.cpp +++ b/src/core/hle/service/btdrv/btdrv.cpp | |||
| @@ -175,6 +175,10 @@ public: | |||
| 175 | {143, nullptr, "GetAudioControlInputState"}, | 175 | {143, nullptr, "GetAudioControlInputState"}, |
| 176 | {144, nullptr, "AcquireAudioConnectionStateChangedEvent"}, | 176 | {144, nullptr, "AcquireAudioConnectionStateChangedEvent"}, |
| 177 | {145, nullptr, "GetConnectedAudioDevice"}, | 177 | {145, nullptr, "GetConnectedAudioDevice"}, |
| 178 | {146, nullptr, "CloseAudioControlInput"}, | ||
| 179 | {147, nullptr, "RegisterAudioControlNotification"}, | ||
| 180 | {148, nullptr, "SendAudioControlPassthroughCommand"}, | ||
| 181 | {149, nullptr, "SendAudioControlSetAbsoluteVolumeCommand"}, | ||
| 178 | {256, nullptr, "IsManufacturingMode"}, | 182 | {256, nullptr, "IsManufacturingMode"}, |
| 179 | {257, nullptr, "EmulateBluetoothCrash"}, | 183 | {257, nullptr, "EmulateBluetoothCrash"}, |
| 180 | {258, nullptr, "GetBleChannelMap"}, | 184 | {258, nullptr, "GetBleChannelMap"}, |
diff --git a/src/core/hle/service/caps/caps_ss.cpp b/src/core/hle/service/caps/caps_ss.cpp index 2b5314691..33a976ddf 100644 --- a/src/core/hle/service/caps/caps_ss.cpp +++ b/src/core/hle/service/caps/caps_ss.cpp | |||
| @@ -15,6 +15,7 @@ CAPS_SS::CAPS_SS(Core::System& system_) : ServiceFramework{system_, "caps:ss"} { | |||
| 15 | {204, nullptr, "SaveEditedScreenShotEx0"}, | 15 | {204, nullptr, "SaveEditedScreenShotEx0"}, |
| 16 | {206, nullptr, "Unknown206"}, | 16 | {206, nullptr, "Unknown206"}, |
| 17 | {208, nullptr, "SaveScreenShotOfMovieEx1"}, | 17 | {208, nullptr, "SaveScreenShotOfMovieEx1"}, |
| 18 | {1000, nullptr, "Unknown1000"}, | ||
| 18 | }; | 19 | }; |
| 19 | // clang-format on | 20 | // clang-format on |
| 20 | 21 | ||
diff --git a/src/core/hle/service/es/es.cpp b/src/core/hle/service/es/es.cpp index 110c7cb1c..f6184acc9 100644 --- a/src/core/hle/service/es/es.cpp +++ b/src/core/hle/service/es/es.cpp | |||
| @@ -55,6 +55,8 @@ public: | |||
| 55 | {36, nullptr, "DeleteAllInactiveELicenseRequiredPersonalizedTicket"}, | 55 | {36, nullptr, "DeleteAllInactiveELicenseRequiredPersonalizedTicket"}, |
| 56 | {37, nullptr, "OwnTicket2"}, | 56 | {37, nullptr, "OwnTicket2"}, |
| 57 | {38, nullptr, "OwnTicket3"}, | 57 | {38, nullptr, "OwnTicket3"}, |
| 58 | {39, nullptr, "DeleteAllInactivePersonalizedTicket"}, | ||
| 59 | {40, nullptr, "DeletePrepurchaseRecordByNintendoAccountId"}, | ||
| 58 | {501, nullptr, "Unknown501"}, | 60 | {501, nullptr, "Unknown501"}, |
| 59 | {502, nullptr, "Unknown502"}, | 61 | {502, nullptr, "Unknown502"}, |
| 60 | {503, nullptr, "GetTitleKey"}, | 62 | {503, nullptr, "GetTitleKey"}, |
| @@ -88,11 +90,15 @@ public: | |||
| 88 | {1503, nullptr, "Unknown1503"}, | 90 | {1503, nullptr, "Unknown1503"}, |
| 89 | {1504, nullptr, "Unknown1504"}, | 91 | {1504, nullptr, "Unknown1504"}, |
| 90 | {1505, nullptr, "Unknown1505"}, | 92 | {1505, nullptr, "Unknown1505"}, |
| 93 | {1506, nullptr, "Unknown1506"}, | ||
| 91 | {2000, nullptr, "Unknown2000"}, | 94 | {2000, nullptr, "Unknown2000"}, |
| 92 | {2001, nullptr, "Unknown2001"}, | 95 | {2001, nullptr, "Unknown2001"}, |
| 96 | {2002, nullptr, "Unknown2002"}, | ||
| 97 | {2003, nullptr, "Unknown2003"}, | ||
| 93 | {2100, nullptr, "Unknown2100"}, | 98 | {2100, nullptr, "Unknown2100"}, |
| 94 | {2501, nullptr, "Unknown2501"}, | 99 | {2501, nullptr, "Unknown2501"}, |
| 95 | {2502, nullptr, "Unknown2502"}, | 100 | {2502, nullptr, "Unknown2502"}, |
| 101 | {2601, nullptr, "Unknown2601"}, | ||
| 96 | {3001, nullptr, "Unknown3001"}, | 102 | {3001, nullptr, "Unknown3001"}, |
| 97 | {3002, nullptr, "Unknown3002"}, | 103 | {3002, nullptr, "Unknown3002"}, |
| 98 | }; | 104 | }; |
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index 4a9b13e45..f8f9e32f7 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp | |||
| @@ -97,14 +97,24 @@ ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) cons | |||
| 97 | 97 | ||
| 98 | ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const { | 98 | ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_) const { |
| 99 | std::string path(Common::FS::SanitizePath(path_)); | 99 | std::string path(Common::FS::SanitizePath(path_)); |
| 100 | auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path)); | 100 | |
| 101 | if (dir == nullptr || Common::FS::GetFilename(Common::FS::GetParentPath(path)).empty()) { | 101 | // NOTE: This is inaccurate behavior. CreateDirectory is not recursive. |
| 102 | dir = backing; | 102 | // CreateDirectory should return PathNotFound if the parent directory does not exist. |
| 103 | } | 103 | // This is here temporarily in order to have UMM "work" in the meantime. |
| 104 | auto new_dir = dir->CreateSubdirectory(Common::FS::GetFilename(path)); | 104 | // TODO (Morph): Remove this when a hardware test verifies the correct behavior. |
| 105 | if (new_dir == nullptr) { | 105 | const auto components = Common::FS::SplitPathComponents(path); |
| 106 | // TODO(DarkLordZach): Find a better error code for this | 106 | std::string relative_path; |
| 107 | return ResultUnknown; | 107 | for (const auto& component : components) { |
| 108 | // Skip empty path components | ||
| 109 | if (component.empty()) { | ||
| 110 | continue; | ||
| 111 | } | ||
| 112 | relative_path = Common::FS::SanitizePath(relative_path + '/' + component); | ||
| 113 | auto new_dir = backing->CreateSubdirectory(relative_path); | ||
| 114 | if (new_dir == nullptr) { | ||
| 115 | // TODO(DarkLordZach): Find a better error code for this | ||
| 116 | return ResultUnknown; | ||
| 117 | } | ||
| 108 | } | 118 | } |
| 109 | return ResultSuccess; | 119 | return ResultSuccess; |
| 110 | } | 120 | } |
| @@ -251,6 +261,18 @@ ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType( | |||
| 251 | return FileSys::ERROR_PATH_NOT_FOUND; | 261 | return FileSys::ERROR_PATH_NOT_FOUND; |
| 252 | } | 262 | } |
| 253 | 263 | ||
| 264 | ResultVal<FileSys::FileTimeStampRaw> VfsDirectoryServiceWrapper::GetFileTimeStampRaw( | ||
| 265 | const std::string& path) const { | ||
| 266 | auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path)); | ||
| 267 | if (dir == nullptr) { | ||
| 268 | return FileSys::ERROR_PATH_NOT_FOUND; | ||
| 269 | } | ||
| 270 | if (GetEntryType(path).Failed()) { | ||
| 271 | return FileSys::ERROR_PATH_NOT_FOUND; | ||
| 272 | } | ||
| 273 | return MakeResult(dir->GetFileTimeStamp(Common::FS::GetFilename(path))); | ||
| 274 | } | ||
| 275 | |||
| 254 | FileSystemController::FileSystemController(Core::System& system_) : system{system_} {} | 276 | FileSystemController::FileSystemController(Core::System& system_) : system{system_} {} |
| 255 | 277 | ||
| 256 | FileSystemController::~FileSystemController() = default; | 278 | FileSystemController::~FileSystemController() = default; |
diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index d387af3cb..b155e0811 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h | |||
| @@ -240,6 +240,12 @@ public: | |||
| 240 | */ | 240 | */ |
| 241 | ResultVal<FileSys::EntryType> GetEntryType(const std::string& path) const; | 241 | ResultVal<FileSys::EntryType> GetEntryType(const std::string& path) const; |
| 242 | 242 | ||
| 243 | /** | ||
| 244 | * Get the timestamp of the specified path | ||
| 245 | * @return The timestamp of the specified path or error code | ||
| 246 | */ | ||
| 247 | ResultVal<FileSys::FileTimeStampRaw> GetFileTimeStampRaw(const std::string& path) const; | ||
| 248 | |||
| 243 | private: | 249 | private: |
| 244 | FileSys::VirtualDir backing; | 250 | FileSys::VirtualDir backing; |
| 245 | }; | 251 | }; |
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index db4d44c12..50c788dd6 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -326,7 +326,7 @@ public: | |||
| 326 | {11, &IFileSystem::GetFreeSpaceSize, "GetFreeSpaceSize"}, | 326 | {11, &IFileSystem::GetFreeSpaceSize, "GetFreeSpaceSize"}, |
| 327 | {12, &IFileSystem::GetTotalSpaceSize, "GetTotalSpaceSize"}, | 327 | {12, &IFileSystem::GetTotalSpaceSize, "GetTotalSpaceSize"}, |
| 328 | {13, &IFileSystem::CleanDirectoryRecursively, "CleanDirectoryRecursively"}, | 328 | {13, &IFileSystem::CleanDirectoryRecursively, "CleanDirectoryRecursively"}, |
| 329 | {14, nullptr, "GetFileTimeStampRaw"}, | 329 | {14, &IFileSystem::GetFileTimeStampRaw, "GetFileTimeStampRaw"}, |
| 330 | {15, nullptr, "QueryEntry"}, | 330 | {15, nullptr, "QueryEntry"}, |
| 331 | }; | 331 | }; |
| 332 | RegisterHandlers(functions); | 332 | RegisterHandlers(functions); |
| @@ -501,6 +501,24 @@ public: | |||
| 501 | rb.Push(size.get_total_size()); | 501 | rb.Push(size.get_total_size()); |
| 502 | } | 502 | } |
| 503 | 503 | ||
| 504 | void GetFileTimeStampRaw(Kernel::HLERequestContext& ctx) { | ||
| 505 | const auto file_buffer = ctx.ReadBuffer(); | ||
| 506 | const std::string name = Common::StringFromBuffer(file_buffer); | ||
| 507 | |||
| 508 | LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); | ||
| 509 | |||
| 510 | auto result = backend.GetFileTimeStampRaw(name); | ||
| 511 | if (result.Failed()) { | ||
| 512 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 513 | rb.Push(result.Code()); | ||
| 514 | return; | ||
| 515 | } | ||
| 516 | |||
| 517 | IPC::ResponseBuilder rb{ctx, 10}; | ||
| 518 | rb.Push(ResultSuccess); | ||
| 519 | rb.PushRaw(*result); | ||
| 520 | } | ||
| 521 | |||
| 504 | private: | 522 | private: |
| 505 | VfsDirectoryServiceWrapper backend; | 523 | VfsDirectoryServiceWrapper backend; |
| 506 | SizeGetter size; | 524 | SizeGetter size; |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 4fcc6f93a..9ee146caf 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -507,6 +507,7 @@ private: | |||
| 507 | LarkNesRight = 18, | 507 | LarkNesRight = 18, |
| 508 | Lucia = 19, | 508 | Lucia = 19, |
| 509 | Verification = 20, | 509 | Verification = 20, |
| 510 | Lagon = 21, | ||
| 510 | }; | 511 | }; |
| 511 | 512 | ||
| 512 | struct NPadEntry { | 513 | struct NPadEntry { |
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h index ef2becefd..8e9b40c0a 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.h +++ b/src/core/hle/service/hid/controllers/touchscreen.h | |||
| @@ -15,6 +15,20 @@ | |||
| 15 | namespace Service::HID { | 15 | namespace Service::HID { |
| 16 | class Controller_Touchscreen final : public ControllerBase { | 16 | class Controller_Touchscreen final : public ControllerBase { |
| 17 | public: | 17 | public: |
| 18 | enum class TouchScreenModeForNx : u8 { | ||
| 19 | UseSystemSetting, | ||
| 20 | Finger, | ||
| 21 | Heat2, | ||
| 22 | }; | ||
| 23 | |||
| 24 | struct TouchScreenConfigurationForNx { | ||
| 25 | TouchScreenModeForNx mode; | ||
| 26 | INSERT_PADDING_BYTES_NOINIT(0x7); | ||
| 27 | INSERT_PADDING_BYTES_NOINIT(0xF); // Reserved | ||
| 28 | }; | ||
| 29 | static_assert(sizeof(TouchScreenConfigurationForNx) == 0x17, | ||
| 30 | "TouchScreenConfigurationForNx is an invalid size"); | ||
| 31 | |||
| 18 | explicit Controller_Touchscreen(Core::System& system_); | 32 | explicit Controller_Touchscreen(Core::System& system_); |
| 19 | ~Controller_Touchscreen() override; | 33 | ~Controller_Touchscreen() override; |
| 20 | 34 | ||
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index b8b80570d..8c363142c 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -106,7 +106,7 @@ void IAppletResource::DeactivateController(HidController controller) { | |||
| 106 | controllers[static_cast<size_t>(controller)]->DeactivateController(); | 106 | controllers[static_cast<size_t>(controller)]->DeactivateController(); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | IAppletResource ::~IAppletResource() { | 109 | IAppletResource::~IAppletResource() { |
| 110 | system.CoreTiming().UnscheduleEvent(pad_update_event, 0); | 110 | system.CoreTiming().UnscheduleEvent(pad_update_event, 0); |
| 111 | system.CoreTiming().UnscheduleEvent(motion_update_event, 0); | 111 | system.CoreTiming().UnscheduleEvent(motion_update_event, 0); |
| 112 | } | 112 | } |
| @@ -239,6 +239,12 @@ Hid::Hid(Core::System& system_) | |||
| 239 | {81, &Hid::ResetGyroscopeZeroDriftMode, "ResetGyroscopeZeroDriftMode"}, | 239 | {81, &Hid::ResetGyroscopeZeroDriftMode, "ResetGyroscopeZeroDriftMode"}, |
| 240 | {82, &Hid::IsSixAxisSensorAtRest, "IsSixAxisSensorAtRest"}, | 240 | {82, &Hid::IsSixAxisSensorAtRest, "IsSixAxisSensorAtRest"}, |
| 241 | {83, &Hid::IsFirmwareUpdateAvailableForSixAxisSensor, "IsFirmwareUpdateAvailableForSixAxisSensor"}, | 241 | {83, &Hid::IsFirmwareUpdateAvailableForSixAxisSensor, "IsFirmwareUpdateAvailableForSixAxisSensor"}, |
| 242 | {84, nullptr, "EnableSixAxisSensorUnalteredPassthrough"}, | ||
| 243 | {85, nullptr, "IsSixAxisSensorUnalteredPassthroughEnabled"}, | ||
| 244 | {86, nullptr, "StoreSixAxisSensorCalibrationParameter"}, | ||
| 245 | {87, nullptr, "LoadSixAxisSensorCalibrationParameter"}, | ||
| 246 | {88, nullptr, "GetSixAxisSensorIcInformation"}, | ||
| 247 | {89, nullptr, "ResetIsSixAxisSensorDeviceNewlyAssigned"}, | ||
| 242 | {91, &Hid::ActivateGesture, "ActivateGesture"}, | 248 | {91, &Hid::ActivateGesture, "ActivateGesture"}, |
| 243 | {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, | 249 | {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, |
| 244 | {101, &Hid::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"}, | 250 | {101, &Hid::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"}, |
| @@ -331,7 +337,7 @@ Hid::Hid(Core::System& system_) | |||
| 331 | {529, nullptr, "SetDisallowedPalmaConnection"}, | 337 | {529, nullptr, "SetDisallowedPalmaConnection"}, |
| 332 | {1000, &Hid::SetNpadCommunicationMode, "SetNpadCommunicationMode"}, | 338 | {1000, &Hid::SetNpadCommunicationMode, "SetNpadCommunicationMode"}, |
| 333 | {1001, &Hid::GetNpadCommunicationMode, "GetNpadCommunicationMode"}, | 339 | {1001, &Hid::GetNpadCommunicationMode, "GetNpadCommunicationMode"}, |
| 334 | {1002, nullptr, "SetTouchScreenConfiguration"}, | 340 | {1002, &Hid::SetTouchScreenConfiguration, "SetTouchScreenConfiguration"}, |
| 335 | {1003, nullptr, "IsFirmwareUpdateNeededForNotification"}, | 341 | {1003, nullptr, "IsFirmwareUpdateNeededForNotification"}, |
| 336 | {2000, nullptr, "ActivateDigitizer"}, | 342 | {2000, nullptr, "ActivateDigitizer"}, |
| 337 | }; | 343 | }; |
| @@ -1631,6 +1637,18 @@ void Hid::GetNpadCommunicationMode(Kernel::HLERequestContext& ctx) { | |||
| 1631 | .GetNpadCommunicationMode()); | 1637 | .GetNpadCommunicationMode()); |
| 1632 | } | 1638 | } |
| 1633 | 1639 | ||
| 1640 | void Hid::SetTouchScreenConfiguration(Kernel::HLERequestContext& ctx) { | ||
| 1641 | IPC::RequestParser rp{ctx}; | ||
| 1642 | const auto touchscreen_mode{rp.PopRaw<Controller_Touchscreen::TouchScreenConfigurationForNx>()}; | ||
| 1643 | const auto applet_resource_user_id{rp.Pop<u64>()}; | ||
| 1644 | |||
| 1645 | LOG_WARNING(Service_HID, "(STUBBED) called, touchscreen_mode={}, applet_resource_user_id={}", | ||
| 1646 | touchscreen_mode.mode, applet_resource_user_id); | ||
| 1647 | |||
| 1648 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 1649 | rb.Push(ResultSuccess); | ||
| 1650 | } | ||
| 1651 | |||
| 1634 | class HidDbg final : public ServiceFramework<HidDbg> { | 1652 | class HidDbg final : public ServiceFramework<HidDbg> { |
| 1635 | public: | 1653 | public: |
| 1636 | explicit HidDbg(Core::System& system_) : ServiceFramework{system_, "hid:dbg"} { | 1654 | explicit HidDbg(Core::System& system_) : ServiceFramework{system_, "hid:dbg"} { |
| @@ -1644,6 +1662,9 @@ public: | |||
| 1644 | {12, nullptr, "UnsetTouchScreenAutoPilotState"}, | 1662 | {12, nullptr, "UnsetTouchScreenAutoPilotState"}, |
| 1645 | {13, nullptr, "GetTouchScreenConfiguration"}, | 1663 | {13, nullptr, "GetTouchScreenConfiguration"}, |
| 1646 | {14, nullptr, "ProcessTouchScreenAutoTune"}, | 1664 | {14, nullptr, "ProcessTouchScreenAutoTune"}, |
| 1665 | {15, nullptr, "ForceStopTouchScreenManagement"}, | ||
| 1666 | {16, nullptr, "ForceRestartTouchScreenManagement"}, | ||
| 1667 | {17, nullptr, "IsTouchScreenManaged"}, | ||
| 1647 | {20, nullptr, "DeactivateMouse"}, | 1668 | {20, nullptr, "DeactivateMouse"}, |
| 1648 | {21, nullptr, "SetMouseAutoPilotState"}, | 1669 | {21, nullptr, "SetMouseAutoPilotState"}, |
| 1649 | {22, nullptr, "UnsetMouseAutoPilotState"}, | 1670 | {22, nullptr, "UnsetMouseAutoPilotState"}, |
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 9c5c7f252..b1fe75e94 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h | |||
| @@ -159,6 +159,7 @@ private: | |||
| 159 | void SetPalmaBoostMode(Kernel::HLERequestContext& ctx); | 159 | void SetPalmaBoostMode(Kernel::HLERequestContext& ctx); |
| 160 | void SetNpadCommunicationMode(Kernel::HLERequestContext& ctx); | 160 | void SetNpadCommunicationMode(Kernel::HLERequestContext& ctx); |
| 161 | void GetNpadCommunicationMode(Kernel::HLERequestContext& ctx); | 161 | void GetNpadCommunicationMode(Kernel::HLERequestContext& ctx); |
| 162 | void SetTouchScreenConfiguration(Kernel::HLERequestContext& ctx); | ||
| 162 | 163 | ||
| 163 | enum class VibrationDeviceType : u32 { | 164 | enum class VibrationDeviceType : u32 { |
| 164 | Unknown = 0, | 165 | Unknown = 0, |
diff --git a/src/core/hle/service/ngct/ngct.cpp b/src/core/hle/service/ngct/ngct.cpp index deb3abb28..8ec7d5266 100644 --- a/src/core/hle/service/ngct/ngct.cpp +++ b/src/core/hle/service/ngct/ngct.cpp | |||
| @@ -15,7 +15,7 @@ public: | |||
| 15 | explicit IService(Core::System& system_) : ServiceFramework{system_, "ngct:u"} { | 15 | explicit IService(Core::System& system_) : ServiceFramework{system_, "ngct:u"} { |
| 16 | // clang-format off | 16 | // clang-format off |
| 17 | static const FunctionInfo functions[] = { | 17 | static const FunctionInfo functions[] = { |
| 18 | {0, nullptr, "Match"}, | 18 | {0, &IService::Match, "Match"}, |
| 19 | {1, &IService::Filter, "Filter"}, | 19 | {1, &IService::Filter, "Filter"}, |
| 20 | }; | 20 | }; |
| 21 | // clang-format on | 21 | // clang-format on |
| @@ -24,6 +24,19 @@ public: | |||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | private: | 26 | private: |
| 27 | void Match(Kernel::HLERequestContext& ctx) { | ||
| 28 | const auto buffer = ctx.ReadBuffer(); | ||
| 29 | const auto text = Common::StringFromFixedZeroTerminatedBuffer( | ||
| 30 | reinterpret_cast<const char*>(buffer.data()), buffer.size()); | ||
| 31 | |||
| 32 | LOG_WARNING(Service_NGCT, "(STUBBED) called, text={}", text); | ||
| 33 | |||
| 34 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 35 | rb.Push(ResultSuccess); | ||
| 36 | // Return false since we don't censor anything | ||
| 37 | rb.Push(false); | ||
| 38 | } | ||
| 39 | |||
| 27 | void Filter(Kernel::HLERequestContext& ctx) { | 40 | void Filter(Kernel::HLERequestContext& ctx) { |
| 28 | const auto buffer = ctx.ReadBuffer(); | 41 | const auto buffer = ctx.ReadBuffer(); |
| 29 | const auto text = Common::StringFromFixedZeroTerminatedBuffer( | 42 | const auto text = Common::StringFromFixedZeroTerminatedBuffer( |
diff --git a/src/core/hle/service/npns/npns.cpp b/src/core/hle/service/npns/npns.cpp index e4c703da4..32533cd94 100644 --- a/src/core/hle/service/npns/npns.cpp +++ b/src/core/hle/service/npns/npns.cpp | |||
| @@ -31,6 +31,7 @@ public: | |||
| 31 | {24, nullptr, "DestroyTokenWithApplicationId"}, | 31 | {24, nullptr, "DestroyTokenWithApplicationId"}, |
| 32 | {25, nullptr, "QueryIsTokenValid"}, | 32 | {25, nullptr, "QueryIsTokenValid"}, |
| 33 | {26, nullptr, "ListenToMyApplicationId"}, | 33 | {26, nullptr, "ListenToMyApplicationId"}, |
| 34 | {27, nullptr, "DestroyTokenAll"}, | ||
| 34 | {31, nullptr, "UploadTokenToBaaS"}, | 35 | {31, nullptr, "UploadTokenToBaaS"}, |
| 35 | {32, nullptr, "DestroyTokenForBaaS"}, | 36 | {32, nullptr, "DestroyTokenForBaaS"}, |
| 36 | {33, nullptr, "CreateTokenForBaaS"}, | 37 | {33, nullptr, "CreateTokenForBaaS"}, |
diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp index ce6065db2..789000294 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp | |||
| @@ -16,7 +16,7 @@ namespace Service::Nvidia::Devices { | |||
| 16 | 16 | ||
| 17 | nvdisp_disp0::nvdisp_disp0(Core::System& system_, std::shared_ptr<nvmap> nvmap_dev_) | 17 | nvdisp_disp0::nvdisp_disp0(Core::System& system_, std::shared_ptr<nvmap> nvmap_dev_) |
| 18 | : nvdevice{system_}, nvmap_dev{std::move(nvmap_dev_)} {} | 18 | : nvdevice{system_}, nvmap_dev{std::move(nvmap_dev_)} {} |
| 19 | nvdisp_disp0 ::~nvdisp_disp0() = default; | 19 | nvdisp_disp0::~nvdisp_disp0() = default; |
| 20 | 20 | ||
| 21 | NvResult nvdisp_disp0::Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input, | 21 | NvResult nvdisp_disp0::Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input, |
| 22 | std::vector<u8>& output) { | 22 | std::vector<u8>& output) { |
| @@ -42,15 +42,14 @@ void nvdisp_disp0::OnClose(DeviceFD fd) {} | |||
| 42 | void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u32 height, | 42 | void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u32 height, |
| 43 | u32 stride, NVFlinger::BufferQueue::BufferTransformFlags transform, | 43 | u32 stride, NVFlinger::BufferQueue::BufferTransformFlags transform, |
| 44 | const Common::Rectangle<int>& crop_rect) { | 44 | const Common::Rectangle<int>& crop_rect) { |
| 45 | VAddr addr = nvmap_dev->GetObjectAddress(buffer_handle); | 45 | const VAddr addr = nvmap_dev->GetObjectAddress(buffer_handle); |
| 46 | LOG_TRACE(Service, | 46 | LOG_TRACE(Service, |
| 47 | "Drawing from address {:X} offset {:08X} Width {} Height {} Stride {} Format {}", | 47 | "Drawing from address {:X} offset {:08X} Width {} Height {} Stride {} Format {}", |
| 48 | addr, offset, width, height, stride, format); | 48 | addr, offset, width, height, stride, format); |
| 49 | 49 | ||
| 50 | using PixelFormat = Tegra::FramebufferConfig::PixelFormat; | 50 | const auto pixel_format = static_cast<Tegra::FramebufferConfig::PixelFormat>(format); |
| 51 | const Tegra::FramebufferConfig framebuffer{ | 51 | const Tegra::FramebufferConfig framebuffer{addr, offset, width, height, |
| 52 | addr, offset, width, height, stride, static_cast<PixelFormat>(format), | 52 | stride, pixel_format, transform, crop_rect}; |
| 53 | transform, crop_rect}; | ||
| 54 | 53 | ||
| 55 | system.GetPerfStats().EndSystemFrame(); | 54 | system.GetPerfStats().EndSystemFrame(); |
| 56 | system.GPU().SwapBuffers(&framebuffer); | 55 | system.GPU().SwapBuffers(&framebuffer); |
diff --git a/src/core/hle/service/nvflinger/buffer_queue.cpp b/src/core/hle/service/nvflinger/buffer_queue.cpp index 59ddf6298..b4c3a6099 100644 --- a/src/core/hle/service/nvflinger/buffer_queue.cpp +++ b/src/core/hle/service/nvflinger/buffer_queue.cpp | |||
| @@ -9,17 +9,20 @@ | |||
| 9 | #include "core/core.h" | 9 | #include "core/core.h" |
| 10 | #include "core/hle/kernel/k_writable_event.h" | 10 | #include "core/hle/kernel/k_writable_event.h" |
| 11 | #include "core/hle/kernel/kernel.h" | 11 | #include "core/hle/kernel/kernel.h" |
| 12 | #include "core/hle/service/kernel_helpers.h" | ||
| 12 | #include "core/hle/service/nvflinger/buffer_queue.h" | 13 | #include "core/hle/service/nvflinger/buffer_queue.h" |
| 13 | 14 | ||
| 14 | namespace Service::NVFlinger { | 15 | namespace Service::NVFlinger { |
| 15 | 16 | ||
| 16 | BufferQueue::BufferQueue(Kernel::KernelCore& kernel, u32 id_, u64 layer_id_) | 17 | BufferQueue::BufferQueue(Kernel::KernelCore& kernel, u32 id_, u64 layer_id_, |
| 17 | : id(id_), layer_id(layer_id_), buffer_wait_event{kernel} { | 18 | KernelHelpers::ServiceContext& service_context_) |
| 18 | Kernel::KAutoObject::Create(std::addressof(buffer_wait_event)); | 19 | : id(id_), layer_id(layer_id_), service_context{service_context_} { |
| 19 | buffer_wait_event.Initialize("BufferQueue:WaitEvent"); | 20 | buffer_wait_event = service_context.CreateEvent("BufferQueue:WaitEvent"); |
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | BufferQueue::~BufferQueue() = default; | 23 | BufferQueue::~BufferQueue() { |
| 24 | service_context.CloseEvent(buffer_wait_event); | ||
| 25 | } | ||
| 23 | 26 | ||
| 24 | void BufferQueue::SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer) { | 27 | void BufferQueue::SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer) { |
| 25 | ASSERT(slot < buffer_slots); | 28 | ASSERT(slot < buffer_slots); |
| @@ -41,7 +44,7 @@ void BufferQueue::SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer) | |||
| 41 | .multi_fence = {}, | 44 | .multi_fence = {}, |
| 42 | }; | 45 | }; |
| 43 | 46 | ||
| 44 | buffer_wait_event.GetWritableEvent().Signal(); | 47 | buffer_wait_event->GetWritableEvent().Signal(); |
| 45 | } | 48 | } |
| 46 | 49 | ||
| 47 | std::optional<std::pair<u32, Service::Nvidia::MultiFence*>> BufferQueue::DequeueBuffer(u32 width, | 50 | std::optional<std::pair<u32, Service::Nvidia::MultiFence*>> BufferQueue::DequeueBuffer(u32 width, |
| @@ -119,7 +122,7 @@ void BufferQueue::CancelBuffer(u32 slot, const Service::Nvidia::MultiFence& mult | |||
| 119 | } | 122 | } |
| 120 | free_buffers_condition.notify_one(); | 123 | free_buffers_condition.notify_one(); |
| 121 | 124 | ||
| 122 | buffer_wait_event.GetWritableEvent().Signal(); | 125 | buffer_wait_event->GetWritableEvent().Signal(); |
| 123 | } | 126 | } |
| 124 | 127 | ||
| 125 | std::optional<std::reference_wrapper<const BufferQueue::Buffer>> BufferQueue::AcquireBuffer() { | 128 | std::optional<std::reference_wrapper<const BufferQueue::Buffer>> BufferQueue::AcquireBuffer() { |
| @@ -154,7 +157,7 @@ void BufferQueue::ReleaseBuffer(u32 slot) { | |||
| 154 | } | 157 | } |
| 155 | free_buffers_condition.notify_one(); | 158 | free_buffers_condition.notify_one(); |
| 156 | 159 | ||
| 157 | buffer_wait_event.GetWritableEvent().Signal(); | 160 | buffer_wait_event->GetWritableEvent().Signal(); |
| 158 | } | 161 | } |
| 159 | 162 | ||
| 160 | void BufferQueue::Connect() { | 163 | void BufferQueue::Connect() { |
| @@ -169,7 +172,7 @@ void BufferQueue::Disconnect() { | |||
| 169 | std::unique_lock lock{queue_sequence_mutex}; | 172 | std::unique_lock lock{queue_sequence_mutex}; |
| 170 | queue_sequence.clear(); | 173 | queue_sequence.clear(); |
| 171 | } | 174 | } |
| 172 | buffer_wait_event.GetWritableEvent().Signal(); | 175 | buffer_wait_event->GetWritableEvent().Signal(); |
| 173 | is_connect = false; | 176 | is_connect = false; |
| 174 | free_buffers_condition.notify_one(); | 177 | free_buffers_condition.notify_one(); |
| 175 | } | 178 | } |
| @@ -189,11 +192,11 @@ u32 BufferQueue::Query(QueryType type) { | |||
| 189 | } | 192 | } |
| 190 | 193 | ||
| 191 | Kernel::KWritableEvent& BufferQueue::GetWritableBufferWaitEvent() { | 194 | Kernel::KWritableEvent& BufferQueue::GetWritableBufferWaitEvent() { |
| 192 | return buffer_wait_event.GetWritableEvent(); | 195 | return buffer_wait_event->GetWritableEvent(); |
| 193 | } | 196 | } |
| 194 | 197 | ||
| 195 | Kernel::KReadableEvent& BufferQueue::GetBufferWaitEvent() { | 198 | Kernel::KReadableEvent& BufferQueue::GetBufferWaitEvent() { |
| 196 | return buffer_wait_event.GetReadableEvent(); | 199 | return buffer_wait_event->GetReadableEvent(); |
| 197 | } | 200 | } |
| 198 | 201 | ||
| 199 | } // namespace Service::NVFlinger | 202 | } // namespace Service::NVFlinger |
diff --git a/src/core/hle/service/nvflinger/buffer_queue.h b/src/core/hle/service/nvflinger/buffer_queue.h index 61e337ac5..78de3f354 100644 --- a/src/core/hle/service/nvflinger/buffer_queue.h +++ b/src/core/hle/service/nvflinger/buffer_queue.h | |||
| @@ -24,6 +24,10 @@ class KReadableEvent; | |||
| 24 | class KWritableEvent; | 24 | class KWritableEvent; |
| 25 | } // namespace Kernel | 25 | } // namespace Kernel |
| 26 | 26 | ||
| 27 | namespace Service::KernelHelpers { | ||
| 28 | class ServiceContext; | ||
| 29 | } // namespace Service::KernelHelpers | ||
| 30 | |||
| 27 | namespace Service::NVFlinger { | 31 | namespace Service::NVFlinger { |
| 28 | 32 | ||
| 29 | constexpr u32 buffer_slots = 0x40; | 33 | constexpr u32 buffer_slots = 0x40; |
| @@ -38,7 +42,9 @@ struct IGBPBuffer { | |||
| 38 | u32_le index; | 42 | u32_le index; |
| 39 | INSERT_PADDING_WORDS(3); | 43 | INSERT_PADDING_WORDS(3); |
| 40 | u32_le gpu_buffer_id; | 44 | u32_le gpu_buffer_id; |
| 41 | INSERT_PADDING_WORDS(17); | 45 | INSERT_PADDING_WORDS(6); |
| 46 | u32_le external_format; | ||
| 47 | INSERT_PADDING_WORDS(10); | ||
| 42 | u32_le nvmap_handle; | 48 | u32_le nvmap_handle; |
| 43 | u32_le offset; | 49 | u32_le offset; |
| 44 | INSERT_PADDING_WORDS(60); | 50 | INSERT_PADDING_WORDS(60); |
| @@ -54,7 +60,8 @@ public: | |||
| 54 | NativeWindowFormat = 2, | 60 | NativeWindowFormat = 2, |
| 55 | }; | 61 | }; |
| 56 | 62 | ||
| 57 | explicit BufferQueue(Kernel::KernelCore& kernel, u32 id_, u64 layer_id_); | 63 | explicit BufferQueue(Kernel::KernelCore& kernel, u32 id_, u64 layer_id_, |
| 64 | KernelHelpers::ServiceContext& service_context_); | ||
| 58 | ~BufferQueue(); | 65 | ~BufferQueue(); |
| 59 | 66 | ||
| 60 | enum class BufferTransformFlags : u32 { | 67 | enum class BufferTransformFlags : u32 { |
| @@ -130,12 +137,14 @@ private: | |||
| 130 | std::list<u32> free_buffers; | 137 | std::list<u32> free_buffers; |
| 131 | std::array<Buffer, buffer_slots> buffers; | 138 | std::array<Buffer, buffer_slots> buffers; |
| 132 | std::list<u32> queue_sequence; | 139 | std::list<u32> queue_sequence; |
| 133 | Kernel::KEvent buffer_wait_event; | 140 | Kernel::KEvent* buffer_wait_event{}; |
| 134 | 141 | ||
| 135 | std::mutex free_buffers_mutex; | 142 | std::mutex free_buffers_mutex; |
| 136 | std::condition_variable free_buffers_condition; | 143 | std::condition_variable free_buffers_condition; |
| 137 | 144 | ||
| 138 | std::mutex queue_sequence_mutex; | 145 | std::mutex queue_sequence_mutex; |
| 146 | |||
| 147 | KernelHelpers::ServiceContext& service_context; | ||
| 139 | }; | 148 | }; |
| 140 | 149 | ||
| 141 | } // namespace Service::NVFlinger | 150 | } // namespace Service::NVFlinger |
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index 32d4e360a..3ead813b0 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp | |||
| @@ -147,7 +147,7 @@ std::optional<u64> NVFlinger::CreateLayer(u64 display_id) { | |||
| 147 | void NVFlinger::CreateLayerAtId(VI::Display& display, u64 layer_id) { | 147 | void NVFlinger::CreateLayerAtId(VI::Display& display, u64 layer_id) { |
| 148 | const u32 buffer_queue_id = next_buffer_queue_id++; | 148 | const u32 buffer_queue_id = next_buffer_queue_id++; |
| 149 | buffer_queues.emplace_back( | 149 | buffer_queues.emplace_back( |
| 150 | std::make_unique<BufferQueue>(system.Kernel(), buffer_queue_id, layer_id)); | 150 | std::make_unique<BufferQueue>(system.Kernel(), buffer_queue_id, layer_id, service_context)); |
| 151 | display.CreateLayer(layer_id, *buffer_queues.back()); | 151 | display.CreateLayer(layer_id, *buffer_queues.back()); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| @@ -298,7 +298,7 @@ void NVFlinger::Compose() { | |||
| 298 | auto nvdisp = nvdrv->GetDevice<Nvidia::Devices::nvdisp_disp0>("/dev/nvdisp_disp0"); | 298 | auto nvdisp = nvdrv->GetDevice<Nvidia::Devices::nvdisp_disp0>("/dev/nvdisp_disp0"); |
| 299 | ASSERT(nvdisp); | 299 | ASSERT(nvdisp); |
| 300 | 300 | ||
| 301 | nvdisp->flip(igbp_buffer.gpu_buffer_id, igbp_buffer.offset, igbp_buffer.format, | 301 | nvdisp->flip(igbp_buffer.gpu_buffer_id, igbp_buffer.offset, igbp_buffer.external_format, |
| 302 | igbp_buffer.width, igbp_buffer.height, igbp_buffer.stride, | 302 | igbp_buffer.width, igbp_buffer.height, igbp_buffer.stride, |
| 303 | buffer->get().transform, buffer->get().crop_rect); | 303 | buffer->get().transform, buffer->get().crop_rect); |
| 304 | 304 | ||
diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp index 7d85ecb6a..b9e765f1d 100644 --- a/src/core/hle/service/sockets/bsd.cpp +++ b/src/core/hle/service/sockets/bsd.cpp | |||
| @@ -415,6 +415,18 @@ void BSD::Write(Kernel::HLERequestContext& ctx) { | |||
| 415 | }); | 415 | }); |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | void BSD::Read(Kernel::HLERequestContext& ctx) { | ||
| 419 | IPC::RequestParser rp{ctx}; | ||
| 420 | const s32 fd = rp.Pop<s32>(); | ||
| 421 | |||
| 422 | LOG_WARNING(Service, "(STUBBED) called. fd={} len={}", fd, ctx.GetWriteBufferSize()); | ||
| 423 | |||
| 424 | IPC::ResponseBuilder rb{ctx, 4}; | ||
| 425 | rb.Push(ResultSuccess); | ||
| 426 | rb.Push<u32>(0); // ret | ||
| 427 | rb.Push<u32>(0); // bsd errno | ||
| 428 | } | ||
| 429 | |||
| 418 | void BSD::Close(Kernel::HLERequestContext& ctx) { | 430 | void BSD::Close(Kernel::HLERequestContext& ctx) { |
| 419 | IPC::RequestParser rp{ctx}; | 431 | IPC::RequestParser rp{ctx}; |
| 420 | const s32 fd = rp.Pop<s32>(); | 432 | const s32 fd = rp.Pop<s32>(); |
| @@ -855,7 +867,7 @@ BSD::BSD(Core::System& system_, const char* name) : ServiceFramework{system_, na | |||
| 855 | {22, &BSD::Shutdown, "Shutdown"}, | 867 | {22, &BSD::Shutdown, "Shutdown"}, |
| 856 | {23, nullptr, "ShutdownAllSockets"}, | 868 | {23, nullptr, "ShutdownAllSockets"}, |
| 857 | {24, &BSD::Write, "Write"}, | 869 | {24, &BSD::Write, "Write"}, |
| 858 | {25, nullptr, "Read"}, | 870 | {25, &BSD::Read, "Read"}, |
| 859 | {26, &BSD::Close, "Close"}, | 871 | {26, &BSD::Close, "Close"}, |
| 860 | {27, nullptr, "DuplicateSocket"}, | 872 | {27, nullptr, "DuplicateSocket"}, |
| 861 | {28, nullptr, "GetResourceStatistics"}, | 873 | {28, nullptr, "GetResourceStatistics"}, |
diff --git a/src/core/hle/service/sockets/bsd.h b/src/core/hle/service/sockets/bsd.h index 1d2df9c61..d68beef5c 100644 --- a/src/core/hle/service/sockets/bsd.h +++ b/src/core/hle/service/sockets/bsd.h | |||
| @@ -135,6 +135,7 @@ private: | |||
| 135 | void Send(Kernel::HLERequestContext& ctx); | 135 | void Send(Kernel::HLERequestContext& ctx); |
| 136 | void SendTo(Kernel::HLERequestContext& ctx); | 136 | void SendTo(Kernel::HLERequestContext& ctx); |
| 137 | void Write(Kernel::HLERequestContext& ctx); | 137 | void Write(Kernel::HLERequestContext& ctx); |
| 138 | void Read(Kernel::HLERequestContext& ctx); | ||
| 138 | void Close(Kernel::HLERequestContext& ctx); | 139 | void Close(Kernel::HLERequestContext& ctx); |
| 139 | void EventFd(Kernel::HLERequestContext& ctx); | 140 | void EventFd(Kernel::HLERequestContext& ctx); |
| 140 | 141 | ||
diff --git a/src/core/hle/service/time/system_clock_core.cpp b/src/core/hle/service/time/system_clock_core.cpp index bd334bbef..5c2354cdd 100644 --- a/src/core/hle/service/time/system_clock_core.cpp +++ b/src/core/hle/service/time/system_clock_core.cpp | |||
| @@ -13,7 +13,7 @@ SystemClockCore::SystemClockCore(SteadyClockCore& steady_clock_core_) | |||
| 13 | context.steady_time_point.clock_source_id = steady_clock_core.GetClockSourceId(); | 13 | context.steady_time_point.clock_source_id = steady_clock_core.GetClockSourceId(); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | SystemClockCore ::~SystemClockCore() = default; | 16 | SystemClockCore::~SystemClockCore() = default; |
| 17 | 17 | ||
| 18 | ResultCode SystemClockCore::GetCurrentTime(Core::System& system, s64& posix_time) const { | 18 | ResultCode SystemClockCore::GetCurrentTime(Core::System& system, s64& posix_time) const { |
| 19 | posix_time = 0; | 19 | posix_time = 0; |
diff --git a/src/core/hle/service/time/time_zone_service.cpp b/src/core/hle/service/time/time_zone_service.cpp index 5c3108768..3871e7316 100644 --- a/src/core/hle/service/time/time_zone_service.cpp +++ b/src/core/hle/service/time/time_zone_service.cpp | |||
| @@ -10,8 +10,8 @@ | |||
| 10 | 10 | ||
| 11 | namespace Service::Time { | 11 | namespace Service::Time { |
| 12 | 12 | ||
| 13 | ITimeZoneService ::ITimeZoneService(Core::System& system_, | 13 | ITimeZoneService::ITimeZoneService(Core::System& system_, |
| 14 | TimeZone::TimeZoneContentManager& time_zone_manager_) | 14 | TimeZone::TimeZoneContentManager& time_zone_manager_) |
| 15 | : ServiceFramework{system_, "ITimeZoneService"}, time_zone_content_manager{time_zone_manager_} { | 15 | : ServiceFramework{system_, "ITimeZoneService"}, time_zone_content_manager{time_zone_manager_} { |
| 16 | static const FunctionInfo functions[] = { | 16 | static const FunctionInfo functions[] = { |
| 17 | {0, &ITimeZoneService::GetDeviceLocationName, "GetDeviceLocationName"}, | 17 | {0, &ITimeZoneService::GetDeviceLocationName, "GetDeviceLocationName"}, |
diff --git a/src/core/hle/service/usb/usb.cpp b/src/core/hle/service/usb/usb.cpp index 7f436c3bb..2ee103b37 100644 --- a/src/core/hle/service/usb/usb.cpp +++ b/src/core/hle/service/usb/usb.cpp | |||
| @@ -97,7 +97,7 @@ public: | |||
| 97 | {3, nullptr, "GetAlternateInterface"}, | 97 | {3, nullptr, "GetAlternateInterface"}, |
| 98 | {4, nullptr, "GetCurrentFrame"}, | 98 | {4, nullptr, "GetCurrentFrame"}, |
| 99 | {5, nullptr, "CtrlXferAsync"}, | 99 | {5, nullptr, "CtrlXferAsync"}, |
| 100 | {6, nullptr, "Unknown6"}, | 100 | {6, nullptr, "GetCtrlXferCompletionEvent"}, |
| 101 | {7, nullptr, "GetCtrlXferReport"}, | 101 | {7, nullptr, "GetCtrlXferReport"}, |
| 102 | {8, nullptr, "ResetDevice"}, | 102 | {8, nullptr, "ResetDevice"}, |
| 103 | {9, nullptr, "OpenUsbEp"}, | 103 | {9, nullptr, "OpenUsbEp"}, |
| @@ -183,8 +183,8 @@ public: | |||
| 183 | {4, nullptr, "GetHostPdcFirmwareRevision"}, | 183 | {4, nullptr, "GetHostPdcFirmwareRevision"}, |
| 184 | {5, nullptr, "GetHostPdcManufactureId"}, | 184 | {5, nullptr, "GetHostPdcManufactureId"}, |
| 185 | {6, nullptr, "GetHostPdcDeviceId"}, | 185 | {6, nullptr, "GetHostPdcDeviceId"}, |
| 186 | {7, nullptr, "AwakeCradle"}, | 186 | {7, nullptr, "EnableCradleRecovery"}, |
| 187 | {8, nullptr, "SleepCradle"}, | 187 | {8, nullptr, "DisableCradleRecovery"}, |
| 188 | }; | 188 | }; |
| 189 | // clang-format on | 189 | // clang-format on |
| 190 | 190 | ||
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 8e8fc40ca..be3d52d54 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp | |||
| @@ -831,6 +831,7 @@ public: | |||
| 831 | {6010, nullptr, "GetLayerPresentationAllFencesExpiredEvent"}, | 831 | {6010, nullptr, "GetLayerPresentationAllFencesExpiredEvent"}, |
| 832 | {6011, nullptr, "EnableLayerAutoClearTransitionBuffer"}, | 832 | {6011, nullptr, "EnableLayerAutoClearTransitionBuffer"}, |
| 833 | {6012, nullptr, "DisableLayerAutoClearTransitionBuffer"}, | 833 | {6012, nullptr, "DisableLayerAutoClearTransitionBuffer"}, |
| 834 | {6013, nullptr, "SetLayerOpacity"}, | ||
| 834 | {7000, nullptr, "SetContentVisibility"}, | 835 | {7000, nullptr, "SetContentVisibility"}, |
| 835 | {8000, nullptr, "SetConductorLayer"}, | 836 | {8000, nullptr, "SetConductorLayer"}, |
| 836 | {8001, nullptr, "SetTimestampTracking"}, | 837 | {8001, nullptr, "SetTimestampTracking"}, |
diff --git a/src/core/network/network.cpp b/src/core/network/network.cpp index 4732d4485..72eea52f0 100644 --- a/src/core/network/network.cpp +++ b/src/core/network/network.cpp | |||
| @@ -7,7 +7,8 @@ | |||
| 7 | #include <limits> | 7 | #include <limits> |
| 8 | #include <utility> | 8 | #include <utility> |
| 9 | #include <vector> | 9 | #include <vector> |
| 10 | #include "common/common_funcs.h" | 10 | |
| 11 | #include "common/error.h" | ||
| 11 | 12 | ||
| 12 | #ifdef _WIN32 | 13 | #ifdef _WIN32 |
| 13 | #include <winsock2.h> | 14 | #include <winsock2.h> |
| @@ -223,7 +224,7 @@ Errno GetAndLogLastError() { | |||
| 223 | if (err == Errno::AGAIN) { | 224 | if (err == Errno::AGAIN) { |
| 224 | return err; | 225 | return err; |
| 225 | } | 226 | } |
| 226 | LOG_ERROR(Network, "Socket operation error: {}", NativeErrorToString(e)); | 227 | LOG_ERROR(Network, "Socket operation error: {}", Common::NativeErrorToString(e)); |
| 227 | return err; | 228 | return err; |
| 228 | } | 229 | } |
| 229 | 230 | ||
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 5a8cfd301..191475f71 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp | |||
| @@ -72,6 +72,18 @@ static const char* TranslateGPUAccuracyLevel(Settings::GPUAccuracy backend) { | |||
| 72 | return "Unknown"; | 72 | return "Unknown"; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | static const char* TranslateNvdecEmulation(Settings::NvdecEmulation backend) { | ||
| 76 | switch (backend) { | ||
| 77 | case Settings::NvdecEmulation::Off: | ||
| 78 | return "Off"; | ||
| 79 | case Settings::NvdecEmulation::CPU: | ||
| 80 | return "CPU"; | ||
| 81 | case Settings::NvdecEmulation::GPU: | ||
| 82 | return "GPU"; | ||
| 83 | } | ||
| 84 | return "Unknown"; | ||
| 85 | } | ||
| 86 | |||
| 75 | u64 GetTelemetryId() { | 87 | u64 GetTelemetryId() { |
| 76 | u64 telemetry_id{}; | 88 | u64 telemetry_id{}; |
| 77 | const auto filename = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "telemetry_id"; | 89 | const auto filename = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "telemetry_id"; |
| @@ -214,8 +226,6 @@ void TelemetrySession::AddInitialInfo(Loader::AppLoader& app_loader, | |||
| 214 | // Log user configuration information | 226 | // Log user configuration information |
| 215 | constexpr auto field_type = Telemetry::FieldType::UserConfig; | 227 | constexpr auto field_type = Telemetry::FieldType::UserConfig; |
| 216 | AddField(field_type, "Audio_SinkId", Settings::values.sink_id.GetValue()); | 228 | AddField(field_type, "Audio_SinkId", Settings::values.sink_id.GetValue()); |
| 217 | AddField(field_type, "Audio_EnableAudioStretching", | ||
| 218 | Settings::values.enable_audio_stretching.GetValue()); | ||
| 219 | AddField(field_type, "Core_UseMultiCore", Settings::values.use_multi_core.GetValue()); | 229 | AddField(field_type, "Core_UseMultiCore", Settings::values.use_multi_core.GetValue()); |
| 220 | AddField(field_type, "Renderer_Backend", | 230 | AddField(field_type, "Renderer_Backend", |
| 221 | TranslateRenderer(Settings::values.renderer_backend.GetValue())); | 231 | TranslateRenderer(Settings::values.renderer_backend.GetValue())); |
| @@ -229,8 +239,8 @@ void TelemetrySession::AddInitialInfo(Loader::AppLoader& app_loader, | |||
| 229 | TranslateGPUAccuracyLevel(Settings::values.gpu_accuracy.GetValue())); | 239 | TranslateGPUAccuracyLevel(Settings::values.gpu_accuracy.GetValue())); |
| 230 | AddField(field_type, "Renderer_UseAsynchronousGpuEmulation", | 240 | AddField(field_type, "Renderer_UseAsynchronousGpuEmulation", |
| 231 | Settings::values.use_asynchronous_gpu_emulation.GetValue()); | 241 | Settings::values.use_asynchronous_gpu_emulation.GetValue()); |
| 232 | AddField(field_type, "Renderer_UseNvdecEmulation", | 242 | AddField(field_type, "Renderer_NvdecEmulation", |
| 233 | Settings::values.use_nvdec_emulation.GetValue()); | 243 | TranslateNvdecEmulation(Settings::values.nvdec_emulation.GetValue())); |
| 234 | AddField(field_type, "Renderer_AccelerateASTC", Settings::values.accelerate_astc.GetValue()); | 244 | AddField(field_type, "Renderer_AccelerateASTC", Settings::values.accelerate_astc.GetValue()); |
| 235 | AddField(field_type, "Renderer_UseVsync", Settings::values.use_vsync.GetValue()); | 245 | AddField(field_type, "Renderer_UseVsync", Settings::values.use_vsync.GetValue()); |
| 236 | AddField(field_type, "Renderer_ShaderBackend", | 246 | AddField(field_type, "Renderer_ShaderBackend", |
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index c4283a952..dd13d948f 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -21,6 +21,10 @@ add_library(input_common STATIC | |||
| 21 | mouse/mouse_poller.h | 21 | mouse/mouse_poller.h |
| 22 | sdl/sdl.cpp | 22 | sdl/sdl.cpp |
| 23 | sdl/sdl.h | 23 | sdl/sdl.h |
| 24 | tas/tas_input.cpp | ||
| 25 | tas/tas_input.h | ||
| 26 | tas/tas_poller.cpp | ||
| 27 | tas/tas_poller.h | ||
| 24 | udp/client.cpp | 28 | udp/client.cpp |
| 25 | udp/client.h | 29 | udp/client.h |
| 26 | udp/protocol.cpp | 30 | udp/protocol.cpp |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index ff23230f0..f3907c65a 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | #include <thread> | 6 | #include <thread> |
| 7 | #include "common/param_package.h" | 7 | #include "common/param_package.h" |
| 8 | #include "common/settings.h" | ||
| 8 | #include "input_common/analog_from_button.h" | 9 | #include "input_common/analog_from_button.h" |
| 9 | #include "input_common/gcadapter/gc_adapter.h" | 10 | #include "input_common/gcadapter/gc_adapter.h" |
| 10 | #include "input_common/gcadapter/gc_poller.h" | 11 | #include "input_common/gcadapter/gc_poller.h" |
| @@ -13,6 +14,8 @@ | |||
| 13 | #include "input_common/motion_from_button.h" | 14 | #include "input_common/motion_from_button.h" |
| 14 | #include "input_common/mouse/mouse_input.h" | 15 | #include "input_common/mouse/mouse_input.h" |
| 15 | #include "input_common/mouse/mouse_poller.h" | 16 | #include "input_common/mouse/mouse_poller.h" |
| 17 | #include "input_common/tas/tas_input.h" | ||
| 18 | #include "input_common/tas/tas_poller.h" | ||
| 16 | #include "input_common/touch_from_button.h" | 19 | #include "input_common/touch_from_button.h" |
| 17 | #include "input_common/udp/client.h" | 20 | #include "input_common/udp/client.h" |
| 18 | #include "input_common/udp/udp.h" | 21 | #include "input_common/udp/udp.h" |
| @@ -60,6 +63,12 @@ struct InputSubsystem::Impl { | |||
| 60 | Input::RegisterFactory<Input::MotionDevice>("mouse", mousemotion); | 63 | Input::RegisterFactory<Input::MotionDevice>("mouse", mousemotion); |
| 61 | mousetouch = std::make_shared<MouseTouchFactory>(mouse); | 64 | mousetouch = std::make_shared<MouseTouchFactory>(mouse); |
| 62 | Input::RegisterFactory<Input::TouchDevice>("mouse", mousetouch); | 65 | Input::RegisterFactory<Input::TouchDevice>("mouse", mousetouch); |
| 66 | |||
| 67 | tas = std::make_shared<TasInput::Tas>(); | ||
| 68 | tasbuttons = std::make_shared<TasButtonFactory>(tas); | ||
| 69 | Input::RegisterFactory<Input::ButtonDevice>("tas", tasbuttons); | ||
| 70 | tasanalog = std::make_shared<TasAnalogFactory>(tas); | ||
| 71 | Input::RegisterFactory<Input::AnalogDevice>("tas", tasanalog); | ||
| 63 | } | 72 | } |
| 64 | 73 | ||
| 65 | void Shutdown() { | 74 | void Shutdown() { |
| @@ -94,6 +103,12 @@ struct InputSubsystem::Impl { | |||
| 94 | mouseanalog.reset(); | 103 | mouseanalog.reset(); |
| 95 | mousemotion.reset(); | 104 | mousemotion.reset(); |
| 96 | mousetouch.reset(); | 105 | mousetouch.reset(); |
| 106 | |||
| 107 | Input::UnregisterFactory<Input::ButtonDevice>("tas"); | ||
| 108 | Input::UnregisterFactory<Input::AnalogDevice>("tas"); | ||
| 109 | |||
| 110 | tasbuttons.reset(); | ||
| 111 | tasanalog.reset(); | ||
| 97 | } | 112 | } |
| 98 | 113 | ||
| 99 | [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { | 114 | [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { |
| @@ -101,6 +116,10 @@ struct InputSubsystem::Impl { | |||
| 101 | Common::ParamPackage{{"display", "Any"}, {"class", "any"}}, | 116 | Common::ParamPackage{{"display", "Any"}, {"class", "any"}}, |
| 102 | Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "keyboard"}}, | 117 | Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "keyboard"}}, |
| 103 | }; | 118 | }; |
| 119 | if (Settings::values.tas_enable) { | ||
| 120 | devices.emplace_back( | ||
| 121 | Common::ParamPackage{{"display", "TAS Controller"}, {"class", "tas"}}); | ||
| 122 | } | ||
| 104 | #ifdef HAVE_SDL2 | 123 | #ifdef HAVE_SDL2 |
| 105 | auto sdl_devices = sdl->GetInputDevices(); | 124 | auto sdl_devices = sdl->GetInputDevices(); |
| 106 | devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end()); | 125 | devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end()); |
| @@ -120,6 +139,9 @@ struct InputSubsystem::Impl { | |||
| 120 | if (params.Get("class", "") == "gcpad") { | 139 | if (params.Get("class", "") == "gcpad") { |
| 121 | return gcadapter->GetAnalogMappingForDevice(params); | 140 | return gcadapter->GetAnalogMappingForDevice(params); |
| 122 | } | 141 | } |
| 142 | if (params.Get("class", "") == "tas") { | ||
| 143 | return tas->GetAnalogMappingForDevice(params); | ||
| 144 | } | ||
| 123 | #ifdef HAVE_SDL2 | 145 | #ifdef HAVE_SDL2 |
| 124 | if (params.Get("class", "") == "sdl") { | 146 | if (params.Get("class", "") == "sdl") { |
| 125 | return sdl->GetAnalogMappingForDevice(params); | 147 | return sdl->GetAnalogMappingForDevice(params); |
| @@ -136,6 +158,9 @@ struct InputSubsystem::Impl { | |||
| 136 | if (params.Get("class", "") == "gcpad") { | 158 | if (params.Get("class", "") == "gcpad") { |
| 137 | return gcadapter->GetButtonMappingForDevice(params); | 159 | return gcadapter->GetButtonMappingForDevice(params); |
| 138 | } | 160 | } |
| 161 | if (params.Get("class", "") == "tas") { | ||
| 162 | return tas->GetButtonMappingForDevice(params); | ||
| 163 | } | ||
| 139 | #ifdef HAVE_SDL2 | 164 | #ifdef HAVE_SDL2 |
| 140 | if (params.Get("class", "") == "sdl") { | 165 | if (params.Get("class", "") == "sdl") { |
| 141 | return sdl->GetButtonMappingForDevice(params); | 166 | return sdl->GetButtonMappingForDevice(params); |
| @@ -174,9 +199,12 @@ struct InputSubsystem::Impl { | |||
| 174 | std::shared_ptr<MouseAnalogFactory> mouseanalog; | 199 | std::shared_ptr<MouseAnalogFactory> mouseanalog; |
| 175 | std::shared_ptr<MouseMotionFactory> mousemotion; | 200 | std::shared_ptr<MouseMotionFactory> mousemotion; |
| 176 | std::shared_ptr<MouseTouchFactory> mousetouch; | 201 | std::shared_ptr<MouseTouchFactory> mousetouch; |
| 202 | std::shared_ptr<TasButtonFactory> tasbuttons; | ||
| 203 | std::shared_ptr<TasAnalogFactory> tasanalog; | ||
| 177 | std::shared_ptr<CemuhookUDP::Client> udp; | 204 | std::shared_ptr<CemuhookUDP::Client> udp; |
| 178 | std::shared_ptr<GCAdapter::Adapter> gcadapter; | 205 | std::shared_ptr<GCAdapter::Adapter> gcadapter; |
| 179 | std::shared_ptr<MouseInput::Mouse> mouse; | 206 | std::shared_ptr<MouseInput::Mouse> mouse; |
| 207 | std::shared_ptr<TasInput::Tas> tas; | ||
| 180 | }; | 208 | }; |
| 181 | 209 | ||
| 182 | InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} | 210 | InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} |
| @@ -207,6 +235,14 @@ const MouseInput::Mouse* InputSubsystem::GetMouse() const { | |||
| 207 | return impl->mouse.get(); | 235 | return impl->mouse.get(); |
| 208 | } | 236 | } |
| 209 | 237 | ||
| 238 | TasInput::Tas* InputSubsystem::GetTas() { | ||
| 239 | return impl->tas.get(); | ||
| 240 | } | ||
| 241 | |||
| 242 | const TasInput::Tas* InputSubsystem::GetTas() const { | ||
| 243 | return impl->tas.get(); | ||
| 244 | } | ||
| 245 | |||
| 210 | std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { | 246 | std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { |
| 211 | return impl->GetInputDevices(); | 247 | return impl->GetInputDevices(); |
| 212 | } | 248 | } |
| @@ -287,6 +323,22 @@ const MouseTouchFactory* InputSubsystem::GetMouseTouch() const { | |||
| 287 | return impl->mousetouch.get(); | 323 | return impl->mousetouch.get(); |
| 288 | } | 324 | } |
| 289 | 325 | ||
| 326 | TasButtonFactory* InputSubsystem::GetTasButtons() { | ||
| 327 | return impl->tasbuttons.get(); | ||
| 328 | } | ||
| 329 | |||
| 330 | const TasButtonFactory* InputSubsystem::GetTasButtons() const { | ||
| 331 | return impl->tasbuttons.get(); | ||
| 332 | } | ||
| 333 | |||
| 334 | TasAnalogFactory* InputSubsystem::GetTasAnalogs() { | ||
| 335 | return impl->tasanalog.get(); | ||
| 336 | } | ||
| 337 | |||
| 338 | const TasAnalogFactory* InputSubsystem::GetTasAnalogs() const { | ||
| 339 | return impl->tasanalog.get(); | ||
| 340 | } | ||
| 341 | |||
| 290 | void InputSubsystem::ReloadInputDevices() { | 342 | void InputSubsystem::ReloadInputDevices() { |
| 291 | if (!impl->udp) { | 343 | if (!impl->udp) { |
| 292 | return; | 344 | return; |
| @@ -294,8 +346,8 @@ void InputSubsystem::ReloadInputDevices() { | |||
| 294 | impl->udp->ReloadSockets(); | 346 | impl->udp->ReloadSockets(); |
| 295 | } | 347 | } |
| 296 | 348 | ||
| 297 | std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers([ | 349 | std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers( |
| 298 | [maybe_unused]] Polling::DeviceType type) const { | 350 | [[maybe_unused]] Polling::DeviceType type) const { |
| 299 | #ifdef HAVE_SDL2 | 351 | #ifdef HAVE_SDL2 |
| 300 | return impl->sdl->GetPollers(type); | 352 | return impl->sdl->GetPollers(type); |
| 301 | #else | 353 | #else |
diff --git a/src/input_common/main.h b/src/input_common/main.h index 5d6f26385..6390d3f09 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -29,6 +29,10 @@ namespace MouseInput { | |||
| 29 | class Mouse; | 29 | class Mouse; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | namespace TasInput { | ||
| 33 | class Tas; | ||
| 34 | } | ||
| 35 | |||
| 32 | namespace InputCommon { | 36 | namespace InputCommon { |
| 33 | namespace Polling { | 37 | namespace Polling { |
| 34 | 38 | ||
| @@ -64,6 +68,8 @@ class MouseButtonFactory; | |||
| 64 | class MouseAnalogFactory; | 68 | class MouseAnalogFactory; |
| 65 | class MouseMotionFactory; | 69 | class MouseMotionFactory; |
| 66 | class MouseTouchFactory; | 70 | class MouseTouchFactory; |
| 71 | class TasButtonFactory; | ||
| 72 | class TasAnalogFactory; | ||
| 67 | class Keyboard; | 73 | class Keyboard; |
| 68 | 74 | ||
| 69 | /** | 75 | /** |
| @@ -103,6 +109,11 @@ public: | |||
| 103 | /// Retrieves the underlying mouse device. | 109 | /// Retrieves the underlying mouse device. |
| 104 | [[nodiscard]] const MouseInput::Mouse* GetMouse() const; | 110 | [[nodiscard]] const MouseInput::Mouse* GetMouse() const; |
| 105 | 111 | ||
| 112 | /// Retrieves the underlying tas device. | ||
| 113 | [[nodiscard]] TasInput::Tas* GetTas(); | ||
| 114 | |||
| 115 | /// Retrieves the underlying tas device. | ||
| 116 | [[nodiscard]] const TasInput::Tas* GetTas() const; | ||
| 106 | /** | 117 | /** |
| 107 | * Returns all available input devices that this Factory can create a new device with. | 118 | * Returns all available input devices that this Factory can create a new device with. |
| 108 | * Each returned ParamPackage should have a `display` field used for display, a class field for | 119 | * Each returned ParamPackage should have a `display` field used for display, a class field for |
| @@ -144,30 +155,42 @@ public: | |||
| 144 | /// Retrieves the underlying udp touch handler. | 155 | /// Retrieves the underlying udp touch handler. |
| 145 | [[nodiscard]] const UDPTouchFactory* GetUDPTouch() const; | 156 | [[nodiscard]] const UDPTouchFactory* GetUDPTouch() const; |
| 146 | 157 | ||
| 147 | /// Retrieves the underlying GameCube button handler. | 158 | /// Retrieves the underlying mouse button handler. |
| 148 | [[nodiscard]] MouseButtonFactory* GetMouseButtons(); | 159 | [[nodiscard]] MouseButtonFactory* GetMouseButtons(); |
| 149 | 160 | ||
| 150 | /// Retrieves the underlying GameCube button handler. | 161 | /// Retrieves the underlying mouse button handler. |
| 151 | [[nodiscard]] const MouseButtonFactory* GetMouseButtons() const; | 162 | [[nodiscard]] const MouseButtonFactory* GetMouseButtons() const; |
| 152 | 163 | ||
| 153 | /// Retrieves the underlying udp touch handler. | 164 | /// Retrieves the underlying mouse analog handler. |
| 154 | [[nodiscard]] MouseAnalogFactory* GetMouseAnalogs(); | 165 | [[nodiscard]] MouseAnalogFactory* GetMouseAnalogs(); |
| 155 | 166 | ||
| 156 | /// Retrieves the underlying udp touch handler. | 167 | /// Retrieves the underlying mouse analog handler. |
| 157 | [[nodiscard]] const MouseAnalogFactory* GetMouseAnalogs() const; | 168 | [[nodiscard]] const MouseAnalogFactory* GetMouseAnalogs() const; |
| 158 | 169 | ||
| 159 | /// Retrieves the underlying udp motion handler. | 170 | /// Retrieves the underlying mouse motion handler. |
| 160 | [[nodiscard]] MouseMotionFactory* GetMouseMotions(); | 171 | [[nodiscard]] MouseMotionFactory* GetMouseMotions(); |
| 161 | 172 | ||
| 162 | /// Retrieves the underlying udp motion handler. | 173 | /// Retrieves the underlying mouse motion handler. |
| 163 | [[nodiscard]] const MouseMotionFactory* GetMouseMotions() const; | 174 | [[nodiscard]] const MouseMotionFactory* GetMouseMotions() const; |
| 164 | 175 | ||
| 165 | /// Retrieves the underlying udp touch handler. | 176 | /// Retrieves the underlying mouse touch handler. |
| 166 | [[nodiscard]] MouseTouchFactory* GetMouseTouch(); | 177 | [[nodiscard]] MouseTouchFactory* GetMouseTouch(); |
| 167 | 178 | ||
| 168 | /// Retrieves the underlying udp touch handler. | 179 | /// Retrieves the underlying mouse touch handler. |
| 169 | [[nodiscard]] const MouseTouchFactory* GetMouseTouch() const; | 180 | [[nodiscard]] const MouseTouchFactory* GetMouseTouch() const; |
| 170 | 181 | ||
| 182 | /// Retrieves the underlying tas button handler. | ||
| 183 | [[nodiscard]] TasButtonFactory* GetTasButtons(); | ||
| 184 | |||
| 185 | /// Retrieves the underlying tas button handler. | ||
| 186 | [[nodiscard]] const TasButtonFactory* GetTasButtons() const; | ||
| 187 | |||
| 188 | /// Retrieves the underlying tas analogs handler. | ||
| 189 | [[nodiscard]] TasAnalogFactory* GetTasAnalogs(); | ||
| 190 | |||
| 191 | /// Retrieves the underlying tas analogs handler. | ||
| 192 | [[nodiscard]] const TasAnalogFactory* GetTasAnalogs() const; | ||
| 193 | |||
| 171 | /// Reloads the input devices | 194 | /// Reloads the input devices |
| 172 | void ReloadInputDevices(); | 195 | void ReloadInputDevices(); |
| 173 | 196 | ||
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 8723acc31..ab6211b29 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | #include "common/logging/log.h" | 21 | #include "common/logging/log.h" |
| 22 | #include "common/math_util.h" | 22 | #include "common/math_util.h" |
| 23 | #include "common/param_package.h" | 23 | #include "common/param_package.h" |
| 24 | #include "common/settings_input.h" | 24 | #include "common/settings.h" |
| 25 | #include "common/threadsafe_queue.h" | 25 | #include "common/threadsafe_queue.h" |
| 26 | #include "core/frontend/input.h" | 26 | #include "core/frontend/input.h" |
| 27 | #include "input_common/motion_input.h" | 27 | #include "input_common/motion_input.h" |
| @@ -903,8 +903,10 @@ SDLState::SDLState() { | |||
| 903 | RegisterFactory<VibrationDevice>("sdl", vibration_factory); | 903 | RegisterFactory<VibrationDevice>("sdl", vibration_factory); |
| 904 | RegisterFactory<MotionDevice>("sdl", motion_factory); | 904 | RegisterFactory<MotionDevice>("sdl", motion_factory); |
| 905 | 905 | ||
| 906 | // Disable raw input. When enabled this setting causes SDL to die when a web applet opens | 906 | if (!Settings::values.enable_raw_input) { |
| 907 | SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0"); | 907 | // Disable raw input. When enabled this setting causes SDL to die when a web applet opens |
| 908 | SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0"); | ||
| 909 | } | ||
| 908 | 910 | ||
| 909 | // Enable HIDAPI rumble. This prevents SDL from disabling motion on PS4 and PS5 controllers | 911 | // Enable HIDAPI rumble. This prevents SDL from disabling motion on PS4 and PS5 controllers |
| 910 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); | 912 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); |
| @@ -912,10 +914,10 @@ SDLState::SDLState() { | |||
| 912 | 914 | ||
| 913 | // Tell SDL2 to use the hidapi driver. This will allow joycons to be detected as a | 915 | // Tell SDL2 to use the hidapi driver. This will allow joycons to be detected as a |
| 914 | // GameController and not a generic one | 916 | // GameController and not a generic one |
| 915 | SDL_SetHint("SDL_JOYSTICK_HIDAPI_JOY_CONS", "1"); | 917 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1"); |
| 916 | 918 | ||
| 917 | // Turn off Pro controller home led | 919 | // Turn off Pro controller home led |
| 918 | SDL_SetHint("SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED", "0"); | 920 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED, "0"); |
| 919 | 921 | ||
| 920 | // If the frontend is going to manage the event loop, then we don't start one here | 922 | // If the frontend is going to manage the event loop, then we don't start one here |
| 921 | start_thread = SDL_WasInit(SDL_INIT_JOYSTICK) == 0; | 923 | start_thread = SDL_WasInit(SDL_INIT_JOYSTICK) == 0; |
diff --git a/src/input_common/tas/tas_input.cpp b/src/input_common/tas/tas_input.cpp new file mode 100644 index 000000000..1598092b6 --- /dev/null +++ b/src/input_common/tas/tas_input.cpp | |||
| @@ -0,0 +1,455 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2+ | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cstring> | ||
| 6 | #include <regex> | ||
| 7 | |||
| 8 | #include "common/fs/file.h" | ||
| 9 | #include "common/fs/fs_types.h" | ||
| 10 | #include "common/fs/path_util.h" | ||
| 11 | #include "common/logging/log.h" | ||
| 12 | #include "common/settings.h" | ||
| 13 | #include "input_common/tas/tas_input.h" | ||
| 14 | |||
| 15 | namespace TasInput { | ||
| 16 | |||
| 17 | // Supported keywords and buttons from a TAS file | ||
| 18 | constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_button = { | ||
| 19 | std::pair{"KEY_A", TasButton::BUTTON_A}, | ||
| 20 | {"KEY_B", TasButton::BUTTON_B}, | ||
| 21 | {"KEY_X", TasButton::BUTTON_X}, | ||
| 22 | {"KEY_Y", TasButton::BUTTON_Y}, | ||
| 23 | {"KEY_LSTICK", TasButton::STICK_L}, | ||
| 24 | {"KEY_RSTICK", TasButton::STICK_R}, | ||
| 25 | {"KEY_L", TasButton::TRIGGER_L}, | ||
| 26 | {"KEY_R", TasButton::TRIGGER_R}, | ||
| 27 | {"KEY_PLUS", TasButton::BUTTON_PLUS}, | ||
| 28 | {"KEY_MINUS", TasButton::BUTTON_MINUS}, | ||
| 29 | {"KEY_DLEFT", TasButton::BUTTON_LEFT}, | ||
| 30 | {"KEY_DUP", TasButton::BUTTON_UP}, | ||
| 31 | {"KEY_DRIGHT", TasButton::BUTTON_RIGHT}, | ||
| 32 | {"KEY_DDOWN", TasButton::BUTTON_DOWN}, | ||
| 33 | {"KEY_SL", TasButton::BUTTON_SL}, | ||
| 34 | {"KEY_SR", TasButton::BUTTON_SR}, | ||
| 35 | {"KEY_CAPTURE", TasButton::BUTTON_CAPTURE}, | ||
| 36 | {"KEY_HOME", TasButton::BUTTON_HOME}, | ||
| 37 | {"KEY_ZL", TasButton::TRIGGER_ZL}, | ||
| 38 | {"KEY_ZR", TasButton::TRIGGER_ZR}, | ||
| 39 | }; | ||
| 40 | |||
| 41 | Tas::Tas() { | ||
| 42 | if (!Settings::values.tas_enable) { | ||
| 43 | needs_reset = true; | ||
| 44 | return; | ||
| 45 | } | ||
| 46 | LoadTasFiles(); | ||
| 47 | } | ||
| 48 | |||
| 49 | Tas::~Tas() { | ||
| 50 | Stop(); | ||
| 51 | }; | ||
| 52 | |||
| 53 | void Tas::LoadTasFiles() { | ||
| 54 | script_length = 0; | ||
| 55 | for (size_t i = 0; i < commands.size(); i++) { | ||
| 56 | LoadTasFile(i); | ||
| 57 | if (commands[i].size() > script_length) { | ||
| 58 | script_length = commands[i].size(); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | void Tas::LoadTasFile(size_t player_index) { | ||
| 64 | if (!commands[player_index].empty()) { | ||
| 65 | commands[player_index].clear(); | ||
| 66 | } | ||
| 67 | std::string file = | ||
| 68 | Common::FS::ReadStringFromFile(Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / | ||
| 69 | fmt::format("script0-{}.txt", player_index + 1), | ||
| 70 | Common::FS::FileType::BinaryFile); | ||
| 71 | std::stringstream command_line(file); | ||
| 72 | std::string line; | ||
| 73 | int frame_no = 0; | ||
| 74 | while (std::getline(command_line, line, '\n')) { | ||
| 75 | if (line.empty()) { | ||
| 76 | continue; | ||
| 77 | } | ||
| 78 | LOG_DEBUG(Input, "Loading line: {}", line); | ||
| 79 | std::smatch m; | ||
| 80 | |||
| 81 | std::stringstream linestream(line); | ||
| 82 | std::string segment; | ||
| 83 | std::vector<std::string> seglist; | ||
| 84 | |||
| 85 | while (std::getline(linestream, segment, ' ')) { | ||
| 86 | seglist.push_back(segment); | ||
| 87 | } | ||
| 88 | |||
| 89 | if (seglist.size() < 4) { | ||
| 90 | continue; | ||
| 91 | } | ||
| 92 | |||
| 93 | while (frame_no < std::stoi(seglist.at(0))) { | ||
| 94 | commands[player_index].push_back({}); | ||
| 95 | frame_no++; | ||
| 96 | } | ||
| 97 | |||
| 98 | TASCommand command = { | ||
| 99 | .buttons = ReadCommandButtons(seglist.at(1)), | ||
| 100 | .l_axis = ReadCommandAxis(seglist.at(2)), | ||
| 101 | .r_axis = ReadCommandAxis(seglist.at(3)), | ||
| 102 | }; | ||
| 103 | commands[player_index].push_back(command); | ||
| 104 | frame_no++; | ||
| 105 | } | ||
| 106 | LOG_INFO(Input, "TAS file loaded! {} frames", frame_no); | ||
| 107 | } | ||
| 108 | |||
| 109 | void Tas::WriteTasFile(std::u8string file_name) { | ||
| 110 | std::string output_text; | ||
| 111 | for (size_t frame = 0; frame < record_commands.size(); frame++) { | ||
| 112 | if (!output_text.empty()) { | ||
| 113 | output_text += "\n"; | ||
| 114 | } | ||
| 115 | const TASCommand& line = record_commands[frame]; | ||
| 116 | output_text += std::to_string(frame) + " " + WriteCommandButtons(line.buttons) + " " + | ||
| 117 | WriteCommandAxis(line.l_axis) + " " + WriteCommandAxis(line.r_axis); | ||
| 118 | } | ||
| 119 | const auto bytes_written = Common::FS::WriteStringToFile( | ||
| 120 | Common::FS::GetYuzuPath(Common::FS::YuzuPath::TASDir) / file_name, | ||
| 121 | Common::FS::FileType::TextFile, output_text); | ||
| 122 | if (bytes_written == output_text.size()) { | ||
| 123 | LOG_INFO(Input, "TAS file written to file!"); | ||
| 124 | } else { | ||
| 125 | LOG_ERROR(Input, "Writing the TAS-file has failed! {} / {} bytes written", bytes_written, | ||
| 126 | output_text.size()); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | std::pair<float, float> Tas::FlipAxisY(std::pair<float, float> old) { | ||
| 131 | auto [x, y] = old; | ||
| 132 | return {x, -y}; | ||
| 133 | } | ||
| 134 | |||
| 135 | void Tas::RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes) { | ||
| 136 | last_input = {buttons, FlipAxisY(axes[0]), FlipAxisY(axes[1])}; | ||
| 137 | } | ||
| 138 | |||
| 139 | std::tuple<TasState, size_t, size_t> Tas::GetStatus() const { | ||
| 140 | TasState state; | ||
| 141 | if (is_recording) { | ||
| 142 | return {TasState::Recording, 0, record_commands.size()}; | ||
| 143 | } | ||
| 144 | |||
| 145 | if (is_running) { | ||
| 146 | state = TasState::Running; | ||
| 147 | } else { | ||
| 148 | state = TasState::Stopped; | ||
| 149 | } | ||
| 150 | |||
| 151 | return {state, current_command, script_length}; | ||
| 152 | } | ||
| 153 | |||
| 154 | std::string Tas::DebugButtons(u32 buttons) const { | ||
| 155 | return fmt::format("{{ {} }}", TasInput::Tas::ButtonsToString(buttons)); | ||
| 156 | } | ||
| 157 | |||
| 158 | std::string Tas::DebugJoystick(float x, float y) const { | ||
| 159 | return fmt::format("[ {} , {} ]", std::to_string(x), std::to_string(y)); | ||
| 160 | } | ||
| 161 | |||
| 162 | std::string Tas::DebugInput(const TasData& data) const { | ||
| 163 | return fmt::format("{{ {} , {} , {} }}", DebugButtons(data.buttons), | ||
| 164 | DebugJoystick(data.axis[0], data.axis[1]), | ||
| 165 | DebugJoystick(data.axis[2], data.axis[3])); | ||
| 166 | } | ||
| 167 | |||
| 168 | std::string Tas::DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) const { | ||
| 169 | std::string returns = "[ "; | ||
| 170 | for (size_t i = 0; i < arr.size(); i++) { | ||
| 171 | returns += DebugInput(arr[i]); | ||
| 172 | if (i != arr.size() - 1) { | ||
| 173 | returns += " , "; | ||
| 174 | } | ||
| 175 | } | ||
| 176 | return returns + "]"; | ||
| 177 | } | ||
| 178 | |||
| 179 | std::string Tas::ButtonsToString(u32 button) const { | ||
| 180 | std::string returns; | ||
| 181 | for (auto [text_button, tas_button] : text_to_tas_button) { | ||
| 182 | if ((button & static_cast<u32>(tas_button)) != 0) | ||
| 183 | returns += fmt::format(", {}", text_button.substr(4)); | ||
| 184 | } | ||
| 185 | return returns.empty() ? "" : returns.substr(2); | ||
| 186 | } | ||
| 187 | |||
| 188 | void Tas::UpdateThread() { | ||
| 189 | if (!Settings::values.tas_enable) { | ||
| 190 | if (is_running) { | ||
| 191 | Stop(); | ||
| 192 | } | ||
| 193 | return; | ||
| 194 | } | ||
| 195 | |||
| 196 | if (is_recording) { | ||
| 197 | record_commands.push_back(last_input); | ||
| 198 | } | ||
| 199 | if (needs_reset) { | ||
| 200 | current_command = 0; | ||
| 201 | needs_reset = false; | ||
| 202 | LoadTasFiles(); | ||
| 203 | LOG_DEBUG(Input, "tas_reset done"); | ||
| 204 | } | ||
| 205 | |||
| 206 | if (!is_running) { | ||
| 207 | tas_data.fill({}); | ||
| 208 | return; | ||
| 209 | } | ||
| 210 | if (current_command < script_length) { | ||
| 211 | LOG_DEBUG(Input, "Playing TAS {}/{}", current_command, script_length); | ||
| 212 | size_t frame = current_command++; | ||
| 213 | for (size_t i = 0; i < commands.size(); i++) { | ||
| 214 | if (frame < commands[i].size()) { | ||
| 215 | TASCommand command = commands[i][frame]; | ||
| 216 | tas_data[i].buttons = command.buttons; | ||
| 217 | auto [l_axis_x, l_axis_y] = command.l_axis; | ||
| 218 | tas_data[i].axis[0] = l_axis_x; | ||
| 219 | tas_data[i].axis[1] = l_axis_y; | ||
| 220 | auto [r_axis_x, r_axis_y] = command.r_axis; | ||
| 221 | tas_data[i].axis[2] = r_axis_x; | ||
| 222 | tas_data[i].axis[3] = r_axis_y; | ||
| 223 | } else { | ||
| 224 | tas_data[i] = {}; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | } else { | ||
| 228 | is_running = Settings::values.tas_loop.GetValue(); | ||
| 229 | current_command = 0; | ||
| 230 | tas_data.fill({}); | ||
| 231 | if (!is_running) { | ||
| 232 | SwapToStoredController(); | ||
| 233 | } | ||
| 234 | } | ||
| 235 | LOG_DEBUG(Input, "TAS inputs: {}", DebugInputs(tas_data)); | ||
| 236 | } | ||
| 237 | |||
| 238 | TasAnalog Tas::ReadCommandAxis(const std::string& line) const { | ||
| 239 | std::stringstream linestream(line); | ||
| 240 | std::string segment; | ||
| 241 | std::vector<std::string> seglist; | ||
| 242 | |||
| 243 | while (std::getline(linestream, segment, ';')) { | ||
| 244 | seglist.push_back(segment); | ||
| 245 | } | ||
| 246 | |||
| 247 | const float x = std::stof(seglist.at(0)) / 32767.0f; | ||
| 248 | const float y = std::stof(seglist.at(1)) / 32767.0f; | ||
| 249 | |||
| 250 | return {x, y}; | ||
| 251 | } | ||
| 252 | |||
| 253 | u32 Tas::ReadCommandButtons(const std::string& data) const { | ||
| 254 | std::stringstream button_text(data); | ||
| 255 | std::string line; | ||
| 256 | u32 buttons = 0; | ||
| 257 | while (std::getline(button_text, line, ';')) { | ||
| 258 | for (auto [text, tas_button] : text_to_tas_button) { | ||
| 259 | if (text == line) { | ||
| 260 | buttons |= static_cast<u32>(tas_button); | ||
| 261 | break; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | } | ||
| 265 | return buttons; | ||
| 266 | } | ||
| 267 | |||
| 268 | std::string Tas::WriteCommandAxis(TasAnalog data) const { | ||
| 269 | auto [x, y] = data; | ||
| 270 | std::string line; | ||
| 271 | line += std::to_string(static_cast<int>(x * 32767)); | ||
| 272 | line += ";"; | ||
| 273 | line += std::to_string(static_cast<int>(y * 32767)); | ||
| 274 | return line; | ||
| 275 | } | ||
| 276 | |||
| 277 | std::string Tas::WriteCommandButtons(u32 data) const { | ||
| 278 | if (data == 0) { | ||
| 279 | return "NONE"; | ||
| 280 | } | ||
| 281 | |||
| 282 | std::string line; | ||
| 283 | u32 index = 0; | ||
| 284 | while (data > 0) { | ||
| 285 | if ((data & 1) == 1) { | ||
| 286 | for (auto [text, tas_button] : text_to_tas_button) { | ||
| 287 | if (tas_button == static_cast<TasButton>(1 << index)) { | ||
| 288 | if (line.size() > 0) { | ||
| 289 | line += ";"; | ||
| 290 | } | ||
| 291 | line += text; | ||
| 292 | break; | ||
| 293 | } | ||
| 294 | } | ||
| 295 | } | ||
| 296 | index++; | ||
| 297 | data >>= 1; | ||
| 298 | } | ||
| 299 | return line; | ||
| 300 | } | ||
| 301 | |||
| 302 | void Tas::StartStop() { | ||
| 303 | if (!Settings::values.tas_enable) { | ||
| 304 | return; | ||
| 305 | } | ||
| 306 | if (is_running) { | ||
| 307 | Stop(); | ||
| 308 | } else { | ||
| 309 | is_running = true; | ||
| 310 | SwapToTasController(); | ||
| 311 | } | ||
| 312 | } | ||
| 313 | |||
| 314 | void Tas::Stop() { | ||
| 315 | is_running = false; | ||
| 316 | SwapToStoredController(); | ||
| 317 | } | ||
| 318 | |||
| 319 | void Tas::SwapToTasController() { | ||
| 320 | if (!Settings::values.tas_swap_controllers) { | ||
| 321 | return; | ||
| 322 | } | ||
| 323 | auto& players = Settings::values.players.GetValue(); | ||
| 324 | for (std::size_t index = 0; index < players.size(); index++) { | ||
| 325 | auto& player = players[index]; | ||
| 326 | player_mappings[index] = player; | ||
| 327 | |||
| 328 | // Only swap active controllers | ||
| 329 | if (!player.connected) { | ||
| 330 | continue; | ||
| 331 | } | ||
| 332 | |||
| 333 | Common::ParamPackage tas_param; | ||
| 334 | tas_param.Set("pad", static_cast<u8>(index)); | ||
| 335 | auto button_mapping = GetButtonMappingForDevice(tas_param); | ||
| 336 | auto analog_mapping = GetAnalogMappingForDevice(tas_param); | ||
| 337 | auto& buttons = player.buttons; | ||
| 338 | auto& analogs = player.analogs; | ||
| 339 | |||
| 340 | for (std::size_t i = 0; i < buttons.size(); ++i) { | ||
| 341 | buttons[i] = button_mapping[static_cast<Settings::NativeButton::Values>(i)].Serialize(); | ||
| 342 | } | ||
| 343 | for (std::size_t i = 0; i < analogs.size(); ++i) { | ||
| 344 | analogs[i] = analog_mapping[static_cast<Settings::NativeAnalog::Values>(i)].Serialize(); | ||
| 345 | } | ||
| 346 | } | ||
| 347 | is_old_input_saved = true; | ||
| 348 | Settings::values.is_device_reload_pending.store(true); | ||
| 349 | } | ||
| 350 | |||
| 351 | void Tas::SwapToStoredController() { | ||
| 352 | if (!is_old_input_saved) { | ||
| 353 | return; | ||
| 354 | } | ||
| 355 | auto& players = Settings::values.players.GetValue(); | ||
| 356 | for (std::size_t index = 0; index < players.size(); index++) { | ||
| 357 | players[index] = player_mappings[index]; | ||
| 358 | } | ||
| 359 | is_old_input_saved = false; | ||
| 360 | Settings::values.is_device_reload_pending.store(true); | ||
| 361 | } | ||
| 362 | |||
| 363 | void Tas::Reset() { | ||
| 364 | if (!Settings::values.tas_enable) { | ||
| 365 | return; | ||
| 366 | } | ||
| 367 | needs_reset = true; | ||
| 368 | } | ||
| 369 | |||
| 370 | bool Tas::Record() { | ||
| 371 | if (!Settings::values.tas_enable) { | ||
| 372 | return true; | ||
| 373 | } | ||
| 374 | is_recording = !is_recording; | ||
| 375 | return is_recording; | ||
| 376 | } | ||
| 377 | |||
| 378 | void Tas::SaveRecording(bool overwrite_file) { | ||
| 379 | if (is_recording) { | ||
| 380 | return; | ||
| 381 | } | ||
| 382 | if (record_commands.empty()) { | ||
| 383 | return; | ||
| 384 | } | ||
| 385 | WriteTasFile(u8"record.txt"); | ||
| 386 | if (overwrite_file) { | ||
| 387 | WriteTasFile(u8"script0-1.txt"); | ||
| 388 | } | ||
| 389 | needs_reset = true; | ||
| 390 | record_commands.clear(); | ||
| 391 | } | ||
| 392 | |||
| 393 | InputCommon::ButtonMapping Tas::GetButtonMappingForDevice( | ||
| 394 | const Common::ParamPackage& params) const { | ||
| 395 | // This list is missing ZL/ZR since those are not considered buttons. | ||
| 396 | // We will add those afterwards | ||
| 397 | // This list also excludes any button that can't be really mapped | ||
| 398 | static constexpr std::array<std::pair<Settings::NativeButton::Values, TasButton>, 20> | ||
| 399 | switch_to_tas_button = { | ||
| 400 | std::pair{Settings::NativeButton::A, TasButton::BUTTON_A}, | ||
| 401 | {Settings::NativeButton::B, TasButton::BUTTON_B}, | ||
| 402 | {Settings::NativeButton::X, TasButton::BUTTON_X}, | ||
| 403 | {Settings::NativeButton::Y, TasButton::BUTTON_Y}, | ||
| 404 | {Settings::NativeButton::LStick, TasButton::STICK_L}, | ||
| 405 | {Settings::NativeButton::RStick, TasButton::STICK_R}, | ||
| 406 | {Settings::NativeButton::L, TasButton::TRIGGER_L}, | ||
| 407 | {Settings::NativeButton::R, TasButton::TRIGGER_R}, | ||
| 408 | {Settings::NativeButton::Plus, TasButton::BUTTON_PLUS}, | ||
| 409 | {Settings::NativeButton::Minus, TasButton::BUTTON_MINUS}, | ||
| 410 | {Settings::NativeButton::DLeft, TasButton::BUTTON_LEFT}, | ||
| 411 | {Settings::NativeButton::DUp, TasButton::BUTTON_UP}, | ||
| 412 | {Settings::NativeButton::DRight, TasButton::BUTTON_RIGHT}, | ||
| 413 | {Settings::NativeButton::DDown, TasButton::BUTTON_DOWN}, | ||
| 414 | {Settings::NativeButton::SL, TasButton::BUTTON_SL}, | ||
| 415 | {Settings::NativeButton::SR, TasButton::BUTTON_SR}, | ||
| 416 | {Settings::NativeButton::Screenshot, TasButton::BUTTON_CAPTURE}, | ||
| 417 | {Settings::NativeButton::Home, TasButton::BUTTON_HOME}, | ||
| 418 | {Settings::NativeButton::ZL, TasButton::TRIGGER_ZL}, | ||
| 419 | {Settings::NativeButton::ZR, TasButton::TRIGGER_ZR}, | ||
| 420 | }; | ||
| 421 | |||
| 422 | InputCommon::ButtonMapping mapping{}; | ||
| 423 | for (const auto& [switch_button, tas_button] : switch_to_tas_button) { | ||
| 424 | Common::ParamPackage button_params({{"engine", "tas"}}); | ||
| 425 | button_params.Set("pad", params.Get("pad", 0)); | ||
| 426 | button_params.Set("button", static_cast<int>(tas_button)); | ||
| 427 | mapping.insert_or_assign(switch_button, std::move(button_params)); | ||
| 428 | } | ||
| 429 | |||
| 430 | return mapping; | ||
| 431 | } | ||
| 432 | |||
| 433 | InputCommon::AnalogMapping Tas::GetAnalogMappingForDevice( | ||
| 434 | const Common::ParamPackage& params) const { | ||
| 435 | |||
| 436 | InputCommon::AnalogMapping mapping = {}; | ||
| 437 | Common::ParamPackage left_analog_params; | ||
| 438 | left_analog_params.Set("engine", "tas"); | ||
| 439 | left_analog_params.Set("pad", params.Get("pad", 0)); | ||
| 440 | left_analog_params.Set("axis_x", static_cast<int>(TasAxes::StickX)); | ||
| 441 | left_analog_params.Set("axis_y", static_cast<int>(TasAxes::StickY)); | ||
| 442 | mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params)); | ||
| 443 | Common::ParamPackage right_analog_params; | ||
| 444 | right_analog_params.Set("engine", "tas"); | ||
| 445 | right_analog_params.Set("pad", params.Get("pad", 0)); | ||
| 446 | right_analog_params.Set("axis_x", static_cast<int>(TasAxes::SubstickX)); | ||
| 447 | right_analog_params.Set("axis_y", static_cast<int>(TasAxes::SubstickY)); | ||
| 448 | mapping.insert_or_assign(Settings::NativeAnalog::RStick, std::move(right_analog_params)); | ||
| 449 | return mapping; | ||
| 450 | } | ||
| 451 | |||
| 452 | const TasData& Tas::GetTasState(std::size_t pad) const { | ||
| 453 | return tas_data[pad]; | ||
| 454 | } | ||
| 455 | } // namespace TasInput | ||
diff --git a/src/input_common/tas/tas_input.h b/src/input_common/tas/tas_input.h new file mode 100644 index 000000000..3e2db8f00 --- /dev/null +++ b/src/input_common/tas/tas_input.h | |||
| @@ -0,0 +1,237 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | |||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "common/settings_input.h" | ||
| 11 | #include "core/frontend/input.h" | ||
| 12 | #include "input_common/main.h" | ||
| 13 | |||
| 14 | /* | ||
| 15 | To play back TAS scripts on Yuzu, select the folder with scripts in the configuration menu below | ||
| 16 | Tools -> Configure TAS. The file itself has normal text format and has to be called script0-1.txt | ||
| 17 | for controller 1, script0-2.txt for controller 2 and so forth (with max. 8 players). | ||
| 18 | |||
| 19 | A script file has the same format as TAS-nx uses, so final files will look like this: | ||
| 20 | |||
| 21 | 1 KEY_B 0;0 0;0 | ||
| 22 | 6 KEY_ZL 0;0 0;0 | ||
| 23 | 41 KEY_ZL;KEY_Y 0;0 0;0 | ||
| 24 | 43 KEY_X;KEY_A 32767;0 0;0 | ||
| 25 | 44 KEY_A 32767;0 0;0 | ||
| 26 | 45 KEY_A 32767;0 0;0 | ||
| 27 | 46 KEY_A 32767;0 0;0 | ||
| 28 | 47 KEY_A 32767;0 0;0 | ||
| 29 | |||
| 30 | After placing the file at the correct location, it can be read into Yuzu with the (default) hotkey | ||
| 31 | CTRL+F6 (refresh). In the bottom left corner, it will display the amount of frames the script file | ||
| 32 | has. Playback can be started or stopped using CTRL+F5. | ||
| 33 | |||
| 34 | However, for playback to actually work, the correct input device has to be selected: In the Controls | ||
| 35 | menu, select TAS from the device list for the controller that the script should be played on. | ||
| 36 | |||
| 37 | Recording a new script file is really simple: Just make sure that the proper device (not TAS) is | ||
| 38 | connected on P1, and press CTRL+F7 to start recording. When done, just press the same keystroke | ||
| 39 | again (CTRL+F7). The new script will be saved at the location previously selected, as the filename | ||
| 40 | record.txt. | ||
| 41 | |||
| 42 | For debugging purposes, the common controller debugger can be used (View -> Debugging -> Controller | ||
| 43 | P1). | ||
| 44 | */ | ||
| 45 | |||
| 46 | namespace TasInput { | ||
| 47 | |||
| 48 | constexpr size_t PLAYER_NUMBER = 8; | ||
| 49 | |||
| 50 | using TasAnalog = std::pair<float, float>; | ||
| 51 | |||
| 52 | enum class TasState { | ||
| 53 | Running, | ||
| 54 | Recording, | ||
| 55 | Stopped, | ||
| 56 | }; | ||
| 57 | |||
| 58 | enum class TasButton : u32 { | ||
| 59 | BUTTON_A = 1U << 0, | ||
| 60 | BUTTON_B = 1U << 1, | ||
| 61 | BUTTON_X = 1U << 2, | ||
| 62 | BUTTON_Y = 1U << 3, | ||
| 63 | STICK_L = 1U << 4, | ||
| 64 | STICK_R = 1U << 5, | ||
| 65 | TRIGGER_L = 1U << 6, | ||
| 66 | TRIGGER_R = 1U << 7, | ||
| 67 | TRIGGER_ZL = 1U << 8, | ||
| 68 | TRIGGER_ZR = 1U << 9, | ||
| 69 | BUTTON_PLUS = 1U << 10, | ||
| 70 | BUTTON_MINUS = 1U << 11, | ||
| 71 | BUTTON_LEFT = 1U << 12, | ||
| 72 | BUTTON_UP = 1U << 13, | ||
| 73 | BUTTON_RIGHT = 1U << 14, | ||
| 74 | BUTTON_DOWN = 1U << 15, | ||
| 75 | BUTTON_SL = 1U << 16, | ||
| 76 | BUTTON_SR = 1U << 17, | ||
| 77 | BUTTON_HOME = 1U << 18, | ||
| 78 | BUTTON_CAPTURE = 1U << 19, | ||
| 79 | }; | ||
| 80 | |||
| 81 | enum class TasAxes : u8 { | ||
| 82 | StickX, | ||
| 83 | StickY, | ||
| 84 | SubstickX, | ||
| 85 | SubstickY, | ||
| 86 | Undefined, | ||
| 87 | }; | ||
| 88 | |||
| 89 | struct TasData { | ||
| 90 | u32 buttons{}; | ||
| 91 | std::array<float, 4> axis{}; | ||
| 92 | }; | ||
| 93 | |||
| 94 | class Tas { | ||
| 95 | public: | ||
| 96 | Tas(); | ||
| 97 | ~Tas(); | ||
| 98 | |||
| 99 | // Changes the input status that will be stored in each frame | ||
| 100 | void RecordInput(u32 buttons, const std::array<std::pair<float, float>, 2>& axes); | ||
| 101 | |||
| 102 | // Main loop that records or executes input | ||
| 103 | void UpdateThread(); | ||
| 104 | |||
| 105 | // Sets the flag to start or stop the TAS command excecution and swaps controllers profiles | ||
| 106 | void StartStop(); | ||
| 107 | |||
| 108 | // Stop the TAS and reverts any controller profile | ||
| 109 | void Stop(); | ||
| 110 | |||
| 111 | // Sets the flag to reload the file and start from the begining in the next update | ||
| 112 | void Reset(); | ||
| 113 | |||
| 114 | /** | ||
| 115 | * Sets the flag to enable or disable recording of inputs | ||
| 116 | * @return Returns true if the current recording status is enabled | ||
| 117 | */ | ||
| 118 | bool Record(); | ||
| 119 | |||
| 120 | // Saves contents of record_commands on a file if overwrite is enabled player 1 will be | ||
| 121 | // overwritten with the recorded commands | ||
| 122 | void SaveRecording(bool overwrite_file); | ||
| 123 | |||
| 124 | /** | ||
| 125 | * Returns the current status values of TAS playback/recording | ||
| 126 | * @return Tuple of | ||
| 127 | * TasState indicating the current state out of Running, Recording or Stopped ; | ||
| 128 | * Current playback progress or amount of frames (so far) for Recording ; | ||
| 129 | * Total length of script file currently loaded or amount of frames (so far) for Recording | ||
| 130 | */ | ||
| 131 | std::tuple<TasState, size_t, size_t> GetStatus() const; | ||
| 132 | |||
| 133 | // Retuns an array of the default button mappings | ||
| 134 | InputCommon::ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) const; | ||
| 135 | |||
| 136 | // Retuns an array of the default analog mappings | ||
| 137 | InputCommon::AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) const; | ||
| 138 | [[nodiscard]] const TasData& GetTasState(std::size_t pad) const; | ||
| 139 | |||
| 140 | private: | ||
| 141 | struct TASCommand { | ||
| 142 | u32 buttons{}; | ||
| 143 | TasAnalog l_axis{}; | ||
| 144 | TasAnalog r_axis{}; | ||
| 145 | }; | ||
| 146 | |||
| 147 | // Loads TAS files from all players | ||
| 148 | void LoadTasFiles(); | ||
| 149 | |||
| 150 | // Loads TAS file from the specified player | ||
| 151 | void LoadTasFile(size_t player_index); | ||
| 152 | |||
| 153 | // Writes a TAS file from the recorded commands | ||
| 154 | void WriteTasFile(std::u8string file_name); | ||
| 155 | |||
| 156 | /** | ||
| 157 | * Parses a string containing the axis values with the following format "x;y" | ||
| 158 | * X and Y have a range from -32767 to 32767 | ||
| 159 | * @return Returns a TAS analog object with axis values with range from -1.0 to 1.0 | ||
| 160 | */ | ||
| 161 | TasAnalog ReadCommandAxis(const std::string& line) const; | ||
| 162 | |||
| 163 | /** | ||
| 164 | * Parses a string containing the button values with the following format "a;b;c;d..." | ||
| 165 | * Each button is represented by it's text format specified in text_to_tas_button array | ||
| 166 | * @return Returns a u32 with each bit representing the status of a button | ||
| 167 | */ | ||
| 168 | u32 ReadCommandButtons(const std::string& line) const; | ||
| 169 | |||
| 170 | /** | ||
| 171 | * Converts an u32 containing the button status into the text equivalent | ||
| 172 | * @return Returns a string with the name of the buttons to be written to the file | ||
| 173 | */ | ||
| 174 | std::string WriteCommandButtons(u32 data) const; | ||
| 175 | |||
| 176 | /** | ||
| 177 | * Converts an TAS analog object containing the axis status into the text equivalent | ||
| 178 | * @return Returns a string with the value of the axis to be written to the file | ||
| 179 | */ | ||
| 180 | std::string WriteCommandAxis(TasAnalog data) const; | ||
| 181 | |||
| 182 | // Inverts the Y axis polarity | ||
| 183 | std::pair<float, float> FlipAxisY(std::pair<float, float> old); | ||
| 184 | |||
| 185 | /** | ||
| 186 | * Converts an u32 containing the button status into the text equivalent | ||
| 187 | * @return Returns a string with the name of the buttons to be printed on console | ||
| 188 | */ | ||
| 189 | std::string DebugButtons(u32 buttons) const; | ||
| 190 | |||
| 191 | /** | ||
| 192 | * Converts an TAS analog object containing the axis status into the text equivalent | ||
| 193 | * @return Returns a string with the value of the axis to be printed on console | ||
| 194 | */ | ||
| 195 | std::string DebugJoystick(float x, float y) const; | ||
| 196 | |||
| 197 | /** | ||
| 198 | * Converts the given TAS status into the text equivalent | ||
| 199 | * @return Returns a string with the value of the TAS status to be printed on console | ||
| 200 | */ | ||
| 201 | std::string DebugInput(const TasData& data) const; | ||
| 202 | |||
| 203 | /** | ||
| 204 | * Converts the given TAS status of multiple players into the text equivalent | ||
| 205 | * @return Returns a string with the value of the status of all TAS players to be printed on | ||
| 206 | * console | ||
| 207 | */ | ||
| 208 | std::string DebugInputs(const std::array<TasData, PLAYER_NUMBER>& arr) const; | ||
| 209 | |||
| 210 | /** | ||
| 211 | * Converts an u32 containing the button status into the text equivalent | ||
| 212 | * @return Returns a string with the name of the buttons | ||
| 213 | */ | ||
| 214 | std::string ButtonsToString(u32 button) const; | ||
| 215 | |||
| 216 | // Stores current controller configuration and sets a TAS controller for every active controller | ||
| 217 | // to the current config | ||
| 218 | void SwapToTasController(); | ||
| 219 | |||
| 220 | // Sets the stored controller configuration to the current config | ||
| 221 | void SwapToStoredController(); | ||
| 222 | |||
| 223 | size_t script_length{0}; | ||
| 224 | std::array<TasData, PLAYER_NUMBER> tas_data; | ||
| 225 | bool is_old_input_saved{false}; | ||
| 226 | bool is_recording{false}; | ||
| 227 | bool is_running{false}; | ||
| 228 | bool needs_reset{false}; | ||
| 229 | std::array<std::vector<TASCommand>, PLAYER_NUMBER> commands{}; | ||
| 230 | std::vector<TASCommand> record_commands{}; | ||
| 231 | size_t current_command{0}; | ||
| 232 | TASCommand last_input{}; // only used for recording | ||
| 233 | |||
| 234 | // Old settings for swapping controllers | ||
| 235 | std::array<Settings::PlayerInput, 10> player_mappings; | ||
| 236 | }; | ||
| 237 | } // namespace TasInput | ||
diff --git a/src/input_common/tas/tas_poller.cpp b/src/input_common/tas/tas_poller.cpp new file mode 100644 index 000000000..15810d6b0 --- /dev/null +++ b/src/input_common/tas/tas_poller.cpp | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <mutex> | ||
| 6 | #include <utility> | ||
| 7 | |||
| 8 | #include "common/settings.h" | ||
| 9 | #include "common/threadsafe_queue.h" | ||
| 10 | #include "input_common/tas/tas_input.h" | ||
| 11 | #include "input_common/tas/tas_poller.h" | ||
| 12 | |||
| 13 | namespace InputCommon { | ||
| 14 | |||
| 15 | class TasButton final : public Input::ButtonDevice { | ||
| 16 | public: | ||
| 17 | explicit TasButton(u32 button_, u32 pad_, const TasInput::Tas* tas_input_) | ||
| 18 | : button(button_), pad(pad_), tas_input(tas_input_) {} | ||
| 19 | |||
| 20 | bool GetStatus() const override { | ||
| 21 | return (tas_input->GetTasState(pad).buttons & button) != 0; | ||
| 22 | } | ||
| 23 | |||
| 24 | private: | ||
| 25 | const u32 button; | ||
| 26 | const u32 pad; | ||
| 27 | const TasInput::Tas* tas_input; | ||
| 28 | }; | ||
| 29 | |||
| 30 | TasButtonFactory::TasButtonFactory(std::shared_ptr<TasInput::Tas> tas_input_) | ||
| 31 | : tas_input(std::move(tas_input_)) {} | ||
| 32 | |||
| 33 | std::unique_ptr<Input::ButtonDevice> TasButtonFactory::Create(const Common::ParamPackage& params) { | ||
| 34 | const auto button_id = params.Get("button", 0); | ||
| 35 | const auto pad = params.Get("pad", 0); | ||
| 36 | |||
| 37 | return std::make_unique<TasButton>(button_id, pad, tas_input.get()); | ||
| 38 | } | ||
| 39 | |||
| 40 | class TasAnalog final : public Input::AnalogDevice { | ||
| 41 | public: | ||
| 42 | explicit TasAnalog(u32 pad_, u32 axis_x_, u32 axis_y_, const TasInput::Tas* tas_input_) | ||
| 43 | : pad(pad_), axis_x(axis_x_), axis_y(axis_y_), tas_input(tas_input_) {} | ||
| 44 | |||
| 45 | float GetAxis(u32 axis) const { | ||
| 46 | std::lock_guard lock{mutex}; | ||
| 47 | return tas_input->GetTasState(pad).axis.at(axis); | ||
| 48 | } | ||
| 49 | |||
| 50 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { | ||
| 51 | float x = GetAxis(analog_axis_x); | ||
| 52 | float y = GetAxis(analog_axis_y); | ||
| 53 | |||
| 54 | // Make sure the coordinates are in the unit circle, | ||
| 55 | // otherwise normalize it. | ||
| 56 | float r = x * x + y * y; | ||
| 57 | if (r > 1.0f) { | ||
| 58 | r = std::sqrt(r); | ||
| 59 | x /= r; | ||
| 60 | y /= r; | ||
| 61 | } | ||
| 62 | |||
| 63 | return {x, y}; | ||
| 64 | } | ||
| 65 | |||
| 66 | std::tuple<float, float> GetStatus() const override { | ||
| 67 | return GetAnalog(axis_x, axis_y); | ||
| 68 | } | ||
| 69 | |||
| 70 | Input::AnalogProperties GetAnalogProperties() const override { | ||
| 71 | return {0.0f, 1.0f, 0.5f}; | ||
| 72 | } | ||
| 73 | |||
| 74 | private: | ||
| 75 | const u32 pad; | ||
| 76 | const u32 axis_x; | ||
| 77 | const u32 axis_y; | ||
| 78 | const TasInput::Tas* tas_input; | ||
| 79 | mutable std::mutex mutex; | ||
| 80 | }; | ||
| 81 | |||
| 82 | /// An analog device factory that creates analog devices from GC Adapter | ||
| 83 | TasAnalogFactory::TasAnalogFactory(std::shared_ptr<TasInput::Tas> tas_input_) | ||
| 84 | : tas_input(std::move(tas_input_)) {} | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Creates analog device from joystick axes | ||
| 88 | * @param params contains parameters for creating the device: | ||
| 89 | * - "port": the nth gcpad on the adapter | ||
| 90 | * - "axis_x": the index of the axis to be bind as x-axis | ||
| 91 | * - "axis_y": the index of the axis to be bind as y-axis | ||
| 92 | */ | ||
| 93 | std::unique_ptr<Input::AnalogDevice> TasAnalogFactory::Create(const Common::ParamPackage& params) { | ||
| 94 | const auto pad = static_cast<u32>(params.Get("pad", 0)); | ||
| 95 | const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); | ||
| 96 | const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); | ||
| 97 | |||
| 98 | return std::make_unique<TasAnalog>(pad, axis_x, axis_y, tas_input.get()); | ||
| 99 | } | ||
| 100 | |||
| 101 | } // namespace InputCommon | ||
diff --git a/src/input_common/tas/tas_poller.h b/src/input_common/tas/tas_poller.h new file mode 100644 index 000000000..09e426cef --- /dev/null +++ b/src/input_common/tas/tas_poller.h | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include "core/frontend/input.h" | ||
| 9 | #include "input_common/tas/tas_input.h" | ||
| 10 | |||
| 11 | namespace InputCommon { | ||
| 12 | |||
| 13 | /** | ||
| 14 | * A button device factory representing a tas bot. It receives tas events and forward them | ||
| 15 | * to all button devices it created. | ||
| 16 | */ | ||
| 17 | class TasButtonFactory final : public Input::Factory<Input::ButtonDevice> { | ||
| 18 | public: | ||
| 19 | explicit TasButtonFactory(std::shared_ptr<TasInput::Tas> tas_input_); | ||
| 20 | |||
| 21 | /** | ||
| 22 | * Creates a button device from a button press | ||
| 23 | * @param params contains parameters for creating the device: | ||
| 24 | * - "code": the code of the key to bind with the button | ||
| 25 | */ | ||
| 26 | std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override; | ||
| 27 | |||
| 28 | private: | ||
| 29 | std::shared_ptr<TasInput::Tas> tas_input; | ||
| 30 | }; | ||
| 31 | |||
| 32 | /// An analog device factory that creates analog devices from tas | ||
| 33 | class TasAnalogFactory final : public Input::Factory<Input::AnalogDevice> { | ||
| 34 | public: | ||
| 35 | explicit TasAnalogFactory(std::shared_ptr<TasInput::Tas> tas_input_); | ||
| 36 | |||
| 37 | std::unique_ptr<Input::AnalogDevice> Create(const Common::ParamPackage& params) override; | ||
| 38 | |||
| 39 | private: | ||
| 40 | std::shared_ptr<TasInput::Tas> tas_input; | ||
| 41 | }; | ||
| 42 | |||
| 43 | } // namespace InputCommon | ||
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index a11ea3068..380f9bb76 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h | |||
| @@ -21,8 +21,6 @@ | |||
| 21 | 21 | ||
| 22 | namespace InputCommon::CemuhookUDP { | 22 | namespace InputCommon::CemuhookUDP { |
| 23 | 23 | ||
| 24 | constexpr char DEFAULT_SRV[] = "127.0.0.1:26760"; | ||
| 25 | |||
| 26 | class Socket; | 24 | class Socket; |
| 27 | 25 | ||
| 28 | namespace Response { | 26 | namespace Response { |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp index 580063fa9..170db269a 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp | |||
| @@ -58,8 +58,8 @@ void GetCbuf(EmitContext& ctx, std::string_view ret, const IR::Value& binding, | |||
| 58 | const auto cbuf{fmt::format("{}_cbuf{}", ctx.stage_name, binding.U32())}; | 58 | const auto cbuf{fmt::format("{}_cbuf{}", ctx.stage_name, binding.U32())}; |
| 59 | const auto cbuf_cast{fmt::format("{}({}[{}]{{}})", cast, cbuf, index)}; | 59 | const auto cbuf_cast{fmt::format("{}({}[{}]{{}})", cast, cbuf, index)}; |
| 60 | const auto extraction{num_bits == 32 ? cbuf_cast | 60 | const auto extraction{num_bits == 32 ? cbuf_cast |
| 61 | : fmt ::format("bitfieldExtract({},int({}),{})", cbuf_cast, | 61 | : fmt::format("bitfieldExtract({},int({}),{})", cbuf_cast, |
| 62 | bit_offset, num_bits)}; | 62 | bit_offset, num_bits)}; |
| 63 | if (!component_indexing_bug) { | 63 | if (!component_indexing_bug) { |
| 64 | const auto result{fmt::format(fmt::runtime(extraction), swizzle)}; | 64 | const auto result{fmt::format(fmt::runtime(extraction), swizzle)}; |
| 65 | ctx.Add("{}={};", ret, result); | 65 | ctx.Add("{}={};", ret, result); |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp index a982dd8a2..cd285e2c8 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp | |||
| @@ -11,6 +11,8 @@ | |||
| 11 | 11 | ||
| 12 | namespace Shader::Backend::GLSL { | 12 | namespace Shader::Backend::GLSL { |
| 13 | namespace { | 13 | namespace { |
| 14 | constexpr char THREAD_ID[]{"gl_SubGroupInvocationARB"}; | ||
| 15 | |||
| 14 | void SetInBoundsFlag(EmitContext& ctx, IR::Inst& inst) { | 16 | void SetInBoundsFlag(EmitContext& ctx, IR::Inst& inst) { |
| 15 | IR::Inst* const in_bounds{inst.GetAssociatedPseudoOperation(IR::Opcode::GetInBoundsFromOp)}; | 17 | IR::Inst* const in_bounds{inst.GetAssociatedPseudoOperation(IR::Opcode::GetInBoundsFromOp)}; |
| 16 | if (!in_bounds) { | 18 | if (!in_bounds) { |
| @@ -43,84 +45,100 @@ void UseShuffleNv(EmitContext& ctx, IR::Inst& inst, std::string_view shfl_op, | |||
| 43 | ctx.AddU32("{}={}({},{},{},shfl_in_bounds);", inst, shfl_op, value, index, width); | 45 | ctx.AddU32("{}={}({},{},{},shfl_in_bounds);", inst, shfl_op, value, index, width); |
| 44 | SetInBoundsFlag(ctx, inst); | 46 | SetInBoundsFlag(ctx, inst); |
| 45 | } | 47 | } |
| 48 | |||
| 49 | std::string_view BallotIndex(EmitContext& ctx) { | ||
| 50 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | ||
| 51 | return ".x"; | ||
| 52 | } | ||
| 53 | return "[gl_SubGroupInvocationARB>>5]"; | ||
| 54 | } | ||
| 55 | |||
| 56 | std::string GetMask(EmitContext& ctx, std::string_view mask) { | ||
| 57 | const auto ballot_index{BallotIndex(ctx)}; | ||
| 58 | return fmt::format("uint(uvec2({}){})", mask, ballot_index); | ||
| 59 | } | ||
| 46 | } // Anonymous namespace | 60 | } // Anonymous namespace |
| 47 | 61 | ||
| 48 | void EmitLaneId(EmitContext& ctx, IR::Inst& inst) { | 62 | void EmitLaneId(EmitContext& ctx, IR::Inst& inst) { |
| 49 | ctx.AddU32("{}=gl_SubGroupInvocationARB&31u;", inst); | 63 | ctx.AddU32("{}={}&31u;", inst, THREAD_ID); |
| 50 | } | 64 | } |
| 51 | 65 | ||
| 52 | void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { | 66 | void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { |
| 53 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | 67 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { |
| 54 | ctx.AddU1("{}=allInvocationsEqualARB({});", inst, pred); | 68 | ctx.AddU1("{}=allInvocationsEqualARB({});", inst, pred); |
| 55 | } else { | 69 | return; |
| 56 | const auto active_mask{fmt::format("uvec2(ballotARB(true))[gl_SubGroupInvocationARB]")}; | ||
| 57 | const auto ballot{fmt::format("uvec2(ballotARB({}))[gl_SubGroupInvocationARB]", pred)}; | ||
| 58 | ctx.AddU1("{}=({}&{})=={};", inst, ballot, active_mask, active_mask); | ||
| 59 | } | 70 | } |
| 71 | const auto ballot_index{BallotIndex(ctx)}; | ||
| 72 | const auto active_mask{fmt::format("uvec2(ballotARB(true)){}", ballot_index)}; | ||
| 73 | const auto ballot{fmt::format("uvec2(ballotARB({})){}", pred, ballot_index)}; | ||
| 74 | ctx.AddU1("{}=({}&{})=={};", inst, ballot, active_mask, active_mask); | ||
| 60 | } | 75 | } |
| 61 | 76 | ||
| 62 | void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { | 77 | void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { |
| 63 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | 78 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { |
| 64 | ctx.AddU1("{}=anyInvocationARB({});", inst, pred); | 79 | ctx.AddU1("{}=anyInvocationARB({});", inst, pred); |
| 65 | } else { | 80 | return; |
| 66 | const auto active_mask{fmt::format("uvec2(ballotARB(true))[gl_SubGroupInvocationARB]")}; | ||
| 67 | const auto ballot{fmt::format("uvec2(ballotARB({}))[gl_SubGroupInvocationARB]", pred)}; | ||
| 68 | ctx.AddU1("{}=({}&{})!=0u;", inst, ballot, active_mask, active_mask); | ||
| 69 | } | 81 | } |
| 82 | const auto ballot_index{BallotIndex(ctx)}; | ||
| 83 | const auto active_mask{fmt::format("uvec2(ballotARB(true)){}", ballot_index)}; | ||
| 84 | const auto ballot{fmt::format("uvec2(ballotARB({})){}", pred, ballot_index)}; | ||
| 85 | ctx.AddU1("{}=({}&{})!=0u;", inst, ballot, active_mask, active_mask); | ||
| 70 | } | 86 | } |
| 71 | 87 | ||
| 72 | void EmitVoteEqual(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { | 88 | void EmitVoteEqual(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { |
| 73 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | 89 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { |
| 74 | ctx.AddU1("{}=allInvocationsEqualARB({});", inst, pred); | 90 | ctx.AddU1("{}=allInvocationsEqualARB({});", inst, pred); |
| 75 | } else { | 91 | return; |
| 76 | const auto active_mask{fmt::format("uvec2(ballotARB(true))[gl_SubGroupInvocationARB]")}; | ||
| 77 | const auto ballot{fmt::format("uvec2(ballotARB({}))[gl_SubGroupInvocationARB]", pred)}; | ||
| 78 | const auto value{fmt::format("({}^{})", ballot, active_mask)}; | ||
| 79 | ctx.AddU1("{}=({}==0)||({}=={});", inst, value, value, active_mask); | ||
| 80 | } | 92 | } |
| 93 | const auto ballot_index{BallotIndex(ctx)}; | ||
| 94 | const auto active_mask{fmt::format("uvec2(ballotARB(true)){}", ballot_index)}; | ||
| 95 | const auto ballot{fmt::format("uvec2(ballotARB({})){}", pred, ballot_index)}; | ||
| 96 | const auto value{fmt::format("({}^{})", ballot, active_mask)}; | ||
| 97 | ctx.AddU1("{}=({}==0)||({}=={});", inst, value, value, active_mask); | ||
| 81 | } | 98 | } |
| 82 | 99 | ||
| 83 | void EmitSubgroupBallot(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { | 100 | void EmitSubgroupBallot(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { |
| 84 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | 101 | const auto ballot_index{BallotIndex(ctx)}; |
| 85 | ctx.AddU32("{}=uvec2(ballotARB({})).x;", inst, pred); | 102 | ctx.AddU32("{}=uvec2(ballotARB({})){};", inst, pred, ballot_index); |
| 86 | } else { | ||
| 87 | ctx.AddU32("{}=uvec2(ballotARB({}))[gl_SubGroupInvocationARB];", inst, pred); | ||
| 88 | } | ||
| 89 | } | 103 | } |
| 90 | 104 | ||
| 91 | void EmitSubgroupEqMask(EmitContext& ctx, IR::Inst& inst) { | 105 | void EmitSubgroupEqMask(EmitContext& ctx, IR::Inst& inst) { |
| 92 | ctx.AddU32("{}=uint(gl_SubGroupEqMaskARB.x);", inst); | 106 | ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupEqMaskARB")); |
| 93 | } | 107 | } |
| 94 | 108 | ||
| 95 | void EmitSubgroupLtMask(EmitContext& ctx, IR::Inst& inst) { | 109 | void EmitSubgroupLtMask(EmitContext& ctx, IR::Inst& inst) { |
| 96 | ctx.AddU32("{}=uint(gl_SubGroupLtMaskARB.x);", inst); | 110 | ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupLtMaskARB")); |
| 97 | } | 111 | } |
| 98 | 112 | ||
| 99 | void EmitSubgroupLeMask(EmitContext& ctx, IR::Inst& inst) { | 113 | void EmitSubgroupLeMask(EmitContext& ctx, IR::Inst& inst) { |
| 100 | ctx.AddU32("{}=uint(gl_SubGroupLeMaskARB.x);", inst); | 114 | ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupLeMaskARB")); |
| 101 | } | 115 | } |
| 102 | 116 | ||
| 103 | void EmitSubgroupGtMask(EmitContext& ctx, IR::Inst& inst) { | 117 | void EmitSubgroupGtMask(EmitContext& ctx, IR::Inst& inst) { |
| 104 | ctx.AddU32("{}=uint(gl_SubGroupGtMaskARB.x);", inst); | 118 | ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupGtMaskARB")); |
| 105 | } | 119 | } |
| 106 | 120 | ||
| 107 | void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst) { | 121 | void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst) { |
| 108 | ctx.AddU32("{}=uint(gl_SubGroupGeMaskARB.x);", inst); | 122 | ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupGeMaskARB")); |
| 109 | } | 123 | } |
| 110 | 124 | ||
| 111 | void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value, | 125 | void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value, |
| 112 | std::string_view index, std::string_view clamp, | 126 | std::string_view index, std::string_view clamp, std::string_view seg_mask) { |
| 113 | std::string_view segmentation_mask) { | ||
| 114 | if (ctx.profile.support_gl_warp_intrinsics) { | 127 | if (ctx.profile.support_gl_warp_intrinsics) { |
| 115 | UseShuffleNv(ctx, inst, "shuffleNV", value, index, clamp, segmentation_mask); | 128 | UseShuffleNv(ctx, inst, "shuffleNV", value, index, clamp, seg_mask); |
| 116 | return; | 129 | return; |
| 117 | } | 130 | } |
| 118 | const auto not_seg_mask{fmt::format("(~{})", segmentation_mask)}; | 131 | const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest}; |
| 119 | const auto thread_id{"gl_SubGroupInvocationARB"}; | 132 | const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"}; |
| 120 | const auto min_thread_id{ComputeMinThreadId(thread_id, segmentation_mask)}; | 133 | const auto upper_index{fmt::format("{}?{}+32:{}", is_upper_partition, index, index)}; |
| 121 | const auto max_thread_id{ComputeMaxThreadId(min_thread_id, clamp, not_seg_mask)}; | 134 | const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)}; |
| 135 | |||
| 136 | const auto not_seg_mask{fmt::format("(~{})", seg_mask)}; | ||
| 137 | const auto min_thread_id{ComputeMinThreadId(THREAD_ID, seg_mask)}; | ||
| 138 | const auto max_thread_id{ | ||
| 139 | ComputeMaxThreadId(min_thread_id, big_warp ? upper_clamp : clamp, not_seg_mask)}; | ||
| 122 | 140 | ||
| 123 | const auto lhs{fmt::format("({}&{})", index, not_seg_mask)}; | 141 | const auto lhs{fmt::format("({}&{})", big_warp ? upper_index : index, not_seg_mask)}; |
| 124 | const auto src_thread_id{fmt::format("({})|({})", lhs, min_thread_id)}; | 142 | const auto src_thread_id{fmt::format("({})|({})", lhs, min_thread_id)}; |
| 125 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); | 143 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); |
| 126 | SetInBoundsFlag(ctx, inst); | 144 | SetInBoundsFlag(ctx, inst); |
| @@ -128,29 +146,34 @@ void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value, | |||
| 128 | } | 146 | } |
| 129 | 147 | ||
| 130 | void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index, | 148 | void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index, |
| 131 | std::string_view clamp, std::string_view segmentation_mask) { | 149 | std::string_view clamp, std::string_view seg_mask) { |
| 132 | if (ctx.profile.support_gl_warp_intrinsics) { | 150 | if (ctx.profile.support_gl_warp_intrinsics) { |
| 133 | UseShuffleNv(ctx, inst, "shuffleUpNV", value, index, clamp, segmentation_mask); | 151 | UseShuffleNv(ctx, inst, "shuffleUpNV", value, index, clamp, seg_mask); |
| 134 | return; | 152 | return; |
| 135 | } | 153 | } |
| 136 | const auto thread_id{"gl_SubGroupInvocationARB"}; | 154 | const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest}; |
| 137 | const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)}; | 155 | const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"}; |
| 138 | const auto src_thread_id{fmt::format("({}-{})", thread_id, index)}; | 156 | const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)}; |
| 157 | |||
| 158 | const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)}; | ||
| 159 | const auto src_thread_id{fmt::format("({}-{})", THREAD_ID, index)}; | ||
| 139 | ctx.Add("shfl_in_bounds=int({})>=int({});", src_thread_id, max_thread_id); | 160 | ctx.Add("shfl_in_bounds=int({})>=int({});", src_thread_id, max_thread_id); |
| 140 | SetInBoundsFlag(ctx, inst); | 161 | SetInBoundsFlag(ctx, inst); |
| 141 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); | 162 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); |
| 142 | } | 163 | } |
| 143 | 164 | ||
| 144 | void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value, | 165 | void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value, |
| 145 | std::string_view index, std::string_view clamp, | 166 | std::string_view index, std::string_view clamp, std::string_view seg_mask) { |
| 146 | std::string_view segmentation_mask) { | ||
| 147 | if (ctx.profile.support_gl_warp_intrinsics) { | 167 | if (ctx.profile.support_gl_warp_intrinsics) { |
| 148 | UseShuffleNv(ctx, inst, "shuffleDownNV", value, index, clamp, segmentation_mask); | 168 | UseShuffleNv(ctx, inst, "shuffleDownNV", value, index, clamp, seg_mask); |
| 149 | return; | 169 | return; |
| 150 | } | 170 | } |
| 151 | const auto thread_id{"gl_SubGroupInvocationARB"}; | 171 | const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest}; |
| 152 | const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)}; | 172 | const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"}; |
| 153 | const auto src_thread_id{fmt::format("({}+{})", thread_id, index)}; | 173 | const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)}; |
| 174 | |||
| 175 | const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)}; | ||
| 176 | const auto src_thread_id{fmt::format("({}+{})", THREAD_ID, index)}; | ||
| 154 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); | 177 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); |
| 155 | SetInBoundsFlag(ctx, inst); | 178 | SetInBoundsFlag(ctx, inst); |
| 156 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); | 179 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); |
| @@ -158,14 +181,17 @@ void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value, | |||
| 158 | 181 | ||
| 159 | void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value, | 182 | void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value, |
| 160 | std::string_view index, std::string_view clamp, | 183 | std::string_view index, std::string_view clamp, |
| 161 | std::string_view segmentation_mask) { | 184 | std::string_view seg_mask) { |
| 162 | if (ctx.profile.support_gl_warp_intrinsics) { | 185 | if (ctx.profile.support_gl_warp_intrinsics) { |
| 163 | UseShuffleNv(ctx, inst, "shuffleXorNV", value, index, clamp, segmentation_mask); | 186 | UseShuffleNv(ctx, inst, "shuffleXorNV", value, index, clamp, seg_mask); |
| 164 | return; | 187 | return; |
| 165 | } | 188 | } |
| 166 | const auto thread_id{"gl_SubGroupInvocationARB"}; | 189 | const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest}; |
| 167 | const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)}; | 190 | const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"}; |
| 168 | const auto src_thread_id{fmt::format("({}^{})", thread_id, index)}; | 191 | const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)}; |
| 192 | |||
| 193 | const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)}; | ||
| 194 | const auto src_thread_id{fmt::format("({}^{})", THREAD_ID, index)}; | ||
| 169 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); | 195 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); |
| 170 | SetInBoundsFlag(ctx, inst); | 196 | SetInBoundsFlag(ctx, inst); |
| 171 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); | 197 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); |
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 2d29d8c14..2885e6799 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -15,6 +15,8 @@ | |||
| 15 | 15 | ||
| 16 | namespace Shader::Backend::SPIRV { | 16 | namespace Shader::Backend::SPIRV { |
| 17 | namespace { | 17 | namespace { |
| 18 | constexpr size_t NUM_FIXEDFNCTEXTURE = 10; | ||
| 19 | |||
| 18 | enum class Operation { | 20 | enum class Operation { |
| 19 | Increment, | 21 | Increment, |
| 20 | Decrement, | 22 | Decrement, |
| @@ -427,6 +429,16 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) { | |||
| 427 | return pointer_type; | 429 | return pointer_type; |
| 428 | } | 430 | } |
| 429 | } | 431 | } |
| 432 | |||
| 433 | size_t FindNextUnusedLocation(const std::bitset<IR::NUM_GENERICS>& used_locations, | ||
| 434 | size_t start_offset) { | ||
| 435 | for (size_t location = start_offset; location < used_locations.size(); ++location) { | ||
| 436 | if (!used_locations.test(location)) { | ||
| 437 | return location; | ||
| 438 | } | ||
| 439 | } | ||
| 440 | throw RuntimeError("Unable to get an unused location for legacy attribute"); | ||
| 441 | } | ||
| 430 | } // Anonymous namespace | 442 | } // Anonymous namespace |
| 431 | 443 | ||
| 432 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { | 444 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { |
| @@ -1227,6 +1239,7 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1227 | loads[IR::Attribute::TessellationEvaluationPointV]) { | 1239 | loads[IR::Attribute::TessellationEvaluationPointV]) { |
| 1228 | tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord); | 1240 | tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord); |
| 1229 | } | 1241 | } |
| 1242 | std::bitset<IR::NUM_GENERICS> used_locations{}; | ||
| 1230 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { | 1243 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { |
| 1231 | const AttributeType input_type{runtime_info.generic_input_types[index]}; | 1244 | const AttributeType input_type{runtime_info.generic_input_types[index]}; |
| 1232 | if (!runtime_info.previous_stage_stores.Generic(index)) { | 1245 | if (!runtime_info.previous_stage_stores.Generic(index)) { |
| @@ -1238,6 +1251,7 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1238 | if (input_type == AttributeType::Disabled) { | 1251 | if (input_type == AttributeType::Disabled) { |
| 1239 | continue; | 1252 | continue; |
| 1240 | } | 1253 | } |
| 1254 | used_locations.set(index); | ||
| 1241 | const Id type{GetAttributeType(*this, input_type)}; | 1255 | const Id type{GetAttributeType(*this, input_type)}; |
| 1242 | const Id id{DefineInput(*this, type, true)}; | 1256 | const Id id{DefineInput(*this, type, true)}; |
| 1243 | Decorate(id, spv::Decoration::Location, static_cast<u32>(index)); | 1257 | Decorate(id, spv::Decoration::Location, static_cast<u32>(index)); |
| @@ -1263,6 +1277,26 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1263 | break; | 1277 | break; |
| 1264 | } | 1278 | } |
| 1265 | } | 1279 | } |
| 1280 | size_t previous_unused_location = 0; | ||
| 1281 | if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | ||
| 1282 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1283 | previous_unused_location = location; | ||
| 1284 | used_locations.set(location); | ||
| 1285 | const Id id{DefineInput(*this, F32[4], true)}; | ||
| 1286 | Decorate(id, spv::Decoration::Location, location); | ||
| 1287 | input_front_color = id; | ||
| 1288 | } | ||
| 1289 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | ||
| 1290 | if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | ||
| 1291 | const size_t location = | ||
| 1292 | FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1293 | previous_unused_location = location; | ||
| 1294 | used_locations.set(location); | ||
| 1295 | const Id id{DefineInput(*this, F32[4], true)}; | ||
| 1296 | Decorate(id, spv::Decoration::Location, location); | ||
| 1297 | input_fixed_fnc_textures[index] = id; | ||
| 1298 | } | ||
| 1299 | } | ||
| 1266 | if (stage == Stage::TessellationEval) { | 1300 | if (stage == Stage::TessellationEval) { |
| 1267 | for (size_t index = 0; index < info.uses_patches.size(); ++index) { | 1301 | for (size_t index = 0; index < info.uses_patches.size(); ++index) { |
| 1268 | if (!info.uses_patches[index]) { | 1302 | if (!info.uses_patches[index]) { |
| @@ -1313,9 +1347,31 @@ void EmitContext::DefineOutputs(const IR::Program& program) { | |||
| 1313 | viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt, | 1347 | viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt, |
| 1314 | spv::BuiltIn::ViewportMaskNV); | 1348 | spv::BuiltIn::ViewportMaskNV); |
| 1315 | } | 1349 | } |
| 1350 | std::bitset<IR::NUM_GENERICS> used_locations{}; | ||
| 1316 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { | 1351 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { |
| 1317 | if (info.stores.Generic(index)) { | 1352 | if (info.stores.Generic(index)) { |
| 1318 | DefineGenericOutput(*this, index, invocations); | 1353 | DefineGenericOutput(*this, index, invocations); |
| 1354 | used_locations.set(index); | ||
| 1355 | } | ||
| 1356 | } | ||
| 1357 | size_t previous_unused_location = 0; | ||
| 1358 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | ||
| 1359 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1360 | previous_unused_location = location; | ||
| 1361 | used_locations.set(location); | ||
| 1362 | const Id id{DefineOutput(*this, F32[4], invocations)}; | ||
| 1363 | Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); | ||
| 1364 | output_front_color = id; | ||
| 1365 | } | ||
| 1366 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | ||
| 1367 | if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | ||
| 1368 | const size_t location = | ||
| 1369 | FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1370 | previous_unused_location = location; | ||
| 1371 | used_locations.set(location); | ||
| 1372 | const Id id{DefineOutput(*this, F32[4], invocations)}; | ||
| 1373 | Decorate(id, spv::Decoration::Location, location); | ||
| 1374 | output_fixed_fnc_textures[index] = id; | ||
| 1319 | } | 1375 | } |
| 1320 | } | 1376 | } |
| 1321 | switch (stage) { | 1377 | switch (stage) { |
diff --git a/src/shader_recompiler/backend/spirv/emit_context.h b/src/shader_recompiler/backend/spirv/emit_context.h index e277bc358..847d0c0e6 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.h +++ b/src/shader_recompiler/backend/spirv/emit_context.h | |||
| @@ -268,10 +268,14 @@ public: | |||
| 268 | Id write_global_func_u32x4{}; | 268 | Id write_global_func_u32x4{}; |
| 269 | 269 | ||
| 270 | Id input_position{}; | 270 | Id input_position{}; |
| 271 | Id input_front_color{}; | ||
| 272 | std::array<Id, 10> input_fixed_fnc_textures{}; | ||
| 271 | std::array<Id, 32> input_generics{}; | 273 | std::array<Id, 32> input_generics{}; |
| 272 | 274 | ||
| 273 | Id output_point_size{}; | 275 | Id output_point_size{}; |
| 274 | Id output_position{}; | 276 | Id output_position{}; |
| 277 | Id output_front_color{}; | ||
| 278 | std::array<Id, 10> output_fixed_fnc_textures{}; | ||
| 275 | std::array<std::array<GenericElementInfo, 4>, 32> output_generics{}; | 279 | std::array<std::array<GenericElementInfo, 4>, 32> output_generics{}; |
| 276 | 280 | ||
| 277 | Id output_tess_level_outer{}; | 281 | Id output_tess_level_outer{}; |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index 9e54a17ee..6f60c6574 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp | |||
| @@ -43,6 +43,25 @@ Id AttrPointer(EmitContext& ctx, Id pointer_type, Id vertex, Id base, Args&&... | |||
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | bool IsFixedFncTexture(IR::Attribute attribute) { | ||
| 47 | return attribute >= IR::Attribute::FixedFncTexture0S && | ||
| 48 | attribute <= IR::Attribute::FixedFncTexture9Q; | ||
| 49 | } | ||
| 50 | |||
| 51 | u32 FixedFncTextureAttributeIndex(IR::Attribute attribute) { | ||
| 52 | if (!IsFixedFncTexture(attribute)) { | ||
| 53 | throw InvalidArgument("Attribute {} is not a FixedFncTexture", attribute); | ||
| 54 | } | ||
| 55 | return (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4u; | ||
| 56 | } | ||
| 57 | |||
| 58 | u32 FixedFncTextureAttributeElement(IR::Attribute attribute) { | ||
| 59 | if (!IsFixedFncTexture(attribute)) { | ||
| 60 | throw InvalidArgument("Attribute {} is not a FixedFncTexture", attribute); | ||
| 61 | } | ||
| 62 | return static_cast<u32>(attribute) % 4u; | ||
| 63 | } | ||
| 64 | |||
| 46 | template <typename... Args> | 65 | template <typename... Args> |
| 47 | Id OutputAccessChain(EmitContext& ctx, Id result_type, Id base, Args&&... args) { | 66 | Id OutputAccessChain(EmitContext& ctx, Id result_type, Id base, Args&&... args) { |
| 48 | if (ctx.stage == Stage::TessellationControl) { | 67 | if (ctx.stage == Stage::TessellationControl) { |
| @@ -74,6 +93,13 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { | |||
| 74 | return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id); | 93 | return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id); |
| 75 | } | 94 | } |
| 76 | } | 95 | } |
| 96 | if (IsFixedFncTexture(attr)) { | ||
| 97 | const u32 index{FixedFncTextureAttributeIndex(attr)}; | ||
| 98 | const u32 element{FixedFncTextureAttributeElement(attr)}; | ||
| 99 | const Id element_id{ctx.Const(element)}; | ||
| 100 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_fixed_fnc_textures[index], | ||
| 101 | element_id); | ||
| 102 | } | ||
| 77 | switch (attr) { | 103 | switch (attr) { |
| 78 | case IR::Attribute::PointSize: | 104 | case IR::Attribute::PointSize: |
| 79 | return ctx.output_point_size; | 105 | return ctx.output_point_size; |
| @@ -85,6 +111,14 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { | |||
| 85 | const Id element_id{ctx.Const(element)}; | 111 | const Id element_id{ctx.Const(element)}; |
| 86 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_position, element_id); | 112 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_position, element_id); |
| 87 | } | 113 | } |
| 114 | case IR::Attribute::ColorFrontDiffuseR: | ||
| 115 | case IR::Attribute::ColorFrontDiffuseG: | ||
| 116 | case IR::Attribute::ColorFrontDiffuseB: | ||
| 117 | case IR::Attribute::ColorFrontDiffuseA: { | ||
| 118 | const u32 element{static_cast<u32>(attr) % 4}; | ||
| 119 | const Id element_id{ctx.Const(element)}; | ||
| 120 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_front_color, element_id); | ||
| 121 | } | ||
| 88 | case IR::Attribute::ClipDistance0: | 122 | case IR::Attribute::ClipDistance0: |
| 89 | case IR::Attribute::ClipDistance1: | 123 | case IR::Attribute::ClipDistance1: |
| 90 | case IR::Attribute::ClipDistance2: | 124 | case IR::Attribute::ClipDistance2: |
| @@ -307,6 +341,12 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { | |||
| 307 | const Id value{ctx.OpLoad(type->id, pointer)}; | 341 | const Id value{ctx.OpLoad(type->id, pointer)}; |
| 308 | return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value; | 342 | return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value; |
| 309 | } | 343 | } |
| 344 | if (IsFixedFncTexture(attr)) { | ||
| 345 | const u32 index{FixedFncTextureAttributeIndex(attr)}; | ||
| 346 | const Id attr_id{ctx.input_fixed_fnc_textures[index]}; | ||
| 347 | const Id attr_ptr{AttrPointer(ctx, ctx.input_f32, vertex, attr_id, ctx.Const(element))}; | ||
| 348 | return ctx.OpLoad(ctx.F32[1], attr_ptr); | ||
| 349 | } | ||
| 310 | switch (attr) { | 350 | switch (attr) { |
| 311 | case IR::Attribute::PrimitiveId: | 351 | case IR::Attribute::PrimitiveId: |
| 312 | return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.primitive_id)); | 352 | return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.primitive_id)); |
| @@ -316,6 +356,13 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { | |||
| 316 | case IR::Attribute::PositionW: | 356 | case IR::Attribute::PositionW: |
| 317 | return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_position, | 357 | return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_position, |
| 318 | ctx.Const(element))); | 358 | ctx.Const(element))); |
| 359 | case IR::Attribute::ColorFrontDiffuseR: | ||
| 360 | case IR::Attribute::ColorFrontDiffuseG: | ||
| 361 | case IR::Attribute::ColorFrontDiffuseB: | ||
| 362 | case IR::Attribute::ColorFrontDiffuseA: { | ||
| 363 | return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_front_color, | ||
| 364 | ctx.Const(element))); | ||
| 365 | } | ||
| 319 | case IR::Attribute::InstanceId: | 366 | case IR::Attribute::InstanceId: |
| 320 | if (ctx.profile.support_vertex_instance_id) { | 367 | if (ctx.profile.support_vertex_instance_id) { |
| 321 | return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.instance_id)); | 368 | return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.instance_id)); |
| @@ -430,7 +477,13 @@ void EmitSetSampleMask(EmitContext& ctx, Id value) { | |||
| 430 | } | 477 | } |
| 431 | 478 | ||
| 432 | void EmitSetFragDepth(EmitContext& ctx, Id value) { | 479 | void EmitSetFragDepth(EmitContext& ctx, Id value) { |
| 433 | ctx.OpStore(ctx.frag_depth, value); | 480 | if (!ctx.runtime_info.convert_depth_mode) { |
| 481 | ctx.OpStore(ctx.frag_depth, value); | ||
| 482 | return; | ||
| 483 | } | ||
| 484 | const Id unit{ctx.Const(0.5f)}; | ||
| 485 | const Id new_depth{ctx.OpFma(ctx.F32[1], value, unit, unit)}; | ||
| 486 | ctx.OpStore(ctx.frag_depth, new_depth); | ||
| 434 | } | 487 | } |
| 435 | 488 | ||
| 436 | void EmitGetZFlag(EmitContext&) { | 489 | void EmitGetZFlag(EmitContext&) { |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_warp.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_warp.cpp index 78b1e1ba7..cef52c56e 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_warp.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_warp.cpp | |||
| @@ -7,8 +7,13 @@ | |||
| 7 | 7 | ||
| 8 | namespace Shader::Backend::SPIRV { | 8 | namespace Shader::Backend::SPIRV { |
| 9 | namespace { | 9 | namespace { |
| 10 | Id GetThreadId(EmitContext& ctx) { | ||
| 11 | return ctx.OpLoad(ctx.U32[1], ctx.subgroup_local_invocation_id); | ||
| 12 | } | ||
| 13 | |||
| 10 | Id WarpExtract(EmitContext& ctx, Id value) { | 14 | Id WarpExtract(EmitContext& ctx, Id value) { |
| 11 | const Id local_index{ctx.OpLoad(ctx.U32[1], ctx.subgroup_local_invocation_id)}; | 15 | const Id thread_id{GetThreadId(ctx)}; |
| 16 | const Id local_index{ctx.OpShiftRightArithmetic(ctx.U32[1], thread_id, ctx.Const(5U))}; | ||
| 12 | return ctx.OpVectorExtractDynamic(ctx.U32[1], value, local_index); | 17 | return ctx.OpVectorExtractDynamic(ctx.U32[1], value, local_index); |
| 13 | } | 18 | } |
| 14 | 19 | ||
| @@ -48,10 +53,17 @@ Id SelectValue(EmitContext& ctx, Id in_range, Id value, Id src_thread_id) { | |||
| 48 | return ctx.OpSelect(ctx.U32[1], in_range, | 53 | return ctx.OpSelect(ctx.U32[1], in_range, |
| 49 | ctx.OpSubgroupReadInvocationKHR(ctx.U32[1], value, src_thread_id), value); | 54 | ctx.OpSubgroupReadInvocationKHR(ctx.U32[1], value, src_thread_id), value); |
| 50 | } | 55 | } |
| 56 | |||
| 57 | Id GetUpperClamp(EmitContext& ctx, Id invocation_id, Id clamp) { | ||
| 58 | const Id thirty_two{ctx.Const(32u)}; | ||
| 59 | const Id is_upper_partition{ctx.OpSGreaterThanEqual(ctx.U1, invocation_id, thirty_two)}; | ||
| 60 | const Id upper_clamp{ctx.OpIAdd(ctx.U32[1], thirty_two, clamp)}; | ||
| 61 | return ctx.OpSelect(ctx.U32[1], is_upper_partition, upper_clamp, clamp); | ||
| 62 | } | ||
| 51 | } // Anonymous namespace | 63 | } // Anonymous namespace |
| 52 | 64 | ||
| 53 | Id EmitLaneId(EmitContext& ctx) { | 65 | Id EmitLaneId(EmitContext& ctx) { |
| 54 | const Id id{ctx.OpLoad(ctx.U32[1], ctx.subgroup_local_invocation_id)}; | 66 | const Id id{GetThreadId(ctx)}; |
| 55 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | 67 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { |
| 56 | return id; | 68 | return id; |
| 57 | } | 69 | } |
| @@ -123,7 +135,15 @@ Id EmitSubgroupGeMask(EmitContext& ctx) { | |||
| 123 | Id EmitShuffleIndex(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clamp, | 135 | Id EmitShuffleIndex(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clamp, |
| 124 | Id segmentation_mask) { | 136 | Id segmentation_mask) { |
| 125 | const Id not_seg_mask{ctx.OpNot(ctx.U32[1], segmentation_mask)}; | 137 | const Id not_seg_mask{ctx.OpNot(ctx.U32[1], segmentation_mask)}; |
| 126 | const Id thread_id{ctx.OpLoad(ctx.U32[1], ctx.subgroup_local_invocation_id)}; | 138 | const Id thread_id{GetThreadId(ctx)}; |
| 139 | if (ctx.profile.warp_size_potentially_larger_than_guest) { | ||
| 140 | const Id thirty_two{ctx.Const(32u)}; | ||
| 141 | const Id is_upper_partition{ctx.OpSGreaterThanEqual(ctx.U1, thread_id, thirty_two)}; | ||
| 142 | const Id upper_index{ctx.OpIAdd(ctx.U32[1], thirty_two, index)}; | ||
| 143 | const Id upper_clamp{ctx.OpIAdd(ctx.U32[1], thirty_two, clamp)}; | ||
| 144 | index = ctx.OpSelect(ctx.U32[1], is_upper_partition, upper_index, index); | ||
| 145 | clamp = ctx.OpSelect(ctx.U32[1], is_upper_partition, upper_clamp, clamp); | ||
| 146 | } | ||
| 127 | const Id min_thread_id{ComputeMinThreadId(ctx, thread_id, segmentation_mask)}; | 147 | const Id min_thread_id{ComputeMinThreadId(ctx, thread_id, segmentation_mask)}; |
| 128 | const Id max_thread_id{ComputeMaxThreadId(ctx, min_thread_id, clamp, not_seg_mask)}; | 148 | const Id max_thread_id{ComputeMaxThreadId(ctx, min_thread_id, clamp, not_seg_mask)}; |
| 129 | 149 | ||
| @@ -137,7 +157,10 @@ Id EmitShuffleIndex(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id cla | |||
| 137 | 157 | ||
| 138 | Id EmitShuffleUp(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clamp, | 158 | Id EmitShuffleUp(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clamp, |
| 139 | Id segmentation_mask) { | 159 | Id segmentation_mask) { |
| 140 | const Id thread_id{ctx.OpLoad(ctx.U32[1], ctx.subgroup_local_invocation_id)}; | 160 | const Id thread_id{GetThreadId(ctx)}; |
| 161 | if (ctx.profile.warp_size_potentially_larger_than_guest) { | ||
| 162 | clamp = GetUpperClamp(ctx, thread_id, clamp); | ||
| 163 | } | ||
| 141 | const Id max_thread_id{GetMaxThreadId(ctx, thread_id, clamp, segmentation_mask)}; | 164 | const Id max_thread_id{GetMaxThreadId(ctx, thread_id, clamp, segmentation_mask)}; |
| 142 | const Id src_thread_id{ctx.OpISub(ctx.U32[1], thread_id, index)}; | 165 | const Id src_thread_id{ctx.OpISub(ctx.U32[1], thread_id, index)}; |
| 143 | const Id in_range{ctx.OpSGreaterThanEqual(ctx.U1, src_thread_id, max_thread_id)}; | 166 | const Id in_range{ctx.OpSGreaterThanEqual(ctx.U1, src_thread_id, max_thread_id)}; |
| @@ -148,7 +171,10 @@ Id EmitShuffleUp(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clamp, | |||
| 148 | 171 | ||
| 149 | Id EmitShuffleDown(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clamp, | 172 | Id EmitShuffleDown(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clamp, |
| 150 | Id segmentation_mask) { | 173 | Id segmentation_mask) { |
| 151 | const Id thread_id{ctx.OpLoad(ctx.U32[1], ctx.subgroup_local_invocation_id)}; | 174 | const Id thread_id{GetThreadId(ctx)}; |
| 175 | if (ctx.profile.warp_size_potentially_larger_than_guest) { | ||
| 176 | clamp = GetUpperClamp(ctx, thread_id, clamp); | ||
| 177 | } | ||
| 152 | const Id max_thread_id{GetMaxThreadId(ctx, thread_id, clamp, segmentation_mask)}; | 178 | const Id max_thread_id{GetMaxThreadId(ctx, thread_id, clamp, segmentation_mask)}; |
| 153 | const Id src_thread_id{ctx.OpIAdd(ctx.U32[1], thread_id, index)}; | 179 | const Id src_thread_id{ctx.OpIAdd(ctx.U32[1], thread_id, index)}; |
| 154 | const Id in_range{ctx.OpSLessThanEqual(ctx.U1, src_thread_id, max_thread_id)}; | 180 | const Id in_range{ctx.OpSLessThanEqual(ctx.U1, src_thread_id, max_thread_id)}; |
| @@ -159,7 +185,10 @@ Id EmitShuffleDown(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clam | |||
| 159 | 185 | ||
| 160 | Id EmitShuffleButterfly(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clamp, | 186 | Id EmitShuffleButterfly(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clamp, |
| 161 | Id segmentation_mask) { | 187 | Id segmentation_mask) { |
| 162 | const Id thread_id{ctx.OpLoad(ctx.U32[1], ctx.subgroup_local_invocation_id)}; | 188 | const Id thread_id{GetThreadId(ctx)}; |
| 189 | if (ctx.profile.warp_size_potentially_larger_than_guest) { | ||
| 190 | clamp = GetUpperClamp(ctx, thread_id, clamp); | ||
| 191 | } | ||
| 163 | const Id max_thread_id{GetMaxThreadId(ctx, thread_id, clamp, segmentation_mask)}; | 192 | const Id max_thread_id{GetMaxThreadId(ctx, thread_id, clamp, segmentation_mask)}; |
| 164 | const Id src_thread_id{ctx.OpBitwiseXor(ctx.U32[1], thread_id, index)}; | 193 | const Id src_thread_id{ctx.OpBitwiseXor(ctx.U32[1], thread_id, index)}; |
| 165 | const Id in_range{ctx.OpSLessThanEqual(ctx.U1, src_thread_id, max_thread_id)}; | 194 | const Id in_range{ctx.OpSLessThanEqual(ctx.U1, src_thread_id, max_thread_id)}; |
diff --git a/src/shader_recompiler/object_pool.h b/src/shader_recompiler/object_pool.h index f3b12d04b..a12ddcc8f 100644 --- a/src/shader_recompiler/object_pool.h +++ b/src/shader_recompiler/object_pool.h | |||
| @@ -11,14 +11,16 @@ | |||
| 11 | namespace Shader { | 11 | namespace Shader { |
| 12 | 12 | ||
| 13 | template <typename T> | 13 | template <typename T> |
| 14 | requires std::is_destructible_v<T> class ObjectPool { | 14 | requires std::is_destructible_v<T> |
| 15 | class ObjectPool { | ||
| 15 | public: | 16 | public: |
| 16 | explicit ObjectPool(size_t chunk_size = 8192) : new_chunk_size{chunk_size} { | 17 | explicit ObjectPool(size_t chunk_size = 8192) : new_chunk_size{chunk_size} { |
| 17 | node = &chunks.emplace_back(new_chunk_size); | 18 | node = &chunks.emplace_back(new_chunk_size); |
| 18 | } | 19 | } |
| 19 | 20 | ||
| 20 | template <typename... Args> | 21 | template <typename... Args> |
| 21 | requires std::is_constructible_v<T, Args...>[[nodiscard]] T* Create(Args&&... args) { | 22 | requires std::is_constructible_v<T, Args...> |
| 23 | [[nodiscard]] T* Create(Args&&... args) { | ||
| 22 | return std::construct_at(Memory(), std::forward<Args>(args)...); | 24 | return std::construct_at(Memory(), std::forward<Args>(args)...); |
| 23 | } | 25 | } |
| 24 | 26 | ||
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 2f6cdd216..269db21a5 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -231,6 +231,7 @@ endif() | |||
| 231 | 231 | ||
| 232 | target_include_directories(video_core PRIVATE ${FFmpeg_INCLUDE_DIR}) | 232 | target_include_directories(video_core PRIVATE ${FFmpeg_INCLUDE_DIR}) |
| 233 | target_link_libraries(video_core PRIVATE ${FFmpeg_LIBRARIES}) | 233 | target_link_libraries(video_core PRIVATE ${FFmpeg_LIBRARIES}) |
| 234 | target_link_options(video_core PRIVATE ${FFmpeg_LDFLAGS}) | ||
| 234 | 235 | ||
| 235 | add_dependencies(video_core host_shaders) | 236 | add_dependencies(video_core host_shaders) |
| 236 | target_include_directories(video_core PRIVATE ${HOST_SHADERS_INCLUDE}) | 237 | target_include_directories(video_core PRIVATE ${HOST_SHADERS_INCLUDE}) |
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 7bfd57369..d350c9b36 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h | |||
| @@ -570,13 +570,12 @@ bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 am | |||
| 570 | ForEachWrittenRange(*cpu_src_address, amount, mirror); | 570 | ForEachWrittenRange(*cpu_src_address, amount, mirror); |
| 571 | // This subtraction in this order is important for overlapping copies. | 571 | // This subtraction in this order is important for overlapping copies. |
| 572 | common_ranges.subtract(subtract_interval); | 572 | common_ranges.subtract(subtract_interval); |
| 573 | bool atleast_1_download = tmp_intervals.size() != 0; | 573 | const bool has_new_downloads = tmp_intervals.size() != 0; |
| 574 | for (const IntervalType add_interval : tmp_intervals) { | 574 | for (const IntervalType& add_interval : tmp_intervals) { |
| 575 | common_ranges.add(add_interval); | 575 | common_ranges.add(add_interval); |
| 576 | } | 576 | } |
| 577 | |||
| 578 | runtime.CopyBuffer(dest_buffer, src_buffer, copies); | 577 | runtime.CopyBuffer(dest_buffer, src_buffer, copies); |
| 579 | if (atleast_1_download) { | 578 | if (has_new_downloads) { |
| 580 | dest_buffer.MarkRegionAsGpuModified(*cpu_dest_address, amount); | 579 | dest_buffer.MarkRegionAsGpuModified(*cpu_dest_address, amount); |
| 581 | } | 580 | } |
| 582 | std::vector<u8> tmp_buffer(amount); | 581 | std::vector<u8> tmp_buffer(amount); |
diff --git a/src/video_core/command_classes/codecs/codec.cpp b/src/video_core/command_classes/codecs/codec.cpp index f798a0053..61966cbfe 100644 --- a/src/video_core/command_classes/codecs/codec.cpp +++ b/src/video_core/command_classes/codecs/codec.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <fstream> | 5 | #include <fstream> |
| 6 | #include <vector> | 6 | #include <vector> |
| 7 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 8 | #include "common/settings.h" | ||
| 8 | #include "video_core/command_classes/codecs/codec.h" | 9 | #include "video_core/command_classes/codecs/codec.h" |
| 9 | #include "video_core/command_classes/codecs/h264.h" | 10 | #include "video_core/command_classes/codecs/h264.h" |
| 10 | #include "video_core/command_classes/codecs/vp9.h" | 11 | #include "video_core/command_classes/codecs/vp9.h" |
| @@ -16,108 +17,146 @@ extern "C" { | |||
| 16 | } | 17 | } |
| 17 | 18 | ||
| 18 | namespace Tegra { | 19 | namespace Tegra { |
| 19 | #if defined(LIBVA_FOUND) | ||
| 20 | // Hardware acceleration code from FFmpeg/doc/examples/hw_decode.c originally under MIT license | ||
| 21 | namespace { | 20 | namespace { |
| 22 | constexpr std::array<const char*, 2> VAAPI_DRIVERS = { | 21 | constexpr AVPixelFormat PREFERRED_GPU_FMT = AV_PIX_FMT_NV12; |
| 23 | "i915", | 22 | constexpr AVPixelFormat PREFERRED_CPU_FMT = AV_PIX_FMT_YUV420P; |
| 24 | "amdgpu", | 23 | |
| 25 | }; | 24 | void AVPacketDeleter(AVPacket* ptr) { |
| 25 | av_packet_free(&ptr); | ||
| 26 | } | ||
| 26 | 27 | ||
| 27 | AVPixelFormat GetHwFormat(AVCodecContext*, const AVPixelFormat* pix_fmts) { | 28 | using AVPacketPtr = std::unique_ptr<AVPacket, decltype(&AVPacketDeleter)>; |
| 29 | |||
| 30 | AVPixelFormat GetGpuFormat(AVCodecContext* av_codec_ctx, const AVPixelFormat* pix_fmts) { | ||
| 28 | for (const AVPixelFormat* p = pix_fmts; *p != AV_PIX_FMT_NONE; ++p) { | 31 | for (const AVPixelFormat* p = pix_fmts; *p != AV_PIX_FMT_NONE; ++p) { |
| 29 | if (*p == AV_PIX_FMT_VAAPI) { | 32 | if (*p == av_codec_ctx->pix_fmt) { |
| 30 | return AV_PIX_FMT_VAAPI; | 33 | return av_codec_ctx->pix_fmt; |
| 31 | } | 34 | } |
| 32 | } | 35 | } |
| 33 | LOG_INFO(Service_NVDRV, "Could not find compatible GPU AV format, falling back to CPU"); | 36 | LOG_INFO(Service_NVDRV, "Could not find compatible GPU AV format, falling back to CPU"); |
| 34 | return *pix_fmts; | 37 | av_buffer_unref(&av_codec_ctx->hw_device_ctx); |
| 38 | av_codec_ctx->pix_fmt = PREFERRED_CPU_FMT; | ||
| 39 | return PREFERRED_CPU_FMT; | ||
| 40 | } | ||
| 41 | } // namespace | ||
| 42 | |||
| 43 | void AVFrameDeleter(AVFrame* ptr) { | ||
| 44 | av_frame_free(&ptr); | ||
| 35 | } | 45 | } |
| 36 | 46 | ||
| 37 | bool CreateVaapiHwdevice(AVBufferRef** av_hw_device) { | 47 | Codec::Codec(GPU& gpu_, const NvdecCommon::NvdecRegisters& regs) |
| 48 | : gpu(gpu_), state{regs}, h264_decoder(std::make_unique<Decoder::H264>(gpu)), | ||
| 49 | vp9_decoder(std::make_unique<Decoder::VP9>(gpu)) {} | ||
| 50 | |||
| 51 | Codec::~Codec() { | ||
| 52 | if (!initialized) { | ||
| 53 | return; | ||
| 54 | } | ||
| 55 | // Free libav memory | ||
| 56 | avcodec_free_context(&av_codec_ctx); | ||
| 57 | av_buffer_unref(&av_gpu_decoder); | ||
| 58 | } | ||
| 59 | |||
| 60 | bool Codec::CreateGpuAvDevice() { | ||
| 61 | #if defined(LIBVA_FOUND) | ||
| 62 | static constexpr std::array<const char*, 3> VAAPI_DRIVERS = { | ||
| 63 | "i915", | ||
| 64 | "iHD", | ||
| 65 | "amdgpu", | ||
| 66 | }; | ||
| 38 | AVDictionary* hwdevice_options = nullptr; | 67 | AVDictionary* hwdevice_options = nullptr; |
| 39 | av_dict_set(&hwdevice_options, "connection_type", "drm", 0); | 68 | av_dict_set(&hwdevice_options, "connection_type", "drm", 0); |
| 40 | for (const auto& driver : VAAPI_DRIVERS) { | 69 | for (const auto& driver : VAAPI_DRIVERS) { |
| 41 | av_dict_set(&hwdevice_options, "kernel_driver", driver, 0); | 70 | av_dict_set(&hwdevice_options, "kernel_driver", driver, 0); |
| 42 | const int hwdevice_error = av_hwdevice_ctx_create(av_hw_device, AV_HWDEVICE_TYPE_VAAPI, | 71 | const int hwdevice_error = av_hwdevice_ctx_create(&av_gpu_decoder, AV_HWDEVICE_TYPE_VAAPI, |
| 43 | nullptr, hwdevice_options, 0); | 72 | nullptr, hwdevice_options, 0); |
| 44 | if (hwdevice_error >= 0) { | 73 | if (hwdevice_error >= 0) { |
| 45 | LOG_INFO(Service_NVDRV, "Using VA-API with {}", driver); | 74 | LOG_INFO(Service_NVDRV, "Using VA-API with {}", driver); |
| 46 | av_dict_free(&hwdevice_options); | 75 | av_dict_free(&hwdevice_options); |
| 76 | av_codec_ctx->pix_fmt = AV_PIX_FMT_VAAPI; | ||
| 47 | return true; | 77 | return true; |
| 48 | } | 78 | } |
| 49 | LOG_DEBUG(Service_NVDRV, "VA-API av_hwdevice_ctx_create failed {}", hwdevice_error); | 79 | LOG_DEBUG(Service_NVDRV, "VA-API av_hwdevice_ctx_create failed {}", hwdevice_error); |
| 50 | } | 80 | } |
| 51 | LOG_DEBUG(Service_NVDRV, "VA-API av_hwdevice_ctx_create failed for all drivers"); | 81 | LOG_DEBUG(Service_NVDRV, "VA-API av_hwdevice_ctx_create failed for all drivers"); |
| 52 | av_dict_free(&hwdevice_options); | 82 | av_dict_free(&hwdevice_options); |
| 53 | return false; | ||
| 54 | } | ||
| 55 | } // namespace | ||
| 56 | #endif | 83 | #endif |
| 57 | 84 | static constexpr auto HW_CONFIG_METHOD = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX; | |
| 58 | void AVFrameDeleter(AVFrame* ptr) { | 85 | static constexpr std::array GPU_DECODER_TYPES{ |
| 59 | av_frame_free(&ptr); | 86 | AV_HWDEVICE_TYPE_CUDA, |
| 87 | #ifdef _WIN32 | ||
| 88 | AV_HWDEVICE_TYPE_D3D11VA, | ||
| 89 | #else | ||
| 90 | AV_HWDEVICE_TYPE_VDPAU, | ||
| 91 | #endif | ||
| 92 | }; | ||
| 93 | for (const auto& type : GPU_DECODER_TYPES) { | ||
| 94 | const int hwdevice_res = av_hwdevice_ctx_create(&av_gpu_decoder, type, nullptr, nullptr, 0); | ||
| 95 | if (hwdevice_res < 0) { | ||
| 96 | LOG_DEBUG(Service_NVDRV, "{} av_hwdevice_ctx_create failed {}", | ||
| 97 | av_hwdevice_get_type_name(type), hwdevice_res); | ||
| 98 | continue; | ||
| 99 | } | ||
| 100 | for (int i = 0;; i++) { | ||
| 101 | const AVCodecHWConfig* config = avcodec_get_hw_config(av_codec, i); | ||
| 102 | if (!config) { | ||
| 103 | LOG_DEBUG(Service_NVDRV, "{} decoder does not support device type {}.", | ||
| 104 | av_codec->name, av_hwdevice_get_type_name(type)); | ||
| 105 | break; | ||
| 106 | } | ||
| 107 | if (config->methods & HW_CONFIG_METHOD && config->device_type == type) { | ||
| 108 | av_codec_ctx->pix_fmt = config->pix_fmt; | ||
| 109 | LOG_INFO(Service_NVDRV, "Using {} GPU decoder", av_hwdevice_get_type_name(type)); | ||
| 110 | return true; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | return false; | ||
| 60 | } | 115 | } |
| 61 | 116 | ||
| 62 | Codec::Codec(GPU& gpu_, const NvdecCommon::NvdecRegisters& regs) | 117 | void Codec::InitializeAvCodecContext() { |
| 63 | : gpu(gpu_), state{regs}, h264_decoder(std::make_unique<Decoder::H264>(gpu)), | 118 | av_codec_ctx = avcodec_alloc_context3(av_codec); |
| 64 | vp9_decoder(std::make_unique<Decoder::VP9>(gpu)) {} | 119 | av_opt_set(av_codec_ctx->priv_data, "tune", "zerolatency", 0); |
| 65 | |||
| 66 | Codec::~Codec() { | ||
| 67 | if (!initialized) { | ||
| 68 | return; | ||
| 69 | } | ||
| 70 | // Free libav memory | ||
| 71 | avcodec_send_packet(av_codec_ctx, nullptr); | ||
| 72 | AVFrame* av_frame = av_frame_alloc(); | ||
| 73 | avcodec_receive_frame(av_codec_ctx, av_frame); | ||
| 74 | avcodec_flush_buffers(av_codec_ctx); | ||
| 75 | av_frame_free(&av_frame); | ||
| 76 | avcodec_close(av_codec_ctx); | ||
| 77 | av_buffer_unref(&av_hw_device); | ||
| 78 | } | 120 | } |
| 79 | 121 | ||
| 80 | void Codec::InitializeHwdec() { | 122 | void Codec::InitializeGpuDecoder() { |
| 81 | // Prioritize integrated GPU to mitigate bandwidth bottlenecks | 123 | if (!CreateGpuAvDevice()) { |
| 82 | #if defined(LIBVA_FOUND) | 124 | av_buffer_unref(&av_gpu_decoder); |
| 83 | if (CreateVaapiHwdevice(&av_hw_device)) { | ||
| 84 | const auto hw_device_ctx = av_buffer_ref(av_hw_device); | ||
| 85 | ASSERT_MSG(hw_device_ctx, "av_buffer_ref failed"); | ||
| 86 | av_codec_ctx->hw_device_ctx = hw_device_ctx; | ||
| 87 | av_codec_ctx->get_format = GetHwFormat; | ||
| 88 | return; | 125 | return; |
| 89 | } | 126 | } |
| 90 | #endif | 127 | auto* hw_device_ctx = av_buffer_ref(av_gpu_decoder); |
| 91 | // TODO more GPU accelerated decoders | 128 | ASSERT_MSG(hw_device_ctx, "av_buffer_ref failed"); |
| 129 | av_codec_ctx->hw_device_ctx = hw_device_ctx; | ||
| 130 | av_codec_ctx->get_format = GetGpuFormat; | ||
| 92 | } | 131 | } |
| 93 | 132 | ||
| 94 | void Codec::Initialize() { | 133 | void Codec::Initialize() { |
| 95 | AVCodecID codec; | 134 | const AVCodecID codec = [&] { |
| 96 | switch (current_codec) { | 135 | switch (current_codec) { |
| 97 | case NvdecCommon::VideoCodec::H264: | 136 | case NvdecCommon::VideoCodec::H264: |
| 98 | codec = AV_CODEC_ID_H264; | 137 | return AV_CODEC_ID_H264; |
| 99 | break; | 138 | case NvdecCommon::VideoCodec::Vp9: |
| 100 | case NvdecCommon::VideoCodec::Vp9: | 139 | return AV_CODEC_ID_VP9; |
| 101 | codec = AV_CODEC_ID_VP9; | 140 | default: |
| 102 | break; | 141 | UNIMPLEMENTED_MSG("Unknown codec {}", current_codec); |
| 103 | default: | 142 | return AV_CODEC_ID_NONE; |
| 104 | UNIMPLEMENTED_MSG("Unknown codec {}", current_codec); | 143 | } |
| 144 | }(); | ||
| 145 | av_codec = avcodec_find_decoder(codec); | ||
| 146 | |||
| 147 | InitializeAvCodecContext(); | ||
| 148 | if (Settings::values.nvdec_emulation.GetValue() == Settings::NvdecEmulation::GPU) { | ||
| 149 | InitializeGpuDecoder(); | ||
| 150 | } | ||
| 151 | if (const int res = avcodec_open2(av_codec_ctx, av_codec, nullptr); res < 0) { | ||
| 152 | LOG_ERROR(Service_NVDRV, "avcodec_open2() Failed with result {}", res); | ||
| 153 | avcodec_free_context(&av_codec_ctx); | ||
| 154 | av_buffer_unref(&av_gpu_decoder); | ||
| 105 | return; | 155 | return; |
| 106 | } | 156 | } |
| 107 | av_codec = avcodec_find_decoder(codec); | ||
| 108 | av_codec_ctx = avcodec_alloc_context3(av_codec); | ||
| 109 | av_opt_set(av_codec_ctx->priv_data, "tune", "zerolatency", 0); | ||
| 110 | InitializeHwdec(); | ||
| 111 | if (!av_codec_ctx->hw_device_ctx) { | 157 | if (!av_codec_ctx->hw_device_ctx) { |
| 112 | LOG_INFO(Service_NVDRV, "Using FFmpeg software decoding"); | 158 | LOG_INFO(Service_NVDRV, "Using FFmpeg software decoding"); |
| 113 | } | 159 | } |
| 114 | const auto av_error = avcodec_open2(av_codec_ctx, av_codec, nullptr); | ||
| 115 | if (av_error < 0) { | ||
| 116 | LOG_ERROR(Service_NVDRV, "avcodec_open2() Failed."); | ||
| 117 | avcodec_close(av_codec_ctx); | ||
| 118 | av_buffer_unref(&av_hw_device); | ||
| 119 | return; | ||
| 120 | } | ||
| 121 | initialized = true; | 160 | initialized = true; |
| 122 | } | 161 | } |
| 123 | 162 | ||
| @@ -133,6 +172,9 @@ void Codec::Decode() { | |||
| 133 | if (is_first_frame) { | 172 | if (is_first_frame) { |
| 134 | Initialize(); | 173 | Initialize(); |
| 135 | } | 174 | } |
| 175 | if (!initialized) { | ||
| 176 | return; | ||
| 177 | } | ||
| 136 | bool vp9_hidden_frame = false; | 178 | bool vp9_hidden_frame = false; |
| 137 | std::vector<u8> frame_data; | 179 | std::vector<u8> frame_data; |
| 138 | if (current_codec == NvdecCommon::VideoCodec::H264) { | 180 | if (current_codec == NvdecCommon::VideoCodec::H264) { |
| @@ -141,50 +183,48 @@ void Codec::Decode() { | |||
| 141 | frame_data = vp9_decoder->ComposeFrameHeader(state); | 183 | frame_data = vp9_decoder->ComposeFrameHeader(state); |
| 142 | vp9_hidden_frame = vp9_decoder->WasFrameHidden(); | 184 | vp9_hidden_frame = vp9_decoder->WasFrameHidden(); |
| 143 | } | 185 | } |
| 144 | AVPacket packet{}; | 186 | AVPacketPtr packet{av_packet_alloc(), AVPacketDeleter}; |
| 145 | av_init_packet(&packet); | 187 | if (!packet) { |
| 146 | packet.data = frame_data.data(); | 188 | LOG_ERROR(Service_NVDRV, "av_packet_alloc failed"); |
| 147 | packet.size = static_cast<s32>(frame_data.size()); | 189 | return; |
| 148 | if (const int ret = avcodec_send_packet(av_codec_ctx, &packet); ret) { | 190 | } |
| 149 | LOG_DEBUG(Service_NVDRV, "avcodec_send_packet error {}", ret); | 191 | packet->data = frame_data.data(); |
| 192 | packet->size = static_cast<s32>(frame_data.size()); | ||
| 193 | if (const int res = avcodec_send_packet(av_codec_ctx, packet.get()); res != 0) { | ||
| 194 | LOG_DEBUG(Service_NVDRV, "avcodec_send_packet error {}", res); | ||
| 150 | return; | 195 | return; |
| 151 | } | 196 | } |
| 152 | // Only receive/store visible frames | 197 | // Only receive/store visible frames |
| 153 | if (vp9_hidden_frame) { | 198 | if (vp9_hidden_frame) { |
| 154 | return; | 199 | return; |
| 155 | } | 200 | } |
| 156 | AVFrame* hw_frame = av_frame_alloc(); | 201 | AVFramePtr initial_frame{av_frame_alloc(), AVFrameDeleter}; |
| 157 | AVFrame* sw_frame = hw_frame; | 202 | AVFramePtr final_frame{nullptr, AVFrameDeleter}; |
| 158 | ASSERT_MSG(hw_frame, "av_frame_alloc hw_frame failed"); | 203 | ASSERT_MSG(initial_frame, "av_frame_alloc initial_frame failed"); |
| 159 | if (const int ret = avcodec_receive_frame(av_codec_ctx, hw_frame); ret) { | 204 | if (const int ret = avcodec_receive_frame(av_codec_ctx, initial_frame.get()); ret) { |
| 160 | LOG_DEBUG(Service_NVDRV, "avcodec_receive_frame error {}", ret); | 205 | LOG_DEBUG(Service_NVDRV, "avcodec_receive_frame error {}", ret); |
| 161 | av_frame_free(&hw_frame); | ||
| 162 | return; | 206 | return; |
| 163 | } | 207 | } |
| 164 | if (!hw_frame->width || !hw_frame->height) { | 208 | if (initial_frame->width == 0 || initial_frame->height == 0) { |
| 165 | LOG_WARNING(Service_NVDRV, "Zero width or height in frame"); | 209 | LOG_WARNING(Service_NVDRV, "Zero width or height in frame"); |
| 166 | av_frame_free(&hw_frame); | ||
| 167 | return; | 210 | return; |
| 168 | } | 211 | } |
| 169 | #if defined(LIBVA_FOUND) | 212 | if (av_codec_ctx->hw_device_ctx) { |
| 170 | // Hardware acceleration code from FFmpeg/doc/examples/hw_decode.c under MIT license | 213 | final_frame = AVFramePtr{av_frame_alloc(), AVFrameDeleter}; |
| 171 | if (hw_frame->format == AV_PIX_FMT_VAAPI) { | 214 | ASSERT_MSG(final_frame, "av_frame_alloc final_frame failed"); |
| 172 | sw_frame = av_frame_alloc(); | ||
| 173 | ASSERT_MSG(sw_frame, "av_frame_alloc sw_frame failed"); | ||
| 174 | // Can't use AV_PIX_FMT_YUV420P and share code with software decoding in vic.cpp | 215 | // Can't use AV_PIX_FMT_YUV420P and share code with software decoding in vic.cpp |
| 175 | // because Intel drivers crash unless using AV_PIX_FMT_NV12 | 216 | // because Intel drivers crash unless using AV_PIX_FMT_NV12 |
| 176 | sw_frame->format = AV_PIX_FMT_NV12; | 217 | final_frame->format = PREFERRED_GPU_FMT; |
| 177 | const int transfer_data_ret = av_hwframe_transfer_data(sw_frame, hw_frame, 0); | 218 | const int ret = av_hwframe_transfer_data(final_frame.get(), initial_frame.get(), 0); |
| 178 | ASSERT_MSG(!transfer_data_ret, "av_hwframe_transfer_data error {}", transfer_data_ret); | 219 | ASSERT_MSG(!ret, "av_hwframe_transfer_data error {}", ret); |
| 179 | av_frame_free(&hw_frame); | 220 | } else { |
| 221 | final_frame = std::move(initial_frame); | ||
| 180 | } | 222 | } |
| 181 | #endif | 223 | if (final_frame->format != PREFERRED_CPU_FMT && final_frame->format != PREFERRED_GPU_FMT) { |
| 182 | if (sw_frame->format != AV_PIX_FMT_YUV420P && sw_frame->format != AV_PIX_FMT_NV12) { | 224 | UNIMPLEMENTED_MSG("Unexpected video format: {}", final_frame->format); |
| 183 | UNIMPLEMENTED_MSG("Unexpected video format from host graphics: {}", sw_frame->format); | ||
| 184 | av_frame_free(&sw_frame); | ||
| 185 | return; | 225 | return; |
| 186 | } | 226 | } |
| 187 | av_frames.push(AVFramePtr{sw_frame, AVFrameDeleter}); | 227 | av_frames.push(std::move(final_frame)); |
| 188 | if (av_frames.size() > 10) { | 228 | if (av_frames.size() > 10) { |
| 189 | LOG_TRACE(Service_NVDRV, "av_frames.push overflow dropped frame"); | 229 | LOG_TRACE(Service_NVDRV, "av_frames.push overflow dropped frame"); |
| 190 | av_frames.pop(); | 230 | av_frames.pop(); |
diff --git a/src/video_core/command_classes/codecs/codec.h b/src/video_core/command_classes/codecs/codec.h index 71936203f..f9a80886f 100644 --- a/src/video_core/command_classes/codecs/codec.h +++ b/src/video_core/command_classes/codecs/codec.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <string_view> | ||
| 8 | #include <queue> | 9 | #include <queue> |
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 10 | #include "video_core/command_classes/nvdec_common.h" | 11 | #include "video_core/command_classes/nvdec_common.h" |
| @@ -50,18 +51,23 @@ public: | |||
| 50 | 51 | ||
| 51 | /// Returns the value of current_codec | 52 | /// Returns the value of current_codec |
| 52 | [[nodiscard]] NvdecCommon::VideoCodec GetCurrentCodec() const; | 53 | [[nodiscard]] NvdecCommon::VideoCodec GetCurrentCodec() const; |
| 54 | |||
| 53 | /// Return name of the current codec | 55 | /// Return name of the current codec |
| 54 | [[nodiscard]] std::string_view GetCurrentCodecName() const; | 56 | [[nodiscard]] std::string_view GetCurrentCodecName() const; |
| 55 | 57 | ||
| 56 | private: | 58 | private: |
| 57 | void InitializeHwdec(); | 59 | void InitializeAvCodecContext(); |
| 60 | |||
| 61 | void InitializeGpuDecoder(); | ||
| 62 | |||
| 63 | bool CreateGpuAvDevice(); | ||
| 58 | 64 | ||
| 59 | bool initialized{}; | 65 | bool initialized{}; |
| 60 | NvdecCommon::VideoCodec current_codec{NvdecCommon::VideoCodec::None}; | 66 | NvdecCommon::VideoCodec current_codec{NvdecCommon::VideoCodec::None}; |
| 61 | 67 | ||
| 62 | AVCodec* av_codec{nullptr}; | 68 | AVCodec* av_codec{nullptr}; |
| 63 | AVBufferRef* av_hw_device{nullptr}; | ||
| 64 | AVCodecContext* av_codec_ctx{nullptr}; | 69 | AVCodecContext* av_codec_ctx{nullptr}; |
| 70 | AVBufferRef* av_gpu_decoder{nullptr}; | ||
| 65 | 71 | ||
| 66 | GPU& gpu; | 72 | GPU& gpu; |
| 67 | const NvdecCommon::NvdecRegisters& state; | 73 | const NvdecCommon::NvdecRegisters& state; |
diff --git a/src/video_core/command_classes/codecs/h264.cpp b/src/video_core/command_classes/codecs/h264.cpp index 5fb6d45ee..51ee14c13 100644 --- a/src/video_core/command_classes/codecs/h264.cpp +++ b/src/video_core/command_classes/codecs/h264.cpp | |||
| @@ -95,7 +95,8 @@ const std::vector<u8>& H264::ComposeFrameHeader(const NvdecCommon::NvdecRegister | |||
| 95 | const s32 pic_height = context.h264_parameter_set.frame_height_in_map_units / | 95 | const s32 pic_height = context.h264_parameter_set.frame_height_in_map_units / |
| 96 | (context.h264_parameter_set.frame_mbs_only_flag ? 1 : 2); | 96 | (context.h264_parameter_set.frame_mbs_only_flag ? 1 : 2); |
| 97 | 97 | ||
| 98 | writer.WriteUe(16); | 98 | // TODO (ameerj): Where do we get this number, it seems to be particular for each stream |
| 99 | writer.WriteUe(6); // Max number of reference frames | ||
| 99 | writer.WriteBit(false); | 100 | writer.WriteBit(false); |
| 100 | writer.WriteUe(context.h264_parameter_set.pic_width_in_mbs - 1); | 101 | writer.WriteUe(context.h264_parameter_set.pic_width_in_mbs - 1); |
| 101 | writer.WriteUe(pic_height - 1); | 102 | writer.WriteUe(pic_height - 1); |
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index 1aa43523a..7f4ca6282 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h | |||
| @@ -475,10 +475,10 @@ public: | |||
| 475 | 475 | ||
| 476 | // These values are used by Nouveau and some games. | 476 | // These values are used by Nouveau and some games. |
| 477 | AddGL = 0x8006, | 477 | AddGL = 0x8006, |
| 478 | SubtractGL = 0x8007, | 478 | MinGL = 0x8007, |
| 479 | ReverseSubtractGL = 0x8008, | 479 | MaxGL = 0x8008, |
| 480 | MinGL = 0x800a, | 480 | SubtractGL = 0x800a, |
| 481 | MaxGL = 0x800b | 481 | ReverseSubtractGL = 0x800b |
| 482 | }; | 482 | }; |
| 483 | 483 | ||
| 484 | enum class Factor : u32 { | 484 | enum class Factor : u32 { |
diff --git a/src/video_core/engines/maxwell_dma.cpp b/src/video_core/engines/maxwell_dma.cpp index c7ec1eac9..67388d980 100644 --- a/src/video_core/engines/maxwell_dma.cpp +++ b/src/video_core/engines/maxwell_dma.cpp | |||
| @@ -82,41 +82,41 @@ void MaxwellDMA::Launch() { | |||
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | void MaxwellDMA::CopyPitchToPitch() { | 84 | void MaxwellDMA::CopyPitchToPitch() { |
| 85 | // When `multi_line_enable` bit is disabled the copy is performed as if we were copying a 1D | 85 | // When `multi_line_enable` bit is enabled we copy a 2D image of dimensions |
| 86 | // buffer of length `line_length_in`. | 86 | // (line_length_in, line_count). |
| 87 | // Otherwise we copy a 2D image of dimensions (line_length_in, line_count). | 87 | // Otherwise the copy is performed as if we were copying a 1D buffer of length line_length_in. |
| 88 | auto& accelerate = rasterizer->AccessAccelerateDMA(); | 88 | const bool remap_enabled = regs.launch_dma.remap_enable != 0; |
| 89 | if (!regs.launch_dma.multi_line_enable) { | 89 | if (regs.launch_dma.multi_line_enable) { |
| 90 | const bool is_buffer_clear = regs.launch_dma.remap_enable != 0 && | 90 | UNIMPLEMENTED_IF(remap_enabled); |
| 91 | regs.remap_const.dst_x == RemapConst::Swizzle::CONST_A; | 91 | |
| 92 | // TODO: allow multisized components. | 92 | // Perform a line-by-line copy. |
| 93 | if (is_buffer_clear) { | 93 | // We're going to take a subrect of size (line_length_in, line_count) from the source |
| 94 | ASSERT(regs.remap_const.component_size_minus_one == 3); | 94 | // rectangle. There is no need to manually flush/invalidate the regions because CopyBlock |
| 95 | accelerate.BufferClear(regs.offset_out, regs.line_length_in, regs.remap_consta_value); | 95 | // does that for us. |
| 96 | std::vector<u32> tmp_buffer(regs.line_length_in, regs.remap_consta_value); | 96 | for (u32 line = 0; line < regs.line_count; ++line) { |
| 97 | memory_manager.WriteBlockUnsafe(regs.offset_out, | 97 | const GPUVAddr source_line = regs.offset_in + static_cast<size_t>(line) * regs.pitch_in; |
| 98 | reinterpret_cast<u8*>(tmp_buffer.data()), | 98 | const GPUVAddr dest_line = regs.offset_out + static_cast<size_t>(line) * regs.pitch_out; |
| 99 | regs.line_length_in * sizeof(u32)); | 99 | memory_manager.CopyBlock(dest_line, source_line, regs.line_length_in); |
| 100 | return; | ||
| 101 | } | ||
| 102 | UNIMPLEMENTED_IF(regs.launch_dma.remap_enable != 0); | ||
| 103 | if (!accelerate.BufferCopy(regs.offset_in, regs.offset_out, regs.line_length_in)) { | ||
| 104 | std::vector<u8> tmp_buffer(regs.line_length_in); | ||
| 105 | memory_manager.ReadBlockUnsafe(regs.offset_in, tmp_buffer.data(), regs.line_length_in); | ||
| 106 | memory_manager.WriteBlock(regs.offset_out, tmp_buffer.data(), regs.line_length_in); | ||
| 107 | } | 100 | } |
| 108 | return; | 101 | return; |
| 109 | } | 102 | } |
| 110 | 103 | // TODO: allow multisized components. | |
| 111 | UNIMPLEMENTED_IF(regs.launch_dma.remap_enable != 0); | 104 | auto& accelerate = rasterizer->AccessAccelerateDMA(); |
| 112 | 105 | const bool is_const_a_dst = regs.remap_const.dst_x == RemapConst::Swizzle::CONST_A; | |
| 113 | // Perform a line-by-line copy. | 106 | const bool is_buffer_clear = remap_enabled && is_const_a_dst; |
| 114 | // We're going to take a subrect of size (line_length_in, line_count) from the source rectangle. | 107 | if (is_buffer_clear) { |
| 115 | // There is no need to manually flush/invalidate the regions because CopyBlock does that for us. | 108 | ASSERT(regs.remap_const.component_size_minus_one == 3); |
| 116 | for (u32 line = 0; line < regs.line_count; ++line) { | 109 | accelerate.BufferClear(regs.offset_out, regs.line_length_in, regs.remap_consta_value); |
| 117 | const GPUVAddr source_line = regs.offset_in + static_cast<size_t>(line) * regs.pitch_in; | 110 | std::vector<u32> tmp_buffer(regs.line_length_in, regs.remap_consta_value); |
| 118 | const GPUVAddr dest_line = regs.offset_out + static_cast<size_t>(line) * regs.pitch_out; | 111 | memory_manager.WriteBlockUnsafe(regs.offset_out, reinterpret_cast<u8*>(tmp_buffer.data()), |
| 119 | memory_manager.CopyBlock(dest_line, source_line, regs.line_length_in); | 112 | regs.line_length_in * sizeof(u32)); |
| 113 | return; | ||
| 114 | } | ||
| 115 | UNIMPLEMENTED_IF(remap_enabled); | ||
| 116 | if (!accelerate.BufferCopy(regs.offset_in, regs.offset_out, regs.line_length_in)) { | ||
| 117 | std::vector<u8> tmp_buffer(regs.line_length_in); | ||
| 118 | memory_manager.ReadBlockUnsafe(regs.offset_in, tmp_buffer.data(), regs.line_length_in); | ||
| 119 | memory_manager.WriteBlock(regs.offset_out, tmp_buffer.data(), regs.line_length_in); | ||
| 120 | } | 120 | } |
| 121 | } | 121 | } |
| 122 | 122 | ||
diff --git a/src/video_core/engines/maxwell_dma.h b/src/video_core/engines/maxwell_dma.h index 9e457ae16..a04514425 100644 --- a/src/video_core/engines/maxwell_dma.h +++ b/src/video_core/engines/maxwell_dma.h | |||
| @@ -175,7 +175,7 @@ public: | |||
| 175 | static_assert(sizeof(LaunchDMA) == 4); | 175 | static_assert(sizeof(LaunchDMA) == 4); |
| 176 | 176 | ||
| 177 | struct RemapConst { | 177 | struct RemapConst { |
| 178 | enum Swizzle : u32 { | 178 | enum class Swizzle : u32 { |
| 179 | SRC_X = 0, | 179 | SRC_X = 0, |
| 180 | SRC_Y = 1, | 180 | SRC_Y = 1, |
| 181 | SRC_Z = 2, | 181 | SRC_Z = 2, |
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index ff024f530..2ae3639b5 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp | |||
| @@ -531,14 +531,6 @@ void GPU::TriggerCpuInterrupt(const u32 syncpoint_id, const u32 value) const { | |||
| 531 | interrupt_manager.GPUInterruptSyncpt(syncpoint_id, value); | 531 | interrupt_manager.GPUInterruptSyncpt(syncpoint_id, value); |
| 532 | } | 532 | } |
| 533 | 533 | ||
| 534 | void GPU::ShutDown() { | ||
| 535 | // Signal that threads should no longer block on syncpoint fences | ||
| 536 | shutting_down.store(true, std::memory_order_relaxed); | ||
| 537 | sync_cv.notify_all(); | ||
| 538 | |||
| 539 | gpu_thread.ShutDown(); | ||
| 540 | } | ||
| 541 | |||
| 542 | void GPU::OnCommandListEnd() { | 534 | void GPU::OnCommandListEnd() { |
| 543 | if (is_async) { | 535 | if (is_async) { |
| 544 | // This command only applies to asynchronous GPU mode | 536 | // This command only applies to asynchronous GPU mode |
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h index a8e98e51b..e6a02a71b 100644 --- a/src/video_core/gpu.h +++ b/src/video_core/gpu.h | |||
| @@ -219,9 +219,6 @@ public: | |||
| 219 | return *shader_notify; | 219 | return *shader_notify; |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | // Stops the GPU execution and waits for the GPU to finish working | ||
| 223 | void ShutDown(); | ||
| 224 | |||
| 225 | /// Allows the CPU/NvFlinger to wait on the GPU before presenting a frame. | 222 | /// Allows the CPU/NvFlinger to wait on the GPU before presenting a frame. |
| 226 | void WaitFence(u32 syncpoint_id, u32 value); | 223 | void WaitFence(u32 syncpoint_id, u32 value); |
| 227 | 224 | ||
diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp index 46f642b19..9547f277a 100644 --- a/src/video_core/gpu_thread.cpp +++ b/src/video_core/gpu_thread.cpp | |||
| @@ -17,9 +17,9 @@ | |||
| 17 | namespace VideoCommon::GPUThread { | 17 | namespace VideoCommon::GPUThread { |
| 18 | 18 | ||
| 19 | /// Runs the GPU thread | 19 | /// Runs the GPU thread |
| 20 | static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, | 20 | static void RunThread(std::stop_token stop_token, Core::System& system, |
| 21 | Core::Frontend::GraphicsContext& context, Tegra::DmaPusher& dma_pusher, | 21 | VideoCore::RendererBase& renderer, Core::Frontend::GraphicsContext& context, |
| 22 | SynchState& state) { | 22 | Tegra::DmaPusher& dma_pusher, SynchState& state) { |
| 23 | std::string name = "yuzu:GPU"; | 23 | std::string name = "yuzu:GPU"; |
| 24 | MicroProfileOnThreadCreate(name.c_str()); | 24 | MicroProfileOnThreadCreate(name.c_str()); |
| 25 | SCOPE_EXIT({ MicroProfileOnThreadExit(); }); | 25 | SCOPE_EXIT({ MicroProfileOnThreadExit(); }); |
| @@ -28,20 +28,14 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, | |||
| 28 | Common::SetCurrentThreadPriority(Common::ThreadPriority::High); | 28 | Common::SetCurrentThreadPriority(Common::ThreadPriority::High); |
| 29 | system.RegisterHostThread(); | 29 | system.RegisterHostThread(); |
| 30 | 30 | ||
| 31 | // Wait for first GPU command before acquiring the window context | ||
| 32 | state.queue.Wait(); | ||
| 33 | |||
| 34 | // If emulation was stopped during disk shader loading, abort before trying to acquire context | ||
| 35 | if (!state.is_running) { | ||
| 36 | return; | ||
| 37 | } | ||
| 38 | |||
| 39 | auto current_context = context.Acquire(); | 31 | auto current_context = context.Acquire(); |
| 40 | VideoCore::RasterizerInterface* const rasterizer = renderer.ReadRasterizer(); | 32 | VideoCore::RasterizerInterface* const rasterizer = renderer.ReadRasterizer(); |
| 41 | 33 | ||
| 42 | CommandDataContainer next; | 34 | while (!stop_token.stop_requested()) { |
| 43 | while (state.is_running) { | 35 | CommandDataContainer next = state.queue.PopWait(stop_token); |
| 44 | next = state.queue.PopWait(); | 36 | if (stop_token.stop_requested()) { |
| 37 | break; | ||
| 38 | } | ||
| 45 | if (auto* submit_list = std::get_if<SubmitListCommand>(&next.data)) { | 39 | if (auto* submit_list = std::get_if<SubmitListCommand>(&next.data)) { |
| 46 | dma_pusher.Push(std::move(submit_list->entries)); | 40 | dma_pusher.Push(std::move(submit_list->entries)); |
| 47 | dma_pusher.DispatchCalls(); | 41 | dma_pusher.DispatchCalls(); |
| @@ -55,8 +49,6 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, | |||
| 55 | rasterizer->FlushRegion(flush->addr, flush->size); | 49 | rasterizer->FlushRegion(flush->addr, flush->size); |
| 56 | } else if (const auto* invalidate = std::get_if<InvalidateRegionCommand>(&next.data)) { | 50 | } else if (const auto* invalidate = std::get_if<InvalidateRegionCommand>(&next.data)) { |
| 57 | rasterizer->OnCPUWrite(invalidate->addr, invalidate->size); | 51 | rasterizer->OnCPUWrite(invalidate->addr, invalidate->size); |
| 58 | } else if (std::holds_alternative<EndProcessingCommand>(next.data)) { | ||
| 59 | ASSERT(state.is_running == false); | ||
| 60 | } else { | 52 | } else { |
| 61 | UNREACHABLE(); | 53 | UNREACHABLE(); |
| 62 | } | 54 | } |
| @@ -73,16 +65,14 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, | |||
| 73 | ThreadManager::ThreadManager(Core::System& system_, bool is_async_) | 65 | ThreadManager::ThreadManager(Core::System& system_, bool is_async_) |
| 74 | : system{system_}, is_async{is_async_} {} | 66 | : system{system_}, is_async{is_async_} {} |
| 75 | 67 | ||
| 76 | ThreadManager::~ThreadManager() { | 68 | ThreadManager::~ThreadManager() = default; |
| 77 | ShutDown(); | ||
| 78 | } | ||
| 79 | 69 | ||
| 80 | void ThreadManager::StartThread(VideoCore::RendererBase& renderer, | 70 | void ThreadManager::StartThread(VideoCore::RendererBase& renderer, |
| 81 | Core::Frontend::GraphicsContext& context, | 71 | Core::Frontend::GraphicsContext& context, |
| 82 | Tegra::DmaPusher& dma_pusher) { | 72 | Tegra::DmaPusher& dma_pusher) { |
| 83 | rasterizer = renderer.ReadRasterizer(); | 73 | rasterizer = renderer.ReadRasterizer(); |
| 84 | thread = std::thread(RunThread, std::ref(system), std::ref(renderer), std::ref(context), | 74 | thread = std::jthread(RunThread, std::ref(system), std::ref(renderer), std::ref(context), |
| 85 | std::ref(dma_pusher), std::ref(state)); | 75 | std::ref(dma_pusher), std::ref(state)); |
| 86 | } | 76 | } |
| 87 | 77 | ||
| 88 | void ThreadManager::SubmitList(Tegra::CommandList&& entries) { | 78 | void ThreadManager::SubmitList(Tegra::CommandList&& entries) { |
| @@ -117,26 +107,6 @@ void ThreadManager::FlushAndInvalidateRegion(VAddr addr, u64 size) { | |||
| 117 | rasterizer->OnCPUWrite(addr, size); | 107 | rasterizer->OnCPUWrite(addr, size); |
| 118 | } | 108 | } |
| 119 | 109 | ||
| 120 | void ThreadManager::ShutDown() { | ||
| 121 | if (!state.is_running) { | ||
| 122 | return; | ||
| 123 | } | ||
| 124 | |||
| 125 | { | ||
| 126 | std::lock_guard lk(state.write_lock); | ||
| 127 | state.is_running = false; | ||
| 128 | state.cv.notify_all(); | ||
| 129 | } | ||
| 130 | |||
| 131 | if (!thread.joinable()) { | ||
| 132 | return; | ||
| 133 | } | ||
| 134 | |||
| 135 | // Notify GPU thread that a shutdown is pending | ||
| 136 | PushCommand(EndProcessingCommand()); | ||
| 137 | thread.join(); | ||
| 138 | } | ||
| 139 | |||
| 140 | void ThreadManager::OnCommandListEnd() { | 110 | void ThreadManager::OnCommandListEnd() { |
| 141 | PushCommand(OnCommandListEndCommand()); | 111 | PushCommand(OnCommandListEndCommand()); |
| 142 | } | 112 | } |
| @@ -152,9 +122,8 @@ u64 ThreadManager::PushCommand(CommandData&& command_data, bool block) { | |||
| 152 | state.queue.Push(CommandDataContainer(std::move(command_data), fence, block)); | 122 | state.queue.Push(CommandDataContainer(std::move(command_data), fence, block)); |
| 153 | 123 | ||
| 154 | if (block) { | 124 | if (block) { |
| 155 | state.cv.wait(lk, [this, fence] { | 125 | state.cv.wait(lk, thread.get_stop_token(), [this, fence] { |
| 156 | return fence <= state.signaled_fence.load(std::memory_order_relaxed) || | 126 | return fence <= state.signaled_fence.load(std::memory_order_relaxed); |
| 157 | !state.is_running; | ||
| 158 | }); | 127 | }); |
| 159 | } | 128 | } |
| 160 | 129 | ||
diff --git a/src/video_core/gpu_thread.h b/src/video_core/gpu_thread.h index 11a648f38..91bada925 100644 --- a/src/video_core/gpu_thread.h +++ b/src/video_core/gpu_thread.h | |||
| @@ -33,9 +33,6 @@ class RendererBase; | |||
| 33 | 33 | ||
| 34 | namespace VideoCommon::GPUThread { | 34 | namespace VideoCommon::GPUThread { |
| 35 | 35 | ||
| 36 | /// Command to signal to the GPU thread that processing has ended | ||
| 37 | struct EndProcessingCommand final {}; | ||
| 38 | |||
| 39 | /// Command to signal to the GPU thread that a command list is ready for processing | 36 | /// Command to signal to the GPU thread that a command list is ready for processing |
| 40 | struct SubmitListCommand final { | 37 | struct SubmitListCommand final { |
| 41 | explicit SubmitListCommand(Tegra::CommandList&& entries_) : entries{std::move(entries_)} {} | 38 | explicit SubmitListCommand(Tegra::CommandList&& entries_) : entries{std::move(entries_)} {} |
| @@ -83,7 +80,7 @@ struct OnCommandListEndCommand final {}; | |||
| 83 | struct GPUTickCommand final {}; | 80 | struct GPUTickCommand final {}; |
| 84 | 81 | ||
| 85 | using CommandData = | 82 | using CommandData = |
| 86 | std::variant<EndProcessingCommand, SubmitListCommand, SwapBuffersCommand, FlushRegionCommand, | 83 | std::variant<std::monostate, SubmitListCommand, SwapBuffersCommand, FlushRegionCommand, |
| 87 | InvalidateRegionCommand, FlushAndInvalidateRegionCommand, OnCommandListEndCommand, | 84 | InvalidateRegionCommand, FlushAndInvalidateRegionCommand, OnCommandListEndCommand, |
| 88 | GPUTickCommand>; | 85 | GPUTickCommand>; |
| 89 | 86 | ||
| @@ -100,14 +97,12 @@ struct CommandDataContainer { | |||
| 100 | 97 | ||
| 101 | /// Struct used to synchronize the GPU thread | 98 | /// Struct used to synchronize the GPU thread |
| 102 | struct SynchState final { | 99 | struct SynchState final { |
| 103 | std::atomic_bool is_running{true}; | 100 | using CommandQueue = Common::SPSCQueue<CommandDataContainer, true>; |
| 104 | |||
| 105 | using CommandQueue = Common::SPSCQueue<CommandDataContainer>; | ||
| 106 | std::mutex write_lock; | 101 | std::mutex write_lock; |
| 107 | CommandQueue queue; | 102 | CommandQueue queue; |
| 108 | u64 last_fence{}; | 103 | u64 last_fence{}; |
| 109 | std::atomic<u64> signaled_fence{}; | 104 | std::atomic<u64> signaled_fence{}; |
| 110 | std::condition_variable cv; | 105 | std::condition_variable_any cv; |
| 111 | }; | 106 | }; |
| 112 | 107 | ||
| 113 | /// Class used to manage the GPU thread | 108 | /// Class used to manage the GPU thread |
| @@ -149,7 +144,7 @@ private: | |||
| 149 | VideoCore::RasterizerInterface* rasterizer = nullptr; | 144 | VideoCore::RasterizerInterface* rasterizer = nullptr; |
| 150 | 145 | ||
| 151 | SynchState state; | 146 | SynchState state; |
| 152 | std::thread thread; | 147 | std::jthread thread; |
| 153 | }; | 148 | }; |
| 154 | 149 | ||
| 155 | } // namespace VideoCommon::GPUThread | 150 | } // namespace VideoCommon::GPUThread |
diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt index c9cff7450..20d748c12 100644 --- a/src/video_core/host_shaders/CMakeLists.txt +++ b/src/video_core/host_shaders/CMakeLists.txt | |||
| @@ -6,7 +6,6 @@ set(SHADER_FILES | |||
| 6 | convert_float_to_depth.frag | 6 | convert_float_to_depth.frag |
| 7 | full_screen_triangle.vert | 7 | full_screen_triangle.vert |
| 8 | opengl_copy_bc4.comp | 8 | opengl_copy_bc4.comp |
| 9 | opengl_copy_bgra.comp | ||
| 10 | opengl_present.frag | 9 | opengl_present.frag |
| 11 | opengl_present.vert | 10 | opengl_present.vert |
| 12 | pitch_unswizzle.comp | 11 | pitch_unswizzle.comp |
diff --git a/src/video_core/host_shaders/opengl_copy_bgra.comp b/src/video_core/host_shaders/opengl_copy_bgra.comp deleted file mode 100644 index 2571a4abf..000000000 --- a/src/video_core/host_shaders/opengl_copy_bgra.comp +++ /dev/null | |||
| @@ -1,15 +0,0 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #version 430 core | ||
| 6 | |||
| 7 | layout (local_size_x = 4, local_size_y = 4) in; | ||
| 8 | |||
| 9 | layout(binding = 0, rgba8) readonly uniform image2DArray bgr_input; | ||
| 10 | layout(binding = 1, rgba8) writeonly uniform image2DArray bgr_output; | ||
| 11 | |||
| 12 | void main() { | ||
| 13 | vec4 color = imageLoad(bgr_input, ivec3(gl_GlobalInvocationID)); | ||
| 14 | imageStore(bgr_output, ivec3(gl_GlobalInvocationID), color.bgra); | ||
| 15 | } | ||
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index c60ed6453..dce00e829 100644 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | |||
| 5 | #include "common/alignment.h" | 7 | #include "common/alignment.h" |
| 6 | #include "common/assert.h" | 8 | #include "common/assert.h" |
| 7 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
diff --git a/src/video_core/renderer_opengl/gl_buffer_cache.cpp b/src/video_core/renderer_opengl/gl_buffer_cache.cpp index 07a995f7d..187a28e4d 100644 --- a/src/video_core/renderer_opengl/gl_buffer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_buffer_cache.cpp | |||
| @@ -147,8 +147,7 @@ void BufferCacheRuntime::CopyBuffer(Buffer& dst_buffer, Buffer& src_buffer, | |||
| 147 | 147 | ||
| 148 | void BufferCacheRuntime::ClearBuffer(Buffer& dest_buffer, u32 offset, size_t size, u32 value) { | 148 | void BufferCacheRuntime::ClearBuffer(Buffer& dest_buffer, u32 offset, size_t size, u32 value) { |
| 149 | glClearNamedBufferSubData(dest_buffer.Handle(), GL_R32UI, static_cast<GLintptr>(offset), | 149 | glClearNamedBufferSubData(dest_buffer.Handle(), GL_R32UI, static_cast<GLintptr>(offset), |
| 150 | static_cast<GLsizeiptr>(size / sizeof(u32)), GL_RED, GL_UNSIGNED_INT, | 150 | static_cast<GLsizeiptr>(size), GL_RED, GL_UNSIGNED_INT, &value); |
| 151 | &value); | ||
| 152 | } | 151 | } |
| 153 | 152 | ||
| 154 | void BufferCacheRuntime::BindIndexBuffer(Buffer& buffer, u32 offset, u32 size) { | 153 | void BufferCacheRuntime::BindIndexBuffer(Buffer& buffer, u32 offset, u32 size) { |
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index b0e14182e..02682bd76 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp | |||
| @@ -293,6 +293,8 @@ void ShaderCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading, | |||
| 293 | }}; | 293 | }}; |
| 294 | LoadPipelines(stop_loading, shader_cache_filename, CACHE_VERSION, load_compute, load_graphics); | 294 | LoadPipelines(stop_loading, shader_cache_filename, CACHE_VERSION, load_compute, load_graphics); |
| 295 | 295 | ||
| 296 | LOG_INFO(Render_OpenGL, "Total Pipeline Count: {}", state.total); | ||
| 297 | |||
| 296 | std::unique_lock lock{state.mutex}; | 298 | std::unique_lock lock{state.mutex}; |
| 297 | callback(VideoCore::LoadCallbackStage::Build, 0, state.total); | 299 | callback(VideoCore::LoadCallbackStage::Build, 0, state.total); |
| 298 | state.has_loaded = true; | 300 | state.has_loaded = true; |
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index b0aee6cc1..54dae2c41 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -461,7 +461,7 @@ bool TextureCacheRuntime::CanImageBeCopied(const Image& dst, const Image& src) { | |||
| 461 | if (dst.info.type == ImageType::e3D && dst.info.format == PixelFormat::BC4_UNORM) { | 461 | if (dst.info.type == ImageType::e3D && dst.info.format == PixelFormat::BC4_UNORM) { |
| 462 | return false; | 462 | return false; |
| 463 | } | 463 | } |
| 464 | if (IsPixelFormatBGR(dst.info.format) || IsPixelFormatBGR(src.info.format)) { | 464 | if (IsPixelFormatBGR(dst.info.format) != IsPixelFormatBGR(src.info.format)) { |
| 465 | return false; | 465 | return false; |
| 466 | } | 466 | } |
| 467 | return true; | 467 | return true; |
| @@ -473,7 +473,7 @@ void TextureCacheRuntime::EmulateCopyImage(Image& dst, Image& src, | |||
| 473 | ASSERT(src.info.type == ImageType::e3D); | 473 | ASSERT(src.info.type == ImageType::e3D); |
| 474 | util_shaders.CopyBC4(dst, src, copies); | 474 | util_shaders.CopyBC4(dst, src, copies); |
| 475 | } else if (IsPixelFormatBGR(dst.info.format) || IsPixelFormatBGR(src.info.format)) { | 475 | } else if (IsPixelFormatBGR(dst.info.format) || IsPixelFormatBGR(src.info.format)) { |
| 476 | util_shaders.CopyBGR(dst, src, copies); | 476 | bgr_copy_pass.CopyBGR(dst, src, copies); |
| 477 | } else { | 477 | } else { |
| 478 | UNREACHABLE(); | 478 | UNREACHABLE(); |
| 479 | } | 479 | } |
| @@ -1112,4 +1112,37 @@ Framebuffer::Framebuffer(TextureCacheRuntime& runtime, std::span<ImageView*, NUM | |||
| 1112 | framebuffer.handle = handle; | 1112 | framebuffer.handle = handle; |
| 1113 | } | 1113 | } |
| 1114 | 1114 | ||
| 1115 | void BGRCopyPass::CopyBGR(Image& dst_image, Image& src_image, | ||
| 1116 | std::span<const VideoCommon::ImageCopy> copies) { | ||
| 1117 | static constexpr VideoCommon::Offset3D zero_offset{0, 0, 0}; | ||
| 1118 | const u32 requested_pbo_size = | ||
| 1119 | std::max(src_image.unswizzled_size_bytes, dst_image.unswizzled_size_bytes); | ||
| 1120 | |||
| 1121 | if (bgr_pbo_size < requested_pbo_size) { | ||
| 1122 | bgr_pbo.Create(); | ||
| 1123 | bgr_pbo_size = requested_pbo_size; | ||
| 1124 | glNamedBufferData(bgr_pbo.handle, bgr_pbo_size, nullptr, GL_STREAM_COPY); | ||
| 1125 | } | ||
| 1126 | for (const ImageCopy& copy : copies) { | ||
| 1127 | ASSERT(copy.src_offset == zero_offset); | ||
| 1128 | ASSERT(copy.dst_offset == zero_offset); | ||
| 1129 | |||
| 1130 | // Copy from source to PBO | ||
| 1131 | glPixelStorei(GL_PACK_ALIGNMENT, 1); | ||
| 1132 | glPixelStorei(GL_PACK_ROW_LENGTH, copy.extent.width); | ||
| 1133 | glBindBuffer(GL_PIXEL_PACK_BUFFER, bgr_pbo.handle); | ||
| 1134 | glGetTextureSubImage(src_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height, | ||
| 1135 | copy.src_subresource.num_layers, src_image.GlFormat(), | ||
| 1136 | src_image.GlType(), static_cast<GLsizei>(bgr_pbo_size), nullptr); | ||
| 1137 | |||
| 1138 | // Copy from PBO to destination in desired GL format | ||
| 1139 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | ||
| 1140 | glPixelStorei(GL_UNPACK_ROW_LENGTH, copy.extent.width); | ||
| 1141 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bgr_pbo.handle); | ||
| 1142 | glTextureSubImage3D(dst_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height, | ||
| 1143 | copy.dst_subresource.num_layers, dst_image.GlFormat(), | ||
| 1144 | dst_image.GlType(), nullptr); | ||
| 1145 | } | ||
| 1146 | } | ||
| 1147 | |||
| 1115 | } // namespace OpenGL | 1148 | } // namespace OpenGL |
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h index 4a4f6301c..c498a8a8f 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.h +++ b/src/video_core/renderer_opengl/gl_texture_cache.h | |||
| @@ -47,6 +47,19 @@ struct FormatProperties { | |||
| 47 | bool is_compressed; | 47 | bool is_compressed; |
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 50 | class BGRCopyPass { | ||
| 51 | public: | ||
| 52 | BGRCopyPass() = default; | ||
| 53 | ~BGRCopyPass() = default; | ||
| 54 | |||
| 55 | void CopyBGR(Image& dst_image, Image& src_image, | ||
| 56 | std::span<const VideoCommon::ImageCopy> copies); | ||
| 57 | |||
| 58 | private: | ||
| 59 | OGLBuffer bgr_pbo; | ||
| 60 | size_t bgr_pbo_size{}; | ||
| 61 | }; | ||
| 62 | |||
| 50 | class TextureCacheRuntime { | 63 | class TextureCacheRuntime { |
| 51 | friend Framebuffer; | 64 | friend Framebuffer; |
| 52 | friend Image; | 65 | friend Image; |
| @@ -118,6 +131,7 @@ private: | |||
| 118 | const Device& device; | 131 | const Device& device; |
| 119 | StateTracker& state_tracker; | 132 | StateTracker& state_tracker; |
| 120 | UtilShaders util_shaders; | 133 | UtilShaders util_shaders; |
| 134 | BGRCopyPass bgr_copy_pass; | ||
| 121 | 135 | ||
| 122 | std::array<std::unordered_map<GLenum, FormatProperties>, 3> format_properties; | 136 | std::array<std::unordered_map<GLenum, FormatProperties>, 3> format_properties; |
| 123 | bool has_broken_texture_view_formats = false; | 137 | bool has_broken_texture_view_formats = false; |
| @@ -162,6 +176,14 @@ public: | |||
| 162 | return texture.handle; | 176 | return texture.handle; |
| 163 | } | 177 | } |
| 164 | 178 | ||
| 179 | GLuint GlFormat() const noexcept { | ||
| 180 | return gl_format; | ||
| 181 | } | ||
| 182 | |||
| 183 | GLuint GlType() const noexcept { | ||
| 184 | return gl_type; | ||
| 185 | } | ||
| 186 | |||
| 165 | private: | 187 | private: |
| 166 | void CopyBufferToImage(const VideoCommon::BufferImageCopy& copy, size_t buffer_offset); | 188 | void CopyBufferToImage(const VideoCommon::BufferImageCopy& copy, size_t buffer_offset); |
| 167 | 189 | ||
diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h index 672f94bfc..39158aa3e 100644 --- a/src/video_core/renderer_opengl/maxwell_to_gl.h +++ b/src/video_core/renderer_opengl/maxwell_to_gl.h | |||
| @@ -52,7 +52,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> FORMAT_TAB | |||
| 52 | {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT}, // BC6H_UFLOAT | 52 | {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT}, // BC6H_UFLOAT |
| 53 | {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT}, // BC6H_SFLOAT | 53 | {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT}, // BC6H_SFLOAT |
| 54 | {GL_COMPRESSED_RGBA_ASTC_4x4_KHR}, // ASTC_2D_4X4_UNORM | 54 | {GL_COMPRESSED_RGBA_ASTC_4x4_KHR}, // ASTC_2D_4X4_UNORM |
| 55 | {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // B8G8R8A8_UNORM | 55 | {GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, // B8G8R8A8_UNORM |
| 56 | {GL_RGBA32F, GL_RGBA, GL_FLOAT}, // R32G32B32A32_FLOAT | 56 | {GL_RGBA32F, GL_RGBA, GL_FLOAT}, // R32G32B32A32_FLOAT |
| 57 | {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, // R32G32B32A32_SINT | 57 | {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, // R32G32B32A32_SINT |
| 58 | {GL_RG32F, GL_RG, GL_FLOAT}, // R32G32_FLOAT | 58 | {GL_RG32F, GL_RG, GL_FLOAT}, // R32G32_FLOAT |
| @@ -81,7 +81,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> FORMAT_TAB | |||
| 81 | {GL_COMPRESSED_RGBA_ASTC_8x8_KHR}, // ASTC_2D_8X8_UNORM | 81 | {GL_COMPRESSED_RGBA_ASTC_8x8_KHR}, // ASTC_2D_8X8_UNORM |
| 82 | {GL_COMPRESSED_RGBA_ASTC_8x5_KHR}, // ASTC_2D_8X5_UNORM | 82 | {GL_COMPRESSED_RGBA_ASTC_8x5_KHR}, // ASTC_2D_8X5_UNORM |
| 83 | {GL_COMPRESSED_RGBA_ASTC_5x4_KHR}, // ASTC_2D_5X4_UNORM | 83 | {GL_COMPRESSED_RGBA_ASTC_5x4_KHR}, // ASTC_2D_5X4_UNORM |
| 84 | {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, // B8G8R8A8_SRGB | 84 | {GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV}, // B8G8R8A8_SRGB |
| 85 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT}, // BC1_RGBA_SRGB | 85 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT}, // BC1_RGBA_SRGB |
| 86 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT}, // BC2_SRGB | 86 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT}, // BC2_SRGB |
| 87 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}, // BC3_SRGB | 87 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}, // BC3_SRGB |
diff --git a/src/video_core/renderer_opengl/util_shaders.cpp b/src/video_core/renderer_opengl/util_shaders.cpp index 333f35a1c..897c380b3 100644 --- a/src/video_core/renderer_opengl/util_shaders.cpp +++ b/src/video_core/renderer_opengl/util_shaders.cpp | |||
| @@ -14,7 +14,6 @@ | |||
| 14 | #include "video_core/host_shaders/block_linear_unswizzle_2d_comp.h" | 14 | #include "video_core/host_shaders/block_linear_unswizzle_2d_comp.h" |
| 15 | #include "video_core/host_shaders/block_linear_unswizzle_3d_comp.h" | 15 | #include "video_core/host_shaders/block_linear_unswizzle_3d_comp.h" |
| 16 | #include "video_core/host_shaders/opengl_copy_bc4_comp.h" | 16 | #include "video_core/host_shaders/opengl_copy_bc4_comp.h" |
| 17 | #include "video_core/host_shaders/opengl_copy_bgra_comp.h" | ||
| 18 | #include "video_core/host_shaders/pitch_unswizzle_comp.h" | 17 | #include "video_core/host_shaders/pitch_unswizzle_comp.h" |
| 19 | #include "video_core/renderer_opengl/gl_shader_manager.h" | 18 | #include "video_core/renderer_opengl/gl_shader_manager.h" |
| 20 | #include "video_core/renderer_opengl/gl_shader_util.h" | 19 | #include "video_core/renderer_opengl/gl_shader_util.h" |
| @@ -44,11 +43,6 @@ namespace { | |||
| 44 | OGLProgram MakeProgram(std::string_view source) { | 43 | OGLProgram MakeProgram(std::string_view source) { |
| 45 | return CreateProgram(source, GL_COMPUTE_SHADER); | 44 | return CreateProgram(source, GL_COMPUTE_SHADER); |
| 46 | } | 45 | } |
| 47 | |||
| 48 | size_t NumPixelsInCopy(const VideoCommon::ImageCopy& copy) { | ||
| 49 | return static_cast<size_t>(copy.extent.width * copy.extent.height * | ||
| 50 | copy.src_subresource.num_layers); | ||
| 51 | } | ||
| 52 | } // Anonymous namespace | 46 | } // Anonymous namespace |
| 53 | 47 | ||
| 54 | UtilShaders::UtilShaders(ProgramManager& program_manager_) | 48 | UtilShaders::UtilShaders(ProgramManager& program_manager_) |
| @@ -56,7 +50,6 @@ UtilShaders::UtilShaders(ProgramManager& program_manager_) | |||
| 56 | block_linear_unswizzle_2d_program(MakeProgram(BLOCK_LINEAR_UNSWIZZLE_2D_COMP)), | 50 | block_linear_unswizzle_2d_program(MakeProgram(BLOCK_LINEAR_UNSWIZZLE_2D_COMP)), |
| 57 | block_linear_unswizzle_3d_program(MakeProgram(BLOCK_LINEAR_UNSWIZZLE_3D_COMP)), | 51 | block_linear_unswizzle_3d_program(MakeProgram(BLOCK_LINEAR_UNSWIZZLE_3D_COMP)), |
| 58 | pitch_unswizzle_program(MakeProgram(PITCH_UNSWIZZLE_COMP)), | 52 | pitch_unswizzle_program(MakeProgram(PITCH_UNSWIZZLE_COMP)), |
| 59 | copy_bgra_program(MakeProgram(OPENGL_COPY_BGRA_COMP)), | ||
| 60 | copy_bc4_program(MakeProgram(OPENGL_COPY_BC4_COMP)) { | 53 | copy_bc4_program(MakeProgram(OPENGL_COPY_BC4_COMP)) { |
| 61 | const auto swizzle_table = Tegra::Texture::MakeSwizzleTable(); | 54 | const auto swizzle_table = Tegra::Texture::MakeSwizzleTable(); |
| 62 | swizzle_table_buffer.Create(); | 55 | swizzle_table_buffer.Create(); |
| @@ -255,43 +248,6 @@ void UtilShaders::CopyBC4(Image& dst_image, Image& src_image, std::span<const Im | |||
| 255 | program_manager.RestoreGuestCompute(); | 248 | program_manager.RestoreGuestCompute(); |
| 256 | } | 249 | } |
| 257 | 250 | ||
| 258 | void UtilShaders::CopyBGR(Image& dst_image, Image& src_image, | ||
| 259 | std::span<const VideoCommon::ImageCopy> copies) { | ||
| 260 | static constexpr GLuint BINDING_INPUT_IMAGE = 0; | ||
| 261 | static constexpr GLuint BINDING_OUTPUT_IMAGE = 1; | ||
| 262 | static constexpr VideoCommon::Offset3D zero_offset{0, 0, 0}; | ||
| 263 | const u32 bytes_per_block = BytesPerBlock(dst_image.info.format); | ||
| 264 | switch (bytes_per_block) { | ||
| 265 | case 2: | ||
| 266 | // BGR565 copy | ||
| 267 | for (const ImageCopy& copy : copies) { | ||
| 268 | ASSERT(copy.src_offset == zero_offset); | ||
| 269 | ASSERT(copy.dst_offset == zero_offset); | ||
| 270 | bgr_copy_pass.Execute(dst_image, src_image, copy); | ||
| 271 | } | ||
| 272 | break; | ||
| 273 | case 4: { | ||
| 274 | // BGRA8 copy | ||
| 275 | program_manager.BindComputeProgram(copy_bgra_program.handle); | ||
| 276 | constexpr GLenum FORMAT = GL_RGBA8; | ||
| 277 | for (const ImageCopy& copy : copies) { | ||
| 278 | ASSERT(copy.src_offset == zero_offset); | ||
| 279 | ASSERT(copy.dst_offset == zero_offset); | ||
| 280 | glBindImageTexture(BINDING_INPUT_IMAGE, src_image.StorageHandle(), | ||
| 281 | copy.src_subresource.base_level, GL_FALSE, 0, GL_READ_ONLY, FORMAT); | ||
| 282 | glBindImageTexture(BINDING_OUTPUT_IMAGE, dst_image.StorageHandle(), | ||
| 283 | copy.dst_subresource.base_level, GL_FALSE, 0, GL_WRITE_ONLY, FORMAT); | ||
| 284 | glDispatchCompute(copy.extent.width, copy.extent.height, copy.extent.depth); | ||
| 285 | } | ||
| 286 | program_manager.RestoreGuestCompute(); | ||
| 287 | break; | ||
| 288 | } | ||
| 289 | default: | ||
| 290 | UNREACHABLE(); | ||
| 291 | break; | ||
| 292 | } | ||
| 293 | } | ||
| 294 | |||
| 295 | GLenum StoreFormat(u32 bytes_per_block) { | 251 | GLenum StoreFormat(u32 bytes_per_block) { |
| 296 | switch (bytes_per_block) { | 252 | switch (bytes_per_block) { |
| 297 | case 1: | 253 | case 1: |
| @@ -309,36 +265,4 @@ GLenum StoreFormat(u32 bytes_per_block) { | |||
| 309 | return GL_R8UI; | 265 | return GL_R8UI; |
| 310 | } | 266 | } |
| 311 | 267 | ||
| 312 | void Bgr565CopyPass::Execute(const Image& dst_image, const Image& src_image, | ||
| 313 | const ImageCopy& copy) { | ||
| 314 | if (CopyBufferCreationNeeded(copy)) { | ||
| 315 | CreateNewCopyBuffer(copy, GL_TEXTURE_2D_ARRAY, GL_RGB565); | ||
| 316 | } | ||
| 317 | // Copy from source to PBO | ||
| 318 | glPixelStorei(GL_PACK_ALIGNMENT, 1); | ||
| 319 | glPixelStorei(GL_PACK_ROW_LENGTH, copy.extent.width); | ||
| 320 | glBindBuffer(GL_PIXEL_PACK_BUFFER, bgr16_pbo.handle); | ||
| 321 | glGetTextureSubImage(src_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height, | ||
| 322 | copy.src_subresource.num_layers, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, | ||
| 323 | static_cast<GLsizei>(bgr16_pbo_size), nullptr); | ||
| 324 | |||
| 325 | // Copy from PBO to destination in reverse order | ||
| 326 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | ||
| 327 | glPixelStorei(GL_UNPACK_ROW_LENGTH, copy.extent.width); | ||
| 328 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bgr16_pbo.handle); | ||
| 329 | glTextureSubImage3D(dst_image.Handle(), 0, 0, 0, 0, copy.extent.width, copy.extent.height, | ||
| 330 | copy.dst_subresource.num_layers, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, | ||
| 331 | nullptr); | ||
| 332 | } | ||
| 333 | |||
| 334 | bool Bgr565CopyPass::CopyBufferCreationNeeded(const ImageCopy& copy) { | ||
| 335 | return bgr16_pbo_size < NumPixelsInCopy(copy) * sizeof(u16); | ||
| 336 | } | ||
| 337 | |||
| 338 | void Bgr565CopyPass::CreateNewCopyBuffer(const ImageCopy& copy, GLenum target, GLuint format) { | ||
| 339 | bgr16_pbo.Create(); | ||
| 340 | bgr16_pbo_size = NumPixelsInCopy(copy) * sizeof(u16); | ||
| 341 | glNamedBufferData(bgr16_pbo.handle, bgr16_pbo_size, nullptr, GL_STREAM_COPY); | ||
| 342 | } | ||
| 343 | |||
| 344 | } // namespace OpenGL | 268 | } // namespace OpenGL |
diff --git a/src/video_core/renderer_opengl/util_shaders.h b/src/video_core/renderer_opengl/util_shaders.h index ef881e35f..5de95ea7a 100644 --- a/src/video_core/renderer_opengl/util_shaders.h +++ b/src/video_core/renderer_opengl/util_shaders.h | |||
| @@ -19,22 +19,6 @@ class ProgramManager; | |||
| 19 | 19 | ||
| 20 | struct ImageBufferMap; | 20 | struct ImageBufferMap; |
| 21 | 21 | ||
| 22 | class Bgr565CopyPass { | ||
| 23 | public: | ||
| 24 | Bgr565CopyPass() = default; | ||
| 25 | ~Bgr565CopyPass() = default; | ||
| 26 | |||
| 27 | void Execute(const Image& dst_image, const Image& src_image, | ||
| 28 | const VideoCommon::ImageCopy& copy); | ||
| 29 | |||
| 30 | private: | ||
| 31 | [[nodiscard]] bool CopyBufferCreationNeeded(const VideoCommon::ImageCopy& copy); | ||
| 32 | void CreateNewCopyBuffer(const VideoCommon::ImageCopy& copy, GLenum target, GLuint format); | ||
| 33 | |||
| 34 | OGLBuffer bgr16_pbo; | ||
| 35 | size_t bgr16_pbo_size{}; | ||
| 36 | }; | ||
| 37 | |||
| 38 | class UtilShaders { | 22 | class UtilShaders { |
| 39 | public: | 23 | public: |
| 40 | explicit UtilShaders(ProgramManager& program_manager); | 24 | explicit UtilShaders(ProgramManager& program_manager); |
| @@ -55,9 +39,6 @@ public: | |||
| 55 | void CopyBC4(Image& dst_image, Image& src_image, | 39 | void CopyBC4(Image& dst_image, Image& src_image, |
| 56 | std::span<const VideoCommon::ImageCopy> copies); | 40 | std::span<const VideoCommon::ImageCopy> copies); |
| 57 | 41 | ||
| 58 | void CopyBGR(Image& dst_image, Image& src_image, | ||
| 59 | std::span<const VideoCommon::ImageCopy> copies); | ||
| 60 | |||
| 61 | private: | 42 | private: |
| 62 | ProgramManager& program_manager; | 43 | ProgramManager& program_manager; |
| 63 | 44 | ||
| @@ -67,10 +48,7 @@ private: | |||
| 67 | OGLProgram block_linear_unswizzle_2d_program; | 48 | OGLProgram block_linear_unswizzle_2d_program; |
| 68 | OGLProgram block_linear_unswizzle_3d_program; | 49 | OGLProgram block_linear_unswizzle_3d_program; |
| 69 | OGLProgram pitch_unswizzle_program; | 50 | OGLProgram pitch_unswizzle_program; |
| 70 | OGLProgram copy_bgra_program; | ||
| 71 | OGLProgram copy_bc4_program; | 51 | OGLProgram copy_bc4_program; |
| 72 | |||
| 73 | Bgr565CopyPass bgr_copy_pass; | ||
| 74 | }; | 52 | }; |
| 75 | 53 | ||
| 76 | GLenum StoreFormat(u32 bytes_per_block); | 54 | GLenum StoreFormat(u32 bytes_per_block); |
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 7c9b0d6db..74822814d 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp | |||
| @@ -97,19 +97,14 @@ RendererVulkan::RendererVulkan(Core::TelemetrySession& telemetry_session_, | |||
| 97 | Core::Frontend::EmuWindow& emu_window, | 97 | Core::Frontend::EmuWindow& emu_window, |
| 98 | Core::Memory::Memory& cpu_memory_, Tegra::GPU& gpu_, | 98 | Core::Memory::Memory& cpu_memory_, Tegra::GPU& gpu_, |
| 99 | std::unique_ptr<Core::Frontend::GraphicsContext> context_) try | 99 | std::unique_ptr<Core::Frontend::GraphicsContext> context_) try |
| 100 | : RendererBase(emu_window, std::move(context_)), | 100 | : RendererBase(emu_window, std::move(context_)), telemetry_session(telemetry_session_), |
| 101 | telemetry_session(telemetry_session_), | 101 | cpu_memory(cpu_memory_), gpu(gpu_), library(OpenLibrary()), |
| 102 | cpu_memory(cpu_memory_), | ||
| 103 | gpu(gpu_), | ||
| 104 | library(OpenLibrary()), | ||
| 105 | instance(CreateInstance(library, dld, VK_API_VERSION_1_1, render_window.GetWindowInfo().type, | 102 | instance(CreateInstance(library, dld, VK_API_VERSION_1_1, render_window.GetWindowInfo().type, |
| 106 | true, Settings::values.renderer_debug.GetValue())), | 103 | true, Settings::values.renderer_debug.GetValue())), |
| 107 | debug_callback(Settings::values.renderer_debug ? CreateDebugCallback(instance) : nullptr), | 104 | debug_callback(Settings::values.renderer_debug ? CreateDebugCallback(instance) : nullptr), |
| 108 | surface(CreateSurface(instance, render_window)), | 105 | surface(CreateSurface(instance, render_window)), |
| 109 | device(CreateDevice(instance, dld, *surface)), | 106 | device(CreateDevice(instance, dld, *surface)), memory_allocator(device, false), |
| 110 | memory_allocator(device, false), | 107 | state_tracker(gpu), scheduler(device, state_tracker), |
| 111 | state_tracker(gpu), | ||
| 112 | scheduler(device, state_tracker), | ||
| 113 | swapchain(*surface, device, scheduler, render_window.GetFramebufferLayout().width, | 108 | swapchain(*surface, device, scheduler, render_window.GetFramebufferLayout().width, |
| 114 | render_window.GetFramebufferLayout().height, false), | 109 | render_window.GetFramebufferLayout().height, false), |
| 115 | blit_screen(cpu_memory, render_window, device, memory_allocator, swapchain, scheduler, | 110 | blit_screen(cpu_memory, render_window, device, memory_allocator, swapchain, scheduler, |
| @@ -149,7 +144,7 @@ void RendererVulkan::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { | |||
| 149 | const Layout::FramebufferLayout layout = render_window.GetFramebufferLayout(); | 144 | const Layout::FramebufferLayout layout = render_window.GetFramebufferLayout(); |
| 150 | swapchain.Create(layout.width, layout.height, is_srgb); | 145 | swapchain.Create(layout.width, layout.height, is_srgb); |
| 151 | }; | 146 | }; |
| 152 | if (swapchain.IsSubOptimal() || swapchain.HasColorSpaceChanged(is_srgb)) { | 147 | if (swapchain.NeedsRecreation(is_srgb)) { |
| 153 | recreate_swapchain(); | 148 | recreate_swapchain(); |
| 154 | } | 149 | } |
| 155 | bool is_outdated; | 150 | bool is_outdated; |
| @@ -164,7 +159,8 @@ void RendererVulkan::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { | |||
| 164 | blit_screen.Recreate(); | 159 | blit_screen.Recreate(); |
| 165 | } | 160 | } |
| 166 | const VkSemaphore render_semaphore = blit_screen.DrawToSwapchain(*framebuffer, use_accelerated); | 161 | const VkSemaphore render_semaphore = blit_screen.DrawToSwapchain(*framebuffer, use_accelerated); |
| 167 | scheduler.Flush(render_semaphore); | 162 | const VkSemaphore present_semaphore = swapchain.CurrentPresentSemaphore(); |
| 163 | scheduler.Flush(render_semaphore, present_semaphore); | ||
| 168 | scheduler.WaitWorker(); | 164 | scheduler.WaitWorker(); |
| 169 | swapchain.Present(render_semaphore); | 165 | swapchain.Present(render_semaphore); |
| 170 | 166 | ||
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.cpp b/src/video_core/renderer_vulkan/vk_blit_screen.cpp index cb0580182..888bc7392 100644 --- a/src/video_core/renderer_vulkan/vk_blit_screen.cpp +++ b/src/video_core/renderer_vulkan/vk_blit_screen.cpp | |||
| @@ -358,7 +358,7 @@ void VKBlitScreen::CreateDescriptorPool() { | |||
| 358 | void VKBlitScreen::CreateRenderPass() { | 358 | void VKBlitScreen::CreateRenderPass() { |
| 359 | const VkAttachmentDescription color_attachment{ | 359 | const VkAttachmentDescription color_attachment{ |
| 360 | .flags = 0, | 360 | .flags = 0, |
| 361 | .format = swapchain.GetImageFormat(), | 361 | .format = swapchain.GetImageViewFormat(), |
| 362 | .samples = VK_SAMPLE_COUNT_1_BIT, | 362 | .samples = VK_SAMPLE_COUNT_1_BIT, |
| 363 | .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR, | 363 | .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR, |
| 364 | .storeOp = VK_ATTACHMENT_STORE_OP_STORE, | 364 | .storeOp = VK_ATTACHMENT_STORE_OP_STORE, |
diff --git a/src/video_core/renderer_vulkan/vk_descriptor_pool.cpp b/src/video_core/renderer_vulkan/vk_descriptor_pool.cpp index 8e77e4796..d87da2a34 100644 --- a/src/video_core/renderer_vulkan/vk_descriptor_pool.cpp +++ b/src/video_core/renderer_vulkan/vk_descriptor_pool.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <mutex> | 6 | #include <mutex> |
| 6 | #include <span> | 7 | #include <span> |
| 7 | #include <vector> | 8 | #include <vector> |
| @@ -18,7 +19,6 @@ namespace Vulkan { | |||
| 18 | // Prefer small grow rates to avoid saturating the descriptor pool with barely used pipelines | 19 | // Prefer small grow rates to avoid saturating the descriptor pool with barely used pipelines |
| 19 | constexpr size_t SETS_GROW_RATE = 16; | 20 | constexpr size_t SETS_GROW_RATE = 16; |
| 20 | constexpr s32 SCORE_THRESHOLD = 3; | 21 | constexpr s32 SCORE_THRESHOLD = 3; |
| 21 | constexpr u32 SETS_PER_POOL = 64; | ||
| 22 | 22 | ||
| 23 | struct DescriptorBank { | 23 | struct DescriptorBank { |
| 24 | DescriptorBankInfo info; | 24 | DescriptorBankInfo info; |
| @@ -58,11 +58,12 @@ static DescriptorBankInfo MakeBankInfo(std::span<const Shader::Info> infos) { | |||
| 58 | static void AllocatePool(const Device& device, DescriptorBank& bank) { | 58 | static void AllocatePool(const Device& device, DescriptorBank& bank) { |
| 59 | std::array<VkDescriptorPoolSize, 6> pool_sizes; | 59 | std::array<VkDescriptorPoolSize, 6> pool_sizes; |
| 60 | size_t pool_cursor{}; | 60 | size_t pool_cursor{}; |
| 61 | const u32 sets_per_pool = device.GetSetsPerPool(); | ||
| 61 | const auto add = [&](VkDescriptorType type, u32 count) { | 62 | const auto add = [&](VkDescriptorType type, u32 count) { |
| 62 | if (count > 0) { | 63 | if (count > 0) { |
| 63 | pool_sizes[pool_cursor++] = { | 64 | pool_sizes[pool_cursor++] = { |
| 64 | .type = type, | 65 | .type = type, |
| 65 | .descriptorCount = count * SETS_PER_POOL, | 66 | .descriptorCount = count * sets_per_pool, |
| 66 | }; | 67 | }; |
| 67 | } | 68 | } |
| 68 | }; | 69 | }; |
| @@ -77,7 +78,7 @@ static void AllocatePool(const Device& device, DescriptorBank& bank) { | |||
| 77 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, | 78 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, |
| 78 | .pNext = nullptr, | 79 | .pNext = nullptr, |
| 79 | .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, | 80 | .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, |
| 80 | .maxSets = SETS_PER_POOL, | 81 | .maxSets = sets_per_pool, |
| 81 | .poolSizeCount = static_cast<u32>(pool_cursor), | 82 | .poolSizeCount = static_cast<u32>(pool_cursor), |
| 82 | .pPoolSizes = std::data(pool_sizes), | 83 | .pPoolSizes = std::data(pool_sizes), |
| 83 | })); | 84 | })); |
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index 7c0f91007..11cd41ad7 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp | |||
| @@ -507,8 +507,9 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) { | |||
| 507 | vertex_attributes.push_back({ | 507 | vertex_attributes.push_back({ |
| 508 | .location = static_cast<u32>(index), | 508 | .location = static_cast<u32>(index), |
| 509 | .binding = 0, | 509 | .binding = 0, |
| 510 | .format = type == 1 ? VK_FORMAT_R32_SFLOAT | 510 | .format = type == 1 ? VK_FORMAT_R32_SFLOAT |
| 511 | : type == 2 ? VK_FORMAT_R32_SINT : VK_FORMAT_R32_UINT, | 511 | : type == 2 ? VK_FORMAT_R32_SINT |
| 512 | : VK_FORMAT_R32_UINT, | ||
| 512 | .offset = 0, | 513 | .offset = 0, |
| 513 | }); | 514 | }); |
| 514 | } | 515 | } |
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 31bfbcb06..eb8b4e08b 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -447,6 +447,8 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading | |||
| 447 | VideoCommon::LoadPipelines(stop_loading, pipeline_cache_filename, CACHE_VERSION, load_compute, | 447 | VideoCommon::LoadPipelines(stop_loading, pipeline_cache_filename, CACHE_VERSION, load_compute, |
| 448 | load_graphics); | 448 | load_graphics); |
| 449 | 449 | ||
| 450 | LOG_INFO(Render_Vulkan, "Total Pipeline Count: {}", state.total); | ||
| 451 | |||
| 450 | std::unique_lock lock{state.mutex}; | 452 | std::unique_lock lock{state.mutex}; |
| 451 | callback(VideoCore::LoadCallbackStage::Build, 0, state.total); | 453 | callback(VideoCore::LoadCallbackStage::Build, 0, state.total); |
| 452 | state.has_loaded = true; | 454 | state.has_loaded = true; |
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 3ac18ea54..3bcd6d6cc 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp | |||
| @@ -228,9 +228,7 @@ void RasterizerVulkan::Clear() { | |||
| 228 | }; | 228 | }; |
| 229 | 229 | ||
| 230 | const u32 color_attachment = regs.clear_buffers.RT; | 230 | const u32 color_attachment = regs.clear_buffers.RT; |
| 231 | const auto attachment_aspect_mask = framebuffer->ImageRanges()[color_attachment].aspectMask; | 231 | if (use_color && framebuffer->HasAspectColorBit(color_attachment)) { |
| 232 | const bool is_color_rt = (attachment_aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0; | ||
| 233 | if (use_color && is_color_rt) { | ||
| 234 | VkClearValue clear_value; | 232 | VkClearValue clear_value; |
| 235 | std::memcpy(clear_value.color.float32, regs.clear_color, sizeof(regs.clear_color)); | 233 | std::memcpy(clear_value.color.float32, regs.clear_color, sizeof(regs.clear_color)); |
| 236 | 234 | ||
| @@ -248,12 +246,15 @@ void RasterizerVulkan::Clear() { | |||
| 248 | return; | 246 | return; |
| 249 | } | 247 | } |
| 250 | VkImageAspectFlags aspect_flags = 0; | 248 | VkImageAspectFlags aspect_flags = 0; |
| 251 | if (use_depth) { | 249 | if (use_depth && framebuffer->HasAspectDepthBit()) { |
| 252 | aspect_flags |= VK_IMAGE_ASPECT_DEPTH_BIT; | 250 | aspect_flags |= VK_IMAGE_ASPECT_DEPTH_BIT; |
| 253 | } | 251 | } |
| 254 | if (use_stencil) { | 252 | if (use_stencil && framebuffer->HasAspectStencilBit()) { |
| 255 | aspect_flags |= VK_IMAGE_ASPECT_STENCIL_BIT; | 253 | aspect_flags |= VK_IMAGE_ASPECT_STENCIL_BIT; |
| 256 | } | 254 | } |
| 255 | if (aspect_flags == 0) { | ||
| 256 | return; | ||
| 257 | } | ||
| 257 | scheduler.Record([clear_depth = regs.clear_depth, clear_stencil = regs.clear_stencil, | 258 | scheduler.Record([clear_depth = regs.clear_depth, clear_stencil = regs.clear_stencil, |
| 258 | clear_rect, aspect_flags](vk::CommandBuffer cmdbuf) { | 259 | clear_rect, aspect_flags](vk::CommandBuffer cmdbuf) { |
| 259 | VkClearAttachment attachment; | 260 | VkClearAttachment attachment; |
| @@ -764,12 +765,7 @@ void RasterizerVulkan::UpdateStencilOp(Tegra::Engines::Maxwell3D::Regs& regs) { | |||
| 764 | const Maxwell::StencilOp zpass = regs.stencil_front_op_zpass; | 765 | const Maxwell::StencilOp zpass = regs.stencil_front_op_zpass; |
| 765 | const Maxwell::ComparisonOp compare = regs.stencil_front_func_func; | 766 | const Maxwell::ComparisonOp compare = regs.stencil_front_func_func; |
| 766 | if (regs.stencil_two_side_enable) { | 767 | if (regs.stencil_two_side_enable) { |
| 767 | scheduler.Record([fail, zfail, zpass, compare](vk::CommandBuffer cmdbuf) { | 768 | // Separate stencil op per face |
| 768 | cmdbuf.SetStencilOpEXT(VK_STENCIL_FACE_FRONT_AND_BACK, MaxwellToVK::StencilOp(fail), | ||
| 769 | MaxwellToVK::StencilOp(zpass), MaxwellToVK::StencilOp(zfail), | ||
| 770 | MaxwellToVK::ComparisonOp(compare)); | ||
| 771 | }); | ||
| 772 | } else { | ||
| 773 | const Maxwell::StencilOp back_fail = regs.stencil_back_op_fail; | 769 | const Maxwell::StencilOp back_fail = regs.stencil_back_op_fail; |
| 774 | const Maxwell::StencilOp back_zfail = regs.stencil_back_op_zfail; | 770 | const Maxwell::StencilOp back_zfail = regs.stencil_back_op_zfail; |
| 775 | const Maxwell::StencilOp back_zpass = regs.stencil_back_op_zpass; | 771 | const Maxwell::StencilOp back_zpass = regs.stencil_back_op_zpass; |
| @@ -784,6 +780,13 @@ void RasterizerVulkan::UpdateStencilOp(Tegra::Engines::Maxwell3D::Regs& regs) { | |||
| 784 | MaxwellToVK::StencilOp(back_zfail), | 780 | MaxwellToVK::StencilOp(back_zfail), |
| 785 | MaxwellToVK::ComparisonOp(back_compare)); | 781 | MaxwellToVK::ComparisonOp(back_compare)); |
| 786 | }); | 782 | }); |
| 783 | } else { | ||
| 784 | // Front face defines the stencil op of both faces | ||
| 785 | scheduler.Record([fail, zfail, zpass, compare](vk::CommandBuffer cmdbuf) { | ||
| 786 | cmdbuf.SetStencilOpEXT(VK_STENCIL_FACE_FRONT_AND_BACK, MaxwellToVK::StencilOp(fail), | ||
| 787 | MaxwellToVK::StencilOp(zpass), MaxwellToVK::StencilOp(zfail), | ||
| 788 | MaxwellToVK::ComparisonOp(compare)); | ||
| 789 | }); | ||
| 787 | } | 790 | } |
| 788 | } | 791 | } |
| 789 | 792 | ||
diff --git a/src/video_core/renderer_vulkan/vk_scheduler.cpp b/src/video_core/renderer_vulkan/vk_scheduler.cpp index 4840962de..0c11c814f 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.cpp +++ b/src/video_core/renderer_vulkan/vk_scheduler.cpp | |||
| @@ -43,26 +43,19 @@ VKScheduler::VKScheduler(const Device& device_, StateTracker& state_tracker_) | |||
| 43 | command_pool{std::make_unique<CommandPool>(*master_semaphore, device)} { | 43 | command_pool{std::make_unique<CommandPool>(*master_semaphore, device)} { |
| 44 | AcquireNewChunk(); | 44 | AcquireNewChunk(); |
| 45 | AllocateWorkerCommandBuffer(); | 45 | AllocateWorkerCommandBuffer(); |
| 46 | worker_thread = std::thread(&VKScheduler::WorkerThread, this); | 46 | worker_thread = std::jthread([this](std::stop_token token) { WorkerThread(token); }); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | VKScheduler::~VKScheduler() { | 49 | VKScheduler::~VKScheduler() = default; |
| 50 | { | ||
| 51 | std::lock_guard lock{work_mutex}; | ||
| 52 | quit = true; | ||
| 53 | } | ||
| 54 | work_cv.notify_all(); | ||
| 55 | worker_thread.join(); | ||
| 56 | } | ||
| 57 | 50 | ||
| 58 | void VKScheduler::Flush(VkSemaphore semaphore) { | 51 | void VKScheduler::Flush(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore) { |
| 59 | SubmitExecution(semaphore); | 52 | SubmitExecution(signal_semaphore, wait_semaphore); |
| 60 | AllocateNewContext(); | 53 | AllocateNewContext(); |
| 61 | } | 54 | } |
| 62 | 55 | ||
| 63 | void VKScheduler::Finish(VkSemaphore semaphore) { | 56 | void VKScheduler::Finish(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore) { |
| 64 | const u64 presubmit_tick = CurrentTick(); | 57 | const u64 presubmit_tick = CurrentTick(); |
| 65 | SubmitExecution(semaphore); | 58 | SubmitExecution(signal_semaphore, wait_semaphore); |
| 66 | WaitWorker(); | 59 | WaitWorker(); |
| 67 | Wait(presubmit_tick); | 60 | Wait(presubmit_tick); |
| 68 | AllocateNewContext(); | 61 | AllocateNewContext(); |
| @@ -135,7 +128,7 @@ bool VKScheduler::UpdateGraphicsPipeline(GraphicsPipeline* pipeline) { | |||
| 135 | return true; | 128 | return true; |
| 136 | } | 129 | } |
| 137 | 130 | ||
| 138 | void VKScheduler::WorkerThread() { | 131 | void VKScheduler::WorkerThread(std::stop_token stop_token) { |
| 139 | Common::SetCurrentThreadName("yuzu:VulkanWorker"); | 132 | Common::SetCurrentThreadName("yuzu:VulkanWorker"); |
| 140 | do { | 133 | do { |
| 141 | if (work_queue.empty()) { | 134 | if (work_queue.empty()) { |
| @@ -144,8 +137,8 @@ void VKScheduler::WorkerThread() { | |||
| 144 | std::unique_ptr<CommandChunk> work; | 137 | std::unique_ptr<CommandChunk> work; |
| 145 | { | 138 | { |
| 146 | std::unique_lock lock{work_mutex}; | 139 | std::unique_lock lock{work_mutex}; |
| 147 | work_cv.wait(lock, [this] { return !work_queue.empty() || quit; }); | 140 | work_cv.wait(lock, stop_token, [this] { return !work_queue.empty(); }); |
| 148 | if (quit) { | 141 | if (stop_token.stop_requested()) { |
| 149 | continue; | 142 | continue; |
| 150 | } | 143 | } |
| 151 | work = std::move(work_queue.front()); | 144 | work = std::move(work_queue.front()); |
| @@ -158,7 +151,7 @@ void VKScheduler::WorkerThread() { | |||
| 158 | } | 151 | } |
| 159 | std::lock_guard reserve_lock{reserve_mutex}; | 152 | std::lock_guard reserve_lock{reserve_mutex}; |
| 160 | chunk_reserve.push_back(std::move(work)); | 153 | chunk_reserve.push_back(std::move(work)); |
| 161 | } while (!quit); | 154 | } while (!stop_token.stop_requested()); |
| 162 | } | 155 | } |
| 163 | 156 | ||
| 164 | void VKScheduler::AllocateWorkerCommandBuffer() { | 157 | void VKScheduler::AllocateWorkerCommandBuffer() { |
| @@ -171,37 +164,41 @@ void VKScheduler::AllocateWorkerCommandBuffer() { | |||
| 171 | }); | 164 | }); |
| 172 | } | 165 | } |
| 173 | 166 | ||
| 174 | void VKScheduler::SubmitExecution(VkSemaphore semaphore) { | 167 | void VKScheduler::SubmitExecution(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore) { |
| 175 | EndPendingOperations(); | 168 | EndPendingOperations(); |
| 176 | InvalidateState(); | 169 | InvalidateState(); |
| 177 | 170 | ||
| 178 | const u64 signal_value = master_semaphore->NextTick(); | 171 | const u64 signal_value = master_semaphore->NextTick(); |
| 179 | Record([semaphore, signal_value, this](vk::CommandBuffer cmdbuf) { | 172 | Record([signal_semaphore, wait_semaphore, signal_value, this](vk::CommandBuffer cmdbuf) { |
| 180 | cmdbuf.End(); | 173 | cmdbuf.End(); |
| 181 | |||
| 182 | const u32 num_signal_semaphores = semaphore ? 2U : 1U; | ||
| 183 | |||
| 184 | const u64 wait_value = signal_value - 1; | ||
| 185 | const VkPipelineStageFlags wait_stage_mask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; | ||
| 186 | |||
| 187 | const VkSemaphore timeline_semaphore = master_semaphore->Handle(); | 174 | const VkSemaphore timeline_semaphore = master_semaphore->Handle(); |
| 175 | |||
| 176 | const u32 num_signal_semaphores = signal_semaphore ? 2U : 1U; | ||
| 188 | const std::array signal_values{signal_value, u64(0)}; | 177 | const std::array signal_values{signal_value, u64(0)}; |
| 189 | const std::array signal_semaphores{timeline_semaphore, semaphore}; | 178 | const std::array signal_semaphores{timeline_semaphore, signal_semaphore}; |
| 179 | |||
| 180 | const u32 num_wait_semaphores = wait_semaphore ? 2U : 1U; | ||
| 181 | const std::array wait_values{signal_value - 1, u64(1)}; | ||
| 182 | const std::array wait_semaphores{timeline_semaphore, wait_semaphore}; | ||
| 183 | static constexpr std::array<VkPipelineStageFlags, 2> wait_stage_masks{ | ||
| 184 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, | ||
| 185 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, | ||
| 186 | }; | ||
| 190 | 187 | ||
| 191 | const VkTimelineSemaphoreSubmitInfoKHR timeline_si{ | 188 | const VkTimelineSemaphoreSubmitInfoKHR timeline_si{ |
| 192 | .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR, | 189 | .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR, |
| 193 | .pNext = nullptr, | 190 | .pNext = nullptr, |
| 194 | .waitSemaphoreValueCount = 1, | 191 | .waitSemaphoreValueCount = num_wait_semaphores, |
| 195 | .pWaitSemaphoreValues = &wait_value, | 192 | .pWaitSemaphoreValues = wait_values.data(), |
| 196 | .signalSemaphoreValueCount = num_signal_semaphores, | 193 | .signalSemaphoreValueCount = num_signal_semaphores, |
| 197 | .pSignalSemaphoreValues = signal_values.data(), | 194 | .pSignalSemaphoreValues = signal_values.data(), |
| 198 | }; | 195 | }; |
| 199 | const VkSubmitInfo submit_info{ | 196 | const VkSubmitInfo submit_info{ |
| 200 | .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, | 197 | .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, |
| 201 | .pNext = &timeline_si, | 198 | .pNext = &timeline_si, |
| 202 | .waitSemaphoreCount = 1, | 199 | .waitSemaphoreCount = num_wait_semaphores, |
| 203 | .pWaitSemaphores = &timeline_semaphore, | 200 | .pWaitSemaphores = wait_semaphores.data(), |
| 204 | .pWaitDstStageMask = &wait_stage_mask, | 201 | .pWaitDstStageMask = wait_stage_masks.data(), |
| 205 | .commandBufferCount = 1, | 202 | .commandBufferCount = 1, |
| 206 | .pCommandBuffers = cmdbuf.address(), | 203 | .pCommandBuffers = cmdbuf.address(), |
| 207 | .signalSemaphoreCount = num_signal_semaphores, | 204 | .signalSemaphoreCount = num_signal_semaphores, |
diff --git a/src/video_core/renderer_vulkan/vk_scheduler.h b/src/video_core/renderer_vulkan/vk_scheduler.h index cf39a2363..85fc1712f 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.h +++ b/src/video_core/renderer_vulkan/vk_scheduler.h | |||
| @@ -34,10 +34,10 @@ public: | |||
| 34 | ~VKScheduler(); | 34 | ~VKScheduler(); |
| 35 | 35 | ||
| 36 | /// Sends the current execution context to the GPU. | 36 | /// Sends the current execution context to the GPU. |
| 37 | void Flush(VkSemaphore semaphore = nullptr); | 37 | void Flush(VkSemaphore signal_semaphore = nullptr, VkSemaphore wait_semaphore = nullptr); |
| 38 | 38 | ||
| 39 | /// Sends the current execution context to the GPU and waits for it to complete. | 39 | /// Sends the current execution context to the GPU and waits for it to complete. |
| 40 | void Finish(VkSemaphore semaphore = nullptr); | 40 | void Finish(VkSemaphore signal_semaphore = nullptr, VkSemaphore wait_semaphore = nullptr); |
| 41 | 41 | ||
| 42 | /// Waits for the worker thread to finish executing everything. After this function returns it's | 42 | /// Waits for the worker thread to finish executing everything. After this function returns it's |
| 43 | /// safe to touch worker resources. | 43 | /// safe to touch worker resources. |
| @@ -187,11 +187,11 @@ private: | |||
| 187 | GraphicsPipeline* graphics_pipeline = nullptr; | 187 | GraphicsPipeline* graphics_pipeline = nullptr; |
| 188 | }; | 188 | }; |
| 189 | 189 | ||
| 190 | void WorkerThread(); | 190 | void WorkerThread(std::stop_token stop_token); |
| 191 | 191 | ||
| 192 | void AllocateWorkerCommandBuffer(); | 192 | void AllocateWorkerCommandBuffer(); |
| 193 | 193 | ||
| 194 | void SubmitExecution(VkSemaphore semaphore); | 194 | void SubmitExecution(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore); |
| 195 | 195 | ||
| 196 | void AllocateNewContext(); | 196 | void AllocateNewContext(); |
| 197 | 197 | ||
| @@ -212,7 +212,6 @@ private: | |||
| 212 | vk::CommandBuffer current_cmdbuf; | 212 | vk::CommandBuffer current_cmdbuf; |
| 213 | 213 | ||
| 214 | std::unique_ptr<CommandChunk> chunk; | 214 | std::unique_ptr<CommandChunk> chunk; |
| 215 | std::thread worker_thread; | ||
| 216 | 215 | ||
| 217 | State state; | 216 | State state; |
| 218 | 217 | ||
| @@ -224,9 +223,9 @@ private: | |||
| 224 | std::vector<std::unique_ptr<CommandChunk>> chunk_reserve; | 223 | std::vector<std::unique_ptr<CommandChunk>> chunk_reserve; |
| 225 | std::mutex reserve_mutex; | 224 | std::mutex reserve_mutex; |
| 226 | std::mutex work_mutex; | 225 | std::mutex work_mutex; |
| 227 | std::condition_variable work_cv; | 226 | std::condition_variable_any work_cv; |
| 228 | std::condition_variable wait_cv; | 227 | std::condition_variable wait_cv; |
| 229 | std::atomic_bool quit{}; | 228 | std::jthread worker_thread; |
| 230 | }; | 229 | }; |
| 231 | 230 | ||
| 232 | } // namespace Vulkan | 231 | } // namespace Vulkan |
diff --git a/src/video_core/renderer_vulkan/vk_state_tracker.h b/src/video_core/renderer_vulkan/vk_state_tracker.h index 5f78f6950..d90935f52 100644 --- a/src/video_core/renderer_vulkan/vk_state_tracker.h +++ b/src/video_core/renderer_vulkan/vk_state_tracker.h | |||
| @@ -110,10 +110,6 @@ public: | |||
| 110 | return Exchange(Dirty::DepthTestEnable, false); | 110 | return Exchange(Dirty::DepthTestEnable, false); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | bool TouchDepthBoundsEnable() { | ||
| 114 | return Exchange(Dirty::DepthBoundsEnable, false); | ||
| 115 | } | ||
| 116 | |||
| 117 | bool TouchDepthWriteEnable() { | 113 | bool TouchDepthWriteEnable() { |
| 118 | return Exchange(Dirty::DepthWriteEnable, false); | 114 | return Exchange(Dirty::DepthWriteEnable, false); |
| 119 | } | 115 | } |
diff --git a/src/video_core/renderer_vulkan/vk_swapchain.cpp b/src/video_core/renderer_vulkan/vk_swapchain.cpp index d990eefba..8972a6921 100644 --- a/src/video_core/renderer_vulkan/vk_swapchain.cpp +++ b/src/video_core/renderer_vulkan/vk_swapchain.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | #include "common/assert.h" | 10 | #include "common/assert.h" |
| 11 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 12 | #include "common/settings.h" | ||
| 12 | #include "core/core.h" | 13 | #include "core/core.h" |
| 13 | #include "core/frontend/framebuffer_layout.h" | 14 | #include "core/frontend/framebuffer_layout.h" |
| 14 | #include "video_core/renderer_vulkan/vk_scheduler.h" | 15 | #include "video_core/renderer_vulkan/vk_scheduler.h" |
| @@ -20,16 +21,15 @@ namespace Vulkan { | |||
| 20 | 21 | ||
| 21 | namespace { | 22 | namespace { |
| 22 | 23 | ||
| 23 | VkSurfaceFormatKHR ChooseSwapSurfaceFormat(vk::Span<VkSurfaceFormatKHR> formats, bool srgb) { | 24 | VkSurfaceFormatKHR ChooseSwapSurfaceFormat(vk::Span<VkSurfaceFormatKHR> formats) { |
| 24 | if (formats.size() == 1 && formats[0].format == VK_FORMAT_UNDEFINED) { | 25 | if (formats.size() == 1 && formats[0].format == VK_FORMAT_UNDEFINED) { |
| 25 | VkSurfaceFormatKHR format; | 26 | VkSurfaceFormatKHR format; |
| 26 | format.format = VK_FORMAT_B8G8R8A8_UNORM; | 27 | format.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 27 | format.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; | 28 | format.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; |
| 28 | return format; | 29 | return format; |
| 29 | } | 30 | } |
| 30 | const auto& found = std::find_if(formats.begin(), formats.end(), [srgb](const auto& format) { | 31 | const auto& found = std::find_if(formats.begin(), formats.end(), [](const auto& format) { |
| 31 | const auto request_format = srgb ? VK_FORMAT_B8G8R8A8_SRGB : VK_FORMAT_B8G8R8A8_UNORM; | 32 | return format.format == VK_FORMAT_B8G8R8A8_UNORM && |
| 32 | return format.format == request_format && | ||
| 33 | format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; | 33 | format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; |
| 34 | }); | 34 | }); |
| 35 | return found != formats.end() ? *found : formats[0]; | 35 | return found != formats.end() ? *found : formats[0]; |
| @@ -37,8 +37,19 @@ VkSurfaceFormatKHR ChooseSwapSurfaceFormat(vk::Span<VkSurfaceFormatKHR> formats, | |||
| 37 | 37 | ||
| 38 | VkPresentModeKHR ChooseSwapPresentMode(vk::Span<VkPresentModeKHR> modes) { | 38 | VkPresentModeKHR ChooseSwapPresentMode(vk::Span<VkPresentModeKHR> modes) { |
| 39 | // Mailbox doesn't lock the application like fifo (vsync), prefer it | 39 | // Mailbox doesn't lock the application like fifo (vsync), prefer it |
| 40 | const auto found = std::find(modes.begin(), modes.end(), VK_PRESENT_MODE_MAILBOX_KHR); | 40 | const auto found_mailbox = std::find(modes.begin(), modes.end(), VK_PRESENT_MODE_MAILBOX_KHR); |
| 41 | return found != modes.end() ? *found : VK_PRESENT_MODE_FIFO_KHR; | 41 | if (found_mailbox != modes.end()) { |
| 42 | return VK_PRESENT_MODE_MAILBOX_KHR; | ||
| 43 | } | ||
| 44 | if (Settings::values.disable_fps_limit.GetValue()) { | ||
| 45 | // FIFO present mode locks the framerate to the monitor's refresh rate, | ||
| 46 | // Find an alternative to surpass this limitation if FPS is unlocked. | ||
| 47 | const auto found_imm = std::find(modes.begin(), modes.end(), VK_PRESENT_MODE_IMMEDIATE_KHR); | ||
| 48 | if (found_imm != modes.end()) { | ||
| 49 | return VK_PRESENT_MODE_IMMEDIATE_KHR; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | return VK_PRESENT_MODE_FIFO_KHR; | ||
| 42 | } | 53 | } |
| 43 | 54 | ||
| 44 | VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, u32 width, u32 height) { | 55 | VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, u32 width, u32 height) { |
| @@ -107,14 +118,12 @@ void VKSwapchain::AcquireNextImage() { | |||
| 107 | } | 118 | } |
| 108 | 119 | ||
| 109 | void VKSwapchain::Present(VkSemaphore render_semaphore) { | 120 | void VKSwapchain::Present(VkSemaphore render_semaphore) { |
| 110 | const VkSemaphore present_semaphore{*present_semaphores[frame_index]}; | ||
| 111 | const std::array<VkSemaphore, 2> semaphores{present_semaphore, render_semaphore}; | ||
| 112 | const auto present_queue{device.GetPresentQueue()}; | 121 | const auto present_queue{device.GetPresentQueue()}; |
| 113 | const VkPresentInfoKHR present_info{ | 122 | const VkPresentInfoKHR present_info{ |
| 114 | .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, | 123 | .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, |
| 115 | .pNext = nullptr, | 124 | .pNext = nullptr, |
| 116 | .waitSemaphoreCount = render_semaphore ? 2U : 1U, | 125 | .waitSemaphoreCount = render_semaphore ? 1U : 0U, |
| 117 | .pWaitSemaphores = semaphores.data(), | 126 | .pWaitSemaphores = &render_semaphore, |
| 118 | .swapchainCount = 1, | 127 | .swapchainCount = 1, |
| 119 | .pSwapchains = swapchain.address(), | 128 | .pSwapchains = swapchain.address(), |
| 120 | .pImageIndices = &image_index, | 129 | .pImageIndices = &image_index, |
| @@ -145,8 +154,8 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, | |||
| 145 | const auto formats{physical_device.GetSurfaceFormatsKHR(surface)}; | 154 | const auto formats{physical_device.GetSurfaceFormatsKHR(surface)}; |
| 146 | const auto present_modes{physical_device.GetSurfacePresentModesKHR(surface)}; | 155 | const auto present_modes{physical_device.GetSurfacePresentModesKHR(surface)}; |
| 147 | 156 | ||
| 148 | const VkSurfaceFormatKHR surface_format{ChooseSwapSurfaceFormat(formats, srgb)}; | 157 | const VkSurfaceFormatKHR surface_format{ChooseSwapSurfaceFormat(formats)}; |
| 149 | const VkPresentModeKHR present_mode{ChooseSwapPresentMode(present_modes)}; | 158 | present_mode = ChooseSwapPresentMode(present_modes); |
| 150 | 159 | ||
| 151 | u32 requested_image_count{capabilities.minImageCount + 1}; | 160 | u32 requested_image_count{capabilities.minImageCount + 1}; |
| 152 | if (capabilities.maxImageCount > 0 && requested_image_count > capabilities.maxImageCount) { | 161 | if (capabilities.maxImageCount > 0 && requested_image_count > capabilities.maxImageCount) { |
| @@ -180,6 +189,17 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, | |||
| 180 | swapchain_ci.queueFamilyIndexCount = static_cast<u32>(queue_indices.size()); | 189 | swapchain_ci.queueFamilyIndexCount = static_cast<u32>(queue_indices.size()); |
| 181 | swapchain_ci.pQueueFamilyIndices = queue_indices.data(); | 190 | swapchain_ci.pQueueFamilyIndices = queue_indices.data(); |
| 182 | } | 191 | } |
| 192 | static constexpr std::array view_formats{VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_SRGB}; | ||
| 193 | VkImageFormatListCreateInfo format_list{ | ||
| 194 | .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR, | ||
| 195 | .pNext = nullptr, | ||
| 196 | .viewFormatCount = static_cast<u32>(view_formats.size()), | ||
| 197 | .pViewFormats = view_formats.data(), | ||
| 198 | }; | ||
| 199 | if (device.IsKhrSwapchainMutableFormatEnabled()) { | ||
| 200 | format_list.pNext = std::exchange(swapchain_ci.pNext, &format_list); | ||
| 201 | swapchain_ci.flags |= VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR; | ||
| 202 | } | ||
| 183 | // Request the size again to reduce the possibility of a TOCTOU race condition. | 203 | // Request the size again to reduce the possibility of a TOCTOU race condition. |
| 184 | const auto updated_capabilities = physical_device.GetSurfaceCapabilitiesKHR(surface); | 204 | const auto updated_capabilities = physical_device.GetSurfaceCapabilitiesKHR(surface); |
| 185 | swapchain_ci.imageExtent = ChooseSwapExtent(updated_capabilities, width, height); | 205 | swapchain_ci.imageExtent = ChooseSwapExtent(updated_capabilities, width, height); |
| @@ -188,10 +208,11 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, | |||
| 188 | 208 | ||
| 189 | extent = swapchain_ci.imageExtent; | 209 | extent = swapchain_ci.imageExtent; |
| 190 | current_srgb = srgb; | 210 | current_srgb = srgb; |
| 211 | current_fps_unlocked = Settings::values.disable_fps_limit.GetValue(); | ||
| 191 | 212 | ||
| 192 | images = swapchain.GetImages(); | 213 | images = swapchain.GetImages(); |
| 193 | image_count = static_cast<u32>(images.size()); | 214 | image_count = static_cast<u32>(images.size()); |
| 194 | image_format = surface_format.format; | 215 | image_view_format = srgb ? VK_FORMAT_B8G8R8A8_SRGB : VK_FORMAT_B8G8R8A8_UNORM; |
| 195 | } | 216 | } |
| 196 | 217 | ||
| 197 | void VKSwapchain::CreateSemaphores() { | 218 | void VKSwapchain::CreateSemaphores() { |
| @@ -207,7 +228,7 @@ void VKSwapchain::CreateImageViews() { | |||
| 207 | .flags = 0, | 228 | .flags = 0, |
| 208 | .image = {}, | 229 | .image = {}, |
| 209 | .viewType = VK_IMAGE_VIEW_TYPE_2D, | 230 | .viewType = VK_IMAGE_VIEW_TYPE_2D, |
| 210 | .format = image_format, | 231 | .format = image_view_format, |
| 211 | .components = | 232 | .components = |
| 212 | { | 233 | { |
| 213 | .r = VK_COMPONENT_SWIZZLE_IDENTITY, | 234 | .r = VK_COMPONENT_SWIZZLE_IDENTITY, |
| @@ -240,4 +261,14 @@ void VKSwapchain::Destroy() { | |||
| 240 | swapchain.reset(); | 261 | swapchain.reset(); |
| 241 | } | 262 | } |
| 242 | 263 | ||
| 264 | bool VKSwapchain::HasFpsUnlockChanged() const { | ||
| 265 | return current_fps_unlocked != Settings::values.disable_fps_limit.GetValue(); | ||
| 266 | } | ||
| 267 | |||
| 268 | bool VKSwapchain::NeedsPresentModeUpdate() const { | ||
| 269 | // Mailbox present mode is the ideal for all scenarios. If it is not available, | ||
| 270 | // A different present mode is needed to support unlocked FPS above the monitor's refresh rate. | ||
| 271 | return present_mode != VK_PRESENT_MODE_MAILBOX_KHR && HasFpsUnlockChanged(); | ||
| 272 | } | ||
| 273 | |||
| 243 | } // namespace Vulkan | 274 | } // namespace Vulkan |
diff --git a/src/video_core/renderer_vulkan/vk_swapchain.h b/src/video_core/renderer_vulkan/vk_swapchain.h index 35c2cdc14..61a6d959e 100644 --- a/src/video_core/renderer_vulkan/vk_swapchain.h +++ b/src/video_core/renderer_vulkan/vk_swapchain.h | |||
| @@ -33,6 +33,11 @@ public: | |||
| 33 | /// Presents the rendered image to the swapchain. | 33 | /// Presents the rendered image to the swapchain. |
| 34 | void Present(VkSemaphore render_semaphore); | 34 | void Present(VkSemaphore render_semaphore); |
| 35 | 35 | ||
| 36 | /// Returns true when the swapchain needs to be recreated. | ||
| 37 | bool NeedsRecreation(bool is_srgb) const { | ||
| 38 | return HasColorSpaceChanged(is_srgb) || IsSubOptimal() || NeedsPresentModeUpdate(); | ||
| 39 | } | ||
| 40 | |||
| 36 | /// Returns true when the color space has changed. | 41 | /// Returns true when the color space has changed. |
| 37 | bool HasColorSpaceChanged(bool is_srgb) const { | 42 | bool HasColorSpaceChanged(bool is_srgb) const { |
| 38 | return current_srgb != is_srgb; | 43 | return current_srgb != is_srgb; |
| @@ -68,8 +73,12 @@ public: | |||
| 68 | return *image_views[index]; | 73 | return *image_views[index]; |
| 69 | } | 74 | } |
| 70 | 75 | ||
| 71 | VkFormat GetImageFormat() const { | 76 | VkFormat GetImageViewFormat() const { |
| 72 | return image_format; | 77 | return image_view_format; |
| 78 | } | ||
| 79 | |||
| 80 | VkSemaphore CurrentPresentSemaphore() const { | ||
| 81 | return *present_semaphores[frame_index]; | ||
| 73 | } | 82 | } |
| 74 | 83 | ||
| 75 | private: | 84 | private: |
| @@ -80,6 +89,10 @@ private: | |||
| 80 | 89 | ||
| 81 | void Destroy(); | 90 | void Destroy(); |
| 82 | 91 | ||
| 92 | bool HasFpsUnlockChanged() const; | ||
| 93 | |||
| 94 | bool NeedsPresentModeUpdate() const; | ||
| 95 | |||
| 83 | const VkSurfaceKHR surface; | 96 | const VkSurfaceKHR surface; |
| 84 | const Device& device; | 97 | const Device& device; |
| 85 | VKScheduler& scheduler; | 98 | VKScheduler& scheduler; |
| @@ -96,10 +109,12 @@ private: | |||
| 96 | u32 image_index{}; | 109 | u32 image_index{}; |
| 97 | u32 frame_index{}; | 110 | u32 frame_index{}; |
| 98 | 111 | ||
| 99 | VkFormat image_format{}; | 112 | VkFormat image_view_format{}; |
| 100 | VkExtent2D extent{}; | 113 | VkExtent2D extent{}; |
| 114 | VkPresentModeKHR present_mode{}; | ||
| 101 | 115 | ||
| 102 | bool current_srgb{}; | 116 | bool current_srgb{}; |
| 117 | bool current_fps_unlocked{}; | ||
| 103 | bool is_outdated{}; | 118 | bool is_outdated{}; |
| 104 | bool is_suboptimal{}; | 119 | bool is_suboptimal{}; |
| 105 | }; | 120 | }; |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 8f4df7122..3b87640b5 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp | |||
| @@ -127,7 +127,7 @@ constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) { | |||
| 127 | const auto format_info = MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, false, format); | 127 | const auto format_info = MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, false, format); |
| 128 | VkImageCreateFlags flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; | 128 | VkImageCreateFlags flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 129 | if (info.type == ImageType::e2D && info.resources.layers >= 6 && | 129 | if (info.type == ImageType::e2D && info.resources.layers >= 6 && |
| 130 | info.size.width == info.size.height) { | 130 | info.size.width == info.size.height && !device.HasBrokenCubeImageCompability()) { |
| 131 | flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; | 131 | flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; |
| 132 | } | 132 | } |
| 133 | if (info.type == ImageType::e3D) { | 133 | if (info.type == ImageType::e3D) { |
| @@ -1186,9 +1186,12 @@ Framebuffer::Framebuffer(TextureCacheRuntime& runtime, std::span<ImageView*, NUM | |||
| 1186 | renderpass_key.depth_format = depth_buffer->format; | 1186 | renderpass_key.depth_format = depth_buffer->format; |
| 1187 | num_layers = std::max(num_layers, depth_buffer->range.extent.layers); | 1187 | num_layers = std::max(num_layers, depth_buffer->range.extent.layers); |
| 1188 | images[num_images] = depth_buffer->ImageHandle(); | 1188 | images[num_images] = depth_buffer->ImageHandle(); |
| 1189 | image_ranges[num_images] = MakeSubresourceRange(depth_buffer); | 1189 | const VkImageSubresourceRange subresource_range = MakeSubresourceRange(depth_buffer); |
| 1190 | image_ranges[num_images] = subresource_range; | ||
| 1190 | samples = depth_buffer->Samples(); | 1191 | samples = depth_buffer->Samples(); |
| 1191 | ++num_images; | 1192 | ++num_images; |
| 1193 | has_depth = (subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0; | ||
| 1194 | has_stencil = (subresource_range.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0; | ||
| 1192 | } else { | 1195 | } else { |
| 1193 | renderpass_key.depth_format = PixelFormat::Invalid; | 1196 | renderpass_key.depth_format = PixelFormat::Invalid; |
| 1194 | } | 1197 | } |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h index 5fe6b7ba3..6d5a68bfe 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.h +++ b/src/video_core/renderer_vulkan/vk_texture_cache.h | |||
| @@ -232,6 +232,18 @@ public: | |||
| 232 | return image_ranges; | 232 | return image_ranges; |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | [[nodiscard]] bool HasAspectColorBit(size_t index) const noexcept { | ||
| 236 | return (image_ranges.at(index).aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != 0; | ||
| 237 | } | ||
| 238 | |||
| 239 | [[nodiscard]] bool HasAspectDepthBit() const noexcept { | ||
| 240 | return has_depth; | ||
| 241 | } | ||
| 242 | |||
| 243 | [[nodiscard]] bool HasAspectStencilBit() const noexcept { | ||
| 244 | return has_stencil; | ||
| 245 | } | ||
| 246 | |||
| 235 | private: | 247 | private: |
| 236 | vk::Framebuffer framebuffer; | 248 | vk::Framebuffer framebuffer; |
| 237 | VkRenderPass renderpass{}; | 249 | VkRenderPass renderpass{}; |
| @@ -241,6 +253,8 @@ private: | |||
| 241 | u32 num_images = 0; | 253 | u32 num_images = 0; |
| 242 | std::array<VkImage, 9> images{}; | 254 | std::array<VkImage, 9> images{}; |
| 243 | std::array<VkImageSubresourceRange, 9> image_ranges{}; | 255 | std::array<VkImageSubresourceRange, 9> image_ranges{}; |
| 256 | bool has_depth{}; | ||
| 257 | bool has_stencil{}; | ||
| 244 | }; | 258 | }; |
| 245 | 259 | ||
| 246 | struct TextureCacheParams { | 260 | struct TextureCacheParams { |
diff --git a/src/video_core/shader_environment.cpp b/src/video_core/shader_environment.cpp index 8a4581c19..81a878bb2 100644 --- a/src/video_core/shader_environment.cpp +++ b/src/video_core/shader_environment.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <filesystem> | 6 | #include <filesystem> |
| 6 | #include <fstream> | 7 | #include <fstream> |
| 7 | #include <memory> | 8 | #include <memory> |
diff --git a/src/video_core/texture_cache/slot_vector.h b/src/video_core/texture_cache/slot_vector.h index 6180b8c0e..50df06409 100644 --- a/src/video_core/texture_cache/slot_vector.h +++ b/src/video_core/texture_cache/slot_vector.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <algorithm> | ||
| 7 | #include <array> | 8 | #include <array> |
| 8 | #include <bit> | 9 | #include <bit> |
| 9 | #include <concepts> | 10 | #include <concepts> |
| @@ -30,8 +31,8 @@ struct SlotId { | |||
| 30 | }; | 31 | }; |
| 31 | 32 | ||
| 32 | template <class T> | 33 | template <class T> |
| 33 | requires std::is_nothrow_move_assignable_v<T>&& | 34 | requires std::is_nothrow_move_assignable_v<T> && std::is_nothrow_move_constructible_v<T> |
| 34 | std::is_nothrow_move_constructible_v<T> class SlotVector { | 35 | class SlotVector { |
| 35 | public: | 36 | public: |
| 36 | class Iterator { | 37 | class Iterator { |
| 37 | friend SlotVector<T>; | 38 | friend SlotVector<T>; |
diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index 3b575db4d..cae543a51 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp | |||
| @@ -37,7 +37,8 @@ std::unique_ptr<VideoCore::RendererBase> CreateRenderer( | |||
| 37 | namespace VideoCore { | 37 | namespace VideoCore { |
| 38 | 38 | ||
| 39 | std::unique_ptr<Tegra::GPU> CreateGPU(Core::Frontend::EmuWindow& emu_window, Core::System& system) { | 39 | std::unique_ptr<Tegra::GPU> CreateGPU(Core::Frontend::EmuWindow& emu_window, Core::System& system) { |
| 40 | const bool use_nvdec = Settings::values.use_nvdec_emulation.GetValue(); | 40 | const auto nvdec_value = Settings::values.nvdec_emulation.GetValue(); |
| 41 | const bool use_nvdec = nvdec_value != Settings::NvdecEmulation::Off; | ||
| 41 | const bool use_async = Settings::values.use_asynchronous_gpu_emulation.GetValue(); | 42 | const bool use_async = Settings::values.use_asynchronous_gpu_emulation.GetValue(); |
| 42 | auto gpu = std::make_unique<Tegra::GPU>(system, use_async, use_nvdec); | 43 | auto gpu = std::make_unique<Tegra::GPU>(system, use_async, use_nvdec); |
| 43 | auto context = emu_window.CreateSharedContext(); | 44 | auto context = emu_window.CreateSharedContext(); |
diff --git a/src/video_core/vulkan_common/vulkan_debug_callback.cpp b/src/video_core/vulkan_common/vulkan_debug_callback.cpp index 0f60765bb..cf94e1d39 100644 --- a/src/video_core/vulkan_common/vulkan_debug_callback.cpp +++ b/src/video_core/vulkan_common/vulkan_debug_callback.cpp | |||
| @@ -16,6 +16,7 @@ VkBool32 Callback(VkDebugUtilsMessageSeverityFlagBitsEXT severity, | |||
| 16 | switch (static_cast<u32>(data->messageIdNumber)) { | 16 | switch (static_cast<u32>(data->messageIdNumber)) { |
| 17 | case 0x682a878au: // VUID-vkCmdBindVertexBuffers2EXT-pBuffers-parameter | 17 | case 0x682a878au: // VUID-vkCmdBindVertexBuffers2EXT-pBuffers-parameter |
| 18 | case 0x99fb7dfdu: // UNASSIGNED-RequiredParameter (vkCmdBindVertexBuffers2EXT pBuffers[0]) | 18 | case 0x99fb7dfdu: // UNASSIGNED-RequiredParameter (vkCmdBindVertexBuffers2EXT pBuffers[0]) |
| 19 | case 0xe8616bf2u: // Bound VkDescriptorSet 0x0[] was destroyed. Likely push_descriptor related | ||
| 19 | return VK_FALSE; | 20 | return VK_FALSE; |
| 20 | default: | 21 | default: |
| 21 | break; | 22 | break; |
diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp index 86ca4be54..6388ed2eb 100644 --- a/src/video_core/vulkan_common/vulkan_device.cpp +++ b/src/video_core/vulkan_common/vulkan_device.cpp | |||
| @@ -368,8 +368,9 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR | |||
| 368 | }; | 368 | }; |
| 369 | SetNext(next, demote); | 369 | SetNext(next, demote); |
| 370 | 370 | ||
| 371 | VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8; | ||
| 371 | if (is_int8_supported || is_float16_supported) { | 372 | if (is_int8_supported || is_float16_supported) { |
| 372 | VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8{ | 373 | float16_int8 = { |
| 373 | .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR, | 374 | .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR, |
| 374 | .pNext = nullptr, | 375 | .pNext = nullptr, |
| 375 | .shaderFloat16 = is_float16_supported, | 376 | .shaderFloat16 = is_float16_supported, |
| @@ -587,6 +588,31 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR | |||
| 587 | ext_extended_dynamic_state = false; | 588 | ext_extended_dynamic_state = false; |
| 588 | } | 589 | } |
| 589 | } | 590 | } |
| 591 | sets_per_pool = 64; | ||
| 592 | |||
| 593 | const bool is_amd = | ||
| 594 | driver_id == VK_DRIVER_ID_AMD_PROPRIETARY || driver_id == VK_DRIVER_ID_AMD_OPEN_SOURCE; | ||
| 595 | if (is_amd) { | ||
| 596 | // AMD drivers need a higher amount of Sets per Pool in certain circunstances like in XC2. | ||
| 597 | sets_per_pool = 96; | ||
| 598 | // Disable VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT on AMD GCN4 and lower as it is broken. | ||
| 599 | if (!is_float16_supported) { | ||
| 600 | LOG_WARNING( | ||
| 601 | Render_Vulkan, | ||
| 602 | "AMD GCN4 and earlier do not properly support VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT"); | ||
| 603 | has_broken_cube_compatibility = true; | ||
| 604 | } | ||
| 605 | } | ||
| 606 | const bool is_amd_or_radv = is_amd || driver_id == VK_DRIVER_ID_MESA_RADV; | ||
| 607 | if (ext_sampler_filter_minmax && is_amd_or_radv) { | ||
| 608 | // Disable ext_sampler_filter_minmax on AMD GCN4 and lower as it is broken. | ||
| 609 | if (!is_float16_supported) { | ||
| 610 | LOG_WARNING(Render_Vulkan, | ||
| 611 | "Blacklisting AMD GCN4 and earlier for VK_EXT_sampler_filter_minmax"); | ||
| 612 | ext_sampler_filter_minmax = false; | ||
| 613 | } | ||
| 614 | } | ||
| 615 | |||
| 590 | if (ext_vertex_input_dynamic_state && driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) { | 616 | if (ext_vertex_input_dynamic_state && driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) { |
| 591 | LOG_WARNING(Render_Vulkan, "Blacklisting Intel for VK_EXT_vertex_input_dynamic_state"); | 617 | LOG_WARNING(Render_Vulkan, "Blacklisting Intel for VK_EXT_vertex_input_dynamic_state"); |
| 592 | ext_vertex_input_dynamic_state = false; | 618 | ext_vertex_input_dynamic_state = false; |
| @@ -839,6 +865,8 @@ std::vector<const char*> Device::LoadExtensions(bool requires_surface) { | |||
| 839 | bool has_khr_shader_float16_int8{}; | 865 | bool has_khr_shader_float16_int8{}; |
| 840 | bool has_khr_workgroup_memory_explicit_layout{}; | 866 | bool has_khr_workgroup_memory_explicit_layout{}; |
| 841 | bool has_khr_pipeline_executable_properties{}; | 867 | bool has_khr_pipeline_executable_properties{}; |
| 868 | bool has_khr_image_format_list{}; | ||
| 869 | bool has_khr_swapchain_mutable_format{}; | ||
| 842 | bool has_ext_subgroup_size_control{}; | 870 | bool has_ext_subgroup_size_control{}; |
| 843 | bool has_ext_transform_feedback{}; | 871 | bool has_ext_transform_feedback{}; |
| 844 | bool has_ext_custom_border_color{}; | 872 | bool has_ext_custom_border_color{}; |
| @@ -888,6 +916,9 @@ std::vector<const char*> Device::LoadExtensions(bool requires_surface) { | |||
| 888 | test(has_ext_shader_atomic_int64, VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME, false); | 916 | test(has_ext_shader_atomic_int64, VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME, false); |
| 889 | test(has_khr_workgroup_memory_explicit_layout, | 917 | test(has_khr_workgroup_memory_explicit_layout, |
| 890 | VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME, false); | 918 | VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME, false); |
| 919 | test(has_khr_image_format_list, VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME, false); | ||
| 920 | test(has_khr_swapchain_mutable_format, VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME, | ||
| 921 | false); | ||
| 891 | test(has_ext_line_rasterization, VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME, false); | 922 | test(has_ext_line_rasterization, VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME, false); |
| 892 | if (Settings::values.enable_nsight_aftermath) { | 923 | if (Settings::values.enable_nsight_aftermath) { |
| 893 | test(nv_device_diagnostics_config, VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME, | 924 | test(nv_device_diagnostics_config, VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME, |
| @@ -1066,6 +1097,11 @@ std::vector<const char*> Device::LoadExtensions(bool requires_surface) { | |||
| 1066 | khr_pipeline_executable_properties = true; | 1097 | khr_pipeline_executable_properties = true; |
| 1067 | } | 1098 | } |
| 1068 | } | 1099 | } |
| 1100 | if (has_khr_image_format_list && has_khr_swapchain_mutable_format) { | ||
| 1101 | extensions.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME); | ||
| 1102 | extensions.push_back(VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME); | ||
| 1103 | khr_swapchain_mutable_format = true; | ||
| 1104 | } | ||
| 1069 | if (khr_push_descriptor) { | 1105 | if (khr_push_descriptor) { |
| 1070 | VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor; | 1106 | VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor; |
| 1071 | push_descriptor.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR; | 1107 | push_descriptor.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR; |
diff --git a/src/video_core/vulkan_common/vulkan_device.h b/src/video_core/vulkan_common/vulkan_device.h index 234d74129..d9e74f1aa 100644 --- a/src/video_core/vulkan_common/vulkan_device.h +++ b/src/video_core/vulkan_common/vulkan_device.h | |||
| @@ -224,6 +224,11 @@ public: | |||
| 224 | return khr_pipeline_executable_properties; | 224 | return khr_pipeline_executable_properties; |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | /// Returns true if VK_KHR_swapchain_mutable_format is enabled. | ||
| 228 | bool IsKhrSwapchainMutableFormatEnabled() const { | ||
| 229 | return khr_swapchain_mutable_format; | ||
| 230 | } | ||
| 231 | |||
| 227 | /// Returns true if the device supports VK_KHR_workgroup_memory_explicit_layout. | 232 | /// Returns true if the device supports VK_KHR_workgroup_memory_explicit_layout. |
| 228 | bool IsKhrWorkgroupMemoryExplicitLayoutSupported() const { | 233 | bool IsKhrWorkgroupMemoryExplicitLayoutSupported() const { |
| 229 | return khr_workgroup_memory_explicit_layout; | 234 | return khr_workgroup_memory_explicit_layout; |
| @@ -304,6 +309,11 @@ public: | |||
| 304 | return has_renderdoc || has_nsight_graphics; | 309 | return has_renderdoc || has_nsight_graphics; |
| 305 | } | 310 | } |
| 306 | 311 | ||
| 312 | /// Returns true when the device does not properly support cube compatibility. | ||
| 313 | bool HasBrokenCubeImageCompability() const { | ||
| 314 | return has_broken_cube_compatibility; | ||
| 315 | } | ||
| 316 | |||
| 307 | /// Returns the vendor name reported from Vulkan. | 317 | /// Returns the vendor name reported from Vulkan. |
| 308 | std::string_view GetVendorName() const { | 318 | std::string_view GetVendorName() const { |
| 309 | return vendor_name; | 319 | return vendor_name; |
| @@ -318,6 +328,10 @@ public: | |||
| 318 | return device_access_memory; | 328 | return device_access_memory; |
| 319 | } | 329 | } |
| 320 | 330 | ||
| 331 | u32 GetSetsPerPool() const { | ||
| 332 | return sets_per_pool; | ||
| 333 | } | ||
| 334 | |||
| 321 | private: | 335 | private: |
| 322 | /// Checks if the physical device is suitable. | 336 | /// Checks if the physical device is suitable. |
| 323 | void CheckSuitability(bool requires_swapchain) const; | 337 | void CheckSuitability(bool requires_swapchain) const; |
| @@ -371,6 +385,7 @@ private: | |||
| 371 | VkShaderStageFlags guest_warp_stages{}; ///< Stages where the guest warp size can be forced. | 385 | VkShaderStageFlags guest_warp_stages{}; ///< Stages where the guest warp size can be forced. |
| 372 | u64 device_access_memory{}; ///< Total size of device local memory in bytes. | 386 | u64 device_access_memory{}; ///< Total size of device local memory in bytes. |
| 373 | u32 max_push_descriptors{}; ///< Maximum number of push descriptors | 387 | u32 max_push_descriptors{}; ///< Maximum number of push descriptors |
| 388 | u32 sets_per_pool{}; ///< Sets per Description Pool | ||
| 374 | bool is_optimal_astc_supported{}; ///< Support for native ASTC. | 389 | bool is_optimal_astc_supported{}; ///< Support for native ASTC. |
| 375 | bool is_float16_supported{}; ///< Support for float16 arithmetic. | 390 | bool is_float16_supported{}; ///< Support for float16 arithmetic. |
| 376 | bool is_int8_supported{}; ///< Support for int8 arithmetic. | 391 | bool is_int8_supported{}; ///< Support for int8 arithmetic. |
| @@ -390,6 +405,7 @@ private: | |||
| 390 | bool khr_workgroup_memory_explicit_layout{}; ///< Support for explicit workgroup layouts. | 405 | bool khr_workgroup_memory_explicit_layout{}; ///< Support for explicit workgroup layouts. |
| 391 | bool khr_push_descriptor{}; ///< Support for VK_KHR_push_descritor. | 406 | bool khr_push_descriptor{}; ///< Support for VK_KHR_push_descritor. |
| 392 | bool khr_pipeline_executable_properties{}; ///< Support for executable properties. | 407 | bool khr_pipeline_executable_properties{}; ///< Support for executable properties. |
| 408 | bool khr_swapchain_mutable_format{}; ///< Support for VK_KHR_swapchain_mutable_format. | ||
| 393 | bool ext_index_type_uint8{}; ///< Support for VK_EXT_index_type_uint8. | 409 | bool ext_index_type_uint8{}; ///< Support for VK_EXT_index_type_uint8. |
| 394 | bool ext_sampler_filter_minmax{}; ///< Support for VK_EXT_sampler_filter_minmax. | 410 | bool ext_sampler_filter_minmax{}; ///< Support for VK_EXT_sampler_filter_minmax. |
| 395 | bool ext_depth_range_unrestricted{}; ///< Support for VK_EXT_depth_range_unrestricted. | 411 | bool ext_depth_range_unrestricted{}; ///< Support for VK_EXT_depth_range_unrestricted. |
| @@ -406,6 +422,7 @@ private: | |||
| 406 | bool ext_conservative_rasterization{}; ///< Support for VK_EXT_conservative_rasterization. | 422 | bool ext_conservative_rasterization{}; ///< Support for VK_EXT_conservative_rasterization. |
| 407 | bool ext_provoking_vertex{}; ///< Support for VK_EXT_provoking_vertex. | 423 | bool ext_provoking_vertex{}; ///< Support for VK_EXT_provoking_vertex. |
| 408 | bool nv_device_diagnostics_config{}; ///< Support for VK_NV_device_diagnostics_config. | 424 | bool nv_device_diagnostics_config{}; ///< Support for VK_NV_device_diagnostics_config. |
| 425 | bool has_broken_cube_compatibility{}; ///< Has broken cube compatiblity bit | ||
| 409 | bool has_renderdoc{}; ///< Has RenderDoc attached | 426 | bool has_renderdoc{}; ///< Has RenderDoc attached |
| 410 | bool has_nsight_graphics{}; ///< Has Nsight Graphics attached | 427 | bool has_nsight_graphics{}; ///< Has Nsight Graphics attached |
| 411 | 428 | ||
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 19ba0dbba..402be6a78 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt | |||
| @@ -108,6 +108,9 @@ add_executable(yuzu | |||
| 108 | configuration/configure_system.cpp | 108 | configuration/configure_system.cpp |
| 109 | configuration/configure_system.h | 109 | configuration/configure_system.h |
| 110 | configuration/configure_system.ui | 110 | configuration/configure_system.ui |
| 111 | configuration/configure_tas.cpp | ||
| 112 | configuration/configure_tas.h | ||
| 113 | configuration/configure_tas.ui | ||
| 111 | configuration/configure_touch_from_button.cpp | 114 | configuration/configure_touch_from_button.cpp |
| 112 | configuration/configure_touch_from_button.h | 115 | configuration/configure_touch_from_button.h |
| 113 | configuration/configure_touch_from_button.ui | 116 | configuration/configure_touch_from_button.ui |
| @@ -287,10 +290,6 @@ if (YUZU_USE_QT_WEB_ENGINE) | |||
| 287 | target_compile_definitions(yuzu PRIVATE -DYUZU_USE_QT_WEB_ENGINE) | 290 | target_compile_definitions(yuzu PRIVATE -DYUZU_USE_QT_WEB_ENGINE) |
| 288 | endif () | 291 | endif () |
| 289 | 292 | ||
| 290 | if (YUZU_ENABLE_BOXCAT) | ||
| 291 | target_compile_definitions(yuzu PRIVATE -DYUZU_ENABLE_BOXCAT) | ||
| 292 | endif () | ||
| 293 | |||
| 294 | if(UNIX AND NOT APPLE) | 293 | if(UNIX AND NOT APPLE) |
| 295 | install(TARGETS yuzu RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") | 294 | install(TARGETS yuzu RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") |
| 296 | endif() | 295 | endif() |
diff --git a/src/yuzu/applets/qt_web_browser.cpp b/src/yuzu/applets/qt_web_browser.cpp index 652d99570..7d433ca50 100644 --- a/src/yuzu/applets/qt_web_browser.cpp +++ b/src/yuzu/applets/qt_web_browser.cpp | |||
| @@ -54,6 +54,9 @@ QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system, | |||
| 54 | input_interpreter(std::make_unique<InputInterpreter>(system)), | 54 | input_interpreter(std::make_unique<InputInterpreter>(system)), |
| 55 | default_profile{QWebEngineProfile::defaultProfile()}, | 55 | default_profile{QWebEngineProfile::defaultProfile()}, |
| 56 | global_settings{QWebEngineSettings::globalSettings()} { | 56 | global_settings{QWebEngineSettings::globalSettings()} { |
| 57 | default_profile->setPersistentStoragePath(QString::fromStdString(Common::FS::PathToUTF8String( | ||
| 58 | Common::FS::GetYuzuPath(Common::FS::YuzuPath::YuzuDir) / "qtwebengine"))); | ||
| 59 | |||
| 57 | QWebEngineScript gamepad; | 60 | QWebEngineScript gamepad; |
| 58 | QWebEngineScript window_nx; | 61 | QWebEngineScript window_nx; |
| 59 | 62 | ||
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 2e0ade815..8b9e186b0 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -36,6 +36,7 @@ | |||
| 36 | #include "input_common/keyboard.h" | 36 | #include "input_common/keyboard.h" |
| 37 | #include "input_common/main.h" | 37 | #include "input_common/main.h" |
| 38 | #include "input_common/mouse/mouse_input.h" | 38 | #include "input_common/mouse/mouse_input.h" |
| 39 | #include "input_common/tas/tas_input.h" | ||
| 39 | #include "video_core/renderer_base.h" | 40 | #include "video_core/renderer_base.h" |
| 40 | #include "video_core/video_core.h" | 41 | #include "video_core/video_core.h" |
| 41 | #include "yuzu/bootmanager.h" | 42 | #include "yuzu/bootmanager.h" |
| @@ -301,17 +302,23 @@ GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread_, | |||
| 301 | connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete); | 302 | connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete); |
| 302 | connect(this, &GRenderWindow::ExecuteProgramSignal, parent, &GMainWindow::OnExecuteProgram, | 303 | connect(this, &GRenderWindow::ExecuteProgramSignal, parent, &GMainWindow::OnExecuteProgram, |
| 303 | Qt::QueuedConnection); | 304 | Qt::QueuedConnection); |
| 305 | connect(this, &GRenderWindow::ExitSignal, parent, &GMainWindow::OnExit, Qt::QueuedConnection); | ||
| 304 | } | 306 | } |
| 305 | 307 | ||
| 306 | void GRenderWindow::ExecuteProgram(std::size_t program_index) { | 308 | void GRenderWindow::ExecuteProgram(std::size_t program_index) { |
| 307 | emit ExecuteProgramSignal(program_index); | 309 | emit ExecuteProgramSignal(program_index); |
| 308 | } | 310 | } |
| 309 | 311 | ||
| 312 | void GRenderWindow::Exit() { | ||
| 313 | emit ExitSignal(); | ||
| 314 | } | ||
| 315 | |||
| 310 | GRenderWindow::~GRenderWindow() { | 316 | GRenderWindow::~GRenderWindow() { |
| 311 | input_subsystem->Shutdown(); | 317 | input_subsystem->Shutdown(); |
| 312 | } | 318 | } |
| 313 | 319 | ||
| 314 | void GRenderWindow::OnFrameDisplayed() { | 320 | void GRenderWindow::OnFrameDisplayed() { |
| 321 | input_subsystem->GetTas()->UpdateThread(); | ||
| 315 | if (!first_frame) { | 322 | if (!first_frame) { |
| 316 | first_frame = true; | 323 | first_frame = true; |
| 317 | emit FirstFrameDisplayed(); | 324 | emit FirstFrameDisplayed(); |
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index 402dd2ee1..54c4e2142 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h | |||
| @@ -181,6 +181,9 @@ public: | |||
| 181 | */ | 181 | */ |
| 182 | void ExecuteProgram(std::size_t program_index); | 182 | void ExecuteProgram(std::size_t program_index); |
| 183 | 183 | ||
| 184 | /// Instructs the window to exit the application. | ||
| 185 | void Exit(); | ||
| 186 | |||
| 184 | public slots: | 187 | public slots: |
| 185 | void OnEmulationStarting(EmuThread* emu_thread); | 188 | void OnEmulationStarting(EmuThread* emu_thread); |
| 186 | void OnEmulationStopping(); | 189 | void OnEmulationStopping(); |
| @@ -191,6 +194,7 @@ signals: | |||
| 191 | void Closed(); | 194 | void Closed(); |
| 192 | void FirstFrameDisplayed(); | 195 | void FirstFrameDisplayed(); |
| 193 | void ExecuteProgramSignal(std::size_t program_index); | 196 | void ExecuteProgramSignal(std::size_t program_index); |
| 197 | void ExitSignal(); | ||
| 194 | void MouseActivity(); | 198 | void MouseActivity(); |
| 195 | 199 | ||
| 196 | private: | 200 | private: |
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 85d292bcc..eb941ce02 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -221,7 +221,7 @@ const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> Config::default | |||
| 221 | // This must be in alphabetical order according to action name as it must have the same order as | 221 | // This must be in alphabetical order according to action name as it must have the same order as |
| 222 | // UISetting::values.shortcuts, which is alphabetically ordered. | 222 | // UISetting::values.shortcuts, which is alphabetically ordered. |
| 223 | // clang-format off | 223 | // clang-format off |
| 224 | const std::array<UISettings::Shortcut, 18> Config::default_hotkeys{{ | 224 | const std::array<UISettings::Shortcut, 21> Config::default_hotkeys{{ |
| 225 | {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::WidgetWithChildrenShortcut}}, | 225 | {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::WidgetWithChildrenShortcut}}, |
| 226 | {QStringLiteral("Change Docked Mode"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::ApplicationShortcut}}, | 226 | {QStringLiteral("Change Docked Mode"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::ApplicationShortcut}}, |
| 227 | {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, | 227 | {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, |
| @@ -235,6 +235,9 @@ const std::array<UISettings::Shortcut, 18> Config::default_hotkeys{{ | |||
| 235 | {QStringLiteral("Mute Audio"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"), Qt::WindowShortcut}}, | 235 | {QStringLiteral("Mute Audio"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"), Qt::WindowShortcut}}, |
| 236 | {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, | 236 | {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, |
| 237 | {QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}}, | 237 | {QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}}, |
| 238 | {QStringLiteral("TAS Start/Stop"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F5"), Qt::ApplicationShortcut}}, | ||
| 239 | {QStringLiteral("TAS Reset"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F6"), Qt::ApplicationShortcut}}, | ||
| 240 | {QStringLiteral("TAS Record"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F7"), Qt::ApplicationShortcut}}, | ||
| 238 | {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, | 241 | {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, |
| 239 | {QStringLiteral("Toggle Framerate Limit"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+U"), Qt::ApplicationShortcut}}, | 242 | {QStringLiteral("Toggle Framerate Limit"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+U"), Qt::ApplicationShortcut}}, |
| 240 | {QStringLiteral("Toggle Mouse Panning"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F9"), Qt::ApplicationShortcut}}, | 243 | {QStringLiteral("Toggle Mouse Panning"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F9"), Qt::ApplicationShortcut}}, |
| @@ -542,7 +545,6 @@ void Config::ReadAudioValues() { | |||
| 542 | ReadBasicSetting(Settings::values.audio_device_id); | 545 | ReadBasicSetting(Settings::values.audio_device_id); |
| 543 | ReadBasicSetting(Settings::values.sink_id); | 546 | ReadBasicSetting(Settings::values.sink_id); |
| 544 | } | 547 | } |
| 545 | ReadGlobalSetting(Settings::values.enable_audio_stretching); | ||
| 546 | ReadGlobalSetting(Settings::values.volume); | 548 | ReadGlobalSetting(Settings::values.volume); |
| 547 | 549 | ||
| 548 | qt_config->endGroup(); | 550 | qt_config->endGroup(); |
| @@ -560,10 +562,20 @@ void Config::ReadControlValues() { | |||
| 560 | ReadTouchscreenValues(); | 562 | ReadTouchscreenValues(); |
| 561 | ReadMotionTouchValues(); | 563 | ReadMotionTouchValues(); |
| 562 | 564 | ||
| 565 | #ifdef _WIN32 | ||
| 566 | ReadBasicSetting(Settings::values.enable_raw_input); | ||
| 567 | #else | ||
| 568 | Settings::values.enable_raw_input = false; | ||
| 569 | #endif | ||
| 563 | ReadBasicSetting(Settings::values.emulate_analog_keyboard); | 570 | ReadBasicSetting(Settings::values.emulate_analog_keyboard); |
| 564 | Settings::values.mouse_panning = false; | 571 | Settings::values.mouse_panning = false; |
| 565 | ReadBasicSetting(Settings::values.mouse_panning_sensitivity); | 572 | ReadBasicSetting(Settings::values.mouse_panning_sensitivity); |
| 566 | 573 | ||
| 574 | ReadBasicSetting(Settings::values.tas_enable); | ||
| 575 | ReadBasicSetting(Settings::values.tas_loop); | ||
| 576 | ReadBasicSetting(Settings::values.tas_swap_controllers); | ||
| 577 | ReadBasicSetting(Settings::values.pause_tas_on_load); | ||
| 578 | |||
| 567 | ReadGlobalSetting(Settings::values.use_docked_mode); | 579 | ReadGlobalSetting(Settings::values.use_docked_mode); |
| 568 | 580 | ||
| 569 | // Disable docked mode if handheld is selected | 581 | // Disable docked mode if handheld is selected |
| @@ -661,6 +673,13 @@ void Config::ReadDataStorageValues() { | |||
| 661 | QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir))) | 673 | QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir))) |
| 662 | .toString() | 674 | .toString() |
| 663 | .toStdString()); | 675 | .toStdString()); |
| 676 | FS::SetYuzuPath(FS::YuzuPath::TASDir, | ||
| 677 | qt_config | ||
| 678 | ->value(QStringLiteral("tas_directory"), | ||
| 679 | QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::TASDir))) | ||
| 680 | .toString() | ||
| 681 | .toStdString()); | ||
| 682 | |||
| 664 | ReadBasicSetting(Settings::values.gamecard_inserted); | 683 | ReadBasicSetting(Settings::values.gamecard_inserted); |
| 665 | ReadBasicSetting(Settings::values.gamecard_current_game); | 684 | ReadBasicSetting(Settings::values.gamecard_current_game); |
| 666 | ReadBasicSetting(Settings::values.gamecard_path); | 685 | ReadBasicSetting(Settings::values.gamecard_path); |
| @@ -690,8 +709,6 @@ void Config::ReadDebuggingValues() { | |||
| 690 | 709 | ||
| 691 | void Config::ReadServiceValues() { | 710 | void Config::ReadServiceValues() { |
| 692 | qt_config->beginGroup(QStringLiteral("Services")); | 711 | qt_config->beginGroup(QStringLiteral("Services")); |
| 693 | ReadBasicSetting(Settings::values.bcat_backend); | ||
| 694 | ReadBasicSetting(Settings::values.bcat_boxcat_local); | ||
| 695 | ReadBasicSetting(Settings::values.network_interface); | 712 | ReadBasicSetting(Settings::values.network_interface); |
| 696 | qt_config->endGroup(); | 713 | qt_config->endGroup(); |
| 697 | } | 714 | } |
| @@ -812,7 +829,7 @@ void Config::ReadRendererValues() { | |||
| 812 | ReadGlobalSetting(Settings::values.use_disk_shader_cache); | 829 | ReadGlobalSetting(Settings::values.use_disk_shader_cache); |
| 813 | ReadGlobalSetting(Settings::values.gpu_accuracy); | 830 | ReadGlobalSetting(Settings::values.gpu_accuracy); |
| 814 | ReadGlobalSetting(Settings::values.use_asynchronous_gpu_emulation); | 831 | ReadGlobalSetting(Settings::values.use_asynchronous_gpu_emulation); |
| 815 | ReadGlobalSetting(Settings::values.use_nvdec_emulation); | 832 | ReadGlobalSetting(Settings::values.nvdec_emulation); |
| 816 | ReadGlobalSetting(Settings::values.accelerate_astc); | 833 | ReadGlobalSetting(Settings::values.accelerate_astc); |
| 817 | ReadGlobalSetting(Settings::values.use_vsync); | 834 | ReadGlobalSetting(Settings::values.use_vsync); |
| 818 | ReadGlobalSetting(Settings::values.shader_backend); | 835 | ReadGlobalSetting(Settings::values.shader_backend); |
| @@ -1163,7 +1180,6 @@ void Config::SaveAudioValues() { | |||
| 1163 | WriteBasicSetting(Settings::values.sink_id); | 1180 | WriteBasicSetting(Settings::values.sink_id); |
| 1164 | WriteBasicSetting(Settings::values.audio_device_id); | 1181 | WriteBasicSetting(Settings::values.audio_device_id); |
| 1165 | } | 1182 | } |
| 1166 | WriteGlobalSetting(Settings::values.enable_audio_stretching); | ||
| 1167 | WriteGlobalSetting(Settings::values.volume); | 1183 | WriteGlobalSetting(Settings::values.volume); |
| 1168 | 1184 | ||
| 1169 | qt_config->endGroup(); | 1185 | qt_config->endGroup(); |
| @@ -1184,10 +1200,16 @@ void Config::SaveControlValues() { | |||
| 1184 | WriteGlobalSetting(Settings::values.vibration_enabled); | 1200 | WriteGlobalSetting(Settings::values.vibration_enabled); |
| 1185 | WriteGlobalSetting(Settings::values.enable_accurate_vibrations); | 1201 | WriteGlobalSetting(Settings::values.enable_accurate_vibrations); |
| 1186 | WriteGlobalSetting(Settings::values.motion_enabled); | 1202 | WriteGlobalSetting(Settings::values.motion_enabled); |
| 1203 | WriteBasicSetting(Settings::values.enable_raw_input); | ||
| 1187 | WriteBasicSetting(Settings::values.keyboard_enabled); | 1204 | WriteBasicSetting(Settings::values.keyboard_enabled); |
| 1188 | WriteBasicSetting(Settings::values.emulate_analog_keyboard); | 1205 | WriteBasicSetting(Settings::values.emulate_analog_keyboard); |
| 1189 | WriteBasicSetting(Settings::values.mouse_panning_sensitivity); | 1206 | WriteBasicSetting(Settings::values.mouse_panning_sensitivity); |
| 1190 | 1207 | ||
| 1208 | WriteBasicSetting(Settings::values.tas_enable); | ||
| 1209 | WriteBasicSetting(Settings::values.tas_loop); | ||
| 1210 | WriteBasicSetting(Settings::values.tas_swap_controllers); | ||
| 1211 | WriteBasicSetting(Settings::values.pause_tas_on_load); | ||
| 1212 | |||
| 1191 | qt_config->endGroup(); | 1213 | qt_config->endGroup(); |
| 1192 | } | 1214 | } |
| 1193 | 1215 | ||
| @@ -1215,6 +1237,10 @@ void Config::SaveDataStorageValues() { | |||
| 1215 | WriteSetting(QStringLiteral("dump_directory"), | 1237 | WriteSetting(QStringLiteral("dump_directory"), |
| 1216 | QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)), | 1238 | QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)), |
| 1217 | QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir))); | 1239 | QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir))); |
| 1240 | WriteSetting(QStringLiteral("tas_directory"), | ||
| 1241 | QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::TASDir)), | ||
| 1242 | QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::TASDir))); | ||
| 1243 | |||
| 1218 | WriteBasicSetting(Settings::values.gamecard_inserted); | 1244 | WriteBasicSetting(Settings::values.gamecard_inserted); |
| 1219 | WriteBasicSetting(Settings::values.gamecard_current_game); | 1245 | WriteBasicSetting(Settings::values.gamecard_current_game); |
| 1220 | WriteBasicSetting(Settings::values.gamecard_path); | 1246 | WriteBasicSetting(Settings::values.gamecard_path); |
| @@ -1241,8 +1267,6 @@ void Config::SaveDebuggingValues() { | |||
| 1241 | void Config::SaveNetworkValues() { | 1267 | void Config::SaveNetworkValues() { |
| 1242 | qt_config->beginGroup(QStringLiteral("Services")); | 1268 | qt_config->beginGroup(QStringLiteral("Services")); |
| 1243 | 1269 | ||
| 1244 | WriteBasicSetting(Settings::values.bcat_backend); | ||
| 1245 | WriteBasicSetting(Settings::values.bcat_boxcat_local); | ||
| 1246 | WriteBasicSetting(Settings::values.network_interface); | 1270 | WriteBasicSetting(Settings::values.network_interface); |
| 1247 | 1271 | ||
| 1248 | qt_config->endGroup(); | 1272 | qt_config->endGroup(); |
| @@ -1349,7 +1373,10 @@ void Config::SaveRendererValues() { | |||
| 1349 | static_cast<u32>(Settings::values.gpu_accuracy.GetDefault()), | 1373 | static_cast<u32>(Settings::values.gpu_accuracy.GetDefault()), |
| 1350 | Settings::values.gpu_accuracy.UsingGlobal()); | 1374 | Settings::values.gpu_accuracy.UsingGlobal()); |
| 1351 | WriteGlobalSetting(Settings::values.use_asynchronous_gpu_emulation); | 1375 | WriteGlobalSetting(Settings::values.use_asynchronous_gpu_emulation); |
| 1352 | WriteGlobalSetting(Settings::values.use_nvdec_emulation); | 1376 | WriteSetting(QString::fromStdString(Settings::values.nvdec_emulation.GetLabel()), |
| 1377 | static_cast<u32>(Settings::values.nvdec_emulation.GetValue(global)), | ||
| 1378 | static_cast<u32>(Settings::values.nvdec_emulation.GetDefault()), | ||
| 1379 | Settings::values.nvdec_emulation.UsingGlobal()); | ||
| 1353 | WriteGlobalSetting(Settings::values.accelerate_astc); | 1380 | WriteGlobalSetting(Settings::values.accelerate_astc); |
| 1354 | WriteGlobalSetting(Settings::values.use_vsync); | 1381 | WriteGlobalSetting(Settings::values.use_vsync); |
| 1355 | WriteSetting(QString::fromStdString(Settings::values.shader_backend.GetLabel()), | 1382 | WriteSetting(QString::fromStdString(Settings::values.shader_backend.GetLabel()), |
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 9555f4498..3ee694e7c 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h | |||
| @@ -42,7 +42,7 @@ public: | |||
| 42 | default_mouse_buttons; | 42 | default_mouse_buttons; |
| 43 | static const std::array<int, Settings::NativeKeyboard::NumKeyboardKeys> default_keyboard_keys; | 43 | static const std::array<int, Settings::NativeKeyboard::NumKeyboardKeys> default_keyboard_keys; |
| 44 | static const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> default_keyboard_mods; | 44 | static const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> default_keyboard_mods; |
| 45 | static const std::array<UISettings::Shortcut, 18> default_hotkeys; | 45 | static const std::array<UISettings::Shortcut, 21> default_hotkeys; |
| 46 | 46 | ||
| 47 | private: | 47 | private: |
| 48 | void Initialize(const std::string& config_name); | 48 | void Initialize(const std::string& config_name); |
| @@ -182,5 +182,6 @@ private: | |||
| 182 | Q_DECLARE_METATYPE(Settings::CPUAccuracy); | 182 | Q_DECLARE_METATYPE(Settings::CPUAccuracy); |
| 183 | Q_DECLARE_METATYPE(Settings::GPUAccuracy); | 183 | Q_DECLARE_METATYPE(Settings::GPUAccuracy); |
| 184 | Q_DECLARE_METATYPE(Settings::FullscreenMode); | 184 | Q_DECLARE_METATYPE(Settings::FullscreenMode); |
| 185 | Q_DECLARE_METATYPE(Settings::NvdecEmulation); | ||
| 185 | Q_DECLARE_METATYPE(Settings::RendererBackend); | 186 | Q_DECLARE_METATYPE(Settings::RendererBackend); |
| 186 | Q_DECLARE_METATYPE(Settings::ShaderBackend); | 187 | Q_DECLARE_METATYPE(Settings::ShaderBackend); |
diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index 1d84bf4ed..f437cb53d 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp | |||
| @@ -50,8 +50,6 @@ void ConfigureAudio::SetConfiguration() { | |||
| 50 | const auto volume_value = static_cast<int>(Settings::values.volume.GetValue()); | 50 | const auto volume_value = static_cast<int>(Settings::values.volume.GetValue()); |
| 51 | ui->volume_slider->setValue(volume_value); | 51 | ui->volume_slider->setValue(volume_value); |
| 52 | 52 | ||
| 53 | ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching.GetValue()); | ||
| 54 | |||
| 55 | if (!Settings::IsConfiguringGlobal()) { | 53 | if (!Settings::IsConfiguringGlobal()) { |
| 56 | if (Settings::values.volume.UsingGlobal()) { | 54 | if (Settings::values.volume.UsingGlobal()) { |
| 57 | ui->volume_combo_box->setCurrentIndex(0); | 55 | ui->volume_combo_box->setCurrentIndex(0); |
| @@ -100,8 +98,6 @@ void ConfigureAudio::SetVolumeIndicatorText(int percentage) { | |||
| 100 | } | 98 | } |
| 101 | 99 | ||
| 102 | void ConfigureAudio::ApplyConfiguration() { | 100 | void ConfigureAudio::ApplyConfiguration() { |
| 103 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.enable_audio_stretching, | ||
| 104 | ui->toggle_audio_stretching, enable_audio_stretching); | ||
| 105 | 101 | ||
| 106 | if (Settings::IsConfiguringGlobal()) { | 102 | if (Settings::IsConfiguringGlobal()) { |
| 107 | Settings::values.sink_id = | 103 | Settings::values.sink_id = |
| @@ -162,15 +158,10 @@ void ConfigureAudio::RetranslateUI() { | |||
| 162 | void ConfigureAudio::SetupPerGameUI() { | 158 | void ConfigureAudio::SetupPerGameUI() { |
| 163 | if (Settings::IsConfiguringGlobal()) { | 159 | if (Settings::IsConfiguringGlobal()) { |
| 164 | ui->volume_slider->setEnabled(Settings::values.volume.UsingGlobal()); | 160 | ui->volume_slider->setEnabled(Settings::values.volume.UsingGlobal()); |
| 165 | ui->toggle_audio_stretching->setEnabled( | ||
| 166 | Settings::values.enable_audio_stretching.UsingGlobal()); | ||
| 167 | 161 | ||
| 168 | return; | 162 | return; |
| 169 | } | 163 | } |
| 170 | 164 | ||
| 171 | ConfigurationShared::SetColoredTristate(ui->toggle_audio_stretching, | ||
| 172 | Settings::values.enable_audio_stretching, | ||
| 173 | enable_audio_stretching); | ||
| 174 | connect(ui->volume_combo_box, qOverload<int>(&QComboBox::activated), this, [this](int index) { | 165 | connect(ui->volume_combo_box, qOverload<int>(&QComboBox::activated), this, [this](int index) { |
| 175 | ui->volume_slider->setEnabled(index == 1); | 166 | ui->volume_slider->setEnabled(index == 1); |
| 176 | ConfigurationShared::SetHighlight(ui->volume_layout, index == 1); | 167 | ConfigurationShared::SetHighlight(ui->volume_layout, index == 1); |
diff --git a/src/yuzu/configuration/configure_audio.h b/src/yuzu/configuration/configure_audio.h index 9dbd3d93e..5a01c8de7 100644 --- a/src/yuzu/configuration/configure_audio.h +++ b/src/yuzu/configuration/configure_audio.h | |||
| @@ -41,6 +41,4 @@ private: | |||
| 41 | void SetupPerGameUI(); | 41 | void SetupPerGameUI(); |
| 42 | 42 | ||
| 43 | std::unique_ptr<Ui::ConfigureAudio> ui; | 43 | std::unique_ptr<Ui::ConfigureAudio> ui; |
| 44 | |||
| 45 | ConfigurationShared::CheckState enable_audio_stretching; | ||
| 46 | }; | 44 | }; |
diff --git a/src/yuzu/configuration/configure_audio.ui b/src/yuzu/configuration/configure_audio.ui index 9bd0cca96..bf736fc2c 100644 --- a/src/yuzu/configuration/configure_audio.ui +++ b/src/yuzu/configuration/configure_audio.ui | |||
| @@ -32,16 +32,6 @@ | |||
| 32 | </layout> | 32 | </layout> |
| 33 | </item> | 33 | </item> |
| 34 | <item> | 34 | <item> |
| 35 | <widget class="QCheckBox" name="toggle_audio_stretching"> | ||
| 36 | <property name="toolTip"> | ||
| 37 | <string>This post-processing effect adjusts audio speed to match emulation speed and helps prevent audio stutter. This however increases audio latency.</string> | ||
| 38 | </property> | ||
| 39 | <property name="text"> | ||
| 40 | <string>Enable audio stretching</string> | ||
| 41 | </property> | ||
| 42 | </widget> | ||
| 43 | </item> | ||
| 44 | <item> | ||
| 45 | <layout class="QHBoxLayout" name="_2"> | 35 | <layout class="QHBoxLayout" name="_2"> |
| 46 | <item> | 36 | <item> |
| 47 | <widget class="QLabel" name="audio_device_label"> | 37 | <widget class="QLabel" name="audio_device_label"> |
diff --git a/src/yuzu/configuration/configure_debug.ui b/src/yuzu/configuration/configure_debug.ui index 3fe9ff7de..b884a56b0 100644 --- a/src/yuzu/configuration/configure_debug.ui +++ b/src/yuzu/configuration/configure_debug.ui | |||
| @@ -2,85 +2,55 @@ | |||
| 2 | <ui version="4.0"> | 2 | <ui version="4.0"> |
| 3 | <class>ConfigureDebug</class> | 3 | <class>ConfigureDebug</class> |
| 4 | <widget class="QWidget" name="ConfigureDebug"> | 4 | <widget class="QWidget" name="ConfigureDebug"> |
| 5 | <property name="geometry"> | ||
| 6 | <rect> | ||
| 7 | <x>0</x> | ||
| 8 | <y>0</y> | ||
| 9 | <width>400</width> | ||
| 10 | <height>777</height> | ||
| 11 | </rect> | ||
| 12 | </property> | ||
| 13 | <property name="windowTitle"> | ||
| 14 | <string>Form</string> | ||
| 15 | </property> | ||
| 16 | <layout class="QVBoxLayout" name="verticalLayout_1"> | 5 | <layout class="QVBoxLayout" name="verticalLayout_1"> |
| 17 | <item> | 6 | <item> |
| 18 | <widget class="QGroupBox" name="groupBox_2"> | 7 | <widget class="QGroupBox" name="groupBox_2"> |
| 19 | <property name="title"> | 8 | <property name="title"> |
| 20 | <string>Logging</string> | 9 | <string>Logging</string> |
| 21 | </property> | 10 | </property> |
| 22 | <layout class="QVBoxLayout" name="verticalLayout_4"> | 11 | <layout class="QGridLayout" name="gridLayout_1"> |
| 23 | <item> | 12 | <item row="0" column="0" colspan="2"> |
| 24 | <layout class="QHBoxLayout" name="horizontalLayout_2"> | 13 | <layout class="QHBoxLayout" name="horizontalLayout_1"> |
| 25 | <item> | 14 | <item> |
| 26 | <widget class="QLabel" name="label_1"> | 15 | <widget class="QLabel" name="label_1"> |
| 27 | <property name="text"> | 16 | <property name="text"> |
| 28 | <string>Global Log Filter</string> | 17 | <string>Global Log Filter</string> |
| 18 | </property> | ||
| 19 | </widget> | ||
| 20 | </item> | ||
| 21 | <item> | ||
| 22 | <widget class="QLineEdit" name="log_filter_edit"/> | ||
| 23 | </item> | ||
| 24 | </layout> | ||
| 25 | </item> | ||
| 26 | <item row="1" column="0"> | ||
| 27 | <widget class="QCheckBox" name="toggle_console"> | ||
| 28 | <property name="text"> | ||
| 29 | <string>Show Log in Console</string> | ||
| 30 | </property> | ||
| 31 | </widget> | ||
| 32 | </item> | ||
| 33 | <item row="1" column="1"> | ||
| 34 | <widget class="QPushButton" name="open_log_button"> | ||
| 35 | <property name="text"> | ||
| 36 | <string>Open Log Location</string> | ||
| 37 | </property> | ||
| 38 | </widget> | ||
| 39 | </item> | ||
| 40 | <item row="2" column="0"> | ||
| 41 | <widget class="QCheckBox" name="extended_logging"> | ||
| 42 | <property name="enabled"> | ||
| 43 | <bool>true</bool> | ||
| 29 | </property> | 44 | </property> |
| 30 | </widget> | 45 | <property name="toolTip"> |
| 31 | </item> | 46 | <string>When checked, the max size of the log increases from 100 MB to 1 GB</string> |
| 32 | <item> | ||
| 33 | <widget class="QLineEdit" name="log_filter_edit"/> | ||
| 34 | </item> | ||
| 35 | </layout> | ||
| 36 | </item> | ||
| 37 | <item> | ||
| 38 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | ||
| 39 | <item> | ||
| 40 | <widget class="QCheckBox" name="toggle_console"> | ||
| 41 | <property name="text"> | ||
| 42 | <string>Show Log in Console</string> | ||
| 43 | </property> | 47 | </property> |
| 44 | </widget> | ||
| 45 | </item> | ||
| 46 | <item> | ||
| 47 | <widget class="QPushButton" name="open_log_button"> | ||
| 48 | <property name="text"> | 48 | <property name="text"> |
| 49 | <string>Open Log Location</string> | 49 | <string>Enable Extended Logging**</string> |
| 50 | </property> | 50 | </property> |
| 51 | </widget> | 51 | </widget> |
| 52 | </item> | 52 | </item> |
| 53 | </layout> | 53 | </layout> |
| 54 | </item> | ||
| 55 | <item> | ||
| 56 | <widget class="QCheckBox" name="extended_logging"> | ||
| 57 | <property name="enabled"> | ||
| 58 | <bool>true</bool> | ||
| 59 | </property> | ||
| 60 | <property name="toolTip"> | ||
| 61 | <string>When checked, the max size of the log increases from 100 MB to 1 GB</string> | ||
| 62 | </property> | ||
| 63 | <property name="text"> | ||
| 64 | <string>Enable Extended Logging</string> | ||
| 65 | </property> | ||
| 66 | </widget> | ||
| 67 | </item> | ||
| 68 | <item> | ||
| 69 | <widget class="QLabel" name="label_2"> | ||
| 70 | <property name="font"> | ||
| 71 | <font> | ||
| 72 | <italic>true</italic> | ||
| 73 | </font> | ||
| 74 | </property> | ||
| 75 | <property name="text"> | ||
| 76 | <string>This will be reset automatically when yuzu closes.</string> | ||
| 77 | </property> | ||
| 78 | <property name="indent"> | ||
| 79 | <number>20</number> | ||
| 80 | </property> | ||
| 81 | </widget> | ||
| 82 | </item> | ||
| 83 | </layout> | ||
| 84 | </widget> | 54 | </widget> |
| 85 | </item> | 55 | </item> |
| 86 | <item> | 56 | <item> |
| @@ -111,7 +81,7 @@ | |||
| 111 | <property name="title"> | 81 | <property name="title"> |
| 112 | <string>Graphics</string> | 82 | <string>Graphics</string> |
| 113 | </property> | 83 | </property> |
| 114 | <layout class="QGridLayout" name="gridLayout_3"> | 84 | <layout class="QGridLayout" name="gridLayout_2"> |
| 115 | <item row="0" column="0"> | 85 | <item row="0" column="0"> |
| 116 | <widget class="QCheckBox" name="enable_graphics_debugging"> | 86 | <widget class="QCheckBox" name="enable_graphics_debugging"> |
| 117 | <property name="enabled"> | 87 | <property name="enabled"> |
| @@ -176,33 +146,18 @@ | |||
| 176 | <property name="title"> | 146 | <property name="title"> |
| 177 | <string>Debugging</string> | 147 | <string>Debugging</string> |
| 178 | </property> | 148 | </property> |
| 179 | <layout class="QVBoxLayout" name="verticalLayout_7"> | 149 | <layout class="QGridLayout" name="gridLayout_3"> |
| 180 | <item> | 150 | <item row="0" column="0"> |
| 181 | <widget class="QCheckBox" name="fs_access_log"> | 151 | <widget class="QCheckBox" name="fs_access_log"> |
| 182 | <property name="text"> | 152 | <property name="text"> |
| 183 | <string>Enable FS Access Log</string> | 153 | <string>Enable FS Access Log</string> |
| 184 | </property> | 154 | </property> |
| 185 | </widget> | 155 | </widget> |
| 186 | </item> | 156 | </item> |
| 187 | <item> | 157 | <item row="1" column="0"> |
| 188 | <widget class="QCheckBox" name="reporting_services"> | 158 | <widget class="QCheckBox" name="reporting_services"> |
| 189 | <property name="text"> | 159 | <property name="text"> |
| 190 | <string>Enable Verbose Reporting Services</string> | 160 | <string>Enable Verbose Reporting Services**</string> |
| 191 | </property> | ||
| 192 | </widget> | ||
| 193 | </item> | ||
| 194 | <item> | ||
| 195 | <widget class="QLabel" name="label_4"> | ||
| 196 | <property name="font"> | ||
| 197 | <font> | ||
| 198 | <italic>true</italic> | ||
| 199 | </font> | ||
| 200 | </property> | ||
| 201 | <property name="text"> | ||
| 202 | <string>This will be reset automatically when yuzu closes.</string> | ||
| 203 | </property> | ||
| 204 | <property name="indent"> | ||
| 205 | <number>20</number> | ||
| 206 | </property> | 161 | </property> |
| 207 | </widget> | 162 | </widget> |
| 208 | </item> | 163 | </item> |
| @@ -214,47 +169,32 @@ | |||
| 214 | <property name="title"> | 169 | <property name="title"> |
| 215 | <string>Advanced</string> | 170 | <string>Advanced</string> |
| 216 | </property> | 171 | </property> |
| 217 | <layout class="QVBoxLayout" name="verticalLayout_8"> | 172 | <layout class="QGridLayout" name="gridLayout_4"> |
| 218 | <item> | 173 | <item> row="0" column="0"> |
| 219 | <widget class="QCheckBox" name="quest_flag"> | 174 | <widget class="QCheckBox" name="quest_flag"> |
| 220 | <property name="text"> | 175 | <property name="text"> |
| 221 | <string>Kiosk (Quest) Mode</string> | 176 | <string>Kiosk (Quest) Mode</string> |
| 222 | </property> | 177 | </property> |
| 223 | </widget> | 178 | </widget> |
| 224 | </item> | 179 | </item> |
| 225 | <item> | 180 | <item row="1" column="0"> |
| 226 | <widget class="QCheckBox" name="enable_cpu_debugging"> | 181 | <widget class="QCheckBox" name="enable_cpu_debugging"> |
| 227 | <property name="text"> | 182 | <property name="text"> |
| 228 | <string>Enable CPU Debugging</string> | 183 | <string>Enable CPU Debugging</string> |
| 229 | </property> | 184 | </property> |
| 230 | </widget> | 185 | </widget> |
| 231 | </item> | 186 | </item> |
| 232 | <item> | 187 | <item row="2" column="0"> |
| 233 | <widget class="QCheckBox" name="use_debug_asserts"> | 188 | <widget class="QCheckBox" name="use_debug_asserts"> |
| 234 | <property name="text"> | 189 | <property name="text"> |
| 235 | <string>Enable Debug Asserts</string> | 190 | <string>Enable Debug Asserts</string> |
| 236 | </property> | 191 | </property> |
| 237 | </widget> | 192 | </widget> |
| 238 | </item> | 193 | </item> |
| 239 | <item> | 194 | <item row="0" column="1"> |
| 240 | <widget class="QCheckBox" name="use_auto_stub"> | 195 | <widget class="QCheckBox" name="use_auto_stub"> |
| 241 | <property name="text"> | 196 | <property name="text"> |
| 242 | <string>Enable Auto-Stub</string> | 197 | <string>Enable Auto-Stub**</string> |
| 243 | </property> | ||
| 244 | </widget> | ||
| 245 | </item> | ||
| 246 | <item> | ||
| 247 | <widget class="QLabel" name="label_5"> | ||
| 248 | <property name="font"> | ||
| 249 | <font> | ||
| 250 | <italic>true</italic> | ||
| 251 | </font> | ||
| 252 | </property> | ||
| 253 | <property name="text"> | ||
| 254 | <string>This will be reset automatically when yuzu closes.</string> | ||
| 255 | </property> | ||
| 256 | <property name="indent"> | ||
| 257 | <number>20</number> | ||
| 258 | </property> | 198 | </property> |
| 259 | </widget> | 199 | </widget> |
| 260 | </item> | 200 | </item> |
| @@ -262,20 +202,19 @@ | |||
| 262 | </widget> | 202 | </widget> |
| 263 | </item> | 203 | </item> |
| 264 | <item> | 204 | <item> |
| 265 | <spacer name="verticalSpacer"> | 205 | <widget class="QLabel" name="label_5"> |
| 266 | <property name="orientation"> | 206 | <property name="font"> |
| 267 | <enum>Qt::Vertical</enum> | 207 | <font> |
| 208 | <italic>true</italic> | ||
| 209 | </font> | ||
| 268 | </property> | 210 | </property> |
| 269 | <property name="sizeType"> | 211 | <property name="text"> |
| 270 | <enum>QSizePolicy::Expanding</enum> | 212 | <string>**This will be reset automatically when yuzu closes.</string> |
| 271 | </property> | 213 | </property> |
| 272 | <property name="sizeHint" stdset="0"> | 214 | <property name="indent"> |
| 273 | <size> | 215 | <number>20</number> |
| 274 | <width>20</width> | ||
| 275 | <height>40</height> | ||
| 276 | </size> | ||
| 277 | </property> | 216 | </property> |
| 278 | </spacer> | 217 | </widget> |
| 279 | </item> | 218 | </item> |
| 280 | </layout> | 219 | </layout> |
| 281 | </widget> | 220 | </widget> |
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 37e896258..c594164be 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp | |||
| @@ -88,24 +88,30 @@ void ConfigureGraphics::SetConfiguration() { | |||
| 88 | ui->api_widget->setEnabled(runtime_lock); | 88 | ui->api_widget->setEnabled(runtime_lock); |
| 89 | ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock); | 89 | ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock); |
| 90 | ui->use_disk_shader_cache->setEnabled(runtime_lock); | 90 | ui->use_disk_shader_cache->setEnabled(runtime_lock); |
| 91 | ui->use_nvdec_emulation->setEnabled(runtime_lock); | 91 | ui->nvdec_emulation_widget->setEnabled(runtime_lock); |
| 92 | ui->accelerate_astc->setEnabled(runtime_lock); | 92 | ui->accelerate_astc->setEnabled(runtime_lock); |
| 93 | ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache.GetValue()); | 93 | ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache.GetValue()); |
| 94 | ui->use_asynchronous_gpu_emulation->setChecked( | 94 | ui->use_asynchronous_gpu_emulation->setChecked( |
| 95 | Settings::values.use_asynchronous_gpu_emulation.GetValue()); | 95 | Settings::values.use_asynchronous_gpu_emulation.GetValue()); |
| 96 | ui->use_nvdec_emulation->setChecked(Settings::values.use_nvdec_emulation.GetValue()); | ||
| 97 | ui->accelerate_astc->setChecked(Settings::values.accelerate_astc.GetValue()); | 96 | ui->accelerate_astc->setChecked(Settings::values.accelerate_astc.GetValue()); |
| 98 | 97 | ||
| 99 | if (Settings::IsConfiguringGlobal()) { | 98 | if (Settings::IsConfiguringGlobal()) { |
| 100 | ui->api->setCurrentIndex(static_cast<int>(Settings::values.renderer_backend.GetValue())); | 99 | ui->api->setCurrentIndex(static_cast<int>(Settings::values.renderer_backend.GetValue())); |
| 101 | ui->fullscreen_mode_combobox->setCurrentIndex( | 100 | ui->fullscreen_mode_combobox->setCurrentIndex( |
| 102 | static_cast<int>(Settings::values.fullscreen_mode.GetValue())); | 101 | static_cast<int>(Settings::values.fullscreen_mode.GetValue())); |
| 102 | ui->nvdec_emulation->setCurrentIndex( | ||
| 103 | static_cast<int>(Settings::values.nvdec_emulation.GetValue())); | ||
| 103 | ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); | 104 | ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); |
| 104 | } else { | 105 | } else { |
| 105 | ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend); | 106 | ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend); |
| 106 | ConfigurationShared::SetHighlight(ui->api_widget, | 107 | ConfigurationShared::SetHighlight(ui->api_widget, |
| 107 | !Settings::values.renderer_backend.UsingGlobal()); | 108 | !Settings::values.renderer_backend.UsingGlobal()); |
| 108 | 109 | ||
| 110 | ConfigurationShared::SetPerGameSetting(ui->nvdec_emulation, | ||
| 111 | &Settings::values.nvdec_emulation); | ||
| 112 | ConfigurationShared::SetHighlight(ui->nvdec_emulation_widget, | ||
| 113 | !Settings::values.nvdec_emulation.UsingGlobal()); | ||
| 114 | |||
| 109 | ConfigurationShared::SetPerGameSetting(ui->fullscreen_mode_combobox, | 115 | ConfigurationShared::SetPerGameSetting(ui->fullscreen_mode_combobox, |
| 110 | &Settings::values.fullscreen_mode); | 116 | &Settings::values.fullscreen_mode); |
| 111 | ConfigurationShared::SetHighlight(ui->fullscreen_mode_label, | 117 | ConfigurationShared::SetHighlight(ui->fullscreen_mode_label, |
| @@ -137,8 +143,6 @@ void ConfigureGraphics::ApplyConfiguration() { | |||
| 137 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation, | 143 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation, |
| 138 | ui->use_asynchronous_gpu_emulation, | 144 | ui->use_asynchronous_gpu_emulation, |
| 139 | use_asynchronous_gpu_emulation); | 145 | use_asynchronous_gpu_emulation); |
| 140 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_nvdec_emulation, | ||
| 141 | ui->use_nvdec_emulation, use_nvdec_emulation); | ||
| 142 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.accelerate_astc, ui->accelerate_astc, | 146 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.accelerate_astc, ui->accelerate_astc, |
| 143 | accelerate_astc); | 147 | accelerate_astc); |
| 144 | 148 | ||
| @@ -147,6 +151,9 @@ void ConfigureGraphics::ApplyConfiguration() { | |||
| 147 | if (Settings::values.renderer_backend.UsingGlobal()) { | 151 | if (Settings::values.renderer_backend.UsingGlobal()) { |
| 148 | Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend()); | 152 | Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend()); |
| 149 | } | 153 | } |
| 154 | if (Settings::values.nvdec_emulation.UsingGlobal()) { | ||
| 155 | Settings::values.nvdec_emulation.SetValue(GetCurrentNvdecEmulation()); | ||
| 156 | } | ||
| 150 | if (Settings::values.shader_backend.UsingGlobal()) { | 157 | if (Settings::values.shader_backend.UsingGlobal()) { |
| 151 | Settings::values.shader_backend.SetValue(shader_backend); | 158 | Settings::values.shader_backend.SetValue(shader_backend); |
| 152 | } | 159 | } |
| @@ -180,6 +187,13 @@ void ConfigureGraphics::ApplyConfiguration() { | |||
| 180 | } | 187 | } |
| 181 | } | 188 | } |
| 182 | 189 | ||
| 190 | if (ui->nvdec_emulation->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { | ||
| 191 | Settings::values.nvdec_emulation.SetGlobal(true); | ||
| 192 | } else { | ||
| 193 | Settings::values.nvdec_emulation.SetGlobal(false); | ||
| 194 | Settings::values.nvdec_emulation.SetValue(GetCurrentNvdecEmulation()); | ||
| 195 | } | ||
| 196 | |||
| 183 | if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { | 197 | if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { |
| 184 | Settings::values.bg_red.SetGlobal(true); | 198 | Settings::values.bg_red.SetGlobal(true); |
| 185 | Settings::values.bg_green.SetGlobal(true); | 199 | Settings::values.bg_green.SetGlobal(true); |
| @@ -278,6 +292,20 @@ Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const { | |||
| 278 | ConfigurationShared::USE_GLOBAL_OFFSET); | 292 | ConfigurationShared::USE_GLOBAL_OFFSET); |
| 279 | } | 293 | } |
| 280 | 294 | ||
| 295 | Settings::NvdecEmulation ConfigureGraphics::GetCurrentNvdecEmulation() const { | ||
| 296 | if (Settings::IsConfiguringGlobal()) { | ||
| 297 | return static_cast<Settings::NvdecEmulation>(ui->nvdec_emulation->currentIndex()); | ||
| 298 | } | ||
| 299 | |||
| 300 | if (ui->nvdec_emulation->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { | ||
| 301 | Settings::values.nvdec_emulation.SetGlobal(true); | ||
| 302 | return Settings::values.nvdec_emulation.GetValue(); | ||
| 303 | } | ||
| 304 | Settings::values.nvdec_emulation.SetGlobal(false); | ||
| 305 | return static_cast<Settings::NvdecEmulation>(ui->nvdec_emulation->currentIndex() - | ||
| 306 | ConfigurationShared::USE_GLOBAL_OFFSET); | ||
| 307 | } | ||
| 308 | |||
| 281 | void ConfigureGraphics::SetupPerGameUI() { | 309 | void ConfigureGraphics::SetupPerGameUI() { |
| 282 | if (Settings::IsConfiguringGlobal()) { | 310 | if (Settings::IsConfiguringGlobal()) { |
| 283 | ui->api->setEnabled(Settings::values.renderer_backend.UsingGlobal()); | 311 | ui->api->setEnabled(Settings::values.renderer_backend.UsingGlobal()); |
| @@ -286,7 +314,7 @@ void ConfigureGraphics::SetupPerGameUI() { | |||
| 286 | ui->aspect_ratio_combobox->setEnabled(Settings::values.aspect_ratio.UsingGlobal()); | 314 | ui->aspect_ratio_combobox->setEnabled(Settings::values.aspect_ratio.UsingGlobal()); |
| 287 | ui->use_asynchronous_gpu_emulation->setEnabled( | 315 | ui->use_asynchronous_gpu_emulation->setEnabled( |
| 288 | Settings::values.use_asynchronous_gpu_emulation.UsingGlobal()); | 316 | Settings::values.use_asynchronous_gpu_emulation.UsingGlobal()); |
| 289 | ui->use_nvdec_emulation->setEnabled(Settings::values.use_nvdec_emulation.UsingGlobal()); | 317 | ui->nvdec_emulation->setEnabled(Settings::values.nvdec_emulation.UsingGlobal()); |
| 290 | ui->accelerate_astc->setEnabled(Settings::values.accelerate_astc.UsingGlobal()); | 318 | ui->accelerate_astc->setEnabled(Settings::values.accelerate_astc.UsingGlobal()); |
| 291 | ui->use_disk_shader_cache->setEnabled(Settings::values.use_disk_shader_cache.UsingGlobal()); | 319 | ui->use_disk_shader_cache->setEnabled(Settings::values.use_disk_shader_cache.UsingGlobal()); |
| 292 | ui->bg_button->setEnabled(Settings::values.bg_red.UsingGlobal()); | 320 | ui->bg_button->setEnabled(Settings::values.bg_red.UsingGlobal()); |
| @@ -301,8 +329,6 @@ void ConfigureGraphics::SetupPerGameUI() { | |||
| 301 | 329 | ||
| 302 | ConfigurationShared::SetColoredTristate( | 330 | ConfigurationShared::SetColoredTristate( |
| 303 | ui->use_disk_shader_cache, Settings::values.use_disk_shader_cache, use_disk_shader_cache); | 331 | ui->use_disk_shader_cache, Settings::values.use_disk_shader_cache, use_disk_shader_cache); |
| 304 | ConfigurationShared::SetColoredTristate( | ||
| 305 | ui->use_nvdec_emulation, Settings::values.use_nvdec_emulation, use_nvdec_emulation); | ||
| 306 | ConfigurationShared::SetColoredTristate(ui->accelerate_astc, Settings::values.accelerate_astc, | 332 | ConfigurationShared::SetColoredTristate(ui->accelerate_astc, Settings::values.accelerate_astc, |
| 307 | accelerate_astc); | 333 | accelerate_astc); |
| 308 | ConfigurationShared::SetColoredTristate(ui->use_asynchronous_gpu_emulation, | 334 | ConfigurationShared::SetColoredTristate(ui->use_asynchronous_gpu_emulation, |
| @@ -316,4 +342,6 @@ void ConfigureGraphics::SetupPerGameUI() { | |||
| 316 | static_cast<int>(Settings::values.fullscreen_mode.GetValue(true))); | 342 | static_cast<int>(Settings::values.fullscreen_mode.GetValue(true))); |
| 317 | ConfigurationShared::InsertGlobalItem( | 343 | ConfigurationShared::InsertGlobalItem( |
| 318 | ui->api, static_cast<int>(Settings::values.renderer_backend.GetValue(true))); | 344 | ui->api, static_cast<int>(Settings::values.renderer_backend.GetValue(true))); |
| 345 | ConfigurationShared::InsertGlobalItem( | ||
| 346 | ui->nvdec_emulation, static_cast<int>(Settings::values.nvdec_emulation.GetValue(true))); | ||
| 319 | } | 347 | } |
diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index c866b911b..7d7ac329d 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h | |||
| @@ -43,6 +43,7 @@ private: | |||
| 43 | void SetupPerGameUI(); | 43 | void SetupPerGameUI(); |
| 44 | 44 | ||
| 45 | Settings::RendererBackend GetCurrentGraphicsBackend() const; | 45 | Settings::RendererBackend GetCurrentGraphicsBackend() const; |
| 46 | Settings::NvdecEmulation GetCurrentNvdecEmulation() const; | ||
| 46 | 47 | ||
| 47 | std::unique_ptr<Ui::ConfigureGraphics> ui; | 48 | std::unique_ptr<Ui::ConfigureGraphics> ui; |
| 48 | QColor bg_color; | 49 | QColor bg_color; |
diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui index 099ddbb7c..1a12cfa4d 100644 --- a/src/yuzu/configuration/configure_graphics.ui +++ b/src/yuzu/configuration/configure_graphics.ui | |||
| @@ -156,7 +156,7 @@ | |||
| 156 | <item> | 156 | <item> |
| 157 | <widget class="QCheckBox" name="use_disk_shader_cache"> | 157 | <widget class="QCheckBox" name="use_disk_shader_cache"> |
| 158 | <property name="text"> | 158 | <property name="text"> |
| 159 | <string>Use disk shader cache</string> | 159 | <string>Use disk pipeline cache</string> |
| 160 | </property> | 160 | </property> |
| 161 | </widget> | 161 | </widget> |
| 162 | </item> | 162 | </item> |
| @@ -168,13 +168,6 @@ | |||
| 168 | </widget> | 168 | </widget> |
| 169 | </item> | 169 | </item> |
| 170 | <item> | 170 | <item> |
| 171 | <widget class="QCheckBox" name="use_nvdec_emulation"> | ||
| 172 | <property name="text"> | ||
| 173 | <string>Use NVDEC emulation</string> | ||
| 174 | </property> | ||
| 175 | </widget> | ||
| 176 | </item> | ||
| 177 | <item> | ||
| 178 | <widget class="QCheckBox" name="accelerate_astc"> | 171 | <widget class="QCheckBox" name="accelerate_astc"> |
| 179 | <property name="text"> | 172 | <property name="text"> |
| 180 | <string>Accelerate ASTC texture decoding</string> | 173 | <string>Accelerate ASTC texture decoding</string> |
| @@ -182,6 +175,50 @@ | |||
| 182 | </widget> | 175 | </widget> |
| 183 | </item> | 176 | </item> |
| 184 | <item> | 177 | <item> |
| 178 | <widget class="QWidget" name="nvdec_emulation_widget" native="true"> | ||
| 179 | <layout class="QHBoxLayout" name="nvdec_emulation_layout"> | ||
| 180 | <property name="leftMargin"> | ||
| 181 | <number>0</number> | ||
| 182 | </property> | ||
| 183 | <property name="topMargin"> | ||
| 184 | <number>0</number> | ||
| 185 | </property> | ||
| 186 | <property name="rightMargin"> | ||
| 187 | <number>0</number> | ||
| 188 | </property> | ||
| 189 | <property name="bottomMargin"> | ||
| 190 | <number>0</number> | ||
| 191 | </property> | ||
| 192 | <item> | ||
| 193 | <widget class="QLabel" name="nvdec_emulation_label"> | ||
| 194 | <property name="text"> | ||
| 195 | <string>NVDEC emulation:</string> | ||
| 196 | </property> | ||
| 197 | </widget> | ||
| 198 | </item> | ||
| 199 | <item> | ||
| 200 | <widget class="QComboBox" name="nvdec_emulation"> | ||
| 201 | <item> | ||
| 202 | <property name="text"> | ||
| 203 | <string>Disabled</string> | ||
| 204 | </property> | ||
| 205 | </item> | ||
| 206 | <item> | ||
| 207 | <property name="text"> | ||
| 208 | <string>CPU Decoding</string> | ||
| 209 | </property> | ||
| 210 | </item> | ||
| 211 | <item> | ||
| 212 | <property name="text"> | ||
| 213 | <string>GPU Decoding</string> | ||
| 214 | </property> | ||
| 215 | </item> | ||
| 216 | </widget> | ||
| 217 | </item> | ||
| 218 | </layout> | ||
| 219 | </widget> | ||
| 220 | </item> | ||
| 221 | <item> | ||
| 185 | <widget class="QWidget" name="fullscreen_mode_layout" native="true"> | 222 | <widget class="QWidget" name="fullscreen_mode_layout" native="true"> |
| 186 | <layout class="QHBoxLayout" name="horizontalLayout_1"> | 223 | <layout class="QHBoxLayout" name="horizontalLayout_1"> |
| 187 | <property name="leftMargin"> | 224 | <property name="leftMargin"> |
diff --git a/src/yuzu/configuration/configure_graphics_advanced.ui b/src/yuzu/configuration/configure_graphics_advanced.ui index 5891f8299..b91abc2f0 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.ui +++ b/src/yuzu/configuration/configure_graphics_advanced.ui | |||
| @@ -82,7 +82,7 @@ | |||
| 82 | <string>Enables asynchronous shader compilation, which may reduce shader stutter. This feature is experimental.</string> | 82 | <string>Enables asynchronous shader compilation, which may reduce shader stutter. This feature is experimental.</string> |
| 83 | </property> | 83 | </property> |
| 84 | <property name="text"> | 84 | <property name="text"> |
| 85 | <string>Use asynchronous shader building (hack)</string> | 85 | <string>Use asynchronous shader building (Hack)</string> |
| 86 | </property> | 86 | </property> |
| 87 | </widget> | 87 | </widget> |
| 88 | </item> | 88 | </item> |
| @@ -92,7 +92,7 @@ | |||
| 92 | <string>Enables Fast GPU Time. This option will force most games to run at their highest native resolution.</string> | 92 | <string>Enables Fast GPU Time. This option will force most games to run at their highest native resolution.</string> |
| 93 | </property> | 93 | </property> |
| 94 | <property name="text"> | 94 | <property name="text"> |
| 95 | <string>Use Fast GPU Time (hack)</string> | 95 | <string>Use Fast GPU Time (Hack)</string> |
| 96 | </property> | 96 | </property> |
| 97 | </widget> | 97 | </widget> |
| 98 | </item> | 98 | </item> |
diff --git a/src/yuzu/configuration/configure_input_advanced.cpp b/src/yuzu/configuration/configure_input_advanced.cpp index 2f1419b5b..b30f09013 100644 --- a/src/yuzu/configuration/configure_input_advanced.cpp +++ b/src/yuzu/configuration/configure_input_advanced.cpp | |||
| @@ -88,6 +88,10 @@ ConfigureInputAdvanced::ConfigureInputAdvanced(QWidget* parent) | |||
| 88 | connect(ui->buttonMotionTouch, &QPushButton::clicked, this, | 88 | connect(ui->buttonMotionTouch, &QPushButton::clicked, this, |
| 89 | &ConfigureInputAdvanced::CallMotionTouchConfigDialog); | 89 | &ConfigureInputAdvanced::CallMotionTouchConfigDialog); |
| 90 | 90 | ||
| 91 | #ifndef _WIN32 | ||
| 92 | ui->enable_raw_input->setVisible(false); | ||
| 93 | #endif | ||
| 94 | |||
| 91 | LoadConfiguration(); | 95 | LoadConfiguration(); |
| 92 | } | 96 | } |
| 93 | 97 | ||
| @@ -126,6 +130,7 @@ void ConfigureInputAdvanced::ApplyConfiguration() { | |||
| 126 | Settings::values.mouse_panning_sensitivity = | 130 | Settings::values.mouse_panning_sensitivity = |
| 127 | static_cast<float>(ui->mouse_panning_sensitivity->value()); | 131 | static_cast<float>(ui->mouse_panning_sensitivity->value()); |
| 128 | Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked(); | 132 | Settings::values.touchscreen.enabled = ui->touchscreen_enabled->isChecked(); |
| 133 | Settings::values.enable_raw_input = ui->enable_raw_input->isChecked(); | ||
| 129 | } | 134 | } |
| 130 | 135 | ||
| 131 | void ConfigureInputAdvanced::LoadConfiguration() { | 136 | void ConfigureInputAdvanced::LoadConfiguration() { |
| @@ -155,6 +160,7 @@ void ConfigureInputAdvanced::LoadConfiguration() { | |||
| 155 | ui->mouse_panning->setChecked(Settings::values.mouse_panning.GetValue()); | 160 | ui->mouse_panning->setChecked(Settings::values.mouse_panning.GetValue()); |
| 156 | ui->mouse_panning_sensitivity->setValue(Settings::values.mouse_panning_sensitivity.GetValue()); | 161 | ui->mouse_panning_sensitivity->setValue(Settings::values.mouse_panning_sensitivity.GetValue()); |
| 157 | ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled); | 162 | ui->touchscreen_enabled->setChecked(Settings::values.touchscreen.enabled); |
| 163 | ui->enable_raw_input->setChecked(Settings::values.enable_raw_input.GetValue()); | ||
| 158 | 164 | ||
| 159 | UpdateUIEnabled(); | 165 | UpdateUIEnabled(); |
| 160 | } | 166 | } |
diff --git a/src/yuzu/configuration/configure_input_advanced.ui b/src/yuzu/configuration/configure_input_advanced.ui index d3ef5bd06..9095206a0 100644 --- a/src/yuzu/configuration/configure_input_advanced.ui +++ b/src/yuzu/configuration/configure_input_advanced.ui | |||
| @@ -2672,6 +2672,22 @@ | |||
| 2672 | </property> | 2672 | </property> |
| 2673 | </widget> | 2673 | </widget> |
| 2674 | </item> | 2674 | </item> |
| 2675 | <item row="9" column="0"> | ||
| 2676 | <widget class="QCheckBox" name="enable_raw_input"> | ||
| 2677 | <property name="toolTip"> | ||
| 2678 | <string>Requires restarting yuzu</string> | ||
| 2679 | </property> | ||
| 2680 | <property name="minimumSize"> | ||
| 2681 | <size> | ||
| 2682 | <width>0</width> | ||
| 2683 | <height>23</height> | ||
| 2684 | </size> | ||
| 2685 | </property> | ||
| 2686 | <property name="text"> | ||
| 2687 | <string>Enable XInput 8 player support (disables web applet)</string> | ||
| 2688 | </property> | ||
| 2689 | </widget> | ||
| 2690 | </item> | ||
| 2675 | </layout> | 2691 | </layout> |
| 2676 | </widget> | 2692 | </widget> |
| 2677 | </item> | 2693 | </item> |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 7527c068b..88f4bf388 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -124,6 +124,19 @@ QString ButtonToText(const Common::ParamPackage& param) { | |||
| 124 | return GetKeyName(param.Get("code", 0)); | 124 | return GetKeyName(param.Get("code", 0)); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | if (param.Get("engine", "") == "tas") { | ||
| 128 | if (param.Has("axis")) { | ||
| 129 | const QString axis_str = QString::fromStdString(param.Get("axis", "")); | ||
| 130 | |||
| 131 | return QObject::tr("TAS Axis %1").arg(axis_str); | ||
| 132 | } | ||
| 133 | if (param.Has("button")) { | ||
| 134 | const QString button_str = QString::number(int(std::log2(param.Get("button", 0)))); | ||
| 135 | return QObject::tr("TAS Btn %1").arg(button_str); | ||
| 136 | } | ||
| 137 | return GetKeyName(param.Get("code", 0)); | ||
| 138 | } | ||
| 139 | |||
| 127 | if (param.Get("engine", "") == "cemuhookudp") { | 140 | if (param.Get("engine", "") == "cemuhookudp") { |
| 128 | if (param.Has("pad_index")) { | 141 | if (param.Has("pad_index")) { |
| 129 | const QString motion_str = QString::fromStdString(param.Get("pad_index", "")); | 142 | const QString motion_str = QString::fromStdString(param.Get("pad_index", "")); |
| @@ -187,7 +200,8 @@ QString AnalogToText(const Common::ParamPackage& param, const std::string& dir) | |||
| 187 | const QString axis_y_str = QString::fromStdString(param.Get("axis_y", "")); | 200 | const QString axis_y_str = QString::fromStdString(param.Get("axis_y", "")); |
| 188 | const bool invert_x = param.Get("invert_x", "+") == "-"; | 201 | const bool invert_x = param.Get("invert_x", "+") == "-"; |
| 189 | const bool invert_y = param.Get("invert_y", "+") == "-"; | 202 | const bool invert_y = param.Get("invert_y", "+") == "-"; |
| 190 | if (engine_str == "sdl" || engine_str == "gcpad" || engine_str == "mouse") { | 203 | if (engine_str == "sdl" || engine_str == "gcpad" || engine_str == "mouse" || |
| 204 | engine_str == "tas") { | ||
| 191 | if (dir == "modifier") { | 205 | if (dir == "modifier") { |
| 192 | return QObject::tr("[unused]"); | 206 | return QObject::tr("[unused]"); |
| 193 | } | 207 | } |
| @@ -926,9 +940,9 @@ void ConfigureInputPlayer::UpdateUI() { | |||
| 926 | 940 | ||
| 927 | int slider_value; | 941 | int slider_value; |
| 928 | auto& param = analogs_param[analog_id]; | 942 | auto& param = analogs_param[analog_id]; |
| 929 | const bool is_controller = param.Get("engine", "") == "sdl" || | 943 | const bool is_controller = |
| 930 | param.Get("engine", "") == "gcpad" || | 944 | param.Get("engine", "") == "sdl" || param.Get("engine", "") == "gcpad" || |
| 931 | param.Get("engine", "") == "mouse"; | 945 | param.Get("engine", "") == "mouse" || param.Get("engine", "") == "tas"; |
| 932 | 946 | ||
| 933 | if (is_controller) { | 947 | if (is_controller) { |
| 934 | if (!param.Has("deadzone")) { | 948 | if (!param.Has("deadzone")) { |
| @@ -1045,8 +1059,12 @@ int ConfigureInputPlayer::GetIndexFromControllerType(Settings::ControllerType ty | |||
| 1045 | void ConfigureInputPlayer::UpdateInputDevices() { | 1059 | void ConfigureInputPlayer::UpdateInputDevices() { |
| 1046 | input_devices = input_subsystem->GetInputDevices(); | 1060 | input_devices = input_subsystem->GetInputDevices(); |
| 1047 | ui->comboDevices->clear(); | 1061 | ui->comboDevices->clear(); |
| 1048 | for (auto device : input_devices) { | 1062 | for (auto& device : input_devices) { |
| 1049 | ui->comboDevices->addItem(QString::fromStdString(device.Get("display", "Unknown")), {}); | 1063 | const std::string display = device.Get("display", "Unknown"); |
| 1064 | ui->comboDevices->addItem(QString::fromStdString(display), {}); | ||
| 1065 | if (display == "TAS") { | ||
| 1066 | device.Set("pad", static_cast<u8>(player_index)); | ||
| 1067 | } | ||
| 1050 | } | 1068 | } |
| 1051 | } | 1069 | } |
| 1052 | 1070 | ||
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp index 9c890ed5d..da328d904 100644 --- a/src/yuzu/configuration/configure_input_player_widget.cpp +++ b/src/yuzu/configuration/configure_input_player_widget.cpp | |||
| @@ -175,7 +175,7 @@ void PlayerControlPreview::ResetInputs() { | |||
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | void PlayerControlPreview::UpdateInput() { | 177 | void PlayerControlPreview::UpdateInput() { |
| 178 | if (!is_enabled && !mapping_active) { | 178 | if (!is_enabled && !mapping_active && !Settings::values.tas_enable) { |
| 179 | return; | 179 | return; |
| 180 | } | 180 | } |
| 181 | bool input_changed = false; | 181 | bool input_changed = false; |
| @@ -222,6 +222,19 @@ void PlayerControlPreview::UpdateInput() { | |||
| 222 | 222 | ||
| 223 | if (input_changed) { | 223 | if (input_changed) { |
| 224 | update(); | 224 | update(); |
| 225 | if (controller_callback.input != nullptr) { | ||
| 226 | ControllerInput input{ | ||
| 227 | .axis_values = {std::pair<float, float>{ | ||
| 228 | axis_values[Settings::NativeAnalog::LStick].value.x(), | ||
| 229 | axis_values[Settings::NativeAnalog::LStick].value.y()}, | ||
| 230 | std::pair<float, float>{ | ||
| 231 | axis_values[Settings::NativeAnalog::RStick].value.x(), | ||
| 232 | axis_values[Settings::NativeAnalog::RStick].value.y()}}, | ||
| 233 | .button_values = button_values, | ||
| 234 | .changed = true, | ||
| 235 | }; | ||
| 236 | controller_callback.input(std::move(input)); | ||
| 237 | } | ||
| 225 | } | 238 | } |
| 226 | 239 | ||
| 227 | if (mapping_active) { | 240 | if (mapping_active) { |
| @@ -229,6 +242,10 @@ void PlayerControlPreview::UpdateInput() { | |||
| 229 | } | 242 | } |
| 230 | } | 243 | } |
| 231 | 244 | ||
| 245 | void PlayerControlPreview::SetCallBack(ControllerCallback callback_) { | ||
| 246 | controller_callback = std::move(callback_); | ||
| 247 | } | ||
| 248 | |||
| 232 | void PlayerControlPreview::paintEvent(QPaintEvent* event) { | 249 | void PlayerControlPreview::paintEvent(QPaintEvent* event) { |
| 233 | QFrame::paintEvent(event); | 250 | QFrame::paintEvent(event); |
| 234 | QPainter p(this); | 251 | QPainter p(this); |
diff --git a/src/yuzu/configuration/configure_input_player_widget.h b/src/yuzu/configuration/configure_input_player_widget.h index f4a6a5e1b..f4bbfa528 100644 --- a/src/yuzu/configuration/configure_input_player_widget.h +++ b/src/yuzu/configuration/configure_input_player_widget.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <QPointer> | 9 | #include <QPointer> |
| 10 | #include "common/settings.h" | 10 | #include "common/settings.h" |
| 11 | #include "core/frontend/input.h" | 11 | #include "core/frontend/input.h" |
| 12 | #include "yuzu/debugger/controller.h" | ||
| 12 | 13 | ||
| 13 | class QLabel; | 14 | class QLabel; |
| 14 | 15 | ||
| @@ -33,6 +34,7 @@ public: | |||
| 33 | void BeginMappingAnalog(std::size_t button_id); | 34 | void BeginMappingAnalog(std::size_t button_id); |
| 34 | void EndMapping(); | 35 | void EndMapping(); |
| 35 | void UpdateInput(); | 36 | void UpdateInput(); |
| 37 | void SetCallBack(ControllerCallback callback_); | ||
| 36 | 38 | ||
| 37 | protected: | 39 | protected: |
| 38 | void paintEvent(QPaintEvent* event) override; | 40 | void paintEvent(QPaintEvent* event) override; |
| @@ -181,6 +183,7 @@ private: | |||
| 181 | using StickArray = | 183 | using StickArray = |
| 182 | std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>; | 184 | std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>; |
| 183 | 185 | ||
| 186 | ControllerCallback controller_callback; | ||
| 184 | bool is_enabled{}; | 187 | bool is_enabled{}; |
| 185 | bool mapping_active{}; | 188 | bool mapping_active{}; |
| 186 | int blink_counter{}; | 189 | int blink_counter{}; |
diff --git a/src/yuzu/configuration/configure_network.cpp b/src/yuzu/configuration/configure_network.cpp index ae22f1018..cc15d36c2 100644 --- a/src/yuzu/configuration/configure_network.cpp +++ b/src/yuzu/configuration/configure_network.cpp | |||
| @@ -6,64 +6,25 @@ | |||
| 6 | #include <QtConcurrent/QtConcurrent> | 6 | #include <QtConcurrent/QtConcurrent> |
| 7 | #include "common/settings.h" | 7 | #include "common/settings.h" |
| 8 | #include "core/core.h" | 8 | #include "core/core.h" |
| 9 | #include "core/hle/service/bcat/backend/boxcat.h" | ||
| 10 | #include "core/network/network_interface.h" | 9 | #include "core/network/network_interface.h" |
| 11 | #include "ui_configure_network.h" | 10 | #include "ui_configure_network.h" |
| 12 | #include "yuzu/configuration/configure_network.h" | 11 | #include "yuzu/configuration/configure_network.h" |
| 13 | 12 | ||
| 14 | #ifdef YUZU_ENABLE_BOXCAT | ||
| 15 | namespace { | ||
| 16 | QString FormatEventStatusString(const Service::BCAT::EventStatus& status) { | ||
| 17 | QString out; | ||
| 18 | |||
| 19 | if (status.header.has_value()) { | ||
| 20 | out += QStringLiteral("<i>%1</i><br>").arg(QString::fromStdString(*status.header)); | ||
| 21 | } | ||
| 22 | |||
| 23 | if (status.events.size() == 1) { | ||
| 24 | out += QStringLiteral("%1<br>").arg(QString::fromStdString(status.events.front())); | ||
| 25 | } else { | ||
| 26 | for (const auto& event : status.events) { | ||
| 27 | out += QStringLiteral("- %1<br>").arg(QString::fromStdString(event)); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | if (status.footer.has_value()) { | ||
| 32 | out += QStringLiteral("<i>%1</i><br>").arg(QString::fromStdString(*status.footer)); | ||
| 33 | } | ||
| 34 | |||
| 35 | return out; | ||
| 36 | } | ||
| 37 | } // Anonymous namespace | ||
| 38 | #endif | ||
| 39 | |||
| 40 | ConfigureNetwork::ConfigureNetwork(QWidget* parent) | 13 | ConfigureNetwork::ConfigureNetwork(QWidget* parent) |
| 41 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureNetwork>()) { | 14 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureNetwork>()) { |
| 42 | ui->setupUi(this); | 15 | ui->setupUi(this); |
| 43 | 16 | ||
| 44 | ui->bcat_source->addItem(QStringLiteral("None")); | ||
| 45 | ui->bcat_empty_label->setHidden(true); | ||
| 46 | ui->bcat_empty_header->setHidden(true); | ||
| 47 | |||
| 48 | #ifdef YUZU_ENABLE_BOXCAT | ||
| 49 | ui->bcat_source->addItem(QStringLiteral("Boxcat"), QStringLiteral("boxcat")); | ||
| 50 | #endif | ||
| 51 | |||
| 52 | ui->network_interface->addItem(tr("None")); | 17 | ui->network_interface->addItem(tr("None")); |
| 53 | for (const auto& iface : Network::GetAvailableNetworkInterfaces()) { | 18 | for (const auto& iface : Network::GetAvailableNetworkInterfaces()) { |
| 54 | ui->network_interface->addItem(QString::fromStdString(iface.name)); | 19 | ui->network_interface->addItem(QString::fromStdString(iface.name)); |
| 55 | } | 20 | } |
| 56 | 21 | ||
| 57 | connect(ui->bcat_source, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | ||
| 58 | &ConfigureNetwork::OnBCATImplChanged); | ||
| 59 | |||
| 60 | this->SetConfiguration(); | 22 | this->SetConfiguration(); |
| 61 | } | 23 | } |
| 62 | 24 | ||
| 63 | ConfigureNetwork::~ConfigureNetwork() = default; | 25 | ConfigureNetwork::~ConfigureNetwork() = default; |
| 64 | 26 | ||
| 65 | void ConfigureNetwork::ApplyConfiguration() { | 27 | void ConfigureNetwork::ApplyConfiguration() { |
| 66 | Settings::values.bcat_backend = ui->bcat_source->currentText().toLower().toStdString(); | ||
| 67 | Settings::values.network_interface = ui->network_interface->currentText().toStdString(); | 28 | Settings::values.network_interface = ui->network_interface->currentText().toStdString(); |
| 68 | } | 29 | } |
| 69 | 30 | ||
| @@ -74,86 +35,8 @@ void ConfigureNetwork::RetranslateUi() { | |||
| 74 | void ConfigureNetwork::SetConfiguration() { | 35 | void ConfigureNetwork::SetConfiguration() { |
| 75 | const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); | 36 | const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); |
| 76 | 37 | ||
| 77 | const int index = | ||
| 78 | ui->bcat_source->findData(QString::fromStdString(Settings::values.bcat_backend.GetValue())); | ||
| 79 | ui->bcat_source->setCurrentIndex(index == -1 ? 0 : index); | ||
| 80 | |||
| 81 | const std::string& network_interface = Settings::values.network_interface.GetValue(); | 38 | const std::string& network_interface = Settings::values.network_interface.GetValue(); |
| 82 | 39 | ||
| 83 | ui->network_interface->setCurrentText(QString::fromStdString(network_interface)); | 40 | ui->network_interface->setCurrentText(QString::fromStdString(network_interface)); |
| 84 | ui->network_interface->setEnabled(runtime_lock); | 41 | ui->network_interface->setEnabled(runtime_lock); |
| 85 | } | 42 | } |
| 86 | |||
| 87 | std::pair<QString, QString> ConfigureNetwork::BCATDownloadEvents() { | ||
| 88 | #ifdef YUZU_ENABLE_BOXCAT | ||
| 89 | std::optional<std::string> global; | ||
| 90 | std::map<std::string, Service::BCAT::EventStatus> map; | ||
| 91 | const auto res = Service::BCAT::Boxcat::GetStatus(global, map); | ||
| 92 | |||
| 93 | switch (res) { | ||
| 94 | case Service::BCAT::Boxcat::StatusResult::Success: | ||
| 95 | break; | ||
| 96 | case Service::BCAT::Boxcat::StatusResult::Offline: | ||
| 97 | return {QString{}, | ||
| 98 | tr("The boxcat service is offline or you are not connected to the internet.")}; | ||
| 99 | case Service::BCAT::Boxcat::StatusResult::ParseError: | ||
| 100 | return {QString{}, | ||
| 101 | tr("There was an error while processing the boxcat event data. Contact the yuzu " | ||
| 102 | "developers.")}; | ||
| 103 | case Service::BCAT::Boxcat::StatusResult::BadClientVersion: | ||
| 104 | return {QString{}, | ||
| 105 | tr("The version of yuzu you are using is either too new or too old for the server. " | ||
| 106 | "Try updating to the latest official release of yuzu.")}; | ||
| 107 | } | ||
| 108 | |||
| 109 | if (map.empty()) { | ||
| 110 | return {QStringLiteral("Current Boxcat Events"), | ||
| 111 | tr("There are currently no events on boxcat.")}; | ||
| 112 | } | ||
| 113 | |||
| 114 | QString out; | ||
| 115 | |||
| 116 | if (global.has_value()) { | ||
| 117 | out += QStringLiteral("%1<br>").arg(QString::fromStdString(*global)); | ||
| 118 | } | ||
| 119 | |||
| 120 | for (const auto& [key, value] : map) { | ||
| 121 | out += QStringLiteral("%1<b>%2</b><br>%3") | ||
| 122 | .arg(out.isEmpty() ? QString{} : QStringLiteral("<br>")) | ||
| 123 | .arg(QString::fromStdString(key)) | ||
| 124 | .arg(FormatEventStatusString(value)); | ||
| 125 | } | ||
| 126 | return {tr("Current Boxcat Events"), std::move(out)}; | ||
| 127 | #else | ||
| 128 | return {tr("Current Boxcat Events"), tr("There are currently no events on boxcat.")}; | ||
| 129 | #endif | ||
| 130 | } | ||
| 131 | |||
| 132 | void ConfigureNetwork::OnBCATImplChanged() { | ||
| 133 | #ifdef YUZU_ENABLE_BOXCAT | ||
| 134 | const auto boxcat = ui->bcat_source->currentText() == QStringLiteral("Boxcat"); | ||
| 135 | ui->bcat_empty_header->setHidden(!boxcat); | ||
| 136 | ui->bcat_empty_label->setHidden(!boxcat); | ||
| 137 | ui->bcat_empty_header->setText(QString{}); | ||
| 138 | ui->bcat_empty_label->setText(tr("Yuzu is retrieving the latest boxcat status...")); | ||
| 139 | |||
| 140 | if (!boxcat) | ||
| 141 | return; | ||
| 142 | |||
| 143 | const auto future = QtConcurrent::run([this] { return BCATDownloadEvents(); }); | ||
| 144 | |||
| 145 | watcher.setFuture(future); | ||
| 146 | connect(&watcher, &QFutureWatcher<std::pair<QString, QString>>::finished, this, | ||
| 147 | [this] { OnUpdateBCATEmptyLabel(watcher.result()); }); | ||
| 148 | #endif | ||
| 149 | } | ||
| 150 | |||
| 151 | void ConfigureNetwork::OnUpdateBCATEmptyLabel(std::pair<QString, QString> string) { | ||
| 152 | #ifdef YUZU_ENABLE_BOXCAT | ||
| 153 | const auto boxcat = ui->bcat_source->currentText() == QStringLiteral("Boxcat"); | ||
| 154 | if (boxcat) { | ||
| 155 | ui->bcat_empty_header->setText(string.first); | ||
| 156 | ui->bcat_empty_label->setText(string.second); | ||
| 157 | } | ||
| 158 | #endif | ||
| 159 | } | ||
diff --git a/src/yuzu/configuration/configure_network.h b/src/yuzu/configuration/configure_network.h index 442b68e6b..028fd4acc 100644 --- a/src/yuzu/configuration/configure_network.h +++ b/src/yuzu/configuration/configure_network.h | |||
| @@ -25,10 +25,5 @@ public: | |||
| 25 | private: | 25 | private: |
| 26 | void SetConfiguration(); | 26 | void SetConfiguration(); |
| 27 | 27 | ||
| 28 | std::pair<QString, QString> BCATDownloadEvents(); | ||
| 29 | void OnBCATImplChanged(); | ||
| 30 | void OnUpdateBCATEmptyLabel(std::pair<QString, QString> string); | ||
| 31 | |||
| 32 | std::unique_ptr<Ui::ConfigureNetwork> ui; | 28 | std::unique_ptr<Ui::ConfigureNetwork> ui; |
| 33 | QFutureWatcher<std::pair<QString, QString>> watcher{this}; | ||
| 34 | }; | 29 | }; |
diff --git a/src/yuzu/configuration/configure_network.ui b/src/yuzu/configuration/configure_network.ui index 5f9b7e97b..9a79262f0 100644 --- a/src/yuzu/configuration/configure_network.ui +++ b/src/yuzu/configuration/configure_network.ui | |||
| @@ -35,92 +35,6 @@ | |||
| 35 | </layout> | 35 | </layout> |
| 36 | </widget> | 36 | </widget> |
| 37 | </item> | 37 | </item> |
| 38 | <item> | ||
| 39 | <widget class="QGroupBox" name="groupBox"> | ||
| 40 | <property name="title"> | ||
| 41 | <string>BCAT</string> | ||
| 42 | </property> | ||
| 43 | <layout class="QGridLayout" name="gridLayout"> | ||
| 44 | <item row="3" column="0"> | ||
| 45 | <widget class="QLabel" name="bcat_empty_header"> | ||
| 46 | <property name="text"> | ||
| 47 | <string/> | ||
| 48 | </property> | ||
| 49 | <property name="alignment"> | ||
| 50 | <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> | ||
| 51 | </property> | ||
| 52 | <property name="wordWrap"> | ||
| 53 | <bool>true</bool> | ||
| 54 | </property> | ||
| 55 | </widget> | ||
| 56 | </item> | ||
| 57 | <item row="0" column="0"> | ||
| 58 | <widget class="QLabel" name="label"> | ||
| 59 | <property name="maximumSize"> | ||
| 60 | <size> | ||
| 61 | <width>16777215</width> | ||
| 62 | <height>16777215</height> | ||
| 63 | </size> | ||
| 64 | </property> | ||
| 65 | <property name="text"> | ||
| 66 | <string>BCAT Backend</string> | ||
| 67 | </property> | ||
| 68 | </widget> | ||
| 69 | </item> | ||
| 70 | <item row="1" column="1" colspan="2"> | ||
| 71 | <widget class="QLabel" name="label_2"> | ||
| 72 | <property name="maximumSize"> | ||
| 73 | <size> | ||
| 74 | <width>260</width> | ||
| 75 | <height>16777215</height> | ||
| 76 | </size> | ||
| 77 | </property> | ||
| 78 | <property name="text"> | ||
| 79 | <string>BCAT is Nintendo's way of sending data to games to engage its community and unlock additional content.</string> | ||
| 80 | </property> | ||
| 81 | <property name="wordWrap"> | ||
| 82 | <bool>true</bool> | ||
| 83 | </property> | ||
| 84 | </widget> | ||
| 85 | </item> | ||
| 86 | <item row="2" column="1" colspan="2"> | ||
| 87 | <widget class="QLabel" name="label_3"> | ||
| 88 | <property name="text"> | ||
| 89 | <string><html><head/><body><p><a href="https://yuzu-emu.org/help/feature/boxcat"><span style=" text-decoration: underline; color:#0000ff;">Learn more about BCAT, Boxcat, and Current Events</span></a></p></body></html></string> | ||
| 90 | </property> | ||
| 91 | <property name="openExternalLinks"> | ||
| 92 | <bool>true</bool> | ||
| 93 | </property> | ||
| 94 | </widget> | ||
| 95 | </item> | ||
| 96 | <item row="0" column="1" colspan="2"> | ||
| 97 | <widget class="QComboBox" name="bcat_source"/> | ||
| 98 | </item> | ||
| 99 | <item row="3" column="1" colspan="2"> | ||
| 100 | <widget class="QLabel" name="bcat_empty_label"> | ||
| 101 | <property name="enabled"> | ||
| 102 | <bool>true</bool> | ||
| 103 | </property> | ||
| 104 | <property name="maximumSize"> | ||
| 105 | <size> | ||
| 106 | <width>260</width> | ||
| 107 | <height>16777215</height> | ||
| 108 | </size> | ||
| 109 | </property> | ||
| 110 | <property name="text"> | ||
| 111 | <string/> | ||
| 112 | </property> | ||
| 113 | <property name="alignment"> | ||
| 114 | <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> | ||
| 115 | </property> | ||
| 116 | <property name="wordWrap"> | ||
| 117 | <bool>true</bool> | ||
| 118 | </property> | ||
| 119 | </widget> | ||
| 120 | </item> | ||
| 121 | </layout> | ||
| 122 | </widget> | ||
| 123 | </item> | ||
| 124 | </layout> | 38 | </layout> |
| 125 | </item> | 39 | </item> |
| 126 | <item> | 40 | <item> |
diff --git a/src/yuzu/configuration/configure_profile_manager.cpp b/src/yuzu/configuration/configure_profile_manager.cpp index ac849b01d..136614bf8 100644 --- a/src/yuzu/configuration/configure_profile_manager.cpp +++ b/src/yuzu/configuration/configure_profile_manager.cpp | |||
| @@ -76,7 +76,7 @@ QString GetProfileUsernameFromUser(QWidget* parent, const QString& description_t | |||
| 76 | } | 76 | } |
| 77 | } // Anonymous namespace | 77 | } // Anonymous namespace |
| 78 | 78 | ||
| 79 | ConfigureProfileManager ::ConfigureProfileManager(QWidget* parent) | 79 | ConfigureProfileManager::ConfigureProfileManager(QWidget* parent) |
| 80 | : QWidget(parent), ui(new Ui::ConfigureProfileManager), | 80 | : QWidget(parent), ui(new Ui::ConfigureProfileManager), |
| 81 | profile_manager(std::make_unique<Service::Account::ProfileManager>()) { | 81 | profile_manager(std::make_unique<Service::Account::ProfileManager>()) { |
| 82 | ui->setupUi(this); | 82 | ui->setupUi(this); |
diff --git a/src/yuzu/configuration/configure_tas.cpp b/src/yuzu/configuration/configure_tas.cpp new file mode 100644 index 000000000..b666b175a --- /dev/null +++ b/src/yuzu/configuration/configure_tas.cpp | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QFileDialog> | ||
| 6 | #include <QMessageBox> | ||
| 7 | #include "common/fs/fs.h" | ||
| 8 | #include "common/fs/path_util.h" | ||
| 9 | #include "common/settings.h" | ||
| 10 | #include "ui_configure_tas.h" | ||
| 11 | #include "yuzu/configuration/configure_tas.h" | ||
| 12 | #include "yuzu/uisettings.h" | ||
| 13 | |||
| 14 | ConfigureTasDialog::ConfigureTasDialog(QWidget* parent) | ||
| 15 | : QDialog(parent), ui(std::make_unique<Ui::ConfigureTas>()) { | ||
| 16 | |||
| 17 | ui->setupUi(this); | ||
| 18 | |||
| 19 | setFocusPolicy(Qt::ClickFocus); | ||
| 20 | setWindowTitle(tr("TAS Configuration")); | ||
| 21 | |||
| 22 | connect(ui->tas_path_button, &QToolButton::pressed, this, | ||
| 23 | [this] { SetDirectory(DirectoryTarget::TAS, ui->tas_path_edit); }); | ||
| 24 | |||
| 25 | LoadConfiguration(); | ||
| 26 | } | ||
| 27 | |||
| 28 | ConfigureTasDialog::~ConfigureTasDialog() = default; | ||
| 29 | |||
| 30 | void ConfigureTasDialog::LoadConfiguration() { | ||
| 31 | ui->tas_path_edit->setText( | ||
| 32 | QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::TASDir))); | ||
| 33 | ui->tas_enable->setChecked(Settings::values.tas_enable.GetValue()); | ||
| 34 | ui->tas_control_swap->setChecked(Settings::values.tas_swap_controllers.GetValue()); | ||
| 35 | ui->tas_loop_script->setChecked(Settings::values.tas_loop.GetValue()); | ||
| 36 | ui->tas_pause_on_load->setChecked(Settings::values.pause_tas_on_load.GetValue()); | ||
| 37 | } | ||
| 38 | |||
| 39 | void ConfigureTasDialog::ApplyConfiguration() { | ||
| 40 | Common::FS::SetYuzuPath(Common::FS::YuzuPath::TASDir, ui->tas_path_edit->text().toStdString()); | ||
| 41 | Settings::values.tas_enable.SetValue(ui->tas_enable->isChecked()); | ||
| 42 | Settings::values.tas_swap_controllers.SetValue(ui->tas_control_swap->isChecked()); | ||
| 43 | Settings::values.tas_loop.SetValue(ui->tas_loop_script->isChecked()); | ||
| 44 | Settings::values.pause_tas_on_load.SetValue(ui->tas_pause_on_load->isChecked()); | ||
| 45 | } | ||
| 46 | |||
| 47 | void ConfigureTasDialog::SetDirectory(DirectoryTarget target, QLineEdit* edit) { | ||
| 48 | QString caption; | ||
| 49 | |||
| 50 | switch (target) { | ||
| 51 | case DirectoryTarget::TAS: | ||
| 52 | caption = tr("Select TAS Load Directory..."); | ||
| 53 | break; | ||
| 54 | } | ||
| 55 | |||
| 56 | QString str = QFileDialog::getExistingDirectory(this, caption, edit->text()); | ||
| 57 | |||
| 58 | if (str.isEmpty()) { | ||
| 59 | return; | ||
| 60 | } | ||
| 61 | |||
| 62 | if (str.back() != QChar::fromLatin1('/')) { | ||
| 63 | str.append(QChar::fromLatin1('/')); | ||
| 64 | } | ||
| 65 | |||
| 66 | edit->setText(str); | ||
| 67 | } | ||
| 68 | |||
| 69 | void ConfigureTasDialog::changeEvent(QEvent* event) { | ||
| 70 | if (event->type() == QEvent::LanguageChange) { | ||
| 71 | RetranslateUI(); | ||
| 72 | } | ||
| 73 | |||
| 74 | QDialog::changeEvent(event); | ||
| 75 | } | ||
| 76 | |||
| 77 | void ConfigureTasDialog::RetranslateUI() { | ||
| 78 | ui->retranslateUi(this); | ||
| 79 | } | ||
| 80 | |||
| 81 | void ConfigureTasDialog::HandleApplyButtonClicked() { | ||
| 82 | UISettings::values.configuration_applied = true; | ||
| 83 | ApplyConfiguration(); | ||
| 84 | } | ||
diff --git a/src/yuzu/configuration/configure_tas.h b/src/yuzu/configuration/configure_tas.h new file mode 100644 index 000000000..1546bf16f --- /dev/null +++ b/src/yuzu/configuration/configure_tas.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <QDialog> | ||
| 8 | |||
| 9 | namespace Ui { | ||
| 10 | class ConfigureTas; | ||
| 11 | } | ||
| 12 | |||
| 13 | class ConfigureTasDialog : public QDialog { | ||
| 14 | Q_OBJECT | ||
| 15 | |||
| 16 | public: | ||
| 17 | explicit ConfigureTasDialog(QWidget* parent); | ||
| 18 | ~ConfigureTasDialog() override; | ||
| 19 | |||
| 20 | /// Save all button configurations to settings file | ||
| 21 | void ApplyConfiguration(); | ||
| 22 | |||
| 23 | private: | ||
| 24 | enum class DirectoryTarget { | ||
| 25 | TAS, | ||
| 26 | }; | ||
| 27 | |||
| 28 | void LoadConfiguration(); | ||
| 29 | |||
| 30 | void SetDirectory(DirectoryTarget target, QLineEdit* edit); | ||
| 31 | |||
| 32 | void changeEvent(QEvent* event) override; | ||
| 33 | void RetranslateUI(); | ||
| 34 | |||
| 35 | void HandleApplyButtonClicked(); | ||
| 36 | |||
| 37 | std::unique_ptr<Ui::ConfigureTas> ui; | ||
| 38 | }; | ||
diff --git a/src/yuzu/configuration/configure_tas.ui b/src/yuzu/configuration/configure_tas.ui new file mode 100644 index 000000000..95575ed9d --- /dev/null +++ b/src/yuzu/configuration/configure_tas.ui | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <ui version="4.0"> | ||
| 3 | <class>ConfigureTas</class> | ||
| 4 | <widget class="QDialog" name="ConfigureTas"> | ||
| 5 | <layout class="QVBoxLayout" name="verticalLayout_1"> | ||
| 6 | <item> | ||
| 7 | <layout class="QHBoxLayout" name="horizontalLayout_1"> | ||
| 8 | <item> | ||
| 9 | <widget class="QGroupBox" name="groupBox_1"> | ||
| 10 | <property name="title"> | ||
| 11 | <string>TAS</string> | ||
| 12 | </property> | ||
| 13 | <layout class="QGridLayout" name="gridLayout_1"> | ||
| 14 | <item row="0" column="0" colspan="4"> | ||
| 15 | <widget class="QLabel" name="label_1"> | ||
| 16 | <property name="text"> | ||
| 17 | <string>Reads controller input from scripts in the same format as TAS-nx scripts.<br/>For a more detailed explanation please consult the FAQ on the yuzu website.</string> | ||
| 18 | </property> | ||
| 19 | </widget> | ||
| 20 | </item> | ||
| 21 | <item row="1" column="0" colspan="4"> | ||
| 22 | <widget class="QLabel" name="label_2"> | ||
| 23 | <property name="text"> | ||
| 24 | <string>To check which hotkeys control the playback/recording, please refer to the Hotkey settings (General -> Hotkeys).</string> | ||
| 25 | </property> | ||
| 26 | <property name="wordWrap"> | ||
| 27 | <bool>true</bool> | ||
| 28 | </property> | ||
| 29 | </widget> | ||
| 30 | </item> | ||
| 31 | <item row="2" column="0" colspan="4"> | ||
| 32 | <widget class="QLabel" name="label_3"> | ||
| 33 | <property name="text"> | ||
| 34 | <string>WARNING: This is an experimental feature.<br/>It will not play back scripts frame perfectly with the current, imperfect syncing method.</string> | ||
| 35 | </property> | ||
| 36 | <property name="wordWrap"> | ||
| 37 | <bool>true</bool> | ||
| 38 | </property> | ||
| 39 | </widget> | ||
| 40 | </item> | ||
| 41 | </layout> | ||
| 42 | </widget> | ||
| 43 | </item> | ||
| 44 | </layout> | ||
| 45 | </item> | ||
| 46 | <item> | ||
| 47 | <layout class="QHBoxLayout" name="horizontalLayout_2"> | ||
| 48 | <item> | ||
| 49 | <widget class="QGroupBox" name="groupBox_2"> | ||
| 50 | <property name="title"> | ||
| 51 | <string>Settings</string> | ||
| 52 | </property> | ||
| 53 | <layout class="QGridLayout" name="gridLayout_2"> | ||
| 54 | <item row="0" column="0" colspan="4"> | ||
| 55 | <widget class="QCheckBox" name="tas_enable"> | ||
| 56 | <property name="text"> | ||
| 57 | <string>Enable TAS features</string> | ||
| 58 | </property> | ||
| 59 | </widget> | ||
| 60 | </item> | ||
| 61 | <item row="1" column="0" colspan="4"> | ||
| 62 | <widget class="QCheckBox" name="tas_control_swap"> | ||
| 63 | <property name="text"> | ||
| 64 | <string>Automatic controller profile swapping</string> | ||
| 65 | </property> | ||
| 66 | </widget> | ||
| 67 | </item> | ||
| 68 | <item row="2" column="0" colspan="4"> | ||
| 69 | <widget class="QCheckBox" name="tas_loop_script"> | ||
| 70 | <property name="text"> | ||
| 71 | <string>Loop script</string> | ||
| 72 | </property> | ||
| 73 | </widget> | ||
| 74 | </item> | ||
| 75 | <item row="3" column="0" colspan="4"> | ||
| 76 | <widget class="QCheckBox" name="tas_pause_on_load"> | ||
| 77 | <property name="enabled"> | ||
| 78 | <bool>false</bool> | ||
| 79 | </property> | ||
| 80 | <property name="text"> | ||
| 81 | <string>Pause execution during loads</string> | ||
| 82 | </property> | ||
| 83 | </widget> | ||
| 84 | </item> | ||
| 85 | </layout> | ||
| 86 | </widget> | ||
| 87 | </item> | ||
| 88 | </layout> | ||
| 89 | </item> | ||
| 90 | <item> | ||
| 91 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | ||
| 92 | <item> | ||
| 93 | <widget class="QGroupBox" name="groupBox_3"> | ||
| 94 | <property name="title"> | ||
| 95 | <string>Script Directory</string> | ||
| 96 | </property> | ||
| 97 | <layout class="QGridLayout" name="gridLayout_3"> | ||
| 98 | <item row="0" column="0"> | ||
| 99 | <widget class="QLabel" name="label_4"> | ||
| 100 | <property name="text"> | ||
| 101 | <string>Path</string> | ||
| 102 | </property> | ||
| 103 | </widget> | ||
| 104 | </item> | ||
| 105 | <item row="0" column="3"> | ||
| 106 | <widget class="QToolButton" name="tas_path_button"> | ||
| 107 | <property name="text"> | ||
| 108 | <string>...</string> | ||
| 109 | </property> | ||
| 110 | </widget> | ||
| 111 | </item> | ||
| 112 | <item row="0" column="2"> | ||
| 113 | <widget class="QLineEdit" name="tas_path_edit"/> | ||
| 114 | </item> | ||
| 115 | </layout> | ||
| 116 | </widget> | ||
| 117 | </item> | ||
| 118 | </layout> | ||
| 119 | </item> | ||
| 120 | <item> | ||
| 121 | <widget class="QDialogButtonBox" name="buttonBox"> | ||
| 122 | <property name="sizePolicy"> | ||
| 123 | <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> | ||
| 124 | <horstretch>0</horstretch> | ||
| 125 | <verstretch>0</verstretch> | ||
| 126 | </sizepolicy> | ||
| 127 | </property> | ||
| 128 | <property name="orientation"> | ||
| 129 | <enum>Qt::Horizontal</enum> | ||
| 130 | </property> | ||
| 131 | <property name="standardButtons"> | ||
| 132 | <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
| 133 | </property> | ||
| 134 | </widget> | ||
| 135 | </item> | ||
| 136 | </layout> | ||
| 137 | </widget> | ||
| 138 | <resources/> | ||
| 139 | <connections> | ||
| 140 | <connection> | ||
| 141 | <sender>buttonBox</sender> | ||
| 142 | <signal>accepted()</signal> | ||
| 143 | <receiver>ConfigureTas</receiver> | ||
| 144 | <slot>accept()</slot> | ||
| 145 | </connection> | ||
| 146 | <connection> | ||
| 147 | <sender>buttonBox</sender> | ||
| 148 | <signal>rejected()</signal> | ||
| 149 | <receiver>ConfigureTas</receiver> | ||
| 150 | <slot>reject()</slot> | ||
| 151 | </connection> | ||
| 152 | </connections> | ||
| 153 | </ui> | ||
diff --git a/src/yuzu/configuration/configure_vibration.cpp b/src/yuzu/configuration/configure_vibration.cpp index 9d92c4949..46a0f3025 100644 --- a/src/yuzu/configuration/configure_vibration.cpp +++ b/src/yuzu/configuration/configure_vibration.cpp | |||
| @@ -99,7 +99,7 @@ void ConfigureVibration::SetVibrationDevices(std::size_t player_index) { | |||
| 99 | const auto guid = param.Get("guid", ""); | 99 | const auto guid = param.Get("guid", ""); |
| 100 | const auto port = param.Get("port", ""); | 100 | const auto port = param.Get("port", ""); |
| 101 | 101 | ||
| 102 | if (engine.empty() || engine == "keyboard" || engine == "mouse") { | 102 | if (engine.empty() || engine == "keyboard" || engine == "mouse" || engine == "tas") { |
| 103 | continue; | 103 | continue; |
| 104 | } | 104 | } |
| 105 | 105 | ||
diff --git a/src/yuzu/debugger/controller.cpp b/src/yuzu/debugger/controller.cpp index c1fc69578..5a844409b 100644 --- a/src/yuzu/debugger/controller.cpp +++ b/src/yuzu/debugger/controller.cpp | |||
| @@ -6,10 +6,13 @@ | |||
| 6 | #include <QLayout> | 6 | #include <QLayout> |
| 7 | #include <QString> | 7 | #include <QString> |
| 8 | #include "common/settings.h" | 8 | #include "common/settings.h" |
| 9 | #include "input_common/main.h" | ||
| 10 | #include "input_common/tas/tas_input.h" | ||
| 9 | #include "yuzu/configuration/configure_input_player_widget.h" | 11 | #include "yuzu/configuration/configure_input_player_widget.h" |
| 10 | #include "yuzu/debugger/controller.h" | 12 | #include "yuzu/debugger/controller.h" |
| 11 | 13 | ||
| 12 | ControllerDialog::ControllerDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) { | 14 | ControllerDialog::ControllerDialog(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_) |
| 15 | : QWidget(parent, Qt::Dialog), input_subsystem{input_subsystem_} { | ||
| 13 | setObjectName(QStringLiteral("Controller")); | 16 | setObjectName(QStringLiteral("Controller")); |
| 14 | setWindowTitle(tr("Controller P1")); | 17 | setWindowTitle(tr("Controller P1")); |
| 15 | resize(500, 350); | 18 | resize(500, 350); |
| @@ -38,6 +41,9 @@ void ControllerDialog::refreshConfiguration() { | |||
| 38 | constexpr std::size_t player = 0; | 41 | constexpr std::size_t player = 0; |
| 39 | widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs); | 42 | widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs); |
| 40 | widget->SetControllerType(players[player].controller_type); | 43 | widget->SetControllerType(players[player].controller_type); |
| 44 | ControllerCallback callback{[this](ControllerInput input) { InputController(input); }}; | ||
| 45 | widget->SetCallBack(callback); | ||
| 46 | widget->repaint(); | ||
| 41 | widget->SetConnectedStatus(players[player].connected); | 47 | widget->SetConnectedStatus(players[player].connected); |
| 42 | } | 48 | } |
| 43 | 49 | ||
| @@ -67,3 +73,13 @@ void ControllerDialog::hideEvent(QHideEvent* ev) { | |||
| 67 | widget->SetConnectedStatus(false); | 73 | widget->SetConnectedStatus(false); |
| 68 | QWidget::hideEvent(ev); | 74 | QWidget::hideEvent(ev); |
| 69 | } | 75 | } |
| 76 | |||
| 77 | void ControllerDialog::InputController(ControllerInput input) { | ||
| 78 | u32 buttons = 0; | ||
| 79 | int index = 0; | ||
| 80 | for (bool btn : input.button_values) { | ||
| 81 | buttons |= (btn ? 1U : 0U) << index; | ||
| 82 | index++; | ||
| 83 | } | ||
| 84 | input_subsystem->GetTas()->RecordInput(buttons, input.axis_values); | ||
| 85 | } | ||
diff --git a/src/yuzu/debugger/controller.h b/src/yuzu/debugger/controller.h index c54750070..7742db58b 100644 --- a/src/yuzu/debugger/controller.h +++ b/src/yuzu/debugger/controller.h | |||
| @@ -4,18 +4,35 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <QFileSystemWatcher> | ||
| 7 | #include <QWidget> | 8 | #include <QWidget> |
| 9 | #include "common/settings.h" | ||
| 8 | 10 | ||
| 9 | class QAction; | 11 | class QAction; |
| 10 | class QHideEvent; | 12 | class QHideEvent; |
| 11 | class QShowEvent; | 13 | class QShowEvent; |
| 12 | class PlayerControlPreview; | 14 | class PlayerControlPreview; |
| 13 | 15 | ||
| 16 | namespace InputCommon { | ||
| 17 | class InputSubsystem; | ||
| 18 | } | ||
| 19 | |||
| 20 | struct ControllerInput { | ||
| 21 | std::array<std::pair<float, float>, Settings::NativeAnalog::NUM_STICKS_HID> axis_values{}; | ||
| 22 | std::array<bool, Settings::NativeButton::NumButtons> button_values{}; | ||
| 23 | bool changed{}; | ||
| 24 | }; | ||
| 25 | |||
| 26 | struct ControllerCallback { | ||
| 27 | std::function<void(ControllerInput)> input; | ||
| 28 | }; | ||
| 29 | |||
| 14 | class ControllerDialog : public QWidget { | 30 | class ControllerDialog : public QWidget { |
| 15 | Q_OBJECT | 31 | Q_OBJECT |
| 16 | 32 | ||
| 17 | public: | 33 | public: |
| 18 | explicit ControllerDialog(QWidget* parent = nullptr); | 34 | explicit ControllerDialog(QWidget* parent = nullptr, |
| 35 | InputCommon::InputSubsystem* input_subsystem_ = nullptr); | ||
| 19 | 36 | ||
| 20 | /// Returns a QAction that can be used to toggle visibility of this dialog. | 37 | /// Returns a QAction that can be used to toggle visibility of this dialog. |
| 21 | QAction* toggleViewAction(); | 38 | QAction* toggleViewAction(); |
| @@ -26,6 +43,9 @@ protected: | |||
| 26 | void hideEvent(QHideEvent* ev) override; | 43 | void hideEvent(QHideEvent* ev) override; |
| 27 | 44 | ||
| 28 | private: | 45 | private: |
| 46 | void InputController(ControllerInput input); | ||
| 29 | QAction* toggle_view_action = nullptr; | 47 | QAction* toggle_view_action = nullptr; |
| 48 | QFileSystemWatcher* watcher = nullptr; | ||
| 30 | PlayerControlPreview* widget; | 49 | PlayerControlPreview* widget; |
| 50 | InputCommon::InputSubsystem* input_subsystem; | ||
| 31 | }; | 51 | }; |
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index e97804220..f9d949e75 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -515,16 +515,16 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri | |||
| 515 | QAction* open_save_location = context_menu.addAction(tr("Open Save Data Location")); | 515 | QAction* open_save_location = context_menu.addAction(tr("Open Save Data Location")); |
| 516 | QAction* open_mod_location = context_menu.addAction(tr("Open Mod Data Location")); | 516 | QAction* open_mod_location = context_menu.addAction(tr("Open Mod Data Location")); |
| 517 | QAction* open_transferable_shader_cache = | 517 | QAction* open_transferable_shader_cache = |
| 518 | context_menu.addAction(tr("Open Transferable Shader Cache")); | 518 | context_menu.addAction(tr("Open Transferable Pipeline Cache")); |
| 519 | context_menu.addSeparator(); | 519 | context_menu.addSeparator(); |
| 520 | QMenu* remove_menu = context_menu.addMenu(tr("Remove")); | 520 | QMenu* remove_menu = context_menu.addMenu(tr("Remove")); |
| 521 | QAction* remove_update = remove_menu->addAction(tr("Remove Installed Update")); | 521 | QAction* remove_update = remove_menu->addAction(tr("Remove Installed Update")); |
| 522 | QAction* remove_dlc = remove_menu->addAction(tr("Remove All Installed DLC")); | 522 | QAction* remove_dlc = remove_menu->addAction(tr("Remove All Installed DLC")); |
| 523 | QAction* remove_custom_config = remove_menu->addAction(tr("Remove Custom Configuration")); | 523 | QAction* remove_custom_config = remove_menu->addAction(tr("Remove Custom Configuration")); |
| 524 | QAction* remove_gl_shader_cache = remove_menu->addAction(tr("Remove OpenGL Shader Cache")); | 524 | QAction* remove_gl_shader_cache = remove_menu->addAction(tr("Remove OpenGL Pipeline Cache")); |
| 525 | QAction* remove_vk_shader_cache = remove_menu->addAction(tr("Remove Vulkan Shader Cache")); | 525 | QAction* remove_vk_shader_cache = remove_menu->addAction(tr("Remove Vulkan Pipeline Cache")); |
| 526 | remove_menu->addSeparator(); | 526 | remove_menu->addSeparator(); |
| 527 | QAction* remove_shader_cache = remove_menu->addAction(tr("Remove All Shader Caches")); | 527 | QAction* remove_shader_cache = remove_menu->addAction(tr("Remove All Pipeline Caches")); |
| 528 | QAction* remove_all_content = remove_menu->addAction(tr("Remove All Installed Contents")); | 528 | QAction* remove_all_content = remove_menu->addAction(tr("Remove All Installed Contents")); |
| 529 | QMenu* dump_romfs_menu = context_menu.addMenu(tr("Dump RomFS")); | 529 | QMenu* dump_romfs_menu = context_menu.addMenu(tr("Dump RomFS")); |
| 530 | QAction* dump_romfs = dump_romfs_menu->addAction(tr("Dump RomFS")); | 530 | QAction* dump_romfs = dump_romfs_menu->addAction(tr("Dump RomFS")); |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index e36774cc6..0bd0c5b04 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | #include "common/nvidia_flags.h" | 19 | #include "common/nvidia_flags.h" |
| 20 | #include "configuration/configure_input.h" | 20 | #include "configuration/configure_input.h" |
| 21 | #include "configuration/configure_per_game.h" | 21 | #include "configuration/configure_per_game.h" |
| 22 | #include "configuration/configure_tas.h" | ||
| 22 | #include "configuration/configure_vibration.h" | 23 | #include "configuration/configure_vibration.h" |
| 23 | #include "core/file_sys/vfs.h" | 24 | #include "core/file_sys/vfs.h" |
| 24 | #include "core/file_sys/vfs_real.h" | 25 | #include "core/file_sys/vfs_real.h" |
| @@ -102,6 +103,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual | |||
| 102 | #include "core/perf_stats.h" | 103 | #include "core/perf_stats.h" |
| 103 | #include "core/telemetry_session.h" | 104 | #include "core/telemetry_session.h" |
| 104 | #include "input_common/main.h" | 105 | #include "input_common/main.h" |
| 106 | #include "input_common/tas/tas_input.h" | ||
| 105 | #include "util/overlay_dialog.h" | 107 | #include "util/overlay_dialog.h" |
| 106 | #include "video_core/gpu.h" | 108 | #include "video_core/gpu.h" |
| 107 | #include "video_core/renderer_base.h" | 109 | #include "video_core/renderer_base.h" |
| @@ -557,7 +559,8 @@ void GMainWindow::WebBrowserOpenWebPage(const std::string& main_url, | |||
| 557 | const std::string& additional_args, bool is_local) { | 559 | const std::string& additional_args, bool is_local) { |
| 558 | #ifdef YUZU_USE_QT_WEB_ENGINE | 560 | #ifdef YUZU_USE_QT_WEB_ENGINE |
| 559 | 561 | ||
| 560 | if (disable_web_applet) { | 562 | // Raw input breaks with the web applet, Disable web applets if enabled |
| 563 | if (disable_web_applet || Settings::values.enable_raw_input) { | ||
| 561 | emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed, | 564 | emit WebBrowserClosed(Service::AM::Applets::WebExitReason::WindowClosed, |
| 562 | "http://localhost/"); | 565 | "http://localhost/"); |
| 563 | return; | 566 | return; |
| @@ -746,6 +749,11 @@ void GMainWindow::InitializeWidgets() { | |||
| 746 | statusBar()->addPermanentWidget(label); | 749 | statusBar()->addPermanentWidget(label); |
| 747 | } | 750 | } |
| 748 | 751 | ||
| 752 | tas_label = new QLabel(); | ||
| 753 | tas_label->setObjectName(QStringLiteral("TASlabel")); | ||
| 754 | tas_label->setFocusPolicy(Qt::NoFocus); | ||
| 755 | statusBar()->insertPermanentWidget(0, tas_label); | ||
| 756 | |||
| 749 | // Setup Dock button | 757 | // Setup Dock button |
| 750 | dock_status_button = new QPushButton(); | 758 | dock_status_button = new QPushButton(); |
| 751 | dock_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton")); | 759 | dock_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton")); |
| @@ -840,7 +848,7 @@ void GMainWindow::InitializeDebugWidgets() { | |||
| 840 | waitTreeWidget->hide(); | 848 | waitTreeWidget->hide(); |
| 841 | debug_menu->addAction(waitTreeWidget->toggleViewAction()); | 849 | debug_menu->addAction(waitTreeWidget->toggleViewAction()); |
| 842 | 850 | ||
| 843 | controller_dialog = new ControllerDialog(this); | 851 | controller_dialog = new ControllerDialog(this, input_subsystem.get()); |
| 844 | controller_dialog->hide(); | 852 | controller_dialog->hide(); |
| 845 | debug_menu->addAction(controller_dialog->toggleViewAction()); | 853 | debug_menu->addAction(controller_dialog->toggleViewAction()); |
| 846 | 854 | ||
| @@ -1013,6 +1021,28 @@ void GMainWindow::InitializeHotkeys() { | |||
| 1013 | render_window->setAttribute(Qt::WA_Hover, true); | 1021 | render_window->setAttribute(Qt::WA_Hover, true); |
| 1014 | } | 1022 | } |
| 1015 | }); | 1023 | }); |
| 1024 | connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("TAS Start/Stop"), this), | ||
| 1025 | &QShortcut::activated, this, [&] { | ||
| 1026 | if (!emulation_running) { | ||
| 1027 | return; | ||
| 1028 | } | ||
| 1029 | input_subsystem->GetTas()->StartStop(); | ||
| 1030 | }); | ||
| 1031 | connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("TAS Reset"), this), | ||
| 1032 | &QShortcut::activated, this, [&] { input_subsystem->GetTas()->Reset(); }); | ||
| 1033 | connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("TAS Record"), this), | ||
| 1034 | &QShortcut::activated, this, [&] { | ||
| 1035 | if (!emulation_running) { | ||
| 1036 | return; | ||
| 1037 | } | ||
| 1038 | bool is_recording = input_subsystem->GetTas()->Record(); | ||
| 1039 | if (!is_recording) { | ||
| 1040 | const auto res = QMessageBox::question(this, tr("TAS Recording"), | ||
| 1041 | tr("Overwrite file of player 1?"), | ||
| 1042 | QMessageBox::Yes | QMessageBox::No); | ||
| 1043 | input_subsystem->GetTas()->SaveRecording(res == QMessageBox::Yes); | ||
| 1044 | } | ||
| 1045 | }); | ||
| 1016 | } | 1046 | } |
| 1017 | 1047 | ||
| 1018 | void GMainWindow::SetDefaultUIGeometry() { | 1048 | void GMainWindow::SetDefaultUIGeometry() { |
| @@ -1131,6 +1161,7 @@ void GMainWindow::ConnectMenuEvents() { | |||
| 1131 | connect(ui.action_Open_FAQ, &QAction::triggered, this, &GMainWindow::OnOpenFAQ); | 1161 | connect(ui.action_Open_FAQ, &QAction::triggered, this, &GMainWindow::OnOpenFAQ); |
| 1132 | connect(ui.action_Restart, &QAction::triggered, this, [this] { BootGame(QString(game_path)); }); | 1162 | connect(ui.action_Restart, &QAction::triggered, this, [this] { BootGame(QString(game_path)); }); |
| 1133 | connect(ui.action_Configure, &QAction::triggered, this, &GMainWindow::OnConfigure); | 1163 | connect(ui.action_Configure, &QAction::triggered, this, &GMainWindow::OnConfigure); |
| 1164 | connect(ui.action_Configure_Tas, &QAction::triggered, this, &GMainWindow::OnConfigureTas); | ||
| 1134 | connect(ui.action_Configure_Current_Game, &QAction::triggered, this, | 1165 | connect(ui.action_Configure_Current_Game, &QAction::triggered, this, |
| 1135 | &GMainWindow::OnConfigurePerGame); | 1166 | &GMainWindow::OnConfigurePerGame); |
| 1136 | 1167 | ||
| @@ -1353,6 +1384,9 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t | |||
| 1353 | system.RegisterExecuteProgramCallback( | 1384 | system.RegisterExecuteProgramCallback( |
| 1354 | [this](std::size_t program_index) { render_window->ExecuteProgram(program_index); }); | 1385 | [this](std::size_t program_index) { render_window->ExecuteProgram(program_index); }); |
| 1355 | 1386 | ||
| 1387 | // Register an Exit callback such that Core can exit the currently running application. | ||
| 1388 | system.RegisterExitCallback([this]() { render_window->Exit(); }); | ||
| 1389 | |||
| 1356 | connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); | 1390 | connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); |
| 1357 | connect(render_window, &GRenderWindow::MouseActivity, this, &GMainWindow::OnMouseActivity); | 1391 | connect(render_window, &GRenderWindow::MouseActivity, this, &GMainWindow::OnMouseActivity); |
| 1358 | // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views | 1392 | // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views |
| @@ -1463,6 +1497,8 @@ void GMainWindow::ShutdownGame() { | |||
| 1463 | game_list->show(); | 1497 | game_list->show(); |
| 1464 | } | 1498 | } |
| 1465 | game_list->SetFilterFocus(); | 1499 | game_list->SetFilterFocus(); |
| 1500 | tas_label->clear(); | ||
| 1501 | input_subsystem->GetTas()->Stop(); | ||
| 1466 | 1502 | ||
| 1467 | render_window->removeEventFilter(render_window); | 1503 | render_window->removeEventFilter(render_window); |
| 1468 | render_window->setAttribute(Qt::WA_Hover, false); | 1504 | render_window->setAttribute(Qt::WA_Hover, false); |
| @@ -2436,6 +2472,10 @@ void GMainWindow::OnExecuteProgram(std::size_t program_index) { | |||
| 2436 | BootGame(last_filename_booted, 0, program_index); | 2472 | BootGame(last_filename_booted, 0, program_index); |
| 2437 | } | 2473 | } |
| 2438 | 2474 | ||
| 2475 | void GMainWindow::OnExit() { | ||
| 2476 | OnStopGame(); | ||
| 2477 | } | ||
| 2478 | |||
| 2439 | void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) { | 2479 | void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) { |
| 2440 | OverlayDialog dialog(render_window, Core::System::GetInstance(), error_code, error_text, | 2480 | OverlayDialog dialog(render_window, Core::System::GetInstance(), error_code, error_text, |
| 2441 | QString{}, tr("OK"), Qt::AlignLeft | Qt::AlignVCenter); | 2481 | QString{}, tr("OK"), Qt::AlignLeft | Qt::AlignVCenter); |
| @@ -2697,6 +2737,19 @@ void GMainWindow::OnConfigure() { | |||
| 2697 | UpdateStatusButtons(); | 2737 | UpdateStatusButtons(); |
| 2698 | } | 2738 | } |
| 2699 | 2739 | ||
| 2740 | void GMainWindow::OnConfigureTas() { | ||
| 2741 | const auto& system = Core::System::GetInstance(); | ||
| 2742 | ConfigureTasDialog dialog(this); | ||
| 2743 | const auto result = dialog.exec(); | ||
| 2744 | |||
| 2745 | if (result != QDialog::Accepted && !UISettings::values.configuration_applied) { | ||
| 2746 | Settings::RestoreGlobalState(system.IsPoweredOn()); | ||
| 2747 | return; | ||
| 2748 | } else if (result == QDialog::Accepted) { | ||
| 2749 | dialog.ApplyConfiguration(); | ||
| 2750 | } | ||
| 2751 | } | ||
| 2752 | |||
| 2700 | void GMainWindow::OnConfigurePerGame() { | 2753 | void GMainWindow::OnConfigurePerGame() { |
| 2701 | const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); | 2754 | const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); |
| 2702 | OpenPerGameConfiguration(title_id, game_path.toStdString()); | 2755 | OpenPerGameConfiguration(title_id, game_path.toStdString()); |
| @@ -2873,12 +2926,32 @@ void GMainWindow::UpdateWindowTitle(std::string_view title_name, std::string_vie | |||
| 2873 | } | 2926 | } |
| 2874 | } | 2927 | } |
| 2875 | 2928 | ||
| 2929 | QString GMainWindow::GetTasStateDescription() const { | ||
| 2930 | auto [tas_status, current_tas_frame, total_tas_frames] = input_subsystem->GetTas()->GetStatus(); | ||
| 2931 | switch (tas_status) { | ||
| 2932 | case TasInput::TasState::Running: | ||
| 2933 | return tr("TAS state: Running %1/%2").arg(current_tas_frame).arg(total_tas_frames); | ||
| 2934 | case TasInput::TasState::Recording: | ||
| 2935 | return tr("TAS state: Recording %1").arg(total_tas_frames); | ||
| 2936 | case TasInput::TasState::Stopped: | ||
| 2937 | return tr("TAS state: Idle %1/%2").arg(current_tas_frame).arg(total_tas_frames); | ||
| 2938 | default: | ||
| 2939 | return tr("TAS State: Invalid"); | ||
| 2940 | } | ||
| 2941 | } | ||
| 2942 | |||
| 2876 | void GMainWindow::UpdateStatusBar() { | 2943 | void GMainWindow::UpdateStatusBar() { |
| 2877 | if (emu_thread == nullptr) { | 2944 | if (emu_thread == nullptr) { |
| 2878 | status_bar_update_timer.stop(); | 2945 | status_bar_update_timer.stop(); |
| 2879 | return; | 2946 | return; |
| 2880 | } | 2947 | } |
| 2881 | 2948 | ||
| 2949 | if (Settings::values.tas_enable) { | ||
| 2950 | tas_label->setText(GetTasStateDescription()); | ||
| 2951 | } else { | ||
| 2952 | tas_label->clear(); | ||
| 2953 | } | ||
| 2954 | |||
| 2882 | auto& system = Core::System::GetInstance(); | 2955 | auto& system = Core::System::GetInstance(); |
| 2883 | auto results = system.GetAndResetPerfStats(); | 2956 | auto results = system.GetAndResetPerfStats(); |
| 2884 | auto& shader_notify = system.GPU().ShaderNotify(); | 2957 | auto& shader_notify = system.GPU().ShaderNotify(); |
| @@ -3174,12 +3247,11 @@ std::optional<u64> GMainWindow::SelectRomFSDumpTarget(const FileSys::ContentProv | |||
| 3174 | } | 3247 | } |
| 3175 | 3248 | ||
| 3176 | bool GMainWindow::ConfirmClose() { | 3249 | bool GMainWindow::ConfirmClose() { |
| 3177 | if (emu_thread == nullptr || !UISettings::values.confirm_before_closing) | 3250 | if (emu_thread == nullptr || !UISettings::values.confirm_before_closing) { |
| 3178 | return true; | 3251 | return true; |
| 3179 | 3252 | } | |
| 3180 | QMessageBox::StandardButton answer = | 3253 | const auto text = tr("Are you sure you want to close yuzu?"); |
| 3181 | QMessageBox::question(this, tr("yuzu"), tr("Are you sure you want to close yuzu?"), | 3254 | const auto answer = QMessageBox::question(this, tr("yuzu"), text); |
| 3182 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No); | ||
| 3183 | return answer != QMessageBox::No; | 3255 | return answer != QMessageBox::No; |
| 3184 | } | 3256 | } |
| 3185 | 3257 | ||
| @@ -3261,14 +3333,13 @@ bool GMainWindow::ConfirmChangeGame() { | |||
| 3261 | } | 3333 | } |
| 3262 | 3334 | ||
| 3263 | bool GMainWindow::ConfirmForceLockedExit() { | 3335 | bool GMainWindow::ConfirmForceLockedExit() { |
| 3264 | if (emu_thread == nullptr) | 3336 | if (emu_thread == nullptr || !UISettings::values.confirm_before_closing) { |
| 3265 | return true; | 3337 | return true; |
| 3338 | } | ||
| 3339 | const auto text = tr("The currently running application has requested yuzu to not exit.\n\n" | ||
| 3340 | "Would you like to bypass this and exit anyway?"); | ||
| 3266 | 3341 | ||
| 3267 | const auto answer = | 3342 | const auto answer = QMessageBox::question(this, tr("yuzu"), text); |
| 3268 | QMessageBox::question(this, tr("yuzu"), | ||
| 3269 | tr("The currently running application has requested yuzu to not " | ||
| 3270 | "exit.\n\nWould you like to bypass this and exit anyway?"), | ||
| 3271 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No); | ||
| 3272 | return answer != QMessageBox::No; | 3343 | return answer != QMessageBox::No; |
| 3273 | } | 3344 | } |
| 3274 | 3345 | ||
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 38e66ccd0..60ce01471 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -153,6 +153,7 @@ signals: | |||
| 153 | public slots: | 153 | public slots: |
| 154 | void OnLoadComplete(); | 154 | void OnLoadComplete(); |
| 155 | void OnExecuteProgram(std::size_t program_index); | 155 | void OnExecuteProgram(std::size_t program_index); |
| 156 | void OnExit(); | ||
| 156 | void ControllerSelectorReconfigureControllers( | 157 | void ControllerSelectorReconfigureControllers( |
| 157 | const Core::Frontend::ControllerParameters& parameters); | 158 | const Core::Frontend::ControllerParameters& parameters); |
| 158 | void SoftwareKeyboardInitialize( | 159 | void SoftwareKeyboardInitialize( |
| @@ -259,6 +260,7 @@ private slots: | |||
| 259 | void OnMenuInstallToNAND(); | 260 | void OnMenuInstallToNAND(); |
| 260 | void OnMenuRecentFile(); | 261 | void OnMenuRecentFile(); |
| 261 | void OnConfigure(); | 262 | void OnConfigure(); |
| 263 | void OnConfigureTas(); | ||
| 262 | void OnConfigurePerGame(); | 264 | void OnConfigurePerGame(); |
| 263 | void OnLoadAmiibo(); | 265 | void OnLoadAmiibo(); |
| 264 | void OnOpenYuzuFolder(); | 266 | void OnOpenYuzuFolder(); |
| @@ -300,6 +302,7 @@ private: | |||
| 300 | void OpenURL(const QUrl& url); | 302 | void OpenURL(const QUrl& url); |
| 301 | void LoadTranslation(); | 303 | void LoadTranslation(); |
| 302 | void OpenPerGameConfiguration(u64 title_id, const std::string& file_name); | 304 | void OpenPerGameConfiguration(u64 title_id, const std::string& file_name); |
| 305 | QString GetTasStateDescription() const; | ||
| 303 | 306 | ||
| 304 | Ui::MainWindow ui; | 307 | Ui::MainWindow ui; |
| 305 | 308 | ||
| @@ -318,6 +321,7 @@ private: | |||
| 318 | QLabel* emu_speed_label = nullptr; | 321 | QLabel* emu_speed_label = nullptr; |
| 319 | QLabel* game_fps_label = nullptr; | 322 | QLabel* game_fps_label = nullptr; |
| 320 | QLabel* emu_frametime_label = nullptr; | 323 | QLabel* emu_frametime_label = nullptr; |
| 324 | QLabel* tas_label = nullptr; | ||
| 321 | QPushButton* gpu_accuracy_button = nullptr; | 325 | QPushButton* gpu_accuracy_button = nullptr; |
| 322 | QPushButton* renderer_status_button = nullptr; | 326 | QPushButton* renderer_status_button = nullptr; |
| 323 | QPushButton* dock_status_button = nullptr; | 327 | QPushButton* dock_status_button = nullptr; |
diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index 048870687..653c010d8 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui | |||
| @@ -100,6 +100,7 @@ | |||
| 100 | <addaction name="action_Rederive"/> | 100 | <addaction name="action_Rederive"/> |
| 101 | <addaction name="separator"/> | 101 | <addaction name="separator"/> |
| 102 | <addaction name="action_Capture_Screenshot"/> | 102 | <addaction name="action_Capture_Screenshot"/> |
| 103 | <addaction name="action_Configure_Tas"/> | ||
| 103 | </widget> | 104 | </widget> |
| 104 | <widget class="QMenu" name="menu_Help"> | 105 | <widget class="QMenu" name="menu_Help"> |
| 105 | <property name="title"> | 106 | <property name="title"> |
| @@ -294,6 +295,11 @@ | |||
| 294 | <string>&Capture Screenshot</string> | 295 | <string>&Capture Screenshot</string> |
| 295 | </property> | 296 | </property> |
| 296 | </action> | 297 | </action> |
| 298 | <action name="action_Configure_Tas"> | ||
| 299 | <property name="text"> | ||
| 300 | <string>Configure &TAS...</string> | ||
| 301 | </property> | ||
| 302 | </action> | ||
| 297 | <action name="action_Configure_Current_Game"> | 303 | <action name="action_Configure_Current_Game"> |
| 298 | <property name="enabled"> | 304 | <property name="enabled"> |
| 299 | <bool>false</bool> | 305 | <bool>false</bool> |
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 757dd1ea0..434518d53 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp | |||
| @@ -465,7 +465,7 @@ void Config::ReadValues() { | |||
| 465 | ReadSetting("Renderer", Settings::values.disable_fps_limit); | 465 | ReadSetting("Renderer", Settings::values.disable_fps_limit); |
| 466 | ReadSetting("Renderer", Settings::values.shader_backend); | 466 | ReadSetting("Renderer", Settings::values.shader_backend); |
| 467 | ReadSetting("Renderer", Settings::values.use_asynchronous_shaders); | 467 | ReadSetting("Renderer", Settings::values.use_asynchronous_shaders); |
| 468 | ReadSetting("Renderer", Settings::values.use_nvdec_emulation); | 468 | ReadSetting("Renderer", Settings::values.nvdec_emulation); |
| 469 | ReadSetting("Renderer", Settings::values.accelerate_astc); | 469 | ReadSetting("Renderer", Settings::values.accelerate_astc); |
| 470 | ReadSetting("Renderer", Settings::values.use_fast_gpu_time); | 470 | ReadSetting("Renderer", Settings::values.use_fast_gpu_time); |
| 471 | 471 | ||
| @@ -475,7 +475,6 @@ void Config::ReadValues() { | |||
| 475 | 475 | ||
| 476 | // Audio | 476 | // Audio |
| 477 | ReadSetting("Audio", Settings::values.sink_id); | 477 | ReadSetting("Audio", Settings::values.sink_id); |
| 478 | ReadSetting("Audio", Settings::values.enable_audio_stretching); | ||
| 479 | ReadSetting("Audio", Settings::values.audio_device_id); | 478 | ReadSetting("Audio", Settings::values.audio_device_id); |
| 480 | ReadSetting("Audio", Settings::values.volume); | 479 | ReadSetting("Audio", Settings::values.volume); |
| 481 | 480 | ||
| @@ -519,10 +518,6 @@ void Config::ReadValues() { | |||
| 519 | ReadSetting("WebService", Settings::values.web_api_url); | 518 | ReadSetting("WebService", Settings::values.web_api_url); |
| 520 | ReadSetting("WebService", Settings::values.yuzu_username); | 519 | ReadSetting("WebService", Settings::values.yuzu_username); |
| 521 | ReadSetting("WebService", Settings::values.yuzu_token); | 520 | ReadSetting("WebService", Settings::values.yuzu_token); |
| 522 | |||
| 523 | // Services | ||
| 524 | ReadSetting("Services", Settings::values.bcat_backend); | ||
| 525 | ReadSetting("Services", Settings::values.bcat_boxcat_local); | ||
| 526 | } | 521 | } |
| 527 | 522 | ||
| 528 | void Config::Reload() { | 523 | void Config::Reload() { |
diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index e02eceb99..8119a50d8 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h | |||
| @@ -261,9 +261,9 @@ shader_backend = | |||
| 261 | # 0 (default): Off, 1: On | 261 | # 0 (default): Off, 1: On |
| 262 | use_asynchronous_shaders = | 262 | use_asynchronous_shaders = |
| 263 | 263 | ||
| 264 | # Enable NVDEC emulation. | 264 | # NVDEC emulation. |
| 265 | # 0: Off, 1 (default): On | 265 | # 0: Disabled, 1: CPU Decoding, 2 (default): GPU Decoding |
| 266 | use_nvdec_emulation = | 266 | nvdec_emulation = |
| 267 | 267 | ||
| 268 | # Accelerate ASTC texture decoding. | 268 | # Accelerate ASTC texture decoding. |
| 269 | # 0: Off, 1 (default): On | 269 | # 0: Off, 1 (default): On |
| @@ -428,11 +428,6 @@ web_api_url = https://api.yuzu-emu.org | |||
| 428 | yuzu_username = | 428 | yuzu_username = |
| 429 | yuzu_token = | 429 | yuzu_token = |
| 430 | 430 | ||
| 431 | [Services] | ||
| 432 | # The name of the backend to use for BCAT | ||
| 433 | # If this is set to 'boxcat' boxcat will be used, otherwise a null implementation will be used | ||
| 434 | bcat_backend = | ||
| 435 | |||
| 436 | [AddOns] | 431 | [AddOns] |
| 437 | # Used to disable add-ons | 432 | # Used to disable add-ons |
| 438 | # List of title IDs of games that will have add-ons disabled (separated by '|'): | 433 | # List of title IDs of games that will have add-ons disabled (separated by '|'): |