mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
ETC2 texture format refactor (#2064)
This commit is contained in:
@@ -691,8 +691,10 @@ impl NumericType {
|
||||
| Tf::Bc3RgbaUnormSrgb
|
||||
| Tf::Bc7RgbaUnorm
|
||||
| Tf::Bc7RgbaUnormSrgb
|
||||
| Tf::Etc2RgbA1Unorm
|
||||
| Tf::Etc2RgbA1UnormSrgb
|
||||
| Tf::Etc2Rgb8A1Unorm
|
||||
| Tf::Etc2Rgb8A1UnormSrgb
|
||||
| Tf::Etc2Rgba8Unorm
|
||||
| Tf::Etc2Rgba8UnormSrgb
|
||||
| Tf::Astc4x4RgbaUnorm
|
||||
| Tf::Astc4x4RgbaUnormSrgb
|
||||
| Tf::Astc5x4RgbaUnorm
|
||||
@@ -721,13 +723,13 @@ impl NumericType {
|
||||
| Tf::Astc12x10RgbaUnormSrgb
|
||||
| Tf::Astc12x12RgbaUnorm
|
||||
| Tf::Astc12x12RgbaUnormSrgb => (NumericDimension::Vector(Vs::Quad), Sk::Float),
|
||||
Tf::Bc4RUnorm | Tf::Bc4RSnorm | Tf::EacRUnorm | Tf::EacRSnorm => {
|
||||
Tf::Bc4RUnorm | Tf::Bc4RSnorm | Tf::EacR11Unorm | Tf::EacR11Snorm => {
|
||||
(NumericDimension::Scalar, Sk::Float)
|
||||
}
|
||||
Tf::Bc5RgUnorm | Tf::Bc5RgSnorm | Tf::EacRgUnorm | Tf::EacRgSnorm => {
|
||||
Tf::Bc5RgUnorm | Tf::Bc5RgSnorm | Tf::EacRg11Unorm | Tf::EacRg11Snorm => {
|
||||
(NumericDimension::Vector(Vs::Bi), Sk::Float)
|
||||
}
|
||||
Tf::Bc6hRgbUfloat | Tf::Bc6hRgbSfloat | Tf::Etc2RgbUnorm | Tf::Etc2RgbUnormSrgb => {
|
||||
Tf::Bc6hRgbUfloat | Tf::Bc6hRgbSfloat | Tf::Etc2Rgb8Unorm | Tf::Etc2Rgb8UnormSrgb => {
|
||||
(NumericDimension::Vector(Vs::Tri), Sk::Float)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -62,14 +62,16 @@ pub(super) fn map_texture_format(format: wgt::TextureFormat) -> dxgiformat::DXGI
|
||||
Tf::Bc6hRgbSfloat => DXGI_FORMAT_BC6H_SF16,
|
||||
Tf::Bc7RgbaUnorm => DXGI_FORMAT_BC7_UNORM,
|
||||
Tf::Bc7RgbaUnormSrgb => DXGI_FORMAT_BC7_UNORM_SRGB,
|
||||
Tf::Etc2RgbUnorm
|
||||
| Tf::Etc2RgbUnormSrgb
|
||||
| Tf::Etc2RgbA1Unorm
|
||||
| Tf::Etc2RgbA1UnormSrgb
|
||||
| Tf::EacRUnorm
|
||||
| Tf::EacRSnorm
|
||||
| Tf::EacRgUnorm
|
||||
| Tf::EacRgSnorm
|
||||
Tf::Etc2Rgb8Unorm
|
||||
| Tf::Etc2Rgb8UnormSrgb
|
||||
| Tf::Etc2Rgb8A1Unorm
|
||||
| Tf::Etc2Rgb8A1UnormSrgb
|
||||
| Tf::Etc2Rgba8Unorm
|
||||
| Tf::Etc2Rgba8UnormSrgb
|
||||
| Tf::EacR11Unorm
|
||||
| Tf::EacR11Snorm
|
||||
| Tf::EacRg11Unorm
|
||||
| Tf::EacRg11Snorm
|
||||
| Tf::Astc4x4RgbaUnorm
|
||||
| Tf::Astc4x4RgbaUnormSrgb
|
||||
| Tf::Astc5x4RgbaUnorm
|
||||
|
||||
@@ -550,14 +550,16 @@ impl crate::Adapter<super::Api> for super::Adapter {
|
||||
| Tf::Bc6hRgbUfloat
|
||||
| Tf::Bc7RgbaUnorm
|
||||
| Tf::Bc7RgbaUnormSrgb
|
||||
| Tf::Etc2RgbUnorm
|
||||
| Tf::Etc2RgbUnormSrgb
|
||||
| Tf::Etc2RgbA1Unorm
|
||||
| Tf::Etc2RgbA1UnormSrgb
|
||||
| Tf::EacRUnorm
|
||||
| Tf::EacRSnorm
|
||||
| Tf::EacRgUnorm
|
||||
| Tf::EacRgSnorm
|
||||
| Tf::Etc2Rgb8Unorm
|
||||
| Tf::Etc2Rgb8UnormSrgb
|
||||
| Tf::Etc2Rgb8A1Unorm
|
||||
| Tf::Etc2Rgb8A1UnormSrgb
|
||||
| Tf::Etc2Rgba8Unorm
|
||||
| Tf::Etc2Rgba8UnormSrgb
|
||||
| Tf::EacR11Unorm
|
||||
| Tf::EacR11Snorm
|
||||
| Tf::EacRg11Unorm
|
||||
| Tf::EacRg11Snorm
|
||||
| Tf::Astc4x4RgbaUnorm
|
||||
| Tf::Astc4x4RgbaUnormSrgb
|
||||
| Tf::Astc5x4RgbaUnorm
|
||||
|
||||
@@ -75,22 +75,29 @@ impl super::AdapterShared {
|
||||
| Tf::Bc6hRgbSfloat
|
||||
| Tf::Bc7RgbaUnorm
|
||||
| Tf::Bc7RgbaUnormSrgb => unimplemented!(),
|
||||
Tf::Etc2RgbUnorm => (glow::COMPRESSED_RGB8_ETC2, glow::RGB, 0),
|
||||
Tf::Etc2RgbUnormSrgb => (glow::COMPRESSED_SRGB8_ETC2, glow::RGB, 0),
|
||||
Tf::Etc2RgbA1Unorm => (
|
||||
Tf::Etc2Rgb8Unorm => (glow::COMPRESSED_RGB8_ETC2, glow::RGB, 0),
|
||||
Tf::Etc2Rgb8UnormSrgb => (glow::COMPRESSED_SRGB8_ETC2, glow::RGB, 0),
|
||||
Tf::Etc2Rgb8A1Unorm => (
|
||||
glow::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
|
||||
glow::RGBA,
|
||||
0,
|
||||
),
|
||||
Tf::Etc2RgbA1UnormSrgb => (
|
||||
Tf::Etc2Rgb8A1UnormSrgb => (
|
||||
glow::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
|
||||
glow::RGBA,
|
||||
0,
|
||||
),
|
||||
Tf::EacRUnorm => (glow::COMPRESSED_R11_EAC, glow::RED, 0),
|
||||
Tf::EacRSnorm => (glow::COMPRESSED_SIGNED_R11_EAC, glow::RED, 0),
|
||||
Tf::EacRgUnorm => (glow::COMPRESSED_RG11_EAC, glow::RG, 0),
|
||||
Tf::EacRgSnorm => (glow::COMPRESSED_SIGNED_RG11_EAC, glow::RG, 0),
|
||||
Tf::Etc2Rgba8Unorm => (
|
||||
//TODO: this is a lie, it's not sRGB
|
||||
glow::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
|
||||
glow::RGBA,
|
||||
0,
|
||||
),
|
||||
Tf::Etc2Rgba8UnormSrgb => (glow::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, glow::RGBA, 0),
|
||||
Tf::EacR11Unorm => (glow::COMPRESSED_R11_EAC, glow::RED, 0),
|
||||
Tf::EacR11Snorm => (glow::COMPRESSED_SIGNED_R11_EAC, glow::RED, 0),
|
||||
Tf::EacRg11Unorm => (glow::COMPRESSED_RG11_EAC, glow::RG, 0),
|
||||
Tf::EacRg11Snorm => (glow::COMPRESSED_SIGNED_RG11_EAC, glow::RG, 0),
|
||||
Tf::Astc4x4RgbaUnorm
|
||||
| Tf::Astc4x4RgbaUnormSrgb
|
||||
| Tf::Astc5x4RgbaUnorm
|
||||
|
||||
@@ -217,14 +217,16 @@ impl crate::Adapter<super::Api> for super::Adapter {
|
||||
Tfc::empty()
|
||||
}
|
||||
}
|
||||
Tf::Etc2RgbUnorm
|
||||
| Tf::Etc2RgbUnormSrgb
|
||||
| Tf::Etc2RgbA1Unorm
|
||||
| Tf::Etc2RgbA1UnormSrgb
|
||||
| Tf::EacRUnorm
|
||||
| Tf::EacRSnorm
|
||||
| Tf::EacRgUnorm
|
||||
| Tf::EacRgSnorm => {
|
||||
Tf::Etc2Rgb8Unorm
|
||||
| Tf::Etc2Rgb8UnormSrgb
|
||||
| Tf::Etc2Rgb8A1Unorm
|
||||
| Tf::Etc2Rgb8A1UnormSrgb
|
||||
| Tf::Etc2Rgba8Unorm
|
||||
| Tf::Etc2Rgba8UnormSrgb
|
||||
| Tf::EacR11Unorm
|
||||
| Tf::EacR11Snorm
|
||||
| Tf::EacRg11Unorm
|
||||
| Tf::EacRg11Snorm => {
|
||||
if pc.format_eac_etc {
|
||||
Tfc::SAMPLED_LINEAR
|
||||
} else {
|
||||
@@ -1018,14 +1020,16 @@ impl super::PrivateCapabilities {
|
||||
Tf::Bc6hRgbUfloat => BC6H_RGBUfloat,
|
||||
Tf::Bc7RgbaUnorm => BC7_RGBAUnorm,
|
||||
Tf::Bc7RgbaUnormSrgb => BC7_RGBAUnorm_sRGB,
|
||||
Tf::Etc2RgbUnorm => ETC2_RGB8,
|
||||
Tf::Etc2RgbUnormSrgb => ETC2_RGB8_sRGB,
|
||||
Tf::Etc2RgbA1Unorm => ETC2_RGB8A1,
|
||||
Tf::Etc2RgbA1UnormSrgb => ETC2_RGB8A1_sRGB,
|
||||
Tf::EacRUnorm => EAC_R11Unorm,
|
||||
Tf::EacRSnorm => EAC_R11Snorm,
|
||||
Tf::EacRgUnorm => EAC_RG11Unorm,
|
||||
Tf::EacRgSnorm => EAC_RG11Snorm,
|
||||
Tf::Etc2Rgb8Unorm => ETC2_RGB8,
|
||||
Tf::Etc2Rgb8UnormSrgb => ETC2_RGB8_sRGB,
|
||||
Tf::Etc2Rgb8A1Unorm => ETC2_RGB8A1,
|
||||
Tf::Etc2Rgb8A1UnormSrgb => ETC2_RGB8A1_sRGB,
|
||||
Tf::Etc2Rgba8Unorm => EAC_RGBA8,
|
||||
Tf::Etc2Rgba8UnormSrgb => EAC_RGBA8_sRGB,
|
||||
Tf::EacR11Unorm => EAC_R11Unorm,
|
||||
Tf::EacR11Snorm => EAC_R11Snorm,
|
||||
Tf::EacRg11Unorm => EAC_RG11Unorm,
|
||||
Tf::EacRg11Snorm => EAC_RG11Snorm,
|
||||
Tf::Astc4x4RgbaUnorm => ASTC_4x4_LDR,
|
||||
Tf::Astc4x4RgbaUnormSrgb => ASTC_4x4_sRGB,
|
||||
Tf::Astc5x4RgbaUnorm => ASTC_5x4_LDR,
|
||||
|
||||
@@ -71,14 +71,16 @@ impl super::PrivateCapabilities {
|
||||
Tf::Bc6hRgbSfloat => F::BC6H_SFLOAT_BLOCK,
|
||||
Tf::Bc7RgbaUnorm => F::BC7_UNORM_BLOCK,
|
||||
Tf::Bc7RgbaUnormSrgb => F::BC7_SRGB_BLOCK,
|
||||
Tf::Etc2RgbUnorm => F::ETC2_R8G8B8_UNORM_BLOCK,
|
||||
Tf::Etc2RgbUnormSrgb => F::ETC2_R8G8B8_SRGB_BLOCK,
|
||||
Tf::Etc2RgbA1Unorm => F::ETC2_R8G8B8A1_UNORM_BLOCK,
|
||||
Tf::Etc2RgbA1UnormSrgb => F::ETC2_R8G8B8A1_SRGB_BLOCK,
|
||||
Tf::EacRUnorm => F::EAC_R11_UNORM_BLOCK,
|
||||
Tf::EacRSnorm => F::EAC_R11_SNORM_BLOCK,
|
||||
Tf::EacRgUnorm => F::EAC_R11G11_UNORM_BLOCK,
|
||||
Tf::EacRgSnorm => F::EAC_R11G11_SNORM_BLOCK,
|
||||
Tf::Etc2Rgb8Unorm => F::ETC2_R8G8B8_UNORM_BLOCK,
|
||||
Tf::Etc2Rgb8UnormSrgb => F::ETC2_R8G8B8_SRGB_BLOCK,
|
||||
Tf::Etc2Rgb8A1Unorm => F::ETC2_R8G8B8A1_UNORM_BLOCK,
|
||||
Tf::Etc2Rgb8A1UnormSrgb => F::ETC2_R8G8B8A1_SRGB_BLOCK,
|
||||
Tf::Etc2Rgba8Unorm => F::ETC2_R8G8B8A8_UNORM_BLOCK,
|
||||
Tf::Etc2Rgba8UnormSrgb => F::ETC2_R8G8B8A8_SRGB_BLOCK,
|
||||
Tf::EacR11Unorm => F::EAC_R11_UNORM_BLOCK,
|
||||
Tf::EacR11Snorm => F::EAC_R11_SNORM_BLOCK,
|
||||
Tf::EacRg11Unorm => F::EAC_R11G11_UNORM_BLOCK,
|
||||
Tf::EacRg11Snorm => F::EAC_R11G11_SNORM_BLOCK,
|
||||
Tf::Astc4x4RgbaUnorm => F::ASTC_4X4_UNORM_BLOCK,
|
||||
Tf::Astc4x4RgbaUnormSrgb => F::ASTC_4X4_SRGB_BLOCK,
|
||||
Tf::Astc5x4RgbaUnorm => F::ASTC_5X4_UNORM_BLOCK,
|
||||
|
||||
@@ -1650,52 +1650,52 @@ pub enum TextureFormat {
|
||||
/// [0, 255] converted to/from float [0, 1] in shader.
|
||||
///
|
||||
/// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format.
|
||||
Etc2RgbUnorm,
|
||||
Etc2Rgb8Unorm,
|
||||
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB.
|
||||
/// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader.
|
||||
///
|
||||
/// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format.
|
||||
Etc2RgbUnormSrgb,
|
||||
Etc2Rgb8UnormSrgb,
|
||||
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB + 1 bit alpha.
|
||||
/// [0, 255] ([0, 1] for alpha) converted to/from float [0, 1] in shader.
|
||||
///
|
||||
/// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format.
|
||||
Etc2RgbA1Unorm,
|
||||
Etc2Rgb8A1Unorm,
|
||||
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB + 1 bit alpha.
|
||||
/// Srgb-color [0, 255] ([0, 1] for alpha) converted to/from linear-color float [0, 1] in shader.
|
||||
///
|
||||
/// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format.
|
||||
Etc2RgbA1UnormSrgb,
|
||||
Etc2Rgb8A1UnormSrgb,
|
||||
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer RGB + 8 bit alpha.
|
||||
/// [0, 255] converted to/from float [0, 1] in shader.
|
||||
///
|
||||
/// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format.
|
||||
//Etc2RgbA8Unorm,
|
||||
Etc2Rgba8Unorm,
|
||||
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer RGB + 8 bit alpha.
|
||||
/// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader.
|
||||
///
|
||||
/// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format.
|
||||
//Etc2RgbA8UnormSrgb,
|
||||
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer R.
|
||||
Etc2Rgba8UnormSrgb,
|
||||
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 11 bit integer R.
|
||||
/// [0, 255] converted to/from float [0, 1] in shader.
|
||||
///
|
||||
/// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format.
|
||||
EacRUnorm,
|
||||
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer R.
|
||||
EacR11Unorm,
|
||||
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 11 bit integer R.
|
||||
/// [-127, 127] converted to/from float [-1, 1] in shader.
|
||||
///
|
||||
/// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format.
|
||||
EacRSnorm,
|
||||
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer R + 8 bit integer G.
|
||||
EacR11Snorm,
|
||||
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 11 bit integer R + 11 bit integer G.
|
||||
/// [0, 255] converted to/from float [0, 1] in shader.
|
||||
///
|
||||
/// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format.
|
||||
EacRgUnorm,
|
||||
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer R + 8 bit integer G.
|
||||
EacRg11Unorm,
|
||||
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 11 bit integer R + 11 bit integer G.
|
||||
/// [-127, 127] converted to/from float [-1, 1] in shader.
|
||||
///
|
||||
/// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format.
|
||||
EacRgSnorm,
|
||||
EacRg11Snorm,
|
||||
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer RGBA.
|
||||
/// [0, 255] converted to/from float [0, 1] in shader.
|
||||
///
|
||||
@@ -1947,16 +1947,16 @@ impl TextureFormat {
|
||||
Self::Bc7RgbaUnormSrgb => (bc, float, srgb, (4, 4), 16, basic, 4),
|
||||
|
||||
// ETC compressed textures
|
||||
Self::Etc2RgbUnorm => (etc2, float, linear, (4, 4), 8, basic, 3),
|
||||
Self::Etc2RgbUnormSrgb => (etc2, float, srgb, (4, 4), 8, basic, 3),
|
||||
Self::Etc2RgbA1Unorm => (etc2, float, linear, (4, 4), 8, basic, 4),
|
||||
Self::Etc2RgbA1UnormSrgb => (etc2, float, srgb, (4, 4), 8, basic, 4),
|
||||
//Self::Etc2RgbA8Unorm => (etc2, float, linear, (4, 4), 16, basic),
|
||||
//Self::Etc2RgbA8UnormSrgb => (etc2, float, srgb, (4, 4), 16, basic),
|
||||
Self::EacRUnorm => (etc2, float, linear, (4, 4), 8, basic, 1),
|
||||
Self::EacRSnorm => (etc2, float, linear, (4, 4), 8, basic, 1),
|
||||
Self::EacRgUnorm => (etc2, float, linear, (4, 4), 16, basic, 2),
|
||||
Self::EacRgSnorm => (etc2, float, linear, (4, 4), 16, basic, 2),
|
||||
Self::Etc2Rgb8Unorm => (etc2, float, linear, (4, 4), 8, basic, 3),
|
||||
Self::Etc2Rgb8UnormSrgb => (etc2, float, srgb, (4, 4), 8, basic, 3),
|
||||
Self::Etc2Rgb8A1Unorm => (etc2, float, linear, (4, 4), 8, basic, 4),
|
||||
Self::Etc2Rgb8A1UnormSrgb => (etc2, float, srgb, (4, 4), 8, basic, 4),
|
||||
Self::Etc2Rgba8Unorm => (etc2, float, linear, (4, 4), 16, basic, 4),
|
||||
Self::Etc2Rgba8UnormSrgb => (etc2, float, srgb, (4, 4), 16, basic, 4),
|
||||
Self::EacR11Unorm => (etc2, float, linear, (4, 4), 8, basic, 1),
|
||||
Self::EacR11Snorm => (etc2, float, linear, (4, 4), 8, basic, 1),
|
||||
Self::EacRg11Unorm => (etc2, float, linear, (4, 4), 16, basic, 2),
|
||||
Self::EacRg11Snorm => (etc2, float, linear, (4, 4), 16, basic, 2),
|
||||
|
||||
// ASTC compressed textures
|
||||
Self::Astc4x4RgbaUnorm => (astc_ldr, float, linear, (4, 4), 16, basic, 4),
|
||||
|
||||
@@ -277,7 +277,7 @@ impl framework::Example for Skybox {
|
||||
wgpu::TextureFormat::Astc4x4RgbaUnormSrgb
|
||||
} else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ETC2) {
|
||||
log::info!("Using ETC2");
|
||||
wgpu::TextureFormat::Etc2RgbUnormSrgb
|
||||
wgpu::TextureFormat::Etc2Rgb8UnormSrgb
|
||||
} else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_BC) {
|
||||
log::info!("Using BC");
|
||||
wgpu::TextureFormat::Bc1RgbaUnormSrgb
|
||||
@@ -308,7 +308,7 @@ impl framework::Example for Skybox {
|
||||
|
||||
let bytes = match skybox_format {
|
||||
wgpu::TextureFormat::Astc4x4RgbaUnormSrgb => &include_bytes!("images/astc.dds")[..],
|
||||
wgpu::TextureFormat::Etc2RgbUnormSrgb => &include_bytes!("images/etc2.dds")[..],
|
||||
wgpu::TextureFormat::Etc2Rgb8UnormSrgb => &include_bytes!("images/etc2.dds")[..],
|
||||
wgpu::TextureFormat::Bc1RgbaUnormSrgb => &include_bytes!("images/bc1.dds")[..],
|
||||
wgpu::TextureFormat::Bgra8UnormSrgb => &include_bytes!("images/bgra.dds")[..],
|
||||
_ => unreachable!(),
|
||||
|
||||
Reference in New Issue
Block a user