shader-slang / slang

Making it easier to work with shaders
MIT License
1.98k stars 169 forks source link

Problem with exported matrices in DxcLinker #4880

Open cheneym2 opened 3 weeks ago

cheneym2 commented 3 weeks ago

First, compile a dxil library that uses the float4x4 matrix type.

$ cat ./lib.slang
module "repro";

export float4x4 to4x4(float3x4 source)
{
    return float4x4(source[0], source[1], source[2], float4(0.0f, 0.0f, 0.0f, 1.0f));
}
$ ./build/Release/bin/slangc.exe ./lib.slang -profile lib_6_6 -o lib.dxil
<success>

Now compile an "anyhit" shader including that precompiled library as a reference so it gets linked in, tickling the DxcLinker usage.

$ cat ./anyhit.slang
struct Attributes
{
    float2 bary;
};

struct ShadowHitInfo
{
    bool isHit;
    uint seed;
};

[shader("anyhit")]
void shadow(inout ShadowHitInfo payload, Attributes attrib)
{
    IgnoreHit();
}
$ ./build/Release/bin/slangc.exe ./anyhit.slang -stage anyhit -entry shadow -o out2.dxil -r lib.dxil
dxc 1.7: : error : error: validation errors
Function: ?to4x4_0@@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_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z'.
Function: ?to4x4_0@@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_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z'.
Function: ?to4x4_0@@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_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z'.
Function: ?to4x4_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: Instructions must be of an allowed type.
note: at '%18 = insertvalue %class.matrix.float.4.4 undef, <4 x float> %17, 0, 0' in block '#0' of function '?to4x4_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z'.
Function: ?to4x4_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: Instructions must be of an allowed type.
note: at '%20 = insertvalue %class.matrix.float.4.4 %18, <4 x float> %19, 0, 1' in block '#0' of function '?to4x4_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z'.
Function: ?to4x4_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: Instructions must be of an allowed type.
note: at '%22 = insertvalue %class.matrix.float.4.4 %20, <4 x float> %21, 0, 2' in block '#0' of function '?to4x4_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z'.
Function: ?to4x4_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z: error: Instructions must be of an allowed type.
note: at '%23 = insertvalue %class.matrix.float.4.4 %22, <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00>, 0, 3' in block '#0' of function '?to4x4_0@@YA?AV?$matrix@M$03$03@@V?$matrix@M$02$03@@@Z'.
Validation failed.
bmillsNV commented 3 weeks ago

Setting P3, marking for Q4 for now. Looks like a DXC issue - would probably require us working w/DXC team to fix.

cheneym2 commented 2 weeks ago

I filed the external bug here https://github.com/microsoft/DirectXShaderCompiler/issues/6889 in the DirectXShaderCompiler github project.