How do you get shader graphs to compile for DirectX 12?

Most existing shaders that were written for DX 11 will not compile on DX 12 and throw tons of errors caused by standard opcodes that are not supported in shader model 6.3 which expects everything to be raytracing compliant.

Is there really no global way compile without raytracing requirements with DX12? Every setting related to raytracing is off in my project, both in the the HDRP global settings and the active RP asset. I also searched the settings for any mention of “ray”, “trace”, “traced”, “tracing” and “dxr” to make sure there are no other settings affecting compilation. I also manually went through the Player settings, could not find anything there either.

If not that means you either can not have your project on DX 12 unless you only stick to the default shaders, or try to manually disable all of the nodes causing errors with the raytracing quality node which is a huge pain and only works for some shader graphs.

Here is an example where it can’t be fixed:

Shader error in 'HDRP/Nature/SpeedTree_Branch': Opcode CalculateLOD not valid in shader model lib_6_3(anyhit). at Assets/TerrainDemoScene_HDRP/ShaderGraphs/SpeedTree_Branch.shadergraph(12623) (on d3d11)

Compiling Subshader: 1, Pass: VisibilityDXR, RayTracing program with STEREO_INSTANCING_ON TRANSPARENT_COLOR_SHADOW _ALPHATEST_ON _DISABLE_DECALS _DISABLE_SSR _DISABLE_SSR_TRANSPARENT _DOUBLESIDED_ON _WINDQUALITY_BEST
Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: EFFECT_BILLBOARD SHADER_API_GLES30 UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING _ADD_PRECOMPUTED_VELOCITY _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_THIN _SURFACE_TYPE_TRANSPARENT _TRANSPARENT_WRITES_MOTION_VEC _WINDQUALITY_BETTER _WINDQUALITY_FAST _WINDQUALITY_FASTEST _WINDQUALITY_NONE _WINDQUALITY_PALM

The SpeedTree branch shader causes 24 compilation errors all coming from CalculateLOD which is not supported with DXR. If you try to cut that out using the raytracing quality node that will just cause another error though.

Error in Shader Graph Assets/TerrainDemoScene_HDRP/ShaderGraphs/SpeedTree_Branch.shadergraph: Graph is generating too many variants. Either delete Keywords, reduce Keyword variants or increase the Shader Variant Limit in Preferences > Shader Graph.

Even if you raise the variant limit to something ridiculous like a million this error will still show up and prevent you from compiling the shader graph.

So now what? Looks like this perfectly good shader is just dead on DX 12 for no reason.

Can somebody please explain to me why this completely artificial issue exists? Even if DX 12 has hard requirement on raytracing support, why does the shader graph compiler not give you an option to just patch in a placeholder shader that renders the entire object black on the raytracing path or something like that? Even if editing the graph would work, it’s still a completely unnecessary pain to splice in the raytracing quality node at each point where an unsupported operation needs to be filtered out instead of just disabling it with a single checkbox in the graph inspector.

2 Likes
  1. Make sure Unity is updated of course. If you are up to date and this error only happens in dx12, file a bug report.
  2. Could you share the shader graph preferences?
  3. If you open the graph, are there any nodes that have a note next to them?
  4. Are there maybe updated versions of this shader available?
  1. I’m using 2022.3.42f1, which is the latest LTS.

  2. The shader variant limit is at 128, error threshold at 32, and warning threshold at 16. All of which are the default values. Like I said, raising the shader variant limit does not fix the error saying to raise it.

  3. No, the nodes are all up to date.

  4. As far as I can tell, no. SpeedTree does not offer a package with the shader that they keep up to date.

All of that is moot though, I just managed to compile by creating a new blank project that is based on DX 11 and then switching to DX 12.

I think the shader graph compiler configuration gets permanently stuck in shader model 6.3 if you ever touched one of the ray tracing settings with no way to ever disable it again in that project, at least from the settings exposed in the editor.

If anyone does know how to retroactively fix this in a project that is already in this state, please let me know. I hope I just missed some setting that was less obviously named.

2 Likes