diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d42faa5..f5e6bf14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,10 @@ The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/ - `WGPUNativeLimits::maxMultiviewViewCount` @lisyarus - `WGPUNativeFeature_StorageTextureArrayNonUniformIndexing`, `WGPUNativeFeature_Multiview`, `WGPUNativeFeature_ShaderFloat32Atomic`, `WGPUNativeFeature_TextureAtomic`, `WGPUNativeFeature_TextureFormatP010`, `WGPUNativeFeature_PipelineCache`, `WGPUNativeFeature_ShaderInt64AtomicMinMax`, `WGPUNativeFeature_ShaderInt64AtomicAllOps`, `WGPUNativeFeature_TextureInt64Atomic`, `WGPUNativeFeature_ShaderBarycentrics`, `WGPUNativeFeature_SelectiveMultiview`, `WGPUNativeFeature_MultisampleArray`, `WGPUNativeFeature_CooperativeMatrix`, `WGPUNativeFeature_ShaderPerVertex`, `WGPUNativeFeature_ShaderDrawIndex`, `WGPUNativeFeature_AccelerationStructureBindingArray`, `WGPUNativeFeature_MemoryDecorationCoherent`, `WGPUNativeFeature_MemoryDecorationVolatile` @lisyarus - `wgpuCommandEncoderClearTexture` @lisyarus +- Sampler address modes ClampToBorder and ClampToZero supported: @lisyarus + - `WGPUNativeAddressMode_ClampToBorder` address mode + - `WGPUSamplerBorderColor` enum + - `WGPUSamplerDescriptorExtras` struct to be chained in `WGPUSamplerDescriptor` ### Removed diff --git a/ffi/wgpu.h b/ffi/wgpu.h index aea7b896..10bbdfbb 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -39,6 +39,8 @@ typedef enum WGPUNativeSType WGPUSType_SurfaceSourceSwapChainPanel = 0x0003000B, /** Identifies @ref WGPUPrimitiveStateExtras. */ WGPUSType_PrimitiveStateExtras = 0x0003000C, + /** Identifies @ref WGPUSamplerDescriptorExtras. */ + WGPUSType_SamplerDescriptorExtras = 0x0003000D, WGPUNativeSType_Force32 = 0x7FFFFFFF } WGPUNativeSType; @@ -335,9 +337,8 @@ typedef enum WGPUNativeFeature * This is a native only feature. */ WGPUNativeFeature_StorageTextureArrayNonUniformIndexing = 0x00030010, - // TODO: requires wgpu.h api change - // WGPUNativeFeature_AddressModeClampToZero = 0x00030011, - // WGPUNativeFeature_AddressModeClampToBorder = 0x00030012, + WGPUNativeFeature_AddressModeClampToZero = 0x00030011, + WGPUNativeFeature_AddressModeClampToBorder = 0x00030012, /** * Allows the user to set @ref WGPUPolygonMode_Line in * @ref WGPUPrimitiveStateExtras::polygonMode. @@ -1471,6 +1472,27 @@ typedef struct WGPUImageSubresourceRange { uint32_t arrayLayerCount; } WGPUImageSubresourceRange WGPU_STRUCTURE_ATTRIBUTE; +typedef enum WGPUNativeAddressMode +{ + WGPUNativeAddressMode_ClampToBorder = 0x00000004, + WGPUNativeAddressMode_Force32 = 0x7FFFFFFF +} WGPUNativeAddressMode WGPU_ENUM_ATTRIBUTE; + +typedef enum WGPUSamplerBorderColor +{ + WGPUSamplerBorderColor_Undefined = 0x00000000, + WGPUSamplerBorderColor_TransparentBlack = 0x00000001, + WGPUSamplerBorderColor_OpaqueBlack = 0x00000002, + WGPUSamplerBorderColor_OpaqueWhite = 0x00000003, + WGPUSamplerBorderColor_Zero = 0x00000004, + WGPUSamplerBorderColor_Force32 = 0x7FFFFFFF +} WGPUSamplerBorderColor; + +typedef struct WGPUSamplerDescriptorExtras { + WGPUChainedStruct chain; + WGPUSamplerBorderColor samplerBorderColor; +} WGPUSamplerDescriptorExtras WGPU_STRUCTURE_ATTRIBUTE; + #ifdef __cplusplus extern "C" { diff --git a/src/conv.rs b/src/conv.rs index 3411c537..c7b3f43a 100644 --- a/src/conv.rs +++ b/src/conv.rs @@ -38,15 +38,6 @@ map_enum_with_undefined!( Discard, Store ); -map_enum_with_undefined!( - map_address_mode, - WGPUAddressMode, - wgt::AddressMode, - "Unknown address mode", - ClampToEdge, - Repeat, - MirrorRepeat -); map_enum_with_undefined!( map_filter_mode, WGPUFilterMode, @@ -249,6 +240,17 @@ map_enum_with_undefined!( ReadWrite ); +map_enum_with_undefined!( + map_sampler_border_color, + WGPUSamplerBorderColor, + wgt::SamplerBorderColor, + "Unknown sampler border color", + TransparentBlack, + OpaqueBlack, + OpaqueWhite, + Zero +); + // These are defined as UINT64_MAX in the header, but bindgen currently can't process that define. // See https://github.com/rust-lang/rust-bindgen/issues/2822 pub const WGPU_WHOLE_SIZE: u64 = u64::MAX; @@ -275,6 +277,18 @@ pub fn map_origin3d(native: &native::WGPUOrigin3D) -> wgt::Origin3d { } } +#[inline] +pub fn map_address_mode(mode: native::WGPUAddressMode) -> Option { + match mode { + native::WGPUAddressMode_Undefined => None, + native::WGPUAddressMode_ClampToEdge => Some(wgt::AddressMode::ClampToEdge), + native::WGPUAddressMode_Repeat => Some(wgt::AddressMode::Repeat), + native::WGPUAddressMode_MirrorRepeat => Some(wgt::AddressMode::MirrorRepeat), + native::WGPUNativeAddressMode_ClampToBorder => Some(wgt::AddressMode::ClampToBorder), + _ => panic!("Unknown address mode"), + } +} + #[inline] pub fn map_instance_backend_flags(flags: native::WGPUInstanceBackend) -> wgt::Backends { if flags == native::WGPUInstanceBackend_All { @@ -1286,13 +1300,12 @@ pub fn features_to_native(features: wgt::Features) -> Vec Option { native::WGPUNativeFeature_MappablePrimaryBuffers => Some(Features::MAPPABLE_PRIMARY_BUFFERS), native::WGPUNativeFeature_BufferBindingArray => Some(Features::BUFFER_BINDING_ARRAY), native::WGPUNativeFeature_StorageTextureArrayNonUniformIndexing => Some(Features::STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING), - // TODO: requires wgpu.h api change - // native::WGPUNativeFeature_AddressModeClampToZero => Some(Features::ADDRESS_MODE_CLAMP_TO_ZERO), - // native::WGPUNativeFeature_AddressModeClampToBorder => Some(Features::ADDRESS_MODE_CLAMP_TO_BORDER), + native::WGPUNativeFeature_AddressModeClampToZero => Some(Features::ADDRESS_MODE_CLAMP_TO_ZERO), + native::WGPUNativeFeature_AddressModeClampToBorder => Some(Features::ADDRESS_MODE_CLAMP_TO_BORDER), native::WGPUNativeFeature_PolygonModeLine => Some(Features::POLYGON_MODE_LINE), native::WGPUNativeFeature_PolygonModePoint => Some(Features::POLYGON_MODE_POINT), native::WGPUNativeFeature_ConservativeRasterization => Some(Features::CONSERVATIVE_RASTERIZATION), @@ -2017,6 +2029,16 @@ pub fn map_primitive_state( } } +pub fn map_sampler_border_color_extras( + _descriptor: native::WGPUSamplerDescriptor, + extras: Option<&native::WGPUSamplerDescriptorExtras>, +) -> Option { + match extras { + Some(extras) => map_sampler_border_color(extras.samplerBorderColor), + None => None, + } +} + pub fn from_u64_bits>(value: u64) -> Option { if value > u32::MAX.into() { return None; diff --git a/src/lib.rs b/src/lib.rs index 7a349c62..0b8c0cd2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,8 @@ use conv::{ from_u64_bits, map_adapter_type, map_backend_type, map_bind_group_entry, map_bind_group_layout_entry, map_device_descriptor, map_instance_backend_flags, map_instance_descriptor, map_pipeline_layout_descriptor, map_query_set_descriptor, - map_query_set_index, map_shader_module, map_surface, map_surface_configuration, - CreateSurfaceParams, + map_query_set_index, map_sampler_border_color_extras, map_shader_module, map_surface, + map_surface_configuration, CreateSurfaceParams, }; use parking_lot::Mutex; use smallvec::SmallVec; @@ -2418,8 +2418,7 @@ pub unsafe extern "C" fn wgpuDeviceCreateSampler( compare: conv::map_compare_function(descriptor.compare) .expect("Invalid compare function"), anisotropy_clamp: descriptor.maxAnisotropy, - // TODO(wgpu.h) - border_color: None, + border_color: follow_chain!(map_sampler_border_color_extras((*descriptor), WGPUSType_SamplerDescriptorExtras => native::WGPUSamplerDescriptorExtras)), }, // wgpu-core doesn't have Default implementation for SamplerDescriptor, // use defaults from spec.