2023-06-12 17:30:22 +00:00
|
|
|
|
using Microsoft.VisualBasic;
|
|
|
|
|
using NUnit.Framework;
|
2023-06-11 17:27:53 +00:00
|
|
|
|
using Ryujinx.Graphics.Gpu;
|
|
|
|
|
using Ryujinx.Graphics.Texture.Astc;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2023-06-12 17:30:22 +00:00
|
|
|
|
using System.IO;
|
2023-06-11 17:27:53 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Tests.Graphics
|
|
|
|
|
{
|
|
|
|
|
public class AstcDecoderTests
|
|
|
|
|
{
|
2023-06-12 17:30:22 +00:00
|
|
|
|
private string _workingDir;
|
|
|
|
|
private string _testDataDir;
|
|
|
|
|
|
2023-06-11 17:27:53 +00:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetupFixture()
|
|
|
|
|
{
|
2023-06-12 17:30:22 +00:00
|
|
|
|
_workingDir = TestContext.CurrentContext.TestDirectory;
|
|
|
|
|
_testDataDir = Path.Join(_workingDir, "Graphics", "TestData");
|
2023-06-11 17:27:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void _Test()
|
|
|
|
|
{
|
2023-06-11 22:34:07 +00:00
|
|
|
|
GraphicsConfig.EnableTextureRecompression = false;
|
2023-06-11 17:27:53 +00:00
|
|
|
|
|
2023-06-12 17:30:22 +00:00
|
|
|
|
var (original, encodedRef, decodedRef) = _getTestDataTupleFromShortname("kodim01");
|
|
|
|
|
int blockWidth = 4;
|
|
|
|
|
int blockHeight = 4;
|
|
|
|
|
|
|
|
|
|
int texWidth = 768;
|
|
|
|
|
int texHeight = 512;
|
|
|
|
|
byte[] outputBuffer = Array.Empty<byte>();
|
|
|
|
|
int depth = 1;
|
|
|
|
|
int levels = 1;
|
|
|
|
|
int layers = 1;
|
|
|
|
|
|
|
|
|
|
_ = AstcDecoder.TryDecodeToRgba8P(original, blockWidth, blockHeight, texWidth, texHeight, depth, levels, layers, out outputBuffer);
|
|
|
|
|
var outputPath = Path.Join(_testDataDir, "kodim01.l4x4.output.png");
|
|
|
|
|
|
|
|
|
|
// Make sure we're clobbering the test output.
|
|
|
|
|
if (File.Exists(outputPath))
|
|
|
|
|
File.Delete(outputPath);
|
|
|
|
|
File.WriteAllBytes(outputPath, outputBuffer);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(decodedRef, outputBuffer);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private (ReadOnlyMemory<byte>, ReadOnlyMemory<byte>, ReadOnlyMemory<byte>) _getTestDataTupleFromShortname(string shortName)
|
|
|
|
|
{
|
|
|
|
|
var original = _getFileDataFromPath($"{shortName}.png");
|
|
|
|
|
// TODO: add brains for block sizes/etc
|
|
|
|
|
var encodedRef = _getFileDataFromPath($"{shortName}.l4x4.astc");
|
|
|
|
|
var decodedRef = _getFileDataFromPath($"{shortName}.l4x4.astc.png");
|
2023-06-11 17:27:53 +00:00
|
|
|
|
|
2023-06-12 17:30:22 +00:00
|
|
|
|
return (original, encodedRef, decodedRef);
|
|
|
|
|
}
|
2023-06-11 17:27:53 +00:00
|
|
|
|
|
2023-06-12 17:30:22 +00:00
|
|
|
|
private ReadOnlyMemory<byte> _getFileDataFromPath(string relativeFilePath)
|
|
|
|
|
{
|
|
|
|
|
var fullPath = Path.Join(_testDataDir, relativeFilePath);
|
|
|
|
|
return File.ReadAllBytes(fullPath);
|
2023-06-11 17:27:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-12 17:30:22 +00:00
|
|
|
|
|
2023-06-11 17:27:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|