From fd0eaaafc13c5e1fde70b6749e8694d79ff1f9e7 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 3 Aug 2023 17:04:59 -0400 Subject: [PATCH] Easier capture stuff --- src/Ryujinx.Graphics.Metal/MetalRenderer.cs | 14 -------- src/Ryujinx.Graphics.Metal/Pipeline.cs | 39 +++++++++++++++++---- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/MetalRenderer.cs b/src/Ryujinx.Graphics.Metal/MetalRenderer.cs index 8a65c2fcc2..a202db4264 100644 --- a/src/Ryujinx.Graphics.Metal/MetalRenderer.cs +++ b/src/Ryujinx.Graphics.Metal/MetalRenderer.cs @@ -38,20 +38,6 @@ namespace Ryujinx.Graphics.Metal var layer = _getMetalLayer(); layer.Device = _device; - var captureDescriptor = new MTLCaptureDescriptor - { - CaptureObject = _queue, - Destination = MTLCaptureDestination.GPUTraceDocument, - OutputURL = NSURL.FileURLWithPath(StringHelper.NSString("/Users/isaacmarovitz/Desktop/Trace.gputrace")) - }; - var captureError = new NSError(IntPtr.Zero); - MTLCaptureManager.SharedCaptureManager().StartCapture(captureDescriptor, ref captureError); - if (captureError != IntPtr.Zero) - { - Console.WriteLine($"Failed to start capture! {StringHelper.String(captureError.LocalizedDescription)}"); - - } - _window = new Window(this, layer); _pipeline = new Pipeline(_device, _queue); } diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index 77594c1420..5f1eddabfb 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -13,10 +13,13 @@ namespace Ryujinx.Graphics.Metal [SupportedOSPlatform("macos")] class Pipeline : IPipeline, IDisposable { - private const int MaxFramesPerCapture = 50; + // 0 Frames = No capture + // Some games like Undertale trigger a stack overflow on capture end + private const int MaxFramesPerCapture = 5; + private const string CaptureLocation = "/Users/isaacmarovitz/Desktop/Captures/Trace-"; private readonly MTLDevice _device; - private readonly MTLCommandQueue _mtlCommandQueue; + private readonly MTLCommandQueue _commandQueue; private readonly HelperShaders _helperShaders; private MTLCommandBuffer _commandBuffer; @@ -29,17 +32,41 @@ namespace Ryujinx.Graphics.Metal private ulong _indexBufferOffset; private MTLClearColor _clearColor; private int _frameCount; - private bool _captureEnded = false; + private bool _captureEnded = true; public Pipeline(MTLDevice device, MTLCommandQueue commandQueue) { _device = device; - _mtlCommandQueue = commandQueue; + _commandQueue = commandQueue; _helperShaders = new HelperShaders(_device); _renderEncoderState = new RenderEncoderState(_helperShaders.BlitShader, _device); - _commandBuffer = _mtlCommandQueue.CommandBuffer(); + _commandBuffer = _commandQueue.CommandBuffer(); + + if (MaxFramesPerCapture > 0) + { + StartCapture(); + } + } + + private void StartCapture() + { + var captureDescriptor = new MTLCaptureDescriptor + { + CaptureObject = _commandQueue, + Destination = MTLCaptureDestination.GPUTraceDocument, + OutputURL = NSURL.FileURLWithPath(StringHelper.NSString(CaptureLocation + DateTimeOffset.UtcNow.ToUnixTimeSeconds() + ".gputrace")) + }; + var captureError = new NSError(IntPtr.Zero); + MTLCaptureManager.SharedCaptureManager().StartCapture(captureDescriptor, ref captureError); + if (captureError != IntPtr.Zero) + { + Console.WriteLine($"Failed to start capture! {StringHelper.String(captureError.LocalizedDescription)}"); + + } + + _captureEnded = false; } public MTLRenderCommandEncoder GetOrCreateRenderEncoder() @@ -160,7 +187,7 @@ namespace Ryujinx.Graphics.Metal } } - _commandBuffer = _mtlCommandQueue.CommandBuffer(); + _commandBuffer = _commandQueue.CommandBuffer(); } public void Barrier()