2023-08-03 12:48:41 +00:00
|
|
|
using Ryujinx.Common;
|
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
using SharpMetal.Foundation;
|
|
|
|
using SharpMetal.Metal;
|
|
|
|
using System;
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Metal
|
|
|
|
{
|
|
|
|
[SupportedOSPlatform("macos")]
|
|
|
|
public class HelperShaders
|
|
|
|
{
|
|
|
|
private const string ShadersSourcePath = "/Ryujinx.Graphics.Metal/HelperShadersSource.metal";
|
|
|
|
|
|
|
|
public HelperShader BlitShader;
|
|
|
|
|
|
|
|
public HelperShaders(MTLDevice device)
|
|
|
|
{
|
|
|
|
var error = new NSError(IntPtr.Zero);
|
|
|
|
|
|
|
|
var shaderSource = EmbeddedResources.ReadAllText(ShadersSourcePath);
|
|
|
|
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)}");
|
|
|
|
}
|
|
|
|
|
|
|
|
BlitShader = new HelperShader(device, library, "vertexBlit", "fragmentBlit");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[SupportedOSPlatform("macos")]
|
2023-08-03 18:50:49 +00:00
|
|
|
public readonly struct HelperShader
|
2023-08-03 12:48:41 +00:00
|
|
|
{
|
2023-10-10 19:26:40 +00:00
|
|
|
public readonly MTLFunction VertexFunction;
|
|
|
|
public readonly MTLFunction FragmentFunction;
|
2023-08-03 12:48:41 +00:00
|
|
|
|
|
|
|
public HelperShader(MTLDevice device, MTLLibrary library, string vertex, string fragment)
|
|
|
|
{
|
2023-10-10 19:26:40 +00:00
|
|
|
VertexFunction = library.NewFunction(StringHelper.NSString(vertex));
|
|
|
|
FragmentFunction = library.NewFunction(StringHelper.NSString(fragment));
|
2023-08-03 12:48:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|