Skip to content

Commit 7b81ae7

Browse files
callymElabajaba
andauthored
Update WGPU to version 22 (#14401)
Upgrading to WGPU 22. Needs `naga_oil` to upgrade first, I've got a fork that compiles but fails tests, so until that's fixed and the crate is officially updated/released this will be blocked. --------- Co-authored-by: Elabajaba <[email protected]>
1 parent 032fd48 commit 7b81ae7

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

crates/bevy_color/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [
1717
bytemuck = { version = "1", features = ["derive"] }
1818
serde = { version = "1.0", features = ["derive"], optional = true }
1919
thiserror = "1.0"
20-
wgpu-types = { version = "0.20", default-features = false, optional = true }
20+
wgpu-types = { version = "22", default-features = false, optional = true }
2121
encase = { version = "0.9", default-features = false }
2222

2323
[features]

crates/bevy_render/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ zstd = ["ruzstd"]
2929

3030
trace = ["profiling"]
3131
tracing-tracy = []
32-
wgpu_trace = ["wgpu/trace"]
32+
wgpu_trace = []
3333
ci_limits = []
3434
webgl = ["wgpu/webgl"]
3535
webgpu = ["wgpu/webgpu"]
@@ -71,15 +71,14 @@ codespan-reporting = "0.11.0"
7171
# It is enabled for now to avoid having to do a significant overhaul of the renderer just for wasm.
7272
# When the 'atomics' feature is enabled `fragile-send-sync-non-atomic` does nothing
7373
# and Bevy instead wraps `wgpu` types to verify they are not used off their origin thread.
74-
wgpu = { version = "0.20", default-features = false, features = [
74+
wgpu = { version = "22", default-features = false, features = [
7575
"wgsl",
7676
"dx12",
7777
"metal",
78-
"naga",
7978
"naga-ir",
8079
"fragile-send-sync-non-atomic-wasm",
8180
] }
82-
naga = { version = "0.20", features = ["wgsl-in"] }
81+
naga = { version = "22", features = ["wgsl-in"] }
8382
serde = { version = "1", features = ["derive"] }
8483
bitflags = { version = "2.3", features = ["serde"] }
8584
bytemuck = { version = "1.5", features = ["derive", "must_cast"] }
@@ -106,12 +105,12 @@ offset-allocator = "0.2"
106105

107106
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
108107
# Omit the `glsl` feature in non-WebAssembly by default.
109-
naga_oil = { version = "0.14", default-features = false, features = [
108+
naga_oil = { version = "0.15", default-features = false, features = [
110109
"test_shader",
111110
] }
112111

113112
[target.'cfg(target_arch = "wasm32")'.dependencies]
114-
naga_oil = "0.14"
113+
naga_oil = "0.15"
115114
js-sys = "0.3"
116115
web-sys = { version = "0.3.67", features = [
117116
'Blob',

crates/bevy_render/src/render_resource/pipeline_cache.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl ShaderDefVal {
173173

174174
impl ShaderCache {
175175
fn new(render_device: &RenderDevice, render_adapter: &RenderAdapter) -> Self {
176-
let (capabilities, subgroup_stages) = get_capabilities(
176+
let capabilities = get_capabilities(
177177
render_device.features(),
178178
render_adapter.get_downlevel_capabilities().flags,
179179
);
@@ -183,7 +183,7 @@ impl ShaderCache {
183183
#[cfg(not(debug_assertions))]
184184
let composer = naga_oil::compose::Composer::non_validating();
185185

186-
let composer = composer.with_capabilities(capabilities, subgroup_stages);
186+
let composer = composer.with_capabilities(capabilities);
187187

188188
Self {
189189
composer,
@@ -742,6 +742,7 @@ impl PipelineCache {
742742
let compilation_options = PipelineCompilationOptions {
743743
constants: &std::collections::HashMap::new(),
744744
zero_initialize_workgroup_memory: false,
745+
vertex_pulling_transform: Default::default(),
745746
};
746747

747748
let descriptor = RawRenderPipelineDescriptor {
@@ -767,6 +768,7 @@ impl PipelineCache {
767768
// TODO: Should this be the same as the vertex compilation options?
768769
compilation_options,
769770
}),
771+
cache: None,
770772
};
771773

772774
Ok(Pipeline::RenderPipeline(
@@ -822,7 +824,9 @@ impl PipelineCache {
822824
compilation_options: PipelineCompilationOptions {
823825
constants: &std::collections::HashMap::new(),
824826
zero_initialize_workgroup_memory: false,
827+
vertex_pulling_transform: Default::default(),
825828
},
829+
cache: None,
826830
};
827831

828832
Ok(Pipeline::ComputePipeline(
@@ -992,14 +996,9 @@ pub enum PipelineCacheError {
992996

993997
// TODO: This needs to be kept up to date with the capabilities in the `create_validator` function in wgpu-core
994998
// https://github.com/gfx-rs/wgpu/blob/trunk/wgpu-core/src/device/mod.rs#L449
995-
// We use a modified version of the `create_validator` function because `naga_oil`'s composer stores the capabilities
996-
// and subgroup shader stages instead of a `Validator`.
997-
// We also can't use that function because `wgpu-core` isn't included in WebGPU builds.
998-
/// Get the device capabilities and subgroup support for use in `naga_oil`.
999-
fn get_capabilities(
1000-
features: Features,
1001-
downlevel: DownlevelFlags,
1002-
) -> (Capabilities, naga::valid::ShaderStages) {
999+
// We can't use the `wgpu-core` function to detect the device's capabilities because `wgpu-core` isn't included in WebGPU builds.
1000+
/// Get the device's capabilities for use in `naga_oil`.
1001+
fn get_capabilities(features: Features, downlevel: DownlevelFlags) -> Capabilities {
10031002
let mut capabilities = Capabilities::empty();
10041003
capabilities.set(
10051004
Capabilities::PUSH_CONSTANT,
@@ -1042,6 +1041,16 @@ fn get_capabilities(
10421041
Capabilities::SHADER_INT64,
10431042
features.contains(Features::SHADER_INT64),
10441043
);
1044+
capabilities.set(
1045+
Capabilities::SHADER_INT64_ATOMIC_MIN_MAX,
1046+
features.intersects(
1047+
Features::SHADER_INT64_ATOMIC_MIN_MAX | Features::SHADER_INT64_ATOMIC_ALL_OPS,
1048+
),
1049+
);
1050+
capabilities.set(
1051+
Capabilities::SHADER_INT64_ATOMIC_ALL_OPS,
1052+
features.contains(Features::SHADER_INT64_ATOMIC_ALL_OPS),
1053+
);
10451054
capabilities.set(
10461055
Capabilities::MULTISAMPLED_SHADING,
10471056
downlevel.contains(DownlevelFlags::MULTISAMPLED_SHADING),
@@ -1062,16 +1071,10 @@ fn get_capabilities(
10621071
Capabilities::SUBGROUP_BARRIER,
10631072
features.intersects(Features::SUBGROUP_BARRIER),
10641073
);
1065-
1066-
let mut subgroup_stages = naga::valid::ShaderStages::empty();
1067-
subgroup_stages.set(
1068-
naga::valid::ShaderStages::COMPUTE | naga::valid::ShaderStages::FRAGMENT,
1069-
features.contains(Features::SUBGROUP),
1070-
);
1071-
subgroup_stages.set(
1072-
naga::valid::ShaderStages::VERTEX,
1074+
capabilities.set(
1075+
Capabilities::SUBGROUP_VERTEX_STAGE,
10731076
features.contains(Features::SUBGROUP_VERTEX),
10741077
);
10751078

1076-
(capabilities, subgroup_stages)
1079+
capabilities
10771080
}

crates/bevy_render/src/renderer/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ pub async fn initialize_renderer(
355355
label: options.device_label.as_ref().map(AsRef::as_ref),
356356
required_features: features,
357357
required_limits: limits,
358+
memory_hints: options.memory_hints.clone(),
358359
},
359360
trace_path,
360361
)
@@ -431,7 +432,7 @@ impl<'w> RenderContext<'w> {
431432
/// configured using the provided `descriptor`.
432433
pub fn begin_tracked_render_pass<'a>(
433434
&'a mut self,
434-
descriptor: RenderPassDescriptor<'a, '_>,
435+
descriptor: RenderPassDescriptor<'_>,
435436
) -> TrackedRenderPass<'a> {
436437
// Cannot use command_encoder() as we need to split the borrow on self
437438
let command_encoder = self.command_encoder.get_or_insert_with(|| {

crates/bevy_render/src/settings.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::borrow::Cow;
55

66
pub use wgpu::{
77
Backends, Dx12Compiler, Features as WgpuFeatures, Gles3MinorVersion, InstanceFlags,
8-
Limits as WgpuLimits, PowerPreference,
8+
Limits as WgpuLimits, MemoryHints, PowerPreference,
99
};
1010

1111
/// Configures the priority used when automatically configuring the features/limits of `wgpu`.
@@ -50,6 +50,8 @@ pub struct WgpuSettings {
5050
pub gles3_minor_version: Gles3MinorVersion,
5151
/// These are for controlling WGPU's debug information to eg. enable validation and shader debug info in release builds.
5252
pub instance_flags: InstanceFlags,
53+
/// This hints to the WGPU device about the preferred memory allocation strategy.
54+
pub memory_hints: MemoryHints,
5355
}
5456

5557
impl Default for WgpuSettings {
@@ -113,6 +115,7 @@ impl Default for WgpuSettings {
113115
dx12_shader_compiler: dx12_compiler,
114116
gles3_minor_version,
115117
instance_flags,
118+
memory_hints: MemoryHints::default(),
116119
}
117120
}
118121
}

0 commit comments

Comments
 (0)