On DirectX 12, when calling ShaderData.Pass.CompileVariant, the returned data contains 38 extra bytes in ShaderData.VariantCompileInfo.ShaderData before the actual compiled shader begins.
Repro
- Open the attached project ("Shader Compile") on a Windows machine
- Select one of the shaders ("NewUnlitShader" or "NewSurfaceShader", or both)
- In the top menu, select "Dump -> Dump DXIL". This creates one file per shader stage / pass in the project's root folder (e.g. "Custom_NewSurfaceShader_sub0_pass0_fragment.dxil"). The file is a straight dump of the ShaderData.VariantCompileInfo.ShaderData content
Expected behavior: The dumped file contains a valid DXIL shader
Actual behavior: There are 38 extra bytes of garbage in the beginning before the actual DXIL shader.
For illustration, I attached screenshots from a hex editor. Notice that the shader compiled by DXC ("dxc_.png") starts with the magic "DXBC". The shader compiled by Unity ("unity.png") has this magic at byte 38 instead.
Reproducible on 2021.3+