Skip to content

Commit 73f9d14

Browse files
committed
Require new F16_IN_F32 capability for pack/unpack/quantize f16
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 capability that decides whether these functions are available. Add some infrastructure to simplify testing of missing capabilities/extensions, and add tests for a few more kinds of f16 usage.
1 parent 167ff7b commit 73f9d14

File tree

16 files changed

+342
-113
lines changed

16 files changed

+342
-113
lines changed

naga/src/front/wgsl/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ mod parse;
1111
#[cfg(test)]
1212
mod tests;
1313

14+
pub use parse::directive::enable_extension::{EnableExtension, ImplementedEnableExtension};
15+
1416
pub use crate::front::wgsl::error::ParseError;
1517
pub use crate::front::wgsl::parse::directive::language_extension::{
1618
ImplementedLanguageExtension, LanguageExtension, UnimplementedLanguageExtension,

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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ 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,
174+
/// which store `f16`-precision values in `f32`s.
175+
const SHADER_FLOAT16_IN_FLOAT32 = 1 << 28;
176+
}
177+
}
178+
179+
impl Capabilities {
180+
/// Returns the `ImplementedEnableExtension` corresponding to this capability, if there is one.
181+
pub const fn extension(&self) -> Option<crate::front::wgsl::ImplementedEnableExtension> {
182+
use crate::front::wgsl::ImplementedEnableExtension as Ext;
183+
match *self {
184+
Self::DUAL_SOURCE_BLENDING => Some(Ext::DualSourceBlending),
185+
Self::SHADER_FLOAT16 => Some(Ext::F16),
186+
// SHADER_FLOAT16_IN_FLOAT32 _does not_ require the `f16` extension
187+
Self::CLIP_DISTANCE => Some(Ext::ClipDistances),
188+
_ => None,
189+
}
173190
}
174191
}
175192

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 # TODO: replace with finer `F16_IN_F32` capability

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
//! Tests of the module validator.
2+
//!
3+
//! There are also some validation tests in `wgsl_errors`.
4+
15
#![allow(
2-
// We need to investiagate these.
6+
// We need to investigate these.
37
clippy::result_large_err
48
)]
59

0 commit comments

Comments
 (0)