Skip to content

Ugrade to wgpu version 25.0 #19563

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_color/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ serde = { version = "1.0", features = [
], default-features = false, optional = true }
thiserror = { version = "2", default-features = false }
derive_more = { version = "1", default-features = false, features = ["from"] }
wgpu-types = { version = "24", default-features = false, optional = true }
wgpu-types = { version = "25", default-features = false, optional = true }
encase = { version = "0.10", default-features = false, optional = true }

[features]
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/src/line_joints.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct LineGizmoUniform {
#endif
}

@group(1) @binding(0) var<uniform> joints_gizmo: LineGizmoUniform;
@group(2) @binding(0) var<uniform> joints_gizmo: LineGizmoUniform;

struct VertexInput {
@location(0) position_a: vec3<f32>,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/src/lines.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct LineGizmoUniform {
#endif
}

@group(1) @binding(0) var<uniform> line_gizmo: LineGizmoUniform;
@group(2) @binding(0) var<uniform> line_gizmo: LineGizmoUniform;

struct VertexInput {
@location(0) position_a: vec3<f32>,
Expand Down
18 changes: 10 additions & 8 deletions crates/bevy_gizmos/src/pipeline_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ impl SpecializedRenderPipeline for LineGizmoPipeline {
.get_view_layout(key.view_key.into())
.clone();

let layout = vec![view_layout, self.uniform_layout.clone()];
let mut layout = view_layout.to_vec();
layout.push(self.uniform_layout.clone());

let fragment_entry_point = match key.line_style {
GizmoLineStyle::Solid => "fragment_solid",
Expand Down Expand Up @@ -221,7 +222,8 @@ impl SpecializedRenderPipeline for LineJointGizmoPipeline {
.get_view_layout(key.view_key.into())
.clone();

let layout = vec![view_layout, self.uniform_layout.clone()];
let mut layout = view_layout.to_vec();
layout.push(self.uniform_layout.clone());

if key.joints == GizmoLineJoint::None {
error!("There is no entry point for line joints with GizmoLineJoints::None. Please consider aborting the drawing process before reaching this stage.");
Expand Down Expand Up @@ -273,20 +275,20 @@ impl SpecializedRenderPipeline for LineJointGizmoPipeline {

type DrawLineGizmo3d = (
SetItemPipeline,
SetMeshViewBindGroup<0>,
SetLineGizmoBindGroup<1>,
SetMeshViewBindGroup<0, 1>,
SetLineGizmoBindGroup<2>,
DrawLineGizmo<false>,
);
type DrawLineGizmo3dStrip = (
SetItemPipeline,
SetMeshViewBindGroup<0>,
SetLineGizmoBindGroup<1>,
SetMeshViewBindGroup<0, 1>,
SetLineGizmoBindGroup<2>,
DrawLineGizmo<true>,
);
type DrawLineJointGizmo3d = (
SetItemPipeline,
SetMeshViewBindGroup<0>,
SetLineGizmoBindGroup<1>,
SetMeshViewBindGroup<0, 1>,
SetLineGizmoBindGroup<2>,
DrawLineJointGizmo,
);

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ image = { version = "0.25.2", default-features = false }
# misc
bitflags = { version = "2.3", features = ["serde"] }
bytemuck = { version = "1.5" }
wgpu-types = { version = "24", default-features = false }
wgpu-types = { version = "25", default-features = false }
serde = { version = "1", features = ["derive"] }
thiserror = { version = "2", default-features = false }
futures-lite = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_mesh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bevy_platform = { path = "../bevy_platform", version = "0.16.0-dev", default-fea
# other
bitflags = { version = "2.3", features = ["serde"] }
bytemuck = { version = "1.5" }
wgpu-types = { version = "24", default-features = false }
wgpu-types = { version = "25", default-features = false }
serde = { version = "1", features = ["derive"] }
hexasphere = "15.0"
thiserror = { version = "2", default-features = false }
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_pbr/src/deferred/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ impl SpecializedRenderPipeline for DeferredLightingLayout {
#[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu")))]
shader_defs.push("SIXTEEN_BYTE_ALIGNMENT".into());

let mut layout = self.mesh_pipeline.get_view_layout(key.into()).to_vec();
layout.push(self.bind_group_layout_1.clone());

RenderPipelineDescriptor {
label: Some("deferred_lighting_pipeline".into()),
layout: vec![
self.mesh_pipeline.get_view_layout(key.into()).clone(),
self.bind_group_layout_1.clone(),
],
layout,
vertex: VertexState {
shader: self.deferred_lighting_shader.clone(),
shader_defs: shader_defs.clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ fn shader_ref(path: PathBuf) -> ShaderRef {
const MESHLET_VISIBILITY_BUFFER_RESOLVE_SHADER_HANDLE: Handle<Shader> =
weak_handle!("69187376-3dea-4d0f-b3f5-185bde63d6a2");

pub const TONEMAPPING_LUT_TEXTURE_BINDING_INDEX: u32 = 26;
pub const TONEMAPPING_LUT_SAMPLER_BINDING_INDEX: u32 = 27;
pub const TONEMAPPING_LUT_TEXTURE_BINDING_INDEX: u32 = 18;
pub const TONEMAPPING_LUT_SAMPLER_BINDING_INDEX: u32 = 19;

/// Sets up the entire PBR infrastructure of bevy.
pub struct PbrPlugin {
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ use tracing::error;
/// In WGSL shaders, the material's binding would look like this:
///
/// ```wgsl
/// @group(2) @binding(0) var<uniform> color: vec4<f32>;
/// @group(2) @binding(1) var color_texture: texture_2d<f32>;
/// @group(2) @binding(2) var color_sampler: sampler;
/// @group(3) @binding(0) var<uniform> color: vec4<f32>;
/// @group(3) @binding(1) var color_texture: texture_2d<f32>;
/// @group(3) @binding(2) var color_sampler: sampler;
/// ```
pub trait Material: Asset + AsBindGroup + Clone + Sized {
/// Returns this material's vertex shader. If [`ShaderRef::Default`] is returned, the default mesh vertex shader
Expand Down Expand Up @@ -501,7 +501,7 @@ where
descriptor.fragment.as_mut().unwrap().shader = fragment_shader.clone();
}

descriptor.layout.insert(2, self.material_layout.clone());
descriptor.layout.insert(3, self.material_layout.clone());

M::specialize(self, &mut descriptor, layout, key)?;

Expand Down Expand Up @@ -543,9 +543,9 @@ impl<M: Material> FromWorld for MaterialPipeline<M> {

type DrawMaterial<M> = (
SetItemPipeline,
SetMeshViewBindGroup<0>,
SetMeshBindGroup<1>,
SetMaterialBindGroup<M, 2>,
SetMeshViewBindGroup<0, 1>,
SetMeshBindGroup<2>,
SetMaterialBindGroup<M, 3>,
DrawMesh,
);

Expand Down
58 changes: 42 additions & 16 deletions crates/bevy_pbr/src/prepass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ where
Render,
prepare_prepass_view_bind_group::<M>.in_set(RenderSystems::PrepareBindGroups),
)
.init_resource::<PrepassViewBindGroup>()
.init_resource::<SpecializedMeshPipelines<PrepassPipeline<M>>>()
.allow_ambiguous_resource::<SpecializedMeshPipelines<PrepassPipeline<M>>>();
}
Expand All @@ -105,7 +104,9 @@ where
return;
};

render_app.init_resource::<PrepassPipeline<M>>();
render_app
.init_resource::<PrepassPipeline<M>>()
.init_resource::<PrepassViewBindGroup>();
}
}

Expand Down Expand Up @@ -267,6 +268,7 @@ pub struct PrepassPipelineInternal {
pub view_layout_motion_vectors: BindGroupLayout,
pub view_layout_no_motion_vectors: BindGroupLayout,
pub mesh_layouts: MeshLayouts,
pub empty_layout: BindGroupLayout,
pub material_layout: BindGroupLayout,
pub prepass_material_vertex_shader: Option<Handle<Shader>>,
pub prepass_material_fragment_shader: Option<Handle<Shader>>,
Expand Down Expand Up @@ -376,6 +378,7 @@ impl<M: Material> FromWorld for PrepassPipeline<M> {
skins_use_uniform_buffers: skin::skins_use_uniform_buffers(render_device),
depth_clip_control_supported,
binding_arrays_are_usable: binding_arrays_are_usable(render_device, render_adapter),
empty_layout: render_device.create_bind_group_layout("prepass_empty_layout", &[]),
};
PrepassPipeline {
internal,
Expand Down Expand Up @@ -420,13 +423,14 @@ impl PrepassPipelineInternal {
layout: &MeshVertexBufferLayoutRef,
) -> Result<RenderPipelineDescriptor, SpecializedMeshPipelineError> {
let mut shader_defs = shader_defs;
let mut bind_group_layouts = vec![if mesh_key
.contains(MeshPipelineKey::MOTION_VECTOR_PREPASS)
{
self.view_layout_motion_vectors.clone()
} else {
self.view_layout_no_motion_vectors.clone()
}];
let mut bind_group_layouts = vec![
if mesh_key.contains(MeshPipelineKey::MOTION_VECTOR_PREPASS) {
self.view_layout_motion_vectors.clone()
} else {
self.view_layout_no_motion_vectors.clone()
},
self.empty_layout.clone(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this empty_layout?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wgpu gets upset if you have a gap in bind groups i guess. should double check that this doesn't have any perf implications but it seems to work.

];
let mut vertex_attributes = Vec::new();

// Let the shader code know that it's running in a prepass pipeline.
Expand Down Expand Up @@ -551,7 +555,7 @@ impl PrepassPipelineInternal {
&mut vertex_attributes,
self.skins_use_uniform_buffers,
);
bind_group_layouts.insert(1, bind_group);
bind_group_layouts.insert(2, bind_group);
let vertex_buffer_layout = layout.0.get_layout(&vertex_attributes)?;
// Setup prepass fragment targets - normals in slot 0 (or None if not needed), motion vectors in slot 1
let mut targets = prepass_target_descriptors(
Expand Down Expand Up @@ -713,10 +717,29 @@ pub fn prepare_previous_view_uniforms(
}
}

#[derive(Default, Resource)]
#[derive(Resource)]
pub struct PrepassViewBindGroup {
pub motion_vectors: Option<BindGroup>,
pub no_motion_vectors: Option<BindGroup>,
pub empty_bind_group: BindGroup,
}

impl FromWorld for PrepassViewBindGroup {
fn from_world(world: &mut World) -> Self {
let pipeline = world.resource::<PrepassPipeline<StandardMaterial>>();

let render_device = world.resource::<RenderDevice>();
let empty_bind_group = render_device.create_bind_group(
"prepass_view_empty_bind_group",
&pipeline.internal.empty_layout,
&[],
);
PrepassViewBindGroup {
motion_vectors: None,
no_motion_vectors: None,
empty_bind_group,
}
}
}

pub fn prepare_prepass_view_bind_group<M: Material>(
Expand Down Expand Up @@ -1231,8 +1254,10 @@ pub fn queue_prepass_material_meshes<M: Material>(
}
}

pub struct SetPrepassViewBindGroup<const I: usize>;
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetPrepassViewBindGroup<I> {
pub struct SetPrepassViewBindGroup<const I: usize, const J: usize>;
impl<P: PhaseItem, const I: usize, const J: usize> RenderCommand<P>
for SetPrepassViewBindGroup<I, J>
{
type Param = SRes<PrepassViewBindGroup>;
type ViewQuery = (
Read<ViewUniformOffset>,
Expand Down Expand Up @@ -1274,15 +1299,16 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetPrepassViewBindGroup<
);
}
}
pass.set_bind_group(J, &prepass_view_bind_group.empty_bind_group, &[]);

RenderCommandResult::Success
}
}

pub type DrawPrepass<M> = (
SetItemPipeline,
SetPrepassViewBindGroup<0>,
SetMeshBindGroup<1>,
SetMaterialBindGroup<M, 2>,
SetPrepassViewBindGroup<0, 1>,
SetMeshBindGroup<2>,
SetMaterialBindGroup<M, 3>,
DrawMesh,
);
9 changes: 5 additions & 4 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ impl MeshPipeline {
}
}

pub fn get_view_layout(&self, layout_key: MeshPipelineViewLayoutKey) -> &BindGroupLayout {
pub fn get_view_layout(&self, layout_key: MeshPipelineViewLayoutKey) -> &[BindGroupLayout; 2] {
self.view_layouts.get_view_layout(layout_key)
}
}
Expand Down Expand Up @@ -2320,7 +2320,7 @@ impl SpecializedMeshPipeline for MeshPipeline {
shader_defs.push("PBR_SPECULAR_TEXTURES_SUPPORTED".into());
}

let mut bind_group_layout = vec![self.get_view_layout(key.into()).clone()];
let mut bind_group_layout = self.get_view_layout(key.into()).to_vec();

if key.msaa_samples() > 1 {
shader_defs.push("MULTISAMPLED".into());
Expand Down Expand Up @@ -2847,8 +2847,8 @@ fn prepare_mesh_bind_groups_for_phase(
groups
}

pub struct SetMeshViewBindGroup<const I: usize>;
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMeshViewBindGroup<I> {
pub struct SetMeshViewBindGroup<const I: usize, const J: usize>;
impl<P: PhaseItem, const I: usize, const J: usize> RenderCommand<P> for SetMeshViewBindGroup<I, J> {
type Param = ();
type ViewQuery = (
Read<ViewUniformOffset>,
Expand Down Expand Up @@ -2891,6 +2891,7 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetMeshViewBindGroup<I>
offsets.push(layers_count_offset.offset);
}
pass.set_bind_group(I, &mesh_view_bind_group.value, &offsets);
pass.set_bind_group(J, &mesh_view_bind_group.value_binding_array, &[]);

RenderCommandResult::Success
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/render/mesh_bindings.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#ifndef MESHLET_MESH_MATERIAL_PASS
#ifdef PER_OBJECT_BUFFER_BATCH_SIZE
@group(1) @binding(0) var<uniform> mesh: array<Mesh, #{PER_OBJECT_BUFFER_BATCH_SIZE}u>;
@group(2) @binding(0) var<uniform> mesh: array<Mesh, #{PER_OBJECT_BUFFER_BATCH_SIZE}u>;
#else
@group(1) @binding(0) var<storage> mesh: array<Mesh>;
@group(2) @binding(0) var<storage> mesh: array<Mesh>;
#endif // PER_OBJECT_BUFFER_BATCH_SIZE
#endif // MESHLET_MESH_MATERIAL_PASS
Loading
Loading