From bafeee6680abc7a24fc598965ac4dd031091a8a1 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Wed, 12 Feb 2025 11:10:24 -0800 Subject: [PATCH] [hlsl-out] Clean up repetition in `write_mapped_math_functions`. Since every `match` arm ends up looking up the type of the operation's first argument, just do that once. This avoids a repetitive lookup for `Abs`. --- naga/src/back/hlsl/help.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/naga/src/back/hlsl/help.rs b/naga/src/back/hlsl/help.rs index bb3235945f..a035ec7ab0 100644 --- a/naga/src/back/hlsl/help.rs +++ b/naga/src/back/hlsl/help.rs @@ -1011,6 +1011,8 @@ impl super::Writer<'_, W> { arg3: _arg3, } = *expression { + let arg_ty = func_ctx.resolve_type(arg, &module.types); + match fun { crate::MathFunction::ExtractBits => { // The behavior of our extractBits polyfill is undefined if offset + count > bit_width. We need @@ -1025,7 +1027,6 @@ impl super::Writer<'_, W> { // c = min(count, w - o) // // bitfieldExtract(x, o, c) - let arg_ty = func_ctx.resolve_type(arg, &module.types); let scalar = arg_ty.scalar().unwrap(); let components = arg_ty.components(); @@ -1068,7 +1069,6 @@ impl super::Writer<'_, W> { crate::MathFunction::InsertBits => { // The behavior of our insertBits polyfill has the same constraints as the extractBits polyfill. - let arg_ty = func_ctx.resolve_type(arg, &module.types); let scalar = arg_ty.scalar().unwrap(); let components = arg_ty.components(); @@ -1126,12 +1126,8 @@ impl super::Writer<'_, W> { writeln!(self.out, "}}")?; } crate::MathFunction::Abs - if matches!( - func_ctx.resolve_type(arg, &module.types).scalar(), - Some(crate::Scalar::I32) - ) => + if matches!(arg_ty.scalar(), Some(crate::Scalar::I32)) => { - let arg_ty = func_ctx.resolve_type(arg, &module.types); let scalar = arg_ty.scalar().unwrap(); let components = arg_ty.components();