microsoft / microsoft/DirectXShaderCompiler

DXIL link validation error with exported matrix function

Open
#6,889 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug matrix-bug shader-linking
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

I encountered a validation error with a DXIL library, after it was successfully compiled to DXIL, during the linking step. As far as I know, the validation error only happens when the linking is done with a lib profile also. This simplified repro links with itself, which I think should be legal and it shows the error simply. Of course I was linking it with other DXIL objects in the real life case.

export float4x4 to4x4(float3x4 source)
{
    return float4x4(source[0], source[1], source[2], float4(0.0f, 0.0f, 0.0f, 1.0f));
}

Compile:
$ ../../../../Downloads/dxc_2024_03_29/bin/x64/dxc.exe ./export.hlsl -T lib_6_6 -Fo ./export.dxil

Link:
$ ../../../../Downloads/dxc_2024_03_29/bin/x64/dxc.exe -T lib_6_6 -link "./export.dxil"

Link failed:
error: validation errors
Function: ?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: ExtractValue should only be used on dxil struct types and cmpxchg.
note: at '%2 = extractvalue %class.matrix.float.3.4 %0, 0, 0' in block '#0' of function '?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@
@Z'.
Function: ?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: ExtractValue should only be used on dxil struct types and cmpxchg.
note: at '%7 = extractvalue %class.matrix.float.3.4 %0, 0, 1' in block '#0' of function '?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@
@Z'.
Function: ?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: ExtractValue should only be used on dxil struct types and cmpxchg.
note: at '%12 = extractvalue %class.matrix.float.3.4 %0, 0, 2' in block '#0' of function '?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@
@@Z'.
Function: ?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: Instructions must be of an allowed type.
note: at '%21 = insertvalue %class.matrix.float.4.4 undef, <4 x float> %20, 0, 0' in block '#0' of function '?to4x4@@YA?AV?$matrix@M$03$03@
@V?$matrix@M$02$03@@@Z'.
Function: ?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: Instructions must be of an allowed type.
note: at '%26 = insertvalue %class.matrix.float.4.4 %21, <4 x float> %25, 0, 1' in block '#0' of function '?to4x4@@YA?AV?$matrix@M$03$03@@V
?$matrix@M$02$03@@@Z'.
Function: ?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: Instructions must be of an allowed type.
note: at '%31 = insertvalue %class.matrix.float.4.4 %26, <4 x float> %30, 0, 2' in block '#0' of function '?to4x4@@YA?AV?$matrix@M$03$03@@V
?$matrix@M$02$03@@@Z'.
Function: ?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: Instructions must be of an allowed type.
note: at '%32 = insertvalue %class.matrix.float.4.4 %31, <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.00
0000e+00>, 0, 3' in block '#0' of function '?to4x4@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z'.
Validation failed.

Environment
$ ../../../../Downloads/dxc_2024_03_29/bin/x64/dxc.exe --version
dxcompiler.dll: 1.8 - 1.8.2403.37 (11e1318c3); dxil.dll: 1.8(101.8.2403.24)

Windows 10 Enterprise v22H2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided dxc compile and -link commands using the exported matrix-function HLSL example. Trace the DXIL link and validation path to determine why the linked library rejects the matrix extractvalue and insertvalue instructions; done means the repro links successfully with the lib_6_6 profile and passes validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.