diff --git a/Directory.Packages.props.orig b/Directory.Packages.props.orig
new file mode 100644
index 000000000..8f22ea60c
--- /dev/null
+++ b/Directory.Packages.props.orig
@@ -0,0 +1,67 @@
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<<<<<<< HEAD
+
+
+
+=======
+
+
+
+>>>>>>> 45a6dffcf (Bump SharpMetal)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<<<<<<< HEAD
+
+
+
+=======
+
+
+
+
+>>>>>>> 45a6dffcf (Bump SharpMetal)
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Metal/CounterEvent.cs b/src/Ryujinx.Graphics.Metal/CounterEvent.cs
index eec810991..1773b9b63 100644
--- a/src/Ryujinx.Graphics.Metal/CounterEvent.cs
+++ b/src/Ryujinx.Graphics.Metal/CounterEvent.cs
@@ -2,7 +2,7 @@ using Ryujinx.Graphics.GAL;
namespace Ryujinx.Graphics.Metal
{
- public class CounterEvent : ICounterEvent
+ class CounterEvent : ICounterEvent
{
public CounterEvent()
diff --git a/src/Ryujinx.Graphics.Metal/FormatCapabilities.cs b/src/Ryujinx.Graphics.Metal/FormatCapabilities.cs
deleted file mode 100644
index 6dc56c59b..000000000
--- a/src/Ryujinx.Graphics.Metal/FormatCapabilities.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using SharpMetal;
-
-namespace Ryujinx.Graphics.Metal
-{
- static class FormatCapabilities
- {
- public static MTLPixelFormat ConvertToMTLFormat(GAL.Format srcFormat)
- {
- var format = FormatTable.GetFormat(srcFormat);
-
- return format;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Ryujinx.Graphics.Metal/HardwareInfo.cs b/src/Ryujinx.Graphics.Metal/HardwareInfo.cs
index 3ca7cdfca..13566dbd8 100644
--- a/src/Ryujinx.Graphics.Metal/HardwareInfo.cs
+++ b/src/Ryujinx.Graphics.Metal/HardwareInfo.cs
@@ -6,8 +6,8 @@ namespace Ryujinx.Graphics.Metal
static partial class HardwareInfoTools
{
- private readonly static IntPtr kCFAllocatorDefault = IntPtr.Zero;
- private readonly static UInt32 kCFStringEncodingASCII = 0x0600;
+ private readonly static IntPtr _kCFAllocatorDefault = IntPtr.Zero;
+ private readonly static UInt32 _kCFStringEncodingASCII = 0x0600;
private const string IOKit = "/System/Library/Frameworks/IOKit.framework/IOKit";
private const string CoreFoundation = "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation";
@@ -47,8 +47,8 @@ namespace Ryujinx.Graphics.Metal
{
var serviceDict = IOServiceMatching("IOGPU");
var service = IOServiceGetMatchingService(IntPtr.Zero, serviceDict);
- var cfString = CFStringCreateWithCString(kCFAllocatorDefault, "vendor-id", kCFStringEncodingASCII);
- var cfProperty = IORegistryEntryCreateCFProperty(service, cfString, kCFAllocatorDefault, 0);
+ var cfString = CFStringCreateWithCString(_kCFAllocatorDefault, "vendor-id", _kCFStringEncodingASCII);
+ var cfProperty = IORegistryEntryCreateCFProperty(service, cfString, _kCFAllocatorDefault, 0);
byte[] buffer = new byte[4];
var bufferPtr = CFDataGetBytePtr(cfProperty);
@@ -63,13 +63,13 @@ namespace Ryujinx.Graphics.Metal
{
var serviceDict = IOServiceMatching("IOGPU");
var service = IOServiceGetMatchingService(IntPtr.Zero, serviceDict);
- var cfString = CFStringCreateWithCString(kCFAllocatorDefault, "model", kCFStringEncodingASCII);
- var cfProperty = IORegistryEntryCreateCFProperty(service, cfString, kCFAllocatorDefault, 0);
+ var cfString = CFStringCreateWithCString(_kCFAllocatorDefault, "model", _kCFStringEncodingASCII);
+ var cfProperty = IORegistryEntryCreateCFProperty(service, cfString, _kCFAllocatorDefault, 0);
char[] buffer = new char[64];
IntPtr bufferPtr = Marshal.AllocHGlobal(buffer.Length);
- if (CFStringGetCString(cfProperty, bufferPtr, buffer.Length, kCFStringEncodingASCII))
+ if (CFStringGetCString(cfProperty, bufferPtr, buffer.Length, _kCFStringEncodingASCII))
{
var model = Marshal.PtrToStringUTF8(bufferPtr);
Marshal.FreeHGlobal(bufferPtr);
diff --git a/src/Ryujinx.Graphics.Metal/HelperShaders.cs b/src/Ryujinx.Graphics.Metal/HelperShaders.cs
index 0864839fd..a4517b7ce 100644
--- a/src/Ryujinx.Graphics.Metal/HelperShaders.cs
+++ b/src/Ryujinx.Graphics.Metal/HelperShaders.cs
@@ -30,17 +30,18 @@ namespace Ryujinx.Graphics.Metal
}
[SupportedOSPlatform("macos")]
- public struct HelperShader
+ public readonly struct HelperShader
{
- private MTLRenderPipelineState _pipelineState;
+ private readonly MTLRenderPipelineState _pipelineState;
public static implicit operator MTLRenderPipelineState(HelperShader shader) => shader._pipelineState;
public HelperShader(MTLDevice device, MTLLibrary library, string vertex, string fragment)
{
- var renderPipelineDescriptor = new MTLRenderPipelineDescriptor();
-
- renderPipelineDescriptor.VertexFunction = library.NewFunction(StringHelper.NSString(vertex));;
- renderPipelineDescriptor.FragmentFunction = library.NewFunction(StringHelper.NSString(fragment));
+ var renderPipelineDescriptor = new MTLRenderPipelineDescriptor
+ {
+ VertexFunction = library.NewFunction(StringHelper.NSString(vertex)),
+ FragmentFunction = library.NewFunction(StringHelper.NSString(fragment))
+ };
renderPipelineDescriptor.ColorAttachments.Object(0).SetBlendingEnabled(true);
renderPipelineDescriptor.ColorAttachments.Object(0).PixelFormat = MTLPixelFormat.BGRA8Unorm;
renderPipelineDescriptor.ColorAttachments.Object(0).SourceAlphaBlendFactor = MTLBlendFactor.SourceAlpha;
diff --git a/src/Ryujinx.Graphics.Metal/MetalRenderer.cs b/src/Ryujinx.Graphics.Metal/MetalRenderer.cs
index d3d73f551..21c8c49b4 100644
--- a/src/Ryujinx.Graphics.Metal/MetalRenderer.cs
+++ b/src/Ryujinx.Graphics.Metal/MetalRenderer.cs
@@ -38,10 +38,12 @@ namespace Ryujinx.Graphics.Metal
var layer = _getMetalLayer();
layer.Device = _device;
- var captureDescriptor = new MTLCaptureDescriptor();
- captureDescriptor.CaptureObject = _queue;
- captureDescriptor.Destination = MTLCaptureDestination.GPUTraceDocument;
- captureDescriptor.OutputURL = NSURL.FileURLWithPath(StringHelper.NSString("/Users/isaacmarovitz/Desktop/Trace.gputrace"));
+ 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)
@@ -216,7 +218,7 @@ namespace Ryujinx.Graphics.Metal
{
MTLBuffer mtlBuffer = new(Unsafe.As(ref buffer));
var span = new Span(mtlBuffer.Contents.ToPointer(), (int)mtlBuffer.Length);
- data.CopyTo(span.Slice(offset));
+ data.CopyTo(span[offset..]);
mtlBuffer.DidModifyRange(new NSRange
{
location = (ulong)offset,
diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs
index c8607c5be..6a3d9a801 100644
--- a/src/Ryujinx.Graphics.Metal/Pipeline.cs
+++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs
@@ -11,7 +11,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Metal
{
[SupportedOSPlatform("macos")]
- public class Pipeline : IPipeline, IDisposable
+ class Pipeline : IPipeline, IDisposable
{
private readonly MTLDevice _device;
private readonly MTLCommandQueue _mtlCommandQueue;
@@ -88,8 +88,13 @@ namespace Ryujinx.Graphics.Metal
return computeCommandEncoder;
}
- public void Present(CAMetalDrawable drawable, Texture texture)
+ public void Present(CAMetalDrawable drawable, ITexture texture)
{
+ if (texture is not Texture tex)
+ {
+ return;
+ }
+
EndCurrentPass();
var descriptor = new MTLRenderPassDescriptor();
@@ -108,7 +113,7 @@ namespace Ryujinx.Graphics.Metal
MipFilter = MTLSamplerMipFilter.NotMipmapped
});
- renderCommandEncoder.SetFragmentTexture(texture.MTLTexture, 0);
+ renderCommandEncoder.SetFragmentTexture(tex.MTLTexture, 0);
renderCommandEncoder.SetFragmentSamplerState(sampler, 0);
renderCommandEncoder.DrawPrimitives(MTLPrimitiveType.Triangle, 0, 6);
@@ -162,7 +167,7 @@ namespace Ryujinx.Graphics.Metal
public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color)
{
- _clearColor = new MTLClearColor { red = color.Red, green = color.Green, blue = color.Blue, alpha = color.Alpha};
+ _clearColor = new MTLClearColor { red = color.Red, green = color.Green, blue = color.Blue, alpha = color.Alpha };
}
public void ClearRenderTargetDepthStencil(int layer, int layerCount, float depthValue, bool depthMask, int stencilValue,
diff --git a/src/Ryujinx.Graphics.Metal/Program.cs b/src/Ryujinx.Graphics.Metal/Program.cs
index add16462f..0a748bfcf 100644
--- a/src/Ryujinx.Graphics.Metal/Program.cs
+++ b/src/Ryujinx.Graphics.Metal/Program.cs
@@ -2,13 +2,8 @@ using Ryujinx.Graphics.GAL;
namespace Ryujinx.Graphics.Metal
{
- public class Program : IProgram
+ class Program : IProgram
{
- public void Dispose()
- {
- return;
- }
-
public ProgramLinkStatus CheckProgramLink(bool blocking)
{
return ProgramLinkStatus.Failure;
@@ -16,7 +11,12 @@ namespace Ryujinx.Graphics.Metal
public byte[] GetBinary()
{
- return new byte[] {};
+ return ""u8.ToArray();
+ }
+
+ public void Dispose()
+ {
+ return;
}
}
}
diff --git a/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs b/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs
index db946d8b8..e24b49090 100644
--- a/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs
+++ b/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs
@@ -1,5 +1,6 @@
using Ryujinx.Graphics.GAL;
using SharpMetal.Metal;
+using System;
using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Metal
@@ -7,8 +8,9 @@ namespace Ryujinx.Graphics.Metal
[SupportedOSPlatform("macos")]
struct RenderEncoderState
{
- private MTLDevice _device;
-
+ private readonly MTLDevice _device;
+ // TODO: Work with more than one pipeline state
+ private readonly MTLRenderPipelineState _copyPipeline;
private MTLDepthStencilState _depthStencilState = null;
private MTLCompareFunction _depthCompareFunction = MTLCompareFunction.Always;
@@ -17,7 +19,6 @@ namespace Ryujinx.Graphics.Metal
private MTLStencilDescriptor _backFaceStencil = null;
private MTLStencilDescriptor _frontFaceStencil = null;
- public MTLRenderPipelineState CopyPipeline;
public PrimitiveTopology Topology = PrimitiveTopology.Triangles;
public MTLCullMode CullMode = MTLCullMode.None;
public MTLWinding Winding = MTLWinding.Clockwise;
@@ -25,15 +26,19 @@ namespace Ryujinx.Graphics.Metal
public RenderEncoderState(MTLRenderPipelineState copyPipeline, MTLDevice device)
{
_device = device;
- CopyPipeline = copyPipeline;
+ _copyPipeline = copyPipeline;
}
- public void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder)
+ public readonly void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder)
{
- renderCommandEncoder.SetRenderPipelineState(CopyPipeline);
+ renderCommandEncoder.SetRenderPipelineState(_copyPipeline);
renderCommandEncoder.SetCullMode(CullMode);
renderCommandEncoder.SetFrontFacingWinding(Winding);
- // renderCommandEncoder.SetDepthStencilState(_depthStencilState);
+
+ if (_depthStencilState != null)
+ {
+ renderCommandEncoder.SetDepthStencilState(_depthStencilState);
+ }
}
public MTLDepthStencilState UpdateStencilState(MTLStencilDescriptor backFace, MTLStencilDescriptor frontFace)
diff --git a/src/Ryujinx.Graphics.Metal/Sampler.cs b/src/Ryujinx.Graphics.Metal/Sampler.cs
index a40040c5f..cc1923cc3 100644
--- a/src/Ryujinx.Graphics.Metal/Sampler.cs
+++ b/src/Ryujinx.Graphics.Metal/Sampler.cs
@@ -3,13 +3,13 @@ using SharpMetal.Metal;
namespace Ryujinx.Graphics.Metal
{
- public class Sampler : ISampler
+ class Sampler : ISampler
{
- private MTLSamplerState _mtlSamplerState;
+ // private readonly MTLSamplerState _mtlSamplerState;
public Sampler(MTLSamplerState mtlSamplerState)
{
- _mtlSamplerState = mtlSamplerState;
+ // _mtlSamplerState = mtlSamplerState;
}
public void Dispose()
diff --git a/src/Ryujinx.Graphics.Metal/Texture.cs b/src/Ryujinx.Graphics.Metal/Texture.cs
index 7074e7da3..ea3a8cba8 100644
--- a/src/Ryujinx.Graphics.Metal/Texture.cs
+++ b/src/Ryujinx.Graphics.Metal/Texture.cs
@@ -9,7 +9,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Metal
{
[SupportedOSPlatform("macos")]
- public class Texture : ITexture, IDisposable
+ class Texture : ITexture, IDisposable
{
private readonly TextureCreateInfo _info;
private readonly Pipeline _pipeline;
@@ -28,12 +28,14 @@ namespace Ryujinx.Graphics.Metal
_pipeline = pipeline;
_info = info;
- var descriptor = new MTLTextureDescriptor();
- descriptor.PixelFormat = FormatTable.GetFormat(Info.Format);
- descriptor.Usage = MTLTextureUsage.ShaderRead | MTLTextureUsage.ShaderWrite | MTLTextureUsage.RenderTarget;
- descriptor.Width = (ulong)Width;
- descriptor.Height = (ulong)Height;
- descriptor.Depth = (ulong)Depth;
+ var descriptor = new MTLTextureDescriptor
+ {
+ PixelFormat = FormatTable.GetFormat(Info.Format),
+ Usage = MTLTextureUsage.ShaderRead | MTLTextureUsage.ShaderWrite | MTLTextureUsage.RenderTarget,
+ Width = (ulong)Width,
+ Height = (ulong)Height,
+ Depth = (ulong)Depth
+ };
descriptor.Depth = (ulong)Info.Depth;
descriptor.SampleCount = (ulong)Info.Samples;
descriptor.MipmapLevelCount = (ulong)Info.Levels;
diff --git a/src/Ryujinx.Graphics.Metal/Window.cs b/src/Ryujinx.Graphics.Metal/Window.cs
index 563f888af..f8ddca3fe 100644
--- a/src/Ryujinx.Graphics.Metal/Window.cs
+++ b/src/Ryujinx.Graphics.Metal/Window.cs
@@ -8,7 +8,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Metal
{
[SupportedOSPlatform("macos")]
- public class Window : IWindow, IDisposable
+ class Window : IWindow, IDisposable
{
private readonly MetalRenderer _renderer;
private readonly CAMetalLayer _metalLayer;
diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Instructions/InstGenHelper.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Instructions/InstGenHelper.cs
index 632ad6bf2..c8757ad35 100644
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Instructions/InstGenHelper.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Msl/Instructions/InstGenHelper.cs
@@ -106,26 +106,26 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
Add(Instruction.ShiftRightS32, InstType.OpBinary, ">>");
Add(Instruction.ShiftRightU32, InstType.OpBinary, ">>");
// TODO: Shuffle funcs
- Add(Instruction.Shuffle, 0);
- Add(Instruction.ShuffleDown, 0);
- Add(Instruction.ShuffleUp, 0);
- Add(Instruction.ShuffleXor, 0);
- Add(Instruction.Sine, InstType.CallUnary, "sin");
- Add(Instruction.SquareRoot, InstType.CallUnary, "sqrt");
- Add(Instruction.Store, InstType.Special);
- Add(Instruction.Subtract, InstType.OpBinary, "-");
+ Add(Instruction.Shuffle, 0);
+ Add(Instruction.ShuffleDown, 0);
+ Add(Instruction.ShuffleUp, 0);
+ Add(Instruction.ShuffleXor, 0);
+ Add(Instruction.Sine, InstType.CallUnary, "sin");
+ Add(Instruction.SquareRoot, InstType.CallUnary, "sqrt");
+ Add(Instruction.Store, InstType.Special);
+ Add(Instruction.Subtract, InstType.OpBinary, "-");
// TODO: Swizzle add
- Add(Instruction.SwizzleAdd, InstType.Special);
- Add(Instruction.TextureSample, InstType.Special);
- Add(Instruction.TextureSize, InstType.Special);
- Add(Instruction.Truncate, InstType.CallUnary, "trunc");
+ Add(Instruction.SwizzleAdd, InstType.Special);
+ Add(Instruction.TextureSample, InstType.Special);
+ Add(Instruction.TextureSize, InstType.Special);
+ Add(Instruction.Truncate, InstType.CallUnary, "trunc");
Add(Instruction.UnpackDouble2x32, 0); // MSL does not have a 64-bit FP
- Add(Instruction.UnpackHalf2x16, InstType.CallUnary, "unpack_unorm2x16_to_half");
+ Add(Instruction.UnpackHalf2x16, InstType.CallUnary, "unpack_unorm2x16_to_half");
Add(Instruction.VectorExtract, InstType.Special);
- Add(Instruction.VoteAll, InstType.CallUnary, "simd_all");
+ Add(Instruction.VoteAll, InstType.CallUnary, "simd_all");
// TODO: https://github.com/KhronosGroup/SPIRV-Cross/blob/bccaa94db814af33d8ef05c153e7c34d8bd4d685/reference/shaders-msl/comp/shader_group_vote.msl21.comp#L9
- Add(Instruction.VoteAllEqual, InstType.Special);
- Add(Instruction.VoteAny, InstType.CallUnary, "simd_any");
+ Add(Instruction.VoteAllEqual, InstType.Special);
+ Add(Instruction.VoteAny, InstType.CallUnary, "simd_any");
#pragma warning restore IDE0055
}
diff --git a/src/Ryujinx/AppHost.cs b/src/Ryujinx/AppHost.cs
index 764230855..8566afb20 100644
--- a/src/Ryujinx/AppHost.cs
+++ b/src/Ryujinx/AppHost.cs
@@ -830,6 +830,10 @@ namespace Ryujinx.Ava
VulkanHelper.GetRequiredInstanceExtensions,
ConfigurationState.Instance.Graphics.PreferredGpu.Value);
}
+ else if (ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.Metal && OperatingSystem.IsMacOS())
+ {
+ renderer = new MetalRenderer();
+ }
else
{
renderer = new OpenGLRenderer();
diff --git a/src/Ryujinx/AppHost.cs.orig b/src/Ryujinx/AppHost.cs.orig
index 99663fbc5..302ef914c 100644
--- a/src/Ryujinx/AppHost.cs.orig
+++ b/src/Ryujinx/AppHost.cs.orig
@@ -760,10 +760,13 @@ namespace Ryujinx.Ava
VulkanHelper.GetRequiredInstanceExtensions,
ConfigurationState.Instance.Graphics.PreferredGpu.Value);
}
- else if (ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.Metal)
+<<<<<<< HEAD
+=======
+ else if (ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.Metal && OperatingSystem.IsMacOS())
{
renderer = new MetalRenderer();
}
+>>>>>>> b83dc41f8 (Formatting)
else
{
renderer = new OpenGLRenderer();
@@ -1002,14 +1005,12 @@ namespace Ryujinx.Ava
StatusUpdatedEvent?.Invoke(this, new StatusUpdatedEventArgs(
Device.EnableDeviceVsync,
LocaleManager.Instance[LocaleKeys.VolumeShort] + $": {(int)(Device.GetVolume() * 100)}%",
-<<<<<<< HEAD
-=======
ConfigurationState.Instance.Graphics.GraphicsBackend.Value.ToText(),
->>>>>>> 2daba02b8 (Start Metal Backend)
dockedMode,
ConfigurationState.Instance.Graphics.AspectRatio.Value.ToText(),
LocaleManager.Instance[LocaleKeys.Game] + $": {Device.Statistics.GetGameFrameRate():00.00} FPS ({Device.Statistics.GetGameFrameTime():00.00} ms)",
- $"FIFO: {Device.Statistics.GetFifoPercent():00.00} %"));
+ $"FIFO: {Device.Statistics.GetFifoPercent():00.00} %",
+ $"GPU: {_renderer.GetHardwareInfo().GpuDriver}"));
}
public async Task ShowExitPrompt()