Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose FeaturesWGPU & FeaturesWebGPU via wgpu crate & implement From #7086

Merged
merged 2 commits into from
Feb 10, 2025
Merged
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
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
186 changes: 123 additions & 63 deletions wgpu-types/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,70 +400,20 @@ macro_rules! bitflags_array {
)*
)*
}
};
}

#[cfg(feature = "serde")]
#[test]
fn check_hex() {
let mut hex = alloc::string::String::new();
FeatureBits::ALL.write_hex(&mut hex).unwrap();
assert_eq!(
FeatureBits::parse_hex(hex.as_str()).unwrap(),
FeatureBits::ALL
);
hex.clear();
FeatureBits::EMPTY.write_hex(&mut hex).unwrap();
assert_eq!(
FeatureBits::parse_hex(hex.as_str()).unwrap(),
FeatureBits::EMPTY
);
for feature in Features::FLAGS {
hex.clear();
feature.value().bits().write_hex(&mut hex).unwrap();
assert_eq!(
FeatureBits::parse_hex(hex.as_str()).unwrap(),
feature.value().bits(),
"{hex}"
);
}
}

#[test]
fn check_features_display() {
use alloc::format;
let feature = Features::CLEAR_TEXTURE;
assert_eq!(format!("{}", feature), "CLEAR_TEXTURE");
let feature = Features::CLEAR_TEXTURE | Features::BGRA8UNORM_STORAGE;
assert_eq!(format!("{}", feature), "CLEAR_TEXTURE | BGRA8UNORM_STORAGE");
}

#[test]
fn check_features_bits() {
let bits = Features::all().bits();
assert_eq!(Features::from_bits_retain(bits), Features::all());
let bits = Features::empty().bits();
assert_eq!(Features::from_bits_retain(bits), Features::empty());
for feature in Features::FLAGS {
let bits = feature.value().bits();
assert_eq!(Features::from_bits_retain(bits), *feature.value());
}
let bits = Features::all().bits();
assert_eq!(Features::from_bits_truncate(bits), Features::all());
let bits = Features::empty().bits();
assert_eq!(Features::from_bits_truncate(bits), Features::empty());
for feature in Features::FLAGS {
let bits = feature.value().bits();
assert_eq!(Features::from_bits_truncate(bits), *feature.value());
}
let bits = Features::all().bits();
assert_eq!(Features::from_bits(bits).unwrap(), Features::all());
let bits = Features::empty().bits();
assert_eq!(Features::from_bits(bits).unwrap(), Features::empty());
for feature in Features::FLAGS {
let bits = feature.value().bits();
assert_eq!(Features::from_bits(bits).unwrap(), *feature.value());
}
$(
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()
}
}
}
)*
};
}
Copy link
Member Author

@Wumpf Wumpf Feb 8, 2025

Choose a reason for hiding this comment

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

only moved those down with some whitespaces, otherwise untouched


impl From<FeatureBits> for Features {
Expand Down Expand Up @@ -1357,3 +1307,113 @@ impl Features {
formats
}
}

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

#[cfg(feature = "serde")]
#[test]
fn check_hex() {
use crate::FeatureBits;

use bitflags::{
parser::{ParseHex as _, WriteHex as _},
Bits as _,
};

let mut hex = alloc::string::String::new();
FeatureBits::ALL.write_hex(&mut hex).unwrap();
assert_eq!(
FeatureBits::parse_hex(hex.as_str()).unwrap(),
FeatureBits::ALL
);

hex.clear();
FeatureBits::EMPTY.write_hex(&mut hex).unwrap();
assert_eq!(
FeatureBits::parse_hex(hex.as_str()).unwrap(),
FeatureBits::EMPTY
);

for feature in Features::FLAGS {
hex.clear();
feature.value().bits().write_hex(&mut hex).unwrap();
assert_eq!(
FeatureBits::parse_hex(hex.as_str()).unwrap(),
feature.value().bits(),
"{hex}"
);
}
}

#[test]
fn check_features_display() {
use alloc::format;

let feature = Features::CLEAR_TEXTURE;
assert_eq!(format!("{}", feature), "CLEAR_TEXTURE");

let feature = Features::CLEAR_TEXTURE | Features::BGRA8UNORM_STORAGE;
assert_eq!(format!("{}", feature), "CLEAR_TEXTURE | BGRA8UNORM_STORAGE");
}

#[test]
fn check_features_bits() {
let bits = Features::all().bits();
assert_eq!(Features::from_bits_retain(bits), Features::all());

let bits = Features::empty().bits();
assert_eq!(Features::from_bits_retain(bits), Features::empty());

for feature in Features::FLAGS {
let bits = feature.value().bits();
assert_eq!(Features::from_bits_retain(bits), *feature.value());
}

let bits = Features::all().bits();
assert_eq!(Features::from_bits_truncate(bits), Features::all());

let bits = Features::empty().bits();
assert_eq!(Features::from_bits_truncate(bits), Features::empty());

for feature in Features::FLAGS {
let bits = feature.value().bits();
assert_eq!(Features::from_bits_truncate(bits), *feature.value());
}

let bits = Features::all().bits();
assert_eq!(Features::from_bits(bits).unwrap(), Features::all());

let bits = Features::empty().bits();
assert_eq!(Features::from_bits(bits).unwrap(), Features::empty());

for feature in Features::FLAGS {
let bits = feature.value().bits();
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
)
);
}
}
3 changes: 1 addition & 2 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ pub mod instance;
pub mod math;

pub use counters::*;
pub use instance::*;

pub use features::*;
pub use instance::*;

/// Integral type used for buffer offsets.
pub type BufferAddress = u64;
Expand Down
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