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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 25 additions & 3 deletions ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"
{
Expand Down
60 changes: 41 additions & 19 deletions src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Comment on lines -41 to -49
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: why did this need to be converted to an explicit function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand it correctly, map_enum_with_undefined appends the native enum name (to get WGPUAddressMode_Repeat and the like), but now it has to mix enum values from two different enums (WGPUAddressMode and WGPUNativeAddressMode).

map_enum_with_undefined!(
map_filter_mode,
WGPUFilterMode,
Expand Down Expand Up @@ -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;
Expand All @@ -275,6 +277,18 @@ pub fn map_origin3d(native: &native::WGPUOrigin3D) -> wgt::Origin3d {
}
}

#[inline]
pub fn map_address_mode(mode: native::WGPUAddressMode) -> Option<wgt::AddressMode> {
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 {
Expand Down Expand Up @@ -1286,13 +1300,12 @@ pub fn features_to_native(features: wgt::Features) -> Vec<native::WGPUFeatureNam
if features.contains(wgt::Features::STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING) {
temp.push(native::WGPUNativeFeature_StorageTextureArrayNonUniformIndexing);
}
// TODO: requires wgpu.h api change
// if features.contains(wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO) {
// temp.push(native::WGPUNativeFeature_AddressModeClampToZero);
// }
// if features.contains(wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER) {
// temp.push(native::WGPUNativeFeature_AddressModeClampToBorder);
// }
if features.contains(wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO) {
temp.push(native::WGPUNativeFeature_AddressModeClampToZero);
}
if features.contains(wgt::Features::ADDRESS_MODE_CLAMP_TO_BORDER) {
temp.push(native::WGPUNativeFeature_AddressModeClampToBorder);
}
if features.contains(wgt::Features::POLYGON_MODE_LINE) {
temp.push(native::WGPUNativeFeature_PolygonModeLine);
}
Expand Down Expand Up @@ -1469,9 +1482,8 @@ pub fn map_feature(feature: native::WGPUFeatureName) -> Option<wgt::Features> {
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),
Expand Down Expand Up @@ -2017,6 +2029,16 @@ pub fn map_primitive_state(
}
}

pub fn map_sampler_border_color_extras(
_descriptor: native::WGPUSamplerDescriptor,
extras: Option<&native::WGPUSamplerDescriptorExtras>,
) -> Option<wgt::SamplerBorderColor> {
match extras {
Some(extras) => map_sampler_border_color(extras.samplerBorderColor),
None => None,
}
}

pub fn from_u64_bits<T: bitflags::Flags<Bits = u32>>(value: u64) -> Option<T> {
if value > u32::MAX.into() {
return None;
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Loading