Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ line upon naming the release. Refer to previous for appropriate section names.

- Fixed an optimizer crash when scalarizing an out-of-bounds vector access
[#8940](https://github.com/microsoft/DirectXShaderCompiler/issues/8940).
- Fixed constant folding of `frac` returning `abs(x - trunc(x))` instead of
`x - floor(x)` for negative values, such as matrix arguments
[#8937](https://github.com/microsoft/DirectXShaderCompiler/issues/8937).

### Upcoming Preview Release

Expand Down
7 changes: 3 additions & 4 deletions lib/Analysis/DxilConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,9 @@ static Constant *ConstantFoldUnaryFPIntrinsic(OP::OpCode opcode, Type *Ty,
case OP::OpCode::Exp:
return DxilConstantFoldFP(exp2, Op, Ty);
case OP::OpCode::Frc: {
NativeFPUnaryOp f = [](double x) {
double unused;
return fabs(modf(x, &unused));
};
// frac(x) = x - floor(x), so negative inputs also give a result in
// [+0, 1), the same as the front end's folding of the frac intrinsic
NativeFPUnaryOp f = [](double x) { return x - floor(x); };
return DxilConstantFoldFP(f, Op, Ty);
}
case OP::OpCode::Log:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ void main() {
f4buf[2] = float4(fmat_splat[0][0], fmat_splat[0][1], fmat_splat[1][0], fmat_splat[1][1]) ;

// matrix non-splat
// CHECK: float 0x3F2A400000000000, float 0x3F53A92A40000000, float 0x3FCD710000000000, float 0.000000e+00
// CHECK: float 0x3FEFFE5C00000000, float 0x3FEFF62B60000000, float 0x3FCD710000000000, float 0.000000e+00
float2x2 fmat = { -21.0002, -0.0012, 421.23, 1 };
fmat = frac(fmat);
f4buf[3] = float4(fmat[0][0], fmat[0][1], fmat[1][0], fmat[1][1]) ;

// matrix with negative values: frac(x) = x - floor(x)
// CHECK: float 2.500000e-01, float 7.500000e-01, float 7.500000e-01, float 2.500000e-01
float2x2 fmat_neg = frac(float2x2(-1.75, -0.25, 0.75, 1.25));
f4buf[4] = float4(fmat_neg[0][0], fmat_neg[0][1], fmat_neg[1][0], fmat_neg[1][1]);
}
Loading