Skip to content
Draft
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
7 changes: 7 additions & 0 deletions lib/HLSL/HLOperationLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2590,6 +2590,13 @@ Value *ExpandDot(Value *arg0, Value *arg1, unsigned vecSize, hlsl::OP *hlslOP,

Value *TranslateFDot(Value *arg0, Value *arg1, unsigned vecSize,
hlsl::OP *hlslOP, IRBuilder<> &Builder) {
// Dot2/3/4 DXIL operations only support half and float, not double.
// For double vectors, expand the dot product using FMul and FMad.
if (arg0->getType()->getScalarType()->isDoubleTy()) {
return ExpandDot(arg0, arg1, vecSize, hlslOP, Builder,
DXIL::OpCode::FMad);
}

switch (vecSize) {
case 2:
return TrivialDotOperation(OP::OpCode::Dot2, arg0, arg1, hlslOP, Builder);
Expand Down
33 changes: 33 additions & 0 deletions tools/clang/test/HLSLFileCheck/hlsl/intrinsics/mul/mul_double.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: %dxc -T cs_6_0 -E main -DFUNC=mul -DDIM=4 %s | FileCheck %s
// RUN: %dxc -T cs_6_0 -E main -DFUNC=mul -DDIM=3 %s | FileCheck %s
// RUN: %dxc -T cs_6_0 -E main -DFUNC=mul -DDIM=2 %s | FileCheck %s
// RUN: %dxc -T cs_6_0 -E main -DFUNC=dot -DDIM=4 %s | FileCheck %s
// RUN: %dxc -T cs_6_0 -E main -DFUNC=dot -DDIM=3 %s | FileCheck %s
// RUN: %dxc -T cs_6_0 -E main -DFUNC=dot -DDIM=2 %s | FileCheck %s

// Verify that mul and dot of double vectors do not produce invalid DXIL Dot
// intrinsics (Dot2/3/4 only support half and float). Instead, the dot product
// should be expanded using FMul and FMad.
// %dxc runs validation, so the test implicitly verifies DXIL validity.

// CHECK-NOT: call double @dx.op.dot2.f64
// CHECK-NOT: call double @dx.op.dot3.f64
// CHECK-NOT: call double @dx.op.dot4.f64
// CHECK: fmul fast double
// CHECK: call double @dx.op.tertiary.f64(i32 46,

#if DIM == 4
typedef double4 DVec;
#elif DIM == 3
typedef double3 DVec;
#else
typedef double2 DVec;
#endif

RWStructuredBuffer<DVec> In;
RWStructuredBuffer<double> Out;

[numthreads(1, 1, 1)]
void main() {
Out[0] = FUNC(In[0], In[1]);
}