Skip to content

Commit 4a7b6ab

Browse files
Add F16_IN_F32 downlevel flag for pack/unpack/quantize f16 (#8130)
Although the operation of these functions is defined in terms of f16 semantics, the input/output types are not f16, and they are generally available even when native `f16` support is not. But in at least one case, they are only available with `f16` support, so add a new downlevel flag that is cleared when these functions are not available. Add some infrastructure to simplify testing of missing capabilities/extensions, and add tests for a few more kinds of f16 usage. Co-authored-by: Erich Gubler <[email protected]>
1 parent 1689c56 commit 4a7b6ab

File tree

15 files changed

+345
-109
lines changed

15 files changed

+345
-109
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ By @cwfitzgerald in [#8162](https://github.com/gfx-rs/wgpu/pull/8162).
110110
By @kpreid in [#8011](https://github.com/gfx-rs/wgpu/pull/8011).
111111
- Make a compacted hal acceleration structure inherit a label from the base BLAS. By @Vecvec in [#8103](https://github.com/gfx-rs/wgpu/pull/8103).
112112
- The limits requested for a device must now satisfy `min_subgroup_size <= max_subgroup_size`. By @andyleiserson in [#8085](https://github.com/gfx-rs/wgpu/pull/8085).
113+
- Require new `F16_IN_F32` downlevel flag for `quantizeToF16`, `pack2x16float`, and `unpack2x16float` in WGSL input. By @aleiserson in [#8130](https://github.com/gfx-rs/wgpu/pull/8130).
113114

114115
#### naga
115116

naga/src/valid/expression.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,20 @@ impl super::Validator {
10601060
arg2,
10611061
arg3,
10621062
} => {
1063+
if matches!(
1064+
fun,
1065+
crate::MathFunction::QuantizeToF16
1066+
| crate::MathFunction::Pack2x16float
1067+
| crate::MathFunction::Unpack2x16float
1068+
) && !self
1069+
.capabilities
1070+
.contains(crate::valid::Capabilities::SHADER_FLOAT16_IN_FLOAT32)
1071+
{
1072+
return Err(ExpressionError::MissingCapabilities(
1073+
crate::valid::Capabilities::SHADER_FLOAT16_IN_FLOAT32,
1074+
));
1075+
}
1076+
10631077
let actuals: &[_] = match (arg1, arg2, arg3) {
10641078
(None, None, None) => &[arg],
10651079
(Some(arg1), None, None) => &[arg, arg1],

naga/src/valid/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ bitflags::bitflags! {
170170
const SHADER_FLOAT16 = 1 << 26;
171171
/// Support for [`ImageClass::External`]
172172
const TEXTURE_EXTERNAL = 1 << 27;
173+
/// Support for `quantizeToF16`, `pack2x16float`, and `unpack2x16float`, which store
174+
/// `f16`-precision values in `f32`s.
175+
const SHADER_FLOAT16_IN_FLOAT32 = 1 << 28;
176+
}
177+
}
178+
179+
impl Capabilities {
180+
/// Returns the extension corresponding to this capability, if there is one.
181+
///
182+
/// This is used by integration tests.
183+
#[cfg(feature = "wgsl-in")]
184+
#[doc(hidden)]
185+
pub const fn extension(&self) -> Option<crate::front::wgsl::ImplementedEnableExtension> {
186+
use crate::front::wgsl::ImplementedEnableExtension as Ext;
187+
match *self {
188+
Self::DUAL_SOURCE_BLENDING => Some(Ext::DualSourceBlending),
189+
// NOTE: `SHADER_FLOAT16_IN_FLOAT32` _does not_ require the `f16` extension
190+
Self::SHADER_FLOAT16 => Some(Ext::F16),
191+
Self::CLIP_DISTANCE => Some(Ext::ClipDistances),
192+
_ => None,
193+
}
173194
}
174195
}
175196

File renamed without changes.

naga/tests/in/glsl/bits.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
god_mode = true # requires F16_IN_F32

naga/tests/in/wgsl/bits-optimized-msl.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
god_mode = true # requires F16_IN_F32
12
targets = "METAL"
23

34
[msl]

naga/tests/in/wgsl/bits.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
god_mode = true # requires F16_IN_F32
2+
13
[msl]
24
fake_missing_bindings = false
35
lang_version = [1, 2]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
god_mode = true # requires F16_IN_F32

naga/tests/naga/validation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Tests of the module validator.
2+
//!
3+
//! There are also some validation tests in [`wgsl_errors`](super::wgsl_errors).
4+
15
#![allow(
26
// We need to investigate these.
37
clippy::result_large_err

0 commit comments

Comments
 (0)