Skip to content

Commit 2c1d7a8

Browse files
stakkamatxwarnezcwfitzgerald
authored
Split Blendability and Filterability into Two Different TextureFormatFeatureFlags (#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>
1 parent 061e04b commit 2c1d7a8

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ SurfaceConfiguration {
7272
### Added/New Features
7373

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

wgpu-core/src/device/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,14 @@ impl<A: HalApi> Device<A> {
26252625
{
26262626
break Some(pipeline::ColorStateError::FormatNotRenderable(cs.format));
26272627
}
2628-
if cs.blend.is_some() && !format_features.flags.contains(Tfff::FILTERABLE) {
2628+
let blendable = format_features.flags.contains(Tfff::BLENDABLE);
2629+
let filterable = format_features.flags.contains(Tfff::FILTERABLE);
2630+
let adapter_specific = self
2631+
.features
2632+
.contains(wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES);
2633+
// according to WebGPU specifications the texture needs to be [`TextureFormatFeatureFlags::FILTERABLE`]
2634+
// if blending is set - use [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] to elude this limitation
2635+
if cs.blend.is_some() && (!blendable || (!filterable && !adapter_specific)) {
26292636
break Some(pipeline::ColorStateError::FormatNotBlendable(cs.format));
26302637
}
26312638
if !hal::FormatAspects::from(cs.format).contains(hal::FormatAspects::COLOR) {

wgpu-core/src/instance.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,14 @@ impl<A: HalApi> Adapter<A> {
249249
caps.contains(Tfc::STORAGE_READ_WRITE),
250250
);
251251

252-
// We are currently taking the filtering and blending together,
253-
// but we may reconsider this in the future if there are formats
254-
// in the wild for which these two capabilities do not match.
255252
flags.set(
256253
wgt::TextureFormatFeatureFlags::FILTERABLE,
257-
caps.contains(Tfc::SAMPLED_LINEAR)
258-
&& (!caps.contains(Tfc::COLOR_ATTACHMENT)
259-
|| caps.contains(Tfc::COLOR_ATTACHMENT_BLEND)),
254+
caps.contains(Tfc::SAMPLED_LINEAR),
255+
);
256+
257+
flags.set(
258+
wgt::TextureFormatFeatureFlags::BLENDABLE,
259+
caps.contains(Tfc::COLOR_ATTACHMENT_BLEND),
260260
);
261261

262262
flags.set(

wgpu-types/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,8 @@ bitflags::bitflags! {
16621662
/// When used as a STORAGE texture, then a texture with this format can be written to with atomics.
16631663
// TODO: No access flag exposed as of writing
16641664
const STORAGE_ATOMICS = 1 << 4;
1665+
/// If not present, the texture can't be blended into the render target.
1666+
const BLENDABLE = 1 << 5;
16651667
}
16661668
}
16671669

@@ -2288,10 +2290,12 @@ impl TextureFormat {
22882290
};
22892291

22902292
let mut flags = msaa_flags;
2293+
let filterable_sample_type = sample_type == TextureSampleType::Float { filterable: true };
22912294
flags.set(
22922295
TextureFormatFeatureFlags::FILTERABLE,
2293-
sample_type == TextureSampleType::Float { filterable: true },
2296+
filterable_sample_type,
22942297
);
2298+
flags.set(TextureFormatFeatureFlags::BLENDABLE, filterable_sample_type);
22952299

22962300
TextureFormatInfo {
22972301
required_features,

0 commit comments

Comments
 (0)