From 75ce45d4f3108b256ae96069c87586c59fada839 Mon Sep 17 00:00:00 2001 From: Ashley Date: Tue, 9 Nov 2021 17:53:55 +0100 Subject: [PATCH] spv-in: fix support for degrees and radians conversion --- src/front/spv/mod.rs | 23 +++++++++++++---------- tests/in/spv/degrees.spv | Bin 0 -> 676 bytes tests/snapshots.rs | 23 +++++++---------------- 3 files changed, 20 insertions(+), 26 deletions(-) create mode 100644 tests/in/spv/degrees.spv 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 0000000000000000000000000000000000000000..0e5eeab4801959135ed79998e86f119fe85e56dc GIT binary patch literal 676 zcmYk3%}N775QNL!tVRIyxB;rvB9#jNT@svvr5g$MnSAw8MqTYQrpUR71eX~1| z36<`yuAc6mO_QS)X-R9UYhUH*C@~{7v>fbcd_Nw3d=|sgvlA38r9p_MZ4IYpyynku z_?t%RUt;@XQReJoK69?_T=6t@E_H8do)`8rt(W{mJ}ob!mir!OFSDmU;AO;(a~) z()Z1|cVHgw;-L98li6|?v#>ih#_Ycs^9ID%u13qOSFWXJ!+>i#B5oRd2Y5gY_rb@S zmi>||Yub*fK|_ujdcwz=u6?+PyRh%J0T*%Sjp*O6ayE+GPQ}q9a=R7B+f2M2Z@Xtu SkDfel$Sk}yxj#>NVf+KmpC3H{ literal 0 HcmV?d00001 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")]