Address feedback

This commit is contained in:
Alex Barney 2019-12-16 20:38:24 -06:00
parent 418225f9e6
commit 98fc3c2f59
2 changed files with 14 additions and 22 deletions

View file

@ -5,7 +5,6 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Texture.Astc
{
// https://github.com/GammaUNC/FasTC/blob/master/ASTCEncoder/src/Decompressor.cpp
@ -25,23 +24,23 @@ namespace Ryujinx.Graphics.Texture.Astc
public AstcDecoder(
ReadOnlyMemory<byte> inputBuffer,
Memory<byte> outputBuffer,
int blockX,
int blockY,
int x,
int y,
int z,
int blockWidth,
int blockHeight,
int width,
int height,
int depth,
int levels)
{
if (blockX > 12 || blockY > 12)
if ((uint)blockWidth > 12 || (uint)blockHeight > 12)
{
throw new AstcDecoderException("Block size unsupported!");
throw new AstcDecoderException("Invalid block size.");
}
InputBuffer = inputBuffer;
OutputBuffer = outputBuffer;
BlockSizeX = blockX;
BlockSizeY = blockY;
BlockSizeX = blockWidth;
BlockSizeY = blockHeight;
Levels = new AstcLevel[levels];
@ -53,12 +52,12 @@ namespace Ryujinx.Graphics.Texture.Astc
{
ref AstcLevel level = ref Levels[i];
level.ImageSizeX = Math.Max(1, x >> i);
level.ImageSizeY = Math.Max(1, y >> i);
level.ImageSizeZ = Math.Max(1, z >> i);
level.ImageSizeX = Math.Max(1, width >> i);
level.ImageSizeY = Math.Max(1, height >> i);
level.ImageSizeZ = Math.Max(1, depth >> i);
level.BlockCountX = (level.ImageSizeX + blockX - 1) / blockX;
level.BlockCountY = (level.ImageSizeY + blockY - 1) / blockY;
level.BlockCountX = (level.ImageSizeX + blockWidth - 1) / blockWidth;
level.BlockCountY = (level.ImageSizeY + blockHeight - 1) / blockHeight;
level.StartBlock = currentInputBlock;
level.OutputByteOffset = currentOutputOffset;
@ -1126,7 +1125,6 @@ namespace Ryujinx.Graphics.Texture.Astc
}
// We now have enough to decode our integer sequence.
//IntegerSequence integerEncodedSequence = new IntegerSequence();
IntegerSequence integerEncodedSequence;
unsafe { _ = &integerEncodedSequence; } // Skip struct initialization
integerEncodedSequence.Reset();

View file

@ -218,17 +218,11 @@ namespace Ryujinx.Graphics.Texture.Astc
private static ReadOnlySpan<byte> GetTritEncoding(int index)
{
Debug.Assert((uint)index < 0x100);
return MemoryMarshal.CreateSpan(ref Unsafe.Add(ref MemoryMarshal.GetReference(TritEncodings), index * 5), 5);
return TritEncodings.Slice(index * 5, 5);
}
private static ReadOnlySpan<byte> GetQuintEncoding(int index)
{
Debug.Assert((uint)index < 0x100);
return MemoryMarshal.CreateSpan(ref Unsafe.Add(ref MemoryMarshal.GetReference(QuintEncodings), index * 3), 3);
return QuintEncodings.Slice(index * 3, 3);
}