Address feedback

This commit is contained in:
Alex Barney 2019-12-16 20:38:24 -06:00
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.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Texture.Astc namespace Ryujinx.Graphics.Texture.Astc
{ {
// https://github.com/GammaUNC/FasTC/blob/master/ASTCEncoder/src/Decompressor.cpp // https://github.com/GammaUNC/FasTC/blob/master/ASTCEncoder/src/Decompressor.cpp
@ -25,23 +24,23 @@ namespace Ryujinx.Graphics.Texture.Astc
public AstcDecoder( public AstcDecoder(
ReadOnlyMemory<byte> inputBuffer, ReadOnlyMemory<byte> inputBuffer,
Memory<byte> outputBuffer, Memory<byte> outputBuffer,
int blockX, int blockWidth,
int blockY, int blockHeight,
int x, int width,
int y, int height,
int z, int depth,
int levels) 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; InputBuffer = inputBuffer;
OutputBuffer = outputBuffer; OutputBuffer = outputBuffer;
BlockSizeX = blockX; BlockSizeX = blockWidth;
BlockSizeY = blockY; BlockSizeY = blockHeight;
Levels = new AstcLevel[levels]; Levels = new AstcLevel[levels];
@ -53,12 +52,12 @@ namespace Ryujinx.Graphics.Texture.Astc
{ {
ref AstcLevel level = ref Levels[i]; ref AstcLevel level = ref Levels[i];
level.ImageSizeX = Math.Max(1, x >> i); level.ImageSizeX = Math.Max(1, width >> i);
level.ImageSizeY = Math.Max(1, y >> i); level.ImageSizeY = Math.Max(1, height >> i);
level.ImageSizeZ = Math.Max(1, z >> i); level.ImageSizeZ = Math.Max(1, depth >> i);
level.BlockCountX = (level.ImageSizeX + blockX - 1) / blockX; level.BlockCountX = (level.ImageSizeX + blockWidth - 1) / blockWidth;
level.BlockCountY = (level.ImageSizeY + blockY - 1) / blockY; level.BlockCountY = (level.ImageSizeY + blockHeight - 1) / blockHeight;
level.StartBlock = currentInputBlock; level.StartBlock = currentInputBlock;
level.OutputByteOffset = currentOutputOffset; level.OutputByteOffset = currentOutputOffset;
@ -1126,7 +1125,6 @@ namespace Ryujinx.Graphics.Texture.Astc
} }
// We now have enough to decode our integer sequence. // We now have enough to decode our integer sequence.
//IntegerSequence integerEncodedSequence = new IntegerSequence();
IntegerSequence integerEncodedSequence; IntegerSequence integerEncodedSequence;
unsafe { _ = &integerEncodedSequence; } // Skip struct initialization unsafe { _ = &integerEncodedSequence; } // Skip struct initialization
integerEncodedSequence.Reset(); integerEncodedSequence.Reset();

View file

@ -218,17 +218,11 @@ namespace Ryujinx.Graphics.Texture.Astc
private static ReadOnlySpan<byte> GetTritEncoding(int index) 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); return TritEncodings.Slice(index * 5, 5);
} }
private static ReadOnlySpan<byte> GetQuintEncoding(int index) 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); return QuintEncodings.Slice(index * 3, 3);
} }