Skip to content

Commit be668ce

Browse files
committed
[naga] Factor out new part of put_block on msl
CI on test failed because the latest changes to `put_block` made its stack too big. Factoring out the new code into a separate method fixes this issue.
1 parent 8813b38 commit be668ce

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

naga/src/back/msl/writer.rs

+40-25
Original file line numberDiff line numberDiff line change
@@ -3399,6 +3399,38 @@ impl<W: Write> Writer<W> {
33993399
Ok(())
34003400
}
34013401

3402+
/// Convert the arguments of `Dot4{I, U}Packed` to `packed_(u?)char4`.
3403+
///
3404+
/// Caches the results in temprary variables (whose names are derived from
3405+
/// the original variable names). This caching avoids the need to redo the
3406+
/// casting for each vector component when emitting the dot product.
3407+
fn put_casting_to_packed_chars(
3408+
&mut self,
3409+
fun: crate::MathFunction,
3410+
arg0: Handle<crate::Expression>,
3411+
arg1: Handle<crate::Expression>,
3412+
indent: back::Level,
3413+
context: &StatementContext<'_>,
3414+
) -> Result<(), Error> {
3415+
let packed_type = match fun {
3416+
crate::MathFunction::Dot4I8Packed => "packed_char4",
3417+
crate::MathFunction::Dot4U8Packed => "packed_uchar4",
3418+
_ => unreachable!(),
3419+
};
3420+
3421+
for arg in [arg0, arg1] {
3422+
write!(
3423+
self.out,
3424+
"{indent}{packed_type} {0} = as_type<{packed_type}>(",
3425+
Reinterpreted::new(packed_type, arg)
3426+
)?;
3427+
self.put_expression(arg, &context.expression, true)?;
3428+
writeln!(self.out, ");")?;
3429+
}
3430+
3431+
Ok(())
3432+
}
3433+
34023434
fn put_block(
34033435
&mut self,
34043436
level: back::Level,
@@ -3443,31 +3475,14 @@ impl<W: Write> Writer<W> {
34433475
arg,
34443476
arg1,
34453477
..
3446-
} => {
3447-
if context.expression.lang_version >= (2, 1) {
3448-
let arg1 = arg1.unwrap();
3449-
let packed_type = match fun {
3450-
Mf::Dot4I8Packed => "packed_char4",
3451-
Mf::Dot4U8Packed => "packed_uchar4",
3452-
_ => unreachable!(),
3453-
};
3454-
3455-
write!(
3456-
self.out,
3457-
"{level}{packed_type} {0} = as_type<{packed_type}>(",
3458-
Reinterpreted::new(packed_type, arg)
3459-
)?;
3460-
self.put_expression(arg, &context.expression, true)?;
3461-
writeln!(self.out, ");")?;
3462-
3463-
write!(
3464-
self.out,
3465-
"{level}{packed_type} {0} = as_type<{packed_type}>(",
3466-
Reinterpreted::new(packed_type, arg1)
3467-
)?;
3468-
self.put_expression(arg1, &context.expression, true)?;
3469-
writeln!(self.out, ");")?;
3470-
}
3478+
} if context.expression.lang_version >= (2, 1) => {
3479+
self.put_casting_to_packed_chars(
3480+
fun,
3481+
arg,
3482+
arg1.unwrap(),
3483+
level,
3484+
context,
3485+
)?;
34713486
}
34723487

34733488
_ => (),

0 commit comments

Comments
 (0)