v0.15.0
Major Changes
WGSL Top-Level let is now const
All top level constants are now declared with const, catching up with the wgsl spec.
let is no longer allowed at the global scope, only within functions.
-let SOME_CONSTANT = 12.0;
+const SOME_CONSTANT = 12.0;See https://github.com/gfx-rs/naga/blob/master/CHANGELOG.md#v011-2023-01-25 for smaller shader improvements.
Surface Capabilities API
The various surface capability functions were combined into a single call that gives you all the capabilities.
- let formats = surface.get_supported_formats(&adapter);
- let present_modes = surface.get_supported_present_modes(&adapter);
- let alpha_modes = surface.get_supported_alpha_modes(&adapter);
+ let caps = surface.get_capabilities(&adapter);
+ let formats = caps.formats;
+ let present_modes = caps.present_modes;
+ let alpha_modes = caps.alpha_modes;Additionally Surface::get_default_config now returns an Option and returns None if the surface isn't supported by the adapter.
- let config = surface.get_default_config(&adapter);
+ let config = surface.get_default_config(&adapter).expect("Surface unsupported by adapter");Fallible surface creation
Instance::create_surface() now returns Result<Surface, CreateSurfaceError> instead of Surface. This allows an error to be returned if the given window is a HTML canvas and obtaining a WebGPU or WebGL 2 context fails. (No other platforms currently report any errors through this path.) By @kpreid in #3052
Queue::copy_external_image_to_texture on WebAssembly
A new api, Queue::copy_external_image_to_texture, allows you to create wgpu textures from various web image primitives. Specificically from HtmlVideoElement, HtmlCanvasElement, OffscreenCanvas, and ImageBitmap. This provides multiple low-copy ways of interacting with the browser. WebGL is also supported, though WebGL has some additional restrictions, represented by the UNRESTRICTED_EXTERNAL_IMAGE_COPIES downlevel flag. By @cwfitzgerald in #3288
Instance creation now takes InstanceDescriptor instead of Backends
Instance::new() and hub::Global::new() now take an InstanceDescriptor struct which cointains both the existing Backends selection as well as a new Dx12Compiler field for selecting which Dx12 shader compiler to use.
- let instance = Instance::new(wgpu::Backends::all());
+ let instance = Instance::new(wgpu::InstanceDescriptor {
+ backends: wgpu::Backends::all(),
+ dx12_shader_compiler: wgpu::Dx12Compiler::Fxc,
+ });Instance now also also implements Default, which uses wgpu::Backends::all() and wgpu::Dx12Compiler::Fxc for InstanceDescriptor
- let instance = Instance::new(wgpu::InstanceDescriptor {
- backends: wgpu::Backends::all(),
- dx12_shader_compiler: wgpu::Dx12Compiler::Fxc,
- });
+ let instance = Instance::default();By @Elabajaba in #3356
Texture Format Reinterpretation
The new view_formats field in the TextureDescriptor is used to specify a list of formats the texture can be re-interpreted to in a texture view. Currently only changing srgb-ness is allowed (ex. Rgba8Unorm <=> Rgba8UnormSrgb).
let texture = device.create_texture(&wgpu::TextureDescriptor {
// ...
format: TextureFormat::Rgba8UnormSrgb,
+ view_formats: &[TextureFormat::Rgba8Unorm],
});let config = wgpu::SurfaceConfiguration {
// ...
format: TextureFormat::Rgba8Unorm,
+ view_formats: vec![wgpu::TextureFormat::Rgba8UnormSrgb],
};
surface.configure(&device, &config);MSAA x2 and x8 Support
Via the TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES feature, MSAA x2 and x8 are now supported on textures. To query for x2 or x8 support, enable the feature and look at the texture format flags for the texture format of your choice.
DXC Shader Compiler Support for DX12
You can now choose to use the DXC compiler for DX12 instead of FXC. The DXC compiler is faster, less buggy, and allows for new features compared to the old, unmaintained FXC compiler.
You can choose which compiler to use at Instance creation using the dx12_shader_compiler field in the InstanceDescriptor struct. Note that DXC requires both dxcompiler.dll and dxil.dll, which can be downloaded from https://github.com/microsoft/DirectXShaderCompiler/releases. Both .dlls need to be shipped with your application when targeting DX12 and using the DXC compiler. If the .dlls can't be loaded, then it will fall back to the FXC compiler. By @39ali and @Elabajaba in #3356
Suballocate DX12 buffers and textures
The DX12 backend can now suballocate buffers and textures from larger chunks of memory, which can give a significant increase in performance (in testing a 100x improvement has been seen in a simple scene with 200 write_buffer calls per frame, and a 1.4x improvement in Bistro using Bevy).
Previously wgpu-hal's DX12 backend created a new heap on the GPU every time you called write_buffer (by calling CreateCommittedResource), whereas now it uses gpu_allocator to manage GPU memory (and calls CreatePlacedResource with a suballocated heap). By @Elabajaba in #3163
Backend selection by features in wgpu-core
Whereas wgpu-core used to automatically select backends to enable
based on the target OS and architecture, it now has separate features
to enable each backend:
- "metal", for the Metal API on macOS and iOS
- "vulkan", for the Vulkan API (Linux, some Android, and occasionally Windows)
- "dx12", for Microsoft's Direct3D 12 API
- "gles", OpenGL ES, available on many systems
- "dx11", for Microsoft's Direct3D 11 API
None are enabled by default, but the wgpu crate automatically
selects these features based on the target operating system and
architecture, using the same rules that wgpu-core used to, so users
of wgpu should be unaffected by this change. However, other crates
using wgpu-core directly will need to copy wgpu's logic or write
their own. See the [target] section of wgpu/Cargo.toml for
details.
Similarly, wgpu-core now has emscripten and renderdoc features
that wgpu enables on appropriate platforms.
In previous releases, the wgpu-core crate decided which backends to
support. However, this left wgpu-core's users with no way to
override those choices. (Firefox doesn't want the GLES back end, for
example.) There doesn't seem to be any way to have a crate select
backends based on target OS and architecture that users of that crate
can still override. Default features can't be selected based on the
target, for example. That implies that we should do the selection as
late in the dependency DAG as feasible. Having wgpu (and
wgpu-core's other dependents) choose backends seems like the best
option.
By @jimblandy in #3254.
Changes
General
- Convert all
DefaultImplementations on Enums toderive(Default) - Implement
DefaultforCompositeAlphaMode - New downlevel feature
UNRESTRICTED_INDEX_BUFFERto indicate support for usingINDEXtogether with other non-copy/map usages (unsupported on WebGL). By @Wumpf in #3157 - Add missing
DEPTH_BIAS_CLAMPandFULL_DRAW_INDEX_UINT32downlevel flags. By @teoxoy in #3316 - Combine
Surface::get_supported_formats,Surface::get_supported_present_modes, andSurface::get_supported_alpha_modesintoSurface::get_capabilitiesandSurfaceCapabilities. By @cwfitzgerald in #3157 - Make
Surface::get_default_configreturn an Option to prevent panics. By @cwfitzgerald in #3157 - Lower the
max_buffer_sizelimit value for compatibility with Apple2 and WebGPU compliance. By @jinleili in #3255 - Limits
min_uniform_buffer_offset_alignmentandmin_storage_buffer_offset_alignmentis now always at least 32. By @Wumpf #3262 - Dereferencing a buffer view is now marked inline. By @Wumpf in #3307
- The
strict_assertfamily of macros was moved towgpu-types. By @i509VCB in #3051 - Make
ObjectIdstructure and invariants idiomatic. By @teoxoy in #3347 - Add validation in accordance with WebGPU
GPUSamplerDescriptorvalid usage forlodMinClampandlodMaxClamp. By @James2022-rgb in #3353 - Remove panics in
Derefimplementations forQueueWriteBufferViewandBufferViewMut. Instead, warnings are logged, since reading from these types is not recommended. By @botahamec in [#3336] - Implement
view_formatsin the TextureDescriptor to match the WebGPU spec. By @jinleili in #3237 - Show more information in error message for non-aligned buffer bindings in WebGL #3414
- Update
TextureViewvalidation according to the WebGPU spec. By @teoxoy in #3410 - Implement
view_formatsin the SurfaceConfiguration to match the WebGPU spec. By @jinleili in #3409
Vulkan
- Set
WEBGPU_TEXTURE_FORMAT_SUPPORTdownlevel flag depending on the proper format support by @teoxoy in #3367. - Set
COPY_SRC/COPY_DSTonly based on Vulkan'sTRANSFER_SRC/TRANSFER_DSTby @teoxoy in #3366.
GLES
- Browsers that support
OVR_multiview2now report theMULTIVIEWfeature by @expenses in #3121. Limits::max_push_constant_sizeon GLES is now 256 by @Dinnerbone in #3374.- Creating multiple pipelines with the same shaders will now be faster, by @Dinnerbone in #3380.
WebGPU
- Implement
queue_validate_write_bufferby @jinleili in #3098 - Sync depth/stencil copy restrictions with the spec by @teoxoy in #3314
Added/New Features
General
- Implement
HashforDepthStencilStateandDepthBiasState - Add the
"wgsl"feature, to enable WGSL shaders inwgpu-coreandwgpu. Enabled by default inwgpu. By @daxpedda in #2890. - Implement
CloneforShaderSourceandShaderModuleDescriptorinwgpu. By @daxpedda in #3086. - Add
get_default_configforSurfaceto simplify user creation ofSurfaceConfiguration. By @jinleili in #3034 - Improve compute shader validation error message. By @haraldreingruber in #3139
- Native adapters can now use MSAA x2 and x8 if it's supported , previously only x1 and x4 were supported . By @39ali in 3140
- Implemented correleation between user timestamps and platform specific presentation timestamps via [
Adapter::get_presentation_timestamp]. By @cwfitzgerald in #3240 - Added support for
Features::SHADER_PRIMITIVE_INDEXon all backends. By @cwfitzgerald in #3272 - Implemented
TextureFormat::Stencil8, allowing for stencil testing without depth components. By @Dinnerbone in #3343 - Implemented
add_srgb_suffix()forTextureFormatfor converting linear formats to sRGB. By @Elabajaba in #3419 - Zero-initialize workgroup memory. By @teoxoy in #3174
GLES
- Surfaces support now
TextureFormat::Rgba8Unormand (non-web only)TextureFormat::Bgra8Unorm. By @Wumpf in #3070 - Support alpha to coverage. By @Wumpf in #3156
- Support filtering f32 textures. By @expenses in #3261
WebGPU
- Add
MULTISAMPLE_X2,MULTISAMPLE_X4andMULTISAMPLE_X8toTextureFormatFeatureFlags. By @39ali in 3140 - Sync
TextureFormat.describewith the spec. By @teoxoy in 3312
Bug Fixes
General
- Update ndk-sys to v0.4.1+23.1.7779620, to fix checksum failures. By @jimblandy in #3232.
- Bother to free the
hal::Api::CommandBufferwhen awgpu_core::command::CommandEncoderis dropped. By @jimblandy in #3069. - Fixed the mipmap example by adding the missing WRITE_TIMESTAMP_INSIDE_PASSES feature. By @Olaroll in #3081.
- Avoid panicking in some interactions with invalid resources by @nical in (#3094)[https://github.com//pull/3094]
- Fixed an integer overflow in
copy_texture_to_textureby @nical #3090 - Remove
wgpu_types::Features::DEPTH24PLUS_STENCIL8, makingwgpu::TextureFormat::Depth24PlusStencil8available on all backends. By @Healthire in (#3151)[https://github.com//pull/3151] - Fix an integer overflow in
queue_write_textureby @nical in (#3146)[https://github.com//pull/3146] - Make
RenderPassCompatibilityErrorandCreateShaderModuleErrornot so huge. By @jimblandy in (#3226)[https://github.com//pull/3226] - Check for invalid bitflag bits in wgpu-core and allow them to be captured/replayed by @nical in (#3229)[https://github.com//pull/3229]
- Evaluate
gfx_select!'s#[cfg]conditions at the right time. By @jimblandy in #3253 - Improve error messages when binding bind group with dynamic offsets. By @cwfitzgerald in #3294
- Allow non-filtering sampling of integer textures. By @JMS55 in #3362.
- Validate texture ids in
Global::queue_texture_write. By @jimblandy in #3378. - Don't panic on mapped buffer in queue_submit. By @crowlKats in #3364.
- Fix being able to sample a depth texture with a filtering sampler. By @teoxoy in #3394.
- Make
make_spirv_rawandmake_spirvhandle big-endian binaries. By @1e1001 in #3411.
Vulkan
- Update ash to 0.37.1+1.3.235 to fix CI breaking by changing a call to the deprecated
debug_utils_set_object_name()function toset_debug_utils_object_name()by @Elabajaba in #3273 - Document and improve extension detection. By @teoxoy in #3327
- Don't use a pointer to a local copy of a
PhysicalDeviceDriverPropertiesstruct after it has gone out of scope. In fact, don't make a local copy at all. Introduce a helper function for buildingCStrs from C character arrays, and remove someunsafeblocks. By @jimblandy in #3076.
DX12
- Fix
depth16Unormformats by @teoxoy in #3313 - Don't re-use
GraphicsCommandListwhencloseorresetfails. By @xiaopengli89 in #3204
Metal
- Fix texture view creation with full-resource views when using an explicit
mip_level_countorarray_layer_count. By @cwfitzgerald in #3323
GLES
- Fixed WebGL not displaying srgb targets correctly if a non-screen filling viewport was previously set. By @Wumpf in #3093
- Fix disallowing multisampling for float textures if otherwise supported. By @Wumpf in #3183
- Fix a panic when creating a pipeline with opaque types other than samplers (images and atomic counters). By @James2022-rgb in #3361
- Fix uniform buffers being empty on some vendors. By @Dinnerbone in #3391
- Fix a panic allocating a new buffer on webgl. By @Dinnerbone in #3396
WebGPU
- Use
loginstead ofprintlnin hello example by @JolifantoBambla in #2858
deno-webgpu
- Let
setVertexBufferandsetIndexBuffercalls on
GPURenderBundleEncoderthrow an error if thesizeargument is
zero, rather than treating that as "until the end of the buffer".
By @jimblandy in #3171
Emscripten
- Let the wgpu examples
framework.rscompile again under Emscripten. By @jimblandy in #3246
Examples
- Log adapter info in hello example on wasm target by @JolifantoBambla in #2858
- Added new example
stencil-trianglesto show basic use of stencil testing. By @Dinnerbone in #3343
Testing/Internal
- Update the
minimum supported rust versionto 1.64 - Move
ResourceMetadatainto its own module. By @jimblandy in #3213 - Add WebAssembly testing infrastructure. By @haraldreingruber in #3238
- Error message when you forget to use cargo-nextest. By @cwfitzgerald in #3293