Clamp number of mipmap levels to avoid API errors due to invalid textures (#2808)
This commit is contained in:
parent
f41687f4c1
commit
f78bcb8048
3 changed files with 40 additions and 12 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue