From 4d54ce14aaee8d7432380df37c41c03c28594b27 Mon Sep 17 00:00:00 2001 From: Airing Date: Wed, 26 Apr 2023 23:34:23 +0800 Subject: [PATCH] Updated to wgpu 0.16.0, wgpu-hal 0.16.0 and naga 0.12.0 (#8446) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - Updated to wgpu 0.16.0 and wgpu-hal 0.16.0 --- ## Changelog 1. Upgrade wgpu to 0.16.0 and wgpu-hal to 0.16.0 2. Fix the error in native when using a filterable `TextureSampleType::Float` on a multisample `BindingType::Texture`. ([https://github.com/gfx-rs/wgpu/pull/3686](https://github.com/gfx-rs/wgpu/pull/3686)) --------- Co-authored-by: François --- crates/bevy_core_pipeline/src/bloom/mod.rs | 3 +-- crates/bevy_pbr/src/prepass/mod.rs | 4 ++-- crates/bevy_pbr/src/render/light.rs | 11 ++++------ crates/bevy_pbr/src/render/mesh.rs | 7 +----- crates/bevy_render/Cargo.toml | 6 ++--- .../bevy_render/src/render_resource/shader.rs | 4 ++-- crates/bevy_render/src/texture/dds.rs | 2 +- .../bevy_render/src/texture/fallback_image.rs | 6 ++--- crates/bevy_render/src/texture/image.rs | 20 ++++++++--------- crates/bevy_render/src/texture/ktx2.rs | 22 ++++++++++--------- .../bevy_render/src/view/window/screenshot.rs | 4 ++-- crates/bevy_sprite/src/mesh2d/mesh.rs | 7 +----- crates/bevy_sprite/src/render/mod.rs | 7 +----- 13 files changed, 42 insertions(+), 61 deletions(-) diff --git a/crates/bevy_core_pipeline/src/bloom/mod.rs b/crates/bevy_core_pipeline/src/bloom/mod.rs index 34f615345f742..3e761fbf763e9 100644 --- a/crates/bevy_core_pipeline/src/bloom/mod.rs +++ b/crates/bevy_core_pipeline/src/bloom/mod.rs @@ -30,7 +30,6 @@ use downsampling_pipeline::{ prepare_downsampling_pipeline, BloomDownsamplingPipeline, BloomDownsamplingPipelineIds, BloomUniforms, }; -use std::num::NonZeroU32; use upsampling_pipeline::{ prepare_upsampling_pipeline, BloomUpsamplingPipeline, UpsamplingPipelineIds, }; @@ -310,7 +309,7 @@ impl BloomTexture { fn view(&self, base_mip_level: u32) -> TextureView { self.texture.texture.create_view(&TextureViewDescriptor { base_mip_level, - mip_level_count: NonZeroU32::new(1), + mip_level_count: Some(1u32), ..Default::default() }) } diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 0659f20a3290a..c24eb14335671 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -561,7 +561,7 @@ pub fn get_bind_group_layout_entries( visibility: ShaderStages::FRAGMENT, ty: BindingType::Texture { multisampled, - sample_type: TextureSampleType::Float { filterable: true }, + sample_type: TextureSampleType::Float { filterable: false }, view_dimension: TextureViewDimension::D2, }, count: None, @@ -572,7 +572,7 @@ pub fn get_bind_group_layout_entries( visibility: ShaderStages::FRAGMENT, ty: BindingType::Texture { multisampled, - sample_type: TextureSampleType::Float { filterable: true }, + sample_type: TextureSampleType::Float { filterable: false }, view_dimension: TextureViewDimension::D2, }, count: None, diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index dc28bdfc0690b..1e73198a8744d 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -30,10 +30,7 @@ use bevy_utils::{ tracing::{error, warn}, HashMap, }; -use std::{ - hash::Hash, - num::{NonZeroU32, NonZeroU64}, -}; +use std::{hash::Hash, num::NonZeroU64}; #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] pub enum RenderLightSystems { @@ -998,7 +995,7 @@ pub fn prepare_lights( base_mip_level: 0, mip_level_count: None, base_array_layer: (light_index * 6 + face_index) as u32, - array_layer_count: NonZeroU32::new(1), + array_layer_count: Some(1u32), }); let view_light_entity = commands @@ -1060,7 +1057,7 @@ pub fn prepare_lights( base_mip_level: 0, mip_level_count: None, base_array_layer: (num_directional_cascades_enabled + light_index) as u32, - array_layer_count: NonZeroU32::new(1), + array_layer_count: Some(1u32), }); let view_light_entity = commands @@ -1124,7 +1121,7 @@ pub fn prepare_lights( base_mip_level: 0, mip_level_count: None, base_array_layer: directional_depth_texture_array_index, - array_layer_count: NonZeroU32::new(1), + array_layer_count: Some(1u32), }); directional_depth_texture_array_index += 1; diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index 61f0eadba96b2..fb5fed27bb342 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -514,12 +514,7 @@ impl FromWorld for MeshPipeline { &image.data, ImageDataLayout { offset: 0, - bytes_per_row: Some( - std::num::NonZeroU32::new( - image.texture_descriptor.size.width * format_size as u32, - ) - .unwrap(), - ), + bytes_per_row: Some(image.texture_descriptor.size.width * format_size as u32), rows_per_image: None, }, image.texture_descriptor.size, diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index a75130c133227..e0f307650f5fe 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -55,10 +55,10 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.11.0-dev" } image = { version = "0.24", default-features = false } # misc -wgpu = { version = "0.15.0" } -wgpu-hal = "0.15.1" +wgpu = { version = "0.16.0" } +wgpu-hal = "0.16.0" codespan-reporting = "0.11.0" -naga = { version = "0.11.0", features = ["wgsl-in"] } +naga = { version = "0.12.0", features = ["wgsl-in"] } serde = { version = "1", features = ["derive"] } bitflags = "1.2.1" smallvec = { version = "1.6", features = ["union", "const_generics"] } diff --git a/crates/bevy_render/src/render_resource/shader.rs b/crates/bevy_render/src/render_resource/shader.rs index 95116432b23f2..572e5fea4abf4 100644 --- a/crates/bevy_render/src/render_resource/shader.rs +++ b/crates/bevy_render/src/render_resource/shader.rs @@ -128,7 +128,7 @@ impl ProcessedShader { ProcessedShader::Wgsl(source) => naga::front::wgsl::parse_str(source)?, #[cfg(feature = "shader_format_glsl")] ProcessedShader::Glsl(source, shader_stage) => { - let mut parser = naga::front::glsl::Parser::default(); + let mut parser = naga::front::glsl::Frontend::default(); parser .parse(&naga::front::glsl::Options::from(*shader_stage), source) .map_err(ShaderReflectError::GlslParse)? @@ -152,7 +152,7 @@ impl ProcessedShader { }; const CAPABILITIES: &[(Features, Capabilities)] = &[ (Features::PUSH_CONSTANTS, Capabilities::PUSH_CONSTANT), - (Features::SHADER_FLOAT64, Capabilities::FLOAT64), + (Features::SHADER_F64, Capabilities::FLOAT64), ( Features::SHADER_PRIMITIVE_INDEX, Capabilities::PRIMITIVE_INDEX, diff --git a/crates/bevy_render/src/texture/dds.rs b/crates/bevy_render/src/texture/dds.rs index bd008a3600fdf..bfedd4b102745 100644 --- a/crates/bevy_render/src/texture/dds.rs +++ b/crates/bevy_render/src/texture/dds.rs @@ -215,7 +215,7 @@ pub fn dds_format_to_texture_format( } DxgiFormat::BC6H_Typeless | DxgiFormat::BC6H_UF16 => TextureFormat::Bc6hRgbUfloat, - DxgiFormat::BC6H_SF16 => TextureFormat::Bc6hRgbSfloat, + DxgiFormat::BC6H_SF16 => TextureFormat::Bc6hRgbFloat, DxgiFormat::BC7_Typeless | DxgiFormat::BC7_UNorm | DxgiFormat::BC7_UNorm_sRGB => { if is_srgb { TextureFormat::Bc7RgbaUnormSrgb diff --git a/crates/bevy_render/src/texture/fallback_image.rs b/crates/bevy_render/src/texture/fallback_image.rs index 2ffe5204acb69..cb3bec1420f8d 100644 --- a/crates/bevy_render/src/texture/fallback_image.rs +++ b/crates/bevy_render/src/texture/fallback_image.rs @@ -1,5 +1,3 @@ -use std::num::NonZeroU32; - use crate::{render_resource::*, texture::DefaultImageSampler}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ @@ -54,7 +52,7 @@ fn fallback_image_new( image.texture_descriptor.usage |= TextureUsages::RENDER_ATTACHMENT; // We can't create textures with data when it's a depth texture or when using multiple samples - let texture = if format.describe().sample_type == TextureSampleType::Depth || samples > 1 { + let texture = if format.is_depth_stencil_format() || samples > 1 { render_device.create_texture(&image.texture_descriptor) } else { render_device.create_texture_with_data(render_queue, &image.texture_descriptor, &image.data) @@ -62,7 +60,7 @@ fn fallback_image_new( let texture_view = texture.create_view(&TextureViewDescriptor { dimension: Some(dimension), - array_layer_count: NonZeroU32::new(extents.depth_or_array_layers), + array_layer_count: Some(extents.depth_or_array_layers), ..TextureViewDescriptor::default() }); let sampler = match image.sampler_descriptor { diff --git a/crates/bevy_render/src/texture/image.rs b/crates/bevy_render/src/texture/image.rs index a2424365fe344..bf3396e327270 100644 --- a/crates/bevy_render/src/texture/image.rs +++ b/crates/bevy_render/src/texture/image.rs @@ -386,15 +386,15 @@ impl Image { /// Whether the texture format is compressed or uncompressed pub fn is_compressed(&self) -> bool { - let format_description = self.texture_descriptor.format.describe(); + let format_description = self.texture_descriptor.format; format_description - .required_features - .contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC_LDR) + .required_features() + .contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC) || format_description - .required_features + .required_features() .contains(wgpu::Features::TEXTURE_COMPRESSION_BC) || format_description - .required_features + .required_features() .contains(wgpu::Features::TEXTURE_COMPRESSION_ETC2) } } @@ -482,9 +482,9 @@ pub trait TextureFormatPixelInfo { impl TextureFormatPixelInfo for TextureFormat { fn pixel_size(&self) -> usize { - let info = self.describe(); - match info.block_dimensions { - (1, 1) => info.block_size.into(), + let info = self; + match info.block_dimensions() { + (1, 1) => info.block_size(None).unwrap() as usize, _ => panic!("Using pixel_size for compressed textures is invalid"), } } @@ -568,7 +568,7 @@ bitflags::bitflags! { impl CompressedImageFormats { pub fn from_features(features: wgpu::Features) -> Self { let mut supported_compressed_formats = Self::default(); - if features.contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC_LDR) { + if features.contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC) { supported_compressed_formats |= Self::ASTC_LDR; } if features.contains(wgpu::Features::TEXTURE_COMPRESSION_BC) { @@ -593,7 +593,7 @@ impl CompressedImageFormats { | TextureFormat::Bc5RgUnorm | TextureFormat::Bc5RgSnorm | TextureFormat::Bc6hRgbUfloat - | TextureFormat::Bc6hRgbSfloat + | TextureFormat::Bc6hRgbFloat | TextureFormat::Bc7RgbaUnorm | TextureFormat::Bc7RgbaUnormSrgb => self.contains(CompressedImageFormats::BC), TextureFormat::Etc2Rgb8Unorm diff --git a/crates/bevy_render/src/texture/ktx2.rs b/crates/bevy_render/src/texture/ktx2.rs index 6202df95d5502..41801178de409 100644 --- a/crates/bevy_render/src/texture/ktx2.rs +++ b/crates/bevy_render/src/texture/ktx2.rs @@ -154,12 +154,13 @@ pub fn ktx2_buffer_to_image( TranscodeFormat::Uastc(data_format) => { let (transcode_block_format, texture_format) = get_transcoded_formats(supported_compressed_formats, data_format, is_srgb); - let texture_format_info = texture_format.describe(); + let texture_format_info = texture_format; let (block_width_pixels, block_height_pixels) = ( - texture_format_info.block_dimensions.0 as u32, - texture_format_info.block_dimensions.1 as u32, + texture_format_info.block_dimensions().0, + texture_format_info.block_dimensions().1, ); - let block_bytes = texture_format_info.block_size as u32; + // Texture is not a depth or stencil format, it is possible to pass `None` and unwrap + let block_bytes = texture_format_info.block_size(None).unwrap(); let transcoder = LowLevelUastcTranscoder::new(); for (level, level_data) in levels.iter().enumerate() { @@ -233,12 +234,13 @@ pub fn ktx2_buffer_to_image( } // Reorder data from KTX2 MipXLayerYFaceZ to wgpu LayerYFaceZMipX - let texture_format_info = texture_format.describe(); + let texture_format_info = texture_format; let (block_width_pixels, block_height_pixels) = ( - texture_format_info.block_dimensions.0 as usize, - texture_format_info.block_dimensions.1 as usize, + texture_format_info.block_dimensions().0 as usize, + texture_format_info.block_dimensions().1 as usize, ); - let block_bytes = texture_format_info.block_size as usize; + // Texture is not a depth or stencil format, it is possible to pass `None` and unwrap + let block_bytes = texture_format_info.block_size(None).unwrap() as usize; let mut wgpu_data = vec![Vec::default(); (layer_count * face_count) as usize]; for (level, level_data) in levels.iter().enumerate() { @@ -1037,7 +1039,7 @@ pub fn ktx2_dfd_to_texture_format( if sample_information[0].lower == 0 { TextureFormat::Bc6hRgbUfloat } else { - TextureFormat::Bc6hRgbSfloat + TextureFormat::Bc6hRgbFloat } } Some(ColorModel::BC7) => { @@ -1311,7 +1313,7 @@ pub fn ktx2_format_to_texture_format( ktx2::Format::BC5_UNORM_BLOCK => TextureFormat::Bc5RgUnorm, ktx2::Format::BC5_SNORM_BLOCK => TextureFormat::Bc5RgSnorm, ktx2::Format::BC6H_UFLOAT_BLOCK => TextureFormat::Bc6hRgbUfloat, - ktx2::Format::BC6H_SFLOAT_BLOCK => TextureFormat::Bc6hRgbSfloat, + ktx2::Format::BC6H_SFLOAT_BLOCK => TextureFormat::Bc6hRgbFloat, ktx2::Format::BC7_UNORM_BLOCK | ktx2::Format::BC7_SRGB_BLOCK => { if is_srgb { TextureFormat::Bc7RgbaUnormSrgb diff --git a/crates/bevy_render/src/view/window/screenshot.rs b/crates/bevy_render/src/view/window/screenshot.rs index 2a67f43005a7a..3ddca122568ae 100644 --- a/crates/bevy_render/src/view/window/screenshot.rs +++ b/crates/bevy_render/src/view/window/screenshot.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, num::NonZeroU32, path::Path}; +use std::{borrow::Cow, path::Path}; use bevy_app::Plugin; use bevy_asset::{load_internal_asset, HandleUntyped}; @@ -117,7 +117,7 @@ pub(crate) fn layout_data(width: u32, height: u32, format: TextureFormat) -> Ima ImageDataLayout { bytes_per_row: if height > 1 { // 1 = 1 row - NonZeroU32::new(get_aligned_size(width, 1, format.pixel_size() as u32)) + Some(get_aligned_size(width, 1, format.pixel_size() as u32)) } else { None }, diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index d7b63d7d4c509..11d4552af50dd 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -232,12 +232,7 @@ impl FromWorld for Mesh2dPipeline { &image.data, ImageDataLayout { offset: 0, - bytes_per_row: Some( - std::num::NonZeroU32::new( - image.texture_descriptor.size.width * format_size as u32, - ) - .unwrap(), - ), + bytes_per_row: Some(image.texture_descriptor.size.width * format_size as u32), rows_per_image: None, }, image.texture_descriptor.size, diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 1279de05f0686..725aab3234df0 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -109,12 +109,7 @@ impl FromWorld for SpritePipeline { &image.data, ImageDataLayout { offset: 0, - bytes_per_row: Some( - std::num::NonZeroU32::new( - image.texture_descriptor.size.width * format_size as u32, - ) - .unwrap(), - ), + bytes_per_row: Some(image.texture_descriptor.size.width * format_size as u32), rows_per_image: None, }, image.texture_descriptor.size,