mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
[naga] Add new function, GuardedIndex::from_expression
.
Pull out the code to build a `naga::proc::index::GuardedIndex` from a `Handle<Expression>` into its own function, `GuardedIndex::from_expression`. Use that function in `GuardedIndex::try_resolve_to_constant`.
This commit is contained in:
parent
0392613b5a
commit
0f17ad6455
@ -340,12 +340,21 @@ impl GuardedIndex {
|
||||
module: &crate::Module,
|
||||
) {
|
||||
if let GuardedIndex::Expression(expr) = *self {
|
||||
if let Ok(value) = module
|
||||
.to_ctx()
|
||||
.eval_expr_to_u32_from(expr, &function.expressions)
|
||||
{
|
||||
*self = GuardedIndex::Known(value);
|
||||
}
|
||||
*self = GuardedIndex::from_expression(expr, function, module);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_expression(
|
||||
expr: Handle<crate::Expression>,
|
||||
function: &crate::Function,
|
||||
module: &crate::Module,
|
||||
) -> Self {
|
||||
match module
|
||||
.to_ctx()
|
||||
.eval_expr_to_u32_from(expr, &function.expressions)
|
||||
{
|
||||
Ok(value) => Self::Known(value),
|
||||
Err(_) => Self::Expression(expr),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user