Ryujinx/src/Ryujinx.Graphics.Texture/BCnEncoder.cs
TSRBerry cebfa54467
[Ryujinx.Graphics.Texture] Address dotnet-format issues (#5375)
* dotnet format style --severity info

Some changes were manually reverted.

* Restore a few unused methods and variables

* Silence dotnet format IDE0060 warnings

* Silence dotnet format IDE0059 warnings

* Address or silence dotnet format CA2208 warnings

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Format if-blocks correctly

* Add comments to disabled warnings

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Address IDE0251 warnings

* Silence IDE0060 in .editorconfig

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* First dotnet format pass

* Apply suggestions from code review

Co-authored-by: Ac_K <Acoustik666@gmail.com>

* Address review feedback

* Update src/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs

Co-authored-by: Ac_K <Acoustik666@gmail.com>

---------

Co-authored-by: Ac_K <Acoustik666@gmail.com>
2023-06-28 18:46:18 +02:00

58 lines
1.8 KiB
C#

using Ryujinx.Common;
using Ryujinx.Graphics.Texture.Encoders;
using System;
namespace Ryujinx.Graphics.Texture
{
public static class BCnEncoder
{
private const int BlockWidth = 4;
private const int BlockHeight = 4;
public static byte[] EncodeBC7(byte[] data, int width, int height, int depth, int levels, int layers)
{
int size = 0;
for (int l = 0; l < levels; l++)
{
int w = BitUtils.DivRoundUp(Math.Max(1, width >> l), BlockWidth);
int h = BitUtils.DivRoundUp(Math.Max(1, height >> l), BlockHeight);
size += w * h * 16 * Math.Max(1, depth >> l) * layers;
}
byte[] output = new byte[size];
int imageBaseIOffs = 0;
int imageBaseOOffs = 0;
for (int l = 0; l < levels; l++)
{
int w = BitUtils.DivRoundUp(width, BlockWidth);
int h = BitUtils.DivRoundUp(height, BlockHeight);
for (int l2 = 0; l2 < layers; l2++)
{
for (int z = 0; z < depth; z++)
{
BC7Encoder.Encode(
output.AsMemory()[imageBaseOOffs..],
data.AsMemory()[imageBaseIOffs..],
width,
height,
EncodeMode.Fast | EncodeMode.Multithreaded);
imageBaseIOffs += width * height * 4;
imageBaseOOffs += w * h * 16;
}
}
width = Math.Max(1, width >> 1);
height = Math.Max(1, height >> 1);
depth = Math.Max(1, depth >> 1);
}
return output;
}
}
}