gfx-rs/wgpu · error
Clamp to border is not supported
Error message
Clamp to border is not supported
What it means
Raised by map_address_mode in the WebGPU (browser) backend when a sampler is created with AddressMode::ClampToBorder. The browser WebGPU API only supports ClampToEdge, Repeat, and MirrorRepeat address modes, so the backend cannot map ClampToBorder and panics. This is a backend capability limitation, not a validation error.
Source
Thrown at wgpu/src/backend/webgpu.rs:775
match mode {
wgt::FilterMode::Nearest => webgpu_sys::GpuFilterMode::Nearest,
wgt::FilterMode::Linear => webgpu_sys::GpuFilterMode::Linear,
}
}
fn map_mipmap_filter_mode(mode: wgt::MipmapFilterMode) -> webgpu_sys::GpuMipmapFilterMode {
match mode {
wgt::MipmapFilterMode::Nearest => webgpu_sys::GpuMipmapFilterMode::Nearest,
wgt::MipmapFilterMode::Linear => webgpu_sys::GpuMipmapFilterMode::Linear,
}
}
fn map_address_mode(mode: wgt::AddressMode) -> webgpu_sys::GpuAddressMode {
match mode {
wgt::AddressMode::ClampToEdge => webgpu_sys::GpuAddressMode::ClampToEdge,
wgt::AddressMode::Repeat => webgpu_sys::GpuAddressMode::Repeat,
wgt::AddressMode::MirrorRepeat => webgpu_sys::GpuAddressMode::MirrorRepeat,
wgt::AddressMode::ClampToBorder => panic!("Clamp to border is not supported"),
}
}
fn map_color(color: wgt::Color) -> webgpu_sys::GpuColorDict {
webgpu_sys::GpuColorDict::new(color.a, color.b, color.g, color.r)
}
fn map_store_op(store: crate::StoreOp) -> webgpu_sys::GpuStoreOp {
match store {
crate::StoreOp::Store => webgpu_sys::GpuStoreOp::Store,
crate::StoreOp::Discard => webgpu_sys::GpuStoreOp::Discard,
}
}
fn map_map_mode(mode: crate::MapMode) -> u32 {
match mode {
crate::MapMode::Read => webgpu_sys::gpu_map_mode::READ,
crate::MapMode::Write => webgpu_sys::gpu_map_mode::WRITE,View on GitHub (pinned to 3e11ff59bf)
Solutions
- Change the sampler's address mode to ClampToEdge, Repeat, or MirrorRepeat on web.
- Emulate ClampToBorder in-shader: clamp UVs and manually blend with the border color at edges.
- Pad the texture with the border color in its own pixels and use ClampToEdge to approximate the behavior.
Example fix
// before
let sampler = device.create_sampler(&wgpu::SamplerDescriptor { address_mode: wgpu::AddressMode::ClampToBorder, ..Default::default() });
// after
let sampler = device.create_sampler(&wgpu::SamplerDescriptor { address_mode: wgpu::AddressMode::ClampToEdge, ..Default::default() }); Defensive patterns
Strategy: validation
Validate before calling
assert_ne!(address_mode, wgpu::AddressMode::ClampToBorder, "ClampToBorder unsupported on web backend");
Type guard
fn is_web_safe_address_mode(m: wgpu::AddressMode) -> bool {
matches!(m, wgpu::AddressMode::ClampToEdge | wgpu::AddressMode::Repeat | wgpu::AddressMode::MirrorRepeat)
} Prevention
- Default shared sampler configs to ClampToEdge unless a native backend is confirmed.
- Emulate border behavior in shaders when edge transparency is needed.
- Add a unit test that validates all sampler descriptors against backend capabilities.
When it happens
Trigger: Calling device.create_sampler with address_mode (or any of address_mode_u/v/w) set to wgpu::AddressMode::ClampToBorder on the web backend.
Common situations: Sharing sampler configuration between native and web builds; using border-color-based effects like mirrored UI padding or shadow-map comparison sampling that rely on ClampToBorder; porting native engines to WASM.
Related errors
- Web backend does not support arrays of samplers
- multi-plane textures are not supported
- found `ShaderSource::Dummy`
- Web backend does not support arrays of buffers
- Web backend does not support BINDING_INDEXING extension
AI-assisted analysis of gfx-rs/wgpu@3e11ff59bf (2026-09-03).
Data as JSON: /api/errors/995c5fd5e94b1d02.
Report an issue: GitHub.