From 4c97e161e4513356e39e9034f8eabc94486cc98f Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 13 Jun 2025 14:10:58 +0900 Subject: [PATCH 1/2] fix(naga): don't panic on `f16`s in pipeline constants --- CHANGELOG.md | 2 +- cts_runner/test.lst | 1 + naga/src/back/pipeline_constants.rs | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca26ae282f..68a45a5ffc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ Bottom level categories: - Generate vectorized code for `[un]pack4x{I,U}8[Clamp]` on SPIR-V and MSL 2.1+. By @robamler in [#7664](https://github.com/gfx-rs/wgpu/pull/7664). - Fix typing for `select`, which had issues particularly with a lack of automatic type conversion. By @ErichDonGubler in [#7572](https://github.com/gfx-rs/wgpu/pull/7572). - Allow scalars as the first argument of the `distance` built-in function. By @bernhl in [#7530](https://github.com/gfx-rs/wgpu/pull/7530). +- Don't panic when handling `f16` for pipeline constants, i.e., `override`s in WGSL. By @ErichDonGubler in [#7801](https://github.com/gfx-rs/wgpu/pull/7801). #### DX12 @@ -128,7 +129,6 @@ Bottom level categories: - Added initial `no_std` support to `wgpu-hal`. By @bushrat011899 in [#7599](https://github.com/gfx-rs/wgpu/pull/7599) - ### Documentation #### General diff --git a/cts_runner/test.lst b/cts_runner/test.lst index 947f8e3b33..1dfe9f431a 100644 --- a/cts_runner/test.lst +++ b/cts_runner/test.lst @@ -27,6 +27,7 @@ webgpu:api,operation,uncapturederror:iff_uncaptured:* // There are also two unimplemented SKIPs in uncapturederror not enumerated here. webgpu:api,validation,encoding,queries,general:occlusion_query,query_type:* webgpu:shader,execution,flow_control,return:* +webgpu:shader,validation,expression,call,builtin,max:values:* webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="break" webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="break_if" webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="continue" diff --git a/naga/src/back/pipeline_constants.rs b/naga/src/back/pipeline_constants.rs index d2c60d1487..a3e827f091 100644 --- a/naga/src/back/pipeline_constants.rs +++ b/naga/src/back/pipeline_constants.rs @@ -945,6 +945,19 @@ fn map_value_to_literal(value: f64, scalar: Scalar) -> Result { + // https://webidl.spec.whatwg.org/#js-float + if !value.is_finite() { + return Err(PipelineConstantError::SrcNeedsToBeFinite); + } + + let value = half::f16::from_f64(value); + if !value.is_finite() { + return Err(PipelineConstantError::DstRangeTooSmall); + } + + Ok(Literal::F16(value)) + } Scalar::F32 => { // https://webidl.spec.whatwg.org/#js-float if !value.is_finite() { From 2c9e80cb8492d3a0c7b69aaf424ac4b71e65a829 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 13 Jun 2025 14:10:58 +0900 Subject: [PATCH 2/2] refactor(naga): improve diags. for unexpected scalars in `pipeline_constants::map_value_to_literal` --- naga/src/back/pipeline_constants.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/naga/src/back/pipeline_constants.rs b/naga/src/back/pipeline_constants.rs index a3e827f091..afa0db1112 100644 --- a/naga/src/back/pipeline_constants.rs +++ b/naga/src/back/pipeline_constants.rs @@ -979,7 +979,10 @@ fn map_value_to_literal(value: f64, scalar: Scalar) -> Result unreachable!(), + Scalar::ABSTRACT_FLOAT | Scalar::ABSTRACT_INT => { + unreachable!("abstract values should not be validated out of override processing") + } + _ => unreachable!("unrecognized scalar type for override"), } }