spv-in: fix support for degrees and radians conversion

This commit is contained in:
Ashley
2021-11-09 17:53:55 +01:00
committed by Dzmitry Malyshau
parent d13e9e3b83
commit 75ce45d4f3
3 changed files with 20 additions and 26 deletions

View File

@@ -2539,26 +2539,29 @@ impl<I: Iterator<Item = u32>> Parser<I> {
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,

BIN
tests/in/spv/degrees.spv Normal file

Binary file not shown.

View File

@@ -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")]