diff options
93 files changed, 1691 insertions, 876 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fa8c852ac..5df2ff3fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -376,7 +376,7 @@ if (ENABLE_SDL2) | |||
| 376 | if (YUZU_USE_BUNDLED_SDL2) | 376 | if (YUZU_USE_BUNDLED_SDL2) |
| 377 | # Detect toolchain and platform | 377 | # Detect toolchain and platform |
| 378 | if ((MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS 1930) AND ARCHITECTURE_x86_64) | 378 | if ((MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS 1930) AND ARCHITECTURE_x86_64) |
| 379 | set(SDL2_VER "SDL2-2.0.15-prerelease") | 379 | set(SDL2_VER "SDL2-2.0.16") |
| 380 | else() | 380 | else() |
| 381 | message(FATAL_ERROR "No bundled SDL2 binaries for your toolchain. Disable YUZU_USE_BUNDLED_SDL2 and provide your own.") | 381 | message(FATAL_ERROR "No bundled SDL2 binaries for your toolchain. Disable YUZU_USE_BUNDLED_SDL2 and provide your own.") |
| 382 | endif() | 382 | endif() |
| @@ -396,7 +396,7 @@ if (ENABLE_SDL2) | |||
| 396 | elseif (YUZU_USE_EXTERNAL_SDL2) | 396 | elseif (YUZU_USE_EXTERNAL_SDL2) |
| 397 | message(STATUS "Using SDL2 from externals.") | 397 | message(STATUS "Using SDL2 from externals.") |
| 398 | else() | 398 | else() |
| 399 | find_package(SDL2 2.0.15 REQUIRED) | 399 | find_package(SDL2 2.0.16 REQUIRED) |
| 400 | 400 | ||
| 401 | # Some installations don't set SDL2_LIBRARIES | 401 | # Some installations don't set SDL2_LIBRARIES |
| 402 | if("${SDL2_LIBRARIES}" STREQUAL "") | 402 | if("${SDL2_LIBRARIES}" STREQUAL "") |
| @@ -767,7 +767,7 @@ if (APPLE) | |||
| 767 | elseif (WIN32) | 767 | elseif (WIN32) |
| 768 | # WSAPoll and SHGetKnownFolderPath (AppData/Roaming) didn't exist before WinNT 6.x (Vista) | 768 | # WSAPoll and SHGetKnownFolderPath (AppData/Roaming) didn't exist before WinNT 6.x (Vista) |
| 769 | add_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600) | 769 | add_definitions(-D_WIN32_WINNT=0x0600 -DWINVER=0x0600) |
| 770 | set(PLATFORM_LIBRARIES winmm ws2_32) | 770 | set(PLATFORM_LIBRARIES winmm ws2_32 iphlpapi) |
| 771 | if (MINGW) | 771 | if (MINGW) |
| 772 | # PSAPI is the Process Status API | 772 | # PSAPI is the Process Status API |
| 773 | set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} psapi imm32 version) | 773 | set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} psapi imm32 version) |
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 4b8d35548..0c2c059a9 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt | |||
| @@ -7,7 +7,9 @@ include(DownloadExternals) | |||
| 7 | # xbyak | 7 | # xbyak |
| 8 | if (ARCHITECTURE_x86 OR ARCHITECTURE_x86_64) | 8 | if (ARCHITECTURE_x86 OR ARCHITECTURE_x86_64) |
| 9 | add_library(xbyak INTERFACE) | 9 | add_library(xbyak INTERFACE) |
| 10 | target_include_directories(xbyak SYSTEM INTERFACE ./xbyak/xbyak) | 10 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/xbyak/include) |
| 11 | file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/xbyak/xbyak DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/xbyak/include) | ||
| 12 | target_include_directories(xbyak SYSTEM INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/xbyak/include) | ||
| 11 | target_compile_definitions(xbyak INTERFACE XBYAK_NO_OP_NAMES) | 13 | target_compile_definitions(xbyak INTERFACE XBYAK_NO_OP_NAMES) |
| 12 | endif() | 14 | endif() |
| 13 | 15 | ||
| @@ -19,6 +21,7 @@ target_include_directories(catch-single-include INTERFACE catch/single_include) | |||
| 19 | if (ARCHITECTURE_x86_64) | 21 | if (ARCHITECTURE_x86_64) |
| 20 | set(DYNARMIC_TESTS OFF) | 22 | set(DYNARMIC_TESTS OFF) |
| 21 | set(DYNARMIC_NO_BUNDLED_FMT ON) | 23 | set(DYNARMIC_NO_BUNDLED_FMT ON) |
| 24 | set(DYNARMIC_IGNORE_ASSERTS ON CACHE BOOL "" FORCE) | ||
| 22 | add_subdirectory(dynarmic) | 25 | add_subdirectory(dynarmic) |
| 23 | endif() | 26 | endif() |
| 24 | 27 | ||
diff --git a/externals/SDL b/externals/SDL | |||
| Subproject 2f248a2a31c3323ecc37c00ad5e269e347ae392 | Subproject 25f9ed87ff6947d9576fc9d79dee0784e638ac5 | ||
diff --git a/externals/dynarmic b/externals/dynarmic | |||
| Subproject 7946868af49d403fe54c92d2d60ef986513d1fe | Subproject 517e35f845e010788b6febe42fd6ddb187b8c23 | ||
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 61dddab3f..e40d117d6 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -2,13 +2,10 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | #include <atomic> | 5 | #include <atomic> |
| 7 | #include <chrono> | 6 | #include <chrono> |
| 8 | #include <climits> | 7 | #include <climits> |
| 9 | #include <condition_variable> | 8 | #include <exception> |
| 10 | #include <memory> | ||
| 11 | #include <mutex> | ||
| 12 | #include <thread> | 9 | #include <thread> |
| 13 | #include <vector> | 10 | #include <vector> |
| 14 | 11 | ||
| @@ -16,104 +13,230 @@ | |||
| 16 | #include <windows.h> // For OutputDebugStringW | 13 | #include <windows.h> // For OutputDebugStringW |
| 17 | #endif | 14 | #endif |
| 18 | 15 | ||
| 19 | #include "common/assert.h" | ||
| 20 | #include "common/fs/file.h" | 16 | #include "common/fs/file.h" |
| 21 | #include "common/fs/fs.h" | 17 | #include "common/fs/fs.h" |
| 18 | #include "common/fs/fs_paths.h" | ||
| 19 | #include "common/fs/path_util.h" | ||
| 22 | #include "common/literals.h" | 20 | #include "common/literals.h" |
| 21 | #include "common/thread.h" | ||
| 23 | 22 | ||
| 24 | #include "common/logging/backend.h" | 23 | #include "common/logging/backend.h" |
| 25 | #include "common/logging/log.h" | 24 | #include "common/logging/log.h" |
| 26 | #include "common/logging/text_formatter.h" | 25 | #include "common/logging/text_formatter.h" |
| 27 | #include "common/settings.h" | 26 | #include "common/settings.h" |
| 27 | #ifdef _WIN32 | ||
| 28 | #include "common/string_util.h" | 28 | #include "common/string_util.h" |
| 29 | #endif | ||
| 29 | #include "common/threadsafe_queue.h" | 30 | #include "common/threadsafe_queue.h" |
| 30 | 31 | ||
| 31 | namespace Common::Log { | 32 | namespace Common::Log { |
| 32 | 33 | ||
| 34 | namespace { | ||
| 35 | |||
| 33 | /** | 36 | /** |
| 34 | * Static state as a singleton. | 37 | * Interface for logging backends. |
| 35 | */ | 38 | */ |
| 36 | class Impl { | 39 | class Backend { |
| 37 | public: | 40 | public: |
| 38 | static Impl& Instance() { | 41 | virtual ~Backend() = default; |
| 39 | static Impl backend; | 42 | |
| 40 | return backend; | 43 | virtual void Write(const Entry& entry) = 0; |
| 44 | |||
| 45 | virtual void EnableForStacktrace() = 0; | ||
| 46 | |||
| 47 | virtual void Flush() = 0; | ||
| 48 | }; | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Backend that writes to stderr and with color | ||
| 52 | */ | ||
| 53 | class ColorConsoleBackend final : public Backend { | ||
| 54 | public: | ||
| 55 | explicit ColorConsoleBackend() = default; | ||
| 56 | |||
| 57 | ~ColorConsoleBackend() override = default; | ||
| 58 | |||
| 59 | void Write(const Entry& entry) override { | ||
| 60 | if (enabled.load(std::memory_order_relaxed)) { | ||
| 61 | PrintColoredMessage(entry); | ||
| 62 | } | ||
| 41 | } | 63 | } |
| 42 | 64 | ||
| 43 | Impl(const Impl&) = delete; | 65 | void Flush() override { |
| 44 | Impl& operator=(const Impl&) = delete; | 66 | // stderr shouldn't be buffered |
| 67 | } | ||
| 45 | 68 | ||
| 46 | Impl(Impl&&) = delete; | 69 | void EnableForStacktrace() override { |
| 47 | Impl& operator=(Impl&&) = delete; | 70 | enabled = true; |
| 71 | } | ||
| 48 | 72 | ||
| 49 | void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num, | 73 | void SetEnabled(bool enabled_) { |
| 50 | const char* function, std::string message) { | 74 | enabled = enabled_; |
| 51 | message_queue.Push( | 75 | } |
| 52 | CreateEntry(log_class, log_level, filename, line_num, function, std::move(message))); | 76 | |
| 77 | private: | ||
| 78 | std::atomic_bool enabled{false}; | ||
| 79 | }; | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Backend that writes to a file passed into the constructor | ||
| 83 | */ | ||
| 84 | class FileBackend final : public Backend { | ||
| 85 | public: | ||
| 86 | explicit FileBackend(const std::filesystem::path& filename) { | ||
| 87 | auto old_filename = filename; | ||
| 88 | old_filename += ".old.txt"; | ||
| 89 | |||
| 90 | // Existence checks are done within the functions themselves. | ||
| 91 | // We don't particularly care if these succeed or not. | ||
| 92 | static_cast<void>(FS::RemoveFile(old_filename)); | ||
| 93 | static_cast<void>(FS::RenameFile(filename, old_filename)); | ||
| 94 | |||
| 95 | file = std::make_unique<FS::IOFile>(filename, FS::FileAccessMode::Write, | ||
| 96 | FS::FileType::TextFile); | ||
| 97 | } | ||
| 98 | |||
| 99 | ~FileBackend() override = default; | ||
| 100 | |||
| 101 | void Write(const Entry& entry) override { | ||
| 102 | if (!enabled) { | ||
| 103 | return; | ||
| 104 | } | ||
| 105 | |||
| 106 | bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n')); | ||
| 107 | |||
| 108 | using namespace Common::Literals; | ||
| 109 | // Prevent logs from exceeding a set maximum size in the event that log entries are spammed. | ||
| 110 | const auto write_limit = Settings::values.extended_logging ? 1_GiB : 100_MiB; | ||
| 111 | const bool write_limit_exceeded = bytes_written > write_limit; | ||
| 112 | if (entry.log_level >= Level::Error || write_limit_exceeded) { | ||
| 113 | if (write_limit_exceeded) { | ||
| 114 | // Stop writing after the write limit is exceeded. | ||
| 115 | // Don't close the file so we can print a stacktrace if necessary | ||
| 116 | enabled = false; | ||
| 117 | } | ||
| 118 | file->Flush(); | ||
| 119 | } | ||
| 120 | } | ||
| 121 | |||
| 122 | void Flush() override { | ||
| 123 | file->Flush(); | ||
| 124 | } | ||
| 125 | |||
| 126 | void EnableForStacktrace() override { | ||
| 127 | enabled = true; | ||
| 128 | bytes_written = 0; | ||
| 53 | } | 129 | } |
| 54 | 130 | ||
| 55 | void AddBackend(std::unique_ptr<Backend> backend) { | 131 | private: |
| 56 | std::lock_guard lock{writing_mutex}; | 132 | std::unique_ptr<FS::IOFile> file; |
| 57 | backends.push_back(std::move(backend)); | 133 | bool enabled = true; |
| 134 | std::size_t bytes_written = 0; | ||
| 135 | }; | ||
| 136 | |||
| 137 | /** | ||
| 138 | * Backend that writes to Visual Studio's output window | ||
| 139 | */ | ||
| 140 | class DebuggerBackend final : public Backend { | ||
| 141 | public: | ||
| 142 | explicit DebuggerBackend() = default; | ||
| 143 | |||
| 144 | ~DebuggerBackend() override = default; | ||
| 145 | |||
| 146 | void Write(const Entry& entry) override { | ||
| 147 | #ifdef _WIN32 | ||
| 148 | ::OutputDebugStringW(UTF8ToUTF16W(FormatLogMessage(entry).append(1, '\n')).c_str()); | ||
| 149 | #endif | ||
| 58 | } | 150 | } |
| 59 | 151 | ||
| 60 | void RemoveBackend(std::string_view backend_name) { | 152 | void Flush() override {} |
| 61 | std::lock_guard lock{writing_mutex}; | 153 | |
| 154 | void EnableForStacktrace() override {} | ||
| 155 | }; | ||
| 156 | |||
| 157 | bool initialization_in_progress_suppress_logging = true; | ||
| 62 | 158 | ||
| 63 | std::erase_if(backends, [&backend_name](const auto& backend) { | 159 | /** |
| 64 | return backend_name == backend->GetName(); | 160 | * Static state as a singleton. |
| 65 | }); | 161 | */ |
| 162 | class Impl { | ||
| 163 | public: | ||
| 164 | static Impl& Instance() { | ||
| 165 | if (!instance) { | ||
| 166 | throw std::runtime_error("Using Logging instance before its initialization"); | ||
| 167 | } | ||
| 168 | return *instance; | ||
| 66 | } | 169 | } |
| 67 | 170 | ||
| 68 | const Filter& GetGlobalFilter() const { | 171 | static void Initialize() { |
| 69 | return filter; | 172 | if (instance) { |
| 173 | LOG_WARNING(Log, "Reinitializing logging backend"); | ||
| 174 | return; | ||
| 175 | } | ||
| 176 | using namespace Common::FS; | ||
| 177 | const auto& log_dir = GetYuzuPath(YuzuPath::LogDir); | ||
| 178 | void(CreateDir(log_dir)); | ||
| 179 | Filter filter; | ||
| 180 | filter.ParseFilterString(Settings::values.log_filter.GetValue()); | ||
| 181 | instance = std::unique_ptr<Impl, decltype(&Deleter)>(new Impl(log_dir / LOG_FILE, filter), | ||
| 182 | Deleter); | ||
| 183 | initialization_in_progress_suppress_logging = false; | ||
| 70 | } | 184 | } |
| 71 | 185 | ||
| 186 | Impl(const Impl&) = delete; | ||
| 187 | Impl& operator=(const Impl&) = delete; | ||
| 188 | |||
| 189 | Impl(Impl&&) = delete; | ||
| 190 | Impl& operator=(Impl&&) = delete; | ||
| 191 | |||
| 72 | void SetGlobalFilter(const Filter& f) { | 192 | void SetGlobalFilter(const Filter& f) { |
| 73 | filter = f; | 193 | filter = f; |
| 74 | } | 194 | } |
| 75 | 195 | ||
| 76 | Backend* GetBackend(std::string_view backend_name) { | 196 | void SetColorConsoleBackendEnabled(bool enabled) { |
| 77 | const auto it = | 197 | color_console_backend.SetEnabled(enabled); |
| 78 | std::find_if(backends.begin(), backends.end(), | 198 | } |
| 79 | [&backend_name](const auto& i) { return backend_name == i->GetName(); }); | 199 | |
| 80 | if (it == backends.end()) | 200 | void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num, |
| 81 | return nullptr; | 201 | const char* function, std::string message) { |
| 82 | return it->get(); | 202 | if (!filter.CheckMessage(log_class, log_level)) |
| 203 | return; | ||
| 204 | const Entry& entry = | ||
| 205 | CreateEntry(log_class, log_level, filename, line_num, function, std::move(message)); | ||
| 206 | message_queue.Push(entry); | ||
| 83 | } | 207 | } |
| 84 | 208 | ||
| 85 | private: | 209 | private: |
| 86 | Impl() { | 210 | Impl(const std::filesystem::path& file_backend_filename, const Filter& filter_) |
| 87 | backend_thread = std::thread([&] { | 211 | : filter{filter_}, file_backend{file_backend_filename}, backend_thread{std::thread([this] { |
| 88 | Entry entry; | 212 | Common::SetCurrentThreadName("yuzu:Log"); |
| 89 | auto write_logs = [&](Entry& e) { | 213 | Entry entry; |
| 90 | std::lock_guard lock{writing_mutex}; | 214 | const auto write_logs = [this, &entry]() { |
| 91 | for (const auto& backend : backends) { | 215 | ForEachBackend([&entry](Backend& backend) { backend.Write(entry); }); |
| 92 | backend->Write(e); | 216 | }; |
| 93 | } | 217 | while (true) { |
| 94 | }; | 218 | entry = message_queue.PopWait(); |
| 95 | while (true) { | 219 | if (entry.final_entry) { |
| 96 | entry = message_queue.PopWait(); | 220 | break; |
| 97 | if (entry.final_entry) { | 221 | } |
| 98 | break; | 222 | write_logs(); |
| 99 | } | 223 | } |
| 100 | write_logs(entry); | 224 | // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a |
| 101 | } | 225 | // case where a system is repeatedly spamming logs even on close. |
| 226 | int max_logs_to_write = filter.IsDebug() ? INT_MAX : 100; | ||
| 227 | while (max_logs_to_write-- && message_queue.Pop(entry)) { | ||
| 228 | write_logs(); | ||
| 229 | } | ||
| 230 | })} {} | ||
| 102 | 231 | ||
| 103 | // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a | 232 | ~Impl() { |
| 104 | // case where a system is repeatedly spamming logs even on close. | 233 | StopBackendThread(); |
| 105 | const int MAX_LOGS_TO_WRITE = filter.IsDebug() ? INT_MAX : 100; | ||
| 106 | int logs_written = 0; | ||
| 107 | while (logs_written++ < MAX_LOGS_TO_WRITE && message_queue.Pop(entry)) { | ||
| 108 | write_logs(entry); | ||
| 109 | } | ||
| 110 | }); | ||
| 111 | } | 234 | } |
| 112 | 235 | ||
| 113 | ~Impl() { | 236 | void StopBackendThread() { |
| 114 | Entry entry; | 237 | Entry stop_entry{}; |
| 115 | entry.final_entry = true; | 238 | stop_entry.final_entry = true; |
| 116 | message_queue.Push(entry); | 239 | message_queue.Push(stop_entry); |
| 117 | backend_thread.join(); | 240 | backend_thread.join(); |
| 118 | } | 241 | } |
| 119 | 242 | ||
| @@ -135,100 +258,51 @@ private: | |||
| 135 | }; | 258 | }; |
| 136 | } | 259 | } |
| 137 | 260 | ||
| 138 | std::mutex writing_mutex; | 261 | void ForEachBackend(auto lambda) { |
| 139 | std::thread backend_thread; | 262 | lambda(static_cast<Backend&>(debugger_backend)); |
| 140 | std::vector<std::unique_ptr<Backend>> backends; | 263 | lambda(static_cast<Backend&>(color_console_backend)); |
| 141 | MPSCQueue<Entry> message_queue; | 264 | lambda(static_cast<Backend&>(file_backend)); |
| 142 | Filter filter; | 265 | } |
| 143 | std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; | ||
| 144 | }; | ||
| 145 | |||
| 146 | ConsoleBackend::~ConsoleBackend() = default; | ||
| 147 | |||
| 148 | void ConsoleBackend::Write(const Entry& entry) { | ||
| 149 | PrintMessage(entry); | ||
| 150 | } | ||
| 151 | |||
| 152 | ColorConsoleBackend::~ColorConsoleBackend() = default; | ||
| 153 | |||
| 154 | void ColorConsoleBackend::Write(const Entry& entry) { | ||
| 155 | PrintColoredMessage(entry); | ||
| 156 | } | ||
| 157 | |||
| 158 | FileBackend::FileBackend(const std::filesystem::path& filename) { | ||
| 159 | auto old_filename = filename; | ||
| 160 | old_filename += ".old.txt"; | ||
| 161 | |||
| 162 | // Existence checks are done within the functions themselves. | ||
| 163 | // We don't particularly care if these succeed or not. | ||
| 164 | FS::RemoveFile(old_filename); | ||
| 165 | void(FS::RenameFile(filename, old_filename)); | ||
| 166 | |||
| 167 | file = | ||
| 168 | std::make_unique<FS::IOFile>(filename, FS::FileAccessMode::Write, FS::FileType::TextFile); | ||
| 169 | } | ||
| 170 | |||
| 171 | FileBackend::~FileBackend() = default; | ||
| 172 | 266 | ||
| 173 | void FileBackend::Write(const Entry& entry) { | 267 | static void Deleter(Impl* ptr) { |
| 174 | if (!file->IsOpen()) { | 268 | delete ptr; |
| 175 | return; | ||
| 176 | } | 269 | } |
| 177 | 270 | ||
| 178 | using namespace Common::Literals; | 271 | static inline std::unique_ptr<Impl, decltype(&Deleter)> instance{nullptr, Deleter}; |
| 179 | // Prevent logs from exceeding a set maximum size in the event that log entries are spammed. | ||
| 180 | constexpr std::size_t MAX_BYTES_WRITTEN = 100_MiB; | ||
| 181 | constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1_GiB; | ||
| 182 | 272 | ||
| 183 | const bool write_limit_exceeded = | 273 | Filter filter; |
| 184 | bytes_written > MAX_BYTES_WRITTEN_EXTENDED || | 274 | DebuggerBackend debugger_backend{}; |
| 185 | (bytes_written > MAX_BYTES_WRITTEN && !Settings::values.extended_logging); | 275 | ColorConsoleBackend color_console_backend{}; |
| 276 | FileBackend file_backend; | ||
| 186 | 277 | ||
| 187 | // Close the file after the write limit is exceeded. | 278 | std::thread backend_thread; |
| 188 | if (write_limit_exceeded) { | 279 | MPSCQueue<Entry> message_queue{}; |
| 189 | file->Close(); | 280 | std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; |
| 190 | return; | 281 | }; |
| 191 | } | 282 | } // namespace |
| 192 | 283 | ||
| 193 | bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n')); | 284 | void Initialize() { |
| 194 | if (entry.log_level >= Level::Error) { | 285 | Impl::Initialize(); |
| 195 | file->Flush(); | ||
| 196 | } | ||
| 197 | } | 286 | } |
| 198 | 287 | ||
| 199 | DebuggerBackend::~DebuggerBackend() = default; | 288 | void DisableLoggingInTests() { |
| 200 | 289 | initialization_in_progress_suppress_logging = true; | |
| 201 | void DebuggerBackend::Write(const Entry& entry) { | ||
| 202 | #ifdef _WIN32 | ||
| 203 | ::OutputDebugStringW(UTF8ToUTF16W(FormatLogMessage(entry).append(1, '\n')).c_str()); | ||
| 204 | #endif | ||
| 205 | } | 290 | } |
| 206 | 291 | ||
| 207 | void SetGlobalFilter(const Filter& filter) { | 292 | void SetGlobalFilter(const Filter& filter) { |
| 208 | Impl::Instance().SetGlobalFilter(filter); | 293 | Impl::Instance().SetGlobalFilter(filter); |
| 209 | } | 294 | } |
| 210 | 295 | ||
| 211 | void AddBackend(std::unique_ptr<Backend> backend) { | 296 | void SetColorConsoleBackendEnabled(bool enabled) { |
| 212 | Impl::Instance().AddBackend(std::move(backend)); | 297 | Impl::Instance().SetColorConsoleBackendEnabled(enabled); |
| 213 | } | ||
| 214 | |||
| 215 | void RemoveBackend(std::string_view backend_name) { | ||
| 216 | Impl::Instance().RemoveBackend(backend_name); | ||
| 217 | } | ||
| 218 | |||
| 219 | Backend* GetBackend(std::string_view backend_name) { | ||
| 220 | return Impl::Instance().GetBackend(backend_name); | ||
| 221 | } | 298 | } |
| 222 | 299 | ||
| 223 | void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, | 300 | void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, |
| 224 | unsigned int line_num, const char* function, const char* format, | 301 | unsigned int line_num, const char* function, const char* format, |
| 225 | const fmt::format_args& args) { | 302 | const fmt::format_args& args) { |
| 226 | auto& instance = Impl::Instance(); | 303 | if (!initialization_in_progress_suppress_logging) { |
| 227 | const auto& filter = instance.GetGlobalFilter(); | 304 | Impl::Instance().PushEntry(log_class, log_level, filename, line_num, function, |
| 228 | if (!filter.CheckMessage(log_class, log_level)) | 305 | fmt::vformat(format, args)); |
| 229 | return; | 306 | } |
| 230 | |||
| 231 | instance.PushEntry(log_class, log_level, filename, line_num, function, | ||
| 232 | fmt::vformat(format, args)); | ||
| 233 | } | 307 | } |
| 234 | } // namespace Common::Log | 308 | } // namespace Common::Log |
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 4b9a910c1..cb7839ee9 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h | |||
| @@ -5,120 +5,21 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <filesystem> | 7 | #include <filesystem> |
| 8 | #include <memory> | ||
| 9 | #include <string> | ||
| 10 | #include <string_view> | ||
| 11 | #include "common/logging/filter.h" | 8 | #include "common/logging/filter.h" |
| 12 | #include "common/logging/log.h" | ||
| 13 | |||
| 14 | namespace Common::FS { | ||
| 15 | class IOFile; | ||
| 16 | } | ||
| 17 | 9 | ||
| 18 | namespace Common::Log { | 10 | namespace Common::Log { |
| 19 | 11 | ||
| 20 | class Filter; | 12 | class Filter; |
| 21 | 13 | ||
| 22 | /** | 14 | /// Initializes the logging system. This should be the first thing called in main. |
| 23 | * Interface for logging backends. As loggers can be created and removed at runtime, this can be | 15 | void Initialize(); |
| 24 | * used by a frontend for adding a custom logging backend as needed | ||
| 25 | */ | ||
| 26 | class Backend { | ||
| 27 | public: | ||
| 28 | virtual ~Backend() = default; | ||
| 29 | |||
| 30 | virtual void SetFilter(const Filter& new_filter) { | ||
| 31 | filter = new_filter; | ||
| 32 | } | ||
| 33 | virtual const char* GetName() const = 0; | ||
| 34 | virtual void Write(const Entry& entry) = 0; | ||
| 35 | |||
| 36 | private: | ||
| 37 | Filter filter; | ||
| 38 | }; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Backend that writes to stderr without any color commands | ||
| 42 | */ | ||
| 43 | class ConsoleBackend : public Backend { | ||
| 44 | public: | ||
| 45 | ~ConsoleBackend() override; | ||
| 46 | |||
| 47 | static const char* Name() { | ||
| 48 | return "console"; | ||
| 49 | } | ||
| 50 | const char* GetName() const override { | ||
| 51 | return Name(); | ||
| 52 | } | ||
| 53 | void Write(const Entry& entry) override; | ||
| 54 | }; | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Backend that writes to stderr and with color | ||
| 58 | */ | ||
| 59 | class ColorConsoleBackend : public Backend { | ||
| 60 | public: | ||
| 61 | ~ColorConsoleBackend() override; | ||
| 62 | |||
| 63 | static const char* Name() { | ||
| 64 | return "color_console"; | ||
| 65 | } | ||
| 66 | |||
| 67 | const char* GetName() const override { | ||
| 68 | return Name(); | ||
| 69 | } | ||
| 70 | void Write(const Entry& entry) override; | ||
| 71 | }; | ||
| 72 | 16 | ||
| 73 | /** | 17 | void DisableLoggingInTests(); |
| 74 | * Backend that writes to a file passed into the constructor | ||
| 75 | */ | ||
| 76 | class FileBackend : public Backend { | ||
| 77 | public: | ||
| 78 | explicit FileBackend(const std::filesystem::path& filename); | ||
| 79 | ~FileBackend() override; | ||
| 80 | |||
| 81 | static const char* Name() { | ||
| 82 | return "file"; | ||
| 83 | } | ||
| 84 | |||
| 85 | const char* GetName() const override { | ||
| 86 | return Name(); | ||
| 87 | } | ||
| 88 | |||
| 89 | void Write(const Entry& entry) override; | ||
| 90 | |||
| 91 | private: | ||
| 92 | std::unique_ptr<FS::IOFile> file; | ||
| 93 | std::size_t bytes_written = 0; | ||
| 94 | }; | ||
| 95 | |||
| 96 | /** | ||
| 97 | * Backend that writes to Visual Studio's output window | ||
| 98 | */ | ||
| 99 | class DebuggerBackend : public Backend { | ||
| 100 | public: | ||
| 101 | ~DebuggerBackend() override; | ||
| 102 | |||
| 103 | static const char* Name() { | ||
| 104 | return "debugger"; | ||
| 105 | } | ||
| 106 | const char* GetName() const override { | ||
| 107 | return Name(); | ||
| 108 | } | ||
| 109 | void Write(const Entry& entry) override; | ||
| 110 | }; | ||
| 111 | |||
| 112 | void AddBackend(std::unique_ptr<Backend> backend); | ||
| 113 | |||
| 114 | void RemoveBackend(std::string_view backend_name); | ||
| 115 | |||
| 116 | Backend* GetBackend(std::string_view backend_name); | ||
| 117 | 18 | ||
| 118 | /** | 19 | /** |
| 119 | * The global filter will prevent any messages from even being processed if they are filtered. Each | 20 | * The global filter will prevent any messages from even being processed if they are filtered. |
| 120 | * backend can have a filter, but if the level is lower than the global filter, the backend will | ||
| 121 | * never get the message | ||
| 122 | */ | 21 | */ |
| 123 | void SetGlobalFilter(const Filter& filter); | 22 | void SetGlobalFilter(const Filter& filter); |
| 124 | } // namespace Common::Log \ No newline at end of file | 23 | |
| 24 | void SetColorConsoleBackendEnabled(bool enabled); | ||
| 25 | } // namespace Common::Log | ||
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index f055f0e11..42744c994 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp | |||
| @@ -111,6 +111,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) { | |||
| 111 | SUB(Service, NCM) \ | 111 | SUB(Service, NCM) \ |
| 112 | SUB(Service, NFC) \ | 112 | SUB(Service, NFC) \ |
| 113 | SUB(Service, NFP) \ | 113 | SUB(Service, NFP) \ |
| 114 | SUB(Service, NGCT) \ | ||
| 114 | SUB(Service, NIFM) \ | 115 | SUB(Service, NIFM) \ |
| 115 | SUB(Service, NIM) \ | 116 | SUB(Service, NIM) \ |
| 116 | SUB(Service, NPNS) \ | 117 | SUB(Service, NPNS) \ |
diff --git a/src/common/logging/types.h b/src/common/logging/types.h index 7ad0334fc..ddf9d27ca 100644 --- a/src/common/logging/types.h +++ b/src/common/logging/types.h | |||
| @@ -81,6 +81,7 @@ enum class Class : u8 { | |||
| 81 | Service_NCM, ///< The NCM service | 81 | Service_NCM, ///< The NCM service |
| 82 | Service_NFC, ///< The NFC (Near-field communication) service | 82 | Service_NFC, ///< The NFC (Near-field communication) service |
| 83 | Service_NFP, ///< The NFP service | 83 | Service_NFP, ///< The NFP service |
| 84 | Service_NGCT, ///< The NGCT (No Good Content for Terra) service | ||
| 84 | Service_NIFM, ///< The NIFM (Network interface) service | 85 | Service_NIFM, ///< The NIFM (Network interface) service |
| 85 | Service_NIM, ///< The NIM service | 86 | Service_NIM, ///< The NIM service |
| 86 | Service_NPNS, ///< The NPNS service | 87 | Service_NPNS, ///< The NPNS service |
diff --git a/src/common/lru_cache.h b/src/common/lru_cache.h new file mode 100644 index 000000000..365488ba5 --- /dev/null +++ b/src/common/lru_cache.h | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2+ or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <deque> | ||
| 8 | #include <memory> | ||
| 9 | #include <type_traits> | ||
| 10 | |||
| 11 | #include "common/common_types.h" | ||
| 12 | |||
| 13 | namespace Common { | ||
| 14 | |||
| 15 | template <class Traits> | ||
| 16 | class LeastRecentlyUsedCache { | ||
| 17 | using ObjectType = typename Traits::ObjectType; | ||
| 18 | using TickType = typename Traits::TickType; | ||
| 19 | |||
| 20 | struct Item { | ||
| 21 | ObjectType obj; | ||
| 22 | TickType tick; | ||
| 23 | Item* next{}; | ||
| 24 | Item* prev{}; | ||
| 25 | }; | ||
| 26 | |||
| 27 | public: | ||
| 28 | LeastRecentlyUsedCache() : first_item{}, last_item{} {} | ||
| 29 | ~LeastRecentlyUsedCache() = default; | ||
| 30 | |||
| 31 | size_t Insert(ObjectType obj, TickType tick) { | ||
| 32 | const auto new_id = Build(); | ||
| 33 | auto& item = item_pool[new_id]; | ||
| 34 | item.obj = obj; | ||
| 35 | item.tick = tick; | ||
| 36 | Attach(item); | ||
| 37 | return new_id; | ||
| 38 | } | ||
| 39 | |||
| 40 | void Touch(size_t id, TickType tick) { | ||
| 41 | auto& item = item_pool[id]; | ||
| 42 | if (item.tick >= tick) { | ||
| 43 | return; | ||
| 44 | } | ||
| 45 | item.tick = tick; | ||
| 46 | if (&item == last_item) { | ||
| 47 | return; | ||
| 48 | } | ||
| 49 | Detach(item); | ||
| 50 | Attach(item); | ||
| 51 | } | ||
| 52 | |||
| 53 | void Free(size_t id) { | ||
| 54 | auto& item = item_pool[id]; | ||
| 55 | Detach(item); | ||
| 56 | item.prev = nullptr; | ||
| 57 | item.next = nullptr; | ||
| 58 | free_items.push_back(id); | ||
| 59 | } | ||
| 60 | |||
| 61 | template <typename Func> | ||
| 62 | void ForEachItemBelow(TickType tick, Func&& func) { | ||
| 63 | static constexpr bool RETURNS_BOOL = | ||
| 64 | std::is_same_v<std::invoke_result<Func, ObjectType>, bool>; | ||
| 65 | Item* iterator = first_item; | ||
| 66 | while (iterator) { | ||
| 67 | if (static_cast<s64>(tick) - static_cast<s64>(iterator->tick) < 0) { | ||
| 68 | return; | ||
| 69 | } | ||
| 70 | Item* next = iterator->next; | ||
| 71 | if constexpr (RETURNS_BOOL) { | ||
| 72 | if (func(iterator->obj)) { | ||
| 73 | return; | ||
| 74 | } | ||
| 75 | } else { | ||
| 76 | func(iterator->obj); | ||
| 77 | } | ||
| 78 | iterator = next; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | private: | ||
| 83 | size_t Build() { | ||
| 84 | if (free_items.empty()) { | ||
| 85 | const size_t item_id = item_pool.size(); | ||
| 86 | auto& item = item_pool.emplace_back(); | ||
| 87 | item.next = nullptr; | ||
| 88 | item.prev = nullptr; | ||
| 89 | return item_id; | ||
| 90 | } | ||
| 91 | const size_t item_id = free_items.front(); | ||
| 92 | free_items.pop_front(); | ||
| 93 | auto& item = item_pool[item_id]; | ||
| 94 | item.next = nullptr; | ||
| 95 | item.prev = nullptr; | ||
| 96 | return item_id; | ||
| 97 | } | ||
| 98 | |||
| 99 | void Attach(Item& item) { | ||
| 100 | if (!first_item) { | ||
| 101 | first_item = &item; | ||
| 102 | } | ||
| 103 | if (!last_item) { | ||
| 104 | last_item = &item; | ||
| 105 | } else { | ||
| 106 | item.prev = last_item; | ||
| 107 | last_item->next = &item; | ||
| 108 | item.next = nullptr; | ||
| 109 | last_item = &item; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | void Detach(Item& item) { | ||
| 114 | if (item.prev) { | ||
| 115 | item.prev->next = item.next; | ||
| 116 | } | ||
| 117 | if (item.next) { | ||
| 118 | item.next->prev = item.prev; | ||
| 119 | } | ||
| 120 | if (&item == first_item) { | ||
| 121 | first_item = item.next; | ||
| 122 | if (first_item) { | ||
| 123 | first_item->prev = nullptr; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | if (&item == last_item) { | ||
| 127 | last_item = item.prev; | ||
| 128 | if (last_item) { | ||
| 129 | last_item->next = nullptr; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | std::deque<Item> item_pool; | ||
| 135 | std::deque<size_t> free_items; | ||
| 136 | Item* first_item{}; | ||
| 137 | Item* last_item{}; | ||
| 138 | }; | ||
| 139 | |||
| 140 | } // namespace Common | ||
diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 33665eab8..0d2df80a8 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp | |||
| @@ -59,7 +59,6 @@ void LogSettings() { | |||
| 59 | log_setting("Renderer_UseVsync", values.use_vsync.GetValue()); | 59 | log_setting("Renderer_UseVsync", values.use_vsync.GetValue()); |
| 60 | log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue()); | 60 | log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue()); |
| 61 | log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); | 61 | log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); |
| 62 | log_setting("Renderer_UseGarbageCollection", values.use_caches_gc.GetValue()); | ||
| 63 | log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue()); | 62 | log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue()); |
| 64 | log_setting("Audio_OutputEngine", values.sink_id.GetValue()); | 63 | log_setting("Audio_OutputEngine", values.sink_id.GetValue()); |
| 65 | log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue()); | 64 | log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue()); |
| @@ -143,7 +142,6 @@ void RestoreGlobalState(bool is_powered_on) { | |||
| 143 | values.shader_backend.SetGlobal(true); | 142 | values.shader_backend.SetGlobal(true); |
| 144 | values.use_asynchronous_shaders.SetGlobal(true); | 143 | values.use_asynchronous_shaders.SetGlobal(true); |
| 145 | values.use_fast_gpu_time.SetGlobal(true); | 144 | values.use_fast_gpu_time.SetGlobal(true); |
| 146 | values.use_caches_gc.SetGlobal(true); | ||
| 147 | values.bg_red.SetGlobal(true); | 145 | values.bg_red.SetGlobal(true); |
| 148 | values.bg_green.SetGlobal(true); | 146 | values.bg_green.SetGlobal(true); |
| 149 | values.bg_blue.SetGlobal(true); | 147 | values.bg_blue.SetGlobal(true); |
diff --git a/src/common/settings.h b/src/common/settings.h index 28074c1b9..b7195670b 100644 --- a/src/common/settings.h +++ b/src/common/settings.h | |||
| @@ -481,7 +481,6 @@ struct Values { | |||
| 481 | ShaderBackend::SPIRV, "shader_backend"}; | 481 | ShaderBackend::SPIRV, "shader_backend"}; |
| 482 | Setting<bool> use_asynchronous_shaders{false, "use_asynchronous_shaders"}; | 482 | Setting<bool> use_asynchronous_shaders{false, "use_asynchronous_shaders"}; |
| 483 | Setting<bool> use_fast_gpu_time{true, "use_fast_gpu_time"}; | 483 | Setting<bool> use_fast_gpu_time{true, "use_fast_gpu_time"}; |
| 484 | Setting<bool> use_caches_gc{false, "use_caches_gc"}; | ||
| 485 | 484 | ||
| 486 | Setting<u8> bg_red{0, "bg_red"}; | 485 | Setting<u8> bg_red{0, "bg_red"}; |
| 487 | Setting<u8> bg_green{0, "bg_green"}; | 486 | Setting<u8> bg_green{0, "bg_green"}; |
| @@ -495,7 +494,7 @@ struct Values { | |||
| 495 | std::chrono::seconds custom_rtc_differential; | 494 | std::chrono::seconds custom_rtc_differential; |
| 496 | 495 | ||
| 497 | BasicSetting<s32> current_user{0, "current_user"}; | 496 | BasicSetting<s32> current_user{0, "current_user"}; |
| 498 | RangedSetting<s32> language_index{1, 0, 16, "language_index"}; | 497 | RangedSetting<s32> language_index{1, 0, 17, "language_index"}; |
| 499 | RangedSetting<s32> region_index{1, 0, 6, "region_index"}; | 498 | RangedSetting<s32> region_index{1, 0, 6, "region_index"}; |
| 500 | RangedSetting<s32> time_zone_index{0, 0, 45, "time_zone_index"}; | 499 | RangedSetting<s32> time_zone_index{0, 0, 45, "time_zone_index"}; |
| 501 | RangedSetting<s32> sound_index{1, 0, 2, "sound_index"}; | 500 | RangedSetting<s32> sound_index{1, 0, 2, "sound_index"}; |
| @@ -564,9 +563,10 @@ struct Values { | |||
| 564 | BasicSetting<std::string> log_filter{"*:Info", "log_filter"}; | 563 | BasicSetting<std::string> log_filter{"*:Info", "log_filter"}; |
| 565 | BasicSetting<bool> use_dev_keys{false, "use_dev_keys"}; | 564 | BasicSetting<bool> use_dev_keys{false, "use_dev_keys"}; |
| 566 | 565 | ||
| 567 | // Services | 566 | // Network |
| 568 | BasicSetting<std::string> bcat_backend{"none", "bcat_backend"}; | 567 | BasicSetting<std::string> bcat_backend{"none", "bcat_backend"}; |
| 569 | BasicSetting<bool> bcat_boxcat_local{false, "bcat_boxcat_local"}; | 568 | BasicSetting<bool> bcat_boxcat_local{false, "bcat_boxcat_local"}; |
| 569 | BasicSetting<std::string> network_interface{std::string(), "network_interface"}; | ||
| 570 | 570 | ||
| 571 | // WebService | 571 | // WebService |
| 572 | BasicSetting<bool> enable_telemetry{true, "enable_telemetry"}; | 572 | BasicSetting<bool> enable_telemetry{true, "enable_telemetry"}; |
diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h index ad04df8ca..8430b9778 100644 --- a/src/common/threadsafe_queue.h +++ b/src/common/threadsafe_queue.h | |||
| @@ -46,15 +46,13 @@ public: | |||
| 46 | ElementPtr* new_ptr = new ElementPtr(); | 46 | ElementPtr* new_ptr = new ElementPtr(); |
| 47 | write_ptr->next.store(new_ptr, std::memory_order_release); | 47 | write_ptr->next.store(new_ptr, std::memory_order_release); |
| 48 | write_ptr = new_ptr; | 48 | write_ptr = new_ptr; |
| 49 | ++size; | ||
| 49 | 50 | ||
| 50 | const size_t previous_size{size++}; | 51 | // cv_mutex must be held or else there will be a missed wakeup if the other thread is in the |
| 51 | 52 | // line before cv.wait | |
| 52 | // Acquire the mutex and then immediately release it as a fence. | ||
| 53 | // TODO(bunnei): This can be replaced with C++20 waitable atomics when properly supported. | 53 | // TODO(bunnei): This can be replaced with C++20 waitable atomics when properly supported. |
| 54 | // See discussion on https://github.com/yuzu-emu/yuzu/pull/3173 for details. | 54 | // See discussion on https://github.com/yuzu-emu/yuzu/pull/3173 for details. |
| 55 | if (previous_size == 0) { | 55 | std::lock_guard lock{cv_mutex}; |
| 56 | std::lock_guard lock{cv_mutex}; | ||
| 57 | } | ||
| 58 | cv.notify_one(); | 56 | cv.notify_one(); |
| 59 | } | 57 | } |
| 60 | 58 | ||
diff --git a/src/common/x64/xbyak_abi.h b/src/common/x64/xbyak_abi.h index c2c9b6134..0ddf9b83e 100644 --- a/src/common/x64/xbyak_abi.h +++ b/src/common/x64/xbyak_abi.h | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <bitset> | 7 | #include <bitset> |
| 8 | #include <initializer_list> | 8 | #include <initializer_list> |
| 9 | #include <xbyak.h> | 9 | #include <xbyak/xbyak.h> |
| 10 | #include "common/assert.h" | 10 | #include "common/assert.h" |
| 11 | 11 | ||
| 12 | namespace Common::X64 { | 12 | namespace Common::X64 { |
diff --git a/src/common/x64/xbyak_util.h b/src/common/x64/xbyak_util.h index df17f8cbe..44d2558f1 100644 --- a/src/common/x64/xbyak_util.h +++ b/src/common/x64/xbyak_util.h | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <type_traits> | 7 | #include <type_traits> |
| 8 | #include <xbyak.h> | 8 | #include <xbyak/xbyak.h> |
| 9 | #include "common/x64/xbyak_abi.h" | 9 | #include "common/x64/xbyak_abi.h" |
| 10 | 10 | ||
| 11 | namespace Common::X64 { | 11 | namespace Common::X64 { |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 5c99c00f5..87d47e2e5 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -452,6 +452,8 @@ add_library(core STATIC | |||
| 452 | hle/service/nfp/nfp.h | 452 | hle/service/nfp/nfp.h |
| 453 | hle/service/nfp/nfp_user.cpp | 453 | hle/service/nfp/nfp_user.cpp |
| 454 | hle/service/nfp/nfp_user.h | 454 | hle/service/nfp/nfp_user.h |
| 455 | hle/service/ngct/ngct.cpp | ||
| 456 | hle/service/ngct/ngct.h | ||
| 455 | hle/service/nifm/nifm.cpp | 457 | hle/service/nifm/nifm.cpp |
| 456 | hle/service/nifm/nifm.h | 458 | hle/service/nifm/nifm.h |
| 457 | hle/service/nim/nim.cpp | 459 | hle/service/nim/nim.cpp |
| @@ -636,6 +638,8 @@ add_library(core STATIC | |||
| 636 | memory.h | 638 | memory.h |
| 637 | network/network.cpp | 639 | network/network.cpp |
| 638 | network/network.h | 640 | network/network.h |
| 641 | network/network_interface.cpp | ||
| 642 | network/network_interface.h | ||
| 639 | network/sockets.h | 643 | network/sockets.h |
| 640 | perf_stats.cpp | 644 | perf_stats.cpp |
| 641 | perf_stats.h | 645 | perf_stats.h |
diff --git a/src/core/core.cpp b/src/core/core.cpp index d3e84c4ef..ba4629993 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <atomic> | 6 | #include <atomic> |
| 7 | #include <exception> | ||
| 7 | #include <memory> | 8 | #include <memory> |
| 8 | #include <utility> | 9 | #include <utility> |
| 9 | 10 | ||
| @@ -84,8 +85,6 @@ FileSys::StorageId GetStorageIdForFrontendSlot( | |||
| 84 | 85 | ||
| 85 | } // Anonymous namespace | 86 | } // Anonymous namespace |
| 86 | 87 | ||
| 87 | /*static*/ System System::s_instance; | ||
| 88 | |||
| 89 | FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, | 88 | FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, |
| 90 | const std::string& path) { | 89 | const std::string& path) { |
| 91 | // To account for split 00+01+etc files. | 90 | // To account for split 00+01+etc files. |
| @@ -425,6 +424,20 @@ struct System::Impl { | |||
| 425 | System::System() : impl{std::make_unique<Impl>(*this)} {} | 424 | System::System() : impl{std::make_unique<Impl>(*this)} {} |
| 426 | System::~System() = default; | 425 | System::~System() = default; |
| 427 | 426 | ||
| 427 | System& System::GetInstance() { | ||
| 428 | if (!s_instance) { | ||
| 429 | throw std::runtime_error("Using System instance before its initialization"); | ||
| 430 | } | ||
| 431 | return *s_instance; | ||
| 432 | } | ||
| 433 | |||
| 434 | void System::InitializeGlobalInstance() { | ||
| 435 | if (s_instance) { | ||
| 436 | throw std::runtime_error("Reinitializing Global System instance."); | ||
| 437 | } | ||
| 438 | s_instance = std::unique_ptr<System>(new System); | ||
| 439 | } | ||
| 440 | |||
| 428 | CpuManager& System::GetCpuManager() { | 441 | CpuManager& System::GetCpuManager() { |
| 429 | return impl->cpu_manager; | 442 | return impl->cpu_manager; |
| 430 | } | 443 | } |
diff --git a/src/core/core.h b/src/core/core.h index ea143043c..715ab88e7 100644 --- a/src/core/core.h +++ b/src/core/core.h | |||
| @@ -120,9 +120,9 @@ public: | |||
| 120 | * Gets the instance of the System singleton class. | 120 | * Gets the instance of the System singleton class. |
| 121 | * @returns Reference to the instance of the System singleton class. | 121 | * @returns Reference to the instance of the System singleton class. |
| 122 | */ | 122 | */ |
| 123 | [[deprecated("Use of the global system instance is deprecated")]] static System& GetInstance() { | 123 | [[deprecated("Use of the global system instance is deprecated")]] static System& GetInstance(); |
| 124 | return s_instance; | 124 | |
| 125 | } | 125 | static void InitializeGlobalInstance(); |
| 126 | 126 | ||
| 127 | /// Enumeration representing the return values of the System Initialize and Load process. | 127 | /// Enumeration representing the return values of the System Initialize and Load process. |
| 128 | enum class ResultStatus : u32 { | 128 | enum class ResultStatus : u32 { |
| @@ -396,7 +396,7 @@ private: | |||
| 396 | struct Impl; | 396 | struct Impl; |
| 397 | std::unique_ptr<Impl> impl; | 397 | std::unique_ptr<Impl> impl; |
| 398 | 398 | ||
| 399 | static System s_instance; | 399 | inline static std::unique_ptr<System> s_instance{}; |
| 400 | }; | 400 | }; |
| 401 | 401 | ||
| 402 | } // namespace Core | 402 | } // namespace Core |
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp index 7e195346b..77efcabf0 100644 --- a/src/core/cpu_manager.cpp +++ b/src/core/cpu_manager.cpp | |||
| @@ -21,34 +21,25 @@ namespace Core { | |||
| 21 | CpuManager::CpuManager(System& system_) : system{system_} {} | 21 | CpuManager::CpuManager(System& system_) : system{system_} {} |
| 22 | CpuManager::~CpuManager() = default; | 22 | CpuManager::~CpuManager() = default; |
| 23 | 23 | ||
| 24 | void CpuManager::ThreadStart(CpuManager& cpu_manager, std::size_t core) { | 24 | void CpuManager::ThreadStart(std::stop_token stop_token, CpuManager& cpu_manager, |
| 25 | cpu_manager.RunThread(core); | 25 | std::size_t core) { |
| 26 | cpu_manager.RunThread(stop_token, core); | ||
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | void CpuManager::Initialize() { | 29 | void CpuManager::Initialize() { |
| 29 | running_mode = true; | 30 | running_mode = true; |
| 30 | if (is_multicore) { | 31 | if (is_multicore) { |
| 31 | for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { | 32 | for (std::size_t core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { |
| 32 | core_data[core].host_thread = | 33 | core_data[core].host_thread = std::jthread(ThreadStart, std::ref(*this), core); |
| 33 | std::make_unique<std::thread>(ThreadStart, std::ref(*this), core); | ||
| 34 | } | 34 | } |
| 35 | } else { | 35 | } else { |
| 36 | core_data[0].host_thread = std::make_unique<std::thread>(ThreadStart, std::ref(*this), 0); | 36 | core_data[0].host_thread = std::jthread(ThreadStart, std::ref(*this), 0); |
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | void CpuManager::Shutdown() { | 40 | void CpuManager::Shutdown() { |
| 41 | running_mode = false; | 41 | running_mode = false; |
| 42 | Pause(false); | 42 | Pause(false); |
| 43 | if (is_multicore) { | ||
| 44 | for (auto& data : core_data) { | ||
| 45 | data.host_thread->join(); | ||
| 46 | data.host_thread.reset(); | ||
| 47 | } | ||
| 48 | } else { | ||
| 49 | core_data[0].host_thread->join(); | ||
| 50 | core_data[0].host_thread.reset(); | ||
| 51 | } | ||
| 52 | } | 43 | } |
| 53 | 44 | ||
| 54 | std::function<void(void*)> CpuManager::GetGuestThreadStartFunc() { | 45 | std::function<void(void*)> CpuManager::GetGuestThreadStartFunc() { |
| @@ -317,7 +308,7 @@ void CpuManager::Pause(bool paused) { | |||
| 317 | } | 308 | } |
| 318 | } | 309 | } |
| 319 | 310 | ||
| 320 | void CpuManager::RunThread(std::size_t core) { | 311 | void CpuManager::RunThread(std::stop_token stop_token, std::size_t core) { |
| 321 | /// Initialization | 312 | /// Initialization |
| 322 | system.RegisterCoreThread(core); | 313 | system.RegisterCoreThread(core); |
| 323 | std::string name; | 314 | std::string name; |
| @@ -361,6 +352,10 @@ void CpuManager::RunThread(std::size_t core) { | |||
| 361 | return; | 352 | return; |
| 362 | } | 353 | } |
| 363 | 354 | ||
| 355 | if (stop_token.stop_requested()) { | ||
| 356 | break; | ||
| 357 | } | ||
| 358 | |||
| 364 | auto current_thread = system.Kernel().CurrentScheduler()->GetCurrentThread(); | 359 | auto current_thread = system.Kernel().CurrentScheduler()->GetCurrentThread(); |
| 365 | data.is_running = true; | 360 | data.is_running = true; |
| 366 | Common::Fiber::YieldTo(data.host_context, *current_thread->GetHostContext()); | 361 | Common::Fiber::YieldTo(data.host_context, *current_thread->GetHostContext()); |
diff --git a/src/core/cpu_manager.h b/src/core/cpu_manager.h index 140263b09..9d92d4af0 100644 --- a/src/core/cpu_manager.h +++ b/src/core/cpu_manager.h | |||
| @@ -78,9 +78,9 @@ private: | |||
| 78 | void SingleCoreRunSuspendThread(); | 78 | void SingleCoreRunSuspendThread(); |
| 79 | void SingleCorePause(bool paused); | 79 | void SingleCorePause(bool paused); |
| 80 | 80 | ||
| 81 | static void ThreadStart(CpuManager& cpu_manager, std::size_t core); | 81 | static void ThreadStart(std::stop_token stop_token, CpuManager& cpu_manager, std::size_t core); |
| 82 | 82 | ||
| 83 | void RunThread(std::size_t core); | 83 | void RunThread(std::stop_token stop_token, std::size_t core); |
| 84 | 84 | ||
| 85 | struct CoreData { | 85 | struct CoreData { |
| 86 | std::shared_ptr<Common::Fiber> host_context; | 86 | std::shared_ptr<Common::Fiber> host_context; |
| @@ -89,7 +89,7 @@ private: | |||
| 89 | std::atomic<bool> is_running; | 89 | std::atomic<bool> is_running; |
| 90 | std::atomic<bool> is_paused; | 90 | std::atomic<bool> is_paused; |
| 91 | std::atomic<bool> initialized; | 91 | std::atomic<bool> initialized; |
| 92 | std::unique_ptr<std::thread> host_thread; | 92 | std::jthread host_thread; |
| 93 | }; | 93 | }; |
| 94 | 94 | ||
| 95 | std::atomic<bool> running_mode{}; | 95 | std::atomic<bool> running_mode{}; |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 92fbc5532..bea945301 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -267,20 +267,23 @@ struct KernelCore::Impl { | |||
| 267 | } | 267 | } |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | /// Creates a new host thread ID, should only be called by GetHostThreadId | 270 | static inline thread_local u32 host_thread_id = UINT32_MAX; |
| 271 | u32 AllocateHostThreadId(std::optional<std::size_t> core_id) { | 271 | |
| 272 | if (core_id) { | 272 | /// Gets the host thread ID for the caller, allocating a new one if this is the first time |
| 273 | // The first for slots are reserved for CPU core threads | 273 | u32 GetHostThreadId(std::size_t core_id) { |
| 274 | ASSERT(*core_id < Core::Hardware::NUM_CPU_CORES); | 274 | if (host_thread_id == UINT32_MAX) { |
| 275 | return static_cast<u32>(*core_id); | 275 | // The first four slots are reserved for CPU core threads |
| 276 | } else { | 276 | ASSERT(core_id < Core::Hardware::NUM_CPU_CORES); |
| 277 | return next_host_thread_id++; | 277 | host_thread_id = static_cast<u32>(core_id); |
| 278 | } | 278 | } |
| 279 | return host_thread_id; | ||
| 279 | } | 280 | } |
| 280 | 281 | ||
| 281 | /// Gets the host thread ID for the caller, allocating a new one if this is the first time | 282 | /// Gets the host thread ID for the caller, allocating a new one if this is the first time |
| 282 | u32 GetHostThreadId(std::optional<std::size_t> core_id = std::nullopt) { | 283 | u32 GetHostThreadId() { |
| 283 | const thread_local auto host_thread_id{AllocateHostThreadId(core_id)}; | 284 | if (host_thread_id == UINT32_MAX) { |
| 285 | host_thread_id = next_host_thread_id++; | ||
| 286 | } | ||
| 284 | return host_thread_id; | 287 | return host_thread_id; |
| 285 | } | 288 | } |
| 286 | 289 | ||
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 2eb532472..62fb06c45 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -1078,8 +1078,8 @@ static ResultCode GetThreadContext(Core::System& system, VAddr out_context, Hand | |||
| 1078 | for (auto i = 0; i < static_cast<s32>(Core::Hardware::NUM_CPU_CORES); ++i) { | 1078 | for (auto i = 0; i < static_cast<s32>(Core::Hardware::NUM_CPU_CORES); ++i) { |
| 1079 | if (thread.GetPointerUnsafe() == kernel.Scheduler(i).GetCurrentThread()) { | 1079 | if (thread.GetPointerUnsafe() == kernel.Scheduler(i).GetCurrentThread()) { |
| 1080 | current = true; | 1080 | current = true; |
| 1081 | break; | ||
| 1081 | } | 1082 | } |
| 1082 | break; | ||
| 1083 | } | 1083 | } |
| 1084 | 1084 | ||
| 1085 | // If the thread is current, retry until it isn't. | 1085 | // If the thread is current, retry until it isn't. |
diff --git a/src/core/hle/service/am/applets/applet_error.cpp b/src/core/hle/service/am/applets/applet_error.cpp index ef6854d62..36a4aa9cd 100644 --- a/src/core/hle/service/am/applets/applet_error.cpp +++ b/src/core/hle/service/am/applets/applet_error.cpp | |||
| @@ -16,6 +16,30 @@ | |||
| 16 | 16 | ||
| 17 | namespace Service::AM::Applets { | 17 | namespace Service::AM::Applets { |
| 18 | 18 | ||
| 19 | struct ErrorCode { | ||
| 20 | u32 error_category{}; | ||
| 21 | u32 error_number{}; | ||
| 22 | |||
| 23 | static constexpr ErrorCode FromU64(u64 error_code) { | ||
| 24 | return { | ||
| 25 | .error_category{static_cast<u32>(error_code >> 32)}, | ||
| 26 | .error_number{static_cast<u32>(error_code & 0xFFFFFFFF)}, | ||
| 27 | }; | ||
| 28 | } | ||
| 29 | |||
| 30 | static constexpr ErrorCode FromResultCode(ResultCode result) { | ||
| 31 | return { | ||
| 32 | .error_category{2000 + static_cast<u32>(result.module.Value())}, | ||
| 33 | .error_number{result.description.Value()}, | ||
| 34 | }; | ||
| 35 | } | ||
| 36 | |||
| 37 | constexpr ResultCode ToResultCode() const { | ||
| 38 | return ResultCode{static_cast<ErrorModule>(error_category - 2000), error_number}; | ||
| 39 | } | ||
| 40 | }; | ||
| 41 | static_assert(sizeof(ErrorCode) == 0x8, "ErrorCode has incorrect size."); | ||
| 42 | |||
| 19 | #pragma pack(push, 4) | 43 | #pragma pack(push, 4) |
| 20 | struct ShowError { | 44 | struct ShowError { |
| 21 | u8 mode; | 45 | u8 mode; |
| @@ -76,12 +100,7 @@ void CopyArgumentData(const std::vector<u8>& data, T& variable) { | |||
| 76 | } | 100 | } |
| 77 | 101 | ||
| 78 | ResultCode Decode64BitError(u64 error) { | 102 | ResultCode Decode64BitError(u64 error) { |
| 79 | const auto description = (error >> 32) & 0x1FFF; | 103 | return ErrorCode::FromU64(error).ToResultCode(); |
| 80 | auto module = error & 0x3FF; | ||
| 81 | if (module >= 2000) | ||
| 82 | module -= 2000; | ||
| 83 | module &= 0x1FF; | ||
| 84 | return {static_cast<ErrorModule>(module), static_cast<u32>(description)}; | ||
| 85 | } | 104 | } |
| 86 | 105 | ||
| 87 | } // Anonymous namespace | 106 | } // Anonymous namespace |
diff --git a/src/core/hle/service/ngct/ngct.cpp b/src/core/hle/service/ngct/ngct.cpp new file mode 100644 index 000000000..deb3abb28 --- /dev/null +++ b/src/core/hle/service/ngct/ngct.cpp | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included | ||
| 4 | |||
| 5 | #include "common/string_util.h" | ||
| 6 | #include "core/core.h" | ||
| 7 | #include "core/hle/ipc_helpers.h" | ||
| 8 | #include "core/hle/service/ngct/ngct.h" | ||
| 9 | #include "core/hle/service/service.h" | ||
| 10 | |||
| 11 | namespace Service::NGCT { | ||
| 12 | |||
| 13 | class IService final : public ServiceFramework<IService> { | ||
| 14 | public: | ||
| 15 | explicit IService(Core::System& system_) : ServiceFramework{system_, "ngct:u"} { | ||
| 16 | // clang-format off | ||
| 17 | static const FunctionInfo functions[] = { | ||
| 18 | {0, nullptr, "Match"}, | ||
| 19 | {1, &IService::Filter, "Filter"}, | ||
| 20 | }; | ||
| 21 | // clang-format on | ||
| 22 | |||
| 23 | RegisterHandlers(functions); | ||
| 24 | } | ||
| 25 | |||
| 26 | private: | ||
| 27 | void Filter(Kernel::HLERequestContext& ctx) { | ||
| 28 | const auto buffer = ctx.ReadBuffer(); | ||
| 29 | const auto text = Common::StringFromFixedZeroTerminatedBuffer( | ||
| 30 | reinterpret_cast<const char*>(buffer.data()), buffer.size()); | ||
| 31 | |||
| 32 | LOG_WARNING(Service_NGCT, "(STUBBED) called, text={}", text); | ||
| 33 | |||
| 34 | // Return the same string since we don't censor anything | ||
| 35 | ctx.WriteBuffer(buffer); | ||
| 36 | |||
| 37 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 38 | rb.Push(ResultSuccess); | ||
| 39 | } | ||
| 40 | }; | ||
| 41 | |||
| 42 | void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system) { | ||
| 43 | std::make_shared<IService>(system)->InstallAsService(system.ServiceManager()); | ||
| 44 | } | ||
| 45 | |||
| 46 | } // namespace Service::NGCT | ||
diff --git a/src/core/hle/service/ngct/ngct.h b/src/core/hle/service/ngct/ngct.h new file mode 100644 index 000000000..1f2a47b78 --- /dev/null +++ b/src/core/hle/service/ngct/ngct.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | namespace Core { | ||
| 8 | class System; | ||
| 9 | } | ||
| 10 | |||
| 11 | namespace Service::SM { | ||
| 12 | class ServiceManager; | ||
| 13 | } | ||
| 14 | |||
| 15 | namespace Service::NGCT { | ||
| 16 | |||
| 17 | /// Registers all NGCT services with the specified service manager. | ||
| 18 | void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system); | ||
| 19 | |||
| 20 | } // namespace Service::NGCT | ||
diff --git a/src/core/hle/service/nifm/nifm.cpp b/src/core/hle/service/nifm/nifm.cpp index e742db48f..9decb9290 100644 --- a/src/core/hle/service/nifm/nifm.cpp +++ b/src/core/hle/service/nifm/nifm.cpp | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include "core/hle/service/nifm/nifm.h" | 11 | #include "core/hle/service/nifm/nifm.h" |
| 12 | #include "core/hle/service/service.h" | 12 | #include "core/hle/service/service.h" |
| 13 | #include "core/network/network.h" | 13 | #include "core/network/network.h" |
| 14 | #include "core/network/network_interface.h" | ||
| 14 | 15 | ||
| 15 | namespace Service::NIFM { | 16 | namespace Service::NIFM { |
| 16 | 17 | ||
| @@ -179,10 +180,10 @@ private: | |||
| 179 | IPC::ResponseBuilder rb{ctx, 3}; | 180 | IPC::ResponseBuilder rb{ctx, 3}; |
| 180 | rb.Push(ResultSuccess); | 181 | rb.Push(ResultSuccess); |
| 181 | 182 | ||
| 182 | if (Settings::values.bcat_backend.GetValue() == "none") { | 183 | if (Network::GetHostIPv4Address().has_value()) { |
| 183 | rb.PushEnum(RequestState::NotSubmitted); | ||
| 184 | } else { | ||
| 185 | rb.PushEnum(RequestState::Connected); | 184 | rb.PushEnum(RequestState::Connected); |
| 185 | } else { | ||
| 186 | rb.PushEnum(RequestState::NotSubmitted); | ||
| 186 | } | 187 | } |
| 187 | } | 188 | } |
| 188 | 189 | ||
| @@ -276,37 +277,45 @@ private: | |||
| 276 | void GetCurrentNetworkProfile(Kernel::HLERequestContext& ctx) { | 277 | void GetCurrentNetworkProfile(Kernel::HLERequestContext& ctx) { |
| 277 | LOG_WARNING(Service_NIFM, "(STUBBED) called"); | 278 | LOG_WARNING(Service_NIFM, "(STUBBED) called"); |
| 278 | 279 | ||
| 279 | const SfNetworkProfileData network_profile_data{ | 280 | const auto net_iface = Network::GetSelectedNetworkInterface(); |
| 280 | .ip_setting_data{ | 281 | |
| 281 | .ip_address_setting{ | 282 | const SfNetworkProfileData network_profile_data = [&net_iface] { |
| 282 | .is_automatic{true}, | 283 | if (!net_iface) { |
| 283 | .current_address{192, 168, 1, 100}, | 284 | return SfNetworkProfileData{}; |
| 284 | .subnet_mask{255, 255, 255, 0}, | 285 | } |
| 285 | .gateway{192, 168, 1, 1}, | 286 | |
| 286 | }, | 287 | return SfNetworkProfileData{ |
| 287 | .dns_setting{ | 288 | .ip_setting_data{ |
| 288 | .is_automatic{true}, | 289 | .ip_address_setting{ |
| 289 | .primary_dns{1, 1, 1, 1}, | 290 | .is_automatic{true}, |
| 290 | .secondary_dns{1, 0, 0, 1}, | 291 | .current_address{Network::TranslateIPv4(net_iface->ip_address)}, |
| 292 | .subnet_mask{Network::TranslateIPv4(net_iface->subnet_mask)}, | ||
| 293 | .gateway{Network::TranslateIPv4(net_iface->gateway)}, | ||
| 294 | }, | ||
| 295 | .dns_setting{ | ||
| 296 | .is_automatic{true}, | ||
| 297 | .primary_dns{1, 1, 1, 1}, | ||
| 298 | .secondary_dns{1, 0, 0, 1}, | ||
| 299 | }, | ||
| 300 | .proxy_setting{ | ||
| 301 | .enabled{false}, | ||
| 302 | .port{}, | ||
| 303 | .proxy_server{}, | ||
| 304 | .automatic_auth_enabled{}, | ||
| 305 | .user{}, | ||
| 306 | .password{}, | ||
| 307 | }, | ||
| 308 | .mtu{1500}, | ||
| 291 | }, | 309 | }, |
| 292 | .proxy_setting{ | 310 | .uuid{0xdeadbeef, 0xdeadbeef}, |
| 293 | .enabled{false}, | 311 | .network_name{"yuzu Network"}, |
| 294 | .port{}, | 312 | .wireless_setting_data{ |
| 295 | .proxy_server{}, | 313 | .ssid_length{12}, |
| 296 | .automatic_auth_enabled{}, | 314 | .ssid{"yuzu Network"}, |
| 297 | .user{}, | 315 | .passphrase{"yuzupassword"}, |
| 298 | .password{}, | ||
| 299 | }, | 316 | }, |
| 300 | .mtu{1500}, | 317 | }; |
| 301 | }, | 318 | }(); |
| 302 | .uuid{0xdeadbeef, 0xdeadbeef}, | ||
| 303 | .network_name{"yuzu Network"}, | ||
| 304 | .wireless_setting_data{ | ||
| 305 | .ssid_length{12}, | ||
| 306 | .ssid{"yuzu Network"}, | ||
| 307 | .passphrase{"yuzupassword"}, | ||
| 308 | }, | ||
| 309 | }; | ||
| 310 | 319 | ||
| 311 | ctx.WriteBuffer(network_profile_data); | 320 | ctx.WriteBuffer(network_profile_data); |
| 312 | 321 | ||
| @@ -322,12 +331,15 @@ private: | |||
| 322 | void GetCurrentIpAddress(Kernel::HLERequestContext& ctx) { | 331 | void GetCurrentIpAddress(Kernel::HLERequestContext& ctx) { |
| 323 | LOG_WARNING(Service_NIFM, "(STUBBED) called"); | 332 | LOG_WARNING(Service_NIFM, "(STUBBED) called"); |
| 324 | 333 | ||
| 325 | const auto [ipv4, error] = Network::GetHostIPv4Address(); | 334 | auto ipv4 = Network::GetHostIPv4Address(); |
| 326 | UNIMPLEMENTED_IF(error != Network::Errno::SUCCESS); | 335 | if (!ipv4) { |
| 336 | LOG_ERROR(Service_NIFM, "Couldn't get host IPv4 address, defaulting to 0.0.0.0"); | ||
| 337 | ipv4.emplace(Network::IPv4Address{0, 0, 0, 0}); | ||
| 338 | } | ||
| 327 | 339 | ||
| 328 | IPC::ResponseBuilder rb{ctx, 3}; | 340 | IPC::ResponseBuilder rb{ctx, 3}; |
| 329 | rb.Push(ResultSuccess); | 341 | rb.Push(ResultSuccess); |
| 330 | rb.PushRaw(ipv4); | 342 | rb.PushRaw(*ipv4); |
| 331 | } | 343 | } |
| 332 | void CreateTemporaryNetworkProfile(Kernel::HLERequestContext& ctx) { | 344 | void CreateTemporaryNetworkProfile(Kernel::HLERequestContext& ctx) { |
| 333 | LOG_DEBUG(Service_NIFM, "called"); | 345 | LOG_DEBUG(Service_NIFM, "called"); |
| @@ -348,25 +360,33 @@ private: | |||
| 348 | LOG_WARNING(Service_NIFM, "(STUBBED) called"); | 360 | LOG_WARNING(Service_NIFM, "(STUBBED) called"); |
| 349 | 361 | ||
| 350 | struct IpConfigInfo { | 362 | struct IpConfigInfo { |
| 351 | IpAddressSetting ip_address_setting; | 363 | IpAddressSetting ip_address_setting{}; |
| 352 | DnsSetting dns_setting; | 364 | DnsSetting dns_setting{}; |
| 353 | }; | 365 | }; |
| 354 | static_assert(sizeof(IpConfigInfo) == sizeof(IpAddressSetting) + sizeof(DnsSetting), | 366 | static_assert(sizeof(IpConfigInfo) == sizeof(IpAddressSetting) + sizeof(DnsSetting), |
| 355 | "IpConfigInfo has incorrect size."); | 367 | "IpConfigInfo has incorrect size."); |
| 356 | 368 | ||
| 357 | const IpConfigInfo ip_config_info{ | 369 | const auto net_iface = Network::GetSelectedNetworkInterface(); |
| 358 | .ip_address_setting{ | 370 | |
| 359 | .is_automatic{true}, | 371 | const IpConfigInfo ip_config_info = [&net_iface] { |
| 360 | .current_address{192, 168, 1, 100}, | 372 | if (!net_iface) { |
| 361 | .subnet_mask{255, 255, 255, 0}, | 373 | return IpConfigInfo{}; |
| 362 | .gateway{192, 168, 1, 1}, | 374 | } |
| 363 | }, | 375 | |
| 364 | .dns_setting{ | 376 | return IpConfigInfo{ |
| 365 | .is_automatic{true}, | 377 | .ip_address_setting{ |
| 366 | .primary_dns{1, 1, 1, 1}, | 378 | .is_automatic{true}, |
| 367 | .secondary_dns{1, 0, 0, 1}, | 379 | .current_address{Network::TranslateIPv4(net_iface->ip_address)}, |
| 368 | }, | 380 | .subnet_mask{Network::TranslateIPv4(net_iface->subnet_mask)}, |
| 369 | }; | 381 | .gateway{Network::TranslateIPv4(net_iface->gateway)}, |
| 382 | }, | ||
| 383 | .dns_setting{ | ||
| 384 | .is_automatic{true}, | ||
| 385 | .primary_dns{1, 1, 1, 1}, | ||
| 386 | .secondary_dns{1, 0, 0, 1}, | ||
| 387 | }, | ||
| 388 | }; | ||
| 389 | }(); | ||
| 370 | 390 | ||
| 371 | IPC::ResponseBuilder rb{ctx, 2 + (sizeof(IpConfigInfo) + 3) / sizeof(u32)}; | 391 | IPC::ResponseBuilder rb{ctx, 2 + (sizeof(IpConfigInfo) + 3) / sizeof(u32)}; |
| 372 | rb.Push(ResultSuccess); | 392 | rb.Push(ResultSuccess); |
| @@ -384,10 +404,10 @@ private: | |||
| 384 | 404 | ||
| 385 | IPC::ResponseBuilder rb{ctx, 3}; | 405 | IPC::ResponseBuilder rb{ctx, 3}; |
| 386 | rb.Push(ResultSuccess); | 406 | rb.Push(ResultSuccess); |
| 387 | if (Settings::values.bcat_backend.GetValue() == "none") { | 407 | if (Network::GetHostIPv4Address().has_value()) { |
| 388 | rb.Push<u8>(0); | ||
| 389 | } else { | ||
| 390 | rb.Push<u8>(1); | 408 | rb.Push<u8>(1); |
| 409 | } else { | ||
| 410 | rb.Push<u8>(0); | ||
| 391 | } | 411 | } |
| 392 | } | 412 | } |
| 393 | void IsAnyInternetRequestAccepted(Kernel::HLERequestContext& ctx) { | 413 | void IsAnyInternetRequestAccepted(Kernel::HLERequestContext& ctx) { |
| @@ -395,10 +415,10 @@ private: | |||
| 395 | 415 | ||
| 396 | IPC::ResponseBuilder rb{ctx, 3}; | 416 | IPC::ResponseBuilder rb{ctx, 3}; |
| 397 | rb.Push(ResultSuccess); | 417 | rb.Push(ResultSuccess); |
| 398 | if (Settings::values.bcat_backend.GetValue() == "none") { | 418 | if (Network::GetHostIPv4Address().has_value()) { |
| 399 | rb.Push<u8>(0); | ||
| 400 | } else { | ||
| 401 | rb.Push<u8>(1); | 419 | rb.Push<u8>(1); |
| 420 | } else { | ||
| 421 | rb.Push<u8>(0); | ||
| 402 | } | 422 | } |
| 403 | } | 423 | } |
| 404 | }; | 424 | }; |
diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp index ce6065db2..a33e47d0b 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp | |||
| @@ -42,15 +42,14 @@ void nvdisp_disp0::OnClose(DeviceFD fd) {} | |||
| 42 | void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u32 height, | 42 | void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u32 height, |
| 43 | u32 stride, NVFlinger::BufferQueue::BufferTransformFlags transform, | 43 | u32 stride, NVFlinger::BufferQueue::BufferTransformFlags transform, |
| 44 | const Common::Rectangle<int>& crop_rect) { | 44 | const Common::Rectangle<int>& crop_rect) { |
| 45 | VAddr addr = nvmap_dev->GetObjectAddress(buffer_handle); | 45 | const VAddr addr = nvmap_dev->GetObjectAddress(buffer_handle); |
| 46 | LOG_TRACE(Service, | 46 | LOG_TRACE(Service, |
| 47 | "Drawing from address {:X} offset {:08X} Width {} Height {} Stride {} Format {}", | 47 | "Drawing from address {:X} offset {:08X} Width {} Height {} Stride {} Format {}", |
| 48 | addr, offset, width, height, stride, format); | 48 | addr, offset, width, height, stride, format); |
| 49 | 49 | ||
| 50 | using PixelFormat = Tegra::FramebufferConfig::PixelFormat; | 50 | const auto pixel_format = static_cast<Tegra::FramebufferConfig::PixelFormat>(format); |
| 51 | const Tegra::FramebufferConfig framebuffer{ | 51 | const Tegra::FramebufferConfig framebuffer{addr, offset, width, height, |
| 52 | addr, offset, width, height, stride, static_cast<PixelFormat>(format), | 52 | stride, pixel_format, transform, crop_rect}; |
| 53 | transform, crop_rect}; | ||
| 54 | 53 | ||
| 55 | system.GetPerfStats().EndSystemFrame(); | 54 | system.GetPerfStats().EndSystemFrame(); |
| 56 | system.GPU().SwapBuffers(&framebuffer); | 55 | system.GPU().SwapBuffers(&framebuffer); |
diff --git a/src/core/hle/service/nvflinger/buffer_queue.cpp b/src/core/hle/service/nvflinger/buffer_queue.cpp index 59ddf6298..b4c3a6099 100644 --- a/src/core/hle/service/nvflinger/buffer_queue.cpp +++ b/src/core/hle/service/nvflinger/buffer_queue.cpp | |||
| @@ -9,17 +9,20 @@ | |||
| 9 | #include "core/core.h" | 9 | #include "core/core.h" |
| 10 | #include "core/hle/kernel/k_writable_event.h" | 10 | #include "core/hle/kernel/k_writable_event.h" |
| 11 | #include "core/hle/kernel/kernel.h" | 11 | #include "core/hle/kernel/kernel.h" |
| 12 | #include "core/hle/service/kernel_helpers.h" | ||
| 12 | #include "core/hle/service/nvflinger/buffer_queue.h" | 13 | #include "core/hle/service/nvflinger/buffer_queue.h" |
| 13 | 14 | ||
| 14 | namespace Service::NVFlinger { | 15 | namespace Service::NVFlinger { |
| 15 | 16 | ||
| 16 | BufferQueue::BufferQueue(Kernel::KernelCore& kernel, u32 id_, u64 layer_id_) | 17 | BufferQueue::BufferQueue(Kernel::KernelCore& kernel, u32 id_, u64 layer_id_, |
| 17 | : id(id_), layer_id(layer_id_), buffer_wait_event{kernel} { | 18 | KernelHelpers::ServiceContext& service_context_) |
| 18 | Kernel::KAutoObject::Create(std::addressof(buffer_wait_event)); | 19 | : id(id_), layer_id(layer_id_), service_context{service_context_} { |
| 19 | buffer_wait_event.Initialize("BufferQueue:WaitEvent"); | 20 | buffer_wait_event = service_context.CreateEvent("BufferQueue:WaitEvent"); |
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | BufferQueue::~BufferQueue() = default; | 23 | BufferQueue::~BufferQueue() { |
| 24 | service_context.CloseEvent(buffer_wait_event); | ||
| 25 | } | ||
| 23 | 26 | ||
| 24 | void BufferQueue::SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer) { | 27 | void BufferQueue::SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer) { |
| 25 | ASSERT(slot < buffer_slots); | 28 | ASSERT(slot < buffer_slots); |
| @@ -41,7 +44,7 @@ void BufferQueue::SetPreallocatedBuffer(u32 slot, const IGBPBuffer& igbp_buffer) | |||
| 41 | .multi_fence = {}, | 44 | .multi_fence = {}, |
| 42 | }; | 45 | }; |
| 43 | 46 | ||
| 44 | buffer_wait_event.GetWritableEvent().Signal(); | 47 | buffer_wait_event->GetWritableEvent().Signal(); |
| 45 | } | 48 | } |
| 46 | 49 | ||
| 47 | std::optional<std::pair<u32, Service::Nvidia::MultiFence*>> BufferQueue::DequeueBuffer(u32 width, | 50 | std::optional<std::pair<u32, Service::Nvidia::MultiFence*>> BufferQueue::DequeueBuffer(u32 width, |
| @@ -119,7 +122,7 @@ void BufferQueue::CancelBuffer(u32 slot, const Service::Nvidia::MultiFence& mult | |||
| 119 | } | 122 | } |
| 120 | free_buffers_condition.notify_one(); | 123 | free_buffers_condition.notify_one(); |
| 121 | 124 | ||
| 122 | buffer_wait_event.GetWritableEvent().Signal(); | 125 | buffer_wait_event->GetWritableEvent().Signal(); |
| 123 | } | 126 | } |
| 124 | 127 | ||
| 125 | std::optional<std::reference_wrapper<const BufferQueue::Buffer>> BufferQueue::AcquireBuffer() { | 128 | std::optional<std::reference_wrapper<const BufferQueue::Buffer>> BufferQueue::AcquireBuffer() { |
| @@ -154,7 +157,7 @@ void BufferQueue::ReleaseBuffer(u32 slot) { | |||
| 154 | } | 157 | } |
| 155 | free_buffers_condition.notify_one(); | 158 | free_buffers_condition.notify_one(); |
| 156 | 159 | ||
| 157 | buffer_wait_event.GetWritableEvent().Signal(); | 160 | buffer_wait_event->GetWritableEvent().Signal(); |
| 158 | } | 161 | } |
| 159 | 162 | ||
| 160 | void BufferQueue::Connect() { | 163 | void BufferQueue::Connect() { |
| @@ -169,7 +172,7 @@ void BufferQueue::Disconnect() { | |||
| 169 | std::unique_lock lock{queue_sequence_mutex}; | 172 | std::unique_lock lock{queue_sequence_mutex}; |
| 170 | queue_sequence.clear(); | 173 | queue_sequence.clear(); |
| 171 | } | 174 | } |
| 172 | buffer_wait_event.GetWritableEvent().Signal(); | 175 | buffer_wait_event->GetWritableEvent().Signal(); |
| 173 | is_connect = false; | 176 | is_connect = false; |
| 174 | free_buffers_condition.notify_one(); | 177 | free_buffers_condition.notify_one(); |
| 175 | } | 178 | } |
| @@ -189,11 +192,11 @@ u32 BufferQueue::Query(QueryType type) { | |||
| 189 | } | 192 | } |
| 190 | 193 | ||
| 191 | Kernel::KWritableEvent& BufferQueue::GetWritableBufferWaitEvent() { | 194 | Kernel::KWritableEvent& BufferQueue::GetWritableBufferWaitEvent() { |
| 192 | return buffer_wait_event.GetWritableEvent(); | 195 | return buffer_wait_event->GetWritableEvent(); |
| 193 | } | 196 | } |
| 194 | 197 | ||
| 195 | Kernel::KReadableEvent& BufferQueue::GetBufferWaitEvent() { | 198 | Kernel::KReadableEvent& BufferQueue::GetBufferWaitEvent() { |
| 196 | return buffer_wait_event.GetReadableEvent(); | 199 | return buffer_wait_event->GetReadableEvent(); |
| 197 | } | 200 | } |
| 198 | 201 | ||
| 199 | } // namespace Service::NVFlinger | 202 | } // namespace Service::NVFlinger |
diff --git a/src/core/hle/service/nvflinger/buffer_queue.h b/src/core/hle/service/nvflinger/buffer_queue.h index 61e337ac5..78de3f354 100644 --- a/src/core/hle/service/nvflinger/buffer_queue.h +++ b/src/core/hle/service/nvflinger/buffer_queue.h | |||
| @@ -24,6 +24,10 @@ class KReadableEvent; | |||
| 24 | class KWritableEvent; | 24 | class KWritableEvent; |
| 25 | } // namespace Kernel | 25 | } // namespace Kernel |
| 26 | 26 | ||
| 27 | namespace Service::KernelHelpers { | ||
| 28 | class ServiceContext; | ||
| 29 | } // namespace Service::KernelHelpers | ||
| 30 | |||
| 27 | namespace Service::NVFlinger { | 31 | namespace Service::NVFlinger { |
| 28 | 32 | ||
| 29 | constexpr u32 buffer_slots = 0x40; | 33 | constexpr u32 buffer_slots = 0x40; |
| @@ -38,7 +42,9 @@ struct IGBPBuffer { | |||
| 38 | u32_le index; | 42 | u32_le index; |
| 39 | INSERT_PADDING_WORDS(3); | 43 | INSERT_PADDING_WORDS(3); |
| 40 | u32_le gpu_buffer_id; | 44 | u32_le gpu_buffer_id; |
| 41 | INSERT_PADDING_WORDS(17); | 45 | INSERT_PADDING_WORDS(6); |
| 46 | u32_le external_format; | ||
| 47 | INSERT_PADDING_WORDS(10); | ||
| 42 | u32_le nvmap_handle; | 48 | u32_le nvmap_handle; |
| 43 | u32_le offset; | 49 | u32_le offset; |
| 44 | INSERT_PADDING_WORDS(60); | 50 | INSERT_PADDING_WORDS(60); |
| @@ -54,7 +60,8 @@ public: | |||
| 54 | NativeWindowFormat = 2, | 60 | NativeWindowFormat = 2, |
| 55 | }; | 61 | }; |
| 56 | 62 | ||
| 57 | explicit BufferQueue(Kernel::KernelCore& kernel, u32 id_, u64 layer_id_); | 63 | explicit BufferQueue(Kernel::KernelCore& kernel, u32 id_, u64 layer_id_, |
| 64 | KernelHelpers::ServiceContext& service_context_); | ||
| 58 | ~BufferQueue(); | 65 | ~BufferQueue(); |
| 59 | 66 | ||
| 60 | enum class BufferTransformFlags : u32 { | 67 | enum class BufferTransformFlags : u32 { |
| @@ -130,12 +137,14 @@ private: | |||
| 130 | std::list<u32> free_buffers; | 137 | std::list<u32> free_buffers; |
| 131 | std::array<Buffer, buffer_slots> buffers; | 138 | std::array<Buffer, buffer_slots> buffers; |
| 132 | std::list<u32> queue_sequence; | 139 | std::list<u32> queue_sequence; |
| 133 | Kernel::KEvent buffer_wait_event; | 140 | Kernel::KEvent* buffer_wait_event{}; |
| 134 | 141 | ||
| 135 | std::mutex free_buffers_mutex; | 142 | std::mutex free_buffers_mutex; |
| 136 | std::condition_variable free_buffers_condition; | 143 | std::condition_variable free_buffers_condition; |
| 137 | 144 | ||
| 138 | std::mutex queue_sequence_mutex; | 145 | std::mutex queue_sequence_mutex; |
| 146 | |||
| 147 | KernelHelpers::ServiceContext& service_context; | ||
| 139 | }; | 148 | }; |
| 140 | 149 | ||
| 141 | } // namespace Service::NVFlinger | 150 | } // namespace Service::NVFlinger |
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index 941748970..3ead813b0 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp | |||
| @@ -61,12 +61,13 @@ void NVFlinger::SplitVSync() { | |||
| 61 | } | 61 | } |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | NVFlinger::NVFlinger(Core::System& system_) : system(system_) { | 64 | NVFlinger::NVFlinger(Core::System& system_) |
| 65 | displays.emplace_back(0, "Default", system); | 65 | : system(system_), service_context(system_, "nvflinger") { |
| 66 | displays.emplace_back(1, "External", system); | 66 | displays.emplace_back(0, "Default", service_context, system); |
| 67 | displays.emplace_back(2, "Edid", system); | 67 | displays.emplace_back(1, "External", service_context, system); |
| 68 | displays.emplace_back(3, "Internal", system); | 68 | displays.emplace_back(2, "Edid", service_context, system); |
| 69 | displays.emplace_back(4, "Null", system); | 69 | displays.emplace_back(3, "Internal", service_context, system); |
| 70 | displays.emplace_back(4, "Null", service_context, system); | ||
| 70 | guard = std::make_shared<std::mutex>(); | 71 | guard = std::make_shared<std::mutex>(); |
| 71 | 72 | ||
| 72 | // Schedule the screen composition events | 73 | // Schedule the screen composition events |
| @@ -146,7 +147,7 @@ std::optional<u64> NVFlinger::CreateLayer(u64 display_id) { | |||
| 146 | void NVFlinger::CreateLayerAtId(VI::Display& display, u64 layer_id) { | 147 | void NVFlinger::CreateLayerAtId(VI::Display& display, u64 layer_id) { |
| 147 | const u32 buffer_queue_id = next_buffer_queue_id++; | 148 | const u32 buffer_queue_id = next_buffer_queue_id++; |
| 148 | buffer_queues.emplace_back( | 149 | buffer_queues.emplace_back( |
| 149 | std::make_unique<BufferQueue>(system.Kernel(), buffer_queue_id, layer_id)); | 150 | std::make_unique<BufferQueue>(system.Kernel(), buffer_queue_id, layer_id, service_context)); |
| 150 | display.CreateLayer(layer_id, *buffer_queues.back()); | 151 | display.CreateLayer(layer_id, *buffer_queues.back()); |
| 151 | } | 152 | } |
| 152 | 153 | ||
| @@ -297,7 +298,7 @@ void NVFlinger::Compose() { | |||
| 297 | auto nvdisp = nvdrv->GetDevice<Nvidia::Devices::nvdisp_disp0>("/dev/nvdisp_disp0"); | 298 | auto nvdisp = nvdrv->GetDevice<Nvidia::Devices::nvdisp_disp0>("/dev/nvdisp_disp0"); |
| 298 | ASSERT(nvdisp); | 299 | ASSERT(nvdisp); |
| 299 | 300 | ||
| 300 | nvdisp->flip(igbp_buffer.gpu_buffer_id, igbp_buffer.offset, igbp_buffer.format, | 301 | nvdisp->flip(igbp_buffer.gpu_buffer_id, igbp_buffer.offset, igbp_buffer.external_format, |
| 301 | igbp_buffer.width, igbp_buffer.height, igbp_buffer.stride, | 302 | igbp_buffer.width, igbp_buffer.height, igbp_buffer.stride, |
| 302 | buffer->get().transform, buffer->get().crop_rect); | 303 | buffer->get().transform, buffer->get().crop_rect); |
| 303 | 304 | ||
diff --git a/src/core/hle/service/nvflinger/nvflinger.h b/src/core/hle/service/nvflinger/nvflinger.h index d80fd07ef..6d84cafb4 100644 --- a/src/core/hle/service/nvflinger/nvflinger.h +++ b/src/core/hle/service/nvflinger/nvflinger.h | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include <vector> | 15 | #include <vector> |
| 16 | 16 | ||
| 17 | #include "common/common_types.h" | 17 | #include "common/common_types.h" |
| 18 | #include "core/hle/service/kernel_helpers.h" | ||
| 18 | 19 | ||
| 19 | namespace Common { | 20 | namespace Common { |
| 20 | class Event; | 21 | class Event; |
| @@ -135,6 +136,8 @@ private: | |||
| 135 | std::unique_ptr<std::thread> vsync_thread; | 136 | std::unique_ptr<std::thread> vsync_thread; |
| 136 | std::unique_ptr<Common::Event> wait_event; | 137 | std::unique_ptr<Common::Event> wait_event; |
| 137 | std::atomic<bool> is_running{}; | 138 | std::atomic<bool> is_running{}; |
| 139 | |||
| 140 | KernelHelpers::ServiceContext service_context; | ||
| 138 | }; | 141 | }; |
| 139 | 142 | ||
| 140 | } // namespace Service::NVFlinger | 143 | } // namespace Service::NVFlinger |
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index b3e50433b..065133166 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -46,6 +46,7 @@ | |||
| 46 | #include "core/hle/service/ncm/ncm.h" | 46 | #include "core/hle/service/ncm/ncm.h" |
| 47 | #include "core/hle/service/nfc/nfc.h" | 47 | #include "core/hle/service/nfc/nfc.h" |
| 48 | #include "core/hle/service/nfp/nfp.h" | 48 | #include "core/hle/service/nfp/nfp.h" |
| 49 | #include "core/hle/service/ngct/ngct.h" | ||
| 49 | #include "core/hle/service/nifm/nifm.h" | 50 | #include "core/hle/service/nifm/nifm.h" |
| 50 | #include "core/hle/service/nim/nim.h" | 51 | #include "core/hle/service/nim/nim.h" |
| 51 | #include "core/hle/service/npns/npns.h" | 52 | #include "core/hle/service/npns/npns.h" |
| @@ -271,6 +272,7 @@ Services::Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system | |||
| 271 | NCM::InstallInterfaces(*sm, system); | 272 | NCM::InstallInterfaces(*sm, system); |
| 272 | NFC::InstallInterfaces(*sm, system); | 273 | NFC::InstallInterfaces(*sm, system); |
| 273 | NFP::InstallInterfaces(*sm, system); | 274 | NFP::InstallInterfaces(*sm, system); |
| 275 | NGCT::InstallInterfaces(*sm, system); | ||
| 274 | NIFM::InstallInterfaces(*sm, system); | 276 | NIFM::InstallInterfaces(*sm, system); |
| 275 | NIM::InstallInterfaces(*sm, system); | 277 | NIM::InstallInterfaces(*sm, system); |
| 276 | NPNS::InstallInterfaces(*sm, system); | 278 | NPNS::InstallInterfaces(*sm, system); |
diff --git a/src/core/hle/service/vi/display/vi_display.cpp b/src/core/hle/service/vi/display/vi_display.cpp index 0dd342dbf..b7705c02a 100644 --- a/src/core/hle/service/vi/display/vi_display.cpp +++ b/src/core/hle/service/vi/display/vi_display.cpp | |||
| @@ -12,18 +12,21 @@ | |||
| 12 | #include "core/hle/kernel/k_event.h" | 12 | #include "core/hle/kernel/k_event.h" |
| 13 | #include "core/hle/kernel/k_readable_event.h" | 13 | #include "core/hle/kernel/k_readable_event.h" |
| 14 | #include "core/hle/kernel/k_writable_event.h" | 14 | #include "core/hle/kernel/k_writable_event.h" |
| 15 | #include "core/hle/service/kernel_helpers.h" | ||
| 15 | #include "core/hle/service/vi/display/vi_display.h" | 16 | #include "core/hle/service/vi/display/vi_display.h" |
| 16 | #include "core/hle/service/vi/layer/vi_layer.h" | 17 | #include "core/hle/service/vi/layer/vi_layer.h" |
| 17 | 18 | ||
| 18 | namespace Service::VI { | 19 | namespace Service::VI { |
| 19 | 20 | ||
| 20 | Display::Display(u64 id, std::string name_, Core::System& system) | 21 | Display::Display(u64 id, std::string name_, KernelHelpers::ServiceContext& service_context_, |
| 21 | : display_id{id}, name{std::move(name_)}, vsync_event{system.Kernel()} { | 22 | Core::System& system_) |
| 22 | Kernel::KAutoObject::Create(std::addressof(vsync_event)); | 23 | : display_id{id}, name{std::move(name_)}, service_context{service_context_} { |
| 23 | vsync_event.Initialize(fmt::format("Display VSync Event {}", id)); | 24 | vsync_event = service_context.CreateEvent(fmt::format("Display VSync Event {}", id)); |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | Display::~Display() = default; | 27 | Display::~Display() { |
| 28 | service_context.CloseEvent(vsync_event); | ||
| 29 | } | ||
| 27 | 30 | ||
| 28 | Layer& Display::GetLayer(std::size_t index) { | 31 | Layer& Display::GetLayer(std::size_t index) { |
| 29 | return *layers.at(index); | 32 | return *layers.at(index); |
| @@ -34,11 +37,11 @@ const Layer& Display::GetLayer(std::size_t index) const { | |||
| 34 | } | 37 | } |
| 35 | 38 | ||
| 36 | Kernel::KReadableEvent& Display::GetVSyncEvent() { | 39 | Kernel::KReadableEvent& Display::GetVSyncEvent() { |
| 37 | return vsync_event.GetReadableEvent(); | 40 | return vsync_event->GetReadableEvent(); |
| 38 | } | 41 | } |
| 39 | 42 | ||
| 40 | void Display::SignalVSyncEvent() { | 43 | void Display::SignalVSyncEvent() { |
| 41 | vsync_event.GetWritableEvent().Signal(); | 44 | vsync_event->GetWritableEvent().Signal(); |
| 42 | } | 45 | } |
| 43 | 46 | ||
| 44 | void Display::CreateLayer(u64 layer_id, NVFlinger::BufferQueue& buffer_queue) { | 47 | void Display::CreateLayer(u64 layer_id, NVFlinger::BufferQueue& buffer_queue) { |
diff --git a/src/core/hle/service/vi/display/vi_display.h b/src/core/hle/service/vi/display/vi_display.h index 166f2a4cc..0979fc421 100644 --- a/src/core/hle/service/vi/display/vi_display.h +++ b/src/core/hle/service/vi/display/vi_display.h | |||
| @@ -18,6 +18,9 @@ class KEvent; | |||
| 18 | namespace Service::NVFlinger { | 18 | namespace Service::NVFlinger { |
| 19 | class BufferQueue; | 19 | class BufferQueue; |
| 20 | } | 20 | } |
| 21 | namespace Service::KernelHelpers { | ||
| 22 | class ServiceContext; | ||
| 23 | } // namespace Service::KernelHelpers | ||
| 21 | 24 | ||
| 22 | namespace Service::VI { | 25 | namespace Service::VI { |
| 23 | 26 | ||
| @@ -31,10 +34,13 @@ class Display { | |||
| 31 | public: | 34 | public: |
| 32 | /// Constructs a display with a given unique ID and name. | 35 | /// Constructs a display with a given unique ID and name. |
| 33 | /// | 36 | /// |
| 34 | /// @param id The unique ID for this display. | 37 | /// @param id The unique ID for this display. |
| 38 | /// @param service_context_ The ServiceContext for the owning service. | ||
| 35 | /// @param name_ The name for this display. | 39 | /// @param name_ The name for this display. |
| 40 | /// @param system_ The global system instance. | ||
| 36 | /// | 41 | /// |
| 37 | Display(u64 id, std::string name_, Core::System& system); | 42 | Display(u64 id, std::string name_, KernelHelpers::ServiceContext& service_context_, |
| 43 | Core::System& system_); | ||
| 38 | ~Display(); | 44 | ~Display(); |
| 39 | 45 | ||
| 40 | /// Gets the unique ID assigned to this display. | 46 | /// Gets the unique ID assigned to this display. |
| @@ -98,9 +104,10 @@ public: | |||
| 98 | private: | 104 | private: |
| 99 | u64 display_id; | 105 | u64 display_id; |
| 100 | std::string name; | 106 | std::string name; |
| 107 | KernelHelpers::ServiceContext& service_context; | ||
| 101 | 108 | ||
| 102 | std::vector<std::shared_ptr<Layer>> layers; | 109 | std::vector<std::shared_ptr<Layer>> layers; |
| 103 | Kernel::KEvent vsync_event; | 110 | Kernel::KEvent* vsync_event{}; |
| 104 | }; | 111 | }; |
| 105 | 112 | ||
| 106 | } // namespace Service::VI | 113 | } // namespace Service::VI |
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 3e5949d52..8e8fc40ca 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp | |||
| @@ -1158,7 +1158,7 @@ private: | |||
| 1158 | 1158 | ||
| 1159 | const auto layer_id = nv_flinger.CreateLayer(display_id); | 1159 | const auto layer_id = nv_flinger.CreateLayer(display_id); |
| 1160 | if (!layer_id) { | 1160 | if (!layer_id) { |
| 1161 | LOG_ERROR(Service_VI, "Layer not found! layer_id={}", *layer_id); | 1161 | LOG_ERROR(Service_VI, "Layer not found! display_id={}", display_id); |
| 1162 | IPC::ResponseBuilder rb{ctx, 2}; | 1162 | IPC::ResponseBuilder rb{ctx, 2}; |
| 1163 | rb.Push(ERR_NOT_FOUND); | 1163 | rb.Push(ERR_NOT_FOUND); |
| 1164 | return; | 1164 | return; |
diff --git a/src/core/network/network.cpp b/src/core/network/network.cpp index 375bc79ec..4732d4485 100644 --- a/src/core/network/network.cpp +++ b/src/core/network/network.cpp | |||
| @@ -10,9 +10,10 @@ | |||
| 10 | #include "common/common_funcs.h" | 10 | #include "common/common_funcs.h" |
| 11 | 11 | ||
| 12 | #ifdef _WIN32 | 12 | #ifdef _WIN32 |
| 13 | #define _WINSOCK_DEPRECATED_NO_WARNINGS // gethostname | ||
| 14 | #include <winsock2.h> | 13 | #include <winsock2.h> |
| 14 | #include <ws2tcpip.h> | ||
| 15 | #elif YUZU_UNIX | 15 | #elif YUZU_UNIX |
| 16 | #include <arpa/inet.h> | ||
| 16 | #include <errno.h> | 17 | #include <errno.h> |
| 17 | #include <fcntl.h> | 18 | #include <fcntl.h> |
| 18 | #include <netdb.h> | 19 | #include <netdb.h> |
| @@ -27,7 +28,9 @@ | |||
| 27 | #include "common/assert.h" | 28 | #include "common/assert.h" |
| 28 | #include "common/common_types.h" | 29 | #include "common/common_types.h" |
| 29 | #include "common/logging/log.h" | 30 | #include "common/logging/log.h" |
| 31 | #include "common/settings.h" | ||
| 30 | #include "core/network/network.h" | 32 | #include "core/network/network.h" |
| 33 | #include "core/network/network_interface.h" | ||
| 31 | #include "core/network/sockets.h" | 34 | #include "core/network/sockets.h" |
| 32 | 35 | ||
| 33 | namespace Network { | 36 | namespace Network { |
| @@ -47,11 +50,6 @@ void Finalize() { | |||
| 47 | WSACleanup(); | 50 | WSACleanup(); |
| 48 | } | 51 | } |
| 49 | 52 | ||
| 50 | constexpr IPv4Address TranslateIPv4(in_addr addr) { | ||
| 51 | auto& bytes = addr.S_un.S_un_b; | ||
| 52 | return IPv4Address{bytes.s_b1, bytes.s_b2, bytes.s_b3, bytes.s_b4}; | ||
| 53 | } | ||
| 54 | |||
| 55 | sockaddr TranslateFromSockAddrIn(SockAddrIn input) { | 53 | sockaddr TranslateFromSockAddrIn(SockAddrIn input) { |
| 56 | sockaddr_in result; | 54 | sockaddr_in result; |
| 57 | 55 | ||
| @@ -138,12 +136,6 @@ void Initialize() {} | |||
| 138 | 136 | ||
| 139 | void Finalize() {} | 137 | void Finalize() {} |
| 140 | 138 | ||
| 141 | constexpr IPv4Address TranslateIPv4(in_addr addr) { | ||
| 142 | const u32 bytes = addr.s_addr; | ||
| 143 | return IPv4Address{static_cast<u8>(bytes), static_cast<u8>(bytes >> 8), | ||
| 144 | static_cast<u8>(bytes >> 16), static_cast<u8>(bytes >> 24)}; | ||
| 145 | } | ||
| 146 | |||
| 147 | sockaddr TranslateFromSockAddrIn(SockAddrIn input) { | 139 | sockaddr TranslateFromSockAddrIn(SockAddrIn input) { |
| 148 | sockaddr_in result; | 140 | sockaddr_in result; |
| 149 | 141 | ||
| @@ -182,7 +174,7 @@ linger MakeLinger(bool enable, u32 linger_value) { | |||
| 182 | } | 174 | } |
| 183 | 175 | ||
| 184 | bool EnableNonBlock(int fd, bool enable) { | 176 | bool EnableNonBlock(int fd, bool enable) { |
| 185 | int flags = fcntl(fd, F_GETFD); | 177 | int flags = fcntl(fd, F_GETFL); |
| 186 | if (flags == -1) { | 178 | if (flags == -1) { |
| 187 | return false; | 179 | return false; |
| 188 | } | 180 | } |
| @@ -191,7 +183,7 @@ bool EnableNonBlock(int fd, bool enable) { | |||
| 191 | } else { | 183 | } else { |
| 192 | flags &= ~O_NONBLOCK; | 184 | flags &= ~O_NONBLOCK; |
| 193 | } | 185 | } |
| 194 | return fcntl(fd, F_SETFD, flags) == 0; | 186 | return fcntl(fd, F_SETFL, flags) == 0; |
| 195 | } | 187 | } |
| 196 | 188 | ||
| 197 | Errno TranslateNativeError(int e) { | 189 | Errno TranslateNativeError(int e) { |
| @@ -227,8 +219,12 @@ Errno GetAndLogLastError() { | |||
| 227 | #else | 219 | #else |
| 228 | int e = errno; | 220 | int e = errno; |
| 229 | #endif | 221 | #endif |
| 222 | const Errno err = TranslateNativeError(e); | ||
| 223 | if (err == Errno::AGAIN) { | ||
| 224 | return err; | ||
| 225 | } | ||
| 230 | LOG_ERROR(Network, "Socket operation error: {}", NativeErrorToString(e)); | 226 | LOG_ERROR(Network, "Socket operation error: {}", NativeErrorToString(e)); |
| 231 | return TranslateNativeError(e); | 227 | return err; |
| 232 | } | 228 | } |
| 233 | 229 | ||
| 234 | int TranslateDomain(Domain domain) { | 230 | int TranslateDomain(Domain domain) { |
| @@ -353,27 +349,29 @@ NetworkInstance::~NetworkInstance() { | |||
| 353 | Finalize(); | 349 | Finalize(); |
| 354 | } | 350 | } |
| 355 | 351 | ||
| 356 | std::pair<IPv4Address, Errno> GetHostIPv4Address() { | 352 | std::optional<IPv4Address> GetHostIPv4Address() { |
| 357 | std::array<char, 256> name{}; | 353 | const std::string& selected_network_interface = Settings::values.network_interface.GetValue(); |
| 358 | if (gethostname(name.data(), static_cast<int>(name.size()) - 1) == SOCKET_ERROR) { | 354 | const auto network_interfaces = Network::GetAvailableNetworkInterfaces(); |
| 359 | return {IPv4Address{}, GetAndLogLastError()}; | 355 | if (network_interfaces.size() == 0) { |
| 356 | LOG_ERROR(Network, "GetAvailableNetworkInterfaces returned no interfaces"); | ||
| 357 | return {}; | ||
| 360 | } | 358 | } |
| 361 | 359 | ||
| 362 | hostent* const ent = gethostbyname(name.data()); | 360 | const auto res = |
| 363 | if (!ent) { | 361 | std::ranges::find_if(network_interfaces, [&selected_network_interface](const auto& iface) { |
| 364 | return {IPv4Address{}, GetAndLogLastError()}; | 362 | return iface.name == selected_network_interface; |
| 365 | } | 363 | }); |
| 366 | if (ent->h_addr_list == nullptr) { | 364 | |
| 367 | UNIMPLEMENTED_MSG("No addr provided in hostent->h_addr_list"); | 365 | if (res != network_interfaces.end()) { |
| 368 | return {IPv4Address{}, Errno::SUCCESS}; | 366 | char ip_addr[16] = {}; |
| 369 | } | 367 | ASSERT(inet_ntop(AF_INET, &res->ip_address, ip_addr, sizeof(ip_addr)) != nullptr); |
| 370 | if (ent->h_length != sizeof(in_addr)) { | 368 | LOG_INFO(Network, "IP address: {}", ip_addr); |
| 371 | UNIMPLEMENTED_MSG("Unexpected size={} in hostent->h_length", ent->h_length); | ||
| 372 | } | ||
| 373 | 369 | ||
| 374 | in_addr addr; | 370 | return TranslateIPv4(res->ip_address); |
| 375 | std::memcpy(&addr, ent->h_addr_list[0], sizeof(addr)); | 371 | } else { |
| 376 | return {TranslateIPv4(addr), Errno::SUCCESS}; | 372 | LOG_ERROR(Network, "Couldn't find selected interface \"{}\"", selected_network_interface); |
| 373 | return {}; | ||
| 374 | } | ||
| 377 | } | 375 | } |
| 378 | 376 | ||
| 379 | std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) { | 377 | std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) { |
diff --git a/src/core/network/network.h b/src/core/network/network.h index bd30f1899..fdd3e4655 100644 --- a/src/core/network/network.h +++ b/src/core/network/network.h | |||
| @@ -5,11 +5,18 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <optional> | ||
| 8 | #include <utility> | 9 | #include <utility> |
| 9 | 10 | ||
| 10 | #include "common/common_funcs.h" | 11 | #include "common/common_funcs.h" |
| 11 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 12 | 13 | ||
| 14 | #ifdef _WIN32 | ||
| 15 | #include <winsock2.h> | ||
| 16 | #elif YUZU_UNIX | ||
| 17 | #include <netinet/in.h> | ||
| 18 | #endif | ||
| 19 | |||
| 13 | namespace Network { | 20 | namespace Network { |
| 14 | 21 | ||
| 15 | class Socket; | 22 | class Socket; |
| @@ -92,8 +99,21 @@ public: | |||
| 92 | ~NetworkInstance(); | 99 | ~NetworkInstance(); |
| 93 | }; | 100 | }; |
| 94 | 101 | ||
| 102 | #ifdef _WIN32 | ||
| 103 | constexpr IPv4Address TranslateIPv4(in_addr addr) { | ||
| 104 | auto& bytes = addr.S_un.S_un_b; | ||
| 105 | return IPv4Address{bytes.s_b1, bytes.s_b2, bytes.s_b3, bytes.s_b4}; | ||
| 106 | } | ||
| 107 | #elif YUZU_UNIX | ||
| 108 | constexpr IPv4Address TranslateIPv4(in_addr addr) { | ||
| 109 | const u32 bytes = addr.s_addr; | ||
| 110 | return IPv4Address{static_cast<u8>(bytes), static_cast<u8>(bytes >> 8), | ||
| 111 | static_cast<u8>(bytes >> 16), static_cast<u8>(bytes >> 24)}; | ||
| 112 | } | ||
| 113 | #endif | ||
| 114 | |||
| 95 | /// @brief Returns host's IPv4 address | 115 | /// @brief Returns host's IPv4 address |
| 96 | /// @return Pair of an array of human ordered IPv4 address (e.g. 192.168.0.1) and an error code | 116 | /// @return human ordered IPv4 address (e.g. 192.168.0.1) as an array |
| 97 | std::pair<IPv4Address, Errno> GetHostIPv4Address(); | 117 | std::optional<IPv4Address> GetHostIPv4Address(); |
| 98 | 118 | ||
| 99 | } // namespace Network | 119 | } // namespace Network |
diff --git a/src/core/network/network_interface.cpp b/src/core/network/network_interface.cpp new file mode 100644 index 000000000..6811f21b1 --- /dev/null +++ b/src/core/network/network_interface.cpp | |||
| @@ -0,0 +1,210 @@ | |||
| 1 | // Copyright 2021 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <fstream> | ||
| 7 | #include <sstream> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "common/bit_cast.h" | ||
| 11 | #include "common/common_types.h" | ||
| 12 | #include "common/logging/log.h" | ||
| 13 | #include "common/settings.h" | ||
| 14 | #include "common/string_util.h" | ||
| 15 | #include "core/network/network_interface.h" | ||
| 16 | |||
| 17 | #ifdef _WIN32 | ||
| 18 | #include <iphlpapi.h> | ||
| 19 | #else | ||
| 20 | #include <cerrno> | ||
| 21 | #include <ifaddrs.h> | ||
| 22 | #include <net/if.h> | ||
| 23 | #endif | ||
| 24 | |||
| 25 | namespace Network { | ||
| 26 | |||
| 27 | #ifdef _WIN32 | ||
| 28 | |||
| 29 | std::vector<NetworkInterface> GetAvailableNetworkInterfaces() { | ||
| 30 | std::vector<IP_ADAPTER_ADDRESSES> adapter_addresses; | ||
| 31 | DWORD ret = ERROR_BUFFER_OVERFLOW; | ||
| 32 | DWORD buf_size = 0; | ||
| 33 | |||
| 34 | // retry up to 5 times | ||
| 35 | for (int i = 0; i < 5 && ret == ERROR_BUFFER_OVERFLOW; i++) { | ||
| 36 | ret = GetAdaptersAddresses( | ||
| 37 | AF_INET, GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_INCLUDE_GATEWAYS, | ||
| 38 | nullptr, adapter_addresses.data(), &buf_size); | ||
| 39 | |||
| 40 | if (ret != ERROR_BUFFER_OVERFLOW) { | ||
| 41 | break; | ||
| 42 | } | ||
| 43 | |||
| 44 | adapter_addresses.resize((buf_size / sizeof(IP_ADAPTER_ADDRESSES)) + 1); | ||
| 45 | } | ||
| 46 | |||
| 47 | if (ret != NO_ERROR) { | ||
| 48 | LOG_ERROR(Network, "Failed to get network interfaces with GetAdaptersAddresses"); | ||
| 49 | return {}; | ||
| 50 | } | ||
| 51 | |||
| 52 | std::vector<NetworkInterface> result; | ||
| 53 | |||
| 54 | for (auto current_address = adapter_addresses.data(); current_address != nullptr; | ||
| 55 | current_address = current_address->Next) { | ||
| 56 | if (current_address->FirstUnicastAddress == nullptr || | ||
| 57 | current_address->FirstUnicastAddress->Address.lpSockaddr == nullptr) { | ||
| 58 | continue; | ||
| 59 | } | ||
| 60 | |||
| 61 | if (current_address->OperStatus != IfOperStatusUp) { | ||
| 62 | continue; | ||
| 63 | } | ||
| 64 | |||
| 65 | const auto ip_addr = Common::BitCast<struct sockaddr_in>( | ||
| 66 | *current_address->FirstUnicastAddress->Address.lpSockaddr) | ||
| 67 | .sin_addr; | ||
| 68 | |||
| 69 | ULONG mask = 0; | ||
| 70 | if (ConvertLengthToIpv4Mask(current_address->FirstUnicastAddress->OnLinkPrefixLength, | ||
| 71 | &mask) != NO_ERROR) { | ||
| 72 | LOG_ERROR(Network, "Failed to convert IPv4 prefix length to subnet mask"); | ||
| 73 | continue; | ||
| 74 | } | ||
| 75 | |||
| 76 | struct in_addr gateway = {.S_un{.S_addr{0}}}; | ||
| 77 | if (current_address->FirstGatewayAddress != nullptr && | ||
| 78 | current_address->FirstGatewayAddress->Address.lpSockaddr != nullptr) { | ||
| 79 | gateway = Common::BitCast<struct sockaddr_in>( | ||
| 80 | *current_address->FirstGatewayAddress->Address.lpSockaddr) | ||
| 81 | .sin_addr; | ||
| 82 | } | ||
| 83 | |||
| 84 | result.emplace_back(NetworkInterface{ | ||
| 85 | .name{Common::UTF16ToUTF8(std::wstring{current_address->FriendlyName})}, | ||
| 86 | .ip_address{ip_addr}, | ||
| 87 | .subnet_mask = in_addr{.S_un{.S_addr{mask}}}, | ||
| 88 | .gateway = gateway}); | ||
| 89 | } | ||
| 90 | |||
| 91 | return result; | ||
| 92 | } | ||
| 93 | |||
| 94 | #else | ||
| 95 | |||
| 96 | std::vector<NetworkInterface> GetAvailableNetworkInterfaces() { | ||
| 97 | struct ifaddrs* ifaddr = nullptr; | ||
| 98 | |||
| 99 | if (getifaddrs(&ifaddr) != 0) { | ||
| 100 | LOG_ERROR(Network, "Failed to get network interfaces with getifaddrs: {}", | ||
| 101 | std::strerror(errno)); | ||
| 102 | return {}; | ||
| 103 | } | ||
| 104 | |||
| 105 | std::vector<NetworkInterface> result; | ||
| 106 | |||
| 107 | for (auto ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) { | ||
| 108 | if (ifa->ifa_addr == nullptr || ifa->ifa_netmask == nullptr) { | ||
| 109 | continue; | ||
| 110 | } | ||
| 111 | |||
| 112 | if (ifa->ifa_addr->sa_family != AF_INET) { | ||
| 113 | continue; | ||
| 114 | } | ||
| 115 | |||
| 116 | if ((ifa->ifa_flags & IFF_UP) == 0 || (ifa->ifa_flags & IFF_LOOPBACK) != 0) { | ||
| 117 | continue; | ||
| 118 | } | ||
| 119 | |||
| 120 | u32 gateway{}; | ||
| 121 | |||
| 122 | std::ifstream file{"/proc/net/route"}; | ||
| 123 | if (!file.is_open()) { | ||
| 124 | LOG_ERROR(Network, "Failed to open \"/proc/net/route\""); | ||
| 125 | |||
| 126 | result.emplace_back(NetworkInterface{ | ||
| 127 | .name{ifa->ifa_name}, | ||
| 128 | .ip_address{Common::BitCast<struct sockaddr_in>(*ifa->ifa_addr).sin_addr}, | ||
| 129 | .subnet_mask{Common::BitCast<struct sockaddr_in>(*ifa->ifa_netmask).sin_addr}, | ||
| 130 | .gateway{in_addr{.s_addr = gateway}}}); | ||
| 131 | continue; | ||
| 132 | } | ||
| 133 | |||
| 134 | // ignore header | ||
| 135 | file.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); | ||
| 136 | |||
| 137 | bool gateway_found = false; | ||
| 138 | |||
| 139 | for (std::string line; std::getline(file, line);) { | ||
| 140 | std::istringstream iss{line}; | ||
| 141 | |||
| 142 | std::string iface_name; | ||
| 143 | iss >> iface_name; | ||
| 144 | if (iface_name != ifa->ifa_name) { | ||
| 145 | continue; | ||
| 146 | } | ||
| 147 | |||
| 148 | iss >> std::hex; | ||
| 149 | |||
| 150 | u32 dest{}; | ||
| 151 | iss >> dest; | ||
| 152 | if (dest != 0) { | ||
| 153 | // not the default route | ||
| 154 | continue; | ||
| 155 | } | ||
| 156 | |||
| 157 | iss >> gateway; | ||
| 158 | |||
| 159 | u16 flags{}; | ||
| 160 | iss >> flags; | ||
| 161 | |||
| 162 | // flag RTF_GATEWAY (defined in <linux/route.h>) | ||
| 163 | if ((flags & 0x2) == 0) { | ||
| 164 | continue; | ||
| 165 | } | ||
| 166 | |||
| 167 | gateway_found = true; | ||
| 168 | break; | ||
| 169 | } | ||
| 170 | |||
| 171 | if (!gateway_found) { | ||
| 172 | gateway = 0; | ||
| 173 | } | ||
| 174 | |||
| 175 | result.emplace_back(NetworkInterface{ | ||
| 176 | .name{ifa->ifa_name}, | ||
| 177 | .ip_address{Common::BitCast<struct sockaddr_in>(*ifa->ifa_addr).sin_addr}, | ||
| 178 | .subnet_mask{Common::BitCast<struct sockaddr_in>(*ifa->ifa_netmask).sin_addr}, | ||
| 179 | .gateway{in_addr{.s_addr = gateway}}}); | ||
| 180 | } | ||
| 181 | |||
| 182 | freeifaddrs(ifaddr); | ||
| 183 | |||
| 184 | return result; | ||
| 185 | } | ||
| 186 | |||
| 187 | #endif | ||
| 188 | |||
| 189 | std::optional<NetworkInterface> GetSelectedNetworkInterface() { | ||
| 190 | const auto& selected_network_interface = Settings::values.network_interface.GetValue(); | ||
| 191 | const auto network_interfaces = Network::GetAvailableNetworkInterfaces(); | ||
| 192 | if (network_interfaces.size() == 0) { | ||
| 193 | LOG_ERROR(Network, "GetAvailableNetworkInterfaces returned no interfaces"); | ||
| 194 | return std::nullopt; | ||
| 195 | } | ||
| 196 | |||
| 197 | const auto res = | ||
| 198 | std::ranges::find_if(network_interfaces, [&selected_network_interface](const auto& iface) { | ||
| 199 | return iface.name == selected_network_interface; | ||
| 200 | }); | ||
| 201 | |||
| 202 | if (res == network_interfaces.end()) { | ||
| 203 | LOG_ERROR(Network, "Couldn't find selected interface \"{}\"", selected_network_interface); | ||
| 204 | return std::nullopt; | ||
| 205 | } | ||
| 206 | |||
| 207 | return *res; | ||
| 208 | } | ||
| 209 | |||
| 210 | } // namespace Network | ||
diff --git a/src/core/network/network_interface.h b/src/core/network/network_interface.h new file mode 100644 index 000000000..980edb2f5 --- /dev/null +++ b/src/core/network/network_interface.h | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | // Copyright 2021 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <optional> | ||
| 8 | #include <string> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #ifdef _WIN32 | ||
| 12 | #include <winsock2.h> | ||
| 13 | #else | ||
| 14 | #include <netinet/in.h> | ||
| 15 | #endif | ||
| 16 | |||
| 17 | namespace Network { | ||
| 18 | |||
| 19 | struct NetworkInterface { | ||
| 20 | std::string name; | ||
| 21 | struct in_addr ip_address; | ||
| 22 | struct in_addr subnet_mask; | ||
| 23 | struct in_addr gateway; | ||
| 24 | }; | ||
| 25 | |||
| 26 | std::vector<NetworkInterface> GetAvailableNetworkInterfaces(); | ||
| 27 | std::optional<NetworkInterface> GetSelectedNetworkInterface(); | ||
| 28 | |||
| 29 | } // namespace Network | ||
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index f1f950d8a..f102410d1 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -889,6 +889,9 @@ SDLState::SDLState() { | |||
| 889 | RegisterFactory<VibrationDevice>("sdl", vibration_factory); | 889 | RegisterFactory<VibrationDevice>("sdl", vibration_factory); |
| 890 | RegisterFactory<MotionDevice>("sdl", motion_factory); | 890 | RegisterFactory<MotionDevice>("sdl", motion_factory); |
| 891 | 891 | ||
| 892 | // Disable raw input. When enabled this setting causes SDL to die when a web applet opens | ||
| 893 | SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "0"); | ||
| 894 | |||
| 892 | // Enable HIDAPI rumble. This prevents SDL from disabling motion on PS4 and PS5 controllers | 895 | // Enable HIDAPI rumble. This prevents SDL from disabling motion on PS4 and PS5 controllers |
| 893 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); | 896 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); |
| 894 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1"); | 897 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1"); |
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 2d29d8c14..2885e6799 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -15,6 +15,8 @@ | |||
| 15 | 15 | ||
| 16 | namespace Shader::Backend::SPIRV { | 16 | namespace Shader::Backend::SPIRV { |
| 17 | namespace { | 17 | namespace { |
| 18 | constexpr size_t NUM_FIXEDFNCTEXTURE = 10; | ||
| 19 | |||
| 18 | enum class Operation { | 20 | enum class Operation { |
| 19 | Increment, | 21 | Increment, |
| 20 | Decrement, | 22 | Decrement, |
| @@ -427,6 +429,16 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) { | |||
| 427 | return pointer_type; | 429 | return pointer_type; |
| 428 | } | 430 | } |
| 429 | } | 431 | } |
| 432 | |||
| 433 | size_t FindNextUnusedLocation(const std::bitset<IR::NUM_GENERICS>& used_locations, | ||
| 434 | size_t start_offset) { | ||
| 435 | for (size_t location = start_offset; location < used_locations.size(); ++location) { | ||
| 436 | if (!used_locations.test(location)) { | ||
| 437 | return location; | ||
| 438 | } | ||
| 439 | } | ||
| 440 | throw RuntimeError("Unable to get an unused location for legacy attribute"); | ||
| 441 | } | ||
| 430 | } // Anonymous namespace | 442 | } // Anonymous namespace |
| 431 | 443 | ||
| 432 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { | 444 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { |
| @@ -1227,6 +1239,7 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1227 | loads[IR::Attribute::TessellationEvaluationPointV]) { | 1239 | loads[IR::Attribute::TessellationEvaluationPointV]) { |
| 1228 | tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord); | 1240 | tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord); |
| 1229 | } | 1241 | } |
| 1242 | std::bitset<IR::NUM_GENERICS> used_locations{}; | ||
| 1230 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { | 1243 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { |
| 1231 | const AttributeType input_type{runtime_info.generic_input_types[index]}; | 1244 | const AttributeType input_type{runtime_info.generic_input_types[index]}; |
| 1232 | if (!runtime_info.previous_stage_stores.Generic(index)) { | 1245 | if (!runtime_info.previous_stage_stores.Generic(index)) { |
| @@ -1238,6 +1251,7 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1238 | if (input_type == AttributeType::Disabled) { | 1251 | if (input_type == AttributeType::Disabled) { |
| 1239 | continue; | 1252 | continue; |
| 1240 | } | 1253 | } |
| 1254 | used_locations.set(index); | ||
| 1241 | const Id type{GetAttributeType(*this, input_type)}; | 1255 | const Id type{GetAttributeType(*this, input_type)}; |
| 1242 | const Id id{DefineInput(*this, type, true)}; | 1256 | const Id id{DefineInput(*this, type, true)}; |
| 1243 | Decorate(id, spv::Decoration::Location, static_cast<u32>(index)); | 1257 | Decorate(id, spv::Decoration::Location, static_cast<u32>(index)); |
| @@ -1263,6 +1277,26 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1263 | break; | 1277 | break; |
| 1264 | } | 1278 | } |
| 1265 | } | 1279 | } |
| 1280 | size_t previous_unused_location = 0; | ||
| 1281 | if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | ||
| 1282 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1283 | previous_unused_location = location; | ||
| 1284 | used_locations.set(location); | ||
| 1285 | const Id id{DefineInput(*this, F32[4], true)}; | ||
| 1286 | Decorate(id, spv::Decoration::Location, location); | ||
| 1287 | input_front_color = id; | ||
| 1288 | } | ||
| 1289 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | ||
| 1290 | if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | ||
| 1291 | const size_t location = | ||
| 1292 | FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1293 | previous_unused_location = location; | ||
| 1294 | used_locations.set(location); | ||
| 1295 | const Id id{DefineInput(*this, F32[4], true)}; | ||
| 1296 | Decorate(id, spv::Decoration::Location, location); | ||
| 1297 | input_fixed_fnc_textures[index] = id; | ||
| 1298 | } | ||
| 1299 | } | ||
| 1266 | if (stage == Stage::TessellationEval) { | 1300 | if (stage == Stage::TessellationEval) { |
| 1267 | for (size_t index = 0; index < info.uses_patches.size(); ++index) { | 1301 | for (size_t index = 0; index < info.uses_patches.size(); ++index) { |
| 1268 | if (!info.uses_patches[index]) { | 1302 | if (!info.uses_patches[index]) { |
| @@ -1313,9 +1347,31 @@ void EmitContext::DefineOutputs(const IR::Program& program) { | |||
| 1313 | viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt, | 1347 | viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt, |
| 1314 | spv::BuiltIn::ViewportMaskNV); | 1348 | spv::BuiltIn::ViewportMaskNV); |
| 1315 | } | 1349 | } |
| 1350 | std::bitset<IR::NUM_GENERICS> used_locations{}; | ||
| 1316 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { | 1351 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { |
| 1317 | if (info.stores.Generic(index)) { | 1352 | if (info.stores.Generic(index)) { |
| 1318 | DefineGenericOutput(*this, index, invocations); | 1353 | DefineGenericOutput(*this, index, invocations); |
| 1354 | used_locations.set(index); | ||
| 1355 | } | ||
| 1356 | } | ||
| 1357 | size_t previous_unused_location = 0; | ||
| 1358 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | ||
| 1359 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1360 | previous_unused_location = location; | ||
| 1361 | used_locations.set(location); | ||
| 1362 | const Id id{DefineOutput(*this, F32[4], invocations)}; | ||
| 1363 | Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); | ||
| 1364 | output_front_color = id; | ||
| 1365 | } | ||
| 1366 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | ||
| 1367 | if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | ||
| 1368 | const size_t location = | ||
| 1369 | FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1370 | previous_unused_location = location; | ||
| 1371 | used_locations.set(location); | ||
| 1372 | const Id id{DefineOutput(*this, F32[4], invocations)}; | ||
| 1373 | Decorate(id, spv::Decoration::Location, location); | ||
| 1374 | output_fixed_fnc_textures[index] = id; | ||
| 1319 | } | 1375 | } |
| 1320 | } | 1376 | } |
| 1321 | switch (stage) { | 1377 | switch (stage) { |
diff --git a/src/shader_recompiler/backend/spirv/emit_context.h b/src/shader_recompiler/backend/spirv/emit_context.h index e277bc358..847d0c0e6 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.h +++ b/src/shader_recompiler/backend/spirv/emit_context.h | |||
| @@ -268,10 +268,14 @@ public: | |||
| 268 | Id write_global_func_u32x4{}; | 268 | Id write_global_func_u32x4{}; |
| 269 | 269 | ||
| 270 | Id input_position{}; | 270 | Id input_position{}; |
| 271 | Id input_front_color{}; | ||
| 272 | std::array<Id, 10> input_fixed_fnc_textures{}; | ||
| 271 | std::array<Id, 32> input_generics{}; | 273 | std::array<Id, 32> input_generics{}; |
| 272 | 274 | ||
| 273 | Id output_point_size{}; | 275 | Id output_point_size{}; |
| 274 | Id output_position{}; | 276 | Id output_position{}; |
| 277 | Id output_front_color{}; | ||
| 278 | std::array<Id, 10> output_fixed_fnc_textures{}; | ||
| 275 | std::array<std::array<GenericElementInfo, 4>, 32> output_generics{}; | 279 | std::array<std::array<GenericElementInfo, 4>, 32> output_generics{}; |
| 276 | 280 | ||
| 277 | Id output_tess_level_outer{}; | 281 | Id output_tess_level_outer{}; |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index fb8c02a77..68f360b3c 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp | |||
| @@ -43,6 +43,25 @@ Id AttrPointer(EmitContext& ctx, Id pointer_type, Id vertex, Id base, Args&&... | |||
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | bool IsFixedFncTexture(IR::Attribute attribute) { | ||
| 47 | return attribute >= IR::Attribute::FixedFncTexture0S && | ||
| 48 | attribute <= IR::Attribute::FixedFncTexture9Q; | ||
| 49 | } | ||
| 50 | |||
| 51 | u32 FixedFncTextureAttributeIndex(IR::Attribute attribute) { | ||
| 52 | if (!IsFixedFncTexture(attribute)) { | ||
| 53 | throw InvalidArgument("Attribute {} is not a FixedFncTexture", attribute); | ||
| 54 | } | ||
| 55 | return (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4u; | ||
| 56 | } | ||
| 57 | |||
| 58 | u32 FixedFncTextureAttributeElement(IR::Attribute attribute) { | ||
| 59 | if (!IsFixedFncTexture(attribute)) { | ||
| 60 | throw InvalidArgument("Attribute {} is not a FixedFncTexture", attribute); | ||
| 61 | } | ||
| 62 | return static_cast<u32>(attribute) % 4u; | ||
| 63 | } | ||
| 64 | |||
| 46 | template <typename... Args> | 65 | template <typename... Args> |
| 47 | Id OutputAccessChain(EmitContext& ctx, Id result_type, Id base, Args&&... args) { | 66 | Id OutputAccessChain(EmitContext& ctx, Id result_type, Id base, Args&&... args) { |
| 48 | if (ctx.stage == Stage::TessellationControl) { | 67 | if (ctx.stage == Stage::TessellationControl) { |
| @@ -74,6 +93,13 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { | |||
| 74 | return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id); | 93 | return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id); |
| 75 | } | 94 | } |
| 76 | } | 95 | } |
| 96 | if (IsFixedFncTexture(attr)) { | ||
| 97 | const u32 index{FixedFncTextureAttributeIndex(attr)}; | ||
| 98 | const u32 element{FixedFncTextureAttributeElement(attr)}; | ||
| 99 | const Id element_id{ctx.Const(element)}; | ||
| 100 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_fixed_fnc_textures[index], | ||
| 101 | element_id); | ||
| 102 | } | ||
| 77 | switch (attr) { | 103 | switch (attr) { |
| 78 | case IR::Attribute::PointSize: | 104 | case IR::Attribute::PointSize: |
| 79 | return ctx.output_point_size; | 105 | return ctx.output_point_size; |
| @@ -85,6 +111,14 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { | |||
| 85 | const Id element_id{ctx.Const(element)}; | 111 | const Id element_id{ctx.Const(element)}; |
| 86 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_position, element_id); | 112 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_position, element_id); |
| 87 | } | 113 | } |
| 114 | case IR::Attribute::ColorFrontDiffuseR: | ||
| 115 | case IR::Attribute::ColorFrontDiffuseG: | ||
| 116 | case IR::Attribute::ColorFrontDiffuseB: | ||
| 117 | case IR::Attribute::ColorFrontDiffuseA: { | ||
| 118 | const u32 element{static_cast<u32>(attr) % 4}; | ||
| 119 | const Id element_id{ctx.Const(element)}; | ||
| 120 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_front_color, element_id); | ||
| 121 | } | ||
| 88 | case IR::Attribute::ClipDistance0: | 122 | case IR::Attribute::ClipDistance0: |
| 89 | case IR::Attribute::ClipDistance1: | 123 | case IR::Attribute::ClipDistance1: |
| 90 | case IR::Attribute::ClipDistance2: | 124 | case IR::Attribute::ClipDistance2: |
| @@ -298,19 +332,21 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { | |||
| 298 | if (IR::IsGeneric(attr)) { | 332 | if (IR::IsGeneric(attr)) { |
| 299 | const u32 index{IR::GenericAttributeIndex(attr)}; | 333 | const u32 index{IR::GenericAttributeIndex(attr)}; |
| 300 | const std::optional<AttrInfo> type{AttrTypes(ctx, index)}; | 334 | const std::optional<AttrInfo> type{AttrTypes(ctx, index)}; |
| 301 | if (!type) { | 335 | if (!type || !ctx.runtime_info.previous_stage_stores.Generic(index, element)) { |
| 302 | // Attribute is disabled | 336 | // Attribute is disabled or varying component is not written |
| 303 | return ctx.Const(element == 3 ? 1.0f : 0.0f); | 337 | return ctx.Const(element == 3 ? 1.0f : 0.0f); |
| 304 | } | 338 | } |
| 305 | if (!ctx.runtime_info.previous_stage_stores.Generic(index, element)) { | ||
| 306 | // Varying component is not written | ||
| 307 | return ctx.Const(type && element == 3 ? 1.0f : 0.0f); | ||
| 308 | } | ||
| 309 | const Id generic_id{ctx.input_generics.at(index)}; | 339 | const Id generic_id{ctx.input_generics.at(index)}; |
| 310 | const Id pointer{AttrPointer(ctx, type->pointer, vertex, generic_id, ctx.Const(element))}; | 340 | const Id pointer{AttrPointer(ctx, type->pointer, vertex, generic_id, ctx.Const(element))}; |
| 311 | const Id value{ctx.OpLoad(type->id, pointer)}; | 341 | const Id value{ctx.OpLoad(type->id, pointer)}; |
| 312 | return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value; | 342 | return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value; |
| 313 | } | 343 | } |
| 344 | if (IsFixedFncTexture(attr)) { | ||
| 345 | const u32 index{FixedFncTextureAttributeIndex(attr)}; | ||
| 346 | const Id attr_id{ctx.input_fixed_fnc_textures[index]}; | ||
| 347 | const Id attr_ptr{AttrPointer(ctx, ctx.input_f32, vertex, attr_id, ctx.Const(element))}; | ||
| 348 | return ctx.OpLoad(ctx.F32[1], attr_ptr); | ||
| 349 | } | ||
| 314 | switch (attr) { | 350 | switch (attr) { |
| 315 | case IR::Attribute::PrimitiveId: | 351 | case IR::Attribute::PrimitiveId: |
| 316 | return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.primitive_id)); | 352 | return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.primitive_id)); |
| @@ -320,6 +356,13 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { | |||
| 320 | case IR::Attribute::PositionW: | 356 | case IR::Attribute::PositionW: |
| 321 | return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_position, | 357 | return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_position, |
| 322 | ctx.Const(element))); | 358 | ctx.Const(element))); |
| 359 | case IR::Attribute::ColorFrontDiffuseR: | ||
| 360 | case IR::Attribute::ColorFrontDiffuseG: | ||
| 361 | case IR::Attribute::ColorFrontDiffuseB: | ||
| 362 | case IR::Attribute::ColorFrontDiffuseA: { | ||
| 363 | return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_front_color, | ||
| 364 | ctx.Const(element))); | ||
| 365 | } | ||
| 323 | case IR::Attribute::InstanceId: | 366 | case IR::Attribute::InstanceId: |
| 324 | if (ctx.profile.support_vertex_instance_id) { | 367 | if (ctx.profile.support_vertex_instance_id) { |
| 325 | return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.instance_id)); | 368 | return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.instance_id)); |
| @@ -337,8 +380,9 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { | |||
| 337 | return ctx.OpBitcast(ctx.F32[1], ctx.OpISub(ctx.U32[1], index, base)); | 380 | return ctx.OpBitcast(ctx.F32[1], ctx.OpISub(ctx.U32[1], index, base)); |
| 338 | } | 381 | } |
| 339 | case IR::Attribute::FrontFace: | 382 | case IR::Attribute::FrontFace: |
| 340 | return ctx.OpSelect(ctx.U32[1], ctx.OpLoad(ctx.U1, ctx.front_face), | 383 | return ctx.OpSelect(ctx.F32[1], ctx.OpLoad(ctx.U1, ctx.front_face), |
| 341 | ctx.Const(std::numeric_limits<u32>::max()), ctx.u32_zero_value); | 384 | ctx.OpBitcast(ctx.F32[1], ctx.Const(std::numeric_limits<u32>::max())), |
| 385 | ctx.f32_zero_value); | ||
| 342 | case IR::Attribute::PointSpriteS: | 386 | case IR::Attribute::PointSpriteS: |
| 343 | return ctx.OpLoad(ctx.F32[1], | 387 | return ctx.OpLoad(ctx.F32[1], |
| 344 | ctx.OpAccessChain(ctx.input_f32, ctx.point_coord, ctx.u32_zero_value)); | 388 | ctx.OpAccessChain(ctx.input_f32, ctx.point_coord, ctx.u32_zero_value)); |
diff --git a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp index 8b3e0a15c..69eeaa3e6 100644 --- a/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp +++ b/src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include "shader_recompiler/frontend/maxwell/decode.h" | 20 | #include "shader_recompiler/frontend/maxwell/decode.h" |
| 21 | #include "shader_recompiler/frontend/maxwell/structured_control_flow.h" | 21 | #include "shader_recompiler/frontend/maxwell/structured_control_flow.h" |
| 22 | #include "shader_recompiler/frontend/maxwell/translate/translate.h" | 22 | #include "shader_recompiler/frontend/maxwell/translate/translate.h" |
| 23 | #include "shader_recompiler/host_translate_info.h" | ||
| 23 | #include "shader_recompiler/object_pool.h" | 24 | #include "shader_recompiler/object_pool.h" |
| 24 | 25 | ||
| 25 | namespace Shader::Maxwell { | 26 | namespace Shader::Maxwell { |
| @@ -652,7 +653,7 @@ class TranslatePass { | |||
| 652 | public: | 653 | public: |
| 653 | TranslatePass(ObjectPool<IR::Inst>& inst_pool_, ObjectPool<IR::Block>& block_pool_, | 654 | TranslatePass(ObjectPool<IR::Inst>& inst_pool_, ObjectPool<IR::Block>& block_pool_, |
| 654 | ObjectPool<Statement>& stmt_pool_, Environment& env_, Statement& root_stmt, | 655 | ObjectPool<Statement>& stmt_pool_, Environment& env_, Statement& root_stmt, |
| 655 | IR::AbstractSyntaxList& syntax_list_) | 656 | IR::AbstractSyntaxList& syntax_list_, const HostTranslateInfo& host_info) |
| 656 | : stmt_pool{stmt_pool_}, inst_pool{inst_pool_}, block_pool{block_pool_}, env{env_}, | 657 | : stmt_pool{stmt_pool_}, inst_pool{inst_pool_}, block_pool{block_pool_}, env{env_}, |
| 657 | syntax_list{syntax_list_} { | 658 | syntax_list{syntax_list_} { |
| 658 | Visit(root_stmt, nullptr, nullptr); | 659 | Visit(root_stmt, nullptr, nullptr); |
| @@ -660,6 +661,9 @@ public: | |||
| 660 | IR::Block& first_block{*syntax_list.front().data.block}; | 661 | IR::Block& first_block{*syntax_list.front().data.block}; |
| 661 | IR::IREmitter ir(first_block, first_block.begin()); | 662 | IR::IREmitter ir(first_block, first_block.begin()); |
| 662 | ir.Prologue(); | 663 | ir.Prologue(); |
| 664 | if (uses_demote_to_helper && host_info.needs_demote_reorder) { | ||
| 665 | DemoteCombinationPass(); | ||
| 666 | } | ||
| 663 | } | 667 | } |
| 664 | 668 | ||
| 665 | private: | 669 | private: |
| @@ -809,7 +813,14 @@ private: | |||
| 809 | } | 813 | } |
| 810 | case StatementType::Return: { | 814 | case StatementType::Return: { |
| 811 | ensure_block(); | 815 | ensure_block(); |
| 812 | IR::IREmitter{*current_block}.Epilogue(); | 816 | IR::Block* return_block{block_pool.Create(inst_pool)}; |
| 817 | IR::IREmitter{*return_block}.Epilogue(); | ||
| 818 | current_block->AddBranch(return_block); | ||
| 819 | |||
| 820 | auto& merge{syntax_list.emplace_back()}; | ||
| 821 | merge.type = IR::AbstractSyntaxNode::Type::Block; | ||
| 822 | merge.data.block = return_block; | ||
| 823 | |||
| 813 | current_block = nullptr; | 824 | current_block = nullptr; |
| 814 | syntax_list.emplace_back().type = IR::AbstractSyntaxNode::Type::Return; | 825 | syntax_list.emplace_back().type = IR::AbstractSyntaxNode::Type::Return; |
| 815 | break; | 826 | break; |
| @@ -824,6 +835,7 @@ private: | |||
| 824 | auto& merge{syntax_list.emplace_back()}; | 835 | auto& merge{syntax_list.emplace_back()}; |
| 825 | merge.type = IR::AbstractSyntaxNode::Type::Block; | 836 | merge.type = IR::AbstractSyntaxNode::Type::Block; |
| 826 | merge.data.block = demote_block; | 837 | merge.data.block = demote_block; |
| 838 | uses_demote_to_helper = true; | ||
| 827 | break; | 839 | break; |
| 828 | } | 840 | } |
| 829 | case StatementType::Unreachable: { | 841 | case StatementType::Unreachable: { |
| @@ -855,11 +867,117 @@ private: | |||
| 855 | return block_pool.Create(inst_pool); | 867 | return block_pool.Create(inst_pool); |
| 856 | } | 868 | } |
| 857 | 869 | ||
| 870 | void DemoteCombinationPass() { | ||
| 871 | using Type = IR::AbstractSyntaxNode::Type; | ||
| 872 | std::vector<IR::Block*> demote_blocks; | ||
| 873 | std::vector<IR::U1> demote_conds; | ||
| 874 | u32 num_epilogues{}; | ||
| 875 | u32 branch_depth{}; | ||
| 876 | for (const IR::AbstractSyntaxNode& node : syntax_list) { | ||
| 877 | if (node.type == Type::If) { | ||
| 878 | ++branch_depth; | ||
| 879 | } | ||
| 880 | if (node.type == Type::EndIf) { | ||
| 881 | --branch_depth; | ||
| 882 | } | ||
| 883 | if (node.type != Type::Block) { | ||
| 884 | continue; | ||
| 885 | } | ||
| 886 | if (branch_depth > 1) { | ||
| 887 | // Skip reordering nested demote branches. | ||
| 888 | continue; | ||
| 889 | } | ||
| 890 | for (const IR::Inst& inst : node.data.block->Instructions()) { | ||
| 891 | const IR::Opcode op{inst.GetOpcode()}; | ||
| 892 | if (op == IR::Opcode::DemoteToHelperInvocation) { | ||
| 893 | demote_blocks.push_back(node.data.block); | ||
| 894 | break; | ||
| 895 | } | ||
| 896 | if (op == IR::Opcode::Epilogue) { | ||
| 897 | ++num_epilogues; | ||
| 898 | } | ||
| 899 | } | ||
| 900 | } | ||
| 901 | if (demote_blocks.size() == 0) { | ||
| 902 | return; | ||
| 903 | } | ||
| 904 | if (num_epilogues > 1) { | ||
| 905 | LOG_DEBUG(Shader, "Combining demotes with more than one return is not implemented."); | ||
| 906 | return; | ||
| 907 | } | ||
| 908 | s64 last_iterator_offset{}; | ||
| 909 | auto& asl{syntax_list}; | ||
| 910 | for (const IR::Block* demote_block : demote_blocks) { | ||
| 911 | const auto start_it{asl.begin() + last_iterator_offset}; | ||
| 912 | auto asl_it{std::find_if(start_it, asl.end(), [&](const IR::AbstractSyntaxNode& asn) { | ||
| 913 | return asn.type == Type::If && asn.data.if_node.body == demote_block; | ||
| 914 | })}; | ||
| 915 | if (asl_it == asl.end()) { | ||
| 916 | // Demote without a conditional branch. | ||
| 917 | // No need to proceed since all fragment instances will be demoted regardless. | ||
| 918 | return; | ||
| 919 | } | ||
| 920 | const IR::Block* const end_if = asl_it->data.if_node.merge; | ||
| 921 | demote_conds.push_back(asl_it->data.if_node.cond); | ||
| 922 | last_iterator_offset = std::distance(asl.begin(), asl_it); | ||
| 923 | |||
| 924 | asl_it = asl.erase(asl_it); | ||
| 925 | asl_it = std::find_if(asl_it, asl.end(), [&](const IR::AbstractSyntaxNode& asn) { | ||
| 926 | return asn.type == Type::Block && asn.data.block == demote_block; | ||
| 927 | }); | ||
| 928 | |||
| 929 | asl_it = asl.erase(asl_it); | ||
| 930 | asl_it = std::find_if(asl_it, asl.end(), [&](const IR::AbstractSyntaxNode& asn) { | ||
| 931 | return asn.type == Type::EndIf && asn.data.end_if.merge == end_if; | ||
| 932 | }); | ||
| 933 | asl_it = asl.erase(asl_it); | ||
| 934 | } | ||
| 935 | const auto epilogue_func{[](const IR::AbstractSyntaxNode& asn) { | ||
| 936 | if (asn.type != Type::Block) { | ||
| 937 | return false; | ||
| 938 | } | ||
| 939 | for (const auto& inst : asn.data.block->Instructions()) { | ||
| 940 | if (inst.GetOpcode() == IR::Opcode::Epilogue) { | ||
| 941 | return true; | ||
| 942 | } | ||
| 943 | } | ||
| 944 | return false; | ||
| 945 | }}; | ||
| 946 | const auto reverse_it{std::find_if(asl.rbegin(), asl.rend(), epilogue_func)}; | ||
| 947 | const auto return_block_it{(reverse_it + 1).base()}; | ||
| 948 | |||
| 949 | IR::IREmitter ir{*(return_block_it - 1)->data.block}; | ||
| 950 | IR::U1 cond(IR::Value(false)); | ||
| 951 | for (const auto& demote_cond : demote_conds) { | ||
| 952 | cond = ir.LogicalOr(cond, demote_cond); | ||
| 953 | } | ||
| 954 | cond.Inst()->DestructiveAddUsage(1); | ||
| 955 | |||
| 956 | IR::AbstractSyntaxNode demote_if_node{}; | ||
| 957 | demote_if_node.type = Type::If; | ||
| 958 | demote_if_node.data.if_node.cond = cond; | ||
| 959 | demote_if_node.data.if_node.body = demote_blocks[0]; | ||
| 960 | demote_if_node.data.if_node.merge = return_block_it->data.block; | ||
| 961 | |||
| 962 | IR::AbstractSyntaxNode demote_node{}; | ||
| 963 | demote_node.type = Type::Block; | ||
| 964 | demote_node.data.block = demote_blocks[0]; | ||
| 965 | |||
| 966 | IR::AbstractSyntaxNode demote_endif_node{}; | ||
| 967 | demote_endif_node.type = Type::EndIf; | ||
| 968 | demote_endif_node.data.end_if.merge = return_block_it->data.block; | ||
| 969 | |||
| 970 | asl.insert(return_block_it, demote_endif_node); | ||
| 971 | asl.insert(return_block_it, demote_node); | ||
| 972 | asl.insert(return_block_it, demote_if_node); | ||
| 973 | } | ||
| 974 | |||
| 858 | ObjectPool<Statement>& stmt_pool; | 975 | ObjectPool<Statement>& stmt_pool; |
| 859 | ObjectPool<IR::Inst>& inst_pool; | 976 | ObjectPool<IR::Inst>& inst_pool; |
| 860 | ObjectPool<IR::Block>& block_pool; | 977 | ObjectPool<IR::Block>& block_pool; |
| 861 | Environment& env; | 978 | Environment& env; |
| 862 | IR::AbstractSyntaxList& syntax_list; | 979 | IR::AbstractSyntaxList& syntax_list; |
| 980 | bool uses_demote_to_helper{}; | ||
| 863 | 981 | ||
| 864 | // TODO: C++20 Remove this when all compilers support constexpr std::vector | 982 | // TODO: C++20 Remove this when all compilers support constexpr std::vector |
| 865 | #if __cpp_lib_constexpr_vector >= 201907 | 983 | #if __cpp_lib_constexpr_vector >= 201907 |
| @@ -871,12 +989,13 @@ private: | |||
| 871 | } // Anonymous namespace | 989 | } // Anonymous namespace |
| 872 | 990 | ||
| 873 | IR::AbstractSyntaxList BuildASL(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, | 991 | IR::AbstractSyntaxList BuildASL(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, |
| 874 | Environment& env, Flow::CFG& cfg) { | 992 | Environment& env, Flow::CFG& cfg, |
| 993 | const HostTranslateInfo& host_info) { | ||
| 875 | ObjectPool<Statement> stmt_pool{64}; | 994 | ObjectPool<Statement> stmt_pool{64}; |
| 876 | GotoPass goto_pass{cfg, stmt_pool}; | 995 | GotoPass goto_pass{cfg, stmt_pool}; |
| 877 | Statement& root{goto_pass.RootStatement()}; | 996 | Statement& root{goto_pass.RootStatement()}; |
| 878 | IR::AbstractSyntaxList syntax_list; | 997 | IR::AbstractSyntaxList syntax_list; |
| 879 | TranslatePass{inst_pool, block_pool, stmt_pool, env, root, syntax_list}; | 998 | TranslatePass{inst_pool, block_pool, stmt_pool, env, root, syntax_list, host_info}; |
| 880 | return syntax_list; | 999 | return syntax_list; |
| 881 | } | 1000 | } |
| 882 | 1001 | ||
diff --git a/src/shader_recompiler/frontend/maxwell/structured_control_flow.h b/src/shader_recompiler/frontend/maxwell/structured_control_flow.h index 88b083649..e38158da3 100644 --- a/src/shader_recompiler/frontend/maxwell/structured_control_flow.h +++ b/src/shader_recompiler/frontend/maxwell/structured_control_flow.h | |||
| @@ -11,10 +11,13 @@ | |||
| 11 | #include "shader_recompiler/frontend/maxwell/control_flow.h" | 11 | #include "shader_recompiler/frontend/maxwell/control_flow.h" |
| 12 | #include "shader_recompiler/object_pool.h" | 12 | #include "shader_recompiler/object_pool.h" |
| 13 | 13 | ||
| 14 | namespace Shader::Maxwell { | 14 | namespace Shader { |
| 15 | struct HostTranslateInfo; | ||
| 16 | namespace Maxwell { | ||
| 15 | 17 | ||
| 16 | [[nodiscard]] IR::AbstractSyntaxList BuildASL(ObjectPool<IR::Inst>& inst_pool, | 18 | [[nodiscard]] IR::AbstractSyntaxList BuildASL(ObjectPool<IR::Inst>& inst_pool, |
| 17 | ObjectPool<IR::Block>& block_pool, Environment& env, | 19 | ObjectPool<IR::Block>& block_pool, Environment& env, |
| 18 | Flow::CFG& cfg); | 20 | Flow::CFG& cfg, const HostTranslateInfo& host_info); |
| 19 | 21 | ||
| 20 | } // namespace Shader::Maxwell | 22 | } // namespace Maxwell |
| 23 | } // namespace Shader | ||
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp index c067d459c..012d55357 100644 --- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp | |||
| @@ -130,7 +130,7 @@ void AddNVNStorageBuffers(IR::Program& program) { | |||
| 130 | IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, | 130 | IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, |
| 131 | Environment& env, Flow::CFG& cfg, const HostTranslateInfo& host_info) { | 131 | Environment& env, Flow::CFG& cfg, const HostTranslateInfo& host_info) { |
| 132 | IR::Program program; | 132 | IR::Program program; |
| 133 | program.syntax_list = BuildASL(inst_pool, block_pool, env, cfg); | 133 | program.syntax_list = BuildASL(inst_pool, block_pool, env, cfg, host_info); |
| 134 | program.blocks = GenerateBlocks(program.syntax_list); | 134 | program.blocks = GenerateBlocks(program.syntax_list); |
| 135 | program.post_order_blocks = PostOrder(program.syntax_list.front()); | 135 | program.post_order_blocks = PostOrder(program.syntax_list.front()); |
| 136 | program.stage = env.ShaderStage(); | 136 | program.stage = env.ShaderStage(); |
diff --git a/src/shader_recompiler/host_translate_info.h b/src/shader_recompiler/host_translate_info.h index 94a584219..96468b2e7 100644 --- a/src/shader_recompiler/host_translate_info.h +++ b/src/shader_recompiler/host_translate_info.h | |||
| @@ -11,8 +11,9 @@ namespace Shader { | |||
| 11 | 11 | ||
| 12 | /// Misc information about the host | 12 | /// Misc information about the host |
| 13 | struct HostTranslateInfo { | 13 | struct HostTranslateInfo { |
| 14 | bool support_float16{}; ///< True when the device supports 16-bit floats | 14 | bool support_float16{}; ///< True when the device supports 16-bit floats |
| 15 | bool support_int64{}; ///< True when the device supports 64-bit integers | 15 | bool support_int64{}; ///< True when the device supports 64-bit integers |
| 16 | bool needs_demote_reorder{}; ///< True when the device needs DemoteToHelperInvocation reordered | ||
| 16 | }; | 17 | }; |
| 17 | 18 | ||
| 18 | } // namespace Shader | 19 | } // namespace Shader |
diff --git a/src/tests/common/param_package.cpp b/src/tests/common/param_package.cpp index 4c0f9654f..e31ca3544 100644 --- a/src/tests/common/param_package.cpp +++ b/src/tests/common/param_package.cpp | |||
| @@ -4,11 +4,13 @@ | |||
| 4 | 4 | ||
| 5 | #include <catch2/catch.hpp> | 5 | #include <catch2/catch.hpp> |
| 6 | #include <math.h> | 6 | #include <math.h> |
| 7 | #include "common/logging/backend.h" | ||
| 7 | #include "common/param_package.h" | 8 | #include "common/param_package.h" |
| 8 | 9 | ||
| 9 | namespace Common { | 10 | namespace Common { |
| 10 | 11 | ||
| 11 | TEST_CASE("ParamPackage", "[common]") { | 12 | TEST_CASE("ParamPackage", "[common]") { |
| 13 | Common::Log::DisableLoggingInTests(); | ||
| 12 | ParamPackage original{ | 14 | ParamPackage original{ |
| 13 | {"abc", "xyz"}, | 15 | {"abc", "xyz"}, |
| 14 | {"def", "42"}, | 16 | {"def", "42"}, |
diff --git a/src/video_core/buffer_cache/buffer_base.h b/src/video_core/buffer_cache/buffer_base.h index c3318095c..be2113f5a 100644 --- a/src/video_core/buffer_cache/buffer_base.h +++ b/src/video_core/buffer_cache/buffer_base.h | |||
| @@ -261,16 +261,6 @@ public: | |||
| 261 | stream_score += score; | 261 | stream_score += score; |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | /// Sets the new frame tick | ||
| 265 | void SetFrameTick(u64 new_frame_tick) noexcept { | ||
| 266 | frame_tick = new_frame_tick; | ||
| 267 | } | ||
| 268 | |||
| 269 | /// Returns the new frame tick | ||
| 270 | [[nodiscard]] u64 FrameTick() const noexcept { | ||
| 271 | return frame_tick; | ||
| 272 | } | ||
| 273 | |||
| 274 | /// Returns the likeliness of this being a stream buffer | 264 | /// Returns the likeliness of this being a stream buffer |
| 275 | [[nodiscard]] int StreamScore() const noexcept { | 265 | [[nodiscard]] int StreamScore() const noexcept { |
| 276 | return stream_score; | 266 | return stream_score; |
| @@ -307,6 +297,14 @@ public: | |||
| 307 | return words.size_bytes; | 297 | return words.size_bytes; |
| 308 | } | 298 | } |
| 309 | 299 | ||
| 300 | size_t getLRUID() const noexcept { | ||
| 301 | return lru_id; | ||
| 302 | } | ||
| 303 | |||
| 304 | void setLRUID(size_t lru_id_) { | ||
| 305 | lru_id = lru_id_; | ||
| 306 | } | ||
| 307 | |||
| 310 | private: | 308 | private: |
| 311 | template <Type type> | 309 | template <Type type> |
| 312 | u64* Array() noexcept { | 310 | u64* Array() noexcept { |
| @@ -603,9 +601,9 @@ private: | |||
| 603 | RasterizerInterface* rasterizer = nullptr; | 601 | RasterizerInterface* rasterizer = nullptr; |
| 604 | VAddr cpu_addr = 0; | 602 | VAddr cpu_addr = 0; |
| 605 | Words words; | 603 | Words words; |
| 606 | u64 frame_tick = 0; | ||
| 607 | BufferFlagBits flags{}; | 604 | BufferFlagBits flags{}; |
| 608 | int stream_score = 0; | 605 | int stream_score = 0; |
| 606 | size_t lru_id = SIZE_MAX; | ||
| 609 | }; | 607 | }; |
| 610 | 608 | ||
| 611 | } // namespace VideoCommon | 609 | } // namespace VideoCommon |
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 3b43554f9..7bfd57369 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include "common/common_types.h" | 20 | #include "common/common_types.h" |
| 21 | #include "common/div_ceil.h" | 21 | #include "common/div_ceil.h" |
| 22 | #include "common/literals.h" | 22 | #include "common/literals.h" |
| 23 | #include "common/lru_cache.h" | ||
| 23 | #include "common/microprofile.h" | 24 | #include "common/microprofile.h" |
| 24 | #include "common/scope_exit.h" | 25 | #include "common/scope_exit.h" |
| 25 | #include "common/settings.h" | 26 | #include "common/settings.h" |
| @@ -330,7 +331,7 @@ private: | |||
| 330 | template <bool insert> | 331 | template <bool insert> |
| 331 | void ChangeRegister(BufferId buffer_id); | 332 | void ChangeRegister(BufferId buffer_id); |
| 332 | 333 | ||
| 333 | void TouchBuffer(Buffer& buffer) const noexcept; | 334 | void TouchBuffer(Buffer& buffer, BufferId buffer_id) noexcept; |
| 334 | 335 | ||
| 335 | bool SynchronizeBuffer(Buffer& buffer, VAddr cpu_addr, u32 size); | 336 | bool SynchronizeBuffer(Buffer& buffer, VAddr cpu_addr, u32 size); |
| 336 | 337 | ||
| @@ -428,7 +429,11 @@ private: | |||
| 428 | size_t immediate_buffer_capacity = 0; | 429 | size_t immediate_buffer_capacity = 0; |
| 429 | std::unique_ptr<u8[]> immediate_buffer_alloc; | 430 | std::unique_ptr<u8[]> immediate_buffer_alloc; |
| 430 | 431 | ||
| 431 | typename SlotVector<Buffer>::Iterator deletion_iterator; | 432 | struct LRUItemParams { |
| 433 | using ObjectType = BufferId; | ||
| 434 | using TickType = u64; | ||
| 435 | }; | ||
| 436 | Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache; | ||
| 432 | u64 frame_tick = 0; | 437 | u64 frame_tick = 0; |
| 433 | u64 total_used_memory = 0; | 438 | u64 total_used_memory = 0; |
| 434 | 439 | ||
| @@ -445,7 +450,6 @@ BufferCache<P>::BufferCache(VideoCore::RasterizerInterface& rasterizer_, | |||
| 445 | kepler_compute{kepler_compute_}, gpu_memory{gpu_memory_}, cpu_memory{cpu_memory_} { | 450 | kepler_compute{kepler_compute_}, gpu_memory{gpu_memory_}, cpu_memory{cpu_memory_} { |
| 446 | // Ensure the first slot is used for the null buffer | 451 | // Ensure the first slot is used for the null buffer |
| 447 | void(slot_buffers.insert(runtime, NullBufferParams{})); | 452 | void(slot_buffers.insert(runtime, NullBufferParams{})); |
| 448 | deletion_iterator = slot_buffers.end(); | ||
| 449 | common_ranges.clear(); | 453 | common_ranges.clear(); |
| 450 | } | 454 | } |
| 451 | 455 | ||
| @@ -454,20 +458,17 @@ void BufferCache<P>::RunGarbageCollector() { | |||
| 454 | const bool aggressive_gc = total_used_memory >= CRITICAL_MEMORY; | 458 | const bool aggressive_gc = total_used_memory >= CRITICAL_MEMORY; |
| 455 | const u64 ticks_to_destroy = aggressive_gc ? 60 : 120; | 459 | const u64 ticks_to_destroy = aggressive_gc ? 60 : 120; |
| 456 | int num_iterations = aggressive_gc ? 64 : 32; | 460 | int num_iterations = aggressive_gc ? 64 : 32; |
| 457 | for (; num_iterations > 0; --num_iterations) { | 461 | const auto clean_up = [this, &num_iterations](BufferId buffer_id) { |
| 458 | if (deletion_iterator == slot_buffers.end()) { | 462 | if (num_iterations == 0) { |
| 459 | deletion_iterator = slot_buffers.begin(); | 463 | return true; |
| 460 | } | ||
| 461 | ++deletion_iterator; | ||
| 462 | if (deletion_iterator == slot_buffers.end()) { | ||
| 463 | break; | ||
| 464 | } | ||
| 465 | const auto [buffer_id, buffer] = *deletion_iterator; | ||
| 466 | if (buffer->FrameTick() + ticks_to_destroy < frame_tick) { | ||
| 467 | DownloadBufferMemory(*buffer); | ||
| 468 | DeleteBuffer(buffer_id); | ||
| 469 | } | 464 | } |
| 470 | } | 465 | --num_iterations; |
| 466 | auto& buffer = slot_buffers[buffer_id]; | ||
| 467 | DownloadBufferMemory(buffer); | ||
| 468 | DeleteBuffer(buffer_id); | ||
| 469 | return false; | ||
| 470 | }; | ||
| 471 | lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, clean_up); | ||
| 471 | } | 472 | } |
| 472 | 473 | ||
| 473 | template <class P> | 474 | template <class P> |
| @@ -485,7 +486,7 @@ void BufferCache<P>::TickFrame() { | |||
| 485 | const bool skip_preferred = hits * 256 < shots * 251; | 486 | const bool skip_preferred = hits * 256 < shots * 251; |
| 486 | uniform_buffer_skip_cache_size = skip_preferred ? DEFAULT_SKIP_CACHE_SIZE : 0; | 487 | uniform_buffer_skip_cache_size = skip_preferred ? DEFAULT_SKIP_CACHE_SIZE : 0; |
| 487 | 488 | ||
| 488 | if (Settings::values.use_caches_gc.GetValue() && total_used_memory >= EXPECTED_MEMORY) { | 489 | if (total_used_memory >= EXPECTED_MEMORY) { |
| 489 | RunGarbageCollector(); | 490 | RunGarbageCollector(); |
| 490 | } | 491 | } |
| 491 | ++frame_tick; | 492 | ++frame_tick; |
| @@ -954,7 +955,7 @@ bool BufferCache<P>::IsRegionCpuModified(VAddr addr, size_t size) { | |||
| 954 | template <class P> | 955 | template <class P> |
| 955 | void BufferCache<P>::BindHostIndexBuffer() { | 956 | void BufferCache<P>::BindHostIndexBuffer() { |
| 956 | Buffer& buffer = slot_buffers[index_buffer.buffer_id]; | 957 | Buffer& buffer = slot_buffers[index_buffer.buffer_id]; |
| 957 | TouchBuffer(buffer); | 958 | TouchBuffer(buffer, index_buffer.buffer_id); |
| 958 | const u32 offset = buffer.Offset(index_buffer.cpu_addr); | 959 | const u32 offset = buffer.Offset(index_buffer.cpu_addr); |
| 959 | const u32 size = index_buffer.size; | 960 | const u32 size = index_buffer.size; |
| 960 | SynchronizeBuffer(buffer, index_buffer.cpu_addr, size); | 961 | SynchronizeBuffer(buffer, index_buffer.cpu_addr, size); |
| @@ -975,7 +976,7 @@ void BufferCache<P>::BindHostVertexBuffers() { | |||
| 975 | for (u32 index = 0; index < NUM_VERTEX_BUFFERS; ++index) { | 976 | for (u32 index = 0; index < NUM_VERTEX_BUFFERS; ++index) { |
| 976 | const Binding& binding = vertex_buffers[index]; | 977 | const Binding& binding = vertex_buffers[index]; |
| 977 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 978 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 978 | TouchBuffer(buffer); | 979 | TouchBuffer(buffer, binding.buffer_id); |
| 979 | SynchronizeBuffer(buffer, binding.cpu_addr, binding.size); | 980 | SynchronizeBuffer(buffer, binding.cpu_addr, binding.size); |
| 980 | if (!flags[Dirty::VertexBuffer0 + index]) { | 981 | if (!flags[Dirty::VertexBuffer0 + index]) { |
| 981 | continue; | 982 | continue; |
| @@ -1011,7 +1012,7 @@ void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32 | |||
| 1011 | const VAddr cpu_addr = binding.cpu_addr; | 1012 | const VAddr cpu_addr = binding.cpu_addr; |
| 1012 | const u32 size = std::min(binding.size, (*uniform_buffer_sizes)[stage][index]); | 1013 | const u32 size = std::min(binding.size, (*uniform_buffer_sizes)[stage][index]); |
| 1013 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 1014 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 1014 | TouchBuffer(buffer); | 1015 | TouchBuffer(buffer, binding.buffer_id); |
| 1015 | const bool use_fast_buffer = binding.buffer_id != NULL_BUFFER_ID && | 1016 | const bool use_fast_buffer = binding.buffer_id != NULL_BUFFER_ID && |
| 1016 | size <= uniform_buffer_skip_cache_size && | 1017 | size <= uniform_buffer_skip_cache_size && |
| 1017 | !buffer.IsRegionGpuModified(cpu_addr, size); | 1018 | !buffer.IsRegionGpuModified(cpu_addr, size); |
| @@ -1083,7 +1084,7 @@ void BufferCache<P>::BindHostGraphicsStorageBuffers(size_t stage) { | |||
| 1083 | ForEachEnabledBit(enabled_storage_buffers[stage], [&](u32 index) { | 1084 | ForEachEnabledBit(enabled_storage_buffers[stage], [&](u32 index) { |
| 1084 | const Binding& binding = storage_buffers[stage][index]; | 1085 | const Binding& binding = storage_buffers[stage][index]; |
| 1085 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 1086 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 1086 | TouchBuffer(buffer); | 1087 | TouchBuffer(buffer, binding.buffer_id); |
| 1087 | const u32 size = binding.size; | 1088 | const u32 size = binding.size; |
| 1088 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 1089 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| 1089 | 1090 | ||
| @@ -1128,7 +1129,7 @@ void BufferCache<P>::BindHostTransformFeedbackBuffers() { | |||
| 1128 | for (u32 index = 0; index < NUM_TRANSFORM_FEEDBACK_BUFFERS; ++index) { | 1129 | for (u32 index = 0; index < NUM_TRANSFORM_FEEDBACK_BUFFERS; ++index) { |
| 1129 | const Binding& binding = transform_feedback_buffers[index]; | 1130 | const Binding& binding = transform_feedback_buffers[index]; |
| 1130 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 1131 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 1131 | TouchBuffer(buffer); | 1132 | TouchBuffer(buffer, binding.buffer_id); |
| 1132 | const u32 size = binding.size; | 1133 | const u32 size = binding.size; |
| 1133 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 1134 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| 1134 | 1135 | ||
| @@ -1148,7 +1149,7 @@ void BufferCache<P>::BindHostComputeUniformBuffers() { | |||
| 1148 | ForEachEnabledBit(enabled_compute_uniform_buffer_mask, [&](u32 index) { | 1149 | ForEachEnabledBit(enabled_compute_uniform_buffer_mask, [&](u32 index) { |
| 1149 | const Binding& binding = compute_uniform_buffers[index]; | 1150 | const Binding& binding = compute_uniform_buffers[index]; |
| 1150 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 1151 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 1151 | TouchBuffer(buffer); | 1152 | TouchBuffer(buffer, binding.buffer_id); |
| 1152 | const u32 size = std::min(binding.size, (*compute_uniform_buffer_sizes)[index]); | 1153 | const u32 size = std::min(binding.size, (*compute_uniform_buffer_sizes)[index]); |
| 1153 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 1154 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| 1154 | 1155 | ||
| @@ -1168,7 +1169,7 @@ void BufferCache<P>::BindHostComputeStorageBuffers() { | |||
| 1168 | ForEachEnabledBit(enabled_compute_storage_buffers, [&](u32 index) { | 1169 | ForEachEnabledBit(enabled_compute_storage_buffers, [&](u32 index) { |
| 1169 | const Binding& binding = compute_storage_buffers[index]; | 1170 | const Binding& binding = compute_storage_buffers[index]; |
| 1170 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 1171 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 1171 | TouchBuffer(buffer); | 1172 | TouchBuffer(buffer, binding.buffer_id); |
| 1172 | const u32 size = binding.size; | 1173 | const u32 size = binding.size; |
| 1173 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 1174 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| 1174 | 1175 | ||
| @@ -1513,11 +1514,11 @@ BufferId BufferCache<P>::CreateBuffer(VAddr cpu_addr, u32 wanted_size) { | |||
| 1513 | const OverlapResult overlap = ResolveOverlaps(cpu_addr, wanted_size); | 1514 | const OverlapResult overlap = ResolveOverlaps(cpu_addr, wanted_size); |
| 1514 | const u32 size = static_cast<u32>(overlap.end - overlap.begin); | 1515 | const u32 size = static_cast<u32>(overlap.end - overlap.begin); |
| 1515 | const BufferId new_buffer_id = slot_buffers.insert(runtime, rasterizer, overlap.begin, size); | 1516 | const BufferId new_buffer_id = slot_buffers.insert(runtime, rasterizer, overlap.begin, size); |
| 1516 | TouchBuffer(slot_buffers[new_buffer_id]); | ||
| 1517 | for (const BufferId overlap_id : overlap.ids) { | 1517 | for (const BufferId overlap_id : overlap.ids) { |
| 1518 | JoinOverlap(new_buffer_id, overlap_id, !overlap.has_stream_leap); | 1518 | JoinOverlap(new_buffer_id, overlap_id, !overlap.has_stream_leap); |
| 1519 | } | 1519 | } |
| 1520 | Register(new_buffer_id); | 1520 | Register(new_buffer_id); |
| 1521 | TouchBuffer(slot_buffers[new_buffer_id], new_buffer_id); | ||
| 1521 | return new_buffer_id; | 1522 | return new_buffer_id; |
| 1522 | } | 1523 | } |
| 1523 | 1524 | ||
| @@ -1534,12 +1535,14 @@ void BufferCache<P>::Unregister(BufferId buffer_id) { | |||
| 1534 | template <class P> | 1535 | template <class P> |
| 1535 | template <bool insert> | 1536 | template <bool insert> |
| 1536 | void BufferCache<P>::ChangeRegister(BufferId buffer_id) { | 1537 | void BufferCache<P>::ChangeRegister(BufferId buffer_id) { |
| 1537 | const Buffer& buffer = slot_buffers[buffer_id]; | 1538 | Buffer& buffer = slot_buffers[buffer_id]; |
| 1538 | const auto size = buffer.SizeBytes(); | 1539 | const auto size = buffer.SizeBytes(); |
| 1539 | if (insert) { | 1540 | if (insert) { |
| 1540 | total_used_memory += Common::AlignUp(size, 1024); | 1541 | total_used_memory += Common::AlignUp(size, 1024); |
| 1542 | buffer.setLRUID(lru_cache.Insert(buffer_id, frame_tick)); | ||
| 1541 | } else { | 1543 | } else { |
| 1542 | total_used_memory -= Common::AlignUp(size, 1024); | 1544 | total_used_memory -= Common::AlignUp(size, 1024); |
| 1545 | lru_cache.Free(buffer.getLRUID()); | ||
| 1543 | } | 1546 | } |
| 1544 | const VAddr cpu_addr_begin = buffer.CpuAddr(); | 1547 | const VAddr cpu_addr_begin = buffer.CpuAddr(); |
| 1545 | const VAddr cpu_addr_end = cpu_addr_begin + size; | 1548 | const VAddr cpu_addr_end = cpu_addr_begin + size; |
| @@ -1555,8 +1558,10 @@ void BufferCache<P>::ChangeRegister(BufferId buffer_id) { | |||
| 1555 | } | 1558 | } |
| 1556 | 1559 | ||
| 1557 | template <class P> | 1560 | template <class P> |
| 1558 | void BufferCache<P>::TouchBuffer(Buffer& buffer) const noexcept { | 1561 | void BufferCache<P>::TouchBuffer(Buffer& buffer, BufferId buffer_id) noexcept { |
| 1559 | buffer.SetFrameTick(frame_tick); | 1562 | if (buffer_id != NULL_BUFFER_ID) { |
| 1563 | lru_cache.Touch(buffer.getLRUID(), frame_tick); | ||
| 1564 | } | ||
| 1560 | } | 1565 | } |
| 1561 | 1566 | ||
| 1562 | template <class P> | 1567 | template <class P> |
diff --git a/src/video_core/command_classes/codecs/vp9.cpp b/src/video_core/command_classes/codecs/vp9.cpp index 70030066a..d7e749485 100644 --- a/src/video_core/command_classes/codecs/vp9.cpp +++ b/src/video_core/command_classes/codecs/vp9.cpp | |||
| @@ -742,6 +742,7 @@ VpxBitStreamWriter VP9::ComposeUncompressedHeader() { | |||
| 742 | uncomp_writer.WriteDeltaQ(current_frame_info.uv_dc_delta_q); | 742 | uncomp_writer.WriteDeltaQ(current_frame_info.uv_dc_delta_q); |
| 743 | uncomp_writer.WriteDeltaQ(current_frame_info.uv_ac_delta_q); | 743 | uncomp_writer.WriteDeltaQ(current_frame_info.uv_ac_delta_q); |
| 744 | 744 | ||
| 745 | ASSERT(!current_frame_info.segment_enabled); | ||
| 745 | uncomp_writer.WriteBit(false); // Segmentation enabled (TODO). | 746 | uncomp_writer.WriteBit(false); // Segmentation enabled (TODO). |
| 746 | 747 | ||
| 747 | const s32 min_tile_cols_log2 = CalcMinLog2TileCols(current_frame_info.frame_size.width); | 748 | const s32 min_tile_cols_log2 = CalcMinLog2TileCols(current_frame_info.frame_size.width); |
diff --git a/src/video_core/command_classes/codecs/vp9_types.h b/src/video_core/command_classes/codecs/vp9_types.h index 87eafdb03..3b1ed4b3a 100644 --- a/src/video_core/command_classes/codecs/vp9_types.h +++ b/src/video_core/command_classes/codecs/vp9_types.h | |||
| @@ -22,7 +22,7 @@ struct Vp9FrameDimensions { | |||
| 22 | }; | 22 | }; |
| 23 | static_assert(sizeof(Vp9FrameDimensions) == 0x8, "Vp9 Vp9FrameDimensions is an invalid size"); | 23 | static_assert(sizeof(Vp9FrameDimensions) == 0x8, "Vp9 Vp9FrameDimensions is an invalid size"); |
| 24 | 24 | ||
| 25 | enum FrameFlags : u32 { | 25 | enum class FrameFlags : u32 { |
| 26 | IsKeyFrame = 1 << 0, | 26 | IsKeyFrame = 1 << 0, |
| 27 | LastFrameIsKeyFrame = 1 << 1, | 27 | LastFrameIsKeyFrame = 1 << 1, |
| 28 | FrameSizeChanged = 1 << 2, | 28 | FrameSizeChanged = 1 << 2, |
| @@ -30,6 +30,7 @@ enum FrameFlags : u32 { | |||
| 30 | LastShowFrame = 1 << 4, | 30 | LastShowFrame = 1 << 4, |
| 31 | IntraOnly = 1 << 5, | 31 | IntraOnly = 1 << 5, |
| 32 | }; | 32 | }; |
| 33 | DECLARE_ENUM_FLAG_OPERATORS(FrameFlags) | ||
| 33 | 34 | ||
| 34 | enum class TxSize { | 35 | enum class TxSize { |
| 35 | Tx4x4 = 0, // 4x4 transform | 36 | Tx4x4 = 0, // 4x4 transform |
| @@ -92,44 +93,34 @@ struct Vp9EntropyProbs { | |||
| 92 | static_assert(sizeof(Vp9EntropyProbs) == 0x7B4, "Vp9EntropyProbs is an invalid size"); | 93 | static_assert(sizeof(Vp9EntropyProbs) == 0x7B4, "Vp9EntropyProbs is an invalid size"); |
| 93 | 94 | ||
| 94 | struct Vp9PictureInfo { | 95 | struct Vp9PictureInfo { |
| 95 | bool is_key_frame; | 96 | u32 bitstream_size; |
| 96 | bool intra_only; | 97 | std::array<u64, 4> frame_offsets; |
| 97 | bool last_frame_was_key; | ||
| 98 | bool frame_size_changed; | ||
| 99 | bool error_resilient_mode; | ||
| 100 | bool last_frame_shown; | ||
| 101 | bool show_frame; | ||
| 102 | std::array<s8, 4> ref_frame_sign_bias; | 98 | std::array<s8, 4> ref_frame_sign_bias; |
| 103 | s32 base_q_index; | 99 | s32 base_q_index; |
| 104 | s32 y_dc_delta_q; | 100 | s32 y_dc_delta_q; |
| 105 | s32 uv_dc_delta_q; | 101 | s32 uv_dc_delta_q; |
| 106 | s32 uv_ac_delta_q; | 102 | s32 uv_ac_delta_q; |
| 107 | bool lossless; | ||
| 108 | s32 transform_mode; | 103 | s32 transform_mode; |
| 109 | bool allow_high_precision_mv; | ||
| 110 | s32 interp_filter; | 104 | s32 interp_filter; |
| 111 | s32 reference_mode; | 105 | s32 reference_mode; |
| 112 | s8 comp_fixed_ref; | ||
| 113 | std::array<s8, 2> comp_var_ref; | ||
| 114 | s32 log2_tile_cols; | 106 | s32 log2_tile_cols; |
| 115 | s32 log2_tile_rows; | 107 | s32 log2_tile_rows; |
| 116 | bool segment_enabled; | ||
| 117 | bool segment_map_update; | ||
| 118 | bool segment_map_temporal_update; | ||
| 119 | s32 segment_abs_delta; | ||
| 120 | std::array<u32, 8> segment_feature_enable; | ||
| 121 | std::array<std::array<s16, 4>, 8> segment_feature_data; | ||
| 122 | bool mode_ref_delta_enabled; | ||
| 123 | bool use_prev_in_find_mv_refs; | ||
| 124 | std::array<s8, 4> ref_deltas; | 108 | std::array<s8, 4> ref_deltas; |
| 125 | std::array<s8, 2> mode_deltas; | 109 | std::array<s8, 2> mode_deltas; |
| 126 | Vp9EntropyProbs entropy; | 110 | Vp9EntropyProbs entropy; |
| 127 | Vp9FrameDimensions frame_size; | 111 | Vp9FrameDimensions frame_size; |
| 128 | u8 first_level; | 112 | u8 first_level; |
| 129 | u8 sharpness_level; | 113 | u8 sharpness_level; |
| 130 | u32 bitstream_size; | 114 | bool is_key_frame; |
| 131 | std::array<u64, 4> frame_offsets; | 115 | bool intra_only; |
| 132 | std::array<bool, 4> refresh_frame; | 116 | bool last_frame_was_key; |
| 117 | bool error_resilient_mode; | ||
| 118 | bool last_frame_shown; | ||
| 119 | bool show_frame; | ||
| 120 | bool lossless; | ||
| 121 | bool allow_high_precision_mv; | ||
| 122 | bool segment_enabled; | ||
| 123 | bool mode_ref_delta_enabled; | ||
| 133 | }; | 124 | }; |
| 134 | 125 | ||
| 135 | struct Vp9FrameContainer { | 126 | struct Vp9FrameContainer { |
| @@ -145,7 +136,7 @@ struct PictureInfo { | |||
| 145 | Vp9FrameDimensions golden_frame_size; ///< 0x50 | 136 | Vp9FrameDimensions golden_frame_size; ///< 0x50 |
| 146 | Vp9FrameDimensions alt_frame_size; ///< 0x58 | 137 | Vp9FrameDimensions alt_frame_size; ///< 0x58 |
| 147 | Vp9FrameDimensions current_frame_size; ///< 0x60 | 138 | Vp9FrameDimensions current_frame_size; ///< 0x60 |
| 148 | u32 vp9_flags; ///< 0x68 | 139 | FrameFlags vp9_flags; ///< 0x68 |
| 149 | std::array<s8, 4> ref_frame_sign_bias; ///< 0x6C | 140 | std::array<s8, 4> ref_frame_sign_bias; ///< 0x6C |
| 150 | u8 first_level; ///< 0x70 | 141 | u8 first_level; ///< 0x70 |
| 151 | u8 sharpness_level; ///< 0x71 | 142 | u8 sharpness_level; ///< 0x71 |
| @@ -158,60 +149,43 @@ struct PictureInfo { | |||
| 158 | u8 allow_high_precision_mv; ///< 0x78 | 149 | u8 allow_high_precision_mv; ///< 0x78 |
| 159 | u8 interp_filter; ///< 0x79 | 150 | u8 interp_filter; ///< 0x79 |
| 160 | u8 reference_mode; ///< 0x7A | 151 | u8 reference_mode; ///< 0x7A |
| 161 | s8 comp_fixed_ref; ///< 0x7B | 152 | INSERT_PADDING_BYTES_NOINIT(3); ///< 0x7B |
| 162 | std::array<s8, 2> comp_var_ref; ///< 0x7C | ||
| 163 | u8 log2_tile_cols; ///< 0x7E | 153 | u8 log2_tile_cols; ///< 0x7E |
| 164 | u8 log2_tile_rows; ///< 0x7F | 154 | u8 log2_tile_rows; ///< 0x7F |
| 165 | Segmentation segmentation; ///< 0x80 | 155 | Segmentation segmentation; ///< 0x80 |
| 166 | LoopFilter loop_filter; ///< 0xE4 | 156 | LoopFilter loop_filter; ///< 0xE4 |
| 167 | INSERT_PADDING_BYTES_NOINIT(5); ///< 0xEB | 157 | INSERT_PADDING_BYTES_NOINIT(21); ///< 0xEB |
| 168 | u32 surface_params; ///< 0xF0 | ||
| 169 | INSERT_PADDING_WORDS_NOINIT(3); ///< 0xF4 | ||
| 170 | 158 | ||
| 171 | [[nodiscard]] Vp9PictureInfo Convert() const { | 159 | [[nodiscard]] Vp9PictureInfo Convert() const { |
| 172 | return { | 160 | return { |
| 173 | .is_key_frame = (vp9_flags & FrameFlags::IsKeyFrame) != 0, | 161 | .bitstream_size = bitstream_size, |
| 174 | .intra_only = (vp9_flags & FrameFlags::IntraOnly) != 0, | 162 | .frame_offsets{}, |
| 175 | .last_frame_was_key = (vp9_flags & FrameFlags::LastFrameIsKeyFrame) != 0, | ||
| 176 | .frame_size_changed = (vp9_flags & FrameFlags::FrameSizeChanged) != 0, | ||
| 177 | .error_resilient_mode = (vp9_flags & FrameFlags::ErrorResilientMode) != 0, | ||
| 178 | .last_frame_shown = (vp9_flags & FrameFlags::LastShowFrame) != 0, | ||
| 179 | .show_frame = true, | ||
| 180 | .ref_frame_sign_bias = ref_frame_sign_bias, | 163 | .ref_frame_sign_bias = ref_frame_sign_bias, |
| 181 | .base_q_index = base_q_index, | 164 | .base_q_index = base_q_index, |
| 182 | .y_dc_delta_q = y_dc_delta_q, | 165 | .y_dc_delta_q = y_dc_delta_q, |
| 183 | .uv_dc_delta_q = uv_dc_delta_q, | 166 | .uv_dc_delta_q = uv_dc_delta_q, |
| 184 | .uv_ac_delta_q = uv_ac_delta_q, | 167 | .uv_ac_delta_q = uv_ac_delta_q, |
| 185 | .lossless = lossless != 0, | ||
| 186 | .transform_mode = tx_mode, | 168 | .transform_mode = tx_mode, |
| 187 | .allow_high_precision_mv = allow_high_precision_mv != 0, | ||
| 188 | .interp_filter = interp_filter, | 169 | .interp_filter = interp_filter, |
| 189 | .reference_mode = reference_mode, | 170 | .reference_mode = reference_mode, |
| 190 | .comp_fixed_ref = comp_fixed_ref, | ||
| 191 | .comp_var_ref = comp_var_ref, | ||
| 192 | .log2_tile_cols = log2_tile_cols, | 171 | .log2_tile_cols = log2_tile_cols, |
| 193 | .log2_tile_rows = log2_tile_rows, | 172 | .log2_tile_rows = log2_tile_rows, |
| 194 | .segment_enabled = segmentation.enabled != 0, | ||
| 195 | .segment_map_update = segmentation.update_map != 0, | ||
| 196 | .segment_map_temporal_update = segmentation.temporal_update != 0, | ||
| 197 | .segment_abs_delta = segmentation.abs_delta, | ||
| 198 | .segment_feature_enable = segmentation.feature_mask, | ||
| 199 | .segment_feature_data = segmentation.feature_data, | ||
| 200 | .mode_ref_delta_enabled = loop_filter.mode_ref_delta_enabled != 0, | ||
| 201 | .use_prev_in_find_mv_refs = !(vp9_flags == (FrameFlags::ErrorResilientMode)) && | ||
| 202 | !(vp9_flags == (FrameFlags::FrameSizeChanged)) && | ||
| 203 | !(vp9_flags == (FrameFlags::IntraOnly)) && | ||
| 204 | (vp9_flags == (FrameFlags::LastShowFrame)) && | ||
| 205 | !(vp9_flags == (FrameFlags::LastFrameIsKeyFrame)), | ||
| 206 | .ref_deltas = loop_filter.ref_deltas, | 173 | .ref_deltas = loop_filter.ref_deltas, |
| 207 | .mode_deltas = loop_filter.mode_deltas, | 174 | .mode_deltas = loop_filter.mode_deltas, |
| 208 | .entropy{}, | 175 | .entropy{}, |
| 209 | .frame_size = current_frame_size, | 176 | .frame_size = current_frame_size, |
| 210 | .first_level = first_level, | 177 | .first_level = first_level, |
| 211 | .sharpness_level = sharpness_level, | 178 | .sharpness_level = sharpness_level, |
| 212 | .bitstream_size = bitstream_size, | 179 | .is_key_frame = True(vp9_flags & FrameFlags::IsKeyFrame), |
| 213 | .frame_offsets{}, | 180 | .intra_only = True(vp9_flags & FrameFlags::IntraOnly), |
| 214 | .refresh_frame{}, | 181 | .last_frame_was_key = True(vp9_flags & FrameFlags::LastFrameIsKeyFrame), |
| 182 | .error_resilient_mode = True(vp9_flags & FrameFlags::ErrorResilientMode), | ||
| 183 | .last_frame_shown = True(vp9_flags & FrameFlags::LastShowFrame), | ||
| 184 | .show_frame = true, | ||
| 185 | .lossless = lossless != 0, | ||
| 186 | .allow_high_precision_mv = allow_high_precision_mv != 0, | ||
| 187 | .segment_enabled = segmentation.enabled != 0, | ||
| 188 | .mode_ref_delta_enabled = loop_filter.mode_ref_delta_enabled != 0, | ||
| 215 | }; | 189 | }; |
| 216 | } | 190 | } |
| 217 | }; | 191 | }; |
| @@ -316,7 +290,6 @@ ASSERT_POSITION(last_frame_size, 0x48); | |||
| 316 | ASSERT_POSITION(first_level, 0x70); | 290 | ASSERT_POSITION(first_level, 0x70); |
| 317 | ASSERT_POSITION(segmentation, 0x80); | 291 | ASSERT_POSITION(segmentation, 0x80); |
| 318 | ASSERT_POSITION(loop_filter, 0xE4); | 292 | ASSERT_POSITION(loop_filter, 0xE4); |
| 319 | ASSERT_POSITION(surface_params, 0xF0); | ||
| 320 | #undef ASSERT_POSITION | 293 | #undef ASSERT_POSITION |
| 321 | 294 | ||
| 322 | #define ASSERT_POSITION(field_name, position) \ | 295 | #define ASSERT_POSITION(field_name, position) \ |
diff --git a/src/video_core/command_classes/vic.cpp b/src/video_core/command_classes/vic.cpp index d5e77941c..0ee07f398 100644 --- a/src/video_core/command_classes/vic.cpp +++ b/src/video_core/command_classes/vic.cpp | |||
| @@ -96,12 +96,11 @@ void Vic::Execute() { | |||
| 96 | if (!converted_frame_buffer) { | 96 | if (!converted_frame_buffer) { |
| 97 | converted_frame_buffer = AVMallocPtr{static_cast<u8*>(av_malloc(linear_size)), av_free}; | 97 | converted_frame_buffer = AVMallocPtr{static_cast<u8*>(av_malloc(linear_size)), av_free}; |
| 98 | } | 98 | } |
| 99 | 99 | const std::array<int, 4> converted_stride{frame->width * 4, frame->height * 4, 0, 0}; | |
| 100 | const int converted_stride{frame->width * 4}; | ||
| 101 | u8* const converted_frame_buf_addr{converted_frame_buffer.get()}; | 100 | u8* const converted_frame_buf_addr{converted_frame_buffer.get()}; |
| 102 | 101 | ||
| 103 | sws_scale(scaler_ctx, frame->data, frame->linesize, 0, frame->height, | 102 | sws_scale(scaler_ctx, frame->data, frame->linesize, 0, frame->height, |
| 104 | &converted_frame_buf_addr, &converted_stride); | 103 | &converted_frame_buf_addr, converted_stride.data()); |
| 105 | 104 | ||
| 106 | const u32 blk_kind = static_cast<u32>(config.block_linear_kind); | 105 | const u32 blk_kind = static_cast<u32>(config.block_linear_kind); |
| 107 | if (blk_kind != 0) { | 106 | if (blk_kind != 0) { |
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index 1aa43523a..7f4ca6282 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h | |||
| @@ -475,10 +475,10 @@ public: | |||
| 475 | 475 | ||
| 476 | // These values are used by Nouveau and some games. | 476 | // These values are used by Nouveau and some games. |
| 477 | AddGL = 0x8006, | 477 | AddGL = 0x8006, |
| 478 | SubtractGL = 0x8007, | 478 | MinGL = 0x8007, |
| 479 | ReverseSubtractGL = 0x8008, | 479 | MaxGL = 0x8008, |
| 480 | MinGL = 0x800a, | 480 | SubtractGL = 0x800a, |
| 481 | MaxGL = 0x800b | 481 | ReverseSubtractGL = 0x800b |
| 482 | }; | 482 | }; |
| 483 | 483 | ||
| 484 | enum class Factor : u32 { | 484 | enum class Factor : u32 { |
diff --git a/src/video_core/macro/macro_jit_x64.h b/src/video_core/macro/macro_jit_x64.h index 7f50ac2f8..d03d480b4 100644 --- a/src/video_core/macro/macro_jit_x64.h +++ b/src/video_core/macro/macro_jit_x64.h | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <bitset> | 8 | #include <bitset> |
| 9 | #include <xbyak.h> | 9 | #include <xbyak/xbyak.h> |
| 10 | #include "common/bit_field.h" | 10 | #include "common/bit_field.h" |
| 11 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 12 | #include "common/x64/xbyak_abi.h" | 12 | #include "common/x64/xbyak_abi.h" |
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index 882eff880..c60ed6453 100644 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp | |||
| @@ -463,6 +463,7 @@ std::vector<std::pair<GPUVAddr, std::size_t>> MemoryManager::GetSubmappedRange( | |||
| 463 | ++page_index; | 463 | ++page_index; |
| 464 | page_offset = 0; | 464 | page_offset = 0; |
| 465 | remaining_size -= num_bytes; | 465 | remaining_size -= num_bytes; |
| 466 | old_page_addr = page_addr; | ||
| 466 | } | 467 | } |
| 467 | split(); | 468 | split(); |
| 468 | return result; | 469 | return result; |
diff --git a/src/video_core/renderer_opengl/gl_device.h b/src/video_core/renderer_opengl/gl_device.h index ee992aed4..de9e41659 100644 --- a/src/video_core/renderer_opengl/gl_device.h +++ b/src/video_core/renderer_opengl/gl_device.h | |||
| @@ -156,6 +156,10 @@ public: | |||
| 156 | return shader_backend; | 156 | return shader_backend; |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | bool IsAmd() const { | ||
| 160 | return vendor_name == "ATI Technologies Inc."; | ||
| 161 | } | ||
| 162 | |||
| 159 | private: | 163 | private: |
| 160 | static bool TestVariableAoffi(); | 164 | static bool TestVariableAoffi(); |
| 161 | static bool TestPreciseBug(); | 165 | static bool TestPreciseBug(); |
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index 1f4dda17e..b0e14182e 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp | |||
| @@ -219,6 +219,7 @@ ShaderCache::ShaderCache(RasterizerOpenGL& rasterizer_, Core::Frontend::EmuWindo | |||
| 219 | host_info{ | 219 | host_info{ |
| 220 | .support_float16 = false, | 220 | .support_float16 = false, |
| 221 | .support_int64 = device.HasShaderInt64(), | 221 | .support_int64 = device.HasShaderInt64(), |
| 222 | .needs_demote_reorder = device.IsAmd(), | ||
| 222 | } { | 223 | } { |
| 223 | if (use_asynchronous_shaders) { | 224 | if (use_asynchronous_shaders) { |
| 224 | workers = CreateWorkers(); | 225 | workers = CreateWorkers(); |
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 7c9b0d6db..9ff0a28cd 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp | |||
| @@ -164,7 +164,8 @@ void RendererVulkan::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { | |||
| 164 | blit_screen.Recreate(); | 164 | blit_screen.Recreate(); |
| 165 | } | 165 | } |
| 166 | const VkSemaphore render_semaphore = blit_screen.DrawToSwapchain(*framebuffer, use_accelerated); | 166 | const VkSemaphore render_semaphore = blit_screen.DrawToSwapchain(*framebuffer, use_accelerated); |
| 167 | scheduler.Flush(render_semaphore); | 167 | const VkSemaphore present_semaphore = swapchain.CurrentPresentSemaphore(); |
| 168 | scheduler.Flush(render_semaphore, present_semaphore); | ||
| 168 | scheduler.WaitWorker(); | 169 | scheduler.WaitWorker(); |
| 169 | swapchain.Present(render_semaphore); | 170 | swapchain.Present(render_semaphore); |
| 170 | 171 | ||
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.cpp b/src/video_core/renderer_vulkan/vk_blit_screen.cpp index 5c43b8acf..888bc7392 100644 --- a/src/video_core/renderer_vulkan/vk_blit_screen.cpp +++ b/src/video_core/renderer_vulkan/vk_blit_screen.cpp | |||
| @@ -159,11 +159,13 @@ VkSemaphore VKBlitScreen::Draw(const Tegra::FramebufferConfig& framebuffer, | |||
| 159 | 159 | ||
| 160 | const VAddr framebuffer_addr = framebuffer.address + framebuffer.offset; | 160 | const VAddr framebuffer_addr = framebuffer.address + framebuffer.offset; |
| 161 | const u8* const host_ptr = cpu_memory.GetPointer(framebuffer_addr); | 161 | const u8* const host_ptr = cpu_memory.GetPointer(framebuffer_addr); |
| 162 | const size_t size_bytes = GetSizeInBytes(framebuffer); | ||
| 163 | 162 | ||
| 164 | // TODO(Rodrigo): Read this from HLE | 163 | // TODO(Rodrigo): Read this from HLE |
| 165 | constexpr u32 block_height_log2 = 4; | 164 | constexpr u32 block_height_log2 = 4; |
| 166 | const u32 bytes_per_pixel = GetBytesPerPixel(framebuffer); | 165 | const u32 bytes_per_pixel = GetBytesPerPixel(framebuffer); |
| 166 | const u64 size_bytes{Tegra::Texture::CalculateSize(true, bytes_per_pixel, | ||
| 167 | framebuffer.stride, framebuffer.height, | ||
| 168 | 1, block_height_log2, 0)}; | ||
| 167 | Tegra::Texture::UnswizzleTexture( | 169 | Tegra::Texture::UnswizzleTexture( |
| 168 | mapped_span.subspan(image_offset, size_bytes), std::span(host_ptr, size_bytes), | 170 | mapped_span.subspan(image_offset, size_bytes), std::span(host_ptr, size_bytes), |
| 169 | bytes_per_pixel, framebuffer.width, framebuffer.height, 1, block_height_log2, 0); | 171 | bytes_per_pixel, framebuffer.width, framebuffer.height, 1, block_height_log2, 0); |
| @@ -356,7 +358,7 @@ void VKBlitScreen::CreateDescriptorPool() { | |||
| 356 | void VKBlitScreen::CreateRenderPass() { | 358 | void VKBlitScreen::CreateRenderPass() { |
| 357 | const VkAttachmentDescription color_attachment{ | 359 | const VkAttachmentDescription color_attachment{ |
| 358 | .flags = 0, | 360 | .flags = 0, |
| 359 | .format = swapchain.GetImageFormat(), | 361 | .format = swapchain.GetImageViewFormat(), |
| 360 | .samples = VK_SAMPLE_COUNT_1_BIT, | 362 | .samples = VK_SAMPLE_COUNT_1_BIT, |
| 361 | .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR, | 363 | .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR, |
| 362 | .storeOp = VK_ATTACHMENT_STORE_OP_STORE, | 364 | .storeOp = VK_ATTACHMENT_STORE_OP_STORE, |
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index a37ca1fdf..31bfbcb06 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -281,7 +281,7 @@ PipelineCache::PipelineCache(RasterizerVulkan& rasterizer_, Tegra::Engines::Maxw | |||
| 281 | .supported_spirv = device.IsKhrSpirv1_4Supported() ? 0x00010400U : 0x00010000U, | 281 | .supported_spirv = device.IsKhrSpirv1_4Supported() ? 0x00010400U : 0x00010000U, |
| 282 | .unified_descriptor_binding = true, | 282 | .unified_descriptor_binding = true, |
| 283 | .support_descriptor_aliasing = true, | 283 | .support_descriptor_aliasing = true, |
| 284 | .support_int8 = true, | 284 | .support_int8 = device.IsInt8Supported(), |
| 285 | .support_int16 = device.IsShaderInt16Supported(), | 285 | .support_int16 = device.IsShaderInt16Supported(), |
| 286 | .support_int64 = device.IsShaderInt64Supported(), | 286 | .support_int64 = device.IsShaderInt64Supported(), |
| 287 | .support_vertex_instance_id = false, | 287 | .support_vertex_instance_id = false, |
| @@ -325,6 +325,8 @@ PipelineCache::PipelineCache(RasterizerVulkan& rasterizer_, Tegra::Engines::Maxw | |||
| 325 | host_info = Shader::HostTranslateInfo{ | 325 | host_info = Shader::HostTranslateInfo{ |
| 326 | .support_float16 = device.IsFloat16Supported(), | 326 | .support_float16 = device.IsFloat16Supported(), |
| 327 | .support_int64 = device.IsShaderInt64Supported(), | 327 | .support_int64 = device.IsShaderInt64Supported(), |
| 328 | .needs_demote_reorder = driver_id == VK_DRIVER_ID_AMD_PROPRIETARY_KHR || | ||
| 329 | driver_id == VK_DRIVER_ID_AMD_OPEN_SOURCE_KHR, | ||
| 328 | }; | 330 | }; |
| 329 | } | 331 | } |
| 330 | 332 | ||
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 3ac18ea54..841a6b846 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp | |||
| @@ -228,9 +228,7 @@ void RasterizerVulkan::Clear() { | |||
| 228 | }; | 228 | }; |
| 229 | 229 | ||
| 230 | const u32 color_attachment = regs.clear_buffers.RT; | 230 | const u32 color_attachment = regs.clear_buffers.RT; |
| 231 | const auto attachment_aspect_mask = framebuffer->ImageRanges()[color_attachment].aspectMask; | 231 | if (use_color && framebuffer->HasAspectColorBit(color_attachment)) { |
| 232 | const bool is_color_rt = (attachment_aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0; | ||
| 233 | if (use_color && is_color_rt) { | ||
| 234 | VkClearValue clear_value; | 232 | VkClearValue clear_value; |
| 235 | std::memcpy(clear_value.color.float32, regs.clear_color, sizeof(regs.clear_color)); | 233 | std::memcpy(clear_value.color.float32, regs.clear_color, sizeof(regs.clear_color)); |
| 236 | 234 | ||
| @@ -248,12 +246,15 @@ void RasterizerVulkan::Clear() { | |||
| 248 | return; | 246 | return; |
| 249 | } | 247 | } |
| 250 | VkImageAspectFlags aspect_flags = 0; | 248 | VkImageAspectFlags aspect_flags = 0; |
| 251 | if (use_depth) { | 249 | if (use_depth && framebuffer->HasAspectDepthBit()) { |
| 252 | aspect_flags |= VK_IMAGE_ASPECT_DEPTH_BIT; | 250 | aspect_flags |= VK_IMAGE_ASPECT_DEPTH_BIT; |
| 253 | } | 251 | } |
| 254 | if (use_stencil) { | 252 | if (use_stencil && framebuffer->HasAspectStencilBit()) { |
| 255 | aspect_flags |= VK_IMAGE_ASPECT_STENCIL_BIT; | 253 | aspect_flags |= VK_IMAGE_ASPECT_STENCIL_BIT; |
| 256 | } | 254 | } |
| 255 | if (aspect_flags == 0) { | ||
| 256 | return; | ||
| 257 | } | ||
| 257 | scheduler.Record([clear_depth = regs.clear_depth, clear_stencil = regs.clear_stencil, | 258 | scheduler.Record([clear_depth = regs.clear_depth, clear_stencil = regs.clear_stencil, |
| 258 | clear_rect, aspect_flags](vk::CommandBuffer cmdbuf) { | 259 | clear_rect, aspect_flags](vk::CommandBuffer cmdbuf) { |
| 259 | VkClearAttachment attachment; | 260 | VkClearAttachment attachment; |
diff --git a/src/video_core/renderer_vulkan/vk_scheduler.cpp b/src/video_core/renderer_vulkan/vk_scheduler.cpp index 4840962de..1d438787a 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.cpp +++ b/src/video_core/renderer_vulkan/vk_scheduler.cpp | |||
| @@ -55,14 +55,14 @@ VKScheduler::~VKScheduler() { | |||
| 55 | worker_thread.join(); | 55 | worker_thread.join(); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | void VKScheduler::Flush(VkSemaphore semaphore) { | 58 | void VKScheduler::Flush(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore) { |
| 59 | SubmitExecution(semaphore); | 59 | SubmitExecution(signal_semaphore, wait_semaphore); |
| 60 | AllocateNewContext(); | 60 | AllocateNewContext(); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | void VKScheduler::Finish(VkSemaphore semaphore) { | 63 | void VKScheduler::Finish(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore) { |
| 64 | const u64 presubmit_tick = CurrentTick(); | 64 | const u64 presubmit_tick = CurrentTick(); |
| 65 | SubmitExecution(semaphore); | 65 | SubmitExecution(signal_semaphore, wait_semaphore); |
| 66 | WaitWorker(); | 66 | WaitWorker(); |
| 67 | Wait(presubmit_tick); | 67 | Wait(presubmit_tick); |
| 68 | AllocateNewContext(); | 68 | AllocateNewContext(); |
| @@ -171,37 +171,41 @@ void VKScheduler::AllocateWorkerCommandBuffer() { | |||
| 171 | }); | 171 | }); |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | void VKScheduler::SubmitExecution(VkSemaphore semaphore) { | 174 | void VKScheduler::SubmitExecution(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore) { |
| 175 | EndPendingOperations(); | 175 | EndPendingOperations(); |
| 176 | InvalidateState(); | 176 | InvalidateState(); |
| 177 | 177 | ||
| 178 | const u64 signal_value = master_semaphore->NextTick(); | 178 | const u64 signal_value = master_semaphore->NextTick(); |
| 179 | Record([semaphore, signal_value, this](vk::CommandBuffer cmdbuf) { | 179 | Record([signal_semaphore, wait_semaphore, signal_value, this](vk::CommandBuffer cmdbuf) { |
| 180 | cmdbuf.End(); | 180 | cmdbuf.End(); |
| 181 | |||
| 182 | const u32 num_signal_semaphores = semaphore ? 2U : 1U; | ||
| 183 | |||
| 184 | const u64 wait_value = signal_value - 1; | ||
| 185 | const VkPipelineStageFlags wait_stage_mask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; | ||
| 186 | |||
| 187 | const VkSemaphore timeline_semaphore = master_semaphore->Handle(); | 181 | const VkSemaphore timeline_semaphore = master_semaphore->Handle(); |
| 182 | |||
| 183 | const u32 num_signal_semaphores = signal_semaphore ? 2U : 1U; | ||
| 188 | const std::array signal_values{signal_value, u64(0)}; | 184 | const std::array signal_values{signal_value, u64(0)}; |
| 189 | const std::array signal_semaphores{timeline_semaphore, semaphore}; | 185 | const std::array signal_semaphores{timeline_semaphore, signal_semaphore}; |
| 186 | |||
| 187 | const u32 num_wait_semaphores = wait_semaphore ? 2U : 1U; | ||
| 188 | const std::array wait_values{signal_value - 1, u64(1)}; | ||
| 189 | const std::array wait_semaphores{timeline_semaphore, wait_semaphore}; | ||
| 190 | static constexpr std::array<VkPipelineStageFlags, 2> wait_stage_masks{ | ||
| 191 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, | ||
| 192 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, | ||
| 193 | }; | ||
| 190 | 194 | ||
| 191 | const VkTimelineSemaphoreSubmitInfoKHR timeline_si{ | 195 | const VkTimelineSemaphoreSubmitInfoKHR timeline_si{ |
| 192 | .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR, | 196 | .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR, |
| 193 | .pNext = nullptr, | 197 | .pNext = nullptr, |
| 194 | .waitSemaphoreValueCount = 1, | 198 | .waitSemaphoreValueCount = num_wait_semaphores, |
| 195 | .pWaitSemaphoreValues = &wait_value, | 199 | .pWaitSemaphoreValues = wait_values.data(), |
| 196 | .signalSemaphoreValueCount = num_signal_semaphores, | 200 | .signalSemaphoreValueCount = num_signal_semaphores, |
| 197 | .pSignalSemaphoreValues = signal_values.data(), | 201 | .pSignalSemaphoreValues = signal_values.data(), |
| 198 | }; | 202 | }; |
| 199 | const VkSubmitInfo submit_info{ | 203 | const VkSubmitInfo submit_info{ |
| 200 | .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, | 204 | .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, |
| 201 | .pNext = &timeline_si, | 205 | .pNext = &timeline_si, |
| 202 | .waitSemaphoreCount = 1, | 206 | .waitSemaphoreCount = num_wait_semaphores, |
| 203 | .pWaitSemaphores = &timeline_semaphore, | 207 | .pWaitSemaphores = wait_semaphores.data(), |
| 204 | .pWaitDstStageMask = &wait_stage_mask, | 208 | .pWaitDstStageMask = wait_stage_masks.data(), |
| 205 | .commandBufferCount = 1, | 209 | .commandBufferCount = 1, |
| 206 | .pCommandBuffers = cmdbuf.address(), | 210 | .pCommandBuffers = cmdbuf.address(), |
| 207 | .signalSemaphoreCount = num_signal_semaphores, | 211 | .signalSemaphoreCount = num_signal_semaphores, |
diff --git a/src/video_core/renderer_vulkan/vk_scheduler.h b/src/video_core/renderer_vulkan/vk_scheduler.h index cf39a2363..759ed5a48 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.h +++ b/src/video_core/renderer_vulkan/vk_scheduler.h | |||
| @@ -34,10 +34,10 @@ public: | |||
| 34 | ~VKScheduler(); | 34 | ~VKScheduler(); |
| 35 | 35 | ||
| 36 | /// Sends the current execution context to the GPU. | 36 | /// Sends the current execution context to the GPU. |
| 37 | void Flush(VkSemaphore semaphore = nullptr); | 37 | void Flush(VkSemaphore signal_semaphore = nullptr, VkSemaphore wait_semaphore = nullptr); |
| 38 | 38 | ||
| 39 | /// Sends the current execution context to the GPU and waits for it to complete. | 39 | /// Sends the current execution context to the GPU and waits for it to complete. |
| 40 | void Finish(VkSemaphore semaphore = nullptr); | 40 | void Finish(VkSemaphore signal_semaphore = nullptr, VkSemaphore wait_semaphore = nullptr); |
| 41 | 41 | ||
| 42 | /// Waits for the worker thread to finish executing everything. After this function returns it's | 42 | /// Waits for the worker thread to finish executing everything. After this function returns it's |
| 43 | /// safe to touch worker resources. | 43 | /// safe to touch worker resources. |
| @@ -191,7 +191,7 @@ private: | |||
| 191 | 191 | ||
| 192 | void AllocateWorkerCommandBuffer(); | 192 | void AllocateWorkerCommandBuffer(); |
| 193 | 193 | ||
| 194 | void SubmitExecution(VkSemaphore semaphore); | 194 | void SubmitExecution(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore); |
| 195 | 195 | ||
| 196 | void AllocateNewContext(); | 196 | void AllocateNewContext(); |
| 197 | 197 | ||
diff --git a/src/video_core/renderer_vulkan/vk_swapchain.cpp b/src/video_core/renderer_vulkan/vk_swapchain.cpp index d990eefba..aadf03cb0 100644 --- a/src/video_core/renderer_vulkan/vk_swapchain.cpp +++ b/src/video_core/renderer_vulkan/vk_swapchain.cpp | |||
| @@ -20,16 +20,15 @@ namespace Vulkan { | |||
| 20 | 20 | ||
| 21 | namespace { | 21 | namespace { |
| 22 | 22 | ||
| 23 | VkSurfaceFormatKHR ChooseSwapSurfaceFormat(vk::Span<VkSurfaceFormatKHR> formats, bool srgb) { | 23 | VkSurfaceFormatKHR ChooseSwapSurfaceFormat(vk::Span<VkSurfaceFormatKHR> formats) { |
| 24 | if (formats.size() == 1 && formats[0].format == VK_FORMAT_UNDEFINED) { | 24 | if (formats.size() == 1 && formats[0].format == VK_FORMAT_UNDEFINED) { |
| 25 | VkSurfaceFormatKHR format; | 25 | VkSurfaceFormatKHR format; |
| 26 | format.format = VK_FORMAT_B8G8R8A8_UNORM; | 26 | format.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 27 | format.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; | 27 | format.colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; |
| 28 | return format; | 28 | return format; |
| 29 | } | 29 | } |
| 30 | const auto& found = std::find_if(formats.begin(), formats.end(), [srgb](const auto& format) { | 30 | const auto& found = std::find_if(formats.begin(), formats.end(), [](const auto& format) { |
| 31 | const auto request_format = srgb ? VK_FORMAT_B8G8R8A8_SRGB : VK_FORMAT_B8G8R8A8_UNORM; | 31 | return format.format == VK_FORMAT_B8G8R8A8_UNORM && |
| 32 | return format.format == request_format && | ||
| 33 | format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; | 32 | format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; |
| 34 | }); | 33 | }); |
| 35 | return found != formats.end() ? *found : formats[0]; | 34 | return found != formats.end() ? *found : formats[0]; |
| @@ -107,14 +106,12 @@ void VKSwapchain::AcquireNextImage() { | |||
| 107 | } | 106 | } |
| 108 | 107 | ||
| 109 | void VKSwapchain::Present(VkSemaphore render_semaphore) { | 108 | void VKSwapchain::Present(VkSemaphore render_semaphore) { |
| 110 | const VkSemaphore present_semaphore{*present_semaphores[frame_index]}; | ||
| 111 | const std::array<VkSemaphore, 2> semaphores{present_semaphore, render_semaphore}; | ||
| 112 | const auto present_queue{device.GetPresentQueue()}; | 109 | const auto present_queue{device.GetPresentQueue()}; |
| 113 | const VkPresentInfoKHR present_info{ | 110 | const VkPresentInfoKHR present_info{ |
| 114 | .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, | 111 | .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, |
| 115 | .pNext = nullptr, | 112 | .pNext = nullptr, |
| 116 | .waitSemaphoreCount = render_semaphore ? 2U : 1U, | 113 | .waitSemaphoreCount = render_semaphore ? 1U : 0U, |
| 117 | .pWaitSemaphores = semaphores.data(), | 114 | .pWaitSemaphores = &render_semaphore, |
| 118 | .swapchainCount = 1, | 115 | .swapchainCount = 1, |
| 119 | .pSwapchains = swapchain.address(), | 116 | .pSwapchains = swapchain.address(), |
| 120 | .pImageIndices = &image_index, | 117 | .pImageIndices = &image_index, |
| @@ -145,7 +142,7 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, | |||
| 145 | const auto formats{physical_device.GetSurfaceFormatsKHR(surface)}; | 142 | const auto formats{physical_device.GetSurfaceFormatsKHR(surface)}; |
| 146 | const auto present_modes{physical_device.GetSurfacePresentModesKHR(surface)}; | 143 | const auto present_modes{physical_device.GetSurfacePresentModesKHR(surface)}; |
| 147 | 144 | ||
| 148 | const VkSurfaceFormatKHR surface_format{ChooseSwapSurfaceFormat(formats, srgb)}; | 145 | const VkSurfaceFormatKHR surface_format{ChooseSwapSurfaceFormat(formats)}; |
| 149 | const VkPresentModeKHR present_mode{ChooseSwapPresentMode(present_modes)}; | 146 | const VkPresentModeKHR present_mode{ChooseSwapPresentMode(present_modes)}; |
| 150 | 147 | ||
| 151 | u32 requested_image_count{capabilities.minImageCount + 1}; | 148 | u32 requested_image_count{capabilities.minImageCount + 1}; |
| @@ -180,6 +177,17 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, | |||
| 180 | swapchain_ci.queueFamilyIndexCount = static_cast<u32>(queue_indices.size()); | 177 | swapchain_ci.queueFamilyIndexCount = static_cast<u32>(queue_indices.size()); |
| 181 | swapchain_ci.pQueueFamilyIndices = queue_indices.data(); | 178 | swapchain_ci.pQueueFamilyIndices = queue_indices.data(); |
| 182 | } | 179 | } |
| 180 | static constexpr std::array view_formats{VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_SRGB}; | ||
| 181 | VkImageFormatListCreateInfo format_list{ | ||
| 182 | .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR, | ||
| 183 | .pNext = nullptr, | ||
| 184 | .viewFormatCount = static_cast<u32>(view_formats.size()), | ||
| 185 | .pViewFormats = view_formats.data(), | ||
| 186 | }; | ||
| 187 | if (device.IsKhrSwapchainMutableFormatEnabled()) { | ||
| 188 | format_list.pNext = std::exchange(swapchain_ci.pNext, &format_list); | ||
| 189 | swapchain_ci.flags |= VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR; | ||
| 190 | } | ||
| 183 | // Request the size again to reduce the possibility of a TOCTOU race condition. | 191 | // Request the size again to reduce the possibility of a TOCTOU race condition. |
| 184 | const auto updated_capabilities = physical_device.GetSurfaceCapabilitiesKHR(surface); | 192 | const auto updated_capabilities = physical_device.GetSurfaceCapabilitiesKHR(surface); |
| 185 | swapchain_ci.imageExtent = ChooseSwapExtent(updated_capabilities, width, height); | 193 | swapchain_ci.imageExtent = ChooseSwapExtent(updated_capabilities, width, height); |
| @@ -191,7 +199,7 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, | |||
| 191 | 199 | ||
| 192 | images = swapchain.GetImages(); | 200 | images = swapchain.GetImages(); |
| 193 | image_count = static_cast<u32>(images.size()); | 201 | image_count = static_cast<u32>(images.size()); |
| 194 | image_format = surface_format.format; | 202 | image_view_format = srgb ? VK_FORMAT_B8G8R8A8_SRGB : VK_FORMAT_B8G8R8A8_UNORM; |
| 195 | } | 203 | } |
| 196 | 204 | ||
| 197 | void VKSwapchain::CreateSemaphores() { | 205 | void VKSwapchain::CreateSemaphores() { |
| @@ -207,7 +215,7 @@ void VKSwapchain::CreateImageViews() { | |||
| 207 | .flags = 0, | 215 | .flags = 0, |
| 208 | .image = {}, | 216 | .image = {}, |
| 209 | .viewType = VK_IMAGE_VIEW_TYPE_2D, | 217 | .viewType = VK_IMAGE_VIEW_TYPE_2D, |
| 210 | .format = image_format, | 218 | .format = image_view_format, |
| 211 | .components = | 219 | .components = |
| 212 | { | 220 | { |
| 213 | .r = VK_COMPONENT_SWIZZLE_IDENTITY, | 221 | .r = VK_COMPONENT_SWIZZLE_IDENTITY, |
diff --git a/src/video_core/renderer_vulkan/vk_swapchain.h b/src/video_core/renderer_vulkan/vk_swapchain.h index 35c2cdc14..5bce41e21 100644 --- a/src/video_core/renderer_vulkan/vk_swapchain.h +++ b/src/video_core/renderer_vulkan/vk_swapchain.h | |||
| @@ -68,8 +68,12 @@ public: | |||
| 68 | return *image_views[index]; | 68 | return *image_views[index]; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | VkFormat GetImageFormat() const { | 71 | VkFormat GetImageViewFormat() const { |
| 72 | return image_format; | 72 | return image_view_format; |
| 73 | } | ||
| 74 | |||
| 75 | VkSemaphore CurrentPresentSemaphore() const { | ||
| 76 | return *present_semaphores[frame_index]; | ||
| 73 | } | 77 | } |
| 74 | 78 | ||
| 75 | private: | 79 | private: |
| @@ -96,7 +100,7 @@ private: | |||
| 96 | u32 image_index{}; | 100 | u32 image_index{}; |
| 97 | u32 frame_index{}; | 101 | u32 frame_index{}; |
| 98 | 102 | ||
| 99 | VkFormat image_format{}; | 103 | VkFormat image_view_format{}; |
| 100 | VkExtent2D extent{}; | 104 | VkExtent2D extent{}; |
| 101 | 105 | ||
| 102 | bool current_srgb{}; | 106 | bool current_srgb{}; |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 8f4df7122..ff979a7ac 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp | |||
| @@ -1186,9 +1186,12 @@ Framebuffer::Framebuffer(TextureCacheRuntime& runtime, std::span<ImageView*, NUM | |||
| 1186 | renderpass_key.depth_format = depth_buffer->format; | 1186 | renderpass_key.depth_format = depth_buffer->format; |
| 1187 | num_layers = std::max(num_layers, depth_buffer->range.extent.layers); | 1187 | num_layers = std::max(num_layers, depth_buffer->range.extent.layers); |
| 1188 | images[num_images] = depth_buffer->ImageHandle(); | 1188 | images[num_images] = depth_buffer->ImageHandle(); |
| 1189 | image_ranges[num_images] = MakeSubresourceRange(depth_buffer); | 1189 | const VkImageSubresourceRange subresource_range = MakeSubresourceRange(depth_buffer); |
| 1190 | image_ranges[num_images] = subresource_range; | ||
| 1190 | samples = depth_buffer->Samples(); | 1191 | samples = depth_buffer->Samples(); |
| 1191 | ++num_images; | 1192 | ++num_images; |
| 1193 | has_depth = (subresource_range.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0; | ||
| 1194 | has_stencil = (subresource_range.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) != 0; | ||
| 1192 | } else { | 1195 | } else { |
| 1193 | renderpass_key.depth_format = PixelFormat::Invalid; | 1196 | renderpass_key.depth_format = PixelFormat::Invalid; |
| 1194 | } | 1197 | } |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h index 5fe6b7ba3..6d5a68bfe 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.h +++ b/src/video_core/renderer_vulkan/vk_texture_cache.h | |||
| @@ -232,6 +232,18 @@ public: | |||
| 232 | return image_ranges; | 232 | return image_ranges; |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | [[nodiscard]] bool HasAspectColorBit(size_t index) const noexcept { | ||
| 236 | return (image_ranges.at(index).aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != 0; | ||
| 237 | } | ||
| 238 | |||
| 239 | [[nodiscard]] bool HasAspectDepthBit() const noexcept { | ||
| 240 | return has_depth; | ||
| 241 | } | ||
| 242 | |||
| 243 | [[nodiscard]] bool HasAspectStencilBit() const noexcept { | ||
| 244 | return has_stencil; | ||
| 245 | } | ||
| 246 | |||
| 235 | private: | 247 | private: |
| 236 | vk::Framebuffer framebuffer; | 248 | vk::Framebuffer framebuffer; |
| 237 | VkRenderPass renderpass{}; | 249 | VkRenderPass renderpass{}; |
| @@ -241,6 +253,8 @@ private: | |||
| 241 | u32 num_images = 0; | 253 | u32 num_images = 0; |
| 242 | std::array<VkImage, 9> images{}; | 254 | std::array<VkImage, 9> images{}; |
| 243 | std::array<VkImageSubresourceRange, 9> image_ranges{}; | 255 | std::array<VkImageSubresourceRange, 9> image_ranges{}; |
| 256 | bool has_depth{}; | ||
| 257 | bool has_stencil{}; | ||
| 244 | }; | 258 | }; |
| 245 | 259 | ||
| 246 | struct TextureCacheParams { | 260 | struct TextureCacheParams { |
diff --git a/src/video_core/texture_cache/image_base.h b/src/video_core/texture_cache/image_base.h index ff1feda9b..0c17a791b 100644 --- a/src/video_core/texture_cache/image_base.h +++ b/src/video_core/texture_cache/image_base.h | |||
| @@ -80,7 +80,7 @@ struct ImageBase { | |||
| 80 | VAddr cpu_addr_end = 0; | 80 | VAddr cpu_addr_end = 0; |
| 81 | 81 | ||
| 82 | u64 modification_tick = 0; | 82 | u64 modification_tick = 0; |
| 83 | u64 frame_tick = 0; | 83 | size_t lru_index = SIZE_MAX; |
| 84 | 84 | ||
| 85 | std::array<u32, MAX_MIP_LEVELS> mip_level_offsets{}; | 85 | std::array<u32, MAX_MIP_LEVELS> mip_level_offsets{}; |
| 86 | 86 | ||
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index a087498ff..24b809242 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/alignment.h" | 7 | #include "common/alignment.h" |
| 8 | #include "common/settings.h" | ||
| 9 | #include "video_core/dirty_flags.h" | 8 | #include "video_core/dirty_flags.h" |
| 10 | #include "video_core/texture_cache/samples_helper.h" | 9 | #include "video_core/texture_cache/samples_helper.h" |
| 11 | #include "video_core/texture_cache/texture_cache_base.h" | 10 | #include "video_core/texture_cache/texture_cache_base.h" |
| @@ -43,8 +42,6 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface& | |||
| 43 | void(slot_image_views.insert(runtime, NullImageParams{})); | 42 | void(slot_image_views.insert(runtime, NullImageParams{})); |
| 44 | void(slot_samplers.insert(runtime, sampler_descriptor)); | 43 | void(slot_samplers.insert(runtime, sampler_descriptor)); |
| 45 | 44 | ||
| 46 | deletion_iterator = slot_images.begin(); | ||
| 47 | |||
| 48 | if constexpr (HAS_DEVICE_MEMORY_INFO) { | 45 | if constexpr (HAS_DEVICE_MEMORY_INFO) { |
| 49 | const auto device_memory = runtime.GetDeviceLocalMemory(); | 46 | const auto device_memory = runtime.GetDeviceLocalMemory(); |
| 50 | const u64 possible_expected_memory = (device_memory * 3) / 10; | 47 | const u64 possible_expected_memory = (device_memory * 3) / 10; |
| @@ -64,70 +61,38 @@ template <class P> | |||
| 64 | void TextureCache<P>::RunGarbageCollector() { | 61 | void TextureCache<P>::RunGarbageCollector() { |
| 65 | const bool high_priority_mode = total_used_memory >= expected_memory; | 62 | const bool high_priority_mode = total_used_memory >= expected_memory; |
| 66 | const bool aggressive_mode = total_used_memory >= critical_memory; | 63 | const bool aggressive_mode = total_used_memory >= critical_memory; |
| 67 | const u64 ticks_to_destroy = high_priority_mode ? 60 : 100; | 64 | const u64 ticks_to_destroy = aggressive_mode ? 10ULL : high_priority_mode ? 25ULL : 100ULL; |
| 68 | int num_iterations = aggressive_mode ? 256 : (high_priority_mode ? 128 : 64); | 65 | size_t num_iterations = aggressive_mode ? 10000 : (high_priority_mode ? 100 : 5); |
| 69 | for (; num_iterations > 0; --num_iterations) { | 66 | const auto clean_up = [this, &num_iterations, high_priority_mode](ImageId image_id) { |
| 70 | if (deletion_iterator == slot_images.end()) { | 67 | if (num_iterations == 0) { |
| 71 | deletion_iterator = slot_images.begin(); | 68 | return true; |
| 72 | if (deletion_iterator == slot_images.end()) { | ||
| 73 | break; | ||
| 74 | } | ||
| 75 | } | 69 | } |
| 76 | auto [image_id, image_tmp] = *deletion_iterator; | 70 | --num_iterations; |
| 77 | Image* image = image_tmp; // fix clang error. | 71 | auto& image = slot_images[image_id]; |
| 78 | const bool is_alias = True(image->flags & ImageFlagBits::Alias); | 72 | const bool must_download = image.IsSafeDownload(); |
| 79 | const bool is_bad_overlap = True(image->flags & ImageFlagBits::BadOverlap); | 73 | if (!high_priority_mode && must_download) { |
| 80 | const bool must_download = image->IsSafeDownload(); | 74 | return false; |
| 81 | bool should_care = is_bad_overlap || is_alias || (high_priority_mode && !must_download); | ||
| 82 | const u64 ticks_needed = | ||
| 83 | is_bad_overlap | ||
| 84 | ? ticks_to_destroy >> 4 | ||
| 85 | : ((should_care && aggressive_mode) ? ticks_to_destroy >> 1 : ticks_to_destroy); | ||
| 86 | should_care |= aggressive_mode; | ||
| 87 | if (should_care && image->frame_tick + ticks_needed < frame_tick) { | ||
| 88 | if (is_bad_overlap) { | ||
| 89 | const bool overlap_check = std::ranges::all_of( | ||
| 90 | image->overlapping_images, [&, image](const ImageId& overlap_id) { | ||
| 91 | auto& overlap = slot_images[overlap_id]; | ||
| 92 | return overlap.frame_tick >= image->frame_tick; | ||
| 93 | }); | ||
| 94 | if (!overlap_check) { | ||
| 95 | ++deletion_iterator; | ||
| 96 | continue; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | if (!is_bad_overlap && must_download) { | ||
| 100 | const bool alias_check = std::ranges::none_of( | ||
| 101 | image->aliased_images, [&, image](const AliasedImage& alias) { | ||
| 102 | auto& alias_image = slot_images[alias.id]; | ||
| 103 | return (alias_image.frame_tick < image->frame_tick) || | ||
| 104 | (alias_image.modification_tick < image->modification_tick); | ||
| 105 | }); | ||
| 106 | |||
| 107 | if (alias_check) { | ||
| 108 | auto map = runtime.DownloadStagingBuffer(image->unswizzled_size_bytes); | ||
| 109 | const auto copies = FullDownloadCopies(image->info); | ||
| 110 | image->DownloadMemory(map, copies); | ||
| 111 | runtime.Finish(); | ||
| 112 | SwizzleImage(gpu_memory, image->gpu_addr, image->info, copies, map.mapped_span); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | if (True(image->flags & ImageFlagBits::Tracked)) { | ||
| 116 | UntrackImage(*image, image_id); | ||
| 117 | } | ||
| 118 | UnregisterImage(image_id); | ||
| 119 | DeleteImage(image_id); | ||
| 120 | if (is_bad_overlap) { | ||
| 121 | ++num_iterations; | ||
| 122 | } | ||
| 123 | } | 75 | } |
| 124 | ++deletion_iterator; | 76 | if (must_download) { |
| 125 | } | 77 | auto map = runtime.DownloadStagingBuffer(image.unswizzled_size_bytes); |
| 78 | const auto copies = FullDownloadCopies(image.info); | ||
| 79 | image.DownloadMemory(map, copies); | ||
| 80 | runtime.Finish(); | ||
| 81 | SwizzleImage(gpu_memory, image.gpu_addr, image.info, copies, map.mapped_span); | ||
| 82 | } | ||
| 83 | if (True(image.flags & ImageFlagBits::Tracked)) { | ||
| 84 | UntrackImage(image, image_id); | ||
| 85 | } | ||
| 86 | UnregisterImage(image_id); | ||
| 87 | DeleteImage(image_id); | ||
| 88 | return false; | ||
| 89 | }; | ||
| 90 | lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, clean_up); | ||
| 126 | } | 91 | } |
| 127 | 92 | ||
| 128 | template <class P> | 93 | template <class P> |
| 129 | void TextureCache<P>::TickFrame() { | 94 | void TextureCache<P>::TickFrame() { |
| 130 | if (Settings::values.use_caches_gc.GetValue() && total_used_memory > minimum_memory) { | 95 | if (total_used_memory > minimum_memory) { |
| 131 | RunGarbageCollector(); | 96 | RunGarbageCollector(); |
| 132 | } | 97 | } |
| 133 | sentenced_images.Tick(); | 98 | sentenced_images.Tick(); |
| @@ -1078,6 +1043,8 @@ void TextureCache<P>::RegisterImage(ImageId image_id) { | |||
| 1078 | tentative_size = EstimatedDecompressedSize(tentative_size, image.info.format); | 1043 | tentative_size = EstimatedDecompressedSize(tentative_size, image.info.format); |
| 1079 | } | 1044 | } |
| 1080 | total_used_memory += Common::AlignUp(tentative_size, 1024); | 1045 | total_used_memory += Common::AlignUp(tentative_size, 1024); |
| 1046 | image.lru_index = lru_cache.Insert(image_id, frame_tick); | ||
| 1047 | |||
| 1081 | ForEachGPUPage(image.gpu_addr, image.guest_size_bytes, | 1048 | ForEachGPUPage(image.gpu_addr, image.guest_size_bytes, |
| 1082 | [this, image_id](u64 page) { gpu_page_table[page].push_back(image_id); }); | 1049 | [this, image_id](u64 page) { gpu_page_table[page].push_back(image_id); }); |
| 1083 | if (False(image.flags & ImageFlagBits::Sparse)) { | 1050 | if (False(image.flags & ImageFlagBits::Sparse)) { |
| @@ -1115,6 +1082,7 @@ void TextureCache<P>::UnregisterImage(ImageId image_id) { | |||
| 1115 | tentative_size = EstimatedDecompressedSize(tentative_size, image.info.format); | 1082 | tentative_size = EstimatedDecompressedSize(tentative_size, image.info.format); |
| 1116 | } | 1083 | } |
| 1117 | total_used_memory -= Common::AlignUp(tentative_size, 1024); | 1084 | total_used_memory -= Common::AlignUp(tentative_size, 1024); |
| 1085 | lru_cache.Free(image.lru_index); | ||
| 1118 | const auto& clear_page_table = | 1086 | const auto& clear_page_table = |
| 1119 | [this, image_id]( | 1087 | [this, image_id]( |
| 1120 | u64 page, | 1088 | u64 page, |
| @@ -1384,7 +1352,7 @@ void TextureCache<P>::PrepareImage(ImageId image_id, bool is_modification, bool | |||
| 1384 | if (is_modification) { | 1352 | if (is_modification) { |
| 1385 | MarkModification(image); | 1353 | MarkModification(image); |
| 1386 | } | 1354 | } |
| 1387 | image.frame_tick = frame_tick; | 1355 | lru_cache.Touch(image.lru_index, frame_tick); |
| 1388 | } | 1356 | } |
| 1389 | 1357 | ||
| 1390 | template <class P> | 1358 | template <class P> |
diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index e4ae351cb..d7528ed24 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| 16 | #include "common/literals.h" | 16 | #include "common/literals.h" |
| 17 | #include "common/lru_cache.h" | ||
| 17 | #include "video_core/compatible_formats.h" | 18 | #include "video_core/compatible_formats.h" |
| 18 | #include "video_core/delayed_destruction_ring.h" | 19 | #include "video_core/delayed_destruction_ring.h" |
| 19 | #include "video_core/engines/fermi_2d.h" | 20 | #include "video_core/engines/fermi_2d.h" |
| @@ -370,6 +371,12 @@ private: | |||
| 370 | std::vector<ImageId> uncommitted_downloads; | 371 | std::vector<ImageId> uncommitted_downloads; |
| 371 | std::queue<std::vector<ImageId>> committed_downloads; | 372 | std::queue<std::vector<ImageId>> committed_downloads; |
| 372 | 373 | ||
| 374 | struct LRUItemParams { | ||
| 375 | using ObjectType = ImageId; | ||
| 376 | using TickType = u64; | ||
| 377 | }; | ||
| 378 | Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache; | ||
| 379 | |||
| 373 | static constexpr size_t TICKS_TO_DESTROY = 6; | 380 | static constexpr size_t TICKS_TO_DESTROY = 6; |
| 374 | DelayedDestructionRing<Image, TICKS_TO_DESTROY> sentenced_images; | 381 | DelayedDestructionRing<Image, TICKS_TO_DESTROY> sentenced_images; |
| 375 | DelayedDestructionRing<ImageView, TICKS_TO_DESTROY> sentenced_image_view; | 382 | DelayedDestructionRing<ImageView, TICKS_TO_DESTROY> sentenced_image_view; |
| @@ -379,7 +386,6 @@ private: | |||
| 379 | 386 | ||
| 380 | u64 modification_tick = 0; | 387 | u64 modification_tick = 0; |
| 381 | u64 frame_tick = 0; | 388 | u64 frame_tick = 0; |
| 382 | typename SlotVector<Image>::Iterator deletion_iterator; | ||
| 383 | }; | 389 | }; |
| 384 | 390 | ||
| 385 | } // namespace VideoCommon | 391 | } // namespace VideoCommon |
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index c32ae956a..24e943e4c 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp | |||
| @@ -63,14 +63,6 @@ void SwizzleImpl(std::span<u8> output, std::span<const u8> input, u32 width, u32 | |||
| 63 | const u32 unswizzled_offset = | 63 | const u32 unswizzled_offset = |
| 64 | slice * pitch * height + line * pitch + column * BYTES_PER_PIXEL; | 64 | slice * pitch * height + line * pitch + column * BYTES_PER_PIXEL; |
| 65 | 65 | ||
| 66 | if (const auto offset = (TO_LINEAR ? unswizzled_offset : swizzled_offset); | ||
| 67 | offset >= input.size()) { | ||
| 68 | // TODO(Rodrigo): This is an out of bounds access that should never happen. To | ||
| 69 | // avoid crashing the emulator, break. | ||
| 70 | ASSERT_MSG(false, "offset {} exceeds input size {}!", offset, input.size()); | ||
| 71 | break; | ||
| 72 | } | ||
| 73 | |||
| 74 | u8* const dst = &output[TO_LINEAR ? swizzled_offset : unswizzled_offset]; | 66 | u8* const dst = &output[TO_LINEAR ? swizzled_offset : unswizzled_offset]; |
| 75 | const u8* const src = &input[TO_LINEAR ? unswizzled_offset : swizzled_offset]; | 67 | const u8* const src = &input[TO_LINEAR ? unswizzled_offset : swizzled_offset]; |
| 76 | 68 | ||
| @@ -84,56 +76,31 @@ template <bool TO_LINEAR> | |||
| 84 | void Swizzle(std::span<u8> output, std::span<const u8> input, u32 bytes_per_pixel, u32 width, | 76 | void Swizzle(std::span<u8> output, std::span<const u8> input, u32 bytes_per_pixel, u32 width, |
| 85 | u32 height, u32 depth, u32 block_height, u32 block_depth, u32 stride_alignment) { | 77 | u32 height, u32 depth, u32 block_height, u32 block_depth, u32 stride_alignment) { |
| 86 | switch (bytes_per_pixel) { | 78 | switch (bytes_per_pixel) { |
| 87 | case 1: | 79 | #define BPP_CASE(x) \ |
| 88 | return SwizzleImpl<TO_LINEAR, 1>(output, input, width, height, depth, block_height, | 80 | case x: \ |
| 89 | block_depth, stride_alignment); | 81 | return SwizzleImpl<TO_LINEAR, x>(output, input, width, height, depth, block_height, \ |
| 90 | case 2: | ||
| 91 | return SwizzleImpl<TO_LINEAR, 2>(output, input, width, height, depth, block_height, | ||
| 92 | block_depth, stride_alignment); | ||
| 93 | case 3: | ||
| 94 | return SwizzleImpl<TO_LINEAR, 3>(output, input, width, height, depth, block_height, | ||
| 95 | block_depth, stride_alignment); | ||
| 96 | case 4: | ||
| 97 | return SwizzleImpl<TO_LINEAR, 4>(output, input, width, height, depth, block_height, | ||
| 98 | block_depth, stride_alignment); | ||
| 99 | case 6: | ||
| 100 | return SwizzleImpl<TO_LINEAR, 6>(output, input, width, height, depth, block_height, | ||
| 101 | block_depth, stride_alignment); | 82 | block_depth, stride_alignment); |
| 102 | case 8: | 83 | BPP_CASE(1) |
| 103 | return SwizzleImpl<TO_LINEAR, 8>(output, input, width, height, depth, block_height, | 84 | BPP_CASE(2) |
| 104 | block_depth, stride_alignment); | 85 | BPP_CASE(3) |
| 105 | case 12: | 86 | BPP_CASE(4) |
| 106 | return SwizzleImpl<TO_LINEAR, 12>(output, input, width, height, depth, block_height, | 87 | BPP_CASE(6) |
| 107 | block_depth, stride_alignment); | 88 | BPP_CASE(8) |
| 108 | case 16: | 89 | BPP_CASE(12) |
| 109 | return SwizzleImpl<TO_LINEAR, 16>(output, input, width, height, depth, block_height, | 90 | BPP_CASE(16) |
| 110 | block_depth, stride_alignment); | 91 | #undef BPP_CASE |
| 111 | default: | 92 | default: |
| 112 | UNREACHABLE_MSG("Invalid bytes_per_pixel={}", bytes_per_pixel); | 93 | UNREACHABLE_MSG("Invalid bytes_per_pixel={}", bytes_per_pixel); |
| 113 | } | 94 | } |
| 114 | } | 95 | } |
| 115 | } // Anonymous namespace | ||
| 116 | |||
| 117 | void UnswizzleTexture(std::span<u8> output, std::span<const u8> input, u32 bytes_per_pixel, | ||
| 118 | u32 width, u32 height, u32 depth, u32 block_height, u32 block_depth, | ||
| 119 | u32 stride_alignment) { | ||
| 120 | Swizzle<false>(output, input, bytes_per_pixel, width, height, depth, block_height, block_depth, | ||
| 121 | stride_alignment); | ||
| 122 | } | ||
| 123 | |||
| 124 | void SwizzleTexture(std::span<u8> output, std::span<const u8> input, u32 bytes_per_pixel, u32 width, | ||
| 125 | u32 height, u32 depth, u32 block_height, u32 block_depth, | ||
| 126 | u32 stride_alignment) { | ||
| 127 | Swizzle<true>(output, input, bytes_per_pixel, width, height, depth, block_height, block_depth, | ||
| 128 | stride_alignment); | ||
| 129 | } | ||
| 130 | 96 | ||
| 97 | template <u32 BYTES_PER_PIXEL> | ||
| 131 | void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 swizzled_width, | 98 | void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 swizzled_width, |
| 132 | u32 bytes_per_pixel, u8* swizzled_data, const u8* unswizzled_data, | 99 | u8* swizzled_data, const u8* unswizzled_data, u32 block_height_bit, |
| 133 | u32 block_height_bit, u32 offset_x, u32 offset_y) { | 100 | u32 offset_x, u32 offset_y) { |
| 134 | const u32 block_height = 1U << block_height_bit; | 101 | const u32 block_height = 1U << block_height_bit; |
| 135 | const u32 image_width_in_gobs = | 102 | const u32 image_width_in_gobs = |
| 136 | (swizzled_width * bytes_per_pixel + (GOB_SIZE_X - 1)) / GOB_SIZE_X; | 103 | (swizzled_width * BYTES_PER_PIXEL + (GOB_SIZE_X - 1)) / GOB_SIZE_X; |
| 137 | for (u32 line = 0; line < subrect_height; ++line) { | 104 | for (u32 line = 0; line < subrect_height; ++line) { |
| 138 | const u32 dst_y = line + offset_y; | 105 | const u32 dst_y = line + offset_y; |
| 139 | const u32 gob_address_y = | 106 | const u32 gob_address_y = |
| @@ -143,20 +110,21 @@ void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 | |||
| 143 | for (u32 x = 0; x < subrect_width; ++x) { | 110 | for (u32 x = 0; x < subrect_width; ++x) { |
| 144 | const u32 dst_x = x + offset_x; | 111 | const u32 dst_x = x + offset_x; |
| 145 | const u32 gob_address = | 112 | const u32 gob_address = |
| 146 | gob_address_y + (dst_x * bytes_per_pixel / GOB_SIZE_X) * GOB_SIZE * block_height; | 113 | gob_address_y + (dst_x * BYTES_PER_PIXEL / GOB_SIZE_X) * GOB_SIZE * block_height; |
| 147 | const u32 swizzled_offset = gob_address + table[(dst_x * bytes_per_pixel) % GOB_SIZE_X]; | 114 | const u32 swizzled_offset = gob_address + table[(dst_x * BYTES_PER_PIXEL) % GOB_SIZE_X]; |
| 148 | const u32 unswizzled_offset = line * source_pitch + x * bytes_per_pixel; | 115 | const u32 unswizzled_offset = line * source_pitch + x * BYTES_PER_PIXEL; |
| 149 | 116 | ||
| 150 | const u8* const source_line = unswizzled_data + unswizzled_offset; | 117 | const u8* const source_line = unswizzled_data + unswizzled_offset; |
| 151 | u8* const dest_addr = swizzled_data + swizzled_offset; | 118 | u8* const dest_addr = swizzled_data + swizzled_offset; |
| 152 | std::memcpy(dest_addr, source_line, bytes_per_pixel); | 119 | std::memcpy(dest_addr, source_line, BYTES_PER_PIXEL); |
| 153 | } | 120 | } |
| 154 | } | 121 | } |
| 155 | } | 122 | } |
| 156 | 123 | ||
| 157 | void UnswizzleSubrect(u32 line_length_in, u32 line_count, u32 pitch, u32 width, u32 bytes_per_pixel, | 124 | template <u32 BYTES_PER_PIXEL> |
| 158 | u32 block_height, u32 origin_x, u32 origin_y, u8* output, const u8* input) { | 125 | void UnswizzleSubrect(u32 line_length_in, u32 line_count, u32 pitch, u32 width, u32 block_height, |
| 159 | const u32 stride = width * bytes_per_pixel; | 126 | u32 origin_x, u32 origin_y, u8* output, const u8* input) { |
| 127 | const u32 stride = width * BYTES_PER_PIXEL; | ||
| 160 | const u32 gobs_in_x = (stride + GOB_SIZE_X - 1) / GOB_SIZE_X; | 128 | const u32 gobs_in_x = (stride + GOB_SIZE_X - 1) / GOB_SIZE_X; |
| 161 | const u32 block_size = gobs_in_x << (GOB_SIZE_SHIFT + block_height); | 129 | const u32 block_size = gobs_in_x << (GOB_SIZE_SHIFT + block_height); |
| 162 | 130 | ||
| @@ -171,24 +139,25 @@ void UnswizzleSubrect(u32 line_length_in, u32 line_count, u32 pitch, u32 width, | |||
| 171 | const u32 src_offset_y = (block_y >> block_height) * block_size + | 139 | const u32 src_offset_y = (block_y >> block_height) * block_size + |
| 172 | ((block_y & block_height_mask) << GOB_SIZE_SHIFT); | 140 | ((block_y & block_height_mask) << GOB_SIZE_SHIFT); |
| 173 | for (u32 column = 0; column < line_length_in; ++column) { | 141 | for (u32 column = 0; column < line_length_in; ++column) { |
| 174 | const u32 src_x = (column + origin_x) * bytes_per_pixel; | 142 | const u32 src_x = (column + origin_x) * BYTES_PER_PIXEL; |
| 175 | const u32 src_offset_x = (src_x >> GOB_SIZE_X_SHIFT) << x_shift; | 143 | const u32 src_offset_x = (src_x >> GOB_SIZE_X_SHIFT) << x_shift; |
| 176 | 144 | ||
| 177 | const u32 swizzled_offset = src_offset_y + src_offset_x + table[src_x % GOB_SIZE_X]; | 145 | const u32 swizzled_offset = src_offset_y + src_offset_x + table[src_x % GOB_SIZE_X]; |
| 178 | const u32 unswizzled_offset = line * pitch + column * bytes_per_pixel; | 146 | const u32 unswizzled_offset = line * pitch + column * BYTES_PER_PIXEL; |
| 179 | 147 | ||
| 180 | std::memcpy(output + unswizzled_offset, input + swizzled_offset, bytes_per_pixel); | 148 | std::memcpy(output + unswizzled_offset, input + swizzled_offset, BYTES_PER_PIXEL); |
| 181 | } | 149 | } |
| 182 | } | 150 | } |
| 183 | } | 151 | } |
| 184 | 152 | ||
| 153 | template <u32 BYTES_PER_PIXEL> | ||
| 185 | void SwizzleSliceToVoxel(u32 line_length_in, u32 line_count, u32 pitch, u32 width, u32 height, | 154 | void SwizzleSliceToVoxel(u32 line_length_in, u32 line_count, u32 pitch, u32 width, u32 height, |
| 186 | u32 bytes_per_pixel, u32 block_height, u32 block_depth, u32 origin_x, | 155 | u32 block_height, u32 block_depth, u32 origin_x, u32 origin_y, u8* output, |
| 187 | u32 origin_y, u8* output, const u8* input) { | 156 | const u8* input) { |
| 188 | UNIMPLEMENTED_IF(origin_x > 0); | 157 | UNIMPLEMENTED_IF(origin_x > 0); |
| 189 | UNIMPLEMENTED_IF(origin_y > 0); | 158 | UNIMPLEMENTED_IF(origin_y > 0); |
| 190 | 159 | ||
| 191 | const u32 stride = width * bytes_per_pixel; | 160 | const u32 stride = width * BYTES_PER_PIXEL; |
| 192 | const u32 gobs_in_x = (stride + GOB_SIZE_X - 1) / GOB_SIZE_X; | 161 | const u32 gobs_in_x = (stride + GOB_SIZE_X - 1) / GOB_SIZE_X; |
| 193 | const u32 block_size = gobs_in_x << (GOB_SIZE_SHIFT + block_height + block_depth); | 162 | const u32 block_size = gobs_in_x << (GOB_SIZE_SHIFT + block_height + block_depth); |
| 194 | 163 | ||
| @@ -203,11 +172,93 @@ void SwizzleSliceToVoxel(u32 line_length_in, u32 line_count, u32 pitch, u32 widt | |||
| 203 | for (u32 x = 0; x < line_length_in; ++x) { | 172 | for (u32 x = 0; x < line_length_in; ++x) { |
| 204 | const u32 dst_offset = | 173 | const u32 dst_offset = |
| 205 | ((x / GOB_SIZE_X) << x_shift) + dst_offset_y + table[x % GOB_SIZE_X]; | 174 | ((x / GOB_SIZE_X) << x_shift) + dst_offset_y + table[x % GOB_SIZE_X]; |
| 206 | const u32 src_offset = x * bytes_per_pixel + line * pitch; | 175 | const u32 src_offset = x * BYTES_PER_PIXEL + line * pitch; |
| 207 | std::memcpy(output + dst_offset, input + src_offset, bytes_per_pixel); | 176 | std::memcpy(output + dst_offset, input + src_offset, BYTES_PER_PIXEL); |
| 208 | } | 177 | } |
| 209 | } | 178 | } |
| 210 | } | 179 | } |
| 180 | } // Anonymous namespace | ||
| 181 | |||
| 182 | void UnswizzleTexture(std::span<u8> output, std::span<const u8> input, u32 bytes_per_pixel, | ||
| 183 | u32 width, u32 height, u32 depth, u32 block_height, u32 block_depth, | ||
| 184 | u32 stride_alignment) { | ||
| 185 | Swizzle<false>(output, input, bytes_per_pixel, width, height, depth, block_height, block_depth, | ||
| 186 | stride_alignment); | ||
| 187 | } | ||
| 188 | |||
| 189 | void SwizzleTexture(std::span<u8> output, std::span<const u8> input, u32 bytes_per_pixel, u32 width, | ||
| 190 | u32 height, u32 depth, u32 block_height, u32 block_depth, | ||
| 191 | u32 stride_alignment) { | ||
| 192 | Swizzle<true>(output, input, bytes_per_pixel, width, height, depth, block_height, block_depth, | ||
| 193 | stride_alignment); | ||
| 194 | } | ||
| 195 | |||
| 196 | void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 swizzled_width, | ||
| 197 | u32 bytes_per_pixel, u8* swizzled_data, const u8* unswizzled_data, | ||
| 198 | u32 block_height_bit, u32 offset_x, u32 offset_y) { | ||
| 199 | switch (bytes_per_pixel) { | ||
| 200 | #define BPP_CASE(x) \ | ||
| 201 | case x: \ | ||
| 202 | return SwizzleSubrect<x>(subrect_width, subrect_height, source_pitch, swizzled_width, \ | ||
| 203 | swizzled_data, unswizzled_data, block_height_bit, offset_x, \ | ||
| 204 | offset_y); | ||
| 205 | BPP_CASE(1) | ||
| 206 | BPP_CASE(2) | ||
| 207 | BPP_CASE(3) | ||
| 208 | BPP_CASE(4) | ||
| 209 | BPP_CASE(6) | ||
| 210 | BPP_CASE(8) | ||
| 211 | BPP_CASE(12) | ||
| 212 | BPP_CASE(16) | ||
| 213 | #undef BPP_CASE | ||
| 214 | default: | ||
| 215 | UNREACHABLE_MSG("Invalid bytes_per_pixel={}", bytes_per_pixel); | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | void UnswizzleSubrect(u32 line_length_in, u32 line_count, u32 pitch, u32 width, u32 bytes_per_pixel, | ||
| 220 | u32 block_height, u32 origin_x, u32 origin_y, u8* output, const u8* input) { | ||
| 221 | switch (bytes_per_pixel) { | ||
| 222 | #define BPP_CASE(x) \ | ||
| 223 | case x: \ | ||
| 224 | return UnswizzleSubrect<x>(line_length_in, line_count, pitch, width, block_height, \ | ||
| 225 | origin_x, origin_y, output, input); | ||
| 226 | BPP_CASE(1) | ||
| 227 | BPP_CASE(2) | ||
| 228 | BPP_CASE(3) | ||
| 229 | BPP_CASE(4) | ||
| 230 | BPP_CASE(6) | ||
| 231 | BPP_CASE(8) | ||
| 232 | BPP_CASE(12) | ||
| 233 | BPP_CASE(16) | ||
| 234 | #undef BPP_CASE | ||
| 235 | default: | ||
| 236 | UNREACHABLE_MSG("Invalid bytes_per_pixel={}", bytes_per_pixel); | ||
| 237 | } | ||
| 238 | } | ||
| 239 | |||
| 240 | void SwizzleSliceToVoxel(u32 line_length_in, u32 line_count, u32 pitch, u32 width, u32 height, | ||
| 241 | u32 bytes_per_pixel, u32 block_height, u32 block_depth, u32 origin_x, | ||
| 242 | u32 origin_y, u8* output, const u8* input) { | ||
| 243 | switch (bytes_per_pixel) { | ||
| 244 | #define BPP_CASE(x) \ | ||
| 245 | case x: \ | ||
| 246 | return SwizzleSliceToVoxel<x>(line_length_in, line_count, pitch, width, height, \ | ||
| 247 | block_height, block_depth, origin_x, origin_y, output, \ | ||
| 248 | input); | ||
| 249 | BPP_CASE(1) | ||
| 250 | BPP_CASE(2) | ||
| 251 | BPP_CASE(3) | ||
| 252 | BPP_CASE(4) | ||
| 253 | BPP_CASE(6) | ||
| 254 | BPP_CASE(8) | ||
| 255 | BPP_CASE(12) | ||
| 256 | BPP_CASE(16) | ||
| 257 | #undef BPP_CASE | ||
| 258 | default: | ||
| 259 | UNREACHABLE_MSG("Invalid bytes_per_pixel={}", bytes_per_pixel); | ||
| 260 | } | ||
| 261 | } | ||
| 211 | 262 | ||
| 212 | void SwizzleKepler(const u32 width, const u32 height, const u32 dst_x, const u32 dst_y, | 263 | void SwizzleKepler(const u32 width, const u32 height, const u32 dst_x, const u32 dst_y, |
| 213 | const u32 block_height_bit, const std::size_t copy_size, const u8* source_data, | 264 | const u32 block_height_bit, const std::size_t copy_size, const u8* source_data, |
| @@ -228,7 +279,7 @@ void SwizzleKepler(const u32 width, const u32 height, const u32 dst_x, const u32 | |||
| 228 | u8* dest_addr = swizzle_data + swizzled_offset; | 279 | u8* dest_addr = swizzle_data + swizzled_offset; |
| 229 | count++; | 280 | count++; |
| 230 | 281 | ||
| 231 | std::memcpy(dest_addr, source_line, 1); | 282 | *dest_addr = *source_line; |
| 232 | } | 283 | } |
| 233 | } | 284 | } |
| 234 | } | 285 | } |
diff --git a/src/video_core/textures/texture.h b/src/video_core/textures/texture.h index 1a9399455..7994cb859 100644 --- a/src/video_core/textures/texture.h +++ b/src/video_core/textures/texture.h | |||
| @@ -159,7 +159,7 @@ static_assert(sizeof(TextureHandle) == 4, "TextureHandle has wrong size"); | |||
| 159 | return {raw, raw}; | 159 | return {raw, raw}; |
| 160 | } else { | 160 | } else { |
| 161 | const Tegra::Texture::TextureHandle handle{raw}; | 161 | const Tegra::Texture::TextureHandle handle{raw}; |
| 162 | return {handle.tic_id, via_header_index ? handle.tic_id : handle.tsc_id}; | 162 | return {handle.tic_id, handle.tsc_id}; |
| 163 | } | 163 | } |
| 164 | } | 164 | } |
| 165 | 165 | ||
diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp index 8e56a89e1..24821c1a3 100644 --- a/src/video_core/vulkan_common/vulkan_device.cpp +++ b/src/video_core/vulkan_common/vulkan_device.cpp | |||
| @@ -368,18 +368,21 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR | |||
| 368 | }; | 368 | }; |
| 369 | SetNext(next, demote); | 369 | SetNext(next, demote); |
| 370 | 370 | ||
| 371 | VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8; | 371 | if (is_int8_supported || is_float16_supported) { |
| 372 | if (is_float16_supported) { | 372 | VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8{ |
| 373 | float16_int8 = { | ||
| 374 | .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR, | 373 | .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR, |
| 375 | .pNext = nullptr, | 374 | .pNext = nullptr, |
| 376 | .shaderFloat16 = true, | 375 | .shaderFloat16 = is_float16_supported, |
| 377 | .shaderInt8 = false, | 376 | .shaderInt8 = is_int8_supported, |
| 378 | }; | 377 | }; |
| 379 | SetNext(next, float16_int8); | 378 | SetNext(next, float16_int8); |
| 380 | } else { | 379 | } |
| 380 | if (!is_float16_supported) { | ||
| 381 | LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively"); | 381 | LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively"); |
| 382 | } | 382 | } |
| 383 | if (!is_int8_supported) { | ||
| 384 | LOG_INFO(Render_Vulkan, "Device doesn't support int8 natively"); | ||
| 385 | } | ||
| 383 | 386 | ||
| 384 | if (!nv_viewport_swizzle) { | 387 | if (!nv_viewport_swizzle) { |
| 385 | LOG_INFO(Render_Vulkan, "Device doesn't support viewport swizzles"); | 388 | LOG_INFO(Render_Vulkan, "Device doesn't support viewport swizzles"); |
| @@ -836,6 +839,8 @@ std::vector<const char*> Device::LoadExtensions(bool requires_surface) { | |||
| 836 | bool has_khr_shader_float16_int8{}; | 839 | bool has_khr_shader_float16_int8{}; |
| 837 | bool has_khr_workgroup_memory_explicit_layout{}; | 840 | bool has_khr_workgroup_memory_explicit_layout{}; |
| 838 | bool has_khr_pipeline_executable_properties{}; | 841 | bool has_khr_pipeline_executable_properties{}; |
| 842 | bool has_khr_image_format_list{}; | ||
| 843 | bool has_khr_swapchain_mutable_format{}; | ||
| 839 | bool has_ext_subgroup_size_control{}; | 844 | bool has_ext_subgroup_size_control{}; |
| 840 | bool has_ext_transform_feedback{}; | 845 | bool has_ext_transform_feedback{}; |
| 841 | bool has_ext_custom_border_color{}; | 846 | bool has_ext_custom_border_color{}; |
| @@ -885,6 +890,9 @@ std::vector<const char*> Device::LoadExtensions(bool requires_surface) { | |||
| 885 | test(has_ext_shader_atomic_int64, VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME, false); | 890 | test(has_ext_shader_atomic_int64, VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME, false); |
| 886 | test(has_khr_workgroup_memory_explicit_layout, | 891 | test(has_khr_workgroup_memory_explicit_layout, |
| 887 | VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME, false); | 892 | VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME, false); |
| 893 | test(has_khr_image_format_list, VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME, false); | ||
| 894 | test(has_khr_swapchain_mutable_format, VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME, | ||
| 895 | false); | ||
| 888 | test(has_ext_line_rasterization, VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME, false); | 896 | test(has_ext_line_rasterization, VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME, false); |
| 889 | if (Settings::values.enable_nsight_aftermath) { | 897 | if (Settings::values.enable_nsight_aftermath) { |
| 890 | test(nv_device_diagnostics_config, VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME, | 898 | test(nv_device_diagnostics_config, VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME, |
| @@ -909,6 +917,7 @@ std::vector<const char*> Device::LoadExtensions(bool requires_surface) { | |||
| 909 | 917 | ||
| 910 | physical.GetFeatures2KHR(features); | 918 | physical.GetFeatures2KHR(features); |
| 911 | is_float16_supported = float16_int8_features.shaderFloat16; | 919 | is_float16_supported = float16_int8_features.shaderFloat16; |
| 920 | is_int8_supported = float16_int8_features.shaderInt8; | ||
| 912 | extensions.push_back(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME); | 921 | extensions.push_back(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME); |
| 913 | } | 922 | } |
| 914 | if (has_ext_subgroup_size_control) { | 923 | if (has_ext_subgroup_size_control) { |
| @@ -1062,6 +1071,11 @@ std::vector<const char*> Device::LoadExtensions(bool requires_surface) { | |||
| 1062 | khr_pipeline_executable_properties = true; | 1071 | khr_pipeline_executable_properties = true; |
| 1063 | } | 1072 | } |
| 1064 | } | 1073 | } |
| 1074 | if (has_khr_image_format_list && has_khr_swapchain_mutable_format) { | ||
| 1075 | extensions.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME); | ||
| 1076 | extensions.push_back(VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME); | ||
| 1077 | khr_swapchain_mutable_format = true; | ||
| 1078 | } | ||
| 1065 | if (khr_push_descriptor) { | 1079 | if (khr_push_descriptor) { |
| 1066 | VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor; | 1080 | VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor; |
| 1067 | push_descriptor.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR; | 1081 | push_descriptor.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR; |
diff --git a/src/video_core/vulkan_common/vulkan_device.h b/src/video_core/vulkan_common/vulkan_device.h index c19f40746..5599c38c5 100644 --- a/src/video_core/vulkan_common/vulkan_device.h +++ b/src/video_core/vulkan_common/vulkan_device.h | |||
| @@ -139,11 +139,16 @@ public: | |||
| 139 | return is_optimal_astc_supported; | 139 | return is_optimal_astc_supported; |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | /// Returns true if the device supports float16 natively | 142 | /// Returns true if the device supports float16 natively. |
| 143 | bool IsFloat16Supported() const { | 143 | bool IsFloat16Supported() const { |
| 144 | return is_float16_supported; | 144 | return is_float16_supported; |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | /// Returns true if the device supports int8 natively. | ||
| 148 | bool IsInt8Supported() const { | ||
| 149 | return is_int8_supported; | ||
| 150 | } | ||
| 151 | |||
| 147 | /// Returns true if the device warp size can potentially be bigger than guest's warp size. | 152 | /// Returns true if the device warp size can potentially be bigger than guest's warp size. |
| 148 | bool IsWarpSizePotentiallyBiggerThanGuest() const { | 153 | bool IsWarpSizePotentiallyBiggerThanGuest() const { |
| 149 | return is_warp_potentially_bigger; | 154 | return is_warp_potentially_bigger; |
| @@ -219,6 +224,11 @@ public: | |||
| 219 | return khr_pipeline_executable_properties; | 224 | return khr_pipeline_executable_properties; |
| 220 | } | 225 | } |
| 221 | 226 | ||
| 227 | /// Returns true if VK_KHR_swapchain_mutable_format is enabled. | ||
| 228 | bool IsKhrSwapchainMutableFormatEnabled() const { | ||
| 229 | return khr_swapchain_mutable_format; | ||
| 230 | } | ||
| 231 | |||
| 222 | /// Returns true if the device supports VK_KHR_workgroup_memory_explicit_layout. | 232 | /// Returns true if the device supports VK_KHR_workgroup_memory_explicit_layout. |
| 223 | bool IsKhrWorkgroupMemoryExplicitLayoutSupported() const { | 233 | bool IsKhrWorkgroupMemoryExplicitLayoutSupported() const { |
| 224 | return khr_workgroup_memory_explicit_layout; | 234 | return khr_workgroup_memory_explicit_layout; |
| @@ -367,7 +377,8 @@ private: | |||
| 367 | u64 device_access_memory{}; ///< Total size of device local memory in bytes. | 377 | u64 device_access_memory{}; ///< Total size of device local memory in bytes. |
| 368 | u32 max_push_descriptors{}; ///< Maximum number of push descriptors | 378 | u32 max_push_descriptors{}; ///< Maximum number of push descriptors |
| 369 | bool is_optimal_astc_supported{}; ///< Support for native ASTC. | 379 | bool is_optimal_astc_supported{}; ///< Support for native ASTC. |
| 370 | bool is_float16_supported{}; ///< Support for float16 arithmetics. | 380 | bool is_float16_supported{}; ///< Support for float16 arithmetic. |
| 381 | bool is_int8_supported{}; ///< Support for int8 arithmetic. | ||
| 371 | bool is_warp_potentially_bigger{}; ///< Host warp size can be bigger than guest. | 382 | bool is_warp_potentially_bigger{}; ///< Host warp size can be bigger than guest. |
| 372 | bool is_formatless_image_load_supported{}; ///< Support for shader image read without format. | 383 | bool is_formatless_image_load_supported{}; ///< Support for shader image read without format. |
| 373 | bool is_depth_bounds_supported{}; ///< Support for depth bounds. | 384 | bool is_depth_bounds_supported{}; ///< Support for depth bounds. |
| @@ -384,6 +395,7 @@ private: | |||
| 384 | bool khr_workgroup_memory_explicit_layout{}; ///< Support for explicit workgroup layouts. | 395 | bool khr_workgroup_memory_explicit_layout{}; ///< Support for explicit workgroup layouts. |
| 385 | bool khr_push_descriptor{}; ///< Support for VK_KHR_push_descritor. | 396 | bool khr_push_descriptor{}; ///< Support for VK_KHR_push_descritor. |
| 386 | bool khr_pipeline_executable_properties{}; ///< Support for executable properties. | 397 | bool khr_pipeline_executable_properties{}; ///< Support for executable properties. |
| 398 | bool khr_swapchain_mutable_format{}; ///< Support for VK_KHR_swapchain_mutable_format. | ||
| 387 | bool ext_index_type_uint8{}; ///< Support for VK_EXT_index_type_uint8. | 399 | bool ext_index_type_uint8{}; ///< Support for VK_EXT_index_type_uint8. |
| 388 | bool ext_sampler_filter_minmax{}; ///< Support for VK_EXT_sampler_filter_minmax. | 400 | bool ext_sampler_filter_minmax{}; ///< Support for VK_EXT_sampler_filter_minmax. |
| 389 | bool ext_depth_range_unrestricted{}; ///< Support for VK_EXT_depth_range_unrestricted. | 401 | bool ext_depth_range_unrestricted{}; ///< Support for VK_EXT_depth_range_unrestricted. |
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index cb4bdcc7e..19ba0dbba 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt | |||
| @@ -102,9 +102,9 @@ add_executable(yuzu | |||
| 102 | configuration/configure_profile_manager.cpp | 102 | configuration/configure_profile_manager.cpp |
| 103 | configuration/configure_profile_manager.h | 103 | configuration/configure_profile_manager.h |
| 104 | configuration/configure_profile_manager.ui | 104 | configuration/configure_profile_manager.ui |
| 105 | configuration/configure_service.cpp | 105 | configuration/configure_network.cpp |
| 106 | configuration/configure_service.h | 106 | configuration/configure_network.h |
| 107 | configuration/configure_service.ui | 107 | configuration/configure_network.ui |
| 108 | configuration/configure_system.cpp | 108 | configuration/configure_system.cpp |
| 109 | configuration/configure_system.h | 109 | configuration/configure_system.h |
| 110 | configuration/configure_system.ui | 110 | configuration/configure_system.ui |
| @@ -182,7 +182,14 @@ if (ENABLE_QT_TRANSLATION) | |||
| 182 | # Update source TS file if enabled | 182 | # Update source TS file if enabled |
| 183 | if (GENERATE_QT_TRANSLATION) | 183 | if (GENERATE_QT_TRANSLATION) |
| 184 | get_target_property(SRCS yuzu SOURCES) | 184 | get_target_property(SRCS yuzu SOURCES) |
| 185 | qt5_create_translation(QM_FILES ${SRCS} ${UIS} ${YUZU_QT_LANGUAGES}/en.ts) | 185 | qt5_create_translation(QM_FILES |
| 186 | ${SRCS} | ||
| 187 | ${UIS} | ||
| 188 | ${YUZU_QT_LANGUAGES}/en.ts | ||
| 189 | OPTIONS | ||
| 190 | -source-language en_US | ||
| 191 | -target-language en_US | ||
| 192 | ) | ||
| 186 | add_custom_target(translation ALL DEPENDS ${YUZU_QT_LANGUAGES}/en.ts) | 193 | add_custom_target(translation ALL DEPENDS ${YUZU_QT_LANGUAGES}/en.ts) |
| 187 | endif() | 194 | endif() |
| 188 | 195 | ||
diff --git a/src/yuzu/applets/qt_software_keyboard.cpp b/src/yuzu/applets/qt_software_keyboard.cpp index 848801cec..8fc0c5a36 100644 --- a/src/yuzu/applets/qt_software_keyboard.cpp +++ b/src/yuzu/applets/qt_software_keyboard.cpp | |||
| @@ -438,7 +438,7 @@ void QtSoftwareKeyboardDialog::ShowInlineKeyboard( | |||
| 438 | initialize_parameters.key_disable_flags = appear_parameters.key_disable_flags; | 438 | initialize_parameters.key_disable_flags = appear_parameters.key_disable_flags; |
| 439 | initialize_parameters.enable_backspace_button = appear_parameters.enable_backspace_button; | 439 | initialize_parameters.enable_backspace_button = appear_parameters.enable_backspace_button; |
| 440 | initialize_parameters.enable_return_button = appear_parameters.enable_return_button; | 440 | initialize_parameters.enable_return_button = appear_parameters.enable_return_button; |
| 441 | initialize_parameters.disable_cancel_button = initialize_parameters.disable_cancel_button; | 441 | initialize_parameters.disable_cancel_button = appear_parameters.disable_cancel_button; |
| 442 | 442 | ||
| 443 | SetKeyboardType(); | 443 | SetKeyboardType(); |
| 444 | SetControllerImage(); | 444 | SetControllerImage(); |
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 6aec3c46c..8744d8e5d 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -692,6 +692,7 @@ void Config::ReadServiceValues() { | |||
| 692 | qt_config->beginGroup(QStringLiteral("Services")); | 692 | qt_config->beginGroup(QStringLiteral("Services")); |
| 693 | ReadBasicSetting(Settings::values.bcat_backend); | 693 | ReadBasicSetting(Settings::values.bcat_backend); |
| 694 | ReadBasicSetting(Settings::values.bcat_boxcat_local); | 694 | ReadBasicSetting(Settings::values.bcat_boxcat_local); |
| 695 | ReadBasicSetting(Settings::values.network_interface); | ||
| 695 | qt_config->endGroup(); | 696 | qt_config->endGroup(); |
| 696 | } | 697 | } |
| 697 | 698 | ||
| @@ -817,7 +818,6 @@ void Config::ReadRendererValues() { | |||
| 817 | ReadGlobalSetting(Settings::values.shader_backend); | 818 | ReadGlobalSetting(Settings::values.shader_backend); |
| 818 | ReadGlobalSetting(Settings::values.use_asynchronous_shaders); | 819 | ReadGlobalSetting(Settings::values.use_asynchronous_shaders); |
| 819 | ReadGlobalSetting(Settings::values.use_fast_gpu_time); | 820 | ReadGlobalSetting(Settings::values.use_fast_gpu_time); |
| 820 | ReadGlobalSetting(Settings::values.use_caches_gc); | ||
| 821 | ReadGlobalSetting(Settings::values.bg_red); | 821 | ReadGlobalSetting(Settings::values.bg_red); |
| 822 | ReadGlobalSetting(Settings::values.bg_green); | 822 | ReadGlobalSetting(Settings::values.bg_green); |
| 823 | ReadGlobalSetting(Settings::values.bg_blue); | 823 | ReadGlobalSetting(Settings::values.bg_blue); |
| @@ -1144,7 +1144,7 @@ void Config::SaveValues() { | |||
| 1144 | SaveDataStorageValues(); | 1144 | SaveDataStorageValues(); |
| 1145 | SaveDebuggingValues(); | 1145 | SaveDebuggingValues(); |
| 1146 | SaveDisabledAddOnValues(); | 1146 | SaveDisabledAddOnValues(); |
| 1147 | SaveServiceValues(); | 1147 | SaveNetworkValues(); |
| 1148 | SaveUIValues(); | 1148 | SaveUIValues(); |
| 1149 | SaveWebServiceValues(); | 1149 | SaveWebServiceValues(); |
| 1150 | SaveMiscellaneousValues(); | 1150 | SaveMiscellaneousValues(); |
| @@ -1238,11 +1238,12 @@ void Config::SaveDebuggingValues() { | |||
| 1238 | qt_config->endGroup(); | 1238 | qt_config->endGroup(); |
| 1239 | } | 1239 | } |
| 1240 | 1240 | ||
| 1241 | void Config::SaveServiceValues() { | 1241 | void Config::SaveNetworkValues() { |
| 1242 | qt_config->beginGroup(QStringLiteral("Services")); | 1242 | qt_config->beginGroup(QStringLiteral("Services")); |
| 1243 | 1243 | ||
| 1244 | WriteBasicSetting(Settings::values.bcat_backend); | 1244 | WriteBasicSetting(Settings::values.bcat_backend); |
| 1245 | WriteBasicSetting(Settings::values.bcat_boxcat_local); | 1245 | WriteBasicSetting(Settings::values.bcat_boxcat_local); |
| 1246 | WriteBasicSetting(Settings::values.network_interface); | ||
| 1246 | 1247 | ||
| 1247 | qt_config->endGroup(); | 1248 | qt_config->endGroup(); |
| 1248 | } | 1249 | } |
| @@ -1360,7 +1361,6 @@ void Config::SaveRendererValues() { | |||
| 1360 | Settings::values.shader_backend.UsingGlobal()); | 1361 | Settings::values.shader_backend.UsingGlobal()); |
| 1361 | WriteGlobalSetting(Settings::values.use_asynchronous_shaders); | 1362 | WriteGlobalSetting(Settings::values.use_asynchronous_shaders); |
| 1362 | WriteGlobalSetting(Settings::values.use_fast_gpu_time); | 1363 | WriteGlobalSetting(Settings::values.use_fast_gpu_time); |
| 1363 | WriteGlobalSetting(Settings::values.use_caches_gc); | ||
| 1364 | WriteGlobalSetting(Settings::values.bg_red); | 1364 | WriteGlobalSetting(Settings::values.bg_red); |
| 1365 | WriteGlobalSetting(Settings::values.bg_green); | 1365 | WriteGlobalSetting(Settings::values.bg_green); |
| 1366 | WriteGlobalSetting(Settings::values.bg_blue); | 1366 | WriteGlobalSetting(Settings::values.bg_blue); |
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 334623997..4733227b6 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h | |||
| @@ -88,7 +88,7 @@ private: | |||
| 88 | void SaveCoreValues(); | 88 | void SaveCoreValues(); |
| 89 | void SaveDataStorageValues(); | 89 | void SaveDataStorageValues(); |
| 90 | void SaveDebuggingValues(); | 90 | void SaveDebuggingValues(); |
| 91 | void SaveServiceValues(); | 91 | void SaveNetworkValues(); |
| 92 | void SaveDisabledAddOnValues(); | 92 | void SaveDisabledAddOnValues(); |
| 93 | void SaveMiscellaneousValues(); | 93 | void SaveMiscellaneousValues(); |
| 94 | void SavePathValues(); | 94 | void SavePathValues(); |
diff --git a/src/yuzu/configuration/configure.ui b/src/yuzu/configuration/configure.ui index fca9aed5f..6258dcf20 100644 --- a/src/yuzu/configuration/configure.ui +++ b/src/yuzu/configuration/configure.ui | |||
| @@ -147,12 +147,12 @@ | |||
| 147 | <string>Web</string> | 147 | <string>Web</string> |
| 148 | </attribute> | 148 | </attribute> |
| 149 | </widget> | 149 | </widget> |
| 150 | <widget class="ConfigureService" name="serviceTab"> | 150 | <widget class="ConfigureNetwork" name="networkTab"> |
| 151 | <property name="accessibleName"> | 151 | <property name="accessibleName"> |
| 152 | <string>Services</string> | 152 | <string>Network</string> |
| 153 | </property> | 153 | </property> |
| 154 | <attribute name="title"> | 154 | <attribute name="title"> |
| 155 | <string>Services</string> | 155 | <string>Network</string> |
| 156 | </attribute> | 156 | </attribute> |
| 157 | </widget> | 157 | </widget> |
| 158 | </widget> | 158 | </widget> |
| @@ -242,9 +242,9 @@ | |||
| 242 | <container>1</container> | 242 | <container>1</container> |
| 243 | </customwidget> | 243 | </customwidget> |
| 244 | <customwidget> | 244 | <customwidget> |
| 245 | <class>ConfigureService</class> | 245 | <class>ConfigureNetwork</class> |
| 246 | <extends>QWidget</extends> | 246 | <extends>QWidget</extends> |
| 247 | <header>configuration/configure_service.h</header> | 247 | <header>configuration/configure_network.h</header> |
| 248 | <container>1</container> | 248 | <container>1</container> |
| 249 | </customwidget> | 249 | </customwidget> |
| 250 | <customwidget> | 250 | <customwidget> |
diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index bc009b6b3..fe4186157 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp | |||
| @@ -67,7 +67,7 @@ void ConfigureDialog::ApplyConfiguration() { | |||
| 67 | ui->audioTab->ApplyConfiguration(); | 67 | ui->audioTab->ApplyConfiguration(); |
| 68 | ui->debugTab->ApplyConfiguration(); | 68 | ui->debugTab->ApplyConfiguration(); |
| 69 | ui->webTab->ApplyConfiguration(); | 69 | ui->webTab->ApplyConfiguration(); |
| 70 | ui->serviceTab->ApplyConfiguration(); | 70 | ui->networkTab->ApplyConfiguration(); |
| 71 | Core::System::GetInstance().ApplySettings(); | 71 | Core::System::GetInstance().ApplySettings(); |
| 72 | Settings::LogSettings(); | 72 | Settings::LogSettings(); |
| 73 | } | 73 | } |
| @@ -103,7 +103,7 @@ Q_DECLARE_METATYPE(QList<QWidget*>); | |||
| 103 | void ConfigureDialog::PopulateSelectionList() { | 103 | void ConfigureDialog::PopulateSelectionList() { |
| 104 | const std::array<std::pair<QString, QList<QWidget*>>, 6> items{ | 104 | const std::array<std::pair<QString, QList<QWidget*>>, 6> items{ |
| 105 | {{tr("General"), {ui->generalTab, ui->hotkeysTab, ui->uiTab, ui->webTab, ui->debugTab}}, | 105 | {{tr("General"), {ui->generalTab, ui->hotkeysTab, ui->uiTab, ui->webTab, ui->debugTab}}, |
| 106 | {tr("System"), {ui->systemTab, ui->profileManagerTab, ui->serviceTab, ui->filesystemTab}}, | 106 | {tr("System"), {ui->systemTab, ui->profileManagerTab, ui->networkTab, ui->filesystemTab}}, |
| 107 | {tr("CPU"), {ui->cpuTab}}, | 107 | {tr("CPU"), {ui->cpuTab}}, |
| 108 | {tr("Graphics"), {ui->graphicsTab, ui->graphicsAdvancedTab}}, | 108 | {tr("Graphics"), {ui->graphicsTab, ui->graphicsAdvancedTab}}, |
| 109 | {tr("Audio"), {ui->audioTab}}, | 109 | {tr("Audio"), {ui->audioTab}}, |
diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui index 41e930f6b..1a12cfa4d 100644 --- a/src/yuzu/configuration/configure_graphics.ui +++ b/src/yuzu/configuration/configure_graphics.ui | |||
| @@ -156,7 +156,7 @@ | |||
| 156 | <item> | 156 | <item> |
| 157 | <widget class="QCheckBox" name="use_disk_shader_cache"> | 157 | <widget class="QCheckBox" name="use_disk_shader_cache"> |
| 158 | <property name="text"> | 158 | <property name="text"> |
| 159 | <string>Use disk shader cache</string> | 159 | <string>Use disk pipeline cache</string> |
| 160 | </property> | 160 | </property> |
| 161 | </widget> | 161 | </widget> |
| 162 | </item> | 162 | </item> |
diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp index a31b8e192..bfd464061 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.cpp +++ b/src/yuzu/configuration/configure_graphics_advanced.cpp | |||
| @@ -28,7 +28,6 @@ void ConfigureGraphicsAdvanced::SetConfiguration() { | |||
| 28 | 28 | ||
| 29 | ui->use_vsync->setChecked(Settings::values.use_vsync.GetValue()); | 29 | ui->use_vsync->setChecked(Settings::values.use_vsync.GetValue()); |
| 30 | ui->use_asynchronous_shaders->setChecked(Settings::values.use_asynchronous_shaders.GetValue()); | 30 | ui->use_asynchronous_shaders->setChecked(Settings::values.use_asynchronous_shaders.GetValue()); |
| 31 | ui->use_caches_gc->setChecked(Settings::values.use_caches_gc.GetValue()); | ||
| 32 | ui->use_fast_gpu_time->setChecked(Settings::values.use_fast_gpu_time.GetValue()); | 31 | ui->use_fast_gpu_time->setChecked(Settings::values.use_fast_gpu_time.GetValue()); |
| 33 | 32 | ||
| 34 | if (Settings::IsConfiguringGlobal()) { | 33 | if (Settings::IsConfiguringGlobal()) { |
| @@ -55,8 +54,6 @@ void ConfigureGraphicsAdvanced::ApplyConfiguration() { | |||
| 55 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_shaders, | 54 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_shaders, |
| 56 | ui->use_asynchronous_shaders, | 55 | ui->use_asynchronous_shaders, |
| 57 | use_asynchronous_shaders); | 56 | use_asynchronous_shaders); |
| 58 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_caches_gc, ui->use_caches_gc, | ||
| 59 | use_caches_gc); | ||
| 60 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_fast_gpu_time, | 57 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_fast_gpu_time, |
| 61 | ui->use_fast_gpu_time, use_fast_gpu_time); | 58 | ui->use_fast_gpu_time, use_fast_gpu_time); |
| 62 | } | 59 | } |
| @@ -81,7 +78,6 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() { | |||
| 81 | ui->use_asynchronous_shaders->setEnabled( | 78 | ui->use_asynchronous_shaders->setEnabled( |
| 82 | Settings::values.use_asynchronous_shaders.UsingGlobal()); | 79 | Settings::values.use_asynchronous_shaders.UsingGlobal()); |
| 83 | ui->use_fast_gpu_time->setEnabled(Settings::values.use_fast_gpu_time.UsingGlobal()); | 80 | ui->use_fast_gpu_time->setEnabled(Settings::values.use_fast_gpu_time.UsingGlobal()); |
| 84 | ui->use_caches_gc->setEnabled(Settings::values.use_caches_gc.UsingGlobal()); | ||
| 85 | ui->anisotropic_filtering_combobox->setEnabled( | 81 | ui->anisotropic_filtering_combobox->setEnabled( |
| 86 | Settings::values.max_anisotropy.UsingGlobal()); | 82 | Settings::values.max_anisotropy.UsingGlobal()); |
| 87 | 83 | ||
| @@ -94,8 +90,6 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() { | |||
| 94 | use_asynchronous_shaders); | 90 | use_asynchronous_shaders); |
| 95 | ConfigurationShared::SetColoredTristate(ui->use_fast_gpu_time, | 91 | ConfigurationShared::SetColoredTristate(ui->use_fast_gpu_time, |
| 96 | Settings::values.use_fast_gpu_time, use_fast_gpu_time); | 92 | Settings::values.use_fast_gpu_time, use_fast_gpu_time); |
| 97 | ConfigurationShared::SetColoredTristate(ui->use_caches_gc, Settings::values.use_caches_gc, | ||
| 98 | use_caches_gc); | ||
| 99 | ConfigurationShared::SetColoredComboBox( | 93 | ConfigurationShared::SetColoredComboBox( |
| 100 | ui->gpu_accuracy, ui->label_gpu_accuracy, | 94 | ui->gpu_accuracy, ui->label_gpu_accuracy, |
| 101 | static_cast<int>(Settings::values.gpu_accuracy.GetValue(true))); | 95 | static_cast<int>(Settings::values.gpu_accuracy.GetValue(true))); |
diff --git a/src/yuzu/configuration/configure_graphics_advanced.h b/src/yuzu/configuration/configure_graphics_advanced.h index 7356e6916..13ba4ff6b 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.h +++ b/src/yuzu/configuration/configure_graphics_advanced.h | |||
| @@ -37,5 +37,4 @@ private: | |||
| 37 | ConfigurationShared::CheckState use_vsync; | 37 | ConfigurationShared::CheckState use_vsync; |
| 38 | ConfigurationShared::CheckState use_asynchronous_shaders; | 38 | ConfigurationShared::CheckState use_asynchronous_shaders; |
| 39 | ConfigurationShared::CheckState use_fast_gpu_time; | 39 | ConfigurationShared::CheckState use_fast_gpu_time; |
| 40 | ConfigurationShared::CheckState use_caches_gc; | ||
| 41 | }; | 40 | }; |
diff --git a/src/yuzu/configuration/configure_graphics_advanced.ui b/src/yuzu/configuration/configure_graphics_advanced.ui index 4fe6b86ae..b91abc2f0 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.ui +++ b/src/yuzu/configuration/configure_graphics_advanced.ui | |||
| @@ -82,7 +82,7 @@ | |||
| 82 | <string>Enables asynchronous shader compilation, which may reduce shader stutter. This feature is experimental.</string> | 82 | <string>Enables asynchronous shader compilation, which may reduce shader stutter. This feature is experimental.</string> |
| 83 | </property> | 83 | </property> |
| 84 | <property name="text"> | 84 | <property name="text"> |
| 85 | <string>Use asynchronous shader building (hack)</string> | 85 | <string>Use asynchronous shader building (Hack)</string> |
| 86 | </property> | 86 | </property> |
| 87 | </widget> | 87 | </widget> |
| 88 | </item> | 88 | </item> |
| @@ -92,17 +92,7 @@ | |||
| 92 | <string>Enables Fast GPU Time. This option will force most games to run at their highest native resolution.</string> | 92 | <string>Enables Fast GPU Time. This option will force most games to run at their highest native resolution.</string> |
| 93 | </property> | 93 | </property> |
| 94 | <property name="text"> | 94 | <property name="text"> |
| 95 | <string>Use Fast GPU Time (hack)</string> | 95 | <string>Use Fast GPU Time (Hack)</string> |
| 96 | </property> | ||
| 97 | </widget> | ||
| 98 | </item> | ||
| 99 | <item> | ||
| 100 | <widget class="QCheckBox" name="use_caches_gc"> | ||
| 101 | <property name="toolTip"> | ||
| 102 | <string>Enables garbage collection for the GPU caches, this will try to keep VRAM within 3-4 GB by flushing the least used textures/buffers. May cause issues in a few games.</string> | ||
| 103 | </property> | ||
| 104 | <property name="text"> | ||
| 105 | <string>Enable GPU cache garbage collection (experimental)</string> | ||
| 106 | </property> | 96 | </property> |
| 107 | </widget> | 97 | </widget> |
| 108 | </item> | 98 | </item> |
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp index cd633e45f..9c890ed5d 100644 --- a/src/yuzu/configuration/configure_input_player_widget.cpp +++ b/src/yuzu/configuration/configure_input_player_widget.cpp | |||
| @@ -647,18 +647,18 @@ void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF cen | |||
| 647 | // Face buttons | 647 | // Face buttons |
| 648 | p.setPen(colors.outline); | 648 | p.setPen(colors.outline); |
| 649 | button_color = colors.button; | 649 | button_color = colors.button; |
| 650 | DrawCircleButton(p, face_center + QPoint(face_distance, 0), button_values[A], face_radius); | 650 | DrawCircleButton(p, face_center + QPointF(face_distance, 0), button_values[A], face_radius); |
| 651 | DrawCircleButton(p, face_center + QPoint(0, face_distance), button_values[B], face_radius); | 651 | DrawCircleButton(p, face_center + QPointF(0, face_distance), button_values[B], face_radius); |
| 652 | DrawCircleButton(p, face_center + QPoint(0, -face_distance), button_values[X], face_radius); | 652 | DrawCircleButton(p, face_center + QPointF(0, -face_distance), button_values[X], face_radius); |
| 653 | DrawCircleButton(p, face_center + QPoint(-face_distance, 0), button_values[Y], face_radius); | 653 | DrawCircleButton(p, face_center + QPointF(-face_distance, 0), button_values[Y], face_radius); |
| 654 | 654 | ||
| 655 | // Face buttons text | 655 | // Face buttons text |
| 656 | p.setPen(colors.transparent); | 656 | p.setPen(colors.transparent); |
| 657 | p.setBrush(colors.font); | 657 | p.setBrush(colors.font); |
| 658 | DrawSymbol(p, face_center + QPoint(face_distance, 0), Symbol::A, text_size); | 658 | DrawSymbol(p, face_center + QPointF(face_distance, 0), Symbol::A, text_size); |
| 659 | DrawSymbol(p, face_center + QPoint(0, face_distance), Symbol::B, text_size); | 659 | DrawSymbol(p, face_center + QPointF(0, face_distance), Symbol::B, text_size); |
| 660 | DrawSymbol(p, face_center + QPoint(0, -face_distance), Symbol::X, text_size); | 660 | DrawSymbol(p, face_center + QPointF(0, -face_distance), Symbol::X, text_size); |
| 661 | DrawSymbol(p, face_center + QPoint(-face_distance, 1), Symbol::Y, text_size); | 661 | DrawSymbol(p, face_center + QPointF(-face_distance, 1), Symbol::Y, text_size); |
| 662 | 662 | ||
| 663 | // D-pad constants | 663 | // D-pad constants |
| 664 | const QPointF dpad_center = center + QPoint(-171, 8); | 664 | const QPointF dpad_center = center + QPoint(-171, 8); |
| @@ -669,18 +669,20 @@ void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF cen | |||
| 669 | // D-pad buttons | 669 | // D-pad buttons |
| 670 | p.setPen(colors.outline); | 670 | p.setPen(colors.outline); |
| 671 | button_color = colors.button; | 671 | button_color = colors.button; |
| 672 | DrawCircleButton(p, dpad_center + QPoint(dpad_distance, 0), button_values[DRight], dpad_radius); | 672 | DrawCircleButton(p, dpad_center + QPointF(dpad_distance, 0), button_values[DRight], |
| 673 | DrawCircleButton(p, dpad_center + QPoint(0, dpad_distance), button_values[DDown], dpad_radius); | 673 | dpad_radius); |
| 674 | DrawCircleButton(p, dpad_center + QPoint(0, -dpad_distance), button_values[DUp], dpad_radius); | 674 | DrawCircleButton(p, dpad_center + QPointF(0, dpad_distance), button_values[DDown], dpad_radius); |
| 675 | DrawCircleButton(p, dpad_center + QPoint(-dpad_distance, 0), button_values[DLeft], dpad_radius); | 675 | DrawCircleButton(p, dpad_center + QPointF(0, -dpad_distance), button_values[DUp], dpad_radius); |
| 676 | DrawCircleButton(p, dpad_center + QPointF(-dpad_distance, 0), button_values[DLeft], | ||
| 677 | dpad_radius); | ||
| 676 | 678 | ||
| 677 | // D-pad arrows | 679 | // D-pad arrows |
| 678 | p.setPen(colors.font2); | 680 | p.setPen(colors.font2); |
| 679 | p.setBrush(colors.font2); | 681 | p.setBrush(colors.font2); |
| 680 | DrawArrow(p, dpad_center + QPoint(dpad_distance, 0), Direction::Right, dpad_arrow_size); | 682 | DrawArrow(p, dpad_center + QPointF(dpad_distance, 0), Direction::Right, dpad_arrow_size); |
| 681 | DrawArrow(p, dpad_center + QPoint(0, dpad_distance), Direction::Down, dpad_arrow_size); | 683 | DrawArrow(p, dpad_center + QPointF(0, dpad_distance), Direction::Down, dpad_arrow_size); |
| 682 | DrawArrow(p, dpad_center + QPoint(0, -dpad_distance), Direction::Up, dpad_arrow_size); | 684 | DrawArrow(p, dpad_center + QPointF(0, -dpad_distance), Direction::Up, dpad_arrow_size); |
| 683 | DrawArrow(p, dpad_center + QPoint(-dpad_distance, 0), Direction::Left, dpad_arrow_size); | 685 | DrawArrow(p, dpad_center + QPointF(-dpad_distance, 0), Direction::Left, dpad_arrow_size); |
| 684 | 686 | ||
| 685 | // ZL and ZR buttons | 687 | // ZL and ZR buttons |
| 686 | p.setPen(colors.outline); | 688 | p.setPen(colors.outline); |
diff --git a/src/yuzu/configuration/configure_service.cpp b/src/yuzu/configuration/configure_network.cpp index 4aa424803..ae22f1018 100644 --- a/src/yuzu/configuration/configure_service.cpp +++ b/src/yuzu/configuration/configure_network.cpp | |||
| @@ -5,9 +5,11 @@ | |||
| 5 | #include <QGraphicsItem> | 5 | #include <QGraphicsItem> |
| 6 | #include <QtConcurrent/QtConcurrent> | 6 | #include <QtConcurrent/QtConcurrent> |
| 7 | #include "common/settings.h" | 7 | #include "common/settings.h" |
| 8 | #include "core/core.h" | ||
| 8 | #include "core/hle/service/bcat/backend/boxcat.h" | 9 | #include "core/hle/service/bcat/backend/boxcat.h" |
| 9 | #include "ui_configure_service.h" | 10 | #include "core/network/network_interface.h" |
| 10 | #include "yuzu/configuration/configure_service.h" | 11 | #include "ui_configure_network.h" |
| 12 | #include "yuzu/configuration/configure_network.h" | ||
| 11 | 13 | ||
| 12 | #ifdef YUZU_ENABLE_BOXCAT | 14 | #ifdef YUZU_ENABLE_BOXCAT |
| 13 | namespace { | 15 | namespace { |
| @@ -35,8 +37,8 @@ QString FormatEventStatusString(const Service::BCAT::EventStatus& status) { | |||
| 35 | } // Anonymous namespace | 37 | } // Anonymous namespace |
| 36 | #endif | 38 | #endif |
| 37 | 39 | ||
| 38 | ConfigureService::ConfigureService(QWidget* parent) | 40 | ConfigureNetwork::ConfigureNetwork(QWidget* parent) |
| 39 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureService>()) { | 41 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureNetwork>()) { |
| 40 | ui->setupUi(this); | 42 | ui->setupUi(this); |
| 41 | 43 | ||
| 42 | ui->bcat_source->addItem(QStringLiteral("None")); | 44 | ui->bcat_source->addItem(QStringLiteral("None")); |
| @@ -47,29 +49,42 @@ ConfigureService::ConfigureService(QWidget* parent) | |||
| 47 | ui->bcat_source->addItem(QStringLiteral("Boxcat"), QStringLiteral("boxcat")); | 49 | ui->bcat_source->addItem(QStringLiteral("Boxcat"), QStringLiteral("boxcat")); |
| 48 | #endif | 50 | #endif |
| 49 | 51 | ||
| 52 | ui->network_interface->addItem(tr("None")); | ||
| 53 | for (const auto& iface : Network::GetAvailableNetworkInterfaces()) { | ||
| 54 | ui->network_interface->addItem(QString::fromStdString(iface.name)); | ||
| 55 | } | ||
| 56 | |||
| 50 | connect(ui->bcat_source, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | 57 | connect(ui->bcat_source, QOverload<int>::of(&QComboBox::currentIndexChanged), this, |
| 51 | &ConfigureService::OnBCATImplChanged); | 58 | &ConfigureNetwork::OnBCATImplChanged); |
| 52 | 59 | ||
| 53 | this->SetConfiguration(); | 60 | this->SetConfiguration(); |
| 54 | } | 61 | } |
| 55 | 62 | ||
| 56 | ConfigureService::~ConfigureService() = default; | 63 | ConfigureNetwork::~ConfigureNetwork() = default; |
| 57 | 64 | ||
| 58 | void ConfigureService::ApplyConfiguration() { | 65 | void ConfigureNetwork::ApplyConfiguration() { |
| 59 | Settings::values.bcat_backend = ui->bcat_source->currentText().toLower().toStdString(); | 66 | Settings::values.bcat_backend = ui->bcat_source->currentText().toLower().toStdString(); |
| 67 | Settings::values.network_interface = ui->network_interface->currentText().toStdString(); | ||
| 60 | } | 68 | } |
| 61 | 69 | ||
| 62 | void ConfigureService::RetranslateUi() { | 70 | void ConfigureNetwork::RetranslateUi() { |
| 63 | ui->retranslateUi(this); | 71 | ui->retranslateUi(this); |
| 64 | } | 72 | } |
| 65 | 73 | ||
| 66 | void ConfigureService::SetConfiguration() { | 74 | void ConfigureNetwork::SetConfiguration() { |
| 75 | const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); | ||
| 76 | |||
| 67 | const int index = | 77 | const int index = |
| 68 | ui->bcat_source->findData(QString::fromStdString(Settings::values.bcat_backend.GetValue())); | 78 | ui->bcat_source->findData(QString::fromStdString(Settings::values.bcat_backend.GetValue())); |
| 69 | ui->bcat_source->setCurrentIndex(index == -1 ? 0 : index); | 79 | ui->bcat_source->setCurrentIndex(index == -1 ? 0 : index); |
| 80 | |||
| 81 | const std::string& network_interface = Settings::values.network_interface.GetValue(); | ||
| 82 | |||
| 83 | ui->network_interface->setCurrentText(QString::fromStdString(network_interface)); | ||
| 84 | ui->network_interface->setEnabled(runtime_lock); | ||
| 70 | } | 85 | } |
| 71 | 86 | ||
| 72 | std::pair<QString, QString> ConfigureService::BCATDownloadEvents() { | 87 | std::pair<QString, QString> ConfigureNetwork::BCATDownloadEvents() { |
| 73 | #ifdef YUZU_ENABLE_BOXCAT | 88 | #ifdef YUZU_ENABLE_BOXCAT |
| 74 | std::optional<std::string> global; | 89 | std::optional<std::string> global; |
| 75 | std::map<std::string, Service::BCAT::EventStatus> map; | 90 | std::map<std::string, Service::BCAT::EventStatus> map; |
| @@ -114,7 +129,7 @@ std::pair<QString, QString> ConfigureService::BCATDownloadEvents() { | |||
| 114 | #endif | 129 | #endif |
| 115 | } | 130 | } |
| 116 | 131 | ||
| 117 | void ConfigureService::OnBCATImplChanged() { | 132 | void ConfigureNetwork::OnBCATImplChanged() { |
| 118 | #ifdef YUZU_ENABLE_BOXCAT | 133 | #ifdef YUZU_ENABLE_BOXCAT |
| 119 | const auto boxcat = ui->bcat_source->currentText() == QStringLiteral("Boxcat"); | 134 | const auto boxcat = ui->bcat_source->currentText() == QStringLiteral("Boxcat"); |
| 120 | ui->bcat_empty_header->setHidden(!boxcat); | 135 | ui->bcat_empty_header->setHidden(!boxcat); |
| @@ -133,7 +148,7 @@ void ConfigureService::OnBCATImplChanged() { | |||
| 133 | #endif | 148 | #endif |
| 134 | } | 149 | } |
| 135 | 150 | ||
| 136 | void ConfigureService::OnUpdateBCATEmptyLabel(std::pair<QString, QString> string) { | 151 | void ConfigureNetwork::OnUpdateBCATEmptyLabel(std::pair<QString, QString> string) { |
| 137 | #ifdef YUZU_ENABLE_BOXCAT | 152 | #ifdef YUZU_ENABLE_BOXCAT |
| 138 | const auto boxcat = ui->bcat_source->currentText() == QStringLiteral("Boxcat"); | 153 | const auto boxcat = ui->bcat_source->currentText() == QStringLiteral("Boxcat"); |
| 139 | if (boxcat) { | 154 | if (boxcat) { |
diff --git a/src/yuzu/configuration/configure_service.h b/src/yuzu/configuration/configure_network.h index f5c1b703a..442b68e6b 100644 --- a/src/yuzu/configuration/configure_service.h +++ b/src/yuzu/configuration/configure_network.h | |||
| @@ -9,15 +9,15 @@ | |||
| 9 | #include <QWidget> | 9 | #include <QWidget> |
| 10 | 10 | ||
| 11 | namespace Ui { | 11 | namespace Ui { |
| 12 | class ConfigureService; | 12 | class ConfigureNetwork; |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | class ConfigureService : public QWidget { | 15 | class ConfigureNetwork : public QWidget { |
| 16 | Q_OBJECT | 16 | Q_OBJECT |
| 17 | 17 | ||
| 18 | public: | 18 | public: |
| 19 | explicit ConfigureService(QWidget* parent = nullptr); | 19 | explicit ConfigureNetwork(QWidget* parent = nullptr); |
| 20 | ~ConfigureService() override; | 20 | ~ConfigureNetwork() override; |
| 21 | 21 | ||
| 22 | void ApplyConfiguration(); | 22 | void ApplyConfiguration(); |
| 23 | void RetranslateUi(); | 23 | void RetranslateUi(); |
| @@ -29,6 +29,6 @@ private: | |||
| 29 | void OnBCATImplChanged(); | 29 | void OnBCATImplChanged(); |
| 30 | void OnUpdateBCATEmptyLabel(std::pair<QString, QString> string); | 30 | void OnUpdateBCATEmptyLabel(std::pair<QString, QString> string); |
| 31 | 31 | ||
| 32 | std::unique_ptr<Ui::ConfigureService> ui; | 32 | std::unique_ptr<Ui::ConfigureNetwork> ui; |
| 33 | QFutureWatcher<std::pair<QString, QString>> watcher{this}; | 33 | QFutureWatcher<std::pair<QString, QString>> watcher{this}; |
| 34 | }; | 34 | }; |
diff --git a/src/yuzu/configuration/configure_service.ui b/src/yuzu/configuration/configure_network.ui index 9668dd557..5f9b7e97b 100644 --- a/src/yuzu/configuration/configure_service.ui +++ b/src/yuzu/configuration/configure_network.ui | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <ui version="4.0"> | 2 | <ui version="4.0"> |
| 3 | <class>ConfigureService</class> | 3 | <class>ConfigureNetwork</class> |
| 4 | <widget class="QWidget" name="ConfigureService"> | 4 | <widget class="QWidget" name="ConfigureNetwork"> |
| 5 | <property name="geometry"> | 5 | <property name="geometry"> |
| 6 | <rect> | 6 | <rect> |
| 7 | <x>0</x> | 7 | <x>0</x> |
| @@ -17,21 +17,37 @@ | |||
| 17 | <item> | 17 | <item> |
| 18 | <layout class="QVBoxLayout" name="verticalLayout_3"> | 18 | <layout class="QVBoxLayout" name="verticalLayout_3"> |
| 19 | <item> | 19 | <item> |
| 20 | <widget class="QGroupBox" name="groupBox_2"> | ||
| 21 | <property name="title"> | ||
| 22 | <string>General</string> | ||
| 23 | </property> | ||
| 24 | <layout class="QGridLayout" name="gridLayout_2"> | ||
| 25 | <item row="1" column="1"> | ||
| 26 | <widget class="QComboBox" name="network_interface"/> | ||
| 27 | </item> | ||
| 28 | <item row="1" column="0"> | ||
| 29 | <widget class="QLabel" name="label_4"> | ||
| 30 | <property name="text"> | ||
| 31 | <string>Network Interface</string> | ||
| 32 | </property> | ||
| 33 | </widget> | ||
| 34 | </item> | ||
| 35 | </layout> | ||
| 36 | </widget> | ||
| 37 | </item> | ||
| 38 | <item> | ||
| 20 | <widget class="QGroupBox" name="groupBox"> | 39 | <widget class="QGroupBox" name="groupBox"> |
| 21 | <property name="title"> | 40 | <property name="title"> |
| 22 | <string>BCAT</string> | 41 | <string>BCAT</string> |
| 23 | </property> | 42 | </property> |
| 24 | <layout class="QGridLayout" name="gridLayout"> | 43 | <layout class="QGridLayout" name="gridLayout"> |
| 25 | <item row="1" column="1" colspan="2"> | 44 | <item row="3" column="0"> |
| 26 | <widget class="QLabel" name="label_2"> | 45 | <widget class="QLabel" name="bcat_empty_header"> |
| 27 | <property name="maximumSize"> | ||
| 28 | <size> | ||
| 29 | <width>260</width> | ||
| 30 | <height>16777215</height> | ||
| 31 | </size> | ||
| 32 | </property> | ||
| 33 | <property name="text"> | 46 | <property name="text"> |
| 34 | <string>BCAT is Nintendo's way of sending data to games to engage its community and unlock additional content.</string> | 47 | <string/> |
| 48 | </property> | ||
| 49 | <property name="alignment"> | ||
| 50 | <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> | ||
| 35 | </property> | 51 | </property> |
| 36 | <property name="wordWrap"> | 52 | <property name="wordWrap"> |
| 37 | <bool>true</bool> | 53 | <bool>true</bool> |
| @@ -51,11 +67,8 @@ | |||
| 51 | </property> | 67 | </property> |
| 52 | </widget> | 68 | </widget> |
| 53 | </item> | 69 | </item> |
| 54 | <item row="3" column="1" colspan="2"> | 70 | <item row="1" column="1" colspan="2"> |
| 55 | <widget class="QLabel" name="bcat_empty_label"> | 71 | <widget class="QLabel" name="label_2"> |
| 56 | <property name="enabled"> | ||
| 57 | <bool>true</bool> | ||
| 58 | </property> | ||
| 59 | <property name="maximumSize"> | 72 | <property name="maximumSize"> |
| 60 | <size> | 73 | <size> |
| 61 | <width>260</width> | 74 | <width>260</width> |
| @@ -63,10 +76,7 @@ | |||
| 63 | </size> | 76 | </size> |
| 64 | </property> | 77 | </property> |
| 65 | <property name="text"> | 78 | <property name="text"> |
| 66 | <string/> | 79 | <string>BCAT is Nintendo's way of sending data to games to engage its community and unlock additional content.</string> |
| 67 | </property> | ||
| 68 | <property name="alignment"> | ||
| 69 | <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> | ||
| 70 | </property> | 80 | </property> |
| 71 | <property name="wordWrap"> | 81 | <property name="wordWrap"> |
| 72 | <bool>true</bool> | 82 | <bool>true</bool> |
| @@ -86,8 +96,17 @@ | |||
| 86 | <item row="0" column="1" colspan="2"> | 96 | <item row="0" column="1" colspan="2"> |
| 87 | <widget class="QComboBox" name="bcat_source"/> | 97 | <widget class="QComboBox" name="bcat_source"/> |
| 88 | </item> | 98 | </item> |
| 89 | <item row="3" column="0"> | 99 | <item row="3" column="1" colspan="2"> |
| 90 | <widget class="QLabel" name="bcat_empty_header"> | 100 | <widget class="QLabel" name="bcat_empty_label"> |
| 101 | <property name="enabled"> | ||
| 102 | <bool>true</bool> | ||
| 103 | </property> | ||
| 104 | <property name="maximumSize"> | ||
| 105 | <size> | ||
| 106 | <width>260</width> | ||
| 107 | <height>16777215</height> | ||
| 108 | </size> | ||
| 109 | </property> | ||
| 91 | <property name="text"> | 110 | <property name="text"> |
| 92 | <string/> | 111 | <string/> |
| 93 | </property> | 112 | </property> |
diff --git a/src/yuzu/debugger/console.cpp b/src/yuzu/debugger/console.cpp index 22ca1285d..f89ea8ea7 100644 --- a/src/yuzu/debugger/console.cpp +++ b/src/yuzu/debugger/console.cpp | |||
| @@ -21,6 +21,7 @@ void ToggleConsole() { | |||
| 21 | console_shown = UISettings::values.show_console.GetValue(); | 21 | console_shown = UISettings::values.show_console.GetValue(); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | using namespace Common::Log; | ||
| 24 | #if defined(_WIN32) && !defined(_DEBUG) | 25 | #if defined(_WIN32) && !defined(_DEBUG) |
| 25 | FILE* temp; | 26 | FILE* temp; |
| 26 | if (UISettings::values.show_console) { | 27 | if (UISettings::values.show_console) { |
| @@ -29,24 +30,20 @@ void ToggleConsole() { | |||
| 29 | freopen_s(&temp, "CONIN$", "r", stdin); | 30 | freopen_s(&temp, "CONIN$", "r", stdin); |
| 30 | freopen_s(&temp, "CONOUT$", "w", stdout); | 31 | freopen_s(&temp, "CONOUT$", "w", stdout); |
| 31 | freopen_s(&temp, "CONOUT$", "w", stderr); | 32 | freopen_s(&temp, "CONOUT$", "w", stderr); |
| 32 | Common::Log::AddBackend(std::make_unique<Common::Log::ColorConsoleBackend>()); | 33 | SetColorConsoleBackendEnabled(true); |
| 33 | } | 34 | } |
| 34 | } else { | 35 | } else { |
| 35 | if (FreeConsole()) { | 36 | if (FreeConsole()) { |
| 36 | // In order to close the console, we have to also detach the streams on it. | 37 | // In order to close the console, we have to also detach the streams on it. |
| 37 | // Just redirect them to NUL if there is no console window | 38 | // Just redirect them to NUL if there is no console window |
| 38 | Common::Log::RemoveBackend(Common::Log::ColorConsoleBackend::Name()); | 39 | SetColorConsoleBackendEnabled(false); |
| 39 | freopen_s(&temp, "NUL", "r", stdin); | 40 | freopen_s(&temp, "NUL", "r", stdin); |
| 40 | freopen_s(&temp, "NUL", "w", stdout); | 41 | freopen_s(&temp, "NUL", "w", stdout); |
| 41 | freopen_s(&temp, "NUL", "w", stderr); | 42 | freopen_s(&temp, "NUL", "w", stderr); |
| 42 | } | 43 | } |
| 43 | } | 44 | } |
| 44 | #else | 45 | #else |
| 45 | if (UISettings::values.show_console) { | 46 | SetColorConsoleBackendEnabled(UISettings::values.show_console.GetValue()); |
| 46 | Common::Log::AddBackend(std::make_unique<Common::Log::ColorConsoleBackend>()); | ||
| 47 | } else { | ||
| 48 | Common::Log::RemoveBackend(Common::Log::ColorConsoleBackend::Name()); | ||
| 49 | } | ||
| 50 | #endif | 47 | #endif |
| 51 | } | 48 | } |
| 52 | } // namespace Debugger | 49 | } // namespace Debugger |
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index e97804220..f9d949e75 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -515,16 +515,16 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri | |||
| 515 | QAction* open_save_location = context_menu.addAction(tr("Open Save Data Location")); | 515 | QAction* open_save_location = context_menu.addAction(tr("Open Save Data Location")); |
| 516 | QAction* open_mod_location = context_menu.addAction(tr("Open Mod Data Location")); | 516 | QAction* open_mod_location = context_menu.addAction(tr("Open Mod Data Location")); |
| 517 | QAction* open_transferable_shader_cache = | 517 | QAction* open_transferable_shader_cache = |
| 518 | context_menu.addAction(tr("Open Transferable Shader Cache")); | 518 | context_menu.addAction(tr("Open Transferable Pipeline Cache")); |
| 519 | context_menu.addSeparator(); | 519 | context_menu.addSeparator(); |
| 520 | QMenu* remove_menu = context_menu.addMenu(tr("Remove")); | 520 | QMenu* remove_menu = context_menu.addMenu(tr("Remove")); |
| 521 | QAction* remove_update = remove_menu->addAction(tr("Remove Installed Update")); | 521 | QAction* remove_update = remove_menu->addAction(tr("Remove Installed Update")); |
| 522 | QAction* remove_dlc = remove_menu->addAction(tr("Remove All Installed DLC")); | 522 | QAction* remove_dlc = remove_menu->addAction(tr("Remove All Installed DLC")); |
| 523 | QAction* remove_custom_config = remove_menu->addAction(tr("Remove Custom Configuration")); | 523 | QAction* remove_custom_config = remove_menu->addAction(tr("Remove Custom Configuration")); |
| 524 | QAction* remove_gl_shader_cache = remove_menu->addAction(tr("Remove OpenGL Shader Cache")); | 524 | QAction* remove_gl_shader_cache = remove_menu->addAction(tr("Remove OpenGL Pipeline Cache")); |
| 525 | QAction* remove_vk_shader_cache = remove_menu->addAction(tr("Remove Vulkan Shader Cache")); | 525 | QAction* remove_vk_shader_cache = remove_menu->addAction(tr("Remove Vulkan Pipeline Cache")); |
| 526 | remove_menu->addSeparator(); | 526 | remove_menu->addSeparator(); |
| 527 | QAction* remove_shader_cache = remove_menu->addAction(tr("Remove All Shader Caches")); | 527 | QAction* remove_shader_cache = remove_menu->addAction(tr("Remove All Pipeline Caches")); |
| 528 | QAction* remove_all_content = remove_menu->addAction(tr("Remove All Installed Contents")); | 528 | QAction* remove_all_content = remove_menu->addAction(tr("Remove All Installed Contents")); |
| 529 | QMenu* dump_romfs_menu = context_menu.addMenu(tr("Dump RomFS")); | 529 | QMenu* dump_romfs_menu = context_menu.addMenu(tr("Dump RomFS")); |
| 530 | QAction* dump_romfs = dump_romfs_menu->addAction(tr("Dump RomFS")); | 530 | QAction* dump_romfs = dump_romfs_menu->addAction(tr("Dump RomFS")); |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 5940e0cfd..e36774cc6 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -175,21 +175,6 @@ void GMainWindow::ShowTelemetryCallout() { | |||
| 175 | 175 | ||
| 176 | const int GMainWindow::max_recent_files_item; | 176 | const int GMainWindow::max_recent_files_item; |
| 177 | 177 | ||
| 178 | static void InitializeLogging() { | ||
| 179 | using namespace Common; | ||
| 180 | |||
| 181 | Log::Filter log_filter; | ||
| 182 | log_filter.ParseFilterString(Settings::values.log_filter.GetValue()); | ||
| 183 | Log::SetGlobalFilter(log_filter); | ||
| 184 | |||
| 185 | const auto log_dir = FS::GetYuzuPath(FS::YuzuPath::LogDir); | ||
| 186 | void(FS::CreateDir(log_dir)); | ||
| 187 | Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir / LOG_FILE)); | ||
| 188 | #ifdef _WIN32 | ||
| 189 | Log::AddBackend(std::make_unique<Log::DebuggerBackend>()); | ||
| 190 | #endif | ||
| 191 | } | ||
| 192 | |||
| 193 | static void RemoveCachedContents() { | 178 | static void RemoveCachedContents() { |
| 194 | const auto cache_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir); | 179 | const auto cache_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir); |
| 195 | const auto offline_fonts = cache_dir / "fonts"; | 180 | const auto offline_fonts = cache_dir / "fonts"; |
| @@ -207,8 +192,7 @@ GMainWindow::GMainWindow() | |||
| 207 | : input_subsystem{std::make_shared<InputCommon::InputSubsystem>()}, | 192 | : input_subsystem{std::make_shared<InputCommon::InputSubsystem>()}, |
| 208 | config{std::make_unique<Config>()}, vfs{std::make_shared<FileSys::RealVfsFilesystem>()}, | 193 | config{std::make_unique<Config>()}, vfs{std::make_shared<FileSys::RealVfsFilesystem>()}, |
| 209 | provider{std::make_unique<FileSys::ManualContentProvider>()} { | 194 | provider{std::make_unique<FileSys::ManualContentProvider>()} { |
| 210 | InitializeLogging(); | 195 | Common::Log::Initialize(); |
| 211 | |||
| 212 | LoadTranslation(); | 196 | LoadTranslation(); |
| 213 | 197 | ||
| 214 | setAcceptDrops(true); | 198 | setAcceptDrops(true); |
| @@ -3437,6 +3421,7 @@ int main(int argc, char* argv[]) { | |||
| 3437 | // generating shaders | 3421 | // generating shaders |
| 3438 | setlocale(LC_ALL, "C"); | 3422 | setlocale(LC_ALL, "C"); |
| 3439 | 3423 | ||
| 3424 | Core::System::InitializeGlobalInstance(); | ||
| 3440 | GMainWindow main_window; | 3425 | GMainWindow main_window; |
| 3441 | // After settings have been loaded by GMainWindow, apply the filter | 3426 | // After settings have been loaded by GMainWindow, apply the filter |
| 3442 | main_window.show(); | 3427 | main_window.show(); |
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 464cd472e..891f7be6f 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp | |||
| @@ -468,7 +468,6 @@ void Config::ReadValues() { | |||
| 468 | ReadSetting("Renderer", Settings::values.nvdec_emulation); | 468 | ReadSetting("Renderer", Settings::values.nvdec_emulation); |
| 469 | ReadSetting("Renderer", Settings::values.accelerate_astc); | 469 | ReadSetting("Renderer", Settings::values.accelerate_astc); |
| 470 | ReadSetting("Renderer", Settings::values.use_fast_gpu_time); | 470 | ReadSetting("Renderer", Settings::values.use_fast_gpu_time); |
| 471 | ReadSetting("Renderer", Settings::values.use_caches_gc); | ||
| 472 | 471 | ||
| 473 | ReadSetting("Renderer", Settings::values.bg_red); | 472 | ReadSetting("Renderer", Settings::values.bg_red); |
| 474 | ReadSetting("Renderer", Settings::values.bg_green); | 473 | ReadSetting("Renderer", Settings::values.bg_green); |
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index c10093820..ba2c993ba 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp | |||
| @@ -74,31 +74,14 @@ static void PrintVersion() { | |||
| 74 | std::cout << "yuzu " << Common::g_scm_branch << " " << Common::g_scm_desc << std::endl; | 74 | std::cout << "yuzu " << Common::g_scm_branch << " " << Common::g_scm_desc << std::endl; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | static void InitializeLogging() { | ||
| 78 | using namespace Common; | ||
| 79 | |||
| 80 | Log::Filter log_filter(Log::Level::Debug); | ||
| 81 | log_filter.ParseFilterString(static_cast<std::string>(Settings::values.log_filter)); | ||
| 82 | Log::SetGlobalFilter(log_filter); | ||
| 83 | |||
| 84 | Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>()); | ||
| 85 | |||
| 86 | const auto& log_dir = FS::GetYuzuPath(FS::YuzuPath::LogDir); | ||
| 87 | void(FS::CreateDir(log_dir)); | ||
| 88 | Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir / LOG_FILE)); | ||
| 89 | #ifdef _WIN32 | ||
| 90 | Log::AddBackend(std::make_unique<Log::DebuggerBackend>()); | ||
| 91 | #endif | ||
| 92 | } | ||
| 93 | |||
| 94 | /// Application entry point | 77 | /// Application entry point |
| 95 | int main(int argc, char** argv) { | 78 | int main(int argc, char** argv) { |
| 79 | Common::Log::Initialize(); | ||
| 80 | Common::Log::SetColorConsoleBackendEnabled(true); | ||
| 96 | Common::DetachedTasks detached_tasks; | 81 | Common::DetachedTasks detached_tasks; |
| 97 | Config config; | 82 | Config config; |
| 98 | 83 | ||
| 99 | int option_index = 0; | 84 | int option_index = 0; |
| 100 | |||
| 101 | InitializeLogging(); | ||
| 102 | #ifdef _WIN32 | 85 | #ifdef _WIN32 |
| 103 | int argc_w; | 86 | int argc_w; |
| 104 | auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w); | 87 | auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w); |
| @@ -163,6 +146,7 @@ int main(int argc, char** argv) { | |||
| 163 | return -1; | 146 | return -1; |
| 164 | } | 147 | } |
| 165 | 148 | ||
| 149 | Core::System::InitializeGlobalInstance(); | ||
| 166 | auto& system{Core::System::GetInstance()}; | 150 | auto& system{Core::System::GetInstance()}; |
| 167 | InputCommon::InputSubsystem input_subsystem; | 151 | InputCommon::InputSubsystem input_subsystem; |
| 168 | 152 | ||