mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-12-28 03:23:05 +00:00
FIx build
This commit is contained in:
parent
62bf395970
commit
3d897c4f9a
4 changed files with 73 additions and 44 deletions
|
@ -10,6 +10,13 @@ using System.Runtime.Versioning;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
|
enum EncoderType
|
||||||
|
{
|
||||||
|
Blit,
|
||||||
|
Compute,
|
||||||
|
Render
|
||||||
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
class Pipeline : IPipeline, IDisposable
|
class Pipeline : IPipeline, IDisposable
|
||||||
{
|
{
|
||||||
|
@ -24,6 +31,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
private MTLCommandBuffer _commandBuffer;
|
private MTLCommandBuffer _commandBuffer;
|
||||||
private MTLCommandEncoder? _currentEncoder;
|
private MTLCommandEncoder? _currentEncoder;
|
||||||
|
private EncoderType _currentEncoderType;
|
||||||
private MTLTexture[] _renderTargets = [];
|
private MTLTexture[] _renderTargets = [];
|
||||||
|
|
||||||
private RenderEncoderState _renderEncoderState;
|
private RenderEncoderState _renderEncoderState;
|
||||||
|
@ -77,9 +85,12 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public MTLRenderCommandEncoder GetOrCreateRenderEncoder()
|
public MTLRenderCommandEncoder GetOrCreateRenderEncoder()
|
||||||
{
|
{
|
||||||
if (_currentEncoder is MTLRenderCommandEncoder encoder)
|
if (_currentEncoder != null)
|
||||||
{
|
{
|
||||||
return encoder;
|
if (_currentEncoderType == EncoderType.Render)
|
||||||
|
{
|
||||||
|
return new MTLRenderCommandEncoder(_currentEncoder.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return BeginRenderPass();
|
return BeginRenderPass();
|
||||||
|
@ -87,9 +98,12 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public MTLBlitCommandEncoder GetOrCreateBlitEncoder()
|
public MTLBlitCommandEncoder GetOrCreateBlitEncoder()
|
||||||
{
|
{
|
||||||
if (_currentEncoder is MTLBlitCommandEncoder encoder)
|
if (_currentEncoder != null)
|
||||||
{
|
{
|
||||||
return encoder;
|
if (_currentEncoderType == EncoderType.Blit)
|
||||||
|
{
|
||||||
|
return new MTLBlitCommandEncoder(_currentEncoder.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return BeginBlitPass();
|
return BeginBlitPass();
|
||||||
|
@ -97,9 +111,12 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public MTLComputeCommandEncoder GetOrCreateComputeEncoder()
|
public MTLComputeCommandEncoder GetOrCreateComputeEncoder()
|
||||||
{
|
{
|
||||||
if (_currentEncoder is MTLComputeCommandEncoder encoder)
|
if (_currentEncoder != null)
|
||||||
{
|
{
|
||||||
return encoder;
|
if (_currentEncoderType == EncoderType.Compute)
|
||||||
|
{
|
||||||
|
return new MTLComputeCommandEncoder(_currentEncoder.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return BeginComputePass();
|
return BeginComputePass();
|
||||||
|
@ -109,8 +126,23 @@ namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
if (_currentEncoder != null)
|
if (_currentEncoder != null)
|
||||||
{
|
{
|
||||||
_currentEncoder.EndEncoding();
|
switch (_currentEncoderType)
|
||||||
_currentEncoder = null;
|
{
|
||||||
|
case EncoderType.Blit:
|
||||||
|
new MTLBlitCommandEncoder(_currentEncoder.Value).EndEncoding();
|
||||||
|
_currentEncoder = null;
|
||||||
|
break;
|
||||||
|
case EncoderType.Compute:
|
||||||
|
new MTLComputeCommandEncoder(_currentEncoder.Value).EndEncoding();
|
||||||
|
_currentEncoder = null;
|
||||||
|
break;
|
||||||
|
case EncoderType.Render:
|
||||||
|
new MTLRenderCommandEncoder(_currentEncoder.Value).EndEncoding();
|
||||||
|
_currentEncoder = null;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +172,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentEncoder = renderCommandEncoder;
|
_currentEncoder = renderCommandEncoder;
|
||||||
|
_currentEncoderType = EncoderType.Render;
|
||||||
return renderCommandEncoder;
|
return renderCommandEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +184,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
var blitCommandEncoder = _commandBuffer.BlitCommandEncoder(descriptor);
|
var blitCommandEncoder = _commandBuffer.BlitCommandEncoder(descriptor);
|
||||||
|
|
||||||
_currentEncoder = blitCommandEncoder;
|
_currentEncoder = blitCommandEncoder;
|
||||||
|
_currentEncoderType = EncoderType.Blit;
|
||||||
return blitCommandEncoder;
|
return blitCommandEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +196,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
var computeCommandEncoder = _commandBuffer.ComputeCommandEncoder(descriptor);
|
var computeCommandEncoder = _commandBuffer.ComputeCommandEncoder(descriptor);
|
||||||
|
|
||||||
_currentEncoder = computeCommandEncoder;
|
_currentEncoder = computeCommandEncoder;
|
||||||
|
_currentEncoderType = EncoderType.Compute;
|
||||||
return computeCommandEncoder;
|
return computeCommandEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,9 +210,13 @@ namespace Ryujinx.Graphics.Metal
|
||||||
EndCurrentPass();
|
EndCurrentPass();
|
||||||
|
|
||||||
var descriptor = new MTLRenderPassDescriptor();
|
var descriptor = new MTLRenderPassDescriptor();
|
||||||
descriptor.ColorAttachments.Object(0).Texture = drawable.Texture;
|
var colorAttachment = descriptor.ColorAttachments.Object(0);
|
||||||
descriptor.ColorAttachments.Object(0).LoadAction = MTLLoadAction.Clear;
|
|
||||||
descriptor.ColorAttachments.Object(0).ClearColor = _clearColor;
|
colorAttachment.Texture = drawable.Texture;
|
||||||
|
colorAttachment.LoadAction = MTLLoadAction.Clear;
|
||||||
|
colorAttachment.ClearColor = _clearColor;
|
||||||
|
|
||||||
|
descriptor.ColorAttachments.SetObject(colorAttachment, 0);
|
||||||
|
|
||||||
var renderCommandEncoder = _commandBuffer.RenderCommandEncoder(descriptor);
|
var renderCommandEncoder = _commandBuffer.RenderCommandEncoder(descriptor);
|
||||||
_renderEncoderState.SetEncoderState(renderCommandEncoder, _vertexDescriptor);
|
_renderEncoderState.SetEncoderState(renderCommandEncoder, _vertexDescriptor);
|
||||||
|
@ -352,9 +391,9 @@ namespace Ryujinx.Graphics.Metal
|
||||||
depthTest.TestEnable ? depthTest.Func.Convert() : MTLCompareFunction.Always,
|
depthTest.TestEnable ? depthTest.Func.Convert() : MTLCompareFunction.Always,
|
||||||
depthTest.WriteEnable);
|
depthTest.WriteEnable);
|
||||||
|
|
||||||
if (_currentEncoder is MTLRenderCommandEncoder renderCommandEncoder)
|
if (_currentEncoderType == EncoderType.Render)
|
||||||
{
|
{
|
||||||
renderCommandEncoder.SetDepthStencilState(depthStencilState);
|
new MTLRenderCommandEncoder(_currentEncoder.Value).SetDepthStencilState(depthStencilState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,9 +401,9 @@ namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
var cullMode = enable ? face.Convert() : MTLCullMode.None;
|
var cullMode = enable ? face.Convert() : MTLCullMode.None;
|
||||||
|
|
||||||
if (_currentEncoder is MTLRenderCommandEncoder renderCommandEncoder)
|
if (_currentEncoderType == EncoderType.Render)
|
||||||
{
|
{
|
||||||
renderCommandEncoder.SetCullMode(cullMode);
|
new MTLRenderCommandEncoder(_currentEncoder.Value).SetCullMode(cullMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
_renderEncoderState.CullMode = cullMode;
|
_renderEncoderState.CullMode = cullMode;
|
||||||
|
@ -374,9 +413,9 @@ namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
var winding = frontFace.Convert();
|
var winding = frontFace.Convert();
|
||||||
|
|
||||||
if (_currentEncoder is MTLRenderCommandEncoder renderCommandEncoder)
|
if (_currentEncoderType == EncoderType.Render)
|
||||||
{
|
{
|
||||||
renderCommandEncoder.SetFrontFacingWinding(winding);
|
new MTLRenderCommandEncoder(_currentEncoder.Value).SetFrontFacingWinding(winding);
|
||||||
}
|
}
|
||||||
|
|
||||||
_renderEncoderState.Winding = winding;
|
_renderEncoderState.Winding = winding;
|
||||||
|
@ -545,9 +584,9 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
var depthStencilState = _renderEncoderState.UpdateStencilState(backFace, frontFace);
|
var depthStencilState = _renderEncoderState.UpdateStencilState(backFace, frontFace);
|
||||||
|
|
||||||
if (_currentEncoder is MTLRenderCommandEncoder renderCommandEncoder)
|
if (_currentEncoderType == EncoderType.Render)
|
||||||
{
|
{
|
||||||
renderCommandEncoder.SetDepthStencilState(depthStencilState);
|
new MTLRenderCommandEncoder(_currentEncoder.Value).SetDepthStencilState(depthStencilState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,7 +633,11 @@ namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
if (vertexBuffers[i].Stride != 0)
|
if (vertexBuffers[i].Stride != 0)
|
||||||
{
|
{
|
||||||
_vertexDescriptor.Layouts.Object((ulong)i).Stride = (ulong)vertexBuffers[i].Stride;
|
var layout = _vertexDescriptor.Layouts.Object(0);
|
||||||
|
|
||||||
|
layout.Stride = (ulong)vertexBuffers[i].Stride;
|
||||||
|
|
||||||
|
_vertexDescriptor.Layouts.SetObject(layout, (ulong)i);
|
||||||
_vertexBuffers[i] = _device.NewBuffer(
|
_vertexBuffers[i] = _device.NewBuffer(
|
||||||
vertexBuffers[i].Buffer.Handle.ToIntPtr(),
|
vertexBuffers[i].Buffer.Handle.ToIntPtr(),
|
||||||
(ulong)vertexBuffers[i].Buffer.Size,
|
(ulong)vertexBuffers[i].Buffer.Size,
|
||||||
|
|
|
@ -832,7 +832,7 @@ namespace Ryujinx.Ava
|
||||||
}
|
}
|
||||||
else if (ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.Metal && OperatingSystem.IsMacOS())
|
else if (ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.Metal && OperatingSystem.IsMacOS())
|
||||||
{
|
{
|
||||||
renderer = new MetalRenderer();
|
renderer = new MetalRenderer((RendererHost.EmbeddedWindow as EmbeddedWindowMetal).CreateSurface);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,25 +1,12 @@
|
||||||
using SPB.Windowing;
|
using SharpMetal.QuartzCore;
|
||||||
using SPB.Platform.Metal;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Ryujinx.Ava.UI.Renderer
|
namespace Ryujinx.Ava.UI.Renderer
|
||||||
{
|
{
|
||||||
public class EmbeddedWindowMetal : EmbeddedWindow
|
public class EmbeddedWindowMetal : EmbeddedWindow
|
||||||
{
|
{
|
||||||
public SimpleMetalWindow CreateSurface()
|
public CAMetalLayer CreateSurface()
|
||||||
{
|
{
|
||||||
SimpleMetalWindow simpleMetalWindow;
|
return new CAMetalLayer(MetalLayer);
|
||||||
|
|
||||||
if (OperatingSystem.IsMacOS())
|
|
||||||
{
|
|
||||||
simpleMetalWindow = new SimpleMetalWindow(new NativeHandle(NsView), new NativeHandle(MetalLayer));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new PlatformNotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return simpleMetalWindow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,13 @@ namespace Ryujinx.Ava.UI.Renderer
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
if (ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.OpenGl)
|
EmbeddedWindow = ConfigurationState.Instance.Graphics.GraphicsBackend.Value switch
|
||||||
{
|
{
|
||||||
EmbeddedWindow = new EmbeddedWindowOpenGL();
|
GraphicsBackend.OpenGl => new EmbeddedWindowOpenGL(),
|
||||||
}
|
GraphicsBackend.Metal => new EmbeddedWindowMetal(),
|
||||||
else
|
GraphicsBackend.Vulkan => new EmbeddedWindowVulkan(),
|
||||||
{
|
_ => throw new NotSupportedException()
|
||||||
EmbeddedWindow = new EmbeddedWindowVulkan();
|
};
|
||||||
}
|
|
||||||
|
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue