Logic Operations

This commit is contained in:
Isaac Marovitz 2024-08-12 15:54:41 +01:00
parent 3c569a6e21
commit e29a8b2997
No known key found for this signature in database
GPG Key ID: 97250B2B09A132E1
5 changed files with 42 additions and 9 deletions

View File

@ -38,7 +38,7 @@
<PackageVersion Include="Ryujinx.SDL2-CS" Version="2.30.0-build32" />
<PackageVersion Include="securifybv.ShellLink" Version="0.1.0" />
<PackageVersion Include="shaderc.net" Version="0.1.0" />
<PackageVersion Include="SharpMetal" Version="1.0.0-preview18" />
<PackageVersion Include="SharpMetal" Version="1.0.0-preview20" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="Silk.NET.Vulkan" Version="2.21.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.EXT" Version="2.21.0" />

View File

@ -663,6 +663,14 @@ namespace Ryujinx.Graphics.Metal
SignalDirty(DirtyFlags.DepthBias);
}
public readonly void UpdateLogicOpState(bool enable, LogicalOp op)
{
_currentState.Pipeline.LogicOpEnable = enable;
_currentState.Pipeline.LogicOp = op.Convert();
SignalDirty(DirtyFlags.RenderPipeline);
}
public readonly void UpdateMultisampleState(MultisampleDescriptor multisample)
{
_currentState.Pipeline.AlphaToCoverageEnable = multisample.AlphaToCoverageEnable;

View File

@ -1,6 +1,7 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using SharpMetal.Metal;
using System;
using System.Runtime.Versioning;
namespace Ryujinx.Graphics.Metal
@ -112,6 +113,30 @@ namespace Ryujinx.Graphics.Metal
};
}
public static MTLLogicOperation Convert(this LogicalOp op)
{
return op switch
{
LogicalOp.Clear => MTLLogicOperation.Clear,
LogicalOp.And => MTLLogicOperation.And,
LogicalOp.AndReverse => MTLLogicOperation.AndReverse,
LogicalOp.Copy => MTLLogicOperation.Copy,
LogicalOp.AndInverted => MTLLogicOperation.AndInverted,
LogicalOp.Noop => MTLLogicOperation.Noop,
LogicalOp.Xor => MTLLogicOperation.Xor,
LogicalOp.Or => MTLLogicOperation.Or,
LogicalOp.Nor => MTLLogicOperation.Nor,
LogicalOp.Equiv => MTLLogicOperation.Equivalence,
LogicalOp.Invert => MTLLogicOperation.Invert,
LogicalOp.OrReverse => MTLLogicOperation.OrReverse,
LogicalOp.CopyInverted => MTLLogicOperation.CopyInverted,
LogicalOp.OrInverted => MTLLogicOperation.OrInverted,
LogicalOp.Nand => MTLLogicOperation.Nand,
LogicalOp.Set => MTLLogicOperation.Set,
_ => LogInvalidAndReturn(op, nameof(LogicalOp), MTLLogicOperation.And)
};
}
public static MTLSamplerMinMagFilter Convert(this MagFilter filter)
{
return filter switch

View File

@ -669,7 +669,7 @@ namespace Ryujinx.Graphics.Metal
public void SetLogicOpState(bool enable, LogicalOp op)
{
// Metal does not support logic operations.
_encoderStateManager.UpdateLogicOpState(enable, op);
}
public void SetMultisampleState(MultisampleDescriptor multisample)

View File

@ -45,10 +45,9 @@ namespace Ryujinx.Graphics.Metal
}
*/
// Reserved for when API is available.
public int LogicOp
public MTLLogicOperation LogicOp
{
readonly get => (int)((Internal.Id0 >> 32) & 0xF);
readonly get => (MTLLogicOperation)((Internal.Id0 >> 32) & 0xF);
set => Internal.Id0 = (Internal.Id0 & 0xFFFFFFF0FFFFFFFF) | ((ulong)value << 32);
}
@ -65,7 +64,6 @@ namespace Ryujinx.Graphics.Metal
set => Internal.Id0 = (Internal.Id0 & 0xFFFFFFDFFFFFFFFF) | ((value ? 1UL : 0UL) << 37);
}
// Reserved for when API is available.
public bool LogicOpEnable
{
readonly get => ((Internal.Id0 >> 38) & 0x1) != 0UL;
@ -208,9 +206,11 @@ namespace Ryujinx.Graphics.Metal
}
}
renderPipelineDescriptor.SetAlphaToCoverageEnabled(AlphaToCoverageEnable);
renderPipelineDescriptor.SetAlphaToOneEnabled(AlphaToOneEnable);
renderPipelineDescriptor.SetRasterizationEnabled(!RasterizerDiscardEnable);
renderPipelineDescriptor.LogicOperationEnabled = LogicOpEnable;
renderPipelineDescriptor.LogicOperation = LogicOp;
renderPipelineDescriptor.AlphaToCoverageEnabled = AlphaToCoverageEnable;
renderPipelineDescriptor.AlphaToOneEnabled = AlphaToOneEnable;
renderPipelineDescriptor.RasterizationEnabled = !RasterizerDiscardEnable;
renderPipelineDescriptor.SampleCount = Math.Max(1, SamplesCount);
var vertexDescriptor = BuildVertexDescriptor();