Expand double vector dot products to FMul/FMad instead of emitting invalid Dot2/3/4 intrinsics#8
Expand double vector dot products to FMul/FMad instead of emitting invalid Dot2/3/4 intrinsics#8
Conversation
The Dot2/3/4 DXIL operations only support half and float (overload bitmask 0x3), not double. When mul(double_vector, double_vector) was called, TranslateFDot would generate an invalid dx.op.dot4.f64 call. Fix: In TranslateFDot, detect double type and expand the dot product using FMul and FMad (which supports double) via ExpandDot, instead of using the unsupported Dot2/3/4 intrinsics. Co-authored-by: damyanp <8118402+damyanp@users.noreply.github.com>
damyanp
left a comment
There was a problem hiding this comment.
Also fixes dot() and normalize() with double vectors, since they share the same TranslateFDot codepath.
Make sure that the tests you add actually cover all the things you think you've changed.
Please confirm for me that these tests fail without your changes, and that you have a test that exercises the actual reported problem. Reported issue was that validation failed, so we need a test that validation succeeds.
Add dot() test cases alongside mul() for double2/3/4 vectors since both share the TranslateFDot codepath. Both fail validation without the fix and pass with it. The %dxc RUN lines implicitly validate DXIL since dxc runs the validator by default. Co-authored-by: damyanp <8118402+damyanp@users.noreply.github.com>
Updated the test in 45f72a9 to cover both I confirmed both functions fail validation without the fix: And all 6 configurations pass with the fix. The Regarding |
mul(double_vector, double_vector)anddot(double_vector, double_vector)emitdx.op.dot{2,3,4}.f64which fails DXIL validation — Dot2/3/4 only support half and float (overload mask0x3), not double.Changes
lib/HLSL/HLOperationLower.cpp: Early-out inTranslateFDotfor double types, routing toExpandDotwithFMad(which supports f64) instead of the unsupported Dot intrinsics. This mirrors the existing integer path which already usesExpandDotfor the same reason.tools/clang/test/HLSLFileCheck/hlsl/intrinsics/mul/mul_double.hlsl: Test coverage for bothmulanddotwithdouble2,double3, anddouble4(6 RUN configurations), asserting nodot*.f64calls and verifyingfmul+tertiary.f64(FMad) expansion. Since%dxcruns the validator by default, the test implicitly verifies DXIL validity.Also fixes
dot()with double vectors, since it shares the sameTranslateFDotcodepath.Original prompt
mulbetween two double vectors produces invalid DXIL microsoft/DirectXShaderCompiler#8208💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.