Make texture format info into an in-code table

This commit is contained in:
Connor Fitzgerald 2022-02-24 17:15:04 -05:00 committed by Dzmitry Malyshau
parent 129c32ffc3
commit 6979c7fe4c

View File

@ -2012,6 +2012,7 @@ impl TextureFormat {
let all_flags = TextureUsages::all();
// See <https://gpuweb.github.io/gpuweb/#texture-format-caps> for reference
#[rustfmt::skip] // lets make a nice table
let (
required_features,
sample_type,
@ -2023,16 +2024,7 @@ impl TextureFormat {
components,
) = match self {
// Normal 8 bit textures
Self::R8Unorm => (
native,
float,
linear,
msaa_resolve,
(1, 1),
1,
attachment,
1,
),
Self::R8Unorm => ( native, float, linear, msaa_resolve, (1, 1), 1, attachment, 1),
Self::R8Snorm => ( native, float, linear, msaa, (1, 1), 1, basic, 1),
Self::R8Uint => ( native, uint, linear, msaa, (1, 1), 1, attachment, 1),
Self::R8Sint => ( native, sint, linear, msaa, (1, 1), 1, attachment, 1),
@ -2040,26 +2032,8 @@ impl TextureFormat {
// Normal 16 bit textures
Self::R16Uint => ( native, uint, linear, msaa, (1, 1), 2, attachment, 1),
Self::R16Sint => ( native, sint, linear, msaa, (1, 1), 2, attachment, 1),
Self::R16Float => (
native,
float,
linear,
msaa_resolve,
(1, 1),
2,
attachment,
1,
),
Self::Rg8Unorm => (
native,
float,
linear,
msaa_resolve,
(1, 1),
2,
attachment,
2,
),
Self::R16Float => ( native, float, linear, msaa_resolve, (1, 1), 2, attachment, 1),
Self::Rg8Unorm => ( native, float, linear, msaa_resolve, (1, 1), 2, attachment, 2),
Self::Rg8Snorm => ( native, float, linear, msaa, (1, 1), 2, attachment, 2),
Self::Rg8Uint => ( native, uint, linear, msaa, (1, 1), 2, attachment, 2),
Self::Rg8Sint => ( native, sint, linear, msaa, (1, 1), 2, basic, 2),
@ -2070,62 +2044,17 @@ impl TextureFormat {
Self::R32Float => ( native, nearest, linear, msaa, (1, 1), 4, all_flags, 1),
Self::Rg16Uint => ( native, uint, linear, msaa, (1, 1), 4, attachment, 2),
Self::Rg16Sint => ( native, sint, linear, msaa, (1, 1), 4, attachment, 2),
Self::Rg16Float => (
native,
float,
linear,
msaa_resolve,
(1, 1),
4,
attachment,
2,
),
Self::Rg16Float => ( native, float, linear, msaa_resolve, (1, 1), 4, attachment, 2),
Self::Rgba8Unorm => ( native, float, linear, msaa_resolve, (1, 1), 4, all_flags, 4),
Self::Rgba8UnormSrgb => (
native,
float,
corrected,
msaa_resolve,
(1, 1),
4,
attachment,
4,
),
Self::Rgba8UnormSrgb => ( native, float, corrected, msaa_resolve, (1, 1), 4, attachment, 4),
Self::Rgba8Snorm => ( native, float, linear, msaa, (1, 1), 4, storage, 4),
Self::Rgba8Uint => ( native, uint, linear, msaa, (1, 1), 4, all_flags, 4),
Self::Rgba8Sint => ( native, sint, linear, msaa, (1, 1), 4, all_flags, 4),
Self::Bgra8Unorm => (
native,
float,
linear,
msaa_resolve,
(1, 1),
4,
attachment,
4,
),
Self::Bgra8UnormSrgb => (
native,
float,
corrected,
msaa_resolve,
(1, 1),
4,
attachment,
4,
),
Self::Bgra8Unorm => ( native, float, linear, msaa_resolve, (1, 1), 4, attachment, 4),
Self::Bgra8UnormSrgb => ( native, float, corrected, msaa_resolve, (1, 1), 4, attachment, 4),
// Packed 32 bit textures
Self::Rgb10a2Unorm => (
native,
float,
linear,
msaa_resolve,
(1, 1),
4,
attachment,
4,
),
Self::Rgb10a2Unorm => ( native, float, linear, msaa_resolve, (1, 1), 4, attachment, 4),
Self::Rg11b10Float => ( native, float, linear, msaa, (1, 1), 4, basic, 3),
// Packed 32 bit textures
@ -2149,6 +2078,14 @@ impl TextureFormat {
// Packed uncompressed
Self::Rgb9e5Ufloat => ( native, float, linear, noaa, (1, 1), 4, basic, 3),
// Optional normalized 16-bit-per-channel formats
Self::R16Unorm => (norm16bit, float, linear, msaa, (1, 1), 2, storage, 1),
Self::R16Snorm => (norm16bit, float, linear, msaa, (1, 1), 2, storage, 1),
Self::Rg16Unorm => (norm16bit, float, linear, msaa, (1, 1), 4, storage, 2),
Self::Rg16Snorm => (norm16bit, float, linear, msaa, (1, 1), 4, storage, 2),
Self::Rgba16Unorm => (norm16bit, float, linear, msaa, (1, 1), 8, storage, 4),
Self::Rgba16Snorm => (norm16bit, float, linear, msaa, (1, 1), 8, storage, 4),
// BCn compressed textures
Self::Bc1RgbaUnorm => ( bc, float, linear, noaa, (4, 4), 8, basic, 4),
Self::Bc1RgbaUnormSrgb => ( bc, float, corrected, noaa, (4, 4), 8, basic, 4),
@ -2202,14 +2139,6 @@ impl TextureFormat {
};
(feature, float, color_space, noaa, dimensions, 16, basic, 4)
}
// Optional normalized 16-bit-per-channel formats
Self::R16Unorm => (norm16bit, float, linear, msaa, (1, 1), 2, storage, 1),
Self::R16Snorm => (norm16bit, float, linear, msaa, (1, 1), 2, storage, 1),
Self::Rg16Unorm => (norm16bit, float, linear, msaa, (1, 1), 4, storage, 2),
Self::Rg16Snorm => (norm16bit, float, linear, msaa, (1, 1), 4, storage, 2),
Self::Rgba16Unorm => (norm16bit, float, linear, msaa, (1, 1), 8, storage, 4),
Self::Rgba16Snorm => (norm16bit, float, linear, msaa, (1, 1), 8, storage, 4),
};
let mut flags = msaa_flags;