Clamp number of mipmap levels to avoid API errors due to invalid textures (#2808)

This commit is contained in:
gdkchan 2021-11-03 20:58:24 -03:00 committed by GitHub
parent f41687f4c1
commit f78bcb8048
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 12 deletions

View file

@ -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);