Compare commits

...

21 Commits

Author SHA1 Message Date
GPUCode
f3bbcb31c9 renderer_opengl: Remove non-separable path 2023-11-04 12:59:20 +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
53 changed files with 1295 additions and 634 deletions

View File

@@ -1,5 +1,10 @@
#!/bin/bash -ex #!/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 mkdir build && cd build
cmake .. -GNinja \ cmake .. -GNinja \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \

View File

@@ -5,6 +5,9 @@ cmake .. -G Ninja \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_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 \ -DENABLE_QT_TRANSLATION=ON \
-DCITRA_ENABLE_COMPATIBILITY_REPORTING=ON \ -DCITRA_ENABLE_COMPATIBILITY_REPORTING=ON \
-DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON \ -DENABLE_COMPATIBILITY_LIST_DOWNLOAD=ON \

View File

@@ -1,5 +1,10 @@
#!/bin/bash -ex #!/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 mkdir build && cd build
cmake .. -GNinja \ cmake .. -GNinja \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \

View File

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

View File

@@ -17,6 +17,12 @@ include(CMakeDependentOption)
project(citra LANGUAGES C CXX ASM) 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) if (APPLE)
# Silence warnings on empty objects, for example when platform-specific code is #ifdef'd out. # 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>") 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_USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
option(CITRA_WARNINGS_AS_ERRORS "Enable warnings as errors" ON) option(CITRA_WARNINGS_AS_ERRORS "Enable warnings as errors" ON)
# System library options include(CitraHandleSystemLibs)
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)
if (CITRA_USE_PRECOMPILED_HEADERS) if (CITRA_USE_PRECOMPILED_HEADERS)
message(STATUS "Using Precompiled Headers.") message(STATUS "Using Precompiled Headers.")
@@ -247,7 +236,7 @@ find_package(Threads REQUIRED)
if (ENABLE_QT) if (ENABLE_QT)
if (NOT USE_SYSTEM_QT) if (NOT USE_SYSTEM_QT)
download_qt(6.5.1) download_qt(6.6.0)
endif() endif()
find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia Concurrent) find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia Concurrent)

View File

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

View File

@@ -2,7 +2,13 @@
Name=colorful_midnight_blue Name=colorful_midnight_blue
Comment=Colorful theme (Midnight Blue style) Comment=Colorful theme (Midnight Blue style)
Inherits=default Inherits=default
Directories=16x16 Directories=16x16,48x48,256x256
[16x16] [16x16]
Size=16 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) target_link_libraries(boost_iostreams PUBLIC boost)
# Add additional boost libs here; remember to ALIAS them in the root CMakeLists! # 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() endif()
# Catch2 # Catch2
@@ -42,11 +46,17 @@ set(CATCH_INSTALL_EXTRAS OFF CACHE BOOL "")
add_subdirectory(catch2) add_subdirectory(catch2)
# Crypto++ # Crypto++
set(CRYPTOPP_BUILD_DOCUMENTATION OFF CACHE BOOL "") if(USE_SYSTEM_CRYPTOPP)
set(CRYPTOPP_BUILD_TESTING OFF CACHE BOOL "") find_package(cryptopp REQUIRED)
set(CRYPTOPP_INSTALL OFF CACHE BOOL "") add_library(cryptopp INTERFACE)
set(CRYPTOPP_SOURCES "${CMAKE_SOURCE_DIR}/externals/cryptopp" CACHE STRING "") target_link_libraries(cryptopp INTERFACE cryptopp::cryptopp)
add_subdirectory(cryptopp-cmake) 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 # dds-ktx
add_library(dds-ktx INTERFACE) add_library(dds-ktx INTERFACE)
@@ -207,22 +217,47 @@ if (ENABLE_LIBUSB AND NOT USE_SYSTEM_LIBUSB)
endif() endif()
# Zstandard # Zstandard
set(ZSTD_LEGACY_SUPPORT OFF) if(USE_SYSTEM_ZSTD)
set(ZSTD_BUILD_PROGRAMS OFF) find_package(zstd REQUIRED)
set(ZSTD_BUILD_SHARED OFF) add_library(zstd INTERFACE)
add_subdirectory(zstd/build/cmake EXCLUDE_FROM_ALL) if(TARGET zstd::libzstd_shared)
target_include_directories(libzstd_static INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/externals/zstd/lib>) 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 # ENet
add_subdirectory(enet) if(USE_SYSTEM_ENET)
target_include_directories(enet INTERFACE ./enet/include) 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 # Cubeb
if (ENABLE_CUBEB) if (ENABLE_CUBEB)
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_TESTS OFF CACHE BOOL "")
set(BUILD_TOOLS OFF CACHE BOOL "") set(BUILD_TOOLS OFF CACHE BOOL "")
set(BUNDLE_SPEEX ON CACHE BOOL "") set(BUNDLE_SPEEX ON CACHE BOOL "")
add_subdirectory(cubeb EXCLUDE_FROM_ALL) add_subdirectory(cubeb EXCLUDE_FROM_ALL)
endif()
endif() endif()
# DiscordRPC # 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) { 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) { if (perform_time_stretching) {
const std::vector<s16> in{fifo.Pop()}; const std::vector<s16> in{fifo.Pop()};
const std::size_t num_in{in.size() / 2}; const std::size_t num_in{in.size() / 2};
frames_written = time_stretcher.Process(in.data(), num_in, buffer, num_frames); frames_written = time_stretcher.Process(in.data(), num_in, buffer, num_frames);
} else if (flushing_time_stretcher) { } else {
if (flushing_time_stretcher) {
time_stretcher.Flush(); time_stretcher.Flush();
frames_written = time_stretcher.Process(nullptr, 0, buffer, num_frames); frames_written = time_stretcher.Process(nullptr, 0, buffer, num_frames);
frames_written += fifo.Pop(buffer, num_frames - frames_written);
flushing_time_stretcher = false; flushing_time_stretcher = false;
} else {
frames_written = fifo.Pop(buffer, num_frames); // 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) { if (frames_written > 0) {

View File

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

View File

@@ -34,7 +34,6 @@ public:
void Flush(); void Flush();
private: private:
unsigned int sample_rate;
std::unique_ptr<soundtouch::SoundTouch> sound_touch; std::unique_ptr<soundtouch::SoundTouch> sound_touch;
double stretch_ratio = 1.0; 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); screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
system.Renderer().RequestScreenshot( system.Renderer().RequestScreenshot(
screenshot_image.bits(), screenshot_image.bits(),
[this, screenshot_path] { [this, screenshot_path](bool invert_y) {
const std::string std_screenshot_path = screenshot_path.toStdString(); 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); LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path);
} else { } else {
LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path); LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path);

View File

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

View File

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

View File

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

View File

@@ -124,6 +124,7 @@ add_library(citra_common STATIC
serialization/boost_flat_set.h serialization/boost_flat_set.h
serialization/boost_small_vector.hpp serialization/boost_small_vector.hpp
serialization/boost_vector.hpp serialization/boost_vector.hpp
static_lru_cache.h
string_literal.h string_literal.h
string_util.cpp string_util.cpp
string_util.h string_util.h
@@ -174,7 +175,7 @@ endif()
create_target_directory_groups(citra_common) 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 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) if ("x86_64" IN_LIST ARCHITECTURE)
target_link_libraries(citra_common PRIVATE xbyak) 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); 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) { std::size_t IOFile::WriteImpl(const void* data, std::size_t length, std::size_t data_size) {
if (!IsOpen()) { if (!IsOpen()) {
m_good = false; m_good = false;

View File

@@ -294,6 +294,18 @@ public:
return items_read; 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> template <typename T>
std::size_t WriteArray(const T* data, std::size_t length) { std::size_t WriteArray(const T* data, std::size_t length) {
static_assert(std::is_trivially_copyable_v<T>, static_assert(std::is_trivially_copyable_v<T>,
@@ -312,6 +324,12 @@ public:
return ReadArray(reinterpret_cast<char*>(data), length); 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> template <typename T>
std::size_t WriteBytes(const T* data, std::size_t length) { std::size_t WriteBytes(const T* data, std::size_t length) {
static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable"); static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable");
@@ -363,6 +381,8 @@ public:
private: private:
std::size_t ReadImpl(void* data, std::size_t length, std::size_t data_size); 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); std::size_t WriteImpl(const void* data, std::size_t length, std::size_t data_size);
bool Open(); bool Open();

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 <algorithm>
#include <zstd.h> #include <zstd.h>
#include "common/logging/log.h"
#include "common/zstd_compression.h" #include "common/zstd_compression.h"
namespace Common::Compression { namespace Common::Compression {

View File

@@ -86,6 +86,20 @@ public:
*/ */
virtual void Flush() const = 0; 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: protected:
std::unique_ptr<DelayGenerator> delay_generator; std::unique_ptr<DelayGenerator> delay_generator;

View File

@@ -131,6 +131,14 @@ public:
} }
void Flush() const override {} 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: private:
std::shared_ptr<RomFSReader> romfs_file; std::shared_ptr<RomFSReader> romfs_file;

View File

@@ -53,6 +53,14 @@ public:
bool DumpRomFS(const std::string& target_path); 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: private:
struct File; struct File;
struct Directory { struct Directory {

View File

@@ -1,4 +1,5 @@
#include <algorithm> #include <algorithm>
#include <vector>
#include <cryptopp/aes.h> #include <cryptopp/aes.h>
#include <cryptopp/modes.h> #include <cryptopp/modes.h>
#include "common/archives.h" #include "common/archives.h"
@@ -9,17 +10,102 @@ SERIALIZE_EXPORT_IMPL(FileSys::DirectRomFSReader)
namespace FileSys { namespace FileSys {
std::size_t DirectRomFSReader::ReadFile(std::size_t offset, std::size_t length, u8* buffer) { 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) if (length == 0)
return 0; // Crypto++ does not like zero size buffer 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); const auto segments = BreakupRead(offset, length);
read_length = file.ReadBytes(buffer, read_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) { if (is_encrypted) {
CryptoPP::CTR_Mode<CryptoPP::AES>::Decryption d(key.data(), key.size(), ctr.data()); CryptoPP::CTR_Mode<CryptoPP::AES>::Decryption d(key.data(), key.size(), ctr.data());
d.Seek(crypto_offset + offset); d.Seek(crypto_offset + offset);
d.ProcessData(buffer, buffer, read_length); d.ProcessData(buffer, buffer, length);
} }
return read_length; // LOG_INFO(Service_FS, "Cache SKIP: offset={}, length={}", offset, length);
return 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 } // namespace FileSys

View File

@@ -1,11 +1,14 @@
#pragma once #pragma once
#include <array> #include <array>
#include <shared_mutex>
#include <boost/serialization/array.hpp> #include <boost/serialization/array.hpp>
#include <boost/serialization/base_object.hpp> #include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp> #include <boost/serialization/export.hpp>
#include "common/alignment.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "common/static_lru_cache.h"
namespace FileSys { namespace FileSys {
@@ -18,6 +21,8 @@ public:
virtual std::size_t GetSize() const = 0; virtual std::size_t GetSize() const = 0;
virtual std::size_t ReadFile(std::size_t offset, std::size_t length, u8* buffer) = 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: private:
template <class Archive> template <class Archive>
@@ -48,6 +53,10 @@ public:
std::size_t ReadFile(std::size_t offset, std::size_t length, u8* buffer) override; 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: private:
bool is_encrypted; bool is_encrypted;
FileUtil::IOFile file; FileUtil::IOFile file;
@@ -57,8 +66,23 @@ private:
u64 crypto_offset; u64 crypto_offset;
u64 data_size; 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; 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> template <class Archive>
void serialize(Archive& ar, const unsigned int) { void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<RomFSReader>(*this); ar& boost::serialization::base_object<RomFSReader>(*this);

View File

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

View File

@@ -57,7 +57,6 @@ void File::Read(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx); IPC::RequestParser rp(ctx);
u64 offset = rp.Pop<u64>(); u64 offset = rp.Pop<u64>();
u32 length = rp.Pop<u32>(); u32 length = rp.Pop<u32>();
auto& buffer = rp.PopMappedBuffer();
LOG_TRACE(Service_FS, "Read {}: offset=0x{:x} length=0x{:08X}", GetName(), offset, length); LOG_TRACE(Service_FS, "Read {}: offset=0x{:x} length=0x{:08X}", GetName(), offset, length);
const FileSessionSlot* file = GetSessionData(ctx.Session()); const FileSessionSlot* file = GetSessionData(ctx.Session());
@@ -76,15 +75,17 @@ void File::Read(Kernel::HLERequestContext& ctx) {
offset, length, backend->GetSize()); offset, length, backend->GetSize());
} }
// Conventional reading if the backend does not support cache.
if (!backend->AllowsCachedReads()) {
auto& buffer = rp.PopMappedBuffer();
IPC::RequestBuilder rb = rp.MakeBuilder(2, 2); IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
std::unique_ptr<u8*> data = std::make_unique<u8*>(static_cast<u8*>(operator new(length)));
std::vector<u8> data(length); const auto read = backend->Read(offset, length, *data);
ResultVal<std::size_t> read = backend->Read(offset, data.size(), data.data());
if (read.Failed()) { if (read.Failed()) {
rb.Push(read.Code()); rb.Push(read.Code());
rb.Push<u32>(0); rb.Push<u32>(0);
} else { } else {
buffer.Write(data.data(), 0, *read); buffer.Write(*data, 0, *read);
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
rb.Push<u32>(static_cast<u32>(*read)); rb.Push<u32>(static_cast<u32>(*read));
} }
@@ -92,6 +93,76 @@ void File::Read(Kernel::HLERequestContext& ctx) {
std::chrono::nanoseconds read_timeout_ns{backend->GetReadDelayNs(length)}; std::chrono::nanoseconds read_timeout_ns{backend->GetReadDelayNs(length)};
ctx.SleepClientThread("file::read", read_timeout_ns, nullptr); ctx.SleepClientThread("file::read", read_timeout_ns, nullptr);
return;
}
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) { 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); 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) { void FS_USER::GetProgramLaunchInfo(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx); IPC::RequestParser rp(ctx);
const auto process_id = rp.Pop<u32>(); const auto process_id = rp.Pop<u32>();
@@ -687,8 +707,20 @@ void FS_USER::GetProgramLaunchInfo(Kernel::HLERequestContext& ctx) {
return; 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.Push(RESULT_SUCCESS);
rb.PushRaw(program_info_result.Unwrap()); rb.PushRaw<ProgramInfo>(program_info);
} }
void FS_USER::ObsoletedCreateExtSaveData(Kernel::HLERequestContext& ctx) { void FS_USER::ObsoletedCreateExtSaveData(Kernel::HLERequestContext& ctx) {
@@ -775,12 +807,12 @@ void FS_USER::AddSeed(Kernel::HLERequestContext& ctx) {
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
} }
void FS_USER::SetSaveDataSecureValue(Kernel::HLERequestContext& ctx) { void FS_USER::ObsoletedSetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx); IPC::RequestParser rp(ctx);
u64 value = rp.Pop<u64>(); const u64 value = rp.Pop<u64>();
u32 secure_value_slot = rp.Pop<u32>(); const u32 secure_value_slot = rp.Pop<u32>();
u32 unique_id = rp.Pop<u32>(); const u32 unique_id = rp.Pop<u32>();
u8 title_variation = rp.Pop<u8>(); const u8 title_variation = rp.Pop<u8>();
// TODO: Generate and Save the Secure Value // TODO: Generate and Save the Secure Value
@@ -794,12 +826,11 @@ void FS_USER::SetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
} }
void FS_USER::GetSaveDataSecureValue(Kernel::HLERequestContext& ctx) { void FS_USER::ObsoletedGetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx); IPC::RequestParser rp(ctx);
const u32 secure_value_slot = rp.Pop<u32>();
u32 secure_value_slot = rp.Pop<u32>(); const u32 unique_id = rp.Pop<u32>();
u32 unique_id = rp.Pop<u32>(); const u8 title_variation = rp.Pop<u8>();
u8 title_variation = rp.Pop<u8>();
LOG_WARNING( LOG_WARNING(
Service_FS, Service_FS,
@@ -816,7 +847,77 @@ void FS_USER::GetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
rb.Push<u64>(0); // the secure value 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); const MediaType media_type = GetMediaTypeFromPath(filepath);
program_info_map.insert_or_assign(process_id, ProgramInfo{program_id, media_type}); program_info_map.insert_or_assign(process_id, ProgramInfo{program_id, media_type});
if (media_type == MediaType::GameCard) { if (media_type == MediaType::GameCard) {
@@ -828,6 +929,19 @@ std::string FS_USER::GetCurrentGamecardPath() const {
return current_gamecard_path; 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) { ResultVal<u16> FS_USER::GetSpecialContentIndexFromGameCard(u64 title_id, SpecialContentType type) {
// TODO(B3N30) check if on real 3DS NCSD is checked if partition exists // 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"}, {0x082B, nullptr, "CardNorDirectRead_4xIO"},
{0x082C, nullptr, "CardNorDirectCpuWriteWithoutVerify"}, {0x082C, nullptr, "CardNorDirectCpuWriteWithoutVerify"},
{0x082D, nullptr, "CardNorDirectSectorEraseWithoutVerify"}, {0x082D, nullptr, "CardNorDirectSectorEraseWithoutVerify"},
{0x082E, nullptr, "GetProductInfo"}, {0x082E, &FS_USER::GetProductInfo, "GetProductInfo"},
{0x082F, &FS_USER::GetProgramLaunchInfo, "GetProgramLaunchInfo"}, {0x082F, &FS_USER::GetProgramLaunchInfo, "GetProgramLaunchInfo"},
{0x0830, &FS_USER::ObsoletedCreateExtSaveData, "Obsoleted_3_0_CreateExtSaveData"}, {0x0830, &FS_USER::ObsoletedCreateExtSaveData, "Obsoleted_3_0_CreateExtSaveData"},
{0x0831, nullptr, "CreateSharedExtSaveData"}, {0x0831, nullptr, "CreateSharedExtSaveData"},
@@ -984,12 +1098,16 @@ FS_USER::FS_USER(Core::System& system)
{0x0862, &FS_USER::SetPriority, "SetPriority"}, {0x0862, &FS_USER::SetPriority, "SetPriority"},
{0x0863, &FS_USER::GetPriority, "GetPriority"}, {0x0863, &FS_USER::GetPriority, "GetPriority"},
{0x0864, nullptr, "GetNandInfo"}, {0x0864, nullptr, "GetNandInfo"},
{0x0865, &FS_USER::SetSaveDataSecureValue, "SetSaveDataSecureValue"}, {0x0865, &FS_USER::ObsoletedSetSaveDataSecureValue, "SetSaveDataSecureValue"},
{0x0866, &FS_USER::GetSaveDataSecureValue, "GetSaveDataSecureValue"}, {0x0866, &FS_USER::ObsoletedGetSaveDataSecureValue, "GetSaveDataSecureValue"},
{0x0867, nullptr, "ControlSecureSave"}, {0x0867, nullptr, "ControlSecureSave"},
{0x0868, nullptr, "GetMediaType"}, {0x0868, nullptr, "GetMediaType"},
{0x0869, nullptr, "GetNandEraseCount"}, {0x0869, nullptr, "GetNandEraseCount"},
{0x086A, nullptr, "ReadNandReport"}, {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"}, {0x087A, &FS_USER::AddSeed, "AddSeed"},
{0x087D, &FS_USER::GetNumSeeds, "GetNumSeeds"}, {0x087D, &FS_USER::GetNumSeeds, "GetNumSeeds"},
{0x0886, nullptr, "CheckUpdatedDat"}, {0x0886, nullptr, "CheckUpdatedDat"},

View File

@@ -4,10 +4,12 @@
#pragma once #pragma once
#include <optional>
#include <unordered_map> #include <unordered_map>
#include <boost/serialization/base_object.hpp> #include <boost/serialization/base_object.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/file_sys/errors.h" #include "core/file_sys/errors.h"
#include "core/hle/service/fs/archive.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
namespace Core { namespace Core {
@@ -47,12 +49,23 @@ class FS_USER final : public ServiceFramework<FS_USER, ClientSlot> {
public: public:
explicit FS_USER(Core::System& system); 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 // On real HW this is part of FSReg (FSReg:Register). But since that module is only used by
// we HLEed, we can just directly use it here // 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); void RegisterProgramInfo(u32 process_id, u64 program_id, const std::string& filepath);
std::string GetCurrentGamecardPath() const; 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. /// Gets the registered program info of a process.
ResultVal<ProgramInfo> GetProgramLaunchInfo(u32 process_id) const { ResultVal<ProgramInfo> GetProgramLaunchInfo(u32 process_id) const {
auto info = program_info_map.find(process_id); auto info = program_info_map.find(process_id);
@@ -509,6 +522,17 @@ private:
*/ */
void GetFormatInfo(Kernel::HLERequestContext& ctx); 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. * FS_User::GetProgramLaunchInfo service function.
* Inputs: * Inputs:
@@ -600,7 +624,7 @@ private:
* 0 : 0x08650140 * 0 : 0x08650140
* 1 : Result of function, 0 on success, otherwise error code * 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. * FS_User::GetSaveDataSecureValue service function.
@@ -615,6 +639,57 @@ private:
* 2 : If Secure Value doesn't exist, 0, if it exists, 1 * 2 : If Secure Value doesn't exist, 0, if it exists, 1
* 3-4 : Secure Value * 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); void GetSaveDataSecureValue(Kernel::HLERequestContext& ctx);
static ResultVal<u16> GetSpecialContentIndexFromGameCard(u64 title_id, SpecialContentType type); static ResultVal<u16> GetSpecialContentIndexFromGameCard(u64 title_id, SpecialContentType type);
@@ -624,6 +699,8 @@ private:
std::unordered_map<u32, ProgramInfo> program_info_map; std::unordered_map<u32, ProgramInfo> program_info_map;
std::string current_gamecard_path; std::string current_gamecard_path;
std::unordered_map<u32, ProductInfo> product_info_map;
u32 priority = -1; ///< For SetPriority and GetPriority service functions u32 priority = -1; ///< For SetPriority and GetPriority service functions
Core::System& system; 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 // On real HW this is done with FS:Reg, but we can be lazy
auto fs_user = auto fs_user =
Core::System::GetInstance().ServiceManager().GetService<Service::FS::FS_USER>("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); 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 = auto fs_user =
Core::System::GetInstance().ServiceManager().GetService<Service::FS::FS_USER>( Core::System::GetInstance().ServiceManager().GetService<Service::FS::FS_USER>(
"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); process->Run(priority, stack_size);
return ResultStatus::Success; return ResultStatus::Success;

View File

@@ -11,6 +11,7 @@
#include <span> #include <span>
#include <catch2/catch_approx.hpp> #include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <fmt/format.h>
#include <nihstro/inline_assembly.h> #include <nihstro/inline_assembly.h>
#include "video_core/shader/shader_interpreter.h" #include "video_core/shader/shader_interpreter.h"
#include "video_core/shader/shader_jit_x64_compiler.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_one = Common::Vec4f::AssignToAll(1.0f);
static constexpr Common::Vec4f vec4_zero = Common::Vec4f::AssignToAll(0.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( static std::unique_ptr<Pica::Shader::ShaderSetup> CompileShaderSetup(
std::initializer_list<nihstro::InlineAsm> code) { std::initializer_list<nihstro::InlineAsm> code) {
const auto shbin = nihstro::InlineAsm::CompileToRawBinary(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)); 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 // TODO: Requires fix from https://github.com/neobrain/nihstro/issues/68
// TEST_CASE("MAD", "[video_core][shader][shader_jit]") { // TEST_CASE("MAD", "[video_core][shader][shader_jit]") {
// const auto sh_input1 = SourceRegister::MakeInput(0); // 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 >= 3 && !uniform_setup.IsFloat32())) {
float_regs_counter = 0; float_regs_counter = 0;
auto& uniform = setup.uniforms.f[uniform_setup.index]; if (uniform_setup.index >= setup.uniforms.f.size()) {
if (uniform_setup.index >= 96) {
LOG_ERROR(HW_GPU, "Invalid {} float uniform index {}", GetShaderSetupTypeName(setup), LOG_ERROR(HW_GPU, "Invalid {} float uniform index {}", GetShaderSetupTypeName(setup),
(int)uniform_setup.index); (int)uniform_setup.index);
} else { } else {
auto& uniform = setup.uniforms.f[uniform_setup.index];
// NOTE: The destination component order indeed is "backwards" // NOTE: The destination component order indeed is "backwards"
if (uniform_setup.IsFloat32()) { if (uniform_setup.IsFloat32()) {

View File

@@ -59,7 +59,7 @@ bool RendererBase::IsScreenshotPending() const {
return settings.screenshot_requested; 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) { const Layout::FramebufferLayout& layout) {
if (settings.screenshot_requested) { if (settings.screenshot_requested) {
LOG_ERROR(Render, "A screenshot is already requested or in progress, ignoring the request"); LOG_ERROR(Render, "A screenshot is already requested or in progress, ignoring the request");

View File

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

View File

@@ -78,8 +78,8 @@ RasterizerOpenGL::RasterizerOpenGL(Memory::MemorySystem& memory,
VideoCore::CustomTexManager& custom_tex_manager, VideoCore::CustomTexManager& custom_tex_manager,
VideoCore::RendererBase& renderer, Driver& driver_) VideoCore::RendererBase& renderer, Driver& driver_)
: VideoCore::RasterizerAccelerated{memory}, driver{driver_}, : VideoCore::RasterizerAccelerated{memory}, driver{driver_},
shader_manager{renderer.GetRenderWindow(), driver, !driver.IsOpenGLES()}, shader_manager{renderer.GetRenderWindow(), driver}, runtime{driver, renderer},
runtime{driver, renderer}, res_cache{memory, custom_tex_manager, runtime, regs, renderer}, res_cache{memory, custom_tex_manager, runtime, regs, renderer},
texture_buffer_size{TextureBufferSize()}, vertex_buffer{driver, GL_ARRAY_BUFFER, texture_buffer_size{TextureBufferSize()}, vertex_buffer{driver, GL_ARRAY_BUFFER,
VERTEX_BUFFER_SIZE}, VERTEX_BUFFER_SIZE},
uniform_buffer{driver, GL_UNIFORM_BUFFER, UNIFORM_BUFFER_SIZE}, uniform_buffer{driver, GL_UNIFORM_BUFFER, UNIFORM_BUFFER_SIZE},

View File

@@ -2,14 +2,10 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "common/microprofile.h"
#include "video_core/renderer_opengl/gl_resource_manager.h" #include "video_core/renderer_opengl/gl_resource_manager.h"
#include "video_core/renderer_opengl/gl_shader_util.h" #include "video_core/renderer_opengl/gl_shader_util.h"
#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_state.h"
MICROPROFILE_DEFINE(OpenGL_ResourceCreation, "OpenGL", "Resource Creation", MP_RGB(128, 128, 192));
MICROPROFILE_DEFINE(OpenGL_ResourceDeletion, "OpenGL", "Resource Deletion", MP_RGB(128, 128, 192));
namespace OpenGL { namespace OpenGL {
void OGLRenderbuffer::Create() { void OGLRenderbuffer::Create() {
@@ -17,7 +13,6 @@ void OGLRenderbuffer::Create() {
return; return;
} }
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenRenderbuffers(1, &handle); glGenRenderbuffers(1, &handle);
} }
@@ -26,7 +21,6 @@ void OGLRenderbuffer::Release() {
return; return;
} }
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteRenderbuffers(1, &handle); glDeleteRenderbuffers(1, &handle);
OpenGLState::GetCurState().ResetRenderbuffer(handle).Apply(); OpenGLState::GetCurState().ResetRenderbuffer(handle).Apply();
handle = 0; handle = 0;
@@ -37,7 +31,6 @@ void OGLTexture::Create() {
return; return;
} }
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenTextures(1, &handle); glGenTextures(1, &handle);
} }
@@ -46,7 +39,6 @@ void OGLTexture::Release() {
return; return;
} }
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteTextures(1, &handle); glDeleteTextures(1, &handle);
OpenGLState::GetCurState().ResetTexture(handle).Apply(); OpenGLState::GetCurState().ResetTexture(handle).Apply();
handle = 0; handle = 0;
@@ -88,7 +80,6 @@ void OGLSampler::Create() {
return; return;
} }
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenSamplers(1, &handle); glGenSamplers(1, &handle);
} }
@@ -97,37 +88,41 @@ void OGLSampler::Release() {
return; return;
} }
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteSamplers(1, &handle); glDeleteSamplers(1, &handle);
OpenGLState::GetCurState().ResetSampler(handle).Apply(); OpenGLState::GetCurState().ResetSampler(handle).Apply();
handle = 0; handle = 0;
} }
void OGLShader::Create(std::string_view source, GLenum type) { void OGLShader::Create(std::string_view source, GLenum type) {
if (handle != 0) if (handle != 0) {
return; return;
if (source.empty()) }
if (source.empty()) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
handle = LoadShader(source, type); handle = LoadShader(source, type);
} }
void OGLShader::Release() { void OGLShader::Release() {
if (handle == 0) if (handle == 0) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteShader(handle); glDeleteShader(handle);
handle = 0; handle = 0;
} }
void OGLProgram::Create(bool separable_program, std::span<const GLuint> shaders) { void OGLProgram::Create(std::string_view source, GLenum type) {
if (handle != 0) if (handle != 0) {
return; return;
}
if (source.empty()) {
return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation); const std::array sources{GetPreamble().data(), source.data()};
handle = LoadProgram(separable_program, shaders); handle = glCreateShaderProgramv(type, 2, sources.data());
} }
void OGLProgram::Create(std::string_view vert_shader, std::string_view frag_shader) { void OGLProgram::Create(std::string_view vert_shader, std::string_view frag_shader) {
@@ -135,88 +130,87 @@ void OGLProgram::Create(std::string_view vert_shader, std::string_view frag_shad
vert.Create(vert_shader, GL_VERTEX_SHADER); vert.Create(vert_shader, GL_VERTEX_SHADER);
frag.Create(frag_shader, GL_FRAGMENT_SHADER); frag.Create(frag_shader, GL_FRAGMENT_SHADER);
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
const std::array shaders{vert.handle, frag.handle}; const std::array shaders{vert.handle, frag.handle};
Create(false, shaders); handle = LoadProgram(shaders);
} }
void OGLProgram::Release() { void OGLProgram::Release() {
if (handle == 0) if (handle == 0) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteProgram(handle); glDeleteProgram(handle);
OpenGLState::GetCurState().ResetProgram(handle).Apply(); OpenGLState::GetCurState().ResetProgram(handle).Apply();
handle = 0; handle = 0;
} }
void OGLPipeline::Create() { void OGLPipeline::Create() {
if (handle != 0) if (handle != 0) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenProgramPipelines(1, &handle); glGenProgramPipelines(1, &handle);
} }
void OGLPipeline::Release() { void OGLPipeline::Release() {
if (handle == 0) if (handle == 0) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteProgramPipelines(1, &handle); glDeleteProgramPipelines(1, &handle);
OpenGLState::GetCurState().ResetPipeline(handle).Apply(); OpenGLState::GetCurState().ResetPipeline(handle).Apply();
handle = 0; handle = 0;
} }
void OGLBuffer::Create() { void OGLBuffer::Create() {
if (handle != 0) if (handle != 0) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenBuffers(1, &handle); glGenBuffers(1, &handle);
} }
void OGLBuffer::Release() { void OGLBuffer::Release() {
if (handle == 0) if (handle == 0) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteBuffers(1, &handle); glDeleteBuffers(1, &handle);
OpenGLState::GetCurState().ResetBuffer(handle).Apply(); OpenGLState::GetCurState().ResetBuffer(handle).Apply();
handle = 0; handle = 0;
} }
void OGLVertexArray::Create() { void OGLVertexArray::Create() {
if (handle != 0) if (handle != 0) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenVertexArrays(1, &handle); glGenVertexArrays(1, &handle);
} }
void OGLVertexArray::Release() { void OGLVertexArray::Release() {
if (handle == 0) if (handle == 0) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteVertexArrays(1, &handle); glDeleteVertexArrays(1, &handle);
OpenGLState::GetCurState().ResetVertexArray(handle).Apply(); OpenGLState::GetCurState().ResetVertexArray(handle).Apply();
handle = 0; handle = 0;
} }
void OGLFramebuffer::Create() { void OGLFramebuffer::Create() {
if (handle != 0) if (handle != 0) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceCreation);
glGenFramebuffers(1, &handle); glGenFramebuffers(1, &handle);
} }
void OGLFramebuffer::Release() { void OGLFramebuffer::Release() {
if (handle == 0) if (handle == 0) {
return; return;
}
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteFramebuffers(1, &handle); glDeleteFramebuffers(1, &handle);
OpenGLState::GetCurState().ResetFramebuffer(handle).Apply(); OpenGLState::GetCurState().ResetFramebuffer(handle).Apply();
handle = 0; handle = 0;

View File

@@ -130,7 +130,7 @@ public:
} }
/// Creates a new program from given shader objects /// Creates a new program from given shader objects
void Create(bool separable_program, std::span<const GLuint> shaders); void Create(std::string_view source, GLenum type);
/// Creates a new program from given shader soruce code /// Creates a new program from given shader soruce code
void Create(std::string_view vert_shader, std::string_view frag_shader); void Create(std::string_view vert_shader, std::string_view frag_shader);

View File

@@ -103,10 +103,8 @@ bool ShaderDiskCacheRaw::Save(FileUtil::IOFile& file) const {
return true; return true;
} }
ShaderDiskCache::ShaderDiskCache(bool separable) ShaderDiskCache::ShaderDiskCache()
: separable{separable}, transferable_file(AppendTransferableFile()), : transferable_file(AppendTransferableFile()), precompiled_file(AppendPrecompiledFile()) {}
// seperable shaders use the virtual precompile file, that already has a header.
precompiled_file(AppendPrecompiledFile(!separable)) {}
std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable() { std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable() {
const bool has_title_id = GetProgramID() != 0; const bool has_title_id = GetProgramID() != 0;
@@ -177,7 +175,7 @@ std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable
} }
std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>, ShaderDumpsMap> std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>, ShaderDumpsMap>
ShaderDiskCache::LoadPrecompiled(bool compressed) { ShaderDiskCache::LoadPrecompiled() {
if (!IsUsable()) if (!IsUsable())
return {}; return {};
@@ -187,7 +185,7 @@ ShaderDiskCache::LoadPrecompiled(bool compressed) {
return {}; return {};
} }
const auto result = LoadPrecompiledFile(precompiled_file, compressed); const auto result = LoadPrecompiledFile(precompiled_file);
if (!result) { if (!result) {
LOG_INFO(Render_OpenGL, LOG_INFO(Render_OpenGL,
"Failed to load precompiled cache for game with title id={} - removing", "Failed to load precompiled cache for game with title id={} - removing",
@@ -199,22 +197,16 @@ ShaderDiskCache::LoadPrecompiled(bool compressed) {
} }
std::optional<std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>, ShaderDumpsMap>> std::optional<std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>, ShaderDumpsMap>>
ShaderDiskCache::LoadPrecompiledFile(FileUtil::IOFile& file, bool compressed) { ShaderDiskCache::LoadPrecompiledFile(FileUtil::IOFile& file) {
// Read compressed file from disk and decompress to virtual precompiled cache file // Read compressed file from disk and decompress to virtual precompiled cache file
std::vector<u8> precompiled_file(file.GetSize()); std::vector<u8> precompiled_file(file.GetSize());
file.ReadBytes(precompiled_file.data(), precompiled_file.size()); file.ReadBytes(precompiled_file.data(), precompiled_file.size());
if (compressed) { const std::vector<u8> decompressed = Common::Compression::DecompressDataZSTD(precompiled_file);
const std::vector<u8> decompressed =
Common::Compression::DecompressDataZSTD(precompiled_file);
if (decompressed.empty()) { if (decompressed.empty()) {
LOG_ERROR(Render_OpenGL, "Could not decompress precompiled shader cache."); LOG_ERROR(Render_OpenGL, "Could not decompress precompiled shader cache.");
return std::nullopt; return std::nullopt;
} }
SaveArrayToPrecompiled(decompressed.data(), decompressed.size()); SaveArrayToPrecompiled(decompressed.data(), decompressed.size());
} else {
SaveArrayToPrecompiled(precompiled_file.data(), precompiled_file.size());
}
decompressed_precompiled_cache_offset = 0; decompressed_precompiled_cache_offset = 0;
ShaderCacheVersionHash file_hash{}; ShaderCacheVersionHash file_hash{};
@@ -353,7 +345,7 @@ void ShaderDiskCache::InvalidatePrecompiled() {
if (!FileUtil::Delete(GetPrecompiledPath())) { if (!FileUtil::Delete(GetPrecompiledPath())) {
LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath()); LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath());
} }
precompiled_file = AppendPrecompiledFile(!separable); precompiled_file = AppendPrecompiledFile();
} }
void ShaderDiskCache::SaveRaw(const ShaderDiskCacheRaw& entry) { void ShaderDiskCache::SaveRaw(const ShaderDiskCacheRaw& entry) {
@@ -471,12 +463,11 @@ FileUtil::IOFile ShaderDiskCache::AppendTransferableFile() {
return file; return file;
} }
FileUtil::IOFile ShaderDiskCache::AppendPrecompiledFile(bool write_header) { FileUtil::IOFile ShaderDiskCache::AppendPrecompiledFile() {
if (!EnsureDirectories()) if (!EnsureDirectories())
return {}; return {};
const auto precompiled_path{GetPrecompiledPath()}; const auto precompiled_path{GetPrecompiledPath()};
const bool existed = FileUtil::Exists(precompiled_path);
FileUtil::IOFile file(precompiled_path, "ab+"); FileUtil::IOFile file(precompiled_path, "ab+");
if (!file.IsOpen()) { if (!file.IsOpen()) {
@@ -484,15 +475,6 @@ FileUtil::IOFile ShaderDiskCache::AppendPrecompiledFile(bool write_header) {
return {}; return {};
} }
// If the file didn't exist, write its version
if (write_header && (!existed || file.GetSize() == 0)) {
const auto hash{GetShaderCacheVersionHash()};
if (file.WriteArray(hash.data(), hash.size()) != hash.size()) {
LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}",
precompiled_path);
return {};
}
}
return file; return file;
} }
@@ -516,7 +498,7 @@ void ShaderDiskCache::SaveVirtualPrecompiledFile() {
if (!FileUtil::Delete(GetPrecompiledPath())) { if (!FileUtil::Delete(GetPrecompiledPath())) {
LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath()); LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath());
} }
precompiled_file = AppendPrecompiledFile(!separable); precompiled_file = AppendPrecompiledFile();
if (precompiled_file.WriteBytes(compressed.data(), compressed.size()) != compressed.size()) { if (precompiled_file.WriteBytes(compressed.data(), compressed.size()) != compressed.size()) {
LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}", LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}",
@@ -558,10 +540,7 @@ std::string ShaderDiskCache::GetPrecompiledDir() const {
} }
std::string ShaderDiskCache::GetPrecompiledShaderDir() const { std::string ShaderDiskCache::GetPrecompiledShaderDir() const {
if (separable) {
return GetPrecompiledDir() + DIR_SEP "separable"; return GetPrecompiledDir() + DIR_SEP "separable";
}
return GetPrecompiledDir() + DIR_SEP "conventional";
} }
std::string ShaderDiskCache::GetBaseDir() const { std::string ShaderDiskCache::GetBaseDir() const {

View File

@@ -16,11 +16,8 @@
#include <glad/glad.h> #include <glad/glad.h>
#include "common/assert.h"
#include "common/common_types.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "video_core/regs.h" #include "video_core/shader/generator/shader_gen.h"
#include "video_core/shader/generator/glsl_shader_gen.h"
namespace Core { namespace Core {
class System; class System;
@@ -90,14 +87,14 @@ struct ShaderDiskCacheDump {
class ShaderDiskCache { class ShaderDiskCache {
public: public:
explicit ShaderDiskCache(bool separable); explicit ShaderDiskCache();
~ShaderDiskCache() = default; ~ShaderDiskCache() = default;
/// Loads transferable cache. If file has a old version or on failure, it deletes the file. /// Loads transferable cache. If file has a old version or on failure, it deletes the file.
std::optional<std::vector<ShaderDiskCacheRaw>> LoadTransferable(); std::optional<std::vector<ShaderDiskCacheRaw>> LoadTransferable();
/// Loads current game's precompiled cache. Invalidates on failure. /// Loads current game's precompiled cache. Invalidates on failure.
std::pair<ShaderDecompiledMap, ShaderDumpsMap> LoadPrecompiled(bool compressed); std::pair<ShaderDecompiledMap, ShaderDumpsMap> LoadPrecompiled();
/// Removes the transferable (and precompiled) cache file. /// Removes the transferable (and precompiled) cache file.
void InvalidateAll(); void InvalidateAll();
@@ -123,7 +120,7 @@ public:
private: private:
/// Loads the transferable cache. Returns empty on failure. /// Loads the transferable cache. Returns empty on failure.
std::optional<std::pair<ShaderDecompiledMap, ShaderDumpsMap>> LoadPrecompiledFile( std::optional<std::pair<ShaderDecompiledMap, ShaderDumpsMap>> LoadPrecompiledFile(
FileUtil::IOFile& file, bool compressed); FileUtil::IOFile& file);
/// Loads a decompiled cache entry from m_precompiled_cache_virtual_file. Returns empty on /// Loads a decompiled cache entry from m_precompiled_cache_virtual_file. Returns empty on
/// failure. /// failure.
@@ -143,7 +140,7 @@ private:
FileUtil::IOFile AppendTransferableFile(); FileUtil::IOFile AppendTransferableFile();
/// Opens current game's precompiled file and write it's header if it doesn't exist /// Opens current game's precompiled file and write it's header if it doesn't exist
FileUtil::IOFile AppendPrecompiledFile(bool write_header); FileUtil::IOFile AppendPrecompiledFile();
/// Save precompiled header to precompiled_cache_in_memory /// Save precompiled header to precompiled_cache_in_memory
void SavePrecompiledHeaderToVirtualPrecompiledCache(); void SavePrecompiledHeaderToVirtualPrecompiledCache();
@@ -219,8 +216,6 @@ private:
// The cache has been loaded at boot // The cache has been loaded at boot
bool tried_to_load{}; bool tried_to_load{};
bool separable{};
u64 program_id{}; u64 program_id{};
std::string title_id; std::string title_id;

View File

@@ -14,7 +14,7 @@
#include "video_core/renderer_opengl/gl_shader_disk_cache.h" #include "video_core/renderer_opengl/gl_shader_disk_cache.h"
#include "video_core/renderer_opengl/gl_shader_manager.h" #include "video_core/renderer_opengl/gl_shader_manager.h"
#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_state.h"
#include "video_core/shader/generator/shader_uniforms.h" #include "video_core/shader/generator/glsl_shader_gen.h"
#include "video_core/video_core.h" #include "video_core/video_core.h"
using namespace Pica::Shader::Generator; using namespace Pica::Shader::Generator;
@@ -35,19 +35,16 @@ static u64 GetUniqueIdentifier(const Pica::Regs& regs, const ProgramCode& code)
} }
static OGLProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump, static OGLProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump,
const std::set<GLenum>& supported_formats, const std::set<GLenum>& supported_formats) {
bool separable) {
if (supported_formats.find(dump.binary_format) == supported_formats.end()) { if (supported_formats.find(dump.binary_format) == supported_formats.end()) {
LOG_INFO(Render_OpenGL, "Precompiled cache entry with unsupported format - removing"); LOG_INFO(Render_OpenGL, "Precompiled cache entry with unsupported format - removing");
return {}; return {};
} }
auto shader = OGLProgram(); OGLProgram shader{};
shader.handle = glCreateProgram(); shader.handle = glCreateProgram();
if (separable) {
glProgramParameteri(shader.handle, GL_PROGRAM_SEPARABLE, GL_TRUE); glProgramParameteri(shader.handle, GL_PROGRAM_SEPARABLE, GL_TRUE);
}
glProgramBinary(shader.handle, dump.binary_format, dump.binary.data(), glProgramBinary(shader.handle, dump.binary_format, dump.binary.data(),
static_cast<GLsizei>(dump.binary.size())); static_cast<GLsizei>(dump.binary.size()));
@@ -90,91 +87,42 @@ static std::tuple<PicaVSConfig, Pica::Shader::ShaderSetup> BuildVSConfigFromRaw(
setup}; setup};
} }
/**
* An object representing a shader program staging. It can be either a shader object or a program
* object, depending on whether separable program is used.
*/
class OGLShaderStage {
public:
explicit OGLShaderStage(bool separable) {
if (separable) {
shader_or_program = OGLProgram();
} else {
shader_or_program = OGLShader();
}
}
void Create(const char* source, GLenum type) {
if (shader_or_program.index() == 0) {
std::get<OGLShader>(shader_or_program).Create(source, type);
} else {
OGLShader shader;
shader.Create(source, type);
OGLProgram& program = std::get<OGLProgram>(shader_or_program);
program.Create(true, std::array{shader.handle});
}
}
GLuint GetHandle() const {
if (shader_or_program.index() == 0) {
return std::get<OGLShader>(shader_or_program).handle;
} else {
return std::get<OGLProgram>(shader_or_program).handle;
}
}
void Inject(OGLProgram&& program) {
shader_or_program = std::move(program);
}
private:
std::variant<OGLShader, OGLProgram> shader_or_program;
};
class TrivialVertexShader { class TrivialVertexShader {
public: public:
explicit TrivialVertexShader(const Driver& driver, bool separable) : program(separable) { explicit TrivialVertexShader(const Driver& driver) {
const auto code = const auto code = GLSL::GenerateTrivialVertexShader(driver.HasClipCullDistance(), true);
GLSL::GenerateTrivialVertexShader(driver.HasClipCullDistance(), separable); program.Create(code, GL_VERTEX_SHADER);
program.Create(code.c_str(), GL_VERTEX_SHADER);
} }
GLuint Get() const { GLuint Get() const {
return program.GetHandle(); return program.handle;
} }
private: private:
OGLShaderStage program; OGLProgram program;
}; };
template <typename KeyConfigType, std::string (*CodeGenerator)(const KeyConfigType&, bool), template <typename KeyConfigType, auto CodeGenerator, GLenum ShaderType>
GLenum ShaderType>
class ShaderCache { class ShaderCache {
public: public:
explicit ShaderCache(bool separable) : separable(separable) {} explicit ShaderCache() = default;
std::tuple<GLuint, std::optional<std::string>> Get(const KeyConfigType& config) { std::tuple<GLuint, std::optional<std::string>> Get(const KeyConfigType& config) {
auto [iter, new_shader] = shaders.emplace(config, OGLShaderStage{separable}); auto [iter, new_shader] = shaders.try_emplace(config);
OGLShaderStage& cached_shader = iter->second; OGLProgram& cached_shader = iter->second;
std::optional<std::string> result{}; std::optional<std::string> result{};
if (new_shader) { if (new_shader) {
result = CodeGenerator(config, separable); result = CodeGenerator(config, true);
cached_shader.Create(result->c_str(), ShaderType); cached_shader.Create(result.value(), ShaderType);
} }
return {cached_shader.GetHandle(), std::move(result)}; return {cached_shader.handle, std::move(result)};
} }
void Inject(const KeyConfigType& key, OGLProgram&& program) { void Inject(const KeyConfigType& key, OGLProgram&& stage) {
OGLShaderStage stage{separable};
stage.Inject(std::move(program));
shaders.emplace(key, std::move(stage));
}
void Inject(const KeyConfigType& key, OGLShaderStage&& stage) {
shaders.emplace(key, std::move(stage)); shaders.emplace(key, std::move(stage));
} }
private: private:
bool separable; std::unordered_map<KeyConfigType, OGLProgram> shaders;
std::unordered_map<KeyConfigType, OGLShaderStage> shaders;
}; };
// This is a cache designed for shaders translated from PICA shaders. The first cache matches the // This is a cache designed for shaders translated from PICA shaders. The first cache matches the
@@ -182,59 +130,48 @@ private:
// GLSL code. The configuration is like this because there might be leftover code in the PICA shader // GLSL code. The configuration is like this because there might be leftover code in the PICA shader
// program buffer from the previous shader, which is hashed into the config, resulting several // program buffer from the previous shader, which is hashed into the config, resulting several
// different config values from the same shader program. // different config values from the same shader program.
template <typename KeyConfigType, template <typename KeyConfigType, auto CodeGenerator, GLenum ShaderType>
std::string (*CodeGenerator)(const Pica::Shader::ShaderSetup&, const KeyConfigType&,
bool),
GLenum ShaderType>
class ShaderDoubleCache { class ShaderDoubleCache {
public: public:
explicit ShaderDoubleCache(bool separable) : separable(separable) {} explicit ShaderDoubleCache() = default;
std::tuple<GLuint, std::optional<std::string>> Get(const KeyConfigType& key, std::tuple<GLuint, std::optional<std::string>> Get(const KeyConfigType& key,
const Pica::Shader::ShaderSetup& setup) { const Pica::Shader::ShaderSetup& setup) {
std::optional<std::string> result{}; std::optional<std::string> result{};
auto map_it = shader_map.find(key); auto map_it = shader_map.find(key);
if (map_it == shader_map.end()) { if (map_it == shader_map.end()) {
auto program = CodeGenerator(setup, key, separable); const auto program = CodeGenerator(setup, key, separable);
if (program.empty()) { if (program.empty()) {
shader_map[key] = nullptr; shader_map[key] = nullptr;
return {0, std::nullopt}; return {0, std::nullopt};
} }
auto [iter, new_shader] = shader_cache.emplace(program, OGLShaderStage{separable}); const auto [iter, new_shader] = shader_cache.try_emplace(program);
OGLShaderStage& cached_shader = iter->second; OGLProgram& cached_shader = iter->second;
if (new_shader) { if (new_shader) {
result = program; result = program;
cached_shader.Create(program.c_str(), ShaderType); cached_shader.Create(program, ShaderType);
} }
shader_map[key] = &cached_shader; shader_map[key] = &cached_shader;
return {cached_shader.GetHandle(), std::move(result)}; return {cached_shader.handle, std::move(result)};
} }
if (map_it->second == nullptr) { if (map_it->second == nullptr) {
return {0, std::nullopt}; return {0, std::nullopt};
} }
return {map_it->second->GetHandle(), std::nullopt}; return {map_it->second->handle, std::nullopt};
} }
void Inject(const KeyConfigType& key, std::string decomp, OGLProgram&& program) { void Inject(const KeyConfigType& key, std::string decomp, OGLProgram&& program) {
OGLShaderStage stage{separable}; const auto iter = shader_cache.emplace(std::move(decomp), std::move(program)).first;
stage.Inject(std::move(program)); shader_map.insert_or_assign(key, &iter->second);
const auto iter = shader_cache.emplace(std::move(decomp), std::move(stage)).first;
OGLShaderStage& cached_shader = iter->second;
shader_map.insert_or_assign(key, &cached_shader);
}
void Inject(const KeyConfigType& key, std::string decomp, OGLShaderStage&& stage) {
const auto iter = shader_cache.emplace(std::move(decomp), std::move(stage)).first;
OGLShaderStage& cached_shader = iter->second;
shader_map.insert_or_assign(key, &cached_shader);
} }
private: private:
bool separable; bool separable;
std::unordered_map<KeyConfigType, OGLShaderStage*> shader_map; std::unordered_map<KeyConfigType, OGLProgram*> shader_map;
std::unordered_map<std::string, OGLShaderStage> shader_cache; std::unordered_map<std::string, OGLProgram> shader_cache;
}; };
using ProgrammableVertexShaders = using ProgrammableVertexShaders =
@@ -248,11 +185,7 @@ using FragmentShaders =
class ShaderProgramManager::Impl { class ShaderProgramManager::Impl {
public: public:
explicit Impl(const Driver& driver, bool separable) explicit Impl(const Driver& driver) : trivial_vertex_shader(driver) {
: separable(separable), programmable_vertex_shaders(separable),
trivial_vertex_shader(driver, separable), fixed_geometry_shaders(separable),
fragment_shaders(separable), disk_cache(separable) {
if (separable)
pipeline.Create(); pipeline.Create();
} }
@@ -282,8 +215,6 @@ public:
static_assert(offsetof(ShaderTuple, fs_hash) == sizeof(std::size_t) * 2, static_assert(offsetof(ShaderTuple, fs_hash) == sizeof(std::size_t) * 2,
"ShaderTuple layout changed!"); "ShaderTuple layout changed!");
bool separable;
ShaderTuple current; ShaderTuple current;
ProgrammableVertexShaders programmable_vertex_shaders; ProgrammableVertexShaders programmable_vertex_shaders;
@@ -297,11 +228,10 @@ public:
ShaderDiskCache disk_cache; ShaderDiskCache disk_cache;
}; };
ShaderProgramManager::ShaderProgramManager(Frontend::EmuWindow& emu_window_, const Driver& driver_, ShaderProgramManager::ShaderProgramManager(Frontend::EmuWindow& emu_window_, const Driver& driver_)
bool separable)
: emu_window{emu_window_}, driver{driver_}, : emu_window{emu_window_}, driver{driver_},
strict_context_required{emu_window.StrictContextRequired()}, impl{std::make_unique<Impl>( strict_context_required{emu_window.StrictContextRequired()}, impl{std::make_unique<Impl>(
driver_, separable)} {} driver_)} {}
ShaderProgramManager::~ShaderProgramManager() = default; ShaderProgramManager::~ShaderProgramManager() = default;
@@ -363,30 +293,18 @@ void ShaderProgramManager::UseFragmentShader(const Pica::Regs& regs, bool use_no
} }
void ShaderProgramManager::ApplyTo(OpenGLState& state) { void ShaderProgramManager::ApplyTo(OpenGLState& state) {
if (impl->separable) {
if (driver.HasBug(DriverBug::ShaderStageChangeFreeze)) { if (driver.HasBug(DriverBug::ShaderStageChangeFreeze)) {
glUseProgramStages( glUseProgramStages(impl->pipeline.handle,
impl->pipeline.handle, GL_VERTEX_SHADER_BIT | GL_GEOMETRY_SHADER_BIT | GL_FRAGMENT_SHADER_BIT,
GL_VERTEX_SHADER_BIT | GL_GEOMETRY_SHADER_BIT | GL_FRAGMENT_SHADER_BIT, 0); 0);
} }
glUseProgramStages(impl->pipeline.handle, GL_VERTEX_SHADER_BIT, impl->current.vs); glUseProgramStages(impl->pipeline.handle, GL_VERTEX_SHADER_BIT, impl->current.vs);
glUseProgramStages(impl->pipeline.handle, GL_GEOMETRY_SHADER_BIT, impl->current.gs); glUseProgramStages(impl->pipeline.handle, GL_GEOMETRY_SHADER_BIT, impl->current.gs);
glUseProgramStages(impl->pipeline.handle, GL_FRAGMENT_SHADER_BIT, impl->current.fs); glUseProgramStages(impl->pipeline.handle, GL_FRAGMENT_SHADER_BIT, impl->current.fs);
state.draw.shader_program = 0; state.draw.shader_program = 0;
state.draw.program_pipeline = impl->pipeline.handle; state.draw.program_pipeline = impl->pipeline.handle;
} else {
const u64 unique_identifier = impl->current.GetConfigHash();
OGLProgram& cached_program = impl->program_cache[unique_identifier];
if (cached_program.handle == 0) {
cached_program.Create(false,
std::array{impl->current.vs, impl->current.gs, impl->current.fs});
auto& disk_cache = impl->disk_cache;
disk_cache.SaveDumpToFile(unique_identifier, cached_program.handle,
VideoCore::g_hw_shader_accurate_mul);
}
state.draw.shader_program = cached_program.handle;
}
} }
void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading, void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
@@ -400,7 +318,7 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
// Load uncompressed precompiled file for non-separable shaders. // Load uncompressed precompiled file for non-separable shaders.
// Precompiled file for separable shaders is compressed. // Precompiled file for separable shaders is compressed.
auto [decompiled, dumps] = disk_cache.LoadPrecompiled(impl->separable); auto [decompiled, dumps] = disk_cache.LoadPrecompiled();
if (stop_loading) { if (stop_loading) {
return; return;
@@ -418,11 +336,11 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
callback(VideoCore::LoadCallbackStage::Decompile, 0, raws.size()); callback(VideoCore::LoadCallbackStage::Decompile, 0, raws.size());
} }
std::vector<std::size_t> load_raws_index; std::vector<std::size_t> load_raws_index;
// Loads both decompiled and precompiled shaders from the cache. If either one is missing for // Loads both decompiled and precompiled shaders from the cache. If either one is missing for
const auto LoadPrecompiledShader = [&](std::size_t begin, std::size_t end, const auto LoadPrecompiledShader =
std::span<const ShaderDiskCacheRaw> raw_cache, [&](std::size_t begin, std::size_t end, std::span<const ShaderDiskCacheRaw> raw_cache,
const ShaderDecompiledMap& decompiled_map, const ShaderDecompiledMap& decompiled_map, const ShaderDumpsMap& dump_map) {
const ShaderDumpsMap& dump_map) {
for (std::size_t i = begin; i < end; ++i) { for (std::size_t i = begin; i < end; ++i) {
if (stop_loading || compilation_failed) { if (stop_loading || compilation_failed) {
return; return;
@@ -454,24 +372,23 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
} }
// If the shader is dumped, attempt to load it // If the shader is dumped, attempt to load it
shader = shader = GeneratePrecompiledProgram(dump->second, supported_formats);
GeneratePrecompiledProgram(dump->second, supported_formats, impl->separable);
if (shader.handle == 0) { if (shader.handle == 0) {
// If any shader failed, stop trying to compile, delete the cache, and start // If any shader failed, stop trying to compile, delete the cache, and start
// loading from raws // loading from raws.
compilation_failed = true; compilation_failed = true;
return; return;
} }
// we have both the binary shader and the decompiled, so inject it into the // We have both the binary shader and the decompiled, so inject it into the
// cache // cache.
if (raw.GetProgramType() == ProgramType::VS) { if (raw.GetProgramType() == ProgramType::VS) {
auto [conf, setup] = BuildVSConfigFromRaw(raw, driver); auto [conf, setup] = BuildVSConfigFromRaw(raw, driver);
std::scoped_lock lock(mutex); std::scoped_lock lock(mutex);
impl->programmable_vertex_shaders.Inject(conf, decomp->second.code, impl->programmable_vertex_shaders.Inject(conf, decomp->second.code,
std::move(shader)); std::move(shader));
} else if (raw.GetProgramType() == ProgramType::FS) { } else if (raw.GetProgramType() == ProgramType::FS) {
PicaFSConfig conf(raw.GetRawShaderConfig(), false, driver.IsOpenGLES(), false, PicaFSConfig conf(raw.GetRawShaderConfig(), false, driver.IsOpenGLES(),
driver.HasBlendMinMaxFactor()); false, driver.HasBlendMinMaxFactor());
std::scoped_lock lock(mutex); std::scoped_lock lock(mutex);
impl->fragment_shaders.Inject(conf, std::move(shader)); impl->fragment_shaders.Inject(conf, std::move(shader));
} else { } else {
@@ -493,42 +410,7 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
} }
}; };
const auto LoadPrecompiledProgram = [&](const ShaderDecompiledMap& decompiled_map,
const ShaderDumpsMap& dump_map) {
std::size_t i{0};
for (const auto& dump : dump_map) {
if (stop_loading) {
break;
}
const u64 unique_identifier{dump.first};
const auto decomp{decompiled_map.find(unique_identifier)};
// Only load the program if its sanitize_mul setting matches
if (decomp->second.sanitize_mul != VideoCore::g_hw_shader_accurate_mul) {
continue;
}
// If the shader program is dumped, attempt to load it
OGLProgram shader =
GeneratePrecompiledProgram(dump.second, supported_formats, impl->separable);
if (shader.handle != 0) {
impl->program_cache.emplace(unique_identifier, std::move(shader));
} else {
LOG_ERROR(Frontend, "Failed to link Precompiled program!");
compilation_failed = true;
break;
}
if (callback) {
callback(VideoCore::LoadCallbackStage::Decompile, ++i, dump_map.size());
}
}
};
if (impl->separable) {
LoadPrecompiledShader(0, raws.size(), raws, decompiled, dumps); LoadPrecompiledShader(0, raws.size(), raws, decompiled, dumps);
} else {
LoadPrecompiledProgram(decompiled, dumps);
}
bool load_all_raws = false; bool load_all_raws = false;
if (compilation_failed) { if (compilation_failed) {
@@ -539,11 +421,6 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
precompiled_cache_altered = true; precompiled_cache_altered = true;
load_all_raws = true; load_all_raws = true;
} }
// TODO(SachinV): Skip loading raws until we implement a proper way to link non-seperable
// shaders.
if (!impl->separable) {
return;
}
const std::size_t load_raws_size = load_all_raws ? raws.size() : load_raws_index.size(); const std::size_t load_raws_size = load_all_raws ? raws.size() : load_raws_index.size();
@@ -570,25 +447,25 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading,
GLuint handle{0}; GLuint handle{0};
std::string code; std::string code;
// Otherwise decompile and build the shader at boot and save the result to the // Otherwise decompile and build the shader at boot and save the result to the
// precompiled file // precompiled file.
if (raw.GetProgramType() == ProgramType::VS) { if (raw.GetProgramType() == ProgramType::VS) {
auto [conf, setup] = BuildVSConfigFromRaw(raw, driver); const auto [conf, setup] = BuildVSConfigFromRaw(raw, driver);
code = GLSL::GenerateVertexShader(setup, conf, impl->separable); code = GLSL::GenerateVertexShader(setup, conf, true);
OGLShaderStage stage{impl->separable}; OGLProgram program{};
stage.Create(code.c_str(), GL_VERTEX_SHADER); program.Create(code, GL_VERTEX_SHADER);
handle = stage.GetHandle(); handle = program.handle;
sanitize_mul = conf.state.sanitize_mul; sanitize_mul = conf.state.sanitize_mul;
std::scoped_lock lock(mutex); std::scoped_lock lock(mutex);
impl->programmable_vertex_shaders.Inject(conf, code, std::move(stage)); impl->programmable_vertex_shaders.Inject(conf, code, std::move(program));
} else if (raw.GetProgramType() == ProgramType::FS) { } else if (raw.GetProgramType() == ProgramType::FS) {
PicaFSConfig conf(raw.GetRawShaderConfig(), false, driver.IsOpenGLES(), false, PicaFSConfig conf(raw.GetRawShaderConfig(), false, driver.IsOpenGLES(), false,
driver.HasBlendMinMaxFactor()); driver.HasBlendMinMaxFactor());
code = GLSL::GenerateFragmentShader(conf, impl->separable); code = GLSL::GenerateFragmentShader(conf, true);
OGLShaderStage stage{impl->separable}; OGLProgram program{};
stage.Create(code.c_str(), GL_FRAGMENT_SHADER); program.Create(code, GL_FRAGMENT_SHADER);
handle = stage.GetHandle(); handle = program.handle;
std::scoped_lock lock(mutex); std::scoped_lock lock(mutex);
impl->fragment_shaders.Inject(conf, std::move(stage)); impl->fragment_shaders.Inject(conf, std::move(program));
} else { } else {
// Unsupported shader type got stored somehow so nuke the cache // Unsupported shader type got stored somehow so nuke the cache
LOG_ERROR(Frontend, "failed to load raw ProgramType {}", raw.GetProgramType()); LOG_ERROR(Frontend, "failed to load raw ProgramType {}", raw.GetProgramType());

View File

@@ -33,22 +33,29 @@ enum UniformBindings {
/// A class that manage different shader stages and configures them with given config data. /// A class that manage different shader stages and configures them with given config data.
class ShaderProgramManager { class ShaderProgramManager {
public: public:
ShaderProgramManager(Frontend::EmuWindow& emu_window, const Driver& driver, bool separable); explicit ShaderProgramManager(Frontend::EmuWindow& emu_window, const Driver& driver);
~ShaderProgramManager(); ~ShaderProgramManager();
/// Loads the pipeline cache stored to disk.
void LoadDiskCache(const std::atomic_bool& stop_loading, void LoadDiskCache(const std::atomic_bool& stop_loading,
const VideoCore::DiskResourceLoadCallback& callback); const VideoCore::DiskResourceLoadCallback& callback);
/// Binds a PICA decompiled vertex shader.
bool UseProgrammableVertexShader(const Pica::Regs& config, Pica::Shader::ShaderSetup& setup); bool UseProgrammableVertexShader(const Pica::Regs& config, Pica::Shader::ShaderSetup& setup);
/// Binds a passthrough vertex shader.
void UseTrivialVertexShader(); void UseTrivialVertexShader();
/// Binds a passthrough geometry shader.
void UseFixedGeometryShader(const Pica::Regs& regs); void UseFixedGeometryShader(const Pica::Regs& regs);
/// Binds no geometry shader.
void UseTrivialGeometryShader(); void UseTrivialGeometryShader();
/// Binds a fragment shader generated from PICA state.
void UseFragmentShader(const Pica::Regs& config, bool use_normal); void UseFragmentShader(const Pica::Regs& config, bool use_normal);
/// Binds current shader state to provided OpenGLState.
void ApplyTo(OpenGLState& state); void ApplyTo(OpenGLState& state);
private: private:

View File

@@ -13,10 +13,9 @@
namespace OpenGL { namespace OpenGL {
GLuint LoadShader(std::string_view source, GLenum type) { std::string_view GetPreamble() {
std::string preamble;
if (GLES) { if (GLES) {
preamble = R"(#version 320 es return R"(#version 320 es
#if defined(GL_ANDROID_extension_pack_es31a) #if defined(GL_ANDROID_extension_pack_es31a)
#extension GL_ANDROID_extension_pack_es31a : enable #extension GL_ANDROID_extension_pack_es31a : enable
@@ -26,9 +25,12 @@ GLuint LoadShader(std::string_view source, GLenum type) {
#extension GL_EXT_clip_cull_distance : enable #extension GL_EXT_clip_cull_distance : enable
#endif // defined(GL_EXT_clip_cull_distance) #endif // defined(GL_EXT_clip_cull_distance)
)"; )";
} else {
preamble = "#version 430 core\n";
} }
return "#version 430 core\n";
}
GLuint LoadShader(std::string_view source, GLenum type) {
const auto preamble = GetPreamble();
std::string_view debug_type; std::string_view debug_type;
switch (type) { switch (type) {
@@ -72,11 +74,9 @@ GLuint LoadShader(std::string_view source, GLenum type) {
return shader_id; return shader_id;
} }
GLuint LoadProgram(bool separable_program, std::span<const GLuint> shaders) { GLuint LoadProgram(std::span<const GLuint> shaders) {
// Link the program
LOG_DEBUG(Render_OpenGL, "Linking program..."); LOG_DEBUG(Render_OpenGL, "Linking program...");
const GLuint program_id = glCreateProgram();
GLuint program_id = glCreateProgram();
for (GLuint shader : shaders) { for (GLuint shader : shaders) {
if (shader != 0) { if (shader != 0) {
@@ -84,10 +84,6 @@ GLuint LoadProgram(bool separable_program, std::span<const GLuint> shaders) {
} }
} }
if (separable_program) {
glProgramParameteri(program_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
}
glProgramParameteri(program_id, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE); glProgramParameteri(program_id, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
glLinkProgram(program_id); glLinkProgram(program_id);

View File

@@ -9,6 +9,11 @@
namespace OpenGL { namespace OpenGL {
/**
* Utility function to retrieve the preamble to compile an OpenGL GLSL shader
*/
std::string_view GetPreamble();
/** /**
* Utility function to create and compile an OpenGL GLSL shader * Utility function to create and compile an OpenGL GLSL shader
* @param source String of the GLSL shader program * @param source String of the GLSL shader program
@@ -22,6 +27,6 @@ GLuint LoadShader(std::string_view source, GLenum type);
* @param shaders ID of shaders to attach to the program * @param shaders ID of shaders to attach to the program
* @returns Handle of the newly created OpenGL program object * @returns Handle of the newly created OpenGL program object
*/ */
GLuint LoadProgram(bool separable_program, std::span<const GLuint> shaders); GLuint LoadProgram(std::span<const GLuint> shaders);
} // namespace OpenGL } // namespace OpenGL

View File

@@ -59,6 +59,7 @@ OpenGLState::OpenGLState() {
texture_buffer_lut_lf.texture_buffer = 0; texture_buffer_lut_lf.texture_buffer = 0;
texture_buffer_lut_rg.texture_buffer = 0; texture_buffer_lut_rg.texture_buffer = 0;
texture_buffer_lut_rgba.texture_buffer = 0; texture_buffer_lut_rgba.texture_buffer = 0;
color_buffer.texture_2d = 0;
image_shadow_buffer = 0; image_shadow_buffer = 0;
image_shadow_texture_px = 0; image_shadow_texture_px = 0;

View File

@@ -151,7 +151,7 @@ void RendererOpenGL::RenderScreenshot() {
state.Apply(); state.Apply();
glDeleteRenderbuffers(1, &renderbuffer); 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/logging/log.h"
#include "common/microprofile.h" #include "common/microprofile.h"
#include "common/settings.h" #include "common/settings.h"
#include "common/texture.h"
#include "core/core.h" #include "core/core.h"
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
#include "core/hw/gpu.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_frag_spv.h"
#include "video_core/host_shaders/vulkan_present_interlaced_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 "video_core/host_shaders/vulkan_present_vert_spv.h"
#include "vulkan/vulkan_format_traits.hpp"
#include <vk_mem_alloc.h> #include <vk_mem_alloc.h>
@@ -867,20 +869,9 @@ void RendererVulkan::RenderScreenshot() {
const u32 width = layout.width; const u32 width = layout.width;
const u32 height = layout.height; const u32 height = layout.height;
const vk::ImageCreateInfo staging_image_info = { const vk::BufferCreateInfo staging_buffer_info = {
.imageType = vk::ImageType::e2D, .size = width * height * 4,
.format = vk::Format::eB8G8R8A8Unorm, .usage = vk::BufferUsageFlagBits::eTransferDst,
.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 VmaAllocationCreateInfo alloc_create_info = { const VmaAllocationCreateInfo alloc_create_info = {
@@ -893,18 +884,18 @@ void RendererVulkan::RenderScreenshot() {
.pUserData = nullptr, .pUserData = nullptr,
}; };
VkImage unsafe_image{}; VkBuffer unsafe_buffer{};
VmaAllocation allocation{}; VmaAllocation allocation{};
VmaAllocationInfo alloc_info; 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, VkResult result = vmaCreateBuffer(instance.GetAllocator(), &unsafe_buffer_info,
&alloc_create_info, &unsafe_image, &allocation, &alloc_info); &alloc_create_info, &unsafe_buffer, &allocation, &alloc_info);
if (result != VK_SUCCESS) [[unlikely]] { if (result != VK_SUCCESS) [[unlikely]] {
LOG_CRITICAL(Render_Vulkan, "Failed allocating texture with error {}", result); LOG_CRITICAL(Render_Vulkan, "Failed allocating texture with error {}", result);
UNREACHABLE(); UNREACHABLE();
} }
vk::Image staging_image{unsafe_image}; vk::Buffer staging_buffer{unsafe_buffer};
Frame frame{}; Frame frame{};
main_window.RecreateFrame(&frame, width, height); main_window.RecreateFrame(&frame, width, height);
@@ -912,9 +903,8 @@ void RendererVulkan::RenderScreenshot() {
DrawScreens(&frame, layout, false); DrawScreens(&frame, layout, false);
scheduler.Record( scheduler.Record(
[width, height, source_image = frame.image, staging_image](vk::CommandBuffer cmdbuf) { [width, height, source_image = frame.image, staging_buffer](vk::CommandBuffer cmdbuf) {
const std::array read_barriers = { const vk::ImageMemoryBarrier read_barrier = {
vk::ImageMemoryBarrier{
.srcAccessMask = vk::AccessFlagBits::eMemoryWrite, .srcAccessMask = vk::AccessFlagBits::eMemoryWrite,
.dstAccessMask = vk::AccessFlagBits::eTransferRead, .dstAccessMask = vk::AccessFlagBits::eTransferRead,
.oldLayout = vk::ImageLayout::eTransferSrcOptimal, .oldLayout = vk::ImageLayout::eTransferSrcOptimal,
@@ -929,26 +919,8 @@ void RendererVulkan::RenderScreenshot() {
.baseArrayLayer = 0, .baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS, .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,
},
},
}; };
const std::array write_barriers = { const vk::ImageMemoryBarrier write_barrier = {
vk::ImageMemoryBarrier{
.srcAccessMask = vk::AccessFlagBits::eTransferRead, .srcAccessMask = vk::AccessFlagBits::eTransferRead,
.dstAccessMask = vk::AccessFlagBits::eMemoryWrite, .dstAccessMask = vk::AccessFlagBits::eMemoryWrite,
.oldLayout = vk::ImageLayout::eTransferSrcOptimal, .oldLayout = vk::ImageLayout::eTransferSrcOptimal,
@@ -963,64 +935,35 @@ void RendererVulkan::RenderScreenshot() {
.baseArrayLayer = 0, .baseArrayLayer = 0,
.layerCount = VK_REMAINING_ARRAY_LAYERS, .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,
},
},
}; };
static constexpr vk::MemoryBarrier memory_write_barrier = { static constexpr vk::MemoryBarrier memory_write_barrier = {
.srcAccessMask = vk::AccessFlagBits::eMemoryWrite, .srcAccessMask = vk::AccessFlagBits::eMemoryWrite,
.dstAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite, .dstAccessMask = vk::AccessFlagBits::eMemoryRead | vk::AccessFlagBits::eMemoryWrite,
}; };
const std::array src_offsets = { const vk::BufferImageCopy image_copy = {
vk::Offset3D{0, 0, 0}, .bufferOffset = 0,
vk::Offset3D{static_cast<s32>(width), static_cast<s32>(height), 1}, .bufferRowLength = 0,
}; .bufferImageHeight = 0,
.imageSubresource =
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, .aspectMask = vk::ImageAspectFlagBits::eColor,
.mipLevel = 0, .mipLevel = 0,
.baseArrayLayer = 0, .baseArrayLayer = 0,
.layerCount = 1, .layerCount = 1,
}, },
.srcOffsets = src_offsets, .imageOffset = {0, 0, 0},
.dstSubresource{ .imageExtent = {width, height, 1},
.aspectMask = vk::ImageAspectFlagBits::eColor,
.mipLevel = 0,
.baseArrayLayer = 0,
.layerCount = 1,
},
.dstOffsets = dst_offsets,
}; };
cmdbuf.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, cmdbuf.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands,
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eTransfer,
vk::DependencyFlagBits::eByRegion, {}, {}, read_barriers); vk::DependencyFlagBits::eByRegion, {}, {}, read_barrier);
cmdbuf.blitImage(source_image, vk::ImageLayout::eTransferSrcOptimal, staging_image, cmdbuf.copyImageToBuffer(source_image, vk::ImageLayout::eTransferSrcOptimal,
vk::ImageLayout::eTransferDstOptimal, blit_area, vk::Filter::eNearest); staging_buffer, image_copy);
cmdbuf.pipelineBarrier( cmdbuf.pipelineBarrier(
vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eAllCommands, 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 // Ensure the copy is fully completed before saving the screenshot
@@ -1028,27 +971,16 @@ void RendererVulkan::RenderScreenshot() {
const vk::Device device = instance.GetDevice(); 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 // Copy backing image data to the QImage screenshot buffer
const u8* data = reinterpret_cast<const u8*>(alloc_info.pMappedData); std::memcpy(settings.screenshot_bits, alloc_info.pMappedData, staging_buffer_info.size);
std::memcpy(settings.screenshot_bits, data + subresource_layout.offset,
subresource_layout.size);
// Destroy allocated resources // Destroy allocated resources
vmaDestroyBuffer(instance.GetAllocator(), unsafe_buffer, allocation);
vmaDestroyImage(instance.GetAllocator(), frame.image, frame.allocation); vmaDestroyImage(instance.GetAllocator(), frame.image, frame.allocation);
device.destroyFramebuffer(frame.framebuffer); device.destroyFramebuffer(frame.framebuffer);
device.destroyImageView(frame.image_view); device.destroyImageView(frame.image_view);
settings.screenshot_complete_callback(); settings.screenshot_complete_callback(false);
} }
} // namespace Vulkan } // namespace Vulkan

View File

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

View File

@@ -1562,7 +1562,7 @@ DebugScope::DebugScope(TextureRuntime& runtime, Common::Vec4f color, std::string
if (!has_debug_tool) { if (!has_debug_tool) {
return; return;
} }
scheduler.Record([color, label](vk::CommandBuffer cmdbuf) { scheduler.Record([color, label = std::string(label)](vk::CommandBuffer cmdbuf) {
const vk::DebugUtilsLabelEXT debug_label = { const vk::DebugUtilsLabelEXT debug_label = {
.pLabelName = label.data(), .pLabelName = label.data(),
.color = std::array{color[0], color[1], color[2], color[3]}, .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; 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) { switch (address_register_index) {
case 1: // address offset 1 case 1:
movaps(dest, xword[src_ptr + ADDROFFS_REG_0 + src_offset_disp]); address_reg = ADDROFFS_REG_0;
break; break;
case 2: // address offset 2 case 2:
movaps(dest, xword[src_ptr + ADDROFFS_REG_1 + src_offset_disp]); address_reg = ADDROFFS_REG_1;
break; break;
case 3: // address offset 3 case 3:
movaps(dest, xword[src_ptr + LOOPCOUNT_REG.cvt64() + src_offset_disp]); address_reg = LOOPCOUNT_REG.cvt64();
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
break; 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 { } else {
// Load the source // Load the source
movaps(dest, xword[src_ptr + src_offset_disp]); 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 // Move and sign-extend high 32 bits
shr(rax, 32); shr(rax, 32);
movsxd(ADDROFFS_REG_1, eax); 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 { } else {
if (swiz.DestComponentEnabled(0)) { if (swiz.DestComponentEnabled(0)) {
// Move and sign-extend low 32 bits // Move and sign-extend low 32 bits
movsxd(ADDROFFS_REG_0, eax); 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)) { } else if (swiz.DestComponentEnabled(1)) {
// Move and sign-extend high 32 bits // Move and sign-extend high 32 bits
shr(rax, 32); shr(rax, 32);
movsxd(ADDROFFS_REG_1, eax); 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()); mov(byte[STATE + offsetof(UnitState, conditional_code[1])], COND1.cvt8());
// Save address/loop registers // 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[0])], ADDROFFS_REG_0.cvt32());
mov(dword[STATE + offsetof(UnitState, address_registers[1])], ADDROFFS_REG_1.cvt32()); mov(dword[STATE + offsetof(UnitState, address_registers[1])], ADDROFFS_REG_1.cvt32());
mov(dword[STATE + offsetof(UnitState, address_registers[2])], LOOPCOUNT_REG); 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); std::size_t offset = Uniforms::GetIntUniformOffset(instr.flow_control.int_uniform_id);
mov(LOOPCOUNT, dword[UNIFORMS + offset]); mov(LOOPCOUNT, dword[UNIFORMS + offset]);
mov(LOOPCOUNT_REG, LOOPCOUNT); mov(LOOPCOUNT_REG, LOOPCOUNT);
shr(LOOPCOUNT_REG, 4); shr(LOOPCOUNT_REG, 8);
and_(LOOPCOUNT_REG, 0xFF0); // Y-component is the start and_(LOOPCOUNT_REG, 0xFF); // Y-component is the start
mov(LOOPINC, LOOPCOUNT); mov(LOOPINC, LOOPCOUNT);
shr(LOOPINC, 12); shr(LOOPINC, 16);
and_(LOOPINC, 0xFF0); // Z-component is the incrementer and_(LOOPINC, 0xFF); // Z-component is the incrementer
movzx(LOOPCOUNT, LOOPCOUNT.cvt8()); // X-component is iteration count movzx(LOOPCOUNT, LOOPCOUNT.cvt8()); // X-component is iteration count
add(LOOPCOUNT, 1); // Iteration count is X-component + 1 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_0, dword[STATE + offsetof(UnitState, address_registers[0])]);
movsxd(ADDROFFS_REG_1, dword[STATE + offsetof(UnitState, address_registers[1])]); movsxd(ADDROFFS_REG_1, dword[STATE + offsetof(UnitState, address_registers[1])]);
mov(LOOPCOUNT_REG, dword[STATE + offsetof(UnitState, address_registers[2])]); 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 // Load conditional code
mov(COND0, byte[STATE + offsetof(UnitState, conditional_code[0])]); mov(COND0, byte[STATE + offsetof(UnitState, conditional_code[0])]);