2023-07-28 20:39:14 +00:00
|
|
|
using Ryujinx.Common.Logging;
|
2024-08-31 20:42:56 +00:00
|
|
|
using Ryujinx.Graphics.GAL;
|
|
|
|
using Ryujinx.Graphics.Shader;
|
2023-07-28 01:51:20 +00:00
|
|
|
using SharpMetal.Foundation;
|
|
|
|
using SharpMetal.Metal;
|
2023-08-02 23:56:59 +00:00
|
|
|
using SharpMetal.QuartzCore;
|
2024-08-31 20:42:56 +00:00
|
|
|
using System;
|
2023-07-28 01:51:20 +00:00
|
|
|
using System.Runtime.CompilerServices;
|
2024-08-31 20:42:56 +00:00
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Metal
|
|
|
|
{
|
2024-03-18 18:48:54 +00:00
|
|
|
enum EncoderType
|
|
|
|
{
|
|
|
|
Blit,
|
|
|
|
Compute,
|
2024-03-20 02:58:42 +00:00
|
|
|
Render,
|
|
|
|
None
|
2024-03-18 18:48:54 +00:00
|
|
|
}
|
|
|
|
|
2024-08-31 20:42:56 +00:00
|
|
|
[SupportedOSPlatform("macos")]
|
2023-08-03 18:50:49 +00:00
|
|
|
class Pipeline : IPipeline, IDisposable
|
2024-08-31 20:42:56 +00:00
|
|
|
{
|
2023-07-28 02:54:24 +00:00
|
|
|
private readonly MTLDevice _device;
|
2023-08-03 21:04:59 +00:00
|
|
|
private readonly MTLCommandQueue _commandQueue;
|
2024-05-18 22:54:55 +00:00
|
|
|
private readonly HelperShader _helperShader;
|
2023-07-28 02:54:24 +00:00
|
|
|
|
2024-08-31 20:42:56 +00:00
|
|
|
private MTLCommandBuffer _commandBuffer;
|
2024-05-18 22:54:55 +00:00
|
|
|
public MTLCommandBuffer CommandBuffer => _commandBuffer;
|
|
|
|
|
2024-03-18 18:32:59 +00:00
|
|
|
private MTLCommandEncoder? _currentEncoder;
|
2024-05-18 22:54:55 +00:00
|
|
|
public MTLCommandEncoder? CurrentEncoder => _currentEncoder;
|
2023-07-28 02:54:24 +00:00
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
private EncoderType _currentEncoderType = EncoderType.None;
|
|
|
|
public EncoderType CurrentEncoderType => _currentEncoderType;
|
2023-07-28 01:51:20 +00:00
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
private EncoderStateManager _encoderStateManager;
|
2023-07-28 01:51:20 +00:00
|
|
|
|
2023-08-03 12:48:41 +00:00
|
|
|
public Pipeline(MTLDevice device, MTLCommandQueue commandQueue)
|
2024-08-31 20:42:56 +00:00
|
|
|
{
|
2023-07-28 02:54:24 +00:00
|
|
|
_device = device;
|
2023-08-03 21:04:59 +00:00
|
|
|
_commandQueue = commandQueue;
|
2024-05-18 22:54:55 +00:00
|
|
|
_helperShader = new HelperShader(_device, this);
|
2024-08-31 20:42:56 +00:00
|
|
|
|
2023-08-03 21:04:59 +00:00
|
|
|
_commandBuffer = _commandQueue.CommandBuffer();
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager = new EncoderStateManager(_device, this);
|
2023-07-28 02:54:24 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 20:47:10 +00:00
|
|
|
public MTLRenderCommandEncoder GetOrCreateRenderEncoder()
|
|
|
|
{
|
2024-03-18 18:48:54 +00:00
|
|
|
if (_currentEncoder != null)
|
2023-08-03 20:47:10 +00:00
|
|
|
{
|
2024-03-18 18:48:54 +00:00
|
|
|
if (_currentEncoderType == EncoderType.Render)
|
|
|
|
{
|
|
|
|
return new MTLRenderCommandEncoder(_currentEncoder.Value);
|
|
|
|
}
|
2023-08-03 20:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return BeginRenderPass();
|
|
|
|
}
|
|
|
|
|
|
|
|
public MTLBlitCommandEncoder GetOrCreateBlitEncoder()
|
|
|
|
{
|
2024-03-18 18:48:54 +00:00
|
|
|
if (_currentEncoder != null)
|
2023-08-03 20:47:10 +00:00
|
|
|
{
|
2024-03-18 18:48:54 +00:00
|
|
|
if (_currentEncoderType == EncoderType.Blit)
|
|
|
|
{
|
|
|
|
return new MTLBlitCommandEncoder(_currentEncoder.Value);
|
|
|
|
}
|
2023-08-03 20:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return BeginBlitPass();
|
|
|
|
}
|
|
|
|
|
|
|
|
public MTLComputeCommandEncoder GetOrCreateComputeEncoder()
|
|
|
|
{
|
2024-03-18 18:48:54 +00:00
|
|
|
if (_currentEncoder != null)
|
2023-08-03 20:47:10 +00:00
|
|
|
{
|
2024-03-18 18:48:54 +00:00
|
|
|
if (_currentEncoderType == EncoderType.Compute)
|
|
|
|
{
|
|
|
|
return new MTLComputeCommandEncoder(_currentEncoder.Value);
|
|
|
|
}
|
2023-08-03 20:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return BeginComputePass();
|
|
|
|
}
|
|
|
|
|
2023-07-28 20:23:13 +00:00
|
|
|
public void EndCurrentPass()
|
2023-07-28 02:54:24 +00:00
|
|
|
{
|
2023-07-28 20:23:13 +00:00
|
|
|
if (_currentEncoder != null)
|
|
|
|
{
|
2024-03-18 18:48:54 +00:00
|
|
|
switch (_currentEncoderType)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
2024-03-20 02:58:42 +00:00
|
|
|
|
|
|
|
_currentEncoderType = EncoderType.None;
|
2023-07-28 20:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public MTLRenderCommandEncoder BeginRenderPass()
|
|
|
|
{
|
|
|
|
EndCurrentPass();
|
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
var renderCommandEncoder = _encoderStateManager.CreateRenderCommandEncoder();
|
2023-10-10 23:02:38 +00:00
|
|
|
|
2023-07-28 20:23:13 +00:00
|
|
|
_currentEncoder = renderCommandEncoder;
|
2024-03-18 18:48:54 +00:00
|
|
|
_currentEncoderType = EncoderType.Render;
|
2024-05-18 22:54:55 +00:00
|
|
|
|
2023-07-28 20:23:13 +00:00
|
|
|
return renderCommandEncoder;
|
2023-07-28 02:54:24 +00:00
|
|
|
}
|
|
|
|
|
2023-07-28 20:23:13 +00:00
|
|
|
public MTLBlitCommandEncoder BeginBlitPass()
|
2023-07-28 02:54:24 +00:00
|
|
|
{
|
2023-07-28 20:23:13 +00:00
|
|
|
EndCurrentPass();
|
|
|
|
|
2023-08-02 02:36:07 +00:00
|
|
|
var descriptor = new MTLBlitPassDescriptor();
|
2023-07-28 20:23:13 +00:00
|
|
|
var blitCommandEncoder = _commandBuffer.BlitCommandEncoder(descriptor);
|
|
|
|
|
|
|
|
_currentEncoder = blitCommandEncoder;
|
2024-03-18 18:48:54 +00:00
|
|
|
_currentEncoderType = EncoderType.Blit;
|
2023-07-28 20:23:13 +00:00
|
|
|
return blitCommandEncoder;
|
|
|
|
}
|
|
|
|
|
2023-07-29 05:18:51 +00:00
|
|
|
public MTLComputeCommandEncoder BeginComputePass()
|
|
|
|
{
|
|
|
|
EndCurrentPass();
|
|
|
|
|
2023-08-02 02:36:07 +00:00
|
|
|
var descriptor = new MTLComputePassDescriptor();
|
2023-07-29 05:18:51 +00:00
|
|
|
var computeCommandEncoder = _commandBuffer.ComputeCommandEncoder(descriptor);
|
|
|
|
|
|
|
|
_currentEncoder = computeCommandEncoder;
|
2024-03-18 18:48:54 +00:00
|
|
|
_currentEncoderType = EncoderType.Compute;
|
2023-07-29 05:18:51 +00:00
|
|
|
return computeCommandEncoder;
|
|
|
|
}
|
|
|
|
|
2023-08-03 18:50:49 +00:00
|
|
|
public void Present(CAMetalDrawable drawable, ITexture texture)
|
2023-07-28 20:23:13 +00:00
|
|
|
{
|
2023-08-03 18:50:49 +00:00
|
|
|
if (texture is not Texture tex)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-28 20:23:13 +00:00
|
|
|
EndCurrentPass();
|
2023-07-28 02:54:24 +00:00
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.SwapStates();
|
2023-08-02 23:56:59 +00:00
|
|
|
|
2024-05-19 00:27:27 +00:00
|
|
|
// TODO: Clean this up
|
|
|
|
var textureInfo = new TextureCreateInfo((int)drawable.Texture.Width, (int)drawable.Texture.Height, (int)drawable.Texture.Depth, (int)drawable.Texture.MipmapLevelCount, (int)drawable.Texture.SampleCount, 0, 0, 0, Format.B8G8R8A8Unorm, 0, Target.Texture2D, SwizzleComponent.Red, SwizzleComponent.Green, SwizzleComponent.Blue, SwizzleComponent.Alpha);
|
|
|
|
var dest = new Texture(_device, this, textureInfo, drawable.Texture, 0, 0);
|
|
|
|
|
|
|
|
_helperShader.BlitColor(tex, dest);
|
2023-08-02 23:56:59 +00:00
|
|
|
|
|
|
|
_commandBuffer.PresentDrawable(drawable);
|
|
|
|
_commandBuffer.Commit();
|
|
|
|
|
2023-08-03 21:04:59 +00:00
|
|
|
_commandBuffer = _commandQueue.CommandBuffer();
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
public void Finish()
|
2024-08-31 20:42:56 +00:00
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.SwapStates();
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
public void Barrier()
|
2024-03-20 20:37:08 +00:00
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-03-20 20:37:08 +00:00
|
|
|
}
|
|
|
|
|
2024-08-31 20:42:56 +00:00
|
|
|
public void ClearBuffer(BufferHandle destination, int offset, int size, uint value)
|
|
|
|
{
|
2023-08-03 20:47:10 +00:00
|
|
|
var blitCommandEncoder = GetOrCreateBlitEncoder();
|
2023-07-28 20:51:07 +00:00
|
|
|
|
|
|
|
// Might need a closer look, range's count, lower, and upper bound
|
|
|
|
// must be a multiple of 4
|
|
|
|
MTLBuffer mtlBuffer = new(Unsafe.As<BufferHandle, IntPtr>(ref destination));
|
|
|
|
blitCommandEncoder.FillBuffer(mtlBuffer,
|
|
|
|
new NSRange
|
|
|
|
{
|
|
|
|
location = (ulong)offset,
|
|
|
|
length = (ulong)size
|
|
|
|
},
|
|
|
|
(byte)value);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
public void ClearRenderTargetDepthStencil(int layer, int layerCount, float depthValue, bool depthMask, int stencilValue, int stencilMask)
|
2024-08-31 20:42:56 +00:00
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void CommandBufferBarrier()
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void CopyBuffer(BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size)
|
|
|
|
{
|
2023-08-03 20:47:10 +00:00
|
|
|
var blitCommandEncoder = GetOrCreateBlitEncoder();
|
2023-07-29 03:56:33 +00:00
|
|
|
|
|
|
|
MTLBuffer sourceBuffer = new(Unsafe.As<BufferHandle, IntPtr>(ref source));
|
|
|
|
MTLBuffer destinationBuffer = new(Unsafe.As<BufferHandle, IntPtr>(ref destination));
|
|
|
|
|
|
|
|
blitCommandEncoder.CopyFromBuffer(
|
|
|
|
sourceBuffer,
|
|
|
|
(ulong)srcOffset,
|
|
|
|
destinationBuffer,
|
|
|
|
(ulong)dstOffset,
|
|
|
|
(ulong)size);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void DispatchCompute(int groupsX, int groupsY, int groupsZ)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance)
|
|
|
|
{
|
2023-08-03 20:47:10 +00:00
|
|
|
var renderCommandEncoder = GetOrCreateRenderEncoder();
|
2023-07-28 20:23:13 +00:00
|
|
|
|
2023-07-28 01:51:20 +00:00
|
|
|
// TODO: Support topology re-indexing to provide support for TriangleFans
|
2024-05-18 22:54:55 +00:00
|
|
|
var primitiveType = _encoderStateManager.Topology.Convert();
|
2023-07-28 01:51:20 +00:00
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
renderCommandEncoder.DrawPrimitives(
|
|
|
|
primitiveType,
|
|
|
|
(ulong)firstVertex,
|
|
|
|
(ulong)vertexCount,
|
|
|
|
(ulong)instanceCount,
|
|
|
|
(ulong)firstInstance);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void DrawIndexed(int indexCount, int instanceCount, int firstIndex, int firstVertex, int firstInstance)
|
|
|
|
{
|
2023-08-03 20:47:10 +00:00
|
|
|
var renderCommandEncoder = GetOrCreateRenderEncoder();
|
2023-08-03 12:58:14 +00:00
|
|
|
|
2023-07-28 01:51:20 +00:00
|
|
|
// TODO: Support topology re-indexing to provide support for TriangleFans
|
2024-05-18 22:54:55 +00:00
|
|
|
var primitiveType = _encoderStateManager.Topology.Convert();
|
2023-07-28 01:51:20 +00:00
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
renderCommandEncoder.DrawIndexedPrimitives(
|
|
|
|
primitiveType,
|
|
|
|
(ulong)indexCount,
|
|
|
|
_encoderStateManager.IndexType,
|
|
|
|
_encoderStateManager.IndexBuffer,
|
|
|
|
_encoderStateManager.IndexBufferOffset,
|
|
|
|
(ulong)instanceCount,
|
|
|
|
firstVertex,
|
|
|
|
(ulong)firstInstance);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void DrawIndexedIndirect(BufferRange indirectBuffer)
|
|
|
|
{
|
2024-03-19 20:23:43 +00:00
|
|
|
// var renderCommandEncoder = GetOrCreateRenderEncoder();
|
2024-03-19 18:05:09 +00:00
|
|
|
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void DrawIndexedIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride)
|
|
|
|
{
|
2024-03-19 20:23:43 +00:00
|
|
|
// var renderCommandEncoder = GetOrCreateRenderEncoder();
|
2024-03-19 18:05:09 +00:00
|
|
|
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void DrawIndirect(BufferRange indirectBuffer)
|
|
|
|
{
|
2024-03-19 20:23:43 +00:00
|
|
|
// var renderCommandEncoder = GetOrCreateRenderEncoder();
|
2024-03-19 18:05:09 +00:00
|
|
|
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void DrawIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride)
|
|
|
|
{
|
2024-03-19 20:23:43 +00:00
|
|
|
// var renderCommandEncoder = GetOrCreateRenderEncoder();
|
2024-03-19 18:05:09 +00:00
|
|
|
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void DrawTexture(ITexture texture, ISampler sampler, Extents2DF srcRegion, Extents2DF dstRegion)
|
|
|
|
{
|
2024-03-19 20:23:43 +00:00
|
|
|
// var renderCommandEncoder = GetOrCreateRenderEncoder();
|
2024-03-19 18:05:09 +00:00
|
|
|
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetAlphaTest(bool enable, float reference, CompareOp op)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetBlendState(AdvancedBlendDescriptor blend)
|
|
|
|
{
|
2024-05-19 01:07:05 +00:00
|
|
|
// Metal does not support advanced blend.
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetBlendState(int index, BlendDescriptor blend)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetDepthClamp(bool clamp)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetDepthMode(DepthMode mode)
|
|
|
|
{
|
2024-05-19 01:02:49 +00:00
|
|
|
// Metal does not support depth clip control.
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetDepthTest(DepthTestDescriptor depthTest)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateDepthState(depthTest);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetFaceCulling(bool enable, Face face)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateCullMode(enable, face);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetFrontFace(FrontFace frontFace)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateFrontFace(frontFace);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetIndexBuffer(BufferRange buffer, IndexType type)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateIndexBuffer(buffer, type);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
2024-03-18 18:32:59 +00:00
|
|
|
public void SetImage(ShaderStage stage, int binding, ITexture texture, Format imageFormat)
|
|
|
|
{
|
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
|
|
|
}
|
|
|
|
|
2024-04-22 21:44:55 +00:00
|
|
|
public void SetImageArray(ShaderStage stage, int binding, IImageArray array)
|
|
|
|
{
|
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
|
|
|
}
|
|
|
|
|
2024-08-31 20:42:56 +00:00
|
|
|
public void SetLineParameters(float width, bool smooth)
|
|
|
|
{
|
2024-05-19 01:07:05 +00:00
|
|
|
// Metal does not support wide-lines.
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetLogicOpState(bool enable, LogicalOp op)
|
|
|
|
{
|
2024-05-19 01:07:05 +00:00
|
|
|
// Metal does not support logic operations.
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetMultisampleState(MultisampleDescriptor multisample)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPatchParameters(int vertices, ReadOnlySpan<float> defaultOuterLevel, ReadOnlySpan<float> defaultInnerLevel)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPointParameters(float size, bool isProgramPointSize, bool enablePointSprite, Origin origin)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPolygonMode(PolygonMode frontMode, PolygonMode backMode)
|
|
|
|
{
|
2024-05-19 01:07:05 +00:00
|
|
|
// Metal does not support polygon mode.
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPrimitiveRestart(bool enable, int index)
|
|
|
|
{
|
2023-07-28 01:51:20 +00:00
|
|
|
// 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
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPrimitiveTopology(PrimitiveTopology topology)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdatePrimitiveTopology(topology);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetProgram(IProgram program)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateProgram(program);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetRasterizerDiscard(bool discard)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMask)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetRenderTargets(ITexture[] colors, ITexture depthStencil)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateRenderTargets(colors, depthStencil);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
public void SetScissors(ReadOnlySpan<Rectangle<int>> regions)
|
2024-08-31 20:42:56 +00:00
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateScissors(regions);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetStencilTest(StencilTestDescriptor stencilTest)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateStencilState(stencilTest);
|
|
|
|
}
|
2023-07-29 04:30:08 +00:00
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
public void SetUniformBuffers(ReadOnlySpan<BufferAssignment> buffers)
|
|
|
|
{
|
|
|
|
_encoderStateManager.UpdateUniformBuffers(buffers);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetStorageBuffers(ReadOnlySpan<BufferAssignment> buffers)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateStorageBuffers(buffers);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetTextureAndSampler(ShaderStage stage, int binding, ITexture texture, ISampler sampler)
|
|
|
|
{
|
2024-03-19 19:07:35 +00:00
|
|
|
if (texture is Texture tex)
|
|
|
|
{
|
|
|
|
if (sampler is Sampler samp)
|
|
|
|
{
|
|
|
|
var mtlTexture = tex.MTLTexture;
|
|
|
|
var mtlSampler = samp.GetSampler();
|
|
|
|
var index = (ulong)binding;
|
|
|
|
|
|
|
|
switch (stage)
|
|
|
|
{
|
|
|
|
case ShaderStage.Vertex:
|
2024-05-18 22:54:55 +00:00
|
|
|
case ShaderStage.Fragment:
|
|
|
|
_encoderStateManager.UpdateTextureAndSampler(stage, index, mtlTexture, mtlSampler);
|
2024-03-19 19:07:35 +00:00
|
|
|
break;
|
|
|
|
case ShaderStage.Compute:
|
2024-05-18 22:54:55 +00:00
|
|
|
var computeCommandEncoder = GetOrCreateComputeEncoder();
|
2024-03-19 19:07:35 +00:00
|
|
|
computeCommandEncoder.SetTexture(mtlTexture, index);
|
|
|
|
computeCommandEncoder.SetSamplerState(mtlSampler, index);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(stage), stage, "Unsupported shader stage!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 21:44:55 +00:00
|
|
|
public void SetTextureArray(ShaderStage stage, int binding, ITextureArray array)
|
|
|
|
{
|
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
|
|
|
}
|
|
|
|
|
2024-08-31 20:42:56 +00:00
|
|
|
public void SetUserClipDistance(int index, bool enableClip)
|
|
|
|
{
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateVertexAttribs(vertexAttribs);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
|
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateVertexBuffers(vertexBuffers);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
2024-05-18 22:54:55 +00:00
|
|
|
public void SetViewports(ReadOnlySpan<Viewport> viewports)
|
2024-08-31 20:42:56 +00:00
|
|
|
{
|
2024-05-18 22:54:55 +00:00
|
|
|
_encoderStateManager.UpdateViewports(viewports);
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void TextureBarrier()
|
|
|
|
{
|
2024-03-19 20:23:43 +00:00
|
|
|
// var renderCommandEncoder = GetOrCreateRenderEncoder();
|
2024-03-19 18:05:09 +00:00
|
|
|
|
|
|
|
// renderCommandEncoder.MemoryBarrier(MTLBarrierScope.Textures, );
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void TextureBarrierTiled()
|
|
|
|
{
|
2024-03-19 20:23:43 +00:00
|
|
|
// var renderCommandEncoder = GetOrCreateRenderEncoder();
|
2024-03-19 18:05:09 +00:00
|
|
|
|
|
|
|
// renderCommandEncoder.MemoryBarrier(MTLBarrierScope.Textures, );
|
2023-08-02 02:36:07 +00:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!");
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual)
|
|
|
|
{
|
2023-07-28 01:51:20 +00:00
|
|
|
// TODO: Implementable via indirect draw commands
|
|
|
|
return false;
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool TryHostConditionalRendering(ICounterEvent value, ICounterEvent compare, bool isEqual)
|
|
|
|
{
|
2023-07-28 01:51:20 +00:00
|
|
|
// TODO: Implementable via indirect draw commands
|
|
|
|
return false;
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void EndHostConditionalRendering()
|
|
|
|
{
|
2023-07-28 01:51:20 +00:00
|
|
|
// TODO: Implementable via indirect draw commands
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void BeginTransformFeedback(PrimitiveTopology topology)
|
|
|
|
{
|
2024-05-19 01:07:05 +00:00
|
|
|
// Metal does not support transform feedback.
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void EndTransformFeedback()
|
|
|
|
{
|
2024-05-19 01:07:05 +00:00
|
|
|
// Metal does not support transform feedback.
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetTransformFeedbackBuffers(ReadOnlySpan<BufferRange> buffers)
|
|
|
|
{
|
2024-05-19 01:07:05 +00:00
|
|
|
// Metal does not support transform feedback.
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
2024-01-27 21:09:24 +00:00
|
|
|
EndCurrentPass();
|
2024-08-31 20:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-28 01:51:20 +00:00
|
|
|
}
|