diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index 4c2f5e3000..963863f38b 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 f21f219f02..35b3144603 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 3a34293a09..12ff35e7f8 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); } }