Bevy on D3D12 fails with shader validation errors if running in an environment with old DXC
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.12.1
## Relevant system information
```
Rust Version 1.73.0
Windows 11
Visual Studio 2022 with Windows SDK 10.0.19041.0 (see below)
AdapterInfo { name: "Intel(R) Iris(R) Plus Graphics", vendor: 32902, device: 35410, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Dx12 }
```
## What you did
I arrived at this problem, by noticing that whenever I tried to run any Bevy project with the D3D12 backend but in the "x64 Native Tools Command Prompt for VS 2022" that comes with Visual Studio, Bevy would always fail with the following errror:
```
2024-01-21T08:18:53.217669Z ERROR log: ID3D12Device::CreatePixelShader: Shader uses double precision float ops which are not supported on the current device. [ STATE_CREATION ERROR #336: DEVICE_CREATEPIXELSHADER_DOUBLEFLOATOPSNOTSUPPORTED]
2024-01-21T08:18:53.220832Z ERROR log: Shader translation error for stage ShaderStages(VERTEX | FRAGMENT): invalid argument
2024-01-21T08:18:53.222051Z ERROR log: Please report it to https://github.com/gfx-rs/naga
2024-01-21T08:18:53.225913Z ERROR log: Handling wgpu errors as fatal by default
thread 'main' panicked at C:\Users\James\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.17.2\src\backend\direct.rs:3056:5:
wgpu error: Validation Error
```
BUT when running under a normal Command Prompt in Windows, it worked fine.
After examining the difference between environment variables in both command prompts, I tracked this down to the addition of the following directory in my PATH variable: `C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\\x64`
And after a bit more digging, I found that in this directory, there is a much older version of DXC than the version of Windows that I am using.
Broken Version of DXC: `dxcompiler.dll: 1.5 - 10.0.19041.685; dxil.dll: 1.5(10.0.19041.685)`
Working Version of DXC: `dxcompiler.dll: 1.7 - 1.6.0.3405 (dc5eac8d0)`
## What went wrong
Bevy currently crashes with an error that doesn't provide much information to the user about the underlying problem here.
If Bevy encounters a version of DXC that is incompatible with its shaders, then it should raise a more meaningful error message (e.g. "Incompatible version of the shader compiler (DXC) found")
## Additional information
The workaround here would be to ensure the Visual Studio environment is using a more up-to-date version of the Windows SDK (that ships with a newer version of DXC).
I couldn't decide whether this was a Bevy or a WGPU issue to be honest - Bevy is asking WGPU to use a version of DXC from the environment, and that is exactly what WGPU is doing. Its just that the version happens to be incompatible with Bevy's shaders. Perhaps the fix here is in two parts - WGPU to provide a means of checking the "minimum DXC version", and then Bevy requesting that it does this?
Contributor guide
Assessment
This issue has not been assessed yet.