diff options
Diffstat (limited to 'src')
175 files changed, 5100 insertions, 3781 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1e977e8a8..71efbb40d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt | |||
| @@ -62,6 +62,12 @@ else() | |||
| 62 | -Wno-unused-parameter | 62 | -Wno-unused-parameter |
| 63 | ) | 63 | ) |
| 64 | 64 | ||
| 65 | # TODO: Remove when we update to a GCC compiler that enables this | ||
| 66 | # by default (i.e. GCC 10 or newer). | ||
| 67 | if (CMAKE_CXX_COMPILER_ID STREQUAL GNU) | ||
| 68 | add_compile_options(-fconcepts) | ||
| 69 | endif() | ||
| 70 | |||
| 65 | if (ARCHITECTURE_x86_64) | 71 | if (ARCHITECTURE_x86_64) |
| 66 | add_compile_options("-mcx16") | 72 | add_compile_options("-mcx16") |
| 67 | endif() | 73 | endif() |
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index f80ab92e4..7be5d5087 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp | |||
| @@ -36,9 +36,10 @@ Stream::Stream(Core::Timing::CoreTiming& core_timing, u32 sample_rate, Format fo | |||
| 36 | ReleaseCallback&& release_callback, SinkStream& sink_stream, std::string&& name_) | 36 | ReleaseCallback&& release_callback, SinkStream& sink_stream, std::string&& name_) |
| 37 | : sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)}, | 37 | : sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)}, |
| 38 | sink_stream{sink_stream}, core_timing{core_timing}, name{std::move(name_)} { | 38 | sink_stream{sink_stream}, core_timing{core_timing}, name{std::move(name_)} { |
| 39 | 39 | release_event = | |
| 40 | release_event = Core::Timing::CreateEvent( | 40 | Core::Timing::CreateEvent(name, [this](std::uintptr_t, std::chrono::nanoseconds ns_late) { |
| 41 | name, [this](u64, std::chrono::nanoseconds ns_late) { ReleaseActiveBuffer(ns_late); }); | 41 | ReleaseActiveBuffer(ns_late); |
| 42 | }); | ||
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | void Stream::Play() { | 45 | void Stream::Play() { |
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d120c8d3d..78c3bfb3b 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -110,6 +110,7 @@ add_library(common STATIC | |||
| 110 | common_funcs.h | 110 | common_funcs.h |
| 111 | common_paths.h | 111 | common_paths.h |
| 112 | common_types.h | 112 | common_types.h |
| 113 | concepts.h | ||
| 113 | dynamic_library.cpp | 114 | dynamic_library.cpp |
| 114 | dynamic_library.h | 115 | dynamic_library.h |
| 115 | fiber.cpp | 116 | fiber.cpp |
diff --git a/src/common/atomic_ops.cpp b/src/common/atomic_ops.cpp index 1098e21ff..1612d0e67 100644 --- a/src/common/atomic_ops.cpp +++ b/src/common/atomic_ops.cpp | |||
| @@ -14,50 +14,55 @@ namespace Common { | |||
| 14 | 14 | ||
| 15 | #if _MSC_VER | 15 | #if _MSC_VER |
| 16 | 16 | ||
| 17 | bool AtomicCompareAndSwap(u8 volatile* pointer, u8 value, u8 expected) { | 17 | bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected) { |
| 18 | u8 result = _InterlockedCompareExchange8((char*)pointer, value, expected); | 18 | const u8 result = |
| 19 | _InterlockedCompareExchange8(reinterpret_cast<volatile char*>(pointer), value, expected); | ||
| 19 | return result == expected; | 20 | return result == expected; |
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | bool AtomicCompareAndSwap(u16 volatile* pointer, u16 value, u16 expected) { | 23 | bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected) { |
| 23 | u16 result = _InterlockedCompareExchange16((short*)pointer, value, expected); | 24 | const u16 result = |
| 25 | _InterlockedCompareExchange16(reinterpret_cast<volatile short*>(pointer), value, expected); | ||
| 24 | return result == expected; | 26 | return result == expected; |
| 25 | } | 27 | } |
| 26 | 28 | ||
| 27 | bool AtomicCompareAndSwap(u32 volatile* pointer, u32 value, u32 expected) { | 29 | bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected) { |
| 28 | u32 result = _InterlockedCompareExchange((long*)pointer, value, expected); | 30 | const u32 result = |
| 31 | _InterlockedCompareExchange(reinterpret_cast<volatile long*>(pointer), value, expected); | ||
| 29 | return result == expected; | 32 | return result == expected; |
| 30 | } | 33 | } |
| 31 | 34 | ||
| 32 | bool AtomicCompareAndSwap(u64 volatile* pointer, u64 value, u64 expected) { | 35 | bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected) { |
| 33 | u64 result = _InterlockedCompareExchange64((__int64*)pointer, value, expected); | 36 | const u64 result = _InterlockedCompareExchange64(reinterpret_cast<volatile __int64*>(pointer), |
| 37 | value, expected); | ||
| 34 | return result == expected; | 38 | return result == expected; |
| 35 | } | 39 | } |
| 36 | 40 | ||
| 37 | bool AtomicCompareAndSwap(u64 volatile* pointer, u128 value, u128 expected) { | 41 | bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected) { |
| 38 | return _InterlockedCompareExchange128((__int64*)pointer, value[1], value[0], | 42 | return _InterlockedCompareExchange128(reinterpret_cast<volatile __int64*>(pointer), value[1], |
| 39 | (__int64*)expected.data()) != 0; | 43 | value[0], |
| 44 | reinterpret_cast<__int64*>(expected.data())) != 0; | ||
| 40 | } | 45 | } |
| 41 | 46 | ||
| 42 | #else | 47 | #else |
| 43 | 48 | ||
| 44 | bool AtomicCompareAndSwap(u8 volatile* pointer, u8 value, u8 expected) { | 49 | bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected) { |
| 45 | return __sync_bool_compare_and_swap(pointer, expected, value); | 50 | return __sync_bool_compare_and_swap(pointer, expected, value); |
| 46 | } | 51 | } |
| 47 | 52 | ||
| 48 | bool AtomicCompareAndSwap(u16 volatile* pointer, u16 value, u16 expected) { | 53 | bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected) { |
| 49 | return __sync_bool_compare_and_swap(pointer, expected, value); | 54 | return __sync_bool_compare_and_swap(pointer, expected, value); |
| 50 | } | 55 | } |
| 51 | 56 | ||
| 52 | bool AtomicCompareAndSwap(u32 volatile* pointer, u32 value, u32 expected) { | 57 | bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected) { |
| 53 | return __sync_bool_compare_and_swap(pointer, expected, value); | 58 | return __sync_bool_compare_and_swap(pointer, expected, value); |
| 54 | } | 59 | } |
| 55 | 60 | ||
| 56 | bool AtomicCompareAndSwap(u64 volatile* pointer, u64 value, u64 expected) { | 61 | bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected) { |
| 57 | return __sync_bool_compare_and_swap(pointer, expected, value); | 62 | return __sync_bool_compare_and_swap(pointer, expected, value); |
| 58 | } | 63 | } |
| 59 | 64 | ||
| 60 | bool AtomicCompareAndSwap(u64 volatile* pointer, u128 value, u128 expected) { | 65 | bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected) { |
| 61 | unsigned __int128 value_a; | 66 | unsigned __int128 value_a; |
| 62 | unsigned __int128 expected_a; | 67 | unsigned __int128 expected_a; |
| 63 | std::memcpy(&value_a, value.data(), sizeof(u128)); | 68 | std::memcpy(&value_a, value.data(), sizeof(u128)); |
diff --git a/src/common/atomic_ops.h b/src/common/atomic_ops.h index e6181d521..8d6b73c00 100644 --- a/src/common/atomic_ops.h +++ b/src/common/atomic_ops.h | |||
| @@ -8,10 +8,10 @@ | |||
| 8 | 8 | ||
| 9 | namespace Common { | 9 | namespace Common { |
| 10 | 10 | ||
| 11 | bool AtomicCompareAndSwap(u8 volatile* pointer, u8 value, u8 expected); | 11 | bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected); |
| 12 | bool AtomicCompareAndSwap(u16 volatile* pointer, u16 value, u16 expected); | 12 | bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected); |
| 13 | bool AtomicCompareAndSwap(u32 volatile* pointer, u32 value, u32 expected); | 13 | bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected); |
| 14 | bool AtomicCompareAndSwap(u64 volatile* pointer, u64 value, u64 expected); | 14 | bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected); |
| 15 | bool AtomicCompareAndSwap(u64 volatile* pointer, u128 value, u128 expected); | 15 | bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected); |
| 16 | 16 | ||
| 17 | } // namespace Common | 17 | } // namespace Common |
diff --git a/src/common/common_paths.h b/src/common/common_paths.h index 076752d3b..3c593d5f6 100644 --- a/src/common/common_paths.h +++ b/src/common/common_paths.h | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | #define KEYS_DIR "keys" | 35 | #define KEYS_DIR "keys" |
| 36 | #define LOAD_DIR "load" | 36 | #define LOAD_DIR "load" |
| 37 | #define DUMP_DIR "dump" | 37 | #define DUMP_DIR "dump" |
| 38 | #define SCREENSHOTS_DIR "screenshots" | ||
| 38 | #define SHADER_DIR "shader" | 39 | #define SHADER_DIR "shader" |
| 39 | #define LOG_DIR "log" | 40 | #define LOG_DIR "log" |
| 40 | 41 | ||
diff --git a/src/common/concepts.h b/src/common/concepts.h new file mode 100644 index 000000000..54252e778 --- /dev/null +++ b/src/common/concepts.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | // Copyright 2020 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 | namespace Common { | ||
| 8 | |||
| 9 | #include <type_traits> | ||
| 10 | |||
| 11 | // Check if type is like an STL container | ||
| 12 | template <typename T> | ||
| 13 | concept IsSTLContainer = requires(T t) { | ||
| 14 | typename T::value_type; | ||
| 15 | typename T::iterator; | ||
| 16 | typename T::const_iterator; | ||
| 17 | // TODO(ogniK): Replace below is std::same_as<void> when MSVC supports it. | ||
| 18 | t.begin(); | ||
| 19 | t.end(); | ||
| 20 | t.cbegin(); | ||
| 21 | t.cend(); | ||
| 22 | t.data(); | ||
| 23 | t.size(); | ||
| 24 | }; | ||
| 25 | |||
| 26 | // TODO: Replace with std::derived_from when the <concepts> header | ||
| 27 | // is available on all supported platforms. | ||
| 28 | template <typename Derived, typename Base> | ||
| 29 | concept DerivedFrom = requires { | ||
| 30 | std::is_base_of_v<Base, Derived>; | ||
| 31 | std::is_convertible_v<const volatile Derived*, const volatile Base*>; | ||
| 32 | }; | ||
| 33 | |||
| 34 | } // namespace Common | ||
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 45b750e1e..4ede9f72c 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -695,6 +695,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) { | |||
| 695 | paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP); | 695 | paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP); |
| 696 | paths.emplace(UserPath::LoadDir, user_path + LOAD_DIR DIR_SEP); | 696 | paths.emplace(UserPath::LoadDir, user_path + LOAD_DIR DIR_SEP); |
| 697 | paths.emplace(UserPath::DumpDir, user_path + DUMP_DIR DIR_SEP); | 697 | paths.emplace(UserPath::DumpDir, user_path + DUMP_DIR DIR_SEP); |
| 698 | paths.emplace(UserPath::ScreenshotsDir, user_path + SCREENSHOTS_DIR DIR_SEP); | ||
| 698 | paths.emplace(UserPath::ShaderDir, user_path + SHADER_DIR DIR_SEP); | 699 | paths.emplace(UserPath::ShaderDir, user_path + SHADER_DIR DIR_SEP); |
| 699 | paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP); | 700 | paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP); |
| 700 | paths.emplace(UserPath::KeysDir, user_path + KEYS_DIR DIR_SEP); | 701 | paths.emplace(UserPath::KeysDir, user_path + KEYS_DIR DIR_SEP); |
diff --git a/src/common/file_util.h b/src/common/file_util.h index f7a0c33fa..187b93161 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -32,6 +32,7 @@ enum class UserPath { | |||
| 32 | SDMCDir, | 32 | SDMCDir, |
| 33 | LoadDir, | 33 | LoadDir, |
| 34 | DumpDir, | 34 | DumpDir, |
| 35 | ScreenshotsDir, | ||
| 35 | ShaderDir, | 36 | ShaderDir, |
| 36 | SysDataDir, | 37 | SysDataDir, |
| 37 | UserDir, | 38 | UserDir, |
diff --git a/src/common/hex_util.cpp b/src/common/hex_util.cpp index c2f6cf0f6..74f52dd11 100644 --- a/src/common/hex_util.cpp +++ b/src/common/hex_util.cpp | |||
| @@ -3,21 +3,9 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/hex_util.h" | 5 | #include "common/hex_util.h" |
| 6 | #include "common/logging/log.h" | ||
| 7 | 6 | ||
| 8 | namespace Common { | 7 | namespace Common { |
| 9 | 8 | ||
| 10 | u8 ToHexNibble(char c1) { | ||
| 11 | if (c1 >= 65 && c1 <= 70) | ||
| 12 | return c1 - 55; | ||
| 13 | if (c1 >= 97 && c1 <= 102) | ||
| 14 | return c1 - 87; | ||
| 15 | if (c1 >= 48 && c1 <= 57) | ||
| 16 | return c1 - 48; | ||
| 17 | LOG_ERROR(Common, "Invalid hex digit: 0x{:02X}", c1); | ||
| 18 | return 0; | ||
| 19 | } | ||
| 20 | |||
| 21 | std::vector<u8> HexStringToVector(std::string_view str, bool little_endian) { | 9 | std::vector<u8> HexStringToVector(std::string_view str, bool little_endian) { |
| 22 | std::vector<u8> out(str.size() / 2); | 10 | std::vector<u8> out(str.size() / 2); |
| 23 | if (little_endian) { | 11 | if (little_endian) { |
| @@ -30,26 +18,4 @@ std::vector<u8> HexStringToVector(std::string_view str, bool little_endian) { | |||
| 30 | return out; | 18 | return out; |
| 31 | } | 19 | } |
| 32 | 20 | ||
| 33 | std::array<u8, 16> operator""_array16(const char* str, std::size_t len) { | ||
| 34 | if (len != 32) { | ||
| 35 | LOG_ERROR(Common, | ||
| 36 | "Attempting to parse string to array that is not of correct size (expected=32, " | ||
| 37 | "actual={}).", | ||
| 38 | len); | ||
| 39 | return {}; | ||
| 40 | } | ||
| 41 | return HexStringToArray<16>(str); | ||
| 42 | } | ||
| 43 | |||
| 44 | std::array<u8, 32> operator""_array32(const char* str, std::size_t len) { | ||
| 45 | if (len != 64) { | ||
| 46 | LOG_ERROR(Common, | ||
| 47 | "Attempting to parse string to array that is not of correct size (expected=64, " | ||
| 48 | "actual={}).", | ||
| 49 | len); | ||
| 50 | return {}; | ||
| 51 | } | ||
| 52 | return HexStringToArray<32>(str); | ||
| 53 | } | ||
| 54 | |||
| 55 | } // namespace Common | 21 | } // namespace Common |
diff --git a/src/common/hex_util.h b/src/common/hex_util.h index bb4736f96..a0a0e78a4 100644 --- a/src/common/hex_util.h +++ b/src/common/hex_util.h | |||
| @@ -14,19 +14,31 @@ | |||
| 14 | 14 | ||
| 15 | namespace Common { | 15 | namespace Common { |
| 16 | 16 | ||
| 17 | u8 ToHexNibble(char c1); | 17 | constexpr u8 ToHexNibble(char c) { |
| 18 | if (c >= 65 && c <= 70) { | ||
| 19 | return c - 55; | ||
| 20 | } | ||
| 21 | |||
| 22 | if (c >= 97 && c <= 102) { | ||
| 23 | return c - 87; | ||
| 24 | } | ||
| 25 | |||
| 26 | return c - 48; | ||
| 27 | } | ||
| 18 | 28 | ||
| 19 | std::vector<u8> HexStringToVector(std::string_view str, bool little_endian); | 29 | std::vector<u8> HexStringToVector(std::string_view str, bool little_endian); |
| 20 | 30 | ||
| 21 | template <std::size_t Size, bool le = false> | 31 | template <std::size_t Size, bool le = false> |
| 22 | std::array<u8, Size> HexStringToArray(std::string_view str) { | 32 | constexpr std::array<u8, Size> HexStringToArray(std::string_view str) { |
| 23 | std::array<u8, Size> out{}; | 33 | std::array<u8, Size> out{}; |
| 24 | if constexpr (le) { | 34 | if constexpr (le) { |
| 25 | for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) | 35 | for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) { |
| 26 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); | 36 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); |
| 37 | } | ||
| 27 | } else { | 38 | } else { |
| 28 | for (std::size_t i = 0; i < 2 * Size; i += 2) | 39 | for (std::size_t i = 0; i < 2 * Size; i += 2) { |
| 29 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); | 40 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); |
| 41 | } | ||
| 30 | } | 42 | } |
| 31 | return out; | 43 | return out; |
| 32 | } | 44 | } |
| @@ -48,7 +60,12 @@ std::string HexToString(const ContiguousContainer& data, bool upper = true) { | |||
| 48 | return out; | 60 | return out; |
| 49 | } | 61 | } |
| 50 | 62 | ||
| 51 | std::array<u8, 0x10> operator"" _array16(const char* str, std::size_t len); | 63 | constexpr std::array<u8, 16> AsArray(const char (&data)[17]) { |
| 52 | std::array<u8, 0x20> operator"" _array32(const char* str, std::size_t len); | 64 | return HexStringToArray<16>(data); |
| 65 | } | ||
| 66 | |||
| 67 | constexpr std::array<u8, 32> AsArray(const char (&data)[65]) { | ||
| 68 | return HexStringToArray<32>(data); | ||
| 69 | } | ||
| 53 | 70 | ||
| 54 | } // namespace Common | 71 | } // namespace Common |
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 04bc3128f..62cfde397 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -113,19 +113,19 @@ private: | |||
| 113 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | 113 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, |
| 114 | const char* function, std::string message) const { | 114 | const char* function, std::string message) const { |
| 115 | using std::chrono::duration_cast; | 115 | using std::chrono::duration_cast; |
| 116 | using std::chrono::microseconds; | ||
| 116 | using std::chrono::steady_clock; | 117 | using std::chrono::steady_clock; |
| 117 | 118 | ||
| 118 | Entry entry; | 119 | return { |
| 119 | entry.timestamp = | 120 | .timestamp = duration_cast<microseconds>(steady_clock::now() - time_origin), |
| 120 | duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); | 121 | .log_class = log_class, |
| 121 | entry.log_class = log_class; | 122 | .log_level = log_level, |
| 122 | entry.log_level = log_level; | 123 | .filename = filename, |
| 123 | entry.filename = filename; | 124 | .line_num = line_nr, |
| 124 | entry.line_num = line_nr; | 125 | .function = function, |
| 125 | entry.function = function; | 126 | .message = std::move(message), |
| 126 | entry.message = std::move(message); | 127 | .final_entry = false, |
| 127 | 128 | }; | |
| 128 | return entry; | ||
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | std::mutex writing_mutex; | 131 | std::mutex writing_mutex; |
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index fc338c70d..e5d702568 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h | |||
| @@ -21,19 +21,13 @@ class Filter; | |||
| 21 | */ | 21 | */ |
| 22 | struct Entry { | 22 | struct Entry { |
| 23 | std::chrono::microseconds timestamp; | 23 | std::chrono::microseconds timestamp; |
| 24 | Class log_class; | 24 | Class log_class{}; |
| 25 | Level log_level; | 25 | Level log_level{}; |
| 26 | const char* filename; | 26 | const char* filename = nullptr; |
| 27 | unsigned int line_num; | 27 | unsigned int line_num = 0; |
| 28 | std::string function; | 28 | std::string function; |
| 29 | std::string message; | 29 | std::string message; |
| 30 | bool final_entry = false; | 30 | bool final_entry = false; |
| 31 | |||
| 32 | Entry() = default; | ||
| 33 | Entry(Entry&& o) = default; | ||
| 34 | |||
| 35 | Entry& operator=(Entry&& o) = default; | ||
| 36 | Entry& operator=(const Entry& o) = default; | ||
| 37 | }; | 31 | }; |
| 38 | 32 | ||
| 39 | /** | 33 | /** |
diff --git a/src/common/string_util.h b/src/common/string_util.h index 583fd05e6..023dff5dc 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -74,16 +74,4 @@ std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t | |||
| 74 | std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, | 74 | std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, |
| 75 | std::size_t max_len); | 75 | std::size_t max_len); |
| 76 | 76 | ||
| 77 | /** | ||
| 78 | * Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's | ||
| 79 | * intended to be used to strip a system-specific build directory from the `__FILE__` macro, | ||
| 80 | * leaving only the path relative to the sources root. | ||
| 81 | * | ||
| 82 | * @param path The input file path as a null-terminated string | ||
| 83 | * @param root The name of the root source directory as a null-terminated string. Path up to and | ||
| 84 | * including the last occurrence of this name will be stripped | ||
| 85 | * @return A pointer to the same string passed as `path`, but starting at the trimmed portion | ||
| 86 | */ | ||
| 87 | const char* TrimSourcePath(const char* path, const char* root = "src"); | ||
| 88 | |||
| 89 | } // namespace Common | 77 | } // namespace Common |
diff --git a/src/common/virtual_buffer.cpp b/src/common/virtual_buffer.cpp index b426f4747..be5b67752 100644 --- a/src/common/virtual_buffer.cpp +++ b/src/common/virtual_buffer.cpp | |||
| @@ -38,7 +38,7 @@ void* AllocateMemoryPages(std::size_t size) { | |||
| 38 | return base; | 38 | return base; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | void FreeMemoryPages(void* base, std::size_t size) { | 41 | void FreeMemoryPages(void* base, [[maybe_unused]] std::size_t size) { |
| 42 | if (!base) { | 42 | if (!base) { |
| 43 | return; | 43 | return; |
| 44 | } | 44 | } |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c42f95705..c85c9485f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -586,6 +586,9 @@ add_library(core STATIC | |||
| 586 | memory/dmnt_cheat_vm.h | 586 | memory/dmnt_cheat_vm.h |
| 587 | memory.cpp | 587 | memory.cpp |
| 588 | memory.h | 588 | memory.h |
| 589 | network/network.cpp | ||
| 590 | network/network.h | ||
| 591 | network/sockets.h | ||
| 589 | perf_stats.cpp | 592 | perf_stats.cpp |
| 590 | perf_stats.h | 593 | perf_stats.h |
| 591 | reporter.cpp | 594 | reporter.cpp |
diff --git a/src/core/core.cpp b/src/core/core.cpp index 69a1aa0a5..42277e2cd 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -43,6 +43,7 @@ | |||
| 43 | #include "core/loader/loader.h" | 43 | #include "core/loader/loader.h" |
| 44 | #include "core/memory.h" | 44 | #include "core/memory.h" |
| 45 | #include "core/memory/cheat_engine.h" | 45 | #include "core/memory/cheat_engine.h" |
| 46 | #include "core/network/network.h" | ||
| 46 | #include "core/perf_stats.h" | 47 | #include "core/perf_stats.h" |
| 47 | #include "core/reporter.h" | 48 | #include "core/reporter.h" |
| 48 | #include "core/settings.h" | 49 | #include "core/settings.h" |
| @@ -145,7 +146,7 @@ struct System::Impl { | |||
| 145 | ResultStatus Init(System& system, Frontend::EmuWindow& emu_window) { | 146 | ResultStatus Init(System& system, Frontend::EmuWindow& emu_window) { |
| 146 | LOG_DEBUG(HW_Memory, "initialized OK"); | 147 | LOG_DEBUG(HW_Memory, "initialized OK"); |
| 147 | 148 | ||
| 148 | device_memory = std::make_unique<Core::DeviceMemory>(system); | 149 | device_memory = std::make_unique<Core::DeviceMemory>(); |
| 149 | 150 | ||
| 150 | is_multicore = Settings::values.use_multi_core.GetValue(); | 151 | is_multicore = Settings::values.use_multi_core.GetValue(); |
| 151 | is_async_gpu = is_multicore || Settings::values.use_asynchronous_gpu_emulation.GetValue(); | 152 | is_async_gpu = is_multicore || Settings::values.use_asynchronous_gpu_emulation.GetValue(); |
| @@ -394,6 +395,9 @@ struct System::Impl { | |||
| 394 | /// Telemetry session for this emulation session | 395 | /// Telemetry session for this emulation session |
| 395 | std::unique_ptr<Core::TelemetrySession> telemetry_session; | 396 | std::unique_ptr<Core::TelemetrySession> telemetry_session; |
| 396 | 397 | ||
| 398 | /// Network instance | ||
| 399 | Network::NetworkInstance network_instance; | ||
| 400 | |||
| 397 | ResultStatus status = ResultStatus::Success; | 401 | ResultStatus status = ResultStatus::Success; |
| 398 | std::string status_details = ""; | 402 | std::string status_details = ""; |
| 399 | 403 | ||
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index b5feb3f24..71af26ec5 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp | |||
| @@ -23,7 +23,7 @@ std::shared_ptr<EventType> CreateEvent(std::string name, TimedCallback&& callbac | |||
| 23 | struct CoreTiming::Event { | 23 | struct CoreTiming::Event { |
| 24 | u64 time; | 24 | u64 time; |
| 25 | u64 fifo_order; | 25 | u64 fifo_order; |
| 26 | u64 userdata; | 26 | std::uintptr_t user_data; |
| 27 | std::weak_ptr<EventType> type; | 27 | std::weak_ptr<EventType> type; |
| 28 | 28 | ||
| 29 | // Sort by time, unless the times are the same, in which case sort by | 29 | // Sort by time, unless the times are the same, in which case sort by |
| @@ -58,7 +58,7 @@ void CoreTiming::Initialize(std::function<void()>&& on_thread_init_) { | |||
| 58 | event_fifo_id = 0; | 58 | event_fifo_id = 0; |
| 59 | shutting_down = false; | 59 | shutting_down = false; |
| 60 | ticks = 0; | 60 | ticks = 0; |
| 61 | const auto empty_timed_callback = [](u64, std::chrono::nanoseconds) {}; | 61 | const auto empty_timed_callback = [](std::uintptr_t, std::chrono::nanoseconds) {}; |
| 62 | ev_lost = CreateEvent("_lost_event", empty_timed_callback); | 62 | ev_lost = CreateEvent("_lost_event", empty_timed_callback); |
| 63 | if (is_multicore) { | 63 | if (is_multicore) { |
| 64 | timer_thread = std::make_unique<std::thread>(ThreadEntry, std::ref(*this)); | 64 | timer_thread = std::make_unique<std::thread>(ThreadEntry, std::ref(*this)); |
| @@ -107,22 +107,24 @@ bool CoreTiming::HasPendingEvents() const { | |||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | void CoreTiming::ScheduleEvent(std::chrono::nanoseconds ns_into_future, | 109 | void CoreTiming::ScheduleEvent(std::chrono::nanoseconds ns_into_future, |
| 110 | const std::shared_ptr<EventType>& event_type, u64 userdata) { | 110 | const std::shared_ptr<EventType>& event_type, |
| 111 | std::uintptr_t user_data) { | ||
| 111 | { | 112 | { |
| 112 | std::scoped_lock scope{basic_lock}; | 113 | std::scoped_lock scope{basic_lock}; |
| 113 | const u64 timeout = static_cast<u64>((GetGlobalTimeNs() + ns_into_future).count()); | 114 | const u64 timeout = static_cast<u64>((GetGlobalTimeNs() + ns_into_future).count()); |
| 114 | 115 | ||
| 115 | event_queue.emplace_back(Event{timeout, event_fifo_id++, userdata, event_type}); | 116 | event_queue.emplace_back(Event{timeout, event_fifo_id++, user_data, event_type}); |
| 116 | 117 | ||
| 117 | std::push_heap(event_queue.begin(), event_queue.end(), std::greater<>()); | 118 | std::push_heap(event_queue.begin(), event_queue.end(), std::greater<>()); |
| 118 | } | 119 | } |
| 119 | event.Set(); | 120 | event.Set(); |
| 120 | } | 121 | } |
| 121 | 122 | ||
| 122 | void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, u64 userdata) { | 123 | void CoreTiming::UnscheduleEvent(const std::shared_ptr<EventType>& event_type, |
| 124 | std::uintptr_t user_data) { | ||
| 123 | std::scoped_lock scope{basic_lock}; | 125 | std::scoped_lock scope{basic_lock}; |
| 124 | const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { | 126 | const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { |
| 125 | return e.type.lock().get() == event_type.get() && e.userdata == userdata; | 127 | return e.type.lock().get() == event_type.get() && e.user_data == user_data; |
| 126 | }); | 128 | }); |
| 127 | 129 | ||
| 128 | // Removing random items breaks the invariant so we have to re-establish it. | 130 | // Removing random items breaks the invariant so we have to re-establish it. |
| @@ -197,7 +199,7 @@ std::optional<s64> CoreTiming::Advance() { | |||
| 197 | 199 | ||
| 198 | if (const auto event_type{evt.type.lock()}) { | 200 | if (const auto event_type{evt.type.lock()}) { |
| 199 | event_type->callback( | 201 | event_type->callback( |
| 200 | evt.userdata, std::chrono::nanoseconds{static_cast<s64>(global_timer - evt.time)}); | 202 | evt.user_data, std::chrono::nanoseconds{static_cast<s64>(global_timer - evt.time)}); |
| 201 | } | 203 | } |
| 202 | 204 | ||
| 203 | basic_lock.lock(); | 205 | basic_lock.lock(); |
diff --git a/src/core/core_timing.h b/src/core/core_timing.h index 120c74e46..b0b6036e4 100644 --- a/src/core/core_timing.h +++ b/src/core/core_timing.h | |||
| @@ -22,7 +22,8 @@ | |||
| 22 | namespace Core::Timing { | 22 | namespace Core::Timing { |
| 23 | 23 | ||
| 24 | /// A callback that may be scheduled for a particular core timing event. | 24 | /// A callback that may be scheduled for a particular core timing event. |
| 25 | using TimedCallback = std::function<void(u64 userdata, std::chrono::nanoseconds ns_late)>; | 25 | using TimedCallback = |
| 26 | std::function<void(std::uintptr_t user_data, std::chrono::nanoseconds ns_late)>; | ||
| 26 | 27 | ||
| 27 | /// Contains the characteristics of a particular event. | 28 | /// Contains the characteristics of a particular event. |
| 28 | struct EventType { | 29 | struct EventType { |
| @@ -94,9 +95,9 @@ public: | |||
| 94 | 95 | ||
| 95 | /// Schedules an event in core timing | 96 | /// Schedules an event in core timing |
| 96 | void ScheduleEvent(std::chrono::nanoseconds ns_into_future, | 97 | void ScheduleEvent(std::chrono::nanoseconds ns_into_future, |
| 97 | const std::shared_ptr<EventType>& event_type, u64 userdata = 0); | 98 | const std::shared_ptr<EventType>& event_type, std::uintptr_t user_data = 0); |
| 98 | 99 | ||
| 99 | void UnscheduleEvent(const std::shared_ptr<EventType>& event_type, u64 userdata); | 100 | void UnscheduleEvent(const std::shared_ptr<EventType>& event_type, std::uintptr_t user_data); |
| 100 | 101 | ||
| 101 | /// We only permit one event of each type in the queue at a time. | 102 | /// We only permit one event of each type in the queue at a time. |
| 102 | void RemoveEvent(const std::shared_ptr<EventType>& event_type); | 103 | void RemoveEvent(const std::shared_ptr<EventType>& event_type); |
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 32afcf3ae..358943429 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp | |||
| @@ -52,15 +52,15 @@ void CpuManager::Shutdown() { | |||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | std::function<void(void*)> CpuManager::GetGuestThreadStartFunc() { | 54 | std::function<void(void*)> CpuManager::GetGuestThreadStartFunc() { |
| 55 | return std::function<void(void*)>(GuestThreadFunction); | 55 | return GuestThreadFunction; |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | std::function<void(void*)> CpuManager::GetIdleThreadStartFunc() { | 58 | std::function<void(void*)> CpuManager::GetIdleThreadStartFunc() { |
| 59 | return std::function<void(void*)>(IdleThreadFunction); | 59 | return IdleThreadFunction; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | std::function<void(void*)> CpuManager::GetSuspendThreadStartFunc() { | 62 | std::function<void(void*)> CpuManager::GetSuspendThreadStartFunc() { |
| 63 | return std::function<void(void*)>(SuspendThreadFunction); | 63 | return SuspendThreadFunction; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | void CpuManager::GuestThreadFunction(void* cpu_manager_) { | 66 | void CpuManager::GuestThreadFunction(void* cpu_manager_) { |
diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp index 4be76bb43..330996b24 100644 --- a/src/core/crypto/aes_util.cpp +++ b/src/core/crypto/aes_util.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 <array> | ||
| 5 | #include <mbedtls/cipher.h> | 6 | #include <mbedtls/cipher.h> |
| 6 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 7 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| @@ -10,8 +11,10 @@ | |||
| 10 | 11 | ||
| 11 | namespace Core::Crypto { | 12 | namespace Core::Crypto { |
| 12 | namespace { | 13 | namespace { |
| 13 | std::vector<u8> CalculateNintendoTweak(std::size_t sector_id) { | 14 | using NintendoTweak = std::array<u8, 16>; |
| 14 | std::vector<u8> out(0x10); | 15 | |
| 16 | NintendoTweak CalculateNintendoTweak(std::size_t sector_id) { | ||
| 17 | NintendoTweak out{}; | ||
| 15 | for (std::size_t i = 0xF; i <= 0xF; --i) { | 18 | for (std::size_t i = 0xF; i <= 0xF; --i) { |
| 16 | out[i] = sector_id & 0xFF; | 19 | out[i] = sector_id & 0xFF; |
| 17 | sector_id >>= 8; | 20 | sector_id >>= 8; |
| @@ -64,13 +67,6 @@ AESCipher<Key, KeySize>::~AESCipher() { | |||
| 64 | } | 67 | } |
| 65 | 68 | ||
| 66 | template <typename Key, std::size_t KeySize> | 69 | template <typename Key, std::size_t KeySize> |
| 67 | void AESCipher<Key, KeySize>::SetIV(std::vector<u8> iv) { | ||
| 68 | ASSERT_MSG((mbedtls_cipher_set_iv(&ctx->encryption_context, iv.data(), iv.size()) || | ||
| 69 | mbedtls_cipher_set_iv(&ctx->decryption_context, iv.data(), iv.size())) == 0, | ||
| 70 | "Failed to set IV on mbedtls ciphers."); | ||
| 71 | } | ||
| 72 | |||
| 73 | template <typename Key, std::size_t KeySize> | ||
| 74 | void AESCipher<Key, KeySize>::Transcode(const u8* src, std::size_t size, u8* dest, Op op) const { | 70 | void AESCipher<Key, KeySize>::Transcode(const u8* src, std::size_t size, u8* dest, Op op) const { |
| 75 | auto* const context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context; | 71 | auto* const context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context; |
| 76 | 72 | ||
| @@ -124,6 +120,13 @@ void AESCipher<Key, KeySize>::XTSTranscode(const u8* src, std::size_t size, u8* | |||
| 124 | } | 120 | } |
| 125 | } | 121 | } |
| 126 | 122 | ||
| 123 | template <typename Key, std::size_t KeySize> | ||
| 124 | void AESCipher<Key, KeySize>::SetIVImpl(const u8* data, std::size_t size) { | ||
| 125 | ASSERT_MSG((mbedtls_cipher_set_iv(&ctx->encryption_context, data, size) || | ||
| 126 | mbedtls_cipher_set_iv(&ctx->decryption_context, data, size)) == 0, | ||
| 127 | "Failed to set IV on mbedtls ciphers."); | ||
| 128 | } | ||
| 129 | |||
| 127 | template class AESCipher<Key128>; | 130 | template class AESCipher<Key128>; |
| 128 | template class AESCipher<Key256>; | 131 | template class AESCipher<Key256>; |
| 129 | } // namespace Core::Crypto | 132 | } // namespace Core::Crypto |
diff --git a/src/core/crypto/aes_util.h b/src/core/crypto/aes_util.h index edc4ab910..e2a304186 100644 --- a/src/core/crypto/aes_util.h +++ b/src/core/crypto/aes_util.h | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <type_traits> | 8 | #include <type_traits> |
| 9 | #include <vector> | ||
| 10 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 11 | #include "core/file_sys/vfs.h" | 10 | #include "core/file_sys/vfs.h" |
| 12 | 11 | ||
| @@ -32,10 +31,12 @@ class AESCipher { | |||
| 32 | 31 | ||
| 33 | public: | 32 | public: |
| 34 | AESCipher(Key key, Mode mode); | 33 | AESCipher(Key key, Mode mode); |
| 35 | |||
| 36 | ~AESCipher(); | 34 | ~AESCipher(); |
| 37 | 35 | ||
| 38 | void SetIV(std::vector<u8> iv); | 36 | template <typename ContiguousContainer> |
| 37 | void SetIV(const ContiguousContainer& container) { | ||
| 38 | SetIVImpl(std::data(container), std::size(container)); | ||
| 39 | } | ||
| 39 | 40 | ||
| 40 | template <typename Source, typename Dest> | 41 | template <typename Source, typename Dest> |
| 41 | void Transcode(const Source* src, std::size_t size, Dest* dest, Op op) const { | 42 | void Transcode(const Source* src, std::size_t size, Dest* dest, Op op) const { |
| @@ -59,6 +60,8 @@ public: | |||
| 59 | std::size_t sector_size, Op op); | 60 | std::size_t sector_size, Op op); |
| 60 | 61 | ||
| 61 | private: | 62 | private: |
| 63 | void SetIVImpl(const u8* data, std::size_t size); | ||
| 64 | |||
| 62 | std::unique_ptr<CipherContext> ctx; | 65 | std::unique_ptr<CipherContext> ctx; |
| 63 | }; | 66 | }; |
| 64 | } // namespace Core::Crypto | 67 | } // namespace Core::Crypto |
diff --git a/src/core/crypto/ctr_encryption_layer.cpp b/src/core/crypto/ctr_encryption_layer.cpp index 902841c77..5c84bb0a4 100644 --- a/src/core/crypto/ctr_encryption_layer.cpp +++ b/src/core/crypto/ctr_encryption_layer.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 <cstring> | 6 | #include <cstring> |
| 6 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 7 | #include "core/crypto/ctr_encryption_layer.h" | 8 | #include "core/crypto/ctr_encryption_layer.h" |
| @@ -10,8 +11,7 @@ namespace Core::Crypto { | |||
| 10 | 11 | ||
| 11 | CTREncryptionLayer::CTREncryptionLayer(FileSys::VirtualFile base_, Key128 key_, | 12 | CTREncryptionLayer::CTREncryptionLayer(FileSys::VirtualFile base_, Key128 key_, |
| 12 | std::size_t base_offset) | 13 | std::size_t base_offset) |
| 13 | : EncryptionLayer(std::move(base_)), base_offset(base_offset), cipher(key_, Mode::CTR), | 14 | : EncryptionLayer(std::move(base_)), base_offset(base_offset), cipher(key_, Mode::CTR) {} |
| 14 | iv(16, 0) {} | ||
| 15 | 15 | ||
| 16 | std::size_t CTREncryptionLayer::Read(u8* data, std::size_t length, std::size_t offset) const { | 16 | std::size_t CTREncryptionLayer::Read(u8* data, std::size_t length, std::size_t offset) const { |
| 17 | if (length == 0) | 17 | if (length == 0) |
| @@ -39,9 +39,8 @@ std::size_t CTREncryptionLayer::Read(u8* data, std::size_t length, std::size_t o | |||
| 39 | return read + Read(data + read, length - read, offset + read); | 39 | return read + Read(data + read, length - read, offset + read); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | void CTREncryptionLayer::SetIV(const std::vector<u8>& iv_) { | 42 | void CTREncryptionLayer::SetIV(const IVData& iv_) { |
| 43 | const auto length = std::min(iv_.size(), iv.size()); | 43 | iv = iv_; |
| 44 | iv.assign(iv_.cbegin(), iv_.cbegin() + length); | ||
| 45 | } | 44 | } |
| 46 | 45 | ||
| 47 | void CTREncryptionLayer::UpdateIV(std::size_t offset) const { | 46 | void CTREncryptionLayer::UpdateIV(std::size_t offset) const { |
diff --git a/src/core/crypto/ctr_encryption_layer.h b/src/core/crypto/ctr_encryption_layer.h index a7bf810f4..a2429f001 100644 --- a/src/core/crypto/ctr_encryption_layer.h +++ b/src/core/crypto/ctr_encryption_layer.h | |||
| @@ -4,7 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <vector> | 7 | #include <array> |
| 8 | |||
| 8 | #include "core/crypto/aes_util.h" | 9 | #include "core/crypto/aes_util.h" |
| 9 | #include "core/crypto/encryption_layer.h" | 10 | #include "core/crypto/encryption_layer.h" |
| 10 | #include "core/crypto/key_manager.h" | 11 | #include "core/crypto/key_manager.h" |
| @@ -14,18 +15,20 @@ namespace Core::Crypto { | |||
| 14 | // Sits on top of a VirtualFile and provides CTR-mode AES decription. | 15 | // Sits on top of a VirtualFile and provides CTR-mode AES decription. |
| 15 | class CTREncryptionLayer : public EncryptionLayer { | 16 | class CTREncryptionLayer : public EncryptionLayer { |
| 16 | public: | 17 | public: |
| 18 | using IVData = std::array<u8, 16>; | ||
| 19 | |||
| 17 | CTREncryptionLayer(FileSys::VirtualFile base, Key128 key, std::size_t base_offset); | 20 | CTREncryptionLayer(FileSys::VirtualFile base, Key128 key, std::size_t base_offset); |
| 18 | 21 | ||
| 19 | std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override; | 22 | std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override; |
| 20 | 23 | ||
| 21 | void SetIV(const std::vector<u8>& iv); | 24 | void SetIV(const IVData& iv); |
| 22 | 25 | ||
| 23 | private: | 26 | private: |
| 24 | std::size_t base_offset; | 27 | std::size_t base_offset; |
| 25 | 28 | ||
| 26 | // Must be mutable as operations modify cipher contexts. | 29 | // Must be mutable as operations modify cipher contexts. |
| 27 | mutable AESCipher<Key128> cipher; | 30 | mutable AESCipher<Key128> cipher; |
| 28 | mutable std::vector<u8> iv; | 31 | mutable IVData iv{}; |
| 29 | 32 | ||
| 30 | void UpdateIV(std::size_t offset) const; | 33 | void UpdateIV(std::size_t offset) const; |
| 31 | }; | 34 | }; |
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index f87fe0abc..c09f7ad41 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp | |||
| @@ -40,12 +40,14 @@ namespace Core::Crypto { | |||
| 40 | constexpr u64 CURRENT_CRYPTO_REVISION = 0x5; | 40 | constexpr u64 CURRENT_CRYPTO_REVISION = 0x5; |
| 41 | constexpr u64 FULL_TICKET_SIZE = 0x400; | 41 | constexpr u64 FULL_TICKET_SIZE = 0x400; |
| 42 | 42 | ||
| 43 | using namespace Common; | 43 | using Common::AsArray; |
| 44 | 44 | ||
| 45 | const std::array<SHA256Hash, 2> eticket_source_hashes{ | 45 | // clang-format off |
| 46 | "B71DB271DC338DF380AA2C4335EF8873B1AFD408E80B3582D8719FC81C5E511C"_array32, // eticket_rsa_kek_source | 46 | constexpr std::array eticket_source_hashes{ |
| 47 | "E8965A187D30E57869F562D04383C996DE487BBA5761363D2D4D32391866A85C"_array32, // eticket_rsa_kekek_source | 47 | AsArray("B71DB271DC338DF380AA2C4335EF8873B1AFD408E80B3582D8719FC81C5E511C"), // eticket_rsa_kek_source |
| 48 | AsArray("E8965A187D30E57869F562D04383C996DE487BBA5761363D2D4D32391866A85C"), // eticket_rsa_kekek_source | ||
| 48 | }; | 49 | }; |
| 50 | // clang-format on | ||
| 49 | 51 | ||
| 50 | const std::map<std::pair<S128KeyType, u64>, std::string> KEYS_VARIABLE_LENGTH{ | 52 | const std::map<std::pair<S128KeyType, u64>, std::string> KEYS_VARIABLE_LENGTH{ |
| 51 | {{S128KeyType::Master, 0}, "master_key_"}, | 53 | {{S128KeyType::Master, 0}, "master_key_"}, |
diff --git a/src/core/crypto/partition_data_manager.cpp b/src/core/crypto/partition_data_manager.cpp index 7ed71ac3a..3e96f7516 100644 --- a/src/core/crypto/partition_data_manager.cpp +++ b/src/core/crypto/partition_data_manager.cpp | |||
| @@ -27,7 +27,7 @@ | |||
| 27 | #include "core/file_sys/vfs_offset.h" | 27 | #include "core/file_sys/vfs_offset.h" |
| 28 | #include "core/file_sys/vfs_vector.h" | 28 | #include "core/file_sys/vfs_vector.h" |
| 29 | 29 | ||
| 30 | using namespace Common; | 30 | using Common::AsArray; |
| 31 | 31 | ||
| 32 | namespace Core::Crypto { | 32 | namespace Core::Crypto { |
| 33 | 33 | ||
| @@ -47,105 +47,123 @@ struct Package2Header { | |||
| 47 | }; | 47 | }; |
| 48 | static_assert(sizeof(Package2Header) == 0x200, "Package2Header has incorrect size."); | 48 | static_assert(sizeof(Package2Header) == 0x200, "Package2Header has incorrect size."); |
| 49 | 49 | ||
| 50 | const std::array<SHA256Hash, 0x10> source_hashes{ | 50 | // clang-format off |
| 51 | "B24BD293259DBC7AC5D63F88E60C59792498E6FC5443402C7FFE87EE8B61A3F0"_array32, // keyblob_mac_key_source | 51 | constexpr std::array source_hashes{ |
| 52 | "7944862A3A5C31C6720595EFD302245ABD1B54CCDCF33000557681E65C5664A4"_array32, // master_key_source | 52 | AsArray("B24BD293259DBC7AC5D63F88E60C59792498E6FC5443402C7FFE87EE8B61A3F0"), // keyblob_mac_key_source |
| 53 | "21E2DF100FC9E094DB51B47B9B1D6E94ED379DB8B547955BEF8FE08D8DD35603"_array32, // package2_key_source | 53 | AsArray("7944862A3A5C31C6720595EFD302245ABD1B54CCDCF33000557681E65C5664A4"), // master_key_source |
| 54 | "FC02B9D37B42D7A1452E71444F1F700311D1132E301A83B16062E72A78175085"_array32, // aes_kek_generation_source | 54 | AsArray("21E2DF100FC9E094DB51B47B9B1D6E94ED379DB8B547955BEF8FE08D8DD35603"), // package2_key_source |
| 55 | "FBD10056999EDC7ACDB96098E47E2C3606230270D23281E671F0F389FC5BC585"_array32, // aes_key_generation_source | 55 | AsArray("FC02B9D37B42D7A1452E71444F1F700311D1132E301A83B16062E72A78175085"), // aes_kek_generation_source |
| 56 | "C48B619827986C7F4E3081D59DB2B460C84312650E9A8E6B458E53E8CBCA4E87"_array32, // titlekek_source | 56 | AsArray("FBD10056999EDC7ACDB96098E47E2C3606230270D23281E671F0F389FC5BC585"), // aes_key_generation_source |
| 57 | "04AD66143C726B2A139FB6B21128B46F56C553B2B3887110304298D8D0092D9E"_array32, // key_area_key_application_source | 57 | AsArray("C48B619827986C7F4E3081D59DB2B460C84312650E9A8E6B458E53E8CBCA4E87"), // titlekek_source |
| 58 | "FD434000C8FF2B26F8E9A9D2D2C12F6BE5773CBB9DC86300E1BD99F8EA33A417"_array32, // key_area_key_ocean_source | 58 | AsArray("04AD66143C726B2A139FB6B21128B46F56C553B2B3887110304298D8D0092D9E"), // key_area_key_application_source |
| 59 | "1F17B1FD51AD1C2379B58F152CA4912EC2106441E51722F38700D5937A1162F7"_array32, // key_area_key_system_source | 59 | AsArray("FD434000C8FF2B26F8E9A9D2D2C12F6BE5773CBB9DC86300E1BD99F8EA33A417"), // key_area_key_ocean_source |
| 60 | "6B2ED877C2C52334AC51E59ABFA7EC457F4A7D01E46291E9F2EAA45F011D24B7"_array32, // sd_card_kek_source | 60 | AsArray("1F17B1FD51AD1C2379B58F152CA4912EC2106441E51722F38700D5937A1162F7"), // key_area_key_system_source |
| 61 | "D482743563D3EA5DCDC3B74E97C9AC8A342164FA041A1DC80F17F6D31E4BC01C"_array32, // sd_card_save_key_source | 61 | AsArray("6B2ED877C2C52334AC51E59ABFA7EC457F4A7D01E46291E9F2EAA45F011D24B7"), // sd_card_kek_source |
| 62 | "2E751CECF7D93A2B957BD5FFCB082FD038CC2853219DD3092C6DAB9838F5A7CC"_array32, // sd_card_nca_key_source | 62 | AsArray("D482743563D3EA5DCDC3B74E97C9AC8A342164FA041A1DC80F17F6D31E4BC01C"), // sd_card_save_key_source |
| 63 | "1888CAED5551B3EDE01499E87CE0D86827F80820EFB275921055AA4E2ABDFFC2"_array32, // header_kek_source | 63 | AsArray("2E751CECF7D93A2B957BD5FFCB082FD038CC2853219DD3092C6DAB9838F5A7CC"), // sd_card_nca_key_source |
| 64 | "8F783E46852DF6BE0BA4E19273C4ADBAEE16380043E1B8C418C4089A8BD64AA6"_array32, // header_key_source | 64 | AsArray("1888CAED5551B3EDE01499E87CE0D86827F80820EFB275921055AA4E2ABDFFC2"), // header_kek_source |
| 65 | "D1757E52F1AE55FA882EC690BC6F954AC46A83DC22F277F8806BD55577C6EED7"_array32, // rsa_kek_seed3 | 65 | AsArray("8F783E46852DF6BE0BA4E19273C4ADBAEE16380043E1B8C418C4089A8BD64AA6"), // header_key_source |
| 66 | "FC02B9D37B42D7A1452E71444F1F700311D1132E301A83B16062E72A78175085"_array32, // rsa_kek_mask0 | 66 | AsArray("D1757E52F1AE55FA882EC690BC6F954AC46A83DC22F277F8806BD55577C6EED7"), // rsa_kek_seed3 |
| 67 | AsArray("FC02B9D37B42D7A1452E71444F1F700311D1132E301A83B16062E72A78175085"), // rsa_kek_mask0 | ||
| 67 | }; | 68 | }; |
| 68 | 69 | // clang-format on | |
| 69 | const std::array<SHA256Hash, 0x20> keyblob_source_hashes{ | 70 | |
| 70 | "8A06FE274AC491436791FDB388BCDD3AB9943BD4DEF8094418CDAC150FD73786"_array32, // keyblob_key_source_00 | 71 | // clang-format off |
| 71 | "2D5CAEB2521FEF70B47E17D6D0F11F8CE2C1E442A979AD8035832C4E9FBCCC4B"_array32, // keyblob_key_source_01 | 72 | constexpr std::array keyblob_source_hashes{ |
| 72 | "61C5005E713BAE780641683AF43E5F5C0E03671117F702F401282847D2FC6064"_array32, // keyblob_key_source_02 | 73 | AsArray("8A06FE274AC491436791FDB388BCDD3AB9943BD4DEF8094418CDAC150FD73786"), // keyblob_key_source_00 |
| 73 | "8E9795928E1C4428E1B78F0BE724D7294D6934689C11B190943923B9D5B85903"_array32, // keyblob_key_source_03 | 74 | AsArray("2D5CAEB2521FEF70B47E17D6D0F11F8CE2C1E442A979AD8035832C4E9FBCCC4B"), // keyblob_key_source_01 |
| 74 | "95FA33AF95AFF9D9B61D164655B32710ED8D615D46C7D6CC3CC70481B686B402"_array32, // keyblob_key_source_04 | 75 | AsArray("61C5005E713BAE780641683AF43E5F5C0E03671117F702F401282847D2FC6064"), // keyblob_key_source_02 |
| 75 | "3F5BE7B3C8B1ABD8C10B4B703D44766BA08730562C172A4FE0D6B866B3E2DB3E"_array32, // keyblob_key_source_05 | 76 | AsArray("8E9795928E1C4428E1B78F0BE724D7294D6934689C11B190943923B9D5B85903"), // keyblob_key_source_03 |
| 76 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_06 | 77 | AsArray("95FA33AF95AFF9D9B61D164655B32710ED8D615D46C7D6CC3CC70481B686B402"), // keyblob_key_source_04 |
| 77 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_07 | 78 | AsArray("3F5BE7B3C8B1ABD8C10B4B703D44766BA08730562C172A4FE0D6B866B3E2DB3E"), // keyblob_key_source_05 |
| 78 | 79 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_06 | |
| 79 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_08 | 80 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_07 |
| 80 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_09 | 81 | |
| 81 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_0A | 82 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_08 |
| 82 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_0B | 83 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_09 |
| 83 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_0C | 84 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_0A |
| 84 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_0D | 85 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_0B |
| 85 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_0E | 86 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_0C |
| 86 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_0F | 87 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_0D |
| 87 | 88 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_0E | |
| 88 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_10 | 89 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_0F |
| 89 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_11 | 90 | |
| 90 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_12 | 91 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_10 |
| 91 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_13 | 92 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_11 |
| 92 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_14 | 93 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_12 |
| 93 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_15 | 94 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_13 |
| 94 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_16 | 95 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_14 |
| 95 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_17 | 96 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_15 |
| 96 | 97 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_16 | |
| 97 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_18 | 98 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_17 |
| 98 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_19 | 99 | |
| 99 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_1A | 100 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_18 |
| 100 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_1B | 101 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_19 |
| 101 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_1C | 102 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_1A |
| 102 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_1D | 103 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_1B |
| 103 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_1E | 104 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_1C |
| 104 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // keyblob_key_source_1F | 105 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_1D |
| 106 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_1E | ||
| 107 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // keyblob_key_source_1F | ||
| 105 | }; | 108 | }; |
| 106 | 109 | // clang-format on | |
| 107 | const std::array<SHA256Hash, 0x20> master_key_hashes{ | 110 | |
| 108 | "0EE359BE3C864BB0782E1D70A718A0342C551EED28C369754F9C4F691BECF7CA"_array32, // master_key_00 | 111 | // clang-format off |
| 109 | "4FE707B7E4ABDAF727C894AAF13B1351BFE2AC90D875F73B2E20FA94B9CC661E"_array32, // master_key_01 | 112 | constexpr std::array master_key_hashes{ |
| 110 | "79277C0237A2252EC3DFAC1F7C359C2B3D121E9DB15BB9AB4C2B4408D2F3AE09"_array32, // master_key_02 | 113 | AsArray("0EE359BE3C864BB0782E1D70A718A0342C551EED28C369754F9C4F691BECF7CA"), // master_key_00 |
| 111 | "4F36C565D13325F65EE134073C6A578FFCB0008E02D69400836844EAB7432754"_array32, // master_key_03 | 114 | AsArray("4FE707B7E4ABDAF727C894AAF13B1351BFE2AC90D875F73B2E20FA94B9CC661E"), // master_key_01 |
| 112 | "75FF1D95D26113550EE6FCC20ACB58E97EDEB3A2FF52543ED5AEC63BDCC3DA50"_array32, // master_key_04 | 115 | AsArray("79277C0237A2252EC3DFAC1F7C359C2B3D121E9DB15BB9AB4C2B4408D2F3AE09"), // master_key_02 |
| 113 | "EBE2BCD6704673EC0F88A187BB2AD9F1CC82B718C389425941BDC194DC46B0DD"_array32, // master_key_05 | 116 | AsArray("4F36C565D13325F65EE134073C6A578FFCB0008E02D69400836844EAB7432754"), // master_key_03 |
| 114 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_06 | 117 | AsArray("75FF1D95D26113550EE6FCC20ACB58E97EDEB3A2FF52543ED5AEC63BDCC3DA50"), // master_key_04 |
| 115 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_07 | 118 | AsArray("EBE2BCD6704673EC0F88A187BB2AD9F1CC82B718C389425941BDC194DC46B0DD"), // master_key_05 |
| 116 | 119 | AsArray("9497E6779F5D840F2BBA1DE4E95BA1D6F21EFC94717D5AE5CA37D7EC5BD37A19"), // master_key_06 | |
| 117 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_08 | 120 | AsArray("4EC96B8CB01B8DCE382149443430B2B6EBCB2983348AFA04A25E53609DABEDF6"), // master_key_07 |
| 118 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_09 | 121 | |
| 119 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_0A | 122 | AsArray("2998E2E23609BC2675FF062A2D64AF5B1B78DFF463B24119D64A1B64F01B2D51"), // master_key_08 |
| 120 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_0B | 123 | AsArray("9D486A98067C44B37CF173D3BF577891EB6081FF6B4A166347D9DBBF7025076B"), // master_key_09 |
| 121 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_0C | 124 | AsArray("4EC5A237A75A083A9C5F6CF615601522A7F822D06BD4BA32612C9CEBBB29BD45"), // master_key_0A |
| 122 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_0D | 125 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_0B |
| 123 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_0E | 126 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_0C |
| 124 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_0F | 127 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_0D |
| 125 | 128 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_0E | |
| 126 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_10 | 129 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_0F |
| 127 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_11 | 130 | |
| 128 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_12 | 131 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_10 |
| 129 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_13 | 132 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_11 |
| 130 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_14 | 133 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_12 |
| 131 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_15 | 134 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_13 |
| 132 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_16 | 135 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_14 |
| 133 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_17 | 136 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_15 |
| 134 | 137 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_16 | |
| 135 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_18 | 138 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_17 |
| 136 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_19 | 139 | |
| 137 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_1A | 140 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_18 |
| 138 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_1B | 141 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_19 |
| 139 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_1C | 142 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_1A |
| 140 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_1D | 143 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_1B |
| 141 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_1E | 144 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_1C |
| 142 | "0000000000000000000000000000000000000000000000000000000000000000"_array32, // master_key_1F | 145 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_1D |
| 146 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_1E | ||
| 147 | AsArray("0000000000000000000000000000000000000000000000000000000000000000"), // master_key_1F | ||
| 143 | }; | 148 | }; |
| 149 | // clang-format on | ||
| 150 | |||
| 151 | static constexpr u8 CalculateMaxKeyblobSourceHash() { | ||
| 152 | const auto is_zero = [](const auto& data) { | ||
| 153 | // TODO: Replace with std::all_of whenever mingw decides to update their | ||
| 154 | // libraries to include the constexpr variant of it. | ||
| 155 | for (const auto element : data) { | ||
| 156 | if (element != 0) { | ||
| 157 | return false; | ||
| 158 | } | ||
| 159 | } | ||
| 160 | return true; | ||
| 161 | }; | ||
| 144 | 162 | ||
| 145 | static u8 CalculateMaxKeyblobSourceHash() { | ||
| 146 | for (s8 i = 0x1F; i >= 0; --i) { | 163 | for (s8 i = 0x1F; i >= 0; --i) { |
| 147 | if (keyblob_source_hashes[i] != SHA256Hash{}) | 164 | if (!is_zero(keyblob_source_hashes[i])) { |
| 148 | return static_cast<u8>(i + 1); | 165 | return static_cast<u8>(i + 1); |
| 166 | } | ||
| 149 | } | 167 | } |
| 150 | 168 | ||
| 151 | return 0; | 169 | return 0; |
| @@ -346,10 +364,9 @@ FileSys::VirtualFile PartitionDataManager::GetPackage2Raw(Package2Type type) con | |||
| 346 | } | 364 | } |
| 347 | 365 | ||
| 348 | static bool AttemptDecrypt(const std::array<u8, 16>& key, Package2Header& header) { | 366 | static bool AttemptDecrypt(const std::array<u8, 16>& key, Package2Header& header) { |
| 349 | const std::vector<u8> iv(header.header_ctr.begin(), header.header_ctr.end()); | ||
| 350 | Package2Header temp = header; | 367 | Package2Header temp = header; |
| 351 | AESCipher<Key128> cipher(key, Mode::CTR); | 368 | AESCipher<Key128> cipher(key, Mode::CTR); |
| 352 | cipher.SetIV(iv); | 369 | cipher.SetIV(header.header_ctr); |
| 353 | cipher.Transcode(&temp.header_ctr, sizeof(Package2Header) - 0x100, &temp.header_ctr, | 370 | cipher.Transcode(&temp.header_ctr, sizeof(Package2Header) - 0x100, &temp.header_ctr, |
| 354 | Op::Decrypt); | 371 | Op::Decrypt); |
| 355 | if (temp.magic == Common::MakeMagic('P', 'K', '2', '1')) { | 372 | if (temp.magic == Common::MakeMagic('P', 'K', '2', '1')) { |
| @@ -388,7 +405,7 @@ void PartitionDataManager::DecryptPackage2(const std::array<Key128, 0x20>& packa | |||
| 388 | auto c = a->ReadAllBytes(); | 405 | auto c = a->ReadAllBytes(); |
| 389 | 406 | ||
| 390 | AESCipher<Key128> cipher(package2_keys[revision], Mode::CTR); | 407 | AESCipher<Key128> cipher(package2_keys[revision], Mode::CTR); |
| 391 | cipher.SetIV({header.section_ctr[1].begin(), header.section_ctr[1].end()}); | 408 | cipher.SetIV(header.section_ctr[1]); |
| 392 | cipher.Transcode(c.data(), c.size(), c.data(), Op::Decrypt); | 409 | cipher.Transcode(c.data(), c.size(), c.data(), Op::Decrypt); |
| 393 | 410 | ||
| 394 | const auto ini_file = std::make_shared<FileSys::VectorVfsFile>(c); | 411 | const auto ini_file = std::make_shared<FileSys::VectorVfsFile>(c); |
diff --git a/src/core/device_memory.cpp b/src/core/device_memory.cpp index 51097ced3..0c4b440ed 100644 --- a/src/core/device_memory.cpp +++ b/src/core/device_memory.cpp | |||
| @@ -2,14 +2,11 @@ | |||
| 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 "core/core.h" | ||
| 6 | #include "core/device_memory.h" | 5 | #include "core/device_memory.h" |
| 7 | #include "core/memory.h" | ||
| 8 | 6 | ||
| 9 | namespace Core { | 7 | namespace Core { |
| 10 | 8 | ||
| 11 | DeviceMemory::DeviceMemory(System& system) : buffer{DramMemoryMap::Size}, system{system} {} | 9 | DeviceMemory::DeviceMemory() : buffer{DramMemoryMap::Size} {} |
| 12 | |||
| 13 | DeviceMemory::~DeviceMemory() = default; | 10 | DeviceMemory::~DeviceMemory() = default; |
| 14 | 11 | ||
| 15 | } // namespace Core | 12 | } // namespace Core |
diff --git a/src/core/device_memory.h b/src/core/device_memory.h index 9efa088d0..5b1ae28f3 100644 --- a/src/core/device_memory.h +++ b/src/core/device_memory.h | |||
| @@ -4,14 +4,11 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/assert.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/common_funcs.h" | ||
| 9 | #include "common/virtual_buffer.h" | 8 | #include "common/virtual_buffer.h" |
| 10 | 9 | ||
| 11 | namespace Core { | 10 | namespace Core { |
| 12 | 11 | ||
| 13 | class System; | ||
| 14 | |||
| 15 | namespace DramMemoryMap { | 12 | namespace DramMemoryMap { |
| 16 | enum : u64 { | 13 | enum : u64 { |
| 17 | Base = 0x80000000ULL, | 14 | Base = 0x80000000ULL, |
| @@ -26,7 +23,7 @@ enum : u64 { | |||
| 26 | 23 | ||
| 27 | class DeviceMemory : NonCopyable { | 24 | class DeviceMemory : NonCopyable { |
| 28 | public: | 25 | public: |
| 29 | explicit DeviceMemory(Core::System& system); | 26 | explicit DeviceMemory(); |
| 30 | ~DeviceMemory(); | 27 | ~DeviceMemory(); |
| 31 | 28 | ||
| 32 | template <typename T> | 29 | template <typename T> |
| @@ -45,7 +42,6 @@ public: | |||
| 45 | 42 | ||
| 46 | private: | 43 | private: |
| 47 | Common::VirtualBuffer<u8> buffer; | 44 | Common::VirtualBuffer<u8> buffer; |
| 48 | Core::System& system; | ||
| 49 | }; | 45 | }; |
| 50 | 46 | ||
| 51 | } // namespace Core | 47 | } // namespace Core |
diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index 473245d5a..5039341c7 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp | |||
| @@ -495,9 +495,10 @@ VirtualFile NCA::Decrypt(const NCASectionHeader& s_header, VirtualFile in, u64 s | |||
| 495 | 495 | ||
| 496 | auto out = std::make_shared<Core::Crypto::CTREncryptionLayer>(std::move(in), *key, | 496 | auto out = std::make_shared<Core::Crypto::CTREncryptionLayer>(std::move(in), *key, |
| 497 | starting_offset); | 497 | starting_offset); |
| 498 | std::vector<u8> iv(16); | 498 | Core::Crypto::CTREncryptionLayer::IVData iv{}; |
| 499 | for (u8 i = 0; i < 8; ++i) | 499 | for (std::size_t i = 0; i < 8; ++i) { |
| 500 | iv[i] = s_header.raw.section_ctr[0x8 - i - 1]; | 500 | iv[i] = s_header.raw.section_ctr[8 - i - 1]; |
| 501 | } | ||
| 501 | out->SetIV(iv); | 502 | out->SetIV(iv); |
| 502 | return std::static_pointer_cast<VfsFile>(out); | 503 | return std::static_pointer_cast<VfsFile>(out); |
| 503 | } | 504 | } |
diff --git a/src/core/file_sys/mode.h b/src/core/file_sys/mode.h index c95205668..2b4f21073 100644 --- a/src/core/file_sys/mode.h +++ b/src/core/file_sys/mode.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_funcs.h" | ||
| 7 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 8 | 9 | ||
| 9 | namespace FileSys { | 10 | namespace FileSys { |
| @@ -11,13 +12,11 @@ namespace FileSys { | |||
| 11 | enum class Mode : u32 { | 12 | enum class Mode : u32 { |
| 12 | Read = 1, | 13 | Read = 1, |
| 13 | Write = 2, | 14 | Write = 2, |
| 14 | ReadWrite = 3, | 15 | ReadWrite = Read | Write, |
| 15 | Append = 4, | 16 | Append = 4, |
| 16 | WriteAppend = 6, | 17 | WriteAppend = Write | Append, |
| 17 | }; | 18 | }; |
| 18 | 19 | ||
| 19 | inline u32 operator&(Mode lhs, Mode rhs) { | 20 | DECLARE_ENUM_FLAG_OPERATORS(Mode) |
| 20 | return static_cast<u32>(lhs) & static_cast<u32>(rhs); | ||
| 21 | } | ||
| 22 | 21 | ||
| 23 | } // namespace FileSys | 22 | } // namespace FileSys |
diff --git a/src/core/file_sys/nca_patch.cpp b/src/core/file_sys/nca_patch.cpp index 0090cc6c4..fe7375e84 100644 --- a/src/core/file_sys/nca_patch.cpp +++ b/src/core/file_sys/nca_patch.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | ||
| 6 | #include <cstddef> | 7 | #include <cstddef> |
| 7 | #include <cstring> | 8 | #include <cstring> |
| 8 | 9 | ||
| @@ -66,7 +67,7 @@ std::size_t BKTR::Read(u8* data, std::size_t length, std::size_t offset) const { | |||
| 66 | Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(key, Core::Crypto::Mode::CTR); | 67 | Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(key, Core::Crypto::Mode::CTR); |
| 67 | 68 | ||
| 68 | // Calculate AES IV | 69 | // Calculate AES IV |
| 69 | std::vector<u8> iv(16); | 70 | std::array<u8, 16> iv{}; |
| 70 | auto subsection_ctr = subsection.ctr; | 71 | auto subsection_ctr = subsection.ctr; |
| 71 | auto offset_iv = section_offset + base_offset; | 72 | auto offset_iv = section_offset + base_offset; |
| 72 | for (std::size_t i = 0; i < section_ctr.size(); ++i) | 73 | for (std::size_t i = 0; i < section_ctr.size(); ++i) |
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index c47ff863e..729dbb5f4 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -288,8 +288,8 @@ std::optional<std::vector<Core::Memory::CheatEntry>> ReadCheatFileFromFolder( | |||
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | Core::Memory::TextCheatParser parser; | 290 | Core::Memory::TextCheatParser parser; |
| 291 | return parser.Parse( | 291 | return parser.Parse(system, |
| 292 | system, std::string_view(reinterpret_cast<const char* const>(data.data()), data.size())); | 292 | std::string_view(reinterpret_cast<const char*>(data.data()), data.size())); |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | } // Anonymous namespace | 295 | } // Anonymous namespace |
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index 37351c561..f831487dd 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp | |||
| @@ -344,15 +344,18 @@ VirtualFile RegisteredCache::GetFileAtID(NcaID id) const { | |||
| 344 | 344 | ||
| 345 | static std::optional<NcaID> CheckMapForContentRecord(const std::map<u64, CNMT>& map, u64 title_id, | 345 | static std::optional<NcaID> CheckMapForContentRecord(const std::map<u64, CNMT>& map, u64 title_id, |
| 346 | ContentRecordType type) { | 346 | ContentRecordType type) { |
| 347 | if (map.find(title_id) == map.end()) | 347 | const auto cmnt_iter = map.find(title_id); |
| 348 | return {}; | 348 | if (cmnt_iter == map.cend()) { |
| 349 | 349 | return std::nullopt; | |
| 350 | const auto& cnmt = map.at(title_id); | 350 | } |
| 351 | 351 | ||
| 352 | const auto iter = std::find_if(cnmt.GetContentRecords().begin(), cnmt.GetContentRecords().end(), | 352 | const auto& cnmt = cmnt_iter->second; |
| 353 | const auto& content_records = cnmt.GetContentRecords(); | ||
| 354 | const auto iter = std::find_if(content_records.cbegin(), content_records.cend(), | ||
| 353 | [type](const ContentRecord& rec) { return rec.type == type; }); | 355 | [type](const ContentRecord& rec) { return rec.type == type; }); |
| 354 | if (iter == cnmt.GetContentRecords().end()) | 356 | if (iter == content_records.cend()) { |
| 355 | return {}; | 357 | return std::nullopt; |
| 358 | } | ||
| 356 | 359 | ||
| 357 | return std::make_optional(iter->nca_id); | 360 | return std::make_optional(iter->nca_id); |
| 358 | } | 361 | } |
| @@ -467,14 +470,16 @@ VirtualFile RegisteredCache::GetEntryUnparsed(u64 title_id, ContentRecordType ty | |||
| 467 | 470 | ||
| 468 | std::optional<u32> RegisteredCache::GetEntryVersion(u64 title_id) const { | 471 | std::optional<u32> RegisteredCache::GetEntryVersion(u64 title_id) const { |
| 469 | const auto meta_iter = meta.find(title_id); | 472 | const auto meta_iter = meta.find(title_id); |
| 470 | if (meta_iter != meta.end()) | 473 | if (meta_iter != meta.cend()) { |
| 471 | return meta_iter->second.GetTitleVersion(); | 474 | return meta_iter->second.GetTitleVersion(); |
| 475 | } | ||
| 472 | 476 | ||
| 473 | const auto yuzu_meta_iter = yuzu_meta.find(title_id); | 477 | const auto yuzu_meta_iter = yuzu_meta.find(title_id); |
| 474 | if (yuzu_meta_iter != yuzu_meta.end()) | 478 | if (yuzu_meta_iter != yuzu_meta.cend()) { |
| 475 | return yuzu_meta_iter->second.GetTitleVersion(); | 479 | return yuzu_meta_iter->second.GetTitleVersion(); |
| 480 | } | ||
| 476 | 481 | ||
| 477 | return {}; | 482 | return std::nullopt; |
| 478 | } | 483 | } |
| 479 | 484 | ||
| 480 | VirtualFile RegisteredCache::GetEntryRaw(u64 title_id, ContentRecordType type) const { | 485 | VirtualFile RegisteredCache::GetEntryRaw(u64 title_id, ContentRecordType type) const { |
| @@ -547,56 +552,6 @@ InstallResult RegisteredCache::InstallEntry(const XCI& xci, bool overwrite_if_ex | |||
| 547 | return InstallEntry(*xci.GetSecurePartitionNSP(), overwrite_if_exists, copy); | 552 | return InstallEntry(*xci.GetSecurePartitionNSP(), overwrite_if_exists, copy); |
| 548 | } | 553 | } |
| 549 | 554 | ||
| 550 | bool RegisteredCache::RemoveExistingEntry(u64 title_id) { | ||
| 551 | const auto delete_nca = [this](const NcaID& id) { | ||
| 552 | const auto path = GetRelativePathFromNcaID(id, false, true, false); | ||
| 553 | |||
| 554 | if (dir->GetFileRelative(path) == nullptr) { | ||
| 555 | return false; | ||
| 556 | } | ||
| 557 | |||
| 558 | Core::Crypto::SHA256Hash hash{}; | ||
| 559 | mbedtls_sha256_ret(id.data(), id.size(), hash.data(), 0); | ||
| 560 | const auto dirname = fmt::format("000000{:02X}", hash[0]); | ||
| 561 | |||
| 562 | const auto dir2 = GetOrCreateDirectoryRelative(dir, dirname); | ||
| 563 | |||
| 564 | const auto res = dir2->DeleteFile(fmt::format("{}.nca", Common::HexToString(id, false))); | ||
| 565 | |||
| 566 | return res; | ||
| 567 | }; | ||
| 568 | |||
| 569 | // If an entry exists in the registered cache, remove it | ||
| 570 | if (HasEntry(title_id, ContentRecordType::Meta)) { | ||
| 571 | LOG_INFO(Loader, | ||
| 572 | "Previously installed entry (v{}) for title_id={:016X} detected! " | ||
| 573 | "Attempting to remove...", | ||
| 574 | GetEntryVersion(title_id).value_or(0), title_id); | ||
| 575 | // Get all the ncas associated with the current CNMT and delete them | ||
| 576 | const auto meta_old_id = | ||
| 577 | GetNcaIDFromMetadata(title_id, ContentRecordType::Meta).value_or(NcaID{}); | ||
| 578 | const auto program_id = | ||
| 579 | GetNcaIDFromMetadata(title_id, ContentRecordType::Program).value_or(NcaID{}); | ||
| 580 | const auto data_id = | ||
| 581 | GetNcaIDFromMetadata(title_id, ContentRecordType::Data).value_or(NcaID{}); | ||
| 582 | const auto control_id = | ||
| 583 | GetNcaIDFromMetadata(title_id, ContentRecordType::Control).value_or(NcaID{}); | ||
| 584 | const auto html_id = | ||
| 585 | GetNcaIDFromMetadata(title_id, ContentRecordType::HtmlDocument).value_or(NcaID{}); | ||
| 586 | const auto legal_id = | ||
| 587 | GetNcaIDFromMetadata(title_id, ContentRecordType::LegalInformation).value_or(NcaID{}); | ||
| 588 | |||
| 589 | delete_nca(meta_old_id); | ||
| 590 | delete_nca(program_id); | ||
| 591 | delete_nca(data_id); | ||
| 592 | delete_nca(control_id); | ||
| 593 | delete_nca(html_id); | ||
| 594 | delete_nca(legal_id); | ||
| 595 | return true; | ||
| 596 | } | ||
| 597 | return false; | ||
| 598 | } | ||
| 599 | |||
| 600 | InstallResult RegisteredCache::InstallEntry(const NSP& nsp, bool overwrite_if_exists, | 555 | InstallResult RegisteredCache::InstallEntry(const NSP& nsp, bool overwrite_if_exists, |
| 601 | const VfsCopyFunction& copy) { | 556 | const VfsCopyFunction& copy) { |
| 602 | const auto ncas = nsp.GetNCAsCollapsed(); | 557 | const auto ncas = nsp.GetNCAsCollapsed(); |
| @@ -692,6 +647,57 @@ InstallResult RegisteredCache::InstallEntry(const NCA& nca, TitleType type, | |||
| 692 | return RawInstallNCA(nca, copy, overwrite_if_exists, c_rec.nca_id); | 647 | return RawInstallNCA(nca, copy, overwrite_if_exists, c_rec.nca_id); |
| 693 | } | 648 | } |
| 694 | 649 | ||
| 650 | bool RegisteredCache::RemoveExistingEntry(u64 title_id) const { | ||
| 651 | const auto delete_nca = [this](const NcaID& id) { | ||
| 652 | const auto path = GetRelativePathFromNcaID(id, false, true, false); | ||
| 653 | |||
| 654 | const bool isFile = dir->GetFileRelative(path) != nullptr; | ||
| 655 | const bool isDir = dir->GetDirectoryRelative(path) != nullptr; | ||
| 656 | |||
| 657 | if (isFile) { | ||
| 658 | return dir->DeleteFile(path); | ||
| 659 | } else if (isDir) { | ||
| 660 | return dir->DeleteSubdirectoryRecursive(path); | ||
| 661 | } | ||
| 662 | |||
| 663 | return false; | ||
| 664 | }; | ||
| 665 | |||
| 666 | // If an entry exists in the registered cache, remove it | ||
| 667 | if (HasEntry(title_id, ContentRecordType::Meta)) { | ||
| 668 | LOG_INFO(Loader, | ||
| 669 | "Previously installed entry (v{}) for title_id={:016X} detected! " | ||
| 670 | "Attempting to remove...", | ||
| 671 | GetEntryVersion(title_id).value_or(0), title_id); | ||
| 672 | |||
| 673 | // Get all the ncas associated with the current CNMT and delete them | ||
| 674 | const auto meta_old_id = | ||
| 675 | GetNcaIDFromMetadata(title_id, ContentRecordType::Meta).value_or(NcaID{}); | ||
| 676 | const auto program_id = | ||
| 677 | GetNcaIDFromMetadata(title_id, ContentRecordType::Program).value_or(NcaID{}); | ||
| 678 | const auto data_id = | ||
| 679 | GetNcaIDFromMetadata(title_id, ContentRecordType::Data).value_or(NcaID{}); | ||
| 680 | const auto control_id = | ||
| 681 | GetNcaIDFromMetadata(title_id, ContentRecordType::Control).value_or(NcaID{}); | ||
| 682 | const auto html_id = | ||
| 683 | GetNcaIDFromMetadata(title_id, ContentRecordType::HtmlDocument).value_or(NcaID{}); | ||
| 684 | const auto legal_id = | ||
| 685 | GetNcaIDFromMetadata(title_id, ContentRecordType::LegalInformation).value_or(NcaID{}); | ||
| 686 | |||
| 687 | const auto deleted_meta = delete_nca(meta_old_id); | ||
| 688 | const auto deleted_program = delete_nca(program_id); | ||
| 689 | const auto deleted_data = delete_nca(data_id); | ||
| 690 | const auto deleted_control = delete_nca(control_id); | ||
| 691 | const auto deleted_html = delete_nca(html_id); | ||
| 692 | const auto deleted_legal = delete_nca(legal_id); | ||
| 693 | |||
| 694 | return deleted_meta && (deleted_meta || deleted_program || deleted_data || | ||
| 695 | deleted_control || deleted_html || deleted_legal); | ||
| 696 | } | ||
| 697 | |||
| 698 | return false; | ||
| 699 | } | ||
| 700 | |||
| 695 | InstallResult RegisteredCache::RawInstallNCA(const NCA& nca, const VfsCopyFunction& copy, | 701 | InstallResult RegisteredCache::RawInstallNCA(const NCA& nca, const VfsCopyFunction& copy, |
| 696 | bool overwrite_if_exists, | 702 | bool overwrite_if_exists, |
| 697 | std::optional<NcaID> override_id) { | 703 | std::optional<NcaID> override_id) { |
diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h index 29cf0d40c..ec1d54f27 100644 --- a/src/core/file_sys/registered_cache.h +++ b/src/core/file_sys/registered_cache.h | |||
| @@ -155,9 +155,6 @@ public: | |||
| 155 | std::optional<TitleType> title_type = {}, std::optional<ContentRecordType> record_type = {}, | 155 | std::optional<TitleType> title_type = {}, std::optional<ContentRecordType> record_type = {}, |
| 156 | std::optional<u64> title_id = {}) const override; | 156 | std::optional<u64> title_id = {}) const override; |
| 157 | 157 | ||
| 158 | // Removes an existing entry based on title id | ||
| 159 | bool RemoveExistingEntry(u64 title_id); | ||
| 160 | |||
| 161 | // Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure | 158 | // Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure |
| 162 | // there is a meta NCA and all of them are accessible. | 159 | // there is a meta NCA and all of them are accessible. |
| 163 | InstallResult InstallEntry(const XCI& xci, bool overwrite_if_exists = false, | 160 | InstallResult InstallEntry(const XCI& xci, bool overwrite_if_exists = false, |
| @@ -172,6 +169,9 @@ public: | |||
| 172 | InstallResult InstallEntry(const NCA& nca, TitleType type, bool overwrite_if_exists = false, | 169 | InstallResult InstallEntry(const NCA& nca, TitleType type, bool overwrite_if_exists = false, |
| 173 | const VfsCopyFunction& copy = &VfsRawCopy); | 170 | const VfsCopyFunction& copy = &VfsRawCopy); |
| 174 | 171 | ||
| 172 | // Removes an existing entry based on title id | ||
| 173 | bool RemoveExistingEntry(u64 title_id) const; | ||
| 174 | |||
| 175 | private: | 175 | private: |
| 176 | template <typename T> | 176 | template <typename T> |
| 177 | void IterateAllMetadata(std::vector<T>& out, | 177 | void IterateAllMetadata(std::vector<T>& out, |
diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index adfd2c1a4..ba4efee3a 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp | |||
| @@ -17,23 +17,23 @@ constexpr char SAVE_DATA_SIZE_FILENAME[] = ".yuzu_save_size"; | |||
| 17 | 17 | ||
| 18 | namespace { | 18 | namespace { |
| 19 | 19 | ||
| 20 | void PrintSaveDataDescriptorWarnings(SaveDataDescriptor meta) { | 20 | void PrintSaveDataAttributeWarnings(SaveDataAttribute meta) { |
| 21 | if (meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData) { | 21 | if (meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData) { |
| 22 | if (meta.zero_1 != 0) { | 22 | if (meta.zero_1 != 0) { |
| 23 | LOG_WARNING(Service_FS, | 23 | LOG_WARNING(Service_FS, |
| 24 | "Possibly incorrect SaveDataDescriptor, type is " | 24 | "Possibly incorrect SaveDataAttribute, type is " |
| 25 | "SystemSaveData||SaveData but offset 0x28 is non-zero ({:016X}).", | 25 | "SystemSaveData||SaveData but offset 0x28 is non-zero ({:016X}).", |
| 26 | meta.zero_1); | 26 | meta.zero_1); |
| 27 | } | 27 | } |
| 28 | if (meta.zero_2 != 0) { | 28 | if (meta.zero_2 != 0) { |
| 29 | LOG_WARNING(Service_FS, | 29 | LOG_WARNING(Service_FS, |
| 30 | "Possibly incorrect SaveDataDescriptor, type is " | 30 | "Possibly incorrect SaveDataAttribute, type is " |
| 31 | "SystemSaveData||SaveData but offset 0x30 is non-zero ({:016X}).", | 31 | "SystemSaveData||SaveData but offset 0x30 is non-zero ({:016X}).", |
| 32 | meta.zero_2); | 32 | meta.zero_2); |
| 33 | } | 33 | } |
| 34 | if (meta.zero_3 != 0) { | 34 | if (meta.zero_3 != 0) { |
| 35 | LOG_WARNING(Service_FS, | 35 | LOG_WARNING(Service_FS, |
| 36 | "Possibly incorrect SaveDataDescriptor, type is " | 36 | "Possibly incorrect SaveDataAttribute, type is " |
| 37 | "SystemSaveData||SaveData but offset 0x38 is non-zero ({:016X}).", | 37 | "SystemSaveData||SaveData but offset 0x38 is non-zero ({:016X}).", |
| 38 | meta.zero_3); | 38 | meta.zero_3); |
| 39 | } | 39 | } |
| @@ -41,33 +41,32 @@ void PrintSaveDataDescriptorWarnings(SaveDataDescriptor meta) { | |||
| 41 | 41 | ||
| 42 | if (meta.type == SaveDataType::SystemSaveData && meta.title_id != 0) { | 42 | if (meta.type == SaveDataType::SystemSaveData && meta.title_id != 0) { |
| 43 | LOG_WARNING(Service_FS, | 43 | LOG_WARNING(Service_FS, |
| 44 | "Possibly incorrect SaveDataDescriptor, type is SystemSaveData but title_id is " | 44 | "Possibly incorrect SaveDataAttribute, type is SystemSaveData but title_id is " |
| 45 | "non-zero ({:016X}).", | 45 | "non-zero ({:016X}).", |
| 46 | meta.title_id); | 46 | meta.title_id); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | if (meta.type == SaveDataType::DeviceSaveData && meta.user_id != u128{0, 0}) { | 49 | if (meta.type == SaveDataType::DeviceSaveData && meta.user_id != u128{0, 0}) { |
| 50 | LOG_WARNING(Service_FS, | 50 | LOG_WARNING(Service_FS, |
| 51 | "Possibly incorrect SaveDataDescriptor, type is DeviceSaveData but user_id is " | 51 | "Possibly incorrect SaveDataAttribute, type is DeviceSaveData but user_id is " |
| 52 | "non-zero ({:016X}{:016X})", | 52 | "non-zero ({:016X}{:016X})", |
| 53 | meta.user_id[1], meta.user_id[0]); | 53 | meta.user_id[1], meta.user_id[0]); |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | bool ShouldSaveDataBeAutomaticallyCreated(SaveDataSpaceId space, const SaveDataDescriptor& desc) { | 57 | bool ShouldSaveDataBeAutomaticallyCreated(SaveDataSpaceId space, const SaveDataAttribute& attr) { |
| 58 | return desc.type == SaveDataType::CacheStorage || desc.type == SaveDataType::TemporaryStorage || | 58 | return attr.type == SaveDataType::CacheStorage || attr.type == SaveDataType::TemporaryStorage || |
| 59 | (space == SaveDataSpaceId::NandUser && ///< Normal Save Data -- Current Title & User | 59 | (space == SaveDataSpaceId::NandUser && ///< Normal Save Data -- Current Title & User |
| 60 | (desc.type == SaveDataType::SaveData || desc.type == SaveDataType::DeviceSaveData) && | 60 | (attr.type == SaveDataType::SaveData || attr.type == SaveDataType::DeviceSaveData) && |
| 61 | desc.title_id == 0 && desc.save_id == 0); | 61 | attr.title_id == 0 && attr.save_id == 0); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | } // Anonymous namespace | 64 | } // Anonymous namespace |
| 65 | 65 | ||
| 66 | std::string SaveDataDescriptor::DebugInfo() const { | 66 | std::string SaveDataAttribute::DebugInfo() const { |
| 67 | return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, " | 67 | return fmt::format("[title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}, type={:02X}, " |
| 68 | "save_id={:016X}, " | ||
| 69 | "rank={}, index={}]", | 68 | "rank={}, index={}]", |
| 70 | static_cast<u8>(type), title_id, user_id[1], user_id[0], save_id, | 69 | title_id, user_id[1], user_id[0], save_id, static_cast<u8>(type), |
| 71 | static_cast<u8>(rank), index); | 70 | static_cast<u8>(rank), index); |
| 72 | } | 71 | } |
| 73 | 72 | ||
| @@ -80,8 +79,8 @@ SaveDataFactory::SaveDataFactory(VirtualDir save_directory) : dir(std::move(save | |||
| 80 | SaveDataFactory::~SaveDataFactory() = default; | 79 | SaveDataFactory::~SaveDataFactory() = default; |
| 81 | 80 | ||
| 82 | ResultVal<VirtualDir> SaveDataFactory::Create(SaveDataSpaceId space, | 81 | ResultVal<VirtualDir> SaveDataFactory::Create(SaveDataSpaceId space, |
| 83 | const SaveDataDescriptor& meta) const { | 82 | const SaveDataAttribute& meta) const { |
| 84 | PrintSaveDataDescriptorWarnings(meta); | 83 | PrintSaveDataAttributeWarnings(meta); |
| 85 | 84 | ||
| 86 | const auto save_directory = | 85 | const auto save_directory = |
| 87 | GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); | 86 | GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); |
| @@ -98,7 +97,7 @@ ResultVal<VirtualDir> SaveDataFactory::Create(SaveDataSpaceId space, | |||
| 98 | } | 97 | } |
| 99 | 98 | ||
| 100 | ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space, | 99 | ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space, |
| 101 | const SaveDataDescriptor& meta) const { | 100 | const SaveDataAttribute& meta) const { |
| 102 | 101 | ||
| 103 | const auto save_directory = | 102 | const auto save_directory = |
| 104 | GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); | 103 | GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); |
diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h index 991e57aa1..6625bbbd8 100644 --- a/src/core/file_sys/savedata_factory.h +++ b/src/core/file_sys/savedata_factory.h | |||
| @@ -21,6 +21,7 @@ enum class SaveDataSpaceId : u8 { | |||
| 21 | TemporaryStorage = 3, | 21 | TemporaryStorage = 3, |
| 22 | SdCardUser = 4, | 22 | SdCardUser = 4, |
| 23 | ProperSystem = 100, | 23 | ProperSystem = 100, |
| 24 | SafeMode = 101, | ||
| 24 | }; | 25 | }; |
| 25 | 26 | ||
| 26 | enum class SaveDataType : u8 { | 27 | enum class SaveDataType : u8 { |
| @@ -30,28 +31,50 @@ enum class SaveDataType : u8 { | |||
| 30 | DeviceSaveData = 3, | 31 | DeviceSaveData = 3, |
| 31 | TemporaryStorage = 4, | 32 | TemporaryStorage = 4, |
| 32 | CacheStorage = 5, | 33 | CacheStorage = 5, |
| 34 | SystemBcat = 6, | ||
| 33 | }; | 35 | }; |
| 34 | 36 | ||
| 35 | enum class SaveDataRank : u8 { | 37 | enum class SaveDataRank : u8 { |
| 36 | Primary, | 38 | Primary = 0, |
| 37 | Secondary, | 39 | Secondary = 1, |
| 38 | }; | 40 | }; |
| 39 | 41 | ||
| 40 | struct SaveDataDescriptor { | 42 | enum class SaveDataFlags : u32 { |
| 41 | u64_le title_id; | 43 | None = (0 << 0), |
| 44 | KeepAfterResettingSystemSaveData = (1 << 0), | ||
| 45 | KeepAfterRefurbishment = (1 << 1), | ||
| 46 | KeepAfterResettingSystemSaveDataWithoutUserSaveData = (1 << 2), | ||
| 47 | NeedsSecureDelete = (1 << 3), | ||
| 48 | }; | ||
| 49 | |||
| 50 | struct SaveDataAttribute { | ||
| 51 | u64 title_id; | ||
| 42 | u128 user_id; | 52 | u128 user_id; |
| 43 | u64_le save_id; | 53 | u64 save_id; |
| 44 | SaveDataType type; | 54 | SaveDataType type; |
| 45 | SaveDataRank rank; | 55 | SaveDataRank rank; |
| 46 | u16_le index; | 56 | u16 index; |
| 47 | INSERT_PADDING_BYTES(4); | 57 | INSERT_PADDING_BYTES(4); |
| 48 | u64_le zero_1; | 58 | u64 zero_1; |
| 49 | u64_le zero_2; | 59 | u64 zero_2; |
| 50 | u64_le zero_3; | 60 | u64 zero_3; |
| 51 | 61 | ||
| 52 | std::string DebugInfo() const; | 62 | std::string DebugInfo() const; |
| 53 | }; | 63 | }; |
| 54 | static_assert(sizeof(SaveDataDescriptor) == 0x40, "SaveDataDescriptor has incorrect size."); | 64 | static_assert(sizeof(SaveDataAttribute) == 0x40, "SaveDataAttribute has incorrect size."); |
| 65 | |||
| 66 | struct SaveDataExtraData { | ||
| 67 | SaveDataAttribute attr; | ||
| 68 | u64 owner_id; | ||
| 69 | s64 timestamp; | ||
| 70 | SaveDataFlags flags; | ||
| 71 | INSERT_PADDING_BYTES(4); | ||
| 72 | s64 available_size; | ||
| 73 | s64 journal_size; | ||
| 74 | s64 commit_id; | ||
| 75 | std::array<u8, 0x190> unused; | ||
| 76 | }; | ||
| 77 | static_assert(sizeof(SaveDataExtraData) == 0x200, "SaveDataExtraData has incorrect size."); | ||
| 55 | 78 | ||
| 56 | struct SaveDataSize { | 79 | struct SaveDataSize { |
| 57 | u64 normal; | 80 | u64 normal; |
| @@ -64,8 +87,8 @@ public: | |||
| 64 | explicit SaveDataFactory(VirtualDir dir); | 87 | explicit SaveDataFactory(VirtualDir dir); |
| 65 | ~SaveDataFactory(); | 88 | ~SaveDataFactory(); |
| 66 | 89 | ||
| 67 | ResultVal<VirtualDir> Create(SaveDataSpaceId space, const SaveDataDescriptor& meta) const; | 90 | ResultVal<VirtualDir> Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const; |
| 68 | ResultVal<VirtualDir> Open(SaveDataSpaceId space, const SaveDataDescriptor& meta) const; | 91 | ResultVal<VirtualDir> Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const; |
| 69 | 92 | ||
| 70 | VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const; | 93 | VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const; |
| 71 | 94 | ||
diff --git a/src/core/file_sys/system_archive/time_zone_binary.cpp b/src/core/file_sys/system_archive/time_zone_binary.cpp index 9806bd197..d1de63f20 100644 --- a/src/core/file_sys/system_archive/time_zone_binary.cpp +++ b/src/core/file_sys/system_archive/time_zone_binary.cpp | |||
| @@ -2,6 +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 <array> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 5 | #include "common/swap.h" | 8 | #include "common/swap.h" |
| 6 | #include "core/file_sys/system_archive/time_zone_binary.h" | 9 | #include "core/file_sys/system_archive/time_zone_binary.h" |
| 7 | #include "core/file_sys/vfs_vector.h" | 10 | #include "core/file_sys/vfs_vector.h" |
| @@ -615,31 +618,36 @@ static constexpr std::array<u8, 9633> LOCATION_NAMES{ | |||
| 615 | 0x0a}; | 618 | 0x0a}; |
| 616 | 619 | ||
| 617 | static VirtualFile GenerateDefaultTimeZoneFile() { | 620 | static VirtualFile GenerateDefaultTimeZoneFile() { |
| 618 | struct { | 621 | struct TimeZoneInfo { |
| 619 | s64_be at; | 622 | s64_be at; |
| 620 | INSERT_PADDING_BYTES(7); | 623 | std::array<u8, 7> padding1; |
| 621 | std::array<char, 4> time_zone_chars; | 624 | std::array<char, 4> time_zone_chars; |
| 622 | INSERT_PADDING_BYTES(2); | 625 | std::array<u8, 2> padding2; |
| 623 | std::array<char, 6> time_zone_name; | 626 | std::array<char, 6> time_zone_name; |
| 624 | } time_zone_info{}; | 627 | }; |
| 625 | 628 | ||
| 626 | const VirtualFile file{std::make_shared<VectorVfsFile>( | 629 | VirtualFile file{std::make_shared<VectorVfsFile>( |
| 627 | std::vector<u8>(sizeof(Service::Time::TimeZone::TzifHeader) + sizeof(time_zone_info)), | 630 | std::vector<u8>(sizeof(Service::Time::TimeZone::TzifHeader) + sizeof(TimeZoneInfo)), |
| 628 | "GMT")}; | 631 | "GMT")}; |
| 629 | 632 | ||
| 630 | Service::Time::TimeZone::TzifHeader header{}; | 633 | const Service::Time::TimeZone::TzifHeader header{ |
| 631 | header.magic = 0x545a6966; | 634 | .magic = 0x545a6966, |
| 632 | header.version = 0x32; | 635 | .version = 0x32, |
| 633 | header.ttis_gmt_count = 0x1; | 636 | .ttis_gmt_count = 1, |
| 634 | header.ttis_std_count = 0x1; | 637 | .ttis_std_count = 1, |
| 635 | header.time_count = 0x1; | 638 | .time_count = 1, |
| 636 | header.type_count = 0x1; | 639 | .type_count = 1, |
| 637 | header.char_count = 0x4; | 640 | .char_count = 4, |
| 641 | }; | ||
| 638 | file->WriteObject(header, 0); | 642 | file->WriteObject(header, 0); |
| 639 | 643 | ||
| 640 | time_zone_info.at = 0xf8; | 644 | const TimeZoneInfo time_zone_info{ |
| 641 | time_zone_info.time_zone_chars = {'G', 'M', 'T', '\0'}; | 645 | .at = 0xf8, |
| 642 | time_zone_info.time_zone_name = {'\n', 'G', 'M', 'T', '0', '\n'}; | 646 | .padding1 = {}, |
| 647 | .time_zone_chars = {'G', 'M', 'T', '\0'}, | ||
| 648 | .padding2 = {}, | ||
| 649 | .time_zone_name = {'\n', 'G', 'M', 'T', '0', '\n'}, | ||
| 650 | }; | ||
| 643 | file->WriteObject(time_zone_info, sizeof(Service::Time::TimeZone::TzifHeader)); | 651 | file->WriteObject(time_zone_info, sizeof(Service::Time::TimeZone::TzifHeader)); |
| 644 | 652 | ||
| 645 | return file; | 653 | return file; |
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 96ce5957c..0db0091f6 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp | |||
| @@ -18,20 +18,22 @@ static std::string ModeFlagsToString(Mode mode) { | |||
| 18 | std::string mode_str; | 18 | std::string mode_str; |
| 19 | 19 | ||
| 20 | // Calculate the correct open mode for the file. | 20 | // Calculate the correct open mode for the file. |
| 21 | if (mode & Mode::Read && mode & Mode::Write) { | 21 | if (True(mode & Mode::Read) && True(mode & Mode::Write)) { |
| 22 | if (mode & Mode::Append) | 22 | if (True(mode & Mode::Append)) { |
| 23 | mode_str = "a+"; | 23 | mode_str = "a+"; |
| 24 | else | 24 | } else { |
| 25 | mode_str = "r+"; | 25 | mode_str = "r+"; |
| 26 | } | ||
| 26 | } else { | 27 | } else { |
| 27 | if (mode & Mode::Read) | 28 | if (True(mode & Mode::Read)) { |
| 28 | mode_str = "r"; | 29 | mode_str = "r"; |
| 29 | else if (mode & Mode::Append) | 30 | } else if (True(mode & Mode::Append)) { |
| 30 | mode_str = "a"; | 31 | mode_str = "a"; |
| 31 | else if (mode & Mode::Write) | 32 | } else if (True(mode & Mode::Write)) { |
| 32 | mode_str = "w"; | 33 | mode_str = "w"; |
| 33 | else | 34 | } else { |
| 34 | UNREACHABLE_MSG("Invalid file open mode: {:02X}", static_cast<u8>(mode)); | 35 | UNREACHABLE_MSG("Invalid file open mode: {:02X}", static_cast<u8>(mode)); |
| 36 | } | ||
| 35 | } | 37 | } |
| 36 | 38 | ||
| 37 | mode_str += "b"; | 39 | mode_str += "b"; |
| @@ -73,8 +75,9 @@ VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { | |||
| 73 | } | 75 | } |
| 74 | } | 76 | } |
| 75 | 77 | ||
| 76 | if (!FileUtil::Exists(path) && (perms & Mode::WriteAppend) != 0) | 78 | if (!FileUtil::Exists(path) && True(perms & Mode::WriteAppend)) { |
| 77 | FileUtil::CreateEmptyFile(path); | 79 | FileUtil::CreateEmptyFile(path); |
| 80 | } | ||
| 78 | 81 | ||
| 79 | auto backing = std::make_shared<FileUtil::IOFile>(path, ModeFlagsToString(perms).c_str()); | 82 | auto backing = std::make_shared<FileUtil::IOFile>(path, ModeFlagsToString(perms).c_str()); |
| 80 | cache[path] = backing; | 83 | cache[path] = backing; |
| @@ -247,11 +250,11 @@ std::shared_ptr<VfsDirectory> RealVfsFile::GetContainingDirectory() const { | |||
| 247 | } | 250 | } |
| 248 | 251 | ||
| 249 | bool RealVfsFile::IsWritable() const { | 252 | bool RealVfsFile::IsWritable() const { |
| 250 | return (perms & Mode::WriteAppend) != 0; | 253 | return True(perms & Mode::WriteAppend); |
| 251 | } | 254 | } |
| 252 | 255 | ||
| 253 | bool RealVfsFile::IsReadable() const { | 256 | bool RealVfsFile::IsReadable() const { |
| 254 | return (perms & Mode::ReadWrite) != 0; | 257 | return True(perms & Mode::ReadWrite); |
| 255 | } | 258 | } |
| 256 | 259 | ||
| 257 | std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const { | 260 | std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const { |
| @@ -319,8 +322,9 @@ RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& | |||
| 319 | path_components(FileUtil::SplitPathComponents(path)), | 322 | path_components(FileUtil::SplitPathComponents(path)), |
| 320 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), | 323 | parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), |
| 321 | perms(perms_) { | 324 | perms(perms_) { |
| 322 | if (!FileUtil::Exists(path) && perms & Mode::WriteAppend) | 325 | if (!FileUtil::Exists(path) && True(perms & Mode::WriteAppend)) { |
| 323 | FileUtil::CreateDir(path); | 326 | FileUtil::CreateDir(path); |
| 327 | } | ||
| 324 | } | 328 | } |
| 325 | 329 | ||
| 326 | RealVfsDirectory::~RealVfsDirectory() = default; | 330 | RealVfsDirectory::~RealVfsDirectory() = default; |
| @@ -371,11 +375,11 @@ std::vector<std::shared_ptr<VfsDirectory>> RealVfsDirectory::GetSubdirectories() | |||
| 371 | } | 375 | } |
| 372 | 376 | ||
| 373 | bool RealVfsDirectory::IsWritable() const { | 377 | bool RealVfsDirectory::IsWritable() const { |
| 374 | return (perms & Mode::WriteAppend) != 0; | 378 | return True(perms & Mode::WriteAppend); |
| 375 | } | 379 | } |
| 376 | 380 | ||
| 377 | bool RealVfsDirectory::IsReadable() const { | 381 | bool RealVfsDirectory::IsReadable() const { |
| 378 | return (perms & Mode::ReadWrite) != 0; | 382 | return True(perms & Mode::ReadWrite); |
| 379 | } | 383 | } |
| 380 | 384 | ||
| 381 | std::string RealVfsDirectory::GetName() const { | 385 | std::string RealVfsDirectory::GetName() const { |
diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp index 86e06ccb9..81413c684 100644 --- a/src/core/file_sys/xts_archive.cpp +++ b/src/core/file_sys/xts_archive.cpp | |||
| @@ -70,14 +70,18 @@ NAX::NAX(VirtualFile file_, std::array<u8, 0x10> nca_id) | |||
| 70 | NAX::~NAX() = default; | 70 | NAX::~NAX() = default; |
| 71 | 71 | ||
| 72 | Loader::ResultStatus NAX::Parse(std::string_view path) { | 72 | Loader::ResultStatus NAX::Parse(std::string_view path) { |
| 73 | if (file->ReadObject(header.get()) != sizeof(NAXHeader)) | 73 | if (file == nullptr) { |
| 74 | return Loader::ResultStatus::ErrorNullFile; | ||
| 75 | } | ||
| 76 | if (file->ReadObject(header.get()) != sizeof(NAXHeader)) { | ||
| 74 | return Loader::ResultStatus::ErrorBadNAXHeader; | 77 | return Loader::ResultStatus::ErrorBadNAXHeader; |
| 75 | 78 | } | |
| 76 | if (header->magic != Common::MakeMagic('N', 'A', 'X', '0')) | 79 | if (header->magic != Common::MakeMagic('N', 'A', 'X', '0')) { |
| 77 | return Loader::ResultStatus::ErrorBadNAXHeader; | 80 | return Loader::ResultStatus::ErrorBadNAXHeader; |
| 78 | 81 | } | |
| 79 | if (file->GetSize() < NAX_HEADER_PADDING_SIZE + header->file_size) | 82 | if (file->GetSize() < NAX_HEADER_PADDING_SIZE + header->file_size) { |
| 80 | return Loader::ResultStatus::ErrorIncorrectNAXFileSize; | 83 | return Loader::ResultStatus::ErrorIncorrectNAXFileSize; |
| 84 | } | ||
| 81 | 85 | ||
| 82 | keys.DeriveSDSeedLazy(); | 86 | keys.DeriveSDSeedLazy(); |
| 83 | std::array<Core::Crypto::Key256, 2> sd_keys{}; | 87 | std::array<Core::Crypto::Key256, 2> sd_keys{}; |
diff --git a/src/core/hardware_interrupt_manager.cpp b/src/core/hardware_interrupt_manager.cpp index efc1030c1..645f26e91 100644 --- a/src/core/hardware_interrupt_manager.cpp +++ b/src/core/hardware_interrupt_manager.cpp | |||
| @@ -11,8 +11,8 @@ | |||
| 11 | namespace Core::Hardware { | 11 | namespace Core::Hardware { |
| 12 | 12 | ||
| 13 | InterruptManager::InterruptManager(Core::System& system_in) : system(system_in) { | 13 | InterruptManager::InterruptManager(Core::System& system_in) : system(system_in) { |
| 14 | gpu_interrupt_event = | 14 | gpu_interrupt_event = Core::Timing::CreateEvent( |
| 15 | Core::Timing::CreateEvent("GPUInterrupt", [this](u64 message, std::chrono::nanoseconds) { | 15 | "GPUInterrupt", [this](std::uintptr_t message, std::chrono::nanoseconds) { |
| 16 | auto nvdrv = system.ServiceManager().GetService<Service::Nvidia::NVDRV>("nvdrv"); | 16 | auto nvdrv = system.ServiceManager().GetService<Service::Nvidia::NVDRV>("nvdrv"); |
| 17 | const u32 syncpt = static_cast<u32>(message >> 32); | 17 | const u32 syncpt = static_cast<u32>(message >> 32); |
| 18 | const u32 value = static_cast<u32>(message); | 18 | const u32 value = static_cast<u32>(message); |
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 0dc6a4a43..1b503331f 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h | |||
| @@ -229,6 +229,8 @@ inline void ResponseBuilder::Push(u32 value) { | |||
| 229 | 229 | ||
| 230 | template <typename T> | 230 | template <typename T> |
| 231 | void ResponseBuilder::PushRaw(const T& value) { | 231 | void ResponseBuilder::PushRaw(const T& value) { |
| 232 | static_assert(std::is_trivially_copyable_v<T>, | ||
| 233 | "It's undefined behavior to use memcpy with non-trivially copyable objects"); | ||
| 232 | std::memcpy(cmdbuf + index, &value, sizeof(T)); | 234 | std::memcpy(cmdbuf + index, &value, sizeof(T)); |
| 233 | index += (sizeof(T) + 3) / 4; // round up to word length | 235 | index += (sizeof(T) + 3) / 4; // round up to word length |
| 234 | } | 236 | } |
| @@ -384,6 +386,8 @@ inline s32 RequestParser::Pop() { | |||
| 384 | 386 | ||
| 385 | template <typename T> | 387 | template <typename T> |
| 386 | void RequestParser::PopRaw(T& value) { | 388 | void RequestParser::PopRaw(T& value) { |
| 389 | static_assert(std::is_trivially_copyable_v<T>, | ||
| 390 | "It's undefined behavior to use memcpy with non-trivially copyable objects"); | ||
| 387 | std::memcpy(&value, cmdbuf + index, sizeof(T)); | 391 | std::memcpy(&value, cmdbuf + index, sizeof(T)); |
| 388 | index += (sizeof(T) + 3) / 4; // round up to word length | 392 | index += (sizeof(T) + 3) / 4; // round up to word length |
| 389 | } | 393 | } |
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index df0debe1b..b882eaa0f 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp | |||
| @@ -81,7 +81,7 @@ ResultCode AddressArbiter::IncrementAndSignalToAddressIfEqual(VAddr address, s32 | |||
| 81 | do { | 81 | do { |
| 82 | current_value = monitor.ExclusiveRead32(current_core, address); | 82 | current_value = monitor.ExclusiveRead32(current_core, address); |
| 83 | 83 | ||
| 84 | if (current_value != value) { | 84 | if (current_value != static_cast<u32>(value)) { |
| 85 | return ERR_INVALID_STATE; | 85 | return ERR_INVALID_STATE; |
| 86 | } | 86 | } |
| 87 | current_value++; | 87 | current_value++; |
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index b31673928..f3277b766 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <vector> | 13 | #include <vector> |
| 14 | #include <boost/container/small_vector.hpp> | 14 | #include <boost/container/small_vector.hpp> |
| 15 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| 16 | #include "common/concepts.h" | ||
| 16 | #include "common/swap.h" | 17 | #include "common/swap.h" |
| 17 | #include "core/hle/ipc.h" | 18 | #include "core/hle/ipc.h" |
| 18 | #include "core/hle/kernel/object.h" | 19 | #include "core/hle/kernel/object.h" |
| @@ -193,23 +194,24 @@ public: | |||
| 193 | 194 | ||
| 194 | /* Helper function to write a buffer using the appropriate buffer descriptor | 195 | /* Helper function to write a buffer using the appropriate buffer descriptor |
| 195 | * | 196 | * |
| 196 | * @tparam ContiguousContainer an arbitrary container that satisfies the | 197 | * @tparam T an arbitrary container that satisfies the |
| 197 | * ContiguousContainer concept in the C++ standard library. | 198 | * ContiguousContainer concept in the C++ standard library or a trivially copyable type. |
| 198 | * | 199 | * |
| 199 | * @param container The container to write the data of into a buffer. | 200 | * @param data The container/data to write into a buffer. |
| 200 | * @param buffer_index The buffer in particular to write to. | 201 | * @param buffer_index The buffer in particular to write to. |
| 201 | */ | 202 | */ |
| 202 | template <typename ContiguousContainer, | 203 | template <typename T, typename = std::enable_if_t<!std::is_pointer_v<T>>> |
| 203 | typename = std::enable_if_t<!std::is_pointer_v<ContiguousContainer>>> | 204 | std::size_t WriteBuffer(const T& data, std::size_t buffer_index = 0) const { |
| 204 | std::size_t WriteBuffer(const ContiguousContainer& container, | 205 | if constexpr (Common::IsSTLContainer<T>) { |
| 205 | std::size_t buffer_index = 0) const { | 206 | using ContiguousType = typename T::value_type; |
| 206 | using ContiguousType = typename ContiguousContainer::value_type; | 207 | static_assert(std::is_trivially_copyable_v<ContiguousType>, |
| 207 | 208 | "Container to WriteBuffer must contain trivially copyable objects"); | |
| 208 | static_assert(std::is_trivially_copyable_v<ContiguousType>, | 209 | return WriteBuffer(std::data(data), std::size(data) * sizeof(ContiguousType), |
| 209 | "Container to WriteBuffer must contain trivially copyable objects"); | 210 | buffer_index); |
| 210 | 211 | } else { | |
| 211 | return WriteBuffer(std::data(container), std::size(container) * sizeof(ContiguousType), | 212 | static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable"); |
| 212 | buffer_index); | 213 | return WriteBuffer(&data, sizeof(T), buffer_index); |
| 214 | } | ||
| 213 | } | 215 | } |
| 214 | 216 | ||
| 215 | /// Helper function to get the size of the input buffer | 217 | /// Helper function to get the size of the input buffer |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 8dd4a2637..cabe8d418 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -145,7 +145,7 @@ struct KernelCore::Impl { | |||
| 145 | 145 | ||
| 146 | void InitializePreemption(KernelCore& kernel) { | 146 | void InitializePreemption(KernelCore& kernel) { |
| 147 | preemption_event = Core::Timing::CreateEvent( | 147 | preemption_event = Core::Timing::CreateEvent( |
| 148 | "PreemptionCallback", [this, &kernel](u64, std::chrono::nanoseconds) { | 148 | "PreemptionCallback", [this, &kernel](std::uintptr_t, std::chrono::nanoseconds) { |
| 149 | { | 149 | { |
| 150 | SchedulerLock lock(kernel); | 150 | SchedulerLock lock(kernel); |
| 151 | global_scheduler.PreemptThreads(); | 151 | global_scheduler.PreemptThreads(); |
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index f93e5e4b0..fc656d613 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp | |||
| @@ -131,7 +131,8 @@ u32 GlobalScheduler::SelectThreads() { | |||
| 131 | u32 cores_needing_context_switch{}; | 131 | u32 cores_needing_context_switch{}; |
| 132 | for (u32 core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { | 132 | for (u32 core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { |
| 133 | Scheduler& sched = kernel.Scheduler(core); | 133 | Scheduler& sched = kernel.Scheduler(core); |
| 134 | ASSERT(top_threads[core] == nullptr || top_threads[core]->GetProcessorID() == core); | 134 | ASSERT(top_threads[core] == nullptr || |
| 135 | static_cast<u32>(top_threads[core]->GetProcessorID()) == core); | ||
| 135 | if (update_thread(top_threads[core], sched)) { | 136 | if (update_thread(top_threads[core], sched)) { |
| 136 | cores_needing_context_switch |= (1ul << core); | 137 | cores_needing_context_switch |= (1ul << core); |
| 137 | } | 138 | } |
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index af22f4c33..7e6391c6c 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp | |||
| @@ -33,8 +33,10 @@ ResultVal<std::shared_ptr<ServerSession>> ServerSession::Create(KernelCore& kern | |||
| 33 | std::string name) { | 33 | std::string name) { |
| 34 | std::shared_ptr<ServerSession> session{std::make_shared<ServerSession>(kernel)}; | 34 | std::shared_ptr<ServerSession> session{std::make_shared<ServerSession>(kernel)}; |
| 35 | 35 | ||
| 36 | session->request_event = Core::Timing::CreateEvent( | 36 | session->request_event = |
| 37 | name, [session](u64, std::chrono::nanoseconds) { session->CompleteSyncRequest(); }); | 37 | Core::Timing::CreateEvent(name, [session](std::uintptr_t, std::chrono::nanoseconds) { |
| 38 | session->CompleteSyncRequest(); | ||
| 39 | }); | ||
| 38 | session->name = std::move(name); | 40 | session->name = std::move(name); |
| 39 | session->parent = std::move(parent); | 41 | session->parent = std::move(parent); |
| 40 | 42 | ||
diff --git a/src/core/hle/kernel/time_manager.cpp b/src/core/hle/kernel/time_manager.cpp index 88b01b751..95f2446c9 100644 --- a/src/core/hle/kernel/time_manager.cpp +++ b/src/core/hle/kernel/time_manager.cpp | |||
| @@ -16,14 +16,14 @@ namespace Kernel { | |||
| 16 | 16 | ||
| 17 | TimeManager::TimeManager(Core::System& system_) : system{system_} { | 17 | TimeManager::TimeManager(Core::System& system_) : system{system_} { |
| 18 | time_manager_event_type = Core::Timing::CreateEvent( | 18 | time_manager_event_type = Core::Timing::CreateEvent( |
| 19 | "Kernel::TimeManagerCallback", [this](u64 thread_handle, std::chrono::nanoseconds) { | 19 | "Kernel::TimeManagerCallback", |
| 20 | SchedulerLock lock(system.Kernel()); | 20 | [this](std::uintptr_t thread_handle, std::chrono::nanoseconds) { |
| 21 | Handle proper_handle = static_cast<Handle>(thread_handle); | 21 | const SchedulerLock lock(system.Kernel()); |
| 22 | const auto proper_handle = static_cast<Handle>(thread_handle); | ||
| 22 | if (cancelled_events[proper_handle]) { | 23 | if (cancelled_events[proper_handle]) { |
| 23 | return; | 24 | return; |
| 24 | } | 25 | } |
| 25 | std::shared_ptr<Thread> thread = | 26 | auto thread = this->system.Kernel().RetrieveThreadFromGlobalHandleTable(proper_handle); |
| 26 | this->system.Kernel().RetrieveThreadFromGlobalHandleTable(proper_handle); | ||
| 27 | thread->OnWakeUp(); | 27 | thread->OnWakeUp(); |
| 28 | }); | 28 | }); |
| 29 | } | 29 | } |
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 8ac856ec3..63e4aeca0 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -286,9 +286,7 @@ protected: | |||
| 286 | ProfileBase profile_base{}; | 286 | ProfileBase profile_base{}; |
| 287 | ProfileData data{}; | 287 | ProfileData data{}; |
| 288 | if (profile_manager.GetProfileBaseAndData(user_id, profile_base, data)) { | 288 | if (profile_manager.GetProfileBaseAndData(user_id, profile_base, data)) { |
| 289 | std::array<u8, sizeof(ProfileData)> raw_data; | 289 | ctx.WriteBuffer(data); |
| 290 | std::memcpy(raw_data.data(), &data, sizeof(ProfileData)); | ||
| 291 | ctx.WriteBuffer(raw_data); | ||
| 292 | IPC::ResponseBuilder rb{ctx, 16}; | 290 | IPC::ResponseBuilder rb{ctx, 16}; |
| 293 | rb.Push(RESULT_SUCCESS); | 291 | rb.Push(RESULT_SUCCESS); |
| 294 | rb.PushRaw(profile_base); | 292 | rb.PushRaw(profile_base); |
| @@ -333,7 +331,7 @@ protected: | |||
| 333 | std::vector<u8> buffer(size); | 331 | std::vector<u8> buffer(size); |
| 334 | image.ReadBytes(buffer.data(), buffer.size()); | 332 | image.ReadBytes(buffer.data(), buffer.size()); |
| 335 | 333 | ||
| 336 | ctx.WriteBuffer(buffer.data(), buffer.size()); | 334 | ctx.WriteBuffer(buffer); |
| 337 | rb.Push<u32>(size); | 335 | rb.Push<u32>(size); |
| 338 | } | 336 | } |
| 339 | 337 | ||
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index eb8c81645..a98d57b5c 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -58,7 +58,7 @@ ProfileManager::~ProfileManager() { | |||
| 58 | /// internal management of the users profiles | 58 | /// internal management of the users profiles |
| 59 | std::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& profile) { | 59 | std::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& profile) { |
| 60 | if (user_count >= MAX_USERS) { | 60 | if (user_count >= MAX_USERS) { |
| 61 | return {}; | 61 | return std::nullopt; |
| 62 | } | 62 | } |
| 63 | profiles[user_count] = profile; | 63 | profiles[user_count] = profile; |
| 64 | return user_count++; | 64 | return user_count++; |
| @@ -101,13 +101,14 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const ProfileUsername& usern | |||
| 101 | [&uuid](const ProfileInfo& profile) { return uuid == profile.user_uuid; })) { | 101 | [&uuid](const ProfileInfo& profile) { return uuid == profile.user_uuid; })) { |
| 102 | return ERROR_USER_ALREADY_EXISTS; | 102 | return ERROR_USER_ALREADY_EXISTS; |
| 103 | } | 103 | } |
| 104 | ProfileInfo profile; | 104 | |
| 105 | profile.user_uuid = uuid; | 105 | return AddUser({ |
| 106 | profile.username = username; | 106 | .user_uuid = uuid, |
| 107 | profile.data = {}; | 107 | .username = username, |
| 108 | profile.creation_time = 0x0; | 108 | .creation_time = 0, |
| 109 | profile.is_open = false; | 109 | .data = {}, |
| 110 | return AddUser(profile); | 110 | .is_open = false, |
| 111 | }); | ||
| 111 | } | 112 | } |
| 112 | 113 | ||
| 113 | /// Creates a new user on the system. This function allows a much simpler method of registration | 114 | /// Creates a new user on the system. This function allows a much simpler method of registration |
| @@ -126,7 +127,7 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) | |||
| 126 | 127 | ||
| 127 | std::optional<UUID> ProfileManager::GetUser(std::size_t index) const { | 128 | std::optional<UUID> ProfileManager::GetUser(std::size_t index) const { |
| 128 | if (index >= MAX_USERS) { | 129 | if (index >= MAX_USERS) { |
| 129 | return {}; | 130 | return std::nullopt; |
| 130 | } | 131 | } |
| 131 | 132 | ||
| 132 | return profiles[index].user_uuid; | 133 | return profiles[index].user_uuid; |
| @@ -135,13 +136,13 @@ std::optional<UUID> ProfileManager::GetUser(std::size_t index) const { | |||
| 135 | /// Returns a users profile index based on their user id. | 136 | /// Returns a users profile index based on their user id. |
| 136 | std::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { | 137 | std::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { |
| 137 | if (!uuid) { | 138 | if (!uuid) { |
| 138 | return {}; | 139 | return std::nullopt; |
| 139 | } | 140 | } |
| 140 | 141 | ||
| 141 | const auto iter = std::find_if(profiles.begin(), profiles.end(), | 142 | const auto iter = std::find_if(profiles.begin(), profiles.end(), |
| 142 | [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; }); | 143 | [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; }); |
| 143 | if (iter == profiles.end()) { | 144 | if (iter == profiles.end()) { |
| 144 | return {}; | 145 | return std::nullopt; |
| 145 | } | 146 | } |
| 146 | 147 | ||
| 147 | return static_cast<std::size_t>(std::distance(profiles.begin(), iter)); | 148 | return static_cast<std::size_t>(std::distance(profiles.begin(), iter)); |
| @@ -339,7 +340,13 @@ void ProfileManager::ParseUserSaveFile() { | |||
| 339 | continue; | 340 | continue; |
| 340 | } | 341 | } |
| 341 | 342 | ||
| 342 | AddUser({user.uuid, user.username, user.timestamp, user.extra_data, false}); | 343 | AddUser({ |
| 344 | .user_uuid = user.uuid, | ||
| 345 | .username = user.username, | ||
| 346 | .creation_time = user.timestamp, | ||
| 347 | .data = user.extra_data, | ||
| 348 | .is_open = false, | ||
| 349 | }); | ||
| 343 | } | 350 | } |
| 344 | 351 | ||
| 345 | std::stable_partition(profiles.begin(), profiles.end(), | 352 | std::stable_partition(profiles.begin(), profiles.end(), |
| @@ -350,11 +357,13 @@ void ProfileManager::WriteUserSaveFile() { | |||
| 350 | ProfileDataRaw raw{}; | 357 | ProfileDataRaw raw{}; |
| 351 | 358 | ||
| 352 | for (std::size_t i = 0; i < MAX_USERS; ++i) { | 359 | for (std::size_t i = 0; i < MAX_USERS; ++i) { |
| 353 | raw.users[i].username = profiles[i].username; | 360 | raw.users[i] = { |
| 354 | raw.users[i].uuid2 = profiles[i].user_uuid; | 361 | .uuid = profiles[i].user_uuid, |
| 355 | raw.users[i].uuid = profiles[i].user_uuid; | 362 | .uuid2 = profiles[i].user_uuid, |
| 356 | raw.users[i].timestamp = profiles[i].creation_time; | 363 | .timestamp = profiles[i].creation_time, |
| 357 | raw.users[i].extra_data = profiles[i].data; | 364 | .username = profiles[i].username, |
| 365 | .extra_data = profiles[i].data, | ||
| 366 | }; | ||
| 358 | } | 367 | } |
| 359 | 368 | ||
| 360 | const auto raw_path = | 369 | const auto raw_path = |
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 4e7a0bec9..55a1edf1a 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -1342,12 +1342,12 @@ void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) { | |||
| 1342 | 1342 | ||
| 1343 | LOG_DEBUG(Service_AM, "called, uid={:016X}{:016X}", user_id[1], user_id[0]); | 1343 | LOG_DEBUG(Service_AM, "called, uid={:016X}{:016X}", user_id[1], user_id[0]); |
| 1344 | 1344 | ||
| 1345 | FileSys::SaveDataDescriptor descriptor{}; | 1345 | FileSys::SaveDataAttribute attribute{}; |
| 1346 | descriptor.title_id = system.CurrentProcess()->GetTitleID(); | 1346 | attribute.title_id = system.CurrentProcess()->GetTitleID(); |
| 1347 | descriptor.user_id = user_id; | 1347 | attribute.user_id = user_id; |
| 1348 | descriptor.type = FileSys::SaveDataType::SaveData; | 1348 | attribute.type = FileSys::SaveDataType::SaveData; |
| 1349 | const auto res = system.GetFileSystemController().CreateSaveData( | 1349 | const auto res = system.GetFileSystemController().CreateSaveData( |
| 1350 | FileSys::SaveDataSpaceId::NandUser, descriptor); | 1350 | FileSys::SaveDataSpaceId::NandUser, attribute); |
| 1351 | 1351 | ||
| 1352 | IPC::ResponseBuilder rb{ctx, 4}; | 1352 | IPC::ResponseBuilder rb{ctx, 4}; |
| 1353 | rb.Push(res.Code()); | 1353 | rb.Push(res.Code()); |
| @@ -1405,7 +1405,6 @@ void IApplicationFunctions::GetDesiredLanguage(Kernel::HLERequestContext& ctx) { | |||
| 1405 | // Get supported languages from NACP, if possible | 1405 | // Get supported languages from NACP, if possible |
| 1406 | // Default to 0 (all languages supported) | 1406 | // Default to 0 (all languages supported) |
| 1407 | u32 supported_languages = 0; | 1407 | u32 supported_languages = 0; |
| 1408 | FileSys::PatchManager pm{system.CurrentProcess()->GetTitleID()}; | ||
| 1409 | 1408 | ||
| 1410 | const auto res = [this] { | 1409 | const auto res = [this] { |
| 1411 | const auto title_id = system.CurrentProcess()->GetTitleID(); | 1410 | const auto title_id = system.CurrentProcess()->GetTitleID(); |
diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp index fbe3686ae..289da2619 100644 --- a/src/core/hle/service/am/applets/software_keyboard.cpp +++ b/src/core/hle/service/am/applets/software_keyboard.cpp | |||
| @@ -13,11 +13,23 @@ | |||
| 13 | 13 | ||
| 14 | namespace Service::AM::Applets { | 14 | namespace Service::AM::Applets { |
| 15 | 15 | ||
| 16 | namespace { | ||
| 17 | enum class Request : u32 { | ||
| 18 | Finalize = 0x4, | ||
| 19 | SetUserWordInfo = 0x6, | ||
| 20 | SetCustomizeDic = 0x7, | ||
| 21 | Calc = 0xa, | ||
| 22 | SetCustomizedDictionaries = 0xb, | ||
| 23 | UnsetCustomizedDictionaries = 0xc, | ||
| 24 | UnknownD = 0xd, | ||
| 25 | UnknownE = 0xe, | ||
| 26 | }; | ||
| 27 | constexpr std::size_t SWKBD_INLINE_INIT_SIZE = 0x8; | ||
| 16 | constexpr std::size_t SWKBD_OUTPUT_BUFFER_SIZE = 0x7D8; | 28 | constexpr std::size_t SWKBD_OUTPUT_BUFFER_SIZE = 0x7D8; |
| 17 | constexpr std::size_t SWKBD_OUTPUT_INTERACTIVE_BUFFER_SIZE = 0x7D4; | 29 | constexpr std::size_t SWKBD_OUTPUT_INTERACTIVE_BUFFER_SIZE = 0x7D4; |
| 18 | constexpr std::size_t DEFAULT_MAX_LENGTH = 500; | 30 | constexpr std::size_t DEFAULT_MAX_LENGTH = 500; |
| 19 | constexpr bool INTERACTIVE_STATUS_OK = false; | 31 | constexpr bool INTERACTIVE_STATUS_OK = false; |
| 20 | 32 | } // Anonymous namespace | |
| 21 | static Core::Frontend::SoftwareKeyboardParameters ConvertToFrontendParameters( | 33 | static Core::Frontend::SoftwareKeyboardParameters ConvertToFrontendParameters( |
| 22 | KeyboardConfig config, std::u16string initial_text) { | 34 | KeyboardConfig config, std::u16string initial_text) { |
| 23 | Core::Frontend::SoftwareKeyboardParameters params{}; | 35 | Core::Frontend::SoftwareKeyboardParameters params{}; |
| @@ -47,6 +59,7 @@ SoftwareKeyboard::~SoftwareKeyboard() = default; | |||
| 47 | 59 | ||
| 48 | void SoftwareKeyboard::Initialize() { | 60 | void SoftwareKeyboard::Initialize() { |
| 49 | complete = false; | 61 | complete = false; |
| 62 | is_inline = false; | ||
| 50 | initial_text.clear(); | 63 | initial_text.clear(); |
| 51 | final_data.clear(); | 64 | final_data.clear(); |
| 52 | 65 | ||
| @@ -56,6 +69,11 @@ void SoftwareKeyboard::Initialize() { | |||
| 56 | ASSERT(keyboard_config_storage != nullptr); | 69 | ASSERT(keyboard_config_storage != nullptr); |
| 57 | const auto& keyboard_config = keyboard_config_storage->GetData(); | 70 | const auto& keyboard_config = keyboard_config_storage->GetData(); |
| 58 | 71 | ||
| 72 | if (keyboard_config.size() == SWKBD_INLINE_INIT_SIZE) { | ||
| 73 | is_inline = true; | ||
| 74 | return; | ||
| 75 | } | ||
| 76 | |||
| 59 | ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig)); | 77 | ASSERT(keyboard_config.size() >= sizeof(KeyboardConfig)); |
| 60 | std::memcpy(&config, keyboard_config.data(), sizeof(KeyboardConfig)); | 78 | std::memcpy(&config, keyboard_config.data(), sizeof(KeyboardConfig)); |
| 61 | 79 | ||
| @@ -87,16 +105,32 @@ void SoftwareKeyboard::ExecuteInteractive() { | |||
| 87 | const auto storage = broker.PopInteractiveDataToApplet(); | 105 | const auto storage = broker.PopInteractiveDataToApplet(); |
| 88 | ASSERT(storage != nullptr); | 106 | ASSERT(storage != nullptr); |
| 89 | const auto data = storage->GetData(); | 107 | const auto data = storage->GetData(); |
| 90 | const auto status = static_cast<bool>(data[0]); | 108 | if (!is_inline) { |
| 91 | 109 | const auto status = static_cast<bool>(data[0]); | |
| 92 | if (status == INTERACTIVE_STATUS_OK) { | 110 | if (status == INTERACTIVE_STATUS_OK) { |
| 93 | complete = true; | 111 | complete = true; |
| 112 | } else { | ||
| 113 | std::array<char16_t, SWKBD_OUTPUT_INTERACTIVE_BUFFER_SIZE / 2 - 2> string; | ||
| 114 | std::memcpy(string.data(), data.data() + 4, string.size() * 2); | ||
| 115 | frontend.SendTextCheckDialog( | ||
| 116 | Common::UTF16StringFromFixedZeroTerminatedBuffer(string.data(), string.size()), | ||
| 117 | [this] { broker.SignalStateChanged(); }); | ||
| 118 | } | ||
| 94 | } else { | 119 | } else { |
| 95 | std::array<char16_t, SWKBD_OUTPUT_INTERACTIVE_BUFFER_SIZE / 2 - 2> string; | 120 | Request request{}; |
| 96 | std::memcpy(string.data(), data.data() + 4, string.size() * 2); | 121 | std::memcpy(&request, data.data(), sizeof(Request)); |
| 97 | frontend.SendTextCheckDialog( | 122 | |
| 98 | Common::UTF16StringFromFixedZeroTerminatedBuffer(string.data(), string.size()), | 123 | switch (request) { |
| 99 | [this] { broker.SignalStateChanged(); }); | 124 | case Request::Calc: { |
| 125 | broker.PushNormalDataFromApplet( | ||
| 126 | std::make_shared<IStorage>(std::move(std::vector<u8>{1}))); | ||
| 127 | broker.SignalStateChanged(); | ||
| 128 | break; | ||
| 129 | } | ||
| 130 | default: | ||
| 131 | UNIMPLEMENTED_MSG("Request {:X} is not implemented", request); | ||
| 132 | break; | ||
| 133 | } | ||
| 100 | } | 134 | } |
| 101 | } | 135 | } |
| 102 | 136 | ||
| @@ -108,9 +142,10 @@ void SoftwareKeyboard::Execute() { | |||
| 108 | } | 142 | } |
| 109 | 143 | ||
| 110 | const auto parameters = ConvertToFrontendParameters(config, initial_text); | 144 | const auto parameters = ConvertToFrontendParameters(config, initial_text); |
| 111 | 145 | if (!is_inline) { | |
| 112 | frontend.RequestText([this](std::optional<std::u16string> text) { WriteText(std::move(text)); }, | 146 | frontend.RequestText( |
| 113 | parameters); | 147 | [this](std::optional<std::u16string> text) { WriteText(std::move(text)); }, parameters); |
| 148 | } | ||
| 114 | } | 149 | } |
| 115 | 150 | ||
| 116 | void SoftwareKeyboard::WriteText(std::optional<std::u16string> text) { | 151 | void SoftwareKeyboard::WriteText(std::optional<std::u16string> text) { |
diff --git a/src/core/hle/service/am/applets/software_keyboard.h b/src/core/hle/service/am/applets/software_keyboard.h index ef4801fc6..5a3824b5a 100644 --- a/src/core/hle/service/am/applets/software_keyboard.h +++ b/src/core/hle/service/am/applets/software_keyboard.h | |||
| @@ -78,6 +78,7 @@ private: | |||
| 78 | KeyboardConfig config; | 78 | KeyboardConfig config; |
| 79 | std::u16string initial_text; | 79 | std::u16string initial_text; |
| 80 | bool complete = false; | 80 | bool complete = false; |
| 81 | bool is_inline = false; | ||
| 81 | std::vector<u8> final_data; | 82 | std::vector<u8> final_data; |
| 82 | }; | 83 | }; |
| 83 | 84 | ||
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index 106e89743..dd80dd1dc 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp | |||
| @@ -71,7 +71,7 @@ public: | |||
| 71 | 71 | ||
| 72 | stream = audio_core.OpenStream(system.CoreTiming(), audio_params.sample_rate, | 72 | stream = audio_core.OpenStream(system.CoreTiming(), audio_params.sample_rate, |
| 73 | audio_params.channel_count, std::move(unique_name), | 73 | audio_params.channel_count, std::move(unique_name), |
| 74 | [=]() { buffer_event.writable->Signal(); }); | 74 | [this] { buffer_event.writable->Signal(); }); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | private: | 77 | private: |
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index d19513cbb..f1d81602c 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp | |||
| @@ -92,7 +92,7 @@ private: | |||
| 92 | if (performance) { | 92 | if (performance) { |
| 93 | rb.Push<u64>(*performance); | 93 | rb.Push<u64>(*performance); |
| 94 | } | 94 | } |
| 95 | ctx.WriteBuffer(samples.data(), samples.size() * sizeof(s16)); | 95 | ctx.WriteBuffer(samples); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | bool DecodeOpusData(u32& consumed, u32& sample_count, const std::vector<u8>& input, | 98 | bool DecodeOpusData(u32& consumed, u32& sample_count, const std::vector<u8>& input, |
diff --git a/src/core/hle/service/bcat/module.cpp b/src/core/hle/service/bcat/module.cpp index 603b64d4f..db0e06ca1 100644 --- a/src/core/hle/service/bcat/module.cpp +++ b/src/core/hle/service/bcat/module.cpp | |||
| @@ -112,7 +112,7 @@ private: | |||
| 112 | void GetImpl(Kernel::HLERequestContext& ctx) { | 112 | void GetImpl(Kernel::HLERequestContext& ctx) { |
| 113 | LOG_DEBUG(Service_BCAT, "called"); | 113 | LOG_DEBUG(Service_BCAT, "called"); |
| 114 | 114 | ||
| 115 | ctx.WriteBuffer(&impl, sizeof(DeliveryCacheProgressImpl)); | 115 | ctx.WriteBuffer(impl); |
| 116 | 116 | ||
| 117 | IPC::ResponseBuilder rb{ctx, 2}; | 117 | IPC::ResponseBuilder rb{ctx, 2}; |
| 118 | rb.Push(RESULT_SUCCESS); | 118 | rb.Push(RESULT_SUCCESS); |
diff --git a/src/core/hle/service/es/es.cpp b/src/core/hle/service/es/es.cpp index a41c73c48..c2737a365 100644 --- a/src/core/hle/service/es/es.cpp +++ b/src/core/hle/service/es/es.cpp | |||
| @@ -160,7 +160,7 @@ private: | |||
| 160 | return; | 160 | return; |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | ctx.WriteBuffer(key.data(), key.size()); | 163 | ctx.WriteBuffer(key); |
| 164 | 164 | ||
| 165 | IPC::ResponseBuilder rb{ctx, 2}; | 165 | IPC::ResponseBuilder rb{ctx, 2}; |
| 166 | rb.Push(RESULT_SUCCESS); | 166 | rb.Push(RESULT_SUCCESS); |
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index c66124998..4490f8e4c 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp | |||
| @@ -311,7 +311,7 @@ ResultVal<FileSys::VirtualFile> FileSystemController::OpenRomFS( | |||
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | ResultVal<FileSys::VirtualDir> FileSystemController::CreateSaveData( | 313 | ResultVal<FileSys::VirtualDir> FileSystemController::CreateSaveData( |
| 314 | FileSys::SaveDataSpaceId space, const FileSys::SaveDataDescriptor& save_struct) const { | 314 | FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const { |
| 315 | LOG_TRACE(Service_FS, "Creating Save Data for space_id={:01X}, save_struct={}", | 315 | LOG_TRACE(Service_FS, "Creating Save Data for space_id={:01X}, save_struct={}", |
| 316 | static_cast<u8>(space), save_struct.DebugInfo()); | 316 | static_cast<u8>(space), save_struct.DebugInfo()); |
| 317 | 317 | ||
| @@ -323,15 +323,15 @@ ResultVal<FileSys::VirtualDir> FileSystemController::CreateSaveData( | |||
| 323 | } | 323 | } |
| 324 | 324 | ||
| 325 | ResultVal<FileSys::VirtualDir> FileSystemController::OpenSaveData( | 325 | ResultVal<FileSys::VirtualDir> FileSystemController::OpenSaveData( |
| 326 | FileSys::SaveDataSpaceId space, const FileSys::SaveDataDescriptor& descriptor) const { | 326 | FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& attribute) const { |
| 327 | LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}", | 327 | LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}", |
| 328 | static_cast<u8>(space), descriptor.DebugInfo()); | 328 | static_cast<u8>(space), attribute.DebugInfo()); |
| 329 | 329 | ||
| 330 | if (save_data_factory == nullptr) { | 330 | if (save_data_factory == nullptr) { |
| 331 | return FileSys::ERROR_ENTITY_NOT_FOUND; | 331 | return FileSys::ERROR_ENTITY_NOT_FOUND; |
| 332 | } | 332 | } |
| 333 | 333 | ||
| 334 | return save_data_factory->Open(space, descriptor); | 334 | return save_data_factory->Open(space, attribute); |
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | ResultVal<FileSys::VirtualDir> FileSystemController::OpenSaveDataSpace( | 337 | ResultVal<FileSys::VirtualDir> FileSystemController::OpenSaveDataSpace( |
diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 1b0a6a949..6dbbf0b2b 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h | |||
| @@ -31,7 +31,7 @@ enum class SaveDataSpaceId : u8; | |||
| 31 | enum class SaveDataType : u8; | 31 | enum class SaveDataType : u8; |
| 32 | enum class StorageId : u8; | 32 | enum class StorageId : u8; |
| 33 | 33 | ||
| 34 | struct SaveDataDescriptor; | 34 | struct SaveDataAttribute; |
| 35 | struct SaveDataSize; | 35 | struct SaveDataSize; |
| 36 | } // namespace FileSys | 36 | } // namespace FileSys |
| 37 | 37 | ||
| @@ -69,9 +69,9 @@ public: | |||
| 69 | ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id, | 69 | ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id, |
| 70 | FileSys::ContentRecordType type) const; | 70 | FileSys::ContentRecordType type) const; |
| 71 | ResultVal<FileSys::VirtualDir> CreateSaveData( | 71 | ResultVal<FileSys::VirtualDir> CreateSaveData( |
| 72 | FileSys::SaveDataSpaceId space, const FileSys::SaveDataDescriptor& save_struct) const; | 72 | FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const; |
| 73 | ResultVal<FileSys::VirtualDir> OpenSaveData( | 73 | ResultVal<FileSys::VirtualDir> OpenSaveData( |
| 74 | FileSys::SaveDataSpaceId space, const FileSys::SaveDataDescriptor& save_struct) const; | 74 | FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const; |
| 75 | ResultVal<FileSys::VirtualDir> OpenSaveDataSpace(FileSys::SaveDataSpaceId space) const; | 75 | ResultVal<FileSys::VirtualDir> OpenSaveDataSpace(FileSys::SaveDataSpaceId space) const; |
| 76 | ResultVal<FileSys::VirtualDir> OpenSDMC() const; | 76 | ResultVal<FileSys::VirtualDir> OpenSDMC() const; |
| 77 | ResultVal<FileSys::VirtualDir> OpenBISPartition(FileSys::BisPartitionId id) const; | 77 | ResultVal<FileSys::VirtualDir> OpenBISPartition(FileSys::BisPartitionId id) const; |
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 20c331b77..26fd87f58 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -696,8 +696,8 @@ FSP_SRV::FSP_SRV(FileSystemController& fsc, const Core::Reporter& reporter) | |||
| 696 | {67, nullptr, "FindSaveDataWithFilter"}, | 696 | {67, nullptr, "FindSaveDataWithFilter"}, |
| 697 | {68, nullptr, "OpenSaveDataInfoReaderBySaveDataFilter"}, | 697 | {68, nullptr, "OpenSaveDataInfoReaderBySaveDataFilter"}, |
| 698 | {69, nullptr, "ReadSaveDataFileSystemExtraDataBySaveDataAttribute"}, | 698 | {69, nullptr, "ReadSaveDataFileSystemExtraDataBySaveDataAttribute"}, |
| 699 | {70, nullptr, "WriteSaveDataFileSystemExtraDataBySaveDataAttribute"}, | 699 | {70, &FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute, "WriteSaveDataFileSystemExtraDataBySaveDataAttribute"}, |
| 700 | {71, nullptr, "ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute"}, | 700 | {71, &FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute, "ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute"}, |
| 701 | {80, nullptr, "OpenSaveDataMetaFile"}, | 701 | {80, nullptr, "OpenSaveDataMetaFile"}, |
| 702 | {81, nullptr, "OpenSaveDataTransferManager"}, | 702 | {81, nullptr, "OpenSaveDataTransferManager"}, |
| 703 | {82, nullptr, "OpenSaveDataTransferManagerVersion2"}, | 703 | {82, nullptr, "OpenSaveDataTransferManagerVersion2"}, |
| @@ -812,7 +812,7 @@ void FSP_SRV::OpenSdCardFileSystem(Kernel::HLERequestContext& ctx) { | |||
| 812 | void FSP_SRV::CreateSaveDataFileSystem(Kernel::HLERequestContext& ctx) { | 812 | void FSP_SRV::CreateSaveDataFileSystem(Kernel::HLERequestContext& ctx) { |
| 813 | IPC::RequestParser rp{ctx}; | 813 | IPC::RequestParser rp{ctx}; |
| 814 | 814 | ||
| 815 | auto save_struct = rp.PopRaw<FileSys::SaveDataDescriptor>(); | 815 | auto save_struct = rp.PopRaw<FileSys::SaveDataAttribute>(); |
| 816 | [[maybe_unused]] auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>(); | 816 | [[maybe_unused]] auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>(); |
| 817 | u128 uid = rp.PopRaw<u128>(); | 817 | u128 uid = rp.PopRaw<u128>(); |
| 818 | 818 | ||
| @@ -826,17 +826,18 @@ void FSP_SRV::CreateSaveDataFileSystem(Kernel::HLERequestContext& ctx) { | |||
| 826 | } | 826 | } |
| 827 | 827 | ||
| 828 | void FSP_SRV::OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx) { | 828 | void FSP_SRV::OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx) { |
| 829 | LOG_INFO(Service_FS, "called."); | 829 | IPC::RequestParser rp{ctx}; |
| 830 | 830 | ||
| 831 | struct Parameters { | 831 | struct Parameters { |
| 832 | FileSys::SaveDataSpaceId save_data_space_id; | 832 | FileSys::SaveDataSpaceId space_id; |
| 833 | FileSys::SaveDataDescriptor descriptor; | 833 | FileSys::SaveDataAttribute attribute; |
| 834 | }; | 834 | }; |
| 835 | 835 | ||
| 836 | IPC::RequestParser rp{ctx}; | ||
| 837 | const auto parameters = rp.PopRaw<Parameters>(); | 836 | const auto parameters = rp.PopRaw<Parameters>(); |
| 838 | 837 | ||
| 839 | auto dir = fsc.OpenSaveData(parameters.save_data_space_id, parameters.descriptor); | 838 | LOG_INFO(Service_FS, "called."); |
| 839 | |||
| 840 | auto dir = fsc.OpenSaveData(parameters.space_id, parameters.attribute); | ||
| 840 | if (dir.Failed()) { | 841 | if (dir.Failed()) { |
| 841 | IPC::ResponseBuilder rb{ctx, 2, 0, 0}; | 842 | IPC::ResponseBuilder rb{ctx, 2, 0, 0}; |
| 842 | rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); | 843 | rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); |
| @@ -844,13 +845,18 @@ void FSP_SRV::OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx) { | |||
| 844 | } | 845 | } |
| 845 | 846 | ||
| 846 | FileSys::StorageId id; | 847 | FileSys::StorageId id; |
| 847 | if (parameters.save_data_space_id == FileSys::SaveDataSpaceId::NandUser) { | 848 | |
| 849 | switch (parameters.space_id) { | ||
| 850 | case FileSys::SaveDataSpaceId::NandUser: | ||
| 848 | id = FileSys::StorageId::NandUser; | 851 | id = FileSys::StorageId::NandUser; |
| 849 | } else if (parameters.save_data_space_id == FileSys::SaveDataSpaceId::SdCardSystem || | 852 | break; |
| 850 | parameters.save_data_space_id == FileSys::SaveDataSpaceId::SdCardUser) { | 853 | case FileSys::SaveDataSpaceId::SdCardSystem: |
| 854 | case FileSys::SaveDataSpaceId::SdCardUser: | ||
| 851 | id = FileSys::StorageId::SdCard; | 855 | id = FileSys::StorageId::SdCard; |
| 852 | } else { | 856 | break; |
| 857 | case FileSys::SaveDataSpaceId::NandSystem: | ||
| 853 | id = FileSys::StorageId::NandSystem; | 858 | id = FileSys::StorageId::NandSystem; |
| 859 | break; | ||
| 854 | } | 860 | } |
| 855 | 861 | ||
| 856 | auto filesystem = | 862 | auto filesystem = |
| @@ -876,22 +882,31 @@ void FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId(Kernel::HLERequestContext& | |||
| 876 | rb.PushIpcInterface<ISaveDataInfoReader>(std::make_shared<ISaveDataInfoReader>(space, fsc)); | 882 | rb.PushIpcInterface<ISaveDataInfoReader>(std::make_shared<ISaveDataInfoReader>(space, fsc)); |
| 877 | } | 883 | } |
| 878 | 884 | ||
| 879 | void FSP_SRV::SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { | 885 | void FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute(Kernel::HLERequestContext& ctx) { |
| 880 | IPC::RequestParser rp{ctx}; | 886 | LOG_WARNING(Service_FS, "(STUBBED) called."); |
| 881 | log_mode = rp.PopEnum<LogMode>(); | ||
| 882 | |||
| 883 | LOG_DEBUG(Service_FS, "called, log_mode={:08X}", static_cast<u32>(log_mode)); | ||
| 884 | 887 | ||
| 885 | IPC::ResponseBuilder rb{ctx, 2}; | 888 | IPC::ResponseBuilder rb{ctx, 2}; |
| 886 | rb.Push(RESULT_SUCCESS); | 889 | rb.Push(RESULT_SUCCESS); |
| 887 | } | 890 | } |
| 888 | 891 | ||
| 889 | void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { | 892 | void FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute( |
| 890 | LOG_DEBUG(Service_FS, "called"); | 893 | Kernel::HLERequestContext& ctx) { |
| 894 | IPC::RequestParser rp{ctx}; | ||
| 895 | |||
| 896 | struct Parameters { | ||
| 897 | FileSys::SaveDataSpaceId space_id; | ||
| 898 | FileSys::SaveDataAttribute attribute; | ||
| 899 | }; | ||
| 900 | |||
| 901 | const auto parameters = rp.PopRaw<Parameters>(); | ||
| 902 | // Stub this to None for now, backend needs an impl to read/write the SaveDataExtraData | ||
| 903 | constexpr auto flags = static_cast<u32>(FileSys::SaveDataFlags::None); | ||
| 904 | |||
| 905 | LOG_WARNING(Service_FS, "(STUBBED) called, flags={}", flags); | ||
| 891 | 906 | ||
| 892 | IPC::ResponseBuilder rb{ctx, 3}; | 907 | IPC::ResponseBuilder rb{ctx, 3}; |
| 893 | rb.Push(RESULT_SUCCESS); | 908 | rb.Push(RESULT_SUCCESS); |
| 894 | rb.PushEnum(log_mode); | 909 | rb.Push(flags); |
| 895 | } | 910 | } |
| 896 | 911 | ||
| 897 | void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { | 912 | void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { |
| @@ -966,6 +981,24 @@ void FSP_SRV::OpenPatchDataStorageByCurrentProcess(Kernel::HLERequestContext& ct | |||
| 966 | rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); | 981 | rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); |
| 967 | } | 982 | } |
| 968 | 983 | ||
| 984 | void FSP_SRV::SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { | ||
| 985 | IPC::RequestParser rp{ctx}; | ||
| 986 | log_mode = rp.PopEnum<LogMode>(); | ||
| 987 | |||
| 988 | LOG_DEBUG(Service_FS, "called, log_mode={:08X}", static_cast<u32>(log_mode)); | ||
| 989 | |||
| 990 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 991 | rb.Push(RESULT_SUCCESS); | ||
| 992 | } | ||
| 993 | |||
| 994 | void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { | ||
| 995 | LOG_DEBUG(Service_FS, "called"); | ||
| 996 | |||
| 997 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 998 | rb.Push(RESULT_SUCCESS); | ||
| 999 | rb.PushEnum(log_mode); | ||
| 1000 | } | ||
| 1001 | |||
| 969 | void FSP_SRV::OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx) { | 1002 | void FSP_SRV::OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx) { |
| 970 | const auto raw = ctx.ReadBuffer(); | 1003 | const auto raw = ctx.ReadBuffer(); |
| 971 | auto log = Common::StringFromFixedZeroTerminatedBuffer( | 1004 | auto log = Common::StringFromFixedZeroTerminatedBuffer( |
diff --git a/src/core/hle/service/filesystem/fsp_srv.h b/src/core/hle/service/filesystem/fsp_srv.h index dfb3e395b..4964e874e 100644 --- a/src/core/hle/service/filesystem/fsp_srv.h +++ b/src/core/hle/service/filesystem/fsp_srv.h | |||
| @@ -43,11 +43,13 @@ private: | |||
| 43 | void OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx); | 43 | void OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx); |
| 44 | void OpenReadOnlySaveDataFileSystem(Kernel::HLERequestContext& ctx); | 44 | void OpenReadOnlySaveDataFileSystem(Kernel::HLERequestContext& ctx); |
| 45 | void OpenSaveDataInfoReaderBySaveDataSpaceId(Kernel::HLERequestContext& ctx); | 45 | void OpenSaveDataInfoReaderBySaveDataSpaceId(Kernel::HLERequestContext& ctx); |
| 46 | void SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); | 46 | void WriteSaveDataFileSystemExtraDataBySaveDataAttribute(Kernel::HLERequestContext& ctx); |
| 47 | void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); | 47 | void ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(Kernel::HLERequestContext& ctx); |
| 48 | void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); | 48 | void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); |
| 49 | void OpenDataStorageByDataId(Kernel::HLERequestContext& ctx); | 49 | void OpenDataStorageByDataId(Kernel::HLERequestContext& ctx); |
| 50 | void OpenPatchDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); | 50 | void OpenPatchDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); |
| 51 | void SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); | ||
| 52 | void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); | ||
| 51 | void OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx); | 53 | void OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx); |
| 52 | void GetAccessLogVersionInfo(Kernel::HLERequestContext& ctx); | 54 | void GetAccessLogVersionInfo(Kernel::HLERequestContext& ctx); |
| 53 | void OpenMultiCommitManager(Kernel::HLERequestContext& ctx); | 55 | void OpenMultiCommitManager(Kernel::HLERequestContext& ctx); |
diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp index cb35919e9..ad251ed4a 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp | |||
| @@ -39,33 +39,36 @@ void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, | |||
| 39 | 39 | ||
| 40 | cur_entry.sampling_number = last_entry.sampling_number + 1; | 40 | cur_entry.sampling_number = last_entry.sampling_number + 1; |
| 41 | cur_entry.sampling_number2 = cur_entry.sampling_number; | 41 | cur_entry.sampling_number2 = cur_entry.sampling_number; |
| 42 | cur_entry.attribute.connected.Assign(1); | ||
| 43 | auto& pad = cur_entry.pad_state; | ||
| 44 | 42 | ||
| 45 | using namespace Settings::NativeButton; | 43 | if (Settings::values.debug_pad_enabled) { |
| 46 | pad.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); | 44 | cur_entry.attribute.connected.Assign(1); |
| 47 | pad.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); | 45 | auto& pad = cur_entry.pad_state; |
| 48 | pad.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 49 | pad.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 50 | pad.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 51 | pad.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 52 | pad.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 53 | pad.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 54 | pad.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 55 | pad.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 56 | pad.d_left.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 57 | pad.d_up.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 58 | pad.d_right.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 59 | pad.d_down.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 60 | 46 | ||
| 61 | const auto [stick_l_x_f, stick_l_y_f] = | 47 | using namespace Settings::NativeButton; |
| 62 | analogs[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus(); | 48 | pad.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus()); |
| 63 | const auto [stick_r_x_f, stick_r_y_f] = | 49 | pad.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus()); |
| 64 | analogs[static_cast<std::size_t>(JoystickId::Joystick_Right)]->GetStatus(); | 50 | pad.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus()); |
| 65 | cur_entry.l_stick.x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX); | 51 | pad.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus()); |
| 66 | cur_entry.l_stick.y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX); | 52 | pad.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus()); |
| 67 | cur_entry.r_stick.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX); | 53 | pad.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus()); |
| 68 | cur_entry.r_stick.y = static_cast<s32>(stick_r_y_f * HID_JOYSTICK_MAX); | 54 | pad.zl.Assign(buttons[ZL - BUTTON_HID_BEGIN]->GetStatus()); |
| 55 | pad.zr.Assign(buttons[ZR - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 56 | pad.plus.Assign(buttons[Plus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 57 | pad.minus.Assign(buttons[Minus - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 58 | pad.d_left.Assign(buttons[DLeft - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 59 | pad.d_up.Assign(buttons[DUp - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 60 | pad.d_right.Assign(buttons[DRight - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 61 | pad.d_down.Assign(buttons[DDown - BUTTON_HID_BEGIN]->GetStatus()); | ||
| 62 | |||
| 63 | const auto [stick_l_x_f, stick_l_y_f] = | ||
| 64 | analogs[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus(); | ||
| 65 | const auto [stick_r_x_f, stick_r_y_f] = | ||
| 66 | analogs[static_cast<std::size_t>(JoystickId::Joystick_Right)]->GetStatus(); | ||
| 67 | cur_entry.l_stick.x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX); | ||
| 68 | cur_entry.l_stick.y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX); | ||
| 69 | cur_entry.r_stick.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX); | ||
| 70 | cur_entry.r_stick.y = static_cast<s32>(stick_r_y_f * HID_JOYSTICK_MAX); | ||
| 71 | } | ||
| 69 | 72 | ||
| 70 | std::memcpy(data, &shared_memory, sizeof(SharedMemory)); | 73 | std::memcpy(data, &shared_memory, sizeof(SharedMemory)); |
| 71 | } | 74 | } |
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index feae89525..0b896d5ad 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp | |||
| @@ -40,15 +40,16 @@ void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing, | |||
| 40 | 40 | ||
| 41 | cur_entry.key.fill(0); | 41 | cur_entry.key.fill(0); |
| 42 | cur_entry.modifier = 0; | 42 | cur_entry.modifier = 0; |
| 43 | 43 | if (Settings::values.keyboard_enabled) { | |
| 44 | for (std::size_t i = 0; i < keyboard_keys.size(); ++i) { | 44 | for (std::size_t i = 0; i < keyboard_keys.size(); ++i) { |
| 45 | cur_entry.key[i / KEYS_PER_BYTE] |= (keyboard_keys[i]->GetStatus() << (i % KEYS_PER_BYTE)); | 45 | cur_entry.key[i / KEYS_PER_BYTE] |= |
| 46 | } | 46 | (keyboard_keys[i]->GetStatus() << (i % KEYS_PER_BYTE)); |
| 47 | 47 | } | |
| 48 | for (std::size_t i = 0; i < keyboard_mods.size(); ++i) { | 48 | |
| 49 | cur_entry.modifier |= (keyboard_mods[i]->GetStatus() << i); | 49 | for (std::size_t i = 0; i < keyboard_mods.size(); ++i) { |
| 50 | cur_entry.modifier |= (keyboard_mods[i]->GetStatus() << i); | ||
| 51 | } | ||
| 50 | } | 52 | } |
| 51 | |||
| 52 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); | 53 | std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory)); |
| 53 | } | 54 | } |
| 54 | 55 | ||
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 680290cbd..1e95b7580 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -77,8 +77,9 @@ IAppletResource::IAppletResource(Core::System& system) | |||
| 77 | 77 | ||
| 78 | // Register update callbacks | 78 | // Register update callbacks |
| 79 | pad_update_event = Core::Timing::CreateEvent( | 79 | pad_update_event = Core::Timing::CreateEvent( |
| 80 | "HID::UpdatePadCallback", [this](u64 userdata, std::chrono::nanoseconds ns_late) { | 80 | "HID::UpdatePadCallback", |
| 81 | UpdateControllers(userdata, ns_late); | 81 | [this](std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { |
| 82 | UpdateControllers(user_data, ns_late); | ||
| 82 | }); | 83 | }); |
| 83 | 84 | ||
| 84 | // TODO(shinyquagsire23): Other update callbacks? (accel, gyro?) | 85 | // TODO(shinyquagsire23): Other update callbacks? (accel, gyro?) |
| @@ -108,7 +109,8 @@ void IAppletResource::GetSharedMemoryHandle(Kernel::HLERequestContext& ctx) { | |||
| 108 | rb.PushCopyObjects(shared_mem); | 109 | rb.PushCopyObjects(shared_mem); |
| 109 | } | 110 | } |
| 110 | 111 | ||
| 111 | void IAppletResource::UpdateControllers(u64 userdata, std::chrono::nanoseconds ns_late) { | 112 | void IAppletResource::UpdateControllers(std::uintptr_t user_data, |
| 113 | std::chrono::nanoseconds ns_late) { | ||
| 112 | auto& core_timing = system.CoreTiming(); | 114 | auto& core_timing = system.CoreTiming(); |
| 113 | 115 | ||
| 114 | const bool should_reload = Settings::values.is_device_reload_pending.exchange(false); | 116 | const bool should_reload = Settings::values.is_device_reload_pending.exchange(false); |
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index c6f0a2584..efb07547f 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h | |||
| @@ -64,7 +64,7 @@ private: | |||
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | void GetSharedMemoryHandle(Kernel::HLERequestContext& ctx); | 66 | void GetSharedMemoryHandle(Kernel::HLERequestContext& ctx); |
| 67 | void UpdateControllers(u64 userdata, std::chrono::nanoseconds ns_late); | 67 | void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); |
| 68 | 68 | ||
| 69 | std::shared_ptr<Kernel::SharedMemory> shared_mem; | 69 | std::shared_ptr<Kernel::SharedMemory> shared_mem; |
| 70 | 70 | ||
diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp index 64a526b9e..d8cd10e31 100644 --- a/src/core/hle/service/ldr/ldr.cpp +++ b/src/core/hle/service/ldr/ldr.cpp | |||
| @@ -310,7 +310,7 @@ public: | |||
| 310 | 310 | ||
| 311 | ResultVal<VAddr> MapProcessCodeMemory(Kernel::Process* process, VAddr baseAddress, | 311 | ResultVal<VAddr> MapProcessCodeMemory(Kernel::Process* process, VAddr baseAddress, |
| 312 | u64 size) const { | 312 | u64 size) const { |
| 313 | for (int retry{}; retry < MAXIMUM_MAP_RETRIES; retry++) { | 313 | for (std::size_t retry = 0; retry < MAXIMUM_MAP_RETRIES; retry++) { |
| 314 | auto& page_table{process->PageTable()}; | 314 | auto& page_table{process->PageTable()}; |
| 315 | const VAddr addr{GetRandomMapRegion(page_table, size)}; | 315 | const VAddr addr{GetRandomMapRegion(page_table, size)}; |
| 316 | const ResultCode result{page_table.MapProcessCodeMemory(addr, baseAddress, size)}; | 316 | const ResultCode result{page_table.MapProcessCodeMemory(addr, baseAddress, size)}; |
| @@ -331,8 +331,7 @@ public: | |||
| 331 | 331 | ||
| 332 | ResultVal<VAddr> MapNro(Kernel::Process* process, VAddr nro_addr, std::size_t nro_size, | 332 | ResultVal<VAddr> MapNro(Kernel::Process* process, VAddr nro_addr, std::size_t nro_size, |
| 333 | VAddr bss_addr, std::size_t bss_size, std::size_t size) const { | 333 | VAddr bss_addr, std::size_t bss_size, std::size_t size) const { |
| 334 | 334 | for (std::size_t retry = 0; retry < MAXIMUM_MAP_RETRIES; retry++) { | |
| 335 | for (int retry{}; retry < MAXIMUM_MAP_RETRIES; retry++) { | ||
| 336 | auto& page_table{process->PageTable()}; | 335 | auto& page_table{process->PageTable()}; |
| 337 | VAddr addr{}; | 336 | VAddr addr{}; |
| 338 | 337 | ||
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 4b79eb81d..5e2d769a4 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp | |||
| @@ -127,7 +127,7 @@ private: | |||
| 127 | const u32 array_size = rp.Pop<u32>(); | 127 | const u32 array_size = rp.Pop<u32>(); |
| 128 | LOG_DEBUG(Service_NFP, "called, array_size={}", array_size); | 128 | LOG_DEBUG(Service_NFP, "called, array_size={}", array_size); |
| 129 | 129 | ||
| 130 | ctx.WriteBuffer(&device_handle, sizeof(device_handle)); | 130 | ctx.WriteBuffer(device_handle); |
| 131 | 131 | ||
| 132 | IPC::ResponseBuilder rb{ctx, 3}; | 132 | IPC::ResponseBuilder rb{ctx, 3}; |
| 133 | rb.Push(RESULT_SUCCESS); | 133 | rb.Push(RESULT_SUCCESS); |
| @@ -220,7 +220,7 @@ private: | |||
| 220 | 220 | ||
| 221 | tag_info.protocol = 1; // TODO(ogniK): Figure out actual values | 221 | tag_info.protocol = 1; // TODO(ogniK): Figure out actual values |
| 222 | tag_info.tag_type = 2; | 222 | tag_info.tag_type = 2; |
| 223 | ctx.WriteBuffer(&tag_info, sizeof(TagInfo)); | 223 | ctx.WriteBuffer(tag_info); |
| 224 | rb.Push(RESULT_SUCCESS); | 224 | rb.Push(RESULT_SUCCESS); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| @@ -237,7 +237,7 @@ private: | |||
| 237 | 237 | ||
| 238 | IPC::ResponseBuilder rb{ctx, 2}; | 238 | IPC::ResponseBuilder rb{ctx, 2}; |
| 239 | auto amiibo = nfp_interface.GetAmiiboBuffer(); | 239 | auto amiibo = nfp_interface.GetAmiiboBuffer(); |
| 240 | ctx.WriteBuffer(&amiibo.model_info, sizeof(amiibo.model_info)); | 240 | ctx.WriteBuffer(amiibo.model_info); |
| 241 | rb.Push(RESULT_SUCCESS); | 241 | rb.Push(RESULT_SUCCESS); |
| 242 | } | 242 | } |
| 243 | 243 | ||
| @@ -283,7 +283,7 @@ private: | |||
| 283 | 283 | ||
| 284 | CommonInfo common_info{}; | 284 | CommonInfo common_info{}; |
| 285 | common_info.application_area_size = 0; | 285 | common_info.application_area_size = 0; |
| 286 | ctx.WriteBuffer(&common_info, sizeof(CommonInfo)); | 286 | ctx.WriteBuffer(common_info); |
| 287 | 287 | ||
| 288 | IPC::ResponseBuilder rb{ctx, 2}; | 288 | IPC::ResponseBuilder rb{ctx, 2}; |
| 289 | rb.Push(RESULT_SUCCESS); | 289 | rb.Push(RESULT_SUCCESS); |
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index 195421cc0..d4ba88147 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp | |||
| @@ -16,11 +16,12 @@ | |||
| 16 | #include "video_core/renderer_base.h" | 16 | #include "video_core/renderer_base.h" |
| 17 | 17 | ||
| 18 | namespace Service::Nvidia::Devices { | 18 | namespace Service::Nvidia::Devices { |
| 19 | |||
| 19 | namespace NvErrCodes { | 20 | namespace NvErrCodes { |
| 20 | enum { | 21 | constexpr u32 Success{}; |
| 21 | InvalidNmapHandle = -22, | 22 | constexpr u32 OutOfMemory{static_cast<u32>(-12)}; |
| 22 | }; | 23 | constexpr u32 InvalidInput{static_cast<u32>(-22)}; |
| 23 | } | 24 | } // namespace NvErrCodes |
| 24 | 25 | ||
| 25 | nvhost_as_gpu::nvhost_as_gpu(Core::System& system, std::shared_ptr<nvmap> nvmap_dev) | 26 | nvhost_as_gpu::nvhost_as_gpu(Core::System& system, std::shared_ptr<nvmap> nvmap_dev) |
| 26 | : nvdevice(system), nvmap_dev(std::move(nvmap_dev)) {} | 27 | : nvdevice(system), nvmap_dev(std::move(nvmap_dev)) {} |
| @@ -49,8 +50,9 @@ u32 nvhost_as_gpu::ioctl(Ioctl command, const std::vector<u8>& input, const std: | |||
| 49 | break; | 50 | break; |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | if (static_cast<IoctlCommand>(command.cmd.Value()) == IoctlCommand::IocRemapCommand) | 53 | if (static_cast<IoctlCommand>(command.cmd.Value()) == IoctlCommand::IocRemapCommand) { |
| 53 | return Remap(input, output); | 54 | return Remap(input, output); |
| 55 | } | ||
| 54 | 56 | ||
| 55 | UNIMPLEMENTED_MSG("Unimplemented ioctl command"); | 57 | UNIMPLEMENTED_MSG("Unimplemented ioctl command"); |
| 56 | return 0; | 58 | return 0; |
| @@ -59,6 +61,7 @@ u32 nvhost_as_gpu::ioctl(Ioctl command, const std::vector<u8>& input, const std: | |||
| 59 | u32 nvhost_as_gpu::InitalizeEx(const std::vector<u8>& input, std::vector<u8>& output) { | 61 | u32 nvhost_as_gpu::InitalizeEx(const std::vector<u8>& input, std::vector<u8>& output) { |
| 60 | IoctlInitalizeEx params{}; | 62 | IoctlInitalizeEx params{}; |
| 61 | std::memcpy(¶ms, input.data(), input.size()); | 63 | std::memcpy(¶ms, input.data(), input.size()); |
| 64 | |||
| 62 | LOG_WARNING(Service_NVDRV, "(STUBBED) called, big_page_size=0x{:X}", params.big_page_size); | 65 | LOG_WARNING(Service_NVDRV, "(STUBBED) called, big_page_size=0x{:X}", params.big_page_size); |
| 63 | 66 | ||
| 64 | return 0; | 67 | return 0; |
| @@ -67,53 +70,61 @@ u32 nvhost_as_gpu::InitalizeEx(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 67 | u32 nvhost_as_gpu::AllocateSpace(const std::vector<u8>& input, std::vector<u8>& output) { | 70 | u32 nvhost_as_gpu::AllocateSpace(const std::vector<u8>& input, std::vector<u8>& output) { |
| 68 | IoctlAllocSpace params{}; | 71 | IoctlAllocSpace params{}; |
| 69 | std::memcpy(¶ms, input.data(), input.size()); | 72 | std::memcpy(¶ms, input.data(), input.size()); |
| 73 | |||
| 70 | LOG_DEBUG(Service_NVDRV, "called, pages={:X}, page_size={:X}, flags={:X}", params.pages, | 74 | LOG_DEBUG(Service_NVDRV, "called, pages={:X}, page_size={:X}, flags={:X}", params.pages, |
| 71 | params.page_size, params.flags); | 75 | params.page_size, params.flags); |
| 72 | 76 | ||
| 73 | auto& gpu = system.GPU(); | 77 | const auto size{static_cast<u64>(params.pages) * static_cast<u64>(params.page_size)}; |
| 74 | const u64 size{static_cast<u64>(params.pages) * static_cast<u64>(params.page_size)}; | 78 | if ((params.flags & AddressSpaceFlags::FixedOffset) != AddressSpaceFlags::None) { |
| 75 | if (params.flags & 1) { | 79 | params.offset = *system.GPU().MemoryManager().AllocateFixed(params.offset, size); |
| 76 | params.offset = gpu.MemoryManager().AllocateSpace(params.offset, size, 1); | ||
| 77 | } else { | 80 | } else { |
| 78 | params.offset = gpu.MemoryManager().AllocateSpace(size, params.align); | 81 | params.offset = system.GPU().MemoryManager().Allocate(size, params.align); |
| 82 | } | ||
| 83 | |||
| 84 | auto result{NvErrCodes::Success}; | ||
| 85 | if (!params.offset) { | ||
| 86 | LOG_CRITICAL(Service_NVDRV, "allocation failed for size {}", size); | ||
| 87 | result = NvErrCodes::OutOfMemory; | ||
| 79 | } | 88 | } |
| 80 | 89 | ||
| 81 | std::memcpy(output.data(), ¶ms, output.size()); | 90 | std::memcpy(output.data(), ¶ms, output.size()); |
| 82 | return 0; | 91 | return result; |
| 83 | } | 92 | } |
| 84 | 93 | ||
| 85 | u32 nvhost_as_gpu::Remap(const std::vector<u8>& input, std::vector<u8>& output) { | 94 | u32 nvhost_as_gpu::Remap(const std::vector<u8>& input, std::vector<u8>& output) { |
| 86 | std::size_t num_entries = input.size() / sizeof(IoctlRemapEntry); | 95 | const auto num_entries = input.size() / sizeof(IoctlRemapEntry); |
| 87 | 96 | ||
| 88 | LOG_WARNING(Service_NVDRV, "(STUBBED) called, num_entries=0x{:X}", num_entries); | 97 | LOG_DEBUG(Service_NVDRV, "called, num_entries=0x{:X}", num_entries); |
| 89 | 98 | ||
| 99 | auto result{NvErrCodes::Success}; | ||
| 90 | std::vector<IoctlRemapEntry> entries(num_entries); | 100 | std::vector<IoctlRemapEntry> entries(num_entries); |
| 91 | std::memcpy(entries.data(), input.data(), input.size()); | 101 | std::memcpy(entries.data(), input.data(), input.size()); |
| 92 | 102 | ||
| 93 | auto& gpu = system.GPU(); | ||
| 94 | for (const auto& entry : entries) { | 103 | for (const auto& entry : entries) { |
| 95 | LOG_WARNING(Service_NVDRV, "remap entry, offset=0x{:X} handle=0x{:X} pages=0x{:X}", | 104 | LOG_DEBUG(Service_NVDRV, "remap entry, offset=0x{:X} handle=0x{:X} pages=0x{:X}", |
| 96 | entry.offset, entry.nvmap_handle, entry.pages); | 105 | entry.offset, entry.nvmap_handle, entry.pages); |
| 97 | GPUVAddr offset = static_cast<GPUVAddr>(entry.offset) << 0x10; | 106 | |
| 98 | auto object = nvmap_dev->GetObject(entry.nvmap_handle); | 107 | const auto object{nvmap_dev->GetObject(entry.nvmap_handle)}; |
| 99 | if (!object) { | 108 | if (!object) { |
| 100 | LOG_CRITICAL(Service_NVDRV, "nvmap {} is an invalid handle!", entry.nvmap_handle); | 109 | LOG_CRITICAL(Service_NVDRV, "invalid nvmap_handle={:X}", entry.nvmap_handle); |
| 101 | std::memcpy(output.data(), entries.data(), output.size()); | 110 | result = NvErrCodes::InvalidInput; |
| 102 | return static_cast<u32>(NvErrCodes::InvalidNmapHandle); | 111 | break; |
| 103 | } | 112 | } |
| 104 | 113 | ||
| 105 | ASSERT(object->status == nvmap::Object::Status::Allocated); | 114 | const auto offset{static_cast<GPUVAddr>(entry.offset) << 0x10}; |
| 115 | const auto size{static_cast<u64>(entry.pages) << 0x10}; | ||
| 116 | const auto map_offset{static_cast<u64>(entry.map_offset) << 0x10}; | ||
| 117 | const auto addr{system.GPU().MemoryManager().Map(object->addr + map_offset, offset, size)}; | ||
| 106 | 118 | ||
| 107 | const u64 size = static_cast<u64>(entry.pages) << 0x10; | 119 | if (!addr) { |
| 108 | ASSERT(size <= object->size); | 120 | LOG_CRITICAL(Service_NVDRV, "map returned an invalid address!"); |
| 109 | const u64 map_offset = static_cast<u64>(entry.map_offset) << 0x10; | 121 | result = NvErrCodes::InvalidInput; |
| 110 | 122 | break; | |
| 111 | const GPUVAddr returned = | 123 | } |
| 112 | gpu.MemoryManager().MapBufferEx(object->addr + map_offset, offset, size); | ||
| 113 | ASSERT(returned == offset); | ||
| 114 | } | 124 | } |
| 125 | |||
| 115 | std::memcpy(output.data(), entries.data(), output.size()); | 126 | std::memcpy(output.data(), entries.data(), output.size()); |
| 116 | return 0; | 127 | return result; |
| 117 | } | 128 | } |
| 118 | 129 | ||
| 119 | u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& output) { | 130 | u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& output) { |
| @@ -126,44 +137,76 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 126 | params.flags, params.nvmap_handle, params.buffer_offset, params.mapping_size, | 137 | params.flags, params.nvmap_handle, params.buffer_offset, params.mapping_size, |
| 127 | params.offset); | 138 | params.offset); |
| 128 | 139 | ||
| 129 | if (!params.nvmap_handle) { | 140 | const auto object{nvmap_dev->GetObject(params.nvmap_handle)}; |
| 130 | return 0; | 141 | if (!object) { |
| 142 | LOG_CRITICAL(Service_NVDRV, "invalid nvmap_handle={:X}", params.nvmap_handle); | ||
| 143 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 144 | return NvErrCodes::InvalidInput; | ||
| 131 | } | 145 | } |
| 132 | 146 | ||
| 133 | auto object = nvmap_dev->GetObject(params.nvmap_handle); | ||
| 134 | ASSERT(object); | ||
| 135 | |||
| 136 | // We can only map objects that have already been assigned a CPU address. | ||
| 137 | ASSERT(object->status == nvmap::Object::Status::Allocated); | ||
| 138 | |||
| 139 | ASSERT(params.buffer_offset == 0); | ||
| 140 | |||
| 141 | // The real nvservices doesn't make a distinction between handles and ids, and | 147 | // The real nvservices doesn't make a distinction between handles and ids, and |
| 142 | // object can only have one handle and it will be the same as its id. Assert that this is the | 148 | // object can only have one handle and it will be the same as its id. Assert that this is the |
| 143 | // case to prevent unexpected behavior. | 149 | // case to prevent unexpected behavior. |
| 144 | ASSERT(object->id == params.nvmap_handle); | 150 | ASSERT(object->id == params.nvmap_handle); |
| 145 | |||
| 146 | auto& gpu = system.GPU(); | 151 | auto& gpu = system.GPU(); |
| 147 | 152 | ||
| 148 | if (params.flags & 1) { | 153 | u64 page_size{params.page_size}; |
| 149 | params.offset = gpu.MemoryManager().MapBufferEx(object->addr, params.offset, object->size); | 154 | if (!page_size) { |
| 150 | } else { | 155 | page_size = object->align; |
| 151 | params.offset = gpu.MemoryManager().MapBufferEx(object->addr, object->size); | 156 | } |
| 157 | |||
| 158 | if ((params.flags & AddressSpaceFlags::Remap) != AddressSpaceFlags::None) { | ||
| 159 | if (const auto buffer_map{FindBufferMap(params.offset)}; buffer_map) { | ||
| 160 | const auto cpu_addr{static_cast<VAddr>(buffer_map->CpuAddr() + params.buffer_offset)}; | ||
| 161 | const auto gpu_addr{static_cast<GPUVAddr>(params.offset + params.buffer_offset)}; | ||
| 162 | |||
| 163 | if (!gpu.MemoryManager().Map(cpu_addr, gpu_addr, params.mapping_size)) { | ||
| 164 | LOG_CRITICAL(Service_NVDRV, | ||
| 165 | "remap failed, flags={:X}, nvmap_handle={:X}, buffer_offset={}, " | ||
| 166 | "mapping_size = {}, offset={}", | ||
| 167 | params.flags, params.nvmap_handle, params.buffer_offset, | ||
| 168 | params.mapping_size, params.offset); | ||
| 169 | |||
| 170 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 171 | return NvErrCodes::InvalidInput; | ||
| 172 | } | ||
| 173 | |||
| 174 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 175 | return NvErrCodes::Success; | ||
| 176 | } else { | ||
| 177 | LOG_CRITICAL(Service_NVDRV, "address not mapped offset={}", params.offset); | ||
| 178 | |||
| 179 | std::memcpy(output.data(), ¶ms, output.size()); | ||
| 180 | return NvErrCodes::InvalidInput; | ||
| 181 | } | ||
| 152 | } | 182 | } |
| 153 | 183 | ||
| 154 | // Create a new mapping entry for this operation. | 184 | // We can only map objects that have already been assigned a CPU address. |
| 155 | ASSERT_MSG(buffer_mappings.find(params.offset) == buffer_mappings.end(), | 185 | ASSERT(object->status == nvmap::Object::Status::Allocated); |
| 156 | "Offset is already mapped"); | 186 | |
| 187 | const auto physical_address{object->addr + params.buffer_offset}; | ||
| 188 | u64 size{params.mapping_size}; | ||
| 189 | if (!size) { | ||
| 190 | size = object->size; | ||
| 191 | } | ||
| 157 | 192 | ||
| 158 | BufferMapping mapping{}; | 193 | const bool is_alloc{(params.flags & AddressSpaceFlags::FixedOffset) == AddressSpaceFlags::None}; |
| 159 | mapping.nvmap_handle = params.nvmap_handle; | 194 | if (is_alloc) { |
| 160 | mapping.offset = params.offset; | 195 | params.offset = gpu.MemoryManager().MapAllocate(physical_address, size, page_size); |
| 161 | mapping.size = object->size; | 196 | } else { |
| 197 | params.offset = gpu.MemoryManager().Map(physical_address, params.offset, size); | ||
| 198 | } | ||
| 162 | 199 | ||
| 163 | buffer_mappings[params.offset] = mapping; | 200 | auto result{NvErrCodes::Success}; |
| 201 | if (!params.offset) { | ||
| 202 | LOG_CRITICAL(Service_NVDRV, "failed to map size={}", size); | ||
| 203 | result = NvErrCodes::InvalidInput; | ||
| 204 | } else { | ||
| 205 | AddBufferMap(params.offset, size, physical_address, is_alloc); | ||
| 206 | } | ||
| 164 | 207 | ||
| 165 | std::memcpy(output.data(), ¶ms, output.size()); | 208 | std::memcpy(output.data(), ¶ms, output.size()); |
| 166 | return 0; | 209 | return result; |
| 167 | } | 210 | } |
| 168 | 211 | ||
| 169 | u32 nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& output) { | 212 | u32 nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& output) { |
| @@ -172,24 +215,20 @@ u32 nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 172 | 215 | ||
| 173 | LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", params.offset); | 216 | LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", params.offset); |
| 174 | 217 | ||
| 175 | const auto itr = buffer_mappings.find(params.offset); | 218 | if (const auto size{RemoveBufferMap(params.offset)}; size) { |
| 176 | if (itr == buffer_mappings.end()) { | 219 | system.GPU().MemoryManager().Unmap(params.offset, *size); |
| 177 | LOG_WARNING(Service_NVDRV, "Tried to unmap an invalid offset 0x{:X}", params.offset); | 220 | } else { |
| 178 | // Hardware tests shows that unmapping an already unmapped buffer always returns successful | 221 | LOG_ERROR(Service_NVDRV, "invalid offset=0x{:X}", params.offset); |
| 179 | // and doesn't fail. | ||
| 180 | return 0; | ||
| 181 | } | 222 | } |
| 182 | 223 | ||
| 183 | params.offset = system.GPU().MemoryManager().UnmapBuffer(params.offset, itr->second.size); | ||
| 184 | buffer_mappings.erase(itr->second.offset); | ||
| 185 | |||
| 186 | std::memcpy(output.data(), ¶ms, output.size()); | 224 | std::memcpy(output.data(), ¶ms, output.size()); |
| 187 | return 0; | 225 | return NvErrCodes::Success; |
| 188 | } | 226 | } |
| 189 | 227 | ||
| 190 | u32 nvhost_as_gpu::BindChannel(const std::vector<u8>& input, std::vector<u8>& output) { | 228 | u32 nvhost_as_gpu::BindChannel(const std::vector<u8>& input, std::vector<u8>& output) { |
| 191 | IoctlBindChannel params{}; | 229 | IoctlBindChannel params{}; |
| 192 | std::memcpy(¶ms, input.data(), input.size()); | 230 | std::memcpy(¶ms, input.data(), input.size()); |
| 231 | |||
| 193 | LOG_DEBUG(Service_NVDRV, "called, fd={:X}", params.fd); | 232 | LOG_DEBUG(Service_NVDRV, "called, fd={:X}", params.fd); |
| 194 | 233 | ||
| 195 | channel = params.fd; | 234 | channel = params.fd; |
| @@ -199,6 +238,7 @@ u32 nvhost_as_gpu::BindChannel(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 199 | u32 nvhost_as_gpu::GetVARegions(const std::vector<u8>& input, std::vector<u8>& output) { | 238 | u32 nvhost_as_gpu::GetVARegions(const std::vector<u8>& input, std::vector<u8>& output) { |
| 200 | IoctlGetVaRegions params{}; | 239 | IoctlGetVaRegions params{}; |
| 201 | std::memcpy(¶ms, input.data(), input.size()); | 240 | std::memcpy(¶ms, input.data(), input.size()); |
| 241 | |||
| 202 | LOG_WARNING(Service_NVDRV, "(STUBBED) called, buf_addr={:X}, buf_size={:X}", params.buf_addr, | 242 | LOG_WARNING(Service_NVDRV, "(STUBBED) called, buf_addr={:X}, buf_size={:X}", params.buf_addr, |
| 203 | params.buf_size); | 243 | params.buf_size); |
| 204 | 244 | ||
| @@ -210,9 +250,43 @@ u32 nvhost_as_gpu::GetVARegions(const std::vector<u8>& input, std::vector<u8>& o | |||
| 210 | params.regions[1].offset = 0x04000000; | 250 | params.regions[1].offset = 0x04000000; |
| 211 | params.regions[1].page_size = 0x10000; | 251 | params.regions[1].page_size = 0x10000; |
| 212 | params.regions[1].pages = 0x1bffff; | 252 | params.regions[1].pages = 0x1bffff; |
| 253 | |||
| 213 | // TODO(ogniK): This probably can stay stubbed but should add support way way later | 254 | // TODO(ogniK): This probably can stay stubbed but should add support way way later |
| 255 | |||
| 214 | std::memcpy(output.data(), ¶ms, output.size()); | 256 | std::memcpy(output.data(), ¶ms, output.size()); |
| 215 | return 0; | 257 | return 0; |
| 216 | } | 258 | } |
| 217 | 259 | ||
| 260 | std::optional<nvhost_as_gpu::BufferMap> nvhost_as_gpu::FindBufferMap(GPUVAddr gpu_addr) const { | ||
| 261 | const auto end{buffer_mappings.upper_bound(gpu_addr)}; | ||
| 262 | for (auto iter{buffer_mappings.begin()}; iter != end; ++iter) { | ||
| 263 | if (gpu_addr >= iter->second.StartAddr() && gpu_addr < iter->second.EndAddr()) { | ||
| 264 | return iter->second; | ||
| 265 | } | ||
| 266 | } | ||
| 267 | |||
| 268 | return {}; | ||
| 269 | } | ||
| 270 | |||
| 271 | void nvhost_as_gpu::AddBufferMap(GPUVAddr gpu_addr, std::size_t size, VAddr cpu_addr, | ||
| 272 | bool is_allocated) { | ||
| 273 | buffer_mappings[gpu_addr] = {gpu_addr, size, cpu_addr, is_allocated}; | ||
| 274 | } | ||
| 275 | |||
| 276 | std::optional<std::size_t> nvhost_as_gpu::RemoveBufferMap(GPUVAddr gpu_addr) { | ||
| 277 | if (const auto iter{buffer_mappings.find(gpu_addr)}; iter != buffer_mappings.end()) { | ||
| 278 | std::size_t size{}; | ||
| 279 | |||
| 280 | if (iter->second.IsAllocated()) { | ||
| 281 | size = iter->second.Size(); | ||
| 282 | } | ||
| 283 | |||
| 284 | buffer_mappings.erase(iter); | ||
| 285 | |||
| 286 | return size; | ||
| 287 | } | ||
| 288 | |||
| 289 | return {}; | ||
| 290 | } | ||
| 291 | |||
| 218 | } // namespace Service::Nvidia::Devices | 292 | } // namespace Service::Nvidia::Devices |
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h index f79fcc065..9a0cdff0c 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h | |||
| @@ -4,9 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <map> | ||
| 7 | #include <memory> | 8 | #include <memory> |
| 8 | #include <unordered_map> | 9 | #include <optional> |
| 9 | #include <vector> | 10 | #include <vector> |
| 11 | |||
| 12 | #include "common/common_funcs.h" | ||
| 10 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 11 | #include "common/swap.h" | 14 | #include "common/swap.h" |
| 12 | #include "core/hle/service/nvdrv/devices/nvdevice.h" | 15 | #include "core/hle/service/nvdrv/devices/nvdevice.h" |
| @@ -15,6 +18,13 @@ namespace Service::Nvidia::Devices { | |||
| 15 | 18 | ||
| 16 | class nvmap; | 19 | class nvmap; |
| 17 | 20 | ||
| 21 | enum class AddressSpaceFlags : u32 { | ||
| 22 | None = 0x0, | ||
| 23 | FixedOffset = 0x1, | ||
| 24 | Remap = 0x100, | ||
| 25 | }; | ||
| 26 | DECLARE_ENUM_FLAG_OPERATORS(AddressSpaceFlags); | ||
| 27 | |||
| 18 | class nvhost_as_gpu final : public nvdevice { | 28 | class nvhost_as_gpu final : public nvdevice { |
| 19 | public: | 29 | public: |
| 20 | explicit nvhost_as_gpu(Core::System& system, std::shared_ptr<nvmap> nvmap_dev); | 30 | explicit nvhost_as_gpu(Core::System& system, std::shared_ptr<nvmap> nvmap_dev); |
| @@ -25,6 +35,45 @@ public: | |||
| 25 | IoctlVersion version) override; | 35 | IoctlVersion version) override; |
| 26 | 36 | ||
| 27 | private: | 37 | private: |
| 38 | class BufferMap final { | ||
| 39 | public: | ||
| 40 | constexpr BufferMap() = default; | ||
| 41 | |||
| 42 | constexpr BufferMap(GPUVAddr start_addr, std::size_t size) | ||
| 43 | : start_addr{start_addr}, end_addr{start_addr + size} {} | ||
| 44 | |||
| 45 | constexpr BufferMap(GPUVAddr start_addr, std::size_t size, VAddr cpu_addr, | ||
| 46 | bool is_allocated) | ||
| 47 | : start_addr{start_addr}, end_addr{start_addr + size}, cpu_addr{cpu_addr}, | ||
| 48 | is_allocated{is_allocated} {} | ||
| 49 | |||
| 50 | constexpr VAddr StartAddr() const { | ||
| 51 | return start_addr; | ||
| 52 | } | ||
| 53 | |||
| 54 | constexpr VAddr EndAddr() const { | ||
| 55 | return end_addr; | ||
| 56 | } | ||
| 57 | |||
| 58 | constexpr std::size_t Size() const { | ||
| 59 | return end_addr - start_addr; | ||
| 60 | } | ||
| 61 | |||
| 62 | constexpr VAddr CpuAddr() const { | ||
| 63 | return cpu_addr; | ||
| 64 | } | ||
| 65 | |||
| 66 | constexpr bool IsAllocated() const { | ||
| 67 | return is_allocated; | ||
| 68 | } | ||
| 69 | |||
| 70 | private: | ||
| 71 | GPUVAddr start_addr{}; | ||
| 72 | GPUVAddr end_addr{}; | ||
| 73 | VAddr cpu_addr{}; | ||
| 74 | bool is_allocated{}; | ||
| 75 | }; | ||
| 76 | |||
| 28 | enum class IoctlCommand : u32_le { | 77 | enum class IoctlCommand : u32_le { |
| 29 | IocInitalizeExCommand = 0x40284109, | 78 | IocInitalizeExCommand = 0x40284109, |
| 30 | IocAllocateSpaceCommand = 0xC0184102, | 79 | IocAllocateSpaceCommand = 0xC0184102, |
| @@ -49,7 +98,7 @@ private: | |||
| 49 | struct IoctlAllocSpace { | 98 | struct IoctlAllocSpace { |
| 50 | u32_le pages; | 99 | u32_le pages; |
| 51 | u32_le page_size; | 100 | u32_le page_size; |
| 52 | u32_le flags; | 101 | AddressSpaceFlags flags; |
| 53 | INSERT_PADDING_WORDS(1); | 102 | INSERT_PADDING_WORDS(1); |
| 54 | union { | 103 | union { |
| 55 | u64_le offset; | 104 | u64_le offset; |
| @@ -69,18 +118,18 @@ private: | |||
| 69 | static_assert(sizeof(IoctlRemapEntry) == 20, "IoctlRemapEntry is incorrect size"); | 118 | static_assert(sizeof(IoctlRemapEntry) == 20, "IoctlRemapEntry is incorrect size"); |
| 70 | 119 | ||
| 71 | struct IoctlMapBufferEx { | 120 | struct IoctlMapBufferEx { |
| 72 | u32_le flags; // bit0: fixed_offset, bit2: cacheable | 121 | AddressSpaceFlags flags; // bit0: fixed_offset, bit2: cacheable |
| 73 | u32_le kind; // -1 is default | 122 | u32_le kind; // -1 is default |
| 74 | u32_le nvmap_handle; | 123 | u32_le nvmap_handle; |
| 75 | u32_le page_size; // 0 means don't care | 124 | u32_le page_size; // 0 means don't care |
| 76 | u64_le buffer_offset; | 125 | s64_le buffer_offset; |
| 77 | u64_le mapping_size; | 126 | u64_le mapping_size; |
| 78 | u64_le offset; | 127 | s64_le offset; |
| 79 | }; | 128 | }; |
| 80 | static_assert(sizeof(IoctlMapBufferEx) == 40, "IoctlMapBufferEx is incorrect size"); | 129 | static_assert(sizeof(IoctlMapBufferEx) == 40, "IoctlMapBufferEx is incorrect size"); |
| 81 | 130 | ||
| 82 | struct IoctlUnmapBuffer { | 131 | struct IoctlUnmapBuffer { |
| 83 | u64_le offset; | 132 | s64_le offset; |
| 84 | }; | 133 | }; |
| 85 | static_assert(sizeof(IoctlUnmapBuffer) == 8, "IoctlUnmapBuffer is incorrect size"); | 134 | static_assert(sizeof(IoctlUnmapBuffer) == 8, "IoctlUnmapBuffer is incorrect size"); |
| 86 | 135 | ||
| @@ -106,15 +155,6 @@ private: | |||
| 106 | static_assert(sizeof(IoctlGetVaRegions) == 16 + sizeof(IoctlVaRegion) * 2, | 155 | static_assert(sizeof(IoctlGetVaRegions) == 16 + sizeof(IoctlVaRegion) * 2, |
| 107 | "IoctlGetVaRegions is incorrect size"); | 156 | "IoctlGetVaRegions is incorrect size"); |
| 108 | 157 | ||
| 109 | struct BufferMapping { | ||
| 110 | u64 offset; | ||
| 111 | u64 size; | ||
| 112 | u32 nvmap_handle; | ||
| 113 | }; | ||
| 114 | |||
| 115 | /// Map containing the nvmap object mappings in GPU memory. | ||
| 116 | std::unordered_map<u64, BufferMapping> buffer_mappings; | ||
| 117 | |||
| 118 | u32 channel{}; | 158 | u32 channel{}; |
| 119 | 159 | ||
| 120 | u32 InitalizeEx(const std::vector<u8>& input, std::vector<u8>& output); | 160 | u32 InitalizeEx(const std::vector<u8>& input, std::vector<u8>& output); |
| @@ -125,7 +165,14 @@ private: | |||
| 125 | u32 BindChannel(const std::vector<u8>& input, std::vector<u8>& output); | 165 | u32 BindChannel(const std::vector<u8>& input, std::vector<u8>& output); |
| 126 | u32 GetVARegions(const std::vector<u8>& input, std::vector<u8>& output); | 166 | u32 GetVARegions(const std::vector<u8>& input, std::vector<u8>& output); |
| 127 | 167 | ||
| 168 | std::optional<BufferMap> FindBufferMap(GPUVAddr gpu_addr) const; | ||
| 169 | void AddBufferMap(GPUVAddr gpu_addr, std::size_t size, VAddr cpu_addr, bool is_allocated); | ||
| 170 | std::optional<std::size_t> RemoveBufferMap(GPUVAddr gpu_addr); | ||
| 171 | |||
| 128 | std::shared_ptr<nvmap> nvmap_dev; | 172 | std::shared_ptr<nvmap> nvmap_dev; |
| 173 | |||
| 174 | // This is expected to be ordered, therefore we must use a map, not unordered_map | ||
| 175 | std::map<GPUVAddr, BufferMap> buffer_mappings; | ||
| 129 | }; | 176 | }; |
| 130 | 177 | ||
| 131 | } // namespace Service::Nvidia::Devices | 178 | } // namespace Service::Nvidia::Devices |
diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp index 8c742316c..9436e16ad 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.cpp +++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp | |||
| @@ -18,7 +18,12 @@ enum { | |||
| 18 | }; | 18 | }; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | nvmap::nvmap(Core::System& system) : nvdevice(system) {} | 21 | nvmap::nvmap(Core::System& system) : nvdevice(system) { |
| 22 | // Handle 0 appears to be used when remapping, so we create a placeholder empty nvmap object to | ||
| 23 | // represent this. | ||
| 24 | CreateObject(0); | ||
| 25 | } | ||
| 26 | |||
| 22 | nvmap::~nvmap() = default; | 27 | nvmap::~nvmap() = default; |
| 23 | 28 | ||
| 24 | VAddr nvmap::GetObjectAddress(u32 handle) const { | 29 | VAddr nvmap::GetObjectAddress(u32 handle) const { |
| @@ -50,6 +55,21 @@ u32 nvmap::ioctl(Ioctl command, const std::vector<u8>& input, const std::vector< | |||
| 50 | return 0; | 55 | return 0; |
| 51 | } | 56 | } |
| 52 | 57 | ||
| 58 | u32 nvmap::CreateObject(u32 size) { | ||
| 59 | // Create a new nvmap object and obtain a handle to it. | ||
| 60 | auto object = std::make_shared<Object>(); | ||
| 61 | object->id = next_id++; | ||
| 62 | object->size = size; | ||
| 63 | object->status = Object::Status::Created; | ||
| 64 | object->refcount = 1; | ||
| 65 | |||
| 66 | const u32 handle = next_handle++; | ||
| 67 | |||
| 68 | handles.insert_or_assign(handle, std::move(object)); | ||
| 69 | |||
| 70 | return handle; | ||
| 71 | } | ||
| 72 | |||
| 53 | u32 nvmap::IocCreate(const std::vector<u8>& input, std::vector<u8>& output) { | 73 | u32 nvmap::IocCreate(const std::vector<u8>& input, std::vector<u8>& output) { |
| 54 | IocCreateParams params; | 74 | IocCreateParams params; |
| 55 | std::memcpy(¶ms, input.data(), sizeof(params)); | 75 | std::memcpy(¶ms, input.data(), sizeof(params)); |
| @@ -59,17 +79,8 @@ u32 nvmap::IocCreate(const std::vector<u8>& input, std::vector<u8>& output) { | |||
| 59 | LOG_ERROR(Service_NVDRV, "Size is 0"); | 79 | LOG_ERROR(Service_NVDRV, "Size is 0"); |
| 60 | return static_cast<u32>(NvErrCodes::InvalidValue); | 80 | return static_cast<u32>(NvErrCodes::InvalidValue); |
| 61 | } | 81 | } |
| 62 | // Create a new nvmap object and obtain a handle to it. | ||
| 63 | auto object = std::make_shared<Object>(); | ||
| 64 | object->id = next_id++; | ||
| 65 | object->size = params.size; | ||
| 66 | object->status = Object::Status::Created; | ||
| 67 | object->refcount = 1; | ||
| 68 | |||
| 69 | u32 handle = next_handle++; | ||
| 70 | handles[handle] = std::move(object); | ||
| 71 | 82 | ||
| 72 | params.handle = handle; | 83 | params.handle = CreateObject(params.size); |
| 73 | 84 | ||
| 74 | std::memcpy(output.data(), ¶ms, sizeof(params)); | 85 | std::memcpy(output.data(), ¶ms, sizeof(params)); |
| 75 | return 0; | 86 | return 0; |
diff --git a/src/core/hle/service/nvdrv/devices/nvmap.h b/src/core/hle/service/nvdrv/devices/nvmap.h index 73c2e8809..84624be00 100644 --- a/src/core/hle/service/nvdrv/devices/nvmap.h +++ b/src/core/hle/service/nvdrv/devices/nvmap.h | |||
| @@ -49,10 +49,10 @@ public: | |||
| 49 | 49 | ||
| 50 | private: | 50 | private: |
| 51 | /// Id to use for the next handle that is created. | 51 | /// Id to use for the next handle that is created. |
| 52 | u32 next_handle = 1; | 52 | u32 next_handle = 0; |
| 53 | 53 | ||
| 54 | /// Id to use for the next object that is created. | 54 | /// Id to use for the next object that is created. |
| 55 | u32 next_id = 1; | 55 | u32 next_id = 0; |
| 56 | 56 | ||
| 57 | /// Mapping of currently allocated handles to the objects they represent. | 57 | /// Mapping of currently allocated handles to the objects they represent. |
| 58 | std::unordered_map<u32, std::shared_ptr<Object>> handles; | 58 | std::unordered_map<u32, std::shared_ptr<Object>> handles; |
| @@ -119,6 +119,8 @@ private: | |||
| 119 | }; | 119 | }; |
| 120 | static_assert(sizeof(IocGetIdParams) == 8, "IocGetIdParams has wrong size"); | 120 | static_assert(sizeof(IocGetIdParams) == 8, "IocGetIdParams has wrong size"); |
| 121 | 121 | ||
| 122 | u32 CreateObject(u32 size); | ||
| 123 | |||
| 122 | u32 IocCreate(const std::vector<u8>& input, std::vector<u8>& output); | 124 | u32 IocCreate(const std::vector<u8>& input, std::vector<u8>& output); |
| 123 | u32 IocAlloc(const std::vector<u8>& input, std::vector<u8>& output); | 125 | u32 IocAlloc(const std::vector<u8>& input, std::vector<u8>& output); |
| 124 | u32 IocGetId(const std::vector<u8>& input, std::vector<u8>& output); | 126 | u32 IocGetId(const std::vector<u8>& input, std::vector<u8>& output); |
diff --git a/src/core/hle/service/nvdrv/interface.cpp b/src/core/hle/service/nvdrv/interface.cpp index deaf0808b..88fbfa9b0 100644 --- a/src/core/hle/service/nvdrv/interface.cpp +++ b/src/core/hle/service/nvdrv/interface.cpp | |||
| @@ -60,24 +60,24 @@ void NVDRV::IoctlBase(Kernel::HLERequestContext& ctx, IoctlVersion version) { | |||
| 60 | 60 | ||
| 61 | if (ctrl.must_delay) { | 61 | if (ctrl.must_delay) { |
| 62 | ctrl.fresh_call = false; | 62 | ctrl.fresh_call = false; |
| 63 | ctx.SleepClientThread("NVServices::DelayedResponse", ctrl.timeout, | 63 | ctx.SleepClientThread( |
| 64 | [=](std::shared_ptr<Kernel::Thread> thread, | 64 | "NVServices::DelayedResponse", ctrl.timeout, |
| 65 | Kernel::HLERequestContext& ctx, | 65 | [=, this](std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx_, |
| 66 | Kernel::ThreadWakeupReason reason) { | 66 | Kernel::ThreadWakeupReason reason) { |
| 67 | IoctlCtrl ctrl2{ctrl}; | 67 | IoctlCtrl ctrl2{ctrl}; |
| 68 | std::vector<u8> tmp_output = output; | 68 | std::vector<u8> tmp_output = output; |
| 69 | std::vector<u8> tmp_output2 = output2; | 69 | std::vector<u8> tmp_output2 = output2; |
| 70 | u32 result = nvdrv->Ioctl(fd, command, input, input2, tmp_output, | 70 | const u32 ioctl_result = nvdrv->Ioctl(fd, command, input, input2, tmp_output, |
| 71 | tmp_output2, ctrl2, version); | 71 | tmp_output2, ctrl2, version); |
| 72 | ctx.WriteBuffer(tmp_output, 0); | 72 | ctx_.WriteBuffer(tmp_output, 0); |
| 73 | if (version == IoctlVersion::Version3) { | 73 | if (version == IoctlVersion::Version3) { |
| 74 | ctx.WriteBuffer(tmp_output2, 1); | 74 | ctx_.WriteBuffer(tmp_output2, 1); |
| 75 | } | 75 | } |
| 76 | IPC::ResponseBuilder rb{ctx, 3}; | 76 | IPC::ResponseBuilder rb{ctx_, 3}; |
| 77 | rb.Push(RESULT_SUCCESS); | 77 | rb.Push(RESULT_SUCCESS); |
| 78 | rb.Push(result); | 78 | rb.Push(ioctl_result); |
| 79 | }, | 79 | }, |
| 80 | nvdrv->GetEventWriteable(ctrl.event_id)); | 80 | nvdrv->GetEventWriteable(ctrl.event_id)); |
| 81 | } else { | 81 | } else { |
| 82 | ctx.WriteBuffer(output); | 82 | ctx.WriteBuffer(output); |
| 83 | if (version == IoctlVersion::Version3) { | 83 | if (version == IoctlVersion::Version3) { |
diff --git a/src/core/hle/service/nvflinger/buffer_queue.cpp b/src/core/hle/service/nvflinger/buffer_queue.cpp index caca80dde..637b310d7 100644 --- a/src/core/hle/service/nvflinger/buffer_queue.cpp +++ b/src/core/hle/service/nvflinger/buffer_queue.cpp | |||
| @@ -24,13 +24,13 @@ BufferQueue::~BufferQueue() = default; | |||
| 24 | void BufferQueue::SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer) { | 24 | void BufferQueue::SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer) { |
| 25 | LOG_WARNING(Service, "Adding graphics buffer {}", slot); | 25 | LOG_WARNING(Service, "Adding graphics buffer {}", slot); |
| 26 | 26 | ||
| 27 | Buffer buffer{}; | ||
| 28 | buffer.slot = slot; | ||
| 29 | buffer.igbp_buffer = igbp_buffer; | ||
| 30 | buffer.status = Buffer::Status::Free; | ||
| 31 | free_buffers.push_back(slot); | 27 | free_buffers.push_back(slot); |
| 28 | queue.push_back({ | ||
| 29 | .slot = slot, | ||
| 30 | .status = Buffer::Status::Free, | ||
| 31 | .igbp_buffer = igbp_buffer, | ||
| 32 | }); | ||
| 32 | 33 | ||
| 33 | queue.emplace_back(buffer); | ||
| 34 | buffer_wait_event.writable->Signal(); | 34 | buffer_wait_event.writable->Signal(); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| @@ -38,7 +38,7 @@ std::optional<std::pair<u32, Service::Nvidia::MultiFence*>> BufferQueue::Dequeue | |||
| 38 | u32 height) { | 38 | u32 height) { |
| 39 | 39 | ||
| 40 | if (free_buffers.empty()) { | 40 | if (free_buffers.empty()) { |
| 41 | return {}; | 41 | return std::nullopt; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | auto f_itr = free_buffers.begin(); | 44 | auto f_itr = free_buffers.begin(); |
| @@ -69,7 +69,7 @@ std::optional<std::pair<u32, Service::Nvidia::MultiFence*>> BufferQueue::Dequeue | |||
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | if (itr == queue.end()) { | 71 | if (itr == queue.end()) { |
| 72 | return {}; | 72 | return std::nullopt; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | itr->status = Buffer::Status::Dequeued; | 75 | itr->status = Buffer::Status::Dequeued; |
| @@ -103,14 +103,15 @@ std::optional<std::reference_wrapper<const BufferQueue::Buffer>> BufferQueue::Ac | |||
| 103 | auto itr = queue.end(); | 103 | auto itr = queue.end(); |
| 104 | // Iterate to find a queued buffer matching the requested slot. | 104 | // Iterate to find a queued buffer matching the requested slot. |
| 105 | while (itr == queue.end() && !queue_sequence.empty()) { | 105 | while (itr == queue.end() && !queue_sequence.empty()) { |
| 106 | u32 slot = queue_sequence.front(); | 106 | const u32 slot = queue_sequence.front(); |
| 107 | itr = std::find_if(queue.begin(), queue.end(), [&slot](const Buffer& buffer) { | 107 | itr = std::find_if(queue.begin(), queue.end(), [&slot](const Buffer& buffer) { |
| 108 | return buffer.status == Buffer::Status::Queued && buffer.slot == slot; | 108 | return buffer.status == Buffer::Status::Queued && buffer.slot == slot; |
| 109 | }); | 109 | }); |
| 110 | queue_sequence.pop_front(); | 110 | queue_sequence.pop_front(); |
| 111 | } | 111 | } |
| 112 | if (itr == queue.end()) | 112 | if (itr == queue.end()) { |
| 113 | return {}; | 113 | return std::nullopt; |
| 114 | } | ||
| 114 | itr->status = Buffer::Status::Acquired; | 115 | itr->status = Buffer::Status::Acquired; |
| 115 | return *itr; | 116 | return *itr; |
| 116 | } | 117 | } |
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index 789856118..f644a460d 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp | |||
| @@ -67,8 +67,8 @@ NVFlinger::NVFlinger(Core::System& system) : system(system) { | |||
| 67 | 67 | ||
| 68 | // Schedule the screen composition events | 68 | // Schedule the screen composition events |
| 69 | composition_event = Core::Timing::CreateEvent( | 69 | composition_event = Core::Timing::CreateEvent( |
| 70 | "ScreenComposition", [this](u64, std::chrono::nanoseconds ns_late) { | 70 | "ScreenComposition", [this](std::uintptr_t, std::chrono::nanoseconds ns_late) { |
| 71 | Lock(); | 71 | const auto guard = Lock(); |
| 72 | Compose(); | 72 | Compose(); |
| 73 | 73 | ||
| 74 | const auto ticks = std::chrono::nanoseconds{GetNextTicks()}; | 74 | const auto ticks = std::chrono::nanoseconds{GetNextTicks()}; |
diff --git a/src/core/hle/service/nvflinger/nvflinger.h b/src/core/hle/service/nvflinger/nvflinger.h index e4959a9af..ff85cbba6 100644 --- a/src/core/hle/service/nvflinger/nvflinger.h +++ b/src/core/hle/service/nvflinger/nvflinger.h | |||
| @@ -54,12 +54,12 @@ public: | |||
| 54 | /// Opens the specified display and returns the ID. | 54 | /// Opens the specified display and returns the ID. |
| 55 | /// | 55 | /// |
| 56 | /// If an invalid display name is provided, then an empty optional is returned. | 56 | /// If an invalid display name is provided, then an empty optional is returned. |
| 57 | std::optional<u64> OpenDisplay(std::string_view name); | 57 | [[nodiscard]] std::optional<u64> OpenDisplay(std::string_view name); |
| 58 | 58 | ||
| 59 | /// Creates a layer on the specified display and returns the layer ID. | 59 | /// Creates a layer on the specified display and returns the layer ID. |
| 60 | /// | 60 | /// |
| 61 | /// If an invalid display ID is specified, then an empty optional is returned. | 61 | /// If an invalid display ID is specified, then an empty optional is returned. |
| 62 | std::optional<u64> CreateLayer(u64 display_id); | 62 | [[nodiscard]] std::optional<u64> CreateLayer(u64 display_id); |
| 63 | 63 | ||
| 64 | /// Closes a layer on all displays for the given layer ID. | 64 | /// Closes a layer on all displays for the given layer ID. |
| 65 | void CloseLayer(u64 layer_id); | 65 | void CloseLayer(u64 layer_id); |
| @@ -67,41 +67,39 @@ public: | |||
| 67 | /// Finds the buffer queue ID of the specified layer in the specified display. | 67 | /// Finds the buffer queue ID of the specified layer in the specified display. |
| 68 | /// | 68 | /// |
| 69 | /// If an invalid display ID or layer ID is provided, then an empty optional is returned. | 69 | /// If an invalid display ID or layer ID is provided, then an empty optional is returned. |
| 70 | std::optional<u32> FindBufferQueueId(u64 display_id, u64 layer_id) const; | 70 | [[nodiscard]] std::optional<u32> FindBufferQueueId(u64 display_id, u64 layer_id) const; |
| 71 | 71 | ||
| 72 | /// Gets the vsync event for the specified display. | 72 | /// Gets the vsync event for the specified display. |
| 73 | /// | 73 | /// |
| 74 | /// If an invalid display ID is provided, then nullptr is returned. | 74 | /// If an invalid display ID is provided, then nullptr is returned. |
| 75 | std::shared_ptr<Kernel::ReadableEvent> FindVsyncEvent(u64 display_id) const; | 75 | [[nodiscard]] std::shared_ptr<Kernel::ReadableEvent> FindVsyncEvent(u64 display_id) const; |
| 76 | 76 | ||
| 77 | /// Obtains a buffer queue identified by the ID. | 77 | /// Obtains a buffer queue identified by the ID. |
| 78 | BufferQueue& FindBufferQueue(u32 id); | 78 | [[nodiscard]] BufferQueue& FindBufferQueue(u32 id); |
| 79 | 79 | ||
| 80 | /// Obtains a buffer queue identified by the ID. | 80 | /// Obtains a buffer queue identified by the ID. |
| 81 | const BufferQueue& FindBufferQueue(u32 id) const; | 81 | [[nodiscard]] const BufferQueue& FindBufferQueue(u32 id) const; |
| 82 | 82 | ||
| 83 | /// Performs a composition request to the emulated nvidia GPU and triggers the vsync events when | 83 | /// Performs a composition request to the emulated nvidia GPU and triggers the vsync events when |
| 84 | /// finished. | 84 | /// finished. |
| 85 | void Compose(); | 85 | void Compose(); |
| 86 | 86 | ||
| 87 | s64 GetNextTicks() const; | 87 | [[nodiscard]] s64 GetNextTicks() const; |
| 88 | 88 | ||
| 89 | std::unique_lock<std::mutex> Lock() { | 89 | [[nodiscard]] std::unique_lock<std::mutex> Lock() const { return std::unique_lock{*guard}; } |
| 90 | return std::unique_lock{*guard}; | ||
| 91 | } | ||
| 92 | 90 | ||
| 93 | private: | 91 | private : |
| 94 | /// Finds the display identified by the specified ID. | 92 | /// Finds the display identified by the specified ID. |
| 95 | VI::Display* FindDisplay(u64 display_id); | 93 | [[nodiscard]] VI::Display* FindDisplay(u64 display_id); |
| 96 | 94 | ||
| 97 | /// Finds the display identified by the specified ID. | 95 | /// Finds the display identified by the specified ID. |
| 98 | const VI::Display* FindDisplay(u64 display_id) const; | 96 | [[nodiscard]] const VI::Display* FindDisplay(u64 display_id) const; |
| 99 | 97 | ||
| 100 | /// Finds the layer identified by the specified ID in the desired display. | 98 | /// Finds the layer identified by the specified ID in the desired display. |
| 101 | VI::Layer* FindLayer(u64 display_id, u64 layer_id); | 99 | [[nodiscard]] VI::Layer* FindLayer(u64 display_id, u64 layer_id); |
| 102 | 100 | ||
| 103 | /// Finds the layer identified by the specified ID in the desired display. | 101 | /// Finds the layer identified by the specified ID in the desired display. |
| 104 | const VI::Layer* FindLayer(u64 display_id, u64 layer_id) const; | 102 | [[nodiscard]] const VI::Layer* FindLayer(u64 display_id, u64 layer_id) const; |
| 105 | 103 | ||
| 106 | static void VSyncThread(NVFlinger& nv_flinger); | 104 | static void VSyncThread(NVFlinger& nv_flinger); |
| 107 | 105 | ||
diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index 34fe2fd82..e64777668 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp | |||
| @@ -106,7 +106,7 @@ void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) { | |||
| 106 | 106 | ||
| 107 | IPC::ResponseBuilder rb{ctx, 2}; | 107 | IPC::ResponseBuilder rb{ctx, 2}; |
| 108 | rb.Push(RESULT_SUCCESS); | 108 | rb.Push(RESULT_SUCCESS); |
| 109 | ctx.WriteBuffer(&layout, sizeof(KeyboardLayout)); | 109 | ctx.WriteBuffer(layout); |
| 110 | } | 110 | } |
| 111 | } // Anonymous namespace | 111 | } // Anonymous namespace |
| 112 | 112 | ||
diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h index b06d2f103..aabf166b7 100644 --- a/src/core/hle/service/sm/sm.h +++ b/src/core/hle/service/sm/sm.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <type_traits> | 9 | #include <type_traits> |
| 10 | #include <unordered_map> | 10 | #include <unordered_map> |
| 11 | 11 | ||
| 12 | #include "common/concepts.h" | ||
| 12 | #include "core/hle/kernel/client_port.h" | 13 | #include "core/hle/kernel/client_port.h" |
| 13 | #include "core/hle/kernel/object.h" | 14 | #include "core/hle/kernel/object.h" |
| 14 | #include "core/hle/kernel/server_port.h" | 15 | #include "core/hle/kernel/server_port.h" |
| @@ -56,10 +57,8 @@ public: | |||
| 56 | ResultVal<std::shared_ptr<Kernel::ClientPort>> GetServicePort(const std::string& name); | 57 | ResultVal<std::shared_ptr<Kernel::ClientPort>> GetServicePort(const std::string& name); |
| 57 | ResultVal<std::shared_ptr<Kernel::ClientSession>> ConnectToService(const std::string& name); | 58 | ResultVal<std::shared_ptr<Kernel::ClientSession>> ConnectToService(const std::string& name); |
| 58 | 59 | ||
| 59 | template <typename T> | 60 | template <Common::DerivedFrom<Kernel::SessionRequestHandler> T> |
| 60 | std::shared_ptr<T> GetService(const std::string& service_name) const { | 61 | std::shared_ptr<T> GetService(const std::string& service_name) const { |
| 61 | static_assert(std::is_base_of_v<Kernel::SessionRequestHandler, T>, | ||
| 62 | "Not a base of ServiceFrameworkBase"); | ||
| 63 | auto service = registered_services.find(service_name); | 62 | auto service = registered_services.find(service_name); |
| 64 | if (service == registered_services.end()) { | 63 | if (service == registered_services.end()) { |
| 65 | LOG_DEBUG(Service, "Can't find service: {}", service_name); | 64 | LOG_DEBUG(Service, "Can't find service: {}", service_name); |
diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index 13e4b3818..ee4fa4b48 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp | |||
| @@ -290,7 +290,7 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { | |||
| 290 | 290 | ||
| 291 | IPC::ResponseBuilder rb{ctx, 2}; | 291 | IPC::ResponseBuilder rb{ctx, 2}; |
| 292 | rb.Push(RESULT_SUCCESS); | 292 | rb.Push(RESULT_SUCCESS); |
| 293 | ctx.WriteBuffer(&clock_snapshot, sizeof(Clock::ClockSnapshot)); | 293 | ctx.WriteBuffer(clock_snapshot); |
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLERequestContext& ctx) { | 296 | void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLERequestContext& ctx) { |
| @@ -313,7 +313,7 @@ void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLEReques | |||
| 313 | 313 | ||
| 314 | IPC::ResponseBuilder rb{ctx, 2}; | 314 | IPC::ResponseBuilder rb{ctx, 2}; |
| 315 | rb.Push(RESULT_SUCCESS); | 315 | rb.Push(RESULT_SUCCESS); |
| 316 | ctx.WriteBuffer(&clock_snapshot, sizeof(Clock::ClockSnapshot)); | 316 | ctx.WriteBuffer(clock_snapshot); |
| 317 | } | 317 | } |
| 318 | 318 | ||
| 319 | void Module::Interface::CalculateStandardUserSystemClockDifferenceByUser( | 319 | void Module::Interface::CalculateStandardUserSystemClockDifferenceByUser( |
diff --git a/src/core/hle/service/time/time_zone_service.cpp b/src/core/hle/service/time/time_zone_service.cpp index db57ae069..ff3a10b3e 100644 --- a/src/core/hle/service/time/time_zone_service.cpp +++ b/src/core/hle/service/time/time_zone_service.cpp | |||
| @@ -142,7 +142,7 @@ void ITimeZoneService::ToPosixTime(Kernel::HLERequestContext& ctx) { | |||
| 142 | IPC::ResponseBuilder rb{ctx, 3}; | 142 | IPC::ResponseBuilder rb{ctx, 3}; |
| 143 | rb.Push(RESULT_SUCCESS); | 143 | rb.Push(RESULT_SUCCESS); |
| 144 | rb.PushRaw<u32>(1); // Number of times we're returning | 144 | rb.PushRaw<u32>(1); // Number of times we're returning |
| 145 | ctx.WriteBuffer(&posix_time, sizeof(s64)); | 145 | ctx.WriteBuffer(posix_time); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | void ITimeZoneService::ToPosixTimeWithMyRule(Kernel::HLERequestContext& ctx) { | 148 | void ITimeZoneService::ToPosixTimeWithMyRule(Kernel::HLERequestContext& ctx) { |
| @@ -164,7 +164,7 @@ void ITimeZoneService::ToPosixTimeWithMyRule(Kernel::HLERequestContext& ctx) { | |||
| 164 | IPC::ResponseBuilder rb{ctx, 3}; | 164 | IPC::ResponseBuilder rb{ctx, 3}; |
| 165 | rb.Push(RESULT_SUCCESS); | 165 | rb.Push(RESULT_SUCCESS); |
| 166 | rb.PushRaw<u32>(1); // Number of times we're returning | 166 | rb.PushRaw<u32>(1); // Number of times we're returning |
| 167 | ctx.WriteBuffer(&posix_time, sizeof(s64)); | 167 | ctx.WriteBuffer(posix_time); |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | } // namespace Service::Time | 170 | } // namespace Service::Time |
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index ea7b4ae13..480d34725 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp | |||
| @@ -511,7 +511,7 @@ private: | |||
| 511 | LOG_DEBUG(Service_VI, "called. id=0x{:08X} transaction={:X}, flags=0x{:08X}", id, | 511 | LOG_DEBUG(Service_VI, "called. id=0x{:08X} transaction={:X}, flags=0x{:08X}", id, |
| 512 | static_cast<u32>(transaction), flags); | 512 | static_cast<u32>(transaction), flags); |
| 513 | 513 | ||
| 514 | nv_flinger->Lock(); | 514 | const auto guard = nv_flinger->Lock(); |
| 515 | auto& buffer_queue = nv_flinger->FindBufferQueue(id); | 515 | auto& buffer_queue = nv_flinger->FindBufferQueue(id); |
| 516 | 516 | ||
| 517 | switch (transaction) { | 517 | switch (transaction) { |
| @@ -548,10 +548,10 @@ private: | |||
| 548 | // Wait the current thread until a buffer becomes available | 548 | // Wait the current thread until a buffer becomes available |
| 549 | ctx.SleepClientThread( | 549 | ctx.SleepClientThread( |
| 550 | "IHOSBinderDriver::DequeueBuffer", UINT64_MAX, | 550 | "IHOSBinderDriver::DequeueBuffer", UINT64_MAX, |
| 551 | [=](std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx, | 551 | [=, this](std::shared_ptr<Kernel::Thread> thread, |
| 552 | Kernel::ThreadWakeupReason reason) { | 552 | Kernel::HLERequestContext& ctx, Kernel::ThreadWakeupReason reason) { |
| 553 | // Repeat TransactParcel DequeueBuffer when a buffer is available | 553 | // Repeat TransactParcel DequeueBuffer when a buffer is available |
| 554 | nv_flinger->Lock(); | 554 | const auto guard = nv_flinger->Lock(); |
| 555 | auto& buffer_queue = nv_flinger->FindBufferQueue(id); | 555 | auto& buffer_queue = nv_flinger->FindBufferQueue(id); |
| 556 | auto result = buffer_queue.DequeueBuffer(width, height); | 556 | auto result = buffer_queue.DequeueBuffer(width, height); |
| 557 | ASSERT_MSG(result != std::nullopt, "Could not dequeue buffer."); | 557 | ASSERT_MSG(result != std::nullopt, "Could not dequeue buffer."); |
| @@ -1199,6 +1199,23 @@ private: | |||
| 1199 | } | 1199 | } |
| 1200 | } | 1200 | } |
| 1201 | 1201 | ||
| 1202 | void GetIndirectLayerImageRequiredMemoryInfo(Kernel::HLERequestContext& ctx) { | ||
| 1203 | IPC::RequestParser rp{ctx}; | ||
| 1204 | const auto width = rp.Pop<u64>(); | ||
| 1205 | const auto height = rp.Pop<u64>(); | ||
| 1206 | LOG_DEBUG(Service_VI, "called width={}, height={}", width, height); | ||
| 1207 | |||
| 1208 | constexpr std::size_t base_size = 0x20000; | ||
| 1209 | constexpr std::size_t alignment = 0x1000; | ||
| 1210 | const auto texture_size = width * height * 4; | ||
| 1211 | const auto out_size = (texture_size + base_size - 1) / base_size * base_size; | ||
| 1212 | |||
| 1213 | IPC::ResponseBuilder rb{ctx, 6}; | ||
| 1214 | rb.Push(RESULT_SUCCESS); | ||
| 1215 | rb.Push(out_size); | ||
| 1216 | rb.Push(alignment); | ||
| 1217 | } | ||
| 1218 | |||
| 1202 | static ResultVal<ConvertedScaleMode> ConvertScalingModeImpl(NintendoScaleMode mode) { | 1219 | static ResultVal<ConvertedScaleMode> ConvertScalingModeImpl(NintendoScaleMode mode) { |
| 1203 | switch (mode) { | 1220 | switch (mode) { |
| 1204 | case NintendoScaleMode::None: | 1221 | case NintendoScaleMode::None: |
| @@ -1243,7 +1260,8 @@ IApplicationDisplayService::IApplicationDisplayService( | |||
| 1243 | {2102, &IApplicationDisplayService::ConvertScalingMode, "ConvertScalingMode"}, | 1260 | {2102, &IApplicationDisplayService::ConvertScalingMode, "ConvertScalingMode"}, |
| 1244 | {2450, nullptr, "GetIndirectLayerImageMap"}, | 1261 | {2450, nullptr, "GetIndirectLayerImageMap"}, |
| 1245 | {2451, nullptr, "GetIndirectLayerImageCropMap"}, | 1262 | {2451, nullptr, "GetIndirectLayerImageCropMap"}, |
| 1246 | {2460, nullptr, "GetIndirectLayerImageRequiredMemoryInfo"}, | 1263 | {2460, &IApplicationDisplayService::GetIndirectLayerImageRequiredMemoryInfo, |
| 1264 | "GetIndirectLayerImageRequiredMemoryInfo"}, | ||
| 1247 | {5202, &IApplicationDisplayService::GetDisplayVsyncEvent, "GetDisplayVsyncEvent"}, | 1265 | {5202, &IApplicationDisplayService::GetDisplayVsyncEvent, "GetDisplayVsyncEvent"}, |
| 1248 | {5203, nullptr, "GetDisplayVsyncEventForDebug"}, | 1266 | {5203, nullptr, "GetDisplayVsyncEventForDebug"}, |
| 1249 | }; | 1267 | }; |
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 59ca7091a..7c48e55e1 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -3,8 +3,10 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | #include <optional> | ||
| 6 | #include <ostream> | 7 | #include <ostream> |
| 7 | #include <string> | 8 | #include <string> |
| 9 | #include "common/concepts.h" | ||
| 8 | #include "common/file_util.h" | 10 | #include "common/file_util.h" |
| 9 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 10 | #include "common/string_util.h" | 12 | #include "common/string_util.h" |
| @@ -21,27 +23,41 @@ | |||
| 21 | 23 | ||
| 22 | namespace Loader { | 24 | namespace Loader { |
| 23 | 25 | ||
| 24 | FileType IdentifyFile(FileSys::VirtualFile file) { | 26 | namespace { |
| 25 | FileType type; | ||
| 26 | |||
| 27 | #define CHECK_TYPE(loader) \ | ||
| 28 | type = AppLoader_##loader::IdentifyType(file); \ | ||
| 29 | if (FileType::Error != type) \ | ||
| 30 | return type; | ||
| 31 | 27 | ||
| 32 | CHECK_TYPE(DeconstructedRomDirectory) | 28 | template <Common::DerivedFrom<AppLoader> T> |
| 33 | CHECK_TYPE(ELF) | 29 | std::optional<FileType> IdentifyFileLoader(FileSys::VirtualFile file) { |
| 34 | CHECK_TYPE(NSO) | 30 | const auto file_type = T::IdentifyType(file); |
| 35 | CHECK_TYPE(NRO) | 31 | if (file_type != FileType::Error) { |
| 36 | CHECK_TYPE(NCA) | 32 | return file_type; |
| 37 | CHECK_TYPE(XCI) | 33 | } |
| 38 | CHECK_TYPE(NAX) | 34 | return std::nullopt; |
| 39 | CHECK_TYPE(NSP) | 35 | } |
| 40 | CHECK_TYPE(KIP) | ||
| 41 | 36 | ||
| 42 | #undef CHECK_TYPE | 37 | } // namespace |
| 43 | 38 | ||
| 44 | return FileType::Unknown; | 39 | FileType IdentifyFile(FileSys::VirtualFile file) { |
| 40 | if (const auto romdir_type = IdentifyFileLoader<AppLoader_DeconstructedRomDirectory>(file)) { | ||
| 41 | return *romdir_type; | ||
| 42 | } else if (const auto elf_type = IdentifyFileLoader<AppLoader_ELF>(file)) { | ||
| 43 | return *elf_type; | ||
| 44 | } else if (const auto nso_type = IdentifyFileLoader<AppLoader_NSO>(file)) { | ||
| 45 | return *nso_type; | ||
| 46 | } else if (const auto nro_type = IdentifyFileLoader<AppLoader_NRO>(file)) { | ||
| 47 | return *nro_type; | ||
| 48 | } else if (const auto nca_type = IdentifyFileLoader<AppLoader_NCA>(file)) { | ||
| 49 | return *nca_type; | ||
| 50 | } else if (const auto xci_type = IdentifyFileLoader<AppLoader_XCI>(file)) { | ||
| 51 | return *xci_type; | ||
| 52 | } else if (const auto nax_type = IdentifyFileLoader<AppLoader_NAX>(file)) { | ||
| 53 | return *nax_type; | ||
| 54 | } else if (const auto nsp_type = IdentifyFileLoader<AppLoader_NSP>(file)) { | ||
| 55 | return *nsp_type; | ||
| 56 | } else if (const auto kip_type = IdentifyFileLoader<AppLoader_KIP>(file)) { | ||
| 57 | return *kip_type; | ||
| 58 | } else { | ||
| 59 | return FileType::Unknown; | ||
| 60 | } | ||
| 45 | } | 61 | } |
| 46 | 62 | ||
| 47 | FileType GuessFromFilename(const std::string& name) { | 63 | FileType GuessFromFilename(const std::string& name) { |
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 2c5588933..86d17c6cb 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -704,7 +704,7 @@ struct Memory::Impl { | |||
| 704 | u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; | 704 | u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; |
| 705 | if (page_pointer != nullptr) { | 705 | if (page_pointer != nullptr) { |
| 706 | // NOTE: Avoid adding any extra logic to this fast-path block | 706 | // NOTE: Avoid adding any extra logic to this fast-path block |
| 707 | T volatile* pointer = reinterpret_cast<T volatile*>(&page_pointer[vaddr]); | 707 | auto* pointer = reinterpret_cast<volatile T*>(&page_pointer[vaddr]); |
| 708 | return Common::AtomicCompareAndSwap(pointer, data, expected); | 708 | return Common::AtomicCompareAndSwap(pointer, data, expected); |
| 709 | } | 709 | } |
| 710 | 710 | ||
| @@ -720,9 +720,8 @@ struct Memory::Impl { | |||
| 720 | case Common::PageType::RasterizerCachedMemory: { | 720 | case Common::PageType::RasterizerCachedMemory: { |
| 721 | u8* host_ptr{GetPointerFromRasterizerCachedMemory(vaddr)}; | 721 | u8* host_ptr{GetPointerFromRasterizerCachedMemory(vaddr)}; |
| 722 | system.GPU().InvalidateRegion(vaddr, sizeof(T)); | 722 | system.GPU().InvalidateRegion(vaddr, sizeof(T)); |
| 723 | T volatile* pointer = reinterpret_cast<T volatile*>(&host_ptr); | 723 | auto* pointer = reinterpret_cast<volatile T*>(&host_ptr); |
| 724 | return Common::AtomicCompareAndSwap(pointer, data, expected); | 724 | return Common::AtomicCompareAndSwap(pointer, data, expected); |
| 725 | break; | ||
| 726 | } | 725 | } |
| 727 | default: | 726 | default: |
| 728 | UNREACHABLE(); | 727 | UNREACHABLE(); |
| @@ -734,7 +733,7 @@ struct Memory::Impl { | |||
| 734 | u8* const page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; | 733 | u8* const page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; |
| 735 | if (page_pointer != nullptr) { | 734 | if (page_pointer != nullptr) { |
| 736 | // NOTE: Avoid adding any extra logic to this fast-path block | 735 | // NOTE: Avoid adding any extra logic to this fast-path block |
| 737 | u64 volatile* pointer = reinterpret_cast<u64 volatile*>(&page_pointer[vaddr]); | 736 | auto* pointer = reinterpret_cast<volatile u64*>(&page_pointer[vaddr]); |
| 738 | return Common::AtomicCompareAndSwap(pointer, data, expected); | 737 | return Common::AtomicCompareAndSwap(pointer, data, expected); |
| 739 | } | 738 | } |
| 740 | 739 | ||
| @@ -750,9 +749,8 @@ struct Memory::Impl { | |||
| 750 | case Common::PageType::RasterizerCachedMemory: { | 749 | case Common::PageType::RasterizerCachedMemory: { |
| 751 | u8* host_ptr{GetPointerFromRasterizerCachedMemory(vaddr)}; | 750 | u8* host_ptr{GetPointerFromRasterizerCachedMemory(vaddr)}; |
| 752 | system.GPU().InvalidateRegion(vaddr, sizeof(u128)); | 751 | system.GPU().InvalidateRegion(vaddr, sizeof(u128)); |
| 753 | u64 volatile* pointer = reinterpret_cast<u64 volatile*>(&host_ptr); | 752 | auto* pointer = reinterpret_cast<volatile u64*>(&host_ptr); |
| 754 | return Common::AtomicCompareAndSwap(pointer, data, expected); | 753 | return Common::AtomicCompareAndSwap(pointer, data, expected); |
| 755 | break; | ||
| 756 | } | 754 | } |
| 757 | default: | 755 | default: |
| 758 | UNREACHABLE(); | 756 | UNREACHABLE(); |
diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp index ced41b1fe..eeebdf02e 100644 --- a/src/core/memory/cheat_engine.cpp +++ b/src/core/memory/cheat_engine.cpp | |||
| @@ -188,11 +188,11 @@ CheatEngine::~CheatEngine() { | |||
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | void CheatEngine::Initialize() { | 190 | void CheatEngine::Initialize() { |
| 191 | event = Core::Timing::CreateEvent("CheatEngine::FrameCallback::" + | 191 | event = Core::Timing::CreateEvent( |
| 192 | Common::HexToString(metadata.main_nso_build_id), | 192 | "CheatEngine::FrameCallback::" + Common::HexToString(metadata.main_nso_build_id), |
| 193 | [this](u64 userdata, std::chrono::nanoseconds ns_late) { | 193 | [this](std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { |
| 194 | FrameCallback(userdata, ns_late); | 194 | FrameCallback(user_data, ns_late); |
| 195 | }); | 195 | }); |
| 196 | core_timing.ScheduleEvent(CHEAT_ENGINE_NS, event); | 196 | core_timing.ScheduleEvent(CHEAT_ENGINE_NS, event); |
| 197 | 197 | ||
| 198 | metadata.process_id = system.CurrentProcess()->GetProcessID(); | 198 | metadata.process_id = system.CurrentProcess()->GetProcessID(); |
| @@ -219,7 +219,7 @@ void CheatEngine::Reload(std::vector<CheatEntry> cheats) { | |||
| 219 | 219 | ||
| 220 | MICROPROFILE_DEFINE(Cheat_Engine, "Add-Ons", "Cheat Engine", MP_RGB(70, 200, 70)); | 220 | MICROPROFILE_DEFINE(Cheat_Engine, "Add-Ons", "Cheat Engine", MP_RGB(70, 200, 70)); |
| 221 | 221 | ||
| 222 | void CheatEngine::FrameCallback(u64, std::chrono::nanoseconds ns_late) { | 222 | void CheatEngine::FrameCallback(std::uintptr_t, std::chrono::nanoseconds ns_late) { |
| 223 | if (is_pending_reload.exchange(false)) { | 223 | if (is_pending_reload.exchange(false)) { |
| 224 | vm.LoadProgram(cheats); | 224 | vm.LoadProgram(cheats); |
| 225 | } | 225 | } |
diff --git a/src/core/memory/cheat_engine.h b/src/core/memory/cheat_engine.h index d4068cf84..fa039a831 100644 --- a/src/core/memory/cheat_engine.h +++ b/src/core/memory/cheat_engine.h | |||
| @@ -72,7 +72,7 @@ public: | |||
| 72 | void Reload(std::vector<CheatEntry> cheats); | 72 | void Reload(std::vector<CheatEntry> cheats); |
| 73 | 73 | ||
| 74 | private: | 74 | private: |
| 75 | void FrameCallback(u64 userdata, std::chrono::nanoseconds ns_late); | 75 | void FrameCallback(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); |
| 76 | 76 | ||
| 77 | DmntCheatVm vm; | 77 | DmntCheatVm vm; |
| 78 | CheatProcessMetadata metadata; | 78 | CheatProcessMetadata metadata; |
diff --git a/src/core/memory/dmnt_cheat_vm.cpp b/src/core/memory/dmnt_cheat_vm.cpp index 2e7da23fe..48be80c12 100644 --- a/src/core/memory/dmnt_cheat_vm.cpp +++ b/src/core/memory/dmnt_cheat_vm.cpp | |||
| @@ -313,30 +313,32 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 313 | 313 | ||
| 314 | switch (opcode_type) { | 314 | switch (opcode_type) { |
| 315 | case CheatVmOpcodeType::StoreStatic: { | 315 | case CheatVmOpcodeType::StoreStatic: { |
| 316 | StoreStaticOpcode store_static{}; | ||
| 317 | // 0TMR00AA AAAAAAAA YYYYYYYY (YYYYYYYY) | 316 | // 0TMR00AA AAAAAAAA YYYYYYYY (YYYYYYYY) |
| 318 | // Read additional words. | 317 | // Read additional words. |
| 319 | const u32 second_dword = GetNextDword(); | 318 | const u32 second_dword = GetNextDword(); |
| 320 | store_static.bit_width = (first_dword >> 24) & 0xF; | 319 | const u32 bit_width = (first_dword >> 24) & 0xF; |
| 321 | store_static.mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF); | 320 | |
| 322 | store_static.offset_register = ((first_dword >> 16) & 0xF); | 321 | opcode.opcode = StoreStaticOpcode{ |
| 323 | store_static.rel_address = | 322 | .bit_width = bit_width, |
| 324 | (static_cast<u64>(first_dword & 0xFF) << 32ul) | static_cast<u64>(second_dword); | 323 | .mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF), |
| 325 | store_static.value = GetNextVmInt(store_static.bit_width); | 324 | .offset_register = (first_dword >> 16) & 0xF, |
| 326 | opcode.opcode = store_static; | 325 | .rel_address = (static_cast<u64>(first_dword & 0xFF) << 32) | second_dword, |
| 326 | .value = GetNextVmInt(bit_width), | ||
| 327 | }; | ||
| 327 | } break; | 328 | } break; |
| 328 | case CheatVmOpcodeType::BeginConditionalBlock: { | 329 | case CheatVmOpcodeType::BeginConditionalBlock: { |
| 329 | BeginConditionalOpcode begin_cond{}; | ||
| 330 | // 1TMC00AA AAAAAAAA YYYYYYYY (YYYYYYYY) | 330 | // 1TMC00AA AAAAAAAA YYYYYYYY (YYYYYYYY) |
| 331 | // Read additional words. | 331 | // Read additional words. |
| 332 | const u32 second_dword = GetNextDword(); | 332 | const u32 second_dword = GetNextDword(); |
| 333 | begin_cond.bit_width = (first_dword >> 24) & 0xF; | 333 | const u32 bit_width = (first_dword >> 24) & 0xF; |
| 334 | begin_cond.mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF); | 334 | |
| 335 | begin_cond.cond_type = static_cast<ConditionalComparisonType>((first_dword >> 16) & 0xF); | 335 | opcode.opcode = BeginConditionalOpcode{ |
| 336 | begin_cond.rel_address = | 336 | .bit_width = bit_width, |
| 337 | (static_cast<u64>(first_dword & 0xFF) << 32ul) | static_cast<u64>(second_dword); | 337 | .mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF), |
| 338 | begin_cond.value = GetNextVmInt(begin_cond.bit_width); | 338 | .cond_type = static_cast<ConditionalComparisonType>((first_dword >> 16) & 0xF), |
| 339 | opcode.opcode = begin_cond; | 339 | .rel_address = (static_cast<u64>(first_dword & 0xFF) << 32) | second_dword, |
| 340 | .value = GetNextVmInt(bit_width), | ||
| 341 | }; | ||
| 340 | } break; | 342 | } break; |
| 341 | case CheatVmOpcodeType::EndConditionalBlock: { | 343 | case CheatVmOpcodeType::EndConditionalBlock: { |
| 342 | // 20000000 | 344 | // 20000000 |
| @@ -344,12 +346,14 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 344 | opcode.opcode = EndConditionalOpcode{}; | 346 | opcode.opcode = EndConditionalOpcode{}; |
| 345 | } break; | 347 | } break; |
| 346 | case CheatVmOpcodeType::ControlLoop: { | 348 | case CheatVmOpcodeType::ControlLoop: { |
| 347 | ControlLoopOpcode ctrl_loop{}; | ||
| 348 | // 300R0000 VVVVVVVV | 349 | // 300R0000 VVVVVVVV |
| 349 | // 310R0000 | 350 | // 310R0000 |
| 350 | // Parse register, whether loop start or loop end. | 351 | // Parse register, whether loop start or loop end. |
| 351 | ctrl_loop.start_loop = ((first_dword >> 24) & 0xF) == 0; | 352 | ControlLoopOpcode ctrl_loop{ |
| 352 | ctrl_loop.reg_index = ((first_dword >> 20) & 0xF); | 353 | .start_loop = ((first_dword >> 24) & 0xF) == 0, |
| 354 | .reg_index = (first_dword >> 20) & 0xF, | ||
| 355 | .num_iters = 0, | ||
| 356 | }; | ||
| 353 | 357 | ||
| 354 | // Read number of iters if loop start. | 358 | // Read number of iters if loop start. |
| 355 | if (ctrl_loop.start_loop) { | 359 | if (ctrl_loop.start_loop) { |
| @@ -358,66 +362,65 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 358 | opcode.opcode = ctrl_loop; | 362 | opcode.opcode = ctrl_loop; |
| 359 | } break; | 363 | } break; |
| 360 | case CheatVmOpcodeType::LoadRegisterStatic: { | 364 | case CheatVmOpcodeType::LoadRegisterStatic: { |
| 361 | LoadRegisterStaticOpcode ldr_static{}; | ||
| 362 | // 400R0000 VVVVVVVV VVVVVVVV | 365 | // 400R0000 VVVVVVVV VVVVVVVV |
| 363 | // Read additional words. | 366 | // Read additional words. |
| 364 | ldr_static.reg_index = ((first_dword >> 16) & 0xF); | 367 | opcode.opcode = LoadRegisterStaticOpcode{ |
| 365 | ldr_static.value = | 368 | .reg_index = (first_dword >> 16) & 0xF, |
| 366 | (static_cast<u64>(GetNextDword()) << 32ul) | static_cast<u64>(GetNextDword()); | 369 | .value = (static_cast<u64>(GetNextDword()) << 32) | GetNextDword(), |
| 367 | opcode.opcode = ldr_static; | 370 | }; |
| 368 | } break; | 371 | } break; |
| 369 | case CheatVmOpcodeType::LoadRegisterMemory: { | 372 | case CheatVmOpcodeType::LoadRegisterMemory: { |
| 370 | LoadRegisterMemoryOpcode ldr_memory{}; | ||
| 371 | // 5TMRI0AA AAAAAAAA | 373 | // 5TMRI0AA AAAAAAAA |
| 372 | // Read additional words. | 374 | // Read additional words. |
| 373 | const u32 second_dword = GetNextDword(); | 375 | const u32 second_dword = GetNextDword(); |
| 374 | ldr_memory.bit_width = (first_dword >> 24) & 0xF; | 376 | opcode.opcode = LoadRegisterMemoryOpcode{ |
| 375 | ldr_memory.mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF); | 377 | .bit_width = (first_dword >> 24) & 0xF, |
| 376 | ldr_memory.reg_index = ((first_dword >> 16) & 0xF); | 378 | .mem_type = static_cast<MemoryAccessType>((first_dword >> 20) & 0xF), |
| 377 | ldr_memory.load_from_reg = ((first_dword >> 12) & 0xF) != 0; | 379 | .reg_index = ((first_dword >> 16) & 0xF), |
| 378 | ldr_memory.rel_address = | 380 | .load_from_reg = ((first_dword >> 12) & 0xF) != 0, |
| 379 | (static_cast<u64>(first_dword & 0xFF) << 32ul) | static_cast<u64>(second_dword); | 381 | .rel_address = (static_cast<u64>(first_dword & 0xFF) << 32) | second_dword, |
| 380 | opcode.opcode = ldr_memory; | 382 | }; |
| 381 | } break; | 383 | } break; |
| 382 | case CheatVmOpcodeType::StoreStaticToAddress: { | 384 | case CheatVmOpcodeType::StoreStaticToAddress: { |
| 383 | StoreStaticToAddressOpcode str_static{}; | ||
| 384 | // 6T0RIor0 VVVVVVVV VVVVVVVV | 385 | // 6T0RIor0 VVVVVVVV VVVVVVVV |
| 385 | // Read additional words. | 386 | // Read additional words. |
| 386 | str_static.bit_width = (first_dword >> 24) & 0xF; | 387 | opcode.opcode = StoreStaticToAddressOpcode{ |
| 387 | str_static.reg_index = ((first_dword >> 16) & 0xF); | 388 | .bit_width = (first_dword >> 24) & 0xF, |
| 388 | str_static.increment_reg = ((first_dword >> 12) & 0xF) != 0; | 389 | .reg_index = (first_dword >> 16) & 0xF, |
| 389 | str_static.add_offset_reg = ((first_dword >> 8) & 0xF) != 0; | 390 | .increment_reg = ((first_dword >> 12) & 0xF) != 0, |
| 390 | str_static.offset_reg_index = ((first_dword >> 4) & 0xF); | 391 | .add_offset_reg = ((first_dword >> 8) & 0xF) != 0, |
| 391 | str_static.value = | 392 | .offset_reg_index = (first_dword >> 4) & 0xF, |
| 392 | (static_cast<u64>(GetNextDword()) << 32ul) | static_cast<u64>(GetNextDword()); | 393 | .value = (static_cast<u64>(GetNextDword()) << 32) | GetNextDword(), |
| 393 | opcode.opcode = str_static; | 394 | }; |
| 394 | } break; | 395 | } break; |
| 395 | case CheatVmOpcodeType::PerformArithmeticStatic: { | 396 | case CheatVmOpcodeType::PerformArithmeticStatic: { |
| 396 | PerformArithmeticStaticOpcode perform_math_static{}; | ||
| 397 | // 7T0RC000 VVVVVVVV | 397 | // 7T0RC000 VVVVVVVV |
| 398 | // Read additional words. | 398 | // Read additional words. |
| 399 | perform_math_static.bit_width = (first_dword >> 24) & 0xF; | 399 | opcode.opcode = PerformArithmeticStaticOpcode{ |
| 400 | perform_math_static.reg_index = ((first_dword >> 16) & 0xF); | 400 | .bit_width = (first_dword >> 24) & 0xF, |
| 401 | perform_math_static.math_type = | 401 | .reg_index = ((first_dword >> 16) & 0xF), |
| 402 | static_cast<RegisterArithmeticType>((first_dword >> 12) & 0xF); | 402 | .math_type = static_cast<RegisterArithmeticType>((first_dword >> 12) & 0xF), |
| 403 | perform_math_static.value = GetNextDword(); | 403 | .value = GetNextDword(), |
| 404 | opcode.opcode = perform_math_static; | 404 | }; |
| 405 | } break; | 405 | } break; |
| 406 | case CheatVmOpcodeType::BeginKeypressConditionalBlock: { | 406 | case CheatVmOpcodeType::BeginKeypressConditionalBlock: { |
| 407 | BeginKeypressConditionalOpcode begin_keypress_cond{}; | ||
| 408 | // 8kkkkkkk | 407 | // 8kkkkkkk |
| 409 | // Just parse the mask. | 408 | // Just parse the mask. |
| 410 | begin_keypress_cond.key_mask = first_dword & 0x0FFFFFFF; | 409 | opcode.opcode = BeginKeypressConditionalOpcode{ |
| 411 | opcode.opcode = begin_keypress_cond; | 410 | .key_mask = first_dword & 0x0FFFFFFF, |
| 411 | }; | ||
| 412 | } break; | 412 | } break; |
| 413 | case CheatVmOpcodeType::PerformArithmeticRegister: { | 413 | case CheatVmOpcodeType::PerformArithmeticRegister: { |
| 414 | PerformArithmeticRegisterOpcode perform_math_reg{}; | ||
| 415 | // 9TCRSIs0 (VVVVVVVV (VVVVVVVV)) | 414 | // 9TCRSIs0 (VVVVVVVV (VVVVVVVV)) |
| 416 | perform_math_reg.bit_width = (first_dword >> 24) & 0xF; | 415 | PerformArithmeticRegisterOpcode perform_math_reg{ |
| 417 | perform_math_reg.math_type = static_cast<RegisterArithmeticType>((first_dword >> 20) & 0xF); | 416 | .bit_width = (first_dword >> 24) & 0xF, |
| 418 | perform_math_reg.dst_reg_index = ((first_dword >> 16) & 0xF); | 417 | .math_type = static_cast<RegisterArithmeticType>((first_dword >> 20) & 0xF), |
| 419 | perform_math_reg.src_reg_1_index = ((first_dword >> 12) & 0xF); | 418 | .dst_reg_index = (first_dword >> 16) & 0xF, |
| 420 | perform_math_reg.has_immediate = ((first_dword >> 8) & 0xF) != 0; | 419 | .src_reg_1_index = (first_dword >> 12) & 0xF, |
| 420 | .src_reg_2_index = 0, | ||
| 421 | .has_immediate = ((first_dword >> 8) & 0xF) != 0, | ||
| 422 | .value = {}, | ||
| 423 | }; | ||
| 421 | if (perform_math_reg.has_immediate) { | 424 | if (perform_math_reg.has_immediate) { |
| 422 | perform_math_reg.src_reg_2_index = 0; | 425 | perform_math_reg.src_reg_2_index = 0; |
| 423 | perform_math_reg.value = GetNextVmInt(perform_math_reg.bit_width); | 426 | perform_math_reg.value = GetNextVmInt(perform_math_reg.bit_width); |
| @@ -427,7 +430,6 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 427 | opcode.opcode = perform_math_reg; | 430 | opcode.opcode = perform_math_reg; |
| 428 | } break; | 431 | } break; |
| 429 | case CheatVmOpcodeType::StoreRegisterToAddress: { | 432 | case CheatVmOpcodeType::StoreRegisterToAddress: { |
| 430 | StoreRegisterToAddressOpcode str_register{}; | ||
| 431 | // ATSRIOxa (aaaaaaaa) | 433 | // ATSRIOxa (aaaaaaaa) |
| 432 | // A = opcode 10 | 434 | // A = opcode 10 |
| 433 | // T = bit width | 435 | // T = bit width |
| @@ -439,20 +441,23 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 439 | // Relative Address | 441 | // Relative Address |
| 440 | // x = offset register (for offset type 1), memory type (for offset type 3) | 442 | // x = offset register (for offset type 1), memory type (for offset type 3) |
| 441 | // a = relative address (for offset type 2+3) | 443 | // a = relative address (for offset type 2+3) |
| 442 | str_register.bit_width = (first_dword >> 24) & 0xF; | 444 | StoreRegisterToAddressOpcode str_register{ |
| 443 | str_register.str_reg_index = ((first_dword >> 20) & 0xF); | 445 | .bit_width = (first_dword >> 24) & 0xF, |
| 444 | str_register.addr_reg_index = ((first_dword >> 16) & 0xF); | 446 | .str_reg_index = (first_dword >> 20) & 0xF, |
| 445 | str_register.increment_reg = ((first_dword >> 12) & 0xF) != 0; | 447 | .addr_reg_index = (first_dword >> 16) & 0xF, |
| 446 | str_register.ofs_type = static_cast<StoreRegisterOffsetType>(((first_dword >> 8) & 0xF)); | 448 | .increment_reg = ((first_dword >> 12) & 0xF) != 0, |
| 447 | str_register.ofs_reg_index = ((first_dword >> 4) & 0xF); | 449 | .ofs_type = static_cast<StoreRegisterOffsetType>(((first_dword >> 8) & 0xF)), |
| 450 | .mem_type = MemoryAccessType::MainNso, | ||
| 451 | .ofs_reg_index = (first_dword >> 4) & 0xF, | ||
| 452 | .rel_address = 0, | ||
| 453 | }; | ||
| 448 | switch (str_register.ofs_type) { | 454 | switch (str_register.ofs_type) { |
| 449 | case StoreRegisterOffsetType::None: | 455 | case StoreRegisterOffsetType::None: |
| 450 | case StoreRegisterOffsetType::Reg: | 456 | case StoreRegisterOffsetType::Reg: |
| 451 | // Nothing more to do | 457 | // Nothing more to do |
| 452 | break; | 458 | break; |
| 453 | case StoreRegisterOffsetType::Imm: | 459 | case StoreRegisterOffsetType::Imm: |
| 454 | str_register.rel_address = | 460 | str_register.rel_address = (static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword(); |
| 455 | ((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword())); | ||
| 456 | break; | 461 | break; |
| 457 | case StoreRegisterOffsetType::MemReg: | 462 | case StoreRegisterOffsetType::MemReg: |
| 458 | str_register.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); | 463 | str_register.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); |
| @@ -460,8 +465,7 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 460 | case StoreRegisterOffsetType::MemImm: | 465 | case StoreRegisterOffsetType::MemImm: |
| 461 | case StoreRegisterOffsetType::MemImmReg: | 466 | case StoreRegisterOffsetType::MemImmReg: |
| 462 | str_register.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); | 467 | str_register.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); |
| 463 | str_register.rel_address = | 468 | str_register.rel_address = (static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword(); |
| 464 | ((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword())); | ||
| 465 | break; | 469 | break; |
| 466 | default: | 470 | default: |
| 467 | str_register.ofs_type = StoreRegisterOffsetType::None; | 471 | str_register.ofs_type = StoreRegisterOffsetType::None; |
| @@ -470,7 +474,6 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 470 | opcode.opcode = str_register; | 474 | opcode.opcode = str_register; |
| 471 | } break; | 475 | } break; |
| 472 | case CheatVmOpcodeType::BeginRegisterConditionalBlock: { | 476 | case CheatVmOpcodeType::BeginRegisterConditionalBlock: { |
| 473 | BeginRegisterConditionalOpcode begin_reg_cond{}; | ||
| 474 | // C0TcSX## | 477 | // C0TcSX## |
| 475 | // C0TcS0Ma aaaaaaaa | 478 | // C0TcS0Ma aaaaaaaa |
| 476 | // C0TcS1Mr | 479 | // C0TcS1Mr |
| @@ -492,11 +495,19 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 492 | // r = offset register. | 495 | // r = offset register. |
| 493 | // X = other register. | 496 | // X = other register. |
| 494 | // V = value. | 497 | // V = value. |
| 495 | begin_reg_cond.bit_width = (first_dword >> 20) & 0xF; | 498 | |
| 496 | begin_reg_cond.cond_type = | 499 | BeginRegisterConditionalOpcode begin_reg_cond{ |
| 497 | static_cast<ConditionalComparisonType>((first_dword >> 16) & 0xF); | 500 | .bit_width = (first_dword >> 20) & 0xF, |
| 498 | begin_reg_cond.val_reg_index = ((first_dword >> 12) & 0xF); | 501 | .cond_type = static_cast<ConditionalComparisonType>((first_dword >> 16) & 0xF), |
| 499 | begin_reg_cond.comp_type = static_cast<CompareRegisterValueType>((first_dword >> 8) & 0xF); | 502 | .val_reg_index = (first_dword >> 12) & 0xF, |
| 503 | .comp_type = static_cast<CompareRegisterValueType>((first_dword >> 8) & 0xF), | ||
| 504 | .mem_type = MemoryAccessType::MainNso, | ||
| 505 | .addr_reg_index = 0, | ||
| 506 | .other_reg_index = 0, | ||
| 507 | .ofs_reg_index = 0, | ||
| 508 | .rel_address = 0, | ||
| 509 | .value = {}, | ||
| 510 | }; | ||
| 500 | 511 | ||
| 501 | switch (begin_reg_cond.comp_type) { | 512 | switch (begin_reg_cond.comp_type) { |
| 502 | case CompareRegisterValueType::StaticValue: | 513 | case CompareRegisterValueType::StaticValue: |
| @@ -508,26 +519,25 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 508 | case CompareRegisterValueType::MemoryRelAddr: | 519 | case CompareRegisterValueType::MemoryRelAddr: |
| 509 | begin_reg_cond.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); | 520 | begin_reg_cond.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); |
| 510 | begin_reg_cond.rel_address = | 521 | begin_reg_cond.rel_address = |
| 511 | ((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword())); | 522 | (static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword(); |
| 512 | break; | 523 | break; |
| 513 | case CompareRegisterValueType::MemoryOfsReg: | 524 | case CompareRegisterValueType::MemoryOfsReg: |
| 514 | begin_reg_cond.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); | 525 | begin_reg_cond.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); |
| 515 | begin_reg_cond.ofs_reg_index = (first_dword & 0xF); | 526 | begin_reg_cond.ofs_reg_index = (first_dword & 0xF); |
| 516 | break; | 527 | break; |
| 517 | case CompareRegisterValueType::RegisterRelAddr: | 528 | case CompareRegisterValueType::RegisterRelAddr: |
| 518 | begin_reg_cond.addr_reg_index = ((first_dword >> 4) & 0xF); | 529 | begin_reg_cond.addr_reg_index = (first_dword >> 4) & 0xF; |
| 519 | begin_reg_cond.rel_address = | 530 | begin_reg_cond.rel_address = |
| 520 | ((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword())); | 531 | (static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword(); |
| 521 | break; | 532 | break; |
| 522 | case CompareRegisterValueType::RegisterOfsReg: | 533 | case CompareRegisterValueType::RegisterOfsReg: |
| 523 | begin_reg_cond.addr_reg_index = ((first_dword >> 4) & 0xF); | 534 | begin_reg_cond.addr_reg_index = (first_dword >> 4) & 0xF; |
| 524 | begin_reg_cond.ofs_reg_index = (first_dword & 0xF); | 535 | begin_reg_cond.ofs_reg_index = first_dword & 0xF; |
| 525 | break; | 536 | break; |
| 526 | } | 537 | } |
| 527 | opcode.opcode = begin_reg_cond; | 538 | opcode.opcode = begin_reg_cond; |
| 528 | } break; | 539 | } break; |
| 529 | case CheatVmOpcodeType::SaveRestoreRegister: { | 540 | case CheatVmOpcodeType::SaveRestoreRegister: { |
| 530 | SaveRestoreRegisterOpcode save_restore_reg{}; | ||
| 531 | // C10D0Sx0 | 541 | // C10D0Sx0 |
| 532 | // C1 = opcode 0xC1 | 542 | // C1 = opcode 0xC1 |
| 533 | // D = destination index. | 543 | // D = destination index. |
| @@ -535,36 +545,37 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 535 | // x = 3 if clearing reg, 2 if clearing saved value, 1 if saving a register, 0 if restoring | 545 | // x = 3 if clearing reg, 2 if clearing saved value, 1 if saving a register, 0 if restoring |
| 536 | // a register. | 546 | // a register. |
| 537 | // NOTE: If we add more save slots later, current encoding is backwards compatible. | 547 | // NOTE: If we add more save slots later, current encoding is backwards compatible. |
| 538 | save_restore_reg.dst_index = (first_dword >> 16) & 0xF; | 548 | opcode.opcode = SaveRestoreRegisterOpcode{ |
| 539 | save_restore_reg.src_index = (first_dword >> 8) & 0xF; | 549 | .dst_index = (first_dword >> 16) & 0xF, |
| 540 | save_restore_reg.op_type = static_cast<SaveRestoreRegisterOpType>((first_dword >> 4) & 0xF); | 550 | .src_index = (first_dword >> 8) & 0xF, |
| 541 | opcode.opcode = save_restore_reg; | 551 | .op_type = static_cast<SaveRestoreRegisterOpType>((first_dword >> 4) & 0xF), |
| 552 | }; | ||
| 542 | } break; | 553 | } break; |
| 543 | case CheatVmOpcodeType::SaveRestoreRegisterMask: { | 554 | case CheatVmOpcodeType::SaveRestoreRegisterMask: { |
| 544 | SaveRestoreRegisterMaskOpcode save_restore_regmask{}; | ||
| 545 | // C2x0XXXX | 555 | // C2x0XXXX |
| 546 | // C2 = opcode 0xC2 | 556 | // C2 = opcode 0xC2 |
| 547 | // x = 3 if clearing reg, 2 if clearing saved value, 1 if saving, 0 if restoring. | 557 | // x = 3 if clearing reg, 2 if clearing saved value, 1 if saving, 0 if restoring. |
| 548 | // X = 16-bit bitmask, bit i --> save or restore register i. | 558 | // X = 16-bit bitmask, bit i --> save or restore register i. |
| 549 | save_restore_regmask.op_type = | 559 | SaveRestoreRegisterMaskOpcode save_restore_regmask{ |
| 550 | static_cast<SaveRestoreRegisterOpType>((first_dword >> 20) & 0xF); | 560 | .op_type = static_cast<SaveRestoreRegisterOpType>((first_dword >> 20) & 0xF), |
| 561 | .should_operate = {}, | ||
| 562 | }; | ||
| 551 | for (std::size_t i = 0; i < NumRegisters; i++) { | 563 | for (std::size_t i = 0; i < NumRegisters; i++) { |
| 552 | save_restore_regmask.should_operate[i] = (first_dword & (1u << i)) != 0; | 564 | save_restore_regmask.should_operate[i] = (first_dword & (1U << i)) != 0; |
| 553 | } | 565 | } |
| 554 | opcode.opcode = save_restore_regmask; | 566 | opcode.opcode = save_restore_regmask; |
| 555 | } break; | 567 | } break; |
| 556 | case CheatVmOpcodeType::ReadWriteStaticRegister: { | 568 | case CheatVmOpcodeType::ReadWriteStaticRegister: { |
| 557 | ReadWriteStaticRegisterOpcode rw_static_reg{}; | ||
| 558 | // C3000XXx | 569 | // C3000XXx |
| 559 | // C3 = opcode 0xC3. | 570 | // C3 = opcode 0xC3. |
| 560 | // XX = static register index. | 571 | // XX = static register index. |
| 561 | // x = register index. | 572 | // x = register index. |
| 562 | rw_static_reg.static_idx = ((first_dword >> 4) & 0xFF); | 573 | opcode.opcode = ReadWriteStaticRegisterOpcode{ |
| 563 | rw_static_reg.idx = (first_dword & 0xF); | 574 | .static_idx = (first_dword >> 4) & 0xFF, |
| 564 | opcode.opcode = rw_static_reg; | 575 | .idx = first_dword & 0xF, |
| 576 | }; | ||
| 565 | } break; | 577 | } break; |
| 566 | case CheatVmOpcodeType::DebugLog: { | 578 | case CheatVmOpcodeType::DebugLog: { |
| 567 | DebugLogOpcode debug_log{}; | ||
| 568 | // FFFTIX## | 579 | // FFFTIX## |
| 569 | // FFFTI0Ma aaaaaaaa | 580 | // FFFTI0Ma aaaaaaaa |
| 570 | // FFFTI1Mr | 581 | // FFFTI1Mr |
| @@ -583,31 +594,36 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) { | |||
| 583 | // a = relative address. | 594 | // a = relative address. |
| 584 | // r = offset register. | 595 | // r = offset register. |
| 585 | // X = value register. | 596 | // X = value register. |
| 586 | debug_log.bit_width = (first_dword >> 16) & 0xF; | 597 | DebugLogOpcode debug_log{ |
| 587 | debug_log.log_id = ((first_dword >> 12) & 0xF); | 598 | .bit_width = (first_dword >> 16) & 0xF, |
| 588 | debug_log.val_type = static_cast<DebugLogValueType>((first_dword >> 8) & 0xF); | 599 | .log_id = (first_dword >> 12) & 0xF, |
| 600 | .val_type = static_cast<DebugLogValueType>((first_dword >> 8) & 0xF), | ||
| 601 | .mem_type = MemoryAccessType::MainNso, | ||
| 602 | .addr_reg_index = 0, | ||
| 603 | .val_reg_index = 0, | ||
| 604 | .ofs_reg_index = 0, | ||
| 605 | .rel_address = 0, | ||
| 606 | }; | ||
| 589 | 607 | ||
| 590 | switch (debug_log.val_type) { | 608 | switch (debug_log.val_type) { |
| 591 | case DebugLogValueType::RegisterValue: | 609 | case DebugLogValueType::RegisterValue: |
| 592 | debug_log.val_reg_index = ((first_dword >> 4) & 0xF); | 610 | debug_log.val_reg_index = (first_dword >> 4) & 0xF; |
| 593 | break; | 611 | break; |
| 594 | case DebugLogValueType::MemoryRelAddr: | 612 | case DebugLogValueType::MemoryRelAddr: |
| 595 | debug_log.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); | 613 | debug_log.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); |
| 596 | debug_log.rel_address = | 614 | debug_log.rel_address = (static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword(); |
| 597 | ((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword())); | ||
| 598 | break; | 615 | break; |
| 599 | case DebugLogValueType::MemoryOfsReg: | 616 | case DebugLogValueType::MemoryOfsReg: |
| 600 | debug_log.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); | 617 | debug_log.mem_type = static_cast<MemoryAccessType>((first_dword >> 4) & 0xF); |
| 601 | debug_log.ofs_reg_index = (first_dword & 0xF); | 618 | debug_log.ofs_reg_index = first_dword & 0xF; |
| 602 | break; | 619 | break; |
| 603 | case DebugLogValueType::RegisterRelAddr: | 620 | case DebugLogValueType::RegisterRelAddr: |
| 604 | debug_log.addr_reg_index = ((first_dword >> 4) & 0xF); | 621 | debug_log.addr_reg_index = (first_dword >> 4) & 0xF; |
| 605 | debug_log.rel_address = | 622 | debug_log.rel_address = (static_cast<u64>(first_dword & 0xF) << 32) | GetNextDword(); |
| 606 | ((static_cast<u64>(first_dword & 0xF) << 32ul) | static_cast<u64>(GetNextDword())); | ||
| 607 | break; | 623 | break; |
| 608 | case DebugLogValueType::RegisterOfsReg: | 624 | case DebugLogValueType::RegisterOfsReg: |
| 609 | debug_log.addr_reg_index = ((first_dword >> 4) & 0xF); | 625 | debug_log.addr_reg_index = (first_dword >> 4) & 0xF; |
| 610 | debug_log.ofs_reg_index = (first_dword & 0xF); | 626 | debug_log.ofs_reg_index = first_dword & 0xF; |
| 611 | break; | 627 | break; |
| 612 | } | 628 | } |
| 613 | opcode.opcode = debug_log; | 629 | opcode.opcode = debug_log; |
diff --git a/src/core/network/network.cpp b/src/core/network/network.cpp new file mode 100644 index 000000000..56d173b5e --- /dev/null +++ b/src/core/network/network.cpp | |||
| @@ -0,0 +1,654 @@ | |||
| 1 | // Copyright 2020 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstring> | ||
| 7 | #include <limits> | ||
| 8 | #include <utility> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #ifdef _WIN32 | ||
| 12 | #define _WINSOCK_DEPRECATED_NO_WARNINGS // gethostname | ||
| 13 | #include <winsock2.h> | ||
| 14 | #elif __unix__ | ||
| 15 | #include <errno.h> | ||
| 16 | #include <fcntl.h> | ||
| 17 | #include <netdb.h> | ||
| 18 | #include <netinet/in.h> | ||
| 19 | #include <poll.h> | ||
| 20 | #include <sys/socket.h> | ||
| 21 | #include <unistd.h> | ||
| 22 | #else | ||
| 23 | #error "Unimplemented platform" | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #include "common/assert.h" | ||
| 27 | #include "common/common_types.h" | ||
| 28 | #include "common/logging/log.h" | ||
| 29 | #include "core/network/network.h" | ||
| 30 | #include "core/network/sockets.h" | ||
| 31 | |||
| 32 | namespace Network { | ||
| 33 | |||
| 34 | namespace { | ||
| 35 | |||
| 36 | #ifdef _WIN32 | ||
| 37 | |||
| 38 | using socklen_t = int; | ||
| 39 | |||
| 40 | void Initialize() { | ||
| 41 | WSADATA wsa_data; | ||
| 42 | (void)WSAStartup(MAKEWORD(2, 2), &wsa_data); | ||
| 43 | } | ||
| 44 | |||
| 45 | void Finalize() { | ||
| 46 | WSACleanup(); | ||
| 47 | } | ||
| 48 | |||
| 49 | constexpr IPv4Address TranslateIPv4(in_addr addr) { | ||
| 50 | auto& bytes = addr.S_un.S_un_b; | ||
| 51 | return IPv4Address{bytes.s_b1, bytes.s_b2, bytes.s_b3, bytes.s_b4}; | ||
| 52 | } | ||
| 53 | |||
| 54 | sockaddr TranslateFromSockAddrIn(SockAddrIn input) { | ||
| 55 | sockaddr_in result; | ||
| 56 | |||
| 57 | #ifdef __unix__ | ||
| 58 | result.sin_len = sizeof(result); | ||
| 59 | #endif | ||
| 60 | |||
| 61 | switch (static_cast<Domain>(input.family)) { | ||
| 62 | case Domain::INET: | ||
| 63 | result.sin_family = AF_INET; | ||
| 64 | break; | ||
| 65 | default: | ||
| 66 | UNIMPLEMENTED_MSG("Unhandled sockaddr family={}", static_cast<int>(input.family)); | ||
| 67 | result.sin_family = AF_INET; | ||
| 68 | break; | ||
| 69 | } | ||
| 70 | |||
| 71 | result.sin_port = htons(input.portno); | ||
| 72 | |||
| 73 | auto& ip = result.sin_addr.S_un.S_un_b; | ||
| 74 | ip.s_b1 = input.ip[0]; | ||
| 75 | ip.s_b2 = input.ip[1]; | ||
| 76 | ip.s_b3 = input.ip[2]; | ||
| 77 | ip.s_b4 = input.ip[3]; | ||
| 78 | |||
| 79 | sockaddr addr; | ||
| 80 | std::memcpy(&addr, &result, sizeof(addr)); | ||
| 81 | return addr; | ||
| 82 | } | ||
| 83 | |||
| 84 | LINGER MakeLinger(bool enable, u32 linger_value) { | ||
| 85 | ASSERT(linger_value <= std::numeric_limits<u_short>::max()); | ||
| 86 | |||
| 87 | LINGER value; | ||
| 88 | value.l_onoff = enable ? 1 : 0; | ||
| 89 | value.l_linger = static_cast<u_short>(linger_value); | ||
| 90 | return value; | ||
| 91 | } | ||
| 92 | |||
| 93 | int LastError() { | ||
| 94 | return WSAGetLastError(); | ||
| 95 | } | ||
| 96 | |||
| 97 | bool EnableNonBlock(SOCKET fd, bool enable) { | ||
| 98 | u_long value = enable ? 1 : 0; | ||
| 99 | return ioctlsocket(fd, FIONBIO, &value) != SOCKET_ERROR; | ||
| 100 | } | ||
| 101 | |||
| 102 | #elif __unix__ // ^ _WIN32 v __unix__ | ||
| 103 | |||
| 104 | using SOCKET = int; | ||
| 105 | using WSAPOLLFD = pollfd; | ||
| 106 | using ULONG = u64; | ||
| 107 | |||
| 108 | constexpr SOCKET INVALID_SOCKET = -1; | ||
| 109 | constexpr SOCKET SOCKET_ERROR = -1; | ||
| 110 | |||
| 111 | constexpr int WSAEWOULDBLOCK = EAGAIN; | ||
| 112 | constexpr int WSAENOTCONN = ENOTCONN; | ||
| 113 | |||
| 114 | constexpr int SD_RECEIVE = SHUT_RD; | ||
| 115 | constexpr int SD_SEND = SHUT_WR; | ||
| 116 | constexpr int SD_BOTH = SHUT_RDWR; | ||
| 117 | |||
| 118 | void Initialize() {} | ||
| 119 | |||
| 120 | void Finalize() {} | ||
| 121 | |||
| 122 | constexpr IPv4Address TranslateIPv4(in_addr addr) { | ||
| 123 | const u32 bytes = addr.s_addr; | ||
| 124 | return IPv4Address{static_cast<u8>(bytes), static_cast<u8>(bytes >> 8), | ||
| 125 | static_cast<u8>(bytes >> 16), static_cast<u8>(bytes >> 24)}; | ||
| 126 | } | ||
| 127 | |||
| 128 | sockaddr TranslateFromSockAddrIn(SockAddrIn input) { | ||
| 129 | sockaddr_in result; | ||
| 130 | |||
| 131 | switch (static_cast<Domain>(input.family)) { | ||
| 132 | case Domain::INET: | ||
| 133 | result.sin_family = AF_INET; | ||
| 134 | break; | ||
| 135 | default: | ||
| 136 | UNIMPLEMENTED_MSG("Unhandled sockaddr family={}", static_cast<int>(input.family)); | ||
| 137 | result.sin_family = AF_INET; | ||
| 138 | break; | ||
| 139 | } | ||
| 140 | |||
| 141 | result.sin_port = htons(input.portno); | ||
| 142 | |||
| 143 | result.sin_addr.s_addr = input.ip[0] | input.ip[1] << 8 | input.ip[2] << 16 | input.ip[3] << 24; | ||
| 144 | |||
| 145 | sockaddr addr; | ||
| 146 | std::memcpy(&addr, &result, sizeof(addr)); | ||
| 147 | return addr; | ||
| 148 | } | ||
| 149 | |||
| 150 | int WSAPoll(WSAPOLLFD* fds, ULONG nfds, int timeout) { | ||
| 151 | return poll(fds, nfds, timeout); | ||
| 152 | } | ||
| 153 | |||
| 154 | int closesocket(SOCKET fd) { | ||
| 155 | return close(fd); | ||
| 156 | } | ||
| 157 | |||
| 158 | linger MakeLinger(bool enable, u32 linger_value) { | ||
| 159 | linger value; | ||
| 160 | value.l_onoff = enable ? 1 : 0; | ||
| 161 | value.l_linger = linger_value; | ||
| 162 | return value; | ||
| 163 | } | ||
| 164 | |||
| 165 | int LastError() { | ||
| 166 | return errno; | ||
| 167 | } | ||
| 168 | |||
| 169 | bool EnableNonBlock(int fd, bool enable) { | ||
| 170 | int flags = fcntl(fd, F_GETFD); | ||
| 171 | if (flags == -1) { | ||
| 172 | return false; | ||
| 173 | } | ||
| 174 | if (enable) { | ||
| 175 | flags |= O_NONBLOCK; | ||
| 176 | } else { | ||
| 177 | flags &= ~O_NONBLOCK; | ||
| 178 | } | ||
| 179 | return fcntl(fd, F_SETFD, flags) == 0; | ||
| 180 | } | ||
| 181 | |||
| 182 | #endif | ||
| 183 | |||
| 184 | int TranslateDomain(Domain domain) { | ||
| 185 | switch (domain) { | ||
| 186 | case Domain::INET: | ||
| 187 | return AF_INET; | ||
| 188 | default: | ||
| 189 | UNIMPLEMENTED_MSG("Unimplemented domain={}", static_cast<int>(domain)); | ||
| 190 | return 0; | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | int TranslateType(Type type) { | ||
| 195 | switch (type) { | ||
| 196 | case Type::STREAM: | ||
| 197 | return SOCK_STREAM; | ||
| 198 | case Type::DGRAM: | ||
| 199 | return SOCK_DGRAM; | ||
| 200 | default: | ||
| 201 | UNIMPLEMENTED_MSG("Unimplemented type={}", static_cast<int>(type)); | ||
| 202 | return 0; | ||
| 203 | } | ||
| 204 | } | ||
| 205 | |||
| 206 | int TranslateProtocol(Protocol protocol) { | ||
| 207 | switch (protocol) { | ||
| 208 | case Protocol::TCP: | ||
| 209 | return IPPROTO_TCP; | ||
| 210 | case Protocol::UDP: | ||
| 211 | return IPPROTO_UDP; | ||
| 212 | default: | ||
| 213 | UNIMPLEMENTED_MSG("Unimplemented protocol={}", static_cast<int>(protocol)); | ||
| 214 | return 0; | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | SockAddrIn TranslateToSockAddrIn(sockaddr input_) { | ||
| 219 | sockaddr_in input; | ||
| 220 | std::memcpy(&input, &input_, sizeof(input)); | ||
| 221 | |||
| 222 | SockAddrIn result; | ||
| 223 | |||
| 224 | switch (input.sin_family) { | ||
| 225 | case AF_INET: | ||
| 226 | result.family = Domain::INET; | ||
| 227 | break; | ||
| 228 | default: | ||
| 229 | UNIMPLEMENTED_MSG("Unhandled sockaddr family={}", input.sin_family); | ||
| 230 | result.family = Domain::INET; | ||
| 231 | break; | ||
| 232 | } | ||
| 233 | |||
| 234 | result.portno = ntohs(input.sin_port); | ||
| 235 | |||
| 236 | result.ip = TranslateIPv4(input.sin_addr); | ||
| 237 | |||
| 238 | return result; | ||
| 239 | } | ||
| 240 | |||
| 241 | u16 TranslatePollEvents(u16 events) { | ||
| 242 | u16 result = 0; | ||
| 243 | |||
| 244 | if (events & POLL_IN) { | ||
| 245 | events &= ~POLL_IN; | ||
| 246 | result |= POLLIN; | ||
| 247 | } | ||
| 248 | if (events & POLL_PRI) { | ||
| 249 | events &= ~POLL_PRI; | ||
| 250 | #ifdef _WIN32 | ||
| 251 | LOG_WARNING(Service, "Winsock doesn't support POLLPRI"); | ||
| 252 | #else | ||
| 253 | result |= POLL_PRI; | ||
| 254 | #endif | ||
| 255 | } | ||
| 256 | if (events & POLL_OUT) { | ||
| 257 | events &= ~POLL_OUT; | ||
| 258 | result |= POLLOUT; | ||
| 259 | } | ||
| 260 | |||
| 261 | UNIMPLEMENTED_IF_MSG(events != 0, "Unhandled guest events=0x{:x}", events); | ||
| 262 | |||
| 263 | return result; | ||
| 264 | } | ||
| 265 | |||
| 266 | u16 TranslatePollRevents(u16 revents) { | ||
| 267 | u16 result = 0; | ||
| 268 | const auto translate = [&result, &revents](int host, unsigned guest) { | ||
| 269 | if (revents & host) { | ||
| 270 | revents &= ~host; | ||
| 271 | result |= guest; | ||
| 272 | } | ||
| 273 | }; | ||
| 274 | |||
| 275 | translate(POLLIN, POLL_IN); | ||
| 276 | translate(POLLPRI, POLL_PRI); | ||
| 277 | translate(POLLOUT, POLL_OUT); | ||
| 278 | translate(POLLERR, POLL_ERR); | ||
| 279 | translate(POLLHUP, POLL_HUP); | ||
| 280 | |||
| 281 | UNIMPLEMENTED_IF_MSG(revents != 0, "Unhandled host revents=0x{:x}", revents); | ||
| 282 | |||
| 283 | return result; | ||
| 284 | } | ||
| 285 | |||
| 286 | template <typename T> | ||
| 287 | Errno SetSockOpt(SOCKET fd, int option, T value) { | ||
| 288 | const int result = | ||
| 289 | setsockopt(fd, SOL_SOCKET, option, reinterpret_cast<const char*>(&value), sizeof(value)); | ||
| 290 | if (result != SOCKET_ERROR) { | ||
| 291 | return Errno::SUCCESS; | ||
| 292 | } | ||
| 293 | const int ec = LastError(); | ||
| 294 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 295 | return Errno::SUCCESS; | ||
| 296 | } | ||
| 297 | |||
| 298 | } // Anonymous namespace | ||
| 299 | |||
| 300 | NetworkInstance::NetworkInstance() { | ||
| 301 | Initialize(); | ||
| 302 | } | ||
| 303 | |||
| 304 | NetworkInstance::~NetworkInstance() { | ||
| 305 | Finalize(); | ||
| 306 | } | ||
| 307 | |||
| 308 | std::pair<IPv4Address, Errno> GetHostIPv4Address() { | ||
| 309 | std::array<char, 256> name{}; | ||
| 310 | if (gethostname(name.data(), static_cast<int>(name.size()) - 1) == SOCKET_ERROR) { | ||
| 311 | UNIMPLEMENTED_MSG("Unhandled gethostname error"); | ||
| 312 | return {IPv4Address{}, Errno::SUCCESS}; | ||
| 313 | } | ||
| 314 | |||
| 315 | hostent* const ent = gethostbyname(name.data()); | ||
| 316 | if (!ent) { | ||
| 317 | UNIMPLEMENTED_MSG("Unhandled gethostbyname error"); | ||
| 318 | return {IPv4Address{}, Errno::SUCCESS}; | ||
| 319 | } | ||
| 320 | if (ent->h_addr_list == nullptr) { | ||
| 321 | UNIMPLEMENTED_MSG("No addr provided in hostent->h_addr_list"); | ||
| 322 | return {IPv4Address{}, Errno::SUCCESS}; | ||
| 323 | } | ||
| 324 | if (ent->h_length != sizeof(in_addr)) { | ||
| 325 | UNIMPLEMENTED_MSG("Unexpected size={} in hostent->h_length", ent->h_length); | ||
| 326 | } | ||
| 327 | |||
| 328 | in_addr addr; | ||
| 329 | std::memcpy(&addr, ent->h_addr_list[0], sizeof(addr)); | ||
| 330 | return {TranslateIPv4(addr), Errno::SUCCESS}; | ||
| 331 | } | ||
| 332 | |||
| 333 | std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) { | ||
| 334 | const size_t num = pollfds.size(); | ||
| 335 | |||
| 336 | std::vector<WSAPOLLFD> host_pollfds(pollfds.size()); | ||
| 337 | std::transform(pollfds.begin(), pollfds.end(), host_pollfds.begin(), [](PollFD fd) { | ||
| 338 | WSAPOLLFD result; | ||
| 339 | result.fd = fd.socket->fd; | ||
| 340 | result.events = TranslatePollEvents(fd.events); | ||
| 341 | result.revents = 0; | ||
| 342 | return result; | ||
| 343 | }); | ||
| 344 | |||
| 345 | const int result = WSAPoll(host_pollfds.data(), static_cast<ULONG>(num), timeout); | ||
| 346 | if (result == 0) { | ||
| 347 | ASSERT(std::all_of(host_pollfds.begin(), host_pollfds.end(), | ||
| 348 | [](WSAPOLLFD fd) { return fd.revents == 0; })); | ||
| 349 | return {0, Errno::SUCCESS}; | ||
| 350 | } | ||
| 351 | |||
| 352 | for (size_t i = 0; i < num; ++i) { | ||
| 353 | pollfds[i].revents = TranslatePollRevents(host_pollfds[i].revents); | ||
| 354 | } | ||
| 355 | |||
| 356 | if (result > 0) { | ||
| 357 | return {result, Errno::SUCCESS}; | ||
| 358 | } | ||
| 359 | |||
| 360 | ASSERT(result == SOCKET_ERROR); | ||
| 361 | |||
| 362 | const int ec = LastError(); | ||
| 363 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 364 | return {-1, Errno::SUCCESS}; | ||
| 365 | } | ||
| 366 | |||
| 367 | Socket::~Socket() { | ||
| 368 | if (fd == INVALID_SOCKET) { | ||
| 369 | return; | ||
| 370 | } | ||
| 371 | (void)closesocket(fd); | ||
| 372 | fd = INVALID_SOCKET; | ||
| 373 | } | ||
| 374 | |||
| 375 | Socket::Socket(Socket&& rhs) noexcept : fd{std::exchange(rhs.fd, INVALID_SOCKET)} {} | ||
| 376 | |||
| 377 | Errno Socket::Initialize(Domain domain, Type type, Protocol protocol) { | ||
| 378 | fd = socket(TranslateDomain(domain), TranslateType(type), TranslateProtocol(protocol)); | ||
| 379 | if (fd != INVALID_SOCKET) { | ||
| 380 | return Errno::SUCCESS; | ||
| 381 | } | ||
| 382 | |||
| 383 | const int ec = LastError(); | ||
| 384 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 385 | return Errno::SUCCESS; | ||
| 386 | } | ||
| 387 | |||
| 388 | std::pair<Socket::AcceptResult, Errno> Socket::Accept() { | ||
| 389 | sockaddr addr; | ||
| 390 | socklen_t addrlen = sizeof(addr); | ||
| 391 | const SOCKET new_socket = accept(fd, &addr, &addrlen); | ||
| 392 | |||
| 393 | if (new_socket == INVALID_SOCKET) { | ||
| 394 | const int ec = LastError(); | ||
| 395 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 396 | return {AcceptResult{}, Errno::SUCCESS}; | ||
| 397 | } | ||
| 398 | |||
| 399 | AcceptResult result; | ||
| 400 | result.socket = std::make_unique<Socket>(); | ||
| 401 | result.socket->fd = new_socket; | ||
| 402 | |||
| 403 | ASSERT(addrlen == sizeof(sockaddr_in)); | ||
| 404 | result.sockaddr_in = TranslateToSockAddrIn(addr); | ||
| 405 | |||
| 406 | return {std::move(result), Errno::SUCCESS}; | ||
| 407 | } | ||
| 408 | |||
| 409 | Errno Socket::Connect(SockAddrIn addr_in) { | ||
| 410 | const sockaddr host_addr_in = TranslateFromSockAddrIn(addr_in); | ||
| 411 | if (connect(fd, &host_addr_in, sizeof(host_addr_in)) != INVALID_SOCKET) { | ||
| 412 | return Errno::SUCCESS; | ||
| 413 | } | ||
| 414 | |||
| 415 | switch (const int ec = LastError()) { | ||
| 416 | case WSAEWOULDBLOCK: | ||
| 417 | LOG_DEBUG(Service, "EAGAIN generated"); | ||
| 418 | return Errno::AGAIN; | ||
| 419 | default: | ||
| 420 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 421 | return Errno::SUCCESS; | ||
| 422 | } | ||
| 423 | } | ||
| 424 | |||
| 425 | std::pair<SockAddrIn, Errno> Socket::GetPeerName() { | ||
| 426 | sockaddr addr; | ||
| 427 | socklen_t addrlen = sizeof(addr); | ||
| 428 | if (getpeername(fd, &addr, &addrlen) == SOCKET_ERROR) { | ||
| 429 | const int ec = LastError(); | ||
| 430 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 431 | return {SockAddrIn{}, Errno::SUCCESS}; | ||
| 432 | } | ||
| 433 | |||
| 434 | ASSERT(addrlen == sizeof(sockaddr_in)); | ||
| 435 | return {TranslateToSockAddrIn(addr), Errno::SUCCESS}; | ||
| 436 | } | ||
| 437 | |||
| 438 | std::pair<SockAddrIn, Errno> Socket::GetSockName() { | ||
| 439 | sockaddr addr; | ||
| 440 | socklen_t addrlen = sizeof(addr); | ||
| 441 | if (getsockname(fd, &addr, &addrlen) == SOCKET_ERROR) { | ||
| 442 | const int ec = LastError(); | ||
| 443 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 444 | return {SockAddrIn{}, Errno::SUCCESS}; | ||
| 445 | } | ||
| 446 | |||
| 447 | ASSERT(addrlen == sizeof(sockaddr_in)); | ||
| 448 | return {TranslateToSockAddrIn(addr), Errno::SUCCESS}; | ||
| 449 | } | ||
| 450 | |||
| 451 | Errno Socket::Bind(SockAddrIn addr) { | ||
| 452 | const sockaddr addr_in = TranslateFromSockAddrIn(addr); | ||
| 453 | if (bind(fd, &addr_in, sizeof(addr_in)) != SOCKET_ERROR) { | ||
| 454 | return Errno::SUCCESS; | ||
| 455 | } | ||
| 456 | |||
| 457 | const int ec = LastError(); | ||
| 458 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 459 | return Errno::SUCCESS; | ||
| 460 | } | ||
| 461 | |||
| 462 | Errno Socket::Listen(s32 backlog) { | ||
| 463 | if (listen(fd, backlog) != SOCKET_ERROR) { | ||
| 464 | return Errno::SUCCESS; | ||
| 465 | } | ||
| 466 | |||
| 467 | const int ec = LastError(); | ||
| 468 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 469 | return Errno::SUCCESS; | ||
| 470 | } | ||
| 471 | |||
| 472 | Errno Socket::Shutdown(ShutdownHow how) { | ||
| 473 | int host_how = 0; | ||
| 474 | switch (how) { | ||
| 475 | case ShutdownHow::RD: | ||
| 476 | host_how = SD_RECEIVE; | ||
| 477 | break; | ||
| 478 | case ShutdownHow::WR: | ||
| 479 | host_how = SD_SEND; | ||
| 480 | break; | ||
| 481 | case ShutdownHow::RDWR: | ||
| 482 | host_how = SD_BOTH; | ||
| 483 | break; | ||
| 484 | default: | ||
| 485 | UNIMPLEMENTED_MSG("Unimplemented flag how={}", static_cast<int>(how)); | ||
| 486 | return Errno::SUCCESS; | ||
| 487 | } | ||
| 488 | if (shutdown(fd, host_how) != SOCKET_ERROR) { | ||
| 489 | return Errno::SUCCESS; | ||
| 490 | } | ||
| 491 | |||
| 492 | switch (const int ec = LastError()) { | ||
| 493 | case WSAENOTCONN: | ||
| 494 | LOG_ERROR(Service, "ENOTCONN generated"); | ||
| 495 | return Errno::NOTCONN; | ||
| 496 | default: | ||
| 497 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 498 | return Errno::SUCCESS; | ||
| 499 | } | ||
| 500 | } | ||
| 501 | |||
| 502 | std::pair<s32, Errno> Socket::Recv(int flags, std::vector<u8>& message) { | ||
| 503 | ASSERT(flags == 0); | ||
| 504 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); | ||
| 505 | |||
| 506 | const int result = | ||
| 507 | recv(fd, reinterpret_cast<char*>(message.data()), static_cast<int>(message.size()), 0); | ||
| 508 | if (result != SOCKET_ERROR) { | ||
| 509 | return {result, Errno::SUCCESS}; | ||
| 510 | } | ||
| 511 | |||
| 512 | switch (const int ec = LastError()) { | ||
| 513 | case WSAEWOULDBLOCK: | ||
| 514 | LOG_DEBUG(Service, "EAGAIN generated"); | ||
| 515 | return {-1, Errno::AGAIN}; | ||
| 516 | case WSAENOTCONN: | ||
| 517 | LOG_ERROR(Service, "ENOTCONN generated"); | ||
| 518 | return {-1, Errno::NOTCONN}; | ||
| 519 | default: | ||
| 520 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 521 | return {0, Errno::SUCCESS}; | ||
| 522 | } | ||
| 523 | } | ||
| 524 | |||
| 525 | std::pair<s32, Errno> Socket::RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr) { | ||
| 526 | ASSERT(flags == 0); | ||
| 527 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); | ||
| 528 | |||
| 529 | sockaddr addr_in{}; | ||
| 530 | socklen_t addrlen = sizeof(addr_in); | ||
| 531 | socklen_t* const p_addrlen = addr ? &addrlen : nullptr; | ||
| 532 | sockaddr* const p_addr_in = addr ? &addr_in : nullptr; | ||
| 533 | |||
| 534 | const int result = recvfrom(fd, reinterpret_cast<char*>(message.data()), | ||
| 535 | static_cast<int>(message.size()), 0, p_addr_in, p_addrlen); | ||
| 536 | if (result != SOCKET_ERROR) { | ||
| 537 | if (addr) { | ||
| 538 | ASSERT(addrlen == sizeof(addr_in)); | ||
| 539 | *addr = TranslateToSockAddrIn(addr_in); | ||
| 540 | } | ||
| 541 | return {result, Errno::SUCCESS}; | ||
| 542 | } | ||
| 543 | |||
| 544 | switch (const int ec = LastError()) { | ||
| 545 | case WSAEWOULDBLOCK: | ||
| 546 | LOG_DEBUG(Service, "EAGAIN generated"); | ||
| 547 | return {-1, Errno::AGAIN}; | ||
| 548 | case WSAENOTCONN: | ||
| 549 | LOG_ERROR(Service, "ENOTCONN generated"); | ||
| 550 | return {-1, Errno::NOTCONN}; | ||
| 551 | default: | ||
| 552 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 553 | return {-1, Errno::SUCCESS}; | ||
| 554 | } | ||
| 555 | } | ||
| 556 | |||
| 557 | std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, int flags) { | ||
| 558 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); | ||
| 559 | ASSERT(flags == 0); | ||
| 560 | |||
| 561 | const int result = send(fd, reinterpret_cast<const char*>(message.data()), | ||
| 562 | static_cast<int>(message.size()), 0); | ||
| 563 | if (result != SOCKET_ERROR) { | ||
| 564 | return {result, Errno::SUCCESS}; | ||
| 565 | } | ||
| 566 | |||
| 567 | const int ec = LastError(); | ||
| 568 | switch (ec) { | ||
| 569 | case WSAEWOULDBLOCK: | ||
| 570 | LOG_DEBUG(Service, "EAGAIN generated"); | ||
| 571 | return {-1, Errno::AGAIN}; | ||
| 572 | case WSAENOTCONN: | ||
| 573 | LOG_ERROR(Service, "ENOTCONN generated"); | ||
| 574 | return {-1, Errno::NOTCONN}; | ||
| 575 | default: | ||
| 576 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 577 | return {-1, Errno::SUCCESS}; | ||
| 578 | } | ||
| 579 | } | ||
| 580 | |||
| 581 | std::pair<s32, Errno> Socket::SendTo(u32 flags, const std::vector<u8>& message, | ||
| 582 | const SockAddrIn* addr) { | ||
| 583 | ASSERT(flags == 0); | ||
| 584 | |||
| 585 | const sockaddr* to = nullptr; | ||
| 586 | const int tolen = addr ? 0 : sizeof(sockaddr); | ||
| 587 | sockaddr host_addr_in; | ||
| 588 | |||
| 589 | if (addr) { | ||
| 590 | host_addr_in = TranslateFromSockAddrIn(*addr); | ||
| 591 | to = &host_addr_in; | ||
| 592 | } | ||
| 593 | |||
| 594 | const int result = sendto(fd, reinterpret_cast<const char*>(message.data()), | ||
| 595 | static_cast<int>(message.size()), 0, to, tolen); | ||
| 596 | if (result != SOCKET_ERROR) { | ||
| 597 | return {result, Errno::SUCCESS}; | ||
| 598 | } | ||
| 599 | |||
| 600 | const int ec = LastError(); | ||
| 601 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 602 | return {-1, Errno::SUCCESS}; | ||
| 603 | } | ||
| 604 | |||
| 605 | Errno Socket::Close() { | ||
| 606 | [[maybe_unused]] const int result = closesocket(fd); | ||
| 607 | ASSERT(result == 0); | ||
| 608 | fd = INVALID_SOCKET; | ||
| 609 | |||
| 610 | return Errno::SUCCESS; | ||
| 611 | } | ||
| 612 | |||
| 613 | Errno Socket::SetLinger(bool enable, u32 linger) { | ||
| 614 | return SetSockOpt(fd, SO_LINGER, MakeLinger(enable, linger)); | ||
| 615 | } | ||
| 616 | |||
| 617 | Errno Socket::SetReuseAddr(bool enable) { | ||
| 618 | return SetSockOpt<u32>(fd, SO_REUSEADDR, enable ? 1 : 0); | ||
| 619 | } | ||
| 620 | |||
| 621 | Errno Socket::SetBroadcast(bool enable) { | ||
| 622 | return SetSockOpt<u32>(fd, SO_BROADCAST, enable ? 1 : 0); | ||
| 623 | } | ||
| 624 | |||
| 625 | Errno Socket::SetSndBuf(u32 value) { | ||
| 626 | return SetSockOpt(fd, SO_SNDBUF, value); | ||
| 627 | } | ||
| 628 | |||
| 629 | Errno Socket::SetRcvBuf(u32 value) { | ||
| 630 | return SetSockOpt(fd, SO_RCVBUF, value); | ||
| 631 | } | ||
| 632 | |||
| 633 | Errno Socket::SetSndTimeo(u32 value) { | ||
| 634 | return SetSockOpt(fd, SO_SNDTIMEO, value); | ||
| 635 | } | ||
| 636 | |||
| 637 | Errno Socket::SetRcvTimeo(u32 value) { | ||
| 638 | return SetSockOpt(fd, SO_RCVTIMEO, value); | ||
| 639 | } | ||
| 640 | |||
| 641 | Errno Socket::SetNonBlock(bool enable) { | ||
| 642 | if (EnableNonBlock(fd, enable)) { | ||
| 643 | return Errno::SUCCESS; | ||
| 644 | } | ||
| 645 | const int ec = LastError(); | ||
| 646 | UNREACHABLE_MSG("Unhandled host socket error={}", ec); | ||
| 647 | return Errno::SUCCESS; | ||
| 648 | } | ||
| 649 | |||
| 650 | bool Socket::IsOpened() const { | ||
| 651 | return fd != INVALID_SOCKET; | ||
| 652 | } | ||
| 653 | |||
| 654 | } // namespace Network | ||
diff --git a/src/core/network/network.h b/src/core/network/network.h new file mode 100644 index 000000000..0622e4593 --- /dev/null +++ b/src/core/network/network.h | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | // Copyright 2020 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 <array> | ||
| 8 | #include <utility> | ||
| 9 | |||
| 10 | #include "common/common_types.h" | ||
| 11 | |||
| 12 | namespace Network { | ||
| 13 | |||
| 14 | class Socket; | ||
| 15 | |||
| 16 | /// Error code for network functions | ||
| 17 | enum class Errno { | ||
| 18 | SUCCESS, | ||
| 19 | BADF, | ||
| 20 | INVAL, | ||
| 21 | MFILE, | ||
| 22 | NOTCONN, | ||
| 23 | AGAIN, | ||
| 24 | }; | ||
| 25 | |||
| 26 | /// Address families | ||
| 27 | enum class Domain { | ||
| 28 | INET, ///< Address family for IPv4 | ||
| 29 | }; | ||
| 30 | |||
| 31 | /// Socket types | ||
| 32 | enum class Type { | ||
| 33 | STREAM, | ||
| 34 | DGRAM, | ||
| 35 | RAW, | ||
| 36 | SEQPACKET, | ||
| 37 | }; | ||
| 38 | |||
| 39 | /// Protocol values for sockets | ||
| 40 | enum class Protocol { | ||
| 41 | ICMP, | ||
| 42 | TCP, | ||
| 43 | UDP, | ||
| 44 | }; | ||
| 45 | |||
| 46 | /// Shutdown mode | ||
| 47 | enum class ShutdownHow { | ||
| 48 | RD, | ||
| 49 | WR, | ||
| 50 | RDWR, | ||
| 51 | }; | ||
| 52 | |||
| 53 | /// Array of IPv4 address | ||
| 54 | using IPv4Address = std::array<u8, 4>; | ||
| 55 | |||
| 56 | /// Cross-platform sockaddr structure | ||
| 57 | struct SockAddrIn { | ||
| 58 | Domain family; | ||
| 59 | IPv4Address ip; | ||
| 60 | u16 portno; | ||
| 61 | }; | ||
| 62 | |||
| 63 | /// Cross-platform poll fd structure | ||
| 64 | struct PollFD { | ||
| 65 | Socket* socket; | ||
| 66 | u16 events; | ||
| 67 | u16 revents; | ||
| 68 | }; | ||
| 69 | |||
| 70 | constexpr u16 POLL_IN = 1 << 0; | ||
| 71 | constexpr u16 POLL_PRI = 1 << 1; | ||
| 72 | constexpr u16 POLL_OUT = 1 << 2; | ||
| 73 | constexpr u16 POLL_ERR = 1 << 3; | ||
| 74 | constexpr u16 POLL_HUP = 1 << 4; | ||
| 75 | constexpr u16 POLL_NVAL = 1 << 5; | ||
| 76 | |||
| 77 | class NetworkInstance { | ||
| 78 | public: | ||
| 79 | explicit NetworkInstance(); | ||
| 80 | ~NetworkInstance(); | ||
| 81 | }; | ||
| 82 | |||
| 83 | /// @brief Returns host's IPv4 address | ||
| 84 | /// @return Pair of an array of human ordered IPv4 address (e.g. 192.168.0.1) and an error code | ||
| 85 | std::pair<IPv4Address, Errno> GetHostIPv4Address(); | ||
| 86 | |||
| 87 | } // namespace Network | ||
diff --git a/src/core/network/sockets.h b/src/core/network/sockets.h new file mode 100644 index 000000000..7bdff0fe4 --- /dev/null +++ b/src/core/network/sockets.h | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | // Copyright 2020 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 <memory> | ||
| 8 | #include <utility> | ||
| 9 | |||
| 10 | #if defined(_WIN32) | ||
| 11 | #include <winsock.h> | ||
| 12 | #elif !defined(__unix__) | ||
| 13 | #error "Platform not implemented" | ||
| 14 | #endif | ||
| 15 | |||
| 16 | #include "common/common_types.h" | ||
| 17 | #include "core/network/network.h" | ||
| 18 | |||
| 19 | // TODO: C++20 Replace std::vector usages with std::span | ||
| 20 | |||
| 21 | namespace Network { | ||
| 22 | |||
| 23 | class Socket { | ||
| 24 | public: | ||
| 25 | struct AcceptResult { | ||
| 26 | std::unique_ptr<Socket> socket; | ||
| 27 | SockAddrIn sockaddr_in; | ||
| 28 | }; | ||
| 29 | |||
| 30 | explicit Socket() = default; | ||
| 31 | ~Socket(); | ||
| 32 | |||
| 33 | Socket(const Socket&) = delete; | ||
| 34 | Socket& operator=(const Socket&) = delete; | ||
| 35 | |||
| 36 | Socket(Socket&& rhs) noexcept; | ||
| 37 | |||
| 38 | // Avoid closing sockets implicitly | ||
| 39 | Socket& operator=(Socket&&) noexcept = delete; | ||
| 40 | |||
| 41 | Errno Initialize(Domain domain, Type type, Protocol protocol); | ||
| 42 | |||
| 43 | Errno Close(); | ||
| 44 | |||
| 45 | std::pair<AcceptResult, Errno> Accept(); | ||
| 46 | |||
| 47 | Errno Connect(SockAddrIn addr_in); | ||
| 48 | |||
| 49 | std::pair<SockAddrIn, Errno> GetPeerName(); | ||
| 50 | |||
| 51 | std::pair<SockAddrIn, Errno> GetSockName(); | ||
| 52 | |||
| 53 | Errno Bind(SockAddrIn addr); | ||
| 54 | |||
| 55 | Errno Listen(s32 backlog); | ||
| 56 | |||
| 57 | Errno Shutdown(ShutdownHow how); | ||
| 58 | |||
| 59 | std::pair<s32, Errno> Recv(int flags, std::vector<u8>& message); | ||
| 60 | |||
| 61 | std::pair<s32, Errno> RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr); | ||
| 62 | |||
| 63 | std::pair<s32, Errno> Send(const std::vector<u8>& message, int flags); | ||
| 64 | |||
| 65 | std::pair<s32, Errno> SendTo(u32 flags, const std::vector<u8>& message, const SockAddrIn* addr); | ||
| 66 | |||
| 67 | Errno SetLinger(bool enable, u32 linger); | ||
| 68 | |||
| 69 | Errno SetReuseAddr(bool enable); | ||
| 70 | |||
| 71 | Errno SetBroadcast(bool enable); | ||
| 72 | |||
| 73 | Errno SetSndBuf(u32 value); | ||
| 74 | |||
| 75 | Errno SetRcvBuf(u32 value); | ||
| 76 | |||
| 77 | Errno SetSndTimeo(u32 value); | ||
| 78 | |||
| 79 | Errno SetRcvTimeo(u32 value); | ||
| 80 | |||
| 81 | Errno SetNonBlock(bool enable); | ||
| 82 | |||
| 83 | bool IsOpened() const; | ||
| 84 | |||
| 85 | #if defined(_WIN32) | ||
| 86 | SOCKET fd = INVALID_SOCKET; | ||
| 87 | #elif defined(__unix__) | ||
| 88 | int fd = -1; | ||
| 89 | #endif | ||
| 90 | }; | ||
| 91 | |||
| 92 | std::pair<s32, Errno> Poll(std::vector<PollFD>& poll_fds, s32 timeout); | ||
| 93 | |||
| 94 | } // namespace Network | ||
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 29339ead7..b899ac884 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp | |||
| @@ -74,15 +74,16 @@ void PerfStats::EndGameFrame() { | |||
| 74 | game_frames += 1; | 74 | game_frames += 1; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | double PerfStats::GetMeanFrametime() { | 77 | double PerfStats::GetMeanFrametime() const { |
| 78 | std::lock_guard lock{object_mutex}; | 78 | std::lock_guard lock{object_mutex}; |
| 79 | 79 | ||
| 80 | if (current_index <= IgnoreFrames) { | 80 | if (current_index <= IgnoreFrames) { |
| 81 | return 0; | 81 | return 0; |
| 82 | } | 82 | } |
| 83 | |||
| 83 | const double sum = std::accumulate(perf_history.begin() + IgnoreFrames, | 84 | const double sum = std::accumulate(perf_history.begin() + IgnoreFrames, |
| 84 | perf_history.begin() + current_index, 0.0); | 85 | perf_history.begin() + current_index, 0.0); |
| 85 | return sum / (current_index - IgnoreFrames); | 86 | return sum / static_cast<double>(current_index - IgnoreFrames); |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) { | 89 | PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us) { |
| @@ -94,12 +95,13 @@ PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us | |||
| 94 | 95 | ||
| 95 | const auto system_us_per_second = (current_system_time_us - reset_point_system_us) / interval; | 96 | const auto system_us_per_second = (current_system_time_us - reset_point_system_us) / interval; |
| 96 | 97 | ||
| 97 | PerfStatsResults results{}; | 98 | const PerfStatsResults results{ |
| 98 | results.system_fps = static_cast<double>(system_frames) / interval; | 99 | .system_fps = static_cast<double>(system_frames) / interval, |
| 99 | results.game_fps = static_cast<double>(game_frames) / interval; | 100 | .game_fps = static_cast<double>(game_frames) / interval, |
| 100 | results.frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() / | 101 | .frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() / |
| 101 | static_cast<double>(system_frames); | 102 | static_cast<double>(system_frames), |
| 102 | results.emulation_speed = system_us_per_second.count() / 1'000'000.0; | 103 | .emulation_speed = system_us_per_second.count() / 1'000'000.0, |
| 104 | }; | ||
| 103 | 105 | ||
| 104 | // Reset counters | 106 | // Reset counters |
| 105 | reset_point = now; | 107 | reset_point = now; |
| @@ -111,7 +113,7 @@ PerfStatsResults PerfStats::GetAndResetStats(microseconds current_system_time_us | |||
| 111 | return results; | 113 | return results; |
| 112 | } | 114 | } |
| 113 | 115 | ||
| 114 | double PerfStats::GetLastFrameTimeScale() { | 116 | double PerfStats::GetLastFrameTimeScale() const { |
| 115 | std::lock_guard lock{object_mutex}; | 117 | std::lock_guard lock{object_mutex}; |
| 116 | 118 | ||
| 117 | constexpr double FRAME_LENGTH = 1.0 / 60; | 119 | constexpr double FRAME_LENGTH = 1.0 / 60; |
diff --git a/src/core/perf_stats.h b/src/core/perf_stats.h index d9a64f072..69256b960 100644 --- a/src/core/perf_stats.h +++ b/src/core/perf_stats.h | |||
| @@ -30,7 +30,6 @@ struct PerfStatsResults { | |||
| 30 | class PerfStats { | 30 | class PerfStats { |
| 31 | public: | 31 | public: |
| 32 | explicit PerfStats(u64 title_id); | 32 | explicit PerfStats(u64 title_id); |
| 33 | |||
| 34 | ~PerfStats(); | 33 | ~PerfStats(); |
| 35 | 34 | ||
| 36 | using Clock = std::chrono::high_resolution_clock; | 35 | using Clock = std::chrono::high_resolution_clock; |
| @@ -42,18 +41,18 @@ public: | |||
| 42 | PerfStatsResults GetAndResetStats(std::chrono::microseconds current_system_time_us); | 41 | PerfStatsResults GetAndResetStats(std::chrono::microseconds current_system_time_us); |
| 43 | 42 | ||
| 44 | /** | 43 | /** |
| 45 | * Returns the Arthimetic Mean of all frametime values stored in the performance history. | 44 | * Returns the arithmetic mean of all frametime values stored in the performance history. |
| 46 | */ | 45 | */ |
| 47 | double GetMeanFrametime(); | 46 | double GetMeanFrametime() const; |
| 48 | 47 | ||
| 49 | /** | 48 | /** |
| 50 | * Gets the ratio between walltime and the emulated time of the previous system frame. This is | 49 | * Gets the ratio between walltime and the emulated time of the previous system frame. This is |
| 51 | * useful for scaling inputs or outputs moving between the two time domains. | 50 | * useful for scaling inputs or outputs moving between the two time domains. |
| 52 | */ | 51 | */ |
| 53 | double GetLastFrameTimeScale(); | 52 | double GetLastFrameTimeScale() const; |
| 54 | 53 | ||
| 55 | private: | 54 | private: |
| 56 | std::mutex object_mutex{}; | 55 | mutable std::mutex object_mutex; |
| 57 | 56 | ||
| 58 | /// Title ID for the game that is running. 0 if there is no game running yet | 57 | /// Title ID for the game that is running. 0 if there is no game running yet |
| 59 | u64 title_id{0}; | 58 | u64 title_id{0}; |
| @@ -61,7 +60,7 @@ private: | |||
| 61 | std::size_t current_index{0}; | 60 | std::size_t current_index{0}; |
| 62 | /// Stores an hour of historical frametime data useful for processing and tracking performance | 61 | /// Stores an hour of historical frametime data useful for processing and tracking performance |
| 63 | /// regressions with code changes. | 62 | /// regressions with code changes. |
| 64 | std::array<double, 216000> perf_history = {}; | 63 | std::array<double, 216000> perf_history{}; |
| 65 | 64 | ||
| 66 | /// Point when the cumulative counters were reset | 65 | /// Point when the cumulative counters were reset |
| 67 | Clock::time_point reset_point = Clock::now(); | 66 | Clock::time_point reset_point = Clock::now(); |
diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 44252dd81..416b2d866 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp | |||
| @@ -173,7 +173,6 @@ void RestoreGlobalState() { | |||
| 173 | values.use_assembly_shaders.SetGlobal(true); | 173 | values.use_assembly_shaders.SetGlobal(true); |
| 174 | values.use_asynchronous_shaders.SetGlobal(true); | 174 | values.use_asynchronous_shaders.SetGlobal(true); |
| 175 | values.use_fast_gpu_time.SetGlobal(true); | 175 | values.use_fast_gpu_time.SetGlobal(true); |
| 176 | values.force_30fps_mode.SetGlobal(true); | ||
| 177 | values.bg_red.SetGlobal(true); | 176 | values.bg_red.SetGlobal(true); |
| 178 | values.bg_green.SetGlobal(true); | 177 | values.bg_green.SetGlobal(true); |
| 179 | values.bg_blue.SetGlobal(true); | 178 | values.bg_blue.SetGlobal(true); |
diff --git a/src/core/settings.h b/src/core/settings.h index 386233fdf..bb145f193 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -435,7 +435,6 @@ struct Values { | |||
| 435 | Setting<bool> use_vsync; | 435 | Setting<bool> use_vsync; |
| 436 | Setting<bool> use_assembly_shaders; | 436 | Setting<bool> use_assembly_shaders; |
| 437 | Setting<bool> use_asynchronous_shaders; | 437 | Setting<bool> use_asynchronous_shaders; |
| 438 | Setting<bool> force_30fps_mode; | ||
| 439 | Setting<bool> use_fast_gpu_time; | 438 | Setting<bool> use_fast_gpu_time; |
| 440 | 439 | ||
| 441 | Setting<float> bg_red; | 440 | Setting<float> bg_red; |
diff --git a/src/core/tools/freezer.cpp b/src/core/tools/freezer.cpp index 27b894b51..2003e096f 100644 --- a/src/core/tools/freezer.cpp +++ b/src/core/tools/freezer.cpp | |||
| @@ -55,10 +55,11 @@ void MemoryWriteWidth(Core::Memory::Memory& memory, u32 width, VAddr addr, u64 v | |||
| 55 | 55 | ||
| 56 | Freezer::Freezer(Core::Timing::CoreTiming& core_timing_, Core::Memory::Memory& memory_) | 56 | Freezer::Freezer(Core::Timing::CoreTiming& core_timing_, Core::Memory::Memory& memory_) |
| 57 | : core_timing{core_timing_}, memory{memory_} { | 57 | : core_timing{core_timing_}, memory{memory_} { |
| 58 | event = Core::Timing::CreateEvent("MemoryFreezer::FrameCallback", | 58 | event = Core::Timing::CreateEvent( |
| 59 | [this](u64 userdata, std::chrono::nanoseconds ns_late) { | 59 | "MemoryFreezer::FrameCallback", |
| 60 | FrameCallback(userdata, ns_late); | 60 | [this](std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { |
| 61 | }); | 61 | FrameCallback(user_data, ns_late); |
| 62 | }); | ||
| 62 | core_timing.ScheduleEvent(memory_freezer_ns, event); | 63 | core_timing.ScheduleEvent(memory_freezer_ns, event); |
| 63 | } | 64 | } |
| 64 | 65 | ||
| @@ -159,7 +160,7 @@ std::vector<Freezer::Entry> Freezer::GetEntries() const { | |||
| 159 | return entries; | 160 | return entries; |
| 160 | } | 161 | } |
| 161 | 162 | ||
| 162 | void Freezer::FrameCallback(u64, std::chrono::nanoseconds ns_late) { | 163 | void Freezer::FrameCallback(std::uintptr_t, std::chrono::nanoseconds ns_late) { |
| 163 | if (!IsActive()) { | 164 | if (!IsActive()) { |
| 164 | LOG_DEBUG(Common_Memory, "Memory freezer has been deactivated, ending callback events."); | 165 | LOG_DEBUG(Common_Memory, "Memory freezer has been deactivated, ending callback events."); |
| 165 | return; | 166 | return; |
diff --git a/src/core/tools/freezer.h b/src/core/tools/freezer.h index 8438783d5..2b2326bc4 100644 --- a/src/core/tools/freezer.h +++ b/src/core/tools/freezer.h | |||
| @@ -73,7 +73,7 @@ public: | |||
| 73 | std::vector<Entry> GetEntries() const; | 73 | std::vector<Entry> GetEntries() const; |
| 74 | 74 | ||
| 75 | private: | 75 | private: |
| 76 | void FrameCallback(u64 userdata, std::chrono::nanoseconds ns_late); | 76 | void FrameCallback(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); |
| 77 | void FillEntryReads(); | 77 | void FillEntryReads(); |
| 78 | 78 | ||
| 79 | std::atomic_bool active{false}; | 79 | std::atomic_bool active{false}; |
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 898a278a9..74759ea7d 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -24,12 +24,9 @@ Adapter::Adapter() { | |||
| 24 | } | 24 | } |
| 25 | LOG_INFO(Input, "GC Adapter Initialization started"); | 25 | LOG_INFO(Input, "GC Adapter Initialization started"); |
| 26 | 26 | ||
| 27 | current_status = NO_ADAPTER_DETECTED; | ||
| 28 | get_origin.fill(true); | ||
| 29 | |||
| 30 | const int init_res = libusb_init(&libusb_ctx); | 27 | const int init_res = libusb_init(&libusb_ctx); |
| 31 | if (init_res == LIBUSB_SUCCESS) { | 28 | if (init_res == LIBUSB_SUCCESS) { |
| 32 | StartScanThread(); | 29 | Setup(); |
| 33 | } else { | 30 | } else { |
| 34 | LOG_ERROR(Input, "libusb could not be initialized. failed with error = {}", init_res); | 31 | LOG_ERROR(Input, "libusb could not be initialized. failed with error = {}", init_res); |
| 35 | } | 32 | } |
| @@ -37,9 +34,9 @@ Adapter::Adapter() { | |||
| 37 | 34 | ||
| 38 | GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array<u8, 37>& adapter_payload) { | 35 | GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array<u8, 37>& adapter_payload) { |
| 39 | GCPadStatus pad = {}; | 36 | GCPadStatus pad = {}; |
| 37 | const std::size_t offset = 1 + (9 * port); | ||
| 40 | 38 | ||
| 41 | ControllerTypes type = ControllerTypes(adapter_payload[1 + (9 * port)] >> 4); | 39 | adapter_controllers_status[port] = static_cast<ControllerTypes>(adapter_payload[offset] >> 4); |
| 42 | adapter_controllers_status[port] = type; | ||
| 43 | 40 | ||
| 44 | static constexpr std::array<PadButton, 8> b1_buttons{ | 41 | static constexpr std::array<PadButton, 8> b1_buttons{ |
| 45 | PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, PadButton::PAD_BUTTON_X, | 42 | PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, PadButton::PAD_BUTTON_X, |
| @@ -54,14 +51,19 @@ GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array<u8, 37>& ad | |||
| 54 | PadButton::PAD_TRIGGER_L, | 51 | PadButton::PAD_TRIGGER_L, |
| 55 | }; | 52 | }; |
| 56 | 53 | ||
| 54 | static constexpr std::array<PadAxes, 6> axes{ | ||
| 55 | PadAxes::StickX, PadAxes::StickY, PadAxes::SubstickX, | ||
| 56 | PadAxes::SubstickY, PadAxes::TriggerLeft, PadAxes::TriggerRight, | ||
| 57 | }; | ||
| 58 | |||
| 57 | if (adapter_controllers_status[port] == ControllerTypes::None && !get_origin[port]) { | 59 | if (adapter_controllers_status[port] == ControllerTypes::None && !get_origin[port]) { |
| 58 | // Controller may have been disconnected, recalibrate if reconnected. | 60 | // Controller may have been disconnected, recalibrate if reconnected. |
| 59 | get_origin[port] = true; | 61 | get_origin[port] = true; |
| 60 | } | 62 | } |
| 61 | 63 | ||
| 62 | if (adapter_controllers_status[port] != ControllerTypes::None) { | 64 | if (adapter_controllers_status[port] != ControllerTypes::None) { |
| 63 | const u8 b1 = adapter_payload[1 + (9 * port) + 1]; | 65 | const u8 b1 = adapter_payload[offset + 1]; |
| 64 | const u8 b2 = adapter_payload[1 + (9 * port) + 2]; | 66 | const u8 b2 = adapter_payload[offset + 2]; |
| 65 | 67 | ||
| 66 | for (std::size_t i = 0; i < b1_buttons.size(); ++i) { | 68 | for (std::size_t i = 0; i < b1_buttons.size(); ++i) { |
| 67 | if ((b1 & (1U << i)) != 0) { | 69 | if ((b1 & (1U << i)) != 0) { |
| @@ -74,21 +76,13 @@ GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array<u8, 37>& ad | |||
| 74 | pad.button |= static_cast<u16>(b2_buttons[j]); | 76 | pad.button |= static_cast<u16>(b2_buttons[j]); |
| 75 | } | 77 | } |
| 76 | } | 78 | } |
| 77 | 79 | for (PadAxes axis : axes) { | |
| 78 | pad.stick_x = adapter_payload[1 + (9 * port) + 3]; | 80 | const std::size_t index = static_cast<std::size_t>(axis); |
| 79 | pad.stick_y = adapter_payload[1 + (9 * port) + 4]; | 81 | pad.axis_values[index] = adapter_payload[offset + 3 + index]; |
| 80 | pad.substick_x = adapter_payload[1 + (9 * port) + 5]; | 82 | } |
| 81 | pad.substick_y = adapter_payload[1 + (9 * port) + 6]; | ||
| 82 | pad.trigger_left = adapter_payload[1 + (9 * port) + 7]; | ||
| 83 | pad.trigger_right = adapter_payload[1 + (9 * port) + 8]; | ||
| 84 | 83 | ||
| 85 | if (get_origin[port]) { | 84 | if (get_origin[port]) { |
| 86 | origin_status[port].stick_x = pad.stick_x; | 85 | origin_status[port].axis_values = pad.axis_values; |
| 87 | origin_status[port].stick_y = pad.stick_y; | ||
| 88 | origin_status[port].substick_x = pad.substick_x; | ||
| 89 | origin_status[port].substick_y = pad.substick_y; | ||
| 90 | origin_status[port].trigger_left = pad.trigger_left; | ||
| 91 | origin_status[port].trigger_right = pad.trigger_right; | ||
| 92 | get_origin[port] = false; | 86 | get_origin[port] = false; |
| 93 | } | 87 | } |
| 94 | } | 88 | } |
| @@ -101,82 +95,47 @@ void Adapter::PadToState(const GCPadStatus& pad, GCState& state) { | |||
| 101 | state.buttons.insert_or_assign(button_value, pad.button & button_value); | 95 | state.buttons.insert_or_assign(button_value, pad.button & button_value); |
| 102 | } | 96 | } |
| 103 | 97 | ||
| 104 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::StickX), pad.stick_x); | 98 | for (size_t i = 0; i < pad.axis_values.size(); ++i) { |
| 105 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::StickY), pad.stick_y); | 99 | state.axes.insert_or_assign(static_cast<u8>(i), pad.axis_values[i]); |
| 106 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::SubstickX), pad.substick_x); | 100 | } |
| 107 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::SubstickY), pad.substick_y); | ||
| 108 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::TriggerLeft), pad.trigger_left); | ||
| 109 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::TriggerRight), pad.trigger_right); | ||
| 110 | } | 101 | } |
| 111 | 102 | ||
| 112 | void Adapter::Read() { | 103 | void Adapter::Read() { |
| 113 | LOG_DEBUG(Input, "GC Adapter Read() thread started"); | 104 | LOG_DEBUG(Input, "GC Adapter Read() thread started"); |
| 114 | 105 | ||
| 115 | int payload_size_in, payload_size_copy; | 106 | int payload_size; |
| 116 | std::array<u8, 37> adapter_payload; | 107 | std::array<u8, 37> adapter_payload; |
| 117 | std::array<u8, 37> adapter_payload_copy; | ||
| 118 | std::array<GCPadStatus, 4> pads; | 108 | std::array<GCPadStatus, 4> pads; |
| 119 | 109 | ||
| 120 | while (adapter_thread_running) { | 110 | while (adapter_thread_running) { |
| 121 | libusb_interrupt_transfer(usb_adapter_handle, input_endpoint, adapter_payload.data(), | 111 | libusb_interrupt_transfer(usb_adapter_handle, input_endpoint, adapter_payload.data(), |
| 122 | sizeof(adapter_payload), &payload_size_in, 16); | 112 | sizeof(adapter_payload), &payload_size, 16); |
| 123 | payload_size_copy = 0; | ||
| 124 | // this mutex might be redundant? | ||
| 125 | { | ||
| 126 | std::lock_guard<std::mutex> lk(s_mutex); | ||
| 127 | std::copy(std::begin(adapter_payload), std::end(adapter_payload), | ||
| 128 | std::begin(adapter_payload_copy)); | ||
| 129 | payload_size_copy = payload_size_in; | ||
| 130 | } | ||
| 131 | 113 | ||
| 132 | if (payload_size_copy != sizeof(adapter_payload_copy) || | 114 | if (payload_size != sizeof(adapter_payload) || adapter_payload[0] != LIBUSB_DT_HID) { |
| 133 | adapter_payload_copy[0] != LIBUSB_DT_HID) { | 115 | LOG_ERROR(Input, |
| 134 | LOG_ERROR(Input, "error reading payload (size: {}, type: {:02x})", payload_size_copy, | 116 | "Error reading payload (size: {}, type: {:02x}) Is the adapter connected?", |
| 135 | adapter_payload_copy[0]); | 117 | payload_size, adapter_payload[0]); |
| 136 | adapter_thread_running = false; // error reading from adapter, stop reading. | 118 | adapter_thread_running = false; // error reading from adapter, stop reading. |
| 137 | break; | 119 | break; |
| 138 | } | 120 | } |
| 139 | for (std::size_t port = 0; port < pads.size(); ++port) { | 121 | for (std::size_t port = 0; port < pads.size(); ++port) { |
| 140 | pads[port] = GetPadStatus(port, adapter_payload_copy); | 122 | pads[port] = GetPadStatus(port, adapter_payload); |
| 141 | if (DeviceConnected(port) && configuring) { | 123 | if (DeviceConnected(port) && configuring) { |
| 142 | if (pads[port].button != 0) { | 124 | if (pads[port].button != 0) { |
| 143 | pad_queue[port].Push(pads[port]); | 125 | pad_queue[port].Push(pads[port]); |
| 144 | } | 126 | } |
| 145 | 127 | ||
| 146 | // Accounting for a threshold here because of some controller variance | 128 | // Accounting for a threshold here to ensure an intentional press |
| 147 | if (pads[port].stick_x > origin_status[port].stick_x + pads[port].THRESHOLD || | 129 | for (size_t i = 0; i < pads[port].axis_values.size(); ++i) { |
| 148 | pads[port].stick_x < origin_status[port].stick_x - pads[port].THRESHOLD) { | 130 | const u8 value = pads[port].axis_values[i]; |
| 149 | pads[port].axis = GCAdapter::PadAxes::StickX; | 131 | const u8 origin = origin_status[port].axis_values[i]; |
| 150 | pads[port].axis_value = pads[port].stick_x; | 132 | |
| 151 | pad_queue[port].Push(pads[port]); | 133 | if (value > origin + pads[port].THRESHOLD || |
| 152 | } | 134 | value < origin - pads[port].THRESHOLD) { |
| 153 | if (pads[port].stick_y > origin_status[port].stick_y + pads[port].THRESHOLD || | 135 | pads[port].axis = static_cast<PadAxes>(i); |
| 154 | pads[port].stick_y < origin_status[port].stick_y - pads[port].THRESHOLD) { | 136 | pads[port].axis_value = pads[port].axis_values[i]; |
| 155 | pads[port].axis = GCAdapter::PadAxes::StickY; | 137 | pad_queue[port].Push(pads[port]); |
| 156 | pads[port].axis_value = pads[port].stick_y; | 138 | } |
| 157 | pad_queue[port].Push(pads[port]); | ||
| 158 | } | ||
| 159 | if (pads[port].substick_x > origin_status[port].substick_x + pads[port].THRESHOLD || | ||
| 160 | pads[port].substick_x < origin_status[port].substick_x - pads[port].THRESHOLD) { | ||
| 161 | pads[port].axis = GCAdapter::PadAxes::SubstickX; | ||
| 162 | pads[port].axis_value = pads[port].substick_x; | ||
| 163 | pad_queue[port].Push(pads[port]); | ||
| 164 | } | ||
| 165 | if (pads[port].substick_y > origin_status[port].substick_y + pads[port].THRESHOLD || | ||
| 166 | pads[port].substick_y < origin_status[port].substick_y - pads[port].THRESHOLD) { | ||
| 167 | pads[port].axis = GCAdapter::PadAxes::SubstickY; | ||
| 168 | pads[port].axis_value = pads[port].substick_y; | ||
| 169 | pad_queue[port].Push(pads[port]); | ||
| 170 | } | ||
| 171 | if (pads[port].trigger_left > pads[port].TRIGGER_THRESHOLD) { | ||
| 172 | pads[port].axis = GCAdapter::PadAxes::TriggerLeft; | ||
| 173 | pads[port].axis_value = pads[port].trigger_left; | ||
| 174 | pad_queue[port].Push(pads[port]); | ||
| 175 | } | ||
| 176 | if (pads[port].trigger_right > pads[port].TRIGGER_THRESHOLD) { | ||
| 177 | pads[port].axis = GCAdapter::PadAxes::TriggerRight; | ||
| 178 | pads[port].axis_value = pads[port].trigger_right; | ||
| 179 | pad_queue[port].Push(pads[port]); | ||
| 180 | } | 139 | } |
| 181 | } | 140 | } |
| 182 | PadToState(pads[port], state[port]); | 141 | PadToState(pads[port], state[port]); |
| @@ -185,42 +144,11 @@ void Adapter::Read() { | |||
| 185 | } | 144 | } |
| 186 | } | 145 | } |
| 187 | 146 | ||
| 188 | void Adapter::ScanThreadFunc() { | ||
| 189 | LOG_INFO(Input, "GC Adapter scanning thread started"); | ||
| 190 | |||
| 191 | while (detect_thread_running) { | ||
| 192 | if (usb_adapter_handle == nullptr) { | ||
| 193 | std::lock_guard<std::mutex> lk(initialization_mutex); | ||
| 194 | Setup(); | ||
| 195 | } | ||
| 196 | std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | void Adapter::StartScanThread() { | ||
| 201 | if (detect_thread_running) { | ||
| 202 | return; | ||
| 203 | } | ||
| 204 | if (!libusb_ctx) { | ||
| 205 | return; | ||
| 206 | } | ||
| 207 | |||
| 208 | detect_thread_running = true; | ||
| 209 | detect_thread = std::thread(&Adapter::ScanThreadFunc, this); | ||
| 210 | } | ||
| 211 | |||
| 212 | void Adapter::StopScanThread() { | ||
| 213 | detect_thread_running = false; | ||
| 214 | detect_thread.join(); | ||
| 215 | } | ||
| 216 | |||
| 217 | void Adapter::Setup() { | 147 | void Adapter::Setup() { |
| 218 | // Reset the error status in case the adapter gets unplugged | 148 | // Initialize all controllers as unplugged |
| 219 | if (current_status < 0) { | ||
| 220 | current_status = NO_ADAPTER_DETECTED; | ||
| 221 | } | ||
| 222 | |||
| 223 | adapter_controllers_status.fill(ControllerTypes::None); | 149 | adapter_controllers_status.fill(ControllerTypes::None); |
| 150 | // Initialize all ports to store axis origin values | ||
| 151 | get_origin.fill(true); | ||
| 224 | 152 | ||
| 225 | // pointer to list of connected usb devices | 153 | // pointer to list of connected usb devices |
| 226 | libusb_device** devices{}; | 154 | libusb_device** devices{}; |
| @@ -229,8 +157,6 @@ void Adapter::Setup() { | |||
| 229 | const ssize_t device_count = libusb_get_device_list(libusb_ctx, &devices); | 157 | const ssize_t device_count = libusb_get_device_list(libusb_ctx, &devices); |
| 230 | if (device_count < 0) { | 158 | if (device_count < 0) { |
| 231 | LOG_ERROR(Input, "libusb_get_device_list failed with error: {}", device_count); | 159 | LOG_ERROR(Input, "libusb_get_device_list failed with error: {}", device_count); |
| 232 | detect_thread_running = false; // Stop the loop constantly checking for gc adapter | ||
| 233 | // TODO: For hotplug+gc adapter checkbox implementation, revert this. | ||
| 234 | return; | 160 | return; |
| 235 | } | 161 | } |
| 236 | 162 | ||
| @@ -244,9 +170,6 @@ void Adapter::Setup() { | |||
| 244 | } | 170 | } |
| 245 | libusb_free_device_list(devices, 1); | 171 | libusb_free_device_list(devices, 1); |
| 246 | } | 172 | } |
| 247 | // Break out of the ScanThreadFunc() loop that is constantly looking for the device | ||
| 248 | // Assumes user has GC adapter plugged in before launch to use the adapter | ||
| 249 | detect_thread_running = false; | ||
| 250 | } | 173 | } |
| 251 | 174 | ||
| 252 | bool Adapter::CheckDeviceAccess(libusb_device* device) { | 175 | bool Adapter::CheckDeviceAccess(libusb_device* device) { |
| @@ -331,32 +254,23 @@ void Adapter::GetGCEndpoint(libusb_device* device) { | |||
| 331 | sizeof(clear_payload), nullptr, 16); | 254 | sizeof(clear_payload), nullptr, 16); |
| 332 | 255 | ||
| 333 | adapter_thread_running = true; | 256 | adapter_thread_running = true; |
| 334 | current_status = ADAPTER_DETECTED; | 257 | adapter_input_thread = std::thread(&Adapter::Read, this); |
| 335 | adapter_input_thread = std::thread([=] { Read(); }); // Read input | ||
| 336 | } | 258 | } |
| 337 | 259 | ||
| 338 | Adapter::~Adapter() { | 260 | Adapter::~Adapter() { |
| 339 | StopScanThread(); | ||
| 340 | Reset(); | 261 | Reset(); |
| 341 | } | 262 | } |
| 342 | 263 | ||
| 343 | void Adapter::Reset() { | 264 | void Adapter::Reset() { |
| 344 | std::unique_lock<std::mutex> lock(initialization_mutex, std::defer_lock); | ||
| 345 | if (!lock.try_lock()) { | ||
| 346 | return; | ||
| 347 | } | ||
| 348 | if (current_status != ADAPTER_DETECTED) { | ||
| 349 | return; | ||
| 350 | } | ||
| 351 | |||
| 352 | if (adapter_thread_running) { | 265 | if (adapter_thread_running) { |
| 353 | adapter_thread_running = false; | 266 | adapter_thread_running = false; |
| 354 | } | 267 | } |
| 355 | adapter_input_thread.join(); | 268 | if (adapter_input_thread.joinable()) { |
| 269 | adapter_input_thread.join(); | ||
| 270 | } | ||
| 356 | 271 | ||
| 357 | adapter_controllers_status.fill(ControllerTypes::None); | 272 | adapter_controllers_status.fill(ControllerTypes::None); |
| 358 | get_origin.fill(true); | 273 | get_origin.fill(true); |
| 359 | current_status = NO_ADAPTER_DETECTED; | ||
| 360 | 274 | ||
| 361 | if (usb_adapter_handle) { | 275 | if (usb_adapter_handle) { |
| 362 | libusb_release_interface(usb_adapter_handle, 1); | 276 | libusb_release_interface(usb_adapter_handle, 1); |
| @@ -409,24 +323,7 @@ const std::array<GCState, 4>& Adapter::GetPadState() const { | |||
| 409 | } | 323 | } |
| 410 | 324 | ||
| 411 | int Adapter::GetOriginValue(int port, int axis) const { | 325 | int Adapter::GetOriginValue(int port, int axis) const { |
| 412 | const auto& status = origin_status[port]; | 326 | return origin_status[port].axis_values[axis]; |
| 413 | |||
| 414 | switch (static_cast<PadAxes>(axis)) { | ||
| 415 | case PadAxes::StickX: | ||
| 416 | return status.stick_x; | ||
| 417 | case PadAxes::StickY: | ||
| 418 | return status.stick_y; | ||
| 419 | case PadAxes::SubstickX: | ||
| 420 | return status.substick_x; | ||
| 421 | case PadAxes::SubstickY: | ||
| 422 | return status.substick_y; | ||
| 423 | case PadAxes::TriggerLeft: | ||
| 424 | return status.trigger_left; | ||
| 425 | case PadAxes::TriggerRight: | ||
| 426 | return status.trigger_right; | ||
| 427 | default: | ||
| 428 | return 0; | ||
| 429 | } | ||
| 430 | } | 327 | } |
| 431 | 328 | ||
| 432 | } // namespace GCAdapter | 329 | } // namespace GCAdapter |
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 3586c8bda..bed81915c 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h | |||
| @@ -47,24 +47,10 @@ enum class PadAxes : u8 { | |||
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | struct GCPadStatus { | 49 | struct GCPadStatus { |
| 50 | u16 button{}; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits | 50 | u16 button{}; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits |
| 51 | u8 stick_x{}; // 0 <= stick_x <= 255 | 51 | |
| 52 | u8 stick_y{}; // 0 <= stick_y <= 255 | 52 | std::array<u8, 6> axis_values{}; // Triggers and sticks, following indices defined in PadAxes |
| 53 | u8 substick_x{}; // 0 <= substick_x <= 255 | 53 | static constexpr u8 THRESHOLD = 50; // Threshold for axis press for polling |
| 54 | u8 substick_y{}; // 0 <= substick_y <= 255 | ||
| 55 | u8 trigger_left{}; // 0 <= trigger_left <= 255 | ||
| 56 | u8 trigger_right{}; // 0 <= trigger_right <= 255 | ||
| 57 | |||
| 58 | static constexpr u8 MAIN_STICK_CENTER_X = 0x80; | ||
| 59 | static constexpr u8 MAIN_STICK_CENTER_Y = 0x80; | ||
| 60 | static constexpr u8 MAIN_STICK_RADIUS = 0x7f; | ||
| 61 | static constexpr u8 C_STICK_CENTER_X = 0x80; | ||
| 62 | static constexpr u8 C_STICK_CENTER_Y = 0x80; | ||
| 63 | static constexpr u8 C_STICK_RADIUS = 0x7f; | ||
| 64 | static constexpr u8 THRESHOLD = 10; | ||
| 65 | |||
| 66 | // 256/4, at least a quarter press to count as a press. For polling mostly | ||
| 67 | static constexpr u8 TRIGGER_THRESHOLD = 64; | ||
| 68 | 54 | ||
| 69 | u8 port{}; | 55 | u8 port{}; |
| 70 | PadAxes axis{PadAxes::Undefined}; | 56 | PadAxes axis{PadAxes::Undefined}; |
| @@ -78,11 +64,6 @@ struct GCState { | |||
| 78 | 64 | ||
| 79 | enum class ControllerTypes { None, Wired, Wireless }; | 65 | enum class ControllerTypes { None, Wired, Wireless }; |
| 80 | 66 | ||
| 81 | enum { | ||
| 82 | NO_ADAPTER_DETECTED = 0, | ||
| 83 | ADAPTER_DETECTED = 1, | ||
| 84 | }; | ||
| 85 | |||
| 86 | class Adapter { | 67 | class Adapter { |
| 87 | public: | 68 | public: |
| 88 | /// Initialize the GC Adapter capture and read sequence | 69 | /// Initialize the GC Adapter capture and read sequence |
| @@ -111,12 +92,6 @@ private: | |||
| 111 | void PadToState(const GCPadStatus& pad, GCState& state); | 92 | void PadToState(const GCPadStatus& pad, GCState& state); |
| 112 | 93 | ||
| 113 | void Read(); | 94 | void Read(); |
| 114 | void ScanThreadFunc(); | ||
| 115 | /// Begin scanning for the GC Adapter. | ||
| 116 | void StartScanThread(); | ||
| 117 | |||
| 118 | /// Stop scanning for the adapter | ||
| 119 | void StopScanThread(); | ||
| 120 | 95 | ||
| 121 | /// Resets status of device connected to port | 96 | /// Resets status of device connected to port |
| 122 | void ResetDeviceType(std::size_t port); | 97 | void ResetDeviceType(std::size_t port); |
| @@ -133,19 +108,11 @@ private: | |||
| 133 | /// For use in initialization, querying devices to find the adapter | 108 | /// For use in initialization, querying devices to find the adapter |
| 134 | void Setup(); | 109 | void Setup(); |
| 135 | 110 | ||
| 136 | int current_status = NO_ADAPTER_DETECTED; | ||
| 137 | libusb_device_handle* usb_adapter_handle = nullptr; | 111 | libusb_device_handle* usb_adapter_handle = nullptr; |
| 138 | std::array<ControllerTypes, 4> adapter_controllers_status{}; | ||
| 139 | |||
| 140 | std::mutex s_mutex; | ||
| 141 | 112 | ||
| 142 | std::thread adapter_input_thread; | 113 | std::thread adapter_input_thread; |
| 143 | bool adapter_thread_running; | 114 | bool adapter_thread_running; |
| 144 | 115 | ||
| 145 | std::mutex initialization_mutex; | ||
| 146 | std::thread detect_thread; | ||
| 147 | bool detect_thread_running = false; | ||
| 148 | |||
| 149 | libusb_context* libusb_ctx; | 116 | libusb_context* libusb_ctx; |
| 150 | 117 | ||
| 151 | u8 input_endpoint = 0; | 118 | u8 input_endpoint = 0; |
| @@ -153,10 +120,11 @@ private: | |||
| 153 | 120 | ||
| 154 | bool configuring = false; | 121 | bool configuring = false; |
| 155 | 122 | ||
| 156 | std::array<Common::SPSCQueue<GCPadStatus>, 4> pad_queue; | ||
| 157 | std::array<GCState, 4> state; | 123 | std::array<GCState, 4> state; |
| 158 | std::array<bool, 4> get_origin; | 124 | std::array<bool, 4> get_origin; |
| 159 | std::array<GCPadStatus, 4> origin_status; | 125 | std::array<GCPadStatus, 4> origin_status; |
| 126 | std::array<Common::SPSCQueue<GCPadStatus>, 4> pad_queue; | ||
| 127 | std::array<ControllerTypes, 4> adapter_controllers_status{}; | ||
| 160 | }; | 128 | }; |
| 161 | 129 | ||
| 162 | } // namespace GCAdapter | 130 | } // namespace GCAdapter |
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 96e22d3ad..f45983f3f 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -76,8 +76,7 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param | |||
| 76 | 76 | ||
| 77 | // button is not an axis/stick button | 77 | // button is not an axis/stick button |
| 78 | if (button_id != PAD_STICK_ID) { | 78 | if (button_id != PAD_STICK_ID) { |
| 79 | auto button = std::make_unique<GCButton>(port, button_id, adapter.get()); | 79 | return std::make_unique<GCButton>(port, button_id, adapter.get()); |
| 80 | return std::move(button); | ||
| 81 | } | 80 | } |
| 82 | 81 | ||
| 83 | // For Axis buttons, used by the binary sticks. | 82 | // For Axis buttons, used by the binary sticks. |
| @@ -264,7 +263,8 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 264 | if (analog_x_axis == -1) { | 263 | if (analog_x_axis == -1) { |
| 265 | analog_x_axis = axis; | 264 | analog_x_axis = axis; |
| 266 | controller_number = static_cast<int>(port); | 265 | controller_number = static_cast<int>(port); |
| 267 | } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) { | 266 | } else if (analog_y_axis == -1 && analog_x_axis != axis && |
| 267 | controller_number == static_cast<int>(port)) { | ||
| 268 | analog_y_axis = axis; | 268 | analog_y_axis = axis; |
| 269 | } | 269 | } |
| 270 | } | 270 | } |
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index e63c73c4f..6c95a8b42 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -9,7 +9,6 @@ | |||
| 9 | #include <functional> | 9 | #include <functional> |
| 10 | #include <thread> | 10 | #include <thread> |
| 11 | #include <boost/asio.hpp> | 11 | #include <boost/asio.hpp> |
| 12 | #include <boost/bind.hpp> | ||
| 13 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 14 | #include "input_common/udp/client.h" | 13 | #include "input_common/udp/client.h" |
| 15 | #include "input_common/udp/protocol.h" | 14 | #include "input_common/udp/protocol.h" |
diff --git a/src/tests/core/core_timing.cpp b/src/tests/core/core_timing.cpp index 244463a47..b35459152 100644 --- a/src/tests/core/core_timing.cpp +++ b/src/tests/core/core_timing.cpp | |||
| @@ -25,10 +25,10 @@ std::bitset<CB_IDS.size()> callbacks_ran_flags; | |||
| 25 | u64 expected_callback = 0; | 25 | u64 expected_callback = 0; |
| 26 | 26 | ||
| 27 | template <unsigned int IDX> | 27 | template <unsigned int IDX> |
| 28 | void HostCallbackTemplate(u64 userdata, std::chrono::nanoseconds ns_late) { | 28 | void HostCallbackTemplate(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { |
| 29 | static_assert(IDX < CB_IDS.size(), "IDX out of range"); | 29 | static_assert(IDX < CB_IDS.size(), "IDX out of range"); |
| 30 | callbacks_ran_flags.set(IDX); | 30 | callbacks_ran_flags.set(IDX); |
| 31 | REQUIRE(CB_IDS[IDX] == userdata); | 31 | REQUIRE(CB_IDS[IDX] == user_data); |
| 32 | REQUIRE(CB_IDS[IDX] == CB_IDS[calls_order[expected_callback]]); | 32 | REQUIRE(CB_IDS[IDX] == CB_IDS[calls_order[expected_callback]]); |
| 33 | delays[IDX] = ns_late.count(); | 33 | delays[IDX] = ns_late.count(); |
| 34 | ++expected_callback; | 34 | ++expected_callback; |
| @@ -46,20 +46,16 @@ struct ScopeInit final { | |||
| 46 | Core::Timing::CoreTiming core_timing; | 46 | Core::Timing::CoreTiming core_timing; |
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | #pragma optimize("", off) | ||
| 50 | |||
| 51 | u64 TestTimerSpeed(Core::Timing::CoreTiming& core_timing) { | 49 | u64 TestTimerSpeed(Core::Timing::CoreTiming& core_timing) { |
| 52 | u64 start = core_timing.GetGlobalTimeNs().count(); | 50 | const u64 start = core_timing.GetGlobalTimeNs().count(); |
| 53 | u64 placebo = 0; | 51 | volatile u64 placebo = 0; |
| 54 | for (std::size_t i = 0; i < 1000; i++) { | 52 | for (std::size_t i = 0; i < 1000; i++) { |
| 55 | placebo += core_timing.GetGlobalTimeNs().count(); | 53 | placebo = placebo + core_timing.GetGlobalTimeNs().count(); |
| 56 | } | 54 | } |
| 57 | u64 end = core_timing.GetGlobalTimeNs().count(); | 55 | const u64 end = core_timing.GetGlobalTimeNs().count(); |
| 58 | return (end - start); | 56 | return end - start; |
| 59 | } | 57 | } |
| 60 | 58 | ||
| 61 | #pragma optimize("", on) | ||
| 62 | |||
| 63 | } // Anonymous namespace | 59 | } // Anonymous namespace |
| 64 | 60 | ||
| 65 | TEST_CASE("CoreTiming[BasicOrder]", "[core]") { | 61 | TEST_CASE("CoreTiming[BasicOrder]", "[core]") { |
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index dd7ce8c99..b5dc68902 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h | |||
| @@ -524,11 +524,8 @@ private: | |||
| 524 | void MarkRegionAsWritten(VAddr start, VAddr end) { | 524 | void MarkRegionAsWritten(VAddr start, VAddr end) { |
| 525 | const u64 page_end = end >> WRITE_PAGE_BIT; | 525 | const u64 page_end = end >> WRITE_PAGE_BIT; |
| 526 | for (u64 page_start = start >> WRITE_PAGE_BIT; page_start <= page_end; ++page_start) { | 526 | for (u64 page_start = start >> WRITE_PAGE_BIT; page_start <= page_end; ++page_start) { |
| 527 | auto it = written_pages.find(page_start); | 527 | if (const auto [it, inserted] = written_pages.emplace(page_start, 1); !inserted) { |
| 528 | if (it != written_pages.end()) { | 528 | ++it->second; |
| 529 | it->second = it->second + 1; | ||
| 530 | } else { | ||
| 531 | written_pages.insert_or_assign(page_start, 1); | ||
| 532 | } | 529 | } |
| 533 | } | 530 | } |
| 534 | } | 531 | } |
| @@ -539,7 +536,7 @@ private: | |||
| 539 | auto it = written_pages.find(page_start); | 536 | auto it = written_pages.find(page_start); |
| 540 | if (it != written_pages.end()) { | 537 | if (it != written_pages.end()) { |
| 541 | if (it->second > 1) { | 538 | if (it->second > 1) { |
| 542 | it->second = it->second - 1; | 539 | --it->second; |
| 543 | } else { | 540 | } else { |
| 544 | written_pages.erase(it); | 541 | written_pages.erase(it); |
| 545 | } | 542 | } |
diff --git a/src/video_core/compatible_formats.cpp b/src/video_core/compatible_formats.cpp index 6c426b035..b06c32c84 100644 --- a/src/video_core/compatible_formats.cpp +++ b/src/video_core/compatible_formats.cpp | |||
| @@ -17,101 +17,94 @@ namespace { | |||
| 17 | // https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_texture_view.txt | 17 | // https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_texture_view.txt |
| 18 | 18 | ||
| 19 | constexpr std::array VIEW_CLASS_128_BITS = { | 19 | constexpr std::array VIEW_CLASS_128_BITS = { |
| 20 | PixelFormat::RGBA32F, | 20 | PixelFormat::R32G32B32A32_FLOAT, |
| 21 | PixelFormat::RGBA32UI, | 21 | PixelFormat::R32G32B32A32_UINT, |
| 22 | PixelFormat::R32G32B32A32_SINT, | ||
| 22 | }; | 23 | }; |
| 23 | // Missing formats: | ||
| 24 | // PixelFormat::RGBA32I | ||
| 25 | 24 | ||
| 26 | constexpr std::array VIEW_CLASS_96_BITS = { | 25 | constexpr std::array VIEW_CLASS_96_BITS = { |
| 27 | PixelFormat::RGB32F, | 26 | PixelFormat::R32G32B32_FLOAT, |
| 28 | }; | 27 | }; |
| 29 | // Missing formats: | 28 | // Missing formats: |
| 30 | // PixelFormat::RGB32UI, | 29 | // PixelFormat::RGB32UI, |
| 31 | // PixelFormat::RGB32I, | 30 | // PixelFormat::RGB32I, |
| 32 | 31 | ||
| 33 | constexpr std::array VIEW_CLASS_64_BITS = { | 32 | constexpr std::array VIEW_CLASS_64_BITS = { |
| 34 | PixelFormat::RGBA16F, PixelFormat::RG32F, PixelFormat::RGBA16UI, PixelFormat::RG32UI, | 33 | PixelFormat::R32G32_FLOAT, PixelFormat::R32G32_UINT, |
| 35 | PixelFormat::RGBA16U, PixelFormat::RGBA16F, PixelFormat::RGBA16S, | 34 | PixelFormat::R32G32_SINT, PixelFormat::R16G16B16A16_FLOAT, |
| 35 | PixelFormat::R16G16B16A16_UNORM, PixelFormat::R16G16B16A16_SNORM, | ||
| 36 | PixelFormat::R16G16B16A16_UINT, PixelFormat::R16G16B16A16_SINT, | ||
| 36 | }; | 37 | }; |
| 37 | // Missing formats: | ||
| 38 | // PixelFormat::RGBA16I | ||
| 39 | // PixelFormat::RG32I | ||
| 40 | 38 | ||
| 41 | // TODO: How should we handle 48 bits? | 39 | // TODO: How should we handle 48 bits? |
| 42 | 40 | ||
| 43 | constexpr std::array VIEW_CLASS_32_BITS = { | 41 | constexpr std::array VIEW_CLASS_32_BITS = { |
| 44 | PixelFormat::RG16F, PixelFormat::R11FG11FB10F, PixelFormat::R32F, | 42 | PixelFormat::R16G16_FLOAT, PixelFormat::B10G11R11_FLOAT, PixelFormat::R32_FLOAT, |
| 45 | PixelFormat::A2B10G10R10U, PixelFormat::RG16UI, PixelFormat::R32UI, | 43 | PixelFormat::A2B10G10R10_UNORM, PixelFormat::R16G16_UINT, PixelFormat::R32_UINT, |
| 46 | PixelFormat::RG16I, PixelFormat::R32I, PixelFormat::ABGR8U, | 44 | PixelFormat::R16G16_SINT, PixelFormat::R32_SINT, PixelFormat::A8B8G8R8_UNORM, |
| 47 | PixelFormat::RG16, PixelFormat::ABGR8S, PixelFormat::RG16S, | 45 | PixelFormat::R16G16_UNORM, PixelFormat::A8B8G8R8_SNORM, PixelFormat::R16G16_SNORM, |
| 48 | PixelFormat::RGBA8_SRGB, PixelFormat::E5B9G9R9F, PixelFormat::BGRA8, | 46 | PixelFormat::A8B8G8R8_SRGB, PixelFormat::E5B9G9R9_FLOAT, PixelFormat::B8G8R8A8_UNORM, |
| 49 | PixelFormat::BGRA8_SRGB, | 47 | PixelFormat::B8G8R8A8_SRGB, PixelFormat::A8B8G8R8_UINT, PixelFormat::A8B8G8R8_SINT, |
| 48 | PixelFormat::A2B10G10R10_UINT, | ||
| 50 | }; | 49 | }; |
| 51 | // Missing formats: | ||
| 52 | // PixelFormat::RGBA8UI | ||
| 53 | // PixelFormat::RGBA8I | ||
| 54 | // PixelFormat::RGB10_A2_UI | ||
| 55 | 50 | ||
| 56 | // TODO: How should we handle 24 bits? | 51 | // TODO: How should we handle 24 bits? |
| 57 | 52 | ||
| 58 | constexpr std::array VIEW_CLASS_16_BITS = { | 53 | constexpr std::array VIEW_CLASS_16_BITS = { |
| 59 | PixelFormat::R16F, PixelFormat::RG8UI, PixelFormat::R16UI, PixelFormat::R16I, | 54 | PixelFormat::R16_FLOAT, PixelFormat::R8G8_UINT, PixelFormat::R16_UINT, |
| 60 | PixelFormat::RG8U, PixelFormat::R16U, PixelFormat::RG8S, PixelFormat::R16S, | 55 | PixelFormat::R16_SINT, PixelFormat::R8G8_UNORM, PixelFormat::R16_UNORM, |
| 56 | PixelFormat::R8G8_SNORM, PixelFormat::R16_SNORM, PixelFormat::R8G8_SINT, | ||
| 61 | }; | 57 | }; |
| 62 | // Missing formats: | ||
| 63 | // PixelFormat::RG8I | ||
| 64 | 58 | ||
| 65 | constexpr std::array VIEW_CLASS_8_BITS = { | 59 | constexpr std::array VIEW_CLASS_8_BITS = { |
| 66 | PixelFormat::R8UI, | 60 | PixelFormat::R8_UINT, |
| 67 | PixelFormat::R8U, | 61 | PixelFormat::R8_UNORM, |
| 62 | PixelFormat::R8_SINT, | ||
| 63 | PixelFormat::R8_SNORM, | ||
| 68 | }; | 64 | }; |
| 69 | // Missing formats: | ||
| 70 | // PixelFormat::R8I | ||
| 71 | // PixelFormat::R8S | ||
| 72 | 65 | ||
| 73 | constexpr std::array VIEW_CLASS_RGTC1_RED = { | 66 | constexpr std::array VIEW_CLASS_RGTC1_RED = { |
| 74 | PixelFormat::DXN1, | 67 | PixelFormat::BC4_UNORM, |
| 68 | PixelFormat::BC4_SNORM, | ||
| 75 | }; | 69 | }; |
| 76 | // Missing formats: | ||
| 77 | // COMPRESSED_SIGNED_RED_RGTC1 | ||
| 78 | 70 | ||
| 79 | constexpr std::array VIEW_CLASS_RGTC2_RG = { | 71 | constexpr std::array VIEW_CLASS_RGTC2_RG = { |
| 80 | PixelFormat::DXN2UNORM, | 72 | PixelFormat::BC5_UNORM, |
| 81 | PixelFormat::DXN2SNORM, | 73 | PixelFormat::BC5_SNORM, |
| 82 | }; | 74 | }; |
| 83 | 75 | ||
| 84 | constexpr std::array VIEW_CLASS_BPTC_UNORM = { | 76 | constexpr std::array VIEW_CLASS_BPTC_UNORM = { |
| 85 | PixelFormat::BC7U, | 77 | PixelFormat::BC7_UNORM, |
| 86 | PixelFormat::BC7U_SRGB, | 78 | PixelFormat::BC7_SRGB, |
| 87 | }; | 79 | }; |
| 88 | 80 | ||
| 89 | constexpr std::array VIEW_CLASS_BPTC_FLOAT = { | 81 | constexpr std::array VIEW_CLASS_BPTC_FLOAT = { |
| 90 | PixelFormat::BC6H_SF16, | 82 | PixelFormat::BC6H_SFLOAT, |
| 91 | PixelFormat::BC6H_UF16, | 83 | PixelFormat::BC6H_UFLOAT, |
| 92 | }; | 84 | }; |
| 93 | 85 | ||
| 94 | // Compatibility table taken from Table 4.X.1 in: | 86 | // Compatibility table taken from Table 4.X.1 in: |
| 95 | // https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_copy_image.txt | 87 | // https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_copy_image.txt |
| 96 | 88 | ||
| 97 | constexpr std::array COPY_CLASS_128_BITS = { | 89 | constexpr std::array COPY_CLASS_128_BITS = { |
| 98 | PixelFormat::RGBA32UI, PixelFormat::RGBA32F, PixelFormat::DXT23, | 90 | PixelFormat::R32G32B32A32_UINT, PixelFormat::R32G32B32A32_FLOAT, PixelFormat::R32G32B32A32_SINT, |
| 99 | PixelFormat::DXT23_SRGB, PixelFormat::DXT45, PixelFormat::DXT45_SRGB, | 91 | PixelFormat::BC2_UNORM, PixelFormat::BC2_SRGB, PixelFormat::BC3_UNORM, |
| 100 | PixelFormat::DXN2SNORM, PixelFormat::BC7U, PixelFormat::BC7U_SRGB, | 92 | PixelFormat::BC3_SRGB, PixelFormat::BC5_UNORM, PixelFormat::BC5_SNORM, |
| 101 | PixelFormat::BC6H_SF16, PixelFormat::BC6H_UF16, | 93 | PixelFormat::BC7_UNORM, PixelFormat::BC7_SRGB, PixelFormat::BC6H_SFLOAT, |
| 94 | PixelFormat::BC6H_UFLOAT, | ||
| 102 | }; | 95 | }; |
| 103 | // Missing formats: | 96 | // Missing formats: |
| 104 | // PixelFormat::RGBA32I | 97 | // PixelFormat::RGBA32I |
| 105 | // COMPRESSED_RG_RGTC2 | 98 | // COMPRESSED_RG_RGTC2 |
| 106 | 99 | ||
| 107 | constexpr std::array COPY_CLASS_64_BITS = { | 100 | constexpr std::array COPY_CLASS_64_BITS = { |
| 108 | PixelFormat::RGBA16F, PixelFormat::RG32F, PixelFormat::RGBA16UI, PixelFormat::RG32UI, | 101 | PixelFormat::R16G16B16A16_FLOAT, PixelFormat::R16G16B16A16_UINT, |
| 109 | PixelFormat::RGBA16U, PixelFormat::RGBA16S, PixelFormat::DXT1_SRGB, PixelFormat::DXT1, | 102 | PixelFormat::R16G16B16A16_UNORM, PixelFormat::R16G16B16A16_SNORM, |
| 110 | 103 | PixelFormat::R16G16B16A16_SINT, PixelFormat::R32G32_UINT, | |
| 104 | PixelFormat::R32G32_FLOAT, PixelFormat::R32G32_SINT, | ||
| 105 | PixelFormat::BC1_RGBA_UNORM, PixelFormat::BC1_RGBA_SRGB, | ||
| 111 | }; | 106 | }; |
| 112 | // Missing formats: | 107 | // Missing formats: |
| 113 | // PixelFormat::RGBA16I | ||
| 114 | // PixelFormat::RG32I, | ||
| 115 | // COMPRESSED_RGB_S3TC_DXT1_EXT | 108 | // COMPRESSED_RGB_S3TC_DXT1_EXT |
| 116 | // COMPRESSED_SRGB_S3TC_DXT1_EXT | 109 | // COMPRESSED_SRGB_S3TC_DXT1_EXT |
| 117 | // COMPRESSED_RGBA_S3TC_DXT1_EXT | 110 | // COMPRESSED_RGBA_S3TC_DXT1_EXT |
diff --git a/src/video_core/compatible_formats.h b/src/video_core/compatible_formats.h index d1082566d..51766349b 100644 --- a/src/video_core/compatible_formats.h +++ b/src/video_core/compatible_formats.h | |||
| @@ -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 | #pragma once | ||
| 6 | |||
| 5 | #include <array> | 7 | #include <array> |
| 6 | #include <bitset> | 8 | #include <bitset> |
| 7 | #include <cstddef> | 9 | #include <cstddef> |
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index 8e19c3373..512578c8b 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp | |||
| @@ -81,7 +81,7 @@ void GPU::WaitFence(u32 syncpoint_id, u32 value) { | |||
| 81 | } | 81 | } |
| 82 | MICROPROFILE_SCOPE(GPU_wait); | 82 | MICROPROFILE_SCOPE(GPU_wait); |
| 83 | std::unique_lock lock{sync_mutex}; | 83 | std::unique_lock lock{sync_mutex}; |
| 84 | sync_cv.wait(lock, [=]() { return syncpoints[syncpoint_id].load() >= value; }); | 84 | sync_cv.wait(lock, [=, this] { return syncpoints[syncpoint_id].load() >= value; }); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | void GPU::IncrementSyncPoint(const u32 syncpoint_id) { | 87 | void GPU::IncrementSyncPoint(const u32 syncpoint_id) { |
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h index 8d04d9fd9..ebfc7b0c7 100644 --- a/src/video_core/gpu.h +++ b/src/video_core/gpu.h | |||
| @@ -40,53 +40,61 @@ namespace Tegra { | |||
| 40 | 40 | ||
| 41 | enum class RenderTargetFormat : u32 { | 41 | enum class RenderTargetFormat : u32 { |
| 42 | NONE = 0x0, | 42 | NONE = 0x0, |
| 43 | RGBA32_FLOAT = 0xC0, | 43 | R32B32G32A32_FLOAT = 0xC0, |
| 44 | RGBA32_UINT = 0xC2, | 44 | R32G32B32A32_SINT = 0xC1, |
| 45 | RGBA16_UNORM = 0xC6, | 45 | R32G32B32A32_UINT = 0xC2, |
| 46 | RGBA16_SNORM = 0xC7, | 46 | R16G16B16A16_UNORM = 0xC6, |
| 47 | RGBA16_UINT = 0xC9, | 47 | R16G16B16A16_SNORM = 0xC7, |
| 48 | RGBA16_FLOAT = 0xCA, | 48 | R16G16B16A16_SINT = 0xC8, |
| 49 | RG32_FLOAT = 0xCB, | 49 | R16G16B16A16_UINT = 0xC9, |
| 50 | RG32_UINT = 0xCD, | 50 | R16G16B16A16_FLOAT = 0xCA, |
| 51 | RGBX16_FLOAT = 0xCE, | 51 | R32G32_FLOAT = 0xCB, |
| 52 | BGRA8_UNORM = 0xCF, | 52 | R32G32_SINT = 0xCC, |
| 53 | BGRA8_SRGB = 0xD0, | 53 | R32G32_UINT = 0xCD, |
| 54 | RGB10_A2_UNORM = 0xD1, | 54 | R16G16B16X16_FLOAT = 0xCE, |
| 55 | RGBA8_UNORM = 0xD5, | 55 | B8G8R8A8_UNORM = 0xCF, |
| 56 | RGBA8_SRGB = 0xD6, | 56 | B8G8R8A8_SRGB = 0xD0, |
| 57 | RGBA8_SNORM = 0xD7, | 57 | A2B10G10R10_UNORM = 0xD1, |
| 58 | RGBA8_UINT = 0xD9, | 58 | A2B10G10R10_UINT = 0xD2, |
| 59 | RG16_UNORM = 0xDA, | 59 | A8B8G8R8_UNORM = 0xD5, |
| 60 | RG16_SNORM = 0xDB, | 60 | A8B8G8R8_SRGB = 0xD6, |
| 61 | RG16_SINT = 0xDC, | 61 | A8B8G8R8_SNORM = 0xD7, |
| 62 | RG16_UINT = 0xDD, | 62 | A8B8G8R8_SINT = 0xD8, |
| 63 | RG16_FLOAT = 0xDE, | 63 | A8B8G8R8_UINT = 0xD9, |
| 64 | R11G11B10_FLOAT = 0xE0, | 64 | R16G16_UNORM = 0xDA, |
| 65 | R16G16_SNORM = 0xDB, | ||
| 66 | R16G16_SINT = 0xDC, | ||
| 67 | R16G16_UINT = 0xDD, | ||
| 68 | R16G16_FLOAT = 0xDE, | ||
| 69 | B10G11R11_FLOAT = 0xE0, | ||
| 65 | R32_SINT = 0xE3, | 70 | R32_SINT = 0xE3, |
| 66 | R32_UINT = 0xE4, | 71 | R32_UINT = 0xE4, |
| 67 | R32_FLOAT = 0xE5, | 72 | R32_FLOAT = 0xE5, |
| 68 | B5G6R5_UNORM = 0xE8, | 73 | R5G6B5_UNORM = 0xE8, |
| 69 | BGR5A1_UNORM = 0xE9, | 74 | A1R5G5B5_UNORM = 0xE9, |
| 70 | RG8_UNORM = 0xEA, | 75 | R8G8_UNORM = 0xEA, |
| 71 | RG8_SNORM = 0xEB, | 76 | R8G8_SNORM = 0xEB, |
| 72 | RG8_UINT = 0xED, | 77 | R8G8_SINT = 0xEC, |
| 78 | R8G8_UINT = 0xED, | ||
| 73 | R16_UNORM = 0xEE, | 79 | R16_UNORM = 0xEE, |
| 74 | R16_SNORM = 0xEF, | 80 | R16_SNORM = 0xEF, |
| 75 | R16_SINT = 0xF0, | 81 | R16_SINT = 0xF0, |
| 76 | R16_UINT = 0xF1, | 82 | R16_UINT = 0xF1, |
| 77 | R16_FLOAT = 0xF2, | 83 | R16_FLOAT = 0xF2, |
| 78 | R8_UNORM = 0xF3, | 84 | R8_UNORM = 0xF3, |
| 85 | R8_SNORM = 0xF4, | ||
| 86 | R8_SINT = 0xF5, | ||
| 79 | R8_UINT = 0xF6, | 87 | R8_UINT = 0xF6, |
| 80 | }; | 88 | }; |
| 81 | 89 | ||
| 82 | enum class DepthFormat : u32 { | 90 | enum class DepthFormat : u32 { |
| 83 | Z32_FLOAT = 0xA, | 91 | D32_FLOAT = 0xA, |
| 84 | Z16_UNORM = 0x13, | 92 | D16_UNORM = 0x13, |
| 85 | S8_Z24_UNORM = 0x14, | 93 | S8_UINT_Z24_UNORM = 0x14, |
| 86 | Z24_X8_UNORM = 0x15, | 94 | D24X8_UNORM = 0x15, |
| 87 | Z24_S8_UNORM = 0x16, | 95 | D24S8_UNORM = 0x16, |
| 88 | Z24_C8_UNORM = 0x18, | 96 | D24C8_UNORM = 0x18, |
| 89 | Z32_S8_X24_FLOAT = 0x19, | 97 | D32_FLOAT_S8X24_UINT = 0x19, |
| 90 | }; | 98 | }; |
| 91 | 99 | ||
| 92 | struct CommandListHeader; | 100 | struct CommandListHeader; |
| @@ -97,9 +105,9 @@ class DebugContext; | |||
| 97 | */ | 105 | */ |
| 98 | struct FramebufferConfig { | 106 | struct FramebufferConfig { |
| 99 | enum class PixelFormat : u32 { | 107 | enum class PixelFormat : u32 { |
| 100 | ABGR8 = 1, | 108 | A8B8G8R8_UNORM = 1, |
| 101 | RGB565 = 4, | 109 | RGB565_UNORM = 4, |
| 102 | BGRA8 = 5, | 110 | B8G8R8A8_UNORM = 5, |
| 103 | }; | 111 | }; |
| 104 | 112 | ||
| 105 | VAddr address; | 113 | VAddr address; |
| @@ -244,7 +252,7 @@ public: | |||
| 244 | const Tegra::DmaPusher& DmaPusher() const; | 252 | const Tegra::DmaPusher& DmaPusher() const; |
| 245 | 253 | ||
| 246 | struct Regs { | 254 | struct Regs { |
| 247 | static constexpr size_t NUM_REGS = 0x100; | 255 | static constexpr size_t NUM_REGS = 0x40; |
| 248 | 256 | ||
| 249 | union { | 257 | union { |
| 250 | struct { | 258 | struct { |
| @@ -263,7 +271,7 @@ public: | |||
| 263 | u32 semaphore_trigger; | 271 | u32 semaphore_trigger; |
| 264 | INSERT_UNION_PADDING_WORDS(0xC); | 272 | INSERT_UNION_PADDING_WORDS(0xC); |
| 265 | 273 | ||
| 266 | // The puser and the puller share the reference counter, the pusher only has read | 274 | // The pusher and the puller share the reference counter, the pusher only has read |
| 267 | // access | 275 | // access |
| 268 | u32 reference_count; | 276 | u32 reference_count; |
| 269 | INSERT_UNION_PADDING_WORDS(0x5); | 277 | INSERT_UNION_PADDING_WORDS(0x5); |
diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp index 738c6f0c1..bf761abf2 100644 --- a/src/video_core/gpu_thread.cpp +++ b/src/video_core/gpu_thread.cpp | |||
| @@ -44,9 +44,9 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, | |||
| 44 | dma_pusher.DispatchCalls(); | 44 | dma_pusher.DispatchCalls(); |
| 45 | } else if (const auto data = std::get_if<SwapBuffersCommand>(&next.data)) { | 45 | } else if (const auto data = std::get_if<SwapBuffersCommand>(&next.data)) { |
| 46 | renderer.SwapBuffers(data->framebuffer ? &*data->framebuffer : nullptr); | 46 | renderer.SwapBuffers(data->framebuffer ? &*data->framebuffer : nullptr); |
| 47 | } else if (const auto data = std::get_if<OnCommandListEndCommand>(&next.data)) { | 47 | } else if (std::holds_alternative<OnCommandListEndCommand>(next.data)) { |
| 48 | renderer.Rasterizer().ReleaseFences(); | 48 | renderer.Rasterizer().ReleaseFences(); |
| 49 | } else if (const auto data = std::get_if<GPUTickCommand>(&next.data)) { | 49 | } else if (std::holds_alternative<GPUTickCommand>(next.data)) { |
| 50 | system.GPU().TickWork(); | 50 | system.GPU().TickWork(); |
| 51 | } else if (const auto data = std::get_if<FlushRegionCommand>(&next.data)) { | 51 | } else if (const auto data = std::get_if<FlushRegionCommand>(&next.data)) { |
| 52 | renderer.Rasterizer().FlushRegion(data->addr, data->size); | 52 | renderer.Rasterizer().FlushRegion(data->addr, data->size); |
diff --git a/src/video_core/macro/macro_jit_x64.cpp b/src/video_core/macro/macro_jit_x64.cpp index 07292702f..c1b9e4ad9 100644 --- a/src/video_core/macro/macro_jit_x64.cpp +++ b/src/video_core/macro/macro_jit_x64.cpp | |||
| @@ -419,7 +419,6 @@ void Tegra::MacroJITx64Impl::Optimizer_ScanFlags() { | |||
| 419 | 419 | ||
| 420 | void MacroJITx64Impl::Compile() { | 420 | void MacroJITx64Impl::Compile() { |
| 421 | MICROPROFILE_SCOPE(MacroJitCompile); | 421 | MICROPROFILE_SCOPE(MacroJitCompile); |
| 422 | bool keep_executing = true; | ||
| 423 | labels.fill(Xbyak::Label()); | 422 | labels.fill(Xbyak::Label()); |
| 424 | 423 | ||
| 425 | Common::X64::ABI_PushRegistersAndAdjustStack(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8); | 424 | Common::X64::ABI_PushRegistersAndAdjustStack(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8); |
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index ff5505d12..844164645 100644 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #include "common/alignment.h" | 5 | #include "common/alignment.h" |
| 6 | #include "common/assert.h" | 6 | #include "common/assert.h" |
| 7 | #include "common/logging/log.h" | ||
| 8 | #include "core/core.h" | 7 | #include "core/core.h" |
| 9 | #include "core/hle/kernel/memory/page_table.h" | 8 | #include "core/hle/kernel/memory/page_table.h" |
| 10 | #include "core/hle/kernel/process.h" | 9 | #include "core/hle/kernel/process.h" |
| @@ -16,121 +15,137 @@ | |||
| 16 | namespace Tegra { | 15 | namespace Tegra { |
| 17 | 16 | ||
| 18 | MemoryManager::MemoryManager(Core::System& system, VideoCore::RasterizerInterface& rasterizer) | 17 | MemoryManager::MemoryManager(Core::System& system, VideoCore::RasterizerInterface& rasterizer) |
| 19 | : rasterizer{rasterizer}, system{system} { | 18 | : system{system}, rasterizer{rasterizer}, page_table(page_table_size) {} |
| 20 | page_table.Resize(address_space_width, page_bits, false); | ||
| 21 | |||
| 22 | // Initialize the map with a single free region covering the entire managed space. | ||
| 23 | VirtualMemoryArea initial_vma; | ||
| 24 | initial_vma.size = address_space_end; | ||
| 25 | vma_map.emplace(initial_vma.base, initial_vma); | ||
| 26 | |||
| 27 | UpdatePageTableForVMA(initial_vma); | ||
| 28 | } | ||
| 29 | 19 | ||
| 30 | MemoryManager::~MemoryManager() = default; | 20 | MemoryManager::~MemoryManager() = default; |
| 31 | 21 | ||
| 32 | GPUVAddr MemoryManager::AllocateSpace(u64 size, u64 align) { | 22 | GPUVAddr MemoryManager::UpdateRange(GPUVAddr gpu_addr, PageEntry page_entry, std::size_t size) { |
| 33 | const u64 aligned_size{Common::AlignUp(size, page_size)}; | 23 | u64 remaining_size{size}; |
| 34 | const GPUVAddr gpu_addr{FindFreeRegion(address_space_base, aligned_size)}; | 24 | for (u64 offset{}; offset < size; offset += page_size) { |
| 35 | 25 | if (remaining_size < page_size) { | |
| 36 | AllocateMemory(gpu_addr, 0, aligned_size); | 26 | SetPageEntry(gpu_addr + offset, page_entry + offset, remaining_size); |
| 37 | 27 | } else { | |
| 28 | SetPageEntry(gpu_addr + offset, page_entry + offset); | ||
| 29 | } | ||
| 30 | remaining_size -= page_size; | ||
| 31 | } | ||
| 38 | return gpu_addr; | 32 | return gpu_addr; |
| 39 | } | 33 | } |
| 40 | 34 | ||
| 41 | GPUVAddr MemoryManager::AllocateSpace(GPUVAddr gpu_addr, u64 size, u64 align) { | 35 | GPUVAddr MemoryManager::Map(VAddr cpu_addr, GPUVAddr gpu_addr, std::size_t size) { |
| 42 | const u64 aligned_size{Common::AlignUp(size, page_size)}; | 36 | return UpdateRange(gpu_addr, cpu_addr, size); |
| 43 | 37 | } | |
| 44 | AllocateMemory(gpu_addr, 0, aligned_size); | ||
| 45 | 38 | ||
| 46 | return gpu_addr; | 39 | GPUVAddr MemoryManager::MapAllocate(VAddr cpu_addr, std::size_t size, std::size_t align) { |
| 40 | return Map(cpu_addr, *FindFreeRange(size, align), size); | ||
| 47 | } | 41 | } |
| 48 | 42 | ||
| 49 | GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) { | 43 | void MemoryManager::Unmap(GPUVAddr gpu_addr, std::size_t size) { |
| 50 | const u64 aligned_size{Common::AlignUp(size, page_size)}; | 44 | if (!size) { |
| 51 | const GPUVAddr gpu_addr{FindFreeRegion(address_space_base, aligned_size)}; | 45 | return; |
| 46 | } | ||
| 52 | 47 | ||
| 53 | MapBackingMemory(gpu_addr, system.Memory().GetPointer(cpu_addr), aligned_size, cpu_addr); | 48 | // Flush and invalidate through the GPU interface, to be asynchronous if possible. |
| 54 | ASSERT( | 49 | system.GPU().FlushAndInvalidateRegion(*GpuToCpuAddress(gpu_addr), size); |
| 55 | system.CurrentProcess()->PageTable().LockForDeviceAddressSpace(cpu_addr, size).IsSuccess()); | ||
| 56 | 50 | ||
| 57 | return gpu_addr; | 51 | UpdateRange(gpu_addr, PageEntry::State::Unmapped, size); |
| 58 | } | 52 | } |
| 59 | 53 | ||
| 60 | GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size) { | 54 | std::optional<GPUVAddr> MemoryManager::AllocateFixed(GPUVAddr gpu_addr, std::size_t size) { |
| 61 | ASSERT((gpu_addr & page_mask) == 0); | 55 | for (u64 offset{}; offset < size; offset += page_size) { |
| 56 | if (!GetPageEntry(gpu_addr + offset).IsUnmapped()) { | ||
| 57 | return {}; | ||
| 58 | } | ||
| 59 | } | ||
| 62 | 60 | ||
| 63 | const u64 aligned_size{Common::AlignUp(size, page_size)}; | 61 | return UpdateRange(gpu_addr, PageEntry::State::Allocated, size); |
| 62 | } | ||
| 64 | 63 | ||
| 65 | MapBackingMemory(gpu_addr, system.Memory().GetPointer(cpu_addr), aligned_size, cpu_addr); | 64 | GPUVAddr MemoryManager::Allocate(std::size_t size, std::size_t align) { |
| 66 | ASSERT( | 65 | return *AllocateFixed(*FindFreeRange(size, align), size); |
| 67 | system.CurrentProcess()->PageTable().LockForDeviceAddressSpace(cpu_addr, size).IsSuccess()); | ||
| 68 | return gpu_addr; | ||
| 69 | } | 66 | } |
| 70 | 67 | ||
| 71 | GPUVAddr MemoryManager::UnmapBuffer(GPUVAddr gpu_addr, u64 size) { | 68 | void MemoryManager::TryLockPage(PageEntry page_entry, std::size_t size) { |
| 72 | ASSERT((gpu_addr & page_mask) == 0); | 69 | if (!page_entry.IsValid()) { |
| 70 | return; | ||
| 71 | } | ||
| 73 | 72 | ||
| 74 | const u64 aligned_size{Common::AlignUp(size, page_size)}; | 73 | ASSERT(system.CurrentProcess() |
| 75 | const auto cpu_addr = GpuToCpuAddress(gpu_addr); | 74 | ->PageTable() |
| 76 | ASSERT(cpu_addr); | 75 | .LockForDeviceAddressSpace(page_entry.ToAddress(), size) |
| 76 | .IsSuccess()); | ||
| 77 | } | ||
| 77 | 78 | ||
| 78 | // Flush and invalidate through the GPU interface, to be asynchronous if possible. | 79 | void MemoryManager::TryUnlockPage(PageEntry page_entry, std::size_t size) { |
| 79 | system.GPU().FlushAndInvalidateRegion(*cpu_addr, aligned_size); | 80 | if (!page_entry.IsValid()) { |
| 81 | return; | ||
| 82 | } | ||
| 80 | 83 | ||
| 81 | UnmapRange(gpu_addr, aligned_size); | ||
| 82 | ASSERT(system.CurrentProcess() | 84 | ASSERT(system.CurrentProcess() |
| 83 | ->PageTable() | 85 | ->PageTable() |
| 84 | .UnlockForDeviceAddressSpace(cpu_addr.value(), size) | 86 | .UnlockForDeviceAddressSpace(page_entry.ToAddress(), size) |
| 85 | .IsSuccess()); | 87 | .IsSuccess()); |
| 86 | |||
| 87 | return gpu_addr; | ||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | GPUVAddr MemoryManager::FindFreeRegion(GPUVAddr region_start, u64 size) const { | 90 | PageEntry MemoryManager::GetPageEntry(GPUVAddr gpu_addr) const { |
| 91 | // Find the first Free VMA. | 91 | return page_table[PageEntryIndex(gpu_addr)]; |
| 92 | const VMAHandle vma_handle{ | 92 | } |
| 93 | std::find_if(vma_map.begin(), vma_map.end(), [region_start, size](const auto& vma) { | ||
| 94 | if (vma.second.type != VirtualMemoryArea::Type::Unmapped) { | ||
| 95 | return false; | ||
| 96 | } | ||
| 97 | 93 | ||
| 98 | const VAddr vma_end{vma.second.base + vma.second.size}; | 94 | void MemoryManager::SetPageEntry(GPUVAddr gpu_addr, PageEntry page_entry, std::size_t size) { |
| 99 | return vma_end > region_start && vma_end >= region_start + size; | 95 | // TODO(bunnei): We should lock/unlock device regions. This currently causes issues due to |
| 100 | })}; | 96 | // improper tracking, but should be fixed in the future. |
| 101 | 97 | ||
| 102 | if (vma_handle == vma_map.end()) { | 98 | //// Unlock the old page |
| 103 | return {}; | 99 | // TryUnlockPage(page_table[PageEntryIndex(gpu_addr)], size); |
| 104 | } | ||
| 105 | 100 | ||
| 106 | return std::max(region_start, vma_handle->second.base); | 101 | //// Lock the new page |
| 107 | } | 102 | // TryLockPage(page_entry, size); |
| 108 | 103 | ||
| 109 | bool MemoryManager::IsAddressValid(GPUVAddr addr) const { | 104 | page_table[PageEntryIndex(gpu_addr)] = page_entry; |
| 110 | return (addr >> page_bits) < page_table.pointers.size(); | ||
| 111 | } | 105 | } |
| 112 | 106 | ||
| 113 | std::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr addr) const { | 107 | std::optional<GPUVAddr> MemoryManager::FindFreeRange(std::size_t size, std::size_t align) const { |
| 114 | if (!IsAddressValid(addr)) { | 108 | if (!align) { |
| 115 | return {}; | 109 | align = page_size; |
| 110 | } else { | ||
| 111 | align = Common::AlignUp(align, page_size); | ||
| 116 | } | 112 | } |
| 117 | 113 | ||
| 118 | const VAddr cpu_addr{page_table.backing_addr[addr >> page_bits]}; | 114 | u64 available_size{}; |
| 119 | if (cpu_addr) { | 115 | GPUVAddr gpu_addr{address_space_start}; |
| 120 | return cpu_addr + (addr & page_mask); | 116 | while (gpu_addr + available_size < address_space_size) { |
| 117 | if (GetPageEntry(gpu_addr + available_size).IsUnmapped()) { | ||
| 118 | available_size += page_size; | ||
| 119 | |||
| 120 | if (available_size >= size) { | ||
| 121 | return gpu_addr; | ||
| 122 | } | ||
| 123 | } else { | ||
| 124 | gpu_addr += available_size + page_size; | ||
| 125 | available_size = 0; | ||
| 126 | |||
| 127 | const auto remainder{gpu_addr % align}; | ||
| 128 | if (remainder) { | ||
| 129 | gpu_addr = (gpu_addr - remainder) + align; | ||
| 130 | } | ||
| 131 | } | ||
| 121 | } | 132 | } |
| 122 | 133 | ||
| 123 | return {}; | 134 | return {}; |
| 124 | } | 135 | } |
| 125 | 136 | ||
| 126 | template <typename T> | 137 | std::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr gpu_addr) const { |
| 127 | T MemoryManager::Read(GPUVAddr addr) const { | 138 | const auto page_entry{GetPageEntry(gpu_addr)}; |
| 128 | if (!IsAddressValid(addr)) { | 139 | if (!page_entry.IsValid()) { |
| 129 | return {}; | 140 | return {}; |
| 130 | } | 141 | } |
| 131 | 142 | ||
| 132 | const u8* page_pointer{GetPointer(addr)}; | 143 | return page_entry.ToAddress() + (gpu_addr & page_mask); |
| 133 | if (page_pointer) { | 144 | } |
| 145 | |||
| 146 | template <typename T> | ||
| 147 | T MemoryManager::Read(GPUVAddr addr) const { | ||
| 148 | if (auto page_pointer{GetPointer(addr)}; page_pointer) { | ||
| 134 | // NOTE: Avoid adding any extra logic to this fast-path block | 149 | // NOTE: Avoid adding any extra logic to this fast-path block |
| 135 | T value; | 150 | T value; |
| 136 | std::memcpy(&value, page_pointer, sizeof(T)); | 151 | std::memcpy(&value, page_pointer, sizeof(T)); |
| @@ -144,12 +159,7 @@ T MemoryManager::Read(GPUVAddr addr) const { | |||
| 144 | 159 | ||
| 145 | template <typename T> | 160 | template <typename T> |
| 146 | void MemoryManager::Write(GPUVAddr addr, T data) { | 161 | void MemoryManager::Write(GPUVAddr addr, T data) { |
| 147 | if (!IsAddressValid(addr)) { | 162 | if (auto page_pointer{GetPointer(addr)}; page_pointer) { |
| 148 | return; | ||
| 149 | } | ||
| 150 | |||
| 151 | u8* page_pointer{GetPointer(addr)}; | ||
| 152 | if (page_pointer) { | ||
| 153 | // NOTE: Avoid adding any extra logic to this fast-path block | 163 | // NOTE: Avoid adding any extra logic to this fast-path block |
| 154 | std::memcpy(page_pointer, &data, sizeof(T)); | 164 | std::memcpy(page_pointer, &data, sizeof(T)); |
| 155 | return; | 165 | return; |
| @@ -167,66 +177,49 @@ template void MemoryManager::Write<u16>(GPUVAddr addr, u16 data); | |||
| 167 | template void MemoryManager::Write<u32>(GPUVAddr addr, u32 data); | 177 | template void MemoryManager::Write<u32>(GPUVAddr addr, u32 data); |
| 168 | template void MemoryManager::Write<u64>(GPUVAddr addr, u64 data); | 178 | template void MemoryManager::Write<u64>(GPUVAddr addr, u64 data); |
| 169 | 179 | ||
| 170 | u8* MemoryManager::GetPointer(GPUVAddr addr) { | 180 | u8* MemoryManager::GetPointer(GPUVAddr gpu_addr) { |
| 171 | if (!IsAddressValid(addr)) { | 181 | if (!GetPageEntry(gpu_addr).IsValid()) { |
| 172 | return {}; | 182 | return {}; |
| 173 | } | 183 | } |
| 174 | 184 | ||
| 175 | auto& memory = system.Memory(); | 185 | const auto address{GpuToCpuAddress(gpu_addr)}; |
| 176 | 186 | if (!address) { | |
| 177 | const VAddr page_addr{page_table.backing_addr[addr >> page_bits]}; | 187 | return {}; |
| 178 | |||
| 179 | if (page_addr != 0) { | ||
| 180 | return memory.GetPointer(page_addr + (addr & page_mask)); | ||
| 181 | } | 188 | } |
| 182 | 189 | ||
| 183 | LOG_ERROR(HW_GPU, "Unknown GetPointer @ 0x{:016X}", addr); | 190 | return system.Memory().GetPointer(*address); |
| 184 | return {}; | ||
| 185 | } | 191 | } |
| 186 | 192 | ||
| 187 | const u8* MemoryManager::GetPointer(GPUVAddr addr) const { | 193 | const u8* MemoryManager::GetPointer(GPUVAddr gpu_addr) const { |
| 188 | if (!IsAddressValid(addr)) { | 194 | if (!GetPageEntry(gpu_addr).IsValid()) { |
| 189 | return {}; | 195 | return {}; |
| 190 | } | 196 | } |
| 191 | 197 | ||
| 192 | const auto& memory = system.Memory(); | 198 | const auto address{GpuToCpuAddress(gpu_addr)}; |
| 193 | 199 | if (!address) { | |
| 194 | const VAddr page_addr{page_table.backing_addr[addr >> page_bits]}; | 200 | return {}; |
| 195 | |||
| 196 | if (page_addr != 0) { | ||
| 197 | return memory.GetPointer(page_addr + (addr & page_mask)); | ||
| 198 | } | 201 | } |
| 199 | 202 | ||
| 200 | LOG_ERROR(HW_GPU, "Unknown GetPointer @ 0x{:016X}", addr); | 203 | return system.Memory().GetPointer(*address); |
| 201 | return {}; | ||
| 202 | } | ||
| 203 | |||
| 204 | bool MemoryManager::IsBlockContinuous(const GPUVAddr start, const std::size_t size) const { | ||
| 205 | const std::size_t inner_size = size - 1; | ||
| 206 | const GPUVAddr end = start + inner_size; | ||
| 207 | const auto host_ptr_start = reinterpret_cast<std::uintptr_t>(GetPointer(start)); | ||
| 208 | const auto host_ptr_end = reinterpret_cast<std::uintptr_t>(GetPointer(end)); | ||
| 209 | const auto range = static_cast<std::size_t>(host_ptr_end - host_ptr_start); | ||
| 210 | return range == inner_size; | ||
| 211 | } | 204 | } |
| 212 | 205 | ||
| 213 | void MemoryManager::ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, | 206 | void MemoryManager::ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size) const { |
| 214 | const std::size_t size) const { | ||
| 215 | std::size_t remaining_size{size}; | 207 | std::size_t remaining_size{size}; |
| 216 | std::size_t page_index{gpu_src_addr >> page_bits}; | 208 | std::size_t page_index{gpu_src_addr >> page_bits}; |
| 217 | std::size_t page_offset{gpu_src_addr & page_mask}; | 209 | std::size_t page_offset{gpu_src_addr & page_mask}; |
| 218 | 210 | ||
| 219 | auto& memory = system.Memory(); | ||
| 220 | |||
| 221 | while (remaining_size > 0) { | 211 | while (remaining_size > 0) { |
| 222 | const std::size_t copy_amount{ | 212 | const std::size_t copy_amount{ |
| 223 | std::min(static_cast<std::size_t>(page_size) - page_offset, remaining_size)}; | 213 | std::min(static_cast<std::size_t>(page_size) - page_offset, remaining_size)}; |
| 224 | 214 | ||
| 225 | const VAddr src_addr{page_table.backing_addr[page_index] + page_offset}; | 215 | if (const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; page_addr) { |
| 226 | // Flush must happen on the rasterizer interface, such that memory is always synchronous | 216 | const auto src_addr{*page_addr + page_offset}; |
| 227 | // when it is read (even when in asynchronous GPU mode). Fixes Dead Cells title menu. | 217 | |
| 228 | rasterizer.FlushRegion(src_addr, copy_amount); | 218 | // Flush must happen on the rasterizer interface, such that memory is always synchronous |
| 229 | memory.ReadBlockUnsafe(src_addr, dest_buffer, copy_amount); | 219 | // when it is read (even when in asynchronous GPU mode). Fixes Dead Cells title menu. |
| 220 | rasterizer.FlushRegion(src_addr, copy_amount); | ||
| 221 | system.Memory().ReadBlockUnsafe(src_addr, dest_buffer, copy_amount); | ||
| 222 | } | ||
| 230 | 223 | ||
| 231 | page_index++; | 224 | page_index++; |
| 232 | page_offset = 0; | 225 | page_offset = 0; |
| @@ -241,18 +234,17 @@ void MemoryManager::ReadBlockUnsafe(GPUVAddr gpu_src_addr, void* dest_buffer, | |||
| 241 | std::size_t page_index{gpu_src_addr >> page_bits}; | 234 | std::size_t page_index{gpu_src_addr >> page_bits}; |
| 242 | std::size_t page_offset{gpu_src_addr & page_mask}; | 235 | std::size_t page_offset{gpu_src_addr & page_mask}; |
| 243 | 236 | ||
| 244 | auto& memory = system.Memory(); | ||
| 245 | |||
| 246 | while (remaining_size > 0) { | 237 | while (remaining_size > 0) { |
| 247 | const std::size_t copy_amount{ | 238 | const std::size_t copy_amount{ |
| 248 | std::min(static_cast<std::size_t>(page_size) - page_offset, remaining_size)}; | 239 | std::min(static_cast<std::size_t>(page_size) - page_offset, remaining_size)}; |
| 249 | const u8* page_pointer = page_table.pointers[page_index]; | 240 | |
| 250 | if (page_pointer) { | 241 | if (const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; page_addr) { |
| 251 | const VAddr src_addr{page_table.backing_addr[page_index] + page_offset}; | 242 | const auto src_addr{*page_addr + page_offset}; |
| 252 | memory.ReadBlockUnsafe(src_addr, dest_buffer, copy_amount); | 243 | system.Memory().ReadBlockUnsafe(src_addr, dest_buffer, copy_amount); |
| 253 | } else { | 244 | } else { |
| 254 | std::memset(dest_buffer, 0, copy_amount); | 245 | std::memset(dest_buffer, 0, copy_amount); |
| 255 | } | 246 | } |
| 247 | |||
| 256 | page_index++; | 248 | page_index++; |
| 257 | page_offset = 0; | 249 | page_offset = 0; |
| 258 | dest_buffer = static_cast<u8*>(dest_buffer) + copy_amount; | 250 | dest_buffer = static_cast<u8*>(dest_buffer) + copy_amount; |
| @@ -260,23 +252,23 @@ void MemoryManager::ReadBlockUnsafe(GPUVAddr gpu_src_addr, void* dest_buffer, | |||
| 260 | } | 252 | } |
| 261 | } | 253 | } |
| 262 | 254 | ||
| 263 | void MemoryManager::WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, | 255 | void MemoryManager::WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size) { |
| 264 | const std::size_t size) { | ||
| 265 | std::size_t remaining_size{size}; | 256 | std::size_t remaining_size{size}; |
| 266 | std::size_t page_index{gpu_dest_addr >> page_bits}; | 257 | std::size_t page_index{gpu_dest_addr >> page_bits}; |
| 267 | std::size_t page_offset{gpu_dest_addr & page_mask}; | 258 | std::size_t page_offset{gpu_dest_addr & page_mask}; |
| 268 | 259 | ||
| 269 | auto& memory = system.Memory(); | ||
| 270 | |||
| 271 | while (remaining_size > 0) { | 260 | while (remaining_size > 0) { |
| 272 | const std::size_t copy_amount{ | 261 | const std::size_t copy_amount{ |
| 273 | std::min(static_cast<std::size_t>(page_size) - page_offset, remaining_size)}; | 262 | std::min(static_cast<std::size_t>(page_size) - page_offset, remaining_size)}; |
| 274 | 263 | ||
| 275 | const VAddr dest_addr{page_table.backing_addr[page_index] + page_offset}; | 264 | if (const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; page_addr) { |
| 276 | // Invalidate must happen on the rasterizer interface, such that memory is always | 265 | const auto dest_addr{*page_addr + page_offset}; |
| 277 | // synchronous when it is written (even when in asynchronous GPU mode). | 266 | |
| 278 | rasterizer.InvalidateRegion(dest_addr, copy_amount); | 267 | // Invalidate must happen on the rasterizer interface, such that memory is always |
| 279 | memory.WriteBlockUnsafe(dest_addr, src_buffer, copy_amount); | 268 | // synchronous when it is written (even when in asynchronous GPU mode). |
| 269 | rasterizer.InvalidateRegion(dest_addr, copy_amount); | ||
| 270 | system.Memory().WriteBlockUnsafe(dest_addr, src_buffer, copy_amount); | ||
| 271 | } | ||
| 280 | 272 | ||
| 281 | page_index++; | 273 | page_index++; |
| 282 | page_offset = 0; | 274 | page_offset = 0; |
| @@ -286,21 +278,20 @@ void MemoryManager::WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, | |||
| 286 | } | 278 | } |
| 287 | 279 | ||
| 288 | void MemoryManager::WriteBlockUnsafe(GPUVAddr gpu_dest_addr, const void* src_buffer, | 280 | void MemoryManager::WriteBlockUnsafe(GPUVAddr gpu_dest_addr, const void* src_buffer, |
| 289 | const std::size_t size) { | 281 | std::size_t size) { |
| 290 | std::size_t remaining_size{size}; | 282 | std::size_t remaining_size{size}; |
| 291 | std::size_t page_index{gpu_dest_addr >> page_bits}; | 283 | std::size_t page_index{gpu_dest_addr >> page_bits}; |
| 292 | std::size_t page_offset{gpu_dest_addr & page_mask}; | 284 | std::size_t page_offset{gpu_dest_addr & page_mask}; |
| 293 | 285 | ||
| 294 | auto& memory = system.Memory(); | ||
| 295 | |||
| 296 | while (remaining_size > 0) { | 286 | while (remaining_size > 0) { |
| 297 | const std::size_t copy_amount{ | 287 | const std::size_t copy_amount{ |
| 298 | std::min(static_cast<std::size_t>(page_size) - page_offset, remaining_size)}; | 288 | std::min(static_cast<std::size_t>(page_size) - page_offset, remaining_size)}; |
| 299 | u8* page_pointer = page_table.pointers[page_index]; | 289 | |
| 300 | if (page_pointer) { | 290 | if (const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; page_addr) { |
| 301 | const VAddr dest_addr{page_table.backing_addr[page_index] + page_offset}; | 291 | const auto dest_addr{*page_addr + page_offset}; |
| 302 | memory.WriteBlockUnsafe(dest_addr, src_buffer, copy_amount); | 292 | system.Memory().WriteBlockUnsafe(dest_addr, src_buffer, copy_amount); |
| 303 | } | 293 | } |
| 294 | |||
| 304 | page_index++; | 295 | page_index++; |
| 305 | page_offset = 0; | 296 | page_offset = 0; |
| 306 | src_buffer = static_cast<const u8*>(src_buffer) + copy_amount; | 297 | src_buffer = static_cast<const u8*>(src_buffer) + copy_amount; |
| @@ -308,273 +299,26 @@ void MemoryManager::WriteBlockUnsafe(GPUVAddr gpu_dest_addr, const void* src_buf | |||
| 308 | } | 299 | } |
| 309 | } | 300 | } |
| 310 | 301 | ||
| 311 | void MemoryManager::CopyBlock(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, | 302 | void MemoryManager::CopyBlock(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, std::size_t size) { |
| 312 | const std::size_t size) { | ||
| 313 | std::vector<u8> tmp_buffer(size); | 303 | std::vector<u8> tmp_buffer(size); |
| 314 | ReadBlock(gpu_src_addr, tmp_buffer.data(), size); | 304 | ReadBlock(gpu_src_addr, tmp_buffer.data(), size); |
| 315 | WriteBlock(gpu_dest_addr, tmp_buffer.data(), size); | 305 | WriteBlock(gpu_dest_addr, tmp_buffer.data(), size); |
| 316 | } | 306 | } |
| 317 | 307 | ||
| 318 | void MemoryManager::CopyBlockUnsafe(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, | 308 | void MemoryManager::CopyBlockUnsafe(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, |
| 319 | const std::size_t size) { | 309 | std::size_t size) { |
| 320 | std::vector<u8> tmp_buffer(size); | 310 | std::vector<u8> tmp_buffer(size); |
| 321 | ReadBlockUnsafe(gpu_src_addr, tmp_buffer.data(), size); | 311 | ReadBlockUnsafe(gpu_src_addr, tmp_buffer.data(), size); |
| 322 | WriteBlockUnsafe(gpu_dest_addr, tmp_buffer.data(), size); | 312 | WriteBlockUnsafe(gpu_dest_addr, tmp_buffer.data(), size); |
| 323 | } | 313 | } |
| 324 | 314 | ||
| 325 | bool MemoryManager::IsGranularRange(GPUVAddr gpu_addr, std::size_t size) { | 315 | bool MemoryManager::IsGranularRange(GPUVAddr gpu_addr, std::size_t size) { |
| 326 | const VAddr addr = page_table.backing_addr[gpu_addr >> page_bits]; | 316 | const auto cpu_addr{GpuToCpuAddress(gpu_addr)}; |
| 327 | const std::size_t page = (addr & Core::Memory::PAGE_MASK) + size; | 317 | if (!cpu_addr) { |
| 328 | return page <= Core::Memory::PAGE_SIZE; | ||
| 329 | } | ||
| 330 | |||
| 331 | void MemoryManager::MapPages(GPUVAddr base, u64 size, u8* memory, Common::PageType type, | ||
| 332 | VAddr backing_addr) { | ||
| 333 | LOG_DEBUG(HW_GPU, "Mapping {} onto {:016X}-{:016X}", fmt::ptr(memory), base * page_size, | ||
| 334 | (base + size) * page_size); | ||
| 335 | |||
| 336 | const VAddr end{base + size}; | ||
| 337 | ASSERT_MSG(end <= page_table.pointers.size(), "out of range mapping at {:016X}", | ||
| 338 | base + page_table.pointers.size()); | ||
| 339 | |||
| 340 | if (memory == nullptr) { | ||
| 341 | while (base != end) { | ||
| 342 | page_table.pointers[base] = nullptr; | ||
| 343 | page_table.backing_addr[base] = 0; | ||
| 344 | |||
| 345 | base += 1; | ||
| 346 | } | ||
| 347 | } else { | ||
| 348 | while (base != end) { | ||
| 349 | page_table.pointers[base] = memory; | ||
| 350 | page_table.backing_addr[base] = backing_addr; | ||
| 351 | |||
| 352 | base += 1; | ||
| 353 | memory += page_size; | ||
| 354 | backing_addr += page_size; | ||
| 355 | } | ||
| 356 | } | ||
| 357 | } | ||
| 358 | |||
| 359 | void MemoryManager::MapMemoryRegion(GPUVAddr base, u64 size, u8* target, VAddr backing_addr) { | ||
| 360 | ASSERT_MSG((size & page_mask) == 0, "non-page aligned size: {:016X}", size); | ||
| 361 | ASSERT_MSG((base & page_mask) == 0, "non-page aligned base: {:016X}", base); | ||
| 362 | MapPages(base / page_size, size / page_size, target, Common::PageType::Memory, backing_addr); | ||
| 363 | } | ||
| 364 | |||
| 365 | void MemoryManager::UnmapRegion(GPUVAddr base, u64 size) { | ||
| 366 | ASSERT_MSG((size & page_mask) == 0, "non-page aligned size: {:016X}", size); | ||
| 367 | ASSERT_MSG((base & page_mask) == 0, "non-page aligned base: {:016X}", base); | ||
| 368 | MapPages(base / page_size, size / page_size, nullptr, Common::PageType::Unmapped); | ||
| 369 | } | ||
| 370 | |||
| 371 | bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const { | ||
| 372 | ASSERT(base + size == next.base); | ||
| 373 | if (type != next.type) { | ||
| 374 | return {}; | ||
| 375 | } | ||
| 376 | if (type == VirtualMemoryArea::Type::Allocated && (offset + size != next.offset)) { | ||
| 377 | return {}; | ||
| 378 | } | ||
| 379 | if (type == VirtualMemoryArea::Type::Mapped && backing_memory + size != next.backing_memory) { | ||
| 380 | return {}; | ||
| 381 | } | ||
| 382 | return true; | ||
| 383 | } | ||
| 384 | |||
| 385 | MemoryManager::VMAHandle MemoryManager::FindVMA(GPUVAddr target) const { | ||
| 386 | if (target >= address_space_end) { | ||
| 387 | return vma_map.end(); | ||
| 388 | } else { | ||
| 389 | return std::prev(vma_map.upper_bound(target)); | ||
| 390 | } | ||
| 391 | } | ||
| 392 | |||
| 393 | MemoryManager::VMAIter MemoryManager::Allocate(VMAIter vma_handle) { | ||
| 394 | VirtualMemoryArea& vma{vma_handle->second}; | ||
| 395 | |||
| 396 | vma.type = VirtualMemoryArea::Type::Allocated; | ||
| 397 | vma.backing_addr = 0; | ||
| 398 | vma.backing_memory = {}; | ||
| 399 | UpdatePageTableForVMA(vma); | ||
| 400 | |||
| 401 | return MergeAdjacent(vma_handle); | ||
| 402 | } | ||
| 403 | |||
| 404 | MemoryManager::VMAHandle MemoryManager::AllocateMemory(GPUVAddr target, std::size_t offset, | ||
| 405 | u64 size) { | ||
| 406 | |||
| 407 | // This is the appropriately sized VMA that will turn into our allocation. | ||
| 408 | VMAIter vma_handle{CarveVMA(target, size)}; | ||
| 409 | VirtualMemoryArea& vma{vma_handle->second}; | ||
| 410 | |||
| 411 | ASSERT(vma.size == size); | ||
| 412 | |||
| 413 | vma.offset = offset; | ||
| 414 | |||
| 415 | return Allocate(vma_handle); | ||
| 416 | } | ||
| 417 | |||
| 418 | MemoryManager::VMAHandle MemoryManager::MapBackingMemory(GPUVAddr target, u8* memory, u64 size, | ||
| 419 | VAddr backing_addr) { | ||
| 420 | // This is the appropriately sized VMA that will turn into our allocation. | ||
| 421 | VMAIter vma_handle{CarveVMA(target, size)}; | ||
| 422 | VirtualMemoryArea& vma{vma_handle->second}; | ||
| 423 | |||
| 424 | ASSERT(vma.size == size); | ||
| 425 | |||
| 426 | vma.type = VirtualMemoryArea::Type::Mapped; | ||
| 427 | vma.backing_memory = memory; | ||
| 428 | vma.backing_addr = backing_addr; | ||
| 429 | UpdatePageTableForVMA(vma); | ||
| 430 | |||
| 431 | return MergeAdjacent(vma_handle); | ||
| 432 | } | ||
| 433 | |||
| 434 | void MemoryManager::UnmapRange(GPUVAddr target, u64 size) { | ||
| 435 | VMAIter vma{CarveVMARange(target, size)}; | ||
| 436 | const VAddr target_end{target + size}; | ||
| 437 | const VMAIter end{vma_map.end()}; | ||
| 438 | |||
| 439 | // The comparison against the end of the range must be done using addresses since VMAs can be | ||
| 440 | // merged during this process, causing invalidation of the iterators. | ||
| 441 | while (vma != end && vma->second.base < target_end) { | ||
| 442 | // Unmapped ranges return to allocated state and can be reused | ||
| 443 | // This behavior is used by Super Mario Odyssey, Sonic Forces, and likely other games | ||
| 444 | vma = std::next(Allocate(vma)); | ||
| 445 | } | ||
| 446 | |||
| 447 | ASSERT(FindVMA(target)->second.size >= size); | ||
| 448 | } | ||
| 449 | |||
| 450 | MemoryManager::VMAIter MemoryManager::StripIterConstness(const VMAHandle& iter) { | ||
| 451 | // This uses a neat C++ trick to convert a const_iterator to a regular iterator, given | ||
| 452 | // non-const access to its container. | ||
| 453 | return vma_map.erase(iter, iter); // Erases an empty range of elements | ||
| 454 | } | ||
| 455 | |||
| 456 | MemoryManager::VMAIter MemoryManager::CarveVMA(GPUVAddr base, u64 size) { | ||
| 457 | ASSERT_MSG((size & page_mask) == 0, "non-page aligned size: 0x{:016X}", size); | ||
| 458 | ASSERT_MSG((base & page_mask) == 0, "non-page aligned base: 0x{:016X}", base); | ||
| 459 | |||
| 460 | VMAIter vma_handle{StripIterConstness(FindVMA(base))}; | ||
| 461 | if (vma_handle == vma_map.end()) { | ||
| 462 | // Target address is outside the managed range | ||
| 463 | return {}; | ||
| 464 | } | ||
| 465 | |||
| 466 | const VirtualMemoryArea& vma{vma_handle->second}; | ||
| 467 | if (vma.type == VirtualMemoryArea::Type::Mapped) { | ||
| 468 | // Region is already allocated | ||
| 469 | return vma_handle; | ||
| 470 | } | ||
| 471 | |||
| 472 | const VAddr start_in_vma{base - vma.base}; | ||
| 473 | const VAddr end_in_vma{start_in_vma + size}; | ||
| 474 | |||
| 475 | ASSERT_MSG(end_in_vma <= vma.size, "region size 0x{:016X} is less than required size 0x{:016X}", | ||
| 476 | vma.size, end_in_vma); | ||
| 477 | |||
| 478 | if (end_in_vma < vma.size) { | ||
| 479 | // Split VMA at the end of the allocated region | ||
| 480 | SplitVMA(vma_handle, end_in_vma); | ||
| 481 | } | ||
| 482 | if (start_in_vma != 0) { | ||
| 483 | // Split VMA at the start of the allocated region | ||
| 484 | vma_handle = SplitVMA(vma_handle, start_in_vma); | ||
| 485 | } | ||
| 486 | |||
| 487 | return vma_handle; | ||
| 488 | } | ||
| 489 | |||
| 490 | MemoryManager::VMAIter MemoryManager::CarveVMARange(GPUVAddr target, u64 size) { | ||
| 491 | ASSERT_MSG((size & page_mask) == 0, "non-page aligned size: 0x{:016X}", size); | ||
| 492 | ASSERT_MSG((target & page_mask) == 0, "non-page aligned base: 0x{:016X}", target); | ||
| 493 | |||
| 494 | const VAddr target_end{target + size}; | ||
| 495 | ASSERT(target_end >= target); | ||
| 496 | ASSERT(size > 0); | ||
| 497 | |||
| 498 | VMAIter begin_vma{StripIterConstness(FindVMA(target))}; | ||
| 499 | const VMAIter i_end{vma_map.lower_bound(target_end)}; | ||
| 500 | if (std::any_of(begin_vma, i_end, [](const auto& entry) { | ||
| 501 | return entry.second.type == VirtualMemoryArea::Type::Unmapped; | ||
| 502 | })) { | ||
| 503 | return {}; | 318 | return {}; |
| 504 | } | 319 | } |
| 505 | 320 | const std::size_t page{(*cpu_addr & Core::Memory::PAGE_MASK) + size}; | |
| 506 | if (target != begin_vma->second.base) { | 321 | return page <= Core::Memory::PAGE_SIZE; |
| 507 | begin_vma = SplitVMA(begin_vma, target - begin_vma->second.base); | ||
| 508 | } | ||
| 509 | |||
| 510 | VMAIter end_vma{StripIterConstness(FindVMA(target_end))}; | ||
| 511 | if (end_vma != vma_map.end() && target_end != end_vma->second.base) { | ||
| 512 | end_vma = SplitVMA(end_vma, target_end - end_vma->second.base); | ||
| 513 | } | ||
| 514 | |||
| 515 | return begin_vma; | ||
| 516 | } | ||
| 517 | |||
| 518 | MemoryManager::VMAIter MemoryManager::SplitVMA(VMAIter vma_handle, u64 offset_in_vma) { | ||
| 519 | VirtualMemoryArea& old_vma{vma_handle->second}; | ||
| 520 | VirtualMemoryArea new_vma{old_vma}; // Make a copy of the VMA | ||
| 521 | |||
| 522 | // For now, don't allow no-op VMA splits (trying to split at a boundary) because it's probably | ||
| 523 | // a bug. This restriction might be removed later. | ||
| 524 | ASSERT(offset_in_vma < old_vma.size); | ||
| 525 | ASSERT(offset_in_vma > 0); | ||
| 526 | |||
| 527 | old_vma.size = offset_in_vma; | ||
| 528 | new_vma.base += offset_in_vma; | ||
| 529 | new_vma.size -= offset_in_vma; | ||
| 530 | |||
| 531 | switch (new_vma.type) { | ||
| 532 | case VirtualMemoryArea::Type::Unmapped: | ||
| 533 | break; | ||
| 534 | case VirtualMemoryArea::Type::Allocated: | ||
| 535 | new_vma.offset += offset_in_vma; | ||
| 536 | break; | ||
| 537 | case VirtualMemoryArea::Type::Mapped: | ||
| 538 | new_vma.backing_memory += offset_in_vma; | ||
| 539 | break; | ||
| 540 | } | ||
| 541 | |||
| 542 | ASSERT(old_vma.CanBeMergedWith(new_vma)); | ||
| 543 | |||
| 544 | return vma_map.emplace_hint(std::next(vma_handle), new_vma.base, new_vma); | ||
| 545 | } | ||
| 546 | |||
| 547 | MemoryManager::VMAIter MemoryManager::MergeAdjacent(VMAIter iter) { | ||
| 548 | const VMAIter next_vma{std::next(iter)}; | ||
| 549 | if (next_vma != vma_map.end() && iter->second.CanBeMergedWith(next_vma->second)) { | ||
| 550 | iter->second.size += next_vma->second.size; | ||
| 551 | vma_map.erase(next_vma); | ||
| 552 | } | ||
| 553 | |||
| 554 | if (iter != vma_map.begin()) { | ||
| 555 | VMAIter prev_vma{std::prev(iter)}; | ||
| 556 | if (prev_vma->second.CanBeMergedWith(iter->second)) { | ||
| 557 | prev_vma->second.size += iter->second.size; | ||
| 558 | vma_map.erase(iter); | ||
| 559 | iter = prev_vma; | ||
| 560 | } | ||
| 561 | } | ||
| 562 | |||
| 563 | return iter; | ||
| 564 | } | ||
| 565 | |||
| 566 | void MemoryManager::UpdatePageTableForVMA(const VirtualMemoryArea& vma) { | ||
| 567 | switch (vma.type) { | ||
| 568 | case VirtualMemoryArea::Type::Unmapped: | ||
| 569 | UnmapRegion(vma.base, vma.size); | ||
| 570 | break; | ||
| 571 | case VirtualMemoryArea::Type::Allocated: | ||
| 572 | MapMemoryRegion(vma.base, vma.size, nullptr, vma.backing_addr); | ||
| 573 | break; | ||
| 574 | case VirtualMemoryArea::Type::Mapped: | ||
| 575 | MapMemoryRegion(vma.base, vma.size, vma.backing_memory, vma.backing_addr); | ||
| 576 | break; | ||
| 577 | } | ||
| 578 | } | 322 | } |
| 579 | 323 | ||
| 580 | } // namespace Tegra | 324 | } // namespace Tegra |
diff --git a/src/video_core/memory_manager.h b/src/video_core/memory_manager.h index 87658e87a..681bd9588 100644 --- a/src/video_core/memory_manager.h +++ b/src/video_core/memory_manager.h | |||
| @@ -6,9 +6,9 @@ | |||
| 6 | 6 | ||
| 7 | #include <map> | 7 | #include <map> |
| 8 | #include <optional> | 8 | #include <optional> |
| 9 | #include <vector> | ||
| 9 | 10 | ||
| 10 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 11 | #include "common/page_table.h" | ||
| 12 | 12 | ||
| 13 | namespace VideoCore { | 13 | namespace VideoCore { |
| 14 | class RasterizerInterface; | 14 | class RasterizerInterface; |
| @@ -20,45 +20,57 @@ class System; | |||
| 20 | 20 | ||
| 21 | namespace Tegra { | 21 | namespace Tegra { |
| 22 | 22 | ||
| 23 | /** | 23 | class PageEntry final { |
| 24 | * Represents a VMA in an address space. A VMA is a contiguous region of virtual addressing space | 24 | public: |
| 25 | * with homogeneous attributes across its extents. In this particular implementation each VMA is | 25 | enum class State : u32 { |
| 26 | * also backed by a single host memory allocation. | 26 | Unmapped = static_cast<u32>(-1), |
| 27 | */ | 27 | Allocated = static_cast<u32>(-2), |
| 28 | struct VirtualMemoryArea { | ||
| 29 | enum class Type : u8 { | ||
| 30 | Unmapped, | ||
| 31 | Allocated, | ||
| 32 | Mapped, | ||
| 33 | }; | 28 | }; |
| 34 | 29 | ||
| 35 | /// Virtual base address of the region. | 30 | constexpr PageEntry() = default; |
| 36 | GPUVAddr base{}; | 31 | constexpr PageEntry(State state) : state{state} {} |
| 37 | /// Size of the region. | 32 | constexpr PageEntry(VAddr addr) : state{static_cast<State>(addr >> ShiftBits)} {} |
| 38 | u64 size{}; | 33 | |
| 39 | /// Memory area mapping type. | 34 | constexpr bool IsUnmapped() const { |
| 40 | Type type{Type::Unmapped}; | 35 | return state == State::Unmapped; |
| 41 | /// CPU memory mapped address corresponding to this memory area. | 36 | } |
| 42 | VAddr backing_addr{}; | 37 | |
| 43 | /// Offset into the backing_memory the mapping starts from. | 38 | constexpr bool IsAllocated() const { |
| 44 | std::size_t offset{}; | 39 | return state == State::Allocated; |
| 45 | /// Pointer backing this VMA. | 40 | } |
| 46 | u8* backing_memory{}; | 41 | |
| 47 | 42 | constexpr bool IsValid() const { | |
| 48 | /// Tests if this area can be merged to the right with `next`. | 43 | return !IsUnmapped() && !IsAllocated(); |
| 49 | bool CanBeMergedWith(const VirtualMemoryArea& next) const; | 44 | } |
| 45 | |||
| 46 | constexpr VAddr ToAddress() const { | ||
| 47 | if (!IsValid()) { | ||
| 48 | return {}; | ||
| 49 | } | ||
| 50 | |||
| 51 | return static_cast<VAddr>(state) << ShiftBits; | ||
| 52 | } | ||
| 53 | |||
| 54 | constexpr PageEntry operator+(u64 offset) { | ||
| 55 | // If this is a reserved value, offsets do not apply | ||
| 56 | if (!IsValid()) { | ||
| 57 | return *this; | ||
| 58 | } | ||
| 59 | return PageEntry{(static_cast<VAddr>(state) << ShiftBits) + offset}; | ||
| 60 | } | ||
| 61 | |||
| 62 | private: | ||
| 63 | static constexpr std::size_t ShiftBits{12}; | ||
| 64 | |||
| 65 | State state{State::Unmapped}; | ||
| 50 | }; | 66 | }; |
| 67 | static_assert(sizeof(PageEntry) == 4, "PageEntry is too large"); | ||
| 51 | 68 | ||
| 52 | class MemoryManager final { | 69 | class MemoryManager final { |
| 53 | public: | 70 | public: |
| 54 | explicit MemoryManager(Core::System& system, VideoCore::RasterizerInterface& rasterizer); | 71 | explicit MemoryManager(Core::System& system, VideoCore::RasterizerInterface& rasterizer); |
| 55 | ~MemoryManager(); | 72 | ~MemoryManager(); |
| 56 | 73 | ||
| 57 | GPUVAddr AllocateSpace(u64 size, u64 align); | ||
| 58 | GPUVAddr AllocateSpace(GPUVAddr addr, u64 size, u64 align); | ||
| 59 | GPUVAddr MapBufferEx(VAddr cpu_addr, u64 size); | ||
| 60 | GPUVAddr MapBufferEx(VAddr cpu_addr, GPUVAddr addr, u64 size); | ||
| 61 | GPUVAddr UnmapBuffer(GPUVAddr addr, u64 size); | ||
| 62 | std::optional<VAddr> GpuToCpuAddress(GPUVAddr addr) const; | 74 | std::optional<VAddr> GpuToCpuAddress(GPUVAddr addr) const; |
| 63 | 75 | ||
| 64 | template <typename T> | 76 | template <typename T> |
| @@ -70,9 +82,6 @@ public: | |||
| 70 | u8* GetPointer(GPUVAddr addr); | 82 | u8* GetPointer(GPUVAddr addr); |
| 71 | const u8* GetPointer(GPUVAddr addr) const; | 83 | const u8* GetPointer(GPUVAddr addr) const; |
| 72 | 84 | ||
| 73 | /// Returns true if the block is continuous in host memory, false otherwise | ||
| 74 | bool IsBlockContinuous(GPUVAddr start, std::size_t size) const; | ||
| 75 | |||
| 76 | /** | 85 | /** |
| 77 | * ReadBlock and WriteBlock are full read and write operations over virtual | 86 | * ReadBlock and WriteBlock are full read and write operations over virtual |
| 78 | * GPU Memory. It's important to use these when GPU memory may not be continuous | 87 | * GPU Memory. It's important to use these when GPU memory may not be continuous |
| @@ -98,92 +107,43 @@ public: | |||
| 98 | void CopyBlockUnsafe(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, std::size_t size); | 107 | void CopyBlockUnsafe(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, std::size_t size); |
| 99 | 108 | ||
| 100 | /** | 109 | /** |
| 101 | * IsGranularRange checks if a gpu region can be simply read with a pointer | 110 | * IsGranularRange checks if a gpu region can be simply read with a pointer. |
| 102 | */ | 111 | */ |
| 103 | bool IsGranularRange(GPUVAddr gpu_addr, std::size_t size); | 112 | bool IsGranularRange(GPUVAddr gpu_addr, std::size_t size); |
| 104 | 113 | ||
| 105 | private: | 114 | GPUVAddr Map(VAddr cpu_addr, GPUVAddr gpu_addr, std::size_t size); |
| 106 | using VMAMap = std::map<GPUVAddr, VirtualMemoryArea>; | 115 | GPUVAddr MapAllocate(VAddr cpu_addr, std::size_t size, std::size_t align); |
| 107 | using VMAHandle = VMAMap::const_iterator; | 116 | std::optional<GPUVAddr> AllocateFixed(GPUVAddr gpu_addr, std::size_t size); |
| 108 | using VMAIter = VMAMap::iterator; | 117 | GPUVAddr Allocate(std::size_t size, std::size_t align); |
| 109 | 118 | void Unmap(GPUVAddr gpu_addr, std::size_t size); | |
| 110 | bool IsAddressValid(GPUVAddr addr) const; | ||
| 111 | void MapPages(GPUVAddr base, u64 size, u8* memory, Common::PageType type, | ||
| 112 | VAddr backing_addr = 0); | ||
| 113 | void MapMemoryRegion(GPUVAddr base, u64 size, u8* target, VAddr backing_addr); | ||
| 114 | void UnmapRegion(GPUVAddr base, u64 size); | ||
| 115 | |||
| 116 | /// Finds the VMA in which the given address is included in, or `vma_map.end()`. | ||
| 117 | VMAHandle FindVMA(GPUVAddr target) const; | ||
| 118 | |||
| 119 | VMAHandle AllocateMemory(GPUVAddr target, std::size_t offset, u64 size); | ||
| 120 | |||
| 121 | /** | ||
| 122 | * Maps an unmanaged host memory pointer at a given address. | ||
| 123 | * | ||
| 124 | * @param target The guest address to start the mapping at. | ||
| 125 | * @param memory The memory to be mapped. | ||
| 126 | * @param size Size of the mapping in bytes. | ||
| 127 | * @param backing_addr The base address of the range to back this mapping. | ||
| 128 | */ | ||
| 129 | VMAHandle MapBackingMemory(GPUVAddr target, u8* memory, u64 size, VAddr backing_addr); | ||
| 130 | |||
| 131 | /// Unmaps a range of addresses, splitting VMAs as necessary. | ||
| 132 | void UnmapRange(GPUVAddr target, u64 size); | ||
| 133 | |||
| 134 | /// Converts a VMAHandle to a mutable VMAIter. | ||
| 135 | VMAIter StripIterConstness(const VMAHandle& iter); | ||
| 136 | |||
| 137 | /// Marks as the specified VMA as allocated. | ||
| 138 | VMAIter Allocate(VMAIter vma); | ||
| 139 | |||
| 140 | /** | ||
| 141 | * Carves a VMA of a specific size at the specified address by splitting Free VMAs while doing | ||
| 142 | * the appropriate error checking. | ||
| 143 | */ | ||
| 144 | VMAIter CarveVMA(GPUVAddr base, u64 size); | ||
| 145 | |||
| 146 | /** | ||
| 147 | * Splits the edges of the given range of non-Free VMAs so that there is a VMA split at each | ||
| 148 | * end of the range. | ||
| 149 | */ | ||
| 150 | VMAIter CarveVMARange(GPUVAddr base, u64 size); | ||
| 151 | |||
| 152 | /** | ||
| 153 | * Splits a VMA in two, at the specified offset. | ||
| 154 | * @returns the right side of the split, with the original iterator becoming the left side. | ||
| 155 | */ | ||
| 156 | VMAIter SplitVMA(VMAIter vma, u64 offset_in_vma); | ||
| 157 | 119 | ||
| 158 | /** | 120 | private: |
| 159 | * Checks for and merges the specified VMA with adjacent ones if possible. | 121 | PageEntry GetPageEntry(GPUVAddr gpu_addr) const; |
| 160 | * @returns the merged VMA or the original if no merging was possible. | 122 | void SetPageEntry(GPUVAddr gpu_addr, PageEntry page_entry, std::size_t size = page_size); |
| 161 | */ | 123 | GPUVAddr UpdateRange(GPUVAddr gpu_addr, PageEntry page_entry, std::size_t size); |
| 162 | VMAIter MergeAdjacent(VMAIter vma); | 124 | std::optional<GPUVAddr> FindFreeRange(std::size_t size, std::size_t align) const; |
| 163 | 125 | ||
| 164 | /// Updates the pages corresponding to this VMA so they match the VMA's attributes. | 126 | void TryLockPage(PageEntry page_entry, std::size_t size); |
| 165 | void UpdatePageTableForVMA(const VirtualMemoryArea& vma); | 127 | void TryUnlockPage(PageEntry page_entry, std::size_t size); |
| 166 | 128 | ||
| 167 | /// Finds a free (unmapped region) of the specified size starting at the specified address. | 129 | static constexpr std::size_t PageEntryIndex(GPUVAddr gpu_addr) { |
| 168 | GPUVAddr FindFreeRegion(GPUVAddr region_start, u64 size) const; | 130 | return (gpu_addr >> page_bits) & page_table_mask; |
| 131 | } | ||
| 169 | 132 | ||
| 170 | private: | 133 | static constexpr u64 address_space_size = 1ULL << 40; |
| 134 | static constexpr u64 address_space_start = 1ULL << 32; | ||
| 171 | static constexpr u64 page_bits{16}; | 135 | static constexpr u64 page_bits{16}; |
| 172 | static constexpr u64 page_size{1 << page_bits}; | 136 | static constexpr u64 page_size{1 << page_bits}; |
| 173 | static constexpr u64 page_mask{page_size - 1}; | 137 | static constexpr u64 page_mask{page_size - 1}; |
| 138 | static constexpr u64 page_table_bits{24}; | ||
| 139 | static constexpr u64 page_table_size{1 << page_table_bits}; | ||
| 140 | static constexpr u64 page_table_mask{page_table_size - 1}; | ||
| 174 | 141 | ||
| 175 | /// Address space in bits, according to Tegra X1 TRM | 142 | Core::System& system; |
| 176 | static constexpr u32 address_space_width{40}; | ||
| 177 | /// Start address for mapping, this is fairly arbitrary but must be non-zero. | ||
| 178 | static constexpr GPUVAddr address_space_base{0x100000}; | ||
| 179 | /// End of address space, based on address space in bits. | ||
| 180 | static constexpr GPUVAddr address_space_end{1ULL << address_space_width}; | ||
| 181 | 143 | ||
| 182 | Common::PageTable page_table; | ||
| 183 | VMAMap vma_map; | ||
| 184 | VideoCore::RasterizerInterface& rasterizer; | 144 | VideoCore::RasterizerInterface& rasterizer; |
| 185 | 145 | ||
| 186 | Core::System& system; | 146 | std::vector<PageEntry> page_table; |
| 187 | }; | 147 | }; |
| 188 | 148 | ||
| 189 | } // namespace Tegra | 149 | } // namespace Tegra |
diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp index 836b25c1d..9da9fb4ff 100644 --- a/src/video_core/morton.cpp +++ b/src/video_core/morton.cpp | |||
| @@ -41,146 +41,168 @@ static void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth | |||
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | static constexpr ConversionArray morton_to_linear_fns = { | 43 | static constexpr ConversionArray morton_to_linear_fns = { |
| 44 | MortonCopy<true, PixelFormat::ABGR8U>, | 44 | MortonCopy<true, PixelFormat::A8B8G8R8_UNORM>, |
| 45 | MortonCopy<true, PixelFormat::ABGR8S>, | 45 | MortonCopy<true, PixelFormat::A8B8G8R8_SNORM>, |
| 46 | MortonCopy<true, PixelFormat::ABGR8UI>, | 46 | MortonCopy<true, PixelFormat::A8B8G8R8_SINT>, |
| 47 | MortonCopy<true, PixelFormat::B5G6R5U>, | 47 | MortonCopy<true, PixelFormat::A8B8G8R8_UINT>, |
| 48 | MortonCopy<true, PixelFormat::A2B10G10R10U>, | 48 | MortonCopy<true, PixelFormat::R5G6B5_UNORM>, |
| 49 | MortonCopy<true, PixelFormat::A1B5G5R5U>, | 49 | MortonCopy<true, PixelFormat::B5G6R5_UNORM>, |
| 50 | MortonCopy<true, PixelFormat::R8U>, | 50 | MortonCopy<true, PixelFormat::A1R5G5B5_UNORM>, |
| 51 | MortonCopy<true, PixelFormat::R8UI>, | 51 | MortonCopy<true, PixelFormat::A2B10G10R10_UNORM>, |
| 52 | MortonCopy<true, PixelFormat::RGBA16F>, | 52 | MortonCopy<true, PixelFormat::A2B10G10R10_UINT>, |
| 53 | MortonCopy<true, PixelFormat::RGBA16U>, | 53 | MortonCopy<true, PixelFormat::A1B5G5R5_UNORM>, |
| 54 | MortonCopy<true, PixelFormat::RGBA16S>, | 54 | MortonCopy<true, PixelFormat::R8_UNORM>, |
| 55 | MortonCopy<true, PixelFormat::RGBA16UI>, | 55 | MortonCopy<true, PixelFormat::R8_SNORM>, |
| 56 | MortonCopy<true, PixelFormat::R11FG11FB10F>, | 56 | MortonCopy<true, PixelFormat::R8_SINT>, |
| 57 | MortonCopy<true, PixelFormat::RGBA32UI>, | 57 | MortonCopy<true, PixelFormat::R8_UINT>, |
| 58 | MortonCopy<true, PixelFormat::DXT1>, | 58 | MortonCopy<true, PixelFormat::R16G16B16A16_FLOAT>, |
| 59 | MortonCopy<true, PixelFormat::DXT23>, | 59 | MortonCopy<true, PixelFormat::R16G16B16A16_UNORM>, |
| 60 | MortonCopy<true, PixelFormat::DXT45>, | 60 | MortonCopy<true, PixelFormat::R16G16B16A16_SNORM>, |
| 61 | MortonCopy<true, PixelFormat::DXN1>, | 61 | MortonCopy<true, PixelFormat::R16G16B16A16_SINT>, |
| 62 | MortonCopy<true, PixelFormat::DXN2UNORM>, | 62 | MortonCopy<true, PixelFormat::R16G16B16A16_UINT>, |
| 63 | MortonCopy<true, PixelFormat::DXN2SNORM>, | 63 | MortonCopy<true, PixelFormat::B10G11R11_FLOAT>, |
| 64 | MortonCopy<true, PixelFormat::BC7U>, | 64 | MortonCopy<true, PixelFormat::R32G32B32A32_UINT>, |
| 65 | MortonCopy<true, PixelFormat::BC6H_UF16>, | 65 | MortonCopy<true, PixelFormat::BC1_RGBA_UNORM>, |
| 66 | MortonCopy<true, PixelFormat::BC6H_SF16>, | 66 | MortonCopy<true, PixelFormat::BC2_UNORM>, |
| 67 | MortonCopy<true, PixelFormat::ASTC_2D_4X4>, | 67 | MortonCopy<true, PixelFormat::BC3_UNORM>, |
| 68 | MortonCopy<true, PixelFormat::BGRA8>, | 68 | MortonCopy<true, PixelFormat::BC4_UNORM>, |
| 69 | MortonCopy<true, PixelFormat::RGBA32F>, | 69 | MortonCopy<true, PixelFormat::BC4_SNORM>, |
| 70 | MortonCopy<true, PixelFormat::RG32F>, | 70 | MortonCopy<true, PixelFormat::BC5_UNORM>, |
| 71 | MortonCopy<true, PixelFormat::R32F>, | 71 | MortonCopy<true, PixelFormat::BC5_SNORM>, |
| 72 | MortonCopy<true, PixelFormat::R16F>, | 72 | MortonCopy<true, PixelFormat::BC7_UNORM>, |
| 73 | MortonCopy<true, PixelFormat::R16U>, | 73 | MortonCopy<true, PixelFormat::BC6H_UFLOAT>, |
| 74 | MortonCopy<true, PixelFormat::R16S>, | 74 | MortonCopy<true, PixelFormat::BC6H_SFLOAT>, |
| 75 | MortonCopy<true, PixelFormat::R16UI>, | 75 | MortonCopy<true, PixelFormat::ASTC_2D_4X4_UNORM>, |
| 76 | MortonCopy<true, PixelFormat::R16I>, | 76 | MortonCopy<true, PixelFormat::B8G8R8A8_UNORM>, |
| 77 | MortonCopy<true, PixelFormat::RG16>, | 77 | MortonCopy<true, PixelFormat::R32G32B32A32_FLOAT>, |
| 78 | MortonCopy<true, PixelFormat::RG16F>, | 78 | MortonCopy<true, PixelFormat::R32G32B32A32_SINT>, |
| 79 | MortonCopy<true, PixelFormat::RG16UI>, | 79 | MortonCopy<true, PixelFormat::R32G32_FLOAT>, |
| 80 | MortonCopy<true, PixelFormat::RG16I>, | 80 | MortonCopy<true, PixelFormat::R32G32_SINT>, |
| 81 | MortonCopy<true, PixelFormat::RG16S>, | 81 | MortonCopy<true, PixelFormat::R32_FLOAT>, |
| 82 | MortonCopy<true, PixelFormat::RGB32F>, | 82 | MortonCopy<true, PixelFormat::R16_FLOAT>, |
| 83 | MortonCopy<true, PixelFormat::RGBA8_SRGB>, | 83 | MortonCopy<true, PixelFormat::R16_UNORM>, |
| 84 | MortonCopy<true, PixelFormat::RG8U>, | 84 | MortonCopy<true, PixelFormat::R16_SNORM>, |
| 85 | MortonCopy<true, PixelFormat::RG8S>, | 85 | MortonCopy<true, PixelFormat::R16_UINT>, |
| 86 | MortonCopy<true, PixelFormat::RG8UI>, | 86 | MortonCopy<true, PixelFormat::R16_SINT>, |
| 87 | MortonCopy<true, PixelFormat::RG32UI>, | 87 | MortonCopy<true, PixelFormat::R16G16_UNORM>, |
| 88 | MortonCopy<true, PixelFormat::RGBX16F>, | 88 | MortonCopy<true, PixelFormat::R16G16_FLOAT>, |
| 89 | MortonCopy<true, PixelFormat::R32UI>, | 89 | MortonCopy<true, PixelFormat::R16G16_UINT>, |
| 90 | MortonCopy<true, PixelFormat::R32I>, | 90 | MortonCopy<true, PixelFormat::R16G16_SINT>, |
| 91 | MortonCopy<true, PixelFormat::ASTC_2D_8X8>, | 91 | MortonCopy<true, PixelFormat::R16G16_SNORM>, |
| 92 | MortonCopy<true, PixelFormat::ASTC_2D_8X5>, | 92 | MortonCopy<true, PixelFormat::R32G32B32_FLOAT>, |
| 93 | MortonCopy<true, PixelFormat::ASTC_2D_5X4>, | 93 | MortonCopy<true, PixelFormat::A8B8G8R8_SRGB>, |
| 94 | MortonCopy<true, PixelFormat::BGRA8_SRGB>, | 94 | MortonCopy<true, PixelFormat::R8G8_UNORM>, |
| 95 | MortonCopy<true, PixelFormat::DXT1_SRGB>, | 95 | MortonCopy<true, PixelFormat::R8G8_SNORM>, |
| 96 | MortonCopy<true, PixelFormat::DXT23_SRGB>, | 96 | MortonCopy<true, PixelFormat::R8G8_SINT>, |
| 97 | MortonCopy<true, PixelFormat::DXT45_SRGB>, | 97 | MortonCopy<true, PixelFormat::R8G8_UINT>, |
| 98 | MortonCopy<true, PixelFormat::BC7U_SRGB>, | 98 | MortonCopy<true, PixelFormat::R32G32_UINT>, |
| 99 | MortonCopy<true, PixelFormat::R4G4B4A4U>, | 99 | MortonCopy<true, PixelFormat::R16G16B16X16_FLOAT>, |
| 100 | MortonCopy<true, PixelFormat::R32_UINT>, | ||
| 101 | MortonCopy<true, PixelFormat::R32_SINT>, | ||
| 102 | MortonCopy<true, PixelFormat::ASTC_2D_8X8_UNORM>, | ||
| 103 | MortonCopy<true, PixelFormat::ASTC_2D_8X5_UNORM>, | ||
| 104 | MortonCopy<true, PixelFormat::ASTC_2D_5X4_UNORM>, | ||
| 105 | MortonCopy<true, PixelFormat::B8G8R8A8_SRGB>, | ||
| 106 | MortonCopy<true, PixelFormat::BC1_RGBA_SRGB>, | ||
| 107 | MortonCopy<true, PixelFormat::BC2_SRGB>, | ||
| 108 | MortonCopy<true, PixelFormat::BC3_SRGB>, | ||
| 109 | MortonCopy<true, PixelFormat::BC7_SRGB>, | ||
| 110 | MortonCopy<true, PixelFormat::A4B4G4R4_UNORM>, | ||
| 100 | MortonCopy<true, PixelFormat::ASTC_2D_4X4_SRGB>, | 111 | MortonCopy<true, PixelFormat::ASTC_2D_4X4_SRGB>, |
| 101 | MortonCopy<true, PixelFormat::ASTC_2D_8X8_SRGB>, | 112 | MortonCopy<true, PixelFormat::ASTC_2D_8X8_SRGB>, |
| 102 | MortonCopy<true, PixelFormat::ASTC_2D_8X5_SRGB>, | 113 | MortonCopy<true, PixelFormat::ASTC_2D_8X5_SRGB>, |
| 103 | MortonCopy<true, PixelFormat::ASTC_2D_5X4_SRGB>, | 114 | MortonCopy<true, PixelFormat::ASTC_2D_5X4_SRGB>, |
| 104 | MortonCopy<true, PixelFormat::ASTC_2D_5X5>, | 115 | MortonCopy<true, PixelFormat::ASTC_2D_5X5_UNORM>, |
| 105 | MortonCopy<true, PixelFormat::ASTC_2D_5X5_SRGB>, | 116 | MortonCopy<true, PixelFormat::ASTC_2D_5X5_SRGB>, |
| 106 | MortonCopy<true, PixelFormat::ASTC_2D_10X8>, | 117 | MortonCopy<true, PixelFormat::ASTC_2D_10X8_UNORM>, |
| 107 | MortonCopy<true, PixelFormat::ASTC_2D_10X8_SRGB>, | 118 | MortonCopy<true, PixelFormat::ASTC_2D_10X8_SRGB>, |
| 108 | MortonCopy<true, PixelFormat::ASTC_2D_6X6>, | 119 | MortonCopy<true, PixelFormat::ASTC_2D_6X6_UNORM>, |
| 109 | MortonCopy<true, PixelFormat::ASTC_2D_6X6_SRGB>, | 120 | MortonCopy<true, PixelFormat::ASTC_2D_6X6_SRGB>, |
| 110 | MortonCopy<true, PixelFormat::ASTC_2D_10X10>, | 121 | MortonCopy<true, PixelFormat::ASTC_2D_10X10_UNORM>, |
| 111 | MortonCopy<true, PixelFormat::ASTC_2D_10X10_SRGB>, | 122 | MortonCopy<true, PixelFormat::ASTC_2D_10X10_SRGB>, |
| 112 | MortonCopy<true, PixelFormat::ASTC_2D_12X12>, | 123 | MortonCopy<true, PixelFormat::ASTC_2D_12X12_UNORM>, |
| 113 | MortonCopy<true, PixelFormat::ASTC_2D_12X12_SRGB>, | 124 | MortonCopy<true, PixelFormat::ASTC_2D_12X12_SRGB>, |
| 114 | MortonCopy<true, PixelFormat::ASTC_2D_8X6>, | 125 | MortonCopy<true, PixelFormat::ASTC_2D_8X6_UNORM>, |
| 115 | MortonCopy<true, PixelFormat::ASTC_2D_8X6_SRGB>, | 126 | MortonCopy<true, PixelFormat::ASTC_2D_8X6_SRGB>, |
| 116 | MortonCopy<true, PixelFormat::ASTC_2D_6X5>, | 127 | MortonCopy<true, PixelFormat::ASTC_2D_6X5_UNORM>, |
| 117 | MortonCopy<true, PixelFormat::ASTC_2D_6X5_SRGB>, | 128 | MortonCopy<true, PixelFormat::ASTC_2D_6X5_SRGB>, |
| 118 | MortonCopy<true, PixelFormat::E5B9G9R9F>, | 129 | MortonCopy<true, PixelFormat::E5B9G9R9_FLOAT>, |
| 119 | MortonCopy<true, PixelFormat::Z32F>, | 130 | MortonCopy<true, PixelFormat::D32_FLOAT>, |
| 120 | MortonCopy<true, PixelFormat::Z16>, | 131 | MortonCopy<true, PixelFormat::D16_UNORM>, |
| 121 | MortonCopy<true, PixelFormat::Z24S8>, | 132 | MortonCopy<true, PixelFormat::D24_UNORM_S8_UINT>, |
| 122 | MortonCopy<true, PixelFormat::S8Z24>, | 133 | MortonCopy<true, PixelFormat::S8_UINT_D24_UNORM>, |
| 123 | MortonCopy<true, PixelFormat::Z32FS8>, | 134 | MortonCopy<true, PixelFormat::D32_FLOAT_S8_UINT>, |
| 124 | }; | 135 | }; |
| 125 | 136 | ||
| 126 | static constexpr ConversionArray linear_to_morton_fns = { | 137 | static constexpr ConversionArray linear_to_morton_fns = { |
| 127 | MortonCopy<false, PixelFormat::ABGR8U>, | 138 | MortonCopy<false, PixelFormat::A8B8G8R8_UNORM>, |
| 128 | MortonCopy<false, PixelFormat::ABGR8S>, | 139 | MortonCopy<false, PixelFormat::A8B8G8R8_SNORM>, |
| 129 | MortonCopy<false, PixelFormat::ABGR8UI>, | 140 | MortonCopy<false, PixelFormat::A8B8G8R8_SINT>, |
| 130 | MortonCopy<false, PixelFormat::B5G6R5U>, | 141 | MortonCopy<false, PixelFormat::A8B8G8R8_UINT>, |
| 131 | MortonCopy<false, PixelFormat::A2B10G10R10U>, | 142 | MortonCopy<false, PixelFormat::R5G6B5_UNORM>, |
| 132 | MortonCopy<false, PixelFormat::A1B5G5R5U>, | 143 | MortonCopy<false, PixelFormat::B5G6R5_UNORM>, |
| 133 | MortonCopy<false, PixelFormat::R8U>, | 144 | MortonCopy<false, PixelFormat::A1R5G5B5_UNORM>, |
| 134 | MortonCopy<false, PixelFormat::R8UI>, | 145 | MortonCopy<false, PixelFormat::A2B10G10R10_UNORM>, |
| 135 | MortonCopy<false, PixelFormat::RGBA16F>, | 146 | MortonCopy<false, PixelFormat::A2B10G10R10_UINT>, |
| 136 | MortonCopy<false, PixelFormat::RGBA16S>, | 147 | MortonCopy<false, PixelFormat::A1B5G5R5_UNORM>, |
| 137 | MortonCopy<false, PixelFormat::RGBA16U>, | 148 | MortonCopy<false, PixelFormat::R8_UNORM>, |
| 138 | MortonCopy<false, PixelFormat::RGBA16UI>, | 149 | MortonCopy<false, PixelFormat::R8_SNORM>, |
| 139 | MortonCopy<false, PixelFormat::R11FG11FB10F>, | 150 | MortonCopy<false, PixelFormat::R8_SINT>, |
| 140 | MortonCopy<false, PixelFormat::RGBA32UI>, | 151 | MortonCopy<false, PixelFormat::R8_UINT>, |
| 141 | MortonCopy<false, PixelFormat::DXT1>, | 152 | MortonCopy<false, PixelFormat::R16G16B16A16_FLOAT>, |
| 142 | MortonCopy<false, PixelFormat::DXT23>, | 153 | MortonCopy<false, PixelFormat::R16G16B16A16_SNORM>, |
| 143 | MortonCopy<false, PixelFormat::DXT45>, | 154 | MortonCopy<false, PixelFormat::R16G16B16A16_SINT>, |
| 144 | MortonCopy<false, PixelFormat::DXN1>, | 155 | MortonCopy<false, PixelFormat::R16G16B16A16_UNORM>, |
| 145 | MortonCopy<false, PixelFormat::DXN2UNORM>, | 156 | MortonCopy<false, PixelFormat::R16G16B16A16_UINT>, |
| 146 | MortonCopy<false, PixelFormat::DXN2SNORM>, | 157 | MortonCopy<false, PixelFormat::B10G11R11_FLOAT>, |
| 147 | MortonCopy<false, PixelFormat::BC7U>, | 158 | MortonCopy<false, PixelFormat::R32G32B32A32_UINT>, |
| 148 | MortonCopy<false, PixelFormat::BC6H_UF16>, | 159 | MortonCopy<false, PixelFormat::BC1_RGBA_UNORM>, |
| 149 | MortonCopy<false, PixelFormat::BC6H_SF16>, | 160 | MortonCopy<false, PixelFormat::BC2_UNORM>, |
| 161 | MortonCopy<false, PixelFormat::BC3_UNORM>, | ||
| 162 | MortonCopy<false, PixelFormat::BC4_UNORM>, | ||
| 163 | MortonCopy<false, PixelFormat::BC4_SNORM>, | ||
| 164 | MortonCopy<false, PixelFormat::BC5_UNORM>, | ||
| 165 | MortonCopy<false, PixelFormat::BC5_SNORM>, | ||
| 166 | MortonCopy<false, PixelFormat::BC7_UNORM>, | ||
| 167 | MortonCopy<false, PixelFormat::BC6H_UFLOAT>, | ||
| 168 | MortonCopy<false, PixelFormat::BC6H_SFLOAT>, | ||
| 150 | // TODO(Subv): Swizzling ASTC formats are not supported | 169 | // TODO(Subv): Swizzling ASTC formats are not supported |
| 151 | nullptr, | 170 | nullptr, |
| 152 | MortonCopy<false, PixelFormat::BGRA8>, | 171 | MortonCopy<false, PixelFormat::B8G8R8A8_UNORM>, |
| 153 | MortonCopy<false, PixelFormat::RGBA32F>, | 172 | MortonCopy<false, PixelFormat::R32G32B32A32_FLOAT>, |
| 154 | MortonCopy<false, PixelFormat::RG32F>, | 173 | MortonCopy<false, PixelFormat::R32G32B32A32_SINT>, |
| 155 | MortonCopy<false, PixelFormat::R32F>, | 174 | MortonCopy<false, PixelFormat::R32G32_FLOAT>, |
| 156 | MortonCopy<false, PixelFormat::R16F>, | 175 | MortonCopy<false, PixelFormat::R32G32_SINT>, |
| 157 | MortonCopy<false, PixelFormat::R16U>, | 176 | MortonCopy<false, PixelFormat::R32_FLOAT>, |
| 158 | MortonCopy<false, PixelFormat::R16S>, | 177 | MortonCopy<false, PixelFormat::R16_FLOAT>, |
| 159 | MortonCopy<false, PixelFormat::R16UI>, | 178 | MortonCopy<false, PixelFormat::R16_UNORM>, |
| 160 | MortonCopy<false, PixelFormat::R16I>, | 179 | MortonCopy<false, PixelFormat::R16_SNORM>, |
| 161 | MortonCopy<false, PixelFormat::RG16>, | 180 | MortonCopy<false, PixelFormat::R16_UINT>, |
| 162 | MortonCopy<false, PixelFormat::RG16F>, | 181 | MortonCopy<false, PixelFormat::R16_SINT>, |
| 163 | MortonCopy<false, PixelFormat::RG16UI>, | 182 | MortonCopy<false, PixelFormat::R16G16_UNORM>, |
| 164 | MortonCopy<false, PixelFormat::RG16I>, | 183 | MortonCopy<false, PixelFormat::R16G16_FLOAT>, |
| 165 | MortonCopy<false, PixelFormat::RG16S>, | 184 | MortonCopy<false, PixelFormat::R16G16_UINT>, |
| 166 | MortonCopy<false, PixelFormat::RGB32F>, | 185 | MortonCopy<false, PixelFormat::R16G16_SINT>, |
| 167 | MortonCopy<false, PixelFormat::RGBA8_SRGB>, | 186 | MortonCopy<false, PixelFormat::R16G16_SNORM>, |
| 168 | MortonCopy<false, PixelFormat::RG8U>, | 187 | MortonCopy<false, PixelFormat::R32G32B32_FLOAT>, |
| 169 | MortonCopy<false, PixelFormat::RG8S>, | 188 | MortonCopy<false, PixelFormat::A8B8G8R8_SRGB>, |
| 170 | MortonCopy<false, PixelFormat::RG8UI>, | 189 | MortonCopy<false, PixelFormat::R8G8_UNORM>, |
| 171 | MortonCopy<false, PixelFormat::RG32UI>, | 190 | MortonCopy<false, PixelFormat::R8G8_SNORM>, |
| 172 | MortonCopy<false, PixelFormat::RGBX16F>, | 191 | MortonCopy<false, PixelFormat::R8G8_SINT>, |
| 173 | MortonCopy<false, PixelFormat::R32UI>, | 192 | MortonCopy<false, PixelFormat::R8G8_UINT>, |
| 174 | MortonCopy<false, PixelFormat::R32I>, | 193 | MortonCopy<false, PixelFormat::R32G32_UINT>, |
| 194 | MortonCopy<false, PixelFormat::R16G16B16X16_FLOAT>, | ||
| 195 | MortonCopy<false, PixelFormat::R32_UINT>, | ||
| 196 | MortonCopy<false, PixelFormat::R32_SINT>, | ||
| 175 | nullptr, | 197 | nullptr, |
| 176 | nullptr, | 198 | nullptr, |
| 177 | nullptr, | 199 | nullptr, |
| 178 | MortonCopy<false, PixelFormat::BGRA8_SRGB>, | 200 | MortonCopy<false, PixelFormat::B8G8R8A8_SRGB>, |
| 179 | MortonCopy<false, PixelFormat::DXT1_SRGB>, | 201 | MortonCopy<false, PixelFormat::BC1_RGBA_SRGB>, |
| 180 | MortonCopy<false, PixelFormat::DXT23_SRGB>, | 202 | MortonCopy<false, PixelFormat::BC2_SRGB>, |
| 181 | MortonCopy<false, PixelFormat::DXT45_SRGB>, | 203 | MortonCopy<false, PixelFormat::BC3_SRGB>, |
| 182 | MortonCopy<false, PixelFormat::BC7U_SRGB>, | 204 | MortonCopy<false, PixelFormat::BC7_SRGB>, |
| 183 | MortonCopy<false, PixelFormat::R4G4B4A4U>, | 205 | MortonCopy<false, PixelFormat::A4B4G4R4_UNORM>, |
| 184 | nullptr, | 206 | nullptr, |
| 185 | nullptr, | 207 | nullptr, |
| 186 | nullptr, | 208 | nullptr, |
| @@ -199,12 +221,12 @@ static constexpr ConversionArray linear_to_morton_fns = { | |||
| 199 | nullptr, | 221 | nullptr, |
| 200 | nullptr, | 222 | nullptr, |
| 201 | nullptr, | 223 | nullptr, |
| 202 | MortonCopy<false, PixelFormat::E5B9G9R9F>, | 224 | MortonCopy<false, PixelFormat::E5B9G9R9_FLOAT>, |
| 203 | MortonCopy<false, PixelFormat::Z32F>, | 225 | MortonCopy<false, PixelFormat::D32_FLOAT>, |
| 204 | MortonCopy<false, PixelFormat::Z16>, | 226 | MortonCopy<false, PixelFormat::D16_UNORM>, |
| 205 | MortonCopy<false, PixelFormat::Z24S8>, | 227 | MortonCopy<false, PixelFormat::D24_UNORM_S8_UINT>, |
| 206 | MortonCopy<false, PixelFormat::S8Z24>, | 228 | MortonCopy<false, PixelFormat::S8_UINT_D24_UNORM>, |
| 207 | MortonCopy<false, PixelFormat::Z32FS8>, | 229 | MortonCopy<false, PixelFormat::D32_FLOAT_S8_UINT>, |
| 208 | }; | 230 | }; |
| 209 | 231 | ||
| 210 | static MortonCopyFn GetSwizzleFunction(MortonSwizzleMode mode, Surface::PixelFormat format) { | 232 | static MortonCopyFn GetSwizzleFunction(MortonSwizzleMode mode, Surface::PixelFormat format) { |
diff --git a/src/video_core/renderer_opengl/gl_arb_decompiler.cpp b/src/video_core/renderer_opengl/gl_arb_decompiler.cpp index 4489abf61..b7e9ed2e9 100644 --- a/src/video_core/renderer_opengl/gl_arb_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_arb_decompiler.cpp | |||
| @@ -913,11 +913,19 @@ void ARBDecompiler::DeclareCompute() { | |||
| 913 | const ComputeInfo& info = registry.GetComputeInfo(); | 913 | const ComputeInfo& info = registry.GetComputeInfo(); |
| 914 | AddLine("GROUP_SIZE {} {} {};", info.workgroup_size[0], info.workgroup_size[1], | 914 | AddLine("GROUP_SIZE {} {} {};", info.workgroup_size[0], info.workgroup_size[1], |
| 915 | info.workgroup_size[2]); | 915 | info.workgroup_size[2]); |
| 916 | if (info.shared_memory_size_in_words > 0) { | 916 | if (info.shared_memory_size_in_words == 0) { |
| 917 | const u32 size_in_bytes = info.shared_memory_size_in_words * 4; | 917 | return; |
| 918 | AddLine("SHARED_MEMORY {};", size_in_bytes); | 918 | } |
| 919 | AddLine("SHARED shared_mem[] = {{program.sharedmem}};"); | 919 | const u32 limit = device.GetMaxComputeSharedMemorySize(); |
| 920 | u32 size_in_bytes = info.shared_memory_size_in_words * 4; | ||
| 921 | if (size_in_bytes > limit) { | ||
| 922 | LOG_ERROR(Render_OpenGL, "Shared memory size {} is clamped to host's limit {}", | ||
| 923 | size_in_bytes, limit); | ||
| 924 | size_in_bytes = limit; | ||
| 920 | } | 925 | } |
| 926 | |||
| 927 | AddLine("SHARED_MEMORY {};", size_in_bytes); | ||
| 928 | AddLine("SHARED shared_mem[] = {{program.sharedmem}};"); | ||
| 921 | } | 929 | } |
| 922 | 930 | ||
| 923 | void ARBDecompiler::DeclareInputAttributes() { | 931 | void ARBDecompiler::DeclareInputAttributes() { |
| @@ -1283,13 +1291,6 @@ std::string ARBDecompiler::Visit(const Node& node) { | |||
| 1283 | return "{0, 0, 0, 0}.x"; | 1291 | return "{0, 0, 0, 0}.x"; |
| 1284 | } | 1292 | } |
| 1285 | 1293 | ||
| 1286 | const auto buffer_index = [this, &abuf]() -> std::string { | ||
| 1287 | if (stage != ShaderType::Geometry) { | ||
| 1288 | return ""; | ||
| 1289 | } | ||
| 1290 | return fmt::format("[{}]", Visit(abuf->GetBuffer())); | ||
| 1291 | }; | ||
| 1292 | |||
| 1293 | const Attribute::Index index = abuf->GetIndex(); | 1294 | const Attribute::Index index = abuf->GetIndex(); |
| 1294 | const u32 element = abuf->GetElement(); | 1295 | const u32 element = abuf->GetElement(); |
| 1295 | const char swizzle = Swizzle(element); | 1296 | const char swizzle = Swizzle(element); |
| @@ -1395,7 +1396,7 @@ std::string ARBDecompiler::Visit(const Node& node) { | |||
| 1395 | return {}; | 1396 | return {}; |
| 1396 | } | 1397 | } |
| 1397 | 1398 | ||
| 1398 | if (const auto cmt = std::get_if<CommentNode>(&*node)) { | 1399 | if ([[maybe_unused]] const auto cmt = std::get_if<CommentNode>(&*node)) { |
| 1399 | // Uncommenting this will generate invalid code. GLASM lacks comments. | 1400 | // Uncommenting this will generate invalid code. GLASM lacks comments. |
| 1400 | // AddLine("// {}", cmt->GetText()); | 1401 | // AddLine("// {}", cmt->GetText()); |
| 1401 | return {}; | 1402 | return {}; |
| @@ -1703,7 +1704,7 @@ std::string ARBDecompiler::HCastFloat(Operation operation) { | |||
| 1703 | } | 1704 | } |
| 1704 | 1705 | ||
| 1705 | std::string ARBDecompiler::HUnpack(Operation operation) { | 1706 | std::string ARBDecompiler::HUnpack(Operation operation) { |
| 1706 | const std::string operand = Visit(operation[0]); | 1707 | std::string operand = Visit(operation[0]); |
| 1707 | switch (std::get<Tegra::Shader::HalfType>(operation.GetMeta())) { | 1708 | switch (std::get<Tegra::Shader::HalfType>(operation.GetMeta())) { |
| 1708 | case Tegra::Shader::HalfType::H0_H1: | 1709 | case Tegra::Shader::HalfType::H0_H1: |
| 1709 | return operand; | 1710 | return operand; |
| @@ -2053,7 +2054,7 @@ std::string ARBDecompiler::InvocationId(Operation) { | |||
| 2053 | 2054 | ||
| 2054 | std::string ARBDecompiler::YNegate(Operation) { | 2055 | std::string ARBDecompiler::YNegate(Operation) { |
| 2055 | LOG_WARNING(Render_OpenGL, "(STUBBED)"); | 2056 | LOG_WARNING(Render_OpenGL, "(STUBBED)"); |
| 2056 | const std::string temporary = AllocTemporary(); | 2057 | std::string temporary = AllocTemporary(); |
| 2057 | AddLine("MOV.F {}, 1;", temporary); | 2058 | AddLine("MOV.F {}, 1;", temporary); |
| 2058 | return temporary; | 2059 | return temporary; |
| 2059 | } | 2060 | } |
| @@ -2076,10 +2077,6 @@ std::string ARBDecompiler::ShuffleIndexed(Operation operation) { | |||
| 2076 | } | 2077 | } |
| 2077 | 2078 | ||
| 2078 | std::string ARBDecompiler::Barrier(Operation) { | 2079 | std::string ARBDecompiler::Barrier(Operation) { |
| 2079 | if (!ir.IsDecompiled()) { | ||
| 2080 | LOG_ERROR(Render_OpenGL, "BAR used but shader is not decompiled"); | ||
| 2081 | return {}; | ||
| 2082 | } | ||
| 2083 | AddLine("BAR;"); | 2080 | AddLine("BAR;"); |
| 2084 | return {}; | 2081 | return {}; |
| 2085 | } | 2082 | } |
diff --git a/src/video_core/renderer_opengl/gl_device.cpp b/src/video_core/renderer_opengl/gl_device.cpp index 630acb73b..e7d95149f 100644 --- a/src/video_core/renderer_opengl/gl_device.cpp +++ b/src/video_core/renderer_opengl/gl_device.cpp | |||
| @@ -212,6 +212,7 @@ Device::Device() | |||
| 212 | shader_storage_alignment = GetInteger<std::size_t>(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT); | 212 | shader_storage_alignment = GetInteger<std::size_t>(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT); |
| 213 | max_vertex_attributes = GetInteger<u32>(GL_MAX_VERTEX_ATTRIBS); | 213 | max_vertex_attributes = GetInteger<u32>(GL_MAX_VERTEX_ATTRIBS); |
| 214 | max_varyings = GetInteger<u32>(GL_MAX_VARYING_VECTORS); | 214 | max_varyings = GetInteger<u32>(GL_MAX_VARYING_VECTORS); |
| 215 | max_compute_shared_memory_size = GetInteger<u32>(GL_MAX_COMPUTE_SHARED_MEMORY_SIZE); | ||
| 215 | has_warp_intrinsics = GLAD_GL_NV_gpu_shader5 && GLAD_GL_NV_shader_thread_group && | 216 | has_warp_intrinsics = GLAD_GL_NV_gpu_shader5 && GLAD_GL_NV_shader_thread_group && |
| 216 | GLAD_GL_NV_shader_thread_shuffle; | 217 | GLAD_GL_NV_shader_thread_shuffle; |
| 217 | has_shader_ballot = GLAD_GL_ARB_shader_ballot; | 218 | has_shader_ballot = GLAD_GL_ARB_shader_ballot; |
| @@ -250,6 +251,7 @@ Device::Device(std::nullptr_t) { | |||
| 250 | shader_storage_alignment = 4; | 251 | shader_storage_alignment = 4; |
| 251 | max_vertex_attributes = 16; | 252 | max_vertex_attributes = 16; |
| 252 | max_varyings = 15; | 253 | max_varyings = 15; |
| 254 | max_compute_shared_memory_size = 0x10000; | ||
| 253 | has_warp_intrinsics = true; | 255 | has_warp_intrinsics = true; |
| 254 | has_shader_ballot = true; | 256 | has_shader_ballot = true; |
| 255 | has_vertex_viewport_layer = true; | 257 | has_vertex_viewport_layer = true; |
diff --git a/src/video_core/renderer_opengl/gl_device.h b/src/video_core/renderer_opengl/gl_device.h index 94d38d7d1..8a4b6b9fc 100644 --- a/src/video_core/renderer_opengl/gl_device.h +++ b/src/video_core/renderer_opengl/gl_device.h | |||
| @@ -52,6 +52,10 @@ public: | |||
| 52 | return max_varyings; | 52 | return max_varyings; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | u32 GetMaxComputeSharedMemorySize() const { | ||
| 56 | return max_compute_shared_memory_size; | ||
| 57 | } | ||
| 58 | |||
| 55 | bool HasWarpIntrinsics() const { | 59 | bool HasWarpIntrinsics() const { |
| 56 | return has_warp_intrinsics; | 60 | return has_warp_intrinsics; |
| 57 | } | 61 | } |
| @@ -118,6 +122,7 @@ private: | |||
| 118 | std::size_t shader_storage_alignment{}; | 122 | std::size_t shader_storage_alignment{}; |
| 119 | u32 max_vertex_attributes{}; | 123 | u32 max_vertex_attributes{}; |
| 120 | u32 max_varyings{}; | 124 | u32 max_varyings{}; |
| 125 | u32 max_compute_shared_memory_size{}; | ||
| 121 | bool has_warp_intrinsics{}; | 126 | bool has_warp_intrinsics{}; |
| 122 | bool has_shader_ballot{}; | 127 | bool has_shader_ballot{}; |
| 123 | bool has_vertex_viewport_layer{}; | 128 | bool has_vertex_viewport_layer{}; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 03e82c599..cb284db77 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -178,16 +178,11 @@ RasterizerOpenGL::RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWind | |||
| 178 | 178 | ||
| 179 | if (device.UseAsynchronousShaders()) { | 179 | if (device.UseAsynchronousShaders()) { |
| 180 | // Max worker threads we should allow | 180 | // Max worker threads we should allow |
| 181 | constexpr auto MAX_THREADS = 2u; | 181 | constexpr u32 MAX_THREADS = 4; |
| 182 | // Amount of threads we should reserve for other parts of yuzu | 182 | // Deduce how many threads we can use |
| 183 | constexpr auto RESERVED_THREADS = 6u; | 183 | const u32 threads_used = std::thread::hardware_concurrency() / 4; |
| 184 | // Get the amount of threads we can use(this can return zero) | ||
| 185 | const auto cpu_thread_count = | ||
| 186 | std::max(RESERVED_THREADS, std::thread::hardware_concurrency()); | ||
| 187 | // Deduce how many "extra" threads we have to use. | ||
| 188 | const auto max_threads_unused = cpu_thread_count - RESERVED_THREADS; | ||
| 189 | // Always allow at least 1 thread regardless of our settings | 184 | // Always allow at least 1 thread regardless of our settings |
| 190 | const auto max_worker_count = std::max(1u, max_threads_unused); | 185 | const auto max_worker_count = std::max(1U, threads_used); |
| 191 | // Don't use more than MAX_THREADS | 186 | // Don't use more than MAX_THREADS |
| 192 | const auto worker_count = std::min(max_worker_count, MAX_THREADS); | 187 | const auto worker_count = std::min(max_worker_count, MAX_THREADS); |
| 193 | async_shaders.AllocateWorkers(worker_count); | 188 | async_shaders.AllocateWorkers(worker_count); |
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index f469ed656..be71e1733 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp | |||
| @@ -126,7 +126,7 @@ std::shared_ptr<Registry> MakeRegistry(const ShaderDiskCacheEntry& entry) { | |||
| 126 | const VideoCore::GuestDriverProfile guest_profile{entry.texture_handler_size}; | 126 | const VideoCore::GuestDriverProfile guest_profile{entry.texture_handler_size}; |
| 127 | const VideoCommon::Shader::SerializedRegistryInfo info{guest_profile, entry.bound_buffer, | 127 | const VideoCommon::Shader::SerializedRegistryInfo info{guest_profile, entry.bound_buffer, |
| 128 | entry.graphics_info, entry.compute_info}; | 128 | entry.graphics_info, entry.compute_info}; |
| 129 | const auto registry = std::make_shared<Registry>(entry.type, info); | 129 | auto registry = std::make_shared<Registry>(entry.type, info); |
| 130 | for (const auto& [address, value] : entry.keys) { | 130 | for (const auto& [address, value] : entry.keys) { |
| 131 | const auto [buffer, offset] = address; | 131 | const auto [buffer, offset] = address; |
| 132 | registry->InsertKey(buffer, offset, value); | 132 | registry->InsertKey(buffer, offset, value); |
| @@ -237,7 +237,6 @@ std::unique_ptr<Shader> Shader::CreateStageFromMemory( | |||
| 237 | const ShaderParameters& params, Maxwell::ShaderProgram program_type, ProgramCode code, | 237 | const ShaderParameters& params, Maxwell::ShaderProgram program_type, ProgramCode code, |
| 238 | ProgramCode code_b, VideoCommon::Shader::AsyncShaders& async_shaders, VAddr cpu_addr) { | 238 | ProgramCode code_b, VideoCommon::Shader::AsyncShaders& async_shaders, VAddr cpu_addr) { |
| 239 | const auto shader_type = GetShaderType(program_type); | 239 | const auto shader_type = GetShaderType(program_type); |
| 240 | const std::size_t size_in_bytes = code.size() * sizeof(u64); | ||
| 241 | 240 | ||
| 242 | auto& gpu = params.system.GPU(); | 241 | auto& gpu = params.system.GPU(); |
| 243 | gpu.ShaderNotify().MarkSharderBuilding(); | 242 | gpu.ShaderNotify().MarkSharderBuilding(); |
| @@ -287,8 +286,6 @@ std::unique_ptr<Shader> Shader::CreateStageFromMemory( | |||
| 287 | 286 | ||
| 288 | std::unique_ptr<Shader> Shader::CreateKernelFromMemory(const ShaderParameters& params, | 287 | std::unique_ptr<Shader> Shader::CreateKernelFromMemory(const ShaderParameters& params, |
| 289 | ProgramCode code) { | 288 | ProgramCode code) { |
| 290 | const std::size_t size_in_bytes = code.size() * sizeof(u64); | ||
| 291 | |||
| 292 | auto& gpu = params.system.GPU(); | 289 | auto& gpu = params.system.GPU(); |
| 293 | gpu.ShaderNotify().MarkSharderBuilding(); | 290 | gpu.ShaderNotify().MarkSharderBuilding(); |
| 294 | 291 | ||
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 2c49aeaac..3f75fcd2b 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -602,8 +602,15 @@ private: | |||
| 602 | return; | 602 | return; |
| 603 | } | 603 | } |
| 604 | const auto& info = registry.GetComputeInfo(); | 604 | const auto& info = registry.GetComputeInfo(); |
| 605 | if (const u32 size = info.shared_memory_size_in_words; size > 0) { | 605 | if (u32 size = info.shared_memory_size_in_words * 4; size > 0) { |
| 606 | code.AddLine("shared uint smem[{}];", size); | 606 | const u32 limit = device.GetMaxComputeSharedMemorySize(); |
| 607 | if (size > limit) { | ||
| 608 | LOG_ERROR(Render_OpenGL, "Shared memory size {} is clamped to host's limit {}", | ||
| 609 | size, limit); | ||
| 610 | size = limit; | ||
| 611 | } | ||
| 612 | |||
| 613 | code.AddLine("shared uint smem[{}];", size / 4); | ||
| 607 | code.AddNewLine(); | 614 | code.AddNewLine(); |
| 608 | } | 615 | } |
| 609 | code.AddLine("layout (local_size_x = {}, local_size_y = {}, local_size_z = {}) in;", | 616 | code.AddLine("layout (local_size_x = {}, local_size_y = {}, local_size_z = {}) in;", |
| @@ -1912,7 +1919,7 @@ private: | |||
| 1912 | Expression Comparison(Operation operation) { | 1919 | Expression Comparison(Operation operation) { |
| 1913 | static_assert(!unordered || type == Type::Float); | 1920 | static_assert(!unordered || type == Type::Float); |
| 1914 | 1921 | ||
| 1915 | const Expression expr = GenerateBinaryInfix(operation, op, Type::Bool, type, type); | 1922 | Expression expr = GenerateBinaryInfix(operation, op, Type::Bool, type, type); |
| 1916 | 1923 | ||
| 1917 | if constexpr (op.compare("!=") == 0 && type == Type::Float && !unordered) { | 1924 | if constexpr (op.compare("!=") == 0 && type == Type::Float && !unordered) { |
| 1918 | // GLSL's operator!=(float, float) doesn't seem be ordered. This happens on both AMD's | 1925 | // GLSL's operator!=(float, float) doesn't seem be ordered. This happens on both AMD's |
| @@ -1952,10 +1959,6 @@ private: | |||
| 1952 | return {fmt::format("({} != 0)", carry), Type::Bool}; | 1959 | return {fmt::format("({} != 0)", carry), Type::Bool}; |
| 1953 | } | 1960 | } |
| 1954 | 1961 | ||
| 1955 | Expression LogicalFIsNan(Operation operation) { | ||
| 1956 | return GenerateUnary(operation, "isnan", Type::Bool, Type::Float); | ||
| 1957 | } | ||
| 1958 | |||
| 1959 | Expression LogicalAssign(Operation operation) { | 1962 | Expression LogicalAssign(Operation operation) { |
| 1960 | const Node& dest = operation[0]; | 1963 | const Node& dest = operation[0]; |
| 1961 | const Node& src = operation[1]; | 1964 | const Node& src = operation[1]; |
| @@ -2771,15 +2774,6 @@ private: | |||
| 2771 | return std::min<u32>(device.GetMaxVaryings(), Maxwell::NumVaryings); | 2774 | return std::min<u32>(device.GetMaxVaryings(), Maxwell::NumVaryings); |
| 2772 | } | 2775 | } |
| 2773 | 2776 | ||
| 2774 | bool IsRenderTargetEnabled(u32 render_target) const { | ||
| 2775 | for (u32 component = 0; component < 4; ++component) { | ||
| 2776 | if (header.ps.IsColorComponentOutputEnabled(render_target, component)) { | ||
| 2777 | return true; | ||
| 2778 | } | ||
| 2779 | } | ||
| 2780 | return false; | ||
| 2781 | } | ||
| 2782 | |||
| 2783 | const Device& device; | 2777 | const Device& device; |
| 2784 | const ShaderIR& ir; | 2778 | const ShaderIR& ir; |
| 2785 | const Registry& registry; | 2779 | const Registry& registry; |
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index 61505879b..0a7bc9e2b 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -41,91 +41,103 @@ struct FormatTuple { | |||
| 41 | }; | 41 | }; |
| 42 | 42 | ||
| 43 | constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex_format_tuples = {{ | 43 | constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex_format_tuples = {{ |
| 44 | {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV}, // ABGR8U | 44 | {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV}, // A8B8G8R8_UNORM |
| 45 | {GL_RGBA8_SNORM, GL_RGBA, GL_BYTE}, // ABGR8S | 45 | {GL_RGBA8_SNORM, GL_RGBA, GL_BYTE}, // A8B8G8R8_SNORM |
| 46 | {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, // ABGR8UI | 46 | {GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE}, // A8B8G8R8_SINT |
| 47 | {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV}, // B5G6R5U | 47 | {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, // A8B8G8R8_UINT |
| 48 | {GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV}, // A2B10G10R10U | 48 | {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, // R5G6B5_UNORM |
| 49 | {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // A1B5G5R5U | 49 | {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV}, // B5G6R5_UNORM |
| 50 | {GL_R8, GL_RED, GL_UNSIGNED_BYTE}, // R8U | 50 | {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // A1R5G5B5_UNORM |
| 51 | {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE}, // R8UI | 51 | {GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV}, // A2B10G10R10_UNORM |
| 52 | {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}, // RGBA16F | 52 | {GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV}, // A2B10G10R10_UINT |
| 53 | {GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT}, // RGBA16U | 53 | {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // A1B5G5R5_UNORM |
| 54 | {GL_RGBA16_SNORM, GL_RGBA, GL_SHORT}, // RGBA16S | 54 | {GL_R8, GL_RED, GL_UNSIGNED_BYTE}, // R8_UNORM |
| 55 | {GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT}, // RGBA16UI | 55 | {GL_R8_SNORM, GL_RED, GL_BYTE}, // R8_SNORM |
| 56 | {GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV}, // R11FG11FB10F | 56 | {GL_R8I, GL_RED_INTEGER, GL_BYTE}, // R8_SINT |
| 57 | {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT}, // RGBA32UI | 57 | {GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE}, // R8_UINT |
| 58 | {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT}, // DXT1 | 58 | {GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}, // R16G16B16A16_FLOAT |
| 59 | {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT}, // DXT23 | 59 | {GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT}, // R16G16B16A16_UNORM |
| 60 | {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT}, // DXT45 | 60 | {GL_RGBA16_SNORM, GL_RGBA, GL_SHORT}, // R16G16B16A16_SNORM |
| 61 | {GL_COMPRESSED_RED_RGTC1}, // DXN1 | 61 | {GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT}, // R16G16B16A16_SINT |
| 62 | {GL_COMPRESSED_RG_RGTC2}, // DXN2UNORM | 62 | {GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT}, // R16G16B16A16_UINT |
| 63 | {GL_COMPRESSED_SIGNED_RG_RGTC2}, // DXN2SNORM | 63 | {GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV}, // B10G11R11_FLOAT |
| 64 | {GL_COMPRESSED_RGBA_BPTC_UNORM}, // BC7U | 64 | {GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT}, // R32G32B32A32_UINT |
| 65 | {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT}, // BC6H_UF16 | 65 | {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT}, // BC1_RGBA_UNORM |
| 66 | {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT}, // BC6H_SF16 | 66 | {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT}, // BC2_UNORM |
| 67 | {GL_COMPRESSED_RGBA_ASTC_4x4_KHR}, // ASTC_2D_4X4 | 67 | {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT}, // BC3_UNORM |
| 68 | {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}, // BGRA8 | 68 | {GL_COMPRESSED_RED_RGTC1}, // BC4_UNORM |
| 69 | {GL_RGBA32F, GL_RGBA, GL_FLOAT}, // RGBA32F | 69 | {GL_COMPRESSED_SIGNED_RED_RGTC1}, // BC4_SNORM |
| 70 | {GL_RG32F, GL_RG, GL_FLOAT}, // RG32F | 70 | {GL_COMPRESSED_RG_RGTC2}, // BC5_UNORM |
| 71 | {GL_R32F, GL_RED, GL_FLOAT}, // R32F | 71 | {GL_COMPRESSED_SIGNED_RG_RGTC2}, // BC5_SNORM |
| 72 | {GL_R16F, GL_RED, GL_HALF_FLOAT}, // R16F | 72 | {GL_COMPRESSED_RGBA_BPTC_UNORM}, // BC7_UNORM |
| 73 | {GL_R16, GL_RED, GL_UNSIGNED_SHORT}, // R16U | 73 | {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT}, // BC6H_UFLOAT |
| 74 | {GL_R16_SNORM, GL_RED, GL_SHORT}, // R16S | 74 | {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT}, // BC6H_SFLOAT |
| 75 | {GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT}, // R16UI | 75 | {GL_COMPRESSED_RGBA_ASTC_4x4_KHR}, // ASTC_2D_4X4_UNORM |
| 76 | {GL_R16I, GL_RED_INTEGER, GL_SHORT}, // R16I | 76 | {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}, // B8G8R8A8_UNORM |
| 77 | {GL_RG16, GL_RG, GL_UNSIGNED_SHORT}, // RG16 | 77 | {GL_RGBA32F, GL_RGBA, GL_FLOAT}, // R32G32B32A32_FLOAT |
| 78 | {GL_RG16F, GL_RG, GL_HALF_FLOAT}, // RG16F | 78 | {GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, // R32G32B32A32_SINT |
| 79 | {GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT}, // RG16UI | 79 | {GL_RG32F, GL_RG, GL_FLOAT}, // R32G32_FLOAT |
| 80 | {GL_RG16I, GL_RG_INTEGER, GL_SHORT}, // RG16I | 80 | {GL_RG32I, GL_RG_INTEGER, GL_INT}, // R32G32_SINT |
| 81 | {GL_RG16_SNORM, GL_RG, GL_SHORT}, // RG16S | 81 | {GL_R32F, GL_RED, GL_FLOAT}, // R32_FLOAT |
| 82 | {GL_RGB32F, GL_RGB, GL_FLOAT}, // RGB32F | 82 | {GL_R16F, GL_RED, GL_HALF_FLOAT}, // R16_FLOAT |
| 83 | {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV}, // RGBA8_SRGB | 83 | {GL_R16, GL_RED, GL_UNSIGNED_SHORT}, // R16_UNORM |
| 84 | {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}, // RG8U | 84 | {GL_R16_SNORM, GL_RED, GL_SHORT}, // R16_SNORM |
| 85 | {GL_RG8_SNORM, GL_RG, GL_BYTE}, // RG8S | 85 | {GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT}, // R16_UINT |
| 86 | {GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_INT}, // RG8UI | 86 | {GL_R16I, GL_RED_INTEGER, GL_SHORT}, // R16_SINT |
| 87 | {GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT}, // RG32UI | 87 | {GL_RG16, GL_RG, GL_UNSIGNED_SHORT}, // R16G16_UNORM |
| 88 | {GL_RGB16F, GL_RGBA, GL_HALF_FLOAT}, // RGBX16F | 88 | {GL_RG16F, GL_RG, GL_HALF_FLOAT}, // R16G16_FLOAT |
| 89 | {GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT}, // R32UI | 89 | {GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT}, // R16G16_UINT |
| 90 | {GL_R32I, GL_RED_INTEGER, GL_INT}, // R32I | 90 | {GL_RG16I, GL_RG_INTEGER, GL_SHORT}, // R16G16_SINT |
| 91 | {GL_COMPRESSED_RGBA_ASTC_8x8_KHR}, // ASTC_2D_8X8 | 91 | {GL_RG16_SNORM, GL_RG, GL_SHORT}, // R16G16_SNORM |
| 92 | {GL_COMPRESSED_RGBA_ASTC_8x5_KHR}, // ASTC_2D_8X5 | 92 | {GL_RGB32F, GL_RGB, GL_FLOAT}, // R32G32B32_FLOAT |
| 93 | {GL_COMPRESSED_RGBA_ASTC_5x4_KHR}, // ASTC_2D_5X4 | 93 | {GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV}, // A8B8G8R8_SRGB |
| 94 | {GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE}, // BGRA8 | 94 | {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}, // R8G8_UNORM |
| 95 | {GL_RG8_SNORM, GL_RG, GL_BYTE}, // R8G8_SNORM | ||
| 96 | {GL_RG8I, GL_RG_INTEGER, GL_BYTE}, // R8G8_SINT | ||
| 97 | {GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE}, // R8G8_UINT | ||
| 98 | {GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT}, // R32G32_UINT | ||
| 99 | {GL_RGB16F, GL_RGBA, GL_HALF_FLOAT}, // R16G16B16X16_FLOAT | ||
| 100 | {GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT}, // R32_UINT | ||
| 101 | {GL_R32I, GL_RED_INTEGER, GL_INT}, // R32_SINT | ||
| 102 | {GL_COMPRESSED_RGBA_ASTC_8x8_KHR}, // ASTC_2D_8X8_UNORM | ||
| 103 | {GL_COMPRESSED_RGBA_ASTC_8x5_KHR}, // ASTC_2D_8X5_UNORM | ||
| 104 | {GL_COMPRESSED_RGBA_ASTC_5x4_KHR}, // ASTC_2D_5X4_UNORM | ||
| 105 | {GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE}, // B8G8R8A8_UNORM | ||
| 95 | // Compressed sRGB formats | 106 | // Compressed sRGB formats |
| 96 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT}, // DXT1_SRGB | 107 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT}, // BC1_RGBA_SRGB |
| 97 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT}, // DXT23_SRGB | 108 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT}, // BC2_SRGB |
| 98 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}, // DXT45_SRGB | 109 | {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}, // BC3_SRGB |
| 99 | {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM}, // BC7U_SRGB | 110 | {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM}, // BC7_SRGB |
| 100 | {GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV}, // R4G4B4A4U | 111 | {GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV}, // A4B4G4R4_UNORM |
| 101 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR}, // ASTC_2D_4X4_SRGB | 112 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR}, // ASTC_2D_4X4_SRGB |
| 102 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR}, // ASTC_2D_8X8_SRGB | 113 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR}, // ASTC_2D_8X8_SRGB |
| 103 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR}, // ASTC_2D_8X5_SRGB | 114 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR}, // ASTC_2D_8X5_SRGB |
| 104 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR}, // ASTC_2D_5X4_SRGB | 115 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR}, // ASTC_2D_5X4_SRGB |
| 105 | {GL_COMPRESSED_RGBA_ASTC_5x5_KHR}, // ASTC_2D_5X5 | 116 | {GL_COMPRESSED_RGBA_ASTC_5x5_KHR}, // ASTC_2D_5X5_UNORM |
| 106 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR}, // ASTC_2D_5X5_SRGB | 117 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR}, // ASTC_2D_5X5_SRGB |
| 107 | {GL_COMPRESSED_RGBA_ASTC_10x8_KHR}, // ASTC_2D_10X8 | 118 | {GL_COMPRESSED_RGBA_ASTC_10x8_KHR}, // ASTC_2D_10X8_UNORM |
| 108 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR}, // ASTC_2D_10X8_SRGB | 119 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR}, // ASTC_2D_10X8_SRGB |
| 109 | {GL_COMPRESSED_RGBA_ASTC_6x6_KHR}, // ASTC_2D_6X6 | 120 | {GL_COMPRESSED_RGBA_ASTC_6x6_KHR}, // ASTC_2D_6X6_UNORM |
| 110 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR}, // ASTC_2D_6X6_SRGB | 121 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR}, // ASTC_2D_6X6_SRGB |
| 111 | {GL_COMPRESSED_RGBA_ASTC_10x10_KHR}, // ASTC_2D_10X10 | 122 | {GL_COMPRESSED_RGBA_ASTC_10x10_KHR}, // ASTC_2D_10X10_UNORM |
| 112 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR}, // ASTC_2D_10X10_SRGB | 123 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR}, // ASTC_2D_10X10_SRGB |
| 113 | {GL_COMPRESSED_RGBA_ASTC_12x12_KHR}, // ASTC_2D_12X12 | 124 | {GL_COMPRESSED_RGBA_ASTC_12x12_KHR}, // ASTC_2D_12X12_UNORM |
| 114 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR}, // ASTC_2D_12X12_SRGB | 125 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR}, // ASTC_2D_12X12_SRGB |
| 115 | {GL_COMPRESSED_RGBA_ASTC_8x6_KHR}, // ASTC_2D_8X6 | 126 | {GL_COMPRESSED_RGBA_ASTC_8x6_KHR}, // ASTC_2D_8X6_UNORM |
| 116 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR}, // ASTC_2D_8X6_SRGB | 127 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR}, // ASTC_2D_8X6_SRGB |
| 117 | {GL_COMPRESSED_RGBA_ASTC_6x5_KHR}, // ASTC_2D_6X5 | 128 | {GL_COMPRESSED_RGBA_ASTC_6x5_KHR}, // ASTC_2D_6X5_UNORM |
| 118 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR}, // ASTC_2D_6X5_SRGB | 129 | {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR}, // ASTC_2D_6X5_SRGB |
| 119 | {GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV}, // E5B9G9R9F | 130 | {GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV}, // E5B9G9R9_FLOAT |
| 120 | 131 | ||
| 121 | // Depth formats | 132 | // Depth formats |
| 122 | {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT}, // Z32F | 133 | {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT}, // D32_FLOAT |
| 123 | {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, // Z16 | 134 | {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}, // D16_UNORM |
| 124 | 135 | ||
| 125 | // DepthStencil formats | 136 | // DepthStencil formats |
| 126 | {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, // Z24S8 | 137 | {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, // D24_UNORM_S8_UINT |
| 127 | {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, // S8Z24 | 138 | {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8}, // S8_UINT_D24_UNORM |
| 128 | {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, // Z32FS8 | 139 | {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, |
| 140 | GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, // D32_FLOAT_S8_UINT | ||
| 129 | }}; | 141 | }}; |
| 130 | 142 | ||
| 131 | const FormatTuple& GetFormatTuple(PixelFormat pixel_format) { | 143 | const FormatTuple& GetFormatTuple(PixelFormat pixel_format) { |
| @@ -178,10 +190,10 @@ GLint GetSwizzleSource(SwizzleSource source) { | |||
| 178 | 190 | ||
| 179 | GLenum GetComponent(PixelFormat format, bool is_first) { | 191 | GLenum GetComponent(PixelFormat format, bool is_first) { |
| 180 | switch (format) { | 192 | switch (format) { |
| 181 | case PixelFormat::Z24S8: | 193 | case PixelFormat::D24_UNORM_S8_UINT: |
| 182 | case PixelFormat::Z32FS8: | 194 | case PixelFormat::D32_FLOAT_S8_UINT: |
| 183 | return is_first ? GL_DEPTH_COMPONENT : GL_STENCIL_INDEX; | 195 | return is_first ? GL_DEPTH_COMPONENT : GL_STENCIL_INDEX; |
| 184 | case PixelFormat::S8Z24: | 196 | case PixelFormat::S8_UINT_D24_UNORM: |
| 185 | return is_first ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT; | 197 | return is_first ? GL_STENCIL_INDEX : GL_DEPTH_COMPONENT; |
| 186 | default: | 198 | default: |
| 187 | UNREACHABLE(); | 199 | UNREACHABLE(); |
| @@ -482,9 +494,9 @@ GLuint CachedSurfaceView::GetTexture(SwizzleSource x_source, SwizzleSource y_sou | |||
| 482 | std::array swizzle{x_source, y_source, z_source, w_source}; | 494 | std::array swizzle{x_source, y_source, z_source, w_source}; |
| 483 | 495 | ||
| 484 | switch (const PixelFormat format = GetSurfaceParams().pixel_format) { | 496 | switch (const PixelFormat format = GetSurfaceParams().pixel_format) { |
| 485 | case PixelFormat::Z24S8: | 497 | case PixelFormat::D24_UNORM_S8_UINT: |
| 486 | case PixelFormat::Z32FS8: | 498 | case PixelFormat::D32_FLOAT_S8_UINT: |
| 487 | case PixelFormat::S8Z24: | 499 | case PixelFormat::S8_UINT_D24_UNORM: |
| 488 | UNIMPLEMENTED_IF(x_source != SwizzleSource::R && x_source != SwizzleSource::G); | 500 | UNIMPLEMENTED_IF(x_source != SwizzleSource::R && x_source != SwizzleSource::G); |
| 489 | glTextureParameteri(view.handle, GL_DEPTH_STENCIL_TEXTURE_MODE, | 501 | glTextureParameteri(view.handle, GL_DEPTH_STENCIL_TEXTURE_MODE, |
| 490 | GetComponent(format, x_source == SwizzleSource::R)); | 502 | GetComponent(format, x_source == SwizzleSource::R)); |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index e66cdc083..52e9e8250 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -535,12 +535,12 @@ void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture, | |||
| 535 | 535 | ||
| 536 | GLint internal_format; | 536 | GLint internal_format; |
| 537 | switch (framebuffer.pixel_format) { | 537 | switch (framebuffer.pixel_format) { |
| 538 | case Tegra::FramebufferConfig::PixelFormat::ABGR8: | 538 | case Tegra::FramebufferConfig::PixelFormat::A8B8G8R8_UNORM: |
| 539 | internal_format = GL_RGBA8; | 539 | internal_format = GL_RGBA8; |
| 540 | texture.gl_format = GL_RGBA; | 540 | texture.gl_format = GL_RGBA; |
| 541 | texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV; | 541 | texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV; |
| 542 | break; | 542 | break; |
| 543 | case Tegra::FramebufferConfig::PixelFormat::RGB565: | 543 | case Tegra::FramebufferConfig::PixelFormat::RGB565_UNORM: |
| 544 | internal_format = GL_RGB565; | 544 | internal_format = GL_RGB565; |
| 545 | texture.gl_format = GL_RGB; | 545 | texture.gl_format = GL_RGB; |
| 546 | texture.gl_type = GL_UNSIGNED_SHORT_5_6_5; | 546 | texture.gl_type = GL_UNSIGNED_SHORT_5_6_5; |
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp index d1f0ea932..81a39a3b8 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp | |||
| @@ -40,7 +40,6 @@ constexpr std::array POLYGON_OFFSET_ENABLE_LUT = { | |||
| 40 | } // Anonymous namespace | 40 | } // Anonymous namespace |
| 41 | 41 | ||
| 42 | void FixedPipelineState::Fill(const Maxwell& regs, bool has_extended_dynamic_state) { | 42 | void FixedPipelineState::Fill(const Maxwell& regs, bool has_extended_dynamic_state) { |
| 43 | const auto& clip = regs.view_volume_clip_control; | ||
| 44 | const std::array enabled_lut = {regs.polygon_offset_point_enable, | 43 | const std::array enabled_lut = {regs.polygon_offset_point_enable, |
| 45 | regs.polygon_offset_line_enable, | 44 | regs.polygon_offset_line_enable, |
| 46 | regs.polygon_offset_fill_enable}; | 45 | regs.polygon_offset_fill_enable}; |
diff --git a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp index d7f1ae89f..f8c77f4fa 100644 --- a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp +++ b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp | |||
| @@ -117,90 +117,101 @@ struct FormatTuple { | |||
| 117 | VkFormat format; ///< Vulkan format | 117 | VkFormat format; ///< Vulkan format |
| 118 | int usage = 0; ///< Describes image format usage | 118 | int usage = 0; ///< Describes image format usage |
| 119 | } constexpr tex_format_tuples[] = { | 119 | } constexpr tex_format_tuples[] = { |
| 120 | {VK_FORMAT_A8B8G8R8_UNORM_PACK32, Attachable | Storage}, // ABGR8U | 120 | {VK_FORMAT_A8B8G8R8_UNORM_PACK32, Attachable | Storage}, // A8B8G8R8_UNORM |
| 121 | {VK_FORMAT_A8B8G8R8_SNORM_PACK32, Attachable | Storage}, // ABGR8S | 121 | {VK_FORMAT_A8B8G8R8_SNORM_PACK32, Attachable | Storage}, // A8B8G8R8_SNORM |
| 122 | {VK_FORMAT_A8B8G8R8_UINT_PACK32, Attachable | Storage}, // ABGR8UI | 122 | {VK_FORMAT_A8B8G8R8_SINT_PACK32, Attachable | Storage}, // A8B8G8R8_SINT |
| 123 | {VK_FORMAT_B5G6R5_UNORM_PACK16}, // B5G6R5U | 123 | {VK_FORMAT_A8B8G8R8_UINT_PACK32, Attachable | Storage}, // A8B8G8R8_UINT |
| 124 | {VK_FORMAT_A2B10G10R10_UNORM_PACK32, Attachable | Storage}, // A2B10G10R10U | 124 | {VK_FORMAT_R5G6B5_UNORM_PACK16, Attachable}, // R5G6B5_UNORM |
| 125 | {VK_FORMAT_A1R5G5B5_UNORM_PACK16, Attachable}, // A1B5G5R5U (flipped with swizzle) | 125 | {VK_FORMAT_B5G6R5_UNORM_PACK16, Attachable}, // B5G6R5_UNORM |
| 126 | {VK_FORMAT_R8_UNORM, Attachable | Storage}, // R8U | 126 | {VK_FORMAT_A1R5G5B5_UNORM_PACK16, Attachable}, // A1R5G5B5_UNORM |
| 127 | {VK_FORMAT_R8_UINT, Attachable | Storage}, // R8UI | 127 | {VK_FORMAT_A2B10G10R10_UNORM_PACK32, Attachable | Storage}, // A2B10G10R10_UNORM |
| 128 | {VK_FORMAT_R16G16B16A16_SFLOAT, Attachable | Storage}, // RGBA16F | 128 | {VK_FORMAT_A2B10G10R10_UINT_PACK32, Attachable | Storage}, // A2B10G10R10_UINT |
| 129 | {VK_FORMAT_R16G16B16A16_UNORM, Attachable | Storage}, // RGBA16U | 129 | {VK_FORMAT_A1R5G5B5_UNORM_PACK16, Attachable}, // A1B5G5R5_UNORM (flipped with swizzle) |
| 130 | {VK_FORMAT_R16G16B16A16_SNORM, Attachable | Storage}, // RGBA16S | 130 | {VK_FORMAT_R8_UNORM, Attachable | Storage}, // R8_UNORM |
| 131 | {VK_FORMAT_R16G16B16A16_UINT, Attachable | Storage}, // RGBA16UI | 131 | {VK_FORMAT_R8_SNORM, Attachable | Storage}, // R8_SNORM |
| 132 | {VK_FORMAT_B10G11R11_UFLOAT_PACK32, Attachable | Storage}, // R11FG11FB10F | 132 | {VK_FORMAT_R8_SINT, Attachable | Storage}, // R8_SINT |
| 133 | {VK_FORMAT_R32G32B32A32_UINT, Attachable | Storage}, // RGBA32UI | 133 | {VK_FORMAT_R8_UINT, Attachable | Storage}, // R8_UINT |
| 134 | {VK_FORMAT_BC1_RGBA_UNORM_BLOCK}, // DXT1 | 134 | {VK_FORMAT_R16G16B16A16_SFLOAT, Attachable | Storage}, // R16G16B16A16_FLOAT |
| 135 | {VK_FORMAT_BC2_UNORM_BLOCK}, // DXT23 | 135 | {VK_FORMAT_R16G16B16A16_UNORM, Attachable | Storage}, // R16G16B16A16_UNORM |
| 136 | {VK_FORMAT_BC3_UNORM_BLOCK}, // DXT45 | 136 | {VK_FORMAT_R16G16B16A16_SNORM, Attachable | Storage}, // R16G16B16A16_SNORM |
| 137 | {VK_FORMAT_BC4_UNORM_BLOCK}, // DXN1 | 137 | {VK_FORMAT_R16G16B16A16_SINT, Attachable | Storage}, // R16G16B16A16_SINT |
| 138 | {VK_FORMAT_BC5_UNORM_BLOCK}, // DXN2UNORM | 138 | {VK_FORMAT_R16G16B16A16_UINT, Attachable | Storage}, // R16G16B16A16_UINT |
| 139 | {VK_FORMAT_BC5_SNORM_BLOCK}, // DXN2SNORM | 139 | {VK_FORMAT_B10G11R11_UFLOAT_PACK32, Attachable | Storage}, // B10G11R11_FLOAT |
| 140 | {VK_FORMAT_BC7_UNORM_BLOCK}, // BC7U | 140 | {VK_FORMAT_R32G32B32A32_UINT, Attachable | Storage}, // R32G32B32A32_UINT |
| 141 | {VK_FORMAT_BC6H_UFLOAT_BLOCK}, // BC6H_UF16 | 141 | {VK_FORMAT_BC1_RGBA_UNORM_BLOCK}, // BC1_RGBA_UNORM |
| 142 | {VK_FORMAT_BC6H_SFLOAT_BLOCK}, // BC6H_SF16 | 142 | {VK_FORMAT_BC2_UNORM_BLOCK}, // BC2_UNORM |
| 143 | {VK_FORMAT_ASTC_4x4_UNORM_BLOCK}, // ASTC_2D_4X4 | 143 | {VK_FORMAT_BC3_UNORM_BLOCK}, // BC3_UNORM |
| 144 | {VK_FORMAT_B8G8R8A8_UNORM, Attachable}, // BGRA8 | 144 | {VK_FORMAT_BC4_UNORM_BLOCK}, // BC4_UNORM |
| 145 | {VK_FORMAT_R32G32B32A32_SFLOAT, Attachable | Storage}, // RGBA32F | 145 | {VK_FORMAT_BC4_SNORM_BLOCK}, // BC4_SNORM |
| 146 | {VK_FORMAT_R32G32_SFLOAT, Attachable | Storage}, // RG32F | 146 | {VK_FORMAT_BC5_UNORM_BLOCK}, // BC5_UNORM |
| 147 | {VK_FORMAT_R32_SFLOAT, Attachable | Storage}, // R32F | 147 | {VK_FORMAT_BC5_SNORM_BLOCK}, // BC5_SNORM |
| 148 | {VK_FORMAT_R16_SFLOAT, Attachable | Storage}, // R16F | 148 | {VK_FORMAT_BC7_UNORM_BLOCK}, // BC7_UNORM |
| 149 | {VK_FORMAT_R16_UNORM, Attachable | Storage}, // R16U | 149 | {VK_FORMAT_BC6H_UFLOAT_BLOCK}, // BC6H_UFLOAT |
| 150 | {VK_FORMAT_UNDEFINED}, // R16S | 150 | {VK_FORMAT_BC6H_SFLOAT_BLOCK}, // BC6H_SFLOAT |
| 151 | {VK_FORMAT_R16_UINT, Attachable | Storage}, // R16UI | 151 | {VK_FORMAT_ASTC_4x4_UNORM_BLOCK}, // ASTC_2D_4X4_UNORM |
| 152 | {VK_FORMAT_UNDEFINED}, // R16I | 152 | {VK_FORMAT_B8G8R8A8_UNORM, Attachable}, // B8G8R8A8_UNORM |
| 153 | {VK_FORMAT_R16G16_UNORM, Attachable | Storage}, // RG16 | 153 | {VK_FORMAT_R32G32B32A32_SFLOAT, Attachable | Storage}, // R32G32B32A32_FLOAT |
| 154 | {VK_FORMAT_R16G16_SFLOAT, Attachable | Storage}, // RG16F | 154 | {VK_FORMAT_R32G32B32A32_SINT, Attachable | Storage}, // R32G32B32A32_SINT |
| 155 | {VK_FORMAT_UNDEFINED}, // RG16UI | 155 | {VK_FORMAT_R32G32_SFLOAT, Attachable | Storage}, // R32G32_FLOAT |
| 156 | {VK_FORMAT_UNDEFINED}, // RG16I | 156 | {VK_FORMAT_R32G32_SINT, Attachable | Storage}, // R32G32_SINT |
| 157 | {VK_FORMAT_R16G16_SNORM, Attachable | Storage}, // RG16S | 157 | {VK_FORMAT_R32_SFLOAT, Attachable | Storage}, // R32_FLOAT |
| 158 | {VK_FORMAT_UNDEFINED}, // RGB32F | 158 | {VK_FORMAT_R16_SFLOAT, Attachable | Storage}, // R16_FLOAT |
| 159 | {VK_FORMAT_R8G8B8A8_SRGB, Attachable}, // RGBA8_SRGB | 159 | {VK_FORMAT_R16_UNORM, Attachable | Storage}, // R16_UNORM |
| 160 | {VK_FORMAT_R8G8_UNORM, Attachable | Storage}, // RG8U | 160 | {VK_FORMAT_UNDEFINED}, // R16_SNORM |
| 161 | {VK_FORMAT_R8G8_SNORM, Attachable | Storage}, // RG8S | 161 | {VK_FORMAT_R16_UINT, Attachable | Storage}, // R16_UINT |
| 162 | {VK_FORMAT_R8G8_UINT, Attachable | Storage}, // RG8UI | 162 | {VK_FORMAT_UNDEFINED}, // R16_SINT |
| 163 | {VK_FORMAT_R32G32_UINT, Attachable | Storage}, // RG32UI | 163 | {VK_FORMAT_R16G16_UNORM, Attachable | Storage}, // R16G16_UNORM |
| 164 | {VK_FORMAT_UNDEFINED}, // RGBX16F | 164 | {VK_FORMAT_R16G16_SFLOAT, Attachable | Storage}, // R16G16_FLOAT |
| 165 | {VK_FORMAT_R32_UINT, Attachable | Storage}, // R32UI | 165 | {VK_FORMAT_UNDEFINED}, // R16G16_UINT |
| 166 | {VK_FORMAT_R32_SINT, Attachable | Storage}, // R32I | 166 | {VK_FORMAT_UNDEFINED}, // R16G16_SINT |
| 167 | {VK_FORMAT_ASTC_8x8_UNORM_BLOCK}, // ASTC_2D_8X8 | 167 | {VK_FORMAT_R16G16_SNORM, Attachable | Storage}, // R16G16_SNORM |
| 168 | {VK_FORMAT_UNDEFINED}, // ASTC_2D_8X5 | 168 | {VK_FORMAT_UNDEFINED}, // R32G32B32_FLOAT |
| 169 | {VK_FORMAT_UNDEFINED}, // ASTC_2D_5X4 | 169 | {VK_FORMAT_R8G8B8A8_SRGB, Attachable}, // A8B8G8R8_SRGB |
| 170 | {VK_FORMAT_B8G8R8A8_SRGB, Attachable}, // BGRA8_SRGB | 170 | {VK_FORMAT_R8G8_UNORM, Attachable | Storage}, // R8G8_UNORM |
| 171 | {VK_FORMAT_BC1_RGBA_SRGB_BLOCK}, // DXT1_SRGB | 171 | {VK_FORMAT_R8G8_SNORM, Attachable | Storage}, // R8G8_SNORM |
| 172 | {VK_FORMAT_BC2_SRGB_BLOCK}, // DXT23_SRGB | 172 | {VK_FORMAT_R8G8_SINT, Attachable | Storage}, // R8G8_SINT |
| 173 | {VK_FORMAT_BC3_SRGB_BLOCK}, // DXT45_SRGB | 173 | {VK_FORMAT_R8G8_UINT, Attachable | Storage}, // R8G8_UINT |
| 174 | {VK_FORMAT_BC7_SRGB_BLOCK}, // BC7U_SRGB | 174 | {VK_FORMAT_R32G32_UINT, Attachable | Storage}, // R32G32_UINT |
| 175 | {VK_FORMAT_R4G4B4A4_UNORM_PACK16, Attachable}, // R4G4B4A4U | 175 | {VK_FORMAT_UNDEFINED}, // R16G16B16X16_FLOAT |
| 176 | {VK_FORMAT_ASTC_4x4_SRGB_BLOCK}, // ASTC_2D_4X4_SRGB | 176 | {VK_FORMAT_R32_UINT, Attachable | Storage}, // R32_UINT |
| 177 | {VK_FORMAT_ASTC_8x8_SRGB_BLOCK}, // ASTC_2D_8X8_SRGB | 177 | {VK_FORMAT_R32_SINT, Attachable | Storage}, // R32_SINT |
| 178 | {VK_FORMAT_ASTC_8x5_SRGB_BLOCK}, // ASTC_2D_8X5_SRGB | 178 | {VK_FORMAT_ASTC_8x8_UNORM_BLOCK}, // ASTC_2D_8X8_UNORM |
| 179 | {VK_FORMAT_ASTC_5x4_SRGB_BLOCK}, // ASTC_2D_5X4_SRGB | 179 | {VK_FORMAT_UNDEFINED}, // ASTC_2D_8X5_UNORM |
| 180 | {VK_FORMAT_ASTC_5x5_UNORM_BLOCK}, // ASTC_2D_5X5 | 180 | {VK_FORMAT_UNDEFINED}, // ASTC_2D_5X4_UNORM |
| 181 | {VK_FORMAT_ASTC_5x5_SRGB_BLOCK}, // ASTC_2D_5X5_SRGB | 181 | {VK_FORMAT_B8G8R8A8_SRGB, Attachable}, // B8G8R8A8_SRGB |
| 182 | {VK_FORMAT_ASTC_10x8_UNORM_BLOCK}, // ASTC_2D_10X8 | 182 | {VK_FORMAT_BC1_RGBA_SRGB_BLOCK}, // BC1_RGBA_SRGB |
| 183 | {VK_FORMAT_ASTC_10x8_SRGB_BLOCK}, // ASTC_2D_10X8_SRGB | 183 | {VK_FORMAT_BC2_SRGB_BLOCK}, // BC2_SRGB |
| 184 | {VK_FORMAT_ASTC_6x6_UNORM_BLOCK}, // ASTC_2D_6X6 | 184 | {VK_FORMAT_BC3_SRGB_BLOCK}, // BC3_SRGB |
| 185 | {VK_FORMAT_ASTC_6x6_SRGB_BLOCK}, // ASTC_2D_6X6_SRGB | 185 | {VK_FORMAT_BC7_SRGB_BLOCK}, // BC7_SRGB |
| 186 | {VK_FORMAT_ASTC_10x10_UNORM_BLOCK}, // ASTC_2D_10X10 | 186 | {VK_FORMAT_R4G4B4A4_UNORM_PACK16, Attachable}, // A4B4G4R4_UNORM |
| 187 | {VK_FORMAT_ASTC_10x10_SRGB_BLOCK}, // ASTC_2D_10X10_SRGB | 187 | {VK_FORMAT_ASTC_4x4_SRGB_BLOCK}, // ASTC_2D_4X4_SRGB |
| 188 | {VK_FORMAT_ASTC_12x12_UNORM_BLOCK}, // ASTC_2D_12X12 | 188 | {VK_FORMAT_ASTC_8x8_SRGB_BLOCK}, // ASTC_2D_8X8_SRGB |
| 189 | {VK_FORMAT_ASTC_12x12_SRGB_BLOCK}, // ASTC_2D_12X12_SRGB | 189 | {VK_FORMAT_ASTC_8x5_SRGB_BLOCK}, // ASTC_2D_8X5_SRGB |
| 190 | {VK_FORMAT_ASTC_8x6_UNORM_BLOCK}, // ASTC_2D_8X6 | 190 | {VK_FORMAT_ASTC_5x4_SRGB_BLOCK}, // ASTC_2D_5X4_SRGB |
| 191 | {VK_FORMAT_ASTC_8x6_SRGB_BLOCK}, // ASTC_2D_8X6_SRGB | 191 | {VK_FORMAT_ASTC_5x5_UNORM_BLOCK}, // ASTC_2D_5X5_UNORM |
| 192 | {VK_FORMAT_ASTC_6x5_UNORM_BLOCK}, // ASTC_2D_6X5 | 192 | {VK_FORMAT_ASTC_5x5_SRGB_BLOCK}, // ASTC_2D_5X5_SRGB |
| 193 | {VK_FORMAT_ASTC_6x5_SRGB_BLOCK}, // ASTC_2D_6X5_SRGB | 193 | {VK_FORMAT_ASTC_10x8_UNORM_BLOCK}, // ASTC_2D_10X8_UNORM |
| 194 | {VK_FORMAT_E5B9G9R9_UFLOAT_PACK32}, // E5B9G9R9F | 194 | {VK_FORMAT_ASTC_10x8_SRGB_BLOCK}, // ASTC_2D_10X8_SRGB |
| 195 | {VK_FORMAT_ASTC_6x6_UNORM_BLOCK}, // ASTC_2D_6X6_UNORM | ||
| 196 | {VK_FORMAT_ASTC_6x6_SRGB_BLOCK}, // ASTC_2D_6X6_SRGB | ||
| 197 | {VK_FORMAT_ASTC_10x10_UNORM_BLOCK}, // ASTC_2D_10X10_UNORM | ||
| 198 | {VK_FORMAT_ASTC_10x10_SRGB_BLOCK}, // ASTC_2D_10X10_SRGB | ||
| 199 | {VK_FORMAT_ASTC_12x12_UNORM_BLOCK}, // ASTC_2D_12X12_UNORM | ||
| 200 | {VK_FORMAT_ASTC_12x12_SRGB_BLOCK}, // ASTC_2D_12X12_SRGB | ||
| 201 | {VK_FORMAT_ASTC_8x6_UNORM_BLOCK}, // ASTC_2D_8X6_UNORM | ||
| 202 | {VK_FORMAT_ASTC_8x6_SRGB_BLOCK}, // ASTC_2D_8X6_SRGB | ||
| 203 | {VK_FORMAT_ASTC_6x5_UNORM_BLOCK}, // ASTC_2D_6X5_UNORM | ||
| 204 | {VK_FORMAT_ASTC_6x5_SRGB_BLOCK}, // ASTC_2D_6X5_SRGB | ||
| 205 | {VK_FORMAT_E5B9G9R9_UFLOAT_PACK32}, // E5B9G9R9_FLOAT | ||
| 195 | 206 | ||
| 196 | // Depth formats | 207 | // Depth formats |
| 197 | {VK_FORMAT_D32_SFLOAT, Attachable}, // Z32F | 208 | {VK_FORMAT_D32_SFLOAT, Attachable}, // D32_FLOAT |
| 198 | {VK_FORMAT_D16_UNORM, Attachable}, // Z16 | 209 | {VK_FORMAT_D16_UNORM, Attachable}, // D16_UNORM |
| 199 | 210 | ||
| 200 | // DepthStencil formats | 211 | // DepthStencil formats |
| 201 | {VK_FORMAT_D24_UNORM_S8_UINT, Attachable}, // Z24S8 | 212 | {VK_FORMAT_D24_UNORM_S8_UINT, Attachable}, // D24_UNORM_S8_UINT |
| 202 | {VK_FORMAT_D24_UNORM_S8_UINT, Attachable}, // S8Z24 (emulated) | 213 | {VK_FORMAT_D24_UNORM_S8_UINT, Attachable}, // S8_UINT_D24_UNORM (emulated) |
| 203 | {VK_FORMAT_D32_SFLOAT_S8_UINT, Attachable}, // Z32FS8 | 214 | {VK_FORMAT_D32_SFLOAT_S8_UINT, Attachable}, // D32_FLOAT_S8_UINT |
| 204 | }; | 215 | }; |
| 205 | static_assert(std::size(tex_format_tuples) == VideoCore::Surface::MaxPixelFormat); | 216 | static_assert(std::size(tex_format_tuples) == VideoCore::Surface::MaxPixelFormat); |
| 206 | 217 | ||
| @@ -221,7 +232,7 @@ FormatInfo SurfaceFormat(const VKDevice& device, FormatType format_type, PixelFo | |||
| 221 | return {VK_FORMAT_A8B8G8R8_UNORM_PACK32, true, true}; | 232 | return {VK_FORMAT_A8B8G8R8_UNORM_PACK32, true, true}; |
| 222 | } | 233 | } |
| 223 | 234 | ||
| 224 | // Use ABGR8 on hardware that doesn't support ASTC natively | 235 | // Use A8B8G8R8_UNORM on hardware that doesn't support ASTC natively |
| 225 | if (!device.IsOptimalAstcSupported() && VideoCore::Surface::IsPixelFormatASTC(pixel_format)) { | 236 | if (!device.IsOptimalAstcSupported() && VideoCore::Surface::IsPixelFormatASTC(pixel_format)) { |
| 226 | tuple.format = VideoCore::Surface::IsPixelFormatSRGB(pixel_format) | 237 | tuple.format = VideoCore::Surface::IsPixelFormatSRGB(pixel_format) |
| 227 | ? VK_FORMAT_A8B8G8R8_SRGB_PACK32 | 238 | ? VK_FORMAT_A8B8G8R8_SRGB_PACK32 |
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.cpp b/src/video_core/renderer_vulkan/vk_blit_screen.cpp index 866813465..a551e3de8 100644 --- a/src/video_core/renderer_vulkan/vk_blit_screen.cpp +++ b/src/video_core/renderer_vulkan/vk_blit_screen.cpp | |||
| @@ -187,9 +187,9 @@ std::size_t GetSizeInBytes(const Tegra::FramebufferConfig& framebuffer) { | |||
| 187 | 187 | ||
| 188 | VkFormat GetFormat(const Tegra::FramebufferConfig& framebuffer) { | 188 | VkFormat GetFormat(const Tegra::FramebufferConfig& framebuffer) { |
| 189 | switch (framebuffer.pixel_format) { | 189 | switch (framebuffer.pixel_format) { |
| 190 | case Tegra::FramebufferConfig::PixelFormat::ABGR8: | 190 | case Tegra::FramebufferConfig::PixelFormat::A8B8G8R8_UNORM: |
| 191 | return VK_FORMAT_A8B8G8R8_UNORM_PACK32; | 191 | return VK_FORMAT_A8B8G8R8_UNORM_PACK32; |
| 192 | case Tegra::FramebufferConfig::PixelFormat::RGB565: | 192 | case Tegra::FramebufferConfig::PixelFormat::RGB565_UNORM: |
| 193 | return VK_FORMAT_R5G6B5_UNORM_PACK16; | 193 | return VK_FORMAT_R5G6B5_UNORM_PACK16; |
| 194 | default: | 194 | default: |
| 195 | UNIMPLEMENTED_MSG("Unknown framebuffer pixel format: {}", | 195 | UNIMPLEMENTED_MSG("Unknown framebuffer pixel format: {}", |
| @@ -696,6 +696,7 @@ void VKBlitScreen::CreateFramebuffers() { | |||
| 696 | .flags = 0, | 696 | .flags = 0, |
| 697 | .renderPass = *renderpass, | 697 | .renderPass = *renderpass, |
| 698 | .attachmentCount = 1, | 698 | .attachmentCount = 1, |
| 699 | .pAttachments = nullptr, | ||
| 699 | .width = size.width, | 700 | .width = size.width, |
| 700 | .height = size.height, | 701 | .height = size.height, |
| 701 | .layers = 1, | 702 | .layers = 1, |
diff --git a/src/video_core/renderer_vulkan/vk_device.cpp b/src/video_core/renderer_vulkan/vk_device.cpp index 26379ee01..0c03e4d83 100644 --- a/src/video_core/renderer_vulkan/vk_device.cpp +++ b/src/video_core/renderer_vulkan/vk_device.cpp | |||
| @@ -84,14 +84,19 @@ std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties( | |||
| 84 | VK_FORMAT_A8B8G8R8_UNORM_PACK32, | 84 | VK_FORMAT_A8B8G8R8_UNORM_PACK32, |
| 85 | VK_FORMAT_A8B8G8R8_UINT_PACK32, | 85 | VK_FORMAT_A8B8G8R8_UINT_PACK32, |
| 86 | VK_FORMAT_A8B8G8R8_SNORM_PACK32, | 86 | VK_FORMAT_A8B8G8R8_SNORM_PACK32, |
| 87 | VK_FORMAT_A8B8G8R8_SINT_PACK32, | ||
| 87 | VK_FORMAT_A8B8G8R8_SRGB_PACK32, | 88 | VK_FORMAT_A8B8G8R8_SRGB_PACK32, |
| 88 | VK_FORMAT_B5G6R5_UNORM_PACK16, | 89 | VK_FORMAT_B5G6R5_UNORM_PACK16, |
| 89 | VK_FORMAT_A2B10G10R10_UNORM_PACK32, | 90 | VK_FORMAT_A2B10G10R10_UNORM_PACK32, |
| 91 | VK_FORMAT_A2B10G10R10_UINT_PACK32, | ||
| 90 | VK_FORMAT_A1R5G5B5_UNORM_PACK16, | 92 | VK_FORMAT_A1R5G5B5_UNORM_PACK16, |
| 91 | VK_FORMAT_R32G32B32A32_SFLOAT, | 93 | VK_FORMAT_R32G32B32A32_SFLOAT, |
| 94 | VK_FORMAT_R32G32B32A32_SINT, | ||
| 92 | VK_FORMAT_R32G32B32A32_UINT, | 95 | VK_FORMAT_R32G32B32A32_UINT, |
| 93 | VK_FORMAT_R32G32_SFLOAT, | 96 | VK_FORMAT_R32G32_SFLOAT, |
| 97 | VK_FORMAT_R32G32_SINT, | ||
| 94 | VK_FORMAT_R32G32_UINT, | 98 | VK_FORMAT_R32G32_UINT, |
| 99 | VK_FORMAT_R16G16B16A16_SINT, | ||
| 95 | VK_FORMAT_R16G16B16A16_UINT, | 100 | VK_FORMAT_R16G16B16A16_UINT, |
| 96 | VK_FORMAT_R16G16B16A16_SNORM, | 101 | VK_FORMAT_R16G16B16A16_SNORM, |
| 97 | VK_FORMAT_R16G16B16A16_UNORM, | 102 | VK_FORMAT_R16G16B16A16_UNORM, |
| @@ -103,8 +108,11 @@ std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties( | |||
| 103 | VK_FORMAT_R8G8B8A8_SRGB, | 108 | VK_FORMAT_R8G8B8A8_SRGB, |
| 104 | VK_FORMAT_R8G8_UNORM, | 109 | VK_FORMAT_R8G8_UNORM, |
| 105 | VK_FORMAT_R8G8_SNORM, | 110 | VK_FORMAT_R8G8_SNORM, |
| 111 | VK_FORMAT_R8G8_SINT, | ||
| 106 | VK_FORMAT_R8G8_UINT, | 112 | VK_FORMAT_R8G8_UINT, |
| 107 | VK_FORMAT_R8_UNORM, | 113 | VK_FORMAT_R8_UNORM, |
| 114 | VK_FORMAT_R8_SNORM, | ||
| 115 | VK_FORMAT_R8_SINT, | ||
| 108 | VK_FORMAT_R8_UINT, | 116 | VK_FORMAT_R8_UINT, |
| 109 | VK_FORMAT_B10G11R11_UFLOAT_PACK32, | 117 | VK_FORMAT_B10G11R11_UFLOAT_PACK32, |
| 110 | VK_FORMAT_R32_SFLOAT, | 118 | VK_FORMAT_R32_SFLOAT, |
| @@ -124,6 +132,7 @@ std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties( | |||
| 124 | VK_FORMAT_BC2_UNORM_BLOCK, | 132 | VK_FORMAT_BC2_UNORM_BLOCK, |
| 125 | VK_FORMAT_BC3_UNORM_BLOCK, | 133 | VK_FORMAT_BC3_UNORM_BLOCK, |
| 126 | VK_FORMAT_BC4_UNORM_BLOCK, | 134 | VK_FORMAT_BC4_UNORM_BLOCK, |
| 135 | VK_FORMAT_BC4_SNORM_BLOCK, | ||
| 127 | VK_FORMAT_BC5_UNORM_BLOCK, | 136 | VK_FORMAT_BC5_UNORM_BLOCK, |
| 128 | VK_FORMAT_BC5_SNORM_BLOCK, | 137 | VK_FORMAT_BC5_SNORM_BLOCK, |
| 129 | VK_FORMAT_BC7_UNORM_BLOCK, | 138 | VK_FORMAT_BC7_UNORM_BLOCK, |
| @@ -762,8 +771,9 @@ std::vector<VkDeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() const | |||
| 762 | .pNext = nullptr, | 771 | .pNext = nullptr, |
| 763 | .flags = 0, | 772 | .flags = 0, |
| 764 | .queueFamilyIndex = queue_family, | 773 | .queueFamilyIndex = queue_family, |
| 774 | .queueCount = 1, | ||
| 775 | .pQueuePriorities = nullptr, | ||
| 765 | }); | 776 | }); |
| 766 | ci.queueCount = 1; | ||
| 767 | ci.pQueuePriorities = &QUEUE_PRIORITY; | 777 | ci.pQueuePriorities = &QUEUE_PRIORITY; |
| 768 | } | 778 | } |
| 769 | 779 | ||
diff --git a/src/video_core/renderer_vulkan/vk_device.h b/src/video_core/renderer_vulkan/vk_device.h index ae5c21baa..529744f2d 100644 --- a/src/video_core/renderer_vulkan/vk_device.h +++ b/src/video_core/renderer_vulkan/vk_device.h | |||
| @@ -122,6 +122,11 @@ public: | |||
| 122 | return properties.limits.maxPushConstantsSize; | 122 | return properties.limits.maxPushConstantsSize; |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | /// Returns the maximum size for shared memory. | ||
| 126 | u32 GetMaxComputeSharedMemorySize() const { | ||
| 127 | return properties.limits.maxComputeSharedMemorySize; | ||
| 128 | } | ||
| 129 | |||
| 125 | /// Returns true if ASTC is natively supported. | 130 | /// Returns true if ASTC is natively supported. |
| 126 | bool IsOptimalAstcSupported() const { | 131 | bool IsOptimalAstcSupported() const { |
| 127 | return is_optimal_astc_supported; | 132 | return is_optimal_astc_supported; |
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 42b3a744c..418c62bc4 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -261,8 +261,13 @@ VKComputePipeline& VKPipelineCache::GetComputePipeline(const ComputePipelineCach | |||
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | const Specialization specialization{ | 263 | const Specialization specialization{ |
| 264 | .base_binding = 0, | ||
| 264 | .workgroup_size = key.workgroup_size, | 265 | .workgroup_size = key.workgroup_size, |
| 265 | .shared_memory_size = key.shared_memory_size, | 266 | .shared_memory_size = key.shared_memory_size, |
| 267 | .point_size = std::nullopt, | ||
| 268 | .enabled_attributes = {}, | ||
| 269 | .attribute_types = {}, | ||
| 270 | .ndc_minus_one_to_one = false, | ||
| 266 | }; | 271 | }; |
| 267 | const SPIRVShader spirv_shader{Decompile(device, shader->GetIR(), ShaderType::Compute, | 272 | const SPIRVShader spirv_shader{Decompile(device, shader->GetIR(), ShaderType::Compute, |
| 268 | shader->GetRegistry(), specialization), | 273 | shader->GetRegistry(), specialization), |
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 31e44aa2b..7500e8244 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp | |||
| @@ -532,10 +532,6 @@ void RasterizerVulkan::Clear() { | |||
| 532 | 532 | ||
| 533 | scheduler.Record([clear_depth = regs.clear_depth, clear_stencil = regs.clear_stencil, | 533 | scheduler.Record([clear_depth = regs.clear_depth, clear_stencil = regs.clear_stencil, |
| 534 | clear_rect, aspect_flags](vk::CommandBuffer cmdbuf) { | 534 | clear_rect, aspect_flags](vk::CommandBuffer cmdbuf) { |
| 535 | VkClearValue clear_value; | ||
| 536 | clear_value.depthStencil.depth = clear_depth; | ||
| 537 | clear_value.depthStencil.stencil = clear_stencil; | ||
| 538 | |||
| 539 | VkClearAttachment attachment; | 535 | VkClearAttachment attachment; |
| 540 | attachment.aspectMask = aspect_flags; | 536 | attachment.aspectMask = aspect_flags; |
| 541 | attachment.colorAttachment = 0; | 537 | attachment.colorAttachment = 0; |
| @@ -819,8 +815,13 @@ bool RasterizerVulkan::WalkAttachmentOverlaps(const CachedSurfaceView& attachmen | |||
| 819 | 815 | ||
| 820 | std::tuple<VkFramebuffer, VkExtent2D> RasterizerVulkan::ConfigureFramebuffers( | 816 | std::tuple<VkFramebuffer, VkExtent2D> RasterizerVulkan::ConfigureFramebuffers( |
| 821 | VkRenderPass renderpass) { | 817 | VkRenderPass renderpass) { |
| 822 | FramebufferCacheKey key{renderpass, std::numeric_limits<u32>::max(), | 818 | FramebufferCacheKey key{ |
| 823 | std::numeric_limits<u32>::max(), std::numeric_limits<u32>::max()}; | 819 | .renderpass = renderpass, |
| 820 | .width = std::numeric_limits<u32>::max(), | ||
| 821 | .height = std::numeric_limits<u32>::max(), | ||
| 822 | .layers = std::numeric_limits<u32>::max(), | ||
| 823 | .views = {}, | ||
| 824 | }; | ||
| 824 | 825 | ||
| 825 | const auto try_push = [&key](const View& view) { | 826 | const auto try_push = [&key](const View& view) { |
| 826 | if (!view) { | 827 | if (!view) { |
diff --git a/src/video_core/renderer_vulkan/vk_sampler_cache.cpp b/src/video_core/renderer_vulkan/vk_sampler_cache.cpp index 2d5460776..b068888f9 100644 --- a/src/video_core/renderer_vulkan/vk_sampler_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_sampler_cache.cpp | |||
| @@ -47,6 +47,7 @@ vk::Sampler VKSamplerCache::CreateSampler(const Tegra::Texture::TSCEntry& tsc) c | |||
| 47 | VkSamplerCustomBorderColorCreateInfoEXT border{ | 47 | VkSamplerCustomBorderColorCreateInfoEXT border{ |
| 48 | .sType = VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT, | 48 | .sType = VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT, |
| 49 | .pNext = nullptr, | 49 | .pNext = nullptr, |
| 50 | .customBorderColor = {}, | ||
| 50 | .format = VK_FORMAT_UNDEFINED, | 51 | .format = VK_FORMAT_UNDEFINED, |
| 51 | }; | 52 | }; |
| 52 | std::memcpy(&border.customBorderColor, color.data(), sizeof(color)); | 53 | std::memcpy(&border.customBorderColor, color.data(), sizeof(color)); |
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp index 97429cc59..cd7d7a4e4 100644 --- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | |||
| @@ -685,13 +685,19 @@ private: | |||
| 685 | } | 685 | } |
| 686 | t_smem_uint = TypePointer(spv::StorageClass::Workgroup, t_uint); | 686 | t_smem_uint = TypePointer(spv::StorageClass::Workgroup, t_uint); |
| 687 | 687 | ||
| 688 | const u32 smem_size = specialization.shared_memory_size; | 688 | u32 smem_size = specialization.shared_memory_size * 4; |
| 689 | if (smem_size == 0) { | 689 | if (smem_size == 0) { |
| 690 | // Avoid declaring an empty array. | 690 | // Avoid declaring an empty array. |
| 691 | return; | 691 | return; |
| 692 | } | 692 | } |
| 693 | const auto element_count = static_cast<u32>(Common::AlignUp(smem_size, 4) / 4); | 693 | const u32 limit = device.GetMaxComputeSharedMemorySize(); |
| 694 | const Id type_array = TypeArray(t_uint, Constant(t_uint, element_count)); | 694 | if (smem_size > limit) { |
| 695 | LOG_ERROR(Render_Vulkan, "Shared memory size {} is clamped to host's limit {}", | ||
| 696 | smem_size, limit); | ||
| 697 | smem_size = limit; | ||
| 698 | } | ||
| 699 | |||
| 700 | const Id type_array = TypeArray(t_uint, Constant(t_uint, smem_size / 4)); | ||
| 695 | const Id type_pointer = TypePointer(spv::StorageClass::Workgroup, type_array); | 701 | const Id type_pointer = TypePointer(spv::StorageClass::Workgroup, type_array); |
| 696 | Name(type_pointer, "SharedMemory"); | 702 | Name(type_pointer, "SharedMemory"); |
| 697 | 703 | ||
| @@ -700,9 +706,9 @@ private: | |||
| 700 | } | 706 | } |
| 701 | 707 | ||
| 702 | void DeclareInternalFlags() { | 708 | void DeclareInternalFlags() { |
| 703 | constexpr std::array names = {"zero", "sign", "carry", "overflow"}; | 709 | static constexpr std::array names{"zero", "sign", "carry", "overflow"}; |
| 710 | |||
| 704 | for (std::size_t flag = 0; flag < INTERNAL_FLAGS_COUNT; ++flag) { | 711 | for (std::size_t flag = 0; flag < INTERNAL_FLAGS_COUNT; ++flag) { |
| 705 | const auto flag_code = static_cast<InternalFlag>(flag); | ||
| 706 | const Id id = OpVariable(t_prv_bool, spv::StorageClass::Private, v_false); | 712 | const Id id = OpVariable(t_prv_bool, spv::StorageClass::Private, v_false); |
| 707 | internal_flags[flag] = AddGlobalVariable(Name(id, names[flag])); | 713 | internal_flags[flag] = AddGlobalVariable(Name(id, names[flag])); |
| 708 | } | 714 | } |
| @@ -2798,7 +2804,6 @@ private: | |||
| 2798 | std::map<GlobalMemoryBase, Id> global_buffers; | 2804 | std::map<GlobalMemoryBase, Id> global_buffers; |
| 2799 | std::map<u32, TexelBuffer> uniform_texels; | 2805 | std::map<u32, TexelBuffer> uniform_texels; |
| 2800 | std::map<u32, SampledImage> sampled_images; | 2806 | std::map<u32, SampledImage> sampled_images; |
| 2801 | std::map<u32, TexelBuffer> storage_texels; | ||
| 2802 | std::map<u32, StorageImage> images; | 2807 | std::map<u32, StorageImage> images; |
| 2803 | 2808 | ||
| 2804 | std::array<Id, Maxwell::NumRenderTargets> frag_colors{}; | 2809 | std::array<Id, Maxwell::NumRenderTargets> frag_colors{}; |
diff --git a/src/video_core/renderer_vulkan/vk_swapchain.cpp b/src/video_core/renderer_vulkan/vk_swapchain.cpp index c25e312b6..6bfd2abae 100644 --- a/src/video_core/renderer_vulkan/vk_swapchain.cpp +++ b/src/video_core/renderer_vulkan/vk_swapchain.cpp | |||
| @@ -156,6 +156,7 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, | |||
| 156 | .minImageCount = requested_image_count, | 156 | .minImageCount = requested_image_count, |
| 157 | .imageFormat = surface_format.format, | 157 | .imageFormat = surface_format.format, |
| 158 | .imageColorSpace = surface_format.colorSpace, | 158 | .imageColorSpace = surface_format.colorSpace, |
| 159 | .imageExtent = {}, | ||
| 159 | .imageArrayLayers = 1, | 160 | .imageArrayLayers = 1, |
| 160 | .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, | 161 | .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 161 | .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE, | 162 | .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE, |
| @@ -204,6 +205,7 @@ void VKSwapchain::CreateImageViews() { | |||
| 204 | .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, | 205 | .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, |
| 205 | .pNext = nullptr, | 206 | .pNext = nullptr, |
| 206 | .flags = 0, | 207 | .flags = 0, |
| 208 | .image = {}, | ||
| 207 | .viewType = VK_IMAGE_VIEW_TYPE_2D, | 209 | .viewType = VK_IMAGE_VIEW_TYPE_2D, |
| 208 | .format = image_format, | 210 | .format = image_format, |
| 209 | .components = | 211 | .components = |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 9bc18c21a..2c6f54101 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp | |||
| @@ -138,6 +138,7 @@ VkImageCreateInfo GenerateImageCreateInfo(const VKDevice& device, const SurfaceP | |||
| 138 | .flags = 0, | 138 | .flags = 0, |
| 139 | .imageType = SurfaceTargetToImage(params.target), | 139 | .imageType = SurfaceTargetToImage(params.target), |
| 140 | .format = format, | 140 | .format = format, |
| 141 | .extent = {}, | ||
| 141 | .mipLevels = params.num_levels, | 142 | .mipLevels = params.num_levels, |
| 142 | .arrayLayers = static_cast<u32>(params.GetNumLayers()), | 143 | .arrayLayers = static_cast<u32>(params.GetNumLayers()), |
| 143 | .samples = VK_SAMPLE_COUNT_1_BIT, | 144 | .samples = VK_SAMPLE_COUNT_1_BIT, |
| @@ -235,7 +236,7 @@ void CachedSurface::UploadTexture(const std::vector<u8>& staging_buffer) { | |||
| 235 | void CachedSurface::DownloadTexture(std::vector<u8>& staging_buffer) { | 236 | void CachedSurface::DownloadTexture(std::vector<u8>& staging_buffer) { |
| 236 | UNIMPLEMENTED_IF(params.IsBuffer()); | 237 | UNIMPLEMENTED_IF(params.IsBuffer()); |
| 237 | 238 | ||
| 238 | if (params.pixel_format == VideoCore::Surface::PixelFormat::A1B5G5R5U) { | 239 | if (params.pixel_format == VideoCore::Surface::PixelFormat::A1B5G5R5_UNORM) { |
| 239 | LOG_WARNING(Render_Vulkan, "A1B5G5R5 flushing is stubbed"); | 240 | LOG_WARNING(Render_Vulkan, "A1B5G5R5 flushing is stubbed"); |
| 240 | } | 241 | } |
| 241 | 242 | ||
| @@ -385,7 +386,7 @@ VkImageView CachedSurfaceView::GetImageView(SwizzleSource x_source, SwizzleSourc | |||
| 385 | 386 | ||
| 386 | std::array swizzle{MaxwellToVK::SwizzleSource(x_source), MaxwellToVK::SwizzleSource(y_source), | 387 | std::array swizzle{MaxwellToVK::SwizzleSource(x_source), MaxwellToVK::SwizzleSource(y_source), |
| 387 | MaxwellToVK::SwizzleSource(z_source), MaxwellToVK::SwizzleSource(w_source)}; | 388 | MaxwellToVK::SwizzleSource(z_source), MaxwellToVK::SwizzleSource(w_source)}; |
| 388 | if (params.pixel_format == VideoCore::Surface::PixelFormat::A1B5G5R5U) { | 389 | if (params.pixel_format == VideoCore::Surface::PixelFormat::A1B5G5R5_UNORM) { |
| 389 | // A1B5G5R5 is implemented as A1R5G5B5, we have to change the swizzle here. | 390 | // A1B5G5R5 is implemented as A1R5G5B5, we have to change the swizzle here. |
| 390 | std::swap(swizzle[0], swizzle[2]); | 391 | std::swap(swizzle[0], swizzle[2]); |
| 391 | } | 392 | } |
| @@ -397,11 +398,11 @@ VkImageView CachedSurfaceView::GetImageView(SwizzleSource x_source, SwizzleSourc | |||
| 397 | UNIMPLEMENTED_IF(x_source != SwizzleSource::R && x_source != SwizzleSource::G); | 398 | UNIMPLEMENTED_IF(x_source != SwizzleSource::R && x_source != SwizzleSource::G); |
| 398 | const bool is_first = x_source == SwizzleSource::R; | 399 | const bool is_first = x_source == SwizzleSource::R; |
| 399 | switch (params.pixel_format) { | 400 | switch (params.pixel_format) { |
| 400 | case VideoCore::Surface::PixelFormat::Z24S8: | 401 | case VideoCore::Surface::PixelFormat::D24_UNORM_S8_UINT: |
| 401 | case VideoCore::Surface::PixelFormat::Z32FS8: | 402 | case VideoCore::Surface::PixelFormat::D32_FLOAT_S8_UINT: |
| 402 | aspect = is_first ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_STENCIL_BIT; | 403 | aspect = is_first ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_STENCIL_BIT; |
| 403 | break; | 404 | break; |
| 404 | case VideoCore::Surface::PixelFormat::S8Z24: | 405 | case VideoCore::Surface::PixelFormat::S8_UINT_D24_UNORM: |
| 405 | aspect = is_first ? VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_DEPTH_BIT; | 406 | aspect = is_first ? VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_DEPTH_BIT; |
| 406 | break; | 407 | break; |
| 407 | default: | 408 | default: |
| @@ -458,6 +459,7 @@ VkImageView CachedSurfaceView::GetAttachment() { | |||
| 458 | .pNext = nullptr, | 459 | .pNext = nullptr, |
| 459 | .flags = 0, | 460 | .flags = 0, |
| 460 | .image = surface.GetImageHandle(), | 461 | .image = surface.GetImageHandle(), |
| 462 | .viewType = VK_IMAGE_VIEW_TYPE_1D, | ||
| 461 | .format = surface.GetImage().GetFormat(), | 463 | .format = surface.GetImage().GetFormat(), |
| 462 | .components = | 464 | .components = |
| 463 | { | 465 | { |
| @@ -471,6 +473,8 @@ VkImageView CachedSurfaceView::GetAttachment() { | |||
| 471 | .aspectMask = aspect_mask, | 473 | .aspectMask = aspect_mask, |
| 472 | .baseMipLevel = base_level, | 474 | .baseMipLevel = base_level, |
| 473 | .levelCount = num_levels, | 475 | .levelCount = num_levels, |
| 476 | .baseArrayLayer = 0, | ||
| 477 | .layerCount = 0, | ||
| 474 | }, | 478 | }, |
| 475 | }; | 479 | }; |
| 476 | if (image_view_type == VK_IMAGE_VIEW_TYPE_3D) { | 480 | if (image_view_type == VK_IMAGE_VIEW_TYPE_3D) { |
diff --git a/src/video_core/shader/decode/arithmetic_integer.cpp b/src/video_core/shader/decode/arithmetic_integer.cpp index a041519b7..73155966f 100644 --- a/src/video_core/shader/decode/arithmetic_integer.cpp +++ b/src/video_core/shader/decode/arithmetic_integer.cpp | |||
| @@ -98,12 +98,12 @@ u32 ShaderIR::DecodeArithmeticInteger(NodeBlock& bb, u32 pc) { | |||
| 98 | op_b = GetOperandAbsNegInteger(op_b, false, instr.iadd3.neg_b, true); | 98 | op_b = GetOperandAbsNegInteger(op_b, false, instr.iadd3.neg_b, true); |
| 99 | op_c = GetOperandAbsNegInteger(op_c, false, instr.iadd3.neg_c, true); | 99 | op_c = GetOperandAbsNegInteger(op_c, false, instr.iadd3.neg_c, true); |
| 100 | 100 | ||
| 101 | const Node value = [&]() { | 101 | const Node value = [&] { |
| 102 | const Node add_ab = Operation(OperationCode::IAdd, NO_PRECISE, op_a, op_b); | 102 | Node add_ab = Operation(OperationCode::IAdd, NO_PRECISE, op_a, op_b); |
| 103 | if (opcode->get().GetId() != OpCode::Id::IADD3_R) { | 103 | if (opcode->get().GetId() != OpCode::Id::IADD3_R) { |
| 104 | return Operation(OperationCode::IAdd, NO_PRECISE, add_ab, op_c); | 104 | return Operation(OperationCode::IAdd, NO_PRECISE, add_ab, op_c); |
| 105 | } | 105 | } |
| 106 | const Node shifted = [&]() { | 106 | const Node shifted = [&] { |
| 107 | switch (instr.iadd3.mode) { | 107 | switch (instr.iadd3.mode) { |
| 108 | case Tegra::Shader::IAdd3Mode::RightShift: | 108 | case Tegra::Shader::IAdd3Mode::RightShift: |
| 109 | // TODO(tech4me): According to | 109 | // TODO(tech4me): According to |
diff --git a/src/video_core/shader/decode/image.cpp b/src/video_core/shader/decode/image.cpp index 07778dc3e..e75ca4fdb 100644 --- a/src/video_core/shader/decode/image.cpp +++ b/src/video_core/shader/decode/image.cpp | |||
| @@ -31,11 +31,11 @@ ComponentType GetComponentType(Tegra::Engines::SamplerDescriptor descriptor, | |||
| 31 | std::size_t component) { | 31 | std::size_t component) { |
| 32 | const TextureFormat format{descriptor.format}; | 32 | const TextureFormat format{descriptor.format}; |
| 33 | switch (format) { | 33 | switch (format) { |
| 34 | case TextureFormat::R16_G16_B16_A16: | 34 | case TextureFormat::R16G16B16A16: |
| 35 | case TextureFormat::R32_G32_B32_A32: | 35 | case TextureFormat::R32G32B32A32: |
| 36 | case TextureFormat::R32_G32_B32: | 36 | case TextureFormat::R32G32B32: |
| 37 | case TextureFormat::R32_G32: | 37 | case TextureFormat::R32G32: |
| 38 | case TextureFormat::R16_G16: | 38 | case TextureFormat::R16G16: |
| 39 | case TextureFormat::R32: | 39 | case TextureFormat::R32: |
| 40 | case TextureFormat::R16: | 40 | case TextureFormat::R16: |
| 41 | case TextureFormat::R8: | 41 | case TextureFormat::R8: |
| @@ -97,7 +97,7 @@ ComponentType GetComponentType(Tegra::Engines::SamplerDescriptor descriptor, | |||
| 97 | break; | 97 | break; |
| 98 | case TextureFormat::B5G6R5: | 98 | case TextureFormat::B5G6R5: |
| 99 | case TextureFormat::B6G5R5: | 99 | case TextureFormat::B6G5R5: |
| 100 | case TextureFormat::BF10GF11RF11: | 100 | case TextureFormat::B10G11R11: |
| 101 | if (component == 0) { | 101 | if (component == 0) { |
| 102 | return descriptor.b_type; | 102 | return descriptor.b_type; |
| 103 | } | 103 | } |
| @@ -108,9 +108,9 @@ ComponentType GetComponentType(Tegra::Engines::SamplerDescriptor descriptor, | |||
| 108 | return descriptor.r_type; | 108 | return descriptor.r_type; |
| 109 | } | 109 | } |
| 110 | break; | 110 | break; |
| 111 | case TextureFormat::G8R24: | 111 | case TextureFormat::R24G8: |
| 112 | case TextureFormat::G24R8: | 112 | case TextureFormat::R8G24: |
| 113 | case TextureFormat::G8R8: | 113 | case TextureFormat::R8G8: |
| 114 | case TextureFormat::G4R4: | 114 | case TextureFormat::G4R4: |
| 115 | if (component == 0) { | 115 | if (component == 0) { |
| 116 | return descriptor.g_type; | 116 | return descriptor.g_type; |
| @@ -137,15 +137,15 @@ bool IsComponentEnabled(std::size_t component_mask, std::size_t component) { | |||
| 137 | 137 | ||
| 138 | u32 GetComponentSize(TextureFormat format, std::size_t component) { | 138 | u32 GetComponentSize(TextureFormat format, std::size_t component) { |
| 139 | switch (format) { | 139 | switch (format) { |
| 140 | case TextureFormat::R32_G32_B32_A32: | 140 | case TextureFormat::R32G32B32A32: |
| 141 | return 32; | 141 | return 32; |
| 142 | case TextureFormat::R16_G16_B16_A16: | 142 | case TextureFormat::R16G16B16A16: |
| 143 | return 16; | 143 | return 16; |
| 144 | case TextureFormat::R32_G32_B32: | 144 | case TextureFormat::R32G32B32: |
| 145 | return component <= 2 ? 32 : 0; | 145 | return component <= 2 ? 32 : 0; |
| 146 | case TextureFormat::R32_G32: | 146 | case TextureFormat::R32G32: |
| 147 | return component <= 1 ? 32 : 0; | 147 | return component <= 1 ? 32 : 0; |
| 148 | case TextureFormat::R16_G16: | 148 | case TextureFormat::R16G16: |
| 149 | return component <= 1 ? 16 : 0; | 149 | return component <= 1 ? 16 : 0; |
| 150 | case TextureFormat::R32: | 150 | case TextureFormat::R32: |
| 151 | return component == 0 ? 32 : 0; | 151 | return component == 0 ? 32 : 0; |
| @@ -192,7 +192,7 @@ u32 GetComponentSize(TextureFormat format, std::size_t component) { | |||
| 192 | return 6; | 192 | return 6; |
| 193 | } | 193 | } |
| 194 | return 0; | 194 | return 0; |
| 195 | case TextureFormat::BF10GF11RF11: | 195 | case TextureFormat::B10G11R11: |
| 196 | if (component == 1 || component == 2) { | 196 | if (component == 1 || component == 2) { |
| 197 | return 11; | 197 | return 11; |
| 198 | } | 198 | } |
| @@ -200,7 +200,7 @@ u32 GetComponentSize(TextureFormat format, std::size_t component) { | |||
| 200 | return 10; | 200 | return 10; |
| 201 | } | 201 | } |
| 202 | return 0; | 202 | return 0; |
| 203 | case TextureFormat::G8R24: | 203 | case TextureFormat::R24G8: |
| 204 | if (component == 0) { | 204 | if (component == 0) { |
| 205 | return 8; | 205 | return 8; |
| 206 | } | 206 | } |
| @@ -208,7 +208,7 @@ u32 GetComponentSize(TextureFormat format, std::size_t component) { | |||
| 208 | return 24; | 208 | return 24; |
| 209 | } | 209 | } |
| 210 | return 0; | 210 | return 0; |
| 211 | case TextureFormat::G24R8: | 211 | case TextureFormat::R8G24: |
| 212 | if (component == 0) { | 212 | if (component == 0) { |
| 213 | return 8; | 213 | return 8; |
| 214 | } | 214 | } |
| @@ -216,7 +216,7 @@ u32 GetComponentSize(TextureFormat format, std::size_t component) { | |||
| 216 | return 24; | 216 | return 24; |
| 217 | } | 217 | } |
| 218 | return 0; | 218 | return 0; |
| 219 | case TextureFormat::G8R8: | 219 | case TextureFormat::R8G8: |
| 220 | return (component == 0 || component == 1) ? 8 : 0; | 220 | return (component == 0 || component == 1) ? 8 : 0; |
| 221 | case TextureFormat::G4R4: | 221 | case TextureFormat::G4R4: |
| 222 | return (component == 0 || component == 1) ? 4 : 0; | 222 | return (component == 0 || component == 1) ? 4 : 0; |
| @@ -231,25 +231,25 @@ std::size_t GetImageComponentMask(TextureFormat format) { | |||
| 231 | constexpr u8 B = 0b0100; | 231 | constexpr u8 B = 0b0100; |
| 232 | constexpr u8 A = 0b1000; | 232 | constexpr u8 A = 0b1000; |
| 233 | switch (format) { | 233 | switch (format) { |
| 234 | case TextureFormat::R32_G32_B32_A32: | 234 | case TextureFormat::R32G32B32A32: |
| 235 | case TextureFormat::R16_G16_B16_A16: | 235 | case TextureFormat::R16G16B16A16: |
| 236 | case TextureFormat::A8R8G8B8: | 236 | case TextureFormat::A8R8G8B8: |
| 237 | case TextureFormat::A2B10G10R10: | 237 | case TextureFormat::A2B10G10R10: |
| 238 | case TextureFormat::A4B4G4R4: | 238 | case TextureFormat::A4B4G4R4: |
| 239 | case TextureFormat::A5B5G5R1: | 239 | case TextureFormat::A5B5G5R1: |
| 240 | case TextureFormat::A1B5G5R5: | 240 | case TextureFormat::A1B5G5R5: |
| 241 | return std::size_t{R | G | B | A}; | 241 | return std::size_t{R | G | B | A}; |
| 242 | case TextureFormat::R32_G32_B32: | 242 | case TextureFormat::R32G32B32: |
| 243 | case TextureFormat::R32_B24G8: | 243 | case TextureFormat::R32_B24G8: |
| 244 | case TextureFormat::B5G6R5: | 244 | case TextureFormat::B5G6R5: |
| 245 | case TextureFormat::B6G5R5: | 245 | case TextureFormat::B6G5R5: |
| 246 | case TextureFormat::BF10GF11RF11: | 246 | case TextureFormat::B10G11R11: |
| 247 | return std::size_t{R | G | B}; | 247 | return std::size_t{R | G | B}; |
| 248 | case TextureFormat::R32_G32: | 248 | case TextureFormat::R32G32: |
| 249 | case TextureFormat::R16_G16: | 249 | case TextureFormat::R16G16: |
| 250 | case TextureFormat::G8R24: | 250 | case TextureFormat::R24G8: |
| 251 | case TextureFormat::G24R8: | 251 | case TextureFormat::R8G24: |
| 252 | case TextureFormat::G8R8: | 252 | case TextureFormat::R8G8: |
| 253 | case TextureFormat::G4R4: | 253 | case TextureFormat::G4R4: |
| 254 | return std::size_t{R | G}; | 254 | return std::size_t{R | G}; |
| 255 | case TextureFormat::R32: | 255 | case TextureFormat::R32: |
diff --git a/src/video_core/shader/decode/other.cpp b/src/video_core/shader/decode/other.cpp index c0a8f233f..29a7cfbfe 100644 --- a/src/video_core/shader/decode/other.cpp +++ b/src/video_core/shader/decode/other.cpp | |||
| @@ -75,8 +75,7 @@ u32 ShaderIR::DecodeOther(NodeBlock& bb, u32 pc) { | |||
| 75 | const Node value = [this, instr] { | 75 | const Node value = [this, instr] { |
| 76 | switch (instr.sys20) { | 76 | switch (instr.sys20) { |
| 77 | case SystemVariable::LaneId: | 77 | case SystemVariable::LaneId: |
| 78 | LOG_WARNING(HW_GPU, "S2R instruction with LaneId is incomplete"); | 78 | return Operation(OperationCode::ThreadId); |
| 79 | return Immediate(0U); | ||
| 80 | case SystemVariable::InvocationId: | 79 | case SystemVariable::InvocationId: |
| 81 | return Operation(OperationCode::InvocationId); | 80 | return Operation(OperationCode::InvocationId); |
| 82 | case SystemVariable::Ydirection: | 81 | case SystemVariable::Ydirection: |
diff --git a/src/video_core/shader/decode/video.cpp b/src/video_core/shader/decode/video.cpp index 64ba60ea2..1c0957277 100644 --- a/src/video_core/shader/decode/video.cpp +++ b/src/video_core/shader/decode/video.cpp | |||
| @@ -91,29 +91,28 @@ u32 ShaderIR::DecodeVideo(NodeBlock& bb, u32 pc) { | |||
| 91 | return pc; | 91 | return pc; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | Node ShaderIR::GetVideoOperand(Node op, bool is_chunk, bool is_signed, | 94 | Node ShaderIR::GetVideoOperand(Node op, bool is_chunk, bool is_signed, VideoType type, |
| 95 | Tegra::Shader::VideoType type, u64 byte_height) { | 95 | u64 byte_height) { |
| 96 | if (!is_chunk) { | 96 | if (!is_chunk) { |
| 97 | return BitfieldExtract(op, static_cast<u32>(byte_height * 8), 8); | 97 | return BitfieldExtract(op, static_cast<u32>(byte_height * 8), 8); |
| 98 | } | 98 | } |
| 99 | const Node zero = Immediate(0); | ||
| 100 | 99 | ||
| 101 | switch (type) { | 100 | switch (type) { |
| 102 | case Tegra::Shader::VideoType::Size16_Low: | 101 | case VideoType::Size16_Low: |
| 103 | return BitfieldExtract(op, 0, 16); | 102 | return BitfieldExtract(op, 0, 16); |
| 104 | case Tegra::Shader::VideoType::Size16_High: | 103 | case VideoType::Size16_High: |
| 105 | return BitfieldExtract(op, 16, 16); | 104 | return BitfieldExtract(op, 16, 16); |
| 106 | case Tegra::Shader::VideoType::Size32: | 105 | case VideoType::Size32: |
| 107 | // TODO(Rodrigo): From my hardware tests it becomes a bit "mad" when this type is used | 106 | // TODO(Rodrigo): From my hardware tests it becomes a bit "mad" when this type is used |
| 108 | // (1 * 1 + 0 == 0x5b800000). Until a better explanation is found: abort. | 107 | // (1 * 1 + 0 == 0x5b800000). Until a better explanation is found: abort. |
| 109 | UNIMPLEMENTED(); | 108 | UNIMPLEMENTED(); |
| 110 | return zero; | 109 | return Immediate(0); |
| 111 | case Tegra::Shader::VideoType::Invalid: | 110 | case VideoType::Invalid: |
| 112 | UNREACHABLE_MSG("Invalid instruction encoding"); | 111 | UNREACHABLE_MSG("Invalid instruction encoding"); |
| 113 | return zero; | 112 | return Immediate(0); |
| 114 | default: | 113 | default: |
| 115 | UNREACHABLE(); | 114 | UNREACHABLE(); |
| 116 | return zero; | 115 | return Immediate(0); |
| 117 | } | 116 | } |
| 118 | } | 117 | } |
| 119 | 118 | ||
diff --git a/src/video_core/shader/decode/xmad.cpp b/src/video_core/shader/decode/xmad.cpp index c83dc6615..233b8fa42 100644 --- a/src/video_core/shader/decode/xmad.cpp +++ b/src/video_core/shader/decode/xmad.cpp | |||
| @@ -81,20 +81,21 @@ u32 ShaderIR::DecodeXmad(NodeBlock& bb, u32 pc) { | |||
| 81 | SetTemporary(bb, 0, product); | 81 | SetTemporary(bb, 0, product); |
| 82 | product = GetTemporary(0); | 82 | product = GetTemporary(0); |
| 83 | 83 | ||
| 84 | const Node original_c = op_c; | 84 | Node original_c = op_c; |
| 85 | const Tegra::Shader::XmadMode set_mode = mode; // Workaround to clang compile error | 85 | const Tegra::Shader::XmadMode set_mode = mode; // Workaround to clang compile error |
| 86 | op_c = [&]() { | 86 | op_c = [&] { |
| 87 | switch (set_mode) { | 87 | switch (set_mode) { |
| 88 | case Tegra::Shader::XmadMode::None: | 88 | case Tegra::Shader::XmadMode::None: |
| 89 | return original_c; | 89 | return original_c; |
| 90 | case Tegra::Shader::XmadMode::CLo: | 90 | case Tegra::Shader::XmadMode::CLo: |
| 91 | return BitfieldExtract(original_c, 0, 16); | 91 | return BitfieldExtract(std::move(original_c), 0, 16); |
| 92 | case Tegra::Shader::XmadMode::CHi: | 92 | case Tegra::Shader::XmadMode::CHi: |
| 93 | return BitfieldExtract(original_c, 16, 16); | 93 | return BitfieldExtract(std::move(original_c), 16, 16); |
| 94 | case Tegra::Shader::XmadMode::CBcc: { | 94 | case Tegra::Shader::XmadMode::CBcc: { |
| 95 | const Node shifted_b = SignedOperation(OperationCode::ILogicalShiftLeft, is_signed_b, | 95 | Node shifted_b = SignedOperation(OperationCode::ILogicalShiftLeft, is_signed_b, |
| 96 | original_b, Immediate(16)); | 96 | original_b, Immediate(16)); |
| 97 | return SignedOperation(OperationCode::IAdd, is_signed_c, original_c, shifted_b); | 97 | return SignedOperation(OperationCode::IAdd, is_signed_c, std::move(original_c), |
| 98 | std::move(shifted_b)); | ||
| 98 | } | 99 | } |
| 99 | case Tegra::Shader::XmadMode::CSfu: { | 100 | case Tegra::Shader::XmadMode::CSfu: { |
| 100 | const Node comp_a = | 101 | const Node comp_a = |
diff --git a/src/video_core/shader/shader_ir.cpp b/src/video_core/shader/shader_ir.cpp index e322c3402..29d794b34 100644 --- a/src/video_core/shader/shader_ir.cpp +++ b/src/video_core/shader/shader_ir.cpp | |||
| @@ -112,9 +112,9 @@ Node ShaderIR::GetOutputAttribute(Attribute::Index index, u64 element, Node buff | |||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | Node ShaderIR::GetInternalFlag(InternalFlag flag, bool negated) const { | 114 | Node ShaderIR::GetInternalFlag(InternalFlag flag, bool negated) const { |
| 115 | const Node node = MakeNode<InternalFlagNode>(flag); | 115 | Node node = MakeNode<InternalFlagNode>(flag); |
| 116 | if (negated) { | 116 | if (negated) { |
| 117 | return Operation(OperationCode::LogicalNegate, node); | 117 | return Operation(OperationCode::LogicalNegate, std::move(node)); |
| 118 | } | 118 | } |
| 119 | return node; | 119 | return node; |
| 120 | } | 120 | } |
diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp index bbe93903c..1688267bb 100644 --- a/src/video_core/surface.cpp +++ b/src/video_core/surface.cpp | |||
| @@ -74,117 +74,131 @@ bool SurfaceTargetIsArray(SurfaceTarget target) { | |||
| 74 | 74 | ||
| 75 | PixelFormat PixelFormatFromDepthFormat(Tegra::DepthFormat format) { | 75 | PixelFormat PixelFormatFromDepthFormat(Tegra::DepthFormat format) { |
| 76 | switch (format) { | 76 | switch (format) { |
| 77 | case Tegra::DepthFormat::S8_Z24_UNORM: | 77 | case Tegra::DepthFormat::S8_UINT_Z24_UNORM: |
| 78 | return PixelFormat::S8Z24; | 78 | return PixelFormat::S8_UINT_D24_UNORM; |
| 79 | case Tegra::DepthFormat::Z24_S8_UNORM: | 79 | case Tegra::DepthFormat::D24S8_UNORM: |
| 80 | return PixelFormat::Z24S8; | 80 | return PixelFormat::D24_UNORM_S8_UINT; |
| 81 | case Tegra::DepthFormat::Z32_FLOAT: | 81 | case Tegra::DepthFormat::D32_FLOAT: |
| 82 | return PixelFormat::Z32F; | 82 | return PixelFormat::D32_FLOAT; |
| 83 | case Tegra::DepthFormat::Z16_UNORM: | 83 | case Tegra::DepthFormat::D16_UNORM: |
| 84 | return PixelFormat::Z16; | 84 | return PixelFormat::D16_UNORM; |
| 85 | case Tegra::DepthFormat::Z32_S8_X24_FLOAT: | 85 | case Tegra::DepthFormat::D32_FLOAT_S8X24_UINT: |
| 86 | return PixelFormat::Z32FS8; | 86 | return PixelFormat::D32_FLOAT_S8_UINT; |
| 87 | default: | 87 | default: |
| 88 | LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format)); | 88 | UNIMPLEMENTED_MSG("Unimplemented format={}", static_cast<u32>(format)); |
| 89 | UNREACHABLE(); | 89 | return PixelFormat::S8_UINT_D24_UNORM; |
| 90 | return PixelFormat::S8Z24; | ||
| 91 | } | 90 | } |
| 92 | } | 91 | } |
| 93 | 92 | ||
| 94 | PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format) { | 93 | PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format) { |
| 95 | switch (format) { | 94 | switch (format) { |
| 96 | case Tegra::RenderTargetFormat::RGBA8_SRGB: | 95 | case Tegra::RenderTargetFormat::R32B32G32A32_FLOAT: |
| 97 | return PixelFormat::RGBA8_SRGB; | 96 | return PixelFormat::R32G32B32A32_FLOAT; |
| 98 | case Tegra::RenderTargetFormat::RGBA8_UNORM: | 97 | case Tegra::RenderTargetFormat::R32G32B32A32_SINT: |
| 99 | return PixelFormat::ABGR8U; | 98 | return PixelFormat::R32G32B32A32_SINT; |
| 100 | case Tegra::RenderTargetFormat::RGBA8_SNORM: | 99 | case Tegra::RenderTargetFormat::R32G32B32A32_UINT: |
| 101 | return PixelFormat::ABGR8S; | 100 | return PixelFormat::R32G32B32A32_UINT; |
| 102 | case Tegra::RenderTargetFormat::RGBA8_UINT: | 101 | case Tegra::RenderTargetFormat::R16G16B16A16_UNORM: |
| 103 | return PixelFormat::ABGR8UI; | 102 | return PixelFormat::R16G16B16A16_UNORM; |
| 104 | case Tegra::RenderTargetFormat::BGRA8_SRGB: | 103 | case Tegra::RenderTargetFormat::R16G16B16A16_SNORM: |
| 105 | return PixelFormat::BGRA8_SRGB; | 104 | return PixelFormat::R16G16B16A16_SNORM; |
| 106 | case Tegra::RenderTargetFormat::BGRA8_UNORM: | 105 | case Tegra::RenderTargetFormat::R16G16B16A16_SINT: |
| 107 | return PixelFormat::BGRA8; | 106 | return PixelFormat::R16G16B16A16_SINT; |
| 108 | case Tegra::RenderTargetFormat::RGB10_A2_UNORM: | 107 | case Tegra::RenderTargetFormat::R16G16B16A16_UINT: |
| 109 | return PixelFormat::A2B10G10R10U; | 108 | return PixelFormat::R16G16B16A16_UINT; |
| 110 | case Tegra::RenderTargetFormat::RGBA16_FLOAT: | 109 | case Tegra::RenderTargetFormat::R16G16B16A16_FLOAT: |
| 111 | return PixelFormat::RGBA16F; | 110 | return PixelFormat::R16G16B16A16_FLOAT; |
| 112 | case Tegra::RenderTargetFormat::RGBA16_UNORM: | 111 | case Tegra::RenderTargetFormat::R32G32_FLOAT: |
| 113 | return PixelFormat::RGBA16U; | 112 | return PixelFormat::R32G32_FLOAT; |
| 114 | case Tegra::RenderTargetFormat::RGBA16_SNORM: | 113 | case Tegra::RenderTargetFormat::R32G32_SINT: |
| 115 | return PixelFormat::RGBA16S; | 114 | return PixelFormat::R32G32_SINT; |
| 116 | case Tegra::RenderTargetFormat::RGBA16_UINT: | 115 | case Tegra::RenderTargetFormat::R32G32_UINT: |
| 117 | return PixelFormat::RGBA16UI; | 116 | return PixelFormat::R32G32_UINT; |
| 118 | case Tegra::RenderTargetFormat::RGBA32_FLOAT: | 117 | case Tegra::RenderTargetFormat::R16G16B16X16_FLOAT: |
| 119 | return PixelFormat::RGBA32F; | 118 | return PixelFormat::R16G16B16X16_FLOAT; |
| 120 | case Tegra::RenderTargetFormat::RG32_FLOAT: | 119 | case Tegra::RenderTargetFormat::B8G8R8A8_UNORM: |
| 121 | return PixelFormat::RG32F; | 120 | return PixelFormat::B8G8R8A8_UNORM; |
| 122 | case Tegra::RenderTargetFormat::R11G11B10_FLOAT: | 121 | case Tegra::RenderTargetFormat::B8G8R8A8_SRGB: |
| 123 | return PixelFormat::R11FG11FB10F; | 122 | return PixelFormat::B8G8R8A8_SRGB; |
| 124 | case Tegra::RenderTargetFormat::B5G6R5_UNORM: | 123 | case Tegra::RenderTargetFormat::A2B10G10R10_UNORM: |
| 125 | return PixelFormat::B5G6R5U; | 124 | return PixelFormat::A2B10G10R10_UNORM; |
| 126 | case Tegra::RenderTargetFormat::BGR5A1_UNORM: | 125 | case Tegra::RenderTargetFormat::A2B10G10R10_UINT: |
| 127 | return PixelFormat::A1B5G5R5U; | 126 | return PixelFormat::A2B10G10R10_UINT; |
| 128 | case Tegra::RenderTargetFormat::RGBA32_UINT: | 127 | case Tegra::RenderTargetFormat::A8B8G8R8_UNORM: |
| 129 | return PixelFormat::RGBA32UI; | 128 | return PixelFormat::A8B8G8R8_UNORM; |
| 130 | case Tegra::RenderTargetFormat::R8_UNORM: | 129 | case Tegra::RenderTargetFormat::A8B8G8R8_SRGB: |
| 131 | return PixelFormat::R8U; | 130 | return PixelFormat::A8B8G8R8_SRGB; |
| 132 | case Tegra::RenderTargetFormat::R8_UINT: | 131 | case Tegra::RenderTargetFormat::A8B8G8R8_SNORM: |
| 133 | return PixelFormat::R8UI; | 132 | return PixelFormat::A8B8G8R8_SNORM; |
| 134 | case Tegra::RenderTargetFormat::RG16_FLOAT: | 133 | case Tegra::RenderTargetFormat::A8B8G8R8_SINT: |
| 135 | return PixelFormat::RG16F; | 134 | return PixelFormat::A8B8G8R8_SINT; |
| 136 | case Tegra::RenderTargetFormat::RG16_UINT: | 135 | case Tegra::RenderTargetFormat::A8B8G8R8_UINT: |
| 137 | return PixelFormat::RG16UI; | 136 | return PixelFormat::A8B8G8R8_UINT; |
| 138 | case Tegra::RenderTargetFormat::RG16_SINT: | 137 | case Tegra::RenderTargetFormat::R16G16_UNORM: |
| 139 | return PixelFormat::RG16I; | 138 | return PixelFormat::R16G16_UNORM; |
| 140 | case Tegra::RenderTargetFormat::RG16_UNORM: | 139 | case Tegra::RenderTargetFormat::R16G16_SNORM: |
| 141 | return PixelFormat::RG16; | 140 | return PixelFormat::R16G16_SNORM; |
| 142 | case Tegra::RenderTargetFormat::RG16_SNORM: | 141 | case Tegra::RenderTargetFormat::R16G16_SINT: |
| 143 | return PixelFormat::RG16S; | 142 | return PixelFormat::R16G16_SINT; |
| 144 | case Tegra::RenderTargetFormat::RG8_UNORM: | 143 | case Tegra::RenderTargetFormat::R16G16_UINT: |
| 145 | return PixelFormat::RG8U; | 144 | return PixelFormat::R16G16_UINT; |
| 146 | case Tegra::RenderTargetFormat::RG8_SNORM: | 145 | case Tegra::RenderTargetFormat::R16G16_FLOAT: |
| 147 | return PixelFormat::RG8S; | 146 | return PixelFormat::R16G16_FLOAT; |
| 148 | case Tegra::RenderTargetFormat::RG8_UINT: | 147 | case Tegra::RenderTargetFormat::B10G11R11_FLOAT: |
| 149 | return PixelFormat::RG8UI; | 148 | return PixelFormat::B10G11R11_FLOAT; |
| 150 | case Tegra::RenderTargetFormat::R16_FLOAT: | 149 | case Tegra::RenderTargetFormat::R32_SINT: |
| 151 | return PixelFormat::R16F; | 150 | return PixelFormat::R32_SINT; |
| 151 | case Tegra::RenderTargetFormat::R32_UINT: | ||
| 152 | return PixelFormat::R32_UINT; | ||
| 153 | case Tegra::RenderTargetFormat::R32_FLOAT: | ||
| 154 | return PixelFormat::R32_FLOAT; | ||
| 155 | case Tegra::RenderTargetFormat::R5G6B5_UNORM: | ||
| 156 | return PixelFormat::R5G6B5_UNORM; | ||
| 157 | case Tegra::RenderTargetFormat::A1R5G5B5_UNORM: | ||
| 158 | return PixelFormat::A1R5G5B5_UNORM; | ||
| 159 | case Tegra::RenderTargetFormat::R8G8_UNORM: | ||
| 160 | return PixelFormat::R8G8_UNORM; | ||
| 161 | case Tegra::RenderTargetFormat::R8G8_SNORM: | ||
| 162 | return PixelFormat::R8G8_SNORM; | ||
| 163 | case Tegra::RenderTargetFormat::R8G8_SINT: | ||
| 164 | return PixelFormat::R8G8_SINT; | ||
| 165 | case Tegra::RenderTargetFormat::R8G8_UINT: | ||
| 166 | return PixelFormat::R8G8_UINT; | ||
| 152 | case Tegra::RenderTargetFormat::R16_UNORM: | 167 | case Tegra::RenderTargetFormat::R16_UNORM: |
| 153 | return PixelFormat::R16U; | 168 | return PixelFormat::R16_UNORM; |
| 154 | case Tegra::RenderTargetFormat::R16_SNORM: | 169 | case Tegra::RenderTargetFormat::R16_SNORM: |
| 155 | return PixelFormat::R16S; | 170 | return PixelFormat::R16_SNORM; |
| 156 | case Tegra::RenderTargetFormat::R16_UINT: | ||
| 157 | return PixelFormat::R16UI; | ||
| 158 | case Tegra::RenderTargetFormat::R16_SINT: | 171 | case Tegra::RenderTargetFormat::R16_SINT: |
| 159 | return PixelFormat::R16I; | 172 | return PixelFormat::R16_SINT; |
| 160 | case Tegra::RenderTargetFormat::R32_FLOAT: | 173 | case Tegra::RenderTargetFormat::R16_UINT: |
| 161 | return PixelFormat::R32F; | 174 | return PixelFormat::R16_UINT; |
| 162 | case Tegra::RenderTargetFormat::R32_SINT: | 175 | case Tegra::RenderTargetFormat::R16_FLOAT: |
| 163 | return PixelFormat::R32I; | 176 | return PixelFormat::R16_FLOAT; |
| 164 | case Tegra::RenderTargetFormat::R32_UINT: | 177 | case Tegra::RenderTargetFormat::R8_UNORM: |
| 165 | return PixelFormat::R32UI; | 178 | return PixelFormat::R8_UNORM; |
| 166 | case Tegra::RenderTargetFormat::RG32_UINT: | 179 | case Tegra::RenderTargetFormat::R8_SNORM: |
| 167 | return PixelFormat::RG32UI; | 180 | return PixelFormat::R8_SNORM; |
| 168 | case Tegra::RenderTargetFormat::RGBX16_FLOAT: | 181 | case Tegra::RenderTargetFormat::R8_SINT: |
| 169 | return PixelFormat::RGBX16F; | 182 | return PixelFormat::R8_SINT; |
| 183 | case Tegra::RenderTargetFormat::R8_UINT: | ||
| 184 | return PixelFormat::R8_UINT; | ||
| 170 | default: | 185 | default: |
| 171 | LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format)); | 186 | UNIMPLEMENTED_MSG("Unimplemented format={}", static_cast<int>(format)); |
| 172 | UNREACHABLE(); | 187 | return PixelFormat::A8B8G8R8_UNORM; |
| 173 | return PixelFormat::RGBA8_SRGB; | ||
| 174 | } | 188 | } |
| 175 | } | 189 | } |
| 176 | 190 | ||
| 177 | PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat format) { | 191 | PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat format) { |
| 178 | switch (format) { | 192 | switch (format) { |
| 179 | case Tegra::FramebufferConfig::PixelFormat::ABGR8: | 193 | case Tegra::FramebufferConfig::PixelFormat::A8B8G8R8_UNORM: |
| 180 | return PixelFormat::ABGR8U; | 194 | return PixelFormat::A8B8G8R8_UNORM; |
| 181 | case Tegra::FramebufferConfig::PixelFormat::RGB565: | 195 | case Tegra::FramebufferConfig::PixelFormat::RGB565_UNORM: |
| 182 | return PixelFormat::B5G6R5U; | 196 | return PixelFormat::R5G6B5_UNORM; |
| 183 | case Tegra::FramebufferConfig::PixelFormat::BGRA8: | 197 | case Tegra::FramebufferConfig::PixelFormat::B8G8R8A8_UNORM: |
| 184 | return PixelFormat::BGRA8; | 198 | return PixelFormat::B8G8R8A8_UNORM; |
| 185 | default: | 199 | default: |
| 186 | UNIMPLEMENTED_MSG("Unimplemented format={}", static_cast<u32>(format)); | 200 | UNIMPLEMENTED_MSG("Unimplemented format={}", static_cast<u32>(format)); |
| 187 | return PixelFormat::ABGR8U; | 201 | return PixelFormat::A8B8G8R8_UNORM; |
| 188 | } | 202 | } |
| 189 | } | 203 | } |
| 190 | 204 | ||
| @@ -212,27 +226,27 @@ SurfaceType GetFormatType(PixelFormat pixel_format) { | |||
| 212 | 226 | ||
| 213 | bool IsPixelFormatASTC(PixelFormat format) { | 227 | bool IsPixelFormatASTC(PixelFormat format) { |
| 214 | switch (format) { | 228 | switch (format) { |
| 215 | case PixelFormat::ASTC_2D_4X4: | 229 | case PixelFormat::ASTC_2D_4X4_UNORM: |
| 216 | case PixelFormat::ASTC_2D_5X4: | 230 | case PixelFormat::ASTC_2D_5X4_UNORM: |
| 217 | case PixelFormat::ASTC_2D_5X5: | 231 | case PixelFormat::ASTC_2D_5X5_UNORM: |
| 218 | case PixelFormat::ASTC_2D_8X8: | 232 | case PixelFormat::ASTC_2D_8X8_UNORM: |
| 219 | case PixelFormat::ASTC_2D_8X5: | 233 | case PixelFormat::ASTC_2D_8X5_UNORM: |
| 220 | case PixelFormat::ASTC_2D_4X4_SRGB: | 234 | case PixelFormat::ASTC_2D_4X4_SRGB: |
| 221 | case PixelFormat::ASTC_2D_5X4_SRGB: | 235 | case PixelFormat::ASTC_2D_5X4_SRGB: |
| 222 | case PixelFormat::ASTC_2D_5X5_SRGB: | 236 | case PixelFormat::ASTC_2D_5X5_SRGB: |
| 223 | case PixelFormat::ASTC_2D_8X8_SRGB: | 237 | case PixelFormat::ASTC_2D_8X8_SRGB: |
| 224 | case PixelFormat::ASTC_2D_8X5_SRGB: | 238 | case PixelFormat::ASTC_2D_8X5_SRGB: |
| 225 | case PixelFormat::ASTC_2D_10X8: | 239 | case PixelFormat::ASTC_2D_10X8_UNORM: |
| 226 | case PixelFormat::ASTC_2D_10X8_SRGB: | 240 | case PixelFormat::ASTC_2D_10X8_SRGB: |
| 227 | case PixelFormat::ASTC_2D_6X6: | 241 | case PixelFormat::ASTC_2D_6X6_UNORM: |
| 228 | case PixelFormat::ASTC_2D_6X6_SRGB: | 242 | case PixelFormat::ASTC_2D_6X6_SRGB: |
| 229 | case PixelFormat::ASTC_2D_10X10: | 243 | case PixelFormat::ASTC_2D_10X10_UNORM: |
| 230 | case PixelFormat::ASTC_2D_10X10_SRGB: | 244 | case PixelFormat::ASTC_2D_10X10_SRGB: |
| 231 | case PixelFormat::ASTC_2D_12X12: | 245 | case PixelFormat::ASTC_2D_12X12_UNORM: |
| 232 | case PixelFormat::ASTC_2D_12X12_SRGB: | 246 | case PixelFormat::ASTC_2D_12X12_SRGB: |
| 233 | case PixelFormat::ASTC_2D_8X6: | 247 | case PixelFormat::ASTC_2D_8X6_UNORM: |
| 234 | case PixelFormat::ASTC_2D_8X6_SRGB: | 248 | case PixelFormat::ASTC_2D_8X6_SRGB: |
| 235 | case PixelFormat::ASTC_2D_6X5: | 249 | case PixelFormat::ASTC_2D_6X5_UNORM: |
| 236 | case PixelFormat::ASTC_2D_6X5_SRGB: | 250 | case PixelFormat::ASTC_2D_6X5_SRGB: |
| 237 | return true; | 251 | return true; |
| 238 | default: | 252 | default: |
| @@ -242,12 +256,12 @@ bool IsPixelFormatASTC(PixelFormat format) { | |||
| 242 | 256 | ||
| 243 | bool IsPixelFormatSRGB(PixelFormat format) { | 257 | bool IsPixelFormatSRGB(PixelFormat format) { |
| 244 | switch (format) { | 258 | switch (format) { |
| 245 | case PixelFormat::RGBA8_SRGB: | 259 | case PixelFormat::A8B8G8R8_SRGB: |
| 246 | case PixelFormat::BGRA8_SRGB: | 260 | case PixelFormat::B8G8R8A8_SRGB: |
| 247 | case PixelFormat::DXT1_SRGB: | 261 | case PixelFormat::BC1_RGBA_SRGB: |
| 248 | case PixelFormat::DXT23_SRGB: | 262 | case PixelFormat::BC2_SRGB: |
| 249 | case PixelFormat::DXT45_SRGB: | 263 | case PixelFormat::BC3_SRGB: |
| 250 | case PixelFormat::BC7U_SRGB: | 264 | case PixelFormat::BC7_SRGB: |
| 251 | case PixelFormat::ASTC_2D_4X4_SRGB: | 265 | case PixelFormat::ASTC_2D_4X4_SRGB: |
| 252 | case PixelFormat::ASTC_2D_8X8_SRGB: | 266 | case PixelFormat::ASTC_2D_8X8_SRGB: |
| 253 | case PixelFormat::ASTC_2D_8X5_SRGB: | 267 | case PixelFormat::ASTC_2D_8X5_SRGB: |
| @@ -269,25 +283,4 @@ std::pair<u32, u32> GetASTCBlockSize(PixelFormat format) { | |||
| 269 | return {GetDefaultBlockWidth(format), GetDefaultBlockHeight(format)}; | 283 | return {GetDefaultBlockWidth(format), GetDefaultBlockHeight(format)}; |
| 270 | } | 284 | } |
| 271 | 285 | ||
| 272 | bool IsFormatBCn(PixelFormat format) { | ||
| 273 | switch (format) { | ||
| 274 | case PixelFormat::DXT1: | ||
| 275 | case PixelFormat::DXT23: | ||
| 276 | case PixelFormat::DXT45: | ||
| 277 | case PixelFormat::DXN1: | ||
| 278 | case PixelFormat::DXN2SNORM: | ||
| 279 | case PixelFormat::DXN2UNORM: | ||
| 280 | case PixelFormat::BC7U: | ||
| 281 | case PixelFormat::BC6H_UF16: | ||
| 282 | case PixelFormat::BC6H_SF16: | ||
| 283 | case PixelFormat::DXT1_SRGB: | ||
| 284 | case PixelFormat::DXT23_SRGB: | ||
| 285 | case PixelFormat::DXT45_SRGB: | ||
| 286 | case PixelFormat::BC7U_SRGB: | ||
| 287 | return true; | ||
| 288 | default: | ||
| 289 | return false; | ||
| 290 | } | ||
| 291 | } | ||
| 292 | |||
| 293 | } // namespace VideoCore::Surface | 286 | } // namespace VideoCore::Surface |
diff --git a/src/video_core/surface.h b/src/video_core/surface.h index 6da6a1b97..cfd12fa61 100644 --- a/src/video_core/surface.h +++ b/src/video_core/surface.h | |||
| @@ -15,94 +15,105 @@ | |||
| 15 | namespace VideoCore::Surface { | 15 | namespace VideoCore::Surface { |
| 16 | 16 | ||
| 17 | enum class PixelFormat { | 17 | enum class PixelFormat { |
| 18 | ABGR8U = 0, | 18 | A8B8G8R8_UNORM, |
| 19 | ABGR8S = 1, | 19 | A8B8G8R8_SNORM, |
| 20 | ABGR8UI = 2, | 20 | A8B8G8R8_SINT, |
| 21 | B5G6R5U = 3, | 21 | A8B8G8R8_UINT, |
| 22 | A2B10G10R10U = 4, | 22 | R5G6B5_UNORM, |
| 23 | A1B5G5R5U = 5, | 23 | B5G6R5_UNORM, |
| 24 | R8U = 6, | 24 | A1R5G5B5_UNORM, |
| 25 | R8UI = 7, | 25 | A2B10G10R10_UNORM, |
| 26 | RGBA16F = 8, | 26 | A2B10G10R10_UINT, |
| 27 | RGBA16U = 9, | 27 | A1B5G5R5_UNORM, |
| 28 | RGBA16S = 10, | 28 | R8_UNORM, |
| 29 | RGBA16UI = 11, | 29 | R8_SNORM, |
| 30 | R11FG11FB10F = 12, | 30 | R8_SINT, |
| 31 | RGBA32UI = 13, | 31 | R8_UINT, |
| 32 | DXT1 = 14, | 32 | R16G16B16A16_FLOAT, |
| 33 | DXT23 = 15, | 33 | R16G16B16A16_UNORM, |
| 34 | DXT45 = 16, | 34 | R16G16B16A16_SNORM, |
| 35 | DXN1 = 17, // This is also known as BC4 | 35 | R16G16B16A16_SINT, |
| 36 | DXN2UNORM = 18, | 36 | R16G16B16A16_UINT, |
| 37 | DXN2SNORM = 19, | 37 | B10G11R11_FLOAT, |
| 38 | BC7U = 20, | 38 | R32G32B32A32_UINT, |
| 39 | BC6H_UF16 = 21, | 39 | BC1_RGBA_UNORM, |
| 40 | BC6H_SF16 = 22, | 40 | BC2_UNORM, |
| 41 | ASTC_2D_4X4 = 23, | 41 | BC3_UNORM, |
| 42 | BGRA8 = 24, | 42 | BC4_UNORM, |
| 43 | RGBA32F = 25, | 43 | BC4_SNORM, |
| 44 | RG32F = 26, | 44 | BC5_UNORM, |
| 45 | R32F = 27, | 45 | BC5_SNORM, |
| 46 | R16F = 28, | 46 | BC7_UNORM, |
| 47 | R16U = 29, | 47 | BC6H_UFLOAT, |
| 48 | R16S = 30, | 48 | BC6H_SFLOAT, |
| 49 | R16UI = 31, | 49 | ASTC_2D_4X4_UNORM, |
| 50 | R16I = 32, | 50 | B8G8R8A8_UNORM, |
| 51 | RG16 = 33, | 51 | R32G32B32A32_FLOAT, |
| 52 | RG16F = 34, | 52 | R32G32B32A32_SINT, |
| 53 | RG16UI = 35, | 53 | R32G32_FLOAT, |
| 54 | RG16I = 36, | 54 | R32G32_SINT, |
| 55 | RG16S = 37, | 55 | R32_FLOAT, |
| 56 | RGB32F = 38, | 56 | R16_FLOAT, |
| 57 | RGBA8_SRGB = 39, | 57 | R16_UNORM, |
| 58 | RG8U = 40, | 58 | R16_SNORM, |
| 59 | RG8S = 41, | 59 | R16_UINT, |
| 60 | RG8UI = 42, | 60 | R16_SINT, |
| 61 | RG32UI = 43, | 61 | R16G16_UNORM, |
| 62 | RGBX16F = 44, | 62 | R16G16_FLOAT, |
| 63 | R32UI = 45, | 63 | R16G16_UINT, |
| 64 | R32I = 46, | 64 | R16G16_SINT, |
| 65 | ASTC_2D_8X8 = 47, | 65 | R16G16_SNORM, |
| 66 | ASTC_2D_8X5 = 48, | 66 | R32G32B32_FLOAT, |
| 67 | ASTC_2D_5X4 = 49, | 67 | A8B8G8R8_SRGB, |
| 68 | BGRA8_SRGB = 50, | 68 | R8G8_UNORM, |
| 69 | DXT1_SRGB = 51, | 69 | R8G8_SNORM, |
| 70 | DXT23_SRGB = 52, | 70 | R8G8_SINT, |
| 71 | DXT45_SRGB = 53, | 71 | R8G8_UINT, |
| 72 | BC7U_SRGB = 54, | 72 | R32G32_UINT, |
| 73 | R4G4B4A4U = 55, | 73 | R16G16B16X16_FLOAT, |
| 74 | ASTC_2D_4X4_SRGB = 56, | 74 | R32_UINT, |
| 75 | ASTC_2D_8X8_SRGB = 57, | 75 | R32_SINT, |
| 76 | ASTC_2D_8X5_SRGB = 58, | 76 | ASTC_2D_8X8_UNORM, |
| 77 | ASTC_2D_5X4_SRGB = 59, | 77 | ASTC_2D_8X5_UNORM, |
| 78 | ASTC_2D_5X5 = 60, | 78 | ASTC_2D_5X4_UNORM, |
| 79 | ASTC_2D_5X5_SRGB = 61, | 79 | B8G8R8A8_SRGB, |
| 80 | ASTC_2D_10X8 = 62, | 80 | BC1_RGBA_SRGB, |
| 81 | ASTC_2D_10X8_SRGB = 63, | 81 | BC2_SRGB, |
| 82 | ASTC_2D_6X6 = 64, | 82 | BC3_SRGB, |
| 83 | ASTC_2D_6X6_SRGB = 65, | 83 | BC7_SRGB, |
| 84 | ASTC_2D_10X10 = 66, | 84 | A4B4G4R4_UNORM, |
| 85 | ASTC_2D_10X10_SRGB = 67, | 85 | ASTC_2D_4X4_SRGB, |
| 86 | ASTC_2D_12X12 = 68, | 86 | ASTC_2D_8X8_SRGB, |
| 87 | ASTC_2D_12X12_SRGB = 69, | 87 | ASTC_2D_8X5_SRGB, |
| 88 | ASTC_2D_8X6 = 70, | 88 | ASTC_2D_5X4_SRGB, |
| 89 | ASTC_2D_8X6_SRGB = 71, | 89 | ASTC_2D_5X5_UNORM, |
| 90 | ASTC_2D_6X5 = 72, | 90 | ASTC_2D_5X5_SRGB, |
| 91 | ASTC_2D_6X5_SRGB = 73, | 91 | ASTC_2D_10X8_UNORM, |
| 92 | E5B9G9R9F = 74, | 92 | ASTC_2D_10X8_SRGB, |
| 93 | ASTC_2D_6X6_UNORM, | ||
| 94 | ASTC_2D_6X6_SRGB, | ||
| 95 | ASTC_2D_10X10_UNORM, | ||
| 96 | ASTC_2D_10X10_SRGB, | ||
| 97 | ASTC_2D_12X12_UNORM, | ||
| 98 | ASTC_2D_12X12_SRGB, | ||
| 99 | ASTC_2D_8X6_UNORM, | ||
| 100 | ASTC_2D_8X6_SRGB, | ||
| 101 | ASTC_2D_6X5_UNORM, | ||
| 102 | ASTC_2D_6X5_SRGB, | ||
| 103 | E5B9G9R9_FLOAT, | ||
| 93 | 104 | ||
| 94 | MaxColorFormat, | 105 | MaxColorFormat, |
| 95 | 106 | ||
| 96 | // Depth formats | 107 | // Depth formats |
| 97 | Z32F = 75, | 108 | D32_FLOAT = MaxColorFormat, |
| 98 | Z16 = 76, | 109 | D16_UNORM, |
| 99 | 110 | ||
| 100 | MaxDepthFormat, | 111 | MaxDepthFormat, |
| 101 | 112 | ||
| 102 | // DepthStencil formats | 113 | // DepthStencil formats |
| 103 | Z24S8 = 77, | 114 | D24_UNORM_S8_UINT = MaxDepthFormat, |
| 104 | S8Z24 = 78, | 115 | S8_UINT_D24_UNORM, |
| 105 | Z32FS8 = 79, | 116 | D32_FLOAT_S8_UINT, |
| 106 | 117 | ||
| 107 | MaxDepthStencilFormat, | 118 | MaxDepthStencilFormat, |
| 108 | 119 | ||
| @@ -130,86 +141,97 @@ enum class SurfaceTarget { | |||
| 130 | }; | 141 | }; |
| 131 | 142 | ||
| 132 | constexpr std::array<u32, MaxPixelFormat> compression_factor_shift_table = {{ | 143 | constexpr std::array<u32, MaxPixelFormat> compression_factor_shift_table = {{ |
| 133 | 0, // ABGR8U | 144 | 0, // A8B8G8R8_UNORM |
| 134 | 0, // ABGR8S | 145 | 0, // A8B8G8R8_SNORM |
| 135 | 0, // ABGR8UI | 146 | 0, // A8B8G8R8_SINT |
| 136 | 0, // B5G6R5U | 147 | 0, // A8B8G8R8_UINT |
| 137 | 0, // A2B10G10R10U | 148 | 0, // R5G6B5_UNORM |
| 138 | 0, // A1B5G5R5U | 149 | 0, // B5G6R5_UNORM |
| 139 | 0, // R8U | 150 | 0, // A1R5G5B5_UNORM |
| 140 | 0, // R8UI | 151 | 0, // A2B10G10R10_UNORM |
| 141 | 0, // RGBA16F | 152 | 0, // A2B10G10R10_UINT |
| 142 | 0, // RGBA16U | 153 | 0, // A1B5G5R5_UNORM |
| 143 | 0, // RGBA16S | 154 | 0, // R8_UNORM |
| 144 | 0, // RGBA16UI | 155 | 0, // R8_SNORM |
| 145 | 0, // R11FG11FB10F | 156 | 0, // R8_SINT |
| 146 | 0, // RGBA32UI | 157 | 0, // R8_UINT |
| 147 | 2, // DXT1 | 158 | 0, // R16G16B16A16_FLOAT |
| 148 | 2, // DXT23 | 159 | 0, // R16G16B16A16_UNORM |
| 149 | 2, // DXT45 | 160 | 0, // R16G16B16A16_SNORM |
| 150 | 2, // DXN1 | 161 | 0, // R16G16B16A16_SINT |
| 151 | 2, // DXN2UNORM | 162 | 0, // R16G16B16A16_UINT |
| 152 | 2, // DXN2SNORM | 163 | 0, // B10G11R11_FLOAT |
| 153 | 2, // BC7U | 164 | 0, // R32G32B32A32_UINT |
| 154 | 2, // BC6H_UF16 | 165 | 2, // BC1_RGBA_UNORM |
| 155 | 2, // BC6H_SF16 | 166 | 2, // BC2_UNORM |
| 156 | 2, // ASTC_2D_4X4 | 167 | 2, // BC3_UNORM |
| 157 | 0, // BGRA8 | 168 | 2, // BC4_UNORM |
| 158 | 0, // RGBA32F | 169 | 2, // BC4_SNORM |
| 159 | 0, // RG32F | 170 | 2, // BC5_UNORM |
| 160 | 0, // R32F | 171 | 2, // BC5_SNORM |
| 161 | 0, // R16F | 172 | 2, // BC7_UNORM |
| 162 | 0, // R16U | 173 | 2, // BC6H_UFLOAT |
| 163 | 0, // R16S | 174 | 2, // BC6H_SFLOAT |
| 164 | 0, // R16UI | 175 | 2, // ASTC_2D_4X4_UNORM |
| 165 | 0, // R16I | 176 | 0, // B8G8R8A8_UNORM |
| 166 | 0, // RG16 | 177 | 0, // R32G32B32A32_FLOAT |
| 167 | 0, // RG16F | 178 | 0, // R32G32B32A32_SINT |
| 168 | 0, // RG16UI | 179 | 0, // R32G32_FLOAT |
| 169 | 0, // RG16I | 180 | 0, // R32G32_SINT |
| 170 | 0, // RG16S | 181 | 0, // R32_FLOAT |
| 171 | 0, // RGB32F | 182 | 0, // R16_FLOAT |
| 172 | 0, // RGBA8_SRGB | 183 | 0, // R16_UNORM |
| 173 | 0, // RG8U | 184 | 0, // R16_SNORM |
| 174 | 0, // RG8S | 185 | 0, // R16_UINT |
| 175 | 0, // RG8UI | 186 | 0, // R16_SINT |
| 176 | 0, // RG32UI | 187 | 0, // R16G16_UNORM |
| 177 | 0, // RGBX16F | 188 | 0, // R16G16_FLOAT |
| 178 | 0, // R32UI | 189 | 0, // R16G16_UINT |
| 179 | 0, // R32I | 190 | 0, // R16G16_SINT |
| 180 | 2, // ASTC_2D_8X8 | 191 | 0, // R16G16_SNORM |
| 181 | 2, // ASTC_2D_8X5 | 192 | 0, // R32G32B32_FLOAT |
| 182 | 2, // ASTC_2D_5X4 | 193 | 0, // A8B8G8R8_SRGB |
| 183 | 0, // BGRA8_SRGB | 194 | 0, // R8G8_UNORM |
| 184 | 2, // DXT1_SRGB | 195 | 0, // R8G8_SNORM |
| 185 | 2, // DXT23_SRGB | 196 | 0, // R8G8_SINT |
| 186 | 2, // DXT45_SRGB | 197 | 0, // R8G8_UINT |
| 187 | 2, // BC7U_SRGB | 198 | 0, // R32G32_UINT |
| 188 | 0, // R4G4B4A4U | 199 | 0, // R16G16B16X16_FLOAT |
| 200 | 0, // R32_UINT | ||
| 201 | 0, // R32_SINT | ||
| 202 | 2, // ASTC_2D_8X8_UNORM | ||
| 203 | 2, // ASTC_2D_8X5_UNORM | ||
| 204 | 2, // ASTC_2D_5X4_UNORM | ||
| 205 | 0, // B8G8R8A8_SRGB | ||
| 206 | 2, // BC1_RGBA_SRGB | ||
| 207 | 2, // BC2_SRGB | ||
| 208 | 2, // BC3_SRGB | ||
| 209 | 2, // BC7_SRGB | ||
| 210 | 0, // A4B4G4R4_UNORM | ||
| 189 | 2, // ASTC_2D_4X4_SRGB | 211 | 2, // ASTC_2D_4X4_SRGB |
| 190 | 2, // ASTC_2D_8X8_SRGB | 212 | 2, // ASTC_2D_8X8_SRGB |
| 191 | 2, // ASTC_2D_8X5_SRGB | 213 | 2, // ASTC_2D_8X5_SRGB |
| 192 | 2, // ASTC_2D_5X4_SRGB | 214 | 2, // ASTC_2D_5X4_SRGB |
| 193 | 2, // ASTC_2D_5X5 | 215 | 2, // ASTC_2D_5X5_UNORM |
| 194 | 2, // ASTC_2D_5X5_SRGB | 216 | 2, // ASTC_2D_5X5_SRGB |
| 195 | 2, // ASTC_2D_10X8 | 217 | 2, // ASTC_2D_10X8_UNORM |
| 196 | 2, // ASTC_2D_10X8_SRGB | 218 | 2, // ASTC_2D_10X8_SRGB |
| 197 | 2, // ASTC_2D_6X6 | 219 | 2, // ASTC_2D_6X6_UNORM |
| 198 | 2, // ASTC_2D_6X6_SRGB | 220 | 2, // ASTC_2D_6X6_SRGB |
| 199 | 2, // ASTC_2D_10X10 | 221 | 2, // ASTC_2D_10X10_UNORM |
| 200 | 2, // ASTC_2D_10X10_SRGB | 222 | 2, // ASTC_2D_10X10_SRGB |
| 201 | 2, // ASTC_2D_12X12 | 223 | 2, // ASTC_2D_12X12_UNORM |
| 202 | 2, // ASTC_2D_12X12_SRGB | 224 | 2, // ASTC_2D_12X12_SRGB |
| 203 | 2, // ASTC_2D_8X6 | 225 | 2, // ASTC_2D_8X6_UNORM |
| 204 | 2, // ASTC_2D_8X6_SRGB | 226 | 2, // ASTC_2D_8X6_SRGB |
| 205 | 2, // ASTC_2D_6X5 | 227 | 2, // ASTC_2D_6X5_UNORM |
| 206 | 2, // ASTC_2D_6X5_SRGB | 228 | 2, // ASTC_2D_6X5_SRGB |
| 207 | 0, // E5B9G9R9F | 229 | 0, // E5B9G9R9_FLOAT |
| 208 | 0, // Z32F | 230 | 0, // D32_FLOAT |
| 209 | 0, // Z16 | 231 | 0, // D16_UNORM |
| 210 | 0, // Z24S8 | 232 | 0, // D24_UNORM_S8_UINT |
| 211 | 0, // S8Z24 | 233 | 0, // S8_UINT_D24_UNORM |
| 212 | 0, // Z32FS8 | 234 | 0, // D32_FLOAT_S8_UINT |
| 213 | }}; | 235 | }}; |
| 214 | 236 | ||
| 215 | /** | 237 | /** |
| @@ -229,86 +251,97 @@ inline constexpr u32 GetCompressionFactor(PixelFormat format) { | |||
| 229 | } | 251 | } |
| 230 | 252 | ||
| 231 | constexpr std::array<u32, MaxPixelFormat> block_width_table = {{ | 253 | constexpr std::array<u32, MaxPixelFormat> block_width_table = {{ |
| 232 | 1, // ABGR8U | 254 | 1, // A8B8G8R8_UNORM |
| 233 | 1, // ABGR8S | 255 | 1, // A8B8G8R8_SNORM |
| 234 | 1, // ABGR8UI | 256 | 1, // A8B8G8R8_SINT |
| 235 | 1, // B5G6R5U | 257 | 1, // A8B8G8R8_UINT |
| 236 | 1, // A2B10G10R10U | 258 | 1, // R5G6B5_UNORM |
| 237 | 1, // A1B5G5R5U | 259 | 1, // B5G6R5_UNORM |
| 238 | 1, // R8U | 260 | 1, // A1R5G5B5_UNORM |
| 239 | 1, // R8UI | 261 | 1, // A2B10G10R10_UNORM |
| 240 | 1, // RGBA16F | 262 | 1, // A2B10G10R10_UINT |
| 241 | 1, // RGBA16U | 263 | 1, // A1B5G5R5_UNORM |
| 242 | 1, // RGBA16S | 264 | 1, // R8_UNORM |
| 243 | 1, // RGBA16UI | 265 | 1, // R8_SNORM |
| 244 | 1, // R11FG11FB10F | 266 | 1, // R8_SINT |
| 245 | 1, // RGBA32UI | 267 | 1, // R8_UINT |
| 246 | 4, // DXT1 | 268 | 1, // R16G16B16A16_FLOAT |
| 247 | 4, // DXT23 | 269 | 1, // R16G16B16A16_UNORM |
| 248 | 4, // DXT45 | 270 | 1, // R16G16B16A16_SNORM |
| 249 | 4, // DXN1 | 271 | 1, // R16G16B16A16_SINT |
| 250 | 4, // DXN2UNORM | 272 | 1, // R16G16B16A16_UINT |
| 251 | 4, // DXN2SNORM | 273 | 1, // B10G11R11_FLOAT |
| 252 | 4, // BC7U | 274 | 1, // R32G32B32A32_UINT |
| 253 | 4, // BC6H_UF16 | 275 | 4, // BC1_RGBA_UNORM |
| 254 | 4, // BC6H_SF16 | 276 | 4, // BC2_UNORM |
| 255 | 4, // ASTC_2D_4X4 | 277 | 4, // BC3_UNORM |
| 256 | 1, // BGRA8 | 278 | 4, // BC4_UNORM |
| 257 | 1, // RGBA32F | 279 | 4, // BC4_SNORM |
| 258 | 1, // RG32F | 280 | 4, // BC5_UNORM |
| 259 | 1, // R32F | 281 | 4, // BC5_SNORM |
| 260 | 1, // R16F | 282 | 4, // BC7_UNORM |
| 261 | 1, // R16U | 283 | 4, // BC6H_UFLOAT |
| 262 | 1, // R16S | 284 | 4, // BC6H_SFLOAT |
| 263 | 1, // R16UI | 285 | 4, // ASTC_2D_4X4_UNORM |
| 264 | 1, // R16I | 286 | 1, // B8G8R8A8_UNORM |
| 265 | 1, // RG16 | 287 | 1, // R32G32B32A32_FLOAT |
| 266 | 1, // RG16F | 288 | 1, // R32G32B32A32_SINT |
| 267 | 1, // RG16UI | 289 | 1, // R32G32_FLOAT |
| 268 | 1, // RG16I | 290 | 1, // R32G32_SINT |
| 269 | 1, // RG16S | 291 | 1, // R32_FLOAT |
| 270 | 1, // RGB32F | 292 | 1, // R16_FLOAT |
| 271 | 1, // RGBA8_SRGB | 293 | 1, // R16_UNORM |
| 272 | 1, // RG8U | 294 | 1, // R16_SNORM |
| 273 | 1, // RG8S | 295 | 1, // R16_UINT |
| 274 | 1, // RG8UI | 296 | 1, // R16_SINT |
| 275 | 1, // RG32UI | 297 | 1, // R16G16_UNORM |
| 276 | 1, // RGBX16F | 298 | 1, // R16G16_FLOAT |
| 277 | 1, // R32UI | 299 | 1, // R16G16_UINT |
| 278 | 1, // R32I | 300 | 1, // R16G16_SINT |
| 279 | 8, // ASTC_2D_8X8 | 301 | 1, // R16G16_SNORM |
| 280 | 8, // ASTC_2D_8X5 | 302 | 1, // R32G32B32_FLOAT |
| 281 | 5, // ASTC_2D_5X4 | 303 | 1, // A8B8G8R8_SRGB |
| 282 | 1, // BGRA8_SRGB | 304 | 1, // R8G8_UNORM |
| 283 | 4, // DXT1_SRGB | 305 | 1, // R8G8_SNORM |
| 284 | 4, // DXT23_SRGB | 306 | 1, // R8G8_SINT |
| 285 | 4, // DXT45_SRGB | 307 | 1, // R8G8_UINT |
| 286 | 4, // BC7U_SRGB | 308 | 1, // R32G32_UINT |
| 287 | 1, // R4G4B4A4U | 309 | 1, // R16G16B16X16_FLOAT |
| 310 | 1, // R32_UINT | ||
| 311 | 1, // R32_SINT | ||
| 312 | 8, // ASTC_2D_8X8_UNORM | ||
| 313 | 8, // ASTC_2D_8X5_UNORM | ||
| 314 | 5, // ASTC_2D_5X4_UNORM | ||
| 315 | 1, // B8G8R8A8_SRGB | ||
| 316 | 4, // BC1_RGBA_SRGB | ||
| 317 | 4, // BC2_SRGB | ||
| 318 | 4, // BC3_SRGB | ||
| 319 | 4, // BC7_SRGB | ||
| 320 | 1, // A4B4G4R4_UNORM | ||
| 288 | 4, // ASTC_2D_4X4_SRGB | 321 | 4, // ASTC_2D_4X4_SRGB |
| 289 | 8, // ASTC_2D_8X8_SRGB | 322 | 8, // ASTC_2D_8X8_SRGB |
| 290 | 8, // ASTC_2D_8X5_SRGB | 323 | 8, // ASTC_2D_8X5_SRGB |
| 291 | 5, // ASTC_2D_5X4_SRGB | 324 | 5, // ASTC_2D_5X4_SRGB |
| 292 | 5, // ASTC_2D_5X5 | 325 | 5, // ASTC_2D_5X5_UNORM |
| 293 | 5, // ASTC_2D_5X5_SRGB | 326 | 5, // ASTC_2D_5X5_SRGB |
| 294 | 10, // ASTC_2D_10X8 | 327 | 10, // ASTC_2D_10X8_UNORM |
| 295 | 10, // ASTC_2D_10X8_SRGB | 328 | 10, // ASTC_2D_10X8_SRGB |
| 296 | 6, // ASTC_2D_6X6 | 329 | 6, // ASTC_2D_6X6_UNORM |
| 297 | 6, // ASTC_2D_6X6_SRGB | 330 | 6, // ASTC_2D_6X6_SRGB |
| 298 | 10, // ASTC_2D_10X10 | 331 | 10, // ASTC_2D_10X10_UNORM |
| 299 | 10, // ASTC_2D_10X10_SRGB | 332 | 10, // ASTC_2D_10X10_SRGB |
| 300 | 12, // ASTC_2D_12X12 | 333 | 12, // ASTC_2D_12X12_UNORM |
| 301 | 12, // ASTC_2D_12X12_SRGB | 334 | 12, // ASTC_2D_12X12_SRGB |
| 302 | 8, // ASTC_2D_8X6 | 335 | 8, // ASTC_2D_8X6_UNORM |
| 303 | 8, // ASTC_2D_8X6_SRGB | 336 | 8, // ASTC_2D_8X6_SRGB |
| 304 | 6, // ASTC_2D_6X5 | 337 | 6, // ASTC_2D_6X5_UNORM |
| 305 | 6, // ASTC_2D_6X5_SRGB | 338 | 6, // ASTC_2D_6X5_SRGB |
| 306 | 1, // E5B9G9R9F | 339 | 1, // E5B9G9R9_FLOAT |
| 307 | 1, // Z32F | 340 | 1, // D32_FLOAT |
| 308 | 1, // Z16 | 341 | 1, // D16_UNORM |
| 309 | 1, // Z24S8 | 342 | 1, // D24_UNORM_S8_UINT |
| 310 | 1, // S8Z24 | 343 | 1, // S8_UINT_D24_UNORM |
| 311 | 1, // Z32FS8 | 344 | 1, // D32_FLOAT_S8_UINT |
| 312 | }}; | 345 | }}; |
| 313 | 346 | ||
| 314 | static constexpr u32 GetDefaultBlockWidth(PixelFormat format) { | 347 | static constexpr u32 GetDefaultBlockWidth(PixelFormat format) { |
| @@ -320,86 +353,97 @@ static constexpr u32 GetDefaultBlockWidth(PixelFormat format) { | |||
| 320 | } | 353 | } |
| 321 | 354 | ||
| 322 | constexpr std::array<u32, MaxPixelFormat> block_height_table = {{ | 355 | constexpr std::array<u32, MaxPixelFormat> block_height_table = {{ |
| 323 | 1, // ABGR8U | 356 | 1, // A8B8G8R8_UNORM |
| 324 | 1, // ABGR8S | 357 | 1, // A8B8G8R8_SNORM |
| 325 | 1, // ABGR8UI | 358 | 1, // A8B8G8R8_SINT |
| 326 | 1, // B5G6R5U | 359 | 1, // A8B8G8R8_UINT |
| 327 | 1, // A2B10G10R10U | 360 | 1, // R5G6B5_UNORM |
| 328 | 1, // A1B5G5R5U | 361 | 1, // B5G6R5_UNORM |
| 329 | 1, // R8U | 362 | 1, // A1R5G5B5_UNORM |
| 330 | 1, // R8UI | 363 | 1, // A2B10G10R10_UNORM |
| 331 | 1, // RGBA16F | 364 | 1, // A2B10G10R10_UINT |
| 332 | 1, // RGBA16U | 365 | 1, // A1B5G5R5_UNORM |
| 333 | 1, // RGBA16S | 366 | 1, // R8_UNORM |
| 334 | 1, // RGBA16UI | 367 | 1, // R8_SNORM |
| 335 | 1, // R11FG11FB10F | 368 | 1, // R8_SINT |
| 336 | 1, // RGBA32UI | 369 | 1, // R8_UINT |
| 337 | 4, // DXT1 | 370 | 1, // R16G16B16A16_FLOAT |
| 338 | 4, // DXT23 | 371 | 1, // R16G16B16A16_UNORM |
| 339 | 4, // DXT45 | 372 | 1, // R16G16B16A16_SNORM |
| 340 | 4, // DXN1 | 373 | 1, // R16G16B16A16_SINT |
| 341 | 4, // DXN2UNORM | 374 | 1, // R16G16B16A16_UINT |
| 342 | 4, // DXN2SNORM | 375 | 1, // B10G11R11_FLOAT |
| 343 | 4, // BC7U | 376 | 1, // R32G32B32A32_UINT |
| 344 | 4, // BC6H_UF16 | 377 | 4, // BC1_RGBA_UNORM |
| 345 | 4, // BC6H_SF16 | 378 | 4, // BC2_UNORM |
| 346 | 4, // ASTC_2D_4X4 | 379 | 4, // BC3_UNORM |
| 347 | 1, // BGRA8 | 380 | 4, // BC4_UNORM |
| 348 | 1, // RGBA32F | 381 | 4, // BC4_SNORM |
| 349 | 1, // RG32F | 382 | 4, // BC5_UNORM |
| 350 | 1, // R32F | 383 | 4, // BC5_SNORM |
| 351 | 1, // R16F | 384 | 4, // BC7_UNORM |
| 352 | 1, // R16U | 385 | 4, // BC6H_UFLOAT |
| 353 | 1, // R16S | 386 | 4, // BC6H_SFLOAT |
| 354 | 1, // R16UI | 387 | 4, // ASTC_2D_4X4_UNORM |
| 355 | 1, // R16I | 388 | 1, // B8G8R8A8_UNORM |
| 356 | 1, // RG16 | 389 | 1, // R32G32B32A32_FLOAT |
| 357 | 1, // RG16F | 390 | 1, // R32G32B32A32_SINT |
| 358 | 1, // RG16UI | 391 | 1, // R32G32_FLOAT |
| 359 | 1, // RG16I | 392 | 1, // R32G32_SINT |
| 360 | 1, // RG16S | 393 | 1, // R32_FLOAT |
| 361 | 1, // RGB32F | 394 | 1, // R16_FLOAT |
| 362 | 1, // RGBA8_SRGB | 395 | 1, // R16_UNORM |
| 363 | 1, // RG8U | 396 | 1, // R16_SNORM |
| 364 | 1, // RG8S | 397 | 1, // R16_UINT |
| 365 | 1, // RG8UI | 398 | 1, // R16_SINT |
| 366 | 1, // RG32UI | 399 | 1, // R16G16_UNORM |
| 367 | 1, // RGBX16F | 400 | 1, // R16G16_FLOAT |
| 368 | 1, // R32UI | 401 | 1, // R16G16_UINT |
| 369 | 1, // R32I | 402 | 1, // R16G16_SINT |
| 370 | 8, // ASTC_2D_8X8 | 403 | 1, // R16G16_SNORM |
| 371 | 5, // ASTC_2D_8X5 | 404 | 1, // R32G32B32_FLOAT |
| 372 | 4, // ASTC_2D_5X4 | 405 | 1, // A8B8G8R8_SRGB |
| 373 | 1, // BGRA8_SRGB | 406 | 1, // R8G8_UNORM |
| 374 | 4, // DXT1_SRGB | 407 | 1, // R8G8_SNORM |
| 375 | 4, // DXT23_SRGB | 408 | 1, // R8G8_SINT |
| 376 | 4, // DXT45_SRGB | 409 | 1, // R8G8_UINT |
| 377 | 4, // BC7U_SRGB | 410 | 1, // R32G32_UINT |
| 378 | 1, // R4G4B4A4U | 411 | 1, // R16G16B16X16_FLOAT |
| 412 | 1, // R32_UINT | ||
| 413 | 1, // R32_SINT | ||
| 414 | 8, // ASTC_2D_8X8_UNORM | ||
| 415 | 5, // ASTC_2D_8X5_UNORM | ||
| 416 | 4, // ASTC_2D_5X4_UNORM | ||
| 417 | 1, // B8G8R8A8_SRGB | ||
| 418 | 4, // BC1_RGBA_SRGB | ||
| 419 | 4, // BC2_SRGB | ||
| 420 | 4, // BC3_SRGB | ||
| 421 | 4, // BC7_SRGB | ||
| 422 | 1, // A4B4G4R4_UNORM | ||
| 379 | 4, // ASTC_2D_4X4_SRGB | 423 | 4, // ASTC_2D_4X4_SRGB |
| 380 | 8, // ASTC_2D_8X8_SRGB | 424 | 8, // ASTC_2D_8X8_SRGB |
| 381 | 5, // ASTC_2D_8X5_SRGB | 425 | 5, // ASTC_2D_8X5_SRGB |
| 382 | 4, // ASTC_2D_5X4_SRGB | 426 | 4, // ASTC_2D_5X4_SRGB |
| 383 | 5, // ASTC_2D_5X5 | 427 | 5, // ASTC_2D_5X5_UNORM |
| 384 | 5, // ASTC_2D_5X5_SRGB | 428 | 5, // ASTC_2D_5X5_SRGB |
| 385 | 8, // ASTC_2D_10X8 | 429 | 8, // ASTC_2D_10X8_UNORM |
| 386 | 8, // ASTC_2D_10X8_SRGB | 430 | 8, // ASTC_2D_10X8_SRGB |
| 387 | 6, // ASTC_2D_6X6 | 431 | 6, // ASTC_2D_6X6_UNORM |
| 388 | 6, // ASTC_2D_6X6_SRGB | 432 | 6, // ASTC_2D_6X6_SRGB |
| 389 | 10, // ASTC_2D_10X10 | 433 | 10, // ASTC_2D_10X10_UNORM |
| 390 | 10, // ASTC_2D_10X10_SRGB | 434 | 10, // ASTC_2D_10X10_SRGB |
| 391 | 12, // ASTC_2D_12X12 | 435 | 12, // ASTC_2D_12X12_UNORM |
| 392 | 12, // ASTC_2D_12X12_SRGB | 436 | 12, // ASTC_2D_12X12_SRGB |
| 393 | 6, // ASTC_2D_8X6 | 437 | 6, // ASTC_2D_8X6_UNORM |
| 394 | 6, // ASTC_2D_8X6_SRGB | 438 | 6, // ASTC_2D_8X6_SRGB |
| 395 | 5, // ASTC_2D_6X5 | 439 | 5, // ASTC_2D_6X5_UNORM |
| 396 | 5, // ASTC_2D_6X5_SRGB | 440 | 5, // ASTC_2D_6X5_SRGB |
| 397 | 1, // E5B9G9R9F | 441 | 1, // E5B9G9R9_FLOAT |
| 398 | 1, // Z32F | 442 | 1, // D32_FLOAT |
| 399 | 1, // Z16 | 443 | 1, // D16_UNORM |
| 400 | 1, // Z24S8 | 444 | 1, // D24_UNORM_S8_UINT |
| 401 | 1, // S8Z24 | 445 | 1, // S8_UINT_D24_UNORM |
| 402 | 1, // Z32FS8 | 446 | 1, // D32_FLOAT_S8_UINT |
| 403 | }}; | 447 | }}; |
| 404 | 448 | ||
| 405 | static constexpr u32 GetDefaultBlockHeight(PixelFormat format) { | 449 | static constexpr u32 GetDefaultBlockHeight(PixelFormat format) { |
| @@ -411,86 +455,97 @@ static constexpr u32 GetDefaultBlockHeight(PixelFormat format) { | |||
| 411 | } | 455 | } |
| 412 | 456 | ||
| 413 | constexpr std::array<u32, MaxPixelFormat> bpp_table = {{ | 457 | constexpr std::array<u32, MaxPixelFormat> bpp_table = {{ |
| 414 | 32, // ABGR8U | 458 | 32, // A8B8G8R8_UNORM |
| 415 | 32, // ABGR8S | 459 | 32, // A8B8G8R8_SNORM |
| 416 | 32, // ABGR8UI | 460 | 32, // A8B8G8R8_SINT |
| 417 | 16, // B5G6R5U | 461 | 32, // A8B8G8R8_UINT |
| 418 | 32, // A2B10G10R10U | 462 | 16, // R5G6B5_UNORM |
| 419 | 16, // A1B5G5R5U | 463 | 16, // B5G6R5_UNORM |
| 420 | 8, // R8U | 464 | 16, // A1R5G5B5_UNORM |
| 421 | 8, // R8UI | 465 | 32, // A2B10G10R10_UNORM |
| 422 | 64, // RGBA16F | 466 | 32, // A2B10G10R10_UINT |
| 423 | 64, // RGBA16U | 467 | 16, // A1B5G5R5_UNORM |
| 424 | 64, // RGBA16S | 468 | 8, // R8_UNORM |
| 425 | 64, // RGBA16UI | 469 | 8, // R8_SNORM |
| 426 | 32, // R11FG11FB10F | 470 | 8, // R8_SINT |
| 427 | 128, // RGBA32UI | 471 | 8, // R8_UINT |
| 428 | 64, // DXT1 | 472 | 64, // R16G16B16A16_FLOAT |
| 429 | 128, // DXT23 | 473 | 64, // R16G16B16A16_UNORM |
| 430 | 128, // DXT45 | 474 | 64, // R16G16B16A16_SNORM |
| 431 | 64, // DXN1 | 475 | 64, // R16G16B16A16_SINT |
| 432 | 128, // DXN2UNORM | 476 | 64, // R16G16B16A16_UINT |
| 433 | 128, // DXN2SNORM | 477 | 32, // B10G11R11_FLOAT |
| 434 | 128, // BC7U | 478 | 128, // R32G32B32A32_UINT |
| 435 | 128, // BC6H_UF16 | 479 | 64, // BC1_RGBA_UNORM |
| 436 | 128, // BC6H_SF16 | 480 | 128, // BC2_UNORM |
| 437 | 128, // ASTC_2D_4X4 | 481 | 128, // BC3_UNORM |
| 438 | 32, // BGRA8 | 482 | 64, // BC4_UNORM |
| 439 | 128, // RGBA32F | 483 | 64, // BC4_SNORM |
| 440 | 64, // RG32F | 484 | 128, // BC5_UNORM |
| 441 | 32, // R32F | 485 | 128, // BC5_SNORM |
| 442 | 16, // R16F | 486 | 128, // BC7_UNORM |
| 443 | 16, // R16U | 487 | 128, // BC6H_UFLOAT |
| 444 | 16, // R16S | 488 | 128, // BC6H_SFLOAT |
| 445 | 16, // R16UI | 489 | 128, // ASTC_2D_4X4_UNORM |
| 446 | 16, // R16I | 490 | 32, // B8G8R8A8_UNORM |
| 447 | 32, // RG16 | 491 | 128, // R32G32B32A32_FLOAT |
| 448 | 32, // RG16F | 492 | 128, // R32G32B32A32_SINT |
| 449 | 32, // RG16UI | 493 | 64, // R32G32_FLOAT |
| 450 | 32, // RG16I | 494 | 64, // R32G32_SINT |
| 451 | 32, // RG16S | 495 | 32, // R32_FLOAT |
| 452 | 96, // RGB32F | 496 | 16, // R16_FLOAT |
| 453 | 32, // RGBA8_SRGB | 497 | 16, // R16_UNORM |
| 454 | 16, // RG8U | 498 | 16, // R16_SNORM |
| 455 | 16, // RG8S | 499 | 16, // R16_UINT |
| 456 | 16, // RG8UI | 500 | 16, // R16_SINT |
| 457 | 64, // RG32UI | 501 | 32, // R16G16_UNORM |
| 458 | 64, // RGBX16F | 502 | 32, // R16G16_FLOAT |
| 459 | 32, // R32UI | 503 | 32, // R16G16_UINT |
| 460 | 32, // R32I | 504 | 32, // R16G16_SINT |
| 461 | 128, // ASTC_2D_8X8 | 505 | 32, // R16G16_SNORM |
| 462 | 128, // ASTC_2D_8X5 | 506 | 96, // R32G32B32_FLOAT |
| 463 | 128, // ASTC_2D_5X4 | 507 | 32, // A8B8G8R8_SRGB |
| 464 | 32, // BGRA8_SRGB | 508 | 16, // R8G8_UNORM |
| 465 | 64, // DXT1_SRGB | 509 | 16, // R8G8_SNORM |
| 466 | 128, // DXT23_SRGB | 510 | 16, // R8G8_SINT |
| 467 | 128, // DXT45_SRGB | 511 | 16, // R8G8_UINT |
| 468 | 128, // BC7U | 512 | 64, // R32G32_UINT |
| 469 | 16, // R4G4B4A4U | 513 | 64, // R16G16B16X16_FLOAT |
| 514 | 32, // R32_UINT | ||
| 515 | 32, // R32_SINT | ||
| 516 | 128, // ASTC_2D_8X8_UNORM | ||
| 517 | 128, // ASTC_2D_8X5_UNORM | ||
| 518 | 128, // ASTC_2D_5X4_UNORM | ||
| 519 | 32, // B8G8R8A8_SRGB | ||
| 520 | 64, // BC1_RGBA_SRGB | ||
| 521 | 128, // BC2_SRGB | ||
| 522 | 128, // BC3_SRGB | ||
| 523 | 128, // BC7_UNORM | ||
| 524 | 16, // A4B4G4R4_UNORM | ||
| 470 | 128, // ASTC_2D_4X4_SRGB | 525 | 128, // ASTC_2D_4X4_SRGB |
| 471 | 128, // ASTC_2D_8X8_SRGB | 526 | 128, // ASTC_2D_8X8_SRGB |
| 472 | 128, // ASTC_2D_8X5_SRGB | 527 | 128, // ASTC_2D_8X5_SRGB |
| 473 | 128, // ASTC_2D_5X4_SRGB | 528 | 128, // ASTC_2D_5X4_SRGB |
| 474 | 128, // ASTC_2D_5X5 | 529 | 128, // ASTC_2D_5X5_UNORM |
| 475 | 128, // ASTC_2D_5X5_SRGB | 530 | 128, // ASTC_2D_5X5_SRGB |
| 476 | 128, // ASTC_2D_10X8 | 531 | 128, // ASTC_2D_10X8_UNORM |
| 477 | 128, // ASTC_2D_10X8_SRGB | 532 | 128, // ASTC_2D_10X8_SRGB |
| 478 | 128, // ASTC_2D_6X6 | 533 | 128, // ASTC_2D_6X6_UNORM |
| 479 | 128, // ASTC_2D_6X6_SRGB | 534 | 128, // ASTC_2D_6X6_SRGB |
| 480 | 128, // ASTC_2D_10X10 | 535 | 128, // ASTC_2D_10X10_UNORM |
| 481 | 128, // ASTC_2D_10X10_SRGB | 536 | 128, // ASTC_2D_10X10_SRGB |
| 482 | 128, // ASTC_2D_12X12 | 537 | 128, // ASTC_2D_12X12_UNORM |
| 483 | 128, // ASTC_2D_12X12_SRGB | 538 | 128, // ASTC_2D_12X12_SRGB |
| 484 | 128, // ASTC_2D_8X6 | 539 | 128, // ASTC_2D_8X6_UNORM |
| 485 | 128, // ASTC_2D_8X6_SRGB | 540 | 128, // ASTC_2D_8X6_SRGB |
| 486 | 128, // ASTC_2D_6X5 | 541 | 128, // ASTC_2D_6X5_UNORM |
| 487 | 128, // ASTC_2D_6X5_SRGB | 542 | 128, // ASTC_2D_6X5_SRGB |
| 488 | 32, // E5B9G9R9F | 543 | 32, // E5B9G9R9_FLOAT |
| 489 | 32, // Z32F | 544 | 32, // D32_FLOAT |
| 490 | 16, // Z16 | 545 | 16, // D16_UNORM |
| 491 | 32, // Z24S8 | 546 | 32, // D24_UNORM_S8_UINT |
| 492 | 32, // S8Z24 | 547 | 32, // S8_UINT_D24_UNORM |
| 493 | 64, // Z32FS8 | 548 | 64, // D32_FLOAT_S8_UINT |
| 494 | }}; | 549 | }}; |
| 495 | 550 | ||
| 496 | static constexpr u32 GetFormatBpp(PixelFormat format) { | 551 | static constexpr u32 GetFormatBpp(PixelFormat format) { |
| @@ -529,7 +584,4 @@ bool IsPixelFormatSRGB(PixelFormat format); | |||
| 529 | 584 | ||
| 530 | std::pair<u32, u32> GetASTCBlockSize(PixelFormat format); | 585 | std::pair<u32, u32> GetASTCBlockSize(PixelFormat format); |
| 531 | 586 | ||
| 532 | /// Returns true if the specified PixelFormat is a BCn format, e.g. DXT or DXN | ||
| 533 | bool IsFormatBCn(PixelFormat format); | ||
| 534 | |||
| 535 | } // namespace VideoCore::Surface | 587 | } // namespace VideoCore::Surface |
diff --git a/src/video_core/texture_cache/format_lookup_table.cpp b/src/video_core/texture_cache/format_lookup_table.cpp index f476f03b0..7d5a75648 100644 --- a/src/video_core/texture_cache/format_lookup_table.cpp +++ b/src/video_core/texture_cache/format_lookup_table.cpp | |||
| @@ -19,8 +19,6 @@ constexpr auto SNORM = ComponentType::SNORM; | |||
| 19 | constexpr auto UNORM = ComponentType::UNORM; | 19 | constexpr auto UNORM = ComponentType::UNORM; |
| 20 | constexpr auto SINT = ComponentType::SINT; | 20 | constexpr auto SINT = ComponentType::SINT; |
| 21 | constexpr auto UINT = ComponentType::UINT; | 21 | constexpr auto UINT = ComponentType::UINT; |
| 22 | constexpr auto SNORM_FORCE_FP16 = ComponentType::SNORM_FORCE_FP16; | ||
| 23 | constexpr auto UNORM_FORCE_FP16 = ComponentType::UNORM_FORCE_FP16; | ||
| 24 | constexpr auto FLOAT = ComponentType::FLOAT; | 22 | constexpr auto FLOAT = ComponentType::FLOAT; |
| 25 | constexpr bool C = false; // Normal color | 23 | constexpr bool C = false; // Normal color |
| 26 | constexpr bool S = true; // Srgb | 24 | constexpr bool S = true; // Srgb |
| @@ -41,119 +39,126 @@ struct Table { | |||
| 41 | ComponentType alpha_component; | 39 | ComponentType alpha_component; |
| 42 | bool is_srgb; | 40 | bool is_srgb; |
| 43 | }; | 41 | }; |
| 44 | constexpr std::array<Table, 78> DefinitionTable = {{ | 42 | constexpr std::array<Table, 86> DefinitionTable = {{ |
| 45 | {TextureFormat::A8R8G8B8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ABGR8U}, | 43 | {TextureFormat::A8R8G8B8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A8B8G8R8_UNORM}, |
| 46 | {TextureFormat::A8R8G8B8, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::ABGR8S}, | 44 | {TextureFormat::A8R8G8B8, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::A8B8G8R8_SNORM}, |
| 47 | {TextureFormat::A8R8G8B8, C, UINT, UINT, UINT, UINT, PixelFormat::ABGR8UI}, | 45 | {TextureFormat::A8R8G8B8, C, UINT, UINT, UINT, UINT, PixelFormat::A8B8G8R8_UINT}, |
| 48 | {TextureFormat::A8R8G8B8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::RGBA8_SRGB}, | 46 | {TextureFormat::A8R8G8B8, C, SINT, SINT, SINT, SINT, PixelFormat::A8B8G8R8_SINT}, |
| 47 | {TextureFormat::A8R8G8B8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::A8B8G8R8_SRGB}, | ||
| 49 | 48 | ||
| 50 | {TextureFormat::B5G6R5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::B5G6R5U}, | 49 | {TextureFormat::B5G6R5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::B5G6R5_UNORM}, |
| 51 | 50 | ||
| 52 | {TextureFormat::A2B10G10R10, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A2B10G10R10U}, | 51 | {TextureFormat::A2B10G10R10, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A2B10G10R10_UNORM}, |
| 52 | {TextureFormat::A2B10G10R10, C, UINT, UINT, UINT, UINT, PixelFormat::A2B10G10R10_UINT}, | ||
| 53 | 53 | ||
| 54 | {TextureFormat::A1B5G5R5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A1B5G5R5U}, | 54 | {TextureFormat::A1B5G5R5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A1B5G5R5_UNORM}, |
| 55 | 55 | ||
| 56 | {TextureFormat::A4B4G4R4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R4G4B4A4U}, | 56 | {TextureFormat::A4B4G4R4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A4B4G4R4_UNORM}, |
| 57 | 57 | ||
| 58 | {TextureFormat::R8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R8U}, | 58 | {TextureFormat::R8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R8_UNORM}, |
| 59 | {TextureFormat::R8, C, UINT, UINT, UINT, UINT, PixelFormat::R8UI}, | 59 | {TextureFormat::R8, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::R8_SNORM}, |
| 60 | {TextureFormat::R8, C, UINT, UINT, UINT, UINT, PixelFormat::R8_UINT}, | ||
| 61 | {TextureFormat::R8, C, SINT, SINT, SINT, SINT, PixelFormat::R8_SINT}, | ||
| 60 | 62 | ||
| 61 | {TextureFormat::G8R8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::RG8U}, | 63 | {TextureFormat::R8G8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R8G8_UNORM}, |
| 62 | {TextureFormat::G8R8, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::RG8S}, | 64 | {TextureFormat::R8G8, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::R8G8_SNORM}, |
| 63 | {TextureFormat::G8R8, C, UINT, UINT, UINT, UINT, PixelFormat::RG8UI}, | 65 | {TextureFormat::R8G8, C, UINT, UINT, UINT, UINT, PixelFormat::R8G8_UINT}, |
| 66 | {TextureFormat::R8G8, C, SINT, SINT, SINT, SINT, PixelFormat::R8G8_SINT}, | ||
| 64 | 67 | ||
| 65 | {TextureFormat::R16_G16_B16_A16, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::RGBA16S}, | 68 | {TextureFormat::R16G16B16A16, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::R16G16B16A16_SNORM}, |
| 66 | {TextureFormat::R16_G16_B16_A16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::RGBA16U}, | 69 | {TextureFormat::R16G16B16A16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R16G16B16A16_UNORM}, |
| 67 | {TextureFormat::R16_G16_B16_A16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RGBA16F}, | 70 | {TextureFormat::R16G16B16A16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R16G16B16A16_FLOAT}, |
| 68 | {TextureFormat::R16_G16_B16_A16, C, UINT, UINT, UINT, UINT, PixelFormat::RGBA16UI}, | 71 | {TextureFormat::R16G16B16A16, C, UINT, UINT, UINT, UINT, PixelFormat::R16G16B16A16_UINT}, |
| 72 | {TextureFormat::R16G16B16A16, C, SINT, SINT, SINT, SINT, PixelFormat::R16G16B16A16_SINT}, | ||
| 69 | 73 | ||
| 70 | {TextureFormat::R16_G16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RG16F}, | 74 | {TextureFormat::R16G16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R16G16_FLOAT}, |
| 71 | {TextureFormat::R16_G16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::RG16}, | 75 | {TextureFormat::R16G16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R16G16_UNORM}, |
| 72 | {TextureFormat::R16_G16, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::RG16S}, | 76 | {TextureFormat::R16G16, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::R16G16_SNORM}, |
| 73 | {TextureFormat::R16_G16, C, UINT, UINT, UINT, UINT, PixelFormat::RG16UI}, | 77 | {TextureFormat::R16G16, C, UINT, UINT, UINT, UINT, PixelFormat::R16G16_UINT}, |
| 74 | {TextureFormat::R16_G16, C, SINT, SINT, SINT, SINT, PixelFormat::RG16I}, | 78 | {TextureFormat::R16G16, C, SINT, SINT, SINT, SINT, PixelFormat::R16G16_SINT}, |
| 75 | 79 | ||
| 76 | {TextureFormat::R16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R16F}, | 80 | {TextureFormat::R16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R16_FLOAT}, |
| 77 | {TextureFormat::R16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R16U}, | 81 | {TextureFormat::R16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R16_UNORM}, |
| 78 | {TextureFormat::R16, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::R16S}, | 82 | {TextureFormat::R16, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::R16_SNORM}, |
| 79 | {TextureFormat::R16, C, UINT, UINT, UINT, UINT, PixelFormat::R16UI}, | 83 | {TextureFormat::R16, C, UINT, UINT, UINT, UINT, PixelFormat::R16_UINT}, |
| 80 | {TextureFormat::R16, C, SINT, SINT, SINT, SINT, PixelFormat::R16I}, | 84 | {TextureFormat::R16, C, SINT, SINT, SINT, SINT, PixelFormat::R16_SINT}, |
| 81 | 85 | ||
| 82 | {TextureFormat::BF10GF11RF11, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R11FG11FB10F}, | 86 | {TextureFormat::B10G11R11, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::B10G11R11_FLOAT}, |
| 83 | 87 | ||
| 84 | {TextureFormat::R32_G32_B32_A32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RGBA32F}, | 88 | {TextureFormat::R32G32B32A32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R32G32B32A32_FLOAT}, |
| 85 | {TextureFormat::R32_G32_B32_A32, C, UINT, UINT, UINT, UINT, PixelFormat::RGBA32UI}, | 89 | {TextureFormat::R32G32B32A32, C, UINT, UINT, UINT, UINT, PixelFormat::R32G32B32A32_UINT}, |
| 90 | {TextureFormat::R32G32B32A32, C, SINT, SINT, SINT, SINT, PixelFormat::R32G32B32A32_SINT}, | ||
| 86 | 91 | ||
| 87 | {TextureFormat::R32_G32_B32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RGB32F}, | 92 | {TextureFormat::R32G32B32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R32G32B32_FLOAT}, |
| 88 | 93 | ||
| 89 | {TextureFormat::R32_G32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RG32F}, | 94 | {TextureFormat::R32G32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R32G32_FLOAT}, |
| 90 | {TextureFormat::R32_G32, C, UINT, UINT, UINT, UINT, PixelFormat::RG32UI}, | 95 | {TextureFormat::R32G32, C, UINT, UINT, UINT, UINT, PixelFormat::R32G32_UINT}, |
| 96 | {TextureFormat::R32G32, C, SINT, SINT, SINT, SINT, PixelFormat::R32G32_SINT}, | ||
| 91 | 97 | ||
| 92 | {TextureFormat::R32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R32F}, | 98 | {TextureFormat::R32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R32_FLOAT}, |
| 93 | {TextureFormat::R32, C, UINT, UINT, UINT, UINT, PixelFormat::R32UI}, | 99 | {TextureFormat::R32, C, UINT, UINT, UINT, UINT, PixelFormat::R32_UINT}, |
| 94 | {TextureFormat::R32, C, SINT, SINT, SINT, SINT, PixelFormat::R32I}, | 100 | {TextureFormat::R32, C, SINT, SINT, SINT, SINT, PixelFormat::R32_SINT}, |
| 95 | 101 | ||
| 96 | {TextureFormat::E5B9G9R9_SHAREDEXP, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::E5B9G9R9F}, | 102 | {TextureFormat::E5B9G9R9, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::E5B9G9R9_FLOAT}, |
| 97 | 103 | ||
| 98 | {TextureFormat::ZF32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::Z32F}, | 104 | {TextureFormat::D32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::D32_FLOAT}, |
| 99 | {TextureFormat::Z16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::Z16}, | 105 | {TextureFormat::D16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::D16_UNORM}, |
| 100 | {TextureFormat::S8Z24, C, UINT, UNORM, UNORM, UNORM, PixelFormat::S8Z24}, | 106 | {TextureFormat::S8D24, C, UINT, UNORM, UNORM, UNORM, PixelFormat::S8_UINT_D24_UNORM}, |
| 101 | {TextureFormat::G24R8, C, UINT, UNORM, UNORM, UNORM, PixelFormat::S8Z24}, | 107 | {TextureFormat::R8G24, C, UINT, UNORM, UNORM, UNORM, PixelFormat::S8_UINT_D24_UNORM}, |
| 102 | {TextureFormat::ZF32_X24S8, C, FLOAT, UINT, UNORM, UNORM, PixelFormat::Z32FS8}, | 108 | {TextureFormat::D32S8, C, FLOAT, UINT, UNORM, UNORM, PixelFormat::D32_FLOAT_S8_UINT}, |
| 103 | 109 | ||
| 104 | {TextureFormat::DXT1, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT1}, | 110 | {TextureFormat::BC1_RGBA, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC1_RGBA_UNORM}, |
| 105 | {TextureFormat::DXT1, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT1_SRGB}, | 111 | {TextureFormat::BC1_RGBA, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC1_RGBA_SRGB}, |
| 106 | 112 | ||
| 107 | {TextureFormat::DXT23, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT23}, | 113 | {TextureFormat::BC2, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC2_UNORM}, |
| 108 | {TextureFormat::DXT23, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT23_SRGB}, | 114 | {TextureFormat::BC2, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC2_SRGB}, |
| 109 | 115 | ||
| 110 | {TextureFormat::DXT45, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT45}, | 116 | {TextureFormat::BC3, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC3_UNORM}, |
| 111 | {TextureFormat::DXT45, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT45_SRGB}, | 117 | {TextureFormat::BC3, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC3_SRGB}, |
| 112 | 118 | ||
| 113 | // TODO: Use a different pixel format for SNORM | 119 | {TextureFormat::BC4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC4_UNORM}, |
| 114 | {TextureFormat::DXN1, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXN1}, | 120 | {TextureFormat::BC4, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::BC4_SNORM}, |
| 115 | {TextureFormat::DXN1, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::DXN1}, | ||
| 116 | 121 | ||
| 117 | {TextureFormat::DXN2, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXN2UNORM}, | 122 | {TextureFormat::BC5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC5_UNORM}, |
| 118 | {TextureFormat::DXN2, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::DXN2SNORM}, | 123 | {TextureFormat::BC5, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::BC5_SNORM}, |
| 119 | 124 | ||
| 120 | {TextureFormat::BC7U, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC7U}, | 125 | {TextureFormat::BC7, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC7_UNORM}, |
| 121 | {TextureFormat::BC7U, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC7U_SRGB}, | 126 | {TextureFormat::BC7, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC7_SRGB}, |
| 122 | 127 | ||
| 123 | {TextureFormat::BC6H_SF16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::BC6H_SF16}, | 128 | {TextureFormat::BC6H_SFLOAT, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::BC6H_SFLOAT}, |
| 124 | {TextureFormat::BC6H_UF16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::BC6H_UF16}, | 129 | {TextureFormat::BC6H_UFLOAT, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::BC6H_UFLOAT}, |
| 125 | 130 | ||
| 126 | {TextureFormat::ASTC_2D_4X4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_4X4}, | 131 | {TextureFormat::ASTC_2D_4X4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_4X4_UNORM}, |
| 127 | {TextureFormat::ASTC_2D_4X4, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_4X4_SRGB}, | 132 | {TextureFormat::ASTC_2D_4X4, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_4X4_SRGB}, |
| 128 | 133 | ||
| 129 | {TextureFormat::ASTC_2D_5X4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X4}, | 134 | {TextureFormat::ASTC_2D_5X4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X4_UNORM}, |
| 130 | {TextureFormat::ASTC_2D_5X4, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X4_SRGB}, | 135 | {TextureFormat::ASTC_2D_5X4, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X4_SRGB}, |
| 131 | 136 | ||
| 132 | {TextureFormat::ASTC_2D_5X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X5}, | 137 | {TextureFormat::ASTC_2D_5X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X5_UNORM}, |
| 133 | {TextureFormat::ASTC_2D_5X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X5_SRGB}, | 138 | {TextureFormat::ASTC_2D_5X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X5_SRGB}, |
| 134 | 139 | ||
| 135 | {TextureFormat::ASTC_2D_8X8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X8}, | 140 | {TextureFormat::ASTC_2D_8X8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X8_UNORM}, |
| 136 | {TextureFormat::ASTC_2D_8X8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X8_SRGB}, | 141 | {TextureFormat::ASTC_2D_8X8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X8_SRGB}, |
| 137 | 142 | ||
| 138 | {TextureFormat::ASTC_2D_8X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X5}, | 143 | {TextureFormat::ASTC_2D_8X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X5_UNORM}, |
| 139 | {TextureFormat::ASTC_2D_8X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X5_SRGB}, | 144 | {TextureFormat::ASTC_2D_8X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X5_SRGB}, |
| 140 | 145 | ||
| 141 | {TextureFormat::ASTC_2D_10X8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X8}, | 146 | {TextureFormat::ASTC_2D_10X8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X8_UNORM}, |
| 142 | {TextureFormat::ASTC_2D_10X8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X8_SRGB}, | 147 | {TextureFormat::ASTC_2D_10X8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X8_SRGB}, |
| 143 | 148 | ||
| 144 | {TextureFormat::ASTC_2D_6X6, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X6}, | 149 | {TextureFormat::ASTC_2D_6X6, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X6_UNORM}, |
| 145 | {TextureFormat::ASTC_2D_6X6, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X6_SRGB}, | 150 | {TextureFormat::ASTC_2D_6X6, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X6_SRGB}, |
| 146 | 151 | ||
| 147 | {TextureFormat::ASTC_2D_10X10, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X10}, | 152 | {TextureFormat::ASTC_2D_10X10, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X10_UNORM}, |
| 148 | {TextureFormat::ASTC_2D_10X10, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X10_SRGB}, | 153 | {TextureFormat::ASTC_2D_10X10, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X10_SRGB}, |
| 149 | 154 | ||
| 150 | {TextureFormat::ASTC_2D_12X12, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_12X12}, | 155 | {TextureFormat::ASTC_2D_12X12, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_12X12_UNORM}, |
| 151 | {TextureFormat::ASTC_2D_12X12, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_12X12_SRGB}, | 156 | {TextureFormat::ASTC_2D_12X12, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_12X12_SRGB}, |
| 152 | 157 | ||
| 153 | {TextureFormat::ASTC_2D_8X6, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X6}, | 158 | {TextureFormat::ASTC_2D_8X6, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X6_UNORM}, |
| 154 | {TextureFormat::ASTC_2D_8X6, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X6_SRGB}, | 159 | {TextureFormat::ASTC_2D_8X6, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X6_SRGB}, |
| 155 | 160 | ||
| 156 | {TextureFormat::ASTC_2D_6X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X5}, | 161 | {TextureFormat::ASTC_2D_6X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X5_UNORM}, |
| 157 | {TextureFormat::ASTC_2D_6X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X5_SRGB}, | 162 | {TextureFormat::ASTC_2D_6X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X5_SRGB}, |
| 158 | }}; | 163 | }}; |
| 159 | 164 | ||
| @@ -184,7 +189,7 @@ PixelFormat FormatLookupTable::GetPixelFormat(TextureFormat format, bool is_srgb | |||
| 184 | static_cast<int>(format), is_srgb, static_cast<int>(red_component), | 189 | static_cast<int>(format), is_srgb, static_cast<int>(red_component), |
| 185 | static_cast<int>(green_component), static_cast<int>(blue_component), | 190 | static_cast<int>(green_component), static_cast<int>(blue_component), |
| 186 | static_cast<int>(alpha_component)); | 191 | static_cast<int>(alpha_component)); |
| 187 | return PixelFormat::ABGR8U; | 192 | return PixelFormat::A8B8G8R8_UNORM; |
| 188 | } | 193 | } |
| 189 | 194 | ||
| 190 | void FormatLookupTable::Set(TextureFormat format, bool is_srgb, ComponentType red_component, | 195 | void FormatLookupTable::Set(TextureFormat format, bool is_srgb, ComponentType red_component, |
diff --git a/src/video_core/texture_cache/surface_base.cpp b/src/video_core/texture_cache/surface_base.cpp index 0caf3b4f0..dfcf36e0b 100644 --- a/src/video_core/texture_cache/surface_base.cpp +++ b/src/video_core/texture_cache/surface_base.cpp | |||
| @@ -228,7 +228,7 @@ void SurfaceBaseImpl::LoadBuffer(Tegra::MemoryManager& memory_manager, | |||
| 228 | } | 228 | } |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | if (!is_converted && params.pixel_format != PixelFormat::S8Z24) { | 231 | if (!is_converted && params.pixel_format != PixelFormat::S8_UINT_D24_UNORM) { |
| 232 | return; | 232 | return; |
| 233 | } | 233 | } |
| 234 | 234 | ||
diff --git a/src/video_core/texture_cache/surface_params.cpp b/src/video_core/texture_cache/surface_params.cpp index 0ecf42368..e614a92df 100644 --- a/src/video_core/texture_cache/surface_params.cpp +++ b/src/video_core/texture_cache/surface_params.cpp | |||
| @@ -74,21 +74,21 @@ SurfaceParams SurfaceParams::CreateForTexture(const FormatLookupTable& lookup_ta | |||
| 74 | SurfaceParams params; | 74 | SurfaceParams params; |
| 75 | params.is_tiled = tic.IsTiled(); | 75 | params.is_tiled = tic.IsTiled(); |
| 76 | params.srgb_conversion = tic.IsSrgbConversionEnabled(); | 76 | params.srgb_conversion = tic.IsSrgbConversionEnabled(); |
| 77 | params.block_width = params.is_tiled ? tic.BlockWidth() : 0, | 77 | params.block_width = params.is_tiled ? tic.BlockWidth() : 0; |
| 78 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, | 78 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0; |
| 79 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, | 79 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0; |
| 80 | params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1; | 80 | params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1; |
| 81 | params.pixel_format = lookup_table.GetPixelFormat( | 81 | params.pixel_format = lookup_table.GetPixelFormat( |
| 82 | tic.format, params.srgb_conversion, tic.r_type, tic.g_type, tic.b_type, tic.a_type); | 82 | tic.format, params.srgb_conversion, tic.r_type, tic.g_type, tic.b_type, tic.a_type); |
| 83 | params.type = GetFormatType(params.pixel_format); | 83 | params.type = GetFormatType(params.pixel_format); |
| 84 | if (entry.is_shadow && params.type == SurfaceType::ColorTexture) { | 84 | if (entry.is_shadow && params.type == SurfaceType::ColorTexture) { |
| 85 | switch (params.pixel_format) { | 85 | switch (params.pixel_format) { |
| 86 | case PixelFormat::R16U: | 86 | case PixelFormat::R16_UNORM: |
| 87 | case PixelFormat::R16F: | 87 | case PixelFormat::R16_FLOAT: |
| 88 | params.pixel_format = PixelFormat::Z16; | 88 | params.pixel_format = PixelFormat::D16_UNORM; |
| 89 | break; | 89 | break; |
| 90 | case PixelFormat::R32F: | 90 | case PixelFormat::R32_FLOAT: |
| 91 | params.pixel_format = PixelFormat::Z32F; | 91 | params.pixel_format = PixelFormat::D32_FLOAT; |
| 92 | break; | 92 | break; |
| 93 | default: | 93 | default: |
| 94 | UNIMPLEMENTED_MSG("Unimplemented shadow convert format: {}", | 94 | UNIMPLEMENTED_MSG("Unimplemented shadow convert format: {}", |
| @@ -129,14 +129,13 @@ SurfaceParams SurfaceParams::CreateForImage(const FormatLookupTable& lookup_tabl | |||
| 129 | SurfaceParams params; | 129 | SurfaceParams params; |
| 130 | params.is_tiled = tic.IsTiled(); | 130 | params.is_tiled = tic.IsTiled(); |
| 131 | params.srgb_conversion = tic.IsSrgbConversionEnabled(); | 131 | params.srgb_conversion = tic.IsSrgbConversionEnabled(); |
| 132 | params.block_width = params.is_tiled ? tic.BlockWidth() : 0, | 132 | params.block_width = params.is_tiled ? tic.BlockWidth() : 0; |
| 133 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, | 133 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0; |
| 134 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, | 134 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0; |
| 135 | params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1; | 135 | params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1; |
| 136 | params.pixel_format = lookup_table.GetPixelFormat( | 136 | params.pixel_format = lookup_table.GetPixelFormat( |
| 137 | tic.format, params.srgb_conversion, tic.r_type, tic.g_type, tic.b_type, tic.a_type); | 137 | tic.format, params.srgb_conversion, tic.r_type, tic.g_type, tic.b_type, tic.a_type); |
| 138 | params.type = GetFormatType(params.pixel_format); | 138 | params.type = GetFormatType(params.pixel_format); |
| 139 | params.type = GetFormatType(params.pixel_format); | ||
| 140 | params.target = ImageTypeToSurfaceTarget(entry.type); | 139 | params.target = ImageTypeToSurfaceTarget(entry.type); |
| 141 | // TODO: on 1DBuffer we should use the tic info. | 140 | // TODO: on 1DBuffer we should use the tic info. |
| 142 | if (tic.IsBuffer()) { | 141 | if (tic.IsBuffer()) { |
| @@ -166,27 +165,30 @@ SurfaceParams SurfaceParams::CreateForImage(const FormatLookupTable& lookup_tabl | |||
| 166 | 165 | ||
| 167 | SurfaceParams SurfaceParams::CreateForDepthBuffer(Core::System& system) { | 166 | SurfaceParams SurfaceParams::CreateForDepthBuffer(Core::System& system) { |
| 168 | const auto& regs = system.GPU().Maxwell3D().regs; | 167 | const auto& regs = system.GPU().Maxwell3D().regs; |
| 169 | SurfaceParams params; | ||
| 170 | params.is_tiled = regs.zeta.memory_layout.type == | ||
| 171 | Tegra::Engines::Maxwell3D::Regs::InvMemoryLayout::BlockLinear; | ||
| 172 | params.srgb_conversion = false; | ||
| 173 | params.block_width = std::min(regs.zeta.memory_layout.block_width.Value(), 5U); | ||
| 174 | params.block_height = std::min(regs.zeta.memory_layout.block_height.Value(), 5U); | ||
| 175 | params.block_depth = std::min(regs.zeta.memory_layout.block_depth.Value(), 5U); | ||
| 176 | params.tile_width_spacing = 1; | ||
| 177 | params.pixel_format = PixelFormatFromDepthFormat(regs.zeta.format); | ||
| 178 | params.type = GetFormatType(params.pixel_format); | ||
| 179 | params.width = regs.zeta_width; | ||
| 180 | params.height = regs.zeta_height; | ||
| 181 | params.pitch = 0; | ||
| 182 | params.num_levels = 1; | ||
| 183 | params.emulated_levels = 1; | ||
| 184 | 168 | ||
| 185 | const bool is_layered = regs.zeta_layers > 1 && params.block_depth == 0; | 169 | const auto block_depth = std::min(regs.zeta.memory_layout.block_depth.Value(), 5U); |
| 186 | params.is_layered = is_layered; | 170 | const bool is_layered = regs.zeta_layers > 1 && block_depth == 0; |
| 187 | params.target = is_layered ? SurfaceTarget::Texture2DArray : SurfaceTarget::Texture2D; | 171 | const auto pixel_format = PixelFormatFromDepthFormat(regs.zeta.format); |
| 188 | params.depth = is_layered ? regs.zeta_layers.Value() : 1U; | 172 | |
| 189 | return params; | 173 | return { |
| 174 | .is_tiled = regs.zeta.memory_layout.type == | ||
| 175 | Tegra::Engines::Maxwell3D::Regs::InvMemoryLayout::BlockLinear, | ||
| 176 | .srgb_conversion = false, | ||
| 177 | .is_layered = is_layered, | ||
| 178 | .block_width = std::min(regs.zeta.memory_layout.block_width.Value(), 5U), | ||
| 179 | .block_height = std::min(regs.zeta.memory_layout.block_height.Value(), 5U), | ||
| 180 | .block_depth = block_depth, | ||
| 181 | .tile_width_spacing = 1, | ||
| 182 | .width = regs.zeta_width, | ||
| 183 | .height = regs.zeta_height, | ||
| 184 | .depth = is_layered ? regs.zeta_layers.Value() : 1U, | ||
| 185 | .pitch = 0, | ||
| 186 | .num_levels = 1, | ||
| 187 | .emulated_levels = 1, | ||
| 188 | .pixel_format = pixel_format, | ||
| 189 | .type = GetFormatType(pixel_format), | ||
| 190 | .target = is_layered ? SurfaceTarget::Texture2DArray : SurfaceTarget::Texture2D, | ||
| 191 | }; | ||
| 190 | } | 192 | } |
| 191 | 193 | ||
| 192 | SurfaceParams SurfaceParams::CreateForFramebuffer(Core::System& system, std::size_t index) { | 194 | SurfaceParams SurfaceParams::CreateForFramebuffer(Core::System& system, std::size_t index) { |
| @@ -194,8 +196,8 @@ SurfaceParams SurfaceParams::CreateForFramebuffer(Core::System& system, std::siz | |||
| 194 | SurfaceParams params; | 196 | SurfaceParams params; |
| 195 | params.is_tiled = | 197 | params.is_tiled = |
| 196 | config.memory_layout.type == Tegra::Engines::Maxwell3D::Regs::InvMemoryLayout::BlockLinear; | 198 | config.memory_layout.type == Tegra::Engines::Maxwell3D::Regs::InvMemoryLayout::BlockLinear; |
| 197 | params.srgb_conversion = config.format == Tegra::RenderTargetFormat::BGRA8_SRGB || | 199 | params.srgb_conversion = config.format == Tegra::RenderTargetFormat::B8G8R8A8_SRGB || |
| 198 | config.format == Tegra::RenderTargetFormat::RGBA8_SRGB; | 200 | config.format == Tegra::RenderTargetFormat::A8B8G8R8_SRGB; |
| 199 | params.block_width = config.memory_layout.block_width; | 201 | params.block_width = config.memory_layout.block_width; |
| 200 | params.block_height = config.memory_layout.block_height; | 202 | params.block_height = config.memory_layout.block_height; |
| 201 | params.block_depth = config.memory_layout.block_depth; | 203 | params.block_depth = config.memory_layout.block_depth; |
| @@ -232,24 +234,29 @@ SurfaceParams SurfaceParams::CreateForFramebuffer(Core::System& system, std::siz | |||
| 232 | 234 | ||
| 233 | SurfaceParams SurfaceParams::CreateForFermiCopySurface( | 235 | SurfaceParams SurfaceParams::CreateForFermiCopySurface( |
| 234 | const Tegra::Engines::Fermi2D::Regs::Surface& config) { | 236 | const Tegra::Engines::Fermi2D::Regs::Surface& config) { |
| 235 | SurfaceParams params{}; | 237 | const bool is_tiled = !config.linear; |
| 236 | params.is_tiled = !config.linear; | 238 | const auto pixel_format = PixelFormatFromRenderTargetFormat(config.format); |
| 237 | params.srgb_conversion = config.format == Tegra::RenderTargetFormat::BGRA8_SRGB || | 239 | |
| 238 | config.format == Tegra::RenderTargetFormat::RGBA8_SRGB; | 240 | SurfaceParams params{ |
| 239 | params.block_width = params.is_tiled ? std::min(config.BlockWidth(), 5U) : 0, | 241 | .is_tiled = is_tiled, |
| 240 | params.block_height = params.is_tiled ? std::min(config.BlockHeight(), 5U) : 0, | 242 | .srgb_conversion = config.format == Tegra::RenderTargetFormat::B8G8R8A8_SRGB || |
| 241 | params.block_depth = params.is_tiled ? std::min(config.BlockDepth(), 5U) : 0, | 243 | config.format == Tegra::RenderTargetFormat::A8B8G8R8_SRGB, |
| 242 | params.tile_width_spacing = 1; | 244 | .block_width = is_tiled ? std::min(config.BlockWidth(), 5U) : 0U, |
| 243 | params.pixel_format = PixelFormatFromRenderTargetFormat(config.format); | 245 | .block_height = is_tiled ? std::min(config.BlockHeight(), 5U) : 0U, |
| 244 | params.type = GetFormatType(params.pixel_format); | 246 | .block_depth = is_tiled ? std::min(config.BlockDepth(), 5U) : 0U, |
| 245 | params.width = config.width; | 247 | .tile_width_spacing = 1, |
| 246 | params.height = config.height; | 248 | .width = config.width, |
| 247 | params.pitch = config.pitch; | 249 | .height = config.height, |
| 248 | // TODO(Rodrigo): Try to guess texture arrays from parameters | 250 | .depth = 1, |
| 249 | params.target = SurfaceTarget::Texture2D; | 251 | .pitch = config.pitch, |
| 250 | params.depth = 1; | 252 | .num_levels = 1, |
| 251 | params.num_levels = 1; | 253 | .emulated_levels = 1, |
| 252 | params.emulated_levels = 1; | 254 | .pixel_format = pixel_format, |
| 255 | .type = GetFormatType(pixel_format), | ||
| 256 | // TODO(Rodrigo): Try to guess texture arrays from parameters | ||
| 257 | .target = SurfaceTarget::Texture2D, | ||
| 258 | }; | ||
| 259 | |||
| 253 | params.is_layered = params.IsLayered(); | 260 | params.is_layered = params.IsLayered(); |
| 254 | return params; | 261 | return params; |
| 255 | } | 262 | } |
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index cdcddb225..96c4e4cc2 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -373,9 +373,9 @@ protected: | |||
| 373 | siblings_table[static_cast<std::size_t>(b)] = a; | 373 | siblings_table[static_cast<std::size_t>(b)] = a; |
| 374 | }; | 374 | }; |
| 375 | std::fill(siblings_table.begin(), siblings_table.end(), PixelFormat::Invalid); | 375 | std::fill(siblings_table.begin(), siblings_table.end(), PixelFormat::Invalid); |
| 376 | make_siblings(PixelFormat::Z16, PixelFormat::R16U); | 376 | make_siblings(PixelFormat::D16_UNORM, PixelFormat::R16_UNORM); |
| 377 | make_siblings(PixelFormat::Z32F, PixelFormat::R32F); | 377 | make_siblings(PixelFormat::D32_FLOAT, PixelFormat::R32_FLOAT); |
| 378 | make_siblings(PixelFormat::Z32FS8, PixelFormat::RG32F); | 378 | make_siblings(PixelFormat::D32_FLOAT_S8_UINT, PixelFormat::R32G32_FLOAT); |
| 379 | 379 | ||
| 380 | sampled_textures.reserve(64); | 380 | sampled_textures.reserve(64); |
| 381 | } | 381 | } |
| @@ -1031,7 +1031,7 @@ private: | |||
| 1031 | params.pitch = 4; | 1031 | params.pitch = 4; |
| 1032 | params.num_levels = 1; | 1032 | params.num_levels = 1; |
| 1033 | params.emulated_levels = 1; | 1033 | params.emulated_levels = 1; |
| 1034 | params.pixel_format = VideoCore::Surface::PixelFormat::R8U; | 1034 | params.pixel_format = VideoCore::Surface::PixelFormat::R8_UNORM; |
| 1035 | params.type = VideoCore::Surface::SurfaceType::ColorTexture; | 1035 | params.type = VideoCore::Surface::SurfaceType::ColorTexture; |
| 1036 | auto surface = CreateSurface(0ULL, params); | 1036 | auto surface = CreateSurface(0ULL, params); |
| 1037 | invalid_memory.resize(surface->GetHostSizeInBytes(), 0U); | 1037 | invalid_memory.resize(surface->GetHostSizeInBytes(), 0U); |
diff --git a/src/video_core/textures/convert.cpp b/src/video_core/textures/convert.cpp index f3efa7eb0..962921483 100644 --- a/src/video_core/textures/convert.cpp +++ b/src/video_core/textures/convert.cpp | |||
| @@ -35,7 +35,7 @@ void SwapS8Z24ToZ24S8(u8* data, u32 width, u32 height) { | |||
| 35 | S8Z24 s8z24_pixel{}; | 35 | S8Z24 s8z24_pixel{}; |
| 36 | Z24S8 z24s8_pixel{}; | 36 | Z24S8 z24s8_pixel{}; |
| 37 | constexpr auto bpp{ | 37 | constexpr auto bpp{ |
| 38 | VideoCore::Surface::GetBytesPerPixel(VideoCore::Surface::PixelFormat::S8Z24)}; | 38 | VideoCore::Surface::GetBytesPerPixel(VideoCore::Surface::PixelFormat::S8_UINT_D24_UNORM)}; |
| 39 | for (std::size_t y = 0; y < height; ++y) { | 39 | for (std::size_t y = 0; y < height; ++y) { |
| 40 | for (std::size_t x = 0; x < width; ++x) { | 40 | for (std::size_t x = 0; x < width; ++x) { |
| 41 | const std::size_t offset{bpp * (y * width + x)}; | 41 | const std::size_t offset{bpp * (y * width + x)}; |
| @@ -73,7 +73,7 @@ void ConvertFromGuestToHost(u8* in_data, u8* out_data, PixelFormat pixel_format, | |||
| 73 | in_data, width, height, depth, block_width, block_height); | 73 | in_data, width, height, depth, block_width, block_height); |
| 74 | std::copy(rgba8_data.begin(), rgba8_data.end(), out_data); | 74 | std::copy(rgba8_data.begin(), rgba8_data.end(), out_data); |
| 75 | 75 | ||
| 76 | } else if (convert_s8z24 && pixel_format == PixelFormat::S8Z24) { | 76 | } else if (convert_s8z24 && pixel_format == PixelFormat::S8_UINT_D24_UNORM) { |
| 77 | Tegra::Texture::ConvertS8Z24ToZ24S8(in_data, width, height); | 77 | Tegra::Texture::ConvertS8Z24ToZ24S8(in_data, width, height); |
| 78 | } | 78 | } |
| 79 | } | 79 | } |
| @@ -85,7 +85,7 @@ void ConvertFromHostToGuest(u8* data, PixelFormat pixel_format, u32 width, u32 h | |||
| 85 | static_cast<u32>(pixel_format)); | 85 | static_cast<u32>(pixel_format)); |
| 86 | UNREACHABLE(); | 86 | UNREACHABLE(); |
| 87 | 87 | ||
| 88 | } else if (convert_s8z24 && pixel_format == PixelFormat::S8Z24) { | 88 | } else if (convert_s8z24 && pixel_format == PixelFormat::S8_UINT_D24_UNORM) { |
| 89 | Tegra::Texture::ConvertZ24S8ToS8Z24(data, width, height); | 89 | Tegra::Texture::ConvertZ24S8ToS8Z24(data, width, height); |
| 90 | } | 90 | } |
| 91 | } | 91 | } |
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index 98beabef1..474ae620a 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp | |||
| @@ -184,53 +184,6 @@ void CopySwizzledData(u32 width, u32 height, u32 depth, u32 bytes_per_pixel, | |||
| 184 | } | 184 | } |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | u32 BytesPerPixel(TextureFormat format) { | ||
| 188 | switch (format) { | ||
| 189 | case TextureFormat::DXT1: | ||
| 190 | case TextureFormat::DXN1: | ||
| 191 | // In this case a 'pixel' actually refers to a 4x4 tile. | ||
| 192 | return 8; | ||
| 193 | case TextureFormat::DXT23: | ||
| 194 | case TextureFormat::DXT45: | ||
| 195 | case TextureFormat::DXN2: | ||
| 196 | case TextureFormat::BC7U: | ||
| 197 | case TextureFormat::BC6H_UF16: | ||
| 198 | case TextureFormat::BC6H_SF16: | ||
| 199 | // In this case a 'pixel' actually refers to a 4x4 tile. | ||
| 200 | return 16; | ||
| 201 | case TextureFormat::R32_G32_B32: | ||
| 202 | return 12; | ||
| 203 | case TextureFormat::ASTC_2D_4X4: | ||
| 204 | case TextureFormat::ASTC_2D_5X4: | ||
| 205 | case TextureFormat::ASTC_2D_8X8: | ||
| 206 | case TextureFormat::ASTC_2D_8X5: | ||
| 207 | case TextureFormat::ASTC_2D_10X8: | ||
| 208 | case TextureFormat::ASTC_2D_5X5: | ||
| 209 | case TextureFormat::A8R8G8B8: | ||
| 210 | case TextureFormat::A2B10G10R10: | ||
| 211 | case TextureFormat::BF10GF11RF11: | ||
| 212 | case TextureFormat::R32: | ||
| 213 | case TextureFormat::R16_G16: | ||
| 214 | return 4; | ||
| 215 | case TextureFormat::A1B5G5R5: | ||
| 216 | case TextureFormat::B5G6R5: | ||
| 217 | case TextureFormat::G8R8: | ||
| 218 | case TextureFormat::R16: | ||
| 219 | return 2; | ||
| 220 | case TextureFormat::R8: | ||
| 221 | return 1; | ||
| 222 | case TextureFormat::R16_G16_B16_A16: | ||
| 223 | return 8; | ||
| 224 | case TextureFormat::R32_G32_B32_A32: | ||
| 225 | return 16; | ||
| 226 | case TextureFormat::R32_G32: | ||
| 227 | return 8; | ||
| 228 | default: | ||
| 229 | UNIMPLEMENTED_MSG("Format not implemented"); | ||
| 230 | return 1; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | |||
| 234 | void UnswizzleTexture(u8* const unswizzled_data, u8* address, u32 tile_size_x, u32 tile_size_y, | 187 | void UnswizzleTexture(u8* const unswizzled_data, u8* address, u32 tile_size_x, u32 tile_size_y, |
| 235 | u32 bytes_per_pixel, u32 width, u32 height, u32 depth, u32 block_height, | 188 | u32 bytes_per_pixel, u32 width, u32 height, u32 depth, u32 block_height, |
| 236 | u32 block_depth, u32 width_spacing) { | 189 | u32 block_depth, u32 width_spacing) { |
| @@ -348,48 +301,6 @@ void SwizzleKepler(const u32 width, const u32 height, const u32 dst_x, const u32 | |||
| 348 | } | 301 | } |
| 349 | } | 302 | } |
| 350 | 303 | ||
| 351 | std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width, | ||
| 352 | u32 height) { | ||
| 353 | std::vector<u8> rgba_data; | ||
| 354 | |||
| 355 | // TODO(Subv): Implement. | ||
| 356 | switch (format) { | ||
| 357 | case TextureFormat::DXT1: | ||
| 358 | case TextureFormat::DXT23: | ||
| 359 | case TextureFormat::DXT45: | ||
| 360 | case TextureFormat::DXN1: | ||
| 361 | case TextureFormat::DXN2: | ||
| 362 | case TextureFormat::BC7U: | ||
| 363 | case TextureFormat::BC6H_UF16: | ||
| 364 | case TextureFormat::BC6H_SF16: | ||
| 365 | case TextureFormat::ASTC_2D_4X4: | ||
| 366 | case TextureFormat::ASTC_2D_8X8: | ||
| 367 | case TextureFormat::ASTC_2D_5X5: | ||
| 368 | case TextureFormat::ASTC_2D_10X8: | ||
| 369 | case TextureFormat::A8R8G8B8: | ||
| 370 | case TextureFormat::A2B10G10R10: | ||
| 371 | case TextureFormat::A1B5G5R5: | ||
| 372 | case TextureFormat::B5G6R5: | ||
| 373 | case TextureFormat::R8: | ||
| 374 | case TextureFormat::G8R8: | ||
| 375 | case TextureFormat::BF10GF11RF11: | ||
| 376 | case TextureFormat::R32_G32_B32_A32: | ||
| 377 | case TextureFormat::R32_G32: | ||
| 378 | case TextureFormat::R32: | ||
| 379 | case TextureFormat::R16: | ||
| 380 | case TextureFormat::R16_G16: | ||
| 381 | case TextureFormat::R32_G32_B32: | ||
| 382 | // TODO(Subv): For the time being just forward the same data without any decoding. | ||
| 383 | rgba_data = texture_data; | ||
| 384 | break; | ||
| 385 | default: | ||
| 386 | UNIMPLEMENTED_MSG("Format not implemented"); | ||
| 387 | break; | ||
| 388 | } | ||
| 389 | |||
| 390 | return rgba_data; | ||
| 391 | } | ||
| 392 | |||
| 393 | std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, | 304 | std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, |
| 394 | u32 block_height, u32 block_depth) { | 305 | u32 block_height, u32 block_depth) { |
| 395 | if (tiled) { | 306 | if (tiled) { |
diff --git a/src/video_core/textures/decoders.h b/src/video_core/textures/decoders.h index 232b696b3..d6fe35d37 100644 --- a/src/video_core/textures/decoders.h +++ b/src/video_core/textures/decoders.h | |||
| @@ -38,10 +38,6 @@ void CopySwizzledData(u32 width, u32 height, u32 depth, u32 bytes_per_pixel, | |||
| 38 | u32 out_bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, | 38 | u32 out_bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, |
| 39 | bool unswizzle, u32 block_height, u32 block_depth, u32 width_spacing); | 39 | bool unswizzle, u32 block_height, u32 block_depth, u32 width_spacing); |
| 40 | 40 | ||
| 41 | /// Decodes an unswizzled texture into a A8R8G8B8 texture. | ||
| 42 | std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width, | ||
| 43 | u32 height); | ||
| 44 | |||
| 45 | /// This function calculates the correct size of a texture depending if it's tiled or not. | 41 | /// This function calculates the correct size of a texture depending if it's tiled or not. |
| 46 | std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, | 42 | std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, |
| 47 | u32 block_height, u32 block_depth); | 43 | u32 block_height, u32 block_depth); |
diff --git a/src/video_core/textures/texture.h b/src/video_core/textures/texture.h index eba05aced..0574fef12 100644 --- a/src/video_core/textures/texture.h +++ b/src/video_core/textures/texture.h | |||
| @@ -12,10 +12,10 @@ | |||
| 12 | namespace Tegra::Texture { | 12 | namespace Tegra::Texture { |
| 13 | 13 | ||
| 14 | enum class TextureFormat : u32 { | 14 | enum class TextureFormat : u32 { |
| 15 | R32_G32_B32_A32 = 0x01, | 15 | R32G32B32A32 = 0x01, |
| 16 | R32_G32_B32 = 0x02, | 16 | R32G32B32 = 0x02, |
| 17 | R16_G16_B16_A16 = 0x03, | 17 | R16G16B16A16 = 0x03, |
| 18 | R32_G32 = 0x04, | 18 | R32G32 = 0x04, |
| 19 | R32_B24G8 = 0x05, | 19 | R32_B24G8 = 0x05, |
| 20 | ETC2_RGB = 0x06, | 20 | ETC2_RGB = 0x06, |
| 21 | X8B8G8R8 = 0x07, | 21 | X8B8G8R8 = 0x07, |
| @@ -23,19 +23,19 @@ enum class TextureFormat : u32 { | |||
| 23 | A2B10G10R10 = 0x09, | 23 | A2B10G10R10 = 0x09, |
| 24 | ETC2_RGB_PTA = 0x0a, | 24 | ETC2_RGB_PTA = 0x0a, |
| 25 | ETC2_RGBA = 0x0b, | 25 | ETC2_RGBA = 0x0b, |
| 26 | R16_G16 = 0x0c, | 26 | R16G16 = 0x0c, |
| 27 | G8R24 = 0x0d, | 27 | R24G8 = 0x0d, |
| 28 | G24R8 = 0x0e, | 28 | R8G24 = 0x0e, |
| 29 | R32 = 0x0f, | 29 | R32 = 0x0f, |
| 30 | BC6H_SF16 = 0x10, | 30 | BC6H_SFLOAT = 0x10, |
| 31 | BC6H_UF16 = 0x11, | 31 | BC6H_UFLOAT = 0x11, |
| 32 | A4B4G4R4 = 0x12, | 32 | A4B4G4R4 = 0x12, |
| 33 | A5B5G5R1 = 0x13, | 33 | A5B5G5R1 = 0x13, |
| 34 | A1B5G5R5 = 0x14, | 34 | A1B5G5R5 = 0x14, |
| 35 | B5G6R5 = 0x15, | 35 | B5G6R5 = 0x15, |
| 36 | B6G5R5 = 0x16, | 36 | B6G5R5 = 0x16, |
| 37 | BC7U = 0x17, | 37 | BC7 = 0x17, |
| 38 | G8R8 = 0x18, | 38 | R8G8 = 0x18, |
| 39 | EAC = 0x19, | 39 | EAC = 0x19, |
| 40 | EACX2 = 0x1a, | 40 | EACX2 = 0x1a, |
| 41 | R16 = 0x1b, | 41 | R16 = 0x1b, |
| @@ -43,23 +43,23 @@ enum class TextureFormat : u32 { | |||
| 43 | R8 = 0x1d, | 43 | R8 = 0x1d, |
| 44 | G4R4 = 0x1e, | 44 | G4R4 = 0x1e, |
| 45 | R1 = 0x1f, | 45 | R1 = 0x1f, |
| 46 | E5B9G9R9_SHAREDEXP = 0x20, | 46 | E5B9G9R9 = 0x20, |
| 47 | BF10GF11RF11 = 0x21, | 47 | B10G11R11 = 0x21, |
| 48 | G8B8G8R8 = 0x22, | 48 | G8B8G8R8 = 0x22, |
| 49 | B8G8R8G8 = 0x23, | 49 | B8G8R8G8 = 0x23, |
| 50 | DXT1 = 0x24, | 50 | BC1_RGBA = 0x24, |
| 51 | DXT23 = 0x25, | 51 | BC2 = 0x25, |
| 52 | DXT45 = 0x26, | 52 | BC3 = 0x26, |
| 53 | DXN1 = 0x27, | 53 | BC4 = 0x27, |
| 54 | DXN2 = 0x28, | 54 | BC5 = 0x28, |
| 55 | S8Z24 = 0x29, | 55 | S8D24 = 0x29, |
| 56 | X8Z24 = 0x2a, | 56 | X8Z24 = 0x2a, |
| 57 | Z24S8 = 0x2b, | 57 | D24S8 = 0x2b, |
| 58 | X4V4Z24__COV4R4V = 0x2c, | 58 | X4V4Z24__COV4R4V = 0x2c, |
| 59 | X4V4Z24__COV8R8V = 0x2d, | 59 | X4V4Z24__COV8R8V = 0x2d, |
| 60 | V8Z24__COV4R12V = 0x2e, | 60 | V8Z24__COV4R12V = 0x2e, |
| 61 | ZF32 = 0x2f, | 61 | D32 = 0x2f, |
| 62 | ZF32_X24S8 = 0x30, | 62 | D32S8 = 0x30, |
| 63 | X8Z24_X20V4S8__COV4R4V = 0x31, | 63 | X8Z24_X20V4S8__COV4R4V = 0x31, |
| 64 | X8Z24_X20V4S8__COV8R8V = 0x32, | 64 | X8Z24_X20V4S8__COV8R8V = 0x32, |
| 65 | ZF32_X20V4X8__COV4R4V = 0x33, | 65 | ZF32_X20V4X8__COV4R4V = 0x33, |
| @@ -69,7 +69,7 @@ enum class TextureFormat : u32 { | |||
| 69 | X8Z24_X16V8S8__COV4R12V = 0x37, | 69 | X8Z24_X16V8S8__COV4R12V = 0x37, |
| 70 | ZF32_X16V8X8__COV4R12V = 0x38, | 70 | ZF32_X16V8X8__COV4R12V = 0x38, |
| 71 | ZF32_X16V8S8__COV4R12V = 0x39, | 71 | ZF32_X16V8S8__COV4R12V = 0x39, |
| 72 | Z16 = 0x3a, | 72 | D16 = 0x3a, |
| 73 | V8Z24__COV8R24V = 0x3b, | 73 | V8Z24__COV8R24V = 0x3b, |
| 74 | X8Z24_X16V8S8__COV8R24V = 0x3c, | 74 | X8Z24_X16V8S8__COV8R24V = 0x3c, |
| 75 | ZF32_X16V8X8__COV8R24V = 0x3d, | 75 | ZF32_X16V8X8__COV8R24V = 0x3d, |
| @@ -375,7 +375,4 @@ struct FullTextureInfo { | |||
| 375 | TSCEntry tsc; | 375 | TSCEntry tsc; |
| 376 | }; | 376 | }; |
| 377 | 377 | ||
| 378 | /// Returns the number of bytes per pixel of the input texture format. | ||
| 379 | u32 BytesPerPixel(TextureFormat format); | ||
| 380 | |||
| 381 | } // namespace Tegra::Texture | 378 | } // namespace Tegra::Texture |
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 5738787ac..8fc322b30 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp | |||
| @@ -567,7 +567,7 @@ void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_p | |||
| 567 | screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32); | 567 | screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32); |
| 568 | renderer.RequestScreenshot( | 568 | renderer.RequestScreenshot( |
| 569 | screenshot_image.bits(), | 569 | screenshot_image.bits(), |
| 570 | [=] { | 570 | [=, this] { |
| 571 | const std::string std_screenshot_path = screenshot_path.toStdString(); | 571 | const std::string std_screenshot_path = screenshot_path.toStdString(); |
| 572 | if (screenshot_image.mirrored(false, true).save(screenshot_path)) { | 572 | if (screenshot_image.mirrored(false, true).save(screenshot_path)) { |
| 573 | LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path); | 573 | LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path); |
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 59a193edd..cb71b8d11 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -578,7 +578,6 @@ void Config::ReadPathValues() { | |||
| 578 | 578 | ||
| 579 | UISettings::values.roms_path = ReadSetting(QStringLiteral("romsPath")).toString(); | 579 | UISettings::values.roms_path = ReadSetting(QStringLiteral("romsPath")).toString(); |
| 580 | UISettings::values.symbols_path = ReadSetting(QStringLiteral("symbolsPath")).toString(); | 580 | UISettings::values.symbols_path = ReadSetting(QStringLiteral("symbolsPath")).toString(); |
| 581 | UISettings::values.screenshot_path = ReadSetting(QStringLiteral("screenshotPath")).toString(); | ||
| 582 | UISettings::values.game_dir_deprecated = | 581 | UISettings::values.game_dir_deprecated = |
| 583 | ReadSetting(QStringLiteral("gameListRootDir"), QStringLiteral(".")).toString(); | 582 | ReadSetting(QStringLiteral("gameListRootDir"), QStringLiteral(".")).toString(); |
| 584 | UISettings::values.game_dir_deprecated_deepscan = | 583 | UISettings::values.game_dir_deprecated_deepscan = |
| @@ -666,8 +665,6 @@ void Config::ReadRendererValues() { | |||
| 666 | QStringLiteral("use_asynchronous_shaders"), false); | 665 | QStringLiteral("use_asynchronous_shaders"), false); |
| 667 | ReadSettingGlobal(Settings::values.use_fast_gpu_time, QStringLiteral("use_fast_gpu_time"), | 666 | ReadSettingGlobal(Settings::values.use_fast_gpu_time, QStringLiteral("use_fast_gpu_time"), |
| 668 | true); | 667 | true); |
| 669 | ReadSettingGlobal(Settings::values.force_30fps_mode, QStringLiteral("force_30fps_mode"), false); | ||
| 670 | |||
| 671 | ReadSettingGlobal(Settings::values.bg_red, QStringLiteral("bg_red"), 0.0); | 668 | ReadSettingGlobal(Settings::values.bg_red, QStringLiteral("bg_red"), 0.0); |
| 672 | ReadSettingGlobal(Settings::values.bg_green, QStringLiteral("bg_green"), 0.0); | 669 | ReadSettingGlobal(Settings::values.bg_green, QStringLiteral("bg_green"), 0.0); |
| 673 | ReadSettingGlobal(Settings::values.bg_blue, QStringLiteral("bg_blue"), 0.0); | 670 | ReadSettingGlobal(Settings::values.bg_blue, QStringLiteral("bg_blue"), 0.0); |
| @@ -675,6 +672,22 @@ void Config::ReadRendererValues() { | |||
| 675 | qt_config->endGroup(); | 672 | qt_config->endGroup(); |
| 676 | } | 673 | } |
| 677 | 674 | ||
| 675 | void Config::ReadScreenshotValues() { | ||
| 676 | qt_config->beginGroup(QStringLiteral("Screenshots")); | ||
| 677 | |||
| 678 | UISettings::values.enable_screenshot_save_as = | ||
| 679 | ReadSetting(QStringLiteral("enable_screenshot_save_as"), true).toBool(); | ||
| 680 | FileUtil::GetUserPath( | ||
| 681 | FileUtil::UserPath::ScreenshotsDir, | ||
| 682 | qt_config | ||
| 683 | ->value(QStringLiteral("screenshot_path"), QString::fromStdString(FileUtil::GetUserPath( | ||
| 684 | FileUtil::UserPath::ScreenshotsDir))) | ||
| 685 | .toString() | ||
| 686 | .toStdString()); | ||
| 687 | |||
| 688 | qt_config->endGroup(); | ||
| 689 | } | ||
| 690 | |||
| 678 | void Config::ReadShortcutValues() { | 691 | void Config::ReadShortcutValues() { |
| 679 | qt_config->beginGroup(QStringLiteral("Shortcuts")); | 692 | qt_config->beginGroup(QStringLiteral("Shortcuts")); |
| 680 | 693 | ||
| @@ -756,6 +769,7 @@ void Config::ReadUIValues() { | |||
| 756 | ReadUIGamelistValues(); | 769 | ReadUIGamelistValues(); |
| 757 | ReadUILayoutValues(); | 770 | ReadUILayoutValues(); |
| 758 | ReadPathValues(); | 771 | ReadPathValues(); |
| 772 | ReadScreenshotValues(); | ||
| 759 | ReadShortcutValues(); | 773 | ReadShortcutValues(); |
| 760 | 774 | ||
| 761 | UISettings::values.single_window_mode = | 775 | UISettings::values.single_window_mode = |
| @@ -1085,7 +1099,6 @@ void Config::SavePathValues() { | |||
| 1085 | 1099 | ||
| 1086 | WriteSetting(QStringLiteral("romsPath"), UISettings::values.roms_path); | 1100 | WriteSetting(QStringLiteral("romsPath"), UISettings::values.roms_path); |
| 1087 | WriteSetting(QStringLiteral("symbolsPath"), UISettings::values.symbols_path); | 1101 | WriteSetting(QStringLiteral("symbolsPath"), UISettings::values.symbols_path); |
| 1088 | WriteSetting(QStringLiteral("screenshotPath"), UISettings::values.screenshot_path); | ||
| 1089 | qt_config->beginWriteArray(QStringLiteral("gamedirs")); | 1102 | qt_config->beginWriteArray(QStringLiteral("gamedirs")); |
| 1090 | for (int i = 0; i < UISettings::values.game_dirs.size(); ++i) { | 1103 | for (int i = 0; i < UISettings::values.game_dirs.size(); ++i) { |
| 1091 | qt_config->setArrayIndex(i); | 1104 | qt_config->setArrayIndex(i); |
| @@ -1153,9 +1166,6 @@ void Config::SaveRendererValues() { | |||
| 1153 | Settings::values.use_asynchronous_shaders, false); | 1166 | Settings::values.use_asynchronous_shaders, false); |
| 1154 | WriteSettingGlobal(QStringLiteral("use_fast_gpu_time"), Settings::values.use_fast_gpu_time, | 1167 | WriteSettingGlobal(QStringLiteral("use_fast_gpu_time"), Settings::values.use_fast_gpu_time, |
| 1155 | true); | 1168 | true); |
| 1156 | WriteSettingGlobal(QStringLiteral("force_30fps_mode"), Settings::values.force_30fps_mode, | ||
| 1157 | false); | ||
| 1158 | |||
| 1159 | // Cast to double because Qt's written float values are not human-readable | 1169 | // Cast to double because Qt's written float values are not human-readable |
| 1160 | WriteSettingGlobal(QStringLiteral("bg_red"), Settings::values.bg_red, 0.0); | 1170 | WriteSettingGlobal(QStringLiteral("bg_red"), Settings::values.bg_red, 0.0); |
| 1161 | WriteSettingGlobal(QStringLiteral("bg_green"), Settings::values.bg_green, 0.0); | 1171 | WriteSettingGlobal(QStringLiteral("bg_green"), Settings::values.bg_green, 0.0); |
| @@ -1164,6 +1174,17 @@ void Config::SaveRendererValues() { | |||
| 1164 | qt_config->endGroup(); | 1174 | qt_config->endGroup(); |
| 1165 | } | 1175 | } |
| 1166 | 1176 | ||
| 1177 | void Config::SaveScreenshotValues() { | ||
| 1178 | qt_config->beginGroup(QStringLiteral("Screenshots")); | ||
| 1179 | |||
| 1180 | WriteSetting(QStringLiteral("enable_screenshot_save_as"), | ||
| 1181 | UISettings::values.enable_screenshot_save_as); | ||
| 1182 | WriteSetting(QStringLiteral("screenshot_path"), | ||
| 1183 | QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))); | ||
| 1184 | |||
| 1185 | qt_config->endGroup(); | ||
| 1186 | } | ||
| 1187 | |||
| 1167 | void Config::SaveShortcutValues() { | 1188 | void Config::SaveShortcutValues() { |
| 1168 | qt_config->beginGroup(QStringLiteral("Shortcuts")); | 1189 | qt_config->beginGroup(QStringLiteral("Shortcuts")); |
| 1169 | 1190 | ||
| @@ -1226,6 +1247,7 @@ void Config::SaveUIValues() { | |||
| 1226 | SaveUIGamelistValues(); | 1247 | SaveUIGamelistValues(); |
| 1227 | SaveUILayoutValues(); | 1248 | SaveUILayoutValues(); |
| 1228 | SavePathValues(); | 1249 | SavePathValues(); |
| 1250 | SaveScreenshotValues(); | ||
| 1229 | SaveShortcutValues(); | 1251 | SaveShortcutValues(); |
| 1230 | 1252 | ||
| 1231 | WriteSetting(QStringLiteral("singleWindowMode"), UISettings::values.single_window_mode, true); | 1253 | WriteSetting(QStringLiteral("singleWindowMode"), UISettings::values.single_window_mode, true); |
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 8e815f829..e5f39b040 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h | |||
| @@ -51,6 +51,7 @@ private: | |||
| 51 | void ReadPathValues(); | 51 | void ReadPathValues(); |
| 52 | void ReadCpuValues(); | 52 | void ReadCpuValues(); |
| 53 | void ReadRendererValues(); | 53 | void ReadRendererValues(); |
| 54 | void ReadScreenshotValues(); | ||
| 54 | void ReadShortcutValues(); | 55 | void ReadShortcutValues(); |
| 55 | void ReadSystemValues(); | 56 | void ReadSystemValues(); |
| 56 | void ReadUIValues(); | 57 | void ReadUIValues(); |
| @@ -76,6 +77,7 @@ private: | |||
| 76 | void SavePathValues(); | 77 | void SavePathValues(); |
| 77 | void SaveCpuValues(); | 78 | void SaveCpuValues(); |
| 78 | void SaveRendererValues(); | 79 | void SaveRendererValues(); |
| 80 | void SaveScreenshotValues(); | ||
| 79 | void SaveShortcutValues(); | 81 | void SaveShortcutValues(); |
| 80 | void SaveSystemValues(); | 82 | void SaveSystemValues(); |
| 81 | void SaveUIValues(); | 83 | void SaveUIValues(); |
diff --git a/src/yuzu/configuration/configuration_shared.cpp b/src/yuzu/configuration/configuration_shared.cpp index bb47c3933..f9becab6e 100644 --- a/src/yuzu/configuration/configuration_shared.cpp +++ b/src/yuzu/configuration/configuration_shared.cpp | |||
| @@ -4,17 +4,20 @@ | |||
| 4 | 4 | ||
| 5 | #include <QCheckBox> | 5 | #include <QCheckBox> |
| 6 | #include <QComboBox> | 6 | #include <QComboBox> |
| 7 | #include <QObject> | ||
| 8 | #include <QString> | ||
| 7 | #include "core/settings.h" | 9 | #include "core/settings.h" |
| 8 | #include "yuzu/configuration/configuration_shared.h" | 10 | #include "yuzu/configuration/configuration_shared.h" |
| 9 | #include "yuzu/configuration/configure_per_game.h" | 11 | #include "yuzu/configuration/configure_per_game.h" |
| 10 | 12 | ||
| 11 | void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<bool>* setting, | 13 | void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<bool>* setting, |
| 12 | const QCheckBox* checkbox) { | 14 | const QCheckBox* checkbox, |
| 13 | if (checkbox->checkState() == Qt::PartiallyChecked) { | 15 | const CheckState& tracker) { |
| 16 | if (tracker == CheckState::Global) { | ||
| 14 | setting->SetGlobal(true); | 17 | setting->SetGlobal(true); |
| 15 | } else { | 18 | } else { |
| 16 | setting->SetGlobal(false); | 19 | setting->SetGlobal(false); |
| 17 | setting->SetValue(checkbox->checkState() == Qt::Checked); | 20 | setting->SetValue(checkbox->checkState()); |
| 18 | } | 21 | } |
| 19 | } | 22 | } |
| 20 | 23 | ||
| @@ -69,8 +72,69 @@ void ConfigurationShared::SetPerGameSetting( | |||
| 69 | ConfigurationShared::USE_GLOBAL_OFFSET); | 72 | ConfigurationShared::USE_GLOBAL_OFFSET); |
| 70 | } | 73 | } |
| 71 | 74 | ||
| 72 | void ConfigurationShared::InsertGlobalItem(QComboBox* combobox) { | 75 | void ConfigurationShared::SetHighlight(QWidget* widget, const std::string& name, bool highlighted) { |
| 73 | const QString use_global_text = ConfigurePerGame::tr("Use global configuration"); | 76 | if (highlighted) { |
| 77 | widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,203,255,0.5) }") | ||
| 78 | .arg(QString::fromStdString(name))); | ||
| 79 | } else { | ||
| 80 | widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,0,0,0) }") | ||
| 81 | .arg(QString::fromStdString(name))); | ||
| 82 | } | ||
| 83 | widget->show(); | ||
| 84 | } | ||
| 85 | |||
| 86 | void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::string& name, | ||
| 87 | const Settings::Setting<bool>& setting, | ||
| 88 | CheckState& tracker) { | ||
| 89 | if (setting.UsingGlobal()) { | ||
| 90 | tracker = CheckState::Global; | ||
| 91 | } else { | ||
| 92 | tracker = (setting.GetValue() == setting.GetValue(true)) ? CheckState::On : CheckState::Off; | ||
| 93 | } | ||
| 94 | SetHighlight(checkbox, name, tracker != CheckState::Global); | ||
| 95 | QObject::connect(checkbox, &QCheckBox::clicked, checkbox, | ||
| 96 | [checkbox, name, setting, &tracker]() { | ||
| 97 | tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) % | ||
| 98 | static_cast<int>(CheckState::Count)); | ||
| 99 | if (tracker == CheckState::Global) { | ||
| 100 | checkbox->setChecked(setting.GetValue(true)); | ||
| 101 | } | ||
| 102 | SetHighlight(checkbox, name, tracker != CheckState::Global); | ||
| 103 | }); | ||
| 104 | } | ||
| 105 | |||
| 106 | void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::string& name, | ||
| 107 | bool global, bool state, bool global_state, | ||
| 108 | CheckState& tracker) { | ||
| 109 | if (global) { | ||
| 110 | tracker = CheckState::Global; | ||
| 111 | } else { | ||
| 112 | tracker = (state == global_state) ? CheckState::On : CheckState::Off; | ||
| 113 | } | ||
| 114 | SetHighlight(checkbox, name, tracker != CheckState::Global); | ||
| 115 | QObject::connect(checkbox, &QCheckBox::clicked, checkbox, | ||
| 116 | [checkbox, name, global_state, &tracker]() { | ||
| 117 | tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) % | ||
| 118 | static_cast<int>(CheckState::Count)); | ||
| 119 | if (tracker == CheckState::Global) { | ||
| 120 | checkbox->setChecked(global_state); | ||
| 121 | } | ||
| 122 | SetHighlight(checkbox, name, tracker != CheckState::Global); | ||
| 123 | }); | ||
| 124 | } | ||
| 125 | |||
| 126 | void ConfigurationShared::SetColoredComboBox(QComboBox* combobox, QWidget* target, | ||
| 127 | const std::string& target_name, int global) { | ||
| 128 | InsertGlobalItem(combobox, global); | ||
| 129 | QObject::connect(combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), target, | ||
| 130 | [target, target_name](int index) { | ||
| 131 | ConfigurationShared::SetHighlight(target, target_name, index != 0); | ||
| 132 | }); | ||
| 133 | } | ||
| 134 | |||
| 135 | void ConfigurationShared::InsertGlobalItem(QComboBox* combobox, int global_index) { | ||
| 136 | const QString use_global_text = | ||
| 137 | ConfigurePerGame::tr("Use global configuration (%1)").arg(combobox->itemText(global_index)); | ||
| 74 | combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text); | 138 | combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text); |
| 75 | combobox->insertSeparator(ConfigurationShared::USE_GLOBAL_SEPARATOR_INDEX); | 139 | combobox->insertSeparator(ConfigurationShared::USE_GLOBAL_SEPARATOR_INDEX); |
| 76 | } | 140 | } |
diff --git a/src/yuzu/configuration/configuration_shared.h b/src/yuzu/configuration/configuration_shared.h index b11b1b950..003148c68 100644 --- a/src/yuzu/configuration/configuration_shared.h +++ b/src/yuzu/configuration/configuration_shared.h | |||
| @@ -15,9 +15,17 @@ constexpr int USE_GLOBAL_INDEX = 0; | |||
| 15 | constexpr int USE_GLOBAL_SEPARATOR_INDEX = 1; | 15 | constexpr int USE_GLOBAL_SEPARATOR_INDEX = 1; |
| 16 | constexpr int USE_GLOBAL_OFFSET = 2; | 16 | constexpr int USE_GLOBAL_OFFSET = 2; |
| 17 | 17 | ||
| 18 | enum class CheckState { | ||
| 19 | Off, | ||
| 20 | On, | ||
| 21 | Global, | ||
| 22 | Count, | ||
| 23 | }; | ||
| 24 | |||
| 18 | // Global-aware apply and set functions | 25 | // Global-aware apply and set functions |
| 19 | 26 | ||
| 20 | void ApplyPerGameSetting(Settings::Setting<bool>* setting, const QCheckBox* checkbox); | 27 | void ApplyPerGameSetting(Settings::Setting<bool>* setting, const QCheckBox* checkbox, |
| 28 | const CheckState& tracker); | ||
| 21 | void ApplyPerGameSetting(Settings::Setting<int>* setting, const QComboBox* combobox); | 29 | void ApplyPerGameSetting(Settings::Setting<int>* setting, const QComboBox* combobox); |
| 22 | void ApplyPerGameSetting(Settings::Setting<Settings::RendererBackend>* setting, | 30 | void ApplyPerGameSetting(Settings::Setting<Settings::RendererBackend>* setting, |
| 23 | const QComboBox* combobox); | 31 | const QComboBox* combobox); |
| @@ -31,6 +39,14 @@ void SetPerGameSetting(QComboBox* combobox, | |||
| 31 | void SetPerGameSetting(QComboBox* combobox, | 39 | void SetPerGameSetting(QComboBox* combobox, |
| 32 | const Settings::Setting<Settings::GPUAccuracy>* setting); | 40 | const Settings::Setting<Settings::GPUAccuracy>* setting); |
| 33 | 41 | ||
| 34 | void InsertGlobalItem(QComboBox* combobox); | 42 | void SetHighlight(QWidget* widget, const std::string& name, bool highlighted); |
| 43 | void SetColoredTristate(QCheckBox* checkbox, const std::string& name, | ||
| 44 | const Settings::Setting<bool>& setting, CheckState& tracker); | ||
| 45 | void SetColoredTristate(QCheckBox* checkbox, const std::string& name, bool global, bool state, | ||
| 46 | bool global_state, CheckState& tracker); | ||
| 47 | void SetColoredComboBox(QComboBox* combobox, QWidget* target, const std::string& target_name, | ||
| 48 | int global); | ||
| 49 | |||
| 50 | void InsertGlobalItem(QComboBox* combobox, int global_index); | ||
| 35 | 51 | ||
| 36 | } // namespace ConfigurationShared | 52 | } // namespace ConfigurationShared |
diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index cc021beec..fea632531 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp | |||
| @@ -49,12 +49,9 @@ void ConfigureAudio::SetConfiguration() { | |||
| 49 | 49 | ||
| 50 | ui->volume_slider->setValue(Settings::values.volume.GetValue() * ui->volume_slider->maximum()); | 50 | ui->volume_slider->setValue(Settings::values.volume.GetValue() * ui->volume_slider->maximum()); |
| 51 | 51 | ||
| 52 | if (Settings::configuring_global) { | 52 | ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching.GetValue()); |
| 53 | ui->toggle_audio_stretching->setChecked( | 53 | |
| 54 | Settings::values.enable_audio_stretching.GetValue()); | 54 | if (!Settings::configuring_global) { |
| 55 | } else { | ||
| 56 | ConfigurationShared::SetPerGameSetting(ui->toggle_audio_stretching, | ||
| 57 | &Settings::values.enable_audio_stretching); | ||
| 58 | if (Settings::values.volume.UsingGlobal()) { | 55 | if (Settings::values.volume.UsingGlobal()) { |
| 59 | ui->volume_combo_box->setCurrentIndex(0); | 56 | ui->volume_combo_box->setCurrentIndex(0); |
| 60 | ui->volume_slider->setEnabled(false); | 57 | ui->volume_slider->setEnabled(false); |
| @@ -62,6 +59,8 @@ void ConfigureAudio::SetConfiguration() { | |||
| 62 | ui->volume_combo_box->setCurrentIndex(1); | 59 | ui->volume_combo_box->setCurrentIndex(1); |
| 63 | ui->volume_slider->setEnabled(true); | 60 | ui->volume_slider->setEnabled(true); |
| 64 | } | 61 | } |
| 62 | ConfigurationShared::SetHighlight(ui->volume_layout, "volume_layout", | ||
| 63 | !Settings::values.volume.UsingGlobal()); | ||
| 65 | } | 64 | } |
| 66 | SetVolumeIndicatorText(ui->volume_slider->sliderPosition()); | 65 | SetVolumeIndicatorText(ui->volume_slider->sliderPosition()); |
| 67 | } | 66 | } |
| @@ -120,7 +119,8 @@ void ConfigureAudio::ApplyConfiguration() { | |||
| 120 | } | 119 | } |
| 121 | } else { | 120 | } else { |
| 122 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.enable_audio_stretching, | 121 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.enable_audio_stretching, |
| 123 | ui->toggle_audio_stretching); | 122 | ui->toggle_audio_stretching, |
| 123 | enable_audio_stretching); | ||
| 124 | if (ui->volume_combo_box->currentIndex() == 0) { | 124 | if (ui->volume_combo_box->currentIndex() == 0) { |
| 125 | Settings::values.volume.SetGlobal(true); | 125 | Settings::values.volume.SetGlobal(true); |
| 126 | } else { | 126 | } else { |
| @@ -173,9 +173,14 @@ void ConfigureAudio::SetupPerGameUI() { | |||
| 173 | return; | 173 | return; |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | ui->toggle_audio_stretching->setTristate(true); | 176 | ConfigurationShared::SetColoredTristate(ui->toggle_audio_stretching, "toggle_audio_stretching", |
| 177 | Settings::values.enable_audio_stretching, | ||
| 178 | enable_audio_stretching); | ||
| 177 | connect(ui->volume_combo_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), | 179 | connect(ui->volume_combo_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), |
| 178 | this, [this](int index) { ui->volume_slider->setEnabled(index == 1); }); | 180 | this, [this](int index) { |
| 181 | ui->volume_slider->setEnabled(index == 1); | ||
| 182 | ConfigurationShared::SetHighlight(ui->volume_layout, "volume_layout", index == 1); | ||
| 183 | }); | ||
| 179 | 184 | ||
| 180 | ui->output_sink_combo_box->setVisible(false); | 185 | ui->output_sink_combo_box->setVisible(false); |
| 181 | ui->output_sink_label->setVisible(false); | 186 | ui->output_sink_label->setVisible(false); |
diff --git a/src/yuzu/configuration/configure_audio.h b/src/yuzu/configuration/configure_audio.h index d84f4a682..9dbd3d93e 100644 --- a/src/yuzu/configuration/configure_audio.h +++ b/src/yuzu/configuration/configure_audio.h | |||
| @@ -7,6 +7,10 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <QWidget> | 8 | #include <QWidget> |
| 9 | 9 | ||
| 10 | namespace ConfigurationShared { | ||
| 11 | enum class CheckState; | ||
| 12 | } | ||
| 13 | |||
| 10 | namespace Ui { | 14 | namespace Ui { |
| 11 | class ConfigureAudio; | 15 | class ConfigureAudio; |
| 12 | } | 16 | } |
| @@ -37,4 +41,6 @@ private: | |||
| 37 | void SetupPerGameUI(); | 41 | void SetupPerGameUI(); |
| 38 | 42 | ||
| 39 | std::unique_ptr<Ui::ConfigureAudio> ui; | 43 | std::unique_ptr<Ui::ConfigureAudio> ui; |
| 44 | |||
| 45 | ConfigurationShared::CheckState enable_audio_stretching; | ||
| 40 | }; | 46 | }; |
diff --git a/src/yuzu/configuration/configure_audio.ui b/src/yuzu/configuration/configure_audio.ui index 862ccb988..9bd0cca96 100644 --- a/src/yuzu/configuration/configure_audio.ui +++ b/src/yuzu/configuration/configure_audio.ui | |||
| @@ -56,80 +56,91 @@ | |||
| 56 | </layout> | 56 | </layout> |
| 57 | </item> | 57 | </item> |
| 58 | <item> | 58 | <item> |
| 59 | <layout class="QHBoxLayout" name="horizontalLayout_2"> | 59 | <widget class="QWidget" name="volume_layout" native="true"> |
| 60 | <property name="topMargin"> | 60 | <layout class="QHBoxLayout" name="horizontalLayout_2"> |
| 61 | <number>0</number> | 61 | <property name="leftMargin"> |
| 62 | </property> | 62 | <number>0</number> |
| 63 | <item> | 63 | </property> |
| 64 | <widget class="QComboBox" name="volume_combo_box"> | 64 | <property name="topMargin"> |
| 65 | <item> | 65 | <number>0</number> |
| 66 | </property> | ||
| 67 | <property name="rightMargin"> | ||
| 68 | <number>0</number> | ||
| 69 | </property> | ||
| 70 | <property name="bottomMargin"> | ||
| 71 | <number>0</number> | ||
| 72 | </property> | ||
| 73 | <item> | ||
| 74 | <widget class="QComboBox" name="volume_combo_box"> | ||
| 75 | <item> | ||
| 76 | <property name="text"> | ||
| 77 | <string>Use global volume</string> | ||
| 78 | </property> | ||
| 79 | </item> | ||
| 80 | <item> | ||
| 81 | <property name="text"> | ||
| 82 | <string>Set volume:</string> | ||
| 83 | </property> | ||
| 84 | </item> | ||
| 85 | </widget> | ||
| 86 | </item> | ||
| 87 | <item> | ||
| 88 | <widget class="QLabel" name="volume_label"> | ||
| 66 | <property name="text"> | 89 | <property name="text"> |
| 67 | <string>Use global volume</string> | 90 | <string>Volume:</string> |
| 91 | </property> | ||
| 92 | </widget> | ||
| 93 | </item> | ||
| 94 | <item> | ||
| 95 | <spacer name="horizontalSpacer"> | ||
| 96 | <property name="orientation"> | ||
| 97 | <enum>Qt::Horizontal</enum> | ||
| 98 | </property> | ||
| 99 | <property name="sizeHint" stdset="0"> | ||
| 100 | <size> | ||
| 101 | <width>30</width> | ||
| 102 | <height>20</height> | ||
| 103 | </size> | ||
| 104 | </property> | ||
| 105 | </spacer> | ||
| 106 | </item> | ||
| 107 | <item> | ||
| 108 | <widget class="QSlider" name="volume_slider"> | ||
| 109 | <property name="sizePolicy"> | ||
| 110 | <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> | ||
| 111 | <horstretch>0</horstretch> | ||
| 112 | <verstretch>0</verstretch> | ||
| 113 | </sizepolicy> | ||
| 114 | </property> | ||
| 115 | <property name="maximum"> | ||
| 116 | <number>100</number> | ||
| 117 | </property> | ||
| 118 | <property name="pageStep"> | ||
| 119 | <number>10</number> | ||
| 120 | </property> | ||
| 121 | <property name="orientation"> | ||
| 122 | <enum>Qt::Horizontal</enum> | ||
| 123 | </property> | ||
| 124 | </widget> | ||
| 125 | </item> | ||
| 126 | <item> | ||
| 127 | <widget class="QLabel" name="volume_indicator"> | ||
| 128 | <property name="minimumSize"> | ||
| 129 | <size> | ||
| 130 | <width>32</width> | ||
| 131 | <height>0</height> | ||
| 132 | </size> | ||
| 68 | </property> | 133 | </property> |
| 69 | </item> | ||
| 70 | <item> | ||
| 71 | <property name="text"> | 134 | <property name="text"> |
| 72 | <string>Set volume:</string> | 135 | <string>0 %</string> |
| 73 | </property> | 136 | </property> |
| 74 | </item> | 137 | <property name="alignment"> |
| 75 | </widget> | 138 | <set>Qt::AlignCenter</set> |
| 76 | </item> | 139 | </property> |
| 77 | <item> | 140 | </widget> |
| 78 | <widget class="QLabel" name="volume_label"> | 141 | </item> |
| 79 | <property name="text"> | 142 | </layout> |
| 80 | <string>Volume:</string> | 143 | </widget> |
| 81 | </property> | ||
| 82 | </widget> | ||
| 83 | </item> | ||
| 84 | <item> | ||
| 85 | <spacer name="horizontalSpacer"> | ||
| 86 | <property name="orientation"> | ||
| 87 | <enum>Qt::Horizontal</enum> | ||
| 88 | </property> | ||
| 89 | <property name="sizeHint" stdset="0"> | ||
| 90 | <size> | ||
| 91 | <width>30</width> | ||
| 92 | <height>20</height> | ||
| 93 | </size> | ||
| 94 | </property> | ||
| 95 | </spacer> | ||
| 96 | </item> | ||
| 97 | <item> | ||
| 98 | <widget class="QSlider" name="volume_slider"> | ||
| 99 | <property name="sizePolicy"> | ||
| 100 | <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> | ||
| 101 | <horstretch>0</horstretch> | ||
| 102 | <verstretch>0</verstretch> | ||
| 103 | </sizepolicy> | ||
| 104 | </property> | ||
| 105 | <property name="maximum"> | ||
| 106 | <number>100</number> | ||
| 107 | </property> | ||
| 108 | <property name="pageStep"> | ||
| 109 | <number>10</number> | ||
| 110 | </property> | ||
| 111 | <property name="orientation"> | ||
| 112 | <enum>Qt::Horizontal</enum> | ||
| 113 | </property> | ||
| 114 | </widget> | ||
| 115 | </item> | ||
| 116 | <item> | ||
| 117 | <widget class="QLabel" name="volume_indicator"> | ||
| 118 | <property name="minimumSize"> | ||
| 119 | <size> | ||
| 120 | <width>32</width> | ||
| 121 | <height>0</height> | ||
| 122 | </size> | ||
| 123 | </property> | ||
| 124 | <property name="text"> | ||
| 125 | <string>0 %</string> | ||
| 126 | </property> | ||
| 127 | <property name="alignment"> | ||
| 128 | <set>Qt::AlignCenter</set> | ||
| 129 | </property> | ||
| 130 | </widget> | ||
| 131 | </item> | ||
| 132 | </layout> | ||
| 133 | </item> | 144 | </item> |
| 134 | </layout> | 145 | </layout> |
| 135 | </widget> | 146 | </widget> |
diff --git a/src/yuzu/configuration/configure_debug.ui b/src/yuzu/configuration/configure_debug.ui index 272bdd6b8..9d6feb9f7 100644 --- a/src/yuzu/configuration/configure_debug.ui +++ b/src/yuzu/configuration/configure_debug.ui | |||
| @@ -171,26 +171,6 @@ | |||
| 171 | </property> | 171 | </property> |
| 172 | <layout class="QVBoxLayout" name="verticalLayout_6"> | 172 | <layout class="QVBoxLayout" name="verticalLayout_6"> |
| 173 | <item> | 173 | <item> |
| 174 | <widget class="QCheckBox" name="dump_decompressed_nso"> | ||
| 175 | <property name="whatsThis"> | ||
| 176 | <string>When checked, any NSO yuzu tries to load or patch will be copied decompressed to the yuzu/dump directory.</string> | ||
| 177 | </property> | ||
| 178 | <property name="text"> | ||
| 179 | <string>Dump Decompressed NSOs</string> | ||
| 180 | </property> | ||
| 181 | </widget> | ||
| 182 | </item> | ||
| 183 | <item> | ||
| 184 | <widget class="QCheckBox" name="dump_exefs"> | ||
| 185 | <property name="whatsThis"> | ||
| 186 | <string>When checked, any game that yuzu loads will have its ExeFS dumped to the yuzu/dump directory.</string> | ||
| 187 | </property> | ||
| 188 | <property name="text"> | ||
| 189 | <string>Dump ExeFS</string> | ||
| 190 | </property> | ||
| 191 | </widget> | ||
| 192 | </item> | ||
| 193 | <item> | ||
| 194 | <widget class="QCheckBox" name="reporting_services"> | 174 | <widget class="QCheckBox" name="reporting_services"> |
| 195 | <property name="text"> | 175 | <property name="text"> |
| 196 | <string>Enable Verbose Reporting Services</string> | 176 | <string>Enable Verbose Reporting Services</string> |
| @@ -257,8 +237,6 @@ | |||
| 257 | <tabstop>open_log_button</tabstop> | 237 | <tabstop>open_log_button</tabstop> |
| 258 | <tabstop>homebrew_args_edit</tabstop> | 238 | <tabstop>homebrew_args_edit</tabstop> |
| 259 | <tabstop>enable_graphics_debugging</tabstop> | 239 | <tabstop>enable_graphics_debugging</tabstop> |
| 260 | <tabstop>dump_decompressed_nso</tabstop> | ||
| 261 | <tabstop>dump_exefs</tabstop> | ||
| 262 | <tabstop>reporting_services</tabstop> | 240 | <tabstop>reporting_services</tabstop> |
| 263 | <tabstop>quest_flag</tabstop> | 241 | <tabstop>quest_flag</tabstop> |
| 264 | </tabstops> | 242 | </tabstops> |
diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp index 20316c9cc..c0dbd9855 100644 --- a/src/yuzu/configuration/configure_general.cpp +++ b/src/yuzu/configuration/configure_general.cpp | |||
| @@ -19,9 +19,10 @@ ConfigureGeneral::ConfigureGeneral(QWidget* parent) | |||
| 19 | 19 | ||
| 20 | SetConfiguration(); | 20 | SetConfiguration(); |
| 21 | 21 | ||
| 22 | connect(ui->toggle_frame_limit, &QCheckBox::stateChanged, ui->frame_limit, [this]() { | 22 | if (Settings::configuring_global) { |
| 23 | ui->frame_limit->setEnabled(ui->toggle_frame_limit->checkState() == Qt::Checked); | 23 | connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit, |
| 24 | }); | 24 | [this]() { ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked()); }); |
| 25 | } | ||
| 25 | } | 26 | } |
| 26 | 27 | ||
| 27 | ConfigureGeneral::~ConfigureGeneral() = default; | 28 | ConfigureGeneral::~ConfigureGeneral() = default; |
| @@ -40,17 +41,12 @@ void ConfigureGeneral::SetConfiguration() { | |||
| 40 | ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit.GetValue()); | 41 | ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit.GetValue()); |
| 41 | ui->frame_limit->setValue(Settings::values.frame_limit.GetValue()); | 42 | ui->frame_limit->setValue(Settings::values.frame_limit.GetValue()); |
| 42 | 43 | ||
| 43 | if (!Settings::configuring_global) { | 44 | if (Settings::configuring_global) { |
| 44 | if (Settings::values.use_multi_core.UsingGlobal()) { | 45 | ui->frame_limit->setEnabled(Settings::values.use_frame_limit.GetValue()); |
| 45 | ui->use_multi_core->setCheckState(Qt::PartiallyChecked); | 46 | } else { |
| 46 | } | 47 | ui->frame_limit->setEnabled(Settings::values.use_frame_limit.GetValue() && |
| 47 | if (Settings::values.use_frame_limit.UsingGlobal()) { | 48 | use_frame_limit != ConfigurationShared::CheckState::Global); |
| 48 | ui->toggle_frame_limit->setCheckState(Qt::PartiallyChecked); | ||
| 49 | } | ||
| 50 | } | 49 | } |
| 51 | |||
| 52 | ui->frame_limit->setEnabled(ui->toggle_frame_limit->checkState() == Qt::Checked && | ||
| 53 | ui->toggle_frame_limit->isEnabled()); | ||
| 54 | } | 50 | } |
| 55 | 51 | ||
| 56 | void ConfigureGeneral::ApplyConfiguration() { | 52 | void ConfigureGeneral::ApplyConfiguration() { |
| @@ -71,9 +67,9 @@ void ConfigureGeneral::ApplyConfiguration() { | |||
| 71 | } | 67 | } |
| 72 | } else { | 68 | } else { |
| 73 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core, | 69 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core, |
| 74 | ui->use_multi_core); | 70 | ui->use_multi_core, use_multi_core); |
| 75 | 71 | ||
| 76 | bool global_frame_limit = ui->toggle_frame_limit->checkState() == Qt::PartiallyChecked; | 72 | bool global_frame_limit = use_frame_limit == ConfigurationShared::CheckState::Global; |
| 77 | Settings::values.use_frame_limit.SetGlobal(global_frame_limit); | 73 | Settings::values.use_frame_limit.SetGlobal(global_frame_limit); |
| 78 | Settings::values.frame_limit.SetGlobal(global_frame_limit); | 74 | Settings::values.frame_limit.SetGlobal(global_frame_limit); |
| 79 | if (!global_frame_limit) { | 75 | if (!global_frame_limit) { |
| @@ -109,6 +105,13 @@ void ConfigureGeneral::SetupPerGameUI() { | |||
| 109 | ui->toggle_background_pause->setVisible(false); | 105 | ui->toggle_background_pause->setVisible(false); |
| 110 | ui->toggle_hide_mouse->setVisible(false); | 106 | ui->toggle_hide_mouse->setVisible(false); |
| 111 | 107 | ||
| 112 | ui->toggle_frame_limit->setTristate(true); | 108 | ConfigurationShared::SetColoredTristate(ui->toggle_frame_limit, "toggle_frame_limit", |
| 113 | ui->use_multi_core->setTristate(true); | 109 | Settings::values.use_frame_limit, use_frame_limit); |
| 110 | ConfigurationShared::SetColoredTristate(ui->use_multi_core, "use_multi_core", | ||
| 111 | Settings::values.use_multi_core, use_multi_core); | ||
| 112 | |||
| 113 | connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit, [this]() { | ||
| 114 | ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked() && | ||
| 115 | (use_frame_limit != ConfigurationShared::CheckState::Global)); | ||
| 116 | }); | ||
| 114 | } | 117 | } |
diff --git a/src/yuzu/configuration/configure_general.h b/src/yuzu/configuration/configure_general.h index 9c785c22e..323ffbd8f 100644 --- a/src/yuzu/configuration/configure_general.h +++ b/src/yuzu/configuration/configure_general.h | |||
| @@ -7,6 +7,10 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <QWidget> | 8 | #include <QWidget> |
| 9 | 9 | ||
| 10 | namespace ConfigurationShared { | ||
| 11 | enum class CheckState; | ||
| 12 | } | ||
| 13 | |||
| 10 | class HotkeyRegistry; | 14 | class HotkeyRegistry; |
| 11 | 15 | ||
| 12 | namespace Ui { | 16 | namespace Ui { |
| @@ -31,4 +35,7 @@ private: | |||
| 31 | void SetupPerGameUI(); | 35 | void SetupPerGameUI(); |
| 32 | 36 | ||
| 33 | std::unique_ptr<Ui::ConfigureGeneral> ui; | 37 | std::unique_ptr<Ui::ConfigureGeneral> ui; |
| 38 | |||
| 39 | ConfigurationShared::CheckState use_frame_limit; | ||
| 40 | ConfigurationShared::CheckState use_multi_core; | ||
| 34 | }; | 41 | }; |
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index cb4706bd6..3e42531c3 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp | |||
| @@ -31,8 +31,14 @@ ConfigureGraphics::ConfigureGraphics(QWidget* parent) | |||
| 31 | 31 | ||
| 32 | SetConfiguration(); | 32 | SetConfiguration(); |
| 33 | 33 | ||
| 34 | connect(ui->api, qOverload<int>(&QComboBox::currentIndexChanged), this, | 34 | connect(ui->api, qOverload<int>(&QComboBox::currentIndexChanged), this, [this] { |
| 35 | [this] { UpdateDeviceComboBox(); }); | 35 | UpdateDeviceComboBox(); |
| 36 | if (!Settings::configuring_global) { | ||
| 37 | ConfigurationShared::SetHighlight(ui->api_layout, "api_layout", | ||
| 38 | ui->api->currentIndex() != | ||
| 39 | ConfigurationShared::USE_GLOBAL_INDEX); | ||
| 40 | } | ||
| 41 | }); | ||
| 36 | connect(ui->device, qOverload<int>(&QComboBox::activated), this, | 42 | connect(ui->device, qOverload<int>(&QComboBox::activated), this, |
| 37 | [this](int device) { UpdateDeviceSelection(device); }); | 43 | [this](int device) { UpdateDeviceSelection(device); }); |
| 38 | 44 | ||
| @@ -65,25 +71,26 @@ void ConfigureGraphics::SetConfiguration() { | |||
| 65 | ui->api->setEnabled(runtime_lock); | 71 | ui->api->setEnabled(runtime_lock); |
| 66 | ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock); | 72 | ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock); |
| 67 | ui->use_disk_shader_cache->setEnabled(runtime_lock); | 73 | ui->use_disk_shader_cache->setEnabled(runtime_lock); |
| 74 | ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache.GetValue()); | ||
| 75 | ui->use_asynchronous_gpu_emulation->setChecked( | ||
| 76 | Settings::values.use_asynchronous_gpu_emulation.GetValue()); | ||
| 68 | 77 | ||
| 69 | if (Settings::configuring_global) { | 78 | if (Settings::configuring_global) { |
| 70 | ui->api->setCurrentIndex(static_cast<int>(Settings::values.renderer_backend.GetValue())); | 79 | ui->api->setCurrentIndex(static_cast<int>(Settings::values.renderer_backend.GetValue())); |
| 71 | ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); | 80 | ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); |
| 72 | ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache.GetValue()); | ||
| 73 | ui->use_asynchronous_gpu_emulation->setChecked( | ||
| 74 | Settings::values.use_asynchronous_gpu_emulation.GetValue()); | ||
| 75 | } else { | 81 | } else { |
| 76 | ConfigurationShared::SetPerGameSetting(ui->use_disk_shader_cache, | ||
| 77 | &Settings::values.use_disk_shader_cache); | ||
| 78 | ConfigurationShared::SetPerGameSetting(ui->use_asynchronous_gpu_emulation, | ||
| 79 | &Settings::values.use_asynchronous_gpu_emulation); | ||
| 80 | |||
| 81 | ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend); | 82 | ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend); |
| 83 | ConfigurationShared::SetHighlight(ui->api_layout, "api_layout", | ||
| 84 | !Settings::values.renderer_backend.UsingGlobal()); | ||
| 82 | ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox, | 85 | ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox, |
| 83 | &Settings::values.aspect_ratio); | 86 | &Settings::values.aspect_ratio); |
| 84 | 87 | ||
| 85 | ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1); | 88 | ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1); |
| 86 | ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal()); | 89 | ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal()); |
| 90 | ConfigurationShared::SetHighlight(ui->ar_label, "ar_label", | ||
| 91 | !Settings::values.aspect_ratio.UsingGlobal()); | ||
| 92 | ConfigurationShared::SetHighlight(ui->bg_layout, "bg_layout", | ||
| 93 | !Settings::values.bg_red.UsingGlobal()); | ||
| 87 | } | 94 | } |
| 88 | 95 | ||
| 89 | UpdateBackgroundColorButton(QColor::fromRgbF(Settings::values.bg_red.GetValue(), | 96 | UpdateBackgroundColorButton(QColor::fromRgbF(Settings::values.bg_red.GetValue(), |
| @@ -135,9 +142,10 @@ void ConfigureGraphics::ApplyConfiguration() { | |||
| 135 | ui->aspect_ratio_combobox); | 142 | ui->aspect_ratio_combobox); |
| 136 | 143 | ||
| 137 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache, | 144 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache, |
| 138 | ui->use_disk_shader_cache); | 145 | ui->use_disk_shader_cache, use_disk_shader_cache); |
| 139 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation, | 146 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation, |
| 140 | ui->use_asynchronous_gpu_emulation); | 147 | ui->use_asynchronous_gpu_emulation, |
| 148 | use_asynchronous_gpu_emulation); | ||
| 141 | 149 | ||
| 142 | if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { | 150 | if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { |
| 143 | Settings::values.bg_red.SetGlobal(true); | 151 | Settings::values.bg_red.SetGlobal(true); |
| @@ -241,10 +249,20 @@ void ConfigureGraphics::SetupPerGameUI() { | |||
| 241 | } | 249 | } |
| 242 | 250 | ||
| 243 | connect(ui->bg_combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, | 251 | connect(ui->bg_combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, |
| 244 | [this](int index) { ui->bg_button->setEnabled(index == 1); }); | 252 | [this](int index) { |
| 245 | 253 | ui->bg_button->setEnabled(index == 1); | |
| 246 | ui->use_disk_shader_cache->setTristate(true); | 254 | ConfigurationShared::SetHighlight(ui->bg_layout, "bg_layout", index == 1); |
| 247 | ui->use_asynchronous_gpu_emulation->setTristate(true); | 255 | }); |
| 248 | ConfigurationShared::InsertGlobalItem(ui->aspect_ratio_combobox); | 256 | |
| 249 | ConfigurationShared::InsertGlobalItem(ui->api); | 257 | ConfigurationShared::SetColoredTristate(ui->use_disk_shader_cache, "use_disk_shader_cache", |
| 258 | Settings::values.use_disk_shader_cache, | ||
| 259 | use_disk_shader_cache); | ||
| 260 | ConfigurationShared::SetColoredTristate( | ||
| 261 | ui->use_asynchronous_gpu_emulation, "use_asynchronous_gpu_emulation", | ||
| 262 | Settings::values.use_asynchronous_gpu_emulation, use_asynchronous_gpu_emulation); | ||
| 263 | |||
| 264 | ConfigurationShared::SetColoredComboBox(ui->aspect_ratio_combobox, ui->ar_label, "ar_label", | ||
| 265 | Settings::values.aspect_ratio.GetValue(true)); | ||
| 266 | ConfigurationShared::InsertGlobalItem( | ||
| 267 | ui->api, static_cast<int>(Settings::values.renderer_backend.GetValue(true))); | ||
| 250 | } | 268 | } |
diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index 24f01c739..b4961f719 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h | |||
| @@ -10,6 +10,10 @@ | |||
| 10 | #include <QWidget> | 10 | #include <QWidget> |
| 11 | #include "core/settings.h" | 11 | #include "core/settings.h" |
| 12 | 12 | ||
| 13 | namespace ConfigurationShared { | ||
| 14 | enum class CheckState; | ||
| 15 | } | ||
| 16 | |||
| 13 | namespace Ui { | 17 | namespace Ui { |
| 14 | class ConfigureGraphics; | 18 | class ConfigureGraphics; |
| 15 | } | 19 | } |
| @@ -42,6 +46,9 @@ private: | |||
| 42 | std::unique_ptr<Ui::ConfigureGraphics> ui; | 46 | std::unique_ptr<Ui::ConfigureGraphics> ui; |
| 43 | QColor bg_color; | 47 | QColor bg_color; |
| 44 | 48 | ||
| 49 | ConfigurationShared::CheckState use_disk_shader_cache; | ||
| 50 | ConfigurationShared::CheckState use_asynchronous_gpu_emulation; | ||
| 51 | |||
| 45 | std::vector<QString> vulkan_devices; | 52 | std::vector<QString> vulkan_devices; |
| 46 | u32 vulkan_device{}; | 53 | u32 vulkan_device{}; |
| 47 | }; | 54 | }; |
diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui index 62418fc14..62aa337e7 100644 --- a/src/yuzu/configuration/configure_graphics.ui +++ b/src/yuzu/configuration/configure_graphics.ui | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | <rect> | 6 | <rect> |
| 7 | <x>0</x> | 7 | <x>0</x> |
| 8 | <y>0</y> | 8 | <y>0</y> |
| 9 | <width>400</width> | 9 | <width>437</width> |
| 10 | <height>321</height> | 10 | <height>321</height> |
| 11 | </rect> | 11 | </rect> |
| 12 | </property> | 12 | </property> |
| @@ -23,43 +23,56 @@ | |||
| 23 | </property> | 23 | </property> |
| 24 | <layout class="QVBoxLayout" name="verticalLayout_3"> | 24 | <layout class="QVBoxLayout" name="verticalLayout_3"> |
| 25 | <item> | 25 | <item> |
| 26 | <layout class="QHBoxLayout" name="horizontalLayout_4"> | 26 | <widget class="QWidget" name="api_layout" native="true"> |
| 27 | <item> | 27 | <layout class="QGridLayout" name="gridLayout"> |
| 28 | <widget class="QLabel" name="label_2"> | 28 | <property name="leftMargin"> |
| 29 | <property name="text"> | 29 | <number>0</number> |
| 30 | <string>API:</string> | 30 | </property> |
| 31 | </property> | 31 | <property name="topMargin"> |
| 32 | </widget> | 32 | <number>0</number> |
| 33 | </item> | 33 | </property> |
| 34 | <item> | 34 | <property name="rightMargin"> |
| 35 | <widget class="QComboBox" name="api"> | 35 | <number>0</number> |
| 36 | <item> | 36 | </property> |
| 37 | <property name="bottomMargin"> | ||
| 38 | <number>0</number> | ||
| 39 | </property> | ||
| 40 | <property name="horizontalSpacing"> | ||
| 41 | <number>6</number> | ||
| 42 | </property> | ||
| 43 | <item row="0" column="0"> | ||
| 44 | <widget class="QLabel" name="api_label"> | ||
| 37 | <property name="text"> | 45 | <property name="text"> |
| 38 | <string notr="true">OpenGL</string> | 46 | <string>API:</string> |
| 39 | </property> | 47 | </property> |
| 40 | </item> | 48 | </widget> |
| 41 | <item> | 49 | </item> |
| 50 | <item row="0" column="1"> | ||
| 51 | <widget class="QComboBox" name="api"> | ||
| 52 | <item> | ||
| 53 | <property name="text"> | ||
| 54 | <string notr="true">OpenGL</string> | ||
| 55 | </property> | ||
| 56 | </item> | ||
| 57 | <item> | ||
| 58 | <property name="text"> | ||
| 59 | <string notr="true">Vulkan</string> | ||
| 60 | </property> | ||
| 61 | </item> | ||
| 62 | </widget> | ||
| 63 | </item> | ||
| 64 | <item row="1" column="0"> | ||
| 65 | <widget class="QLabel" name="device_label"> | ||
| 42 | <property name="text"> | 66 | <property name="text"> |
| 43 | <string notr="true">Vulkan</string> | 67 | <string>Device:</string> |
| 44 | </property> | 68 | </property> |
| 45 | </item> | 69 | </widget> |
| 46 | </widget> | 70 | </item> |
| 47 | </item> | 71 | <item row="1" column="1"> |
| 48 | </layout> | 72 | <widget class="QComboBox" name="device"/> |
| 49 | </item> | 73 | </item> |
| 50 | <item> | 74 | </layout> |
| 51 | <layout class="QHBoxLayout" name="horizontalLayout_5"> | 75 | </widget> |
| 52 | <item> | ||
| 53 | <widget class="QLabel" name="label_3"> | ||
| 54 | <property name="text"> | ||
| 55 | <string>Device:</string> | ||
| 56 | </property> | ||
| 57 | </widget> | ||
| 58 | </item> | ||
| 59 | <item> | ||
| 60 | <widget class="QComboBox" name="device"/> | ||
| 61 | </item> | ||
| 62 | </layout> | ||
| 63 | </item> | 76 | </item> |
| 64 | </layout> | 77 | </layout> |
| 65 | </widget> | 78 | </widget> |
| @@ -85,96 +98,133 @@ | |||
| 85 | </widget> | 98 | </widget> |
| 86 | </item> | 99 | </item> |
| 87 | <item> | 100 | <item> |
| 88 | <layout class="QHBoxLayout" name="horizontalLayout_6"> | 101 | <widget class="QWidget" name="aspect_ratio_layout" native="true"> |
| 89 | <item> | 102 | <layout class="QHBoxLayout" name="horizontalLayout_6"> |
| 90 | <widget class="QLabel" name="ar_label"> | 103 | <property name="leftMargin"> |
| 91 | <property name="text"> | 104 | <number>0</number> |
| 92 | <string>Aspect Ratio:</string> | 105 | </property> |
| 93 | </property> | 106 | <property name="topMargin"> |
| 94 | </widget> | 107 | <number>0</number> |
| 95 | </item> | 108 | </property> |
| 96 | <item> | 109 | <property name="rightMargin"> |
| 97 | <widget class="QComboBox" name="aspect_ratio_combobox"> | 110 | <number>0</number> |
| 98 | <item> | 111 | </property> |
| 99 | <property name="text"> | 112 | <property name="bottomMargin"> |
| 100 | <string>Default (16:9)</string> | 113 | <number>0</number> |
| 101 | </property> | 114 | </property> |
| 102 | </item> | 115 | <item> |
| 103 | <item> | 116 | <widget class="QLabel" name="ar_label"> |
| 104 | <property name="text"> | ||
| 105 | <string>Force 4:3</string> | ||
| 106 | </property> | ||
| 107 | </item> | ||
| 108 | <item> | ||
| 109 | <property name="text"> | ||
| 110 | <string>Force 21:9</string> | ||
| 111 | </property> | ||
| 112 | </item> | ||
| 113 | <item> | ||
| 114 | <property name="text"> | 117 | <property name="text"> |
| 115 | <string>Stretch to Window</string> | 118 | <string>Aspect Ratio:</string> |
| 116 | </property> | 119 | </property> |
| 117 | </item> | 120 | </widget> |
| 118 | </widget> | 121 | </item> |
| 119 | </item> | 122 | <item> |
| 120 | </layout> | 123 | <widget class="QComboBox" name="aspect_ratio_combobox"> |
| 124 | <item> | ||
| 125 | <property name="text"> | ||
| 126 | <string>Default (16:9)</string> | ||
| 127 | </property> | ||
| 128 | </item> | ||
| 129 | <item> | ||
| 130 | <property name="text"> | ||
| 131 | <string>Force 4:3</string> | ||
| 132 | </property> | ||
| 133 | </item> | ||
| 134 | <item> | ||
| 135 | <property name="text"> | ||
| 136 | <string>Force 21:9</string> | ||
| 137 | </property> | ||
| 138 | </item> | ||
| 139 | <item> | ||
| 140 | <property name="text"> | ||
| 141 | <string>Stretch to Window</string> | ||
| 142 | </property> | ||
| 143 | </item> | ||
| 144 | </widget> | ||
| 145 | </item> | ||
| 146 | </layout> | ||
| 147 | </widget> | ||
| 121 | </item> | 148 | </item> |
| 122 | <item> | 149 | <item> |
| 123 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | 150 | <widget class="QWidget" name="bg_layout" native="true"> |
| 124 | <item> | 151 | <property name="sizePolicy"> |
| 125 | <widget class="QComboBox" name="bg_combobox"> | 152 | <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> |
| 126 | <property name="currentText"> | 153 | <horstretch>0</horstretch> |
| 127 | <string>Use global background color</string> | 154 | <verstretch>0</verstretch> |
| 128 | </property> | 155 | </sizepolicy> |
| 129 | <property name="currentIndex"> | 156 | </property> |
| 130 | <number>0</number> | 157 | <layout class="QHBoxLayout" name="horizontalLayout_3"> |
| 131 | </property> | 158 | <property name="spacing"> |
| 132 | <property name="maxVisibleItems"> | 159 | <number>6</number> |
| 133 | <number>10</number> | 160 | </property> |
| 134 | </property> | 161 | <property name="leftMargin"> |
| 135 | <item> | 162 | <number>0</number> |
| 136 | <property name="text"> | 163 | </property> |
| 164 | <property name="topMargin"> | ||
| 165 | <number>0</number> | ||
| 166 | </property> | ||
| 167 | <property name="rightMargin"> | ||
| 168 | <number>0</number> | ||
| 169 | </property> | ||
| 170 | <property name="bottomMargin"> | ||
| 171 | <number>0</number> | ||
| 172 | </property> | ||
| 173 | <item> | ||
| 174 | <widget class="QComboBox" name="bg_combobox"> | ||
| 175 | <property name="currentText"> | ||
| 137 | <string>Use global background color</string> | 176 | <string>Use global background color</string> |
| 138 | </property> | 177 | </property> |
| 139 | </item> | 178 | <property name="currentIndex"> |
| 140 | <item> | 179 | <number>0</number> |
| 180 | </property> | ||
| 181 | <property name="maxVisibleItems"> | ||
| 182 | <number>10</number> | ||
| 183 | </property> | ||
| 184 | <item> | ||
| 185 | <property name="text"> | ||
| 186 | <string>Use global background color</string> | ||
| 187 | </property> | ||
| 188 | </item> | ||
| 189 | <item> | ||
| 190 | <property name="text"> | ||
| 191 | <string>Set background color:</string> | ||
| 192 | </property> | ||
| 193 | </item> | ||
| 194 | </widget> | ||
| 195 | </item> | ||
| 196 | <item> | ||
| 197 | <widget class="QLabel" name="bg_label"> | ||
| 141 | <property name="text"> | 198 | <property name="text"> |
| 142 | <string>Set background color:</string> | 199 | <string>Background Color:</string> |
| 143 | </property> | 200 | </property> |
| 144 | </item> | 201 | </widget> |
| 145 | </widget> | 202 | </item> |
| 146 | </item> | 203 | <item> |
| 147 | <item> | 204 | <spacer name="horizontalSpacer"> |
| 148 | <widget class="QLabel" name="bg_label"> | 205 | <property name="orientation"> |
| 149 | <property name="text"> | 206 | <enum>Qt::Horizontal</enum> |
| 150 | <string>Background Color:</string> | 207 | </property> |
| 151 | </property> | 208 | <property name="sizeHint" stdset="0"> |
| 152 | </widget> | 209 | <size> |
| 153 | </item> | 210 | <width>40</width> |
| 154 | <item> | 211 | <height>20</height> |
| 155 | <spacer name="horizontalSpacer"> | 212 | </size> |
| 156 | <property name="orientation"> | 213 | </property> |
| 157 | <enum>Qt::Horizontal</enum> | 214 | </spacer> |
| 158 | </property> | 215 | </item> |
| 159 | <property name="sizeHint" stdset="0"> | 216 | <item> |
| 160 | <size> | 217 | <widget class="QPushButton" name="bg_button"> |
| 161 | <width>40</width> | 218 | <property name="maximumSize"> |
| 162 | <height>20</height> | 219 | <size> |
| 163 | </size> | 220 | <width>40</width> |
| 164 | </property> | 221 | <height>16777215</height> |
| 165 | </spacer> | 222 | </size> |
| 166 | </item> | 223 | </property> |
| 167 | <item> | 224 | </widget> |
| 168 | <widget class="QPushButton" name="bg_button"> | 225 | </item> |
| 169 | <property name="maximumSize"> | 226 | </layout> |
| 170 | <size> | 227 | </widget> |
| 171 | <width>40</width> | ||
| 172 | <height>16777215</height> | ||
| 173 | </size> | ||
| 174 | </property> | ||
| 175 | </widget> | ||
| 176 | </item> | ||
| 177 | </layout> | ||
| 178 | </item> | 228 | </item> |
| 179 | </layout> | 229 | </layout> |
| 180 | </widget> | 230 | </widget> |
diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp index ce30188cd..c5d1a778c 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.cpp +++ b/src/yuzu/configuration/configure_graphics_advanced.cpp | |||
| @@ -25,35 +25,26 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { | |||
| 25 | ui->use_vsync->setEnabled(runtime_lock); | 25 | ui->use_vsync->setEnabled(runtime_lock); |
| 26 | ui->use_assembly_shaders->setEnabled(runtime_lock); | 26 | ui->use_assembly_shaders->setEnabled(runtime_lock); |
| 27 | ui->use_asynchronous_shaders->setEnabled(runtime_lock); | 27 | ui->use_asynchronous_shaders->setEnabled(runtime_lock); |
| 28 | ui->force_30fps_mode->setEnabled(runtime_lock); | ||
| 29 | ui->anisotropic_filtering_combobox->setEnabled(runtime_lock); | 28 | ui->anisotropic_filtering_combobox->setEnabled(runtime_lock); |
| 30 | 29 | ||
| 30 | ui->use_vsync->setChecked(Settings::values.use_vsync.GetValue()); | ||
| 31 | ui->use_assembly_shaders->setChecked(Settings::values.use_assembly_shaders.GetValue()); | ||
| 32 | ui->use_asynchronous_shaders->setChecked(Settings::values.use_asynchronous_shaders.GetValue()); | ||
| 33 | ui->use_fast_gpu_time->setChecked(Settings::values.use_fast_gpu_time.GetValue()); | ||
| 34 | |||
| 31 | if (Settings::configuring_global) { | 35 | if (Settings::configuring_global) { |
| 32 | ui->gpu_accuracy->setCurrentIndex( | 36 | ui->gpu_accuracy->setCurrentIndex( |
| 33 | static_cast<int>(Settings::values.gpu_accuracy.GetValue())); | 37 | static_cast<int>(Settings::values.gpu_accuracy.GetValue())); |
| 34 | ui->use_vsync->setChecked(Settings::values.use_vsync.GetValue()); | ||
| 35 | ui->use_assembly_shaders->setChecked(Settings::values.use_assembly_shaders.GetValue()); | ||
| 36 | ui->use_asynchronous_shaders->setChecked( | ||
| 37 | Settings::values.use_asynchronous_shaders.GetValue()); | ||
| 38 | ui->use_fast_gpu_time->setChecked(Settings::values.use_fast_gpu_time.GetValue()); | ||
| 39 | ui->force_30fps_mode->setChecked(Settings::values.force_30fps_mode.GetValue()); | ||
| 40 | ui->anisotropic_filtering_combobox->setCurrentIndex( | 38 | ui->anisotropic_filtering_combobox->setCurrentIndex( |
| 41 | Settings::values.max_anisotropy.GetValue()); | 39 | Settings::values.max_anisotropy.GetValue()); |
| 42 | } else { | 40 | } else { |
| 43 | ConfigurationShared::SetPerGameSetting(ui->gpu_accuracy, &Settings::values.gpu_accuracy); | 41 | ConfigurationShared::SetPerGameSetting(ui->gpu_accuracy, &Settings::values.gpu_accuracy); |
| 44 | ConfigurationShared::SetPerGameSetting(ui->use_vsync, &Settings::values.use_vsync); | ||
| 45 | ConfigurationShared::SetPerGameSetting(ui->use_assembly_shaders, | ||
| 46 | &Settings::values.use_assembly_shaders); | ||
| 47 | ConfigurationShared::SetPerGameSetting(ui->use_asynchronous_shaders, | ||
| 48 | &Settings::values.use_asynchronous_shaders); | ||
| 49 | ConfigurationShared::SetPerGameSetting(ui->use_asynchronous_shaders, | ||
| 50 | &Settings::values.use_asynchronous_shaders); | ||
| 51 | ConfigurationShared::SetPerGameSetting(ui->use_fast_gpu_time, | ||
| 52 | &Settings::values.use_fast_gpu_time); | ||
| 53 | ConfigurationShared::SetPerGameSetting(ui->force_30fps_mode, | ||
| 54 | &Settings::values.force_30fps_mode); | ||
| 55 | ConfigurationShared::SetPerGameSetting(ui->anisotropic_filtering_combobox, | 42 | ConfigurationShared::SetPerGameSetting(ui->anisotropic_filtering_combobox, |
| 56 | &Settings::values.max_anisotropy); | 43 | &Settings::values.max_anisotropy); |
| 44 | ConfigurationShared::SetHighlight(ui->label_gpu_accuracy, "label_gpu_accuracy", | ||
| 45 | !Settings::values.gpu_accuracy.UsingGlobal()); | ||
| 46 | ConfigurationShared::SetHighlight(ui->af_label, "af_label", | ||
| 47 | !Settings::values.max_anisotropy.UsingGlobal()); | ||
| 57 | } | 48 | } |
| 58 | } | 49 | } |
| 59 | 50 | ||
| @@ -85,9 +76,6 @@ void ConfigureGraphicsAdvanced::ApplyConfiguration() { | |||
| 85 | if (Settings::values.use_fast_gpu_time.UsingGlobal()) { | 76 | if (Settings::values.use_fast_gpu_time.UsingGlobal()) { |
| 86 | Settings::values.use_fast_gpu_time.SetValue(ui->use_fast_gpu_time->isChecked()); | 77 | Settings::values.use_fast_gpu_time.SetValue(ui->use_fast_gpu_time->isChecked()); |
| 87 | } | 78 | } |
| 88 | if (Settings::values.force_30fps_mode.UsingGlobal()) { | ||
| 89 | Settings::values.force_30fps_mode.SetValue(ui->force_30fps_mode->isChecked()); | ||
| 90 | } | ||
| 91 | if (Settings::values.max_anisotropy.UsingGlobal()) { | 79 | if (Settings::values.max_anisotropy.UsingGlobal()) { |
| 92 | Settings::values.max_anisotropy.SetValue( | 80 | Settings::values.max_anisotropy.SetValue( |
| 93 | ui->anisotropic_filtering_combobox->currentIndex()); | 81 | ui->anisotropic_filtering_combobox->currentIndex()); |
| @@ -95,17 +83,15 @@ void ConfigureGraphicsAdvanced::ApplyConfiguration() { | |||
| 95 | } else { | 83 | } else { |
| 96 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.max_anisotropy, | 84 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.max_anisotropy, |
| 97 | ui->anisotropic_filtering_combobox); | 85 | ui->anisotropic_filtering_combobox); |
| 98 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_vsync, ui->use_vsync); | 86 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_vsync, ui->use_vsync, |
| 87 | use_vsync); | ||
| 99 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_assembly_shaders, | 88 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_assembly_shaders, |
| 100 | ui->use_assembly_shaders); | 89 | ui->use_assembly_shaders, use_assembly_shaders); |
| 101 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_shaders, | ||
| 102 | ui->use_asynchronous_shaders); | ||
| 103 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_shaders, | 90 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_shaders, |
| 104 | ui->use_asynchronous_shaders); | 91 | ui->use_asynchronous_shaders, |
| 92 | use_asynchronous_shaders); | ||
| 105 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_fast_gpu_time, | 93 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_fast_gpu_time, |
| 106 | ui->use_fast_gpu_time); | 94 | ui->use_fast_gpu_time, use_fast_gpu_time); |
| 107 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.force_30fps_mode, | ||
| 108 | ui->force_30fps_mode); | ||
| 109 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.max_anisotropy, | 95 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.max_anisotropy, |
| 110 | ui->anisotropic_filtering_combobox); | 96 | ui->anisotropic_filtering_combobox); |
| 111 | 97 | ||
| @@ -139,18 +125,26 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() { | |||
| 139 | ui->use_asynchronous_shaders->setEnabled( | 125 | ui->use_asynchronous_shaders->setEnabled( |
| 140 | Settings::values.use_asynchronous_shaders.UsingGlobal()); | 126 | Settings::values.use_asynchronous_shaders.UsingGlobal()); |
| 141 | ui->use_fast_gpu_time->setEnabled(Settings::values.use_fast_gpu_time.UsingGlobal()); | 127 | ui->use_fast_gpu_time->setEnabled(Settings::values.use_fast_gpu_time.UsingGlobal()); |
| 142 | ui->force_30fps_mode->setEnabled(Settings::values.force_30fps_mode.UsingGlobal()); | ||
| 143 | ui->anisotropic_filtering_combobox->setEnabled( | 128 | ui->anisotropic_filtering_combobox->setEnabled( |
| 144 | Settings::values.max_anisotropy.UsingGlobal()); | 129 | Settings::values.max_anisotropy.UsingGlobal()); |
| 145 | 130 | ||
| 146 | return; | 131 | return; |
| 147 | } | 132 | } |
| 148 | 133 | ||
| 149 | ConfigurationShared::InsertGlobalItem(ui->gpu_accuracy); | 134 | ConfigurationShared::SetColoredTristate(ui->use_vsync, "use_vsync", Settings::values.use_vsync, |
| 150 | ui->use_vsync->setTristate(true); | 135 | use_vsync); |
| 151 | ui->use_assembly_shaders->setTristate(true); | 136 | ConfigurationShared::SetColoredTristate(ui->use_assembly_shaders, "use_assembly_shaders", |
| 152 | ui->use_asynchronous_shaders->setTristate(true); | 137 | Settings::values.use_assembly_shaders, |
| 153 | ui->use_fast_gpu_time->setTristate(true); | 138 | use_assembly_shaders); |
| 154 | ui->force_30fps_mode->setTristate(true); | 139 | ConfigurationShared::SetColoredTristate( |
| 155 | ConfigurationShared::InsertGlobalItem(ui->anisotropic_filtering_combobox); | 140 | ui->use_asynchronous_shaders, "use_asynchronous_shaders", |
| 141 | Settings::values.use_asynchronous_shaders, use_asynchronous_shaders); | ||
| 142 | ConfigurationShared::SetColoredTristate(ui->use_fast_gpu_time, "use_fast_gpu_time", | ||
| 143 | Settings::values.use_fast_gpu_time, use_fast_gpu_time); | ||
| 144 | ConfigurationShared::SetColoredComboBox( | ||
| 145 | ui->gpu_accuracy, ui->label_gpu_accuracy, "label_gpu_accuracy", | ||
| 146 | static_cast<int>(Settings::values.gpu_accuracy.GetValue(true))); | ||
| 147 | ConfigurationShared::SetColoredComboBox( | ||
| 148 | ui->anisotropic_filtering_combobox, ui->af_label, "af_label", | ||
| 149 | static_cast<int>(Settings::values.max_anisotropy.GetValue(true))); | ||
| 156 | } | 150 | } |
diff --git a/src/yuzu/configuration/configure_graphics_advanced.h b/src/yuzu/configuration/configure_graphics_advanced.h index c043588ff..e61b571c7 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.h +++ b/src/yuzu/configuration/configure_graphics_advanced.h | |||
| @@ -7,6 +7,10 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <QWidget> | 8 | #include <QWidget> |
| 9 | 9 | ||
| 10 | namespace ConfigurationShared { | ||
| 11 | enum class CheckState; | ||
| 12 | } | ||
| 13 | |||
| 10 | namespace Ui { | 14 | namespace Ui { |
| 11 | class ConfigureGraphicsAdvanced; | 15 | class ConfigureGraphicsAdvanced; |
| 12 | } | 16 | } |
| @@ -29,4 +33,9 @@ private: | |||
| 29 | void SetupPerGameUI(); | 33 | void SetupPerGameUI(); |
| 30 | 34 | ||
| 31 | std::unique_ptr<Ui::ConfigureGraphicsAdvanced> ui; | 35 | std::unique_ptr<Ui::ConfigureGraphicsAdvanced> ui; |
| 36 | |||
| 37 | ConfigurationShared::CheckState use_vsync; | ||
| 38 | ConfigurationShared::CheckState use_assembly_shaders; | ||
| 39 | ConfigurationShared::CheckState use_asynchronous_shaders; | ||
| 40 | ConfigurationShared::CheckState use_fast_gpu_time; | ||
| 32 | }; | 41 | }; |
diff --git a/src/yuzu/configuration/configure_graphics_advanced.ui b/src/yuzu/configuration/configure_graphics_advanced.ui index 71e7dfe5e..a793c803d 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.ui +++ b/src/yuzu/configuration/configure_graphics_advanced.ui | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | <rect> | 6 | <rect> |
| 7 | <x>0</x> | 7 | <x>0</x> |
| 8 | <y>0</y> | 8 | <y>0</y> |
| 9 | <width>400</width> | 9 | <width>404</width> |
| 10 | <height>321</height> | 10 | <height>321</height> |
| 11 | </rect> | 11 | </rect> |
| 12 | </property> | 12 | </property> |
| @@ -23,34 +23,48 @@ | |||
| 23 | </property> | 23 | </property> |
| 24 | <layout class="QVBoxLayout" name="verticalLayout_3"> | 24 | <layout class="QVBoxLayout" name="verticalLayout_3"> |
| 25 | <item> | 25 | <item> |
| 26 | <layout class="QHBoxLayout" name="horizontalLayout_2"> | 26 | <widget class="QWidget" name="gpu_accuracy_layout" native="true"> |
| 27 | <item> | 27 | <layout class="QHBoxLayout" name="horizontalLayout_2"> |
| 28 | <widget class="QLabel" name="label_gpu_accuracy"> | 28 | <property name="leftMargin"> |
| 29 | <property name="text"> | 29 | <number>0</number> |
| 30 | <string>Accuracy Level:</string> | 30 | </property> |
| 31 | </property> | 31 | <property name="topMargin"> |
| 32 | </widget> | 32 | <number>0</number> |
| 33 | </item> | 33 | </property> |
| 34 | <item> | 34 | <property name="rightMargin"> |
| 35 | <widget class="QComboBox" name="gpu_accuracy"> | 35 | <number>0</number> |
| 36 | <item> | 36 | </property> |
| 37 | <property name="bottomMargin"> | ||
| 38 | <number>0</number> | ||
| 39 | </property> | ||
| 40 | <item> | ||
| 41 | <widget class="QLabel" name="label_gpu_accuracy"> | ||
| 37 | <property name="text"> | 42 | <property name="text"> |
| 38 | <string notr="true">Normal</string> | 43 | <string>Accuracy Level:</string> |
| 39 | </property> | 44 | </property> |
| 40 | </item> | 45 | </widget> |
| 41 | <item> | 46 | </item> |
| 42 | <property name="text"> | 47 | <item> |
| 43 | <string notr="true">High</string> | 48 | <widget class="QComboBox" name="gpu_accuracy"> |
| 44 | </property> | 49 | <item> |
| 45 | </item> | 50 | <property name="text"> |
| 46 | <item> | 51 | <string notr="true">Normal</string> |
| 47 | <property name="text"> | 52 | </property> |
| 48 | <string notr="true">Extreme(very slow)</string> | 53 | </item> |
| 49 | </property> | 54 | <item> |
| 50 | </item> | 55 | <property name="text"> |
| 51 | </widget> | 56 | <string notr="true">High</string> |
| 52 | </item> | 57 | </property> |
| 53 | </layout> | 58 | </item> |
| 59 | <item> | ||
| 60 | <property name="text"> | ||
| 61 | <string notr="true">Extreme(very slow)</string> | ||
| 62 | </property> | ||
| 63 | </item> | ||
| 64 | </widget> | ||
| 65 | </item> | ||
| 66 | </layout> | ||
| 67 | </widget> | ||
| 54 | </item> | 68 | </item> |
| 55 | <item> | 69 | <item> |
| 56 | <widget class="QCheckBox" name="use_vsync"> | 70 | <widget class="QCheckBox" name="use_vsync"> |
| @@ -83,13 +97,6 @@ | |||
| 83 | </widget> | 97 | </widget> |
| 84 | </item> | 98 | </item> |
| 85 | <item> | 99 | <item> |
| 86 | <widget class="QCheckBox" name="force_30fps_mode"> | ||
| 87 | <property name="text"> | ||
| 88 | <string>Force 30 FPS mode</string> | ||
| 89 | </property> | ||
| 90 | </widget> | ||
| 91 | </item> | ||
| 92 | <item> | ||
| 93 | <widget class="QCheckBox" name="use_fast_gpu_time"> | 100 | <widget class="QCheckBox" name="use_fast_gpu_time"> |
| 94 | <property name="text"> | 101 | <property name="text"> |
| 95 | <string>Use Fast GPU Time</string> | 102 | <string>Use Fast GPU Time</string> |
| @@ -97,44 +104,58 @@ | |||
| 97 | </widget> | 104 | </widget> |
| 98 | </item> | 105 | </item> |
| 99 | <item> | 106 | <item> |
| 100 | <layout class="QHBoxLayout" name="horizontalLayout_1"> | 107 | <widget class="QWidget" name="af_layout" native="true"> |
| 101 | <item> | 108 | <layout class="QHBoxLayout" name="horizontalLayout_1"> |
| 102 | <widget class="QLabel" name="af_label"> | 109 | <property name="leftMargin"> |
| 103 | <property name="text"> | 110 | <number>0</number> |
| 104 | <string>Anisotropic Filtering:</string> | 111 | </property> |
| 105 | </property> | 112 | <property name="topMargin"> |
| 106 | </widget> | 113 | <number>0</number> |
| 107 | </item> | 114 | </property> |
| 108 | <item> | 115 | <property name="rightMargin"> |
| 109 | <widget class="QComboBox" name="anisotropic_filtering_combobox"> | 116 | <number>0</number> |
| 110 | <item> | 117 | </property> |
| 118 | <property name="bottomMargin"> | ||
| 119 | <number>0</number> | ||
| 120 | </property> | ||
| 121 | <item> | ||
| 122 | <widget class="QLabel" name="af_label"> | ||
| 111 | <property name="text"> | 123 | <property name="text"> |
| 112 | <string>Default</string> | 124 | <string>Anisotropic Filtering:</string> |
| 113 | </property> | 125 | </property> |
| 114 | </item> | 126 | </widget> |
| 115 | <item> | 127 | </item> |
| 116 | <property name="text"> | 128 | <item> |
| 117 | <string>2x</string> | 129 | <widget class="QComboBox" name="anisotropic_filtering_combobox"> |
| 118 | </property> | 130 | <item> |
| 119 | </item> | 131 | <property name="text"> |
| 120 | <item> | 132 | <string>Default</string> |
| 121 | <property name="text"> | 133 | </property> |
| 122 | <string>4x</string> | 134 | </item> |
| 123 | </property> | 135 | <item> |
| 124 | </item> | 136 | <property name="text"> |
| 125 | <item> | 137 | <string>2x</string> |
| 126 | <property name="text"> | 138 | </property> |
| 127 | <string>8x</string> | 139 | </item> |
| 128 | </property> | 140 | <item> |
| 129 | </item> | 141 | <property name="text"> |
| 130 | <item> | 142 | <string>4x</string> |
| 131 | <property name="text"> | 143 | </property> |
| 132 | <string>16x</string> | 144 | </item> |
| 133 | </property> | 145 | <item> |
| 134 | </item> | 146 | <property name="text"> |
| 135 | </widget> | 147 | <string>8x</string> |
| 136 | </item> | 148 | </property> |
| 137 | </layout> | 149 | </item> |
| 150 | <item> | ||
| 151 | <property name="text"> | ||
| 152 | <string>16x</string> | ||
| 153 | </property> | ||
| 154 | </item> | ||
| 155 | </widget> | ||
| 156 | </item> | ||
| 157 | </layout> | ||
| 158 | </widget> | ||
| 138 | </item> | 159 | </item> |
| 139 | </layout> | 160 | </layout> |
| 140 | </widget> | 161 | </widget> |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 00433926d..b1850bc95 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -280,9 +280,9 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 280 | } | 280 | } |
| 281 | 281 | ||
| 282 | button->setContextMenuPolicy(Qt::CustomContextMenu); | 282 | button->setContextMenuPolicy(Qt::CustomContextMenu); |
| 283 | connect(button, &QPushButton::clicked, [=] { | 283 | connect(button, &QPushButton::clicked, [=, this] { |
| 284 | HandleClick(button_map[button_id], | 284 | HandleClick(button_map[button_id], |
| 285 | [=](Common::ParamPackage params) { | 285 | [=, this](Common::ParamPackage params) { |
| 286 | // Workaround for ZL & ZR for analog triggers like on XBOX controllors. | 286 | // Workaround for ZL & ZR for analog triggers like on XBOX controllors. |
| 287 | // Analog triggers (from controllers like the XBOX controller) would not | 287 | // Analog triggers (from controllers like the XBOX controller) would not |
| 288 | // work due to a different range of their signals (from 0 to 255 on | 288 | // work due to a different range of their signals (from 0 to 255 on |
| @@ -300,19 +300,20 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 300 | }, | 300 | }, |
| 301 | InputCommon::Polling::DeviceType::Button); | 301 | InputCommon::Polling::DeviceType::Button); |
| 302 | }); | 302 | }); |
| 303 | connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { | 303 | connect(button, &QPushButton::customContextMenuRequested, |
| 304 | QMenu context_menu; | 304 | [=, this](const QPoint& menu_location) { |
| 305 | context_menu.addAction(tr("Clear"), [&] { | 305 | QMenu context_menu; |
| 306 | buttons_param[button_id].Clear(); | 306 | context_menu.addAction(tr("Clear"), [&] { |
| 307 | button_map[button_id]->setText(tr("[not set]")); | 307 | buttons_param[button_id].Clear(); |
| 308 | }); | 308 | button_map[button_id]->setText(tr("[not set]")); |
| 309 | context_menu.addAction(tr("Restore Default"), [&] { | 309 | }); |
| 310 | buttons_param[button_id] = Common::ParamPackage{ | 310 | context_menu.addAction(tr("Restore Default"), [&] { |
| 311 | InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; | 311 | buttons_param[button_id] = Common::ParamPackage{ |
| 312 | button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); | 312 | InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; |
| 313 | }); | 313 | button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); |
| 314 | context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); | 314 | }); |
| 315 | }); | 315 | context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); |
| 316 | }); | ||
| 316 | } | 317 | } |
| 317 | 318 | ||
| 318 | for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { | 319 | for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { |
| @@ -323,16 +324,16 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 323 | } | 324 | } |
| 324 | 325 | ||
| 325 | analog_button->setContextMenuPolicy(Qt::CustomContextMenu); | 326 | analog_button->setContextMenuPolicy(Qt::CustomContextMenu); |
| 326 | connect(analog_button, &QPushButton::clicked, [=]() { | 327 | connect(analog_button, &QPushButton::clicked, [=, this] { |
| 327 | HandleClick(analog_map_buttons[analog_id][sub_button_id], | 328 | HandleClick(analog_map_buttons[analog_id][sub_button_id], |
| 328 | [=](const Common::ParamPackage& params) { | 329 | [=, this](const Common::ParamPackage& params) { |
| 329 | SetAnalogButton(params, analogs_param[analog_id], | 330 | SetAnalogButton(params, analogs_param[analog_id], |
| 330 | analog_sub_buttons[sub_button_id]); | 331 | analog_sub_buttons[sub_button_id]); |
| 331 | }, | 332 | }, |
| 332 | InputCommon::Polling::DeviceType::Button); | 333 | InputCommon::Polling::DeviceType::Button); |
| 333 | }); | 334 | }); |
| 334 | connect(analog_button, &QPushButton::customContextMenuRequested, | 335 | connect(analog_button, &QPushButton::customContextMenuRequested, |
| 335 | [=](const QPoint& menu_location) { | 336 | [=, this](const QPoint& menu_location) { |
| 336 | QMenu context_menu; | 337 | QMenu context_menu; |
| 337 | context_menu.addAction(tr("Clear"), [&] { | 338 | context_menu.addAction(tr("Clear"), [&] { |
| 338 | analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); | 339 | analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]); |
| @@ -350,32 +351,35 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 350 | menu_location)); | 351 | menu_location)); |
| 351 | }); | 352 | }); |
| 352 | } | 353 | } |
| 353 | connect(analog_map_stick[analog_id], &QPushButton::clicked, [=] { | 354 | connect(analog_map_stick[analog_id], &QPushButton::clicked, [=, this] { |
| 354 | if (QMessageBox::information( | 355 | if (QMessageBox::information( |
| 355 | this, tr("Information"), | 356 | this, tr("Information"), |
| 356 | tr("After pressing OK, first move your joystick horizontally, " | 357 | tr("After pressing OK, first move your joystick horizontally, " |
| 357 | "and then vertically."), | 358 | "and then vertically."), |
| 358 | QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { | 359 | QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { |
| 359 | HandleClick( | 360 | HandleClick(analog_map_stick[analog_id], |
| 360 | analog_map_stick[analog_id], | 361 | [=, this](const Common::ParamPackage& params) { |
| 361 | [=](const Common::ParamPackage& params) { analogs_param[analog_id] = params; }, | 362 | analogs_param[analog_id] = params; |
| 362 | InputCommon::Polling::DeviceType::Analog); | 363 | }, |
| 364 | InputCommon::Polling::DeviceType::Analog); | ||
| 363 | } | 365 | } |
| 364 | }); | 366 | }); |
| 365 | 367 | ||
| 366 | connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, [=] { | 368 | connect(analog_map_deadzone_and_modifier_slider[analog_id], &QSlider::valueChanged, |
| 367 | const float slider_value = analog_map_deadzone_and_modifier_slider[analog_id]->value(); | 369 | [=, this] { |
| 368 | if (analogs_param[analog_id].Get("engine", "") == "sdl" || | 370 | const float slider_value = |
| 369 | analogs_param[analog_id].Get("engine", "") == "gcpad") { | 371 | analog_map_deadzone_and_modifier_slider[analog_id]->value(); |
| 370 | analog_map_deadzone_and_modifier_slider_label[analog_id]->setText( | 372 | if (analogs_param[analog_id].Get("engine", "") == "sdl" || |
| 371 | tr("Deadzone: %1%").arg(slider_value)); | 373 | analogs_param[analog_id].Get("engine", "") == "gcpad") { |
| 372 | analogs_param[analog_id].Set("deadzone", slider_value / 100.0f); | 374 | analog_map_deadzone_and_modifier_slider_label[analog_id]->setText( |
| 373 | } else { | 375 | tr("Deadzone: %1%").arg(slider_value)); |
| 374 | analog_map_deadzone_and_modifier_slider_label[analog_id]->setText( | 376 | analogs_param[analog_id].Set("deadzone", slider_value / 100.0f); |
| 375 | tr("Modifier Scale: %1%").arg(slider_value)); | 377 | } else { |
| 376 | analogs_param[analog_id].Set("modifier_scale", slider_value / 100.0f); | 378 | analog_map_deadzone_and_modifier_slider_label[analog_id]->setText( |
| 377 | } | 379 | tr("Modifier Scale: %1%").arg(slider_value)); |
| 378 | }); | 380 | analogs_param[analog_id].Set("modifier_scale", slider_value / 100.0f); |
| 381 | } | ||
| 382 | }); | ||
| 379 | } | 383 | } |
| 380 | 384 | ||
| 381 | connect(ui->buttonClearAll, &QPushButton::clicked, [this] { ClearAll(); }); | 385 | connect(ui->buttonClearAll, &QPushButton::clicked, [this] { ClearAll(); }); |
diff --git a/src/yuzu/configuration/configure_mouse_advanced.cpp b/src/yuzu/configuration/configure_mouse_advanced.cpp index e0647ea5b..ea2549363 100644 --- a/src/yuzu/configuration/configure_mouse_advanced.cpp +++ b/src/yuzu/configuration/configure_mouse_advanced.cpp | |||
| @@ -83,25 +83,28 @@ ConfigureMouseAdvanced::ConfigureMouseAdvanced(QWidget* parent) | |||
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | button->setContextMenuPolicy(Qt::CustomContextMenu); | 85 | button->setContextMenuPolicy(Qt::CustomContextMenu); |
| 86 | connect(button, &QPushButton::clicked, [=] { | 86 | connect(button, &QPushButton::clicked, [=, this] { |
| 87 | HandleClick( | 87 | HandleClick(button_map[button_id], |
| 88 | button_map[button_id], | 88 | [=, this](const Common::ParamPackage& params) { |
| 89 | [=](const Common::ParamPackage& params) { buttons_param[button_id] = params; }, | 89 | buttons_param[button_id] = params; |
| 90 | InputCommon::Polling::DeviceType::Button); | 90 | }, |
| 91 | }); | 91 | InputCommon::Polling::DeviceType::Button); |
| 92 | connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { | ||
| 93 | QMenu context_menu; | ||
| 94 | context_menu.addAction(tr("Clear"), [&] { | ||
| 95 | buttons_param[button_id].Clear(); | ||
| 96 | button_map[button_id]->setText(tr("[not set]")); | ||
| 97 | }); | ||
| 98 | context_menu.addAction(tr("Restore Default"), [&] { | ||
| 99 | buttons_param[button_id] = Common::ParamPackage{ | ||
| 100 | InputCommon::GenerateKeyboardParam(Config::default_mouse_buttons[button_id])}; | ||
| 101 | button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); | ||
| 102 | }); | ||
| 103 | context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); | ||
| 104 | }); | 92 | }); |
| 93 | connect(button, &QPushButton::customContextMenuRequested, | ||
| 94 | [=, this](const QPoint& menu_location) { | ||
| 95 | QMenu context_menu; | ||
| 96 | context_menu.addAction(tr("Clear"), [&] { | ||
| 97 | buttons_param[button_id].Clear(); | ||
| 98 | button_map[button_id]->setText(tr("[not set]")); | ||
| 99 | }); | ||
| 100 | context_menu.addAction(tr("Restore Default"), [&] { | ||
| 101 | buttons_param[button_id] = | ||
| 102 | Common::ParamPackage{InputCommon::GenerateKeyboardParam( | ||
| 103 | Config::default_mouse_buttons[button_id])}; | ||
| 104 | button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); | ||
| 105 | }); | ||
| 106 | context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); | ||
| 107 | }); | ||
| 105 | } | 108 | } |
| 106 | 109 | ||
| 107 | connect(ui->buttonClearAll, &QPushButton::clicked, [this] { ClearAll(); }); | 110 | connect(ui->buttonClearAll, &QPushButton::clicked, [this] { ClearAll(); }); |
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 68e02738b..0c4daf147 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp | |||
| @@ -67,21 +67,21 @@ void ConfigureSystem::SetConfiguration() { | |||
| 67 | const auto rtc_time = Settings::values.custom_rtc.GetValue().value_or( | 67 | const auto rtc_time = Settings::values.custom_rtc.GetValue().value_or( |
| 68 | std::chrono::seconds(QDateTime::currentSecsSinceEpoch())); | 68 | std::chrono::seconds(QDateTime::currentSecsSinceEpoch())); |
| 69 | 69 | ||
| 70 | ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.GetValue().has_value()); | ||
| 71 | ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.GetValue().has_value() && | ||
| 72 | Settings::values.rng_seed.UsingGlobal()); | ||
| 73 | ui->rng_seed_edit->setText(rng_seed); | ||
| 74 | |||
| 75 | ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.GetValue().has_value()); | ||
| 76 | ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.GetValue().has_value() && | ||
| 77 | Settings::values.rng_seed.UsingGlobal()); | ||
| 78 | ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time.count())); | ||
| 79 | |||
| 70 | if (Settings::configuring_global) { | 80 | if (Settings::configuring_global) { |
| 71 | ui->combo_language->setCurrentIndex(Settings::values.language_index.GetValue()); | 81 | ui->combo_language->setCurrentIndex(Settings::values.language_index.GetValue()); |
| 72 | ui->combo_region->setCurrentIndex(Settings::values.region_index.GetValue()); | 82 | ui->combo_region->setCurrentIndex(Settings::values.region_index.GetValue()); |
| 73 | ui->combo_time_zone->setCurrentIndex(Settings::values.time_zone_index.GetValue()); | 83 | ui->combo_time_zone->setCurrentIndex(Settings::values.time_zone_index.GetValue()); |
| 74 | ui->combo_sound->setCurrentIndex(Settings::values.sound_index.GetValue()); | 84 | ui->combo_sound->setCurrentIndex(Settings::values.sound_index.GetValue()); |
| 75 | |||
| 76 | ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.GetValue().has_value()); | ||
| 77 | ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.GetValue().has_value() && | ||
| 78 | Settings::values.rng_seed.UsingGlobal()); | ||
| 79 | ui->rng_seed_edit->setText(rng_seed); | ||
| 80 | |||
| 81 | ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.GetValue().has_value()); | ||
| 82 | ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.GetValue().has_value() && | ||
| 83 | Settings::values.rng_seed.UsingGlobal()); | ||
| 84 | ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time.count())); | ||
| 85 | } else { | 85 | } else { |
| 86 | ConfigurationShared::SetPerGameSetting(ui->combo_language, | 86 | ConfigurationShared::SetPerGameSetting(ui->combo_language, |
| 87 | &Settings::values.language_index); | 87 | &Settings::values.language_index); |
| @@ -90,27 +90,14 @@ void ConfigureSystem::SetConfiguration() { | |||
| 90 | &Settings::values.time_zone_index); | 90 | &Settings::values.time_zone_index); |
| 91 | ConfigurationShared::SetPerGameSetting(ui->combo_sound, &Settings::values.sound_index); | 91 | ConfigurationShared::SetPerGameSetting(ui->combo_sound, &Settings::values.sound_index); |
| 92 | 92 | ||
| 93 | if (Settings::values.rng_seed.UsingGlobal()) { | 93 | ConfigurationShared::SetHighlight(ui->label_language, "label_language", |
| 94 | ui->rng_seed_checkbox->setCheckState(Qt::PartiallyChecked); | 94 | !Settings::values.language_index.UsingGlobal()); |
| 95 | } else { | 95 | ConfigurationShared::SetHighlight(ui->label_region, "label_region", |
| 96 | ui->rng_seed_checkbox->setCheckState( | 96 | !Settings::values.region_index.UsingGlobal()); |
| 97 | Settings::values.rng_seed.GetValue().has_value() ? Qt::Checked : Qt::Unchecked); | 97 | ConfigurationShared::SetHighlight(ui->label_timezone, "label_timezone", |
| 98 | ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.GetValue().has_value()); | 98 | !Settings::values.time_zone_index.UsingGlobal()); |
| 99 | if (Settings::values.rng_seed.GetValue().has_value()) { | 99 | ConfigurationShared::SetHighlight(ui->label_sound, "label_sound", |
| 100 | ui->rng_seed_edit->setText(rng_seed); | 100 | !Settings::values.sound_index.UsingGlobal()); |
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | if (Settings::values.custom_rtc.UsingGlobal()) { | ||
| 105 | ui->custom_rtc_checkbox->setCheckState(Qt::PartiallyChecked); | ||
| 106 | } else { | ||
| 107 | ui->custom_rtc_checkbox->setCheckState( | ||
| 108 | Settings::values.custom_rtc.GetValue().has_value() ? Qt::Checked : Qt::Unchecked); | ||
| 109 | ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.GetValue().has_value()); | ||
| 110 | if (Settings::values.custom_rtc.GetValue().has_value()) { | ||
| 111 | ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time.count())); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | } | 101 | } |
| 115 | } | 102 | } |
| 116 | 103 | ||
| @@ -161,37 +148,44 @@ void ConfigureSystem::ApplyConfiguration() { | |||
| 161 | ui->combo_time_zone); | 148 | ui->combo_time_zone); |
| 162 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.sound_index, ui->combo_sound); | 149 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.sound_index, ui->combo_sound); |
| 163 | 150 | ||
| 164 | switch (ui->rng_seed_checkbox->checkState()) { | 151 | switch (use_rng_seed) { |
| 165 | case Qt::Checked: | 152 | case ConfigurationShared::CheckState::On: |
| 166 | Settings::values.rng_seed.SetGlobal(false); | 153 | case ConfigurationShared::CheckState::Off: |
| 167 | Settings::values.rng_seed.SetValue(ui->rng_seed_edit->text().toULongLong(nullptr, 16)); | ||
| 168 | break; | ||
| 169 | case Qt::Unchecked: | ||
| 170 | Settings::values.rng_seed.SetGlobal(false); | 154 | Settings::values.rng_seed.SetGlobal(false); |
| 171 | Settings::values.rng_seed.SetValue(std::nullopt); | 155 | if (ui->rng_seed_checkbox->isChecked()) { |
| 156 | Settings::values.rng_seed.SetValue( | ||
| 157 | ui->rng_seed_edit->text().toULongLong(nullptr, 16)); | ||
| 158 | } else { | ||
| 159 | Settings::values.rng_seed.SetValue(std::nullopt); | ||
| 160 | } | ||
| 172 | break; | 161 | break; |
| 173 | case Qt::PartiallyChecked: | 162 | case ConfigurationShared::CheckState::Global: |
| 174 | Settings::values.rng_seed.SetGlobal(false); | 163 | Settings::values.rng_seed.SetGlobal(false); |
| 175 | Settings::values.rng_seed.SetValue(std::nullopt); | 164 | Settings::values.rng_seed.SetValue(std::nullopt); |
| 176 | Settings::values.rng_seed.SetGlobal(true); | 165 | Settings::values.rng_seed.SetGlobal(true); |
| 177 | break; | 166 | break; |
| 167 | case ConfigurationShared::CheckState::Count: | ||
| 168 | break; | ||
| 178 | } | 169 | } |
| 179 | 170 | ||
| 180 | switch (ui->custom_rtc_checkbox->checkState()) { | 171 | switch (use_custom_rtc) { |
| 181 | case Qt::Checked: | 172 | case ConfigurationShared::CheckState::On: |
| 182 | Settings::values.custom_rtc.SetGlobal(false); | 173 | case ConfigurationShared::CheckState::Off: |
| 183 | Settings::values.custom_rtc.SetValue( | ||
| 184 | std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch())); | ||
| 185 | break; | ||
| 186 | case Qt::Unchecked: | ||
| 187 | Settings::values.custom_rtc.SetGlobal(false); | 174 | Settings::values.custom_rtc.SetGlobal(false); |
| 188 | Settings::values.custom_rtc.SetValue(std::nullopt); | 175 | if (ui->custom_rtc_checkbox->isChecked()) { |
| 176 | Settings::values.custom_rtc.SetValue( | ||
| 177 | std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch())); | ||
| 178 | } else { | ||
| 179 | Settings::values.custom_rtc.SetValue(std::nullopt); | ||
| 180 | } | ||
| 189 | break; | 181 | break; |
| 190 | case Qt::PartiallyChecked: | 182 | case ConfigurationShared::CheckState::Global: |
| 191 | Settings::values.custom_rtc.SetGlobal(false); | 183 | Settings::values.custom_rtc.SetGlobal(false); |
| 192 | Settings::values.custom_rtc.SetValue(std::nullopt); | 184 | Settings::values.custom_rtc.SetValue(std::nullopt); |
| 193 | Settings::values.custom_rtc.SetGlobal(true); | 185 | Settings::values.custom_rtc.SetGlobal(true); |
| 194 | break; | 186 | break; |
| 187 | case ConfigurationShared::CheckState::Count: | ||
| 188 | break; | ||
| 195 | } | 189 | } |
| 196 | } | 190 | } |
| 197 | 191 | ||
| @@ -229,10 +223,23 @@ void ConfigureSystem::SetupPerGameUI() { | |||
| 229 | return; | 223 | return; |
| 230 | } | 224 | } |
| 231 | 225 | ||
| 232 | ConfigurationShared::InsertGlobalItem(ui->combo_language); | 226 | ConfigurationShared::SetColoredComboBox(ui->combo_language, ui->label_language, |
| 233 | ConfigurationShared::InsertGlobalItem(ui->combo_region); | 227 | "label_language", |
| 234 | ConfigurationShared::InsertGlobalItem(ui->combo_time_zone); | 228 | Settings::values.language_index.GetValue(true)); |
| 235 | ConfigurationShared::InsertGlobalItem(ui->combo_sound); | 229 | ConfigurationShared::SetColoredComboBox(ui->combo_region, ui->label_region, "label_region", |
| 236 | ui->rng_seed_checkbox->setTristate(true); | 230 | Settings::values.region_index.GetValue(true)); |
| 237 | ui->custom_rtc_checkbox->setTristate(true); | 231 | ConfigurationShared::SetColoredComboBox(ui->combo_time_zone, ui->label_timezone, |
| 232 | "label_timezone", | ||
| 233 | Settings::values.time_zone_index.GetValue(true)); | ||
| 234 | ConfigurationShared::SetColoredComboBox(ui->combo_sound, ui->label_sound, "label_sound", | ||
| 235 | Settings::values.sound_index.GetValue(true)); | ||
| 236 | |||
| 237 | ConfigurationShared::SetColoredTristate( | ||
| 238 | ui->rng_seed_checkbox, "rng_seed_checkbox", Settings::values.rng_seed.UsingGlobal(), | ||
| 239 | Settings::values.rng_seed.GetValue().has_value(), | ||
| 240 | Settings::values.rng_seed.GetValue(true).has_value(), use_rng_seed); | ||
| 241 | ConfigurationShared::SetColoredTristate( | ||
| 242 | ui->custom_rtc_checkbox, "custom_rtc_checkbox", Settings::values.custom_rtc.UsingGlobal(), | ||
| 243 | Settings::values.custom_rtc.GetValue().has_value(), | ||
| 244 | Settings::values.custom_rtc.GetValue(true).has_value(), use_custom_rtc); | ||
| 238 | } | 245 | } |
diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index f317ef8b5..fc5cd2945 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h | |||
| @@ -9,6 +9,10 @@ | |||
| 9 | #include <QList> | 9 | #include <QList> |
| 10 | #include <QWidget> | 10 | #include <QWidget> |
| 11 | 11 | ||
| 12 | namespace ConfigurationShared { | ||
| 13 | enum class CheckState; | ||
| 14 | } | ||
| 15 | |||
| 12 | namespace Ui { | 16 | namespace Ui { |
| 13 | class ConfigureSystem; | 17 | class ConfigureSystem; |
| 14 | } | 18 | } |
| @@ -41,4 +45,7 @@ private: | |||
| 41 | int region_index = 0; | 45 | int region_index = 0; |
| 42 | int time_zone_index = 0; | 46 | int time_zone_index = 0; |
| 43 | int sound_index = 0; | 47 | int sound_index = 0; |
| 48 | |||
| 49 | ConfigurationShared::CheckState use_rng_seed; | ||
| 50 | ConfigurationShared::CheckState use_custom_rtc; | ||
| 44 | }; | 51 | }; |
diff --git a/src/yuzu/configuration/configure_system.ui b/src/yuzu/configuration/configure_system.ui index 9c8cca6dc..53b95658b 100644 --- a/src/yuzu/configuration/configure_system.ui +++ b/src/yuzu/configuration/configure_system.ui | |||
| @@ -21,490 +21,494 @@ | |||
| 21 | <property name="title"> | 21 | <property name="title"> |
| 22 | <string>System Settings</string> | 22 | <string>System Settings</string> |
| 23 | </property> | 23 | </property> |
| 24 | <layout class="QGridLayout" name="gridLayout"> | 24 | <layout class="QVBoxLayout" name="verticalLayout_2"> |
| 25 | <item row="3" column="0"> | 25 | <item> |
| 26 | <widget class="QLabel" name="label_sound"> | 26 | <layout class="QGridLayout" name="gridLayout_2"> |
| 27 | <property name="text"> | 27 | <item row="1" column="0"> |
| 28 | <string>Sound output mode</string> | 28 | <widget class="QLabel" name="label_region"> |
| 29 | </property> | 29 | <property name="text"> |
| 30 | </widget> | 30 | <string>Region:</string> |
| 31 | </item> | 31 | </property> |
| 32 | <item row="4" column="0"> | 32 | </widget> |
| 33 | <widget class="QLabel" name="label_console_id"> | 33 | </item> |
| 34 | <property name="text"> | 34 | <item row="2" column="1"> |
| 35 | <string>Console ID:</string> | 35 | <widget class="QComboBox" name="combo_time_zone"> |
| 36 | </property> | 36 | <item> |
| 37 | </widget> | 37 | <property name="text"> |
| 38 | </item> | 38 | <string>Auto</string> |
| 39 | <item row="0" column="1"> | 39 | </property> |
| 40 | <widget class="QComboBox" name="combo_language"> | 40 | </item> |
| 41 | <property name="toolTip"> | 41 | <item> |
| 42 | <string>Note: this can be overridden when region setting is auto-select</string> | 42 | <property name="text"> |
| 43 | </property> | 43 | <string>Default</string> |
| 44 | <item> | 44 | </property> |
| 45 | <property name="text"> | 45 | </item> |
| 46 | <string>Japanese (日本語)</string> | 46 | <item> |
| 47 | </property> | 47 | <property name="text"> |
| 48 | </item> | 48 | <string>CET</string> |
| 49 | <item> | 49 | </property> |
| 50 | <property name="text"> | 50 | </item> |
| 51 | <string>English</string> | 51 | <item> |
| 52 | </property> | 52 | <property name="text"> |
| 53 | </item> | 53 | <string>CST6CDT</string> |
| 54 | <item> | 54 | </property> |
| 55 | <property name="text"> | 55 | </item> |
| 56 | <string>French (français)</string> | 56 | <item> |
| 57 | </property> | 57 | <property name="text"> |
| 58 | </item> | 58 | <string>Cuba</string> |
| 59 | <item> | 59 | </property> |
| 60 | <property name="text"> | 60 | </item> |
| 61 | <string>German (Deutsch)</string> | 61 | <item> |
| 62 | </property> | 62 | <property name="text"> |
| 63 | </item> | 63 | <string>EET</string> |
| 64 | <item> | 64 | </property> |
| 65 | <property name="text"> | 65 | </item> |
| 66 | <string>Italian (italiano)</string> | 66 | <item> |
| 67 | </property> | 67 | <property name="text"> |
| 68 | </item> | 68 | <string>Egypt</string> |
| 69 | <item> | 69 | </property> |
| 70 | <property name="text"> | 70 | </item> |
| 71 | <string>Spanish (español)</string> | 71 | <item> |
| 72 | </property> | 72 | <property name="text"> |
| 73 | </item> | 73 | <string>Eire</string> |
| 74 | <item> | 74 | </property> |
| 75 | <property name="text"> | 75 | </item> |
| 76 | <string>Chinese</string> | 76 | <item> |
| 77 | </property> | 77 | <property name="text"> |
| 78 | </item> | 78 | <string>EST</string> |
| 79 | <item> | 79 | </property> |
| 80 | <property name="text"> | 80 | </item> |
| 81 | <string>Korean (한국어)</string> | 81 | <item> |
| 82 | </property> | 82 | <property name="text"> |
| 83 | </item> | 83 | <string>EST5EDT</string> |
| 84 | <item> | 84 | </property> |
| 85 | <property name="text"> | 85 | </item> |
| 86 | <string>Dutch (Nederlands)</string> | 86 | <item> |
| 87 | </property> | 87 | <property name="text"> |
| 88 | </item> | 88 | <string>GB</string> |
| 89 | <item> | 89 | </property> |
| 90 | <property name="text"> | 90 | </item> |
| 91 | <string>Portuguese (português)</string> | 91 | <item> |
| 92 | </property> | 92 | <property name="text"> |
| 93 | </item> | 93 | <string>GB-Eire</string> |
| 94 | <item> | 94 | </property> |
| 95 | <property name="text"> | 95 | </item> |
| 96 | <string>Russian (Русский)</string> | 96 | <item> |
| 97 | </property> | 97 | <property name="text"> |
| 98 | </item> | 98 | <string>GMT</string> |
| 99 | <item> | 99 | </property> |
| 100 | <property name="text"> | 100 | </item> |
| 101 | <string>Taiwanese</string> | 101 | <item> |
| 102 | </property> | 102 | <property name="text"> |
| 103 | </item> | 103 | <string>GMT+0</string> |
| 104 | <item> | 104 | </property> |
| 105 | <property name="text"> | 105 | </item> |
| 106 | <string>British English</string> | 106 | <item> |
| 107 | </property> | 107 | <property name="text"> |
| 108 | </item> | 108 | <string>GMT-0</string> |
| 109 | <item> | 109 | </property> |
| 110 | <property name="text"> | 110 | </item> |
| 111 | <string>Canadian French</string> | 111 | <item> |
| 112 | </property> | 112 | <property name="text"> |
| 113 | </item> | 113 | <string>GMT0</string> |
| 114 | <item> | 114 | </property> |
| 115 | <property name="text"> | 115 | </item> |
| 116 | <string>Latin American Spanish</string> | 116 | <item> |
| 117 | </property> | 117 | <property name="text"> |
| 118 | </item> | 118 | <string>Greenwich</string> |
| 119 | <item> | 119 | </property> |
| 120 | <property name="text"> | 120 | </item> |
| 121 | <string>Simplified Chinese</string> | 121 | <item> |
| 122 | </property> | 122 | <property name="text"> |
| 123 | </item> | 123 | <string>Hongkong</string> |
| 124 | <item> | 124 | </property> |
| 125 | <property name="text"> | 125 | </item> |
| 126 | <string>Traditional Chinese (正體中文)</string> | 126 | <item> |
| 127 | </property> | 127 | <property name="text"> |
| 128 | </item> | 128 | <string>HST</string> |
| 129 | </widget> | 129 | </property> |
| 130 | </item> | 130 | </item> |
| 131 | <item row="1" column="0"> | 131 | <item> |
| 132 | <widget class="QLabel" name="label_region"> | 132 | <property name="text"> |
| 133 | <property name="text"> | 133 | <string>Iceland</string> |
| 134 | <string>Region:</string> | 134 | </property> |
| 135 | </property> | 135 | </item> |
| 136 | </widget> | 136 | <item> |
| 137 | </item> | 137 | <property name="text"> |
| 138 | <item row="1" column="1"> | 138 | <string>Iran</string> |
| 139 | <widget class="QComboBox" name="combo_region"> | 139 | </property> |
| 140 | <item> | 140 | </item> |
| 141 | <property name="text"> | 141 | <item> |
| 142 | <string>Japan</string> | 142 | <property name="text"> |
| 143 | </property> | 143 | <string>Israel</string> |
| 144 | </item> | 144 | </property> |
| 145 | <item> | 145 | </item> |
| 146 | <property name="text"> | 146 | <item> |
| 147 | <string>USA</string> | 147 | <property name="text"> |
| 148 | </property> | 148 | <string>Jamaica</string> |
| 149 | </item> | 149 | </property> |
| 150 | <item> | 150 | </item> |
| 151 | <property name="text"> | 151 | <item> |
| 152 | <string>Europe</string> | 152 | <property name="text"> |
| 153 | </property> | 153 | <string>Japan</string> |
| 154 | </item> | 154 | </property> |
| 155 | <item> | 155 | </item> |
| 156 | <property name="text"> | 156 | <item> |
| 157 | <string>Australia</string> | 157 | <property name="text"> |
| 158 | </property> | 158 | <string>Kwajalein</string> |
| 159 | </item> | 159 | </property> |
| 160 | <item> | 160 | </item> |
| 161 | <property name="text"> | 161 | <item> |
| 162 | <string>China</string> | 162 | <property name="text"> |
| 163 | </property> | 163 | <string>Libya</string> |
| 164 | </item> | 164 | </property> |
| 165 | <item> | 165 | </item> |
| 166 | <property name="text"> | 166 | <item> |
| 167 | <string>Korea</string> | 167 | <property name="text"> |
| 168 | </property> | 168 | <string>MET</string> |
| 169 | </item> | 169 | </property> |
| 170 | <item> | 170 | </item> |
| 171 | <property name="text"> | 171 | <item> |
| 172 | <string>Taiwan</string> | 172 | <property name="text"> |
| 173 | </property> | 173 | <string>MST</string> |
| 174 | </item> | 174 | </property> |
| 175 | </widget> | 175 | </item> |
| 176 | </item> | 176 | <item> |
| 177 | <item row="2" column="0"> | 177 | <property name="text"> |
| 178 | <widget class="QLabel" name="label_timezone"> | 178 | <string>MST7MDT</string> |
| 179 | <property name="text"> | 179 | </property> |
| 180 | <string>Time Zone:</string> | 180 | </item> |
| 181 | </property> | 181 | <item> |
| 182 | </widget> | 182 | <property name="text"> |
| 183 | </item> | 183 | <string>Navajo</string> |
| 184 | <item row="2" column="1"> | 184 | </property> |
| 185 | <widget class="QComboBox" name="combo_time_zone"> | 185 | </item> |
| 186 | <item> | 186 | <item> |
| 187 | <property name="text"> | 187 | <property name="text"> |
| 188 | <string>Auto</string> | 188 | <string>NZ</string> |
| 189 | </property> | 189 | </property> |
| 190 | </item> | 190 | </item> |
| 191 | <item> | 191 | <item> |
| 192 | <property name="text"> | 192 | <property name="text"> |
| 193 | <string>Default</string> | 193 | <string>NZ-CHAT</string> |
| 194 | </property> | 194 | </property> |
| 195 | </item> | 195 | </item> |
| 196 | <item> | 196 | <item> |
| 197 | <property name="text"> | 197 | <property name="text"> |
| 198 | <string>CET</string> | 198 | <string>Poland</string> |
| 199 | </property> | 199 | </property> |
| 200 | </item> | 200 | </item> |
| 201 | <item> | 201 | <item> |
| 202 | <property name="text"> | 202 | <property name="text"> |
| 203 | <string>CST6CDT</string> | 203 | <string>Portugal</string> |
| 204 | </property> | 204 | </property> |
| 205 | </item> | 205 | </item> |
| 206 | <item> | 206 | <item> |
| 207 | <property name="text"> | 207 | <property name="text"> |
| 208 | <string>Cuba</string> | 208 | <string>PRC</string> |
| 209 | </property> | 209 | </property> |
| 210 | </item> | 210 | </item> |
| 211 | <item> | 211 | <item> |
| 212 | <property name="text"> | 212 | <property name="text"> |
| 213 | <string>EET</string> | 213 | <string>PST8PDT</string> |
| 214 | </property> | 214 | </property> |
| 215 | </item> | 215 | </item> |
| 216 | <item> | 216 | <item> |
| 217 | <property name="text"> | 217 | <property name="text"> |
| 218 | <string>Egypt</string> | 218 | <string>ROC</string> |
| 219 | </property> | 219 | </property> |
| 220 | </item> | 220 | </item> |
| 221 | <item> | 221 | <item> |
| 222 | <property name="text"> | 222 | <property name="text"> |
| 223 | <string>Eire</string> | 223 | <string>ROK</string> |
| 224 | </property> | 224 | </property> |
| 225 | </item> | 225 | </item> |
| 226 | <item> | 226 | <item> |
| 227 | <property name="text"> | 227 | <property name="text"> |
| 228 | <string>EST</string> | 228 | <string>Singapore</string> |
| 229 | </property> | 229 | </property> |
| 230 | </item> | 230 | </item> |
| 231 | <item> | 231 | <item> |
| 232 | <property name="text"> | 232 | <property name="text"> |
| 233 | <string>EST5EDT</string> | 233 | <string>Turkey</string> |
| 234 | </property> | 234 | </property> |
| 235 | </item> | 235 | </item> |
| 236 | <item> | 236 | <item> |
| 237 | <property name="text"> | 237 | <property name="text"> |
| 238 | <string>GB</string> | 238 | <string>UCT</string> |
| 239 | </property> | 239 | </property> |
| 240 | </item> | 240 | </item> |
| 241 | <item> | 241 | <item> |
| 242 | <property name="text"> | 242 | <property name="text"> |
| 243 | <string>GB-Eire</string> | 243 | <string>Universal</string> |
| 244 | </property> | 244 | </property> |
| 245 | </item> | 245 | </item> |
| 246 | <item> | 246 | <item> |
| 247 | <property name="text"> | 247 | <property name="text"> |
| 248 | <string>GMT</string> | 248 | <string>UTC</string> |
| 249 | </property> | 249 | </property> |
| 250 | </item> | 250 | </item> |
| 251 | <item> | 251 | <item> |
| 252 | <property name="text"> | 252 | <property name="text"> |
| 253 | <string>GMT+0</string> | 253 | <string>W-SU</string> |
| 254 | </property> | 254 | </property> |
| 255 | </item> | 255 | </item> |
| 256 | <item> | 256 | <item> |
| 257 | <property name="text"> | 257 | <property name="text"> |
| 258 | <string>GMT-0</string> | 258 | <string>WET</string> |
| 259 | </property> | 259 | </property> |
| 260 | </item> | 260 | </item> |
| 261 | <item> | 261 | <item> |
| 262 | <property name="text"> | 262 | <property name="text"> |
| 263 | <string>GMT0</string> | 263 | <string>Zulu</string> |
| 264 | </property> | 264 | </property> |
| 265 | </item> | 265 | </item> |
| 266 | <item> | 266 | </widget> |
| 267 | <property name="text"> | 267 | </item> |
| 268 | <string>Greenwich</string> | 268 | <item row="1" column="1"> |
| 269 | </property> | 269 | <widget class="QComboBox" name="combo_region"> |
| 270 | </item> | 270 | <item> |
| 271 | <item> | 271 | <property name="text"> |
| 272 | <property name="text"> | 272 | <string>Japan</string> |
| 273 | <string>Hongkong</string> | 273 | </property> |
| 274 | </property> | 274 | </item> |
| 275 | </item> | 275 | <item> |
| 276 | <item> | 276 | <property name="text"> |
| 277 | <property name="text"> | 277 | <string>USA</string> |
| 278 | <string>HST</string> | 278 | </property> |
| 279 | </property> | 279 | </item> |
| 280 | </item> | 280 | <item> |
| 281 | <item> | 281 | <property name="text"> |
| 282 | <property name="text"> | 282 | <string>Europe</string> |
| 283 | <string>Iceland</string> | 283 | </property> |
| 284 | </property> | 284 | </item> |
| 285 | </item> | 285 | <item> |
| 286 | <item> | 286 | <property name="text"> |
| 287 | <property name="text"> | 287 | <string>Australia</string> |
| 288 | <string>Iran</string> | 288 | </property> |
| 289 | </property> | 289 | </item> |
| 290 | </item> | 290 | <item> |
| 291 | <item> | 291 | <property name="text"> |
| 292 | <property name="text"> | 292 | <string>China</string> |
| 293 | <string>Israel</string> | 293 | </property> |
| 294 | </property> | 294 | </item> |
| 295 | </item> | 295 | <item> |
| 296 | <item> | 296 | <property name="text"> |
| 297 | <property name="text"> | 297 | <string>Korea</string> |
| 298 | <string>Jamaica</string> | 298 | </property> |
| 299 | </property> | 299 | </item> |
| 300 | </item> | 300 | <item> |
| 301 | <item> | 301 | <property name="text"> |
| 302 | <property name="text"> | 302 | <string>Taiwan</string> |
| 303 | <string>Japan</string> | 303 | </property> |
| 304 | </property> | 304 | </item> |
| 305 | </item> | 305 | </widget> |
| 306 | <item> | 306 | </item> |
| 307 | <property name="text"> | 307 | <item row="2" column="0"> |
| 308 | <string>Kwajalein</string> | 308 | <widget class="QLabel" name="label_timezone"> |
| 309 | </property> | 309 | <property name="text"> |
| 310 | </item> | 310 | <string>Time Zone:</string> |
| 311 | <item> | 311 | </property> |
| 312 | <property name="text"> | 312 | </widget> |
| 313 | <string>Libya</string> | 313 | </item> |
| 314 | </property> | 314 | <item row="0" column="1"> |
| 315 | </item> | 315 | <widget class="QComboBox" name="combo_language"> |
| 316 | <item> | 316 | <property name="toolTip"> |
| 317 | <property name="text"> | 317 | <string>Note: this can be overridden when region setting is auto-select</string> |
| 318 | <string>MET</string> | 318 | </property> |
| 319 | </property> | 319 | <item> |
| 320 | </item> | 320 | <property name="text"> |
| 321 | <item> | 321 | <string>Japanese (日本語)</string> |
| 322 | <property name="text"> | 322 | </property> |
| 323 | <string>MST</string> | 323 | </item> |
| 324 | </property> | 324 | <item> |
| 325 | </item> | 325 | <property name="text"> |
| 326 | <item> | 326 | <string>English</string> |
| 327 | <property name="text"> | 327 | </property> |
| 328 | <string>MST7MDT</string> | 328 | </item> |
| 329 | </property> | 329 | <item> |
| 330 | </item> | 330 | <property name="text"> |
| 331 | <item> | 331 | <string>French (français)</string> |
| 332 | <property name="text"> | 332 | </property> |
| 333 | <string>Navajo</string> | 333 | </item> |
| 334 | </property> | 334 | <item> |
| 335 | </item> | 335 | <property name="text"> |
| 336 | <item> | 336 | <string>German (Deutsch)</string> |
| 337 | <property name="text"> | 337 | </property> |
| 338 | <string>NZ</string> | 338 | </item> |
| 339 | </property> | 339 | <item> |
| 340 | </item> | 340 | <property name="text"> |
| 341 | <item> | 341 | <string>Italian (italiano)</string> |
| 342 | <property name="text"> | 342 | </property> |
| 343 | <string>NZ-CHAT</string> | 343 | </item> |
| 344 | </property> | 344 | <item> |
| 345 | </item> | 345 | <property name="text"> |
| 346 | <item> | 346 | <string>Spanish (español)</string> |
| 347 | <property name="text"> | 347 | </property> |
| 348 | <string>Poland</string> | 348 | </item> |
| 349 | </property> | 349 | <item> |
| 350 | </item> | 350 | <property name="text"> |
| 351 | <item> | 351 | <string>Chinese</string> |
| 352 | <property name="text"> | 352 | </property> |
| 353 | <string>Portugal</string> | 353 | </item> |
| 354 | </property> | 354 | <item> |
| 355 | </item> | 355 | <property name="text"> |
| 356 | <item> | 356 | <string>Korean (한국어)</string> |
| 357 | <property name="text"> | 357 | </property> |
| 358 | <string>PRC</string> | 358 | </item> |
| 359 | </property> | 359 | <item> |
| 360 | </item> | 360 | <property name="text"> |
| 361 | <item> | 361 | <string>Dutch (Nederlands)</string> |
| 362 | <property name="text"> | 362 | </property> |
| 363 | <string>PST8PDT</string> | 363 | </item> |
| 364 | </property> | 364 | <item> |
| 365 | </item> | 365 | <property name="text"> |
| 366 | <item> | 366 | <string>Portuguese (português)</string> |
| 367 | <property name="text"> | 367 | </property> |
| 368 | <string>ROC</string> | 368 | </item> |
| 369 | </property> | 369 | <item> |
| 370 | </item> | 370 | <property name="text"> |
| 371 | <item> | 371 | <string>Russian (Русский)</string> |
| 372 | <property name="text"> | 372 | </property> |
| 373 | <string>ROK</string> | 373 | </item> |
| 374 | </property> | 374 | <item> |
| 375 | </item> | 375 | <property name="text"> |
| 376 | <item> | 376 | <string>Taiwanese</string> |
| 377 | <property name="text"> | 377 | </property> |
| 378 | <string>Singapore</string> | 378 | </item> |
| 379 | </property> | 379 | <item> |
| 380 | </item> | 380 | <property name="text"> |
| 381 | <item> | 381 | <string>British English</string> |
| 382 | <property name="text"> | 382 | </property> |
| 383 | <string>Turkey</string> | 383 | </item> |
| 384 | </property> | 384 | <item> |
| 385 | </item> | 385 | <property name="text"> |
| 386 | <item> | 386 | <string>Canadian French</string> |
| 387 | <property name="text"> | 387 | </property> |
| 388 | <string>UCT</string> | 388 | </item> |
| 389 | </property> | 389 | <item> |
| 390 | </item> | 390 | <property name="text"> |
| 391 | <item> | 391 | <string>Latin American Spanish</string> |
| 392 | <property name="text"> | 392 | </property> |
| 393 | <string>Universal</string> | 393 | </item> |
| 394 | </property> | 394 | <item> |
| 395 | </item> | 395 | <property name="text"> |
| 396 | <item> | 396 | <string>Simplified Chinese</string> |
| 397 | <property name="text"> | 397 | </property> |
| 398 | <string>UTC</string> | 398 | </item> |
| 399 | </property> | 399 | <item> |
| 400 | </item> | 400 | <property name="text"> |
| 401 | <item> | 401 | <string>Traditional Chinese (正體中文)</string> |
| 402 | <property name="text"> | 402 | </property> |
| 403 | <string>W-SU</string> | 403 | </item> |
| 404 | </property> | 404 | </widget> |
| 405 | </item> | 405 | </item> |
| 406 | <item> | 406 | <item row="5" column="0"> |
| 407 | <property name="text"> | 407 | <widget class="QCheckBox" name="custom_rtc_checkbox"> |
| 408 | <string>WET</string> | 408 | <property name="text"> |
| 409 | </property> | 409 | <string>Custom RTC</string> |
| 410 | </item> | 410 | </property> |
| 411 | <item> | 411 | </widget> |
| 412 | <property name="text"> | 412 | </item> |
| 413 | <string>Zulu</string> | 413 | <item row="0" column="0"> |
| 414 | </property> | 414 | <widget class="QLabel" name="label_language"> |
| 415 | </item> | 415 | <property name="text"> |
| 416 | </widget> | 416 | <string>Language</string> |
| 417 | </item> | 417 | </property> |
| 418 | <item row="6" column="0"> | 418 | </widget> |
| 419 | <widget class="QCheckBox" name="rng_seed_checkbox"> | 419 | </item> |
| 420 | <property name="text"> | 420 | <item row="6" column="0"> |
| 421 | <string>RNG Seed</string> | 421 | <widget class="QCheckBox" name="rng_seed_checkbox"> |
| 422 | </property> | 422 | <property name="text"> |
| 423 | </widget> | 423 | <string>RNG Seed</string> |
| 424 | </item> | 424 | </property> |
| 425 | <item row="3" column="1"> | 425 | </widget> |
| 426 | <widget class="QComboBox" name="combo_sound"> | 426 | </item> |
| 427 | <item> | 427 | <item row="3" column="1"> |
| 428 | <property name="text"> | 428 | <widget class="QComboBox" name="combo_sound"> |
| 429 | <string>Mono</string> | 429 | <item> |
| 430 | </property> | 430 | <property name="text"> |
| 431 | </item> | 431 | <string>Mono</string> |
| 432 | <item> | 432 | </property> |
| 433 | <property name="text"> | 433 | </item> |
| 434 | <string>Stereo</string> | 434 | <item> |
| 435 | </property> | 435 | <property name="text"> |
| 436 | </item> | 436 | <string>Stereo</string> |
| 437 | <item> | 437 | </property> |
| 438 | <property name="text"> | 438 | </item> |
| 439 | <string>Surround</string> | 439 | <item> |
| 440 | </property> | 440 | <property name="text"> |
| 441 | </item> | 441 | <string>Surround</string> |
| 442 | </widget> | 442 | </property> |
| 443 | </item> | 443 | </item> |
| 444 | <item row="0" column="0"> | 444 | </widget> |
| 445 | <widget class="QLabel" name="label_language"> | 445 | </item> |
| 446 | <property name="text"> | 446 | <item row="4" column="0"> |
| 447 | <string>Language</string> | 447 | <widget class="QLabel" name="label_console_id"> |
| 448 | </property> | 448 | <property name="text"> |
| 449 | </widget> | 449 | <string>Console ID:</string> |
| 450 | </item> | 450 | </property> |
| 451 | <item row="4" column="1"> | 451 | </widget> |
| 452 | <widget class="QPushButton" name="button_regenerate_console_id"> | 452 | </item> |
| 453 | <property name="sizePolicy"> | 453 | <item row="3" column="0"> |
| 454 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | 454 | <widget class="QLabel" name="label_sound"> |
| 455 | <horstretch>0</horstretch> | 455 | <property name="text"> |
| 456 | <verstretch>0</verstretch> | 456 | <string>Sound output mode</string> |
| 457 | </sizepolicy> | 457 | </property> |
| 458 | </property> | 458 | </widget> |
| 459 | <property name="layoutDirection"> | 459 | </item> |
| 460 | <enum>Qt::RightToLeft</enum> | 460 | <item row="5" column="1"> |
| 461 | </property> | 461 | <widget class="QDateTimeEdit" name="custom_rtc_edit"> |
| 462 | <property name="text"> | 462 | <property name="minimumDate"> |
| 463 | <string>Regenerate</string> | 463 | <date> |
| 464 | </property> | 464 | <year>1970</year> |
| 465 | </widget> | 465 | <month>1</month> |
| 466 | </item> | 466 | <day>1</day> |
| 467 | <item row="5" column="0"> | 467 | </date> |
| 468 | <widget class="QCheckBox" name="custom_rtc_checkbox"> | 468 | </property> |
| 469 | <property name="text"> | 469 | <property name="displayFormat"> |
| 470 | <string>Custom RTC</string> | 470 | <string>d MMM yyyy h:mm:ss AP</string> |
| 471 | </property> | 471 | </property> |
| 472 | </widget> | 472 | </widget> |
| 473 | </item> | 473 | </item> |
| 474 | <item row="5" column="1"> | 474 | <item row="6" column="1"> |
| 475 | <widget class="QDateTimeEdit" name="custom_rtc_edit"> | 475 | <widget class="QLineEdit" name="rng_seed_edit"> |
| 476 | <property name="minimumDate"> | 476 | <property name="sizePolicy"> |
| 477 | <date> | 477 | <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> |
| 478 | <year>1970</year> | 478 | <horstretch>0</horstretch> |
| 479 | <month>1</month> | 479 | <verstretch>0</verstretch> |
| 480 | <day>1</day> | 480 | </sizepolicy> |
| 481 | </date> | 481 | </property> |
| 482 | </property> | 482 | <property name="font"> |
| 483 | <property name="displayFormat"> | 483 | <font> |
| 484 | <string>d MMM yyyy h:mm:ss AP</string> | 484 | <family>Lucida Console</family> |
| 485 | </property> | 485 | </font> |
| 486 | </widget> | 486 | </property> |
| 487 | </item> | 487 | <property name="inputMask"> |
| 488 | <item row="6" column="1"> | 488 | <string notr="true">HHHHHHHH</string> |
| 489 | <widget class="QLineEdit" name="rng_seed_edit"> | 489 | </property> |
| 490 | <property name="sizePolicy"> | 490 | <property name="maxLength"> |
| 491 | <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> | 491 | <number>8</number> |
| 492 | <horstretch>0</horstretch> | 492 | </property> |
| 493 | <verstretch>0</verstretch> | 493 | </widget> |
| 494 | </sizepolicy> | 494 | </item> |
| 495 | </property> | 495 | <item row="4" column="1"> |
| 496 | <property name="font"> | 496 | <widget class="QPushButton" name="button_regenerate_console_id"> |
| 497 | <font> | 497 | <property name="sizePolicy"> |
| 498 | <family>Lucida Console</family> | 498 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
| 499 | </font> | 499 | <horstretch>0</horstretch> |
| 500 | </property> | 500 | <verstretch>0</verstretch> |
| 501 | <property name="inputMask"> | 501 | </sizepolicy> |
| 502 | <string notr="true">HHHHHHHH</string> | 502 | </property> |
| 503 | </property> | 503 | <property name="layoutDirection"> |
| 504 | <property name="maxLength"> | 504 | <enum>Qt::RightToLeft</enum> |
| 505 | <number>8</number> | 505 | </property> |
| 506 | </property> | 506 | <property name="text"> |
| 507 | </widget> | 507 | <string>Regenerate</string> |
| 508 | </property> | ||
| 509 | </widget> | ||
| 510 | </item> | ||
| 511 | </layout> | ||
| 508 | </item> | 512 | </item> |
| 509 | </layout> | 513 | </layout> |
| 510 | </widget> | 514 | </widget> |
diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index 24b6c5b72..2c20b68d0 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp | |||
| @@ -4,9 +4,11 @@ | |||
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <utility> | 6 | #include <utility> |
| 7 | #include <QFileDialog> | ||
| 7 | 8 | ||
| 8 | #include <QDirIterator> | 9 | #include <QDirIterator> |
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/file_util.h" | ||
| 10 | #include "core/settings.h" | 12 | #include "core/settings.h" |
| 11 | #include "ui_configure_ui.h" | 13 | #include "ui_configure_ui.h" |
| 12 | #include "yuzu/configuration/configure_ui.h" | 14 | #include "yuzu/configuration/configure_ui.h" |
| @@ -52,9 +54,21 @@ ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::Configur | |||
| 52 | 54 | ||
| 53 | // Update text ComboBoxes after user interaction. | 55 | // Update text ComboBoxes after user interaction. |
| 54 | connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::activated), | 56 | connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::activated), |
| 55 | [=]() { ConfigureUi::UpdateSecondRowComboBox(); }); | 57 | [this] { ConfigureUi::UpdateSecondRowComboBox(); }); |
| 56 | connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::activated), | 58 | connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::activated), |
| 57 | [=]() { ConfigureUi::UpdateFirstRowComboBox(); }); | 59 | [this] { ConfigureUi::UpdateFirstRowComboBox(); }); |
| 60 | |||
| 61 | // Set screenshot path to user specification. | ||
| 62 | connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] { | ||
| 63 | const QString& filename = | ||
| 64 | QFileDialog::getExistingDirectory( | ||
| 65 | this, tr("Select Screenshots Path..."), | ||
| 66 | QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))) + | ||
| 67 | QDir::separator(); | ||
| 68 | if (!filename.isEmpty()) { | ||
| 69 | ui->screenshot_path_edit->setText(filename); | ||
| 70 | } | ||
| 71 | }); | ||
| 58 | } | 72 | } |
| 59 | 73 | ||
| 60 | ConfigureUi::~ConfigureUi() = default; | 74 | ConfigureUi::~ConfigureUi() = default; |
| @@ -66,6 +80,10 @@ void ConfigureUi::ApplyConfiguration() { | |||
| 66 | UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt(); | 80 | UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt(); |
| 67 | UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt(); | 81 | UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt(); |
| 68 | UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt(); | 82 | UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt(); |
| 83 | |||
| 84 | UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked(); | ||
| 85 | FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir, | ||
| 86 | ui->screenshot_path_edit->text().toStdString()); | ||
| 69 | Settings::Apply(); | 87 | Settings::Apply(); |
| 70 | } | 88 | } |
| 71 | 89 | ||
| @@ -80,6 +98,10 @@ void ConfigureUi::SetConfiguration() { | |||
| 80 | ui->show_add_ons->setChecked(UISettings::values.show_add_ons); | 98 | ui->show_add_ons->setChecked(UISettings::values.show_add_ons); |
| 81 | ui->icon_size_combobox->setCurrentIndex( | 99 | ui->icon_size_combobox->setCurrentIndex( |
| 82 | ui->icon_size_combobox->findData(UISettings::values.icon_size)); | 100 | ui->icon_size_combobox->findData(UISettings::values.icon_size)); |
| 101 | |||
| 102 | ui->enable_screenshot_save_as->setChecked(UISettings::values.enable_screenshot_save_as); | ||
| 103 | ui->screenshot_path_edit->setText( | ||
| 104 | QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))); | ||
| 83 | } | 105 | } |
| 84 | 106 | ||
| 85 | void ConfigureUi::changeEvent(QEvent* event) { | 107 | void ConfigureUi::changeEvent(QEvent* event) { |
diff --git a/src/yuzu/configuration/configure_ui.ui b/src/yuzu/configuration/configure_ui.ui index 0b81747d7..d895b799f 100644 --- a/src/yuzu/configuration/configure_ui.ui +++ b/src/yuzu/configuration/configure_ui.ui | |||
| @@ -6,8 +6,8 @@ | |||
| 6 | <rect> | 6 | <rect> |
| 7 | <x>0</x> | 7 | <x>0</x> |
| 8 | <y>0</y> | 8 | <y>0</y> |
| 9 | <width>300</width> | 9 | <width>363</width> |
| 10 | <height>377</height> | 10 | <height>391</height> |
| 11 | </rect> | 11 | </rect> |
| 12 | </property> | 12 | </property> |
| 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
| @@ -128,6 +128,47 @@ | |||
| 128 | </widget> | 128 | </widget> |
| 129 | </item> | 129 | </item> |
| 130 | <item> | 130 | <item> |
| 131 | <widget class="QGroupBox" name="screenshots_GroupBox"> | ||
| 132 | <property name="title"> | ||
| 133 | <string>Screenshots</string> | ||
| 134 | </property> | ||
| 135 | <layout class="QVBoxLayout" name="verticalLayout_4"> | ||
| 136 | <item> | ||
| 137 | <layout class="QVBoxLayout" name="verticalLayout_3"> | ||
| 138 | <item> | ||
| 139 | <widget class="QCheckBox" name="enable_screenshot_save_as"> | ||
| 140 | <property name="text"> | ||
| 141 | <string>Ask Where To Save Screenshots (Windows Only)</string> | ||
| 142 | </property> | ||
| 143 | </widget> | ||
| 144 | </item> | ||
| 145 | <item> | ||
| 146 | <layout class="QHBoxLayout" name="horizontalLayout_4"> | ||
| 147 | <item> | ||
| 148 | <widget class="QLabel" name="label"> | ||
| 149 | <property name="text"> | ||
| 150 | <string>Screenshots Path: </string> | ||
| 151 | </property> | ||
| 152 | </widget> | ||
| 153 | </item> | ||
| 154 | <item> | ||
| 155 | <widget class="QLineEdit" name="screenshot_path_edit"/> | ||
| 156 | </item> | ||
| 157 | <item> | ||
| 158 | <widget class="QToolButton" name="screenshot_path_button"> | ||
| 159 | <property name="text"> | ||
| 160 | <string>...</string> | ||
| 161 | </property> | ||
| 162 | </widget> | ||
| 163 | </item> | ||
| 164 | </layout> | ||
| 165 | </item> | ||
| 166 | </layout> | ||
| 167 | </item> | ||
| 168 | </layout> | ||
| 169 | </widget> | ||
| 170 | </item> | ||
| 171 | <item> | ||
| 131 | <spacer name="verticalSpacer"> | 172 | <spacer name="verticalSpacer"> |
| 132 | <property name="orientation"> | 173 | <property name="orientation"> |
| 133 | <enum>Qt::Vertical</enum> | 174 | <enum>Qt::Vertical</enum> |
diff --git a/src/yuzu/debugger/wait_tree.cpp b/src/yuzu/debugger/wait_tree.cpp index f391a41a9..3439cb333 100644 --- a/src/yuzu/debugger/wait_tree.cpp +++ b/src/yuzu/debugger/wait_tree.cpp | |||
| @@ -38,7 +38,10 @@ constexpr std::array<std::array<Qt::GlobalColor, 2>, 10> WaitTreeColors{{ | |||
| 38 | 38 | ||
| 39 | bool IsDarkTheme() { | 39 | bool IsDarkTheme() { |
| 40 | const auto& theme = UISettings::values.theme; | 40 | const auto& theme = UISettings::values.theme; |
| 41 | return theme == QStringLiteral("qdarkstyle") || theme == QStringLiteral("colorful_dark"); | 41 | return theme == QStringLiteral("qdarkstyle") || |
| 42 | theme == QStringLiteral("qdarkstyle_midnight_blue") || | ||
| 43 | theme == QStringLiteral("colorful_dark") || | ||
| 44 | theme == QStringLiteral("colorful_midnight_blue"); | ||
| 42 | } | 45 | } |
| 43 | 46 | ||
| 44 | } // namespace | 47 | } // namespace |
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index ab7fc7a24..62acc3720 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -474,28 +474,56 @@ void GameList::PopupContextMenu(const QPoint& menu_location) { | |||
| 474 | 474 | ||
| 475 | void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, std::string path) { | 475 | void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, std::string path) { |
| 476 | QAction* open_save_location = context_menu.addAction(tr("Open Save Data Location")); | 476 | QAction* open_save_location = context_menu.addAction(tr("Open Save Data Location")); |
| 477 | QAction* open_lfs_location = context_menu.addAction(tr("Open Mod Data Location")); | 477 | QAction* open_mod_location = context_menu.addAction(tr("Open Mod Data Location")); |
| 478 | QAction* open_transferable_shader_cache = | 478 | QAction* open_transferable_shader_cache = |
| 479 | context_menu.addAction(tr("Open Transferable Shader Cache")); | 479 | context_menu.addAction(tr("Open Transferable Shader Cache")); |
| 480 | context_menu.addSeparator(); | 480 | context_menu.addSeparator(); |
| 481 | QMenu* remove_menu = context_menu.addMenu(tr("Remove")); | ||
| 482 | QAction* remove_update = remove_menu->addAction(tr("Remove Installed Update")); | ||
| 483 | QAction* remove_dlc = remove_menu->addAction(tr("Remove All Installed DLC")); | ||
| 484 | QAction* remove_shader_cache = remove_menu->addAction(tr("Remove Shader Cache")); | ||
| 485 | QAction* remove_custom_config = remove_menu->addAction(tr("Remove Custom Configuration")); | ||
| 486 | remove_menu->addSeparator(); | ||
| 487 | QAction* remove_all_content = remove_menu->addAction(tr("Remove All Installed Contents")); | ||
| 481 | QAction* dump_romfs = context_menu.addAction(tr("Dump RomFS")); | 488 | QAction* dump_romfs = context_menu.addAction(tr("Dump RomFS")); |
| 482 | QAction* copy_tid = context_menu.addAction(tr("Copy Title ID to Clipboard")); | 489 | QAction* copy_tid = context_menu.addAction(tr("Copy Title ID to Clipboard")); |
| 483 | QAction* navigate_to_gamedb_entry = context_menu.addAction(tr("Navigate to GameDB entry")); | 490 | QAction* navigate_to_gamedb_entry = context_menu.addAction(tr("Navigate to GameDB entry")); |
| 484 | context_menu.addSeparator(); | 491 | context_menu.addSeparator(); |
| 485 | QAction* properties = context_menu.addAction(tr("Properties")); | 492 | QAction* properties = context_menu.addAction(tr("Properties")); |
| 486 | 493 | ||
| 487 | open_save_location->setEnabled(program_id != 0); | 494 | open_save_location->setVisible(program_id != 0); |
| 495 | open_mod_location->setVisible(program_id != 0); | ||
| 496 | open_transferable_shader_cache->setVisible(program_id != 0); | ||
| 497 | remove_update->setVisible(program_id != 0); | ||
| 498 | remove_dlc->setVisible(program_id != 0); | ||
| 499 | remove_shader_cache->setVisible(program_id != 0); | ||
| 500 | remove_all_content->setVisible(program_id != 0); | ||
| 488 | auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id); | 501 | auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id); |
| 489 | navigate_to_gamedb_entry->setVisible(it != compatibility_list.end() && program_id != 0); | 502 | navigate_to_gamedb_entry->setVisible(it != compatibility_list.end() && program_id != 0); |
| 490 | 503 | ||
| 491 | connect(open_save_location, &QAction::triggered, [this, program_id, path]() { | 504 | connect(open_save_location, &QAction::triggered, [this, program_id, path]() { |
| 492 | emit OpenFolderRequested(GameListOpenTarget::SaveData, path); | 505 | emit OpenFolderRequested(GameListOpenTarget::SaveData, path); |
| 493 | }); | 506 | }); |
| 494 | connect(open_lfs_location, &QAction::triggered, [this, program_id, path]() { | 507 | connect(open_mod_location, &QAction::triggered, [this, program_id, path]() { |
| 495 | emit OpenFolderRequested(GameListOpenTarget::ModData, path); | 508 | emit OpenFolderRequested(GameListOpenTarget::ModData, path); |
| 496 | }); | 509 | }); |
| 497 | connect(open_transferable_shader_cache, &QAction::triggered, | 510 | connect(open_transferable_shader_cache, &QAction::triggered, |
| 498 | [this, program_id]() { emit OpenTransferableShaderCacheRequested(program_id); }); | 511 | [this, program_id]() { emit OpenTransferableShaderCacheRequested(program_id); }); |
| 512 | connect(remove_all_content, &QAction::triggered, [this, program_id]() { | ||
| 513 | emit RemoveInstalledEntryRequested(program_id, InstalledEntryType::Game); | ||
| 514 | }); | ||
| 515 | connect(remove_update, &QAction::triggered, [this, program_id]() { | ||
| 516 | emit RemoveInstalledEntryRequested(program_id, InstalledEntryType::Update); | ||
| 517 | }); | ||
| 518 | connect(remove_dlc, &QAction::triggered, [this, program_id]() { | ||
| 519 | emit RemoveInstalledEntryRequested(program_id, InstalledEntryType::AddOnContent); | ||
| 520 | }); | ||
| 521 | connect(remove_shader_cache, &QAction::triggered, [this, program_id]() { | ||
| 522 | emit RemoveFileRequested(program_id, GameListRemoveTarget::ShaderCache); | ||
| 523 | }); | ||
| 524 | connect(remove_custom_config, &QAction::triggered, [this, program_id]() { | ||
| 525 | emit RemoveFileRequested(program_id, GameListRemoveTarget::CustomConfiguration); | ||
| 526 | }); | ||
| 499 | connect(dump_romfs, &QAction::triggered, | 527 | connect(dump_romfs, &QAction::triggered, |
| 500 | [this, program_id, path]() { emit DumpRomFSRequested(program_id, path); }); | 528 | [this, program_id, path]() { emit DumpRomFSRequested(program_id, path); }); |
| 501 | connect(copy_tid, &QAction::triggered, | 529 | connect(copy_tid, &QAction::triggered, |
diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h index a38cb2fc3..483835cce 100644 --- a/src/yuzu/game_list.h +++ b/src/yuzu/game_list.h | |||
| @@ -39,6 +39,17 @@ enum class GameListOpenTarget { | |||
| 39 | ModData, | 39 | ModData, |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | enum class GameListRemoveTarget { | ||
| 43 | ShaderCache, | ||
| 44 | CustomConfiguration, | ||
| 45 | }; | ||
| 46 | |||
| 47 | enum class InstalledEntryType { | ||
| 48 | Game, | ||
| 49 | Update, | ||
| 50 | AddOnContent, | ||
| 51 | }; | ||
| 52 | |||
| 42 | class GameList : public QWidget { | 53 | class GameList : public QWidget { |
| 43 | Q_OBJECT | 54 | Q_OBJECT |
| 44 | 55 | ||
| @@ -75,6 +86,8 @@ signals: | |||
| 75 | void ShouldCancelWorker(); | 86 | void ShouldCancelWorker(); |
| 76 | void OpenFolderRequested(GameListOpenTarget target, const std::string& game_path); | 87 | void OpenFolderRequested(GameListOpenTarget target, const std::string& game_path); |
| 77 | void OpenTransferableShaderCacheRequested(u64 program_id); | 88 | void OpenTransferableShaderCacheRequested(u64 program_id); |
| 89 | void RemoveInstalledEntryRequested(u64 program_id, InstalledEntryType type); | ||
| 90 | void RemoveFileRequested(u64 program_id, GameListRemoveTarget target); | ||
| 78 | void DumpRomFSRequested(u64 program_id, const std::string& game_path); | 91 | void DumpRomFSRequested(u64 program_id, const std::string& game_path); |
| 79 | void CopyTIDRequested(u64 program_id); | 92 | void CopyTIDRequested(u64 program_id); |
| 80 | void NavigateToGamedbEntryRequested(u64 program_id, | 93 | void NavigateToGamedbEntryRequested(u64 program_id, |
| @@ -117,8 +130,6 @@ private: | |||
| 117 | friend class GameListSearchField; | 130 | friend class GameListSearchField; |
| 118 | }; | 131 | }; |
| 119 | 132 | ||
| 120 | Q_DECLARE_METATYPE(GameListOpenTarget); | ||
| 121 | |||
| 122 | class GameListPlaceholder : public QWidget { | 133 | class GameListPlaceholder : public QWidget { |
| 123 | Q_OBJECT | 134 | Q_OBJECT |
| 124 | public: | 135 | public: |
diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 2018150db..239016b94 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp | |||
| @@ -369,8 +369,8 @@ void GameListWorker::run() { | |||
| 369 | auto* const game_list_dir = new GameListDir(game_dir); | 369 | auto* const game_list_dir = new GameListDir(game_dir); |
| 370 | emit DirEntryReady(game_list_dir); | 370 | emit DirEntryReady(game_list_dir); |
| 371 | provider->ClearAllEntries(); | 371 | provider->ClearAllEntries(); |
| 372 | ScanFileSystem(ScanTarget::FillManualContentProvider, game_dir.path.toStdString(), 2, | 372 | ScanFileSystem(ScanTarget::FillManualContentProvider, game_dir.path.toStdString(), |
| 373 | game_list_dir); | 373 | game_dir.deep_scan ? 256 : 0, game_list_dir); |
| 374 | ScanFileSystem(ScanTarget::PopulateGameList, game_dir.path.toStdString(), | 374 | ScanFileSystem(ScanTarget::PopulateGameList, game_dir.path.toStdString(), |
| 375 | game_dir.deep_scan ? 256 : 0, game_list_dir); | 375 | game_dir.deep_scan ? 256 : 0, game_list_dir); |
| 376 | } | 376 | } |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 31a635176..592993c36 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -583,7 +583,7 @@ void GMainWindow::InitializeWidgets() { | |||
| 583 | renderer_status_button->setObjectName(QStringLiteral("RendererStatusBarButton")); | 583 | renderer_status_button->setObjectName(QStringLiteral("RendererStatusBarButton")); |
| 584 | renderer_status_button->setCheckable(true); | 584 | renderer_status_button->setCheckable(true); |
| 585 | renderer_status_button->setFocusPolicy(Qt::NoFocus); | 585 | renderer_status_button->setFocusPolicy(Qt::NoFocus); |
| 586 | connect(renderer_status_button, &QPushButton::toggled, [=](bool checked) { | 586 | connect(renderer_status_button, &QPushButton::toggled, [this](bool checked) { |
| 587 | renderer_status_button->setText(checked ? tr("VULKAN") : tr("OPENGL")); | 587 | renderer_status_button->setText(checked ? tr("VULKAN") : tr("OPENGL")); |
| 588 | }); | 588 | }); |
| 589 | renderer_status_button->toggle(); | 589 | renderer_status_button->toggle(); |
| @@ -595,7 +595,7 @@ void GMainWindow::InitializeWidgets() { | |||
| 595 | #else | 595 | #else |
| 596 | renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() == | 596 | renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() == |
| 597 | Settings::RendererBackend::Vulkan); | 597 | Settings::RendererBackend::Vulkan); |
| 598 | connect(renderer_status_button, &QPushButton::clicked, [=] { | 598 | connect(renderer_status_button, &QPushButton::clicked, [this] { |
| 599 | if (emulation_running) { | 599 | if (emulation_running) { |
| 600 | return; | 600 | return; |
| 601 | } | 601 | } |
| @@ -847,6 +847,9 @@ void GMainWindow::ConnectWidgetEvents() { | |||
| 847 | connect(game_list, &GameList::OpenFolderRequested, this, &GMainWindow::OnGameListOpenFolder); | 847 | connect(game_list, &GameList::OpenFolderRequested, this, &GMainWindow::OnGameListOpenFolder); |
| 848 | connect(game_list, &GameList::OpenTransferableShaderCacheRequested, this, | 848 | connect(game_list, &GameList::OpenTransferableShaderCacheRequested, this, |
| 849 | &GMainWindow::OnTransferableShaderCacheOpenFile); | 849 | &GMainWindow::OnTransferableShaderCacheOpenFile); |
| 850 | connect(game_list, &GameList::RemoveInstalledEntryRequested, this, | ||
| 851 | &GMainWindow::OnGameListRemoveInstalledEntry); | ||
| 852 | connect(game_list, &GameList::RemoveFileRequested, this, &GMainWindow::OnGameListRemoveFile); | ||
| 850 | connect(game_list, &GameList::DumpRomFSRequested, this, &GMainWindow::OnGameListDumpRomFS); | 853 | connect(game_list, &GameList::DumpRomFSRequested, this, &GMainWindow::OnGameListDumpRomFS); |
| 851 | connect(game_list, &GameList::CopyTIDRequested, this, &GMainWindow::OnGameListCopyTID); | 854 | connect(game_list, &GameList::CopyTIDRequested, this, &GMainWindow::OnGameListCopyTID); |
| 852 | connect(game_list, &GameList::NavigateToGamedbEntryRequested, this, | 855 | connect(game_list, &GameList::NavigateToGamedbEntryRequested, this, |
| @@ -1257,7 +1260,6 @@ void GMainWindow::OnGameListOpenFolder(GameListOpenTarget target, const std::str | |||
| 1257 | case GameListOpenTarget::SaveData: { | 1260 | case GameListOpenTarget::SaveData: { |
| 1258 | open_target = tr("Save Data"); | 1261 | open_target = tr("Save Data"); |
| 1259 | const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); | 1262 | const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); |
| 1260 | ASSERT(program_id != 0); | ||
| 1261 | 1263 | ||
| 1262 | if (has_user_save) { | 1264 | if (has_user_save) { |
| 1263 | // User save data | 1265 | // User save data |
| @@ -1322,14 +1324,12 @@ void GMainWindow::OnGameListOpenFolder(GameListOpenTarget target, const std::str | |||
| 1322 | } | 1324 | } |
| 1323 | 1325 | ||
| 1324 | void GMainWindow::OnTransferableShaderCacheOpenFile(u64 program_id) { | 1326 | void GMainWindow::OnTransferableShaderCacheOpenFile(u64 program_id) { |
| 1325 | ASSERT(program_id != 0); | ||
| 1326 | |||
| 1327 | const QString shader_dir = | 1327 | const QString shader_dir = |
| 1328 | QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)); | 1328 | QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)); |
| 1329 | const QString tranferable_shader_cache_folder_path = | 1329 | const QString transferable_shader_cache_folder_path = |
| 1330 | shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable"); | 1330 | shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable"); |
| 1331 | const QString transferable_shader_cache_file_path = | 1331 | const QString transferable_shader_cache_file_path = |
| 1332 | tranferable_shader_cache_folder_path + QDir::separator() + | 1332 | transferable_shader_cache_folder_path + QDir::separator() + |
| 1333 | QString::fromStdString(fmt::format("{:016X}.bin", program_id)); | 1333 | QString::fromStdString(fmt::format("{:016X}.bin", program_id)); |
| 1334 | 1334 | ||
| 1335 | if (!QFile::exists(transferable_shader_cache_file_path)) { | 1335 | if (!QFile::exists(transferable_shader_cache_file_path)) { |
| @@ -1350,7 +1350,7 @@ void GMainWindow::OnTransferableShaderCacheOpenFile(u64 program_id) { | |||
| 1350 | param << QDir::toNativeSeparators(transferable_shader_cache_file_path); | 1350 | param << QDir::toNativeSeparators(transferable_shader_cache_file_path); |
| 1351 | QProcess::startDetached(explorer, param); | 1351 | QProcess::startDetached(explorer, param); |
| 1352 | #else | 1352 | #else |
| 1353 | QDesktopServices::openUrl(QUrl::fromLocalFile(tranferable_shader_cache_folder_path)); | 1353 | QDesktopServices::openUrl(QUrl::fromLocalFile(transferable_shader_cache_folder_path)); |
| 1354 | #endif | 1354 | #endif |
| 1355 | } | 1355 | } |
| 1356 | 1356 | ||
| @@ -1394,6 +1394,174 @@ static bool RomFSRawCopy(QProgressDialog& dialog, const FileSys::VirtualDir& src | |||
| 1394 | return true; | 1394 | return true; |
| 1395 | } | 1395 | } |
| 1396 | 1396 | ||
| 1397 | void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type) { | ||
| 1398 | const QString entry_type = [this, type] { | ||
| 1399 | switch (type) { | ||
| 1400 | case InstalledEntryType::Game: | ||
| 1401 | return tr("Contents"); | ||
| 1402 | case InstalledEntryType::Update: | ||
| 1403 | return tr("Update"); | ||
| 1404 | case InstalledEntryType::AddOnContent: | ||
| 1405 | return tr("DLC"); | ||
| 1406 | default: | ||
| 1407 | return QString{}; | ||
| 1408 | } | ||
| 1409 | }(); | ||
| 1410 | |||
| 1411 | if (QMessageBox::question( | ||
| 1412 | this, tr("Remove Entry"), tr("Remove Installed Game %1?").arg(entry_type), | ||
| 1413 | QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) { | ||
| 1414 | return; | ||
| 1415 | } | ||
| 1416 | |||
| 1417 | switch (type) { | ||
| 1418 | case InstalledEntryType::Game: | ||
| 1419 | RemoveBaseContent(program_id, entry_type); | ||
| 1420 | [[fallthrough]]; | ||
| 1421 | case InstalledEntryType::Update: | ||
| 1422 | RemoveUpdateContent(program_id, entry_type); | ||
| 1423 | if (type != InstalledEntryType::Game) { | ||
| 1424 | break; | ||
| 1425 | } | ||
| 1426 | [[fallthrough]]; | ||
| 1427 | case InstalledEntryType::AddOnContent: | ||
| 1428 | RemoveAddOnContent(program_id, entry_type); | ||
| 1429 | break; | ||
| 1430 | } | ||
| 1431 | FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + | ||
| 1432 | "game_list"); | ||
| 1433 | game_list->PopulateAsync(UISettings::values.game_dirs); | ||
| 1434 | } | ||
| 1435 | |||
| 1436 | void GMainWindow::RemoveBaseContent(u64 program_id, const QString& entry_type) { | ||
| 1437 | const auto& fs_controller = Core::System::GetInstance().GetFileSystemController(); | ||
| 1438 | const auto res = fs_controller.GetUserNANDContents()->RemoveExistingEntry(program_id) || | ||
| 1439 | fs_controller.GetSDMCContents()->RemoveExistingEntry(program_id); | ||
| 1440 | |||
| 1441 | if (res) { | ||
| 1442 | QMessageBox::information(this, tr("Successfully Removed"), | ||
| 1443 | tr("Successfully removed the installed base game.")); | ||
| 1444 | } else { | ||
| 1445 | QMessageBox::warning( | ||
| 1446 | this, tr("Error Removing %1").arg(entry_type), | ||
| 1447 | tr("The base game is not installed in the NAND and cannot be removed.")); | ||
| 1448 | } | ||
| 1449 | } | ||
| 1450 | |||
| 1451 | void GMainWindow::RemoveUpdateContent(u64 program_id, const QString& entry_type) { | ||
| 1452 | const auto update_id = program_id | 0x800; | ||
| 1453 | const auto& fs_controller = Core::System::GetInstance().GetFileSystemController(); | ||
| 1454 | const auto res = fs_controller.GetUserNANDContents()->RemoveExistingEntry(update_id) || | ||
| 1455 | fs_controller.GetSDMCContents()->RemoveExistingEntry(update_id); | ||
| 1456 | |||
| 1457 | if (res) { | ||
| 1458 | QMessageBox::information(this, tr("Successfully Removed"), | ||
| 1459 | tr("Successfully removed the installed update.")); | ||
| 1460 | } else { | ||
| 1461 | QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type), | ||
| 1462 | tr("There is no update installed for this title.")); | ||
| 1463 | } | ||
| 1464 | } | ||
| 1465 | |||
| 1466 | void GMainWindow::RemoveAddOnContent(u64 program_id, const QString& entry_type) { | ||
| 1467 | u32 count{}; | ||
| 1468 | const auto& fs_controller = Core::System::GetInstance().GetFileSystemController(); | ||
| 1469 | const auto dlc_entries = Core::System::GetInstance().GetContentProvider().ListEntriesFilter( | ||
| 1470 | FileSys::TitleType::AOC, FileSys::ContentRecordType::Data); | ||
| 1471 | |||
| 1472 | for (const auto& entry : dlc_entries) { | ||
| 1473 | if ((entry.title_id & DLC_BASE_TITLE_ID_MASK) == program_id) { | ||
| 1474 | const auto res = | ||
| 1475 | fs_controller.GetUserNANDContents()->RemoveExistingEntry(entry.title_id) || | ||
| 1476 | fs_controller.GetSDMCContents()->RemoveExistingEntry(entry.title_id); | ||
| 1477 | if (res) { | ||
| 1478 | ++count; | ||
| 1479 | } | ||
| 1480 | } | ||
| 1481 | } | ||
| 1482 | |||
| 1483 | if (count == 0) { | ||
| 1484 | QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type), | ||
| 1485 | tr("There are no DLC installed for this title.")); | ||
| 1486 | return; | ||
| 1487 | } | ||
| 1488 | |||
| 1489 | QMessageBox::information(this, tr("Successfully Removed"), | ||
| 1490 | tr("Successfully removed %1 installed DLC.").arg(count)); | ||
| 1491 | } | ||
| 1492 | |||
| 1493 | void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target) { | ||
| 1494 | const QString question = [this, target] { | ||
| 1495 | switch (target) { | ||
| 1496 | case GameListRemoveTarget::ShaderCache: | ||
| 1497 | return tr("Delete Transferable Shader Cache?"); | ||
| 1498 | case GameListRemoveTarget::CustomConfiguration: | ||
| 1499 | return tr("Remove Custom Game Configuration?"); | ||
| 1500 | default: | ||
| 1501 | return QString{}; | ||
| 1502 | } | ||
| 1503 | }(); | ||
| 1504 | |||
| 1505 | if (QMessageBox::question(this, tr("Remove File"), question, QMessageBox::Yes | QMessageBox::No, | ||
| 1506 | QMessageBox::No) != QMessageBox::Yes) { | ||
| 1507 | return; | ||
| 1508 | } | ||
| 1509 | |||
| 1510 | switch (target) { | ||
| 1511 | case GameListRemoveTarget::ShaderCache: | ||
| 1512 | RemoveTransferableShaderCache(program_id); | ||
| 1513 | break; | ||
| 1514 | case GameListRemoveTarget::CustomConfiguration: | ||
| 1515 | RemoveCustomConfiguration(program_id); | ||
| 1516 | break; | ||
| 1517 | } | ||
| 1518 | } | ||
| 1519 | |||
| 1520 | void GMainWindow::RemoveTransferableShaderCache(u64 program_id) { | ||
| 1521 | const QString shader_dir = | ||
| 1522 | QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)); | ||
| 1523 | const QString transferable_shader_cache_folder_path = | ||
| 1524 | shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable"); | ||
| 1525 | const QString transferable_shader_cache_file_path = | ||
| 1526 | transferable_shader_cache_folder_path + QDir::separator() + | ||
| 1527 | QString::fromStdString(fmt::format("{:016X}.bin", program_id)); | ||
| 1528 | |||
| 1529 | if (!QFile::exists(transferable_shader_cache_file_path)) { | ||
| 1530 | QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"), | ||
| 1531 | tr("A shader cache for this title does not exist.")); | ||
| 1532 | return; | ||
| 1533 | } | ||
| 1534 | |||
| 1535 | if (QFile::remove(transferable_shader_cache_file_path)) { | ||
| 1536 | QMessageBox::information(this, tr("Successfully Removed"), | ||
| 1537 | tr("Successfully removed the transferable shader cache.")); | ||
| 1538 | } else { | ||
| 1539 | QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"), | ||
| 1540 | tr("Failed to remove the transferable shader cache.")); | ||
| 1541 | } | ||
| 1542 | } | ||
| 1543 | |||
| 1544 | void GMainWindow::RemoveCustomConfiguration(u64 program_id) { | ||
| 1545 | const QString config_dir = | ||
| 1546 | QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir)); | ||
| 1547 | const QString custom_config_file_path = | ||
| 1548 | config_dir + QString::fromStdString(fmt::format("{:016X}.ini", program_id)); | ||
| 1549 | |||
| 1550 | if (!QFile::exists(custom_config_file_path)) { | ||
| 1551 | QMessageBox::warning(this, tr("Error Removing Custom Configuration"), | ||
| 1552 | tr("A custom configuration for this title does not exist.")); | ||
| 1553 | return; | ||
| 1554 | } | ||
| 1555 | |||
| 1556 | if (QFile::remove(custom_config_file_path)) { | ||
| 1557 | QMessageBox::information(this, tr("Successfully Removed"), | ||
| 1558 | tr("Successfully removed the custom game configuration.")); | ||
| 1559 | } else { | ||
| 1560 | QMessageBox::warning(this, tr("Error Removing Custom Configuration"), | ||
| 1561 | tr("Failed to remove the custom game configuration.")); | ||
| 1562 | } | ||
| 1563 | } | ||
| 1564 | |||
| 1397 | void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_path) { | 1565 | void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_path) { |
| 1398 | const auto failed = [this] { | 1566 | const auto failed = [this] { |
| 1399 | QMessageBox::warning(this, tr("RomFS Extraction Failed!"), | 1567 | QMessageBox::warning(this, tr("RomFS Extraction Failed!"), |
| @@ -1655,7 +1823,7 @@ void GMainWindow::OnMenuInstallToNAND() { | |||
| 1655 | 1823 | ||
| 1656 | ui.action_Install_File_NAND->setEnabled(false); | 1824 | ui.action_Install_File_NAND->setEnabled(false); |
| 1657 | 1825 | ||
| 1658 | install_progress = new QProgressDialog(QStringLiteral(""), tr("Cancel"), 0, total_size, this); | 1826 | install_progress = new QProgressDialog(QString{}, tr("Cancel"), 0, total_size, this); |
| 1659 | install_progress->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & | 1827 | install_progress->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & |
| 1660 | ~Qt::WindowMaximizeButtonHint); | 1828 | ~Qt::WindowMaximizeButtonHint); |
| 1661 | install_progress->setAttribute(Qt::WA_DeleteOnClose, true); | 1829 | install_progress->setAttribute(Qt::WA_DeleteOnClose, true); |
| @@ -1705,18 +1873,18 @@ void GMainWindow::OnMenuInstallToNAND() { | |||
| 1705 | install_progress->close(); | 1873 | install_progress->close(); |
| 1706 | 1874 | ||
| 1707 | const QString install_results = | 1875 | const QString install_results = |
| 1708 | (new_files.isEmpty() ? QStringLiteral("") | 1876 | (new_files.isEmpty() ? QString{} |
| 1709 | : tr("%n file(s) were newly installed\n", "", new_files.size())) + | 1877 | : tr("%n file(s) were newly installed\n", "", new_files.size())) + |
| 1710 | (overwritten_files.isEmpty() | 1878 | (overwritten_files.isEmpty() |
| 1711 | ? QStringLiteral("") | 1879 | ? QString{} |
| 1712 | : tr("%n file(s) were overwritten\n", "", overwritten_files.size())) + | 1880 | : tr("%n file(s) were overwritten\n", "", overwritten_files.size())) + |
| 1713 | (failed_files.isEmpty() ? QStringLiteral("") | 1881 | (failed_files.isEmpty() ? QString{} |
| 1714 | : tr("%n file(s) failed to install\n", "", failed_files.size())); | 1882 | : tr("%n file(s) failed to install\n", "", failed_files.size())); |
| 1715 | 1883 | ||
| 1716 | QMessageBox::information(this, tr("Install Results"), install_results); | 1884 | QMessageBox::information(this, tr("Install Results"), install_results); |
| 1717 | game_list->PopulateAsync(UISettings::values.game_dirs); | ||
| 1718 | FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + | 1885 | FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + |
| 1719 | "game_list"); | 1886 | "game_list"); |
| 1887 | game_list->PopulateAsync(UISettings::values.game_dirs); | ||
| 1720 | ui.action_Install_File_NAND->setEnabled(true); | 1888 | ui.action_Install_File_NAND->setEnabled(true); |
| 1721 | } | 1889 | } |
| 1722 | 1890 | ||
| @@ -2153,17 +2321,28 @@ void GMainWindow::OnToggleFilterBar() { | |||
| 2153 | 2321 | ||
| 2154 | void GMainWindow::OnCaptureScreenshot() { | 2322 | void GMainWindow::OnCaptureScreenshot() { |
| 2155 | OnPauseGame(); | 2323 | OnPauseGame(); |
| 2156 | QFileDialog png_dialog(this, tr("Capture Screenshot"), UISettings::values.screenshot_path, | 2324 | |
| 2157 | tr("PNG Image (*.png)")); | 2325 | const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); |
| 2158 | png_dialog.setAcceptMode(QFileDialog::AcceptSave); | 2326 | const auto screenshot_path = |
| 2159 | png_dialog.setDefaultSuffix(QStringLiteral("png")); | 2327 | QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir)); |
| 2160 | if (png_dialog.exec()) { | 2328 | const auto date = |
| 2161 | const QString path = png_dialog.selectedFiles().first(); | 2329 | QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz")); |
| 2162 | if (!path.isEmpty()) { | 2330 | QString filename = QStringLiteral("%1%2_%3.png") |
| 2163 | UISettings::values.screenshot_path = QFileInfo(path).path(); | 2331 | .arg(screenshot_path) |
| 2164 | render_window->CaptureScreenshot(UISettings::values.screenshot_resolution_factor, path); | 2332 | .arg(title_id, 16, 16, QLatin1Char{'0'}) |
| 2333 | .arg(date); | ||
| 2334 | |||
| 2335 | #ifdef _WIN32 | ||
| 2336 | if (UISettings::values.enable_screenshot_save_as) { | ||
| 2337 | filename = QFileDialog::getSaveFileName(this, tr("Capture Screenshot"), filename, | ||
| 2338 | tr("PNG Image (*.png)")); | ||
| 2339 | if (filename.isEmpty()) { | ||
| 2340 | OnStartGame(); | ||
| 2341 | return; | ||
| 2165 | } | 2342 | } |
| 2166 | } | 2343 | } |
| 2344 | #endif | ||
| 2345 | render_window->CaptureScreenshot(UISettings::values.screenshot_resolution_factor, filename); | ||
| 2167 | OnStartGame(); | 2346 | OnStartGame(); |
| 2168 | } | 2347 | } |
| 2169 | 2348 | ||
| @@ -2202,8 +2381,7 @@ void GMainWindow::UpdateStatusBar() { | |||
| 2202 | 2381 | ||
| 2203 | if (shaders_building != 0) { | 2382 | if (shaders_building != 0) { |
| 2204 | shader_building_label->setText( | 2383 | shader_building_label->setText( |
| 2205 | tr("Building: %1 shader").arg(shaders_building) + | 2384 | tr("Building: %n shader(s)", "", static_cast<int>(shaders_building))); |
| 2206 | (shaders_building != 1 ? QString::fromStdString("s") : QString::fromStdString(""))); | ||
| 2207 | shader_building_label->setVisible(true); | 2385 | shader_building_label->setVisible(true); |
| 2208 | } else { | 2386 | } else { |
| 2209 | shader_building_label->setVisible(false); | 2387 | shader_building_label->setVisible(false); |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index db573d606..73a44a3bf 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -32,6 +32,8 @@ class QPushButton; | |||
| 32 | class QProgressDialog; | 32 | class QProgressDialog; |
| 33 | class WaitTreeWidget; | 33 | class WaitTreeWidget; |
| 34 | enum class GameListOpenTarget; | 34 | enum class GameListOpenTarget; |
| 35 | enum class GameListRemoveTarget; | ||
| 36 | enum class InstalledEntryType; | ||
| 35 | class GameListPlaceholder; | 37 | class GameListPlaceholder; |
| 36 | 38 | ||
| 37 | namespace Core::Frontend { | 39 | namespace Core::Frontend { |
| @@ -198,6 +200,8 @@ private slots: | |||
| 198 | void OnGameListLoadFile(QString game_path); | 200 | void OnGameListLoadFile(QString game_path); |
| 199 | void OnGameListOpenFolder(GameListOpenTarget target, const std::string& game_path); | 201 | void OnGameListOpenFolder(GameListOpenTarget target, const std::string& game_path); |
| 200 | void OnTransferableShaderCacheOpenFile(u64 program_id); | 202 | void OnTransferableShaderCacheOpenFile(u64 program_id); |
| 203 | void OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type); | ||
| 204 | void OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target); | ||
| 201 | void OnGameListDumpRomFS(u64 program_id, const std::string& game_path); | 205 | void OnGameListDumpRomFS(u64 program_id, const std::string& game_path); |
| 202 | void OnGameListCopyTID(u64 program_id); | 206 | void OnGameListCopyTID(u64 program_id); |
| 203 | void OnGameListNavigateToGamedbEntry(u64 program_id, | 207 | void OnGameListNavigateToGamedbEntry(u64 program_id, |
| @@ -229,6 +233,11 @@ private slots: | |||
| 229 | void OnLanguageChanged(const QString& locale); | 233 | void OnLanguageChanged(const QString& locale); |
| 230 | 234 | ||
| 231 | private: | 235 | private: |
| 236 | void RemoveBaseContent(u64 program_id, const QString& entry_type); | ||
| 237 | void RemoveUpdateContent(u64 program_id, const QString& entry_type); | ||
| 238 | void RemoveAddOnContent(u64 program_id, const QString& entry_type); | ||
| 239 | void RemoveTransferableShaderCache(u64 program_id); | ||
| 240 | void RemoveCustomConfiguration(u64 program_id); | ||
| 232 | std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); | 241 | std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); |
| 233 | InstallResult InstallNSPXCI(const QString& filename); | 242 | InstallResult InstallNSPXCI(const QString& filename); |
| 234 | InstallResult InstallNCA(const QString& filename); | 243 | InstallResult InstallNCA(const QString& filename); |
diff --git a/src/yuzu/uisettings.cpp b/src/yuzu/uisettings.cpp index 738c4b2fc..a51175f36 100644 --- a/src/yuzu/uisettings.cpp +++ b/src/yuzu/uisettings.cpp | |||
| @@ -11,6 +11,8 @@ const Themes themes{{ | |||
| 11 | {"Light Colorful", "colorful"}, | 11 | {"Light Colorful", "colorful"}, |
| 12 | {"Dark", "qdarkstyle"}, | 12 | {"Dark", "qdarkstyle"}, |
| 13 | {"Dark Colorful", "colorful_dark"}, | 13 | {"Dark Colorful", "colorful_dark"}, |
| 14 | {"Midnight Blue", "qdarkstyle_midnight_blue"}, | ||
| 15 | {"Midnight Blue Colorful", "colorful_midnight_blue"}, | ||
| 14 | }}; | 16 | }}; |
| 15 | 17 | ||
| 16 | Values values = {}; | 18 | Values values = {}; |
diff --git a/src/yuzu/uisettings.h b/src/yuzu/uisettings.h index 6cc65736d..bbfeafc55 100644 --- a/src/yuzu/uisettings.h +++ b/src/yuzu/uisettings.h | |||
| @@ -24,7 +24,7 @@ struct Shortcut { | |||
| 24 | ContextualShortcut shortcut; | 24 | ContextualShortcut shortcut; |
| 25 | }; | 25 | }; |
| 26 | 26 | ||
| 27 | using Themes = std::array<std::pair<const char*, const char*>, 4>; | 27 | using Themes = std::array<std::pair<const char*, const char*>, 6>; |
| 28 | extern const Themes themes; | 28 | extern const Themes themes; |
| 29 | 29 | ||
| 30 | struct GameDir { | 30 | struct GameDir { |
| @@ -66,11 +66,11 @@ struct Values { | |||
| 66 | // Discord RPC | 66 | // Discord RPC |
| 67 | bool enable_discord_presence; | 67 | bool enable_discord_presence; |
| 68 | 68 | ||
| 69 | bool enable_screenshot_save_as; | ||
| 69 | u16 screenshot_resolution_factor; | 70 | u16 screenshot_resolution_factor; |
| 70 | 71 | ||
| 71 | QString roms_path; | 72 | QString roms_path; |
| 72 | QString symbols_path; | 73 | QString symbols_path; |
| 73 | QString screenshot_path; | ||
| 74 | QString game_dir_deprecated; | 74 | QString game_dir_deprecated; |
| 75 | bool game_dir_deprecated_deepscan; | 75 | bool game_dir_deprecated_deepscan; |
| 76 | QVector<UISettings::GameDir> game_dirs; | 76 | QVector<UISettings::GameDir> game_dirs; |