diff --git a/crates/bevy_core_pipeline/Cargo.toml b/crates/bevy_core_pipeline/Cargo.toml index 7151f7e437..dcee2df7f5 100644 --- a/crates/bevy_core_pipeline/Cargo.toml +++ b/crates/bevy_core_pipeline/Cargo.toml @@ -13,6 +13,7 @@ license = "MIT OR Apache-2.0" keywords = ["bevy"] [features] +dds = [] trace = [] webgl = [] webgpu = [] diff --git a/crates/bevy_core_pipeline/src/tonemapping/mod.rs b/crates/bevy_core_pipeline/src/tonemapping/mod.rs index 0c230deb05..0045d9e050 100644 --- a/crates/bevy_core_pipeline/src/tonemapping/mod.rs +++ b/crates/bevy_core_pipeline/src/tonemapping/mod.rs @@ -355,6 +355,8 @@ fn setup_tonemapping_lut_image(bytes: &[u8], image_type: ImageType) -> Image { ..default() }); Image::from_buffer( + #[cfg(all(debug_assertions, feature = "dds"))] + "Tonemapping LUT sampler".to_string(), bytes, image_type, CompressedImageFormats::NONE, diff --git a/crates/bevy_gltf/Cargo.toml b/crates/bevy_gltf/Cargo.toml index 05cbd9a940..78306fd6db 100644 --- a/crates/bevy_gltf/Cargo.toml +++ b/crates/bevy_gltf/Cargo.toml @@ -9,6 +9,7 @@ license = "MIT OR Apache-2.0" keywords = ["bevy"] [features] +dds = [] pbr_transmission_textures = [] [dependencies] diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index e04eb97eb9..2ce9c2162c 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -733,12 +733,18 @@ async fn load_image<'a, 'b>( ) -> Result { let is_srgb = !linear_textures.contains(&gltf_texture.index()); let sampler_descriptor = texture_sampler(&gltf_texture); + #[cfg(all(debug_assertions, feature = "dds"))] + let name = gltf_texture + .name() + .map_or("Unknown GLTF Texture".to_string(), |s| s.to_string()); match gltf_texture.source().source() { gltf::image::Source::View { view, mime_type } => { let start = view.offset(); let end = view.offset() + view.length(); let buffer = &buffer_data[view.buffer().index()][start..end]; let image = Image::from_buffer( + #[cfg(all(debug_assertions, feature = "dds"))] + name, buffer, ImageType::MimeType(mime_type), supported_compressed_formats, @@ -761,6 +767,8 @@ async fn load_image<'a, 'b>( let image_type = ImageType::MimeType(data_uri.mime_type); Ok(ImageOrPath::Image { image: Image::from_buffer( + #[cfg(all(debug_assertions, feature = "dds"))] + name, &bytes, mime_type.map(ImageType::MimeType).unwrap_or(image_type), supported_compressed_formats, diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 32c0068f64..a92f3f6ba0 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -34,7 +34,7 @@ jpeg = ["bevy_render/jpeg"] bmp = ["bevy_render/bmp"] webp = ["bevy_render/webp"] basis-universal = ["bevy_render/basis-universal"] -dds = ["bevy_render/dds"] +dds = ["bevy_render/dds", "bevy_core_pipeline/dds", "bevy_gltf/dds"] pnm = ["bevy_render/pnm"] ktx2 = ["bevy_render/ktx2"] # For ktx2 supercompression diff --git a/crates/bevy_render/src/texture/dds.rs b/crates/bevy_render/src/texture/dds.rs index 16f1aa7240..b3ae1e7cfe 100644 --- a/crates/bevy_render/src/texture/dds.rs +++ b/crates/bevy_render/src/texture/dds.rs @@ -1,3 +1,5 @@ +#[cfg(debug_assertions)] +use bevy_utils::warn_once; use ddsfile::{Caps2, D3DFormat, Dds, DxgiFormat}; use std::io::Cursor; use wgpu::{ @@ -7,6 +9,7 @@ use wgpu::{ use super::{CompressedImageFormats, Image, TextureError}; pub fn dds_buffer_to_image( + #[cfg(debug_assertions)] name: String, buffer: &[u8], supported_compressed_formats: CompressedImageFormats, is_srgb: bool, @@ -45,7 +48,18 @@ pub fn dds_buffer_to_image( depth_or_array_layers, } .physical_size(texture_format); - image.texture_descriptor.mip_level_count = dds.get_num_mipmap_levels(); + let mip_map_level = match dds.get_num_mipmap_levels() { + 0 => { + #[cfg(debug_assertions)] + warn_once!( + "Mipmap levels for texture {} are 0, bumping them to 1", + name + ); + 1 + } + t => t, + }; + image.texture_descriptor.mip_level_count = mip_map_level; image.texture_descriptor.format = texture_format; image.texture_descriptor.dimension = if dds.get_depth() > 1 { TextureDimension::D3 diff --git a/crates/bevy_render/src/texture/image.rs b/crates/bevy_render/src/texture/image.rs index 9f29c72018..aef212100c 100644 --- a/crates/bevy_render/src/texture/image.rs +++ b/crates/bevy_render/src/texture/image.rs @@ -643,6 +643,7 @@ impl Image { /// Load a bytes buffer in a [`Image`], according to type `image_type`, using the `image` /// crate pub fn from_buffer( + #[cfg(all(debug_assertions, feature = "dds"))] name: String, buffer: &[u8], image_type: ImageType, #[allow(unused_variables)] supported_compressed_formats: CompressedImageFormats, @@ -664,7 +665,13 @@ impl Image { basis_buffer_to_image(buffer, supported_compressed_formats, is_srgb)? } #[cfg(feature = "dds")] - ImageFormat::Dds => dds_buffer_to_image(buffer, supported_compressed_formats, is_srgb)?, + ImageFormat::Dds => dds_buffer_to_image( + #[cfg(debug_assertions)] + name, + buffer, + supported_compressed_formats, + is_srgb, + )?, #[cfg(feature = "ktx2")] ImageFormat::Ktx2 => { ktx2_buffer_to_image(buffer, supported_compressed_formats, is_srgb)? diff --git a/crates/bevy_render/src/texture/image_loader.rs b/crates/bevy_render/src/texture/image_loader.rs index d2d5899b66..44a4fdb925 100644 --- a/crates/bevy_render/src/texture/image_loader.rs +++ b/crates/bevy_render/src/texture/image_loader.rs @@ -102,6 +102,8 @@ impl AssetLoader for ImageLoader { ImageFormatSetting::Format(format) => ImageType::Format(format), }; Ok(Image::from_buffer( + #[cfg(all(debug_assertions, feature = "dds"))] + load_context.path().display().to_string(), &bytes, image_type, self.supported_compressed_formats,