Skip to content

Commit 669d139

Browse files
JMS55alice-i-cecileIceSentrymockersf
authored
Upgrade to wgpu v24 (bevyengine#17542)
Didn't remove WgpuWrapper. Not sure if it's needed or not still. ## Testing - Did you test these changes? If so, how? Example runner - Are there any parts that need more testing? Web (portable atomics thingy?), DXC. ## Migration Guide - Bevy has upgraded to [wgpu v24](https://github.com/gfx-rs/wgpu/blob/trunk/CHANGELOG.md#v2400-2025-01-15). - When using the DirectX 12 rendering backend, the new priority system for choosing a shader compiler is as follows: - If the `WGPU_DX12_COMPILER` environment variable is set at runtime, it is used - Else if the new `statically-linked-dxc` feature is enabled, a custom version of DXC will be statically linked into your app at compile time. - Else Bevy will look in the app's working directory for `dxcompiler.dll` and `dxil.dll` at runtime. - Else if they are missing, Bevy will fall back to FXC (not recommended) --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: IceSentry <[email protected]> Co-authored-by: François Mockers <[email protected]>
1 parent 33e8333 commit 669d139

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+174
-175
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ bevy_remote = ["bevy_internal/bevy_remote"]
256256
# Enable passthrough loading for SPIR-V shaders (Only supported on Vulkan, shader capabilities and extensions must agree with the platform implementation)
257257
spirv_shader_passthrough = ["bevy_internal/spirv_shader_passthrough"]
258258

259+
# Statically linked DXC shader compiler for DirectX 12
260+
statically-linked-dxc = ["bevy_internal/statically-linked-dxc"]
261+
259262
# Tracing support, saving a file in Chrome Tracing format
260263
trace_chrome = ["trace", "bevy_internal/trace_chrome"]
261264

crates/bevy_color/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ serde = { version = "1.0", features = [
2222
], default-features = false, optional = true }
2323
thiserror = { version = "2", default-features = false }
2424
derive_more = { version = "1", default-features = false, features = ["from"] }
25-
wgpu-types = { version = "23", default-features = false, optional = true }
25+
wgpu-types = { version = "24", default-features = false, optional = true }
2626
encase = { version = "0.10", default-features = false, optional = true }
2727

2828
[features]

crates/bevy_core_pipeline/src/experimental/mip_generation/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ pub fn create_depth_pyramid_dummy_texture(
484484
label: Some(texture_view_label),
485485
format: Some(TextureFormat::R32Float),
486486
dimension: Some(TextureViewDimension::D2),
487+
usage: None,
487488
aspect: TextureAspect::All,
488489
base_mip_level: 0,
489490
mip_level_count: Some(1),
@@ -551,6 +552,7 @@ impl ViewDepthPyramid {
551552
label: Some(texture_view_label),
552553
format: Some(TextureFormat::R32Float),
553554
dimension: Some(TextureViewDimension::D2),
555+
usage: None,
554556
aspect: TextureAspect::All,
555557
base_mip_level: i as u32,
556558
mip_level_count: Some(1),

crates/bevy_image/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ image = { version = "0.25.2", default-features = false }
6363
# misc
6464
bitflags = { version = "2.3", features = ["serde"] }
6565
bytemuck = { version = "1.5" }
66-
wgpu-types = { version = "23", default-features = false }
67-
# TODO: remove dependency on wgpu once https://github.com/gfx-rs/wgpu/pull/6648, 6649 and 6650 have been released
68-
wgpu = { version = "23.0.1", default-features = false }
66+
wgpu-types = { version = "24", default-features = false }
6967
serde = { version = "1", features = ["derive"] }
7068
thiserror = { version = "2", default-features = false }
7169
futures-lite = "2.0.1"

crates/bevy_image/src/dds.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
33
use ddsfile::{Caps2, D3DFormat, Dds, DxgiFormat};
44
use std::io::Cursor;
5-
use wgpu::TextureViewDescriptor;
6-
use wgpu_types::{Extent3d, TextureDimension, TextureFormat, TextureViewDimension};
5+
use wgpu_types::{
6+
Extent3d, TextureDimension, TextureFormat, TextureViewDescriptor, TextureViewDimension,
7+
};
78
#[cfg(debug_assertions)]
89
use {bevy_utils::once, tracing::warn};
910

@@ -283,8 +284,7 @@ pub fn dds_format_to_texture_format(
283284

284285
#[cfg(test)]
285286
mod test {
286-
use wgpu::util::TextureDataOrder;
287-
use wgpu_types::{TextureDescriptor, TextureDimension, TextureFormat};
287+
use wgpu_types::{TextureDataOrder, TextureDescriptor, TextureDimension, TextureFormat};
288288

289289
use crate::CompressedImageFormats;
290290

crates/bevy_image/src/image.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use bevy_math::{AspectRatio, UVec2, UVec3, Vec2};
1313
use core::hash::Hash;
1414
use serde::{Deserialize, Serialize};
1515
use thiserror::Error;
16-
use wgpu::{SamplerDescriptor, TextureViewDescriptor};
1716
use wgpu_types::{
1817
AddressMode, CompareFunction, Extent3d, Features, FilterMode, SamplerBorderColor,
19-
TextureDescriptor, TextureDimension, TextureFormat, TextureUsages,
18+
SamplerDescriptor, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages,
19+
TextureViewDescriptor,
2020
};
2121

2222
pub trait BevyDefault {
@@ -343,7 +343,7 @@ pub struct Image {
343343
pub texture_descriptor: TextureDescriptor<Option<&'static str>, &'static [TextureFormat]>,
344344
/// The [`ImageSampler`] to use during rendering.
345345
pub sampler: ImageSampler,
346-
pub texture_view_descriptor: Option<TextureViewDescriptor<'static>>,
346+
pub texture_view_descriptor: Option<TextureViewDescriptor<Option<&'static str>>>,
347347
pub asset_usage: RenderAssetUsages,
348348
}
349349

@@ -559,7 +559,7 @@ impl ImageSamplerDescriptor {
559559
}
560560
}
561561

562-
pub fn as_wgpu(&self) -> SamplerDescriptor {
562+
pub fn as_wgpu(&self) -> SamplerDescriptor<Option<&str>> {
563563
SamplerDescriptor {
564564
label: self.label.as_deref(),
565565
address_mode_u: self.address_mode_u.into(),
@@ -669,8 +669,8 @@ impl From<SamplerBorderColor> for ImageSamplerBorderColor {
669669
}
670670
}
671671

672-
impl<'a> From<SamplerDescriptor<'a>> for ImageSamplerDescriptor {
673-
fn from(value: SamplerDescriptor) -> Self {
672+
impl From<SamplerDescriptor<Option<&str>>> for ImageSamplerDescriptor {
673+
fn from(value: SamplerDescriptor<Option<&str>>) -> Self {
674674
ImageSamplerDescriptor {
675675
label: value.label.map(ToString::to_string),
676676
address_mode_u: value.address_mode_u.into(),

crates/bevy_image/src/ktx2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use ktx2::{
1313
BasicDataFormatDescriptor, ChannelTypeQualifiers, ColorModel, DataFormatDescriptorHeader,
1414
Header, SampleInformation,
1515
};
16-
use wgpu::TextureViewDescriptor;
1716
use wgpu_types::{
18-
AstcBlock, AstcChannel, Extent3d, TextureDimension, TextureFormat, TextureViewDimension,
17+
AstcBlock, AstcChannel, Extent3d, TextureDimension, TextureFormat, TextureViewDescriptor,
18+
TextureViewDimension,
1919
};
2020

2121
use super::{CompressedImageFormats, DataFormat, Image, TextureError, TranscodeFormat};

crates/bevy_internal/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ webp = ["bevy_image/webp"]
5959
# Enable SPIR-V passthrough
6060
spirv_shader_passthrough = ["bevy_render/spirv_shader_passthrough"]
6161

62+
# Statically linked DXC shader compiler for DirectX 12
63+
# TODO: When wgpu switches to DirectX 12 instead of Vulkan by default on windows, make this a default feature
64+
statically-linked-dxc = ["bevy_render/statically-linked-dxc"]
65+
6266
# Include tonemapping LUT KTX2 files.
6367
tonemapping_luts = ["bevy_core_pipeline/tonemapping_luts"]
6468

crates/bevy_mesh/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-d
2929
# other
3030
bitflags = { version = "2.3", features = ["serde"] }
3131
bytemuck = { version = "1.5" }
32-
wgpu-types = { version = "23", default-features = false }
32+
wgpu-types = { version = "24", default-features = false }
3333
serde = { version = "1", features = ["derive"] }
3434
hexasphere = "15.0"
3535
thiserror = { version = "2", default-features = false }

crates/bevy_mesh/src/mesh.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use super::{
66
GenerateTangentsError, Indices, MeshAttributeData, MeshTrianglesError, MeshVertexAttribute,
77
MeshVertexAttributeId, MeshVertexBufferLayout, MeshVertexBufferLayoutRef,
88
MeshVertexBufferLayouts, MeshWindingInvertError, VertexAttributeValues, VertexBufferLayout,
9-
VertexFormatSize,
109
};
1110
use alloc::collections::BTreeMap;
1211
use bevy_asset::{Asset, Handle, RenderAssetUsages};
@@ -379,7 +378,7 @@ impl Mesh {
379378
pub fn get_vertex_size(&self) -> u64 {
380379
self.attributes
381380
.values()
382-
.map(|data| data.attribute.format.get_size())
381+
.map(|data| data.attribute.format.size())
383382
.sum()
384383
}
385384

@@ -414,7 +413,7 @@ impl Mesh {
414413
format: data.attribute.format,
415414
shader_location: index as u32,
416415
});
417-
accumulated_offset += data.attribute.format.get_size();
416+
accumulated_offset += data.attribute.format.size();
418417
}
419418

420419
let layout = MeshVertexBufferLayout {
@@ -482,7 +481,7 @@ impl Mesh {
482481
// bundle into interleaved buffers
483482
let mut attribute_offset = 0;
484483
for attribute_data in self.attributes.values() {
485-
let attribute_size = attribute_data.attribute.format.get_size() as usize;
484+
let attribute_size = attribute_data.attribute.format.size() as usize;
486485
let attributes_bytes = attribute_data.values.get_bytes();
487486
for (vertex_index, attribute_bytes) in attributes_bytes
488487
.chunks_exact(attribute_size)

crates/bevy_mesh/src/vertex.rs

-45
Original file line numberDiff line numberDiff line change
@@ -165,51 +165,6 @@ pub fn face_normal(a: [f32; 3], b: [f32; 3], c: [f32; 3]) -> [f32; 3] {
165165
(b - a).cross(c - a).normalize().into()
166166
}
167167

168-
pub trait VertexFormatSize {
169-
fn get_size(self) -> u64;
170-
}
171-
172-
impl VertexFormatSize for VertexFormat {
173-
fn get_size(self) -> u64 {
174-
use core::mem::size_of;
175-
let size = match self {
176-
VertexFormat::Uint8x2 | VertexFormat::Unorm8x2 => size_of::<u8>() * 2,
177-
VertexFormat::Uint8x4 | VertexFormat::Unorm8x4 => size_of::<u8>() * 4,
178-
VertexFormat::Sint8x2 | VertexFormat::Snorm8x2 => size_of::<i8>() * 2,
179-
VertexFormat::Sint8x4 | VertexFormat::Snorm8x4 => size_of::<i8>() * 4,
180-
VertexFormat::Unorm10_10_10_2 => 10 + 10 + 10 + 2,
181-
VertexFormat::Uint16x2 | VertexFormat::Unorm16x2 => size_of::<u16>() * 2,
182-
VertexFormat::Uint16x4 | VertexFormat::Unorm16x4 => size_of::<u16>() * 4,
183-
VertexFormat::Sint16x2 | VertexFormat::Snorm16x2 => size_of::<i16>() * 2,
184-
VertexFormat::Sint16x4 | VertexFormat::Snorm16x4 => size_of::<i16>() * 4,
185-
// NOTE: As of the time of writing this code, `f16` is not a stabilized primitive, so we
186-
// can't use `size_of::<f16>()` here.
187-
VertexFormat::Float16x2 => 2 * 2,
188-
VertexFormat::Float16x4 => 2 * 4,
189-
VertexFormat::Float32 => size_of::<f32>(),
190-
VertexFormat::Float32x2 => size_of::<f32>() * 2,
191-
VertexFormat::Float32x3 => size_of::<f32>() * 3,
192-
VertexFormat::Float32x4 => size_of::<f32>() * 4,
193-
VertexFormat::Uint32 => size_of::<u32>(),
194-
VertexFormat::Uint32x2 => size_of::<u32>() * 2,
195-
VertexFormat::Uint32x3 => size_of::<u32>() * 3,
196-
VertexFormat::Uint32x4 => size_of::<u32>() * 4,
197-
VertexFormat::Sint32 => size_of::<i32>(),
198-
VertexFormat::Sint32x2 => size_of::<i32>() * 2,
199-
VertexFormat::Sint32x3 => size_of::<i32>() * 3,
200-
VertexFormat::Sint32x4 => size_of::<i32>() * 4,
201-
VertexFormat::Float64 => size_of::<f64>(),
202-
VertexFormat::Float64x2 => size_of::<f64>() * 2,
203-
VertexFormat::Float64x3 => size_of::<f64>() * 3,
204-
VertexFormat::Float64x4 => size_of::<f64>() * 4,
205-
};
206-
207-
// We can safely cast `size` (a `usize`) into a `u64`, as we don't even reach the limits of
208-
// of a `u8`.
209-
size.try_into().unwrap()
210-
}
211-
}
212-
213168
/// Contains an array where each entry describes a property of a single vertex.
214169
/// Matches the [`VertexFormats`](VertexFormat).
215170
#[derive(Clone, Debug, EnumVariantMeta)]

crates/bevy_pbr/src/meshlet/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ use self::{
5656
},
5757
visibility_buffer_raster_node::MeshletVisibilityBufferRasterPassNode,
5858
};
59-
use crate::graph::NodePbr;
60-
use crate::PreviousGlobalTransform;
59+
use crate::{graph::NodePbr, PreviousGlobalTransform};
6160
use bevy_app::{App, Plugin};
6261
use bevy_asset::{load_internal_asset, weak_handle, AssetApp, AssetId, Handle};
6362
use bevy_core_pipeline::{

crates/bevy_pbr/src/meshlet/visibility_buffer_raster_node.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl Node for MeshletVisibilityBufferRasterPassNode {
150150
meshlet_view_resources.raster_cluster_rightmost_slot,
151151
);
152152
meshlet_view_resources.depth_pyramid.downsample_depth(
153-
"meshlet early downsample depth",
153+
"downsample_depth",
154154
render_context,
155155
meshlet_view_resources.view_size,
156156
&meshlet_view_bind_groups.downsample_depth,
@@ -202,7 +202,7 @@ impl Node for MeshletVisibilityBufferRasterPassNode {
202202
camera,
203203
);
204204
meshlet_view_resources.depth_pyramid.downsample_depth(
205-
"meshlet late downsample depth",
205+
"downsample_depth",
206206
render_context,
207207
meshlet_view_resources.view_size,
208208
&meshlet_view_bind_groups.downsample_depth,
@@ -270,7 +270,7 @@ impl Node for MeshletVisibilityBufferRasterPassNode {
270270
meshlet_view_resources.raster_cluster_rightmost_slot,
271271
);
272272
meshlet_view_resources.depth_pyramid.downsample_depth(
273-
"meshlet early shadow downsample depth",
273+
"downsample_depth",
274274
render_context,
275275
meshlet_view_resources.view_size,
276276
&meshlet_view_bind_groups.downsample_depth,
@@ -315,7 +315,7 @@ impl Node for MeshletVisibilityBufferRasterPassNode {
315315
camera,
316316
);
317317
meshlet_view_resources.depth_pyramid.downsample_depth(
318-
"meshlet late shadow downsample depth",
318+
"downsample_depth",
319319
render_context,
320320
meshlet_view_resources.view_size,
321321
&meshlet_view_bind_groups.downsample_depth,

crates/bevy_pbr/src/render/build_indirect_params.wgsl

+3-5
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ fn main(@builtin(global_invocation_id) global_invocation_id: vec3<u32>) {
6363
// If we aren't using `multi_draw_indirect_count`, we have a 1:1 fixed
6464
// assignment of batches to slots in the indirect parameters buffer, so we
6565
// can just use the instance index as the index of our indirect parameters.
66-
let early_instance_count =
67-
atomicLoad(&indirect_parameters_metadata[instance_index].early_instance_count);
68-
let late_instance_count =
69-
atomicLoad(&indirect_parameters_metadata[instance_index].late_instance_count);
66+
let early_instance_count = indirect_parameters_metadata[instance_index].early_instance_count;
67+
let late_instance_count = indirect_parameters_metadata[instance_index].late_instance_count;
7068

7169
// If in the early phase, we draw only the early meshes. If in the late
7270
// phase, we draw only the late meshes. If in the main phase, draw all the
@@ -135,4 +133,4 @@ fn main(@builtin(global_invocation_id) global_invocation_id: vec3<u32>) {
135133
indirect_parameters[indirect_parameters_index].vertex_count =
136134
current_input[mesh_index].index_count;
137135
#endif // INDEXED
138-
}
136+
}

crates/bevy_pbr/src/render/gpu_preprocess.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ impl SpecializedComputePipeline for PreprocessPipeline {
11511151
type Key = PreprocessPipelineKey;
11521152

11531153
fn specialize(&self, key: Self::Key) -> ComputePipelineDescriptor {
1154-
let mut shader_defs = vec![];
1154+
let mut shader_defs = vec!["WRITE_INDIRECT_PARAMETERS_METADATA".into()];
11551155
if key.contains(PreprocessPipelineKey::FRUSTUM_CULLING) {
11561156
shader_defs.push("INDIRECT".into());
11571157
shader_defs.push("FRUSTUM_CULLING".into());

crates/bevy_pbr/src/render/light.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ pub fn prepare_lights(
10771077
all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu"))
10781078
))]
10791079
dimension: Some(TextureViewDimension::Cube),
1080+
usage: None,
10801081
aspect: TextureAspect::DepthOnly,
10811082
base_mip_level: 0,
10821083
mip_level_count: None,
@@ -1120,6 +1121,7 @@ pub fn prepare_lights(
11201121
dimension: Some(TextureViewDimension::D2Array),
11211122
#[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu")))]
11221123
dimension: Some(TextureViewDimension::D2),
1124+
usage: None,
11231125
aspect: TextureAspect::DepthOnly,
11241126
base_mip_level: 0,
11251127
mip_level_count: None,
@@ -1242,6 +1244,7 @@ pub fn prepare_lights(
12421244
label: Some("point_light_shadow_map_texture_view"),
12431245
format: None,
12441246
dimension: Some(TextureViewDimension::D2),
1247+
usage: None,
12451248
aspect: TextureAspect::All,
12461249
base_mip_level: 0,
12471250
mip_level_count: None,
@@ -1343,6 +1346,7 @@ pub fn prepare_lights(
13431346
label: Some("spot_light_shadow_map_texture_view"),
13441347
format: None,
13451348
dimension: Some(TextureViewDimension::D2),
1349+
usage: None,
13461350
aspect: TextureAspect::All,
13471351
base_mip_level: 0,
13481352
mip_level_count: None,
@@ -1477,6 +1481,7 @@ pub fn prepare_lights(
14771481
label: Some("directional_light_shadow_map_array_texture_view"),
14781482
format: None,
14791483
dimension: Some(TextureViewDimension::D2),
1484+
usage: None,
14801485
aspect: TextureAspect::All,
14811486
base_mip_level: 0,
14821487
mip_level_count: None,

crates/bevy_pbr/src/render/mesh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ impl FromWorld for MeshPipeline {
17331733
render_queue.write_texture(
17341734
texture.as_image_copy(),
17351735
&image.data,
1736-
ImageDataLayout {
1736+
TexelCopyBufferLayout {
17371737
offset: 0,
17381738
bytes_per_row: Some(image.width() * format_size as u32),
17391739
rows_per_image: None,

crates/bevy_pbr/src/render/shadow_sampling.wgsl

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ fn search_for_blockers_in_shadow_map_hardware(
4747
view_bindings::directional_shadow_textures,
4848
view_bindings::directional_shadow_textures_linear_sampler,
4949
light_local,
50-
0.0,
50+
0u,
5151
);
5252
#else // NO_ARRAY_TEXTURES_SUPPORT
5353
let sampled_depth = textureSampleLevel(
5454
view_bindings::directional_shadow_textures,
5555
view_bindings::directional_shadow_textures_linear_sampler,
5656
light_local,
5757
array_index,
58-
0.0,
58+
0u,
5959
);
6060
#endif // NO_ARRAY_TEXTURES_SUPPORT
6161
return select(vec2(0.0), vec2(sampled_depth, 1.0), sampled_depth >= depth);

crates/bevy_pbr/src/ssr/raymarch.wgsl

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ fn depth_raymarch_distance_fn_evaluate(
242242
// * The shrink-wrap surface is no longer continuous, so it's possible for rays to miss it.
243243

244244
let linear_depth =
245-
1.0 / textureSampleLevel(depth_prepass_texture, depth_linear_sampler, interp_uv, 0.0);
245+
1.0 / textureSampleLevel(depth_prepass_texture, depth_linear_sampler, interp_uv, 0u);
246246
let unfiltered_depth =
247-
1.0 / textureSampleLevel(depth_prepass_texture, depth_nearest_sampler, interp_uv, 0.0);
247+
1.0 / textureSampleLevel(depth_prepass_texture, depth_nearest_sampler, interp_uv, 0u);
248248

249249
var max_depth: f32;
250250
var min_depth: f32;

crates/bevy_reflect/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ uuid = { version = "1.13.1", default-features = false, optional = true, features
116116
"serde",
117117
] }
118118
variadics_please = "1.1"
119-
wgpu-types = { version = "23", features = ["serde"], optional = true }
119+
wgpu-types = { version = "24", features = ["serde"], optional = true }
120120

121121
[target.'cfg(target_arch = "wasm32")'.dependencies]
122122
uuid = { version = "1.13.1", default-features = false, features = ["js"] }

0 commit comments

Comments
 (0)