Skip to content

Commit

Permalink
allow creation of Features from FeaturesWGPU & FeaturesWebGPU
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Feb 8, 2025
1 parent f06daad commit 0d8834c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 37 additions & 1 deletion wgpu-types/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
)*
};
}

Expand Down Expand Up @@ -1297,7 +1310,7 @@ impl Features {

#[cfg(test)]
mod tests {
use crate::Features;
use crate::{Features, FeaturesWGPU, FeaturesWebGPU};

#[cfg(feature = "serde")]
#[test]
Expand Down Expand Up @@ -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
)
);
}
}
26 changes: 13 additions & 13 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 0d8834c

Please sign in to comment.