Skip to content

Commit 1407f35

Browse files
beicausetychedelia
authored andcommitted
KTX2: Support ASTC HDR (bevyengine#21886)
# Objective ASTC HDR support is missing for ktx2 image loader. ## Solution Add support for it. ## Testing I compressed the `CircuitBoardLightmap.hdr` to astc_4x4_hdr and bc6h_ufloat and made use of them in depth of field example. Tested on Android and Linux desktop.
1 parent 2498d2f commit 1407f35

2 files changed

Lines changed: 73 additions & 2 deletions

File tree

crates/bevy_image/src/image.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,9 @@ impl Image {
15101510
format_description
15111511
.required_features()
15121512
.contains(Features::TEXTURE_COMPRESSION_ASTC)
1513+
|| format_description
1514+
.required_features()
1515+
.contains(Features::TEXTURE_COMPRESSION_ASTC_HDR)
15131516
|| format_description
15141517
.required_features()
15151518
.contains(Features::TEXTURE_COMPRESSION_BC)
@@ -2215,6 +2218,11 @@ bitflags::bitflags! {
22152218
///
22162219
/// [ASTC Format Specification]: https://registry.khronos.org/DataFormat/specs/1.3/dataformat.1.3.html#ASTC
22172220
const ASTC_LDR = 1 << 0;
2221+
/// Support for ASTC HDR textures.
2222+
///
2223+
/// For more information see:
2224+
/// - [`Features::TEXTURE_COMPRESSION_ASTC_HDR`]
2225+
const ASTC_HDR = 1 << 1;
22182226
/// Support for Block Compressed textures.
22192227
///
22202228
/// For more information see:
@@ -2226,15 +2234,15 @@ bitflags::bitflags! {
22262234
/// [S3TC Format Specification]: https://registry.khronos.org/DataFormat/specs/1.3/dataformat.1.3.html#S3TC
22272235
/// [RGTC Format Specification]: https://registry.khronos.org/DataFormat/specs/1.3/dataformat.1.3.html#RGTC
22282236
/// [BPTC Format Specification]: https://registry.khronos.org/DataFormat/specs/1.3/dataformat.1.3.html#BPTC
2229-
const BC = 1 << 1;
2237+
const BC = 1 << 2;
22302238
/// Support for Ericsson Texture Compression.
22312239
///
22322240
/// For more information see:
22332241
/// - [`Features::TEXTURE_COMPRESSION_ETC2`]
22342242
/// - [ETC2 Format Specification]
22352243
///
22362244
/// [ETC2 Format Specification]: https://registry.khronos.org/DataFormat/specs/1.3/dataformat.1.3.html#ETC2
2237-
const ETC2 = 1 << 2;
2245+
const ETC2 = 1 << 3;
22382246
}
22392247
}
22402248

@@ -2245,6 +2253,9 @@ impl CompressedImageFormats {
22452253
if features.contains(Features::TEXTURE_COMPRESSION_ASTC) {
22462254
supported_compressed_formats |= Self::ASTC_LDR;
22472255
}
2256+
if features.contains(Features::TEXTURE_COMPRESSION_ASTC_HDR) {
2257+
supported_compressed_formats |= Self::ASTC_HDR;
2258+
}
22482259
if features.contains(Features::TEXTURE_COMPRESSION_BC) {
22492260
supported_compressed_formats |= Self::BC;
22502261
}
@@ -2284,6 +2295,10 @@ impl CompressedImageFormats {
22842295
| TextureFormat::EacR11Snorm
22852296
| TextureFormat::EacRg11Unorm
22862297
| TextureFormat::EacRg11Snorm => self.contains(CompressedImageFormats::ETC2),
2298+
TextureFormat::Astc {
2299+
channel: wgpu_types::AstcChannel::Hdr,
2300+
..
2301+
} => self.contains(CompressedImageFormats::ASTC_HDR),
22872302
TextureFormat::Astc { .. } => self.contains(CompressedImageFormats::ASTC_LDR),
22882303
_ => true,
22892304
}

crates/bevy_image/src/ktx2.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,62 @@ pub fn ktx2_format_to_texture_format(
14991499
},
15001500
}
15011501
}
1502+
ktx2::Format::ASTC_4x4_SFLOAT_BLOCK => TextureFormat::Astc {
1503+
block: AstcBlock::B4x4,
1504+
channel: AstcChannel::Hdr,
1505+
},
1506+
ktx2::Format::ASTC_5x4_SFLOAT_BLOCK => TextureFormat::Astc {
1507+
block: AstcBlock::B5x4,
1508+
channel: AstcChannel::Hdr,
1509+
},
1510+
ktx2::Format::ASTC_5x5_SFLOAT_BLOCK => TextureFormat::Astc {
1511+
block: AstcBlock::B5x5,
1512+
channel: AstcChannel::Hdr,
1513+
},
1514+
ktx2::Format::ASTC_6x5_SFLOAT_BLOCK => TextureFormat::Astc {
1515+
block: AstcBlock::B6x5,
1516+
channel: AstcChannel::Hdr,
1517+
},
1518+
ktx2::Format::ASTC_6x6_SFLOAT_BLOCK => TextureFormat::Astc {
1519+
block: AstcBlock::B6x6,
1520+
channel: AstcChannel::Hdr,
1521+
},
1522+
ktx2::Format::ASTC_8x5_SFLOAT_BLOCK => TextureFormat::Astc {
1523+
block: AstcBlock::B8x5,
1524+
channel: AstcChannel::Hdr,
1525+
},
1526+
ktx2::Format::ASTC_8x6_SFLOAT_BLOCK => TextureFormat::Astc {
1527+
block: AstcBlock::B8x6,
1528+
channel: AstcChannel::Hdr,
1529+
},
1530+
ktx2::Format::ASTC_8x8_SFLOAT_BLOCK => TextureFormat::Astc {
1531+
block: AstcBlock::B8x8,
1532+
channel: AstcChannel::Hdr,
1533+
},
1534+
ktx2::Format::ASTC_10x5_SFLOAT_BLOCK => TextureFormat::Astc {
1535+
block: AstcBlock::B10x5,
1536+
channel: AstcChannel::Hdr,
1537+
},
1538+
ktx2::Format::ASTC_10x6_SFLOAT_BLOCK => TextureFormat::Astc {
1539+
block: AstcBlock::B10x6,
1540+
channel: AstcChannel::Hdr,
1541+
},
1542+
ktx2::Format::ASTC_10x8_SFLOAT_BLOCK => TextureFormat::Astc {
1543+
block: AstcBlock::B10x8,
1544+
channel: AstcChannel::Hdr,
1545+
},
1546+
ktx2::Format::ASTC_10x10_SFLOAT_BLOCK => TextureFormat::Astc {
1547+
block: AstcBlock::B10x10,
1548+
channel: AstcChannel::Hdr,
1549+
},
1550+
ktx2::Format::ASTC_12x10_SFLOAT_BLOCK => TextureFormat::Astc {
1551+
block: AstcBlock::B12x10,
1552+
channel: AstcChannel::Hdr,
1553+
},
1554+
ktx2::Format::ASTC_12x12_SFLOAT_BLOCK => TextureFormat::Astc {
1555+
block: AstcBlock::B12x12,
1556+
channel: AstcChannel::Hdr,
1557+
},
15021558
_ => {
15031559
return Err(TextureError::UnsupportedTextureFormat(format!(
15041560
"{ktx2_format:?}"

0 commit comments

Comments
 (0)