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 {
color: vec4<f32>;
};

View file

@ -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"

View file

@ -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"] }

View file

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

View file

@ -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 {

View file

@ -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,

View file

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

View file

@ -1,4 +1,3 @@
[[block]]
struct View {
view_proj: mat4x4<f32>;
inverse_view: mat4x4<f32>;
@ -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<DirectionalLight, 1u>;
@ -56,18 +54,15 @@ struct Lights {
n_directional_lights: u32;
};
[[block]]
struct PointLights {
data: array<PointLight, 256u>;
};
[[block]]
struct ClusterLightIndexLists {
// each u32 contains 4 u8 indices into the PointLights array
data: array<vec4<u32>, 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

View file

@ -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,
},
],

View file

@ -38,7 +38,6 @@
[[group(2), binding(0)]]
var<uniform> mesh: Mesh;
[[block]]
struct StandardMaterial {
base_color: vec4<f32>;
emissive: vec4<f32>;
@ -505,7 +504,7 @@ fn fragment(in: FragmentInput) -> [[location(0)]] vec4<f32> {
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;

View file

@ -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"] }

View file

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

View file

@ -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<naga::valid::ValidationError>),
}
/// 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<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};
#[rustfmt::skip]
const WGSL: &str = r"
[[block]]
struct View {
view_proj: mat4x4<f32>;
world_position: vec3<f32>;
@ -493,7 +492,6 @@ fn vertex(
";
const WGSL_ELSE: &str = r"
[[block]]
struct View {
view_proj: mat4x4<f32>;
world_position: vec3<f32>;
@ -527,7 +525,6 @@ fn vertex(
";
const WGSL_NESTED_IFDEF: &str = r"
[[block]]
struct View {
view_proj: mat4x4<f32>;
world_position: vec3<f32>;
@ -560,7 +557,6 @@ fn vertex(
";
const WGSL_NESTED_IFDEF_ELSE: &str = r"
[[block]]
struct View {
view_proj: mat4x4<f32>;
world_position: vec3<f32>;
@ -599,7 +595,6 @@ fn vertex(
fn process_shader_def_defined() {
#[rustfmt::skip]
const EXPECTED: &str = r"
[[block]]
struct View {
view_proj: mat4x4<f32>;
world_position: vec3<f32>;
@ -642,7 +637,6 @@ fn vertex(
fn process_shader_def_not_defined() {
#[rustfmt::skip]
const EXPECTED: &str = r"
[[block]]
struct View {
view_proj: mat4x4<f32>;
world_position: vec3<f32>;
@ -683,7 +677,6 @@ fn vertex(
fn process_shader_def_else() {
#[rustfmt::skip]
const EXPECTED: &str = r"
[[block]]
struct View {
view_proj: mat4x4<f32>;
world_position: vec3<f32>;
@ -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<f32>;
world_position: vec3<f32>;
@ -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<f32>;
world_position: vec3<f32>;
@ -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<f32>;
world_position: vec3<f32>;
@ -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<f32>;
world_position: vec3<f32>;
@ -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<f32>;
world_position: vec3<f32>;
@ -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<f32>;
world_position: vec3<f32>;

View file

@ -31,3 +31,4 @@ guillotiere = "0.6.0"
thiserror = "1.0"
rectangle-pack = "0.4"
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 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,

View file

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

View file

@ -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"] }
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 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,

View file

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

View file

@ -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 }

View file

@ -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]