mirror of
https://github.com/Ryubing/Ryujinx.git
synced 2025-11-15 06:42:44 -05:00
EXPERIMENTAL: Metal backend (#441)
This is not a continuation of the Metal backend; this is simply bringing the branch up to date and merging it as-is behind an experiment. --------- Co-authored-by: Isaac Marovitz <isaacryu@icloud.com> Co-authored-by: Samuliak <samuliak77@gmail.com> Co-authored-by: SamoZ256 <96914946+SamoZ256@users.noreply.github.com> Co-authored-by: Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com> Co-authored-by: riperiperi <rhy3756547@hotmail.com> Co-authored-by: Gabriel A <gab.dark.100@gmail.com>
This commit is contained in:
90
src/Ryujinx.Graphics.Metal/SamplerHolder.cs
Normal file
90
src/Ryujinx.Graphics.Metal/SamplerHolder.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using Ryujinx.Graphics.GAL;
|
||||
using SharpMetal.Metal;
|
||||
using System;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ryujinx.Graphics.Metal
|
||||
{
|
||||
[SupportedOSPlatform("macos")]
|
||||
class SamplerHolder : ISampler
|
||||
{
|
||||
private readonly MetalRenderer _renderer;
|
||||
private readonly Auto<DisposableSampler> _sampler;
|
||||
|
||||
public SamplerHolder(MetalRenderer renderer, MTLDevice device, SamplerCreateInfo info)
|
||||
{
|
||||
_renderer = renderer;
|
||||
|
||||
renderer.Samplers.Add(this);
|
||||
|
||||
(MTLSamplerMinMagFilter minFilter, MTLSamplerMipFilter mipFilter) = info.MinFilter.Convert();
|
||||
|
||||
MTLSamplerBorderColor borderColor = GetConstrainedBorderColor(info.BorderColor, out _);
|
||||
|
||||
using var descriptor = new MTLSamplerDescriptor
|
||||
{
|
||||
BorderColor = borderColor,
|
||||
MinFilter = minFilter,
|
||||
MagFilter = info.MagFilter.Convert(),
|
||||
MipFilter = mipFilter,
|
||||
CompareFunction = info.CompareOp.Convert(),
|
||||
LodMinClamp = info.MinLod,
|
||||
LodMaxClamp = info.MaxLod,
|
||||
LodAverage = false,
|
||||
MaxAnisotropy = Math.Max((uint)info.MaxAnisotropy, 1),
|
||||
SAddressMode = info.AddressU.Convert(),
|
||||
TAddressMode = info.AddressV.Convert(),
|
||||
RAddressMode = info.AddressP.Convert(),
|
||||
SupportArgumentBuffers = true
|
||||
};
|
||||
|
||||
var sampler = device.NewSamplerState(descriptor);
|
||||
|
||||
_sampler = new Auto<DisposableSampler>(new DisposableSampler(sampler));
|
||||
}
|
||||
|
||||
private static MTLSamplerBorderColor GetConstrainedBorderColor(ColorF arbitraryBorderColor, out bool cantConstrain)
|
||||
{
|
||||
float r = arbitraryBorderColor.Red;
|
||||
float g = arbitraryBorderColor.Green;
|
||||
float b = arbitraryBorderColor.Blue;
|
||||
float a = arbitraryBorderColor.Alpha;
|
||||
|
||||
if (r == 0f && g == 0f && b == 0f)
|
||||
{
|
||||
if (a == 1f)
|
||||
{
|
||||
cantConstrain = false;
|
||||
return MTLSamplerBorderColor.OpaqueBlack;
|
||||
}
|
||||
|
||||
if (a == 0f)
|
||||
{
|
||||
cantConstrain = false;
|
||||
return MTLSamplerBorderColor.TransparentBlack;
|
||||
}
|
||||
}
|
||||
else if (r == 1f && g == 1f && b == 1f && a == 1f)
|
||||
{
|
||||
cantConstrain = false;
|
||||
return MTLSamplerBorderColor.OpaqueWhite;
|
||||
}
|
||||
|
||||
cantConstrain = true;
|
||||
return MTLSamplerBorderColor.OpaqueBlack;
|
||||
}
|
||||
|
||||
public Auto<DisposableSampler> GetSampler()
|
||||
{
|
||||
return _sampler;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_renderer.Samplers.Remove(this))
|
||||
{
|
||||
_sampler.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user