Skip to content

Commit

Permalink
[hlsl-out] Clean up repetition in write_mapped_math_functions.
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
jimblandy committed Feb 14, 2025
1 parent a25098f commit bafeee6
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions naga/src/back/hlsl/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,8 @@ impl<W: Write> 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
Expand All @@ -1025,7 +1027,6 @@ impl<W: Write> 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();

Expand Down Expand Up @@ -1068,7 +1069,6 @@ impl<W: Write> 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();

Expand Down Expand Up @@ -1126,12 +1126,8 @@ impl<W: Write> 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();

Expand Down

0 comments on commit bafeee6

Please sign in to comment.