mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-12-27 02:53:04 +00:00
Cleanup Pipeline
Housekeeping More housekeeping
This commit is contained in:
parent
30b50a99e4
commit
b1928461bb
24 changed files with 77 additions and 92 deletions
|
@ -5,7 +5,7 @@ using System.Threading;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
public interface IAuto
|
interface IAuto
|
||||||
{
|
{
|
||||||
bool HasCommandBufferDependency(CommandBufferScoped cbs);
|
bool HasCommandBufferDependency(CommandBufferScoped cbs);
|
||||||
|
|
||||||
|
@ -14,13 +14,13 @@ namespace Ryujinx.Graphics.Metal
|
||||||
void DecrementReferenceCount();
|
void DecrementReferenceCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IAutoPrivate : IAuto
|
interface IAutoPrivate : IAuto
|
||||||
{
|
{
|
||||||
void AddCommandBufferDependencies(CommandBufferScoped cbs);
|
void AddCommandBufferDependencies(CommandBufferScoped cbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class Auto<T> : IAutoPrivate, IDisposable where T : IDisposable
|
class Auto<T> : IAutoPrivate, IDisposable where T : IDisposable
|
||||||
{
|
{
|
||||||
private int _referenceCount;
|
private int _referenceCount;
|
||||||
private T _value;
|
private T _value;
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
if (_pool == null)
|
if (_pool == null)
|
||||||
{
|
{
|
||||||
MTLCommandQueue queue = _renderer.BackgroundQueue;
|
MTLCommandQueue queue = _renderer.BackgroundQueue;
|
||||||
_pool = new CommandBufferPool(queue.Device, queue);
|
_pool = new CommandBufferPool(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _pool;
|
return _pool;
|
||||||
|
|
|
@ -8,7 +8,7 @@ using System.Threading;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class BufferHolder : IDisposable
|
class BufferHolder : IDisposable
|
||||||
{
|
{
|
||||||
private CacheByRange<BufferHolder> _cachedConvertedBuffers;
|
private CacheByRange<BufferHolder> _cachedConvertedBuffers;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ using System.Runtime.Versioning;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
public readonly struct ScopedTemporaryBuffer : IDisposable
|
readonly struct ScopedTemporaryBuffer : IDisposable
|
||||||
{
|
{
|
||||||
private readonly BufferManager _bufferManager;
|
private readonly BufferManager _bufferManager;
|
||||||
private readonly bool _isReserved;
|
private readonly bool _isReserved;
|
||||||
|
@ -39,7 +39,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
}
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class BufferManager : IDisposable
|
class BufferManager : IDisposable
|
||||||
{
|
{
|
||||||
private readonly IdList<BufferHolder> _buffers;
|
private readonly IdList<BufferHolder> _buffers;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
using SharpMetal.Metal;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
public interface ICacheKey : IDisposable
|
interface ICacheKey : IDisposable
|
||||||
{
|
{
|
||||||
bool KeyEqual(ICacheKey other);
|
bool KeyEqual(ICacheKey other);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +115,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
}
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public readonly struct Dependency
|
readonly struct Dependency
|
||||||
{
|
{
|
||||||
private readonly BufferHolder _buffer;
|
private readonly BufferHolder _buffer;
|
||||||
private readonly int _offset;
|
private readonly int _offset;
|
||||||
|
|
|
@ -7,14 +7,12 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class CommandBufferPool : IDisposable
|
class CommandBufferPool : IDisposable
|
||||||
{
|
{
|
||||||
public const int MaxCommandBuffers = 16;
|
public const int MaxCommandBuffers = 16;
|
||||||
|
|
||||||
private readonly int _totalCommandBuffers;
|
private readonly int _totalCommandBuffers;
|
||||||
private readonly int _totalCommandBuffersMask;
|
private readonly int _totalCommandBuffersMask;
|
||||||
|
|
||||||
private readonly MTLDevice _device;
|
|
||||||
private readonly MTLCommandQueue _queue;
|
private readonly MTLCommandQueue _queue;
|
||||||
|
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
|
@ -45,9 +43,8 @@ namespace Ryujinx.Graphics.Metal
|
||||||
private int _queuedCount;
|
private int _queuedCount;
|
||||||
private int _inUseCount;
|
private int _inUseCount;
|
||||||
|
|
||||||
public CommandBufferPool(MTLDevice device, MTLCommandQueue queue)
|
public CommandBufferPool(MTLCommandQueue queue)
|
||||||
{
|
{
|
||||||
_device = device;
|
|
||||||
_queue = queue;
|
_queue = queue;
|
||||||
|
|
||||||
_totalCommandBuffers = MaxCommandBuffers;
|
_totalCommandBuffers = MaxCommandBuffers;
|
||||||
|
|
|
@ -5,7 +5,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public readonly struct CommandBufferScoped : IDisposable
|
readonly struct CommandBufferScoped : IDisposable
|
||||||
{
|
{
|
||||||
private readonly CommandBufferPool _pool;
|
private readonly CommandBufferPool _pool;
|
||||||
public MTLCommandBuffer CommandBuffer { get; }
|
public MTLCommandBuffer CommandBuffer { get; }
|
||||||
|
|
|
@ -7,7 +7,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class ComputePipelineCache : StateCache<MTLComputePipelineState, MTLFunction, MTLFunction>
|
class ComputePipelineCache : StateCache<MTLComputePipelineState, MTLFunction, MTLFunction>
|
||||||
{
|
{
|
||||||
private readonly MTLDevice _device;
|
private readonly MTLDevice _device;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public struct DepthStencilHash
|
struct DepthStencilHash
|
||||||
{
|
{
|
||||||
public struct StencilHash
|
public struct StencilHash
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
}
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class DepthStencilCache : StateCache<MTLDepthStencilState, MTLDepthStencilDescriptor, DepthStencilHash>
|
class DepthStencilCache : StateCache<MTLDepthStencilState, MTLDepthStencilDescriptor, DepthStencilHash>
|
||||||
{
|
{
|
||||||
private readonly MTLDevice _device;
|
private readonly MTLDevice _device;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public readonly struct DisposableBuffer : IDisposable
|
readonly struct DisposableBuffer : IDisposable
|
||||||
{
|
{
|
||||||
public MTLBuffer Value { get; }
|
public MTLBuffer Value { get; }
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ using System.Runtime.Versioning;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
public struct DirtyFlags
|
struct DirtyFlags
|
||||||
{
|
{
|
||||||
public bool RenderPipeline = false;
|
public bool RenderPipeline = false;
|
||||||
public bool ComputePipeline = false;
|
public bool ComputePipeline = false;
|
||||||
|
@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record struct BufferRef
|
record struct BufferRef
|
||||||
{
|
{
|
||||||
public Auto<DisposableBuffer> Buffer;
|
public Auto<DisposableBuffer> Buffer;
|
||||||
public int Index;
|
public int Index;
|
||||||
|
|
|
@ -360,7 +360,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
_currentState.IndexType = MTLIndexType.UInt16;
|
_currentState.IndexType = MTLIndexType.UInt16;
|
||||||
_currentState.IndexBufferOffset = (ulong)buffer.Offset;
|
_currentState.IndexBufferOffset = (ulong)buffer.Offset;
|
||||||
_currentState.IndexBuffer = _bufferManager.GetBufferI8ToI16(_pipeline.CurrentCommandBuffer, buffer.Handle, buffer.Offset, buffer.Size);
|
_currentState.IndexBuffer = _bufferManager.GetBufferI8ToI16(_pipeline.Cbs, buffer.Handle, buffer.Offset, buffer.Size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1036,12 +1036,12 @@ namespace Ryujinx.Graphics.Metal
|
||||||
if (range.HasValue)
|
if (range.HasValue)
|
||||||
{
|
{
|
||||||
offset = range.Value.Offset;
|
offset = range.Value.Offset;
|
||||||
mtlBuffer = autoBuffer.Get(_pipeline.CurrentCommandBuffer, offset, range.Value.Size, range.Value.Write).Value;
|
mtlBuffer = autoBuffer.Get(_pipeline.Cbs, offset, range.Value.Size, range.Value.Write).Value;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mtlBuffer = autoBuffer.Get(_pipeline.CurrentCommandBuffer).Value;
|
mtlBuffer = autoBuffer.Get(_pipeline.Cbs).Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderCommandEncoder.SetVertexBuffer(mtlBuffer, (ulong)offset, (ulong)index);
|
renderCommandEncoder.SetVertexBuffer(mtlBuffer, (ulong)offset, (ulong)index);
|
||||||
|
@ -1072,12 +1072,12 @@ namespace Ryujinx.Graphics.Metal
|
||||||
if (range.HasValue)
|
if (range.HasValue)
|
||||||
{
|
{
|
||||||
offset = range.Value.Offset;
|
offset = range.Value.Offset;
|
||||||
mtlBuffer = autoBuffer.Get(_pipeline.CurrentCommandBuffer, offset, range.Value.Size, range.Value.Write).Value;
|
mtlBuffer = autoBuffer.Get(_pipeline.Cbs, offset, range.Value.Size, range.Value.Write).Value;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mtlBuffer = autoBuffer.Get(_pipeline.CurrentCommandBuffer).Value;
|
mtlBuffer = autoBuffer.Get(_pipeline.Cbs).Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
computeCommandEncoder.SetBuffer(mtlBuffer, (ulong)offset, (ulong)index);
|
computeCommandEncoder.SetBuffer(mtlBuffer, (ulong)offset, (ulong)index);
|
||||||
|
|
|
@ -6,7 +6,7 @@ using System.Threading;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class FenceHolder : IDisposable
|
class FenceHolder : IDisposable
|
||||||
{
|
{
|
||||||
private MTLCommandBuffer _fence;
|
private MTLCommandBuffer _fence;
|
||||||
private int _referenceCount;
|
private int _referenceCount;
|
||||||
|
|
|
@ -10,7 +10,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class HelperShader : IDisposable
|
class HelperShader : IDisposable
|
||||||
{
|
{
|
||||||
private const int ConvertElementsPerWorkgroup = 32 * 100; // Work group size of 32 times 100 elements.
|
private const int ConvertElementsPerWorkgroup = 32 * 100; // Work group size of 32 times 100 elements.
|
||||||
private const string ShadersSourcePath = "/Ryujinx.Graphics.Metal/Shaders";
|
private const string ShadersSourcePath = "/Ryujinx.Graphics.Metal/Shaders";
|
||||||
|
@ -268,7 +268,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
// TODO: Flush
|
// TODO: Flush
|
||||||
|
|
||||||
using var buffer = _renderer.BufferManager.ReserveOrCreate(_pipeline.CurrentCommandBuffer, ClearColorBufferSize);
|
using var buffer = _renderer.BufferManager.ReserveOrCreate(_pipeline.Cbs, ClearColorBufferSize);
|
||||||
buffer.Holder.SetDataUnchecked(buffer.Offset, clearColor);
|
buffer.Holder.SetDataUnchecked(buffer.Offset, clearColor);
|
||||||
_pipeline.SetUniformBuffers([new BufferAssignment(0, buffer.Range)]);
|
_pipeline.SetUniformBuffers([new BufferAssignment(0, buffer.Range)]);
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured;
|
public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured;
|
||||||
public bool PreferThreading => true;
|
public bool PreferThreading => true;
|
||||||
|
|
||||||
public IPipeline Pipeline => _pipeline;
|
public IPipeline Pipeline => _pipeline;
|
||||||
public IWindow Window => _window;
|
public IWindow Window => _window;
|
||||||
|
|
||||||
|
@ -54,9 +53,9 @@ namespace Ryujinx.Graphics.Metal
|
||||||
layer.Device = _device;
|
layer.Device = _device;
|
||||||
layer.FramebufferOnly = false;
|
layer.FramebufferOnly = false;
|
||||||
|
|
||||||
CommandBufferPool = new CommandBufferPool(_device, _queue);
|
CommandBufferPool = new CommandBufferPool(_queue);
|
||||||
_window = new Window(this, layer);
|
_window = new Window(this, layer);
|
||||||
_pipeline = new Pipeline(_device, this, _queue);
|
_pipeline = new Pipeline(_device, this);
|
||||||
BufferManager = new BufferManager(_device, this, _pipeline);
|
BufferManager = new BufferManager(_device, this, _pipeline);
|
||||||
|
|
||||||
_pipeline.InitEncoderStateManager(BufferManager);
|
_pipeline.InitEncoderStateManager(BufferManager);
|
||||||
|
@ -222,7 +221,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data)
|
public void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data)
|
||||||
{
|
{
|
||||||
BufferManager.SetData(buffer, offset, data, _pipeline.CurrentCommandBuffer, _pipeline.EndRenderPassDelegate);
|
BufferManager.SetData(buffer, offset, data, _pipeline.Cbs, _pipeline.EndRenderPassDelegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateCounters()
|
public void UpdateCounters()
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
/// Holder for multiple host GPU fences.
|
/// Holder for multiple host GPU fences.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class MultiFenceHolder
|
class MultiFenceHolder
|
||||||
{
|
{
|
||||||
private const int BufferUsageTrackingGranularity = 4096;
|
private const int BufferUsageTrackingGranularity = 4096;
|
||||||
|
|
||||||
|
|
|
@ -18,40 +18,30 @@ namespace Ryujinx.Graphics.Metal
|
||||||
}
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class Pipeline : IPipeline, IDisposable
|
class Pipeline : IPipeline, IDisposable
|
||||||
{
|
{
|
||||||
private readonly MTLDevice _device;
|
private readonly MTLDevice _device;
|
||||||
private readonly MTLCommandQueue _commandQueue;
|
|
||||||
private readonly MetalRenderer _renderer;
|
private readonly MetalRenderer _renderer;
|
||||||
|
|
||||||
private CommandBufferScoped Cbs;
|
|
||||||
private CommandBufferScoped? PreloadCbs;
|
|
||||||
public MTLCommandBuffer CommandBuffer;
|
|
||||||
|
|
||||||
public readonly Action EndRenderPassDelegate;
|
|
||||||
|
|
||||||
public CommandBufferScoped CurrentCommandBuffer => Cbs;
|
|
||||||
|
|
||||||
private MTLCommandEncoder? _currentEncoder;
|
|
||||||
public MTLCommandEncoder? CurrentEncoder => _currentEncoder;
|
|
||||||
|
|
||||||
private EncoderType _currentEncoderType = EncoderType.None;
|
|
||||||
public EncoderType CurrentEncoderType => _currentEncoderType;
|
|
||||||
|
|
||||||
private EncoderStateManager _encoderStateManager;
|
private EncoderStateManager _encoderStateManager;
|
||||||
|
|
||||||
public Pipeline(MTLDevice device, MetalRenderer renderer, MTLCommandQueue commandQueue)
|
public readonly Action EndRenderPassDelegate;
|
||||||
|
public MTLCommandBuffer CommandBuffer;
|
||||||
|
|
||||||
|
internal CommandBufferScoped Cbs { get; private set; }
|
||||||
|
internal MTLCommandEncoder? CurrentEncoder { get; private set; }
|
||||||
|
internal EncoderType CurrentEncoderType { get; private set; } = EncoderType.None;
|
||||||
|
|
||||||
|
public Pipeline(MTLDevice device, MetalRenderer renderer)
|
||||||
{
|
{
|
||||||
_device = device;
|
_device = device;
|
||||||
_renderer = renderer;
|
_renderer = renderer;
|
||||||
_commandQueue = commandQueue;
|
|
||||||
|
|
||||||
EndRenderPassDelegate = EndCurrentPass;
|
EndRenderPassDelegate = EndCurrentPass;
|
||||||
|
|
||||||
CommandBuffer = (Cbs = _renderer.CommandBufferPool.Rent()).CommandBuffer;
|
CommandBuffer = (Cbs = _renderer.CommandBufferPool.Rent()).CommandBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitEncoderStateManager(BufferManager bufferManager)
|
internal void InitEncoderStateManager(BufferManager bufferManager)
|
||||||
{
|
{
|
||||||
_encoderStateManager = new EncoderStateManager(_device, bufferManager, this);
|
_encoderStateManager = new EncoderStateManager(_device, bufferManager, this);
|
||||||
}
|
}
|
||||||
|
@ -79,13 +69,13 @@ namespace Ryujinx.Graphics.Metal
|
||||||
public MTLRenderCommandEncoder GetOrCreateRenderEncoder(bool forDraw = false)
|
public MTLRenderCommandEncoder GetOrCreateRenderEncoder(bool forDraw = false)
|
||||||
{
|
{
|
||||||
MTLRenderCommandEncoder renderCommandEncoder;
|
MTLRenderCommandEncoder renderCommandEncoder;
|
||||||
if (_currentEncoder == null || _currentEncoderType != EncoderType.Render)
|
if (CurrentEncoder == null || CurrentEncoderType != EncoderType.Render)
|
||||||
{
|
{
|
||||||
renderCommandEncoder = BeginRenderPass();
|
renderCommandEncoder = BeginRenderPass();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
renderCommandEncoder = new MTLRenderCommandEncoder(_currentEncoder.Value);
|
renderCommandEncoder = new MTLRenderCommandEncoder(CurrentEncoder.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (forDraw)
|
if (forDraw)
|
||||||
|
@ -98,11 +88,11 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public MTLBlitCommandEncoder GetOrCreateBlitEncoder()
|
public MTLBlitCommandEncoder GetOrCreateBlitEncoder()
|
||||||
{
|
{
|
||||||
if (_currentEncoder != null)
|
if (CurrentEncoder != null)
|
||||||
{
|
{
|
||||||
if (_currentEncoderType == EncoderType.Blit)
|
if (CurrentEncoderType == EncoderType.Blit)
|
||||||
{
|
{
|
||||||
return new MTLBlitCommandEncoder(_currentEncoder.Value);
|
return new MTLBlitCommandEncoder(CurrentEncoder.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,13 +102,13 @@ namespace Ryujinx.Graphics.Metal
|
||||||
public MTLComputeCommandEncoder GetOrCreateComputeEncoder()
|
public MTLComputeCommandEncoder GetOrCreateComputeEncoder()
|
||||||
{
|
{
|
||||||
MTLComputeCommandEncoder computeCommandEncoder;
|
MTLComputeCommandEncoder computeCommandEncoder;
|
||||||
if (_currentEncoder == null || _currentEncoderType != EncoderType.Compute)
|
if (CurrentEncoder == null || CurrentEncoderType != EncoderType.Compute)
|
||||||
{
|
{
|
||||||
computeCommandEncoder = BeginComputePass();
|
computeCommandEncoder = BeginComputePass();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
computeCommandEncoder = new MTLComputeCommandEncoder(_currentEncoder.Value);
|
computeCommandEncoder = new MTLComputeCommandEncoder(CurrentEncoder.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
_encoderStateManager.RebindComputeState(computeCommandEncoder);
|
_encoderStateManager.RebindComputeState(computeCommandEncoder);
|
||||||
|
@ -128,62 +118,62 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public void EndCurrentPass()
|
public void EndCurrentPass()
|
||||||
{
|
{
|
||||||
if (_currentEncoder != null)
|
if (CurrentEncoder != null)
|
||||||
{
|
{
|
||||||
switch (_currentEncoderType)
|
switch (CurrentEncoderType)
|
||||||
{
|
{
|
||||||
case EncoderType.Blit:
|
case EncoderType.Blit:
|
||||||
new MTLBlitCommandEncoder(_currentEncoder.Value).EndEncoding();
|
new MTLBlitCommandEncoder(CurrentEncoder.Value).EndEncoding();
|
||||||
_currentEncoder = null;
|
CurrentEncoder = null;
|
||||||
break;
|
break;
|
||||||
case EncoderType.Compute:
|
case EncoderType.Compute:
|
||||||
new MTLComputeCommandEncoder(_currentEncoder.Value).EndEncoding();
|
new MTLComputeCommandEncoder(CurrentEncoder.Value).EndEncoding();
|
||||||
_currentEncoder = null;
|
CurrentEncoder = null;
|
||||||
break;
|
break;
|
||||||
case EncoderType.Render:
|
case EncoderType.Render:
|
||||||
new MTLRenderCommandEncoder(_currentEncoder.Value).EndEncoding();
|
new MTLRenderCommandEncoder(CurrentEncoder.Value).EndEncoding();
|
||||||
_currentEncoder = null;
|
CurrentEncoder = null;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentEncoderType = EncoderType.None;
|
CurrentEncoderType = EncoderType.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MTLRenderCommandEncoder BeginRenderPass()
|
private MTLRenderCommandEncoder BeginRenderPass()
|
||||||
{
|
{
|
||||||
EndCurrentPass();
|
EndCurrentPass();
|
||||||
|
|
||||||
var renderCommandEncoder = _encoderStateManager.CreateRenderCommandEncoder();
|
var renderCommandEncoder = _encoderStateManager.CreateRenderCommandEncoder();
|
||||||
|
|
||||||
_currentEncoder = renderCommandEncoder;
|
CurrentEncoder = renderCommandEncoder;
|
||||||
_currentEncoderType = EncoderType.Render;
|
CurrentEncoderType = EncoderType.Render;
|
||||||
|
|
||||||
return renderCommandEncoder;
|
return renderCommandEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MTLBlitCommandEncoder BeginBlitPass()
|
private MTLBlitCommandEncoder BeginBlitPass()
|
||||||
{
|
{
|
||||||
EndCurrentPass();
|
EndCurrentPass();
|
||||||
|
|
||||||
var descriptor = new MTLBlitPassDescriptor();
|
var descriptor = new MTLBlitPassDescriptor();
|
||||||
var blitCommandEncoder = Cbs.CommandBuffer.BlitCommandEncoder(descriptor);
|
var blitCommandEncoder = Cbs.CommandBuffer.BlitCommandEncoder(descriptor);
|
||||||
|
|
||||||
_currentEncoder = blitCommandEncoder;
|
CurrentEncoder = blitCommandEncoder;
|
||||||
_currentEncoderType = EncoderType.Blit;
|
CurrentEncoderType = EncoderType.Blit;
|
||||||
return blitCommandEncoder;
|
return blitCommandEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MTLComputeCommandEncoder BeginComputePass()
|
private MTLComputeCommandEncoder BeginComputePass()
|
||||||
{
|
{
|
||||||
EndCurrentPass();
|
EndCurrentPass();
|
||||||
|
|
||||||
var computeCommandEncoder = _encoderStateManager.CreateComputeCommandEncoder();
|
var computeCommandEncoder = _encoderStateManager.CreateComputeCommandEncoder();
|
||||||
|
|
||||||
_currentEncoder = computeCommandEncoder;
|
CurrentEncoder = computeCommandEncoder;
|
||||||
_currentEncoderType = EncoderType.Compute;
|
CurrentEncoderType = EncoderType.Compute;
|
||||||
return computeCommandEncoder;
|
return computeCommandEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +222,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public void Barrier()
|
public void Barrier()
|
||||||
{
|
{
|
||||||
switch (_currentEncoderType)
|
switch (CurrentEncoderType)
|
||||||
{
|
{
|
||||||
case EncoderType.Render:
|
case EncoderType.Render:
|
||||||
{
|
{
|
||||||
|
@ -546,7 +536,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
_encoderStateManager.UpdateStorageBuffers(buffers);
|
_encoderStateManager.UpdateStorageBuffers(buffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetStorageBuffers(int first, ReadOnlySpan<Auto<DisposableBuffer>> buffers)
|
internal void SetStorageBuffers(int first, ReadOnlySpan<Auto<DisposableBuffer>> buffers)
|
||||||
{
|
{
|
||||||
_encoderStateManager.UpdateStorageBuffers(first, buffers);
|
_encoderStateManager.UpdateStorageBuffers(first, buffers);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public struct RenderPipelineHash
|
struct RenderPipelineHash
|
||||||
{
|
{
|
||||||
public MTLFunction VertexFunction;
|
public MTLFunction VertexFunction;
|
||||||
public MTLFunction FragmentFunction;
|
public MTLFunction FragmentFunction;
|
||||||
|
@ -162,7 +162,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
}
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class RenderPipelineCache : StateCache<MTLRenderPipelineState, MTLRenderPipelineDescriptor, RenderPipelineHash>
|
class RenderPipelineCache : StateCache<MTLRenderPipelineState, MTLRenderPipelineDescriptor, RenderPipelineHash>
|
||||||
{
|
{
|
||||||
private readonly MTLDevice _device;
|
private readonly MTLDevice _device;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ using System.Runtime.Versioning;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
public readonly struct StagingBufferReserved
|
readonly struct StagingBufferReserved
|
||||||
{
|
{
|
||||||
public readonly BufferHolder Buffer;
|
public readonly BufferHolder Buffer;
|
||||||
public readonly int Offset;
|
public readonly int Offset;
|
||||||
|
@ -23,7 +23,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
}
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class StagingBuffer : IDisposable
|
class StagingBuffer : IDisposable
|
||||||
{
|
{
|
||||||
private const int BufferSize = 32 * 1024 * 1024;
|
private const int BufferSize = 32 * 1024 * 1024;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public abstract class StateCache<T, TDescriptor, THash> : IDisposable where T : IDisposable
|
abstract class StateCache<T, TDescriptor, THash> : IDisposable where T : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Dictionary<THash, T> _cache = new();
|
private readonly Dictionary<THash, T> _cache = new();
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class StringHelper
|
class StringHelper
|
||||||
{
|
{
|
||||||
public static NSString NSString(string source)
|
public static NSString NSString(string source)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class SyncManager
|
class SyncManager
|
||||||
{
|
{
|
||||||
private class SyncHandle
|
private class SyncHandle
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,7 +8,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public class Texture : TextureBase, ITexture
|
class Texture : TextureBase, ITexture
|
||||||
{
|
{
|
||||||
public Texture(MTLDevice device, MetalRenderer renderer, Pipeline pipeline, TextureCreateInfo info) : base(device, renderer, pipeline, info)
|
public Texture(MTLDevice device, MetalRenderer renderer, Pipeline pipeline, TextureCreateInfo info) : base(device, renderer, pipeline, info)
|
||||||
{
|
{
|
||||||
|
@ -162,7 +162,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
public void CopyTo(BufferRange range, int layer, int level, int stride)
|
public void CopyTo(BufferRange range, int layer, int level, int stride)
|
||||||
{
|
{
|
||||||
var blitCommandEncoder = _pipeline.GetOrCreateBlitEncoder();
|
var blitCommandEncoder = _pipeline.GetOrCreateBlitEncoder();
|
||||||
var cbs = _pipeline.CurrentCommandBuffer;
|
var cbs = _pipeline.Cbs;
|
||||||
|
|
||||||
int outSize = Info.GetMipSize(level);
|
int outSize = Info.GetMipSize(level);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ using System.Runtime.Versioning;
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
public abstract class TextureBase : IDisposable
|
abstract class TextureBase : IDisposable
|
||||||
{
|
{
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue