Updated to wgpu 0.16.0, wgpu-hal 0.16.0 and naga 0.12.0 (#8446)

# 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 <mockersf@gmail.com>
This commit is contained in:
Airing 2023-04-26 23:34:23 +08:00 committed by GitHub
parent 75130bd5ec
commit 4d54ce14aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 42 additions and 61 deletions

View file

@ -30,7 +30,6 @@ use downsampling_pipeline::{
prepare_downsampling_pipeline, BloomDownsamplingPipeline, BloomDownsamplingPipelineIds, prepare_downsampling_pipeline, BloomDownsamplingPipeline, BloomDownsamplingPipelineIds,
BloomUniforms, BloomUniforms,
}; };
use std::num::NonZeroU32;
use upsampling_pipeline::{ use upsampling_pipeline::{
prepare_upsampling_pipeline, BloomUpsamplingPipeline, UpsamplingPipelineIds, prepare_upsampling_pipeline, BloomUpsamplingPipeline, UpsamplingPipelineIds,
}; };
@ -310,7 +309,7 @@ impl BloomTexture {
fn view(&self, base_mip_level: u32) -> TextureView { fn view(&self, base_mip_level: u32) -> TextureView {
self.texture.texture.create_view(&TextureViewDescriptor { self.texture.texture.create_view(&TextureViewDescriptor {
base_mip_level, base_mip_level,
mip_level_count: NonZeroU32::new(1), mip_level_count: Some(1u32),
..Default::default() ..Default::default()
}) })
} }

View file

@ -561,7 +561,7 @@ pub fn get_bind_group_layout_entries(
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture { ty: BindingType::Texture {
multisampled, multisampled,
sample_type: TextureSampleType::Float { filterable: true }, sample_type: TextureSampleType::Float { filterable: false },
view_dimension: TextureViewDimension::D2, view_dimension: TextureViewDimension::D2,
}, },
count: None, count: None,
@ -572,7 +572,7 @@ pub fn get_bind_group_layout_entries(
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Texture { ty: BindingType::Texture {
multisampled, multisampled,
sample_type: TextureSampleType::Float { filterable: true }, sample_type: TextureSampleType::Float { filterable: false },
view_dimension: TextureViewDimension::D2, view_dimension: TextureViewDimension::D2,
}, },
count: None, count: None,

View file

@ -30,10 +30,7 @@ use bevy_utils::{
tracing::{error, warn}, tracing::{error, warn},
HashMap, HashMap,
}; };
use std::{ use std::{hash::Hash, num::NonZeroU64};
hash::Hash,
num::{NonZeroU32, NonZeroU64},
};
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub enum RenderLightSystems { pub enum RenderLightSystems {
@ -998,7 +995,7 @@ pub fn prepare_lights(
base_mip_level: 0, base_mip_level: 0,
mip_level_count: None, mip_level_count: None,
base_array_layer: (light_index * 6 + face_index) as u32, 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 let view_light_entity = commands
@ -1060,7 +1057,7 @@ pub fn prepare_lights(
base_mip_level: 0, base_mip_level: 0,
mip_level_count: None, mip_level_count: None,
base_array_layer: (num_directional_cascades_enabled + light_index) as u32, 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 let view_light_entity = commands
@ -1124,7 +1121,7 @@ pub fn prepare_lights(
base_mip_level: 0, base_mip_level: 0,
mip_level_count: None, mip_level_count: None,
base_array_layer: directional_depth_texture_array_index, 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; directional_depth_texture_array_index += 1;

View file

@ -514,12 +514,7 @@ impl FromWorld for MeshPipeline {
&image.data, &image.data,
ImageDataLayout { ImageDataLayout {
offset: 0, offset: 0,
bytes_per_row: Some( bytes_per_row: Some(image.texture_descriptor.size.width * format_size as u32),
std::num::NonZeroU32::new(
image.texture_descriptor.size.width * format_size as u32,
)
.unwrap(),
),
rows_per_image: None, rows_per_image: None,
}, },
image.texture_descriptor.size, image.texture_descriptor.size,

View file

@ -55,10 +55,10 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.11.0-dev" }
image = { version = "0.24", default-features = false } image = { version = "0.24", default-features = false }
# misc # misc
wgpu = { version = "0.15.0" } wgpu = { version = "0.16.0" }
wgpu-hal = "0.15.1" wgpu-hal = "0.16.0"
codespan-reporting = "0.11.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"] } serde = { version = "1", features = ["derive"] }
bitflags = "1.2.1" bitflags = "1.2.1"
smallvec = { version = "1.6", features = ["union", "const_generics"] } smallvec = { version = "1.6", features = ["union", "const_generics"] }

View file

@ -128,7 +128,7 @@ impl ProcessedShader {
ProcessedShader::Wgsl(source) => naga::front::wgsl::parse_str(source)?, ProcessedShader::Wgsl(source) => naga::front::wgsl::parse_str(source)?,
#[cfg(feature = "shader_format_glsl")] #[cfg(feature = "shader_format_glsl")]
ProcessedShader::Glsl(source, shader_stage) => { ProcessedShader::Glsl(source, shader_stage) => {
let mut parser = naga::front::glsl::Parser::default(); let mut parser = naga::front::glsl::Frontend::default();
parser parser
.parse(&naga::front::glsl::Options::from(*shader_stage), source) .parse(&naga::front::glsl::Options::from(*shader_stage), source)
.map_err(ShaderReflectError::GlslParse)? .map_err(ShaderReflectError::GlslParse)?
@ -152,7 +152,7 @@ impl ProcessedShader {
}; };
const CAPABILITIES: &[(Features, Capabilities)] = &[ const CAPABILITIES: &[(Features, Capabilities)] = &[
(Features::PUSH_CONSTANTS, Capabilities::PUSH_CONSTANT), (Features::PUSH_CONSTANTS, Capabilities::PUSH_CONSTANT),
(Features::SHADER_FLOAT64, Capabilities::FLOAT64), (Features::SHADER_F64, Capabilities::FLOAT64),
( (
Features::SHADER_PRIMITIVE_INDEX, Features::SHADER_PRIMITIVE_INDEX,
Capabilities::PRIMITIVE_INDEX, Capabilities::PRIMITIVE_INDEX,

View file

@ -215,7 +215,7 @@ pub fn dds_format_to_texture_format(
} }
DxgiFormat::BC6H_Typeless | DxgiFormat::BC6H_UF16 => TextureFormat::Bc6hRgbUfloat, 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 => { DxgiFormat::BC7_Typeless | DxgiFormat::BC7_UNorm | DxgiFormat::BC7_UNorm_sRGB => {
if is_srgb { if is_srgb {
TextureFormat::Bc7RgbaUnormSrgb TextureFormat::Bc7RgbaUnormSrgb

View file

@ -1,5 +1,3 @@
use std::num::NonZeroU32;
use crate::{render_resource::*, texture::DefaultImageSampler}; use crate::{render_resource::*, texture::DefaultImageSampler};
use bevy_derive::{Deref, DerefMut}; use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{ use bevy_ecs::{
@ -54,7 +52,7 @@ fn fallback_image_new(
image.texture_descriptor.usage |= TextureUsages::RENDER_ATTACHMENT; 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 // 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) render_device.create_texture(&image.texture_descriptor)
} else { } else {
render_device.create_texture_with_data(render_queue, &image.texture_descriptor, &image.data) 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 { let texture_view = texture.create_view(&TextureViewDescriptor {
dimension: Some(dimension), dimension: Some(dimension),
array_layer_count: NonZeroU32::new(extents.depth_or_array_layers), array_layer_count: Some(extents.depth_or_array_layers),
..TextureViewDescriptor::default() ..TextureViewDescriptor::default()
}); });
let sampler = match image.sampler_descriptor { let sampler = match image.sampler_descriptor {

View file

@ -386,15 +386,15 @@ impl Image {
/// Whether the texture format is compressed or uncompressed /// Whether the texture format is compressed or uncompressed
pub fn is_compressed(&self) -> bool { pub fn is_compressed(&self) -> bool {
let format_description = self.texture_descriptor.format.describe(); let format_description = self.texture_descriptor.format;
format_description format_description
.required_features .required_features()
.contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC_LDR) .contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC)
|| format_description || format_description
.required_features .required_features()
.contains(wgpu::Features::TEXTURE_COMPRESSION_BC) .contains(wgpu::Features::TEXTURE_COMPRESSION_BC)
|| format_description || format_description
.required_features .required_features()
.contains(wgpu::Features::TEXTURE_COMPRESSION_ETC2) .contains(wgpu::Features::TEXTURE_COMPRESSION_ETC2)
} }
} }
@ -482,9 +482,9 @@ pub trait TextureFormatPixelInfo {
impl TextureFormatPixelInfo for TextureFormat { impl TextureFormatPixelInfo for TextureFormat {
fn pixel_size(&self) -> usize { fn pixel_size(&self) -> usize {
let info = self.describe(); let info = self;
match info.block_dimensions { match info.block_dimensions() {
(1, 1) => info.block_size.into(), (1, 1) => info.block_size(None).unwrap() as usize,
_ => panic!("Using pixel_size for compressed textures is invalid"), _ => panic!("Using pixel_size for compressed textures is invalid"),
} }
} }
@ -568,7 +568,7 @@ bitflags::bitflags! {
impl CompressedImageFormats { impl CompressedImageFormats {
pub fn from_features(features: wgpu::Features) -> Self { pub fn from_features(features: wgpu::Features) -> Self {
let mut supported_compressed_formats = Self::default(); 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; supported_compressed_formats |= Self::ASTC_LDR;
} }
if features.contains(wgpu::Features::TEXTURE_COMPRESSION_BC) { if features.contains(wgpu::Features::TEXTURE_COMPRESSION_BC) {
@ -593,7 +593,7 @@ impl CompressedImageFormats {
| TextureFormat::Bc5RgUnorm | TextureFormat::Bc5RgUnorm
| TextureFormat::Bc5RgSnorm | TextureFormat::Bc5RgSnorm
| TextureFormat::Bc6hRgbUfloat | TextureFormat::Bc6hRgbUfloat
| TextureFormat::Bc6hRgbSfloat | TextureFormat::Bc6hRgbFloat
| TextureFormat::Bc7RgbaUnorm | TextureFormat::Bc7RgbaUnorm
| TextureFormat::Bc7RgbaUnormSrgb => self.contains(CompressedImageFormats::BC), | TextureFormat::Bc7RgbaUnormSrgb => self.contains(CompressedImageFormats::BC),
TextureFormat::Etc2Rgb8Unorm TextureFormat::Etc2Rgb8Unorm

View file

@ -154,12 +154,13 @@ pub fn ktx2_buffer_to_image(
TranscodeFormat::Uastc(data_format) => { TranscodeFormat::Uastc(data_format) => {
let (transcode_block_format, texture_format) = let (transcode_block_format, texture_format) =
get_transcoded_formats(supported_compressed_formats, data_format, is_srgb); 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) = ( let (block_width_pixels, block_height_pixels) = (
texture_format_info.block_dimensions.0 as u32, texture_format_info.block_dimensions().0,
texture_format_info.block_dimensions.1 as u32, 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(); let transcoder = LowLevelUastcTranscoder::new();
for (level, level_data) in levels.iter().enumerate() { 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 // 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) = ( let (block_width_pixels, block_height_pixels) = (
texture_format_info.block_dimensions.0 as usize, texture_format_info.block_dimensions().0 as usize,
texture_format_info.block_dimensions.1 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]; let mut wgpu_data = vec![Vec::default(); (layer_count * face_count) as usize];
for (level, level_data) in levels.iter().enumerate() { 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 { if sample_information[0].lower == 0 {
TextureFormat::Bc6hRgbUfloat TextureFormat::Bc6hRgbUfloat
} else { } else {
TextureFormat::Bc6hRgbSfloat TextureFormat::Bc6hRgbFloat
} }
} }
Some(ColorModel::BC7) => { Some(ColorModel::BC7) => {
@ -1311,7 +1313,7 @@ pub fn ktx2_format_to_texture_format(
ktx2::Format::BC5_UNORM_BLOCK => TextureFormat::Bc5RgUnorm, ktx2::Format::BC5_UNORM_BLOCK => TextureFormat::Bc5RgUnorm,
ktx2::Format::BC5_SNORM_BLOCK => TextureFormat::Bc5RgSnorm, ktx2::Format::BC5_SNORM_BLOCK => TextureFormat::Bc5RgSnorm,
ktx2::Format::BC6H_UFLOAT_BLOCK => TextureFormat::Bc6hRgbUfloat, 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 => { ktx2::Format::BC7_UNORM_BLOCK | ktx2::Format::BC7_SRGB_BLOCK => {
if is_srgb { if is_srgb {
TextureFormat::Bc7RgbaUnormSrgb TextureFormat::Bc7RgbaUnormSrgb

View file

@ -1,4 +1,4 @@
use std::{borrow::Cow, num::NonZeroU32, path::Path}; use std::{borrow::Cow, path::Path};
use bevy_app::Plugin; use bevy_app::Plugin;
use bevy_asset::{load_internal_asset, HandleUntyped}; use bevy_asset::{load_internal_asset, HandleUntyped};
@ -117,7 +117,7 @@ pub(crate) fn layout_data(width: u32, height: u32, format: TextureFormat) -> Ima
ImageDataLayout { ImageDataLayout {
bytes_per_row: if height > 1 { bytes_per_row: if height > 1 {
// 1 = 1 row // 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 { } else {
None None
}, },

View file

@ -232,12 +232,7 @@ impl FromWorld for Mesh2dPipeline {
&image.data, &image.data,
ImageDataLayout { ImageDataLayout {
offset: 0, offset: 0,
bytes_per_row: Some( bytes_per_row: Some(image.texture_descriptor.size.width * format_size as u32),
std::num::NonZeroU32::new(
image.texture_descriptor.size.width * format_size as u32,
)
.unwrap(),
),
rows_per_image: None, rows_per_image: None,
}, },
image.texture_descriptor.size, image.texture_descriptor.size,

View file

@ -109,12 +109,7 @@ impl FromWorld for SpritePipeline {
&image.data, &image.data,
ImageDataLayout { ImageDataLayout {
offset: 0, offset: 0,
bytes_per_row: Some( bytes_per_row: Some(image.texture_descriptor.size.width * format_size as u32),
std::num::NonZeroU32::new(
image.texture_descriptor.size.width * format_size as u32,
)
.unwrap(),
),
rows_per_image: None, rows_per_image: None,
}, },
image.texture_descriptor.size, image.texture_descriptor.size,