From 0d8834c8a43fe53110b9f6d291d598815ad90b95 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sat, 8 Feb 2025 17:42:44 +0100 Subject: [PATCH] allow creation of `Features` from `FeaturesWGPU` & `FeaturesWebGPU` --- CHANGELOG.md | 2 +- wgpu-types/src/features.rs | 38 +++++++++++++++++++++++++++++++++++++- wgpu/src/lib.rs | 26 +++++++++++++------------- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de6a9cc352..f0eb50318d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,7 +63,7 @@ changes from this. This means there are also namespaces (as well as the old `Fea features and webgpu feature (`FeaturesWGPU` and `FeaturesWebGPU` respectively) and `Features::from_internal_flags` which allow you to be explicit about whether features you need are available on the web too. -By @Vecvec in [#6905](https://github.com/gfx-rs/wgpu/pull/6905). +By @Vecvec in [#6905](https://github.com/gfx-rs/wgpu/pull/6905), [#7086](https://github.com/gfx-rs/wgpu/pull/7086) ##### Refactored internal trace path parameter diff --git a/wgpu-types/src/features.rs b/wgpu-types/src/features.rs index 66b1bfbe4a..004eba863c 100644 --- a/wgpu-types/src/features.rs +++ b/wgpu-types/src/features.rs @@ -400,6 +400,19 @@ macro_rules! bitflags_array { )* )* } + + $( + impl From<$inner_name> for Features { + // We need this for structs with only a member. + #[allow(clippy::needless_update)] + fn from($lower_inner_name: $inner_name) -> Self { + Self { + $lower_inner_name, + ..Self::empty() + } + } + } + )* }; } @@ -1297,7 +1310,7 @@ impl Features { #[cfg(test)] mod tests { - use crate::Features; + use crate::{Features, FeaturesWGPU, FeaturesWebGPU}; #[cfg(feature = "serde")] #[test] @@ -1380,4 +1393,27 @@ mod tests { assert_eq!(Features::from_bits(bits).unwrap(), *feature.value()); } } + + #[test] + fn create_features_from_parts() { + let features: Features = FeaturesWGPU::TEXTURE_ATOMIC.into(); + assert_eq!(features, Features::TEXTURE_ATOMIC); + + let features: Features = FeaturesWebGPU::TIMESTAMP_QUERY.into(); + assert_eq!(features, Features::TIMESTAMP_QUERY); + + let features: Features = Features::from(FeaturesWGPU::TEXTURE_ATOMIC) + | Features::from(FeaturesWebGPU::TIMESTAMP_QUERY); + assert_eq!( + features, + Features::TEXTURE_ATOMIC | Features::TIMESTAMP_QUERY + ); + assert_eq!( + features, + Features::from_internal_flags( + FeaturesWGPU::TEXTURE_ATOMIC, + FeaturesWebGPU::TIMESTAMP_QUERY + ) + ); + } } diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 29cf6fe163..cdfa2bbb1d 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -64,19 +64,19 @@ pub use wgt::{ Color, ColorTargetState, ColorWrites, CommandBufferDescriptor, CompareFunction, CompositeAlphaMode, CopyExternalImageDestInfo, CoreCounters, DepthBiasState, DepthStencilState, DeviceLostReason, DeviceType, DownlevelCapabilities, DownlevelFlags, DownlevelLimits, - Dx12BackendOptions, Dx12Compiler, DynamicOffset, Extent3d, Face, Features, FilterMode, - FrontFace, GlBackendOptions, Gles3MinorVersion, HalCounters, ImageSubresourceRange, - IndexFormat, InstanceDescriptor, InstanceFlags, InternalCounters, Limits, MaintainResult, - MemoryHints, MultisampleState, Origin2d, Origin3d, PipelineStatisticsTypes, PolygonMode, - PowerPreference, PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState, - PrimitiveTopology, PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType, - SamplerBorderColor, ShaderLocation, ShaderModel, ShaderRuntimeChecks, ShaderStages, - StencilFaceState, StencilOperation, StencilState, StorageTextureAccess, SurfaceCapabilities, - SurfaceStatus, TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat, - TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, TextureTransition, - TextureUsages, TextureUses, TextureViewDimension, VertexAttribute, VertexFormat, - VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT, - COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, + Dx12BackendOptions, Dx12Compiler, DynamicOffset, Extent3d, Face, Features, FeaturesWGPU, + FeaturesWebGPU, FilterMode, FrontFace, GlBackendOptions, Gles3MinorVersion, HalCounters, + ImageSubresourceRange, IndexFormat, InstanceDescriptor, InstanceFlags, InternalCounters, + Limits, MaintainResult, MemoryHints, MultisampleState, Origin2d, Origin3d, + PipelineStatisticsTypes, PolygonMode, PowerPreference, PredefinedColorSpace, PresentMode, + PresentationTimestamp, PrimitiveState, PrimitiveTopology, PushConstantRange, QueryType, + RenderBundleDepthStencil, SamplerBindingType, SamplerBorderColor, ShaderLocation, ShaderModel, + ShaderRuntimeChecks, ShaderStages, StencilFaceState, StencilOperation, StencilState, + StorageTextureAccess, SurfaceCapabilities, SurfaceStatus, TexelCopyBufferLayout, TextureAspect, + TextureDimension, TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, + TextureSampleType, TextureTransition, TextureUsages, TextureUses, TextureViewDimension, + VertexAttribute, VertexFormat, VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, + COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, }; #[expect(deprecated)]