Skip to content

Commit 51cf3d0

Browse files
ErichDonGublersharmajai
authored andcommitted
fix(naga): don't panic on f16s in pipeline constants (gfx-rs#7801)
1 parent 1bbd8ab commit 51cf3d0

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Bottom level categories:
8080
- 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).
8181
- 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).
8282
- Allow scalars as the first argument of the `distance` built-in function. By @bernhl in [#7530](https://github.com/gfx-rs/wgpu/pull/7530).
83+
- 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).
8384

8485
#### DX12
8586

@@ -128,7 +129,6 @@ Bottom level categories:
128129

129130
- Added initial `no_std` support to `wgpu-hal`. By @bushrat011899 in [#7599](https://github.com/gfx-rs/wgpu/pull/7599)
130131

131-
132132
### Documentation
133133

134134
#### General

cts_runner/test.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ webgpu:api,operation,uncapturederror:iff_uncaptured:*
2727
// There are also two unimplemented SKIPs in uncapturederror not enumerated here.
2828
webgpu:api,validation,encoding,queries,general:occlusion_query,query_type:*
2929
webgpu:shader,execution,flow_control,return:*
30+
webgpu:shader,validation,expression,call,builtin,max:values:*
3031
webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="break"
3132
webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="break_if"
3233
webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="continue"

naga/src/back/pipeline_constants.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,19 @@ fn map_value_to_literal(value: f64, scalar: Scalar) -> Result<Literal, PipelineC
945945
let value = value as u32;
946946
Ok(Literal::U32(value))
947947
}
948+
Scalar::F16 => {
949+
// https://webidl.spec.whatwg.org/#js-float
950+
if !value.is_finite() {
951+
return Err(PipelineConstantError::SrcNeedsToBeFinite);
952+
}
953+
954+
let value = half::f16::from_f64(value);
955+
if !value.is_finite() {
956+
return Err(PipelineConstantError::DstRangeTooSmall);
957+
}
958+
959+
Ok(Literal::F16(value))
960+
}
948961
Scalar::F32 => {
949962
// https://webidl.spec.whatwg.org/#js-float
950963
if !value.is_finite() {
@@ -966,7 +979,10 @@ fn map_value_to_literal(value: f64, scalar: Scalar) -> Result<Literal, PipelineC
966979

967980
Ok(Literal::F64(value))
968981
}
969-
_ => unreachable!(),
982+
Scalar::ABSTRACT_FLOAT | Scalar::ABSTRACT_INT => {
983+
unreachable!("abstract values should not be validated out of override processing")
984+
}
985+
_ => unreachable!("unrecognized scalar type for override"),
970986
}
971987
}
972988

0 commit comments

Comments
 (0)