2019-10-13 02:02:07 -04:00
|
|
|
using Ryujinx.Graphics.GAL;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Image
|
|
|
|
{
|
2019-12-29 18:26:37 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Cached sampler entry for sampler pools.
|
|
|
|
/// </summary>
|
2019-10-13 02:02:07 -04:00
|
|
|
class Sampler : IDisposable
|
|
|
|
{
|
2019-12-29 18:26:37 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Host sampler object.
|
|
|
|
/// </summary>
|
2019-10-13 02:02:07 -04:00
|
|
|
public ISampler HostSampler { get; }
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new instance of the cached sampler.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="context">The GPU context the sampler belongs to</param>
|
|
|
|
/// <param name="descriptor">The Maxwell sampler descriptor</param>
|
2019-10-13 02:02:07 -04:00
|
|
|
public Sampler(GpuContext context, SamplerDescriptor descriptor)
|
|
|
|
{
|
|
|
|
MinFilter minFilter = descriptor.UnpackMinFilter();
|
|
|
|
MagFilter magFilter = descriptor.UnpackMagFilter();
|
|
|
|
|
|
|
|
AddressMode addressU = descriptor.UnpackAddressU();
|
|
|
|
AddressMode addressV = descriptor.UnpackAddressV();
|
|
|
|
AddressMode addressP = descriptor.UnpackAddressP();
|
|
|
|
|
|
|
|
CompareMode compareMode = descriptor.UnpackCompareMode();
|
|
|
|
CompareOp compareOp = descriptor.UnpackCompareOp();
|
|
|
|
|
2020-01-17 03:55:38 -05:00
|
|
|
ColorF color = new ColorF(
|
|
|
|
descriptor.BorderColorR,
|
|
|
|
descriptor.BorderColorG,
|
|
|
|
descriptor.BorderColorB,
|
|
|
|
descriptor.BorderColorA);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
float minLod = descriptor.UnpackMinLod();
|
|
|
|
float maxLod = descriptor.UnpackMaxLod();
|
|
|
|
float mipLodBias = descriptor.UnpackMipLodBias();
|
|
|
|
|
2020-03-30 17:38:52 -04:00
|
|
|
float maxRequestedAnisotropy = GraphicsConfig.MaxAnisotropy >= 0 && GraphicsConfig.MaxAnisotropy <= 16 ? GraphicsConfig.MaxAnisotropy : descriptor.UnpackMaxAnisotropy();
|
2020-05-27 19:03:07 -04:00
|
|
|
float maxSupportedAnisotropy = context.Capabilities.MaximumSupportedAnisotropy;
|
2020-03-30 17:38:52 -04:00
|
|
|
|
|
|
|
if (maxRequestedAnisotropy > maxSupportedAnisotropy)
|
|
|
|
maxRequestedAnisotropy = maxSupportedAnisotropy;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
HostSampler = context.Renderer.CreateSampler(new SamplerCreateInfo(
|
|
|
|
minFilter,
|
|
|
|
magFilter,
|
|
|
|
addressU,
|
|
|
|
addressV,
|
|
|
|
addressP,
|
|
|
|
compareMode,
|
|
|
|
compareOp,
|
|
|
|
color,
|
|
|
|
minLod,
|
|
|
|
maxLod,
|
|
|
|
mipLodBias,
|
2020-03-30 17:38:52 -04:00
|
|
|
maxRequestedAnisotropy));
|
2019-10-13 02:02:07 -04:00
|
|
|
}
|
|
|
|
|
2019-12-29 18:26:37 -05:00
|
|
|
/// <summary>
|
|
|
|
/// Disposes the host sampler object.
|
|
|
|
/// </summary>
|
2019-10-13 02:02:07 -04:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
HostSampler.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|