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
This commit is contained in:
Vabka 2021-12-19 03:03:06 +00:00
parent e018ac838d
commit 9a89295a17
21 changed files with 34 additions and 80 deletions

View File

@ -1,4 +1,3 @@
[[block]]
struct CustomMaterial { struct CustomMaterial {
color: vec4<f32>; color: vec4<f32>;
}; };

View File

@ -29,4 +29,4 @@ thiserror = "1.0"
anyhow = "1.0.4" anyhow = "1.0.4"
base64 = "0.13.0" base64 = "0.13.0"
percent-encoding = "2.1" percent-encoding = "2.1"
wgpu = "0.11.0" wgpu = "0.12.0"

View File

@ -27,4 +27,4 @@ bitflags = "1.2"
# direct dependency required for derive macro # direct dependency required for derive macro
bytemuck = { version = "1", features = ["derive"] } bytemuck = { version = "1", features = ["derive"] }
crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] }
wgpu = { version = "0.11.0", features = ["spirv"] } wgpu = { version = "0.12.0", features = ["spirv"] }

View File

@ -1,7 +1,6 @@
#import bevy_pbr::mesh_struct #import bevy_pbr::mesh_struct
// NOTE: Keep in sync with pbr.wgsl // NOTE: Keep in sync with pbr.wgsl
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
projection: mat4x4<f32>; projection: mat4x4<f32>;

View File

@ -293,8 +293,8 @@ impl SpecializedPipeline for ShadowPipeline {
strip_index_format: None, strip_index_format: None,
front_face: FrontFace::Ccw, front_face: FrontFace::Ccw,
cull_mode: None, cull_mode: None,
unclipped_depth: false,
polygon_mode: PolygonMode::Fill, polygon_mode: PolygonMode::Fill,
clamp_depth: false,
conservative: false, conservative: false,
}, },
depth_stencil: Some(DepthStencilState { depth_stencil: Some(DepthStencilState {

View File

@ -24,8 +24,8 @@ use bevy_render::{
use bevy_transform::components::GlobalTransform; use bevy_transform::components::GlobalTransform;
use crevice::std140::AsStd140; use crevice::std140::AsStd140;
use wgpu::{ use wgpu::{
Extent3d, ImageCopyTexture, ImageDataLayout, Origin3d, TextureDimension, TextureFormat, Extent3d, ImageCopyTexture, ImageDataLayout, Origin3d, SamplerBindingType, TextureDimension,
TextureViewDescriptor, TextureFormat, TextureViewDescriptor,
}; };
#[derive(Default)] #[derive(Default)]
@ -210,10 +210,7 @@ impl FromWorld for MeshPipeline {
BindGroupLayoutEntry { BindGroupLayoutEntry {
binding: 3, binding: 3,
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler { ty: BindingType::Sampler(SamplerBindingType::Comparison),
comparison: true,
filtering: true,
},
count: None, count: None,
}, },
// Directional Shadow Texture Array // Directional Shadow Texture Array
@ -231,10 +228,7 @@ impl FromWorld for MeshPipeline {
BindGroupLayoutEntry { BindGroupLayoutEntry {
binding: 5, binding: 5,
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler { ty: BindingType::Sampler(SamplerBindingType::Comparison),
comparison: true,
filtering: true,
},
count: None, count: None,
}, },
// PointLights // PointLights
@ -516,8 +510,8 @@ impl SpecializedPipeline for MeshPipeline {
primitive: PrimitiveState { primitive: PrimitiveState {
front_face: FrontFace::Ccw, front_face: FrontFace::Ccw,
cull_mode: Some(Face::Back), cull_mode: Some(Face::Back),
unclipped_depth: false,
polygon_mode: PolygonMode::Fill, polygon_mode: PolygonMode::Fill,
clamp_depth: false,
conservative: false, conservative: false,
topology: key.primitive_topology(), topology: key.primitive_topology(),
strip_index_format: None, strip_index_format: None,

View File

@ -1,4 +1,3 @@
[[block]]
struct Mesh { struct Mesh {
model: mat4x4<f32>; model: mat4x4<f32>;
inverse_transpose_model: mat4x4<f32>; inverse_transpose_model: mat4x4<f32>;

View File

@ -1,4 +1,3 @@
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
inverse_view: mat4x4<f32>; inverse_view: mat4x4<f32>;
@ -35,7 +34,6 @@ struct DirectionalLight {
let DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT: u32 = 1u; let DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT: u32 = 1u;
[[block]]
struct Lights { struct Lights {
// NOTE: this array size must be kept in sync with the constants defined bevy_pbr2/src/render/light.rs // NOTE: this array size must be kept in sync with the constants defined bevy_pbr2/src/render/light.rs
directional_lights: array<DirectionalLight, 1u>; directional_lights: array<DirectionalLight, 1u>;
@ -56,18 +54,15 @@ struct Lights {
n_directional_lights: u32; n_directional_lights: u32;
}; };
[[block]]
struct PointLights { struct PointLights {
data: array<PointLight, 256u>; data: array<PointLight, 256u>;
}; };
[[block]]
struct ClusterLightIndexLists { struct ClusterLightIndexLists {
// each u32 contains 4 u8 indices into the PointLights array // each u32 contains 4 u8 indices into the PointLights array
data: array<vec4<u32>, 1024u>; data: array<vec4<u32>, 1024u>;
}; };
[[block]]
struct ClusterOffsetsAndCounts { struct ClusterOffsetsAndCounts {
// each u32 contains a 24-bit index into ClusterLightIndexLists in the high 24 bits // 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 // and an 8-bit count of the number of lights in the low 8 bits

View File

@ -3,6 +3,7 @@ mod mesh;
pub use light::*; pub use light::*;
pub use mesh::*; pub use mesh::*;
use wgpu::SamplerBindingType;
use crate::{AlphaMode, StandardMaterial, StandardMaterialUniformData, PBR_SHADER_HANDLE}; use crate::{AlphaMode, StandardMaterial, StandardMaterialUniformData, PBR_SHADER_HANDLE};
use bevy_asset::Handle; use bevy_asset::Handle;
@ -81,10 +82,7 @@ impl FromWorld for PbrPipeline {
BindGroupLayoutEntry { BindGroupLayoutEntry {
binding: 2, binding: 2,
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler { ty: BindingType::Sampler(SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
// Emissive Texture // Emissive Texture
@ -102,10 +100,7 @@ impl FromWorld for PbrPipeline {
BindGroupLayoutEntry { BindGroupLayoutEntry {
binding: 4, binding: 4,
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler { ty: BindingType::Sampler(SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
// Metallic Roughness Texture // Metallic Roughness Texture
@ -123,10 +118,7 @@ impl FromWorld for PbrPipeline {
BindGroupLayoutEntry { BindGroupLayoutEntry {
binding: 6, binding: 6,
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler { ty: BindingType::Sampler(SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
// Occlusion Texture // Occlusion Texture
@ -144,10 +136,7 @@ impl FromWorld for PbrPipeline {
BindGroupLayoutEntry { BindGroupLayoutEntry {
binding: 8, binding: 8,
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler { ty: BindingType::Sampler(SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
// Normal Map Texture // Normal Map Texture
@ -165,10 +154,7 @@ impl FromWorld for PbrPipeline {
BindGroupLayoutEntry { BindGroupLayoutEntry {
binding: 10, binding: 10,
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler { ty: BindingType::Sampler(SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
], ],

View File

@ -38,7 +38,6 @@
[[group(2), binding(0)]] [[group(2), binding(0)]]
var<uniform> mesh: Mesh; var<uniform> mesh: Mesh;
[[block]]
struct StandardMaterial { struct StandardMaterial {
base_color: vec4<f32>; base_color: vec4<f32>;
emissive: vec4<f32>; emissive: vec4<f32>;

View File

@ -36,8 +36,8 @@ bevy_utils = { path = "../bevy_utils", version = "0.5.0" }
image = { version = "0.23.12", default-features = false } image = { version = "0.23.12", default-features = false }
# misc # misc
wgpu = { version = "0.11.0", features = ["spirv"] } wgpu = { version = "0.12.0", features = ["spirv"] }
naga = { version = "0.7.0", features = ["glsl-in", "spv-in", "spv-out", "wgsl-in", "wgsl-out"] } naga = { version = "0.8.0", features = ["glsl-in", "spv-in", "spv-out", "wgsl-in", "wgsl-out"] }
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"] }
@ -53,4 +53,4 @@ regex = "1.5"
crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] }
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
wgpu = { version = "0.11.0", features = ["spirv", "webgl"] } wgpu = { version = "0.12.0", features = ["spirv", "webgl"] }

View File

@ -339,6 +339,7 @@ impl RenderPipelineCache {
}; };
let descriptor = RawRenderPipelineDescriptor { let descriptor = RawRenderPipelineDescriptor {
multiview: None,
depth_stencil: descriptor.depth_stencil.clone(), depth_stencil: descriptor.depth_stencil.clone(),
label: descriptor.label.as_deref(), label: descriptor.label.as_deref(),
layout, layout,

View File

@ -1,6 +1,7 @@
use bevy_asset::{AssetLoader, Handle, LoadContext, LoadedAsset}; use bevy_asset::{AssetLoader, Handle, LoadContext, LoadedAsset};
use bevy_reflect::{TypeUuid, Uuid}; use bevy_reflect::{TypeUuid, Uuid};
use bevy_utils::{tracing::error, BoxedFuture, HashMap}; use bevy_utils::{tracing::error, BoxedFuture, HashMap};
use naga::back::wgsl::WriterFlags;
use naga::{valid::ModuleInfo, Module}; use naga::{valid::ModuleInfo, Module};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
@ -29,9 +30,8 @@ pub enum ShaderReflectError {
#[error(transparent)] #[error(transparent)]
SpirVParse(#[from] naga::front::spv::Error), SpirVParse(#[from] naga::front::spv::Error),
#[error(transparent)] #[error(transparent)]
Validation(#[from] naga::valid::ValidationError), Validation(#[from] naga::WithSpan<naga::valid::ValidationError>),
} }
/// A shader, as defined by its [`ShaderSource`] and [`ShaderStage`](naga::ShaderStage) /// A shader, as defined by its [`ShaderSource`] and [`ShaderStage`](naga::ShaderStage)
/// This is an "unprocessed" shader. It can contain preprocessor directives. /// This is an "unprocessed" shader. It can contain preprocessor directives.
#[derive(Debug, Clone, TypeUuid)] #[derive(Debug, Clone, TypeUuid)]
@ -204,7 +204,7 @@ impl ShaderReflection {
} }
pub fn get_wgsl(&self) -> Result<String, naga::back::wgsl::Error> { pub fn get_wgsl(&self) -> Result<String, naga::back::wgsl::Error> {
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}; use crate::render_resource::{ProcessShaderError, Shader, ShaderImport, ShaderProcessor};
#[rustfmt::skip] #[rustfmt::skip]
const WGSL: &str = r" const WGSL: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -493,7 +492,6 @@ fn vertex(
"; ";
const WGSL_ELSE: &str = r" const WGSL_ELSE: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -527,7 +525,6 @@ fn vertex(
"; ";
const WGSL_NESTED_IFDEF: &str = r" const WGSL_NESTED_IFDEF: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -560,7 +557,6 @@ fn vertex(
"; ";
const WGSL_NESTED_IFDEF_ELSE: &str = r" const WGSL_NESTED_IFDEF_ELSE: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -599,7 +595,6 @@ fn vertex(
fn process_shader_def_defined() { fn process_shader_def_defined() {
#[rustfmt::skip] #[rustfmt::skip]
const EXPECTED: &str = r" const EXPECTED: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -642,7 +637,6 @@ fn vertex(
fn process_shader_def_not_defined() { fn process_shader_def_not_defined() {
#[rustfmt::skip] #[rustfmt::skip]
const EXPECTED: &str = r" const EXPECTED: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -683,7 +677,6 @@ fn vertex(
fn process_shader_def_else() { fn process_shader_def_else() {
#[rustfmt::skip] #[rustfmt::skip]
const EXPECTED: &str = r" const EXPECTED: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -849,7 +842,6 @@ void bar() { }
fn process_nested_shader_def_outer_defined_inner_not() { fn process_nested_shader_def_outer_defined_inner_not() {
#[rustfmt::skip] #[rustfmt::skip]
const EXPECTED: &str = r" const EXPECTED: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -890,7 +882,6 @@ fn vertex(
fn process_nested_shader_def_outer_defined_inner_else() { fn process_nested_shader_def_outer_defined_inner_else() {
#[rustfmt::skip] #[rustfmt::skip]
const EXPECTED: &str = r" const EXPECTED: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -933,7 +924,6 @@ fn vertex(
fn process_nested_shader_def_neither_defined() { fn process_nested_shader_def_neither_defined() {
#[rustfmt::skip] #[rustfmt::skip]
const EXPECTED: &str = r" const EXPECTED: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -974,7 +964,6 @@ fn vertex(
fn process_nested_shader_def_neither_defined_else() { fn process_nested_shader_def_neither_defined_else() {
#[rustfmt::skip] #[rustfmt::skip]
const EXPECTED: &str = r" const EXPECTED: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -1015,7 +1004,6 @@ fn vertex(
fn process_nested_shader_def_inner_defined_outer_not() { fn process_nested_shader_def_inner_defined_outer_not() {
#[rustfmt::skip] #[rustfmt::skip]
const EXPECTED: &str = r" const EXPECTED: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;
@ -1056,7 +1044,6 @@ fn vertex(
fn process_nested_shader_def_both_defined() { fn process_nested_shader_def_both_defined() {
#[rustfmt::skip] #[rustfmt::skip]
const EXPECTED: &str = r" const EXPECTED: &str = r"
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;

View File

@ -31,3 +31,4 @@ guillotiere = "0.6.0"
thiserror = "1.0" thiserror = "1.0"
rectangle-pack = "0.4" rectangle-pack = "0.4"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
wgpu = "0.12.0"

View File

@ -26,6 +26,7 @@ use bevy_transform::components::GlobalTransform;
use bevy_utils::HashMap; use bevy_utils::HashMap;
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use crevice::std140::AsStd140; use crevice::std140::AsStd140;
use wgpu::SamplerBindingType;
pub struct SpritePipeline { pub struct SpritePipeline {
view_layout: BindGroupLayout, view_layout: BindGroupLayout,
@ -66,10 +67,7 @@ impl FromWorld for SpritePipeline {
BindGroupLayoutEntry { BindGroupLayoutEntry {
binding: 1, binding: 1,
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler { ty: BindingType::Sampler(SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
], ],
@ -140,8 +138,8 @@ impl SpecializedPipeline for SpritePipeline {
primitive: PrimitiveState { primitive: PrimitiveState {
front_face: FrontFace::Ccw, front_face: FrontFace::Ccw,
cull_mode: None, cull_mode: None,
unclipped_depth: false,
polygon_mode: PolygonMode::Fill, polygon_mode: PolygonMode::Fill,
clamp_depth: false,
conservative: false, conservative: false,
topology: PrimitiveTopology::TriangleList, topology: PrimitiveTopology::TriangleList,
strip_index_format: None, strip_index_format: None,

View File

@ -1,4 +1,3 @@
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;

View File

@ -33,3 +33,4 @@ serde = {version = "1", features = ["derive"]}
smallvec = { version = "1.6", features = ["union", "const_generics"] } smallvec = { version = "1.6", features = ["union", "const_generics"] }
bytemuck = { version = "1.5", features = ["derive"] } bytemuck = { version = "1.5", features = ["derive"] }
crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] }
wgpu = "0.12.0"

View File

@ -4,6 +4,7 @@ use bevy_render::{
}; };
use crevice::std140::AsStd140; use crevice::std140::AsStd140;
use wgpu::SamplerBindingType;
pub struct UiPipeline { pub struct UiPipeline {
pub view_layout: BindGroupLayout, pub view_layout: BindGroupLayout,
@ -44,10 +45,7 @@ impl FromWorld for UiPipeline {
BindGroupLayoutEntry { BindGroupLayoutEntry {
binding: 1, binding: 1,
visibility: ShaderStages::FRAGMENT, visibility: ShaderStages::FRAGMENT,
ty: BindingType::Sampler { ty: BindingType::Sampler(SamplerBindingType::Filtering),
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
], ],
@ -114,8 +112,8 @@ impl SpecializedPipeline for UiPipeline {
primitive: PrimitiveState { primitive: PrimitiveState {
front_face: FrontFace::Ccw, front_face: FrontFace::Ccw,
cull_mode: None, cull_mode: None,
unclipped_depth: false,
polygon_mode: PolygonMode::Fill, polygon_mode: PolygonMode::Fill,
clamp_depth: false,
conservative: false, conservative: false,
topology: PrimitiveTopology::TriangleList, topology: PrimitiveTopology::TriangleList,
strip_index_format: None, strip_index_format: None,

View File

@ -1,4 +1,3 @@
[[block]]
struct View { struct View {
view_proj: mat4x4<f32>; view_proj: mat4x4<f32>;
world_position: vec3<f32>; world_position: vec3<f32>;

View File

@ -16,5 +16,5 @@ memoffset = "0.6.4"
mint = "0.5.5" mint = "0.5.5"
futures = { version = "0.3.17", features = ["executor"], optional = true } futures = { version = "0.3.17", features = ["executor"], optional = true }
naga = { version = "0.7.0", features = ["glsl-in", "wgsl-out"], optional = true } naga = { version = "0.8.0", features = ["glsl-in", "wgsl-out"], optional = true }
wgpu = { version = "0.11.0", optional = true } wgpu = { version = "0.12.0", optional = true }

View File

@ -58,7 +58,6 @@ skip = [
{ name = "proc-macro-crate", version = "0.1" }, # from rodio v0.14.0 { name = "proc-macro-crate", version = "0.1" }, # from rodio v0.14.0
{ name = "stdweb", 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 = "strsim", version = "0.9" }, # from rodio v0.14.0
{ name = "raw-window-handle", version = "0.3" }, # from wgpu v0.11.1
] ]
[sources] [sources]