From e904d2bfd62795f40e093b733ef910fb70e5af4a Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Mon, 7 Feb 2022 14:10:28 -0800 Subject: [PATCH] [msl-out] Document why dot operator on ints requires baking. --- src/back/msl/writer.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/back/msl/writer.rs b/src/back/msl/writer.rs index acf787f40b..d0dea3ef17 100644 --- a/src/back/msl/writer.rs +++ b/src/back/msl/writer.rs @@ -1856,8 +1856,12 @@ impl Writer { if min_ref_count <= expr_info.ref_count { self.need_bake_expressions.insert(expr.0); } - // if the expression is a Dot product with integer arguments, - // then the args needs baking as well + + // WGSL's `dot` function works on any `vecN` type, but Metal's only + // works on floating-point vectors, so we emit inline code for + // integer vector `dot` calls. But that code uses each argument `N` + // times, once for each component (see `put_dot_product`), so to + // avoid duplicated evaluation, we must bake integer operands. if let ( fun_handle, &Expression::Math {