diff options
56 files changed, 1283 insertions, 580 deletions
diff --git a/.ci/scripts/windows/upload.ps1 b/.ci/scripts/windows/upload.ps1 index 21abcd752..492763420 100644 --- a/.ci/scripts/windows/upload.ps1 +++ b/.ci/scripts/windows/upload.ps1 | |||
| @@ -26,7 +26,11 @@ $env:BUILD_ZIP = $MSVC_BUILD_ZIP | |||
| 26 | $env:BUILD_SYMBOLS = $MSVC_BUILD_PDB | 26 | $env:BUILD_SYMBOLS = $MSVC_BUILD_PDB |
| 27 | $env:BUILD_UPDATE = $MSVC_SEVENZIP | 27 | $env:BUILD_UPDATE = $MSVC_SEVENZIP |
| 28 | 28 | ||
| 29 | $BUILD_DIR = ".\build\bin\Release" | 29 | if (Test-Path -Path ".\build\bin\Release") { |
| 30 | $BUILD_DIR = ".\build\bin\Release" | ||
| 31 | } else { | ||
| 32 | $BUILD_DIR = ".\build\bin\" | ||
| 33 | } | ||
| 30 | 34 | ||
| 31 | # Cleanup unneeded data in submodules | 35 | # Cleanup unneeded data in submodules |
| 32 | git submodule foreach git clean -fxd | 36 | git submodule foreach git clean -fxd |
diff --git a/CMakeLists.txt b/CMakeLists.txt index 561eaafb2..7276ac9dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -453,6 +453,7 @@ endif() | |||
| 453 | # List of all FFmpeg components required | 453 | # List of all FFmpeg components required |
| 454 | set(FFmpeg_COMPONENTS | 454 | set(FFmpeg_COMPONENTS |
| 455 | avcodec | 455 | avcodec |
| 456 | avfilter | ||
| 456 | avutil | 457 | avutil |
| 457 | swscale) | 458 | swscale) |
| 458 | 459 | ||
diff --git a/CMakeModules/CopyYuzuFFmpegDeps.cmake b/CMakeModules/CopyYuzuFFmpegDeps.cmake index c6231737e..e50696cc0 100644 --- a/CMakeModules/CopyYuzuFFmpegDeps.cmake +++ b/CMakeModules/CopyYuzuFFmpegDeps.cmake | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | function(copy_yuzu_FFmpeg_deps target_dir) | 4 | function(copy_yuzu_FFmpeg_deps target_dir) |
| 5 | include(WindowsCopyFiles) | 5 | include(WindowsCopyFiles) |
| 6 | set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/") | 6 | set(DLL_DEST "$<TARGET_FILE_DIR:${target_dir}>/") |
| 7 | file(READ "${FFmpeg_PATH}/requirements.txt" FFmpeg_REQUIRED_DLLS) | 7 | file(READ "${FFmpeg_PATH}/requirements.txt" FFmpeg_REQUIRED_DLLS) |
| 8 | string(STRIP "${FFmpeg_REQUIRED_DLLS}" FFmpeg_REQUIRED_DLLS) | 8 | string(STRIP "${FFmpeg_REQUIRED_DLLS}" FFmpeg_REQUIRED_DLLS) |
| 9 | windows_copy_files(${target_dir} ${FFmpeg_DLL_DIR} ${DLL_DEST} ${FFmpeg_REQUIRED_DLLS}) | 9 | windows_copy_files(${target_dir} ${FFmpeg_LIBRARY_DIR} ${DLL_DEST} ${FFmpeg_REQUIRED_DLLS}) |
| 10 | endfunction(copy_yuzu_FFmpeg_deps) | 10 | endfunction(copy_yuzu_FFmpeg_deps) |
diff --git a/CMakeModules/CopyYuzuQt5Deps.cmake b/CMakeModules/CopyYuzuQt5Deps.cmake index ab56de444..b3a65c347 100644 --- a/CMakeModules/CopyYuzuQt5Deps.cmake +++ b/CMakeModules/CopyYuzuQt5Deps.cmake | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | function(copy_yuzu_Qt5_deps target_dir) | 4 | function(copy_yuzu_Qt5_deps target_dir) |
| 5 | include(WindowsCopyFiles) | 5 | include(WindowsCopyFiles) |
| 6 | if (MSVC) | 6 | if (MSVC) |
| 7 | set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/") | 7 | set(DLL_DEST "$<TARGET_FILE_DIR:${target_dir}>/") |
| 8 | set(Qt5_DLL_DIR "${Qt5_DIR}/../../../bin") | 8 | set(Qt5_DLL_DIR "${Qt5_DIR}/../../../bin") |
| 9 | else() | 9 | else() |
| 10 | set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/") | 10 | set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/") |
diff --git a/CMakeModules/CopyYuzuSDLDeps.cmake b/CMakeModules/CopyYuzuSDLDeps.cmake index 7ffdd8a1d..464eed5e9 100644 --- a/CMakeModules/CopyYuzuSDLDeps.cmake +++ b/CMakeModules/CopyYuzuSDLDeps.cmake | |||
| @@ -3,6 +3,6 @@ | |||
| 3 | 3 | ||
| 4 | function(copy_yuzu_SDL_deps target_dir) | 4 | function(copy_yuzu_SDL_deps target_dir) |
| 5 | include(WindowsCopyFiles) | 5 | include(WindowsCopyFiles) |
| 6 | set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/") | 6 | set(DLL_DEST "$<TARGET_FILE_DIR:${target_dir}>/") |
| 7 | windows_copy_files(${target_dir} ${SDL2_DLL_DIR} ${DLL_DEST} SDL2.dll) | 7 | windows_copy_files(${target_dir} ${SDL2_DLL_DIR} ${DLL_DEST} SDL2.dll) |
| 8 | endfunction(copy_yuzu_SDL_deps) | 8 | endfunction(copy_yuzu_SDL_deps) |
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index e59eeb489..d78d10147 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt | |||
| @@ -8,15 +8,21 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) | |||
| 8 | # Disable tests in all externals supporting the standard option name | 8 | # Disable tests in all externals supporting the standard option name |
| 9 | set(BUILD_TESTING OFF) | 9 | set(BUILD_TESTING OFF) |
| 10 | 10 | ||
| 11 | # Build only static externals | ||
| 12 | set(BUILD_SHARED_LIBS OFF) | ||
| 13 | |||
| 14 | # Skip install rules for all externals | ||
| 15 | set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL ON) | ||
| 16 | |||
| 11 | # xbyak | 17 | # xbyak |
| 12 | if ((ARCHITECTURE_x86 OR ARCHITECTURE_x86_64) AND NOT TARGET xbyak::xbyak) | 18 | if ((ARCHITECTURE_x86 OR ARCHITECTURE_x86_64) AND NOT TARGET xbyak::xbyak) |
| 13 | add_subdirectory(xbyak EXCLUDE_FROM_ALL) | 19 | add_subdirectory(xbyak) |
| 14 | endif() | 20 | endif() |
| 15 | 21 | ||
| 16 | # Dynarmic | 22 | # Dynarmic |
| 17 | if ((ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64) AND NOT TARGET dynarmic::dynarmic) | 23 | if ((ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64) AND NOT TARGET dynarmic::dynarmic) |
| 18 | set(DYNARMIC_IGNORE_ASSERTS ON) | 24 | set(DYNARMIC_IGNORE_ASSERTS ON) |
| 19 | add_subdirectory(dynarmic EXCLUDE_FROM_ALL) | 25 | add_subdirectory(dynarmic) |
| 20 | add_library(dynarmic::dynarmic ALIAS dynarmic) | 26 | add_library(dynarmic::dynarmic ALIAS dynarmic) |
| 21 | endif() | 27 | endif() |
| 22 | 28 | ||
| @@ -34,7 +40,7 @@ if (NOT TARGET inih::INIReader) | |||
| 34 | endif() | 40 | endif() |
| 35 | 41 | ||
| 36 | # mbedtls | 42 | # mbedtls |
| 37 | add_subdirectory(mbedtls EXCLUDE_FROM_ALL) | 43 | add_subdirectory(mbedtls) |
| 38 | target_include_directories(mbedtls PUBLIC ./mbedtls/include) | 44 | target_include_directories(mbedtls PUBLIC ./mbedtls/include) |
| 39 | 45 | ||
| 40 | # MicroProfile | 46 | # MicroProfile |
| @@ -48,7 +54,7 @@ endif() | |||
| 48 | 54 | ||
| 49 | # libusb | 55 | # libusb |
| 50 | if (ENABLE_LIBUSB AND NOT TARGET libusb::usb) | 56 | if (ENABLE_LIBUSB AND NOT TARGET libusb::usb) |
| 51 | add_subdirectory(libusb EXCLUDE_FROM_ALL) | 57 | add_subdirectory(libusb) |
| 52 | endif() | 58 | endif() |
| 53 | 59 | ||
| 54 | # SDL2 | 60 | # SDL2 |
| @@ -67,18 +73,16 @@ if (YUZU_USE_EXTERNAL_SDL2) | |||
| 67 | 73 | ||
| 68 | set(HIDAPI ON) | 74 | set(HIDAPI ON) |
| 69 | endif() | 75 | endif() |
| 70 | set(SDL_STATIC ON) | ||
| 71 | set(SDL_SHARED OFF) | ||
| 72 | if (APPLE) | 76 | if (APPLE) |
| 73 | set(SDL_FILE ON) | 77 | set(SDL_FILE ON) |
| 74 | endif() | 78 | endif() |
| 75 | 79 | ||
| 76 | add_subdirectory(SDL EXCLUDE_FROM_ALL) | 80 | add_subdirectory(SDL) |
| 77 | endif() | 81 | endif() |
| 78 | 82 | ||
| 79 | # ENet | 83 | # ENet |
| 80 | if (NOT TARGET enet::enet) | 84 | if (NOT TARGET enet::enet) |
| 81 | add_subdirectory(enet EXCLUDE_FROM_ALL) | 85 | add_subdirectory(enet) |
| 82 | target_include_directories(enet INTERFACE ./enet/include) | 86 | target_include_directories(enet INTERFACE ./enet/include) |
| 83 | add_library(enet::enet ALIAS enet) | 87 | add_library(enet::enet ALIAS enet) |
| 84 | endif() | 88 | endif() |
| @@ -86,24 +90,26 @@ endif() | |||
| 86 | # Cubeb | 90 | # Cubeb |
| 87 | if (ENABLE_CUBEB AND NOT TARGET cubeb::cubeb) | 91 | if (ENABLE_CUBEB AND NOT TARGET cubeb::cubeb) |
| 88 | set(BUILD_TESTS OFF) | 92 | set(BUILD_TESTS OFF) |
| 89 | add_subdirectory(cubeb EXCLUDE_FROM_ALL) | 93 | set(BUILD_TOOLS OFF) |
| 94 | add_subdirectory(cubeb) | ||
| 90 | add_library(cubeb::cubeb ALIAS cubeb) | 95 | add_library(cubeb::cubeb ALIAS cubeb) |
| 91 | endif() | 96 | endif() |
| 92 | 97 | ||
| 93 | # DiscordRPC | 98 | # DiscordRPC |
| 94 | if (USE_DISCORD_PRESENCE AND NOT TARGET DiscordRPC::discord-rpc) | 99 | if (USE_DISCORD_PRESENCE AND NOT TARGET DiscordRPC::discord-rpc) |
| 95 | add_subdirectory(discord-rpc EXCLUDE_FROM_ALL) | 100 | set(BUILD_EXAMPLES OFF) |
| 101 | add_subdirectory(discord-rpc) | ||
| 96 | target_include_directories(discord-rpc INTERFACE ./discord-rpc/include) | 102 | target_include_directories(discord-rpc INTERFACE ./discord-rpc/include) |
| 97 | add_library(DiscordRPC::discord-rpc ALIAS discord-rpc) | 103 | add_library(DiscordRPC::discord-rpc ALIAS discord-rpc) |
| 98 | endif() | 104 | endif() |
| 99 | 105 | ||
| 100 | # Sirit | 106 | # Sirit |
| 101 | add_subdirectory(sirit EXCLUDE_FROM_ALL) | 107 | add_subdirectory(sirit) |
| 102 | 108 | ||
| 103 | # httplib | 109 | # httplib |
| 104 | if (ENABLE_WEB_SERVICE AND NOT TARGET httplib::httplib) | 110 | if (ENABLE_WEB_SERVICE AND NOT TARGET httplib::httplib) |
| 105 | set(HTTPLIB_REQUIRE_OPENSSL ON) | 111 | set(HTTPLIB_REQUIRE_OPENSSL ON) |
| 106 | add_subdirectory(cpp-httplib EXCLUDE_FROM_ALL) | 112 | add_subdirectory(cpp-httplib) |
| 107 | endif() | 113 | endif() |
| 108 | 114 | ||
| 109 | # cpp-jwt | 115 | # cpp-jwt |
| @@ -111,12 +117,12 @@ if (ENABLE_WEB_SERVICE AND NOT TARGET cpp-jwt::cpp-jwt) | |||
| 111 | set(CPP_JWT_BUILD_EXAMPLES OFF) | 117 | set(CPP_JWT_BUILD_EXAMPLES OFF) |
| 112 | set(CPP_JWT_BUILD_TESTS OFF) | 118 | set(CPP_JWT_BUILD_TESTS OFF) |
| 113 | set(CPP_JWT_USE_VENDORED_NLOHMANN_JSON OFF) | 119 | set(CPP_JWT_USE_VENDORED_NLOHMANN_JSON OFF) |
| 114 | add_subdirectory(cpp-jwt EXCLUDE_FROM_ALL) | 120 | add_subdirectory(cpp-jwt) |
| 115 | endif() | 121 | endif() |
| 116 | 122 | ||
| 117 | # Opus | 123 | # Opus |
| 118 | if (NOT TARGET Opus::opus) | 124 | if (NOT TARGET Opus::opus) |
| 119 | add_subdirectory(opus EXCLUDE_FROM_ALL) | 125 | add_subdirectory(opus) |
| 120 | endif() | 126 | endif() |
| 121 | 127 | ||
| 122 | # FFMpeg | 128 | # FFMpeg |
| @@ -130,16 +136,14 @@ endif() | |||
| 130 | 136 | ||
| 131 | # Vulkan-Headers | 137 | # Vulkan-Headers |
| 132 | if (YUZU_USE_EXTERNAL_VULKAN_HEADERS) | 138 | if (YUZU_USE_EXTERNAL_VULKAN_HEADERS) |
| 133 | add_subdirectory(Vulkan-Headers EXCLUDE_FROM_ALL) | 139 | add_subdirectory(Vulkan-Headers) |
| 134 | endif() | 140 | endif() |
| 135 | 141 | ||
| 136 | if (NOT TARGET LLVM::Demangle) | 142 | if (NOT TARGET LLVM::Demangle) |
| 137 | add_library(demangle STATIC) | 143 | add_library(demangle demangle/ItaniumDemangle.cpp) |
| 138 | target_include_directories(demangle PUBLIC ./demangle) | 144 | target_include_directories(demangle PUBLIC ./demangle) |
| 139 | target_sources(demangle PRIVATE demangle/ItaniumDemangle.cpp) | ||
| 140 | add_library(LLVM::Demangle ALIAS demangle) | 145 | add_library(LLVM::Demangle ALIAS demangle) |
| 141 | endif() | 146 | endif() |
| 142 | 147 | ||
| 143 | add_library(stb STATIC) | 148 | add_library(stb stb/stb_dxt.cpp) |
| 144 | target_include_directories(stb PUBLIC ./stb) | 149 | target_include_directories(stb PUBLIC ./stb) |
| 145 | target_sources(stb PRIVATE stb/stb_dxt.cpp) | ||
diff --git a/externals/ffmpeg/CMakeLists.txt b/externals/ffmpeg/CMakeLists.txt index 0baac8e17..03fad0778 100644 --- a/externals/ffmpeg/CMakeLists.txt +++ b/externals/ffmpeg/CMakeLists.txt | |||
| @@ -131,7 +131,6 @@ if (NOT WIN32) | |||
| 131 | COMMAND | 131 | COMMAND |
| 132 | /bin/bash ${FFmpeg_PREFIX}/configure | 132 | /bin/bash ${FFmpeg_PREFIX}/configure |
| 133 | --disable-avdevice | 133 | --disable-avdevice |
| 134 | --disable-avfilter | ||
| 135 | --disable-avformat | 134 | --disable-avformat |
| 136 | --disable-doc | 135 | --disable-doc |
| 137 | --disable-everything | 136 | --disable-everything |
| @@ -143,6 +142,7 @@ if (NOT WIN32) | |||
| 143 | --enable-decoder=h264 | 142 | --enable-decoder=h264 |
| 144 | --enable-decoder=vp8 | 143 | --enable-decoder=vp8 |
| 145 | --enable-decoder=vp9 | 144 | --enable-decoder=vp9 |
| 145 | --enable-filter=yadif | ||
| 146 | --cc="${FFmpeg_CC}" | 146 | --cc="${FFmpeg_CC}" |
| 147 | --cxx="${FFmpeg_CXX}" | 147 | --cxx="${FFmpeg_CXX}" |
| 148 | ${FFmpeg_HWACCEL_FLAGS} | 148 | ${FFmpeg_HWACCEL_FLAGS} |
| @@ -199,7 +199,7 @@ if (NOT WIN32) | |||
| 199 | endif() | 199 | endif() |
| 200 | else(WIN32) | 200 | else(WIN32) |
| 201 | # Use yuzu FFmpeg binaries | 201 | # Use yuzu FFmpeg binaries |
| 202 | set(FFmpeg_EXT_NAME "ffmpeg-4.4") | 202 | set(FFmpeg_EXT_NAME "ffmpeg-5.1.3") |
| 203 | set(FFmpeg_PATH "${CMAKE_BINARY_DIR}/externals/${FFmpeg_EXT_NAME}") | 203 | set(FFmpeg_PATH "${CMAKE_BINARY_DIR}/externals/${FFmpeg_EXT_NAME}") |
| 204 | download_bundled_external("ffmpeg/" ${FFmpeg_EXT_NAME} "") | 204 | download_bundled_external("ffmpeg/" ${FFmpeg_EXT_NAME} "") |
| 205 | set(FFmpeg_FOUND YES) | 205 | set(FFmpeg_FOUND YES) |
| @@ -210,6 +210,7 @@ else(WIN32) | |||
| 210 | set(FFmpeg_LIBRARIES | 210 | set(FFmpeg_LIBRARIES |
| 211 | ${FFmpeg_LIBRARY_DIR}/swscale.lib | 211 | ${FFmpeg_LIBRARY_DIR}/swscale.lib |
| 212 | ${FFmpeg_LIBRARY_DIR}/avcodec.lib | 212 | ${FFmpeg_LIBRARY_DIR}/avcodec.lib |
| 213 | ${FFmpeg_LIBRARY_DIR}/avfilter.lib | ||
| 213 | ${FFmpeg_LIBRARY_DIR}/avutil.lib | 214 | ${FFmpeg_LIBRARY_DIR}/avutil.lib |
| 214 | CACHE PATH "Paths to FFmpeg libraries" FORCE) | 215 | CACHE PATH "Paths to FFmpeg libraries" FORCE) |
| 215 | # exported variables | 216 | # exported variables |
diff --git a/externals/glad/CMakeLists.txt b/externals/glad/CMakeLists.txt index 3dfcac2fd..0c8e285a4 100644 --- a/externals/glad/CMakeLists.txt +++ b/externals/glad/CMakeLists.txt | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | # SPDX-FileCopyrightText: 2015 Yuri Kunde Schlesner <yuriks@yuriks.net> | 1 | # SPDX-FileCopyrightText: 2015 Yuri Kunde Schlesner <yuriks@yuriks.net> |
| 2 | # SPDX-License-Identifier: GPL-2.0-or-later | 2 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | add_library(glad STATIC | 4 | add_library(glad |
| 5 | src/glad.c | 5 | src/glad.c |
| 6 | include/KHR/khrplatform.h | 6 | include/KHR/khrplatform.h |
| 7 | include/glad/glad.h | 7 | include/glad/glad.h |
diff --git a/externals/libusb/CMakeLists.txt b/externals/libusb/CMakeLists.txt index 6317ea807..6757b59da 100644 --- a/externals/libusb/CMakeLists.txt +++ b/externals/libusb/CMakeLists.txt | |||
| @@ -122,7 +122,7 @@ else() # MINGW OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux") | |||
| 122 | add_compile_options(/utf-8) | 122 | add_compile_options(/utf-8) |
| 123 | endif() | 123 | endif() |
| 124 | 124 | ||
| 125 | add_library(usb STATIC EXCLUDE_FROM_ALL | 125 | add_library(usb |
| 126 | libusb/libusb/core.c | 126 | libusb/libusb/core.c |
| 127 | libusb/libusb/core.c | 127 | libusb/libusb/core.c |
| 128 | libusb/libusb/descriptor.c | 128 | libusb/libusb/descriptor.c |
diff --git a/externals/microprofile/microprofile.h b/externals/microprofile/microprofile.h index 639f3618c..8f75a25aa 100644 --- a/externals/microprofile/microprofile.h +++ b/externals/microprofile/microprofile.h | |||
| @@ -1697,7 +1697,13 @@ void MicroProfileFlip() | |||
| 1697 | { | 1697 | { |
| 1698 | int nTimer = MicroProfileLogTimerIndex(LE); | 1698 | int nTimer = MicroProfileLogTimerIndex(LE); |
| 1699 | uint8_t nGroup = pTimerToGroup[nTimer]; | 1699 | uint8_t nGroup = pTimerToGroup[nTimer]; |
| 1700 | MP_ASSERT(nStackPos < MICROPROFILE_STACK_MAX); | 1700 | |
| 1701 | // To avoid crashing due to OOB memory accesses/asserts | ||
| 1702 | // simply skip this iteration | ||
| 1703 | // MP_ASSERT(nStackPos < MICROPROFILE_STACK_MAX); | ||
| 1704 | if (nStackPos >= MICROPROFILE_STACK_MAX) { | ||
| 1705 | break; | ||
| 1706 | } | ||
| 1701 | MP_ASSERT(nGroup < MICROPROFILE_MAX_GROUPS); | 1707 | MP_ASSERT(nGroup < MICROPROFILE_MAX_GROUPS); |
| 1702 | pGroupStackPos[nGroup]++; | 1708 | pGroupStackPos[nGroup]++; |
| 1703 | pStack[nStackPos++] = k; | 1709 | pStack[nStackPos++] = k; |
diff --git a/externals/opus/CMakeLists.txt b/externals/opus/CMakeLists.txt index 410ff7c08..d9a03423d 100644 --- a/externals/opus/CMakeLists.txt +++ b/externals/opus/CMakeLists.txt | |||
| @@ -23,7 +23,7 @@ else() | |||
| 23 | endif() | 23 | endif() |
| 24 | endif() | 24 | endif() |
| 25 | 25 | ||
| 26 | add_library(opus STATIC | 26 | add_library(opus |
| 27 | # CELT sources | 27 | # CELT sources |
| 28 | opus/celt/bands.c | 28 | opus/celt/bands.c |
| 29 | opus/celt/celt.c | 29 | opus/celt/celt.c |
diff --git a/externals/vcpkg b/externals/vcpkg | |||
| Subproject a7b6122f6b6504d16d96117336a056269357993 | Subproject 656fcc6ab2b05c6d999b7eaca717027ac3738f7 | ||
diff --git a/src/audio_core/renderer/adsp/audio_renderer.cpp b/src/audio_core/renderer/adsp/audio_renderer.cpp index 503f40349..1cbeed302 100644 --- a/src/audio_core/renderer/adsp/audio_renderer.cpp +++ b/src/audio_core/renderer/adsp/audio_renderer.cpp | |||
| @@ -154,6 +154,11 @@ void AudioRenderer::ThreadFunc() { | |||
| 154 | return; | 154 | return; |
| 155 | 155 | ||
| 156 | case RenderMessage::AudioRenderer_Render: { | 156 | case RenderMessage::AudioRenderer_Render: { |
| 157 | if (system.IsShuttingDown()) [[unlikely]] { | ||
| 158 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); | ||
| 159 | mailbox->ADSPSendMessage(RenderMessage::AudioRenderer_RenderResponse); | ||
| 160 | continue; | ||
| 161 | } | ||
| 157 | std::array<bool, MaxRendererSessions> buffers_reset{}; | 162 | std::array<bool, MaxRendererSessions> buffers_reset{}; |
| 158 | std::array<u64, MaxRendererSessions> render_times_taken{}; | 163 | std::array<u64, MaxRendererSessions> render_times_taken{}; |
| 159 | const auto start_time{system.CoreTiming().GetClockTicks()}; | 164 | const auto start_time{system.CoreTiming().GetClockTicks()}; |
diff --git a/src/audio_core/renderer/system_manager.cpp b/src/audio_core/renderer/system_manager.cpp index 07d8ed093..300ecdbf1 100644 --- a/src/audio_core/renderer/system_manager.cpp +++ b/src/audio_core/renderer/system_manager.cpp | |||
| @@ -27,7 +27,7 @@ bool SystemManager::InitializeUnsafe() { | |||
| 27 | if (!active) { | 27 | if (!active) { |
| 28 | if (adsp.Start()) { | 28 | if (adsp.Start()) { |
| 29 | active = true; | 29 | active = true; |
| 30 | thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(); }); | 30 | thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(stop_token); }); |
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| @@ -39,8 +39,7 @@ void SystemManager::Stop() { | |||
| 39 | return; | 39 | return; |
| 40 | } | 40 | } |
| 41 | active = false; | 41 | active = false; |
| 42 | update.store(true); | 42 | thread.request_stop(); |
| 43 | update.notify_all(); | ||
| 44 | thread.join(); | 43 | thread.join(); |
| 45 | adsp.Stop(); | 44 | adsp.Stop(); |
| 46 | } | 45 | } |
| @@ -85,12 +84,12 @@ bool SystemManager::Remove(System& system_) { | |||
| 85 | return true; | 84 | return true; |
| 86 | } | 85 | } |
| 87 | 86 | ||
| 88 | void SystemManager::ThreadFunc() { | 87 | void SystemManager::ThreadFunc(std::stop_token stop_token) { |
| 89 | static constexpr char name[]{"AudioRenderSystemManager"}; | 88 | static constexpr char name[]{"AudioRenderSystemManager"}; |
| 90 | MicroProfileOnThreadCreate(name); | 89 | MicroProfileOnThreadCreate(name); |
| 91 | Common::SetCurrentThreadName(name); | 90 | Common::SetCurrentThreadName(name); |
| 92 | Common::SetCurrentThreadPriority(Common::ThreadPriority::High); | 91 | Common::SetCurrentThreadPriority(Common::ThreadPriority::High); |
| 93 | while (active) { | 92 | while (active && !stop_token.stop_requested()) { |
| 94 | { | 93 | { |
| 95 | std::scoped_lock l{mutex1}; | 94 | std::scoped_lock l{mutex1}; |
| 96 | 95 | ||
diff --git a/src/audio_core/renderer/system_manager.h b/src/audio_core/renderer/system_manager.h index 1f0bbd8b4..9681fd121 100644 --- a/src/audio_core/renderer/system_manager.h +++ b/src/audio_core/renderer/system_manager.h | |||
| @@ -66,13 +66,7 @@ private: | |||
| 66 | /** | 66 | /** |
| 67 | * Main thread responsible for command generation. | 67 | * Main thread responsible for command generation. |
| 68 | */ | 68 | */ |
| 69 | void ThreadFunc(); | 69 | void ThreadFunc(std::stop_token stop_token); |
| 70 | |||
| 71 | enum class StreamState { | ||
| 72 | Filling, | ||
| 73 | Steady, | ||
| 74 | Draining, | ||
| 75 | }; | ||
| 76 | 70 | ||
| 77 | /// Core system | 71 | /// Core system |
| 78 | Core::System& core; | 72 | Core::System& core; |
| @@ -90,8 +84,6 @@ private: | |||
| 90 | ADSP::ADSP& adsp; | 84 | ADSP::ADSP& adsp; |
| 91 | /// AudioRenderer mailbox for communication | 85 | /// AudioRenderer mailbox for communication |
| 92 | ADSP::AudioRenderer_Mailbox* mailbox{}; | 86 | ADSP::AudioRenderer_Mailbox* mailbox{}; |
| 93 | /// Atomic for main thread to wait on | ||
| 94 | std::atomic<bool> update{}; | ||
| 95 | }; | 87 | }; |
| 96 | 88 | ||
| 97 | } // namespace AudioCore::AudioRenderer | 89 | } // namespace AudioCore::AudioRenderer |
diff --git a/src/audio_core/sink/sink_stream.cpp b/src/audio_core/sink/sink_stream.cpp index 13ba26e74..2331aaff9 100644 --- a/src/audio_core/sink/sink_stream.cpp +++ b/src/audio_core/sink/sink_stream.cpp | |||
| @@ -271,8 +271,11 @@ u64 SinkStream::GetExpectedPlayedSampleCount() { | |||
| 271 | 271 | ||
| 272 | void SinkStream::WaitFreeSpace() { | 272 | void SinkStream::WaitFreeSpace() { |
| 273 | std::unique_lock lk{release_mutex}; | 273 | std::unique_lock lk{release_mutex}; |
| 274 | release_cv.wait( | 274 | release_cv.wait_for(lk, std::chrono::milliseconds(5), |
| 275 | lk, [this]() { return queued_buffers < max_queue_size || system.IsShuttingDown(); }); | 275 | [this]() { return queued_buffers < max_queue_size; }); |
| 276 | if (queued_buffers > max_queue_size + 3) { | ||
| 277 | release_cv.wait(lk, [this]() { return queued_buffers < max_queue_size; }); | ||
| 278 | } | ||
| 276 | } | 279 | } |
| 277 | 280 | ||
| 278 | } // namespace AudioCore::Sink | 281 | } // namespace AudioCore::Sink |
diff --git a/src/common/bit_field.h b/src/common/bit_field.h index e4e58ea45..0168ff9cb 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h | |||
| @@ -188,3 +188,8 @@ private: | |||
| 188 | 188 | ||
| 189 | template <std::size_t Position, std::size_t Bits, typename T> | 189 | template <std::size_t Position, std::size_t Bits, typename T> |
| 190 | using BitFieldBE = BitField<Position, Bits, T, BETag>; | 190 | using BitFieldBE = BitField<Position, Bits, T, BETag>; |
| 191 | |||
| 192 | template <std::size_t Position, std::size_t Bits, typename T, typename EndianTag = LETag> | ||
| 193 | inline auto format_as(BitField<Position, Bits, T, EndianTag> bitfield) { | ||
| 194 | return bitfield.Value(); | ||
| 195 | } | ||
diff --git a/src/core/core.cpp b/src/core/core.cpp index b5f62690e..4406ae30e 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -117,8 +117,7 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, | |||
| 117 | return nullptr; | 117 | return nullptr; |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | return FileSys::ConcatenatedVfsFile::MakeConcatenatedFile(std::move(concat), | 120 | return FileSys::ConcatenatedVfsFile::MakeConcatenatedFile(concat, dir->GetName()); |
| 121 | dir->GetName()); | ||
| 122 | } | 121 | } |
| 123 | 122 | ||
| 124 | if (Common::FS::IsDir(path)) { | 123 | if (Common::FS::IsDir(path)) { |
diff --git a/src/core/file_sys/romfs.cpp b/src/core/file_sys/romfs.cpp index ddcfe5980..fb5683a6b 100644 --- a/src/core/file_sys/romfs.cpp +++ b/src/core/file_sys/romfs.cpp | |||
| @@ -140,7 +140,8 @@ VirtualFile CreateRomFS(VirtualDir dir, VirtualDir ext) { | |||
| 140 | return nullptr; | 140 | return nullptr; |
| 141 | 141 | ||
| 142 | RomFSBuildContext ctx{dir, ext}; | 142 | RomFSBuildContext ctx{dir, ext}; |
| 143 | return ConcatenatedVfsFile::MakeConcatenatedFile(0, ctx.Build(), dir->GetName()); | 143 | auto file_map = ctx.Build(); |
| 144 | return ConcatenatedVfsFile::MakeConcatenatedFile(0, file_map, dir->GetName()); | ||
| 144 | } | 145 | } |
| 145 | 146 | ||
| 146 | } // namespace FileSys | 147 | } // namespace FileSys |
diff --git a/src/core/file_sys/vfs_concat.cpp b/src/core/file_sys/vfs_concat.cpp index d23623aa0..853b893a1 100644 --- a/src/core/file_sys/vfs_concat.cpp +++ b/src/core/file_sys/vfs_concat.cpp | |||
| @@ -10,84 +10,105 @@ | |||
| 10 | 10 | ||
| 11 | namespace FileSys { | 11 | namespace FileSys { |
| 12 | 12 | ||
| 13 | static bool VerifyConcatenationMapContinuity(const std::multimap<u64, VirtualFile>& map) { | 13 | ConcatenatedVfsFile::ConcatenatedVfsFile(ConcatenationMap&& concatenation_map_, std::string&& name_) |
| 14 | const auto last_valid = --map.end(); | 14 | : concatenation_map(std::move(concatenation_map_)), name(std::move(name_)) { |
| 15 | for (auto iter = map.begin(); iter != last_valid;) { | 15 | DEBUG_ASSERT(this->VerifyContinuity()); |
| 16 | const auto old = iter++; | 16 | } |
| 17 | if (old->first + old->second->GetSize() != iter->first) { | 17 | |
| 18 | bool ConcatenatedVfsFile::VerifyContinuity() const { | ||
| 19 | u64 last_offset = 0; | ||
| 20 | for (auto& entry : concatenation_map) { | ||
| 21 | if (entry.offset != last_offset) { | ||
| 18 | return false; | 22 | return false; |
| 19 | } | 23 | } |
| 20 | } | ||
| 21 | |||
| 22 | return map.begin()->first == 0; | ||
| 23 | } | ||
| 24 | 24 | ||
| 25 | ConcatenatedVfsFile::ConcatenatedVfsFile(std::vector<VirtualFile> files_, std::string name_) | 25 | last_offset = entry.offset + entry.file->GetSize(); |
| 26 | : name(std::move(name_)) { | ||
| 27 | std::size_t next_offset = 0; | ||
| 28 | for (const auto& file : files_) { | ||
| 29 | files.emplace(next_offset, file); | ||
| 30 | next_offset += file->GetSize(); | ||
| 31 | } | 26 | } |
| 32 | } | ||
| 33 | 27 | ||
| 34 | ConcatenatedVfsFile::ConcatenatedVfsFile(std::multimap<u64, VirtualFile> files_, std::string name_) | 28 | return true; |
| 35 | : files(std::move(files_)), name(std::move(name_)) { | ||
| 36 | ASSERT(VerifyConcatenationMapContinuity(files)); | ||
| 37 | } | 29 | } |
| 38 | 30 | ||
| 39 | ConcatenatedVfsFile::~ConcatenatedVfsFile() = default; | 31 | ConcatenatedVfsFile::~ConcatenatedVfsFile() = default; |
| 40 | 32 | ||
| 41 | VirtualFile ConcatenatedVfsFile::MakeConcatenatedFile(std::vector<VirtualFile> files, | 33 | VirtualFile ConcatenatedVfsFile::MakeConcatenatedFile(const std::vector<VirtualFile>& files, |
| 42 | std::string name) { | 34 | std::string&& name) { |
| 43 | if (files.empty()) | 35 | // Fold trivial cases. |
| 36 | if (files.empty()) { | ||
| 44 | return nullptr; | 37 | return nullptr; |
| 45 | if (files.size() == 1) | 38 | } |
| 46 | return files[0]; | 39 | if (files.size() == 1) { |
| 40 | return files.front(); | ||
| 41 | } | ||
| 42 | |||
| 43 | // Make the concatenation map from the input. | ||
| 44 | std::vector<ConcatenationEntry> concatenation_map; | ||
| 45 | concatenation_map.reserve(files.size()); | ||
| 46 | u64 last_offset = 0; | ||
| 47 | |||
| 48 | for (auto& file : files) { | ||
| 49 | concatenation_map.emplace_back(ConcatenationEntry{ | ||
| 50 | .offset = last_offset, | ||
| 51 | .file = file, | ||
| 52 | }); | ||
| 53 | |||
| 54 | last_offset += file->GetSize(); | ||
| 55 | } | ||
| 47 | 56 | ||
| 48 | return VirtualFile(new ConcatenatedVfsFile(std::move(files), std::move(name))); | 57 | return VirtualFile(new ConcatenatedVfsFile(std::move(concatenation_map), std::move(name))); |
| 49 | } | 58 | } |
| 50 | 59 | ||
| 51 | VirtualFile ConcatenatedVfsFile::MakeConcatenatedFile(u8 filler_byte, | 60 | VirtualFile ConcatenatedVfsFile::MakeConcatenatedFile(u8 filler_byte, |
| 52 | std::multimap<u64, VirtualFile> files, | 61 | const std::multimap<u64, VirtualFile>& files, |
| 53 | std::string name) { | 62 | std::string&& name) { |
| 54 | if (files.empty()) | 63 | // Fold trivial cases. |
| 64 | if (files.empty()) { | ||
| 55 | return nullptr; | 65 | return nullptr; |
| 56 | if (files.size() == 1) | 66 | } |
| 67 | if (files.size() == 1) { | ||
| 57 | return files.begin()->second; | 68 | return files.begin()->second; |
| 69 | } | ||
| 58 | 70 | ||
| 59 | const auto last_valid = --files.end(); | 71 | // Make the concatenation map from the input. |
| 60 | for (auto iter = files.begin(); iter != last_valid;) { | 72 | std::vector<ConcatenationEntry> concatenation_map; |
| 61 | const auto old = iter++; | 73 | |
| 62 | if (old->first + old->second->GetSize() != iter->first) { | 74 | concatenation_map.reserve(files.size()); |
| 63 | files.emplace(old->first + old->second->GetSize(), | 75 | u64 last_offset = 0; |
| 64 | std::make_shared<StaticVfsFile>(filler_byte, iter->first - old->first - | 76 | |
| 65 | old->second->GetSize())); | 77 | // Iteration of a multimap is ordered, so offset will be strictly non-decreasing. |
| 78 | for (auto& [offset, file] : files) { | ||
| 79 | if (offset > last_offset) { | ||
| 80 | concatenation_map.emplace_back(ConcatenationEntry{ | ||
| 81 | .offset = last_offset, | ||
| 82 | .file = std::make_shared<StaticVfsFile>(filler_byte, offset - last_offset), | ||
| 83 | }); | ||
| 66 | } | 84 | } |
| 67 | } | ||
| 68 | 85 | ||
| 69 | // Ensure the map starts at offset 0 (start of file), otherwise pad to fill. | 86 | concatenation_map.emplace_back(ConcatenationEntry{ |
| 70 | if (files.begin()->first != 0) | 87 | .offset = offset, |
| 71 | files.emplace(0, std::make_shared<StaticVfsFile>(filler_byte, files.begin()->first)); | 88 | .file = file, |
| 89 | }); | ||
| 90 | |||
| 91 | last_offset = offset + file->GetSize(); | ||
| 92 | } | ||
| 72 | 93 | ||
| 73 | return VirtualFile(new ConcatenatedVfsFile(std::move(files), std::move(name))); | 94 | return VirtualFile(new ConcatenatedVfsFile(std::move(concatenation_map), std::move(name))); |
| 74 | } | 95 | } |
| 75 | 96 | ||
| 76 | std::string ConcatenatedVfsFile::GetName() const { | 97 | std::string ConcatenatedVfsFile::GetName() const { |
| 77 | if (files.empty()) { | 98 | if (concatenation_map.empty()) { |
| 78 | return ""; | 99 | return ""; |
| 79 | } | 100 | } |
| 80 | if (!name.empty()) { | 101 | if (!name.empty()) { |
| 81 | return name; | 102 | return name; |
| 82 | } | 103 | } |
| 83 | return files.begin()->second->GetName(); | 104 | return concatenation_map.front().file->GetName(); |
| 84 | } | 105 | } |
| 85 | 106 | ||
| 86 | std::size_t ConcatenatedVfsFile::GetSize() const { | 107 | std::size_t ConcatenatedVfsFile::GetSize() const { |
| 87 | if (files.empty()) { | 108 | if (concatenation_map.empty()) { |
| 88 | return 0; | 109 | return 0; |
| 89 | } | 110 | } |
| 90 | return files.rbegin()->first + files.rbegin()->second->GetSize(); | 111 | return concatenation_map.back().offset + concatenation_map.back().file->GetSize(); |
| 91 | } | 112 | } |
| 92 | 113 | ||
| 93 | bool ConcatenatedVfsFile::Resize(std::size_t new_size) { | 114 | bool ConcatenatedVfsFile::Resize(std::size_t new_size) { |
| @@ -95,10 +116,10 @@ bool ConcatenatedVfsFile::Resize(std::size_t new_size) { | |||
| 95 | } | 116 | } |
| 96 | 117 | ||
| 97 | VirtualDir ConcatenatedVfsFile::GetContainingDirectory() const { | 118 | VirtualDir ConcatenatedVfsFile::GetContainingDirectory() const { |
| 98 | if (files.empty()) { | 119 | if (concatenation_map.empty()) { |
| 99 | return nullptr; | 120 | return nullptr; |
| 100 | } | 121 | } |
| 101 | return files.begin()->second->GetContainingDirectory(); | 122 | return concatenation_map.front().file->GetContainingDirectory(); |
| 102 | } | 123 | } |
| 103 | 124 | ||
| 104 | bool ConcatenatedVfsFile::IsWritable() const { | 125 | bool ConcatenatedVfsFile::IsWritable() const { |
| @@ -110,25 +131,45 @@ bool ConcatenatedVfsFile::IsReadable() const { | |||
| 110 | } | 131 | } |
| 111 | 132 | ||
| 112 | std::size_t ConcatenatedVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const { | 133 | std::size_t ConcatenatedVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const { |
| 113 | auto entry = --files.end(); | 134 | const ConcatenationEntry key{ |
| 114 | for (auto iter = files.begin(); iter != files.end(); ++iter) { | 135 | .offset = offset, |
| 115 | if (iter->first > offset) { | 136 | .file = nullptr, |
| 116 | entry = --iter; | 137 | }; |
| 138 | |||
| 139 | // Read nothing if the map is empty. | ||
| 140 | if (concatenation_map.empty()) { | ||
| 141 | return 0; | ||
| 142 | } | ||
| 143 | |||
| 144 | // Binary search to find the iterator to the first position we can check. | ||
| 145 | // It must exist, since we are not empty and are comparing unsigned integers. | ||
| 146 | auto it = std::prev(std::upper_bound(concatenation_map.begin(), concatenation_map.end(), key)); | ||
| 147 | u64 cur_length = length; | ||
| 148 | u64 cur_offset = offset; | ||
| 149 | |||
| 150 | while (cur_length > 0 && it != concatenation_map.end()) { | ||
| 151 | // Check if we can read the file at this position. | ||
| 152 | const auto& file = it->file; | ||
| 153 | const u64 file_offset = it->offset; | ||
| 154 | const u64 file_size = file->GetSize(); | ||
| 155 | |||
| 156 | if (cur_offset >= file_offset + file_size) { | ||
| 157 | // Entirely out of bounds read. | ||
| 117 | break; | 158 | break; |
| 118 | } | 159 | } |
| 119 | } | ||
| 120 | 160 | ||
| 121 | if (entry->first + entry->second->GetSize() <= offset) | 161 | // Read the file at this position. |
| 122 | return 0; | 162 | const u64 intended_read_size = std::min<u64>(cur_length, file_size); |
| 163 | const u64 actual_read_size = | ||
| 164 | file->Read(data + (cur_offset - offset), intended_read_size, cur_offset - file_offset); | ||
| 123 | 165 | ||
| 124 | const auto read_in = | 166 | // Update tracking. |
| 125 | std::min<u64>(entry->first + entry->second->GetSize() - offset, entry->second->GetSize()); | 167 | cur_offset += actual_read_size; |
| 126 | if (length > read_in) { | 168 | cur_length -= actual_read_size; |
| 127 | return entry->second->Read(data, read_in, offset - entry->first) + | 169 | it++; |
| 128 | Read(data + read_in, length - read_in, offset + read_in); | ||
| 129 | } | 170 | } |
| 130 | 171 | ||
| 131 | return entry->second->Read(data, std::min<u64>(read_in, length), offset - entry->first); | 172 | return cur_offset - offset; |
| 132 | } | 173 | } |
| 133 | 174 | ||
| 134 | std::size_t ConcatenatedVfsFile::Write(const u8* data, std::size_t length, std::size_t offset) { | 175 | std::size_t ConcatenatedVfsFile::Write(const u8* data, std::size_t length, std::size_t offset) { |
diff --git a/src/core/file_sys/vfs_concat.h b/src/core/file_sys/vfs_concat.h index 9be0261b6..6b329d545 100644 --- a/src/core/file_sys/vfs_concat.h +++ b/src/core/file_sys/vfs_concat.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <compare> | ||
| 6 | #include <map> | 7 | #include <map> |
| 7 | #include <memory> | 8 | #include <memory> |
| 8 | #include "core/file_sys/vfs.h" | 9 | #include "core/file_sys/vfs.h" |
| @@ -12,19 +13,33 @@ namespace FileSys { | |||
| 12 | // Class that wraps multiple vfs files and concatenates them, making reads seamless. Currently | 13 | // Class that wraps multiple vfs files and concatenates them, making reads seamless. Currently |
| 13 | // read-only. | 14 | // read-only. |
| 14 | class ConcatenatedVfsFile : public VfsFile { | 15 | class ConcatenatedVfsFile : public VfsFile { |
| 15 | explicit ConcatenatedVfsFile(std::vector<VirtualFile> files, std::string name_); | 16 | private: |
| 16 | explicit ConcatenatedVfsFile(std::multimap<u64, VirtualFile> files, std::string name_); | 17 | struct ConcatenationEntry { |
| 18 | u64 offset; | ||
| 19 | VirtualFile file; | ||
| 20 | |||
| 21 | auto operator<=>(const ConcatenationEntry& other) const { | ||
| 22 | return this->offset <=> other.offset; | ||
| 23 | } | ||
| 24 | }; | ||
| 25 | using ConcatenationMap = std::vector<ConcatenationEntry>; | ||
| 26 | |||
| 27 | explicit ConcatenatedVfsFile(std::vector<ConcatenationEntry>&& concatenation_map, | ||
| 28 | std::string&& name); | ||
| 29 | bool VerifyContinuity() const; | ||
| 17 | 30 | ||
| 18 | public: | 31 | public: |
| 19 | ~ConcatenatedVfsFile() override; | 32 | ~ConcatenatedVfsFile() override; |
| 20 | 33 | ||
| 21 | /// Wrapper function to allow for more efficient handling of files.size() == 0, 1 cases. | 34 | /// Wrapper function to allow for more efficient handling of files.size() == 0, 1 cases. |
| 22 | static VirtualFile MakeConcatenatedFile(std::vector<VirtualFile> files, std::string name); | 35 | static VirtualFile MakeConcatenatedFile(const std::vector<VirtualFile>& files, |
| 36 | std::string&& name); | ||
| 23 | 37 | ||
| 24 | /// Convenience function that turns a map of offsets to files into a concatenated file, filling | 38 | /// Convenience function that turns a map of offsets to files into a concatenated file, filling |
| 25 | /// gaps with a given filler byte. | 39 | /// gaps with a given filler byte. |
| 26 | static VirtualFile MakeConcatenatedFile(u8 filler_byte, std::multimap<u64, VirtualFile> files, | 40 | static VirtualFile MakeConcatenatedFile(u8 filler_byte, |
| 27 | std::string name); | 41 | const std::multimap<u64, VirtualFile>& files, |
| 42 | std::string&& name); | ||
| 28 | 43 | ||
| 29 | std::string GetName() const override; | 44 | std::string GetName() const override; |
| 30 | std::size_t GetSize() const override; | 45 | std::size_t GetSize() const override; |
| @@ -37,8 +52,7 @@ public: | |||
| 37 | bool Rename(std::string_view new_name) override; | 52 | bool Rename(std::string_view new_name) override; |
| 38 | 53 | ||
| 39 | private: | 54 | private: |
| 40 | // Maps starting offset to file -- more efficient. | 55 | ConcatenationMap concatenation_map; |
| 41 | std::multimap<u64, VirtualFile> files; | ||
| 42 | std::string name; | 56 | std::string name; |
| 43 | }; | 57 | }; |
| 44 | 58 | ||
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 366880711..bbfea7117 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -1283,9 +1283,14 @@ bool EmulatedController::HasNfc() const { | |||
| 1283 | } | 1283 | } |
| 1284 | 1284 | ||
| 1285 | bool EmulatedController::WriteNfc(const std::vector<u8>& data) { | 1285 | bool EmulatedController::WriteNfc(const std::vector<u8>& data) { |
| 1286 | auto& nfc_output_device = output_devices[3]; | 1286 | auto& nfc_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)]; |
| 1287 | auto& nfc_virtual_output_device = output_devices[3]; | ||
| 1288 | |||
| 1289 | if (nfc_output_device->SupportsNfc() != Common::Input::NfcState::NotSupported) { | ||
| 1290 | return nfc_output_device->WriteNfcData(data) == Common::Input::NfcState::Success; | ||
| 1291 | } | ||
| 1287 | 1292 | ||
| 1288 | return nfc_output_device->WriteNfcData(data) == Common::Input::NfcState::Success; | 1293 | return nfc_virtual_output_device->WriteNfcData(data) == Common::Input::NfcState::Success; |
| 1289 | } | 1294 | } |
| 1290 | 1295 | ||
| 1291 | void EmulatedController::SetLedPattern() { | 1296 | void EmulatedController::SetLedPattern() { |
diff --git a/src/core/hle/service/nfc/common/amiibo_crypto.cpp b/src/core/hle/service/nfc/common/amiibo_crypto.cpp index f3901ee8d..b2bcb68c3 100644 --- a/src/core/hle/service/nfc/common/amiibo_crypto.cpp +++ b/src/core/hle/service/nfc/common/amiibo_crypto.cpp | |||
| @@ -52,9 +52,6 @@ bool IsAmiiboValid(const EncryptedNTAG215File& ntag_file) { | |||
| 52 | if (ntag_file.compability_container != 0xEEFF10F1U) { | 52 | if (ntag_file.compability_container != 0xEEFF10F1U) { |
| 53 | return false; | 53 | return false; |
| 54 | } | 54 | } |
| 55 | if (amiibo_data.constant_value != 0xA5) { | ||
| 56 | return false; | ||
| 57 | } | ||
| 58 | if (amiibo_data.model_info.tag_type != NFC::PackedTagType::Type2) { | 55 | if (amiibo_data.model_info.tag_type != NFC::PackedTagType::Type2) { |
| 59 | return false; | 56 | return false; |
| 60 | } | 57 | } |
diff --git a/src/core/hle/service/nfc/common/device.cpp b/src/core/hle/service/nfc/common/device.cpp index 322bde2ed..0bd7900e1 100644 --- a/src/core/hle/service/nfc/common/device.cpp +++ b/src/core/hle/service/nfc/common/device.cpp | |||
| @@ -119,18 +119,31 @@ bool NfcDevice::LoadNfcTag(std::span<const u8> data) { | |||
| 119 | 119 | ||
| 120 | memcpy(&tag_data, data.data(), sizeof(NFP::EncryptedNTAG215File)); | 120 | memcpy(&tag_data, data.data(), sizeof(NFP::EncryptedNTAG215File)); |
| 121 | is_plain_amiibo = NFP::AmiiboCrypto::IsAmiiboValid(tag_data); | 121 | is_plain_amiibo = NFP::AmiiboCrypto::IsAmiiboValid(tag_data); |
| 122 | is_write_protected = false; | ||
| 122 | 123 | ||
| 124 | device_state = DeviceState::TagFound; | ||
| 125 | deactivate_event->GetReadableEvent().Clear(); | ||
| 126 | activate_event->Signal(); | ||
| 127 | |||
| 128 | // Fallback for plain amiibos | ||
| 123 | if (is_plain_amiibo) { | 129 | if (is_plain_amiibo) { |
| 124 | encrypted_tag_data = NFP::AmiiboCrypto::EncodedDataToNfcData(tag_data); | ||
| 125 | LOG_INFO(Service_NFP, "Using plain amiibo"); | 130 | LOG_INFO(Service_NFP, "Using plain amiibo"); |
| 126 | } else { | 131 | encrypted_tag_data = NFP::AmiiboCrypto::EncodedDataToNfcData(tag_data); |
| 127 | tag_data = {}; | 132 | return true; |
| 133 | } | ||
| 134 | |||
| 135 | // Fallback for encrypted amiibos without keys | ||
| 136 | if (!NFP::AmiiboCrypto::IsKeyAvailable()) { | ||
| 137 | LOG_INFO(Service_NFC, "Loading amiibo without keys"); | ||
| 128 | memcpy(&encrypted_tag_data, data.data(), sizeof(NFP::EncryptedNTAG215File)); | 138 | memcpy(&encrypted_tag_data, data.data(), sizeof(NFP::EncryptedNTAG215File)); |
| 139 | BuildAmiiboWithoutKeys(); | ||
| 140 | is_plain_amiibo = true; | ||
| 141 | is_write_protected = true; | ||
| 142 | return true; | ||
| 129 | } | 143 | } |
| 130 | 144 | ||
| 131 | device_state = DeviceState::TagFound; | 145 | tag_data = {}; |
| 132 | deactivate_event->GetReadableEvent().Clear(); | 146 | memcpy(&encrypted_tag_data, data.data(), sizeof(NFP::EncryptedNTAG215File)); |
| 133 | activate_event->Signal(); | ||
| 134 | return true; | 147 | return true; |
| 135 | } | 148 | } |
| 136 | 149 | ||
| @@ -346,23 +359,15 @@ Result NfcDevice::Mount(NFP::ModelType model_type, NFP::MountTarget mount_target | |||
| 346 | return ResultWrongDeviceState; | 359 | return ResultWrongDeviceState; |
| 347 | } | 360 | } |
| 348 | 361 | ||
| 349 | // The loaded amiibo is not encrypted | ||
| 350 | if (is_plain_amiibo) { | ||
| 351 | device_state = DeviceState::TagMounted; | ||
| 352 | mount_target = mount_target_; | ||
| 353 | return ResultSuccess; | ||
| 354 | } | ||
| 355 | |||
| 356 | if (!NFP::AmiiboCrypto::IsAmiiboValid(encrypted_tag_data)) { | 362 | if (!NFP::AmiiboCrypto::IsAmiiboValid(encrypted_tag_data)) { |
| 357 | LOG_ERROR(Service_NFP, "Not an amiibo"); | 363 | LOG_ERROR(Service_NFP, "Not an amiibo"); |
| 358 | return ResultNotAnAmiibo; | 364 | return ResultNotAnAmiibo; |
| 359 | } | 365 | } |
| 360 | 366 | ||
| 361 | // Mark amiibos as read only when keys are missing | 367 | // The loaded amiibo is not encrypted |
| 362 | if (!NFP::AmiiboCrypto::IsKeyAvailable()) { | 368 | if (is_plain_amiibo) { |
| 363 | LOG_ERROR(Service_NFP, "No keys detected"); | ||
| 364 | device_state = DeviceState::TagMounted; | 369 | device_state = DeviceState::TagMounted; |
| 365 | mount_target = NFP::MountTarget::Rom; | 370 | mount_target = mount_target_; |
| 366 | return ResultSuccess; | 371 | return ResultSuccess; |
| 367 | } | 372 | } |
| 368 | 373 | ||
| @@ -421,11 +426,11 @@ Result NfcDevice::Flush() { | |||
| 421 | 426 | ||
| 422 | tag_data.write_counter++; | 427 | tag_data.write_counter++; |
| 423 | 428 | ||
| 424 | FlushWithBreak(NFP::BreakType::Normal); | 429 | const auto result = FlushWithBreak(NFP::BreakType::Normal); |
| 425 | 430 | ||
| 426 | is_data_moddified = false; | 431 | is_data_moddified = false; |
| 427 | 432 | ||
| 428 | return ResultSuccess; | 433 | return result; |
| 429 | } | 434 | } |
| 430 | 435 | ||
| 431 | Result NfcDevice::FlushDebug() { | 436 | Result NfcDevice::FlushDebug() { |
| @@ -444,11 +449,11 @@ Result NfcDevice::FlushDebug() { | |||
| 444 | 449 | ||
| 445 | tag_data.write_counter++; | 450 | tag_data.write_counter++; |
| 446 | 451 | ||
| 447 | FlushWithBreak(NFP::BreakType::Normal); | 452 | const auto result = FlushWithBreak(NFP::BreakType::Normal); |
| 448 | 453 | ||
| 449 | is_data_moddified = false; | 454 | is_data_moddified = false; |
| 450 | 455 | ||
| 451 | return ResultSuccess; | 456 | return result; |
| 452 | } | 457 | } |
| 453 | 458 | ||
| 454 | Result NfcDevice::FlushWithBreak(NFP::BreakType break_type) { | 459 | Result NfcDevice::FlushWithBreak(NFP::BreakType break_type) { |
| @@ -457,6 +462,11 @@ Result NfcDevice::FlushWithBreak(NFP::BreakType break_type) { | |||
| 457 | return ResultWrongDeviceState; | 462 | return ResultWrongDeviceState; |
| 458 | } | 463 | } |
| 459 | 464 | ||
| 465 | if (is_write_protected) { | ||
| 466 | LOG_ERROR(Service_NFP, "No keys available skipping write request"); | ||
| 467 | return ResultSuccess; | ||
| 468 | } | ||
| 469 | |||
| 460 | std::vector<u8> data(sizeof(NFP::EncryptedNTAG215File)); | 470 | std::vector<u8> data(sizeof(NFP::EncryptedNTAG215File)); |
| 461 | if (is_plain_amiibo) { | 471 | if (is_plain_amiibo) { |
| 462 | memcpy(data.data(), &tag_data, sizeof(tag_data)); | 472 | memcpy(data.data(), &tag_data, sizeof(tag_data)); |
| @@ -1033,7 +1043,6 @@ Result NfcDevice::GetAll(NFP::NfpData& data) const { | |||
| 1033 | } | 1043 | } |
| 1034 | 1044 | ||
| 1035 | NFP::CommonInfo common_info{}; | 1045 | NFP::CommonInfo common_info{}; |
| 1036 | Service::Mii::MiiManager manager; | ||
| 1037 | const u64 application_id = tag_data.application_id; | 1046 | const u64 application_id = tag_data.application_id; |
| 1038 | 1047 | ||
| 1039 | GetCommonInfo(common_info); | 1048 | GetCommonInfo(common_info); |
| @@ -1249,6 +1258,28 @@ void NfcDevice::UpdateRegisterInfoCrc() { | |||
| 1249 | tag_data.register_info_crc = crc.checksum(); | 1258 | tag_data.register_info_crc = crc.checksum(); |
| 1250 | } | 1259 | } |
| 1251 | 1260 | ||
| 1261 | void NfcDevice::BuildAmiiboWithoutKeys() { | ||
| 1262 | Service::Mii::MiiManager manager; | ||
| 1263 | auto& settings = tag_data.settings; | ||
| 1264 | |||
| 1265 | tag_data = NFP::AmiiboCrypto::NfcDataToEncodedData(encrypted_tag_data); | ||
| 1266 | |||
| 1267 | // Common info | ||
| 1268 | tag_data.write_counter = 0; | ||
| 1269 | tag_data.amiibo_version = 0; | ||
| 1270 | settings.write_date = GetAmiiboDate(GetCurrentPosixTime()); | ||
| 1271 | |||
| 1272 | // Register info | ||
| 1273 | SetAmiiboName(settings, {'y', 'u', 'z', 'u', 'A', 'm', 'i', 'i', 'b', 'o'}); | ||
| 1274 | settings.settings.font_region.Assign(0); | ||
| 1275 | settings.init_date = GetAmiiboDate(GetCurrentPosixTime()); | ||
| 1276 | tag_data.owner_mii = manager.BuildFromStoreData(manager.BuildDefault(0)); | ||
| 1277 | |||
| 1278 | // Admin info | ||
| 1279 | settings.settings.amiibo_initialized.Assign(1); | ||
| 1280 | settings.settings.appdata_initialized.Assign(0); | ||
| 1281 | } | ||
| 1282 | |||
| 1252 | u64 NfcDevice::GetHandle() const { | 1283 | u64 NfcDevice::GetHandle() const { |
| 1253 | // Generate a handle based of the npad id | 1284 | // Generate a handle based of the npad id |
| 1254 | return static_cast<u64>(npad_id); | 1285 | return static_cast<u64>(npad_id); |
diff --git a/src/core/hle/service/nfc/common/device.h b/src/core/hle/service/nfc/common/device.h index 98e1945c1..6a37e8458 100644 --- a/src/core/hle/service/nfc/common/device.h +++ b/src/core/hle/service/nfc/common/device.h | |||
| @@ -110,6 +110,8 @@ private: | |||
| 110 | void UpdateSettingsCrc(); | 110 | void UpdateSettingsCrc(); |
| 111 | void UpdateRegisterInfoCrc(); | 111 | void UpdateRegisterInfoCrc(); |
| 112 | 112 | ||
| 113 | void BuildAmiiboWithoutKeys(); | ||
| 114 | |||
| 113 | bool is_controller_set{}; | 115 | bool is_controller_set{}; |
| 114 | int callback_key; | 116 | int callback_key; |
| 115 | const Core::HID::NpadIdType npad_id; | 117 | const Core::HID::NpadIdType npad_id; |
| @@ -128,6 +130,7 @@ private: | |||
| 128 | bool is_data_moddified{}; | 130 | bool is_data_moddified{}; |
| 129 | bool is_app_area_open{}; | 131 | bool is_app_area_open{}; |
| 130 | bool is_plain_amiibo{}; | 132 | bool is_plain_amiibo{}; |
| 133 | bool is_write_protected{}; | ||
| 131 | NFP::MountTarget mount_target{NFP::MountTarget::None}; | 134 | NFP::MountTarget mount_target{NFP::MountTarget::None}; |
| 132 | 135 | ||
| 133 | NFP::NTAG215File tag_data{}; | 136 | NFP::NTAG215File tag_data{}; |
diff --git a/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp b/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp index aba51d280..c4c4c2593 100644 --- a/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp +++ b/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp | |||
| @@ -64,7 +64,7 @@ void SyncpointManager::FreeSyncpoint(u32 id) { | |||
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | bool SyncpointManager::IsSyncpointAllocated(u32 id) const { | 66 | bool SyncpointManager::IsSyncpointAllocated(u32 id) const { |
| 67 | return (id <= SyncpointCount) && syncpoints[id].reserved; | 67 | return (id < SyncpointCount) && syncpoints[id].reserved; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | bool SyncpointManager::HasSyncpointExpired(u32 id, u32 threshold) const { | 70 | bool SyncpointManager::HasSyncpointExpired(u32 id, u32 threshold) const { |
diff --git a/src/input_common/drivers/joycon.cpp b/src/input_common/drivers/joycon.cpp index 653862a72..b2b5677c8 100644 --- a/src/input_common/drivers/joycon.cpp +++ b/src/input_common/drivers/joycon.cpp | |||
| @@ -291,9 +291,13 @@ Common::Input::NfcState Joycons::SupportsNfc(const PadIdentifier& identifier_) c | |||
| 291 | return Common::Input::NfcState::Success; | 291 | return Common::Input::NfcState::Success; |
| 292 | }; | 292 | }; |
| 293 | 293 | ||
| 294 | Common::Input::NfcState Joycons::WriteNfcData(const PadIdentifier& identifier_, | 294 | Common::Input::NfcState Joycons::WriteNfcData(const PadIdentifier& identifier, |
| 295 | const std::vector<u8>& data) { | 295 | const std::vector<u8>& data) { |
| 296 | return Common::Input::NfcState::NotSupported; | 296 | auto handle = GetHandle(identifier); |
| 297 | if (handle->WriteNfcData(data) != Joycon::DriverResult::Success) { | ||
| 298 | return Common::Input::NfcState::WriteFailed; | ||
| 299 | } | ||
| 300 | return Common::Input::NfcState::Success; | ||
| 297 | }; | 301 | }; |
| 298 | 302 | ||
| 299 | Common::Input::DriverResult Joycons::SetPollingMode(const PadIdentifier& identifier, | 303 | Common::Input::DriverResult Joycons::SetPollingMode(const PadIdentifier& identifier, |
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp index 83429a336..95106f16d 100644 --- a/src/input_common/helpers/joycon_driver.cpp +++ b/src/input_common/helpers/joycon_driver.cpp | |||
| @@ -492,6 +492,26 @@ DriverResult JoyconDriver::SetRingConMode() { | |||
| 492 | return result; | 492 | return result; |
| 493 | } | 493 | } |
| 494 | 494 | ||
| 495 | DriverResult JoyconDriver::WriteNfcData(std::span<const u8> data) { | ||
| 496 | std::scoped_lock lock{mutex}; | ||
| 497 | disable_input_thread = true; | ||
| 498 | |||
| 499 | if (!supported_features.nfc) { | ||
| 500 | return DriverResult::NotSupported; | ||
| 501 | } | ||
| 502 | if (!nfc_protocol->IsEnabled()) { | ||
| 503 | return DriverResult::Disabled; | ||
| 504 | } | ||
| 505 | if (!amiibo_detected) { | ||
| 506 | return DriverResult::ErrorWritingData; | ||
| 507 | } | ||
| 508 | |||
| 509 | const auto result = nfc_protocol->WriteAmiibo(data); | ||
| 510 | |||
| 511 | disable_input_thread = false; | ||
| 512 | return result; | ||
| 513 | } | ||
| 514 | |||
| 495 | bool JoyconDriver::IsConnected() const { | 515 | bool JoyconDriver::IsConnected() const { |
| 496 | std::scoped_lock lock{mutex}; | 516 | std::scoped_lock lock{mutex}; |
| 497 | return is_connected.load(); | 517 | return is_connected.load(); |
diff --git a/src/input_common/helpers/joycon_driver.h b/src/input_common/helpers/joycon_driver.h index 72a9e71dc..e9b2fccbb 100644 --- a/src/input_common/helpers/joycon_driver.h +++ b/src/input_common/helpers/joycon_driver.h | |||
| @@ -49,6 +49,7 @@ public: | |||
| 49 | DriverResult SetIrMode(); | 49 | DriverResult SetIrMode(); |
| 50 | DriverResult SetNfcMode(); | 50 | DriverResult SetNfcMode(); |
| 51 | DriverResult SetRingConMode(); | 51 | DriverResult SetRingConMode(); |
| 52 | DriverResult WriteNfcData(std::span<const u8> data); | ||
| 52 | 53 | ||
| 53 | void SetCallbacks(const JoyconCallbacks& callbacks); | 54 | void SetCallbacks(const JoyconCallbacks& callbacks); |
| 54 | 55 | ||
diff --git a/src/input_common/helpers/joycon_protocol/joycon_types.h b/src/input_common/helpers/joycon_protocol/joycon_types.h index 353dc744d..5007b0e18 100644 --- a/src/input_common/helpers/joycon_protocol/joycon_types.h +++ b/src/input_common/helpers/joycon_protocol/joycon_types.h | |||
| @@ -23,6 +23,7 @@ constexpr std::array<u8, 8> DefaultVibrationBuffer{0x0, 0x1, 0x40, 0x40, 0x0, 0x | |||
| 23 | 23 | ||
| 24 | using MacAddress = std::array<u8, 6>; | 24 | using MacAddress = std::array<u8, 6>; |
| 25 | using SerialNumber = std::array<u8, 15>; | 25 | using SerialNumber = std::array<u8, 15>; |
| 26 | using TagUUID = std::array<u8, 7>; | ||
| 26 | 27 | ||
| 27 | enum class ControllerType : u8 { | 28 | enum class ControllerType : u8 { |
| 28 | None = 0x00, | 29 | None = 0x00, |
| @@ -276,12 +277,13 @@ enum class MCUPacketFlag : u8 { | |||
| 276 | LastCommandPacket = 0x08, | 277 | LastCommandPacket = 0x08, |
| 277 | }; | 278 | }; |
| 278 | 279 | ||
| 279 | enum class NFCReadCommand : u8 { | 280 | enum class NFCCommand : u8 { |
| 280 | CancelAll = 0x00, | 281 | CancelAll = 0x00, |
| 281 | StartPolling = 0x01, | 282 | StartPolling = 0x01, |
| 282 | StopPolling = 0x02, | 283 | StopPolling = 0x02, |
| 283 | StartWaitingRecieve = 0x04, | 284 | StartWaitingRecieve = 0x04, |
| 284 | Ntag = 0x06, | 285 | ReadNtag = 0x06, |
| 286 | WriteNtag = 0x08, | ||
| 285 | Mifare = 0x0F, | 287 | Mifare = 0x0F, |
| 286 | }; | 288 | }; |
| 287 | 289 | ||
| @@ -292,14 +294,19 @@ enum class NFCTagType : u8 { | |||
| 292 | 294 | ||
| 293 | enum class NFCPages { | 295 | enum class NFCPages { |
| 294 | Block0 = 0, | 296 | Block0 = 0, |
| 297 | Block3 = 3, | ||
| 295 | Block45 = 45, | 298 | Block45 = 45, |
| 296 | Block135 = 135, | 299 | Block135 = 135, |
| 297 | Block231 = 231, | 300 | Block231 = 231, |
| 298 | }; | 301 | }; |
| 299 | 302 | ||
| 300 | enum class NFCStatus : u8 { | 303 | enum class NFCStatus : u8 { |
| 304 | Ready = 0x00, | ||
| 305 | Polling = 0x01, | ||
| 301 | LastPackage = 0x04, | 306 | LastPackage = 0x04, |
| 307 | WriteDone = 0x05, | ||
| 302 | TagLost = 0x07, | 308 | TagLost = 0x07, |
| 309 | WriteReady = 0x09, | ||
| 303 | }; | 310 | }; |
| 304 | 311 | ||
| 305 | enum class IrsMode : u8 { | 312 | enum class IrsMode : u8 { |
| @@ -559,13 +566,32 @@ static_assert(sizeof(NFCReadBlockCommand) == 0x9, "NFCReadBlockCommand is an inv | |||
| 559 | struct NFCReadCommandData { | 566 | struct NFCReadCommandData { |
| 560 | u8 unknown; | 567 | u8 unknown; |
| 561 | u8 uuid_length; | 568 | u8 uuid_length; |
| 562 | u8 unknown_2; | 569 | TagUUID uid; |
| 563 | std::array<u8, 6> uid; | ||
| 564 | NFCTagType tag_type; | 570 | NFCTagType tag_type; |
| 565 | NFCReadBlockCommand read_block; | 571 | NFCReadBlockCommand read_block; |
| 566 | }; | 572 | }; |
| 567 | static_assert(sizeof(NFCReadCommandData) == 0x13, "NFCReadCommandData is an invalid size"); | 573 | static_assert(sizeof(NFCReadCommandData) == 0x13, "NFCReadCommandData is an invalid size"); |
| 568 | 574 | ||
| 575 | #pragma pack(push, 1) | ||
| 576 | struct NFCWriteCommandData { | ||
| 577 | u8 unknown; | ||
| 578 | u8 uuid_length; | ||
| 579 | TagUUID uid; | ||
| 580 | NFCTagType tag_type; | ||
| 581 | u8 unknown2; | ||
| 582 | u8 unknown3; | ||
| 583 | u8 unknown4; | ||
| 584 | u8 unknown5; | ||
| 585 | u8 unknown6; | ||
| 586 | u8 unknown7; | ||
| 587 | u8 unknown8; | ||
| 588 | u8 magic; | ||
| 589 | u16_be write_count; | ||
| 590 | u8 amiibo_version; | ||
| 591 | }; | ||
| 592 | static_assert(sizeof(NFCWriteCommandData) == 0x15, "NFCWriteCommandData is an invalid size"); | ||
| 593 | #pragma pack(pop) | ||
| 594 | |||
| 569 | struct NFCPollingCommandData { | 595 | struct NFCPollingCommandData { |
| 570 | u8 enable_mifare; | 596 | u8 enable_mifare; |
| 571 | u8 unknown_1; | 597 | u8 unknown_1; |
| @@ -576,8 +602,8 @@ struct NFCPollingCommandData { | |||
| 576 | static_assert(sizeof(NFCPollingCommandData) == 0x05, "NFCPollingCommandData is an invalid size"); | 602 | static_assert(sizeof(NFCPollingCommandData) == 0x05, "NFCPollingCommandData is an invalid size"); |
| 577 | 603 | ||
| 578 | struct NFCRequestState { | 604 | struct NFCRequestState { |
| 579 | NFCReadCommand command_argument; | 605 | NFCCommand command_argument; |
| 580 | INSERT_PADDING_BYTES(0x1); | 606 | u8 block_id; |
| 581 | u8 packet_id; | 607 | u8 packet_id; |
| 582 | MCUPacketFlag packet_flag; | 608 | MCUPacketFlag packet_flag; |
| 583 | u8 data_length; | 609 | u8 data_length; |
| @@ -591,6 +617,18 @@ struct NFCRequestState { | |||
| 591 | }; | 617 | }; |
| 592 | static_assert(sizeof(NFCRequestState) == 0x26, "NFCRequestState is an invalid size"); | 618 | static_assert(sizeof(NFCRequestState) == 0x26, "NFCRequestState is an invalid size"); |
| 593 | 619 | ||
| 620 | struct NFCDataChunk { | ||
| 621 | u8 nfc_page; | ||
| 622 | u8 data_size; | ||
| 623 | std::array<u8, 0xFF> data; | ||
| 624 | }; | ||
| 625 | |||
| 626 | struct NFCWritePackage { | ||
| 627 | NFCWriteCommandData command_data; | ||
| 628 | u8 number_of_chunks; | ||
| 629 | std::array<NFCDataChunk, 4> data_chunks; | ||
| 630 | }; | ||
| 631 | |||
| 594 | struct IrsConfigure { | 632 | struct IrsConfigure { |
| 595 | MCUCommand command; | 633 | MCUCommand command; |
| 596 | MCUSubCommand sub_command; | 634 | MCUSubCommand sub_command; |
diff --git a/src/input_common/helpers/joycon_protocol/nfc.cpp b/src/input_common/helpers/joycon_protocol/nfc.cpp index 46c9e9489..f7058c4a7 100644 --- a/src/input_common/helpers/joycon_protocol/nfc.cpp +++ b/src/input_common/helpers/joycon_protocol/nfc.cpp | |||
| @@ -34,6 +34,12 @@ DriverResult NfcProtocol::EnableNfc() { | |||
| 34 | 34 | ||
| 35 | result = ConfigureMCU(config); | 35 | result = ConfigureMCU(config); |
| 36 | } | 36 | } |
| 37 | if (result == DriverResult::Success) { | ||
| 38 | result = WaitSetMCUMode(ReportMode::NFC_IR_MODE_60HZ, MCUMode::NFC); | ||
| 39 | } | ||
| 40 | if (result == DriverResult::Success) { | ||
| 41 | result = WaitUntilNfcIs(NFCStatus::Ready); | ||
| 42 | } | ||
| 37 | 43 | ||
| 38 | return result; | 44 | return result; |
| 39 | } | 45 | } |
| @@ -56,27 +62,20 @@ DriverResult NfcProtocol::StartNFCPollingMode() { | |||
| 56 | LOG_DEBUG(Input, "Start NFC pooling Mode"); | 62 | LOG_DEBUG(Input, "Start NFC pooling Mode"); |
| 57 | ScopedSetBlocking sb(this); | 63 | ScopedSetBlocking sb(this); |
| 58 | DriverResult result{DriverResult::Success}; | 64 | DriverResult result{DriverResult::Success}; |
| 59 | TagFoundData tag_data{}; | ||
| 60 | 65 | ||
| 61 | if (result == DriverResult::Success) { | 66 | if (result == DriverResult::Success) { |
| 62 | result = WaitSetMCUMode(ReportMode::NFC_IR_MODE_60HZ, MCUMode::NFC); | ||
| 63 | } | ||
| 64 | if (result == DriverResult::Success) { | ||
| 65 | result = WaitUntilNfcIsReady(); | ||
| 66 | } | ||
| 67 | if (result == DriverResult::Success) { | ||
| 68 | MCUCommandResponse output{}; | 67 | MCUCommandResponse output{}; |
| 69 | result = SendStopPollingRequest(output); | 68 | result = SendStopPollingRequest(output); |
| 70 | } | 69 | } |
| 71 | if (result == DriverResult::Success) { | 70 | if (result == DriverResult::Success) { |
| 72 | result = WaitUntilNfcIsReady(); | 71 | result = WaitUntilNfcIs(NFCStatus::Ready); |
| 73 | } | 72 | } |
| 74 | if (result == DriverResult::Success) { | 73 | if (result == DriverResult::Success) { |
| 75 | MCUCommandResponse output{}; | 74 | MCUCommandResponse output{}; |
| 76 | result = SendStartPollingRequest(output); | 75 | result = SendStartPollingRequest(output); |
| 77 | } | 76 | } |
| 78 | if (result == DriverResult::Success) { | 77 | if (result == DriverResult::Success) { |
| 79 | result = WaitUntilNfcIsPolling(); | 78 | result = WaitUntilNfcIs(NFCStatus::Polling); |
| 80 | } | 79 | } |
| 81 | if (result == DriverResult::Success) { | 80 | if (result == DriverResult::Success) { |
| 82 | is_enabled = true; | 81 | is_enabled = true; |
| @@ -112,6 +111,49 @@ DriverResult NfcProtocol::ScanAmiibo(std::vector<u8>& data) { | |||
| 112 | return result; | 111 | return result; |
| 113 | } | 112 | } |
| 114 | 113 | ||
| 114 | DriverResult NfcProtocol::WriteAmiibo(std::span<const u8> data) { | ||
| 115 | LOG_DEBUG(Input, "Write amiibo"); | ||
| 116 | ScopedSetBlocking sb(this); | ||
| 117 | DriverResult result{DriverResult::Success}; | ||
| 118 | TagUUID tag_uuid = GetTagUUID(data); | ||
| 119 | TagFoundData tag_data{}; | ||
| 120 | |||
| 121 | if (result == DriverResult::Success) { | ||
| 122 | result = IsTagInRange(tag_data, 7); | ||
| 123 | } | ||
| 124 | if (result == DriverResult::Success) { | ||
| 125 | if (tag_data.uuid != tag_uuid) { | ||
| 126 | result = DriverResult::InvalidParameters; | ||
| 127 | } | ||
| 128 | } | ||
| 129 | if (result == DriverResult::Success) { | ||
| 130 | MCUCommandResponse output{}; | ||
| 131 | result = SendStopPollingRequest(output); | ||
| 132 | } | ||
| 133 | if (result == DriverResult::Success) { | ||
| 134 | result = WaitUntilNfcIs(NFCStatus::Ready); | ||
| 135 | } | ||
| 136 | if (result == DriverResult::Success) { | ||
| 137 | MCUCommandResponse output{}; | ||
| 138 | result = SendStartPollingRequest(output, true); | ||
| 139 | } | ||
| 140 | if (result == DriverResult::Success) { | ||
| 141 | result = WaitUntilNfcIs(NFCStatus::WriteReady); | ||
| 142 | } | ||
| 143 | if (result == DriverResult::Success) { | ||
| 144 | result = WriteAmiiboData(tag_uuid, data); | ||
| 145 | } | ||
| 146 | if (result == DriverResult::Success) { | ||
| 147 | result = WaitUntilNfcIs(NFCStatus::WriteDone); | ||
| 148 | } | ||
| 149 | if (result == DriverResult::Success) { | ||
| 150 | MCUCommandResponse output{}; | ||
| 151 | result = SendStopPollingRequest(output); | ||
| 152 | } | ||
| 153 | |||
| 154 | return result; | ||
| 155 | } | ||
| 156 | |||
| 115 | bool NfcProtocol::HasAmiibo() { | 157 | bool NfcProtocol::HasAmiibo() { |
| 116 | if (update_counter++ < AMIIBO_UPDATE_DELAY) { | 158 | if (update_counter++ < AMIIBO_UPDATE_DELAY) { |
| 117 | return true; | 159 | return true; |
| @@ -129,7 +171,7 @@ bool NfcProtocol::HasAmiibo() { | |||
| 129 | return result == DriverResult::Success; | 171 | return result == DriverResult::Success; |
| 130 | } | 172 | } |
| 131 | 173 | ||
| 132 | DriverResult NfcProtocol::WaitUntilNfcIsReady() { | 174 | DriverResult NfcProtocol::WaitUntilNfcIs(NFCStatus status) { |
| 133 | constexpr std::size_t timeout_limit = 10; | 175 | constexpr std::size_t timeout_limit = 10; |
| 134 | MCUCommandResponse output{}; | 176 | MCUCommandResponse output{}; |
| 135 | std::size_t tries = 0; | 177 | std::size_t tries = 0; |
| @@ -145,28 +187,7 @@ DriverResult NfcProtocol::WaitUntilNfcIsReady() { | |||
| 145 | } | 187 | } |
| 146 | } while (output.mcu_report != MCUReport::NFCState || | 188 | } while (output.mcu_report != MCUReport::NFCState || |
| 147 | (output.mcu_data[1] << 8) + output.mcu_data[0] != 0x0500 || | 189 | (output.mcu_data[1] << 8) + output.mcu_data[0] != 0x0500 || |
| 148 | output.mcu_data[5] != 0x31 || output.mcu_data[6] != 0x00); | 190 | output.mcu_data[5] != 0x31 || output.mcu_data[6] != static_cast<u8>(status)); |
| 149 | |||
| 150 | return DriverResult::Success; | ||
| 151 | } | ||
| 152 | |||
| 153 | DriverResult NfcProtocol::WaitUntilNfcIsPolling() { | ||
| 154 | constexpr std::size_t timeout_limit = 10; | ||
| 155 | MCUCommandResponse output{}; | ||
| 156 | std::size_t tries = 0; | ||
| 157 | |||
| 158 | do { | ||
| 159 | auto result = SendNextPackageRequest(output, {}); | ||
| 160 | |||
| 161 | if (result != DriverResult::Success) { | ||
| 162 | return result; | ||
| 163 | } | ||
| 164 | if (tries++ > timeout_limit) { | ||
| 165 | return DriverResult::Timeout; | ||
| 166 | } | ||
| 167 | } while (output.mcu_report != MCUReport::NFCState || | ||
| 168 | (output.mcu_data[1] << 8) + output.mcu_data[0] != 0x0500 || | ||
| 169 | output.mcu_data[5] != 0x31 || output.mcu_data[6] != 0x01); | ||
| 170 | 191 | ||
| 171 | return DriverResult::Success; | 192 | return DriverResult::Success; |
| 172 | } | 193 | } |
| @@ -188,7 +209,7 @@ DriverResult NfcProtocol::IsTagInRange(TagFoundData& data, std::size_t timeout_l | |||
| 188 | (output.mcu_data[6] != 0x09 && output.mcu_data[6] != 0x04)); | 209 | (output.mcu_data[6] != 0x09 && output.mcu_data[6] != 0x04)); |
| 189 | 210 | ||
| 190 | data.type = output.mcu_data[12]; | 211 | data.type = output.mcu_data[12]; |
| 191 | data.uuid.resize(output.mcu_data[14]); | 212 | data.uuid_size = std::min(output.mcu_data[14], static_cast<u8>(sizeof(TagUUID))); |
| 192 | memcpy(data.uuid.data(), output.mcu_data.data() + 15, data.uuid.size()); | 213 | memcpy(data.uuid.data(), output.mcu_data.data() + 15, data.uuid.size()); |
| 193 | 214 | ||
| 194 | return DriverResult::Success; | 215 | return DriverResult::Success; |
| @@ -245,17 +266,94 @@ DriverResult NfcProtocol::GetAmiiboData(std::vector<u8>& ntag_data) { | |||
| 245 | return DriverResult::Timeout; | 266 | return DriverResult::Timeout; |
| 246 | } | 267 | } |
| 247 | 268 | ||
| 248 | DriverResult NfcProtocol::SendStartPollingRequest(MCUCommandResponse& output) { | 269 | DriverResult NfcProtocol::WriteAmiiboData(const TagUUID& tag_uuid, std::span<const u8> data) { |
| 270 | constexpr std::size_t timeout_limit = 60; | ||
| 271 | const auto nfc_data = MakeAmiiboWritePackage(tag_uuid, data); | ||
| 272 | const std::vector<u8> nfc_buffer_data = SerializeWritePackage(nfc_data); | ||
| 273 | std::span<const u8> buffer(nfc_buffer_data); | ||
| 274 | MCUCommandResponse output{}; | ||
| 275 | u8 block_id = 1; | ||
| 276 | u8 package_index = 0; | ||
| 277 | std::size_t tries = 0; | ||
| 278 | std::size_t current_position = 0; | ||
| 279 | |||
| 280 | LOG_INFO(Input, "Writing amiibo data"); | ||
| 281 | |||
| 282 | auto result = SendWriteAmiiboRequest(output, tag_uuid); | ||
| 283 | |||
| 284 | if (result != DriverResult::Success) { | ||
| 285 | return result; | ||
| 286 | } | ||
| 287 | |||
| 288 | // Read Tag data but ignore the actual sent data | ||
| 289 | while (tries++ < timeout_limit) { | ||
| 290 | result = SendNextPackageRequest(output, package_index); | ||
| 291 | const auto nfc_status = static_cast<NFCStatus>(output.mcu_data[6]); | ||
| 292 | |||
| 293 | if (result != DriverResult::Success) { | ||
| 294 | return result; | ||
| 295 | } | ||
| 296 | |||
| 297 | if ((output.mcu_report == MCUReport::NFCReadData || | ||
| 298 | output.mcu_report == MCUReport::NFCState) && | ||
| 299 | nfc_status == NFCStatus::TagLost) { | ||
| 300 | return DriverResult::ErrorReadingData; | ||
| 301 | } | ||
| 302 | |||
| 303 | if (output.mcu_report == MCUReport::NFCReadData && output.mcu_data[1] == 0x07) { | ||
| 304 | package_index++; | ||
| 305 | continue; | ||
| 306 | } | ||
| 307 | |||
| 308 | if (output.mcu_report == MCUReport::NFCState && nfc_status == NFCStatus::LastPackage) { | ||
| 309 | LOG_INFO(Input, "Finished reading amiibo"); | ||
| 310 | break; | ||
| 311 | } | ||
| 312 | } | ||
| 313 | |||
| 314 | // Send Data. Nfc buffer size is 31, Send the data in smaller packages | ||
| 315 | while (current_position < buffer.size() && tries++ < timeout_limit) { | ||
| 316 | const std::size_t next_position = | ||
| 317 | std::min(current_position + sizeof(NFCRequestState::raw_data), buffer.size()); | ||
| 318 | const std::size_t block_size = next_position - current_position; | ||
| 319 | const bool is_last_packet = block_size < sizeof(NFCRequestState::raw_data); | ||
| 320 | |||
| 321 | SendWriteDataAmiiboRequest(output, block_id, is_last_packet, | ||
| 322 | buffer.subspan(current_position, block_size)); | ||
| 323 | |||
| 324 | const auto nfc_status = static_cast<NFCStatus>(output.mcu_data[6]); | ||
| 325 | |||
| 326 | if ((output.mcu_report == MCUReport::NFCReadData || | ||
| 327 | output.mcu_report == MCUReport::NFCState) && | ||
| 328 | nfc_status == NFCStatus::TagLost) { | ||
| 329 | return DriverResult::ErrorReadingData; | ||
| 330 | } | ||
| 331 | |||
| 332 | // Increase position when data is confirmed by the joycon | ||
| 333 | if (output.mcu_report == MCUReport::NFCState && | ||
| 334 | (output.mcu_data[1] << 8) + output.mcu_data[0] == 0x0500 && | ||
| 335 | output.mcu_data[3] == block_id) { | ||
| 336 | block_id++; | ||
| 337 | current_position = next_position; | ||
| 338 | } | ||
| 339 | } | ||
| 340 | |||
| 341 | return result; | ||
| 342 | } | ||
| 343 | |||
| 344 | DriverResult NfcProtocol::SendStartPollingRequest(MCUCommandResponse& output, | ||
| 345 | bool is_second_attempt) { | ||
| 249 | NFCRequestState request{ | 346 | NFCRequestState request{ |
| 250 | .command_argument = NFCReadCommand::StartPolling, | 347 | .command_argument = NFCCommand::StartPolling, |
| 251 | .packet_id = 0x0, | 348 | .block_id = {}, |
| 349 | .packet_id = {}, | ||
| 252 | .packet_flag = MCUPacketFlag::LastCommandPacket, | 350 | .packet_flag = MCUPacketFlag::LastCommandPacket, |
| 253 | .data_length = sizeof(NFCPollingCommandData), | 351 | .data_length = sizeof(NFCPollingCommandData), |
| 254 | .nfc_polling = | 352 | .nfc_polling = |
| 255 | { | 353 | { |
| 256 | .enable_mifare = 0x01, | 354 | .enable_mifare = 0x00, |
| 257 | .unknown_1 = 0x00, | 355 | .unknown_1 = static_cast<u8>(is_second_attempt ? 0xe8 : 0x00), |
| 258 | .unknown_2 = 0x00, | 356 | .unknown_2 = static_cast<u8>(is_second_attempt ? 0x03 : 0x00), |
| 259 | .unknown_3 = 0x2c, | 357 | .unknown_3 = 0x2c, |
| 260 | .unknown_4 = 0x01, | 358 | .unknown_4 = 0x01, |
| 261 | }, | 359 | }, |
| @@ -271,10 +369,11 @@ DriverResult NfcProtocol::SendStartPollingRequest(MCUCommandResponse& output) { | |||
| 271 | 369 | ||
| 272 | DriverResult NfcProtocol::SendStopPollingRequest(MCUCommandResponse& output) { | 370 | DriverResult NfcProtocol::SendStopPollingRequest(MCUCommandResponse& output) { |
| 273 | NFCRequestState request{ | 371 | NFCRequestState request{ |
| 274 | .command_argument = NFCReadCommand::StopPolling, | 372 | .command_argument = NFCCommand::StopPolling, |
| 275 | .packet_id = 0x0, | 373 | .block_id = {}, |
| 374 | .packet_id = {}, | ||
| 276 | .packet_flag = MCUPacketFlag::LastCommandPacket, | 375 | .packet_flag = MCUPacketFlag::LastCommandPacket, |
| 277 | .data_length = 0, | 376 | .data_length = {}, |
| 278 | .raw_data = {}, | 377 | .raw_data = {}, |
| 279 | .crc = {}, | 378 | .crc = {}, |
| 280 | }; | 379 | }; |
| @@ -288,10 +387,11 @@ DriverResult NfcProtocol::SendStopPollingRequest(MCUCommandResponse& output) { | |||
| 288 | 387 | ||
| 289 | DriverResult NfcProtocol::SendNextPackageRequest(MCUCommandResponse& output, u8 packet_id) { | 388 | DriverResult NfcProtocol::SendNextPackageRequest(MCUCommandResponse& output, u8 packet_id) { |
| 290 | NFCRequestState request{ | 389 | NFCRequestState request{ |
| 291 | .command_argument = NFCReadCommand::StartWaitingRecieve, | 390 | .command_argument = NFCCommand::StartWaitingRecieve, |
| 391 | .block_id = {}, | ||
| 292 | .packet_id = packet_id, | 392 | .packet_id = packet_id, |
| 293 | .packet_flag = MCUPacketFlag::LastCommandPacket, | 393 | .packet_flag = MCUPacketFlag::LastCommandPacket, |
| 294 | .data_length = 0, | 394 | .data_length = {}, |
| 295 | .raw_data = {}, | 395 | .raw_data = {}, |
| 296 | .crc = {}, | 396 | .crc = {}, |
| 297 | }; | 397 | }; |
| @@ -305,17 +405,17 @@ DriverResult NfcProtocol::SendNextPackageRequest(MCUCommandResponse& output, u8 | |||
| 305 | 405 | ||
| 306 | DriverResult NfcProtocol::SendReadAmiiboRequest(MCUCommandResponse& output, NFCPages ntag_pages) { | 406 | DriverResult NfcProtocol::SendReadAmiiboRequest(MCUCommandResponse& output, NFCPages ntag_pages) { |
| 307 | NFCRequestState request{ | 407 | NFCRequestState request{ |
| 308 | .command_argument = NFCReadCommand::Ntag, | 408 | .command_argument = NFCCommand::ReadNtag, |
| 309 | .packet_id = 0x0, | 409 | .block_id = {}, |
| 410 | .packet_id = {}, | ||
| 310 | .packet_flag = MCUPacketFlag::LastCommandPacket, | 411 | .packet_flag = MCUPacketFlag::LastCommandPacket, |
| 311 | .data_length = sizeof(NFCReadCommandData), | 412 | .data_length = sizeof(NFCReadCommandData), |
| 312 | .nfc_read = | 413 | .nfc_read = |
| 313 | { | 414 | { |
| 314 | .unknown = 0xd0, | 415 | .unknown = 0xd0, |
| 315 | .uuid_length = 0x07, | 416 | .uuid_length = sizeof(NFCReadCommandData::uid), |
| 316 | .unknown_2 = 0x00, | ||
| 317 | .uid = {}, | 417 | .uid = {}, |
| 318 | .tag_type = NFCTagType::AllTags, | 418 | .tag_type = NFCTagType::Ntag215, |
| 319 | .read_block = GetReadBlockCommand(ntag_pages), | 419 | .read_block = GetReadBlockCommand(ntag_pages), |
| 320 | }, | 420 | }, |
| 321 | .crc = {}, | 421 | .crc = {}, |
| @@ -328,12 +428,135 @@ DriverResult NfcProtocol::SendReadAmiiboRequest(MCUCommandResponse& output, NFCP | |||
| 328 | output); | 428 | output); |
| 329 | } | 429 | } |
| 330 | 430 | ||
| 431 | DriverResult NfcProtocol::SendWriteAmiiboRequest(MCUCommandResponse& output, | ||
| 432 | const TagUUID& tag_uuid) { | ||
| 433 | NFCRequestState request{ | ||
| 434 | .command_argument = NFCCommand::ReadNtag, | ||
| 435 | .block_id = {}, | ||
| 436 | .packet_id = {}, | ||
| 437 | .packet_flag = MCUPacketFlag::LastCommandPacket, | ||
| 438 | .data_length = sizeof(NFCReadCommandData), | ||
| 439 | .nfc_read = | ||
| 440 | { | ||
| 441 | .unknown = 0xd0, | ||
| 442 | .uuid_length = sizeof(NFCReadCommandData::uid), | ||
| 443 | .uid = tag_uuid, | ||
| 444 | .tag_type = NFCTagType::Ntag215, | ||
| 445 | .read_block = GetReadBlockCommand(NFCPages::Block3), | ||
| 446 | }, | ||
| 447 | .crc = {}, | ||
| 448 | }; | ||
| 449 | |||
| 450 | std::array<u8, sizeof(NFCRequestState)> request_data{}; | ||
| 451 | memcpy(request_data.data(), &request, sizeof(NFCRequestState)); | ||
| 452 | request_data[36] = CalculateMCU_CRC8(request_data.data(), 36); | ||
| 453 | return SendMCUData(ReportMode::NFC_IR_MODE_60HZ, MCUSubCommand::ReadDeviceMode, request_data, | ||
| 454 | output); | ||
| 455 | } | ||
| 456 | |||
| 457 | DriverResult NfcProtocol::SendWriteDataAmiiboRequest(MCUCommandResponse& output, u8 block_id, | ||
| 458 | bool is_last_packet, | ||
| 459 | std::span<const u8> data) { | ||
| 460 | const auto data_size = std::min(data.size(), sizeof(NFCRequestState::raw_data)); | ||
| 461 | NFCRequestState request{ | ||
| 462 | .command_argument = NFCCommand::WriteNtag, | ||
| 463 | .block_id = block_id, | ||
| 464 | .packet_id = {}, | ||
| 465 | .packet_flag = | ||
| 466 | is_last_packet ? MCUPacketFlag::LastCommandPacket : MCUPacketFlag::MorePacketsRemaining, | ||
| 467 | .data_length = static_cast<u8>(data_size), | ||
| 468 | .raw_data = {}, | ||
| 469 | .crc = {}, | ||
| 470 | }; | ||
| 471 | memcpy(request.raw_data.data(), data.data(), data_size); | ||
| 472 | |||
| 473 | std::array<u8, sizeof(NFCRequestState)> request_data{}; | ||
| 474 | memcpy(request_data.data(), &request, sizeof(NFCRequestState)); | ||
| 475 | request_data[36] = CalculateMCU_CRC8(request_data.data(), 36); | ||
| 476 | return SendMCUData(ReportMode::NFC_IR_MODE_60HZ, MCUSubCommand::ReadDeviceMode, request_data, | ||
| 477 | output); | ||
| 478 | } | ||
| 479 | |||
| 480 | std::vector<u8> NfcProtocol::SerializeWritePackage(const NFCWritePackage& package) const { | ||
| 481 | const std::size_t header_size = | ||
| 482 | sizeof(NFCWriteCommandData) + sizeof(NFCWritePackage::number_of_chunks); | ||
| 483 | std::vector<u8> serialized_data(header_size); | ||
| 484 | std::size_t start_index = 0; | ||
| 485 | |||
| 486 | memcpy(serialized_data.data(), &package, header_size); | ||
| 487 | start_index += header_size; | ||
| 488 | |||
| 489 | for (const auto& data_chunk : package.data_chunks) { | ||
| 490 | const std::size_t chunk_size = | ||
| 491 | sizeof(NFCDataChunk::nfc_page) + sizeof(NFCDataChunk::data_size) + data_chunk.data_size; | ||
| 492 | |||
| 493 | serialized_data.resize(start_index + chunk_size); | ||
| 494 | memcpy(serialized_data.data() + start_index, &data_chunk, chunk_size); | ||
| 495 | start_index += chunk_size; | ||
| 496 | } | ||
| 497 | |||
| 498 | return serialized_data; | ||
| 499 | } | ||
| 500 | |||
| 501 | NFCWritePackage NfcProtocol::MakeAmiiboWritePackage(const TagUUID& tag_uuid, | ||
| 502 | std::span<const u8> data) const { | ||
| 503 | return { | ||
| 504 | .command_data{ | ||
| 505 | .unknown = 0xd0, | ||
| 506 | .uuid_length = sizeof(NFCReadCommandData::uid), | ||
| 507 | .uid = tag_uuid, | ||
| 508 | .tag_type = NFCTagType::Ntag215, | ||
| 509 | .unknown2 = 0x00, | ||
| 510 | .unknown3 = 0x01, | ||
| 511 | .unknown4 = 0x04, | ||
| 512 | .unknown5 = 0xff, | ||
| 513 | .unknown6 = 0xff, | ||
| 514 | .unknown7 = 0xff, | ||
| 515 | .unknown8 = 0xff, | ||
| 516 | .magic = data[16], | ||
| 517 | .write_count = static_cast<u16>((data[17] << 8) + data[18]), | ||
| 518 | .amiibo_version = data[19], | ||
| 519 | }, | ||
| 520 | .number_of_chunks = 3, | ||
| 521 | .data_chunks = | ||
| 522 | { | ||
| 523 | MakeAmiiboChunk(0x05, 0x20, data), | ||
| 524 | MakeAmiiboChunk(0x20, 0xf0, data), | ||
| 525 | MakeAmiiboChunk(0x5c, 0x98, data), | ||
| 526 | }, | ||
| 527 | }; | ||
| 528 | } | ||
| 529 | |||
| 530 | NFCDataChunk NfcProtocol::MakeAmiiboChunk(u8 page, u8 size, std::span<const u8> data) const { | ||
| 531 | constexpr u8 NFC_PAGE_SIZE = 4; | ||
| 532 | |||
| 533 | if (static_cast<std::size_t>(page * NFC_PAGE_SIZE) + size >= data.size()) { | ||
| 534 | return {}; | ||
| 535 | } | ||
| 536 | |||
| 537 | NFCDataChunk chunk{ | ||
| 538 | .nfc_page = page, | ||
| 539 | .data_size = size, | ||
| 540 | .data = {}, | ||
| 541 | }; | ||
| 542 | std::memcpy(chunk.data.data(), data.data() + (page * NFC_PAGE_SIZE), size); | ||
| 543 | return chunk; | ||
| 544 | } | ||
| 545 | |||
| 331 | NFCReadBlockCommand NfcProtocol::GetReadBlockCommand(NFCPages pages) const { | 546 | NFCReadBlockCommand NfcProtocol::GetReadBlockCommand(NFCPages pages) const { |
| 332 | switch (pages) { | 547 | switch (pages) { |
| 333 | case NFCPages::Block0: | 548 | case NFCPages::Block0: |
| 334 | return { | 549 | return { |
| 335 | .block_count = 1, | 550 | .block_count = 1, |
| 336 | }; | 551 | }; |
| 552 | case NFCPages::Block3: | ||
| 553 | return { | ||
| 554 | .block_count = 1, | ||
| 555 | .blocks = | ||
| 556 | { | ||
| 557 | NFCReadBlock{0x03, 0x03}, | ||
| 558 | }, | ||
| 559 | }; | ||
| 337 | case NFCPages::Block45: | 560 | case NFCPages::Block45: |
| 338 | return { | 561 | return { |
| 339 | .block_count = 1, | 562 | .block_count = 1, |
| @@ -368,6 +591,17 @@ NFCReadBlockCommand NfcProtocol::GetReadBlockCommand(NFCPages pages) const { | |||
| 368 | }; | 591 | }; |
| 369 | } | 592 | } |
| 370 | 593 | ||
| 594 | TagUUID NfcProtocol::GetTagUUID(std::span<const u8> data) const { | ||
| 595 | if (data.size() < 10) { | ||
| 596 | return {}; | ||
| 597 | } | ||
| 598 | |||
| 599 | // crc byte 3 is omitted in this operation | ||
| 600 | return { | ||
| 601 | data[0], data[1], data[2], data[4], data[5], data[6], data[7], | ||
| 602 | }; | ||
| 603 | } | ||
| 604 | |||
| 371 | bool NfcProtocol::IsEnabled() const { | 605 | bool NfcProtocol::IsEnabled() const { |
| 372 | return is_enabled; | 606 | return is_enabled; |
| 373 | } | 607 | } |
diff --git a/src/input_common/helpers/joycon_protocol/nfc.h b/src/input_common/helpers/joycon_protocol/nfc.h index c9e9af03f..eb58c427d 100644 --- a/src/input_common/helpers/joycon_protocol/nfc.h +++ b/src/input_common/helpers/joycon_protocol/nfc.h | |||
| @@ -27,6 +27,8 @@ public: | |||
| 27 | 27 | ||
| 28 | DriverResult ScanAmiibo(std::vector<u8>& data); | 28 | DriverResult ScanAmiibo(std::vector<u8>& data); |
| 29 | 29 | ||
| 30 | DriverResult WriteAmiibo(std::span<const u8> data); | ||
| 31 | |||
| 30 | bool HasAmiibo(); | 32 | bool HasAmiibo(); |
| 31 | 33 | ||
| 32 | bool IsEnabled() const; | 34 | bool IsEnabled() const; |
| @@ -37,18 +39,20 @@ private: | |||
| 37 | 39 | ||
| 38 | struct TagFoundData { | 40 | struct TagFoundData { |
| 39 | u8 type; | 41 | u8 type; |
| 40 | std::vector<u8> uuid; | 42 | u8 uuid_size; |
| 43 | TagUUID uuid; | ||
| 41 | }; | 44 | }; |
| 42 | 45 | ||
| 43 | DriverResult WaitUntilNfcIsReady(); | 46 | DriverResult WaitUntilNfcIs(NFCStatus status); |
| 44 | |||
| 45 | DriverResult WaitUntilNfcIsPolling(); | ||
| 46 | 47 | ||
| 47 | DriverResult IsTagInRange(TagFoundData& data, std::size_t timeout_limit = 1); | 48 | DriverResult IsTagInRange(TagFoundData& data, std::size_t timeout_limit = 1); |
| 48 | 49 | ||
| 49 | DriverResult GetAmiiboData(std::vector<u8>& data); | 50 | DriverResult GetAmiiboData(std::vector<u8>& data); |
| 50 | 51 | ||
| 51 | DriverResult SendStartPollingRequest(MCUCommandResponse& output); | 52 | DriverResult WriteAmiiboData(const TagUUID& tag_uuid, std::span<const u8> data); |
| 53 | |||
| 54 | DriverResult SendStartPollingRequest(MCUCommandResponse& output, | ||
| 55 | bool is_second_attempt = false); | ||
| 52 | 56 | ||
| 53 | DriverResult SendStopPollingRequest(MCUCommandResponse& output); | 57 | DriverResult SendStopPollingRequest(MCUCommandResponse& output); |
| 54 | 58 | ||
| @@ -56,8 +60,21 @@ private: | |||
| 56 | 60 | ||
| 57 | DriverResult SendReadAmiiboRequest(MCUCommandResponse& output, NFCPages ntag_pages); | 61 | DriverResult SendReadAmiiboRequest(MCUCommandResponse& output, NFCPages ntag_pages); |
| 58 | 62 | ||
| 63 | DriverResult SendWriteAmiiboRequest(MCUCommandResponse& output, const TagUUID& tag_uuid); | ||
| 64 | |||
| 65 | DriverResult SendWriteDataAmiiboRequest(MCUCommandResponse& output, u8 block_id, | ||
| 66 | bool is_last_packet, std::span<const u8> data); | ||
| 67 | |||
| 68 | std::vector<u8> SerializeWritePackage(const NFCWritePackage& package) const; | ||
| 69 | |||
| 70 | NFCWritePackage MakeAmiiboWritePackage(const TagUUID& tag_uuid, std::span<const u8> data) const; | ||
| 71 | |||
| 72 | NFCDataChunk MakeAmiiboChunk(u8 page, u8 size, std::span<const u8> data) const; | ||
| 73 | |||
| 59 | NFCReadBlockCommand GetReadBlockCommand(NFCPages pages) const; | 74 | NFCReadBlockCommand GetReadBlockCommand(NFCPages pages) const; |
| 60 | 75 | ||
| 76 | TagUUID GetTagUUID(std::span<const u8> data) const; | ||
| 77 | |||
| 61 | bool is_enabled{}; | 78 | bool is_enabled{}; |
| 62 | std::size_t update_counter{}; | 79 | std::size_t update_counter{}; |
| 63 | }; | 80 | }; |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/integer_funnel_shift.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/integer_funnel_shift.cpp index 442365a26..c2a0ee6f1 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/integer_funnel_shift.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/integer_funnel_shift.cpp | |||
| @@ -30,7 +30,7 @@ void SHF(TranslatorVisitor& v, u64 insn, const IR::U32& shift, const IR::U32& hi | |||
| 30 | union { | 30 | union { |
| 31 | u64 insn; | 31 | u64 insn; |
| 32 | BitField<0, 8, IR::Reg> dest_reg; | 32 | BitField<0, 8, IR::Reg> dest_reg; |
| 33 | BitField<0, 8, IR::Reg> lo_bits_reg; | 33 | BitField<8, 8, IR::Reg> lo_bits_reg; |
| 34 | BitField<37, 2, MaxShift> max_shift; | 34 | BitField<37, 2, MaxShift> max_shift; |
| 35 | BitField<47, 1, u64> cc; | 35 | BitField<47, 1, u64> cc; |
| 36 | BitField<48, 2, u64> x_mode; | 36 | BitField<48, 2, u64> x_mode; |
diff --git a/src/video_core/buffer_cache/buffer_cache.cpp b/src/video_core/buffer_cache/buffer_cache.cpp index 40db243d2..4b4f7061b 100644 --- a/src/video_core/buffer_cache/buffer_cache.cpp +++ b/src/video_core/buffer_cache/buffer_cache.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | 2 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | 3 | ||
| 4 | #include "common/microprofile.h" | 4 | #include "common/microprofile.h" |
| 5 | #include "video_core/buffer_cache/buffer_cache_base.h" | ||
| 6 | #include "video_core/control/channel_state_cache.inc" | ||
| 5 | 7 | ||
| 6 | namespace VideoCommon { | 8 | namespace VideoCommon { |
| 7 | 9 | ||
| @@ -9,4 +11,6 @@ MICROPROFILE_DEFINE(GPU_PrepareBuffers, "GPU", "Prepare buffers", MP_RGB(224, 12 | |||
| 9 | MICROPROFILE_DEFINE(GPU_BindUploadBuffers, "GPU", "Bind and upload buffers", MP_RGB(224, 128, 128)); | 11 | MICROPROFILE_DEFINE(GPU_BindUploadBuffers, "GPU", "Bind and upload buffers", MP_RGB(224, 128, 128)); |
| 10 | MICROPROFILE_DEFINE(GPU_DownloadMemory, "GPU", "Download buffers", MP_RGB(224, 128, 128)); | 12 | MICROPROFILE_DEFINE(GPU_DownloadMemory, "GPU", "Download buffers", MP_RGB(224, 128, 128)); |
| 11 | 13 | ||
| 14 | template class VideoCommon::ChannelSetupCaches<VideoCommon::BufferCacheChannelInfo>; | ||
| 15 | |||
| 12 | } // namespace VideoCommon | 16 | } // namespace VideoCommon |
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 88d3b2515..f1ad5f7cb 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h | |||
| @@ -63,18 +63,27 @@ void BufferCache<P>::RunGarbageCollector() { | |||
| 63 | 63 | ||
| 64 | template <class P> | 64 | template <class P> |
| 65 | void BufferCache<P>::TickFrame() { | 65 | void BufferCache<P>::TickFrame() { |
| 66 | // Homebrew console apps don't create or bind any channels, so this will be nullptr. | ||
| 67 | if (!channel_state) { | ||
| 68 | return; | ||
| 69 | } | ||
| 70 | |||
| 66 | // Calculate hits and shots and move hit bits to the right | 71 | // Calculate hits and shots and move hit bits to the right |
| 67 | const u32 hits = std::reduce(uniform_cache_hits.begin(), uniform_cache_hits.end()); | 72 | const u32 hits = std::reduce(channel_state->uniform_cache_hits.begin(), |
| 68 | const u32 shots = std::reduce(uniform_cache_shots.begin(), uniform_cache_shots.end()); | 73 | channel_state->uniform_cache_hits.end()); |
| 69 | std::copy_n(uniform_cache_hits.begin(), uniform_cache_hits.size() - 1, | 74 | const u32 shots = std::reduce(channel_state->uniform_cache_shots.begin(), |
| 70 | uniform_cache_hits.begin() + 1); | 75 | channel_state->uniform_cache_shots.end()); |
| 71 | std::copy_n(uniform_cache_shots.begin(), uniform_cache_shots.size() - 1, | 76 | std::copy_n(channel_state->uniform_cache_hits.begin(), |
| 72 | uniform_cache_shots.begin() + 1); | 77 | channel_state->uniform_cache_hits.size() - 1, |
| 73 | uniform_cache_hits[0] = 0; | 78 | channel_state->uniform_cache_hits.begin() + 1); |
| 74 | uniform_cache_shots[0] = 0; | 79 | std::copy_n(channel_state->uniform_cache_shots.begin(), |
| 80 | channel_state->uniform_cache_shots.size() - 1, | ||
| 81 | channel_state->uniform_cache_shots.begin() + 1); | ||
| 82 | channel_state->uniform_cache_hits[0] = 0; | ||
| 83 | channel_state->uniform_cache_shots[0] = 0; | ||
| 75 | 84 | ||
| 76 | const bool skip_preferred = hits * 256 < shots * 251; | 85 | const bool skip_preferred = hits * 256 < shots * 251; |
| 77 | uniform_buffer_skip_cache_size = skip_preferred ? DEFAULT_SKIP_CACHE_SIZE : 0; | 86 | channel_state->uniform_buffer_skip_cache_size = skip_preferred ? DEFAULT_SKIP_CACHE_SIZE : 0; |
| 78 | 87 | ||
| 79 | // If we can obtain the memory info, use it instead of the estimate. | 88 | // If we can obtain the memory info, use it instead of the estimate. |
| 80 | if (runtime.CanReportMemoryUsage()) { | 89 | if (runtime.CanReportMemoryUsage()) { |
| @@ -164,10 +173,10 @@ bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 am | |||
| 164 | BufferId buffer_a; | 173 | BufferId buffer_a; |
| 165 | BufferId buffer_b; | 174 | BufferId buffer_b; |
| 166 | do { | 175 | do { |
| 167 | has_deleted_buffers = false; | 176 | channel_state->has_deleted_buffers = false; |
| 168 | buffer_a = FindBuffer(*cpu_src_address, static_cast<u32>(amount)); | 177 | buffer_a = FindBuffer(*cpu_src_address, static_cast<u32>(amount)); |
| 169 | buffer_b = FindBuffer(*cpu_dest_address, static_cast<u32>(amount)); | 178 | buffer_b = FindBuffer(*cpu_dest_address, static_cast<u32>(amount)); |
| 170 | } while (has_deleted_buffers); | 179 | } while (channel_state->has_deleted_buffers); |
| 171 | auto& src_buffer = slot_buffers[buffer_a]; | 180 | auto& src_buffer = slot_buffers[buffer_a]; |
| 172 | auto& dest_buffer = slot_buffers[buffer_b]; | 181 | auto& dest_buffer = slot_buffers[buffer_b]; |
| 173 | SynchronizeBuffer(src_buffer, *cpu_src_address, static_cast<u32>(amount)); | 182 | SynchronizeBuffer(src_buffer, *cpu_src_address, static_cast<u32>(amount)); |
| @@ -272,30 +281,30 @@ void BufferCache<P>::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr | |||
| 272 | .size = size, | 281 | .size = size, |
| 273 | .buffer_id = BufferId{}, | 282 | .buffer_id = BufferId{}, |
| 274 | }; | 283 | }; |
| 275 | uniform_buffers[stage][index] = binding; | 284 | channel_state->uniform_buffers[stage][index] = binding; |
| 276 | } | 285 | } |
| 277 | 286 | ||
| 278 | template <class P> | 287 | template <class P> |
| 279 | void BufferCache<P>::DisableGraphicsUniformBuffer(size_t stage, u32 index) { | 288 | void BufferCache<P>::DisableGraphicsUniformBuffer(size_t stage, u32 index) { |
| 280 | uniform_buffers[stage][index] = NULL_BINDING; | 289 | channel_state->uniform_buffers[stage][index] = NULL_BINDING; |
| 281 | } | 290 | } |
| 282 | 291 | ||
| 283 | template <class P> | 292 | template <class P> |
| 284 | void BufferCache<P>::UpdateGraphicsBuffers(bool is_indexed) { | 293 | void BufferCache<P>::UpdateGraphicsBuffers(bool is_indexed) { |
| 285 | MICROPROFILE_SCOPE(GPU_PrepareBuffers); | 294 | MICROPROFILE_SCOPE(GPU_PrepareBuffers); |
| 286 | do { | 295 | do { |
| 287 | has_deleted_buffers = false; | 296 | channel_state->has_deleted_buffers = false; |
| 288 | DoUpdateGraphicsBuffers(is_indexed); | 297 | DoUpdateGraphicsBuffers(is_indexed); |
| 289 | } while (has_deleted_buffers); | 298 | } while (channel_state->has_deleted_buffers); |
| 290 | } | 299 | } |
| 291 | 300 | ||
| 292 | template <class P> | 301 | template <class P> |
| 293 | void BufferCache<P>::UpdateComputeBuffers() { | 302 | void BufferCache<P>::UpdateComputeBuffers() { |
| 294 | MICROPROFILE_SCOPE(GPU_PrepareBuffers); | 303 | MICROPROFILE_SCOPE(GPU_PrepareBuffers); |
| 295 | do { | 304 | do { |
| 296 | has_deleted_buffers = false; | 305 | channel_state->has_deleted_buffers = false; |
| 297 | DoUpdateComputeBuffers(); | 306 | DoUpdateComputeBuffers(); |
| 298 | } while (has_deleted_buffers); | 307 | } while (channel_state->has_deleted_buffers); |
| 299 | } | 308 | } |
| 300 | 309 | ||
| 301 | template <class P> | 310 | template <class P> |
| @@ -338,98 +347,102 @@ template <class P> | |||
| 338 | void BufferCache<P>::SetUniformBuffersState(const std::array<u32, NUM_STAGES>& mask, | 347 | void BufferCache<P>::SetUniformBuffersState(const std::array<u32, NUM_STAGES>& mask, |
| 339 | const UniformBufferSizes* sizes) { | 348 | const UniformBufferSizes* sizes) { |
| 340 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { | 349 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { |
| 341 | if (enabled_uniform_buffer_masks != mask) { | 350 | if (channel_state->enabled_uniform_buffer_masks != mask) { |
| 342 | if constexpr (IS_OPENGL) { | 351 | if constexpr (IS_OPENGL) { |
| 343 | fast_bound_uniform_buffers.fill(0); | 352 | channel_state->fast_bound_uniform_buffers.fill(0); |
| 344 | } | 353 | } |
| 345 | dirty_uniform_buffers.fill(~u32{0}); | 354 | channel_state->dirty_uniform_buffers.fill(~u32{0}); |
| 346 | uniform_buffer_binding_sizes.fill({}); | 355 | channel_state->uniform_buffer_binding_sizes.fill({}); |
| 347 | } | 356 | } |
| 348 | } | 357 | } |
| 349 | enabled_uniform_buffer_masks = mask; | 358 | channel_state->enabled_uniform_buffer_masks = mask; |
| 350 | uniform_buffer_sizes = sizes; | 359 | channel_state->uniform_buffer_sizes = sizes; |
| 351 | } | 360 | } |
| 352 | 361 | ||
| 353 | template <class P> | 362 | template <class P> |
| 354 | void BufferCache<P>::SetComputeUniformBufferState(u32 mask, | 363 | void BufferCache<P>::SetComputeUniformBufferState(u32 mask, |
| 355 | const ComputeUniformBufferSizes* sizes) { | 364 | const ComputeUniformBufferSizes* sizes) { |
| 356 | enabled_compute_uniform_buffer_mask = mask; | 365 | channel_state->enabled_compute_uniform_buffer_mask = mask; |
| 357 | compute_uniform_buffer_sizes = sizes; | 366 | channel_state->compute_uniform_buffer_sizes = sizes; |
| 358 | } | 367 | } |
| 359 | 368 | ||
| 360 | template <class P> | 369 | template <class P> |
| 361 | void BufferCache<P>::UnbindGraphicsStorageBuffers(size_t stage) { | 370 | void BufferCache<P>::UnbindGraphicsStorageBuffers(size_t stage) { |
| 362 | enabled_storage_buffers[stage] = 0; | 371 | channel_state->enabled_storage_buffers[stage] = 0; |
| 363 | written_storage_buffers[stage] = 0; | 372 | channel_state->written_storage_buffers[stage] = 0; |
| 364 | } | 373 | } |
| 365 | 374 | ||
| 366 | template <class P> | 375 | template <class P> |
| 367 | void BufferCache<P>::BindGraphicsStorageBuffer(size_t stage, size_t ssbo_index, u32 cbuf_index, | 376 | void BufferCache<P>::BindGraphicsStorageBuffer(size_t stage, size_t ssbo_index, u32 cbuf_index, |
| 368 | u32 cbuf_offset, bool is_written) { | 377 | u32 cbuf_offset, bool is_written) { |
| 369 | enabled_storage_buffers[stage] |= 1U << ssbo_index; | 378 | channel_state->enabled_storage_buffers[stage] |= 1U << ssbo_index; |
| 370 | written_storage_buffers[stage] |= (is_written ? 1U : 0U) << ssbo_index; | 379 | channel_state->written_storage_buffers[stage] |= (is_written ? 1U : 0U) << ssbo_index; |
| 371 | 380 | ||
| 372 | const auto& cbufs = maxwell3d->state.shader_stages[stage]; | 381 | const auto& cbufs = maxwell3d->state.shader_stages[stage]; |
| 373 | const GPUVAddr ssbo_addr = cbufs.const_buffers[cbuf_index].address + cbuf_offset; | 382 | const GPUVAddr ssbo_addr = cbufs.const_buffers[cbuf_index].address + cbuf_offset; |
| 374 | storage_buffers[stage][ssbo_index] = StorageBufferBinding(ssbo_addr, cbuf_index, is_written); | 383 | channel_state->storage_buffers[stage][ssbo_index] = |
| 384 | StorageBufferBinding(ssbo_addr, cbuf_index, is_written); | ||
| 375 | } | 385 | } |
| 376 | 386 | ||
| 377 | template <class P> | 387 | template <class P> |
| 378 | void BufferCache<P>::UnbindGraphicsTextureBuffers(size_t stage) { | 388 | void BufferCache<P>::UnbindGraphicsTextureBuffers(size_t stage) { |
| 379 | enabled_texture_buffers[stage] = 0; | 389 | channel_state->enabled_texture_buffers[stage] = 0; |
| 380 | written_texture_buffers[stage] = 0; | 390 | channel_state->written_texture_buffers[stage] = 0; |
| 381 | image_texture_buffers[stage] = 0; | 391 | channel_state->image_texture_buffers[stage] = 0; |
| 382 | } | 392 | } |
| 383 | 393 | ||
| 384 | template <class P> | 394 | template <class P> |
| 385 | void BufferCache<P>::BindGraphicsTextureBuffer(size_t stage, size_t tbo_index, GPUVAddr gpu_addr, | 395 | void BufferCache<P>::BindGraphicsTextureBuffer(size_t stage, size_t tbo_index, GPUVAddr gpu_addr, |
| 386 | u32 size, PixelFormat format, bool is_written, | 396 | u32 size, PixelFormat format, bool is_written, |
| 387 | bool is_image) { | 397 | bool is_image) { |
| 388 | enabled_texture_buffers[stage] |= 1U << tbo_index; | 398 | channel_state->enabled_texture_buffers[stage] |= 1U << tbo_index; |
| 389 | written_texture_buffers[stage] |= (is_written ? 1U : 0U) << tbo_index; | 399 | channel_state->written_texture_buffers[stage] |= (is_written ? 1U : 0U) << tbo_index; |
| 390 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { | 400 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { |
| 391 | image_texture_buffers[stage] |= (is_image ? 1U : 0U) << tbo_index; | 401 | channel_state->image_texture_buffers[stage] |= (is_image ? 1U : 0U) << tbo_index; |
| 392 | } | 402 | } |
| 393 | texture_buffers[stage][tbo_index] = GetTextureBufferBinding(gpu_addr, size, format); | 403 | channel_state->texture_buffers[stage][tbo_index] = |
| 404 | GetTextureBufferBinding(gpu_addr, size, format); | ||
| 394 | } | 405 | } |
| 395 | 406 | ||
| 396 | template <class P> | 407 | template <class P> |
| 397 | void BufferCache<P>::UnbindComputeStorageBuffers() { | 408 | void BufferCache<P>::UnbindComputeStorageBuffers() { |
| 398 | enabled_compute_storage_buffers = 0; | 409 | channel_state->enabled_compute_storage_buffers = 0; |
| 399 | written_compute_storage_buffers = 0; | 410 | channel_state->written_compute_storage_buffers = 0; |
| 400 | image_compute_texture_buffers = 0; | 411 | channel_state->image_compute_texture_buffers = 0; |
| 401 | } | 412 | } |
| 402 | 413 | ||
| 403 | template <class P> | 414 | template <class P> |
| 404 | void BufferCache<P>::BindComputeStorageBuffer(size_t ssbo_index, u32 cbuf_index, u32 cbuf_offset, | 415 | void BufferCache<P>::BindComputeStorageBuffer(size_t ssbo_index, u32 cbuf_index, u32 cbuf_offset, |
| 405 | bool is_written) { | 416 | bool is_written) { |
| 406 | enabled_compute_storage_buffers |= 1U << ssbo_index; | 417 | channel_state->enabled_compute_storage_buffers |= 1U << ssbo_index; |
| 407 | written_compute_storage_buffers |= (is_written ? 1U : 0U) << ssbo_index; | 418 | channel_state->written_compute_storage_buffers |= (is_written ? 1U : 0U) << ssbo_index; |
| 408 | 419 | ||
| 409 | const auto& launch_desc = kepler_compute->launch_description; | 420 | const auto& launch_desc = kepler_compute->launch_description; |
| 410 | ASSERT(((launch_desc.const_buffer_enable_mask >> cbuf_index) & 1) != 0); | 421 | ASSERT(((launch_desc.const_buffer_enable_mask >> cbuf_index) & 1) != 0); |
| 411 | 422 | ||
| 412 | const auto& cbufs = launch_desc.const_buffer_config; | 423 | const auto& cbufs = launch_desc.const_buffer_config; |
| 413 | const GPUVAddr ssbo_addr = cbufs[cbuf_index].Address() + cbuf_offset; | 424 | const GPUVAddr ssbo_addr = cbufs[cbuf_index].Address() + cbuf_offset; |
| 414 | compute_storage_buffers[ssbo_index] = StorageBufferBinding(ssbo_addr, cbuf_index, is_written); | 425 | channel_state->compute_storage_buffers[ssbo_index] = |
| 426 | StorageBufferBinding(ssbo_addr, cbuf_index, is_written); | ||
| 415 | } | 427 | } |
| 416 | 428 | ||
| 417 | template <class P> | 429 | template <class P> |
| 418 | void BufferCache<P>::UnbindComputeTextureBuffers() { | 430 | void BufferCache<P>::UnbindComputeTextureBuffers() { |
| 419 | enabled_compute_texture_buffers = 0; | 431 | channel_state->enabled_compute_texture_buffers = 0; |
| 420 | written_compute_texture_buffers = 0; | 432 | channel_state->written_compute_texture_buffers = 0; |
| 421 | image_compute_texture_buffers = 0; | 433 | channel_state->image_compute_texture_buffers = 0; |
| 422 | } | 434 | } |
| 423 | 435 | ||
| 424 | template <class P> | 436 | template <class P> |
| 425 | void BufferCache<P>::BindComputeTextureBuffer(size_t tbo_index, GPUVAddr gpu_addr, u32 size, | 437 | void BufferCache<P>::BindComputeTextureBuffer(size_t tbo_index, GPUVAddr gpu_addr, u32 size, |
| 426 | PixelFormat format, bool is_written, bool is_image) { | 438 | PixelFormat format, bool is_written, bool is_image) { |
| 427 | enabled_compute_texture_buffers |= 1U << tbo_index; | 439 | channel_state->enabled_compute_texture_buffers |= 1U << tbo_index; |
| 428 | written_compute_texture_buffers |= (is_written ? 1U : 0U) << tbo_index; | 440 | channel_state->written_compute_texture_buffers |= (is_written ? 1U : 0U) << tbo_index; |
| 429 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { | 441 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { |
| 430 | image_compute_texture_buffers |= (is_image ? 1U : 0U) << tbo_index; | 442 | channel_state->image_compute_texture_buffers |= (is_image ? 1U : 0U) << tbo_index; |
| 431 | } | 443 | } |
| 432 | compute_texture_buffers[tbo_index] = GetTextureBufferBinding(gpu_addr, size, format); | 444 | channel_state->compute_texture_buffers[tbo_index] = |
| 445 | GetTextureBufferBinding(gpu_addr, size, format); | ||
| 433 | } | 446 | } |
| 434 | 447 | ||
| 435 | template <class P> | 448 | template <class P> |
| @@ -672,10 +685,10 @@ bool BufferCache<P>::IsRegionCpuModified(VAddr addr, size_t size) { | |||
| 672 | 685 | ||
| 673 | template <class P> | 686 | template <class P> |
| 674 | void BufferCache<P>::BindHostIndexBuffer() { | 687 | void BufferCache<P>::BindHostIndexBuffer() { |
| 675 | Buffer& buffer = slot_buffers[index_buffer.buffer_id]; | 688 | Buffer& buffer = slot_buffers[channel_state->index_buffer.buffer_id]; |
| 676 | TouchBuffer(buffer, index_buffer.buffer_id); | 689 | TouchBuffer(buffer, channel_state->index_buffer.buffer_id); |
| 677 | const u32 offset = buffer.Offset(index_buffer.cpu_addr); | 690 | const u32 offset = buffer.Offset(channel_state->index_buffer.cpu_addr); |
| 678 | const u32 size = index_buffer.size; | 691 | const u32 size = channel_state->index_buffer.size; |
| 679 | const auto& draw_state = maxwell3d->draw_manager->GetDrawState(); | 692 | const auto& draw_state = maxwell3d->draw_manager->GetDrawState(); |
| 680 | if (!draw_state.inline_index_draw_indexes.empty()) [[unlikely]] { | 693 | if (!draw_state.inline_index_draw_indexes.empty()) [[unlikely]] { |
| 681 | if constexpr (USE_MEMORY_MAPS) { | 694 | if constexpr (USE_MEMORY_MAPS) { |
| @@ -689,7 +702,7 @@ void BufferCache<P>::BindHostIndexBuffer() { | |||
| 689 | buffer.ImmediateUpload(0, draw_state.inline_index_draw_indexes); | 702 | buffer.ImmediateUpload(0, draw_state.inline_index_draw_indexes); |
| 690 | } | 703 | } |
| 691 | } else { | 704 | } else { |
| 692 | SynchronizeBuffer(buffer, index_buffer.cpu_addr, size); | 705 | SynchronizeBuffer(buffer, channel_state->index_buffer.cpu_addr, size); |
| 693 | } | 706 | } |
| 694 | if constexpr (HAS_FULL_INDEX_AND_PRIMITIVE_SUPPORT) { | 707 | if constexpr (HAS_FULL_INDEX_AND_PRIMITIVE_SUPPORT) { |
| 695 | const u32 new_offset = | 708 | const u32 new_offset = |
| @@ -706,7 +719,7 @@ template <class P> | |||
| 706 | void BufferCache<P>::BindHostVertexBuffers() { | 719 | void BufferCache<P>::BindHostVertexBuffers() { |
| 707 | auto& flags = maxwell3d->dirty.flags; | 720 | auto& flags = maxwell3d->dirty.flags; |
| 708 | for (u32 index = 0; index < NUM_VERTEX_BUFFERS; ++index) { | 721 | for (u32 index = 0; index < NUM_VERTEX_BUFFERS; ++index) { |
| 709 | const Binding& binding = vertex_buffers[index]; | 722 | const Binding& binding = channel_state->vertex_buffers[index]; |
| 710 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 723 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 711 | TouchBuffer(buffer, binding.buffer_id); | 724 | TouchBuffer(buffer, binding.buffer_id); |
| 712 | SynchronizeBuffer(buffer, binding.cpu_addr, binding.size); | 725 | SynchronizeBuffer(buffer, binding.cpu_addr, binding.size); |
| @@ -729,19 +742,19 @@ void BufferCache<P>::BindHostDrawIndirectBuffers() { | |||
| 729 | SynchronizeBuffer(buffer, binding.cpu_addr, binding.size); | 742 | SynchronizeBuffer(buffer, binding.cpu_addr, binding.size); |
| 730 | }; | 743 | }; |
| 731 | if (current_draw_indirect->include_count) { | 744 | if (current_draw_indirect->include_count) { |
| 732 | bind_buffer(count_buffer_binding); | 745 | bind_buffer(channel_state->count_buffer_binding); |
| 733 | } | 746 | } |
| 734 | bind_buffer(indirect_buffer_binding); | 747 | bind_buffer(channel_state->indirect_buffer_binding); |
| 735 | } | 748 | } |
| 736 | 749 | ||
| 737 | template <class P> | 750 | template <class P> |
| 738 | void BufferCache<P>::BindHostGraphicsUniformBuffers(size_t stage) { | 751 | void BufferCache<P>::BindHostGraphicsUniformBuffers(size_t stage) { |
| 739 | u32 dirty = ~0U; | 752 | u32 dirty = ~0U; |
| 740 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { | 753 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { |
| 741 | dirty = std::exchange(dirty_uniform_buffers[stage], 0); | 754 | dirty = std::exchange(channel_state->dirty_uniform_buffers[stage], 0); |
| 742 | } | 755 | } |
| 743 | u32 binding_index = 0; | 756 | u32 binding_index = 0; |
| 744 | ForEachEnabledBit(enabled_uniform_buffer_masks[stage], [&](u32 index) { | 757 | ForEachEnabledBit(channel_state->enabled_uniform_buffer_masks[stage], [&](u32 index) { |
| 745 | const bool needs_bind = ((dirty >> index) & 1) != 0; | 758 | const bool needs_bind = ((dirty >> index) & 1) != 0; |
| 746 | BindHostGraphicsUniformBuffer(stage, index, binding_index, needs_bind); | 759 | BindHostGraphicsUniformBuffer(stage, index, binding_index, needs_bind); |
| 747 | if constexpr (NEEDS_BIND_UNIFORM_INDEX) { | 760 | if constexpr (NEEDS_BIND_UNIFORM_INDEX) { |
| @@ -753,13 +766,13 @@ void BufferCache<P>::BindHostGraphicsUniformBuffers(size_t stage) { | |||
| 753 | template <class P> | 766 | template <class P> |
| 754 | void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32 binding_index, | 767 | void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32 binding_index, |
| 755 | bool needs_bind) { | 768 | bool needs_bind) { |
| 756 | const Binding& binding = uniform_buffers[stage][index]; | 769 | const Binding& binding = channel_state->uniform_buffers[stage][index]; |
| 757 | const VAddr cpu_addr = binding.cpu_addr; | 770 | const VAddr cpu_addr = binding.cpu_addr; |
| 758 | const u32 size = std::min(binding.size, (*uniform_buffer_sizes)[stage][index]); | 771 | const u32 size = std::min(binding.size, (*channel_state->uniform_buffer_sizes)[stage][index]); |
| 759 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 772 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 760 | TouchBuffer(buffer, binding.buffer_id); | 773 | TouchBuffer(buffer, binding.buffer_id); |
| 761 | const bool use_fast_buffer = binding.buffer_id != NULL_BUFFER_ID && | 774 | const bool use_fast_buffer = binding.buffer_id != NULL_BUFFER_ID && |
| 762 | size <= uniform_buffer_skip_cache_size && | 775 | size <= channel_state->uniform_buffer_skip_cache_size && |
| 763 | !memory_tracker.IsRegionGpuModified(cpu_addr, size); | 776 | !memory_tracker.IsRegionGpuModified(cpu_addr, size); |
| 764 | if (use_fast_buffer) { | 777 | if (use_fast_buffer) { |
| 765 | if constexpr (IS_OPENGL) { | 778 | if constexpr (IS_OPENGL) { |
| @@ -767,11 +780,11 @@ void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32 | |||
| 767 | // Fast path for Nvidia | 780 | // Fast path for Nvidia |
| 768 | const bool should_fast_bind = | 781 | const bool should_fast_bind = |
| 769 | !HasFastUniformBufferBound(stage, binding_index) || | 782 | !HasFastUniformBufferBound(stage, binding_index) || |
| 770 | uniform_buffer_binding_sizes[stage][binding_index] != size; | 783 | channel_state->uniform_buffer_binding_sizes[stage][binding_index] != size; |
| 771 | if (should_fast_bind) { | 784 | if (should_fast_bind) { |
| 772 | // We only have to bind when the currently bound buffer is not the fast version | 785 | // We only have to bind when the currently bound buffer is not the fast version |
| 773 | fast_bound_uniform_buffers[stage] |= 1U << binding_index; | 786 | channel_state->fast_bound_uniform_buffers[stage] |= 1U << binding_index; |
| 774 | uniform_buffer_binding_sizes[stage][binding_index] = size; | 787 | channel_state->uniform_buffer_binding_sizes[stage][binding_index] = size; |
| 775 | runtime.BindFastUniformBuffer(stage, binding_index, size); | 788 | runtime.BindFastUniformBuffer(stage, binding_index, size); |
| 776 | } | 789 | } |
| 777 | const auto span = ImmediateBufferWithData(cpu_addr, size); | 790 | const auto span = ImmediateBufferWithData(cpu_addr, size); |
| @@ -780,8 +793,8 @@ void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32 | |||
| 780 | } | 793 | } |
| 781 | } | 794 | } |
| 782 | if constexpr (IS_OPENGL) { | 795 | if constexpr (IS_OPENGL) { |
| 783 | fast_bound_uniform_buffers[stage] |= 1U << binding_index; | 796 | channel_state->fast_bound_uniform_buffers[stage] |= 1U << binding_index; |
| 784 | uniform_buffer_binding_sizes[stage][binding_index] = size; | 797 | channel_state->uniform_buffer_binding_sizes[stage][binding_index] = size; |
| 785 | } | 798 | } |
| 786 | // Stream buffer path to avoid stalling on non-Nvidia drivers or Vulkan | 799 | // Stream buffer path to avoid stalling on non-Nvidia drivers or Vulkan |
| 787 | const std::span<u8> span = runtime.BindMappedUniformBuffer(stage, binding_index, size); | 800 | const std::span<u8> span = runtime.BindMappedUniformBuffer(stage, binding_index, size); |
| @@ -791,15 +804,15 @@ void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32 | |||
| 791 | // Classic cached path | 804 | // Classic cached path |
| 792 | const bool sync_cached = SynchronizeBuffer(buffer, cpu_addr, size); | 805 | const bool sync_cached = SynchronizeBuffer(buffer, cpu_addr, size); |
| 793 | if (sync_cached) { | 806 | if (sync_cached) { |
| 794 | ++uniform_cache_hits[0]; | 807 | ++channel_state->uniform_cache_hits[0]; |
| 795 | } | 808 | } |
| 796 | ++uniform_cache_shots[0]; | 809 | ++channel_state->uniform_cache_shots[0]; |
| 797 | 810 | ||
| 798 | // Skip binding if it's not needed and if the bound buffer is not the fast version | 811 | // Skip binding if it's not needed and if the bound buffer is not the fast version |
| 799 | // This exists to avoid instances where the fast buffer is bound and a GPU write happens | 812 | // This exists to avoid instances where the fast buffer is bound and a GPU write happens |
| 800 | needs_bind |= HasFastUniformBufferBound(stage, binding_index); | 813 | needs_bind |= HasFastUniformBufferBound(stage, binding_index); |
| 801 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { | 814 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { |
| 802 | needs_bind |= uniform_buffer_binding_sizes[stage][binding_index] != size; | 815 | needs_bind |= channel_state->uniform_buffer_binding_sizes[stage][binding_index] != size; |
| 803 | } | 816 | } |
| 804 | if (!needs_bind) { | 817 | if (!needs_bind) { |
| 805 | return; | 818 | return; |
| @@ -807,14 +820,14 @@ void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32 | |||
| 807 | const u32 offset = buffer.Offset(cpu_addr); | 820 | const u32 offset = buffer.Offset(cpu_addr); |
| 808 | if constexpr (IS_OPENGL) { | 821 | if constexpr (IS_OPENGL) { |
| 809 | // Fast buffer will be unbound | 822 | // Fast buffer will be unbound |
| 810 | fast_bound_uniform_buffers[stage] &= ~(1U << binding_index); | 823 | channel_state->fast_bound_uniform_buffers[stage] &= ~(1U << binding_index); |
| 811 | 824 | ||
| 812 | // Mark the index as dirty if offset doesn't match | 825 | // Mark the index as dirty if offset doesn't match |
| 813 | const bool is_copy_bind = offset != 0 && !runtime.SupportsNonZeroUniformOffset(); | 826 | const bool is_copy_bind = offset != 0 && !runtime.SupportsNonZeroUniformOffset(); |
| 814 | dirty_uniform_buffers[stage] |= (is_copy_bind ? 1U : 0U) << index; | 827 | channel_state->dirty_uniform_buffers[stage] |= (is_copy_bind ? 1U : 0U) << index; |
| 815 | } | 828 | } |
| 816 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { | 829 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { |
| 817 | uniform_buffer_binding_sizes[stage][binding_index] = size; | 830 | channel_state->uniform_buffer_binding_sizes[stage][binding_index] = size; |
| 818 | } | 831 | } |
| 819 | if constexpr (NEEDS_BIND_UNIFORM_INDEX) { | 832 | if constexpr (NEEDS_BIND_UNIFORM_INDEX) { |
| 820 | runtime.BindUniformBuffer(stage, binding_index, buffer, offset, size); | 833 | runtime.BindUniformBuffer(stage, binding_index, buffer, offset, size); |
| @@ -826,15 +839,15 @@ void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32 | |||
| 826 | template <class P> | 839 | template <class P> |
| 827 | void BufferCache<P>::BindHostGraphicsStorageBuffers(size_t stage) { | 840 | void BufferCache<P>::BindHostGraphicsStorageBuffers(size_t stage) { |
| 828 | u32 binding_index = 0; | 841 | u32 binding_index = 0; |
| 829 | ForEachEnabledBit(enabled_storage_buffers[stage], [&](u32 index) { | 842 | ForEachEnabledBit(channel_state->enabled_storage_buffers[stage], [&](u32 index) { |
| 830 | const Binding& binding = storage_buffers[stage][index]; | 843 | const Binding& binding = channel_state->storage_buffers[stage][index]; |
| 831 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 844 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 832 | TouchBuffer(buffer, binding.buffer_id); | 845 | TouchBuffer(buffer, binding.buffer_id); |
| 833 | const u32 size = binding.size; | 846 | const u32 size = binding.size; |
| 834 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 847 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| 835 | 848 | ||
| 836 | const u32 offset = buffer.Offset(binding.cpu_addr); | 849 | const u32 offset = buffer.Offset(binding.cpu_addr); |
| 837 | const bool is_written = ((written_storage_buffers[stage] >> index) & 1) != 0; | 850 | const bool is_written = ((channel_state->written_storage_buffers[stage] >> index) & 1) != 0; |
| 838 | if constexpr (NEEDS_BIND_STORAGE_INDEX) { | 851 | if constexpr (NEEDS_BIND_STORAGE_INDEX) { |
| 839 | runtime.BindStorageBuffer(stage, binding_index, buffer, offset, size, is_written); | 852 | runtime.BindStorageBuffer(stage, binding_index, buffer, offset, size, is_written); |
| 840 | ++binding_index; | 853 | ++binding_index; |
| @@ -846,8 +859,8 @@ void BufferCache<P>::BindHostGraphicsStorageBuffers(size_t stage) { | |||
| 846 | 859 | ||
| 847 | template <class P> | 860 | template <class P> |
| 848 | void BufferCache<P>::BindHostGraphicsTextureBuffers(size_t stage) { | 861 | void BufferCache<P>::BindHostGraphicsTextureBuffers(size_t stage) { |
| 849 | ForEachEnabledBit(enabled_texture_buffers[stage], [&](u32 index) { | 862 | ForEachEnabledBit(channel_state->enabled_texture_buffers[stage], [&](u32 index) { |
| 850 | const TextureBufferBinding& binding = texture_buffers[stage][index]; | 863 | const TextureBufferBinding& binding = channel_state->texture_buffers[stage][index]; |
| 851 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 864 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 852 | const u32 size = binding.size; | 865 | const u32 size = binding.size; |
| 853 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 866 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| @@ -855,7 +868,7 @@ void BufferCache<P>::BindHostGraphicsTextureBuffers(size_t stage) { | |||
| 855 | const u32 offset = buffer.Offset(binding.cpu_addr); | 868 | const u32 offset = buffer.Offset(binding.cpu_addr); |
| 856 | const PixelFormat format = binding.format; | 869 | const PixelFormat format = binding.format; |
| 857 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { | 870 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { |
| 858 | if (((image_texture_buffers[stage] >> index) & 1) != 0) { | 871 | if (((channel_state->image_texture_buffers[stage] >> index) & 1) != 0) { |
| 859 | runtime.BindImageBuffer(buffer, offset, size, format); | 872 | runtime.BindImageBuffer(buffer, offset, size, format); |
| 860 | } else { | 873 | } else { |
| 861 | runtime.BindTextureBuffer(buffer, offset, size, format); | 874 | runtime.BindTextureBuffer(buffer, offset, size, format); |
| @@ -872,7 +885,7 @@ void BufferCache<P>::BindHostTransformFeedbackBuffers() { | |||
| 872 | return; | 885 | return; |
| 873 | } | 886 | } |
| 874 | for (u32 index = 0; index < NUM_TRANSFORM_FEEDBACK_BUFFERS; ++index) { | 887 | for (u32 index = 0; index < NUM_TRANSFORM_FEEDBACK_BUFFERS; ++index) { |
| 875 | const Binding& binding = transform_feedback_buffers[index]; | 888 | const Binding& binding = channel_state->transform_feedback_buffers[index]; |
| 876 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 889 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 877 | TouchBuffer(buffer, binding.buffer_id); | 890 | TouchBuffer(buffer, binding.buffer_id); |
| 878 | const u32 size = binding.size; | 891 | const u32 size = binding.size; |
| @@ -887,15 +900,16 @@ template <class P> | |||
| 887 | void BufferCache<P>::BindHostComputeUniformBuffers() { | 900 | void BufferCache<P>::BindHostComputeUniformBuffers() { |
| 888 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { | 901 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { |
| 889 | // Mark all uniform buffers as dirty | 902 | // Mark all uniform buffers as dirty |
| 890 | dirty_uniform_buffers.fill(~u32{0}); | 903 | channel_state->dirty_uniform_buffers.fill(~u32{0}); |
| 891 | fast_bound_uniform_buffers.fill(0); | 904 | channel_state->fast_bound_uniform_buffers.fill(0); |
| 892 | } | 905 | } |
| 893 | u32 binding_index = 0; | 906 | u32 binding_index = 0; |
| 894 | ForEachEnabledBit(enabled_compute_uniform_buffer_mask, [&](u32 index) { | 907 | ForEachEnabledBit(channel_state->enabled_compute_uniform_buffer_mask, [&](u32 index) { |
| 895 | const Binding& binding = compute_uniform_buffers[index]; | 908 | const Binding& binding = channel_state->compute_uniform_buffers[index]; |
| 896 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 909 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 897 | TouchBuffer(buffer, binding.buffer_id); | 910 | TouchBuffer(buffer, binding.buffer_id); |
| 898 | const u32 size = std::min(binding.size, (*compute_uniform_buffer_sizes)[index]); | 911 | const u32 size = |
| 912 | std::min(binding.size, (*channel_state->compute_uniform_buffer_sizes)[index]); | ||
| 899 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 913 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| 900 | 914 | ||
| 901 | const u32 offset = buffer.Offset(binding.cpu_addr); | 915 | const u32 offset = buffer.Offset(binding.cpu_addr); |
| @@ -911,15 +925,16 @@ void BufferCache<P>::BindHostComputeUniformBuffers() { | |||
| 911 | template <class P> | 925 | template <class P> |
| 912 | void BufferCache<P>::BindHostComputeStorageBuffers() { | 926 | void BufferCache<P>::BindHostComputeStorageBuffers() { |
| 913 | u32 binding_index = 0; | 927 | u32 binding_index = 0; |
| 914 | ForEachEnabledBit(enabled_compute_storage_buffers, [&](u32 index) { | 928 | ForEachEnabledBit(channel_state->enabled_compute_storage_buffers, [&](u32 index) { |
| 915 | const Binding& binding = compute_storage_buffers[index]; | 929 | const Binding& binding = channel_state->compute_storage_buffers[index]; |
| 916 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 930 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 917 | TouchBuffer(buffer, binding.buffer_id); | 931 | TouchBuffer(buffer, binding.buffer_id); |
| 918 | const u32 size = binding.size; | 932 | const u32 size = binding.size; |
| 919 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 933 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| 920 | 934 | ||
| 921 | const u32 offset = buffer.Offset(binding.cpu_addr); | 935 | const u32 offset = buffer.Offset(binding.cpu_addr); |
| 922 | const bool is_written = ((written_compute_storage_buffers >> index) & 1) != 0; | 936 | const bool is_written = |
| 937 | ((channel_state->written_compute_storage_buffers >> index) & 1) != 0; | ||
| 923 | if constexpr (NEEDS_BIND_STORAGE_INDEX) { | 938 | if constexpr (NEEDS_BIND_STORAGE_INDEX) { |
| 924 | runtime.BindComputeStorageBuffer(binding_index, buffer, offset, size, is_written); | 939 | runtime.BindComputeStorageBuffer(binding_index, buffer, offset, size, is_written); |
| 925 | ++binding_index; | 940 | ++binding_index; |
| @@ -931,8 +946,8 @@ void BufferCache<P>::BindHostComputeStorageBuffers() { | |||
| 931 | 946 | ||
| 932 | template <class P> | 947 | template <class P> |
| 933 | void BufferCache<P>::BindHostComputeTextureBuffers() { | 948 | void BufferCache<P>::BindHostComputeTextureBuffers() { |
| 934 | ForEachEnabledBit(enabled_compute_texture_buffers, [&](u32 index) { | 949 | ForEachEnabledBit(channel_state->enabled_compute_texture_buffers, [&](u32 index) { |
| 935 | const TextureBufferBinding& binding = compute_texture_buffers[index]; | 950 | const TextureBufferBinding& binding = channel_state->compute_texture_buffers[index]; |
| 936 | Buffer& buffer = slot_buffers[binding.buffer_id]; | 951 | Buffer& buffer = slot_buffers[binding.buffer_id]; |
| 937 | const u32 size = binding.size; | 952 | const u32 size = binding.size; |
| 938 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 953 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| @@ -940,7 +955,7 @@ void BufferCache<P>::BindHostComputeTextureBuffers() { | |||
| 940 | const u32 offset = buffer.Offset(binding.cpu_addr); | 955 | const u32 offset = buffer.Offset(binding.cpu_addr); |
| 941 | const PixelFormat format = binding.format; | 956 | const PixelFormat format = binding.format; |
| 942 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { | 957 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { |
| 943 | if (((image_compute_texture_buffers >> index) & 1) != 0) { | 958 | if (((channel_state->image_compute_texture_buffers >> index) & 1) != 0) { |
| 944 | runtime.BindImageBuffer(buffer, offset, size, format); | 959 | runtime.BindImageBuffer(buffer, offset, size, format); |
| 945 | } else { | 960 | } else { |
| 946 | runtime.BindTextureBuffer(buffer, offset, size, format); | 961 | runtime.BindTextureBuffer(buffer, offset, size, format); |
| @@ -954,7 +969,7 @@ void BufferCache<P>::BindHostComputeTextureBuffers() { | |||
| 954 | template <class P> | 969 | template <class P> |
| 955 | void BufferCache<P>::DoUpdateGraphicsBuffers(bool is_indexed) { | 970 | void BufferCache<P>::DoUpdateGraphicsBuffers(bool is_indexed) { |
| 956 | do { | 971 | do { |
| 957 | has_deleted_buffers = false; | 972 | channel_state->has_deleted_buffers = false; |
| 958 | if (is_indexed) { | 973 | if (is_indexed) { |
| 959 | UpdateIndexBuffer(); | 974 | UpdateIndexBuffer(); |
| 960 | } | 975 | } |
| @@ -968,7 +983,7 @@ void BufferCache<P>::DoUpdateGraphicsBuffers(bool is_indexed) { | |||
| 968 | if (current_draw_indirect) { | 983 | if (current_draw_indirect) { |
| 969 | UpdateDrawIndirect(); | 984 | UpdateDrawIndirect(); |
| 970 | } | 985 | } |
| 971 | } while (has_deleted_buffers); | 986 | } while (channel_state->has_deleted_buffers); |
| 972 | } | 987 | } |
| 973 | 988 | ||
| 974 | template <class P> | 989 | template <class P> |
| @@ -999,7 +1014,7 @@ void BufferCache<P>::UpdateIndexBuffer() { | |||
| 999 | slot_buffers.erase(inline_buffer_id); | 1014 | slot_buffers.erase(inline_buffer_id); |
| 1000 | inline_buffer_id = CreateBuffer(0, buffer_size); | 1015 | inline_buffer_id = CreateBuffer(0, buffer_size); |
| 1001 | } | 1016 | } |
| 1002 | index_buffer = Binding{ | 1017 | channel_state->index_buffer = Binding{ |
| 1003 | .cpu_addr = 0, | 1018 | .cpu_addr = 0, |
| 1004 | .size = inline_index_size, | 1019 | .size = inline_index_size, |
| 1005 | .buffer_id = inline_buffer_id, | 1020 | .buffer_id = inline_buffer_id, |
| @@ -1015,10 +1030,10 @@ void BufferCache<P>::UpdateIndexBuffer() { | |||
| 1015 | (index_buffer_ref.count + index_buffer_ref.first) * index_buffer_ref.FormatSizeInBytes(); | 1030 | (index_buffer_ref.count + index_buffer_ref.first) * index_buffer_ref.FormatSizeInBytes(); |
| 1016 | const u32 size = std::min(address_size, draw_size); | 1031 | const u32 size = std::min(address_size, draw_size); |
| 1017 | if (size == 0 || !cpu_addr) { | 1032 | if (size == 0 || !cpu_addr) { |
| 1018 | index_buffer = NULL_BINDING; | 1033 | channel_state->index_buffer = NULL_BINDING; |
| 1019 | return; | 1034 | return; |
| 1020 | } | 1035 | } |
| 1021 | index_buffer = Binding{ | 1036 | channel_state->index_buffer = Binding{ |
| 1022 | .cpu_addr = *cpu_addr, | 1037 | .cpu_addr = *cpu_addr, |
| 1023 | .size = size, | 1038 | .size = size, |
| 1024 | .buffer_id = FindBuffer(*cpu_addr, size), | 1039 | .buffer_id = FindBuffer(*cpu_addr, size), |
| @@ -1051,13 +1066,13 @@ void BufferCache<P>::UpdateVertexBuffer(u32 index) { | |||
| 1051 | const u32 address_size = static_cast<u32>(gpu_addr_end - gpu_addr_begin); | 1066 | const u32 address_size = static_cast<u32>(gpu_addr_end - gpu_addr_begin); |
| 1052 | u32 size = address_size; // TODO: Analyze stride and number of vertices | 1067 | u32 size = address_size; // TODO: Analyze stride and number of vertices |
| 1053 | if (array.enable == 0 || size == 0 || !cpu_addr) { | 1068 | if (array.enable == 0 || size == 0 || !cpu_addr) { |
| 1054 | vertex_buffers[index] = NULL_BINDING; | 1069 | channel_state->vertex_buffers[index] = NULL_BINDING; |
| 1055 | return; | 1070 | return; |
| 1056 | } | 1071 | } |
| 1057 | if (!gpu_memory->IsWithinGPUAddressRange(gpu_addr_end)) { | 1072 | if (!gpu_memory->IsWithinGPUAddressRange(gpu_addr_end)) { |
| 1058 | size = static_cast<u32>(gpu_memory->MaxContinuousRange(gpu_addr_begin, size)); | 1073 | size = static_cast<u32>(gpu_memory->MaxContinuousRange(gpu_addr_begin, size)); |
| 1059 | } | 1074 | } |
| 1060 | vertex_buffers[index] = Binding{ | 1075 | channel_state->vertex_buffers[index] = Binding{ |
| 1061 | .cpu_addr = *cpu_addr, | 1076 | .cpu_addr = *cpu_addr, |
| 1062 | .size = size, | 1077 | .size = size, |
| 1063 | .buffer_id = FindBuffer(*cpu_addr, size), | 1078 | .buffer_id = FindBuffer(*cpu_addr, size), |
| @@ -1079,23 +1094,24 @@ void BufferCache<P>::UpdateDrawIndirect() { | |||
| 1079 | }; | 1094 | }; |
| 1080 | }; | 1095 | }; |
| 1081 | if (current_draw_indirect->include_count) { | 1096 | if (current_draw_indirect->include_count) { |
| 1082 | update(current_draw_indirect->count_start_address, sizeof(u32), count_buffer_binding); | 1097 | update(current_draw_indirect->count_start_address, sizeof(u32), |
| 1098 | channel_state->count_buffer_binding); | ||
| 1083 | } | 1099 | } |
| 1084 | update(current_draw_indirect->indirect_start_address, current_draw_indirect->buffer_size, | 1100 | update(current_draw_indirect->indirect_start_address, current_draw_indirect->buffer_size, |
| 1085 | indirect_buffer_binding); | 1101 | channel_state->indirect_buffer_binding); |
| 1086 | } | 1102 | } |
| 1087 | 1103 | ||
| 1088 | template <class P> | 1104 | template <class P> |
| 1089 | void BufferCache<P>::UpdateUniformBuffers(size_t stage) { | 1105 | void BufferCache<P>::UpdateUniformBuffers(size_t stage) { |
| 1090 | ForEachEnabledBit(enabled_uniform_buffer_masks[stage], [&](u32 index) { | 1106 | ForEachEnabledBit(channel_state->enabled_uniform_buffer_masks[stage], [&](u32 index) { |
| 1091 | Binding& binding = uniform_buffers[stage][index]; | 1107 | Binding& binding = channel_state->uniform_buffers[stage][index]; |
| 1092 | if (binding.buffer_id) { | 1108 | if (binding.buffer_id) { |
| 1093 | // Already updated | 1109 | // Already updated |
| 1094 | return; | 1110 | return; |
| 1095 | } | 1111 | } |
| 1096 | // Mark as dirty | 1112 | // Mark as dirty |
| 1097 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { | 1113 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { |
| 1098 | dirty_uniform_buffers[stage] |= 1U << index; | 1114 | channel_state->dirty_uniform_buffers[stage] |= 1U << index; |
| 1099 | } | 1115 | } |
| 1100 | // Resolve buffer | 1116 | // Resolve buffer |
| 1101 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); | 1117 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); |
| @@ -1104,10 +1120,10 @@ void BufferCache<P>::UpdateUniformBuffers(size_t stage) { | |||
| 1104 | 1120 | ||
| 1105 | template <class P> | 1121 | template <class P> |
| 1106 | void BufferCache<P>::UpdateStorageBuffers(size_t stage) { | 1122 | void BufferCache<P>::UpdateStorageBuffers(size_t stage) { |
| 1107 | const u32 written_mask = written_storage_buffers[stage]; | 1123 | const u32 written_mask = channel_state->written_storage_buffers[stage]; |
| 1108 | ForEachEnabledBit(enabled_storage_buffers[stage], [&](u32 index) { | 1124 | ForEachEnabledBit(channel_state->enabled_storage_buffers[stage], [&](u32 index) { |
| 1109 | // Resolve buffer | 1125 | // Resolve buffer |
| 1110 | Binding& binding = storage_buffers[stage][index]; | 1126 | Binding& binding = channel_state->storage_buffers[stage][index]; |
| 1111 | const BufferId buffer_id = FindBuffer(binding.cpu_addr, binding.size); | 1127 | const BufferId buffer_id = FindBuffer(binding.cpu_addr, binding.size); |
| 1112 | binding.buffer_id = buffer_id; | 1128 | binding.buffer_id = buffer_id; |
| 1113 | // Mark buffer as written if needed | 1129 | // Mark buffer as written if needed |
| @@ -1119,11 +1135,11 @@ void BufferCache<P>::UpdateStorageBuffers(size_t stage) { | |||
| 1119 | 1135 | ||
| 1120 | template <class P> | 1136 | template <class P> |
| 1121 | void BufferCache<P>::UpdateTextureBuffers(size_t stage) { | 1137 | void BufferCache<P>::UpdateTextureBuffers(size_t stage) { |
| 1122 | ForEachEnabledBit(enabled_texture_buffers[stage], [&](u32 index) { | 1138 | ForEachEnabledBit(channel_state->enabled_texture_buffers[stage], [&](u32 index) { |
| 1123 | Binding& binding = texture_buffers[stage][index]; | 1139 | Binding& binding = channel_state->texture_buffers[stage][index]; |
| 1124 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); | 1140 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); |
| 1125 | // Mark buffer as written if needed | 1141 | // Mark buffer as written if needed |
| 1126 | if (((written_texture_buffers[stage] >> index) & 1) != 0) { | 1142 | if (((channel_state->written_texture_buffers[stage] >> index) & 1) != 0) { |
| 1127 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, binding.size); | 1143 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, binding.size); |
| 1128 | } | 1144 | } |
| 1129 | }); | 1145 | }); |
| @@ -1146,11 +1162,11 @@ void BufferCache<P>::UpdateTransformFeedbackBuffer(u32 index) { | |||
| 1146 | const u32 size = binding.size; | 1162 | const u32 size = binding.size; |
| 1147 | const std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); | 1163 | const std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); |
| 1148 | if (binding.enable == 0 || size == 0 || !cpu_addr) { | 1164 | if (binding.enable == 0 || size == 0 || !cpu_addr) { |
| 1149 | transform_feedback_buffers[index] = NULL_BINDING; | 1165 | channel_state->transform_feedback_buffers[index] = NULL_BINDING; |
| 1150 | return; | 1166 | return; |
| 1151 | } | 1167 | } |
| 1152 | const BufferId buffer_id = FindBuffer(*cpu_addr, size); | 1168 | const BufferId buffer_id = FindBuffer(*cpu_addr, size); |
| 1153 | transform_feedback_buffers[index] = Binding{ | 1169 | channel_state->transform_feedback_buffers[index] = Binding{ |
| 1154 | .cpu_addr = *cpu_addr, | 1170 | .cpu_addr = *cpu_addr, |
| 1155 | .size = size, | 1171 | .size = size, |
| 1156 | .buffer_id = buffer_id, | 1172 | .buffer_id = buffer_id, |
| @@ -1160,8 +1176,8 @@ void BufferCache<P>::UpdateTransformFeedbackBuffer(u32 index) { | |||
| 1160 | 1176 | ||
| 1161 | template <class P> | 1177 | template <class P> |
| 1162 | void BufferCache<P>::UpdateComputeUniformBuffers() { | 1178 | void BufferCache<P>::UpdateComputeUniformBuffers() { |
| 1163 | ForEachEnabledBit(enabled_compute_uniform_buffer_mask, [&](u32 index) { | 1179 | ForEachEnabledBit(channel_state->enabled_compute_uniform_buffer_mask, [&](u32 index) { |
| 1164 | Binding& binding = compute_uniform_buffers[index]; | 1180 | Binding& binding = channel_state->compute_uniform_buffers[index]; |
| 1165 | binding = NULL_BINDING; | 1181 | binding = NULL_BINDING; |
| 1166 | const auto& launch_desc = kepler_compute->launch_description; | 1182 | const auto& launch_desc = kepler_compute->launch_description; |
| 1167 | if (((launch_desc.const_buffer_enable_mask >> index) & 1) != 0) { | 1183 | if (((launch_desc.const_buffer_enable_mask >> index) & 1) != 0) { |
| @@ -1178,12 +1194,12 @@ void BufferCache<P>::UpdateComputeUniformBuffers() { | |||
| 1178 | 1194 | ||
| 1179 | template <class P> | 1195 | template <class P> |
| 1180 | void BufferCache<P>::UpdateComputeStorageBuffers() { | 1196 | void BufferCache<P>::UpdateComputeStorageBuffers() { |
| 1181 | ForEachEnabledBit(enabled_compute_storage_buffers, [&](u32 index) { | 1197 | ForEachEnabledBit(channel_state->enabled_compute_storage_buffers, [&](u32 index) { |
| 1182 | // Resolve buffer | 1198 | // Resolve buffer |
| 1183 | Binding& binding = compute_storage_buffers[index]; | 1199 | Binding& binding = channel_state->compute_storage_buffers[index]; |
| 1184 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); | 1200 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); |
| 1185 | // Mark as written if needed | 1201 | // Mark as written if needed |
| 1186 | if (((written_compute_storage_buffers >> index) & 1) != 0) { | 1202 | if (((channel_state->written_compute_storage_buffers >> index) & 1) != 0) { |
| 1187 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, binding.size); | 1203 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, binding.size); |
| 1188 | } | 1204 | } |
| 1189 | }); | 1205 | }); |
| @@ -1191,11 +1207,11 @@ void BufferCache<P>::UpdateComputeStorageBuffers() { | |||
| 1191 | 1207 | ||
| 1192 | template <class P> | 1208 | template <class P> |
| 1193 | void BufferCache<P>::UpdateComputeTextureBuffers() { | 1209 | void BufferCache<P>::UpdateComputeTextureBuffers() { |
| 1194 | ForEachEnabledBit(enabled_compute_texture_buffers, [&](u32 index) { | 1210 | ForEachEnabledBit(channel_state->enabled_compute_texture_buffers, [&](u32 index) { |
| 1195 | Binding& binding = compute_texture_buffers[index]; | 1211 | Binding& binding = channel_state->compute_texture_buffers[index]; |
| 1196 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); | 1212 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); |
| 1197 | // Mark as written if needed | 1213 | // Mark as written if needed |
| 1198 | if (((written_compute_texture_buffers >> index) & 1) != 0) { | 1214 | if (((channel_state->written_compute_texture_buffers >> index) & 1) != 0) { |
| 1199 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, binding.size); | 1215 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, binding.size); |
| 1200 | } | 1216 | } |
| 1201 | }); | 1217 | }); |
| @@ -1610,13 +1626,13 @@ void BufferCache<P>::DeleteBuffer(BufferId buffer_id, bool do_not_mark) { | |||
| 1610 | const auto replace = [scalar_replace](std::span<Binding> bindings) { | 1626 | const auto replace = [scalar_replace](std::span<Binding> bindings) { |
| 1611 | std::ranges::for_each(bindings, scalar_replace); | 1627 | std::ranges::for_each(bindings, scalar_replace); |
| 1612 | }; | 1628 | }; |
| 1613 | scalar_replace(index_buffer); | 1629 | scalar_replace(channel_state->index_buffer); |
| 1614 | replace(vertex_buffers); | 1630 | replace(channel_state->vertex_buffers); |
| 1615 | std::ranges::for_each(uniform_buffers, replace); | 1631 | std::ranges::for_each(channel_state->uniform_buffers, replace); |
| 1616 | std::ranges::for_each(storage_buffers, replace); | 1632 | std::ranges::for_each(channel_state->storage_buffers, replace); |
| 1617 | replace(transform_feedback_buffers); | 1633 | replace(channel_state->transform_feedback_buffers); |
| 1618 | replace(compute_uniform_buffers); | 1634 | replace(channel_state->compute_uniform_buffers); |
| 1619 | replace(compute_storage_buffers); | 1635 | replace(channel_state->compute_storage_buffers); |
| 1620 | 1636 | ||
| 1621 | // Mark the whole buffer as CPU written to stop tracking CPU writes | 1637 | // Mark the whole buffer as CPU written to stop tracking CPU writes |
| 1622 | if (!do_not_mark) { | 1638 | if (!do_not_mark) { |
| @@ -1634,8 +1650,8 @@ void BufferCache<P>::DeleteBuffer(BufferId buffer_id, bool do_not_mark) { | |||
| 1634 | template <class P> | 1650 | template <class P> |
| 1635 | void BufferCache<P>::NotifyBufferDeletion() { | 1651 | void BufferCache<P>::NotifyBufferDeletion() { |
| 1636 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { | 1652 | if constexpr (HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS) { |
| 1637 | dirty_uniform_buffers.fill(~u32{0}); | 1653 | channel_state->dirty_uniform_buffers.fill(~u32{0}); |
| 1638 | uniform_buffer_binding_sizes.fill({}); | 1654 | channel_state->uniform_buffer_binding_sizes.fill({}); |
| 1639 | } | 1655 | } |
| 1640 | auto& flags = maxwell3d->dirty.flags; | 1656 | auto& flags = maxwell3d->dirty.flags; |
| 1641 | flags[Dirty::IndexBuffer] = true; | 1657 | flags[Dirty::IndexBuffer] = true; |
| @@ -1643,13 +1659,12 @@ void BufferCache<P>::NotifyBufferDeletion() { | |||
| 1643 | for (u32 index = 0; index < NUM_VERTEX_BUFFERS; ++index) { | 1659 | for (u32 index = 0; index < NUM_VERTEX_BUFFERS; ++index) { |
| 1644 | flags[Dirty::VertexBuffer0 + index] = true; | 1660 | flags[Dirty::VertexBuffer0 + index] = true; |
| 1645 | } | 1661 | } |
| 1646 | has_deleted_buffers = true; | 1662 | channel_state->has_deleted_buffers = true; |
| 1647 | } | 1663 | } |
| 1648 | 1664 | ||
| 1649 | template <class P> | 1665 | template <class P> |
| 1650 | typename BufferCache<P>::Binding BufferCache<P>::StorageBufferBinding(GPUVAddr ssbo_addr, | 1666 | Binding BufferCache<P>::StorageBufferBinding(GPUVAddr ssbo_addr, u32 cbuf_index, |
| 1651 | u32 cbuf_index, | 1667 | bool is_written) const { |
| 1652 | bool is_written) const { | ||
| 1653 | const GPUVAddr gpu_addr = gpu_memory->Read<u64>(ssbo_addr); | 1668 | const GPUVAddr gpu_addr = gpu_memory->Read<u64>(ssbo_addr); |
| 1654 | const auto size = [&]() { | 1669 | const auto size = [&]() { |
| 1655 | const bool is_nvn_cbuf = cbuf_index == 0; | 1670 | const bool is_nvn_cbuf = cbuf_index == 0; |
| @@ -1681,8 +1696,8 @@ typename BufferCache<P>::Binding BufferCache<P>::StorageBufferBinding(GPUVAddr s | |||
| 1681 | } | 1696 | } |
| 1682 | 1697 | ||
| 1683 | template <class P> | 1698 | template <class P> |
| 1684 | typename BufferCache<P>::TextureBufferBinding BufferCache<P>::GetTextureBufferBinding( | 1699 | TextureBufferBinding BufferCache<P>::GetTextureBufferBinding(GPUVAddr gpu_addr, u32 size, |
| 1685 | GPUVAddr gpu_addr, u32 size, PixelFormat format) { | 1700 | PixelFormat format) { |
| 1686 | const std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); | 1701 | const std::optional<VAddr> cpu_addr = gpu_memory->GpuToCpuAddress(gpu_addr); |
| 1687 | TextureBufferBinding binding; | 1702 | TextureBufferBinding binding; |
| 1688 | if (!cpu_addr || size == 0) { | 1703 | if (!cpu_addr || size == 0) { |
| @@ -1721,7 +1736,7 @@ std::span<u8> BufferCache<P>::ImmediateBuffer(size_t wanted_capacity) { | |||
| 1721 | template <class P> | 1736 | template <class P> |
| 1722 | bool BufferCache<P>::HasFastUniformBufferBound(size_t stage, u32 binding_index) const noexcept { | 1737 | bool BufferCache<P>::HasFastUniformBufferBound(size_t stage, u32 binding_index) const noexcept { |
| 1723 | if constexpr (IS_OPENGL) { | 1738 | if constexpr (IS_OPENGL) { |
| 1724 | return ((fast_bound_uniform_buffers[stage] >> binding_index) & 1) != 0; | 1739 | return ((channel_state->fast_bound_uniform_buffers[stage] >> binding_index) & 1) != 0; |
| 1725 | } else { | 1740 | } else { |
| 1726 | // Only OpenGL has fast uniform buffers | 1741 | // Only OpenGL has fast uniform buffers |
| 1727 | return false; | 1742 | return false; |
| @@ -1730,14 +1745,14 @@ bool BufferCache<P>::HasFastUniformBufferBound(size_t stage, u32 binding_index) | |||
| 1730 | 1745 | ||
| 1731 | template <class P> | 1746 | template <class P> |
| 1732 | std::pair<typename BufferCache<P>::Buffer*, u32> BufferCache<P>::GetDrawIndirectCount() { | 1747 | std::pair<typename BufferCache<P>::Buffer*, u32> BufferCache<P>::GetDrawIndirectCount() { |
| 1733 | auto& buffer = slot_buffers[count_buffer_binding.buffer_id]; | 1748 | auto& buffer = slot_buffers[channel_state->count_buffer_binding.buffer_id]; |
| 1734 | return std::make_pair(&buffer, buffer.Offset(count_buffer_binding.cpu_addr)); | 1749 | return std::make_pair(&buffer, buffer.Offset(channel_state->count_buffer_binding.cpu_addr)); |
| 1735 | } | 1750 | } |
| 1736 | 1751 | ||
| 1737 | template <class P> | 1752 | template <class P> |
| 1738 | std::pair<typename BufferCache<P>::Buffer*, u32> BufferCache<P>::GetDrawIndirectBuffer() { | 1753 | std::pair<typename BufferCache<P>::Buffer*, u32> BufferCache<P>::GetDrawIndirectBuffer() { |
| 1739 | auto& buffer = slot_buffers[indirect_buffer_binding.buffer_id]; | 1754 | auto& buffer = slot_buffers[channel_state->indirect_buffer_binding.buffer_id]; |
| 1740 | return std::make_pair(&buffer, buffer.Offset(indirect_buffer_binding.cpu_addr)); | 1755 | return std::make_pair(&buffer, buffer.Offset(channel_state->indirect_buffer_binding.cpu_addr)); |
| 1741 | } | 1756 | } |
| 1742 | 1757 | ||
| 1743 | } // namespace VideoCommon | 1758 | } // namespace VideoCommon |
diff --git a/src/video_core/buffer_cache/buffer_cache_base.h b/src/video_core/buffer_cache/buffer_cache_base.h index ac00d4d9d..c689fe06b 100644 --- a/src/video_core/buffer_cache/buffer_cache_base.h +++ b/src/video_core/buffer_cache/buffer_cache_base.h | |||
| @@ -86,8 +86,78 @@ enum class ObtainBufferOperation : u32 { | |||
| 86 | MarkQuery = 3, | 86 | MarkQuery = 3, |
| 87 | }; | 87 | }; |
| 88 | 88 | ||
| 89 | template <typename P> | 89 | static constexpr BufferId NULL_BUFFER_ID{0}; |
| 90 | class BufferCache : public VideoCommon::ChannelSetupCaches<VideoCommon::ChannelInfo> { | 90 | static constexpr u32 DEFAULT_SKIP_CACHE_SIZE = static_cast<u32>(4_KiB); |
| 91 | |||
| 92 | struct Binding { | ||
| 93 | VAddr cpu_addr{}; | ||
| 94 | u32 size{}; | ||
| 95 | BufferId buffer_id; | ||
| 96 | }; | ||
| 97 | |||
| 98 | struct TextureBufferBinding : Binding { | ||
| 99 | PixelFormat format; | ||
| 100 | }; | ||
| 101 | |||
| 102 | static constexpr Binding NULL_BINDING{ | ||
| 103 | .cpu_addr = 0, | ||
| 104 | .size = 0, | ||
| 105 | .buffer_id = NULL_BUFFER_ID, | ||
| 106 | }; | ||
| 107 | |||
| 108 | class BufferCacheChannelInfo : public ChannelInfo { | ||
| 109 | public: | ||
| 110 | BufferCacheChannelInfo() = delete; | ||
| 111 | BufferCacheChannelInfo(Tegra::Control::ChannelState& state) noexcept : ChannelInfo(state) {} | ||
| 112 | BufferCacheChannelInfo(const BufferCacheChannelInfo& state) = delete; | ||
| 113 | BufferCacheChannelInfo& operator=(const BufferCacheChannelInfo&) = delete; | ||
| 114 | |||
| 115 | Binding index_buffer; | ||
| 116 | std::array<Binding, NUM_VERTEX_BUFFERS> vertex_buffers; | ||
| 117 | std::array<std::array<Binding, NUM_GRAPHICS_UNIFORM_BUFFERS>, NUM_STAGES> uniform_buffers; | ||
| 118 | std::array<std::array<Binding, NUM_STORAGE_BUFFERS>, NUM_STAGES> storage_buffers; | ||
| 119 | std::array<std::array<TextureBufferBinding, NUM_TEXTURE_BUFFERS>, NUM_STAGES> texture_buffers; | ||
| 120 | std::array<Binding, NUM_TRANSFORM_FEEDBACK_BUFFERS> transform_feedback_buffers; | ||
| 121 | Binding count_buffer_binding; | ||
| 122 | Binding indirect_buffer_binding; | ||
| 123 | |||
| 124 | std::array<Binding, NUM_COMPUTE_UNIFORM_BUFFERS> compute_uniform_buffers; | ||
| 125 | std::array<Binding, NUM_STORAGE_BUFFERS> compute_storage_buffers; | ||
| 126 | std::array<TextureBufferBinding, NUM_TEXTURE_BUFFERS> compute_texture_buffers; | ||
| 127 | |||
| 128 | std::array<u32, NUM_STAGES> enabled_uniform_buffer_masks{}; | ||
| 129 | u32 enabled_compute_uniform_buffer_mask = 0; | ||
| 130 | |||
| 131 | const UniformBufferSizes* uniform_buffer_sizes{}; | ||
| 132 | const ComputeUniformBufferSizes* compute_uniform_buffer_sizes{}; | ||
| 133 | |||
| 134 | std::array<u32, NUM_STAGES> enabled_storage_buffers{}; | ||
| 135 | std::array<u32, NUM_STAGES> written_storage_buffers{}; | ||
| 136 | u32 enabled_compute_storage_buffers = 0; | ||
| 137 | u32 written_compute_storage_buffers = 0; | ||
| 138 | |||
| 139 | std::array<u32, NUM_STAGES> enabled_texture_buffers{}; | ||
| 140 | std::array<u32, NUM_STAGES> written_texture_buffers{}; | ||
| 141 | std::array<u32, NUM_STAGES> image_texture_buffers{}; | ||
| 142 | u32 enabled_compute_texture_buffers = 0; | ||
| 143 | u32 written_compute_texture_buffers = 0; | ||
| 144 | u32 image_compute_texture_buffers = 0; | ||
| 145 | |||
| 146 | std::array<u32, 16> uniform_cache_hits{}; | ||
| 147 | std::array<u32, 16> uniform_cache_shots{}; | ||
| 148 | |||
| 149 | u32 uniform_buffer_skip_cache_size = DEFAULT_SKIP_CACHE_SIZE; | ||
| 150 | |||
| 151 | bool has_deleted_buffers = false; | ||
| 152 | |||
| 153 | std::array<u32, NUM_STAGES> dirty_uniform_buffers{}; | ||
| 154 | std::array<u32, NUM_STAGES> fast_bound_uniform_buffers{}; | ||
| 155 | std::array<std::array<u32, NUM_GRAPHICS_UNIFORM_BUFFERS>, NUM_STAGES> | ||
| 156 | uniform_buffer_binding_sizes{}; | ||
| 157 | }; | ||
| 158 | |||
| 159 | template <class P> | ||
| 160 | class BufferCache : public VideoCommon::ChannelSetupCaches<BufferCacheChannelInfo> { | ||
| 91 | // Page size for caching purposes. | 161 | // Page size for caching purposes. |
| 92 | // This is unrelated to the CPU page size and it can be changed as it seems optimal. | 162 | // This is unrelated to the CPU page size and it can be changed as it seems optimal. |
| 93 | static constexpr u32 CACHING_PAGEBITS = 16; | 163 | static constexpr u32 CACHING_PAGEBITS = 16; |
| @@ -104,8 +174,6 @@ class BufferCache : public VideoCommon::ChannelSetupCaches<VideoCommon::ChannelI | |||
| 104 | static constexpr bool SEPARATE_IMAGE_BUFFERS_BINDINGS = P::SEPARATE_IMAGE_BUFFER_BINDINGS; | 174 | static constexpr bool SEPARATE_IMAGE_BUFFERS_BINDINGS = P::SEPARATE_IMAGE_BUFFER_BINDINGS; |
| 105 | static constexpr bool IMPLEMENTS_ASYNC_DOWNLOADS = P::IMPLEMENTS_ASYNC_DOWNLOADS; | 175 | static constexpr bool IMPLEMENTS_ASYNC_DOWNLOADS = P::IMPLEMENTS_ASYNC_DOWNLOADS; |
| 106 | 176 | ||
| 107 | static constexpr BufferId NULL_BUFFER_ID{0}; | ||
| 108 | |||
| 109 | static constexpr s64 DEFAULT_EXPECTED_MEMORY = 512_MiB; | 177 | static constexpr s64 DEFAULT_EXPECTED_MEMORY = 512_MiB; |
| 110 | static constexpr s64 DEFAULT_CRITICAL_MEMORY = 1_GiB; | 178 | static constexpr s64 DEFAULT_CRITICAL_MEMORY = 1_GiB; |
| 111 | static constexpr s64 TARGET_THRESHOLD = 4_GiB; | 179 | static constexpr s64 TARGET_THRESHOLD = 4_GiB; |
| @@ -149,8 +217,6 @@ class BufferCache : public VideoCommon::ChannelSetupCaches<VideoCommon::ChannelI | |||
| 149 | using OverlapSection = boost::icl::inter_section<int>; | 217 | using OverlapSection = boost::icl::inter_section<int>; |
| 150 | using OverlapCounter = boost::icl::split_interval_map<VAddr, int>; | 218 | using OverlapCounter = boost::icl::split_interval_map<VAddr, int>; |
| 151 | 219 | ||
| 152 | struct Empty {}; | ||
| 153 | |||
| 154 | struct OverlapResult { | 220 | struct OverlapResult { |
| 155 | std::vector<BufferId> ids; | 221 | std::vector<BufferId> ids; |
| 156 | VAddr begin; | 222 | VAddr begin; |
| @@ -158,25 +224,7 @@ class BufferCache : public VideoCommon::ChannelSetupCaches<VideoCommon::ChannelI | |||
| 158 | bool has_stream_leap = false; | 224 | bool has_stream_leap = false; |
| 159 | }; | 225 | }; |
| 160 | 226 | ||
| 161 | struct Binding { | ||
| 162 | VAddr cpu_addr{}; | ||
| 163 | u32 size{}; | ||
| 164 | BufferId buffer_id; | ||
| 165 | }; | ||
| 166 | |||
| 167 | struct TextureBufferBinding : Binding { | ||
| 168 | PixelFormat format; | ||
| 169 | }; | ||
| 170 | |||
| 171 | static constexpr Binding NULL_BINDING{ | ||
| 172 | .cpu_addr = 0, | ||
| 173 | .size = 0, | ||
| 174 | .buffer_id = NULL_BUFFER_ID, | ||
| 175 | }; | ||
| 176 | |||
| 177 | public: | 227 | public: |
| 178 | static constexpr u32 DEFAULT_SKIP_CACHE_SIZE = static_cast<u32>(4_KiB); | ||
| 179 | |||
| 180 | explicit BufferCache(VideoCore::RasterizerInterface& rasterizer_, | 228 | explicit BufferCache(VideoCore::RasterizerInterface& rasterizer_, |
| 181 | Core::Memory::Memory& cpu_memory_, Runtime& runtime_); | 229 | Core::Memory::Memory& cpu_memory_, Runtime& runtime_); |
| 182 | 230 | ||
| @@ -496,51 +544,6 @@ private: | |||
| 496 | 544 | ||
| 497 | u32 last_index_count = 0; | 545 | u32 last_index_count = 0; |
| 498 | 546 | ||
| 499 | Binding index_buffer; | ||
| 500 | std::array<Binding, NUM_VERTEX_BUFFERS> vertex_buffers; | ||
| 501 | std::array<std::array<Binding, NUM_GRAPHICS_UNIFORM_BUFFERS>, NUM_STAGES> uniform_buffers; | ||
| 502 | std::array<std::array<Binding, NUM_STORAGE_BUFFERS>, NUM_STAGES> storage_buffers; | ||
| 503 | std::array<std::array<TextureBufferBinding, NUM_TEXTURE_BUFFERS>, NUM_STAGES> texture_buffers; | ||
| 504 | std::array<Binding, NUM_TRANSFORM_FEEDBACK_BUFFERS> transform_feedback_buffers; | ||
| 505 | Binding count_buffer_binding; | ||
| 506 | Binding indirect_buffer_binding; | ||
| 507 | |||
| 508 | std::array<Binding, NUM_COMPUTE_UNIFORM_BUFFERS> compute_uniform_buffers; | ||
| 509 | std::array<Binding, NUM_STORAGE_BUFFERS> compute_storage_buffers; | ||
| 510 | std::array<TextureBufferBinding, NUM_TEXTURE_BUFFERS> compute_texture_buffers; | ||
| 511 | |||
| 512 | std::array<u32, NUM_STAGES> enabled_uniform_buffer_masks{}; | ||
| 513 | u32 enabled_compute_uniform_buffer_mask = 0; | ||
| 514 | |||
| 515 | const UniformBufferSizes* uniform_buffer_sizes{}; | ||
| 516 | const ComputeUniformBufferSizes* compute_uniform_buffer_sizes{}; | ||
| 517 | |||
| 518 | std::array<u32, NUM_STAGES> enabled_storage_buffers{}; | ||
| 519 | std::array<u32, NUM_STAGES> written_storage_buffers{}; | ||
| 520 | u32 enabled_compute_storage_buffers = 0; | ||
| 521 | u32 written_compute_storage_buffers = 0; | ||
| 522 | |||
| 523 | std::array<u32, NUM_STAGES> enabled_texture_buffers{}; | ||
| 524 | std::array<u32, NUM_STAGES> written_texture_buffers{}; | ||
| 525 | std::array<u32, NUM_STAGES> image_texture_buffers{}; | ||
| 526 | u32 enabled_compute_texture_buffers = 0; | ||
| 527 | u32 written_compute_texture_buffers = 0; | ||
| 528 | u32 image_compute_texture_buffers = 0; | ||
| 529 | |||
| 530 | std::array<u32, 16> uniform_cache_hits{}; | ||
| 531 | std::array<u32, 16> uniform_cache_shots{}; | ||
| 532 | |||
| 533 | u32 uniform_buffer_skip_cache_size = DEFAULT_SKIP_CACHE_SIZE; | ||
| 534 | |||
| 535 | bool has_deleted_buffers = false; | ||
| 536 | |||
| 537 | std::conditional_t<HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS, std::array<u32, NUM_STAGES>, Empty> | ||
| 538 | dirty_uniform_buffers{}; | ||
| 539 | std::conditional_t<IS_OPENGL, std::array<u32, NUM_STAGES>, Empty> fast_bound_uniform_buffers{}; | ||
| 540 | std::conditional_t<HAS_PERSISTENT_UNIFORM_BUFFER_BINDINGS, | ||
| 541 | std::array<std::array<u32, NUM_GRAPHICS_UNIFORM_BUFFERS>, NUM_STAGES>, Empty> | ||
| 542 | uniform_buffer_binding_sizes{}; | ||
| 543 | |||
| 544 | MemoryTracker memory_tracker; | 547 | MemoryTracker memory_tracker; |
| 545 | IntervalSet uncommitted_ranges; | 548 | IntervalSet uncommitted_ranges; |
| 546 | IntervalSet common_ranges; | 549 | IntervalSet common_ranges; |
diff --git a/src/video_core/host1x/codecs/codec.cpp b/src/video_core/host1x/codecs/codec.cpp index 3e9022dce..cd6a3a9b8 100644 --- a/src/video_core/host1x/codecs/codec.cpp +++ b/src/video_core/host1x/codecs/codec.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <fstream> | 5 | #include <fstream> |
| 6 | #include <vector> | 6 | #include <vector> |
| 7 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 8 | #include "common/scope_exit.h" | ||
| 8 | #include "common/settings.h" | 9 | #include "common/settings.h" |
| 9 | #include "video_core/host1x/codecs/codec.h" | 10 | #include "video_core/host1x/codecs/codec.h" |
| 10 | #include "video_core/host1x/codecs/h264.h" | 11 | #include "video_core/host1x/codecs/h264.h" |
| @@ -14,6 +15,8 @@ | |||
| 14 | #include "video_core/memory_manager.h" | 15 | #include "video_core/memory_manager.h" |
| 15 | 16 | ||
| 16 | extern "C" { | 17 | extern "C" { |
| 18 | #include <libavfilter/buffersink.h> | ||
| 19 | #include <libavfilter/buffersrc.h> | ||
| 17 | #include <libavutil/opt.h> | 20 | #include <libavutil/opt.h> |
| 18 | #ifdef LIBVA_FOUND | 21 | #ifdef LIBVA_FOUND |
| 19 | // for querying VAAPI driver information | 22 | // for querying VAAPI driver information |
| @@ -85,6 +88,10 @@ Codec::~Codec() { | |||
| 85 | // Free libav memory | 88 | // Free libav memory |
| 86 | avcodec_free_context(&av_codec_ctx); | 89 | avcodec_free_context(&av_codec_ctx); |
| 87 | av_buffer_unref(&av_gpu_decoder); | 90 | av_buffer_unref(&av_gpu_decoder); |
| 91 | |||
| 92 | if (filters_initialized) { | ||
| 93 | avfilter_graph_free(&av_filter_graph); | ||
| 94 | } | ||
| 88 | } | 95 | } |
| 89 | 96 | ||
| 90 | bool Codec::CreateGpuAvDevice() { | 97 | bool Codec::CreateGpuAvDevice() { |
| @@ -167,6 +174,62 @@ void Codec::InitializeGpuDecoder() { | |||
| 167 | av_codec_ctx->get_format = GetGpuFormat; | 174 | av_codec_ctx->get_format = GetGpuFormat; |
| 168 | } | 175 | } |
| 169 | 176 | ||
| 177 | void Codec::InitializeAvFilters(AVFrame* frame) { | ||
| 178 | const AVFilter* buffer_src = avfilter_get_by_name("buffer"); | ||
| 179 | const AVFilter* buffer_sink = avfilter_get_by_name("buffersink"); | ||
| 180 | AVFilterInOut* inputs = avfilter_inout_alloc(); | ||
| 181 | AVFilterInOut* outputs = avfilter_inout_alloc(); | ||
| 182 | SCOPE_EXIT({ | ||
| 183 | avfilter_inout_free(&inputs); | ||
| 184 | avfilter_inout_free(&outputs); | ||
| 185 | }); | ||
| 186 | |||
| 187 | // Don't know how to get the accurate time_base but it doesn't matter for yadif filter | ||
| 188 | // so just use 1/1 to make buffer filter happy | ||
| 189 | std::string args = fmt::format("video_size={}x{}:pix_fmt={}:time_base=1/1", frame->width, | ||
| 190 | frame->height, frame->format); | ||
| 191 | |||
| 192 | av_filter_graph = avfilter_graph_alloc(); | ||
| 193 | int ret = avfilter_graph_create_filter(&av_filter_src_ctx, buffer_src, "in", args.c_str(), | ||
| 194 | nullptr, av_filter_graph); | ||
| 195 | if (ret < 0) { | ||
| 196 | LOG_ERROR(Service_NVDRV, "avfilter_graph_create_filter source error: {}", ret); | ||
| 197 | return; | ||
| 198 | } | ||
| 199 | |||
| 200 | ret = avfilter_graph_create_filter(&av_filter_sink_ctx, buffer_sink, "out", nullptr, nullptr, | ||
| 201 | av_filter_graph); | ||
| 202 | if (ret < 0) { | ||
| 203 | LOG_ERROR(Service_NVDRV, "avfilter_graph_create_filter sink error: {}", ret); | ||
| 204 | return; | ||
| 205 | } | ||
| 206 | |||
| 207 | inputs->name = av_strdup("out"); | ||
| 208 | inputs->filter_ctx = av_filter_sink_ctx; | ||
| 209 | inputs->pad_idx = 0; | ||
| 210 | inputs->next = nullptr; | ||
| 211 | |||
| 212 | outputs->name = av_strdup("in"); | ||
| 213 | outputs->filter_ctx = av_filter_src_ctx; | ||
| 214 | outputs->pad_idx = 0; | ||
| 215 | outputs->next = nullptr; | ||
| 216 | |||
| 217 | const char* description = "yadif=1:-1:0"; | ||
| 218 | ret = avfilter_graph_parse_ptr(av_filter_graph, description, &inputs, &outputs, nullptr); | ||
| 219 | if (ret < 0) { | ||
| 220 | LOG_ERROR(Service_NVDRV, "avfilter_graph_parse_ptr error: {}", ret); | ||
| 221 | return; | ||
| 222 | } | ||
| 223 | |||
| 224 | ret = avfilter_graph_config(av_filter_graph, nullptr); | ||
| 225 | if (ret < 0) { | ||
| 226 | LOG_ERROR(Service_NVDRV, "avfilter_graph_config error: {}", ret); | ||
| 227 | return; | ||
| 228 | } | ||
| 229 | |||
| 230 | filters_initialized = true; | ||
| 231 | } | ||
| 232 | |||
| 170 | void Codec::Initialize() { | 233 | void Codec::Initialize() { |
| 171 | const AVCodecID codec = [&] { | 234 | const AVCodecID codec = [&] { |
| 172 | switch (current_codec) { | 235 | switch (current_codec) { |
| @@ -271,8 +334,34 @@ void Codec::Decode() { | |||
| 271 | UNIMPLEMENTED_MSG("Unexpected video format: {}", final_frame->format); | 334 | UNIMPLEMENTED_MSG("Unexpected video format: {}", final_frame->format); |
| 272 | return; | 335 | return; |
| 273 | } | 336 | } |
| 274 | av_frames.push(std::move(final_frame)); | 337 | if (!final_frame->interlaced_frame) { |
| 275 | if (av_frames.size() > 10) { | 338 | av_frames.push(std::move(final_frame)); |
| 339 | } else { | ||
| 340 | if (!filters_initialized) { | ||
| 341 | InitializeAvFilters(final_frame.get()); | ||
| 342 | } | ||
| 343 | if (const int ret = av_buffersrc_add_frame_flags(av_filter_src_ctx, final_frame.get(), | ||
| 344 | AV_BUFFERSRC_FLAG_KEEP_REF); | ||
| 345 | ret) { | ||
| 346 | LOG_DEBUG(Service_NVDRV, "av_buffersrc_add_frame_flags error {}", ret); | ||
| 347 | return; | ||
| 348 | } | ||
| 349 | while (true) { | ||
| 350 | auto filter_frame = AVFramePtr{av_frame_alloc(), AVFrameDeleter}; | ||
| 351 | |||
| 352 | int ret = av_buffersink_get_frame(av_filter_sink_ctx, filter_frame.get()); | ||
| 353 | |||
| 354 | if (ret == AVERROR(EAGAIN) || ret == AVERROR(AVERROR_EOF)) | ||
| 355 | break; | ||
| 356 | if (ret < 0) { | ||
| 357 | LOG_DEBUG(Service_NVDRV, "av_buffersink_get_frame error {}", ret); | ||
| 358 | return; | ||
| 359 | } | ||
| 360 | |||
| 361 | av_frames.push(std::move(filter_frame)); | ||
| 362 | } | ||
| 363 | } | ||
| 364 | while (av_frames.size() > 10) { | ||
| 276 | LOG_TRACE(Service_NVDRV, "av_frames.push overflow dropped frame"); | 365 | LOG_TRACE(Service_NVDRV, "av_frames.push overflow dropped frame"); |
| 277 | av_frames.pop(); | 366 | av_frames.pop(); |
| 278 | } | 367 | } |
diff --git a/src/video_core/host1x/codecs/codec.h b/src/video_core/host1x/codecs/codec.h index 0d45fb7fe..06fe00a4b 100644 --- a/src/video_core/host1x/codecs/codec.h +++ b/src/video_core/host1x/codecs/codec.h | |||
| @@ -15,6 +15,7 @@ extern "C" { | |||
| 15 | #pragma GCC diagnostic ignored "-Wconversion" | 15 | #pragma GCC diagnostic ignored "-Wconversion" |
| 16 | #endif | 16 | #endif |
| 17 | #include <libavcodec/avcodec.h> | 17 | #include <libavcodec/avcodec.h> |
| 18 | #include <libavfilter/avfilter.h> | ||
| 18 | #if defined(__GNUC__) || defined(__clang__) | 19 | #if defined(__GNUC__) || defined(__clang__) |
| 19 | #pragma GCC diagnostic pop | 20 | #pragma GCC diagnostic pop |
| 20 | #endif | 21 | #endif |
| @@ -61,17 +62,24 @@ public: | |||
| 61 | private: | 62 | private: |
| 62 | void InitializeAvCodecContext(); | 63 | void InitializeAvCodecContext(); |
| 63 | 64 | ||
| 65 | void InitializeAvFilters(AVFrame* frame); | ||
| 66 | |||
| 64 | void InitializeGpuDecoder(); | 67 | void InitializeGpuDecoder(); |
| 65 | 68 | ||
| 66 | bool CreateGpuAvDevice(); | 69 | bool CreateGpuAvDevice(); |
| 67 | 70 | ||
| 68 | bool initialized{}; | 71 | bool initialized{}; |
| 72 | bool filters_initialized{}; | ||
| 69 | Host1x::NvdecCommon::VideoCodec current_codec{Host1x::NvdecCommon::VideoCodec::None}; | 73 | Host1x::NvdecCommon::VideoCodec current_codec{Host1x::NvdecCommon::VideoCodec::None}; |
| 70 | 74 | ||
| 71 | const AVCodec* av_codec{nullptr}; | 75 | const AVCodec* av_codec{nullptr}; |
| 72 | AVCodecContext* av_codec_ctx{nullptr}; | 76 | AVCodecContext* av_codec_ctx{nullptr}; |
| 73 | AVBufferRef* av_gpu_decoder{nullptr}; | 77 | AVBufferRef* av_gpu_decoder{nullptr}; |
| 74 | 78 | ||
| 79 | AVFilterContext* av_filter_src_ctx{nullptr}; | ||
| 80 | AVFilterContext* av_filter_sink_ctx{nullptr}; | ||
| 81 | AVFilterGraph* av_filter_graph{nullptr}; | ||
| 82 | |||
| 75 | Host1x::Host1x& host1x; | 83 | Host1x::Host1x& host1x; |
| 76 | const Host1x::NvdecCommon::NvdecRegisters& state; | 84 | const Host1x::NvdecCommon::NvdecRegisters& state; |
| 77 | std::unique_ptr<Decoder::H264> h264_decoder; | 85 | std::unique_ptr<Decoder::H264> h264_decoder; |
diff --git a/src/video_core/renderer_opengl/gl_buffer_cache.cpp b/src/video_core/renderer_opengl/gl_buffer_cache.cpp index 6af4ae793..6d3bda192 100644 --- a/src/video_core/renderer_opengl/gl_buffer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_buffer_cache.cpp | |||
| @@ -117,7 +117,7 @@ BufferCacheRuntime::BufferCacheRuntime(const Device& device_) | |||
| 117 | for (auto& stage_uniforms : fast_uniforms) { | 117 | for (auto& stage_uniforms : fast_uniforms) { |
| 118 | for (OGLBuffer& buffer : stage_uniforms) { | 118 | for (OGLBuffer& buffer : stage_uniforms) { |
| 119 | buffer.Create(); | 119 | buffer.Create(); |
| 120 | glNamedBufferData(buffer.handle, BufferCache::DEFAULT_SKIP_CACHE_SIZE, nullptr, | 120 | glNamedBufferData(buffer.handle, VideoCommon::DEFAULT_SKIP_CACHE_SIZE, nullptr, |
| 121 | GL_STREAM_DRAW); | 121 | GL_STREAM_DRAW); |
| 122 | } | 122 | } |
| 123 | } | 123 | } |
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index 1e0823836..56d0ff869 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -439,6 +439,11 @@ OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_form | |||
| 439 | return GL_R32UI; | 439 | return GL_R32UI; |
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | [[nodiscard]] bool IsAstcRecompressionEnabled() { | ||
| 443 | return Settings::values.astc_recompression.GetValue() != | ||
| 444 | Settings::AstcRecompression::Uncompressed; | ||
| 445 | } | ||
| 446 | |||
| 442 | [[nodiscard]] GLenum SelectAstcFormat(PixelFormat format, bool is_srgb) { | 447 | [[nodiscard]] GLenum SelectAstcFormat(PixelFormat format, bool is_srgb) { |
| 443 | switch (Settings::values.astc_recompression.GetValue()) { | 448 | switch (Settings::values.astc_recompression.GetValue()) { |
| 444 | case Settings::AstcRecompression::Bc1: | 449 | case Settings::AstcRecompression::Bc1: |
| @@ -760,7 +765,7 @@ Image::Image(TextureCacheRuntime& runtime_, const VideoCommon::ImageInfo& info_, | |||
| 760 | gl_format = GL_RGBA; | 765 | gl_format = GL_RGBA; |
| 761 | gl_type = GL_UNSIGNED_INT_8_8_8_8_REV; | 766 | gl_type = GL_UNSIGNED_INT_8_8_8_8_REV; |
| 762 | 767 | ||
| 763 | if (IsPixelFormatASTC(info.format)) { | 768 | if (IsPixelFormatASTC(info.format) && IsAstcRecompressionEnabled()) { |
| 764 | gl_internal_format = SelectAstcFormat(info.format, is_srgb); | 769 | gl_internal_format = SelectAstcFormat(info.format, is_srgb); |
| 765 | gl_format = GL_NONE; | 770 | gl_format = GL_NONE; |
| 766 | } | 771 | } |
| @@ -1155,7 +1160,7 @@ ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::ImageViewI | |||
| 1155 | const bool is_srgb = IsPixelFormatSRGB(info.format); | 1160 | const bool is_srgb = IsPixelFormatSRGB(info.format); |
| 1156 | internal_format = is_srgb ? GL_SRGB8_ALPHA8 : GL_RGBA8; | 1161 | internal_format = is_srgb ? GL_SRGB8_ALPHA8 : GL_RGBA8; |
| 1157 | 1162 | ||
| 1158 | if (IsPixelFormatASTC(info.format)) { | 1163 | if (IsPixelFormatASTC(info.format) && IsAstcRecompressionEnabled()) { |
| 1159 | internal_format = SelectAstcFormat(info.format, is_srgb); | 1164 | internal_format = SelectAstcFormat(info.format, is_srgb); |
| 1160 | } | 1165 | } |
| 1161 | } else { | 1166 | } else { |
diff --git a/src/video_core/renderer_vulkan/vk_master_semaphore.cpp b/src/video_core/renderer_vulkan/vk_master_semaphore.cpp index 8b65aeaeb..b128c4f6e 100644 --- a/src/video_core/renderer_vulkan/vk_master_semaphore.cpp +++ b/src/video_core/renderer_vulkan/vk_master_semaphore.cpp | |||
| @@ -128,15 +128,12 @@ VkResult MasterSemaphore::SubmitQueueTimeline(vk::CommandBuffer& cmdbuf, | |||
| 128 | const std::array signal_values{host_tick, u64(0)}; | 128 | const std::array signal_values{host_tick, u64(0)}; |
| 129 | const std::array signal_semaphores{timeline_semaphore, signal_semaphore}; | 129 | const std::array signal_semaphores{timeline_semaphore, signal_semaphore}; |
| 130 | 130 | ||
| 131 | const u32 num_wait_semaphores = wait_semaphore ? 2 : 1; | 131 | const u32 num_wait_semaphores = wait_semaphore ? 1 : 0; |
| 132 | const std::array wait_values{host_tick - 1, u64(1)}; | ||
| 133 | const std::array wait_semaphores{timeline_semaphore, wait_semaphore}; | ||
| 134 | |||
| 135 | const VkTimelineSemaphoreSubmitInfo timeline_si{ | 132 | const VkTimelineSemaphoreSubmitInfo timeline_si{ |
| 136 | .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO, | 133 | .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO, |
| 137 | .pNext = nullptr, | 134 | .pNext = nullptr, |
| 138 | .waitSemaphoreValueCount = num_wait_semaphores, | 135 | .waitSemaphoreValueCount = 0, |
| 139 | .pWaitSemaphoreValues = wait_values.data(), | 136 | .pWaitSemaphoreValues = nullptr, |
| 140 | .signalSemaphoreValueCount = num_signal_semaphores, | 137 | .signalSemaphoreValueCount = num_signal_semaphores, |
| 141 | .pSignalSemaphoreValues = signal_values.data(), | 138 | .pSignalSemaphoreValues = signal_values.data(), |
| 142 | }; | 139 | }; |
| @@ -144,7 +141,7 @@ VkResult MasterSemaphore::SubmitQueueTimeline(vk::CommandBuffer& cmdbuf, | |||
| 144 | .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, | 141 | .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, |
| 145 | .pNext = &timeline_si, | 142 | .pNext = &timeline_si, |
| 146 | .waitSemaphoreCount = num_wait_semaphores, | 143 | .waitSemaphoreCount = num_wait_semaphores, |
| 147 | .pWaitSemaphores = wait_semaphores.data(), | 144 | .pWaitSemaphores = &wait_semaphore, |
| 148 | .pWaitDstStageMask = wait_stage_masks.data(), | 145 | .pWaitDstStageMask = wait_stage_masks.data(), |
| 149 | .commandBufferCount = 1, | 146 | .commandBufferCount = 1, |
| 150 | .pCommandBuffers = cmdbuf.address(), | 147 | .pCommandBuffers = cmdbuf.address(), |
diff --git a/src/video_core/texture_cache/image_base.cpp b/src/video_core/texture_cache/image_base.cpp index 91512022f..d79594ce5 100644 --- a/src/video_core/texture_cache/image_base.cpp +++ b/src/video_core/texture_cache/image_base.cpp | |||
| @@ -155,7 +155,7 @@ void ImageBase::CheckAliasState() { | |||
| 155 | flags &= ~ImageFlagBits::Alias; | 155 | flags &= ~ImageFlagBits::Alias; |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | void AddImageAlias(ImageBase& lhs, ImageBase& rhs, ImageId lhs_id, ImageId rhs_id) { | 158 | bool AddImageAlias(ImageBase& lhs, ImageBase& rhs, ImageId lhs_id, ImageId rhs_id) { |
| 159 | static constexpr auto OPTIONS = RelaxedOptions::Size | RelaxedOptions::Format; | 159 | static constexpr auto OPTIONS = RelaxedOptions::Size | RelaxedOptions::Format; |
| 160 | ASSERT(lhs.info.type == rhs.info.type); | 160 | ASSERT(lhs.info.type == rhs.info.type); |
| 161 | std::optional<SubresourceBase> base; | 161 | std::optional<SubresourceBase> base; |
| @@ -169,7 +169,7 @@ void AddImageAlias(ImageBase& lhs, ImageBase& rhs, ImageId lhs_id, ImageId rhs_i | |||
| 169 | } | 169 | } |
| 170 | if (!base) { | 170 | if (!base) { |
| 171 | LOG_ERROR(HW_GPU, "Image alias should have been flipped"); | 171 | LOG_ERROR(HW_GPU, "Image alias should have been flipped"); |
| 172 | return; | 172 | return false; |
| 173 | } | 173 | } |
| 174 | const PixelFormat lhs_format = lhs.info.format; | 174 | const PixelFormat lhs_format = lhs.info.format; |
| 175 | const PixelFormat rhs_format = rhs.info.format; | 175 | const PixelFormat rhs_format = rhs.info.format; |
| @@ -248,12 +248,13 @@ void AddImageAlias(ImageBase& lhs, ImageBase& rhs, ImageId lhs_id, ImageId rhs_i | |||
| 248 | } | 248 | } |
| 249 | ASSERT(lhs_alias.copies.empty() == rhs_alias.copies.empty()); | 249 | ASSERT(lhs_alias.copies.empty() == rhs_alias.copies.empty()); |
| 250 | if (lhs_alias.copies.empty()) { | 250 | if (lhs_alias.copies.empty()) { |
| 251 | return; | 251 | return false; |
| 252 | } | 252 | } |
| 253 | lhs.aliased_images.push_back(std::move(lhs_alias)); | 253 | lhs.aliased_images.push_back(std::move(lhs_alias)); |
| 254 | rhs.aliased_images.push_back(std::move(rhs_alias)); | 254 | rhs.aliased_images.push_back(std::move(rhs_alias)); |
| 255 | lhs.flags &= ~ImageFlagBits::IsRescalable; | 255 | lhs.flags &= ~ImageFlagBits::IsRescalable; |
| 256 | rhs.flags &= ~ImageFlagBits::IsRescalable; | 256 | rhs.flags &= ~ImageFlagBits::IsRescalable; |
| 257 | return true; | ||
| 257 | } | 258 | } |
| 258 | 259 | ||
| 259 | } // namespace VideoCommon | 260 | } // namespace VideoCommon |
diff --git a/src/video_core/texture_cache/image_base.h b/src/video_core/texture_cache/image_base.h index 329396bb6..1b8a17ee8 100644 --- a/src/video_core/texture_cache/image_base.h +++ b/src/video_core/texture_cache/image_base.h | |||
| @@ -142,6 +142,6 @@ struct ImageAllocBase { | |||
| 142 | std::vector<ImageId> images; | 142 | std::vector<ImageId> images; |
| 143 | }; | 143 | }; |
| 144 | 144 | ||
| 145 | void AddImageAlias(ImageBase& lhs, ImageBase& rhs, ImageId lhs_id, ImageId rhs_id); | 145 | bool AddImageAlias(ImageBase& lhs, ImageBase& rhs, ImageId lhs_id, ImageId rhs_id); |
| 146 | 146 | ||
| 147 | } // namespace VideoCommon | 147 | } // namespace VideoCommon |
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 9790949f5..2cf082c5d 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -139,7 +139,6 @@ void TextureCache<P>::TickFrame() { | |||
| 139 | TickAsyncDecode(); | 139 | TickAsyncDecode(); |
| 140 | 140 | ||
| 141 | runtime.TickFrame(); | 141 | runtime.TickFrame(); |
| 142 | critical_gc = 0; | ||
| 143 | ++frame_tick; | 142 | ++frame_tick; |
| 144 | 143 | ||
| 145 | if constexpr (IMPLEMENTS_ASYNC_DOWNLOADS) { | 144 | if constexpr (IMPLEMENTS_ASYNC_DOWNLOADS) { |
| @@ -1312,17 +1311,18 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA | |||
| 1312 | const size_t size_bytes = CalculateGuestSizeInBytes(new_info); | 1311 | const size_t size_bytes = CalculateGuestSizeInBytes(new_info); |
| 1313 | const bool broken_views = runtime.HasBrokenTextureViewFormats(); | 1312 | const bool broken_views = runtime.HasBrokenTextureViewFormats(); |
| 1314 | const bool native_bgr = runtime.HasNativeBgr(); | 1313 | const bool native_bgr = runtime.HasNativeBgr(); |
| 1315 | boost::container::small_vector<ImageId, 4> overlap_ids; | 1314 | join_overlap_ids.clear(); |
| 1316 | std::unordered_set<ImageId> overlaps_found; | 1315 | join_overlaps_found.clear(); |
| 1317 | boost::container::small_vector<ImageId, 4> left_aliased_ids; | 1316 | join_left_aliased_ids.clear(); |
| 1318 | boost::container::small_vector<ImageId, 4> right_aliased_ids; | 1317 | join_right_aliased_ids.clear(); |
| 1319 | std::unordered_set<ImageId> ignore_textures; | 1318 | join_ignore_textures.clear(); |
| 1320 | boost::container::small_vector<ImageId, 4> bad_overlap_ids; | 1319 | join_bad_overlap_ids.clear(); |
| 1321 | boost::container::small_vector<ImageId, 4> all_siblings; | 1320 | join_copies_to_do.clear(); |
| 1321 | join_alias_indices.clear(); | ||
| 1322 | const bool this_is_linear = info.type == ImageType::Linear; | 1322 | const bool this_is_linear = info.type == ImageType::Linear; |
| 1323 | const auto region_check = [&](ImageId overlap_id, ImageBase& overlap) { | 1323 | const auto region_check = [&](ImageId overlap_id, ImageBase& overlap) { |
| 1324 | if (True(overlap.flags & ImageFlagBits::Remapped)) { | 1324 | if (True(overlap.flags & ImageFlagBits::Remapped)) { |
| 1325 | ignore_textures.insert(overlap_id); | 1325 | join_ignore_textures.insert(overlap_id); |
| 1326 | return; | 1326 | return; |
| 1327 | } | 1327 | } |
| 1328 | const bool overlap_is_linear = overlap.info.type == ImageType::Linear; | 1328 | const bool overlap_is_linear = overlap.info.type == ImageType::Linear; |
| @@ -1332,11 +1332,11 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA | |||
| 1332 | if (this_is_linear && overlap_is_linear) { | 1332 | if (this_is_linear && overlap_is_linear) { |
| 1333 | if (info.pitch == overlap.info.pitch && gpu_addr == overlap.gpu_addr) { | 1333 | if (info.pitch == overlap.info.pitch && gpu_addr == overlap.gpu_addr) { |
| 1334 | // Alias linear images with the same pitch | 1334 | // Alias linear images with the same pitch |
| 1335 | left_aliased_ids.push_back(overlap_id); | 1335 | join_left_aliased_ids.push_back(overlap_id); |
| 1336 | } | 1336 | } |
| 1337 | return; | 1337 | return; |
| 1338 | } | 1338 | } |
| 1339 | overlaps_found.insert(overlap_id); | 1339 | join_overlaps_found.insert(overlap_id); |
| 1340 | static constexpr bool strict_size = true; | 1340 | static constexpr bool strict_size = true; |
| 1341 | const std::optional<OverlapResult> solution = ResolveOverlap( | 1341 | const std::optional<OverlapResult> solution = ResolveOverlap( |
| 1342 | new_info, gpu_addr, cpu_addr, overlap, strict_size, broken_views, native_bgr); | 1342 | new_info, gpu_addr, cpu_addr, overlap, strict_size, broken_views, native_bgr); |
| @@ -1344,33 +1344,33 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA | |||
| 1344 | gpu_addr = solution->gpu_addr; | 1344 | gpu_addr = solution->gpu_addr; |
| 1345 | cpu_addr = solution->cpu_addr; | 1345 | cpu_addr = solution->cpu_addr; |
| 1346 | new_info.resources = solution->resources; | 1346 | new_info.resources = solution->resources; |
| 1347 | overlap_ids.push_back(overlap_id); | 1347 | join_overlap_ids.push_back(overlap_id); |
| 1348 | all_siblings.push_back(overlap_id); | 1348 | join_copies_to_do.emplace_back(JoinCopy{false, overlap_id}); |
| 1349 | return; | 1349 | return; |
| 1350 | } | 1350 | } |
| 1351 | static constexpr auto options = RelaxedOptions::Size | RelaxedOptions::Format; | 1351 | static constexpr auto options = RelaxedOptions::Size | RelaxedOptions::Format; |
| 1352 | const ImageBase new_image_base(new_info, gpu_addr, cpu_addr); | 1352 | const ImageBase new_image_base(new_info, gpu_addr, cpu_addr); |
| 1353 | if (IsSubresource(new_info, overlap, gpu_addr, options, broken_views, native_bgr)) { | 1353 | if (IsSubresource(new_info, overlap, gpu_addr, options, broken_views, native_bgr)) { |
| 1354 | left_aliased_ids.push_back(overlap_id); | 1354 | join_left_aliased_ids.push_back(overlap_id); |
| 1355 | overlap.flags |= ImageFlagBits::Alias; | 1355 | overlap.flags |= ImageFlagBits::Alias; |
| 1356 | all_siblings.push_back(overlap_id); | 1356 | join_copies_to_do.emplace_back(JoinCopy{true, overlap_id}); |
| 1357 | } else if (IsSubresource(overlap.info, new_image_base, overlap.gpu_addr, options, | 1357 | } else if (IsSubresource(overlap.info, new_image_base, overlap.gpu_addr, options, |
| 1358 | broken_views, native_bgr)) { | 1358 | broken_views, native_bgr)) { |
| 1359 | right_aliased_ids.push_back(overlap_id); | 1359 | join_right_aliased_ids.push_back(overlap_id); |
| 1360 | overlap.flags |= ImageFlagBits::Alias; | 1360 | overlap.flags |= ImageFlagBits::Alias; |
| 1361 | all_siblings.push_back(overlap_id); | 1361 | join_copies_to_do.emplace_back(JoinCopy{true, overlap_id}); |
| 1362 | } else { | 1362 | } else { |
| 1363 | bad_overlap_ids.push_back(overlap_id); | 1363 | join_bad_overlap_ids.push_back(overlap_id); |
| 1364 | } | 1364 | } |
| 1365 | }; | 1365 | }; |
| 1366 | ForEachImageInRegion(cpu_addr, size_bytes, region_check); | 1366 | ForEachImageInRegion(cpu_addr, size_bytes, region_check); |
| 1367 | const auto region_check_gpu = [&](ImageId overlap_id, ImageBase& overlap) { | 1367 | const auto region_check_gpu = [&](ImageId overlap_id, ImageBase& overlap) { |
| 1368 | if (!overlaps_found.contains(overlap_id)) { | 1368 | if (!join_overlaps_found.contains(overlap_id)) { |
| 1369 | if (True(overlap.flags & ImageFlagBits::Remapped)) { | 1369 | if (True(overlap.flags & ImageFlagBits::Remapped)) { |
| 1370 | ignore_textures.insert(overlap_id); | 1370 | join_ignore_textures.insert(overlap_id); |
| 1371 | } | 1371 | } |
| 1372 | if (overlap.gpu_addr == gpu_addr && overlap.guest_size_bytes == size_bytes) { | 1372 | if (overlap.gpu_addr == gpu_addr && overlap.guest_size_bytes == size_bytes) { |
| 1373 | ignore_textures.insert(overlap_id); | 1373 | join_ignore_textures.insert(overlap_id); |
| 1374 | } | 1374 | } |
| 1375 | } | 1375 | } |
| 1376 | }; | 1376 | }; |
| @@ -1378,11 +1378,11 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA | |||
| 1378 | 1378 | ||
| 1379 | bool can_rescale = info.rescaleable; | 1379 | bool can_rescale = info.rescaleable; |
| 1380 | bool any_rescaled = false; | 1380 | bool any_rescaled = false; |
| 1381 | for (const ImageId sibling_id : all_siblings) { | 1381 | for (const auto& copy : join_copies_to_do) { |
| 1382 | if (!can_rescale) { | 1382 | if (!can_rescale) { |
| 1383 | break; | 1383 | break; |
| 1384 | } | 1384 | } |
| 1385 | Image& sibling = slot_images[sibling_id]; | 1385 | Image& sibling = slot_images[copy.id]; |
| 1386 | can_rescale &= ImageCanRescale(sibling); | 1386 | can_rescale &= ImageCanRescale(sibling); |
| 1387 | any_rescaled |= True(sibling.flags & ImageFlagBits::Rescaled); | 1387 | any_rescaled |= True(sibling.flags & ImageFlagBits::Rescaled); |
| 1388 | } | 1388 | } |
| @@ -1390,13 +1390,13 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA | |||
| 1390 | can_rescale &= any_rescaled; | 1390 | can_rescale &= any_rescaled; |
| 1391 | 1391 | ||
| 1392 | if (can_rescale) { | 1392 | if (can_rescale) { |
| 1393 | for (const ImageId sibling_id : all_siblings) { | 1393 | for (const auto& copy : join_copies_to_do) { |
| 1394 | Image& sibling = slot_images[sibling_id]; | 1394 | Image& sibling = slot_images[copy.id]; |
| 1395 | ScaleUp(sibling); | 1395 | ScaleUp(sibling); |
| 1396 | } | 1396 | } |
| 1397 | } else { | 1397 | } else { |
| 1398 | for (const ImageId sibling_id : all_siblings) { | 1398 | for (const auto& copy : join_copies_to_do) { |
| 1399 | Image& sibling = slot_images[sibling_id]; | 1399 | Image& sibling = slot_images[copy.id]; |
| 1400 | ScaleDown(sibling); | 1400 | ScaleDown(sibling); |
| 1401 | } | 1401 | } |
| 1402 | } | 1402 | } |
| @@ -1408,7 +1408,7 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA | |||
| 1408 | new_image.flags |= ImageFlagBits::Sparse; | 1408 | new_image.flags |= ImageFlagBits::Sparse; |
| 1409 | } | 1409 | } |
| 1410 | 1410 | ||
| 1411 | for (const ImageId overlap_id : ignore_textures) { | 1411 | for (const ImageId overlap_id : join_ignore_textures) { |
| 1412 | Image& overlap = slot_images[overlap_id]; | 1412 | Image& overlap = slot_images[overlap_id]; |
| 1413 | if (True(overlap.flags & ImageFlagBits::GpuModified)) { | 1413 | if (True(overlap.flags & ImageFlagBits::GpuModified)) { |
| 1414 | UNIMPLEMENTED(); | 1414 | UNIMPLEMENTED(); |
| @@ -1429,14 +1429,60 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA | |||
| 1429 | ScaleDown(new_image); | 1429 | ScaleDown(new_image); |
| 1430 | } | 1430 | } |
| 1431 | 1431 | ||
| 1432 | std::ranges::sort(overlap_ids, [this](const ImageId lhs, const ImageId rhs) { | 1432 | std::ranges::sort(join_copies_to_do, [this](const JoinCopy& lhs, const JoinCopy& rhs) { |
| 1433 | const ImageBase& lhs_image = slot_images[lhs]; | 1433 | const ImageBase& lhs_image = slot_images[lhs.id]; |
| 1434 | const ImageBase& rhs_image = slot_images[rhs]; | 1434 | const ImageBase& rhs_image = slot_images[rhs.id]; |
| 1435 | return lhs_image.modification_tick < rhs_image.modification_tick; | 1435 | return lhs_image.modification_tick < rhs_image.modification_tick; |
| 1436 | }); | 1436 | }); |
| 1437 | 1437 | ||
| 1438 | for (const ImageId overlap_id : overlap_ids) { | 1438 | ImageBase& new_image_base = new_image; |
| 1439 | Image& overlap = slot_images[overlap_id]; | 1439 | for (const ImageId aliased_id : join_right_aliased_ids) { |
| 1440 | ImageBase& aliased = slot_images[aliased_id]; | ||
| 1441 | size_t alias_index = new_image_base.aliased_images.size(); | ||
| 1442 | if (!AddImageAlias(new_image_base, aliased, new_image_id, aliased_id)) { | ||
| 1443 | continue; | ||
| 1444 | } | ||
| 1445 | join_alias_indices.emplace(aliased_id, alias_index); | ||
| 1446 | new_image.flags |= ImageFlagBits::Alias; | ||
| 1447 | } | ||
| 1448 | for (const ImageId aliased_id : join_left_aliased_ids) { | ||
| 1449 | ImageBase& aliased = slot_images[aliased_id]; | ||
| 1450 | size_t alias_index = new_image_base.aliased_images.size(); | ||
| 1451 | if (!AddImageAlias(aliased, new_image_base, aliased_id, new_image_id)) { | ||
| 1452 | continue; | ||
| 1453 | } | ||
| 1454 | join_alias_indices.emplace(aliased_id, alias_index); | ||
| 1455 | new_image.flags |= ImageFlagBits::Alias; | ||
| 1456 | } | ||
| 1457 | for (const ImageId aliased_id : join_bad_overlap_ids) { | ||
| 1458 | ImageBase& aliased = slot_images[aliased_id]; | ||
| 1459 | aliased.overlapping_images.push_back(new_image_id); | ||
| 1460 | new_image.overlapping_images.push_back(aliased_id); | ||
| 1461 | if (aliased.info.resources.levels == 1 && aliased.info.block.depth == 0 && | ||
| 1462 | aliased.overlapping_images.size() > 1) { | ||
| 1463 | aliased.flags |= ImageFlagBits::BadOverlap; | ||
| 1464 | } | ||
| 1465 | if (new_image.info.resources.levels == 1 && new_image.info.block.depth == 0 && | ||
| 1466 | new_image.overlapping_images.size() > 1) { | ||
| 1467 | new_image.flags |= ImageFlagBits::BadOverlap; | ||
| 1468 | } | ||
| 1469 | } | ||
| 1470 | |||
| 1471 | for (const auto& copy_object : join_copies_to_do) { | ||
| 1472 | Image& overlap = slot_images[copy_object.id]; | ||
| 1473 | if (copy_object.is_alias) { | ||
| 1474 | if (!overlap.IsSafeDownload()) { | ||
| 1475 | continue; | ||
| 1476 | } | ||
| 1477 | const auto alias_pointer = join_alias_indices.find(copy_object.id); | ||
| 1478 | if (alias_pointer == join_alias_indices.end()) { | ||
| 1479 | continue; | ||
| 1480 | } | ||
| 1481 | const AliasedImage& aliased = new_image.aliased_images[alias_pointer->second]; | ||
| 1482 | CopyImage(new_image_id, aliased.id, aliased.copies); | ||
| 1483 | new_image.modification_tick = overlap.modification_tick; | ||
| 1484 | continue; | ||
| 1485 | } | ||
| 1440 | if (True(overlap.flags & ImageFlagBits::GpuModified)) { | 1486 | if (True(overlap.flags & ImageFlagBits::GpuModified)) { |
| 1441 | new_image.flags |= ImageFlagBits::GpuModified; | 1487 | new_image.flags |= ImageFlagBits::GpuModified; |
| 1442 | const auto& resolution = Settings::values.resolution_info; | 1488 | const auto& resolution = Settings::values.resolution_info; |
| @@ -1449,35 +1495,15 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA | |||
| 1449 | } else { | 1495 | } else { |
| 1450 | runtime.CopyImage(new_image, overlap, std::move(copies)); | 1496 | runtime.CopyImage(new_image, overlap, std::move(copies)); |
| 1451 | } | 1497 | } |
| 1498 | new_image.modification_tick = overlap.modification_tick; | ||
| 1452 | } | 1499 | } |
| 1453 | if (True(overlap.flags & ImageFlagBits::Tracked)) { | 1500 | if (True(overlap.flags & ImageFlagBits::Tracked)) { |
| 1454 | UntrackImage(overlap, overlap_id); | 1501 | UntrackImage(overlap, copy_object.id); |
| 1455 | } | ||
| 1456 | UnregisterImage(overlap_id); | ||
| 1457 | DeleteImage(overlap_id); | ||
| 1458 | } | ||
| 1459 | ImageBase& new_image_base = new_image; | ||
| 1460 | for (const ImageId aliased_id : right_aliased_ids) { | ||
| 1461 | ImageBase& aliased = slot_images[aliased_id]; | ||
| 1462 | AddImageAlias(new_image_base, aliased, new_image_id, aliased_id); | ||
| 1463 | new_image.flags |= ImageFlagBits::Alias; | ||
| 1464 | } | ||
| 1465 | for (const ImageId aliased_id : left_aliased_ids) { | ||
| 1466 | ImageBase& aliased = slot_images[aliased_id]; | ||
| 1467 | AddImageAlias(aliased, new_image_base, aliased_id, new_image_id); | ||
| 1468 | new_image.flags |= ImageFlagBits::Alias; | ||
| 1469 | } | ||
| 1470 | for (const ImageId aliased_id : bad_overlap_ids) { | ||
| 1471 | ImageBase& aliased = slot_images[aliased_id]; | ||
| 1472 | aliased.overlapping_images.push_back(new_image_id); | ||
| 1473 | new_image.overlapping_images.push_back(aliased_id); | ||
| 1474 | if (aliased.info.resources.levels == 1 && aliased.overlapping_images.size() > 1) { | ||
| 1475 | aliased.flags |= ImageFlagBits::BadOverlap; | ||
| 1476 | } | ||
| 1477 | if (new_image.info.resources.levels == 1 && new_image.overlapping_images.size() > 1) { | ||
| 1478 | new_image.flags |= ImageFlagBits::BadOverlap; | ||
| 1479 | } | 1502 | } |
| 1503 | UnregisterImage(copy_object.id); | ||
| 1504 | DeleteImage(copy_object.id); | ||
| 1480 | } | 1505 | } |
| 1506 | |||
| 1481 | RegisterImage(new_image_id); | 1507 | RegisterImage(new_image_id); |
| 1482 | return new_image_id; | 1508 | return new_image_id; |
| 1483 | } | 1509 | } |
| @@ -1507,7 +1533,7 @@ std::optional<typename TextureCache<P>::BlitImages> TextureCache<P>::GetBlitImag | |||
| 1507 | if (!copy.must_accelerate) { | 1533 | if (!copy.must_accelerate) { |
| 1508 | do { | 1534 | do { |
| 1509 | if (!src_id && !dst_id) { | 1535 | if (!src_id && !dst_id) { |
| 1510 | break; | 1536 | return std::nullopt; |
| 1511 | } | 1537 | } |
| 1512 | if (src_id && True(slot_images[src_id].flags & ImageFlagBits::GpuModified)) { | 1538 | if (src_id && True(slot_images[src_id].flags & ImageFlagBits::GpuModified)) { |
| 1513 | break; | 1539 | break; |
| @@ -1885,10 +1911,6 @@ void TextureCache<P>::RegisterImage(ImageId image_id) { | |||
| 1885 | tentative_size = EstimatedDecompressedSize(tentative_size, image.info.format); | 1911 | tentative_size = EstimatedDecompressedSize(tentative_size, image.info.format); |
| 1886 | } | 1912 | } |
| 1887 | total_used_memory += Common::AlignUp(tentative_size, 1024); | 1913 | total_used_memory += Common::AlignUp(tentative_size, 1024); |
| 1888 | if (total_used_memory > critical_memory && critical_gc < GC_EMERGENCY_COUNTS) { | ||
| 1889 | RunGarbageCollector(); | ||
| 1890 | critical_gc++; | ||
| 1891 | } | ||
| 1892 | image.lru_index = lru_cache.Insert(image_id, frame_tick); | 1914 | image.lru_index = lru_cache.Insert(image_id, frame_tick); |
| 1893 | 1915 | ||
| 1894 | ForEachGPUPage(image.gpu_addr, image.guest_size_bytes, [this, image_id](u64 page) { | 1916 | ForEachGPUPage(image.gpu_addr, image.guest_size_bytes, [this, image_id](u64 page) { |
diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index 1a3308e2d..3bfa92154 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h | |||
| @@ -10,7 +10,9 @@ | |||
| 10 | #include <span> | 10 | #include <span> |
| 11 | #include <type_traits> | 11 | #include <type_traits> |
| 12 | #include <unordered_map> | 12 | #include <unordered_map> |
| 13 | #include <unordered_set> | ||
| 13 | #include <vector> | 14 | #include <vector> |
| 15 | #include <boost/container/small_vector.hpp> | ||
| 14 | #include <queue> | 16 | #include <queue> |
| 15 | 17 | ||
| 16 | #include "common/common_types.h" | 18 | #include "common/common_types.h" |
| @@ -427,7 +429,6 @@ private: | |||
| 427 | u64 minimum_memory; | 429 | u64 minimum_memory; |
| 428 | u64 expected_memory; | 430 | u64 expected_memory; |
| 429 | u64 critical_memory; | 431 | u64 critical_memory; |
| 430 | size_t critical_gc; | ||
| 431 | 432 | ||
| 432 | struct BufferDownload { | 433 | struct BufferDownload { |
| 433 | GPUVAddr address; | 434 | GPUVAddr address; |
| @@ -477,6 +478,20 @@ private: | |||
| 477 | 478 | ||
| 478 | Common::ThreadWorker texture_decode_worker{1, "TextureDecoder"}; | 479 | Common::ThreadWorker texture_decode_worker{1, "TextureDecoder"}; |
| 479 | std::vector<std::unique_ptr<AsyncDecodeContext>> async_decodes; | 480 | std::vector<std::unique_ptr<AsyncDecodeContext>> async_decodes; |
| 481 | |||
| 482 | // Join caching | ||
| 483 | boost::container::small_vector<ImageId, 4> join_overlap_ids; | ||
| 484 | std::unordered_set<ImageId> join_overlaps_found; | ||
| 485 | boost::container::small_vector<ImageId, 4> join_left_aliased_ids; | ||
| 486 | boost::container::small_vector<ImageId, 4> join_right_aliased_ids; | ||
| 487 | std::unordered_set<ImageId> join_ignore_textures; | ||
| 488 | boost::container::small_vector<ImageId, 4> join_bad_overlap_ids; | ||
| 489 | struct JoinCopy { | ||
| 490 | bool is_alias; | ||
| 491 | ImageId id; | ||
| 492 | }; | ||
| 493 | boost::container::small_vector<JoinCopy, 4> join_copies_to_do; | ||
| 494 | std::unordered_map<ImageId, size_t> join_alias_indices; | ||
| 480 | }; | 495 | }; |
| 481 | 496 | ||
| 482 | } // namespace VideoCommon | 497 | } // namespace VideoCommon |
diff --git a/src/video_core/texture_cache/util.cpp b/src/video_core/texture_cache/util.cpp index 1463f157b..95a5b47d8 100644 --- a/src/video_core/texture_cache/util.cpp +++ b/src/video_core/texture_cache/util.cpp | |||
| @@ -123,7 +123,9 @@ template <u32 GOB_EXTENT> | |||
| 123 | return { | 123 | return { |
| 124 | .width = AdjustMipBlockSize<GOB_SIZE_X>(num_tiles.width, block_size.width, level), | 124 | .width = AdjustMipBlockSize<GOB_SIZE_X>(num_tiles.width, block_size.width, level), |
| 125 | .height = AdjustMipBlockSize<GOB_SIZE_Y>(num_tiles.height, block_size.height, level), | 125 | .height = AdjustMipBlockSize<GOB_SIZE_Y>(num_tiles.height, block_size.height, level), |
| 126 | .depth = AdjustMipBlockSize<GOB_SIZE_Z>(num_tiles.depth, block_size.depth, level), | 126 | .depth = level == 0 |
| 127 | ? block_size.depth | ||
| 128 | : AdjustMipBlockSize<GOB_SIZE_Z>(num_tiles.depth, block_size.depth, level), | ||
| 127 | }; | 129 | }; |
| 128 | } | 130 | } |
| 129 | 131 | ||
| @@ -165,6 +167,13 @@ template <u32 GOB_EXTENT> | |||
| 165 | } | 167 | } |
| 166 | 168 | ||
| 167 | [[nodiscard]] constexpr Extent3D TileShift(const LevelInfo& info, u32 level) { | 169 | [[nodiscard]] constexpr Extent3D TileShift(const LevelInfo& info, u32 level) { |
| 170 | if (level == 0) { | ||
| 171 | return Extent3D{ | ||
| 172 | .width = info.block.width, | ||
| 173 | .height = info.block.height, | ||
| 174 | .depth = info.block.depth, | ||
| 175 | }; | ||
| 176 | } | ||
| 168 | const Extent3D blocks = NumLevelBlocks(info, level); | 177 | const Extent3D blocks = NumLevelBlocks(info, level); |
| 169 | return Extent3D{ | 178 | return Extent3D{ |
| 170 | .width = AdjustTileSize(info.block.width, GOB_SIZE_X, blocks.width), | 179 | .width = AdjustTileSize(info.block.width, GOB_SIZE_X, blocks.width), |
| @@ -1288,7 +1297,9 @@ u32 MapSizeBytes(const ImageBase& image) { | |||
| 1288 | 1297 | ||
| 1289 | static_assert(CalculateLevelSize(LevelInfo{{1920, 1080, 1}, {0, 2, 0}, {1, 1}, 2, 0}, 0) == | 1298 | static_assert(CalculateLevelSize(LevelInfo{{1920, 1080, 1}, {0, 2, 0}, {1, 1}, 2, 0}, 0) == |
| 1290 | 0x7f8000); | 1299 | 0x7f8000); |
| 1291 | static_assert(CalculateLevelSize(LevelInfo{{32, 32, 1}, {0, 0, 4}, {1, 1}, 4, 0}, 0) == 0x4000); | 1300 | static_assert(CalculateLevelSize(LevelInfo{{32, 32, 1}, {0, 0, 4}, {1, 1}, 4, 0}, 0) == 0x40000); |
| 1301 | |||
| 1302 | static_assert(CalculateLevelSize(LevelInfo{{128, 8, 1}, {0, 4, 0}, {1, 1}, 4, 0}, 0) == 0x40000); | ||
| 1292 | 1303 | ||
| 1293 | static_assert(CalculateLevelOffset(PixelFormat::R8_SINT, {1920, 1080, 1}, {0, 2, 0}, 0, 7) == | 1304 | static_assert(CalculateLevelOffset(PixelFormat::R8_SINT, {1920, 1080, 1}, {0, 2, 0}, 0, 7) == |
| 1294 | 0x2afc00); | 1305 | 0x2afc00); |
diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp index 3a7c2dedf..aea677cb3 100644 --- a/src/video_core/vulkan_common/vulkan_device.cpp +++ b/src/video_core/vulkan_common/vulkan_device.cpp | |||
| @@ -473,11 +473,12 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR | |||
| 473 | } | 473 | } |
| 474 | if (extensions.push_descriptor && is_intel_anv) { | 474 | if (extensions.push_descriptor && is_intel_anv) { |
| 475 | const u32 version = (properties.properties.driverVersion << 3) >> 3; | 475 | const u32 version = (properties.properties.driverVersion << 3) >> 3; |
| 476 | if (version >= VK_MAKE_API_VERSION(0, 22, 3, 0)) { | 476 | if (version >= VK_MAKE_API_VERSION(0, 22, 3, 0) && |
| 477 | version < VK_MAKE_API_VERSION(0, 23, 2, 0)) { | ||
| 477 | // Disable VK_KHR_push_descriptor due to | 478 | // Disable VK_KHR_push_descriptor due to |
| 478 | // mesa/mesa/-/commit/ff91c5ca42bc80aa411cb3fd8f550aa6fdd16bdc | 479 | // mesa/mesa/-/commit/ff91c5ca42bc80aa411cb3fd8f550aa6fdd16bdc |
| 479 | LOG_WARNING(Render_Vulkan, | 480 | LOG_WARNING(Render_Vulkan, |
| 480 | "ANV drivers 22.3.0 and later have broken VK_KHR_push_descriptor"); | 481 | "ANV drivers 22.3.0 to 23.1.0 have broken VK_KHR_push_descriptor"); |
| 481 | extensions.push_descriptor = false; | 482 | extensions.push_descriptor = false; |
| 482 | loaded_extensions.erase(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); | 483 | loaded_extensions.erase(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); |
| 483 | } | 484 | } |
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 2d7b9ab65..84d9ca796 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt | |||
| @@ -378,11 +378,7 @@ if(UNIX AND NOT APPLE) | |||
| 378 | endif() | 378 | endif() |
| 379 | 379 | ||
| 380 | if (WIN32 AND QT_VERSION VERSION_GREATER_EQUAL 6) | 380 | if (WIN32 AND QT_VERSION VERSION_GREATER_EQUAL 6) |
| 381 | if (MSVC AND NOT ${CMAKE_GENERATOR} STREQUAL "Ninja") | 381 | set(YUZU_EXE_DIR "$<TARGET_FILE_DIR:yuzu>") |
| 382 | set(YUZU_EXE_DIR "${CMAKE_BINARY_DIR}/bin/$<CONFIG>") | ||
| 383 | else() | ||
| 384 | set(YUZU_EXE_DIR "${CMAKE_BINARY_DIR}/bin") | ||
| 385 | endif() | ||
| 386 | add_custom_command(TARGET yuzu POST_BUILD COMMAND ${WINDEPLOYQT_EXECUTABLE} "${YUZU_EXE_DIR}/yuzu.exe" --dir "${YUZU_EXE_DIR}" --libdir "${YUZU_EXE_DIR}" --plugindir "${YUZU_EXE_DIR}/plugins" --no-compiler-runtime --no-opengl-sw --no-system-d3d-compiler --no-translations --verbose 0) | 382 | add_custom_command(TARGET yuzu POST_BUILD COMMAND ${WINDEPLOYQT_EXECUTABLE} "${YUZU_EXE_DIR}/yuzu.exe" --dir "${YUZU_EXE_DIR}" --libdir "${YUZU_EXE_DIR}" --plugindir "${YUZU_EXE_DIR}/plugins" --no-compiler-runtime --no-opengl-sw --no-system-d3d-compiler --no-translations --verbose 0) |
| 387 | endif() | 383 | endif() |
| 388 | 384 | ||
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 662651196..6288fef62 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -65,6 +65,42 @@ const std::array<int, 2> Config::default_ringcon_analogs{{ | |||
| 65 | Qt::Key_D, | 65 | Qt::Key_D, |
| 66 | }}; | 66 | }}; |
| 67 | 67 | ||
| 68 | const std::map<Settings::AntiAliasing, QString> Config::anti_aliasing_texts_map = { | ||
| 69 | {Settings::AntiAliasing::None, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "None"))}, | ||
| 70 | {Settings::AntiAliasing::Fxaa, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "FXAA"))}, | ||
| 71 | {Settings::AntiAliasing::Smaa, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "SMAA"))}, | ||
| 72 | }; | ||
| 73 | |||
| 74 | const std::map<Settings::ScalingFilter, QString> Config::scaling_filter_texts_map = { | ||
| 75 | {Settings::ScalingFilter::NearestNeighbor, | ||
| 76 | QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Nearest"))}, | ||
| 77 | {Settings::ScalingFilter::Bilinear, | ||
| 78 | QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Bilinear"))}, | ||
| 79 | {Settings::ScalingFilter::Bicubic, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Bicubic"))}, | ||
| 80 | {Settings::ScalingFilter::Gaussian, | ||
| 81 | QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Gaussian"))}, | ||
| 82 | {Settings::ScalingFilter::ScaleForce, | ||
| 83 | QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "ScaleForce"))}, | ||
| 84 | {Settings::ScalingFilter::Fsr, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "FSR"))}, | ||
| 85 | }; | ||
| 86 | |||
| 87 | const std::map<bool, QString> Config::use_docked_mode_texts_map = { | ||
| 88 | {true, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Docked"))}, | ||
| 89 | {false, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Handheld"))}, | ||
| 90 | }; | ||
| 91 | |||
| 92 | const std::map<Settings::GPUAccuracy, QString> Config::gpu_accuracy_texts_map = { | ||
| 93 | {Settings::GPUAccuracy::Normal, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Normal"))}, | ||
| 94 | {Settings::GPUAccuracy::High, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "High"))}, | ||
| 95 | {Settings::GPUAccuracy::Extreme, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Extreme"))}, | ||
| 96 | }; | ||
| 97 | |||
| 98 | const std::map<Settings::RendererBackend, QString> Config::renderer_backend_texts_map = { | ||
| 99 | {Settings::RendererBackend::Vulkan, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Vulkan"))}, | ||
| 100 | {Settings::RendererBackend::OpenGL, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "OpenGL"))}, | ||
| 101 | {Settings::RendererBackend::Null, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "Null"))}, | ||
| 102 | }; | ||
| 103 | |||
| 68 | // This shouldn't have anything except static initializers (no functions). So | 104 | // This shouldn't have anything except static initializers (no functions). So |
| 69 | // QKeySequence(...).toString() is NOT ALLOWED HERE. | 105 | // QKeySequence(...).toString() is NOT ALLOWED HERE. |
| 70 | // This must be in alphabetical order according to action name as it must have the same order as | 106 | // This must be in alphabetical order according to action name as it must have the same order as |
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 9cb9db6cf..ad590ea9e 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h | |||
| @@ -49,6 +49,12 @@ public: | |||
| 49 | static const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> default_keyboard_mods; | 49 | static const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> default_keyboard_mods; |
| 50 | static const std::array<UISettings::Shortcut, 22> default_hotkeys; | 50 | static const std::array<UISettings::Shortcut, 22> default_hotkeys; |
| 51 | 51 | ||
| 52 | static const std::map<Settings::AntiAliasing, QString> anti_aliasing_texts_map; | ||
| 53 | static const std::map<Settings::ScalingFilter, QString> scaling_filter_texts_map; | ||
| 54 | static const std::map<bool, QString> use_docked_mode_texts_map; | ||
| 55 | static const std::map<Settings::GPUAccuracy, QString> gpu_accuracy_texts_map; | ||
| 56 | static const std::map<Settings::RendererBackend, QString> renderer_backend_texts_map; | ||
| 57 | |||
| 52 | static constexpr UISettings::Theme default_theme{ | 58 | static constexpr UISettings::Theme default_theme{ |
| 53 | #ifdef _WIN32 | 59 | #ifdef _WIN32 |
| 54 | UISettings::Theme::DarkColorful | 60 | UISettings::Theme::DarkColorful |
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index c21828b1d..465084fea 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -544,6 +544,7 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri | |||
| 544 | QAction* remove_update = remove_menu->addAction(tr("Remove Installed Update")); | 544 | QAction* remove_update = remove_menu->addAction(tr("Remove Installed Update")); |
| 545 | QAction* remove_dlc = remove_menu->addAction(tr("Remove All Installed DLC")); | 545 | QAction* remove_dlc = remove_menu->addAction(tr("Remove All Installed DLC")); |
| 546 | QAction* remove_custom_config = remove_menu->addAction(tr("Remove Custom Configuration")); | 546 | QAction* remove_custom_config = remove_menu->addAction(tr("Remove Custom Configuration")); |
| 547 | QAction* remove_cache_storage = remove_menu->addAction(tr("Remove Cache Storage")); | ||
| 547 | QAction* remove_gl_shader_cache = remove_menu->addAction(tr("Remove OpenGL Pipeline Cache")); | 548 | QAction* remove_gl_shader_cache = remove_menu->addAction(tr("Remove OpenGL Pipeline Cache")); |
| 548 | QAction* remove_vk_shader_cache = remove_menu->addAction(tr("Remove Vulkan Pipeline Cache")); | 549 | QAction* remove_vk_shader_cache = remove_menu->addAction(tr("Remove Vulkan Pipeline Cache")); |
| 549 | remove_menu->addSeparator(); | 550 | remove_menu->addSeparator(); |
| @@ -614,6 +615,9 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri | |||
| 614 | connect(remove_custom_config, &QAction::triggered, [this, program_id, path]() { | 615 | connect(remove_custom_config, &QAction::triggered, [this, program_id, path]() { |
| 615 | emit RemoveFileRequested(program_id, GameListRemoveTarget::CustomConfiguration, path); | 616 | emit RemoveFileRequested(program_id, GameListRemoveTarget::CustomConfiguration, path); |
| 616 | }); | 617 | }); |
| 618 | connect(remove_cache_storage, &QAction::triggered, [this, program_id, path] { | ||
| 619 | emit RemoveFileRequested(program_id, GameListRemoveTarget::CacheStorage, path); | ||
| 620 | }); | ||
| 617 | connect(dump_romfs, &QAction::triggered, [this, program_id, path]() { | 621 | connect(dump_romfs, &QAction::triggered, [this, program_id, path]() { |
| 618 | emit DumpRomFSRequested(program_id, path, DumpRomFSTarget::Normal); | 622 | emit DumpRomFSRequested(program_id, path, DumpRomFSTarget::Normal); |
| 619 | }); | 623 | }); |
diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h index 64e5af4c1..6c2f75e53 100644 --- a/src/yuzu/game_list.h +++ b/src/yuzu/game_list.h | |||
| @@ -45,6 +45,7 @@ enum class GameListRemoveTarget { | |||
| 45 | VkShaderCache, | 45 | VkShaderCache, |
| 46 | AllShaderCache, | 46 | AllShaderCache, |
| 47 | CustomConfiguration, | 47 | CustomConfiguration, |
| 48 | CacheStorage, | ||
| 48 | }; | 49 | }; |
| 49 | 50 | ||
| 50 | enum class DumpRomFSTarget { | 51 | enum class DumpRomFSTarget { |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 4489f43af..82bce9a3a 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -1054,6 +1054,24 @@ void GMainWindow::InitializeWidgets() { | |||
| 1054 | bottomLeft.setY(bottomLeft.y() - volume_popup->geometry().height()); | 1054 | bottomLeft.setY(bottomLeft.y() - volume_popup->geometry().height()); |
| 1055 | volume_popup->setGeometry(QRect(bottomLeft, QSize(rect.width(), rect.height()))); | 1055 | volume_popup->setGeometry(QRect(bottomLeft, QSize(rect.width(), rect.height()))); |
| 1056 | }); | 1056 | }); |
| 1057 | volume_button->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 1058 | connect(volume_button, &QPushButton::customContextMenuRequested, | ||
| 1059 | [this](const QPoint& menu_location) { | ||
| 1060 | QMenu context_menu; | ||
| 1061 | context_menu.addAction( | ||
| 1062 | Settings::values.audio_muted ? tr("Unmute") : tr("Mute"), [this] { | ||
| 1063 | Settings::values.audio_muted = !Settings::values.audio_muted; | ||
| 1064 | UpdateVolumeUI(); | ||
| 1065 | }); | ||
| 1066 | |||
| 1067 | context_menu.addAction(tr("Reset Volume"), [this] { | ||
| 1068 | Settings::values.volume.SetValue(100); | ||
| 1069 | UpdateVolumeUI(); | ||
| 1070 | }); | ||
| 1071 | |||
| 1072 | context_menu.exec(volume_button->mapToGlobal(menu_location)); | ||
| 1073 | volume_button->repaint(); | ||
| 1074 | }); | ||
| 1057 | statusBar()->insertPermanentWidget(0, volume_button); | 1075 | statusBar()->insertPermanentWidget(0, volume_button); |
| 1058 | 1076 | ||
| 1059 | // setup AA button | 1077 | // setup AA button |
| @@ -1074,6 +1092,19 @@ void GMainWindow::InitializeWidgets() { | |||
| 1074 | UpdateAAText(); | 1092 | UpdateAAText(); |
| 1075 | aa_status_button->setCheckable(true); | 1093 | aa_status_button->setCheckable(true); |
| 1076 | aa_status_button->setChecked(true); | 1094 | aa_status_button->setChecked(true); |
| 1095 | aa_status_button->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 1096 | connect(aa_status_button, &QPushButton::customContextMenuRequested, | ||
| 1097 | [this](const QPoint& menu_location) { | ||
| 1098 | QMenu context_menu; | ||
| 1099 | for (auto const& aa_text_pair : Config::anti_aliasing_texts_map) { | ||
| 1100 | context_menu.addAction(aa_text_pair.second, [this, aa_text_pair] { | ||
| 1101 | Settings::values.anti_aliasing.SetValue(aa_text_pair.first); | ||
| 1102 | UpdateAAText(); | ||
| 1103 | }); | ||
| 1104 | } | ||
| 1105 | context_menu.exec(aa_status_button->mapToGlobal(menu_location)); | ||
| 1106 | aa_status_button->repaint(); | ||
| 1107 | }); | ||
| 1077 | statusBar()->insertPermanentWidget(0, aa_status_button); | 1108 | statusBar()->insertPermanentWidget(0, aa_status_button); |
| 1078 | 1109 | ||
| 1079 | // Setup Filter button | 1110 | // Setup Filter button |
| @@ -1085,6 +1116,19 @@ void GMainWindow::InitializeWidgets() { | |||
| 1085 | UpdateFilterText(); | 1116 | UpdateFilterText(); |
| 1086 | filter_status_button->setCheckable(true); | 1117 | filter_status_button->setCheckable(true); |
| 1087 | filter_status_button->setChecked(true); | 1118 | filter_status_button->setChecked(true); |
| 1119 | filter_status_button->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 1120 | connect(filter_status_button, &QPushButton::customContextMenuRequested, | ||
| 1121 | [this](const QPoint& menu_location) { | ||
| 1122 | QMenu context_menu; | ||
| 1123 | for (auto const& filter_text_pair : Config::scaling_filter_texts_map) { | ||
| 1124 | context_menu.addAction(filter_text_pair.second, [this, filter_text_pair] { | ||
| 1125 | Settings::values.scaling_filter.SetValue(filter_text_pair.first); | ||
| 1126 | UpdateFilterText(); | ||
| 1127 | }); | ||
| 1128 | } | ||
| 1129 | context_menu.exec(filter_status_button->mapToGlobal(menu_location)); | ||
| 1130 | filter_status_button->repaint(); | ||
| 1131 | }); | ||
| 1088 | statusBar()->insertPermanentWidget(0, filter_status_button); | 1132 | statusBar()->insertPermanentWidget(0, filter_status_button); |
| 1089 | 1133 | ||
| 1090 | // Setup Dock button | 1134 | // Setup Dock button |
| @@ -1094,14 +1138,47 @@ void GMainWindow::InitializeWidgets() { | |||
| 1094 | connect(dock_status_button, &QPushButton::clicked, this, &GMainWindow::OnToggleDockedMode); | 1138 | connect(dock_status_button, &QPushButton::clicked, this, &GMainWindow::OnToggleDockedMode); |
| 1095 | dock_status_button->setCheckable(true); | 1139 | dock_status_button->setCheckable(true); |
| 1096 | UpdateDockedButton(); | 1140 | UpdateDockedButton(); |
| 1141 | dock_status_button->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 1142 | connect(dock_status_button, &QPushButton::customContextMenuRequested, | ||
| 1143 | [this](const QPoint& menu_location) { | ||
| 1144 | QMenu context_menu; | ||
| 1145 | |||
| 1146 | for (auto const& docked_mode_pair : Config::use_docked_mode_texts_map) { | ||
| 1147 | context_menu.addAction(docked_mode_pair.second, [this, docked_mode_pair] { | ||
| 1148 | if (docked_mode_pair.first != Settings::values.use_docked_mode.GetValue()) { | ||
| 1149 | OnToggleDockedMode(); | ||
| 1150 | } | ||
| 1151 | }); | ||
| 1152 | } | ||
| 1153 | context_menu.exec(dock_status_button->mapToGlobal(menu_location)); | ||
| 1154 | dock_status_button->repaint(); | ||
| 1155 | }); | ||
| 1097 | statusBar()->insertPermanentWidget(0, dock_status_button); | 1156 | statusBar()->insertPermanentWidget(0, dock_status_button); |
| 1098 | 1157 | ||
| 1158 | // Setup GPU Accuracy button | ||
| 1099 | gpu_accuracy_button = new QPushButton(); | 1159 | gpu_accuracy_button = new QPushButton(); |
| 1100 | gpu_accuracy_button->setObjectName(QStringLiteral("GPUStatusBarButton")); | 1160 | gpu_accuracy_button->setObjectName(QStringLiteral("GPUStatusBarButton")); |
| 1101 | gpu_accuracy_button->setCheckable(true); | 1161 | gpu_accuracy_button->setCheckable(true); |
| 1102 | gpu_accuracy_button->setFocusPolicy(Qt::NoFocus); | 1162 | gpu_accuracy_button->setFocusPolicy(Qt::NoFocus); |
| 1103 | connect(gpu_accuracy_button, &QPushButton::clicked, this, &GMainWindow::OnToggleGpuAccuracy); | 1163 | connect(gpu_accuracy_button, &QPushButton::clicked, this, &GMainWindow::OnToggleGpuAccuracy); |
| 1104 | UpdateGPUAccuracyButton(); | 1164 | UpdateGPUAccuracyButton(); |
| 1165 | gpu_accuracy_button->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 1166 | connect(gpu_accuracy_button, &QPushButton::customContextMenuRequested, | ||
| 1167 | [this](const QPoint& menu_location) { | ||
| 1168 | QMenu context_menu; | ||
| 1169 | |||
| 1170 | for (auto const& gpu_accuracy_pair : Config::gpu_accuracy_texts_map) { | ||
| 1171 | if (gpu_accuracy_pair.first == Settings::GPUAccuracy::Extreme) { | ||
| 1172 | continue; | ||
| 1173 | } | ||
| 1174 | context_menu.addAction(gpu_accuracy_pair.second, [this, gpu_accuracy_pair] { | ||
| 1175 | Settings::values.gpu_accuracy.SetValue(gpu_accuracy_pair.first); | ||
| 1176 | UpdateGPUAccuracyButton(); | ||
| 1177 | }); | ||
| 1178 | } | ||
| 1179 | context_menu.exec(gpu_accuracy_button->mapToGlobal(menu_location)); | ||
| 1180 | gpu_accuracy_button->repaint(); | ||
| 1181 | }); | ||
| 1105 | statusBar()->insertPermanentWidget(0, gpu_accuracy_button); | 1182 | statusBar()->insertPermanentWidget(0, gpu_accuracy_button); |
| 1106 | 1183 | ||
| 1107 | // Setup Renderer API button | 1184 | // Setup Renderer API button |
| @@ -1114,6 +1191,24 @@ void GMainWindow::InitializeWidgets() { | |||
| 1114 | renderer_status_button->setCheckable(true); | 1191 | renderer_status_button->setCheckable(true); |
| 1115 | renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() == | 1192 | renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() == |
| 1116 | Settings::RendererBackend::Vulkan); | 1193 | Settings::RendererBackend::Vulkan); |
| 1194 | renderer_status_button->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 1195 | connect(renderer_status_button, &QPushButton::customContextMenuRequested, | ||
| 1196 | [this](const QPoint& menu_location) { | ||
| 1197 | QMenu context_menu; | ||
| 1198 | |||
| 1199 | for (auto const& renderer_backend_pair : Config::renderer_backend_texts_map) { | ||
| 1200 | if (renderer_backend_pair.first == Settings::RendererBackend::Null) { | ||
| 1201 | continue; | ||
| 1202 | } | ||
| 1203 | context_menu.addAction( | ||
| 1204 | renderer_backend_pair.second, [this, renderer_backend_pair] { | ||
| 1205 | Settings::values.renderer_backend.SetValue(renderer_backend_pair.first); | ||
| 1206 | UpdateAPIText(); | ||
| 1207 | }); | ||
| 1208 | } | ||
| 1209 | context_menu.exec(renderer_status_button->mapToGlobal(menu_location)); | ||
| 1210 | renderer_status_button->repaint(); | ||
| 1211 | }); | ||
| 1117 | statusBar()->insertPermanentWidget(0, renderer_status_button); | 1212 | statusBar()->insertPermanentWidget(0, renderer_status_button); |
| 1118 | 1213 | ||
| 1119 | statusBar()->setVisible(true); | 1214 | statusBar()->setVisible(true); |
| @@ -1798,6 +1893,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t | |||
| 1798 | } | 1893 | } |
| 1799 | 1894 | ||
| 1800 | system->SetShuttingDown(false); | 1895 | system->SetShuttingDown(false); |
| 1896 | game_list->setDisabled(true); | ||
| 1801 | 1897 | ||
| 1802 | // Create and start the emulation thread | 1898 | // Create and start the emulation thread |
| 1803 | emu_thread = std::make_unique<EmuThread>(*system); | 1899 | emu_thread = std::make_unique<EmuThread>(*system); |
| @@ -1993,6 +2089,9 @@ void GMainWindow::OnEmulationStopped() { | |||
| 1993 | // When closing the game, destroy the GLWindow to clear the context after the game is closed | 2089 | // When closing the game, destroy the GLWindow to clear the context after the game is closed |
| 1994 | render_window->ReleaseRenderTarget(); | 2090 | render_window->ReleaseRenderTarget(); |
| 1995 | 2091 | ||
| 2092 | // Enable game list | ||
| 2093 | game_list->setEnabled(true); | ||
| 2094 | |||
| 1996 | Settings::RestoreGlobalState(system->IsPoweredOn()); | 2095 | Settings::RestoreGlobalState(system->IsPoweredOn()); |
| 1997 | system->HIDCore().ReloadInputDevices(); | 2096 | system->HIDCore().ReloadInputDevices(); |
| 1998 | UpdateStatusButtons(); | 2097 | UpdateStatusButtons(); |
| @@ -2323,6 +2422,8 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ | |||
| 2323 | return tr("Delete All Transferable Shader Caches?"); | 2422 | return tr("Delete All Transferable Shader Caches?"); |
| 2324 | case GameListRemoveTarget::CustomConfiguration: | 2423 | case GameListRemoveTarget::CustomConfiguration: |
| 2325 | return tr("Remove Custom Game Configuration?"); | 2424 | return tr("Remove Custom Game Configuration?"); |
| 2425 | case GameListRemoveTarget::CacheStorage: | ||
| 2426 | return tr("Remove Cache Storage?"); | ||
| 2326 | default: | 2427 | default: |
| 2327 | return QString{}; | 2428 | return QString{}; |
| 2328 | } | 2429 | } |
| @@ -2346,6 +2447,9 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ | |||
| 2346 | case GameListRemoveTarget::CustomConfiguration: | 2447 | case GameListRemoveTarget::CustomConfiguration: |
| 2347 | RemoveCustomConfiguration(program_id, game_path); | 2448 | RemoveCustomConfiguration(program_id, game_path); |
| 2348 | break; | 2449 | break; |
| 2450 | case GameListRemoveTarget::CacheStorage: | ||
| 2451 | RemoveCacheStorage(program_id); | ||
| 2452 | break; | ||
| 2349 | } | 2453 | } |
| 2350 | } | 2454 | } |
| 2351 | 2455 | ||
| @@ -2435,6 +2539,21 @@ void GMainWindow::RemoveCustomConfiguration(u64 program_id, const std::string& g | |||
| 2435 | } | 2539 | } |
| 2436 | } | 2540 | } |
| 2437 | 2541 | ||
| 2542 | void GMainWindow::RemoveCacheStorage(u64 program_id) { | ||
| 2543 | const auto nand_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir); | ||
| 2544 | auto vfs_nand_dir = | ||
| 2545 | vfs->OpenDirectory(Common::FS::PathToUTF8String(nand_dir), FileSys::Mode::Read); | ||
| 2546 | |||
| 2547 | const auto cache_storage_path = FileSys::SaveDataFactory::GetFullPath( | ||
| 2548 | *system, vfs_nand_dir, FileSys::SaveDataSpaceId::NandUser, | ||
| 2549 | FileSys::SaveDataType::CacheStorage, 0 /* program_id */, {}, 0); | ||
| 2550 | |||
| 2551 | const auto path = Common::FS::ConcatPathSafe(nand_dir, cache_storage_path); | ||
| 2552 | |||
| 2553 | // Not an error if it wasn't cleared. | ||
| 2554 | Common::FS::RemoveDirRecursively(path); | ||
| 2555 | } | ||
| 2556 | |||
| 2438 | void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_path, | 2557 | void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_path, |
| 2439 | DumpRomFSTarget target) { | 2558 | DumpRomFSTarget target) { |
| 2440 | const auto failed = [this] { | 2559 | const auto failed = [this] { |
| @@ -3980,94 +4099,38 @@ void GMainWindow::UpdateStatusBar() { | |||
| 3980 | } | 4099 | } |
| 3981 | 4100 | ||
| 3982 | void GMainWindow::UpdateGPUAccuracyButton() { | 4101 | void GMainWindow::UpdateGPUAccuracyButton() { |
| 3983 | switch (Settings::values.gpu_accuracy.GetValue()) { | 4102 | const auto gpu_accuracy = Settings::values.gpu_accuracy.GetValue(); |
| 3984 | case Settings::GPUAccuracy::Normal: { | 4103 | const auto gpu_accuracy_text = Config::gpu_accuracy_texts_map.find(gpu_accuracy)->second; |
| 3985 | gpu_accuracy_button->setText(tr("GPU NORMAL")); | 4104 | gpu_accuracy_button->setText(gpu_accuracy_text.toUpper()); |
| 3986 | gpu_accuracy_button->setChecked(false); | 4105 | gpu_accuracy_button->setChecked(gpu_accuracy != Settings::GPUAccuracy::Normal); |
| 3987 | break; | ||
| 3988 | } | ||
| 3989 | case Settings::GPUAccuracy::High: { | ||
| 3990 | gpu_accuracy_button->setText(tr("GPU HIGH")); | ||
| 3991 | gpu_accuracy_button->setChecked(true); | ||
| 3992 | break; | ||
| 3993 | } | ||
| 3994 | case Settings::GPUAccuracy::Extreme: { | ||
| 3995 | gpu_accuracy_button->setText(tr("GPU EXTREME")); | ||
| 3996 | gpu_accuracy_button->setChecked(true); | ||
| 3997 | break; | ||
| 3998 | } | ||
| 3999 | default: { | ||
| 4000 | gpu_accuracy_button->setText(tr("GPU ERROR")); | ||
| 4001 | gpu_accuracy_button->setChecked(true); | ||
| 4002 | break; | ||
| 4003 | } | ||
| 4004 | } | ||
| 4005 | } | 4106 | } |
| 4006 | 4107 | ||
| 4007 | void GMainWindow::UpdateDockedButton() { | 4108 | void GMainWindow::UpdateDockedButton() { |
| 4008 | const bool is_docked = Settings::values.use_docked_mode.GetValue(); | 4109 | const bool is_docked = Settings::values.use_docked_mode.GetValue(); |
| 4009 | dock_status_button->setChecked(is_docked); | 4110 | dock_status_button->setChecked(is_docked); |
| 4010 | dock_status_button->setText(is_docked ? tr("DOCKED") : tr("HANDHELD")); | 4111 | dock_status_button->setText( |
| 4112 | Config::use_docked_mode_texts_map.find(is_docked)->second.toUpper()); | ||
| 4011 | } | 4113 | } |
| 4012 | 4114 | ||
| 4013 | void GMainWindow::UpdateAPIText() { | 4115 | void GMainWindow::UpdateAPIText() { |
| 4014 | const auto api = Settings::values.renderer_backend.GetValue(); | 4116 | const auto api = Settings::values.renderer_backend.GetValue(); |
| 4015 | switch (api) { | 4117 | const auto renderer_status_text = Config::renderer_backend_texts_map.find(api)->second; |
| 4016 | case Settings::RendererBackend::OpenGL: | 4118 | renderer_status_button->setText(renderer_status_text.toUpper()); |
| 4017 | renderer_status_button->setText(tr("OPENGL")); | ||
| 4018 | break; | ||
| 4019 | case Settings::RendererBackend::Vulkan: | ||
| 4020 | renderer_status_button->setText(tr("VULKAN")); | ||
| 4021 | break; | ||
| 4022 | case Settings::RendererBackend::Null: | ||
| 4023 | renderer_status_button->setText(tr("NULL")); | ||
| 4024 | break; | ||
| 4025 | } | ||
| 4026 | } | 4119 | } |
| 4027 | 4120 | ||
| 4028 | void GMainWindow::UpdateFilterText() { | 4121 | void GMainWindow::UpdateFilterText() { |
| 4029 | const auto filter = Settings::values.scaling_filter.GetValue(); | 4122 | const auto filter = Settings::values.scaling_filter.GetValue(); |
| 4030 | switch (filter) { | 4123 | const auto filter_text = Config::scaling_filter_texts_map.find(filter)->second; |
| 4031 | case Settings::ScalingFilter::NearestNeighbor: | 4124 | filter_status_button->setText(filter == Settings::ScalingFilter::Fsr ? tr("FSR") |
| 4032 | filter_status_button->setText(tr("NEAREST")); | 4125 | : filter_text.toUpper()); |
| 4033 | break; | ||
| 4034 | case Settings::ScalingFilter::Bilinear: | ||
| 4035 | filter_status_button->setText(tr("BILINEAR")); | ||
| 4036 | break; | ||
| 4037 | case Settings::ScalingFilter::Bicubic: | ||
| 4038 | filter_status_button->setText(tr("BICUBIC")); | ||
| 4039 | break; | ||
| 4040 | case Settings::ScalingFilter::Gaussian: | ||
| 4041 | filter_status_button->setText(tr("GAUSSIAN")); | ||
| 4042 | break; | ||
| 4043 | case Settings::ScalingFilter::ScaleForce: | ||
| 4044 | filter_status_button->setText(tr("SCALEFORCE")); | ||
| 4045 | break; | ||
| 4046 | case Settings::ScalingFilter::Fsr: | ||
| 4047 | filter_status_button->setText(tr("FSR")); | ||
| 4048 | break; | ||
| 4049 | default: | ||
| 4050 | filter_status_button->setText(tr("BILINEAR")); | ||
| 4051 | break; | ||
| 4052 | } | ||
| 4053 | } | 4126 | } |
| 4054 | 4127 | ||
| 4055 | void GMainWindow::UpdateAAText() { | 4128 | void GMainWindow::UpdateAAText() { |
| 4056 | const auto aa_mode = Settings::values.anti_aliasing.GetValue(); | 4129 | const auto aa_mode = Settings::values.anti_aliasing.GetValue(); |
| 4057 | switch (aa_mode) { | 4130 | const auto aa_text = Config::anti_aliasing_texts_map.find(aa_mode)->second; |
| 4058 | case Settings::AntiAliasing::None: | 4131 | aa_status_button->setText(aa_mode == Settings::AntiAliasing::None |
| 4059 | aa_status_button->setText(tr("NO AA")); | 4132 | ? QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "NO AA")) |
| 4060 | break; | 4133 | : aa_text.toUpper()); |
| 4061 | case Settings::AntiAliasing::Fxaa: | ||
| 4062 | aa_status_button->setText(tr("FXAA")); | ||
| 4063 | break; | ||
| 4064 | case Settings::AntiAliasing::Smaa: | ||
| 4065 | aa_status_button->setText(tr("SMAA")); | ||
| 4066 | break; | ||
| 4067 | default: | ||
| 4068 | aa_status_button->setText(tr("NO AA")); | ||
| 4069 | break; | ||
| 4070 | } | ||
| 4071 | } | 4134 | } |
| 4072 | 4135 | ||
| 4073 | void GMainWindow::UpdateVolumeUI() { | 4136 | void GMainWindow::UpdateVolumeUI() { |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 17631a2d9..6bb70972f 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -370,6 +370,7 @@ private: | |||
| 370 | void RemoveVulkanDriverPipelineCache(u64 program_id); | 370 | void RemoveVulkanDriverPipelineCache(u64 program_id); |
| 371 | void RemoveAllTransferableShaderCaches(u64 program_id); | 371 | void RemoveAllTransferableShaderCaches(u64 program_id); |
| 372 | void RemoveCustomConfiguration(u64 program_id, const std::string& game_path); | 372 | void RemoveCustomConfiguration(u64 program_id, const std::string& game_path); |
| 373 | void RemoveCacheStorage(u64 program_id); | ||
| 373 | std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); | 374 | std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); |
| 374 | InstallResult InstallNSPXCI(const QString& filename); | 375 | InstallResult InstallNSPXCI(const QString& filename); |
| 375 | InstallResult InstallNCA(const QString& filename); | 376 | InstallResult InstallNCA(const QString& filename); |
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 5f39ece32..7b6d49c63 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp | |||
| @@ -227,7 +227,7 @@ int main(int argc, char** argv) { | |||
| 227 | }; | 227 | }; |
| 228 | 228 | ||
| 229 | while (optind < argc) { | 229 | while (optind < argc) { |
| 230 | int arg = getopt_long(argc, argv, "g:fhvp::c:", long_options, &option_index); | 230 | int arg = getopt_long(argc, argv, "g:fhvp::c:u:", long_options, &option_index); |
| 231 | if (arg != -1) { | 231 | if (arg != -1) { |
| 232 | switch (static_cast<char>(arg)) { | 232 | switch (static_cast<char>(arg)) { |
| 233 | case 'c': | 233 | case 'c': |
| @@ -283,7 +283,7 @@ int main(int argc, char** argv) { | |||
| 283 | break; | 283 | break; |
| 284 | case 'u': | 284 | case 'u': |
| 285 | selected_user = atoi(optarg); | 285 | selected_user = atoi(optarg); |
| 286 | return 0; | 286 | break; |
| 287 | case 'v': | 287 | case 'v': |
| 288 | PrintVersion(); | 288 | PrintVersion(); |
| 289 | return 0; | 289 | return 0; |
diff --git a/vcpkg.json b/vcpkg.json index 19f99e89e..26f545c6c 100644 --- a/vcpkg.json +++ b/vcpkg.json | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | { | 1 | { |
| 2 | "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", | 2 | "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", |
| 3 | "name": "yuzu", | 3 | "name": "yuzu", |
| 4 | "builtin-baseline": "acc3bcf76b84ae5041c86ab55fe138ae7b8255c7", | 4 | "builtin-baseline": "656fcc6ab2b05c6d999b7eaca717027ac3738f71", |
| 5 | "version": "1.0", | 5 | "version": "1.0", |
| 6 | "dependencies": [ | 6 | "dependencies": [ |
| 7 | "boost-algorithm", | 7 | "boost-algorithm", |
| @@ -53,7 +53,7 @@ | |||
| 53 | }, | 53 | }, |
| 54 | { | 54 | { |
| 55 | "name": "fmt", | 55 | "name": "fmt", |
| 56 | "version": "9.0.0" | 56 | "version": "10.0.0" |
| 57 | } | 57 | } |
| 58 | ] | 58 | ] |
| 59 | } | 59 | } |