mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-26 17:31:05 +01:00
avoid having constants pointing to other constants
This commit is contained in:
1 parent
648540999e
commit
3d346977e5
8 files changed
+130
-114
No files matched your search
@@ -543,33 +543,26 @@ fn constants() {
|
||||
}
|
||||
);
|
||||
|
||||
let (init_a_handle, init_a) = const_expressions.next().unwrap();
|
||||
assert_eq!(init_a, &Expression::Literal(crate::Literal::F32(1.0)));
|
||||
let (init_handle, init) = const_expressions.next().unwrap();
|
||||
assert_eq!(init, &Expression::Literal(crate::Literal::F32(1.0)));
|
||||
|
||||
let (constant_a_handle, constant_a) = constants.next().unwrap();
|
||||
assert_eq!(
|
||||
constant_a,
|
||||
constants.next().unwrap().1,
|
||||
&Constant {
|
||||
name: Some("a".to_owned()),
|
||||
r#override: crate::Override::None,
|
||||
ty: ty_handle,
|
||||
init: init_a_handle
|
||||
init: init_handle
|
||||
}
|
||||
);
|
||||
|
||||
// skip const expr that was inserted for `global` var
|
||||
const_expressions.next().unwrap();
|
||||
|
||||
let (init_b_handle, init_b) = const_expressions.next().unwrap();
|
||||
assert_eq!(init_b, &Expression::Constant(constant_a_handle));
|
||||
|
||||
assert_eq!(
|
||||
constants.next().unwrap().1,
|
||||
&Constant {
|
||||
name: Some("b".to_owned()),
|
||||
r#override: crate::Override::None,
|
||||
ty: ty_handle,
|
||||
init: init_b_handle
|
||||
init: init_handle
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -210,6 +210,11 @@ impl<'a> ConstantEvaluator<'a> {
|
||||
) -> Result<Handle<Expression>, ConstantEvaluatorError> {
|
||||
log::trace!("try_eval_and_append: {:?}", expr);
|
||||
match *expr {
|
||||
Expression::Constant(c) if self.function_local_data.is_none() => {
|
||||
// "See through" the constant and use its initializer.
|
||||
// This is mainly done to avoid having constants pointing to other constants.
|
||||
Ok(self.constants[c].init)
|
||||
}
|
||||
Expression::Literal(_) | Expression::ZeroValue(_) | Expression::Constant(_) => {
|
||||
Ok(self.register_evaluated_expr(expr.clone(), span))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user