From 07af701afeb91d09ae25eff5520086e6fe881a10 Mon Sep 17 00:00:00 2001 From: myfreeweb Date: Thu, 14 Sep 2017 21:02:09 +0300 Subject: [PATCH] Vulkan: use pkg-config instead of checking for Linux (#3440) Makes Vulkan optional on Linux / makes it possible on FreeBSD. --- README.md | 15 ++++++++------ rpcs3/CMakeLists.txt | 30 ++++++++++++++++++++-------- rpcs3/Emu/RSX/VK/VKGSRender.cpp | 4 ++-- rpcs3/Emu/RSX/VK/VKGSRender.h | 2 +- rpcs3/Emu/RSX/VK/VKHelpers.h | 2 +- rpcs3/cmake_modules/FindVulkan.cmake | 18 +++++++++++++++++ rpcs3/rpcs3_app.cpp | 4 ++-- rpcs3/rpcs3qt/emu_settings.cpp | 4 ++-- 8 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 rpcs3/cmake_modules/FindVulkan.cmake diff --git a/README.md b/README.md index cd0eec9015..6d747e2f9c 100644 --- a/README.md +++ b/README.md @@ -76,20 +76,23 @@ When using GDB, configure it to ignore SIGSEGV signal (`handle SIGSEGV nostop no ## CMake Build Options (Linux & Mac OS) -- ```-DUSE_SYSTEM_LIBPNG=ON/OFF``` (default = *OFF*)
+- ```-DUSE_SYSTEM_LIBPNG=ON/OFF``` (default = *OFF*) Build against the shared libpng instead of using the builtin one. libpng 1.6+ highly recommended. Try this option if you get version conflict errors or only see black game icons. -- ```-DUSE_SYSTEM_FFMPEG=ON/OFF``` (default = *OFF*)
+- ```-DUSE_SYSTEM_FFMPEG=ON/OFF``` (default = *OFF*) Build against the shared ffmpeg libraries instead of using the builtin patched version. Try this if the builtin version breaks the OpenGL renderer for you. -- ```-DUSE_SHARED_LLVM_LIBS=ON/OFF``` (default = *OFF*)
+- ```-DUSE_SHARED_LLVM_LIBS=ON/OFF``` (default = *OFF*) This builds against the shared LLVM libs, rather than the static ones. This may interfere with Mesa and render RPCS3 non-functional. Only recommended on gentoo. -- ```-DWITHOUT_LLVM=ON/OFF``` (default = *OFF*)
+- ```-DWITHOUT_LLVM=ON/OFF``` (default = *OFF*) This forces RPCS3 to build without LLVM, not recommended. -- ```-DWITH_GDB=ON/OFF``` (default = *OFF*)
-This Builds RPCS3 with support for debugging PS3 games using gdb." +- ```-DWITH_GDB=ON/OFF``` (default = *OFF*) +This Builds RPCS3 with support for debugging PS3 games using gdb. + +- ```-DUSE_VULKAN=ON/OFF``` (default = *ON*) +This builds RPCS3 with Vulkan support. ## License diff --git a/rpcs3/CMakeLists.txt b/rpcs3/CMakeLists.txt index fd85939eb1..3274377fe0 100644 --- a/rpcs3/CMakeLists.txt +++ b/rpcs3/CMakeLists.txt @@ -140,15 +140,17 @@ else() set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /DYNAMICBASE:NO /BASE:0x10000 /FIXED") endif() +set(ADDITIONAL_LIBS "") if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") #on some Linux distros shm_unlink and similar functions are in librt only - set(ADDITIONAL_LIBS "rt" "X11") + set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} "rt") elseif(NOT MSVC AND NOT CMAKE_CXX_FLAGS MATCHES "LIBICONV_PLUG") #it seems like glibc includes the iconv functions we use but other libc #implementations like the one on OSX don't seem implement them - set(ADDITIONAL_LIBS "iconv") -else() - set(ADDITIONAL_LIBS "") + set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} "iconv") +endif() +if(UNIX AND NOT APPLE) + set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} "X11") endif() if(NOT RPCS3_SRC_DIR) @@ -176,6 +178,7 @@ else() option(USE_ALSA "ALSA audio backend" ON) option(USE_PULSE "PulseAudio audio backend" ON) option(USE_LIBEVDEV "libevdev-based joystick support" ON) + option(USE_VULKAN "Vulkan render backend" ON) endif() if(USE_ALSA) @@ -205,6 +208,15 @@ if(USE_LIBEVDEV) list(APPEND ADDITIONAL_LIBS ${LIBEVDEV_LDFLAGS}) endif() endif() +if(NOT WIN32 AND USE_VULKAN) + find_package(Vulkan) + if(VULKAN_FOUND) + add_definitions(-DHAVE_VULKAN) + list(APPEND ADDITIONAL_LIBS ${VULKAN_LIBRARY}) + else() + message("WARNING! USE_VULKAN was enabled, but libvulkan was not found. RPCS3 will be compiled without Vulkan support.") + endif() +endif() # Select the version of libpng to use, default is builtin if(USE_SYSTEM_LIBPNG) @@ -304,7 +316,7 @@ RPCS3_SRC "${RPCS3_SRC_DIR}/../asmjit/src/asmjit/*.cpp" ) -if (NOT WIN32 AND "${CMAKE_SYSTEM}" MATCHES "Linux") +if (NOT WIN32 AND VULKAN_FOUND) # Compile glslang and SPIRV modules needed for glsl compilation file( GLOB_RECURSE @@ -322,8 +334,7 @@ endif() #File exclusion section -#Ignore vulkan if not on windows or linux -if(NOT WIN32 AND NOT "${CMAKE_SYSTEM}" MATCHES "Linux") +if(NOT WIN32 AND NOT VULKAN_FOUND) set (EXCLUDE_FILES "/RSX/VK/") endif() @@ -366,10 +377,13 @@ else() if(APPLE) target_link_libraries(rpcs3 hidapi-mac "-framework CoreFoundation" "-framework IOKit") elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_link_libraries(rpcs3 hidapi-hidraw udev vulkan) + target_link_libraries(rpcs3 hidapi-hidraw udev) else() target_link_libraries(rpcs3 hidapi-libusb usb) endif() + if(VULKAN_FOUND) + target_link_libraries(rpcs3 ${VULKAN_LIBRARIES}) + endif() target_link_libraries(rpcs3 ${CMAKE_DL_LIBS} -lpthread ${ZLIB_LIBRARIES} ${ADDITIONAL_LIBS}) if (USE_SYSTEM_FFMPEG) link_libraries(${FFMPEG_LIBRARY_DIR}) diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index 519ba6052d..f7f750ac91 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -500,7 +500,7 @@ VKGSRender::VKGSRender() : GSRender() m_swap_chain = m_thread_context.createSwapChain(hInstance, hWnd, gpus[0]); } -#elif __linux__ +#elif HAVE_VULKAN Window window = (Window)m_frame->handle(); Display *display = XOpenDisplay(0); @@ -722,7 +722,7 @@ VKGSRender::~VKGSRender() delete m_swap_chain; -#ifdef __linux__ +#if !defined(_WIN32) && defined(HAVE_VULKAN) if (m_display_handle) XCloseDisplay(m_display_handle); #endif diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.h b/rpcs3/Emu/RSX/VK/VKGSRender.h index 243d7f78c3..4f405728a5 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.h +++ b/rpcs3/Emu/RSX/VK/VKGSRender.h @@ -249,7 +249,7 @@ private: //Vertex layout rsx::vertex_input_layout m_vertex_layout; -#ifdef __linux__ +#if !defined(_WIN32) && defined(HAVE_VULKAN) Display *m_display_handle = nullptr; #endif diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.h b/rpcs3/Emu/RSX/VK/VKHelpers.h index 9af1e92b64..b1f79294a5 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.h +++ b/rpcs3/Emu/RSX/VK/VKHelpers.h @@ -1247,7 +1247,7 @@ namespace vk VkSurfaceKHR surface; CHECK_RESULT(vkCreateWin32SurfaceKHR(m_instance, &createInfo, NULL, &surface)); -#elif __linux__ +#elif HAVE_VULKAN vk::swap_chain* createSwapChain(Display *display, Window window, vk::physical_device &dev) { diff --git a/rpcs3/cmake_modules/FindVulkan.cmake b/rpcs3/cmake_modules/FindVulkan.cmake new file mode 100644 index 0000000000..e7e61d530d --- /dev/null +++ b/rpcs3/cmake_modules/FindVulkan.cmake @@ -0,0 +1,18 @@ +# Find Vulkan + +find_package(PkgConfig) +pkg_check_modules(PC_VULKAN vulkan) + +# RPCS3 ships with the SDK headers +# find_path(VULKAN_INCLUDE_DIR +# NAMES vulkan/vulkan.h +# HINTS ${PC_VULKAN_INCLUDE_DIR} ${PC_VULKAN_INCLUDE_DIRS}) + +find_library(VULKAN_LIBRARY + NAMES vulkan + HINTS ${PC_VULKAN_LIBRARY} ${PC_VULKAN_LIBRARY_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Vulkan DEFAULT_MSG VULKAN_LIBRARY) + +mark_as_advanced(VULKAN_LIBRARY VULKAN_INCLUDE_DIR) diff --git a/rpcs3/rpcs3_app.cpp b/rpcs3/rpcs3_app.cpp index eb3c62a051..76141e1147 100644 --- a/rpcs3/rpcs3_app.cpp +++ b/rpcs3/rpcs3_app.cpp @@ -41,7 +41,7 @@ #ifdef _MSC_VER #include "Emu/RSX/D3D12/D3D12GSRender.h" #endif -#if defined(_WIN32) || defined(__linux__) +#if defined(_WIN32) || defined(HAVE_VULKAN) #include "Emu/RSX/VK/VKGSRender.h" #endif #ifdef _WIN32 @@ -201,7 +201,7 @@ void rpcs3_app::InitializeCallbacks() { case video_renderer::null: return std::make_shared(); case video_renderer::opengl: return std::make_shared(); -#if defined(_WIN32) || defined(__linux__) +#if defined(_WIN32) || defined(HAVE_VULKAN) case video_renderer::vulkan: return std::make_shared(); #endif #ifdef _MSC_VER diff --git a/rpcs3/rpcs3qt/emu_settings.cpp b/rpcs3/rpcs3qt/emu_settings.cpp index 03a32b502b..67c2f197f2 100644 --- a/rpcs3/rpcs3qt/emu_settings.cpp +++ b/rpcs3/rpcs3qt/emu_settings.cpp @@ -12,7 +12,7 @@ #include #endif -#if defined(_WIN32) || defined(__linux__) +#if defined(_WIN32) || defined(HAVE_VULKAN) #include "Emu/RSX/VK/VKHelpers.h" #endif @@ -143,7 +143,7 @@ Render_Creator::Render_Creator() } #endif -#if defined(WIN32) || defined(__linux__) +#if defined(WIN32) || defined(HAVE_VULKAN) // check for vulkan adapters vk::context device_enum_context; u32 instance_handle = device_enum_context.createInstance("RPCS3", true);