Skip to content

Commit 5cdca08

Browse files
committed
libretro port
1 parent f73a2d5 commit 5cdca08

61 files changed

Lines changed: 6082 additions & 46 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ KeepEmptyLinesAtTheStartOfBlocks: true
6161
MacroBlockBegin: ''
6262
MacroBlockEnd: ''
6363
MaxEmptyLinesToKeep: 3
64-
NamespaceIndentation: All
64+
NamespaceIndentation: None
6565
ObjCBlockIndentWidth: 2
6666
ObjCSpaceAfterProperty: false
6767
ObjCSpaceBeforeProtocolList: true

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,14 @@ oprofile_data/
9999
CMakeSettings.json
100100
/ci-artifacts/
101101
/out/
102+
103+
bin/*
104+
build*/
105+
*.cflags
106+
*.config
107+
*.creator
108+
*.creator.user.*
109+
*.cxxflags
110+
*.files
111+
*.includes
112+
*.autosave

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ include(Pcsx2Utils)
3232
check_no_parenthesis_in_path()
3333
detectOperatingSystem()
3434
check_compiler_version("7.0" "7.0")
35+
if(NOT MSVC)
36+
find_program(CCACHE_FOUND ccache)
37+
if(CCACHE_FOUND)
38+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND})
39+
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_FOUND})
40+
endif()
41+
endif()
3542

3643
#-------------------------------------------------------------------------------
3744
# Include specific module
@@ -60,6 +67,10 @@ if (QT_BUILD)
6067
endif()
6168
endif()
6269

70+
if(LIBRETRO)
71+
add_subdirectory(libretro)
72+
endif()
73+
6374
# tests
6475
if(ACTUALLY_ENABLE_TESTS)
6576
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

cmake/BuildParameters.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,28 @@ set(PCSX2_DEFS "")
66
#-------------------------------------------------------------------------------
77
option(DISABLE_BUILD_DATE "Disable including the binary compile date")
88
option(ENABLE_TESTS "Enables building the unit tests" ON)
9+
option(LIBRETRO "Enables building the libretro core" OFF)
910
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")
1011
optional_system_library(fmt)
1112
optional_system_library(ryml)
1213
optional_system_library(zstd)
1314
optional_system_library(libzip)
1415
optional_system_library(SDL2)
1516
option(LTO_PCSX2_CORE "Enable LTO/IPO/LTCG on the subset of pcsx2 that benefits most from it but not anything else")
17+
18+
if(LIBRETRO)
19+
set(ENABLE_TESTS OFF)
20+
set(CMAKE_BUILD_PO FALSE)
21+
set(BUILD_REPLAY_LOADERS FALSE)
22+
set(CUBEB_API FALSE)
23+
set(DISABLE_SETCAP TRUE)
24+
set(USE_VULKAN FALSE)
25+
set(USE_DISCORD_PRESENCE FALSE)
26+
set(USE_ACHIEVEMENTS OFF)
27+
set(QT_BUILD OFF)
28+
add_definitions(-D__LIBRETRO__ -DwxUSE_GUI=0)
29+
endif()
30+
1631
option(USE_VTUNE "Plug VTUNE to profile GS JIT.")
1732
option(USE_ACHIEVEMENTS "Build with RetroAchievements support" ON)
1833
option(USE_DISCORD_PRESENCE "Enable support for Discord Rich Presence" ON)
@@ -135,6 +150,32 @@ endif()
135150
string(REPLACE " " ";" ARCH_FLAG_LIST "${ARCH_FLAG}")
136151
add_compile_options("${ARCH_FLAG_LIST}")
137152

153+
#if(MSVC)
154+
# set(ARCH_FLAG)
155+
# # add_compile_options(/permissive-)
156+
# # add_compile_options(/Zc:inline)
157+
# # add_compile_options(/Zc:throwingNew)
158+
# # add_compile_options(/volatile:iso)
159+
# #string(APPEND CMAKE_EXE_LINKER_FLAGS " /NXCOMPAT")
160+
## add_compile_options(/EHsc)
161+
# add_compile_options(/EHa)
162+
# add_compile_options(/MP)
163+
# if(CMAKE_BUILD_TYPE MATCHES "Release")
164+
# add_definitions(-DNDEBUG)
165+
# else()
166+
# if(CMAKE_BUILD_TYPE MATCHES "Debug")
167+
# add_definitions(-D_DEBUG -DPCSX2_DEVBUILD -DPCSX2_DEBUG)
168+
# else()
169+
# add_definitions(-DNDEBUG -DPCSX2_DEVBUILD -D_DEVEL)
170+
# endif()
171+
# add_compile_options(/Zi)
172+
# add_link_options(/DEBUG)
173+
# endif()
174+
# add_definitions(-D__WIN32__ -DWIN32 -D_WINDOWS -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE)
175+
# add_definitions(${PLUGIN_SUPPORT})
176+
# add_definitions(-D_ARCH_64=1 -D_M_X86_64 -D__M_X86_64)
177+
# add_definitions(/wd4063 /wd4100 /wd4267 /wd4244 /wd4244 /wd4312 /wd4334)
178+
#else(MSVC)
138179
#-------------------------------------------------------------------------------
139180
# Set some default compiler flags
140181
#-------------------------------------------------------------------------------
@@ -238,6 +279,7 @@ endif()
238279
if(USE_PGO_OPTIMIZE)
239280
add_compile_options(-fprofile-use)
240281
endif()
282+
#endif(MSVC)
241283

242284
list(APPEND PCSX2_DEFS
243285
"$<$<CONFIG:Debug>:PCSX2_DEVBUILD;PCSX2_DEBUG;_DEBUG>"

cmake/SearchForStuff.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ else()
4444
find_package(ZLIB REQUIRED)
4545

4646
## Use pcsx2 package to find module
47+
# if (NOT MSVC)
4748
include(FindLibc)
49+
# endif()
4850

4951
## Use CheckLib package to find module
5052
include(CheckLib)
@@ -89,6 +91,15 @@ else()
8991
endif()
9092
endif(WIN32)
9193

94+
#if(MSVC)
95+
# add_definitions(-DPTW32_STATIC_LIB)
96+
## add_definitions(-D__CLEANUP_SEH)
97+
# add_subdirectory(${CMAKE_SOURCE_DIR}/3rdparty/pthreads4w)
98+
# include_directories(${CMAKE_SOURCE_DIR}/3rdparty/pthreads4w/include)
99+
# add_subdirectory(${CMAKE_SOURCE_DIR}/3rdparty/baseclasses)
100+
## include_directories(${CMAKE_SOURCE_DIR}/3rdparty/baseclasses)
101+
#endif()
102+
92103
# Require threads on all OSes.
93104
find_package(Threads REQUIRED)
94105

common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,6 @@ target_include_directories(common PUBLIC ../3rdparty/include ../)
305305
target_compile_definitions(common PUBLIC "${PCSX2_DEFS}")
306306
target_compile_options(common PRIVATE "${PCSX2_WARNINGS}")
307307

308-
if(COMMAND target_precompile_headers)
308+
if(COMMAND target_precompile_headers AND NOT CCACHE_FOUND)
309309
target_precompile_headers(common PRIVATE PrecompiledHeader.h)
310310
endif()

common/GL/Context.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
#include <malloc.h>
2929
#endif
3030

31-
#if defined(_WIN32) && !defined(_M_ARM64)
31+
#if defined(__LIBRETRO__)
32+
#include "common/GL/ContextRetroGL.h"
33+
#elif defined(_WIN32) && !defined(_M_ARM64)
3234
#include "common/GL/ContextWGL.h"
3335
#elif defined(__APPLE__)
3436
#include "common/GL/ContextAGL.h"
@@ -100,6 +102,9 @@ namespace GL
100102
}
101103

102104
std::unique_ptr<Context> context;
105+
#if defined(__LIBRETRO__)
106+
context = ContextRetroGL::Create(wi, versions_to_try);
107+
#else
103108
#if defined(_WIN32) && !defined(_M_ARM64)
104109
context = ContextWGL::Create(wi, versions_to_try);
105110
#elif defined(__APPLE__)
@@ -114,6 +119,7 @@ namespace GL
114119
#if defined(WAYLAND_API)
115120
if (wi.type == WindowInfo::Type::Wayland)
116121
context = ContextEGLWayland::Create(wi, versions_to_try);
122+
#endif
117123
#endif
118124

119125
if (!context)

common/GL/ContextRetroGL.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* PCSX2 - PS2 Emulator for PCs
2+
* Copyright (C) 2002-2021 PCSX2 Dev Team
3+
*
4+
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
5+
* of the GNU Lesser General Public License as published by the Free Software Found-
6+
* ation, either version 3 of the License, or (at your option) any later version.
7+
*
8+
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
* PURPOSE. See the GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License along with PCSX2.
13+
* If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
16+
#include "common/PrecompiledHeader.h"
17+
18+
#include "common/Console.h"
19+
#include "ContextRetroGL.h"
20+
#include <optional>
21+
#include <vector>
22+
#include "common/WindowInfo.h"
23+
#include "GS/Renderers/Common/GSDevice.h"
24+
#include "GS/GSVector.h"
25+
26+
#include <libretro.h>
27+
extern retro_video_refresh_t video_cb;
28+
extern retro_hw_render_callback hw_render;
29+
30+
namespace GL
31+
{
32+
ContextRetroGL::ContextRetroGL(const WindowInfo& wi)
33+
: Context(wi)
34+
{
35+
}
36+
37+
ContextRetroGL::~ContextRetroGL()
38+
{
39+
}
40+
41+
std::unique_ptr<Context> ContextRetroGL::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try)
42+
{
43+
std::unique_ptr<ContextRetroGL> context = std::make_unique<ContextRetroGL>(wi);
44+
return context;
45+
}
46+
47+
void* ContextRetroGL::GetProcAddress(const char* name)
48+
{
49+
return reinterpret_cast<void*>(hw_render.get_proc_address(name));
50+
}
51+
52+
bool ContextRetroGL::ChangeSurface(const WindowInfo& new_wi)
53+
{
54+
return true;
55+
}
56+
57+
void ContextRetroGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_height /*= 0*/)
58+
{
59+
m_wi.surface_width = new_surface_width;
60+
m_wi.surface_height = new_surface_height;
61+
}
62+
63+
bool ContextRetroGL::SwapBuffers()
64+
{
65+
if(g_gs_device->GetCurrent())
66+
video_cb(RETRO_HW_FRAME_BUFFER_VALID, g_gs_device->GetCurrent()->GetWidth(), g_gs_device->GetCurrent()->GetHeight(), 0);
67+
else
68+
video_cb(NULL, 640, 480, 0);
69+
return true;
70+
}
71+
72+
bool ContextRetroGL::MakeCurrent()
73+
{
74+
return true;
75+
}
76+
77+
bool ContextRetroGL::DoneCurrent()
78+
{
79+
return true;
80+
}
81+
82+
bool ContextRetroGL::SetSwapInterval(s32 interval)
83+
{
84+
return true;
85+
}
86+
87+
std::unique_ptr<Context> ContextRetroGL::CreateSharedContext(const WindowInfo& wi)
88+
{
89+
std::unique_ptr<ContextRetroGL> context = std::make_unique<ContextRetroGL>(wi);
90+
return context;
91+
}
92+
93+
} // namespace GL

common/GL/ContextRetroGL.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* PCSX2 - PS2 Emulator for PCs
2+
* Copyright (C) 2002-2021 PCSX2 Dev Team
3+
*
4+
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
5+
* of the GNU Lesser General Public License as published by the Free Software Found-
6+
* ation, either version 3 of the License, or (at your option) any later version.
7+
*
8+
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
* PURPOSE. See the GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License along with PCSX2.
13+
* If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
16+
#pragma once
17+
18+
#include "common/GL/Context.h"
19+
20+
namespace GL
21+
{
22+
class ContextRetroGL : public Context
23+
{
24+
public:
25+
ContextRetroGL(const WindowInfo& wi);
26+
~ContextRetroGL() override;
27+
28+
static std::unique_ptr<Context> Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try);
29+
30+
void* GetProcAddress(const char* name) override;
31+
virtual bool ChangeSurface(const WindowInfo& new_wi) override;
32+
virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
33+
bool SwapBuffers() override;
34+
bool MakeCurrent() override;
35+
bool DoneCurrent() override;
36+
bool SetSwapInterval(s32 interval) override;
37+
virtual std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) override;
38+
};
39+
40+
} // namespace GL

common/Perf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#pragma once
1717

18+
#include <cstdio>
1819
#include <vector>
1920
#include <cstdio>
2021
#include "common/Pcsx2Types.h"

0 commit comments

Comments
 (0)