Formatting cleanup

This commit is contained in:
Isaac Marovitz 2024-07-06 22:56:04 +01:00 committed by Isaac Marovitz
parent b734c81683
commit 18a1741348
10 changed files with 192 additions and 201 deletions

View File

@ -10,15 +10,13 @@ namespace Ryujinx.Graphics.Metal
class BackgroundResource : IDisposable
{
private readonly MetalRenderer _renderer;
private readonly Pipeline _pipeline;
private CommandBufferPool _pool;
private PersistentFlushBuffer _flushBuffer;
public BackgroundResource(MetalRenderer renderer, Pipeline pipeline)
public BackgroundResource(MetalRenderer renderer)
{
_renderer = renderer;
_pipeline = pipeline;
}
public CommandBufferPool GetPool()
@ -35,7 +33,7 @@ namespace Ryujinx.Graphics.Metal
public PersistentFlushBuffer GetFlushBuffer()
{
_flushBuffer ??= new PersistentFlushBuffer(_renderer, _pipeline);
_flushBuffer ??= new PersistentFlushBuffer(_renderer);
return _flushBuffer;
}
@ -51,14 +49,12 @@ namespace Ryujinx.Graphics.Metal
class BackgroundResources : IDisposable
{
private readonly MetalRenderer _renderer;
private readonly Pipeline _pipeline;
private readonly Dictionary<Thread, BackgroundResource> _resources;
public BackgroundResources(MetalRenderer renderer, Pipeline pipeline)
public BackgroundResources(MetalRenderer renderer)
{
_renderer = renderer;
_pipeline = pipeline;
_resources = new Dictionary<Thread, BackgroundResource>();
}
@ -88,7 +84,7 @@ namespace Ryujinx.Graphics.Metal
{
Cleanup();
resource = new BackgroundResource(_renderer, _pipeline);
resource = new BackgroundResource(_renderer);
_resources[thread] = resource;
}

View File

@ -59,7 +59,7 @@ namespace Ryujinx.Graphics.Metal
_pipeline = pipeline;
_buffers = new IdList<BufferHolder>();
StagingBuffer = new StagingBuffer(_renderer, _pipeline, this);
StagingBuffer = new StagingBuffer(_renderer, this);
}
public BufferHandle Create(nint pointer, int size)

View File

@ -13,13 +13,13 @@ namespace Ryujinx.Graphics.Metal
struct I8ToI16CacheKey : ICacheKey
{
// Used to notify the pipeline that bindings have invalidated on dispose.
private readonly MetalRenderer _renderer;
private Auto<DisposableBuffer> _buffer;
// private readonly MetalRenderer _renderer;
// private Auto<DisposableBuffer> _buffer;
public I8ToI16CacheKey(MetalRenderer renderer)
{
_renderer = renderer;
_buffer = null;
// _renderer = renderer;
// _buffer = null;
}
public readonly bool KeyEqual(ICacheKey other)
@ -27,92 +27,92 @@ namespace Ryujinx.Graphics.Metal
return other is I8ToI16CacheKey;
}
public void SetBuffer(Auto<DisposableBuffer> buffer)
public readonly void SetBuffer(Auto<DisposableBuffer> buffer)
{
_buffer = buffer;
// _buffer = buffer;
}
public void Dispose()
public readonly void Dispose()
{
// TODO: Tell pipeline buffer is dirty!
// _renderer.PipelineInternal.DirtyIndexBuffer(_buffer);
}
}
[SupportedOSPlatform("macos")]
struct AlignedVertexBufferCacheKey : ICacheKey
{
private readonly int _stride;
private readonly int _alignment;
// [SupportedOSPlatform("macos")]
// struct AlignedVertexBufferCacheKey : ICacheKey
// {
// private readonly int _stride;
// private readonly int _alignment;
//
// // Used to notify the pipeline that bindings have invalidated on dispose.
// // private readonly MetalRenderer _renderer;
// // private Auto<DisposableBuffer> _buffer;
//
// public AlignedVertexBufferCacheKey(MetalRenderer renderer, int stride, int alignment)
// {
// // _renderer = renderer;
// _stride = stride;
// _alignment = alignment;
// // _buffer = null;
// }
//
// public readonly bool KeyEqual(ICacheKey other)
// {
// return other is AlignedVertexBufferCacheKey entry &&
// entry._stride == _stride &&
// entry._alignment == _alignment;
// }
//
// public void SetBuffer(Auto<DisposableBuffer> buffer)
// {
// // _buffer = buffer;
// }
//
// public readonly void Dispose()
// {
// // TODO: Tell pipeline buffer is dirty!
// // _renderer.PipelineInternal.DirtyVertexBuffer(_buffer);
// }
// }
// Used to notify the pipeline that bindings have invalidated on dispose.
private readonly MetalRenderer _renderer;
private Auto<DisposableBuffer> _buffer;
public AlignedVertexBufferCacheKey(MetalRenderer renderer, int stride, int alignment)
{
_renderer = renderer;
_stride = stride;
_alignment = alignment;
_buffer = null;
}
public readonly bool KeyEqual(ICacheKey other)
{
return other is AlignedVertexBufferCacheKey entry &&
entry._stride == _stride &&
entry._alignment == _alignment;
}
public void SetBuffer(Auto<DisposableBuffer> buffer)
{
_buffer = buffer;
}
public readonly void Dispose()
{
// TODO: Tell pipeline buffer is dirty!
// _renderer.PipelineInternal.DirtyVertexBuffer(_buffer);
}
}
[SupportedOSPlatform("macos")]
struct TopologyConversionCacheKey : ICacheKey
{
// TODO: Patterns
// private readonly IndexBufferPattern _pattern;
private readonly int _indexSize;
// Used to notify the pipeline that bindings have invalidated on dispose.
private readonly MetalRenderer _renderer;
private Auto<DisposableBuffer> _buffer;
public TopologyConversionCacheKey(MetalRenderer renderer, /*IndexBufferPattern pattern, */int indexSize)
{
_renderer = renderer;
// _pattern = pattern;
_indexSize = indexSize;
_buffer = null;
}
public readonly bool KeyEqual(ICacheKey other)
{
return other is TopologyConversionCacheKey entry &&
// entry._pattern == _pattern &&
entry._indexSize == _indexSize;
}
public void SetBuffer(Auto<DisposableBuffer> buffer)
{
_buffer = buffer;
}
public readonly void Dispose()
{
// TODO: Tell pipeline buffer is dirty!
// _renderer.PipelineInternal.DirtyVertexBuffer(_buffer);
}
}
// [SupportedOSPlatform("macos")]
// struct TopologyConversionCacheKey : ICacheKey
// {
// // TODO: Patterns
// // private readonly IndexBufferPattern _pattern;
// private readonly int _indexSize;
//
// // Used to notify the pipeline that bindings have invalidated on dispose.
// // private readonly MetalRenderer _renderer;
// // private Auto<DisposableBuffer> _buffer;
//
// public TopologyConversionCacheKey(MetalRenderer renderer, /*IndexBufferPattern pattern, */int indexSize)
// {
// // _renderer = renderer;
// // _pattern = pattern;
// _indexSize = indexSize;
// // _buffer = null;
// }
//
// public readonly bool KeyEqual(ICacheKey other)
// {
// return other is TopologyConversionCacheKey entry &&
// // entry._pattern == _pattern &&
// entry._indexSize == _indexSize;
// }
//
// public void SetBuffer(Auto<DisposableBuffer> buffer)
// {
// // _buffer = buffer;
// }
//
// public readonly void Dispose()
// {
// // TODO: Tell pipeline buffer is dirty!
// // _renderer.PipelineInternal.DirtyVertexBuffer(_buffer);
// }
// }
[SupportedOSPlatform("macos")]
readonly struct Dependency
@ -141,8 +141,8 @@ namespace Ryujinx.Graphics.Metal
{
private struct Entry
{
public ICacheKey Key;
public T Value;
public readonly ICacheKey Key;
public readonly T Value;
public List<Dependency> DependencyList;
public Entry(ICacheKey key, T value)

View File

@ -52,7 +52,7 @@ namespace Ryujinx.Graphics.Metal
}
}
public void Dispose()
public readonly void Dispose()
{
// State
@ -79,7 +79,7 @@ namespace Ryujinx.Graphics.Metal
};
}
public void RestorePredrawState(PredrawState state)
public readonly void RestorePredrawState(PredrawState state)
{
_currentState.CullMode = state.CullMode;
_currentState.DepthStencilUid = state.DepthStencilUid;
@ -89,12 +89,12 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty |= DirtyFlags.CullMode | DirtyFlags.DepthStencil | DirtyFlags.Viewports;
}
public void SetClearLoadAction(bool clear)
public readonly void SetClearLoadAction(bool clear)
{
_currentState.ClearLoadAction = clear;
}
public MTLRenderCommandEncoder CreateRenderCommandEncoder()
public readonly MTLRenderCommandEncoder CreateRenderCommandEncoder()
{
// Initialise Pass & State
var renderPassDescriptor = new MTLRenderPassDescriptor();
@ -161,7 +161,7 @@ namespace Ryujinx.Graphics.Metal
return renderCommandEncoder;
}
public MTLComputeCommandEncoder CreateComputeCommandEncoder()
public readonly MTLComputeCommandEncoder CreateComputeCommandEncoder()
{
var descriptor = new MTLComputePassDescriptor();
var computeCommandEncoder = _pipeline.CommandBuffer.ComputeCommandEncoder(descriptor);
@ -246,7 +246,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty &= ~DirtyFlags.RenderAll;
}
public void RebindComputeState(MTLComputeCommandEncoder computeCommandEncoder)
public readonly void RebindComputeState(MTLComputeCommandEncoder computeCommandEncoder)
{
if (_currentState.Dirty.HasFlag(DirtyFlags.ComputePipeline))
{
@ -276,7 +276,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty &= ~DirtyFlags.ComputeAll;
}
private void SetRenderPipelineState(MTLRenderCommandEncoder renderCommandEncoder)
private readonly void SetRenderPipelineState(MTLRenderCommandEncoder renderCommandEncoder)
{
MTLRenderPipelineState pipelineState = _currentState.Pipeline.CreateRenderPipeline(_device, _currentState.RenderProgram);
@ -289,7 +289,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.BlendColor.Alpha);
}
private void SetComputePipelineState(MTLComputeCommandEncoder computeCommandEncoder)
private readonly void SetComputePipelineState(MTLComputeCommandEncoder computeCommandEncoder)
{
if (_currentState.ComputeProgram == null)
{
@ -301,7 +301,7 @@ namespace Ryujinx.Graphics.Metal
computeCommandEncoder.SetComputePipelineState(pipelineState);
}
public void UpdateIndexBuffer(BufferRange buffer, IndexType type)
public readonly void UpdateIndexBuffer(BufferRange buffer, IndexType type)
{
if (buffer.Handle != BufferHandle.Null)
{
@ -320,12 +320,12 @@ namespace Ryujinx.Graphics.Metal
}
}
public void UpdatePrimitiveTopology(PrimitiveTopology topology)
public readonly void UpdatePrimitiveTopology(PrimitiveTopology topology)
{
_currentState.Topology = topology;
}
public void UpdateProgram(IProgram program)
public readonly void UpdateProgram(IProgram program)
{
Program prg = (Program)program;
@ -356,13 +356,13 @@ namespace Ryujinx.Graphics.Metal
}
}
public void UpdateRenderTargets(ITexture[] colors, ITexture depthStencil)
public readonly void UpdateRenderTargets(ITexture[] colors, ITexture depthStencil)
{
_currentState.FramebufferUsingColorWriteMask = false;
UpdateRenderTargetsInternal(colors, depthStencil);
}
public void UpdateRenderTargetColorMasks(ReadOnlySpan<uint> componentMask)
public readonly void UpdateRenderTargetColorMasks(ReadOnlySpan<uint> componentMask)
{
ref var blendState = ref _currentState.Pipeline.Internal.ColorBlendState;
@ -415,7 +415,7 @@ namespace Ryujinx.Graphics.Metal
}
}
private void UpdateRenderTargetsInternal(ITexture[] colors, ITexture depthStencil)
private readonly void UpdateRenderTargetsInternal(ITexture[] colors, ITexture depthStencil)
{
// TBDR GPUs don't work properly if the same attachment is bound to multiple targets,
// due to each attachment being a copy of the real attachment, rather than a direct write.
@ -496,7 +496,7 @@ namespace Ryujinx.Graphics.Metal
}
}
private void MaskOut(ITexture[] colors, ITexture depthStencil)
private readonly void MaskOut(ITexture[] colors, ITexture depthStencil)
{
if (!_currentState.FramebufferUsingColorWriteMask)
{
@ -508,7 +508,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.FramebufferUsingColorWriteMask = true;
}
public void UpdateVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
public readonly void UpdateVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
{
vertexAttribs.CopyTo(_currentState.VertexAttribs);
@ -519,7 +519,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty |= DirtyFlags.RenderPipeline;
}
public void UpdateBlendDescriptors(int index, BlendDescriptor blend)
public readonly void UpdateBlendDescriptors(int index, BlendDescriptor blend)
{
ref var blendState = ref _currentState.Pipeline.Internal.ColorBlendState[index];
@ -577,7 +577,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty |= DirtyFlags.DepthStencil;
}
public void UpdateDepthState(DepthTestDescriptor depthTest)
public readonly void UpdateDepthState(DepthTestDescriptor depthTest)
{
ref DepthStencilUid uid = ref _currentState.DepthStencilUid;
@ -589,7 +589,7 @@ namespace Ryujinx.Graphics.Metal
}
// Inlineable
public void UpdateDepthClamp(bool clamp)
public readonly void UpdateDepthClamp(bool clamp)
{
_currentState.DepthClipMode = clamp ? MTLDepthClipMode.Clamp : MTLDepthClipMode.Clip;
@ -605,7 +605,7 @@ namespace Ryujinx.Graphics.Metal
}
// Inlineable
public void UpdateDepthBias(float depthBias, float slopeScale, float clamp)
public readonly void UpdateDepthBias(float depthBias, float slopeScale, float clamp)
{
_currentState.DepthBias = depthBias;
_currentState.SlopeScale = slopeScale;
@ -683,7 +683,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty |= DirtyFlags.Viewports;
}
public void UpdateVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
public readonly void UpdateVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
{
vertexBuffers.CopyTo(_currentState.VertexBuffers);
@ -694,7 +694,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty |= DirtyFlags.RenderPipeline;
}
public void UpdateUniformBuffers(ReadOnlySpan<BufferAssignment> buffers)
public readonly void UpdateUniformBuffers(ReadOnlySpan<BufferAssignment> buffers)
{
foreach (BufferAssignment assignment in buffers)
{
@ -711,7 +711,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty |= DirtyFlags.Uniforms;
}
public void UpdateStorageBuffers(ReadOnlySpan<BufferAssignment> buffers)
public readonly void UpdateStorageBuffers(ReadOnlySpan<BufferAssignment> buffers)
{
foreach (BufferAssignment assignment in buffers)
{
@ -728,7 +728,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty |= DirtyFlags.Storages;
}
public void UpdateStorageBuffers(int first, ReadOnlySpan<Auto<DisposableBuffer>> buffers)
public readonly void UpdateStorageBuffers(int first, ReadOnlySpan<Auto<DisposableBuffer>> buffers)
{
for (int i = 0; i < buffers.Length; i++)
{
@ -767,7 +767,7 @@ namespace Ryujinx.Graphics.Metal
}
// Inlineable
public void UpdateFrontFace(FrontFace frontFace)
public readonly void UpdateFrontFace(FrontFace frontFace)
{
_currentState.Winding = frontFace.Convert();
@ -782,7 +782,7 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty |= DirtyFlags.FrontFace;
}
private void UpdateStencilRefValue(int frontRef, int backRef)
private readonly void UpdateStencilRefValue(int frontRef, int backRef)
{
_currentState.FrontRefValue = frontRef;
_currentState.BackRefValue = backRef;
@ -797,9 +797,9 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty |= DirtyFlags.StencilRef;
}
public void UpdateTextureAndSampler(ShaderStage stage, ulong binding, TextureBase texture, Sampler sampler)
public readonly void UpdateTextureAndSampler(ShaderStage stage, ulong binding, TextureBase texture, Sampler sampler)
{
if (texture is TextureBuffer textureBuffer)
if (texture is TextureBuffer)
{
// TODO: Texture buffers
}
@ -853,7 +853,7 @@ namespace Ryujinx.Graphics.Metal
}
}
private unsafe void SetViewports(MTLRenderCommandEncoder renderCommandEncoder)
private readonly unsafe void SetViewports(MTLRenderCommandEncoder renderCommandEncoder)
{
if (_currentState.Viewports.Length > 0)
{
@ -864,7 +864,7 @@ namespace Ryujinx.Graphics.Metal
}
}
private void UpdatePipelineVertexState(VertexBufferDescriptor[] bufferDescriptors, VertexAttribDescriptor[] attribDescriptors)
private readonly void UpdatePipelineVertexState(VertexBufferDescriptor[] bufferDescriptors, VertexAttribDescriptor[] attribDescriptors)
{
ref PipelineState pipeline = ref _currentState.Pipeline;
uint indexMask = 0;
@ -941,7 +941,7 @@ namespace Ryujinx.Graphics.Metal
pipeline.VertexBindingDescriptionsCount = Constants.ZeroBufferIndex + 1; // TODO: move this out?
}
private void SetVertexBuffers(MTLRenderCommandEncoder renderCommandEncoder, VertexBufferDescriptor[] bufferDescriptors)
private readonly void SetVertexBuffers(MTLRenderCommandEncoder renderCommandEncoder, VertexBufferDescriptor[] bufferDescriptors)
{
for (int i = 0; i < bufferDescriptors.Length; i++)
{
@ -974,7 +974,7 @@ namespace Ryujinx.Graphics.Metal
renderCommandEncoder.SetVertexBuffer(zeroMtlBuffer, 0, Constants.ZeroBufferIndex);
}
private void UpdateAndBind(MTLRenderCommandEncoder renderCommandEncoder, Program program, int setIndex)
private readonly void UpdateAndBind(MTLRenderCommandEncoder renderCommandEncoder, Program program, int setIndex)
{
var bindingSegments = program.BindingSegments[setIndex];
@ -1193,7 +1193,7 @@ namespace Ryujinx.Graphics.Metal
}
}
private void UpdateAndBind(MTLComputeCommandEncoder computeCommandEncoder, Program program, int setIndex)
private readonly void UpdateAndBind(MTLComputeCommandEncoder computeCommandEncoder, Program program, int setIndex)
{
var bindingSegments = program.BindingSegments[setIndex];

View File

@ -67,7 +67,7 @@ namespace Ryujinx.Graphics.Metal
_pipeline.InitEncoderStateManager(BufferManager);
BackgroundResources = new BackgroundResources(this, _pipeline);
BackgroundResources = new BackgroundResources(this);
HelperShader = new HelperShader(_device, this, _pipeline);
SyncManager = new SyncManager(this);
}

View File

@ -8,14 +8,12 @@ namespace Ryujinx.Graphics.Metal
internal class PersistentFlushBuffer : IDisposable
{
private readonly MetalRenderer _renderer;
private readonly Pipeline _pipeline;
private BufferHolder _flushStorage;
public PersistentFlushBuffer(MetalRenderer renderer, Pipeline pipeline)
public PersistentFlushBuffer(MetalRenderer renderer)
{
_renderer = renderer;
_pipeline = pipeline;
}
private BufferHolder ResizeIfNeeded(int size)

View File

@ -31,7 +31,6 @@ namespace Ryujinx.Graphics.Metal
private int _freeSize;
private readonly MetalRenderer _renderer;
private readonly Pipeline _pipeline;
private readonly BufferHolder _buffer;
private readonly int _resourceAlignment;
@ -52,10 +51,9 @@ namespace Ryujinx.Graphics.Metal
private readonly Queue<PendingCopy> _pendingCopies;
public StagingBuffer(MetalRenderer renderer, Pipeline pipeline, BufferManager bufferManager)
public StagingBuffer(MetalRenderer renderer, BufferManager bufferManager)
{
_renderer = renderer;
_pipeline = pipeline;
Handle = bufferManager.CreateWithHandle(BufferSize, out _buffer);
_pendingCopies = new Queue<PendingCopy>();

View File

@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.Metal
class Texture : TextureBase, ITexture
{
private MTLTexture _identitySwizzleHandle;
private bool _identityIsDifferent;
private readonly bool _identityIsDifferent;
public Texture(MTLDevice device, MetalRenderer renderer, Pipeline pipeline, TextureCreateInfo info) : base(device, renderer, pipeline, info)
{
@ -40,15 +40,15 @@ namespace Ryujinx.Graphics.Metal
MTLTextureSwizzleChannels swizzle = GetSwizzle(info, descriptor.PixelFormat);
_identitySwizzleHandle = _device.NewTexture(descriptor);
_identitySwizzleHandle = Device.NewTexture(descriptor);
if (SwizzleIsIdentity(swizzle))
{
_mtlTexture = _identitySwizzleHandle;
MtlTexture = _identitySwizzleHandle;
}
else
{
_mtlTexture = CreateDefaultView(_identitySwizzleHandle, swizzle, descriptor);
MtlTexture = CreateDefaultView(_identitySwizzleHandle, swizzle, descriptor);
_identityIsDifferent = true;
}
@ -73,11 +73,11 @@ namespace Ryujinx.Graphics.Metal
if (SwizzleIsIdentity(swizzle))
{
_mtlTexture = _identitySwizzleHandle;
MtlTexture = _identitySwizzleHandle;
}
else
{
_mtlTexture = sourceTexture.NewTextureView(pixelFormat, textureType, levels, slices, swizzle);
MtlTexture = sourceTexture.NewTextureView(pixelFormat, textureType, levels, slices, swizzle);
_identityIsDifferent = true;
}
@ -146,7 +146,7 @@ namespace Ryujinx.Graphics.Metal
public void CopyTo(ITexture destination, int firstLayer, int firstLevel)
{
CommandBufferScoped cbs = _pipeline.Cbs;
CommandBufferScoped cbs = Pipeline.Cbs;
TextureBase src = this;
TextureBase dst = (TextureBase)destination;
@ -156,30 +156,30 @@ namespace Ryujinx.Graphics.Metal
if (!dst.Info.Target.IsMultisample() && Info.Target.IsMultisample())
{
//int layers = Math.Min(Info.GetLayers(), dst.Info.GetLayers() - firstLayer);
// int layers = Math.Min(Info.GetLayers(), dst.Info.GetLayers() - firstLayer);
//_gd.HelperShader.CopyMSToNonMS(_gd, cbs, src, dst, 0, firstLayer, layers);
// _gd.HelperShader.CopyMSToNonMS(_gd, cbs, src, dst, 0, firstLayer, layers);
}
else if (dst.Info.Target.IsMultisample() && !Info.Target.IsMultisample())
{
//int layers = Math.Min(Info.GetLayers(), dst.Info.GetLayers() - firstLayer);
// int layers = Math.Min(Info.GetLayers(), dst.Info.GetLayers() - firstLayer);
//_gd.HelperShader.CopyNonMSToMS(_gd, cbs, src, dst, 0, firstLayer, layers);
// _gd.HelperShader.CopyNonMSToMS(_gd, cbs, src, dst, 0, firstLayer, layers);
}
else if (dst.Info.BytesPerPixel != Info.BytesPerPixel)
{
//int layers = Math.Min(Info.GetLayers(), dst.Info.GetLayers() - firstLayer);
//int levels = Math.Min(Info.Levels, dst.Info.Levels - firstLevel);
// int layers = Math.Min(Info.GetLayers(), dst.Info.GetLayers() - firstLayer);
// int levels = Math.Min(Info.Levels, dst.Info.Levels - firstLevel);
//_gd.HelperShader.CopyIncompatibleFormats(_gd, cbs, src, dst, 0, firstLayer, 0, firstLevel, layers, levels);
// _gd.HelperShader.CopyIncompatibleFormats(_gd, cbs, src, dst, 0, firstLayer, 0, firstLevel, layers, levels);
}
else if (src.Info.Format.IsDepthOrStencil() != dst.Info.Format.IsDepthOrStencil())
{
int layers = Math.Min(Info.GetLayers(), dst.Info.GetLayers() - firstLayer);
int levels = Math.Min(Info.Levels, dst.Info.Levels - firstLevel);
// int layers = Math.Min(Info.GetLayers(), dst.Info.GetLayers() - firstLayer);
// int levels = Math.Min(Info.Levels, dst.Info.Levels - firstLevel);
// TODO: depth copy?
//_gd.HelperShader.CopyColor(_gd, cbs, src, dst, 0, firstLayer, 0, FirstLevel, layers, levels);
// _gd.HelperShader.CopyColor(_gd, cbs, src, dst, 0, firstLayer, 0, FirstLevel, layers, levels);
}
else
{
@ -198,7 +198,7 @@ namespace Ryujinx.Graphics.Metal
public void CopyTo(ITexture destination, int srcLayer, int dstLayer, int srcLevel, int dstLevel)
{
CommandBufferScoped cbs = _pipeline.Cbs;
CommandBufferScoped cbs = Pipeline.Cbs;
TextureBase src = this;
TextureBase dst = (TextureBase)destination;
@ -208,19 +208,19 @@ namespace Ryujinx.Graphics.Metal
if (!dst.Info.Target.IsMultisample() && Info.Target.IsMultisample())
{
//_gd.HelperShader.CopyMSToNonMS(_gd, cbs, src, dst, srcLayer, dstLayer, 1);
// _gd.HelperShader.CopyMSToNonMS(_gd, cbs, src, dst, srcLayer, dstLayer, 1);
}
else if (dst.Info.Target.IsMultisample() && !Info.Target.IsMultisample())
{
//_gd.HelperShader.CopyNonMSToMS(_gd, cbs, src, dst, srcLayer, dstLayer, 1);
// _gd.HelperShader.CopyNonMSToMS(_gd, cbs, src, dst, srcLayer, dstLayer, 1);
}
else if (dst.Info.BytesPerPixel != Info.BytesPerPixel)
{
//_gd.HelperShader.CopyIncompatibleFormats(_gd, cbs, src, dst, srcLayer, dstLayer, srcLevel, dstLevel, 1, 1);
// _gd.HelperShader.CopyIncompatibleFormats(_gd, cbs, src, dst, srcLayer, dstLayer, srcLevel, dstLevel, 1, 1);
}
else if (src.Info.Format.IsDepthOrStencil() != dst.Info.Format.IsDepthOrStencil())
{
//_gd.HelperShader.CopyColor(_gd, cbs, src, dst, srcLayer, dstLayer, srcLevel, dstLevel, 1, 1);
// _gd.HelperShader.CopyColor(_gd, cbs, src, dst, srcLayer, dstLayer, srcLevel, dstLevel, 1, 1);
}
else
{
@ -241,7 +241,7 @@ namespace Ryujinx.Graphics.Metal
public void CopyTo(ITexture destination, Extents2D srcRegion, Extents2D dstRegion, bool linearFilter)
{
if (!_renderer.CommandBufferPool.OwnedByCurrentThread)
if (!Renderer.CommandBufferPool.OwnedByCurrentThread)
{
Logger.Warning?.PrintMsg(LogClass.Gpu, "Metal doesn't currently support scaled blit on background thread.");
@ -256,29 +256,29 @@ namespace Ryujinx.Graphics.Metal
Console.WriteLine("shit");
}
_pipeline.Blit(this, destination, srcRegion, dstRegion, isDepthOrStencil, linearFilter);
Pipeline.Blit(this, destination, srcRegion, dstRegion, isDepthOrStencil, linearFilter);
}
public void CopyTo(BufferRange range, int layer, int level, int stride)
{
var cbs = _pipeline.Cbs;
var cbs = Pipeline.Cbs;
int outSize = Info.GetMipSize(level);
int hostSize = GetBufferDataLength(outSize);
int offset = range.Offset;
var autoBuffer = _renderer.BufferManager.GetBuffer(range.Handle, true);
var autoBuffer = Renderer.BufferManager.GetBuffer(range.Handle, true);
var mtlBuffer = autoBuffer.Get(cbs, range.Offset, outSize).Value;
// TODO: D32S8 conversion via temp copy holder
CopyFromOrToBuffer(cbs, mtlBuffer, _mtlTexture, hostSize, true, layer, level, 1, 1, singleSlice: true, offset: offset, stride: stride);
CopyFromOrToBuffer(cbs, mtlBuffer, MtlTexture, hostSize, true, layer, level, 1, 1, singleSlice: true, offset: offset, stride: stride);
}
public ITexture CreateView(TextureCreateInfo info, int firstLayer, int firstLevel)
{
return new Texture(_device, _renderer, _pipeline, info, _identitySwizzleHandle, firstLayer, firstLevel);
return new Texture(Device, Renderer, Pipeline, info, _identitySwizzleHandle, firstLayer, firstLevel);
}
private int GetBufferDataLength(int size)
@ -415,13 +415,13 @@ namespace Ryujinx.Graphics.Metal
public PinnedSpan<byte> GetData()
{
BackgroundResource resources = _renderer.BackgroundResources.Get();
BackgroundResource resources = Renderer.BackgroundResources.Get();
if (_renderer.CommandBufferPool.OwnedByCurrentThread)
if (Renderer.CommandBufferPool.OwnedByCurrentThread)
{
_renderer.FlushAllCommands();
Renderer.FlushAllCommands();
return PinnedSpan<byte>.UnsafeFromSpan(GetData(_renderer.CommandBufferPool, resources.GetFlushBuffer()));
return PinnedSpan<byte>.UnsafeFromSpan(GetData(Renderer.CommandBufferPool, resources.GetFlushBuffer()));
}
return PinnedSpan<byte>.UnsafeFromSpan(GetData(resources.GetPool(), resources.GetFlushBuffer()));
@ -429,13 +429,13 @@ namespace Ryujinx.Graphics.Metal
public PinnedSpan<byte> GetData(int layer, int level)
{
BackgroundResource resources = _renderer.BackgroundResources.Get();
BackgroundResource resources = Renderer.BackgroundResources.Get();
if (_renderer.CommandBufferPool.OwnedByCurrentThread)
if (Renderer.CommandBufferPool.OwnedByCurrentThread)
{
_renderer.FlushAllCommands();
Renderer.FlushAllCommands();
return PinnedSpan<byte>.UnsafeFromSpan(GetData(_renderer.CommandBufferPool, resources.GetFlushBuffer(), layer, level));
return PinnedSpan<byte>.UnsafeFromSpan(GetData(Renderer.CommandBufferPool, resources.GetFlushBuffer(), layer, level));
}
return PinnedSpan<byte>.UnsafeFromSpan(GetData(resources.GetPool(), resources.GetFlushBuffer(), layer, level));
@ -443,13 +443,13 @@ namespace Ryujinx.Graphics.Metal
public void SetData(IMemoryOwner<byte> data)
{
var blitCommandEncoder = _pipeline.GetOrCreateBlitEncoder();
var blitCommandEncoder = Pipeline.GetOrCreateBlitEncoder();
var dataSpan = data.Memory.Span;
var buffer = _renderer.BufferManager.Create(dataSpan.Length);
var buffer = Renderer.BufferManager.Create(dataSpan.Length);
buffer.SetDataUnchecked(0, dataSpan);
var mtlBuffer = buffer.GetBuffer(false).Get(_pipeline.Cbs).Value;
var mtlBuffer = buffer.GetBuffer(false).Get(Pipeline.Cbs).Value;
int width = Info.Width;
int height = Info.Height;
@ -478,7 +478,7 @@ namespace Ryujinx.Graphics.Metal
(ulong)Info.GetMipStride(level),
(ulong)mipSize,
new MTLSize { width = (ulong)width, height = (ulong)height, depth = is3D ? (ulong)depth : 1 },
_mtlTexture,
MtlTexture,
(ulong)layer,
(ulong)level,
new MTLOrigin()
@ -504,11 +504,11 @@ namespace Ryujinx.Graphics.Metal
{
int bufferDataLength = GetBufferDataLength(data.Length);
using var bufferHolder = _renderer.BufferManager.Create(bufferDataLength);
using var bufferHolder = Renderer.BufferManager.Create(bufferDataLength);
// TODO: loadInline logic
var cbs = _pipeline.Cbs;
var cbs = Pipeline.Cbs;
CopyDataToBuffer(bufferHolder.GetDataStorage(0, bufferDataLength), data);
@ -527,20 +527,20 @@ namespace Ryujinx.Graphics.Metal
public void SetData(IMemoryOwner<byte> data, int layer, int level, Rectangle<int> region)
{
var blitCommandEncoder = _pipeline.GetOrCreateBlitEncoder();
var blitCommandEncoder = Pipeline.GetOrCreateBlitEncoder();
ulong bytesPerRow = (ulong)Info.GetMipStride(level);
ulong bytesPerImage = 0;
if (_mtlTexture.TextureType == MTLTextureType.Type3D)
if (MtlTexture.TextureType == MTLTextureType.Type3D)
{
bytesPerImage = bytesPerRow * (ulong)Info.Height;
}
var dataSpan = data.Memory.Span;
var buffer = _renderer.BufferManager.Create(dataSpan.Length);
var buffer = Renderer.BufferManager.Create(dataSpan.Length);
buffer.SetDataUnchecked(0, dataSpan);
var mtlBuffer = buffer.GetBuffer(false).Get(_pipeline.Cbs).Value;
var mtlBuffer = buffer.GetBuffer(false).Get(Pipeline.Cbs).Value;
blitCommandEncoder.CopyFromBuffer(
mtlBuffer,
@ -548,7 +548,7 @@ namespace Ryujinx.Graphics.Metal
bytesPerRow,
bytesPerImage,
new MTLSize { width = (ulong)region.Width, height = (ulong)region.Height, depth = 1 },
_mtlTexture,
MtlTexture,
(ulong)layer,
(ulong)level,
new MTLOrigin { x = (ulong)region.X, y = (ulong)region.Y }

View File

@ -10,14 +10,13 @@ namespace Ryujinx.Graphics.Metal
{
private bool _disposed;
protected readonly TextureCreateInfo _info;
protected readonly Pipeline _pipeline;
protected readonly MTLDevice _device;
protected readonly MetalRenderer _renderer;
protected readonly Pipeline Pipeline;
protected readonly MTLDevice Device;
protected readonly MetalRenderer Renderer;
protected MTLTexture _mtlTexture;
protected MTLTexture MtlTexture;
public TextureCreateInfo Info => _info;
public readonly TextureCreateInfo Info;
public int Width => Info.Width;
public int Height => Info.Height;
public int Depth => Info.Depth;
@ -28,10 +27,10 @@ namespace Ryujinx.Graphics.Metal
public TextureBase(MTLDevice device, MetalRenderer renderer, Pipeline pipeline, TextureCreateInfo info)
{
_device = device;
_renderer = renderer;
_pipeline = pipeline;
_info = info;
Device = device;
Renderer = renderer;
Pipeline = pipeline;
Info = info;
}
public MTLTexture GetHandle()
@ -41,7 +40,7 @@ namespace Ryujinx.Graphics.Metal
return new MTLTexture(IntPtr.Zero);
}
return _mtlTexture;
return MtlTexture;
}
public virtual void Release()
@ -51,9 +50,9 @@ namespace Ryujinx.Graphics.Metal
public void Dispose()
{
if (_mtlTexture != IntPtr.Zero)
if (MtlTexture != IntPtr.Zero)
{
_mtlTexture.Dispose();
MtlTexture.Dispose();
}
_disposed = true;
}

View File

@ -37,23 +37,23 @@ namespace Ryujinx.Graphics.Metal
// Find the parent buffer, and try to build a texture from it.
// TODO: texture uses should register read/write usage on the assigned buffer.
Auto<DisposableBuffer> bufferAuto = _renderer.BufferManager.GetBuffer(_bufferHandle, false);
Auto<DisposableBuffer> bufferAuto = Renderer.BufferManager.GetBuffer(_bufferHandle, false);
if (_mtlTexture.NativePtr != 0)
if (MtlTexture.NativePtr != 0)
{
_mtlTexture.Dispose();
MtlTexture.Dispose();
}
if (bufferAuto == null)
{
_mtlTexture = default;
MtlTexture = default;
}
else
{
DisposableBuffer buffer = bufferAuto.Get(_pipeline.Cbs, _offset, _size);
DisposableBuffer buffer = bufferAuto.Get(Pipeline.Cbs, _offset, _size);
_descriptor.Width = (uint)(_size / Info.BytesPerPixel);
_mtlTexture = buffer.Value.NewTexture(_descriptor, (ulong)_offset, (ulong)_size);
MtlTexture = buffer.Value.NewTexture(_descriptor, (ulong)_offset, (ulong)_size);
}
}
@ -79,7 +79,7 @@ namespace Ryujinx.Graphics.Metal
public PinnedSpan<byte> GetData()
{
return _renderer.GetBufferData(_bufferHandle, _offset, _size);
return Renderer.GetBufferData(_bufferHandle, _offset, _size);
}
public PinnedSpan<byte> GetData(int layer, int level)
@ -94,7 +94,7 @@ namespace Ryujinx.Graphics.Metal
public void SetData(IMemoryOwner<byte> data)
{
_renderer.SetBufferData(_bufferHandle, _offset, data.Memory.Span);
Renderer.SetBufferData(_bufferHandle, _offset, data.Memory.Span);
data.Dispose();
}
@ -113,7 +113,7 @@ namespace Ryujinx.Graphics.Metal
if (_bufferHandle == buffer.Handle &&
_offset == buffer.Offset &&
_size == buffer.Size &&
_bufferCount == _renderer.BufferManager.BufferCount)
_bufferCount == Renderer.BufferManager.BufferCount)
{
return;
}
@ -121,7 +121,7 @@ namespace Ryujinx.Graphics.Metal
_bufferHandle = buffer.Handle;
_offset = buffer.Offset;
_size = buffer.Size;
_bufferCount = _renderer.BufferManager.BufferCount;
_bufferCount = Renderer.BufferManager.BufferCount;
RebuildStorage();
}