Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Bottom level categories:

#### 'wgpu::Instance::enumerate_adapters` is now `async` & available on WebGPU

Making `enumerate_adapters` async allows custom backends to use it along with elimnating some native/non-native distinctions
Making `enumerate_adapters` async allows custom backends to use it along with eliminating some native/non-native distinctions

This is a breaking change

Expand All @@ -54,6 +54,19 @@ This is a breaking change

By @R-Cramer4 in [#8230](https://github.com/gfx-rs/wgpu/pull/8230)

#### `MipmapFilterMode` is split from `FilterMode`

This is a breaking change that aligns wgpu with spec.

```diff
SamplerDescriptor {
...
- mipmap_filter: FilterMode::Nearest
+ mipmap_filter: MipmapFilterMode::Nearest
...
}
```

## v27.0.2 (2025-10-03)

### Bug Fixes
Expand Down
21 changes: 18 additions & 3 deletions deno_webgpu/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ pub(super) struct GPUSamplerDescriptor {
pub mag_filter: GPUFilterMode,
#[webidl(default = GPUFilterMode::Nearest)]
pub min_filter: GPUFilterMode,
#[webidl(default = GPUFilterMode::Nearest)]
pub mipmap_filter: GPUFilterMode,
#[webidl(default = GPUMipmapFilterMode::Nearest)]
pub mipmap_filter: GPUMipmapFilterMode,

#[webidl(default = 0.0)]
pub lod_min_clamp: f32,
Expand Down Expand Up @@ -99,7 +99,6 @@ impl From<GPUAddressMode> for wgpu_types::AddressMode {
}
}

// Same as GPUMipmapFilterMode
#[derive(WebIDL)]
#[webidl(enum)]
pub(crate) enum GPUFilterMode {
Expand All @@ -116,6 +115,22 @@ impl From<GPUFilterMode> for wgpu_types::FilterMode {
}
}

#[derive(WebIDL)]
#[webidl(enum)]
pub(crate) enum GPUMipmapFilterMode {
Nearest,
Linear,
}

impl From<GPUMipmapFilterMode> for wgpu_types::MipmapFilterMode {
fn from(value: GPUMipmapFilterMode) -> Self {
match value {
GPUMipmapFilterMode::Nearest => Self::Nearest,
GPUMipmapFilterMode::Linear => Self::Linear,
}
}
}

#[derive(WebIDL)]
#[webidl(enum)]
pub(crate) enum GPUCompareFunction {
Expand Down
2 changes: 1 addition & 1 deletion examples/features/src/bunnymark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl crate::framework::Example for Example {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
..Default::default()
});

Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/mipmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Example {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
..Default::default()
});

Expand Down Expand Up @@ -268,7 +268,7 @@ impl crate::framework::Example for Example {
address_mode_w: wgpu::AddressMode::Repeat,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::MipmapFilterMode::Linear,
..Default::default()
});
let mx_total = Self::generate_matrix(config.width as f32 / config.height as f32);
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/multiple_render_targets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl MultiTargetRenderer {
address_mode_w: wgpu::AddressMode::Repeat,
mag_filter: wgpu::FilterMode::Nearest,
min_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
..Default::default()
});

Expand Down Expand Up @@ -240,7 +240,7 @@ impl TargetRenderer {
address_mode_w: wgpu::AddressMode::Repeat,
mag_filter: wgpu::FilterMode::Nearest,
min_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
..Default::default()
});

Expand Down
2 changes: 1 addition & 1 deletion examples/features/src/ray_cube_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl crate::framework::Example for Example {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
..Default::default()
});

Expand Down
2 changes: 1 addition & 1 deletion examples/features/src/ray_cube_normals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl crate::framework::Example for Example {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
..Default::default()
});

Expand Down
2 changes: 1 addition & 1 deletion examples/features/src/ray_traced_triangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl crate::framework::Example for Example {
address_mode_w: Default::default(),
mag_filter: wgpu::FilterMode::Nearest,
min_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
lod_min_clamp: 1.0,
lod_max_clamp: 1.0,
compare: None,
Expand Down
2 changes: 1 addition & 1 deletion examples/features/src/shadow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl crate::framework::Example for Example {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
compare: Some(wgpu::CompareFunction::LessEqual),
..Default::default()
});
Expand Down
2 changes: 1 addition & 1 deletion examples/features/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl crate::framework::Example for Example {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::MipmapFilterMode::Linear,
..Default::default()
});

Expand Down
2 changes: 1 addition & 1 deletion examples/features/src/water/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl Example {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Nearest,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
..Default::default()
});

Expand Down
8 changes: 4 additions & 4 deletions tests/tests/wgpu-gpu/bind_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static BIND_GROUP_NONFILTERING_LAYOUT_NONFILTERING_SAMPLER: GpuTestConfiguration
label: Some("bind_group_non_filtering_layout_nonfiltering_sampler"),
min_filter: wgpu::FilterMode::Nearest,
mag_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
..wgpu::SamplerDescriptor::default()
},
true,
Expand All @@ -210,7 +210,7 @@ static BIND_GROUP_NONFILTERING_LAYOUT_MIN_SAMPLER: GpuTestConfiguration =
label: Some("bind_group_non_filtering_layout_min_sampler"),
min_filter: wgpu::FilterMode::Linear,
mag_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
..wgpu::SamplerDescriptor::default()
},
false,
Expand All @@ -228,7 +228,7 @@ static BIND_GROUP_NONFILTERING_LAYOUT_MAG_SAMPLER: GpuTestConfiguration =
label: Some("bind_group_non_filtering_layout_mag_sampler"),
min_filter: wgpu::FilterMode::Nearest,
mag_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
..wgpu::SamplerDescriptor::default()
},
false,
Expand All @@ -246,7 +246,7 @@ static BIND_GROUP_NONFILTERING_LAYOUT_MIPMAP_SAMPLER: GpuTestConfiguration =
label: Some("bind_group_non_filtering_layout_mipmap_sampler"),
min_filter: wgpu::FilterMode::Nearest,
mag_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::MipmapFilterMode::Linear,
..wgpu::SamplerDescriptor::default()
},
false,
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/wgpu-gpu/binding_array/samplers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async fn binding_array_samplers(ctx: TestingContext, partially_bound: bool) {
address_mode_w: AddressMode::ClampToEdge,
mag_filter: FilterMode::Linear,
min_filter: FilterMode::Linear,
mipmap_filter: FilterMode::Linear,
mipmap_filter: MipmapFilterMode::Linear,
lod_min_clamp: 0.0,
lod_max_clamp: 1000.0,
compare: None,
Expand All @@ -134,7 +134,7 @@ async fn binding_array_samplers(ctx: TestingContext, partially_bound: bool) {
address_mode_w: AddressMode::ClampToEdge,
mag_filter: FilterMode::Nearest,
min_filter: FilterMode::Nearest,
mipmap_filter: FilterMode::Nearest,
mipmap_filter: MipmapFilterMode::Nearest,
lod_min_clamp: 0.0,
lod_max_clamp: 1000.0,
compare: None,
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/wgpu-gpu/samplers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn sampler_deduplication(ctx: TestingContext) {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Nearest,
min_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: None,
Expand All @@ -52,7 +52,7 @@ fn sampler_deduplication(ctx: TestingContext) {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::MipmapFilterMode::Linear,
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: None,
Expand Down Expand Up @@ -96,7 +96,7 @@ fn sampler_creation_failure(ctx: TestingContext) {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Nearest,
min_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: None,
Expand Down Expand Up @@ -397,7 +397,7 @@ fn sampler_bind_group(ctx: TestingContext, group_type: GroupType) {
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Linear,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Nearest,
mipmap_filter: wgpu::MipmapFilterMode::Nearest,
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: None,
Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,9 +1951,9 @@ impl Device {
},
);
}
if !matches!(desc.mipmap_filter, wgt::FilterMode::Linear) {
if !matches!(desc.mipmap_filter, wgt::MipmapFilterMode::Linear) {
return Err(
resource::CreateSamplerError::InvalidFilterModeWithAnisotropy {
resource::CreateSamplerError::InvalidMipmapFilterModeWithAnisotropy {
filter_type: resource::SamplerFilterErrorType::MipmapFilter,
filter_mode: desc.mipmap_filter,
anisotropic_clamp: desc.anisotropy_clamp,
Expand Down Expand Up @@ -1999,7 +1999,7 @@ impl Device {
comparison: desc.compare.is_some(),
filtering: desc.min_filter == wgt::FilterMode::Linear
|| desc.mag_filter == wgt::FilterMode::Linear
|| desc.mipmap_filter == wgt::FilterMode::Linear,
|| desc.mipmap_filter == wgt::MipmapFilterMode::Linear,
};

let sampler = Arc::new(sampler);
Expand Down
11 changes: 9 additions & 2 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ pub struct SamplerDescriptor<'a> {
/// How to filter the texture when it needs to be minified (made smaller)
pub min_filter: wgt::FilterMode,
/// How to filter between mip map levels
pub mipmap_filter: wgt::FilterMode,
pub mipmap_filter: wgt::MipmapFilterMode,
/// Minimum level of detail (i.e. mip level) to use
pub lod_min_clamp: f32,
/// Maximum level of detail (i.e. mip level) to use
Expand Down Expand Up @@ -1989,6 +1989,12 @@ pub enum CreateSamplerError {
filter_mode: wgt::FilterMode,
anisotropic_clamp: u16,
},
#[error("Invalid filter mode for {filter_type:?}: {filter_mode:?}. When anistropic clamp is not 1 (it is {anisotropic_clamp}), all filter modes must be linear.")]
InvalidMipmapFilterModeWithAnisotropy {
filter_type: SamplerFilterErrorType,
filter_mode: wgt::MipmapFilterMode,
anisotropic_clamp: u16,
},
#[error(transparent)]
MissingFeatures(#[from] MissingFeatures),
}
Expand All @@ -2008,7 +2014,8 @@ impl WebGpuError for CreateSamplerError {
Self::InvalidLodMinClamp(_)
| Self::InvalidLodMaxClamp { .. }
| Self::InvalidAnisotropy(_)
| Self::InvalidFilterModeWithAnisotropy { .. } => return ErrorType::Validation,
| Self::InvalidFilterModeWithAnisotropy { .. }
| Self::InvalidMipmapFilterModeWithAnisotropy { .. } => return ErrorType::Validation,
};
e.webgpu_error_type()
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/examples/halmark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl<A: hal::Api> Example<A> {
address_modes: [wgpu_types::AddressMode::ClampToEdge; 3],
mag_filter: wgpu_types::FilterMode::Linear,
min_filter: wgpu_types::FilterMode::Nearest,
mipmap_filter: wgpu_types::FilterMode::Nearest,
mipmap_filter: wgpu_types::MipmapFilterMode::Nearest,
lod_clamp: 0.0..32.0,
compare: None,
anisotropy_clamp: 1,
Expand Down
7 changes: 7 additions & 0 deletions wgpu-hal/src/dx12/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ pub fn map_filter_mode(mode: wgt::FilterMode) -> Direct3D12::D3D12_FILTER_TYPE {
}
}

pub fn map_mipmap_filter_mode(mode: wgt::MipmapFilterMode) -> Direct3D12::D3D12_FILTER_TYPE {
match mode {
wgt::MipmapFilterMode::Nearest => Direct3D12::D3D12_FILTER_TYPE_POINT,
wgt::MipmapFilterMode::Linear => Direct3D12::D3D12_FILTER_TYPE_LINEAR,
}
}

pub fn map_comparison(func: wgt::CompareFunction) -> Direct3D12::D3D12_COMPARISON_FUNC {
use wgt::CompareFunction as Cf;
match func {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ impl crate::Device for super::Device {
let mut filter = Direct3D12::D3D12_FILTER(
(conv::map_filter_mode(desc.min_filter).0 << Direct3D12::D3D12_MIN_FILTER_SHIFT)
| (conv::map_filter_mode(desc.mag_filter).0 << Direct3D12::D3D12_MAG_FILTER_SHIFT)
| (conv::map_filter_mode(desc.mipmap_filter).0
| (conv::map_mipmap_filter_mode(desc.mipmap_filter).0
<< Direct3D12::D3D12_MIP_FILTER_SHIFT)
| (reduction.0 << Direct3D12::D3D12_FILTER_REDUCTION_TYPE_SHIFT),
);
Expand Down
11 changes: 6 additions & 5 deletions wgpu-hal/src/gles/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,21 @@ pub(super) fn describe_vertex_format(vertex_format: wgt::VertexFormat) -> super:
pub fn map_filter_modes(
min: wgt::FilterMode,
mag: wgt::FilterMode,
mip: wgt::FilterMode,
mip: wgt::MipmapFilterMode,
) -> (u32, u32) {
use wgt::FilterMode as Fm;
use wgt::MipmapFilterMode as Mfm;

let mag_filter = match mag {
Fm::Nearest => glow::NEAREST,
Fm::Linear => glow::LINEAR,
};

let min_filter = match (min, mip) {
(Fm::Nearest, Fm::Nearest) => glow::NEAREST_MIPMAP_NEAREST,
(Fm::Nearest, Fm::Linear) => glow::NEAREST_MIPMAP_LINEAR,
(Fm::Linear, Fm::Nearest) => glow::LINEAR_MIPMAP_NEAREST,
(Fm::Linear, Fm::Linear) => glow::LINEAR_MIPMAP_LINEAR,
(Fm::Nearest, Mfm::Nearest) => glow::NEAREST_MIPMAP_NEAREST,
(Fm::Nearest, Mfm::Linear) => glow::NEAREST_MIPMAP_LINEAR,
(Fm::Linear, Mfm::Nearest) => glow::LINEAR_MIPMAP_NEAREST,
(Fm::Linear, Mfm::Linear) => glow::LINEAR_MIPMAP_LINEAR,
};

(min_filter, mag_filter)
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ pub struct SamplerDescriptor<'a> {
pub address_modes: [wgt::AddressMode; 3],
pub mag_filter: wgt::FilterMode,
pub min_filter: wgt::FilterMode,
pub mipmap_filter: wgt::FilterMode,
pub mipmap_filter: wgt::MipmapFilterMode,
pub lod_clamp: Range<f32>,
pub compare: Option<wgt::CompareFunction>,
// Must in the range [1, 16].
Expand Down
6 changes: 3 additions & 3 deletions wgpu-hal/src/metal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,11 @@ impl crate::Device for super::Device {
descriptor.set_min_filter(conv::map_filter_mode(desc.min_filter));
descriptor.set_mag_filter(conv::map_filter_mode(desc.mag_filter));
descriptor.set_mip_filter(match desc.mipmap_filter {
wgt::FilterMode::Nearest if desc.lod_clamp == (0.0..0.0) => {
wgt::MipmapFilterMode::Nearest if desc.lod_clamp == (0.0..0.0) => {
MTLSamplerMipFilter::NotMipmapped
}
wgt::FilterMode::Nearest => MTLSamplerMipFilter::Nearest,
wgt::FilterMode::Linear => MTLSamplerMipFilter::Linear,
wgt::MipmapFilterMode::Nearest => MTLSamplerMipFilter::Nearest,
wgt::MipmapFilterMode::Linear => MTLSamplerMipFilter::Linear,
});

let [s, t, r] = desc.address_modes;
Expand Down
Loading