1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-19 00:22:02 +00:00

Cleanup + Format

This commit is contained in:
Isaac Marovitz 2024-05-23 14:08:34 -04:00 committed by Isaac Marovitz
parent 937d84018e
commit 997393bc65
10 changed files with 71 additions and 93 deletions

View file

@ -1,9 +1,4 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using SharpMetal.Foundation;
using SharpMetal.Metal;
using System;
using System.Collections.Generic;
using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Metal
@ -31,37 +26,40 @@ namespace Ryujinx.Graphics.Metal
{
private readonly MTLDevice _device;
public DepthStencilCache(MTLDevice device) {
public DepthStencilCache(MTLDevice device)
{
_device = device;
}
protected override DepthStencilHash GetHash(MTLDepthStencilDescriptor descriptor) {
var hash = new DepthStencilHash();
// Front face
hash.FrontFace = new DepthStencilHash.StencilHash {
StencilFailureOperation = descriptor.FrontFaceStencil.StencilFailureOperation,
DepthFailureOperation = descriptor.FrontFaceStencil.DepthFailureOperation,
DepthStencilPassOperation = descriptor.FrontFaceStencil.DepthStencilPassOperation,
StencilCompareFunction = descriptor.FrontFaceStencil.StencilCompareFunction,
ReadMask = descriptor.FrontFaceStencil.ReadMask,
WriteMask = descriptor.FrontFaceStencil.WriteMask
protected override DepthStencilHash GetHash(MTLDepthStencilDescriptor descriptor)
{
var hash = new DepthStencilHash
{
// Front face
FrontFace = new DepthStencilHash.StencilHash
{
StencilFailureOperation = descriptor.FrontFaceStencil.StencilFailureOperation,
DepthFailureOperation = descriptor.FrontFaceStencil.DepthFailureOperation,
DepthStencilPassOperation = descriptor.FrontFaceStencil.DepthStencilPassOperation,
StencilCompareFunction = descriptor.FrontFaceStencil.StencilCompareFunction,
ReadMask = descriptor.FrontFaceStencil.ReadMask,
WriteMask = descriptor.FrontFaceStencil.WriteMask
},
// Back face
BackFace = new DepthStencilHash.StencilHash
{
StencilFailureOperation = descriptor.BackFaceStencil.StencilFailureOperation,
DepthFailureOperation = descriptor.BackFaceStencil.DepthFailureOperation,
DepthStencilPassOperation = descriptor.BackFaceStencil.DepthStencilPassOperation,
StencilCompareFunction = descriptor.BackFaceStencil.StencilCompareFunction,
ReadMask = descriptor.BackFaceStencil.ReadMask,
WriteMask = descriptor.BackFaceStencil.WriteMask
},
// Depth
DepthCompareFunction = descriptor.DepthCompareFunction,
DepthWriteEnabled = descriptor.DepthWriteEnabled
};
// Back face
hash.BackFace = new DepthStencilHash.StencilHash {
StencilFailureOperation = descriptor.BackFaceStencil.StencilFailureOperation,
DepthFailureOperation = descriptor.BackFaceStencil.DepthFailureOperation,
DepthStencilPassOperation = descriptor.BackFaceStencil.DepthStencilPassOperation,
StencilCompareFunction = descriptor.BackFaceStencil.StencilCompareFunction,
ReadMask = descriptor.BackFaceStencil.ReadMask,
WriteMask = descriptor.BackFaceStencil.WriteMask
};
// Depth
hash.DepthCompareFunction = descriptor.DepthCompareFunction;
hash.DepthWriteEnabled = descriptor.DepthWriteEnabled;
return hash;
}

View file

@ -12,7 +12,8 @@ namespace Ryujinx.Graphics.Metal
public DirtyFlags() { }
public void MarkAll() {
public void MarkAll()
{
Pipeline = true;
DepthStencil = true;
}

View file

@ -12,11 +12,10 @@ namespace Ryujinx.Graphics.Metal
[SupportedOSPlatform("macos")]
struct EncoderStateManager
{
private readonly MTLDevice _device;
private readonly Pipeline _pipeline;
private readonly RenderPipelineCache RenderPipelineCache;
private readonly DepthStencilCache DepthStencilCache;
private readonly RenderPipelineCache _renderPipelineCache;
private readonly DepthStencilCache _depthStencilCache;
private EncoderState _currentState = new();
private EncoderState _backState = new();
@ -30,10 +29,9 @@ namespace Ryujinx.Graphics.Metal
public EncoderStateManager(MTLDevice device, Pipeline pipeline)
{
_device = device;
_pipeline = pipeline;
RenderPipelineCache = new(device);
DepthStencilCache = new(device);
_renderPipelineCache = new(device);
_depthStencilCache = new(device);
}
public void SwapStates()
@ -139,7 +137,8 @@ namespace Ryujinx.Graphics.Metal
_currentState.Dirty.Clear();
}
private void SetPipelineState(MTLRenderCommandEncoder renderCommandEncoder) {
private readonly void SetPipelineState(MTLRenderCommandEncoder renderCommandEncoder)
{
var renderPipelineDescriptor = new MTLRenderPipelineDescriptor();
for (int i = 0; i < Constants.MaxColorAttachments; i++)
@ -209,7 +208,7 @@ namespace Ryujinx.Graphics.Metal
renderPipelineDescriptor.FragmentFunction = _currentState.FragmentFunction.Value;
}
var pipelineState = RenderPipelineCache.GetOrCreate(renderPipelineDescriptor);
var pipelineState = _renderPipelineCache.GetOrCreate(renderPipelineDescriptor);
renderCommandEncoder.SetRenderPipelineState(pipelineState);
@ -330,7 +329,7 @@ namespace Ryujinx.Graphics.Metal
descriptor.FrontFaceStencil = _currentState.FrontFaceStencil;
}
_currentState.DepthStencilState = DepthStencilCache.GetOrCreate(descriptor);
_currentState.DepthStencilState = _depthStencilCache.GetOrCreate(descriptor);
// Mark dirty
_currentState.Dirty.DepthStencil = true;
@ -354,7 +353,7 @@ namespace Ryujinx.Graphics.Metal
descriptor.FrontFaceStencil = _currentState.FrontFaceStencil;
}
_currentState.DepthStencilState = DepthStencilCache.GetOrCreate(descriptor);
_currentState.DepthStencilState = _depthStencilCache.GetOrCreate(descriptor);
// Mark dirty
_currentState.Dirty.DepthStencil = true;
@ -556,7 +555,7 @@ namespace Ryujinx.Graphics.Metal
}
}
private void SetDepthStencilState(MTLRenderCommandEncoder renderCommandEncoder)
private readonly void SetDepthStencilState(MTLRenderCommandEncoder renderCommandEncoder)
{
if (_currentState.DepthStencilState != null)
{
@ -564,7 +563,7 @@ namespace Ryujinx.Graphics.Metal
}
}
private void SetDepthClamp(MTLRenderCommandEncoder renderCommandEncoder)
private readonly void SetDepthClamp(MTLRenderCommandEncoder renderCommandEncoder)
{
renderCommandEncoder.SetDepthClipMode(_currentState.DepthClipMode);
}
@ -591,7 +590,7 @@ namespace Ryujinx.Graphics.Metal
}
}
private MTLVertexDescriptor BuildVertexDescriptor(VertexBufferDescriptor[] bufferDescriptors, VertexAttribDescriptor[] attribDescriptors)
private readonly MTLVertexDescriptor BuildVertexDescriptor(VertexBufferDescriptor[] bufferDescriptors, VertexAttribDescriptor[] attribDescriptors)
{
var vertexDescriptor = new MTLVertexDescriptor();
uint indexMask = 0;
@ -635,7 +634,7 @@ namespace Ryujinx.Graphics.Metal
SetBuffers(renderCommandEncoder, buffers);
}
private void SetBuffers(MTLRenderCommandEncoder renderCommandEncoder, List<BufferInfo> buffers, bool fragment = false)
private readonly void SetBuffers(MTLRenderCommandEncoder renderCommandEncoder, List<BufferInfo> buffers, bool fragment = false)
{
foreach (var buffer in buffers)
{
@ -648,17 +647,17 @@ namespace Ryujinx.Graphics.Metal
}
}
private void SetCullMode(MTLRenderCommandEncoder renderCommandEncoder)
private readonly void SetCullMode(MTLRenderCommandEncoder renderCommandEncoder)
{
renderCommandEncoder.SetCullMode(_currentState.CullMode);
}
private void SetFrontFace(MTLRenderCommandEncoder renderCommandEncoder)
private readonly void SetFrontFace(MTLRenderCommandEncoder renderCommandEncoder)
{
renderCommandEncoder.SetFrontFacingWinding(_currentState.Winding);
}
private void SetTextureAndSampler(MTLRenderCommandEncoder renderCommandEncoder, ShaderStage stage, Dictionary<ulong, MTLTexture> textures, Dictionary<ulong, MTLSamplerState> samplers)
private static void SetTextureAndSampler(MTLRenderCommandEncoder renderCommandEncoder, ShaderStage stage, Dictionary<ulong, MTLTexture> textures, Dictionary<ulong, MTLSamplerState> samplers)
{
foreach (var texture in textures)
{

View file

@ -208,7 +208,7 @@ namespace Ryujinx.Graphics.Metal
Format.R16G16B16A16Float => MTLVertexFormat.Half4,
Format.R32Float => MTLVertexFormat.Float,
Format.R32G32Float => MTLVertexFormat.Float2,
Format.R32G32B32Float=> MTLVertexFormat.Float3,
Format.R32G32B32Float => MTLVertexFormat.Float3,
Format.R11G11B10Float => MTLVertexFormat.FloatRG11B10,
Format.R32G32B32A32Float => MTLVertexFormat.Float4,
Format.R8Uint => MTLVertexFormat.UChar,

View file

@ -10,13 +10,6 @@ using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Metal
{
enum ComponentType
{
Float,
SignedInteger,
UnsignedInteger,
}
[SupportedOSPlatform("macos")]
class HelperShader : IDisposable
{

View file

@ -5,7 +5,6 @@ using SharpMetal.Foundation;
using SharpMetal.Metal;
using SharpMetal.QuartzCore;
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;

View file

@ -1,9 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using SharpMetal.Foundation;
using SharpMetal.Metal;
using System;
using System.Collections.Generic;
using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Metal
@ -72,16 +70,24 @@ namespace Ryujinx.Graphics.Metal
{
private readonly MTLDevice _device;
public RenderPipelineCache(MTLDevice device) {
public RenderPipelineCache(MTLDevice device)
{
_device = device;
}
protected override RenderPipelineHash GetHash(MTLRenderPipelineDescriptor descriptor) {
var hash = new RenderPipelineHash();
// Functions
hash.VertexFunction = descriptor.VertexFunction;
hash.FragmentFunction = descriptor.FragmentFunction;
protected override RenderPipelineHash GetHash(MTLRenderPipelineDescriptor descriptor)
{
var hash = new RenderPipelineHash
{
// Functions
VertexFunction = descriptor.VertexFunction,
FragmentFunction = descriptor.FragmentFunction,
DepthStencilAttachment = new RenderPipelineHash.DepthStencilAttachmentHash
{
DepthPixelFormat = descriptor.DepthAttachmentPixelFormat,
StencilPixelFormat = descriptor.StencilAttachmentPixelFormat
},
};
// Color Attachments
for (int i = 0; i < Constants.MaxColorAttachments; i++)
@ -100,13 +106,6 @@ namespace Ryujinx.Graphics.Metal
};
}
// Depth stencil attachment
hash.DepthStencilAttachment = new RenderPipelineHash.DepthStencilAttachmentHash
{
DepthPixelFormat = descriptor.DepthAttachmentPixelFormat,
StencilPixelFormat = descriptor.StencilAttachmentPixelFormat
};
// Vertex descriptor
hash.VertexDescriptor = new RenderPipelineHash.VertexDescriptorHash();

View file

@ -1,33 +1,28 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using SharpMetal.Foundation;
using SharpMetal.Metal;
using System;
using System.Collections.Generic;
using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Metal
{
[SupportedOSPlatform("macos")]
public abstract class StateCache<T, DescriptorT, HashT>
public abstract class StateCache<T, TDescriptor, THash>
{
private Dictionary<HashT, T> Cache = new();
private readonly Dictionary<THash, T> _cache = new();
protected abstract HashT GetHash(DescriptorT descriptor);
protected abstract THash GetHash(TDescriptor descriptor);
protected abstract T CreateValue(DescriptorT descriptor);
protected abstract T CreateValue(TDescriptor descriptor);
public T GetOrCreate(DescriptorT descriptor)
public T GetOrCreate(TDescriptor descriptor)
{
var hash = GetHash(descriptor);
if (Cache.TryGetValue(hash, out T value))
if (_cache.TryGetValue(hash, out T value))
{
return value;
}
else
{
var newValue = CreateValue(descriptor);
Cache.Add(hash, newValue);
_cache.Add(hash, newValue);
return newValue;
}

View file

@ -58,7 +58,7 @@ namespace Ryujinx.Graphics.Metal
public void Dispose()
{
_metalLayer.Dispose();
}
}
}

View file

@ -246,12 +246,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
return resourceDefinitions.Textures[textOp.Binding].Name;
}
// TODO: Verify that this is valid in MSL
private static string GetMask(int index)
{
return $".{"rgba".AsSpan(index, 1)}";
}
private static string GetMaskMultiDest(int mask)
{
string swizzle = ".";