Skip to content

Commit 8336578

Browse files
authored
Use a type-appropriate 2.0 for reflect (microsoft#3998)
The reflection calculation involves a multiply by two that was always float, which caused an internal assert when the variable was not float. Now the constant uses the type of the other operand
1 parent ac1683b commit 8336578

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/HLSL/HLOperationLower.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ Value *TranslateReflect(CallInst *CI, IntrinsicOp IOP, OP::OpCode op,
21472147
unsigned vecSize = VT->getNumElements();
21482148
Value *dot = TranslateFDot(i, n, vecSize, hlslOP, Builder);
21492149
// 2 * dot (i, n).
2150-
dot = Builder.CreateFMul(hlslOP->GetFloatConst(2), dot);
2150+
dot = Builder.CreateFMul(ConstantFP::get(dot->getType(), 2.0), dot);
21512151
// 2 * n * dot(i, n).
21522152
Value *vecDot = Builder.CreateVectorSplat(vecSize, dot);
21532153
Value *nMulDot = Builder.CreateFMul(vecDot, n);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %dxc -T ps_6_0 %s | FileCheck %s
2+
3+
// Ensure no validation errors
4+
// CHECK-NOT: error
5+
6+
// Ensure the reflect generated intrinsics are present
7+
// CHECK: call half @dx.op.dot3.f16
8+
// CHECK: fmul fast half {{.*}}, 0xH4000
9+
10+
11+
min16float3 main(min16float3 i : I, min16float3 n: N) : SV_Target {
12+
return reflect(i,n);
13+
}

0 commit comments

Comments
 (0)