Use a generic version of the Convert* functions rather than lambdas.
This is some real monkey's paw shit.
This commit is contained in:
parent
85d0327542
commit
aa43dcfbe8
1 changed files with 143 additions and 116 deletions
|
@ -1,5 +1,6 @@
|
||||||
using Ryujinx.Common;
|
using Ryujinx.Common;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.Intrinsics;
|
using System.Runtime.Intrinsics;
|
||||||
using static Ryujinx.Graphics.Texture.BlockLinearConstants;
|
using static Ryujinx.Graphics.Texture.BlockLinearConstants;
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ namespace Ryujinx.Graphics.Texture
|
||||||
{
|
{
|
||||||
private const int HostStrideAlignment = 4;
|
private const int HostStrideAlignment = 4;
|
||||||
|
|
||||||
public static Span<byte> ConvertBlockLinearToLinear(
|
private static unsafe Span<byte> ConvertBlockLinearToLinear<T>(
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int depth,
|
int depth,
|
||||||
|
@ -17,13 +18,14 @@ namespace Ryujinx.Graphics.Texture
|
||||||
int layers,
|
int layers,
|
||||||
int blockWidth,
|
int blockWidth,
|
||||||
int blockHeight,
|
int blockHeight,
|
||||||
int bytesPerPixel,
|
|
||||||
int gobBlocksInY,
|
int gobBlocksInY,
|
||||||
int gobBlocksInZ,
|
int gobBlocksInZ,
|
||||||
int gobBlocksInTileX,
|
int gobBlocksInTileX,
|
||||||
SizeInfo sizeInfo,
|
SizeInfo sizeInfo,
|
||||||
ReadOnlySpan<byte> data)
|
ReadOnlySpan<byte> data) where T : unmanaged
|
||||||
{
|
{
|
||||||
|
int bytesPerPixel = Unsafe.SizeOf<T>();
|
||||||
|
|
||||||
int outSize = GetTextureSize(
|
int outSize = GetTextureSize(
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
@ -89,8 +91,6 @@ namespace Ryujinx.Graphics.Texture
|
||||||
mipGobBlocksInZ,
|
mipGobBlocksInZ,
|
||||||
bytesPerPixel);
|
bytesPerPixel);
|
||||||
|
|
||||||
unsafe bool Convert<T>(Span<byte> output, ReadOnlySpan<byte> data) where T : unmanaged
|
|
||||||
{
|
|
||||||
fixed (byte* outputPtr = output, dataPtr = data)
|
fixed (byte* outputPtr = output, dataPtr = data)
|
||||||
{
|
{
|
||||||
byte* outPtr = outputPtr + outOffs;
|
byte* outPtr = outputPtr + outOffs;
|
||||||
|
@ -143,23 +143,37 @@ namespace Ryujinx.Graphics.Texture
|
||||||
}
|
}
|
||||||
outOffs += stride * h * d * layers;
|
outOffs += stride * h * d * layers;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _ = bytesPerPixel switch
|
|
||||||
{
|
|
||||||
1 => Convert<byte>(output, data),
|
|
||||||
2 => Convert<ushort>(output, data),
|
|
||||||
4 => Convert<uint>(output, data),
|
|
||||||
8 => Convert<ulong>(output, data),
|
|
||||||
12 => Convert<Bpp12Pixel>(output, data),
|
|
||||||
16 => Convert<Vector128<byte>>(output, data),
|
|
||||||
_ => throw new NotSupportedException($"Unable to convert ${bytesPerPixel} bpp pixel format.")
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Span<byte> ConvertBlockLinearToLinear(
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int depth,
|
||||||
|
int levels,
|
||||||
|
int layers,
|
||||||
|
int blockWidth,
|
||||||
|
int blockHeight,
|
||||||
|
int bytesPerPixel,
|
||||||
|
int gobBlocksInY,
|
||||||
|
int gobBlocksInZ,
|
||||||
|
int gobBlocksInTileX,
|
||||||
|
SizeInfo sizeInfo,
|
||||||
|
ReadOnlySpan<byte> data)
|
||||||
|
{
|
||||||
|
return bytesPerPixel switch
|
||||||
|
{
|
||||||
|
1 => ConvertBlockLinearToLinear<byte>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
2 => ConvertBlockLinearToLinear<ushort>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
4 => ConvertBlockLinearToLinear<uint>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
8 => ConvertBlockLinearToLinear<ulong>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
12 => ConvertBlockLinearToLinear<Bpp12Pixel>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
16 => ConvertBlockLinearToLinear<Vector128<byte>>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
_ => throw new NotSupportedException($"Unable to convert ${bytesPerPixel} bpp pixel format.")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static Span<byte> ConvertLinearStridedToLinear(
|
public static Span<byte> ConvertLinearStridedToLinear(
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
@ -191,7 +205,7 @@ namespace Ryujinx.Graphics.Texture
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Span<byte> ConvertLinearToBlockLinear(
|
private static unsafe Span<byte> ConvertLinearToBlockLinear<T>(
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int depth,
|
int depth,
|
||||||
|
@ -199,13 +213,14 @@ namespace Ryujinx.Graphics.Texture
|
||||||
int layers,
|
int layers,
|
||||||
int blockWidth,
|
int blockWidth,
|
||||||
int blockHeight,
|
int blockHeight,
|
||||||
int bytesPerPixel,
|
|
||||||
int gobBlocksInY,
|
int gobBlocksInY,
|
||||||
int gobBlocksInZ,
|
int gobBlocksInZ,
|
||||||
int gobBlocksInTileX,
|
int gobBlocksInTileX,
|
||||||
SizeInfo sizeInfo,
|
SizeInfo sizeInfo,
|
||||||
ReadOnlySpan<byte> data)
|
ReadOnlySpan<byte> data) where T : unmanaged
|
||||||
{
|
{
|
||||||
|
int bytesPerPixel = Unsafe.SizeOf<T>();
|
||||||
|
|
||||||
Span<byte> output = new byte[sizeInfo.TotalSize];
|
Span<byte> output = new byte[sizeInfo.TotalSize];
|
||||||
|
|
||||||
int inOffs = 0;
|
int inOffs = 0;
|
||||||
|
@ -261,8 +276,6 @@ namespace Ryujinx.Graphics.Texture
|
||||||
mipGobBlocksInZ,
|
mipGobBlocksInZ,
|
||||||
bytesPerPixel);
|
bytesPerPixel);
|
||||||
|
|
||||||
unsafe bool Convert<T>(Span<byte> output, ReadOnlySpan<byte> data) where T : unmanaged
|
|
||||||
{
|
|
||||||
fixed (byte* outputPtr = output, dataPtr = data)
|
fixed (byte* outputPtr = output, dataPtr = data)
|
||||||
{
|
{
|
||||||
byte* inPtr = dataPtr + inOffs;
|
byte* inPtr = dataPtr + inOffs;
|
||||||
|
@ -315,24 +328,38 @@ namespace Ryujinx.Graphics.Texture
|
||||||
}
|
}
|
||||||
inOffs += stride * h * d * layers;
|
inOffs += stride * h * d * layers;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _ = bytesPerPixel switch
|
|
||||||
{
|
|
||||||
1 => Convert<byte>(output, data),
|
|
||||||
2 => Convert<ushort>(output, data),
|
|
||||||
4 => Convert<uint>(output, data),
|
|
||||||
8 => Convert<ulong>(output, data),
|
|
||||||
12 => Convert<Bpp12Pixel>(output, data),
|
|
||||||
16 => Convert<Vector128<byte>>(output, data),
|
|
||||||
_ => throw new NotSupportedException($"Unable to convert ${bytesPerPixel} bpp pixel format.")
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Span<byte> ConvertLinearToBlockLinear(
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int depth,
|
||||||
|
int levels,
|
||||||
|
int layers,
|
||||||
|
int blockWidth,
|
||||||
|
int blockHeight,
|
||||||
|
int bytesPerPixel,
|
||||||
|
int gobBlocksInY,
|
||||||
|
int gobBlocksInZ,
|
||||||
|
int gobBlocksInTileX,
|
||||||
|
SizeInfo sizeInfo,
|
||||||
|
ReadOnlySpan<byte> data)
|
||||||
|
{
|
||||||
|
return bytesPerPixel switch
|
||||||
|
{
|
||||||
|
1 => ConvertLinearToBlockLinear<byte>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
2 => ConvertLinearToBlockLinear<ushort>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
4 => ConvertLinearToBlockLinear<uint>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
8 => ConvertLinearToBlockLinear<ulong>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
12 => ConvertLinearToBlockLinear<Bpp12Pixel>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
16 => ConvertLinearToBlockLinear<Vector128<byte>>(width, height, depth, levels, layers, blockWidth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX, sizeInfo, data),
|
||||||
|
_ => throw new NotSupportedException($"Unable to convert ${bytesPerPixel} bpp pixel format.")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static Span<byte> ConvertLinearToLinearStrided(
|
public static Span<byte> ConvertLinearToLinearStrided(
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
|
Loading…
Reference in a new issue