Compare commits

...

21 Commits

Author SHA1 Message Date
GPUCode
b94374009e code: Add texture sampling option
* This replaces the nearest neighbour filter that shouldn't have existed in the first place
2023-11-23 01:22:47 +02:00
Wunk
b10f3d96f5 command_processor: Fix out-of-bounds float-uniform access (#7111)
Addresses:
https://github.com/citra-emu/citra/issues/6696
https://github.com/citra-emu/citra/issues/6871
2023-11-03 03:35:52 -07:00
Steveice10
b5d744bcae ci: Work around macOS GitHub runner pip install failures. (#7110) 2023-11-03 03:35:32 -07:00
Castor215
89d5d4a2b6 externals: allow user to use system cubeb (#7107) 2023-11-02 17:33:40 -07:00
PabloMK7
4284893044 Implement RomFS cache and async reads. (#7089)
* Implement RomFS cache and async reads.

* Suggestions and fix compilation.

* Apply suggestions
2023-11-02 17:19:00 -07:00
Steveice10
79ea06b226 qt: Update to 6.6.0 (#7099) 2023-11-01 17:58:02 -07:00
Castor215
8d811913a5 externals: allow user to use system cryptopp (#7105) 2023-11-01 17:57:10 -07:00
Wunk
ac9d72a95c vk_texture_runtime: Fix debug scope label lambda-capture (#7102)
`DebugScope` was capturing a `string_view` in a lambda which is only
valid during the scope of this ctor. When the lambda gets invoked at a
later time, it will read undefined garbage. The lambda needs to make a
deep copy of this `string_view` into a `string` so that it is valid by
the time the scheduler invokes this lambda.
2023-11-01 21:30:54 +01:00
Castor215
d3ce43782d externals: allow users to use system libenet (#7100) 2023-10-31 14:01:50 -07:00
PabloMK7
597a2e8ead Add missing FS:USER functions (#7051) 2023-10-31 14:01:25 -07:00
TGP17
b231a22ea5 Switch compiler to clang on Linux (#7077) 2023-10-25 11:00:52 -07:00
Steveice10
1110c01657 ci: Install Vulkan SPIRV-Tools on Windows to fix glslang install error. (#7092) 2023-10-25 11:00:10 -07:00
Steveice10
45ef11654a audio_core: Clear time stretcher after flushing to avoid sample bleed. (#7081) 2023-10-24 17:22:10 -07:00
Dominik Kreutzer
259dbf17dc citra-qt: ensure image interface is registered before starting game (#7090) 2023-10-24 17:21:38 -07:00
Castor215
ec55807669 build: fix build failure when not using precompiled headers (#7087)
Co-authored-by: vitor-k <vitor-kiguchi@hotmail.com>
2023-10-23 17:21:35 -03:00
GPUCode
36146459f8 renderer_vulkan: Fix screenshots under NVIDIA vulkan (#7082) 2023-10-22 22:53:14 +03:00
Wunk
597297ffb4 tests: Fix out-of-bounds access (#7085) 2023-10-22 11:07:06 -07:00
Castor215
4ac10c4a9d externals: allow users to use system Zstandard (#7083) 2023-10-21 16:10:02 -07:00
Castor215
2416258117 externals: add overarching USE_SYSTEM_LIBS variable (#7078) 2023-10-20 17:02:20 -07:00
Steveice10
6d4e462e42 build: Ensure we default to Release build type. (#7080) 2023-10-19 15:02:49 -07:00
GPUCode
ef43776c7b shader: Fix address register offset behavior in x64 Jit (#6942)
* shader: Fix address register offset behavior in x64 Jit

* shader: Remove redundant jump

* tests: Add address register tests

* shader: Remove additional pre-multiplications by 16

* tests: Add catch-stringifier for vec4f

* tests: Format
2023-10-18 19:41:36 +03:00
54 changed files with 1198 additions and 340 deletions

View File

@@ -1,5 +1,10 @@
#!/bin/bash -ex
# TODO: Work around pip install issues with Python 3.12 in the GitHub runner image.
# See: https://github.com/actions/runner-images/issues/8709
PYTHON_PATH=$(brew --prefix python@3.11)
export PATH=$PYTHON_PATH/bin:$PYTHON_PATH/libexec/bin:$PATH
mkdir build && cd build
cmake .. -GNinja \
-DCMAKE_BUILD_TYPE=Release \

View File

@@ -5,6 +5,9 @@ cmake .. -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_LINKER=/etc/bin/ld.lld \
-DENABLE_QT_TRANSLATION=ON \
-DCITRA_ENABLE_COMPATIBILITY_REPORTING=ON \
-DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON \

View File

@@ -1,5 +1,10 @@
#!/bin/bash -ex
# TODO: Work around pip install issues with Python 3.12 in the GitHub runner image.
# See: https://github.com/actions/runner-images/issues/8709
PYTHON_PATH=$(brew --prefix python@3.11)
export PATH=$PYTHON_PATH/bin:$PYTHON_PATH/libexec/bin:$PATH
mkdir build && cd build
cmake .. -GNinja \
-DCMAKE_BUILD_TYPE=Release \

View File

@@ -59,7 +59,7 @@ jobs:
name: ${{ env.OS }}-${{ env.TARGET }}
path: artifacts/
macos:
runs-on: macos-latest
runs-on: macos-13
strategy:
matrix:
target: ["x86_64", "arm64"]
@@ -92,7 +92,7 @@ jobs:
path: ${{ env.OS }}-${{ env.TARGET }}
key: ${{ runner.os }}-${{ matrix.target }}-${{ github.sha }}-${{ github.run_id }}-${{ github.run_attempt }}
macos-universal:
runs-on: macos-latest
runs-on: macos-13
needs: macos
env:
OS: macos
@@ -158,7 +158,7 @@ jobs:
if: ${{ matrix.target == 'msvc' }}
with:
vulkan-query-version: latest
vulkan-components: Glslang
vulkan-components: SPIRV-Tools, Glslang
vulkan-use-cache: true
- name: Set up MSYS2
uses: msys2/setup-msys2@v2
@@ -234,7 +234,7 @@ jobs:
name: ${{ env.OS }}-${{ env.TARGET }}
path: src/android/app/artifacts/
ios:
runs-on: macos-latest
runs-on: macos-13
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache

View File

@@ -17,6 +17,12 @@ include(CMakeDependentOption)
project(citra LANGUAGES C CXX ASM)
# Some submodules like to pick their own default build type if not specified.
# Make sure we default to Release build type always, unless the generator has custom types.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
if (APPLE)
# Silence warnings on empty objects, for example when platform-specific code is #ifdef'd out.
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
@@ -86,24 +92,7 @@ option(ENABLE_LTO "Enable link time optimization" ${DEFAULT_ENABLE_LTO})
option(CITRA_USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
option(CITRA_WARNINGS_AS_ERRORS "Enable warnings as errors" ON)
# System library options
CMAKE_DEPENDENT_OPTION(USE_SYSTEM_QT "Use the system Qt lib (instead of the bundled one)" OFF "ENABLE_QT;MSVC OR APPLE" ON)
CMAKE_DEPENDENT_OPTION(USE_SYSTEM_MOLTENVK "Use the system MoltenVK lib (instead of the bundled one)" OFF "APPLE" OFF)
option(USE_SYSTEM_SDL2 "Use the system SDL2 lib (instead of the bundled one)" OFF)
option(USE_SYSTEM_BOOST "Use the system Boost libs (instead of the bundled ones)" OFF)
option(USE_SYSTEM_OPENSSL "Use the system OpenSSL libs (instead of the bundled LibreSSL)" OFF)
option(USE_SYSTEM_LIBUSB "Use the system libusb (instead of the bundled libusb)" OFF)
option(USE_SYSTEM_CPP_JWT "Use the system cpp-jwt (instead of the bundled one)" OFF)
option(USE_SYSTEM_SOUNDTOUCH "Use the system SoundTouch (instead of the bundled one)" OFF)
option(USE_SYSTEM_CPP_HTTPLIB "Use the system cpp-httplib (instead of the bundled one)" OFF)
option(USE_SYSTEM_JSON "Use the system JSON (nlohmann-json3) package (instead of the bundled one)" OFF)
option(USE_SYSTEM_DYNARMIC "Use the system dynarmic (instead of the bundled one)" OFF)
option(USE_SYSTEM_FMT "Use the system fmt (instead of the bundled one)" OFF)
option(USE_SYSTEM_XBYAK "Use the system xbyak (instead of the bundled one)" OFF)
option(USE_SYSTEM_INIH "Use the system inih (instead of the bundled one)" OFF)
option(USE_SYSTEM_FDK_AAC_HEADERS "Use the system fdk-aac headers (instead of the bundled one)" OFF)
option(USE_SYSTEM_FFMPEG_HEADERS "Use the system FFmpeg headers (instead of the bundled one)" OFF)
option(USE_SYSTEM_GLSLANG "Use the system glslang and SPIR-V libraries (instead of the bundled ones)" OFF)
include(CitraHandleSystemLibs)
if (CITRA_USE_PRECOMPILED_HEADERS)
message(STATUS "Using Precompiled Headers.")
@@ -247,7 +236,7 @@ find_package(Threads REQUIRED)
if (ENABLE_QT)
if (NOT USE_SYSTEM_QT)
download_qt(6.5.1)
download_qt(6.6.0)
endif()
find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia Concurrent)

View File

@@ -2,7 +2,13 @@
Name=colorful_dark
Comment=Colorful theme (Dark style)
Inherits=default
Directories=16x16
Directories=16x16,48x48,256x256
[16x16]
Size=16
[48x48]
Size=48
[256x256]
Size=256

View File

@@ -2,7 +2,13 @@
Name=colorful_midnight_blue
Comment=Colorful theme (Midnight Blue style)
Inherits=default
Directories=16x16
Directories=16x16,48x48,256x256
[16x16]
Size=16
[48x48]
Size=48
[256x256]
Size=256

View File

@@ -34,6 +34,10 @@ if (NOT USE_SYSTEM_BOOST)
)
target_link_libraries(boost_iostreams PUBLIC boost)
# Add additional boost libs here; remember to ALIAS them in the root CMakeLists!
else()
unset(BOOST_ROOT CACHE)
unset(Boost_INCLUDE_DIR CACHE)
set(Boost_NO_SYSTEM_PATHS OFF CACHE BOOL "" FORCE)
endif()
# Catch2
@@ -42,11 +46,17 @@ set(CATCH_INSTALL_EXTRAS OFF CACHE BOOL "")
add_subdirectory(catch2)
# Crypto++
set(CRYPTOPP_BUILD_DOCUMENTATION OFF CACHE BOOL "")
set(CRYPTOPP_BUILD_TESTING OFF CACHE BOOL "")
set(CRYPTOPP_INSTALL OFF CACHE BOOL "")
set(CRYPTOPP_SOURCES "${CMAKE_SOURCE_DIR}/externals/cryptopp" CACHE STRING "")
add_subdirectory(cryptopp-cmake)
if(USE_SYSTEM_CRYPTOPP)
find_package(cryptopp REQUIRED)
add_library(cryptopp INTERFACE)
target_link_libraries(cryptopp INTERFACE cryptopp::cryptopp)
else()
set(CRYPTOPP_BUILD_DOCUMENTATION OFF CACHE BOOL "")
set(CRYPTOPP_BUILD_TESTING OFF CACHE BOOL "")
set(CRYPTOPP_INSTALL OFF CACHE BOOL "")
set(CRYPTOPP_SOURCES "${CMAKE_SOURCE_DIR}/externals/cryptopp" CACHE STRING "")
add_subdirectory(cryptopp-cmake)
endif()
# dds-ktx
add_library(dds-ktx INTERFACE)
@@ -207,22 +217,47 @@ if (ENABLE_LIBUSB AND NOT USE_SYSTEM_LIBUSB)
endif()
# Zstandard
set(ZSTD_LEGACY_SUPPORT OFF)
set(ZSTD_BUILD_PROGRAMS OFF)
set(ZSTD_BUILD_SHARED OFF)
add_subdirectory(zstd/build/cmake EXCLUDE_FROM_ALL)
target_include_directories(libzstd_static INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/externals/zstd/lib>)
if(USE_SYSTEM_ZSTD)
find_package(zstd REQUIRED)
add_library(zstd INTERFACE)
if(TARGET zstd::libzstd_shared)
message(STATUS "Found system Zstandard")
endif()
target_link_libraries(zstd INTERFACE zstd::libzstd_shared)
else()
set(ZSTD_LEGACY_SUPPORT OFF)
set(ZSTD_BUILD_PROGRAMS OFF)
set(ZSTD_BUILD_SHARED OFF)
add_subdirectory(zstd/build/cmake EXCLUDE_FROM_ALL)
target_include_directories(libzstd_static INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/externals/zstd/lib>)
add_library(zstd ALIAS libzstd_static)
endif()
# ENet
add_subdirectory(enet)
target_include_directories(enet INTERFACE ./enet/include)
if(USE_SYSTEM_ENET)
find_package(libenet REQUIRED)
add_library(enet INTERFACE)
target_link_libraries(enet INTERFACE libenet::libenet)
else()
add_subdirectory(enet)
target_include_directories(enet INTERFACE ./enet/include)
endif()
# Cubeb
if (ENABLE_CUBEB)
set(BUILD_TESTS OFF CACHE BOOL "")
set(BUILD_TOOLS OFF CACHE BOOL "")
set(BUNDLE_SPEEX ON CACHE BOOL "")
add_subdirectory(cubeb EXCLUDE_FROM_ALL)
if(USE_SYSTEM_CUBEB)
find_package(cubeb REQUIRED)
add_library(cubeb INTERFACE)
target_link_libraries(cubeb INTERFACE cubeb::cubeb)
if(TARGET cubeb::cubeb)
message(STATUS "Found system cubeb")
endif()
else()
set(BUILD_TESTS OFF CACHE BOOL "")
set(BUILD_TOOLS OFF CACHE BOOL "")
set(BUNDLE_SPEEX ON CACHE BOOL "")
add_subdirectory(cubeb EXCLUDE_FROM_ALL)
endif()
endif()
# DiscordRPC

View File

@@ -0,0 +1,88 @@
option(USE_SYSTEM_LIBS "Use system libraries over bundled ones" OFF)
# System library options
CMAKE_DEPENDENT_OPTION(USE_SYSTEM_QT "Use the system Qt lib (instead of the bundled one)" OFF "ENABLE_QT;MSVC OR APPLE" ON)
CMAKE_DEPENDENT_OPTION(USE_SYSTEM_MOLTENVK "Use the system MoltenVK lib (instead of the bundled one)" OFF "APPLE" OFF)
option(USE_SYSTEM_SDL2 "Use the system SDL2 lib (instead of the bundled one)" OFF)
option(USE_SYSTEM_BOOST "Use the system Boost libs (instead of the bundled ones)" OFF)
option(USE_SYSTEM_OPENSSL "Use the system OpenSSL libs (instead of the bundled LibreSSL)" OFF)
option(USE_SYSTEM_LIBUSB "Use the system libusb (instead of the bundled libusb)" OFF)
option(USE_SYSTEM_CPP_JWT "Use the system cpp-jwt (instead of the bundled one)" OFF)
option(USE_SYSTEM_SOUNDTOUCH "Use the system SoundTouch (instead of the bundled one)" OFF)
option(USE_SYSTEM_CPP_HTTPLIB "Use the system cpp-httplib (instead of the bundled one)" OFF)
option(USE_SYSTEM_JSON "Use the system JSON (nlohmann-json3) package (instead of the bundled one)" OFF)
option(USE_SYSTEM_DYNARMIC "Use the system dynarmic (instead of the bundled one)" OFF)
option(USE_SYSTEM_FMT "Use the system fmt (instead of the bundled one)" OFF)
option(USE_SYSTEM_XBYAK "Use the system xbyak (instead of the bundled one)" OFF)
option(USE_SYSTEM_INIH "Use the system inih (instead of the bundled one)" OFF)
option(USE_SYSTEM_FDK_AAC_HEADERS "Use the system fdk-aac headers (instead of the bundled one)" OFF)
option(USE_SYSTEM_FFMPEG_HEADERS "Use the system FFmpeg headers (instead of the bundled one)" OFF)
option(USE_SYSTEM_GLSLANG "Use the system glslang and SPIR-V libraries (instead of the bundled ones)" OFF)
option(USE_SYSTEM_ZSTD "Use the system Zstandard library (instead of the bundled one)" OFF)
option(USE_SYSTEM_ENET "Use the system libenet (instead of the bundled one)" OFF)
option(USE_SYSTEM_CRYPTOPP "Use the system cryptopp (instead of the bundled one)" OFF)
option(USE_SYSTEM_CUBEB "Use the system cubeb (instead of the bundled one)" OFF)
# Qt and MoltenVK are handled separately
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_SDL2 "Disable system SDL2" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_BOOST "Disable system Boost" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_OPENSSL "Disable system OpenSSL" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_LIBUSB "Disable system LibUSB" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CPP_JWT "Disable system cpp-jwt" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_SOUNDTOUCH "Disable system SoundTouch" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CPP_HTTPLIB "Disable system cpp-httplib" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_JSON "Disable system JSON" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_DYNARMIC "Disable system Dynarmic" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FMT "Disable system fmt" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_XBYAK "Disable system xbyak" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_INIH "Disable system inih" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FDK_AAC_HEADERS "Disable system fdk_aac" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FFMPEG_HEADERS "Disable system ffmpeg" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_GLSLANG "Disable system glslang" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_ZSTD "Disable system Zstandard" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_ENET "Disable system libenet" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CRYPTOPP "Disable system cryptopp" OFF "USE_SYSTEM_LIBS" OFF)
CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CUBEB "Disable system cubeb" OFF "USE_SYSTEM_LIBS" OFF)
set(LIB_VAR_LIST
SDL2
BOOST
OPENSSL
LIBUSB
CPP_JWT
SOUNDTOUCH
CPP_HTTPLIB
JSON
DYNARMIC
FMT
XBYAK
INIH
FDK_AAC_HEADERS
FFMPEG_HEADERS
GLSLANG
ZSTD
ENET
CRYPTOPP
CUBEB
)
# First, check that USE_SYSTEM_XXX is not used with USE_SYSTEM_LIBS
if(USE_SYSTEM_LIBS)
foreach(CURRENT_LIB IN LISTS LIB_VAR_LIST)
if(USE_SYSTEM_${CURRENT_LIB})
unset(USE_SYSTEM_${CURRENT_LIB})
endif()
endforeach()
# Next, set which libraries to use
foreach(CURRENT_LIB IN LISTS LIB_VAR_LIST)
if(NOT DISABLE_SYSTEM_${CURRENT_LIB})
set(USE_SYSTEM_${CURRENT_LIB} ON CACHE BOOL "Using system ${CURRENT_LIB}" FORCE)
else()
# Explicitly disable this in case of multiple CMake invocations
set(USE_SYSTEM_${CURRENT_LIB} OFF CACHE BOOL "Using system ${CURRENT_LIB}" FORCE)
endif()
endforeach()
endif()

View File

@@ -0,0 +1,36 @@
if(NOT CRYPTOPP_FOUND)
pkg_check_modules(CRYPTOPP_TMP libcrypto++)
find_path(CRYPTOPP_INCLUDE_DIRS NAMES cryptlib.h
PATHS
${CRYPTOPP_TMP_INCLUDE_DIRS}
/usr/include
/usr/include/crypto++
/usr/local/include
/usr/local/include/crypto++
)
find_library(CRYPTOPP_LIBRARY_DIRS NAMES crypto++
PATHS
${CRYPTOPP_TMP_LIBRARY_DIRS}
/usr/lib
/usr/locallib
)
if(CRYPTOPP_INCLUDE_DIRS AND CRYPTOPP_LIBRARY_DIRS)
set(CRYPTOPP_FOUND TRUE CACHE INTERNAL "Found cryptopp")
message(STATUS "Found cryptopp: ${CRYPTOPP_LIBRARY_DIRS}, ${CRYPTOPP_INCLUDE_DIRS}")
else()
set(CRYPTOPP_FOUND FALSE CACHE INTERNAL "Found cryptopp")
message(STATUS "Cryptopp not found.")
endif()
endif()
if(CRYPTOPP_FOUND AND NOT TARGET cryptopp::cryptopp)
add_library(cryptopp::cryptopp UNKNOWN IMPORTED)
set_target_properties(cryptopp::cryptopp PROPERTIES
INCLUDE_DIRECTORIES ${CRYPTOPP_INCLUDE_DIRS}
INTERFACE_LINK_LIBRARIES ${CRYPTOPP_LIBRARY_DIRS}
IMPORTED_LOCATION ${CRYPTOPP_LIBRARY_DIRS}
)
endif()

View File

@@ -0,0 +1,34 @@
if(NOT libenet_FOUND)
pkg_check_modules(ENET_TMP libenet)
find_path(libenet_INCLUDE_DIRS NAMES enet.h PATH_SUFFIXES enet
PATHS
${ENET_TMP_INCLUDE_DIRS}
/usr/include
/usr/local/include
)
find_library(libenet_LIBRARY_DIRS NAMES enet
PATHS
${ENET_TMP_LIBRARY_DIRS}
/usr/lib
/usr/local/lib
)
if(libenet_INCLUDE_DIRS AND libenet_LIBRARY_DIRS)
set(libenet_FOUND TRUE CACHE INTERNAL "Found libenet")
message(STATUS "Found libenet ${libenet_LIBRARY_DIRS}, ${libenet_INCLUDE_DIRS}")
else()
set(libenet_FOUND FALSE CACHE INTERNAL "Found libenet")
message(STATUS "Libenet not found.")
endif()
endif()
if(libenet_FOUND AND NOT TARGET libenet::libenet)
add_library(libenet::libenet UNKNOWN IMPORTED)
set_target_properties(libenet::libenet PROPERTIES
INCLUDE_DIRECTORIES ${libenet_INCLUDE_DIRS}
INTERFACE_LINK_LIBRARIES ${libenet_LIBRARY_DIRS}
IMPORTED_LOCATION ${libenet_LIBRARY_DIRS}
)
endif()

View File

@@ -66,18 +66,22 @@ void DspInterface::OutputSample(std::array<s16, 2> sample) {
}
void DspInterface::OutputCallback(s16* buffer, std::size_t num_frames) {
std::size_t frames_written;
std::size_t frames_written = 0;
if (perform_time_stretching) {
const std::vector<s16> in{fifo.Pop()};
const std::size_t num_in{in.size() / 2};
frames_written = time_stretcher.Process(in.data(), num_in, buffer, num_frames);
} else if (flushing_time_stretcher) {
time_stretcher.Flush();
frames_written = time_stretcher.Process(nullptr, 0, buffer, num_frames);
frames_written += fifo.Pop(buffer, num_frames - frames_written);
flushing_time_stretcher = false;
} else {
frames_written = fifo.Pop(buffer, num_frames);
if (flushing_time_stretcher) {
time_stretcher.Flush();
frames_written = time_stretcher.Process(nullptr, 0, buffer, num_frames);
flushing_time_stretcher = false;
// Make sure any frames that did not fit are cleared from the time stretcher,
// so that they do not bleed into the next time the stretcher is enabled.
time_stretcher.Clear();
}
frames_written += fifo.Pop(buffer, num_frames - frames_written);
}
if (frames_written > 0) {

View File

@@ -18,8 +18,7 @@
namespace AudioCore {
TimeStretcher::TimeStretcher()
: sample_rate(native_sample_rate), sound_touch(std::make_unique<soundtouch::SoundTouch>()) {
TimeStretcher::TimeStretcher() : sound_touch(std::make_unique<soundtouch::SoundTouch>()) {
sound_touch->setChannels(2);
sound_touch->setSampleRate(native_sample_rate);
sound_touch->setPitch(1.0);
@@ -30,16 +29,15 @@ TimeStretcher::~TimeStretcher() = default;
void TimeStretcher::SetOutputSampleRate(unsigned int sample_rate) {
sound_touch->setSampleRate(sample_rate);
sample_rate = native_sample_rate;
}
std::size_t TimeStretcher::Process(const s16* in, std::size_t num_in, s16* out,
std::size_t num_out) {
const double time_delta = static_cast<double>(num_out) / sample_rate; // seconds
const double time_delta = static_cast<double>(num_out) / native_sample_rate; // seconds
double current_ratio = static_cast<double>(num_in) / static_cast<double>(num_out);
const double max_latency = 0.25; // seconds
const double max_backlog = sample_rate * max_latency;
const double max_backlog = native_sample_rate * max_latency;
const double backlog_fullness = sound_touch->numSamples() / max_backlog;
if (backlog_fullness > 4.0) {
// Too many samples in backlog: Don't push anymore on

View File

@@ -34,7 +34,6 @@ public:
void Flush();
private:
unsigned int sample_rate;
std::unique_ptr<soundtouch::SoundTouch> sound_touch;
double stretch_ratio = 1.0;
};

View File

@@ -669,9 +669,9 @@ void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_p
screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
system.Renderer().RequestScreenshot(
screenshot_image.bits(),
[this, screenshot_path] {
[this, screenshot_path](bool invert_y) {
const std::string std_screenshot_path = screenshot_path.toStdString();
if (screenshot_image.mirrored(false, true).save(screenshot_path)) {
if (screenshot_image.mirrored(false, invert_y).save(screenshot_path)) {
LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path);
} else {
LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path);

View File

@@ -184,11 +184,6 @@
<string>Bicubic</string>
</property>
</item>
<item>
<property name="text">
<string>Nearest Neighbor</string>
</property>
</item>
<item>
<property name="text">
<string>ScaleForce</string>
@@ -199,11 +194,11 @@
<string>xBRZ</string>
</property>
</item>
<item>
<property name="text">
<string>MMPX</string>
</property>
</item>
<item>
<property name="text">
<string>MMPX</string>
</property>
</item>
</widget>
</item>
</layout>

View File

@@ -71,11 +71,17 @@ void ConfigureGraphics::SetConfiguration() {
!Settings::values.physical_device.UsingGlobal());
ConfigurationShared::SetPerGameSetting(ui->physical_device_combo,
&Settings::values.physical_device);
ConfigurationShared::SetPerGameSetting(ui->texture_sampling_combobox,
&Settings::values.texture_sampling);
ConfigurationShared::SetHighlight(ui->widget_texture_sampling,
!Settings::values.texture_sampling.UsingGlobal());
} else {
ui->graphics_api_combo->setCurrentIndex(
static_cast<int>(Settings::values.graphics_api.GetValue()));
ui->physical_device_combo->setCurrentIndex(
static_cast<int>(Settings::values.physical_device.GetValue()));
ui->texture_sampling_combobox->setCurrentIndex(
static_cast<int>(Settings::values.texture_sampling.GetValue()));
}
ui->toggle_hw_shader->setChecked(Settings::values.use_hw_shader.GetValue());
@@ -106,6 +112,8 @@ void ConfigureGraphics::ApplyConfiguration() {
use_hw_shader);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.shaders_accurate_mul,
ui->toggle_accurate_mul, shaders_accurate_mul);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.texture_sampling,
ui->texture_sampling_combobox);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache,
ui->toggle_disk_shader_cache, use_disk_shader_cache);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_vsync_new, ui->toggle_vsync_new,
@@ -132,6 +140,7 @@ void ConfigureGraphics::SetupPerGameUI() {
Settings::values.use_vsync_new.UsingGlobal());
ui->toggle_async_shaders->setEnabled(
Settings::values.async_shader_compilation.UsingGlobal());
ui->widget_texture_sampling->setEnabled(Settings::values.texture_sampling.UsingGlobal());
ui->toggle_async_present->setEnabled(Settings::values.async_presentation.UsingGlobal());
ui->graphics_api_combo->setEnabled(Settings::values.graphics_api.UsingGlobal());
ui->physical_device_combo->setEnabled(Settings::values.physical_device.UsingGlobal());
@@ -148,6 +157,10 @@ void ConfigureGraphics::SetupPerGameUI() {
ui->physical_device_combo, ui->physical_device_group,
static_cast<u32>(Settings::values.physical_device.GetValue(true)));
ConfigurationShared::SetColoredComboBox(
ui->texture_sampling_combobox, ui->widget_texture_sampling,
static_cast<int>(Settings::values.texture_sampling.GetValue(true)));
ConfigurationShared::SetColoredTristate(ui->toggle_hw_shader, Settings::values.use_hw_shader,
use_hw_shader);
ConfigurationShared::SetColoredTristate(

View File

@@ -212,6 +212,53 @@
<string>Advanced</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="widget_texture_sampling" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="texture_sampling_label">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Overrides the sampling filter used by games. This can be useful in certain cases with poorly behaved games when upscaling. If unsure set this to Game Controlled&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Texture Sampling</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="texture_sampling_combobox">
<item>
<property name="text">
<string>Game Controlled</string>
</property>
</item>
<item>
<property name="text">
<string>Nearest Neighbor</string>
</property>
</item>
<item>
<property name="text">
<string>Linear</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="toggle_disk_shader_cache">
<property name="toolTip">

View File

@@ -258,13 +258,15 @@ void GameList::OnUpdateThemedIcons() {
for (int i = 0; i < item_model->invisibleRootItem()->rowCount(); i++) {
QStandardItem* child = item_model->invisibleRootItem()->child(i);
const int icon_size = IconSizes.at(UISettings::values.game_list_icon_size.GetValue());
switch (child->data(GameListItem::TypeRole).value<GameListItemType>()) {
case GameListItemType::InstalledDir:
child->setData(QIcon::fromTheme(QStringLiteral("sd_card")).pixmap(48),
child->setData(QIcon::fromTheme(QStringLiteral("sd_card")).pixmap(icon_size),
Qt::DecorationRole);
break;
case GameListItemType::SystemDir:
child->setData(QIcon::fromTheme(QStringLiteral("chip")).pixmap(48), Qt::DecorationRole);
child->setData(QIcon::fromTheme(QStringLiteral("chip")).pixmap(icon_size),
Qt::DecorationRole);
break;
case GameListItemType::CustomDir: {
const UISettings::GameDir& game_dir =
@@ -272,11 +274,12 @@ void GameList::OnUpdateThemedIcons() {
const QString icon_name = QFileInfo::exists(game_dir.path)
? QStringLiteral("folder")
: QStringLiteral("bad_folder");
child->setData(QIcon::fromTheme(icon_name).pixmap(48), Qt::DecorationRole);
child->setData(QIcon::fromTheme(icon_name).pixmap(icon_size), Qt::DecorationRole);
break;
}
case GameListItemType::AddDir:
child->setData(QIcon::fromTheme(QStringLiteral("plus")).pixmap(48), Qt::DecorationRole);
child->setData(QIcon::fromTheme(QStringLiteral("plus")).pixmap(icon_size),
Qt::DecorationRole);
break;
default:
break;

View File

@@ -2741,7 +2741,10 @@ void GMainWindow::filterBarSetChecked(bool state) {
}
void GMainWindow::UpdateUITheme() {
const QString default_icons = QStringLiteral(":/icons/default");
const QString icons_base_path = QStringLiteral(":/icons/");
const QString default_theme = QStringLiteral("default");
const QString default_theme_path = icons_base_path + default_theme;
const QString& current_theme = UISettings::values.theme;
const bool is_default_theme = current_theme == QString::fromUtf8(UISettings::themes[0].second);
QStringList theme_paths(default_theme_paths);
@@ -2759,8 +2762,8 @@ void GMainWindow::UpdateUITheme() {
qApp->setStyleSheet({});
setStyleSheet({});
}
theme_paths.append(default_icons);
QIcon::setThemeName(default_icons);
theme_paths.append(default_theme_path);
QIcon::setThemeName(default_theme);
} else {
const QString theme_uri(QLatin1Char{':'} + current_theme + QStringLiteral("/style.qss"));
QFile f(theme_uri);
@@ -2772,9 +2775,9 @@ void GMainWindow::UpdateUITheme() {
LOG_ERROR(Frontend, "Unable to set style, stylesheet file not found");
}
const QString theme_name = QStringLiteral(":/icons/") + current_theme;
theme_paths.append({default_icons, theme_name});
QIcon::setThemeName(theme_name);
const QString current_theme_path = icons_base_path + current_theme;
theme_paths.append({default_theme_path, current_theme_path});
QIcon::setThemeName(current_theme);
}
QIcon::setThemeSearchPaths(theme_paths);
@@ -2998,6 +3001,10 @@ int main(int argc, char* argv[]) {
setlocale(LC_ALL, "C");
auto& system{Core::System::GetInstance()};
// Register Qt image interface
system.RegisterImageInterface(std::make_shared<QtImageInterface>());
GMainWindow main_window(system);
// Register frontend applets
@@ -3006,9 +3013,6 @@ int main(int argc, char* argv[]) {
system.RegisterMiiSelector(std::make_shared<QtMiiSelector>(main_window));
system.RegisterSoftwareKeyboard(std::make_shared<QtKeyboard>(main_window));
// Register Qt image interface
system.RegisterImageInterface(std::make_shared<QtImageInterface>());
#ifdef __APPLE__
// Register microphone permission check.
system.RegisterMicPermissionCheck(&AppleAuthorization::CheckAuthorizationForMicrophone);

View File

@@ -17,7 +17,7 @@
#include "common/file_util.h"
#include "common/logging/log.h"
#ifdef Q_OS_OSX
#ifdef Q_OS_MACOS
#define DEFAULT_TOOL_PATH QStringLiteral("../../../../maintenancetool")
#else
#define DEFAULT_TOOL_PATH QStringLiteral("../maintenancetool")
@@ -102,7 +102,7 @@ QString UpdaterPrivate::ToSystemExe(QString base_path) {
return base_path + QStringLiteral(".exe");
else
return base_path;
#elif defined(Q_OS_OSX)
#elif defined(Q_OS_MACOS)
if (base_path.endsWith(QStringLiteral(".app")))
base_path.truncate(base_path.lastIndexOf(QStringLiteral(".")));
return base_path + QStringLiteral(".app/Contents/MacOS/") + QFileInfo(base_path).fileName();
@@ -112,7 +112,7 @@ QString UpdaterPrivate::ToSystemExe(QString base_path) {
}
QFileInfo UpdaterPrivate::GetMaintenanceTool() const {
#if defined(Q_OS_UNIX) && !defined(Q_OS_OSX)
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
const auto appimage_path = QProcessEnvironment::systemEnvironment()
.value(QStringLiteral("APPIMAGE"), {})
.toStdString();

View File

@@ -124,6 +124,7 @@ add_library(citra_common STATIC
serialization/boost_flat_set.h
serialization/boost_small_vector.hpp
serialization/boost_vector.hpp
static_lru_cache.h
string_literal.h
string_util.cpp
string_util.h
@@ -174,7 +175,7 @@ endif()
create_target_directory_groups(citra_common)
target_link_libraries(citra_common PUBLIC fmt library-headers microprofile Boost::boost Boost::serialization Boost::iostreams)
target_link_libraries(citra_common PRIVATE libzstd_static)
target_link_libraries(citra_common PRIVATE zstd)
if ("x86_64" IN_LIST ARCHITECTURE)
target_link_libraries(citra_common PRIVATE xbyak)

View File

@@ -1155,6 +1155,43 @@ std::size_t IOFile::ReadImpl(void* data, std::size_t length, std::size_t data_si
return std::fread(data, data_size, length, m_file);
}
#ifdef _WIN32
static std::size_t pread(int fd, void* buf, size_t count, uint64_t offset) {
long unsigned int read_bytes = 0;
OVERLAPPED overlapped = {0};
HANDLE file = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
overlapped.OffsetHigh = static_cast<uint32_t>(offset >> 32);
overlapped.Offset = static_cast<uint32_t>(offset & 0xFFFF'FFFFLL);
SetLastError(0);
bool ret = ReadFile(file, buf, static_cast<uint32_t>(count), &read_bytes, &overlapped);
if (!ret && GetLastError() != ERROR_HANDLE_EOF) {
errno = GetLastError();
return std::numeric_limits<std::size_t>::max();
}
return read_bytes;
}
#else
#define pread ::pread
#endif
std::size_t IOFile::ReadAtImpl(void* data, std::size_t length, std::size_t data_size,
std::size_t offset) {
if (!IsOpen()) {
m_good = false;
return std::numeric_limits<std::size_t>::max();
}
if (length == 0) {
return 0;
}
DEBUG_ASSERT(data != nullptr);
return pread(fileno(m_file), data, data_size * length, offset);
}
std::size_t IOFile::WriteImpl(const void* data, std::size_t length, std::size_t data_size) {
if (!IsOpen()) {
m_good = false;

View File

@@ -294,6 +294,18 @@ public:
return items_read;
}
template <typename T>
std::size_t ReadAtArray(T* data, std::size_t length, std::size_t offset) {
static_assert(std::is_trivially_copyable_v<T>,
"Given array does not consist of trivially copyable objects");
std::size_t items_read = ReadAtImpl(data, length, sizeof(T), offset);
if (items_read != length)
m_good = false;
return items_read;
}
template <typename T>
std::size_t WriteArray(const T* data, std::size_t length) {
static_assert(std::is_trivially_copyable_v<T>,
@@ -312,6 +324,12 @@ public:
return ReadArray(reinterpret_cast<char*>(data), length);
}
template <typename T>
std::size_t ReadAtBytes(T* data, std::size_t length, std::size_t offset) {
static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable");
return ReadAtArray(reinterpret_cast<char*>(data), length, offset);
}
template <typename T>
std::size_t WriteBytes(const T* data, std::size_t length) {
static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable");
@@ -363,6 +381,8 @@ public:
private:
std::size_t ReadImpl(void* data, std::size_t length, std::size_t data_size);
std::size_t ReadAtImpl(void* data, std::size_t length, std::size_t data_size,
std::size_t offset);
std::size_t WriteImpl(const void* data, std::size_t length, std::size_t data_size);
bool Open();

View File

@@ -46,8 +46,6 @@ std::string_view GetTextureFilterName(TextureFilter filter) {
return "Anime4K";
case TextureFilter::Bicubic:
return "Bicubic";
case TextureFilter::NearestNeighbor:
return "NearestNeighbor";
case TextureFilter::ScaleForce:
return "ScaleForce";
case TextureFilter::xBRZ:
@@ -59,6 +57,19 @@ std::string_view GetTextureFilterName(TextureFilter filter) {
}
}
std::string_view GetTextureSamplingName(TextureSampling sampling) {
switch (sampling) {
case TextureSampling::GameControlled:
return "GameControlled";
case TextureSampling::NearestNeighbor:
return "NearestNeighbor";
case TextureSampling::Linear:
return "Linear";
default:
return "Invalid";
}
}
} // Anonymous namespace
Values values = {};
@@ -87,6 +98,8 @@ void LogSettings() {
log_setting("Renderer_PostProcessingShader", values.pp_shader_name.GetValue());
log_setting("Renderer_FilterMode", values.filter_mode.GetValue());
log_setting("Renderer_TextureFilter", GetTextureFilterName(values.texture_filter.GetValue()));
log_setting("Renderer_TextureSampling",
GetTextureSamplingName(values.texture_sampling.GetValue()));
log_setting("Stereoscopy_Render3d", values.render_3d.GetValue());
log_setting("Stereoscopy_Factor3d", values.factor_3d.GetValue());
log_setting("Stereoscopy_MonoRenderOption", values.mono_render_option.GetValue());
@@ -175,6 +188,7 @@ void RestoreGlobalState(bool is_powered_on) {
values.resolution_factor.SetGlobal(true);
values.frame_limit.SetGlobal(true);
values.texture_filter.SetGlobal(true);
values.texture_sampling.SetGlobal(true);
values.layout_option.SetGlobal(true);
values.swap_screen.SetGlobal(true);
values.upright_screen.SetGlobal(true);

View File

@@ -72,10 +72,15 @@ enum class TextureFilter : u32 {
None = 0,
Anime4K = 1,
Bicubic = 2,
NearestNeighbor = 3,
ScaleForce = 4,
xBRZ = 5,
MMPX = 6
ScaleForce = 3,
xBRZ = 4,
MMPX = 5,
};
enum class TextureSampling : u32 {
GameControlled = 0,
NearestNeighbor = 1,
Linear = 2,
};
namespace NativeButton {
@@ -451,6 +456,8 @@ struct Values {
SwitchableSetting<u32, true> resolution_factor{1, 0, 10, "resolution_factor"};
SwitchableSetting<u16, true> frame_limit{100, 0, 1000, "frame_limit"};
SwitchableSetting<TextureFilter> texture_filter{TextureFilter::None, "texture_filter"};
SwitchableSetting<TextureSampling> texture_sampling{TextureSampling::GameControlled,
"texture_sampling"};
SwitchableSetting<LayoutOption> layout_option{LayoutOption::Default, "layout_option"};
SwitchableSetting<bool> swap_screen{false, "swap_screen"};

View File

@@ -0,0 +1,113 @@
// Modified version of: https://www.boost.org/doc/libs/1_79_0/boost/compute/detail/lru_cache.hpp
// Most important change is the use of an array instead of a map, so that elements are
// statically allocated. The insert and get methods have been merged into the request method.
// Original license:
//
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#pragma once
#include <array>
#include <list>
#include <tuple>
#include <utility>
namespace Common {
// a cache which evicts the least recently used item when it is full
// the cache elements are statically allocated.
template <class Key, class Value, size_t Size>
class StaticLRUCache {
public:
using key_type = Key;
using value_type = Value;
using list_type = std::list<std::pair<Key, size_t>>;
using array_type = std::array<Value, Size>;
StaticLRUCache() = default;
~StaticLRUCache() = default;
size_t size() const {
return m_list.size();
}
constexpr size_t capacity() const {
return m_array.size();
}
bool empty() const {
return m_list.empty();
}
bool contains(const key_type& key) const {
return find(key) != m_list.end();
}
// Requests an element from the cache. If it is not found,
// the element is inserted using its key.
// Returns whether the element was present in the cache
// and a reference to the element itself.
std::pair<bool, value_type&> request(const key_type& key) {
// lookup value in the cache
auto i = find(key);
if (i == m_list.cend()) {
size_t next_index = size();
// insert item into the cache, but first check if it is full
if (next_index >= capacity()) {
// cache is full, evict the least recently used item
next_index = evict();
}
// insert the new item
m_list.push_front(std::make_pair(key, next_index));
return std::pair<bool, value_type&>(false, m_array[next_index]);
}
// return the value, but first update its place in the most
// recently used list
if (i != m_list.cbegin()) {
// move item to the front of the most recently used list
auto backup = *i;
m_list.erase(i);
m_list.push_front(backup);
// return the value
return std::pair<bool, value_type&>(true, m_array[backup.second]);
} else {
// the item is already at the front of the most recently
// used list so just return it
return std::pair<bool, value_type&>(true, m_array[i->second]);
}
}
void clear() {
m_list.clear();
}
private:
typename list_type::const_iterator find(const key_type& key) const {
return std::find_if(m_list.cbegin(), m_list.cend(),
[&key](const auto& el) { return el.first == key; });
}
size_t evict() {
// evict item from the end of most recently used list
typename list_type::iterator i = --m_list.end();
size_t evicted_index = i->second;
m_list.erase(i);
return evicted_index;
}
private:
array_type m_array;
list_type m_list;
};
} // namespace Common

View File

@@ -5,6 +5,7 @@
#include <algorithm>
#include <zstd.h>
#include "common/logging/log.h"
#include "common/zstd_compression.h"
namespace Common::Compression {

View File

@@ -86,6 +86,20 @@ public:
*/
virtual void Flush() const = 0;
/**
* Whether the backend supports cached reads.
*/
virtual bool AllowsCachedReads() const {
return false;
}
/**
* Whether the cache is ready for a specified offset and length.
*/
virtual bool CacheReady(std::size_t file_offset, std::size_t length) {
return false;
}
protected:
std::unique_ptr<DelayGenerator> delay_generator;

View File

@@ -131,6 +131,14 @@ public:
}
void Flush() const override {}
bool AllowsCachedReads() const override {
return romfs_file->AllowsCachedReads();
}
bool CacheReady(std::size_t file_offset, std::size_t length) override {
return romfs_file->CacheReady(file_offset, length);
}
private:
std::shared_ptr<RomFSReader> romfs_file;

View File

@@ -53,6 +53,14 @@ public:
bool DumpRomFS(const std::string& target_path);
bool AllowsCachedReads() const override {
return false;
}
bool CacheReady(std::size_t file_offset, std::size_t length) override {
return false;
}
private:
struct File;
struct Directory {

View File

@@ -1,4 +1,5 @@
#include <algorithm>
#include <vector>
#include <cryptopp/aes.h>
#include <cryptopp/modes.h>
#include "common/archives.h"
@@ -9,17 +10,102 @@ SERIALIZE_EXPORT_IMPL(FileSys::DirectRomFSReader)
namespace FileSys {
std::size_t DirectRomFSReader::ReadFile(std::size_t offset, std::size_t length, u8* buffer) {
length = std::min(length, static_cast<std::size_t>(data_size) - offset);
if (length == 0)
return 0; // Crypto++ does not like zero size buffer
file.Seek(file_offset + offset, SEEK_SET);
std::size_t read_length = std::min(length, static_cast<std::size_t>(data_size) - offset);
read_length = file.ReadBytes(buffer, read_length);
if (is_encrypted) {
CryptoPP::CTR_Mode<CryptoPP::AES>::Decryption d(key.data(), key.size(), ctr.data());
d.Seek(crypto_offset + offset);
d.ProcessData(buffer, buffer, read_length);
const auto segments = BreakupRead(offset, length);
size_t read_progress = 0;
// Skip cache if the read is too big
if (segments.size() == 1 && segments[0].second > cache_line_size) {
length = file.ReadAtBytes(buffer, length, file_offset + offset);
if (is_encrypted) {
CryptoPP::CTR_Mode<CryptoPP::AES>::Decryption d(key.data(), key.size(), ctr.data());
d.Seek(crypto_offset + offset);
d.ProcessData(buffer, buffer, length);
}
// LOG_INFO(Service_FS, "Cache SKIP: offset={}, length={}", offset, length);
return length;
}
return read_length;
// TODO(PabloMK7): Make cache thread safe, read the comment in CacheReady function.
// std::unique_lock<std::shared_mutex> read_guard(cache_mutex);
for (const auto& seg : segments) {
size_t read_size = cache_line_size;
size_t page = OffsetToPage(seg.first);
// Check if segment is in cache
auto cache_entry = cache.request(page);
if (!cache_entry.first) {
// If not found, read from disk and cache the data
read_size = file.ReadAtBytes(cache_entry.second.data(), read_size, file_offset + page);
if (is_encrypted && read_size) {
CryptoPP::CTR_Mode<CryptoPP::AES>::Decryption d(key.data(), key.size(), ctr.data());
d.Seek(crypto_offset + page);
d.ProcessData(cache_entry.second.data(), cache_entry.second.data(), read_size);
}
// LOG_INFO(Service_FS, "Cache MISS: page={}, length={}, into={}", page, seg.second,
// (seg.first - page));
} else {
// LOG_INFO(Service_FS, "Cache HIT: page={}, length={}, into={}", page, seg.second,
// (seg.first - page));
}
size_t copy_amount =
(read_size > (seg.first - page))
? std::min((seg.first - page) + seg.second, read_size) - (seg.first - page)
: 0;
std::memcpy(buffer + read_progress, cache_entry.second.data() + (seg.first - page),
copy_amount);
read_progress += copy_amount;
}
return read_progress;
}
bool DirectRomFSReader::AllowsCachedReads() const {
return true;
}
bool DirectRomFSReader::CacheReady(std::size_t file_offset, std::size_t length) {
auto segments = BreakupRead(file_offset, length);
if (segments.size() == 1 && segments[0].second > cache_line_size) {
return false;
} else {
// TODO(PabloMK7): Since the LRU cache is not thread safe, a lock must be used.
// However, this completely breaks the point of using a cache, because
// smaller reads may be blocked by bigger reads. For now, always return
// data being in cache to prevent the need of a lock, and only read data
// asynchronously if it is too big to use the cache.
/*
std::shared_lock<std::shared_mutex> read_guard(cache_mutex);
for (auto it = segments.begin(); it != segments.end(); it++) {
if (!cache.contains(OffsetToPage(it->first)))
return false;
}
*/
return true;
}
}
std::vector<std::pair<std::size_t, std::size_t>> DirectRomFSReader::BreakupRead(
std::size_t offset, std::size_t length) {
std::vector<std::pair<std::size_t, std::size_t>> ret;
// Reads bigger than the cache line size will probably never hit again
if (length > cache_line_size) {
ret.push_back(std::make_pair(offset, length));
return ret;
}
size_t curr_offset = offset;
while (length) {
size_t next_page = OffsetToPage(curr_offset + cache_line_size);
size_t curr_page_len = std::min(length, next_page - curr_offset);
ret.push_back(std::make_pair(curr_offset, curr_page_len));
curr_offset = next_page;
length -= curr_page_len;
}
return ret;
}
} // namespace FileSys

View File

@@ -1,11 +1,14 @@
#pragma once
#include <array>
#include <shared_mutex>
#include <boost/serialization/array.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#include "common/alignment.h"
#include "common/common_types.h"
#include "common/file_util.h"
#include "common/static_lru_cache.h"
namespace FileSys {
@@ -18,6 +21,8 @@ public:
virtual std::size_t GetSize() const = 0;
virtual std::size_t ReadFile(std::size_t offset, std::size_t length, u8* buffer) = 0;
virtual bool AllowsCachedReads() const = 0;
virtual bool CacheReady(std::size_t file_offset, std::size_t length) = 0;
private:
template <class Archive>
@@ -48,6 +53,10 @@ public:
std::size_t ReadFile(std::size_t offset, std::size_t length, u8* buffer) override;
bool AllowsCachedReads() const override;
bool CacheReady(std::size_t file_offset, std::size_t length) override;
private:
bool is_encrypted;
FileUtil::IOFile file;
@@ -57,8 +66,23 @@ private:
u64 crypto_offset;
u64 data_size;
// Total cache size: 128KB
static constexpr size_t cache_line_size = (1 << 13); // About 8KB
static constexpr size_t cache_line_count = 16;
Common::StaticLRUCache<std::size_t, std::array<u8, cache_line_size>, cache_line_count> cache;
// TODO(PabloMK7): Make cache thread safe, read the comment in CacheReady function.
// std::shared_mutex cache_mutex;
DirectRomFSReader() = default;
std::size_t OffsetToPage(std::size_t offset) {
return Common::AlignDown<std::size_t>(offset, cache_line_size);
}
std::vector<std::pair<std::size_t, std::size_t>> BreakupRead(std::size_t offset,
std::size_t length);
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<RomFSReader>(*this);

View File

@@ -221,6 +221,13 @@ public:
return session;
}
/**
* Returns the client thread that made the service request.
*/
std::shared_ptr<Thread> ClientThread() const {
return thread;
}
class WakeupCallback {
public:
virtual ~WakeupCallback() = default;

View File

@@ -57,7 +57,6 @@ void File::Read(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u64 offset = rp.Pop<u64>();
u32 length = rp.Pop<u32>();
auto& buffer = rp.PopMappedBuffer();
LOG_TRACE(Service_FS, "Read {}: offset=0x{:x} length=0x{:08X}", GetName(), offset, length);
const FileSessionSlot* file = GetSessionData(ctx.Session());
@@ -76,22 +75,94 @@ void File::Read(Kernel::HLERequestContext& ctx) {
offset, length, backend->GetSize());
}
IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
// Conventional reading if the backend does not support cache.
if (!backend->AllowsCachedReads()) {
auto& buffer = rp.PopMappedBuffer();
IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
std::unique_ptr<u8*> data = std::make_unique<u8*>(static_cast<u8*>(operator new(length)));
const auto read = backend->Read(offset, length, *data);
if (read.Failed()) {
rb.Push(read.Code());
rb.Push<u32>(0);
} else {
buffer.Write(*data, 0, *read);
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(static_cast<u32>(*read));
}
rb.PushMappedBuffer(buffer);
std::vector<u8> data(length);
ResultVal<std::size_t> read = backend->Read(offset, data.size(), data.data());
if (read.Failed()) {
rb.Push(read.Code());
rb.Push<u32>(0);
} else {
buffer.Write(data.data(), 0, *read);
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(static_cast<u32>(*read));
std::chrono::nanoseconds read_timeout_ns{backend->GetReadDelayNs(length)};
ctx.SleepClientThread("file::read", read_timeout_ns, nullptr);
return;
}
rb.PushMappedBuffer(buffer);
std::chrono::nanoseconds read_timeout_ns{backend->GetReadDelayNs(length)};
ctx.SleepClientThread("file::read", read_timeout_ns, nullptr);
struct AsyncData {
// Input
u32 length;
u64 offset;
std::chrono::steady_clock::time_point pre_timer;
bool cache_ready;
// Output
ResultCode ret{0};
Kernel::MappedBuffer* buffer;
std::unique_ptr<u8*> data;
size_t read_size;
};
auto async_data = std::make_shared<AsyncData>();
async_data->buffer = &rp.PopMappedBuffer();
async_data->length = length;
async_data->offset = offset;
async_data->cache_ready = backend->CacheReady(offset, length);
if (!async_data->cache_ready) {
async_data->pre_timer = std::chrono::steady_clock::now();
}
// LOG_DEBUG(Service_FS, "cache={}, offset={}, length={}", cache_ready, offset, length);
ctx.RunAsync(
[this, async_data](Kernel::HLERequestContext& ctx) {
async_data->data =
std::make_unique<u8*>(static_cast<u8*>(operator new(async_data->length)));
const auto read =
backend->Read(async_data->offset, async_data->length, *async_data->data);
if (read.Failed()) {
async_data->ret = read.Code();
async_data->read_size = 0;
} else {
async_data->ret = RESULT_SUCCESS;
async_data->read_size = *read;
}
const auto read_delay = static_cast<s64>(backend->GetReadDelayNs(async_data->length));
if (!async_data->cache_ready) {
const auto time_took = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::steady_clock::now() - async_data->pre_timer)
.count();
/*
if (time_took > read_delay) {
LOG_DEBUG(Service_FS, "Took longer! length={}, time_took={}, read_delay={}",
async_data->length, time_took, read_delay);
}
*/
return static_cast<s64>((read_delay > time_took) ? (read_delay - time_took) : 0);
} else {
return static_cast<s64>(read_delay);
}
},
[async_data](Kernel::HLERequestContext& ctx) {
IPC::RequestBuilder rb(ctx, 0x0802, 2, 2);
if (async_data->ret.IsError()) {
rb.Push(async_data->ret);
rb.Push<u32>(0);
} else {
async_data->buffer->Write(*async_data->data, 0, async_data->read_size);
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(static_cast<u32>(async_data->read_size));
}
rb.PushMappedBuffer(*async_data->buffer);
},
!async_data->cache_ready);
}
void File::Write(Kernel::HLERequestContext& ctx) {

View File

@@ -670,6 +670,26 @@ void FS_USER::GetFormatInfo(Kernel::HLERequestContext& ctx) {
rb.Push<bool>(format_info->duplicate_data != 0);
}
void FS_USER::GetProductInfo(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u32 process_id = rp.Pop<u32>();
LOG_DEBUG(Service_FS, "called, process_id={}", process_id);
IPC::RequestBuilder rb = rp.MakeBuilder(6, 0);
const auto product_info = GetProductInfo(process_id);
if (!product_info.has_value()) {
rb.Push(ResultCode(FileSys::ErrCodes::ArchiveNotMounted, ErrorModule::FS,
ErrorSummary::NotFound, ErrorLevel::Status));
return;
}
rb.Push(RESULT_SUCCESS);
rb.PushRaw<ProductInfo>(product_info.value());
}
void FS_USER::GetProgramLaunchInfo(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto process_id = rp.Pop<u32>();
@@ -687,8 +707,20 @@ void FS_USER::GetProgramLaunchInfo(Kernel::HLERequestContext& ctx) {
return;
}
ProgramInfo program_info = program_info_result.Unwrap();
// Always report the launched program mediatype is SD if the friends module is requesting this
// information and the media type is game card. Otherwise, friends will append a "romid" field
// to the NASC request with a cartridge unique identifier. Using a dump of a game card and the
// game card itself at the same time online is known to have caused issues in the past.
auto process = ctx.ClientThread()->owner_process.lock();
if (process && process->codeset->name == "friends" &&
program_info.media_type == MediaType::GameCard) {
program_info.media_type = MediaType::SDMC;
}
rb.Push(RESULT_SUCCESS);
rb.PushRaw(program_info_result.Unwrap());
rb.PushRaw<ProgramInfo>(program_info);
}
void FS_USER::ObsoletedCreateExtSaveData(Kernel::HLERequestContext& ctx) {
@@ -775,12 +807,12 @@ void FS_USER::AddSeed(Kernel::HLERequestContext& ctx) {
rb.Push(RESULT_SUCCESS);
}
void FS_USER::SetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
void FS_USER::ObsoletedSetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u64 value = rp.Pop<u64>();
u32 secure_value_slot = rp.Pop<u32>();
u32 unique_id = rp.Pop<u32>();
u8 title_variation = rp.Pop<u8>();
const u64 value = rp.Pop<u64>();
const u32 secure_value_slot = rp.Pop<u32>();
const u32 unique_id = rp.Pop<u32>();
const u8 title_variation = rp.Pop<u8>();
// TODO: Generate and Save the Secure Value
@@ -794,12 +826,11 @@ void FS_USER::SetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
rb.Push(RESULT_SUCCESS);
}
void FS_USER::GetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
void FS_USER::ObsoletedGetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u32 secure_value_slot = rp.Pop<u32>();
u32 unique_id = rp.Pop<u32>();
u8 title_variation = rp.Pop<u8>();
const u32 secure_value_slot = rp.Pop<u32>();
const u32 unique_id = rp.Pop<u32>();
const u8 title_variation = rp.Pop<u8>();
LOG_WARNING(
Service_FS,
@@ -816,7 +847,77 @@ void FS_USER::GetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
rb.Push<u64>(0); // the secure value
}
void FS_USER::Register(u32 process_id, u64 program_id, const std::string& filepath) {
void FS_USER::SetThisSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 secure_value_slot = rp.Pop<u32>();
const u64 value = rp.Pop<u64>();
// TODO: Generate and Save the Secure Value
LOG_WARNING(Service_FS, "(STUBBED) called, value=0x{:016x} secure_value_slot=0x{:08X}", value,
secure_value_slot);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
}
void FS_USER::GetThisSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 secure_value_slot = rp.Pop<u32>();
LOG_WARNING(Service_FS, "(STUBBED) called secure_value_slot=0x{:08X}", secure_value_slot);
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
rb.Push(RESULT_SUCCESS);
// TODO: Implement Secure Value Lookup & Generation
rb.Push<bool>(false); // indicates that the secure value doesn't exist
rb.Push<bool>(false); // looks like a boolean value, purpose unknown
rb.Push<u64>(0); // the secure value
}
void FS_USER::SetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const u32 secure_value_slot = rp.Pop<u32>();
const u64 value = rp.Pop<u64>();
const bool flush = rp.Pop<bool>();
// TODO: Generate and Save the Secure Value
LOG_WARNING(Service_FS,
"(STUBBED) called, value=0x{:016x} secure_value_slot=0x{:04X} "
"archive_handle=0x{:08X} flush={}",
value, secure_value_slot, archive_handle, flush);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
}
void FS_USER::GetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const u32 secure_value_slot = rp.Pop<u32>();
LOG_WARNING(Service_FS, "(STUBBED) called secure_value_slot=0x{:08X} archive_handle=0x{:08X}",
secure_value_slot, archive_handle);
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
rb.Push(RESULT_SUCCESS);
// TODO: Implement Secure Value Lookup & Generation
rb.Push<bool>(false); // indicates that the secure value doesn't exist
rb.Push<bool>(false); // looks like a boolean value, purpose unknown
rb.Push<u64>(0); // the secure value
}
void FS_USER::RegisterProgramInfo(u32 process_id, u64 program_id, const std::string& filepath) {
const MediaType media_type = GetMediaTypeFromPath(filepath);
program_info_map.insert_or_assign(process_id, ProgramInfo{program_id, media_type});
if (media_type == MediaType::GameCard) {
@@ -828,6 +929,19 @@ std::string FS_USER::GetCurrentGamecardPath() const {
return current_gamecard_path;
}
void FS_USER::RegisterProductInfo(u32 process_id, const ProductInfo& product_info) {
product_info_map.insert_or_assign(process_id, product_info);
}
std::optional<FS_USER::ProductInfo> FS_USER::GetProductInfo(u32 process_id) {
auto it = product_info_map.find(process_id);
if (it != product_info_map.end()) {
return it->second;
} else {
return {};
}
}
ResultVal<u16> FS_USER::GetSpecialContentIndexFromGameCard(u64 title_id, SpecialContentType type) {
// TODO(B3N30) check if on real 3DS NCSD is checked if partition exists
@@ -929,7 +1043,7 @@ FS_USER::FS_USER(Core::System& system)
{0x082B, nullptr, "CardNorDirectRead_4xIO"},
{0x082C, nullptr, "CardNorDirectCpuWriteWithoutVerify"},
{0x082D, nullptr, "CardNorDirectSectorEraseWithoutVerify"},
{0x082E, nullptr, "GetProductInfo"},
{0x082E, &FS_USER::GetProductInfo, "GetProductInfo"},
{0x082F, &FS_USER::GetProgramLaunchInfo, "GetProgramLaunchInfo"},
{0x0830, &FS_USER::ObsoletedCreateExtSaveData, "Obsoleted_3_0_CreateExtSaveData"},
{0x0831, nullptr, "CreateSharedExtSaveData"},
@@ -984,12 +1098,16 @@ FS_USER::FS_USER(Core::System& system)
{0x0862, &FS_USER::SetPriority, "SetPriority"},
{0x0863, &FS_USER::GetPriority, "GetPriority"},
{0x0864, nullptr, "GetNandInfo"},
{0x0865, &FS_USER::SetSaveDataSecureValue, "SetSaveDataSecureValue"},
{0x0866, &FS_USER::GetSaveDataSecureValue, "GetSaveDataSecureValue"},
{0x0865, &FS_USER::ObsoletedSetSaveDataSecureValue, "SetSaveDataSecureValue"},
{0x0866, &FS_USER::ObsoletedGetSaveDataSecureValue, "GetSaveDataSecureValue"},
{0x0867, nullptr, "ControlSecureSave"},
{0x0868, nullptr, "GetMediaType"},
{0x0869, nullptr, "GetNandEraseCount"},
{0x086A, nullptr, "ReadNandReport"},
{0x086E, &FS_USER::SetThisSaveDataSecureValue, "SetThisSaveDataSecureValue" },
{0x086F, &FS_USER::GetThisSaveDataSecureValue, "GetThisSaveDataSecureValue" },
{0x0875, &FS_USER::SetSaveDataSecureValue, "SetSaveDataSecureValue" },
{0x0876, &FS_USER::GetSaveDataSecureValue, "GetSaveDataSecureValue" },
{0x087A, &FS_USER::AddSeed, "AddSeed"},
{0x087D, &FS_USER::GetNumSeeds, "GetNumSeeds"},
{0x0886, nullptr, "CheckUpdatedDat"},

View File

@@ -4,10 +4,12 @@
#pragma once
#include <optional>
#include <unordered_map>
#include <boost/serialization/base_object.hpp>
#include "common/common_types.h"
#include "core/file_sys/errors.h"
#include "core/hle/service/fs/archive.h"
#include "core/hle/service/service.h"
namespace Core {
@@ -47,12 +49,23 @@ class FS_USER final : public ServiceFramework<FS_USER, ClientSlot> {
public:
explicit FS_USER(Core::System& system);
// On real HW this is part of FS:Reg. But since that module is only used by loader and pm, which
// we HLEed, we can just directly use it here
void Register(u32 process_id, u64 program_id, const std::string& filepath);
// On real HW this is part of FSReg (FSReg:Register). But since that module is only used by
// loader and pm, which we HLEed, we can just directly use it here
void RegisterProgramInfo(u32 process_id, u64 program_id, const std::string& filepath);
std::string GetCurrentGamecardPath() const;
struct ProductInfo {
std::array<u8, 0x10> product_code;
u16_le maker_code;
u16_le remaster_version;
};
static_assert(sizeof(ProductInfo) == 0x14);
void RegisterProductInfo(u32 process_id, const ProductInfo& product_info);
std::optional<ProductInfo> GetProductInfo(u32 process_id);
/// Gets the registered program info of a process.
ResultVal<ProgramInfo> GetProgramLaunchInfo(u32 process_id) const {
auto info = program_info_map.find(process_id);
@@ -509,6 +522,17 @@ private:
*/
void GetFormatInfo(Kernel::HLERequestContext& ctx);
/**
* FS_User::GetProductInfo service function.
* Inputs:
* 0 : 0x082E0040
* 1 : Process ID
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2-6 : Product info
*/
void GetProductInfo(Kernel::HLERequestContext& ctx);
/**
* FS_User::GetProgramLaunchInfo service function.
* Inputs:
@@ -600,7 +624,7 @@ private:
* 0 : 0x08650140
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetSaveDataSecureValue(Kernel::HLERequestContext& ctx);
void ObsoletedSetSaveDataSecureValue(Kernel::HLERequestContext& ctx);
/**
* FS_User::GetSaveDataSecureValue service function.
@@ -615,6 +639,57 @@ private:
* 2 : If Secure Value doesn't exist, 0, if it exists, 1
* 3-4 : Secure Value
*/
void ObsoletedGetSaveDataSecureValue(Kernel::HLERequestContext& ctx);
/**
* FS_User::SetThisSaveDataSecureValue service function.
* Inputs:
* 1 : Secure Value Slot
* 2-3 : Secure Value
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetThisSaveDataSecureValue(Kernel::HLERequestContext& ctx);
/**
* FS_User::GetSaveDataSecureValue service function.
* Inputs:
* 1 : Secure Value Slot
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
* 2 : If Secure Value doesn't exist, 0, if it exists, 1
* 3 : Unknown
* 4-5 : Secure Value
*/
void GetThisSaveDataSecureValue(Kernel::HLERequestContext& ctx);
/**
* FS_User::SetSaveDataSecureValue service function.
* Inputs:
* 0 : 0x08750180
* 1-2 : Archive
* 3 : Secure Value Slot
* 4 : value
* 5 : flush
* Outputs:
* 0 : header
* 1 : Result of function, 0 on success, otherwise error code
*/
void SetSaveDataSecureValue(Kernel::HLERequestContext& ctx);
/**
* FS_User::GetSaveDataSecureValue service function.
* Inputs:
* 0 : 0x087600C0
* 1-2 : Archive
* 2 : Secure Value slot
* Outputs:
* 0 : Header
* 1 : Result of function, 0 on success, otherwise error code
* 2 : If Secure Value doesn't exist, 0, if it exists, 1
* 3 : unknown
* 4-5 : Secure Value
*/
void GetSaveDataSecureValue(Kernel::HLERequestContext& ctx);
static ResultVal<u16> GetSpecialContentIndexFromGameCard(u64 title_id, SpecialContentType type);
@@ -624,6 +699,8 @@ private:
std::unordered_map<u32, ProgramInfo> program_info_map;
std::string current_gamecard_path;
std::unordered_map<u32, ProductInfo> product_info_map;
u32 priority = -1; ///< For SetPriority and GetPriority service functions
Core::System& system;

View File

@@ -282,7 +282,7 @@ ResultStatus AppLoader_THREEDSX::Load(std::shared_ptr<Kernel::Process>& process)
// On real HW this is done with FS:Reg, but we can be lazy
auto fs_user =
Core::System::GetInstance().ServiceManager().GetService<Service::FS::FS_USER>("fs:USER");
fs_user->Register(process->GetObjectId(), process->codeset->program_id, filepath);
fs_user->RegisterProgramInfo(process->GetObjectId(), process->codeset->program_id, filepath);
process->Run(48, Kernel::DEFAULT_STACK_SIZE);

View File

@@ -174,7 +174,16 @@ ResultStatus AppLoader_NCCH::LoadExec(std::shared_ptr<Kernel::Process>& process)
auto fs_user =
Core::System::GetInstance().ServiceManager().GetService<Service::FS::FS_USER>(
"fs:USER");
fs_user->Register(process->process_id, process->codeset->program_id, filepath);
fs_user->RegisterProgramInfo(process->process_id, process->codeset->program_id, filepath);
Service::FS::FS_USER::ProductInfo product_info{};
std::memcpy(product_info.product_code.data(), overlay_ncch->ncch_header.product_code,
product_info.product_code.size());
std::memcpy(&product_info.remaster_version,
overlay_ncch->exheader_header.codeset_info.flags.remaster_version,
sizeof(product_info.remaster_version));
product_info.maker_code = overlay_ncch->ncch_header.maker_code;
fs_user->RegisterProductInfo(process->process_id, product_info);
process->Run(priority, stack_size);
return ResultStatus::Success;

View File

@@ -11,6 +11,7 @@
#include <span>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <fmt/format.h>
#include <nihstro/inline_assembly.h>
#include "video_core/shader/shader_interpreter.h"
#include "video_core/shader/shader_jit_x64_compiler.h"
@@ -28,6 +29,15 @@ static constexpr Common::Vec4f vec4_nan = Common::Vec4f::AssignToAll(NAN);
static constexpr Common::Vec4f vec4_one = Common::Vec4f::AssignToAll(1.0f);
static constexpr Common::Vec4f vec4_zero = Common::Vec4f::AssignToAll(0.0f);
namespace Catch {
template <>
struct StringMaker<Common::Vec4f> {
static std::string convert(Common::Vec4f value) {
return fmt::format("({}, {}, {}, {})", value.r(), value.g(), value.b(), value.a());
}
};
} // namespace Catch
static std::unique_ptr<Pica::Shader::ShaderSetup> CompileShaderSetup(
std::initializer_list<nihstro::InlineAsm> code) {
const auto shbin = nihstro::InlineAsm::CompileToRawBinary(code);
@@ -385,6 +395,56 @@ TEST_CASE("RSQ", "[video_core][shader][shader_jit]") {
REQUIRE(shader.Run({0.0625f}).x == Catch::Approx(4.0f).margin(0.004f));
}
TEST_CASE("Address Register Offset", "[video_core][shader][shader_jit]") {
const auto sh_input = SourceRegister::MakeInput(0);
const auto sh_c40 = SourceRegister::MakeFloat(40);
const auto sh_output = DestRegister::MakeOutput(0);
auto shader = ShaderTest({
// mova a0.x, sh_input.x
{OpCode::Id::MOVA, DestRegister{}, "x", sh_input, "x", SourceRegister{}, "",
nihstro::InlineAsm::RelativeAddress::A1},
// mov sh_output.xyzw, c40[a0.x].xyzw
{OpCode::Id::MOV, sh_output, "xyzw", sh_c40, "xyzw", SourceRegister{}, "",
nihstro::InlineAsm::RelativeAddress::A1},
{OpCode::Id::END},
});
// Prepare shader uniforms
const bool inverted = true;
std::array<Common::Vec4f, 96> f_uniforms;
for (u32 i = 0; i < 0x80; i++) {
if (i >= 0x00 && i < 0x60) {
const u32 base = inverted ? (0x60 - i) : i;
const auto color = (base * 2.f) / 255.0f;
const auto color_f24 = Pica::f24::FromFloat32(color);
shader.shader_setup->uniforms.f[i] = {color_f24, color_f24, color_f24,
Pica::f24::One()};
f_uniforms[i] = {color, color, color, 1.f};
} else if (i >= 0x60 && i < 0x64) {
const u8 color = static_cast<u8>((i - 0x60) * 0x10);
shader.shader_setup->uniforms.i[i - 0x60] = {color, color, color, 255};
} else if (i >= 0x70 && i < 0x80) {
shader.shader_setup->uniforms.b[i - 0x70] = i >= 0x78;
}
}
REQUIRE(shader.Run(0.f) == f_uniforms[40]);
REQUIRE(shader.Run(13.f) == f_uniforms[53]);
REQUIRE(shader.Run(50.f) == f_uniforms[90]);
REQUIRE(shader.Run(60.f) == vec4_one);
REQUIRE(shader.Run(74.f) == vec4_one);
REQUIRE(shader.Run(87.f) == vec4_one);
REQUIRE(shader.Run(88.f) == f_uniforms[0]);
REQUIRE(shader.Run(128.f) == f_uniforms[40]);
REQUIRE(shader.Run(-40.f) == f_uniforms[0]);
REQUIRE(shader.Run(-42.f) == vec4_one);
REQUIRE(shader.Run(-70.f) == vec4_one);
REQUIRE(shader.Run(-73.f) == f_uniforms[95]);
REQUIRE(shader.Run(-127.f) == f_uniforms[41]);
REQUIRE(shader.Run(-129.f) == f_uniforms[40]);
}
// TODO: Requires fix from https://github.com/neobrain/nihstro/issues/68
// TEST_CASE("MAD", "[video_core][shader][shader_jit]") {
// const auto sh_input1 = SourceRegister::MakeInput(0);

View File

@@ -78,12 +78,11 @@ static void WriteUniformFloatReg(ShaderRegs& config, Shader::ShaderSetup& setup,
(float_regs_counter >= 3 && !uniform_setup.IsFloat32())) {
float_regs_counter = 0;
auto& uniform = setup.uniforms.f[uniform_setup.index];
if (uniform_setup.index >= 96) {
if (uniform_setup.index >= setup.uniforms.f.size()) {
LOG_ERROR(HW_GPU, "Invalid {} float uniform index {}", GetShaderSetupTypeName(setup),
(int)uniform_setup.index);
} else {
auto& uniform = setup.uniforms.f[uniform_setup.index];
// NOTE: The destination component order indeed is "backwards"
if (uniform_setup.IsFloat32()) {

View File

@@ -7,7 +7,6 @@ set(SHADER_FILES
format_reinterpreter/rgba4_to_rgb5a1.frag
format_reinterpreter/vulkan_d24s8_to_rgba8.comp
texture_filtering/bicubic.frag
texture_filtering/nearest_neighbor.frag
texture_filtering/refine.frag
texture_filtering/scale_force.frag
texture_filtering/xbrz_freescale.frag

View File

@@ -1,15 +0,0 @@
// Copyright 2023 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
//? #version 430 core
precision mediump float;
layout(location = 0) in vec2 tex_coord;
layout(location = 0) out vec4 frag_color;
layout(binding = 2) uniform sampler2D input_texture;
void main() {
frag_color = texture(input_texture, tex_coord);
}

View File

@@ -361,10 +361,25 @@ typename T::Sampler& RasterizerCache<T>::GetSampler(SamplerId sampler_id) {
template <class T>
typename T::Sampler& RasterizerCache<T>::GetSampler(
const Pica::TexturingRegs::TextureConfig& config) {
using TextureFilter = Pica::TexturingRegs::TextureConfig::TextureFilter;
const auto get_filter = [](TextureFilter filter) {
switch (Settings::values.texture_sampling.GetValue()) {
case Settings::TextureSampling::GameControlled:
return filter;
case Settings::TextureSampling::NearestNeighbor:
return TextureFilter::Nearest;
case Settings::TextureSampling::Linear:
return TextureFilter::Linear;
default:
return filter;
}
};
const SamplerParams params = {
.mag_filter = config.mag_filter,
.min_filter = config.min_filter,
.mip_filter = config.mip_filter,
.mag_filter = get_filter(config.mag_filter),
.min_filter = get_filter(config.min_filter),
.mip_filter = get_filter(config.mip_filter),
.wrap_s = config.wrap_s,
.wrap_t = config.wrap_t,
.border_color = config.border_color.raw,

View File

@@ -59,7 +59,7 @@ bool RendererBase::IsScreenshotPending() const {
return settings.screenshot_requested;
}
void RendererBase::RequestScreenshot(void* data, std::function<void()> callback,
void RendererBase::RequestScreenshot(void* data, std::function<void(bool)> callback,
const Layout::FramebufferLayout& layout) {
if (settings.screenshot_requested) {
LOG_ERROR(Render, "A screenshot is already requested or in progress, ignoring the request");

View File

@@ -28,7 +28,7 @@ struct RendererSettings {
// Screenshot
std::atomic_bool screenshot_requested{false};
void* screenshot_bits{};
std::function<void()> screenshot_complete_callback;
std::function<void(bool)> screenshot_complete_callback;
Layout::FramebufferLayout screenshot_framebuffer_layout;
// Renderer
std::atomic_bool bg_color_update_requested{false};
@@ -103,7 +103,7 @@ public:
[[nodiscard]] bool IsScreenshotPending() const;
/// Request a screenshot of the next frame
void RequestScreenshot(void* data, std::function<void()> callback,
void RequestScreenshot(void* data, std::function<void(bool)> callback,
const Layout::FramebufferLayout& layout);
protected:

View File

@@ -15,7 +15,6 @@
#include "video_core/host_shaders/full_screen_triangle_vert.h"
#include "video_core/host_shaders/texture_filtering/bicubic_frag.h"
#include "video_core/host_shaders/texture_filtering/mmpx_frag.h"
#include "video_core/host_shaders/texture_filtering/nearest_neighbor_frag.h"
#include "video_core/host_shaders/texture_filtering/refine_frag.h"
#include "video_core/host_shaders/texture_filtering/scale_force_frag.h"
#include "video_core/host_shaders/texture_filtering/x_gradient_frag.h"
@@ -58,7 +57,6 @@ BlitHelper::BlitHelper(const Driver& driver_)
: driver{driver_}, linear_sampler{CreateSampler(GL_LINEAR)},
nearest_sampler{CreateSampler(GL_NEAREST)}, bicubic_program{CreateProgram(
HostShaders::BICUBIC_FRAG)},
nearest_program{CreateProgram(HostShaders::NEAREST_NEIGHBOR_FRAG)},
scale_force_program{CreateProgram(HostShaders::SCALE_FORCE_FRAG)},
xbrz_program{CreateProgram(HostShaders::XBRZ_FREESCALE_FRAG)},
mmpx_program{CreateProgram(HostShaders::MMPX_FRAG)}, gradient_x_program{CreateProgram(
@@ -175,9 +173,6 @@ bool BlitHelper::Filter(Surface& surface, const VideoCore::TextureBlit& blit) {
case TextureFilter::Bicubic:
FilterBicubic(surface, blit);
break;
case TextureFilter::NearestNeighbor:
FilterNearest(surface, blit);
break;
case TextureFilter::ScaleForce:
FilterScaleForce(surface, blit);
break;
@@ -257,14 +252,6 @@ void BlitHelper::FilterBicubic(Surface& surface, const VideoCore::TextureBlit& b
Draw(bicubic_program, surface.Handle(), draw_fbo.handle, blit.dst_level, blit.dst_rect);
}
void BlitHelper::FilterNearest(Surface& surface, const VideoCore::TextureBlit& blit) {
const OpenGLState prev_state = OpenGLState::GetCurState();
SCOPE_EXIT({ prev_state.Apply(); });
state.texture_units[2].texture_2d = surface.Handle(0);
SetParams(nearest_program, surface.RealExtent(false), blit.src_rect);
Draw(nearest_program, surface.Handle(), draw_fbo.handle, blit.dst_level, blit.dst_rect);
}
void BlitHelper::FilterScaleForce(Surface& surface, const VideoCore::TextureBlit& blit) {
const OpenGLState prev_state = OpenGLState::GetCurState();
SCOPE_EXIT({ prev_state.Apply(); });

View File

@@ -33,20 +33,13 @@ public:
private:
void FilterAnime4K(Surface& surface, const VideoCore::TextureBlit& blit);
void FilterBicubic(Surface& surface, const VideoCore::TextureBlit& blit);
void FilterNearest(Surface& surface, const VideoCore::TextureBlit& blit);
void FilterScaleForce(Surface& surface, const VideoCore::TextureBlit& blit);
void FilterXbrz(Surface& surface, const VideoCore::TextureBlit& blit);
void FilterMMPX(Surface& surface, const VideoCore::TextureBlit& blit);
void SetParams(OGLProgram& program, const VideoCore::Extent& src_extent,
Common::Rectangle<u32> src_rect);
void Draw(OGLProgram& program, GLuint dst_tex, GLuint dst_fbo, u32 dst_level,
Common::Rectangle<u32> dst_rect);
@@ -59,7 +52,6 @@ private:
OGLSampler nearest_sampler;
OGLProgram bicubic_program;
OGLProgram nearest_program;
OGLProgram scale_force_program;
OGLProgram xbrz_program;
OGLProgram mmpx_program;

View File

@@ -151,7 +151,7 @@ void RendererOpenGL::RenderScreenshot() {
state.Apply();
glDeleteRenderbuffers(1, &renderbuffer);
settings.screenshot_complete_callback();
settings.screenshot_complete_callback(true);
}
}

View File

@@ -6,6 +6,7 @@
#include "common/logging/log.h"
#include "common/microprofile.h"
#include "common/settings.h"
#include "common/texture.h"
#include "core/core.h"
#include "core/frontend/emu_window.h"
#include "core/hw/gpu.h"
@@ -18,6 +19,7 @@
#include "video_core/host_shaders/vulkan_present_frag_spv.h"
#include "video_core/host_shaders/vulkan_present_interlaced_frag_spv.h"
#include "video_core/host_shaders/vulkan_present_vert_spv.h"
#include "vulkan/vulkan_format_traits.hpp"
#include <vk_mem_alloc.h>
@@ -867,20 +869,9 @@ void RendererVulkan::RenderScreenshot() {
const u32 width = layout.width;
const u32 height = layout.height;
const vk::ImageCreateInfo staging_image_info = {
.imageType = vk::ImageType::e2D,
.format = vk::Format::eB8G8R8A8Unorm,
.extent{
.width = width,
.height = height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 1,
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eLinear,
.usage = vk::ImageUsageFlagBits::eTransferDst,
.initialLayout = vk::ImageLayout::eUndefined,
const vk::BufferCreateInfo staging_buffer_info = {
.size = width * height * 4,
.usage = vk::BufferUsageFlagBits::eTransferDst,
};
const VmaAllocationCreateInfo alloc_create_info = {
@@ -893,18 +884,18 @@ void RendererVulkan::RenderScreenshot() {
.pUserData = nullptr,
};
VkImage unsafe_image{};
VkBuffer unsafe_buffer{};
VmaAllocation allocation{};
VmaAllocationInfo alloc_info;
VkImageCreateInfo unsafe_image_info = static_cast<VkImageCreateInfo>(staging_image_info);
VkBufferCreateInfo unsafe_buffer_info = static_cast<VkBufferCreateInfo>(staging_buffer_info);
VkResult result = vmaCreateImage(instance.GetAllocator(), &unsafe_image_info,
&alloc_create_info, &unsafe_image, &allocation, &alloc_info);
VkResult result = vmaCreateBuffer(instance.GetAllocator(), &unsafe_buffer_info,
&alloc_create_info, &unsafe_buffer, &allocation, &alloc_info);
if (result != VK_SUCCESS) [[unlikely]] {
LOG_CRITICAL(Render_Vulkan, "Failed allocating texture with error {}", result);
UNREACHABLE();
}
vk::Image staging_image{unsafe_image};
vk::Buffer staging_buffer{unsafe_buffer};
Frame frame{};
main_window.RecreateFrame(&frame, width, height);
@@ -912,73 +903,37 @@ void RendererVulkan::RenderScreenshot() {
DrawScreens(&frame, layout, false);
scheduler.Record(
[width, height, source_image = frame.image, staging_image](vk::CommandBuffer cmdbuf) {
const std::array read_barriers = {
vk::ImageMemoryBarrier{
.srcAccessMask = vk::AccessFlagBits::eMemoryWrite,
.dstAccessMask = vk::AccessFlagBits::eTransferRead,
.oldLayout = vk::ImageLayout::eTransferSrcOptimal,
.newLayout = vk::ImageLayout::eTransferSrcOptimal,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = source_image,
.subresourceRange{
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = VK_REMAINING_MIP_LEVELS,
.baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS,
},
},
vk::ImageMemoryBarrier{
.srcAccessMask = vk::AccessFlagBits::eNone,
.dstAccessMask = vk::AccessFlagBits::eTransferWrite,
.oldLayout = vk::ImageLayout::eUndefined,
.newLayout = vk::ImageLayout::eTransferDstOptimal,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = staging_image,
.subresourceRange{
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = VK_REMAINING_MIP_LEVELS,
.baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS,
},
[width, height, source_image = frame.image, staging_buffer](vk::CommandBuffer cmdbuf) {
const vk::ImageMemoryBarrier read_barrier = {
.srcAccessMask = vk::AccessFlagBits::eMemoryWrite,
.dstAccessMask = vk::AccessFlagBits::eTransferRead,
.oldLayout = vk::ImageLayout::eTransferSrcOptimal,
.newLayout = vk::ImageLayout::eTransferSrcOptimal,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = source_image,
.subresourceRange{
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = VK_REMAINING_MIP_LEVELS,
.baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS,
},
};
const std::array write_barriers = {
vk::ImageMemoryBarrier{
.srcAccessMask = vk::AccessFlagBits::eTransferRead,
.dstAccessMask = vk::AccessFlagBits::eMemoryWrite,
.oldLayout = vk::ImageLayout::eTransferSrcOptimal,
.newLayout = vk::ImageLayout::eTransferSrcOptimal,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = source_image,
.subresourceRange{
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = VK_REMAINING_MIP_LEVELS,
.baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS,
},
},
vk::ImageMemoryBarrier{
.srcAccessMask = vk::AccessFlagBits::eTransferWrite,
.dstAccessMask = vk::AccessFlagBits::eMemoryRead,
.oldLayout = vk::ImageLayout::eTransferDstOptimal,
.newLayout = vk::ImageLayout::eGeneral,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = staging_image,
.subresourceRange{
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = VK_REMAINING_MIP_LEVELS,
.baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS,
},
const vk::ImageMemoryBarrier write_barrier = {
.srcAccessMask = vk::AccessFlagBits::eTransferRead,
.dstAccessMask = vk::AccessFlagBits::eMemoryWrite,
.oldLayout = vk::ImageLayout::eTransferSrcOptimal,
.newLayout = vk::ImageLayout::eTransferSrcOptimal,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = source_image,
.subresourceRange{
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = VK_REMAINING_MIP_LEVELS,
.baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS,
},
};
static constexpr vk::MemoryBarrier memory_write_barrier = {
@@ -986,41 +941,29 @@ void RendererVulkan::RenderScreenshot() {
.dstAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite,
};
const std::array src_offsets = {
vk::Offset3D{0, 0, 0},
vk::Offset3D{static_cast<s32>(width), static_cast<s32>(height), 1},
};
const std::array dst_offsets = {
vk::Offset3D{0, static_cast<s32>(height), 0},
vk::Offset3D{static_cast<s32>(width), 0, 1},
};
const vk::ImageBlit blit_area = {
.srcSubresource{
.aspectMask = vk::ImageAspectFlagBits::eColor,
.mipLevel = 0,
.baseArrayLayer = 0,
.layerCount = 1,
},
.srcOffsets = src_offsets,
.dstSubresource{
.aspectMask = vk::ImageAspectFlagBits::eColor,
.mipLevel = 0,
.baseArrayLayer = 0,
.layerCount = 1,
},
.dstOffsets = dst_offsets,
const vk::BufferImageCopy image_copy = {
.bufferOffset = 0,
.bufferRowLength = 0,
.bufferImageHeight = 0,
.imageSubresource =
{
.aspectMask = vk::ImageAspectFlagBits::eColor,
.mipLevel = 0,
.baseArrayLayer = 0,
.layerCount = 1,
},
.imageOffset = {0, 0, 0},
.imageExtent = {width, height, 1},
};
cmdbuf.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands,
vk::PipelineStageFlagBits::eTransfer,
vk::DependencyFlagBits::eByRegion, {}, {}, read_barriers);
cmdbuf.blitImage(source_image, vk::ImageLayout::eTransferSrcOptimal, staging_image,
vk::ImageLayout::eTransferDstOptimal, blit_area, vk::Filter::eNearest);
vk::DependencyFlagBits::eByRegion, {}, {}, read_barrier);
cmdbuf.copyImageToBuffer(source_image, vk::ImageLayout::eTransferSrcOptimal,
staging_buffer, image_copy);
cmdbuf.pipelineBarrier(
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eAllCommands,
vk::DependencyFlagBits::eByRegion, memory_write_barrier, {}, write_barriers);
vk::DependencyFlagBits::eByRegion, memory_write_barrier, {}, write_barrier);
});
// Ensure the copy is fully completed before saving the screenshot
@@ -1028,27 +971,16 @@ void RendererVulkan::RenderScreenshot() {
const vk::Device device = instance.GetDevice();
// Get layout of the image (including row pitch)
const vk::ImageSubresource subresource = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.mipLevel = 0,
.arrayLayer = 0,
};
const vk::SubresourceLayout subresource_layout =
device.getImageSubresourceLayout(staging_image, subresource);
// Copy backing image data to the QImage screenshot buffer
const u8* data = reinterpret_cast<const u8*>(alloc_info.pMappedData);
std::memcpy(settings.screenshot_bits, data + subresource_layout.offset,
subresource_layout.size);
std::memcpy(settings.screenshot_bits, alloc_info.pMappedData, staging_buffer_info.size);
// Destroy allocated resources
vmaDestroyBuffer(instance.GetAllocator(), unsafe_buffer, allocation);
vmaDestroyImage(instance.GetAllocator(), frame.image, frame.allocation);
device.destroyFramebuffer(frame.framebuffer);
device.destroyImageView(frame.image_view);
settings.screenshot_complete_callback();
settings.screenshot_complete_callback(false);
}
} // namespace Vulkan

View File

@@ -35,10 +35,7 @@ public:
const VideoCore::BufferTextureCopy& copy);
private:
/// Creates compute pipelines used for blit
vk::Pipeline MakeComputePipeline(vk::ShaderModule shader, vk::PipelineLayout layout);
/// Creates graphics pipelines used for blit
vk::Pipeline MakeDepthStencilBlitPipeline();
private:

View File

@@ -150,8 +150,7 @@ void Swapchain::FindPresentFormat() {
return;
}
LOG_CRITICAL(Render_Vulkan, "Unable to find required swapchain format!");
UNREACHABLE();
UNREACHABLE_MSG("Unable to find required swapchain format!");
}
void Swapchain::SetPresentMode() {

View File

@@ -1562,7 +1562,7 @@ DebugScope::DebugScope(TextureRuntime& runtime, Common::Vec4f color, std::string
if (!has_debug_tool) {
return;
}
scheduler.Record([color, label](vk::CommandBuffer cmdbuf) {
scheduler.Record([color, label = std::string(label)](vk::CommandBuffer cmdbuf) {
const vk::DebugUtilsLabelEXT debug_label = {
.pLabelName = label.data(),
.color = std::array{color[0], color[1], color[2], color[3]},

View File

@@ -232,21 +232,45 @@ void JitShader::Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRe
address_register_index = instr.common.address_register_index;
}
if (src_num == offset_src && address_register_index != 0) {
if (src_reg.GetRegisterType() == RegisterType::FloatUniform && src_num == offset_src &&
address_register_index != 0) {
Xbyak::Reg64 address_reg;
switch (address_register_index) {
case 1: // address offset 1
movaps(dest, xword[src_ptr + ADDROFFS_REG_0 + src_offset_disp]);
case 1:
address_reg = ADDROFFS_REG_0;
break;
case 2: // address offset 2
movaps(dest, xword[src_ptr + ADDROFFS_REG_1 + src_offset_disp]);
case 2:
address_reg = ADDROFFS_REG_1;
break;
case 3: // address offset 3
movaps(dest, xword[src_ptr + LOOPCOUNT_REG.cvt64() + src_offset_disp]);
case 3:
address_reg = LOOPCOUNT_REG.cvt64();
break;
default:
UNREACHABLE();
break;
}
// s32 offset = address_reg >= -128 && address_reg <= 127 ? address_reg : 0;
// u32 index = (src_reg.GetIndex() + offset) & 0x7f;
// First we add 128 to address_reg so the first comparison is turned to
// address_reg >= 0 && address_reg < 256 which can be performed with
// a single unsigned comparison (cmovb)
lea(eax, ptr[address_reg + 128]);
mov(ebx, src_reg.GetIndex());
mov(ecx, address_reg.cvt32());
add(ecx, ebx);
cmp(eax, 256);
cmovb(ebx, ecx);
and_(ebx, 0x7f);
// index > 95 ? vec4(1.0) : uniforms.f[index];
movaps(dest, ONE);
cmp(ebx, 95);
Label load_end;
jg(load_end);
shl(rbx, 4);
movaps(dest, xword[src_ptr + rbx]);
L(load_end);
} else {
// Load the source
movaps(dest, xword[src_ptr + src_offset_disp]);
@@ -590,24 +614,14 @@ void JitShader::Compile_MOVA(Instruction instr) {
// Move and sign-extend high 32 bits
shr(rax, 32);
movsxd(ADDROFFS_REG_1, eax);
// Multiply by 16 to be used as an offset later
shl(ADDROFFS_REG_0, 4);
shl(ADDROFFS_REG_1, 4);
} else {
if (swiz.DestComponentEnabled(0)) {
// Move and sign-extend low 32 bits
movsxd(ADDROFFS_REG_0, eax);
// Multiply by 16 to be used as an offset later
shl(ADDROFFS_REG_0, 4);
} else if (swiz.DestComponentEnabled(1)) {
// Move and sign-extend high 32 bits
shr(rax, 32);
movsxd(ADDROFFS_REG_1, eax);
// Multiply by 16 to be used as an offset later
shl(ADDROFFS_REG_1, 4);
}
}
}
@@ -659,9 +673,6 @@ void JitShader::Compile_END(Instruction instr) {
mov(byte[STATE + offsetof(UnitState, conditional_code[1])], COND1.cvt8());
// Save address/loop registers
sar(ADDROFFS_REG_0, 4);
sar(ADDROFFS_REG_1, 4);
sar(LOOPCOUNT_REG, 4);
mov(dword[STATE + offsetof(UnitState, address_registers[0])], ADDROFFS_REG_0.cvt32());
mov(dword[STATE + offsetof(UnitState, address_registers[1])], ADDROFFS_REG_1.cvt32());
mov(dword[STATE + offsetof(UnitState, address_registers[2])], LOOPCOUNT_REG);
@@ -813,11 +824,11 @@ void JitShader::Compile_LOOP(Instruction instr) {
std::size_t offset = Uniforms::GetIntUniformOffset(instr.flow_control.int_uniform_id);
mov(LOOPCOUNT, dword[UNIFORMS + offset]);
mov(LOOPCOUNT_REG, LOOPCOUNT);
shr(LOOPCOUNT_REG, 4);
and_(LOOPCOUNT_REG, 0xFF0); // Y-component is the start
shr(LOOPCOUNT_REG, 8);
and_(LOOPCOUNT_REG, 0xFF); // Y-component is the start
mov(LOOPINC, LOOPCOUNT);
shr(LOOPINC, 12);
and_(LOOPINC, 0xFF0); // Z-component is the incrementer
shr(LOOPINC, 16);
and_(LOOPINC, 0xFF); // Z-component is the incrementer
movzx(LOOPCOUNT, LOOPCOUNT.cvt8()); // X-component is iteration count
add(LOOPCOUNT, 1); // Iteration count is X-component + 1
@@ -993,9 +1004,6 @@ void JitShader::Compile(const std::array<u32, MAX_PROGRAM_CODE_LENGTH>* program_
movsxd(ADDROFFS_REG_0, dword[STATE + offsetof(UnitState, address_registers[0])]);
movsxd(ADDROFFS_REG_1, dword[STATE + offsetof(UnitState, address_registers[1])]);
mov(LOOPCOUNT_REG, dword[STATE + offsetof(UnitState, address_registers[2])]);
shl(ADDROFFS_REG_0, 4);
shl(ADDROFFS_REG_1, 4);
shl(LOOPCOUNT_REG, 4);
// Load conditional code
mov(COND0, byte[STATE + offsetof(UnitState, conditional_code[0])]);