diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index 88917557a8..cfdf1fe88f 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -2539,26 +2539,29 @@ impl> Parser { get_expr_handle!(arg_id, lexp) }; - let constant_handle = ctx.const_arena.fetch_or_append( + // constant expressions need to be excluded from the emitter + block.extend(emitter.finish(ctx.expressions)); + let const_value = match gl_op { + Glo::Radians => std::f64::consts::PI / 180.0, + Glo::Degrees => 180.0 / std::f64::consts::PI, + _ => unreachable!(), + }; + let const_handle = ctx.const_arena.fetch_or_append( crate::Constant { name: None, specialization: None, inner: crate::ConstantInner::Scalar { width: 4, - value: crate::ScalarValue::Float(match gl_op { - Glo::Radians => std::f64::consts::PI / 180.0, - Glo::Degrees => 180.0 / std::f64::consts::PI, - _ => unreachable!(), - }), + value: crate::ScalarValue::Float(const_value), }, }, - Default::default(), + crate::Span::default(), ); - let expr_handle = ctx.expressions.append( - crate::Expression::Constant(constant_handle), - Default::default(), + crate::Expression::Constant(const_handle), + crate::Span::default(), ); + emitter.start(ctx.expressions); self.lookup_expression.insert( result_id, diff --git a/tests/in/spv/degrees.spv b/tests/in/spv/degrees.spv new file mode 100644 index 0000000000..0e5eeab480 Binary files /dev/null and b/tests/in/spv/degrees.spv differ diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 565f326190..2d93636495 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -519,38 +519,29 @@ fn convert_spv(name: &str, adjust_coordinate_space: bool, targets: Targets) { #[cfg(feature = "spv-in")] #[test] -fn convert_spv_quad_vert() { +fn convert_spv_all() { convert_spv( "quad-vert", false, Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL, ); -} - -#[cfg(feature = "spv-in")] -#[test] -fn convert_spv_shadow() { convert_spv("shadow", true, Targets::IR | Targets::ANALYSIS); -} - -#[cfg(feature = "spv-in")] -#[test] -fn convert_spv_inverse_hyperbolic_trig_functions() { convert_spv( "inv-hyperbolic-trig-functions", true, Targets::HLSL | Targets::WGSL, ); -} - -#[cfg(feature = "spv-in")] -#[test] -fn convert_spv_empty_global_name() { convert_spv( "empty-global-name", true, Targets::HLSL | Targets::WGSL | Targets::METAL, ); + convert_spv( + "empty-global-name", + true, + Targets::HLSL | Targets::WGSL | Targets::METAL, + ); + convert_spv("degrees", false, Targets::empty()); } #[cfg(feature = "glsl-in")]