From 9a89295a1741da0258c56c326aecfcad37ae6b41 Mon Sep 17 00:00:00 2001 From: Vabka Date: Sun, 19 Dec 2021 03:03:06 +0000 Subject: [PATCH] Update wgpu to 0.12 and naga to 0.8 (#3375) # Objective Fixes #3352 Fixes #3208 ## Solution - Update wgpu to 0.12 - Update naga to 0.8 - Resolve compilation errors - Remove [[block]] from WGSL shaders (because it is depracated and now wgpu cant parse it) - Replace `elseif` with `else if` in pbr.wgsl --- assets/shaders/custom_material.wgsl | 1 - crates/bevy_gltf/Cargo.toml | 2 +- crates/bevy_pbr/Cargo.toml | 2 +- crates/bevy_pbr/src/render/depth.wgsl | 1 - crates/bevy_pbr/src/render/light.rs | 2 +- crates/bevy_pbr/src/render/mesh.rs | 16 ++++-------- crates/bevy_pbr/src/render/mesh_struct.wgsl | 1 - .../src/render/mesh_view_bind_group.wgsl | 5 ---- crates/bevy_pbr/src/render/mod.rs | 26 +++++-------------- crates/bevy_pbr/src/render/pbr.wgsl | 3 +-- crates/bevy_render/Cargo.toml | 6 ++--- .../src/render_resource/pipeline_cache.rs | 1 + .../bevy_render/src/render_resource/shader.rs | 19 +++----------- crates/bevy_sprite/Cargo.toml | 1 + crates/bevy_sprite/src/render/mod.rs | 8 +++--- crates/bevy_sprite/src/render/sprite.wgsl | 1 - crates/bevy_ui/Cargo.toml | 5 ++-- crates/bevy_ui/src/render/pipeline.rs | 8 +++--- crates/bevy_ui/src/render/ui.wgsl | 1 - crates/crevice/crevice-tests/Cargo.toml | 4 +-- deny.toml | 1 - 21 files changed, 34 insertions(+), 80 deletions(-) diff --git a/assets/shaders/custom_material.wgsl b/assets/shaders/custom_material.wgsl index 9dfaa6f568..4f40d3cff6 100644 --- a/assets/shaders/custom_material.wgsl +++ b/assets/shaders/custom_material.wgsl @@ -1,4 +1,3 @@ -[[block]] struct CustomMaterial { color: vec4; }; diff --git a/crates/bevy_gltf/Cargo.toml b/crates/bevy_gltf/Cargo.toml index a314412102..977f9e2757 100644 --- a/crates/bevy_gltf/Cargo.toml +++ b/crates/bevy_gltf/Cargo.toml @@ -29,4 +29,4 @@ thiserror = "1.0" anyhow = "1.0.4" base64 = "0.13.0" percent-encoding = "2.1" -wgpu = "0.11.0" +wgpu = "0.12.0" diff --git a/crates/bevy_pbr/Cargo.toml b/crates/bevy_pbr/Cargo.toml index e943223f99..6d8c854ed3 100644 --- a/crates/bevy_pbr/Cargo.toml +++ b/crates/bevy_pbr/Cargo.toml @@ -27,4 +27,4 @@ bitflags = "1.2" # direct dependency required for derive macro bytemuck = { version = "1", features = ["derive"] } crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } -wgpu = { version = "0.11.0", features = ["spirv"] } +wgpu = { version = "0.12.0", features = ["spirv"] } diff --git a/crates/bevy_pbr/src/render/depth.wgsl b/crates/bevy_pbr/src/render/depth.wgsl index 7b983b31cc..857ece2472 100644 --- a/crates/bevy_pbr/src/render/depth.wgsl +++ b/crates/bevy_pbr/src/render/depth.wgsl @@ -1,7 +1,6 @@ #import bevy_pbr::mesh_struct // NOTE: Keep in sync with pbr.wgsl -[[block]] struct View { view_proj: mat4x4; projection: mat4x4; diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 213254ee01..8442ed16a9 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -293,8 +293,8 @@ impl SpecializedPipeline for ShadowPipeline { strip_index_format: None, front_face: FrontFace::Ccw, cull_mode: None, + unclipped_depth: false, polygon_mode: PolygonMode::Fill, - clamp_depth: false, conservative: false, }, depth_stencil: Some(DepthStencilState { diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index f3116f797d..42e4bb344d 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -24,8 +24,8 @@ use bevy_render::{ use bevy_transform::components::GlobalTransform; use crevice::std140::AsStd140; use wgpu::{ - Extent3d, ImageCopyTexture, ImageDataLayout, Origin3d, TextureDimension, TextureFormat, - TextureViewDescriptor, + Extent3d, ImageCopyTexture, ImageDataLayout, Origin3d, SamplerBindingType, TextureDimension, + TextureFormat, TextureViewDescriptor, }; #[derive(Default)] @@ -210,10 +210,7 @@ impl FromWorld for MeshPipeline { BindGroupLayoutEntry { binding: 3, visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler { - comparison: true, - filtering: true, - }, + ty: BindingType::Sampler(SamplerBindingType::Comparison), count: None, }, // Directional Shadow Texture Array @@ -231,10 +228,7 @@ impl FromWorld for MeshPipeline { BindGroupLayoutEntry { binding: 5, visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler { - comparison: true, - filtering: true, - }, + ty: BindingType::Sampler(SamplerBindingType::Comparison), count: None, }, // PointLights @@ -516,8 +510,8 @@ impl SpecializedPipeline for MeshPipeline { primitive: PrimitiveState { front_face: FrontFace::Ccw, cull_mode: Some(Face::Back), + unclipped_depth: false, polygon_mode: PolygonMode::Fill, - clamp_depth: false, conservative: false, topology: key.primitive_topology(), strip_index_format: None, diff --git a/crates/bevy_pbr/src/render/mesh_struct.wgsl b/crates/bevy_pbr/src/render/mesh_struct.wgsl index 672f6a021a..93987cd70a 100644 --- a/crates/bevy_pbr/src/render/mesh_struct.wgsl +++ b/crates/bevy_pbr/src/render/mesh_struct.wgsl @@ -1,4 +1,3 @@ -[[block]] struct Mesh { model: mat4x4; inverse_transpose_model: mat4x4; diff --git a/crates/bevy_pbr/src/render/mesh_view_bind_group.wgsl b/crates/bevy_pbr/src/render/mesh_view_bind_group.wgsl index a6d4b0d238..e1e1b87dd8 100644 --- a/crates/bevy_pbr/src/render/mesh_view_bind_group.wgsl +++ b/crates/bevy_pbr/src/render/mesh_view_bind_group.wgsl @@ -1,4 +1,3 @@ -[[block]] struct View { view_proj: mat4x4; inverse_view: mat4x4; @@ -35,7 +34,6 @@ struct DirectionalLight { let DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT: u32 = 1u; -[[block]] struct Lights { // NOTE: this array size must be kept in sync with the constants defined bevy_pbr2/src/render/light.rs directional_lights: array; @@ -56,18 +54,15 @@ struct Lights { n_directional_lights: u32; }; -[[block]] struct PointLights { data: array; }; -[[block]] struct ClusterLightIndexLists { // each u32 contains 4 u8 indices into the PointLights array data: array, 1024u>; }; -[[block]] struct ClusterOffsetsAndCounts { // each u32 contains a 24-bit index into ClusterLightIndexLists in the high 24 bits // and an 8-bit count of the number of lights in the low 8 bits diff --git a/crates/bevy_pbr/src/render/mod.rs b/crates/bevy_pbr/src/render/mod.rs index 2bad31a8e9..88a8476c17 100644 --- a/crates/bevy_pbr/src/render/mod.rs +++ b/crates/bevy_pbr/src/render/mod.rs @@ -3,6 +3,7 @@ mod mesh; pub use light::*; pub use mesh::*; +use wgpu::SamplerBindingType; use crate::{AlphaMode, StandardMaterial, StandardMaterialUniformData, PBR_SHADER_HANDLE}; use bevy_asset::Handle; @@ -81,10 +82,7 @@ impl FromWorld for PbrPipeline { BindGroupLayoutEntry { binding: 2, visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler { - comparison: false, - filtering: true, - }, + ty: BindingType::Sampler(SamplerBindingType::Filtering), count: None, }, // Emissive Texture @@ -102,10 +100,7 @@ impl FromWorld for PbrPipeline { BindGroupLayoutEntry { binding: 4, visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler { - comparison: false, - filtering: true, - }, + ty: BindingType::Sampler(SamplerBindingType::Filtering), count: None, }, // Metallic Roughness Texture @@ -123,10 +118,7 @@ impl FromWorld for PbrPipeline { BindGroupLayoutEntry { binding: 6, visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler { - comparison: false, - filtering: true, - }, + ty: BindingType::Sampler(SamplerBindingType::Filtering), count: None, }, // Occlusion Texture @@ -144,10 +136,7 @@ impl FromWorld for PbrPipeline { BindGroupLayoutEntry { binding: 8, visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler { - comparison: false, - filtering: true, - }, + ty: BindingType::Sampler(SamplerBindingType::Filtering), count: None, }, // Normal Map Texture @@ -165,10 +154,7 @@ impl FromWorld for PbrPipeline { BindGroupLayoutEntry { binding: 10, visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler { - comparison: false, - filtering: true, - }, + ty: BindingType::Sampler(SamplerBindingType::Filtering), count: None, }, ], diff --git a/crates/bevy_pbr/src/render/pbr.wgsl b/crates/bevy_pbr/src/render/pbr.wgsl index 0d25eedd1a..da7d135adf 100644 --- a/crates/bevy_pbr/src/render/pbr.wgsl +++ b/crates/bevy_pbr/src/render/pbr.wgsl @@ -38,7 +38,6 @@ [[group(2), binding(0)]] var mesh: Mesh; -[[block]] struct StandardMaterial { base_color: vec4; emissive: vec4; @@ -505,7 +504,7 @@ fn fragment(in: FragmentInput) -> [[location(0)]] vec4 { if ((material.flags & STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE) != 0u) { // NOTE: If rendering as opaque, alpha should be ignored so set to 1.0 output_color.a = 1.0; - } elseif ((material.flags & STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MASK) != 0u) { + } else if ((material.flags & STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MASK) != 0u) { if (output_color.a >= material.alpha_cutoff) { // NOTE: If rendering as masked alpha and >= the cutoff, render as fully opaque output_color.a = 1.0; diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index ebcd6fd708..9b30e7c1ab 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -36,8 +36,8 @@ bevy_utils = { path = "../bevy_utils", version = "0.5.0" } image = { version = "0.23.12", default-features = false } # misc -wgpu = { version = "0.11.0", features = ["spirv"] } -naga = { version = "0.7.0", features = ["glsl-in", "spv-in", "spv-out", "wgsl-in", "wgsl-out"] } +wgpu = { version = "0.12.0", features = ["spirv"] } +naga = { version = "0.8.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"] } @@ -53,4 +53,4 @@ regex = "1.5" crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } [target.'cfg(target_arch = "wasm32")'.dependencies] -wgpu = { version = "0.11.0", features = ["spirv", "webgl"] } +wgpu = { version = "0.12.0", features = ["spirv", "webgl"] } diff --git a/crates/bevy_render/src/render_resource/pipeline_cache.rs b/crates/bevy_render/src/render_resource/pipeline_cache.rs index 1dff4fe617..c904ff7471 100644 --- a/crates/bevy_render/src/render_resource/pipeline_cache.rs +++ b/crates/bevy_render/src/render_resource/pipeline_cache.rs @@ -339,6 +339,7 @@ impl RenderPipelineCache { }; let descriptor = RawRenderPipelineDescriptor { + multiview: None, depth_stencil: descriptor.depth_stencil.clone(), label: descriptor.label.as_deref(), layout, diff --git a/crates/bevy_render/src/render_resource/shader.rs b/crates/bevy_render/src/render_resource/shader.rs index 95dc413bee..5e7ed5a29d 100644 --- a/crates/bevy_render/src/render_resource/shader.rs +++ b/crates/bevy_render/src/render_resource/shader.rs @@ -1,6 +1,7 @@ use bevy_asset::{AssetLoader, Handle, LoadContext, LoadedAsset}; use bevy_reflect::{TypeUuid, Uuid}; use bevy_utils::{tracing::error, BoxedFuture, HashMap}; +use naga::back::wgsl::WriterFlags; use naga::{valid::ModuleInfo, Module}; use once_cell::sync::Lazy; use regex::Regex; @@ -29,9 +30,8 @@ pub enum ShaderReflectError { #[error(transparent)] SpirVParse(#[from] naga::front::spv::Error), #[error(transparent)] - Validation(#[from] naga::valid::ValidationError), + Validation(#[from] naga::WithSpan), } - /// A shader, as defined by its [`ShaderSource`] and [`ShaderStage`](naga::ShaderStage) /// This is an "unprocessed" shader. It can contain preprocessor directives. #[derive(Debug, Clone, TypeUuid)] @@ -204,7 +204,7 @@ impl ShaderReflection { } pub fn get_wgsl(&self) -> Result { - naga::back::wgsl::write_string(&self.module, &self.module_info) + naga::back::wgsl::write_string(&self.module, &self.module_info, WriterFlags::EXPLICIT_TYPES) } } @@ -462,7 +462,6 @@ mod tests { use crate::render_resource::{ProcessShaderError, Shader, ShaderImport, ShaderProcessor}; #[rustfmt::skip] const WGSL: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -493,7 +492,6 @@ fn vertex( "; const WGSL_ELSE: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -527,7 +525,6 @@ fn vertex( "; const WGSL_NESTED_IFDEF: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -560,7 +557,6 @@ fn vertex( "; const WGSL_NESTED_IFDEF_ELSE: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -599,7 +595,6 @@ fn vertex( fn process_shader_def_defined() { #[rustfmt::skip] const EXPECTED: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -642,7 +637,6 @@ fn vertex( fn process_shader_def_not_defined() { #[rustfmt::skip] const EXPECTED: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -683,7 +677,6 @@ fn vertex( fn process_shader_def_else() { #[rustfmt::skip] const EXPECTED: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -849,7 +842,6 @@ void bar() { } fn process_nested_shader_def_outer_defined_inner_not() { #[rustfmt::skip] const EXPECTED: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -890,7 +882,6 @@ fn vertex( fn process_nested_shader_def_outer_defined_inner_else() { #[rustfmt::skip] const EXPECTED: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -933,7 +924,6 @@ fn vertex( fn process_nested_shader_def_neither_defined() { #[rustfmt::skip] const EXPECTED: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -974,7 +964,6 @@ fn vertex( fn process_nested_shader_def_neither_defined_else() { #[rustfmt::skip] const EXPECTED: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -1015,7 +1004,6 @@ fn vertex( fn process_nested_shader_def_inner_defined_outer_not() { #[rustfmt::skip] const EXPECTED: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; @@ -1056,7 +1044,6 @@ fn vertex( fn process_nested_shader_def_both_defined() { #[rustfmt::skip] const EXPECTED: &str = r" -[[block]] struct View { view_proj: mat4x4; world_position: vec3; diff --git a/crates/bevy_sprite/Cargo.toml b/crates/bevy_sprite/Cargo.toml index 6416300628..8e01359985 100644 --- a/crates/bevy_sprite/Cargo.toml +++ b/crates/bevy_sprite/Cargo.toml @@ -31,3 +31,4 @@ guillotiere = "0.6.0" thiserror = "1.0" rectangle-pack = "0.4" serde = { version = "1", features = ["derive"] } +wgpu = "0.12.0" diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index f50bfa4846..a58b53d5d7 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -26,6 +26,7 @@ use bevy_transform::components::GlobalTransform; use bevy_utils::HashMap; use bytemuck::{Pod, Zeroable}; use crevice::std140::AsStd140; +use wgpu::SamplerBindingType; pub struct SpritePipeline { view_layout: BindGroupLayout, @@ -66,10 +67,7 @@ impl FromWorld for SpritePipeline { BindGroupLayoutEntry { binding: 1, visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler { - comparison: false, - filtering: true, - }, + ty: BindingType::Sampler(SamplerBindingType::Filtering), count: None, }, ], @@ -140,8 +138,8 @@ impl SpecializedPipeline for SpritePipeline { primitive: PrimitiveState { front_face: FrontFace::Ccw, cull_mode: None, + unclipped_depth: false, polygon_mode: PolygonMode::Fill, - clamp_depth: false, conservative: false, topology: PrimitiveTopology::TriangleList, strip_index_format: None, diff --git a/crates/bevy_sprite/src/render/sprite.wgsl b/crates/bevy_sprite/src/render/sprite.wgsl index e331817950..128536c691 100644 --- a/crates/bevy_sprite/src/render/sprite.wgsl +++ b/crates/bevy_sprite/src/render/sprite.wgsl @@ -1,4 +1,3 @@ -[[block]] struct View { view_proj: mat4x4; world_position: vec3; diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 1858f8d447..f6227010a8 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -29,7 +29,8 @@ bevy_utils = { path = "../bevy_utils", version = "0.5.0" } # other stretch = "0.3.2" -serde = {version = "1", features = ["derive"]} +serde = { version = "1", features = ["derive"] } smallvec = { version = "1.6", features = ["union", "const_generics"] } bytemuck = { version = "1.5", features = ["derive"] } -crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } \ No newline at end of file +crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } +wgpu = "0.12.0" diff --git a/crates/bevy_ui/src/render/pipeline.rs b/crates/bevy_ui/src/render/pipeline.rs index 720300e12d..5acb69f6a4 100644 --- a/crates/bevy_ui/src/render/pipeline.rs +++ b/crates/bevy_ui/src/render/pipeline.rs @@ -4,6 +4,7 @@ use bevy_render::{ }; use crevice::std140::AsStd140; +use wgpu::SamplerBindingType; pub struct UiPipeline { pub view_layout: BindGroupLayout, @@ -44,10 +45,7 @@ impl FromWorld for UiPipeline { BindGroupLayoutEntry { binding: 1, visibility: ShaderStages::FRAGMENT, - ty: BindingType::Sampler { - comparison: false, - filtering: true, - }, + ty: BindingType::Sampler(SamplerBindingType::Filtering), count: None, }, ], @@ -114,8 +112,8 @@ impl SpecializedPipeline for UiPipeline { primitive: PrimitiveState { front_face: FrontFace::Ccw, cull_mode: None, + unclipped_depth: false, polygon_mode: PolygonMode::Fill, - clamp_depth: false, conservative: false, topology: PrimitiveTopology::TriangleList, strip_index_format: None, diff --git a/crates/bevy_ui/src/render/ui.wgsl b/crates/bevy_ui/src/render/ui.wgsl index 786f46b1f9..5c6c02664c 100644 --- a/crates/bevy_ui/src/render/ui.wgsl +++ b/crates/bevy_ui/src/render/ui.wgsl @@ -1,4 +1,3 @@ -[[block]] struct View { view_proj: mat4x4; world_position: vec3; diff --git a/crates/crevice/crevice-tests/Cargo.toml b/crates/crevice/crevice-tests/Cargo.toml index a6f8605c5a..103614eb39 100644 --- a/crates/crevice/crevice-tests/Cargo.toml +++ b/crates/crevice/crevice-tests/Cargo.toml @@ -16,5 +16,5 @@ memoffset = "0.6.4" mint = "0.5.5" futures = { version = "0.3.17", features = ["executor"], optional = true } -naga = { version = "0.7.0", features = ["glsl-in", "wgsl-out"], optional = true } -wgpu = { version = "0.11.0", optional = true } +naga = { version = "0.8.0", features = ["glsl-in", "wgsl-out"], optional = true } +wgpu = { version = "0.12.0", optional = true } diff --git a/deny.toml b/deny.toml index 72129c3955..ad00ea3a9d 100644 --- a/deny.toml +++ b/deny.toml @@ -58,7 +58,6 @@ skip = [ { name = "proc-macro-crate", version = "0.1" }, # from rodio v0.14.0 { name = "stdweb", version = "0.1" }, # from rodio v0.14.0 { name = "strsim", version = "0.9" }, # from rodio v0.14.0 - { name = "raw-window-handle", version = "0.3" }, # from wgpu v0.11.1 ] [sources]