From 08333e0876af55c204493514cd2ce145c59eb807 Mon Sep 17 00:00:00 2001 From: nastys Date: Sun, 12 Dec 2021 21:35:56 +0100 Subject: [PATCH] macOS moltenVK support and SIGBUS handling (#11252) --- Utilities/Thread.cpp | 8 ++++++++ buildfiles/cmake/ConfigureCompiler.cmake | 4 +++- rpcs3/Emu/RSX/Program/GLSLCommon.cpp | 4 ++-- rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp | 2 ++ rpcs3/Emu/RSX/VK/vkutils/device.cpp | 8 ++++++++ rpcs3/main.cpp | 5 +++-- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 32bb89872c..ec453ff51c 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -1826,6 +1826,14 @@ const bool s_exception_handler_set = []() -> bool std::abort(); } +#ifdef __APPLE__ + if (::sigaction(SIGBUS, &sa, NULL) == -1) + { + std::fprintf(stderr, "sigaction(SIGBUS) failed (%d).\n", errno); + std::abort(); + } +#endif + sa.sa_handler = sigpipe_signaling_handler; if (::sigaction(SIGPIPE, &sa, NULL) == -1) { diff --git a/buildfiles/cmake/ConfigureCompiler.cmake b/buildfiles/cmake/ConfigureCompiler.cmake index cbec6ef73c..6a5a390b8b 100644 --- a/buildfiles/cmake/ConfigureCompiler.cmake +++ b/buildfiles/cmake/ConfigureCompiler.cmake @@ -81,7 +81,9 @@ else() set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie") endif() elseif(APPLE) - add_compile_options(-stdlib=libc++) + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_compile_options(-stdlib=libc++) + endif() set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-image_base,0x10000 -Wl,-pagezero_size,0x10000") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-no_pie") elseif(WIN32) diff --git a/rpcs3/Emu/RSX/Program/GLSLCommon.cpp b/rpcs3/Emu/RSX/Program/GLSLCommon.cpp index 75a037d577..9c8e145b68 100644 --- a/rpcs3/Emu/RSX/Program/GLSLCommon.cpp +++ b/rpcs3/Emu/RSX/Program/GLSLCommon.cpp @@ -681,8 +681,8 @@ namespace glsl "{\n" " vec4 low = cl * 12.92;\n" " vec4 high = 1.055 * pow(cl, vec4(1. / 2.4)) - 0.055;\n" - " bvec4 select = lessThan(cl, vec4(0.0031308));\n" - " return clamp(mix(high, low, select), 0., 1.);\n" + " bvec4 selection = lessThan(cl, vec4(0.0031308));\n" + " return clamp(mix(high, low, selection), 0., 1.);\n" "}\n\n"; } diff --git a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp index 15e0d1c377..d155ce1295 100644 --- a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp +++ b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp @@ -29,7 +29,9 @@ namespace vk case rsx::primitive_type::quad_strip: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; case rsx::primitive_type::triangle_fan: +#ifndef __APPLE__ return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN; +#endif case rsx::primitive_type::quads: case rsx::primitive_type::polygon: requires_modification = true; diff --git a/rpcs3/Emu/RSX/VK/vkutils/device.cpp b/rpcs3/Emu/RSX/VK/vkutils/device.cpp index fef5425e21..5480ba4011 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/device.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/device.cpp @@ -495,6 +495,14 @@ namespace vk enabled_features.occlusionQueryPrecise = VK_FALSE; } +#ifdef __APPLE__ + if (!pgpu->features.logicOp) + { + rsx_log.error("Your GPU does not support framebuffer logical operations. Graphics may not render correctly."); + enabled_features.logicOp = VK_FALSE; + } +#endif + VkDeviceCreateInfo device = {}; device.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; device.pNext = nullptr; diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index fa666e886d..8db1996a69 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -49,7 +49,7 @@ DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResoluti #include #endif -#ifdef __APPLE__ +#if defined(__APPLE__) && defined(BLOCKS) // BLOCKS is required for dispatch_sync, but GCC-11 does not support it #include #endif @@ -130,8 +130,9 @@ LOG_CHANNEL(q_debug, "QDEBUG"); dlg.exec(); }; -#ifdef __APPLE__ +#if defined(__APPLE__) && defined(BLOCKS) // BLOCKS is required for dispatch_sync, but GCC-11 does not support it // Cocoa access is not allowed outside of the main thread + // Prevents crash dialogs from freezing the program if (!pthread_main_np()) { dispatch_sync(dispatch_get_main_queue(), ^ { show_report(text); });