Formatting

This commit is contained in:
Isaac Marovitz 2023-08-03 14:50:49 -04:00
parent da7f3e128f
commit 222aded39b
No known key found for this signature in database
GPG Key ID: 97250B2B09A132E1
15 changed files with 156 additions and 83 deletions

View File

@ -0,0 +1,67 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Avalonia" Version="11.0.7" />
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="11.0.7" />
<PackageVersion Include="Avalonia.Desktop" Version="11.0.7" />
<PackageVersion Include="Avalonia.Diagnostics" Version="11.0.7" />
<PackageVersion Include="Avalonia.Markup.Xaml.Loader" Version="11.0.7" />
<PackageVersion Include="Avalonia.Svg" Version="11.0.0.10" />
<PackageVersion Include="Avalonia.Svg.Skia" Version="11.0.0.10" />
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="Concentus" Version="1.1.7" />
<PackageVersion Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageVersion Include="DynamicData" Version="8.4.1" />
<PackageVersion Include="FluentAvaloniaUI" Version="2.0.5" />
<PackageVersion Include="GtkSharp.Dependencies" Version="1.1.1" />
<PackageVersion Include="GtkSharp.Dependencies.osx" Version="0.0.5" />
<PackageVersion Include="jp2masa.Avalonia.Flexbox" Version="0.3.0-beta.4" />
<PackageVersion Include="LibHac" Version="0.19.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<<<<<<< HEAD
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.5.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
=======
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.2.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
>>>>>>> 45a6dffcf (Bump SharpMetal)
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
<PackageVersion Include="MsgPack.Cli" Version="1.0.1" />
<PackageVersion Include="NetCoreServer" Version="8.0.7" />
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageVersion Include="OpenTK.Core" Version="4.8.2" />
<PackageVersion Include="OpenTK.Graphics" Version="4.8.2" />
<PackageVersion Include="OpenTK.Audio.OpenAL" Version="4.8.2" />
<PackageVersion Include="OpenTK.Windowing.GraphicsLibraryFramework" Version="4.8.2" />
<PackageVersion Include="Ryujinx.Audio.OpenAL.Dependencies" Version="1.21.0.1" />
<PackageVersion Include="Ryujinx.Graphics.Nvdec.Dependencies" Version="5.0.1-build13" />
<PackageVersion Include="Ryujinx.Graphics.Vulkan.Dependencies.MoltenVK" Version="1.2.0" />
<PackageVersion Include="Ryujinx.GtkSharp" Version="3.24.24.59-ryujinx" />
<PackageVersion Include="Ryujinx.SDL2-CS" Version="2.28.1-build28" />
<PackageVersion Include="securifybv.ShellLink" Version="0.1.0" />
<PackageVersion Include="shaderc.net" Version="0.1.0" />
<PackageVersion Include="SharpMetal" Version="1.0.0-preview9" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="Silk.NET.Vulkan" Version="2.16.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.EXT" Version="2.16.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.KHR" Version="2.16.0" />
<<<<<<< HEAD
<PackageVersion Include="SixLabors.ImageSharp" Version="2.1.8" />
<PackageVersion Include="SixLabors.ImageSharp.Drawing" Version="1.0.0" />
<PackageVersion Include="SPB" Version="0.0.4-build32" />
=======
<PackageVersion Include="SixLabors.ImageSharp" Version="1.0.4" />
<PackageVersion Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11" />
<PackageVersion Include="SPB" Version="0.0.4-build28" />
<PackageVersion Include="System.Drawing.Common" Version="8.0.1" />
>>>>>>> 45a6dffcf (Bump SharpMetal)
<PackageVersion Include="System.IO.Hashing" Version="8.0.0" />
<PackageVersion Include="System.Management" Version="8.0.0" />
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
</ItemGroup>
</Project>

View File

@ -2,7 +2,7 @@ using Ryujinx.Graphics.GAL;
namespace Ryujinx.Graphics.Metal
{
public class CounterEvent : ICounterEvent
class CounterEvent : ICounterEvent
{
public CounterEvent()

View File

@ -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;
}
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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<BufferHandle, IntPtr>(ref buffer));
var span = new Span<byte>(mtlBuffer.Contents.ToPointer(), (int)mtlBuffer.Length);
data.CopyTo(span.Slice(offset));
data.CopyTo(span[offset..]);
mtlBuffer.DidModifyRange(new NSRange
{
location = (ulong)offset,

View File

@ -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,

View File

@ -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;
}
}
}

View File

@ -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)

View File

@ -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()

View File

@ -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;

View File

@ -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;

View File

@ -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
}

View File

@ -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();

View File

@ -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()