Skip to content

Commit 831fe30

Browse files
Update ktx2 to 0.4.0 (#19073)
# Objective Adopted #19065 Closes #19065 Updates the requirements on [ktx2](https://github.com/BVE-Reborn/ktx2) to permit the latest version. - [Release notes](https://github.com/BVE-Reborn/ktx2/releases) - [Changelog](https://github.com/BVE-Reborn/ktx2/blob/trunk/CHANGELOG.md) - [Commits](BVE-Reborn/ktx2@v0.3.0...v0.4.0) # Overview - Some renames - A `u8` became `NonZero<u8>` - Some methods return a new `Level` struct with a `data` member instead of raw level data. # Testing - Passed CI locally - Ran several examples which utilize `ktx2` files: `scrolling_fog`, `mixed_lighting`, `skybox`, `lightmaps`. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent ea7e868 commit 831fe30

File tree

3 files changed

+38
-39
lines changed

3 files changed

+38
-39
lines changed

crates/bevy_image/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ futures-lite = "2.0.1"
6666
guillotiere = "0.6.0"
6767
rectangle-pack = "0.4"
6868
ddsfile = { version = "0.5.2", optional = true }
69-
ktx2 = { version = "0.3.0", optional = true }
69+
ktx2 = { version = "0.4.0", optional = true }
7070
# For ktx2 supercompression
7171
flate2 = { version = "1.0.22", optional = true }
7272
ruzstd = { version = "0.8.0", optional = true }

crates/bevy_image/src/ktx2.rs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use bevy_utils::default;
1010
#[cfg(any(feature = "flate2", feature = "ruzstd"))]
1111
use ktx2::SupercompressionScheme;
1212
use ktx2::{
13-
BasicDataFormatDescriptor, ChannelTypeQualifiers, ColorModel, DataFormatDescriptorHeader,
14-
Header, SampleInformation,
13+
ChannelTypeQualifiers, ColorModel, DfdBlockBasic, DfdBlockHeaderBasic, DfdHeader, Header,
14+
SampleInformation,
1515
};
1616
use wgpu_types::{
1717
AstcBlock, AstcChannel, Extent3d, TextureDimension, TextureFormat, TextureViewDescriptor,
@@ -45,28 +45,28 @@ pub fn ktx2_buffer_to_image(
4545
// Handle supercompression
4646
let mut levels = Vec::new();
4747
if let Some(supercompression_scheme) = supercompression_scheme {
48-
for (_level, _level_data) in ktx2.levels().enumerate() {
48+
for (level_index, level) in ktx2.levels().enumerate() {
4949
match supercompression_scheme {
5050
#[cfg(feature = "flate2")]
5151
SupercompressionScheme::ZLIB => {
52-
let mut decoder = flate2::bufread::ZlibDecoder::new(_level_data);
52+
let mut decoder = flate2::bufread::ZlibDecoder::new(level.data);
5353
let mut decompressed = Vec::new();
5454
decoder.read_to_end(&mut decompressed).map_err(|err| {
5555
TextureError::SuperDecompressionError(format!(
56-
"Failed to decompress {supercompression_scheme:?} for mip {_level}: {err:?}",
56+
"Failed to decompress {supercompression_scheme:?} for mip {level_index}: {err:?}",
5757
))
5858
})?;
5959
levels.push(decompressed);
6060
}
6161
#[cfg(feature = "ruzstd")]
6262
SupercompressionScheme::Zstandard => {
63-
let mut cursor = std::io::Cursor::new(_level_data);
63+
let mut cursor = std::io::Cursor::new(level.data);
6464
let mut decoder = ruzstd::decoding::StreamingDecoder::new(&mut cursor)
6565
.map_err(|err| TextureError::SuperDecompressionError(err.to_string()))?;
6666
let mut decompressed = Vec::new();
6767
decoder.read_to_end(&mut decompressed).map_err(|err| {
6868
TextureError::SuperDecompressionError(format!(
69-
"Failed to decompress {supercompression_scheme:?} for mip {_level}: {err:?}",
69+
"Failed to decompress {supercompression_scheme:?} for mip {level_index}: {err:?}",
7070
))
7171
})?;
7272
levels.push(decompressed);
@@ -79,7 +79,7 @@ pub fn ktx2_buffer_to_image(
7979
}
8080
}
8181
} else {
82-
levels = ktx2.levels().map(<[u8]>::to_vec).collect();
82+
levels = ktx2.levels().map(|level| level.data.to_vec()).collect();
8383
}
8484

8585
// Identify the format
@@ -397,16 +397,15 @@ pub fn ktx2_get_texture_format<Data: AsRef<[u8]>>(
397397
return ktx2_format_to_texture_format(format, is_srgb);
398398
}
399399

400-
for data_format_descriptor in ktx2.data_format_descriptors() {
401-
if data_format_descriptor.header == DataFormatDescriptorHeader::BASIC {
402-
let basic_data_format_descriptor =
403-
BasicDataFormatDescriptor::parse(data_format_descriptor.data)
404-
.map_err(|err| TextureError::InvalidData(format!("KTX2: {err:?}")))?;
400+
for data_format_descriptor in ktx2.dfd_blocks() {
401+
if data_format_descriptor.header == DfdHeader::BASIC {
402+
let basic_data_format_descriptor = DfdBlockBasic::parse(data_format_descriptor.data)
403+
.map_err(|err| TextureError::InvalidData(format!("KTX2: {err:?}")))?;
405404
let sample_information = basic_data_format_descriptor
406405
.sample_information()
407406
.collect::<Vec<_>>();
408-
return ktx2_dfd_to_texture_format(
409-
&basic_data_format_descriptor,
407+
return ktx2_dfd_header_to_texture_format(
408+
&basic_data_format_descriptor.header,
410409
&sample_information,
411410
is_srgb,
412411
);
@@ -476,8 +475,8 @@ fn sample_information_to_data_type(
476475
}
477476

478477
#[cfg(feature = "ktx2")]
479-
pub fn ktx2_dfd_to_texture_format(
480-
data_format_descriptor: &BasicDataFormatDescriptor,
478+
pub fn ktx2_dfd_header_to_texture_format(
479+
data_format_descriptor: &DfdBlockHeaderBasic,
481480
sample_information: &[SampleInformation],
482481
is_srgb: bool,
483482
) -> Result<TextureFormat, TextureError> {
@@ -495,7 +494,7 @@ pub fn ktx2_dfd_to_texture_format(
495494

496495
let sample = &sample_information[0];
497496
let data_type = sample_information_to_data_type(sample, false)?;
498-
match sample.bit_length {
497+
match sample.bit_length.get() {
499498
8 => match data_type {
500499
DataType::Unorm => TextureFormat::R8Unorm,
501500
DataType::UnormSrgb => {
@@ -577,7 +576,7 @@ pub fn ktx2_dfd_to_texture_format(
577576

578577
let sample = &sample_information[0];
579578
let data_type = sample_information_to_data_type(sample, false)?;
580-
match sample.bit_length {
579+
match sample.bit_length.get() {
581580
8 => match data_type {
582581
DataType::Unorm => TextureFormat::Rg8Unorm,
583582
DataType::UnormSrgb => {
@@ -635,27 +634,27 @@ pub fn ktx2_dfd_to_texture_format(
635634
}
636635
3 => {
637636
if sample_information[0].channel_type == 0
638-
&& sample_information[0].bit_length == 11
637+
&& sample_information[0].bit_length.get() == 11
639638
&& sample_information[1].channel_type == 1
640-
&& sample_information[1].bit_length == 11
639+
&& sample_information[1].bit_length.get() == 11
641640
&& sample_information[2].channel_type == 2
642-
&& sample_information[2].bit_length == 10
641+
&& sample_information[2].bit_length.get() == 10
643642
{
644643
TextureFormat::Rg11b10Ufloat
645644
} else if sample_information[0].channel_type == 0
646-
&& sample_information[0].bit_length == 9
645+
&& sample_information[0].bit_length.get() == 9
647646
&& sample_information[1].channel_type == 1
648-
&& sample_information[1].bit_length == 9
647+
&& sample_information[1].bit_length.get() == 9
649648
&& sample_information[2].channel_type == 2
650-
&& sample_information[2].bit_length == 9
649+
&& sample_information[2].bit_length.get() == 9
651650
{
652651
TextureFormat::Rgb9e5Ufloat
653652
} else if sample_information[0].channel_type == 0
654-
&& sample_information[0].bit_length == 8
653+
&& sample_information[0].bit_length.get() == 8
655654
&& sample_information[1].channel_type == 1
656-
&& sample_information[1].bit_length == 8
655+
&& sample_information[1].bit_length.get() == 8
657656
&& sample_information[2].channel_type == 2
658-
&& sample_information[2].bit_length == 8
657+
&& sample_information[2].bit_length.get() == 8
659658
{
660659
return Err(TextureError::FormatRequiresTranscodingError(
661660
TranscodeFormat::Rgb8,
@@ -681,10 +680,10 @@ pub fn ktx2_dfd_to_texture_format(
681680
assert_eq!(sample_information[3].channel_type, 15);
682681

683682
// Handle one special packed format
684-
if sample_information[0].bit_length == 10
685-
&& sample_information[1].bit_length == 10
686-
&& sample_information[2].bit_length == 10
687-
&& sample_information[3].bit_length == 2
683+
if sample_information[0].bit_length.get() == 10
684+
&& sample_information[1].bit_length.get() == 10
685+
&& sample_information[2].bit_length.get() == 10
686+
&& sample_information[3].bit_length.get() == 2
688687
{
689688
return Ok(TextureFormat::Rgb10a2Unorm);
690689
}
@@ -708,7 +707,7 @@ pub fn ktx2_dfd_to_texture_format(
708707

709708
let sample = &sample_information[0];
710709
let data_type = sample_information_to_data_type(sample, is_srgb)?;
711-
match sample.bit_length {
710+
match sample.bit_length.get() {
712711
8 => match data_type {
713712
DataType::Unorm => {
714713
if is_rgba {
@@ -896,7 +895,7 @@ pub fn ktx2_dfd_to_texture_format(
896895
Some(ColorModel::XYZW) => {
897896
// Same number of channels in both texel block dimensions and sample info descriptions
898897
assert_eq!(
899-
data_format_descriptor.texel_block_dimensions[0] as usize,
898+
data_format_descriptor.texel_block_dimensions[0].get() as usize,
900899
sample_information.len()
901900
);
902901
match sample_information.len() {
@@ -935,7 +934,7 @@ pub fn ktx2_dfd_to_texture_format(
935934

936935
let sample = &sample_information[0];
937936
let data_type = sample_information_to_data_type(sample, false)?;
938-
match sample.bit_length {
937+
match sample.bit_length.get() {
939938
8 => match data_type {
940939
DataType::Unorm => TextureFormat::Rgba8Unorm,
941940
DataType::UnormSrgb => {
@@ -1124,8 +1123,8 @@ pub fn ktx2_dfd_to_texture_format(
11241123
},
11251124
Some(ColorModel::ASTC) => TextureFormat::Astc {
11261125
block: match (
1127-
data_format_descriptor.texel_block_dimensions[0],
1128-
data_format_descriptor.texel_block_dimensions[1],
1126+
data_format_descriptor.texel_block_dimensions[0].get(),
1127+
data_format_descriptor.texel_block_dimensions[1].get(),
11291128
) {
11301129
(4, 4) => AstcBlock::B4x4,
11311130
(5, 4) => AstcBlock::B5x4,

crates/bevy_render/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ downcast-rs = { version = "2", default-features = false, features = ["std"] }
9797
thiserror = { version = "2", default-features = false }
9898
derive_more = { version = "1", default-features = false, features = ["from"] }
9999
futures-lite = "2.0.1"
100-
ktx2 = { version = "0.3.0", optional = true }
100+
ktx2 = { version = "0.4.0", optional = true }
101101
encase = { version = "0.10", features = ["glam"] }
102102
# For wgpu profiling using tracing. Use `RUST_LOG=info` to also capture the wgpu spans.
103103
profiling = { version = "1", features = [

0 commit comments

Comments
 (0)