0
0
Fork 0
mirror of https://github.com/ryujinx-mirror/ryujinx.git synced 2024-12-23 07:45:45 +00:00
ryujinx-fork/src/Ryujinx.Graphics.Vulkan/FormatTable.cs
TSRBerry 801b71a128
[Ryujinx.Graphics.Vulkan] Address dotnet-format issues (#5378)
* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Restore a few unused methods and variables

* Silence dotnet format IDE0060 warnings

* Silence dotnet format IDE0059 warnings

* Address dotnet format CA1816 warnings

* Fix new dotnet-format issues after rebase

* 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

* Another rebase, another dotnet format run

* Run dotnet format whitespace after rebase

* Run dotnet format style after rebase

* Run dotnet format analyzers after rebase

* Run dotnet format style after rebase

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Disable 'prefer switch expression' rule

* Add comments to disabled warnings

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

* Run dotnet format after rebase

* Address IDE0251 warnings

* Address a few disabled IDE0060 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

* Fix naming rule violations

* Remove redundant code

* Rename generics

* Address review feedback

* Remove SetOrigin
2023-07-01 12:31:42 +02:00

342 lines
18 KiB
C#

using Ryujinx.Graphics.GAL;
using System;
using VkFormat = Silk.NET.Vulkan.Format;
namespace Ryujinx.Graphics.Vulkan
{
static class FormatTable
{
private static readonly VkFormat[] _table;
static FormatTable()
{
_table = new VkFormat[Enum.GetNames(typeof(Format)).Length];
#pragma warning disable IDE0055 // Disable formatting
Add(Format.R8Unorm, VkFormat.R8Unorm);
Add(Format.R8Snorm, VkFormat.R8SNorm);
Add(Format.R8Uint, VkFormat.R8Uint);
Add(Format.R8Sint, VkFormat.R8Sint);
Add(Format.R16Float, VkFormat.R16Sfloat);
Add(Format.R16Unorm, VkFormat.R16Unorm);
Add(Format.R16Snorm, VkFormat.R16SNorm);
Add(Format.R16Uint, VkFormat.R16Uint);
Add(Format.R16Sint, VkFormat.R16Sint);
Add(Format.R32Float, VkFormat.R32Sfloat);
Add(Format.R32Uint, VkFormat.R32Uint);
Add(Format.R32Sint, VkFormat.R32Sint);
Add(Format.R8G8Unorm, VkFormat.R8G8Unorm);
Add(Format.R8G8Snorm, VkFormat.R8G8SNorm);
Add(Format.R8G8Uint, VkFormat.R8G8Uint);
Add(Format.R8G8Sint, VkFormat.R8G8Sint);
Add(Format.R16G16Float, VkFormat.R16G16Sfloat);
Add(Format.R16G16Unorm, VkFormat.R16G16Unorm);
Add(Format.R16G16Snorm, VkFormat.R16G16SNorm);
Add(Format.R16G16Uint, VkFormat.R16G16Uint);
Add(Format.R16G16Sint, VkFormat.R16G16Sint);
Add(Format.R32G32Float, VkFormat.R32G32Sfloat);
Add(Format.R32G32Uint, VkFormat.R32G32Uint);
Add(Format.R32G32Sint, VkFormat.R32G32Sint);
Add(Format.R8G8B8Unorm, VkFormat.R8G8B8Unorm);
Add(Format.R8G8B8Snorm, VkFormat.R8G8B8SNorm);
Add(Format.R8G8B8Uint, VkFormat.R8G8B8Uint);
Add(Format.R8G8B8Sint, VkFormat.R8G8B8Sint);
Add(Format.R16G16B16Float, VkFormat.R16G16B16Sfloat);
Add(Format.R16G16B16Unorm, VkFormat.R16G16B16Unorm);
Add(Format.R16G16B16Snorm, VkFormat.R16G16B16SNorm);
Add(Format.R16G16B16Uint, VkFormat.R16G16B16Uint);
Add(Format.R16G16B16Sint, VkFormat.R16G16B16Sint);
Add(Format.R32G32B32Float, VkFormat.R32G32B32Sfloat);
Add(Format.R32G32B32Uint, VkFormat.R32G32B32Uint);
Add(Format.R32G32B32Sint, VkFormat.R32G32B32Sint);
Add(Format.R8G8B8A8Unorm, VkFormat.R8G8B8A8Unorm);
Add(Format.R8G8B8A8Snorm, VkFormat.R8G8B8A8SNorm);
Add(Format.R8G8B8A8Uint, VkFormat.R8G8B8A8Uint);
Add(Format.R8G8B8A8Sint, VkFormat.R8G8B8A8Sint);
Add(Format.R16G16B16A16Float, VkFormat.R16G16B16A16Sfloat);
Add(Format.R16G16B16A16Unorm, VkFormat.R16G16B16A16Unorm);
Add(Format.R16G16B16A16Snorm, VkFormat.R16G16B16A16SNorm);
Add(Format.R16G16B16A16Uint, VkFormat.R16G16B16A16Uint);
Add(Format.R16G16B16A16Sint, VkFormat.R16G16B16A16Sint);
Add(Format.R32G32B32A32Float, VkFormat.R32G32B32A32Sfloat);
Add(Format.R32G32B32A32Uint, VkFormat.R32G32B32A32Uint);
Add(Format.R32G32B32A32Sint, VkFormat.R32G32B32A32Sint);
Add(Format.S8Uint, VkFormat.S8Uint);
Add(Format.D16Unorm, VkFormat.D16Unorm);
Add(Format.S8UintD24Unorm, VkFormat.D24UnormS8Uint);
Add(Format.D32Float, VkFormat.D32Sfloat);
Add(Format.D24UnormS8Uint, VkFormat.D24UnormS8Uint);
Add(Format.D32FloatS8Uint, VkFormat.D32SfloatS8Uint);
Add(Format.R8G8B8A8Srgb, VkFormat.R8G8B8A8Srgb);
Add(Format.R4G4Unorm, VkFormat.R4G4UnormPack8);
Add(Format.R4G4B4A4Unorm, VkFormat.A4B4G4R4UnormPack16Ext);
Add(Format.R5G5B5X1Unorm, VkFormat.A1R5G5B5UnormPack16);
Add(Format.R5G5B5A1Unorm, VkFormat.A1R5G5B5UnormPack16);
Add(Format.R5G6B5Unorm, VkFormat.R5G6B5UnormPack16);
Add(Format.R10G10B10A2Unorm, VkFormat.A2B10G10R10UnormPack32);
Add(Format.R10G10B10A2Uint, VkFormat.A2B10G10R10UintPack32);
Add(Format.R11G11B10Float, VkFormat.B10G11R11UfloatPack32);
Add(Format.R9G9B9E5Float, VkFormat.E5B9G9R9UfloatPack32);
Add(Format.Bc1RgbaUnorm, VkFormat.BC1RgbaUnormBlock);
Add(Format.Bc2Unorm, VkFormat.BC2UnormBlock);
Add(Format.Bc3Unorm, VkFormat.BC3UnormBlock);
Add(Format.Bc1RgbaSrgb, VkFormat.BC1RgbaSrgbBlock);
Add(Format.Bc2Srgb, VkFormat.BC2SrgbBlock);
Add(Format.Bc3Srgb, VkFormat.BC3SrgbBlock);
Add(Format.Bc4Unorm, VkFormat.BC4UnormBlock);
Add(Format.Bc4Snorm, VkFormat.BC4SNormBlock);
Add(Format.Bc5Unorm, VkFormat.BC5UnormBlock);
Add(Format.Bc5Snorm, VkFormat.BC5SNormBlock);
Add(Format.Bc7Unorm, VkFormat.BC7UnormBlock);
Add(Format.Bc7Srgb, VkFormat.BC7SrgbBlock);
Add(Format.Bc6HSfloat, VkFormat.BC6HSfloatBlock);
Add(Format.Bc6HUfloat, VkFormat.BC6HUfloatBlock);
Add(Format.Etc2RgbUnorm, VkFormat.Etc2R8G8B8UnormBlock);
Add(Format.Etc2RgbaUnorm, VkFormat.Etc2R8G8B8A8UnormBlock);
Add(Format.Etc2RgbPtaUnorm, VkFormat.Etc2R8G8B8A1UnormBlock);
Add(Format.Etc2RgbSrgb, VkFormat.Etc2R8G8B8SrgbBlock);
Add(Format.Etc2RgbaSrgb, VkFormat.Etc2R8G8B8A8SrgbBlock);
Add(Format.Etc2RgbPtaSrgb, VkFormat.Etc2R8G8B8A1SrgbBlock);
Add(Format.R8Uscaled, VkFormat.R8Uscaled);
Add(Format.R8Sscaled, VkFormat.R8Sscaled);
Add(Format.R16Uscaled, VkFormat.R16Uscaled);
Add(Format.R16Sscaled, VkFormat.R16Sscaled);
// Add(Format.R32Uscaled, VkFormat.R32Uscaled);
// Add(Format.R32Sscaled, VkFormat.R32Sscaled);
Add(Format.R8G8Uscaled, VkFormat.R8G8Uscaled);
Add(Format.R8G8Sscaled, VkFormat.R8G8Sscaled);
Add(Format.R16G16Uscaled, VkFormat.R16G16Uscaled);
Add(Format.R16G16Sscaled, VkFormat.R16G16Sscaled);
// Add(Format.R32G32Uscaled, VkFormat.R32G32Uscaled);
// Add(Format.R32G32Sscaled, VkFormat.R32G32Sscaled);
Add(Format.R8G8B8Uscaled, VkFormat.R8G8B8Uscaled);
Add(Format.R8G8B8Sscaled, VkFormat.R8G8B8Sscaled);
Add(Format.R16G16B16Uscaled, VkFormat.R16G16B16Uscaled);
Add(Format.R16G16B16Sscaled, VkFormat.R16G16B16Sscaled);
// Add(Format.R32G32B32Uscaled, VkFormat.R32G32B32Uscaled);
// Add(Format.R32G32B32Sscaled, VkFormat.R32G32B32Sscaled);
Add(Format.R8G8B8A8Uscaled, VkFormat.R8G8B8A8Uscaled);
Add(Format.R8G8B8A8Sscaled, VkFormat.R8G8B8A8Sscaled);
Add(Format.R16G16B16A16Uscaled, VkFormat.R16G16B16A16Uscaled);
Add(Format.R16G16B16A16Sscaled, VkFormat.R16G16B16A16Sscaled);
// Add(Format.R32G32B32A32Uscaled, VkFormat.R32G32B32A32Uscaled);
// Add(Format.R32G32B32A32Sscaled, VkFormat.R32G32B32A32Sscaled);
Add(Format.R10G10B10A2Snorm, VkFormat.A2B10G10R10SNormPack32);
Add(Format.R10G10B10A2Sint, VkFormat.A2B10G10R10SintPack32);
Add(Format.R10G10B10A2Uscaled, VkFormat.A2B10G10R10UscaledPack32);
Add(Format.R10G10B10A2Sscaled, VkFormat.A2B10G10R10SscaledPack32);
Add(Format.Astc4x4Unorm, VkFormat.Astc4x4UnormBlock);
Add(Format.Astc5x4Unorm, VkFormat.Astc5x4UnormBlock);
Add(Format.Astc5x5Unorm, VkFormat.Astc5x5UnormBlock);
Add(Format.Astc6x5Unorm, VkFormat.Astc6x5UnormBlock);
Add(Format.Astc6x6Unorm, VkFormat.Astc6x6UnormBlock);
Add(Format.Astc8x5Unorm, VkFormat.Astc8x5UnormBlock);
Add(Format.Astc8x6Unorm, VkFormat.Astc8x6UnormBlock);
Add(Format.Astc8x8Unorm, VkFormat.Astc8x8UnormBlock);
Add(Format.Astc10x5Unorm, VkFormat.Astc10x5UnormBlock);
Add(Format.Astc10x6Unorm, VkFormat.Astc10x6UnormBlock);
Add(Format.Astc10x8Unorm, VkFormat.Astc10x8UnormBlock);
Add(Format.Astc10x10Unorm, VkFormat.Astc10x10UnormBlock);
Add(Format.Astc12x10Unorm, VkFormat.Astc12x10UnormBlock);
Add(Format.Astc12x12Unorm, VkFormat.Astc12x12UnormBlock);
Add(Format.Astc4x4Srgb, VkFormat.Astc4x4SrgbBlock);
Add(Format.Astc5x4Srgb, VkFormat.Astc5x4SrgbBlock);
Add(Format.Astc5x5Srgb, VkFormat.Astc5x5SrgbBlock);
Add(Format.Astc6x5Srgb, VkFormat.Astc6x5SrgbBlock);
Add(Format.Astc6x6Srgb, VkFormat.Astc6x6SrgbBlock);
Add(Format.Astc8x5Srgb, VkFormat.Astc8x5SrgbBlock);
Add(Format.Astc8x6Srgb, VkFormat.Astc8x6SrgbBlock);
Add(Format.Astc8x8Srgb, VkFormat.Astc8x8SrgbBlock);
Add(Format.Astc10x5Srgb, VkFormat.Astc10x5SrgbBlock);
Add(Format.Astc10x6Srgb, VkFormat.Astc10x6SrgbBlock);
Add(Format.Astc10x8Srgb, VkFormat.Astc10x8SrgbBlock);
Add(Format.Astc10x10Srgb, VkFormat.Astc10x10SrgbBlock);
Add(Format.Astc12x10Srgb, VkFormat.Astc12x10SrgbBlock);
Add(Format.Astc12x12Srgb, VkFormat.Astc12x12SrgbBlock);
Add(Format.B5G6R5Unorm, VkFormat.R5G6B5UnormPack16);
Add(Format.B5G5R5A1Unorm, VkFormat.A1R5G5B5UnormPack16);
Add(Format.A1B5G5R5Unorm, VkFormat.R5G5B5A1UnormPack16);
Add(Format.B8G8R8A8Unorm, VkFormat.B8G8R8A8Unorm);
Add(Format.B8G8R8A8Srgb, VkFormat.B8G8R8A8Srgb);
#pragma warning restore IDE0055
}
private static void Add(Format format, VkFormat vkFormat)
{
_table[(int)format] = vkFormat;
}
public static VkFormat GetFormat(Format format)
{
return _table[(int)format];
}
public static Format ConvertRgba8SrgbToUnorm(Format format)
{
return format switch
{
Format.R8G8B8A8Srgb => Format.R8G8B8A8Unorm,
Format.B8G8R8A8Srgb => Format.B8G8R8A8Unorm,
_ => format,
};
}
public static int GetAttributeFormatSize(VkFormat format)
{
switch (format)
{
case VkFormat.R8Unorm:
case VkFormat.R8SNorm:
case VkFormat.R8Uint:
case VkFormat.R8Sint:
case VkFormat.R8Uscaled:
case VkFormat.R8Sscaled:
return 1;
case VkFormat.R8G8Unorm:
case VkFormat.R8G8SNorm:
case VkFormat.R8G8Uint:
case VkFormat.R8G8Sint:
case VkFormat.R8G8Uscaled:
case VkFormat.R8G8Sscaled:
case VkFormat.R16Sfloat:
case VkFormat.R16Unorm:
case VkFormat.R16SNorm:
case VkFormat.R16Uint:
case VkFormat.R16Sint:
case VkFormat.R16Uscaled:
case VkFormat.R16Sscaled:
return 2;
case VkFormat.R8G8B8Unorm:
case VkFormat.R8G8B8SNorm:
case VkFormat.R8G8B8Uint:
case VkFormat.R8G8B8Sint:
case VkFormat.R8G8B8Uscaled:
case VkFormat.R8G8B8Sscaled:
return 3;
case VkFormat.R8G8B8A8Unorm:
case VkFormat.R8G8B8A8SNorm:
case VkFormat.R8G8B8A8Uint:
case VkFormat.R8G8B8A8Sint:
case VkFormat.R8G8B8A8Srgb:
case VkFormat.R8G8B8A8Uscaled:
case VkFormat.R8G8B8A8Sscaled:
case VkFormat.B8G8R8A8Unorm:
case VkFormat.B8G8R8A8Srgb:
case VkFormat.R16G16Sfloat:
case VkFormat.R16G16Unorm:
case VkFormat.R16G16SNorm:
case VkFormat.R16G16Uint:
case VkFormat.R16G16Sint:
case VkFormat.R16G16Uscaled:
case VkFormat.R16G16Sscaled:
case VkFormat.R32Sfloat:
case VkFormat.R32Uint:
case VkFormat.R32Sint:
case VkFormat.A2B10G10R10UnormPack32:
case VkFormat.A2B10G10R10UintPack32:
case VkFormat.B10G11R11UfloatPack32:
case VkFormat.E5B9G9R9UfloatPack32:
case VkFormat.A2B10G10R10SNormPack32:
case VkFormat.A2B10G10R10SintPack32:
case VkFormat.A2B10G10R10UscaledPack32:
case VkFormat.A2B10G10R10SscaledPack32:
return 4;
case VkFormat.R16G16B16Sfloat:
case VkFormat.R16G16B16Unorm:
case VkFormat.R16G16B16SNorm:
case VkFormat.R16G16B16Uint:
case VkFormat.R16G16B16Sint:
case VkFormat.R16G16B16Uscaled:
case VkFormat.R16G16B16Sscaled:
return 6;
case VkFormat.R16G16B16A16Sfloat:
case VkFormat.R16G16B16A16Unorm:
case VkFormat.R16G16B16A16SNorm:
case VkFormat.R16G16B16A16Uint:
case VkFormat.R16G16B16A16Sint:
case VkFormat.R16G16B16A16Uscaled:
case VkFormat.R16G16B16A16Sscaled:
case VkFormat.R32G32Sfloat:
case VkFormat.R32G32Uint:
case VkFormat.R32G32Sint:
return 8;
case VkFormat.R32G32B32Sfloat:
case VkFormat.R32G32B32Uint:
case VkFormat.R32G32B32Sint:
return 12;
case VkFormat.R32G32B32A32Sfloat:
case VkFormat.R32G32B32A32Uint:
case VkFormat.R32G32B32A32Sint:
return 16;
}
return 1;
}
public static VkFormat DropLastComponent(VkFormat format)
{
return format switch
{
VkFormat.R8G8Unorm => VkFormat.R8Unorm,
VkFormat.R8G8SNorm => VkFormat.R8SNorm,
VkFormat.R8G8Uint => VkFormat.R8Uint,
VkFormat.R8G8Sint => VkFormat.R8Sint,
VkFormat.R8G8Uscaled => VkFormat.R8Uscaled,
VkFormat.R8G8Sscaled => VkFormat.R8Sscaled,
VkFormat.R8G8B8Unorm => VkFormat.R8G8Unorm,
VkFormat.R8G8B8SNorm => VkFormat.R8G8SNorm,
VkFormat.R8G8B8Uint => VkFormat.R8G8Uint,
VkFormat.R8G8B8Sint => VkFormat.R8G8Sint,
VkFormat.R8G8B8Uscaled => VkFormat.R8G8Uscaled,
VkFormat.R8G8B8Sscaled => VkFormat.R8G8Sscaled,
VkFormat.R8G8B8A8Unorm => VkFormat.R8G8B8Unorm,
VkFormat.R8G8B8A8SNorm => VkFormat.R8G8B8SNorm,
VkFormat.R8G8B8A8Uint => VkFormat.R8G8B8Uint,
VkFormat.R8G8B8A8Sint => VkFormat.R8G8B8Sint,
VkFormat.R8G8B8A8Srgb => VkFormat.R8G8B8Srgb,
VkFormat.R8G8B8A8Uscaled => VkFormat.R8G8B8Uscaled,
VkFormat.R8G8B8A8Sscaled => VkFormat.R8G8B8Sscaled,
VkFormat.B8G8R8A8Unorm => VkFormat.B8G8R8Unorm,
VkFormat.B8G8R8A8Srgb => VkFormat.B8G8R8Srgb,
VkFormat.R16G16Sfloat => VkFormat.R16Sfloat,
VkFormat.R16G16Unorm => VkFormat.R16Unorm,
VkFormat.R16G16SNorm => VkFormat.R16SNorm,
VkFormat.R16G16Uint => VkFormat.R16Uint,
VkFormat.R16G16Sint => VkFormat.R16Sint,
VkFormat.R16G16Uscaled => VkFormat.R16Uscaled,
VkFormat.R16G16Sscaled => VkFormat.R16Sscaled,
VkFormat.R16G16B16Sfloat => VkFormat.R16G16Sfloat,
VkFormat.R16G16B16Unorm => VkFormat.R16G16Unorm,
VkFormat.R16G16B16SNorm => VkFormat.R16G16SNorm,
VkFormat.R16G16B16Uint => VkFormat.R16G16Uint,
VkFormat.R16G16B16Sint => VkFormat.R16G16Sint,
VkFormat.R16G16B16Uscaled => VkFormat.R16G16Uscaled,
VkFormat.R16G16B16Sscaled => VkFormat.R16G16Sscaled,
VkFormat.R16G16B16A16Sfloat => VkFormat.R16G16B16Sfloat,
VkFormat.R16G16B16A16Unorm => VkFormat.R16G16B16Unorm,
VkFormat.R16G16B16A16SNorm => VkFormat.R16G16B16SNorm,
VkFormat.R16G16B16A16Uint => VkFormat.R16G16B16Uint,
VkFormat.R16G16B16A16Sint => VkFormat.R16G16B16Sint,
VkFormat.R16G16B16A16Uscaled => VkFormat.R16G16B16Uscaled,
VkFormat.R16G16B16A16Sscaled => VkFormat.R16G16B16Sscaled,
VkFormat.R32G32Sfloat => VkFormat.R32Sfloat,
VkFormat.R32G32Uint => VkFormat.R32Uint,
VkFormat.R32G32Sint => VkFormat.R32Sint,
VkFormat.R32G32B32Sfloat => VkFormat.R32G32Sfloat,
VkFormat.R32G32B32Uint => VkFormat.R32G32Uint,
VkFormat.R32G32B32Sint => VkFormat.R32G32Sint,
VkFormat.R32G32B32A32Sfloat => VkFormat.R32G32B32Sfloat,
VkFormat.R32G32B32A32Uint => VkFormat.R32G32B32Uint,
VkFormat.R32G32B32A32Sint => VkFormat.R32G32B32Sint,
_ => format,
};
}
}
}