Skip to content

Commit

Permalink
[naga hlsl-out] Use Scalar associated constants in patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy committed Feb 14, 2025
1 parent 6cf4b71 commit a25098f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
13 changes: 2 additions & 11 deletions naga/src/back/hlsl/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,7 @@ impl<W: Write> super::Writer<'_, W> {
crate::MathFunction::Abs
if matches!(
func_ctx.resolve_type(arg, &module.types).scalar(),
Some(crate::Scalar {
kind: ScalarKind::Sint,
width: 4,
})
Some(crate::Scalar::I32)
) =>
{
let arg_ty = func_ctx.resolve_type(arg, &module.types);
Expand Down Expand Up @@ -1186,13 +1183,7 @@ impl<W: Write> super::Writer<'_, W> {
};

match (op, scalar) {
(
crate::UnaryOperator::Negate,
crate::Scalar {
kind: ScalarKind::Sint,
width: 4,
},
) => {
(crate::UnaryOperator::Negate, crate::Scalar::I32) => {
if !self.wrapped.unary_op.insert(wrapped) {
continue;
}
Expand Down
27 changes: 5 additions & 22 deletions naga/src/back/hlsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2775,10 +2775,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
right,
} if matches!(
func_ctx.resolve_type(expr, &module.types).scalar(),
Some(Scalar {
kind: ScalarKind::Sint,
width: 4
})
Some(Scalar::I32)
) =>
{
write!(self.out, "asint(asuint(",)?;
Expand Down Expand Up @@ -3338,10 +3335,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
let op_str = match op {
crate::UnaryOperator::Negate => {
match func_ctx.resolve_type(expr, &module.types).scalar() {
Some(Scalar {
kind: ScalarKind::Sint,
width: 4,
}) => NEG_FUNCTION,
Some(Scalar::I32) => NEG_FUNCTION,
_ => "-",
}
}
Expand Down Expand Up @@ -3444,10 +3438,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
let fun = match fun {
// comparison
Mf::Abs => match func_ctx.resolve_type(arg, &module.types).scalar() {
Some(Scalar {
kind: ScalarKind::Sint,
width: 4,
}) => Function::Regular(ABS_FUNCTION),
Some(Scalar::I32) => Function::Regular(ABS_FUNCTION),
_ => Function::Regular("abs"),
},
Mf::Min => Function::Regular("min"),
Expand Down Expand Up @@ -3735,11 +3726,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
// as non-32bit types are DXC only.
Function::MissingIntOverload(fun_name) => {
let scalar_kind = func_ctx.resolve_type(arg, &module.types).scalar();
if let Some(Scalar {
kind: ScalarKind::Sint,
width: 4,
}) = scalar_kind
{
if let Some(Scalar::I32) = scalar_kind {
write!(self.out, "asint({fun_name}(asuint(")?;
self.write_expr(module, arg, func_ctx)?;
write!(self.out, ")))")?;
Expand All @@ -3753,11 +3740,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
// as non-32bit types are DXC only.
Function::MissingIntReturnType(fun_name) => {
let scalar_kind = func_ctx.resolve_type(arg, &module.types).scalar();
if let Some(Scalar {
kind: ScalarKind::Sint,
width: 4,
}) = scalar_kind
{
if let Some(Scalar::I32) = scalar_kind {
write!(self.out, "asint({fun_name}(")?;
self.write_expr(module, arg, func_ctx)?;
write!(self.out, "))")?;
Expand Down

0 comments on commit a25098f

Please sign in to comment.