Skip to content

Commit

Permalink
Split Blendability and Filterability into Two Different TextureFormat…
Browse files Browse the repository at this point in the history
…FeatureFlags (#3012)

* Split Blendability and Filterability into Two Different TextureFormatFeatureFlags

* Update CHANGELOG.md

* Split out individual booleans to improve readability

* Make sure blendablity is correctly set for guaranteed format features of WebGPU

* Cargo fmt

Co-authored-by: Xander Warnez <xander.warnez@materialise.be>
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
  • Loading branch information
3 people committed Sep 21, 2022
1 parent 061e04b commit 2c1d7a8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -72,6 +72,7 @@ SurfaceConfiguration {
### Added/New Features

- Add `Buffer::size()` and `Buffer::usage()`; by @kpreid in [#2923](https://github.com/gfx-rs/wgpu/pull/2923)
- Split Blendability and Filterability into Two Different TextureFormatFeatureFlags; by @stakka in [#3012](https://github.com/gfx-rs/wgpu/pull/3012)
- Expose `alpha_mode` on SurfaceConfiguration, by @jinleili in [#2836](https://github.com/gfx-rs/wgpu/pull/2836)
- Introduce fields for driver name and info in `AdapterInfo`, by @i509VCB in [#3037](https://github.com/gfx-rs/wgpu/pull/3037)

Expand Down
9 changes: 8 additions & 1 deletion wgpu-core/src/device/mod.rs
Expand Up @@ -2625,7 +2625,14 @@ impl<A: HalApi> Device<A> {
{
break Some(pipeline::ColorStateError::FormatNotRenderable(cs.format));
}
if cs.blend.is_some() && !format_features.flags.contains(Tfff::FILTERABLE) {
let blendable = format_features.flags.contains(Tfff::BLENDABLE);
let filterable = format_features.flags.contains(Tfff::FILTERABLE);
let adapter_specific = self
.features
.contains(wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES);
// according to WebGPU specifications the texture needs to be [`TextureFormatFeatureFlags::FILTERABLE`]
// if blending is set - use [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] to elude this limitation
if cs.blend.is_some() && (!blendable || (!filterable && !adapter_specific)) {
break Some(pipeline::ColorStateError::FormatNotBlendable(cs.format));
}
if !hal::FormatAspects::from(cs.format).contains(hal::FormatAspects::COLOR) {
Expand Down
12 changes: 6 additions & 6 deletions wgpu-core/src/instance.rs
Expand Up @@ -249,14 +249,14 @@ impl<A: HalApi> Adapter<A> {
caps.contains(Tfc::STORAGE_READ_WRITE),
);

// We are currently taking the filtering and blending together,
// but we may reconsider this in the future if there are formats
// in the wild for which these two capabilities do not match.
flags.set(
wgt::TextureFormatFeatureFlags::FILTERABLE,
caps.contains(Tfc::SAMPLED_LINEAR)
&& (!caps.contains(Tfc::COLOR_ATTACHMENT)
|| caps.contains(Tfc::COLOR_ATTACHMENT_BLEND)),
caps.contains(Tfc::SAMPLED_LINEAR),
);

flags.set(
wgt::TextureFormatFeatureFlags::BLENDABLE,
caps.contains(Tfc::COLOR_ATTACHMENT_BLEND),
);

flags.set(
Expand Down
6 changes: 5 additions & 1 deletion wgpu-types/src/lib.rs
Expand Up @@ -1662,6 +1662,8 @@ bitflags::bitflags! {
/// When used as a STORAGE texture, then a texture with this format can be written to with atomics.
// TODO: No access flag exposed as of writing
const STORAGE_ATOMICS = 1 << 4;
/// If not present, the texture can't be blended into the render target.
const BLENDABLE = 1 << 5;
}
}

Expand Down Expand Up @@ -2288,10 +2290,12 @@ impl TextureFormat {
};

let mut flags = msaa_flags;
let filterable_sample_type = sample_type == TextureSampleType::Float { filterable: true };
flags.set(
TextureFormatFeatureFlags::FILTERABLE,
sample_type == TextureSampleType::Float { filterable: true },
filterable_sample_type,
);
flags.set(TextureFormatFeatureFlags::BLENDABLE, filterable_sample_type);

TextureFormatInfo {
required_features,
Expand Down

0 comments on commit 2c1d7a8

Please sign in to comment.