Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from Apr 26, 2023
3 changes: 1 addition & 2 deletions crates/bevy_core_pipeline/src/bloom/mod.rs
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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()
})
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/prepass/mod.rs
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions crates/bevy_pbr/src/render/light.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
7 changes: 1 addition & 6 deletions crates/bevy_pbr/src/render/mesh.rs
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_render/Cargo.toml
Expand Up @@ -52,10 +52,10 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.11.0-dev" }
image = { version = "0.24", default-features = false }

# misc
wgpu = { version = "0.15.0", features = ["spirv"] }
wgpu-hal = "0.15.1"
wgpu = { version = "0.16.0", features = ["spirv"] }
wgpu-hal = "0.16.0"
codespan-reporting = "0.11.0"
naga = { version = "0.11.0", features = ["glsl-in", "spv-in", "spv-out", "wgsl-in", "wgsl-out"] }
naga = { version = "0.12.0", features = ["glsl-in", "spv-in", "spv-out", "wgsl-in", "wgsl-out"] }
serde = { version = "1", features = ["derive"] }
bitflags = "1.2.1"
smallvec = { version = "1.6", features = ["union", "const_generics"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/render_resource/shader.rs
Expand Up @@ -121,7 +121,7 @@ impl ProcessedShader {
// TODO: process macros here
ProcessedShader::Wgsl(source) => naga::front::wgsl::parse_str(source)?,
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)?
Expand All @@ -136,7 +136,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,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/texture/dds.rs
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions 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::{
Expand Down Expand Up @@ -54,15 +52,15 @@ 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)
};

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 {
Expand Down
20 changes: 10 additions & 10 deletions crates/bevy_render/src/texture/image.rs
Expand Up @@ -387,15 +387,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()
superdump marked this conversation as resolved.
Show resolved Hide resolved
.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)
}
}
Expand Down Expand Up @@ -483,9 +483,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_or_default() as usize,
mockersf marked this conversation as resolved.
Show resolved Hide resolved
_ => panic!("Using pixel_size for compressed textures is invalid"),
}
}
Expand Down Expand Up @@ -569,7 +569,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) {
Expand All @@ -594,7 +594,7 @@ impl CompressedImageFormats {
| TextureFormat::Bc5RgUnorm
| TextureFormat::Bc5RgSnorm
| TextureFormat::Bc6hRgbUfloat
| TextureFormat::Bc6hRgbSfloat
| TextureFormat::Bc6hRgbFloat
| TextureFormat::Bc7RgbaUnorm
| TextureFormat::Bc7RgbaUnormSrgb => self.contains(CompressedImageFormats::BC),
TextureFormat::Etc2Rgb8Unorm
Expand Down
22 changes: 12 additions & 10 deletions crates/bevy_render/src/texture/ktx2.rs
Expand Up @@ -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,
superdump marked this conversation as resolved.
Show resolved Hide resolved
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_or_default();

let transcoder = LowLevelUastcTranscoder::new();
for (level, level_data) in levels.iter().enumerate() {
Expand Down Expand Up @@ -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_or_default() as usize;
mockersf marked this conversation as resolved.
Show resolved Hide resolved
mockersf marked this conversation as resolved.
Show resolved Hide resolved

let mut wgpu_data = vec![Vec::default(); (layer_count * face_count) as usize];
for (level, level_data) in levels.iter().enumerate() {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions 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};
Expand Down Expand Up @@ -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
},
Expand Down
7 changes: 1 addition & 6 deletions crates/bevy_sprite/src/mesh2d/mesh.rs
Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions crates/bevy_sprite/src/render/mod.rs
Expand Up @@ -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,
Expand Down