Skip to content

Commit 0d8834c

Browse files
committed
allow creation of Features from FeaturesWGPU & FeaturesWebGPU
1 parent f06daad commit 0d8834c

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ changes from this. This means there are also namespaces (as well as the old `Fea
6363
features and webgpu feature (`FeaturesWGPU` and `FeaturesWebGPU` respectively) and `Features::from_internal_flags` which
6464
allow you to be explicit about whether features you need are available on the web too.
6565

66-
By @Vecvec in [#6905](https://github.com/gfx-rs/wgpu/pull/6905).
66+
By @Vecvec in [#6905](https://github.com/gfx-rs/wgpu/pull/6905), [#7086](https://github.com/gfx-rs/wgpu/pull/7086)
6767

6868
##### Refactored internal trace path parameter
6969

wgpu-types/src/features.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,19 @@ macro_rules! bitflags_array {
400400
)*
401401
)*
402402
}
403+
404+
$(
405+
impl From<$inner_name> for Features {
406+
// We need this for structs with only a member.
407+
#[allow(clippy::needless_update)]
408+
fn from($lower_inner_name: $inner_name) -> Self {
409+
Self {
410+
$lower_inner_name,
411+
..Self::empty()
412+
}
413+
}
414+
}
415+
)*
403416
};
404417
}
405418

@@ -1297,7 +1310,7 @@ impl Features {
12971310

12981311
#[cfg(test)]
12991312
mod tests {
1300-
use crate::Features;
1313+
use crate::{Features, FeaturesWGPU, FeaturesWebGPU};
13011314

13021315
#[cfg(feature = "serde")]
13031316
#[test]
@@ -1380,4 +1393,27 @@ mod tests {
13801393
assert_eq!(Features::from_bits(bits).unwrap(), *feature.value());
13811394
}
13821395
}
1396+
1397+
#[test]
1398+
fn create_features_from_parts() {
1399+
let features: Features = FeaturesWGPU::TEXTURE_ATOMIC.into();
1400+
assert_eq!(features, Features::TEXTURE_ATOMIC);
1401+
1402+
let features: Features = FeaturesWebGPU::TIMESTAMP_QUERY.into();
1403+
assert_eq!(features, Features::TIMESTAMP_QUERY);
1404+
1405+
let features: Features = Features::from(FeaturesWGPU::TEXTURE_ATOMIC)
1406+
| Features::from(FeaturesWebGPU::TIMESTAMP_QUERY);
1407+
assert_eq!(
1408+
features,
1409+
Features::TEXTURE_ATOMIC | Features::TIMESTAMP_QUERY
1410+
);
1411+
assert_eq!(
1412+
features,
1413+
Features::from_internal_flags(
1414+
FeaturesWGPU::TEXTURE_ATOMIC,
1415+
FeaturesWebGPU::TIMESTAMP_QUERY
1416+
)
1417+
);
1418+
}
13831419
}

wgpu/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ pub use wgt::{
6464
Color, ColorTargetState, ColorWrites, CommandBufferDescriptor, CompareFunction,
6565
CompositeAlphaMode, CopyExternalImageDestInfo, CoreCounters, DepthBiasState, DepthStencilState,
6666
DeviceLostReason, DeviceType, DownlevelCapabilities, DownlevelFlags, DownlevelLimits,
67-
Dx12BackendOptions, Dx12Compiler, DynamicOffset, Extent3d, Face, Features, FilterMode,
68-
FrontFace, GlBackendOptions, Gles3MinorVersion, HalCounters, ImageSubresourceRange,
69-
IndexFormat, InstanceDescriptor, InstanceFlags, InternalCounters, Limits, MaintainResult,
70-
MemoryHints, MultisampleState, Origin2d, Origin3d, PipelineStatisticsTypes, PolygonMode,
71-
PowerPreference, PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState,
72-
PrimitiveTopology, PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType,
73-
SamplerBorderColor, ShaderLocation, ShaderModel, ShaderRuntimeChecks, ShaderStages,
74-
StencilFaceState, StencilOperation, StencilState, StorageTextureAccess, SurfaceCapabilities,
75-
SurfaceStatus, TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat,
76-
TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, TextureTransition,
77-
TextureUsages, TextureUses, TextureViewDimension, VertexAttribute, VertexFormat,
78-
VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT,
79-
COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT,
67+
Dx12BackendOptions, Dx12Compiler, DynamicOffset, Extent3d, Face, Features, FeaturesWGPU,
68+
FeaturesWebGPU, FilterMode, FrontFace, GlBackendOptions, Gles3MinorVersion, HalCounters,
69+
ImageSubresourceRange, IndexFormat, InstanceDescriptor, InstanceFlags, InternalCounters,
70+
Limits, MaintainResult, MemoryHints, MultisampleState, Origin2d, Origin3d,
71+
PipelineStatisticsTypes, PolygonMode, PowerPreference, PredefinedColorSpace, PresentMode,
72+
PresentationTimestamp, PrimitiveState, PrimitiveTopology, PushConstantRange, QueryType,
73+
RenderBundleDepthStencil, SamplerBindingType, SamplerBorderColor, ShaderLocation, ShaderModel,
74+
ShaderRuntimeChecks, ShaderStages, StencilFaceState, StencilOperation, StencilState,
75+
StorageTextureAccess, SurfaceCapabilities, SurfaceStatus, TexelCopyBufferLayout, TextureAspect,
76+
TextureDimension, TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures,
77+
TextureSampleType, TextureTransition, TextureUsages, TextureUses, TextureViewDimension,
78+
VertexAttribute, VertexFormat, VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync,
79+
COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT,
8080
QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT,
8181
};
8282
#[expect(deprecated)]

0 commit comments

Comments
 (0)