Look ma no crash

This commit is contained in:
Isaac Marovitz 2023-08-01 22:36:07 -04:00 committed by Isaac Marovitz
parent 425177a876
commit 6c3435aaac
7 changed files with 212 additions and 149 deletions

View file

@ -1,6 +1,6 @@
using Ryujinx.Graphics.GAL;
using SharpMetal.Metal;
using System;
using SharpMetal;
namespace Ryujinx.Graphics.Metal
{
@ -12,30 +12,30 @@ namespace Ryujinx.Graphics.Metal
{
_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.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);
@ -48,53 +48,54 @@ namespace Ryujinx.Graphics.Metal
// 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.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);
// Approximate
Add(Format.S8UintD24Unorm, MTLPixelFormat.BGRA8Unorm);
Add(Format.D32Float, MTLPixelFormat.Depth32Float);
Add(Format.D24UnormS8Uint, MTLPixelFormat.Depth24UnormStencil8);
Add(Format.D32FloatS8Uint, MTLPixelFormat.Depth32FloatStencil8);
Add(Format.R8G8B8A8Srgb, MTLPixelFormat.RGBA8UnormsRGB);
// 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.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.BC1RGBA);
Add(Format.Bc2Unorm, MTLPixelFormat.BC2RGBA);
Add(Format.Bc3Unorm, MTLPixelFormat.BC3RGBA);
Add(Format.Bc1RgbaSrgb, MTLPixelFormat.BC1RGBAsRGB);
Add(Format.Bc2Srgb, MTLPixelFormat.BC2RGBAsRGB);
Add(Format.Bc3Srgb, MTLPixelFormat.BC3RGBAsRGB);
Add(Format.Bc4Unorm, MTLPixelFormat.BC4RUnorm);
Add(Format.Bc4Snorm, MTLPixelFormat.BC4RSnorm);
Add(Format.Bc5Unorm, MTLPixelFormat.BC5RGUnorm);
Add(Format.Bc5Snorm, MTLPixelFormat.BC5RGSnorm);
Add(Format.Bc7Unorm, MTLPixelFormat.BC7RGBAUnorm);
Add(Format.Bc7Srgb, MTLPixelFormat.BC7RGBAUnormsRGB);
Add(Format.Bc6HSfloat, MTLPixelFormat.BC6HRGBFloat);
Add(Format.Bc6HUfloat, MTLPixelFormat.BC6HRGBUfloat);
Add(Format.Etc2RgbUnorm, MTLPixelFormat.ETC2RGB8);
Add(Format.Etc2RgbaUnorm, MTLPixelFormat.ETC2RGB8A1);
// Add(Format.Etc2RgbPtaUnorm, MTLPixelFormat.Etc2RgbPtaUnorm);
Add(Format.Etc2RgbSrgb, MTLPixelFormat.ETC2_RGB8_sRGB);
Add(Format.Etc2RgbaSrgb, MTLPixelFormat.ETC2_RGB8A1_sRGB);
Add(Format.Etc2RgbSrgb, MTLPixelFormat.ETC2RGB8sRGB);
Add(Format.Etc2RgbaSrgb, MTLPixelFormat.ETC2RGB8A1sRGB);
// Add(Format.Etc2RgbPtaSrgb, MTLPixelFormat.Etc2RgbPtaSrgb);
// Add(Format.R8Uscaled, MTLPixelFormat.R8Uscaled);
// Add(Format.R8Sscaled, MTLPixelFormat.R8Sscaled);
@ -124,39 +125,39 @@ namespace Ryujinx.Graphics.Metal
// 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);
Add(Format.Astc4x4Unorm, MTLPixelFormat.ASTC4x4HDR);
Add(Format.Astc5x4Unorm, MTLPixelFormat.ASTC5x4LDR);
Add(Format.Astc5x5Unorm, MTLPixelFormat.ASTC5x5LDR);
Add(Format.Astc6x5Unorm, MTLPixelFormat.ASTC6x5LDR);
Add(Format.Astc6x6Unorm, MTLPixelFormat.ASTC6x6LDR);
Add(Format.Astc8x5Unorm, MTLPixelFormat.ASTC8x5LDR);
Add(Format.Astc8x6Unorm, MTLPixelFormat.ASTC8x6LDR);
Add(Format.Astc8x8Unorm, MTLPixelFormat.ASTC8x8LDR);
Add(Format.Astc10x5Unorm, MTLPixelFormat.ASTC10x5LDR);
Add(Format.Astc10x6Unorm, MTLPixelFormat.ASTC10x6LDR);
Add(Format.Astc10x8Unorm, MTLPixelFormat.ASTC10x8LDR);
Add(Format.Astc10x10Unorm, MTLPixelFormat.ASTC10x10LDR);
Add(Format.Astc12x10Unorm, MTLPixelFormat.ASTC12x10LDR);
Add(Format.Astc12x12Unorm, MTLPixelFormat.ASTC12x12LDR);
Add(Format.Astc4x4Srgb, MTLPixelFormat.ASTC4x4sRGB);
Add(Format.Astc5x4Srgb, MTLPixelFormat.ASTC5x4sRGB);
Add(Format.Astc5x5Srgb, MTLPixelFormat.ASTC5x5sRGB);
Add(Format.Astc6x5Srgb, MTLPixelFormat.ASTC6x5sRGB);
Add(Format.Astc6x6Srgb, MTLPixelFormat.ASTC6x6sRGB);
Add(Format.Astc8x5Srgb, MTLPixelFormat.ASTC8x5sRGB);
Add(Format.Astc8x6Srgb, MTLPixelFormat.ASTC8x6sRGB);
Add(Format.Astc8x8Srgb, MTLPixelFormat.ASTC8x8sRGB);
Add(Format.Astc10x5Srgb, MTLPixelFormat.ASTC10x5sRGB);
Add(Format.Astc10x6Srgb, MTLPixelFormat.ASTC10x6sRGB);
Add(Format.Astc10x8Srgb, MTLPixelFormat.ASTC10x8sRGB);
Add(Format.Astc10x10Srgb, MTLPixelFormat.ASTC10x10sRGB);
Add(Format.Astc12x10Srgb, MTLPixelFormat.ASTC12x10sRGB);
Add(Format.Astc12x12Srgb, MTLPixelFormat.ASTC12x12sRGB);
Add(Format.B5G6R5Unorm, MTLPixelFormat.B5G6R5Unorm);
Add(Format.B5G5R5A1Unorm, MTLPixelFormat.BGR5A1Unorm);
Add(Format.A1B5G5R5Unorm, MTLPixelFormat.A1BGR5Unorm);
Add(Format.B8G8R8A8Unorm, MTLPixelFormat.BGRA8Unorm);
Add(Format.B8G8R8A8Srgb, MTLPixelFormat.BGRA8UnormsRGB);
}
private static void Add(Format format, MTLPixelFormat mtlFormat)
@ -169,4 +170,4 @@ namespace Ryujinx.Graphics.Metal
return _table[(int)format];
}
}
}
}

View file

@ -1,4 +1,5 @@
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Shader.Translation;
using SharpMetal.Foundation;
@ -106,7 +107,7 @@ namespace Ryujinx.Graphics.Metal
public void CreateSync(ulong id, bool strict)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void DeleteBuffer(BufferHandle buffer)
@ -175,7 +176,8 @@ namespace Ryujinx.Graphics.Metal
public ulong GetCurrentSync()
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
return 0;
}
public HardwareInfo GetHardwareInfo()

View file

@ -1,3 +1,4 @@
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Shader;
@ -12,6 +13,8 @@ namespace Ryujinx.Graphics.Metal
[SupportedOSPlatform("macos")]
public class Pipeline : IPipeline, IDisposable
{
private const string ShaderSourcePath = "Ryujinx.Graphics.Metal/Shaders";
private readonly MTLDevice _device;
private readonly MTLCommandQueue _mtlCommandQueue;
@ -31,9 +34,23 @@ namespace Ryujinx.Graphics.Metal
_device = device;
_mtlCommandQueue = commandQueue;
var error = new NSError(IntPtr.Zero);
var shaderSource = EmbeddedResources.ReadAllText(string.Join('/', ShaderSourcePath, "ColorBlitShaderSource.metal"));
var library = _device.NewLibrary(StringHelper.NSString(shaderSource), new(IntPtr.Zero), ref error);
if (error != IntPtr.Zero)
{
Logger.Error?.PrintMsg(LogClass.Gpu, $"Failed to create Library: {StringHelper.String(error.LocalizedDescription)}");
}
var vertexFunction = library.NewFunction(StringHelper.NSString("vertexMain"));
var fragmentFunction = library.NewFunction(StringHelper.NSString("fragmentMain"));
// TODO: Recreate descriptor and encoder state as needed
var renderPipelineDescriptor = new MTLRenderPipelineDescriptor();
var error = new NSError(IntPtr.Zero);
renderPipelineDescriptor.VertexFunction = vertexFunction;
renderPipelineDescriptor.FragmentFunction = fragmentFunction;
_renderEncoderState = new(_device.NewRenderPipelineState(renderPipelineDescriptor, ref error), _device);
if (error != IntPtr.Zero)
{
@ -57,7 +74,7 @@ namespace Ryujinx.Graphics.Metal
{
EndCurrentPass();
var descriptor = new MTLRenderPassDescriptor { };
var descriptor = new MTLRenderPassDescriptor();
var renderCommandEncoder = _commandBuffer.RenderCommandEncoder(descriptor);
_renderEncoderState.SetEncoderState(renderCommandEncoder);
@ -69,7 +86,7 @@ namespace Ryujinx.Graphics.Metal
{
EndCurrentPass();
var descriptor = new MTLBlitPassDescriptor { };
var descriptor = new MTLBlitPassDescriptor();
var blitCommandEncoder = _commandBuffer.BlitCommandEncoder(descriptor);
_currentEncoder = blitCommandEncoder;
@ -80,7 +97,7 @@ namespace Ryujinx.Graphics.Metal
{
EndCurrentPass();
var descriptor = new MTLComputePassDescriptor { };
var descriptor = new MTLComputePassDescriptor();
var computeCommandEncoder = _commandBuffer.ComputeCommandEncoder(descriptor);
_currentEncoder = computeCommandEncoder;
@ -93,14 +110,14 @@ namespace Ryujinx.Graphics.Metal
// TODO: Give command buffer a valid MTLDrawable
// _commandBuffer.PresentDrawable();
_commandBuffer.Commit();
// _commandBuffer.Commit();
_commandBuffer = _mtlCommandQueue.CommandBuffer();
}
public void Barrier()
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void ClearBuffer(BufferHandle destination, int offset, int size, uint value)
@ -130,18 +147,18 @@ namespace Ryujinx.Graphics.Metal
public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void ClearRenderTargetDepthStencil(int layer, int layerCount, float depthValue, bool depthMask, int stencilValue,
int stencilMask)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void CommandBufferBarrier()
{
// TODO: Only required for MTLHeap or untracked resources
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void CopyBuffer(BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size)
@ -170,7 +187,7 @@ namespace Ryujinx.Graphics.Metal
public void DispatchCompute(int groupsX, int groupsY, int groupsZ)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void Draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance)
@ -213,57 +230,57 @@ namespace Ryujinx.Graphics.Metal
public void DrawIndexedIndirect(BufferRange indirectBuffer)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void DrawIndexedIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void DrawIndirect(BufferRange indirectBuffer)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void DrawIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void DrawTexture(ITexture texture, ISampler sampler, Extents2DF srcRegion, Extents2DF dstRegion)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetAlphaTest(bool enable, float reference, CompareOp op)
{
// Metal does not support alpha test.
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetBlendState(AdvancedBlendDescriptor blend)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetBlendState(int index, BlendDescriptor blend)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetDepthClamp(bool clamp)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetDepthMode(DepthMode mode)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetDepthTest(DepthTestDescriptor depthTest)
@ -315,37 +332,40 @@ namespace Ryujinx.Graphics.Metal
public void SetImage(int binding, ITexture texture, Format imageFormat)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetLineParameters(float width, bool smooth)
{
// Not supported in Metal
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetLogicOpState(bool enable, LogicalOp op)
{
// Not supported in Metal
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetMultisampleState(MultisampleDescriptor multisample)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetPatchParameters(int vertices, ReadOnlySpan<float> defaultOuterLevel, ReadOnlySpan<float> defaultInnerLevel)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetPointParameters(float size, bool isProgramPointSize, bool enablePointSprite, Origin origin)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetPolygonMode(PolygonMode frontMode, PolygonMode backMode)
{
// Not supported in Metal
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetPrimitiveRestart(bool enable, int index)
@ -354,6 +374,7 @@ namespace Ryujinx.Graphics.Metal
// 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
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetPrimitiveTopology(PrimitiveTopology topology)
@ -363,22 +384,22 @@ namespace Ryujinx.Graphics.Metal
public void SetProgram(IProgram program)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetRasterizerDiscard(bool discard)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMask)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetRenderTargets(ITexture[] colors, ITexture depthStencil)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public unsafe void SetScissors(ReadOnlySpan<Rectangle<int>> regions)
@ -437,32 +458,32 @@ namespace Ryujinx.Graphics.Metal
public void SetStorageBuffers(ReadOnlySpan<BufferAssignment> buffers)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetTextureAndSampler(ShaderStage stage, int binding, ITexture texture, ISampler sampler)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetUniformBuffers(ReadOnlySpan<BufferAssignment> buffers)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetUserClipDistance(int index, bool enableClip)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public unsafe void SetViewports(ReadOnlySpan<Viewport> viewports)
@ -493,12 +514,12 @@ namespace Ryujinx.Graphics.Metal
public void TextureBarrier()
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void TextureBarrierTiled()
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual)
@ -521,16 +542,19 @@ namespace Ryujinx.Graphics.Metal
public void BeginTransformFeedback(PrimitiveTopology topology)
{
// Metal does not support Transform Feedback
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void EndTransformFeedback()
{
// Metal does not support Transform Feedback
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetTransformFeedbackBuffers(ReadOnlySpan<BufferRange> buffers)
{
// Metal does not support Transform Feedback
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void Dispose()

View file

@ -9,6 +9,10 @@
<ProjectReference Include="..\Ryujinx.Common\Ryujinx.Common.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.GAL\Ryujinx.Graphics.GAL.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Shaders\ColorBlitShaderSource.metal" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpMetal" />

View file

@ -0,0 +1,30 @@
#include <metal_stdlib>
using namespace metal;
struct TexCoordIn {
float4 tex_coord_in_data;
};
vertex float4 vertexMain(uint vertexID [[vertex_id]],
constant TexCoordIn& tex_coord_in [[buffer(1)]]) {
int low = vertexID & 1;
int high = vertexID >> 1;
float2 tex_coord;
tex_coord.x = tex_coord_in.tex_coord_in_data[low];
tex_coord.y = tex_coord_in.tex_coord_in_data[2 + high];
float4 position;
position.x = (float(low) - 0.5) * 2.0;
position.y = (float(high) - 0.5) * 2.0;
position.z = 0.0;
position.w = 1.0;
return position;
}
fragment float4 fragmentMain(float2 tex_coord [[stage_in]],
texture2d<float> tex [[texture(0)]]) {
float4 color = tex.sample(metal::address::clamp_to_edge, tex_coord);
return color;
}

View file

@ -1,3 +1,4 @@
using Ryujinx.Common.Logging;
using Ryujinx.Common.Memory;
using Ryujinx.Graphics.GAL;
using SharpMetal.Metal;
@ -158,7 +159,7 @@ namespace Ryujinx.Graphics.Metal
public void SetData(SpanOrArray<byte> data)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetData(SpanOrArray<byte> data, int layer, int level)
@ -245,17 +246,17 @@ namespace Ryujinx.Graphics.Metal
public void SetStorage(BufferRange buffer)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void Release()
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void Dispose()
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
}
}

View file

@ -1,3 +1,4 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using System;
using System.Runtime.Versioning;
@ -24,27 +25,27 @@ namespace Ryujinx.Graphics.Metal
public void SetSize(int width, int height)
{
// Not needed as we can get the size from the surface.
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void ChangeVSyncMode(bool vsyncEnabled)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetAntiAliasing(AntiAliasing antialiasing)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetScalingFilter(ScalingFilter type)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void SetScalingFilterLevel(float level)
{
throw new NotImplementedException();
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
}
public void Dispose()