diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2021-11-03 20:58:24 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-03 20:58:24 -0300 |
| commit | f78bcb80485419466fde56812425a53e22705765 (patch) | |
| tree | 4e7674da6d1ace1be146d5f3b6dacaf94ed98bfc /Ryujinx.Graphics.GAL/TextureCreateInfo.cs | |
| parent | f41687f4c1948e9e111afd70e979e98ea5de52fa (diff) | |
Clamp number of mipmap levels to avoid API errors due to invalid textures (#2808)
Diffstat (limited to 'Ryujinx.Graphics.GAL/TextureCreateInfo.cs')
| -rw-r--r-- | Ryujinx.Graphics.GAL/TextureCreateInfo.cs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.GAL/TextureCreateInfo.cs b/Ryujinx.Graphics.GAL/TextureCreateInfo.cs index eedf58a0..3ccfb700 100644 --- a/Ryujinx.Graphics.GAL/TextureCreateInfo.cs +++ b/Ryujinx.Graphics.GAL/TextureCreateInfo.cs @@ -1,5 +1,6 @@ using Ryujinx.Common; using System; +using System.Numerics; namespace Ryujinx.Graphics.GAL { @@ -112,6 +113,25 @@ namespace Ryujinx.Graphics.GAL return 1; } + public readonly int GetLevelsClamped() + { + int maxSize = Width; + + if (Target != Target.Texture1D && + Target != Target.Texture1DArray) + { + maxSize = Math.Max(maxSize, Height); + } + + if (Target == Target.Texture3D) + { + maxSize = Math.Max(maxSize, Depth); + } + + int maxLevels = BitOperations.Log2((uint)maxSize) + 1; + return Math.Min(Levels, maxLevels); + } + private static int GetLevelSize(int size, int level) { return Math.Max(1, size >> level); |
