mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-09-10 09:48:51 +02:00
Supper 2D array ASTC compressed texture formats decoding (#1593)
This commit is contained in:
parent
f8c41a9a51
commit
86412ed30a
2 changed files with 31 additions and 22 deletions
|
@ -657,6 +657,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||||
Info.Height,
|
Info.Height,
|
||||||
_depth,
|
_depth,
|
||||||
Info.Levels,
|
Info.Levels,
|
||||||
|
_layers,
|
||||||
out Span<byte> decoded))
|
out Span<byte> decoded))
|
||||||
{
|
{
|
||||||
string texInfo = $"{Info.Target} {Info.FormatInfo.Format} {Info.Width}x{Info.Height}x{Info.DepthOrLayers} levels {Info.Levels}";
|
string texInfo = $"{Info.Target} {Info.FormatInfo.Format} {Info.Width}x{Info.Height}x{Info.DepthOrLayers} levels {Info.Levels}";
|
||||||
|
|
|
@ -30,7 +30,8 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int depth,
|
int depth,
|
||||||
int levels)
|
int levels,
|
||||||
|
int layers)
|
||||||
{
|
{
|
||||||
if ((uint)blockWidth > 12)
|
if ((uint)blockWidth > 12)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +49,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
BlockSizeX = blockWidth;
|
BlockSizeX = blockWidth;
|
||||||
BlockSizeY = blockHeight;
|
BlockSizeY = blockHeight;
|
||||||
|
|
||||||
Levels = new AstcLevel[levels];
|
Levels = new AstcLevel[levels * layers];
|
||||||
|
|
||||||
Success = true;
|
Success = true;
|
||||||
|
|
||||||
|
@ -59,7 +60,9 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
|
|
||||||
for (int i = 0; i < levels; i++)
|
for (int i = 0; i < levels; i++)
|
||||||
{
|
{
|
||||||
ref AstcLevel level = ref Levels[i];
|
for (int j = 0; j < layers; j++)
|
||||||
|
{
|
||||||
|
ref AstcLevel level = ref Levels[i * layers + j];
|
||||||
|
|
||||||
level.ImageSizeX = Math.Max(1, width >> i);
|
level.ImageSizeX = Math.Max(1, width >> i);
|
||||||
level.ImageSizeY = Math.Max(1, height >> i);
|
level.ImageSizeY = Math.Max(1, height >> i);
|
||||||
|
@ -74,6 +77,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
currentInputBlock += level.TotalBlockCount;
|
currentInputBlock += level.TotalBlockCount;
|
||||||
currentOutputOffset += level.PixelCount * 4;
|
currentOutputOffset += level.PixelCount * 4;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TotalBlockCount = currentInputBlock;
|
TotalBlockCount = currentInputBlock;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +98,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
public int PixelCount => ImageSizeX * ImageSizeY * ImageSizeZ;
|
public int PixelCount => ImageSizeX * ImageSizeY * ImageSizeZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int QueryDecompressedSize(int sizeX, int sizeY, int sizeZ, int levelCount)
|
public static int QueryDecompressedSize(int sizeX, int sizeY, int sizeZ, int levelCount, int layerCount)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
|
@ -104,7 +108,7 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
int levelSizeY = Math.Max(1, sizeY >> i);
|
int levelSizeY = Math.Max(1, sizeY >> i);
|
||||||
int levelSizeZ = Math.Max(1, sizeZ >> i);
|
int levelSizeZ = Math.Max(1, sizeZ >> i);
|
||||||
|
|
||||||
size += levelSizeX * levelSizeY * levelSizeZ;
|
size += levelSizeX * levelSizeY * levelSizeZ * layerCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
return size * 4;
|
return size * 4;
|
||||||
|
@ -221,11 +225,12 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
int height,
|
int height,
|
||||||
int depth,
|
int depth,
|
||||||
int levels,
|
int levels,
|
||||||
|
int layers,
|
||||||
out Span<byte> decoded)
|
out Span<byte> decoded)
|
||||||
{
|
{
|
||||||
byte[] output = new byte[QueryDecompressedSize(width, height, depth, levels)];
|
byte[] output = new byte[QueryDecompressedSize(width, height, depth, levels, layers)];
|
||||||
|
|
||||||
AstcDecoder decoder = new AstcDecoder(data, output, blockWidth, blockHeight, width, height, depth, levels);
|
AstcDecoder decoder = new AstcDecoder(data, output, blockWidth, blockHeight, width, height, depth, levels, layers);
|
||||||
|
|
||||||
for (int i = 0; i < decoder.TotalBlockCount; i++)
|
for (int i = 0; i < decoder.TotalBlockCount; i++)
|
||||||
{
|
{
|
||||||
|
@ -245,9 +250,10 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int depth,
|
int depth,
|
||||||
int levels)
|
int levels,
|
||||||
|
int layers)
|
||||||
{
|
{
|
||||||
AstcDecoder decoder = new AstcDecoder(data, outputBuffer, blockWidth, blockHeight, width, height, depth, levels);
|
AstcDecoder decoder = new AstcDecoder(data, outputBuffer, blockWidth, blockHeight, width, height, depth, levels, layers);
|
||||||
|
|
||||||
for (int i = 0; i < decoder.TotalBlockCount; i++)
|
for (int i = 0; i < decoder.TotalBlockCount; i++)
|
||||||
{
|
{
|
||||||
|
@ -265,9 +271,10 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int depth,
|
int depth,
|
||||||
int levels)
|
int levels,
|
||||||
|
int layers)
|
||||||
{
|
{
|
||||||
AstcDecoder decoder = new AstcDecoder(data, outputBuffer, blockWidth, blockHeight, width, height, depth, levels);
|
AstcDecoder decoder = new AstcDecoder(data, outputBuffer, blockWidth, blockHeight, width, height, depth, levels, layers);
|
||||||
|
|
||||||
// Lazy parallelism
|
// Lazy parallelism
|
||||||
Enumerable.Range(0, decoder.TotalBlockCount).AsParallel().ForAll(x => decoder.ProcessBlock(x));
|
Enumerable.Range(0, decoder.TotalBlockCount).AsParallel().ForAll(x => decoder.ProcessBlock(x));
|
||||||
|
@ -283,11 +290,12 @@ namespace Ryujinx.Graphics.Texture.Astc
|
||||||
int height,
|
int height,
|
||||||
int depth,
|
int depth,
|
||||||
int levels,
|
int levels,
|
||||||
|
int layers,
|
||||||
out Span<byte> decoded)
|
out Span<byte> decoded)
|
||||||
{
|
{
|
||||||
byte[] output = new byte[QueryDecompressedSize(width, height, depth, levels)];
|
byte[] output = new byte[QueryDecompressedSize(width, height, depth, levels, layers)];
|
||||||
|
|
||||||
AstcDecoder decoder = new AstcDecoder(data, output, blockWidth, blockHeight, width, height, depth, levels);
|
AstcDecoder decoder = new AstcDecoder(data, output, blockWidth, blockHeight, width, height, depth, levels, layers);
|
||||||
|
|
||||||
Enumerable.Range(0, decoder.TotalBlockCount).AsParallel().ForAll(x => decoder.ProcessBlock(x));
|
Enumerable.Range(0, decoder.TotalBlockCount).AsParallel().ForAll(x => decoder.ProcessBlock(x));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue