By default, Unity compiles shadersA program that runs on the GPU. More info
See in Glossary using the DirectX 11 (DX11) compiler FXC. To speed up compilation and use the latest shader features on some platforms, use the DirectX 12 (DX12) compiler DXC instead.
Note: DXC in Unity is supported only on Windows platforms using the DX12 graphics API. On Vulkan and Metal platforms, DXC support in Unity is experimental and not ready for production use. DXC isn’t compatible with DX11.
Using DXC has the following advantages over FXC:
For more information about the different shader compilers, refer to shader compilation.
If you build your project for Windows platforms and use the DirectX 12 (DX12) graphics API, you can enable the DXC compiler for all shaders.
Important: This is recommended if you build only for DX12. If you build for both DX11 and DX12, Unity compiles two sets of shaders by using FXC for DX11 and DXC for DX12.
Follow these steps:
For more information about the DirectX graphics APIs, refer to DirectX.
To use either the FXC or DXC compiler for a specific shader pass in a custom shader on any platform, add one of the following #pragma directives to the shader code:
#pragma use_dxc to use the DXC compiler for the shader pass.#pragma never_use_dxc to use the FXC compiler for the shader pass.To restrict the directive to specific platforms or graphics APIs, add the platform or graphics API name after the directive. For example, #pragma use_dxc d3d12. For a full list of names, refer to Set the graphics API or platform for a shader.
The #pragma directives override the value you set in your build profile.
For more information about #pragma directives, refer to Pass information to shader compilers in HLSL.
Unity’s built-in shaders are already compatible with the DXC compiler.
If you have custom shaders, make the following changes to make sure they’re compatible with the DXC compiler:
COLOR semantic with SV_Target.POSITION semantic with SV_Position.VFACE float semantic with the SV_IsFrontFace boolean.float a = uv.xy, use float a = uv.x or float a = uv.y.Texture2DMS to declare a multisampled texture, make sure you include a sample count. For example Texture2DMS<float4, 4> instead of only Texture2DMS<float4>.RWBuffer, add : register(uN) to the declaration, where N is the index in your Graphics.SetRandomWriteTarget call.StructuredBuffer in the argument list of a shader method. Declare them outside the method instead.You might also need to make changes to your shader code based on the following:
atan2(0,0) as π ÷ 2, but FXC calculates it as NaN.round(0.5) as 0.0, but FXC calculates it as 1.0 for constants and 0.0 for non-constants.For a full list of HLSL differences between the two compilers, refer to Porting shaders from FXC to DXC on the Microsoft website.