Skip to content
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

fix(deps): update rust crate wgpu to v24 #155

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Jan 16, 2025

This PR contains the following updates:

Package Type Update Change
wgpu (source) dependencies major 0.20 -> 24.0

Release Notes

gfx-rs/wgpu (wgpu)

v24.0.0

Compare Source

Major changes
Refactored Dispatch Between wgpu-core and webgpu

The crate wgpu has two different "backends", one which targets webgpu in the browser, one which targets wgpu_core on native platforms and webgl. This was previously very difficult to traverse and add new features to. The entire system was refactored to make it simpler. Additionally the new system has zero overhead if there is only one "backend" in use. You can see the new system in action by using go-to-definition on any wgpu functions in your IDE.

By @​cwfitzgerald in #​6619.

Render and Compute Passes Now Properly Enforce Their Lifetime

A regression introduced in 23.0.0 caused lifetimes of render and compute passes to be incorrectly enforced. While this is not
a soundness issue, the intent is to move an error from runtime to compile time. This issue has been fixed and restored to the 22.0.0 behavior.

Bindless (binding_array) Grew More Capabilities
  • DX12 now supports PARTIALLY_BOUND_BINDING_ARRAY on Resource Binding Tier 3 Hardware. This is most D3D12 hardware D3D12 Feature Table for more information on what hardware supports this feature. By @​cwfitzgerald in #​6734.
Device::create_shader_module_unchecked Renamed and Now Has Configuration Options

create_shader_module_unchecked became create_shader_module_trusted.

This allows you to customize which exact checks are omitted so that you can get the correct balance of performance and safety for your use case. Calling the function is still unsafe, but now can be used to skip certain checks only on certain builds.

This also allows users to disable the workarounds in the msl-out backend to prevent the compiler from optimizing infinite loops. This can have a big impact on performance, but is not recommended for untrusted shaders.

let desc: ShaderModuleDescriptor = include_wgsl!(...)
- let module = unsafe { device.create_shader_module_unchecked(desc) };
+ let module = unsafe { device.create_shader_module_trusted(desc, wgpu::ShaderRuntimeChecks::unchecked()) };

By @​cwfitzgerald and @​rudderbucky in #​6662.

wgpu::Instance::new now takes InstanceDescriptor by reference

Previously wgpu::Instance::new took InstanceDescriptor by value (which is overall fairly uncommon in wgpu).
Furthermore, InstanceDescriptor is now cloneable.

- let instance = wgpu::Instance::new(instance_desc);
+ let instance = wgpu::Instance::new(&instance_desc);

By @​wumpf in #​6849.

Environment Variable Handling Overhaul

Previously how various bits of code handled reading settings from environment variables was inconsistent and unideomatic.
We have unified it to (Type::from_env() or Type::from_env_or_default()) and Type::with_env for all types.

- wgpu::util::backend_bits_from_env()
+ wgpu::Backends::from_env()

- wgpu::util::power_preference_from_env()
+ wgpu::PowerPreference::from_env()

- wgpu::util::dx12_shader_compiler_from_env()
+ wgpu::Dx12Compiler::from_env()

- wgpu::util::gles_minor_version_from_env()
+ wgpu::Gles3MinorVersion::from_env()

- wgpu::util::instance_descriptor_from_env()
+ wgpu::InstanceDescriptor::from_env_or_default()

- wgpu::util::parse_backends_from_comma_list(&str)
+ wgpu::Backends::from_comma_list(&str)

By @​cwfitzgerald in #​6895

Backend-specific instance options are now in separate structs

In order to better facilitate growing more interesting backend options, we have put them into individual structs. This allows users to more easily understand what options can be defaulted and which they care about. All of these new structs implement from_env() and delegate to their respective from_env() methods.

- let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
-     backends: wgpu::Backends::all(),
-     flags: wgpu::InstanceFlags::default(),
-     dx12_shader_compiler: wgpu::Dx12Compiler::Dxc,
-     gles_minor_version: wgpu::Gles3MinorVersion::Automatic,
- });
+ let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
+     backends: wgpu::Backends::all(),
+     flags: wgpu::InstanceFlags::default(),
+     backend_options: wgpu::BackendOptions {
+         dx12: wgpu::Dx12BackendOptions {
+             shader_compiler: wgpu::Dx12ShaderCompiler::Dxc,
+         },
+         gl: wgpu::GlBackendOptions {
+             gles_minor_version: wgpu::Gles3MinorVersion::Automatic,
+         },
+     },
+ });

If you do not need any of these options, or only need one backend's info use the default() impl to fill out the remaining feelds.

By @​cwfitzgerald in #​6895

The diagnostic(…); directive is now supported in WGSL

Naga now parses diagnostic(…); directives according to the WGSL spec. This allows users to control certain lints, similar to Rust's allow, warn, and deny attributes. For example, in standard WGSL (but, notably, not Naga yet—see #​4369) this snippet would emit a uniformity error:

@​group(0) @​binding(0) var s : sampler;
@&#8203;group(0) @&#8203;binding(2) var tex : texture_2d<f32>;
@&#8203;group(1) @&#8203;binding(0) var<storage, read> ro_buffer : array<f32, 4>;

@&#8203;fragment
fn main(@&#8203;builtin(position) p : vec4f) -> @&#8203;location(0) vec4f {
  if ro_buffer[0] == 0 {
    // Emits a derivative uniformity error during validation.
    return textureSample(tex, s, vec2(0.,0.));
  }

  return vec4f(0.);
}

…but we can now silence it with the off severity level, like so:

// Disable the diagnosic with this…
diagnostic(off, derivative_uniformity);

@&#8203;group(0) @&#8203;binding(0) var s : sampler;
@&#8203;group(0) @&#8203;binding(2) var tex : texture_2d<f32>;
@&#8203;group(1) @&#8203;binding(0) var<storage, read> ro_buffer : array<f32, 4>;

@&#8203;fragment
fn main(@&#8203;builtin(position) p : vec4f) -> @&#8203;location(0) vec4f {
  if ro_buffer[0] == 0 {
    // Look ma, no error!
    return textureSample(tex, s, vec2(0.,0.));
  }

  return vec4f(0.);
}

There are some limitations to keep in mind with this new functionality:

  • We support @diagnostic(…) rules as fn attributes, but prioritization for rules in statement positions (i.e., if (…) @&#8203;diagnostic(…) { … } is unclear. If you are blocked by not being able to parse diagnostic(…) rules in statement positions, please let us know in #​5320, so we can determine how to prioritize it!
  • Standard WGSL specifies error, warning, info, and off severity levels. These are all technically usable now! A caveat, though: warning- and info-level are only emitted to stderr via the log façade, rather than being reported through a Result::Err in Naga or the CompilationInfo interface in wgpu{,-core}. This will require breaking changes in Naga to fix, and is being tracked by #​6458.
  • Not all lints can be controlled with diagnostic(…) rules. In fact, only the derivative_uniformity triggering rule exists in the WGSL standard. That said, Naga contributors are excited to see how this level of control unlocks a new ecosystem of configurable diagnostics.
  • Finally, diagnostic(…) rules are not yet emitted in WGSL output. This means that wgsl-inwgsl-out is currently a lossy process. We felt that it was important to unblock users who needed diagnostic(…) rules (i.e., #​3135) before we took significant effort to fix this (tracked in #​6496).

By @​ErichDonGubler in #​6456, #​6148, #​6533, #​6353, #​6537.

New Features
Naga
General
Vulkan
  • Allow using some 32-bit floating-point atomic operations (load, store, add, sub, exchange) in shaders. It requires the extension VK_EXT_shader_atomic_float. By @​AsherJingkongChen in #​6234.
Metal
  • Allow using some 32-bit floating-point atomic operations (load, store, add, sub, exchange) in shaders. It requires Metal 3.0+ with Apple 7, 8, 9 or Mac 2. By @​AsherJingkongChen in #​6234.
  • Add build support for Apple Vision Pro. By @​guusw in #​6611.
  • Add raw_handle method to access raw Metal textures in #​6894.
D3D12
Changes
Naga
  • Show types of LHS and RHS in binary operation type mismatch errors. By @​ErichDonGubler in #​6450.
  • The GLSL parser now uses less expressions for function calls. By @​magcius in #​6604.
  • Add a note to help with a common syntax error case for global diagnostic filter directives. By @​e-hat in #​6718
  • Change arithmetic operations between two i32 variables to wrap on overflow to match WGSL spec. By @​matthew-wong1 in #​6835.
  • Add directives to suggestions in error message for parsing global items. By @​e-hat in #​6723.
  • Automatic conversion for override initializers. By @​sagudev in 6920
General
  • Align Storage Access enums to the webgpu spec. By @​atlv24 in #​6642
  • Make Surface::as_hal take an immutable reference to the surface. By @​jerzywilczek in #​9999
  • Add actual sample type to CreateBindGroupError::InvalidTextureSampleType error message. By @​ErichDonGubler in #​6530.
  • Improve binding error to give a clearer message when there is a mismatch between resource binding as it is in the shader and as it is in the binding layout. By @​eliemichel in #​6553.
  • Surface::configure and Surface::get_current_texture are no longer fatal. By @​alokedesai in #​6253
  • Rename BlasTriangleGeometry::index_buffer_offset to BlasTriangleGeometry::first_index. By @​Vecvec in #​6873
D3D12
  • Avoid using FXC as fallback when the DXC container was passed at instance creation. Paths to dxcompiler.dll & dxil.dll are also now required. By @​teoxoy in #​6643.
Vulkan
  • Add a cache for samplers, deduplicating any samplers, allowing more programs to stay within the global sampler limit. By @​cwfitzgerald in #​6847
HAL
  • Replace usage: Range<T>, for BufferUses, TextureUses, and AccelerationStructureBarrier with a new StateTransition<T>. By @​atlv24 in #​6703
  • Change the DropCallback API to use FnOnce instead of FnMut. By @​jerzywilczek in #​6482
Bug Fixes
General
  • Handle query set creation failure as an internal error that loses the Device, rather than panicking. By @​ErichDonGubler in #​6505.
  • Ensure that Features::TIMESTAMP_QUERY is set when using timestamp writes in render and compute passes. By @​ErichDonGubler in #​6497.
  • Check for device mismatches when beginning render and compute passes. By @​ErichDonGubler in #​6497.
  • Lower QUERY_SET_MAX_QUERIES (and enforced limits) from 8192 to 4096 to match WebGPU spec. By @​ErichDonGubler in #​6525.
  • Allow non-filterable float on texture bindings never used with samplers when using a derived bind group layout. By @​ErichDonGubler in #​6531.
  • Replace potentially unsound usage of PreHashedMap with FastHashMap. By @​jamienicol in #​6541.
  • Add missing validation for timestamp writes in compute and render passes. By @​ErichDonGubler in #​6578, #​6583.
    • Check the status of the TIMESTAMP_QUERY feature before other validation.
    • Check that indices are in-bounds for the query set.
    • Check that begin and end indices are not equal.
    • Check that at least one index is specified.
  • Reject destroyed buffers in query set resolution. By @​ErichDonGubler in #​6579.
  • Fix panic when dropping Device on some environments. By @​Dinnerbone in #​6681.
  • Reduced the overhead of command buffer validation. By @​nical in #​6721.
  • Set index type to NONE in get_acceleration_structure_build_sizes. By @​Vecvec in #​6802.
  • Fix wgpu-info not showing dx12 adapters. By @​wumpf in #​6844.
  • Use transform_buffer_offset when initialising transform_buffer. By @​Vecvec in #​6864.
Naga
Vulkan
D3D12
Examples
Testing
  • Tests the early returns in the acceleration structure build calls with empty calls. By @​Vecvec in #​6651.

v23.0.1

Compare Source

This release includes patches for wgpu, wgpu-core and wgpu-hal. All other crates remain at 23.0.0.
Below changes were cherry-picked from 24.0.0 development line.

Bug fixes
General
Metal
Vulkan
  • Fix surface capabilities being advertised when its query failed. By @​wumpf in #​6510

v23.0.0

Compare Source

Themes of this release

This release's theme is one that is likely to repeat for a few releases: convergence with the WebGPU specification! WGPU's design and base functionality are actually determined by two specifications: one for WebGPU, and one for the WebGPU Shading Language.

This may not sound exciting, but let us convince you otherwise! All major web browsers have committed to offering WebGPU in their environment. Even JS runtimes like Node and Deno have communities that are very interested in providing WebGPU! WebGPU is slowly eating the world, as it were. 😀 It's really important, then, that WebGPU implementations behave in ways that one would expect across all platforms. For example, if Firefox's WebGPU implementation were to break when running scripts and shaders that worked just fine in Chrome, that would mean sad users for both application authors and browser authors.

WGPU also benefits from standard, portable behavior in the same way as web browsers. Because of this behavior, it's generally fairly easy to port over usage of WebGPU in JavaScript to WGPU. It is also what lets WGPU go full circle: WGPU can be an implementation of WebGPU on native targets, but also it can use other implementations of WebGPU as a backend in JavaScript when compiled to WASM. Therefore, the same dynamic applies: if WGPU's own behavior were significantly different, then WGPU and end users would be sad, sad humans as soon as they discover places where their nice apps are breaking, right?

The answer is: yes, we do have sad, sad humans that really want their WGPU code to work everywhere. As Firefox and others use WGPU to implement WebGPU, the above example of Firefox diverging from standard is, unfortunately, today's reality. It mostly behaves the same as a standards-compliant WebGPU, but it still doesn't in many important ways. Of particular note is Naga, its implementation of the WebGPU Shader Language. Shaders are pretty much a black-and-white point of failure in GPU programming; if they don't compile, then you can't use the rest of the API! And yet, it's extremely easy to run into a case like that from #​4400:

fn gimme_a_float() -> f32 {
  return 42; // fails in Naga, but standard WGSL happily converts to `f32`
}

We intend to continue making visible strides in converging with specifications for WebGPU and WGSL, as this release has. This is, unfortunately, one of the major reasons that WGPU has no plans to work hard at keeping a SemVer-stable interface for the foreseeable future; we have an entire platform of GPU programming functionality we have to catch up with, and SemVer stability is unfortunately in tension with that. So, for now, you're going to keep seeing major releases and breaking changes. Where possible, we'll try to make that painless, but compromises to do so don't always make sense with our limited resources.

This is also the last planned major version release of 2024; the next milestone is set for January 1st, 2025, according to our regular 12-week cadence (offset from the originally planned date of 2024-10-09 for this release 😅). We'll see you next year!

Contributor spotlight: @​sagudev

This release, we'd like to spotlight the work of @​sagudev, who has made significant contributions to the WGPU ecosystem this release. Among other things, they contributed a particularly notable feature where runtime-known indices are finally allowed for use with const array values. For example, this WGSL shader previously wasn't allowed:

const arr: array<u32, 4> = array(1, 2, 3, 4);

fn what_number_should_i_use(idx: u32) -> u32 {
  return arr[idx];
}

…but now it works! This is significant because this sort of shader rejection was one of the most impactful issues we are aware of for converging with the WGSL specification. There are more still to go—some of which we expect to even more drastically change how folks author shaders—but we suspect that many more will come in the next few releases, including with @​sagudev's help.

We're excited for more of @​sagudev's contributions via the Servo community. Oh, did we forget to mention that these contributions were motivated by their work on Servo? That's right, a third well-known JavaScript runtime is now using WGPU to implement its WebGPU implementation. We're excited to support Servo to becoming another fully fledged browsing environment this way.

Major Changes

In addition to the above spotlight, we have the following particularly interesting items to call out for this release:

wgpu-core is no longer generic over wgpu-hal backends

Dynamic dispatch between different backends has been moved from the user facing wgpu crate, to a new dynamic dispatch mechanism inside the backend abstraction layer wgpu-hal.

Whenever targeting more than a single backend (default on Windows & Linux) this leads to faster compile times and smaller binaries! This also solves a long standing issue with cargo doc failing to run for wgpu-core.

Benchmarking indicated that compute pass recording is slower as a consequence, whereas on render passes speed improvements have been observed. However, this effort simplifies many of the internals of the wgpu family of crates which we're hoping to build performance improvements upon in the future.

By @​wumpf in #​6069, #​6099, #​6100.

wgpu's resources no longer have .global_id() getters

wgpu-core's internals no longer use nor need IDs and we are moving towards removing IDs completely. This is a step in that direction.

Current users of .global_id() are encouraged to make use of the PartialEq, Eq, Hash, PartialOrd and Ord traits that have now been implemented for wgpu resources.

By @​teoxoy in #​6134.

set_bind_group now takes an Option for the bind group argument.

https://gpuweb.github.io/gpuweb/#programmable-passes-bind-groups specifies that bindGroup is nullable. This change is the start of implementing this part of the spec. Callers that specify a Some() value should have unchanged behavior. Handling of None values still needs to be implemented by backends.

For convenience, the set_bind_group on compute/render passes & encoders takes impl Into<Option<&BindGroup>>, so most code should still work the same.

By @​bradwerth in #​6216.

entry_points are now Optional

One of the changes in the WebGPU spec. (from about this time last year 😅) was to allow optional entry points in GPUProgrammableStage. In wgpu, this corresponds to a subset of fields in FragmentState, VertexState, and ComputeState as the entry_point member:

let render_pipeline = device.createRenderPipeline(wgpu::RenderPipelineDescriptor {
    module,
    entry_point: Some("cs_main"), // This is now `Option`al.
    // …
});

let compute_pipeline = device.createComputePipeline(wgpu::ComputePipelineDescriptor {
    module,
    entry_point: None, // This is now `Option`al.
    // …
});

When set to None, it's assumed that the shader only has a single entry point associated with the pipeline stage (i.e., @compute, @fragment, or @vertex). If there is not one and only one candidate entry point, then a validation error is returned. To continue the example, we might have written the above API usage with the following shader module:

// We can't use `entry_point: None` for compute pipelines with this module,
// because there are two `@compute` entry points.

@&#8203;compute
fn cs_main() { /**/ }

@&#8203;compute
fn other_cs_main() { /**/ }

// The following entry points _can_ be inferred from `entry_point: None` in a
// render pipeline, because they're the only `@vertex` and `@fragment` entry
// points:

@&#8203;vertex
fn vs_main() { /**/ }

@&#8203;fragment
fn fs_main() { /**/ }
WGPU's DX12 backend is now based on the windows crate ecosystem, instead of the d3d12 crate

WGPU has retired the d3d12 crate (based on winapi), and now uses the windows crate for interfacing with Windows. For many, this may not be a change that affects day-to-day work. However, for users who need to vet their dependencies, or who may vendor in dependencies, this may be a nontrivial migration.

By @​MarijnS95 in #​6006.

New Features
Wgpu
Naga
General
  • Add VideoFrame to ExternalImageSource enum. By @​jprochazk in #​6170.
  • Add wgpu::util::new_instance_with_webgpu_detection & wgpu::util::is_browser_webgpu_supported to make it easier to support WebGPU & WebGL in the same binary. By @​wumpf in #​6371.
Vulkan
Metal
  • Implement atomicCompareExchangeWeak. By @​AsherJingkongChen in #​6265.
  • Unless an explicit CAMetalLayer is provided, surfaces now render to a sublayer. This improves resizing behavior, fixing glitches during on window resize. By @​madsmtm in #​6107.
Bug Fixes
Naga
General
  • If GL context creation fails retry with GLES. By @​Rapdorian in #​5996.
  • Bump MSRV for d3d12/naga/wgpu-core/wgpu-hal/wgpu-types' to 1.76. By @​wumpf in #​6003.
  • Print requested and supported usages on UnsupportedUsage error. By @​VladasZ in #​6007.
  • Deduplicate bind group layouts that are created from pipelines with "auto" layouts. By @​teoxoy #​6049.
  • Document wgpu_hal bounds-checking promises, and adapt wgpu_core's lazy initialization logic to the slightly weaker-than-expected guarantees. By @​jimblandy in #​6201.
  • Raise validation error instead of panicking in {Render,Compute}Pipeline::get_bind_group_layout on native / WebGL. By @​bgr360 in #​6280.
  • BREAKING: Remove the last exposed C symbols in project, located in wgpu_core::render::bundle::bundle_ffi, to allow multiple versions of WGPU to compile together. By @​ErichDonGubler in #​6272.
  • Call flush_mapped_ranges when unmapping write-mapped buffers. By @​teoxoy in #​6089.
  • When mapping buffers for reading, mark buffers as initialized only when they have MAP_WRITE usage. By @​teoxoy in #​6178.
  • Add a separate pipeline constants error. By @​teoxoy in #​6094.
  • Ensure safety of indirect dispatch by injecting a compute shader that validates the content of the indirect buffer. By @​teoxoy in #​5714.
  • Add conversions between TextureFormat and StorageFormat. By @​caelunshun in #​6185
GLES / OpenGL
  • Fix GL debug message callbacks not being properly cleaned up (causing UB). By @​Imberflur in #​6114.
  • Fix calling slice::from_raw_parts with unaligned pointers in push constant handling. By @​Imberflur in #​6341.
  • Optimise fence checking when Queue::submit is called many times per frame. By @​dinnerbone in #​6427.
WebGPU
  • Fix JS TypeError exception in Instance::request_adapter when browser doesn't support WebGPU but wgpu not compiled with webgl support. By @​bgr360 in #​6197.
Vulkan
  • Avoid undefined behaviour with adversarial debug label. By @​DJMcNab in #​6257.
  • Add .index_type(vk::IndexType::NONE_KHR) when creating AccelerationStructureGeometryTrianglesDataKHR in the raytraced triangle example to prevent a validation error. By @​Vecvec in #​6282.
Changes
  • wgpu_hal::gles::Adapter::new_external now requires the context to be current when dropping the adapter and related objects. By @​Imberflur in #​6114.
  • Reduce the amount of debug and trace logs emitted by wgpu-core and wgpu-hal. By @​nical in #​6065.
  • Rename Rg11b10Float to Rg11b10Ufloat. By @​sagudev in #​6108.
  • Invalidate the device when we encounter driver-induced device loss or on unexpected errors. By @​teoxoy in #​6229.
  • Make Vulkan error handling more robust. By @​teoxoy in #​6119.
  • Add bounds checking to Buffer slice method. By @​beholdnec in #​6432.
  • Replace impl From<StorageFormat> for ScalarKind with impl From<StorageFormat> for Scalar so that byte width is included. By @​atlv24 in #​6451.
Internal
HAL
  • Change the inconsistent DropGuard based API on Vulkan and GLES to a consistent, callback-based one. By @​jerzywilczek in #​6164.
Documentation
  • Removed some OpenGL and Vulkan references from wgpu-types documentation. Fixed Storage texel types in examples. By @​Nelarius in #​6271.
  • Used wgpu::include_wgsl!(…) more in examples and tests. By @​ErichDonGubler in #​6326.
Dependency Updates
GLES
DX12
HAL

v22.1.0

Compare Source

This release includes wgpu, wgpu-core and naga. All other crates remain at 22.0.0.

Added
Naga
Bug Fixes
General

v22.0.0

Compare Source

Overview
Our first major version release!

For the first time ever, WGPU is being released with a major version (i.e., 22.* instead of 0.22.*)! Maintainership has decided to fully adhere to Semantic Versioning's recommendations for versioning production software. According to SemVer 2.0.0's Q&A about when to use 1.0.0 versions (and beyond):

How do I know when to release 1.0.0?

If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backward compatibility, you should probably already be 1.0.0.

It is a well-known fact that WGPU has been used for applications and platforms already in production for years, at this point. We are often concerned with tracking breaking changes, and affecting these consumers' ability to ship. By releasing our first major version, we publicly acknowledge that this is the case. We encourage other projects in the Rust ecosystem to follow suit.

Note that while we start to use the major version number, WGPU is not "going stable", as many Rust projects do. We anticipate many breaking changes before we fully comply with the WebGPU spec., which we expect to take a small number of years.

Overview

A major (pun intended) theme of this release is incremental improvement. Among the typically large set of bug fixes, new features, and other adjustments to WGPU by the many contributors listed below, @​wumpf and @​teoxoy have merged a series of many simplifications to WGPU's internals and, in one case, to the render and compute pass recording APIs. Many of these change WGPU to use atomically reference-counted resource tracking (i.e., Arc<…>), rather than using IDs to manage the lifetimes of platform-specific graphics resources in a registry of separate reference counts. This has led us to diagnose and fix many long-standing bugs, and net some neat performance improvements on the order of 40% or more of some workloads.

While the above is exciting, we acknowledge already finding and fixing some (easy-to-fix) regressions from the above work. If you migrate to WGPU 22 and encounter such bugs, please engage us in the issue tracker right away!

Major Changes
Lifetime bounds on wgpu::RenderPass & wgpu::ComputePass

wgpu::RenderPass & wgpu::ComputePass recording methods (e.g. wgpu::RenderPass:set_render_pipeline) no longer impose a lifetime constraint to objects passed to a pass (like pipelines/buffers/bindgroups/query-sets etc.).

This means the following pattern works now as expected:

let mut pipelines: Vec<wgpu::RenderPipeline> = ...;
// ...
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor::default());
cpass.set_pipeline(&pipelines[123]);
// Change pipeline container - this requires mutable access to `pipelines` while one of the pipelines is in use.
pipelines.push(/* ... */);
// Continue pass recording.
cpass.set_bindgroup(...);

Previously, a set pipeline (or other resource) had to outlive pass recording which often affected wider systems,
meaning that users needed to prove to the borrow checker that Vec<wgpu::RenderPipeline> (or similar constructs)
aren't accessed mutably for the duration of pass recording.

Furthermore, you can now opt out of wgpu::RenderPass/wgpu::ComputePass's lifetime dependency on its parent wgpu::CommandEncoder using wgpu::RenderPass::forget_lifetime/wgpu::ComputePass::forget_lifetime:

fn independent_cpass<'enc>(encoder: &'enc mut wgpu::CommandEncoder) -> wgpu::ComputePass<'static> {
    let cpass: wgpu::ComputePass<'enc> = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor::default());
    cpass.forget_lifetime()
}

⚠️ As long as a wgpu::RenderPass/wgpu::ComputePass is pending for a given wgpu::CommandEncoder, creation of a compute or render pass is an error and invalidates the wgpu::CommandEncoder.
forget_lifetime can be very useful for library authors, but opens up an easy way for incorrect use, so use with care.
This method doesn't add any additional overhead and has no side effects on pass recording.

By @​wumpf in #​5569, #​5575, #​5620, #​5768 (together with @​kpreid), #​5671, #​5794, #​5884.

Querying shader compilation errors

Wgpu now supports querying shader compilation info.

This allows you to get more structured information about compilation errors, warnings and info:

...
let lighting_shader = ctx.device.create_shader_module(include_wgsl!("lighting.wgsl"));
let compilation_info = lighting_shader.get_compilation_info().await;
for message in compilation_info
    .messages
    .iter()
    .filter(|m| m.message_type == wgpu::CompilationMessageType::Error)
{
    let line = message.location.map(|l| l.line_number).unwrap_or(1);
    println!("Compile error at line {line}");
}

By @​stefnotch in #​5410

64 bit integer atomic support in shaders.

Add support for 64 bit integer atomic operations in shaders.


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Enabled.

Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot enabled auto-merge (squash) January 16, 2025 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants