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
|
|
|
|
|
{
|
2023-06-12 22:14:38 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* NOTES
|
|
|
|
|
*
|
|
|
|
|
* HOW I GENERATED INPUT DATA
|
|
|
|
|
* Step 1. Create ASTC-compressed image from sample data.
|
|
|
|
|
* *** NOTE This image isn't 2^x evenly sized, it's 768x512 - something that would break down into nice squares, for sure.
|
|
|
|
|
* `bin/astcenc-avx2 -cl sources/kodim01.png output/kodim01.l4x4.astc 4x4 -fast`
|
|
|
|
|
*
|
|
|
|
|
* Step 2. Decompress the data we just created.
|
|
|
|
|
* `bin/astcenc-avx2 -dl output/kodim01.l4x4.astc output/kodim01.l4x4.astc.png`
|
|
|
|
|
*
|
|
|
|
|
* WHAT WE DO IN THE TEST BELOW:
|
|
|
|
|
* 1. Read the sample iamge, ASTC-compressed reference, and decompressed reference that we generated above.
|
|
|
|
|
* 2. Run TryDecodeToRgba8P on our ASTC-compressed texture.
|
|
|
|
|
* 3. Assert that the data we decompressed in our method is the same data as the decompressed reference image.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-06-11 17:27:53 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2023-06-12 22:14:38 +00:00
|
|
|
|
_ = AstcDecoder.TryDecodeToRgba8P(encodedRef, blockWidth, blockHeight, texWidth, texHeight, depth, levels, layers, out outputBuffer);
|
2023-06-12 17:30:22 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|