Skip to content

Commit

Permalink
Update wgpu to 24.0.0 (#8743)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf authored Jan 21, 2025
1 parent b926e95 commit 9437f4f
Show file tree
Hide file tree
Showing 21 changed files with 212 additions and 229 deletions.
286 changes: 140 additions & 146 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,23 @@ uuid = "1.1"
vec1 = "1.8"
walkdir = "2.0"
walkers = "0.32"
# NOTE: `rerun_js/web-viewer/build-wasm.mjs` is HIGHLY sensitive to changes in `wasm-bindgen`.
# TODO(#8766): `rerun_js/web-viewer/build-wasm.mjs` is HIGHLY sensitive to changes in `wasm-bindgen`.
# Whenever updating `wasm-bindgen`, update this and the narrower dependency specifications in
# `crates/viewer/re_viewer/Cargo.toml`, and make sure that the build script still works.
# Do not make this an `=` dependency, because that may break Rust users’ builds when a newer
# version is released, even if they are not building the web viewer.
wasm-bindgen = "0.2.95"
wasm-bindgen-cli-support = "=0.2.95"
wasm-bindgen-futures = "0.4.33"
# For details see https://github.com/rerun-io/rerun/issues/8766
wasm-bindgen = "0.2.100"
wasm-bindgen-cli-support = "=0.2.100"
wasm-bindgen-futures = "0.4.50"
wayland-sys = "0.31.5"
web-sys = "0.3"
web-time = "1.1.0"
webbrowser = "1.0"
winit = { version = "0.30.5", default-features = false }
# TODO(andreas): Try to get rid of `fragile-send-sync-non-atomic-wasm`. This requires re_renderer being aware of single-thread restriction on resources.
# See also https://gpuweb.github.io/gpuweb/explainer/#multithreading-transfer (unsolved part of the Spec as of writing!)
wgpu = { version = "23.0", default-features = false, features = [
wgpu = { version = "24.0", default-features = false, features = [
# Backends (see https://docs.rs/wgpu/latest/wgpu/#feature-flags)
"webgl",
"metal",
Expand All @@ -331,7 +332,8 @@ wgpu = { version = "23.0", default-features = false, features = [
# Other:
"fragile-send-sync-non-atomic-wasm",
] }
wgpu-core = "23.0"
# TODO(gfx-rs/wgpu#6962): There's a type export missing in 24.0.0, so we need to get it directly from wgpu-types.
wgpu-types = "24.0"
xshell = "0.2"
zip = { version = "0.6", default-features = false } # We're stuck on 0.6 because https://crates.io/crates/protoc-prebuilt is still using 0.6

Expand Down Expand Up @@ -567,13 +569,13 @@ significant_drop_tightening = "allow" # An update of parking_lot made this trigg
# Prefer patching with `branch` over `rev` and let `Cargo.lock` handle the commit hash.
# That makes it easy to upade with `cargo update -p $CRATE`.

ecolor = { git = "https://github.com/emilk/egui.git", rev = "f0d7c74e838b8e8920a22e7515990fbe057ec218" } # egui master 2025-01-08
eframe = { git = "https://github.com/emilk/egui.git", rev = "f0d7c74e838b8e8920a22e7515990fbe057ec218" } # egui master 2025-01-08
egui = { git = "https://github.com/emilk/egui.git", rev = "f0d7c74e838b8e8920a22e7515990fbe057ec218" } # egui master 2025-01-08
egui_extras = { git = "https://github.com/emilk/egui.git", rev = "f0d7c74e838b8e8920a22e7515990fbe057ec218" } # egui master 2025-01-08
egui_kittest = { git = "https://github.com/emilk/egui.git", rev = "f0d7c74e838b8e8920a22e7515990fbe057ec218" } # egui master 2025-01-08
egui-wgpu = { git = "https://github.com/emilk/egui.git", rev = "f0d7c74e838b8e8920a22e7515990fbe057ec218" } # egui master 2025-01-08
emath = { git = "https://github.com/emilk/egui.git", rev = "f0d7c74e838b8e8920a22e7515990fbe057ec218" } # egui master 2025-01-08
ecolor = { git = "https://github.com/emilk/egui.git", rev = "30e66e457575096bd60e95800e7dd9fd755c0046" } # egui master 2025-01-20
eframe = { git = "https://github.com/emilk/egui.git", rev = "30e66e457575096bd60e95800e7dd9fd755c0046" } # egui master 2025-01-20
egui = { git = "https://github.com/emilk/egui.git", rev = "30e66e457575096bd60e95800e7dd9fd755c0046" } # egui master 2025-01-20
egui_extras = { git = "https://github.com/emilk/egui.git", rev = "30e66e457575096bd60e95800e7dd9fd755c0046" } # egui master 2025-01-20
egui_kittest = { git = "https://github.com/emilk/egui.git", rev = "30e66e457575096bd60e95800e7dd9fd755c0046" } # egui master 2025-01-20
egui-wgpu = { git = "https://github.com/emilk/egui.git", rev = "30e66e457575096bd60e95800e7dd9fd755c0046" } # egui master 2025-01-20
emath = { git = "https://github.com/emilk/egui.git", rev = "30e66e457575096bd60e95800e7dd9fd755c0046" } # egui master 2025-01-20

# Useful while developing:
# ecolor = { path = "../../egui/crates/ecolor" }
Expand Down
5 changes: 1 addition & 4 deletions crates/build/re_dev_tools/src/build_web_viewer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ pub fn build(
match target {
Target::Browser => bindgen_cmd.no_modules(true)?.typescript(false),
Target::Module => bindgen_cmd.no_modules(false)?.typescript(true),
Target::NoModulesBase => bindgen_cmd
.no_modules(true)?
.reference_types(true)
.typescript(true),
Target::NoModulesBase => bindgen_cmd.no_modules(true)?.typescript(true),
};
if let Err(err) = bindgen_cmd.generate(build_dir.as_str()) {
if err
Expand Down
3 changes: 2 additions & 1 deletion crates/viewer/re_renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ thiserror.workspace = true
type-map.workspace = true
web-time.workspace = true
wgpu.workspace = true
wgpu-core.workspace = true # Needed for error handling when wgpu-core implemented backend is used.
# TODO(gfx-rs/wgpu#6962): There's a type export missing in 24.0.0, so we need to get it directly from wgpu-types.
wgpu-types.workspace = true

# optional
gltf = { workspace = true, optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ where
) -> Result<(), CpuWriteGpuReadError> {
self.copy_to_texture2d(
encoder,
wgpu::ImageCopyTexture {
wgpu::TexelCopyTextureInfo {
texture: &destination.texture,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
Expand All @@ -294,7 +294,7 @@ where
pub fn copy_to_texture2d(
self,
encoder: &mut wgpu::CommandEncoder,
destination: wgpu::ImageCopyTexture<'_>,
destination: wgpu::TexelCopyTextureInfo<'_>,
copy_size: wgpu::Extent3d,
) -> Result<(), CpuWriteGpuReadError> {
let buffer_info = Texture2DBufferInfo::new(destination.texture.format(), copy_size);
Expand All @@ -310,9 +310,9 @@ where
}

encoder.copy_buffer_to_texture(
wgpu::ImageCopyBuffer {
wgpu::TexelCopyBufferInfo {
buffer: &self.chunk_buffer,
layout: wgpu::ImageDataLayout {
layout: wgpu::TexelCopyBufferLayout {
offset: self.byte_offset_in_chunk_buffer,
bytes_per_row: Some(buffer_info.bytes_per_row_padded),
rows_per_image: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl<'a, T: Pod + Send + Sync> DataTextureSource<'a, T> {

buffer.copy_to_texture2d(
encoder.get(),
wgpu::ImageCopyTexture {
wgpu::TexelCopyTextureInfo {
texture: &data_texture.texture,
mip_level: 0,
origin: wgpu::Origin3d {
Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/allocator/gpu_readback_belt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl GpuReadbackBuffer {
pub fn read_texture2d(
&mut self,
encoder: &mut wgpu::CommandEncoder,
source: wgpu::ImageCopyTexture<'_>,
source: wgpu::TexelCopyTextureInfo<'_>,
copy_extents: wgpu::Extent3d,
) -> Result<(), GpuReadbackError> {
self.read_multiple_texture2d(encoder, &[(source, copy_extents)])
Expand All @@ -63,7 +63,7 @@ impl GpuReadbackBuffer {
pub fn read_multiple_texture2d(
&mut self,
encoder: &mut wgpu::CommandEncoder,
sources_and_extents: &[(wgpu::ImageCopyTexture<'_>, wgpu::Extent3d)],
sources_and_extents: &[(wgpu::TexelCopyTextureInfo<'_>, wgpu::Extent3d)],
) -> Result<(), GpuReadbackError> {
for (source, copy_extents) in sources_and_extents {
let src_texture = source.texture;
Expand Down Expand Up @@ -91,9 +91,9 @@ impl GpuReadbackBuffer {

encoder.copy_texture_to_buffer(
*source,
wgpu::ImageCopyBuffer {
wgpu::TexelCopyBufferInfo {
buffer: &self.chunk_buffer,
layout: wgpu::ImageDataLayout {
layout: wgpu::TexelCopyBufferLayout {
offset: start_offset,
bytes_per_row: Some(buffer_info.bytes_per_row_padded),
rows_per_image: None,
Expand Down
16 changes: 5 additions & 11 deletions crates/viewer/re_renderer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ pub fn instance_descriptor(force_backend: Option<&str>) -> wgpu::InstanceDescrip

wgpu::InstanceDescriptor {
backends,

flags: wgpu::InstanceFlags::default()
// Allow adapters that aren't compliant with the backend they're implementing.
// A concrete example of this is the latest Vulkan drivers on WSL which (as of writing)
Expand All @@ -357,16 +356,11 @@ pub fn instance_descriptor(force_backend: Option<&str>) -> wgpu::InstanceDescrip
// In the future we might consider enabling this _only_ for WSL as this might otherwise
// cause us to run with arbitrary development versions of drivers.
// (then again, if a user has such a driver they likely *want* us to run with it anyways!)
.union(wgpu::InstanceFlags::ALLOW_UNDERLYING_NONCOMPLIANT_ADAPTER)
// Allow manipulation via environment variables.
.with_env(),

// FXC isn't great (slow & outdated), but DXC is painful to ship as it has to be provided separately.
// (Note though that we generally prefer running with Vulkan)
dx12_shader_compiler: wgpu::Dx12Compiler::Fxc,

gles_minor_version: wgpu::Gles3MinorVersion::Automatic,
.union(wgpu::InstanceFlags::ALLOW_UNDERLYING_NONCOMPLIANT_ADAPTER),
backend_options: wgpu::BackendOptions::default(),
}
// Allow manipulation of all options via environment variables.
.with_env()
}

/// Returns an instance descriptor that is suitable for testing.
Expand Down Expand Up @@ -450,7 +444,7 @@ pub fn supported_backends() -> wgpu::Backends {
// with old hardware or bad/missing drivers. Wgpu automatically prefers Vulkan over GL when possible.
//
// For changing the backend we use standard wgpu env var, i.e. WGPU_BACKEND.
wgpu::util::backend_bits_from_env()
wgpu::Backends::from_env()
.unwrap_or(wgpu::Backends::VULKAN | wgpu::Backends::METAL | wgpu::Backends::GL)
} else {
wgpu::Backends::GL | wgpu::Backends::BROWSER_WEBGPU
Expand Down
8 changes: 4 additions & 4 deletions crates/viewer/re_renderer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub enum RenderContextError {
/// Any resource involving wgpu rendering which can be re-used across different scenes.
/// I.e. render pipelines, resource pools, etc.
pub struct RenderContext {
pub device: Arc<wgpu::Device>,
pub queue: Arc<wgpu::Queue>,
pub device: wgpu::Device,
pub queue: wgpu::Queue,

device_caps: DeviceCaps,
output_format_color: wgpu::TextureFormat,
Expand Down Expand Up @@ -126,8 +126,8 @@ impl RenderContext {

pub fn new(
adapter: &wgpu::Adapter,
device: Arc<wgpu::Device>,
queue: Arc<wgpu::Queue>,
device: wgpu::Device,
queue: wgpu::Queue,
output_format_color: wgpu::TextureFormat,
) -> Result<Self, RenderContextError> {
re_tracing::profile_function!();
Expand Down
15 changes: 4 additions & 11 deletions crates/viewer/re_renderer/src/context_test.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
//! Extensions for the [`RenderContext`] for testing.
use std::sync::Arc;

//!
use crate::{config, RenderContext};

impl RenderContext {
/// Creates a new [`RenderContext`] for testing.
pub fn new_test() -> Self {
let instance = wgpu::Instance::new(config::testing_instance_descriptor());
let instance = wgpu::Instance::new(&config::testing_instance_descriptor());
let adapter = config::select_testing_adapter(&instance);
let device_caps = config::DeviceCaps::from_adapter(&adapter)
.expect("Failed to determine device capabilities");
let (device, queue) =
pollster::block_on(adapter.request_device(&device_caps.device_descriptor(), None))
.expect("Failed to request device.");

Self::new(
&adapter,
Arc::new(device),
Arc::new(queue),
wgpu::TextureFormat::Rgba8Unorm,
)
.expect("Failed to create RenderContext")
Self::new(&adapter, device, queue, wgpu::TextureFormat::Rgba8Unorm)
.expect("Failed to create RenderContext")
}

/// Executes a test frame.
Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/re_renderer/src/draw_phases/picking_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl PickingLayerProcessor {
encoder,
&[
(
wgpu::ImageCopyTexture {
wgpu::TexelCopyTextureInfo {
texture: &self.picking_target.texture,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
Expand All @@ -370,7 +370,7 @@ impl PickingLayerProcessor {
extent,
),
(
wgpu::ImageCopyTexture {
wgpu::TexelCopyTextureInfo {
texture: &readable_depth_texture.texture,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_renderer/src/draw_phases/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl ScreenshotProcessor {
) -> Result<(), GpuReadbackError> {
self.screenshot_readback_buffer.lock().read_texture2d(
encoder,
wgpu::ImageCopyTexture {
wgpu::TexelCopyTextureInfo {
texture: &self.screenshot_texture.texture,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/re_renderer/src/error_handling/error_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ impl ErrorTracker {
description: description.clone(),
};

let should_log = match _source.downcast::<wgpu_core::error::ContextError>() {
let should_log = match _source.downcast::<wgpu::core::error::ContextError>() {
Ok(ctx_err) => {
if ctx_err
.source
.downcast_ref::<wgpu_core::command::CommandEncoderError>()
.downcast_ref::<wgpu::core::command::CommandEncoderError>()
.is_some()
{
// Actual command encoder errors never carry any meaningful
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::hash::Hash as _;

use wgpu::core as wgpu_core;

/// Tries downcasting a given value into the specified possibilities (or all of them
/// if none are specified), then run the given expression on the downcasted value.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use std::sync::Arc;

/// Wgpu device error scope for all filters that auto closes when exiting the scope unless it was already closed.
///
/// The expectation is that the scope is manually closed, but this construct is useful to not accidentally
/// leave the scope open when returning early from a function.
/// Opens scopes for all error types.
pub struct WgpuErrorScope {
open: bool,
device: Arc<wgpu::Device>,
device: wgpu::Device,
}

impl WgpuErrorScope {
pub fn start(device: &Arc<wgpu::Device>) -> Self {
pub fn start(device: &wgpu::Device) -> Self {
device.push_error_scope(wgpu::ErrorFilter::Validation);
device.push_error_scope(wgpu::ErrorFilter::OutOfMemory);
device.push_error_scope(wgpu::ErrorFilter::Internal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ impl TextureManager2D {
},
));
queue.write_texture(
wgpu::ImageCopyTexture {
wgpu::TexelCopyTextureInfo {
texture: &white_texture_unorm.texture,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
},
&[255, 255, 255, 255],
wgpu::ImageDataLayout {
wgpu::TexelCopyBufferLayout {
offset: 0,
bytes_per_row: Some(4),
rows_per_image: None,
Expand Down
5 changes: 3 additions & 2 deletions crates/viewer/re_renderer/src/video/chunk_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,16 @@ fn copy_web_video_frame_to_texture(
depth_or_array_layers: 1,
};
let frame: &web_sys::VideoFrame = frame;
let source = wgpu::ImageCopyExternalImage {
let source = wgpu::CopyExternalImageSourceInfo {
// Careful: `web_sys::VideoFrame` has a custom `clone` method:
// https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame/clone
// We instead just want to clone the js value wrapped in VideoFrame!
source: wgpu::ExternalImageSource::VideoFrame(Clone::clone(frame)),
origin: wgpu::Origin2d { x: 0, y: 0 },
flip_y: false,
};
let dest = wgpu::ImageCopyTextureTagged {
// TODO(wgpu#6962): This type is not exposed through wgpu.
let dest = wgpu_types::CopyExternalImageDestInfo {
texture: &target_texture.texture,
mip_level: 0,
origin: wgpu::Origin3d { x: 0, y: 0, z: 0 },
Expand Down
4 changes: 1 addition & 3 deletions crates/viewer/re_renderer_examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<E: Example + 'static> Application<E> {
// Run without validation layers, they can be annoying on shader reload depending on the backend.
instance_desc.flags.remove(wgpu::InstanceFlags::VALIDATION);

let instance = wgpu::Instance::new(instance_desc);
let instance = wgpu::Instance::new(&instance_desc);
let surface = instance.create_surface(window.clone()).unwrap();
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
Expand All @@ -137,8 +137,6 @@ impl<E: Example + 'static> Application<E> {
)
.await
.context("failed to create device")?;
let device = Arc::new(device);
let queue = Arc::new(queue);

let output_format_color =
preferred_framebuffer_format(&surface.get_capabilities(&adapter).formats);
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_view_spatial/src/picking_ui_pixel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ fn pixel_value_string_from_gpu_texture(
let mut encoder = render_ctx.active_frame.before_view_builder_encoder.lock();
if let Err(err) = readback_buffer.read_texture2d(
encoder.get(),
wgpu::ImageCopyTexture {
wgpu::TexelCopyTextureInfo {
texture: &texture.texture,
mip_level: 0,
origin: readback_rect.wgpu_origin(),
Expand Down
11 changes: 7 additions & 4 deletions crates/viewer/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,13 @@ js-sys.workspace = true
strum.workspace = true
strum_macros.workspace = true
wasm-bindgen-futures.workspace = true
# NOTE: `rerun_js/web-viewer/build-wasm.mjs` is HIGHLY sensitive to changes in `wasm-bindgen`.
# Whenever updating `wasm-bindgen`, update this and the broader dependency specifications in
# the root `/Cargo.toml`, and make sure that the output of `pixi run js-build-base` still works.
wasm-bindgen = "=0.2.95"
# TODO(#8766): `rerun_js/web-viewer/build-wasm.mjs` is HIGHLY sensitive to changes in `wasm-bindgen`.
# Whenever updating `wasm-bindgen`, update this and the narrower dependency specifications in
# `crates/viewer/re_viewer/Cargo.toml`, and make sure that the build script still works.
# Do not make this an `=` dependency, because that may break Rust users’ builds when a newer
# version is released, even if they are not building the web viewer.
# For details see https://github.com/rerun-io/rerun/issues/8766
wasm-bindgen = "=0.2.100"
web-sys = { workspace = true, features = [
"History",
"Location",
Expand Down
Loading

0 comments on commit 9437f4f

Please sign in to comment.