mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2025-01-09 11:17:20 -03:00
some initial metal commits cherry-picked
This commit is contained in:
parent
278fe9d4f0
commit
cbad43b003
27 changed files with 2821 additions and 1 deletions
|
@ -44,6 +44,7 @@
|
|||
<PackageVersion Include="Gommon" Version="2.6.8" />
|
||||
<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.21.0" />
|
||||
<PackageVersion Include="Silk.NET.Vulkan.Extensions.EXT" Version="2.21.0" />
|
||||
|
|
|
@ -80,6 +80,10 @@ EndProject
|
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Horizon.Kernel.Generators", "src\Ryujinx.Horizon.Kernel.Generators\Ryujinx.Horizon.Kernel.Generators.csproj", "{7F55A45D-4E1D-4A36-ADD3-87F29A285AA2}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.HLE.Generators", "src\Ryujinx.HLE.Generators\Ryujinx.HLE.Generators.csproj", "{B575BCDE-2FD8-4A5D-8756-31CDD7FE81F0}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ryujinx.Graphics.Metal", "src\Ryujinx.Graphics.Metal\Ryujinx.Graphics.Metal.csproj", "{C08931FA-1191-417A-864F-3882D93E683B}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{A602AE97-91A5-4608-8DF1-EBF4ED7A0B9E} = {A602AE97-91A5-4608-8DF1-EBF4ED7A0B9E}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{36F870C1-3E5F-485F-B426-F0645AF78751}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
|
@ -257,6 +261,10 @@ Global
|
|||
{4A89A234-4F19-497D-A576-DDE8CDFC5B22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4A89A234-4F19-497D-A576-DDE8CDFC5B22}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4A89A234-4F19-497D-A576-DDE8CDFC5B22}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C08931FA-1191-417A-864F-3882D93E683B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C08931FA-1191-417A-864F-3882D93E683B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C08931FA-1191-417A-864F-3882D93E683B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C08931FA-1191-417A-864F-3882D93E683B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -8,5 +8,6 @@ namespace Ryujinx.Common.Configuration
|
|||
{
|
||||
Vulkan,
|
||||
OpenGl,
|
||||
Metal
|
||||
}
|
||||
}
|
||||
|
|
13
src/Ryujinx.Graphics.Metal/Constants.cs
Normal file
13
src/Ryujinx.Graphics.Metal/Constants.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
static class Constants
|
||||
{
|
||||
// TODO: Check these values, these were largely copied from Vulkan
|
||||
public const int MaxShaderStages = 5;
|
||||
public const int MaxUniformBuffersPerStage = 18;
|
||||
public const int MaxStorageBuffersPerStage = 16;
|
||||
public const int MaxTexturesPerStage = 64;
|
||||
public const int MaxCommandBuffersPerQueue = 16;
|
||||
public const int MaxTextureBindings = MaxTexturesPerStage * MaxShaderStages;
|
||||
}
|
||||
}
|
23
src/Ryujinx.Graphics.Metal/CounterEvent.cs
Normal file
23
src/Ryujinx.Graphics.Metal/CounterEvent.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using Ryujinx.Graphics.GAL;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
public class CounterEvent : ICounterEvent
|
||||
{
|
||||
|
||||
public CounterEvent()
|
||||
{
|
||||
Invalid = false;
|
||||
}
|
||||
|
||||
public bool Invalid { get; set; }
|
||||
public bool ReserveForHostAccess()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Flush() { }
|
||||
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
206
src/Ryujinx.Graphics.Metal/EnumConversion.cs
Normal file
206
src/Ryujinx.Graphics.Metal/EnumConversion.cs
Normal file
|
@ -0,0 +1,206 @@
|
|||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Graphics.GAL;
|
||||
using SharpMetal;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
static class EnumConversion
|
||||
{
|
||||
public static MTLSamplerAddressMode Convert(this AddressMode mode)
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
AddressMode.Clamp => MTLSamplerAddressMode.ClampToEdge, // TODO: Should be clamp.
|
||||
AddressMode.Repeat => MTLSamplerAddressMode.Repeat,
|
||||
AddressMode.MirrorClamp => MTLSamplerAddressMode.MirrorClampToEdge, // TODO: Should be mirror clamp.
|
||||
AddressMode.MirroredRepeat => MTLSamplerAddressMode.MirrorRepeat,
|
||||
AddressMode.ClampToBorder => MTLSamplerAddressMode.ClampToBorderColor,
|
||||
AddressMode.ClampToEdge => MTLSamplerAddressMode.ClampToEdge,
|
||||
AddressMode.MirrorClampToEdge => MTLSamplerAddressMode.MirrorClampToEdge,
|
||||
AddressMode.MirrorClampToBorder => MTLSamplerAddressMode.ClampToBorderColor, // TODO: Should be mirror clamp to border.
|
||||
_ => LogInvalidAndReturn(mode, nameof(AddressMode), MTLSamplerAddressMode.ClampToEdge) // TODO: Should be clamp.
|
||||
};
|
||||
}
|
||||
|
||||
public static MTLBlendFactor Convert(this BlendFactor factor)
|
||||
{
|
||||
return factor switch
|
||||
{
|
||||
BlendFactor.Zero or BlendFactor.ZeroGl => MTLBlendFactor.Zero,
|
||||
BlendFactor.One or BlendFactor.OneGl => MTLBlendFactor.One,
|
||||
BlendFactor.SrcColor or BlendFactor.SrcColorGl => MTLBlendFactor.SourceColor,
|
||||
BlendFactor.OneMinusSrcColor or BlendFactor.OneMinusSrcColorGl => MTLBlendFactor.OneMinusSourceColor,
|
||||
BlendFactor.SrcAlpha or BlendFactor.SrcAlphaGl => MTLBlendFactor.SourceAlpha,
|
||||
BlendFactor.OneMinusSrcAlpha or BlendFactor.OneMinusSrcAlphaGl => MTLBlendFactor.OneMinusSourceAlpha,
|
||||
BlendFactor.DstAlpha or BlendFactor.DstAlphaGl => MTLBlendFactor.DestinationAlpha,
|
||||
BlendFactor.OneMinusDstAlpha or BlendFactor.OneMinusDstAlphaGl => MTLBlendFactor.OneMinusDestinationAlpha,
|
||||
BlendFactor.DstColor or BlendFactor.DstColorGl => MTLBlendFactor.DestinationColor,
|
||||
BlendFactor.OneMinusDstColor or BlendFactor.OneMinusDstColorGl => MTLBlendFactor.OneMinusDestinationColor,
|
||||
BlendFactor.SrcAlphaSaturate or BlendFactor.SrcAlphaSaturateGl => MTLBlendFactor.SourceAlphaSaturated,
|
||||
BlendFactor.Src1Color or BlendFactor.Src1ColorGl => MTLBlendFactor.Source1Color,
|
||||
BlendFactor.OneMinusSrc1Color or BlendFactor.OneMinusSrc1ColorGl => MTLBlendFactor.OneMinusSource1Color,
|
||||
BlendFactor.Src1Alpha or BlendFactor.Src1AlphaGl => MTLBlendFactor.Source1Alpha,
|
||||
BlendFactor.OneMinusSrc1Alpha or BlendFactor.OneMinusSrc1AlphaGl => MTLBlendFactor.OneMinusSource1Alpha,
|
||||
BlendFactor.ConstantColor => MTLBlendFactor.BlendColor,
|
||||
BlendFactor.OneMinusConstantColor => MTLBlendFactor.OneMinusBlendColor,
|
||||
BlendFactor.ConstantAlpha => MTLBlendFactor.BlendAlpha,
|
||||
BlendFactor.OneMinusConstantAlpha => MTLBlendFactor.OneMinusBlendAlpha,
|
||||
_ => LogInvalidAndReturn(factor, nameof(BlendFactor), MTLBlendFactor.Zero)
|
||||
};
|
||||
}
|
||||
|
||||
public static MTLBlendOperation Convert(this BlendOp op)
|
||||
{
|
||||
return op switch
|
||||
{
|
||||
BlendOp.Add or BlendOp.AddGl => MTLBlendOperation.Add,
|
||||
BlendOp.Subtract or BlendOp.SubtractGl => MTLBlendOperation.Subtract,
|
||||
BlendOp.ReverseSubtract or BlendOp.ReverseSubtractGl => MTLBlendOperation.ReverseSubtract,
|
||||
BlendOp.Minimum => MTLBlendOperation.Min,
|
||||
BlendOp.Maximum => MTLBlendOperation.Max,
|
||||
_ => LogInvalidAndReturn(op, nameof(BlendOp), MTLBlendOperation.Add)
|
||||
};
|
||||
}
|
||||
|
||||
public static MTLCompareFunction Convert(this CompareOp op)
|
||||
{
|
||||
return op switch
|
||||
{
|
||||
CompareOp.Never or CompareOp.NeverGl => MTLCompareFunction.Never,
|
||||
CompareOp.Less or CompareOp.LessGl => MTLCompareFunction.Less,
|
||||
CompareOp.Equal or CompareOp.EqualGl => MTLCompareFunction.Equal,
|
||||
CompareOp.LessOrEqual or CompareOp.LessOrEqualGl => MTLCompareFunction.LessEqual,
|
||||
CompareOp.Greater or CompareOp.GreaterGl => MTLCompareFunction.Greater,
|
||||
CompareOp.NotEqual or CompareOp.NotEqualGl => MTLCompareFunction.NotEqual,
|
||||
CompareOp.GreaterOrEqual or CompareOp.GreaterOrEqualGl => MTLCompareFunction.GreaterEqual,
|
||||
CompareOp.Always or CompareOp.AlwaysGl => MTLCompareFunction.Always,
|
||||
_ => LogInvalidAndReturn(op, nameof(CompareOp), MTLCompareFunction.Never)
|
||||
};
|
||||
}
|
||||
|
||||
public static MTLCullMode Convert(this Face face)
|
||||
{
|
||||
return face switch
|
||||
{
|
||||
Face.Back => MTLCullMode.Back,
|
||||
Face.Front => MTLCullMode.Front,
|
||||
Face.FrontAndBack => MTLCullMode.None,
|
||||
_ => LogInvalidAndReturn(face, nameof(Face), MTLCullMode.Back)
|
||||
};
|
||||
}
|
||||
|
||||
public static MTLWinding Convert(this FrontFace frontFace)
|
||||
{
|
||||
return frontFace switch
|
||||
{
|
||||
FrontFace.Clockwise => MTLWinding.Clockwise,
|
||||
FrontFace.CounterClockwise => MTLWinding.CounterClockwise,
|
||||
_ => LogInvalidAndReturn(frontFace, nameof(FrontFace), MTLWinding.Clockwise)
|
||||
};
|
||||
}
|
||||
|
||||
public static MTLIndexType Convert(this IndexType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
IndexType.UShort => MTLIndexType.UInt16,
|
||||
IndexType.UInt => MTLIndexType.UInt32,
|
||||
_ => LogInvalidAndReturn(type, nameof(IndexType), MTLIndexType.UInt16)
|
||||
};
|
||||
}
|
||||
|
||||
public static MTLSamplerMinMagFilter Convert(this MagFilter filter)
|
||||
{
|
||||
return filter switch
|
||||
{
|
||||
MagFilter.Nearest => MTLSamplerMinMagFilter.Nearest,
|
||||
MagFilter.Linear => MTLSamplerMinMagFilter.Linear,
|
||||
_ => LogInvalidAndReturn(filter, nameof(MagFilter), MTLSamplerMinMagFilter.Nearest)
|
||||
};
|
||||
}
|
||||
|
||||
public static (MTLSamplerMinMagFilter, MTLSamplerMipFilter) Convert(this MinFilter filter)
|
||||
{
|
||||
return filter switch
|
||||
{
|
||||
MinFilter.Nearest => (MTLSamplerMinMagFilter.Nearest, MTLSamplerMipFilter.Nearest),
|
||||
MinFilter.Linear => (MTLSamplerMinMagFilter.Linear, MTLSamplerMipFilter.Linear),
|
||||
MinFilter.NearestMipmapNearest => (MTLSamplerMinMagFilter.Nearest, MTLSamplerMipFilter.Nearest),
|
||||
MinFilter.LinearMipmapNearest => (MTLSamplerMinMagFilter.Linear, MTLSamplerMipFilter.Nearest),
|
||||
MinFilter.NearestMipmapLinear => (MTLSamplerMinMagFilter.Nearest, MTLSamplerMipFilter.Linear),
|
||||
MinFilter.LinearMipmapLinear => (MTLSamplerMinMagFilter.Linear, MTLSamplerMipFilter.Linear),
|
||||
_ => LogInvalidAndReturn(filter, nameof(MinFilter), (MTLSamplerMinMagFilter.Nearest, MTLSamplerMipFilter.Nearest))
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Metal does not have native support for Triangle Fans but it is possible to emulate with TriangleStrip and moving around the indices
|
||||
public static MTLPrimitiveType Convert(this PrimitiveTopology topology)
|
||||
{
|
||||
return topology switch
|
||||
{
|
||||
PrimitiveTopology.Points => MTLPrimitiveType.Point,
|
||||
PrimitiveTopology.Lines => MTLPrimitiveType.Line,
|
||||
PrimitiveTopology.LineStrip => MTLPrimitiveType.LineStrip,
|
||||
PrimitiveTopology.Triangles => MTLPrimitiveType.Triangle,
|
||||
PrimitiveTopology.TriangleStrip => MTLPrimitiveType.TriangleStrip,
|
||||
_ => LogInvalidAndReturn(topology, nameof(PrimitiveTopology), MTLPrimitiveType.Triangle)
|
||||
};
|
||||
}
|
||||
|
||||
public static MTLStencilOperation Convert(this StencilOp op)
|
||||
{
|
||||
return op switch
|
||||
{
|
||||
StencilOp.Keep or StencilOp.KeepGl => MTLStencilOperation.Keep,
|
||||
StencilOp.Zero or StencilOp.ZeroGl => MTLStencilOperation.Zero,
|
||||
StencilOp.Replace or StencilOp.ReplaceGl => MTLStencilOperation.Replace,
|
||||
StencilOp.IncrementAndClamp or StencilOp.IncrementAndClampGl => MTLStencilOperation.IncrementClamp,
|
||||
StencilOp.DecrementAndClamp or StencilOp.DecrementAndClampGl => MTLStencilOperation.DecrementClamp,
|
||||
StencilOp.Invert or StencilOp.InvertGl => MTLStencilOperation.Invert,
|
||||
StencilOp.IncrementAndWrap or StencilOp.IncrementAndWrapGl => MTLStencilOperation.IncrementWrap,
|
||||
StencilOp.DecrementAndWrap or StencilOp.DecrementAndWrapGl => MTLStencilOperation.DecrementWrap,
|
||||
_ => LogInvalidAndReturn(op, nameof(StencilOp), MTLStencilOperation.Keep)
|
||||
};
|
||||
}
|
||||
|
||||
public static MTLTextureType Convert(this Target target)
|
||||
{
|
||||
return target switch
|
||||
{
|
||||
Target.TextureBuffer => MTLTextureType.TypeTextureBuffer,
|
||||
Target.Texture1D => MTLTextureType.Type1D,
|
||||
Target.Texture1DArray => MTLTextureType.Type1DArray,
|
||||
Target.Texture2D => MTLTextureType.Type2D,
|
||||
Target.Texture2DArray => MTLTextureType.Type2DArray,
|
||||
Target.Texture2DMultisample => MTLTextureType.Type2DMultisample,
|
||||
Target.Texture2DMultisampleArray => MTLTextureType.Type2DMultisampleArray,
|
||||
Target.Texture3D => MTLTextureType.Type3D,
|
||||
Target.Cubemap => MTLTextureType.TypeCube,
|
||||
Target.CubemapArray => MTLTextureType.TypeCubeArray,
|
||||
_ => LogInvalidAndReturn(target, nameof(Target), MTLTextureType.Type2D)
|
||||
};
|
||||
}
|
||||
|
||||
public static MTLTextureSwizzle Convert(this SwizzleComponent swizzleComponent)
|
||||
{
|
||||
return swizzleComponent switch
|
||||
{
|
||||
SwizzleComponent.Zero => MTLTextureSwizzle.Zero,
|
||||
SwizzleComponent.One => MTLTextureSwizzle.One,
|
||||
SwizzleComponent.Red => MTLTextureSwizzle.Red,
|
||||
SwizzleComponent.Green => MTLTextureSwizzle.Green,
|
||||
SwizzleComponent.Blue => MTLTextureSwizzle.Blue,
|
||||
SwizzleComponent.Alpha => MTLTextureSwizzle.Alpha,
|
||||
_ => LogInvalidAndReturn(swizzleComponent, nameof(SwizzleComponent), MTLTextureSwizzle.Zero),
|
||||
};
|
||||
}
|
||||
|
||||
private static T2 LogInvalidAndReturn<T1, T2>(T1 value, string name, T2 defaultValue = default)
|
||||
{
|
||||
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {name} enum value: {value}.");
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
14
src/Ryujinx.Graphics.Metal/FormatCapabilities.cs
Normal file
14
src/Ryujinx.Graphics.Metal/FormatCapabilities.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using SharpMetal;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
static class FormatCapabilities
|
||||
{
|
||||
public static MTLPixelFormat ConvertToMTLFormat(GAL.Format srcFormat)
|
||||
{
|
||||
var format = FormatTable.GetFormat(srcFormat);
|
||||
|
||||
return format;
|
||||
}
|
||||
}
|
||||
}
|
172
src/Ryujinx.Graphics.Metal/FormatTable.cs
Normal file
172
src/Ryujinx.Graphics.Metal/FormatTable.cs
Normal file
|
@ -0,0 +1,172 @@
|
|||
using Ryujinx.Graphics.GAL;
|
||||
using System;
|
||||
using SharpMetal;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
static class FormatTable
|
||||
{
|
||||
private static readonly MTLPixelFormat[] _table;
|
||||
|
||||
static FormatTable()
|
||||
{
|
||||
_table = new MTLPixelFormat[Enum.GetNames(typeof(Format)).Length];
|
||||
|
||||
Add(Format.R8Unorm, MTLPixelFormat.R8Unorm);
|
||||
Add(Format.R8Snorm, MTLPixelFormat.R8Snorm);
|
||||
Add(Format.R8Uint, MTLPixelFormat.R8Uint);
|
||||
Add(Format.R8Sint, MTLPixelFormat.R8Sint);
|
||||
Add(Format.R16Float, MTLPixelFormat.R16Float);
|
||||
Add(Format.R16Unorm, MTLPixelFormat.R16Unorm);
|
||||
Add(Format.R16Snorm, MTLPixelFormat.R16Snorm);
|
||||
Add(Format.R16Uint, MTLPixelFormat.R16Uint);
|
||||
Add(Format.R16Sint, MTLPixelFormat.R16Sint);
|
||||
Add(Format.R32Float, MTLPixelFormat.R32Float);
|
||||
Add(Format.R32Uint, MTLPixelFormat.R32Uint);
|
||||
Add(Format.R32Sint, MTLPixelFormat.R32Sint);
|
||||
Add(Format.R8G8Unorm, MTLPixelFormat.RG8Unorm);
|
||||
Add(Format.R8G8Snorm, MTLPixelFormat.RG8Snorm);
|
||||
Add(Format.R8G8Uint, MTLPixelFormat.RG8Uint);
|
||||
Add(Format.R8G8Sint, MTLPixelFormat.RG8Sint);
|
||||
Add(Format.R16G16Float, MTLPixelFormat.RG16Float);
|
||||
Add(Format.R16G16Unorm, MTLPixelFormat.RG16Unorm);
|
||||
Add(Format.R16G16Snorm, MTLPixelFormat.RG16Snorm);
|
||||
Add(Format.R16G16Uint, MTLPixelFormat.RG16Uint);
|
||||
Add(Format.R16G16Sint, MTLPixelFormat.RG16Sint);
|
||||
Add(Format.R32G32Float, MTLPixelFormat.RG32Float);
|
||||
Add(Format.R32G32Uint, MTLPixelFormat.RG32Uint);
|
||||
Add(Format.R32G32Sint, MTLPixelFormat.RG32Sint);
|
||||
// Add(Format.R8G8B8Unorm, MTLPixelFormat.R8G8B8Unorm);
|
||||
// Add(Format.R8G8B8Snorm, MTLPixelFormat.R8G8B8Snorm);
|
||||
// Add(Format.R8G8B8Uint, MTLPixelFormat.R8G8B8Uint);
|
||||
// Add(Format.R8G8B8Sint, MTLPixelFormat.R8G8B8Sint);
|
||||
// Add(Format.R16G16B16Float, MTLPixelFormat.R16G16B16Float);
|
||||
// Add(Format.R16G16B16Unorm, MTLPixelFormat.R16G16B16Unorm);
|
||||
// Add(Format.R16G16B16Snorm, MTLPixelFormat.R16G16B16SNorm);
|
||||
// Add(Format.R16G16B16Uint, MTLPixelFormat.R16G16B16Uint);
|
||||
// Add(Format.R16G16B16Sint, MTLPixelFormat.R16G16B16Sint);
|
||||
// Add(Format.R32G32B32Float, MTLPixelFormat.R32G32B32Sfloat);
|
||||
// Add(Format.R32G32B32Uint, MTLPixelFormat.R32G32B32Uint);
|
||||
// Add(Format.R32G32B32Sint, MTLPixelFormat.R32G32B32Sint);
|
||||
Add(Format.R8G8B8A8Unorm, MTLPixelFormat.RGBA8Unorm);
|
||||
Add(Format.R8G8B8A8Snorm, MTLPixelFormat.RGBA8Snorm);
|
||||
Add(Format.R8G8B8A8Uint, MTLPixelFormat.RGBA8Uint);
|
||||
Add(Format.R8G8B8A8Sint, MTLPixelFormat.RGBA8Sint);
|
||||
Add(Format.R16G16B16A16Float, MTLPixelFormat.RGBA16Float);
|
||||
Add(Format.R16G16B16A16Unorm, MTLPixelFormat.RGBA16Unorm);
|
||||
Add(Format.R16G16B16A16Snorm, MTLPixelFormat.RGBA16Snorm);
|
||||
Add(Format.R16G16B16A16Uint, MTLPixelFormat.RGBA16Uint);
|
||||
Add(Format.R16G16B16A16Sint, MTLPixelFormat.RGBA16Sint);
|
||||
Add(Format.R32G32B32A32Float, MTLPixelFormat.RGBA32Float);
|
||||
Add(Format.R32G32B32A32Uint, MTLPixelFormat.RGBA32Uint);
|
||||
Add(Format.R32G32B32A32Sint, MTLPixelFormat.RGBA32Sint);
|
||||
Add(Format.S8Uint, MTLPixelFormat.Stencil8);
|
||||
Add(Format.D16Unorm, MTLPixelFormat.Depth16Unorm);
|
||||
// Add(Format.S8UintD24Unorm, MTLPixelFormat.S8UintD24Unorm);
|
||||
Add(Format.D32Float, MTLPixelFormat.Depth32Float);
|
||||
Add(Format.D24UnormS8Uint, MTLPixelFormat.Depth24Unorm_Stencil8);
|
||||
Add(Format.D32FloatS8Uint, MTLPixelFormat.Depth32Float_Stencil8);
|
||||
Add(Format.R8G8B8A8Srgb, MTLPixelFormat.RGBA8Unorm_sRGB);
|
||||
// Add(Format.R4G4Unorm, MTLPixelFormat.R4G4Unorm);
|
||||
// Add(Format.R4G4B4A4Unorm, MTLPixelFormat.R4G4B4A4Unorm);
|
||||
// Add(Format.R5G5B5X1Unorm, MTLPixelFormat.R5G5B5X1Unorm);
|
||||
// Add(Format.R5G5B5A1Unorm, MTLPixelFormat.R5G5B5A1Unorm);
|
||||
Add(Format.R5G6B5Unorm, MTLPixelFormat.B5G6R5Unorm);
|
||||
Add(Format.R10G10B10A2Unorm, MTLPixelFormat.RGB10A2Unorm);
|
||||
Add(Format.R10G10B10A2Uint, MTLPixelFormat.RGB10A2Uint);
|
||||
Add(Format.R11G11B10Float, MTLPixelFormat.RG11B10Float);
|
||||
Add(Format.R9G9B9E5Float, MTLPixelFormat.RGB9E5Float);
|
||||
Add(Format.Bc1RgbaUnorm, MTLPixelFormat.BC1_RGBA);
|
||||
Add(Format.Bc2Unorm, MTLPixelFormat.BC2_RGBA);
|
||||
Add(Format.Bc3Unorm, MTLPixelFormat.BC3_RGBA);
|
||||
Add(Format.Bc1RgbaSrgb, MTLPixelFormat.BC1_RGBA_sRGB);
|
||||
Add(Format.Bc2Srgb, MTLPixelFormat.BC2_RGBA_sRGB);
|
||||
Add(Format.Bc3Srgb, MTLPixelFormat.BC3_RGBA_sRGB);
|
||||
Add(Format.Bc4Unorm, MTLPixelFormat.BC4_RUnorm);
|
||||
Add(Format.Bc4Snorm, MTLPixelFormat.BC4_RSnorm);
|
||||
Add(Format.Bc5Unorm, MTLPixelFormat.BC5_RGUnorm);
|
||||
Add(Format.Bc5Snorm, MTLPixelFormat.BC5_RGSnorm);
|
||||
Add(Format.Bc7Unorm, MTLPixelFormat.BC7_RGBAUnorm);
|
||||
Add(Format.Bc7Srgb, MTLPixelFormat.BC7_RGBAUnorm_sRGB);
|
||||
Add(Format.Bc6HSfloat, MTLPixelFormat.BC6H_RGBFloat);
|
||||
Add(Format.Bc6HUfloat, MTLPixelFormat.BC6H_RGBUfloat);
|
||||
Add(Format.Etc2RgbUnorm, MTLPixelFormat.ETC2_RGB8);
|
||||
Add(Format.Etc2RgbaUnorm, MTLPixelFormat.ETC2_RGB8A1);
|
||||
// Add(Format.Etc2RgbPtaUnorm, MTLPixelFormat.Etc2RgbPtaUnorm);
|
||||
Add(Format.Etc2RgbSrgb, MTLPixelFormat.ETC2_RGB8_sRGB);
|
||||
Add(Format.Etc2RgbaSrgb, MTLPixelFormat.ETC2_RGB8A1_sRGB);
|
||||
// Add(Format.Etc2RgbPtaSrgb, MTLPixelFormat.Etc2RgbPtaSrgb);
|
||||
// Add(Format.R8Uscaled, MTLPixelFormat.R8Uscaled);
|
||||
// Add(Format.R8Sscaled, MTLPixelFormat.R8Sscaled);
|
||||
// Add(Format.R16Uscaled, MTLPixelFormat.R16Uscaled);
|
||||
// Add(Format.R16Sscaled, MTLPixelFormat.R16Sscaled);
|
||||
// Add(Format.R32Uscaled, MTLPixelFormat.R32Uscaled);
|
||||
// Add(Format.R32Sscaled, MTLPixelFormat.R32Sscaled);
|
||||
// Add(Format.R8G8Uscaled, MTLPixelFormat.R8G8Uscaled);
|
||||
// Add(Format.R8G8Sscaled, MTLPixelFormat.R8G8Sscaled);
|
||||
// Add(Format.R16G16Uscaled, MTLPixelFormat.R16G16Uscaled);
|
||||
// Add(Format.R16G16Sscaled, MTLPixelFormat.R16G16Sscaled);
|
||||
// Add(Format.R32G32Uscaled, MTLPixelFormat.R32G32Uscaled);
|
||||
// Add(Format.R32G32Sscaled, MTLPixelFormat.R32G32Sscaled);
|
||||
// Add(Format.R8G8B8Uscaled, MTLPixelFormat.R8G8B8Uscaled);
|
||||
// Add(Format.R8G8B8Sscaled, MTLPixelFormat.R8G8B8Sscaled);
|
||||
// Add(Format.R16G16B16Uscaled, MTLPixelFormat.R16G16B16Uscaled);
|
||||
// Add(Format.R16G16B16Sscaled, MTLPixelFormat.R16G16B16Sscaled);
|
||||
// Add(Format.R32G32B32Uscaled, MTLPixelFormat.R32G32B32Uscaled);
|
||||
// Add(Format.R32G32B32Sscaled, MTLPixelFormat.R32G32B32Sscaled);
|
||||
// Add(Format.R8G8B8A8Uscaled, MTLPixelFormat.R8G8B8A8Uscaled);
|
||||
// Add(Format.R8G8B8A8Sscaled, MTLPixelFormat.R8G8B8A8Sscaled);
|
||||
// Add(Format.R16G16B16A16Uscaled, MTLPixelFormat.R16G16B16A16Uscaled);
|
||||
// Add(Format.R16G16B16A16Sscaled, MTLPixelFormat.R16G16B16A16Sscaled);
|
||||
// Add(Format.R32G32B32A32Uscaled, MTLPixelFormat.R32G32B32A32Uscaled);
|
||||
// Add(Format.R32G32B32A32Sscaled, MTLPixelFormat.R32G32B32A32Sscaled);
|
||||
// Add(Format.R10G10B10A2Snorm, MTLPixelFormat.A2B10G10R10SNormPack32);
|
||||
// Add(Format.R10G10B10A2Sint, MTLPixelFormat.A2B10G10R10SintPack32);
|
||||
// Add(Format.R10G10B10A2Uscaled, MTLPixelFormat.A2B10G10R10UscaledPack32);
|
||||
// Add(Format.R10G10B10A2Sscaled, MTLPixelFormat.A2B10G10R10SscaledPack32);
|
||||
Add(Format.Astc4x4Unorm, MTLPixelFormat.ASTC_4x4_LDR);
|
||||
Add(Format.Astc5x4Unorm, MTLPixelFormat.ASTC_5x4_LDR);
|
||||
Add(Format.Astc5x5Unorm, MTLPixelFormat.ASTC_5x5_LDR);
|
||||
Add(Format.Astc6x5Unorm, MTLPixelFormat.ASTC_6x5_LDR);
|
||||
Add(Format.Astc6x6Unorm, MTLPixelFormat.ASTC_6x6_LDR);
|
||||
Add(Format.Astc8x5Unorm, MTLPixelFormat.ASTC_8x5_LDR);
|
||||
Add(Format.Astc8x6Unorm, MTLPixelFormat.ASTC_8x6_LDR);
|
||||
Add(Format.Astc8x8Unorm, MTLPixelFormat.ASTC_8x8_LDR);
|
||||
Add(Format.Astc10x5Unorm, MTLPixelFormat.ASTC_10x5_LDR);
|
||||
Add(Format.Astc10x6Unorm, MTLPixelFormat.ASTC_10x6_LDR);
|
||||
Add(Format.Astc10x8Unorm, MTLPixelFormat.ASTC_10x8_LDR);
|
||||
Add(Format.Astc10x10Unorm, MTLPixelFormat.ASTC_10x10_LDR);
|
||||
Add(Format.Astc12x10Unorm, MTLPixelFormat.ASTC_12x10_LDR);
|
||||
Add(Format.Astc12x12Unorm, MTLPixelFormat.ASTC_12x12_LDR);
|
||||
Add(Format.Astc4x4Srgb, MTLPixelFormat.ASTC_4x4_sRGB);
|
||||
Add(Format.Astc5x4Srgb, MTLPixelFormat.ASTC_5x4_sRGB);
|
||||
Add(Format.Astc5x5Srgb, MTLPixelFormat.ASTC_5x5_sRGB);
|
||||
Add(Format.Astc6x5Srgb, MTLPixelFormat.ASTC_6x5_sRGB);
|
||||
Add(Format.Astc6x6Srgb, MTLPixelFormat.ASTC_6x6_sRGB);
|
||||
Add(Format.Astc8x5Srgb, MTLPixelFormat.ASTC_8x5_sRGB);
|
||||
Add(Format.Astc8x6Srgb, MTLPixelFormat.ASTC_8x6_sRGB);
|
||||
Add(Format.Astc8x8Srgb, MTLPixelFormat.ASTC_8x8_sRGB);
|
||||
Add(Format.Astc10x5Srgb, MTLPixelFormat.ASTC_10x5_sRGB);
|
||||
Add(Format.Astc10x6Srgb, MTLPixelFormat.ASTC_10x6_sRGB);
|
||||
Add(Format.Astc10x8Srgb, MTLPixelFormat.ASTC_10x8_sRGB);
|
||||
Add(Format.Astc10x10Srgb, MTLPixelFormat.ASTC_10x10_sRGB);
|
||||
Add(Format.Astc12x10Srgb, MTLPixelFormat.ASTC_12x10_sRGB);
|
||||
Add(Format.Astc12x12Srgb, MTLPixelFormat.ASTC_12x12_sRGB);
|
||||
Add(Format.B5G6R5Unorm, MTLPixelFormat.B5G6R5Unorm);
|
||||
Add(Format.B5G5R5A1Unorm, MTLPixelFormat.BGR5A1Unorm);
|
||||
Add(Format.A1B5G5R5Unorm, MTLPixelFormat.A1BGR5Unorm);
|
||||
Add(Format.B8G8R8A8Unorm, MTLPixelFormat.BGRA8Unorm);
|
||||
Add(Format.B8G8R8A8Srgb, MTLPixelFormat.BGRA8Unorm_sRGB);
|
||||
}
|
||||
|
||||
private static void Add(Format format, MTLPixelFormat mtlFormat)
|
||||
{
|
||||
_table[(int)format] = mtlFormat;
|
||||
}
|
||||
|
||||
public static MTLPixelFormat GetFormat(Format format)
|
||||
{
|
||||
return _table[(int)format];
|
||||
}
|
||||
}
|
||||
}
|
82
src/Ryujinx.Graphics.Metal/HardwareInfo.cs
Normal file
82
src/Ryujinx.Graphics.Metal/HardwareInfo.cs
Normal file
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
static partial class HardwareInfoTools
|
||||
{
|
||||
|
||||
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";
|
||||
|
||||
[LibraryImport(IOKit, StringMarshalling = StringMarshalling.Utf8)]
|
||||
private static partial IntPtr IOServiceMatching(string name);
|
||||
|
||||
[LibraryImport(IOKit)]
|
||||
private static partial IntPtr IOServiceGetMatchingService(IntPtr mainPort, IntPtr matching);
|
||||
|
||||
[LibraryImport(IOKit)]
|
||||
private static partial IntPtr IORegistryEntryCreateCFProperty(IntPtr entry, IntPtr key, IntPtr allocator, UInt32 options);
|
||||
|
||||
[LibraryImport(CoreFoundation, StringMarshalling = StringMarshalling.Utf8)]
|
||||
private static partial IntPtr CFStringCreateWithCString(IntPtr allocator, string cString, UInt32 encoding);
|
||||
|
||||
[LibraryImport(CoreFoundation)]
|
||||
[return: MarshalAs(UnmanagedType.U1)]
|
||||
public static partial bool CFStringGetCString(IntPtr theString, IntPtr buffer, long bufferSizes, UInt32 encoding);
|
||||
|
||||
[LibraryImport(CoreFoundation)]
|
||||
public static partial IntPtr CFDataGetBytePtr(IntPtr theData);
|
||||
|
||||
static string GetNameFromId(uint id)
|
||||
{
|
||||
return id switch
|
||||
{
|
||||
0x1002 => "AMD",
|
||||
0x106B => "Apple",
|
||||
0x10DE => "NVIDIA",
|
||||
0x13B5 => "ARM",
|
||||
0x8086 => "Intel",
|
||||
_ => $"0x{id:X}"
|
||||
};
|
||||
}
|
||||
|
||||
public static string GetVendor()
|
||||
{
|
||||
var serviceDict = IOServiceMatching("IOGPU");
|
||||
var service = IOServiceGetMatchingService(IntPtr.Zero, serviceDict);
|
||||
var cfString = CFStringCreateWithCString(kCFAllocatorDefault, "vendor-id", kCFStringEncodingASCII);
|
||||
var cfProperty = IORegistryEntryCreateCFProperty(service, cfString, kCFAllocatorDefault, 0);
|
||||
|
||||
byte[] buffer = new byte[4];
|
||||
var bufferPtr = CFDataGetBytePtr(cfProperty);
|
||||
Marshal.Copy(bufferPtr, buffer, 0, buffer.Length);
|
||||
|
||||
var vendorId = BitConverter.ToUInt32(buffer);
|
||||
|
||||
return GetNameFromId(vendorId);
|
||||
}
|
||||
|
||||
public static string GetModel()
|
||||
{
|
||||
var serviceDict = IOServiceMatching("IOGPU");
|
||||
var service = IOServiceGetMatchingService(IntPtr.Zero, serviceDict);
|
||||
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))
|
||||
{
|
||||
var model = Marshal.PtrToStringUTF8(bufferPtr);
|
||||
Marshal.FreeHGlobal(bufferPtr);
|
||||
return model;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
247
src/Ryujinx.Graphics.Metal/MetalRenderer.cs
Normal file
247
src/Ryujinx.Graphics.Metal/MetalRenderer.cs
Normal file
|
@ -0,0 +1,247 @@
|
|||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Graphics.GAL;
|
||||
using Ryujinx.Graphics.Shader.Translation;
|
||||
using SharpMetal.Foundation;
|
||||
using SharpMetal.Metal;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
[SupportedOSPlatform("macos")]
|
||||
public sealed class MetalRenderer : IRenderer
|
||||
{
|
||||
private readonly MTLDevice _device;
|
||||
private readonly Window _window;
|
||||
private readonly Pipeline _pipeline;
|
||||
private readonly MTLCommandQueue _queue;
|
||||
|
||||
public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured;
|
||||
public bool PreferThreading => true;
|
||||
public IPipeline Pipeline => _pipeline;
|
||||
public IWindow Window => _window;
|
||||
|
||||
public MetalRenderer()
|
||||
{
|
||||
_device = MTLDevice.CreateSystemDefaultDevice();
|
||||
_queue = _device.NewCommandQueue();
|
||||
_pipeline = new Pipeline(_device, _queue);
|
||||
_window = new Window(this);
|
||||
}
|
||||
|
||||
public void Initialize(GraphicsDebugLevel logLevel)
|
||||
{
|
||||
}
|
||||
|
||||
public void BackgroundContextAction(Action action, bool alwaysBackground = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public BufferHandle CreateBuffer(int size, BufferHandle storageHint)
|
||||
{
|
||||
return CreateBuffer(size, BufferAccess.Default);
|
||||
}
|
||||
|
||||
public BufferHandle CreateBuffer(IntPtr pointer, int size)
|
||||
{
|
||||
var buffer = _device.NewBuffer(pointer, (ulong)size, MTLResourceOptions.ResourceStorageModeShared);
|
||||
var bufferPtr = buffer.NativePtr;
|
||||
return Unsafe.As<IntPtr, BufferHandle>(ref bufferPtr);
|
||||
}
|
||||
|
||||
public BufferHandle CreateBuffer(int size, BufferAccess access)
|
||||
{
|
||||
var buffer = _device.NewBuffer((ulong)size, MTLResourceOptions.ResourceStorageModeShared);
|
||||
|
||||
if (access == BufferAccess.FlushPersistent)
|
||||
{
|
||||
buffer.SetPurgeableState(MTLPurgeableState.NonVolatile);
|
||||
}
|
||||
|
||||
var bufferPtr = buffer.NativePtr;
|
||||
return Unsafe.As<IntPtr, BufferHandle>(ref bufferPtr);
|
||||
}
|
||||
|
||||
public IProgram CreateProgram(ShaderSource[] shaders, ShaderInfo info)
|
||||
{
|
||||
var library = _device.NewDefaultLibrary();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ISampler CreateSampler(SamplerCreateInfo info)
|
||||
{
|
||||
(MTLSamplerMinMagFilter minFilter, MTLSamplerMipFilter mipFilter) = info.MinFilter.Convert();
|
||||
|
||||
var sampler = _device.NewSamplerState(new MTLSamplerDescriptor
|
||||
{
|
||||
BorderColor = MTLSamplerBorderColor.TransparentBlack,
|
||||
MinFilter = minFilter,
|
||||
MagFilter = info.MagFilter.Convert(),
|
||||
MipFilter = mipFilter,
|
||||
CompareFunction = info.CompareOp.Convert(),
|
||||
LodMinClamp = info.MinLod,
|
||||
LodMaxClamp = info.MaxLod,
|
||||
LodAverage = false,
|
||||
MaxAnisotropy = (uint)info.MaxAnisotropy,
|
||||
SAddressMode = info.AddressU.Convert(),
|
||||
TAddressMode = info.AddressV.Convert(),
|
||||
RAddressMode = info.AddressP.Convert()
|
||||
});
|
||||
|
||||
return new Sampler(sampler);
|
||||
}
|
||||
|
||||
public ITexture CreateTexture(TextureCreateInfo info)
|
||||
{
|
||||
return new Texture(_device, _pipeline, info);
|
||||
}
|
||||
|
||||
public bool PrepareHostMapping(IntPtr address, ulong size)
|
||||
{
|
||||
// TODO: Metal Host Mapping
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CreateSync(ulong id, bool strict)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DeleteBuffer(BufferHandle buffer)
|
||||
{
|
||||
MTLBuffer mtlBuffer = new(Unsafe.As<BufferHandle, IntPtr>(ref buffer));
|
||||
mtlBuffer.SetPurgeableState(MTLPurgeableState.Empty);
|
||||
}
|
||||
|
||||
public unsafe PinnedSpan<byte> GetBufferData(BufferHandle buffer, int offset, int size)
|
||||
{
|
||||
MTLBuffer mtlBuffer = new(Unsafe.As<BufferHandle, IntPtr>(ref buffer));
|
||||
return new PinnedSpan<byte>(IntPtr.Add(mtlBuffer.Contents, offset).ToPointer(), size);
|
||||
}
|
||||
|
||||
public Capabilities GetCapabilities()
|
||||
{
|
||||
// TODO: Finalize these values
|
||||
return new Capabilities(
|
||||
api: TargetApi.Metal,
|
||||
vendorName: HardwareInfoTools.GetVendor(),
|
||||
hasFrontFacingBug: false,
|
||||
hasVectorIndexingBug: true,
|
||||
needsFragmentOutputSpecialization: true,
|
||||
reduceShaderPrecision: true,
|
||||
supportsAstcCompression: true,
|
||||
supportsBc123Compression: true,
|
||||
supportsBc45Compression: true,
|
||||
supportsBc67Compression: true,
|
||||
supportsEtc2Compression: true,
|
||||
supports3DTextureCompression: true,
|
||||
supportsBgraFormat: true,
|
||||
supportsR4G4Format: false,
|
||||
supportsR4G4B4A4Format: true,
|
||||
supportsSnormBufferTextureFormat: true,
|
||||
supports5BitComponentFormat: true,
|
||||
supportsBlendEquationAdvanced: false,
|
||||
supportsFragmentShaderInterlock: true,
|
||||
supportsFragmentShaderOrderingIntel: false,
|
||||
supportsGeometryShader: false,
|
||||
supportsGeometryShaderPassthrough: false,
|
||||
supportsTransformFeedback: false,
|
||||
supportsImageLoadFormatted: false,
|
||||
supportsLayerVertexTessellation: false,
|
||||
supportsMismatchingViewFormat: true,
|
||||
supportsCubemapView: true,
|
||||
supportsNonConstantTextureOffset: false,
|
||||
supportsShaderBallot: false,
|
||||
supportsShaderBarrierDivergence: false,
|
||||
supportsShaderFloat64: false,
|
||||
supportsTextureShadowLod: false,
|
||||
supportsViewportIndexVertexTessellation: false,
|
||||
supportsViewportMask: false,
|
||||
supportsViewportSwizzle: false,
|
||||
supportsIndirectParameters: true,
|
||||
supportsDepthClipControl: false,
|
||||
maximumUniformBuffersPerStage: Constants.MaxUniformBuffersPerStage,
|
||||
maximumStorageBuffersPerStage: Constants.MaxStorageBuffersPerStage,
|
||||
maximumTexturesPerStage: Constants.MaxTexturesPerStage,
|
||||
maximumImagesPerStage: Constants.MaxTextureBindings,
|
||||
maximumComputeSharedMemorySize: (int)_device.MaxThreadgroupMemoryLength,
|
||||
maximumSupportedAnisotropy: 0,
|
||||
storageBufferOffsetAlignment: 0,
|
||||
gatherBiasPrecision: 0
|
||||
);
|
||||
}
|
||||
|
||||
public ulong GetCurrentSync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public HardwareInfo GetHardwareInfo()
|
||||
{
|
||||
return new HardwareInfo(HardwareInfoTools.GetVendor(), HardwareInfoTools.GetModel());
|
||||
}
|
||||
|
||||
public IProgram LoadProgramBinary(byte[] programBinary, bool hasFragmentShader, ShaderInfo info)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public unsafe void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data)
|
||||
{
|
||||
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));
|
||||
mtlBuffer.DidModifyRange(new NSRange
|
||||
{
|
||||
location = (ulong)offset,
|
||||
length = (ulong)data.Length
|
||||
});
|
||||
}
|
||||
|
||||
public void UpdateCounters()
|
||||
{
|
||||
// https://developer.apple.com/documentation/metal/gpu_counters_and_counter_sample_buffers/creating_a_counter_sample_buffer_to_store_a_gpu_s_counter_data_during_a_pass?language=objc
|
||||
}
|
||||
|
||||
public void PreFrame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, float divisor, bool hostReserved)
|
||||
{
|
||||
// https://developer.apple.com/documentation/metal/gpu_counters_and_counter_sample_buffers/creating_a_counter_sample_buffer_to_store_a_gpu_s_counter_data_during_a_pass?language=objc
|
||||
var counterEvent = new CounterEvent();
|
||||
resultHandler?.Invoke(counterEvent, type == CounterType.SamplesPassed ? (ulong)1 : 0);
|
||||
return counterEvent;
|
||||
}
|
||||
|
||||
public void ResetCounter(CounterType type)
|
||||
{
|
||||
// https://developer.apple.com/documentation/metal/gpu_counters_and_counter_sample_buffers/creating_a_counter_sample_buffer_to_store_a_gpu_s_counter_data_during_a_pass?language=objc
|
||||
}
|
||||
|
||||
public void WaitSync(ulong id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetInterruptAction(Action<Action> interruptAction)
|
||||
{
|
||||
// Not needed for now
|
||||
}
|
||||
|
||||
public void Screenshot()
|
||||
{
|
||||
// TODO: Screenshots
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_window.Dispose();
|
||||
_pipeline.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
402
src/Ryujinx.Graphics.Metal/Pipeline.cs
Normal file
402
src/Ryujinx.Graphics.Metal/Pipeline.cs
Normal file
|
@ -0,0 +1,402 @@
|
|||
using Ryujinx.Graphics.GAL;
|
||||
using Ryujinx.Graphics.Shader;
|
||||
using SharpMetal.Foundation;
|
||||
using SharpMetal.Metal;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
[SupportedOSPlatform("macos")]
|
||||
public class Pipeline : IPipeline, IDisposable
|
||||
{
|
||||
private readonly MTLDevice _device;
|
||||
private readonly MTLCommandQueue _mtlCommandQueue;
|
||||
|
||||
private MTLCommandBuffer _commandBuffer;
|
||||
private MTLRenderCommandEncoder _renderCommandEncoder;
|
||||
private MTLRenderPipelineState _renderPipelineState;
|
||||
private MTLBlitCommandEncoder _blitCommandEncoder;
|
||||
|
||||
public MTLRenderCommandEncoder RenderCommandEncoder => _renderCommandEncoder;
|
||||
public MTLBlitCommandEncoder BlitCommandEncoder => _blitCommandEncoder;
|
||||
|
||||
private PrimitiveTopology _topology;
|
||||
|
||||
private MTLBuffer _indexBuffer;
|
||||
private MTLIndexType _indexType;
|
||||
private ulong _indexBufferOffset;
|
||||
|
||||
public Pipeline(MTLDevice device, MTLCommandQueue commandQueue)
|
||||
{
|
||||
_device = device;
|
||||
_mtlCommandQueue = commandQueue;
|
||||
|
||||
var renderPipelineDescriptor = new MTLRenderPipelineDescriptor();
|
||||
var error = new NSError(IntPtr.Zero);
|
||||
_renderPipelineState = _device.NewRenderPipelineState(renderPipelineDescriptor, ref error);
|
||||
if (error != IntPtr.Zero)
|
||||
{
|
||||
// throw new Exception($"Failed to create render pipeline state! {StringHelp}");
|
||||
throw new Exception($"Failed to create render pipeline state!");
|
||||
}
|
||||
|
||||
CreateCommandBuffer();
|
||||
}
|
||||
|
||||
public void Present()
|
||||
{
|
||||
_renderCommandEncoder.EndEncoding();
|
||||
_blitCommandEncoder.EndEncoding();
|
||||
// TODO: Give command buffer a valid MTLDrawable
|
||||
// _commandBuffer.PresentDrawable();
|
||||
_commandBuffer.Commit();
|
||||
|
||||
CreateCommandBuffer();
|
||||
}
|
||||
|
||||
public void CreateCommandBuffer()
|
||||
{
|
||||
_commandBuffer = _mtlCommandQueue.CommandBuffer();
|
||||
|
||||
_renderCommandEncoder = _commandBuffer.RenderCommandEncoder(new MTLRenderPassDescriptor());
|
||||
_renderCommandEncoder.SetRenderPipelineState(_renderPipelineState);
|
||||
|
||||
_blitCommandEncoder = _commandBuffer.BlitCommandEncoder(new MTLBlitPassDescriptor());
|
||||
}
|
||||
|
||||
public void Barrier()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ClearBuffer(BufferHandle destination, int offset, int size, uint value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ClearRenderTargetDepthStencil(int layer, int layerCount, float depthValue, bool depthMask, int stencilValue,
|
||||
int stencilMask)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void CommandBufferBarrier()
|
||||
{
|
||||
// TODO: Only required for MTLHeap or untracked resources
|
||||
}
|
||||
|
||||
public void CopyBuffer(BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DispatchCompute(int groupsX, int groupsY, int groupsZ)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance)
|
||||
{
|
||||
// TODO: Support topology re-indexing to provide support for TriangleFans
|
||||
var _primitiveType = _topology.Convert();
|
||||
|
||||
_renderCommandEncoder.DrawPrimitives(_primitiveType, (ulong)firstVertex, (ulong)vertexCount, (ulong)instanceCount, (ulong)firstInstance);
|
||||
}
|
||||
|
||||
public void DrawIndexed(int indexCount, int instanceCount, int firstIndex, int firstVertex, int firstInstance)
|
||||
{
|
||||
// TODO: Support topology re-indexing to provide support for TriangleFans
|
||||
var _primitiveType = _topology.Convert();
|
||||
|
||||
_renderCommandEncoder.DrawIndexedPrimitives(_primitiveType, (ulong)indexCount, _indexType, _indexBuffer, _indexBufferOffset, (ulong)instanceCount, firstVertex, (ulong)firstInstance);
|
||||
}
|
||||
|
||||
public void DrawIndexedIndirect(BufferRange indirectBuffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DrawIndexedIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DrawIndirect(BufferRange indirectBuffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DrawIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DrawTexture(ITexture texture, ISampler sampler, Extents2DF srcRegion, Extents2DF dstRegion)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetAlphaTest(bool enable, float reference, CompareOp op)
|
||||
{
|
||||
// Metal does not support alpha test.
|
||||
}
|
||||
|
||||
public void SetBlendState(AdvancedBlendDescriptor blend)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetBlendState(int index, BlendDescriptor blend)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetDepthClamp(bool clamp)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetDepthMode(DepthMode mode)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetDepthTest(DepthTestDescriptor depthTest)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetFaceCulling(bool enable, Face face)
|
||||
{
|
||||
_renderCommandEncoder.SetCullMode(enable ? face.Convert() : MTLCullMode.None);
|
||||
}
|
||||
|
||||
public void SetFrontFace(FrontFace frontFace)
|
||||
{
|
||||
_renderCommandEncoder.SetFrontFacingWinding(frontFace.Convert());
|
||||
}
|
||||
|
||||
public void SetIndexBuffer(BufferRange buffer, IndexType type)
|
||||
{
|
||||
if (buffer.Handle != BufferHandle.Null)
|
||||
{
|
||||
_indexType = type.Convert();
|
||||
_indexBufferOffset = (ulong)buffer.Offset;
|
||||
var handle = buffer.Handle;
|
||||
_indexBuffer = new(Unsafe.As<BufferHandle, IntPtr>(ref handle));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetImage(int binding, ITexture texture, Format imageFormat)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetLineParameters(float width, bool smooth)
|
||||
{
|
||||
// Not supported in Metal
|
||||
}
|
||||
|
||||
public void SetLogicOpState(bool enable, LogicalOp op)
|
||||
{
|
||||
// Not supported in Metal
|
||||
}
|
||||
|
||||
public void SetMultisampleState(MultisampleDescriptor multisample)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetPatchParameters(int vertices, ReadOnlySpan<float> defaultOuterLevel, ReadOnlySpan<float> defaultInnerLevel)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetPointParameters(float size, bool isProgramPointSize, bool enablePointSprite, Origin origin)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetPolygonMode(PolygonMode frontMode, PolygonMode backMode)
|
||||
{
|
||||
// Not supported in Metal
|
||||
}
|
||||
|
||||
public void SetPrimitiveRestart(bool enable, int index)
|
||||
{
|
||||
// TODO: Supported for LineStrip and TriangleStrip
|
||||
// https://github.com/gpuweb/gpuweb/issues/1220#issuecomment-732483263
|
||||
// https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515520-drawindexedprimitives
|
||||
// https://stackoverflow.com/questions/70813665/how-to-render-multiple-trianglestrips-using-metal
|
||||
}
|
||||
|
||||
public void SetPrimitiveTopology(PrimitiveTopology topology)
|
||||
{
|
||||
_topology = topology;
|
||||
}
|
||||
|
||||
public void SetProgram(IProgram program)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetRasterizerDiscard(bool discard)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMask)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetRenderTargets(ITexture[] colors, ITexture depthStencil)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public unsafe void SetScissors(ReadOnlySpan<Rectangle<int>> regions)
|
||||
{
|
||||
// TODO: Test max allowed scissor rects on device
|
||||
var mtlScissorRects = new MTLScissorRect[regions.Length];
|
||||
|
||||
for (int i = 0; i < regions.Length; i++)
|
||||
{
|
||||
var region = regions[i];
|
||||
mtlScissorRects[i] = new MTLScissorRect
|
||||
{
|
||||
height = (ulong)region.Height,
|
||||
width = (ulong)region.Width,
|
||||
x = (ulong)region.X,
|
||||
y = (ulong)region.Y
|
||||
};
|
||||
}
|
||||
|
||||
fixed (MTLScissorRect* pMtlScissorRects = mtlScissorRects)
|
||||
{
|
||||
// TODO: Fix this function which currently wont accept pointer as intended
|
||||
// _renderCommandEncoder.SetScissorRects(pMtlScissorRects, regions.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetStencilTest(StencilTestDescriptor stencilTest)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
public void SetStorageBuffers(ReadOnlySpan<BufferAssignment> buffers)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetTextureAndSampler(ShaderStage stage, int binding, ITexture texture, ISampler sampler)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetUniformBuffers(ReadOnlySpan<BufferAssignment> buffers)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetUserClipDistance(int index, bool enableClip)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public unsafe void SetViewports(ReadOnlySpan<Viewport> viewports)
|
||||
{
|
||||
// TODO: Test max allowed viewports on device
|
||||
var mtlViewports = new MTLViewport[viewports.Length];
|
||||
|
||||
for (int i = 0; i < viewports.Length; i++)
|
||||
{
|
||||
var viewport = viewports[i];
|
||||
mtlViewports[i] = new MTLViewport
|
||||
{
|
||||
originX = viewport.Region.X,
|
||||
originY = viewport.Region.Y,
|
||||
width = viewport.Region.Width,
|
||||
height = viewport.Region.Height,
|
||||
znear = viewport.DepthNear,
|
||||
zfar = viewport.DepthFar
|
||||
};
|
||||
}
|
||||
|
||||
fixed (MTLViewport* pMtlViewports = mtlViewports)
|
||||
{
|
||||
// TODO: Fix this function which currently wont accept pointer as intended
|
||||
// _renderCommandEncoder.SetViewports(pMtlViewports, viewports.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public void TextureBarrier()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void TextureBarrierTiled()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual)
|
||||
{
|
||||
// TODO: Implementable via indirect draw commands
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryHostConditionalRendering(ICounterEvent value, ICounterEvent compare, bool isEqual)
|
||||
{
|
||||
// TODO: Implementable via indirect draw commands
|
||||
return false;
|
||||
}
|
||||
|
||||
public void EndHostConditionalRendering()
|
||||
{
|
||||
// TODO: Implementable via indirect draw commands
|
||||
}
|
||||
|
||||
public void BeginTransformFeedback(PrimitiveTopology topology)
|
||||
{
|
||||
// Metal does not support Transform Feedback
|
||||
}
|
||||
|
||||
public void EndTransformFeedback()
|
||||
{
|
||||
// Metal does not support Transform Feedback
|
||||
}
|
||||
|
||||
public void SetTransformFeedbackBuffers(ReadOnlySpan<BufferRange> buffers)
|
||||
{
|
||||
// Metal does not support Transform Feedback
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
17
src/Ryujinx.Graphics.Metal/Ryujinx.Graphics.Metal.csproj
Normal file
17
src/Ryujinx.Graphics.Metal/Ryujinx.Graphics.Metal.csproj
Normal file
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ryujinx.Common\Ryujinx.Common.csproj" />
|
||||
<ProjectReference Include="..\Ryujinx.Graphics.GAL\Ryujinx.Graphics.GAL.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SharpMetal" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
19
src/Ryujinx.Graphics.Metal/Sampler.cs
Normal file
19
src/Ryujinx.Graphics.Metal/Sampler.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using Ryujinx.Graphics.GAL;
|
||||
using SharpMetal.Metal;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
public class Sampler : ISampler
|
||||
{
|
||||
private MTLSamplerState _mtlSamplerState;
|
||||
|
||||
public Sampler(MTLSamplerState mtlSamplerState)
|
||||
{
|
||||
_mtlSamplerState = mtlSamplerState;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
151
src/Ryujinx.Graphics.Metal/Texture.cs
Normal file
151
src/Ryujinx.Graphics.Metal/Texture.cs
Normal file
|
@ -0,0 +1,151 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Graphics.GAL;
|
||||
using SharpMetal.Metal;
|
||||
using System;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
[SupportedOSPlatform("macos")]
|
||||
class Texture : ITexture, IDisposable
|
||||
{
|
||||
private readonly TextureCreateInfo _info;
|
||||
private readonly Pipeline _pipeline;
|
||||
private readonly MTLDevice _device;
|
||||
|
||||
public MTLTexture MTLTexture;
|
||||
public TextureCreateInfo Info => Info;
|
||||
public int Width => Info.Width;
|
||||
public int Height => Info.Height;
|
||||
|
||||
public Texture(MTLDevice device, Pipeline pipeline, TextureCreateInfo info)
|
||||
{
|
||||
_device = device;
|
||||
_pipeline = pipeline;
|
||||
_info = info;
|
||||
|
||||
var descriptor = new MTLTextureDescriptor();
|
||||
descriptor.PixelFormat = FormatTable.GetFormat(Info.Format);
|
||||
// descriptor.Usage =
|
||||
descriptor.Width = (ulong)Width;
|
||||
descriptor.Height = (ulong)Height;
|
||||
descriptor.Depth = (ulong)Info.Depth;
|
||||
descriptor.SampleCount = (ulong)Info.Samples;
|
||||
descriptor.MipmapLevelCount = (ulong)Info.Levels;
|
||||
descriptor.TextureType = Info.Target.Convert();
|
||||
descriptor.Swizzle = new MTLTextureSwizzleChannels
|
||||
{
|
||||
red = Info.SwizzleR.Convert(),
|
||||
green = Info.SwizzleG.Convert(),
|
||||
blue = Info.SwizzleB.Convert(),
|
||||
alpha = Info.SwizzleA.Convert()
|
||||
};
|
||||
|
||||
MTLTexture = _device.NewTexture(descriptor);
|
||||
}
|
||||
|
||||
public void CopyTo(ITexture destination, int firstLayer, int firstLevel)
|
||||
{
|
||||
if (destination is Texture destinationTexture)
|
||||
{
|
||||
_pipeline.BlitCommandEncoder.CopyFromTexture(
|
||||
MTLTexture,
|
||||
(ulong)firstLayer,
|
||||
(ulong)firstLevel,
|
||||
destinationTexture.MTLTexture,
|
||||
(ulong)firstLayer,
|
||||
(ulong)firstLevel,
|
||||
MTLTexture.ArrayLength,
|
||||
MTLTexture.MipmapLevelCount);
|
||||
}
|
||||
}
|
||||
|
||||
public void CopyTo(ITexture destination, int srcLayer, int dstLayer, int srcLevel, int dstLevel)
|
||||
{
|
||||
if (destination is Texture destinationTexture)
|
||||
{
|
||||
_pipeline.BlitCommandEncoder.CopyFromTexture(
|
||||
MTLTexture,
|
||||
(ulong)srcLayer,
|
||||
(ulong)srcLevel,
|
||||
destinationTexture.MTLTexture,
|
||||
(ulong)dstLayer,
|
||||
(ulong)dstLevel,
|
||||
MTLTexture.ArrayLength,
|
||||
MTLTexture.MipmapLevelCount);
|
||||
}
|
||||
}
|
||||
|
||||
public void CopyTo(ITexture destination, Extents2D srcRegion, Extents2D dstRegion, bool linearFilter)
|
||||
{
|
||||
var samplerDescriptor = new MTLSamplerDescriptor();
|
||||
samplerDescriptor.MinFilter = linearFilter ? MTLSamplerMinMagFilter.Linear : MTLSamplerMinMagFilter.Nearest;
|
||||
samplerDescriptor.MagFilter = linearFilter ? MTLSamplerMinMagFilter.Linear : MTLSamplerMinMagFilter.Nearest;
|
||||
var samplerState = _device.NewSamplerState(samplerDescriptor);
|
||||
}
|
||||
|
||||
public void CopyTo(BufferRange range, int layer, int level, int stride)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ITexture CreateView(TextureCreateInfo info, int firstLayer, int firstLevel)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public PinnedSpan<byte> GetData()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public PinnedSpan<byte> GetData(int layer, int level)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetData(SpanOrArray<byte> data)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetData(SpanOrArray<byte> data, int layer, int level)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public unsafe void SetData(SpanOrArray<byte> data, int layer, int level, Rectangle<int> region)
|
||||
{
|
||||
// TODO: Figure out bytesPerRow
|
||||
// For an ordinary or packed pixel format, the stride, in bytes, between rows of source data.
|
||||
// For a compressed pixel format, the stride is the number of bytes from the beginning of one row of blocks to the beginning of the next.
|
||||
if (MTLTexture.IsSparse)
|
||||
ulong bytesPerRow = 0;
|
||||
var mtlRegion = new MTLRegion
|
||||
{
|
||||
origin = new MTLOrigin { x = (ulong)region.X, y = (ulong)region.Y },
|
||||
size = new MTLSize { width = (ulong)region.Width, height = (ulong)region.Height },
|
||||
};
|
||||
|
||||
fixed (byte* pData = data.Span)
|
||||
{
|
||||
MTLTexture.ReplaceRegion(mtlRegion, (ulong)level, (ulong)layer, new IntPtr(pData), bytesPerRow, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetStorage(BufferRange buffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
55
src/Ryujinx.Graphics.Metal/Window.cs
Normal file
55
src/Ryujinx.Graphics.Metal/Window.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using Ryujinx.Graphics.GAL;
|
||||
using System;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
[SupportedOSPlatform("macos")]
|
||||
public class Window : IWindow, IDisposable
|
||||
{
|
||||
private readonly MetalRenderer _renderer;
|
||||
|
||||
public Window(MetalRenderer renderer)
|
||||
{
|
||||
_renderer = renderer;
|
||||
}
|
||||
|
||||
public void Present(ITexture texture, ImageCrop crop, Action swapBuffersCallback)
|
||||
{
|
||||
if (_renderer.Pipeline is Pipeline pipeline)
|
||||
{
|
||||
pipeline.Present();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSize(int width, int height)
|
||||
{
|
||||
// Not needed as we can get the size from the surface.
|
||||
}
|
||||
|
||||
public void ChangeVSyncMode(bool vsyncEnabled)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetAntiAliasing(AntiAliasing antialiasing)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetScalingFilter(ScalingFilter type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetScalingFilterLevel(float level)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
88
src/Ryujinx.Graphics.Shader/CodeGen/Msl/CodeGenContext.cs
Normal file
88
src/Ryujinx.Graphics.Shader/CodeGen/Msl/CodeGenContext.cs
Normal file
|
@ -0,0 +1,88 @@
|
|||
using Ryujinx.Graphics.Shader.StructuredIr;
|
||||
using Ryujinx.Graphics.Shader.Translation;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
{
|
||||
class CodeGenContext
|
||||
{
|
||||
public const string Tab = " ";
|
||||
|
||||
public StructuredProgramInfo Info { get; }
|
||||
public ShaderConfig Config { get; }
|
||||
|
||||
private readonly StringBuilder _sb;
|
||||
|
||||
private int _level;
|
||||
|
||||
private string _indentation;
|
||||
|
||||
public CodeGenContext(StructuredProgramInfo info, ShaderConfig config)
|
||||
{
|
||||
Info = info;
|
||||
Config = Config;
|
||||
|
||||
_sb = new StringBuilder();
|
||||
}
|
||||
|
||||
public void AppendLine()
|
||||
{
|
||||
_sb.AppendLine();
|
||||
}
|
||||
|
||||
public void AppendLine(string str)
|
||||
{
|
||||
_sb.AppendLine(_indentation + str);
|
||||
}
|
||||
|
||||
public string GetCode()
|
||||
{
|
||||
return _sb.ToString();
|
||||
}
|
||||
|
||||
public void EnterScope()
|
||||
{
|
||||
AppendLine("{");
|
||||
|
||||
_level++;
|
||||
|
||||
UpdateIndentation();
|
||||
}
|
||||
|
||||
public void LeaveScope(string suffix = "")
|
||||
{
|
||||
if (_level == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_level--;
|
||||
|
||||
UpdateIndentation();
|
||||
|
||||
AppendLine("}" + suffix);
|
||||
}
|
||||
|
||||
public StructuredFunction GetFunction(int id)
|
||||
{
|
||||
return Info.Functions[id];
|
||||
}
|
||||
|
||||
private void UpdateIndentation()
|
||||
{
|
||||
_indentation = GetIndentation(_level);
|
||||
}
|
||||
|
||||
private static string GetIndentation(int level)
|
||||
{
|
||||
string indentation = string.Empty;
|
||||
|
||||
for (int index = 0; index < level; index++)
|
||||
{
|
||||
indentation += Tab;
|
||||
}
|
||||
|
||||
return indentation;
|
||||
}
|
||||
}
|
||||
}
|
16
src/Ryujinx.Graphics.Shader/CodeGen/Msl/Declarations.cs
Normal file
16
src/Ryujinx.Graphics.Shader/CodeGen/Msl/Declarations.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using Ryujinx.Graphics.Shader.CodeGen.Glsl;
|
||||
using Ryujinx.Graphics.Shader.StructuredIr;
|
||||
|
||||
namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
{
|
||||
static class Declarations
|
||||
{
|
||||
public static void Declare(CodeGenContext context, StructuredProgramInfo info)
|
||||
{
|
||||
context.AppendLine("#include <metal_stdlib>");
|
||||
context.AppendLine("#include <simd/simd.h>");
|
||||
context.AppendLine();
|
||||
context.AppendLine("using namespace metal;");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
||||
using Ryujinx.Graphics.Shader.Translation;
|
||||
|
||||
namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||
{
|
||||
static class IoMap
|
||||
{
|
||||
public static (string, AggregateType) GetMSLBuiltIn(IoVariable ioVariable)
|
||||
{
|
||||
return ioVariable switch
|
||||
{
|
||||
IoVariable.BaseInstance => ("base_instance", AggregateType.S32),
|
||||
IoVariable.BaseVertex => ("base_vertex", AggregateType.S32),
|
||||
IoVariable.ClipDistance => ("clip_distance", AggregateType.Array | AggregateType.FP32),
|
||||
IoVariable.FragmentOutputColor => ("color", AggregateType.Vector2 | AggregateType.Vector3 | AggregateType.Vector4),
|
||||
IoVariable.FragmentOutputDepth => ("depth", AggregateType.FP32),
|
||||
IoVariable.FrontFacing => ("front_facing", AggregateType.Bool),
|
||||
IoVariable.InstanceId => ("instance_id", AggregateType.S32),
|
||||
IoVariable.PointCoord => ("point_coord", AggregateType.Vector2),
|
||||
IoVariable.PointSize => ("point_size", AggregateType.FP32),
|
||||
IoVariable.Position => ("position", AggregateType.Vector4),
|
||||
IoVariable.PrimitiveId => ("primitive_id", AggregateType.S32),
|
||||
IoVariable.VertexId => ("vertex_id", AggregateType.S32),
|
||||
IoVariable.ViewportIndex => ("viewport_array_index", AggregateType.S32),
|
||||
_ => (null, AggregateType.Invalid),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
17
src/Ryujinx.Graphics.Shader/CodeGen/Msl/MslGenerator.cs
Normal file
17
src/Ryujinx.Graphics.Shader/CodeGen/Msl/MslGenerator.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using Ryujinx.Graphics.Shader.StructuredIr;
|
||||
using Ryujinx.Graphics.Shader.Translation;
|
||||
|
||||
namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||
{
|
||||
static class MslGenerator
|
||||
{
|
||||
public static string Generate(StructuredProgramInfo info, ShaderConfig config)
|
||||
{
|
||||
CodeGenContext context = new CodeGenContext(info, config);
|
||||
|
||||
Declarations.Declare(context, info);
|
||||
|
||||
return context.GetCode();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,5 +4,6 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
{
|
||||
OpenGL,
|
||||
Vulkan,
|
||||
Metal
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,6 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
{
|
||||
Glsl,
|
||||
Spirv,
|
||||
Arb,
|
||||
Msl
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ using Ryujinx.Graphics.GAL.Multithreading;
|
|||
using Ryujinx.Graphics.Gpu;
|
||||
using Ryujinx.Graphics.OpenGL;
|
||||
using Ryujinx.Graphics.Vulkan;
|
||||
using Ryujinx.Graphics.Metal;
|
||||
using Ryujinx.HLE;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using Ryujinx.HLE.HOS;
|
||||
|
@ -1137,6 +1138,7 @@ namespace Ryujinx.Ava
|
|||
StatusUpdatedEvent?.Invoke(this, new StatusUpdatedEventArgs(
|
||||
vSyncMode,
|
||||
LocaleManager.Instance[LocaleKeys.VolumeShort] + $": {(int)(Device.GetVolume() * 100)}%",
|
||||
ConfigurationState.Instance.Graphics.GraphicsBackend.Value.ToText(),
|
||||
dockedMode,
|
||||
ConfigurationState.Instance.Graphics.AspectRatio.Value.ToText(),
|
||||
$"{Device.Statistics.GetGameFrameRate():00.00} FPS ({Device.Statistics.GetGameFrameTime():00.00} ms)",
|
||||
|
|
1225
src/Ryujinx/AppHost.cs.orig
Normal file
1225
src/Ryujinx/AppHost.cs.orig
Normal file
File diff suppressed because it is too large
Load diff
|
@ -198,6 +198,7 @@ namespace Ryujinx.Ava
|
|||
{
|
||||
"opengl" => GraphicsBackend.OpenGl,
|
||||
"vulkan" => GraphicsBackend.Vulkan,
|
||||
"metal" => GraphicsBackend.Metal,
|
||||
_ => ConfigurationState.Instance.Graphics.GraphicsBackend
|
||||
};
|
||||
|
||||
|
|
25
src/Ryujinx/UI/Renderer/EmbeddedWindowMetal.cs
Normal file
25
src/Ryujinx/UI/Renderer/EmbeddedWindowMetal.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using SPB.Windowing;
|
||||
using SPB.Platform.Metal;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.UI.Renderer
|
||||
{
|
||||
public class EmbeddedWindowMetal : EmbeddedWindow
|
||||
{
|
||||
public SimpleMetalWindow CreateSurface()
|
||||
{
|
||||
SimpleMetalWindow simpleMetalWindow;
|
||||
|
||||
if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
simpleMetalWindow = new SimpleMetalWindow(new NativeHandle(NsView), new NativeHandle(MetalLayer));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PlatformNotSupportedException();
|
||||
}
|
||||
|
||||
return simpleMetalWindow;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -120,6 +120,8 @@ namespace Ryujinx.Ava.UI.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsMetalAvailable => OperatingSystem.IsMacOS();
|
||||
|
||||
public bool IsOpenGLAvailable => !OperatingSystem.IsMacOS();
|
||||
|
||||
public bool IsHypervisorAvailable => OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64;
|
||||
|
|
|
@ -43,6 +43,9 @@
|
|||
<ComboBoxItem IsEnabled="{Binding IsOpenGLAvailable}">
|
||||
<TextBlock Text="OpenGL" />
|
||||
</ComboBoxItem>
|
||||
<ComboBoxItem IsVisible="{Binding IsMetalAvailable}">
|
||||
<TextBlock Text="Metal" />
|
||||
</ComboBoxItem>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" IsVisible="{Binding IsVulkanSelected}">
|
||||
|
|
Loading…
Reference in a new issue