Major Changes
Pipeline overridable constants
Wgpu supports now pipeline-overridable constants
This allows you to define constants in wgsl like this:
override some_factor: f32 = 42.1337; // Specifies a default of 42.1337 if it's not set.And then set them at runtime like so on your pipeline consuming this shader:
// ...
fragment: Some(wgpu::FragmentState {
compilation_options: wgpu::PipelineCompilationOptions {
constants: &[("some_factor".to_owned(), 0.1234)].into(), // Sets `some_factor` to 0.1234.
..Default::default()
},
// ...
}),
// ...By @teoxoy & @jimblandy in #5500
Changed feature requirements for timestamps
Due to a specification change write_timestamp is no longer supported on WebGPU.
wgpu::CommandEncoder::write_timestamp requires now the new wgpu::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS feature which is available on all native backends but not on WebGPU.
Wgsl const evaluation for many more built-ins
Many numeric built-ins have had a constant evaluation implementation added for them, which allows them to be used in a const context:
abs, acos, acosh, asin, asinh, atan, atanh, cos, cosh, round, saturate, sin, sinh, sqrt, step, tan, tanh, ceil, countLeadingZeros, countOneBits, countTrailingZeros, degrees, exp, exp2, floor, fract, fma, inverseSqrt, log, log2, max, min, radians, reverseBits, sign, trunc
By @ErichDonGubler in #4879, #5098
New native-only wgsl features
Subgroup operations
The following subgroup operations are available in wgsl now:
subgroupBallot, subgroupAll, subgroupAny, subgroupAdd, subgroupMul, subgroupMin, subgroupMax, subgroupAnd, subgroupOr, subgroupXor, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupBroadcastFirst, subgroupBroadcast, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor
Availability is governed by the following feature flags:
wgpu::Features::SUBGROUPfor all operations exceptsubgroupBarrierin fragment & compute, supported on Vulkan, DX12 and Metal.wgpu::Features::SUBGROUP_VERTEX, for all operations exceptsubgroupBarriergeneral operations in vertex shaders, supported on Vulkanwgpu::Features::SUBGROUP_BARRIER, for support of thesubgroupBarrieroperation, supported on Vulkan & Metal
Note that there currently some differences between wgpu's native-only implementation and the open WebGPU proposal.
By @exrook and @Lichtso in #5301
Signed and unsigned 64 bit integer support in shaders.
wgpu::Features::SHADER_INT64 enables 64 bit integer signed and unsigned integer variables in wgsl (i64 and u64 respectively).
Supported on Vulkan, DX12 (requires DXC) and Metal (with MSL 2.3+ support).
By @atlv24 and @cwfitzgerald in #5154
New features
General
- Implemented the
Unorm10_10_10_2VertexFormat by @McMackety in #5477 wgpu-types'straceandreplayfeatures have been replaced by theserdefeature. By @KirmesBude in #5149wgpu-core'sserial-passfeature has been removed. Useserdeinstead. By @KirmesBude in #5149- Added
InstanceFlags::GPU_BASED_VALIDATION, which enables GPU-based validation for shaders. This is currently only supported on the DX12 and Vulkan backends; other platforms ignore this flag, for now. By @ErichDonGubler in #5146, #5046.- When set, this flag implies
InstanceFlags::VALIDATION. - This has been added to the set of flags set by
InstanceFlags::advanced_debugging. Since the overhead is potentially very large, the flag is not enabled by default in debug builds when usingInstanceFlags::from_build_config. - As with other instance flags, this flag can be changed in calls to
InstanceFlags::with_envwith the newWGPU_GPU_BASED_VALIDATIONenvironment variable.
- When set, this flag implies
wgpu::Instancecan now report whichwgpu::Backendsare available based on the build configuration. By @Wumpf #5167-wgpu::Instance::any_backend_feature_enabled() +!wgpu::Instance::enabled_backend_features().is_empty()
- Breaking change:
wgpu_core::pipeline::ProgrammableStageDescriptoris now optional. By @ErichDonGubler in #5305. Features::downlevel{_webgl2,}_featureswas made const by @MultisampledNight in #5343- More as_hal methods and improvements by @JMS55 in #5452
- Added
wgpu::CommandEncoder::as_hal_mut - Added
wgpu::TextureView::as_hal wgpu::Texture::as_halnow returns a user-defined type to match the other as_hal functions
- Added
Naga
- Allow user to select which MSL version to use via
--metal-versionwith Naga CLI. By @pcleavelin in #5392 - Support
arrayLengthfor runtime-sized arrays inside binding arrays (for WGSL input and SPIR-V output). By @kvark in #5428 - Added
--shader-stageand--input-kindoptions to naga-cli for specifying vertex/fragment/compute shaders, and frontend. by @ratmice in #5411 - Added a
create_validatorfunction to wgpu_coreDeviceto create nagaValidators. By @atlv24 #5606
WebGPU
- Implement the
device_set_device_lost_callbackmethod forContextWebGpu. By @suti in #5438 - Add support for storage texture access modes
ReadOnlyandReadWrite. By @JolifantoBambla in #5434
GLES / OpenGL
- Log an error when GLES texture format heuristics fail. By @PolyMeilex in #5266
- Cache the sample count to keep
get_texture_format_featurescheap. By @Dinnerbone in #5346 - Mark
DEPTH32FLOAT_STENCIL8as supported in GLES. By @Dinnerbone in #5370 - Desktop GL now also supports
TEXTURE_COMPRESSION_ETC2. By @valaphee in #5568 - Don't create a program for shader-clearing if that workaround isn't required. By @Dinnerbone in #5348.
- OpenGL will now be preferred over OpenGL ES on EGL, making it consistent with WGL. By @valaphee in #5482
- Fill out
driveranddriver_info, with the OpenGL flavor and version, similar to Vulkan. By @valaphee in #5482
Metal
DX12
Other performance improvements
- Simplify and speed up the allocation of internal IDs. By @nical in #5229
- Use memory pooling for UsageScopes to avoid frequent large allocations. by @robtfm in #5414
- Eager release of GPU resources comes from device.trackers. By @bradwerth in #5075
- Support disabling zero-initialization of workgroup local memory in compute shaders. By @DJMcNab in #5508
Documentation
- Improved
wgpu_haldocumentation. By @jimblandy in #5516, #5524, #5562, #5563, #5566, #5617, #5618 - Add mention of primitive restart in the description of
PrimitiveState::strip_index_format. By @cpsdqs in #5350 - Document precise behaviour of
SourceLocation. By @stefnotch in #5386 - Give short example of WGSL
push_constantsyntax. By @waywardmonkeys in #5393 - Fix incorrect documentation of
Limits::max_compute_workgroup_storage_sizedefault value. By @atlv24 in #5601
Bug Fixes
General
- Fix
serdefeature not compiling forwgpu-types. By @KirmesBude in #5149 - Fix the validation of vertex and index ranges. By @nical in #5144 and #5156
- Fix panic when creating a surface while no backend is available. By @Wumpf #5166
- Correctly compute minimum buffer size for array-typed
storageanduniformvars. By @jimblandy #5222 - Fix timeout when presenting a surface where no work has been done. By @waywardmonkeys in #5200
- Fix registry leaks with de-duplicated resources. By @nical in #5244
- Fix linking when targeting android. By @ashdnazg in #5326.
- Failing to set the device lost closure will call the closure before returning. By @bradwerth in #5358.
- Fix deadlocks caused by recursive read-write lock acquisitions #5426.
- Remove exposed C symbols (
extern "C"+ [no_mangle]) from RenderPass & ComputePass recording. By @Wumpf in #5409. - Fix surfaces being only compatible with first backend enabled on an instance, causing failures when manually specifying an adapter. By @Wumpf in #5535.
Naga
- In spv-in, remove unnecessary "gl_PerVertex" name check so unused builtins will always be skipped. Prevents validation errors caused by capability requirements of these builtins #4915. By @Imberflur in #5227.
- In spv-out, check for acceleration and ray-query types when enabling ray-query extension to prevent validation error. By @Vecvec in #5463
- Add a limit for curly brace nesting in WGSL parsing, plus a note about stack size requirements. By @ErichDonGubler in #5447.
- In hlsl-out, fix accesses on zero value expressions by generating helper functions for
Expression::ZeroValue. By @Imberflur in #5587. - Fix behavior of
extractBitsandinsertBitswhenoffset + countoverflows the bit width. By @cwfitzgerald in #5305 - Fix behavior of integer
clampwhenminargument >maxargument. By @cwfitzgerald in #5300. - Fix
TypeInner::scalar_widthto be consistent with the rest of the codebase and return values in bytes not bits. By @atlv24 in #5532.
GLES / OpenGL
- GLSL 410 does not support layout(binding = ...), enable only for GLSL 420. By @bes in #5357
- Fixes for being able to use an OpenGL 4.1 core context provided by macOS with wgpu. By @bes in #5331.
- Fix crash when holding multiple devices on wayland/surfaceless. By @ashdnazg in #5351.
- Fix
first_instancegetting ignored in draw indexed whenARB_shader_draw_parametersfeature is present andbase_vertexis 0. By @valaphee in #5482
Vulkan
- Set object labels when the DEBUG flag is set, even if the VALIDATION flag is disabled. By @DJMcNab in #5345.
- Add safety check to
wgpu_hal::vulkan::CommandEncoderto make surediscard_encodingis not called in the closed state. By @villuna in #5557 - Fix SPIR-V type capability requests to not depend on
LocalTypecaching. By @atlv24 in #5590
Tests
- Fix intermittent crashes on Linux in the
multithreaded_computetest. By @jimblandy in #5129. - Refactor tests to read feature flags by name instead of a hardcoded hexadecimal u64. By @atlv24 in #5155.
- Add test that verifies that we can drop the queue before using the device to create a command encoder. By @Davidster in #5211