Merge branch 'main' into add_keyboard_keymapping

This commit is contained in:
Vasyl_Baran 2024-08-23 13:38:55 +03:00 committed by GitHub
commit beef42c8ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
52 changed files with 468 additions and 2194 deletions

26
.gitmodules vendored
View File

@ -1,66 +1,84 @@
[submodule "externals/discord-rpc"]
path = externals/discord-rpc
url = https://github.com/shadps4-emu/ext-discord-rpc.git
[submodule "externals/cryptopp-cmake"]
path = externals/cryptopp-cmake
url = https://github.com/shadps4-emu/ext-cryptopp-cmake.git
shallow = true
[submodule "externals/cryptopp"]
path = externals/cryptopp
url = https://github.com/shadps4-emu/ext-cryptopp.git
shallow = true
[submodule "externals/cryptoppwin"]
path = externals/cryptoppwin
url = https://github.com/shadps4-emu/ext-cryptoppwin.git
shallow = true
[submodule "externals/zlib-ng"]
path = externals/zlib-ng
url = https://github.com/shadps4-emu/ext-zlib-ng.git
shallow = true
[submodule "externals/sdl3"]
path = externals/sdl3
url = https://github.com/shadps4-emu/ext-SDL.git
shallow = true
[submodule "externals/fmt"]
path = externals/fmt
url = https://github.com/shadps4-emu/ext-fmt.git
shallow = true
[submodule "externals/vulkan-headers"]
path = externals/vulkan-headers
url = https://github.com/KhronosGroup/Vulkan-Headers.git
shallow = true
[submodule "externals/vma"]
path = externals/vma
url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
shallow = true
[submodule "externals/glslang"]
path = externals/glslang
url = https://github.com/KhronosGroup/glslang.git
shallow = true
[submodule "externals/robin-map"]
path = externals/robin-map
url = https://github.com/Tessil/robin-map.git
shallow = true
[submodule "externals/xbyak"]
path = externals/xbyak
url = https://github.com/herumi/xbyak.git
shallow = true
[submodule "externals/winpthreads"]
path = externals/winpthreads
url = https://github.com/shadps4-emu/winpthreads.git
shallow = true
[submodule "externals/magic_enum"]
path = externals/magic_enum
url = https://github.com/Neargye/magic_enum.git
shallow = true
[submodule "externals/toml11"]
path = externals/toml11
url = https://github.com/ToruNiina/toml11.git
shallow = true
[submodule "externals/zydis"]
path = externals/zydis
url = https://github.com/zyantific/zydis.git
shallow = true
[submodule "externals/sirit"]
path = externals/sirit
url = https://github.com/shadps4-emu/sirit.git
shallow = true
[submodule "externals/xxhash"]
path = externals/xxhash
url = https://github.com/Cyan4973/xxHash.git
shallow = true
[submodule "externals/tracy"]
path = externals/tracy
url = https://github.com/shadps4-emu/tracy.git
shallow = true
[submodule "externals/ext-boost"]
path = externals/ext-boost
url = https://github.com/shadps4-emu/ext-boost.git
shallow = true
[submodule "externals/date"]
path = externals/date
url = https://github.com/HowardHinnant/date.git
shallow = true
[submodule "externals/ffmpeg-core"]
path = externals/ffmpeg-core
url = https://github.com/shadps4-emu/ext-ffmpeg-core
url = https://github.com/shadps4-emu/ext-ffmpeg-core.git
shallow = true

View File

@ -223,21 +223,7 @@ set(VIDEOOUT_LIB src/core/libraries/videoout/buffer.h
src/core/libraries/videoout/video_out.h
)
set(LIBC_SOURCES src/core/libraries/libc/libc.cpp
src/core/libraries/libc/libc.h
src/core/libraries/libc/printf.h
src/core/libraries/libc/va_ctx.h
src/core/libraries/libc/libc_cxa.cpp
src/core/libraries/libc/libc_cxa.h
src/core/libraries/libc/libc_stdio.cpp
src/core/libraries/libc/libc_stdio.h
src/core/libraries/libc/libc_math.cpp
src/core/libraries/libc/libc_math.h
src/core/libraries/libc/libc_string.cpp
src/core/libraries/libc/libc_string.h
src/core/libraries/libc/libc_stdlib.cpp
src/core/libraries/libc/libc_stdlib.h
src/core/libraries/libc_internal/libc_internal.cpp
set(LIBC_SOURCES src/core/libraries/libc_internal/libc_internal.cpp
src/core/libraries/libc_internal/libc_internal.h
)
@ -276,6 +262,7 @@ set(NP_LIBS src/core/libraries/np_manager/np_manager.cpp
src/core/libraries/np_trophy/np_trophy.cpp
src/core/libraries/np_trophy/np_trophy.h
)
set(MISC_LIBS src/core/libraries/screenshot/screenshot.cpp
src/core/libraries/screenshot/screenshot.h
)
@ -425,7 +412,6 @@ set(SHADER_RECOMPILER src/shader_recompiler/exception.h
src/shader_recompiler/backend/spirv/spirv_emit_context.h
src/shader_recompiler/frontend/translate/data_share.cpp
src/shader_recompiler/frontend/translate/export.cpp
src/shader_recompiler/frontend/translate/flat_memory.cpp
src/shader_recompiler/frontend/translate/scalar_alu.cpp
src/shader_recompiler/frontend/translate/scalar_memory.cpp
src/shader_recompiler/frontend/translate/translate.cpp

View File

@ -91,6 +91,10 @@ Check the build instructions for [**Linux**](https://github.com/shadps4-emu/shad
|macOS Qt Build|[![macOS-qt](https://github.com/shadps4-emu/shadPS4/actions/workflows/macos-qt.yml/badge.svg)](https://github.com/shadps4-emu/shadPS4/actions/workflows/macos-qt.yml)
</details>
# Debugging and reporting issues
For more information on how to test, debug and report issues with the emulator or games, read the [Debugging documentation](https://github.com/shadps4-emu/shadPS4/blob/main/documents/Debugging/Debugging.md).
# Keyboard Mapping
| Controller button | Keyboard |

View File

@ -0,0 +1,156 @@
<!--
SPDX-FileCopyrightText: 2024 shadPS4 Emulator Project
SPDX-License-Identifier: GPL-2.0-or-later
-->
# Debugging and reporting issues about shadPS4 and games
This document covers information about debugging, troubleshooting and reporting developer-side issues related to shadPS4 and games.
## Setup
This section will guide you through setting up tools for debugging the emulator. This list will likely expand as more tools and platforms receive consistent setups.
<details>
<summary>Windows and Visual Studio</summary>
Make sure you have the project set up for building on Windows with Visual Studio and CMake: [Build shadPS4 for Windows
](https://github.com/shadps4-emu/shadPS4/blob/main/documents/building-windows.md)
1. Open the project folder in Visual Studio **as a folder**. _Do not run `cmake ..` or other commands that set up the project._
2. In the Solution Explorer, click the **Switch between solutions and available views** button.\
![image](https://github.com/user-attachments/assets/4e2be2b1-ba5a-4451-9ab2-f4ecf246213d)
3. Double-click on **CMake Targets View**.\
![image](https://github.com/user-attachments/assets/5ce7cf90-cd61-4cfa-bef5-645909827290)
4. Under **shadPS4 Project**, right-click on the **shadps4 (executable)** solution and click **Set as Startup Item**. This will let you start and debug shadPS4 using the VS debug buttons, as well as the default F5 shortcut.\
![image](https://github.com/user-attachments/assets/34c7c047-28a3-499f-be8f-df781134d104)
5. Right-click the **shadps4 (executable)** solution once more and click **Add debug configuration**.
6. Add an `"args: []"` section into the first `configurations` entry.\
List your game path as an argument, as if you were launching the non-GUI emulator from the command line.
![image](https://github.com/user-attachments/assets/8c7c3e69-f38f-4d6b-bdfd-4f1c41c50be7)
7. Set the appropriate CMake configuration for debugging or testing.
- For debugging the emulator and games within it, select `x64-Clang-Debug`.
- For testing the emulator with compiler optimizations as a release build, it is recommended to select `x64-Clang-RelWithDebInfo`,
as debug symbols will still be generated in case you encounter release configuration-exclusive bugs/errors.
![image](https://github.com/user-attachments/assets/0d975f7a-7bea-4f89-87ef-5d685bea4381)
Launch and debug the emulator through **Debug > Start Debugging** (F5 by default), or **Debug > Start Without Debugging** (Ctrl+F5 by default) when testing games for performance.
</details>
## Configuration
You can configure the emulator by editing the `config.toml` file found in the `user` folder created after starting the application.
<details>
<summary>Some configuration entries worth changing</summary>
- `[General]`
- `logType`: Configures logging synchronization (`sync`/`async`)
- By default, the emulator logs messages asynchronously for better performance. Some log messages may end up being received out-of-order.
- It can be beneficial to set this to `sync` in order for the log to accurately maintain message order, at the cost of performance.
- When communicating about issues with games and the log messages aren't clear due to potentially confusing order, set this to `sync` and send that log as well.
- `logFilter`: Sets the logging category for various logging classes.
- Format: `<class>:<level> ...`
- Multiple classes can be set by separating them with a space. (example: `Render:Warning Debug:Critical Lib.Pad:Error`)
- Sub-classes can be specified in the same format as seen in the console/log (such as `Core.Linker`).
- All classes and sub-classes can be set by specifying a `*` symbol. (example: `Kernel.*:Critical`)
- Valid log levels: `Trace, Debug, Info, Warning, Error, Critical` - in this order, setting a level silences all levels preceding it and logs every level after it.
- Examples:
- If the log is being spammed with messages coming from Lib.Pad, you can use `Lib.Pad:Critical` to only log critical-level messages.
- If you'd like to mute everything, but still want to receive messages from Vulkan rendering: `*:Critical Render.Vulkan:Info`
- `Fullscreen`: Display the game in a full screen borderless window.
- `[GPU]`
- `dumpShaders`: Dump shaders that are loaded by the emulator. Dump path: `../user/shader/dumps`
- `nullGpu`: Disables rendering.
- `screenWidth` and `screenHeight`: Configures the game window width and height.
- `[Vulkan]`
- `validation`-related settings: Use when debugging Vulkan.
- `rdocEnable`: Automatically hook RenderDoc when installed. Useful for debugging shaders and game rendering.
- `rdocMarkersEnable`: Enable automatic RenderDoc event annotation
- `[LLE]`
- `libc`: Use LLE with `libc`.
</details>
## Quick analysis
This section will provide some preliminary steps to take and tips on what to do when you encounter scenarios that require debugging.
<details open>
<summary>When a game crashes and breaks in the debugger</summary>
1. Analyze the log
- A console will open by default when you launch the emulator. It shows the same log messages that go into the log file found at `<emulator executable>/user/log/shad_log.txt`.
- It is recommended that you start analyzing the log bottom-up first:
- Are there any critical or error-level messages at the end of the log that would point to a reason for the game crashing?
- Do any of the last few messages contain information about the game loading files?
- Did the game window draw anything on-screen?
- Continue analyzing the log from the start to see other errors (such as with initialization, memory mapping, linker errors etc.)
2. Analyze the stack trace
- When the emulator is launched through a debugger, it will **break** when an exception or violation is encountered.\
_(**breaking** in this context means pausing execution of the program before it continues or stops altogether.
Breaks can be intentional as well - these are set with various kinds of **breakpoints**.)_
- Default setups of most debuggers include a **Stack trace** window/panel that lists the functions the program has called before breaking.
- The stack trace entries can be navigated to and will show the relevant function, as well as switch to the state that the program was in at the time of execution.\
Use the **Locals** and **Watch** windows to investigate variables and other code in these contexts.
3. Identify the reason for the crash
- **Logs aren't always accurate in determining the reason for a crash.**\
Some log entries are reported as errors but may not be fatal for the execution to stop. `Critical` entries are most likely to be the cause for crashes.
- Pinpoint the area of the emulator where the crash occured\
If the stack trace ends with functions that are relevant to rendering, it is safe to assume that the issue is with **rendering**.\
Similarly, if a crash is in a library responsible for playing videos, your issue can be narrowed down to the scope of video playback in the emulator.
- **⚠ Some crashes are intentional**
- If you identify **Access violations for writing operations** where the function is (or in cases of game libraries, _looks like_ it is) copying memory,
it most likely is an **intentional exception** meant to catch game data being written by the game.
This is used by the emulator developers to identify procedures that have to do with game data changing.
- Debugging tools usually include an option to not break on certain types of exceptions. **Exclude access violations and other intentional exceptions when debugging to skip these exceptions.**
- You can also identify such cases if the game works in Release builds of the emulator. These intentional exceptions are development-time only.
- Attempt to **Continue** and observe whether the stack trace and/or variables and registers change when you encounter exceptions.
</details>
## Reporting and communicating about issues
When communicating with the project about game-specific issues, specify an **uniquely identifable game name** along with its `CUSA-xxxxx` code that is specific to the region/variant of the game you're testing.\
The version number is also important to add at least in the description, especially if you can verify that the game behaves differently across versions.\
Accurately identifying games will help other developers that own that game recognize your issue by its title and jump in to help test and debug it.
- Examples of good naming schemes:
- Amplitude (2016) `CUSA02480`
- Rock Band 4 (`CUSA02084`) v1.0
- inFamous: Second Son \[`CUSA-00004`\]
- Examples of unideal naming schemes:
- _The Witness_
- _GTA 5_
- _Watch Dogs_
- If your issue is small or you aren't sure whether you have properly identified something, [join the Discord server](https://discord.gg/MyZRaBngxA) and use the #development channel
to concisely explain the issue, as well as any findings you currently have.
- It is recommended that you check the [game compatibility issue tracker](https://github.com/shadps4-emu/shadps4-game-compatibility/issues) and post very short summaries of progress changes there,
(such as the game now booting into the menu or getting in-game) for organizational and status update purposes.
- ⚠ **Do not post theoretical, unproven game-specific issues in the emulator issue tracker that you cannot verify and locate in the emulator source code as being a bug.**\
Do, however, add information about the game you experienced the issue in, so that it can be tested in a reproducible environment.
- Good example: "_Crash in `Shader::Gcn::CFG::EmitBlocks()`, out of bounds list access_" -> _issue description shares stack trace, points to code in the repository and provides relevant information_
- Bad example: "_Amplitude crashes on boot, access violation_" -> _issue description reiterates title, focuses on the game instead of the emulator and refuses to elaborate_

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

View File

@ -58,4 +58,24 @@ To install PKG files (game and updates), you will need the Qt application (with
## Configure the emulator
You can configure the emulator in the "user" folder (created after the first start of the application) then in the "config.toml" file. Here you can find lots of parameters to set with True or False.
You can configure the emulator by editing the `config.toml` file found in the `user` folder created after starting the application.\
Some settings may be related to more technical development and debugging. For more information on those, see [Debugging](https://github.com/shadps4-emu/shadPS4/blob/main/documents/Debugging/Debugging.md#configuration).
Here's a list of configuration entries that are worth changing:
- `[General]`
- `Fullscreen`: Display the game in a full screen borderless window.
- `logType`: Configures logging synchronization (`sync`/`async`)
- It can be beneficial to set this to `sync` in order for the log to accurately maintain message order, at the cost of performance.
- Use when sending logs to developers. See more about [reporting issues](https://github.com/shadps4-emu/shadPS4/blob/main/documents/Debugging/Debugging.md#reporting-and-communicating-about-issues).
- `logFilter`: Sets the logging category for various logging classes.
- Format: `<class>:<level> ...`, `<class.*>:<level> <*:level> ...`
- Valid log levels: `Trace, Debug, Info, Warning, Error, Critical` - in this order, setting a level silences all levels preceding it and logs every level after it.
- Examples:
- If the log is being spammed with messages coming from Lib.Pad, you can use `Lib.Pad:Critical` to only log critical-level messages.
- If you'd like to mute everything, but still want to receive messages from Vulkan rendering: `*:Error Render.Vulkan:Info`
- `[GPU]`
- `screenWidth` and `screenHeight`: Configures the game window width and height.

View File

@ -1,32 +1,44 @@
v0.2.0 15/08/2024 - codename validptr
=================
- Adding macOS support
- Big shader recompiler improvements
- Core improvements
- GUI improvements
v0.1.0 01/07/2024 - codename madturtle
=================
- Added a shader recompiler, with this we have a lot of games that starts to work
- Rewrote a big part of core
v0.0.3 23/03/2024 - codename salad
=================
-Switching to std::thread
-Use unique_ptr where possible
-Replace printf/scanf with type safe fmt
-Implemented sceKernelGetProcessTime
-Implemented sceKernelGetProcessTimeCounter , sceKernelGetProcessTimeCounterFrequency
-Pause emu with P button
-Timers rewrote with std::chrono
-Added sceSystemServiceGetStatus
-Initial FileSystem implementation
-Initial TLS work
-New logging implementation
-Some functions implemented for userService,systemService
-Added sceAudioOut module and output using sdl audio
- Switching to std::thread
- Use unique_ptr where possible
- Replace printf/scanf with type safe fmt
- Implemented sceKernelGetProcessTime
- Implemented sceKernelGetProcessTimeCounter, sceKernelGetProcessTimeCounterFrequency
- Pause emu with P button
- Timers rewrote with std::chrono
- Added sceSystemServiceGetStatus
- Initial FileSystem implementation
- Initial TLS work
- New logging implementation
- Some functions implemented for userService, systemService
- Added sceAudioOut module and output using SDL audio
v0.0.2 21/10/2023
=================
-using cstdint header in variable types
-run_main_entry: Rewrite in asm for stack setup
-printf libc implementation for work with sysv_abi
-initial pad emulation (only digital pad atm)
-Implemented sceVideoOutIsFlipPending
-Added auto stubs , now unsupported hle function will resolve as empty stubs
-Rewrote libc_cxa functions
-Libc implementations ( _ZdlPv,_Znwm,rand,_Fsin,qsort,free,strncpy,memmove,atan2f,pow,_Sin)
-ET_SCE_DYNAMIC behaves as valid for execution now.
-Initial FileSystem work (not yet usable).
- Using cstdint header in variable types
- run_main_entry: Rewrite in asm for stack setup
- Printf libc implementation for work with sysv_abi
- Initial pad emulation (only digital pad atm)
- Implemented sceVideoOutIsFlipPending
- Added auto stubs, now unsupported hle function will resolve as empty stubs
- Rewrote libc_cxa functions
- Libc implementations ( _ZdlPv,_Znwm,rand,_Fsin,qsort,free,strncpy,memmove,atan2f,pow,_Sin)
- ET_SCE_DYNAMIC behaves as valid for execution now
- Initial FileSystem work (not yet usable)
v0.0.1 29/09/2023
=================
First public release . Everything is new
First public release. Everything is new.

View File

@ -1,35 +0,0 @@
shadPS4 - A PS4 emulator
=========================
1. Intro
2. Current status
3. Contributors
4. Greetings
1.Intro
=======
shadPS4 is a Play Station 4 emulator for Windows and Linux. Although atm it can't run a lot of stuff, we are working torwards to make it more compatible.
2.Current status
================
shadPS4 is a HLE emulator. Currently on a small amount of functions is emulated, which is one of the reasons compatibility is low.
3.Contributors
==============
- georgemoralis
- raphaelthegreat
- skmp
- wheremyfoodat
4.Greetings
===========
I would like to thank the following people for helping me so far, with coding or moral support.
- wheremyfoodat - or @rodakinos for believed me
- paris - or OFFTKP for not believing me and that made me a better coder :D
- skmp - or kornilios for being good old friend
- PandaBad - our beloved stalker
- emufan4568 - for advices
- velocity - for talking 1-2 times per year on discord server. We miss you velocity
- probably more, will include in the next readme :D

View File

@ -25,11 +25,6 @@ if (NOT TARGET fmt::fmt)
add_subdirectory(fmt)
endif()
# Discord-RPC
set(BUILD_EXAMPLES OFF CACHE BOOL "")
add_subdirectory(discord-rpc)
target_include_directories(discord-rpc INTERFACE ./discord-rpc/include)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND MSVC)
# If it is clang and MSVC we will add a static lib
# CryptoPP

@ -1 +0,0 @@
Subproject commit 4ec218155d73bcb8022f8f7ca72305d801f84beb

View File

@ -18,7 +18,6 @@ static std::string logFilter;
static std::string logType = "async";
static std::string userName = "shadPS4";
static bool isDebugDump = false;
static bool isLibc = true;
static bool isShowSplash = false;
static bool isNullGpu = false;
static bool shouldDumpShaders = false;
@ -50,10 +49,6 @@ std::vector<std::string> m_recent_files;
u32 m_language = 1; // english
std::map<u32, KeysMapping> m_keyboard_binding_map;
bool isLleLibc() {
return isLibc;
}
bool isNeoMode() {
return isNeo;
}
@ -190,15 +185,15 @@ void setNeoMode(bool enable) {
isNeo = enable;
}
void setLogType(std::string type) {
void setLogType(const std::string& type) {
logType = type;
}
void setLogFilter(std::string type) {
void setLogFilter(const std::string& type) {
logFilter = type;
}
void setUserName(std::string type) {
void setUserName(const std::string& type) {
userName = type;
}
@ -235,15 +230,15 @@ void setMainWindowWidth(u32 width) {
void setMainWindowHeight(u32 height) {
m_window_size_H = height;
}
void setPkgViewer(std::vector<std::string> pkgList) {
void setPkgViewer(const std::vector<std::string>& pkgList) {
m_pkg_viewer.resize(pkgList.size());
m_pkg_viewer = pkgList;
}
void setElfViewer(std::vector<std::string> elfList) {
void setElfViewer(const std::vector<std::string>& elfList) {
m_elf_viewer.resize(elfList.size());
m_elf_viewer = elfList;
}
void setRecentFiles(std::vector<std::string> recentFiles) {
void setRecentFiles(const std::vector<std::string>& recentFiles) {
m_recent_files.resize(recentFiles.size());
m_recent_files = recentFiles;
}
@ -363,12 +358,6 @@ void load(const std::filesystem::path& path) {
isDebugDump = toml::find_or<bool>(debug, "DebugDump", false);
}
if (data.contains("LLE")) {
const toml::value& lle = data.at("LLE");
isLibc = toml::find_or<bool>(lle, "libc", true);
}
if (data.contains("GUI")) {
const toml::value& gui = data.at("GUI");
@ -462,7 +451,6 @@ void save(const std::filesystem::path& path) {
data["Vulkan"]["rdocEnable"] = rdocEnable;
data["Vulkan"]["rdocMarkersEnable"] = rdocMarkersEnable;
data["Debug"]["DebugDump"] = isDebugDump;
data["LLE"]["libc"] = isLibc;
data["GUI"]["theme"] = mw_themes;
data["GUI"]["iconSize"] = m_icon_size;
data["GUI"]["sliderPos"] = m_slider_pos;

View File

@ -25,7 +25,6 @@ u32 getScreenHeight();
s32 getGpuId();
bool debugDump();
bool isLleLibc();
bool showSplash();
bool nullGpu();
bool dumpShaders();
@ -46,10 +45,10 @@ void setScreenHeight(u32 height);
void setFullscreenMode(bool enable);
void setLanguage(u32 language);
void setNeoMode(bool enable);
void setUserName(std::string type);
void setUserName(const std::string& type);
void setLogType(std::string type);
void setLogFilter(std::string type);
void setLogType(const std::string& type);
void setLogFilter(const std::string& type);
void setVkValidation(bool enable);
void setVkSyncValidation(bool enable);
@ -70,9 +69,9 @@ void setSliderPositonGrid(u32 pos);
void setTableMode(u32 mode);
void setMainWindowWidth(u32 width);
void setMainWindowHeight(u32 height);
void setPkgViewer(std::vector<std::string> pkgList);
void setElfViewer(std::vector<std::string> elfList);
void setRecentFiles(std::vector<std::string> recentFiles);
void setPkgViewer(const std::vector<std::string>& pkgList);
void setElfViewer(const std::vector<std::string>& elfList);
void setRecentFiles(const std::vector<std::string>& recentFiles);
void setKeyboardBindingMap(std::map<u32, KeysMapping> map);
const std::map<u32, KeysMapping>& getKeyboardBindingMap();

View File

@ -217,7 +217,7 @@ void IOFile::Close() {
file = nullptr;
#ifdef _WIN64
if (file_mapping) {
if (file_mapping && file_access_mode == FileAccessMode::ReadWrite) {
CloseHandle(std::bit_cast<HANDLE>(file_mapping));
}
#endif
@ -259,8 +259,7 @@ uintptr_t IOFile::GetFileMapping() {
mapping = CreateFileMapping2(hfile, NULL, FILE_MAP_WRITE, PAGE_READWRITE, SEC_COMMIT, 0,
NULL, NULL, 0);
} else {
mapping = CreateFileMapping2(hfile, NULL, FILE_MAP_READ, PAGE_READONLY, SEC_COMMIT, 0, NULL,
NULL, 0);
mapping = hfile;
}
file_mapping = std::bit_cast<uintptr_t>(mapping);

View File

@ -94,7 +94,7 @@ namespace Common {
// This function divides a u128 by a u32 value and produces two u64 values:
// the result of division and the remainder
[[nodiscard]] static inline std::pair<u64, u64> Divide128On32(u128 dividend, u32 divisor) {
[[nodiscard]] static inline std::pair<u64, u64> Divide128On32(const u128& dividend, u32 divisor) {
u64 remainder = dividend[0] % divisor;
u64 accum = dividend[0] / divisor;
if (dividend[1] == 0)

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <boost/icl/separate_interval_set.hpp>
#include "common/alignment.h"
#include "common/assert.h"
#include "common/error.h"
#include "core/address_space.h"
@ -129,9 +130,10 @@ struct AddressSpace::Impl {
}
void* Map(VAddr virtual_addr, PAddr phys_addr, size_t size, ULONG prot, uintptr_t fd = 0) {
const size_t aligned_size = Common::AlignUp(size, 16_KB);
const auto it = placeholders.find(virtual_addr);
ASSERT_MSG(it != placeholders.end(), "Cannot map already mapped region");
ASSERT_MSG(virtual_addr >= it->lower() && virtual_addr + size <= it->upper(),
ASSERT_MSG(virtual_addr >= it->lower() && virtual_addr + aligned_size <= it->upper(),
"Map range must be fully contained in a placeholder");
// Windows only allows splitting a placeholder into two.
@ -140,7 +142,7 @@ struct AddressSpace::Impl {
// one at the start and at the end.
const VAddr placeholder_start = it->lower();
const VAddr placeholder_end = it->upper();
const VAddr virtual_end = virtual_addr + size;
const VAddr virtual_end = virtual_addr + aligned_size;
// If the placeholder doesn't exactly start at virtual_addr, split it at the start.
if (placeholder_start != virtual_addr) {
@ -161,11 +163,23 @@ struct AddressSpace::Impl {
void* ptr = nullptr;
if (phys_addr != -1) {
HANDLE backing = fd ? reinterpret_cast<HANDLE>(fd) : backing_handle;
ptr = MapViewOfFile3(backing, process, reinterpret_cast<PVOID>(virtual_addr), phys_addr,
size, MEM_REPLACE_PLACEHOLDER, prot, nullptr, 0);
if (fd && prot == PAGE_READONLY) {
DWORD resultvar;
ptr = VirtualAlloc2(process, reinterpret_cast<PVOID>(virtual_addr), aligned_size,
MEM_RESERVE | MEM_COMMIT | MEM_REPLACE_PLACEHOLDER,
PAGE_READWRITE, nullptr, 0);
bool ret = ReadFile(backing, ptr, size, &resultvar, NULL);
ASSERT_MSG(ret, "ReadFile failed. {}", Common::GetLastErrorMsg());
ret = VirtualProtect(ptr, size, prot, &resultvar);
ASSERT_MSG(ret, "VirtualProtect failed. {}", Common::GetLastErrorMsg());
} else {
ptr = MapViewOfFile3(backing, process, reinterpret_cast<PVOID>(virtual_addr),
phys_addr, aligned_size, MEM_REPLACE_PLACEHOLDER, prot,
nullptr, 0);
}
} else {
ptr =
VirtualAlloc2(process, reinterpret_cast<PVOID>(virtual_addr), size,
VirtualAlloc2(process, reinterpret_cast<PVOID>(virtual_addr), aligned_size,
MEM_RESERVE | MEM_COMMIT | MEM_REPLACE_PLACEHOLDER, prot, nullptr, 0);
}
ASSERT_MSG(ptr, "{}", Common::GetLastErrorMsg());
@ -455,12 +469,12 @@ void* AddressSpace::MapFile(VAddr virtual_addr, size_t size, size_t offset, u32
}
void AddressSpace::Unmap(VAddr virtual_addr, size_t size, VAddr start_in_vma, VAddr end_in_vma,
PAddr phys_base, bool is_exec, bool has_backing) {
PAddr phys_base, bool is_exec, bool has_backing, bool readonly_file) {
#ifdef _WIN32
// There does not appear to be comparable support for partial unmapping on Windows.
// Unfortunately, a least one title was found to require this. The workaround is to unmap
// the entire allocation and remap the portions outside of the requested unmapping range.
impl->Unmap(virtual_addr, size, has_backing);
impl->Unmap(virtual_addr, size, has_backing && !readonly_file);
// TODO: Determine if any titles require partial unmapping support for flexible allocations.
ASSERT_MSG(has_backing || (start_in_vma == 0 && end_in_vma == size),

View File

@ -92,7 +92,7 @@ public:
/// Unmaps specified virtual memory area.
void Unmap(VAddr virtual_addr, size_t size, VAddr start_in_vma, VAddr end_in_vma,
PAddr phys_base, bool is_exec, bool has_backing);
PAddr phys_base, bool is_exec, bool has_backing, bool readonly_file);
void Protect(VAddr virtual_addr, size_t size, MemoryPermission perms);

View File

@ -60,7 +60,7 @@ bool PlaygoFile::LoadChunks(const Common::FS::IOFile& file) {
return false;
}
bool PlaygoFile::load_chunk_data(const Common::FS::IOFile& file, const chunk_t& chunk,
bool PlaygoFile::load_chunk_data(const Common::FS::IOFile& file, const chunk_t chunk,
std::string& data) {
if (file.IsOpen()) {
if (file.Seek(chunk.offset)) {

View File

@ -123,7 +123,7 @@ public:
}
private:
bool load_chunk_data(const Common::FS::IOFile& file, const chunk_t& chunk, std::string& data);
bool load_chunk_data(const Common::FS::IOFile& file, const chunk_t chunk, std::string& data);
private:
PlaygoHeader playgoHeader;

View File

@ -9,7 +9,7 @@ PSF::PSF() = default;
PSF::~PSF() = default;
bool PSF::open(const std::string& filepath, std::vector<u8> psfBuffer) {
bool PSF::open(const std::string& filepath, const std::vector<u8>& psfBuffer) {
if (!psfBuffer.empty()) {
psf.resize(psfBuffer.size());
psf = psfBuffer;

View File

@ -35,7 +35,7 @@ public:
PSF();
~PSF();
bool open(const std::string& filepath, std::vector<u8> psfBuffer);
bool open(const std::string& filepath, const std::vector<u8>& psfBuffer);
std::string GetString(const std::string& key);
u32 GetInteger(const std::string& key);

View File

@ -82,7 +82,7 @@ static s32 CodecTypeToStreamType(AVMediaType codec_type) {
}
}
static f32 AVRationalToF32(const AVRational& rational) {
static f32 AVRationalToF32(const AVRational rational) {
return f32(rational.num) / rational.den;
}
@ -366,6 +366,9 @@ bool AvPlayerSource::GetAudioData(SceAvPlayerFrameInfo& audio_info) {
}
u64 AvPlayerSource::CurrentTime() {
if (!IsActive()) {
return 0;
}
using namespace std::chrono;
return duration_cast<milliseconds>(high_resolution_clock::now() - m_start_time).count();
}

View File

@ -1,496 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstdlib>
#include "common/debug.h"
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/libraries/libc/libc.h"
#include "core/libraries/libc/libc_cxa.h"
#include "core/libraries/libc/libc_math.h"
#include "core/libraries/libc/libc_stdio.h"
#include "core/libraries/libc/libc_stdlib.h"
#include "core/libraries/libc/libc_string.h"
#include "core/libraries/libs.h"
namespace Libraries::LibC {
constexpr bool log_file_libc = true; // disable it to disable logging
static u32 g_need_sceLibc = 1;
using cxa_destructor_func_t = void (*)(void*);
struct CxaDestructor {
cxa_destructor_func_t destructor_func;
void* destructor_object;
void* module_id;
};
struct CContext {
std::vector<CxaDestructor> cxa;
};
static PS4_SYSV_ABI int ps4___cxa_atexit(void (*func)(void*), void* arg, void* dso_handle) {
auto* cc = Common::Singleton<CContext>::Instance();
CxaDestructor c{};
c.destructor_func = func;
c.destructor_object = arg;
c.module_id = dso_handle;
cc->cxa.push_back(c);
return 0;
}
void PS4_SYSV_ABI ps4___cxa_finalize(void* d) {
BREAKPOINT();
}
void PS4_SYSV_ABI ps4___cxa_pure_virtual() {
BREAKPOINT();
}
static PS4_SYSV_ABI void ps4_init_env() {
LOG_INFO(Lib_LibC, "called");
}
static PS4_SYSV_ABI void ps4_catchReturnFromMain(int status) {
LOG_INFO(Lib_LibC, "returned = {}", status);
}
static PS4_SYSV_ABI void ps4__Assert() {
LOG_INFO(Lib_LibC, "called");
BREAKPOINT();
}
PS4_SYSV_ABI void ps4__ZdlPv(void* ptr) {
std::free(ptr);
}
PS4_SYSV_ABI void ps4__ZSt11_Xbad_allocv() {
LOG_INFO(Lib_LibC, "called");
BREAKPOINT();
}
PS4_SYSV_ABI void ps4__ZSt14_Xlength_errorPKc() {
LOG_INFO(Lib_LibC, "called");
BREAKPOINT();
}
PS4_SYSV_ABI void* ps4__Znwm(u64 count) {
if (count == 0) {
LOG_INFO(Lib_LibC, "_Znwm count ={}", count);
BREAKPOINT();
}
void* ptr = std::malloc(count);
return ptr;
}
static constexpr u16 lowercaseTable[256] = {
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B,
0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023,
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B,
0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073,
0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B,
0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, 0x0080, 0x0081, 0x0082, 0x0083,
0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3,
0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB,
0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3,
0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB,
0x00FC, 0x00FD, 0x00FE, 0x00FF,
};
const PS4_SYSV_ABI u16* ps4__Getptolower() {
return &lowercaseTable[0];
}
static constexpr u16 uppercaseTable[256] = {
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B,
0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023,
0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B,
0x003C, 0x003D, 0x003E, 0x003F, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053,
0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
0x0060, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B,
0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, 0x0080, 0x0081, 0x0082, 0x0083,
0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
0x009C, 0x009D, 0x009E, 0x009F, 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3,
0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB,
0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3,
0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB,
0x00FC, 0x00FD, 0x00FE, 0x00FF,
};
const PS4_SYSV_ABI u16* ps4__Getptoupper() {
return &uppercaseTable[0];
}
namespace CharacterType {
enum : u16 {
HexDigit = 0x1, // '0'-'9', 'A'-'F', 'a'-'f'
Uppercase = 0x2, // 'A'-'Z'
Space = 0x4,
Punctuation = 0x08,
Lowercase = 0x10, // 'a'-'z'
DecimalDigit = 0x20, // '0'-'9'
Control = 0x40, // CR, FF, HT, NL, VT
Control2 = 0x80, // BEL, BS, etc
ExtraSpace = 0x100,
ExtraAlphabetic = 0x200,
ExtraBlank = 0x400
};
}
static constexpr u16 characterTypeTable[256] = {
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control | CharacterType::Control2 | CharacterType::ExtraBlank,
CharacterType::Control | CharacterType::Control2,
CharacterType::Control | CharacterType::Control2,
CharacterType::Control | CharacterType::Control2,
CharacterType::Control | CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Control2,
CharacterType::Space, //
CharacterType::Punctuation, // !
CharacterType::Punctuation, // "
CharacterType::Punctuation, // #
CharacterType::Punctuation, // $
CharacterType::Punctuation, // %
CharacterType::Punctuation, // &
CharacterType::Punctuation, // '
CharacterType::Punctuation, // (
CharacterType::Punctuation, // )
CharacterType::Punctuation, // *
CharacterType::Punctuation, // +
CharacterType::Punctuation, // ,
CharacterType::Punctuation, // -
CharacterType::Punctuation, // .
CharacterType::Punctuation, // /
CharacterType::HexDigit | CharacterType::DecimalDigit, // 0
CharacterType::HexDigit | CharacterType::DecimalDigit, // 1
CharacterType::HexDigit | CharacterType::DecimalDigit, // 2
CharacterType::HexDigit | CharacterType::DecimalDigit, // 3
CharacterType::HexDigit | CharacterType::DecimalDigit, // 4
CharacterType::HexDigit | CharacterType::DecimalDigit, // 5
CharacterType::HexDigit | CharacterType::DecimalDigit, // 6
CharacterType::HexDigit | CharacterType::DecimalDigit, // 7
CharacterType::HexDigit | CharacterType::DecimalDigit, // 8
CharacterType::HexDigit | CharacterType::DecimalDigit, // 9
CharacterType::Punctuation, // :
CharacterType::Punctuation, // ;
CharacterType::Punctuation, // <
CharacterType::Punctuation, // =
CharacterType::Punctuation, // >
CharacterType::Punctuation, // ?
CharacterType::Punctuation, // @
CharacterType::HexDigit | CharacterType::Uppercase, // A
CharacterType::HexDigit | CharacterType::Uppercase, // B
CharacterType::HexDigit | CharacterType::Uppercase, // C
CharacterType::HexDigit | CharacterType::Uppercase, // D
CharacterType::HexDigit | CharacterType::Uppercase, // E
CharacterType::HexDigit | CharacterType::Uppercase, // F
CharacterType::Uppercase, // G
CharacterType::Uppercase, // H
CharacterType::Uppercase, // I
CharacterType::Uppercase, // J
CharacterType::Uppercase, // K
CharacterType::Uppercase, // L
CharacterType::Uppercase, // M
CharacterType::Uppercase, // N
CharacterType::Uppercase, // O
CharacterType::Uppercase, // P
CharacterType::Uppercase, // Q
CharacterType::Uppercase, // R
CharacterType::Uppercase, // S
CharacterType::Uppercase, // T
CharacterType::Uppercase, // U
CharacterType::Uppercase, // V
CharacterType::Uppercase, // W
CharacterType::Uppercase, // X
CharacterType::Uppercase, // Y
CharacterType::Uppercase, // Z
CharacterType::Punctuation, // [
CharacterType::Punctuation, //
CharacterType::Punctuation, // ]
CharacterType::Punctuation, // ^
CharacterType::Punctuation, // _
CharacterType::Punctuation, // `
CharacterType::HexDigit | CharacterType::Lowercase, // a
CharacterType::HexDigit | CharacterType::Lowercase, // b
CharacterType::HexDigit | CharacterType::Lowercase, // c
CharacterType::HexDigit | CharacterType::Lowercase, // d
CharacterType::HexDigit | CharacterType::Lowercase, // e
CharacterType::HexDigit | CharacterType::Lowercase, // f
CharacterType::Lowercase, // g
CharacterType::Lowercase, // h
CharacterType::Lowercase, // i
CharacterType::Lowercase, // j
CharacterType::Lowercase, // k
CharacterType::Lowercase, // l
CharacterType::Lowercase, // m
CharacterType::Lowercase, // n
CharacterType::Lowercase, // o
CharacterType::Lowercase, // p
CharacterType::Lowercase, // q
CharacterType::Lowercase, // r
CharacterType::Lowercase, // s
CharacterType::Lowercase, // t
CharacterType::Lowercase, // u
CharacterType::Lowercase, // v
CharacterType::Lowercase, // w
CharacterType::Lowercase, // x
CharacterType::Lowercase, // y
CharacterType::Lowercase, // z
CharacterType::Punctuation, // {
CharacterType::Punctuation, // |
CharacterType::Punctuation, // }
CharacterType::Punctuation, // ~
CharacterType::Control2,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
};
const PS4_SYSV_ABI u16* ps4__Getpctype() {
return &characterTypeTable[0];
}
void libcSymbolsRegister(Core::Loader::SymbolsResolver* sym) {
// cxa functions
LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, ps4___cxa_guard_acquire);
LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1, ps4___cxa_guard_release);
LIB_FUNCTION("2emaaluWzUw", "libc", 1, "libc", 1, 1, ps4___cxa_guard_abort);
// stdlib functions
LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1, ps4_exit);
LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1, ps4_atexit);
LIB_FUNCTION("gQX+4GDQjpM", "libc", 1, "libc", 1, 1, ps4_malloc);
LIB_FUNCTION("tIhsqj0qsFE", "libc", 1, "libc", 1, 1, ps4_free);
LIB_FUNCTION("cpCOXWMgha0", "libc", 1, "libc", 1, 1, ps4_rand);
LIB_FUNCTION("AEJdIVZTEmo", "libc", 1, "libc", 1, 1, ps4_qsort);
// math functions
LIB_FUNCTION("EH-x713A99c", "libc", 1, "libc", 1, 1, ps4_atan2f);
LIB_FUNCTION("QI-x0SL8jhw", "libc", 1, "libc", 1, 1, ps4_acosf);
LIB_FUNCTION("ZE6RNL+eLbk", "libc", 1, "libc", 1, 1, ps4_tanf);
LIB_FUNCTION("GZWjF-YIFFk", "libc", 1, "libc", 1, 1, ps4_asinf);
LIB_FUNCTION("9LCjpWyQ5Zc", "libc", 1, "libc", 1, 1, ps4_pow);
LIB_FUNCTION("cCXjU72Z0Ow", "libc", 1, "libc", 1, 1, ps4__Sin);
LIB_FUNCTION("ZtjspkJQ+vw", "libc", 1, "libc", 1, 1, ps4__Fsin);
LIB_FUNCTION("dnaeGXbjP6E", "libc", 1, "libc", 1, 1, ps4_exp2);
LIB_FUNCTION("1D0H2KNjshE", "libc", 1, "libc", 1, 1, ps4_powf);
LIB_FUNCTION("DDHG1a6+3q0", "libc", 1, "libc", 1, 1, ps4_roundf);
// string functions
LIB_FUNCTION("Ovb2dSJOAuE", "libc", 1, "libc", 1, 1, ps4_strcmp);
LIB_FUNCTION("j4ViWNHEgww", "libc", 1, "libc", 1, 1, ps4_strlen);
LIB_FUNCTION("6sJWiWSRuqk", "libc", 1, "libc", 1, 1, ps4_strncpy);
LIB_FUNCTION("+P6FRGH4LfA", "libc", 1, "libc", 1, 1, ps4_memmove);
LIB_FUNCTION("kiZSXIWd9vg", "libc", 1, "libc", 1, 1, ps4_strcpy);
LIB_FUNCTION("Ls4tzzhimqQ", "libc", 1, "libc", 1, 1, ps4_strcat);
LIB_FUNCTION("DfivPArhucg", "libc", 1, "libc", 1, 1, ps4_memcmp);
LIB_FUNCTION("Q3VBxCXhUHs", "libc", 1, "libc", 1, 1, ps4_memcpy);
LIB_FUNCTION("8zTFvBIAIN8", "libc", 1, "libc", 1, 1, ps4_memset);
LIB_FUNCTION("9yDWMxEFdJU", "libc", 1, "libc", 1, 1, ps4_strrchr);
LIB_FUNCTION("aesyjrHVWy4", "libc", 1, "libc", 1, 1, ps4_strncmp);
LIB_FUNCTION("g7zzzLDYGw0", "libc", 1, "libc", 1, 1, ps4_strdup);
// stdio functions
LIB_FUNCTION("xeYO4u7uyJ0", "libc", 1, "libc", 1, 1, ps4_fopen);
// LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1, ps4_printf);
LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, ps4_vsnprintf);
LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, ps4_puts);
// LIB_FUNCTION("fffwELXNVFA", "libc", 1, "libc", 1, 1, ps4_fprintf);
LIB_FUNCTION("QMFyLoqNxIg", "libc", 1, "libc", 1, 1, ps4_setvbuf);
LIB_FUNCTION("uodLYyUip20", "libc", 1, "libc", 1, 1, ps4_fclose);
LIB_FUNCTION("rQFVBXp-Cxg", "libc", 1, "libc", 1, 1, ps4_fseek);
LIB_FUNCTION("SHlt7EhOtqA", "libc", 1, "libc", 1, 1, ps4_fgetpos);
LIB_FUNCTION("lbB+UlZqVG0", "libc", 1, "libc", 1, 1, ps4_fread);
LIB_FUNCTION("Qazy8LmXTvw", "libc", 1, "libc", 1, 1, ps4_ftell);
// misc
LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &g_need_sceLibc);
LIB_OBJ("2sWzhYqFH4E", "libc", 1, "libc", 1, 1, stdout);
LIB_OBJ("H8AprKeZtNg", "libc", 1, "libc", 1, 1, stderr);
LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, ps4_init_env);
LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, ps4_catchReturnFromMain);
LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, ps4__Assert);
LIB_FUNCTION("z+P+xCnWLBk", "libc", 1, "libc", 1, 1, ps4__ZdlPv);
LIB_FUNCTION("eT2UsmTewbU", "libc", 1, "libc", 1, 1, ps4__ZSt11_Xbad_allocv);
LIB_FUNCTION("tQIo+GIPklo", "libc", 1, "libc", 1, 1, ps4__ZSt14_Xlength_errorPKc);
LIB_FUNCTION("fJnpuVVBbKk", "libc", 1, "libc", 1, 1, ps4__Znwm);
LIB_FUNCTION("tsvEmnenz48", "libc", 1, "libc", 1, 1, ps4___cxa_atexit);
LIB_FUNCTION("H2e8t5ScQGc", "libc", 1, "libc", 1, 1, ps4___cxa_finalize);
LIB_FUNCTION("zr094EQ39Ww", "libc", 1, "libc", 1, 1, ps4___cxa_pure_virtual);
LIB_FUNCTION("1uJgoVq3bQU", "libc", 1, "libc", 1, 1, ps4__Getptolower);
LIB_FUNCTION("rcQCUr0EaRU", "libc", 1, "libc", 1, 1, ps4__Getptoupper);
LIB_FUNCTION("sUP1hBaouOw", "libc", 1, "libc", 1, 1, ps4__Getpctype);
}
}; // namespace Libraries::LibC

View File

@ -1,14 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
namespace Core::Loader {
class SymbolsResolver;
}
namespace Libraries::LibC {
void libcSymbolsRegister(Core::Loader::SymbolsResolver* sym);
} // namespace Libraries::LibC

View File

@ -1,161 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/logging/log.h"
#include "core/libraries/libc/libc_cxa.h"
// adapted from
// https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html
namespace Libraries::LibC {
// This file implements the __cxa_guard_* functions as defined at:
// http://www.codesourcery.com/public/cxx-abi/abi.html
//
// The goal of these functions is to support thread-safe, one-time
// initialization of function scope variables. The compiler will generate
// code like the following:
//
// if ( obj_guard.first_byte == 0 ) {
// if ( __cxa_guard_acquire(&obj_guard) ) {
// try {
// ... initialize the object ...;
// }
// catch (...) {
// __cxa_guard_abort(&obj_guard);
// throw;
// }
// ... queue object destructor with __cxa_atexit() ...;
// __cxa_guard_release(&obj_guard);
// }
// }
//
// Notes:
// ojb_guard is a 64-bytes in size and statically initialized to zero.
//
// Section 6.7 of the C++ Spec says "If control re-enters the declaration
// recursively while the object is being initialized, the behavior is
// undefined". This implementation calls abort().
//
// Note don't use function local statics to avoid use of cxa functions...
static pthread_mutex_t __guard_mutex;
static pthread_once_t __once_control = PTHREAD_ONCE_INIT;
static void makeRecusiveMutex() {
pthread_mutexattr_t recursiveMutexAttr;
pthread_mutexattr_init(&recursiveMutexAttr);
pthread_mutexattr_settype(&recursiveMutexAttr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&__guard_mutex, &recursiveMutexAttr);
}
__attribute__((noinline)) static pthread_mutex_t* guard_mutex() {
pthread_once(&__once_control, &makeRecusiveMutex);
return &__guard_mutex;
}
// helper functions for getting/setting flags in guard_object
static bool initializerHasRun(u64* guard_object) {
return (*((u8*)guard_object) != 0);
}
static void setInitializerHasRun(u64* guard_object) {
*((u8*)guard_object) = 1;
}
static bool inUse(u64* guard_object) {
return (((u8*)guard_object)[1] != 0);
}
static void setInUse(u64* guard_object) {
((u8*)guard_object)[1] = 1;
}
static void setNotInUse(u64* guard_object) {
((u8*)guard_object)[1] = 0;
}
//
// Returns 1 if the caller needs to run the initializer and then either
// call __cxa_guard_release() or __cxa_guard_abort(). If zero is returned,
// then the initializer has already been run. This function blocks
// if another thread is currently running the initializer. This function
// aborts if called again on the same guard object without an intervening
// call to __cxa_guard_release() or __cxa_guard_abort().
//
int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object) {
// Double check that the initializer has not already been run
if (initializerHasRun(guard_object))
return 0;
// We now need to acquire a lock that allows only one thread
// to run the initializer. If a different thread calls
// __cxa_guard_acquire() with the same guard object, we want
// that thread to block until this thread is done running the
// initializer and calls __cxa_guard_release(). But if the same
// thread calls __cxa_guard_acquire() with the same guard object,
// we want to abort.
// To implement this we have one global pthread recursive mutex
// shared by all guard objects, but only one at a time.
int result = ::pthread_mutex_lock(guard_mutex());
if (result != 0) {
LOG_ERROR(Lib_LibC, "pthread_mutex_lock failed with {}", result);
}
// At this point all other threads will block in __cxa_guard_acquire()
// Check if another thread has completed initializer run
if (initializerHasRun(guard_object)) {
int result = ::pthread_mutex_unlock(guard_mutex());
if (result != 0) {
LOG_ERROR(Lib_LibC, "pthread_mutex_lock failed with {}", result);
}
return 0;
}
// The pthread mutex is recursive to allow other lazy initialized
// function locals to be evaluated during evaluation of this one.
// But if the same thread can call __cxa_guard_acquire() on the
// *same* guard object again, we call abort();
if (inUse(guard_object)) {
LOG_ERROR(Lib_LibC,
"initializer for function local static variable called enclosing function");
}
// mark this guard object as being in use
setInUse(guard_object);
// return non-zero to tell caller to run initializer
return 1;
}
//
// Sets the first byte of the guard_object to a non-zero value.
// Releases any locks acquired by __cxa_guard_acquire().
//
void PS4_SYSV_ABI ps4___cxa_guard_release(u64* guard_object) {
// first mark initalizer as having been run, so
// other threads won't try to re-run it.
setInitializerHasRun(guard_object);
// release global mutex
int result = ::pthread_mutex_unlock(guard_mutex());
if (result != 0) {
LOG_ERROR(Lib_LibC, "pthread_mutex_unlock failed with {}", result);
}
}
//
// Releases any locks acquired by __cxa_guard_acquire().
//
void PS4_SYSV_ABI ps4___cxa_guard_abort(u64* guard_object) {
int result = ::pthread_mutex_unlock(guard_mutex());
if (result != 0) {
LOG_ERROR(Lib_LibC, "pthread_mutex_unlock failed with {}", result);
}
// now reset state, so possible to try to initialize again
setNotInUse(guard_object);
}
} // namespace Libraries::LibC

View File

@ -1,15 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <pthread.h>
#include "common/types.h"
namespace Libraries::LibC {
int PS4_SYSV_ABI ps4___cxa_guard_acquire(u64* guard_object);
void PS4_SYSV_ABI ps4___cxa_guard_release(u64* guard_object);
void PS4_SYSV_ABI ps4___cxa_guard_abort(u64* guard_object);
} // namespace Libraries::LibC

View File

@ -1,55 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cmath>
#include "common/assert.h"
#include "core/libraries/libc/libc_math.h"
namespace Libraries::LibC {
float PS4_SYSV_ABI ps4_atan2f(float y, float x) {
return atan2f(y, x);
}
float PS4_SYSV_ABI ps4_acosf(float num) {
return acosf(num);
}
float PS4_SYSV_ABI ps4_tanf(float num) {
return tanf(num);
}
float PS4_SYSV_ABI ps4_asinf(float num) {
return asinf(num);
}
double PS4_SYSV_ABI ps4_pow(double base, double exponent) {
return pow(base, exponent);
}
float PS4_SYSV_ABI ps4_powf(float x, float y) {
return powf(x, y);
}
float PS4_SYSV_ABI ps4_roundf(float arg) {
return roundf(arg);
}
double PS4_SYSV_ABI ps4__Sin(double x) {
return sin(x);
}
float PS4_SYSV_ABI ps4__Fsin(float arg, unsigned int m, int n) {
ASSERT(n == 0);
if (m != 0) {
return cosf(arg);
} else {
return sinf(arg);
}
}
double PS4_SYSV_ABI ps4_exp2(double arg) {
return exp2(arg);
}
} // namespace Libraries::LibC

View File

@ -1,21 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "common/types.h"
namespace Libraries::LibC {
float PS4_SYSV_ABI ps4_atan2f(float y, float x);
float PS4_SYSV_ABI ps4_acosf(float num);
float PS4_SYSV_ABI ps4_tanf(float num);
float PS4_SYSV_ABI ps4_asinf(float num);
double PS4_SYSV_ABI ps4_pow(double base, double exponent);
double PS4_SYSV_ABI ps4__Sin(double x);
float PS4_SYSV_ABI ps4__Fsin(float arg, unsigned int, int);
double PS4_SYSV_ABI ps4_exp2(double arg);
float PS4_SYSV_ABI ps4_powf(float x, float y);
float PS4_SYSV_ABI ps4_roundf(float arg);
} // namespace Libraries::LibC

View File

@ -1,78 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/file_sys/fs.h"
#include "core/libraries/libc/libc_stdio.h"
namespace Libraries::LibC {
std::FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode) {
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
const auto host_path = mnt->GetHostPath(filename).string();
FILE* f = std::fopen(host_path.c_str(), mode);
if (f != nullptr) {
LOG_INFO(Lib_LibC, "fopen = {}", host_path);
} else {
LOG_INFO(Lib_LibC, "fopen can't open = {}", host_path);
}
return f;
}
int PS4_SYSV_ABI ps4_fclose(FILE* stream) {
LOG_INFO(Lib_LibC, "callled");
int ret = 0;
if (stream != nullptr) {
ret = fclose(stream);
}
return ret;
}
int PS4_SYSV_ABI ps4_setvbuf(FILE* stream, char* buf, int mode, size_t size) {
return setvbuf(stream, buf, mode, size);
}
int PS4_SYSV_ABI ps4_fseek(FILE* stream, long offset, int whence) {
return fseek(stream, offset, whence);
}
int PS4_SYSV_ABI ps4_fgetpos(FILE* stream, fpos_t* pos) {
return fgetpos(stream, pos);
}
std::size_t PS4_SYSV_ABI ps4_fread(void* ptr, size_t size, size_t nmemb, FILE* stream) {
return fread(ptr, size, nmemb, stream);
}
int PS4_SYSV_ABI ps4_printf(VA_ARGS) {
VA_CTX(ctx);
return printf_ctx(&ctx);
}
int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS) {
int fd = fileno(file);
if (fd == 1 || fd == 2) { // output stdout and stderr to console
VA_CTX(ctx);
return printf_ctx(&ctx);
} else {
VA_CTX(ctx);
char buf[256];
fprintf_ctx(&ctx, buf);
return fprintf(file, "%s", buf);
}
}
int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg) {
return vsnprintf_ctx(s, n, format, arg);
}
int PS4_SYSV_ABI ps4_puts(const char* s) {
return std::puts(s);
}
long PS4_SYSV_ABI ps4_ftell(FILE* stream) {
return ftell(stream);
}
} // namespace Libraries::LibC

View File

@ -1,23 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "common/types.h"
#include "core/libraries/libc/printf.h"
namespace Libraries::LibC {
std::FILE* PS4_SYSV_ABI ps4_fopen(const char* filename, const char* mode);
int PS4_SYSV_ABI ps4_printf(VA_ARGS);
int PS4_SYSV_ABI ps4_vsnprintf(char* s, size_t n, const char* format, VaList* arg);
int PS4_SYSV_ABI ps4_puts(const char* s);
int PS4_SYSV_ABI ps4_fprintf(FILE* file, VA_ARGS);
int PS4_SYSV_ABI ps4_setvbuf(FILE* stream, char* buf, int mode, size_t size);
int PS4_SYSV_ABI ps4_fclose(FILE* stream);
int PS4_SYSV_ABI ps4_fseek(FILE* stream, long offset, int whence);
int PS4_SYSV_ABI ps4_fgetpos(FILE* stream, fpos_t* pos);
std::size_t PS4_SYSV_ABI ps4_fread(void* ptr, size_t size, size_t nmemb, FILE* stream);
long PS4_SYSV_ABI ps4_ftell(FILE* stream);
} // namespace Libraries::LibC

View File

@ -1,45 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstdlib>
#include "common/assert.h"
#include "core/libraries/libc/libc_stdlib.h"
namespace Libraries::LibC {
void PS4_SYSV_ABI ps4_exit(int code) {
std::exit(code);
}
int PS4_SYSV_ABI ps4_atexit(void (*func)()) {
int rt = std::atexit(func);
ASSERT_MSG(rt == 0, "atexit returned {}", rt);
return rt;
}
void* PS4_SYSV_ABI ps4_malloc(size_t size) {
return std::malloc(size);
}
void PS4_SYSV_ABI ps4_free(void* ptr) {
std::free(ptr);
}
typedef int(PS4_SYSV_ABI* pfunc_QsortCmp)(const void*, const void*);
thread_local static pfunc_QsortCmp compair_ps4;
int qsort_compair(const void* arg1, const void* arg2) {
return compair_ps4(arg1, arg2);
}
void PS4_SYSV_ABI ps4_qsort(void* ptr, size_t count, size_t size,
int(PS4_SYSV_ABI* comp)(const void*, const void*)) {
compair_ps4 = comp;
std::qsort(ptr, count, size, qsort_compair);
}
int PS4_SYSV_ABI ps4_rand() {
return std::rand();
}
} // namespace Libraries::LibC

View File

@ -1,19 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <cstddef>
#include "common/types.h"
namespace Libraries::LibC {
void PS4_SYSV_ABI ps4_exit(int code);
int PS4_SYSV_ABI ps4_atexit(void (*func)());
void* PS4_SYSV_ABI ps4_malloc(size_t size);
void PS4_SYSV_ABI ps4_free(void* ptr);
void PS4_SYSV_ABI ps4_qsort(void* ptr, size_t count, size_t size,
int(PS4_SYSV_ABI* comp)(const void*, const void*));
int PS4_SYSV_ABI ps4_rand();
} // namespace Libraries::LibC

View File

@ -1,61 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstdlib>
#include <cstring>
#include "core/libraries/libc/libc_string.h"
namespace Libraries::LibC {
int PS4_SYSV_ABI ps4_memcmp(const void* s1, const void* s2, size_t n) {
return std::memcmp(s1, s2, n);
}
void* PS4_SYSV_ABI ps4_memcpy(void* dest, const void* src, size_t n) {
return std::memcpy(dest, src, n);
}
void* PS4_SYSV_ABI ps4_memset(void* s, int c, size_t n) {
return std::memset(s, c, n);
}
int PS4_SYSV_ABI ps4_strcmp(const char* str1, const char* str2) {
return std::strcmp(str1, str2);
}
char* PS4_SYSV_ABI ps4_strncpy(char* dest, const char* src, size_t count) {
return std::strncpy(dest, src, count);
}
void* PS4_SYSV_ABI ps4_memmove(void* dest, const void* src, std::size_t count) {
return std::memmove(dest, src, count);
}
char* PS4_SYSV_ABI ps4_strcpy(char* dest, const char* src) {
return std::strcpy(dest, src);
}
char* PS4_SYSV_ABI ps4_strcat(char* dest, const char* src) {
return std::strcat(dest, src);
}
size_t PS4_SYSV_ABI ps4_strlen(const char* str) {
return std::strlen(str);
}
char* PS4_SYSV_ABI ps4_strrchr(const char* s, int c) {
return (char*)strrchr(s, c);
}
int PS4_SYSV_ABI ps4_strncmp(const char* s1, const char* s2, size_t n) {
return strncmp(s1, s2, n);
}
char* PS4_SYSV_ABI ps4_strdup(const char* str1) {
char* dup = (char*)std::malloc(std::strlen(str1) + 1);
if (dup != NULL)
strcpy(dup, str1);
return dup;
}
} // namespace Libraries::LibC

View File

@ -1,24 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <cstddef>
#include "common/types.h"
namespace Libraries::LibC {
int PS4_SYSV_ABI ps4_memcmp(const void* s1, const void* s2, size_t n);
void* PS4_SYSV_ABI ps4_memcpy(void* dest, const void* src, size_t n);
void* PS4_SYSV_ABI ps4_memset(void* s, int c, size_t n);
int PS4_SYSV_ABI ps4_strcmp(const char* str1, const char* str2);
char* PS4_SYSV_ABI ps4_strncpy(char* dest, const char* src, size_t count);
void* PS4_SYSV_ABI ps4_memmove(void* dest, const void* src, std::size_t count);
char* PS4_SYSV_ABI ps4_strcpy(char* destination, const char* source);
char* PS4_SYSV_ABI ps4_strcat(char* dest, const char* src);
size_t PS4_SYSV_ABI ps4_strlen(const char* str);
char* PS4_SYSV_ABI ps4_strrchr(const char* s, int c);
int PS4_SYSV_ABI ps4_strncmp(const char* s1, const char* s2, size_t n);
char* PS4_SYSV_ABI ps4_strdup(const char* str1);
} // namespace Libraries::LibC

View File

@ -1,753 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2014-2018 Marco Paland (info@paland.com)
// SPDX-License-Identifier: MIT
///////////////////////////////////////////////////////////////////////////////
// \author (c) Marco Paland (info@paland.com)
// 2014-2018, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
// embedded systems with a very limited resources.
// Use this instead of bloated standard/newlib printf.
// These routines are thread safe and reentrant!
//
///////////////////////////////////////////////////////////////////////////////
// Vita3K emulator project
// Copyright (C) 2023 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// copied from Vita3k project at 6/10/2023 (latest update 30/06/2023)
// modifications for adapting va_args parameters
#pragma once
#include <stdio.h>
#include <cstdarg>
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <string>
#include "va_ctx.h"
namespace Libraries::LibC {
// ntoa conversion buffer size, this must be big enough to hold
// one converted numeric number including padded zeros (dynamically created on stack)
// 32 byte is a good default
#define PRINTF_NTOA_BUFFER_SIZE 32U
// ftoa conversion buffer size, this must be big enough to hold
// one converted float number including padded zeros (dynamically created on stack)
// 32 byte is a good default
#define PRINTF_FTOA_BUFFER_SIZE 32U
// define this to support floating point (%f)
#define PRINTF_SUPPORT_FLOAT
// define this to support long long types (%llu or %p)
#define PRINTF_SUPPORT_LONG_LONG
// define this to support the ptrdiff_t type (%t)
// ptrdiff_t is normally defined in <stddef.h> as long or long long type
#define PRINTF_SUPPORT_PTRDIFF_T
///////////////////////////////////////////////////////////////////////////////
// internal flag definitions
#define FLAGS_ZEROPAD (1U << 0U)
#define FLAGS_LEFT (1U << 1U)
#define FLAGS_PLUS (1U << 2U)
#define FLAGS_SPACE (1U << 3U)
#define FLAGS_HASH (1U << 4U)
#define FLAGS_UPPERCASE (1U << 5U)
#define FLAGS_CHAR (1U << 6U)
#define FLAGS_SHORT (1U << 7U)
#define FLAGS_LONG (1U << 8U)
#define FLAGS_LONG_LONG (1U << 9U)
#define FLAGS_PRECISION (1U << 10U)
#define FLAGS_WIDTH (1U << 11U)
// output function type
typedef void (*out_fct_type)(char character, void* buffer, size_t idx, size_t maxlen);
// wrapper (used as buffer) for output function type
typedef struct {
void (*fct)(char character, void* arg);
void* arg;
} out_fct_wrap_type;
// internal buffer output
static inline void _out_buffer(char character, void* buffer, size_t idx, size_t maxlen) {
if (idx < maxlen) {
((char*)buffer)[idx] = character;
}
}
// internal null output
static inline void _out_null(char character, void* buffer, size_t idx, size_t maxlen) {
(void)character;
(void)buffer;
(void)idx;
(void)maxlen;
}
// internal output function wrapper
static inline void _out_fct(char character, void* buffer, size_t idx, size_t maxlen) {
(void)idx;
(void)maxlen;
// buffer is the output fct pointer
((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->arg);
}
// internal strlen
// \return The length of the string (excluding the terminating 0)
static inline unsigned int _strlen(const char* str) {
const char* s;
for (s = str; *s; ++s)
;
return (unsigned int)(s - str);
}
// internal test if char is a digit (0-9)
// \return true if char is a digit
static inline bool _is_digit(char ch) {
return (ch >= '0') && (ch <= '9');
}
// internal ASCII string to unsigned int conversion
static inline unsigned int _atoi(const char** str) {
unsigned int i = 0U;
while (_is_digit(**str)) {
i = i * 10U + (unsigned int)(*((*str)++) - '0');
}
return i;
}
// internal itoa format
static inline size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
char* buf, size_t len, bool negative, unsigned int base,
unsigned int prec, unsigned int width, unsigned int flags) {
const size_t start_idx = idx;
// pad leading zeros
while (!(flags & FLAGS_LEFT) && (len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = '0';
}
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) &&
(len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = '0';
}
// handle hash
if (flags & FLAGS_HASH) {
if (((len == prec) || (len == width)) && (len > 0U)) {
len--;
if ((base == 16U) && (len > 0U)) {
len--;
}
}
if ((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = 'x';
}
if ((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = 'X';
}
if (len < PRINTF_NTOA_BUFFER_SIZE) {
buf[len++] = '0';
}
}
// handle sign
if ((len == width) && (negative || (flags & FLAGS_PLUS) || (flags & FLAGS_SPACE))) {
len--;
}
if (len < PRINTF_NTOA_BUFFER_SIZE) {
if (negative) {
buf[len++] = '-';
} else if (flags & FLAGS_PLUS) {
buf[len++] = '+'; // ignore the space if the '+' exists
} else if (flags & FLAGS_SPACE) {
buf[len++] = ' ';
}
}
// pad spaces up to given width
if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) {
for (size_t i = len; i < width; i++) {
out(' ', buffer, idx++, maxlen);
}
}
// reverse string
for (size_t i = 0U; i < len; i++) {
out(buf[len - i - 1U], buffer, idx++, maxlen);
}
// append pad spaces up to given width
if (flags & FLAGS_LEFT) {
while (idx - start_idx < width) {
out(' ', buffer, idx++, maxlen);
}
}
return idx;
}
// internal itoa for 'long' type
static inline size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
unsigned long value, bool negative, unsigned long base,
unsigned int prec, unsigned int width, unsigned int flags) {
char buf[PRINTF_NTOA_BUFFER_SIZE];
size_t len = 0U;
// write if precision != 0 and value is != 0
if (!(flags & FLAGS_PRECISION) || value) {
do {
const char digit = (char)(value % base);
buf[len++] =
digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
value /= base;
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE));
}
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec,
width, flags);
}
// internal itoa for 'long long' type
#if defined(PRINTF_SUPPORT_LONG_LONG)
static inline size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen,
unsigned long long value, bool negative,
unsigned long long base, unsigned int prec, unsigned int width,
unsigned int flags) {
char buf[PRINTF_NTOA_BUFFER_SIZE];
size_t len = 0U;
// write if precision != 0 and value is != 0
if (!(flags & FLAGS_PRECISION) || value) {
do {
const char digit = (char)(value % base);
buf[len++] =
digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
value /= base;
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE));
}
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec,
width, flags);
}
#endif // PRINTF_SUPPORT_LONG_LONG
#if defined(PRINTF_SUPPORT_FLOAT)
static inline size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value,
unsigned int prec, unsigned int width, unsigned int flags) {
char buf[PRINTF_FTOA_BUFFER_SIZE];
size_t len = 0U;
double diff = 0.0;
// if input is larger than thres_max, revert to exponential
const double thres_max = (double)0x7FFFFFFF;
// powers of 10
static const double pow10[] = {1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000};
// test for negative
bool negative = false;
if (value < 0) {
negative = true;
value = 0 - value;
}
// set default precision to 6, if not set explicitly
if (!(flags & FLAGS_PRECISION)) {
prec = 6U;
}
// limit precision to 9, cause a prec >= 10 can lead to overflow errors
while ((len < PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U)) {
buf[len++] = '0';
prec--;
}
int whole = (int)value;
double tmp = (value - whole) * pow10[prec];
unsigned long frac = (unsigned long)tmp;
diff = tmp - frac;
if (diff > 0.5) {
++frac;
// handle rollover, e.g. case 0.99 with prec 1 is 1.0
if (frac >= pow10[prec]) {
frac = 0;
++whole;
}
} else if ((diff == 0.5) && ((frac == 0U) || (frac & 1U))) {
// if halfway, round up if odd, OR if last digit is 0
++frac;
}
// TBD: for very large numbers switch back to native sprintf for exponentials. Anyone want to
// write code to replace this? Normal printf behavior is to print EVERY whole number digit which
// can be 100s of characters overflowing your buffers == bad
if (value > thres_max) {
return 0U;
}
if (prec == 0U) {
diff = value - (double)whole;
if (diff > 0.5) {
// greater than 0.5, round up, e.g. 1.6 -> 2
++whole;
} else if ((diff == 0.5) && (whole & 1)) {
// exactly 0.5 and ODD, then round up
// 1.5 -> 2, but 2.5 -> 2
++whole;
}
} else {
unsigned int count = prec;
// now do fractional part, as an unsigned number
while (len < PRINTF_FTOA_BUFFER_SIZE) {
--count;
buf[len++] = (char)(48U + (frac % 10U));
if (!(frac /= 10U)) {
break;
}
}
// add extra 0s
while ((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) {
buf[len++] = '0';
}
if (len < PRINTF_FTOA_BUFFER_SIZE) {
// add decimal
buf[len++] = '.';
}
}
// do whole part, number is reversed
while (len < PRINTF_FTOA_BUFFER_SIZE) {
buf[len++] = (char)(48 + (whole % 10));
if (!(whole /= 10)) {
break;
}
}
// pad leading zeros
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) &&
(len < PRINTF_FTOA_BUFFER_SIZE)) {
buf[len++] = '0';
}
// handle sign
if ((len == width) && (negative || (flags & FLAGS_PLUS) || (flags & FLAGS_SPACE))) {
len--;
}
if (len < PRINTF_FTOA_BUFFER_SIZE) {
if (negative) {
buf[len++] = '-';
} else if (flags & FLAGS_PLUS) {
buf[len++] = '+'; // ignore the space if the '+' exists
} else if (flags & FLAGS_SPACE) {
buf[len++] = ' ';
}
}
// pad spaces up to given width
if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) {
for (size_t i = len; i < width; i++) {
out(' ', buffer, idx++, maxlen);
}
}
// reverse string
for (size_t i = 0U; i < len; i++) {
out(buf[len - i - 1U], buffer, idx++, maxlen);
}
// append pad spaces up to given width
if (flags & FLAGS_LEFT) {
while (idx < width) {
out(' ', buffer, idx++, maxlen);
}
}
return idx;
}
#endif // PRINTF_SUPPORT_FLOAT
// internal vsnprintf
static inline int _vsnprintf(out_fct_type out, char* buffer, const char* format, VaList* va_list) {
unsigned int flags, width, precision, n;
size_t idx = 0U;
auto maxlen = static_cast<size_t>(-1);
if (!buffer) {
// use null output function
out = _out_null;
}
while (*format) {
// format specifier? %[flags][width][.precision][length]
if (*format != '%') {
// no
out(*format, buffer, idx++, maxlen);
format++;
continue;
} else {
// yes, evaluate it
format++;
}
// evaluate flags
flags = 0U;
do {
switch (*format) {
case '0':
flags |= FLAGS_ZEROPAD;
format++;
n = 1U;
break;
case '-':
flags |= FLAGS_LEFT;
format++;
n = 1U;
break;
case '+':
flags |= FLAGS_PLUS;
format++;
n = 1U;
break;
case ' ':
flags |= FLAGS_SPACE;
format++;
n = 1U;
break;
case '#':
flags |= FLAGS_HASH;
format++;
n = 1U;
break;
default:
n = 0U;
break;
}
} while (n);
// evaluate width field
width = 0U;
if (_is_digit(*format)) {
width = _atoi(&format);
} else if (*format == '*') {
const int w = vaArgInteger(va_list); // const int w = va.next<int>(cpu, mem);
if (w < 0) {
flags |= FLAGS_LEFT; // reverse padding
width = (unsigned int)-w;
} else {
width = (unsigned int)w;
}
format++;
}
// evaluate precision field
precision = 0U;
if (*format == '.') {
flags |= FLAGS_PRECISION;
format++;
if (_is_digit(*format)) {
precision = _atoi(&format);
} else if (*format == '*') {
precision =
vaArgInteger(va_list); // precision = (unsigned int)va.next<int>(cpu, mem);
format++;
}
}
// evaluate length field
switch (*format) {
case 'l':
flags |= FLAGS_LONG;
format++;
if (*format == 'l') {
flags |= FLAGS_LONG_LONG;
format++;
}
break;
case 'h':
flags |= FLAGS_SHORT;
format++;
if (*format == 'h') {
flags |= FLAGS_CHAR;
format++;
}
break;
#if defined(PRINTF_SUPPORT_PTRDIFF_T)
case 't':
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
format++;
break;
#endif
case 'j':
flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
format++;
break;
case 'z':
flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
format++;
break;
default:
break;
}
// evaluate specifier
switch (*format) {
case 'd':
case 'i':
case 'u':
case 'x':
case 'X':
case 'o':
case 'b': {
// set the base
unsigned int base;
if (*format == 'x' || *format == 'X') {
base = 16U;
} else if (*format == 'o') {
base = 8U;
} else if (*format == 'b') {
base = 2U;
flags &= ~FLAGS_HASH; // no hash for bin format
} else {
base = 10U;
flags &= ~FLAGS_HASH; // no hash for dec format
}
// uppercase
if (*format == 'X') {
flags |= FLAGS_UPPERCASE;
}
// no plus or space flag for u, x, X, o, b
if ((*format != 'i') && (*format != 'd')) {
flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
}
// convert the integer
if ((*format == 'i') || (*format == 'd')) {
// signed
if (flags & FLAGS_LONG_LONG) {
#if defined(PRINTF_SUPPORT_LONG_LONG)
auto value = vaArgLongLong(
va_list); // const long long value = va.next<long long>(cpu, mem);
idx = _ntoa_long_long(out, buffer, idx, maxlen,
(unsigned long long)(value > 0 ? value : 0 - value),
value < 0, base, precision, width, flags);
#endif
} else if (flags & FLAGS_LONG) {
auto value = vaArgLong(va_list); // const long value = va.next<long>(cpu, mem);
idx = _ntoa_long(out, buffer, idx, maxlen,
(unsigned long)(value > 0 ? value : 0 - value), value < 0,
base, precision, width, flags);
} else {
// const int value = (flags & FLAGS_CHAR) ? (char)va.next<int>(cpu, mem) :
// (flags & FLAGS_SHORT) ? (short int)va.next<int>(cpu, mem): va.next<int>(cpu,
// mem);
const int value =
(flags & FLAGS_CHAR) ? static_cast<char>(vaArgInteger(va_list))
: (flags & FLAGS_SHORT) ? static_cast<int16_t>(vaArgInteger(va_list))
: vaArgInteger(va_list);
idx = _ntoa_long(out, buffer, idx, maxlen,
(unsigned int)(value > 0 ? value : 0 - value), value < 0, base,
precision, width, flags);
}
} else {
// unsigned
if (flags & FLAGS_LONG_LONG) {
#if defined(PRINTF_SUPPORT_LONG_LONG)
// idx = _ntoa_long_long(out, buffer, idx, maxlen, va.next<unsigned long
// long>(cpu, mem), false, base, precision, width, flags);
idx = _ntoa_long_long(out, buffer, idx, maxlen,
static_cast<u64>(vaArgLongLong(va_list)), false, base,
precision, width, flags);
#endif
} else if (flags & FLAGS_LONG) {
// idx = _ntoa_long(out, buffer, idx, maxlen, va.next<unsigned long>(cpu, mem),
// false, base, precision, width, flags);
idx = _ntoa_long(out, buffer, idx, maxlen, static_cast<u32>(vaArgLong(va_list)),
false, base, precision, width, flags);
} else {
// const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned
// char)va.next<unsigned int>(cpu, mem) : (flags & FLAGS_SHORT) ?
// (unsigned short int)va.next<unsigned int>(cpu, mem) : va.next<unsigned
// int>(cpu, mem);
const unsigned int value =
(flags & FLAGS_CHAR) ? static_cast<u8>(vaArgInteger(va_list))
: (flags & FLAGS_SHORT) ? static_cast<u16>(vaArgInteger(va_list))
: static_cast<u32>(vaArgInteger(va_list));
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width,
flags);
}
}
format++;
break;
}
#if defined(PRINTF_SUPPORT_FLOAT)
case 'f':
case 'F':
// idx = _ftoa(out, buffer, idx, maxlen, va.next<double>(cpu, mem), precision, width,
// flags);
idx = _ftoa(out, buffer, idx, maxlen, vaArgDouble(va_list), precision, width, flags);
format++;
break;
#endif // PRINTF_SUPPORT_FLOAT
case 'c': {
unsigned int l = 1U;
// pre padding
if (!(flags & FLAGS_LEFT)) {
while (l++ < width) {
out(' ', buffer, idx++, maxlen);
}
}
// char output
// out((char)va.next<int>(cpu, mem), buffer, idx++, maxlen);
out(static_cast<char>(vaArgInteger(va_list)), buffer, idx++, maxlen);
// post padding
if (flags & FLAGS_LEFT) {
while (l++ < width) {
out(' ', buffer, idx++, maxlen);
}
}
format++;
break;
}
case 's': {
const char* p = vaArgPtr<const char>(
va_list); // const char *p = va.next<Ptr<char>>(cpu, mem).get(mem);
p = p != nullptr ? p : "(null)";
unsigned int l = _strlen(p);
// pre padding
if (flags & FLAGS_PRECISION) {
l = (l < precision ? l : precision);
}
if (!(flags & FLAGS_LEFT)) {
while (l++ < width) {
out(' ', buffer, idx++, maxlen);
}
}
// string output
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
out(*(p++), buffer, idx++, maxlen);
}
// post padding
if (flags & FLAGS_LEFT) {
while (l++ < width) {
out(' ', buffer, idx++, maxlen);
}
}
format++;
break;
}
case 'p': {
width = sizeof(void*) * 2U;
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
#if defined(PRINTF_SUPPORT_LONG_LONG)
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
if (is_ll) {
// idx = _ntoa_long_long(out, buffer, idx, maxlen,
// (uintptr_t)va.next<Ptr<void>>(cpu, mem).address(), false, 16U, precision, width,
// flags);
idx = _ntoa_long_long(out, buffer, idx, maxlen,
reinterpret_cast<uintptr_t>(vaArgPtr<void>(va_list)), false,
16U, precision, width, flags);
} else {
#endif
// idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned
// long)((uintptr_t)va.next<Ptr<void>>(cpu, mem).address()), false, 16U, precision,
// width, flags);
idx = _ntoa_long(
out, buffer, idx, maxlen,
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(vaArgPtr<void>(va_list))),
false, 16U, precision, width, flags);
#if defined(PRINTF_SUPPORT_LONG_LONG)
}
#endif
format++;
break;
}
case '%':
out('%', buffer, idx++, maxlen);
format++;
break;
default:
out(*format, buffer, idx++, maxlen);
format++;
break;
}
}
// termination
out((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen);
// return written chars without terminating \0
return (int)idx;
}
static int printf_ctx(VaCtx* ctx) {
const char* format = vaArgPtr<const char>(&ctx->va_list);
char buffer[256];
int result = _vsnprintf(_out_buffer, buffer, format, &ctx->va_list);
printf("%s", buffer);
return result;
}
static int fprintf_ctx(VaCtx* ctx, char* buf) {
const char* format = vaArgPtr<const char>(&ctx->va_list);
char buffer[256];
int result = _vsnprintf(_out_buffer, buffer, format, &ctx->va_list);
std::strcpy(buf, buffer);
return result;
}
static int vsnprintf_ctx(char* s, size_t n, const char* format, VaList* arg) {
char buffer[n];
int result = _vsnprintf(_out_buffer, buffer, format, arg);
std::strcpy(s, buffer);
return result;
}
} // namespace Libraries::LibC

View File

@ -1,110 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <xmmintrin.h>
#include "common/types.h"
#define VA_ARGS \
uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx, uint64_t r8, uint64_t r9, \
uint64_t overflow_arg_area, __m128 xmm0, __m128 xmm1, __m128 xmm2, __m128 xmm3, \
__m128 xmm4, __m128 xmm5, __m128 xmm6, __m128 xmm7, ...
#define VA_CTX(ctx) \
alignas(16) VaCtx ctx; \
(ctx).reg_save_area.gp[0] = rdi; \
(ctx).reg_save_area.gp[1] = rsi; \
(ctx).reg_save_area.gp[2] = rdx; \
(ctx).reg_save_area.gp[3] = rcx; \
(ctx).reg_save_area.gp[4] = r8; \
(ctx).reg_save_area.gp[5] = r9; \
(ctx).reg_save_area.fp[0] = xmm0; \
(ctx).reg_save_area.fp[1] = xmm1; \
(ctx).reg_save_area.fp[2] = xmm2; \
(ctx).reg_save_area.fp[3] = xmm3; \
(ctx).reg_save_area.fp[4] = xmm4; \
(ctx).reg_save_area.fp[5] = xmm5; \
(ctx).reg_save_area.fp[6] = xmm6; \
(ctx).reg_save_area.fp[7] = xmm7; \
(ctx).va_list.reg_save_area = &(ctx).reg_save_area; \
(ctx).va_list.gp_offset = offsetof(VaRegSave, gp); \
(ctx).va_list.fp_offset = offsetof(VaRegSave, fp); \
(ctx).va_list.overflow_arg_area = &overflow_arg_area;
namespace Libraries::LibC {
// https://stackoverflow.com/questions/4958384/what-is-the-format-of-the-x86-64-va-list-structure
struct VaList {
u32 gp_offset;
u32 fp_offset;
void* overflow_arg_area;
void* reg_save_area;
};
struct VaRegSave {
u64 gp[6];
__m128 fp[8];
};
struct VaCtx {
VaRegSave reg_save_area;
VaList va_list;
};
template <class T, uint32_t Size>
T vaArgRegSaveAreaGp(VaList* l) {
auto* addr = reinterpret_cast<T*>(static_cast<u8*>(l->reg_save_area) + l->gp_offset);
l->gp_offset += Size;
return *addr;
}
template <class T, u64 Align, u64 Size>
T vaArgOverflowArgArea(VaList* l) {
auto ptr = ((reinterpret_cast<u64>(l->overflow_arg_area) + (Align - 1)) & ~(Align - 1));
auto* addr = reinterpret_cast<T*>(ptr);
l->overflow_arg_area = reinterpret_cast<void*>(ptr + Size);
return *addr;
}
template <class T, uint32_t Size>
T vaArgRegSaveAreaFp(VaList* l) {
auto* addr = reinterpret_cast<T*>(static_cast<u8*>(l->reg_save_area) + l->fp_offset);
l->fp_offset += Size;
return *addr;
}
inline int vaArgInteger(VaList* l) {
if (l->gp_offset <= 40) {
return vaArgRegSaveAreaGp<int, 8>(l);
}
return vaArgOverflowArgArea<int, 1, 8>(l);
}
inline long long vaArgLongLong(VaList* l) {
if (l->gp_offset <= 40) {
return vaArgRegSaveAreaGp<long long, 8>(l);
}
return vaArgOverflowArgArea<long long, 1, 8>(l);
}
inline long vaArgLong(VaList* l) {
if (l->gp_offset <= 40) {
return vaArgRegSaveAreaGp<long, 8>(l);
}
return vaArgOverflowArgArea<long, 1, 8>(l);
}
inline double vaArgDouble(VaList* l) {
if (l->fp_offset <= 160) {
return vaArgRegSaveAreaFp<double, 16>(l);
}
return vaArgOverflowArgArea<double, 1, 8>(l);
}
template <class T>
T* vaArgPtr(VaList* l) {
if (l->gp_offset <= 40) {
return vaArgRegSaveAreaGp<T*, 8>(l);
}
return vaArgOverflowArgArea<T*, 1, 8>(l);
}
} // namespace Libraries::LibC

View File

@ -8,7 +8,6 @@
#include "core/libraries/disc_map/disc_map.h"
#include "core/libraries/gnmdriver/gnmdriver.h"
#include "core/libraries/kernel/libkernel.h"
#include "core/libraries/libc/libc.h"
#include "core/libraries/libc_internal/libc_internal.h"
#include "core/libraries/libs.h"
#include "core/libraries/network/http.h"
@ -46,9 +45,6 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) {
Libraries::Kernel::LibKernel_Register(sym);
Libraries::GnmDriver::RegisterlibSceGnmDriver(sym);
Libraries::VideoOut::RegisterLib(sym);
if (!Config::isLleLibc()) {
Libraries::LibC::libcSymbolsRegister(sym);
}
// New libraries folder from autogen
Libraries::UserService::RegisterlibSceUserService(sym);

View File

@ -6,6 +6,8 @@
#include "core/libraries/libs.h"
#include "core/libraries/system/msgdialog.h"
#include <magic_enum.hpp>
namespace Libraries::MsgDialog {
int PS4_SYSV_ABI sceMsgDialogClose() {
@ -30,9 +32,22 @@ int PS4_SYSV_ABI sceMsgDialogInitialize() {
s32 PS4_SYSV_ABI sceMsgDialogOpen(const OrbisMsgDialogParam* param) {
LOG_ERROR(Lib_MsgDlg, "(STUBBED) called");
OrbisMsgDialogUserMessageParam* userMsgParam = param->userMsgParam;
const char* msg = userMsgParam->msg;
printf("sceMsgDialogOpen msg : %s", msg);
switch (param->mode) {
case ORBIS_MSG_DIALOG_MODE_USER_MSG:
LOG_INFO(Lib_MsgDlg, "sceMsgDialogOpen userMsg type = %s msg = %s",
magic_enum::enum_name(param->userMsgParam->buttonType), param->userMsgParam->msg);
break;
case ORBIS_MSG_DIALOG_MODE_PROGRESS_BAR:
LOG_INFO(Lib_MsgDlg, "sceMsgDialogOpen progressBar type = %s msg = %s",
magic_enum::enum_name(param->progBarParam->barType), param->progBarParam->msg);
break;
case ORBIS_MSG_DIALOG_MODE_SYSTEM_MSG:
LOG_INFO(Lib_MsgDlg, "sceMsgDialogOpen systemMsg type: %s",
magic_enum::enum_name(param->sysMsgParam->sysMsgType));
break;
default:
break;
}
return ORBIS_OK;
}

View File

@ -242,10 +242,11 @@ void MemoryManager::UnmapMemory(VAddr virtual_addr, size_t size) {
vma.disallow_merge = false;
vma.name = "";
MergeAdjacent(vma_map, new_it);
bool readonly_file = vma.prot == MemoryProt::CpuRead && type == VMAType::File;
// Unmap the memory region.
impl.Unmap(vma_base_addr, vma_base_size, start_in_vma, start_in_vma + size, phys_base, is_exec,
has_backing);
has_backing, readonly_file);
TRACK_FREE(virtual_addr, "VMEM");
}

View File

@ -19,7 +19,6 @@
#include "core/file_sys/fs.h"
#include "core/libraries/disc_map/disc_map.h"
#include "core/libraries/kernel/thread_management.h"
#include "core/libraries/libc/libc.h"
#include "core/libraries/libc_internal/libc_internal.h"
#include "core/libraries/libs.h"
#include "core/libraries/ngs2/ngs2.h"
@ -52,6 +51,18 @@ Emulator::Emulator() {
LOG_INFO(Loader, "Branch {}", Common::g_scm_branch);
LOG_INFO(Loader, "Description {}", Common::g_scm_desc);
LOG_INFO(Config, "General isNeo: {}", Config::isNeoMode());
LOG_INFO(Config, "GPU isNullGpu: {}", Config::nullGpu());
LOG_INFO(Config, "GPU shouldDumpShaders: {}", Config::dumpShaders());
LOG_INFO(Config, "GPU shouldDumpPM4: {}", Config::dumpPM4());
LOG_INFO(Config, "GPU vblankDivider: {}", Config::vblankDiv());
LOG_INFO(Config, "Vulkan gpuId: {}", Config::getGpuId());
LOG_INFO(Config, "Vulkan vkValidation: {}", Config::vkValidationEnabled());
LOG_INFO(Config, "Vulkan vkValidationSync: {}", Config::vkValidationSyncEnabled());
LOG_INFO(Config, "Vulkan vkValidationGpu: {}", Config::vkValidationGpuEnabled());
LOG_INFO(Config, "Vulkan rdocEnable: {}", Config::isRdocEnabled());
LOG_INFO(Config, "Vulkan rdocMarkersEnable: {}", Config::isMarkersEnabled());
// Defer until after logging is initialized.
memory = Core::Memory::Instance();
controller = Common::Singleton<Input::GameController>::Instance();
@ -154,23 +165,14 @@ void Emulator::Run(const std::filesystem::path& file) {
// check if we have system modules to load
LoadSystemModules(file);
// Check if there is a libc.prx in sce_module folder
bool found = false;
if (Config::isLleLibc()) {
std::filesystem::path sce_module_folder = file.parent_path() / "sce_module";
if (std::filesystem::is_directory(sce_module_folder)) {
for (const auto& entry : std::filesystem::directory_iterator(sce_module_folder)) {
if (entry.path().filename() == "libc.prx") {
found = true;
}
LOG_INFO(Loader, "Loading {}", entry.path().string().c_str());
linker->LoadModule(entry.path());
}
// Load all prx from game's sce_module folder
std::filesystem::path sce_module_folder = file.parent_path() / "sce_module";
if (std::filesystem::is_directory(sce_module_folder)) {
for (const auto& entry : std::filesystem::directory_iterator(sce_module_folder)) {
LOG_INFO(Loader, "Loading {}", entry.path().string().c_str());
linker->LoadModule(entry.path());
}
}
if (!found) {
Libraries::LibC::libcSymbolsRegister(&linker->GetHLESymbols());
}
// start execution
std::jthread mainthread =

View File

@ -40,9 +40,6 @@
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="shad_title">
<property name="geometry">
@ -106,5 +103,6 @@
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -51,8 +51,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>832</width>
<height>418</height>
<width>836</width>
<height>428</height>
</rect>
</property>
<property name="sizePolicy">
@ -74,7 +74,7 @@
<item>
<layout class="QVBoxLayout" name="systemTabLayoutLeft">
<item>
<widget class="QGroupBox" name="emuSettings">
<widget class="QGroupBox" name="SystemSettings">
<property name="title">
<string>System</string>
</property>
@ -112,28 +112,11 @@
</property>
<layout class="QVBoxLayout" name="settingsLayout">
<item>
<widget class="QComboBox" name="consoleLanguageComboBox">
</widget>
<widget class="QComboBox" name="consoleLanguageComboBox"/>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="emulatorTabSpacerLeft">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@ -148,35 +131,39 @@
</property>
<layout class="QVBoxLayout" name="additionalSettingsVLayout">
<item>
<widget class="QCheckBox" name="fullscreenCheckBox">
<property name="text">
<string>Enable Fullscreen</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showSplashCheckBox">
<property name="text">
<string>Show Splash</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ps4proCheckBox">
<property name="text">
<string>Is PS4 Pro</string>
</property>
</widget>
<layout class="QVBoxLayout" name="emulatorverticalLayout">
<item>
<widget class="QCheckBox" name="fullscreenCheckBox">
<property name="text">
<string>Enable Fullscreen</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showSplashCheckBox">
<property name="text">
<string>Show Splash</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ps4proCheckBox">
<property name="text">
<string>Is PS4 Pro</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="emulatorSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
@ -261,19 +248,6 @@
</item>
</layout>
</item>
<item>
<spacer name="logSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@ -282,34 +256,29 @@
</layout>
</item>
<item>
<widget class="QWidget" name="widgetSettingsBottom" native="true">
<layout class="QHBoxLayout" name="widgetGpuBottomLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
<spacer name="generalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="gpuTab">
<widget class="QWidget" name="grphicsTab">
<attribute name="title">
<string>GPU</string>
<string>Graphics</string>
</attribute>
<layout class="QVBoxLayout" name="gpuTabVLayout" stretch="0">
<layout class="QVBoxLayout" name="graphicsTabVLayout" stretch="0,0">
<item>
<layout class="QHBoxLayout" name="gpuTabHLayout" stretch="1,1,1">
<layout class="QHBoxLayout" name="graphicsTabHLayout" stretch="1,1,1">
<item>
<layout class="QVBoxLayout" name="gpuTabLayoutLeft">
<layout class="QVBoxLayout" name="graphicsTabLayoutLeft">
<item>
<widget class="QGroupBox" name="graphicsAdapterGroupBox">
<property name="title">
@ -323,8 +292,8 @@
</widget>
</item>
<item>
<widget class="QWidget" name="widgetGpuTop" native="true">
<layout class="QHBoxLayout" name="widgetGpuTopHLayout">
<widget class="QWidget" name="widgetgraphicsBottom" native="true">
<layout class="QHBoxLayout" name="widgetgraphicsBottomHLayout">
<property name="leftMargin">
<number>0</number>
</property>
@ -340,44 +309,10 @@
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widgetGpuBottom" native="true">
<layout class="QHBoxLayout" name="widgetGpuBottomHLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item>
<spacer name="gpu_tab_layout_right_spacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="gpuTabLayoutMiddle">
<layout class="QVBoxLayout" name="graphicsTabLayoutMiddle">
<item>
<layout class="QVBoxLayout" name="layoutResolution">
<property name="spacing">
@ -505,26 +440,10 @@
</item>
</layout>
</item>
<item>
<spacer name="gpuTabLayoutMiddleSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="gpuTabLayoutRight">
<layout class="QVBoxLayout" name="graphicsTabLayoutRight">
<property name="rightMargin">
<number>12</number>
</property>
@ -534,7 +453,7 @@
<item>
<widget class="QGroupBox" name="additionalSettingsGroupBox">
<property name="title">
<string>Additional Settings</string>
<string>Advanced</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
@ -565,17 +484,14 @@
</widget>
</item>
<item>
<spacer name="additionalSettingsSpacer">
<spacer name="AdvancedSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
@ -584,6 +500,19 @@
</item>
</layout>
</item>
<item>
<spacer name="graphicSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="debugTab">

View File

@ -414,7 +414,13 @@ void WindowSDL::onGamepadEvent(const SDL_Event* event) {
: event->gaxis.axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER ? Input::Axis::TriggerRight
: Input::Axis::AxisMax;
if (axis != Input::Axis::AxisMax) {
controller->Axis(0, axis, Input::GetAxis(-0x8000, 0x8000, event->gaxis.value));
if (event->gaxis.axis == SDL_GAMEPAD_AXIS_LEFT_TRIGGER ||
event->gaxis.axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) {
controller->Axis(0, axis, Input::GetAxis(0, 0x8000, event->gaxis.value));
} else {
controller->Axis(0, axis, Input::GetAxis(-0x8000, 0x8000, event->gaxis.value));
}
}
break;
}

View File

@ -101,7 +101,7 @@ struct fmt::formatter<Shader::IR::Opcode> {
return ctx.begin();
}
template <typename FormatContext>
auto format(const Shader::IR::Opcode& op, FormatContext& ctx) const {
auto format(const Shader::IR::Opcode op, FormatContext& ctx) const {
return fmt::format_to(ctx.out(), "{}", Shader::IR::NameOf(op));
}
};

View File

@ -848,6 +848,7 @@ struct Liverpool {
u32 raw;
BitField<0, 1, u32> depth_clear_enable;
BitField<1, 1, u32> stencil_clear_enable;
BitField<5, 1, u32> stencil_compress_disable;
BitField<6, 1, u32> depth_compress_disable;
};

View File

@ -5,6 +5,8 @@
#include "video_core/amdgpu/pixel_format.h"
#include "video_core/renderer_vulkan/liverpool_to_vk.h"
#include <magic_enum.hpp>
namespace Vulkan::LiverpoolToVK {
using DepthBuffer = Liverpool::DepthBuffer;
@ -588,6 +590,8 @@ vk::Format AdjustColorBufferFormat(vk::Format base_format,
return is_vo_surface ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8A8Srgb;
case vk::Format::eB8G8R8A8Srgb:
return is_vo_surface ? vk::Format::eR8G8B8A8Unorm : vk::Format::eR8G8B8A8Srgb;
default:
break;
}
} else {
if (is_vo_surface && base_format == vk::Format::eR8G8B8A8Srgb) {
@ -601,27 +605,29 @@ vk::Format AdjustColorBufferFormat(vk::Format base_format,
}
vk::Format DepthFormat(DepthBuffer::ZFormat z_format, DepthBuffer::StencilFormat stencil_format) {
if (z_format == DepthBuffer::ZFormat::Z32Float &&
stencil_format == DepthBuffer::StencilFormat::Stencil8) {
using ZFormat = DepthBuffer::ZFormat;
using StencilFormat = DepthBuffer::StencilFormat;
if (z_format == ZFormat::Z32Float && stencil_format == StencilFormat::Stencil8) {
return vk::Format::eD32SfloatS8Uint;
}
if (z_format == DepthBuffer::ZFormat::Z32Float &&
stencil_format == DepthBuffer::StencilFormat::Invalid) {
if (z_format == ZFormat::Z32Float && stencil_format == StencilFormat::Invalid) {
return vk::Format::eD32Sfloat;
}
if (z_format == DepthBuffer::ZFormat::Z16 &&
stencil_format == DepthBuffer::StencilFormat::Invalid) {
if (z_format == ZFormat::Z16 && stencil_format == StencilFormat::Invalid) {
return vk::Format::eD16Unorm;
}
if (z_format == DepthBuffer::ZFormat::Z16 &&
stencil_format == DepthBuffer::StencilFormat::Stencil8) {
if (z_format == ZFormat::Z16 && stencil_format == StencilFormat::Stencil8) {
return vk::Format::eD16UnormS8Uint;
}
if (z_format == DepthBuffer::ZFormat::Invalid &&
stencil_format == DepthBuffer::StencilFormat::Invalid) {
if (z_format == ZFormat::Invalid && stencil_format == StencilFormat::Stencil8) {
return vk::Format::eD32SfloatS8Uint;
}
if (z_format == ZFormat::Invalid && stencil_format == StencilFormat::Invalid) {
return vk::Format::eUndefined;
}
UNREACHABLE();
UNREACHABLE_MSG("Unsupported depth/stencil format. depth = {} stencil = {}",
magic_enum::enum_name(z_format), magic_enum::enum_name(stencil_format));
}
void EmitQuadToTriangleListIndices(u8* out_ptr, u32 num_vertices) {

View File

@ -214,8 +214,7 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul
.colorAttachmentCount = num_color_formats,
.pColorAttachmentFormats = key.color_formats.data(),
.depthAttachmentFormat = key.depth_format,
.stencilAttachmentFormat =
key.depth.stencil_enable ? key.depth_format : vk::Format::eUndefined,
.stencilAttachmentFormat = key.stencil_format,
};
std::array<vk::PipelineColorBlendAttachmentState, Liverpool::NumColorBuffers> attachments;

View File

@ -26,6 +26,7 @@ struct GraphicsPipelineKey {
std::array<size_t, MaxShaderStages> stage_hashes;
std::array<vk::Format, Liverpool::NumColorBuffers> color_formats;
vk::Format depth_format;
vk::Format stencil_format;
Liverpool::DepthControl depth;
float depth_bounds_min;

View File

@ -180,11 +180,26 @@ void PipelineCache::RefreshGraphicsKey() {
key.num_samples = regs.aa_config.NumSamples();
const auto& db = regs.depth_buffer;
key.depth_format = LiverpoolToVK::DepthFormat(db.z_info.format, db.stencil_info.format);
const auto ds_format = LiverpoolToVK::DepthFormat(db.z_info.format, db.stencil_info.format);
if (db.z_info.format != AmdGpu::Liverpool::DepthBuffer::ZFormat::Invalid) {
key.depth_format = ds_format;
} else {
key.depth_format = vk::Format::eUndefined;
}
if (key.depth.depth_enable) {
key.depth.depth_enable.Assign(key.depth_format != vk::Format::eUndefined);
}
if (db.stencil_info.format != AmdGpu::Liverpool::DepthBuffer::StencilFormat::Invalid) {
key.stencil_format = key.depth_format;
} else {
key.stencil_format = vk::Format::eUndefined;
}
if (key.depth.stencil_enable) {
key.depth.stencil_enable.Assign(key.stencil_format != vk::Format::eUndefined);
}
const auto skip_cb_binding =
regs.color_control.mode == AmdGpu::Liverpool::ColorControl::OperationMode::Disable;

View File

@ -10,6 +10,7 @@
#include "video_core/renderer_vulkan/vk_scheduler.h"
#include "video_core/texture_cache/image_view.h"
#include "video_core/texture_cache/texture_cache.h"
#include "vk_rasterizer.h"
namespace Vulkan {
@ -129,8 +130,12 @@ void Rasterizer::BeginRendering() {
texture_cache.TouchMeta(col_buf.CmaskAddress(), false);
}
if (regs.depth_buffer.z_info.format != Liverpool::DepthBuffer::ZFormat::Invalid &&
regs.depth_buffer.Address() != 0) {
using ZFormat = AmdGpu::Liverpool::DepthBuffer::ZFormat;
using StencilFormat = AmdGpu::Liverpool::DepthBuffer::StencilFormat;
if (regs.depth_buffer.Address() != 0 &&
((regs.depth_control.depth_enable && regs.depth_buffer.z_info.format != ZFormat::Invalid) ||
regs.depth_control.stencil_enable &&
regs.depth_buffer.stencil_info.format != StencilFormat::Invalid)) {
const auto htile_address = regs.depth_htile_data_base.GetAddress();
const bool is_clear = regs.depth_render_control.depth_clear_enable ||
texture_cache.IsMetaCleared(htile_address);
@ -152,8 +157,10 @@ void Rasterizer::BeginRendering() {
.stencil = regs.stencil_clear}},
};
texture_cache.TouchMeta(htile_address, false);
state.has_depth = true;
state.has_stencil = regs.depth_control.stencil_enable;
state.has_depth =
regs.depth_buffer.z_info.format != AmdGpu::Liverpool::DepthBuffer::ZFormat::Invalid;
state.has_stencil = regs.depth_buffer.stencil_info.format !=
AmdGpu::Liverpool::DepthBuffer::StencilFormat::Invalid;
}
scheduler.BeginRendering(state);
}

View File

@ -29,15 +29,22 @@ void Scheduler::BeginRendering(const RenderState& new_state) {
is_rendering = true;
render_state = new_state;
const auto witdh =
render_state.width != std::numeric_limits<u32>::max() ? render_state.width : 1;
const auto height =
render_state.height != std::numeric_limits<u32>::max() ? render_state.height : 1;
const vk::RenderingInfo rendering_info = {
.renderArea =
{
.offset = {0, 0},
.extent = {render_state.width, render_state.height},
.extent = {witdh, height},
},
.layerCount = 1,
.colorAttachmentCount = render_state.num_color_attachments,
.pColorAttachments = render_state.color_attachments.data(),
.pColorAttachments = render_state.num_color_attachments > 0
? render_state.color_attachments.data()
: nullptr,
.pDepthAttachment = render_state.has_depth ? &render_state.depth_attachment : nullptr,
.pStencilAttachment = render_state.has_stencil ? &render_state.depth_attachment : nullptr,
};
@ -72,7 +79,7 @@ void Scheduler::EndRendering() {
},
});
}
if (render_state.has_depth) {
if (render_state.has_depth || render_state.has_stencil) {
barriers.push_back(vk::ImageMemoryBarrier{
.srcAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentWrite,
.dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite,

View File

@ -131,11 +131,19 @@ Image::Image(const Vulkan::Instance& instance_, Vulkan::Scheduler& scheduler_,
usage = ImageUsageFlags(info);
if (info.pixel_format == vk::Format::eD32Sfloat) {
switch (info.pixel_format) {
case vk::Format::eD16Unorm:
case vk::Format::eD32Sfloat:
case vk::Format::eX8D24UnormPack32:
aspect_mask = vk::ImageAspectFlagBits::eDepth;
}
if (info.pixel_format == vk::Format::eD32SfloatS8Uint) {
break;
case vk::Format::eD16UnormS8Uint:
case vk::Format::eD24UnormS8Uint:
case vk::Format::eD32SfloatS8Uint:
aspect_mask = vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil;
break;
default:
break;
}
const vk::ImageCreateInfo image_ci = {