From 07be20c3691508f9aa813af6f3d0b6e8938b20a3 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 2 Aug 2023 20:32:59 -0400 Subject: [PATCH] Barry is here mashallah --- src/Ryujinx.Graphics.Metal/Pipeline.cs | 7 +++---- .../Shaders/ColorBlitShaderSource.metal | 1 + src/Ryujinx.Graphics.Metal/Window.cs | 12 +++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index 4c2f5e300..963863f38 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -52,7 +52,7 @@ namespace Ryujinx.Graphics.Metal // TODO: Recreate descriptor and encoder state as needed var renderPipelineDescriptor = new MTLRenderPipelineDescriptor(); renderPipelineDescriptor.VertexFunction = vertexFunction; - // renderPipelineDescriptor.FragmentFunction = fragmentFunction; + renderPipelineDescriptor.FragmentFunction = fragmentFunction; // TODO: This should not be hardcoded, but a bug in SharpMetal prevents me from doing this correctly renderPipelineDescriptor.ColorAttachments.Object(0).PixelFormat = MTLPixelFormat.BGRA8Unorm; @@ -115,7 +115,7 @@ namespace Ryujinx.Graphics.Metal return computeCommandEncoder; } - public void Present(CAMetalDrawable drawable) + public void Present(CAMetalDrawable drawable, Texture texture) { EndCurrentPass(); @@ -128,8 +128,7 @@ namespace Ryujinx.Graphics.Metal Logger.Warning?.Print(LogClass.Gpu, "Began present"); _renderEncoderState.SetEncoderState(renderCommandEncoder); - // Barry goes here - // renderCommandEncoder.SetFragmentTexture(_renderTarget, 0); + renderCommandEncoder.SetFragmentTexture(texture.MTLTexture, 0); renderCommandEncoder.DrawPrimitives(MTLPrimitiveType.Triangle, 0, 6); renderCommandEncoder.EndEncoding(); diff --git a/src/Ryujinx.Graphics.Metal/Shaders/ColorBlitShaderSource.metal b/src/Ryujinx.Graphics.Metal/Shaders/ColorBlitShaderSource.metal index f21f219f0..35b314460 100644 --- a/src/Ryujinx.Graphics.Metal/Shaders/ColorBlitShaderSource.metal +++ b/src/Ryujinx.Graphics.Metal/Shaders/ColorBlitShaderSource.metal @@ -22,6 +22,7 @@ vertex CopyVertexOut vertexMain(unsigned short vid [[vertex_id]]) { CopyVertexOut out; out.position = float4(position, 0, 1); + out.position.y = -out.position.y; out.uv = position * 0.5f + 0.5f; return out; diff --git a/src/Ryujinx.Graphics.Metal/Window.cs b/src/Ryujinx.Graphics.Metal/Window.cs index 3a34293a0..12ff35e7f 100644 --- a/src/Ryujinx.Graphics.Metal/Window.cs +++ b/src/Ryujinx.Graphics.Metal/Window.cs @@ -1,5 +1,8 @@ using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; +using SharpMetal.Metal; +using SharpMetal.ObjectiveCCore; +using SharpMetal.QuartzCore; using System; using System.Runtime.Versioning; @@ -9,17 +12,20 @@ namespace Ryujinx.Graphics.Metal public class Window : IWindow, IDisposable { private readonly MetalRenderer _renderer; + private readonly CAMetalLayer _metalLayer; - public Window(MetalRenderer renderer) + public Window(MetalRenderer renderer, CAMetalLayer metalLayer) { _renderer = renderer; + _metalLayer = metalLayer; } public void Present(ITexture texture, ImageCrop crop, Action swapBuffersCallback) { - if (_renderer.Pipeline is Pipeline pipeline) + if (_renderer.Pipeline is Pipeline pipeline && texture is Texture tex) { - pipeline.Present(); + var drawable = new CAMetalDrawable(ObjectiveC.IntPtr_objc_msgSend(_metalLayer, "nextDrawable")); + pipeline.Present(drawable, tex); } }