From 562503335770ae989c096ec115f88fbda97cd04f Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Thu, 6 Jan 2022 18:39:37 -0500 Subject: [PATCH 01/12] add AddressMode::ClampToZero --- wgpu-core/src/device/mod.rs | 8 ++++++++ wgpu-hal/src/dx12/conv.rs | 2 +- wgpu-hal/src/dx12/device.rs | 14 +++++++++++++- wgpu-hal/src/gles/conv.rs | 2 +- wgpu-hal/src/gles/device.rs | 6 ++++++ wgpu-hal/src/metal/adapter.rs | 4 ++++ wgpu-hal/src/metal/conv.rs | 1 + wgpu-hal/src/metal/device.rs | 1 + wgpu-hal/src/vulkan/conv.rs | 2 +- wgpu-hal/src/vulkan/device.rs | 7 +++++++ wgpu-types/src/lib.rs | 17 +++++++++++++++++ wgpu/src/backend/web.rs | 1 + 12 files changed, 61 insertions(+), 4 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 2045f22812..6d22c70c80 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -990,6 +990,14 @@ impl Device { self.require_features(wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER)?; } + if desc + .address_modes + .iter() + .any(|am| am == &wgt::AddressMode::ClampToZero) + { + self.require_features(wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO)?; + } + let lod_clamp = if desc.lod_min_clamp > 0.0 || desc.lod_max_clamp < 32.0 { Some(desc.lod_min_clamp..desc.lod_max_clamp) } else { diff --git a/wgpu-hal/src/dx12/conv.rs b/wgpu-hal/src/dx12/conv.rs index 3763d31671..0150573940 100644 --- a/wgpu-hal/src/dx12/conv.rs +++ b/wgpu-hal/src/dx12/conv.rs @@ -247,7 +247,7 @@ pub fn map_address_mode(mode: wgt::AddressMode) -> d3d12::D3D12_TEXTURE_ADDRESS_ Am::Repeat => d3d12::D3D12_TEXTURE_ADDRESS_MODE_WRAP, Am::MirrorRepeat => d3d12::D3D12_TEXTURE_ADDRESS_MODE_MIRROR, Am::ClampToEdge => d3d12::D3D12_TEXTURE_ADDRESS_MODE_CLAMP, - Am::ClampToBorder => d3d12::D3D12_TEXTURE_ADDRESS_MODE_BORDER, + Am::ClampToBorder | Am::ClampToZero => d3d12::D3D12_TEXTURE_ADDRESS_MODE_BORDER, //Am::MirrorClamp => d3d12::D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE, } } diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 5294a16275..bcb903ed70 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -620,6 +620,18 @@ impl crate::Device for super::Device { .anisotropy_clamp .map_or(0, |_| d3d12::D3D12_FILTER_ANISOTROPIC); + let border_color = conv::map_border_color(desc.border_color).or_else(|| { + if desc + .address_modes + .iter() + .any(|am| am == &wgt::AddressMode::ClampToBorder) + { + Some([0.0; 4]) + } else { + None + } + }); + self.raw.create_sampler( handle.raw, filter, @@ -631,7 +643,7 @@ impl crate::Device for super::Device { 0.0, desc.anisotropy_clamp.map_or(0, |aniso| aniso.get() as u32), conv::map_comparison(desc.compare.unwrap_or(wgt::CompareFunction::Always)), - conv::map_border_color(desc.border_color), + border_color, desc.lod_clamp.clone().unwrap_or(0.0..16.0), ); diff --git a/wgpu-hal/src/gles/conv.rs b/wgpu-hal/src/gles/conv.rs index 09c269143a..b161b73a42 100644 --- a/wgpu-hal/src/gles/conv.rs +++ b/wgpu-hal/src/gles/conv.rs @@ -226,7 +226,7 @@ pub fn map_address_mode(mode: wgt::AddressMode) -> u32 { wgt::AddressMode::Repeat => glow::REPEAT, wgt::AddressMode::MirrorRepeat => glow::MIRRORED_REPEAT, wgt::AddressMode::ClampToEdge => glow::CLAMP_TO_EDGE, - wgt::AddressMode::ClampToBorder => glow::CLAMP_TO_BORDER, + wgt::AddressMode::ClampToBorder | wgt::AddressMode::ClampToZero => glow::CLAMP_TO_BORDER, //wgt::AddressMode::MirrorClamp => glow::MIRROR_CLAMP_TO_EDGE, } } diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index a85301fa2c..ff481908be 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -726,6 +726,12 @@ impl crate::Device for super::Device { wgt::SamplerBorderColor::OpaqueWhite => [1.0; 4], }; gl.sampler_parameter_f32_slice(raw, glow::TEXTURE_BORDER_COLOR, &border); + } else if desc + .address_modes + .iter() + .any(|am| am == &wgt::AddressMode::ClampToBorder) + { + gl.sampler_parameter_f32_slice(raw, glow::TEXTURE_BORDER_COLOR, &[0.0; 4]); } if let Some(ref range) = desc.lod_clamp { diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 287430a7fe..215327435f 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -944,6 +944,10 @@ impl super::PrivateCapabilities { F::ADDRESS_MODE_CLAMP_TO_BORDER, self.sampler_clamp_to_border, ); + features.set( + F::ADDRESS_MODE_CLAMP_TO_ZERO, + true, + ); features } diff --git a/wgpu-hal/src/metal/conv.rs b/wgpu-hal/src/metal/conv.rs index 8cc7dc67c9..5c4b686ce8 100644 --- a/wgpu-hal/src/metal/conv.rs +++ b/wgpu-hal/src/metal/conv.rs @@ -63,6 +63,7 @@ pub fn map_address_mode(address: wgt::AddressMode) -> mtl::MTLSamplerAddressMode Fm::MirrorRepeat => MirrorRepeat, Fm::ClampToEdge => ClampToEdge, Fm::ClampToBorder => ClampToBorderColor, + Fm::ClampToZero => ClampToZero, //Fm::MirrorClamp => MirrorClampToEdge, } } diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 84a2caf362..68803ef78d 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -409,6 +409,7 @@ impl crate::Device for super::Device { if let Some(fun) = desc.compare { descriptor.set_compare_function(conv::map_compare_function(fun)); } + if let Some(border_color) = desc.border_color { descriptor.set_border_color(conv::map_border_color(border_color)); } diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index b77ef051b6..18c455caf4 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -588,7 +588,7 @@ pub fn map_address_mode(mode: wgt::AddressMode) -> vk::SamplerAddressMode { wgt::AddressMode::ClampToEdge => vk::SamplerAddressMode::CLAMP_TO_EDGE, wgt::AddressMode::Repeat => vk::SamplerAddressMode::REPEAT, wgt::AddressMode::MirrorRepeat => vk::SamplerAddressMode::MIRRORED_REPEAT, - wgt::AddressMode::ClampToBorder => vk::SamplerAddressMode::CLAMP_TO_BORDER, + wgt::AddressMode::ClampToBorder | wgt::AddressMode::ClampToZero => vk::SamplerAddressMode::CLAMP_TO_BORDER, //wgt::AddressMode::MirrorClamp => vk::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE, } } diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 5af777e595..d84d01d919 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -974,8 +974,15 @@ impl crate::Device for super::Device { .max_anisotropy(aniso.get() as f32); } } + if let Some(color) = desc.border_color { vk_info = vk_info.border_color(conv::map_border_color(color)); + } else if desc + .address_modes + .iter() + .any(|am| am == &wgt::AddressMode::ClampToBorder) + { + vk_info = vk_info.border_color(vk::BorderColor::FLOAT_TRANSPARENT_BLACK); } let raw = self.shared.raw.create_sampler(&vk_info, None)?; diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index e356c1669a..d238222b68 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -551,6 +551,17 @@ bitflags::bitflags! { /// /// This is a native only feature. const TEXTURE_FORMAT_16BIT_NORM = 1 << 41; + /// Allows the use of [`AddressMode::ClampToZero`]. + /// + /// Supported platforms: + /// - DX12 + /// - Vulkan + /// - Metal + /// - DX11 + /// - OpenGL + /// + /// This is a web and native feature. + const ADDRESS_MODE_CLAMP_TO_ZERO = 1 << 42; } } @@ -3048,6 +3059,12 @@ pub enum AddressMode { /// -0.25 -> border /// 1.25 -> border ClampToBorder = 3, + /// Clamp the value to zero outside of the texture + /// Requires feature [`Features::ADDRESS_MODE_CLAMP_TO_ZERO`] + /// + /// -0.25 -> zero + /// 1.25 -> zero + ClampToZero = 3, } impl Default for AddressMode { diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 9f3e55edba..c930549359 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -887,6 +887,7 @@ fn map_address_mode(mode: wgt::AddressMode) -> web_sys::GpuAddressMode { wgt::AddressMode::Repeat => web_sys::GpuAddressMode::Repeat, wgt::AddressMode::MirrorRepeat => web_sys::GpuAddressMode::MirrorRepeat, wgt::AddressMode::ClampToBorder => panic!("Clamp to border is not supported"), + wgt::AddressMode::ClampToZero => panic!("Clamp to zero is not supported"), } } From 5fefff93340367743fbcd45107299b0e86e16e1d Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Thu, 6 Jan 2022 18:50:16 -0500 Subject: [PATCH 02/12] add feature checks --- wgpu-hal/src/dx12/adapter.rs | 1 + wgpu-hal/src/gles/adapter.rs | 4 ++++ wgpu-hal/src/vulkan/adapter.rs | 1 + 3 files changed, 6 insertions(+) diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index b405d55da9..2027e000c1 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -180,6 +180,7 @@ impl super::Adapter { | wgt::Features::MULTI_DRAW_INDIRECT | wgt::Features::MULTI_DRAW_INDIRECT_COUNT | wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER + | wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO | wgt::Features::POLYGON_MODE_LINE | wgt::Features::POLYGON_MODE_POINT | wgt::Features::VERTEX_WRITABLE_STORAGE diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 9c882c8c41..31e74c7d9f 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -291,6 +291,10 @@ impl super::Adapter { wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER, extensions.contains("GL_EXT_texture_border_clamp"), ); + features.set( + wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO, + extensions.contains("GL_EXT_texture_border_clamp"), + ); features.set( wgt::Features::DEPTH_CLIP_CONTROL, extensions.contains("GL_EXT_depth_clamp"), diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 993d55538b..482befcb57 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -329,6 +329,7 @@ impl PhysicalDeviceFeatures { | F::MAPPABLE_PRIMARY_BUFFERS | F::PUSH_CONSTANTS | F::ADDRESS_MODE_CLAMP_TO_BORDER + | F::ADDRESS_MODE_CLAMP_TO_ZERO | F::TIMESTAMP_QUERY | F::PIPELINE_STATISTICS_QUERY | F::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES From d154e5ae25cba4c0f18bd11c4b46b921e771083f Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Thu, 6 Jan 2022 18:54:23 -0500 Subject: [PATCH 03/12] oops --- wgpu-types/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index d238222b68..89c132b9fa 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -3064,7 +3064,7 @@ pub enum AddressMode { /// /// -0.25 -> zero /// 1.25 -> zero - ClampToZero = 3, + ClampToZero = 4, } impl Default for AddressMode { From 337f2199c25c1e1be62afcd3767521da4b1436d6 Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Fri, 7 Jan 2022 12:35:26 -0500 Subject: [PATCH 04/12] rustfmt --- wgpu-hal/src/metal/adapter.rs | 5 +---- wgpu-hal/src/metal/device.rs | 2 +- wgpu-hal/src/vulkan/conv.rs | 4 +++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 215327435f..78bc3707bc 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -944,10 +944,7 @@ impl super::PrivateCapabilities { F::ADDRESS_MODE_CLAMP_TO_BORDER, self.sampler_clamp_to_border, ); - features.set( - F::ADDRESS_MODE_CLAMP_TO_ZERO, - true, - ); + features.set(F::ADDRESS_MODE_CLAMP_TO_ZERO, true); features } diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 68803ef78d..f18e010941 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -409,7 +409,7 @@ impl crate::Device for super::Device { if let Some(fun) = desc.compare { descriptor.set_compare_function(conv::map_compare_function(fun)); } - + if let Some(border_color) = desc.border_color { descriptor.set_border_color(conv::map_border_color(border_color)); } diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index 18c455caf4..df18c6a653 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -588,7 +588,9 @@ pub fn map_address_mode(mode: wgt::AddressMode) -> vk::SamplerAddressMode { wgt::AddressMode::ClampToEdge => vk::SamplerAddressMode::CLAMP_TO_EDGE, wgt::AddressMode::Repeat => vk::SamplerAddressMode::REPEAT, wgt::AddressMode::MirrorRepeat => vk::SamplerAddressMode::MIRRORED_REPEAT, - wgt::AddressMode::ClampToBorder | wgt::AddressMode::ClampToZero => vk::SamplerAddressMode::CLAMP_TO_BORDER, + wgt::AddressMode::ClampToBorder | wgt::AddressMode::ClampToZero => { + vk::SamplerAddressMode::CLAMP_TO_BORDER + } //wgt::AddressMode::MirrorClamp => vk::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE, } } From b4d43753dade2ef798cb036fe9a6c5d1275ee824 Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Fri, 7 Jan 2022 12:37:50 -0500 Subject: [PATCH 05/12] fix dx12 --- wgpu-hal/src/dx12/device.rs | 20 +++++++++----------- wgpu-hal/src/vulkan/conv.rs | 3 +-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index bcb903ed70..4bb91654eb 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -620,17 +620,15 @@ impl crate::Device for super::Device { .anisotropy_clamp .map_or(0, |_| d3d12::D3D12_FILTER_ANISOTROPIC); - let border_color = conv::map_border_color(desc.border_color).or_else(|| { - if desc - .address_modes - .iter() - .any(|am| am == &wgt::AddressMode::ClampToBorder) - { - Some([0.0; 4]) - } else { - None - } - }); + let border_color = if desc + .address_modes + .iter() + .any(|am| am == &wgt::AddressMode::ClampToZero) + { + [0.0; 4] + } else { + conv::map_border_color(desc.border_color) + }; self.raw.create_sampler( handle.raw, diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index df18c6a653..0cf3e11cc4 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -590,8 +590,7 @@ pub fn map_address_mode(mode: wgt::AddressMode) -> vk::SamplerAddressMode { wgt::AddressMode::MirrorRepeat => vk::SamplerAddressMode::MIRRORED_REPEAT, wgt::AddressMode::ClampToBorder | wgt::AddressMode::ClampToZero => { vk::SamplerAddressMode::CLAMP_TO_BORDER - } - //wgt::AddressMode::MirrorClamp => vk::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE, + } //wgt::AddressMode::MirrorClamp => vk::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE, } } From 0446182ee8bac0610b146edadba0656a92a78a76 Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Tue, 11 Jan 2022 17:33:15 -0500 Subject: [PATCH 06/12] change to use SamplerBorderColor --- wgpu-core/src/device/mod.rs | 8 ++------ wgpu-hal/src/dx12/adapter.rs | 2 +- wgpu-hal/src/dx12/conv.rs | 2 +- wgpu-hal/src/dx12/device.rs | 10 +--------- wgpu-hal/src/gles/adapter.rs | 2 +- wgpu-hal/src/gles/conv.rs | 2 +- wgpu-hal/src/gles/device.rs | 8 +------- wgpu-hal/src/metal/adapter.rs | 2 +- wgpu-hal/src/metal/conv.rs | 2 +- wgpu-hal/src/metal/device.rs | 24 +++++++++++++++++++----- wgpu-hal/src/vulkan/adapter.rs | 2 +- wgpu-hal/src/vulkan/conv.rs | 9 +++++---- wgpu-hal/src/vulkan/device.rs | 6 ------ wgpu-types/src/lib.rs | 17 ++++++++--------- wgpu/src/backend/web.rs | 1 - 15 files changed, 43 insertions(+), 54 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 6d22c70c80..60023beeef 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -990,12 +990,8 @@ impl Device { self.require_features(wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER)?; } - if desc - .address_modes - .iter() - .any(|am| am == &wgt::AddressMode::ClampToZero) - { - self.require_features(wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO)?; + if desc.border_color == Some(wgt::SamplerBorderColor::AutoBlack) { + self.require_features(wgt::Features::SAMPLER_BORDER_COLOR_AUTO_BLACK)?; } let lod_clamp = if desc.lod_min_clamp > 0.0 || desc.lod_max_clamp < 32.0 { diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 2027e000c1..31eefdb12b 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -180,7 +180,7 @@ impl super::Adapter { | wgt::Features::MULTI_DRAW_INDIRECT | wgt::Features::MULTI_DRAW_INDIRECT_COUNT | wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER - | wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO + | wgt::Features::SAMPLER_BORDER_COLOR_AUTO_BLACK | wgt::Features::POLYGON_MODE_LINE | wgt::Features::POLYGON_MODE_POINT | wgt::Features::VERTEX_WRITABLE_STORAGE diff --git a/wgpu-hal/src/dx12/conv.rs b/wgpu-hal/src/dx12/conv.rs index 0150573940..a59c30c9fd 100644 --- a/wgpu-hal/src/dx12/conv.rs +++ b/wgpu-hal/src/dx12/conv.rs @@ -276,7 +276,7 @@ pub fn map_comparison(func: wgt::CompareFunction) -> d3d12::D3D12_COMPARISON_FUN pub fn map_border_color(border_color: Option) -> [f32; 4] { use wgt::SamplerBorderColor as Sbc; match border_color { - Some(Sbc::TransparentBlack) | None => [0.0; 4], + Some(Sbc::TransparentBlack) | Some(Sbc::AutoBlack) | None => [0.0; 4], Some(Sbc::OpaqueBlack) => [0.0, 0.0, 0.0, 1.0], Some(Sbc::OpaqueWhite) => [1.0; 4], } diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 4bb91654eb..a29eeed45b 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -620,15 +620,7 @@ impl crate::Device for super::Device { .anisotropy_clamp .map_or(0, |_| d3d12::D3D12_FILTER_ANISOTROPIC); - let border_color = if desc - .address_modes - .iter() - .any(|am| am == &wgt::AddressMode::ClampToZero) - { - [0.0; 4] - } else { - conv::map_border_color(desc.border_color) - }; + let border_color = conv::map_border_color(desc.border_color); self.raw.create_sampler( handle.raw, diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 31e74c7d9f..92e506c173 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -292,7 +292,7 @@ impl super::Adapter { extensions.contains("GL_EXT_texture_border_clamp"), ); features.set( - wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO, + wgt::Features::SAMPLER_BORDER_COLOR_AUTO_BLACK, extensions.contains("GL_EXT_texture_border_clamp"), ); features.set( diff --git a/wgpu-hal/src/gles/conv.rs b/wgpu-hal/src/gles/conv.rs index b161b73a42..09c269143a 100644 --- a/wgpu-hal/src/gles/conv.rs +++ b/wgpu-hal/src/gles/conv.rs @@ -226,7 +226,7 @@ pub fn map_address_mode(mode: wgt::AddressMode) -> u32 { wgt::AddressMode::Repeat => glow::REPEAT, wgt::AddressMode::MirrorRepeat => glow::MIRRORED_REPEAT, wgt::AddressMode::ClampToEdge => glow::CLAMP_TO_EDGE, - wgt::AddressMode::ClampToBorder | wgt::AddressMode::ClampToZero => glow::CLAMP_TO_BORDER, + wgt::AddressMode::ClampToBorder => glow::CLAMP_TO_BORDER, //wgt::AddressMode::MirrorClamp => glow::MIRROR_CLAMP_TO_EDGE, } } diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index ff481908be..266888db61 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -721,17 +721,11 @@ impl crate::Device for super::Device { if let Some(border_color) = desc.border_color { let border = match border_color { - wgt::SamplerBorderColor::TransparentBlack => [0.0; 4], + wgt::SamplerBorderColor::TransparentBlack | wgt::SamplerBorderColor::AutoBlack => [0.0; 4], wgt::SamplerBorderColor::OpaqueBlack => [0.0, 0.0, 0.0, 1.0], wgt::SamplerBorderColor::OpaqueWhite => [1.0; 4], }; gl.sampler_parameter_f32_slice(raw, glow::TEXTURE_BORDER_COLOR, &border); - } else if desc - .address_modes - .iter() - .any(|am| am == &wgt::AddressMode::ClampToBorder) - { - gl.sampler_parameter_f32_slice(raw, glow::TEXTURE_BORDER_COLOR, &[0.0; 4]); } if let Some(ref range) = desc.lod_clamp { diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 78bc3707bc..ef69df1153 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -944,7 +944,7 @@ impl super::PrivateCapabilities { F::ADDRESS_MODE_CLAMP_TO_BORDER, self.sampler_clamp_to_border, ); - features.set(F::ADDRESS_MODE_CLAMP_TO_ZERO, true); + features.set(F::SAMPLER_BORDER_COLOR_AUTO_BLACK, true); features } diff --git a/wgpu-hal/src/metal/conv.rs b/wgpu-hal/src/metal/conv.rs index 5c4b686ce8..dba44155a8 100644 --- a/wgpu-hal/src/metal/conv.rs +++ b/wgpu-hal/src/metal/conv.rs @@ -63,7 +63,6 @@ pub fn map_address_mode(address: wgt::AddressMode) -> mtl::MTLSamplerAddressMode Fm::MirrorRepeat => MirrorRepeat, Fm::ClampToEdge => ClampToEdge, Fm::ClampToBorder => ClampToBorderColor, - Fm::ClampToZero => ClampToZero, //Fm::MirrorClamp => MirrorClampToEdge, } } @@ -74,6 +73,7 @@ pub fn map_border_color(border_color: wgt::SamplerBorderColor) -> mtl::MTLSample wgt::SamplerBorderColor::TransparentBlack => TransparentBlack, wgt::SamplerBorderColor::OpaqueBlack => OpaqueBlack, wgt::SamplerBorderColor::OpaqueWhite => OpaqueWhite, + _ => unreachable!() } } diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index f18e010941..5622fd61c8 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -388,15 +388,15 @@ impl crate::Device for super::Device { wgt::FilterMode::Linear => mtl::MTLSamplerMipFilter::Linear, }); - if let Some(aniso) = desc.anisotropy_clamp { - descriptor.set_max_anisotropy(aniso.get() as _); - } - let [s, t, r] = desc.address_modes; descriptor.set_address_mode_s(conv::map_address_mode(s)); descriptor.set_address_mode_t(conv::map_address_mode(t)); descriptor.set_address_mode_r(conv::map_address_mode(r)); + if let Some(aniso) = desc.anisotropy_clamp { + descriptor.set_max_anisotropy(aniso.get() as _); + } + if let Some(ref range) = desc.lod_clamp { descriptor.set_lod_min_clamp(range.start); descriptor.set_lod_max_clamp(range.end); @@ -411,7 +411,21 @@ impl crate::Device for super::Device { } if let Some(border_color) = desc.border_color { - descriptor.set_border_color(conv::map_border_color(border_color)); + if let SamplerBorderColor::AutoBlack = border_color { + if s == SamplerAddressMode::ClampToBorder { + descriptor.set_address_mode_s(mtl::MTLSamplerAddressMode::ClampToZero); + } + + if t == SamplerAddressMode::ClampToBorder { + descriptor.set_address_mode_t(mtl::MTLSamplerAddressMode::ClampToZero); + } + + if r == SamplerAddressMode::ClampToBorder { + descriptor.set_address_mode_r(mtl::MTLSamplerAddressMode::ClampToZero); + } + } else { + descriptor.set_border_color(conv::map_border_color(border_color)); + } } if let Some(label) = desc.label { diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 482befcb57..8efaa6bbea 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -329,7 +329,7 @@ impl PhysicalDeviceFeatures { | F::MAPPABLE_PRIMARY_BUFFERS | F::PUSH_CONSTANTS | F::ADDRESS_MODE_CLAMP_TO_BORDER - | F::ADDRESS_MODE_CLAMP_TO_ZERO + | F::SAMPLER_BORDER_COLOR_AUTO_BLACK | F::TIMESTAMP_QUERY | F::PIPELINE_STATISTICS_QUERY | F::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index 0cf3e11cc4..5d9154240a 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -588,15 +588,16 @@ pub fn map_address_mode(mode: wgt::AddressMode) -> vk::SamplerAddressMode { wgt::AddressMode::ClampToEdge => vk::SamplerAddressMode::CLAMP_TO_EDGE, wgt::AddressMode::Repeat => vk::SamplerAddressMode::REPEAT, wgt::AddressMode::MirrorRepeat => vk::SamplerAddressMode::MIRRORED_REPEAT, - wgt::AddressMode::ClampToBorder | wgt::AddressMode::ClampToZero => { - vk::SamplerAddressMode::CLAMP_TO_BORDER - } //wgt::AddressMode::MirrorClamp => vk::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE, + wgt::AddressMode::ClampToBorder => vk::SamplerAddressMode::CLAMP_TO_BORDER, + // wgt::AddressMode::MirrorClamp => vk::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE, } } pub fn map_border_color(border_color: wgt::SamplerBorderColor) -> vk::BorderColor { match border_color { - wgt::SamplerBorderColor::TransparentBlack => vk::BorderColor::FLOAT_TRANSPARENT_BLACK, + wgt::SamplerBorderColor::TransparentBlack | wgt::SamplerBorderColor::AutoBlack => { + vk::BorderColor::FLOAT_TRANSPARENT_BLACK + } wgt::SamplerBorderColor::OpaqueBlack => vk::BorderColor::FLOAT_OPAQUE_BLACK, wgt::SamplerBorderColor::OpaqueWhite => vk::BorderColor::FLOAT_OPAQUE_WHITE, } diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index d84d01d919..0bbc1b79a0 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -977,12 +977,6 @@ impl crate::Device for super::Device { if let Some(color) = desc.border_color { vk_info = vk_info.border_color(conv::map_border_color(color)); - } else if desc - .address_modes - .iter() - .any(|am| am == &wgt::AddressMode::ClampToBorder) - { - vk_info = vk_info.border_color(vk::BorderColor::FLOAT_TRANSPARENT_BLACK); } let raw = self.shared.raw.create_sampler(&vk_info, None)?; diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 89c132b9fa..6769833d6f 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -551,7 +551,7 @@ bitflags::bitflags! { /// /// This is a native only feature. const TEXTURE_FORMAT_16BIT_NORM = 1 << 41; - /// Allows the use of [`AddressMode::ClampToZero`]. + /// Allows the use of [`SamplerBorderColor::AutoBlack`]. /// /// Supported platforms: /// - DX12 @@ -560,8 +560,8 @@ bitflags::bitflags! { /// - DX11 /// - OpenGL /// - /// This is a web and native feature. - const ADDRESS_MODE_CLAMP_TO_ZERO = 1 << 42; + /// This is a native only feature. + const SAMPLER_BORDER_COLOR_AUTO_BLACK = 1 << 42; } } @@ -3059,12 +3059,6 @@ pub enum AddressMode { /// -0.25 -> border /// 1.25 -> border ClampToBorder = 3, - /// Clamp the value to zero outside of the texture - /// Requires feature [`Features::ADDRESS_MODE_CLAMP_TO_ZERO`] - /// - /// -0.25 -> zero - /// 1.25 -> zero - ClampToZero = 4, } impl Default for AddressMode { @@ -3549,6 +3543,11 @@ pub enum SamplerBorderColor { OpaqueBlack, /// [1, 1, 1, 1] OpaqueWhite, + /// On the Metal backend, this is equivalent to `TransparentBlack` for + /// textures that have an alpha component, and equivalent to `OpaqueBlack` + /// for textures that do not have an alpha component. On other backends, + /// this is equivalent to `TransparentBlack`. Not supported on the web. + AutoBlack, } /// Describes how to create a QuerySet. diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index c930549359..9f3e55edba 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -887,7 +887,6 @@ fn map_address_mode(mode: wgt::AddressMode) -> web_sys::GpuAddressMode { wgt::AddressMode::Repeat => web_sys::GpuAddressMode::Repeat, wgt::AddressMode::MirrorRepeat => web_sys::GpuAddressMode::MirrorRepeat, wgt::AddressMode::ClampToBorder => panic!("Clamp to border is not supported"), - wgt::AddressMode::ClampToZero => panic!("Clamp to zero is not supported"), } } From 94c250d4419c694a481cd2ada97ca7d8bc2fb883 Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Tue, 11 Jan 2022 17:38:58 -0500 Subject: [PATCH 07/12] fix metal --- wgpu-hal/src/metal/device.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 5622fd61c8..66150b4eca 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -411,16 +411,16 @@ impl crate::Device for super::Device { } if let Some(border_color) = desc.border_color { - if let SamplerBorderColor::AutoBlack = border_color { - if s == SamplerAddressMode::ClampToBorder { + if let wgt::SamplerBorderColor::AutoBlack = border_color { + if s == wgt::AddressMode::ClampToBorder { descriptor.set_address_mode_s(mtl::MTLSamplerAddressMode::ClampToZero); } - if t == SamplerAddressMode::ClampToBorder { + if t == wgt::AddressMode::ClampToBorder { descriptor.set_address_mode_t(mtl::MTLSamplerAddressMode::ClampToZero); } - if r == SamplerAddressMode::ClampToBorder { + if r == wgt::AddressMode::ClampToBorder { descriptor.set_address_mode_r(mtl::MTLSamplerAddressMode::ClampToZero); } } else { From c90dd03ddc6227cb4c936fc21cc49241728e4be7 Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Fri, 14 Jan 2022 13:22:05 -0500 Subject: [PATCH 08/12] update to use new config --- wgpu-core/src/device/mod.rs | 4 ++-- wgpu-hal/src/gles/adapter.rs | 2 +- wgpu-hal/src/gles/device.rs | 2 +- wgpu-hal/src/metal/adapter.rs | 8 +++----- wgpu-hal/src/metal/device.rs | 2 +- wgpu-hal/src/vulkan/adapter.rs | 2 +- wgpu-hal/src/vulkan/conv.rs | 2 +- wgpu-types/src/lib.rs | 10 ++++++---- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 60023beeef..a8305d0c47 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -990,8 +990,8 @@ impl Device { self.require_features(wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER)?; } - if desc.border_color == Some(wgt::SamplerBorderColor::AutoBlack) { - self.require_features(wgt::Features::SAMPLER_BORDER_COLOR_AUTO_BLACK)?; + if desc.border_color == Some(wgt::SamplerBorderColor::Zero) { + self.require_features(wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO)?; } let lod_clamp = if desc.lod_min_clamp > 0.0 || desc.lod_max_clamp < 32.0 { diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 92e506c173..31e74c7d9f 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -292,7 +292,7 @@ impl super::Adapter { extensions.contains("GL_EXT_texture_border_clamp"), ); features.set( - wgt::Features::SAMPLER_BORDER_COLOR_AUTO_BLACK, + wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO, extensions.contains("GL_EXT_texture_border_clamp"), ); features.set( diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 266888db61..769bdda19e 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -721,7 +721,7 @@ impl crate::Device for super::Device { if let Some(border_color) = desc.border_color { let border = match border_color { - wgt::SamplerBorderColor::TransparentBlack | wgt::SamplerBorderColor::AutoBlack => [0.0; 4], + wgt::SamplerBorderColor::TransparentBlack | wgt::SamplerBorderColor::Zero => [0.0; 4], wgt::SamplerBorderColor::OpaqueBlack => [0.0, 0.0, 0.0, 1.0], wgt::SamplerBorderColor::OpaqueWhite => [1.0; 4], }; diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index ef69df1153..c89d848258 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -940,11 +940,9 @@ impl super::PrivateCapabilities { { features.insert(F::STORAGE_RESOURCE_BINDING_ARRAY); } - features.set( - F::ADDRESS_MODE_CLAMP_TO_BORDER, - self.sampler_clamp_to_border, - ); - features.set(F::SAMPLER_BORDER_COLOR_AUTO_BLACK, true); + + features.set(F::ADDRESS_MODE_CLAMP_TO_BORDER, self.sampler_clamp_to_border); + features.set(F::ADDRESS_MODE_CLAMP_TO_ZERO, true); features } diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 66150b4eca..0872cb3aa6 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -411,7 +411,7 @@ impl crate::Device for super::Device { } if let Some(border_color) = desc.border_color { - if let wgt::SamplerBorderColor::AutoBlack = border_color { + if let wgt::SamplerBorderColor::Zero = border_color { if s == wgt::AddressMode::ClampToBorder { descriptor.set_address_mode_s(mtl::MTLSamplerAddressMode::ClampToZero); } diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 8efaa6bbea..482befcb57 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -329,7 +329,7 @@ impl PhysicalDeviceFeatures { | F::MAPPABLE_PRIMARY_BUFFERS | F::PUSH_CONSTANTS | F::ADDRESS_MODE_CLAMP_TO_BORDER - | F::SAMPLER_BORDER_COLOR_AUTO_BLACK + | F::ADDRESS_MODE_CLAMP_TO_ZERO | F::TIMESTAMP_QUERY | F::PIPELINE_STATISTICS_QUERY | F::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index 5d9154240a..33bc2cc245 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -595,7 +595,7 @@ pub fn map_address_mode(mode: wgt::AddressMode) -> vk::SamplerAddressMode { pub fn map_border_color(border_color: wgt::SamplerBorderColor) -> vk::BorderColor { match border_color { - wgt::SamplerBorderColor::TransparentBlack | wgt::SamplerBorderColor::AutoBlack => { + wgt::SamplerBorderColor::TransparentBlack | wgt::SamplerBorderColor::Zero => { vk::BorderColor::FLOAT_TRANSPARENT_BLACK } wgt::SamplerBorderColor::OpaqueBlack => vk::BorderColor::FLOAT_OPAQUE_BLACK, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 6769833d6f..b868b5f7d9 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -399,7 +399,7 @@ bitflags::bitflags! { /// Supported platforms: /// - DX12 /// - Vulkan - /// - Metal (macOS 10.12+ only) + /// - Metal (macOS 10.12+ always, iOS if used with [`SamplerBorderColor::AutoBlack`]) /// - DX11 /// - OpenGL /// @@ -561,7 +561,7 @@ bitflags::bitflags! { /// - OpenGL /// /// This is a native only feature. - const SAMPLER_BORDER_COLOR_AUTO_BLACK = 1 << 42; + const ADDRESS_MODE_CLAMP_TO_ZERO = 1 << 42; } } @@ -3543,11 +3543,13 @@ pub enum SamplerBorderColor { OpaqueBlack, /// [1, 1, 1, 1] OpaqueWhite, + /// On the Metal backend, this is equivalent to `TransparentBlack` for /// textures that have an alpha component, and equivalent to `OpaqueBlack` /// for textures that do not have an alpha component. On other backends, - /// this is equivalent to `TransparentBlack`. Not supported on the web. - AutoBlack, + /// this is equivalent to `TransparentBlack`. Requires + /// [`Features::ADDRESS_MODE_CLAMP_TO_ZERO`]. Not supported on the web. + Zero, } /// Describes how to create a QuerySet. From 9a6a534f8407c8ba4359b4882561bfa3f69ddcc5 Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Fri, 14 Jan 2022 13:25:34 -0500 Subject: [PATCH 09/12] update dx12 + docs --- wgpu-hal/src/dx12/adapter.rs | 2 +- wgpu-hal/src/dx12/conv.rs | 2 +- wgpu-types/src/lib.rs | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 31eefdb12b..2027e000c1 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -180,7 +180,7 @@ impl super::Adapter { | wgt::Features::MULTI_DRAW_INDIRECT | wgt::Features::MULTI_DRAW_INDIRECT_COUNT | wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER - | wgt::Features::SAMPLER_BORDER_COLOR_AUTO_BLACK + | wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO | wgt::Features::POLYGON_MODE_LINE | wgt::Features::POLYGON_MODE_POINT | wgt::Features::VERTEX_WRITABLE_STORAGE diff --git a/wgpu-hal/src/dx12/conv.rs b/wgpu-hal/src/dx12/conv.rs index a59c30c9fd..37cc335b7a 100644 --- a/wgpu-hal/src/dx12/conv.rs +++ b/wgpu-hal/src/dx12/conv.rs @@ -276,7 +276,7 @@ pub fn map_comparison(func: wgt::CompareFunction) -> d3d12::D3D12_COMPARISON_FUN pub fn map_border_color(border_color: Option) -> [f32; 4] { use wgt::SamplerBorderColor as Sbc; match border_color { - Some(Sbc::TransparentBlack) | Some(Sbc::AutoBlack) | None => [0.0; 4], + Some(Sbc::TransparentBlack) | Some(Sbc::Zero) | None => [0.0; 4], Some(Sbc::OpaqueBlack) => [0.0, 0.0, 0.0, 1.0], Some(Sbc::OpaqueWhite) => [1.0; 4], } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index b868b5f7d9..7ce7257547 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -394,12 +394,13 @@ bitflags::bitflags! { /// /// This is a native only feature. const PUSH_CONSTANTS = 1 << 26; - /// Allows the use of [`AddressMode::ClampToBorder`]. + /// Allows the use of [`AddressMode::ClampToBorder`] with a border color + /// other than [`SamplerBorderColor::Zero`]. /// /// Supported platforms: /// - DX12 /// - Vulkan - /// - Metal (macOS 10.12+ always, iOS if used with [`SamplerBorderColor::AutoBlack`]) + /// - Metal (macOS 10.12+ only) /// - DX11 /// - OpenGL /// @@ -551,7 +552,8 @@ bitflags::bitflags! { /// /// This is a native only feature. const TEXTURE_FORMAT_16BIT_NORM = 1 << 41; - /// Allows the use of [`SamplerBorderColor::AutoBlack`]. + /// Allows the use of [`AddressMode::ClampToBorder`] with a border color + /// of [`SamplerBorderColor::Zero`]. /// /// Supported platforms: /// - DX12 From 7106242ea3e4dfd3d94a72d1820fd458fa296e41 Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Fri, 14 Jan 2022 14:49:26 -0500 Subject: [PATCH 10/12] address nits --- wgpu-hal/src/gles/adapter.rs | 6 +----- wgpu-hal/src/metal/conv.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 31e74c7d9f..601e9a8e80 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -288,11 +288,7 @@ impl super::Adapter { | wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES | wgt::Features::CLEAR_TEXTURE; features.set( - wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER, - extensions.contains("GL_EXT_texture_border_clamp"), - ); - features.set( - wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO, + wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER | wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO, extensions.contains("GL_EXT_texture_border_clamp"), ); features.set( diff --git a/wgpu-hal/src/metal/conv.rs b/wgpu-hal/src/metal/conv.rs index dba44155a8..96d801a265 100644 --- a/wgpu-hal/src/metal/conv.rs +++ b/wgpu-hal/src/metal/conv.rs @@ -73,7 +73,7 @@ pub fn map_border_color(border_color: wgt::SamplerBorderColor) -> mtl::MTLSample wgt::SamplerBorderColor::TransparentBlack => TransparentBlack, wgt::SamplerBorderColor::OpaqueBlack => OpaqueBlack, wgt::SamplerBorderColor::OpaqueWhite => OpaqueWhite, - _ => unreachable!() + wgt::SamplerBorderColor::Zero => unreachable!() } } From 13cced7e4121157726332d817db3dd933ab7e42a Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Fri, 14 Jan 2022 15:16:45 -0500 Subject: [PATCH 11/12] cargo fmt --- wgpu-hal/src/gles/device.rs | 4 +++- wgpu-hal/src/metal/adapter.rs | 7 +++++-- wgpu-hal/src/metal/conv.rs | 2 +- wgpu-hal/src/vulkan/conv.rs | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 769bdda19e..93a582c265 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -721,7 +721,9 @@ impl crate::Device for super::Device { if let Some(border_color) = desc.border_color { let border = match border_color { - wgt::SamplerBorderColor::TransparentBlack | wgt::SamplerBorderColor::Zero => [0.0; 4], + wgt::SamplerBorderColor::TransparentBlack | wgt::SamplerBorderColor::Zero => { + [0.0; 4] + } wgt::SamplerBorderColor::OpaqueBlack => [0.0, 0.0, 0.0, 1.0], wgt::SamplerBorderColor::OpaqueWhite => [1.0; 4], }; diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index c89d848258..5568dfa0a7 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -940,8 +940,11 @@ impl super::PrivateCapabilities { { features.insert(F::STORAGE_RESOURCE_BINDING_ARRAY); } - - features.set(F::ADDRESS_MODE_CLAMP_TO_BORDER, self.sampler_clamp_to_border); + + features.set( + F::ADDRESS_MODE_CLAMP_TO_BORDER, + self.sampler_clamp_to_border, + ); features.set(F::ADDRESS_MODE_CLAMP_TO_ZERO, true); features diff --git a/wgpu-hal/src/metal/conv.rs b/wgpu-hal/src/metal/conv.rs index 96d801a265..f275a74ec9 100644 --- a/wgpu-hal/src/metal/conv.rs +++ b/wgpu-hal/src/metal/conv.rs @@ -73,7 +73,7 @@ pub fn map_border_color(border_color: wgt::SamplerBorderColor) -> mtl::MTLSample wgt::SamplerBorderColor::TransparentBlack => TransparentBlack, wgt::SamplerBorderColor::OpaqueBlack => OpaqueBlack, wgt::SamplerBorderColor::OpaqueWhite => OpaqueWhite, - wgt::SamplerBorderColor::Zero => unreachable!() + wgt::SamplerBorderColor::Zero => unreachable!(), } } diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index 33bc2cc245..de5872e2c8 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -588,7 +588,7 @@ pub fn map_address_mode(mode: wgt::AddressMode) -> vk::SamplerAddressMode { wgt::AddressMode::ClampToEdge => vk::SamplerAddressMode::CLAMP_TO_EDGE, wgt::AddressMode::Repeat => vk::SamplerAddressMode::REPEAT, wgt::AddressMode::MirrorRepeat => vk::SamplerAddressMode::MIRRORED_REPEAT, - wgt::AddressMode::ClampToBorder => vk::SamplerAddressMode::CLAMP_TO_BORDER, + wgt::AddressMode::ClampToBorder => vk::SamplerAddressMode::CLAMP_TO_BORDER, // wgt::AddressMode::MirrorClamp => vk::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE, } } From 4e3c40384bf899e9ace241c28fc6588e4ac6a5c4 Mon Sep 17 00:00:00 2001 From: Ibiyemi Abiodun Date: Fri, 14 Jan 2022 15:17:12 -0500 Subject: [PATCH 12/12] fix dx12 --- wgpu-hal/src/dx12/conv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-hal/src/dx12/conv.rs b/wgpu-hal/src/dx12/conv.rs index 37cc335b7a..45c648a6ab 100644 --- a/wgpu-hal/src/dx12/conv.rs +++ b/wgpu-hal/src/dx12/conv.rs @@ -247,7 +247,7 @@ pub fn map_address_mode(mode: wgt::AddressMode) -> d3d12::D3D12_TEXTURE_ADDRESS_ Am::Repeat => d3d12::D3D12_TEXTURE_ADDRESS_MODE_WRAP, Am::MirrorRepeat => d3d12::D3D12_TEXTURE_ADDRESS_MODE_MIRROR, Am::ClampToEdge => d3d12::D3D12_TEXTURE_ADDRESS_MODE_CLAMP, - Am::ClampToBorder | Am::ClampToZero => d3d12::D3D12_TEXTURE_ADDRESS_MODE_BORDER, + Am::ClampToBorder => d3d12::D3D12_TEXTURE_ADDRESS_MODE_BORDER, //Am::MirrorClamp => d3d12::D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE, } }