Compare commits
224 Commits
__refs_pul
...
__refs_pul
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28d9c30861 | ||
|
|
3392fdac9b | ||
|
|
9933121256 | ||
|
|
c6767704fb | ||
|
|
ea70d9c79e | ||
|
|
3e6850f00b | ||
|
|
cb7f0c2ec3 | ||
|
|
c86e21abe4 | ||
|
|
201733d1b5 | ||
|
|
db15142ac9 | ||
|
|
fa231645f2 | ||
|
|
646656412f | ||
|
|
99eccf581e | ||
|
|
80670a5b6c | ||
|
|
60ce34aa80 | ||
|
|
ae6015a69b | ||
|
|
053ad04d3f | ||
|
|
1b11e0f0d3 | ||
|
|
fe126f993d | ||
|
|
c6590ad07b | ||
|
|
9f199c8b0b | ||
|
|
6cb6b2da8e | ||
|
|
64869807e2 | ||
|
|
61e4f2d931 | ||
|
|
bdef22ff85 | ||
|
|
4bc2d82130 | ||
|
|
cfc34dd41d | ||
|
|
88ba5a7f22 | ||
|
|
e44d1fe73c | ||
|
|
b60a93a936 | ||
|
|
42d81aab32 | ||
|
|
864c8e4b2f | ||
|
|
690a4c9438 | ||
|
|
190ded7f48 | ||
|
|
c770f25ccb | ||
|
|
67c0d714c5 | ||
|
|
cf01a507fb | ||
|
|
fcc93a445f | ||
|
|
79f1f326c7 | ||
|
|
2724ffd6e3 | ||
|
|
ee71404d71 | ||
|
|
dcc8abf254 | ||
|
|
56b0f979eb | ||
|
|
c218c7d4da | ||
|
|
f999d268f9 | ||
|
|
c489cbee29 | ||
|
|
dffeca66fa | ||
|
|
fd1ea0fd84 | ||
|
|
48108a8c9b | ||
|
|
92ce241d4d | ||
|
|
d3123079e8 | ||
|
|
5da72a891f | ||
|
|
f8a7d6a0ae | ||
|
|
da31326c17 | ||
|
|
45672d43e3 | ||
|
|
a3bac5550d | ||
|
|
4faea2bbf4 | ||
|
|
fa10374d39 | ||
|
|
98135dee16 | ||
|
|
243404bf34 | ||
|
|
7bf4bec257 | ||
|
|
f7d95d0a3a | ||
|
|
bbb202ceed | ||
|
|
789da737af | ||
|
|
b541a35e27 | ||
|
|
6bc1a477bf | ||
|
|
9bfd4d880e | ||
|
|
6a56f42f5d | ||
|
|
b81caf1879 | ||
|
|
b1d633532f | ||
|
|
12c0f682e6 | ||
|
|
9ff891ce71 | ||
|
|
82d80869fc | ||
|
|
20cbf6f3db | ||
|
|
dca4f0687a | ||
|
|
b8c03411e7 | ||
|
|
3ff7a5de1a | ||
|
|
4447c9a46e | ||
|
|
e2f32e8c88 | ||
|
|
beba9c9b61 | ||
|
|
a222f02c7a | ||
|
|
0104e28fe4 | ||
|
|
c5f519e1e4 | ||
|
|
5a5bb91f40 | ||
|
|
4fce72c902 | ||
|
|
77b0d01639 | ||
|
|
18bdf45868 | ||
|
|
09e3029c11 | ||
|
|
2221afaf26 | ||
|
|
45fcde817e | ||
|
|
29fbce9fe6 | ||
|
|
5754456292 | ||
|
|
3cc3176ad6 | ||
|
|
d5f53da79d | ||
|
|
a4696285af | ||
|
|
179adee396 | ||
|
|
f44c60321e | ||
|
|
f6868ae4dd | ||
|
|
0ed80c9818 | ||
|
|
339a37f8cb | ||
|
|
da58eb6208 | ||
|
|
b32b9524ad | ||
|
|
3e1e6c66c0 | ||
|
|
8ef9075b1b | ||
|
|
0c531ff911 | ||
|
|
d5684dbe7d | ||
|
|
ed37192441 | ||
|
|
623429a27e | ||
|
|
456322dde6 | ||
|
|
821da3ed54 | ||
|
|
8d1d6e149f | ||
|
|
1085bbb0a3 | ||
|
|
a5bc86a9ac | ||
|
|
6982423931 | ||
|
|
e532b74e11 | ||
|
|
985ed1e160 | ||
|
|
f6e705737a | ||
|
|
66c4331de5 | ||
|
|
c586ac9be2 | ||
|
|
0e265db873 | ||
|
|
5b837157bd | ||
|
|
37014e9127 | ||
|
|
1e64b5e2ec | ||
|
|
15d63c3d3d | ||
|
|
41461514d6 | ||
|
|
bf0b957c05 | ||
|
|
bfdd512787 | ||
|
|
9704acb982 | ||
|
|
e1f5f4bdea | ||
|
|
08d4e7c7af | ||
|
|
4b7e73e0a6 | ||
|
|
d8534ea140 | ||
|
|
bbdb6d391e | ||
|
|
a86af1b776 | ||
|
|
131ed37803 | ||
|
|
a225ba4cda | ||
|
|
e86e144a7c | ||
|
|
99494e77c3 | ||
|
|
dba84458be | ||
|
|
bb3440f7c4 | ||
|
|
f385175aa2 | ||
|
|
7c68f93bdf | ||
|
|
04779b3d2a | ||
|
|
90145c424d | ||
|
|
7e7a23363a | ||
|
|
eadc1ae1e7 | ||
|
|
e7f9f58fa4 | ||
|
|
e6ae720c33 | ||
|
|
fedd857054 | ||
|
|
d8da9a2afd | ||
|
|
2b40cdf04f | ||
|
|
a84676c2aa | ||
|
|
e26c86a6e7 | ||
|
|
9bbb77637e | ||
|
|
bcf59ff3a7 | ||
|
|
e4a16f50ef | ||
|
|
87543b9dea | ||
|
|
7bf4b45349 | ||
|
|
4255e30722 | ||
|
|
78eeefb030 | ||
|
|
efa8711bf3 | ||
|
|
c3fd211b43 | ||
|
|
dcca650599 | ||
|
|
dddc9bb8f1 | ||
|
|
4769d798f9 | ||
|
|
7381f873e9 | ||
|
|
3b19f741bd | ||
|
|
c7f32300b2 | ||
|
|
6352c5dc31 | ||
|
|
752236caad | ||
|
|
a52d0b82a6 | ||
|
|
cec3a3cd5a | ||
|
|
3b9db85646 | ||
|
|
522e7c5663 | ||
|
|
ec547824f1 | ||
|
|
919b4acfea | ||
|
|
8e17b5469f | ||
|
|
0cbfdf7ecb | ||
|
|
157981cac5 | ||
|
|
18831e0933 | ||
|
|
ea56d8f388 | ||
|
|
f23f875dd8 | ||
|
|
06a67d2bbd | ||
|
|
bbc1809951 | ||
|
|
a9633ba8b2 | ||
|
|
7fc6514be1 | ||
|
|
e44a804ec7 | ||
|
|
a948ab3e48 | ||
|
|
f4b5570e7c | ||
|
|
02b10a6e4d | ||
|
|
6d2c597371 | ||
|
|
14440b195c | ||
|
|
f77cc6c412 | ||
|
|
75e16547f8 | ||
|
|
22aff09b33 | ||
|
|
ac0721a4bc | ||
|
|
c043ba8467 | ||
|
|
9a5d8b356a | ||
|
|
6072b22a0b | ||
|
|
d8bd52c6f1 | ||
|
|
a4725bcb73 | ||
|
|
dcc663e1bf | ||
|
|
3ef006b5ab | ||
|
|
cb5400b34d | ||
|
|
e67b829cc7 | ||
|
|
5ff19890e9 | ||
|
|
2d2be2facf | ||
|
|
be05cb640c | ||
|
|
5b5612c1cc | ||
|
|
3c39c0ac3e | ||
|
|
51358d2b5e | ||
|
|
a78372110c | ||
|
|
37bc5118ea | ||
|
|
5695ae6bdd | ||
|
|
cae6c13ffb | ||
|
|
00fdffec58 | ||
|
|
89dd7dc180 | ||
|
|
4cbbf590e3 | ||
|
|
3de05726eb | ||
|
|
b1b20ad84a | ||
|
|
2956a33463 | ||
|
|
9737615948 | ||
|
|
9efdad6a27 | ||
|
|
0d6a8824d0 |
@@ -11,6 +11,7 @@ ccache -s
|
||||
mkdir build || true && cd build
|
||||
cmake .. \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_CXX_FLAGS="-march=x86-64-v2" \
|
||||
-DCMAKE_CXX_COMPILER=/usr/lib/ccache/clang++ \
|
||||
-DCMAKE_C_COMPILER=/usr/lib/ccache/clang \
|
||||
-DCMAKE_INSTALL_PREFIX="/usr" \
|
||||
@@ -19,6 +20,7 @@ cmake .. \
|
||||
-DENABLE_QT_TRANSLATION=ON \
|
||||
-DUSE_DISCORD_PRESENCE=ON \
|
||||
-DYUZU_ENABLE_COMPATIBILITY_REPORTING=${ENABLE_COMPATIBILITY_REPORTING:-"OFF"} \
|
||||
-DYUZU_USE_BUNDLED_FFMPEG=ON \
|
||||
-GNinja
|
||||
|
||||
ninja
|
||||
|
||||
@@ -12,6 +12,7 @@ mkdir build || true && cd build
|
||||
cmake .. \
|
||||
-DBoost_USE_STATIC_LIBS=ON \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_CXX_FLAGS="-march=x86-64-v2" \
|
||||
-DCMAKE_CXX_COMPILER=/usr/lib/ccache/g++ \
|
||||
-DCMAKE_C_COMPILER=/usr/lib/ccache/gcc \
|
||||
-DCMAKE_INSTALL_PREFIX="/usr" \
|
||||
|
||||
@@ -9,7 +9,7 @@ parameters:
|
||||
steps:
|
||||
- script: choco install vulkan-sdk
|
||||
displayName: 'Install vulkan-sdk'
|
||||
- script: refreshenv && mkdir build && cd build && cmake -G "Visual Studio 17 2022" -A x64 -DYUZU_USE_BUNDLED_QT=1 -DYUZU_USE_BUNDLED_SDL2=1 -DYUZU_USE_QT_WEB_ENGINE=ON -DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON -DYUZU_ENABLE_COMPATIBILITY_REPORTING=${COMPAT} -DYUZU_TESTS=OFF -DUSE_DISCORD_PRESENCE=ON -DENABLE_QT_TRANSLATION=ON -DDISPLAY_VERSION=${{ parameters['version'] }} -DCMAKE_BUILD_TYPE=Release -DYUZU_CRASH_DUMPS=ON .. && cd ..
|
||||
- script: refreshenv && mkdir build && cd build && cmake -E env CXXFLAGS="/Gw /GA /Gr /Ob2" cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DCMAKE_POLICY_DEFAULT_CMP0069=NEW -DYUZU_USE_BUNDLED_QT=1 -DYUZU_USE_BUNDLED_SDL2=1 -DYUZU_USE_QT_WEB_ENGINE=ON -DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON -DYUZU_ENABLE_COMPATIBILITY_REPORTING=${COMPAT} -DYUZU_TESTS=OFF -DUSE_DISCORD_PRESENCE=ON -DENABLE_QT_TRANSLATION=ON -DDISPLAY_VERSION=${{ parameters['version'] }} -DCMAKE_BUILD_TYPE=Release -DYUZU_CRASH_DUMPS=ON .. && cd ..
|
||||
displayName: 'Configure CMake'
|
||||
- task: MSBuild@1
|
||||
displayName: 'Build'
|
||||
|
||||
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -27,7 +27,7 @@
|
||||
url = https://github.com/KhronosGroup/Vulkan-Headers.git
|
||||
[submodule "sirit"]
|
||||
path = externals/sirit
|
||||
url = https://github.com/ReinUsesLisp/sirit
|
||||
url = https://github.com/yuzu-emu/sirit
|
||||
[submodule "mbedtls"]
|
||||
path = externals/mbedtls
|
||||
url = https://github.com/yuzu-emu/mbedtls
|
||||
|
||||
134
CMakeLists.txt
134
CMakeLists.txt
@@ -3,6 +3,10 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
# Dynarmic has cmake_minimum_required(3.12) and we may want to override
|
||||
# some of its variables, which is only possible in 3.13+
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules")
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/find-modules")
|
||||
@@ -18,6 +22,8 @@ CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" ON
|
||||
# On Linux system SDL2 is likely to be lacking HIDAPI support which have drawbacks but is needed for SDL motion
|
||||
CMAKE_DEPENDENT_OPTION(YUZU_USE_EXTERNAL_SDL2 "Compile external SDL2" ON "ENABLE_SDL2;NOT MSVC" OFF)
|
||||
|
||||
option(ENABLE_OPENGL "Enable OpenGL" ON)
|
||||
mark_as_advanced(FORCE ENABLE_OPENGL)
|
||||
option(ENABLE_QT "Enable the Qt frontend" ON)
|
||||
option(ENABLE_QT6 "Allow usage of Qt6 to be attempted" OFF)
|
||||
set(QT6_LOCATION "" CACHE PATH "Additional Location to search for Qt6 libraries like C:/Qt/6.3.1/msvc2019_64/")
|
||||
@@ -27,8 +33,6 @@ CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" "${MSV
|
||||
|
||||
option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON)
|
||||
|
||||
option(YUZU_USE_BUNDLED_LIBUSB "Compile bundled libusb" OFF)
|
||||
|
||||
option(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" "${WIN32}")
|
||||
|
||||
option(YUZU_USE_QT_MULTIMEDIA "Use QtMultimedia for Camera" OFF)
|
||||
@@ -39,16 +43,18 @@ option(ENABLE_CUBEB "Enables the cubeb audio backend" ON)
|
||||
|
||||
option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF)
|
||||
|
||||
option(YUZU_USE_BUNDLED_OPUS "Compile bundled opus" ON)
|
||||
|
||||
option(YUZU_TESTS "Compile tests" ON)
|
||||
|
||||
option(YUZU_USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
|
||||
|
||||
CMAKE_DEPENDENT_OPTION(YUZU_CRASH_DUMPS "Compile Windows crash dump (Minidump) support" OFF "WIN32" OFF)
|
||||
|
||||
option(YUZU_USE_BUNDLED_VCPKG "Use vcpkg for yuzu dependencies" "${MSVC}")
|
||||
|
||||
option(YUZU_CHECK_SUBMODULES "Check if submodules are present" ON)
|
||||
|
||||
CMAKE_DEPENDENT_OPTION(YUZU_USE_FASTER_LD "Check if a faster linker is available" ON "NOT WIN32" OFF)
|
||||
|
||||
if (YUZU_USE_BUNDLED_VCPKG)
|
||||
if (YUZU_TESTS)
|
||||
list(APPEND VCPKG_MANIFEST_FEATURES "yuzu-tests")
|
||||
@@ -64,6 +70,21 @@ elseif(NOT "$ENV{VCPKG_TOOLCHAIN_FILE}" STREQUAL "")
|
||||
include("$ENV{VCPKG_TOOLCHAIN_FILE}")
|
||||
endif()
|
||||
|
||||
if (YUZU_USE_PRECOMPILED_HEADERS)
|
||||
if (MSVC AND CCACHE)
|
||||
# buildcache does not properly cache PCH files, leading to compilation errors.
|
||||
# See https://github.com/mbitsnbites/buildcache/discussions/230
|
||||
message(WARNING "buildcache does not properly support Precompiled Headers. Disabling PCH")
|
||||
set(DYNARMIC_USE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
|
||||
set(YUZU_USE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
endif()
|
||||
if (YUZU_USE_PRECOMPILED_HEADERS)
|
||||
message(STATUS "Using Precompiled Headers.")
|
||||
set(CMAKE_PCH_INSTANTIATE_TEMPLATES ON)
|
||||
endif()
|
||||
|
||||
|
||||
# Default to a Release build
|
||||
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if (NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
|
||||
@@ -180,24 +201,40 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
|
||||
# System imported libraries
|
||||
# =======================================================================
|
||||
|
||||
find_package(fmt 8.0.1 REQUIRED CONFIG)
|
||||
find_package(nlohmann_json 3.8 REQUIRED CONFIG)
|
||||
find_package(enet 1.3)
|
||||
find_package(fmt 9 REQUIRED)
|
||||
find_package(inih)
|
||||
find_package(libusb 1.0.24)
|
||||
find_package(lz4 REQUIRED)
|
||||
find_package(nlohmann_json 3.8 REQUIRED)
|
||||
find_package(Opus 1.3)
|
||||
find_package(Vulkan 1.3.238)
|
||||
find_package(ZLIB 1.2 REQUIRED)
|
||||
find_package(zstd 1.5 REQUIRED)
|
||||
|
||||
# Search for config-only package first (for vcpkg), then try non-config
|
||||
find_package(zstd 1.5 CONFIG)
|
||||
if (NOT zstd_FOUND)
|
||||
find_package(zstd 1.5 REQUIRED)
|
||||
if (ARCHITECTURE_x86 OR ARCHITECTURE_x86_64)
|
||||
find_package(xbyak 6)
|
||||
endif()
|
||||
|
||||
# lz4 1.8 is required, but vcpkg's lz4-config.cmake does not have version info
|
||||
find_package(lz4 CONFIG)
|
||||
if (NOT lz4_FOUND)
|
||||
find_package(lz4 1.8 REQUIRED)
|
||||
if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
|
||||
find_package(dynarmic 6.4.0)
|
||||
endif()
|
||||
|
||||
if (ENABLE_CUBEB)
|
||||
find_package(cubeb)
|
||||
endif()
|
||||
|
||||
if (USE_DISCORD_PRESENCE)
|
||||
find_package(DiscordRPC)
|
||||
endif()
|
||||
|
||||
if (ENABLE_WEB_SERVICE)
|
||||
find_package(cpp-jwt 1.4)
|
||||
find_package(httplib 0.11)
|
||||
endif()
|
||||
|
||||
if (YUZU_TESTS)
|
||||
find_package(Catch2 2.13.7 REQUIRED CONFIG)
|
||||
find_package(Catch2 2.13.7 REQUIRED)
|
||||
endif()
|
||||
|
||||
find_package(Boost 1.73.0 COMPONENTS context)
|
||||
@@ -399,23 +436,13 @@ if (ENABLE_SDL2)
|
||||
set(SDL2_LIBRARY "${SDL2_PREFIX}/lib/x64/SDL2.lib" CACHE PATH "Path to SDL2 library")
|
||||
set(SDL2_DLL_DIR "${SDL2_PREFIX}/lib/x64/" CACHE PATH "Path to SDL2.dll")
|
||||
|
||||
add_library(SDL2 INTERFACE)
|
||||
target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARY}")
|
||||
target_include_directories(SDL2 INTERFACE "${SDL2_INCLUDE_DIR}")
|
||||
add_library(SDL2::SDL2 INTERFACE IMPORTED)
|
||||
target_link_libraries(SDL2::SDL2 INTERFACE "${SDL2_LIBRARY}")
|
||||
target_include_directories(SDL2::SDL2 INTERFACE "${SDL2_INCLUDE_DIR}")
|
||||
elseif (YUZU_USE_EXTERNAL_SDL2)
|
||||
message(STATUS "Using SDL2 from externals.")
|
||||
else()
|
||||
find_package(SDL2 2.0.18 REQUIRED)
|
||||
|
||||
# Some installations don't set SDL2_LIBRARIES
|
||||
if("${SDL2_LIBRARIES}" STREQUAL "")
|
||||
message(WARNING "SDL2_LIBRARIES wasn't set, manually setting to SDL2::SDL2")
|
||||
set(SDL2_LIBRARIES "SDL2::SDL2")
|
||||
endif()
|
||||
|
||||
include_directories(SYSTEM ${SDL2_INCLUDE_DIRS})
|
||||
add_library(SDL2 INTERFACE)
|
||||
target_link_libraries(SDL2 INTERFACE "${SDL2_LIBRARIES}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -427,25 +454,6 @@ if (TARGET Boost::boost)
|
||||
add_library(boost ALIAS Boost::boost)
|
||||
endif()
|
||||
|
||||
# Ensure libusb is properly configured (based on dolphin libusb include)
|
||||
if(NOT APPLE AND NOT YUZU_USE_BUNDLED_LIBUSB)
|
||||
find_package(PkgConfig)
|
||||
if (PKG_CONFIG_FOUND AND NOT CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD")
|
||||
pkg_check_modules(LIBUSB QUIET libusb-1.0>=1.0.24)
|
||||
else()
|
||||
find_package(LibUSB)
|
||||
endif()
|
||||
|
||||
if (LIBUSB_FOUND)
|
||||
add_library(usb INTERFACE)
|
||||
target_include_directories(usb INTERFACE "${LIBUSB_INCLUDE_DIRS}")
|
||||
target_link_libraries(usb INTERFACE "${LIBUSB_LIBRARIES}")
|
||||
else()
|
||||
message(WARNING "libusb not found, falling back to externals")
|
||||
set(YUZU_USE_BUNDLED_LIBUSB ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# List of all FFmpeg components required
|
||||
set(FFmpeg_COMPONENTS
|
||||
avcodec
|
||||
@@ -458,22 +466,7 @@ if (UNIX AND NOT APPLE)
|
||||
endif()
|
||||
if (NOT YUZU_USE_BUNDLED_FFMPEG)
|
||||
# Use system installed FFmpeg
|
||||
find_package(FFmpeg 4.3 QUIET COMPONENTS ${FFmpeg_COMPONENTS})
|
||||
|
||||
if (FFmpeg_FOUND)
|
||||
# Overwrite aggregate defines from FFmpeg module to avoid over-linking libraries.
|
||||
# Prevents shipping too many libraries with the AppImage.
|
||||
set(FFmpeg_LIBRARIES "")
|
||||
set(FFmpeg_INCLUDE_DIR "")
|
||||
|
||||
foreach(COMPONENT ${FFmpeg_COMPONENTS})
|
||||
set(FFmpeg_LIBRARIES ${FFmpeg_LIBRARIES} ${FFmpeg_LIBRARY_${COMPONENT}} CACHE PATH "Paths to FFmpeg libraries" FORCE)
|
||||
set(FFmpeg_INCLUDE_DIR ${FFmpeg_INCLUDE_DIR} ${FFmpeg_INCLUDE_${COMPONENT}} CACHE PATH "Path to FFmpeg headers" FORCE)
|
||||
endforeach()
|
||||
else()
|
||||
message(WARNING "FFmpeg not found or too old, falling back to externals")
|
||||
set(YUZU_USE_BUNDLED_FFMPEG ON)
|
||||
endif()
|
||||
find_package(FFmpeg 4.3 REQUIRED QUIET COMPONENTS ${FFmpeg_COMPONENTS})
|
||||
endif()
|
||||
|
||||
# Prefer the -pthread flag on Linux.
|
||||
@@ -590,6 +583,21 @@ if (MSVC AND CMAKE_GENERATOR STREQUAL "Ninja")
|
||||
)
|
||||
endif()
|
||||
|
||||
if (YUZU_USE_FASTER_LD AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
# We will assume that if the compiler is GCC, it will attempt to use ld.bfd by default.
|
||||
# Try to pick a faster linker.
|
||||
find_program(LLD lld)
|
||||
find_program(MOLD mold)
|
||||
|
||||
if (MOLD AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12.1")
|
||||
message(NOTICE "Selecting mold as linker")
|
||||
add_link_options("-fuse-ld=mold")
|
||||
elseif (LLD)
|
||||
message(NOTICE "Selecting lld as linker")
|
||||
add_link_options("-fuse-ld=lld")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
enable_testing()
|
||||
add_subdirectory(externals)
|
||||
add_subdirectory(src)
|
||||
|
||||
57
externals/CMakeLists.txt
vendored
57
externals/CMakeLists.txt
vendored
@@ -6,18 +6,16 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/externals/find-modules")
|
||||
include(DownloadExternals)
|
||||
|
||||
# xbyak
|
||||
if (ARCHITECTURE_x86 OR ARCHITECTURE_x86_64)
|
||||
add_subdirectory(xbyak)
|
||||
if ((ARCHITECTURE_x86 OR ARCHITECTURE_x86_64) AND NOT TARGET xbyak::xbyak)
|
||||
add_subdirectory(xbyak EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
# Dynarmic
|
||||
if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
|
||||
if (ARCHITECTURE_arm64)
|
||||
set(DYNARMIC_FRONTENDS "A32")
|
||||
endif()
|
||||
if ((ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64) AND NOT TARGET dynarmic::dynarmic)
|
||||
set(DYNARMIC_NO_BUNDLED_FMT ON)
|
||||
set(DYNARMIC_IGNORE_ASSERTS ON CACHE BOOL "" FORCE)
|
||||
add_subdirectory(dynarmic)
|
||||
add_subdirectory(dynarmic EXCLUDE_FROM_ALL)
|
||||
add_library(dynarmic::dynarmic ALIAS dynarmic)
|
||||
endif()
|
||||
|
||||
# getopt
|
||||
@@ -29,7 +27,9 @@ endif()
|
||||
add_subdirectory(glad)
|
||||
|
||||
# inih
|
||||
add_subdirectory(inih)
|
||||
if (NOT TARGET inih::INIReader)
|
||||
add_subdirectory(inih)
|
||||
endif()
|
||||
|
||||
# mbedtls
|
||||
add_subdirectory(mbedtls EXCLUDE_FROM_ALL)
|
||||
@@ -45,8 +45,8 @@ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12" AND CMAKE_CXX_COMPILER
|
||||
endif()
|
||||
|
||||
# libusb
|
||||
if (NOT LIBUSB_FOUND OR YUZU_USE_BUNDLED_LIBUSB)
|
||||
add_subdirectory(libusb)
|
||||
if (NOT TARGET libusb::usb)
|
||||
add_subdirectory(libusb EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
# SDL2
|
||||
@@ -67,30 +67,38 @@ if (YUZU_USE_EXTERNAL_SDL2)
|
||||
endif()
|
||||
set(SDL_STATIC ON)
|
||||
set(SDL_SHARED OFF)
|
||||
if (APPLE)
|
||||
set(SDL_FILE ON)
|
||||
endif()
|
||||
|
||||
add_subdirectory(SDL EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
# ENet
|
||||
add_subdirectory(enet)
|
||||
target_include_directories(enet INTERFACE ./enet/include)
|
||||
if (NOT TARGET enet::enet)
|
||||
add_subdirectory(enet EXCLUDE_FROM_ALL)
|
||||
target_include_directories(enet INTERFACE ./enet/include)
|
||||
add_library(enet::enet ALIAS enet)
|
||||
endif()
|
||||
|
||||
# Cubeb
|
||||
if(ENABLE_CUBEB)
|
||||
if (ENABLE_CUBEB AND NOT TARGET cubeb::cubeb)
|
||||
set(BUILD_TESTS OFF CACHE BOOL "")
|
||||
add_subdirectory(cubeb EXCLUDE_FROM_ALL)
|
||||
add_library(cubeb::cubeb ALIAS cubeb)
|
||||
endif()
|
||||
|
||||
# DiscordRPC
|
||||
if (USE_DISCORD_PRESENCE)
|
||||
if (USE_DISCORD_PRESENCE AND NOT TARGET DiscordRPC::discord-rpc)
|
||||
add_subdirectory(discord-rpc EXCLUDE_FROM_ALL)
|
||||
target_include_directories(discord-rpc INTERFACE ./discord-rpc/include)
|
||||
add_library(DiscordRPC::discord-rpc ALIAS discord-rpc)
|
||||
endif()
|
||||
|
||||
# Sirit
|
||||
add_subdirectory(sirit)
|
||||
add_subdirectory(sirit EXCLUDE_FROM_ALL)
|
||||
|
||||
if (ENABLE_WEB_SERVICE)
|
||||
if (ENABLE_WEB_SERVICE AND NOT TARGET httplib::httplib)
|
||||
if (NOT WIN32)
|
||||
find_package(OpenSSL 1.1)
|
||||
if (OPENSSL_FOUND)
|
||||
@@ -118,18 +126,20 @@ if (ENABLE_WEB_SERVICE)
|
||||
if (WIN32)
|
||||
target_link_libraries(httplib INTERFACE crypt32 cryptui ws2_32)
|
||||
endif()
|
||||
|
||||
# cpp-jwt
|
||||
add_library(httplib::httplib ALIAS httplib)
|
||||
endif()
|
||||
|
||||
# cpp-jwt
|
||||
if (ENABLE_WEB_SERVICE AND NOT TARGET cpp-jwt::cpp-jwt)
|
||||
add_library(cpp-jwt INTERFACE)
|
||||
target_include_directories(cpp-jwt INTERFACE ./cpp-jwt/include)
|
||||
target_compile_definitions(cpp-jwt INTERFACE CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||
add_library(cpp-jwt::cpp-jwt ALIAS cpp-jwt)
|
||||
endif()
|
||||
|
||||
# Opus
|
||||
if (YUZU_USE_BUNDLED_OPUS)
|
||||
if (NOT TARGET Opus::opus)
|
||||
add_subdirectory(opus EXCLUDE_FROM_ALL)
|
||||
else()
|
||||
find_package(Opus 1.3 REQUIRED)
|
||||
endif()
|
||||
|
||||
# FFMpeg
|
||||
@@ -140,3 +150,8 @@ if (YUZU_USE_BUNDLED_FFMPEG)
|
||||
set(FFmpeg_LIBRARIES "${FFmpeg_LIBRARIES}" PARENT_SCOPE)
|
||||
set(FFmpeg_INCLUDE_DIR "${FFmpeg_INCLUDE_DIR}" PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
# Vulkan-Headers
|
||||
if (NOT TARGET Vulkan::Headers)
|
||||
add_subdirectory(Vulkan-Headers EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
2
externals/SDL
vendored
2
externals/SDL
vendored
Submodule externals/SDL updated: b424665e08...f17058b562
2
externals/Vulkan-Headers
vendored
2
externals/Vulkan-Headers
vendored
Submodule externals/Vulkan-Headers updated: 33d4dd987f...00671c64ba
2
externals/dynarmic
vendored
2
externals/dynarmic
vendored
Submodule externals/dynarmic updated: 07c614f91b...bd570e093c
27
externals/find-modules/FindDiscordRPC.cmake
vendored
Normal file
27
externals/find-modules/FindDiscordRPC.cmake
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
find_path(DiscordRPC_INCLUDE_DIR discord_rpc.h)
|
||||
|
||||
find_library(DiscordRPC_LIBRARY discord-rpc)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(DiscordRPC
|
||||
REQUIRED_VARS
|
||||
DiscordRPC_LIBRARY
|
||||
DiscordRPC_INCLUDE_DIR
|
||||
)
|
||||
|
||||
if (DiscordRPC_FOUND AND NOT TARGET DiscordRPC::discord-rpc)
|
||||
add_library(DiscordRPC::discord-rpc UNKNOWN IMPORTED)
|
||||
set_target_properties(DiscordRPC::discord-rpc PROPERTIES
|
||||
IMPORTED_LOCATION "${DiscordRPC_LIBRARY}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${DiscordRPC_INCLUDE_DIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(
|
||||
DiscordRPC_INCLUDE_DIR
|
||||
DiscordRPC_LIBRARY
|
||||
)
|
||||
8
externals/find-modules/FindFFmpeg.cmake
vendored
8
externals/find-modules/FindFFmpeg.cmake
vendored
@@ -185,3 +185,11 @@ foreach(c ${_FFmpeg_ALL_COMPONENTS})
|
||||
endforeach()
|
||||
unset(_FFmpeg_ALL_COMPONENTS)
|
||||
unset(_FFmpeg_REQUIRED_VARS)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(FFmpeg
|
||||
REQUIRED_VARS
|
||||
FFmpeg_LIBRARIES
|
||||
FFmpeg_INCLUDE_DIR
|
||||
HANDLE_COMPONENTS
|
||||
)
|
||||
|
||||
44
externals/find-modules/FindLibUSB.cmake
vendored
44
externals/find-modules/FindLibUSB.cmake
vendored
@@ -1,44 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2009 Michal Cihar <michal@cihar.com>
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
# - Find libusb-1.0 library
|
||||
# This module defines
|
||||
# LIBUSB_INCLUDE_DIR, where to find bluetooth.h
|
||||
# LIBUSB_LIBRARIES, the libraries needed to use libusb-1.0.
|
||||
# LIBUSB_FOUND, If false, do not try to use libusb-1.0.
|
||||
#
|
||||
# vim: expandtab sw=4 ts=4 sts=4:
|
||||
|
||||
if(ANDROID)
|
||||
set(LIBUSB_FOUND FALSE CACHE INTERNAL "libusb-1.0 found")
|
||||
message(STATUS "libusb-1.0 not found.")
|
||||
elseif (NOT LIBUSB_FOUND)
|
||||
pkg_check_modules (LIBUSB_PKG libusb-1.0)
|
||||
|
||||
find_path(LIBUSB_INCLUDE_DIR NAMES libusb.h
|
||||
PATHS
|
||||
${LIBUSB_PKG_INCLUDE_DIRS}
|
||||
/usr/include/libusb-1.0
|
||||
/usr/include
|
||||
/usr/local/include/libusb-1.0
|
||||
/usr/local/include
|
||||
)
|
||||
|
||||
find_library(LIBUSB_LIBRARIES NAMES usb-1.0 usb
|
||||
PATHS
|
||||
${LIBUSB_PKG_LIBRARY_DIRS}
|
||||
/usr/lib
|
||||
/usr/local/lib
|
||||
)
|
||||
|
||||
if(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
|
||||
set(LIBUSB_FOUND TRUE CACHE INTERNAL "libusb-1.0 found")
|
||||
message(STATUS "Found libusb-1.0: ${LIBUSB_INCLUDE_DIR}, ${LIBUSB_LIBRARIES}")
|
||||
else(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
|
||||
set(LIBUSB_FOUND FALSE CACHE INTERNAL "libusb-1.0 found")
|
||||
message(STATUS "libusb-1.0 not found.")
|
||||
endif(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
|
||||
|
||||
mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES)
|
||||
endif ()
|
||||
|
||||
20
externals/find-modules/FindOpus.cmake
vendored
20
externals/find-modules/FindOpus.cmake
vendored
@@ -1,19 +1,15 @@
|
||||
# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
find_package(PkgConfig)
|
||||
|
||||
if (PKG_CONFIG_FOUND)
|
||||
pkg_search_module(opus IMPORTED_TARGET GLOBAL opus)
|
||||
if (opus_FOUND)
|
||||
add_library(Opus::opus ALIAS PkgConfig::opus)
|
||||
endif()
|
||||
endif()
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_search_module(OPUS QUIET IMPORTED_TARGET opus)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Opus
|
||||
REQUIRED_VARS
|
||||
opus_LINK_LIBRARIES
|
||||
opus_FOUND
|
||||
VERSION_VAR opus_VERSION
|
||||
REQUIRED_VARS OPUS_LINK_LIBRARIES
|
||||
VERSION_VAR OPUS_VERSION
|
||||
)
|
||||
|
||||
if (Opus_FOUND AND NOT TARGET Opus::opus)
|
||||
add_library(Opus::opus ALIAS PkgConfig::OPUS)
|
||||
endif()
|
||||
|
||||
16
externals/find-modules/Findenet.cmake
vendored
Normal file
16
externals/find-modules/Findenet.cmake
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_search_module(ENET QUIET IMPORTED_TARGET libenet)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(enet
|
||||
REQUIRED_VARS ENET_LINK_LIBRARIES
|
||||
VERSION_VAR ENET_VERSION
|
||||
)
|
||||
|
||||
if (enet_FOUND AND NOT TARGET enet::enet)
|
||||
add_library(enet::enet ALIAS PkgConfig::ENET)
|
||||
endif()
|
||||
21
externals/find-modules/Findhttplib.cmake
vendored
Normal file
21
externals/find-modules/Findhttplib.cmake
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# SPDX-FileCopyrightText: 2022 Andrea Pappacoda <andrea@pappacoda.it>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package(httplib QUIET CONFIG)
|
||||
if (httplib_FOUND)
|
||||
find_package_handle_standard_args(httplib CONFIG_MODE)
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_search_module(HTTPLIB QUIET IMPORTED_TARGET cpp-httplib)
|
||||
find_package_handle_standard_args(httplib
|
||||
REQUIRED_VARS HTTPLIB_INCLUDEDIR
|
||||
VERSION_VAR HTTPLIB_VERSION
|
||||
)
|
||||
endif()
|
||||
|
||||
if (httplib_FOUND AND NOT TARGET httplib::httplib)
|
||||
add_library(httplib::httplib ALIAS PkgConfig::HTTPLIB)
|
||||
endif()
|
||||
16
externals/find-modules/Findinih.cmake
vendored
Normal file
16
externals/find-modules/Findinih.cmake
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_search_module(INIREADER QUIET IMPORTED_TARGET INIReader)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(inih
|
||||
REQUIRED_VARS INIREADER_LINK_LIBRARIES
|
||||
VERSION_VAR INIREADER_VERSION
|
||||
)
|
||||
|
||||
if (inih_FOUND AND NOT TARGET inih::INIReader)
|
||||
add_library(inih::INIReader ALIAS PkgConfig::INIREADER)
|
||||
endif()
|
||||
16
externals/find-modules/Findlibusb.cmake
vendored
Normal file
16
externals/find-modules/Findlibusb.cmake
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_search_module(LIBUSB QUIET IMPORTED_TARGET libusb-1.0)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(libusb
|
||||
REQUIRED_VARS LIBUSB_LINK_LIBRARIES
|
||||
VERSION_VAR LIBUSB_VERSION
|
||||
)
|
||||
|
||||
if (libusb_FOUND AND NOT TARGET libusb::usb)
|
||||
add_library(libusb::usb ALIAS PkgConfig::LIBUSB)
|
||||
endif()
|
||||
33
externals/find-modules/Findlz4.cmake
vendored
33
externals/find-modules/Findlz4.cmake
vendored
@@ -1,19 +1,26 @@
|
||||
# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
find_package(PkgConfig)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
if (PKG_CONFIG_FOUND)
|
||||
pkg_search_module(liblz4 IMPORTED_TARGET GLOBAL liblz4)
|
||||
if (liblz4_FOUND)
|
||||
add_library(lz4::lz4 ALIAS PkgConfig::liblz4)
|
||||
endif()
|
||||
find_package(lz4 QUIET CONFIG)
|
||||
if (lz4_FOUND)
|
||||
find_package_handle_standard_args(lz4 CONFIG_MODE)
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_search_module(LZ4 QUIET IMPORTED_TARGET liblz4)
|
||||
find_package_handle_standard_args(lz4
|
||||
REQUIRED_VARS LZ4_LINK_LIBRARIES
|
||||
VERSION_VAR LZ4_VERSION
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(lz4
|
||||
REQUIRED_VARS
|
||||
liblz4_LINK_LIBRARIES
|
||||
liblz4_FOUND
|
||||
VERSION_VAR liblz4_VERSION
|
||||
)
|
||||
if (lz4_FOUND AND NOT TARGET lz4::lz4)
|
||||
if (TARGET LZ4::lz4_shared)
|
||||
add_library(lz4::lz4 ALIAS LZ4::lz4_shared)
|
||||
elseif (TARGET LZ4::lz4_static)
|
||||
add_library(lz4::lz4 ALIAS LZ4::lz4_static)
|
||||
else()
|
||||
add_library(lz4::lz4 ALIAS PkgConfig::LZ4)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
33
externals/find-modules/Findzstd.cmake
vendored
33
externals/find-modules/Findzstd.cmake
vendored
@@ -1,19 +1,26 @@
|
||||
# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
find_package(PkgConfig)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
if (PKG_CONFIG_FOUND)
|
||||
pkg_search_module(libzstd IMPORTED_TARGET GLOBAL libzstd)
|
||||
if (libzstd_FOUND)
|
||||
add_library(zstd::zstd ALIAS PkgConfig::libzstd)
|
||||
endif()
|
||||
find_package(zstd QUIET CONFIG)
|
||||
if (zstd_FOUND)
|
||||
find_package_handle_standard_args(zstd CONFIG_MODE)
|
||||
else()
|
||||
find_package(PkgConfig QUIET)
|
||||
pkg_search_module(ZSTD QUIET IMPORTED_TARGET libzstd)
|
||||
find_package_handle_standard_args(zstd
|
||||
REQUIRED_VARS ZSTD_LINK_LIBRARIES
|
||||
VERSION_VAR ZSTD_VERSION
|
||||
)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(zstd
|
||||
REQUIRED_VARS
|
||||
libzstd_LINK_LIBRARIES
|
||||
libzstd_FOUND
|
||||
VERSION_VAR libzstd_VERSION
|
||||
)
|
||||
if (zstd_FOUND AND NOT TARGET zstd::zstd)
|
||||
if (TARGET zstd::libzstd_shared)
|
||||
add_library(zstd::zstd ALIAS zstd::libzstd_shared)
|
||||
elseif (TARGET zstd::libzstd_static)
|
||||
add_library(zstd::zstd ALIAS zstd::libzstd_static)
|
||||
else()
|
||||
add_library(zstd::zstd ALIAS PkgConfig::ZSTD)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
3
externals/inih/CMakeLists.txt
vendored
3
externals/inih/CMakeLists.txt
vendored
@@ -9,4 +9,5 @@ add_library(inih
|
||||
)
|
||||
|
||||
create_target_directory_groups(inih)
|
||||
target_include_directories(inih INTERFACE .)
|
||||
target_include_directories(inih INTERFACE inih/cpp)
|
||||
add_library(inih::INIReader ALIAS inih)
|
||||
|
||||
2
externals/libusb/CMakeLists.txt
vendored
2
externals/libusb/CMakeLists.txt
vendored
@@ -273,3 +273,5 @@ else() # MINGW OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
|
||||
configure_file(config.h.in config.h)
|
||||
endif() # MINGW OR (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
|
||||
add_library(libusb::usb ALIAS usb)
|
||||
|
||||
2
externals/sirit
vendored
2
externals/sirit
vendored
Submodule externals/sirit updated: aa292d5665...d7ad93a888
@@ -82,8 +82,9 @@ if (MSVC)
|
||||
/wd4324 # 'struct_name': structure was padded due to __declspec(align())
|
||||
)
|
||||
|
||||
if (USE_CCACHE)
|
||||
if (USE_CCACHE OR YUZU_USE_PRECOMPILED_HEADERS)
|
||||
# when caching, we need to use /Z7 to downgrade debug info to use an older but more cachable format
|
||||
# Precompiled headers are deleted if not using /Z7. See https://github.com/nanoant/CMakePCHCompiler/issues/21
|
||||
add_compile_options(/Z7)
|
||||
else()
|
||||
add_compile_options(/Zi)
|
||||
@@ -112,6 +113,8 @@ else()
|
||||
|
||||
$<$<CXX_COMPILER_ID:Clang>:-Wno-braced-scalar-init>
|
||||
$<$<CXX_COMPILER_ID:Clang>:-Wno-unused-private-field>
|
||||
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-braced-scalar-init>
|
||||
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-unused-private-field>
|
||||
)
|
||||
|
||||
if (ARCHITECTURE_x86_64)
|
||||
|
||||
@@ -31,6 +31,7 @@ add_library(audio_core STATIC
|
||||
out/audio_out.h
|
||||
out/audio_out_system.cpp
|
||||
out/audio_out_system.h
|
||||
precompiled_headers.h
|
||||
renderer/adsp/adsp.cpp
|
||||
renderer/adsp/adsp.h
|
||||
renderer/adsp/audio_renderer.cpp
|
||||
@@ -218,18 +219,18 @@ endif()
|
||||
|
||||
target_link_libraries(audio_core PUBLIC common core)
|
||||
if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
|
||||
target_link_libraries(audio_core PRIVATE dynarmic)
|
||||
target_link_libraries(audio_core PRIVATE dynarmic::dynarmic)
|
||||
endif()
|
||||
|
||||
if(ENABLE_CUBEB)
|
||||
target_link_libraries(audio_core PRIVATE cubeb)
|
||||
target_link_libraries(audio_core PRIVATE cubeb::cubeb)
|
||||
target_compile_definitions(audio_core PRIVATE -DHAVE_CUBEB=1)
|
||||
endif()
|
||||
if(ENABLE_SDL2)
|
||||
if (YUZU_USE_EXTERNAL_SDL2)
|
||||
target_link_libraries(audio_core PRIVATE SDL2-static)
|
||||
else()
|
||||
target_link_libraries(audio_core PRIVATE SDL2)
|
||||
endif()
|
||||
target_link_libraries(audio_core PRIVATE SDL2::SDL2)
|
||||
target_compile_definitions(audio_core PRIVATE HAVE_SDL2)
|
||||
endif()
|
||||
|
||||
if (YUZU_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(audio_core PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "audio_core/audio_event.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/polyfill_ranges.h"
|
||||
|
||||
namespace AudioCore {
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include "common/polyfill_thread.h"
|
||||
|
||||
#include "audio_core/audio_event.h"
|
||||
|
||||
union Result;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/polyfill_thread.h"
|
||||
|
||||
#include "audio_core/common/common.h"
|
||||
#include "audio_core/renderer/system_manager.h"
|
||||
#include "core/hle/service/audio/errors.h"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "common/assert.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/polyfill_ranges.h"
|
||||
|
||||
namespace AudioCore {
|
||||
constexpr u32 CurrentRevision = 11;
|
||||
|
||||
@@ -91,9 +91,10 @@ public:
|
||||
* @param core_timing - The CoreTiming instance
|
||||
* @param session - The device session
|
||||
*
|
||||
* @return Is the buffer was released.
|
||||
* @return If any buffer was released.
|
||||
*/
|
||||
bool ReleaseBuffers(const Core::Timing::CoreTiming& core_timing, const DeviceSession& session) {
|
||||
bool ReleaseBuffers(const Core::Timing::CoreTiming& core_timing, const DeviceSession& session,
|
||||
bool force) {
|
||||
std::scoped_lock l{lock};
|
||||
bool buffer_released{false};
|
||||
while (registered_count > 0) {
|
||||
@@ -103,7 +104,8 @@ public:
|
||||
}
|
||||
|
||||
// Check with the backend if this buffer can be released yet.
|
||||
if (!session.IsBufferConsumed(buffers[index])) {
|
||||
// If we're shutting down, we don't care if it's been played or not.
|
||||
if (!force && !session.IsBufferConsumed(buffers[index])) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,12 @@ void DeviceSession::Stop() {
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceSession::ClearBuffers() {
|
||||
if (stream) {
|
||||
stream->ClearQueue();
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) const {
|
||||
for (const auto& buffer : buffers) {
|
||||
Sink::SinkBuffer new_buffer{
|
||||
|
||||
@@ -90,6 +90,11 @@ public:
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
* Clear out the underlying audio buffers in the backend stream.
|
||||
*/
|
||||
void ClearBuffers();
|
||||
|
||||
/**
|
||||
* Set this device session's volume.
|
||||
*
|
||||
|
||||
@@ -23,7 +23,6 @@ System::~System() {
|
||||
void System::Finalize() {
|
||||
Stop();
|
||||
session->Finalize();
|
||||
buffer_event->Signal();
|
||||
}
|
||||
|
||||
void System::StartSession() {
|
||||
@@ -102,6 +101,10 @@ Result System::Stop() {
|
||||
if (state == State::Started) {
|
||||
session->Stop();
|
||||
session->SetVolume(0.0f);
|
||||
session->ClearBuffers();
|
||||
if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
|
||||
buffer_event->Signal();
|
||||
}
|
||||
state = State::Stopped;
|
||||
}
|
||||
|
||||
@@ -138,7 +141,7 @@ void System::RegisterBuffers() {
|
||||
}
|
||||
|
||||
void System::ReleaseBuffers() {
|
||||
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session)};
|
||||
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)};
|
||||
|
||||
if (signal) {
|
||||
// Signal if any buffer was released, or if none are registered, we need more.
|
||||
|
||||
@@ -24,7 +24,6 @@ System::~System() {
|
||||
void System::Finalize() {
|
||||
Stop();
|
||||
session->Finalize();
|
||||
buffer_event->Signal();
|
||||
}
|
||||
|
||||
std::string_view System::GetDefaultOutputDeviceName() const {
|
||||
@@ -102,6 +101,10 @@ Result System::Stop() {
|
||||
if (state == State::Started) {
|
||||
session->Stop();
|
||||
session->SetVolume(0.0f);
|
||||
session->ClearBuffers();
|
||||
if (buffers.ReleaseBuffers(system.CoreTiming(), *session, true)) {
|
||||
buffer_event->Signal();
|
||||
}
|
||||
state = State::Stopped;
|
||||
}
|
||||
|
||||
@@ -138,7 +141,7 @@ void System::RegisterBuffers() {
|
||||
}
|
||||
|
||||
void System::ReleaseBuffers() {
|
||||
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session)};
|
||||
bool signal{buffers.ReleaseBuffers(system.CoreTiming(), *session, false)};
|
||||
if (signal) {
|
||||
// Signal if any buffer was released, or if none are registered, we need more.
|
||||
buffer_event->Signal();
|
||||
|
||||
6
src/audio_core/precompiled_headers.h
Normal file
6
src/audio_core/precompiled_headers.h
Normal file
@@ -0,0 +1,6 @@
|
||||
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_precompiled_headers.h"
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "audio_core/renderer/adsp/command_list_processor.h"
|
||||
#include "audio_core/renderer/command/effect/i3dl2_reverb.h"
|
||||
#include "common/polyfill_ranges.h"
|
||||
|
||||
namespace AudioCore::AudioRenderer {
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "audio_core/renderer/adsp/command_list_processor.h"
|
||||
#include "audio_core/renderer/command/effect/reverb.h"
|
||||
#include "common/polyfill_ranges.h"
|
||||
|
||||
namespace AudioCore::AudioRenderer {
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "audio_core/renderer/mix/mix_context.h"
|
||||
#include "audio_core/renderer/splitter/splitter_context.h"
|
||||
#include "common/polyfill_ranges.h"
|
||||
|
||||
namespace AudioCore::AudioRenderer {
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ class CommandGenerator;
|
||||
*/
|
||||
class DetailAspect {
|
||||
public:
|
||||
DetailAspect() = default;
|
||||
DetailAspect(CommandGenerator& command_generator, PerformanceEntryType entry_type, s32 node_id,
|
||||
PerformanceDetailType detail_type);
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ class CommandGenerator;
|
||||
*/
|
||||
class EntryAspect {
|
||||
public:
|
||||
EntryAspect() = default;
|
||||
EntryAspect(CommandGenerator& command_generator, PerformanceEntryType type, s32 node_id);
|
||||
|
||||
/// Command generator the command will be generated into
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <ranges>
|
||||
|
||||
#include "audio_core/renderer/voice/voice_context.h"
|
||||
#include "common/polyfill_ranges.h"
|
||||
|
||||
namespace AudioCore::AudioRenderer {
|
||||
|
||||
|
||||
@@ -170,8 +170,8 @@ void SinkStream::ProcessAudioIn(std::span<const s16> input_buffer, std::size_t n
|
||||
|
||||
// Get the minimum frames available between the currently playing buffer, and the
|
||||
// amount we have left to fill
|
||||
size_t frames_available{std::min(playing_buffer.frames - playing_buffer.frames_played,
|
||||
num_frames - frames_written)};
|
||||
size_t frames_available{std::min<u64>(playing_buffer.frames - playing_buffer.frames_played,
|
||||
num_frames - frames_written)};
|
||||
|
||||
samples_buffer.Push(&input_buffer[frames_written * frame_size],
|
||||
frames_available * frame_size);
|
||||
@@ -241,8 +241,8 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz
|
||||
|
||||
// Get the minimum frames available between the currently playing buffer, and the
|
||||
// amount we have left to fill
|
||||
size_t frames_available{std::min(playing_buffer.frames - playing_buffer.frames_played,
|
||||
num_frames - frames_written)};
|
||||
size_t frames_available{std::min<u64>(playing_buffer.frames - playing_buffer.frames_played,
|
||||
num_frames - frames_written)};
|
||||
|
||||
samples_buffer.Pop(&output_buffer[frames_written * frame_size],
|
||||
frames_available * frame_size);
|
||||
|
||||
@@ -34,9 +34,8 @@ add_library(common STATIC
|
||||
bit_util.h
|
||||
cityhash.cpp
|
||||
cityhash.h
|
||||
cache_management.cpp
|
||||
cache_management.h
|
||||
common_funcs.h
|
||||
common_precompiled_headers.h
|
||||
common_types.h
|
||||
concepts.h
|
||||
div_ceil.h
|
||||
@@ -79,6 +78,7 @@ add_library(common STATIC
|
||||
logging/types.h
|
||||
lz4_compression.cpp
|
||||
lz4_compression.h
|
||||
make_unique_for_overwrite.h
|
||||
math_util.h
|
||||
memory_detect.cpp
|
||||
memory_detect.h
|
||||
@@ -95,12 +95,14 @@ add_library(common STATIC
|
||||
param_package.h
|
||||
parent_of_member.h
|
||||
point.h
|
||||
precompiled_headers.h
|
||||
quaternion.h
|
||||
reader_writer_queue.h
|
||||
ring_buffer.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/scm_rev.cpp
|
||||
scm_rev.h
|
||||
scope_exit.h
|
||||
scratch_buffer.h
|
||||
settings.cpp
|
||||
settings.h
|
||||
settings_input.cpp
|
||||
@@ -147,7 +149,7 @@ if(ARCHITECTURE_x86_64)
|
||||
x64/xbyak_abi.h
|
||||
x64/xbyak_util.h
|
||||
)
|
||||
target_link_libraries(common PRIVATE xbyak)
|
||||
target_link_libraries(common PRIVATE xbyak::xbyak)
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
@@ -172,14 +174,8 @@ endif()
|
||||
create_target_directory_groups(common)
|
||||
|
||||
target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile Threads::Threads)
|
||||
if (TARGET lz4::lz4)
|
||||
target_link_libraries(common PRIVATE lz4::lz4)
|
||||
else()
|
||||
target_link_libraries(common PRIVATE LZ4::lz4_shared)
|
||||
endif()
|
||||
if (TARGET zstd::zstd)
|
||||
target_link_libraries(common PRIVATE zstd::zstd)
|
||||
else()
|
||||
target_link_libraries(common PRIVATE
|
||||
$<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
|
||||
target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd)
|
||||
|
||||
if (YUZU_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(common PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
@@ -69,7 +69,7 @@ void assert_fail_impl();
|
||||
#define ASSERT_OR_EXECUTE(_a_, _b_) \
|
||||
do { \
|
||||
ASSERT(_a_); \
|
||||
if (!(_a_)) { \
|
||||
if (!(_a_)) [[unlikely]] { \
|
||||
_b_ \
|
||||
} \
|
||||
} while (0)
|
||||
@@ -78,7 +78,7 @@ void assert_fail_impl();
|
||||
#define ASSERT_OR_EXECUTE_MSG(_a_, _b_, ...) \
|
||||
do { \
|
||||
ASSERT_MSG(_a_, __VA_ARGS__); \
|
||||
if (!(_a_)) { \
|
||||
if (!(_a_)) [[unlikely]] { \
|
||||
_b_ \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include "common/cache_management.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
#if defined(ARCHITECTURE_x86_64)
|
||||
|
||||
// Most cache operations are no-ops on x86
|
||||
|
||||
void DataCacheLineCleanByVAToPoU(void* start, size_t size) {}
|
||||
void DataCacheLineCleanAndInvalidateByVAToPoC(void* start, size_t size) {}
|
||||
void DataCacheLineCleanByVAToPoC(void* start, size_t size) {}
|
||||
void DataCacheZeroByVA(void* start, size_t size) {
|
||||
std::memset(start, 0, size);
|
||||
}
|
||||
|
||||
#elif defined(ARCHITECTURE_arm64)
|
||||
|
||||
// BS/DminLine is log2(cache size in words), we want size in bytes
|
||||
#define EXTRACT_DMINLINE(ctr_el0) (1 << ((((ctr_el0) >> 16) & 0xf) + 2))
|
||||
#define EXTRACT_BS(dczid_el0) (1 << (((dczid_el0)&0xf) + 2))
|
||||
|
||||
#define DEFINE_DC_OP(op_name, function_name) \
|
||||
void function_name(void* start, size_t size) { \
|
||||
size_t ctr_el0; \
|
||||
asm volatile("mrs %[ctr_el0], ctr_el0\n\t" : [ctr_el0] "=r"(ctr_el0)); \
|
||||
size_t cacheline_size = EXTRACT_DMINLINE(ctr_el0); \
|
||||
uintptr_t va_start = reinterpret_cast<uintptr_t>(start); \
|
||||
uintptr_t va_end = va_start + size; \
|
||||
for (uintptr_t va = va_start; va < va_end; va += cacheline_size) { \
|
||||
asm volatile("dc " #op_name ", %[va]\n\t" : : [va] "r"(va) : "memory"); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFINE_DC_OP_DCZID(op_name, function_name) \
|
||||
void function_name(void* start, size_t size) { \
|
||||
size_t dczid_el0; \
|
||||
asm volatile("mrs %[dczid_el0], dczid_el0\n\t" : [dczid_el0] "=r"(dczid_el0)); \
|
||||
size_t cacheline_size = EXTRACT_BS(dczid_el0); \
|
||||
uintptr_t va_start = reinterpret_cast<uintptr_t>(start); \
|
||||
uintptr_t va_end = va_start + size; \
|
||||
for (uintptr_t va = va_start; va < va_end; va += cacheline_size) { \
|
||||
asm volatile("dc " #op_name ", %[va]\n\t" : : [va] "r"(va) : "memory"); \
|
||||
} \
|
||||
}
|
||||
|
||||
DEFINE_DC_OP(cvau, DataCacheLineCleanByVAToPoU);
|
||||
DEFINE_DC_OP(civac, DataCacheLineCleanAndInvalidateByVAToPoC);
|
||||
DEFINE_DC_OP(cvac, DataCacheLineCleanByVAToPoC);
|
||||
DEFINE_DC_OP_DCZID(zva, DataCacheZeroByVA);
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace Common
|
||||
@@ -1,27 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace Common {
|
||||
|
||||
// Data cache instructions enabled at EL0 by SCTLR_EL1.UCI.
|
||||
// VA = virtual address
|
||||
// PoC = point of coherency
|
||||
// PoU = point of unification
|
||||
|
||||
// dc cvau
|
||||
void DataCacheLineCleanByVAToPoU(void* start, size_t size);
|
||||
|
||||
// dc civac
|
||||
void DataCacheLineCleanAndInvalidateByVAToPoC(void* start, size_t size);
|
||||
|
||||
// dc cvac
|
||||
void DataCacheLineCleanByVAToPoC(void* start, size_t size);
|
||||
|
||||
// dc zva
|
||||
void DataCacheZeroByVA(void* start, size_t size);
|
||||
|
||||
} // namespace Common
|
||||
14
src/common/common_precompiled_headers.h
Normal file
14
src/common/common_precompiled_headers.h
Normal file
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/common_types.h"
|
||||
@@ -1,6 +1,8 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "common/fs/file.h"
|
||||
#include "common/fs/fs.h"
|
||||
#include "common/logging/log.h"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "common/fs/fs_util.h"
|
||||
#include "common/polyfill_ranges.h"
|
||||
|
||||
namespace Common::FS {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common/fs/fs.h"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "common/logging/log.h"
|
||||
#include "common/param_package.h"
|
||||
#include "common/uuid.h"
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <climits>
|
||||
#include <stop_token>
|
||||
#include <thread>
|
||||
|
||||
#include <fmt/format.h>
|
||||
@@ -18,6 +17,7 @@
|
||||
#include "common/fs/fs_paths.h"
|
||||
#include "common/fs/path_util.h"
|
||||
#include "common/literals.h"
|
||||
#include "common/polyfill_thread.h"
|
||||
#include "common/thread.h"
|
||||
|
||||
#include "common/logging/backend.h"
|
||||
|
||||
25
src/common/make_unique_for_overwrite.h
Normal file
25
src/common/make_unique_for_overwrite.h
Normal file
@@ -0,0 +1,25 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Common {
|
||||
|
||||
template <class T>
|
||||
requires(!std::is_array_v<T>) std::unique_ptr<T> make_unique_for_overwrite() {
|
||||
return std::unique_ptr<T>(new T);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
requires std::is_unbounded_array_v<T> std::unique_ptr<T> make_unique_for_overwrite(std::size_t n) {
|
||||
return std::unique_ptr<T>(new std::remove_extent_t<T>[n]);
|
||||
}
|
||||
|
||||
template <class T, class... Args>
|
||||
requires std::is_bounded_array_v<T>
|
||||
void make_unique_for_overwrite(Args&&...) = delete;
|
||||
|
||||
} // namespace Common
|
||||
530
src/common/polyfill_ranges.h
Normal file
530
src/common/polyfill_ranges.h
Normal file
@@ -0,0 +1,530 @@
|
||||
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
//
|
||||
// TODO: remove this file when ranges are supported by all compilation targets
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <version>
|
||||
|
||||
#ifndef __cpp_lib_ranges
|
||||
|
||||
namespace std {
|
||||
namespace ranges {
|
||||
|
||||
template <typename T>
|
||||
concept range = requires(T& t) {
|
||||
begin(t);
|
||||
end(t);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
concept input_range = range<T>;
|
||||
|
||||
template <typename T>
|
||||
concept output_range = range<T>;
|
||||
|
||||
template <range R>
|
||||
using range_difference_t = ptrdiff_t;
|
||||
|
||||
//
|
||||
// find, find_if, find_if_not
|
||||
//
|
||||
|
||||
struct find_fn {
|
||||
template <typename Iterator, typename T, typename Proj = std::identity>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, const T& value,
|
||||
Proj proj = {}) const {
|
||||
for (; first != last; ++first) {
|
||||
if (std::invoke(proj, *first) == value) {
|
||||
return first;
|
||||
}
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename T, typename Proj = std::identity>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, const T& value, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), value, std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
struct find_if_fn {
|
||||
template <typename Iterator, typename Proj = std::identity, typename Pred>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, Pred pred, Proj proj = {}) const {
|
||||
for (; first != last; ++first) {
|
||||
if (std::invoke(pred, std::invoke(proj, *first))) {
|
||||
return first;
|
||||
}
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Proj = std::identity, typename Pred>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, Pred pred, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
struct find_if_not_fn {
|
||||
template <typename Iterator, typename Proj = std::identity, typename Pred>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, Pred pred, Proj proj = {}) const {
|
||||
for (; first != last; ++first) {
|
||||
if (!std::invoke(pred, std::invoke(proj, *first))) {
|
||||
return first;
|
||||
}
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Proj = std::identity, typename Pred>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, Pred pred, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr find_fn find;
|
||||
inline constexpr find_if_fn find_if;
|
||||
inline constexpr find_if_not_fn find_if_not;
|
||||
|
||||
//
|
||||
// any_of, all_of, none_of
|
||||
//
|
||||
|
||||
struct all_of_fn {
|
||||
template <typename Iterator, typename Proj = std::identity, typename Pred>
|
||||
constexpr bool operator()(Iterator first, Iterator last, Pred pred, Proj proj = {}) const {
|
||||
return ranges::find_if_not(first, last, std::ref(pred), std::ref(proj)) == last;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Proj = std::identity, typename Pred>
|
||||
constexpr bool operator()(R&& r, Pred pred, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
struct any_of_fn {
|
||||
template <typename Iterator, typename Proj = std::identity, typename Pred>
|
||||
constexpr bool operator()(Iterator first, Iterator last, Pred pred, Proj proj = {}) const {
|
||||
return ranges::find_if(first, last, std::ref(pred), std::ref(proj)) != last;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Proj = std::identity, typename Pred>
|
||||
constexpr bool operator()(R&& r, Pred pred, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
struct none_of_fn {
|
||||
template <typename Iterator, typename Proj = std::identity, typename Pred>
|
||||
constexpr bool operator()(Iterator first, Iterator last, Pred pred, Proj proj = {}) const {
|
||||
return ranges::find_if(first, last, std::ref(pred), std::ref(proj)) == last;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Proj = std::identity, typename Pred>
|
||||
constexpr bool operator()(R&& r, Pred pred, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr any_of_fn any_of;
|
||||
inline constexpr all_of_fn all_of;
|
||||
inline constexpr none_of_fn none_of;
|
||||
|
||||
//
|
||||
// count, count_if
|
||||
//
|
||||
|
||||
struct count_fn {
|
||||
template <typename Iterator, typename T, typename Proj = std::identity>
|
||||
constexpr ptrdiff_t operator()(Iterator first, Iterator last, const T& value,
|
||||
Proj proj = {}) const {
|
||||
ptrdiff_t counter = 0;
|
||||
for (; first != last; ++first)
|
||||
if (std::invoke(proj, *first) == value)
|
||||
++counter;
|
||||
return counter;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename T, typename Proj = std::identity>
|
||||
constexpr ptrdiff_t operator()(R&& r, const T& value, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), value, std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
struct count_if_fn {
|
||||
template <typename Iterator, typename Proj = std::identity, typename Pred>
|
||||
constexpr ptrdiff_t operator()(Iterator first, Iterator last, Pred pred, Proj proj = {}) const {
|
||||
ptrdiff_t counter = 0;
|
||||
for (; first != last; ++first)
|
||||
if (std::invoke(pred, std::invoke(proj, *first)))
|
||||
++counter;
|
||||
return counter;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Proj = std::identity, typename Pred>
|
||||
constexpr ptrdiff_t operator()(R&& r, Pred pred, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr count_fn count;
|
||||
inline constexpr count_if_fn count_if;
|
||||
|
||||
//
|
||||
// transform
|
||||
//
|
||||
|
||||
struct transform_fn {
|
||||
template <typename InputIterator, typename OutputIterator, typename F,
|
||||
typename Proj = std::identity>
|
||||
constexpr void operator()(InputIterator first1, InputIterator last1, OutputIterator result,
|
||||
F op, Proj proj = {}) const {
|
||||
for (; first1 != last1; ++first1, (void)++result) {
|
||||
*result = std::invoke(op, std::invoke(proj, *first1));
|
||||
}
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename OutputIterator, typename F,
|
||||
typename Proj = std::identity>
|
||||
constexpr void operator()(R&& r, OutputIterator result, F op, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), result, std::ref(op), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr transform_fn transform;
|
||||
|
||||
//
|
||||
// sort
|
||||
//
|
||||
|
||||
struct sort_fn {
|
||||
template <typename Iterator, typename Comp = ranges::less, typename Proj = std::identity>
|
||||
constexpr void operator()(Iterator first, Iterator last, Comp comp = {}, Proj proj = {}) const {
|
||||
if (first == last)
|
||||
return;
|
||||
|
||||
Iterator last_iter = ranges::next(first, last);
|
||||
std::sort(first, last_iter,
|
||||
[&](auto& lhs, auto& rhs) { return comp(proj(lhs), proj(rhs)); });
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Comp = ranges::less, typename Proj = std::identity>
|
||||
constexpr void operator()(R&& r, Comp comp = {}, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::move(comp), std::move(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr sort_fn sort;
|
||||
|
||||
//
|
||||
// fill
|
||||
//
|
||||
|
||||
struct fill_fn {
|
||||
template <typename T, typename OutputIterator>
|
||||
constexpr OutputIterator operator()(OutputIterator first, OutputIterator last,
|
||||
const T& value) const {
|
||||
while (first != last) {
|
||||
*first++ = value;
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
template <typename T, ranges::output_range R>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, const T& value) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), value);
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr fill_fn fill;
|
||||
|
||||
//
|
||||
// for_each
|
||||
//
|
||||
|
||||
struct for_each_fn {
|
||||
template <typename Iterator, typename Proj = std::identity, typename Fun>
|
||||
constexpr void operator()(Iterator first, Iterator last, Fun f, Proj proj = {}) const {
|
||||
for (; first != last; ++first) {
|
||||
std::invoke(f, std::invoke(proj, *first));
|
||||
}
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Proj = std::identity, typename Fun>
|
||||
constexpr void operator()(R&& r, Fun f, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::move(f), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr for_each_fn for_each;
|
||||
|
||||
//
|
||||
// min_element, max_element
|
||||
//
|
||||
|
||||
struct min_element_fn {
|
||||
template <typename Iterator, typename Proj = std::identity, typename Comp = ranges::less>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, Comp comp = {},
|
||||
Proj proj = {}) const {
|
||||
if (first == last) {
|
||||
return last;
|
||||
}
|
||||
|
||||
auto smallest = first;
|
||||
++first;
|
||||
for (; first != last; ++first) {
|
||||
if (!std::invoke(comp, std::invoke(proj, *smallest), std::invoke(proj, *first))) {
|
||||
smallest = first;
|
||||
}
|
||||
}
|
||||
return smallest;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Proj = std::identity, typename Comp = ranges::less>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, Comp comp = {}, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::ref(comp), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
struct max_element_fn {
|
||||
template <typename Iterator, typename Proj = std::identity, typename Comp = ranges::less>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, Comp comp = {},
|
||||
Proj proj = {}) const {
|
||||
if (first == last) {
|
||||
return last;
|
||||
}
|
||||
|
||||
auto largest = first;
|
||||
++first;
|
||||
for (; first != last; ++first) {
|
||||
if (std::invoke(comp, std::invoke(proj, *largest), std::invoke(proj, *first))) {
|
||||
largest = first;
|
||||
}
|
||||
}
|
||||
return largest;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Proj = std::identity, typename Comp = ranges::less>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, Comp comp = {}, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::ref(comp), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr min_element_fn min_element;
|
||||
inline constexpr max_element_fn max_element;
|
||||
|
||||
//
|
||||
// replace, replace_if
|
||||
//
|
||||
|
||||
struct replace_fn {
|
||||
template <typename Iterator, typename T1, typename T2, typename Proj = std::identity>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, const T1& old_value,
|
||||
const T2& new_value, Proj proj = {}) const {
|
||||
for (; first != last; ++first) {
|
||||
if (old_value == std::invoke(proj, *first)) {
|
||||
*first = new_value;
|
||||
}
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename T1, typename T2, typename Proj = std::identity>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, const T1& old_value, const T2& new_value,
|
||||
Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), old_value, new_value, std::move(proj));
|
||||
}
|
||||
};
|
||||
|
||||
struct replace_if_fn {
|
||||
template <typename Iterator, typename T, typename Proj = std::identity, typename Pred>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, Pred pred, const T& new_value,
|
||||
Proj proj = {}) const {
|
||||
for (; first != last; ++first) {
|
||||
if (!!std::invoke(pred, std::invoke(proj, *first))) {
|
||||
*first = new_value;
|
||||
}
|
||||
}
|
||||
return std::move(first);
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename T, typename Proj = std::identity, typename Pred>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, Pred pred, const T& new_value,
|
||||
Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::move(pred), new_value,
|
||||
std::move(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr replace_fn replace;
|
||||
inline constexpr replace_if_fn replace_if;
|
||||
|
||||
//
|
||||
// copy, copy_if
|
||||
//
|
||||
|
||||
struct copy_fn {
|
||||
template <typename InputIterator, typename OutputIterator>
|
||||
constexpr void operator()(InputIterator first, InputIterator last,
|
||||
OutputIterator result) const {
|
||||
for (; first != last; ++first, (void)++result) {
|
||||
*result = *first;
|
||||
}
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename OutputIterator>
|
||||
constexpr void operator()(R&& r, OutputIterator result) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::move(result));
|
||||
}
|
||||
};
|
||||
|
||||
struct copy_if_fn {
|
||||
template <typename InputIterator, typename OutputIterator, typename Proj = std::identity,
|
||||
typename Pred>
|
||||
constexpr void operator()(InputIterator first, InputIterator last, OutputIterator result,
|
||||
Pred pred, Proj proj = {}) const {
|
||||
for (; first != last; ++first) {
|
||||
if (std::invoke(pred, std::invoke(proj, *first))) {
|
||||
*result = *first;
|
||||
++result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename OutputIterator, typename Proj = std::identity,
|
||||
typename Pred>
|
||||
constexpr void operator()(R&& r, OutputIterator result, Pred pred, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::move(result), std::ref(pred),
|
||||
std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr copy_fn copy;
|
||||
inline constexpr copy_if_fn copy_if;
|
||||
|
||||
//
|
||||
// generate
|
||||
//
|
||||
|
||||
struct generate_fn {
|
||||
template <typename Iterator, typename F>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, F gen) const {
|
||||
for (; first != last; *first = std::invoke(gen), ++first)
|
||||
;
|
||||
return first;
|
||||
}
|
||||
|
||||
template <typename R, std::copy_constructible F>
|
||||
requires std::invocable<F&> && ranges::output_range<R>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, F gen) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::move(gen));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr generate_fn generate;
|
||||
|
||||
//
|
||||
// lower_bound, upper_bound
|
||||
//
|
||||
|
||||
struct lower_bound_fn {
|
||||
template <typename Iterator, typename T, typename Proj = std::identity,
|
||||
typename Comp = ranges::less>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, const T& value, Comp comp = {},
|
||||
Proj proj = {}) const {
|
||||
Iterator it;
|
||||
std::ptrdiff_t _count, _step;
|
||||
_count = std::distance(first, last);
|
||||
|
||||
while (_count > 0) {
|
||||
it = first;
|
||||
_step = _count / 2;
|
||||
ranges::advance(it, _step, last);
|
||||
if (comp(std::invoke(proj, *it), value)) {
|
||||
first = ++it;
|
||||
_count -= _step + 1;
|
||||
} else {
|
||||
_count = _step;
|
||||
}
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename T, typename Proj = std::identity,
|
||||
typename Comp = ranges::less>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, const T& value, Comp comp = {},
|
||||
Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), value, std::ref(comp), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
struct upper_bound_fn {
|
||||
template <typename Iterator, typename T, typename Proj = std::identity,
|
||||
typename Comp = ranges::less>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, const T& value, Comp comp = {},
|
||||
Proj proj = {}) const {
|
||||
Iterator it;
|
||||
std::ptrdiff_t _count, _step;
|
||||
_count = std::distance(first, last);
|
||||
|
||||
while (_count > 0) {
|
||||
it = first;
|
||||
_step = _count / 2;
|
||||
ranges::advance(it, _step, last);
|
||||
if (!comp(value, std::invoke(proj, *it))) {
|
||||
first = ++it;
|
||||
_count -= _step + 1;
|
||||
} else {
|
||||
_count = _step;
|
||||
}
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename T, typename Proj = std::identity,
|
||||
typename Comp = ranges::less>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, const T& value, Comp comp = {},
|
||||
Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), value, std::ref(comp), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr lower_bound_fn lower_bound;
|
||||
inline constexpr upper_bound_fn upper_bound;
|
||||
|
||||
//
|
||||
// adjacent_find
|
||||
//
|
||||
|
||||
struct adjacent_find_fn {
|
||||
template <typename Iterator, typename Proj = std::identity, typename Pred = ranges::equal_to>
|
||||
constexpr Iterator operator()(Iterator first, Iterator last, Pred pred = {},
|
||||
Proj proj = {}) const {
|
||||
if (first == last)
|
||||
return first;
|
||||
auto _next = ranges::next(first);
|
||||
for (; _next != last; ++_next, ++first)
|
||||
if (std::invoke(pred, std::invoke(proj, *first), std::invoke(proj, *_next)))
|
||||
return first;
|
||||
return _next;
|
||||
}
|
||||
|
||||
template <ranges::input_range R, typename Proj = std::identity,
|
||||
typename Pred = ranges::equal_to>
|
||||
constexpr ranges::iterator_t<R> operator()(R&& r, Pred pred = {}, Proj proj = {}) const {
|
||||
return operator()(ranges::begin(r), ranges::end(r), std::ref(pred), std::ref(proj));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr adjacent_find_fn adjacent_find;
|
||||
|
||||
} // namespace ranges
|
||||
} // namespace std
|
||||
|
||||
#endif
|
||||
323
src/common/polyfill_thread.h
Normal file
323
src/common/polyfill_thread.h
Normal file
@@ -0,0 +1,323 @@
|
||||
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
//
|
||||
// TODO: remove this file when jthread is supported by all compilation targets
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <version>
|
||||
|
||||
#ifdef __cpp_lib_jthread
|
||||
|
||||
#include <stop_token>
|
||||
#include <thread>
|
||||
|
||||
namespace Common {
|
||||
|
||||
template <typename Condvar, typename Lock, typename Pred>
|
||||
void CondvarWait(Condvar& cv, Lock& lock, std::stop_token token, Pred&& pred) {
|
||||
cv.wait(lock, token, std::move(pred));
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
||||
#else
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
|
||||
namespace std {
|
||||
namespace polyfill {
|
||||
|
||||
using stop_state_callbacks = list<function<void()>>;
|
||||
|
||||
class stop_state {
|
||||
public:
|
||||
stop_state() = default;
|
||||
~stop_state() = default;
|
||||
|
||||
bool request_stop() {
|
||||
stop_state_callbacks callbacks;
|
||||
|
||||
{
|
||||
scoped_lock lk{m_lock};
|
||||
|
||||
if (m_stop_requested.load()) {
|
||||
// Already set, nothing to do
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set as requested
|
||||
m_stop_requested = true;
|
||||
|
||||
// Copy callback list
|
||||
callbacks = m_callbacks;
|
||||
}
|
||||
|
||||
for (auto callback : callbacks) {
|
||||
callback();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool stop_requested() const {
|
||||
return m_stop_requested.load();
|
||||
}
|
||||
|
||||
stop_state_callbacks::const_iterator insert_callback(function<void()> f) {
|
||||
stop_state_callbacks::const_iterator ret{};
|
||||
bool should_run{};
|
||||
|
||||
{
|
||||
scoped_lock lk{m_lock};
|
||||
should_run = m_stop_requested.load();
|
||||
m_callbacks.push_front(f);
|
||||
ret = m_callbacks.begin();
|
||||
}
|
||||
|
||||
if (should_run) {
|
||||
f();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void remove_callback(stop_state_callbacks::const_iterator it) {
|
||||
scoped_lock lk{m_lock};
|
||||
m_callbacks.erase(it);
|
||||
}
|
||||
|
||||
private:
|
||||
mutex m_lock;
|
||||
atomic<bool> m_stop_requested;
|
||||
stop_state_callbacks m_callbacks;
|
||||
};
|
||||
|
||||
} // namespace polyfill
|
||||
|
||||
class stop_token;
|
||||
class stop_source;
|
||||
struct nostopstate_t {
|
||||
explicit nostopstate_t() = default;
|
||||
};
|
||||
inline constexpr nostopstate_t nostopstate{};
|
||||
|
||||
template <class Callback>
|
||||
class stop_callback;
|
||||
|
||||
class stop_token {
|
||||
public:
|
||||
stop_token() noexcept = default;
|
||||
|
||||
stop_token(const stop_token&) noexcept = default;
|
||||
stop_token(stop_token&&) noexcept = default;
|
||||
stop_token& operator=(const stop_token&) noexcept = default;
|
||||
stop_token& operator=(stop_token&&) noexcept = default;
|
||||
~stop_token() = default;
|
||||
|
||||
void swap(stop_token& other) noexcept {
|
||||
m_stop_state.swap(other.m_stop_state);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool stop_requested() const noexcept {
|
||||
return m_stop_state && m_stop_state->stop_requested();
|
||||
}
|
||||
[[nodiscard]] bool stop_possible() const noexcept {
|
||||
return m_stop_state != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class stop_source;
|
||||
template <typename Callback>
|
||||
friend class stop_callback;
|
||||
stop_token(shared_ptr<polyfill::stop_state> stop_state) : m_stop_state(move(stop_state)) {}
|
||||
|
||||
private:
|
||||
shared_ptr<polyfill::stop_state> m_stop_state;
|
||||
};
|
||||
|
||||
class stop_source {
|
||||
public:
|
||||
stop_source() : m_stop_state(make_shared<polyfill::stop_state>()) {}
|
||||
explicit stop_source(nostopstate_t) noexcept {}
|
||||
|
||||
stop_source(const stop_source&) noexcept = default;
|
||||
stop_source(stop_source&&) noexcept = default;
|
||||
stop_source& operator=(const stop_source&) noexcept = default;
|
||||
stop_source& operator=(stop_source&&) noexcept = default;
|
||||
~stop_source() = default;
|
||||
void swap(stop_source& other) noexcept {
|
||||
m_stop_state.swap(other.m_stop_state);
|
||||
}
|
||||
|
||||
[[nodiscard]] stop_token get_token() const noexcept {
|
||||
return stop_token(m_stop_state);
|
||||
}
|
||||
[[nodiscard]] bool stop_possible() const noexcept {
|
||||
return m_stop_state != nullptr;
|
||||
}
|
||||
[[nodiscard]] bool stop_requested() const noexcept {
|
||||
return m_stop_state && m_stop_state->stop_requested();
|
||||
}
|
||||
bool request_stop() noexcept {
|
||||
return m_stop_state && m_stop_state->request_stop();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class jthread;
|
||||
explicit stop_source(shared_ptr<polyfill::stop_state> stop_state)
|
||||
: m_stop_state(move(stop_state)) {}
|
||||
|
||||
private:
|
||||
shared_ptr<polyfill::stop_state> m_stop_state;
|
||||
};
|
||||
|
||||
template <typename Callback>
|
||||
class stop_callback {
|
||||
static_assert(is_nothrow_destructible_v<Callback>);
|
||||
static_assert(is_invocable_v<Callback>);
|
||||
|
||||
public:
|
||||
using callback_type = Callback;
|
||||
|
||||
template <typename C>
|
||||
requires constructible_from<Callback, C>
|
||||
explicit stop_callback(const stop_token& st,
|
||||
C&& cb) noexcept(is_nothrow_constructible_v<Callback, C>)
|
||||
: m_stop_state(st.m_stop_state) {
|
||||
if (m_stop_state) {
|
||||
m_callback = m_stop_state->insert_callback(move(cb));
|
||||
}
|
||||
}
|
||||
template <typename C>
|
||||
requires constructible_from<Callback, C>
|
||||
explicit stop_callback(stop_token&& st,
|
||||
C&& cb) noexcept(is_nothrow_constructible_v<Callback, C>)
|
||||
: m_stop_state(move(st.m_stop_state)) {
|
||||
if (m_stop_state) {
|
||||
m_callback = m_stop_state->insert_callback(move(cb));
|
||||
}
|
||||
}
|
||||
~stop_callback() {
|
||||
if (m_stop_state && m_callback) {
|
||||
m_stop_state->remove_callback(*m_callback);
|
||||
}
|
||||
}
|
||||
|
||||
stop_callback(const stop_callback&) = delete;
|
||||
stop_callback(stop_callback&&) = delete;
|
||||
stop_callback& operator=(const stop_callback&) = delete;
|
||||
stop_callback& operator=(stop_callback&&) = delete;
|
||||
|
||||
private:
|
||||
shared_ptr<polyfill::stop_state> m_stop_state;
|
||||
optional<polyfill::stop_state_callbacks::const_iterator> m_callback;
|
||||
};
|
||||
|
||||
template <typename Callback>
|
||||
stop_callback(stop_token, Callback) -> stop_callback<Callback>;
|
||||
|
||||
class jthread {
|
||||
public:
|
||||
using id = thread::id;
|
||||
using native_handle_type = thread::native_handle_type;
|
||||
|
||||
jthread() noexcept = default;
|
||||
|
||||
template <typename F, typename... Args,
|
||||
typename = enable_if_t<!is_same_v<remove_cvref_t<F>, jthread>>>
|
||||
explicit jthread(F&& f, Args&&... args)
|
||||
: m_stop_state(make_shared<polyfill::stop_state>()),
|
||||
m_thread(make_thread(move(f), move(args)...)) {}
|
||||
|
||||
~jthread() {
|
||||
if (joinable()) {
|
||||
request_stop();
|
||||
join();
|
||||
}
|
||||
}
|
||||
|
||||
jthread(const jthread&) = delete;
|
||||
jthread(jthread&&) noexcept = default;
|
||||
jthread& operator=(const jthread&) = delete;
|
||||
|
||||
jthread& operator=(jthread&& other) noexcept {
|
||||
m_thread.swap(other.m_thread);
|
||||
m_stop_state.swap(other.m_stop_state);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(jthread& other) noexcept {
|
||||
m_thread.swap(other.m_thread);
|
||||
m_stop_state.swap(other.m_stop_state);
|
||||
}
|
||||
[[nodiscard]] bool joinable() const noexcept {
|
||||
return m_thread.joinable();
|
||||
}
|
||||
void join() {
|
||||
m_thread.join();
|
||||
}
|
||||
void detach() {
|
||||
m_thread.detach();
|
||||
m_stop_state.reset();
|
||||
}
|
||||
|
||||
[[nodiscard]] id get_id() const noexcept {
|
||||
return m_thread.get_id();
|
||||
}
|
||||
[[nodiscard]] native_handle_type native_handle() {
|
||||
return m_thread.native_handle();
|
||||
}
|
||||
[[nodiscard]] stop_source get_stop_source() noexcept {
|
||||
return stop_source(m_stop_state);
|
||||
}
|
||||
[[nodiscard]] stop_token get_stop_token() const noexcept {
|
||||
return stop_source(m_stop_state).get_token();
|
||||
}
|
||||
bool request_stop() noexcept {
|
||||
return get_stop_source().request_stop();
|
||||
}
|
||||
[[nodiscard]] static unsigned int hardware_concurrency() noexcept {
|
||||
return thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename F, typename... Args>
|
||||
thread make_thread(F&& f, Args&&... args) {
|
||||
if constexpr (is_invocable_v<decay_t<F>, stop_token, decay_t<Args>...>) {
|
||||
return thread(move(f), get_stop_token(), move(args)...);
|
||||
} else {
|
||||
return thread(move(f), move(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<polyfill::stop_state> m_stop_state;
|
||||
thread m_thread;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
namespace Common {
|
||||
|
||||
template <typename Condvar, typename Lock, typename Pred>
|
||||
void CondvarWait(Condvar& cv, Lock& lock, std::stop_token token, Pred pred) {
|
||||
if (token.stop_requested()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::stop_callback callback(token, [&] { cv.notify_all(); });
|
||||
cv.wait(lock, [&] { return pred() || token.stop_requested(); });
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
||||
#endif
|
||||
6
src/common/precompiled_headers.h
Normal file
6
src/common/precompiled_headers.h
Normal file
@@ -0,0 +1,6 @@
|
||||
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_precompiled_headers.h"
|
||||
95
src/common/scratch_buffer.h
Normal file
95
src/common/scratch_buffer.h
Normal file
@@ -0,0 +1,95 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/make_unique_for_overwrite.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
/**
|
||||
* ScratchBuffer class
|
||||
* This class creates a default initialized heap allocated buffer for cases such as intermediate
|
||||
* buffers being copied into entirely, where value initializing members during allocation or resize
|
||||
* is redundant.
|
||||
*/
|
||||
template <typename T>
|
||||
class ScratchBuffer {
|
||||
public:
|
||||
ScratchBuffer() = default;
|
||||
|
||||
explicit ScratchBuffer(size_t initial_capacity)
|
||||
: last_requested_size{initial_capacity}, buffer_capacity{initial_capacity},
|
||||
buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {}
|
||||
|
||||
~ScratchBuffer() = default;
|
||||
|
||||
/// This will only grow the buffer's capacity if size is greater than the current capacity.
|
||||
/// The previously held data will remain intact.
|
||||
void resize(size_t size) {
|
||||
if (size > buffer_capacity) {
|
||||
auto new_buffer = Common::make_unique_for_overwrite<T[]>(size);
|
||||
std::move(buffer.get(), buffer.get() + buffer_capacity, new_buffer.get());
|
||||
buffer = std::move(new_buffer);
|
||||
buffer_capacity = size;
|
||||
}
|
||||
last_requested_size = size;
|
||||
}
|
||||
|
||||
/// This will only grow the buffer's capacity if size is greater than the current capacity.
|
||||
/// The previously held data will be destroyed if a reallocation occurs.
|
||||
void resize_destructive(size_t size) {
|
||||
if (size > buffer_capacity) {
|
||||
buffer_capacity = size;
|
||||
buffer = Common::make_unique_for_overwrite<T[]>(buffer_capacity);
|
||||
}
|
||||
last_requested_size = size;
|
||||
}
|
||||
|
||||
[[nodiscard]] T* data() noexcept {
|
||||
return buffer.get();
|
||||
}
|
||||
|
||||
[[nodiscard]] const T* data() const noexcept {
|
||||
return buffer.get();
|
||||
}
|
||||
|
||||
[[nodiscard]] T* begin() noexcept {
|
||||
return data();
|
||||
}
|
||||
|
||||
[[nodiscard]] const T* begin() const noexcept {
|
||||
return data();
|
||||
}
|
||||
|
||||
[[nodiscard]] T* end() noexcept {
|
||||
return data() + last_requested_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] const T* end() const noexcept {
|
||||
return data() + last_requested_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] T& operator[](size_t i) {
|
||||
return buffer[i];
|
||||
}
|
||||
|
||||
[[nodiscard]] const T& operator[](size_t i) const {
|
||||
return buffer[i];
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t size() const noexcept {
|
||||
return last_requested_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t capacity() const noexcept {
|
||||
return buffer_capacity;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t last_requested_size{};
|
||||
size_t buffer_capacity{};
|
||||
std::unique_ptr<T[]> buffer{};
|
||||
};
|
||||
|
||||
} // namespace Common
|
||||
@@ -40,6 +40,7 @@ void LogSettings() {
|
||||
LOG_INFO(Config, "yuzu Configuration:");
|
||||
log_setting("Controls_UseDockedMode", values.use_docked_mode.GetValue());
|
||||
log_setting("System_RngSeed", values.rng_seed.GetValue().value_or(0));
|
||||
log_setting("System_DeviceName", values.device_name.GetValue());
|
||||
log_setting("System_CurrentUser", values.current_user.GetValue());
|
||||
log_setting("System_LanguageIndex", values.language_index.GetValue());
|
||||
log_setting("System_RegionIndex", values.region_index.GetValue());
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace Settings {
|
||||
enum class RendererBackend : u32 {
|
||||
OpenGL = 0,
|
||||
Vulkan = 1,
|
||||
Null = 2,
|
||||
};
|
||||
|
||||
enum class ShaderBackend : u32 {
|
||||
@@ -75,7 +76,8 @@ enum class ScalingFilter : u32 {
|
||||
enum class AntiAliasing : u32 {
|
||||
None = 0,
|
||||
Fxaa = 1,
|
||||
LastAA = Fxaa,
|
||||
Smaa = 2,
|
||||
LastAA = Smaa,
|
||||
};
|
||||
|
||||
struct ResolutionScalingInfo {
|
||||
@@ -399,6 +401,7 @@ struct Values {
|
||||
Setting<bool> cpuopt_fastmem{true, "cpuopt_fastmem"};
|
||||
Setting<bool> cpuopt_fastmem_exclusives{true, "cpuopt_fastmem_exclusives"};
|
||||
Setting<bool> cpuopt_recompile_exclusives{true, "cpuopt_recompile_exclusives"};
|
||||
Setting<bool> cpuopt_ignore_memory_aborts{true, "cpuopt_ignore_memory_aborts"};
|
||||
|
||||
SwitchableSetting<bool> cpuopt_unsafe_unfuse_fma{true, "cpuopt_unsafe_unfuse_fma"};
|
||||
SwitchableSetting<bool> cpuopt_unsafe_reduce_fp_error{true, "cpuopt_unsafe_reduce_fp_error"};
|
||||
@@ -411,7 +414,7 @@ struct Values {
|
||||
|
||||
// Renderer
|
||||
SwitchableSetting<RendererBackend, true> renderer_backend{
|
||||
RendererBackend::Vulkan, RendererBackend::OpenGL, RendererBackend::Vulkan, "backend"};
|
||||
RendererBackend::Vulkan, RendererBackend::OpenGL, RendererBackend::Null, "backend"};
|
||||
Setting<bool> renderer_debug{false, "debug"};
|
||||
Setting<bool> renderer_shader_feedback{false, "shader_feedback"};
|
||||
Setting<bool> enable_nsight_aftermath{false, "nsight_aftermath"};
|
||||
@@ -455,6 +458,7 @@ struct Values {
|
||||
|
||||
// System
|
||||
SwitchableSetting<std::optional<u32>> rng_seed{std::optional<u32>(), "rng_seed"};
|
||||
Setting<std::string> device_name{"Yuzu", "device_name"};
|
||||
// Measured in seconds since epoch
|
||||
std::optional<s64> custom_rtc;
|
||||
// Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc`
|
||||
|
||||
@@ -391,6 +391,7 @@ struct PlayerInput {
|
||||
u32 body_color_right;
|
||||
u32 button_color_left;
|
||||
u32 button_color_right;
|
||||
std::string profile_name;
|
||||
};
|
||||
|
||||
struct TouchscreenInput {
|
||||
|
||||
@@ -141,7 +141,7 @@ static std::wstring CPToUTF16(u32 code_page, const std::string& input) {
|
||||
MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0);
|
||||
|
||||
if (size == 0) {
|
||||
return L"";
|
||||
return {};
|
||||
}
|
||||
|
||||
std::wstring output(size, L'\0');
|
||||
@@ -158,7 +158,7 @@ std::string UTF16ToUTF8(const std::wstring& input) {
|
||||
const auto size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()),
|
||||
nullptr, 0, nullptr, nullptr);
|
||||
if (size == 0) {
|
||||
return "";
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string output(size, '\0');
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include "common/common_types.h"
|
||||
#include "common/polyfill_thread.h"
|
||||
|
||||
namespace Common {
|
||||
|
||||
@@ -69,7 +70,7 @@ public:
|
||||
explicit Barrier(std::size_t count_) : count(count_) {}
|
||||
|
||||
/// Blocks until all "count" threads have called Sync()
|
||||
void Sync() {
|
||||
bool Sync(std::stop_token token = {}) {
|
||||
std::unique_lock lk{mutex};
|
||||
const std::size_t current_generation = generation;
|
||||
|
||||
@@ -77,14 +78,16 @@ public:
|
||||
generation++;
|
||||
waiting = 0;
|
||||
condvar.notify_all();
|
||||
return true;
|
||||
} else {
|
||||
condvar.wait(lk,
|
||||
[this, current_generation] { return current_generation != generation; });
|
||||
CondvarWait(condvar, lk, token,
|
||||
[this, current_generation] { return current_generation != generation; });
|
||||
return !token.stop_requested();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::condition_variable condvar;
|
||||
std::condition_variable_any condvar;
|
||||
std::mutex mutex;
|
||||
std::size_t count;
|
||||
std::size_t waiting = 0;
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
#include "common/polyfill_thread.h"
|
||||
#include "common/thread.h"
|
||||
#include "common/unique_function.h"
|
||||
|
||||
@@ -47,7 +47,8 @@ public:
|
||||
if (requests.empty()) {
|
||||
wait_condition.notify_all();
|
||||
}
|
||||
condition.wait(lock, stop_token, [this] { return !requests.empty(); });
|
||||
Common::CondvarWait(condition, lock, stop_token,
|
||||
[this] { return !requests.empty(); });
|
||||
if (stop_token.stop_requested()) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
|
||||
#include "common/polyfill_thread.h"
|
||||
|
||||
namespace Common {
|
||||
template <typename T, bool with_stop_token = false>
|
||||
class SPSCQueue {
|
||||
@@ -97,7 +99,7 @@ public:
|
||||
T PopWait(std::stop_token stop_token) {
|
||||
if (Empty()) {
|
||||
std::unique_lock lock{cv_mutex};
|
||||
cv.wait(lock, stop_token, [this] { return !Empty(); });
|
||||
Common::CondvarWait(cv, lock, stop_token, [this] { return !Empty(); });
|
||||
}
|
||||
if (stop_token.stop_requested()) {
|
||||
return T{};
|
||||
|
||||
@@ -201,6 +201,9 @@ add_library(core STATIC
|
||||
hle/kernel/k_event_info.h
|
||||
hle/kernel/k_handle_table.cpp
|
||||
hle/kernel/k_handle_table.h
|
||||
hle/kernel/k_hardware_timer_base.h
|
||||
hle/kernel/k_hardware_timer.cpp
|
||||
hle/kernel/k_hardware_timer.h
|
||||
hle/kernel/k_interrupt_manager.cpp
|
||||
hle/kernel/k_interrupt_manager.h
|
||||
hle/kernel/k_light_condition_variable.cpp
|
||||
@@ -223,6 +226,7 @@ add_library(core STATIC
|
||||
hle/kernel/k_page_buffer.h
|
||||
hle/kernel/k_page_heap.cpp
|
||||
hle/kernel/k_page_heap.h
|
||||
hle/kernel/k_page_group.cpp
|
||||
hle/kernel/k_page_group.h
|
||||
hle/kernel/k_page_table.cpp
|
||||
hle/kernel/k_page_table.h
|
||||
@@ -268,6 +272,7 @@ add_library(core STATIC
|
||||
hle/kernel/k_thread_local_page.h
|
||||
hle/kernel/k_thread_queue.cpp
|
||||
hle/kernel/k_thread_queue.h
|
||||
hle/kernel/k_timer_task.h
|
||||
hle/kernel/k_trace.h
|
||||
hle/kernel/k_transfer_memory.cpp
|
||||
hle/kernel/k_transfer_memory.h
|
||||
@@ -290,8 +295,6 @@ add_library(core STATIC
|
||||
hle/kernel/svc_common.h
|
||||
hle/kernel/svc_types.h
|
||||
hle/kernel/svc_wrap.h
|
||||
hle/kernel/time_manager.cpp
|
||||
hle/kernel/time_manager.h
|
||||
hle/result.h
|
||||
hle/service/acc/acc.cpp
|
||||
hle/service/acc/acc.h
|
||||
@@ -528,6 +531,8 @@ add_library(core STATIC
|
||||
hle/service/mnpp/mnpp_app.h
|
||||
hle/service/ncm/ncm.cpp
|
||||
hle/service/ncm/ncm.h
|
||||
hle/service/nfc/mifare_user.cpp
|
||||
hle/service/nfc/mifare_user.h
|
||||
hle/service/nfc/nfc.cpp
|
||||
hle/service/nfc/nfc.h
|
||||
hle/service/nfc/nfc_device.cpp
|
||||
@@ -771,6 +776,7 @@ add_library(core STATIC
|
||||
memory.h
|
||||
perf_stats.cpp
|
||||
perf_stats.h
|
||||
precompiled_headers.h
|
||||
reporter.cpp
|
||||
reporter.h
|
||||
telemetry_session.cpp
|
||||
@@ -823,5 +829,9 @@ if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64)
|
||||
hle/service/jit/jit.cpp
|
||||
hle/service/jit/jit.h
|
||||
)
|
||||
target_link_libraries(core PRIVATE dynarmic)
|
||||
target_link_libraries(core PRIVATE dynarmic::dynarmic)
|
||||
endif()
|
||||
|
||||
if (YUZU_USE_PRECOMPILED_HEADERS)
|
||||
target_precompile_headers(core PRIVATE precompiled_headers.h)
|
||||
endif()
|
||||
|
||||
@@ -145,11 +145,15 @@ void ARM_Interface::Run() {
|
||||
// Notify the debugger and go to sleep if a breakpoint was hit,
|
||||
// or if the thread is unable to continue for any reason.
|
||||
if (Has(hr, breakpoint) || Has(hr, no_execute)) {
|
||||
RewindBreakpointInstruction();
|
||||
if (!Has(hr, no_execute)) {
|
||||
RewindBreakpointInstruction();
|
||||
}
|
||||
if (system.DebuggerEnabled()) {
|
||||
system.GetDebugger().NotifyThreadStopped(current_thread);
|
||||
} else {
|
||||
LogBacktrace();
|
||||
}
|
||||
current_thread->RequestSuspend(Kernel::SuspendType::Debug);
|
||||
current_thread->RequestSuspend(SuspendType::Debug);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,9 @@ class DynarmicCallbacks32 : public Dynarmic::A32::UserCallbacks {
|
||||
public:
|
||||
explicit DynarmicCallbacks32(ARM_Dynarmic_32& parent_)
|
||||
: parent{parent_},
|
||||
memory(parent.system.Memory()), debugger_enabled{parent.system.DebuggerEnabled()} {}
|
||||
memory(parent.system.Memory()), debugger_enabled{parent.system.DebuggerEnabled()},
|
||||
check_memory_access{debugger_enabled ||
|
||||
!Settings::values.cpuopt_ignore_memory_aborts.GetValue()} {}
|
||||
|
||||
u8 MemoryRead8(u32 vaddr) override {
|
||||
CheckMemoryAccess(vaddr, 1, Kernel::DebugWatchpointType::Read);
|
||||
@@ -154,6 +156,17 @@ public:
|
||||
}
|
||||
|
||||
bool CheckMemoryAccess(VAddr addr, u64 size, Kernel::DebugWatchpointType type) {
|
||||
if (!check_memory_access) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memory.IsValidVirtualAddressRange(addr, size)) {
|
||||
LOG_CRITICAL(Core_ARM, "Stopping execution due to unmapped memory access at {:#x}",
|
||||
addr);
|
||||
parent.jit.load()->HaltExecution(ARM_Interface::no_execute);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!debugger_enabled) {
|
||||
return true;
|
||||
}
|
||||
@@ -181,7 +194,8 @@ public:
|
||||
ARM_Dynarmic_32& parent;
|
||||
Core::Memory::Memory& memory;
|
||||
std::size_t num_interpreted_instructions{};
|
||||
bool debugger_enabled{};
|
||||
const bool debugger_enabled{};
|
||||
const bool check_memory_access{};
|
||||
static constexpr u64 minimum_run_cycles = 10000U;
|
||||
};
|
||||
|
||||
@@ -264,6 +278,9 @@ std::shared_ptr<Dynarmic::A32::Jit> ARM_Dynarmic_32::MakeJit(Common::PageTable*
|
||||
if (!Settings::values.cpuopt_recompile_exclusives) {
|
||||
config.recompile_on_exclusive_fastmem_failure = false;
|
||||
}
|
||||
if (!Settings::values.cpuopt_ignore_memory_aborts) {
|
||||
config.check_halt_on_memory_access = true;
|
||||
}
|
||||
} else {
|
||||
// Unsafe optimizations
|
||||
if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::Unsafe) {
|
||||
|
||||
@@ -29,7 +29,9 @@ class DynarmicCallbacks64 : public Dynarmic::A64::UserCallbacks {
|
||||
public:
|
||||
explicit DynarmicCallbacks64(ARM_Dynarmic_64& parent_)
|
||||
: parent{parent_},
|
||||
memory(parent.system.Memory()), debugger_enabled{parent.system.DebuggerEnabled()} {}
|
||||
memory(parent.system.Memory()), debugger_enabled{parent.system.DebuggerEnabled()},
|
||||
check_memory_access{debugger_enabled ||
|
||||
!Settings::values.cpuopt_ignore_memory_aborts.GetValue()} {}
|
||||
|
||||
u8 MemoryRead8(u64 vaddr) override {
|
||||
CheckMemoryAccess(vaddr, 1, Kernel::DebugWatchpointType::Read);
|
||||
@@ -198,6 +200,17 @@ public:
|
||||
}
|
||||
|
||||
bool CheckMemoryAccess(VAddr addr, u64 size, Kernel::DebugWatchpointType type) {
|
||||
if (!check_memory_access) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!memory.IsValidVirtualAddressRange(addr, size)) {
|
||||
LOG_CRITICAL(Core_ARM, "Stopping execution due to unmapped memory access at {:#x}",
|
||||
addr);
|
||||
parent.jit.load()->HaltExecution(ARM_Interface::no_execute);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!debugger_enabled) {
|
||||
return true;
|
||||
}
|
||||
@@ -226,7 +239,8 @@ public:
|
||||
Core::Memory::Memory& memory;
|
||||
u64 tpidrro_el0 = 0;
|
||||
u64 tpidr_el0 = 0;
|
||||
bool debugger_enabled{};
|
||||
const bool debugger_enabled{};
|
||||
const bool check_memory_access{};
|
||||
static constexpr u64 minimum_run_cycles = 10000U;
|
||||
};
|
||||
|
||||
@@ -323,6 +337,9 @@ std::shared_ptr<Dynarmic::A64::Jit> ARM_Dynarmic_64::MakeJit(Common::PageTable*
|
||||
if (!Settings::values.cpuopt_recompile_exclusives) {
|
||||
config.recompile_on_exclusive_fastmem_failure = false;
|
||||
}
|
||||
if (!Settings::values.cpuopt_ignore_memory_aborts) {
|
||||
config.check_halt_on_memory_access = true;
|
||||
}
|
||||
} else {
|
||||
// Unsafe optimizations
|
||||
if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::Unsafe) {
|
||||
|
||||
@@ -183,26 +183,20 @@ struct System::Impl {
|
||||
Initialize(system);
|
||||
}
|
||||
|
||||
SystemResultStatus Run() {
|
||||
void Run() {
|
||||
std::unique_lock<std::mutex> lk(suspend_guard);
|
||||
status = SystemResultStatus::Success;
|
||||
|
||||
kernel.Suspend(false);
|
||||
core_timing.SyncPause(false);
|
||||
is_paused.store(false, std::memory_order_relaxed);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
SystemResultStatus Pause() {
|
||||
void Pause() {
|
||||
std::unique_lock<std::mutex> lk(suspend_guard);
|
||||
status = SystemResultStatus::Success;
|
||||
|
||||
core_timing.SyncPause(true);
|
||||
kernel.Suspend(true);
|
||||
is_paused.store(true, std::memory_order_relaxed);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool IsPaused() const {
|
||||
@@ -389,7 +383,9 @@ struct System::Impl {
|
||||
kernel.ShutdownCores();
|
||||
cpu_manager.Shutdown();
|
||||
debugger.reset();
|
||||
services->KillNVNFlinger();
|
||||
if (services) {
|
||||
services->KillNVNFlinger();
|
||||
}
|
||||
kernel.CloseServices();
|
||||
services.reset();
|
||||
service_manager.reset();
|
||||
@@ -551,12 +547,12 @@ void System::Initialize() {
|
||||
impl->Initialize(*this);
|
||||
}
|
||||
|
||||
SystemResultStatus System::Run() {
|
||||
return impl->Run();
|
||||
void System::Run() {
|
||||
impl->Run();
|
||||
}
|
||||
|
||||
SystemResultStatus System::Pause() {
|
||||
return impl->Pause();
|
||||
void System::Pause() {
|
||||
impl->Pause();
|
||||
}
|
||||
|
||||
bool System::IsPaused() const {
|
||||
|
||||
@@ -152,13 +152,13 @@ public:
|
||||
* Run the OS and Application
|
||||
* This function will start emulation and run the relevant devices
|
||||
*/
|
||||
[[nodiscard]] SystemResultStatus Run();
|
||||
void Run();
|
||||
|
||||
/**
|
||||
* Pause the OS and Application
|
||||
* This function will pause emulation and stop the relevant devices
|
||||
*/
|
||||
[[nodiscard]] SystemResultStatus Pause();
|
||||
void Pause();
|
||||
|
||||
/// Check if the core is currently paused.
|
||||
[[nodiscard]] bool IsPaused() const;
|
||||
|
||||
@@ -20,23 +20,20 @@ namespace Core {
|
||||
CpuManager::CpuManager(System& system_) : system{system_} {}
|
||||
CpuManager::~CpuManager() = default;
|
||||
|
||||
void CpuManager::ThreadStart(std::stop_token stop_token, CpuManager& cpu_manager,
|
||||
std::size_t core) {
|
||||
cpu_manager.RunThread(core);
|
||||
}
|
||||
|
||||
void CpuManager::Initialize() {
|
||||
num_cores = is_multicore ? Core::Hardware::NUM_CPU_CORES : 1;
|
||||
gpu_barrier = std::make_unique<Common::Barrier>(num_cores + 1);
|
||||
|
||||
for (std::size_t core = 0; core < num_cores; core++) {
|
||||
core_data[core].host_thread = std::jthread(ThreadStart, std::ref(*this), core);
|
||||
core_data[core].host_thread =
|
||||
std::jthread([this, core](std::stop_token token) { RunThread(token, core); });
|
||||
}
|
||||
}
|
||||
|
||||
void CpuManager::Shutdown() {
|
||||
for (std::size_t core = 0; core < num_cores; core++) {
|
||||
if (core_data[core].host_thread.joinable()) {
|
||||
core_data[core].host_thread.request_stop();
|
||||
core_data[core].host_thread.join();
|
||||
}
|
||||
}
|
||||
@@ -184,7 +181,7 @@ void CpuManager::ShutdownThread() {
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
void CpuManager::RunThread(std::size_t core) {
|
||||
void CpuManager::RunThread(std::stop_token token, std::size_t core) {
|
||||
/// Initialization
|
||||
system.RegisterCoreThread(core);
|
||||
std::string name;
|
||||
@@ -206,7 +203,9 @@ void CpuManager::RunThread(std::size_t core) {
|
||||
});
|
||||
|
||||
// Running
|
||||
gpu_barrier->Sync();
|
||||
if (!gpu_barrier->Sync(token)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_async_gpu && !is_multicore) {
|
||||
system.GPU().ObtainContext();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include "common/fiber.h"
|
||||
#include "common/polyfill_thread.h"
|
||||
#include "common/thread.h"
|
||||
#include "core/hardware_properties.h"
|
||||
|
||||
@@ -80,12 +81,10 @@ private:
|
||||
void SingleCoreRunGuestThread();
|
||||
void SingleCoreRunIdleThread();
|
||||
|
||||
static void ThreadStart(std::stop_token stop_token, CpuManager& cpu_manager, std::size_t core);
|
||||
|
||||
void GuestActivate();
|
||||
void HandleInterrupt();
|
||||
void ShutdownThread();
|
||||
void RunThread(std::size_t core);
|
||||
void RunThread(std::stop_token stop_token, std::size_t core);
|
||||
|
||||
struct CoreData {
|
||||
std::shared_ptr<Common::Fiber> host_context;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <boost/process/async_pipe.hpp>
|
||||
|
||||
#include "common/logging/log.h"
|
||||
#include "common/polyfill_thread.h"
|
||||
#include "common/thread.h"
|
||||
#include "core/core.h"
|
||||
#include "core/debugger/debugger.h"
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "common/logging/log.h"
|
||||
#include "common/polyfill_ranges.h"
|
||||
#include "core/crypto/aes_util.h"
|
||||
#include "core/crypto/ctr_encryption_layer.h"
|
||||
#include "core/crypto/key_manager.h"
|
||||
|
||||
@@ -16,7 +16,7 @@ DefaultControllerApplet::DefaultControllerApplet(HID::HIDCore& hid_core_) : hid_
|
||||
|
||||
DefaultControllerApplet::~DefaultControllerApplet() = default;
|
||||
|
||||
void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callback,
|
||||
void DefaultControllerApplet::ReconfigureControllers(ReconfigureCallback callback,
|
||||
const ControllerParameters& parameters) const {
|
||||
LOG_INFO(Service_HID, "called, deducing the best configuration based on the given parameters!");
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
@@ -35,9 +36,11 @@ struct ControllerParameters {
|
||||
|
||||
class ControllerApplet {
|
||||
public:
|
||||
using ReconfigureCallback = std::function<void()>;
|
||||
|
||||
virtual ~ControllerApplet();
|
||||
|
||||
virtual void ReconfigureControllers(std::function<void()> callback,
|
||||
virtual void ReconfigureControllers(ReconfigureCallback callback,
|
||||
const ControllerParameters& parameters) const = 0;
|
||||
};
|
||||
|
||||
@@ -46,7 +49,7 @@ public:
|
||||
explicit DefaultControllerApplet(HID::HIDCore& hid_core_);
|
||||
~DefaultControllerApplet() override;
|
||||
|
||||
void ReconfigureControllers(std::function<void()> callback,
|
||||
void ReconfigureControllers(ReconfigureCallback callback,
|
||||
const ControllerParameters& parameters) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -8,13 +8,13 @@ namespace Core::Frontend {
|
||||
|
||||
ErrorApplet::~ErrorApplet() = default;
|
||||
|
||||
void DefaultErrorApplet::ShowError(Result error, std::function<void()> finished) const {
|
||||
void DefaultErrorApplet::ShowError(Result error, FinishedCallback finished) const {
|
||||
LOG_CRITICAL(Service_Fatal, "Application requested error display: {:04}-{:04} (raw={:08X})",
|
||||
error.module.Value(), error.description.Value(), error.raw);
|
||||
}
|
||||
|
||||
void DefaultErrorApplet::ShowErrorWithTimestamp(Result error, std::chrono::seconds time,
|
||||
std::function<void()> finished) const {
|
||||
FinishedCallback finished) const {
|
||||
LOG_CRITICAL(
|
||||
Service_Fatal,
|
||||
"Application requested error display: {:04X}-{:04X} (raw={:08X}) with timestamp={:016X}",
|
||||
@@ -23,7 +23,7 @@ void DefaultErrorApplet::ShowErrorWithTimestamp(Result error, std::chrono::secon
|
||||
|
||||
void DefaultErrorApplet::ShowCustomErrorText(Result error, std::string main_text,
|
||||
std::string detail_text,
|
||||
std::function<void()> finished) const {
|
||||
FinishedCallback finished) const {
|
||||
LOG_CRITICAL(Service_Fatal,
|
||||
"Application requested custom error with error_code={:04X}-{:04X} (raw={:08X})",
|
||||
error.module.Value(), error.description.Value(), error.raw);
|
||||
|
||||
@@ -12,25 +12,27 @@ namespace Core::Frontend {
|
||||
|
||||
class ErrorApplet {
|
||||
public:
|
||||
using FinishedCallback = std::function<void()>;
|
||||
|
||||
virtual ~ErrorApplet();
|
||||
|
||||
virtual void ShowError(Result error, std::function<void()> finished) const = 0;
|
||||
virtual void ShowError(Result error, FinishedCallback finished) const = 0;
|
||||
|
||||
virtual void ShowErrorWithTimestamp(Result error, std::chrono::seconds time,
|
||||
std::function<void()> finished) const = 0;
|
||||
FinishedCallback finished) const = 0;
|
||||
|
||||
virtual void ShowCustomErrorText(Result error, std::string dialog_text,
|
||||
std::string fullscreen_text,
|
||||
std::function<void()> finished) const = 0;
|
||||
FinishedCallback finished) const = 0;
|
||||
};
|
||||
|
||||
class DefaultErrorApplet final : public ErrorApplet {
|
||||
public:
|
||||
void ShowError(Result error, std::function<void()> finished) const override;
|
||||
void ShowError(Result error, FinishedCallback finished) const override;
|
||||
void ShowErrorWithTimestamp(Result error, std::chrono::seconds time,
|
||||
std::function<void()> finished) const override;
|
||||
FinishedCallback finished) const override;
|
||||
void ShowCustomErrorText(Result error, std::string main_text, std::string detail_text,
|
||||
std::function<void()> finished) const override;
|
||||
FinishedCallback finished) const override;
|
||||
};
|
||||
|
||||
} // namespace Core::Frontend
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Core::Frontend {
|
||||
|
||||
MiiEditApplet::~MiiEditApplet() = default;
|
||||
|
||||
void DefaultMiiEditApplet::ShowMiiEdit(const std::function<void()>& callback) const {
|
||||
void DefaultMiiEditApplet::ShowMiiEdit(const MiiEditCallback& callback) const {
|
||||
LOG_WARNING(Service_AM, "(STUBBED) called");
|
||||
|
||||
callback();
|
||||
|
||||
@@ -9,14 +9,16 @@ namespace Core::Frontend {
|
||||
|
||||
class MiiEditApplet {
|
||||
public:
|
||||
using MiiEditCallback = std::function<void()>;
|
||||
|
||||
virtual ~MiiEditApplet();
|
||||
|
||||
virtual void ShowMiiEdit(const std::function<void()>& callback) const = 0;
|
||||
virtual void ShowMiiEdit(const MiiEditCallback& callback) const = 0;
|
||||
};
|
||||
|
||||
class DefaultMiiEditApplet final : public MiiEditApplet {
|
||||
public:
|
||||
void ShowMiiEdit(const std::function<void()>& callback) const override;
|
||||
void ShowMiiEdit(const MiiEditCallback& callback) const override;
|
||||
};
|
||||
|
||||
} // namespace Core::Frontend
|
||||
|
||||
@@ -9,8 +9,7 @@ namespace Core::Frontend {
|
||||
|
||||
ProfileSelectApplet::~ProfileSelectApplet() = default;
|
||||
|
||||
void DefaultProfileSelectApplet::SelectProfile(
|
||||
std::function<void(std::optional<Common::UUID>)> callback) const {
|
||||
void DefaultProfileSelectApplet::SelectProfile(SelectProfileCallback callback) const {
|
||||
Service::Account::ProfileManager manager;
|
||||
callback(manager.GetUser(Settings::values.current_user.GetValue()).value_or(Common::UUID{}));
|
||||
LOG_INFO(Service_ACC, "called, selecting current user instead of prompting...");
|
||||
|
||||
@@ -11,14 +11,16 @@ namespace Core::Frontend {
|
||||
|
||||
class ProfileSelectApplet {
|
||||
public:
|
||||
using SelectProfileCallback = std::function<void(std::optional<Common::UUID>)>;
|
||||
|
||||
virtual ~ProfileSelectApplet();
|
||||
|
||||
virtual void SelectProfile(std::function<void(std::optional<Common::UUID>)> callback) const = 0;
|
||||
virtual void SelectProfile(SelectProfileCallback callback) const = 0;
|
||||
};
|
||||
|
||||
class DefaultProfileSelectApplet final : public ProfileSelectApplet {
|
||||
public:
|
||||
void SelectProfile(std::function<void(std::optional<Common::UUID>)> callback) const override;
|
||||
void SelectProfile(SelectProfileCallback callback) const override;
|
||||
};
|
||||
|
||||
} // namespace Core::Frontend
|
||||
|
||||
@@ -15,10 +15,7 @@ DefaultSoftwareKeyboardApplet::~DefaultSoftwareKeyboardApplet() = default;
|
||||
|
||||
void DefaultSoftwareKeyboardApplet::InitializeKeyboard(
|
||||
bool is_inline, KeyboardInitializeParameters initialize_parameters,
|
||||
std::function<void(Service::AM::Applets::SwkbdResult, std::u16string, bool)>
|
||||
submit_normal_callback_,
|
||||
std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)>
|
||||
submit_inline_callback_) {
|
||||
SubmitNormalCallback submit_normal_callback_, SubmitInlineCallback submit_inline_callback_) {
|
||||
if (is_inline) {
|
||||
LOG_WARNING(
|
||||
Service_AM,
|
||||
|
||||
@@ -54,14 +54,17 @@ struct InlineTextParameters {
|
||||
|
||||
class SoftwareKeyboardApplet {
|
||||
public:
|
||||
using SubmitInlineCallback =
|
||||
std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)>;
|
||||
using SubmitNormalCallback =
|
||||
std::function<void(Service::AM::Applets::SwkbdResult, std::u16string, bool)>;
|
||||
|
||||
virtual ~SoftwareKeyboardApplet();
|
||||
|
||||
virtual void InitializeKeyboard(
|
||||
bool is_inline, KeyboardInitializeParameters initialize_parameters,
|
||||
std::function<void(Service::AM::Applets::SwkbdResult, std::u16string, bool)>
|
||||
submit_normal_callback_,
|
||||
std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)>
|
||||
submit_inline_callback_) = 0;
|
||||
virtual void InitializeKeyboard(bool is_inline,
|
||||
KeyboardInitializeParameters initialize_parameters,
|
||||
SubmitNormalCallback submit_normal_callback_,
|
||||
SubmitInlineCallback submit_inline_callback_) = 0;
|
||||
|
||||
virtual void ShowNormalKeyboard() const = 0;
|
||||
|
||||
@@ -81,12 +84,9 @@ class DefaultSoftwareKeyboardApplet final : public SoftwareKeyboardApplet {
|
||||
public:
|
||||
~DefaultSoftwareKeyboardApplet() override;
|
||||
|
||||
void InitializeKeyboard(
|
||||
bool is_inline, KeyboardInitializeParameters initialize_parameters,
|
||||
std::function<void(Service::AM::Applets::SwkbdResult, std::u16string, bool)>
|
||||
submit_normal_callback_,
|
||||
std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)>
|
||||
submit_inline_callback_) override;
|
||||
void InitializeKeyboard(bool is_inline, KeyboardInitializeParameters initialize_parameters,
|
||||
SubmitNormalCallback submit_normal_callback_,
|
||||
SubmitInlineCallback submit_inline_callback_) override;
|
||||
|
||||
void ShowNormalKeyboard() const override;
|
||||
|
||||
@@ -105,12 +105,10 @@ private:
|
||||
void SubmitNormalText(std::u16string text) const;
|
||||
void SubmitInlineText(std::u16string_view text) const;
|
||||
|
||||
KeyboardInitializeParameters parameters;
|
||||
KeyboardInitializeParameters parameters{};
|
||||
|
||||
mutable std::function<void(Service::AM::Applets::SwkbdResult, std::u16string, bool)>
|
||||
submit_normal_callback;
|
||||
mutable std::function<void(Service::AM::Applets::SwkbdReplyType, std::u16string, s32)>
|
||||
submit_inline_callback;
|
||||
mutable SubmitNormalCallback submit_normal_callback;
|
||||
mutable SubmitInlineCallback submit_inline_callback;
|
||||
};
|
||||
|
||||
} // namespace Core::Frontend
|
||||
|
||||
@@ -10,18 +10,17 @@ WebBrowserApplet::~WebBrowserApplet() = default;
|
||||
|
||||
DefaultWebBrowserApplet::~DefaultWebBrowserApplet() = default;
|
||||
|
||||
void DefaultWebBrowserApplet::OpenLocalWebPage(
|
||||
const std::string& local_url, std::function<void()> extract_romfs_callback,
|
||||
std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const {
|
||||
void DefaultWebBrowserApplet::OpenLocalWebPage(const std::string& local_url,
|
||||
ExtractROMFSCallback extract_romfs_callback,
|
||||
OpenWebPageCallback callback) const {
|
||||
LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open local web page at {}",
|
||||
local_url);
|
||||
|
||||
callback(Service::AM::Applets::WebExitReason::WindowClosed, "http://localhost/");
|
||||
}
|
||||
|
||||
void DefaultWebBrowserApplet::OpenExternalWebPage(
|
||||
const std::string& external_url,
|
||||
std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const {
|
||||
void DefaultWebBrowserApplet::OpenExternalWebPage(const std::string& external_url,
|
||||
OpenWebPageCallback callback) const {
|
||||
LOG_WARNING(Service_AM, "(STUBBED) called, backend requested to open external web page at {}",
|
||||
external_url);
|
||||
|
||||
|
||||
@@ -11,29 +11,29 @@ namespace Core::Frontend {
|
||||
|
||||
class WebBrowserApplet {
|
||||
public:
|
||||
using ExtractROMFSCallback = std::function<void()>;
|
||||
using OpenWebPageCallback =
|
||||
std::function<void(Service::AM::Applets::WebExitReason, std::string)>;
|
||||
|
||||
virtual ~WebBrowserApplet();
|
||||
|
||||
virtual void OpenLocalWebPage(
|
||||
const std::string& local_url, std::function<void()> extract_romfs_callback,
|
||||
std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const = 0;
|
||||
virtual void OpenLocalWebPage(const std::string& local_url,
|
||||
ExtractROMFSCallback extract_romfs_callback,
|
||||
OpenWebPageCallback callback) const = 0;
|
||||
|
||||
virtual void OpenExternalWebPage(
|
||||
const std::string& external_url,
|
||||
std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback) const = 0;
|
||||
virtual void OpenExternalWebPage(const std::string& external_url,
|
||||
OpenWebPageCallback callback) const = 0;
|
||||
};
|
||||
|
||||
class DefaultWebBrowserApplet final : public WebBrowserApplet {
|
||||
public:
|
||||
~DefaultWebBrowserApplet() override;
|
||||
|
||||
void OpenLocalWebPage(const std::string& local_url,
|
||||
std::function<void()> extract_romfs_callback,
|
||||
std::function<void(Service::AM::Applets::WebExitReason, std::string)>
|
||||
callback) const override;
|
||||
void OpenLocalWebPage(const std::string& local_url, ExtractROMFSCallback extract_romfs_callback,
|
||||
OpenWebPageCallback callback) const override;
|
||||
|
||||
void OpenExternalWebPage(const std::string& external_url,
|
||||
std::function<void(Service::AM::Applets::WebExitReason, std::string)>
|
||||
callback) const override;
|
||||
OpenWebPageCallback callback) const override;
|
||||
};
|
||||
|
||||
} // namespace Core::Frontend
|
||||
|
||||
@@ -17,6 +17,8 @@ enum class WindowSystemType {
|
||||
Windows,
|
||||
X11,
|
||||
Wayland,
|
||||
Cocoa,
|
||||
Android,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -129,6 +131,10 @@ public:
|
||||
return active_config;
|
||||
}
|
||||
|
||||
bool StrictContextRequired() const {
|
||||
return strict_context_required;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the internal configuration to be replaced by the specified argument at some point in
|
||||
* the future.
|
||||
@@ -205,6 +211,8 @@ protected:
|
||||
|
||||
WindowSystemInfo window_info;
|
||||
|
||||
bool strict_context_required = false;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Handler called when the minimal client area was requested to be changed via SetConfig.
|
||||
|
||||
@@ -37,7 +37,7 @@ void EmulatedConsole::SetTouchParams() {
|
||||
touchscreen_param.Set("axis_x", i * 2);
|
||||
touchscreen_param.Set("axis_y", (i * 2) + 1);
|
||||
touchscreen_param.Set("button", i);
|
||||
touch_params[index++] = touchscreen_param;
|
||||
touch_params[index++] = std::move(touchscreen_param);
|
||||
}
|
||||
|
||||
const auto button_index =
|
||||
@@ -59,7 +59,7 @@ void EmulatedConsole::SetTouchParams() {
|
||||
touch_button_params.Set("button", params.Serialize());
|
||||
touch_button_params.Set("x", x);
|
||||
touch_button_params.Set("y", y);
|
||||
touch_params[index] = touch_button_params;
|
||||
touch_params[index] = std::move(touch_button_params);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ Common::ParamPackage EmulatedConsole::GetMotionParam() const {
|
||||
}
|
||||
|
||||
void EmulatedConsole::SetMotionParam(Common::ParamPackage param) {
|
||||
motion_params = param;
|
||||
motion_params = std::move(param);
|
||||
ReloadInput();
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ void EmulatedConsole::SetTouch(const Common::Input::CallbackStatus& callback, st
|
||||
|
||||
if (is_new_input) {
|
||||
touch_value.pressed.value = true;
|
||||
touch_value.id = static_cast<u32>(index);
|
||||
touch_value.id = static_cast<int>(index);
|
||||
}
|
||||
|
||||
touch_value.x = touch_input.x;
|
||||
@@ -284,7 +284,7 @@ void EmulatedConsole::TriggerOnChange(ConsoleTriggerType type) {
|
||||
|
||||
int EmulatedConsole::SetCallback(ConsoleUpdateCallback update_callback) {
|
||||
std::scoped_lock lock{callback_mutex};
|
||||
callback_list.insert_or_assign(last_callback_key, update_callback);
|
||||
callback_list.insert_or_assign(last_callback_key, std::move(update_callback));
|
||||
return last_callback_key++;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "common/polyfill_ranges.h"
|
||||
#include "common/thread.h"
|
||||
#include "core/hid/emulated_controller.h"
|
||||
#include "core/hid/input_converter.h"
|
||||
@@ -109,10 +110,9 @@ void EmulatedController::ReloadFromSettings() {
|
||||
original_npad_type = npad_type;
|
||||
}
|
||||
|
||||
Disconnect();
|
||||
if (player.connected) {
|
||||
Connect();
|
||||
} else {
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
ReloadInput();
|
||||
@@ -145,6 +145,7 @@ void EmulatedController::LoadDevices() {
|
||||
output_params[3].Set("output", true);
|
||||
|
||||
LoadTASParams();
|
||||
LoadVirtualGamepadParams();
|
||||
|
||||
std::ranges::transform(button_params, button_devices.begin(), Common::Input::CreateInputDevice);
|
||||
std::ranges::transform(stick_params, stick_devices.begin(), Common::Input::CreateInputDevice);
|
||||
@@ -163,6 +164,12 @@ void EmulatedController::LoadDevices() {
|
||||
Common::Input::CreateInputDevice);
|
||||
std::ranges::transform(tas_stick_params, tas_stick_devices.begin(),
|
||||
Common::Input::CreateInputDevice);
|
||||
|
||||
// Initialize virtual gamepad devices
|
||||
std::ranges::transform(virtual_button_params, virtual_button_devices.begin(),
|
||||
Common::Input::CreateInputDevice);
|
||||
std::ranges::transform(virtual_stick_params, virtual_stick_devices.begin(),
|
||||
Common::Input::CreateInputDevice);
|
||||
}
|
||||
|
||||
void EmulatedController::LoadTASParams() {
|
||||
@@ -205,6 +212,46 @@ void EmulatedController::LoadTASParams() {
|
||||
tas_stick_params[Settings::NativeAnalog::RStick].Set("axis_y", 3);
|
||||
}
|
||||
|
||||
void EmulatedController::LoadVirtualGamepadParams() {
|
||||
const auto player_index = NpadIdTypeToIndex(npad_id_type);
|
||||
Common::ParamPackage common_params{};
|
||||
common_params.Set("engine", "virtual_gamepad");
|
||||
common_params.Set("port", static_cast<int>(player_index));
|
||||
for (auto& param : virtual_button_params) {
|
||||
param = common_params;
|
||||
}
|
||||
for (auto& param : virtual_stick_params) {
|
||||
param = common_params;
|
||||
}
|
||||
|
||||
// TODO(german77): Replace this with an input profile or something better
|
||||
virtual_button_params[Settings::NativeButton::A].Set("button", 0);
|
||||
virtual_button_params[Settings::NativeButton::B].Set("button", 1);
|
||||
virtual_button_params[Settings::NativeButton::X].Set("button", 2);
|
||||
virtual_button_params[Settings::NativeButton::Y].Set("button", 3);
|
||||
virtual_button_params[Settings::NativeButton::LStick].Set("button", 4);
|
||||
virtual_button_params[Settings::NativeButton::RStick].Set("button", 5);
|
||||
virtual_button_params[Settings::NativeButton::L].Set("button", 6);
|
||||
virtual_button_params[Settings::NativeButton::R].Set("button", 7);
|
||||
virtual_button_params[Settings::NativeButton::ZL].Set("button", 8);
|
||||
virtual_button_params[Settings::NativeButton::ZR].Set("button", 9);
|
||||
virtual_button_params[Settings::NativeButton::Plus].Set("button", 10);
|
||||
virtual_button_params[Settings::NativeButton::Minus].Set("button", 11);
|
||||
virtual_button_params[Settings::NativeButton::DLeft].Set("button", 12);
|
||||
virtual_button_params[Settings::NativeButton::DUp].Set("button", 13);
|
||||
virtual_button_params[Settings::NativeButton::DRight].Set("button", 14);
|
||||
virtual_button_params[Settings::NativeButton::DDown].Set("button", 15);
|
||||
virtual_button_params[Settings::NativeButton::SL].Set("button", 16);
|
||||
virtual_button_params[Settings::NativeButton::SR].Set("button", 17);
|
||||
virtual_button_params[Settings::NativeButton::Home].Set("button", 18);
|
||||
virtual_button_params[Settings::NativeButton::Screenshot].Set("button", 19);
|
||||
|
||||
virtual_stick_params[Settings::NativeAnalog::LStick].Set("axis_x", 0);
|
||||
virtual_stick_params[Settings::NativeAnalog::LStick].Set("axis_y", 1);
|
||||
virtual_stick_params[Settings::NativeAnalog::RStick].Set("axis_x", 2);
|
||||
virtual_stick_params[Settings::NativeAnalog::RStick].Set("axis_y", 3);
|
||||
}
|
||||
|
||||
void EmulatedController::ReloadInput() {
|
||||
// If you load any device here add the equivalent to the UnloadInput() function
|
||||
LoadDevices();
|
||||
@@ -322,6 +369,35 @@ void EmulatedController::ReloadInput() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Use a common UUID for Virtual Gamepad
|
||||
static constexpr Common::UUID VIRTUAL_UUID = Common::UUID{
|
||||
{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};
|
||||
|
||||
// Register virtual devices. No need to force update
|
||||
for (std::size_t index = 0; index < virtual_button_devices.size(); ++index) {
|
||||
if (!virtual_button_devices[index]) {
|
||||
continue;
|
||||
}
|
||||
virtual_button_devices[index]->SetCallback({
|
||||
.on_change =
|
||||
[this, index](const Common::Input::CallbackStatus& callback) {
|
||||
SetButton(callback, index, VIRTUAL_UUID);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
for (std::size_t index = 0; index < virtual_stick_devices.size(); ++index) {
|
||||
if (!virtual_stick_devices[index]) {
|
||||
continue;
|
||||
}
|
||||
virtual_stick_devices[index]->SetCallback({
|
||||
.on_change =
|
||||
[this, index](const Common::Input::CallbackStatus& callback) {
|
||||
SetStick(callback, index, VIRTUAL_UUID);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void EmulatedController::UnloadInput() {
|
||||
@@ -349,6 +425,12 @@ void EmulatedController::UnloadInput() {
|
||||
for (auto& stick : tas_stick_devices) {
|
||||
stick.reset();
|
||||
}
|
||||
for (auto& button : virtual_button_devices) {
|
||||
button.reset();
|
||||
}
|
||||
for (auto& stick : virtual_stick_devices) {
|
||||
stick.reset();
|
||||
}
|
||||
camera_devices.reset();
|
||||
nfc_devices.reset();
|
||||
}
|
||||
@@ -424,15 +506,14 @@ void EmulatedController::RestoreConfig() {
|
||||
ReloadFromSettings();
|
||||
}
|
||||
|
||||
std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(
|
||||
EmulatedDeviceIndex device_index) const {
|
||||
std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices() const {
|
||||
std::vector<Common::ParamPackage> devices;
|
||||
for (const auto& param : button_params) {
|
||||
if (!param.Has("engine")) {
|
||||
continue;
|
||||
}
|
||||
const auto devices_it = std::find_if(
|
||||
devices.begin(), devices.end(), [param](const Common::ParamPackage param_) {
|
||||
devices.begin(), devices.end(), [¶m](const Common::ParamPackage& param_) {
|
||||
return param.Get("engine", "") == param_.Get("engine", "") &&
|
||||
param.Get("guid", "") == param_.Get("guid", "") &&
|
||||
param.Get("port", 0) == param_.Get("port", 0) &&
|
||||
@@ -441,12 +522,12 @@ std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(
|
||||
if (devices_it != devices.end()) {
|
||||
continue;
|
||||
}
|
||||
Common::ParamPackage device{};
|
||||
|
||||
auto& device = devices.emplace_back();
|
||||
device.Set("engine", param.Get("engine", ""));
|
||||
device.Set("guid", param.Get("guid", ""));
|
||||
device.Set("port", param.Get("port", 0));
|
||||
device.Set("pad", param.Get("pad", 0));
|
||||
devices.push_back(device);
|
||||
}
|
||||
|
||||
for (const auto& param : stick_params) {
|
||||
@@ -457,7 +538,7 @@ std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(
|
||||
continue;
|
||||
}
|
||||
const auto devices_it = std::find_if(
|
||||
devices.begin(), devices.end(), [param](const Common::ParamPackage param_) {
|
||||
devices.begin(), devices.end(), [¶m](const Common::ParamPackage& param_) {
|
||||
return param.Get("engine", "") == param_.Get("engine", "") &&
|
||||
param.Get("guid", "") == param_.Get("guid", "") &&
|
||||
param.Get("port", 0) == param_.Get("port", 0) &&
|
||||
@@ -466,12 +547,12 @@ std::vector<Common::ParamPackage> EmulatedController::GetMappedDevices(
|
||||
if (devices_it != devices.end()) {
|
||||
continue;
|
||||
}
|
||||
Common::ParamPackage device{};
|
||||
|
||||
auto& device = devices.emplace_back();
|
||||
device.Set("engine", param.Get("engine", ""));
|
||||
device.Set("guid", param.Get("guid", ""));
|
||||
device.Set("port", param.Get("port", 0));
|
||||
device.Set("pad", param.Get("pad", 0));
|
||||
devices.push_back(device);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/input.h"
|
||||
@@ -243,7 +244,7 @@ public:
|
||||
void RestoreConfig();
|
||||
|
||||
/// Returns a vector of mapped devices from the mapped button and stick parameters
|
||||
std::vector<Common::ParamPackage> GetMappedDevices(EmulatedDeviceIndex device_index) const;
|
||||
std::vector<Common::ParamPackage> GetMappedDevices() const;
|
||||
|
||||
// Returns the current mapped button device
|
||||
Common::ParamPackage GetButtonParam(std::size_t index) const;
|
||||
@@ -384,6 +385,9 @@ private:
|
||||
/// Set the params for TAS devices
|
||||
void LoadTASParams();
|
||||
|
||||
/// Set the params for virtual pad devices
|
||||
void LoadVirtualGamepadParams();
|
||||
|
||||
/**
|
||||
* @param use_temporary_value If true tmp_npad_type will be used
|
||||
* @return true if the controller style is fullkey
|
||||
@@ -499,6 +503,12 @@ private:
|
||||
ButtonDevices tas_button_devices;
|
||||
StickDevices tas_stick_devices;
|
||||
|
||||
// Virtual gamepad related variables
|
||||
ButtonParams virtual_button_params;
|
||||
StickParams virtual_stick_params;
|
||||
ButtonDevices virtual_button_devices;
|
||||
StickDevices virtual_stick_devices;
|
||||
|
||||
mutable std::mutex mutex;
|
||||
mutable std::mutex callback_mutex;
|
||||
std::unordered_map<int, ControllerUpdateCallback> callback_list;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/input.h"
|
||||
|
||||
@@ -167,6 +167,9 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32
|
||||
}
|
||||
if (incoming) {
|
||||
// Populate the object lists with the data in the IPC request.
|
||||
incoming_copy_handles.reserve(handle_descriptor_header->num_handles_to_copy);
|
||||
incoming_move_handles.reserve(handle_descriptor_header->num_handles_to_move);
|
||||
|
||||
for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_copy; ++handle) {
|
||||
incoming_copy_handles.push_back(rp.Pop<Handle>());
|
||||
}
|
||||
@@ -181,6 +184,11 @@ void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32
|
||||
}
|
||||
}
|
||||
|
||||
buffer_x_desciptors.reserve(command_header->num_buf_x_descriptors);
|
||||
buffer_a_desciptors.reserve(command_header->num_buf_a_descriptors);
|
||||
buffer_b_desciptors.reserve(command_header->num_buf_b_descriptors);
|
||||
buffer_w_desciptors.reserve(command_header->num_buf_w_descriptors);
|
||||
|
||||
for (u32 i = 0; i < command_header->num_buf_x_descriptors; ++i) {
|
||||
buffer_x_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorX>());
|
||||
}
|
||||
@@ -318,25 +326,23 @@ Result HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_threa
|
||||
}
|
||||
|
||||
std::vector<u8> HLERequestContext::ReadBuffer(std::size_t buffer_index) const {
|
||||
std::vector<u8> buffer{};
|
||||
const bool is_buffer_a{BufferDescriptorA().size() > buffer_index &&
|
||||
BufferDescriptorA()[buffer_index].Size()};
|
||||
|
||||
if (is_buffer_a) {
|
||||
ASSERT_OR_EXECUTE_MSG(
|
||||
BufferDescriptorA().size() > buffer_index, { return buffer; },
|
||||
BufferDescriptorA().size() > buffer_index, { return {}; },
|
||||
"BufferDescriptorA invalid buffer_index {}", buffer_index);
|
||||
buffer.resize(BufferDescriptorA()[buffer_index].Size());
|
||||
std::vector<u8> buffer(BufferDescriptorA()[buffer_index].Size());
|
||||
memory.ReadBlock(BufferDescriptorA()[buffer_index].Address(), buffer.data(), buffer.size());
|
||||
return buffer;
|
||||
} else {
|
||||
ASSERT_OR_EXECUTE_MSG(
|
||||
BufferDescriptorX().size() > buffer_index, { return buffer; },
|
||||
BufferDescriptorX().size() > buffer_index, { return {}; },
|
||||
"BufferDescriptorX invalid buffer_index {}", buffer_index);
|
||||
buffer.resize(BufferDescriptorX()[buffer_index].Size());
|
||||
std::vector<u8> buffer(BufferDescriptorX()[buffer_index].Size());
|
||||
memory.ReadBlock(BufferDescriptorX()[buffer_index].Address(), buffer.data(), buffer.size());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size,
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "core/hle/kernel/k_thread_queue.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/svc_results.h"
|
||||
#include "core/hle/kernel/time_manager.h"
|
||||
#include "core/memory.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
@@ -27,13 +27,13 @@ Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, VAddr addr, si
|
||||
auto& page_table = m_owner->PageTable();
|
||||
|
||||
// Construct the page group.
|
||||
m_page_group = {};
|
||||
m_page_group.emplace(kernel, page_table.GetBlockInfoManager());
|
||||
|
||||
// Lock the memory.
|
||||
R_TRY(page_table.LockForCodeMemory(&m_page_group, addr, size))
|
||||
R_TRY(page_table.LockForCodeMemory(std::addressof(*m_page_group), addr, size))
|
||||
|
||||
// Clear the memory.
|
||||
for (const auto& block : m_page_group.Nodes()) {
|
||||
for (const auto& block : *m_page_group) {
|
||||
std::memset(device_memory.GetPointer<void>(block.GetAddress()), 0xFF, block.GetSize());
|
||||
}
|
||||
|
||||
@@ -51,12 +51,13 @@ Result KCodeMemory::Initialize(Core::DeviceMemory& device_memory, VAddr addr, si
|
||||
void KCodeMemory::Finalize() {
|
||||
// Unlock.
|
||||
if (!m_is_mapped && !m_is_owner_mapped) {
|
||||
const size_t size = m_page_group.GetNumPages() * PageSize;
|
||||
m_owner->PageTable().UnlockForCodeMemory(m_address, size, m_page_group);
|
||||
const size_t size = m_page_group->GetNumPages() * PageSize;
|
||||
m_owner->PageTable().UnlockForCodeMemory(m_address, size, *m_page_group);
|
||||
}
|
||||
|
||||
// Close the page group.
|
||||
m_page_group = {};
|
||||
m_page_group->Close();
|
||||
m_page_group->Finalize();
|
||||
|
||||
// Close our reference to our owner.
|
||||
m_owner->Close();
|
||||
@@ -64,7 +65,7 @@ void KCodeMemory::Finalize() {
|
||||
|
||||
Result KCodeMemory::Map(VAddr address, size_t size) {
|
||||
// Validate the size.
|
||||
R_UNLESS(m_page_group.GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
|
||||
// Lock ourselves.
|
||||
KScopedLightLock lk(m_lock);
|
||||
@@ -74,7 +75,7 @@ Result KCodeMemory::Map(VAddr address, size_t size) {
|
||||
|
||||
// Map the memory.
|
||||
R_TRY(kernel.CurrentProcess()->PageTable().MapPages(
|
||||
address, m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite));
|
||||
address, *m_page_group, KMemoryState::CodeOut, KMemoryPermission::UserReadWrite));
|
||||
|
||||
// Mark ourselves as mapped.
|
||||
m_is_mapped = true;
|
||||
@@ -84,13 +85,13 @@ Result KCodeMemory::Map(VAddr address, size_t size) {
|
||||
|
||||
Result KCodeMemory::Unmap(VAddr address, size_t size) {
|
||||
// Validate the size.
|
||||
R_UNLESS(m_page_group.GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
|
||||
// Lock ourselves.
|
||||
KScopedLightLock lk(m_lock);
|
||||
|
||||
// Unmap the memory.
|
||||
R_TRY(kernel.CurrentProcess()->PageTable().UnmapPages(address, m_page_group,
|
||||
R_TRY(kernel.CurrentProcess()->PageTable().UnmapPages(address, *m_page_group,
|
||||
KMemoryState::CodeOut));
|
||||
|
||||
// Mark ourselves as unmapped.
|
||||
@@ -101,7 +102,7 @@ Result KCodeMemory::Unmap(VAddr address, size_t size) {
|
||||
|
||||
Result KCodeMemory::MapToOwner(VAddr address, size_t size, Svc::MemoryPermission perm) {
|
||||
// Validate the size.
|
||||
R_UNLESS(m_page_group.GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
|
||||
// Lock ourselves.
|
||||
KScopedLightLock lk(m_lock);
|
||||
@@ -125,7 +126,7 @@ Result KCodeMemory::MapToOwner(VAddr address, size_t size, Svc::MemoryPermission
|
||||
|
||||
// Map the memory.
|
||||
R_TRY(
|
||||
m_owner->PageTable().MapPages(address, m_page_group, KMemoryState::GeneratedCode, k_perm));
|
||||
m_owner->PageTable().MapPages(address, *m_page_group, KMemoryState::GeneratedCode, k_perm));
|
||||
|
||||
// Mark ourselves as mapped.
|
||||
m_is_owner_mapped = true;
|
||||
@@ -135,13 +136,13 @@ Result KCodeMemory::MapToOwner(VAddr address, size_t size, Svc::MemoryPermission
|
||||
|
||||
Result KCodeMemory::UnmapFromOwner(VAddr address, size_t size) {
|
||||
// Validate the size.
|
||||
R_UNLESS(m_page_group.GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize);
|
||||
|
||||
// Lock ourselves.
|
||||
KScopedLightLock lk(m_lock);
|
||||
|
||||
// Unmap the memory.
|
||||
R_TRY(m_owner->PageTable().UnmapPages(address, m_page_group, KMemoryState::GeneratedCode));
|
||||
R_TRY(m_owner->PageTable().UnmapPages(address, *m_page_group, KMemoryState::GeneratedCode));
|
||||
|
||||
// Mark ourselves as unmapped.
|
||||
m_is_owner_mapped = false;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/device_memory.h"
|
||||
#include "core/hle/kernel/k_auto_object.h"
|
||||
@@ -49,11 +51,11 @@ public:
|
||||
return m_address;
|
||||
}
|
||||
size_t GetSize() const {
|
||||
return m_is_initialized ? m_page_group.GetNumPages() * PageSize : 0;
|
||||
return m_is_initialized ? m_page_group->GetNumPages() * PageSize : 0;
|
||||
}
|
||||
|
||||
private:
|
||||
KPageGroup m_page_group{};
|
||||
std::optional<KPageGroup> m_page_group{};
|
||||
KProcess* m_owner{};
|
||||
VAddr m_address{};
|
||||
KLightLock m_lock;
|
||||
|
||||
74
src/core/hle/kernel/k_hardware_timer.cpp
Normal file
74
src/core/hle/kernel/k_hardware_timer.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/kernel/k_hardware_timer.h"
|
||||
#include "core/hle/kernel/k_scheduler.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
void KHardwareTimer::Initialize() {
|
||||
// Create the timing callback to register with CoreTiming.
|
||||
m_event_type = Core::Timing::CreateEvent(
|
||||
"KHardwareTimer::Callback", [](std::uintptr_t timer_handle, s64, std::chrono::nanoseconds) {
|
||||
reinterpret_cast<KHardwareTimer*>(timer_handle)->DoTask();
|
||||
return std::nullopt;
|
||||
});
|
||||
}
|
||||
|
||||
void KHardwareTimer::Finalize() {
|
||||
this->DisableInterrupt();
|
||||
m_event_type.reset();
|
||||
}
|
||||
|
||||
void KHardwareTimer::DoTask() {
|
||||
// Handle the interrupt.
|
||||
{
|
||||
KScopedSchedulerLock slk{m_kernel};
|
||||
KScopedSpinLock lk(this->GetLock());
|
||||
|
||||
//! Ignore this event if needed.
|
||||
if (!this->GetInterruptEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable the timer interrupt while we handle this.
|
||||
this->DisableInterrupt();
|
||||
|
||||
if (const s64 next_time = this->DoInterruptTaskImpl(GetTick());
|
||||
0 < next_time && next_time <= m_wakeup_time) {
|
||||
// We have a next time, so we should set the time to interrupt and turn the interrupt
|
||||
// on.
|
||||
this->EnableInterrupt(next_time);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the timer interrupt.
|
||||
// Kernel::GetInterruptManager().ClearInterrupt(KInterruptName_NonSecurePhysicalTimer,
|
||||
// GetCurrentCoreId());
|
||||
}
|
||||
|
||||
void KHardwareTimer::EnableInterrupt(s64 wakeup_time) {
|
||||
this->DisableInterrupt();
|
||||
|
||||
m_wakeup_time = wakeup_time;
|
||||
m_kernel.System().CoreTiming().ScheduleEvent(std::chrono::nanoseconds{m_wakeup_time},
|
||||
m_event_type, reinterpret_cast<uintptr_t>(this),
|
||||
true);
|
||||
}
|
||||
|
||||
void KHardwareTimer::DisableInterrupt() {
|
||||
m_kernel.System().CoreTiming().UnscheduleEvent(m_event_type, reinterpret_cast<uintptr_t>(this));
|
||||
m_wakeup_time = std::numeric_limits<s64>::max();
|
||||
}
|
||||
|
||||
s64 KHardwareTimer::GetTick() const {
|
||||
return m_kernel.System().CoreTiming().GetGlobalTimeNs().count();
|
||||
}
|
||||
|
||||
bool KHardwareTimer::GetInterruptEnabled() {
|
||||
return m_wakeup_time != std::numeric_limits<s64>::max();
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
||||
54
src/core/hle/kernel/k_hardware_timer.h
Normal file
54
src/core/hle/kernel/k_hardware_timer.h
Normal file
@@ -0,0 +1,54 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/hle/kernel/k_hardware_timer_base.h"
|
||||
|
||||
namespace Core::Timing {
|
||||
struct EventType;
|
||||
} // namespace Core::Timing
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class KHardwareTimer : /* public KInterruptTask, */ public KHardwareTimerBase {
|
||||
public:
|
||||
explicit KHardwareTimer(KernelCore& kernel) : KHardwareTimerBase{kernel} {}
|
||||
|
||||
// Public API.
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
s64 GetCount() const {
|
||||
return GetTick();
|
||||
}
|
||||
|
||||
void RegisterTask(KTimerTask* task, s64 time_from_now) {
|
||||
this->RegisterAbsoluteTask(task, GetTick() + time_from_now);
|
||||
}
|
||||
|
||||
void RegisterAbsoluteTask(KTimerTask* task, s64 task_time) {
|
||||
KScopedDisableDispatch dd{m_kernel};
|
||||
KScopedSpinLock lk{this->GetLock()};
|
||||
|
||||
if (this->RegisterAbsoluteTaskImpl(task, task_time)) {
|
||||
if (task_time <= m_wakeup_time) {
|
||||
this->EnableInterrupt(task_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void EnableInterrupt(s64 wakeup_time);
|
||||
void DisableInterrupt();
|
||||
bool GetInterruptEnabled();
|
||||
s64 GetTick() const;
|
||||
void DoTask();
|
||||
|
||||
private:
|
||||
// Absolute time in nanoseconds
|
||||
s64 m_wakeup_time{std::numeric_limits<s64>::max()};
|
||||
std::shared_ptr<Core::Timing::EventType> m_event_type{};
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
92
src/core/hle/kernel/k_hardware_timer_base.h
Normal file
92
src/core/hle/kernel/k_hardware_timer_base.h
Normal file
@@ -0,0 +1,92 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/hle/kernel/k_spin_lock.h"
|
||||
#include "core/hle/kernel/k_thread.h"
|
||||
#include "core/hle/kernel/k_timer_task.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class KHardwareTimerBase {
|
||||
public:
|
||||
explicit KHardwareTimerBase(KernelCore& kernel) : m_kernel{kernel} {}
|
||||
|
||||
void CancelTask(KTimerTask* task) {
|
||||
KScopedDisableDispatch dd{m_kernel};
|
||||
KScopedSpinLock lk{m_lock};
|
||||
|
||||
if (const s64 task_time = task->GetTime(); task_time > 0) {
|
||||
this->RemoveTaskFromTree(task);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
KSpinLock& GetLock() {
|
||||
return m_lock;
|
||||
}
|
||||
|
||||
s64 DoInterruptTaskImpl(s64 cur_time) {
|
||||
// We want to handle all tasks, returning the next time that a task is scheduled.
|
||||
while (true) {
|
||||
// Get the next task. If there isn't one, return 0.
|
||||
KTimerTask* task = m_next_task;
|
||||
if (task == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If the task needs to be done in the future, do it in the future and not now.
|
||||
if (const s64 task_time = task->GetTime(); task_time > cur_time) {
|
||||
return task_time;
|
||||
}
|
||||
|
||||
// Remove the task from the tree of tasks, and update our next task.
|
||||
this->RemoveTaskFromTree(task);
|
||||
|
||||
// Handle the task.
|
||||
task->OnTimer();
|
||||
}
|
||||
}
|
||||
|
||||
bool RegisterAbsoluteTaskImpl(KTimerTask* task, s64 task_time) {
|
||||
ASSERT(task_time > 0);
|
||||
|
||||
// Set the task's time, and insert it into our tree.
|
||||
task->SetTime(task_time);
|
||||
m_task_tree.insert(*task);
|
||||
|
||||
// Update our next task if relevant.
|
||||
if (m_next_task != nullptr && m_next_task->GetTime() <= task_time) {
|
||||
return false;
|
||||
}
|
||||
m_next_task = task;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
void RemoveTaskFromTree(KTimerTask* task) {
|
||||
// Erase from the tree.
|
||||
auto it = m_task_tree.erase(m_task_tree.iterator_to(*task));
|
||||
|
||||
// Clear the task's scheduled time.
|
||||
task->SetTime(0);
|
||||
|
||||
// Update our next task if relevant.
|
||||
if (m_next_task == task) {
|
||||
m_next_task = (it != m_task_tree.end()) ? std::addressof(*it) : nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
KernelCore& m_kernel;
|
||||
|
||||
private:
|
||||
using TimerTaskTree = Common::IntrusiveRedBlackTreeBaseTraits<KTimerTask>::TreeType<KTimerTask>;
|
||||
|
||||
KSpinLock m_lock{};
|
||||
TimerTaskTree m_task_tree{};
|
||||
KTimerTask* m_next_task{};
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
||||
@@ -280,18 +280,19 @@ struct KMemoryInfo {
|
||||
|
||||
class KMemoryBlock : public Common::IntrusiveRedBlackTreeBaseNode<KMemoryBlock> {
|
||||
private:
|
||||
u16 m_device_disable_merge_left_count;
|
||||
u16 m_device_disable_merge_right_count;
|
||||
VAddr m_address;
|
||||
size_t m_num_pages;
|
||||
KMemoryState m_memory_state;
|
||||
u16 m_ipc_lock_count;
|
||||
u16 m_device_use_count;
|
||||
u16 m_ipc_disable_merge_count;
|
||||
KMemoryPermission m_permission;
|
||||
KMemoryPermission m_original_permission;
|
||||
KMemoryAttribute m_attribute;
|
||||
KMemoryBlockDisableMergeAttribute m_disable_merge_attribute;
|
||||
u16 m_device_disable_merge_left_count{};
|
||||
u16 m_device_disable_merge_right_count{};
|
||||
VAddr m_address{};
|
||||
size_t m_num_pages{};
|
||||
KMemoryState m_memory_state{KMemoryState::None};
|
||||
u16 m_ipc_lock_count{};
|
||||
u16 m_device_use_count{};
|
||||
u16 m_ipc_disable_merge_count{};
|
||||
KMemoryPermission m_permission{KMemoryPermission::None};
|
||||
KMemoryPermission m_original_permission{KMemoryPermission::None};
|
||||
KMemoryAttribute m_attribute{KMemoryAttribute::None};
|
||||
KMemoryBlockDisableMergeAttribute m_disable_merge_attribute{
|
||||
KMemoryBlockDisableMergeAttribute::None};
|
||||
|
||||
public:
|
||||
static constexpr int Compare(const KMemoryBlock& lhs, const KMemoryBlock& rhs) {
|
||||
@@ -367,12 +368,8 @@ public:
|
||||
|
||||
constexpr KMemoryBlock(VAddr addr, size_t np, KMemoryState ms, KMemoryPermission p,
|
||||
KMemoryAttribute attr)
|
||||
: Common::IntrusiveRedBlackTreeBaseNode<KMemoryBlock>(),
|
||||
m_device_disable_merge_left_count(), m_device_disable_merge_right_count(),
|
||||
m_address(addr), m_num_pages(np), m_memory_state(ms), m_ipc_lock_count(0),
|
||||
m_device_use_count(0), m_ipc_disable_merge_count(), m_permission(p),
|
||||
m_original_permission(KMemoryPermission::None), m_attribute(attr),
|
||||
m_disable_merge_attribute() {}
|
||||
: Common::IntrusiveRedBlackTreeBaseNode<KMemoryBlock>(), m_address(addr), m_num_pages(np),
|
||||
m_memory_state(ms), m_permission(p), m_attribute(attr) {}
|
||||
|
||||
constexpr void Initialize(VAddr addr, size_t np, KMemoryState ms, KMemoryPermission p,
|
||||
KMemoryAttribute attr) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
@@ -17,9 +18,9 @@ public:
|
||||
static constexpr size_t MaxBlocks = 2;
|
||||
|
||||
private:
|
||||
KMemoryBlock* m_blocks[MaxBlocks];
|
||||
size_t m_index;
|
||||
KMemoryBlockSlabManager* m_slab_manager;
|
||||
std::array<KMemoryBlock*, MaxBlocks> m_blocks{};
|
||||
size_t m_index{MaxBlocks};
|
||||
KMemoryBlockSlabManager* m_slab_manager{};
|
||||
|
||||
private:
|
||||
Result Initialize(size_t num_blocks) {
|
||||
@@ -41,7 +42,7 @@ private:
|
||||
public:
|
||||
KMemoryBlockManagerUpdateAllocator(Result* out_result, KMemoryBlockSlabManager* sm,
|
||||
size_t num_blocks = MaxBlocks)
|
||||
: m_blocks(), m_index(MaxBlocks), m_slab_manager(sm) {
|
||||
: m_slab_manager(sm) {
|
||||
*out_result = this->Initialize(num_blocks);
|
||||
}
|
||||
|
||||
|
||||
@@ -223,10 +223,10 @@ Result KMemoryManager::AllocatePageGroupImpl(KPageGroup* out, size_t num_pages,
|
||||
|
||||
// Ensure that we don't leave anything un-freed.
|
||||
ON_RESULT_FAILURE {
|
||||
for (const auto& it : out->Nodes()) {
|
||||
for (const auto& it : *out) {
|
||||
auto& manager = this->GetManager(it.GetAddress());
|
||||
const size_t node_num_pages =
|
||||
std::min(it.GetNumPages(), (manager.GetEndAddress() - it.GetAddress()) / PageSize);
|
||||
const size_t node_num_pages = std::min<u64>(
|
||||
it.GetNumPages(), (manager.GetEndAddress() - it.GetAddress()) / PageSize);
|
||||
manager.Free(it.GetAddress(), node_num_pages);
|
||||
}
|
||||
out->Finalize();
|
||||
@@ -285,7 +285,7 @@ Result KMemoryManager::AllocateAndOpen(KPageGroup* out, size_t num_pages, u32 op
|
||||
m_has_optimized_process[static_cast<size_t>(pool)], true));
|
||||
|
||||
// Open the first reference to the pages.
|
||||
for (const auto& block : out->Nodes()) {
|
||||
for (const auto& block : *out) {
|
||||
PAddr cur_address = block.GetAddress();
|
||||
size_t remaining_pages = block.GetNumPages();
|
||||
while (remaining_pages > 0) {
|
||||
@@ -335,7 +335,7 @@ Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32
|
||||
// Perform optimized memory tracking, if we should.
|
||||
if (optimized) {
|
||||
// Iterate over the allocated blocks.
|
||||
for (const auto& block : out->Nodes()) {
|
||||
for (const auto& block : *out) {
|
||||
// Get the block extents.
|
||||
const PAddr block_address = block.GetAddress();
|
||||
const size_t block_pages = block.GetNumPages();
|
||||
@@ -391,7 +391,7 @@ Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32
|
||||
}
|
||||
} else {
|
||||
// Set all the allocated memory.
|
||||
for (const auto& block : out->Nodes()) {
|
||||
for (const auto& block : *out) {
|
||||
std::memset(m_system.DeviceMemory().GetPointer<void>(block.GetAddress()), fill_pattern,
|
||||
block.GetSize());
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user