diff --git a/pcsx2/Frontend/MetalHostDisplay.mm b/pcsx2/Frontend/MetalHostDisplay.mm index 35f9ee203c718..ebe41fcaf1648 100644 --- a/pcsx2/Frontend/MetalHostDisplay.mm +++ b/pcsx2/Frontend/MetalHostDisplay.mm @@ -18,6 +18,7 @@ #include "GS/Renderers/Metal/GSMetalCPPAccessible.h" #include "GS/Renderers/Metal/GSDeviceMTL.h" #include +#include #ifdef __APPLE__ @@ -266,6 +267,12 @@ static void OnMainThread(Fn&& fn) GSDeviceMTL* dev = static_cast(g_gs_device.get()); if (dev && m_capture_start_frame && dev->FrameNo() == m_capture_start_frame) s_capture_next = true; + static bool f8 = false; + bool option = CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, kVK_Option) || CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, kVK_RightOption); + bool newf8 = CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, kVK_F8) && option; + if (newf8 && !f8) + s_capture_next = true; + f8 = newf8; if (frame_skip || m_window_info.type == WindowInfo::Type::Surfaceless || !g_gs_device) { ImGui::EndFrame(); @@ -300,52 +307,49 @@ static void OnMainThread(Fn&& fn) if (m_current_drawable) [m_current_drawable present]; m_current_drawable = nullptr; - if (m_capture_start_frame) + if (@available(macOS 10.15, iOS 13, *)) { - if (@available(macOS 10.15, iOS 13, *)) + static NSString* const path = @"/tmp/PCSX2MTLCapture.gputrace"; + static u32 frames; + if (frames) { - static NSString* const path = @"/tmp/PCSX2MTLCapture.gputrace"; - static u32 frames; - if (frames) + --frames; + if (!frames) { - --frames; - if (!frames) - { - [[MTLCaptureManager sharedCaptureManager] stopCapture]; - Console.WriteLn("Metal Trace Capture to /tmp/PCSX2MTLCapture.gputrace finished"); - [[NSWorkspace sharedWorkspace] selectFile:path - inFileViewerRootedAtPath:@"/tmp/"]; - } + [[MTLCaptureManager sharedCaptureManager] stopCapture]; + Console.WriteLn("Metal Trace Capture to /tmp/PCSX2MTLCapture.gputrace finished"); + [[NSWorkspace sharedWorkspace] selectFile:path + inFileViewerRootedAtPath:@"/tmp/"]; } - else if (s_capture_next) + } + else if (s_capture_next) + { + s_capture_next = false; + MTLCaptureManager* mgr = [MTLCaptureManager sharedCaptureManager]; + if ([mgr supportsDestination:MTLCaptureDestinationGPUTraceDocument]) { - s_capture_next = false; - MTLCaptureManager* mgr = [MTLCaptureManager sharedCaptureManager]; - if ([mgr supportsDestination:MTLCaptureDestinationGPUTraceDocument]) + MTLCaptureDescriptor* desc = [[MTLCaptureDescriptor new] autorelease]; + [desc setCaptureObject:m_dev.dev]; + if ([[NSFileManager defaultManager] fileExistsAtPath:path]) + [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; + [desc setOutputURL:[NSURL fileURLWithPath:path]]; + [desc setDestination:MTLCaptureDestinationGPUTraceDocument]; + NSError* err = nullptr; + [mgr startCaptureWithDescriptor:desc error:&err]; + if (err) { - MTLCaptureDescriptor* desc = [[MTLCaptureDescriptor new] autorelease]; - [desc setCaptureObject:m_dev.dev]; - if ([[NSFileManager defaultManager] fileExistsAtPath:path]) - [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; - [desc setOutputURL:[NSURL fileURLWithPath:path]]; - [desc setDestination:MTLCaptureDestinationGPUTraceDocument]; - NSError* err = nullptr; - [mgr startCaptureWithDescriptor:desc error:&err]; - if (err) - { - Console.Error("Metal Trace Capture failed: %s", [[err localizedDescription] UTF8String]); - } - else - { - Console.WriteLn("Metal Trace Capture to /tmp/PCSX2MTLCapture.gputrace started"); - frames = 2; - } + Console.Error("Metal Trace Capture failed: %s", [[err localizedDescription] UTF8String]); } else { - Console.Error("Metal Trace Capture Failed: MTLCaptureManager doesn't support GPU trace documents! (Did you forget to run with METAL_CAPTURE_ENABLED=1?)"); + Console.WriteLn("Metal Trace Capture to /tmp/PCSX2MTLCapture.gputrace started"); + frames = 2; } } + else + { + Console.Error("Metal Trace Capture Failed: MTLCaptureManager doesn't support GPU trace documents! (Did you forget to run with METAL_CAPTURE_ENABLED=1?)"); + } } } }}