Housekeeping

This commit is contained in:
Isaac Marovitz 2024-06-21 00:26:46 +01:00
commit 686b0c686a
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1
13 changed files with 24 additions and 29 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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; }

View file

@ -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;

View file

@ -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";

View file

@ -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,7 +53,7 @@ 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); _pipeline = new Pipeline(_device, this);
BufferManager = new BufferManager(_device, this, _pipeline); BufferManager = new BufferManager(_device, this, _pipeline);

View file

@ -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;

View file

@ -41,7 +41,7 @@ namespace Ryujinx.Graphics.Metal
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);
} }
@ -142,7 +142,7 @@ namespace Ryujinx.Graphics.Metal
} }
} }
public MTLRenderCommandEncoder BeginRenderPass() private MTLRenderCommandEncoder BeginRenderPass()
{ {
EndCurrentPass(); EndCurrentPass();
@ -154,7 +154,7 @@ namespace Ryujinx.Graphics.Metal
return renderCommandEncoder; return renderCommandEncoder;
} }
public MTLBlitCommandEncoder BeginBlitPass() private MTLBlitCommandEncoder BeginBlitPass()
{ {
EndCurrentPass(); EndCurrentPass();
@ -166,7 +166,7 @@ namespace Ryujinx.Graphics.Metal
return blitCommandEncoder; return blitCommandEncoder;
} }
public MTLComputeCommandEncoder BeginComputePass() private MTLComputeCommandEncoder BeginComputePass()
{ {
EndCurrentPass(); EndCurrentPass();
@ -536,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);
} }

View file

@ -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;