Skip to content

Commit

Permalink
libretro port
Browse files Browse the repository at this point in the history
  • Loading branch information
aliaspider committed Mar 22, 2023
1 parent f73a2d5 commit 5cdca08
Show file tree
Hide file tree
Showing 61 changed files with 6,082 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 3
NamespaceIndentation: All
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
Expand Down
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,14 @@ oprofile_data/
CMakeSettings.json
/ci-artifacts/
/out/

bin/*
build*/
*.cflags
*.config
*.creator
*.creator.user.*
*.cxxflags
*.files
*.includes
*.autosave
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ include(Pcsx2Utils)
check_no_parenthesis_in_path()
detectOperatingSystem()
check_compiler_version("7.0" "7.0")
if(NOT MSVC)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_FOUND})
endif()
endif()

#-------------------------------------------------------------------------------
# Include specific module
Expand Down Expand Up @@ -60,6 +67,10 @@ if (QT_BUILD)
endif()
endif()

if(LIBRETRO)
add_subdirectory(libretro)
endif()

# tests
if(ACTUALLY_ENABLE_TESTS)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
Expand Down
42 changes: 42 additions & 0 deletions cmake/BuildParameters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@ set(PCSX2_DEFS "")
#-------------------------------------------------------------------------------
option(DISABLE_BUILD_DATE "Disable including the binary compile date")
option(ENABLE_TESTS "Enables building the unit tests" ON)
option(LIBRETRO "Enables building the libretro core" OFF)
set(USE_SYSTEM_LIBS "AUTO" CACHE STRING "Use system libraries instead of bundled libraries. ON - Always use system and fail if unavailable, OFF - Always use bundled, AUTO - Use system if available, otherwise use bundled. Default is AUTO")
optional_system_library(fmt)
optional_system_library(ryml)
optional_system_library(zstd)
optional_system_library(libzip)
optional_system_library(SDL2)
option(LTO_PCSX2_CORE "Enable LTO/IPO/LTCG on the subset of pcsx2 that benefits most from it but not anything else")

if(LIBRETRO)
set(ENABLE_TESTS OFF)
set(CMAKE_BUILD_PO FALSE)
set(BUILD_REPLAY_LOADERS FALSE)
set(CUBEB_API FALSE)
set(DISABLE_SETCAP TRUE)
set(USE_VULKAN FALSE)
set(USE_DISCORD_PRESENCE FALSE)
set(USE_ACHIEVEMENTS OFF)
set(QT_BUILD OFF)
add_definitions(-D__LIBRETRO__ -DwxUSE_GUI=0)
endif()

option(USE_VTUNE "Plug VTUNE to profile GS JIT.")
option(USE_ACHIEVEMENTS "Build with RetroAchievements support" ON)
option(USE_DISCORD_PRESENCE "Enable support for Discord Rich Presence" ON)
Expand Down Expand Up @@ -135,6 +150,32 @@ endif()
string(REPLACE " " ";" ARCH_FLAG_LIST "${ARCH_FLAG}")
add_compile_options("${ARCH_FLAG_LIST}")

#if(MSVC)
# set(ARCH_FLAG)
# # add_compile_options(/permissive-)
# # add_compile_options(/Zc:inline)
# # add_compile_options(/Zc:throwingNew)
# # add_compile_options(/volatile:iso)
# #string(APPEND CMAKE_EXE_LINKER_FLAGS " /NXCOMPAT")
## add_compile_options(/EHsc)
# add_compile_options(/EHa)
# add_compile_options(/MP)
# if(CMAKE_BUILD_TYPE MATCHES "Release")
# add_definitions(-DNDEBUG)
# else()
# if(CMAKE_BUILD_TYPE MATCHES "Debug")
# add_definitions(-D_DEBUG -DPCSX2_DEVBUILD -DPCSX2_DEBUG)
# else()
# add_definitions(-DNDEBUG -DPCSX2_DEVBUILD -D_DEVEL)
# endif()
# add_compile_options(/Zi)
# add_link_options(/DEBUG)
# endif()
# add_definitions(-D__WIN32__ -DWIN32 -D_WINDOWS -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE)
# add_definitions(${PLUGIN_SUPPORT})
# add_definitions(-D_ARCH_64=1 -D_M_X86_64 -D__M_X86_64)
# add_definitions(/wd4063 /wd4100 /wd4267 /wd4244 /wd4244 /wd4312 /wd4334)
#else(MSVC)
#-------------------------------------------------------------------------------
# Set some default compiler flags
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -238,6 +279,7 @@ endif()
if(USE_PGO_OPTIMIZE)
add_compile_options(-fprofile-use)
endif()
#endif(MSVC)

list(APPEND PCSX2_DEFS
"$<$<CONFIG:Debug>:PCSX2_DEVBUILD;PCSX2_DEBUG;_DEBUG>"
Expand Down
11 changes: 11 additions & 0 deletions cmake/SearchForStuff.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ else()
find_package(ZLIB REQUIRED)

## Use pcsx2 package to find module
# if (NOT MSVC)
include(FindLibc)
# endif()

## Use CheckLib package to find module
include(CheckLib)
Expand Down Expand Up @@ -89,6 +91,15 @@ else()
endif()
endif(WIN32)

#if(MSVC)
# add_definitions(-DPTW32_STATIC_LIB)
## add_definitions(-D__CLEANUP_SEH)
# add_subdirectory(${CMAKE_SOURCE_DIR}/3rdparty/pthreads4w)
# include_directories(${CMAKE_SOURCE_DIR}/3rdparty/pthreads4w/include)
# add_subdirectory(${CMAKE_SOURCE_DIR}/3rdparty/baseclasses)
## include_directories(${CMAKE_SOURCE_DIR}/3rdparty/baseclasses)
#endif()

# Require threads on all OSes.
find_package(Threads REQUIRED)

Expand Down
2 changes: 1 addition & 1 deletion common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,6 @@ target_include_directories(common PUBLIC ../3rdparty/include ../)
target_compile_definitions(common PUBLIC "${PCSX2_DEFS}")
target_compile_options(common PRIVATE "${PCSX2_WARNINGS}")

if(COMMAND target_precompile_headers)
if(COMMAND target_precompile_headers AND NOT CCACHE_FOUND)
target_precompile_headers(common PRIVATE PrecompiledHeader.h)
endif()
8 changes: 7 additions & 1 deletion common/GL/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include <malloc.h>
#endif

#if defined(_WIN32) && !defined(_M_ARM64)
#if defined(__LIBRETRO__)
#include "common/GL/ContextRetroGL.h"
#elif defined(_WIN32) && !defined(_M_ARM64)
#include "common/GL/ContextWGL.h"
#elif defined(__APPLE__)
#include "common/GL/ContextAGL.h"
Expand Down Expand Up @@ -100,6 +102,9 @@ namespace GL
}

std::unique_ptr<Context> context;
#if defined(__LIBRETRO__)
context = ContextRetroGL::Create(wi, versions_to_try);
#else
#if defined(_WIN32) && !defined(_M_ARM64)
context = ContextWGL::Create(wi, versions_to_try);
#elif defined(__APPLE__)
Expand All @@ -114,6 +119,7 @@ namespace GL
#if defined(WAYLAND_API)
if (wi.type == WindowInfo::Type::Wayland)
context = ContextEGLWayland::Create(wi, versions_to_try);
#endif
#endif

if (!context)
Expand Down
93 changes: 93 additions & 0 deletions common/GL/ContextRetroGL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2021 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/

#include "common/PrecompiledHeader.h"

#include "common/Console.h"
#include "ContextRetroGL.h"
#include <optional>
#include <vector>
#include "common/WindowInfo.h"
#include "GS/Renderers/Common/GSDevice.h"
#include "GS/GSVector.h"

#include <libretro.h>
extern retro_video_refresh_t video_cb;
extern retro_hw_render_callback hw_render;

namespace GL
{
ContextRetroGL::ContextRetroGL(const WindowInfo& wi)
: Context(wi)
{
}

ContextRetroGL::~ContextRetroGL()
{
}

std::unique_ptr<Context> ContextRetroGL::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try)
{
std::unique_ptr<ContextRetroGL> context = std::make_unique<ContextRetroGL>(wi);
return context;
}

void* ContextRetroGL::GetProcAddress(const char* name)
{
return reinterpret_cast<void*>(hw_render.get_proc_address(name));
}

bool ContextRetroGL::ChangeSurface(const WindowInfo& new_wi)
{
return true;
}

void ContextRetroGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_height /*= 0*/)
{
m_wi.surface_width = new_surface_width;
m_wi.surface_height = new_surface_height;
}

bool ContextRetroGL::SwapBuffers()
{
if(g_gs_device->GetCurrent())
video_cb(RETRO_HW_FRAME_BUFFER_VALID, g_gs_device->GetCurrent()->GetWidth(), g_gs_device->GetCurrent()->GetHeight(), 0);
else
video_cb(NULL, 640, 480, 0);
return true;
}

bool ContextRetroGL::MakeCurrent()
{
return true;
}

bool ContextRetroGL::DoneCurrent()
{
return true;
}

bool ContextRetroGL::SetSwapInterval(s32 interval)
{
return true;
}

std::unique_ptr<Context> ContextRetroGL::CreateSharedContext(const WindowInfo& wi)
{
std::unique_ptr<ContextRetroGL> context = std::make_unique<ContextRetroGL>(wi);
return context;
}

} // namespace GL
40 changes: 40 additions & 0 deletions common/GL/ContextRetroGL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2021 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "common/GL/Context.h"

namespace GL
{
class ContextRetroGL : public Context
{
public:
ContextRetroGL(const WindowInfo& wi);
~ContextRetroGL() override;

static std::unique_ptr<Context> Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try);

void* GetProcAddress(const char* name) override;
virtual bool ChangeSurface(const WindowInfo& new_wi) override;
virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
bool SwapBuffers() override;
bool MakeCurrent() override;
bool DoneCurrent() override;
bool SetSwapInterval(s32 interval) override;
virtual std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) override;
};

} // namespace GL
1 change: 1 addition & 0 deletions common/Perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#pragma once

#include <cstdio>
#include <vector>
#include <cstdio>
#include "common/Pcsx2Types.h"
Expand Down
1 change: 1 addition & 0 deletions common/Vulkan/Builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/

#include <limits>
#include "common/Vulkan/Builders.h"
#include "common/Vulkan/Util.h"
#include "common/Assertions.h"
Expand Down
3 changes: 2 additions & 1 deletion common/WindowInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ struct WindowInfo
Win32,
X11,
Wayland,
MacOS
MacOS,
Libretro
};

/// The type of the surface. Surfaceless indicates it will not be displayed on screen at all.
Expand Down
Loading

0 comments on commit 5cdca08

Please sign in to comment.