From 993448ab2ca6155f0c859cad49624a119d8bc4b7 Mon Sep 17 00:00:00 2001 From: atlv Date: Wed, 14 Jan 2026 11:28:50 -0800 Subject: [PATCH] Add Limits::or_worse_values_from (#8870) --- CHANGELOG.md | 1 + wgpu-types/src/limits.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4dc55f9a..45a047d7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Bottom level categories: - Added support for cooperative load/store operations in shaders. Currently only WGSL on the input and SPIR-V, METAL, and WGSL on the output are supported. By @kvark in [#8251](https://github.com/gfx-rs/wgpu/issues/8251). - Added support for obtaining `AdapterInfo` from `Device`. By @sagudev in [#8807](https://github.com/gfx-rs/wgpu/pull/8807). +- Added `Limits::or_worse_values_from`. By @atlv24 in [#8870](https://github.com/gfx-rs/wgpu/pull/8870). ### Bug Fixes diff --git a/wgpu-types/src/limits.rs b/wgpu-types/src/limits.rs index 5fbc6c318..a83886793 100644 --- a/wgpu-types/src/limits.rs +++ b/wgpu-types/src/limits.rs @@ -717,8 +717,7 @@ impl Limits { /// /// This function is not for clamping requests for values beyond the /// supported limits. For that purpose the desired function would be - /// `or_worse_values_from` (which doesn't exist, but could be added if - /// needed). + /// `or_worse_values_from`. #[must_use] pub fn or_better_values_from(mut self, other: &Self) -> Self { macro_rules! or_better_value_from { @@ -737,6 +736,30 @@ impl Limits { self } + + /// For each limit in `other` that is worse than the value in `self`, + /// replace the value in `self` with the value from `other`. + /// + /// This function is for clamping requests for values beyond the + /// supported limits. + #[must_use] + pub fn or_worse_values_from(mut self, other: &Self) -> Self { + macro_rules! or_worse_value_from { + ($name:ident, $ordering:expr) => { + match $ordering { + // Limits that are maximum values (most of them) + Ordering::Less => self.$name = self.$name.min(other.$name), + // Limits that are minimum values + Ordering::Greater => self.$name = self.$name.max(other.$name), + Ordering::Equal => unreachable!(), + } + }; + } + + with_limits!(or_worse_value_from); + + self + } } /// Represents the sets of additional limits on an adapter,