|
|
@@ -6,6 +6,7 @@ using Ryujinx.Memory.Range;
|
|
|
using System;
|
|
|
using System.Collections.Concurrent;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Numerics;
|
|
|
using System.Threading;
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Image
|
|
|
@@ -490,6 +491,8 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|
|
levels = (maxLod - minLod) + 1;
|
|
|
}
|
|
|
|
|
|
+ levels = ClampLevels(target, width, height, depthOrLayers, levels);
|
|
|
+
|
|
|
SwizzleComponent swizzleR = descriptor.UnpackSwizzleR().Convert();
|
|
|
SwizzleComponent swizzleG = descriptor.UnpackSwizzleG().Convert();
|
|
|
SwizzleComponent swizzleB = descriptor.UnpackSwizzleB().Convert();
|
|
|
@@ -540,6 +543,34 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|
|
swizzleA);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Clamps the amount of mipmap levels to the maximum allowed for the given texture dimensions.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="target">Number of texture dimensions (1D, 2D, 3D, Cube, etc)</param>
|
|
|
+ /// <param name="width">Width of the texture</param>
|
|
|
+ /// <param name="height">Height of the texture, ignored for 1D textures</param>
|
|
|
+ /// <param name="depthOrLayers">Depth of the texture for 3D textures, otherwise ignored</param>
|
|
|
+ /// <param name="levels">Original amount of mipmap levels</param>
|
|
|
+ /// <returns>Clamped mipmap levels</returns>
|
|
|
+ private static int ClampLevels(Target target, int width, int height, int depthOrLayers, int levels)
|
|
|
+ {
|
|
|
+ int maxSize = width;
|
|
|
+
|
|
|
+ if (target != Target.Texture1D &&
|
|
|
+ target != Target.Texture1DArray)
|
|
|
+ {
|
|
|
+ maxSize = Math.Max(maxSize, height);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (target == Target.Texture3D)
|
|
|
+ {
|
|
|
+ maxSize = Math.Max(maxSize, depthOrLayers);
|
|
|
+ }
|
|
|
+
|
|
|
+ int maxLevels = BitOperations.Log2((uint)maxSize) + 1;
|
|
|
+ return Math.Min(levels, maxLevels);
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Gets the texture depth-stencil mode, based on the swizzle components of each color channel.
|
|
|
/// The depth-stencil mode is determined based on how the driver sets those parameters.
|