mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-11-16 18:15:25 +00:00
bc4e70b6fa
Rather than calculating this for every sampler, this PR calculates if a texture can force anisotropy when its info is set, and exposes the value via a public boolean. This should help texture/sampler heavy games when anisotropic filtering is not Auto, like UE4 ones (or so i hear?). There is another cost where samplers are created twice when anisotropic filtering is enabled, but I'm not sure how relevant this one is.
108 lines
3.8 KiB
C#
108 lines
3.8 KiB
C#
using Ryujinx.Graphics.GAL;
|
|
using System;
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Image
|
|
{
|
|
/// <summary>
|
|
/// Cached sampler entry for sampler pools.
|
|
/// </summary>
|
|
class Sampler : IDisposable
|
|
{
|
|
/// <summary>
|
|
/// Host sampler object.
|
|
/// </summary>
|
|
private readonly ISampler _hostSampler;
|
|
|
|
/// <summary>
|
|
/// Host sampler object, with anisotropy forced.
|
|
/// </summary>
|
|
private readonly ISampler _anisoSampler;
|
|
|
|
/// <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>
|
|
public Sampler(GpuContext context, SamplerDescriptor descriptor)
|
|
{
|
|
MinFilter minFilter = descriptor.UnpackMinFilter();
|
|
MagFilter magFilter = descriptor.UnpackMagFilter();
|
|
|
|
bool seamlessCubemap = descriptor.UnpackSeamlessCubemap();
|
|
|
|
AddressMode addressU = descriptor.UnpackAddressU();
|
|
AddressMode addressV = descriptor.UnpackAddressV();
|
|
AddressMode addressP = descriptor.UnpackAddressP();
|
|
|
|
CompareMode compareMode = descriptor.UnpackCompareMode();
|
|
CompareOp compareOp = descriptor.UnpackCompareOp();
|
|
|
|
ColorF color = new ColorF(
|
|
descriptor.BorderColorR,
|
|
descriptor.BorderColorG,
|
|
descriptor.BorderColorB,
|
|
descriptor.BorderColorA);
|
|
|
|
float minLod = descriptor.UnpackMinLod();
|
|
float maxLod = descriptor.UnpackMaxLod();
|
|
float mipLodBias = descriptor.UnpackMipLodBias();
|
|
|
|
float maxRequestedAnisotropy = descriptor.UnpackMaxAnisotropy();
|
|
float maxSupportedAnisotropy = context.Capabilities.MaximumSupportedAnisotropy;
|
|
|
|
_hostSampler = context.Renderer.CreateSampler(new SamplerCreateInfo(
|
|
minFilter,
|
|
magFilter,
|
|
seamlessCubemap,
|
|
addressU,
|
|
addressV,
|
|
addressP,
|
|
compareMode,
|
|
compareOp,
|
|
color,
|
|
minLod,
|
|
maxLod,
|
|
mipLodBias,
|
|
Math.Min(maxRequestedAnisotropy, maxSupportedAnisotropy)));
|
|
|
|
if (GraphicsConfig.MaxAnisotropy >= 0 && GraphicsConfig.MaxAnisotropy <= 16 && (minFilter == MinFilter.LinearMipmapNearest || minFilter == MinFilter.LinearMipmapLinear))
|
|
{
|
|
maxRequestedAnisotropy = GraphicsConfig.MaxAnisotropy;
|
|
|
|
_anisoSampler = context.Renderer.CreateSampler(new SamplerCreateInfo(
|
|
minFilter,
|
|
magFilter,
|
|
seamlessCubemap,
|
|
addressU,
|
|
addressV,
|
|
addressP,
|
|
compareMode,
|
|
compareOp,
|
|
color,
|
|
minLod,
|
|
maxLod,
|
|
mipLodBias,
|
|
Math.Min(maxRequestedAnisotropy, maxSupportedAnisotropy)));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a host sampler for the given texture.
|
|
/// </summary>
|
|
/// <param name="texture">Texture to be sampled</param>
|
|
/// <returns>A host sampler</returns>
|
|
public ISampler GetHostSampler(Texture texture)
|
|
{
|
|
return _anisoSampler != null && texture?.CanForceAnisotropy == true ? _anisoSampler : _hostSampler;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Disposes the host sampler object.
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
_hostSampler.Dispose();
|
|
_anisoSampler?.Dispose();
|
|
}
|
|
}
|
|
} |