mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-12-27 02:53:04 +00:00
Cleanup + Format
This commit is contained in:
parent
937d84018e
commit
997393bc65
10 changed files with 71 additions and 93 deletions
|
@ -1,9 +1,4 @@
|
||||||
using Ryujinx.Common.Logging;
|
|
||||||
using Ryujinx.Graphics.GAL;
|
|
||||||
using SharpMetal.Foundation;
|
|
||||||
using SharpMetal.Metal;
|
using SharpMetal.Metal;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
|
@ -31,37 +26,40 @@ namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
private readonly MTLDevice _device;
|
private readonly MTLDevice _device;
|
||||||
|
|
||||||
public DepthStencilCache(MTLDevice device) {
|
public DepthStencilCache(MTLDevice device)
|
||||||
|
{
|
||||||
_device = device;
|
_device = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DepthStencilHash GetHash(MTLDepthStencilDescriptor descriptor) {
|
protected override DepthStencilHash GetHash(MTLDepthStencilDescriptor descriptor)
|
||||||
var hash = new DepthStencilHash();
|
{
|
||||||
|
var hash = new DepthStencilHash
|
||||||
// Front face
|
{
|
||||||
hash.FrontFace = new DepthStencilHash.StencilHash {
|
// Front face
|
||||||
StencilFailureOperation = descriptor.FrontFaceStencil.StencilFailureOperation,
|
FrontFace = new DepthStencilHash.StencilHash
|
||||||
DepthFailureOperation = descriptor.FrontFaceStencil.DepthFailureOperation,
|
{
|
||||||
DepthStencilPassOperation = descriptor.FrontFaceStencil.DepthStencilPassOperation,
|
StencilFailureOperation = descriptor.FrontFaceStencil.StencilFailureOperation,
|
||||||
StencilCompareFunction = descriptor.FrontFaceStencil.StencilCompareFunction,
|
DepthFailureOperation = descriptor.FrontFaceStencil.DepthFailureOperation,
|
||||||
ReadMask = descriptor.FrontFaceStencil.ReadMask,
|
DepthStencilPassOperation = descriptor.FrontFaceStencil.DepthStencilPassOperation,
|
||||||
WriteMask = descriptor.FrontFaceStencil.WriteMask
|
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;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public DirtyFlags() { }
|
public DirtyFlags() { }
|
||||||
|
|
||||||
public void MarkAll() {
|
public void MarkAll()
|
||||||
|
{
|
||||||
Pipeline = true;
|
Pipeline = true;
|
||||||
DepthStencil = true;
|
DepthStencil = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,10 @@ namespace Ryujinx.Graphics.Metal
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
struct EncoderStateManager
|
struct EncoderStateManager
|
||||||
{
|
{
|
||||||
private readonly MTLDevice _device;
|
|
||||||
private readonly Pipeline _pipeline;
|
private readonly Pipeline _pipeline;
|
||||||
|
|
||||||
private readonly RenderPipelineCache RenderPipelineCache;
|
private readonly RenderPipelineCache _renderPipelineCache;
|
||||||
private readonly DepthStencilCache DepthStencilCache;
|
private readonly DepthStencilCache _depthStencilCache;
|
||||||
|
|
||||||
private EncoderState _currentState = new();
|
private EncoderState _currentState = new();
|
||||||
private EncoderState _backState = new();
|
private EncoderState _backState = new();
|
||||||
|
@ -30,10 +29,9 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public EncoderStateManager(MTLDevice device, Pipeline pipeline)
|
public EncoderStateManager(MTLDevice device, Pipeline pipeline)
|
||||||
{
|
{
|
||||||
_device = device;
|
|
||||||
_pipeline = pipeline;
|
_pipeline = pipeline;
|
||||||
RenderPipelineCache = new(device);
|
_renderPipelineCache = new(device);
|
||||||
DepthStencilCache = new(device);
|
_depthStencilCache = new(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SwapStates()
|
public void SwapStates()
|
||||||
|
@ -139,7 +137,8 @@ namespace Ryujinx.Graphics.Metal
|
||||||
_currentState.Dirty.Clear();
|
_currentState.Dirty.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetPipelineState(MTLRenderCommandEncoder renderCommandEncoder) {
|
private readonly void SetPipelineState(MTLRenderCommandEncoder renderCommandEncoder)
|
||||||
|
{
|
||||||
var renderPipelineDescriptor = new MTLRenderPipelineDescriptor();
|
var renderPipelineDescriptor = new MTLRenderPipelineDescriptor();
|
||||||
|
|
||||||
for (int i = 0; i < Constants.MaxColorAttachments; i++)
|
for (int i = 0; i < Constants.MaxColorAttachments; i++)
|
||||||
|
@ -209,7 +208,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
renderPipelineDescriptor.FragmentFunction = _currentState.FragmentFunction.Value;
|
renderPipelineDescriptor.FragmentFunction = _currentState.FragmentFunction.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pipelineState = RenderPipelineCache.GetOrCreate(renderPipelineDescriptor);
|
var pipelineState = _renderPipelineCache.GetOrCreate(renderPipelineDescriptor);
|
||||||
|
|
||||||
renderCommandEncoder.SetRenderPipelineState(pipelineState);
|
renderCommandEncoder.SetRenderPipelineState(pipelineState);
|
||||||
|
|
||||||
|
@ -330,7 +329,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
descriptor.FrontFaceStencil = _currentState.FrontFaceStencil;
|
descriptor.FrontFaceStencil = _currentState.FrontFaceStencil;
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentState.DepthStencilState = DepthStencilCache.GetOrCreate(descriptor);
|
_currentState.DepthStencilState = _depthStencilCache.GetOrCreate(descriptor);
|
||||||
|
|
||||||
// Mark dirty
|
// Mark dirty
|
||||||
_currentState.Dirty.DepthStencil = true;
|
_currentState.Dirty.DepthStencil = true;
|
||||||
|
@ -354,7 +353,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
descriptor.FrontFaceStencil = _currentState.FrontFaceStencil;
|
descriptor.FrontFaceStencil = _currentState.FrontFaceStencil;
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentState.DepthStencilState = DepthStencilCache.GetOrCreate(descriptor);
|
_currentState.DepthStencilState = _depthStencilCache.GetOrCreate(descriptor);
|
||||||
|
|
||||||
// Mark dirty
|
// Mark dirty
|
||||||
_currentState.Dirty.DepthStencil = true;
|
_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)
|
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);
|
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();
|
var vertexDescriptor = new MTLVertexDescriptor();
|
||||||
uint indexMask = 0;
|
uint indexMask = 0;
|
||||||
|
@ -635,7 +634,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
SetBuffers(renderCommandEncoder, buffers);
|
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)
|
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);
|
renderCommandEncoder.SetCullMode(_currentState.CullMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetFrontFace(MTLRenderCommandEncoder renderCommandEncoder)
|
private readonly void SetFrontFace(MTLRenderCommandEncoder renderCommandEncoder)
|
||||||
{
|
{
|
||||||
renderCommandEncoder.SetFrontFacingWinding(_currentState.Winding);
|
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)
|
foreach (var texture in textures)
|
||||||
{
|
{
|
||||||
|
|
|
@ -208,7 +208,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
Format.R16G16B16A16Float => MTLVertexFormat.Half4,
|
Format.R16G16B16A16Float => MTLVertexFormat.Half4,
|
||||||
Format.R32Float => MTLVertexFormat.Float,
|
Format.R32Float => MTLVertexFormat.Float,
|
||||||
Format.R32G32Float => MTLVertexFormat.Float2,
|
Format.R32G32Float => MTLVertexFormat.Float2,
|
||||||
Format.R32G32B32Float=> MTLVertexFormat.Float3,
|
Format.R32G32B32Float => MTLVertexFormat.Float3,
|
||||||
Format.R11G11B10Float => MTLVertexFormat.FloatRG11B10,
|
Format.R11G11B10Float => MTLVertexFormat.FloatRG11B10,
|
||||||
Format.R32G32B32A32Float => MTLVertexFormat.Float4,
|
Format.R32G32B32A32Float => MTLVertexFormat.Float4,
|
||||||
Format.R8Uint => MTLVertexFormat.UChar,
|
Format.R8Uint => MTLVertexFormat.UChar,
|
||||||
|
|
|
@ -10,13 +10,6 @@ using System.Runtime.Versioning;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
enum ComponentType
|
|
||||||
{
|
|
||||||
Float,
|
|
||||||
SignedInteger,
|
|
||||||
UnsignedInteger,
|
|
||||||
}
|
|
||||||
|
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
class HelperShader : IDisposable
|
class HelperShader : IDisposable
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,6 @@ using SharpMetal.Foundation;
|
||||||
using SharpMetal.Metal;
|
using SharpMetal.Metal;
|
||||||
using SharpMetal.QuartzCore;
|
using SharpMetal.QuartzCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.Graphics.GAL;
|
|
||||||
using SharpMetal.Foundation;
|
using SharpMetal.Foundation;
|
||||||
using SharpMetal.Metal;
|
using SharpMetal.Metal;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
|
@ -72,16 +70,24 @@ namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
private readonly MTLDevice _device;
|
private readonly MTLDevice _device;
|
||||||
|
|
||||||
public RenderPipelineCache(MTLDevice device) {
|
public RenderPipelineCache(MTLDevice device)
|
||||||
|
{
|
||||||
_device = device;
|
_device = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override RenderPipelineHash GetHash(MTLRenderPipelineDescriptor descriptor) {
|
protected override RenderPipelineHash GetHash(MTLRenderPipelineDescriptor descriptor)
|
||||||
var hash = new RenderPipelineHash();
|
{
|
||||||
|
var hash = new RenderPipelineHash
|
||||||
// Functions
|
{
|
||||||
hash.VertexFunction = descriptor.VertexFunction;
|
// Functions
|
||||||
hash.FragmentFunction = descriptor.FragmentFunction;
|
VertexFunction = descriptor.VertexFunction,
|
||||||
|
FragmentFunction = descriptor.FragmentFunction,
|
||||||
|
DepthStencilAttachment = new RenderPipelineHash.DepthStencilAttachmentHash
|
||||||
|
{
|
||||||
|
DepthPixelFormat = descriptor.DepthAttachmentPixelFormat,
|
||||||
|
StencilPixelFormat = descriptor.StencilAttachmentPixelFormat
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// Color Attachments
|
// Color Attachments
|
||||||
for (int i = 0; i < Constants.MaxColorAttachments; i++)
|
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
|
// Vertex descriptor
|
||||||
hash.VertexDescriptor = new RenderPipelineHash.VertexDescriptorHash();
|
hash.VertexDescriptor = new RenderPipelineHash.VertexDescriptorHash();
|
||||||
|
|
||||||
|
|
|
@ -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.Collections.Generic;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[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);
|
var hash = GetHash(descriptor);
|
||||||
if (Cache.TryGetValue(hash, out T value))
|
if (_cache.TryGetValue(hash, out T value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var newValue = CreateValue(descriptor);
|
var newValue = CreateValue(descriptor);
|
||||||
Cache.Add(hash, newValue);
|
_cache.Add(hash, newValue);
|
||||||
|
|
||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
_metalLayer.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,12 +246,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
|
||||||
return resourceDefinitions.Textures[textOp.Binding].Name;
|
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)
|
private static string GetMaskMultiDest(int mask)
|
||||||
{
|
{
|
||||||
string swizzle = ".";
|
string swizzle = ".";
|
||||||
|
|
Loading…
Reference in a new issue