Repository: microsoft/DirectXShaderCompiler (2026-04-07T20:19:43Z)

Issue:
[sm6.10] coopvec input vec type convert
**Description**
There is a simple convert from f16 to fp8 for input vec, however, the dxil looks incorrect.
hlsl:
typedef vector<half, 16> half16;
half16 srcF16 = inbuf.Load<half16>(0);
InterpretedVector<uint, 4, ComponentEnum::F8_E4M3FN> converted =
      Convert<ComponentEnum::F8_E4M3FN, ComponentEnum::F16>(srcF16);

dxil:
  %4 = call %dx.types.ResRet.v16f16 @dx.op.rawBufferVectorLoad.v16f16(i32 303, %dx.types.Handle %3, i32 0, i32 undef, i32 2)  ; RawBufferVectorLoad(buf,index,elementOffset,alignment)
  %5 = extractvalue %dx.types.ResRet.v16f16 %4, 0
  %6 = shufflevector <16 x half> %5, <16 x half> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  %7 = call <4 x i32> @dx.op.linAlgConvert.v4i32.v4f16(i32 -2147483618, **<4 x half> %6**, i32 8, i32 21)  ; LinAlgConvert(**inputVector**,inputInterpretation,outputInterpretation)

we expected <16 x half> %5 as the convert input, but it shufflevector to <4xhalf> which is not expected.

Is there something wrong from this hlsl or dxc problem

**Steps to Reproduce**
<!--- Provide a description of how to reproduce the error. If possible please 
provide source and tool command line options. If the issue reproduces on
Compiler Explorer (https://godbolt.org/) or Shader Playground
(https://shader-playground.timjones.io/) please provide a link. If the source is
split across multiple files, please preprocess into a single file using DXC's 
command line `-P -Fi <path>`. --->


**Actual Behavior**
<!--- Please provide error output or a description of the observed issue. --->

**Environment**
- DXC version <!-- replace with the output of 'dxc --version' -->
- Host Operating System <!--- Host operating system and version --->



Discussion:

Patch:
diff --git a/utils/hct/gen_intrin_main.txt b/utils/hct/gen_intrin_main.txt
index 3075e8a4cf..657b3e942f 100644
--- a/utils/hct/gen_intrin_main.txt
+++ b/utils/hct/gen_intrin_main.txt
@@ -408,8 +408,8 @@ void [[min_sm=6.10]] __builtin_LinAlg_MatrixVectorMultiply(out numeric<c> ret, i
 void [[min_sm=6.10]] __builtin_LinAlg_MatrixVectorMultiplyAdd(out numeric<c> ret, in LinAlgMatrix mat, in bool isOutputSigned, in numeric<c2> input, in uint inputInterp, in numeric<c> bias, in uint biasInterp);
 void [[min_sm=6.10]] __builtin_LinAlg_MatrixAccumulateToDescriptor(in LinAlgMatrix matrix, in RWByteAddressBuffer buf, in uint offset, in uint stride, in uint layout, in uint align);
 void [[min_sm=6.10]] __builtin_LinAlg_MatrixAccumulateToMemory(in LinAlgMatrix matrix, groupshared numeric[] memory, in uint offset, in uint stride, in uint layout);
-void [[min_sm=6.10]] __builtin_LinAlg_MatrixOuterProduct(out LinAlgMatrix ret, in numeric<> vecA, in numeric<> vecB);
-void [[min_sm=6.10]] __builtin_LinAlg_Convert(out numeric<> ret, in numeric<> vec, in uint input_interp, in uint output_interp);
+void [[min_sm=6.10]] __builtin_LinAlg_MatrixOuterProduct(out LinAlgMatrix ret, in numeric<c> vecA, in numeric<c2> vecB);
+void [[min_sm=6.10]] __builtin_LinAlg_Convert(out numeric<c> ret, in numeric<c2> vec, in uint input_interp, in uint output_interp);
 
 } namespace
 


Test patch:
diff --git a/tools/clang/test/CodeGenDXIL/hlsl/linalg/api/vectors.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/linalg/api/vectors.hlsl
index 876edcca46..268e814e7e 100644
--- a/tools/clang/test/CodeGenDXIL/hlsl/linalg/api/vectors.hlsl
+++ b/tools/clang/test/CodeGenDXIL/hlsl/linalg/api/vectors.hlsl
@@ -5,7 +5,8 @@
 using namespace dx::linalg;
 
 using MatrixATy = Matrix<ComponentType::F16, 8, 4, MatrixUse::A, MatrixScope::Thread>;
-using MatrixAccumTy = Matrix<ComponentType::F16, 8, 8, MatrixUse::Accumulator, MatrixScope::Thread>;
+using MatrixAccum_8_8_Ty = Matrix<ComponentType::F16, 8, 8, MatrixUse::Accumulator, MatrixScope::Thread>;
+using MatrixAccum_8_4_Ty = Matrix<ComponentType::F16, 8, 4, MatrixUse::Accumulator, MatrixScope::Thread>;
 
 ByteAddressBuffer BAB : register(t0);
 
@@ -13,14 +14,14 @@ ByteAddressBuffer BAB : register(t0);
 void main(uint ID : SV_GroupID) {
   
 // CHECK: %[[MAT1:.*]] = call %dx.types.LinAlgMatrixC8M8N4U0S0 @dx.op.linAlgMatrixLoadFromDescriptor.mC8M8N4U0S0(
-// CHECK-SAME: i32 -2147483634, %dx.types.Handle %2, i32 0, i32 8, i32 1, i32 2)
+// CHECK-SAME: i32 -2147483634, %dx.types.Handle %{{[0-9]+}}, i32 0, i32 8, i32 1, i32 2)
 // CHECK-SAME: ; LinAlgMatrixLoadFromDescriptor(handle,offset,stride,layout,align)
   MatrixATy Mat1 = MatrixATy::Load<MatrixLayoutEnum::ColMajor>(BAB, 0, 8);
 
   vector<half, 4> vec1 = 10.3f;
 
 // CHECK: %[[VEC2:.*]] = call <8 x half> @dx.op.linAlgMatVecMul.v8f16.mC8M8N4U0S0.v4f16(i32 -2147483623,
-// CHECK-SAME: %dx.types.LinAlgMatrixC8M8N4U0S0 %3, i1 true, <4 x half> <half 0xH4926, half 0xH4926, half 0xH4926, 
+// CHECK-SAME: %dx.types.LinAlgMatrixC8M8N4U0S0 %[[MAT1]], i1 true, <4 x half> <half 0xH4926, half 0xH4926, half 0xH4926, 
 // CHECK-SAME: half 0xH4926>, i32 8) ; LinAlgMatVecMul(matrix,isOutputSigned,inputVector,interpretation)
   vector<half, 8> vec2 = Multiply<half>(Mat1, vec1);
 
@@ -61,13 +62,24 @@ void main(uint ID : SV_GroupID) {
   // CHECK-SAME: ; LinAlgMatVecMulAdd(matrix,isOutputSigned,inputVector,inputInterpretation,biasVector,biasInterpretation)
   vector<half, 8> vec6 = MultiplyAdd<half>(Mat1, interpVec2, memBias);
 
-  // CHECK: %[[ACCUM:.*]] = call %dx.types.LinAlgMatrixC8M8N8U2S0
+  // CHECK: %[[ACCUM1:.*]] = call %dx.types.LinAlgMatrixC8M8N8U2S0
   // CHECK-SAME: @dx.op.linAlgMatrixOuterProduct.mC8M8N8U2S0.v8f16.v8f16(i32 -2147483619,
   // CHECK-SAME: <8 x half> %[[VEC5]], <8 x half> %[[VEC6]])  ; LinAlgMatrixOuterProduct(vectorA,vectorB)
-  MatrixAccumTy AccumMatrix = OuterProduct<ComponentType::F16>(vec5, vec6);
+  MatrixAccum_8_8_Ty AccumMatrix1 = OuterProduct<ComponentType::F16>(vec5, vec6);
+
+  // CHECK: %[[ACCUM2:.*]] = call %dx.types.LinAlgMatrixC8M8N4U2S0 @dx.op.linAlgMatrixOuterProduct.mC8M8N4U2S0.v8f16.v4f16(
+  // CHECK-SAME: i32 -2147483619, <8 x half> %[[VEC5]], <4 x half> %[[VEC20]]) ; LinAlgMatrixOuterProduct(vectorA,vectorB)
+  MatrixAccum_8_4_Ty AccumMatrix2 = OuterProduct<ComponentType::F16>(vec5, vec20);
 
   // CHECK: %[[CONV_VEC:.*]] = call <8 x float> @dx.op.linAlgConvert.v8f32.v8f16(i32 -2147483618,
   // CHECK-SAME: <8 x half> %[[VEC6]], i32 8, i32 9)  ; LinAlgConvert(inputVector,inputInterpretation,outputInterpretation)
   InterpretedVector<float, 8, ComponentType::F32> convertedVec;
   convertedVec = Convert<ComponentType::F32, ComponentType::F16>(vec6);
+
+  // CHECK: call <4 x i32> @dx.op.linAlgConvert.v4i32.v16f16(i32 -2147483618, <16 x half> %21, i32 8, i32 21)
+  // CHECK: ; LinAlgConvert(inputVector,inputInterpretation,outputInterpretation)
+  typedef vector<half, 16> half16;
+  half16 srcF16 = BAB.Load<half16>(128);
+  InterpretedVector<uint, 4, ComponentEnum::F8_E4M3FN> convertedPacked = Convert<ComponentEnum::F8_E4M3FN, ComponentEnum::F16>(srcF16);
+
 }