Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y ninja-build libgl-dev libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
sudo apt-get install -y ninja-build libgl-dev libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev pkg-config libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev
- name: Configure
run: |
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{VITASDK})
endif()
endif()

project("PS2 Retro X")
project(PS2RetroX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down
27 changes: 27 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
}
]
}
11 changes: 2 additions & 9 deletions ps2xRecomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ include(FetchContent)
FetchContent_Declare(
elfio
GIT_REPOSITORY https://github.com/serge1/ELFIO.git
GIT_TAG 7d30a22fc5aac06adfe7887ae57f3701b6b5f913
GIT_TAG Release_3.12
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(elfio)

FetchContent_Declare(
toml11
GIT_REPOSITORY https://github.com/ToruNiina/toml11.git
GIT_TAG master
GIT_TAG v4.4.0
)
FetchContent_MakeAvailable(toml11)

Expand All @@ -38,13 +38,6 @@ FetchContent_Declare(
GIT_SHALLOW TRUE
)

FetchContent_Declare(
libdwarf
GIT_REPOSITORY https://github.com/davea42/libdwarf-code.git
GIT_TAG v2.2.0
GIT_SHALLOW TRUE
)

set(BUILD_DWARFDUMP OFF CACHE BOOL "" FORCE)
set(BUILD_DWARFEXAMPLE OFF CACHE BOOL "" FORCE)
set(BUILD_DWARFGEN OFF CACHE BOOL "" FORCE)
Expand Down
137 changes: 135 additions & 2 deletions ps2xRuntime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,128 @@ else()
target_link_libraries(ps2_host_backend INTERFACE raylib)
endif()

if(WIN32)
include(ExternalProject)

set(FFMPEG_PREBUILT_TAG "n7.1-241205")
set(FFMPEG_PREBUILT_URL
"https://github.com/System233/ffmpeg-msvc-prebuilt/releases/download/${FFMPEG_PREBUILT_TAG}/ffmpeg-${FFMPEG_PREBUILT_TAG}-lgpl-amd64-shared.zip")

set(FFMPEG_PREFIX_DIR "${CMAKE_BINARY_DIR}/ThirdParty/ffmpeg-prefix")
set(FFMPEG_SOURCE_DIR "${FFMPEG_PREFIX_DIR}/src/ffmpeg_external")
set(FFMPEG_INCLUDE_DIR "${FFMPEG_SOURCE_DIR}/include")
set(FFMPEG_LIB_DIR "${FFMPEG_SOURCE_DIR}/bin")
set(FFMPEG_BIN_DIR "${FFMPEG_SOURCE_DIR}/bin")

ExternalProject_Add(ffmpeg_external
URL "${FFMPEG_PREBUILT_URL}"
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
PREFIX "${FFMPEG_PREFIX_DIR}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
BUILD_BYPRODUCTS
"${FFMPEG_LIB_DIR}/avcodec.lib"
"${FFMPEG_LIB_DIR}/avformat.lib"
"${FFMPEG_LIB_DIR}/avutil.lib"
"${FFMPEG_LIB_DIR}/swresample.lib"
"${FFMPEG_LIB_DIR}/swscale.lib"
)

# Link against the import libraries shipped with the Windows DLLs.
add_library(ffmpeg_avcodec STATIC IMPORTED GLOBAL)
set_target_properties(ffmpeg_avcodec PROPERTIES
IMPORTED_LOCATION "${FFMPEG_LIB_DIR}/avcodec.lib"
INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}"
)
add_dependencies(ffmpeg_avcodec ffmpeg_external)

add_library(ffmpeg_avformat STATIC IMPORTED GLOBAL)
set_target_properties(ffmpeg_avformat PROPERTIES
IMPORTED_LOCATION "${FFMPEG_LIB_DIR}/avformat.lib"
INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}"
)
add_dependencies(ffmpeg_avformat ffmpeg_external)

add_library(ffmpeg_avutil STATIC IMPORTED GLOBAL)
set_target_properties(ffmpeg_avutil PROPERTIES
IMPORTED_LOCATION "${FFMPEG_LIB_DIR}/avutil.lib"
INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}"
)
add_dependencies(ffmpeg_avutil ffmpeg_external)

add_library(ffmpeg_swresample STATIC IMPORTED GLOBAL)
set_target_properties(ffmpeg_swresample PROPERTIES
IMPORTED_LOCATION "${FFMPEG_LIB_DIR}/swresample.lib"
INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}"
)
add_dependencies(ffmpeg_swresample ffmpeg_external)

add_library(ffmpeg_swscale STATIC IMPORTED GLOBAL)
set_target_properties(ffmpeg_swscale PROPERTIES
IMPORTED_LOCATION "${FFMPEG_LIB_DIR}/swscale.lib"
INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_INCLUDE_DIR}"
)
add_dependencies(ffmpeg_swscale ffmpeg_external)

add_library(ffmpeg INTERFACE)
target_link_libraries(ffmpeg INTERFACE
ffmpeg_avcodec
ffmpeg_avformat
ffmpeg_avutil
ffmpeg_swresample
ffmpeg_swscale
bcrypt
secur32
ws2_32
user32
advapi32
ole32
shell32
)

set(PS2X_FFMPEG_BIN_DIR "${FFMPEG_BIN_DIR}" CACHE INTERNAL "Directory containing FFmpeg runtime DLLs")
set(PS2X_COPY_FFMPEG_DLLS_SCRIPT
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyFfmpegDlls.cmake"
CACHE INTERNAL
"Script used to stage FFmpeg runtime DLLs beside executables")
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(FFMPEG REQUIRED IMPORTED_TARGET GLOBAL
libavcodec
libavformat
libavutil
libswresample
libswscale
)

add_library(ffmpeg INTERFACE)
target_link_libraries(ffmpeg INTERFACE PkgConfig::FFMPEG)
endif()

function(ps2x_stage_ffmpeg_runtime_dlls target_name)
if(NOT WIN32)
return()
endif()

if(NOT PS2X_FFMPEG_BIN_DIR OR NOT PS2X_COPY_FFMPEG_DLLS_SCRIPT)
return()
endif()

if(TARGET ffmpeg_external)
add_dependencies(${target_name} ffmpeg_external)
endif()

add_custom_command(
TARGET ${target_name} POST_BUILD
COMMAND "${CMAKE_COMMAND}"
"-Dsource_dir=${PS2X_FFMPEG_BIN_DIR}"
"-Ddest_dir=$<TARGET_FILE_DIR:${target_name}>"
-P "${PS2X_COPY_FFMPEG_DLLS_SCRIPT}"
VERBATIM
)
endfunction()

add_library(ps2_runtime STATIC
src/lib/game_overrides.cpp
src/lib/ps2_gif_arbiter.cpp
Expand Down Expand Up @@ -225,12 +347,14 @@ target_include_directories(ps2_runtime PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/lib/Kernel
)

target_link_libraries(ps2_runtime PUBLIC ps2_host_backend)
target_link_libraries(ps2_runtime PUBLIC ps2_host_backend ffmpeg)
target_link_libraries(ps2EntryRunner
PRIVATE
ps2_runtime
)

ps2x_stage_ffmpeg_runtime_dlls(ps2EntryRunner)

if(PS2X_IS_VITA)
set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d PARENTAL_LEVEL=1")

Expand Down Expand Up @@ -265,11 +389,20 @@ if(MSVC)
target_link_options(ps2EntryRunner PRIVATE "/FORCE:MULTIPLE")
endif()

install(TARGETS ps2_runtime
install(TARGETS ps2_runtime ps2EntryRunner
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

if(WIN32)
install(DIRECTORY "${FFMPEG_BIN_DIR}/"
DESTINATION bin
FILES_MATCHING
PATTERN "*.dll"
)
endif()

install(DIRECTORY include/
DESTINATION include
)
24 changes: 24 additions & 0 deletions ps2xRuntime/cmake/CopyFfmpegDlls.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if(NOT DEFINED source_dir OR source_dir STREQUAL "")
message(FATAL_ERROR "CopyFfmpegDlls.cmake requires -Dsource_dir=<ffmpeg bin dir>")
endif()

if(NOT DEFINED dest_dir OR dest_dir STREQUAL "")
message(FATAL_ERROR "CopyFfmpegDlls.cmake requires -Ddest_dir=<target output dir>")
endif()

file(GLOB ffmpeg_runtime_dlls "${source_dir}/*.dll")
if(NOT ffmpeg_runtime_dlls)
message(FATAL_ERROR "No FFmpeg runtime DLLs found in '${source_dir}'")
endif()

file(MAKE_DIRECTORY "${dest_dir}")

foreach(ffmpeg_runtime_dll IN LISTS ffmpeg_runtime_dlls)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${ffmpeg_runtime_dll}" "${dest_dir}"
RESULT_VARIABLE copy_result
)
if(NOT copy_result EQUAL 0)
message(FATAL_ERROR "Failed to copy '${ffmpeg_runtime_dll}' to '${dest_dir}'")
endif()
endforeach()
2 changes: 1 addition & 1 deletion ps2xRuntime/include/ps2_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define PS2_AGRESSIVE_LOGS_ENABLED 0
#endif

#if defined(_DEBUG)
#if defined(PS2_RUNTIME_LOGS) || defined(AGRESSIVE_LOGS)
#define RUNTIME_LOG(x) do { std::cout << x; } while (0)
#else
#define RUNTIME_LOG(x) do {} while(0)
Expand Down
2 changes: 2 additions & 0 deletions ps2xRuntime/include/ps2_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,13 @@ class PS2Runtime
std::unordered_map<uint32_t, RecompiledFunction> m_functionTable;
std::atomic<bool> m_stopRequested{false};

public:
// TODO remove this later
std::atomic<uint32_t> m_debugPc{0};
std::atomic<uint32_t> m_debugRa{0};
std::atomic<uint32_t> m_debugSp{0};
std::atomic<uint32_t> m_debugGp{0};
private:

struct LoadedModule
{
Expand Down
26 changes: 0 additions & 26 deletions ps2xRuntime/include/ps2_stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,11 @@ class PS2Runtime;
#include "runtime/ps2_memory.h"
#include "Stubs/Unimplemented.h"

struct PS2MpegCompatLayout
{
uint32_t mpegObjectAddr = 0;
uint32_t videoStateAddr = 0;
uint32_t movieStateAddr = 0;
uint32_t syntheticFramesBeforeEnd = 1u;
uint32_t playingVideoStateValue = 0u;
uint32_t playingMovieStateValue = 2u;
uint32_t finishedVideoStateValue = 3u;
uint32_t finishedMovieStateValue = 3u;

[[nodiscard]] bool matchesMpegObject(uint32_t addr) const
{
return mpegObjectAddr != 0u && ((addr & PS2_RAM_MASK) == (mpegObjectAddr & PS2_RAM_MASK));
}

[[nodiscard]] bool hasFinishTargets() const
{
return videoStateAddr != 0u || movieStateAddr != 0u;
}
};


namespace ps2_stubs
{
#define PS2_DECLARE_STUB(name) void name(uint8_t *rdram, R5900Context *ctx, PS2Runtime *runtime);
PS2_STUB_LIST(PS2_DECLARE_STUB)
#undef PS2_DECLARE_STUB

void resetSifState();

void setMpegCompatLayout(const PS2MpegCompatLayout &layout);
void clearMpegCompatLayout();
}
2 changes: 2 additions & 0 deletions ps2xRuntime/include/runtime/ps2_gs_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class GS
}
bool getPreferredDisplaySource(GSFrameReg &outSource, uint32_t &outDestFbp) const;
void latchHostPresentationFrame();
bool tryLatchHostPresentationFrame();
bool copyLatchedHostPresentationFrame(std::vector<uint8_t> &outPixels,
uint32_t &outWidth,
uint32_t &outHeight,
Expand All @@ -253,6 +254,7 @@ class GS
void snapshotVRAM();
void writeRegisterPacked(uint8_t regDesc, uint64_t lo, uint64_t hi);
void vertexKick(bool drawing);
void latchHostPresentationFrameUnlocked();

void processImageData(const uint8_t *data, uint32_t sizeBytes);
void performLocalToLocalTransfer();
Expand Down
Loading
Loading