mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-01-10 06:58:12 -05:00
Expose FeaturesWGPU & FeaturesWebGPU via wgpu crate & implement From (#7086)
* move tests into conditionally compiled mod and place them at the end. add some whitespace for readability * allow creation of `Features` from `FeaturesWGPU` & `FeaturesWebGPU`
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -400,72 +400,22 @@ 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
#[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<FeatureBits> for Features {
|
||||
fn from(value: FeatureBits) -> Self {
|
||||
Self::from_bits_retain(value)
|
||||
@@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user