mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Rustification of Extensions and SamplerDescriptor
This commit is contained in:
parent
78ab563541
commit
ade7ce10b2
@ -1003,16 +1003,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let (device_guard, mut token) = hub.devices.read(&mut token);
|
||||
let device = &device_guard[device_id];
|
||||
|
||||
if desc.anisotropy_clamp > 1 {
|
||||
if let Some(clamp) = desc.anisotropy_clamp {
|
||||
assert!(
|
||||
device.extensions.anisotropic_filtering,
|
||||
device.extensions.contains(wgt::Extensions::ANISOTROPIC_FILTERING),
|
||||
"Anisotropic clamp may only be used when the anisotropic filtering extension is enabled"
|
||||
);
|
||||
let valid_clamp = desc.anisotropy_clamp <= MAX_ANISOTROPY
|
||||
&& conv::is_power_of_two(desc.anisotropy_clamp as u32);
|
||||
let valid_clamp = clamp <= MAX_ANISOTROPY && conv::is_power_of_two(clamp as u32);
|
||||
assert!(
|
||||
valid_clamp,
|
||||
"Anisotropic clamp must be one of the values: 0, 1, 2, 4, 8, or 16"
|
||||
"Anisotropic clamp must be one of the values: 1, 2, 4, 8, or 16"
|
||||
);
|
||||
}
|
||||
|
||||
@ -1027,14 +1026,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
),
|
||||
lod_bias: hal::image::Lod(0.0),
|
||||
lod_range: hal::image::Lod(desc.lod_min_clamp)..hal::image::Lod(desc.lod_max_clamp),
|
||||
comparison: conv::map_compare_function(desc.compare),
|
||||
comparison: desc.compare.and_then(conv::map_compare_function),
|
||||
border: hal::image::PackedColor(0),
|
||||
normalized: true,
|
||||
anisotropy_clamp: if desc.anisotropy_clamp > 1 {
|
||||
Some(desc.anisotropy_clamp)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
anisotropy_clamp: desc.anisotropy_clamp,
|
||||
};
|
||||
|
||||
let sampler = resource::Sampler {
|
||||
|
||||
@ -534,9 +534,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
|
||||
let features = adapter.raw.physical_device.features();
|
||||
|
||||
wgt::Extensions {
|
||||
anisotropic_filtering: features.contains(hal::Features::SAMPLER_ANISOTROPY),
|
||||
}
|
||||
let mut extensions = wgt::Extensions::default();
|
||||
extensions.set(
|
||||
wgt::Extensions::ANISOTROPIC_FILTERING,
|
||||
features.contains(hal::Features::SAMPLER_ANISOTROPY),
|
||||
);
|
||||
extensions
|
||||
}
|
||||
|
||||
pub fn adapter_limits<B: GfxBackend>(&self, adapter_id: AdapterId) -> wgt::Limits {
|
||||
@ -601,7 +604,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
|
||||
// Check features needed by extensions
|
||||
if desc.extensions.anisotropic_filtering {
|
||||
if desc
|
||||
.extensions
|
||||
.contains(wgt::Extensions::ANISOTROPIC_FILTERING)
|
||||
{
|
||||
assert!(
|
||||
available_features.contains(hal::Features::SAMPLER_ANISOTROPY),
|
||||
"Missing feature SAMPLER_ANISOTROPY for anisotropic filtering extension"
|
||||
|
||||
@ -100,16 +100,18 @@ impl From<Backend> for BackendBit {
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
bitflags::bitflags! {
|
||||
#[repr(transparent)]
|
||||
#[derive(Default)]
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
pub struct Extensions {
|
||||
pub struct Extensions: u64 {
|
||||
/// This is a native only extension. Support is planned to be added to webgpu,
|
||||
/// but it is not yet implemented.
|
||||
///
|
||||
/// https://github.com/gpuweb/gpuweb/issues/696
|
||||
pub anisotropic_filtering: bool,
|
||||
const ANISOTROPIC_FILTERING = 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -939,7 +941,6 @@ impl Default for FilterMode {
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "trace", derive(Serialize))]
|
||||
#[cfg_attr(feature = "replay", derive(Deserialize))]
|
||||
@ -953,12 +954,12 @@ pub struct SamplerDescriptor<L> {
|
||||
pub mipmap_filter: FilterMode,
|
||||
pub lod_min_clamp: f32,
|
||||
pub lod_max_clamp: f32,
|
||||
pub compare: CompareFunction,
|
||||
pub compare: Option<CompareFunction>,
|
||||
/// Anisotropic filtering extension must be enabled if this value is
|
||||
/// anything other than 0 and 1.
|
||||
/// anything other than 0 or 1.
|
||||
///
|
||||
/// Valid values are 0, 1, 2, 4, 8, and 16.
|
||||
pub anisotropy_clamp: u8,
|
||||
/// Valid values: 1, 2, 4, 8, and 16.
|
||||
pub anisotropy_clamp: Option<u8>,
|
||||
}
|
||||
|
||||
impl<L> SamplerDescriptor<L> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user