[hlsl-out] use fmod instead of %

This commit is contained in:
teoxoy
2022-04-27 15:16:50 +02:00
committed by Dzmitry Malyshau
parent e312a7adeb
commit c584331f39
2 changed files with 22 additions and 4 deletions

View File

@@ -1795,6 +1795,24 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
self.write_expr(module, left, func_ctx)?;
write!(self.out, ")")?;
}
// While HLSL supports float operands with the % operator it is only
// defined in cases where both sides are either positive or negative.
Expression::Binary {
op: crate::BinaryOperator::Modulo,
left,
right,
} if func_ctx.info[left]
.ty
.inner_with(&module.types)
.scalar_kind()
== Some(crate::ScalarKind::Float) =>
{
write!(self.out, "fmod(")?;
self.write_expr(module, left, func_ctx)?;
write!(self.out, ", ")?;
self.write_expr(module, right, func_ctx)?;
write!(self.out, ")")?;
}
Expression::Binary { op, left, right } => {
write!(self.out, "(")?;
self.write_expr(module, left, func_ctx)?;

View File

@@ -110,10 +110,10 @@ void arithmetic()
float4 unnamed_36 = ((2.0).xxxx / (1.0).xxxx);
int unnamed_37 = (2 % 1);
uint unnamed_38 = (2u % 1u);
float unnamed_39 = (2.0 % 1.0);
float unnamed_39 = fmod(2.0, 1.0);
int2 unnamed_40 = ((2).xx % (1).xx);
uint3 unnamed_41 = ((2u).xxx % (1u).xxx);
float4 unnamed_42 = ((2.0).xxxx % (1.0).xxxx);
float4 unnamed_42 = fmod((2.0).xxxx, (1.0).xxxx);
int2 unnamed_43 = ((2).xx + (1).xx);
int2 unnamed_44 = ((2).xx + (1).xx);
uint2 unnamed_45 = ((2u).xx + (1u).xx);
@@ -142,8 +142,8 @@ void arithmetic()
int2 unnamed_68 = ((2).xx % (1).xx);
uint2 unnamed_69 = ((2u).xx % (1u).xx);
uint2 unnamed_70 = ((2u).xx % (1u).xx);
float2 unnamed_71 = ((2.0).xx % (1.0).xx);
float2 unnamed_72 = ((2.0).xx % (1.0).xx);
float2 unnamed_71 = fmod((2.0).xx, (1.0).xx);
float2 unnamed_72 = fmod((2.0).xx, (1.0).xx);
float3x3 unnamed_73 = (float3x3(float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0)) + float3x3(float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0)));
float3x3 unnamed_74 = (float3x3(float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0)) - float3x3(float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0)));
float3x3 unnamed_75 = mul(1.0, float3x3(float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0)));